@forsion/unit 2.13.4 → 2.13.6
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/README.md +2 -2
- package/main.mjs +129 -10
- package/package.json +1 -1
- package/release.json +6 -5
- package/web/assets/ArtificialView-DHqb9CTL.js +1 -0
- package/web/assets/AutomationBuilder-CzBKmOiw.js +1 -0
- package/web/assets/CalendarConfigView-Blw47NCs.js +1 -0
- package/web/assets/CalendarSide-CFSzme3H.js +1 -0
- package/web/assets/CalendarView-B8sQfgZt.js +3 -0
- package/web/assets/CalendarView-t91KpUG7.css +1 -0
- package/web/assets/CapabilityMenu-Dzn6RbB1.js +1 -0
- package/web/assets/Chrome-owLewFu4.js +1 -0
- package/web/assets/{CodeView-GZ0BAgoW.js → CodeView-E18NDilX.js} +3 -3
- package/web/assets/CtxMenuButtons-CAiwQkOK.js +1 -0
- package/web/assets/DashboardGridView-CBbYKcCo.js +25 -0
- package/web/assets/DashboardGridView-RoVFSkNO.css +1 -0
- package/web/assets/EventCard-D9uQe7g4.js +1 -0
- package/web/assets/ExcalidrawCanvas-BSOERegJ.js +1 -0
- package/web/assets/ExcalidrawCanvas-BgcFPMpU.css +1 -0
- package/web/assets/FloatingToc-iK08Qpjc.js +1 -0
- package/web/assets/{GitCloneDialog-Bj9G3o-n.css → GitCloneDialog-DOxZk2K0.css} +1 -1
- package/web/assets/GitCloneDialog-DfY0kqhP.js +1 -0
- package/web/assets/HomepageView-BCqFe1Ym.js +4 -0
- package/web/assets/HomepageView-Bx8FbWlY.css +1 -0
- package/web/assets/ImageStudioPanels-DdwihAkT.js +3 -0
- package/web/assets/ImageStudioView-gJSYrmu1.js +1 -0
- package/web/assets/InlineAiPanel-CjYOW0_0.js +1 -0
- package/web/assets/InlineFiles-3g2jMUeA.js +1 -0
- package/web/assets/{MarkdownBlock-DQTuoen3.css → MarkdownBlock-Cqfk5DhC.css} +1 -1
- package/web/assets/MarkdownBlock-DjsGkPZ_.js +58 -0
- package/web/assets/{ModelPill-CzdNh7Mt.css → ModelPill-BiUsuhy3.css} +1 -1
- package/web/assets/ModelPill-DgyXBsL9.js +2 -0
- package/web/assets/MuseLibraryView-D_HBijmU.js +2 -0
- package/web/assets/MuseView-BVDlmM6i.js +7 -0
- package/web/assets/{PageHistoryPanel-Bn4-XmdK.js → PageHistoryPanel-B1EAPZeX.js} +2 -2
- package/web/assets/{PdfAnnotator-Cq8cklTz.js → PdfAnnotator-bdB9evsY.js} +3 -3
- package/web/assets/PenRow-DCOIGlfY.js +1 -0
- package/web/assets/PluginToolCard-BXE5vA1h.js +2 -0
- package/web/assets/PluginToolCard-BmTRr5JT.css +1 -0
- package/web/assets/ProductView-l5Q7uBy6.js +1 -0
- package/web/assets/SettingsPage-fjxfS_Mt.js +3 -0
- package/web/assets/StudioGuestSurface-360CWUwf.js +1 -0
- package/web/assets/TodoListView-BsPt2GUU.js +1 -0
- package/web/assets/Tooltip-CuXpWtdJ.js +1 -0
- package/web/assets/UnifiedPage-6xbFLtXT.js +712 -0
- package/web/assets/UnifiedPage-CTmQpf2T.css +1 -0
- package/web/assets/{ViewSelectionBar-35x8TiLA.js → ViewSelectionBar-C5FDh7fO.js} +2 -2
- package/web/assets/appStore-BskcSDl6.js +455 -0
- package/web/assets/appStore-iy8_Tmac.css +1 -0
- package/web/assets/arrow-up-right-DEykpgsH.js +1 -0
- package/web/assets/{artificial-BzLFkChP.css → artificial-BubVxExB.css} +1 -1
- package/web/assets/astryxBridge-B2IZdPvo.js +69 -0
- package/web/assets/astryxBridge-djzCiy4v.css +1 -0
- package/web/assets/automationListSource-Cm09JKkK.js +1 -0
- package/web/assets/boardSurface-Dv-aVaUJ.js +1 -0
- package/web/assets/calendarNavStore-FKStA7Hh.js +1 -0
- package/web/assets/canvasPrefs-CMulOS0k.js +1 -0
- package/web/assets/chatBoxSurface-BR_G6cxG.js +1 -0
- package/web/assets/chevron-up-C_EDOZzI.js +1 -0
- package/web/assets/{client-CaivGZFR.js → client-DD5czSuF.js} +5 -5
- package/web/assets/code-xml-vTB4LtTf.js +1 -0
- package/web/assets/{codeStudioStore-DhyMazGT.js → codeStudioStore-OswE1_s0.js} +8 -8
- package/web/assets/codingNavigation-BrkLENBZ.css +1 -0
- package/web/assets/contextMenuSurface-DqdYEGuH.js +1 -0
- package/web/assets/copy-plus-CVHqDNny.js +1 -0
- package/web/assets/create-DZWy4zBR.js +14 -0
- package/web/assets/dashboardSurface-Co4byEQm.js +1 -0
- package/web/assets/dbStore-Bc2lC8ZI.js +2 -0
- package/web/assets/deskCapture-BfTzH2aO.js +1 -0
- package/web/assets/{diff2html-Daje9Kkm.js → diff2html-0MkNy2ws.js} +2 -2
- package/web/assets/{docx-preview-CABR7n30.js → docx-preview-CwNWZegI.js} +1 -1
- package/web/assets/draft-DTzuTatQ.js +2 -0
- package/web/assets/drawingStore-BD5m2eqn.js +7 -0
- package/web/assets/file-down-Cjo_T6By.js +1 -0
- package/web/assets/floatingTocSurface-D3IIVNnq.js +1 -0
- package/web/assets/foldActions-utwZpRrA.js +1 -0
- package/web/assets/folder-DiaFWdCg.js +1 -0
- package/web/assets/folder-minus-DUEOcs12.js +1 -0
- package/web/assets/folder-plus-Cmhq0GcR.js +1 -0
- package/web/assets/gestures-Bx9M0le5.js +1 -0
- package/web/assets/git-branch-DzGWffyD.js +1 -0
- package/web/assets/homeCardStatus-NAk4A77P.js +1 -0
- package/web/assets/i18n-CAf4PT1o.css +1 -0
- package/web/assets/i18n.generated-D4-Wu9Wh.js +15 -0
- package/web/assets/imageStudio-CwG21Bat.css +1 -0
- package/web/assets/imageStudio-D67oElIb.js +4 -0
- package/web/assets/index-3VWZ1rsL.js +13 -0
- package/web/assets/index-58wBjkHy.js +3 -0
- package/web/assets/index-B9_zH7f5.js +1 -0
- package/web/assets/index-BQrMYjou.js +1 -0
- package/web/assets/index-BWrWMYua.js +1 -0
- package/web/assets/index-BdLJBf4-.js +1 -0
- package/web/assets/index-Bf3W92Hb.js +1 -0
- package/web/assets/index-BjmPaLFA.js +1 -0
- package/web/assets/index-Bv-vJTzF.js +7 -0
- package/web/assets/index-C7yb62gg.js +1 -0
- package/web/assets/index-C9gBBMYv.js +1 -0
- package/web/assets/index-CiQ59Kib.js +1 -0
- package/web/assets/{index-gt5JBIFf.js → index-CzTUjEMt.js} +2 -2
- package/web/assets/index-D4Qx6o3E.js +1 -0
- package/web/assets/index-DDBcn3UD.js +1 -0
- package/web/assets/index-DEADY94l.js +1 -0
- package/web/assets/index-DGTKsPAQ.js +1 -0
- package/web/assets/index-DRwDqvjf.js +1 -0
- package/web/assets/{index-BGfvNj7R.js → index-DexVkoxH.js} +2 -2
- package/web/assets/{index-O05r2Ty6.js → index-IMOhRWY8.js} +1 -1
- package/web/assets/index-XjvpYHIo.js +1 -0
- package/web/assets/index-YuejkHoJ.js +3412 -0
- package/web/assets/index-pH0266gX.js +1 -0
- package/web/assets/index-sQl_bGM_.js +1 -0
- package/web/assets/index-vbNFy5lS.js +1 -0
- package/web/assets/{invitePage-Bgveo6Hj.js → invitePage-BT_rFfab.js} +1 -1
- package/web/assets/{ipc-B6hkgxQL.js → ipc-8cxXGSZK.js} +1 -1
- package/web/assets/{jszip.min-eU-k-vEy.js → jszip.min-By4OI3XR.js} +1 -1
- package/web/assets/launchpad-BX4jQyF4.js +2 -0
- package/web/assets/launchpad-C9U9hpWJ.css +1 -0
- package/web/assets/layout-grid-CzxXbCDa.js +1 -0
- package/web/assets/linkFollow-J2c0wSgB.js +8 -0
- package/web/assets/{listFold-M8s5JYEC.js → listFold-B_2Xqxn_.js} +1 -1
- package/web/assets/lock-open-DVWCLSZm.js +1 -0
- package/web/assets/log-out-CdKTS7HC.js +1 -0
- package/web/assets/magnet-BmVcZ9U4.js +1 -0
- package/web/assets/main-BlVApHpj.css +1 -0
- package/web/assets/main-CForzSFD.js +15 -0
- package/web/assets/markdownEditorSurface-BiDH0__r.css +1 -0
- package/web/assets/markdownEditorSurface-Bs8FJNHu.js +3 -0
- package/web/assets/mediaPlayer-O9pVRl_k.js +1 -0
- package/web/assets/message-square-plus-CspBv9iG.js +1 -0
- package/web/assets/{messages-CKtabOqy.js → messages-CG7ywZ-K.js} +1 -1
- package/web/assets/minimize-2-Bq4vUin-.js +1 -0
- package/web/assets/mobileEntry-6u7TYC4s.css +1 -0
- package/web/assets/mobileEntry-CptXQ4Ov.js +13 -0
- package/web/assets/modelPickerSurface-C0SkjaPL.js +1 -0
- package/web/assets/nativeDownload-DlnT8U-y.js +1 -0
- package/web/assets/nativeSheetMenu-CVC51DzC.js +1 -0
- package/web/assets/pageStore-BC6Z18n7.css +1 -0
- package/web/assets/pageStore-D_fKLv-o.js +13 -0
- package/web/assets/{pageTree-BYYPgZm_.js → pageTree-DtDKozTg.js} +3 -3
- package/web/assets/pen-line-ho1GgAe2.js +1 -0
- package/web/assets/pen-tool-CV-FKFEZ.js +1 -0
- package/web/assets/pencil-BgF4Kiqp.js +1 -0
- package/web/assets/phoneList-BLVdQcXY.js +1 -0
- package/web/assets/phoneList-BpLxxdq6.css +1 -0
- package/web/assets/pluginChat-C6t6DWhY.js +2 -0
- package/web/assets/react-DOzedx9n.js +1 -0
- package/web/assets/recordSurface-C9SRNjy4.js +1 -0
- package/web/assets/redo-2-DWZTaEz-.js +1 -0
- package/web/assets/rotate-ccw-CyZpL7MX.js +1 -0
- package/web/assets/selectionActions-C2a8ImJm.js +2 -0
- package/web/assets/selectionBarSurface-DaXlyy1s.js +1 -0
- package/web/assets/sessionTitle-BtZ1BteL.js +1 -0
- package/web/assets/settingsPageSurface-Cg8FNZq3.js +1 -0
- package/web/assets/sharePage-vnghra3Q.js +2 -0
- package/web/assets/{shareViewer-BiMqIBxP.js → shareViewer-CWJQHiV-.js} +2 -2
- package/web/assets/star-ZEpUQwnX.js +1 -0
- package/web/assets/tableSurface-DfEdzVDn.js +1 -0
- package/web/assets/tanguProbe-BboOas-a.js +6 -0
- package/web/assets/{terminalView-lbcBgG0c.js → terminalView-xp8ARBLi.js} +3 -3
- package/web/assets/type-CMyP4cKt.js +1 -0
- package/web/assets/undo-2-C4ZCsMsx.js +1 -0
- package/web/assets/{unitAccount-DGwGsmC3.js → unitAccount-DNxfGo3c.js} +1 -1
- package/web/assets/{unitBridge-CE2yAvm0.js → unitBridge-Bq0n1ZM6.js} +1 -1
- package/web/assets/{unitCloudTransport-BGFwkaDM.js → unitCloudTransport-CErylgEO.js} +1 -1
- package/web/assets/unitOwnerAccess-7s-3dfNM.js +1 -0
- package/web/assets/unitShim-BfheyIG8.js +5 -0
- package/web/assets/upload-VtCrluEO.js +1 -0
- package/web/assets/userSpaces-BpeYjLni.js +1 -0
- package/web/assets/viewportLock-B0l1GU_k.css +1 -0
- package/web/assets/viewportLock-cVUalJAI.js +738 -0
- package/web/assets/zoom-in-C7R8s9x-.js +1 -0
- package/web/excalidraw/excalidraw.js +4 -2
- package/web/index.html +12 -13
- package/web/assets/ArtificialView-DLh75dAI.js +0 -1
- package/web/assets/AutomationBuilder-DNWWGnFr.js +0 -1
- package/web/assets/CalendarConfigView-G7je7k9-.js +0 -1
- package/web/assets/CalendarView-B2MtaOJk.js +0 -1
- package/web/assets/CapabilityMenu-DJaZ_Cyt.js +0 -1
- package/web/assets/CheckboxInput-FYXLaZke.js +0 -1
- package/web/assets/Chrome-CFonajM4.js +0 -1
- package/web/assets/DashboardGridView-D9s9pez_.css +0 -1
- package/web/assets/DashboardGridView-Xgw4wa0_.js +0 -17
- package/web/assets/EventCard-_39F_I5M.js +0 -1
- package/web/assets/ExcalidrawCanvas-4uYrLYin.css +0 -1
- package/web/assets/ExcalidrawCanvas-rXujil36.js +0 -1
- package/web/assets/FloatingToc-DNqAkkI0.js +0 -1
- package/web/assets/GitCloneDialog-CQx-O4j1.js +0 -1
- package/web/assets/HomepageView-DcWmTPQO.css +0 -1
- package/web/assets/HomepageView-MYEk3RCs.js +0 -3
- package/web/assets/ImageStudioPanels-4wnb2XF4.js +0 -3
- package/web/assets/ImageStudioView-qrmW8pfx.js +0 -1
- package/web/assets/InlineAiPanel-B3kd1ob2.js +0 -1
- package/web/assets/InlineFiles-Clnqh9jD.js +0 -1
- package/web/assets/MarkdownBlock-DT_wsaja.js +0 -58
- package/web/assets/ModelPill-JaIH3ffZ.js +0 -2
- package/web/assets/MuseLibraryView-DOJVVeU6.js +0 -2
- package/web/assets/MuseView-uxTmjVQa.js +0 -6
- package/web/assets/PenRow-COOYAaxx.js +0 -1
- package/web/assets/ProductView-DPTveulg.js +0 -1
- package/web/assets/RightPanel-BJUacrsf.js +0 -4
- package/web/assets/RightPanel-D0zk1g3I.css +0 -1
- package/web/assets/SketchCard-B_UU5sxV.js +0 -641
- package/web/assets/StudioGuestSurface-yBa4QKfX.js +0 -1
- package/web/assets/TargetHealthNotice-BLzDB-Xl.css +0 -1
- package/web/assets/TargetHealthNotice-CgkdTdhB.js +0 -47
- package/web/assets/TodoListView-CricdCfW.js +0 -1
- package/web/assets/Tooltip-o8ZqIb3L.js +0 -1
- package/web/assets/UnifiedPage-BWAyqj65.js +0 -69
- package/web/assets/UnifiedPage-CWXc_mo1.css +0 -1
- package/web/assets/appStore-CI1_L5OS.js +0 -3357
- package/web/assets/appStore-DQc2marq.css +0 -1
- package/web/assets/approvalText-Cy2UAUAQ.js +0 -2
- package/web/assets/arrow-up-right-BDsMFoNQ.js +0 -1
- package/web/assets/astryxBridge-CF_hpqC2.css +0 -1
- package/web/assets/astryxBridge-CH_c5xjo.js +0 -70
- package/web/assets/automationListSource-CB6AWkL_.js +0 -1
- package/web/assets/boardSurface-CLvEUjbF.js +0 -1
- package/web/assets/book-open-BLzEdGfu.js +0 -1
- package/web/assets/calendarNavStore-BHUNxDx8.js +0 -1
- package/web/assets/canvasPrefs-CvE7mgyq.js +0 -1
- package/web/assets/chatBoxSurface-CuuHLzs5.js +0 -1
- package/web/assets/circle-question-mark-BM4ZRxQS.js +0 -1
- package/web/assets/circle-x-DTcNGZDT.js +0 -1
- package/web/assets/code-xml-AE3mT4T5.js +0 -1
- package/web/assets/codingNavigation-B0kVsy4x.js +0 -53
- package/web/assets/codingNavigation-DHCidM4N.css +0 -1
- package/web/assets/create-1JI2I47p.js +0 -14
- package/web/assets/dashboardSurface-CIE5HybN.js +0 -1
- package/web/assets/deskCapture-COW7aG5Y.js +0 -1
- package/web/assets/emoji-DZ9CA_3l.css +0 -1
- package/web/assets/emoji-DphwSxPx.js +0 -1
- package/web/assets/floatingTocSurface-BOm2QYBK.js +0 -1
- package/web/assets/foldActions-DNbJPlPl.js +0 -1
- package/web/assets/folder-DotgUhYD.js +0 -1
- package/web/assets/folder-plus-aJgL9NeP.js +0 -1
- package/web/assets/gestures-dqncPOwo.js +0 -1
- package/web/assets/git-branch-CwR2qic6.js +0 -1
- package/web/assets/hack2gate-dark-Dx2RtDRI.jpg +0 -0
- package/web/assets/hack2gate-light-DRKq9tyS.jpg +0 -0
- package/web/assets/hand-XNkzNiW2.js +0 -1
- package/web/assets/hard-drive-CfWKRoAE.js +0 -1
- package/web/assets/i18n-CykmULlm.css +0 -1
- package/web/assets/i18n.generated-BwynSSMk.js +0 -15
- package/web/assets/imageStudio-CWgLpC_d.js +0 -2
- package/web/assets/imageStudio-DZ0qGU2s.css +0 -1
- package/web/assets/index-B65ULikK.js +0 -1
- package/web/assets/index-BIIeiIap.js +0 -1
- package/web/assets/index-BOzsniE1.js +0 -297
- package/web/assets/index-BfrjVzia.js +0 -13
- package/web/assets/index-Bi9UtjVz.js +0 -1
- package/web/assets/index-C1uilc9i.js +0 -1
- package/web/assets/index-C3Dc3Ivz.js +0 -1
- package/web/assets/index-CJF_Ld1Y.js +0 -1
- package/web/assets/index-CMARP4oV.js +0 -1
- package/web/assets/index-C_RsQVNm.js +0 -7
- package/web/assets/index-ChyxZMm8.js +0 -1
- package/web/assets/index-CoKcOaZg.js +0 -1
- package/web/assets/index-CuviSCbk.js +0 -1
- package/web/assets/index-Cw43kua8.js +0 -1
- package/web/assets/index-D1fu6XQN.js +0 -3
- package/web/assets/index-DG-hXb63.js +0 -1
- package/web/assets/index-DjnTfJpN.js +0 -1
- package/web/assets/index-Dtw0abst.js +0 -1
- package/web/assets/index-W3ErfZiX.js +0 -1
- package/web/assets/index-Yc56b3XX.js +0 -1
- package/web/assets/index-d4jCdYJH.js +0 -1
- package/web/assets/index-siHtlYTM.js +0 -1
- package/web/assets/launchpad-C2c1MSVX.css +0 -1
- package/web/assets/layout-grid-CraV7nhh.js +0 -1
- package/web/assets/linkFollow-BpvDWzUx.js +0 -8
- package/web/assets/list-tree-cLJw-jYQ.js +0 -1
- package/web/assets/lock-DBkXXwaI.js +0 -1
- package/web/assets/lock-open-C-9-AWct.js +0 -1
- package/web/assets/log-out-C8bDXj9P.js +0 -1
- package/web/assets/main-BiS_5wrB.css +0 -1
- package/web/assets/main-CMk6twzA.js +0 -20
- package/web/assets/markdownEditorSurface-Bql20IAf.css +0 -1
- package/web/assets/markdownEditorSurface-DgQ0TUWH.js +0 -3
- package/web/assets/message-square-plus-8pfimvem.js +0 -1
- package/web/assets/minus-CfA9fAN3.js +0 -1
- package/web/assets/mobileEntry-DS1vohuL.css +0 -1
- package/web/assets/mobileEntry-NcMcK0LV.js +0 -13
- package/web/assets/nativeDownload-CNtwSCy0.js +0 -1
- package/web/assets/pageChrome-BR4cfIaA.js +0 -1
- package/web/assets/pageChrome-BbUhILy0.css +0 -1
- package/web/assets/pen-tool-C5ftHCnm.js +0 -1
- package/web/assets/pencil-ehhM9_9k.js +0 -1
- package/web/assets/phoneList-B6gwUJZF.js +0 -9
- package/web/assets/phoneList-iRdfiKA8.css +0 -1
- package/web/assets/pluginChat-DTTWWiUS.js +0 -2
- package/web/assets/redo-2-DCEAgQlN.js +0 -1
- package/web/assets/rotate-ccw-DdkrbRAB.js +0 -1
- package/web/assets/selectionActions-BQD2kox1.js +0 -2
- package/web/assets/selectionBarSurface-CzUZmJDJ.js +0 -1
- package/web/assets/server-Ddu9f1k3.js +0 -1
- package/web/assets/sharePage-CNrm2xTC.js +0 -2
- package/web/assets/star-Dxv7XANS.js +0 -1
- package/web/assets/tableSurface-Bly1iCXc.js +0 -1
- package/web/assets/terminal-CAmmC9cV.js +0 -1
- package/web/assets/type-Dz6rnTvG.js +0 -1
- package/web/assets/undo-2-B7izWNb_.js +0 -1
- package/web/assets/unitOwnerAccess-D4nKS6Gg.js +0 -1
- package/web/assets/unitShim-2_2hhGxS.js +0 -5
- package/web/assets/upload-DqpRRAhG.js +0 -1
- package/web/assets/userSpaces-VFu4s05v.js +0 -1
- package/web/assets/viewportLock-3AOdDmwi.js +0 -631
- package/web/assets/viewportLock-djvL8fUQ.css +0 -1
- package/web/assets/zoom-in-Bf-eKTnH.js +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import{r as A,a as Be,at as qn,aF as Za,aE as lf,B as Zo,c7 as dn,c8 as es,c9 as Mi,t as P,ca as Ni,Q as Ei,S as Ti,R as Ii,cb as ts,q as Ri,u as hn,j as b,bV as Br,cc as Li,cd as $i,f as xo,m as Di,aP as cf,a8 as uf,E as ns,ce as el,C as df,cf as vo,cg as tl,ch as ff,ci as pf,bZ as mf,c4 as hf,ab as nl,ac as gf,bc as bf,bd as yf,c5 as kf,bp as wf,bS as xf}from"./index-YuejkHoJ.js";import{m7 as be,lZ as se,n4 as rs,me as os,mf as vf,md as ke,mg as te,m0 as q,m9 as oe,ms as _e,n5 as ss,n6 as Cf,m4 as as,m6 as fr,m1 as fe,n7 as Sf,n8 as Qt,n9 as Wn,na as dt,mH as ie,mo as ce,nb as On,nc as ls,nd as Af,ne as ft,nf as Mf,ng as Nf,m5 as Co,nh as Ef,ni as is,nj as _i,nk as nt,mq as Tf,nl as If,m8 as Qe,mx as Rf,nm as Lf,nn as zi,no as $f,np as Un,gW as Df,gX as _f,mI as qt,nq as zf,nr as Of,ns as Oi,mG as xr,nt as Pf,nu as Pi,nv as Bi,nw as Bf,nx as Kf,ny as jf,nz as Hf,nA as Ff,nB as qf,nC as Wf,nD as Uf,mh as Vf,nE as Gf,nF as Jf,aM as Yf,dZ as Xf,fJ as Ze,nG as Qf,nH as Zf,nI as ep,g9 as Je,nJ as vr,nK as tp,fG as np,fC as rp,nL as op,aA as sp,nM as ap,nN as lp,ma as ip,nO as cp,nP as up,nQ as dp,mv as Ki,nR as fp,bV as pp,nS as mp,gS as hp,nT as gp,e_ as So,nU as oo,bG as bp,L as yp,nV as kp,nW as wp,nX as xp,nY as vp,nZ as Cp,n_ as Sp,n$ as Ap,o0 as Mp,o1 as Np,o2 as Ep,o3 as Tp,o4 as Ip,o5 as Rp,o6 as Lp,o7 as $p,o8 as Dp,o9 as _p,oa as zp,ob as Op,oc as Pp,od as Bp,oe as Kp,of as jp,og as Hp,oh as Fp,oi as qp,oj as Wp,mJ as Up,kT as so,ok as Vp,ol as Gp,om as Jp,on as rl,l$ as ol,l1 as Yp,oo as ji,op as Xp,fI as Qp,oq as Zp,or as em}from"./appStore-BskcSDl6.js";import{$ as re,c as V,d as pt,e as Vn,f as je,g as cs,a as Ne,h as rt,b as De,i as us,j as he,k as tm}from"./index-CiQ59Kib.js";import{s as Hi,b as Kr,e as ds,d as nm,L as sl,m as rm,f as om,a as sm,u as Fi,g as am,h as lm,w as im,l as cm,j as um,k as dm,I as al}from"./linkFollow-J2c0wSgB.js";import{p as qi,X as Wt,u as Pn,aE as Fe,bm as fm,B as Wi,cL as pm,bj as mm,b4 as Ui,as as hm,q as gm,c7 as bm,aV as ar}from"./pageStore-D_fKLv-o.js";import"./client-DD5czSuF.js";import{M as ym,c as km,s as wm}from"./selectionActions-C2a8ImJm.js";import{b as xm,t as vm,m as Cm,g as Sm}from"./listFold-B_2Xqxn_.js";import{c as Am}from"./FloatingToc-iK08Qpjc.js";const Mm=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],Nm=qi("text-align-center",Mm);const Em=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],Tm=qi("text-align-end",Em);Be({"settings.notes.spellcheckLabel":{zh:"拼写检查",en:"Spell check"},"settings.notes.spellcheckHint":{zh:"在笔记正文、标题和源码模式里标出拼写错误。代码块、行内代码和公式始终不检查。",en:"Underline misspellings in note text, titles, and source mode. Code blocks, inline code, and formulas are never checked."}});const fs="amadeus.notes.spellcheck",Ao="amadeus:notes-spellcheck";function Vi(){try{return localStorage.getItem(fs)!=="0"}catch{return!0}}function L1(e){try{localStorage.setItem(fs,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(Ao))}catch{}}function Gi(e){const t=n=>{(!n.key||n.key===fs)&&e()};return window.addEventListener(Ao,e),window.addEventListener("storage",t),()=>{window.removeEventListener(Ao,e),window.removeEventListener("storage",t)}}function $1(){return A.useSyncExternalStore(Gi,Vi,()=>!0)}const ll={spellcheck:"false"};function Ji(e,t,n){const r=[];return e.nodesBetween(t,n,(o,s)=>{if(!o.isTextblock)return!0;if(o.type.spec.code)return!1;const a=s+1;if(o.forEach((l,i)=>{l.isText&&l.marks.some(c=>c.type.spec.code||c.type.name==="inlineCode")&&r.push(te.inline(a+i,a+i+l.nodeSize,ll))}),o.textContent.includes("$"))for(const l of Hi(Kr(o)))r.push(te.inline(a+l.from,a+l.to,ll));return!1}),r}function Yi(e){const t=Ji(e,0,e.content.size);return t.length?ke.create(e,t):ke.empty}function Im(e,t){const n=e.doc;if(!e.steps.every(s=>s instanceof rs||s instanceof os||s instanceof vf))return Yi(n);const r=[];for(let s=0;s<e.steps.length;s++){const a=e.mapping.slice(s+1),l=r.length;if(e.mapping.maps[s].forEach((c,u,d,f)=>{r.push([a.map(d,-1),a.map(f,1)])}),r.length>l)continue;const i=e.steps[s];r.push([a.map(i.from,-1),a.map(i.to,1)])}let o=t.map(e.mapping,n);for(const[s,a]of r){const l=n.resolve(Math.min(s,n.content.size)),i=n.resolve(Math.min(a,n.content.size)),c=l.depth?l.before(1):l.pos,u=i.depth?i.after(1):i.pos;o=o.remove(o.find(c,u)).add(n,Ji(n,c,u))}return o}const il=new be("amadeus-spellcheck"),Rm=re(()=>new se({key:il,state:{init:(e,t)=>Yi(t.doc),apply:(e,t)=>e.docChanged?Im(e,t):t},props:{decorations:e=>il.getState(e),attributes:()=>({spellcheck:Vi()?"true":"false"})},view:e=>({destroy:Gi(()=>e.updateState(e.state))})}));Be({"settings.notes.codeAutoPairLabel":{zh:"代码块自动补全括号",en:"Auto-close brackets in code blocks"},"settings.notes.codeAutoPairHint":{zh:"在代码块里输入左括号或引号时自动补上另一半;紧挨着再输入同一个闭合符号会直接跳过。",en:"Typing an opening bracket or quote in a code block inserts the closing half. Typing the same closing character next to it steps over it."}});const ps="amadeus.notes.codeAutoPair",Mo="amadeus:notes-code-autopair";function Xi(){try{return localStorage.getItem(ps)!=="0"}catch{return!0}}function D1(e){try{localStorage.setItem(ps,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(Mo))}catch{}}function Lm(e){const t=n=>{(!n.key||n.key===ps)&&e()};return window.addEventListener(Mo,e),window.addEventListener("storage",t),()=>{window.removeEventListener(Mo,e),window.removeEventListener("storage",t)}}function _1(){return A.useSyncExternalStore(Lm,Xi,()=>!0)}const Cr={"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"},$m=new Set(Object.values(Cr)),cl=/[\p{L}\p{N}_]/u;function Qi(e,t,n){if(t!==n||!Xi())return null;const r=e.state.doc.resolve(t);return r.parent.type.name!=="code_block"?null:{text:r.parent.textContent,off:r.parentOffset}}function Dm(e,t,n,r){const o=Qi(e,t,n);if(!o||r.length!==1)return!1;const s=o.text.charAt(o.off),a=o.text.charAt(o.off-1);if($m.has(r)&&s===r)return e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,t+1))),!0;const l=Cr[r];if(!l||cl.test(s)||l===r&&cl.test(a))return!1;const i=e.state.tr.insertText(r+l,t,n);return i.setSelection(q.create(i.doc,t+1)),e.dispatch(i),!0}function _m(e){const{from:t,to:n}=e.state.selection,r=Qi(e,t,n);if(!r||r.off===0)return!1;const o=r.text.charAt(r.off-1);return!Cr[o]||r.text.charAt(r.off)!==Cr[o]?!1:(e.dispatch(e.state.tr.delete(t-1,t+1)),!0)}function zm(e,t){return function(n,r){let{$from:o,$to:s,node:a}=n.selection;if(a&&a.isBlock||o.depth<2||!o.sameParent(s))return!1;let l=o.node(-1);if(l.type!=e)return!1;if(o.parent.content.size==0&&o.node(-1).childCount==o.indexAfter(-1)){if(o.depth==3||o.node(-3).type!=e||o.index(-2)!=o.node(-2).childCount-1)return!1;if(r){let d=oe.empty,f=o.index(-1)?1:o.index(-2)?2:3;for(let y=o.depth-f;y>=o.depth-3;y--)d=oe.from(o.node(y).copy(d));let m=o.indexAfter(-1)<o.node(-2).childCount?1:o.indexAfter(-2)<o.node(-3).childCount?2:3;d=d.append(oe.from(e.createAndFill()));let p=o.before(o.depth-(f-1)),h=n.tr.replace(p,o.after(-m),new _e(d,4-f,0)),g=-1;h.doc.nodesBetween(p,h.doc.content.size,(y,k)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=k+1)}),g>-1&&h.setSelection(fe.near(h.doc.resolve(g))),r(h.scrollIntoView())}return!0}let i=s.pos==o.end()?l.contentMatchAt(0).defaultType:null,c=n.tr.delete(o.pos,s.pos),u=i?[null,{type:i}]:void 0;return Sf(c.doc,o.pos,2,u)?(r&&r(c.split(o.pos,2,u).scrollIntoView()),!0):!1}}function Zi(e){return function(t,n){let{$from:r,$to:o}=t.selection,s=r.blockRange(o,a=>a.childCount>0&&a.firstChild.type==e);return s?n?r.node(s.depth-1).type==e?Om(t,n,e,s):Pm(t,n,s):!0:!1}}function Om(e,t,n,r){let o=e.tr,s=r.end,a=r.$to.end(r.depth);s<a&&(o.step(new ss(s-1,a,s,a,new _e(oe.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new Cf(o.doc.resolve(r.$from.pos),o.doc.resolve(a),r.depth));const l=as(r);if(l==null)return!1;o.lift(r,l);let i=o.doc.resolve(o.mapping.map(s,-1)-1);return fr(o.doc,i.pos)&&i.nodeBefore.type==i.nodeAfter.type&&o.join(i.pos),t(o.scrollIntoView()),!0}function Pm(e,t,n){let r=e.tr,o=n.parent;for(let m=n.end,p=n.endIndex-1,h=n.startIndex;p>h;p--)m-=o.child(p).nodeSize,r.delete(m-1,m+1);let s=r.doc.resolve(n.start),a=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,i=n.endIndex==o.childCount,c=s.node(-1),u=s.index(-1);if(!c.canReplace(u+(l?0:1),u+1,a.content.append(i?oe.empty:oe.from(o))))return!1;let d=s.pos,f=d+a.nodeSize;return r.step(new ss(d-(l?1:0),f+(i?1:0),d+1,f-1,new _e((l?oe.empty:oe.from(o.copy(oe.empty))).append(i?oe.empty:oe.from(o.copy(oe.empty))),l?0:1,i?0:1),l?0:1)),t(r.scrollIntoView()),!0}function ec(e){return function(t,n){let{$from:r,$to:o}=t.selection,s=r.blockRange(o,c=>c.childCount>0&&c.firstChild.type==e);if(!s)return!1;let a=s.startIndex;if(a==0)return!1;let l=s.parent,i=l.child(a-1);if(i.type!=e)return!1;if(n){let c=i.lastChild&&i.lastChild.type==l.type,u=oe.from(c?e.create():null),d=new _e(oe.from(e.create(null,oe.from(l.type.create(null,u)))),c?3:1,0),f=s.start,m=s.end;n(t.tr.step(new ss(f-(c?3:1),m,f,m,d,1,!0)).scrollIntoView())}return!0}}function Bm(e){const t=new Map;if(!e||!e.type)throw new Error("mdast-util-definitions expected node");return qn(e,"definition",function(r){const o=ul(r.identifier);o&&!t.get(o)&&t.set(o,r)}),n;function n(r){const o=ul(r);return t.get(o)}}function ul(e){return String(e||"").toUpperCase()}function Km(){return function(e){const t=Bm(e);qn(e,function(n,r,o){if(n.type==="definition"&&o!==void 0&&typeof r=="number")return o.children.splice(r,1),[Za,r];if(n.type==="imageReference"||n.type==="linkReference"){const s=t(n.identifier);if(s&&o&&typeof r=="number")return o.children[r]=n.type==="imageReference"?{type:"image",url:s.url,title:s.title,alt:n.alt}:{type:"link",url:s.url,title:s.title,children:n.children},[Za,r]}})}}function tc(e,t){if(!(t.childCount>=1&&t.lastChild?.type.name==="hardbreak")){e.next(t.content);return}const n=[];t.content.forEach((r,o,s)=>{s!==t.childCount-1&&n.push(r)}),e.next(oe.fromArray(n))}function v(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-commonmark",...t}}),e}var ms=Vn("emphasis");v(ms,{displayName:"Attr<emphasis>",group:"Emphasis"});var Dt=pt("emphasis",e=>({attrs:{marker:{default:e.get(Qt).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:t=>t==="italic"}],toDOM:t=>["em",e.get(ms.key)(t)],parseMarkdown:{match:t=>t.type==="emphasis",runner:(t,n,r)=>{t.openMark(r,{marker:n.marker}),t.next(n.children),t.closeMark(r)}},toMarkdown:{match:t=>t.type.name==="emphasis",runner:(t,n)=>{t.withMark(n,"emphasis",void 0,{marker:n.attrs.marker})}}}));v(Dt.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});v(Dt.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var jr=V("ToggleEmphasis",e=>()=>Wn(Dt.type(e)));v(jr,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var hs=he(e=>ft(/(?:^|[^*])\*([^*]+)\*$/,Dt.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}));v(hs,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var gs=he(e=>ft(/\b_(?![_\s])(.*?[^_\s])_\b/,Dt.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}));v(gs,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var bs=je("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:e=>{const t=e.get(ce);return()=>t.call(jr.key)}}});v(bs.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});v(bs.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var ys=Vn("strong");v(ys,{displayName:"Attr<strong>",group:"Strong"});var gn=pt("strong",e=>({attrs:{marker:{default:e.get(Qt).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:t=>t.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:t=>t==="bold"},{style:"font-weight=400",clearMark:t=>t.type.name=="strong"},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM:t=>["strong",e.get(ys.key)(t)],parseMarkdown:{match:t=>t.type==="strong",runner:(t,n,r)=>{t.openMark(r,{marker:n.marker}),t.next(n.children),t.closeMark(r)}},toMarkdown:{match:t=>t.type.name==="strong",runner:(t,n)=>{t.withMark(n,"strong",void 0,{marker:n.attrs.marker})}}}));v(gn.mark,{displayName:"MarkSchema<strong>",group:"Strong"});v(gn.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var Hr=V("ToggleStrong",e=>()=>Wn(gn.type(e)));v(Hr,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var ks=he(e=>ft(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),gn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}));v(ks,{displayName:"InputRule<strong>",group:"Strong"});var ws=je("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:e=>{const t=e.get(ce);return()=>t.call(Hr.key)}}});v(ws.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});v(ws.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var xs=Vn("inlineCode");v(xs,{displayName:"Attr<inlineCode>",group:"InlineCode"});var bt=pt("inlineCode",e=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:t=>["code",e.get(xs.key)(t)],parseMarkdown:{match:t=>t.type==="inlineCode",runner:(t,n,r)=>{t.openMark(r),t.addText(n.value),t.closeMark(r)}},toMarkdown:{match:t=>t.type.name==="inlineCode",runner:(t,n,r)=>(t.withMark(n,"inlineCode",r.text||""),!0)}}));v(bt.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});v(bt.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Fr=V("ToggleInlineCode",e=>()=>(t,n)=>{const{selection:r,tr:o}=t;if(r.empty)return!1;const{from:s,to:a}=r;return t.doc.rangeHasMark(s,a,bt.type(e))?(n?.(o.removeMark(s,a,bt.type(e))),!0):(Object.keys(t.schema.marks).filter(l=>l!==bt.type.name).map(l=>t.schema.marks[l]).forEach(l=>{o.removeMark(s,a,l)}),n?.(o.addMark(s,a,bt.type(e).create())),!0)});v(Fr,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var vs=he(e=>ft(/(?:`)([^`]+)(?:`)$/,bt.type(e)));v(vs,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var Cs=je("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:e=>{const t=e.get(ce);return()=>t.call(Fr.key)}}});v(Cs.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});v(Cs.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var qr=Vn("link");v(qr,{displayName:"Attr<link>",group:"Link"});var et=pt("link",e=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{href:t.getAttribute("href"),title:t.getAttribute("title")}}}],toDOM:t=>["a",{...e.get(qr.key)(t),...t.attrs}],parseMarkdown:{match:t=>t.type==="link",runner:(t,n,r)=>{const o=n.url,s=n.title;t.openMark(r,{href:o,title:s}),t.next(n.children),t.closeMark(r)}},toMarkdown:{match:t=>t.type.name==="link",runner:(t,n)=>{t.withMark(n,"link",void 0,{title:n.attrs.title,url:n.attrs.href})}}}));v(et.mark,{displayName:"MarkSchema<link>",group:"Link"});var nc=V("ToggleLink",e=>(t={})=>Wn(et.type(e),t));v(nc,{displayName:"Command<toggleLinkCommand>",group:"Link"});var rc=V("UpdateLink",e=>(t={})=>(n,r)=>{if(!r)return!1;let o,s=-1;const{selection:a}=n,{from:l,to:i}=a;if(n.doc.nodesBetween(l,l===i?i+1:i,(p,h)=>{if(et.type(e).isInSet(p.marks))return o=p,s=h,!1}),!o)return!1;const c=o.marks.find(({type:p})=>p===et.type(e));if(!c)return!1;const u=s,d=s+o.nodeSize,{tr:f}=n,m=et.type(e).create({...c.attrs,...t});return m?(r(f.removeMark(u,d,c).addMark(u,d,m).setSelection(new q(f.selection.$anchor)).scrollIntoView()),!0):!1});v(rc,{displayName:"Command<updateLinkCommand>",group:"Link"});var Ss=cs("doc",()=>({content:"block+",parseMarkdown:{match:({type:e})=>e==="root",runner:(e,t,n)=>{e.injectRoot(t,n)}},toMarkdown:{match:e=>e.type.name==="doc",runner:(e,t)=>{e.openNode("root"),e.next(t.content)}}}));v(Ss,{displayName:"NodeSchema<doc>",group:"Doc"});function jm(e){return lf(e,t=>t.type==="html"&&["<br />","<br>","<br >","<br/>"].includes(t.value?.trim()),(t,n)=>{if(!n.length)return;const r=n[n.length-1];if(!r)return;const o=r.children.indexOf(t);o!==-1&&r.children.splice(o,1)},!0)}var Wr=Ne("remark-preserve-empty-line",()=>()=>jm);v(Wr.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});v(Wr.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Ur=rt("paragraph");v(Ur,{displayName:"Attr<paragraph>",group:"Paragraph"});var We=De("paragraph",e=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:t=>["p",e.get(Ur.key)(t),0],parseMarkdown:{match:t=>t.type==="paragraph",runner:(t,n,r)=>{t.openNode(r),n.children?t.next(n.children):t.addText(n.value||""),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="paragraph",runner:(t,n)=>{const r=e.get(ie).state?.doc.lastChild;t.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&Hm(e)?t.addNode("html",void 0,"<br />"):tc(t,n),t.closeNode()}}}));function Hm(e){let t=!1;try{e.get(Wr.id),t=!0}catch{t=!1}return t}v(We.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});v(We.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var As=V("TurnIntoText",e=>()=>On(We.type(e)));v(As,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var Ms=je("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:e=>{const t=e.get(ce);return()=>t.call(As.key)}}});v(Ms.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});v(Ms.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var Fm=Array(6).fill(0).map((e,t)=>t+1);function qm(e){return e.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Gn=us(qm,"headingIdGenerator");v(Gn,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Vr=rt("heading");v(Vr,{displayName:"Attr<heading>",group:"Heading"});var ut=De("heading",e=>{const t=e.get(Gn.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Fm.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw dt(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...e.get(Vr.key)(n),id:n.attrs.id||t(n)},0],parseMarkdown:{match:({type:n})=>n==="heading",runner:(n,r,o)=>{const s=r.depth;n.openNode(o,{level:s}),n.next(r.children),n.closeNode()}},toMarkdown:{match:n=>n.type.name==="heading",runner:(n,r)=>{n.openNode("heading",void 0,{depth:r.attrs.level}),tc(n,r),n.closeNode()}}}});v(ut.node,{displayName:"NodeSchema<heading>",group:"Heading"});v(ut.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var oc=he(e=>_i(/^(?<hashes>#+)\s$/,ut.type(e),t=>{const n=t.groups?.hashes?.length||0,{$from:r}=e.get(ie).state.selection,o=r.node();if(o.type.name==="heading"){let s=Number(o.attrs.level)+Number(n);return s>6&&(s=6),{level:s}}return{level:n}}));v(oc,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var At=V("WrapInHeading",e=>t=>(t??=1,t<1?On(We.type(e)):On(ut.type(e),{level:t})));v(At,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var Ns=V("DowngradeHeading",e=>()=>(t,n,r)=>{const{$from:o}=t.selection,s=o.node();if(s.type!==ut.type(e)||!t.selection.empty||o.parentOffset!==0)return!1;const a=s.attrs.level-1;return a?(n?.(t.tr.setNodeMarkup(t.selection.$from.before(),void 0,{...s.attrs,level:a})),!0):On(We.type(e))(t,n,r)});v(Ns,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Es=je("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:e=>{const t=e.get(ce);return()=>t.call(At.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:e=>{const t=e.get(ce);return()=>t.call(At.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:e=>{const t=e.get(ce);return()=>t.call(At.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:e=>{const t=e.get(ce);return()=>t.call(At.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:e=>{const t=e.get(ce);return()=>t.call(At.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:e=>{const t=e.get(ce);return()=>t.call(At.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:e=>{const t=e.get(ce);return()=>t.call(Ns.key)}}});v(Es.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});v(Es.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Gr=rt("blockquote");v(Gr,{displayName:"Attr<blockquote>",group:"Blockquote"});var Rt=De("blockquote",e=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:t=>["blockquote",e.get(Gr.key)(t),0],parseMarkdown:{match:({type:t})=>t==="blockquote",runner:(t,n,r)=>{t.openNode(r).next(n.children).closeNode()}},toMarkdown:{match:t=>t.type.name==="blockquote",runner:(t,n)=>{t.openNode("blockquote").next(n.content).closeNode()}}}));v(Rt.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});v(Rt.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var sc=he(e=>is(/^\s*>\s$/,Rt.type(e)));v(sc,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Ts=V("WrapInBlockquote",e=>()=>ls(Rt.type(e)));v(Ts,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Is=je("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:e=>{const t=e.get(ce);return()=>t.call(Ts.key)}}});v(Is.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});v(Is.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var Rs=rt("codeBlock",()=>({pre:{},code:{}}));v(Rs,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var Jn=De("code_block",e=>({content:"text*",group:"block",marks:"",defining:!0,code:!0,attrs:{language:{default:"",validate:"string"}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{language:t.dataset.language}}}],toDOM:t=>{const n=e.get(Rs.key)(t),r=t.attrs.language,o=r&&r.length>0?{"data-language":r}:void 0;return["pre",{...n.pre,...o},["code",n.code,0]]},parseMarkdown:{match:({type:t})=>t==="code",runner:(t,n,r)=>{const o=n.lang??"",s=n.value;t.openNode(r,{language:o}),s&&t.addText(s),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="code_block",runner:(t,n)=>{t.addNode("code",void 0,n.content.firstChild?.text||"",{lang:n.attrs.language})}}}));v(Jn.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});v(Jn.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var ac=he(e=>_i(/^```(?<language>[a-z]*)?[\s\n]$/,Jn.type(e),t=>({language:t.groups?.language??""})));v(ac,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Ls=V("CreateCodeBlock",e=>(t="")=>On(Jn.type(e),{language:t}));v(Ls,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var Wm=V("UpdateCodeBlockLanguage",()=>({pos:e,language:t}={pos:-1,language:""})=>(n,r)=>e>=0?(r?.(n.tr.setNodeAttribute(e,"language",t)),!0):!1);v(Wm,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var $s=je("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:e=>{const t=e.get(ce);return()=>t.call(Ls.key)}}});v($s.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});v($s.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Ds=rt("image");v(Ds,{displayName:"Attr<image>",group:"Image"});var bn=De("image",e=>({inline:!0,group:"inline",selectable:!0,draggable:!0,marks:"",atom:!0,defining:!0,isolating:!0,attrs:{src:{default:"",validate:"string"},alt:{default:"",validate:"string"},title:{default:"",validate:"string"}},parseDOM:[{tag:"img[src]",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{src:t.getAttribute("src")||"",alt:t.getAttribute("alt")||"",title:t.getAttribute("title")||t.getAttribute("alt")||""}}}],toDOM:t=>["img",{...e.get(Ds.key)(t),...t.attrs}],parseMarkdown:{match:({type:t})=>t==="image",runner:(t,n,r)=>{const o=n.url,s=n.alt,a=n.title;t.addNode(r,{src:o,alt:s,title:a})}},toMarkdown:{match:t=>t.type.name==="image",runner:(t,n)=>{t.addNode("image",void 0,void 0,{title:n.attrs.title,url:n.attrs.src,alt:n.attrs.alt})}}}));v(bn.node,{displayName:"NodeSchema<image>",group:"Image"});v(bn.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var lc=V("InsertImage",e=>(t={})=>(n,r)=>{if(!r)return!0;const{src:o="",alt:s="",title:a=""}=t,l=bn.type(e).create({src:o,alt:s,title:a});return l&&r(n.tr.replaceSelectionWith(l).scrollIntoView()),!0});v(lc,{displayName:"Command<insertImageCommand>",group:"Image"});var ic=V("UpdateImage",e=>(t={})=>(n,r)=>{const o=Mf(n.selection,bn.type(e));if(!o)return!1;const{node:s,pos:a}=o,l={...s.attrs},{src:i,alt:c,title:u}=t;return i!==void 0&&(l.src=i),c!==void 0&&(l.alt=c),u!==void 0&&(l.title=u),r?.(n.tr.setNodeMarkup(a,void 0,l).scrollIntoView()),!0});v(ic,{displayName:"Command<updateImageCommand>",group:"Image"});var Um=he(e=>new nt(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(t,n,r,o)=>{const[s,a,l="",i]=n;return s?t.tr.replaceWith(r,o,bn.type(e).create({src:l,alt:a,title:i})):null}));v(Um,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var Sr=rt("hardbreak",e=>({"data-type":"hardbreak","data-is-inline":e.attrs.isInline}));v(Sr,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var tt=De("hardbreak",e=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:t=>t.attrs.isInline?["span",e.get(Sr.key)(t)," "]:["br",e.get(Sr.key)(t)],parseMarkdown:{match:({type:t})=>t==="break",runner:(t,n,r)=>{t.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>`
|
|
2
|
+
`,toMarkdown:{match:t=>t.type.name==="hardbreak",runner:(t,n)=>{n.attrs.isInline?t.addNode("text",void 0,`
|
|
3
|
+
`):t.addNode("break")}}}));v(tt.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});v(tt.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var _s=V("InsertHardbreak",e=>()=>(t,n)=>{const{selection:r,tr:o}=t;if(!(r instanceof q))return!1;if(r.empty){const s=r.$from.node();if(s.childCount>0&&s.lastChild?.type.name==="hardbreak")return n?.(o.replaceRangeWith(r.to-1,r.to,t.schema.node("paragraph")).setSelection(fe.near(o.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(o.setMeta("hardbreak",!0).replaceSelectionWith(tt.type(e).create()).scrollIntoView()),!0});v(_s,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var zs=je("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:e=>{const t=e.get(ce);return()=>t.call(_s.key)}}});v(zs.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});v(zs.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Os=rt("hr");v(Os,{displayName:"Attr<hr>",group:"Hr"});var Yn=De("hr",e=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:t=>["hr",e.get(Os.key)(t)],parseMarkdown:{match:({type:t})=>t==="thematicBreak",runner:(t,n,r)=>{t.addNode(r)}},toMarkdown:{match:t=>t.type.name==="hr",runner:t=>{t.addNode("thematicBreak")}}}));v(Yn.node,{displayName:"NodeSchema<hr>",group:"Hr"});v(Yn.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var cc=he(e=>new nt(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,o)=>{const{tr:s}=t;return n[0]&&s.replaceWith(r-1,o,Yn.type(e).create()),s}));v(cc,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var uc=V("InsertHr",e=>()=>(t,n)=>{if(!n)return!0;const r=We.node.type(e).create(),{tr:o,selection:s}=t,{from:a}=s,l=Yn.type(e).create();if(!l)return!0;const i=o.replaceSelectionWith(l).insert(a,r),c=fe.findFrom(i.doc.resolve(a),1,!0);return c&&n(i.setSelection(c).scrollIntoView()),!0});v(uc,{displayName:"Command<insertHrCommand>",group:"Hr"});var Jr=rt("bulletList");v(Jr,{displayName:"Attr<bulletList>",group:"BulletList"});var kt=De("bullet_list",e=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{spread:t.dataset.spread==="true"}}}],toDOM:t=>["ul",{...e.get(Jr.key)(t),"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:t,ordered:n})=>t==="list"&&!n,runner:(t,n,r)=>{const o=n.spread!=null?`${n.spread}`:"false";t.openNode(r,{spread:o}).next(n.children).closeNode()}},toMarkdown:{match:t=>t.type.name==="bullet_list",runner:(t,n)=>{t.openNode("list",void 0,{ordered:!1,spread:n.attrs.spread}).next(n.content).closeNode()}}}));v(kt.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});v(kt.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var dc=he(e=>is(/^\s*([-+*])\s$/,kt.type(e)));v(dc,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Ps=V("WrapInBulletList",e=>()=>ls(kt.type(e)));v(Ps,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Bs=je("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:e=>{const t=e.get(ce);return()=>t.call(Ps.key)}}});v(Bs.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});v(Bs.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var Yr=rt("orderedList");v(Yr,{displayName:"Attr<orderedList>",group:"OrderedList"});var wt=De("ordered_list",e=>({content:"listItem+",group:"block",attrs:{order:{default:1,validate:"number"},spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ol",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{spread:t.dataset.spread,order:t.hasAttribute("start")?Number(t.getAttribute("start")):1}}}],toDOM:t=>["ol",{...e.get(Yr.key)(t),...t.attrs.order===1?{}:{start:t.attrs.order},"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:t,ordered:n})=>t==="list"&&!!n,runner:(t,n,r)=>{const o=n.spread!=null?`${n.spread}`:"true";t.openNode(r,{spread:o,order:n.start??1}).next(n.children).closeNode()}},toMarkdown:{match:t=>t.type.name==="ordered_list",runner:(t,n)=>{t.openNode("list",void 0,{ordered:!0,start:n.attrs.order??1,spread:n.attrs.spread==="true"}),t.next(n.content),t.closeNode()}}}));v(wt.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});v(wt.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var fc=he(e=>is(/^\s*(\d+)\.\s$/,wt.type(e),t=>({order:Number(t[1])}),(t,n)=>n.childCount+n.attrs.order===Number(t[1])));v(fc,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Ks=V("WrapInOrderedList",e=>()=>ls(wt.type(e)));v(Ks,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var js=je("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:e=>{const t=e.get(ce);return()=>t.call(Ks.key)}}});v(js.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});v(js.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Hs=rt("listItem");v(Hs,{displayName:"Attr<listItem>",group:"ListItem"});var vt=De("list_item",e=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"•",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:t=>{if(!(t instanceof HTMLElement))throw dt(t);return{label:t.dataset.label,listType:t.dataset.listType,spread:t.dataset.spread==="true"}}}],toDOM:t=>["li",{...e.get(Hs.key)(t),"data-label":t.attrs.label,"data-list-type":t.attrs.listType,"data-spread":t.attrs.spread},0],parseMarkdown:{match:({type:t})=>t==="listItem",runner:(t,n,r)=>{const o=n.label!=null?`${n.label}.`:"•",s=n.label!=null?"ordered":"bullet",a=n.spread!=null?`${n.spread}`:"true";t.openNode(r,{label:o,listType:s,spread:a}),t.next(n.children),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="list_item",runner:(t,n)=>{t.openNode("listItem",void 0,{spread:n.attrs.spread}),t.next(n.content),t.closeNode()}}}));v(vt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});v(vt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Fs=V("SinkListItem",e=>()=>ec(vt.type(e)));v(Fs,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var qs=V("LiftListItem",e=>()=>Zi(vt.type(e)));v(qs,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Ws=V("SplitListItem",e=>()=>zm(vt.type(e)));v(Ws,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Vm(e){return(t,n,r)=>{const{selection:o}=t;if(!(o instanceof q))return!1;const{empty:s,$from:a}=o;return!s||a.parentOffset!==0||a.node(-1).type!==vt.type(e)?!1:Af(t,n,r)}}var Us=V("LiftFirstListItem",e=>()=>Vm(e));v(Us,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Vs=je("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:e=>{const t=e.get(ce);return()=>t.call(Ws.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:e=>{const t=e.get(ce);return()=>t.call(Fs.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:e=>{const t=e.get(ce);return()=>t.call(qs.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:e=>{const t=e.get(ce);return()=>t.call(Us.key)}}});v(Vs.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});v(Vs.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var pc=cs("text",()=>({group:"inline",parseMarkdown:{match:({type:e})=>e==="text",runner:(e,t)=>{e.addText(t.value)}},toMarkdown:{match:e=>e.type.name==="text",runner:(e,t)=>{e.addNode("text",void 0,t.text)}}}));v(pc,{displayName:"NodeSchema<text>",group:"Text"});var Gs=rt("html");v(Gs,{displayName:"Attr<html>",group:"Html"});var Js=De("html",e=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:t=>{const n=document.createElement("span"),r={...e.get(Gs.key)(t),"data-value":t.attrs.value,"data-type":"html"};return n.textContent=t.attrs.value,["span",r,t.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:t=>({value:t.dataset.value??""})}],parseMarkdown:{match:({type:t})=>t==="html",runner:(t,n,r)=>{t.addNode(r,{value:n.value})}},toMarkdown:{match:t=>t.type.name==="html",runner:(t,n)=>{t.addNode("html",void 0,n.attrs.value)}}}));v(Js.node,{displayName:"NodeSchema<html>",group:"Html"});v(Js.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var Gm=[Ss,Ur,We,Gn,Vr,ut,Sr,tt,Gr,Rt,Rs,Jn,Os,Yn,Ds,bn,Jr,kt,Yr,wt,Hs,vt,ms,Dt,ys,gn,xs,bt,qr,et,Gs,Js,pc].flat(),Jm=[sc,dc,fc,ac,cc,oc].flat(),Ym=[hs,gs,vs,ks],Xm=V("IsMarkSelected",()=>e=>t=>{if(!e)return!1;const{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),Qm=V("IsNoteSelected",()=>e=>t=>e?Nf(t,e).hasNode:!1),Zm=V("ClearTextInCurrentBlock",()=>()=>(e,t)=>{let n=e.tr;const{$from:r,$to:o}=n.selection,{pos:s}=r,{pos:a}=o,l=s-r.node().content.size;return l<0?!1:(n=n.deleteRange(l,a),t?.(n),!0)}),eh=V("SetBlockType",()=>e=>(t,n)=>{const{nodeType:r,attrs:o=null}=e??{};if(!r)return!1;const s=t.tr,{from:a,to:l}=s.selection;try{s.setBlockType(a,l,r,o)}catch{return!1}return n?.(s),!0}),th=V("WrapInBlockType",()=>e=>(t,n)=>{const{nodeType:r,attrs:o=null}=e??{};if(!r)return!1;let s=t.tr;try{const{$from:a,$to:l}=s.selection,i=a.blockRange(l),c=i&&Co(i,r,o);if(!c)return!1;s=s.wrap(i,c)}catch{return!1}return n?.(s),!0}),nh=V("AddBlockType",()=>e=>(t,n)=>{const{nodeType:r,attrs:o=null}=e??{};if(!r)return!1;const s=t.tr;try{const a=r instanceof Ef?r:r.createAndFill(o);if(!a)return!1;s.replaceSelectionWith(a)}catch{return!1}return n?.(s),!0}),rh=V("SelectTextNearPos",()=>e=>(t,n)=>{const{pos:r}=e??{};if(r==null)return!1;const o=(a,l,i)=>Math.min(Math.max(a,l),i),s=t.tr;try{const a=t.doc.resolve(o(r,0,t.doc.content.size));s.setSelection(q.near(a))}catch{return!1}return n?.(s.scrollIntoView()),!0}),oh=[As,Ts,At,Ns,Ls,_s,uc,lc,ic,Ks,Ps,Fs,Ws,qs,Us,jr,Fr,Hr,nc,rc,Xm,Qm,Zm,eh,th,nh,rh],sh=[Is,$s,zs,Es,Vs,js,Bs,Ms,bs,Cs,ws].flat(),Xr=Ne("remarkAddOrderInList",()=>()=>e=>{qn(e,"list",t=>{if(t.ordered){const n=t.start??1;t.children.forEach((r,o)=>{r.label=o+n})}})});v(Xr.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});v(Xr.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var Ys=Ne("remarkLineBreak",()=>()=>e=>{const t=/[\t ]*(?:\r?\n|\r)/g;qn(e,"text",(n,r,o)=>{if(!n.value||typeof n.value!="string")return;const s=[];let a=0;t.lastIndex=0;let l=t.exec(n.value);for(;l;){const i=l.index;a!==i&&s.push({type:"text",value:n.value.slice(a,i)}),s.push({type:"break",data:{isInline:!0}}),a=i+l[0].length,l=t.exec(n.value)}if(s.length>0&&o&&typeof r=="number")return a<n.value.length&&s.push({type:"text",value:n.value.slice(a)}),o.children.splice(r,1,...s),r+s.length})});v(Ys.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});v(Ys.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Xs=Ne("remarkInlineLink",()=>Km);v(Xs.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});v(Xs.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var ah=e=>!!e.children,lh=e=>e.type==="html";function ih(e,t){return n(e,0,null)[0];function n(r,o,s){if(ah(r)){const a=[];for(let l=0,i=r.children.length;l<i;l++){const c=r.children[l];if(c){const u=n(c,l,r);if(u)for(let d=0,f=u.length;d<f;d++){const m=u[d];m&&a.push(m)}}}r.children=a}return t(r,o,s)}}var ch=["root","blockquote","listItem"],Qs=Ne("remarkHTMLTransformer",()=>()=>e=>{ih(e,(t,n,r)=>lh(t)?(r&&ch.includes(r.type)&&(t.children=[{...t}],delete t.value,t.type="paragraph"),[t]):[t])});v(Qs.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});v(Qs.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var Zs=Ne("remarkMarker",()=>()=>(e,t)=>{const n=r=>t.value.charAt(r.position.start.offset);qn(e,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});v(Zs.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});v(Zs.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var mc=re(()=>{let e=!1;const t=new se({key:new be("MILKDOWN_INLINE_NODES_CURSOR"),state:{init(){return!1},apply(n){if(!n.selection.empty)return!1;const r=n.selection.$from,o=r.nodeBefore,s=r.nodeAfter;return!!(o&&s&&o.isInline&&!o.isText&&s.isInline&&!s.isText)}},props:{handleDOMEvents:{compositionend:(n,r)=>e?(e=!1,requestAnimationFrame(()=>{if(t.getState(n.state)){const o=n.state.selection.from;r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",o))}}),!0):!1,compositionstart:n=>(t.getState(n.state)&&(e=!0),!1),beforeinput:(n,r)=>{if(t.getState(n.state)&&r instanceof InputEvent&&r.data&&!e){const o=n.state.selection.from;return r.preventDefault(),n.dispatch(n.state.tr.insertText(r.data||"",o)),!0}return!1}},decorations(n){if(t.getState(n)){const r=n.selection.$from.pos,o=document.createElement("span"),s=te.widget(r,o,{side:-1}),a=document.createElement("span"),l=te.widget(r,a);return setTimeout(()=>{o.contentEditable="true",a.contentEditable="true"}),ke.create(n.doc,[s,l])}return ke.empty}}});return t});v(mc,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var ea=re(e=>new se({key:new be("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(t,n,r)=>{if(!t.length)return;const[o]=t;if(!o)return;const[s]=o.steps;if(o.getMeta("hardbreak")){if(!(s instanceof rs))return;const{from:a}=s;return r.tr.setNodeMarkup(a,tt.type(e),void 0,[])}if(s instanceof os){let a=r.tr;const{from:l,to:i}=s;return r.doc.nodesBetween(l,i,(c,u)=>{c.type===tt.type(e)&&(a=a.setNodeMarkup(u,tt.type(e),void 0,[]))}),a}}}));v(ea,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var ta=us(["table","code_block"],"hardbreakFilterNodes");v(ta,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var hc=re(e=>{const t=e.get(ta.key);return new se({key:new be("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(n,r)=>{const o=n.getMeta("hardbreak"),[s]=n.steps;if(o&&s){const{from:a}=s,l=r.doc.resolve(a);let i=l.depth,c=!0;for(;i>0;)t.includes(l.node(i).type.name)&&(c=!1),i--;return c}return!0}})});v(hc,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var gc=re(e=>{const t=new be("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;const o=e.get(Gn.key),s=r.state.tr.setMeta("addToHistory",!1);let a=!1;const l={};r.state.doc.descendants((i,c)=>{if(i.type===ut.type(e)){if(i.textContent.trim().length===0)return;const u=i.attrs;let d=o(i);l[d]?(l[d]+=1,d+=`-#${l[d]}`):l[d]=1,u.id!==d&&(a=!0,s.setMeta(t,!0).setNodeMarkup(c,void 0,{...u,id:d}))}}),a&&r.dispatch(s)};return new se({key:t,view:r=>(n(r),{update:(o,s)=>{o.state.doc.eq(s.doc)||n(o)}})})});v(gc,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var bc=re(e=>{const t=(n,r,o)=>{if(!o.selection||n.some(d=>d.getMeta("addToHistory")===!1||!d.isGeneric))return null;const s=wt.type(e),a=kt.type(e),l=vt.type(e),i=(d,f,m=1)=>{let p=!1;const h=`${f+m}.`;return d.label!==h&&(d.label=h,p=!0),p};let c=o.tr,u=!1;return o.doc.descendants((d,f,m,p)=>{if(d.type===a){const h=d.maybeChild(0);h?.type===l&&h.attrs.listType==="ordered"&&(u=!0,c.setNodeMarkup(f,s,{spread:"true"}),d.descendants((g,y,k,M)=>{if(g.type===l){const E={...g.attrs};i(E,M)&&(c=c.setNodeMarkup(y,void 0,E))}return!1}))}else if(d.type===l&&m?.type===s){const h={...d.attrs};let g=!1;h.listType!=="ordered"&&(h.listType="ordered",g=!0),m?.maybeChild(0)&&(g=i(h,p,m?.attrs.order??1)),g&&(c=c.setNodeMarkup(f,void 0,h),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new se({key:new be("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:t})});v(bc,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var uh=[ea,ta,hc,mc,Xr,Xs,Ys,Qs,Zs,Wr,gc,bc].flat(),dh=[Gm,Jm,Ym,oh,sh,uh].flat();let No,Eo;if(typeof WeakMap<"u"){let e=new WeakMap;No=t=>e.get(t),Eo=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;No=r=>{for(let o=0;o<e.length;o+=2)if(e[o]==r)return e[o+1]},Eo=(r,o)=>(n==10&&(n=0),e[n++]=r,e[n++]=o)}var ne=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const r=t%this.width,o=t/this.width|0;let s=r+1,a=o+1;for(let l=1;s<this.width&&this.map[t+l]==n;l++)s++;for(let l=1;a<this.height&&this.map[t+this.width*l]==n;l++)a++;return{left:r,top:o,right:s,bottom:a}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:r,right:o,top:s,bottom:a}=this.findCell(e);return t=="horiz"?(n<0?r==0:o==this.width)?null:this.map[s*this.width+(n<0?r-1:o)]:(n<0?s==0:a==this.height)?null:this.map[r+this.width*(n<0?s-1:a)]}rectBetween(e,t){const{left:n,right:r,top:o,bottom:s}=this.findCell(e),{left:a,right:l,top:i,bottom:c}=this.findCell(t);return{left:Math.min(n,a),top:Math.min(o,i),right:Math.max(r,l),bottom:Math.max(s,c)}}cellsInRect(e){const t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let o=e.left;o<e.right;o++){const s=r*this.width+o,a=this.map[s];n[a]||(n[a]=!0,!(o==e.left&&o&&this.map[s-1]==a||r==e.top&&r&&this.map[s-this.width]==a)&&t.push(a))}return t}positionAt(e,t,n){for(let r=0,o=0;;r++){const s=o+n.child(r).nodeSize;if(r==e){let a=t+e*this.width;const l=(e+1)*this.width;for(;a<l&&this.map[a]<o;)a++;return a==l?s-1:this.map[a]}o=s}}static get(e){return No(e)||Eo(e,fh(e))}};function fh(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=ph(e),n=e.childCount,r=[];let o=0,s=null;const a=[];for(let c=0,u=t*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){const d=e.child(c);u++;for(let p=0;;p++){for(;o<r.length&&r[o]!=0;)o++;if(p==d.childCount)break;const h=d.child(p),{colspan:g,rowspan:y,colwidth:k}=h.attrs;for(let M=0;M<y;M++){if(M+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:y-M});break}const E=o+M*t;for(let x=0;x<g;x++){r[E+x]==0?r[E+x]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:g-x});const I=k&&k[x];if(I){const R=(E+x)%t*2,D=a[R];D==null||D!=I&&a[R+1]==1?(a[R]=I,a[R+1]=1):D==I&&a[R+1]++}}}o+=g,u+=h.nodeSize}const f=(c+1)*t;let m=0;for(;o<f;)r[o++]==0&&m++;m&&(s||(s=[])).push({type:"missing",row:c,n:m}),u++}(t===0||n===0)&&(s||(s=[])).push({type:"zero_sized"});const l=new ne(t,n,r,s);let i=!1;for(let c=0;!i&&c<a.length;c+=2)a[c]!=null&&a[c+1]<n&&(i=!0);return i&&mh(l,a,e),l}function ph(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){const o=e.child(r);let s=0;if(n)for(let a=0;a<r;a++){const l=e.child(a);for(let i=0;i<l.childCount;i++){const c=l.child(i);a+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let a=0;a<o.childCount;a++){const l=o.child(a);s+=l.attrs.colspan,l.attrs.rowspan>1&&(n=!0)}t==-1?t=s:t!=s&&(t=Math.max(t,s))}return t}function mh(e,t,n){e.problems||(e.problems=[]);const r={};for(let o=0;o<e.map.length;o++){const s=e.map[o];if(r[s])continue;r[s]=!0;const a=n.nodeAt(s);if(!a)throw new RangeError(`No cell with offset ${s} found`);let l=null;const i=a.attrs;for(let c=0;c<i.colspan;c++){const u=t[(o+c)%e.width*2];u!=null&&(!i.colwidth||i.colwidth[c]!=u)&&((l||(l=hh(i)))[c]=u)}l&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function hh(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function dl(e,t){if(typeof e=="string")return{};const n=e.getAttribute("data-colwidth"),r=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(a=>Number(a)):null,o=Number(e.getAttribute("colspan")||1),s={colspan:o,rowspan:Number(e.getAttribute("rowspan")||1),colwidth:r&&r.length==o?r:null};for(const a in t){const l=t[a].getFromDOM,i=l&&l(e);i!=null&&(s[a]=i)}return s}function fl(e,t){const n={};e.attrs.colspan!=1&&(n.colspan=e.attrs.colspan),e.attrs.rowspan!=1&&(n.rowspan=e.attrs.rowspan),e.attrs.colwidth&&(n["data-colwidth"]=e.attrs.colwidth.join(","));for(const r in t){const o=t[r].setDOMAttr;o&&o(e.attrs[r],n)}return n}function gh(e){if(e!==null){if(!Array.isArray(e))throw new TypeError("colwidth must be null or an array");for(const t of e)if(typeof t!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function bh(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:gh}};for(const r in t)n[r]={default:t[r].default,validate:t[r].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:e.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:e.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>dl(r,t)}],toDOM(r){return["td",fl(r,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>dl(r,t)}],toDOM(r){return["th",fl(r,t),0]}}}}function Ye(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const r=e.nodes[n],o=r.spec.tableRole;o&&(t[o]=r)}}return t}const Nt=new be("selectingCells");function Ut(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return e.node(0).resolve(e.before(t+1));return null}function Ue(e){const t=e.selection.$head;for(let n=t.depth;n>0;n--)if(t.node(n).type.spec.tableRole=="row")return!0;return!1}function Xn(e){const t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&t.node.type.spec.tableRole=="cell")return t.$anchor;const n=Ut(t.$head)||yh(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function yh(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const r=t.type.spec.tableRole;if(r=="cell"||r=="header_cell")return e.doc.resolve(n-t.nodeSize)}}function To(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function kh(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function na(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function yc(e,t,n){const r=e.node(-1),o=ne.get(r),s=e.start(-1),a=o.nextCell(e.pos-s,t,n);return a==null?null:e.node(0).resolve(s+a)}function Vt(e,t,n=1){const r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(o=>o>0)||(r.colwidth=null)),r}function wh(e,t,n=1){const r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let o=0;o<n;o++)r.colwidth.splice(t,0,0)}return r}function xh(e,t,n){const r=Ye(t.type.schema).header_cell;for(let o=0;o<e.height;o++)if(t.nodeAt(e.map[n+o*e.width]).type!=r)return!1;return!0}var ge=class gt extends fe{constructor(t,n=t){const r=t.node(-1),o=ne.get(r),s=t.start(-1),a=o.rectBetween(t.pos-s,n.pos-s),l=t.node(0),i=o.cellsInRect(a).filter(u=>u!=n.pos-s);i.unshift(n.pos-s);const c=i.map(u=>{const d=r.nodeAt(u);if(!d)throw new RangeError(`No cell with offset ${u} found`);const f=s+u+1;return new If(l.resolve(f),l.resolve(f+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=t,this.$headCell=n}map(t,n){const r=t.resolve(n.map(this.$anchorCell.pos)),o=t.resolve(n.map(this.$headCell.pos));if(To(r)&&To(o)&&na(r,o)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?gt.rowSelection(r,o):s&&this.isColSelection()?gt.colSelection(r,o):new gt(r,o)}return q.between(r,o)}content(){const t=this.$anchorCell.node(-1),n=ne.get(t),r=this.$anchorCell.start(-1),o=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},a=[];for(let i=o.top;i<o.bottom;i++){const c=[];for(let u=i*n.width+o.left,d=o.left;d<o.right;d++,u++){const f=n.map[u];if(s[f])continue;s[f]=!0;const m=n.findCell(f);let p=t.nodeAt(f);if(!p)throw new RangeError(`No cell with offset ${f} found`);const h=o.left-m.left,g=m.right-o.right;if(h>0||g>0){let y=p.attrs;if(h>0&&(y=Vt(y,0,h)),g>0&&(y=Vt(y,y.colspan-g,g)),m.left<o.left){if(p=p.type.createAndFill(y),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else p=p.type.create(y,p.content)}if(m.top<o.top||m.bottom>o.bottom){const y={...p.attrs,rowspan:Math.min(m.bottom,o.bottom)-Math.max(m.top,o.top)};m.top<o.top?p=p.type.createAndFill(y):p=p.type.create(y,p.content)}c.push(p)}a.push(t.child(i).copy(oe.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?t:a;return new _e(oe.from(l),1,1)}replace(t,n=_e.empty){const r=t.steps.length,o=this.ranges;for(let a=0;a<o.length;a++){const{$from:l,$to:i}=o[a],c=t.mapping.slice(r);t.replace(c.map(l.pos),c.map(i.pos),a?_e.empty:n)}const s=fe.findFrom(t.doc.resolve(t.mapping.slice(r).map(this.to)),-1);s&&t.setSelection(s)}replaceWith(t,n){this.replace(t,new _e(oe.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=ne.get(n),o=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let a=0;a<s.length;a++)t(n.nodeAt(s[a]),o+s[a])}isColSelection(){const t=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(t,n)>0)return!1;const r=t+this.$anchorCell.nodeAfter.attrs.rowspan,o=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,o)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const r=t.node(-1),o=ne.get(r),s=t.start(-1),a=o.findCell(t.pos-s),l=o.findCell(n.pos-s),i=t.node(0);return a.top<=l.top?(a.top>0&&(t=i.resolve(s+o.map[a.left])),l.bottom<o.height&&(n=i.resolve(s+o.map[o.width*(o.height-1)+l.right-1]))):(l.top>0&&(n=i.resolve(s+o.map[l.left])),a.bottom<o.height&&(t=i.resolve(s+o.map[o.width*(o.height-1)+a.right-1]))),new gt(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=ne.get(t),r=this.$anchorCell.start(-1),o=n.colCount(this.$anchorCell.pos-r),s=n.colCount(this.$headCell.pos-r);if(Math.min(o,s)>0)return!1;const a=o+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,l)==n.width}eq(t){return t instanceof gt&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),o=ne.get(r),s=t.start(-1),a=o.findCell(t.pos-s),l=o.findCell(n.pos-s),i=t.node(0);return a.left<=l.left?(a.left>0&&(t=i.resolve(s+o.map[a.top*o.width])),l.right<o.width&&(n=i.resolve(s+o.map[o.width*(l.top+1)-1]))):(l.left>0&&(n=i.resolve(s+o.map[l.top*o.width])),a.right<o.width&&(t=i.resolve(s+o.map[o.width*(a.top+1)-1]))),new gt(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new gt(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new gt(t.resolve(n),t.resolve(r))}getBookmark(){return new vh(this.$anchorCell.pos,this.$headCell.pos)}};ge.prototype.visible=!1;fe.jsonID("cell",ge);var vh=class kc{constructor(t,n){this.anchor=t,this.head=n}map(t){return new kc(t.map(this.anchor),t.map(this.head))}resolve(t){const n=t.resolve(this.anchor),r=t.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&na(n,r)?new ge(n,r):fe.near(r,1)}};function Ch(e){if(!(e.selection instanceof ge))return null;const t=[];return e.selection.forEachCell((n,r)=>{t.push(te.node(r,r+n.nodeSize,{class:"selectedCell"}))}),ke.create(e.doc,t)}function Sh({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,o=e.depth;for(;o>=0&&!(e.after(o+1)<e.end(o));o--,n++);for(let s=t.depth;s>=0&&!(t.before(s+1)>t.start(s));s--,r--);return n==r&&/row|table/.test(e.node(o).type.spec.tableRole)}function Ah({$from:e,$to:t}){let n,r;for(let o=e.depth;o>0;o--){const s=e.node(o);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}for(let o=t.depth;o>0;o--){const s=t.node(o);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return n!==r&&t.parentOffset===0}function Mh(e,t,n){const r=(t||e).selection,o=(t||e).doc;let s,a;if(r instanceof Qe&&(a=r.node.type.spec.tableRole)){if(a=="cell"||a=="header_cell")s=ge.create(o,r.from);else if(a=="row"){const l=o.resolve(r.from+1);s=ge.rowSelection(l,l)}else if(!n){const l=ne.get(r.node),i=r.from+1,c=i+l.map[l.width*l.height-1];s=ge.create(o,i+1,c)}}else r instanceof q&&Sh(r)?s=q.create(o,r.from):r instanceof q&&Ah(r)&&(s=q.create(o,r.$from.start(),r.$from.end()));return s&&(t||(t=e.tr)).setSelection(s),t}const Nh=new be("fix-tables");function wc(e,t,n,r){const o=e.childCount,s=t.childCount;e:for(let a=0,l=0;a<s;a++){const i=t.child(a);for(let c=l,u=Math.min(o,a+3);c<u;c++)if(e.child(c)==i){l=c+1,n+=i.nodeSize;continue e}r(i,n),l<o&&e.child(l).sameMarkup(i)?wc(e.child(l),i,n+1,r):i.nodesBetween(0,i.content.size,r,n+1),n+=i.nodeSize}}function Eh(e,t){let n;const r=(o,s)=>{o.type.spec.tableRole=="table"&&(n=Th(e,o,s,n))};return t?t.doc!=e.doc&&wc(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Th(e,t,n,r){const o=ne.get(t);if(!o.problems)return r;r||(r=e.tr);const s=[];for(let i=0;i<o.height;i++)s.push(0);for(let i=0;i<o.problems.length;i++){const c=o.problems[i];if(c.type=="collision"){const u=t.nodeAt(c.pos);if(!u)continue;const d=u.attrs;for(let f=0;f<d.rowspan;f++)s[c.row+f]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,Vt(d,d.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const u=t.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const u=r.mapping.map(n);r.delete(u,u+t.nodeSize)}}let a,l;for(let i=0;i<s.length;i++)s[i]&&(a==null&&(a=i),l=i);for(let i=0,c=n+1;i<o.height;i++){const u=t.child(i),d=c+u.nodeSize,f=s[i];if(f>0){let m="cell";u.firstChild&&(m=u.firstChild.type.spec.tableRole);const p=[];for(let g=0;g<f;g++){const y=Ye(e.schema)[m].createAndFill();y&&p.push(y)}const h=(i==0||a==i-1)&&l==i?c+1:d-1;r.insert(r.mapping.map(h),p)}c=d}return r.setMeta(Nh,{fixTables:!0})}function xc(e){const t=ne.get(e),n=[],r=t.height,o=t.width;for(let s=0;s<r;s++){const a=[];for(let l=0;l<o;l++){const i=s*o+l,c=t.map[i];if(s>0){const u=i-o;if(c===t.map[u]){a.push(null);continue}}if(l>0){const u=i-1;if(c===t.map[u]){a.push(null);continue}}a.push(e.nodeAt(c))}n.push(a)}return n}function vc(e,t){const n=[],r=ne.get(e),o=r.height,s=r.width;for(let a=0;a<o;a++){const l=e.child(a),i=[];for(let u=0;u<s;u++){const d=t[a][u];if(!d)continue;const f=r.map[a*r.width+u],m=e.nodeAt(f);if(!m)continue;const p=m.type.createChecked(d.attrs,d.content,d.marks);i.push(p)}const c=l.type.createChecked(l.attrs,i,l.marks);n.push(c)}return e.type.createChecked(e.attrs,n,e.marks)}function Cc(e,t,n,r){const o=t[0]>n[0]?-1:1,s=e.splice(t[0],t.length),a=s.length%2===0?1:0;let l;return l=o===-1?n[0]:n[n.length-1]-a,e.splice(l,0,...s),e}function Qn(e){return Ih(t=>t.type.spec.tableRole==="table",e)}function Ih(e,t){for(let n=t.depth;n>=0;n-=1){const r=t.node(n);if(e(r))return{node:r,pos:n===0?0:t.before(n),start:t.start(n),depth:n}}return null}function on(e,t){const n=Qn(t.$from);if(!n)return;const r=ne.get(n.node);if(!(e<0||e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(o=>{const s=n.node.nodeAt(o),a=o+n.start;return{pos:a,start:a+1,node:s,depth:n.depth+2}})}function sn(e,t){const n=Qn(t.$from);if(!n)return;const r=ne.get(n.node);if(!(e<0||e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(o=>{const s=n.node.nodeAt(o),a=o+n.start;return{pos:a,start:a+1,node:s,depth:n.depth+2}})}function pl(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=on(u,e.selection);d&&d.forEach(f=>{const m=f.node.attrs.colspan+u-1;m>=r&&(r=u),m>o&&(o=m)})}for(let u=t;u<=o;u++){const d=on(u,e.selection);d&&d.forEach(f=>{const m=f.node.attrs.colspan+u-1;f.node.attrs.colspan>1&&m>o&&(o=m)})}const s=[];for(let u=r;u<=o;u++){const d=on(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=on(r,e.selection),l=sn(0,e.selection);if(!a||!l)return;const i=e.doc.resolve(a[a.length-1].pos);let c;for(let u=o;u>=r;u--){const d=on(u,e.selection);if(d&&d.length>0){for(let f=l.length-1;f>=0;f--)if(l[f].pos===d[0].pos){c=d[0];break}if(c)break}}if(c)return{$anchor:i,$head:e.doc.resolve(c.pos),indexes:s}}function ml(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=sn(u,e.selection);d&&d.forEach(f=>{const m=f.node.attrs.rowspan+u-1;m>=r&&(r=u),m>o&&(o=m)})}for(let u=t;u<=o;u++){const d=sn(u,e.selection);d&&d.forEach(f=>{const m=f.node.attrs.rowspan+u-1;f.node.attrs.rowspan>1&&m>o&&(o=m)})}const s=[];for(let u=r;u<=o;u++){const d=sn(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=sn(r,e.selection),l=on(0,e.selection);if(!a||!l)return;const i=e.doc.resolve(a[a.length-1].pos);let c;for(let u=o;u>=r;u--){const d=sn(u,e.selection);if(d&&d.length>0){for(let f=l.length-1;f>=0;f--)if(l[f].pos===d[0].pos){c=d[0];break}if(c)break}}if(c)return{$anchor:i,$head:e.doc.resolve(c.pos),indexes:s}}function hl(e){return e[0].map((t,n)=>e.map(r=>r[n]))}function Rh(e){var t,n;const{tr:r,originIndex:o,targetIndex:s,select:a,pos:l}=e,i=Qn(r.doc.resolve(l));if(!i)return!1;const c=(t=pl(r,o))===null||t===void 0?void 0:t.indexes,u=(n=pl(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=Lh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=ne.get(d),m=i.start,p=s,h=f.positionAt(f.height-1,p,d),g=r.doc.resolve(m+h),y=f.positionAt(0,p,d),k=r.doc.resolve(m+y);return r.setSelection(ge.colSelection(g,k)),!0}function Lh(e,t,n,r){let o=hl(xc(e));return o=Cc(o,t,n),o=hl(o),vc(e,o)}function $h(e){var t,n;const{tr:r,originIndex:o,targetIndex:s,select:a,pos:l}=e,i=Qn(r.doc.resolve(l));if(!i)return!1;const c=(t=ml(r,o))===null||t===void 0?void 0:t.indexes,u=(n=ml(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=Dh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=ne.get(d),m=i.start,p=s,h=f.positionAt(p,f.width-1,d),g=r.doc.resolve(m+h),y=f.positionAt(p,0,d),k=r.doc.resolve(m+y);return r.setSelection(ge.rowSelection(g,k)),!0}function Dh(e,t,n,r){let o=xc(e);return o=Cc(o,t,n),vc(e,o)}function _t(e){const t=e.selection,n=Xn(e),r=n.node(-1),o=n.start(-1),s=ne.get(r);return{...t instanceof ge?s.rectBetween(t.$anchorCell.pos-o,t.$headCell.pos-o):s.findCell(n.pos-o),tableStart:o,map:s,table:r}}function ra(e,{map:t,tableStart:n,table:r},o){let s=o>0?-1:0;xh(t,r,o+s)&&(s=o==0||o==t.width?null:0);for(let a=0;a<t.height;a++){const l=a*t.width+o;if(o>0&&o<t.width&&t.map[l-1]==t.map[l]){const i=t.map[l],c=r.nodeAt(i);e.setNodeMarkup(e.mapping.map(n+i),null,wh(c.attrs,o-t.colCount(i))),a+=c.attrs.rowspan-1}else{const i=s==null?Ye(r.type.schema).cell:r.nodeAt(t.map[l+s]).type,c=t.positionAt(a,o,r);e.insert(e.mapping.map(n+c),i.createAndFill())}}return e}function _h(e,t){if(!Ue(e))return!1;if(t){const n=_t(e);t(ra(e.tr,n,n.left))}return!0}function zh(e,t){if(!Ue(e))return!1;if(t){const n=_t(e);t(ra(e.tr,n,n.right))}return!0}function Sc(e,{map:t,table:n,tableStart:r},o){const s=e.mapping.maps.length;for(let a=0;a<t.height;){const l=a*t.width+o,i=t.map[l],c=n.nodeAt(i),u=c.attrs;if(o>0&&t.map[l-1]==i||o<t.width-1&&t.map[l+1]==i)e.setNodeMarkup(e.mapping.slice(s).map(r+i),null,Vt(u,o-t.colCount(i)));else{const d=e.mapping.slice(s).map(r+i);e.delete(d,d+c.nodeSize)}a+=u.rowspan}}function Oh(e,t){if(!Ue(e))return!1;if(t){const n=_t(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let o=n.right-1;Sc(r,n,o),o!=n.left;o--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=ne.get(s)}t(r)}return!0}function Ac(e,{map:t,table:n,tableStart:r},o){let s=0;for(let c=0;c<o;c++)s+=n.child(c).nodeSize;const a=s+n.child(o).nodeSize,l=e.mapping.maps.length;e.delete(s+r,a+r);const i=new Set;for(let c=0,u=o*t.width;c<t.width;c++,u++){const d=t.map[u];if(!i.has(d)){if(i.add(d),o>0&&d==t.map[u-t.width]){const f=n.nodeAt(d).attrs;e.setNodeMarkup(e.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),c+=f.colspan-1}else if(o<t.height&&d==t.map[u+t.width]){const f=n.nodeAt(d),m=f.attrs,p=f.type.create({...m,rowspan:f.attrs.rowspan-1},f.content),h=t.positionAt(o+1,c,n);e.insert(e.mapping.slice(l).map(r+h),p),c+=m.colspan-1}}}}function Ph(e,t){if(!Ue(e))return!1;if(t){const n=_t(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let o=n.bottom-1;Ac(r,n,o),o!=n.top;o--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=ne.get(n.table)}t(r)}return!0}function Bh(e,t){return function(n,r){if(!Ue(n))return!1;const o=Xn(n);if(o.nodeAfter.attrs[e]===t)return!1;if(r){const s=n.tr;n.selection instanceof ge?n.selection.forEachCell((a,l)=>{a.attrs[e]!==t&&s.setNodeMarkup(l,null,{...a.attrs,[e]:t})}):s.setNodeMarkup(o.pos,null,{...o.nodeAfter.attrs,[e]:t}),r(s)}return!0}}function Kh(e){return function(t,n){if(!Ue(t))return!1;if(n){const r=Ye(t.schema),o=_t(t),s=t.tr,a=o.map.cellsInRect(e=="column"?{left:o.left,top:0,right:o.right,bottom:o.map.height}:e=="row"?{left:0,top:o.top,right:o.map.width,bottom:o.bottom}:o),l=a.map(i=>o.table.nodeAt(i));for(let i=0;i<a.length;i++)l[i].type==r.header_cell&&s.setNodeMarkup(o.tableStart+a[i],r.cell,l[i].attrs);if(s.steps.length===0)for(let i=0;i<a.length;i++)s.setNodeMarkup(o.tableStart+a[i],r.header_cell,l[i].attrs);n(s)}return!0}}function gl(e,t,n){const r=t.map.cellsInRect({left:0,top:0,right:e=="row"?t.map.width:1,bottom:e=="column"?t.map.height:1});for(let o=0;o<r.length;o++){const s=t.table.nodeAt(r[o]);if(s&&s.type!==n.header_cell)return!1}return!0}function oa(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?Kh(e):function(n,r){if(!Ue(n))return!1;if(r){const o=Ye(n.schema),s=_t(n),a=n.tr,l=gl("row",s,o),i=gl("column",s,o),c=(e==="column"?l:e==="row"&&i)?1:0,u=e=="column"?{left:0,top:c,right:1,bottom:s.map.height}:e=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,d=e=="column"?i?o.cell:o.header_cell:e=="row"?l?o.cell:o.header_cell:o.cell;s.map.cellsInRect(u).forEach(f=>{const m=f+s.tableStart,p=a.doc.nodeAt(m);p&&a.setNodeMarkup(m,d,p.attrs)}),r(a)}return!0}}oa("row",{useDeprecatedLogic:!0});oa("column",{useDeprecatedLogic:!0});oa("cell",{useDeprecatedLogic:!0});function jh(e,t){if(t<0){const n=e.nodeBefore;if(n)return e.pos-n.nodeSize;for(let r=e.index(-1)-1,o=e.before();r>=0;r--){const s=e.node(-1).child(r),a=s.lastChild;if(a)return o-1-a.nodeSize;o-=s.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const n=e.node(-1);for(let r=e.indexAfter(-1),o=e.after();r<n.childCount;r++){const s=n.child(r);if(s.childCount)return o+1;o+=s.nodeSize}}return null}function sa(e){return function(t,n){if(!Ue(t))return!1;const r=jh(Xn(t),e);if(r==null)return!1;if(n){const o=t.doc.resolve(r);n(t.tr.setSelection(q.between(o,kh(o))).scrollIntoView())}return!0}}function Hh(e,t){const n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function lr(e,t){const n=e.selection;if(!(n instanceof ge))return!1;if(t){const r=e.tr,o=Ye(e.schema).cell.createAndFill().content;n.forEachCell((s,a)=>{s.content.eq(o)||r.replace(r.mapping.map(a+1),r.mapping.map(a+s.nodeSize-1),new _e(o,0,0))}),r.docChanged&&t(r)}return!0}function Fh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return $h({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function qh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return Rh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function Wh(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole=="table");)n--,r--,t=t.child(0).content;const o=t.child(0),s=o.type.spec.tableRole,a=o.type.schema,l=[];if(s=="row")for(let i=0;i<t.childCount;i++){let c=t.child(i).content;const u=i?0:Math.max(0,n-1),d=i<t.childCount-1?0:Math.max(0,r-1);(u||d)&&(c=Io(Ye(a).row,new _e(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(n||r?Io(Ye(a).row,new _e(t,n,r)).content:t);else return null;return Uh(a,l)}function Uh(e,t){const n=[];for(let o=0;o<t.length;o++){const s=t[o];for(let a=s.childCount-1;a>=0;a--){const{rowspan:l,colspan:i}=s.child(a).attrs;for(let c=o;c<o+l;c++)n[c]=(n[c]||0)+i}}let r=0;for(let o=0;o<n.length;o++)r=Math.max(r,n[o]);for(let o=0;o<n.length;o++)if(o>=t.length&&t.push(oe.empty),n[o]<r){const s=Ye(e).cell.createAndFill(),a=[];for(let l=n[o];l<r;l++)a.push(s);t[o]=t[o].append(oe.from(a))}return{height:t.length,width:r,rows:t}}function Io(e,t){const n=e.createAndFill();return new Rf(n).replace(0,n.content.size,t).doc}function Vh({width:e,height:t,rows:n},r,o){if(e!=r){const s=[],a=[];for(let l=0;l<n.length;l++){const i=n[l],c=[];for(let u=s[l]||0,d=0;u<r;d++){let f=i.child(d%i.childCount);u+f.attrs.colspan>r&&(f=f.type.createChecked(Vt(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let m=1;m<f.attrs.rowspan;m++)s[l+m]=(s[l+m]||0)+f.attrs.colspan}a.push(oe.from(c))}n=a,e=r}if(t!=o){const s=[];for(let a=0,l=0;a<o;a++,l++){const i=[],c=n[l%t];for(let u=0;u<c.childCount;u++){let d=c.child(u);a+d.attrs.rowspan>o&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,o-d.attrs.rowspan)},d.content)),i.push(d)}s.push(oe.from(i))}n=s,t=o}return{width:e,height:t,rows:n}}function Gh(e,t,n,r,o,s,a){const l=e.doc.type.schema,i=Ye(l);let c,u;if(o>t.width)for(let d=0,f=0;d<t.height;d++){const m=n.child(d);f+=m.nodeSize;const p=[];let h;m.lastChild==null||m.lastChild.type==i.cell?h=c||(c=i.cell.createAndFill()):h=u||(u=i.header_cell.createAndFill());for(let g=t.width;g<o;g++)p.push(h);e.insert(e.mapping.slice(a).map(f-1+r),p)}if(s>t.height){const d=[];for(let p=0,h=(t.height-1)*t.width;p<Math.max(t.width,o);p++){const g=p>=t.width?!1:n.nodeAt(t.map[h+p]).type==i.header_cell;d.push(g?u||(u=i.header_cell.createAndFill()):c||(c=i.cell.createAndFill()))}const f=i.row.create(null,oe.from(d)),m=[];for(let p=t.height;p<s;p++)m.push(f);e.insert(e.mapping.slice(a).map(r+n.nodeSize-2),m)}return!!(c||u)}function bl(e,t,n,r,o,s,a,l){if(a==0||a==t.height)return!1;let i=!1;for(let c=o;c<s;c++){const u=a*t.width+c,d=t.map[u];if(t.map[u-t.width]==d){i=!0;const f=n.nodeAt(d),{top:m,left:p}=t.findCell(d);e.setNodeMarkup(e.mapping.slice(l).map(d+r),null,{...f.attrs,rowspan:a-m}),e.insert(e.mapping.slice(l).map(t.positionAt(a,p,n)),f.type.createAndFill({...f.attrs,rowspan:m+f.attrs.rowspan-a})),c+=f.attrs.colspan-1}}return i}function yl(e,t,n,r,o,s,a,l){if(a==0||a==t.width)return!1;let i=!1;for(let c=o;c<s;c++){const u=c*t.width+a,d=t.map[u];if(t.map[u-1]==d){i=!0;const f=n.nodeAt(d),m=t.colCount(d),p=e.mapping.slice(l).map(d+r);e.setNodeMarkup(p,null,Vt(f.attrs,a-m,f.attrs.colspan-(a-m))),e.insert(p+f.nodeSize,f.type.createAndFill(Vt(f.attrs,0,a-m))),c+=f.attrs.rowspan-1}}return i}function kl(e,t,n,r,o){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw new Error("No table found");let a=ne.get(s);const{top:l,left:i}=r,c=i+o.width,u=l+o.height,d=e.tr;let f=0;function m(){if(s=n?d.doc.nodeAt(n-1):d.doc,!s)throw new Error("No table found");a=ne.get(s),f=d.mapping.maps.length}Gh(d,a,s,n,c,u,f)&&m(),bl(d,a,s,n,i,c,l,f)&&m(),bl(d,a,s,n,i,c,u,f)&&m(),yl(d,a,s,n,l,u,i,f)&&m(),yl(d,a,s,n,l,u,c,f)&&m();for(let p=l;p<u;p++){const h=a.positionAt(p,i,s),g=a.positionAt(p,c,s);d.replace(d.mapping.slice(f).map(h+n),d.mapping.slice(f).map(g+n),new _e(o.rows[p-l],0,0))}m(),d.setSelection(new ge(d.doc.resolve(n+a.positionAt(l,i,s)),d.doc.resolve(n+a.positionAt(u-1,c-1,s)))),t(d)}const Jh=Tf({ArrowLeft:ir("horiz",-1),ArrowRight:ir("horiz",1),ArrowUp:ir("vert",-1),ArrowDown:ir("vert",1),"Shift-ArrowLeft":cr("horiz",-1),"Shift-ArrowRight":cr("horiz",1),"Shift-ArrowUp":cr("vert",-1),"Shift-ArrowDown":cr("vert",1),Backspace:lr,"Mod-Backspace":lr,Delete:lr,"Mod-Delete":lr});function pr(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function ir(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;if(s instanceof ge)return pr(n,r,fe.near(s.$headCell,t));if(e!="horiz"&&!s.empty)return!1;const a=Mc(o,e,t);if(a==null)return!1;if(e=="horiz")return pr(n,r,fe.near(n.doc.resolve(s.head+t),t));{const l=n.doc.resolve(a),i=yc(l,e,t);let c;return i?c=fe.near(i,1):t<0?c=fe.near(n.doc.resolve(l.before(-1)),-1):c=fe.near(n.doc.resolve(l.after(-1)),1),pr(n,r,c)}}}function cr(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;let a;if(s instanceof ge)a=s;else{const i=Mc(o,e,t);if(i==null)return!1;a=new ge(n.doc.resolve(i))}const l=yc(a.$headCell,e,t);return l?pr(n,r,new ge(a.$anchorCell,l)):!1}}function Yh(e,t){const n=e.state.doc,r=Ut(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new ge(r))),!0):!1}function Xh(e,t,n){if(!Ue(e.state))return!1;let r=Wh(n);const o=e.state.selection;if(o instanceof ge){r||(r={width:1,height:1,rows:[oe.from(Io(Ye(e.state.schema).cell,n))]});const s=o.$anchorCell.node(-1),a=o.$anchorCell.start(-1),l=ne.get(s).rectBetween(o.$anchorCell.pos-a,o.$headCell.pos-a);return r=Vh(r,l.right-l.left,l.bottom-l.top),kl(e.state,e.dispatch,a,l,r),!0}else if(r){const s=Xn(e.state),a=s.start(-1);return kl(e.state,e.dispatch,a,ne.get(s.node(-1)).findCell(s.pos-a),r),!0}else return!1}function Qh(e,t){var n;if(t.button!=0||t.ctrlKey||t.metaKey)return;const r=wl(e,t.target);let o;if(t.shiftKey&&e.state.selection instanceof ge)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&r&&(o=Ut(e.state.selection.$anchor))!=null&&((n=ao(e,t))===null||n===void 0?void 0:n.pos)!=o.pos)s(o,t),t.preventDefault();else if(!r)return;function s(i,c){let u=ao(e,c);const d=Nt.getState(e.state)==null;if(!u||!na(i,u))if(d)u=i;else return;const f=new ge(i,u);if(d||!e.state.selection.eq(f)){const m=e.state.tr.setSelection(f);d&&m.setMeta(Nt,i.pos),e.dispatch(m)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",l),Nt.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(Nt,-1))}function l(i){const c=i,u=Nt.getState(e.state);let d;if(u!=null)d=e.state.doc.resolve(u);else if(wl(e,c.target)!=r&&(d=ao(e,t),!d))return a();d&&s(d,c)}e.root.addEventListener("mouseup",a),e.root.addEventListener("dragstart",a),e.root.addEventListener("mousemove",l)}function Mc(e,t,n){if(!(e.state.selection instanceof q))return null;const{$head:r}=e.state.selection;for(let o=r.depth-1;o>=0;o--){const s=r.node(o);if((n<0?r.index(o):r.indexAfter(o))!=(n<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const a=r.before(o),l=t=="vert"?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(l)?a:null}}return null}function wl(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function ao(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:o}=n;return r>=0&&Ut(e.state.doc.resolve(r))||Ut(e.state.doc.resolve(o))}var Zh=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Ro(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,Ro(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function Ro(e,t,n,r,o,s){let a=0,l=!0,i=t.firstChild;const c=e.firstChild;if(c){for(let d=0,f=0;d<c.childCount;d++){const{colspan:m,colwidth:p}=c.child(d).attrs;for(let h=0;h<m;h++,f++){const g=o==f?s:p&&p[h],y=g?g+"px":"";if(a+=g||r,g||(l=!1),i)i.style.width!=y&&(i.style.width=y),i=i.nextSibling;else{const k=document.createElement("col");k.style.width=y,t.appendChild(k)}}}for(;i;){var u;const d=i.nextSibling;(u=i.parentNode)===null||u===void 0||u.removeChild(i),i=d}l?(n.style.width=a+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=a+"px")}}const qe=new be("tableColumnResizing");function eg({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Zh,lastColumnResizable:o=!0}={}){const s=new se({key:qe,state:{init(a,l){var i;const c=(i=s.spec)===null||i===void 0||(i=i.props)===null||i===void 0?void 0:i.nodeViews,u=Ye(l.schema).table.name;return r&&c&&(c[u]=(d,f)=>new r(d,n,f)),new tg(-1,!1)},apply(a,l){return l.apply(a)}},props:{attributes:a=>{const l=qe.getState(a);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,l)=>{ng(a,l,e,o)},mouseleave:a=>{rg(a)},mousedown:(a,l)=>{og(a,l,t,n)}},decorations:a=>{const l=qe.getState(a);if(l&&l.activeHandle>-1)return cg(a,l.activeHandle)},nodeViews:{}}});return s}var tg=class mr{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(qe);if(r&&r.setHandle!=null)return new mr(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new mr(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return To(t.doc.resolve(o))||(o=-1),new mr(o,n.dragging)}return n}};function ng(e,t,n,r){if(!e.editable)return;const o=qe.getState(e.state);if(o&&!o.dragging){const s=ag(t.target);let a=-1;if(s){const{left:l,right:i}=s.getBoundingClientRect();t.clientX-l<=n?a=xl(e,t,"left",n):i-t.clientX<=n&&(a=xl(e,t,"right",n))}if(a!=o.activeHandle){if(!r&&a!==-1){const l=e.state.doc.resolve(a),i=l.node(-1),c=ne.get(i),u=l.start(-1);if(c.colCount(l.pos-u)+l.nodeAfter.attrs.colspan-1==c.width-1)return}Nc(e,a)}}}function rg(e){if(!e.editable)return;const t=qe.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Nc(e,-1)}function og(e,t,n,r){var o;if(!e.editable)return!1;const s=(o=e.dom.ownerDocument.defaultView)!==null&&o!==void 0?o:window,a=qe.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const l=e.state.doc.nodeAt(a.activeHandle),i=sg(e,a.activeHandle,l.attrs);e.dispatch(e.state.tr.setMeta(qe,{setDragging:{startX:t.clientX,startWidth:i}}));function c(d){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=qe.getState(e.state);f?.dragging&&(lg(e,f.activeHandle,vl(f.dragging,d,n)),e.dispatch(e.state.tr.setMeta(qe,{setDragging:null})))}function u(d){if(!d.which)return c(d);const f=qe.getState(e.state);if(f&&f.dragging){const m=vl(f.dragging,d,n);Cl(e,f.activeHandle,m,r)}}return Cl(e,a.activeHandle,i,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),t.preventDefault(),!0}function sg(e,t,{colspan:n,colwidth:r}){const o=r&&r[r.length-1];if(o)return o;const s=e.domAtPos(t);let a=s.node.childNodes[s.offset].offsetWidth,l=n;if(r)for(let i=0;i<n;i++)r[i]&&(a-=r[i],l--);return a/l}function ag(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function xl(e,t,n,r){const o=n=="right"?-r:r,s=e.posAtCoords({left:t.clientX+o,top:t.clientY});if(!s)return-1;const{pos:a}=s,l=Ut(e.state.doc.resolve(a));if(!l)return-1;if(n=="right")return l.pos;const i=ne.get(l.node(-1)),c=l.start(-1),u=i.map.indexOf(l.pos-c);return u%i.width==0?-1:c+i.map[u-1]}function vl(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Nc(e,t){e.dispatch(e.state.tr.setMeta(qe,{setHandle:t}))}function lg(e,t,n){const r=e.state.doc.resolve(t),o=r.node(-1),s=ne.get(o),a=r.start(-1),l=s.colCount(r.pos-a)+r.nodeAfter.attrs.colspan-1,i=e.state.tr;for(let c=0;c<s.height;c++){const u=c*s.width+l;if(c&&s.map[u]==s.map[u-s.width])continue;const d=s.map[u],f=o.nodeAt(d).attrs,m=f.colspan==1?0:l-s.colCount(d);if(f.colwidth&&f.colwidth[m]==n)continue;const p=f.colwidth?f.colwidth.slice():ig(f.colspan);p[m]=n,i.setNodeMarkup(a+d,null,{...f,colwidth:p})}i.docChanged&&e.dispatch(i)}function Cl(e,t,n,r){const o=e.state.doc.resolve(t),s=o.node(-1),a=o.start(-1),l=ne.get(s).colCount(o.pos-a)+o.nodeAfter.attrs.colspan-1;let i=e.domAtPos(o.start(-1)).node;for(;i&&i.nodeName!="TABLE";)i=i.parentNode;i&&Ro(s,i.firstChild,i,r,l,n)}function ig(e){return Array(e).fill(0)}function cg(e,t){const n=[],r=e.doc.resolve(t),o=r.node(-1);if(!o)return ke.empty;const s=ne.get(o),a=r.start(-1),l=s.colCount(r.pos-a)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const u=l+c*s.width;if((l==s.width-1||s.map[u]!=s.map[u+1])&&(c==0||s.map[u]!=s.map[u-s.width])){var i;const d=s.map[u],f=a+d+o.nodeAt(d).nodeSize-1,m=document.createElement("div");m.className="column-resize-handle",!((i=qe.getState(e))===null||i===void 0)&&i.dragging&&n.push(te.node(a+d,a+d+o.nodeAt(d).nodeSize,{class:"column-resize-dragging"})),n.push(te.widget(f,m))}}return ke.create(e.doc,n)}function ug({allowTableNodeSelection:e=!1}={}){return new se({key:Nt,state:{init(){return null},apply(t,n){const r=t.getMeta(Nt);if(r!=null)return r==-1?null:r;if(n==null||!t.docChanged)return n;const{deleted:o,pos:s}=t.mapping.mapResult(n);return o?null:s}},props:{decorations:Ch,handleDOMEvents:{mousedown:Qh},createSelectionBetween(t){return Nt.getState(t.state)!=null?t.state.selection:null},handleTripleClick:Yh,handleKeyDown:Jh,handlePaste:Xh},appendTransaction(t,n,r){return Mh(r,Eh(r,n),e)}})}var Ar=typeof navigator<"u"?navigator:null,aa=Ar&&Ar.userAgent||"",dg=/Edge\/(\d+)/.exec(aa),fg=/MSIE \d/.exec(aa),pg=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(aa),mg=!!(fg||pg||dg),hg=!mg&&!!Ar&&/Apple Computer/.test(Ar.vendor),Ec=new be("safari-ime-span"),Lo=!1,gg={key:Ec,props:{decorations:bg,handleDOMEvents:{compositionstart:()=>{Lo=!0},compositionend:()=>{Lo=!1}}}};function bg(e){const{$from:t,$to:n,to:r}=e.selection;if(Lo&&t.sameParent(n)){const o=te.widget(r,yg,{ignoreSelection:!0,key:"safari-ime-span"});return ke.create(e.doc,[o])}}function yg(e){const t=e.dom.ownerDocument.createElement("span");return t.className="ProseMirror-safari-ime-span",t}var kg=new se(hg?gg:{key:Ec});function G(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-gfm",...t}}),e}var la=Vn("strike_through");G(la,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var yn=pt("strike_through",e=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:t=>t==="line-through"}],toDOM:t=>["del",e.get(la.key)(t)],parseMarkdown:{match:t=>t.type==="delete",runner:(t,n,r)=>{t.openMark(r),t.next(n.children),t.closeMark(r)}},toMarkdown:{match:t=>t.type.name==="strike_through",runner:(t,n)=>{t.withMark(n,"delete")}}}));G(yn.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});G(yn.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Bn=V("ToggleStrikeThrough",e=>()=>Wn(yn.type(e)));G(Bn,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var ia=he(e=>ft(new RegExp("(?<![\\w:/])(~{1,2})(.+?)\\1(?!\\w|\\/)"),yn.type(e)));G(ia,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var ca=je("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:e=>{const t=e.get(ce);return()=>t.call(Bn.key)}}});G(ca.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});G(ca.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Zn=bh({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:e=>e.style.textAlign||"left",setDOMAttr:(e,t)=>{t.style=`text-align: ${e||"left"}`}}}}),yt=De("table",()=>({...Zn.table,content:"table_header_row table_row+",disableDropCursor:!0,parseMarkdown:{match:e=>e.type==="table",runner:(e,t,n)=>{const r=t.align,o=t.children.map((s,a)=>({...s,align:r,isHeader:a===0}));e.openNode(n),e.next(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="table",runner:(e,t)=>{const n=t.content.firstChild?.content;if(!n)return;const r=[];n.forEach(o=>{r.push(o.attrs.alignment)}),e.openNode("table",void 0,{align:r}),e.next(t.content),e.closeNode()}}}));G(yt.node,{displayName:"NodeSchema<table>",group:"Table"});G(yt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var er=De("table_header_row",()=>({...Zn.table_row,disableDropCursor:!0,content:"(table_header)*",parseDOM:[{tag:"tr[data-is-header]"},{tag:"tr",getAttrs:e=>e instanceof HTMLElement&&e.querySelector("th")?{}:!1}],toDOM(){return["tr",{"data-is-header":!0},0]},parseMarkdown:{match:e=>!!(e.type==="tableRow"&&e.isHeader),runner:(e,t,n)=>{const r=t.align,o=t.children.map((s,a)=>({...s,align:r[a],isHeader:t.isHeader}));e.openNode(n),e.next(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="table_header_row",runner:(e,t)=>{t.content.size!==0&&(e.openNode("tableRow",void 0,{isHeader:!0}),e.next(t.content),e.closeNode())}}}));G(er.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});G(er.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var kn=De("table_row",()=>({...Zn.table_row,disableDropCursor:!0,content:"(table_cell)*",parseMarkdown:{match:e=>e.type==="tableRow",runner:(e,t,n)=>{const r=t.align,o=t.children.map((s,a)=>({...s,align:r[a]}));e.openNode(n),e.next(o),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="table_row",runner:(e,t)=>{t.content.size!==0&&(e.openNode("tableRow"),e.next(t.content),e.closeNode())}}}));G(kn.node,{displayName:"NodeSchema<tableRow>",group:"Table"});G(kn.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var tr=De("table_cell",()=>({...Zn.table_cell,disableDropCursor:!0,parseMarkdown:{match:e=>e.type==="tableCell"&&!e.isHeader,runner:(e,t,n)=>{const r=t.align;e.openNode(n,{alignment:r}).openNode(e.schema.nodes.paragraph).next(t.children).closeNode().closeNode()}},toMarkdown:{match:e=>e.type.name==="table_cell",runner:(e,t)=>{e.openNode("tableCell").next(t.content).closeNode()}}}));G(tr.node,{displayName:"NodeSchema<tableCell>",group:"Table"});G(tr.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var fn=De("table_header",()=>({...Zn.table_header,disableDropCursor:!0,parseMarkdown:{match:e=>e.type==="tableCell"&&!!e.isHeader,runner:(e,t,n)=>{const r=t.align;e.openNode(n,{alignment:r}),e.openNode(e.schema.nodes.paragraph),e.next(t.children),e.closeNode(),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="table_header",runner:(e,t)=>{e.openNode("tableCell"),e.next(t.content),e.closeNode()}}}));G(fn.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});G(fn.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function Tc(e,t=3,n=3){const r=Array(n).fill(0).map(()=>tr.type(e).createAndFill()),o=Array(n).fill(0).map(()=>fn.type(e).createAndFill()),s=Array(t).fill(0).map((a,l)=>l===0?er.type(e).create(null,o):kn.type(e).create(null,r));return yt.type(e).create(null,s)}function Ic(e){return(t,n)=>r=>{n=n??r.selection.from;const o=r.doc.resolve(n),s=$f(i=>i.type.name==="table")(o),a=s?{node:s.node,from:s.start}:void 0,l=e==="row";if(a){const i=ne.get(a.node);if(t>=0&&t<(l?i.height:i.width)){const c=i.positionAt(l?t:i.height-1,l?i.width-1:t,a.node),u=r.doc.resolve(a.from+c),d=l?ge.rowSelection:ge.colSelection,f=i.positionAt(l?t:0,l?0:t,a.node),m=r.doc.resolve(a.from+f);return zi(r.setSelection(d(u,m)))}}return r}}var wg=Ic("row"),xg=Ic("col");function Rc(e,t,{map:n,tableStart:r,table:o},s){const a=Array(s).fill(0).reduce((i,c,u)=>i+o.child(u).nodeSize,r),l=Array(n.width).fill(0).map((i,c)=>{const u=o.nodeAt(n.map[c]);return tr.type(e).createAndFill({alignment:u?.attrs.alignment})});return t.insert(a,kn.type(e).create(null,l)),t}function vg(e){const t=Qn(e.$from);if(!t)return;const n=ne.get(t.node);return n.cellsInRect({left:0,right:n.width,top:0,bottom:n.height}).map(r=>{const o=t.node.nodeAt(r),s=r+t.start;return{pos:s,start:s+1,node:o}})}function Cg(e){const t=vg(e.selection);if(t&&t[0]){const n=e.doc.resolve(t[0].pos),r=t[t.length-1];if(r){const o=e.doc.resolve(r.pos);return zi(e.setSelection(new ge(o,n)))}}return e}var ua=V("GoToPrevTableCell",()=>()=>sa(-1));G(ua,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var da=V("GoToNextTableCell",()=>()=>sa(1));G(da,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var fa=V("ExitTable",e=>()=>(t,n)=>{if(!Ue(t))return!1;const{$head:r}=t.selection,o=Lf(r,yt.type(e));if(!o)return!1;const{to:s}=o,a=t.tr.replaceWith(s,s,We.type(e).createAndFill());return a.setSelection(fe.near(a.doc.resolve(s),1)).scrollIntoView(),n?.(a),!0});G(fa,{displayName:"Command<breakTableCommand>",group:"Table"});var Lc=V("InsertTable",e=>({row:t,col:n}={})=>(r,o)=>{const{selection:s,tr:a}=r,{from:l}=s,i=Tc(e,t,n),c=a.replaceSelectionWith(i),u=fe.findFrom(c.doc.resolve(l),1,!0);return u&&c.setSelection(u),o?.(c),!0});G(Lc,{displayName:"Command<insertTableCommand>",group:"Table"});var $c=V("MoveRow",()=>({from:e,to:t,pos:n}={})=>Fh({from:e??0,to:t??0,pos:n}));G($c,{displayName:"Command<moveRowCommand>",group:"Table"});var Dc=V("MoveCol",()=>({from:e,to:t,pos:n}={})=>qh({from:e??0,to:t??0,pos:n}));G(Dc,{displayName:"Command<moveColCommand>",group:"Table"});var _c=V("SelectRow",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(wg(e.index,e.pos)(r))});G(_c,{displayName:"Command<selectRowCommand>",group:"Table"});var zc=V("SelectCol",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(xg(e.index,e.pos)(r))});G(zc,{displayName:"Command<selectColCommand>",group:"Table"});var Oc=V("SelectTable",()=>()=>(e,t)=>{const{tr:n}=e;return!!t?.(Cg(n))});G(Oc,{displayName:"Command<selectTableCommand>",group:"Table"});var Pc=V("DeleteSelectedCells",()=>()=>(e,t)=>{const{selection:n}=e;if(!(n instanceof ge))return!1;const r=n.isRowSelection(),o=n.isColSelection();return r&&o?Hh(e,t):o?Oh(e,t):Ph(e,t)});G(Pc,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var Bc=V("AddColBefore",()=>()=>_h);G(Bc,{displayName:"Command<addColBeforeCommand>",group:"Table"});var Kc=V("AddColAfter",()=>()=>zh);G(Kc,{displayName:"Command<addColAfterCommand>",group:"Table"});var jc=V("AddRowBefore",e=>()=>(t,n)=>{if(!Ue(t))return!1;if(n){const r=_t(t);n(Rc(e,t.tr,r,r.top))}return!0});G(jc,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var Hc=V("AddRowAfter",e=>()=>(t,n)=>{if(!Ue(t))return!1;if(n){const r=_t(t);n(Rc(e,t.tr,r,r.bottom))}return!0});G(Hc,{displayName:"Command<addRowAfterCommand>",group:"Table"});var Fc=V("SetAlign",()=>(e="left")=>Bh("alignment",e));G(Fc,{displayName:"Command<setAlignCommand>",group:"Table"});var qc=he(e=>new nt(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,(t,n,r,o)=>{const s=t.doc.resolve(r);if(!s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),yt.type(e)))return null;const a=Tc(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),l=t.tr.replaceRangeWith(r,o,a);return l.setSelection(q.create(l.doc,r+3)).scrollIntoView()}));G(qc,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var Wc=tm(e=>({run:(t,n,r)=>{if(r)return t;function o(c){const u=c.childCount,d=c.lastChild?.childCount??0;if(u===0||d===0)return We.type(e).create();const f=c.firstChild;if(!(d>0&&f&&f.childCount===0))return c;if(u>=3){const g=c.child(1),y=[];for(let E=0;E<g.childCount;E++){const x=g.child(E);y.push(fn.type(e).create(x.attrs,x.content,x.marks))}const k=f.type.create(f.attrs,y),M=[];for(let E=2;E<u;E++)M.push(c.child(E));return c.type.create(c.attrs,[k,...M])}const m=Array(d).fill(0).map(()=>fn.type(e).createAndFill()),p=new _e(oe.from(m),0,0),h=f.replace(0,0,p);return c.replace(0,f.nodeSize,new _e(oe.from(h),0,0))}function s(c){const u=kn.type(e),d=[];let f=[],m=!1;function p(){if(f.length===0)return;const h=er.type(e).createAndFill(),g=yt.type(e).create(null,[h,...f]);d.push(o(g)),f=[]}return c.forEach(h=>{h.type===u?(m=!0,f.push(h)):(p(),d.push(h))}),p(),m?oe.from(d):c}function a(c){let u=s(c),d=u!==c;const f=[];return u.forEach(m=>{if(m.type===yt.type(e)){const p=o(m);p!==m&&(d=!0),f.push(p)}else if(m.childCount>0){const p=a(m.content);p!==m.content?(d=!0,f.push(m.copy(p))):f.push(m)}else f.push(m)}),d?oe.from(f):c}function l(c){const u=[],d=[];c.forEach(f=>d.push(f));for(let f=0;f<d.length;f++){const m=d[f],p=d[f+1];m.type===We.type(e)&&m.content.size===0&&p&&p.type===yt.type(e)||u.push(m)}return u.length<d.length?oe.from(u):c}let i=a(t.content);return i=l(i),new _e(oe.from(i),t.openStart,t.openEnd)}}));G(Wc,{displayName:"PasteRule<table>",group:"Table"});var pa=je("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:e=>{const t=e.get(ce);return()=>t.call(da.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:e=>{const t=e.get(ce);return()=>t.call(ua.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:e=>{const t=e.get(ce);return()=>t.call(fa.key)}}});G(pa.ctx,{displayName:"KeymapCtx<table>",group:"Table"});G(pa.shortcuts,{displayName:"Keymap<table>",group:"Table"});var lo="footnote_definition",Sl="footnoteDefinition",ma=De("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${lo}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw dt(e);return{label:e.dataset.label}},contentElement:"dd"}],toDOM:e=>{const t=e.attrs.label;return["dl",{"data-label":t,"data-type":lo},["dt",t],["dd",0]]},parseMarkdown:{match:({type:e})=>e===Sl,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===lo,runner:(e,t)=>{e.openNode(Sl,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));G(ma.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});G(ma.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var io="footnote_reference",ha=De("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${io}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw dt(e);return{label:e.dataset.label}}}],toDOM:e=>{const t=e.attrs.label;return["sup",{"data-label":t,"data-type":io},t]},parseMarkdown:{match:({type:e})=>e==="footnoteReference",runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===io,runner:(e,t)=>{e.addNode("footnoteReference",void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));G(ha.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});G(ha.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var ga=vt.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs,checked:{default:null,validate:"boolean|null"}},parseDOM:[{tag:'li[data-item-type="task"]',getAttrs:r=>{if(!(r instanceof HTMLElement))throw dt(r);return{label:r.dataset.label,listType:r.dataset.listType,spread:r.dataset.spread,checked:r.dataset.checked?r.dataset.checked==="true":null}}},...n?.parseDOM||[]],toDOM:r=>n.toDOM&&r.attrs.checked==null?n.toDOM(r):["li",{"data-item-type":"task","data-label":r.attrs.label,"data-list-type":r.attrs.listType,"data-spread":r.attrs.spread,"data-checked":r.attrs.checked},0],parseMarkdown:{match:({type:r})=>r==="listItem",runner:(r,o,s)=>{if(o.checked==null){n.parseMarkdown.runner(r,o,s);return}const a=o.label!=null?`${o.label}.`:"•",l=o.checked!=null?!!o.checked:null,i=o.label!=null?"ordered":"bullet",c=o.spread!=null?`${o.spread}`:"true";r.openNode(s,{label:a,listType:i,spread:c,checked:l}),r.next(o.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="list_item",runner:(r,o)=>{if(o.attrs.checked==null){n.toMarkdown.runner(r,o);return}const s=o.attrs.label,a=o.attrs.listType,l=o.attrs.spread==="true",i=o.attrs.checked;r.openNode("listItem",void 0,{label:s,listType:a,spread:l,checked:i}),r.next(o.content),r.closeNode()}}}});G(ga.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});G(ga.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var Uc=he(()=>new nt(/^\[(?<checked>\s|x)\]\s$/,(e,t,n,r)=>{const o=e.doc.resolve(n);let s=0,a=o.node(s);for(;a&&a.type.name!=="list_item";)s--,a=o.node(s);if(!a||a.attrs.checked!=null)return null;const l=t.groups?.checked==="x",i=o.before(s),c=e.tr;return c.deleteRange(n,r).setNodeMarkup(i,void 0,{...a.attrs,checked:l}),c}));G(Uc,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var Sg=[ca,pa].flat(),Ag=[qc,Uc],Mg=[ia],Ng=[Wc],Vc=re(()=>kg);G(Vc,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var Eg=re(()=>eg({}));G(Eg,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var Gc=re(()=>ug({allowTableNodeSelection:!0}));G(Gc,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var Gt=Ne("remarkGFM",()=>Zo);G(Gt.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});G(Gt.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var Tg=new be("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function Ig(e,t){let n=0;return t.forEach((r,o,s)=>{r===e&&(n=s)}),n}var Jc=re(()=>new se({key:Tg,appendTransaction:(e,t,n)=>{let r;const o=(s,a)=>{if(r||(r=n.tr),s.type.name!=="table_cell")return;const l=n.doc.resolve(a),i=l.node(l.depth),c=l.node(l.depth-1).firstChild;if(!c)return;const u=Ig(s,i),d=c.maybeChild(u);if(!d)return;const f=d.attrs.alignment;f!==s.attrs.alignment&&r.setNodeMarkup(a,void 0,{...s.attrs,alignment:f})};return t.doc!==n.doc&&n.doc.descendants(o),r}}));G(Jc,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var Rg=[Jc,Vc,Gt,Gc].flat(),Lg=[ga,yt,er,kn,fn,tr,ma,ha,la,yn].flat(),$g=[da,ua,fa,Lc,$c,Dc,_c,zc,Oc,Pc,jc,Hc,Bc,Kc,Fc,Bn],Dg=[Lg,Ag,Ng,Mg,Sg,$g,Rg].flat();function _g(e,t,n,r){const o=e.value;if(/^[^*_\\]*\s+$/.test(o)){const s=o.replace(/\s+$/,"");if(!s)return o;const a=o.slice(s.length),l=n.safe(s,{...r,after:a[0],encode:[]});return l===s?o:l+a}return n.safe(o,{...r,encode:[]})}const zg=1,Og=2,$o=e=>`&#x${e.toString(16).toUpperCase()};`,ba=e=>e>=55296&&e<=57343,Mr=e=>!Number.isNaN(e)&&!ba(e)&&Mi(e)&&es(e)===void 0;function Al(e,t,n){return t===126||t===95?!0:t===42?_o(e,n)!=="punct":!1}function Ml(e,t){const n=es(t);return n===zg?{inside:!0,outside:Mr(e)}:n===Og?{inside:!1,outside:Mr(e)}:{inside:!1,outside:!1}}const Yc=/(?:https?:\/\/|www\.)[^\s<]*$/i,Xc=/^(?:https?:\/\/|www\.)/i,Qc=(e,t,n)=>e?.children?.[t.indexStack[t.indexStack.length-1]+n],Zc=(e,t)=>{const n=Qc(e,t,-1);return n?.type==="text"&&(n.value.charAt(n.value.length-2)==="\\"||Yc.test(n.value))},eu=(e,t)=>{const n=Qc(e,t,1);return n?.type==="text"&&Xc.test(n.value)},ya=new Set(["delete","strong","emphasis"]),pn=e=>Array.isArray(e?.children)&&e.children.every(t=>t.type==="text"?!t.value:ya.has(t.type)&&pn(t));let Jt=!1;function Pg(e){Jt=!0;try{return e()}finally{Jt=!1}}const Nl={inside:!1,outside:!1},tu=(e,t,n,r)=>{if(pn(e))return"";const o=n.createTracker(r),s=n.enter("strikethrough"),a=o.move("~~");let l=o.move(n.containerPhrasing(e,{...o.current(),before:a,after:"~"}));const i=l.charCodeAt(0),c=Jt?Nl:Ml(r.before.charCodeAt(r.before.length-1),i);c.inside&&(l=$o(i)+l.slice(1));const u=l.charCodeAt(l.length-1),d=Jt?Nl:Ml(r.after.charCodeAt(0),u);d.inside&&(l=l.slice(0,-1)+$o(u));const f=o.move("~~");return s(),n.attentionEncodeSurroundingInfo={after:d.outside&&!eu(t,n),before:c.outside&&!Zc(t,n)},a+l+f};tu.peek=e=>pn(e)?"":"~";function nu(e){const t=(n,r,o,s)=>{if(pn(n))return"";const a=e(n,r,o,s),l=o.attentionEncodeSurroundingInfo;if(l){const i=n.type==="strong"?2:1,c=a.charCodeAt(i),u=a.charCodeAt(a.length-i-1);l.before&&(Jt||Al(n,c,!1)||Zc(r,o)||!Mr(s.before.charCodeAt(s.before.length-1)))&&(l.before=!1),l.after&&(Jt||Al(n,u,!0)||eu(r,o)||!Mr(s.after.charCodeAt(0)))&&(l.after=!1)}return a};return t.peek=(n,r,o)=>pn(n)?"":e.peek(n,r,o),t}const Bg=nu(dn.strong),Kg=nu(dn.emphasis);function jg(e){const t=[];for(const n of e.children){const r=t[t.length-1];r&&ya.has(n.type)&&n.type===r.type?r.children=[...r.children,...n.children]:t.push(n)}return t}const Do=new Set(["strong","emphasis"]),ru=e=>e.type==="text"?!e.value:ya.has(e.type)&&pn(e);function ou(e,t){let n=e;for(;;){const r=n.children??[];let o=t?r.length-1:0;for(;o>=0&&o<r.length&&ru(r[o]);)o+=t?-1:1;if(o<0||o>=r.length)return null;if(!Do.has(r[o].type))return{host:n,index:o};n=r[o]}}function _o(e,t){const n=ou(e,t);if(!n)return"ok";const r=n.host.children[n.index];if(r.type==="delete"||r.type==="break")return"ok";if(r.type!=="text")return"punct";const o=r.value,s=t?o.charCodeAt(o.length-1):o.charCodeAt(0);if(t&&(s===42||s===95||s===126))return"ok";if(es(s)!==void 0)return"punct";const a=t?o.codePointAt(o.length-(o.length>1&&ba(s)?2:1)):o.codePointAt(0);return!Mi(a)||(t?Yc.test(o):Xc.test(o))?"ok":"letter"}function El(e,t){const n=ou(e,t);if(!n)return!1;const r=n.host.children,o=r[n.index].value,s=t?o.length-(o.length>1&&ba(o.charCodeAt(o.length-1))?2:1):0,a=o.codePointAt(s),l=[{type:"text",value:o.slice(0,s)},{type:zo,value:$o(a)},{type:"text",value:o.slice(s+(a>65535?2:1))}];return r.splice(n.index,1,...l.filter(i=>i.type===zo||i.value)),!0}const zo="amadeusCharRef",su=e=>e.value;su.peek=()=>"&";function au(e){if(Array.isArray(e?.children)){e.children=jg(e);for(let t=!Jt;t;){t=!1;const n=e.children.filter(r=>!ru(r));for(let r=1;r<n.length;r++){const[o,s]=[n[r-1],n[r]];if(!Do.has(o.type)||!Do.has(s.type))continue;const a=_o(o,!0),l=_o(s,!1);if(a==="letter"&&l==="punct"?t=El(o,!0):a==="punct"&&l==="letter"&&(t=El(s,!1)),t)break}}for(const t of e.children)au(t)}}const Hg=(e,t,n,r)=>(au(e),dn.root(e,t,n,r)),Fg=_g,qg={root:Hg,text:Fg,delete:tu,strong:Bg,emphasis:Kg,[zo]:su},Wg=Un(e=>{e.update(Qt,t=>({...t,handlers:{...t.handlers,...qg}}))});function Ug(){Df.call(this),_f.call(this,{singleTilde:!1})}const Vg=Ne("amadeusCjkFriendly",()=>Ug),Kn="amadeusU",jn="amadeusFg",Hn="amadeusBg",ka="amadeusKbd",wa="amadeusSub",xa="amadeusSup",va=new Map([["kbd",ka],["sub",wa],["sup",xa]]),Nr=e=>/^(#[0-9a-fA-F]{3,8}|rgba?\([\d.,%\s/]+\)|hsla?\([\d.,%\s/]+\)|[a-zA-Z]+|var\(--[\w-]+\))$/.test(e.trim());function lu(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<u>$/i.test(t))return{type:Kn};const n=/^<([a-z]+)>$/.exec(t),r=n&&va.get(n[1]);if(r)return{type:r};let o=t.match(/^<span\s+style\s*=\s*"(?:[^"]*;\s*)?color\s*:\s*([^;"]+)[^"]*"\s*>$/i);if(o){const s=o[1].trim();return Nr(s)?{type:jn,color:s}:null}if(o=t.match(/^<mark(?:\s+style\s*=\s*"(?:[^"]*;\s*)?background\s*:\s*([^;"]+)[^"]*")?\s*>$/i),o){const s=(o[1]??"").trim();return s&&!Nr(s)?null:{type:Hn,bg:s}}return null}function iu(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<\/u>$/i.test(t))return Kn;if(/^<\/span>$/i.test(t))return jn;if(/^<\/mark>$/i.test(t))return Hn;const n=/^<\/([a-z]+)>$/.exec(t);return n&&va.get(n[1])||null}const Gg=16,Tl=new Set(va.values()),Jg=new Set(["paragraph","heading","tableCell"]);function Yg(e){const t=new Map,n=new Set,r=o=>{for(const s of o){const a=lu(s)?.type;if(a&&Tl.has(a)){const i=(t.get(a)??0)+1;t.set(a,i),i>1&&n.add(a);continue}const l=iu(s);if(l&&Tl.has(l)){t.set(l,Math.max(0,(t.get(l)??0)-1));continue}Array.isArray(s?.children)&&r(s.children)}};return r(e),n}function cu(e,t=new Set){const n=[],r=[{tgt:n,type:null,kind:"real",raw:null,node:null}],o=()=>r[r.length-1];for(const s of e){const a=lu(s),l=a&&!t.has(a.type)?a:null,i=iu(s),c=i&&!t.has(i)?i:null;if(l){const u=r.length-1,d=r.some(f=>f.kind==="real"&&f.type===l.type);if(u>=Gg)o().tgt.push(s),r.push({tgt:o().tgt,type:l.type,kind:"literal",raw:s,node:null});else if(d)r.push({tgt:o().tgt,type:l.type,kind:"phantom",raw:s,node:null});else{const f={...l,children:[]};o().tgt.push(f),r.push({tgt:f.children,type:l.type,kind:"real",raw:s,node:f})}}else if(c&&r.length>1&&o().type===c)r.pop().kind==="literal"&&o().tgt.push(s);else{if(Array.isArray(s?.children)){const u=Jg.has(s.type)?new Set([...t,...Yg(s.children)]):t;s.children=cu(s.children,u)}o().tgt.push(s)}}for(;r.length>1;){const s=r.pop();if(s.kind==="real"){const a=o().tgt,l=a.indexOf(s.node);l>=0&&a.splice(l,1,s.raw,...s.node.children)}}return n}function tn(e,t){const n=(r,o,s,a)=>{const l=s.createTracker(a),i=s.enter("emphasis");let c=l.move(e(r));return c+=s.containerPhrasing(r,{...a,before:">",after:"<"}),c+=l.move(t),i(),c};return n.peek=()=>"<",n}function Xg(){const e=this.data();return(e.toMarkdownExtensions||=[]).push({handlers:{[Kn]:tn(()=>"<u>","</u>"),[jn]:tn(n=>`<span style="color:${n.color}">`,"</span>"),[Hn]:tn(n=>n.bg?`<mark style="background:${n.bg}">`:"<mark>","</mark>"),[ka]:tn(()=>"<kbd>","</kbd>"),[wa]:tn(()=>"<sub>","</sub>"),[xa]:tn(()=>"<sup>","</sup>")}}),n=>{Array.isArray(n?.children)&&(n.children=cu(n.children))}}const Qg=Ne("amadeusInlineHtmlMarks",()=>Xg),uu=pt("amadeusUnderline",()=>({parseDOM:[{tag:"u"}],toDOM:()=>["u",0],parseMarkdown:{match:e=>e.type===Kn,runner:(e,t,n)=>{e.openMark(n),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="amadeusUnderline",runner:(e,t)=>{e.withMark(t,Kn)}}}));function Ca(e,t,n){return pt(e,()=>({parseDOM:[{tag:t}],toDOM:()=>[t,0],parseMarkdown:{match:r=>r.type===n,runner:(r,o,s)=>{r.openMark(s),r.next(o.children),r.closeMark(s)}},toMarkdown:{match:r=>r.type.name===e,runner:(r,o)=>{r.withMark(o,n)}}}))}const Zg=Ca("amadeusKbd","kbd",ka),eb=Ca("amadeusSub","sub",wa),tb=Ca("amadeusSup","sup",xa),Sa={"#c62222":"red","#b9450a":"orange","#8f6203":"yellow","#117b38":"green","#06748f":"teal","#2159d3":"blue","#842ed3":"purple","#941555":"magenta","#6a6a6a":"grey","#d34f0b":"orange","#b67c04":"yellow","#149343":"green","#0782a0":"teal","#7a7a7a":"grey","#ca4c0b":"orange","#9e6b03":"yellow","#12873e":"green","#077f9d":"teal","#757575":"grey","#c83030":"red","#db7123":"orange","#ac7400":"yellow","#225c18":"green","#0e4841":"teal","#003c67":"blue","#7c3aed":"purple","#e03131":"red","#e8590c":"orange","#f08c00":"yellow","#2f9e44":"green","#0c8599":"teal","#1971c2":"blue","#9c36b5":"purple","#868e96":"grey"},Aa={"#fed5d5":"red","#fedfbb":"orange","#fef3a1":"yellow","#e1fab1":"green","#adf8e9":"teal","#cce2fe":"blue","#edddff":"purple","#ffcece":"magenta","#eaecef":"grey","#fce5e6":"red","#ffebd5":"orange","#fff9b6":"yellow","#f0fccb":"green","#c7f8f2":"teal","#daf0ff":"blue","#ede9ff":"purple","#ffecf6":"magenta","#e6e6e6":"grey","#ffe3e3":"red","#ffe8cc":"orange","#fff3bf":"yellow","#d3f9d8":"green","#c5f6fa":"teal","#d0ebff":"blue","#f3d9fa":"purple","#e9ecef":"grey"};function du(e){const t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(t);if(n)return"#"+(n[1].length===3?[...n[1]].map(s=>s+s).join(""):n[1]);const r=/^rgba?\(\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})\s*(?:[,/]\s*([\d.]+)(%?)\s*)?\)$/.exec(t);if(!r||r[4]!==void 0&&Number(r[4])!==(r[5]?100:1))return null;const o=[r[1],r[2],r[3]].map(Number);return o.some(s=>s>255)?null:"#"+o.map(s=>s.toString(16).padStart(2,"0")).join("")}const fu=e=>{const t={};for(const[n,r]of Object.entries(e))r in t||(t[r]=n);return t},nb=fu(Sa),rb=fu(Aa),pu=(e,t,n,r)=>{const o=du(r);return o&&e[o]&&(!n||e[o]===n)?o:n&&t[n]?t[n]:null};function ob(e){const t=e.getAttribute("data-amx-fg");if(t&&Nr(t))return{color:t};if(!e.style.color)return!1;const n=pu(Sa,nb,e.getAttribute("data-hlc"),e.style.color);return n?{color:n}:!1}function sb(e){const t=e.getAttribute("data-amx-bg");return t!==null&&(t===""||Nr(t))?{bg:t}:{bg:pu(Aa,rb,e.getAttribute("data-hl"),e.style.backgroundColor)??""}}const mu=(e,t)=>e[du(t)??t.toLowerCase()],Oo=pt("amadeusColor",()=>({attrs:{color:{default:""}},parseDOM:[{tag:'span[style*="color"]',getAttrs:e=>ob(e)}],toDOM:e=>{const t=String(e.attrs.color),n=mu(Sa,t);return["span",{style:`color:${t}`,"data-amx-fg":t,...n?{"data-hlc":n}:{}},0]},parseMarkdown:{match:e=>e.type===jn,runner:(e,t,n)=>{e.openMark(n,{color:t.color}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="amadeusColor",runner:(e,t)=>{e.withMark(t,jn,void 0,{color:t.attrs.color})}}})),Po=pt("amadeusBg",()=>({attrs:{bg:{default:""}},parseDOM:[{tag:"mark",getAttrs:e=>sb(e)}],toDOM:e=>{const t=String(e.attrs.bg);if(!t)return["mark",{"data-amx-bg":""},0];const n=mu(Aa,t);return["mark",{style:`background:${t}`,"data-amx-bg":t,...n?{"data-hl":n}:{}},0]},parseMarkdown:{match:e=>e.type===Hn,runner:(e,t,n)=>{e.openMark(n,{bg:t.bg}),e.next(t.children),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name==="amadeusBg",runner:(e,t)=>{e.withMark(t,Hn,void 0,{bg:t.attrs.bg})}}})),co=V("AmadeusToggleUnderline",e=>()=>Wn(uu.type(e)));function hu(e,t){return(n,r)=>{const{from:o,to:s,empty:a}=n.selection;return a?!1:(r&&r(n.tr.removeMark(o,s,e).addMark(o,s,e.create(t))),!0)}}function gu(e){return(t,n)=>{const{from:r,to:o,empty:s}=t.selection;return s?!1:(n&&n(t.tr.removeMark(r,o,e)),!0)}}const Il=V("AmadeusApplyColor",e=>t=>t?hu(Oo.type(e),{color:t}):gu(Oo.type(e))),Rl=V("AmadeusApplyBg",e=>t=>t?hu(Po.type(e),{bg:t}):gu(Po.type(e)));Be({"obsinline.comment.title":{zh:"注释(点击编辑)",en:"Comment (click to edit)"}});function bu(e){if(e.indexOf("%%")===-1&&e.indexOf("==")===-1)return[];let t=e;for(const o of Hi(e))t=t.slice(0,o.from)+" ".repeat(o.to-o.from)+t.slice(o.to);const n=[];for(let o=t.indexOf("%%");o!==-1;){const s=t.indexOf("%%",o+2);if(s===-1)break;s>o+2?(n.push({kind:"cmt",from:o,to:s+2}),o=t.indexOf("%%",s+2)):o=t.indexOf("%%",o+1)}const r=new RegExp("(?<!=)==(?![\\s=])([^\\n]*?)(?<![\\s=])==(?!=)","g");for(let o=r.exec(t);o;o=r.exec(t)){const s=o.index,a=s+o[0].length;a-s<=4||n.some(l=>l.kind==="cmt"&&s<l.to&&a>l.from)||n.push({kind:"hl",from:s,to:a})}return n.sort((o,s)=>o.from-s.from)}const ab=new be("amadeus-obsidian-inline");function lb(e,t){const n=document.createElement("span");return n.className="amx-obs-cmt-badge",n.contentEditable="false",n.textContent="%%",n.title=P("obsinline.comment.title"),n.addEventListener("mousedown",r=>{if(!e.editable)return;r.preventDefault();const o=Math.min(t,e.state.doc.content.size);e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,o)).setMeta(nm,!0)),e.focus()}),n}function ib(e){const t=ds(e),{from:n,to:r}=e.selection,o=[];return e.doc.descendants((s,a)=>{if(!s.isTextblock)return!0;if(s.type.spec.code)return!1;const l=s.textContent;if(l.indexOf("%%")===-1&&l.indexOf("==")===-1)return!1;const i=a+1;for(const c of bu(Kr(s))){const u=i+c.from,d=i+c.to,f=t&&n<=d&&r>=u;if(c.kind==="hl"){o.push(te.inline(u+2,d-2,{class:"amx-obs-hl"}));const m=f?"amx-obs-delim":"amx-obs-hidden";o.push(te.inline(u,u+2,{class:m}),te.inline(d-2,d,{class:m}))}else f?o.push(te.inline(u,d,{class:"amx-obs-cmt"})):(o.push(te.inline(u,d,{class:"amx-obs-hidden"})),o.push(te.widget(u,m=>lb(m,u+2),{side:-1,ignoreSelection:!0,key:`obs-cmt:${u}`})))}return!1}),o.length?ke.create(e.doc,o):ke.empty}function cb(){return re(()=>new se({key:ab,props:{decorations:e=>ib(e)}}))}const ub=(e,t)=>{const{$from:n,$to:r,from:o,to:s,empty:a}=e.selection;if(!n.sameParent(r)||!n.parent.isTextblock||n.parent.type.spec.code)return!0;const l=n.start(),i=bu(Kr(n.parent)).find(p=>p.kind==="hl"&&l+p.from<=o&&s<=l+p.to);if(i)return t?.(e.tr.delete(l+i.to-2,l+i.to).delete(l+i.from,l+i.from+2)),!0;if(a)return!0;const c=e.doc.textBetween(o,s,`
|
|
4
|
+
`,"");if(c.includes(`
|
|
5
|
+
`))return!0;const u=o+(c.length-c.trimStart().length),d=s-(c.length-c.trimEnd().length);if(d<=u)return!0;const f=e.schema.text("=="),m=e.tr.insert(d,f).insert(u,f);return m.setSelection(q.create(m.doc,u+2,d+2)),t?.(m),!0},Ll=e=>e?.type==="break",db=/^(?:\s*<br\b[^>]*>)+/i;function Bo(e){if(e?.type!=="html"||typeof e.value!="string")return{count:0,rest:""};const t=db.exec(e.value);return t?{count:(t[0].match(/<br\b/gi)??[]).length,rest:e.value.slice(t[0].length)}:{count:0,rest:""}}const yu=e=>{const t=e.replace(/^\n+/,"");return t&&!t.includes("<")?t:null};function ku(e){const t=Array.isArray(e?.children)?e.children:[];if(!t.some(a=>Ll(a)||Bo(a).count>0||a?.type==="text"&&typeof a.value=="string"&&a.value.includes(`
|
|
6
|
+
`)))return[e];const r=[[]],o=a=>{r[r.length-1].push(a)};for(const a of t){if(Ll(a)){r.push([]);continue}const l=Bo(a);if(l.count>0){for(let c=0;c<l.count;c++)r.push([]);const i=yu(l.rest);i?o({type:"text",value:i}):l.rest.trim()&&o({...a,value:l.rest});continue}if(a?.type==="text"&&typeof a.value=="string"&&a.value.includes(`
|
|
7
|
+
`)){a.value.split(`
|
|
8
|
+
`).forEach((c,u)=>{u>0&&r.push([]),c&&o({...a,value:c})});continue}o(a)}for(;r.length&&r[0].length===0;)r.shift();for(;r.length&&r[r.length-1].length===0;)r.pop();const s=e?.data?.amadeusRaw;if(typeof s=="string"&&r.length>1){const a=s.split(`
|
|
9
|
+
`);return r.map((l,i)=>({...e,children:l,data:{...e.data,amadeusRaw:a.length===r.length?a[i]:void 0}}))}return r.map(a=>({...e,children:a}))}function wu(e){if(!e.includes("<br"))return e;const t=e.split(`
|
|
10
|
+
`);let n=null;for(let r=0;r<t.length;r++){const o=/^ {0,3}(`{3,}|~{3,})/.exec(t[r]);if(o){const a=o[1][0];n?a===n&&(n=null):n=a;continue}if(n)continue;const s=/^(\s*(?:(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?|>\s?)*)<br\s*\/?>\s*$/i.exec(t[r]);if(s){const a=s[1].replace(/\s+$/,"");t[r]=/\[[ xX]\]$/.test(a)?`${a} `:a}}return t.join(`
|
|
11
|
+
`)}function fb(e,t){if(e?.type!=="paragraph"||t?.type!=="paragraph")return 0;const n=e.position?.end?.line,r=t.position?.start?.line;return typeof n!="number"||typeof r!="number"?0:Math.max(0,r-n-1)}function xu(e){if(!Array.isArray(e?.children))return;const t=[];let n=null;for(const r of e.children){for(let s=0;s<fb(n,r);s++)t.push({type:"paragraph",children:[]});if(n=r,r?.type==="paragraph"){t.push(...ku(r));continue}const o=Bo(r);if(o.count>0){for(let a=0;a<o.count;a++)t.push({type:"paragraph",children:[]});const s=yu(o.rest);s?t.push({type:"paragraph",children:[{type:"text",value:s}]}):o.rest.trim()&&t.push({...r,value:o.rest});continue}xu(r),t.push(r)}e.children=t}const pb=(e,t)=>e?.type==="paragraph"&&t?.type==="paragraph"?0:void 0,mb=e=>Math.max(0,Math.floor((e-1)/2)),hb=e=>Math.max(0,Math.floor(e/2)),gb=e=>Math.max(0,Math.floor((e+1)/2));function An(e,t){const n=t==="start"?e?.data?.amadeusIndentLine:void 0,r=typeof n=="number"?n:e?.position?.[t]?.line;return typeof r=="number"?r:null}function bb(e){const t=Array.isArray(e?.children)?e.children:[];if(!t.length)return;const n=()=>({type:"paragraph",children:[]}),r=(c,u)=>{for(let d=0;d<u;d++)c.push(n())},o=[],s=An(e,"start"),a=An(t[0],"start");s!=null&&a!=null&&r(o,hb(a-s));let l=null;for(const c of t){const u=An(c,"start");l!=null&&u!=null&&r(o,mb(u-l-1)),o.push(c),l=An(c,"end")}const i=An(e,"end");i!=null&&l!=null&&r(o,gb(i-l-1)),e.children=o}const yb=Ne("amadeusBlankLine",()=>()=>e=>bb(e)),kb=Ne("amadeusSoftBreak",()=>function(){const t=this.data();return(t.toMarkdownExtensions||=[]).push({join:[pb]}),r=>xu(r)});function wb(e){const t=n=>{if(!(!n||typeof n!="object")){n.type==="break"&&(n.data={...n.data||{},isInline:!1});for(const r of Array.isArray(n.children)?n.children:[])t(r)}};t(e)}const z1=Ne("amadeusHardBreak",()=>()=>e=>wb(e)),xb=/^[-*+]$/,ln=e=>typeof e=="string"&&xb.test(e)?e:null;function vb(e,t){const n=r=>{if(r?.type==="list"&&!r.ordered){const o=r.children?.[0]?.position?.start?.offset,s=typeof o=="number"?ln(t[o]):null;s&&(r.data={...r.data,amadeusBullet:s})}for(const o of Array.isArray(r?.children)?r.children:[])n(o)};n(e)}const Cb=Ne("amadeusListBullet",()=>()=>(e,t)=>vb(e,String(t?.value??""))),$l=e=>e===!0||e==="true";function Sb(e,t,n,r){const o=$l(e.spread);e.spread=o;for(const l of Array.isArray(e.children)?e.children:[])l?.type==="listItem"&&(l.spread=$l(l.spread)&&o);const s=e.ordered?null:ln(e.amadeusBullet);if(!s)return dn.list(e,t,n,r);const a=n.options.bullet;n.options.bullet=s;try{return dn.list(e,t,n,r)}finally{n.options.bullet=a}}const Ab=Un(e=>{e.update(Qt,t=>({...t,handlers:{...t.handlers,list:Sb}}))}),Mb=[Cb,Ab].flat(),ze=e=>Math.max(0,Math.min(Ni,Math.floor(e)||0)),Nb=/^<!-- amadeus-indent:([1-8]) -->$/,Eb=new Set(["heading","blockquote","list"]);function vu(e){if(!e.children)return;const t=e.children;for(let n=0;n<t.length;n++){const r=t[n],o=t[n+1],s=r.type==="paragraph"&&r.children?.length===1?r.children[0]:r,a=s.type==="html"&&typeof s.value=="string"?Nb.exec(s.value.trim()):null;if(a&&o&&Eb.has(o.type)){const l=s.position?.start;o.data={...o.data,amadeusIndent:Number(a[1]),...typeof l?.offset=="number"?{amadeusIndentFrom:l.offset}:{},...typeof l?.line=="number"?{amadeusIndentLine:l.line}:{}},t.splice(n,1),n--;continue}vu(r)}}const Tb=Ne("amadeusStructuralIndent",()=>()=>e=>vu(e)),Qr=e=>ze(Number(e.data?.amadeusIndent??0)),Zr=e=>`<!-- amadeus-indent:${ze(e)} -->`,Dl=Rt.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0}},parseDOM:[{tag:"blockquote",getAttrs:r=>({indent:ze(Number(r.dataset.indent))})}],toDOM:r=>{const o=ze(r.attrs.indent);return["blockquote",{...t.get(Gr.key)(r),...o?{"data-indent":o}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{r.openNode(s,{indent:Qr(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=ze(o.attrs.indent);s&&r.addNode("html",void 0,Zr(s)),n.toMarkdown.runner(r,o)}}}}),_l=kt.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0},bullet:{default:null}},parseDOM:[{tag:"ul",getAttrs:r=>({spread:r.dataset.spread==="true",indent:ze(Number(r.dataset.indent)),bullet:ln(r.dataset.bullet)})}],toDOM:r=>{const o=ze(r.attrs.indent),s=ln(r.attrs.bullet);return["ul",{...t.get(Jr.key)(r),"data-spread":r.attrs.spread,...o?{"data-indent":o}:{},...s?{"data-bullet":s}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{const a=o.spread!=null?`${o.spread}`:"false";r.openNode(s,{spread:a,indent:Qr(o),bullet:ln(o.data?.amadeusBullet)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=ze(o.attrs.indent);s&&r.addNode("html",void 0,Zr(s));const a=ln(o.attrs.bullet);r.openNode("list",void 0,{ordered:!1,spread:o.attrs.spread,...a?{amadeusBullet:a}:{}}).next(o.content).closeNode()}}}}),zl=wt.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0}},parseDOM:[{tag:"ol",getAttrs:r=>({spread:r.dataset.spread,order:r.hasAttribute("start")?Number(r.getAttribute("start")):1,indent:ze(Number(r.dataset.indent))})}],toDOM:r=>{const o=ze(r.attrs.indent);return["ol",{...t.get(Yr.key)(r),...r.attrs.order===1?{}:{start:r.attrs.order},"data-spread":r.attrs.spread,...o?{"data-indent":o}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{const a=o.spread!=null?`${o.spread}`:"true";r.openNode(s,{spread:a,order:o.start??1,indent:Qr(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=ze(o.attrs.indent);s&&r.addNode("html",void 0,Zr(s)),n.toMarkdown.runner(r,o)}}}}),Ko=new Set(["heading","blockquote","bullet_list","ordered_list"]);function Cu(e,t,n){const{from:r,to:o}=e.selection,s=e.tr;let a=!1;return e.doc.nodesBetween(r,o,(l,i)=>{const c=l.type.name;if(c==="table"||c==="code_block")return!1;if(c!=="paragraph"&&!Ko.has(c))return!0;if(c==="paragraph"){const f=e.doc.resolve(i);for(let m=f.depth;m>=1;m--)if(f.node(m).type.name==="list_item"||f.node(m).type.name==="blockquote")return!1}a=!0;const u=ze(Number(l.attrs.indent??0)),d=ze(u+n);return d!==u&&s.setNodeMarkup(i,void 0,{...l.attrs,indent:d}),!1}),s.steps.length&&t?.(s.scrollIntoView()),a}function Ft(e,t,n,r){if(e.selection instanceof Qe&&Ko.has(e.selection.node.type.name)){const o=e.selection.node,s=e.selection.from,a=ze(Number(o.attrs.indent??0)+r);return a!==ze(Number(o.attrs.indent??0))&&t?.(e.tr.setNodeMarkup(s,void 0,{...o.attrs,indent:a}).scrollIntoView()),!0}for(let o=n.depth;o>=1;o--){const s=n.node(o);if(!Ko.has(s.type.name))continue;const a=n.before(o),l=ze(Number(s.attrs.indent??0)+r);return l!==ze(Number(s.attrs.indent??0))&&t?.(e.tr.setNodeMarkup(a,void 0,{...s.attrs,indent:l}).scrollIntoView()),!0}return!1}const Su=/^<br\b[^<>]*>$/i,Ib=e=>e!=null&&Su.test(e)?e:null,Rb=new Set(["root","blockquote","listItem","footnoteDefinition"]);function Lb(e,t){const n=e[t-1],r=e[t+1],o=l=>l.type==="break"&&!l.data?.amadeusBr,s=l=>!l||o(l)||l.type==="text"&&/\n[ \t]*$/.test(l.value??""),a=l=>!l||o(l)||l.type==="text"&&/^[ \t]*\n/.test(l.value??"");return s(n)&&a(r)}function $b(e){const t=n=>{const r=n?.children;if(!Array.isArray(r))return;const o=!Rb.has(n.type);for(let s=0;s<r.length;s++){const a=r[s];if(o&&a?.type==="html"&&typeof a.value=="string"&&Su.test(a.value)&&!Lb(r,s)){r[s]={type:"break",data:{amadeusBr:a.value},position:a.position};continue}t(a)}};t(e)}const Db=Ne("amadeusInlineBr",()=>()=>e=>$b(e)),Ol=tt.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},html:{default:null}},parseDOM:[{tag:"br[data-md-br]",getAttrs:r=>({html:Ib(r.getAttribute("data-md-br"))})},...n.parseDOM??[]],toDOM:r=>{const o=n.toDOM(r);return typeof r.attrs.html=="string"&&o[0]==="br"?[o[0],{...o[1],"data-md-br":r.attrs.html},...o.slice(2)]:o},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{const a=o.data?.amadeusBr;r.addNode(s,{isInline:!!o.data?.isInline,html:typeof a=="string"?a:null})}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{typeof o.attrs.html=="string"?r.addNode("html",void 0,o.attrs.html):n.toMarkdown.runner(r,o)}}}}),Au=e=>e.lastChild?.type.name==="hardbreak"&&typeof e.lastChild.attrs.html=="string",_b=re(e=>new se({key:new be("AMADEUS_HARDBREAK_MARKS"),appendTransaction:(t,n,r)=>{const o=t[0],s=o?.steps[0];if(!o||!s)return null;const a=tt.type(e);if(o.getMeta("hardbreak"))return s instanceof rs?r.tr.setNodeMarkup(s.from,a,void 0,[]):null;if(s instanceof os){let l=r.tr;return r.doc.nodesBetween(s.from,s.to,(i,c)=>{i.type===a&&i.marks.length&&(l=l.setNodeMarkup(c,a,i.attrs,[]))}),l.docChanged?l:null}return null}})),uo=e=>String(e??"").toUpperCase();function zb(e,t){const n=e?.position?.start,r=e?.position?.end;if(typeof n?.offset!="number"||typeof r?.offset!="number")return null;const o=t.slice(n.offset,r.offset);if(n.column<=1||!o.includes(`
|
|
12
|
+
`))return o;const s=new RegExp(`^[ \\t>]{0,${n.column-1}}`);return o.split(`
|
|
13
|
+
`).map((a,l)=>l?a.replace(s,""):a).join(`
|
|
14
|
+
`)}const Ob=e=>`[${e.label??e.identifier}]: ${e.url}${e.title?` "${e.title}"`:""}`;function Pb(e,t,n){const r=e[0].position?.start,o=e[e.length-1].position?.end;let s;if(t?.type==="root"&&typeof r?.offset=="number"&&typeof o?.offset=="number"){let l=r.offset;for(;l>0&&(n[l-1]===" "||n[l-1]===" ");)l--;l>0&&n[l-1]!==`
|
|
15
|
+
`&&(l=r.offset),s=n.slice(l,o.offset)}else s=e.map(l=>zb(l,n)??Ob(l)).join(`
|
|
16
|
+
`);s=s.replace(/\r\n?/g,`
|
|
17
|
+
`);const a=[];return s.split(`
|
|
18
|
+
`).forEach((l,i)=>{i&&a.push({type:"break"}),l&&a.push({type:"text",value:l})}),{type:"paragraph",children:a,data:{amadeusRaw:s},...r&&o?{position:{start:r,end:o}}:{}}}function Bb(e,t){const n=new Map,r=s=>{if(s?.type==="definition"){const a=uo(s.identifier);a&&!n.has(a)&&n.set(a,s)}for(const a of s?.children??[])r(a)};r(e);const o=s=>{const a=s?.children;if(!Array.isArray(a))return;const l=[];let i=[];const c=()=>{i.length&&l.push(Pb(i,s,t)),i=[]};for(const u of a){if(u?.type==="definition"){const d=i[i.length-1];d&&u.position?.start?.line!==(d.position?.end?.line??-2)+1&&c(),i.push(u);continue}if(c(),u?.type==="linkReference"){const d=n.get(uo(u.identifier));if(!d){const p={children:u.children??[]};o(p),l.push(...p.children);continue}const f={referenceType:u.referenceType,label:String(u.label??u.identifier),url:d.url},m={type:"link",url:d.url,title:d.title??null,children:u.children??[],position:u.position,data:{amadeusRef:f}};o(m),l.push(m);continue}if(u?.type==="imageReference"){const d=n.get(uo(u.identifier));l.push(d?{type:"image",url:d.url,title:d.title??null,alt:u.alt,position:u.position}:{type:"text",value:u.alt??""});continue}o(u),l.push(u)}c(),s.children=l};o(e)}const Kb=Ne("amadeusRefDefinitions",()=>()=>(e,t)=>Bb(e,String(t?.value??""))),Pl=e=>e.replace(/[\t ]+(?=\n|$)/g,"");function jo(e){const t=e.attrs.raw;if(typeof t!="string"||e.attrs.indent||e.attrs.align&&e.attrs.align!=="left")return null;let n=!0;return e.forEach(r=>{(r.marks.length||!r.isText&&!(r.type.name==="hardbreak"&&r.attrs.html==null))&&(n=!1)}),n&&Pl(e.textContent)===Pl(t)?t:null}const jb=/^[ \t]{0,3}(\[((?:[^\\[\]]|\\[\s\S])+)\]:)/;let Bl=null;const Hb=e=>{Bl??=Ei().use(Ti).use(Zo);const t=Bl.parse(e)?.children??[];return t.length>0&&t.every(n=>n?.type==="definition")},Fb=e=>e==null||!jb.test(e.split(`
|
|
19
|
+
`)[0])||/(?:^|\n)[ \t\r]*(?:\n|$)/.test(e)?null:Hb(e)?e:null,qb=e=>{if(!e)return null;try{const t=JSON.parse(e);return t&&typeof t.label=="string"&&typeof t.url=="string"?{referenceType:t.referenceType,label:t.label,url:t.url}:null}catch{return null}},Kl=et.extendSchema(e=>t=>{const n=e(t);return{...n,inclusive:!1,attrs:{...n.attrs??{},ref:{default:null}},parseDOM:[{tag:"a[href]",getAttrs:r=>{const o=r;return{href:o.getAttribute("href"),title:o.getAttribute("title"),ref:qb(o.getAttribute("data-md-ref"))}}}],toDOM:r=>{const{ref:o,...s}=r.attrs;return["a",{...t.get(qr.key)(r),...s,...o?{"data-md-ref":JSON.stringify(o)}:{}}]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{const a=o.data?.amadeusRef??null;r.openMark(s,{href:o.url,title:o.title??null,ref:a}),r.next(o.children),r.closeMark(s)}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o,s)=>n.toMarkdown.runner(r,o,s)}}});function nr(e){const t=e;return new nt(t.match,(n,r,o,s)=>typeof r.index=="number"&&typeof r.input=="string"&&r.index+r[0].length===r.input.length?t.handler(n,r,o,s):null,{undoable:t.undoable,inCode:t.inCode,inCodeMark:t.inCodeMark})}const Wb=he(e=>nr(ft(/(?:^|[^*])\*([^*]+)\*$/,Dt.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}))),Ub=/\b_(?![_\s])([^_]*[^_\s])_$/,Vb=he(e=>nr(ft(Ub,Dt.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}))),Gb=he(e=>nr(ft(/(?:`)([^`]+)(?:`)$/,bt.type(e)))),Jb=new RegExp("(?:(?<![:/])\\*\\*(?=[^*_]+?\\*\\*$)|(?<![\\w:/])__(?=[^*_]+?__$))([^*_]+?)(?:\\*\\*|__)$"),Yb=he(e=>nr(ft(Jb,gn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}))),Xb=new RegExp("(?<![\\w:/~])(~~)([^\\s~](?:[^~]*[^\\s~])?)~~$"),Qb=he(e=>nr(ft(Xb,yn.type(e)))),Zb=e=>(e.inject(Gt.options.key,{singleTilde:!1}),()=>()=>{e.remove(Gt.options.key)});function ey(){const e=t=>{!t||typeof t!="object"||(Array.isArray(t.extensions)&&t.extensions.forEach(e),!(!t.handlers?.delete||!Array.isArray(t.unsafe))&&(t.unsafe=t.unsafe.map(n=>n.character==="~"&&!("before"in n)&&!("after"in n)&&!n.atBreak?{...n,after:"(?=~)|(?<=~~)"}:n)))};for(const t of this.data().toMarkdownExtensions??[])e(t)}const ty=Ne("amadeusStrictTildeUnsafe",()=>ey),jl=new Map([[hs,Wb],[gs,Vb],[vs,Gb],[ks,Yb]]),ny=Dg.flatMap(e=>e===ia?[Qb]:e===Gt.options?[Zb]:e===Gt.plugin?[e,...ty]:[e]),Dn=new WeakMap,fo=e=>!/\S/.test(e);function ry(e,t){let n=t;for(;n>0&&e[n-1]!==`
|
|
20
|
+
`;)n--;const r=e.slice(n,t);return r?/^ {1,3}$/.test(r)?n:null:t}function oy(e,t){let n=t;for(;n<e.length&&(e[n]===" "||e[n]===" ");)n++;return n===e.length||e[n]===`
|
|
21
|
+
`?n:t}const sy=/!\[(?!\[)[^\]\n]*\](?!\()/;function ay(e){let t=e.type.name==="paragraph"&&typeof e.attrs.raw=="string",n=!1;return e.descendants(r=>(r.type.name==="paragraph"&&typeof r.attrs.raw=="string"&&(t=!0),r.isText&&r.marks.some(o=>o.type.name==="link"&&o.attrs.ref!=null)&&(n=!0),!(t&&n))),{def:t,link:n}}const ly=e=>e?.type==="html"||e?.type==="paragraph"&&e.children?.length===1&&e.children[0]?.type==="html";function iy(e,t,n){const r=n.length,o={text:e,nodes:n.slice(),from:new Array(r).fill(null),to:new Array(r).fill(null),sealBefore:new Array(r).fill(!1),sealAfter:new Array(r).fill(!1),eofOpen:new Array(r).fill(!1),indentStart:new Array(r).fill(!1),def:new Array(r).fill(!1),ref:new Array(r).fill(!1)},s=new Map;n.forEach((c,u)=>s.set(c,u));let a=0;for(const c of t){if(!c.made.length)continue;const u=s.get(c.made[0]),d=s.get(c.made[c.made.length-1]);if(u==null||d==null)continue;const f=c.md?.position?.start?.offset,m=c.md?.position?.end?.offset;if(typeof f!="number"||typeof m!="number"||f>m||m>e.length)continue;const p=c.md?.data?.amadeusIndentFrom,h=typeof p=="number"&&p>=0&&p<f?p:f;if(h<a)continue;const g=ry(e,h),y=g??h,k=oy(e,m);o.from[u]=y,o.to[d]=k,g==null&&(o.sealBefore[u]=!0),a=k;const M=e.slice(y,k),E=c.md;(k===e.length||fo(e.slice(k)))&&(E?.type==="code"&&/^[ \t]*(`{3,}|~{3,})/.test(M)||ly(E))&&(o.eofOpen[d]=!0),/^[ \t]/.test(M)&&(o.indentStart[u]=!0);let x=!1,I=sy.test(M);for(const R of c.made){const D=ay(R);x||=D.def,I||=D.link}for(let R=u;R<=d;R++)o.def[R]=x,o.ref[R]=I}let l=null,i=0;for(let c=0;c<r;c++){const u=o.from[c];u!=null&&!fo(e.slice(i,u))&&(o.sealBefore[c]=!0,l!=null&&(o.sealAfter[l]=!0));const d=o.to[c];d!=null&&(l=c,i=d)}l!=null&&!fo(e.slice(i))&&(o.sealAfter[l]=!0),n.forEach((c,u)=>Dn.set(c,{src:o,idx:u}))}function cy(e,t,n){e.openNode(n);const r=e.top(),o=t?.data?.amadeusSource,s=[];let a=!!r&&typeof o=="string"&&!o.includes("\r");for(const l of Array.isArray(t?.children)?t.children:[]){const i=r?r.content.length:0;if(e.next(l),!!a){if(e.top()!==r||r.content.length<i){a=!1;continue}s.push({md:l,made:r.content.slice(i)})}}a&&iy(o,s,r.content)}const uy=Ne("amadeusVerbatimSource",()=>()=>(e,t)=>{e.data={...e.data,amadeusSource:String(t?.value??"")}});function dy(e,t){const n=e.type.name==="heading";for(const r of Object.keys(e.attrs)){if(n&&r==="id")continue;const o=e.attrs[r],s=t.attrs[r];if(o!==s&&JSON.stringify(o)!==JSON.stringify(s))return!1}return!0}function Er(e,t){if(e===t)return!0;if(e.type!==t.type||!zf.sameSet(e.marks,t.marks))return!1;if(e.isText)return e.text===t.text;if(!dy(e,t)||e.childCount!==t.childCount)return!1;for(let n=0;n<e.childCount;n++)if(!Er(e.child(n),t.child(n)))return!1;return!0}const Ho=e=>e.type.name==="bullet_list"||e.type.name==="ordered_list",fy=e=>Ho(e)||e.type.name==="footnote_definition",Hl=e=>e.type.name==="paragraph"&&e.content.size===0;function py(e){let t=e.type.name==="paragraph"&&jo(e)!=null;return e.descendants(n=>(!t&&n.type.name==="paragraph"&&jo(n)!=null&&(t=!0),!t)),t}function my(e){const t=e.childCount;if(!t)return null;const n=[];e.forEach(p=>{n.push(p)});const r=n.map(p=>Dn.get(p)??null);if(!r.some(Boolean))return null;const o=(p,h,g)=>{if(r[p]||!h)return;const y=h.idx+g;y>=0&&y<h.src.nodes.length&&Er(n[p],h.src.nodes[y])&&(r[p]={src:h.src,idx:y})};for(let p=1;p<t;p++)o(p,r[p-1],1);for(let p=t-2;p>=0;p--)o(p,r[p+1],-1);if(!r[0]){const p=r.find(Boolean);p&&Er(n[0],p.src.nodes[0])&&(r[0]={src:p.src,idx:0})}for(let p=1;p<t;p++)o(p,r[p-1],1);const s=new Set,a=new WeakMap;let l=0;const i=p=>{let h=a.get(p.src);return h==null&&a.set(p.src,h=l++),`${h}:${p.idx}`};r.forEach((p,h)=>{if(!p)return;const g=i(p);s.has(g)?r[h]=null:s.add(g)});const c=new Map,u=p=>{let h=c.get(p);if(h!=null)return h;h=!0;let g=-1;const y=new Set;return r.forEach((k,M)=>{if(!k){py(n[M])&&(h=!1);return}if(k.src!==p){k.src.def[k.idx]&&(h=!1);return}p.def[k.idx]&&(k.idx<g&&(h=!1),g=k.idx,y.add(k.idx))}),p.def.forEach((k,M)=>{k&&!y.has(M)&&(h=!1)}),c.set(p,h),h},d=r.map((p,h)=>!(!p||p.src.ref[p.idx]&&!u(p.src)||p.src.eofOpen[p.idx]&&!(h===t-1&&p.idx===p.src.nodes.length-1))),f=p=>p===0&&r[p].idx===0,m=p=>p===t-1&&r[p].idx===r[p].src.nodes.length-1;for(let p=0;p<=t+1;p++){const h=[];for(let x=0;x<t;x++){if(!d[x])continue;const I=x;for(;x+1<t&&d[x+1]&&r[x+1].src===r[I].src&&r[x+1].idx===r[x].idx+1;)x++;h.push([I,x])}let g=!1;for(const[x,I]of h){const R=r[x].src,D=f(x)||R.from[r[x].idx]!=null&&!R.sealBefore[r[x].idx],U=m(I)||R.to[r[I].idx]!=null&&!R.sealAfter[r[I].idx];D||(d[x]=!1,g=!0),U||(d[I]=!1,g=!0)}if(g)continue;const y=x=>{let I=x-1;for(;I>=0&&Hl(n[I]);)I--;return I},k=x=>{let I=x+1;for(;I<t&&Hl(n[I]);)I++;return I};for(const[x,I]of h){const R=r[x].src,D=y(x);D>=0&&Ho(n[x])&&n[D].type===n[x].type&&(d[x]=!1,g=!0);const U=k(I);U<t&&Ho(n[I])&&n[U].type===n[I].type&&(d[I]=!1,g=!0),R.indentStart[r[x].idx]&&D>=0&&(fy(n[D])||n[x].type.name==="code_block"&&n[D].type.name==="code_block")&&(d[x]=!1,g=!0),x===0&&/^---\r?\n/.test(R.text.slice(f(0)?0:R.from[r[0].idx]??0))&&(d[0]=!1,g=!0)}if(g)continue;if(!h.length)return null;const M=h.map(([x,I])=>{const R=r[x].src;return{a:x,b:I,src:R,from:f(x)?0:R.from[r[x].idx],to:m(I)?R.text.length:R.to[r[I].idx],tail:m(I)}}),E=new Map;return M.forEach((x,I)=>E.set(x.a,I)),{doc:e,runs:M,startAt:E,nonce:Math.random().toString(36).slice(2,10)}}return null}let _n=null;const Mu=(e,t)=>`${e.nonce}:${t}`;function hy(e,t){e.openNode("root");const n=_n&&_n.doc===t?_n:null;if(!n){e.next(t.content);return}for(let r=0;r<t.childCount;r++){const o=n.startAt.get(r);if(o==null){e.next(t.child(r));continue}e.addNode("amadeusVerbatim",void 0,Mu(n,o)),r=n.runs[o].b}}const gy=Un(e=>{e.update(Qt,t=>({...t,handlers:{...t.handlers,amadeusVerbatim:n=>String(n.value??"")}}))}),by=cs("doc",()=>({content:"block+",parseMarkdown:{match:({type:e})=>e==="root",runner:cy},toMarkdown:{match:e=>e.type.name==="doc",runner:hy}})),yy=[uy,gy].flat();function ky(e,t,n){const r=e.get(qt);let o=null;try{o=my(t)}catch{o=null}if(!o)return n(r(t));_n=o;let s;try{s=r(t)}finally{_n=null}let l=n(s);for(let i=0;i<o.runs.length;i++){const c=Mu(o,i),u=l.indexOf(c);if(u<0||l.indexOf(c,u+c.length)>=0)return n(r(t));const d=o.runs[i],f=d.src.text.slice(d.from,d.to),m=u+c.length,p=d.tail&&l.length===m+1&&l[m]===`
|
|
22
|
+
`?1:0;l=l.slice(0,u)+f+l.slice(m+p)}return l.includes(""+o.nonce)?n(r(t)):l}function O1(e,t){const n=Math.min(e.childCount,t.childCount),r=(s,a)=>{if(s===a)return!0;if(!Er(s,a))return!1;const l=Dn.get(a);return l?Dn.set(s,l):Dn.delete(s),!0};let o=0;for(;o<n&&r(e.child(o),t.child(o));)o++;for(let s=1;s<=n-o&&r(e.child(e.childCount-s),t.child(t.childCount-s));s++);}const Fl="amadeusEscaped",Tr="amadeusEscape",Nu="\0",wy=/[!-/:-@[-`{-~]/g,xy=/\u0000(?=[!-/:-@[-`{-~])/g;function Eu(e){return e.includes(Nu)?e.replace(xy,"\\"):e}function vy(e){const t=n=>{const r=n?.children;if(!Array.isArray(r))return;let o=!1;const s=[];for(const a of r){const l=a?.type==="text"?a.data?.[sl]:void 0;if(!l?.length){t(a),s.push(a);continue}o=!0;const{[sl]:i,...c}=a.data,u=Object.keys(c).length?{...a,data:c}:(({data:p,...h})=>h)(a),d=a.value,f=new Set(l.filter(p=>p>=0&&p<d.length));let m=0;for(;m<d.length;){const p=f.has(m);let h=m+1;for(;h<d.length&&f.has(h)===p;)h++;s.push(p?{type:Tr,value:d.slice(m,h)}:{...u,value:d.slice(m,h)}),m=h}}o&&(n.children=s)};t(e)}const Cy=Ne("amadeusLiteralEscape",()=>()=>vy),Sy=pt(Fl,()=>({inclusive:!1,priority:100,parseDOM:[{tag:"span[data-amx-esc]"}],toDOM:()=>["span",{"data-amx-esc":""},0],parseMarkdown:{match:e=>e.type===Tr,runner:(e,t,n)=>{e.openMark(n),e.addText(String(t.value??"")),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===Fl,runner:(e,t,n)=>(e.addNode(Tr,void 0,n.text??""),!0)}})),Tu=e=>String(e.value??"").replace(wy,t=>Nu+t);Tu.peek=()=>"\\";const Ay=Un(e=>{e.update(Qt,t=>({...t,handlers:{...t.handlers,[Tr]:Tu}}))}),My=[Sy,Ay].flat(),lt=e=>Math.max(0,Math.min(Ni,Math.floor(e)||0)),Ny=/^<span data-amadeus-align="(left|center|right)"><\/span>$/,Ey=/^<span data-amadeus-align="(left|center|right)">$/,it=e=>e==="center"||e==="right"?e:"left",Iu=e=>`<span data-amadeus-align="${e}"></span>`,Ru=e=>{const t=e?.[0];if(t?.type!=="html"||typeof t.value!="string")return{align:"left",children:e};const n=Ny.exec(t.value.trim());if(n)return{align:it(n[1]),children:e.slice(1)};const r=Ey.exec(t.value.trim()),o=e?.[1];return r&&o?.type==="html"&&o.value?.trim()==="</span>"?{align:it(r[1]),children:e.slice(2)}:{align:"left",children:e}},ql=We.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0},align:{default:"left"},raw:{default:null}},parseDOM:[{tag:"p",getAttrs:r=>({indent:lt(Number(r.getAttribute("data-indent"))),align:it(r.getAttribute("data-align")||r.style.textAlign),raw:Fb(r.getAttribute("data-md-raw"))})}],toDOM:r=>{const o={...t.get(Ur.key)(r)},s=lt(r.attrs.indent),a=it(r.attrs.align);return s&&(o["data-indent"]=String(s)),a!=="left"&&(o["data-align"]=a),typeof r.attrs.raw=="string"&&(o["data-md-raw"]=r.attrs.raw),["p",o,0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{let a=0;const l=Ru(o.children),i=l.align;let c=l.children;const u=c?.[0];if(u&&u.type==="text"&&typeof u.value=="string"){const f=/^\t+/.exec(u.value);if(f){a=lt(f[0].length);const m=u.value.slice(a);c=m?[{...u,value:m},...c.slice(1)]:c.slice(1)}}const d=o.data?.amadeusRaw??null;r.openNode(s,a||i!=="left"||d!=null?{indent:a,align:i,raw:d}:void 0),c?.length?r.next(c):c||r.addText(o.value||""),r.closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=jo(o);if(s!=null){r.openNode("paragraph"),r.addNode("html",void 0,s),r.closeNode();return}if(o.content.size===0&&r.top()?.type==="tableCell"){r.openNode("paragraph"),r.closeNode();return}const a=lt(o.attrs.indent),l=it(o.attrs.align),i=Au(o);if((!a&&l==="left"||o.content.size===0&&l==="left")&&!i)return void n.toMarkdown.runner(r,o);r.openNode("paragraph"),l!=="left"&&r.addNode("html",void 0,Iu(l)),a&&r.addNode("html",void 0,"	".repeat(a));const c=o.lastChild?.type.name==="hardbreak"&&!i;r.next(c?o.content.cut(0,o.content.size-o.lastChild.nodeSize):o.content),r.closeNode()}}}}),Wl=ut.extendSchema(e=>t=>{const n=e(t),r=t.get(Gn.key);return{...n,attrs:{...n.attrs??{},align:{default:"left"},indent:{default:0}},parseDOM:[1,2,3,4,5,6].map(o=>({tag:`h${o}`,getAttrs:s=>{const a=s;return{level:o,id:a.id,align:it(a.getAttribute("data-align")||a.style.textAlign),indent:lt(Number(a.dataset.indent))}}})),toDOM:o=>{const s={...t.get(Vr.key)(o),id:o.attrs.id||r(o)},a=it(o.attrs.align);a!=="left"&&(s["data-align"]=a);const l=lt(o.attrs.indent);return l&&(s["data-indent"]=String(l)),[`h${o.attrs.level}`,s,0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(o,s,a)=>{const l=Ru(s.children);o.openNode(a,{level:s.depth,...l.align!=="left"?{align:l.align}:{},indent:Qr(s)}),l.children?.length&&o.next(l.children),o.closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(o,s)=>{const a=lt(s.attrs.indent);a&&o.addNode("html",void 0,Zr(a));const l=it(s.attrs.align),i=Au(s);if(l==="left"&&!i)return void n.toMarkdown.runner(o,s);o.openNode("heading",void 0,{depth:s.attrs.level}),l!=="left"&&o.addNode("html",void 0,Iu(l));const c=s.lastChild?.type.name==="hardbreak"&&!i;o.next(c?s.content.cut(0,s.content.size-s.lastChild.nodeSize):s.content),o.closeNode()}}}}),Ty=[...Db,...rm,...Cy,...Kb],Iy=dh.map(e=>e===Ss?by:e===We.node?ql.node:e===We.ctx?ql.ctx:e===ut.node?Wl.node:e===ut.ctx?Wl.ctx:e===Rt.node?Dl.node:e===Rt.ctx?Dl.ctx:e===kt.node?_l.node:e===kt.ctx?_l.ctx:e===wt.node?zl.node:e===wt.ctx?zl.ctx:e===tt.node?Ol.node:e===tt.ctx?Ol.ctx:e===ea?_b:e===et.mark?Kl.mark:e===et.ctx?Kl.ctx:jl.has(e)?jl.get(e):e),Ry=[...Iy.flatMap(e=>e===Xr.options?[...Ty,e]:[e]),...Mb,...yy,...My];function Lu(e){for(let t=e.depth;t>=1;t--){const n=e.node(t).type.name;if(n==="list_item"||n==="blockquote")return!1}return!0}function P1(e){return e.parent.type.name!=="paragraph"?null:Lu(e)?lt(e.parent.attrs.indent):null}function Ir(e,t,n){const{from:r,to:o}=e.selection,s=e.tr;let a=!1;return e.doc.nodesBetween(r,o,(l,i)=>{if(l.type.name!=="paragraph")return;if(!Lu(e.doc.resolve(i)))return!1;const c=lt(l.attrs.indent),u=lt(c+n);return u!==c&&(s.setNodeMarkup(i,void 0,{...l.attrs,indent:u}),a=!0),!1}),a&&t?.(s.scrollIntoView()),!0}function ur(e,t,n){const r=it(n),o=new Set,s=i=>i==="paragraph"||i==="heading";if(e.doc.nodesBetween(e.selection.from,e.selection.to,(i,c)=>(s(i.type.name)&&o.add(c),!0)),!o.size){const{$from:i}=e.selection;for(let c=i.depth;c>0;c--)if(s(i.node(c).type.name)){o.add(i.before(c));break}}if(!o.size)return!1;let a=e.tr,l=!1;for(const i of o){const c=e.doc.nodeAt(i);!c||it(c.attrs.align)===r||(a=a.setNodeMarkup(i,void 0,{...c.attrs,align:r}),l=!0)}return l&&t?.(a.scrollIntoView()),!0}const $u=e=>{const t=e?.type.spec.tableRole;return t==="cell"||t==="header_cell"};function Du(e){if(!$u(e.nodeAfter)||e.depth<1)return null;const t=e.node(-1);if(t.type.spec.tableRole!=="table")return null;const n=e.start(-1),r=ne.get(t),o=r.findCell(e.pos-n);return{table:t,tablePos:n-1,map:r,cellPos:e.pos,row:o.top,col:o.left,bottom:o.bottom}}function eo(e){if(!Ue(e))return null;try{return Du(Xn(e))}catch{return null}}function Ma(e,t){return t<0||t>=e.content.size?null:Du(e.resolve(t))}function B1(e,t){const n=e.resolve(t),r=Ut(n);return r&&$u(r.nodeAfter)?r.pos:null}function to(e,t,n=!0){const r=e.nodeAt(t);if(!r)return null;const o=q.near(e.resolve(n?t+r.nodeSize-1:t+1),n?-1:1);return o instanceof q?o:null}const Na=(e,t,n,r)=>{const o=e.nodeAt(t);if(!o)return null;const s=ne.get(o);return n<0||n>=s.height||r<0||r>=s.width?null:t+1+s.map[n*s.width+r]};function Ea(e,t,n){const r=e.doc.nodeAt(t),{table_row:o,table_cell:s}=e.doc.type.schema.nodes;if(!r||!o||!s||n<1||n>r.childCount)return null;const a=ne.get(r),l=[];for(let c=0;c<a.width;c++){const u=s.createAndFill({alignment:r.nodeAt(a.map[c])?.attrs.alignment??null});if(!u)return null;l.push(u)}let i=t+1;for(let c=0;c<n;c++)i+=r.child(c).nodeSize;return e.insert(i,o.create(null,l)),i}const K1=(e,t)=>{const n=eo(e);if(!n)return!1;const r=e.tr;if(n.bottom>=n.map.height&&Ea(r,n.tablePos,n.map.height)==null)return!1;const o=Na(r.doc,n.tablePos,n.bottom,n.col),s=o==null?null:to(r.doc,o);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1},j1=(e,t)=>{if(!eo(e))return!1;const n=e.schema.nodes.hardbreak;return n?(e.selection instanceof q&&t?.(e.tr.replaceSelectionWith(n.create({html:"<br>"}),!1).scrollIntoView()),!0):!1},H1=(e,t)=>{const n=eo(e),r=e.schema.nodes.paragraph;if(!n||!r)return!1;const o=n.tablePos+n.table.nodeSize,s=e.tr.insert(o,r.create());return t?.(s.setSelection(q.create(s.doc,o+1)).scrollIntoView()),!0},Ly=(e,t)=>{const n=eo(e);if(!n)return!1;const r=e.tr,o=Ea(r,n.tablePos,n.map.height),s=o==null?null:to(r.doc,o+1,!1);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1};function F1(e,t,n){const r=e.nodeAt(t);if(!r||r.type.spec.tableRole!=="table")return null;const o=n!=null?Ma(e,n):null;if(o&&o.tablePos===t){const{row:l,map:i}=o,c=[];l>0&&c.push("rowAbove"),c.push("rowBelow","colLeft","colRight"),l>0&&i.height>2&&c.push("deleteRow"),i.width>1&&c.push("deleteCol");const u=r.nodeAt(i.map[o.col])?.attrs.alignment;return{tablePos:t,cellPos:o.cellPos,explicit:!0,ops:c,align:u==="center"||u==="right"?u:"left"}}const s=ne.get(r),a=Na(e,t,s.height-1,s.width-1);return a==null?null:{tablePos:t,cellPos:a,explicit:!1,ops:["rowBelow","colRight"],align:null}}function q1(e,t,n){const r=Ma(e.doc,t);if(!r)return null;const o=e.tr,s=r.tablePos+1,a={left:r.col,right:r.col+1,top:r.row,bottom:r.bottom,tableStart:s,map:r.map,table:r.table};let l=r.row,i=r.col;switch(n){case"rowAbove":case"rowBelow":{if(l=n==="rowAbove"?r.row:r.bottom,Ea(o,r.tablePos,l)==null)return null;break}case"colLeft":case"colRight":{i=n==="colLeft"?r.col:r.col+1,ra(o,a,i);const d=o.doc.nodeAt(r.tablePos);if(!d)return null;const f=ne.get(d);for(let m=0;m<f.height;m++){const p=s+f.map[m*f.width+i],h=o.doc.nodeAt(p);h&&h.attrs.alignment!=null&&o.setNodeMarkup(p,void 0,{...h.attrs,alignment:null})}break}case"deleteRow":{if(r.row===0||r.map.height<=2)return null;Ac(o,a,r.row),l=Math.min(r.row,r.map.height-2);break}case"deleteCol":{if(r.map.width<=1)return null;Sc(o,a,r.col),i=Math.min(r.col,r.map.width-2);break}}const c=Na(o.doc,r.tablePos,l,i),u=c==null?null:to(o.doc,c);return u&&o.setSelection(u),o.scrollIntoView()}function W1(e,t,n){const r=Ma(e.doc,t);if(!r)return null;const o=n==="left"?null:n,s=e.tr;for(let l=0;l<r.map.height;l++){const i=r.tablePos+1+r.map.map[l*r.map.width+r.col],c=s.doc.nodeAt(i);c&&c.attrs.alignment!==o&&s.setNodeMarkup(i,void 0,{...c.attrs,alignment:o})}const a=to(s.doc,r.cellPos);return a&&s.setSelection(a),s.scrollIntoView()}const Rr=e=>{const t=e.schema.nodes.list_item;if(!t)return!1;const{$from:n}=e.selection;for(let r=n.depth;r>=1;r--)if(n.node(r).type===t)return!0;return!1},_u=e=>{const{$from:t}=e.selection;for(let n=t.depth;n>=1;n--)if(t.node(n).type.name==="table")return!0;return!1},$y=e=>{const{$from:t}=e.selection;for(let n=t.depth;n>=1;n--){const r=t.node(n);if(r.type.name==="bullet_list"||r.type.name==="ordered_list")return Number(r.attrs.indent??0)}return 0};function zu(e,t,n){return!sa(n)(e,t)&&n===1&&Ly(e,t),!0}function Ou(e){const{$from:t,$to:n}=e.selection,r=t.parent.textContent,o=[r.lastIndexOf(`
|
|
23
|
+
`,t.parentOffset-1)+1];for(let s=t.parentOffset;s<n.parentOffset;s++)r[s]===`
|
|
24
|
+
`&&o.push(s+1);return o.map(s=>t.start()+s)}function Dy(e,t,n,r){const{$from:o,$to:s}=e.selection;if(o.parent.type.name==="code_block"){if(!o.sameParent(s))return!0;if(!e.selection.empty&&o.parent.textContent.slice(o.parentOffset,s.parentOffset).includes(`
|
|
25
|
+
`)){const a=e.tr;for(const l of Ou(e).reverse())a.insertText(" ",l,l);return t?.(a.scrollIntoView()),!0}return t?.(e.tr.insertText(" ",o.pos,s.pos)),!0}if(_u(e))return zu(e,t,1);if(!e.selection.empty&&!o.sameParent(s)&&!Rr(e)&&Cu(e,t,1))return!0;if(Rr(e)){const a=e.schema.nodes.list_item;let l=o.depth;for(;l>=1&&o.node(l).type!==a;)l--;if(l>=1){const i=o.before(l),c=e.doc.resolve(i).nodeBefore;if(c&&c.type===a){const u=i-c.nodeSize;if(r?.listFoldedAt?.(e,u))return n&&r?.unfoldList?.(n,u),!0}}return ec(e.schema.nodes.list_item)(e,t)||Ft(e,t,o,1),!0}return o.parent.type.name==="paragraph"?Ft(e,t,o,1)?!0:Ir(e,t,1):e.selection instanceof Qe&&e.selection.node.type.name==="paragraph"?Ir(e,t,1):(Ft(e,t,o,1),!0)}function _y(e,t){const{$from:n,$to:r}=e.selection;if(n.parent.type.name==="code_block"){if(!n.sameParent(r))return!0;const o=e.doc,s=e.tr;for(const a of Ou(e).reverse()){let l=0;for(;l<2&&o.textBetween(a+l,a+l+1)===" ";)l++;l>0&&s.delete(a,a+l)}return s.steps.length&&t?.(s.scrollIntoView()),!0}if(_u(e))return zu(e,t,-1);if(!e.selection.empty&&!n.sameParent(r)&&!Rr(e)&&Cu(e,t,-1))return!0;if(Rr(e)){const o=e.schema.nodes.list_item;if($y(e)>0)return Ft(e,t,n,-1);if(n.parent.type.name==="paragraph"&&n.depth>=2&&n.node(n.depth-1).type===o&&n.index(n.depth-1)>0){const s=n.blockRange(r),a=s?as(s):null;if(s&&a!=null)return t?.(e.tr.lift(s,a).scrollIntoView()),!0}return Zi(o)(e,t)||Ft(e,t,n,-1),!0}return n.parent.type.name==="paragraph"?Ft(e,t,n,-1)?!0:Ir(e,t,-1):e.selection instanceof Qe&&e.selection.node.type.name==="paragraph"?Ir(e,t,-1):(Ft(e,t,n,-1),!0)}function Fo(e){if(!e)return!1;if(Array.isArray(e))return e.length>1?!1:Fo(e[0]);const t=e.content;return t?Fo(t):e.type==="text"}function zy(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-clipboard",...t}}),e}function Ul(e,t){const n=Bf(t);if(n)return e.dispatch(e.state.tr.replaceSelectionWith(n,!0)),!0;try{return e.dispatch(e.state.tr.replaceSelection(t)),!0}catch{return!1}}var Pu=re(e=>{const t=e.get(Of);return e.update(Oi,n=>({...n,editable:n.editable??(()=>!0),transformPastedHTML:(r,o)=>{const s=n.transformPastedHTML;return s&&(r=s(r,o)),r.includes("docs-internal-guid")&&(r=r.replace(/<b[^>]*id="docs-internal-guid[^"]*"[^>]*>([\s\S]*)<\/b>/,"$1"),r=r.replace(/<div[^>]*>(<table[\s\S]*?<\/table>)<\/div>/g,"$1")),r}})),new se({key:new be("MILKDOWN_CLIPBOARD"),props:{handlePaste:(n,r,o)=>{const s=e.get(xr),a=n.props.editable?.(n.state),{clipboardData:l}=r;if(!a||!l||n.state.selection.$from.node().type.spec.code)return!1;const i=l.getData("text/plain"),c=l.getData("vscode-editor-data");if(c){const m=JSON.parse(c)?.mode;if(i&&m){const{tr:p}=n.state,h=Pf("code_block",t);return p.replaceSelectionWith(h.create({language:m})).setSelection(q.near(p.doc.resolve(Math.max(0,p.selection.from-2)))).insertText(i.replace(/\r\n?/g,`
|
|
26
|
+
`)),n.dispatch(p),!0}}const u=l.getData("text/html");if(u.length===0&&i.length===0)return!1;if(u.length>0&&o)return Ul(n,o);const d=Pi.fromSchema(t);let f;if(u.length===0){const m=s(i);if(!m||typeof m=="string")return!1;f=Bi.fromSchema(t).serializeFragment(m.content)}else{const m=document.createElement("template");m.innerHTML=u,f=m.content.cloneNode(!0),m.remove()}return Ul(n,d.parseSlice(f))},clipboardTextSerializer:n=>{const r=e.get(qt);if(Fo(n.content.toJSON()))return n.content.textBetween(0,n.content.size,`
|
|
27
|
+
|
|
28
|
+
`);const o=t.topNodeType.createAndFill(void 0,n.content);return o?r(o):""}}})});zy(Pu,{displayName:"Prose<clipboard>"});var Lr=200,$e=function(){};$e.prototype.append=function(t){return t.length?(t=$e.from(t),!this.length&&t||t.length<Lr&&this.leafAppend(t)||this.length<Lr&&t.leafPrepend(this)||this.appendInner(t)):this};$e.prototype.prepend=function(t){return t.length?$e.from(t).append(this):this};$e.prototype.appendInner=function(t){return new Oy(this,t)};$e.prototype.slice=function(t,n){return t===void 0&&(t=0),n===void 0&&(n=this.length),t>=n?$e.empty:this.sliceInner(Math.max(0,t),Math.min(this.length,n))};$e.prototype.get=function(t){if(!(t<0||t>=this.length))return this.getInner(t)};$e.prototype.forEach=function(t,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length),n<=r?this.forEachInner(t,n,r,0):this.forEachInvertedInner(t,n,r,0)};$e.prototype.map=function(t,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length);var o=[];return this.forEach(function(s,a){return o.push(t(s,a))},n,r),o};$e.from=function(t){return t instanceof $e?t:t&&t.length?new Bu(t):$e.empty};var Bu=(function(e){function t(r){e.call(this),this.values=r}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(o,s){return o==0&&s==this.length?this:new t(this.values.slice(o,s))},t.prototype.getInner=function(o){return this.values[o]},t.prototype.forEachInner=function(o,s,a,l){for(var i=s;i<a;i++)if(o(this.values[i],l+i)===!1)return!1},t.prototype.forEachInvertedInner=function(o,s,a,l){for(var i=s-1;i>=a;i--)if(o(this.values[i],l+i)===!1)return!1},t.prototype.leafAppend=function(o){if(this.length+o.length<=Lr)return new t(this.values.concat(o.flatten()))},t.prototype.leafPrepend=function(o){if(this.length+o.length<=Lr)return new t(o.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t})($e);$e.empty=new Bu([]);var Oy=(function(e){function t(n,r){e.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},t.prototype.forEachInner=function(r,o,s,a){var l=this.left.length;if(o<l&&this.left.forEachInner(r,o,Math.min(s,l),a)===!1||s>l&&this.right.forEachInner(r,Math.max(o-l,0),Math.min(this.length,s)-l,a+l)===!1)return!1},t.prototype.forEachInvertedInner=function(r,o,s,a){var l=this.left.length;if(o>l&&this.right.forEachInvertedInner(r,o-l,Math.max(s,l)-l,a+l)===!1||s<l&&this.left.forEachInvertedInner(r,Math.min(o,l),s,a)===!1)return!1},t.prototype.sliceInner=function(r,o){if(r==0&&o==this.length)return this;var s=this.left.length;return o<=s?this.left.slice(r,o):r>=s?this.right.slice(r-s,o-s):this.left.slice(r,s).append(this.right.slice(0,o-s))},t.prototype.leafAppend=function(r){var o=this.right.leafAppend(r);if(o)return new t(this.left,o)},t.prototype.leafPrepend=function(r){var o=this.left.leafPrepend(r);if(o)return new t(o,this.right)},t.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new t(this.left,new t(this.right,r)):new t(this,r)},t})($e);const Py=500;class Xe{constructor(t,n){this.items=t,this.eventCount=n}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let o,s;n&&(o=this.remapping(r,this.items.length),s=o.maps.length);let a=t.tr,l,i,c=[],u=[];return this.items.forEach((d,f)=>{if(!d.step){o||(o=this.remapping(r,f+1),s=o.maps.length),s--,u.push(d);return}if(o){u.push(new st(d.map));let m=d.step.map(o.slice(s)),p;m&&a.maybeStep(m).doc&&(p=a.mapping.maps[a.mapping.maps.length-1],c.push(new st(p,void 0,void 0,c.length+u.length))),s--,p&&o.appendMap(p,s)}else a.maybeStep(d.step);if(d.selection)return l=o?d.selection.map(o.slice(s)):d.selection,i=new Xe(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:i,transform:a,selection:l}}addTransform(t,n,r,o){let s=[],a=this.eventCount,l=this.items,i=!o&&l.length?l.get(l.length-1):null;for(let u=0;u<t.steps.length;u++){let d=t.steps[u].invert(t.docs[u]),f=new st(t.mapping.maps[u],d,n),m;(m=i&&i.merge(f))&&(f=m,u?s.pop():l=l.slice(0,l.length-1)),s.push(f),n&&(a++,n=void 0),o||(i=f)}let c=a-r.depth;return c>Ky&&(l=By(l,c),a-=c),new Xe(l.append(s),a)}remapping(t,n){let r=new Kf;return this.items.forEach((o,s)=>{let a=o.mirrorOffset!=null&&s-o.mirrorOffset>=t?r.maps.length-o.mirrorOffset:void 0;r.appendMap(o.map,a)},t,n),r}addMaps(t){return this.eventCount==0?this:new Xe(this.items.append(t.map(n=>new st(n))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],o=Math.max(0,this.items.length-n),s=t.mapping,a=t.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},o);let i=n;this.items.forEach(f=>{let m=s.getMirror(--i);if(m==null)return;a=Math.min(a,m);let p=s.maps[m];if(f.step){let h=t.steps[m].invert(t.docs[m]),g=f.selection&&f.selection.map(s.slice(i+1,m));g&&l++,r.push(new st(p,h,g))}else r.push(new st(p))},o);let c=[];for(let f=n;f<a;f++)c.push(new st(s.maps[f]));let u=this.items.slice(0,o).append(c).append(r),d=new Xe(u,l);return d.emptyItemCount()>Py&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let t=0;return this.items.forEach(n=>{n.step||t++}),t}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,o=[],s=0;return this.items.forEach((a,l)=>{if(l>=t)o.push(a),a.selection&&s++;else if(a.step){let i=a.step.map(n.slice(r)),c=i&&i.getMap();if(r--,c&&n.appendMap(c,r),i){let u=a.selection&&a.selection.map(n.slice(r));u&&s++;let d=new st(c.invert(),i,u),f,m=o.length-1;(f=o.length&&o[m].merge(d))?o[m]=f:o.push(d)}}else a.map&&r--},this.items.length,0),new Xe($e.from(o.reverse()),s)}}Xe.empty=new Xe($e.empty,0);function By(e,t){let n;return e.forEach((r,o)=>{if(r.selection&&t--==0)return n=o,!1}),e.slice(n)}class st{constructor(t,n,r,o){this.map=t,this.step=n,this.selection=r,this.mirrorOffset=o}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new st(n.getMap().invert(),n,this.selection)}}}class Mt{constructor(t,n,r,o,s){this.done=t,this.undone=n,this.prevRanges=r,this.prevTime=o,this.prevComposition=s}}const Ky=20;function jy(e,t,n,r){let o=n.getMeta(ct),s;if(o)return o.historyState;n.getMeta(Ku)&&(e=new Mt(e.done,e.undone,null,0,-1));let a=n.getMeta("appendedTransaction");if(n.steps.length==0)return e;if(a&&a.getMeta(ct))return a.getMeta(ct).redo?new Mt(e.done.addTransform(n,void 0,r,hr(t)),e.undone,Vl(n.mapping.maps),e.prevTime,e.prevComposition):new Mt(e.done,e.undone.addTransform(n,void 0,r,hr(t)),null,e.prevTime,e.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(a&&a.getMeta("addToHistory")===!1)){let l=n.getMeta("composition"),i=e.prevTime==0||!a&&e.prevComposition!=l&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Hy(n,e.prevRanges)),c=a?po(e.prevRanges,n.mapping):Vl(n.mapping.maps);return new Mt(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,hr(t)),Xe.empty,c,n.time,l??e.prevComposition)}else return(s=n.getMeta("rebased"))?new Mt(e.done.rebased(n,s),e.undone.rebased(n,s),po(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new Mt(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),po(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Hy(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((r,o)=>{for(let s=0;s<t.length;s+=2)r<=t[s+1]&&o>=t[s]&&(n=!0)}),n}function Vl(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((r,o,s,a)=>t.push(s,a));return t}function po(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let o=t.map(e[r],1),s=t.map(e[r+1],-1);o<=s&&n.push(o,s)}return n}function Fy(e,t,n){let r=hr(t),o=ct.get(t).spec.config,s=(n?e.undone:e.done).popEvent(t,r);if(!s)return null;let a=s.selection.resolve(s.transform.doc),l=(n?e.done:e.undone).addTransform(s.transform,t.selection.getBookmark(),o,r),i=new Mt(n?l:s.remaining,n?s.remaining:l,null,0,-1);return s.transform.setSelection(a).setMeta(ct,{redo:n,historyState:i})}let mo=!1,Gl=null;function hr(e){let t=e.plugins;if(Gl!=t){mo=!1,Gl=t;for(let n=0;n<t.length;n++)if(t[n].spec.historyPreserveItems){mo=!0;break}}return mo}function Jl(e){return e.setMeta(Ku,!0)}const ct=new be("history"),Ku=new be("closeHistory");function qy(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new se({key:ct,state:{init(){return new Mt(Xe.empty,Xe.empty,null,0,-1)},apply(t,n,r){return jy(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(t,n){let r=n.inputType,o=r=="historyUndo"?Hu:r=="historyRedo"?Fu:null;return!o||!t.editable?!1:(n.preventDefault(),o(t.state,t.dispatch))}}}})}function ju(e,t){return(n,r)=>{let o=ct.getState(n);if(!o||(e?o.undone:o.done).eventCount==0)return!1;if(r){let s=Fy(o,n,e);s&&r(t?s.scrollIntoView():s)}return!0}}const Hu=ju(!1,!0),Fu=ju(!0,!0);function U1(e){let t=ct.getState(e);return t?t.done.eventCount:0}function V1(e){let t=ct.getState(e);return t?t.undone.eventCount:0}function G1(e){return e.getMeta(ct)!=null}function wn(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-history",...t}}),e}var Ta=V("Undo",()=>()=>Hu);wn(Ta,{displayName:"Command<undo>"});var Ia=V("Redo",()=>()=>Fu);wn(Ia,{displayName:"Command<redo>"});var Ra=us({},"historyProviderConfig");wn(Ra,{displayName:"Ctx<historyProviderConfig>"});var qu=re(e=>qy(e.get(Ra.key)));wn(qu,{displayName:"Ctx<historyProviderPlugin>"});var La=je("historyKeymap",{Undo:{shortcuts:"Mod-z",command:e=>{const t=e.get(ce);return()=>t.call(Ta.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:e=>{const t=e.get(ce);return()=>t.call(Ia.key)}}});wn(La.ctx,{displayName:"KeymapCtx<history>"});wn(La.shortcuts,{displayName:"Keymap<history>"});var Wy=[Ra,qu,La,Ta,Ia].flat(),Uy=typeof global=="object"&&global&&global.Object===Object&&global,Vy=typeof self=="object"&&self&&self.Object===Object&&self,Wu=Uy||Vy||Function("return this")(),$r=Wu.Symbol,Uu=Object.prototype,Gy=Uu.hasOwnProperty,Jy=Uu.toString,Mn=$r?$r.toStringTag:void 0;function Yy(e){var t=Gy.call(e,Mn),n=e[Mn];try{e[Mn]=void 0;var r=!0}catch{}var o=Jy.call(e);return r&&(t?e[Mn]=n:delete e[Mn]),o}var Xy=Object.prototype,Qy=Xy.toString;function Zy(e){return Qy.call(e)}var ek="[object Null]",tk="[object Undefined]",Yl=$r?$r.toStringTag:void 0;function nk(e){return e==null?e===void 0?tk:ek:Yl&&Yl in Object(e)?Yy(e):Zy(e)}function rk(e){return e!=null&&typeof e=="object"}var ok="[object Symbol]";function sk(e){return typeof e=="symbol"||rk(e)&&nk(e)==ok}var ak=/\s/;function lk(e){for(var t=e.length;t--&&ak.test(e.charAt(t)););return t}var ik=/^\s+/;function ck(e){return e&&e.slice(0,lk(e)+1).replace(ik,"")}function qo(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Xl=NaN,uk=/^[-+]0x[0-9a-f]+$/i,dk=/^0b[01]+$/i,fk=/^0o[0-7]+$/i,pk=parseInt;function Ql(e){if(typeof e=="number")return e;if(sk(e))return Xl;if(qo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=qo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=ck(e);var n=dk.test(e);return n||fk.test(e)?pk(e.slice(2),n?2:8):uk.test(e)?Xl:+e}var ho=function(){return Wu.Date.now()},mk="Expected a function",hk=Math.max,gk=Math.min;function bk(e,t,n){var r,o,s,a,l,i,c=0,u=!1,d=!1,f=!0;if(typeof e!="function")throw new TypeError(mk);t=Ql(t)||0,qo(n)&&(u=!!n.leading,d="maxWait"in n,s=d?hk(Ql(n.maxWait)||0,t):s,f="trailing"in n?!!n.trailing:f);function m(I){var R=r,D=o;return r=o=void 0,c=I,a=e.apply(D,R),a}function p(I){return c=I,l=setTimeout(y,t),u?m(I):a}function h(I){var R=I-i,D=I-c,U=t-R;return d?gk(U,s-D):U}function g(I){var R=I-i,D=I-c;return i===void 0||R>=t||R<0||d&&D>=s}function y(){var I=ho();if(g(I))return k(I);l=setTimeout(y,h(I))}function k(I){return l=void 0,f&&r?m(I):(r=o=void 0,a)}function M(){l!==void 0&&clearTimeout(l),c=0,r=i=o=l=void 0}function E(){return l===void 0?a:k(ho())}function x(){var I=ho(),R=g(I);if(r=arguments,o=this,i=I,R){if(l===void 0)return p(i);if(d)return clearTimeout(l),l=setTimeout(y,t),m(i)}return l===void 0&&(l=setTimeout(y,t)),a}return x.cancel=M,x.flush=E,x}var Vu=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},Dr=jf(new Vu,"listener"),yk=new be("MILKDOWN_LISTENER"),Gu=e=>(e.inject(Dr,new Vu),async()=>{await e.wait(Hf);const{listeners:t}=e.get(Dr);t.beforeMount.forEach(c=>c(e)),await e.wait(Ff);const n=e.get(qt);let r=null,o=null,s=null,a=null;const l=bk(()=>{if(!a)return;const{doc:c}=a;if(t.updated.length>0&&r&&!r.eq(c)&&t.updated.forEach(u=>{u(e,c,r)}),t.markdownUpdated.length>0&&r&&!r.eq(c)){const u=n(c);t.markdownUpdated.forEach(d=>{d(e,u,o)}),o=u}r=c,a=null},200),i=new se({key:yk,view:()=>({destroy:()=>{l.cancel(),t.destroy.forEach(c=>c(e))}}),props:{handleDOMEvents:{focus:()=>(t.focus.forEach(c=>c(e)),!1),blur:()=>(t.blur.forEach(c=>c(e)),!1)}},state:{init:(c,u)=>{r=u.doc,o=n(u.doc)},apply:c=>{const u=c.selection;(!s&&u||s&&!u.eq(s))&&(t.selectionUpdated.forEach(d=>{d(e,u,s)}),s=u),!(!(c.docChanged||c.storedMarksSet)||c.getMeta("addToHistory")===!1)&&(a=c,l())}}});e.update(qf,c=>c.concat(i)),await e.wait(Wf),t.mounted.forEach(c=>c(e))});Gu.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var no=A.createContext({});function kk(){const{dom:e,editor:t,setLoading:n,editorFactory:r}=A.useContext(no),o=A.useRef(null);return A.useEffect(()=>{const s=o.current;if(!r||!s)return;e.current=s;const a=r(s);if(a)return n(!0),a.create().then(l=>{t.current=l}).finally(()=>{n(!1)}).catch(console.error),()=>{a.destroy().catch(console.error)}},[e,t,r,n]),o}var wk=()=>{const e=kk();return Ii.createElement("div",{"data-milkdown-root":!0,ref:e})},Ju=({children:e})=>{const t=A.useRef(void 0),[n,r]=A.useState(void 0),o=A.useRef(void 0),[s,a]=A.useState(!0),l=A.useMemo(()=>({loading:s,dom:t,editor:o,setLoading:a,editorFactory:n,setEditorFactory:r}),[s,n]);return Ii.createElement(no.Provider,{value:l},e)};function xk(e,t=[]){const n=A.useContext(no),r=A.useCallback(e,t);return A.useLayoutEffect(()=>{n.setEditorFactory(()=>r)},[n,r]),{loading:n.loading,get:()=>n.editor.current}}function vk(){const e=A.useContext(no),t=A.useCallback(()=>e.editor.current,[e.editor]);return[e.loading,t]}const Ck=re(()=>new se({props:{handleKeyDown(e,t){if(t.key!=="ArrowRight"||t.shiftKey||t.metaKey||t.ctrlKey||t.altKey||t.isComposing)return!1;const{state:n}=e,r=n.selection;if(!(r instanceof q)||!r.empty)return!1;let o=r.head,s=!1;const a=n.storedMarks?null:e.root.getSelection?.();if(a&&a.isCollapsed&&a.anchorNode&&e.dom.contains(a.anchorNode))try{const f=e.posAtDOM(a.anchorNode,a.anchorOffset);f!==o&&(o=f,s=!0)}catch{}const l=n.doc.resolve(o);if(!l.parent.isTextblock||l.parent.type.spec.code)return!1;const i=!s&&n.storedMarks||l.marks(),c=i.find(f=>f.type.spec.code);if(!c)return!1;const u=l.nodeAfter;if(u&&c.isInSet(u.marks))return!1;const d=n.tr;return s&&d.setSelection(q.create(n.doc,o)),e.dispatch(d.setStoredMarks(c.removeFromSet(i))),!0}}}));function go(e){const t=/^(.*)\|(\d+)$/.exec(e);return t?{label:t[1],width:Number(t[2])}:{label:e}}function Sk(e,t){return`${e}|${t}`}class Ak{constructor(t,n,r,o){this.node=t,this.view=n,this.getPos=r,this.onDestroy=o,this.dom=document.createElement("span"),this.dom.className="wiki-inline-img-wrap",this.dom.contentEditable="false",this.img=document.createElement("img"),this.img.className="wiki-inline-img",this.dom.appendChild(this.img),this.dom.addEventListener("mousedown",s=>{if(s.button!==0||s.target.closest(".amx-img-resize, .amx-src-btn, .amx-img-srcline"))return;const a=()=>{const l=this.getPos();l!=null&&(this.view.dispatch(this.view.state.tr.setSelection(Qe.create(this.view.state.doc,l))),this.view.focus())};om(this.view,this.dom,s,a)||(s.preventDefault(),a())}),sm(this.dom,n,()=>this.openSource()),Uf(this.dom,this.img,()=>go(this.node.attrs.alt??"").label||Gf(this.node.attrs.src??"")),this.apply(t)}node;view;getPos;onDestroy;dom;img;drop=null;srcLine=null;apply(t){const{label:n,width:r}=go(t.attrs.alt??"");this.img.src=t.attrs.src??"",this.img.alt=n,this.img.style.width=r?`${r}px`:"",t.attrs.title&&(this.img.title=t.attrs.title)}update(t){return t.type.name!==this.node.type.name?!1:(this.node=t,this.apply(t),!0)}selectNode(){this.dom.dataset.selected="",this.view.editable&&(this.drop=Vf(this.dom,this.img,t=>this.commit(t)))}deselectNode(){delete this.dom.dataset.selected,this.drop?.(),this.drop=null}syncSelection(){const t=this.getPos();if(t==null)return delete this.dom.dataset.rangeSelected,this.deselectNode();const n=this.view.state.selection;n.from<t+this.node.nodeSize&&n.to>t?this.dom.dataset.rangeSelected="":delete this.dom.dataset.rangeSelected;const r=n instanceof Qe&&n.from===t;r&&!this.dom.hasAttribute("data-selected")?this.selectNode():!r&&this.dom.hasAttribute("data-selected")&&this.deselectNode()}openSource(){if(this.srcLine){this.srcLine.focus(),this.srcLine.select();return}const t=String(this.node.attrs.src??""),n=document.createElement("input");n.className="embed-src-input amx-img-srcline",n.value=`??t})`;let r=!1;const o=s=>{if(r)return;r=!0;const a=n.value.trim();n.remove(),this.srcLine=null,s&&this.commitSource(a),this.view.focus()};n.addEventListener("keydown",s=>{s.stopPropagation(),s.key==="Enter"?(s.preventDefault(),o(!0)):s.key==="Escape"&&(s.preventDefault(),o(!1))}),n.addEventListener("blur",()=>o(!0)),this.dom.insertBefore(n,this.img),this.srcLine=n,n.focus(),n.select()}commitSource(t){const n=/^!\[([^\]]*)\]\((.*)\)$/.exec(t),r=this.getPos();if(!n||r==null)return;const o=n[2].trim();if(!o)return;const s=/^(https?:|data:|blob:)/i.test(o)?o:Ri(o,!0);this.view.dispatch(this.view.state.tr.setNodeMarkup(r,void 0,{...this.node.attrs,alt:n[1],src:s}))}commit(t){const n=this.getPos();if(n==null)return;const{label:r}=go(this.node.attrs.alt??""),o=this.view.state.tr.setNodeMarkup(n,void 0,{...this.node.attrs,alt:Sk(r,t)});o.setSelection(Qe.create(o.doc,n)),this.view.dispatch(o)}stopEvent(t){return t.target?.closest?.(".amx-img-srcline")?!0:t.type==="mousedown"||t.type.startsWith("pointer")}ignoreMutation(){return!0}destroy(){this.drop?.(),this.onDestroy()}}function Mk(){return re(()=>{const e=new Set;return new se({view:()=>({update:()=>{for(const t of e)t.syncSelection()}}),props:{nodeViews:{image:(t,n,r)=>{let o;return o=new Ak(t,n,r,()=>e.delete(o)),e.add(o),o}}}})})}Be({"blocklabel.text":{zh:"正文",en:"Text"},"blocklabel.heading":{zh:"标题 {n}",en:"Heading {n}"},"blocklabel.code":{zh:"代码",en:"Code"},"blocklabel.todo":{zh:"待办",en:"To-do"},"blocklabel.ordered":{zh:"有序列表",en:"Numbered list"},"blocklabel.bullet":{zh:"无序列表",en:"Bulleted list"},"blocklabel.quote":{zh:"引用",en:"Quote"}});const cn="[!fold]-",Nk=/^\[![\w-]+\]/;function Ek(e,t){return e==="code_block"?!1:e!=="heading"||t.kind!=="ordered"}function Yu(e){return e.parent.textBetween(0,e.parentOffset,void 0,"")}const Tk={"【":"[","】":"]","》":">","|":"|","·":"`","¥":"$","#":"#"};function Ik(e){return/^\d{1,9}。$/.test(e)?`${e.slice(0,-1)}.`:e.replace(/[【】》|·¥#]/g,t=>Tk[t]??t)}function Rk(e){const t=Ik(e.replace(/\u00A0/g," "));let n;return(n=/^(#{1,6})$/.exec(t))?{kind:"heading",level:n[1].length}:/^[-*+]$/.test(t)?{kind:"bullet"}:(n=/^(\d{1,9})\.$/.exec(t))?{kind:"ordered",order:Number(n[1])}:(n=/^- \[( |x)\]$/i.exec(t))?{kind:"task",checked:n[1].toLowerCase()==="x"}:(n=/^\[( |x)?\]$/i.exec(t))?{kind:"task",checked:(n[1]??"").toLowerCase()==="x"}:t==="|"?{kind:"quote"}:t===">"?{kind:"fold"}:(n=/^```([A-Za-z0-9+#._-]*)$/.exec(t))?{kind:"code",lang:n[1]}:t==="$$"?{kind:"math"}:null}function Lk(e){const t=Rk(Yu(e));return t?.kind==="fold"&&e.parentOffset<e.parent.content.size?{kind:"quote",rejoin:!0}:t}function $k(e,t,n){const r=e.state.selection.$from.start();n&&e.dispatch(e.state.tr.insertText(n)),e.dispatch(Jl(e.state.tr));const o=Yt(e,t,{from:r,to:e.state.selection.from});return e.dispatch(Jl(e.state.tr)),o||!!n}function $a(e){const t=e.replace(/\u00A0/g," ");let n;return(n=/^(#{1,6}) $/.exec(t))?{kind:"heading",level:n[1].length}:/^[-*+] $/.test(t)?{kind:"bullet"}:(n=/^(\d{1,9})\. $/.exec(t))?{kind:"ordered",order:Number(n[1])}:(n=/^- \[( |x)\] $/i.exec(t))?{kind:"task",checked:n[1].toLowerCase()==="x"}:t==="> "?{kind:"quote"}:null}function Zl(e,t){const n=Yu(e),r=n.lastIndexOf("/");if(r<0)return null;const o=r>0&&/\s/.test(n[r-1])?1:0;return{from:e.start()+r-o,to:e.pos}}function Dk(e,t){const n=[];let r="";e.state.doc.descendants((l,i)=>(l.isText?(n.push({at:r.length,pos:i}),r+=l.text??""):l.isLeaf?(n.push({at:r.length,pos:i}),r+=""):l.isTextblock&&r&&(r+=`
|
|
29
|
+
`),!0));const o=r.lastIndexOf(t);if(o<0)return null;const s=o+t.length;let a=null;for(const l of n)l.at<=s&&(a=l.pos+(s-l.at));return a}function _k(e){const{state:t}=e,n=t.selection.from;if(!_r(t.selection.$from,["list_item","blockquote"]))return!1;const r=t.tr,o=gr(r,n,["list_item","blockquote"]);return r.steps.length?(r.setSelection(fe.near(r.doc.resolve(o))),e.dispatch(r.scrollIntoView()),!0):!1}function zk(e,t){const{state:n}=e,r=n.selection.to;if(r>=fe.atEnd(n.doc).$head.pos)return null;const o=n.doc.slice(r,n.doc.content.size);if(o.content.size===0)return null;const s=n.schema.topNodeType.createAndFill(void 0,o.content);if(!s||!s.textBetween(0,s.content.size,`
|
|
30
|
+
`,"").trim())return null;const a=t(s).trim();return a?(e.dispatch(n.tr.delete(r,n.doc.content.size).scrollIntoView()),a):null}function Ok(e){for(const t of e){if(t.name==="heading")return P("blocklabel.heading",{n:String(t.level??1)});if(t.name==="code_block")return P("blocklabel.code");if(t.name==="list_item"&&t.checked!=null)return P("blocklabel.todo");if(t.name==="ordered_list")return P("blocklabel.ordered");if(t.name==="bullet_list")return P("blocklabel.bullet");if(t.name==="blockquote")return P("blocklabel.quote")}return P("blocklabel.text")}function In(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}const _r=(e,t)=>t.some(n=>In(e,n)!==null);function gr(e,t,n){let r=t;for(let o=0;o<32;o++){const s=e.doc.resolve(r);if(!_r(s,n))break;const a=s.blockRange(),l=a?as(a):null;if(!a||l==null)break;const i=e.steps.length;if(e.lift(a,l),e.steps.length===i)break;r=e.mapping.slice(i).map(r)}return r}function Yt(e,t,n,r){const{state:o}=e,{schema:s}=o,a=s.nodes.paragraph,l=s.nodes.heading,i=s.nodes.blockquote,c=s.nodes.bullet_list,u=s.nodes.ordered_list,d=s.nodes.list_item;if(!a)return!1;const f=o.tr;n&&n.to>n.from&&f.delete(n.from,n.to);let m=n?n.from:o.selection.from,p=f.doc.resolve(m);if(!p.parent.isTextblock)return!1;const h=In(p,"list_item");if(h!==null&&(t.kind==="bullet"||t.kind==="ordered"||t.kind==="task")){const E=p.node(h);if(t.kind==="task")f.setNodeMarkup(p.before(h),void 0,{...E.attrs,checked:t.checked??!1});else{const x=h-1,I=p.node(x),R=t.kind==="bullet"?c:u;if(!R||x<1||!/_list$/.test(I.type.name))return!1;const D=t.kind==="ordered"?{order:t.order??1,spread:!1}:{spread:!1};f.setNodeMarkup(p.before(x),R,D),f.setNodeMarkup(p.before(h),void 0,{...E.attrs,checked:null})}return e.dispatch(f.scrollIntoView()),!0}if(t.kind==="heading"||t.kind==="text"){const E=t.kind==="heading"?l:a;if(!E||_r(p,["list_item","blockquote"])&&(m=gr(f,m,["list_item","blockquote"]),p=f.doc.resolve(m),!p.parent.isTextblock))return!1;const x=p.index(-1);return p.node(-1).canReplaceWith(x,x+1,E)?(f.setBlockType(p.before(),p.after(),E,t.kind==="heading"?{level:t.level??1}:void 0),r?.(f,m),e.dispatch(f.scrollIntoView()),!0):!1}if(t.kind==="code"||t.kind==="math"){const E=s.nodes.code_block;if(t.kind==="code"&&!E)return!1;let x=f.doc.resolve(m);if(t.kind==="code"&&_r(x,["list_item"])&&(m=gr(f,m,["list_item"]),x=f.doc.resolve(m)),!x.parent.isTextblock)return!1;const I=f.doc.textBetween(x.pos,x.end(),`
|
|
31
|
+
`,`
|
|
32
|
+
`);I&&f.delete(x.pos,x.end()),x=f.doc.resolve(f.mapping.map(m));const R=x.before(),D=x.after();let U;if(t.kind==="math")f.insertText("$$ $$",R+1),f.setSelection(fe.near(f.doc.resolve(R+4))),U=f.mapping.map(D);else{const Re=E.create({language:t.lang||null});f.replaceWith(R,D,Re),f.setSelection(fe.near(f.doc.resolve(R+1))),U=R+Re.nodeSize}return I&&f.insert(U,a.create(null,s.text(I))),e.dispatch(f.scrollIntoView()),!0}if(t.kind==="quote"||t.kind==="fold"){if(!i)return!1;if(In(p,"blockquote")===null){if(In(p,"list_item")!==null&&(m=gr(f,m,["list_item"]),p=f.doc.resolve(m),!p.parent.isTextblock))return!1;p.parent.type===l&&(f.setBlockType(p.before(),p.after(),a),p=f.doc.resolve(m));const E=p.blockRange(),x=E&&Co(E,i);if(!x)return!1;const I=f.steps.length;if(f.wrap(E,x),m=f.mapping.slice(I).map(m),p=f.doc.resolve(m),t.rejoin){const R=In(p,"blockquote");if(R!==null){const D=p.after(R);f.doc.resolve(D).nodeAfter?.type===i&&fr(f.doc,D)&&f.join(D);const U=p.before(R);f.doc.resolve(U).nodeBefore?.type===i&&fr(f.doc,U)&&f.join(U)}}}if(t.kind==="fold"&&!Nk.test(p.parent.textContent)){const E=p.start();f.insertText(cn,E),f.setSelection(fe.near(f.doc.resolve(E+cn.length)))}return e.dispatch(f.scrollIntoView()),!0}const g=t.kind==="ordered"?u:c;if(!g||!d)return!1;p.parent.type===l&&(f.setBlockType(p.before(),p.after(),a),p=f.doc.resolve(m));const y=p.blockRange(),k=y&&Co(y,g,t.kind==="ordered"?{order:t.order??1}:void 0);if(!k)return!1;if(f.wrap(y,k),t.kind==="task"){const E=f.doc.nodeAt(y.start+1);E&&E.type.name==="list_item"&&f.setNodeMarkup(y.start+1,void 0,{...E.attrs,checked:t.checked??!1})}const M=f.doc.resolve(y.start).nodeBefore;return M&&M.type===g&&fr(f.doc,y.start)&&f.join(y.start),e.dispatch(f.scrollIntoView()),!0}function J1(e,t,n){const{state:r}=e,o=r.doc.nodeAt(t);if(!o||!o.type.spec.code)return!1;const{schema:s}=r,{paragraph:a,heading:l,blockquote:i,bullet_list:c,ordered_list:u,list_item:d}=s.nodes;if(!a)return!1;const f=o.textContent.split(`
|
|
33
|
+
`),m=g=>a.create(null,g?s.text(g):null);let p;if(n.kind==="text"||n.kind==="heading"){if(n.kind==="heading"&&!l)return!1;p=f.map(g=>n.kind==="heading"&&g?l.create({level:n.level??1},s.text(g)):m(g))}else if(n.kind==="bullet"||n.kind==="ordered"||n.kind==="task"){const g=n.kind==="ordered"?u:c;if(!g||!d)return!1;const y=n.kind==="task"?{checked:n.checked??!1}:null,k=f.filter(E=>E.trim()),M=(k.length?k:[""]).map(E=>d.create(y,m(E)));p=[g.create(n.kind==="ordered"?{order:n.order??1}:null,M)]}else if(n.kind==="quote"||n.kind==="fold"){if(!i)return!1;p=[i.create(null,n.kind==="fold"?[a.create(null,s.text(cn)),o]:[o])]}else return!1;const h=r.tr;try{h.replaceWith(t,t+o.nodeSize,p)}catch{return!1}return h.setSelection(fe.near(h.doc.resolve(Math.min(t+1,h.doc.content.size)))),e.dispatch(h.scrollIntoView()),!0}Be({"mdcallout.expand":{zh:"展开",en:"Expand"},"mdcallout.collapse":{zh:"折叠",en:"Collapse"},"mdcallout.title":{zh:"折叠标题",en:"Toggle title"},"mdcallout.empty":{zh:"空折叠块,点击添加内容",en:"Empty toggle. Click to add content."},"mdcallout.source":{zh:"编辑折叠源码",en:"Edit toggle source"},"mdcallout.type.note":{zh:"笔记",en:"Note"},"mdcallout.type.abstract":{zh:"摘要",en:"Abstract"},"mdcallout.type.info":{zh:"信息",en:"Info"},"mdcallout.type.todo":{zh:"待办",en:"Todo"},"mdcallout.type.tip":{zh:"提示",en:"Tip"},"mdcallout.type.success":{zh:"成功",en:"Success"},"mdcallout.type.question":{zh:"问题",en:"Question"},"mdcallout.type.warning":{zh:"警告",en:"Warning"},"mdcallout.type.failure":{zh:"失败",en:"Failure"},"mdcallout.type.danger":{zh:"危险",en:"Danger"},"mdcallout.type.bug":{zh:"缺陷",en:"Bug"},"mdcallout.type.example":{zh:"示例",en:"Example"},"mdcallout.type.quote":{zh:"引用",en:"Quote"}});const Pk={summary:"abstract",tldr:"abstract",hint:"tip",important:"tip",check:"success",done:"success",help:"question",faq:"question",caution:"warning",attention:"warning",fail:"failure",missing:"failure",error:"danger",cite:"quote"},Xu={note:'<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/>',abstract:'<rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M12 11h4"/><path d="M12 16h4"/><path d="M8 11h.01"/><path d="M8 16h.01"/>',info:'<circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/>',todo:'<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',tip:'<path d="M12 3q1 4 4 6.5t3 5.5a1 1 0 0 1-14 0 5 5 0 0 1 1-3 1 1 0 0 0 5 0c0-2-1.5-3-1.5-5q0-2 2.5-4"/>',success:'<path d="M20 6 9 17l-5-5"/>',question:'<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/>',warning:'<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/>',failure:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',danger:'<path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>',bug:'<path d="M12 20v-9"/><path d="M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z"/><path d="M14.12 3.88 16 2"/><path d="M21 21a4 4 0 0 0-3.81-4"/><path d="M21 5a4 4 0 0 1-3.55 3.97"/><path d="M22 13h-4"/><path d="M3 21a4 4 0 0 1 3.81-4"/><path d="M3 5a4 4 0 0 0 3.55 3.97"/><path d="M6 13H2"/><path d="m8 2 1.88 1.88"/><path d="M9 7.13V6a3 3 0 1 1 6 0v1.13"/>',example:'<path d="M3 5h.01"/><path d="M3 12h.01"/><path d="M3 19h.01"/><path d="M8 5h13"/><path d="M8 12h13"/><path d="M8 19h13"/>',quote:'<path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/><path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z"/>'};function Bk(e){const t=Pk[e]??e;return t in Xu?t:null}function Qu(e){const t=e.children?.[0];if(e.type==="blockquote"&&t?.type==="paragraph"&&t.position&&/^\[![\w-]+\][+-]?/.test(t.children?.[0]?.value??"")){const n=ku(t);n.length>1&&e.children.splice(0,1,...n)}e.children?.forEach(Qu)}const Kk=Ne("amadeusCalloutTitle",()=>()=>Qu),Zu=e=>e.replace(/^((?:[ \t]*>[ \t]?)+)\\\[!/gm,"$1[!"),ed=/^\[!([\w-]+)\]([+-])?/,jk=/^(#{1,6}|[-*+]) /;function mn(e){if(e.type.name!=="blockquote")return null;const t=e.firstChild,n=t&&t.isTextblock?ed.exec(t.textContent):null;if(!n||!t)return null;const r=/[ \u00a0]/.test(t.textContent[n[0].length]??"")?1:0,o=jk.exec(t.textContent.slice(n[0].length+r));return{type:n[1].toLowerCase(),raw:n[1],marker:n[2],token:n[0],hideLen:n[0].length+r,first:t,mark:o?{at:n[0].length+r,len:o[0].length,cls:o[1][0]==="#"?`h${o[1].length}`:"bullet"}:null}}function td(e,t){e.doc.descendants((n,r)=>{const o=mn(n);if(o?.marker!=="-")return;const s=r+1+o.first.nodeSize,a=r+n.nodeSize-1;if(t.some(([l,i])=>l<a&&i>s&&!(l<=r&&i>=r+n.nodeSize))){const l=r+2+o.raw.length+3;e.insertText("+",l,l+1)}})}function Y1(e,t,n){td(e,[[t,n]])}function Hk(e,t){const n=[];if(e.forEach((o,s)=>{!o.docChanged||o.getMeta("uiEvent")!=="drop"||o.mapping.maps.forEach((a,l)=>{a.forEach((i,c,u,d)=>{if(d<=u)return;let f=o.mapping.slice(l+1).map(u,1),m=o.mapping.slice(l+1).map(d,-1);for(let p=s+1;p<e.length;p++)f=e[p].mapping.map(f,1),m=e[p].mapping.map(m,-1);m>f&&n.push([f,m])})})}),!n.length)return null;const r=t.tr;return td(r,n),r.docChanged?r:null}function at(e,t=!1){for(let n=1;n<=e.depth;n++){const r=t?n:e.depth+1-n,o=e.node(r);if(o.type.name!=="blockquote")continue;const s=mn(o);if(!s)continue;const a=e.start(r),l=e.pos<a+s.first.nodeSize;if(!(t&&(s.marker!=="-"||l)))return{...s,node:o,marker:s.marker,collapsed:s.marker==="-",bqPos:e.before(r),bqStart:a,afterBq:e.after(r),headEnd:a+1+s.first.content.size,inHead:l,markerPos:a+1+s.type.length+3,hidden:[[a+1,a+1+s.hideLen],...s.mark?[[a+1+s.mark.at,a+1+s.mark.at+s.mark.len]]:[]]}}return null}const Fk=e=>{const t=at(e);return t&&t.collapsed?t:null},nd="--amx-fold-scroll-buffer",nn=e=>parseFloat(e.style.getPropertyValue(nd))||0,bo=(e,t)=>{e.style.setProperty(nd,`${Math.max(0,Math.ceil(t))}px`)},Nn=new WeakMap,dr=new WeakMap;function qk(e,t){Nn.get(e)?.(),dr.get(e)?.();const n=e.scrollTop,r=n+e.clientHeight;bo(e,nn(e)+e.scrollHeight),t();let o=0,s=!0;const a=performance.now(),l=()=>{const f=e.scrollHeight-nn(e),m=Math.max(0,e.scrollTop+e.clientHeight-f);m<nn(e)&&bo(e,m),nn(e)||(e.removeEventListener("scroll",l),dr.delete(e))},i=()=>{l(),nn(e)&&(e.addEventListener("scroll",l,{passive:!0}),dr.set(e,()=>{e.removeEventListener("scroll",l),dr.delete(e)}))},c=()=>{e.removeEventListener("wheel",d),e.removeEventListener("touchmove",d),e.removeEventListener("keydown",d)},u=()=>{const f=nn(e),m=e.scrollHeight-f;bo(e,Math.max(0,r-m)),e.scrollTop=n,s&&performance.now()-a<260?o=requestAnimationFrame(u):(c(),Nn.delete(e),i())},d=()=>{s&&(s=!1,cancelAnimationFrame(o),c(),Nn.delete(e),requestAnimationFrame(()=>{Nn.has(e)||i()}))};Nn.set(e,d),e.addEventListener("wheel",d,{passive:!0,once:!0}),e.addEventListener("touchmove",d,{passive:!0,once:!0}),e.addEventListener("keydown",d,{once:!0}),u()}let Wk=0;function ei(e,t){const n=e.state.doc.nodeAt(t.bqPos),r=!!n&&!!mn(n),o=r?++Wk:0;if(r){e.dispatch(e.state.tr.setMeta(Oe,{foldStart:{at:t.bqPos,id:o}}));const l=e.nodeDOM(t.bqPos);l instanceof HTMLElement&&l.offsetHeight}const s=()=>{const l=e.state.tr;e.dispatch(t.marker?l.insertText(t.collapsed?"+":"-",t.markerPos,t.markerPos+1):l.insertText("-",t.markerPos,t.markerPos))},a=e.dom.closest(".amx-pane.amx-editor");t.marker&&a?qk(a,s):s(),r&&setTimeout(()=>{e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(Oe,{foldEnd:o}))},matchMedia("(prefers-reduced-motion: reduce)").matches?0:230)}function br(e){const t=e.state.selection;if(!t.empty||!e.hasFocus()||e.composing)return;const n=at(t.$from);if(!n||n.type!=="fold"||!n.inHead||Oe.getState(e.state)?.srcAt===n.bqPos||t.from!==n.hidden[n.hidden.length-1][1])return;const r=e.dom.ownerDocument.getSelection(),o=r?.anchorNode;if(!r?.isCollapsed||!o||!e.dom.contains(o)||e.posAtDOM(o,r.anchorOffset)!==t.from)return;const s=e.nodeDOM(n.bqStart);if(!(s instanceof HTMLElement))return;const a=document.createTreeWalker(s,NodeFilter.SHOW_TEXT);let l;for(;l=a.nextNode();){if(!l.textContent||l.parentElement?.closest(".callout-syntax,button")||l.parentElement?.closest(".ProseMirror-widget")||e.posAtDOM(l,0)!==t.from)continue;if(o===l&&r.anchorOffset===0)return;const i=document.createRange();i.setStart(l,0),i.collapse(!0),r.removeAllRanges(),r.addRange(i);return}}const Oe=new be("amadeus-callout-src");function rd(e,t){if(!e.editable||t.isComposing)return!1;const{state:n}=e,r=at(n.selection.$from);if(!r||r.type!=="fold"||Oe.getState(n)?.srcAt===r.bqPos)return!1;if(!r.inHead){const{$from:s,empty:a}=n.selection;return t.key!=="Enter"||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||!a||s.parent.type.name!=="paragraph"||s.parent.content.size!==0||s.node(s.depth-1)!==r.node||s.index(s.depth-1)===r.node.childCount-1?!1:(e.dispatch(n.tr.split(s.pos).scrollIntoView()),!0)}const o=r.hidden[r.hidden.length-1][1];if(t.key==="Home"||t.key==="ArrowLeft"&&t.metaKey)return e.dispatch(n.tr.setSelection(q.create(n.doc,t.shiftKey?Math.max(o,n.selection.anchor):o,o))),br(e),!0;if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return!1;if(t.key==="ArrowLeft"&&n.selection.empty&&n.selection.from<=o){const s=q.near(n.doc.resolve(r.bqPos),-1);return s.from<r.bqPos&&e.dispatch(n.tr.setSelection(s)),!0}if(t.key==="Backspace"&&n.selection.empty&&n.selection.from<=o){const s=[n.schema.nodes.paragraph.create(null,r.first.content.cut(o-r.bqStart-1))];r.node.forEach((l,i,c)=>{c>0&&s.push(l)});const a=n.tr.replaceWith(r.bqPos,r.afterBq,s);return e.dispatch(a.setSelection(q.near(a.doc.resolve(r.bqPos+1))).scrollIntoView()),!0}if(t.key==="Enter"&&n.selection.$from.sameParent(n.selection.$to)){const s=n.tr.deleteSelection();r.marker!=="+"&&s.insertText("+",r.markerPos,r.markerPos+(r.marker?1:0));const a=Math.max(s.selection.from,s.mapping.map(o));return s.split(a,1,[{type:n.schema.nodes.paragraph}]),e.dispatch(s.setSelection(q.near(s.doc.resolve(a+2))).scrollIntoView()),!0}return!1}function ti(e){const t=e.selection;if(!t.empty)return null;const n=at(t.$from);if(!n||!n.inHead||Oe.getState(e)?.srcAt===n.bqPos)return null;const r=n.hidden[n.hidden.length-1][1];return t.from<r?r:null}function Uk(e,t,n){const r=e.doc.content.size;if(t<0||t>r)return null;const o=e.doc.resolve(t),s=at(o);if(!s||Oe.getState(e)?.srcAt===s.bqPos)return null;for(const[a,l]of s.hidden)if(t>a&&t<l)return n>0?l:a;return null}function Vk(){return re(()=>new se({key:Oe,state:{init:()=>({srcAt:null,animations:[]}),apply:(e,t)=>{const n=e.getMeta(Oe);let r=t.animations.map(a=>({...a,at:e.mapping.map(a.at)}));if(n?.foldStart&&(r=[...r.filter(a=>a.at!==n.foldStart.at),n.foldStart]),n?.foldEnd&&(r=r.filter(a=>a.id!==n.foldEnd)),n&&"srcAt"in n)return{srcAt:n.srcAt??null,animations:r};if(t.srcAt===null)return{srcAt:null,animations:r};const o=e.mapping.map(t.srcAt),s=e.doc.nodeAt(o);return{srcAt:s&&mn(s)&&e.selection.from>o&&e.selection.to<o+s.nodeSize?o:null,animations:r}}},view(e){return br(e),{update:br}},appendTransaction(e,t,n){const r=Hk(e,n);if(r)return r;const o=n.selection;if(!o.empty)return null;const s=at(o.$from);if(s?.type==="fold"&&s.inHead&&Oe.getState(n)?.srcAt!==s.bqPos){const u=s.hidden[s.hidden.length-1][1];if(o.from<u)return n.tr.setSelection(q.create(n.doc,u))}const a=at(o.$from,!0);if(!a)return null;if(a.type==="fold")return n.tr.setSelection(q.create(n.doc,a.headEnd));const l=u=>u.from<a.bqStart||u.from>=a.afterBq,i=q.near(n.doc.resolve(Math.min(a.afterBq,n.doc.content.size)),1);if(l(i))return n.tr.setSelection(i);const c=q.near(n.doc.resolve(Math.max(a.bqStart-1,0)),-1);return l(c)?n.tr.setSelection(c):n.tr.setSelection(q.create(n.doc,a.headEnd))},props:{handleDOMEvents:{blur:e=>(Oe.getState(e.state)?.srcAt!==null&&e.dispatch(e.state.tr.setMeta(Oe,{srcAt:null})),!1)},handleKeyDown(e,t){if(rd(e,t))return!0;if((t.key==="Enter"||t.key==="Delete")&&!t.isComposing&&!t.metaKey&&!t.ctrlKey&&!t.altKey){const r=ti(e.state);r!=null&&e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,r)))}if((t.key==="ArrowLeft"||t.key==="ArrowRight")&&!t.shiftKey){const r=e.state.selection;if(r.empty){const o=t.key==="ArrowRight"?1:-1,s=Uk(e.state,r.from+o,o);if(s!==null)return e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,s))),!0}return!1}if(t.key!=="Enter"||t.isComposing)return!1;const n=Fk(e.state.selection.$from);return n&&e.dispatch(e.state.tr.insertText("+",n.markerPos,n.markerPos+1)),!1},handleTextInput(e,t,n,r){const o=t===n?ti(e.state):null;if(o!=null&&t<o){const u=e.state.tr.insertText(r,o);return e.dispatch(u.setSelection(q.create(u.doc,o+r.length)).scrollIntoView()),!0}if(!r.includes("]"))return!1;const{state:s}=e,a=s.doc.resolve(t);if(!a.parent.isTextblock||a.depth<2||!a.sameParent(s.doc.resolve(n))||a.node(-1).type.name!=="blockquote"||a.index(-1)!==0)return!1;const l=a.start(),i=a.parent,c=i.textBetween(0,t-l,void 0,"")+r+i.textBetween(n-l,i.content.size,void 0,"");return!c.startsWith(cn)||!ed.test(c.slice(cn.length))?!1:(e.dispatch(s.tr.insertText(r,t,n).delete(l,l+cn.length).scrollIntoView()),!0)},handleClick(e,t){const n=at(e.state.doc.resolve(t));if(!n||!n.inHead||Oe.getState(e.state)?.srcAt===n.bqPos)return!1;if(n.type==="fold"){if(!e.editable)return!1;const r=Math.max(n.hidden[n.hidden.length-1][1],Math.min(t,n.headEnd));return e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,r))),e.focus(),br(e),!0}return n.marker?(ei(e,n),!0):!1},handleDoubleClick(e,t){const n=at(e.state.doc.resolve(t));return!n||!n.inHead||n.type==="fold"||e.dispatch(e.state.tr.setMeta(Oe,{srcAt:n.bqPos})),!1},decorations(e){const t=[];return e.doc.descendants((n,r)=>{if(n.type.name!=="blockquote")return!0;const o=mn(n);if(o){const{type:s,marker:a,token:l,hideLen:i,mark:c}=o,u=a==="-",d=Oe.getState(e),f=d?.srcAt===r,m=s==="fold"?null:Bk(s);t.push(te.node(r,r+n.nodeSize,{class:`callout callout-${s}${m&&m!==s?` callout-${m}`:""}${u?" callout-collapsed":""}`,"data-callout":s,...d?.animations.some(y=>y.at===r)?{"data-fold-animating":""}:{}})),t.push(te.inline(r+2,r+2+l.length,{class:"callout-token"}));const p=r+1,h=p+o.first.nodeSize;if(s==="fold"){const y=!f&&o.first.content.size===i+(c?.len??0);f||t.push(te.widget(r+2+i+(c?.len??0),()=>{const k=document.createElement("span");return k.className="callout-title-anchor",k.contentEditable="false",k.setAttribute("aria-hidden","true"),k.textContent="",k},{side:-1,ignoreSelection:!0,key:"ca"})),t.push(te.node(p,h,{class:"callout-toggle-title",...y?{"data-placeholder":P("mdcallout.title")}:{}}))}if(c&&t.push(te.node(p,h,{class:`callout-title-${c.cls}`})),s!=="fold"){const y=Xu[m??"note"];if(t.push(te.widget(r+2,()=>{const k=document.createElement("span");return k.className="callout-icon",k.contentEditable="false",k.setAttribute("aria-hidden","true"),k.innerHTML=`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${y}</svg>`,k},{side:-1,ignoreSelection:!0,key:`ci:${m??"note"}`})),!f&&o.first.content.size===i+(c?.len??0)){const k=m?P(`mdcallout.type.${m}`):o.raw.charAt(0).toUpperCase()+o.raw.slice(1);t.push(te.widget(h-1,()=>{const M=document.createElement("span");return M.className="callout-default-title",M.contentEditable="false",M.textContent=k,M},{side:-1,ignoreSelection:!0,key:`cd:${k}`}))}}f||(t.push(te.inline(r+2,r+2+i,{class:"callout-syntax"})),c&&t.push(te.inline(r+2+c.at,r+2+c.at+c.len,{class:`callout-syntax callout-syntax-${c.cls}`})));const g=s==="fold"?r+2:r+2+o.first.content.size;(s==="fold"||a)&&t.push(te.widget(g,(y,k)=>{const M=document.createElement("button");M.className=`callout-chevron${u?" collapsed":""}`,M.type="button",M.title=u?P("mdcallout.expand"):P("mdcallout.collapse"),M.setAttribute("aria-label",M.title),M.setAttribute("aria-expanded",String(!u)),M.innerHTML='<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill="currentColor" d="M5.5 3.8a.65.65 0 0 1 1.02-.53l5.3 3.67a1.3 1.3 0 0 1 0 2.12l-5.3 3.67a.65.65 0 0 1-1.02-.53z"/></svg>',M.contentEditable="false",M.addEventListener("mousedown",D=>{D.preventDefault(),D.stopPropagation()});const E=()=>{const D=k();return D==null?null:at(y.state.doc.resolve(D))},x=()=>{const D=E();D&&ei(y,D)};let I=null;const R=()=>{const D=I??E()?.bqPos;(D==null?null:y.nodeDOM(D+1))?.querySelector(".callout-chevron")?.focus()};return M.addEventListener("keydown",D=>{D.key!==" "&&D.key!=="Enter"||(D.preventDefault(),D.stopPropagation(),I=E()?.bqPos??null,document.addEventListener("keyup",R,{capture:!0,once:!0}),x())}),M.addEventListener("click",D=>{D.preventDefault(),D.stopPropagation(),I=E()?.bqPos??null,x(),D.detail===0&&queueMicrotask(R)}),M},{side:s==="fold"?-1:1,ignoreSelection:!0,stopEvent:()=>!0,key:`cf:${s==="fold"?"f":"c"}:${a??""}`})),s==="fold"&&(t.push(te.widget(r+2,(y,k)=>{const M=document.createElement("button");return M.type="button",M.className="amx-src-btn callout-source",M.contentEditable="false",M.textContent="</>",M.title=P("mdcallout.source"),M.setAttribute("aria-label",M.title),y.editable||(M.style.display="none"),M.onmousedown=E=>E.preventDefault(),M.onclick=E=>{E.preventDefault();const x=k();x!=null&&(y.dispatch(y.state.tr.setMeta(Oe,{srcAt:x-2}).setSelection(q.create(y.state.doc,x))),y.focus())},M},{side:-1,stopEvent:()=>!0,key:"cs"})),!u&&n.childCount===1&&t.push(te.widget(h,(y,k)=>{const M=document.createElement("button");return M.type="button",M.className="callout-empty",M.contentEditable="false",M.textContent=P("mdcallout.empty"),y.editable||(M.style.display="none"),M.onmousedown=E=>E.preventDefault(),M.onclick=()=>{const E=k();if(E==null)return;const x=y.state.tr.insert(E,y.state.schema.nodes.paragraph.create());y.dispatch(x.setSelection(q.create(x.doc,E+1))),y.focus()},M},{side:-1,stopEvent:()=>!0,key:"ce"})))}return!0}),t.length?ke.create(e.doc,t):null}}}))}Be({"structsrc.prefixAriaLabel":{zh:"Markdown 标记",en:"Markdown marker"}});const Lt=new be("amadeus-structural-source");function od(e,t){const n=Math.max(1,Math.min(6,Number(e.attrs.level)||1));return{source:`${"#".repeat(n)} `,widgetPos:t+1,decorateFrom:t,decorateTo:t+e.nodeSize,kind:"heading"}}function Wo(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}function sd(e){if(!e.selection.empty)return null;const t=e.selection.$from;if(!t.parent.isTextblock)return null;const n=t.start();if(t.parent.type.name==="heading")return od(t.parent,t.before());const r=Wo(t,"list_item");if(r!==null){const s=t.node(r);if(s.firstChild===t.parent){const a=r-1,l=t.node(a),i=s.attrs.checked;let c="- ",u="list";if(i!=null)c=i?"- [x] ":"- [ ] ",u="task";else if(l.type.name==="ordered_list"){const f=t.index(a);c=`${(Number(l.attrs.order)||1)+f}. `}const d=t.before(r);return{source:c,widgetPos:n,decorateFrom:d,decorateTo:d+s.nodeSize,kind:u}}}const o=Wo(t,"blockquote");if(o!==null){const s=t.node(o),a=t.before(o);return mn(s)?.type==="fold"&&Oe.getState(e)?.srcAt!==a&&Lt.getState(e)?.openAt!==n?null:{source:"> ",widgetPos:n,decorateFrom:a,decorateTo:a+s.nodeSize,kind:"quote"}}return null}function Gk(e){const{$from:t,$to:n}=e.selection;return t.parent.type.name!=="heading"||n.parent.type.name!=="heading"||t.before()!==n.before()?null:od(t.parent,t.before())}function ad(e){e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(Lt,{refresh:!0}))}function ld(e,t){const n=e.state.doc.nodeAt(t.decorateFrom);if(!n||!n.isTextblock||t.widgetPos!==t.decorateFrom+1)return!1;const{selection:r}=e.state;return r.empty&&r.from===t.widgetPos||e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,t.widgetPos))),!0}function zr(e){e.style.setProperty("--amx-prefix-ch",String(Math.max(2,e.value.length+.4)))}function Jk(e,t,n){const r=$a(t.value);if(n.kind!=="heading"||r?.kind!=="heading")return!1;if(t.value===(t.dataset.original??""))return!0;const o=t.selectionStart??t.value.length,s=t.selectionEnd??o;if(t.dataset.committed="1",!ld(e,n)||!Yt(e,r,null))return t.value=t.dataset.original??n.source,zr(t),t.dataset.committed="0",!0;const a=e.dom.querySelector(`.amx-struct-prefix[data-structural-prefix="heading"][data-widget-pos="${n.widgetPos}"]`)??t;return a.value=t.value,a.dataset.original=t.value,a.dataset.committed="0",zr(a),a.focus({preventScroll:!0}),a.setSelectionRange(Math.min(o,a.value.length),Math.min(s,a.value.length)),!0}function Yk(e,t){let n=!1;return Yt(e,{kind:"text"},null,(o,s)=>{const a=o.doc.resolve(s);if(!a.parent.isTextblock)return;const l=a.start();o.insertText(t,l),o.setSelection(q.create(o.doc,l+t.length)),n=!0})&&n}function Rn(e,t,n){if(t.dataset.committed==="1")return;t.dataset.committed="1";const r=t.value,o=t.dataset.original??"";let s=!1;if(r!==o){const a=$a(r);a?Yt(e,a,null):s=Yk(e,r)}if(e.dispatch(e.state.tr.setMeta(Lt,{openAt:null})),n){e.focus();const{$from:a}=e.state.selection;!s&&a.parent.isTextblock&&e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,a.start())).scrollIntoView())}}let Uo=!1;function ni(e,t){Uo=!0;try{return e.someProp("handleKeyDown",n=>n(e,t))??!1}finally{Uo=!1}}function Xk(e,t,n){if(Rn(e,t,!0),n.key==="Backspace"){ni(e,n);return}const r=n.key==="ArrowDown"?1:-1;if(r>0&&!e.endOfTextblock("down")||ni(e,n))return;const{$from:o}=e.state.selection;if(!o.parent.isTextblock)return;const s=r>0?o.after():o.before(),a=fe.findFrom(e.state.doc.resolve(s),r,!0);a&&e.dispatch(e.state.tr.setSelection(a).scrollIntoView())}function ri(e,t){const n=document.createElement("input");n.className="amx-struct-prefix",n.type="text",n.value=t.source,n.dataset.original=t.source,n.dataset.structuralPrefix=t.kind,n.dataset.widgetPos=String(t.widgetPos),n.setAttribute("aria-label",P("structsrc.prefixAriaLabel")),n.setAttribute("autocomplete","off"),n.setAttribute("autocapitalize","off"),n.spellcheck=!1,zr(n),n.addEventListener("focus",()=>{n.dataset.committed="0",ld(e,t)});const r=o=>{o?.isComposing||Jk(e,n,t)||$a(n.value)||Rn(e,n,!0)};return n.addEventListener("input",o=>r(o)),n.addEventListener("compositionend",()=>r()),n.addEventListener("keydown",o=>{o.stopPropagation();const s=!o.metaKey&&!o.ctrlKey&&!o.altKey&&!o.shiftKey,a=n.selectionStart===n.selectionEnd,l=a&&(n.selectionStart??0)===0;if(s&&!o.isComposing&&a&&((o.key==="ArrowLeft"||o.key==="Backspace")&&l||o.key==="ArrowUp"||o.key==="ArrowDown")){o.preventDefault(),Xk(e,n,o);return}if(o.key==="Escape"){o.preventDefault(),n.value=n.dataset.original??t.source,zr(n),Rn(e,n,!0);return}const i=o.key==="ArrowRight"&&n.selectionStart===n.selectionEnd&&(n.selectionStart??0)>=Math.max(0,n.value.length-1);if(o.key==="Enter"||i){o.preventDefault();const c=n.value===(n.dataset.original??"");Rn(e,n,!0),o.key==="Enter"&&c&&!o.isComposing&&e.someProp("handleKeyDown",u=>u(e,o))}}),n.addEventListener("blur",()=>{Rn(e,n,!1),queueMicrotask(()=>ad(e))}),n}function Qk(e,t){const n=[],r=Lt.getState(e)?.openAt,o=t.hasFocus()||t.dom.contains(document.activeElement),s=Gk(e),a=s&&(o||r===s.widgetPos)?s:null;if(a){const l=a;n.push(te.widget(l.widgetPos,()=>ri(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}if(r!=null){const l=sd(e);l&&l.kind!=="heading"&&l.widgetPos===r&&e.doc.nodeAt(l.decorateFrom)&&n.push(te.node(l.decorateFrom,l.decorateTo,{class:`amx-struct-source-open amx-struct-source-${l.kind}`}),te.widget(l.widgetPos,()=>ri(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}return n.length?ke.create(e.doc,n):ke.empty}function Zk(e){const t=e.state.selection;if(t.empty&&t.$from.parentOffset===0)return!0;const n=e.dom.ownerDocument.getSelection();if(!n?.isCollapsed||!n.anchorNode||!e.dom.contains(n.anchorNode))return!1;let r;try{r=e.posAtDOM(n.anchorNode,n.anchorOffset)}catch{return!1}const o=e.state.doc.resolve(r);return!o.parent.isTextblock||o.parentOffset!==0?!1:(e.dispatch(e.state.tr.setSelection(q.create(e.state.doc,r))),!0)}function oi(e,t=!1){if(Uo||!Zk(e))return!1;const n=sd(e.state);if(!n)return!1;if(t&&e.state.selection.$from.parent.content.size===0){const s=e.state.selection.$from,a=n.kind==="quote"?Wo(s,"blockquote"):null;if((n.kind!=="quote"||a!==null&&s.node(a).childCount===1)&&Yt(e,{kind:"text"},null))return!0}e.dispatch(e.state.tr.setMeta(Lt,{openAt:n.widgetPos}));const r=e.dom.querySelector(`.amx-struct-prefix[data-structural-prefix="${n.kind}"][data-widget-pos="${n.widgetPos}"]`);if(!r)return e.dispatch(e.state.tr.setMeta(Lt,{openAt:null})),!1;r.focus({preventScroll:!0});const o=t?r.value.length:Math.max(0,r.value.length-1);return r.setSelectionRange(o,o),t&&o>0&&(r.setRangeText("",o-1,o,"end"),r.dispatchEvent(new InputEvent("input",{bubbles:!0,inputType:"deleteContentBackward"}))),!0}function ew(){return re(()=>{let e=null;return new se({key:Lt,view:t=>(e=t,{destroy:()=>{e===t&&(e=null)}}),state:{init:()=>({openAt:null}),apply:(t,n)=>{const r=t.getMeta(Lt);return r&&Object.prototype.hasOwnProperty.call(r,"openAt")?{openAt:r.openAt??null}:n.openAt==null?n:{openAt:t.mapping.map(n.openAt)}}},props:{decorations:t=>e?Qk(t,e):ke.empty,handleDOMEvents:{blur:t=>(queueMicrotask(()=>ad(t)),!1)}}})})}function Vo(e){const t={code:!!e.parent.type.spec.code,tableCell:!1,listItem:!1,column:!1,card:!1,topLevel:e.depth===1};for(let n=e.depth;n>0;n--){const r=e.node(n),o=r.type.spec.tableRole;o==="cell"||o==="header_cell"?t.tableCell=!0:r.type.name==="list_item"?t.listItem=!0:r.type.name==="amadeusColumnCell"?t.column=!0:r.type.name==="amadeusCanvasCard"&&(t.card=!0)}return t}function id(e){const t=Vo(e.$from);if(e.empty)return t;const n=Vo(e.$to);return{code:t.code||n.code,tableCell:t.tableCell||n.tableCell,listItem:t.listItem||n.listItem,column:t.column||n.column,card:t.card||n.card,topLevel:t.topLevel&&n.topLevel}}function tw(e){return e.code?{turnInto:!0,format:!1,link:!1,color:!1,align:!1}:e.tableCell?{turnInto:!1,format:!0,link:!0,color:!0,align:!1}:{turnInto:!0,format:!0,link:!0,color:!0,align:!0}}function nw(e){return!e.code&&!e.tableCell}function rw(e,t){return e==="instructions"||e==="columns"?t.topLevel:e==="card"?!t.listItem&&!t.column:!0}function X1(e){const t=e.node;return t?e.$from.depth===0&&!/^amadeus(CanvasCard|ColumnRow)$/.test(t.type.name):!1}function Q1(e){const t=e.$from;for(let n=t.depth;n>0;n--)if(t.node(n).type.name==="amadeusColumnRow")return t.before(n);return null}const Go=new WeakMap;function Z1(e,t){Go.set(e,t)}function si(e,t){const n=Go.get(e);return Go.delete(e),n===t}Be({"wikiac.multiBlocks":{zh:"多个块",en:"Multiple blocks"}});const ow=he(()=>new nt(/【【$/,(e,t,n,r)=>e.tr.insertText("[[",n,r),{inCodeMark:!1}));function Zt(e,t,n){if(e.selection.$head.parent.type.spec.code)return!0;let r=!1;return e.doc.nodesBetween(t,n,o=>{o.isInline&&o.marks.some(s=>s.type.spec.code)&&(r=!0)}),r}const rr=e=>({handleDOMEvents:{blur:()=>(e(null,!0),!1)}});function sw(e){return re(()=>new se({props:rr(e),view:()=>({update(t,n){if(!t.hasFocus())return e(null,!0);const{selection:r}=t.state;if(!r.empty)return e(null);const o=r.$head;if(!o.parent.isTextblock)return e(null);const s=o.parent.textBetween(0,o.parentOffset,void 0,""),a=s.lastIndexOf("[[");if(a<0)return e(null);const l=s.slice(a+2);if(/[\]\n]/.test(l)||Zt(t.state,o.start()+a,r.head))return e(null);const c=o.parent.textBetween(o.parentOffset,o.parent.content.size,void 0,"").split(`
|
|
34
|
+
`,1)[0],u=c.indexOf("]]"),d=c.indexOf("[["),f=u>=0&&(d<0||u<d);if(f&&(!n||n.doc.eq(t.state.doc))||f&&/[#|]/.test(l))return e(null);const m=o.start()+a+2,p=r.head;let h;try{h=t.coordsAtPos(p)}catch{return e(null)}const g=f?p+u:void 0;e({query:l,from:m,to:p,left:h.left,top:h.bottom,anchorTop:h.top,closeAt:g})}})}))}function aw(e){return re(()=>new se({props:rr(e),view:()=>({update(t){if(!t.hasFocus())return e(null,!0);const{selection:n}=t.state;if(!n.empty)return e(null);const r=n.$head;if(!r.parent.isTextblock||r.parent.type.name==="code_block")return e(null);const o=Vo(r);if(!nw(o))return e(null);const s=r.parent.textBetween(0,r.parentOffset,void 0,""),a=s.lastIndexOf("/");if(a<0||Zt(t.state,r.start()+a,n.head)||a>0&&!/\s/.test(s[a-1]))return e(null);const l=s.slice(a+1);if(l.length>40||/[\s\]\n]/.test(l))return e(null);const i=r.start()+a+1,c=n.head;let u;try{u=t.coordsAtPos(c)}catch{return e(null)}e({query:l,from:i,to:c,left:u.left,top:u.bottom,anchorTop:u.top,ctx:o})}})}))}function lw(e){return re(()=>new se({props:rr(e),view:()=>({update(t){if(!t.hasFocus())return e(null,!0);const{selection:n}=t.state;if(!n.empty)return e(null);const r=n.$head;if(!r.parent.isTextblock)return e(null);const o=r.parent.textBetween(0,r.parentOffset,void 0,""),s=o.lastIndexOf("@");if(s<0||Zt(t.state,r.start()+s,n.head)||s>0&&Jf.test(o[s-1]))return e(null);const a=o.slice(s+1);if(a.length>30||/[\s[\]\n]/.test(a))return e(null);const l=r.start()+s+1,i=n.head;let c;try{c=t.coordsAtPos(i)}catch{return e(null)}e({query:a,from:l,to:i,left:c.left,top:c.bottom,anchorTop:c.top})}})}))}const iw=/^!\[\[[^\]\n|]+\.(png|jpe?g|gif|webp|svg|avif|bmp)(\|\d+)?\]\]$/i,ai=()=>!!document.activeElement?.closest?.(".inline-toolbar");function cw(e){const t=e.selection;return t instanceof Qe?t.node.type.name==="image":iw.test(e.doc.textBetween(t.from,t.to))}const yr=new be("amx-toolbar-dismissed");function uw(e){return re(()=>{let t=!1;const n=r=>{if(t||yr.getState(r.state))return e(null);const{selection:o,doc:s}=r.state;if(o.empty||!r.editable)return e(null);if(!r.hasFocus()&&!ai()){setTimeout(()=>{!r.isDestroyed&&!r.hasFocus()&&!ai()&&e(null)},0);return}if(cw(r.state))return e(null);const{from:a,to:l}=o,i=s.resolve(a);if(!i.parent.isTextblock)return e(null);const c=!i.sameParent(s.resolve(l));let u,d;try{u=r.coordsAtPos(a),d=r.coordsAtPos(l)}catch{return e(null)}const f=[];for(let y=i.depth;y>0;y--){const k=i.node(y);f.push({name:k.type.name,level:k.attrs.level,checked:k.attrs.checked??null})}const m=[];for(const y of["strong","emphasis","inlineCode","strike_through","amadeusUnderline","link"]){const k=r.state.schema.marks[y];if(!k)continue;let M=!0,E=!1;s.nodesBetween(a,l,x=>(x.isText&&(E=!0,k.isInSet(x.marks)||(M=!1)),!0)),E&&M&&m.push(y)}const p=new Set;s.nodesBetween(a,l,y=>((y.type.name==="paragraph"||y.type.name==="heading")&&p.add(y.attrs.align==="center"||y.attrs.align==="right"?y.attrs.align:"left"),!0)),!p.size&&(i.parent.type.name==="paragraph"||i.parent.type.name==="heading")&&p.add(i.parent.attrs.align==="center"||i.parent.attrs.align==="right"?i.parent.attrs.align:"left");const h=p.size===1?[...p][0]:void 0,g=(y,k)=>{const M=r.state.schema.marks[y];if(!M)return;const E=new Set;return s.nodesBetween(a,l,x=>(x.isText&&E.add(String(M.isInSet(x.marks)?.attrs[k]??"")),!0)),E.size===1&&[...E][0]||void 0};e({from:a,to:l,active:m,align:h,shape:tw(id(o)),fg:g("amadeusColor","color"),bg:g("amadeusBg","bg"),left:(u.left+d.left)/2,top:Math.min(u.top,d.top),bottom:Math.max(u.bottom,d.bottom),kind:c?P("wikiac.multiBlocks"):Ok(f)})};return new se({key:yr,state:{init:()=>!1,apply:(r,o,s,a)=>r.getMeta(yr)?!0:o&&a.selection.eq(s.selection)},props:{handleDOMEvents:{mousedown:(r,o)=>{if(o.button!==0)return!1;t=!0,e(null);const s=()=>{window.removeEventListener("mouseup",s,!0),window.removeEventListener("pointercancel",s,!0),window.removeEventListener("blur",s),t=!1,setTimeout(()=>{r.isDestroyed||n(r)},0)};return window.addEventListener("mouseup",s,!0),window.addEventListener("pointercancel",s,!0),window.addEventListener("blur",s),!1}}},view:()=>({update:n})})})}Be({"itb.turnInto":{zh:"转换为…",en:"Turn into…"},"itb.bold":{zh:"加粗",en:"Bold"},"itb.italic":{zh:"斜体",en:"Italic"},"itb.underline":{zh:"下划线",en:"Underline"},"itb.strike":{zh:"删除线",en:"Strikethrough"},"itb.code":{zh:"行内代码 (⌘E)",en:"Inline code (⌘E)"},"itb.link":{zh:"链接",en:"Link"},"itb.colorMenu":{zh:"文字 / 背景颜色",en:"Text / background color"},"itb.clear":{zh:"清除格式",en:"Clear formatting"},"itb.alignLeftTitle":{zh:"左对齐 (⌘⇧L)",en:"Align left (⌘⇧L)"},"itb.alignLeft":{zh:"左对齐",en:"Align left"},"itb.alignCenterTitle":{zh:"居中 (⌘⇧E)",en:"Align center (⌘⇧E)"},"itb.alignCenter":{zh:"居中",en:"Align center"},"itb.alignRightTitle":{zh:"右对齐 (⌘⇧R)",en:"Align right (⌘⇧R)"},"itb.alignRight":{zh:"右对齐",en:"Align right"},"itb.textColor":{zh:"文字颜色",en:"Text color"},"itb.bgColor":{zh:"背景颜色",en:"Background color"},"itb.color.default":{zh:"默认",en:"Default"},"itb.color.red":{zh:"红",en:"Red"},"itb.color.orange":{zh:"橙",en:"Orange"},"itb.color.yellow":{zh:"黄",en:"Yellow"},"itb.color.green":{zh:"绿",en:"Green"},"itb.color.teal":{zh:"青",en:"Teal"},"itb.color.blue":{zh:"蓝",en:"Blue"},"itb.color.purple":{zh:"紫",en:"Purple"},"itb.color.magenta":{zh:"品红",en:"Magenta"},"itb.color.pink":{zh:"粉",en:"Pink"},"itb.color.grey":{zh:"灰",en:"Gray"},"itb.turn.text":{zh:"正文",en:"Text"},"itb.turn.h1":{zh:"标题 1",en:"Heading 1"},"itb.turn.h2":{zh:"标题 2",en:"Heading 2"},"itb.turn.h3":{zh:"标题 3",en:"Heading 3"},"itb.turn.h4":{zh:"标题 4",en:"Heading 4"},"itb.turn.h5":{zh:"标题 5",en:"Heading 5"},"itb.turn.h6":{zh:"标题 6",en:"Heading 6"},"itb.turn.bullet":{zh:"无序列表",en:"Bulleted list"},"itb.turn.ordered":{zh:"有序列表",en:"Numbered list"},"itb.turn.todo":{zh:"待办",en:"To-do"},"itb.turn.quote":{zh:"引用",en:"Quote"},"itb.turn.fold":{zh:"折叠",en:"Toggle"},"itb.turn.codeblock":{zh:"代码块",en:"Code block"},"itb.turn.math":{zh:"公式",en:"Equation"},"itb.askTangu":{zh:"问 Tangu",en:"Ask Tangu"},"itb.askTanguTitle":{zh:"把选中的文字带到侧栏对话里问",en:"Ask about the selection in the side chat"},"itb.ai":{zh:"AI",en:"AI"},"itb.aiTitle":{zh:"用 AI 改写选中的文字(先预览,确认后才写入)",en:"Rewrite the selection with AI (preview first, nothing is written until you confirm)"},"itb.aiPlugins":{zh:"插件",en:"Plugins"},"itb.translate":{zh:"翻译",en:"Translate"},"itb.translateTitle":{zh:"翻译选中的文字(先预览,确认后才写入)",en:"Translate the selection (preview first, nothing is written until you confirm)"},"itb.more":{zh:"更多",en:"More"},"itb.aria":{zh:"文字格式",en:"Text formatting"}});const dw=[{nameKey:"itb.color.default",v:""},{nameKey:"itb.color.red",v:"#c62222"},{nameKey:"itb.color.orange",v:"#b9450a"},{nameKey:"itb.color.yellow",v:"#8f6203"},{nameKey:"itb.color.green",v:"#117b38"},{nameKey:"itb.color.teal",v:"#06748f"},{nameKey:"itb.color.blue",v:"#2159d3"},{nameKey:"itb.color.purple",v:"#842ed3"},{nameKey:"itb.color.magenta",v:"#941555"},{nameKey:"itb.color.grey",v:"#6a6a6a"}],fw=[{nameKey:"itb.color.default",v:""},{nameKey:"itb.color.red",v:"#fed5d5"},{nameKey:"itb.color.orange",v:"#fedfbb"},{nameKey:"itb.color.yellow",v:"#fef3a1"},{nameKey:"itb.color.green",v:"#e1fab1"},{nameKey:"itb.color.teal",v:"#adf8e9"},{nameKey:"itb.color.blue",v:"#cce2fe"},{nameKey:"itb.color.purple",v:"#edddff"},{nameKey:"itb.color.pink",v:"#ffcece"},{nameKey:"itb.color.grey",v:"#eaecef"}],pw={turnInto:!0,format:!0,link:!0,color:!0,align:!0},cd=[{k:"text",labelKey:"itb.turn.text"},{k:"h1",labelKey:"itb.turn.h1"},{k:"h2",labelKey:"itb.turn.h2"},{k:"h3",labelKey:"itb.turn.h3"},{k:"h4",labelKey:"itb.turn.h4"},{k:"h5",labelKey:"itb.turn.h5"},{k:"h6",labelKey:"itb.turn.h6"},{k:"bullet",labelKey:"itb.turn.bullet"},{k:"ordered",labelKey:"itb.turn.ordered"},{k:"todo",labelKey:"itb.turn.todo"},{k:"quote",labelKey:"itb.turn.quote"},{k:"fold",labelKey:"itb.turn.fold"},{k:"codeblock",labelKey:"itb.turn.codeblock"},{k:"math",labelKey:"itb.turn.math"}],mw=Object.fromEntries(cd.map(e=>[e.k,e.labelKey]));function hw({left:e,top:t,bottom:n,kind:r,active:o,align:s,shape:a=pw,fg:l,bg:i,onAct:c,onColor:u,onBg:d,onClose:f,onReturnFocus:m,onAsk:p,ai:h}){const{t:g}=hn(),[y,k]=A.useState(null),M=A.useRef(null),E=A.useRef(!1);A.useEffect(()=>{const _=ye=>{if(ye.key==="Escape"){ye.preventDefault(),ye.stopPropagation();const Z=M.current,Ee=!!Z&&Z.contains(document.activeElement);if(y&&Ee){const B=Z.querySelector(`[data-panel="${y}"]`);k(null),B?.focus();return}f(),Ee&&m?.()}};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[f,m,y]),A.useEffect(()=>{!y||!E.current||(E.current=!1,M.current?.querySelector(".itb-panel button")?.focus())},[y]);const x=_=>o?.includes(_)?" on":"",I=_=>ye=>{ye.preventDefault(),_()},R=_=>({onMouseDown:I(_),onClick:ye=>{ye.detail===0&&_()}}),D=_=>({onMouseDown:I(()=>k(y===_?null:_)),onClick:ye=>{ye.detail===0&&(E.current=y!==_,k(y===_?null:_))},"aria-haspopup":"menu","aria-expanded":y===_,"data-panel":_}),U=_=>{const ye=_.target.closest(".itb-row, .itb-panel");if(!ye||!(ye.classList.contains("itb-panel")?["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]:["ArrowRight","ArrowLeft","Home","End"]).includes(_.key))return;const B=[...ye.querySelectorAll(":scope > button, :scope > * > button")],N=B.indexOf(document.activeElement),J=_.key==="ArrowRight"||_.key==="ArrowDown",K=_.key==="Home"?0:_.key==="End"?B.length-1:N<0?0:(N+(J?1:-1)+B.length)%B.length;_.preventDefault(),_.stopPropagation(),B[K]?.focus()},Re=[...p?[{id:"ask",label:g("itb.askTangu"),title:g("itb.askTanguTitle"),icon:b.jsx(ym,{size:14}),lead:!0,onRun:p}]:[],...h?.translate?[{id:"translate",label:g("itb.translate"),title:g("itb.translateTitle"),icon:b.jsx(Yf,{size:14}),onRun:()=>h.onPick("translate")}]:[]],we=h?.more?.length?h.more:null,pe=Re.length||we?b.jsx(km,{actions:Re,more:we?{label:g("itb.more"),open:y==="more",onToggle:_=>{E.current=_&&y!=="more",k(y==="more"?null:"more")}}:void 0}):null,Ke=wm()==="actions";return b.jsxs(Wt,{className:"inline-toolbar",x:e,y:n+8,anchorTop:t-8,prefer:"above",center:!0,role:"toolbar","aria-label":g("itb.aria"),"data-testid":"inline-toolbar","data-order":Ke?"actions":"tools",innerRef:_=>{M.current=_},onKeyDown:U,children:[b.jsxs("div",{className:"itb-row",children:[Ke&&pe&&b.jsxs(b.Fragment,{children:[pe,b.jsx("span",{className:"itb-sep"})]}),h&&h.items.length>0&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{className:"itb-btn itb-ask",title:g("itb.aiTitle"),"data-act":"ai",...D("ai"),children:[g("itb.ai")," ▾"]}),b.jsx("span",{className:"itb-sep"})]}),a.turnInto&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{className:"itb-btn itb-turn",title:g("itb.turnInto"),"aria-label":`${g("itb.turnInto")} ${r}`,...D("turn"),children:[r," ▾"]}),b.jsx("span",{className:"itb-sep"})]}),a.format&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:`itb-btn${x("strong")}`,style:{fontWeight:700},title:g("itb.bold"),"data-act":"bold","aria-label":g("itb.bold"),"aria-pressed":!!o?.includes("strong"),...R(()=>c("bold")),children:"B"}),b.jsx("button",{className:`itb-btn${x("emphasis")}`,style:{fontStyle:"italic"},title:g("itb.italic"),"data-act":"italic","aria-label":g("itb.italic"),"aria-pressed":!!o?.includes("emphasis"),...R(()=>c("italic")),children:"I"}),b.jsx("button",{className:`itb-btn${x("amadeusUnderline")}`,style:{textDecoration:"underline"},title:g("itb.underline"),"data-act":"underline","aria-label":g("itb.underline"),"aria-pressed":!!o?.includes("amadeusUnderline"),...R(()=>c("underline")),children:"U"}),b.jsx("button",{className:`itb-btn${x("strike_through")}`,style:{textDecoration:"line-through"},title:g("itb.strike"),"data-act":"strike","aria-label":g("itb.strike"),"aria-pressed":!!o?.includes("strike_through"),...R(()=>c("strike")),children:"S"}),b.jsx("button",{className:`itb-btn${x("inlineCode")}`,title:g("itb.code"),"data-act":"code","aria-label":g("itb.code"),"aria-pressed":!!o?.includes("inlineCode"),...R(()=>c("code")),children:"</>"})]}),a.link&&b.jsx("button",{className:`itb-btn${x("link")}`,title:g("itb.link"),"aria-label":g("itb.link"),"aria-pressed":!!o?.includes("link"),"data-act":"link",...R(()=>c("link")),children:"🔗"}),(a.format||a.link)&&b.jsx("span",{className:"itb-sep"}),a.color&&b.jsxs("button",{className:"itb-btn itb-color",title:g("itb.colorMenu"),"aria-label":g("itb.colorMenu"),"data-fg":l||void 0,"data-bg":i||void 0,...D("color"),children:[b.jsx("span",{className:"itb-color-cur",style:{color:l||void 0,background:i||void 0},children:"A"})," ▾"]}),b.jsx("button",{className:"itb-btn",title:g("itb.clear"),"aria-label":g("itb.clear"),"data-act":"clear",...R(()=>c("clear")),children:"T×"}),a.align&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"itb-sep"}),b.jsx("button",{className:`itb-btn${s==="left"?" on":""}`,title:g("itb.alignLeftTitle"),"aria-label":g("itb.alignLeft"),"aria-pressed":s==="left","data-act":"alignLeft",...R(()=>c("alignLeft")),children:b.jsx(Xf,{size:14})}),b.jsx("button",{className:`itb-btn${s==="center"?" on":""}`,title:g("itb.alignCenterTitle"),"aria-label":g("itb.alignCenter"),"aria-pressed":s==="center","data-act":"alignCenter",...R(()=>c("alignCenter")),children:b.jsx(Nm,{size:14})}),b.jsx("button",{className:`itb-btn${s==="right"?" on":""}`,title:g("itb.alignRightTitle"),"aria-label":g("itb.alignRight"),"aria-pressed":s==="right","data-act":"alignRight",...R(()=>c("alignRight")),children:b.jsx(Tm,{size:14})})]}),!Ke&&pe&&b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"itb-sep"}),pe]})]}),y==="turn"&&b.jsx("div",{className:"itb-panel",role:"menu","aria-label":g("itb.turnInto"),children:cd.map(_=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,...R(()=>{k(null),c(_.k)}),children:g(_.labelKey)},_.k))}),y==="ai"&&h&&b.jsx("div",{className:"itb-panel itb-ai-menu",role:"menu","data-testid":"itb-ai-menu",children:h.items.map(_=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":_.id,...R(()=>{k(null),h.onPick(_.id)}),children:_.label},_.id))}),y==="more"&&h&&we&&b.jsxs("div",{className:"itb-panel itb-ai-menu",role:"menu","aria-label":g("itb.more"),"data-testid":"selbar-more",children:[b.jsx("div",{className:"itb-color-head",children:g("itb.aiPlugins")}),we.map(_=>b.jsxs("button",{className:"itb-menu-item itb-more-item",role:"menuitem",tabIndex:-1,"data-ai":_.id,...R(()=>{k(null),h.onPick(_.id)}),children:[_.icon,b.jsx("span",{children:_.label})]},_.id))]}),y==="color"&&b.jsxs("div",{className:"itb-panel itb-colors",role:"menu","aria-label":g("itb.colorMenu"),children:[b.jsx("div",{className:"itb-color-head",children:g("itb.textColor")}),b.jsx("div",{className:"itb-swatches",children:dw.map(_=>b.jsx("button",{className:"itb-swatch",title:g(_.nameKey),role:"menuitem",tabIndex:-1,"aria-label":`${g("itb.textColor")}: ${g(_.nameKey)}`,"data-fg":_.v||"default",...R(()=>{k(null),u(_.v)}),children:b.jsx("span",{className:"itb-swatch-a",style:{color:_.v||"var(--text)"},children:"A"})},_.v||"def"))}),b.jsx("div",{className:"itb-color-head",children:g("itb.bgColor")}),b.jsx("div",{className:"itb-swatches",children:fw.map(_=>b.jsx("button",{className:"itb-swatch",title:g(_.nameKey),role:"menuitem",tabIndex:-1,"aria-label":`${g("itb.bgColor")}: ${g(_.nameKey)}`,"data-bg":_.v||"default",...R(()=>{k(null),d(_.v)}),children:b.jsx("span",{className:"itb-swatch-bg",style:{background:_.v||"transparent"}})},_.v||"def"))})]})]})}const Ln=["basic","ai","plugin"];function ud(e){return e.category??"basic"}function gw(e,t){return t.trim()&&e.length?ud(e[0]):"basic"}function bw(e,t){if(t!=="ArrowLeft"&&t!=="ArrowRight")return null;const n=Ln.indexOf(e);return Ln[(n+(t==="ArrowRight"?1:-1)+Ln.length)%Ln.length]}function yw(e,t,n){return!e||n!=="ArrowUp"&&n!=="ArrowDown"?null:Math.max(0,Math.min(e-1,t+(n==="ArrowDown"?1:-1)))}function dd(e,t=""){const n=A.useRef(null);return A.useLayoutEffect(()=>{const r=n.current;if(!r)return;const o=()=>{const a=r.querySelector('[role="tab"][aria-selected="true"]');a&&(r.style.setProperty("--cap-x",`${a.offsetLeft}px`),r.style.setProperty("--cap-y",`${a.offsetTop}px`),r.style.setProperty("--cap-w",`${a.offsetWidth}px`),r.style.setProperty("--cap-h",`${a.offsetHeight}px`),r.hasAttribute("data-cap-ready")||requestAnimationFrame(()=>r.setAttribute("data-cap-ready","")))};o();const s=new ResizeObserver(o);return s.observe(r),()=>s.disconnect()},[e,t]),n}const kw=8,ww=2;function xw(e,t,n=kw){const r=[];for(const l of e){if(l.alias&&!t.trim())continue;const i=Ze(t,l.base),c=i!==null?i+1e3:Ze(t,l.path);c!==null&&r.push({c:l,s:c})}r.sort((l,i)=>i.s-l.s);const o=r.map(l=>l.c),s=o.slice(0,n),a=o.filter(l=>l.file&&!s.includes(l)).slice(0,ww);return a.length?[...s.slice(0,n-a.length),...a]:s}Be({"dateq.schedule":{zh:"日程",en:"Schedule"},"dateq.remind":{zh:"提醒",en:"Remind me"},"dateq.today":{zh:"今天",en:"Today"},"dateq.tomorrow":{zh:"明天",en:"Tomorrow"}});const Tt=e=>String(e).padStart(2,"0"),Fn=e=>`${e.getFullYear()}-${Tt(e.getMonth()+1)}-${Tt(e.getDate())}`,Jo=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),vw=/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/,Cw=/^(\d{4})年(\d{1,2})月(\d{1,2})(?:日|号)?$/,Sw=/^(\d{1,2})[-/.](\d{1,2})$/,Aw=/^(\d{1,2})月(\d{1,2})(?:日|号)?$/,Mw=/^(\d{4})(\d{2})(\d{2})$/,Nw=/^(\d{1,2})(?:日|号)?$/,Ew={昨天:-1,yesterday:-1,今天:0,today:0,明天:1,tomorrow:1,后天:2};function li(e){const t=e.trim().toLowerCase();let n,r,o=/^(\d{1,2}):(\d{2})(am|pm)?$/.exec(t);if(o){n=Number(o[1]),r=Number(o[2]);const s=o[3];if(s){if(n<1||n>12)return null;n=n%12+(s==="pm"?12:0)}}else if(o=/^(\d{1,2})(am|pm)$/.exec(t)){if(n=Number(o[1]),r=0,n<1||n>12)return null;n=n%12+(o[2]==="pm"?12:0)}else if(o=/^(\d{1,2})(?:点|时)(?:(\d{1,2})分?)?$/.exec(t))n=Number(o[1]),r=o[2]===void 0?0:Number(o[2]);else if(o=/^(\d{3,4})$/.exec(t)){const s=o[1].padStart(4,"0");n=Number(s.slice(0,2)),r=Number(s.slice(2))}else return null;return n<=23&&r<=59?{hour:n,minute:r}:null}function Tw(e,t){if(e<1||e>31)return null;const n=new Date(t.getFullYear(),t.getMonth(),t.getDate());for(let r=0;r<=12;r+=1){const o=new Date(t.getFullYear(),t.getMonth()+r,e);if(o.getDate()===e&&o>=n)return Fn(o)}return null}function ii(e,t){const n=e.trim().toLowerCase(),r=Ew[n];if(r!==void 0)return Fn(Jo(t,r));const o=(a,l,i)=>{const c=`${Number(a)}-${Tt(Number(l))}-${Tt(Number(i))}`;return ep(c)?c:null};let s=vw.exec(n);return s||(s=Cw.exec(n),s)||(s=Mw.exec(n),s)?o(s[1],s[2],s[3]):(s=Sw.exec(n),s||(s=Aw.exec(n),s)?o(t.getFullYear(),s[1],s[2]):(s=Nw.exec(n),s?Tw(Number(s[1]),t):null))}function ci(e,t=new Date){const n=e.normalize("NFKC").trim();if(!n)return null;const r=ii(n,t);if(r)return r;const o=li(n);if(o)return`${Fn(t)}T${Tt(o.hour)}:${Tt(o.minute)}`;const s=/^(.+?)(?:[tT]|\s+)(\S.+)$/.exec(n)??/^(.+?(?:日|号))\s*(\d{1,2}(?:点|时).*)$/.exec(n);if(s){const a=ii(s[1],t),l=li(s[2]);if(a&&l)return`${a}T${Tt(l.hour)}:${Tt(l.minute)}`}return null}const Iw=[{key:"dateq.today",words:["today","今天"],days:0},{key:"dateq.tomorrow",words:["tomorrow","明天"],days:1}],Rw=["remind","提醒"];function Lw(e,t=new Date){const n=e.trim(),r=u=>Qf(Zf(u)),o=u=>{const d=u.includes("T")?u:`${u}T09:00`;return{insert:`@remind:${d}`,label:P("dateq.remind"),hint:r(d)}},s=Fn(Jo(t,1));if(/^remind:/i.test(n)){const u=n.length===7?s:ci(n.slice(7),t);return u?[o(u)]:[]}const a=n.toLowerCase(),l=u=>!a||u.some(d=>d.startsWith(a)),i=[];for(const u of Iw){if(!l(u.words))continue;const d=Fn(Jo(t,u.days));i.push({insert:`@${d}`,label:P(u.key),hint:r(d)})}if(l(Rw)&&i.push(o(s)),i.length)return i;const c=ci(n,t);return c?[{insert:`@${c}`,label:P("dateq.schedule"),hint:r(c)},o(c)]:[]}let En=null;function $w(){const e=Pn(s=>s.vaultRoot),t=Pn(s=>s.linkGraphVersion),n=`${e??""}\0${t}`,[r,o]=A.useState(()=>En?.map??{});return A.useEffect(()=>{if(En?.key===n){o(En.map);return}let s=!0;return Fe?.pageAliases?.().then(a=>{En={key:n,map:a??{}},s&&o(En.map)}).catch(()=>{}),()=>{s=!1}},[n]),r}function Dw(e){const t=e.indexOf("#");if(t<0||e.includes("|"))return null;const n=e.slice(t+1),r=n.startsWith("^");return{name:e.slice(0,t).trim(),kind:r?"block":"heading",q:r?n.slice(1):n}}const Yo=e=>e.replace(/[[\]|#^]/g," ").replace(/\s+/g," ").trim();function _w(e){const t=[],n=new Set;return Br($i(e),r=>{const o=/^ {0,3}(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/.exec(r);if(o){const s=Yo(Li(o[2]));s&&!n.has(s)&&(n.add(s),t.push({level:o[1].length,text:s}))}return r}),t}function zw(e){const t=[],n=new Set;return Br($i(e),r=>{const o=/(?:^|\s)\^([A-Za-z0-9-]+)[ \t]*$/.exec(r);return o&&!n.has(o[1])&&(n.add(o[1]),t.push({id:o[1],preview:Li(r.slice(0,o.index))})),r}),t}const Ow=["all","window","app","note"],Pw=4,Bw=3,Kw=12;function jw(e,t){return e?t?[...Ow]:["all","window","app"]:[]}function Hw(e,t){const n=[...e?["agent"]:[],"date",...t?["note"]:[]];return n.length>1?["all",...n]:[]}function Fw(e,t,n){if(!e.length||n!=="ArrowLeft"&&n!=="ArrowRight")return null;const r=Math.max(0,e.indexOf(t));return n==="ArrowLeft"?r>0?e[r-1]:null:e[Math.min(r+1,e.length-1)]}const qw=e=>!/[#|^]/.test(e),Ww=e=>/^\s*(?:app|window):\/\//.test(e);function ui(e,t,n,r=Kw){if(!e||!qw(t))return[];const o=n==="window"?e.windows.map(a=>({ref:{kind:"window",id:a.id,name:a.title},hint:a.app,alt:a.app})):e.apps.map(a=>({ref:{kind:"app",id:a.id,name:a.name}}));if(!t.trim())return o.slice(0,r).map(({ref:a,hint:l})=>({ref:a,hint:l}));const s=[];for(const{alt:a,...l}of o){const i=Ze(t,l.ref.name),c=i!==null?i+1e3:a?Ze(t,a):null;c!==null&&s.push({c:l,s:c})}return s.sort((a,l)=>l.s-a.s),s.slice(0,r).map(a=>a.c)}const Uw=e=>fm(e).slice(2,-2);Be({"wiki.sec.agent":{zh:"交办 Agent",en:"Assign to an agent"},"wiki.agentTask":{zh:"新建任务块",en:"New task block"},"wiki.sec.date":{zh:"日期",en:"Date"},"wiki.sec.page":{zh:"链接到页面",en:"Link to page"},"wiki.sec.window":{zh:"窗口",en:"Windows"},"wiki.sec.app":{zh:"应用",en:"Apps"},"wiki.create":{zh:"新建链接 “{q}”",en:"New link “{q}”"},"wiki.aliasOf":{zh:"别名 → {name}",en:"Alias → {name}"},"wiki.tab.label":{zh:"候选分类",en:"Suggestion categories"},"wiki.tab.all":{zh:"全部",en:"All"},"wiki.tab.window":{zh:"窗口",en:"Windows"},"wiki.tab.app":{zh:"应用",en:"Apps"},"wiki.tab.note":{zh:"笔记",en:"Notes"},"wiki.tab.agent":{zh:"Agent",en:"Agents"},"wiki.tab.date":{zh:"日期",en:"Dates"},"wiki.tab.empty":{zh:"这一类里没有匹配的",en:"Nothing matches in this category"}});function Vw(e,t){const[n,r]=A.useState(null);return A.useEffect(()=>{if(!e||!t){r(null);return}let o=!0;const s=l=>{if(o){if(l==null){r([]);return}r(t==="heading"?_w(l).map(i=>({label:i.text,insert:i.text,hint:`H${i.level}`})):zw(l).map(i=>({label:`^${i.id}`,insert:`^${i.id}`,hint:i.preview})))}},a=t==="heading"?cf(e):null;if(a)r(a.map(l=>({label:Yo(l.text),insert:Yo(l.text),hint:`H${l.level}`})).filter(l=>l.insert));else{const l=uf(e);l!=null?s(l):Fe?.readTextFile?.(e).then(i=>s(i),()=>s(null))}return()=>{o=!1}},[e,t]),n}function yo(e){return(e.split(/[\\/]/).pop()??e).replace(/\.md$/i,"")}function Gw(e){return e.split(/[\\/]/).pop()??e}function Jw(e){const t=e.replace(/\\/g,"/"),n=t.lastIndexOf("/");return n===-1?"":t.slice(0,n)}const rn=e=>e.file?e.base.toLowerCase():Di(e.base);function di({query:e,left:t,top:n,anchorTop:r,getPageNames:o,getFiles:s,onPick:a,onPickRaw:l,onClose:i,editorFocused:c,caretMidWord:u,sourcePath:d,agents:f=[],onPickAgent:m,allowCreate:p=!0,dates:h=!1}){const[g,y]=A.useState(0),[,k]=A.useState(0),M=!!m;A.useEffect(()=>M?Je()?.subscribeAgents?.(()=>k(z=>z+1)):void 0,[M]);const E=M?Je()?.agents?.()??f:f,{t:x}=hn(),I=Pn(z=>z.icons),R=$w(),D=o(),U=[...D.map(z=>({path:z,base:yo(z),file:!1})),...(s?.()??[]).map(z=>({path:z,base:Gw(z),file:!0})),...D.flatMap(z=>(R[z]??[]).map(F=>({path:z,base:F,file:!1,alias:F})))],Re=new Map;for(const z of U)z.alias||Re.set(rn(z),(Re.get(rn(z))??0)+1);const we=e.trim(),pe=h?null:Dw(e),Ke=pe?pe.name?xo(pe.name,D,d):d||null:null,_=Vw(Ke,pe?pe.kind:null),ye=z=>{if(z.alias){const Q={path:z.path,base:yo(z.path),file:!1};return`${(Re.get(rn(Q))??0)<=1?Q.base:z.path.replace(/\\/g,"/").replace(/\.md$/i,"")}|${z.alias}`}if((Re.get(rn(z))??0)<=1)return z.base;const F=z.path.replace(/\\/g,"/");return`${z.file?F:F.replace(/\.md$/i,"")}|${z.base}`},Z=[];if(pe){const z=(_??[]).map(F=>({it:F,s:Ze(pe.q,F.insert.replace(/^\^/,""))})).filter(F=>F.s!==null).sort((F,Q)=>Q.s-F.s).slice(0,8);for(const{it:F}of z)Z.push({key:`s:${F.insert}`,name:F.label,hint:F.hint,pick:()=>a(`${pe.name}#${F.insert}`)})}else{if(m)for(const Q of E.filter(ot=>!we||Ze(we,ot.name)!==null||Ze(we,ot.slug)!==null).slice(0,6))Z.push({key:`agent:${Q.slug}`,name:b.jsxs(b.Fragment,{children:[b.jsx(Wi,{size:"1em","aria-hidden":"true"}),Q.name]}),hint:x("wiki.agentTask"),section:"agent",pick:()=>m(Q.slug)});const z=h?Lw(e):[];for(const Q of z)Z.push({key:`d:${Q.insert}`,name:Q.label,hint:Q.hint,section:"date",pick:()=>l?.(Q.insert)});for(const Q of xw(U,e))Z.push({key:(Q.file?"f:":Q.alias?`a:${Q.alias}:`:"p:")+Q.path,name:b.jsxs(b.Fragment,{children:[Q.file?b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:/\.db$/i.test(Q.base)?b.jsx(vr,{}):b.jsx(tp,{})}):I[Q.path]&&b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:I[Q.path]}),Q.base]}),hint:Q.alias?x("wiki.aliasOf",{name:yo(Q.path)}):(Re.get(rn(Q))??0)>1?Jw(Q.path)||"/":void 0,section:"page",pick:()=>a(ye(Q))});p&&we.length>0&&!pm(we)&&!/[#|^]/.test(we)&&!Ww(we)&&!U.some(Q=>Q.alias?Q.alias.toLowerCase()===we.toLowerCase():rn(Q)===Di(we))&&Z.push({key:"create",name:x("wiki.create",{q:we}),create:!0,pick:()=>a(we)})}const Ee=!h&&np(),[B,N]=A.useState(null);A.useEffect(()=>{if(!Ee)return;let z=!0;return window.tangu?.appRefs?.list().then(F=>{z&&N(F)},()=>{}),()=>{z=!1}},[Ee]);const J=Ee&&!pe,K=h?Hw(!!m&&E.length>0,U.length>0):jw(J,U.length>0),W=K.length>0,[Y,de]=A.useState("all"),ve=K.includes(Y)?Y:"all",me=z=>({key:`${z.ref.kind}:${z.ref.id}:${z.ref.name}`,name:b.jsxs(b.Fragment,{children:[b.jsx(rp,{id:z.ref.id}),z.ref.name]}),hint:z.hint,section:z.ref.kind,pick:()=>a(Uw(z.ref))}),Pe=J?ui(B,e,"window").map(me):[],Me=J?ui(B,e,"app").map(me):[],Ve=[...Z,...Pe.slice(0,Pw),...Me.slice(0,Bw)],He=ve==="all"?Ve:ve==="window"?Pe:ve==="app"?Me:h?Z.filter(z=>z.section===(ve==="note"?"page":ve)):Z,Ct=He.length,zt=Ve.length>0,xn=dd(W&&zt?ve:""),en=A.useRef(null),[St,Ot]=A.useState(null),Pt=W&&St?.query===e?St.height:void 0;if(A.useLayoutEffect(()=>{if(!W)return;const z=en.current?.offsetHeight??0;z>(Pt??0)&&Ot({query:e,height:z})}),A.useEffect(()=>{y(0)},[e]),A.useLayoutEffect(()=>{if(!zt)return;const z=F=>{if(F.isComposing||F.key==="Process"||F.keyCode===229||c&&!c())return;const Q=F.metaKey||F.ctrlKey||F.altKey||F.shiftKey||ve==="all"&&u?.()?null:Fw(K,ve,F.key);if(Q){F.preventDefault(),F.stopPropagation(),de(Q),y(0);return}Ct===0&&F.key!=="Escape"||(F.key==="ArrowDown"?(F.preventDefault(),F.stopPropagation(),y(ot=>Math.min(ot+1,Ct-1))):F.key==="ArrowUp"?(F.preventDefault(),F.stopPropagation(),y(ot=>Math.max(ot-1,0))):F.key==="Enter"||F.key==="Tab"?(F.preventDefault(),F.stopPropagation(),He[g]?.pick()):F.key==="Escape"&&(F.preventDefault(),F.stopPropagation(),i()))};return window.addEventListener("keydown",z,!0),()=>window.removeEventListener("keydown",z,!0)}),!zt)return null;const ee=z=>z===g?F=>F?.scrollIntoView({block:"nearest"}):void 0,vn=He.map((z,F)=>b.jsx(Yw,{r:z,i:F,active:g,setActive:y,reveal:ee,label:(h||W)&&ve==="all"&&z.section&&z.section!==He[F-1]?.section?x(`wiki.sec.${z.section}`):void 0},z.key));return W?b.jsxs(Wt,{className:"wiki-suggest wiki-suggest-tabbed",x:t,y:n,anchorTop:r,style:{minHeight:Pt},innerRef:z=>{en.current=z},onMouseDown:z=>z.preventDefault(),children:[b.jsx("div",{className:"wiki-tabs cap-tabs",role:"tablist","aria-label":x("wiki.tab.label"),ref:xn,children:K.map(z=>b.jsx("button",{type:"button",className:"wiki-tab",role:"tab","data-category":z,"aria-selected":z===ve,tabIndex:-1,onMouseDown:F=>F.preventDefault(),onClick:()=>{de(z),y(0)},children:x(`wiki.tab.${z}`)},z))}),b.jsxs("div",{className:"wiki-suggest-list",role:"menu",children:[vn,Ct===0&&b.jsx("div",{className:"slash-empty",children:x("wiki.tab.empty")})]})]}):b.jsx(Wt,{className:"wiki-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:z=>z.preventDefault(),children:vn})}function Yw({r:e,i:t,active:n,setActive:r,reveal:o,label:s}){return b.jsxs(b.Fragment,{children:[s&&b.jsx("div",{className:"slash-group-label",children:s}),b.jsxs("button",{className:e.create?"wiki-item wiki-create":"wiki-item","data-active":t===n||void 0,ref:o(t),onMouseEnter:()=>r(t),onMouseDown:a=>{a.preventDefault(),e.pick()},role:"menuitem",children:[b.jsx("span",{className:"wiki-item-name",children:e.name}),e.hint&&b.jsx("span",{className:"wiki-item-hint",children:e.hint})]})]})}const Xw=/(?:^|\s)#([\p{L}\p{N}_/-]+)$/u;function Qw(e){return re(()=>new se({props:rr(e),view:()=>({update(t,n){if(!t.hasFocus())return e(null,!0);const{selection:r}=t.state;if(!r.empty)return e(null);const o=r.$head;if(!o.parent.isTextblock||o.parent.type.spec.code||!n||n.doc.eq(t.state.doc))return e(null);const s=o.parent.textBetween(0,o.parentOffset,void 0,""),a=Xw.exec(s);if(!a||/^[0-9/]+$/.test(a[1]))return e(null);const l=o.parent.textBetween(o.parentOffset,o.parent.content.size,void 0,"");if(/^[\p{L}\p{N}_/-]/u.test(l))return e(null);const i=o.parentOffset-a[1].length-1;if(Zt(t.state,o.start()+i,r.head))return e(null);let c;try{c=t.coordsAtPos(r.head)}catch{return e(null)}e({query:a[1],from:o.start()+i+1,to:r.head,left:c.left,top:c.bottom,anchorTop:c.top})}})}))}let fi=[];function Zw(e,t,n=8){const r=[];for(const o of e){const s=Ze(t,o.tag);s!==null&&r.push({t:o,s})}return r.sort((o,s)=>s.s-o.s||s.t.count-o.t.count),r.slice(0,n).map(o=>o.t)}function e0({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=A.useState(fi),[c,u]=A.useState(0);A.useEffect(()=>{let p=!0;return Fe?.listTags?.().then(h=>{fi=h,p&&i(h)}).catch(()=>{}),()=>{p=!1}},[]),A.useEffect(()=>{u(0)},[e]);const d=Zw(l,e),f=d.length;if(A.useLayoutEffect(()=>{if(f===0)return;const p=h=>{if(!(h.isComposing||h.key==="Process"||h.keyCode===229)&&!(a&&!a()))if(h.key==="ArrowDown")h.preventDefault(),h.stopPropagation(),u(g=>Math.min(g+1,f-1));else if(h.key==="ArrowUp")h.preventDefault(),h.stopPropagation(),u(g=>Math.max(g-1,0));else if(h.key==="Enter"||h.key==="Tab"){h.preventDefault(),h.stopPropagation();const g=d[c];g&&o(g.tag)}else h.key==="Escape"&&(h.preventDefault(),h.stopPropagation(),s())};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)}),f===0)return null;const m=p=>p===c?h=>h?.scrollIntoView({block:"nearest"}):void 0;return b.jsx(Wt,{className:"wiki-suggest tag-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:p=>p.preventDefault(),children:d.map((p,h)=>b.jsxs("button",{className:"wiki-item","data-active":h===c||void 0,ref:m(h),onMouseEnter:()=>u(h),onMouseDown:g=>{g.preventDefault(),o(p.tag)},role:"menuitem",children:[b.jsxs("span",{className:"wiki-item-name",children:["#",p.tag]}),b.jsx("span",{className:"wiki-item-hint",children:p.count})]},p.tag))})}Be({"emoji.group.frequent":{zh:"常用",en:"Frequently used"},"emoji.group.smileys":{zh:"表情",en:"Smileys"},"emoji.group.people":{zh:"手势人物",en:"People & gestures"},"emoji.group.nature":{zh:"动物自然",en:"Animals & nature"},"emoji.group.food":{zh:"食物",en:"Food"},"emoji.group.activity":{zh:"活动旅行",en:"Activities & travel"},"emoji.group.objects":{zh:"物品",en:"Objects"},"emoji.group.symbols":{zh:"符号",en:"Symbols"}});const fd=[{nameKey:"emoji.group.frequent",items:[["📄","文档 页面 文件 doc page file"],["📝","备忘 笔记 memo note write 写"],["📌","图钉 置顶 pin"],["⭐","星 收藏 star favorite"],["✅","完成 勾 对 check done"],["🔥","火 热门 fire hot"],["💡","灯泡 想法 点子 idea bulb"],["🎯","靶 目标 target goal"],["🚀","火箭 发布 上线 rocket launch"],["🐞","瓢虫 bug 缺陷 debug"],["📅","日历 日程 calendar date"],["🧠","大脑 思考 brain think"],["🔒","锁 加密 私密 lock private"],["🔑","钥匙 密钥 key"],["📊","图表 统计 chart data"],["💰","钱 预算 money budget"],["⚙️","齿轮 设置 配置 gear settings config"],["📚","书 资料 books library"],["🏠","房子 首页 home house"],["❤️","心 喜欢 爱 heart love"]]},{nameKey:"emoji.group.smileys",items:[["😀","笑 开心 grin happy"],["😃","笑 开心 smile"],["😄","大笑 laugh"],["😁","龇牙 beam"],["😆","大笑 眯眼 laughing"],["😅","苦笑 汗 sweat smile"],["🤣","笑翻 rofl"],["😂","笑哭 joy tears"],["🙂","微笑 slight smile"],["🙃","倒脸 upside down"],["😉","眨眼 wink"],["😊","害羞 blush"],["😇","天使 innocent halo"],["🥰","爱心眼 love"],["😍","花痴 heart eyes"],["🤩","星星眼 star struck"],["😘","飞吻 kiss"],["😗","亲 kissing"],["🤗","拥抱 hug"],["🤔","思考 thinking"],["🤨","挑眉 raised eyebrow"],["😐","面无表情 neutral"],["😑","无语 expressionless"],["🙄","白眼 roll eyes"],["😏","得意 smirk"],["😣","难受 persevere"],["😥","失望 sad"],["😮","惊讶 open mouth"],["🤐","闭嘴 zipper"],["😴","睡觉 sleep zzz"],["😌","放松 relieved"],["😛","吐舌 tongue"],["🤤","流口水 drool"],["😒","不爽 unamused"],["😓","流汗 downcast sweat"],["😔","沮丧 pensive"],["🙁","不开心 frown"],["😕","困惑 confused"],["😟","担心 worried"],["😢","哭 cry"],["😭","大哭 sob"],["😤","生气 哼 triumph"],["😠","生气 angry"],["😡","愤怒 rage"],["🤯","爆炸 震惊 mind blown"],["😳","脸红 flushed"],["🥵","热 hot face"],["🥶","冷 cold face"],["😱","尖叫 scream"],["😨","害怕 fearful"],["😰","冷汗 anxious"],["🤠","牛仔 cowboy"],["🥳","庆祝 party face"],["😎","墨镜 酷 sunglasses cool"],["🤓","书呆 nerd"],["🧐","单片镜 monocle"],["😷","口罩 mask"],["🤒","发烧 sick"],["🤢","恶心 nauseated"],["🥱","打哈欠 yawn"],["😬","尴尬 grimace"],["🤫","嘘 安静 shush quiet"],["🤥","说谎 lying"],["👻","幽灵 ghost"],["💀","骷髅 skull"],["👽","外星人 alien"],["🤖","机器人 robot ai"],["🎃","南瓜 万圣节 halloween"],["😺","猫笑 cat"],["🙈","不看 see no evil"]]},{nameKey:"emoji.group.people",items:[["👍","赞 好 thumbs up"],["👎","踩 差 thumbs down"],["👌","ok 好 okay"],["✌️","胜利 victory peace"],["🤞","祈祷 交叉手指 fingers crossed"],["🤝","握手 合作 handshake"],["👏","鼓掌 clap"],["🙌","举手 庆祝 raising hands"],["🙏","拜托 感谢 pray thanks"],["👋","挥手 你好 wave hello"],["✋","手掌 停 hand stop"],["👆","向上 point up"],["👇","向下 point down"],["👈","向左 point left"],["👉","向右 point right"],["✍️","写字 writing"],["💪","肌肉 加油 muscle strong"],["🦾","机械臂 mechanical arm"],["👀","眼睛 看 eyes look"],["🧑","人 person"],["👤","用户 剪影 user profile"],["👥","多人 团队 users team"],["👶","婴儿 baby"],["🧒","小孩 child"],["👨💻","程序员 开发 developer coder"],["👩💻","程序员 开发 developer coder"],["🧑🏫","老师 teacher"],["🧑🎓","学生 毕业 student graduate"],["🧑🍳","厨师 chef"],["🧑🔬","科学家 scientist"],["🧑⚕️","医生 doctor"],["🕵️","侦探 调查 detective"],["🦸","超人 英雄 hero"],["🧙","法师 巫师 wizard"],["🧘","冥想 打坐 meditate yoga"],["🏃","跑步 run"],["🚶","走路 walk"],["💃","跳舞 dance"],["👪","家庭 family"],["🤦","扶额 无语 facepalm"],["🤷","耸肩 shrug"],["🫡","敬礼 salute"]]},{nameKey:"emoji.group.nature",items:[["🐶","狗 dog"],["🐱","猫 cat"],["🐭","鼠 mouse"],["🐹","仓鼠 hamster"],["🐰","兔 rabbit"],["🦊","狐狸 fox"],["🐻","熊 bear"],["🐼","熊猫 panda"],["🐨","考拉 koala"],["🐯","虎 tiger"],["🦁","狮 lion"],["🐮","牛 cow"],["🐷","猪 pig"],["🐸","青蛙 frog"],["🐵","猴 monkey"],["🐔","鸡 chicken"],["🐧","企鹅 penguin"],["🐦","鸟 bird"],["🦆","鸭 duck"],["🦉","猫头鹰 owl"],["🦋","蝴蝶 butterfly"],["🐝","蜜蜂 bee"],["🐢","乌龟 turtle"],["🐍","蛇 snake"],["🐙","章鱼 octopus"],["🐳","鲸 whale"],["🐬","海豚 dolphin"],["🐟","鱼 fish"],["🦈","鲨鱼 shark"],["🦀","螃蟹 crab"],["🐴","马 horse"],["🦄","独角兽 unicorn"],["🐘","大象 elephant"],["🐺","狼 wolf"],["🦅","鹰 eagle"],["🐳","鲸鱼 whale"],["🌲","树 松树 tree pine"],["🌳","树 tree"],["🌵","仙人掌 cactus"],["🌴","棕榈 palm"],["🍀","四叶草 幸运 clover luck"],["🌿","草叶 herb"],["🍃","叶子 leaf"],["🌸","樱花 blossom sakura"],["🌺","花 hibiscus"],["🌻","向日葵 sunflower"],["🌹","玫瑰 rose"],["🌷","郁金香 tulip"],["🌼","雏菊 daisy"],["🌊","海浪 水 wave ocean"],["☀️","太阳 晴 sun sunny"],["🌙","月亮 夜 moon night"],["⭐","星 star"],["🌟","闪星 sparkle star"],["⚡","闪电 快 lightning fast"],["🔥","火 fire"],["❄️","雪花 冷 snow cold"],["🌈","彩虹 rainbow"],["☁️","云 cloud"],["🌧️","雨 rain"],["⛰️","山 mountain"],["🌍","地球 世界 earth world"]]},{nameKey:"emoji.group.food",items:[["🍎","苹果 apple"],["🍊","橙子 orange"],["🍋","柠檬 lemon"],["🍌","香蕉 banana"],["🍉","西瓜 watermelon"],["🍇","葡萄 grapes"],["🍓","草莓 strawberry"],["🫐","蓝莓 blueberry"],["🍑","桃 peach"],["🥭","芒果 mango"],["🍍","菠萝 pineapple"],["🥥","椰子 coconut"],["🥑","牛油果 avocado"],["🍅","番茄 tomato"],["🥕","胡萝卜 carrot"],["🌽","玉米 corn"],["🥔","土豆 potato"],["🍞","面包 bread"],["🥐","可颂 croissant"],["🥯","贝果 bagel"],["🧀","奶酪 cheese"],["🥚","蛋 egg"],["🍳","煎蛋 早餐 cooking breakfast"],["🥞","松饼 pancake"],["🥓","培根 bacon"],["🍔","汉堡 burger"],["🍟","薯条 fries"],["🍕","披萨 pizza"],["🌭","热狗 hotdog"],["🌮","塔可 taco"],["🍜","拉面 面 noodles ramen"],["🍚","米饭 rice"],["🍱","便当 bento"],["🍣","寿司 sushi"],["🍤","虾 shrimp"],["🥟","饺子 dumpling"],["🍲","炖菜 火锅 stew hotpot"],["🥗","沙拉 salad"],["🍿","爆米花 popcorn"],["🍰","蛋糕 cake"],["🎂","生日蛋糕 birthday"],["🍪","饼干 cookie"],["🍫","巧克力 chocolate"],["🍬","糖 candy"],["🍦","冰淇淋 ice cream"],["☕","咖啡 coffee"],["🍵","茶 tea"],["🧋","奶茶 bubble tea"],["🍺","啤酒 beer"],["🍷","红酒 wine"],["🥂","干杯 庆祝 cheers"],["💧","水 滴 water drop"]]},{nameKey:"emoji.group.activity",items:[["⚽","足球 soccer"],["🏀","篮球 basketball"],["🏈","橄榄球 football"],["⚾","棒球 baseball"],["🎾","网球 tennis"],["🏐","排球 volleyball"],["🏓","乒乓 ping pong"],["🏸","羽毛球 badminton"],["🥊","拳击 boxing"],["🏊","游泳 swim"],["🚴","骑车 cycling"],["⛷️","滑雪 ski"],["🏔️","雪山 mountain"],["🎣","钓鱼 fishing"],["🎮","游戏 game"],["🕹️","街机 arcade"],["🎲","骰子 dice"],["♟️","棋 chess"],["🎨","画画 艺术 art paint"],["🎭","戏剧 theater"],["🎵","音乐 music"],["🎸","吉他 guitar"],["🎹","钢琴 piano"],["🎤","麦克风 唱歌 mic sing"],["🎧","耳机 headphone"],["🎬","电影 拍摄 movie film"],["📷","相机 拍照 camera photo"],["🎥","摄像 video"],["🏆","奖杯 冠军 trophy win"],["🥇","金牌 first medal"],["🎁","礼物 gift"],["🎉","庆祝 party"],["🎊","彩带 confetti"],["🎈","气球 balloon"],["✈️","飞机 出行 plane travel"],["🚗","汽车 car"],["🚕","出租 taxi"],["🚌","公交 bus"],["🚇","地铁 metro subway"],["🚄","高铁 火车 train"],["🚢","船 ship"],["🚲","自行车 bike"],["🛵","摩托 scooter"],["🗺️","地图 map"],["🧭","指南针 方向 compass"],["🏝️","海岛 island"],["🏖️","海滩 beach"],["🏕️","露营 camping"],["🗼","塔 tower"],["🏛️","建筑 古典 classical building"],["🏢","办公楼 office"],["🏫","学校 school"],["🏥","医院 hospital"],["🏦","银行 bank"],["⛩️","神社 shrine"],["🗿","石像 moai"]]},{nameKey:"emoji.group.objects",items:[["💻","电脑 笔记本 laptop computer"],["🖥️","台式机 显示器 desktop monitor"],["⌨️","键盘 keyboard"],["🖱️","鼠标 mouse"],["📱","手机 phone mobile"],["💾","软盘 保存 save floppy"],["💿","光盘 disc"],["🗄️","文件柜 归档 archive cabinet"],["🗂️","分类 索引 folder index"],["📁","文件夹 folder"],["📂","打开文件夹 open folder"],["📎","回形针 附件 clip attach"],["📏","尺子 ruler"],["✂️","剪刀 剪 scissors cut"],["🖊️","笔 pen"],["✏️","铅笔 编辑 pencil edit"],["🖍️","蜡笔 crayon"],["🔍","搜索 放大镜 search find"],["🔎","搜索 search"],["🔬","显微镜 研究 microscope"],["🔭","望远镜 探索 telescope"],["🧪","试管 实验 test experiment"],["🧬","基因 dna"],["💊","药 medicine pill"],["🩺","听诊器 医疗 stethoscope"],["🔧","扳手 修 wrench fix"],["🔨","锤子 hammer build"],["🪛","螺丝刀 screwdriver"],["🧰","工具箱 toolbox"],["🧲","磁铁 magnet"],["🔋","电池 battery"],["🔌","插头 电源 plug power"],["💡","灯泡 light idea"],["🕯️","蜡烛 candle"],["📦","包裹 打包 package box"],["🛒","购物车 cart shopping"],["💳","信用卡 支付 card pay"],["🧾","收据 账单 receipt bill"],["💵","钞票 现金 cash"],["📈","上涨 增长 chart up growth"],["📉","下跌 chart down"],["📊","柱状图 统计 bar chart stats"],["🗒️","记事本 notepad"],["📋","剪贴板 待办 clipboard todo"],["📇","名片 卡片 card index"],["📖","书 阅读 book read"],["📰","报纸 新闻 news"],["✉️","信 邮件 mail"],["📧","邮件 email"],["📨","收件 inbox"],["📮","邮筒 postbox"],["🔔","铃铛 提醒 bell notify"],["📢","喇叭 公告 announce"],["🎙️","播客 麦克风 podcast"],["⏰","闹钟 提醒 alarm"],["⏳","沙漏 等待 hourglass wait"],["⌛","计时 timer"],["🗓️","日程表 calendar schedule"],["🖼️","图片 相框 image picture"],["🧩","拼图 模块 puzzle module"],["⚗️","蒸馏 化学 alembic"],["🛠️","工具 维护 tools maintain"],["🔗","链接 link"],["📡","卫星 信号 satellite signal"]]},{nameKey:"emoji.group.symbols",items:[["✅","完成 对勾 check done"],["☑️","勾选框 checkbox"],["❌","错 删除 cross wrong"],["❗","感叹号 重要 important"],["❓","问号 疑问 question"],["⚠️","警告 warning"],["🚫","禁止 forbidden"],["🔴","红点 red"],["🟠","橙 orange"],["🟡","黄 yellow"],["🟢","绿 green"],["🔵","蓝 blue"],["🟣","紫 purple"],["⚫","黑 black"],["⚪","白 white"],["🟥","红方块 red square"],["🟩","绿方块 green square"],["🟦","蓝方块 blue square"],["🔶","橙菱形 diamond"],["🔺","上三角 triangle up"],["🔻","下三角 triangle down"],["➡️","右箭头 arrow right"],["⬅️","左箭头 arrow left"],["⬆️","上箭头 arrow up"],["⬇️","下箭头 arrow down"],["🔄","循环 刷新 refresh loop"],["🔀","随机 shuffle"],["▶️","播放 play"],["⏸️","暂停 pause"],["⏹️","停止 stop"],["♻️","回收 循环 recycle"],["💯","满分 一百 hundred perfect"],["💬","对话 评论 comment chat"],["🗨️","发言 speech"],["💭","想法 气泡 thought"],["♾️","无限 infinity"],["〰️","波浪 wave"],["✳️","星号 asterisk"],["🔆","亮度 bright"],["🆕","新 new"],["🆗","ok 好"],["🔝","置顶 top"],["🈁","这里 here"],["㊗️","祝 congrat"],["💤","睡 zzz"]]}],ex=fd.flatMap(e=>e.items.map(([t])=>t));function tx(e){const t=e.trim().toLowerCase();return t?pd(t).map(n=>n.emoji):null}function pd(e){const t=e.trim().toLowerCase();if(!t)return[];const n=[],r=[],o=new Set,s=(a,l)=>a.filter(i=>/^[\x21-\x7e]+$/.test(i)).join(" ")||l;for(const a of fd)for(const[l,i]of a.items){if(o.has(l))continue;const c=i.split(/\s+/),u=c.find(d=>d.startsWith(t));u?(n.push({emoji:l,name:s(c,u)}),o.add(l)):i.includes(t)&&(r.push({emoji:l,name:s(c,t)}),o.add(l))}return[...n,...r]}const t0=/(?:^|[^A-Za-z0-9_:])(:([A-Za-z]{2,30}))$/;function n0(e){return re(()=>new se({props:rr(e),view:()=>({update(t,n){if(!t.hasFocus())return e(null,!0);if(t.composing)return e(null);const{selection:r}=t.state;if(!r.empty)return e(null);const o=r.$head;if(!o.parent.isTextblock||o.parent.type.spec.code||!n||n.doc.eq(t.state.doc))return e(null);const s=o.parent.textBetween(0,o.parentOffset,void 0,""),a=t0.exec(s);if(!a)return e(null);const l=o.parent.textBetween(o.parentOffset,o.parent.content.size,void 0,"");if(/^[A-Za-z0-9_]/.test(l))return e(null);const i=o.parentOffset-a[1].length;if(Zt(t.state,o.start()+i,r.head))return e(null);let c;try{c=t.coordsAtPos(r.head)}catch{return e(null)}e({query:a[2],from:o.start()+i+1,to:r.head,left:c.left,top:c.bottom,anchorTop:c.top})}})}))}function r0({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=A.useState(0);A.useEffect(()=>{i(0)},[e]);const c=pd(e).slice(0,8),u=c.length;if(A.useLayoutEffect(()=>{if(u===0)return;const f=m=>{if(!(m.isComposing||m.key==="Process"||m.keyCode===229)&&!(a&&!a()))if(m.key==="ArrowDown")m.preventDefault(),m.stopPropagation(),i(p=>Math.min(p+1,u-1));else if(m.key==="ArrowUp")m.preventDefault(),m.stopPropagation(),i(p=>Math.max(p-1,0));else if(m.key==="Enter"||m.key==="Tab"){m.preventDefault(),m.stopPropagation();const p=c[l];p&&o(p.emoji)}else m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),s())};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)}),u===0)return null;const d=f=>f===l?m=>m?.scrollIntoView({block:"nearest"}):void 0;return b.jsx(Wt,{className:"wiki-suggest emoji-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:f=>f.preventDefault(),children:c.map((f,m)=>b.jsxs("button",{className:"wiki-item","data-active":m===l||void 0,ref:d(m),onMouseEnter:()=>i(m),onMouseDown:p=>{p.preventDefault(),o(f.emoji)},role:"menuitem",children:[b.jsx("span",{className:"emoji-suggest-char",children:f.emoji}),b.jsx("span",{className:"wiki-item-name",children:f.name})]},f.emoji))})}const o0=/[\p{L}\p{N}_/-]/u;function s0(e){let t="";return e.forEach(n=>{n.isText?t+=n.text??"":t+="".repeat(n.nodeSize)}),t}function nx(e,t,n=!1){for(const r of t){const o=r.trim().toLowerCase();if(!o)continue;let s=null;if(e.descendants((a,l)=>{if(s)return!1;if(!a.isTextblock)return!0;const i=s0(a),c=i.toLowerCase(),u=c.length===i.length?c:i;for(let d=u.indexOf(o);d>=0;d=u.indexOf(o,d+1)){if(n){if(d>0&&!/\s/.test(u[d-1]))continue;const f=u.codePointAt(d+o.length);if(f!=null&&o0.test(String.fromCodePoint(f)))continue}s={from:l+1+d,to:l+1+d+o.length,block:l};break}return!1}),s)return s}return null}function md(e,t){let n=!1;for(let r=0;r<32;r++){const o=xm(e.state,t);if(o!=null){vm(e,o),n=!0;continue}const s=Cm(e.state,t);if(!s.length)break;Sm(e,s[0]),n=!0}return n}function a0(e){for(let t=e;t&&t!==document.body;t=t.parentElement){if(!(t instanceof HTMLElement))continue;const n=getComputedStyle(t);if(/auto|scroll/.test(n.overflowY)&&t.scrollHeight>t.clientHeight+1)return t}return null}function l0(e){const t=e.querySelector(":scope > .amx-toolbar");if(!(t instanceof HTMLElement))return 0;const n=getComputedStyle(t);return n.position!=="sticky"||n.display==="none"||n.visibility==="hidden"?0:t.getBoundingClientRect().height}const i0=12;function c0(e,t=i0){const n=e.getBoundingClientRect();if(!n.width&&!n.height||!e.dispatchEvent(new CustomEvent("amx-reveal",{bubbles:!0,cancelable:!0,detail:{rect:n}})))return;const o=a0(e.parentElement);if(!o){window.scrollBy(0,n.top-t);return}const s=o.getBoundingClientRect(),a=o.currentCSSZoom||1;Am(o),o.scrollTop+=(n.top-(s.top+l0(o)+t))/a}Be({"footnote.backToRef":{zh:"回到引用处",en:"Back to reference"}});const $n=new be("amx-footnote"),hd="jumped",Xt="footnote_reference",xt="footnote_definition",Da="[^\\s[\\]\\\\\\ufffc]{1,200}",$t=e=>e.replace(/[\t\n\r ]+/g," ").trim().toLowerCase().toUpperCase();function Or(e,t){const n=$t(t);let r=null;return e.descendants((o,s)=>r?!1:o.type.name===xt&&$t(String(o.attrs.label))===n?(r={pos:s,node:o},!1):!o.isTextblock),r}function rx(e,t){const n=Or(e,t);if(!n)return null;const r=[];return n.node.descendants(o=>o.isTextblock?(r.push(o.textContent),!1):!0),r.join(`
|
|
35
|
+
`).trim()}const pi=e=>e.type.name===xt&&e.childCount===1&&e.firstChild.isTextblock&&e.firstChild.content.size===0;function gd(e,t,n,r,o=""){const s=e.schema.nodes[Xt],a=e.schema.nodes[xt],l=e.schema.nodes.paragraph;if(!s||!a||!l||Zt(e,t,n))return null;const i=e.tr.replaceWith(t,n,s.create({label:r}));if(o&&i.insertText(o,t+1),Or(e.doc,r))return i;const c=i.doc.content.size;return i.insert(c,a.create({label:r},l.create())),i.setSelection(q.create(i.doc,c+2)).setMeta($n,hd).scrollIntoView()}const u0=new nt(new RegExp(`(?<![[!\\\\])\\[\\^(${Da})\\]$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset===0&&o.parent.type.name==="paragraph"?null:gd(e,n,r,t[1])},{inCodeMark:!1}),d0=new nt(new RegExp(`^\\[\\^(${Da})\\]([^:\\n])$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset!==0||o.parent.type.name!=="paragraph"?null:gd(e,n,r,t[1],t[2])},{inCodeMark:!1}),f0=new nt(new RegExp(`^\\[\\^(${Da})\\]:[ \\u00a0]$`,"u"),(e,t,n,r)=>{const o=e.schema.nodes[xt],s=e.doc.resolve(n);if(!o||s.parentOffset!==0||s.parent.type.name!=="paragraph"||s.depth!==1||Zt(e,n,r))return null;const a=t[1],l=[];e.doc.forEach((u,d)=>{pi(u)&&$t(String(u.attrs.label))===$t(a)&&l.push(d)});const i=e.tr.delete(n,r),c=i.doc.resolve(n).blockRange();if(!c)return null;i.wrap(c,[{type:o,attrs:{label:a}}]);for(const u of l.reverse()){const d=i.mapping.map(u),f=i.doc.nodeAt(d);f&&pi(f)&&i.delete(d,d+f.nodeSize)}return i},{inCodeMark:!1}),p0=[he(()=>u0),he(()=>d0),he(()=>f0)];function mi(e){const t=new Map,n=[],r=[];if(e.descendants((s,a)=>{if(s.type.name===Xt){const l=$t(String(s.attrs.label));t.has(l)||t.set(l,t.size+1),n.push({pos:a,node:s})}else s.type.name===xt&&r.push({pos:a,node:s});return!0}),!n.length&&!r.length)return ke.empty;const o=s=>{const a=t.get($t(String(s.node.attrs.label)));return te.node(s.pos,s.pos+s.node.nodeSize,{"data-fn-num":a==null?"":String(a)},{fnNum:a??null})};return ke.create(e,[...n,...r].map(o))}function m0(e){return e.steps.some(t=>{const n=t.slice;let r=!1;return n?.content.descendants(o=>((o.type.name===Xt||o.type.name===xt)&&(r=!0),!r)),r})}const bd=e=>{for(const t of e){const n=t.spec.fnNum;if(n!=null)return n}return null};class h0{constructor(t,n){this.node=t,this.dom=document.createElement("sup"),this.dom.setAttribute("data-type",Xt),this.dom.contentEditable="false",this.render(n)}node;dom;render(t){const n=String(this.node.attrs.label),r=bd(t);this.dom.setAttribute("data-label",n),this.dom.textContent=r!=null?String(r):n}update(t,n){return t.type!==this.node.type?!1:(this.node=t,this.render(n),!0)}ignoreMutation(){return!0}}class g0{constructor(t,n){this.node=t,this.dom=document.createElement("dl"),this.dom.setAttribute("data-type",xt),this.dt=document.createElement("dt"),this.dt.contentEditable="false",this.contentDOM=document.createElement("dd"),this.dom.append(this.dt,this.contentDOM);const r=()=>{this.dt.title=P("footnote.backToRef")};r(),this.off=ns(r),this.render(n)}node;dom;contentDOM;dt;off;render(t){const n=String(this.node.attrs.label),r=bd(t);this.dom.setAttribute("data-label",n),this.dt.textContent=r!=null?String(r):n}update(t,n){return t.type!==this.node.type?!1:(this.node=t,this.render(n),!0)}ignoreMutation(t){return t.type==="selection"?!1:t.target===this.dom||!this.contentDOM.contains(t.target)}destroy(){this.off()}}function yd(e){if(!(e instanceof HTMLElement))return;const t=e.getBoundingClientRect();t.top>=0&&t.bottom<=window.innerHeight||c0(e)}function b0(e,t){let n=Or(e.state.doc,t);if(!n||(md(e,n.pos)&&(n=Or(e.state.doc,t)),!n))return!1;const r=n.pos+n.node.nodeSize-1;return e.dispatch(e.state.tr.setSelection(q.near(e.state.doc.resolve(r),-1))),e.focus(),yd(e.nodeDOM(n.pos)),!0}function y0(e,t){const n=$t(t);let r=-1;return e.state.doc.descendants((o,s)=>r>=0?!1:(o.type.name===Xt&&$t(String(o.attrs.label))===n&&(r=s),r<0)),r<0?!1:(md(e,r),e.dispatch(e.state.tr.setSelection(q.near(e.state.doc.resolve(r+1)))),e.focus(),yd(e.nodeDOM(r)),!0)}const k0=re(()=>new se({key:$n,state:{init:(e,t)=>({decos:mi(t.doc),jumped:!1}),apply:(e,t)=>{const n=e.getMeta($n)===hd||!e.docChanged&&!e.selectionSet&&t.jumped;let r=t.decos;return e.docChanged&&(r!==ke.empty||m0(e))&&(r=mi(e.doc)),r===t.decos&&n===t.jumped?t:{decos:r,jumped:n}}},props:{decorations:e=>$n.getState(e)?.decos,handleKeyDown(e,t){if(t.key!=="Backspace"||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||!$n.getState(e.state)?.jumped)return!1;const n=e.state.plugins.map(r=>r.spec.isInputRules?r.getState(e.state):null).find(Boolean);return n?op(e.state,r=>{const o=Math.min(n.from+n.text.length,r.doc.content.size);e.dispatch(r.setSelection(q.near(r.doc.resolve(o))).scrollIntoView())}):!1},nodeViews:{[Xt]:(e,t,n,r)=>new h0(e,r),[xt]:(e,t,n,r)=>new g0(e,r)},handleClickOn(e,t,n,r,o,s){return!s||n.type.name!==Xt||o.button!==0||o.ctrlKey?!1:b0(e,String(n.attrs.label))},handleDOMEvents:{mousedown(e,t){if(t.button!==0)return!1;const n=t.target?.closest?.(`dl[data-type="${xt}"] > dt`);if(!n||!e.dom.contains(n))return!1;const r=n.parentElement?.getAttribute("data-label")??"";return t.preventDefault(),y0(e,r),!0}}}})),w0="amadeus:open-tag",x0=new be("amadeus-tag-pill");function v0(e){const t=ds(e),{from:n,to:r}=e.selection,o=[];return e.doc.descendants((s,a)=>{if(!s.isTextblock)return!0;if(s.type.spec.code)return!1;const l=Kr(s);if(!l.includes("#"))return!1;const i=a+1;let c=-1,u=-1;if(t&&n>=i&&r<=i+s.content.size){const m=Math.max(0,Math.min(l.length,n-i)),p=Math.max(0,Math.min(l.length,r-i));c=l.lastIndexOf(`
|
|
36
|
+
`,m-1)+1;const h=l.indexOf(`
|
|
37
|
+
`,p);u=h===-1?l.length:h}const d=new RegExp(el.source,el.flags);let f;for(;f=d.exec(l);){const m=f[1];if(/^[0-9/]+$/.test(m))continue;const p=f.index+f[0].length,h=p-m.length-1;c!==-1&&h<=u&&p>=c||o.push(te.inline(i+h,i+p,{class:"amx-tag-pill","data-tag":m}))}return!1}),o.length?ke.create(e.doc,o):ke.empty}function C0(){return re(()=>new se({key:x0,props:{decorations:e=>v0(e),handleDOMEvents:{mousedown:(e,t)=>{const r=(t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&!t.altKey?t.target?.closest?.(".amx-tag-pill"):null)?.dataset.tag;return r?(t.preventDefault(),window.dispatchEvent(new CustomEvent(w0,{detail:{tag:r}})),!0):!1}}}}))}function S0(e,t){if(mm(t))return t;const n=e.search(/[#|]/),r=n<0?"":e.slice(n),o=t.indexOf("|"),s=o<0?t:t.slice(0,o),a=o<0?"":t.slice(o);return r.includes("|")?s+r:s+r+a}const A0={instructions:"forsion-instructions",task:"forsion-task",prompt:"forsion-prompt"},M0=new Set(["v","id","agent","prompt","sessionId"]),ko=e=>typeof e=="string"&&e.length>0&&e.length<=256&&e===e.trim()&&!/[\u0000-\u0020\u007f]/.test(e);function N0(e){try{const t=JSON.parse(e);if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t;return Object.keys(n).some(r=>!M0.has(r))||n.v!==1||!ko(n.id)||typeof n.prompt!="string"||n.agent!==void 0&&!ko(n.agent)||n.sessionId!==void 0&&!ko(n.sessionId)?null:{v:1,id:n.id,prompt:n.prompt,...n.agent!==void 0?{agent:n.agent}:{},...n.sessionId!==void 0?{sessionId:n.sessionId}:{}}}catch{return null}}function kd(e){const t=JSON.stringify(e);if(!N0(t))throw new Error("Invalid document agent block");return t}function E0(e,t=""){const n={v:1,id:crypto.randomUUID(),prompt:t,...e?{agent:e}:{}};return kd(n),n}function ox(e,t){const n=Math.max(2,...Array.from(t.matchAll(/`+/g),o=>o[0].length)),r="`".repeat(n+1);return`${r}${A0[e]}
|
|
38
|
+
${t}
|
|
39
|
+
${r}`}Be({"mdtask.checkbox":{zh:"完成",en:"Done"}});function T0(e){const t=n=>{if(n?.type==="listItem"&&n.checked==null){const r=n.children?.[0],o=r?.type==="paragraph"&&r.children?.length===1?r.children[0]:null,s=o?.type==="text"?/^\[([ xX])\]$/.exec(String(o.value)):null;s&&(n.checked=s[1]!==" ",r.children=[])}for(const r of n?.children??[])t(r)};t(e)}const I0=Ne("amadeusEmptyTask",()=>()=>T0);function Xo(e,t){const n=e.doc.resolve(t);for(let r=n.depth;r>=0;r--){const o=n.node(r);if(o.type.name==="list_item")return o.attrs.checked==null?null:e.tr.setNodeMarkup(n.before(r),void 0,{...o.attrs,checked:!o.attrs.checked})}return null}const hi=new be("amadeusTaskA11y"),R0="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";function wd(e,t){return te.widget(e,(n,r)=>{const o=document.createElement("span");o.className="amx-task-a11y",o.setAttribute("role","checkbox"),o.setAttribute("aria-checked",String(t)),o.contentEditable="false",o.tabIndex=-1,o.style.cssText=R0;const s=()=>{o.setAttribute("aria-label",P("mdtask.checkbox"))};return s(),o.__off=ns(s),o.addEventListener("click",a=>{if(a.preventDefault(),a.stopPropagation(),!n.editable)return;const l=r();if(l==null)return;const i=Xo(n.state,l);i&&n.dispatch(i)}),o},{side:-1,ignoreSelection:!0,key:`amxtask:${t?1:0}`,stopEvent:()=>!0,destroy:n=>{n.__off?.()}})}function xd(e,t,n){const r=new Map;return e.nodesBetween(t,n,(o,s)=>(o.type.name==="list_item"&&o.attrs.checked!=null&&r.set(s+1,!!o.attrs.checked),!0)),r}function L0(e,t){if(!e.docChanged)return t;let n=t.map(e.mapping,e.doc);const r=e.doc.content.size;return e.mapping.maps.forEach((o,s)=>{const a=e.mapping.slice(s+1);o.forEach((l,i,c,u)=>{const d=Math.max(0,a.map(c,-1)-1),f=Math.min(r,a.map(u,1)+1),m=xd(e.doc,d,f);let p=n.find(d,f);for(const h of m.keys())p=p.concat(n.find(h,h));n=n.remove(p).add(e.doc,[...m].map(([h,g])=>wd(h,g)))})}),n}function gi(e,t){const n=t.target?.closest?.('li[data-item-type="task"]');return n?t.clientX-n.getBoundingClientRect().left>2?null:n:null}function $0(){return re(()=>new se({key:hi,state:{init:(e,t)=>ke.create(t.doc,[...xd(t.doc,0,t.doc.content.size)].map(([n,r])=>wd(n,r))),apply:L0},props:{decorations:e=>hi.getState(e),handleClick(e,t,n){if(!e.editable)return!1;const r=gi(e,n);if(!r)return!1;const o=Xo(e.state,e.posAtDOM(r,0));return o?(e.dispatch(o),!0):!1},handleDOMEvents:{mousedown(e,t){if(!e.editable||e.hasFocus()||t.button!==0||!sp())return!1;const n=gi(e,t);if(!n)return!1;const r=Xo(e.state,e.posAtDOM(n,0));return r?(t.preventDefault(),e.dispatch(r),!0):!1}}}}))}const an=ap(lp),bi=["javascript","typescript","python","bash","json","html","css","sql","java","go","rust","c","cpp","yaml","markdown","diff"],kr=[...bi,...an.listLanguages().filter(e=>!bi.includes(e)&&e!=="plaintext").sort()],D0=kr.filter(e=>!["markdown","ini","less","scss","vbnet","arduino","shell","python-repl","php-template"].includes(e)),_0=4096;let wo=0;function Qo(e){return["text","txt","plaintext"].includes(e.toLowerCase())}function z0(e){if(/^\s*[\[{]/.test(e))try{return JSON.parse(e),"json"}catch{}return/^\s*(?:export\s+)?(?:interface\s+\w+\s*(?:extends\b[^\n{]*)?\{|type\s+\w+\s*=|(?:const|let)\s+[\w$]+\s*:\s*[\w$][^=\n]*=)/m.test(e)?"typescript":/^\s*(?:async\s+)?def\s+\w+\s*\([^)]*\)\s*(?:->[^:\n]+)?\s*:/m.test(e)?"python":/^\s*public\s+(?:final\s+)?class\s+\w+[^{\n]*\{|\bSystem\.out\.(?:print|println)\s*\(/m.test(e)?"java":/^\s*(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+\w+\s*\(/m.test(e)?"rust":/\bstd::\w+|^\s*#include\s*<\s*(?:iostream|vector|map|unordered_map|string|memory)\s*>/m.test(e)?"cpp":/^\s*#include\s*<\s*(?:stdio|stdlib|string)\.h\s*>/m.test(e)?"c":/^\s*import\s+(?:Foundation|SwiftUI|UIKit)\b/m.test(e)?"swift":/^\s*(?:export\s+)?(?:const|let|var)\s+[\w$]+\s*=/m.test(e)?"javascript":""}function O0(e,t){const n=t.trim(),r={language:"",ranges:[]};if(!e||Qo(n))return r;try{let o=n,s;if(o){if(!an.registered(o))return r;wo++,s=an.highlight(o,e)}else{const c=e.slice(0,_0);if(o=z0(c),wo++,o)s=an.highlight(o,e);else{if(s=an.highlightAuto(c,{subset:D0}),!s.data?.language||(s.data.relevance??0)<3)return r;o=s.data.language,c.length<e.length&&(wo++,s=an.highlight(o,e))}}const a=[];let l=0;const i=(c,u)=>{for(const d of c)d.type==="text"?(u.length&&d.value.length&&a.push({from:l,to:l+d.value.length,cls:u.join(" ")}),l+=d.value.length):d.type==="element"&&i(d.children??[],[...u,...d.properties?.className??[]])};return i(s.children,[]),{language:o,ranges:a}}catch{return r}}Be({"amxcode.langTitle":{zh:"语言",en:"Language"},"amxcode.auto":{zh:"自动",en:"Auto"},"amxcode.autoDetected":{zh:"自动 · {language}",en:"Auto · {language}"},"amxcode.plainText":{zh:"纯文本",en:"Plain text"},"amxcode.copy":{zh:"复制",en:"Copy"},"amxcode.copyTitle":{zh:"复制代码",en:"Copy code"},"amxcode.copied":{zh:"已复制",en:"Copied"},"amxcode.run":{zh:"运行",en:"Run"},"amxcode.runTitle":{zh:"在内置终端运行(底部面板)",en:"Run in the built-in terminal (bottom panel)"},"amxcode.wrap":{zh:"折行",en:"Wrap"},"amxcode.wrapTitle":{zh:"切换自动折行(视图态,不改内容)",en:"Toggle line wrap (view only, does not change content)"},"amxcode.linenoOff":{zh:"取消行号",en:"Hide numbers"},"amxcode.lineno":{zh:"行号",en:"Numbers"},"amxcode.linenoDisabled":{zh:"折行开着时不显示行号(软换行无独立行号)",en:"Line numbers are unavailable while wrapping is on (soft-wrapped lines have no number of their own)"},"amxcode.linenoTitle":{zh:"切换行号(视图态,不改内容)",en:"Toggle line numbers (view only, does not change content)"},"amxcode.expand":{zh:"展开",en:"Unfold"},"amxcode.collapse":{zh:"折叠",en:"Fold"},"amxcode.collapseTitle":{zh:"折叠代码块(限高 8 行,视图态)",en:"Fold the code block (8-line limit, view only)"}});const yi=new WeakMap;function vd(e){let t=yi.get(e);return t||(t=O0(e.textContent,String(e.attrs.language??"")),yi.set(e,t)),t}const It=new be("amx-code-block");function Cd(e,t,n){const r=n.wrapped.has(t),o=n.lineno.has(t)&&!r,s=n.collapsed.has(t),a=[te.node(t,t+e.nodeSize,{class:`amx-code${r?" amx-code-wrap":""}${o?" amx-code-lineno":""}${s?" amx-code-collapsed":""}`,...o?{"data-lines":String(e.textContent.split(`
|
|
40
|
+
`).length)}:{}})];for(const l of vd(e).ranges)a.push(te.inline(t+1+l.from,t+1+l.to,{class:l.cls}));return a}function ki(e,t){const n=[];return e.descendants((r,o)=>r.type.name!=="code_block"?!0:(n.push(...Cd(r,o,t)),!1)),n.length?ke.create(e,n):ke.empty}function P0(e,t,n){let r=e.map(t.mapping,t.doc);const o=t.doc.content.size,s=new Map,a=[];t.mapping.maps.forEach((i,c)=>{const u=t.mapping.slice(c+1);i.forEach((d,f,m,p)=>{const h=Math.max(0,u.map(m,-1)-1),g=Math.min(o,u.map(p,1)+1);t.doc.nodesBetween(h,g,(y,k)=>y.type.name==="code_block"?(s.set(k,y),!1):y.isTextblock?(a.push([k,k+y.nodeSize]),!1):!0)})});const l=(i,c)=>r.find(i,c).filter(u=>u.from>=i&&u.to<=c);for(const[i,c]of a){const u=l(i,c);u.length&&(r=r.remove(u))}for(const[i,c]of s){const u=i+c.nodeSize;r=r.remove(l(i,u)).add(t.doc,Cd(c,i,n))}return r}const Tn=[];function B0(e,t,n,r,o,s,a){const l=document.createElement("div");l.className="amx-code-tools",l.contentEditable="false";const i=document.createElement("select");i.className="amx-code-lang",i.title=r?P("amxcode.autoDetected",{language:r}):P("amxcode.langTitle");const c=document.createElement("option");c.value="";const u=r==="javascript"?"JS":r==="typescript"?"TS":r;c.textContent=r?P("amxcode.autoDetected",{language:u}):P("amxcode.auto"),i.appendChild(c);const d=document.createElement("option");d.value=Qo(n)?n:"plaintext",d.textContent=P("amxcode.plainText"),i.appendChild(d);const f=kr.includes(n)||!n||Qo(n),m=[...Tn.filter(k=>kr.includes(k)),...kr.filter(k=>!Tn.includes(k))];for(const k of f?m:[n,...m]){const M=document.createElement("option");M.value=k,M.textContent=k,i.appendChild(M)}i.value=n,i.addEventListener("change",()=>{const k=t();if(i.value){const E=Tn.indexOf(i.value);E>=0&&Tn.splice(E,1),Tn.unshift(i.value)}if(k===null)return;const M=e.state.doc.nodeAt(k);M?.type.name==="code_block"&&e.dispatch(e.state.tr.setNodeMarkup(k,void 0,{...M.attrs,language:i.value}))});const p=document.createElement("button");p.className="amx-code-btn",p.textContent=P("amxcode.copy"),p.title=P("amxcode.copyTitle"),p.addEventListener("click",()=>{const k=t(),M=k===null?null:e.state.doc.nodeAt(k);M&&navigator.clipboard.writeText(M.textContent).then(()=>{p.textContent=P("amxcode.copied"),setTimeout(()=>{p.textContent=P("amxcode.copy")},1200)})});const h=document.createElement("button");h.className=`amx-code-btn${o?" on":""}`,h.textContent=P("amxcode.wrap"),h.title=P("amxcode.wrapTitle"),h.addEventListener("click",()=>{const k=t();k!==null&&e.dispatch(e.state.tr.setMeta(It,{toggle:k}))});const g=document.createElement("button");g.className=`amx-code-btn${s?" on":""}`,g.textContent=s?P("amxcode.linenoOff"):P("amxcode.lineno"),g.title=o?P("amxcode.linenoDisabled"):P("amxcode.linenoTitle"),g.disabled=o,g.addEventListener("click",()=>{const k=t();k!==null&&e.dispatch(e.state.tr.setMeta(It,{toggle:k,which:"lineno"}))});const y=document.createElement("button");if(y.className=`amx-code-btn${a?" on":""}`,y.textContent=a?P("amxcode.expand"):P("amxcode.collapse"),y.title=P("amxcode.collapseTitle"),y.addEventListener("click",()=>{const k=t();k!==null&&e.dispatch(e.state.tr.setMeta(It,{toggle:k,which:"collapse"}))}),l.append(i,p,h,g,y),cp(n)&&window.tangu?.pty){const k=document.createElement("button");k.className="amx-code-btn",k.textContent=P("amxcode.run"),k.title=P("amxcode.runTitle"),k.addEventListener("click",()=>{const M=t(),E=M===null?null:e.state.doc.nodeAt(M),x=E?up(E.textContent):"";x&&dp(x)}),l.append(k)}return l}class K0{constructor(t,n,r,o){this.node=t,this.view=n,this.getPos=r,this.onDestroy=o,this.dom=document.createElement("pre"),this.dom.spellcheck=!1,this.contentDOM=document.createElement("code"),this.dom.appendChild(this.contentDOM),this.sync()}node;view;getPos;onDestroy;dom;contentDOM;bar=null;nums=null;barSig="";update(t){return t.type!==this.node.type?!1:(this.node=t,this.sync(),!0)}sync(){const t=String(this.node.attrs.language??"").trim(),n=t?"":vd(this.node).language;t?this.dom.setAttribute("data-language",t):this.dom.removeAttribute("data-language"),n?this.dom.setAttribute("data-detected-language",n):this.dom.removeAttribute("data-detected-language");const r=this.getPos(),o=It.getState(this.view.state),s=r!=null&&!!o?.wrapped.has(r),a=r!=null&&!!o?.lineno.has(r)&&!s,l=r!=null&&!!o?.collapsed.has(r),i=t==="forsion-button"&&!!ip("```forsion-button\n"+this.node.textContent+"\n```"),c=i?"button":`${t}:${n}:${s?1:0}:${a?1:0}:${l?1:0}:${df()}`;if(c!==this.barSig){if(i)this.bar?.remove(),this.bar=null;else{const u=B0(this.view,()=>this.getPos()??null,t,n,s,a,l);this.bar?this.bar.replaceWith(u):this.dom.insertBefore(u,this.contentDOM),this.bar=u}this.barSig=c}if(a){const u=this.node.textContent.split(`
|
|
41
|
+
`).length,d=Array.from({length:u},(f,m)=>String(m+1)).join(`
|
|
42
|
+
`);this.nums||(this.nums=document.createElement("span"),this.nums.className="amx-code-nums",this.nums.contentEditable="false",this.dom.insertBefore(this.nums,this.contentDOM)),this.nums.textContent!==d&&(this.nums.textContent=d)}else this.nums&&(this.nums.remove(),this.nums=null)}ignoreMutation(t){return t.type==="selection"?!1:!this.contentDOM.contains(t.target)}stopEvent(t){const n=t.target;return!!n&&n!==this.dom&&this.dom.contains(n)&&!this.contentDOM.contains(n)}destroy(){this.onDestroy()}}function j0(){return re(()=>{const e=new Set;return new se({key:It,view:()=>({update:()=>{for(const t of e)t.sync()}}),state:{init:(t,n)=>{const r={wrapped:new Set,lineno:new Set,collapsed:new Set};return{...r,decos:ki(n.doc,r)}},apply(t,n){if(!t.docChanged&&!t.getMeta(It))return n;const r=new Set([...n.wrapped].map(c=>t.mapping.map(c))),o=new Set([...n.lineno].map(c=>t.mapping.map(c))),s=new Set([...n.collapsed].map(c=>t.mapping.map(c))),a=t.getMeta(It);if(a?.toggle!=null){const c=a.which==="lineno"?o:a.which==="collapse"?s:r;c.has(a.toggle)?c.delete(a.toggle):c.add(a.toggle)}const l={wrapped:r,lineno:o,collapsed:s},i=a?.toggle!=null?ki(t.doc,l):P0(n.decos,t,l);return{...l,decos:i}}},props:{nodeViews:{code_block:(t,n,r)=>{let o;return o=new K0(t,n,r,()=>e.delete(o)),e.add(o),o}},decorations(t){return It.getState(t)?.decos??ke.empty},handleTextInput:(t,n,r,o)=>Dm(t,n,r,o),handleKeyDown:(t,n)=>n.key==="Backspace"&&!n.metaKey&&!n.ctrlKey&&!n.altKey&&!n.shiftKey&&!n.isComposing?_m(t):!1}})})}const H0=["http:","https:"],F0=/^[^/?#]+\.(?:md|markdown|pdf|png|jpe?g|gif|webp|svg|bmp|heic|avif|mp4|webm|mov|m4v|mp3|wav|ogg|m4a|flac|txt|csv|tsv|json|docx?|xlsx?|pptx?|zip|canvas|excalidraw|db)(?:[?#].*)?$/i;function Et(e){const t=e.trim();if(!t)return null;const n=Array.from(t).filter(o=>o.charCodeAt(0)>32).join(""),r=/^([a-z][a-z0-9+.-]*):/i.exec(n);return r?H0.includes(r[1].toLowerCase()+":")?t:null:t.startsWith("//")?"https:"+t:t.startsWith("/")||t.startsWith("#")||t.startsWith("./")||t.startsWith("../")||F0.test(t)?t:/^[^\s/]+\.[^\s/]/.test(t)?"https://"+t:t}const Sd=e=>e.replace(/[?#].*$/,""),Ad=e=>{try{return decodeURIComponent(e)}catch{return e}};function wi(e){const t=e.trim();if(!t||t.startsWith("#"))return"other";const n=Et(t);return n?/^https?:/i.test(n)?"external":/\.md$/i.test(Ad(Sd(t)))?"note":"file":"other"}function xi(e,t,n=[]){const r=Ad(Sd(e.trim())).replace(/\\/g,"/");if(r.startsWith("/"))return r.replace(/^\/+/,"");if(!r.includes("/"))return r;const s=[...t&&t.includes("/")?t.slice(0,t.lastIndexOf("/")).split("/"):[]];for(const i of r.split("/"))i===""||i==="."||(i===".."?s.pop():s.push(i));const a=s.join("/");if(r.startsWith("./")||r.startsWith("../"))return a;const l=i=>i.replace(/\.md$/i,"").toLowerCase();return n.some(i=>l(i.replace(/\\/g,"/"))===l(a))?a:r}const q0=he(()=>new nt(/\[([^[\]]+)\]\((\S+)\)$/,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=Et(t[2]);return s?e.tr.replaceWith(n,r,e.schema.text(t[1],[o.create({href:s})])).removeStoredMark(o):null})),W0=/^ {0,3}(?:#{1,6}(?:\s|$)|[-*+]\s|\d{1,9}[.)]\s|>|```|~~~|\|.*\||(?:[-*_][ \t]*){3,}$|\[\^[^\]]+\]:)/,U0=/\*\*[^*\n]+\*\*|__[^_\n]+__|~~[^~\n]+~~|`[^`\n]+`|!?\[[^\]\n]*\]\([^)\n]*\)|\[\[[^\]\n]+\]\]|\$\$|%%/,V0=/^ {0,3}(?=[^\n]*\|)(?=[^\n]*-)[|:\- \t]+$/,G0=/^(?: {4}|\t)/;function J0(e){return e.replace(/\r\n?/g,`
|
|
43
|
+
`).split(`
|
|
44
|
+
`).some(n=>W0.test(n)||V0.test(n)||G0.test(n)&&n.trim()!=="")?!0:U0.test(e)}function Md(e){return e.replace(/\r\n?/g,`
|
|
45
|
+
`).replace(new RegExp("(?<!\\n)\\n(?!\\n)","g"),`
|
|
46
|
+
|
|
47
|
+
`)}function Y0(e,t){const n=e.trim();return t||!n||!/\s/.test(n)&&/^https?:\/\//i.test(n)?null:Nd(e)?Md(e):e}function Nd(e){return new RegExp("(?<!\\n)\\n(?!\\n)").test(e.replace(/\r\n?/g,`
|
|
48
|
+
`).trim())&&!J0(e)}function X0(e,t){return t.length!==1||t[0]!=="paragraph"?"literal":e.trim()!==e?"inline-ws":"default"}const vi=",。;:!?、)」』】》",Q0=new RegExp(`(?<![A-Za-z])(https?:\\/\\/[^\\s<>\\ufffc${vi}(「『【《]+)([ \\t\\u00a0\\u3000${vi}])$`,"i");function Z0(e){let t=e;for(;;){const n=t[t.length-1];if(/[.,:;!?"'*_~]/.test(n)){t=t.slice(0,-1);continue}if(n===")"&&(t.match(/\(/g)?.length??0)<(t.match(/\)/g)?.length??0)){t=t.slice(0,-1);continue}return t}}const e1=he(()=>new nt(Q0,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=Z0(t[1]);if(!/^https?:\/\/[^/?#\s]/i.test(s))return null;const a=e.doc.resolve(n);if(a.parent.type.spec.code)return null;const l=a.parent.textBetween(0,a.parentOffset,void 0,"");if(/(?:\]\(|\[\[|<)$/.test(l)||(l.match(/`/g)?.length??0)%2===1)return null;const i=n+s.length;if(e.doc.textBetween(n,i)!==s||e.doc.rangeHasMark(n,i,o))return null;let c=!1;if(e.doc.nodesBetween(n,i,d=>{d.isText&&d.marks.some(f=>f.type.spec.code||f.type.name==="inlineCode"||f.type.name==="code")&&(c=!0)}),c)return null;const u=Et(s);return u?e.tr.addMark(n,i,o.create({href:u})).insertText(t[2],r).removeStoredMark(o):null}));let Ci=null;function t1(e,t,n){Ci??=Ei().use(Ti).use(Zo);let r;try{r=Ci.parse(t+e+n)}catch{return!1}let o=null;const s=a=>{if(!(o||!a)){if(a.type==="link"){o=a;return}for(const l of Array.isArray(a.children)?a.children:[])s(l)}};return s(r),!!o&&o.position?.start?.offset===t.length&&o.url===e&&o.children?.length===1&&o.children[0].type==="text"&&o.children[0].value===e}const n1={before:"",after:"",now:{line:1,column:1},lineShift:0};function r1(e,t,n,r){const o=Array.isArray(t?.children)?t.children:[];let s=o.indexOf(e),a="";for(;s>=0&&s+1<o.length&&!/\s/.test(a)&&a.length<256;)s++,a+=String(n.handle(o[s],t,n,n1));return!/\s/.test(a)&&(s<0||s+1>=o.length)&&(a+=r?.after??""),a}function Ed(e,t,n,r){const o=e?.url;if(typeof o!="string"||e.title||!/^https?:\/\//i.test(o))return null;const s=e.children;return!Array.isArray(s)||s.length!==1||s[0]?.type!=="text"||s[0].value!==o?null:t1(o,r?.before??"",r1(e,t,n,r))?o:null}const Td=dn.link;function Id(e,t,n,r){const o=Ed(e,t,n,r);return o==null?Td(e,t,n,r):n.createTracker(r).move(o)}Id.peek=(e,t,n,r)=>Ed(e,t,n,r)!=null?"h":Td.peek(e,t,n,r);const o1=Un(e=>{e.update(Qt,t=>({...t,handlers:{...t.handlers,link:Id}}))}),s1=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\#(?=[^\s#])/;function Rd(e){return e.includes("\\#")?Br(e,t=>t.replace(s1,"$1#")):e}const a1=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\==(?=[^\s=])/;function Ld(e){return e.includes("\\==")?Br(e,t=>t.replace(a1,"$1==")):e}Be({"mdblock.default.childNote":{zh:"未命名",en:"Untitled"},"mdblock.default.database":{zh:"未命名多维表",en:"Untitled database"},"mdblock.default.drawing":{zh:"画板",en:"Drawing"},"mdblock.default.noteViewFolder":{zh:"笔记视图",en:"Note view"},"mdblock.default.noteView":{zh:"未命名视图",en:"Untitled view"},"amadeus.default.tableColumn":{zh:"列 {n}",en:"Column {n}"},"mdblock.placeholder":{zh:"输入文字,或按 “/” 选择类型…",en:"Type something, or press “/” to pick a block…"},"mdblock.group.ai":{zh:"AI",en:"AI"},"mdblock.category.basic":{zh:"基本",en:"Basic"},"mdblock.category.ai":{zh:"AI",en:"AI"},"mdblock.category.plugin":{zh:"插件",en:"Plugins"},"mdblock.category.label":{zh:"命令分类",en:"Command categories"},"mdblock.category.empty":{zh:"此分类暂无可用命令",en:"No commands available in this category"},"mdblock.foot.category":{zh:"← → 分类",en:"← → Category"},"mdblock.slash.instructions":{zh:"页指令",en:"Instructions"},"mdblock.slash.agentTask":{zh:"Agent 任务",en:"Agent task"},"mdblock.slash.prompt":{zh:"提示模板",en:"Prompt"},"mdblock.group.basic":{zh:"基础",en:"Basic"},"mdblock.group.list":{zh:"列表",en:"Lists"},"mdblock.group.advanced":{zh:"高级",en:"Advanced"},"mdblock.group.plugin":{zh:"插件",en:"Plugins"},"mdblock.slash.text":{zh:"文本",en:"Text"},"mdblock.slash.h1":{zh:"标题 1",en:"Heading 1"},"mdblock.slash.h2":{zh:"标题 2",en:"Heading 2"},"mdblock.slash.h3":{zh:"标题 3",en:"Heading 3"},"mdblock.slash.h4":{zh:"标题 4",en:"Heading 4"},"mdblock.slash.h5":{zh:"标题 5",en:"Heading 5"},"mdblock.slash.h6":{zh:"标题 6",en:"Heading 6"},"mdblock.slash.ul":{zh:"无序列表",en:"Bulleted list"},"mdblock.slash.ol":{zh:"有序列表",en:"Numbered list"},"mdblock.slash.todo":{zh:"待办",en:"To-do list"},"mdblock.slash.card":{zh:"卡片",en:"Card"},"mdblock.slash.quote":{zh:"引用",en:"Quote"},"mdblock.slash.fold":{zh:"折叠",en:"Toggle"},"mdblock.slash.code":{zh:"代码块",en:"Code block"},"mdblock.slash.table":{zh:"表格",en:"Table"},"mdblock.slash.divider":{zh:"分割线",en:"Divider"},"mdblock.slash.math":{zh:"数学公式",en:"Equation"},"mdblock.slash.wikilink":{zh:"链接笔记",en:"Link to note"},"mdblock.slash.image":{zh:"图片",en:"Image"},"mdblock.slash.columns":{zh:"分栏",en:"Columns"},"mdblock.slash.page":{zh:"页面",en:"Page"},"mdblock.slash.database":{zh:"多维表",en:"Database"},"mdblock.slash.drawing":{zh:"画板",en:"Drawing"},"mdblock.slash.linkdb":{zh:"链接多维表",en:"Link database"},"mdblock.slash.noteview":{zh:"笔记视图",en:"Note view"},"mdblock.slash.template":{zh:"模板",en:"Template"},"mdblock.slash.embed":{zh:"嵌入块引用",en:"Embed block"},"mdblock.slash.bookmark":{zh:"书签",en:"Bookmark"},"mdblock.slash.button":{zh:"按钮",en:"Button"},"mdblock.slash.ai":{zh:"AI 写作",en:"AI writing"},"mdblock.link.title":{zh:"插入链接",en:"Insert link"},"mdblock.link.editTitle":{zh:"编辑链接",en:"Edit link"},"mdblock.link.remove":{zh:"移除链接",en:"Remove link"},"mdblock.turn.failed":{zh:"这里不能转换为「{kind}」",en:"Can't turn this into {kind} here"},"mdblock.link.label":{zh:"输入或粘贴地址(裸域名会自动补 https://)",en:"Type or paste an address (a bare domain gets https:// added)"},"mdblock.bookmark.title":{zh:"插入书签",en:"Insert bookmark"},"mdblock.bookmark.label":{zh:"粘贴链接地址(https:// 开头);YouTube 链接会直接内嵌播放器。",en:"Paste a link (starting with https://); a YouTube link embeds the player directly."},"mdblock.embed.title":{zh:"嵌入块引用",en:"Embed a block reference"},"mdblock.embed.label":{zh:"形如 笔记名#块ID(块菜单「复制嵌入引用」可得);也可只填笔记名嵌整篇首块。",en:"Shaped like note-name#block-id (the block menu’s “Copy embed reference” gives you one); a note name alone embeds that note’s first block."},"mdblock.embed.confirm":{zh:"嵌入",en:"Embed"},"mdblock.toast.staleTarget":{zh:"文件已创建,但原插入位置已失效(笔记已切换或块已删除)",en:"The file was created, but the original insert position is gone (the note changed or the block was deleted)"},"mdblock.toast.slashFailed":{zh:"「{label}」失败:{message}",en:"“{label}” failed: {message}"},"mdblock.plugin.runNotString":{zh:"run() 必须返回字符串,实际是 {type}",en:"run() must return a string, but it returned {type}"},"mdblock.plugin.runTooLong":{zh:"run() 返回内容过长",en:"run() returned too much content"},"mdblock.plugin.runControlChars":{zh:"run() 返回内容含控制字符",en:"run() returned content containing control characters"},"mdblock.pasteAs.title":{zh:"粘贴为",en:"Paste as"},"mdblock.pasteAs.link":{zh:"链接",en:"Link"},"mdblock.pasteAs.bookmark":{zh:"书签卡",en:"Bookmark card"},"mdblock.pasteAs.bookmarkHint":{zh:"默认",en:"Default"},"mdblock.pasteAs.embed":{zh:"内嵌",en:"Embed"},"mdblock.pasteAs.embedHint":{zh:"播放器 / 网页",en:"Player / web page"},"mdblock.menu.noMatch":{zh:"无匹配项",en:"No matches"},"mdblock.editorLabel":{zh:"笔记正文",en:"Note body"},"mdblock.menu.noDatabase":{zh:"库里还没有多维表(用 /多维表 新建一个)",en:"No databases in this vault yet (create one with /database)"},"mdblock.foot.select":{zh:"↑↓ 选择",en:"↑↓ Select"},"mdblock.foot.confirm":{zh:"↵ 确认",en:"↵ Confirm"},"mdblock.foot.insert":{zh:"↵ 插入",en:"↵ Insert"},"mdblock.foot.embed":{zh:"↵ 嵌入",en:"↵ Embed"},"mdblock.foot.close":{zh:"esc 关闭",en:"esc Close"}});function $d(e){const t=new Date,n=r=>String(r).padStart(2,"0");return`${e} ${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}.${n(t.getMinutes())}.${n(t.getSeconds())}`}function un(e){return Eu(wu(Zu(Fi(Rd(Ld(ff(pf(e))))))))}function Dd(e,t){return ky(e,t,un)}function _d(e){return Eu(wu(Zu(Fi(Rd(Ld(e))))))}const _a="\0__amadeus_embed__",za="\0__amadeus_linkdb__",Oa="\0__amadeus_bookmark__",Pa="\0__amadeus_template__",Ba="\0__amadeus_image__",Ka="\0__amadeus_column__",ja="\0__amadeus_database__",Ha="\0__amadeus_drawing__",zd="\0__amadeus_card__",Od="\0__amadeus_ai__",Pd="\0__amadeus_instructions__",Bd="\0__amadeus_agent_task__",Kd="\0__amadeus_prompt__",Fa="\0__amadeus_noteview__",qa="\0__amadeus_page__";function l1(e){return re(()=>new se({key:new be("amx-placeholder"),props:{decorations(t){if(!ds(t))return null;const{doc:n}=t;return!(n.childCount===1&&!!n.firstChild?.isTextblock&&n.firstChild.content.size===0)||!n.firstChild?null:ke.create(n,[te.node(0,n.firstChild.nodeSize,{class:"is-empty","data-placeholder":e()})])}}}))}function i1(e){if(!e)return null;for(const t of Array.from(e.files))if(t.type.startsWith("image/"))return t;return null}function c1(e){const t=e.state.selection;let n="",r=null;if(t instanceof Qe?t.node.type.name==="image"?r=t.node:t.node.type.name==="paragraph"&&t.node.childCount===1&&t.node.firstChild?.type.name==="image"?r=t.node.firstChild:n=t.node.textContent.trim():t.empty||(n=e.state.doc.textBetween(t.from,t.to).trim()),r){const l=String(r.attrs.src??""),i=ts(l)??l;return!i||/^(?:https?:|data:|blob:)/i.test(i)?null:{reference:``,ref:i}}const o=/^!\[\[([^\]\n]+)\]\]$/.exec(n);if(!o)return null;let s=o[1].replace(/\|\d+\s*$/,"").trim();const a=s.indexOf("#");return a>0&&/\.[a-z0-9]{1,10}$/i.test(s.slice(0,a))&&(s=s.slice(0,a)),s?{reference:n,ref:s}:null}function u1(e,t){if(!e)return null;try{const l=e.getData(ji).trim();if(l&&(!t||l===t))return l}catch{}const n=em(),r=Array.from(e.types??[]),o=e.files.length>0||r.some(l=>/^(?:files|public\.file-url|text\/uri-list)$/i.test(l)),s=!!n&&Array.from(e.files).some(l=>l.name===n.fileName||/\.(?:png|jpe?g|gif|webp|svg|avif|bmp)$/i.test(n.fileName)&&l.type.startsWith("image/"));if(n&&(n.reference===t||!t&&o&&s))return n.reference;if(!t)return null;const a=/^!\[\[[^\]\n]+\]\]$/.test(t)||/^!\[[^\]\n]*\]\((?!https?:|data:|blob:)[^)\n]+\)$/i.test(t);return o&&a?t:null}function Si(e,t){const n=d1(e);if(!n)return e.endOfTextblock(t);let r;try{const s=t==="up"?fe.atStart(e.state.doc).from:fe.atEnd(e.state.doc).to;r=e.coordsAtPos(s)}catch{return e.endOfTextblock(t)}const o=Math.max(4,(n.bottom-n.top)*.5);return t==="up"?n.top<=r.top+o:n.bottom>=r.bottom-o}function d1(e){const t=(e.dom.ownerDocument.defaultView??window).getSelection();if(!t||t.rangeCount===0)return null;const n=t.getRangeAt(0);let r=n.getBoundingClientRect();if(r.height||(r=n.getClientRects()[0]),!r?.height)try{const o=e.coordsAtPos(e.state.selection.head);return{top:o.top,bottom:o.bottom}}catch{return null}return{top:r.top,bottom:r.bottom}}function Ai(e){const t=(e.dom.ownerDocument.defaultView??window).getSelection();if(!t||t.rangeCount===0)return;const n=t.getRangeAt(0);let r=n.getBoundingClientRect();if(!r.height){const o=n.getClientRects();o.length&&(r=o[0])}return r.left}function f1(e,t,n){const r=e,o=r.caretRangeFromPoint?.(t,n);if(o)return{node:o.startContainer,offset:o.startOffset};const s=r.caretPositionFromPoint?.(t,n);return s?{node:s.offsetNode,offset:s.offset}:null}function p1(e,t,n){const r=e.dom.getBoundingClientRect(),o=Math.min(Math.max(n,r.left+2),r.right-2),s=t==="end"?r.bottom-4:r.top+4,a=f1(e.dom.ownerDocument,o,s);if(!a||!e.dom.contains(a.node))return null;try{return e.posAtDOM(a.node,a.offset)}catch{return null}}function Wa({initial:e,onChange:t,keys:n,saveImage:r,saveFiles:o,onOpenWiki:s,getPageNames:a,getFiles:l,isWikiResolved:i,wikiIcon:c,focusPlace:u,focusGoalX:d,focusAnchor:f,onFocused:m,blockId:p,slashOpsRef:h,onSlashPick:g,readOnly:y=!1,unified:k=!1,attachmentPagePath:M,extraPlugins:E,onAskTangu:x,aiMenu:I}){const R=A.useRef(!1),D=A.useRef(M);D.current=M;const U=A.useRef(n);U.current=n;const Re=A.useRef(r);Re.current=r;const we=A.useRef(o);we.current=o;const pe=A.useRef(s);pe.current=s;const Ke=A.useRef(a);Ke.current=a;const _=A.useRef(()=>!0);_.current=i??(()=>!0);const ye=A.useRef(()=>{});ye.current=c??(()=>{});const[Z,Ee]=A.useState(null),[B,N]=A.useState(null),[J,K]=A.useState(null),W=A.useRef(null),[Y,de]=A.useState(null),ve=A.useRef(null),[me,Pe]=A.useState(null),[Me,Ve]=A.useState(null),[He,Ct]=A.useState(null),zt=A.useRef(null),xn=A.useRef(null),en=A.useRef(null),St=A.useRef(!1),Ot=A.useRef(!1),[Pt,ee]=vk(),vn=Ui(),z=T=>{let C="";return ee()?.action(L=>{C=L.get(qt)(T)}),_d(C)};xk(T=>{const C=(S,w)=>{const{state:O}=S,j=O.selection,le=w.key.toLowerCase();if(p&&(w.metaKey||w.ctrlKey)&&(le==="z"||le==="y")){w.preventDefault(),w.stopPropagation();const ue=vn.getState();return le==="y"||w.shiftKey?ue.redo():ue.undo(),!0}if(w.key===" "&&j.empty&&!w.metaKey&&!w.ctrlKey&&!w.altKey){const ue=Lk(j.$from);if(ue&&Ek(j.$from.parent.type.name,ue)&&$k(S,ue," "))return w.preventDefault(),!0}if(rd(S,w))return w.preventDefault(),!0;const Ie=um(w);if(Ie){const ue=dm(O);if(ue)return w.preventDefault(),Le(ue,Ie==="followNewTab"),!0}if(w.key==="Enter")return w.shiftKey?k?!1:(U.current.insertAfter(zk(S,z)??void 0),!0):!1;if(!w.metaKey&&!w.ctrlKey&&!w.altKey&&!w.shiftKey&&(w.key==="ArrowLeft"&&oi(S)||w.key==="Backspace"&&oi(S,!0)))return w.preventDefault(),!0;if(w.key==="Backspace"){if(k||!j.empty||j.$head.pos!==fe.atStart(O.doc).$head.pos)return!1;const ue=j.$head.parent,Ce=O.schema.nodes.paragraph;return ue.type.name==="heading"&&ue.content.size>0&&Ce?(S.dispatch(O.tr.setBlockType(j.$head.start(),j.$head.end(),Ce)),!0):(_k(S)||(O.doc.textContent.trim()===""?U.current.deleteEmpty():U.current.mergePrev()),!0)}return w.key==="ArrowUp"?k?!1:(w.metaKey||w.ctrlKey)&&w.shiftKey?(U.current.moveDir("up"),!0):j.empty&&!w.metaKey&&!w.ctrlKey&&!w.shiftKey&&!w.altKey&&Si(S,"up")?(U.current.arrow("prev",Ai(S)),!0):!1:w.key==="ArrowDown"?k?!1:(w.metaKey||w.ctrlKey)&&w.shiftKey?(U.current.moveDir("down"),!0):j.empty&&!w.metaKey&&!w.ctrlKey&&!w.shiftKey&&!w.altKey&&Si(S,"down")?(U.current.arrow("next",Ai(S)),!0):!1:w.key==="Escape"&&p?(S.dom.blur(),Yp.getState().select(p),!0):!1},L=(S,w)=>{const O=()=>S.content.textBetween(0,S.content.size,`
|
|
49
|
+
|
|
50
|
+
`),j=S.content.childCount===1?S.content.firstChild:null,le=j?.type.name==="image"?j:j?.type.name==="paragraph"&&j.childCount===1&&j.firstChild?.type.name==="image"?j.firstChild:null;if(le){const Ae=String(le.attrs.src??"");return`??Ae})`}const Ie=w.state.selection,{$from:xe,$to:ue}=Ie;if(!(Ie instanceof Qe||!xe.sameParent(ue)||xe.parentOffset===0&&ue.parentOffset===ue.parent.content.size))return O();let mt=!1;if(S.content.forEach(Ae=>{Ae.type.name!=="paragraph"&&(mt=!0)}),!mt)return O();const Sn=Ie instanceof Qe&&Ie.node.type.name==="list_item"&&/_list$/.test(xe.parent.type.name)?oe.from(xe.parent.type.create(xe.parent.attrs,S.content)):S.content,Kt=w.state.schema.topNodeType.createAndFill(void 0,Sn);if(!Kt)return O();let jt=!1;Kt.descendants(Ae=>(/^amadeusCanvasCard$|^amadeusColumn/.test(Ae.type.name)&&(jt=!0),!jt));let Se=Pg(()=>{let Ae="";return ee()?.action(Ht=>{Ae=Ht.get(qt)(Kt)}),un(Ae)});return jt&&(Se=Se.replace(/^<!--\s*\/?a\s+[A-Za-z0-9_-]+\s*-->[ \t]*\n?/gm,"")),vo(Se).trim()||O()},$=async(S,w)=>{const O=await Re.current(w);if(!O)return;const j=S.state.schema.nodes.image;j&&S.dispatch(S.state.tr.replaceSelectionWith(j.create({src:O})).scrollIntoView())},H=(S,w)=>{const O=S.state.selection,j=(w.clipboardData?.getData("text/plain")??"").trim(),le=u1(w.clipboardData,j);if(le)return j?!1:(w.preventDefault(),S.pasteText(le));const Ie=S.state.schema.marks.link;if(Ie&&!O.empty&&O.$from.sameParent(O.$to)&&O.$from.parent.type.allowsMarkType(Ie)&&j&&!/\s/.test(j)&&/^https?:\/\//i.test(j)){const Se=Et(j);if(Se)return w.preventDefault(),S.dispatch(S.state.tr.addMark(O.from,O.to,Ie.create({href:Se}))),!0}const xe=i1(w.clipboardData);if(xe)return w.preventDefault(),$(S,xe),!0;const ue=Array.from(w.clipboardData?.files??[]);if(ue.length)return w.preventDefault(),we.current(ue),!0;if(k&&O.empty&&j&&!/\s/.test(j)&&/^https?:\/\//i.test(j)&&O.$from.parent.type.name==="paragraph"&&O.$from.parent.content.size===0){w.preventDefault();const Se=O.from,ht=Se+j.length;let Ae=null;try{Ae=S.coordsAtPos(Se)}catch{}return S.dispatch(S.state.tr.insertText(j,Se,O.to).setMeta("uiEvent","paste")),Ae&&Ct({url:j,from:Se,to:ht,left:Ae.left,top:Ae.bottom,anchorTop:Ae.top}),!0}const Ce=w.clipboardData?.getData("text/plain")??"",mt=w.clipboardData?.getData("text/html")??"",Sn=!!O.$from.parent.type.spec.code;if(k&&Ce&&!Sn&&S.input?.shiftKey){w.preventDefault();const Se=Ce.replace(/\r\n?/g,`
|
|
51
|
+
`).split(`
|
|
52
|
+
`),ht=S.state.schema.nodes.paragraph;if(Se.length===1||!ht)S.dispatch(S.state.tr.insertText(Se.join(" ")).scrollIntoView().setMeta("uiEvent","paste"));else{const Ae=oe.from(Se.map(Ht=>ht.create(null,Ht?S.state.schema.text(Ht):null)));S.dispatch(S.state.tr.replaceSelection(new _e(Ae,1,1)).scrollIntoView().setMeta("uiEvent","paste"))}return!0}const Kt=O.$from,jt=O.$to;if(k&&Ce&&!mt&&!Sn&&!/[\r\n]/.test(Ce)&&Kt.sameParent(jt)&&Kt.parent.isTextblock&&(Kt.parentOffset>0||jt.parentOffset<jt.parent.content.size)){let Se=null;ee()?.action(Ae=>{Se=Ae.get(xr)(Ce)??null});const ht=Se;if(ht){const Ae=[];ht.forEach(or=>{Ae.push(or.type.name)});const Ht=X0(Ce,Ae);if(Ht==="literal")return w.preventDefault(),S.dispatch(S.state.tr.insertText(Ce).scrollIntoView().setMeta("uiEvent","paste")),!0;if(Ht==="inline-ws"){w.preventDefault();const{schema:or}=S.state,Xa=/^\s*/.exec(Ce)[0],Qa=/\s*$/.exec(Ce)[0],sr=[];return Xa&&sr.push(or.text(Xa)),ht.firstChild.forEach(af=>{sr.push(af)}),Qa&&sr.push(or.text(Qa)),S.dispatch(S.state.tr.replaceSelection(new _e(oe.from(sr),0,0)).scrollIntoView().setMeta("uiEvent","paste")),!0}}}if(k&&Ce&&!mt&&!Sn&&Nd(Ce)){const Se=new DataTransfer;return Se.setData("text/plain",Md(Ce)),w.preventDefault(),S.pasteText(Se.getData("text/plain"),new ClipboardEvent("paste",{clipboardData:Se}))}return!1},X=(S,w)=>{if(!M||!Fe.copyAttachment)return!1;const O=c1(S),j=w;if(!O||!j.clipboardData)return!1;j.preventDefault(),j.clipboardData.clearData(),j.clipboardData.setData("text/plain",O.reference);try{j.clipboardData.setData(ji,O.reference)}catch{}return Fe.copyAttachment(M,O.ref,O.reference).then(le=>{le&&Xp(O.reference,O.ref)}),!0};let ae=!1;const Te=()=>(ae=!0,queueMicrotask(()=>{ae=!1}),!1),Le=(S,w)=>{const O=w?{newTab:!0}:void 0;if(S.kind==="app")return Qp(S.ref);if(S.kind==="wiki")return pe.current(S.arg,O);const j=wi(S.href);if(j==="note")return pe.current(xi(S.href,D.current,Ke.current()),O);if(j==="file"){D.current&&Fe.openAttachment(D.current,S.href);return}const le=Et(S.href);le&&window.open(le,"_blank","noopener")},Ge=(S,w,O)=>{if(O.button===2||al&&O.ctrlKey)return!1;const j=O.target?.closest?.("a[href]");if(!j||!j.getAttribute("href"))return!1;const le=wi(j.getAttribute("href"));if(le==="file")return!1;if(le==="note"){O.preventDefault();const xe=O.button===1||(al?O.metaKey:O.ctrlKey);return pe.current(xi(j.getAttribute("href"),D.current,Ke.current()),xe?{newTab:!0}:void 0),!0}const Ie=Et(j.getAttribute("href"));return Ie?(O.preventDefault(),window.open(Ie,"_blank","noopener"),!0):!1};return Vp.make().config(S=>{S.set(Gp,T),S.set(Jp,e),S.update(Oi,w=>({...w,editable:()=>!y,handleKeyDown:y?void 0:C,handlePaste:y?void 0:H,handleDOMEvents:y?w.handleDOMEvents:{...w.handleDOMEvents,copy:X,drop:Te},clipboardTextParser:y?void 0:(O,j,le,Ie)=>{if(!ae)return null;ae=!1;const xe=Y0(O,le);if(xe==null)return null;const ue=S.get(xr)(xe);if(!ue||typeof ue=="string")return null;const Ce=Bi.fromSchema(Ie.state.schema).serializeFragment(ue.content);return Pi.fromSchema(Ie.state.schema).parseSlice(Ce)},handleClick:Ge,clipboardTextSerializer:L})),k?S.get(Dr).updated((w,O)=>{!R.current||y||t(Dd(w,O))}):p==null&&S.get(Dr).markdownUpdated((w,O)=>{!R.current||y||t(un(O))})}).use(re(S=>new se({view:()=>({update:(w,O)=>{k||p==null||y||!R.current||w.state.doc.eq(O.doc)||t(un(S.get(qt)(w.state.doc)))}})}))).use(rl("high",{pagePath:()=>D.current})).use(Ry).use(ny).use(Tb).use(I0).use(Vg).use(Qg).use(Wg).use(o1).use(k?yb:kb).use(Kk).use(uu).use(Oo).use(Po).use(Zg).use(eb).use(tb).use(co).use(Il).use(Rl).use(am()).use(lm()).use(cb()).use(Wy).use(Gu).use(l1(()=>P("mdblock.placeholder"))).use(ew()).use(im((S,w)=>pe.current(S,w),S=>_.current(S),S=>ye.current(S))).use(cm(Le)).use(re(()=>new se({props:{attributes:()=>D.current?{"data-amx-src":D.current}:{}}}))).use(re(()=>new se({view:S=>{const w=()=>{S.dom.setAttribute("aria-label",P("mdblock.editorLabel"))};return w(),{destroy:ns(w)}}}))).use(C0()).use(Mk()).use(sw((S,w)=>{if(!S){w||(en.current=null),St.current=!1,Ee(null);return}if(en.current===S.from){St.current=!1,Ee(null);return}St.current=!0,Ee(S)})).use(lw((S,w)=>{if(!S){w||(zt.current=null),Ot.current=!1,N(null);return}if(zt.current===S.from){Ot.current=!1;return}Ot.current=!0,N(S)})).use(Qw((S,w)=>{if(!S){w||(W.current=null),K(null);return}if(W.current===S.from){K(null);return}K(S)})).use(n0((S,w)=>{if(!S){w||(ve.current=null),de(null);return}if(ve.current===S.from){de(null);return}de(S)})).use(aw((S,w)=>{if(h){if(!S){w||(xn.current=null),Pe(null);return}if(St.current||Ot.current){Pe(null);return}if(xn.current===S.from){Pe(null);return}Pe(S)}})).use(uw(S=>Ve(h?S:null))).use(Pu).use($0()).use(Vk()).use(j0()).use(Rm).use(Ck).use(re(S=>ol({"Mod-u":()=>(S.get(ce).call(co.key),!0),"Mod-Shift-s":()=>(S.get(ce).call(Bn.key),!0),"Mod-k":()=>Ja(),"Mod-Shift-v":(w,O,j)=>!j?.editable||!navigator.clipboard?.readText?!1:(navigator.clipboard.readText().then(le=>{le&&!j.isDestroyed&&j.pasteText(le)}).catch(()=>{}),!0),"Mod-Shift-h":ub,"Alt-F10":()=>{const w=document.querySelector('[data-testid="inline-toolbar"] .itb-row button');return w?(w.focus(),!0):!1},"Mod-Shift-l":(w,O)=>ur(w,O,"left"),"Mod-Shift-e":(w,O)=>ur(w,O,"center"),"Mod-Shift-r":(w,O)=>ur(w,O,"right")}))).use(re(()=>ol({Tab:(S,w,O)=>k?!1:Dy(S,w,O),"Shift-Tab":(S,w)=>k?!1:_y(S,w)}))).use(q0).use(e1).use(ow).use(p0).use(k0).use(rl("normal",{pagePath:()=>D.current})).use(E??[])},[]),A.useEffect(()=>{if(h)return h.current={consume:()=>{let T=!0;return ee()?.action(C=>{const L=C.get(ie),{$from:$,empty:H}=L.state.selection;if(H){const X=Zl($);X&&L.dispatch(L.state.tr.delete(X.from,X.to))}T=L.state.doc.textContent.trim()===""}),T},transform:T=>{let C=!1;return ee()?.action(L=>{const $=L.get(ie),{$from:H,empty:X}=$.state.selection;C=Yt($,T,X?Zl(H):null),$.focus()}),C}},()=>{h&&(h.current=null)}},[h,ee]),A.useEffect(()=>{const T=requestAnimationFrame(()=>{R.current=!0});return()=>cancelAnimationFrame(T)},[]);const F=T=>C=>!(C.target instanceof Element&&C.target.closest(T)),Q=!!me;A.useEffect(()=>{if(!Q)return;const T=F(".slash-menu"),C=$=>{T($)&&Pe(null)},L=()=>Pe(null);return window.addEventListener("scroll",C,!0),window.addEventListener("resize",L),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",L)}},[Q]);const ot=!!Me;A.useEffect(()=>{if(!ot)return;const T=F(".inline-toolbar"),C=$=>{T($)&&Ve(null)},L=()=>Ve(null);return window.addEventListener("scroll",C,!0),window.addEventListener("resize",L),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",L)}},[ot]);const Ua=!!He;A.useEffect(()=>{if(!Ua)return;const T=()=>Ct(null);return window.addEventListener("scroll",T,!0),window.addEventListener("resize",T),()=>{window.removeEventListener("scroll",T,!0),window.removeEventListener("resize",T)}},[Ua]);const Gd=T=>{const C=He;Ct(null),C&&ee()?.action(L=>{const $=L.get(ie);if(!(C.to>$.state.doc.content.size||$.state.doc.textBetween(C.from,C.to)!==C.url)){if(T==="bookmark"){const H=$.state.doc.resolve(C.to),X=H.after(H.depth),ae=$.state.tr,Te=ae.doc.nodeAt(X),Le=$.state.schema.nodes.paragraph;Le&&!(Te?.type.name==="paragraph"&&Te.content.size===0)&&ae.insert(X,Le.create()),ae.setSelection(q.near(ae.doc.resolve(Math.min(X+1,ae.doc.content.size)))),$.dispatch(ae),$.focus();return}if(T==="embed"){const H=`![[${mf(C.url)}]]`,X=$.state.tr.insertText(H,C.from,C.to),ae=X.doc.resolve(Math.min(C.from+H.length,X.doc.content.size)),Te=ae.after(ae.depth),Le=X.doc.nodeAt(Te),Ge=$.state.schema.nodes.paragraph;Ge&&!(Le?.type.name==="paragraph"&&Le.content.size===0)&&X.insert(Te,Ge.create()),X.setSelection(q.near(X.doc.resolve(Math.min(Te+1,X.doc.content.size)))),$.dispatch(X)}else{const H=$.state.schema.marks.link,X=Pr(C.url),ae=$.state.tr.insertText(X,C.from,C.to);H&&ae.addMark(C.from,C.from+X.length,H.create({href:Et(C.url)||C.url})),$.dispatch(ae)}$.focus()}})};A.useEffect(()=>{if(u==null||Pt)return;const T=ee();T&&(T.action(C=>{const L=C.get(ie);if(L.focus(),u==="body-enter"){const ae=L.state.schema.nodes.paragraph,Te=L.state.doc.firstChild;let Le=L.state.tr;ae&&!(Te&&Te.type===ae&&Te.content.size===0)&&(Le=Le.insert(0,ae.create())),L.dispatch(Le.setSelection(q.near(Le.doc.resolve(1))).scrollIntoView());return}const $=u==="end"?fe.atEnd(L.state.doc):fe.atStart(L.state.doc);L.dispatch(L.state.tr.setSelection($).scrollIntoView());const H=d!=null?p1(L,u,d):null;H!=null&&L.dispatch(L.state.tr.setSelection(q.near(L.state.doc.resolve(H))).scrollIntoView());const X=f?Dk(L,f):null;X!=null&&L.dispatch(L.state.tr.setSelection(q.near(L.state.doc.resolve(X))).scrollIntoView())}),m())},[u,d,f,Pt,ee,m]),A.useEffect(()=>vn.subscribe((T,C)=>{T.pages===C.pages||Pt||ee()?.action(L=>{const $=L.get(ie);$.dispatch($.state.tr)})}),[Pt,ee]);const Jd=T=>{const C=Z;C&&ee()?.action($=>{const H=$.get(ie),{doc:X}=H.state;if(C.closeAt!==void 0&&X.textBetween(C.closeAt,Math.min(C.closeAt+2,X.content.size))==="]]"){const ae=S0(X.textBetween(C.to,C.closeAt,void 0,""),T),Te=H.state.tr.insertText(ae,C.from,C.closeAt);H.dispatch(Te.setSelection(q.create(Te.doc,C.from+ae.length+2)))}else H.dispatch(H.state.tr.insertText(`${T}]]`,C.from,C.to)),hm("note.wikilink");H.focus()}),Ee(null)},Cn=()=>{let T=!1;return ee()?.action(C=>{T=C.get(ie).hasFocus()}),T},Va=()=>{let T=!1;return ee()?.action(C=>{const{$head:L,empty:$}=C.get(ie).state.selection,H=L.parent.textBetween(L.parentOffset,Math.min(L.parentOffset+1,L.parent.content.size));T=!$||/[^\s\]]/.test(H)}),T},Yd=()=>{let T=null;return ee()?.action(C=>{T=C.get(ie).dom}),T},Xd=T=>{const C=B;C&&ee()?.action($=>{const H=$.get(ie);H.dispatch(H.state.tr.insertText(`[[${T}]]`,C.from-1,C.to)),H.focus()}),N(null)},Qd=T=>{if(!B||!k||!Je()?.submitDocumentTask||Je()?.hostExecution?.()===!1)return;const C=B;ee()?.action(L=>{const $=L.get(ie),H=$.state.schema.nodes.code_block.create({language:"forsion-task"},$.state.schema.text(kd(E0(T))));$.dispatch($.state.tr.replaceRangeWith(C.from-1,C.to,H).scrollIntoView()),$.focus()}),N(null)},Zd=T=>{const C=B;C&&ee()?.action($=>{const H=$.get(ie);H.dispatch(H.state.tr.insertText(`${T} `,C.from-1,C.to)),H.focus()}),N(null)},ef=T=>{const C=J;C&&ee()?.action(L=>{const $=L.get(ie),H=$.state.doc.textBetween(C.to,Math.min(C.to+1,$.state.doc.content.size),void 0,"");$.dispatch($.state.tr.insertText(/^\s/.test(H)?T:`${T} `,C.from,C.to)),$.focus()}),K(null)},tf=T=>{const C=Y;C&&ee()?.action(L=>{const $=L.get(ie);$.dispatch($.state.tr.insertText(T,C.from-1,C.to)),$.focus()}),de(null)},Ga=()=>{const T=a(),C=new Set(T),L=fp().filter(H=>C.has(H)),$=new Set(L);return[...L,...T.filter(H=>!$.has(H))]},Bt=(T,C)=>{ee()?.action(L=>{L.get(ce).call(T,C),L.get(ie).focus()})},Ja=()=>{const T=ee();if(!T)return!1;let C=!1;return T.action(L=>{const $=L.get(ie),H=et.type(L),{from:X,to:ae,empty:Te,$from:Le}=$.state.selection;if(!Le.parent.isTextblock||Le.parent.type.spec.code)return;C=!0;const Ge=Wd($.state.doc,X,ae,H),S=$.state.doc,w=Ge??{from:X,to:ae};(Ge?gp(P("mdblock.link.editTitle"),Ge.href,{label:P("mdblock.link.label"),altLabel:P("mdblock.link.remove")}):So(P("mdblock.link.title"),"",{label:P("mdblock.link.label")})).then(j=>{const le=j===null||j===oo?null:Et(j);j!==oo&&!le||ee()?.action(Ie=>{const xe=Ie.get(ie);if(xe.state.doc!==S)return;const ue=et.type(Ie);if(j===oo)xe.dispatch(xe.state.tr.removeMark(w.from,w.to,ue));else if(w.to>w.from)xe.dispatch(xe.state.tr.removeMark(w.from,w.to,ue).addMark(w.from,w.to,ue.create({href:le})));else if(le){const Ce=Pr(le),mt=xe.state.tr.insertText(Ce,w.from);mt.addMark(w.from,w.from+Ce.length,ue.create({href:le})),xe.dispatch(mt.setSelection(q.create(mt.doc,w.from+Ce.length)).scrollIntoView())}xe.focus()})})}),C},nf=()=>{ee()?.action(T=>{const C=T.get(ie),{from:L,to:$,empty:H}=C.state.selection;H||C.dispatch(C.state.tr.removeMark(L,$,null)),C.focus()})},ro=T=>{ee()?.action(C=>{const L=C.get(ie);ur(L.state,$=>L.dispatch($),T),L.focus()})},rf={text:{kind:"text"},h1:{kind:"heading",level:1},h2:{kind:"heading",level:2},h3:{kind:"heading",level:3},h4:{kind:"heading",level:4},h5:{kind:"heading",level:5},h6:{kind:"heading",level:6},bullet:{kind:"bullet"},ordered:{kind:"ordered",order:1},todo:{kind:"task",checked:!1},quote:{kind:"quote"},fold:{kind:"fold"}},of=T=>{let C=!1;return ee()?.action(L=>{const $=L.get(ie),{state:H}=$;if(id(H.selection).tableCell)return;const{$from:X,$to:ae}=H.selection,Te=X.before(X.depth),Le=ae.after(ae.depth),Ge=H.doc.textBetween(Te,Le,`
|
|
53
|
+
`,`
|
|
54
|
+
`).trim(),S=T==="codeblock"?H.schema.nodes.code_block?.create(null,Ge?H.schema.text(Ge):void 0):H.schema.nodes.paragraph?.create(null,H.schema.text(`$$ ${Ge} $$`));if(!S)return;const w=H.tr.replaceWith(Te,Le,S);w.setSelection(q.near(w.doc.resolve(Te+1))),$.dispatch(w.scrollIntoView()),$.focus(),C=!0}),C},Ya=T=>{const C=mw[T];window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:P("mdblock.turn.failed",{kind:C?P(C):T})}}))},sf=T=>{if(T==="codeblock"||T==="math"){of(T)||Ya(T);return}const C=rf[T];if(C){let $=!1;ee()?.action(H=>{const X=H.get(ie);$=Yt(X,C,null),X.focus()}),$||Ya(T);return}({bold:()=>Bt(Hr.key),italic:()=>Bt(jr.key),underline:()=>Bt(co.key),strike:()=>Bt(Bn.key),code:()=>Bt(Fr.key),link:Ja,clear:nf,alignLeft:()=>ro("left"),alignCenter:()=>ro("center"),alignRight:()=>ro("right")})[T]?.()};return b.jsxs(b.Fragment,{children:[b.jsx(wk,{}),b.jsxs(Ki,{children:[Z&&!y&&b.jsx(di,{query:Z.query,left:Z.left,top:Z.top,anchorTop:Z.anchorTop,getPageNames:Ga,getFiles:l,onPick:Jd,onClose:()=>{en.current=Z.from,St.current=!1,Ee(null)},editorFocused:Cn,caretMidWord:Va,sourcePath:M}),!Z&&B&&!y&&b.jsx(di,{query:B.query,left:B.left,top:B.top,anchorTop:B.anchorTop,getPageNames:Ga,getFiles:l,onPick:Xd,onPickRaw:Zd,agents:k&&Je()?.submitDocumentTask&&Je()?.hostExecution?.()!==!1?Je()?.agents?.():void 0,onPickAgent:k&&Je()?.submitDocumentTask&&Je()?.hostExecution?.()!==!1?Qd:void 0,editorFocused:Cn,caretMidWord:Va,dates:!0,allowCreate:!1,onClose:()=>{zt.current=B.from,Ot.current=!1,N(null)}}),J&&!Z&&!B&&!y&&b.jsx(e0,{query:J.query,left:J.left,top:J.top,anchorTop:J.anchorTop,onPick:ef,editorFocused:Cn,onClose:()=>{W.current=J.from,K(null)}}),Y&&!Z&&!B&&!J&&!me&&!y&&b.jsx(r0,{query:Y.query,left:Y.left,top:Y.top,anchorTop:Y.anchorTop,onPick:tf,editorFocused:Cn,onClose:()=>{ve.current=Y.from,de(null)}}),me&&g&&!Z&&!B&&!y&&b.jsx(v1,{query:me.query,left:me.left,top:me.top,anchorTop:me.anchorTop,hideKeys:k?b1:void 0,ctx:me.ctx,unified:k,editorFocused:Cn,editorDom:Yd,onPick:T=>{Pe(null),ee()?.action(C=>{si(C.get(ie),me.from)}),g(T)},onClose:()=>{let T=!1;ee()?.action(C=>{const L=C.get(ie);if(!si(L,me.from))return;const{doc:$}=L.state;me.from<1||me.to>$.content.size||$.textBetween(me.from-1,me.from)!=="/"||(L.dispatch(L.state.tr.delete(me.from-1,me.to)),T=!0)}),T||(xn.current=me.from),Pe(null)}}),He&&!y&&b.jsx(x1,{left:He.left,top:He.top,anchorTop:He.anchorTop,url:He.url,onPick:Gd,onClose:()=>Ct(null)}),Me&&!Z&&!B&&!me&&!He&&!y&&b.jsx(hw,{left:Me.left,top:Me.top,bottom:Me.bottom,kind:Me.kind,active:Me.active,align:Me.align,shape:Me.shape,fg:Me.fg,bg:Me.bg,onAct:sf,onColor:T=>Bt(Il.key,T||void 0),onBg:T=>Bt(Rl.key,T||void 0),onClose:()=>{Ve(null),ee()?.action(T=>{const C=T.get(ie);C.dispatch(C.state.tr.setMeta(yr,!0))})},onReturnFocus:()=>ee()?.action(T=>T.get(ie).focus()),onAsk:x?()=>{Ve(null),ee()?.action(T=>x(T.get(ie)))}:void 0,ai:I?{items:I.items,translate:I.translate,more:I.more?.(Me.from,Me.to),onPick:T=>{Ve(null),ee()?.action(C=>I.onPick(T,C.get(ie)))}}:void 0})]})]})}function jd({blockId:e,content:t,pagePath:n,onChange:r,onInsertAfter:o,onDeleteEmpty:s,onMergePrev:a,onArrowOut:l,onMoveDir:i,focusPlace:c,focusGoalX:u,focusAnchor:d,onFocused:f,requestSelfFocus:m,onOpenWiki:p,onInsertEmbed:h,getPageNames:g,readOnly:y=!1}){const k=Ui(),M=n.replace(/\\/g,"/").split("/").slice(0,-1).join("/"),E=A.useRef(t),[x,I]=A.useState(0),[R,D]=A.useState(!1),U=A.useRef(null);t!==E.current&&(E.current=t,I(B=>B+1));const Re=B=>{const N=xf(B,M);E.current=N,r(N)},we=async B=>{if(!n)return null;try{const N=new Uint8Array(await B.arrayBuffer()),{opts:J}=await so(),{pageRel:K}=await Fe.saveAttachment(n,B.name||"pasted.png",N,J);return Ri(wf(M,K),!0)}catch{return null}},pe=async B=>{if(!n)return;const N=[];for(const J of B)try{const K=new Uint8Array(await J.arrayBuffer()),{opts:W}=await so(),{base:Y}=await Fe.saveAttachment(n,J.name||"file",K,W);N.push(`![[${Y}]]`)}catch{}N.length&&(t.trim()===""?(r(N[0]),N.length>1&&k.getState().insertBlocksAfter(e,N.slice(1))):k.getState().insertBlocksAfter(e,N))},Ke={insertAfter:o,deleteEmpty:s,mergePrev:a,arrow:l,moveDir:i,selfFocus:m},_=(B,N)=>{const J=k.getState();if(J.activePage!==n||!J.blocks[e]){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:P("mdblock.toast.staleTarget")}}));return}const K=(J.blocks[e].content??"").trim()==="";N&&K?r(B):o(B)},ye=async B=>{const N=B.scaffold;if(!U.current)return;const J=B.run?void 0:Hd[N];if(J){U.current.transform(J)||Ud(B.label);return}const K=U.current.consume();if(B.run){try{const W=await B.run({pagePath:n,folder:ar(n)});if(W!==""&&W!=null){if(typeof W!="string")throw new Error(P("mdblock.plugin.runNotString",{type:typeof W}));if(W.length>8192)throw new Error(P("mdblock.plugin.runTooLong"));if(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(W))throw new Error(P("mdblock.plugin.runControlChars"));_(W,K),k.getState().syncFdChildren(n)}}catch(W){console.error("[plugin] slash item failed",W),window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:P("mdblock.toast.slashFailed",{label:B.label,message:W instanceof Error?W.message:String(W)}),error:!0}}))}return}if(N===Pa){window.dispatchEvent(new CustomEvent("amadeus:template-picker",{detail:{afterId:e,emptyBlock:K}}));return}if(N===Ba){const W=document.createElement("input");W.type="file",W.accept="image/*",W.onchange=()=>{const Y=W.files?.[0];Y&&(async()=>{try{const de=new Uint8Array(await Y.arrayBuffer()),{opts:ve}=await so(),{base:me}=await Fe.saveAttachment(n,Y.name||"image.png",de,ve),Pe=`![[${me}]]`;_(Pe,K)}catch{}})()},W.click();return}if(N===qa){(async()=>{try{const W=k.getState(),Y=await W.createChildNote(n,P("mdblock.default.childNote")),ve=`[[${Y.split("/").pop().replace(/\.md$/i,"")}]]`;_(ve,K),W.loadPage(Y)}catch{}})();return}if(N===ja){(async()=>{try{const W=P("mdblock.default.database"),Y=new TextEncoder().encode(nl(gf(W))),{base:de}=await Fe.saveAttachment(n,`${W}.db`,Y,{mode:"vault",folder:ar(n)}),ve=`![[${de}]]`;_(ve,K),k.getState().syncFdChildren(n)}catch{}})();return}if(N===Ha){(async()=>{try{const W=new TextEncoder().encode(bf(yf)),de=`![[${(await Fe.saveAttachment(n,`${$d(P("mdblock.default.drawing"))}.excalidraw.md`,W,{mode:"vault",folder:ar(n)})).base.replace(/\.md$/i,"")}]]`;_(de,K),k.getState().syncFdChildren(n)}catch{}})();return}if(N===Fa){(async()=>{try{const W=ar(n);let Y=null;for(let Me=1;Me<=20&&Y===null;Me++)try{const Ve=P("mdblock.default.noteViewFolder");Y=await Fe.createFolder(W,Me===1?Ve:`${Ve} ${Me}`)}catch{}if(Y===null)return;const de=P("mdblock.default.noteView"),ve=new TextEncoder().encode(nl(kf(de,Y))),{base:me}=await Fe.saveAttachment(n,`${de}.db`,ve,{mode:"vault",folder:W}),Pe=`![[${me}]]`;_(Pe,K),k.getState().syncFdChildren(n)}catch{}})();return}if(N===Ka){k.getState().splitToColumn(e,"right");return}if(N===za){D(!0);return}if(N===Oa){So(P("mdblock.bookmark.title"),"",{label:P("mdblock.bookmark.label")}).then(W=>{const Y=W?.trim();Y&&/^https?:\/\/\S+$/i.test(Y)&&(K?r(Y):o(Y))});return}if(N===_a){if(!h)return;let W="";try{const Y=await navigator.clipboard.readText(),de=/!\[\[([^\]\n]+)\]\]/.exec(Y);de&&(W=de[1].trim())}catch{}So(P("mdblock.embed.title"),W,{label:P("mdblock.embed.label"),confirmLabel:P("mdblock.embed.confirm")}).then(Y=>{const de=Y?.trim().replace(/^!?\[\[/,"").replace(/\]\]$/,"").trim();de&&h(de)});return}K?(r(N),setTimeout(()=>m("end"),0)):o(N)},Z=A.useRef(()=>{});Z.current=B=>{ye(B)};const Ee=A.useRef(B=>Z.current(B)).current;return A.useEffect(()=>()=>{zn===Ee&&(zn=null)},[Ee]),b.jsxs("div",{className:"md-block",onFocusCapture:()=>{y||(zn=Ee)},children:[b.jsx(Ju,{children:b.jsx(Wa,{initial:hf(t,M),onChange:Re,keys:Ke,saveImage:we,saveFiles:pe,onOpenWiki:p,getPageNames:g,blockId:e,slashOpsRef:U,onSlashPick:ye,getFiles:()=>Up()?k.getState().files:[],isWikiResolved:B=>!!xo(B,g(),n)||!!bm(B,k.getState().files,n),wikiIcon:B=>{const N=xo(B,g(),n);return N?k.getState().icons[N]:void 0},focusPlace:c,focusGoalX:u,focusAnchor:d,onFocused:f,attachmentPagePath:n,readOnly:y})},`${x}:${y?1:0}`),R&&!y&&b.jsx(Ki,{children:b.jsx(Vd,{onClose:()=>D(!1),onPick:B=>{D(!1);const N=`![[${B}]]`;t.trim()===""?r(N):o(N)}})})]})}function m1({initial:e,onChange:t,readOnly:n=!1,immediate:r=!1}){const o=A.useRef(t);o.current=t;const s=A.useRef(e);s.current=e;const a=A.useRef(null),l=A.useRef(!1),i=A.useRef(null),c=p=>{const h=vo(un(p));i.current!==h&&(i.current=h,l.current||o.current(h))},u=A.useRef(c);u.current=c;const d=A.useMemo(()=>r?[re(p=>new se({view:h=>{const g=()=>{if(h.isDestroyed||s.current===i.current)return;const y=p.get(xr)(tl(s.current));if(!(!y||y.eq(h.state.doc))){l.current=!0;try{h.dispatch(h.state.tr.replaceWith(0,h.state.doc.content.size,y.content).setMeta("addToHistory",!1))}finally{l.current=!1}}};return a.current=g,queueMicrotask(()=>{a.current===g&&g()}),{update:(y,k)=>{y.state.doc.eq(k.doc)||u.current(p.get(qt)(y.state.doc))},destroy:()=>{a.current===g&&(a.current=null)}}}}))]:void 0,[r]);A.useLayoutEffect(()=>{r&&a.current?.()},[e,r]);const f=()=>{},m={insertAfter:f,deleteEmpty:f,mergePrev:f,arrow:f,moveDir:f,selfFocus:f};return b.jsx("div",{className:"md-block md-plain",children:b.jsx(Ju,{children:b.jsx(Wa,{initial:tl(e),onChange:r?f:p=>t(vo(p)),extraPlugins:d,keys:m,saveImage:async()=>null,saveFiles:async()=>{},onOpenWiki:f,getPageNames:()=>[],focusPlace:null,onFocused:f,readOnly:n})})})}function h1(e){const t=n=>e("amadeus.default.tableColumn",{n});return`| ${t(1)} | ${t(2)} |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| | |`}const g1={embed:_a,linkdb:za,bookmark:Oa,template:Pa,image:Ba,column:Ka,database:ja,drawing:Ha,noteview:Fa,page:qa,card:zd,ai:Od,instructions:Pd,agentTask:Bd,prompt:Kd},Hd={"":{kind:"text"},"# ":{kind:"heading",level:1},"## ":{kind:"heading",level:2},"### ":{kind:"heading",level:3},"#### ":{kind:"heading",level:4},"##### ":{kind:"heading",level:5},"###### ":{kind:"heading",level:6},"- ":{kind:"bullet"},"1. ":{kind:"ordered",order:1},"- [ ] ":{kind:"task",checked:!1},"| ":{kind:"quote"},"> ":{kind:"fold"}},Fd=[{key:"ai",labelKey:"mdblock.slash.ai",hint:"AI",icon:b.jsx(gm,{width:"1em",height:"1em",strokeWidth:1.6}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Od,kw:"ai 人工智能 写作 xiezuo 续写 xuxie 生成 tangu ask 问",unifiedOnly:!0,needsAi:!0},{key:"instructions",labelKey:"mdblock.slash.instructions",hint:"",icon:b.jsx(bp,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Pd,kw:"ai instructions instruction 指令 zhiling 页指令 维护规则",unifiedOnly:!0},{key:"agent-task",labelKey:"mdblock.slash.agentTask",hint:"",icon:b.jsx(Wi,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Bd,kw:"ai agent task mention 任务 renwu 交办 提及",unifiedOnly:!0,needsDocumentTask:!0},{key:"prompt",labelKey:"mdblock.slash.prompt",hint:"",icon:b.jsx(yp,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Kd,kw:"ai prompt 提示词 tishici 模板",unifiedOnly:!0,needsDocumentTask:!0},{key:"text",labelKey:"mdblock.slash.text",hint:"",icon:b.jsx(kp,{}),groupKey:"mdblock.group.basic",scaffold:"",kw:"text 文本 paragraph zhengwen 正文"},{key:"h1",labelKey:"mdblock.slash.h1",hint:"#",icon:b.jsx(wp,{}),groupKey:"mdblock.group.basic",scaffold:"# ",kw:"h1 heading 标题 biaoti title 大标题"},{key:"h2",labelKey:"mdblock.slash.h2",hint:"##",icon:b.jsx(xp,{}),groupKey:"mdblock.group.basic",scaffold:"## ",kw:"h2 heading 标题 biaoti 中标题"},{key:"h3",labelKey:"mdblock.slash.h3",hint:"###",icon:b.jsx(vp,{}),groupKey:"mdblock.group.basic",scaffold:"### ",kw:"h3 heading 标题 biaoti 小标题"},{key:"h4",labelKey:"mdblock.slash.h4",hint:"####",icon:b.jsx(Cp,{}),groupKey:"mdblock.group.basic",scaffold:"#### ",kw:"h4 heading 标题 biaoti 四级"},{key:"h5",labelKey:"mdblock.slash.h5",hint:"#####",icon:b.jsx(Sp,{}),groupKey:"mdblock.group.basic",scaffold:"##### ",kw:"h5 heading 标题 biaoti 五级"},{key:"h6",labelKey:"mdblock.slash.h6",hint:"######",icon:b.jsx(Ap,{}),groupKey:"mdblock.group.basic",scaffold:"###### ",kw:"h6 heading 标题 biaoti 六级"},{key:"ul",labelKey:"mdblock.slash.ul",hint:"-",icon:b.jsx(Mp,{}),groupKey:"mdblock.group.list",scaffold:"- ",kw:"ul bullet list 无序 列表 liebiao"},{key:"ol",labelKey:"mdblock.slash.ol",hint:"1.",icon:b.jsx(Np,{}),groupKey:"mdblock.group.list",scaffold:"1. ",kw:"ol number list 有序 列表 编号"},{key:"todo",labelKey:"mdblock.slash.todo",hint:"[ ]",icon:b.jsx(Ep,{}),groupKey:"mdblock.group.list",scaffold:"- [ ] ",kw:"todo task check 待办 任务 复选框 daiban renwu"},{key:"card",labelKey:"mdblock.slash.card",hint:"Canvas",icon:b.jsx(Tp,{}),groupKey:"mdblock.group.basic",scaffold:zd,kw:"card 卡片 node 节点 canvas 画布",unifiedOnly:!0},{key:"quote",labelKey:"mdblock.slash.quote",hint:"|",icon:b.jsx(Ip,{}),groupKey:"mdblock.group.advanced",scaffold:"| ",kw:"quote 引用 yinyong blockquote"},{key:"fold",labelKey:"mdblock.slash.fold",hint:">",icon:b.jsx(Rp,{}),groupKey:"mdblock.group.advanced",scaffold:"> ",kw:"fold toggle 折叠 zhedie collapse 展开 详情 details"},{key:"code",labelKey:"mdblock.slash.code",hint:"```",icon:b.jsx(Lp,{}),groupKey:"mdblock.group.advanced",scaffold:"```\n\n```",kw:"code 代码 daima codeblock"},{key:"table",labelKey:"mdblock.slash.table",hint:"⊞",icon:b.jsx($p,{}),groupKey:"mdblock.group.advanced",scaffold:h1,kw:"table 表格 biaoge grid 网格"},{key:"divider",labelKey:"mdblock.slash.divider",hint:"---",icon:b.jsx(Dp,{}),groupKey:"mdblock.group.advanced",scaffold:`---
|
|
57
|
+
|
|
58
|
+
`,kw:"divider hr 分割线 分隔 fenge"},{key:"math",labelKey:"mdblock.slash.math",hint:"$$",icon:b.jsx(_p,{}),groupKey:"mdblock.group.advanced",scaffold:"$$ $$",kw:"math latex katex formula 数学 公式 gongshi"},{key:"wikilink",labelKey:"mdblock.slash.wikilink",hint:"[[",icon:b.jsx(zp,{}),groupKey:"mdblock.group.advanced",scaffold:"[[",kw:"link wiki note 链接 笔记 双链 lianjie shuanglian"},{key:"image",labelKey:"mdblock.slash.image",hint:"",icon:b.jsx(Op,{}),groupKey:"mdblock.group.advanced",scaffold:Ba,kw:"image picture photo 图片 tupian 插图"},{key:"columns",labelKey:"mdblock.slash.columns",hint:"⫿",icon:b.jsx(Pp,{}),groupKey:"mdblock.group.advanced",scaffold:Ka,kw:"column split 分栏 分列 fenlan 并排"},{key:"page",labelKey:"mdblock.slash.page",hint:".fd",icon:b.jsx(Bp,{}),groupKey:"mdblock.group.advanced",scaffold:qa,kw:"page 页面 子页面 subpage child yemian xinjian 新建页面 notion"},{key:"database",labelKey:"mdblock.slash.database",hint:".db",icon:b.jsx(vr,{}),groupKey:"mdblock.group.advanced",scaffold:ja,kw:"database db 多维表 duoweibiao 数据库 shujuku 表格 base notion"},{key:"drawing",labelKey:"mdblock.slash.drawing",hint:"Excalidraw",icon:b.jsx(Kp,{}),groupKey:"mdblock.group.advanced",scaffold:Ha,kw:"drawing draw excalidraw 画板 huaban 手绘 白板 whiteboard 草图 sketch 流程图"},{key:"linkdb",labelKey:"mdblock.slash.linkdb",hint:"![[.db]]",icon:b.jsx(vr,{}),groupKey:"mdblock.group.advanced",scaffold:za,kw:"link database db 链接多维表 链接数据库 引用数据库 嵌入数据库 已有 lianjie duoweibiao shujuku"},{key:"noteview",labelKey:"mdblock.slash.noteview",hint:"Bases",icon:b.jsx(jp,{}),groupKey:"mdblock.group.advanced",scaffold:Fa,kw:"noteview bases 笔记视图 bijishitu 行即笔记 folder page 多维表 notion"},{key:"template",labelKey:"mdblock.slash.template",hint:"templates/",icon:b.jsx(Hp,{}),groupKey:"mdblock.group.advanced",scaffold:Pa,kw:"template 模板 muban 套用"},{key:"embed",labelKey:"mdblock.slash.embed",hint:"![[ ]]",icon:b.jsx(Fp,{}),groupKey:"mdblock.group.advanced",scaffold:_a,kw:"embed 嵌入 引用 transclude block 块 qianru yinyong 复用"},{key:"bookmark",labelKey:"mdblock.slash.bookmark",hint:"https://",icon:b.jsx(qp,{}),groupKey:"mdblock.group.advanced",scaffold:Oa,kw:"bookmark link url 书签 链接 网页 网址 shuqian youtube 视频"},{key:"button",labelKey:"mdblock.slash.button",hint:"",icon:b.jsx(Wp,{}),groupKey:"mdblock.group.advanced",scaffold:mp,kw:"button 按钮 anniu 自动化 automation 一键 yijian 快捷 notion"}],b1=new Set;function wr(e){return typeof e=="function"?e():e}function qd({unified:e=!1}={}){const{t}=hn(),n=pp(a=>a.slashItems),r=[...Fd.map(({labelKey:a,groupKey:l,scaffold:i,...c})=>({...c,label:t(a),group:t(l),scaffold:typeof i=="function"?i(t):i})),...n.map(({item:a})=>({key:a.id,category:"plugin",label:wr(a.label),hint:a.hint??"",icon:hp(a.icon,"·"),group:wr(a.group)??t("mdblock.group.plugin"),scaffold:a.scaffold??"",run:a.run,kw:`${a.keywords??""} ${wr(a.label)}`}))],o=!!Je()?.complete,s=!!Je()?.submitDocumentTask&&Je()?.hostExecution?.()!==!1;return r.filter(a=>(e||!a.unifiedOnly)&&(o||!a.needsAi)&&(s||!a.needsDocumentTask))}let zn=null;function y1(){return zn}function k1(e){zn=e}function w1(e,t){let n=null;for(const r of[t.label,...t.kw.split(/\s+/)]){const o=Ze(e,r);o!==null&&(n=n===null?o:Math.max(n,o))}return n}function Wd(e,t,n,r){const o=e.resolve(t);if(!o.sameParent(e.resolve(n))||!o.parent.isTextblock)return null;const s=[];let a=o.start();o.parent.forEach(i=>{const c=a+i.nodeSize,u=r.isInSet(i.marks);if(u){const d=String(u.attrs.href??""),f=s[s.length-1];f&&f.to===a&&f.href===d?f.to=c:s.push({from:a,to:c,href:d})}a=c});const l=s.filter(i=>t===n?i.from<=t&&t<=i.to:i.from<n&&t<i.to);return l.length?{from:Math.min(t,l[0].from),to:Math.max(n,l[l.length-1].to),href:l[0].href}:null}function Ud(e){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:P("mdblock.turn.failed",{kind:e})}}))}function Pr(e){try{return new URL(e).hostname.replace(/^www\./,"")||e}catch{return e}}function x1({left:e,top:t,anchorTop:n,url:r,onPick:o,onClose:s}){const{t:a}=hn(),l=[{k:"link",label:a("mdblock.pasteAs.link"),hint:Pr(r)},{k:"bookmark",label:a("mdblock.pasteAs.bookmark"),hint:a("mdblock.pasteAs.bookmarkHint")},{k:"embed",label:a("mdblock.pasteAs.embed"),hint:a("mdblock.pasteAs.embedHint")}],[i,c]=A.useState(-1),u=A.useRef(-1);return u.current=i,A.useLayoutEffect(()=>{const d=m=>{m.preventDefault(),m.stopPropagation()},f=m=>{if(m.isComposing||m.key==="Process"||m.keyCode===229)return;const p=!m.metaKey&&!m.ctrlKey&&!m.altKey&&!m.shiftKey;if(m.key==="Escape")d(m),s();else if((m.key==="ArrowDown"||m.key==="ArrowUp")&&p)d(m),c(h=>h<0?0:Math.max(0,Math.min(h+(m.key==="ArrowDown"?1:-1),l.length-1)));else if(m.key==="Enter"||m.key==="Tab"){const h=u.current;if(h<0){s();return}d(m),o(l[h].k)}else m.key!=="Shift"&&m.key!=="Meta"&&m.key!=="Control"&&m.key!=="Alt"&&s()};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[o,s,l.length]),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:s}),b.jsxs(Wt,{className:"paste-as-menu",role:"menu",x:e,y:t,anchorTop:n,prefer:"above",children:[b.jsx("div",{className:"paste-as-label",children:a("mdblock.pasteAs.title")}),l.map((d,f)=>b.jsxs("button",{className:"paste-as-item","data-active":f===i||void 0,role:"menuitem",onMouseEnter:()=>c(f),onMouseDown:m=>{m.preventDefault(),m.stopPropagation(),o(d.k)},children:[b.jsx("span",{className:"paste-as-name",children:d.label}),b.jsx("span",{className:"paste-as-hint",children:d.hint})]},d.k)),b.jsxs("div",{className:"paste-as-foot",children:[b.jsx("span",{children:a("mdblock.foot.select")}),b.jsx("span",{children:a("mdblock.foot.confirm")}),b.jsx("span",{children:a("mdblock.foot.close")})]})]})]})}function v1({query:e,left:t,top:n,anchorTop:r,hideKeys:o,ctx:s,unified:a,editorFocused:l,editorDom:i,onPick:c,onClose:u}){const{t:d}=hn(),[f,m]=A.useState(0),[p,h]=A.useState(null),g=`amx-slash-${A.useId().replace(/[^\w-]/g,"")}`,y=A.useRef(i);y.current=i;const k=qd({unified:a}),M=A.useMemo(()=>k.filter(N=>!o?.has(N.key)&&(!s||rw(N.key,s))),[k,o,s]),E=e.trim().toLowerCase(),x=E?M.map(N=>({it:N,s:w1(E,N)})).filter(N=>N.s!==null).sort((N,J)=>J.s-N.s).map(N=>N.it):M,I=p?.query===E?p.category:gw(x,E),R=x.filter(N=>ud(N)===I),D=Array.from(new Set(R.map(N=>N.group))),U=E?R:D.flatMap(N=>R.filter(J=>J.group===N)),Re=N=>{h({query:E,category:N}),m(0)},we=dd(I);A.useEffect(()=>{m(0),h(null)},[e]);const pe=A.useRef(null),[Ke,_]=A.useState(null),ye=Ke?.query===E?Ke.height:void 0;A.useLayoutEffect(()=>{const N=pe.current?.offsetHeight??0;N>(ye??0)&&_({query:E,height:N})});const Z=U.length?Math.min(f,U.length-1):-1;A.useEffect(()=>{const N=y.current?.();if(N)return N.setAttribute("aria-controls",`${g}-commands`),Z>=0?N.setAttribute("aria-activedescendant",`${g}-${Z}`):N.removeAttribute("aria-activedescendant"),()=>{N.removeAttribute("aria-activedescendant"),N.removeAttribute("aria-controls")}},[g,Z]),A.useEffect(()=>{const N=K=>{K.preventDefault(),K.stopPropagation()},J=K=>{if(K.isComposing||K.key==="Process"||K.keyCode===229||l&&!l())return;const W=!K.metaKey&&!K.ctrlKey&&!K.altKey&&!K.shiftKey;if(K.key==="Escape")N(K),u();else if(W&&K.key.startsWith("Arrow")){const Y=bw(I,K.key);if(Y!==null)N(K),Re(Y);else{const de=yw(U.length,Z,K.key);de!==null&&(N(K),m(de))}}else if(K.key==="Enter"||K.key==="Tab"){const Y=U[Z];Y?(N(K),c(Y)):u()}};return window.addEventListener("keydown",J,!0),()=>window.removeEventListener("keydown",J,!0)},[U,f,I,E,c,u,l]);const Ee=(N,J)=>b.jsxs("button",{id:`${g}-${J}`,className:"slash-item","data-key":N.key,"aria-label":N.label,"data-active":J===Z||void 0,ref:J===Z?K=>K?.scrollIntoView({block:"nearest"}):void 0,onMouseEnter:()=>m(J),onMouseDown:K=>{K.preventDefault(),c(N)},role:"menuitem",children:[b.jsx("span",{className:"slash-icon","aria-hidden":!0,children:N.icon}),b.jsx("span",{className:"slash-label",children:N.label}),b.jsx("span",{className:"slash-hint",children:N.hint})]},N.key),B=[];return U.forEach((N,J)=>{let K=B.find(W=>W.name===N.group);K||(K={name:N.group,rows:[]},B.push(K)),K.rows.push({it:N,idx:J})}),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:u}),b.jsxs(Wt,{id:g,className:"slash-menu",x:t,y:n,anchorTop:r,style:{minHeight:ye},innerRef:N=>{pe.current=N},onMouseDown:N=>N.preventDefault(),children:[b.jsx("div",{className:"slash-category-tabs cap-tabs",role:"tablist","aria-label":d("mdblock.category.label"),ref:we,children:Ln.map(N=>b.jsx("button",{type:"button",id:`${g}-tab-${N}`,className:"slash-category-tab",role:"tab","data-category":N,"aria-selected":I===N,"aria-controls":`${g}-panel`,tabIndex:-1,onMouseDown:J=>J.preventDefault(),onClick:()=>Re(N),children:d(`mdblock.category.${N}`)},N))}),b.jsxs("div",{className:"slash-list",id:`${g}-panel`,role:"tabpanel","data-category":I,"aria-labelledby":`${g}-tab-${I}`,children:[U.length===0&&b.jsx("div",{className:"slash-empty",children:d(E?"mdblock.menu.noMatch":"mdblock.category.empty")}),b.jsx("div",{className:"slash-scroll",id:`${g}-commands`,role:"menu","aria-labelledby":`${g}-tab-${I}`,children:E||B.length<=1?U.map(Ee):B.map(N=>b.jsxs("div",{className:"slash-group",children:[b.jsx("div",{className:"slash-group-label",children:N.name}),N.rows.map(({it:J,idx:K})=>Ee(J,K))]},N.name))})]}),b.jsxs("div",{className:"slash-foot",children:[b.jsx("span",{children:d("mdblock.foot.category")}),U.length>0&&b.jsx("span",{children:d("mdblock.foot.select")}),U.length>0&&b.jsx("span",{children:d("mdblock.foot.insert")}),b.jsx("span",{children:d("mdblock.foot.close")})]})]})]})}function Vd({onPick:e,onClose:t}){const{t:n}=hn(),[r,o]=A.useState(""),[s,a]=A.useState(0),l=Pn(p=>p.files);A.useEffect(()=>{Pn.getState().refreshStructure()},[]);const i=l.filter(p=>/\.db$/i.test(p)),c=p=>p.replace(/\\/g,"/").split("/").pop()??p,u=new Map;for(const p of i){const h=c(p).toLowerCase();u.set(h,(u.get(h)??0)+1)}const d=r.trim().toLowerCase(),f=d?i.map(p=>{const h=Ze(d,c(p));return{f:p,s:h!==null?h+1e3:Ze(d,p)}}).filter(p=>p.s!==null).sort((p,h)=>h.s-p.s).map(p=>p.f):i,m=p=>(u.get(c(p).toLowerCase())??0)>1?p.replace(/\\/g,"/"):c(p);return A.useEffect(()=>{a(0)},[r]),A.useEffect(()=>{const p=g=>{g.preventDefault(),g.stopPropagation()},h=g=>{if(g.key==="Escape")p(g),t();else if(g.key==="ArrowDown")p(g),a(y=>Math.min(y+1,f.length-1));else if(g.key==="ArrowUp")p(g),a(y=>Math.max(y-1,0));else if(g.key==="Enter"){p(g);const y=f[s];y?e(m(y)):t()}else g.key==="Backspace"?(p(g),o(y=>y.slice(0,-1))):g.key.length===1&&!g.metaKey&&!g.ctrlKey&&!g.altKey&&(p(g),o(y=>y+g.key))};return window.addEventListener("keydown",h,!0),()=>window.removeEventListener("keydown",h,!0)},[f,s,e,t]),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:t}),b.jsxs("div",{className:"slash-menu",role:"menu",children:[r&&b.jsx("div",{className:"slash-query",children:r}),i.length===0&&b.jsx("div",{className:"slash-empty",children:n("mdblock.menu.noDatabase")}),i.length>0&&f.length===0&&b.jsx("div",{className:"slash-empty",children:n("mdblock.menu.noMatch")}),b.jsx("div",{className:"slash-scroll",children:f.map((p,h)=>b.jsxs("button",{className:"slash-item","data-active":h===s||void 0,onMouseEnter:()=>a(h),onClick:()=>e(m(p)),role:"menuitem",children:[b.jsx("span",{className:"slash-icon","aria-hidden":!0,children:b.jsx(vr,{})}),b.jsx("span",{className:"slash-label",children:c(p).replace(/\.db$/i,"")}),b.jsx("span",{className:"slash-hint",children:p.replace(/\\/g,"/").split("/").slice(0,-1).join("/")||"/"})]},p))}),f.length>0&&b.jsxs("div",{className:"slash-foot",children:[b.jsx("span",{children:n("mdblock.foot.select")}),b.jsx("span",{children:n("mdblock.foot.embed")}),b.jsx("span",{children:n("mdblock.foot.close")})]})]})]})}Zp({id:"markdown",fileExtensions:[".md"],Editor:jd});const sx=Object.freeze(Object.defineProperty({__proto__:null,DbLinkPicker:Vd,MarkdownBlock:jd,MilkdownInner:Wa,PREFIX_TRIGGERS:Hd,PlainMarkdownEditor:m1,SLASH_ITEMS:Fd,SLASH_SENTINELS:g1,getFocusedBlockApply:y1,hostLabel:Pr,linkExtent:Wd,normalizeFragmentMd:_d,normalizeSerializedMd:un,serializeUnified:Dd,setFocusedBlockApply:k1,slashTurnFailed:Ud,stampedFileName:$d,textOf:wr,useAllSlashItems:qd},Symbol.toStringTag,{value:"Module"}));export{xi as $,Lk as A,Ek as B,$k as C,Dy as D,ex as E,cn as F,_y as G,Z1 as H,Y1 as I,U1 as J,G1 as K,Jl as L,V1 as M,Hu as N,Fu as O,m1 as P,Et as Q,i0 as R,rx as S,F1 as T,Nm as U,Tm as V,q1 as W,W1 as X,B1 as Y,z1 as Z,Ju as _,_1 as a,X1 as a0,Q1 as a1,vk as a2,Dd as a3,un as a4,O1 as a5,gr as a6,md as a7,c0 as a8,Wa as a9,Vd as aa,Hd as ab,Ud as ac,g1 as ad,ox as ae,E0 as af,$d as ag,k1 as ah,nx as ai,J1 as aj,sx as ak,D1 as b,dd as c,l0 as d,qd as e,tx as f,y1 as g,wi as h,fd as i,Yt as j,Yo as k,kd as l,j1 as m,K1 as n,Fr as o,N0 as p,P1 as q,Zi as r,L1 as s,H1 as t,$1 as u,Xo as v,zm as w,_k as x,mn as y,Oe as z};
|