@forsion/unit 2.13.0 → 2.13.1

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.
Files changed (144) hide show
  1. package/main.mjs +5 -3
  2. package/package.json +1 -1
  3. package/release.json +5 -5
  4. package/web/assets/{ArtificialView-BSv3Mx5C.js → ArtificialView-XwHMLUFb.js} +1 -1
  5. package/web/assets/{AutomationBuilder-BuiHtVB-.js → AutomationBuilder-hqs0QhMt.js} +1 -1
  6. package/web/assets/{CalendarConfigView-BJtG6cqN.js → CalendarConfigView-DKib8Oed.js} +1 -1
  7. package/web/assets/{CalendarView-C-FX1RED.js → CalendarView-DJ5iOzvu.js} +1 -1
  8. package/web/assets/{CapabilityMenu-kx1TIJYN.js → CapabilityMenu-SwVlZ06x.js} +1 -1
  9. package/web/assets/{CheckboxInput-eW7xdiRS.js → CheckboxInput-BC-5a_C9.js} +1 -1
  10. package/web/assets/{Chrome-B77-lQyh.js → Chrome-HdfyYV3i.js} +1 -1
  11. package/web/assets/{CodeView-Df3AiSIi.js → CodeView-CFL6yQ-6.js} +3 -3
  12. package/web/assets/{DashboardGridView-MlO1dpuo.js → DashboardGridView-B9DCWYVb.js} +12 -12
  13. package/web/assets/{EventCard-CDmeCbI8.js → EventCard-B_ndpqH_.js} +1 -1
  14. package/web/assets/{ExcalidrawCanvas-D9vkBh_5.js → ExcalidrawCanvas-BQ4KKLJP.js} +1 -1
  15. package/web/assets/{FloatingToc-tART_jC4.js → FloatingToc-Ce9GamvH.js} +1 -1
  16. package/web/assets/{HomepageView-Trqmd3RV.js → HomepageView-RCOfcVbE.js} +1 -1
  17. package/web/assets/{ImageStudioPanels-BfCVTnKC.js → ImageStudioPanels-lkS_y2uM.js} +2 -2
  18. package/web/assets/{ImageStudioView-KJhx0wJk.js → ImageStudioView-UPv52acl.js} +1 -1
  19. package/web/assets/{InlineFiles-BHwivGbQ.js → InlineFiles-CQbQumkf.js} +1 -1
  20. package/web/assets/{MarkdownBlock-D8LgHFYY.js → MarkdownBlock-CkqiwPXa.js} +19 -19
  21. package/web/assets/{ModelPill-DrW2cG0l.js → ModelPill-CY-rU1RU.js} +2 -2
  22. package/web/assets/{MuseLibraryView-CW78Uivf.js → MuseLibraryView-CtTHlVnT.js} +2 -2
  23. package/web/assets/{MuseView-Cb6R_l4i.js → MuseView-CC2A7MBs.js} +2 -2
  24. package/web/assets/{PageHistoryPanel-BQs9IWTP.js → PageHistoryPanel-KhKT1DLy.js} +2 -2
  25. package/web/assets/{PdfAnnotator-BFTBkxvO.js → PdfAnnotator-DUyrgY-t.js} +1 -1
  26. package/web/assets/{ProductView-mB-S0j81.js → ProductView-CgsIYZqD.js} +1 -1
  27. package/web/assets/{RightPanel-BVZeVO3c.js → RightPanel-BHDgqTFs.js} +3 -3
  28. package/web/assets/RunLocationPicker-DBnXYV5B.js +38 -0
  29. package/web/assets/{SidebarRow-D77yrSLf.js → SidebarRow-BAJxbMcx.js} +1 -1
  30. package/web/assets/{SketchCard-CAAr_cqF.js → SketchCard-BGYz-bXP.js} +1 -1
  31. package/web/assets/{StudioGuestSurface-DthpuVGg.js → StudioGuestSurface-lt6znmkl.js} +1 -1
  32. package/web/assets/{TodoListView-C3ZkMIIf.js → TodoListView-DPKhee6i.js} +1 -1
  33. package/web/assets/{Tooltip-D9Dt9ZTr.js → Tooltip-ZxrDqN4p.js} +1 -1
  34. package/web/assets/{UnifiedPage-C75y-MKT.js → UnifiedPage-BX6ZQL0h.js} +27 -27
  35. package/web/assets/{amadeus-manual.en-D5wZKuag.js → amadeus-manual.en-DzRWr4BL.js} +15 -15
  36. package/web/assets/{amadeus-manual.zh-Br5fidrj.js → amadeus-manual.zh-DW32DkL7.js} +15 -15
  37. package/web/assets/{appStore-B1ynyt42.js → appStore-DWP8UET9.js} +99 -79
  38. package/web/assets/appStore-wtOILggO.css +1 -0
  39. package/web/assets/{arrow-up-right-R10mR2I6.js → arrow-up-right-DrCXuWS7.js} +1 -1
  40. package/web/assets/{astryxBridge-CU_kQTEl.js → astryxBridge-D-m4_kYt.js} +3 -3
  41. package/web/assets/{automationListSource-B8EIRmDW.js → automationListSource-C8BNy6RY.js} +1 -1
  42. package/web/assets/{book-open-DBJ3dDpw.js → book-open-OLNm7OaB.js} +1 -1
  43. package/web/assets/{calendarNavStore-DGvUlU5N.js → calendarNavStore-Cylfvv3s.js} +1 -1
  44. package/web/assets/{canvasPrefs-DwL_OAAo.js → canvasPrefs-8taQ42Cz.js} +1 -1
  45. package/web/assets/{chatBoxSurface-Lq-2qfd3.js → chatBoxSurface-CIlzs45H.js} +1 -1
  46. package/web/assets/{circle-question-mark-HPZpZQxd.js → circle-question-mark-XbAFplz1.js} +1 -1
  47. package/web/assets/{circle-x-BZfe7d6S.js → circle-x-fcReAZaE.js} +1 -1
  48. package/web/assets/{client-DxGbwZLy.js → client-0MPbodA6.js} +1 -1
  49. package/web/assets/{code-xml-joKQ-qGS.js → code-xml-Cuna8Kh4.js} +1 -1
  50. package/web/assets/{codeStudioStore-C7rGKlOC.js → codeStudioStore-BBU62GTy.js} +1 -1
  51. package/web/assets/{codingNavigation-CjeWG4xm.js → codingNavigation-DDlPpPk5.js} +7 -7
  52. package/web/assets/{create-BjBRKATq.js → create-BGtEfCcg.js} +2 -2
  53. package/web/assets/{dashboardSurface-Cojgf_-U.js → dashboardSurface-BYM3C7WG.js} +1 -1
  54. package/web/assets/{deskCapture-DnGWk1iq.js → deskCapture-BiUCmqfc.js} +1 -1
  55. package/web/assets/{diff2html-Cd1rVi_Z.js → diff2html-BNp2FTbk.js} +1 -1
  56. package/web/assets/{docx-preview-CK0k1mUD.js → docx-preview-CFznGVOU.js} +1 -1
  57. package/web/assets/{emoji-Cjm3bKiF.js → emoji-6zl4yfOS.js} +1 -1
  58. package/web/assets/{floatingTocSurface-Dd1pT5j5.js → floatingTocSurface-DreXPCa6.js} +1 -1
  59. package/web/assets/{foldActions-Dm-uAt3L.js → foldActions-05QcQziQ.js} +1 -1
  60. package/web/assets/{folder-CvZyHIgb.js → folder-BpsfOHD4.js} +1 -1
  61. package/web/assets/{folder-plus-BRScGQ9m.js → folder-plus-BeQHr4AZ.js} +1 -1
  62. package/web/assets/{gestures-CZQVefU0.js → gestures-DQBCcK4y.js} +1 -1
  63. package/web/assets/{hand-D3QspKYq.js → hand-Bko7ms15.js} +1 -1
  64. package/web/assets/{hard-drive-BQsHSala.js → hard-drive-BpuI5ebj.js} +1 -1
  65. package/web/assets/{i18n.generated-BZRHO2Nc.js → i18n.generated-BuLjnmY8.js} +1 -1
  66. package/web/assets/{imageStudio-Cy3_437s.js → imageStudio-BLVNKmEG.js} +2 -2
  67. package/web/assets/{index-BPhwi4-v.js → index-BF10xp_K.js} +1 -1
  68. package/web/assets/{index-GjLSlygt.js → index-BHm6K743.js} +1 -1
  69. package/web/assets/{index-Bh_nLVTc.js → index-BM2o7PeV.js} +5 -5
  70. package/web/assets/{index-BcVGjCAJ.js → index-BgnNNv3e.js} +1 -1
  71. package/web/assets/{index-CcOag8eb.js → index-C0Gy2NQ6.js} +1 -1
  72. package/web/assets/{index-0AYHATDX.js → index-C1doZp5H.js} +1 -1
  73. package/web/assets/{index-9BmmlTjY.js → index-C4L6vjd_.js} +1 -1
  74. package/web/assets/{index-8ag1K7AZ.js → index-CD3yIkOA.js} +1 -1
  75. package/web/assets/{index-Dkd-nl1u.js → index-CJeUgjPU.js} +1 -1
  76. package/web/assets/{index-B5GxvbNm.js → index-CLHoq1w-.js} +1 -1
  77. package/web/assets/{index-DElrDw66.js → index-CUZI62qU.js} +1 -1
  78. package/web/assets/{index-BgtO11q8.js → index-Cff42k7q.js} +1 -1
  79. package/web/assets/{index-Dj-PygjB.js → index-Ck_O3Jdd.js} +1 -1
  80. package/web/assets/index-CuiYK18N.js +1 -0
  81. package/web/assets/{index-Bpc3R3DS.js → index-CwcOeZdT.js} +1 -1
  82. package/web/assets/{index-DJLWTPtq.js → index-D6AycQIz.js} +1 -1
  83. package/web/assets/{index-C9yo04Ck.js → index-D7gVhvNY.js} +1 -1
  84. package/web/assets/{index-BnWj6ggb.js → index-D9UZQy42.js} +1 -1
  85. package/web/assets/{index-D6mpAJ9S.js → index-DuBQ0j2g.js} +1 -1
  86. package/web/assets/{index-1FhRiJ_X.js → index-OD1gSX3h.js} +1 -1
  87. package/web/assets/{index-DNE_PBJt.js → index-Uo5tswys.js} +1 -1
  88. package/web/assets/{index-BgDZGDqt.js → index-o8cj0pRH.js} +1 -1
  89. package/web/assets/{index-BdZaheMZ.js → index-rHjhbwvm.js} +1 -1
  90. package/web/assets/{index-4E9nrhwf.js → index-rggq2czF.js} +1 -1
  91. package/web/assets/{index-D0FLFLfh.js → index-sCXThwqZ.js} +1 -1
  92. package/web/assets/{invitePage-B4gMvEKi.js → invitePage-b0HGvMj6.js} +1 -1
  93. package/web/assets/{ipc-CPhL3bPp.js → ipc-CxAyeo8q.js} +1 -1
  94. package/web/assets/{jszip.min-DAJT9RUA.js → jszip.min-B94KpE21.js} +1 -1
  95. package/web/assets/{layout-grid-DfUfnvDS.js → layout-grid-BBVuEdWG.js} +1 -1
  96. package/web/assets/{linkFollow-C6PHGUxk.js → linkFollow-B7ivDZMM.js} +5 -5
  97. package/web/assets/{list-tree-DaGpnIYu.js → list-tree-4-0QDbLu.js} +1 -1
  98. package/web/assets/{listFold-Q_8mh5ZG.js → listFold-DLuxXiIj.js} +1 -1
  99. package/web/assets/{lock-DQ_yL4nF.js → lock-CnbZm4vo.js} +1 -1
  100. package/web/assets/{log-out-DFwTeh2X.js → log-out-BEynWaHa.js} +1 -1
  101. package/web/assets/{main-NgUPPqDn.css → main-BiS_5wrB.css} +1 -1
  102. package/web/assets/main-sIq2N9Z5.js +20 -0
  103. package/web/assets/{markdownEditorSurface-e_oMhqx-.js → markdownEditorSurface-ZSJ3RHAv.js} +1 -1
  104. package/web/assets/{mdMarkStore-DjN4bf1T.js → mdMarkStore-DQHDjG7s.js} +2 -2
  105. package/web/assets/{mdMarks-cmL6vzR-.js → mdMarks-DbIcRa0O.js} +1 -1
  106. package/web/assets/{message-square-plus-CEHkduIL.js → message-square-plus-CpiKDvle.js} +1 -1
  107. package/web/assets/{messages-CBtmbpur.js → messages-_jta1lSI.js} +1 -1
  108. package/web/assets/minus-C9ndHJ9O.js +1 -0
  109. package/web/assets/{mobileEntry-qR7BAROr.js → mobileEntry-CPmU_c4m.js} +1 -1
  110. package/web/assets/{nativeDownload-CziEyW_p.js → nativeDownload-BYT082bY.js} +1 -1
  111. package/web/assets/{pageChrome-DFz_AAzZ.js → pageChrome-D3Niv1JM.js} +1 -1
  112. package/web/assets/{pageTree-yVO1_fSy.js → pageTree-CgfvpzIj.js} +1 -1
  113. package/web/assets/{pen-tool-uxsFELYC.js → pen-tool-BXEFnU2i.js} +1 -1
  114. package/web/assets/{pencil-BSbra1Ra.js → pencil-cqvCkekG.js} +1 -1
  115. package/web/assets/pluginChat-BbBukMuN.js +2 -0
  116. package/web/assets/{redo-2-BK5LMNa5.js → redo-2-BO7wCDwy.js} +1 -1
  117. package/web/assets/{rotate-ccw-HedfU4na.js → rotate-ccw-BvipPIjC.js} +1 -1
  118. package/web/assets/{sharePage-CpzDpuU1.js → sharePage-XbN50US7.js} +2 -2
  119. package/web/assets/{shareViewer-BwzH2bIs.js → shareViewer-BaYogetW.js} +1 -1
  120. package/web/assets/{star-CgYon3z4.js → star-BQWMXnn7.js} +1 -1
  121. package/web/assets/tableSurface-BXqqidd1.js +1 -0
  122. package/web/assets/{terminal-krsPf1mc.js → terminal-l9k6RDrH.js} +1 -1
  123. package/web/assets/{terminalView-4e2_u5_I.js → terminalView-Cpnt5_0P.js} +1 -1
  124. package/web/assets/{type-GJYLEhY-.js → type-CFoaj2eD.js} +1 -1
  125. package/web/assets/{undo-2-DCTs4Ro4.js → undo-2-DusxpdLa.js} +1 -1
  126. package/web/assets/{unitAccount-D3xjX3cu.js → unitAccount-DwutFPPw.js} +1 -1
  127. package/web/assets/{unitBridge-D5JcIkAP.js → unitBridge-CcgQpkqV.js} +1 -1
  128. package/web/assets/{unitCloudTransport-B44L3x6M.js → unitCloudTransport-vA7cLDts.js} +1 -1
  129. package/web/assets/{unitOwnerAccess-CRUHWGpf.js → unitOwnerAccess-LBlJ1YfA.js} +1 -1
  130. package/web/assets/{unitShim-_VzxvdEG.js → unitShim-B_M9IrbC.js} +3 -3
  131. package/web/assets/{upload-MVVRQtkj.js → upload-ZrOj6tXA.js} +1 -1
  132. package/web/assets/{userSpaces-CI4eqEgh.js → userSpaces-uJOnsedR.js} +1 -1
  133. package/web/assets/viewportLock-D3SNkwS2.js +631 -0
  134. package/web/assets/{workflow-DzeW9OXR.js → workflow-DPoG4QE2.js} +1 -1
  135. package/web/assets/{zoom-in-CovPsw4g.js → zoom-in-lbTgzdQP.js} +1 -1
  136. package/web/index.html +27 -7
  137. package/web/assets/RunLocationPicker-CyVa0RJa.js +0 -38
  138. package/web/assets/appStore-BC_CQv-L.css +0 -1
  139. package/web/assets/index-BaRySZ-M.js +0 -1
  140. package/web/assets/main-CwqZ_ymb.js +0 -19
  141. package/web/assets/minus-BUT48dAC.js +0 -1
  142. package/web/assets/pluginChat-BMFnf_j2.js +0 -2
  143. package/web/assets/tableSurface-CmDwnKnd.js +0 -1
  144. package/web/assets/viewportLock-BH26xHQO.js +0 -611
@@ -1,6 +1,6 @@
1
- import{d as E,r as De,be as zn,bq as Xa,bp as nf,W as Xo,c3 as Zt,c4 as Qo,c5 as Si,t as O,c6 as Mi,Q as Ai,U as Ni,R as Ei,bW as Zo,q as Ti,u as rn,j as b,bQ as $r,c7 as Ii,c8 as Li,m as yo,n as Ri,am as rf,ar as of,B as es,c9 as Qa,J as sf,ca as ko,cb as Za,cc as af,cd as lf,bS as cf,bZ as uf,b_ as el,b$ as df,aw as ff,ax as pf,c1 as mf,aO as hf,bM as gf}from"./index-Bh_nLVTc.js";import{F as $i,mL as fe,my as Z,mS as J,mR as me,mB as j,mN as X,n4 as Ie,oi as ts,oj as bf,mI as ns,mK as ar,mC as ce,ok as yf,ol as Ft,om as On,on as ot,nM as le,oo as Di,op as _i,m$ as se,oq as Nn,or as rs,os as kf,ot as st,ou as wf,ov as xf,mJ as wo,ow as vf,ox as os,oy as zi,oz as Ye,n1 as Cf,oA as Sf,mM as Ve,no as Mf,oB as Af,oC as Oi,oD as Nf,oE as Pn,mr as Ef,ms as Tf,nN as en,oF as If,oG as Lf,oH as Pi,nL as hr,oI as Rf,oJ as Bi,oK as Ki,oL as $f,oM as Df,oN as _f,oO as zf,oP as Of,oQ as Pf,oR as Bf,oS as Kf,mT as jf,oT as Hf,ah as on,eC as Ff,oU as ft,oV as qf,jf as Wf,oW as Uf,b as En,dk as Oe,l4 as Fe,G as ji,oX as gr,oY as Vf,mv as Gf,oZ as Jf,cp as Yf,o_ as Xf,o$ as Qf,mO as Zf,p0 as ep,p1 as tp,p2 as np,fp as Hi,nb as Fi,p3 as rp,cU as op,p4 as sp,hu as ap,p5 as lp,fJ as xo,p6 as to,K as ip,aI as cp,jL as up,p7 as dp,p8 as fp,p9 as pp,pa as mp,pb as hp,pc as gp,pd as bp,pe as yp,jJ as kp,jA as wp,pf as xp,pg as vp,ph as Cp,pi as Sp,pj as Mp,pk as Ap,pl as Np,pm as Ep,pn as Tp,po as Ip,pp as Lp,pq as Rp,pr as $p,ps as Dp,pt as _p,pu as zp,f7 as Op,nO as Pp,fc as er,nP as no,pv as Bp,pw as Kp,px as jp,py as tl,mA as nl,pz as Hp,pA as qi,pB as Fp,pC as qp,pD as Wp}from"./appStore-B1ynyt42.js";import{$ as Q,c as F,d as at,e as Bn,f as _e,g as ss,a as ve,h as Xe,b as Ee,i as as,j as ue,k as Up}from"./index-BaRySZ-M.js";import{s as Wi,b as Dr,L as rl,m as Vp,d as Gp,a as Jp,u as Ui,e as Yp,w as Xp,l as Qp,f as Zp,g as em,I as ol}from"./linkFollow-C6PHGUxk.js";import{A as tm}from"./mdMarks-cmL6vzR-.js";import"./client-DxGbwZLy.js";import{s as nm}from"./emoji-Cjm3bKiF.js";import{b as rm,t as om,m as sm,g as am}from"./listFold-Q_8mh5ZG.js";import{B as lm}from"./book-open-DBJ3dDpw.js";const im=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],cm=$i("text-align-center",im);const um=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],dm=$i("text-align-end",um);De({"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 ls="amadeus.notes.spellcheck",vo="amadeus:notes-spellcheck";function Vi(){try{return localStorage.getItem(ls)!=="0"}catch{return!0}}function t1(e){try{localStorage.setItem(ls,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(vo))}catch{}}function Gi(e){const t=n=>{(!n.key||n.key===ls)&&e()};return window.addEventListener(vo,e),window.addEventListener("storage",t),()=>{window.removeEventListener(vo,e),window.removeEventListener("storage",t)}}function n1(){return E.useSyncExternalStore(Gi,Vi,()=>!0)}const sl={spellcheck:"false"};function al(e){const t=[];return e.descendants((n,r)=>{if(!n.isTextblock)return!0;if(n.type.spec.code)return!1;const o=r+1;if(n.forEach((s,a)=>{s.isText&&s.marks.some(l=>l.type.spec.code||l.type.name==="inlineCode")&&t.push(J.inline(o+a,o+a+s.nodeSize,sl))}),n.textContent.includes("$"))for(const s of Wi(Dr(n)))t.push(J.inline(o+s.from,o+s.to,sl));return!1}),t.length?me.create(e,t):me.empty}const ll=new fe("amadeus-spellcheck"),fm=Q(()=>new Z({key:ll,state:{init:(e,t)=>al(t.doc),apply:(e,t)=>e.docChanged?al(e.doc):t},props:{decorations:e=>ll.getState(e),attributes:()=>({spellcheck:Vi()?"true":"false"})},view:e=>({destroy:Gi(()=>e.updateState(e.state))})}));De({"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 is="amadeus.notes.codeAutoPair",Co="amadeus:notes-code-autopair";function Ji(){try{return localStorage.getItem(is)!=="0"}catch{return!0}}function r1(e){try{localStorage.setItem(is,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(Co))}catch{}}function pm(e){const t=n=>{(!n.key||n.key===is)&&e()};return window.addEventListener(Co,e),window.addEventListener("storage",t),()=>{window.removeEventListener(Co,e),window.removeEventListener("storage",t)}}function o1(){return E.useSyncExternalStore(pm,Ji,()=>!0)}const br={"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"},mm=new Set(Object.values(br)),il=/[\p{L}\p{N}_]/u;function Yi(e,t,n){if(t!==n||!Ji())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 hm(e,t,n,r){const o=Yi(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(mm.has(r)&&s===r)return e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,t+1))),!0;const l=br[r];if(!l||il.test(s)||l===r&&il.test(a))return!1;const i=e.state.tr.insertText(r+l,t,n);return i.setSelection(j.create(i.doc,t+1)),e.dispatch(i),!0}function gm(e){const{from:t,to:n}=e.state.selection,r=Yi(e,t,n);if(!r||r.off===0)return!1;const o=r.text.charAt(r.off-1);return!br[o]||r.text.charAt(r.off)!==br[o]?!1:(e.dispatch(e.state.tr.delete(t-1,t+1)),!0)}function bm(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=X.empty,f=o.index(-1)?1:o.index(-2)?2:3;for(let w=o.depth-f;w>=o.depth-3;w--)d=X.from(o.node(w).copy(d));let m=o.indexAfter(-1)<o.node(-2).childCount?1:o.indexAfter(-2)<o.node(-3).childCount?2:3;d=d.append(X.from(e.createAndFill()));let p=o.before(o.depth-(f-1)),h=n.tr.replace(p,o.after(-m),new Ie(d,4-f,0)),g=-1;h.doc.nodesBetween(p,h.doc.content.size,(w,y)=>{if(g>-1)return!1;w.isTextblock&&w.content.size==0&&(g=y+1)}),g>-1&&h.setSelection(ce.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 yf(c.doc,o.pos,2,u)?(r&&r(c.split(o.pos,2,u).scrollIntoView()),!0):!1}}function Xi(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?ym(t,n,e,s):km(t,n,s):!0:!1}}function ym(e,t,n,r){let o=e.tr,s=r.end,a=r.$to.end(r.depth);s<a&&(o.step(new ts(s-1,a,s,a,new Ie(X.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new bf(o.doc.resolve(r.$from.pos),o.doc.resolve(a),r.depth));const l=ns(r);if(l==null)return!1;o.lift(r,l);let i=o.doc.resolve(o.mapping.map(s,-1)-1);return ar(o.doc,i.pos)&&i.nodeBefore.type==i.nodeAfter.type&&o.join(i.pos),t(o.scrollIntoView()),!0}function km(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?X.empty:X.from(o))))return!1;let d=s.pos,f=d+a.nodeSize;return r.step(new ts(d-(l?1:0),f+(i?1:0),d+1,f-1,new Ie((l?X.empty:X.from(o.copy(X.empty))).append(i?X.empty:X.from(o.copy(X.empty))),l?0:1,i?0:1),l?0:1)),t(r.scrollIntoView()),!0}function Qi(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=X.from(c?e.create():null),d=new Ie(X.from(e.create(null,X.from(l.type.create(null,u)))),c?3:1,0),f=s.start,m=s.end;n(t.tr.step(new ts(f-(c?3:1),m,f,m,d,1,!0)).scrollIntoView())}return!0}}function wm(e){const t=new Map;if(!e||!e.type)throw new Error("mdast-util-definitions expected node");return zn(e,"definition",function(r){const o=cl(r.identifier);o&&!t.get(o)&&t.set(o,r)}),n;function n(r){const o=cl(r);return t.get(o)}}function cl(e){return String(e||"").toUpperCase()}function xm(){return function(e){const t=wm(e);zn(e,function(n,r,o){if(n.type==="definition"&&o!==void 0&&typeof r=="number")return o.children.splice(r,1),[Xa,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},[Xa,r]}})}}function Zi(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(X.fromArray(n))}function v(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-commonmark",...t}}),e}var cs=Bn("emphasis");v(cs,{displayName:"Attr<emphasis>",group:"Emphasis"});var Et=at("emphasis",e=>({attrs:{marker:{default:e.get(Ft).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:t=>t==="italic"}],toDOM:t=>["em",e.get(cs.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(Et.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});v(Et.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var _r=F("ToggleEmphasis",e=>()=>On(Et.type(e)));v(_r,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var us=ue(e=>st(/(?:^|[^*])\*([^*]+)\*$/,Et.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}));v(us,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var ds=ue(e=>st(/\b_(?![_\s])(.*?[^_\s])_\b/,Et.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}));v(ds,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var fs=_e("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:e=>{const t=e.get(se);return()=>t.call(_r.key)}}});v(fs.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});v(fs.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var ps=Bn("strong");v(ps,{displayName:"Attr<strong>",group:"Strong"});var sn=at("strong",e=>({attrs:{marker:{default:e.get(Ft).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(ps.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(sn.mark,{displayName:"MarkSchema<strong>",group:"Strong"});v(sn.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var zr=F("ToggleStrong",e=>()=>On(sn.type(e)));v(zr,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var ms=ue(e=>st(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),sn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}));v(ms,{displayName:"InputRule<strong>",group:"Strong"});var hs=_e("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:e=>{const t=e.get(se);return()=>t.call(zr.key)}}});v(hs.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});v(hs.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var gs=Bn("inlineCode");v(gs,{displayName:"Attr<inlineCode>",group:"InlineCode"});var dt=at("inlineCode",e=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:t=>["code",e.get(gs.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(dt.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});v(dt.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Or=F("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,dt.type(e))?(n?.(o.removeMark(s,a,dt.type(e))),!0):(Object.keys(t.schema.marks).filter(l=>l!==dt.type.name).map(l=>t.schema.marks[l]).forEach(l=>{o.removeMark(s,a,l)}),n?.(o.addMark(s,a,dt.type(e).create())),!0)});v(Or,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var bs=ue(e=>st(/(?:`)([^`]+)(?:`)$/,dt.type(e)));v(bs,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var ys=_e("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:e=>{const t=e.get(se);return()=>t.call(Or.key)}}});v(ys.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});v(ys.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var Pr=Bn("link");v(Pr,{displayName:"Attr<link>",group:"Link"});var Ge=at("link",e=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:t=>{if(!(t instanceof HTMLElement))throw ot(t);return{href:t.getAttribute("href"),title:t.getAttribute("title")}}}],toDOM:t=>["a",{...e.get(Pr.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(Ge.mark,{displayName:"MarkSchema<link>",group:"Link"});var ec=F("ToggleLink",e=>(t={})=>On(Ge.type(e),t));v(ec,{displayName:"Command<toggleLinkCommand>",group:"Link"});var tc=F("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(Ge.type(e).isInSet(p.marks))return o=p,s=h,!1}),!o)return!1;const c=o.marks.find(({type:p})=>p===Ge.type(e));if(!c)return!1;const u=s,d=s+o.nodeSize,{tr:f}=n,m=Ge.type(e).create({...c.attrs,...t});return m?(r(f.removeMark(u,d,c).addMark(u,d,m).setSelection(new j(f.selection.$anchor)).scrollIntoView()),!0):!1});v(tc,{displayName:"Command<updateLinkCommand>",group:"Link"});var ks=ss("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(ks,{displayName:"NodeSchema<doc>",group:"Doc"});function vm(e){return nf(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 Br=ve("remark-preserve-empty-line",()=>()=>vm);v(Br.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});v(Br.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Kr=Xe("paragraph");v(Kr,{displayName:"Attr<paragraph>",group:"Paragraph"});var Be=Ee("paragraph",e=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:t=>["p",e.get(Kr.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(le).state?.doc.lastChild;t.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&Cm(e)?t.addNode("html",void 0,"<br />"):Zi(t,n),t.closeNode()}}}));function Cm(e){let t=!1;try{e.get(Br.id),t=!0}catch{t=!1}return t}v(Be.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});v(Be.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var ws=F("TurnIntoText",e=>()=>Nn(Be.type(e)));v(ws,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var xs=_e("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:e=>{const t=e.get(se);return()=>t.call(ws.key)}}});v(xs.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});v(xs.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var Sm=Array(6).fill(0).map((e,t)=>t+1);function Mm(e){return e.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Kn=as(Mm,"headingIdGenerator");v(Kn,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var jr=Xe("heading");v(jr,{displayName:"Attr<heading>",group:"Heading"});var rt=Ee("heading",e=>{const t=e.get(Kn.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Sm.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw ot(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...e.get(jr.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}),Zi(n,r),n.closeNode()}}}});v(rt.node,{displayName:"NodeSchema<heading>",group:"Heading"});v(rt.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var nc=ue(e=>zi(/^(?<hashes>#+)\s$/,rt.type(e),t=>{const n=t.groups?.hashes?.length||0,{$from:r}=e.get(le).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(nc,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var kt=F("WrapInHeading",e=>t=>(t??=1,t<1?Nn(Be.type(e)):Nn(rt.type(e),{level:t})));v(kt,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var vs=F("DowngradeHeading",e=>()=>(t,n,r)=>{const{$from:o}=t.selection,s=o.node();if(s.type!==rt.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):Nn(Be.type(e))(t,n,r)});v(vs,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Cs=_e("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:e=>{const t=e.get(se);return()=>t.call(kt.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:e=>{const t=e.get(se);return()=>t.call(kt.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:e=>{const t=e.get(se);return()=>t.call(kt.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:e=>{const t=e.get(se);return()=>t.call(kt.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:e=>{const t=e.get(se);return()=>t.call(kt.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:e=>{const t=e.get(se);return()=>t.call(kt.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:e=>{const t=e.get(se);return()=>t.call(vs.key)}}});v(Cs.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});v(Cs.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Hr=Xe("blockquote");v(Hr,{displayName:"Attr<blockquote>",group:"Blockquote"});var At=Ee("blockquote",e=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:t=>["blockquote",e.get(Hr.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(At.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});v(At.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var rc=ue(e=>os(/^\s*>\s$/,At.type(e)));v(rc,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Ss=F("WrapInBlockquote",e=>()=>rs(At.type(e)));v(Ss,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Ms=_e("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:e=>{const t=e.get(se);return()=>t.call(Ss.key)}}});v(Ms.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});v(Ms.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var As=Xe("codeBlock",()=>({pre:{},code:{}}));v(As,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var jn=Ee("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 ot(t);return{language:t.dataset.language}}}],toDOM:t=>{const n=e.get(As.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 oc=ue(e=>zi(/^```(?<language>[a-z]*)?[\s\n]$/,jn.type(e),t=>({language:t.groups?.language??""})));v(oc,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Ns=F("CreateCodeBlock",e=>(t="")=>Nn(jn.type(e),{language:t}));v(Ns,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var Am=F("UpdateCodeBlockLanguage",()=>({pos:e,language:t}={pos:-1,language:""})=>(n,r)=>e>=0?(r?.(n.tr.setNodeAttribute(e,"language",t)),!0):!1);v(Am,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Es=_e("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:e=>{const t=e.get(se);return()=>t.call(Ns.key)}}});v(Es.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});v(Es.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Ts=Xe("image");v(Ts,{displayName:"Attr<image>",group:"Image"});var an=Ee("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 ot(t);return{src:t.getAttribute("src")||"",alt:t.getAttribute("alt")||"",title:t.getAttribute("title")||t.getAttribute("alt")||""}}}],toDOM:t=>["img",{...e.get(Ts.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(an.node,{displayName:"NodeSchema<image>",group:"Image"});v(an.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var sc=F("InsertImage",e=>(t={})=>(n,r)=>{if(!r)return!0;const{src:o="",alt:s="",title:a=""}=t,l=an.type(e).create({src:o,alt:s,title:a});return l&&r(n.tr.replaceSelectionWith(l).scrollIntoView()),!0});v(sc,{displayName:"Command<insertImageCommand>",group:"Image"});var ac=F("UpdateImage",e=>(t={})=>(n,r)=>{const o=wf(n.selection,an.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(ac,{displayName:"Command<updateImageCommand>",group:"Image"});var Nm=ue(e=>new Ye(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(t,n,r,o)=>{const[s,a,l="",i]=n;return s?t.tr.replaceWith(r,o,an.type(e).create({src:l,alt:a,title:i})):null}));v(Nm,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var yr=Xe("hardbreak",e=>({"data-type":"hardbreak","data-is-inline":e.attrs.isInline}));v(yr,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Je=Ee("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(yr.key)(t)," "]:["br",e.get(yr.key)(t)],parseMarkdown:{match:({type:t})=>t==="break",runner:(t,n,r)=>{t.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>`
1
+ import{d as E,r as De,be as zn,bq as Xa,bp as nf,W as Xo,c3 as Zt,c4 as Qo,c5 as Si,t as O,c6 as Mi,Q as Ai,U as Ni,R as Ei,bW as Zo,q as Ti,u as rn,j as b,bQ as $r,c7 as Ii,c8 as Li,m as yo,n as Ri,am as rf,ar as of,B as es,c9 as Qa,J as sf,ca as ko,cb as Za,cc as af,cd as lf,bS as cf,bZ as uf,b_ as el,b$ as df,aw as ff,ax as pf,c1 as mf,aO as hf,bM as gf}from"./index-BM2o7PeV.js";import{F as $i,mN as fe,mA as Z,mU as Y,mT as me,mD as j,mP as X,n6 as Ie,ok as ts,ol as bf,mK as ns,mM as ar,mE as ce,om as yf,on as Ft,oo as On,op as ot,nO as le,oq as Di,or as _i,n1 as se,os as Nn,ot as rs,ou as kf,ov as st,ow as wf,ox as xf,mL as wo,oy as vf,oz as os,oA as zi,oB as Je,n3 as Cf,oC as Sf,mO as Ve,nq as Mf,oD as Af,oE as Oi,oF as Nf,oG as Pn,mt as Ef,mu as Tf,nP as en,oH as If,oI as Lf,oJ as Pi,nN as hr,oK as Rf,oL as Bi,oM as Ki,oN as $f,oO as Df,oP as _f,oQ as zf,oR as Of,oS as Pf,oT as Bf,oU as Kf,mV as jf,oV as Hf,ah as on,eD as Ff,oW as ft,oX as qf,jh as Wf,oY as Uf,b as En,dl as Oe,l6 as Fe,G as ji,oZ as gr,o_ as Vf,mx as Gf,o$ as Yf,cq as Jf,p0 as Xf,p1 as Qf,mQ as Zf,p2 as ep,p3 as tp,p4 as np,fr as Hi,nd as Fi,p5 as rp,cV as op,p6 as sp,hw as ap,p7 as lp,fL as xo,p8 as to,K as ip,aI as cp,jN as up,p9 as dp,pa as fp,pb as pp,pc as mp,pd as hp,pe as gp,pf as bp,pg as yp,jL as kp,jC as wp,ph as xp,pi as vp,pj as Cp,pk as Sp,pl as Mp,pm as Ap,pn as Np,po as Ep,pp as Tp,pq as Ip,pr as Lp,ps as Rp,pt as $p,pu as Dp,pv as _p,pw as zp,f9 as Op,nQ as Pp,fe as er,nR as no,px as Bp,py as Kp,pz as jp,pA as tl,mC as nl,pB as Hp,pC as qi,pD as Fp,pE as qp,pF as Wp}from"./appStore-DWP8UET9.js";import{$ as Q,c as F,d as at,e as Bn,f as _e,g as ss,a as ve,h as Xe,b as Ee,i as as,j as ue,k as Up}from"./index-CuiYK18N.js";import{s as Wi,b as Dr,L as rl,m as Vp,d as Gp,a as Yp,u as Ui,e as Jp,w as Xp,l as Qp,f as Zp,g as em,I as ol}from"./linkFollow-B7ivDZMM.js";import{A as tm}from"./mdMarks-DbIcRa0O.js";import"./client-0MPbodA6.js";import{s as nm}from"./emoji-6zl4yfOS.js";import{b as rm,t as om,m as sm,g as am}from"./listFold-DLuxXiIj.js";import{B as lm}from"./book-open-OLNm7OaB.js";const im=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],cm=$i("text-align-center",im);const um=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],dm=$i("text-align-end",um);De({"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 ls="amadeus.notes.spellcheck",vo="amadeus:notes-spellcheck";function Vi(){try{return localStorage.getItem(ls)!=="0"}catch{return!0}}function t1(e){try{localStorage.setItem(ls,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(vo))}catch{}}function Gi(e){const t=n=>{(!n.key||n.key===ls)&&e()};return window.addEventListener(vo,e),window.addEventListener("storage",t),()=>{window.removeEventListener(vo,e),window.removeEventListener("storage",t)}}function n1(){return E.useSyncExternalStore(Gi,Vi,()=>!0)}const sl={spellcheck:"false"};function al(e){const t=[];return e.descendants((n,r)=>{if(!n.isTextblock)return!0;if(n.type.spec.code)return!1;const o=r+1;if(n.forEach((s,a)=>{s.isText&&s.marks.some(l=>l.type.spec.code||l.type.name==="inlineCode")&&t.push(Y.inline(o+a,o+a+s.nodeSize,sl))}),n.textContent.includes("$"))for(const s of Wi(Dr(n)))t.push(Y.inline(o+s.from,o+s.to,sl));return!1}),t.length?me.create(e,t):me.empty}const ll=new fe("amadeus-spellcheck"),fm=Q(()=>new Z({key:ll,state:{init:(e,t)=>al(t.doc),apply:(e,t)=>e.docChanged?al(e.doc):t},props:{decorations:e=>ll.getState(e),attributes:()=>({spellcheck:Vi()?"true":"false"})},view:e=>({destroy:Gi(()=>e.updateState(e.state))})}));De({"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 is="amadeus.notes.codeAutoPair",Co="amadeus:notes-code-autopair";function Yi(){try{return localStorage.getItem(is)!=="0"}catch{return!0}}function r1(e){try{localStorage.setItem(is,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(Co))}catch{}}function pm(e){const t=n=>{(!n.key||n.key===is)&&e()};return window.addEventListener(Co,e),window.addEventListener("storage",t),()=>{window.removeEventListener(Co,e),window.removeEventListener("storage",t)}}function o1(){return E.useSyncExternalStore(pm,Yi,()=>!0)}const br={"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"},mm=new Set(Object.values(br)),il=/[\p{L}\p{N}_]/u;function Ji(e,t,n){if(t!==n||!Yi())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 hm(e,t,n,r){const o=Ji(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(mm.has(r)&&s===r)return e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,t+1))),!0;const l=br[r];if(!l||il.test(s)||l===r&&il.test(a))return!1;const i=e.state.tr.insertText(r+l,t,n);return i.setSelection(j.create(i.doc,t+1)),e.dispatch(i),!0}function gm(e){const{from:t,to:n}=e.state.selection,r=Ji(e,t,n);if(!r||r.off===0)return!1;const o=r.text.charAt(r.off-1);return!br[o]||r.text.charAt(r.off)!==br[o]?!1:(e.dispatch(e.state.tr.delete(t-1,t+1)),!0)}function bm(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=X.empty,f=o.index(-1)?1:o.index(-2)?2:3;for(let w=o.depth-f;w>=o.depth-3;w--)d=X.from(o.node(w).copy(d));let m=o.indexAfter(-1)<o.node(-2).childCount?1:o.indexAfter(-2)<o.node(-3).childCount?2:3;d=d.append(X.from(e.createAndFill()));let p=o.before(o.depth-(f-1)),h=n.tr.replace(p,o.after(-m),new Ie(d,4-f,0)),g=-1;h.doc.nodesBetween(p,h.doc.content.size,(w,y)=>{if(g>-1)return!1;w.isTextblock&&w.content.size==0&&(g=y+1)}),g>-1&&h.setSelection(ce.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 yf(c.doc,o.pos,2,u)?(r&&r(c.split(o.pos,2,u).scrollIntoView()),!0):!1}}function Xi(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?ym(t,n,e,s):km(t,n,s):!0:!1}}function ym(e,t,n,r){let o=e.tr,s=r.end,a=r.$to.end(r.depth);s<a&&(o.step(new ts(s-1,a,s,a,new Ie(X.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new bf(o.doc.resolve(r.$from.pos),o.doc.resolve(a),r.depth));const l=ns(r);if(l==null)return!1;o.lift(r,l);let i=o.doc.resolve(o.mapping.map(s,-1)-1);return ar(o.doc,i.pos)&&i.nodeBefore.type==i.nodeAfter.type&&o.join(i.pos),t(o.scrollIntoView()),!0}function km(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?X.empty:X.from(o))))return!1;let d=s.pos,f=d+a.nodeSize;return r.step(new ts(d-(l?1:0),f+(i?1:0),d+1,f-1,new Ie((l?X.empty:X.from(o.copy(X.empty))).append(i?X.empty:X.from(o.copy(X.empty))),l?0:1,i?0:1),l?0:1)),t(r.scrollIntoView()),!0}function Qi(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=X.from(c?e.create():null),d=new Ie(X.from(e.create(null,X.from(l.type.create(null,u)))),c?3:1,0),f=s.start,m=s.end;n(t.tr.step(new ts(f-(c?3:1),m,f,m,d,1,!0)).scrollIntoView())}return!0}}function wm(e){const t=new Map;if(!e||!e.type)throw new Error("mdast-util-definitions expected node");return zn(e,"definition",function(r){const o=cl(r.identifier);o&&!t.get(o)&&t.set(o,r)}),n;function n(r){const o=cl(r);return t.get(o)}}function cl(e){return String(e||"").toUpperCase()}function xm(){return function(e){const t=wm(e);zn(e,function(n,r,o){if(n.type==="definition"&&o!==void 0&&typeof r=="number")return o.children.splice(r,1),[Xa,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},[Xa,r]}})}}function Zi(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(X.fromArray(n))}function v(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-commonmark",...t}}),e}var cs=Bn("emphasis");v(cs,{displayName:"Attr<emphasis>",group:"Emphasis"});var Et=at("emphasis",e=>({attrs:{marker:{default:e.get(Ft).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:t=>t==="italic"}],toDOM:t=>["em",e.get(cs.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(Et.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});v(Et.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var _r=F("ToggleEmphasis",e=>()=>On(Et.type(e)));v(_r,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var us=ue(e=>st(/(?:^|[^*])\*([^*]+)\*$/,Et.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}));v(us,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var ds=ue(e=>st(/\b_(?![_\s])(.*?[^_\s])_\b/,Et.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}));v(ds,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var fs=_e("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:e=>{const t=e.get(se);return()=>t.call(_r.key)}}});v(fs.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});v(fs.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var ps=Bn("strong");v(ps,{displayName:"Attr<strong>",group:"Strong"});var sn=at("strong",e=>({attrs:{marker:{default:e.get(Ft).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(ps.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(sn.mark,{displayName:"MarkSchema<strong>",group:"Strong"});v(sn.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var zr=F("ToggleStrong",e=>()=>On(sn.type(e)));v(zr,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var ms=ue(e=>st(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),sn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}));v(ms,{displayName:"InputRule<strong>",group:"Strong"});var hs=_e("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:e=>{const t=e.get(se);return()=>t.call(zr.key)}}});v(hs.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});v(hs.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var gs=Bn("inlineCode");v(gs,{displayName:"Attr<inlineCode>",group:"InlineCode"});var dt=at("inlineCode",e=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:t=>["code",e.get(gs.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(dt.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});v(dt.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Or=F("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,dt.type(e))?(n?.(o.removeMark(s,a,dt.type(e))),!0):(Object.keys(t.schema.marks).filter(l=>l!==dt.type.name).map(l=>t.schema.marks[l]).forEach(l=>{o.removeMark(s,a,l)}),n?.(o.addMark(s,a,dt.type(e).create())),!0)});v(Or,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var bs=ue(e=>st(/(?:`)([^`]+)(?:`)$/,dt.type(e)));v(bs,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var ys=_e("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:e=>{const t=e.get(se);return()=>t.call(Or.key)}}});v(ys.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});v(ys.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var Pr=Bn("link");v(Pr,{displayName:"Attr<link>",group:"Link"});var Ge=at("link",e=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:t=>{if(!(t instanceof HTMLElement))throw ot(t);return{href:t.getAttribute("href"),title:t.getAttribute("title")}}}],toDOM:t=>["a",{...e.get(Pr.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(Ge.mark,{displayName:"MarkSchema<link>",group:"Link"});var ec=F("ToggleLink",e=>(t={})=>On(Ge.type(e),t));v(ec,{displayName:"Command<toggleLinkCommand>",group:"Link"});var tc=F("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(Ge.type(e).isInSet(p.marks))return o=p,s=h,!1}),!o)return!1;const c=o.marks.find(({type:p})=>p===Ge.type(e));if(!c)return!1;const u=s,d=s+o.nodeSize,{tr:f}=n,m=Ge.type(e).create({...c.attrs,...t});return m?(r(f.removeMark(u,d,c).addMark(u,d,m).setSelection(new j(f.selection.$anchor)).scrollIntoView()),!0):!1});v(tc,{displayName:"Command<updateLinkCommand>",group:"Link"});var ks=ss("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(ks,{displayName:"NodeSchema<doc>",group:"Doc"});function vm(e){return nf(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 Br=ve("remark-preserve-empty-line",()=>()=>vm);v(Br.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});v(Br.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Kr=Xe("paragraph");v(Kr,{displayName:"Attr<paragraph>",group:"Paragraph"});var Be=Ee("paragraph",e=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:t=>["p",e.get(Kr.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(le).state?.doc.lastChild;t.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&Cm(e)?t.addNode("html",void 0,"<br />"):Zi(t,n),t.closeNode()}}}));function Cm(e){let t=!1;try{e.get(Br.id),t=!0}catch{t=!1}return t}v(Be.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});v(Be.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var ws=F("TurnIntoText",e=>()=>Nn(Be.type(e)));v(ws,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var xs=_e("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:e=>{const t=e.get(se);return()=>t.call(ws.key)}}});v(xs.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});v(xs.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var Sm=Array(6).fill(0).map((e,t)=>t+1);function Mm(e){return e.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Kn=as(Mm,"headingIdGenerator");v(Kn,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var jr=Xe("heading");v(jr,{displayName:"Attr<heading>",group:"Heading"});var rt=Ee("heading",e=>{const t=e.get(Kn.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Sm.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw ot(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...e.get(jr.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}),Zi(n,r),n.closeNode()}}}});v(rt.node,{displayName:"NodeSchema<heading>",group:"Heading"});v(rt.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var nc=ue(e=>zi(/^(?<hashes>#+)\s$/,rt.type(e),t=>{const n=t.groups?.hashes?.length||0,{$from:r}=e.get(le).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(nc,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var kt=F("WrapInHeading",e=>t=>(t??=1,t<1?Nn(Be.type(e)):Nn(rt.type(e),{level:t})));v(kt,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var vs=F("DowngradeHeading",e=>()=>(t,n,r)=>{const{$from:o}=t.selection,s=o.node();if(s.type!==rt.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):Nn(Be.type(e))(t,n,r)});v(vs,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var Cs=_e("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:e=>{const t=e.get(se);return()=>t.call(kt.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:e=>{const t=e.get(se);return()=>t.call(kt.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:e=>{const t=e.get(se);return()=>t.call(kt.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:e=>{const t=e.get(se);return()=>t.call(kt.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:e=>{const t=e.get(se);return()=>t.call(kt.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:e=>{const t=e.get(se);return()=>t.call(kt.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:e=>{const t=e.get(se);return()=>t.call(vs.key)}}});v(Cs.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});v(Cs.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Hr=Xe("blockquote");v(Hr,{displayName:"Attr<blockquote>",group:"Blockquote"});var At=Ee("blockquote",e=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:t=>["blockquote",e.get(Hr.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(At.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});v(At.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var rc=ue(e=>os(/^\s*>\s$/,At.type(e)));v(rc,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var Ss=F("WrapInBlockquote",e=>()=>rs(At.type(e)));v(Ss,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var Ms=_e("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:e=>{const t=e.get(se);return()=>t.call(Ss.key)}}});v(Ms.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});v(Ms.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var As=Xe("codeBlock",()=>({pre:{},code:{}}));v(As,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var jn=Ee("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 ot(t);return{language:t.dataset.language}}}],toDOM:t=>{const n=e.get(As.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 oc=ue(e=>zi(/^```(?<language>[a-z]*)?[\s\n]$/,jn.type(e),t=>({language:t.groups?.language??""})));v(oc,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Ns=F("CreateCodeBlock",e=>(t="")=>Nn(jn.type(e),{language:t}));v(Ns,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var Am=F("UpdateCodeBlockLanguage",()=>({pos:e,language:t}={pos:-1,language:""})=>(n,r)=>e>=0?(r?.(n.tr.setNodeAttribute(e,"language",t)),!0):!1);v(Am,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Es=_e("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:e=>{const t=e.get(se);return()=>t.call(Ns.key)}}});v(Es.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});v(Es.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Ts=Xe("image");v(Ts,{displayName:"Attr<image>",group:"Image"});var an=Ee("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 ot(t);return{src:t.getAttribute("src")||"",alt:t.getAttribute("alt")||"",title:t.getAttribute("title")||t.getAttribute("alt")||""}}}],toDOM:t=>["img",{...e.get(Ts.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(an.node,{displayName:"NodeSchema<image>",group:"Image"});v(an.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var sc=F("InsertImage",e=>(t={})=>(n,r)=>{if(!r)return!0;const{src:o="",alt:s="",title:a=""}=t,l=an.type(e).create({src:o,alt:s,title:a});return l&&r(n.tr.replaceSelectionWith(l).scrollIntoView()),!0});v(sc,{displayName:"Command<insertImageCommand>",group:"Image"});var ac=F("UpdateImage",e=>(t={})=>(n,r)=>{const o=wf(n.selection,an.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(ac,{displayName:"Command<updateImageCommand>",group:"Image"});var Nm=ue(e=>new Je(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(t,n,r,o)=>{const[s,a,l="",i]=n;return s?t.tr.replaceWith(r,o,an.type(e).create({src:l,alt:a,title:i})):null}));v(Nm,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var yr=Xe("hardbreak",e=>({"data-type":"hardbreak","data-is-inline":e.attrs.isInline}));v(yr,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Ye=Ee("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(yr.key)(t)," "]:["br",e.get(yr.key)(t)],parseMarkdown:{match:({type:t})=>t==="break",runner:(t,n,r)=>{t.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>`
2
2
  `,toMarkdown:{match:t=>t.type.name==="hardbreak",runner:(t,n)=>{n.attrs.isInline?t.addNode("text",void 0,`
3
- `):t.addNode("break")}}}));v(Je.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});v(Je.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Is=F("InsertHardbreak",e=>()=>(t,n)=>{const{selection:r,tr:o}=t;if(!(r instanceof j))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(ce.near(o.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(o.setMeta("hardbreak",!0).replaceSelectionWith(Je.type(e).create()).scrollIntoView()),!0});v(Is,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Ls=_e("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:e=>{const t=e.get(se);return()=>t.call(Is.key)}}});v(Ls.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});v(Ls.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Rs=Xe("hr");v(Rs,{displayName:"Attr<hr>",group:"Hr"});var Hn=Ee("hr",e=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:t=>["hr",e.get(Rs.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(Hn.node,{displayName:"NodeSchema<hr>",group:"Hr"});v(Hn.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var lc=ue(e=>new Ye(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,o)=>{const{tr:s}=t;return n[0]&&s.replaceWith(r-1,o,Hn.type(e).create()),s}));v(lc,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var ic=F("InsertHr",e=>()=>(t,n)=>{if(!n)return!0;const r=Be.node.type(e).create(),{tr:o,selection:s}=t,{from:a}=s,l=Hn.type(e).create();if(!l)return!0;const i=o.replaceSelectionWith(l).insert(a,r),c=ce.findFrom(i.doc.resolve(a),1,!0);return c&&n(i.setSelection(c).scrollIntoView()),!0});v(ic,{displayName:"Command<insertHrCommand>",group:"Hr"});var Fr=Xe("bulletList");v(Fr,{displayName:"Attr<bulletList>",group:"BulletList"});var mt=Ee("bullet_list",e=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:t=>{if(!(t instanceof HTMLElement))throw ot(t);return{spread:t.dataset.spread==="true"}}}],toDOM:t=>["ul",{...e.get(Fr.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(mt.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});v(mt.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var cc=ue(e=>os(/^\s*([-+*])\s$/,mt.type(e)));v(cc,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var $s=F("WrapInBulletList",e=>()=>rs(mt.type(e)));v($s,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Ds=_e("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:e=>{const t=e.get(se);return()=>t.call($s.key)}}});v(Ds.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});v(Ds.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var qr=Xe("orderedList");v(qr,{displayName:"Attr<orderedList>",group:"OrderedList"});var ht=Ee("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 ot(t);return{spread:t.dataset.spread,order:t.hasAttribute("start")?Number(t.getAttribute("start")):1}}}],toDOM:t=>["ol",{...e.get(qr.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(ht.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});v(ht.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var uc=ue(e=>os(/^\s*(\d+)\.\s$/,ht.type(e),t=>({order:Number(t[1])}),(t,n)=>n.childCount+n.attrs.order===Number(t[1])));v(uc,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var _s=F("WrapInOrderedList",e=>()=>rs(ht.type(e)));v(_s,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var zs=_e("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:e=>{const t=e.get(se);return()=>t.call(_s.key)}}});v(zs.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});v(zs.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Os=Xe("listItem");v(Os,{displayName:"Attr<listItem>",group:"ListItem"});var bt=Ee("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 ot(t);return{label:t.dataset.label,listType:t.dataset.listType,spread:t.dataset.spread==="true"}}}],toDOM:t=>["li",{...e.get(Os.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(bt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});v(bt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Ps=F("SinkListItem",e=>()=>Qi(bt.type(e)));v(Ps,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Bs=F("LiftListItem",e=>()=>Xi(bt.type(e)));v(Bs,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Ks=F("SplitListItem",e=>()=>bm(bt.type(e)));v(Ks,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Em(e){return(t,n,r)=>{const{selection:o}=t;if(!(o instanceof j))return!1;const{empty:s,$from:a}=o;return!s||a.parentOffset!==0||a.node(-1).type!==bt.type(e)?!1:kf(t,n,r)}}var js=F("LiftFirstListItem",e=>()=>Em(e));v(js,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Hs=_e("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:e=>{const t=e.get(se);return()=>t.call(Ks.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:e=>{const t=e.get(se);return()=>t.call(Ps.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:e=>{const t=e.get(se);return()=>t.call(Bs.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:e=>{const t=e.get(se);return()=>t.call(js.key)}}});v(Hs.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});v(Hs.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var dc=ss("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(dc,{displayName:"NodeSchema<text>",group:"Text"});var Fs=Xe("html");v(Fs,{displayName:"Attr<html>",group:"Html"});var qs=Ee("html",e=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:t=>{const n=document.createElement("span"),r={...e.get(Fs.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(qs.node,{displayName:"NodeSchema<html>",group:"Html"});v(qs.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var Tm=[ks,Kr,Be,Kn,jr,rt,yr,Je,Hr,At,As,jn,Rs,Hn,Ts,an,Fr,mt,qr,ht,Os,bt,cs,Et,ps,sn,gs,dt,Pr,Ge,Fs,qs,dc].flat(),Im=[rc,cc,uc,oc,lc,nc].flat(),Lm=[us,ds,bs,ms],Rm=F("IsMarkSelected",()=>e=>t=>{if(!e)return!1;const{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),$m=F("IsNoteSelected",()=>e=>t=>e?xf(t,e).hasNode:!1),Dm=F("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)}),_m=F("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}),zm=F("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&&wo(i,r,o);if(!c)return!1;s=s.wrap(i,c)}catch{return!1}return n?.(s),!0}),Om=F("AddBlockType",()=>e=>(t,n)=>{const{nodeType:r,attrs:o=null}=e??{};if(!r)return!1;const s=t.tr;try{const a=r instanceof vf?r:r.createAndFill(o);if(!a)return!1;s.replaceSelectionWith(a)}catch{return!1}return n?.(s),!0}),Pm=F("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(j.near(a))}catch{return!1}return n?.(s.scrollIntoView()),!0}),Bm=[ws,Ss,kt,vs,Ns,Is,ic,sc,ac,_s,$s,Ps,Ks,Bs,js,_r,Or,zr,ec,tc,Rm,$m,Dm,_m,zm,Om,Pm],Km=[Ms,Es,Ls,Cs,Hs,zs,Ds,xs,fs,ys,hs].flat(),Wr=ve("remarkAddOrderInList",()=>()=>e=>{zn(e,"list",t=>{if(t.ordered){const n=t.start??1;t.children.forEach((r,o)=>{r.label=o+n})}})});v(Wr.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});v(Wr.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var Ws=ve("remarkLineBreak",()=>()=>e=>{const t=/[\t ]*(?:\r?\n|\r)/g;zn(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(Ws.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});v(Ws.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Us=ve("remarkInlineLink",()=>xm);v(Us.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});v(Us.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var jm=e=>!!e.children,Hm=e=>e.type==="html";function Fm(e,t){return n(e,0,null)[0];function n(r,o,s){if(jm(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 qm=["root","blockquote","listItem"],Vs=ve("remarkHTMLTransformer",()=>()=>e=>{Fm(e,(t,n,r)=>Hm(t)?(r&&qm.includes(r.type)&&(t.children=[{...t}],delete t.value,t.type="paragraph"),[t]):[t])});v(Vs.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});v(Vs.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var Gs=ve("remarkMarker",()=>()=>(e,t)=>{const n=r=>t.value.charAt(r.position.start.offset);zn(e,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});v(Gs.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});v(Gs.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var fc=Q(()=>{let e=!1;const t=new Z({key:new fe("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=J.widget(r,o,{side:-1}),a=document.createElement("span"),l=J.widget(r,a);return setTimeout(()=>{o.contentEditable="true",a.contentEditable="true"}),me.create(n.doc,[s,l])}return me.empty}}});return t});v(fc,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Js=Q(e=>new Z({key:new fe("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 Di))return;const{from:a}=s;return r.tr.setNodeMarkup(a,Je.type(e),void 0,[])}if(s instanceof _i){let a=r.tr;const{from:l,to:i}=s;return r.doc.nodesBetween(l,i,(c,u)=>{c.type===Je.type(e)&&(a=a.setNodeMarkup(u,Je.type(e),void 0,[]))}),a}}}));v(Js,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var Ys=as(["table","code_block"],"hardbreakFilterNodes");v(Ys,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var pc=Q(e=>{const t=e.get(Ys.key);return new Z({key:new fe("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(pc,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var mc=Q(e=>{const t=new fe("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;const o=e.get(Kn.key),s=r.state.tr.setMeta("addToHistory",!1);let a=!1;const l={};r.state.doc.descendants((i,c)=>{if(i.type===rt.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 Z({key:t,view:r=>(n(r),{update:(o,s)=>{o.state.doc.eq(s.doc)||n(o)}})})});v(mc,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var hc=Q(e=>{const t=(n,r,o)=>{if(!o.selection||n.some(d=>d.getMeta("addToHistory")===!1||!d.isGeneric))return null;const s=ht.type(e),a=mt.type(e),l=bt.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,w,y,C)=>{if(g.type===l){const N={...g.attrs};i(N,C)&&(c=c.setNodeMarkup(w,void 0,N))}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 Z({key:new fe("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:t})});v(hc,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Wm=[Js,Ys,pc,fc,Wr,Us,Ws,Vs,Gs,Br,mc,hc].flat(),Um=[Tm,Im,Lm,Bm,Km,Wm].flat();let So,Mo;if(typeof WeakMap<"u"){let e=new WeakMap;So=t=>e.get(t),Mo=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;So=r=>{for(let o=0;o<e.length;o+=2)if(e[o]==r)return e[o+1]},Mo=(r,o)=>(n==10&&(n=0),e[n++]=r,e[n++]=o)}var Y=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 So(e)||Mo(e,Vm(e))}};function Vm(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=Gm(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:w,colwidth:y}=h.attrs;for(let C=0;C<w;C++){if(C+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-C});break}const N=o+C*t;for(let M=0;M<g;M++){r[N+M]==0?r[N+M]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:g-M});const T=y&&y[M];if(T){const D=(N+M)%t*2,H=a[D];H==null||H!=T&&a[D+1]==1?(a[D]=T,a[D+1]=1):H==T&&a[D+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 Y(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&&Jm(l,a,e),l}function Gm(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 Jm(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=Ym(i)))[c]=u)}l&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Ym(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function ul(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 dl(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 Xm(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 Qm(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Xm}};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=>ul(r,t)}],toDOM(r){return["td",dl(r,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ul(r,t)}],toDOM(r){return["th",dl(r,t),0]}}}}function qe(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 vt=new fe("selectingCells");function zt(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 Ke(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 Fn(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=zt(t.$head)||Zm(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function Zm(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 Ao(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function eh(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Xs(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function gc(e,t,n){const r=e.node(-1),o=Y.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 Ot(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 th(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 nh(e,t,n){const r=qe(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 de=class ut extends ce{constructor(t,n=t){const r=t.node(-1),o=Y.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 Sf(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(Ao(r)&&Ao(o)&&Xs(r,o)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?ut.rowSelection(r,o):s&&this.isColSelection()?ut.colSelection(r,o):new ut(r,o)}return j.between(r,o)}content(){const t=this.$anchorCell.node(-1),n=Y.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 w=p.attrs;if(h>0&&(w=Ot(w,0,h)),g>0&&(w=Ot(w,w.colspan-g,g)),m.left<o.left){if(p=p.type.createAndFill(w),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(w)}`)}else p=p.type.create(w,p.content)}if(m.top<o.top||m.bottom>o.bottom){const w={...p.attrs,rowspan:Math.min(m.bottom,o.bottom)-Math.max(m.top,o.top)};m.top<o.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}a.push(t.child(i).copy(X.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?t:a;return new Ie(X.from(l),1,1)}replace(t,n=Ie.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?Ie.empty:n)}const s=ce.findFrom(t.doc.resolve(t.mapping.slice(r).map(this.to)),-1);s&&t.setSelection(s)}replaceWith(t,n){this.replace(t,new Ie(X.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=Y.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=Y.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 ut(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=Y.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 ut&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),o=Y.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 ut(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new ut(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new ut(t.resolve(n),t.resolve(r))}getBookmark(){return new rh(this.$anchorCell.pos,this.$headCell.pos)}};de.prototype.visible=!1;ce.jsonID("cell",de);var rh=class bc{constructor(t,n){this.anchor=t,this.head=n}map(t){return new bc(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&&Xs(n,r)?new de(n,r):ce.near(r,1)}};function oh(e){if(!(e.selection instanceof de))return null;const t=[];return e.selection.forEachCell((n,r)=>{t.push(J.node(r,r+n.nodeSize,{class:"selectedCell"}))}),me.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 lh(e,t,n){const r=(t||e).selection,o=(t||e).doc;let s,a;if(r instanceof Ve&&(a=r.node.type.spec.tableRole)){if(a=="cell"||a=="header_cell")s=de.create(o,r.from);else if(a=="row"){const l=o.resolve(r.from+1);s=de.rowSelection(l,l)}else if(!n){const l=Y.get(r.node),i=r.from+1,c=i+l.map[l.width*l.height-1];s=de.create(o,i+1,c)}}else r instanceof j&&sh(r)?s=j.create(o,r.from):r instanceof j&&ah(r)&&(s=j.create(o,r.$from.start(),r.$from.end()));return s&&(t||(t=e.tr)).setSelection(s),t}const ih=new fe("fix-tables");function yc(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)?yc(e.child(l),i,n+1,r):i.nodesBetween(0,i.content.size,r,n+1),n+=i.nodeSize}}function ch(e,t){let n;const r=(o,s)=>{o.type.spec.tableRole=="table"&&(n=uh(e,o,s,n))};return t?t.doc!=e.doc&&yc(t.doc,e.doc,0,r):e.doc.descendants(r),n}function uh(e,t,n,r){const o=Y.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,Ot(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 w=qe(e.schema)[m].createAndFill();w&&p.push(w)}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(ih,{fixTables:!0})}function kc(e){const t=Y.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 wc(e,t){const n=[],r=Y.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 xc(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 dh(t=>t.type.spec.tableRole==="table",e)}function dh(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 Gt(e,t){const n=qn(t.$from);if(!n)return;const r=Y.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 Jt(e,t){const n=qn(t.$from);if(!n)return;const r=Y.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 fl(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=Gt(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=Gt(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=Gt(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=Gt(r,e.selection),l=Jt(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=Gt(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 pl(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=Jt(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=Jt(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=Jt(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=Jt(r,e.selection),l=Gt(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=Jt(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){return e[0].map((t,n)=>e.map(r=>r[n]))}function fh(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=fl(r,o))===null||t===void 0?void 0:t.indexes,u=(n=fl(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=ph(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=Y.get(d),m=i.start,p=s,h=f.positionAt(f.height-1,p,d),g=r.doc.resolve(m+h),w=f.positionAt(0,p,d),y=r.doc.resolve(m+w);return r.setSelection(de.colSelection(g,y)),!0}function ph(e,t,n,r){let o=ml(kc(e));return o=xc(o,t,n),o=ml(o),wc(e,o)}function mh(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=hh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=Y.get(d),m=i.start,p=s,h=f.positionAt(p,f.width-1,d),g=r.doc.resolve(m+h),w=f.positionAt(p,0,d),y=r.doc.resolve(m+w);return r.setSelection(de.rowSelection(g,y)),!0}function hh(e,t,n,r){let o=kc(e);return o=xc(o,t,n),wc(e,o)}function Tt(e){const t=e.selection,n=Fn(e),r=n.node(-1),o=n.start(-1),s=Y.get(r);return{...t instanceof de?s.rectBetween(t.$anchorCell.pos-o,t.$headCell.pos-o):s.findCell(n.pos-o),tableStart:o,map:s,table:r}}function Qs(e,{map:t,tableStart:n,table:r},o){let s=o>0?-1:0;nh(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,th(c.attrs,o-t.colCount(i))),a+=c.attrs.rowspan-1}else{const i=s==null?qe(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 gh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e);t(Qs(e.tr,n,n.left))}return!0}function bh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e);t(Qs(e.tr,n,n.right))}return!0}function vc(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,Ot(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 yh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let o=n.right-1;vc(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=Y.get(s)}t(r)}return!0}function Cc(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 kh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let o=n.bottom-1;Cc(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=Y.get(n.table)}t(r)}return!0}function wh(e,t){return function(n,r){if(!Ke(n))return!1;const o=Fn(n);if(o.nodeAfter.attrs[e]===t)return!1;if(r){const s=n.tr;n.selection instanceof de?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 xh(e){return function(t,n){if(!Ke(t))return!1;if(n){const r=qe(t.schema),o=Tt(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 hl(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 Zs(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?xh(e):function(n,r){if(!Ke(n))return!1;if(r){const o=qe(n.schema),s=Tt(n),a=n.tr,l=hl("row",s,o),i=hl("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}}Zs("row",{useDeprecatedLogic:!0});Zs("column",{useDeprecatedLogic:!0});Zs("cell",{useDeprecatedLogic:!0});function vh(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 ea(e){return function(t,n){if(!Ke(t))return!1;const r=vh(Fn(t),e);if(r==null)return!1;if(n){const o=t.doc.resolve(r);n(t.tr.setSelection(j.between(o,eh(o))).scrollIntoView())}return!0}}function Ch(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 tr(e,t){const n=e.selection;if(!(n instanceof de))return!1;if(t){const r=e.tr,o=qe(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 Ie(o,0,0))}),r.docChanged&&t(r)}return!0}function Sh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return mh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function Mh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return fh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function Ah(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=No(qe(a).row,new Ie(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(n||r?No(qe(a).row,new Ie(t,n,r)).content:t);else return null;return Nh(a,l)}function Nh(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(X.empty),n[o]<r){const s=qe(e).cell.createAndFill(),a=[];for(let l=n[o];l<r;l++)a.push(s);t[o]=t[o].append(X.from(a))}return{height:t.length,width:r,rows:t}}function No(e,t){const n=e.createAndFill();return new Mf(n).replace(0,n.content.size,t).doc}function Eh({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(Ot(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(X.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(X.from(i))}n=s,t=o}return{width:e,height:t,rows:n}}function Th(e,t,n,r,o,s,a){const l=e.doc.type.schema,i=qe(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,X.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 gl(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 bl(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,Ot(f.attrs,a-m,f.attrs.colspan-(a-m))),e.insert(p+f.nodeSize,f.type.createAndFill(Ot(f.attrs,0,a-m))),c+=f.attrs.rowspan-1}}return i}function yl(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=Y.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=Y.get(s),f=d.mapping.maps.length}Th(d,a,s,n,c,u,f)&&m(),gl(d,a,s,n,i,c,l,f)&&m(),gl(d,a,s,n,i,c,u,f)&&m(),bl(d,a,s,n,l,u,i,f)&&m(),bl(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 Ie(o.rows[p-l],0,0))}m(),d.setSelection(new de(d.doc.resolve(n+a.positionAt(l,i,s)),d.doc.resolve(n+a.positionAt(u-1,c-1,s)))),t(d)}const Ih=Cf({ArrowLeft:nr("horiz",-1),ArrowRight:nr("horiz",1),ArrowUp:nr("vert",-1),ArrowDown:nr("vert",1),"Shift-ArrowLeft":rr("horiz",-1),"Shift-ArrowRight":rr("horiz",1),"Shift-ArrowUp":rr("vert",-1),"Shift-ArrowDown":rr("vert",1),Backspace:tr,"Mod-Backspace":tr,Delete:tr,"Mod-Delete":tr});function lr(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function nr(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;if(s instanceof de)return lr(n,r,ce.near(s.$headCell,t));if(e!="horiz"&&!s.empty)return!1;const a=Sc(o,e,t);if(a==null)return!1;if(e=="horiz")return lr(n,r,ce.near(n.doc.resolve(s.head+t),t));{const l=n.doc.resolve(a),i=gc(l,e,t);let c;return i?c=ce.near(i,1):t<0?c=ce.near(n.doc.resolve(l.before(-1)),-1):c=ce.near(n.doc.resolve(l.after(-1)),1),lr(n,r,c)}}}function rr(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;let a;if(s instanceof de)a=s;else{const i=Sc(o,e,t);if(i==null)return!1;a=new de(n.doc.resolve(i))}const l=gc(a.$headCell,e,t);return l?lr(n,r,new de(a.$anchorCell,l)):!1}}function Lh(e,t){const n=e.state.doc,r=zt(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new de(r))),!0):!1}function Rh(e,t,n){if(!Ke(e.state))return!1;let r=Ah(n);const o=e.state.selection;if(o instanceof de){r||(r={width:1,height:1,rows:[X.from(No(qe(e.state.schema).cell,n))]});const s=o.$anchorCell.node(-1),a=o.$anchorCell.start(-1),l=Y.get(s).rectBetween(o.$anchorCell.pos-a,o.$headCell.pos-a);return r=Eh(r,l.right-l.left,l.bottom-l.top),yl(e.state,e.dispatch,a,l,r),!0}else if(r){const s=Fn(e.state),a=s.start(-1);return yl(e.state,e.dispatch,a,Y.get(s.node(-1)).findCell(s.pos-a),r),!0}else return!1}function $h(e,t){var n;if(t.button!=0||t.ctrlKey||t.metaKey)return;const r=kl(e,t.target);let o;if(t.shiftKey&&e.state.selection instanceof de)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&r&&(o=zt(e.state.selection.$anchor))!=null&&((n=ro(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=ro(e,c);const d=vt.getState(e.state)==null;if(!u||!Xs(i,u))if(d)u=i;else return;const f=new de(i,u);if(d||!e.state.selection.eq(f)){const m=e.state.tr.setSelection(f);d&&m.setMeta(vt,i.pos),e.dispatch(m)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",l),vt.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(vt,-1))}function l(i){const c=i,u=vt.getState(e.state);let d;if(u!=null)d=e.state.doc.resolve(u);else if(kl(e,c.target)!=r&&(d=ro(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 Sc(e,t,n){if(!(e.state.selection instanceof j))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 kl(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function ro(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&&zt(e.state.doc.resolve(r))||zt(e.state.doc.resolve(o))}var Dh=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")),Eo(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,Eo(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function Eo(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],w=g?g+"px":"";if(a+=g||r,g||(l=!1),i)i.style.width!=w&&(i.style.width=w),i=i.nextSibling;else{const y=document.createElement("col");y.style.width=w,t.appendChild(y)}}}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 Pe=new fe("tableColumnResizing");function _h({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Dh,lastColumnResizable:o=!0}={}){const s=new Z({key:Pe,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=qe(l.schema).table.name;return r&&c&&(c[u]=(d,f)=>new r(d,n,f)),new zh(-1,!1)},apply(a,l){return l.apply(a)}},props:{attributes:a=>{const l=Pe.getState(a);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,l)=>{Oh(a,l,e,o)},mouseleave:a=>{Ph(a)},mousedown:(a,l)=>{Bh(a,l,t,n)}},decorations:a=>{const l=Pe.getState(a);if(l&&l.activeHandle>-1)return qh(a,l.activeHandle)},nodeViews:{}}});return s}var zh=class ir{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(Pe);if(r&&r.setHandle!=null)return new ir(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ir(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return Ao(t.doc.resolve(o))||(o=-1),new ir(o,n.dragging)}return n}};function Oh(e,t,n,r){if(!e.editable)return;const o=Pe.getState(e.state);if(o&&!o.dragging){const s=jh(t.target);let a=-1;if(s){const{left:l,right:i}=s.getBoundingClientRect();t.clientX-l<=n?a=wl(e,t,"left",n):i-t.clientX<=n&&(a=wl(e,t,"right",n))}if(a!=o.activeHandle){if(!r&&a!==-1){const l=e.state.doc.resolve(a),i=l.node(-1),c=Y.get(i),u=l.start(-1);if(c.colCount(l.pos-u)+l.nodeAfter.attrs.colspan-1==c.width-1)return}Mc(e,a)}}}function Ph(e){if(!e.editable)return;const t=Pe.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Mc(e,-1)}function Bh(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=Pe.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const l=e.state.doc.nodeAt(a.activeHandle),i=Kh(e,a.activeHandle,l.attrs);e.dispatch(e.state.tr.setMeta(Pe,{setDragging:{startX:t.clientX,startWidth:i}}));function c(d){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=Pe.getState(e.state);f?.dragging&&(Hh(e,f.activeHandle,xl(f.dragging,d,n)),e.dispatch(e.state.tr.setMeta(Pe,{setDragging:null})))}function u(d){if(!d.which)return c(d);const f=Pe.getState(e.state);if(f&&f.dragging){const m=xl(f.dragging,d,n);vl(e,f.activeHandle,m,r)}}return vl(e,a.activeHandle,i,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),t.preventDefault(),!0}function Kh(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 jh(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function wl(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=zt(e.state.doc.resolve(a));if(!l)return-1;if(n=="right")return l.pos;const i=Y.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 xl(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Mc(e,t){e.dispatch(e.state.tr.setMeta(Pe,{setHandle:t}))}function Hh(e,t,n){const r=e.state.doc.resolve(t),o=r.node(-1),s=Y.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():Fh(f.colspan);p[m]=n,i.setNodeMarkup(a+d,null,{...f,colwidth:p})}i.docChanged&&e.dispatch(i)}function vl(e,t,n,r){const o=e.state.doc.resolve(t),s=o.node(-1),a=o.start(-1),l=Y.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&&Eo(s,i.firstChild,i,r,l,n)}function Fh(e){return Array(e).fill(0)}function qh(e,t){const n=[],r=e.doc.resolve(t),o=r.node(-1);if(!o)return me.empty;const s=Y.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=Pe.getState(e))===null||i===void 0)&&i.dragging&&n.push(J.node(a+d,a+d+o.nodeAt(d).nodeSize,{class:"column-resize-dragging"})),n.push(J.widget(f,m))}}return me.create(e.doc,n)}function Wh({allowTableNodeSelection:e=!1}={}){return new Z({key:vt,state:{init(){return null},apply(t,n){const r=t.getMeta(vt);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:oh,handleDOMEvents:{mousedown:$h},createSelectionBetween(t){return vt.getState(t.state)!=null?t.state.selection:null},handleTripleClick:Lh,handleKeyDown:Ih,handlePaste:Rh},appendTransaction(t,n,r){return lh(r,ch(r,n),e)}})}var kr=typeof navigator<"u"?navigator:null,ta=kr&&kr.userAgent||"",Uh=/Edge\/(\d+)/.exec(ta),Vh=/MSIE \d/.exec(ta),Gh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ta),Jh=!!(Vh||Gh||Uh),Yh=!Jh&&!!kr&&/Apple Computer/.test(kr.vendor),Ac=new fe("safari-ime-span"),To=!1,Xh={key:Ac,props:{decorations:Qh,handleDOMEvents:{compositionstart:()=>{To=!0},compositionend:()=>{To=!1}}}};function Qh(e){const{$from:t,$to:n,to:r}=e.selection;if(To&&t.sameParent(n)){const o=J.widget(r,Zh,{ignoreSelection:!0,key:"safari-ime-span"});return me.create(e.doc,[o])}}function Zh(e){const t=e.dom.ownerDocument.createElement("span");return t.className="ProseMirror-safari-ime-span",t}var eg=new Z(Yh?Xh:{key:Ac});function q(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-gfm",...t}}),e}var na=Bn("strike_through");q(na,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var ln=at("strike_through",e=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:t=>t==="line-through"}],toDOM:t=>["del",e.get(na.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")}}}));q(ln.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});q(ln.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Tn=F("ToggleStrikeThrough",e=>()=>On(ln.type(e)));q(Tn,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var ra=ue(e=>st(new RegExp("(?<![\\w:/])(~{1,2})(.+?)\\1(?!\\w|\\/)"),ln.type(e)));q(ra,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var oa=_e("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:e=>{const t=e.get(se);return()=>t.call(Tn.key)}}});q(oa.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});q(oa.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Wn=Qm({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:e=>e.style.textAlign||"left",setDOMAttr:(e,t)=>{t.style=`text-align: ${e||"left"}`}}}}),pt=Ee("table",()=>({...Wn.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()}}}));q(pt.node,{displayName:"NodeSchema<table>",group:"Table"});q(pt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var Un=Ee("table_header_row",()=>({...Wn.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())}}}));q(Un.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});q(Un.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var cn=Ee("table_row",()=>({...Wn.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())}}}));q(cn.node,{displayName:"NodeSchema<tableRow>",group:"Table"});q(cn.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var Vn=Ee("table_cell",()=>({...Wn.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()}}}));q(Vn.node,{displayName:"NodeSchema<tableCell>",group:"Table"});q(Vn.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var tn=Ee("table_header",()=>({...Wn.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()}}}));q(tn.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});q(tn.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function Nc(e,t=3,n=3){const r=Array(n).fill(0).map(()=>Vn.type(e).createAndFill()),o=Array(n).fill(0).map(()=>tn.type(e).createAndFill()),s=Array(t).fill(0).map((a,l)=>l===0?Un.type(e).create(null,o):cn.type(e).create(null,r));return pt.type(e).create(null,s)}function Ec(e){return(t,n)=>r=>{n=n??r.selection.from;const o=r.doc.resolve(n),s=Nf(i=>i.type.name==="table")(o),a=s?{node:s.node,from:s.start}:void 0,l=e==="row";if(a){const i=Y.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?de.rowSelection:de.colSelection,f=i.positionAt(l?t:0,l?0:t,a.node),m=r.doc.resolve(a.from+f);return Oi(r.setSelection(d(u,m)))}}return r}}var tg=Ec("row"),ng=Ec("col");function Tc(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 Vn.type(e).createAndFill({alignment:u?.attrs.alignment})});return t.insert(a,cn.type(e).create(null,l)),t}function rg(e){const t=qn(e.$from);if(!t)return;const n=Y.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 og(e){const t=rg(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 Oi(e.setSelection(new de(o,n)))}}return e}var sa=F("GoToPrevTableCell",()=>()=>ea(-1));q(sa,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var aa=F("GoToNextTableCell",()=>()=>ea(1));q(aa,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var la=F("ExitTable",e=>()=>(t,n)=>{if(!Ke(t))return!1;const{$head:r}=t.selection,o=Af(r,pt.type(e));if(!o)return!1;const{to:s}=o,a=t.tr.replaceWith(s,s,Be.type(e).createAndFill());return a.setSelection(ce.near(a.doc.resolve(s),1)).scrollIntoView(),n?.(a),!0});q(la,{displayName:"Command<breakTableCommand>",group:"Table"});var Ic=F("InsertTable",e=>({row:t,col:n}={})=>(r,o)=>{const{selection:s,tr:a}=r,{from:l}=s,i=Nc(e,t,n),c=a.replaceSelectionWith(i),u=ce.findFrom(c.doc.resolve(l),1,!0);return u&&c.setSelection(u),o?.(c),!0});q(Ic,{displayName:"Command<insertTableCommand>",group:"Table"});var Lc=F("MoveRow",()=>({from:e,to:t,pos:n}={})=>Sh({from:e??0,to:t??0,pos:n}));q(Lc,{displayName:"Command<moveRowCommand>",group:"Table"});var Rc=F("MoveCol",()=>({from:e,to:t,pos:n}={})=>Mh({from:e??0,to:t??0,pos:n}));q(Rc,{displayName:"Command<moveColCommand>",group:"Table"});var $c=F("SelectRow",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(tg(e.index,e.pos)(r))});q($c,{displayName:"Command<selectRowCommand>",group:"Table"});var Dc=F("SelectCol",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(ng(e.index,e.pos)(r))});q(Dc,{displayName:"Command<selectColCommand>",group:"Table"});var _c=F("SelectTable",()=>()=>(e,t)=>{const{tr:n}=e;return!!t?.(og(n))});q(_c,{displayName:"Command<selectTableCommand>",group:"Table"});var zc=F("DeleteSelectedCells",()=>()=>(e,t)=>{const{selection:n}=e;if(!(n instanceof de))return!1;const r=n.isRowSelection(),o=n.isColSelection();return r&&o?Ch(e,t):o?yh(e,t):kh(e,t)});q(zc,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var Oc=F("AddColBefore",()=>()=>gh);q(Oc,{displayName:"Command<addColBeforeCommand>",group:"Table"});var Pc=F("AddColAfter",()=>()=>bh);q(Pc,{displayName:"Command<addColAfterCommand>",group:"Table"});var Bc=F("AddRowBefore",e=>()=>(t,n)=>{if(!Ke(t))return!1;if(n){const r=Tt(t);n(Tc(e,t.tr,r,r.top))}return!0});q(Bc,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var Kc=F("AddRowAfter",e=>()=>(t,n)=>{if(!Ke(t))return!1;if(n){const r=Tt(t);n(Tc(e,t.tr,r,r.bottom))}return!0});q(Kc,{displayName:"Command<addRowAfterCommand>",group:"Table"});var jc=F("SetAlign",()=>(e="left")=>wh("alignment",e));q(jc,{displayName:"Command<setAlignCommand>",group:"Table"});var Hc=ue(e=>new Ye(/^\|(?<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),pt.type(e)))return null;const a=Nc(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),l=t.tr.replaceRangeWith(r,o,a);return l.setSelection(j.create(l.doc,r+3)).scrollIntoView()}));q(Hc,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var Fc=Up(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 Be.type(e).create();const f=c.firstChild;if(!(d>0&&f&&f.childCount===0))return c;if(u>=3){const g=c.child(1),w=[];for(let N=0;N<g.childCount;N++){const M=g.child(N);w.push(tn.type(e).create(M.attrs,M.content,M.marks))}const y=f.type.create(f.attrs,w),C=[];for(let N=2;N<u;N++)C.push(c.child(N));return c.type.create(c.attrs,[y,...C])}const m=Array(d).fill(0).map(()=>tn.type(e).createAndFill()),p=new Ie(X.from(m),0,0),h=f.replace(0,0,p);return c.replace(0,f.nodeSize,new Ie(X.from(h),0,0))}function s(c){const u=cn.type(e),d=[];let f=[],m=!1;function p(){if(f.length===0)return;const h=Un.type(e).createAndFill(),g=pt.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?X.from(d):c}function a(c){let u=s(c),d=u!==c;const f=[];return u.forEach(m=>{if(m.type===pt.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?X.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===Be.type(e)&&m.content.size===0&&p&&p.type===pt.type(e)||u.push(m)}return u.length<d.length?X.from(u):c}let i=a(t.content);return i=l(i),new Ie(X.from(i),t.openStart,t.openEnd)}}));q(Fc,{displayName:"PasteRule<table>",group:"Table"});var ia=_e("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:e=>{const t=e.get(se);return()=>t.call(aa.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:e=>{const t=e.get(se);return()=>t.call(sa.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:e=>{const t=e.get(se);return()=>t.call(la.key)}}});q(ia.ctx,{displayName:"KeymapCtx<table>",group:"Table"});q(ia.shortcuts,{displayName:"Keymap<table>",group:"Table"});var oo="footnote_definition",Cl="footnoteDefinition",ca=Ee("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${oo}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw ot(e);return{label:e.dataset.label}},contentElement:"dd"}],toDOM:e=>{const t=e.attrs.label;return["dl",{"data-label":t,"data-type":oo},["dt",t],["dd",0]]},parseMarkdown:{match:({type:e})=>e===Cl,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===oo,runner:(e,t)=>{e.openNode(Cl,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));q(ca.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});q(ca.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var so="footnote_reference",ua=Ee("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${so}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw ot(e);return{label:e.dataset.label}}}],toDOM:e=>{const t=e.attrs.label;return["sup",{"data-label":t,"data-type":so},t]},parseMarkdown:{match:({type:e})=>e==="footnoteReference",runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===so,runner:(e,t)=>{e.addNode("footnoteReference",void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));q(ua.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});q(ua.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var da=bt.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 ot(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()}}}});q(da.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});q(da.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var qc=ue(()=>new Ye(/^\[(?<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}));q(qc,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var sg=[oa,ia].flat(),ag=[Hc,qc],lg=[ra],ig=[Fc],Wc=Q(()=>eg);q(Wc,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var cg=Q(()=>_h({}));q(cg,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var Uc=Q(()=>Wh({allowTableNodeSelection:!0}));q(Uc,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var Pt=ve("remarkGFM",()=>Xo);q(Pt.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});q(Pt.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var ug=new fe("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function dg(e,t){let n=0;return t.forEach((r,o,s)=>{r===e&&(n=s)}),n}var Vc=Q(()=>new Z({key:ug,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=dg(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}}));q(Vc,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var fg=[Vc,Wc,Pt,Uc].flat(),pg=[da,pt,Un,cn,tn,Vn,ca,ua,na,ln].flat(),mg=[aa,sa,la,Ic,Lc,Rc,$c,Dc,_c,zc,Bc,Kc,Oc,Pc,jc,Tn],hg=[pg,ag,ig,lg,sg,mg,fg].flat();function gg(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 bg=1,yg=2,Io=e=>`&#x${e.toString(16).toUpperCase()};`,fa=e=>e>=55296&&e<=57343,wr=e=>!Number.isNaN(e)&&!fa(e)&&Si(e)&&Qo(e)===void 0;function Sl(e,t,n){return t===126||t===95?!0:t===42?Ro(e,n)!=="punct":!1}function Ml(e,t){const n=Qo(t);return n===bg?{inside:!0,outside:wr(e)}:n===yg?{inside:!1,outside:wr(e)}:{inside:!1,outside:!1}}const Gc=/(?:https?:\/\/|www\.)[^\s<]*$/i,Jc=/^(?:https?:\/\/|www\.)/i,Yc=(e,t,n)=>e?.children?.[t.indexStack[t.indexStack.length-1]+n],Xc=(e,t)=>{const n=Yc(e,t,-1);return n?.type==="text"&&(n.value.charAt(n.value.length-2)==="\\"||Gc.test(n.value))},Qc=(e,t)=>{const n=Yc(e,t,1);return n?.type==="text"&&Jc.test(n.value)},pa=new Set(["delete","strong","emphasis"]),nn=e=>Array.isArray(e?.children)&&e.children.every(t=>t.type==="text"?!t.value:pa.has(t.type)&&nn(t));let Bt=!1;function kg(e){Bt=!0;try{return e()}finally{Bt=!1}}const Al={inside:!1,outside:!1},Zc=(e,t,n,r)=>{if(nn(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=Bt?Al:Ml(r.before.charCodeAt(r.before.length-1),i);c.inside&&(l=Io(i)+l.slice(1));const u=l.charCodeAt(l.length-1),d=Bt?Al:Ml(r.after.charCodeAt(0),u);d.inside&&(l=l.slice(0,-1)+Io(u));const f=o.move("~~");return s(),n.attentionEncodeSurroundingInfo={after:d.outside&&!Qc(t,n),before:c.outside&&!Xc(t,n)},a+l+f};Zc.peek=e=>nn(e)?"":"~";function eu(e){const t=(n,r,o,s)=>{if(nn(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&&(Bt||Sl(n,c,!1)||Xc(r,o)||!wr(s.before.charCodeAt(s.before.length-1)))&&(l.before=!1),l.after&&(Bt||Sl(n,u,!0)||Qc(r,o)||!wr(s.after.charCodeAt(0)))&&(l.after=!1)}return a};return t.peek=(n,r,o)=>nn(n)?"":e.peek(n,r,o),t}const wg=eu(Zt.strong),xg=eu(Zt.emphasis);function vg(e){const t=[];for(const n of e.children){const r=t[t.length-1];r&&pa.has(n.type)&&n.type===r.type?r.children=[...r.children,...n.children]:t.push(n)}return t}const Lo=new Set(["strong","emphasis"]),tu=e=>e.type==="text"?!e.value:pa.has(e.type)&&nn(e);function nu(e,t){let n=e;for(;;){const r=n.children??[];let o=t?r.length-1:0;for(;o>=0&&o<r.length&&tu(r[o]);)o+=t?-1:1;if(o<0||o>=r.length)return null;if(!Lo.has(r[o].type))return{host:n,index:o};n=r[o]}}function Ro(e,t){const n=nu(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(Qo(s)!==void 0)return"punct";const a=t?o.codePointAt(o.length-(o.length>1&&fa(s)?2:1)):o.codePointAt(0);return!Si(a)||(t?Gc.test(o):Jc.test(o))?"ok":"letter"}function Nl(e,t){const n=nu(e,t);if(!n)return!1;const r=n.host.children,o=r[n.index].value,s=t?o.length-(o.length>1&&fa(o.charCodeAt(o.length-1))?2:1):0,a=o.codePointAt(s),l=[{type:"text",value:o.slice(0,s)},{type:$o,value:Io(a)},{type:"text",value:o.slice(s+(a>65535?2:1))}];return r.splice(n.index,1,...l.filter(i=>i.type===$o||i.value)),!0}const $o="amadeusCharRef",ru=e=>e.value;ru.peek=()=>"&";function ou(e){if(Array.isArray(e?.children)){e.children=vg(e);for(let t=!Bt;t;){t=!1;const n=e.children.filter(r=>!tu(r));for(let r=1;r<n.length;r++){const[o,s]=[n[r-1],n[r]];if(!Lo.has(o.type)||!Lo.has(s.type))continue;const a=Ro(o,!0),l=Ro(s,!1);if(a==="letter"&&l==="punct"?t=Nl(o,!0):a==="punct"&&l==="letter"&&(t=Nl(s,!1)),t)break}}for(const t of e.children)ou(t)}}const Cg=(e,t,n,r)=>(ou(e),Zt.root(e,t,n,r)),Sg=gg,Mg={root:Cg,text:Sg,delete:Zc,strong:wg,emphasis:xg,[$o]:ru},Ag=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,...Mg}}))});function Ng(){Ef.call(this),Tf.call(this,{singleTilde:!1})}const Eg=ve("amadeusCjkFriendly",()=>Ng),In="amadeusU",Ln="amadeusFg",Rn="amadeusBg",ma="amadeusKbd",ha="amadeusSub",ga="amadeusSup",ba=new Map([["kbd",ma],["sub",ha],["sup",ga]]),xr=e=>/^(#[0-9a-fA-F]{3,8}|rgba?\([\d.,%\s/]+\)|hsla?\([\d.,%\s/]+\)|[a-zA-Z]+|var\(--[\w-]+\))$/.test(e.trim());function su(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<u>$/i.test(t))return{type:In};const n=/^<([a-z]+)>$/.exec(t),r=n&&ba.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 xr(s)?{type:Ln,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&&!xr(s)?null:{type:Rn,bg:s}}return null}function au(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<\/u>$/i.test(t))return In;if(/^<\/span>$/i.test(t))return Ln;if(/^<\/mark>$/i.test(t))return Rn;const n=/^<\/([a-z]+)>$/.exec(t);return n&&ba.get(n[1])||null}const Tg=16,El=new Set(ba.values()),Ig=new Set(["paragraph","heading","tableCell"]);function Lg(e){const t=new Map,n=new Set,r=o=>{for(const s of o){const a=su(s)?.type;if(a&&El.has(a)){const i=(t.get(a)??0)+1;t.set(a,i),i>1&&n.add(a);continue}const l=au(s);if(l&&El.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 lu(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=su(s),l=a&&!t.has(a.type)?a:null,i=au(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>=Tg)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=Ig.has(s.type)?new Set([...t,...Lg(s.children)]):t;s.children=lu(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 Wt(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 Rg(){const e=this.data();return(e.toMarkdownExtensions||=[]).push({handlers:{[In]:Wt(()=>"<u>","</u>"),[Ln]:Wt(n=>`<span style="color:${n.color}">`,"</span>"),[Rn]:Wt(n=>n.bg?`<mark style="background:${n.bg}">`:"<mark>","</mark>"),[ma]:Wt(()=>"<kbd>","</kbd>"),[ha]:Wt(()=>"<sub>","</sub>"),[ga]:Wt(()=>"<sup>","</sup>")}}),n=>{Array.isArray(n?.children)&&(n.children=lu(n.children))}}const $g=ve("amadeusInlineHtmlMarks",()=>Rg),iu=at("amadeusUnderline",()=>({parseDOM:[{tag:"u"}],toDOM:()=>["u",0],parseMarkdown:{match:e=>e.type===In,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,In)}}}));function ya(e,t,n){return at(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 Dg=ya("amadeusKbd","kbd",ma),_g=ya("amadeusSub","sub",ha),zg=ya("amadeusSup","sup",ga),ka={"#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"},wa={"#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 cu(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 uu=e=>{const t={};for(const[n,r]of Object.entries(e))r in t||(t[r]=n);return t},Og=uu(ka),Pg=uu(wa),du=(e,t,n,r)=>{const o=cu(r);return o&&e[o]&&(!n||e[o]===n)?o:n&&t[n]?t[n]:null};function Bg(e){const t=e.getAttribute("data-amx-fg");if(t&&xr(t))return{color:t};if(!e.style.color)return!1;const n=du(ka,Og,e.getAttribute("data-hlc"),e.style.color);return n?{color:n}:!1}function Kg(e){const t=e.getAttribute("data-amx-bg");return t!==null&&(t===""||xr(t))?{bg:t}:{bg:du(wa,Pg,e.getAttribute("data-hl"),e.style.backgroundColor)??""}}const fu=(e,t)=>e[cu(t)??t.toLowerCase()],Do=at("amadeusColor",()=>({attrs:{color:{default:""}},parseDOM:[{tag:'span[style*="color"]',getAttrs:e=>Bg(e)}],toDOM:e=>{const t=String(e.attrs.color),n=fu(ka,t);return["span",{style:`color:${t}`,"data-amx-fg":t,...n?{"data-hlc":n}:{}},0]},parseMarkdown:{match:e=>e.type===Ln,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,Ln,void 0,{color:t.attrs.color})}}})),_o=at("amadeusBg",()=>({attrs:{bg:{default:""}},parseDOM:[{tag:"mark",getAttrs:e=>Kg(e)}],toDOM:e=>{const t=String(e.attrs.bg);if(!t)return["mark",{"data-amx-bg":""},0];const n=fu(wa,t);return["mark",{style:`background:${t}`,"data-amx-bg":t,...n?{"data-hl":n}:{}},0]},parseMarkdown:{match:e=>e.type===Rn,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,Rn,void 0,{bg:t.attrs.bg})}}})),ao=F("AmadeusToggleUnderline",e=>()=>On(iu.type(e)));function pu(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 mu(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 Tl=F("AmadeusApplyColor",e=>t=>t?pu(Do.type(e),{color:t}):mu(Do.type(e))),Il=F("AmadeusApplyBg",e=>t=>t?pu(_o.type(e),{bg:t}):mu(_o.type(e)));De({"obsinline.comment.title":{zh:"注释(点击编辑)",en:"Comment (click to edit)"}});function hu(e){if(e.indexOf("%%")===-1&&e.indexOf("==")===-1)return[];let t=e;for(const o of Wi(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 wt=new fe("amadeus-obsidian-inline");function jg(e,t){const n=document.createElement("span");return n.className="amx-obs-cmt-badge",n.contentEditable="false",n.textContent="%%",n.title=O("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(j.create(e.state.doc,o)).setMeta(wt,{focus:!0})),e.focus()}),n}function Hg(e){const t=wt.getState(e)?.focus??!1,{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 hu(Dr(s))){const u=i+c.from,d=i+c.to,f=t&&n<=d&&r>=u;if(c.kind==="hl"){o.push(J.inline(u+2,d-2,{class:"amx-obs-hl"}));const m=f?"amx-obs-delim":"amx-obs-hidden";o.push(J.inline(u,u+2,{class:m}),J.inline(d-2,d,{class:m}))}else f?o.push(J.inline(u,d,{class:"amx-obs-cmt"})):(o.push(J.inline(u,d,{class:"amx-obs-hidden"})),o.push(J.widget(u,m=>jg(m,u+2),{side:-1,ignoreSelection:!0,key:`obs-cmt:${u}`})))}return!1}),o.length?me.create(e.doc,o):me.empty}function Fg(){return Q(()=>new Z({key:wt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(wt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{handleDOMEvents:{focus:e=>(wt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(wt,{focus:!0})),!1),blur:e=>(wt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(wt,{focus:!1})),!1)},decorations:e=>Hg(e)}}))}const qg=(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=hu(Dr(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,`
3
+ `):t.addNode("break")}}}));v(Ye.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});v(Ye.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var Is=F("InsertHardbreak",e=>()=>(t,n)=>{const{selection:r,tr:o}=t;if(!(r instanceof j))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(ce.near(o.doc.resolve(r.to))).scrollIntoView()),!0}return n?.(o.setMeta("hardbreak",!0).replaceSelectionWith(Ye.type(e).create()).scrollIntoView()),!0});v(Is,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Ls=_e("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:e=>{const t=e.get(se);return()=>t.call(Is.key)}}});v(Ls.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});v(Ls.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Rs=Xe("hr");v(Rs,{displayName:"Attr<hr>",group:"Hr"});var Hn=Ee("hr",e=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:t=>["hr",e.get(Rs.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(Hn.node,{displayName:"NodeSchema<hr>",group:"Hr"});v(Hn.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var lc=ue(e=>new Je(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,o)=>{const{tr:s}=t;return n[0]&&s.replaceWith(r-1,o,Hn.type(e).create()),s}));v(lc,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var ic=F("InsertHr",e=>()=>(t,n)=>{if(!n)return!0;const r=Be.node.type(e).create(),{tr:o,selection:s}=t,{from:a}=s,l=Hn.type(e).create();if(!l)return!0;const i=o.replaceSelectionWith(l).insert(a,r),c=ce.findFrom(i.doc.resolve(a),1,!0);return c&&n(i.setSelection(c).scrollIntoView()),!0});v(ic,{displayName:"Command<insertHrCommand>",group:"Hr"});var Fr=Xe("bulletList");v(Fr,{displayName:"Attr<bulletList>",group:"BulletList"});var mt=Ee("bullet_list",e=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:t=>{if(!(t instanceof HTMLElement))throw ot(t);return{spread:t.dataset.spread==="true"}}}],toDOM:t=>["ul",{...e.get(Fr.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(mt.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});v(mt.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var cc=ue(e=>os(/^\s*([-+*])\s$/,mt.type(e)));v(cc,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var $s=F("WrapInBulletList",e=>()=>rs(mt.type(e)));v($s,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Ds=_e("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:e=>{const t=e.get(se);return()=>t.call($s.key)}}});v(Ds.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});v(Ds.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var qr=Xe("orderedList");v(qr,{displayName:"Attr<orderedList>",group:"OrderedList"});var ht=Ee("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 ot(t);return{spread:t.dataset.spread,order:t.hasAttribute("start")?Number(t.getAttribute("start")):1}}}],toDOM:t=>["ol",{...e.get(qr.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(ht.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});v(ht.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var uc=ue(e=>os(/^\s*(\d+)\.\s$/,ht.type(e),t=>({order:Number(t[1])}),(t,n)=>n.childCount+n.attrs.order===Number(t[1])));v(uc,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var _s=F("WrapInOrderedList",e=>()=>rs(ht.type(e)));v(_s,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var zs=_e("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:e=>{const t=e.get(se);return()=>t.call(_s.key)}}});v(zs.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});v(zs.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var Os=Xe("listItem");v(Os,{displayName:"Attr<listItem>",group:"ListItem"});var bt=Ee("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 ot(t);return{label:t.dataset.label,listType:t.dataset.listType,spread:t.dataset.spread==="true"}}}],toDOM:t=>["li",{...e.get(Os.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(bt.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});v(bt.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Ps=F("SinkListItem",e=>()=>Qi(bt.type(e)));v(Ps,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var Bs=F("LiftListItem",e=>()=>Xi(bt.type(e)));v(Bs,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var Ks=F("SplitListItem",e=>()=>bm(bt.type(e)));v(Ks,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function Em(e){return(t,n,r)=>{const{selection:o}=t;if(!(o instanceof j))return!1;const{empty:s,$from:a}=o;return!s||a.parentOffset!==0||a.node(-1).type!==bt.type(e)?!1:kf(t,n,r)}}var js=F("LiftFirstListItem",e=>()=>Em(e));v(js,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Hs=_e("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:e=>{const t=e.get(se);return()=>t.call(Ks.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:e=>{const t=e.get(se);return()=>t.call(Ps.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:e=>{const t=e.get(se);return()=>t.call(Bs.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:e=>{const t=e.get(se);return()=>t.call(js.key)}}});v(Hs.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});v(Hs.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var dc=ss("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(dc,{displayName:"NodeSchema<text>",group:"Text"});var Fs=Xe("html");v(Fs,{displayName:"Attr<html>",group:"Html"});var qs=Ee("html",e=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:t=>{const n=document.createElement("span"),r={...e.get(Fs.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(qs.node,{displayName:"NodeSchema<html>",group:"Html"});v(qs.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var Tm=[ks,Kr,Be,Kn,jr,rt,yr,Ye,Hr,At,As,jn,Rs,Hn,Ts,an,Fr,mt,qr,ht,Os,bt,cs,Et,ps,sn,gs,dt,Pr,Ge,Fs,qs,dc].flat(),Im=[rc,cc,uc,oc,lc,nc].flat(),Lm=[us,ds,bs,ms],Rm=F("IsMarkSelected",()=>e=>t=>{if(!e)return!1;const{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),$m=F("IsNoteSelected",()=>e=>t=>e?xf(t,e).hasNode:!1),Dm=F("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)}),_m=F("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}),zm=F("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&&wo(i,r,o);if(!c)return!1;s=s.wrap(i,c)}catch{return!1}return n?.(s),!0}),Om=F("AddBlockType",()=>e=>(t,n)=>{const{nodeType:r,attrs:o=null}=e??{};if(!r)return!1;const s=t.tr;try{const a=r instanceof vf?r:r.createAndFill(o);if(!a)return!1;s.replaceSelectionWith(a)}catch{return!1}return n?.(s),!0}),Pm=F("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(j.near(a))}catch{return!1}return n?.(s.scrollIntoView()),!0}),Bm=[ws,Ss,kt,vs,Ns,Is,ic,sc,ac,_s,$s,Ps,Ks,Bs,js,_r,Or,zr,ec,tc,Rm,$m,Dm,_m,zm,Om,Pm],Km=[Ms,Es,Ls,Cs,Hs,zs,Ds,xs,fs,ys,hs].flat(),Wr=ve("remarkAddOrderInList",()=>()=>e=>{zn(e,"list",t=>{if(t.ordered){const n=t.start??1;t.children.forEach((r,o)=>{r.label=o+n})}})});v(Wr.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});v(Wr.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var Ws=ve("remarkLineBreak",()=>()=>e=>{const t=/[\t ]*(?:\r?\n|\r)/g;zn(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(Ws.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});v(Ws.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Us=ve("remarkInlineLink",()=>xm);v(Us.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});v(Us.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var jm=e=>!!e.children,Hm=e=>e.type==="html";function Fm(e,t){return n(e,0,null)[0];function n(r,o,s){if(jm(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 qm=["root","blockquote","listItem"],Vs=ve("remarkHTMLTransformer",()=>()=>e=>{Fm(e,(t,n,r)=>Hm(t)?(r&&qm.includes(r.type)&&(t.children=[{...t}],delete t.value,t.type="paragraph"),[t]):[t])});v(Vs.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});v(Vs.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var Gs=ve("remarkMarker",()=>()=>(e,t)=>{const n=r=>t.value.charAt(r.position.start.offset);zn(e,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});v(Gs.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});v(Gs.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var fc=Q(()=>{let e=!1;const t=new Z({key:new fe("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=Y.widget(r,o,{side:-1}),a=document.createElement("span"),l=Y.widget(r,a);return setTimeout(()=>{o.contentEditable="true",a.contentEditable="true"}),me.create(n.doc,[s,l])}return me.empty}}});return t});v(fc,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Ys=Q(e=>new Z({key:new fe("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 Di))return;const{from:a}=s;return r.tr.setNodeMarkup(a,Ye.type(e),void 0,[])}if(s instanceof _i){let a=r.tr;const{from:l,to:i}=s;return r.doc.nodesBetween(l,i,(c,u)=>{c.type===Ye.type(e)&&(a=a.setNodeMarkup(u,Ye.type(e),void 0,[]))}),a}}}));v(Ys,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var Js=as(["table","code_block"],"hardbreakFilterNodes");v(Js,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var pc=Q(e=>{const t=e.get(Js.key);return new Z({key:new fe("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(pc,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var mc=Q(e=>{const t=new fe("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;const o=e.get(Kn.key),s=r.state.tr.setMeta("addToHistory",!1);let a=!1;const l={};r.state.doc.descendants((i,c)=>{if(i.type===rt.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 Z({key:t,view:r=>(n(r),{update:(o,s)=>{o.state.doc.eq(s.doc)||n(o)}})})});v(mc,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var hc=Q(e=>{const t=(n,r,o)=>{if(!o.selection||n.some(d=>d.getMeta("addToHistory")===!1||!d.isGeneric))return null;const s=ht.type(e),a=mt.type(e),l=bt.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,w,y,C)=>{if(g.type===l){const N={...g.attrs};i(N,C)&&(c=c.setNodeMarkup(w,void 0,N))}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 Z({key:new fe("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:t})});v(hc,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Wm=[Ys,Js,pc,fc,Wr,Us,Ws,Vs,Gs,Br,mc,hc].flat(),Um=[Tm,Im,Lm,Bm,Km,Wm].flat();let So,Mo;if(typeof WeakMap<"u"){let e=new WeakMap;So=t=>e.get(t),Mo=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;So=r=>{for(let o=0;o<e.length;o+=2)if(e[o]==r)return e[o+1]},Mo=(r,o)=>(n==10&&(n=0),e[n++]=r,e[n++]=o)}var J=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 So(e)||Mo(e,Vm(e))}};function Vm(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=Gm(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:w,colwidth:y}=h.attrs;for(let C=0;C<w;C++){if(C+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-C});break}const N=o+C*t;for(let M=0;M<g;M++){r[N+M]==0?r[N+M]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:g-M});const T=y&&y[M];if(T){const D=(N+M)%t*2,H=a[D];H==null||H!=T&&a[D+1]==1?(a[D]=T,a[D+1]=1):H==T&&a[D+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 J(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&&Ym(l,a,e),l}function Gm(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 Ym(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=Jm(i)))[c]=u)}l&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Jm(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function ul(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 dl(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 Xm(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 Qm(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Xm}};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=>ul(r,t)}],toDOM(r){return["td",dl(r,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ul(r,t)}],toDOM(r){return["th",dl(r,t),0]}}}}function qe(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 vt=new fe("selectingCells");function zt(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 Ke(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 Fn(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=zt(t.$head)||Zm(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function Zm(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 Ao(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function eh(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Xs(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function gc(e,t,n){const r=e.node(-1),o=J.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 Ot(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 th(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 nh(e,t,n){const r=qe(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 de=class ut extends ce{constructor(t,n=t){const r=t.node(-1),o=J.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 Sf(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(Ao(r)&&Ao(o)&&Xs(r,o)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?ut.rowSelection(r,o):s&&this.isColSelection()?ut.colSelection(r,o):new ut(r,o)}return j.between(r,o)}content(){const t=this.$anchorCell.node(-1),n=J.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 w=p.attrs;if(h>0&&(w=Ot(w,0,h)),g>0&&(w=Ot(w,w.colspan-g,g)),m.left<o.left){if(p=p.type.createAndFill(w),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(w)}`)}else p=p.type.create(w,p.content)}if(m.top<o.top||m.bottom>o.bottom){const w={...p.attrs,rowspan:Math.min(m.bottom,o.bottom)-Math.max(m.top,o.top)};m.top<o.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}a.push(t.child(i).copy(X.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?t:a;return new Ie(X.from(l),1,1)}replace(t,n=Ie.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?Ie.empty:n)}const s=ce.findFrom(t.doc.resolve(t.mapping.slice(r).map(this.to)),-1);s&&t.setSelection(s)}replaceWith(t,n){this.replace(t,new Ie(X.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=J.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=J.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 ut(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=J.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 ut&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),o=J.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 ut(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new ut(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new ut(t.resolve(n),t.resolve(r))}getBookmark(){return new rh(this.$anchorCell.pos,this.$headCell.pos)}};de.prototype.visible=!1;ce.jsonID("cell",de);var rh=class bc{constructor(t,n){this.anchor=t,this.head=n}map(t){return new bc(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&&Xs(n,r)?new de(n,r):ce.near(r,1)}};function oh(e){if(!(e.selection instanceof de))return null;const t=[];return e.selection.forEachCell((n,r)=>{t.push(Y.node(r,r+n.nodeSize,{class:"selectedCell"}))}),me.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 lh(e,t,n){const r=(t||e).selection,o=(t||e).doc;let s,a;if(r instanceof Ve&&(a=r.node.type.spec.tableRole)){if(a=="cell"||a=="header_cell")s=de.create(o,r.from);else if(a=="row"){const l=o.resolve(r.from+1);s=de.rowSelection(l,l)}else if(!n){const l=J.get(r.node),i=r.from+1,c=i+l.map[l.width*l.height-1];s=de.create(o,i+1,c)}}else r instanceof j&&sh(r)?s=j.create(o,r.from):r instanceof j&&ah(r)&&(s=j.create(o,r.$from.start(),r.$from.end()));return s&&(t||(t=e.tr)).setSelection(s),t}const ih=new fe("fix-tables");function yc(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)?yc(e.child(l),i,n+1,r):i.nodesBetween(0,i.content.size,r,n+1),n+=i.nodeSize}}function ch(e,t){let n;const r=(o,s)=>{o.type.spec.tableRole=="table"&&(n=uh(e,o,s,n))};return t?t.doc!=e.doc&&yc(t.doc,e.doc,0,r):e.doc.descendants(r),n}function uh(e,t,n,r){const o=J.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,Ot(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 w=qe(e.schema)[m].createAndFill();w&&p.push(w)}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(ih,{fixTables:!0})}function kc(e){const t=J.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 wc(e,t){const n=[],r=J.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 xc(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 dh(t=>t.type.spec.tableRole==="table",e)}function dh(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 Gt(e,t){const n=qn(t.$from);if(!n)return;const r=J.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 Yt(e,t){const n=qn(t.$from);if(!n)return;const r=J.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 fl(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=Gt(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=Gt(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=Gt(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=Gt(r,e.selection),l=Yt(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=Gt(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 pl(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=Yt(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=Yt(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=Yt(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=Yt(r,e.selection),l=Gt(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=Yt(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){return e[0].map((t,n)=>e.map(r=>r[n]))}function fh(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=fl(r,o))===null||t===void 0?void 0:t.indexes,u=(n=fl(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=ph(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=J.get(d),m=i.start,p=s,h=f.positionAt(f.height-1,p,d),g=r.doc.resolve(m+h),w=f.positionAt(0,p,d),y=r.doc.resolve(m+w);return r.setSelection(de.colSelection(g,y)),!0}function ph(e,t,n,r){let o=ml(kc(e));return o=xc(o,t,n),o=ml(o),wc(e,o)}function mh(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=hh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=J.get(d),m=i.start,p=s,h=f.positionAt(p,f.width-1,d),g=r.doc.resolve(m+h),w=f.positionAt(p,0,d),y=r.doc.resolve(m+w);return r.setSelection(de.rowSelection(g,y)),!0}function hh(e,t,n,r){let o=kc(e);return o=xc(o,t,n),wc(e,o)}function Tt(e){const t=e.selection,n=Fn(e),r=n.node(-1),o=n.start(-1),s=J.get(r);return{...t instanceof de?s.rectBetween(t.$anchorCell.pos-o,t.$headCell.pos-o):s.findCell(n.pos-o),tableStart:o,map:s,table:r}}function Qs(e,{map:t,tableStart:n,table:r},o){let s=o>0?-1:0;nh(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,th(c.attrs,o-t.colCount(i))),a+=c.attrs.rowspan-1}else{const i=s==null?qe(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 gh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e);t(Qs(e.tr,n,n.left))}return!0}function bh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e);t(Qs(e.tr,n,n.right))}return!0}function vc(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,Ot(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 yh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let o=n.right-1;vc(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=J.get(s)}t(r)}return!0}function Cc(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 kh(e,t){if(!Ke(e))return!1;if(t){const n=Tt(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let o=n.bottom-1;Cc(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=J.get(n.table)}t(r)}return!0}function wh(e,t){return function(n,r){if(!Ke(n))return!1;const o=Fn(n);if(o.nodeAfter.attrs[e]===t)return!1;if(r){const s=n.tr;n.selection instanceof de?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 xh(e){return function(t,n){if(!Ke(t))return!1;if(n){const r=qe(t.schema),o=Tt(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 hl(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 Zs(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?xh(e):function(n,r){if(!Ke(n))return!1;if(r){const o=qe(n.schema),s=Tt(n),a=n.tr,l=hl("row",s,o),i=hl("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}}Zs("row",{useDeprecatedLogic:!0});Zs("column",{useDeprecatedLogic:!0});Zs("cell",{useDeprecatedLogic:!0});function vh(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 ea(e){return function(t,n){if(!Ke(t))return!1;const r=vh(Fn(t),e);if(r==null)return!1;if(n){const o=t.doc.resolve(r);n(t.tr.setSelection(j.between(o,eh(o))).scrollIntoView())}return!0}}function Ch(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 tr(e,t){const n=e.selection;if(!(n instanceof de))return!1;if(t){const r=e.tr,o=qe(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 Ie(o,0,0))}),r.docChanged&&t(r)}return!0}function Sh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return mh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function Mh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return fh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function Ah(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=No(qe(a).row,new Ie(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(n||r?No(qe(a).row,new Ie(t,n,r)).content:t);else return null;return Nh(a,l)}function Nh(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(X.empty),n[o]<r){const s=qe(e).cell.createAndFill(),a=[];for(let l=n[o];l<r;l++)a.push(s);t[o]=t[o].append(X.from(a))}return{height:t.length,width:r,rows:t}}function No(e,t){const n=e.createAndFill();return new Mf(n).replace(0,n.content.size,t).doc}function Eh({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(Ot(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(X.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(X.from(i))}n=s,t=o}return{width:e,height:t,rows:n}}function Th(e,t,n,r,o,s,a){const l=e.doc.type.schema,i=qe(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,X.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 gl(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 bl(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,Ot(f.attrs,a-m,f.attrs.colspan-(a-m))),e.insert(p+f.nodeSize,f.type.createAndFill(Ot(f.attrs,0,a-m))),c+=f.attrs.rowspan-1}}return i}function yl(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=J.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=J.get(s),f=d.mapping.maps.length}Th(d,a,s,n,c,u,f)&&m(),gl(d,a,s,n,i,c,l,f)&&m(),gl(d,a,s,n,i,c,u,f)&&m(),bl(d,a,s,n,l,u,i,f)&&m(),bl(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 Ie(o.rows[p-l],0,0))}m(),d.setSelection(new de(d.doc.resolve(n+a.positionAt(l,i,s)),d.doc.resolve(n+a.positionAt(u-1,c-1,s)))),t(d)}const Ih=Cf({ArrowLeft:nr("horiz",-1),ArrowRight:nr("horiz",1),ArrowUp:nr("vert",-1),ArrowDown:nr("vert",1),"Shift-ArrowLeft":rr("horiz",-1),"Shift-ArrowRight":rr("horiz",1),"Shift-ArrowUp":rr("vert",-1),"Shift-ArrowDown":rr("vert",1),Backspace:tr,"Mod-Backspace":tr,Delete:tr,"Mod-Delete":tr});function lr(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function nr(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;if(s instanceof de)return lr(n,r,ce.near(s.$headCell,t));if(e!="horiz"&&!s.empty)return!1;const a=Sc(o,e,t);if(a==null)return!1;if(e=="horiz")return lr(n,r,ce.near(n.doc.resolve(s.head+t),t));{const l=n.doc.resolve(a),i=gc(l,e,t);let c;return i?c=ce.near(i,1):t<0?c=ce.near(n.doc.resolve(l.before(-1)),-1):c=ce.near(n.doc.resolve(l.after(-1)),1),lr(n,r,c)}}}function rr(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;let a;if(s instanceof de)a=s;else{const i=Sc(o,e,t);if(i==null)return!1;a=new de(n.doc.resolve(i))}const l=gc(a.$headCell,e,t);return l?lr(n,r,new de(a.$anchorCell,l)):!1}}function Lh(e,t){const n=e.state.doc,r=zt(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new de(r))),!0):!1}function Rh(e,t,n){if(!Ke(e.state))return!1;let r=Ah(n);const o=e.state.selection;if(o instanceof de){r||(r={width:1,height:1,rows:[X.from(No(qe(e.state.schema).cell,n))]});const s=o.$anchorCell.node(-1),a=o.$anchorCell.start(-1),l=J.get(s).rectBetween(o.$anchorCell.pos-a,o.$headCell.pos-a);return r=Eh(r,l.right-l.left,l.bottom-l.top),yl(e.state,e.dispatch,a,l,r),!0}else if(r){const s=Fn(e.state),a=s.start(-1);return yl(e.state,e.dispatch,a,J.get(s.node(-1)).findCell(s.pos-a),r),!0}else return!1}function $h(e,t){var n;if(t.button!=0||t.ctrlKey||t.metaKey)return;const r=kl(e,t.target);let o;if(t.shiftKey&&e.state.selection instanceof de)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&r&&(o=zt(e.state.selection.$anchor))!=null&&((n=ro(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=ro(e,c);const d=vt.getState(e.state)==null;if(!u||!Xs(i,u))if(d)u=i;else return;const f=new de(i,u);if(d||!e.state.selection.eq(f)){const m=e.state.tr.setSelection(f);d&&m.setMeta(vt,i.pos),e.dispatch(m)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",l),vt.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(vt,-1))}function l(i){const c=i,u=vt.getState(e.state);let d;if(u!=null)d=e.state.doc.resolve(u);else if(kl(e,c.target)!=r&&(d=ro(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 Sc(e,t,n){if(!(e.state.selection instanceof j))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 kl(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function ro(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&&zt(e.state.doc.resolve(r))||zt(e.state.doc.resolve(o))}var Dh=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")),Eo(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,Eo(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function Eo(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],w=g?g+"px":"";if(a+=g||r,g||(l=!1),i)i.style.width!=w&&(i.style.width=w),i=i.nextSibling;else{const y=document.createElement("col");y.style.width=w,t.appendChild(y)}}}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 Pe=new fe("tableColumnResizing");function _h({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Dh,lastColumnResizable:o=!0}={}){const s=new Z({key:Pe,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=qe(l.schema).table.name;return r&&c&&(c[u]=(d,f)=>new r(d,n,f)),new zh(-1,!1)},apply(a,l){return l.apply(a)}},props:{attributes:a=>{const l=Pe.getState(a);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,l)=>{Oh(a,l,e,o)},mouseleave:a=>{Ph(a)},mousedown:(a,l)=>{Bh(a,l,t,n)}},decorations:a=>{const l=Pe.getState(a);if(l&&l.activeHandle>-1)return qh(a,l.activeHandle)},nodeViews:{}}});return s}var zh=class ir{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(Pe);if(r&&r.setHandle!=null)return new ir(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ir(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return Ao(t.doc.resolve(o))||(o=-1),new ir(o,n.dragging)}return n}};function Oh(e,t,n,r){if(!e.editable)return;const o=Pe.getState(e.state);if(o&&!o.dragging){const s=jh(t.target);let a=-1;if(s){const{left:l,right:i}=s.getBoundingClientRect();t.clientX-l<=n?a=wl(e,t,"left",n):i-t.clientX<=n&&(a=wl(e,t,"right",n))}if(a!=o.activeHandle){if(!r&&a!==-1){const l=e.state.doc.resolve(a),i=l.node(-1),c=J.get(i),u=l.start(-1);if(c.colCount(l.pos-u)+l.nodeAfter.attrs.colspan-1==c.width-1)return}Mc(e,a)}}}function Ph(e){if(!e.editable)return;const t=Pe.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Mc(e,-1)}function Bh(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=Pe.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const l=e.state.doc.nodeAt(a.activeHandle),i=Kh(e,a.activeHandle,l.attrs);e.dispatch(e.state.tr.setMeta(Pe,{setDragging:{startX:t.clientX,startWidth:i}}));function c(d){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=Pe.getState(e.state);f?.dragging&&(Hh(e,f.activeHandle,xl(f.dragging,d,n)),e.dispatch(e.state.tr.setMeta(Pe,{setDragging:null})))}function u(d){if(!d.which)return c(d);const f=Pe.getState(e.state);if(f&&f.dragging){const m=xl(f.dragging,d,n);vl(e,f.activeHandle,m,r)}}return vl(e,a.activeHandle,i,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),t.preventDefault(),!0}function Kh(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 jh(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function wl(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=zt(e.state.doc.resolve(a));if(!l)return-1;if(n=="right")return l.pos;const i=J.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 xl(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Mc(e,t){e.dispatch(e.state.tr.setMeta(Pe,{setHandle:t}))}function Hh(e,t,n){const r=e.state.doc.resolve(t),o=r.node(-1),s=J.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():Fh(f.colspan);p[m]=n,i.setNodeMarkup(a+d,null,{...f,colwidth:p})}i.docChanged&&e.dispatch(i)}function vl(e,t,n,r){const o=e.state.doc.resolve(t),s=o.node(-1),a=o.start(-1),l=J.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&&Eo(s,i.firstChild,i,r,l,n)}function Fh(e){return Array(e).fill(0)}function qh(e,t){const n=[],r=e.doc.resolve(t),o=r.node(-1);if(!o)return me.empty;const s=J.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=Pe.getState(e))===null||i===void 0)&&i.dragging&&n.push(Y.node(a+d,a+d+o.nodeAt(d).nodeSize,{class:"column-resize-dragging"})),n.push(Y.widget(f,m))}}return me.create(e.doc,n)}function Wh({allowTableNodeSelection:e=!1}={}){return new Z({key:vt,state:{init(){return null},apply(t,n){const r=t.getMeta(vt);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:oh,handleDOMEvents:{mousedown:$h},createSelectionBetween(t){return vt.getState(t.state)!=null?t.state.selection:null},handleTripleClick:Lh,handleKeyDown:Ih,handlePaste:Rh},appendTransaction(t,n,r){return lh(r,ch(r,n),e)}})}var kr=typeof navigator<"u"?navigator:null,ta=kr&&kr.userAgent||"",Uh=/Edge\/(\d+)/.exec(ta),Vh=/MSIE \d/.exec(ta),Gh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ta),Yh=!!(Vh||Gh||Uh),Jh=!Yh&&!!kr&&/Apple Computer/.test(kr.vendor),Ac=new fe("safari-ime-span"),To=!1,Xh={key:Ac,props:{decorations:Qh,handleDOMEvents:{compositionstart:()=>{To=!0},compositionend:()=>{To=!1}}}};function Qh(e){const{$from:t,$to:n,to:r}=e.selection;if(To&&t.sameParent(n)){const o=Y.widget(r,Zh,{ignoreSelection:!0,key:"safari-ime-span"});return me.create(e.doc,[o])}}function Zh(e){const t=e.dom.ownerDocument.createElement("span");return t.className="ProseMirror-safari-ime-span",t}var eg=new Z(Jh?Xh:{key:Ac});function q(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-gfm",...t}}),e}var na=Bn("strike_through");q(na,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var ln=at("strike_through",e=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:t=>t==="line-through"}],toDOM:t=>["del",e.get(na.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")}}}));q(ln.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});q(ln.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Tn=F("ToggleStrikeThrough",e=>()=>On(ln.type(e)));q(Tn,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var ra=ue(e=>st(new RegExp("(?<![\\w:/])(~{1,2})(.+?)\\1(?!\\w|\\/)"),ln.type(e)));q(ra,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var oa=_e("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:e=>{const t=e.get(se);return()=>t.call(Tn.key)}}});q(oa.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});q(oa.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Wn=Qm({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:e=>e.style.textAlign||"left",setDOMAttr:(e,t)=>{t.style=`text-align: ${e||"left"}`}}}}),pt=Ee("table",()=>({...Wn.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()}}}));q(pt.node,{displayName:"NodeSchema<table>",group:"Table"});q(pt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var Un=Ee("table_header_row",()=>({...Wn.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())}}}));q(Un.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});q(Un.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var cn=Ee("table_row",()=>({...Wn.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())}}}));q(cn.node,{displayName:"NodeSchema<tableRow>",group:"Table"});q(cn.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var Vn=Ee("table_cell",()=>({...Wn.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()}}}));q(Vn.node,{displayName:"NodeSchema<tableCell>",group:"Table"});q(Vn.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var tn=Ee("table_header",()=>({...Wn.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()}}}));q(tn.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});q(tn.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function Nc(e,t=3,n=3){const r=Array(n).fill(0).map(()=>Vn.type(e).createAndFill()),o=Array(n).fill(0).map(()=>tn.type(e).createAndFill()),s=Array(t).fill(0).map((a,l)=>l===0?Un.type(e).create(null,o):cn.type(e).create(null,r));return pt.type(e).create(null,s)}function Ec(e){return(t,n)=>r=>{n=n??r.selection.from;const o=r.doc.resolve(n),s=Nf(i=>i.type.name==="table")(o),a=s?{node:s.node,from:s.start}:void 0,l=e==="row";if(a){const i=J.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?de.rowSelection:de.colSelection,f=i.positionAt(l?t:0,l?0:t,a.node),m=r.doc.resolve(a.from+f);return Oi(r.setSelection(d(u,m)))}}return r}}var tg=Ec("row"),ng=Ec("col");function Tc(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 Vn.type(e).createAndFill({alignment:u?.attrs.alignment})});return t.insert(a,cn.type(e).create(null,l)),t}function rg(e){const t=qn(e.$from);if(!t)return;const n=J.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 og(e){const t=rg(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 Oi(e.setSelection(new de(o,n)))}}return e}var sa=F("GoToPrevTableCell",()=>()=>ea(-1));q(sa,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var aa=F("GoToNextTableCell",()=>()=>ea(1));q(aa,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var la=F("ExitTable",e=>()=>(t,n)=>{if(!Ke(t))return!1;const{$head:r}=t.selection,o=Af(r,pt.type(e));if(!o)return!1;const{to:s}=o,a=t.tr.replaceWith(s,s,Be.type(e).createAndFill());return a.setSelection(ce.near(a.doc.resolve(s),1)).scrollIntoView(),n?.(a),!0});q(la,{displayName:"Command<breakTableCommand>",group:"Table"});var Ic=F("InsertTable",e=>({row:t,col:n}={})=>(r,o)=>{const{selection:s,tr:a}=r,{from:l}=s,i=Nc(e,t,n),c=a.replaceSelectionWith(i),u=ce.findFrom(c.doc.resolve(l),1,!0);return u&&c.setSelection(u),o?.(c),!0});q(Ic,{displayName:"Command<insertTableCommand>",group:"Table"});var Lc=F("MoveRow",()=>({from:e,to:t,pos:n}={})=>Sh({from:e??0,to:t??0,pos:n}));q(Lc,{displayName:"Command<moveRowCommand>",group:"Table"});var Rc=F("MoveCol",()=>({from:e,to:t,pos:n}={})=>Mh({from:e??0,to:t??0,pos:n}));q(Rc,{displayName:"Command<moveColCommand>",group:"Table"});var $c=F("SelectRow",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(tg(e.index,e.pos)(r))});q($c,{displayName:"Command<selectRowCommand>",group:"Table"});var Dc=F("SelectCol",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(ng(e.index,e.pos)(r))});q(Dc,{displayName:"Command<selectColCommand>",group:"Table"});var _c=F("SelectTable",()=>()=>(e,t)=>{const{tr:n}=e;return!!t?.(og(n))});q(_c,{displayName:"Command<selectTableCommand>",group:"Table"});var zc=F("DeleteSelectedCells",()=>()=>(e,t)=>{const{selection:n}=e;if(!(n instanceof de))return!1;const r=n.isRowSelection(),o=n.isColSelection();return r&&o?Ch(e,t):o?yh(e,t):kh(e,t)});q(zc,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var Oc=F("AddColBefore",()=>()=>gh);q(Oc,{displayName:"Command<addColBeforeCommand>",group:"Table"});var Pc=F("AddColAfter",()=>()=>bh);q(Pc,{displayName:"Command<addColAfterCommand>",group:"Table"});var Bc=F("AddRowBefore",e=>()=>(t,n)=>{if(!Ke(t))return!1;if(n){const r=Tt(t);n(Tc(e,t.tr,r,r.top))}return!0});q(Bc,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var Kc=F("AddRowAfter",e=>()=>(t,n)=>{if(!Ke(t))return!1;if(n){const r=Tt(t);n(Tc(e,t.tr,r,r.bottom))}return!0});q(Kc,{displayName:"Command<addRowAfterCommand>",group:"Table"});var jc=F("SetAlign",()=>(e="left")=>wh("alignment",e));q(jc,{displayName:"Command<setAlignCommand>",group:"Table"});var Hc=ue(e=>new Je(/^\|(?<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),pt.type(e)))return null;const a=Nc(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),l=t.tr.replaceRangeWith(r,o,a);return l.setSelection(j.create(l.doc,r+3)).scrollIntoView()}));q(Hc,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var Fc=Up(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 Be.type(e).create();const f=c.firstChild;if(!(d>0&&f&&f.childCount===0))return c;if(u>=3){const g=c.child(1),w=[];for(let N=0;N<g.childCount;N++){const M=g.child(N);w.push(tn.type(e).create(M.attrs,M.content,M.marks))}const y=f.type.create(f.attrs,w),C=[];for(let N=2;N<u;N++)C.push(c.child(N));return c.type.create(c.attrs,[y,...C])}const m=Array(d).fill(0).map(()=>tn.type(e).createAndFill()),p=new Ie(X.from(m),0,0),h=f.replace(0,0,p);return c.replace(0,f.nodeSize,new Ie(X.from(h),0,0))}function s(c){const u=cn.type(e),d=[];let f=[],m=!1;function p(){if(f.length===0)return;const h=Un.type(e).createAndFill(),g=pt.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?X.from(d):c}function a(c){let u=s(c),d=u!==c;const f=[];return u.forEach(m=>{if(m.type===pt.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?X.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===Be.type(e)&&m.content.size===0&&p&&p.type===pt.type(e)||u.push(m)}return u.length<d.length?X.from(u):c}let i=a(t.content);return i=l(i),new Ie(X.from(i),t.openStart,t.openEnd)}}));q(Fc,{displayName:"PasteRule<table>",group:"Table"});var ia=_e("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:e=>{const t=e.get(se);return()=>t.call(aa.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:e=>{const t=e.get(se);return()=>t.call(sa.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:e=>{const t=e.get(se);return()=>t.call(la.key)}}});q(ia.ctx,{displayName:"KeymapCtx<table>",group:"Table"});q(ia.shortcuts,{displayName:"Keymap<table>",group:"Table"});var oo="footnote_definition",Cl="footnoteDefinition",ca=Ee("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${oo}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw ot(e);return{label:e.dataset.label}},contentElement:"dd"}],toDOM:e=>{const t=e.attrs.label;return["dl",{"data-label":t,"data-type":oo},["dt",t],["dd",0]]},parseMarkdown:{match:({type:e})=>e===Cl,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===oo,runner:(e,t)=>{e.openNode(Cl,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));q(ca.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});q(ca.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var so="footnote_reference",ua=Ee("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${so}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw ot(e);return{label:e.dataset.label}}}],toDOM:e=>{const t=e.attrs.label;return["sup",{"data-label":t,"data-type":so},t]},parseMarkdown:{match:({type:e})=>e==="footnoteReference",runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===so,runner:(e,t)=>{e.addNode("footnoteReference",void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));q(ua.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});q(ua.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var da=bt.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 ot(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()}}}});q(da.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});q(da.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var qc=ue(()=>new Je(/^\[(?<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}));q(qc,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var sg=[oa,ia].flat(),ag=[Hc,qc],lg=[ra],ig=[Fc],Wc=Q(()=>eg);q(Wc,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var cg=Q(()=>_h({}));q(cg,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var Uc=Q(()=>Wh({allowTableNodeSelection:!0}));q(Uc,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var Pt=ve("remarkGFM",()=>Xo);q(Pt.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});q(Pt.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var ug=new fe("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function dg(e,t){let n=0;return t.forEach((r,o,s)=>{r===e&&(n=s)}),n}var Vc=Q(()=>new Z({key:ug,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=dg(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}}));q(Vc,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var fg=[Vc,Wc,Pt,Uc].flat(),pg=[da,pt,Un,cn,tn,Vn,ca,ua,na,ln].flat(),mg=[aa,sa,la,Ic,Lc,Rc,$c,Dc,_c,zc,Bc,Kc,Oc,Pc,jc,Tn],hg=[pg,ag,ig,lg,sg,mg,fg].flat();function gg(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 bg=1,yg=2,Io=e=>`&#x${e.toString(16).toUpperCase()};`,fa=e=>e>=55296&&e<=57343,wr=e=>!Number.isNaN(e)&&!fa(e)&&Si(e)&&Qo(e)===void 0;function Sl(e,t,n){return t===126||t===95?!0:t===42?Ro(e,n)!=="punct":!1}function Ml(e,t){const n=Qo(t);return n===bg?{inside:!0,outside:wr(e)}:n===yg?{inside:!1,outside:wr(e)}:{inside:!1,outside:!1}}const Gc=/(?:https?:\/\/|www\.)[^\s<]*$/i,Yc=/^(?:https?:\/\/|www\.)/i,Jc=(e,t,n)=>e?.children?.[t.indexStack[t.indexStack.length-1]+n],Xc=(e,t)=>{const n=Jc(e,t,-1);return n?.type==="text"&&(n.value.charAt(n.value.length-2)==="\\"||Gc.test(n.value))},Qc=(e,t)=>{const n=Jc(e,t,1);return n?.type==="text"&&Yc.test(n.value)},pa=new Set(["delete","strong","emphasis"]),nn=e=>Array.isArray(e?.children)&&e.children.every(t=>t.type==="text"?!t.value:pa.has(t.type)&&nn(t));let Bt=!1;function kg(e){Bt=!0;try{return e()}finally{Bt=!1}}const Al={inside:!1,outside:!1},Zc=(e,t,n,r)=>{if(nn(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=Bt?Al:Ml(r.before.charCodeAt(r.before.length-1),i);c.inside&&(l=Io(i)+l.slice(1));const u=l.charCodeAt(l.length-1),d=Bt?Al:Ml(r.after.charCodeAt(0),u);d.inside&&(l=l.slice(0,-1)+Io(u));const f=o.move("~~");return s(),n.attentionEncodeSurroundingInfo={after:d.outside&&!Qc(t,n),before:c.outside&&!Xc(t,n)},a+l+f};Zc.peek=e=>nn(e)?"":"~";function eu(e){const t=(n,r,o,s)=>{if(nn(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&&(Bt||Sl(n,c,!1)||Xc(r,o)||!wr(s.before.charCodeAt(s.before.length-1)))&&(l.before=!1),l.after&&(Bt||Sl(n,u,!0)||Qc(r,o)||!wr(s.after.charCodeAt(0)))&&(l.after=!1)}return a};return t.peek=(n,r,o)=>nn(n)?"":e.peek(n,r,o),t}const wg=eu(Zt.strong),xg=eu(Zt.emphasis);function vg(e){const t=[];for(const n of e.children){const r=t[t.length-1];r&&pa.has(n.type)&&n.type===r.type?r.children=[...r.children,...n.children]:t.push(n)}return t}const Lo=new Set(["strong","emphasis"]),tu=e=>e.type==="text"?!e.value:pa.has(e.type)&&nn(e);function nu(e,t){let n=e;for(;;){const r=n.children??[];let o=t?r.length-1:0;for(;o>=0&&o<r.length&&tu(r[o]);)o+=t?-1:1;if(o<0||o>=r.length)return null;if(!Lo.has(r[o].type))return{host:n,index:o};n=r[o]}}function Ro(e,t){const n=nu(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(Qo(s)!==void 0)return"punct";const a=t?o.codePointAt(o.length-(o.length>1&&fa(s)?2:1)):o.codePointAt(0);return!Si(a)||(t?Gc.test(o):Yc.test(o))?"ok":"letter"}function Nl(e,t){const n=nu(e,t);if(!n)return!1;const r=n.host.children,o=r[n.index].value,s=t?o.length-(o.length>1&&fa(o.charCodeAt(o.length-1))?2:1):0,a=o.codePointAt(s),l=[{type:"text",value:o.slice(0,s)},{type:$o,value:Io(a)},{type:"text",value:o.slice(s+(a>65535?2:1))}];return r.splice(n.index,1,...l.filter(i=>i.type===$o||i.value)),!0}const $o="amadeusCharRef",ru=e=>e.value;ru.peek=()=>"&";function ou(e){if(Array.isArray(e?.children)){e.children=vg(e);for(let t=!Bt;t;){t=!1;const n=e.children.filter(r=>!tu(r));for(let r=1;r<n.length;r++){const[o,s]=[n[r-1],n[r]];if(!Lo.has(o.type)||!Lo.has(s.type))continue;const a=Ro(o,!0),l=Ro(s,!1);if(a==="letter"&&l==="punct"?t=Nl(o,!0):a==="punct"&&l==="letter"&&(t=Nl(s,!1)),t)break}}for(const t of e.children)ou(t)}}const Cg=(e,t,n,r)=>(ou(e),Zt.root(e,t,n,r)),Sg=gg,Mg={root:Cg,text:Sg,delete:Zc,strong:wg,emphasis:xg,[$o]:ru},Ag=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,...Mg}}))});function Ng(){Ef.call(this),Tf.call(this,{singleTilde:!1})}const Eg=ve("amadeusCjkFriendly",()=>Ng),In="amadeusU",Ln="amadeusFg",Rn="amadeusBg",ma="amadeusKbd",ha="amadeusSub",ga="amadeusSup",ba=new Map([["kbd",ma],["sub",ha],["sup",ga]]),xr=e=>/^(#[0-9a-fA-F]{3,8}|rgba?\([\d.,%\s/]+\)|hsla?\([\d.,%\s/]+\)|[a-zA-Z]+|var\(--[\w-]+\))$/.test(e.trim());function su(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<u>$/i.test(t))return{type:In};const n=/^<([a-z]+)>$/.exec(t),r=n&&ba.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 xr(s)?{type:Ln,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&&!xr(s)?null:{type:Rn,bg:s}}return null}function au(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<\/u>$/i.test(t))return In;if(/^<\/span>$/i.test(t))return Ln;if(/^<\/mark>$/i.test(t))return Rn;const n=/^<\/([a-z]+)>$/.exec(t);return n&&ba.get(n[1])||null}const Tg=16,El=new Set(ba.values()),Ig=new Set(["paragraph","heading","tableCell"]);function Lg(e){const t=new Map,n=new Set,r=o=>{for(const s of o){const a=su(s)?.type;if(a&&El.has(a)){const i=(t.get(a)??0)+1;t.set(a,i),i>1&&n.add(a);continue}const l=au(s);if(l&&El.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 lu(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=su(s),l=a&&!t.has(a.type)?a:null,i=au(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>=Tg)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=Ig.has(s.type)?new Set([...t,...Lg(s.children)]):t;s.children=lu(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 Wt(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 Rg(){const e=this.data();return(e.toMarkdownExtensions||=[]).push({handlers:{[In]:Wt(()=>"<u>","</u>"),[Ln]:Wt(n=>`<span style="color:${n.color}">`,"</span>"),[Rn]:Wt(n=>n.bg?`<mark style="background:${n.bg}">`:"<mark>","</mark>"),[ma]:Wt(()=>"<kbd>","</kbd>"),[ha]:Wt(()=>"<sub>","</sub>"),[ga]:Wt(()=>"<sup>","</sup>")}}),n=>{Array.isArray(n?.children)&&(n.children=lu(n.children))}}const $g=ve("amadeusInlineHtmlMarks",()=>Rg),iu=at("amadeusUnderline",()=>({parseDOM:[{tag:"u"}],toDOM:()=>["u",0],parseMarkdown:{match:e=>e.type===In,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,In)}}}));function ya(e,t,n){return at(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 Dg=ya("amadeusKbd","kbd",ma),_g=ya("amadeusSub","sub",ha),zg=ya("amadeusSup","sup",ga),ka={"#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"},wa={"#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 cu(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 uu=e=>{const t={};for(const[n,r]of Object.entries(e))r in t||(t[r]=n);return t},Og=uu(ka),Pg=uu(wa),du=(e,t,n,r)=>{const o=cu(r);return o&&e[o]&&(!n||e[o]===n)?o:n&&t[n]?t[n]:null};function Bg(e){const t=e.getAttribute("data-amx-fg");if(t&&xr(t))return{color:t};if(!e.style.color)return!1;const n=du(ka,Og,e.getAttribute("data-hlc"),e.style.color);return n?{color:n}:!1}function Kg(e){const t=e.getAttribute("data-amx-bg");return t!==null&&(t===""||xr(t))?{bg:t}:{bg:du(wa,Pg,e.getAttribute("data-hl"),e.style.backgroundColor)??""}}const fu=(e,t)=>e[cu(t)??t.toLowerCase()],Do=at("amadeusColor",()=>({attrs:{color:{default:""}},parseDOM:[{tag:'span[style*="color"]',getAttrs:e=>Bg(e)}],toDOM:e=>{const t=String(e.attrs.color),n=fu(ka,t);return["span",{style:`color:${t}`,"data-amx-fg":t,...n?{"data-hlc":n}:{}},0]},parseMarkdown:{match:e=>e.type===Ln,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,Ln,void 0,{color:t.attrs.color})}}})),_o=at("amadeusBg",()=>({attrs:{bg:{default:""}},parseDOM:[{tag:"mark",getAttrs:e=>Kg(e)}],toDOM:e=>{const t=String(e.attrs.bg);if(!t)return["mark",{"data-amx-bg":""},0];const n=fu(wa,t);return["mark",{style:`background:${t}`,"data-amx-bg":t,...n?{"data-hl":n}:{}},0]},parseMarkdown:{match:e=>e.type===Rn,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,Rn,void 0,{bg:t.attrs.bg})}}})),ao=F("AmadeusToggleUnderline",e=>()=>On(iu.type(e)));function pu(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 mu(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 Tl=F("AmadeusApplyColor",e=>t=>t?pu(Do.type(e),{color:t}):mu(Do.type(e))),Il=F("AmadeusApplyBg",e=>t=>t?pu(_o.type(e),{bg:t}):mu(_o.type(e)));De({"obsinline.comment.title":{zh:"注释(点击编辑)",en:"Comment (click to edit)"}});function hu(e){if(e.indexOf("%%")===-1&&e.indexOf("==")===-1)return[];let t=e;for(const o of Wi(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 wt=new fe("amadeus-obsidian-inline");function jg(e,t){const n=document.createElement("span");return n.className="amx-obs-cmt-badge",n.contentEditable="false",n.textContent="%%",n.title=O("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(j.create(e.state.doc,o)).setMeta(wt,{focus:!0})),e.focus()}),n}function Hg(e){const t=wt.getState(e)?.focus??!1,{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 hu(Dr(s))){const u=i+c.from,d=i+c.to,f=t&&n<=d&&r>=u;if(c.kind==="hl"){o.push(Y.inline(u+2,d-2,{class:"amx-obs-hl"}));const m=f?"amx-obs-delim":"amx-obs-hidden";o.push(Y.inline(u,u+2,{class:m}),Y.inline(d-2,d,{class:m}))}else f?o.push(Y.inline(u,d,{class:"amx-obs-cmt"})):(o.push(Y.inline(u,d,{class:"amx-obs-hidden"})),o.push(Y.widget(u,m=>jg(m,u+2),{side:-1,ignoreSelection:!0,key:`obs-cmt:${u}`})))}return!1}),o.length?me.create(e.doc,o):me.empty}function Fg(){return Q(()=>new Z({key:wt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(wt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{handleDOMEvents:{focus:e=>(wt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(wt,{focus:!0})),!1),blur:e=>(wt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(wt,{focus:!1})),!1)},decorations:e=>Hg(e)}}))}const qg=(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=hu(Dr(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
4
  `,"");if(c.includes(`
5
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(j.create(m.doc,u+2,d+2)),t?.(m),!0},Ll=e=>e?.type==="break",Wg=/^(?:\s*<br\b[^>]*>)+/i;function zo(e){if(e?.type!=="html"||typeof e.value!="string")return{count:0,rest:""};const t=Wg.exec(e.value);return t?{count:(t[0].match(/<br\b/gi)??[]).length,rest:e.value.slice(t[0].length)}:{count:0,rest:""}}const gu=e=>{const t=e.replace(/^\n+/,"");return t&&!t.includes("<")?t:null};function bu(e){const t=Array.isArray(e?.children)?e.children:[];if(!t.some(a=>Ll(a)||zo(a).count>0||a?.type==="text"&&typeof a.value=="string"&&a.value.includes(`
6
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=zo(a);if(l.count>0){for(let c=0;c<l.count;c++)r.push([]);const i=gu(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(`
@@ -8,7 +8,7 @@ import{d as E,r as De,be as zn,bq as Xa,bp as nf,W as Xo,c3 as Zt,c4 as Qo,c5 as
8
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
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 yu(e){if(!e.includes("<br"))return e;const t=e.split(`
10
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 Ug(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 ku(e){if(!Array.isArray(e?.children))return;const t=[];let n=null;for(const r of e.children){for(let s=0;s<Ug(n,r);s++)t.push({type:"paragraph",children:[]});if(n=r,r?.type==="paragraph"){t.push(...bu(r));continue}const o=zo(r);if(o.count>0){for(let a=0;a<o.count;a++)t.push({type:"paragraph",children:[]});const s=gu(o.rest);s?t.push({type:"paragraph",children:[{type:"text",value:s}]}):o.rest.trim()&&t.push({...r,value:o.rest});continue}ku(r),t.push(r)}e.children=t}const Vg=(e,t)=>e?.type==="paragraph"&&t?.type==="paragraph"?0:void 0,Gg=e=>Math.max(0,Math.floor((e-1)/2)),Jg=e=>Math.max(0,Math.floor(e/2)),Yg=e=>Math.max(0,Math.floor((e+1)/2));function hn(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 Xg(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=hn(e,"start"),a=hn(t[0],"start");s!=null&&a!=null&&r(o,Jg(a-s));let l=null;for(const c of t){const u=hn(c,"start");l!=null&&u!=null&&r(o,Gg(u-l-1)),o.push(c),l=hn(c,"end")}const i=hn(e,"end");i!=null&&l!=null&&r(o,Yg(i-l-1)),e.children=o}const Qg=ve("amadeusBlankLine",()=>()=>e=>Xg(e)),Zg=ve("amadeusSoftBreak",()=>function(){const t=this.data();return(t.toMarkdownExtensions||=[]).push({join:[Vg]}),r=>ku(r)});function eb(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 s1=ve("amadeusHardBreak",()=>()=>e=>eb(e)),tb=/^[-*+]$/,Xt=e=>typeof e=="string"&&tb.test(e)?e:null;function nb(e,t){const n=r=>{if(r?.type==="list"&&!r.ordered){const o=r.children?.[0]?.position?.start?.offset,s=typeof o=="number"?Xt(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 rb=ve("amadeusListBullet",()=>()=>(e,t)=>nb(e,String(t?.value??""))),Rl=e=>e===!0||e==="true";function ob(e,t,n,r){const o=Rl(e.spread);e.spread=o;for(const l of Array.isArray(e.children)?e.children:[])l?.type==="listItem"&&(l.spread=Rl(l.spread)&&o);const s=e.ordered?null:Xt(e.amadeusBullet);if(!s)return Zt.list(e,t,n,r);const a=n.options.bullet;n.options.bullet=s;try{return Zt.list(e,t,n,r)}finally{n.options.bullet=a}}const sb=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,list:ob}}))}),ab=[rb,sb].flat(),Le=e=>Math.max(0,Math.min(Mi,Math.floor(e)||0)),lb=/^<!-- amadeus-indent:([1-8]) -->$/,ib=new Set(["heading","blockquote","list"]);function wu(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"?lb.exec(s.value.trim()):null;if(a&&o&&ib.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}wu(r)}}const cb=ve("amadeusStructuralIndent",()=>()=>e=>wu(e)),Ur=e=>Le(Number(e.data?.amadeusIndent??0)),Vr=e=>`<!-- amadeus-indent:${Le(e)} -->`,$l=At.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0}},parseDOM:[{tag:"blockquote",getAttrs:r=>({indent:Le(Number(r.dataset.indent))})}],toDOM:r=>{const o=Le(r.attrs.indent);return["blockquote",{...t.get(Hr.key)(r),...o?{"data-indent":o}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{r.openNode(s,{indent:Ur(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s)),n.toMarkdown.runner(r,o)}}}}),Dl=mt.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:Le(Number(r.dataset.indent)),bullet:Xt(r.dataset.bullet)})}],toDOM:r=>{const o=Le(r.attrs.indent),s=Xt(r.attrs.bullet);return["ul",{...t.get(Fr.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:Ur(o),bullet:Xt(o.data?.amadeusBullet)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s));const a=Xt(o.attrs.bullet);r.openNode("list",void 0,{ordered:!1,spread:o.attrs.spread,...a?{amadeusBullet:a}:{}}).next(o.content).closeNode()}}}}),_l=ht.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:Le(Number(r.dataset.indent))})}],toDOM:r=>{const o=Le(r.attrs.indent);return["ol",{...t.get(qr.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:Ur(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s)),n.toMarkdown.runner(r,o)}}}}),Oo=new Set(["heading","blockquote","bullet_list","ordered_list"]);function xu(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"&&!Oo.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=Le(Number(l.attrs.indent??0)),d=Le(u+n);return d!==u&&s.setNodeMarkup(i,void 0,{...l.attrs,indent:d}),!1}),s.steps.length&&t?.(s.scrollIntoView()),a}function _t(e,t,n,r){if(e.selection instanceof Ve&&Oo.has(e.selection.node.type.name)){const o=e.selection.node,s=e.selection.from,a=Le(Number(o.attrs.indent??0)+r);return a!==Le(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(!Oo.has(s.type.name))continue;const a=n.before(o),l=Le(Number(s.attrs.indent??0)+r);return l!==Le(Number(s.attrs.indent??0))&&t?.(e.tr.setNodeMarkup(a,void 0,{...s.attrs,indent:l}).scrollIntoView()),!0}return!1}const vu=/^<br\b[^<>]*>$/i,ub=e=>e!=null&&vu.test(e)?e:null,db=new Set(["root","blockquote","listItem","footnoteDefinition"]);function fb(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 pb(e){const t=n=>{const r=n?.children;if(!Array.isArray(r))return;const o=!db.has(n.type);for(let s=0;s<r.length;s++){const a=r[s];if(o&&a?.type==="html"&&typeof a.value=="string"&&vu.test(a.value)&&!fb(r,s)){r[s]={type:"break",data:{amadeusBr:a.value},position:a.position};continue}t(a)}};t(e)}const mb=ve("amadeusInlineBr",()=>()=>e=>pb(e)),zl=Je.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},html:{default:null}},parseDOM:[{tag:"br[data-md-br]",getAttrs:r=>({html:ub(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)}}}}),Cu=e=>e.lastChild?.type.name==="hardbreak"&&typeof e.lastChild.attrs.html=="string",hb=Q(e=>new Z({key:new fe("AMADEUS_HARDBREAK_MARKS"),appendTransaction:(t,n,r)=>{const o=t[0],s=o?.steps[0];if(!o||!s)return null;const a=Je.type(e);if(o.getMeta("hardbreak"))return s instanceof Di?r.tr.setNodeMarkup(s.from,a,void 0,[]):null;if(s instanceof _i){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}})),lo=e=>String(e??"").toUpperCase();function gb(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(`
11
+ `)}function Ug(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 ku(e){if(!Array.isArray(e?.children))return;const t=[];let n=null;for(const r of e.children){for(let s=0;s<Ug(n,r);s++)t.push({type:"paragraph",children:[]});if(n=r,r?.type==="paragraph"){t.push(...bu(r));continue}const o=zo(r);if(o.count>0){for(let a=0;a<o.count;a++)t.push({type:"paragraph",children:[]});const s=gu(o.rest);s?t.push({type:"paragraph",children:[{type:"text",value:s}]}):o.rest.trim()&&t.push({...r,value:o.rest});continue}ku(r),t.push(r)}e.children=t}const Vg=(e,t)=>e?.type==="paragraph"&&t?.type==="paragraph"?0:void 0,Gg=e=>Math.max(0,Math.floor((e-1)/2)),Yg=e=>Math.max(0,Math.floor(e/2)),Jg=e=>Math.max(0,Math.floor((e+1)/2));function hn(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 Xg(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=hn(e,"start"),a=hn(t[0],"start");s!=null&&a!=null&&r(o,Yg(a-s));let l=null;for(const c of t){const u=hn(c,"start");l!=null&&u!=null&&r(o,Gg(u-l-1)),o.push(c),l=hn(c,"end")}const i=hn(e,"end");i!=null&&l!=null&&r(o,Jg(i-l-1)),e.children=o}const Qg=ve("amadeusBlankLine",()=>()=>e=>Xg(e)),Zg=ve("amadeusSoftBreak",()=>function(){const t=this.data();return(t.toMarkdownExtensions||=[]).push({join:[Vg]}),r=>ku(r)});function eb(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 s1=ve("amadeusHardBreak",()=>()=>e=>eb(e)),tb=/^[-*+]$/,Xt=e=>typeof e=="string"&&tb.test(e)?e:null;function nb(e,t){const n=r=>{if(r?.type==="list"&&!r.ordered){const o=r.children?.[0]?.position?.start?.offset,s=typeof o=="number"?Xt(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 rb=ve("amadeusListBullet",()=>()=>(e,t)=>nb(e,String(t?.value??""))),Rl=e=>e===!0||e==="true";function ob(e,t,n,r){const o=Rl(e.spread);e.spread=o;for(const l of Array.isArray(e.children)?e.children:[])l?.type==="listItem"&&(l.spread=Rl(l.spread)&&o);const s=e.ordered?null:Xt(e.amadeusBullet);if(!s)return Zt.list(e,t,n,r);const a=n.options.bullet;n.options.bullet=s;try{return Zt.list(e,t,n,r)}finally{n.options.bullet=a}}const sb=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,list:ob}}))}),ab=[rb,sb].flat(),Le=e=>Math.max(0,Math.min(Mi,Math.floor(e)||0)),lb=/^<!-- amadeus-indent:([1-8]) -->$/,ib=new Set(["heading","blockquote","list"]);function wu(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"?lb.exec(s.value.trim()):null;if(a&&o&&ib.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}wu(r)}}const cb=ve("amadeusStructuralIndent",()=>()=>e=>wu(e)),Ur=e=>Le(Number(e.data?.amadeusIndent??0)),Vr=e=>`<!-- amadeus-indent:${Le(e)} -->`,$l=At.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0}},parseDOM:[{tag:"blockquote",getAttrs:r=>({indent:Le(Number(r.dataset.indent))})}],toDOM:r=>{const o=Le(r.attrs.indent);return["blockquote",{...t.get(Hr.key)(r),...o?{"data-indent":o}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{r.openNode(s,{indent:Ur(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s)),n.toMarkdown.runner(r,o)}}}}),Dl=mt.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:Le(Number(r.dataset.indent)),bullet:Xt(r.dataset.bullet)})}],toDOM:r=>{const o=Le(r.attrs.indent),s=Xt(r.attrs.bullet);return["ul",{...t.get(Fr.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:Ur(o),bullet:Xt(o.data?.amadeusBullet)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s));const a=Xt(o.attrs.bullet);r.openNode("list",void 0,{ordered:!1,spread:o.attrs.spread,...a?{amadeusBullet:a}:{}}).next(o.content).closeNode()}}}}),_l=ht.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:Le(Number(r.dataset.indent))})}],toDOM:r=>{const o=Le(r.attrs.indent);return["ol",{...t.get(qr.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:Ur(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Le(o.attrs.indent);s&&r.addNode("html",void 0,Vr(s)),n.toMarkdown.runner(r,o)}}}}),Oo=new Set(["heading","blockquote","bullet_list","ordered_list"]);function xu(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"&&!Oo.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=Le(Number(l.attrs.indent??0)),d=Le(u+n);return d!==u&&s.setNodeMarkup(i,void 0,{...l.attrs,indent:d}),!1}),s.steps.length&&t?.(s.scrollIntoView()),a}function _t(e,t,n,r){if(e.selection instanceof Ve&&Oo.has(e.selection.node.type.name)){const o=e.selection.node,s=e.selection.from,a=Le(Number(o.attrs.indent??0)+r);return a!==Le(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(!Oo.has(s.type.name))continue;const a=n.before(o),l=Le(Number(s.attrs.indent??0)+r);return l!==Le(Number(s.attrs.indent??0))&&t?.(e.tr.setNodeMarkup(a,void 0,{...s.attrs,indent:l}).scrollIntoView()),!0}return!1}const vu=/^<br\b[^<>]*>$/i,ub=e=>e!=null&&vu.test(e)?e:null,db=new Set(["root","blockquote","listItem","footnoteDefinition"]);function fb(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 pb(e){const t=n=>{const r=n?.children;if(!Array.isArray(r))return;const o=!db.has(n.type);for(let s=0;s<r.length;s++){const a=r[s];if(o&&a?.type==="html"&&typeof a.value=="string"&&vu.test(a.value)&&!fb(r,s)){r[s]={type:"break",data:{amadeusBr:a.value},position:a.position};continue}t(a)}};t(e)}const mb=ve("amadeusInlineBr",()=>()=>e=>pb(e)),zl=Ye.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},html:{default:null}},parseDOM:[{tag:"br[data-md-br]",getAttrs:r=>({html:ub(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)}}}}),Cu=e=>e.lastChild?.type.name==="hardbreak"&&typeof e.lastChild.attrs.html=="string",hb=Q(e=>new Z({key:new fe("AMADEUS_HARDBREAK_MARKS"),appendTransaction:(t,n,r)=>{const o=t[0],s=o?.steps[0];if(!o||!s)return null;const a=Ye.type(e);if(o.getMeta("hardbreak"))return s instanceof Di?r.tr.setNodeMarkup(s.from,a,void 0,[]):null;if(s instanceof _i){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}})),lo=e=>String(e??"").toUpperCase();function gb(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
12
  `))return o;const s=new RegExp(`^[ \\t>]{0,${n.column-1}}`);return o.split(`
13
13
  `).map((a,l)=>l?a.replace(s,""):a).join(`
14
14
  `)}const bb=e=>`[${e.label??e.identifier}]: ${e.url}${e.title?` "${e.title}"`:""}`;function yb(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]!==`
@@ -16,43 +16,43 @@ import{d as E,r as De,be as zn,bq as Xa,bp as nf,W as Xo,c3 as Zt,c4 as Qo,c5 as
16
16
  `);s=s.replace(/\r\n?/g,`
17
17
  `);const a=[];return s.split(`
18
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 kb(e,t){const n=new Map,r=s=>{if(s?.type==="definition"){const a=lo(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(yb(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(lo(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(lo(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 wb=ve("amadeusRefDefinitions",()=>()=>(e,t)=>kb(e,String(t?.value??""))),Ol=e=>e.replace(/[\t ]+(?=\n|$)/g,"");function Po(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&&Ol(e.textContent)===Ol(t)?t:null}const xb=/^[ \t]{0,3}(\[((?:[^\\[\]]|\\[\s\S])+)\]:)/;let Pl=null;const vb=e=>{Pl??=Ai().use(Ni).use(Xo);const t=Pl.parse(e)?.children??[];return t.length>0&&t.every(n=>n?.type==="definition")},Cb=e=>e==null||!xb.test(e.split(`
19
- `)[0])||/(?:^|\n)[ \t\r]*(?:\n|$)/.test(e)?null:vb(e)?e:null,Sb=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}},Bl=Ge.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:Sb(o.getAttribute("data-md-ref"))}}}],toDOM:r=>{const{ref:o,...s}=r.attrs;return["a",{...t.get(Pr.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 Gn(e){const t=e;return new Ye(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 Mb=ue(e=>Gn(st(/(?:^|[^*])\*([^*]+)\*$/,Et.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}))),Ab=/\b_(?![_\s])([^_]*[^_\s])_$/,Nb=ue(e=>Gn(st(Ab,Et.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}))),Eb=ue(e=>Gn(st(/(?:`)([^`]+)(?:`)$/,dt.type(e)))),Tb=new RegExp("(?:(?<![:/])\\*\\*(?=[^*_]+?\\*\\*$)|(?<![\\w:/])__(?=[^*_]+?__$))([^*_]+?)(?:\\*\\*|__)$"),Ib=ue(e=>Gn(st(Tb,sn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}))),Lb=new RegExp("(?<![\\w:/~])(~~)([^\\s~](?:[^~]*[^\\s~])?)~~$"),Rb=ue(e=>Gn(st(Lb,ln.type(e)))),$b=e=>(e.inject(Pt.options.key,{singleTilde:!1}),()=>()=>{e.remove(Pt.options.key)});function Db(){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 _b=ve("amadeusStrictTildeUnsafe",()=>Db),Kl=new Map([[us,Mb],[ds,Nb],[bs,Eb],[ms,Ib]]),zb=hg.flatMap(e=>e===ra?[Rb]:e===Pt.options?[$b]:e===Pt.plugin?[e,..._b]:[e]),Sn=new WeakMap,io=e=>!/\S/.test(e);function Ob(e,t){let n=t;for(;n>0&&e[n-1]!==`
19
+ `)[0])||/(?:^|\n)[ \t\r]*(?:\n|$)/.test(e)?null:vb(e)?e:null,Sb=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}},Bl=Ge.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:Sb(o.getAttribute("data-md-ref"))}}}],toDOM:r=>{const{ref:o,...s}=r.attrs;return["a",{...t.get(Pr.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 Gn(e){const t=e;return new Je(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 Mb=ue(e=>Gn(st(/(?:^|[^*])\*([^*]+)\*$/,Et.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}))),Ab=/\b_(?![_\s])([^_]*[^_\s])_$/,Nb=ue(e=>Gn(st(Ab,Et.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}))),Eb=ue(e=>Gn(st(/(?:`)([^`]+)(?:`)$/,dt.type(e)))),Tb=new RegExp("(?:(?<![:/])\\*\\*(?=[^*_]+?\\*\\*$)|(?<![\\w:/])__(?=[^*_]+?__$))([^*_]+?)(?:\\*\\*|__)$"),Ib=ue(e=>Gn(st(Tb,sn.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}))),Lb=new RegExp("(?<![\\w:/~])(~~)([^\\s~](?:[^~]*[^\\s~])?)~~$"),Rb=ue(e=>Gn(st(Lb,ln.type(e)))),$b=e=>(e.inject(Pt.options.key,{singleTilde:!1}),()=>()=>{e.remove(Pt.options.key)});function Db(){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 _b=ve("amadeusStrictTildeUnsafe",()=>Db),Kl=new Map([[us,Mb],[ds,Nb],[bs,Eb],[ms,Ib]]),zb=hg.flatMap(e=>e===ra?[Rb]:e===Pt.options?[$b]:e===Pt.plugin?[e,..._b]:[e]),Sn=new WeakMap,io=e=>!/\S/.test(e);function Ob(e,t){let n=t;for(;n>0&&e[n-1]!==`
20
20
  `;)n--;const r=e.slice(n,t);return r?/^ {1,3}$/.test(r)?n:null:t}function Pb(e,t){let n=t;for(;n<e.length&&(e[n]===" "||e[n]===" ");)n++;return n===e.length||e[n]===`
21
- `?n:t}const Bb=/!\[(?!\[)[^\]\n]*\](?!\()/;function Kb(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 jb=e=>e?.type==="html"||e?.type==="paragraph"&&e.children?.length===1&&e.children[0]?.type==="html";function Hb(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=Ob(e,h),w=g??h,y=Pb(e,m);o.from[u]=w,o.to[d]=y,g==null&&(o.sealBefore[u]=!0),a=y;const C=e.slice(w,y),N=c.md;(y===e.length||io(e.slice(y)))&&(N?.type==="code"&&/^[ \t]*(`{3,}|~{3,})/.test(C)||jb(N))&&(o.eofOpen[d]=!0),/^[ \t]/.test(C)&&(o.indentStart[u]=!0);let M=!1,T=Bb.test(C);for(const D of c.made){const H=Kb(D);M||=H.def,T||=H.link}for(let D=u;D<=d;D++)o.def[D]=M,o.ref[D]=T}let l=null,i=0;for(let c=0;c<r;c++){const u=o.from[c];u!=null&&!io(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&&!io(e.slice(i))&&(o.sealAfter[l]=!0),n.forEach((c,u)=>Sn.set(c,{src:o,idx:u}))}function Fb(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&&Hb(o,s,r.content)}const qb=ve("amadeusVerbatimSource",()=>()=>(e,t)=>{e.data={...e.data,amadeusSource:String(t?.value??"")}});function Wb(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 vr(e,t){if(e===t)return!0;if(e.type!==t.type||!If.sameSet(e.marks,t.marks))return!1;if(e.isText)return e.text===t.text;if(!Wb(e,t)||e.childCount!==t.childCount)return!1;for(let n=0;n<e.childCount;n++)if(!vr(e.child(n),t.child(n)))return!1;return!0}const Bo=e=>e.type.name==="bullet_list"||e.type.name==="ordered_list",Ub=e=>Bo(e)||e.type.name==="footnote_definition",jl=e=>e.type.name==="paragraph"&&e.content.size===0;function Vb(e){let t=e.type.name==="paragraph"&&Po(e)!=null;return e.descendants(n=>(!t&&n.type.name==="paragraph"&&Po(n)!=null&&(t=!0),!t)),t}function Gb(e){const t=e.childCount;if(!t)return null;const n=[];e.forEach(p=>{n.push(p)});const r=n.map(p=>Sn.get(p)??null);if(!r.some(Boolean))return null;const o=(p,h,g)=>{if(r[p]||!h)return;const w=h.idx+g;w>=0&&w<h.src.nodes.length&&vr(n[p],h.src.nodes[w])&&(r[p]={src:h.src,idx:w})};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&&vr(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 w=new Set;return r.forEach((y,C)=>{if(!y){Vb(n[C])&&(h=!1);return}if(y.src!==p){y.src.def[y.idx]&&(h=!1);return}p.def[y.idx]&&(y.idx<g&&(h=!1),g=y.idx,w.add(y.idx))}),p.def.forEach((y,C)=>{y&&!w.has(C)&&(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 M=0;M<t;M++){if(!d[M])continue;const T=M;for(;M+1<t&&d[M+1]&&r[M+1].src===r[T].src&&r[M+1].idx===r[M].idx+1;)M++;h.push([T,M])}let g=!1;for(const[M,T]of h){const D=r[M].src,H=f(M)||D.from[r[M].idx]!=null&&!D.sealBefore[r[M].idx],W=m(T)||D.to[r[T].idx]!=null&&!D.sealAfter[r[T].idx];H||(d[M]=!1,g=!0),W||(d[T]=!1,g=!0)}if(g)continue;const w=M=>{let T=M-1;for(;T>=0&&jl(n[T]);)T--;return T},y=M=>{let T=M+1;for(;T<t&&jl(n[T]);)T++;return T};for(const[M,T]of h){const D=r[M].src,H=w(M);H>=0&&Bo(n[M])&&n[H].type===n[M].type&&(d[M]=!1,g=!0);const W=y(T);W<t&&Bo(n[T])&&n[W].type===n[T].type&&(d[T]=!1,g=!0),D.indentStart[r[M].idx]&&H>=0&&(Ub(n[H])||n[M].type.name==="code_block"&&n[H].type.name==="code_block")&&(d[M]=!1,g=!0),M===0&&/^---\r?\n/.test(D.text.slice(f(0)?0:D.from[r[0].idx]??0))&&(d[0]=!1,g=!0)}if(g)continue;if(!h.length)return null;const C=h.map(([M,T])=>{const D=r[M].src;return{a:M,b:T,src:D,from:f(M)?0:D.from[r[M].idx],to:m(T)?D.text.length:D.to[r[T].idx],tail:m(T)}}),N=new Map;return C.forEach((M,T)=>N.set(M.a,T)),{doc:e,runs:C,startAt:N,nonce:Math.random().toString(36).slice(2,10)}}return null}let Mn=null;const Su=(e,t)=>`${e.nonce}:${t}`;function Jb(e,t){e.openNode("root");const n=Mn&&Mn.doc===t?Mn: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,Su(n,o)),r=n.runs[o].b}}const Yb=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,amadeusVerbatim:n=>String(n.value??"")}}))}),Xb=ss("doc",()=>({content:"block+",parseMarkdown:{match:({type:e})=>e==="root",runner:Fb},toMarkdown:{match:e=>e.type.name==="doc",runner:Jb}})),Qb=[qb,Yb].flat();function Zb(e,t,n){const r=e.get(en);let o=null;try{o=Gb(t)}catch{o=null}if(!o)return n(r(t));Mn=o;let s;try{s=r(t)}finally{Mn=null}let l=n(s);for(let i=0;i<o.runs.length;i++){const c=Su(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 a1(e,t){const n=Math.min(e.childCount,t.childCount),r=(s,a)=>{if(s===a)return!0;if(!vr(s,a))return!1;const l=Sn.get(a);return l?Sn.set(s,l):Sn.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 Hl="amadeusEscaped",Cr="amadeusEscape",Mu="\0",ey=/[!-/:-@[-`{-~]/g,ty=/\u0000(?=[!-/:-@[-`{-~])/g;function Au(e){return e.includes(Mu)?e.replace(ty,"\\"):e}function ny(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?.[rl]:void 0;if(!l?.length){t(a),s.push(a);continue}o=!0;const{[rl]: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:Cr,value:d.slice(m,h)}:{...u,value:d.slice(m,h)}),m=h}}o&&(n.children=s)};t(e)}const ry=ve("amadeusLiteralEscape",()=>()=>ny),oy=at(Hl,()=>({inclusive:!1,priority:100,parseDOM:[{tag:"span[data-amx-esc]"}],toDOM:()=>["span",{"data-amx-esc":""},0],parseMarkdown:{match:e=>e.type===Cr,runner:(e,t,n)=>{e.openMark(n),e.addText(String(t.value??"")),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===Hl,runner:(e,t,n)=>(e.addNode(Cr,void 0,n.text??""),!0)}})),Nu=e=>String(e.value??"").replace(ey,t=>Mu+t);Nu.peek=()=>"\\";const sy=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,[Cr]:Nu}}))}),ay=[oy,sy].flat(),et=e=>Math.max(0,Math.min(Mi,Math.floor(e)||0)),ly=/^<span data-amadeus-align="(left|center|right)"><\/span>$/,iy=/^<span data-amadeus-align="(left|center|right)">$/,tt=e=>e==="center"||e==="right"?e:"left",Eu=e=>`<span data-amadeus-align="${e}"></span>`,Tu=e=>{const t=e?.[0];if(t?.type!=="html"||typeof t.value!="string")return{align:"left",children:e};const n=ly.exec(t.value.trim());if(n)return{align:tt(n[1]),children:e.slice(1)};const r=iy.exec(t.value.trim()),o=e?.[1];return r&&o?.type==="html"&&o.value?.trim()==="</span>"?{align:tt(r[1]),children:e.slice(2)}:{align:"left",children:e}},Fl=Be.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:et(Number(r.getAttribute("data-indent"))),align:tt(r.getAttribute("data-align")||r.style.textAlign),raw:Cb(r.getAttribute("data-md-raw"))})}],toDOM:r=>{const o={...t.get(Kr.key)(r)},s=et(r.attrs.indent),a=tt(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=Tu(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=et(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=Po(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=et(o.attrs.indent),l=tt(o.attrs.align),i=Cu(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,Eu(l)),a&&r.addNode("html",void 0,"&#9;".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()}}}}),ql=rt.extendSchema(e=>t=>{const n=e(t),r=t.get(Kn.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:tt(a.getAttribute("data-align")||a.style.textAlign),indent:et(Number(a.dataset.indent))}}})),toDOM:o=>{const s={...t.get(jr.key)(o),id:o.attrs.id||r(o)},a=tt(o.attrs.align);a!=="left"&&(s["data-align"]=a);const l=et(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=Tu(s.children);o.openNode(a,{level:s.depth,...l.align!=="left"?{align:l.align}:{},indent:Ur(s)}),l.children?.length&&o.next(l.children),o.closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(o,s)=>{const a=et(s.attrs.indent);a&&o.addNode("html",void 0,Vr(a));const l=tt(s.attrs.align),i=Cu(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,Eu(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()}}}}),cy=[...mb,...Vp,...ry,...wb],uy=Um.map(e=>e===ks?Xb:e===Be.node?Fl.node:e===Be.ctx?Fl.ctx:e===rt.node?ql.node:e===rt.ctx?ql.ctx:e===At.node?$l.node:e===At.ctx?$l.ctx:e===mt.node?Dl.node:e===mt.ctx?Dl.ctx:e===ht.node?_l.node:e===ht.ctx?_l.ctx:e===Je.node?zl.node:e===Je.ctx?zl.ctx:e===Js?hb:e===Ge.mark?Bl.mark:e===Ge.ctx?Bl.ctx:Kl.has(e)?Kl.get(e):e),dy=[...uy.flatMap(e=>e===Wr.options?[...cy,e]:[e]),...ab,...Qb,...ay];function Iu(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 l1(e){return e.parent.type.name!=="paragraph"?null:Iu(e)?et(e.parent.attrs.indent):null}function Sr(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(!Iu(e.doc.resolve(i)))return!1;const c=et(l.attrs.indent),u=et(c+n);return u!==c&&(s.setNodeMarkup(i,void 0,{...l.attrs,indent:u}),a=!0),!1}),a&&t?.(s.scrollIntoView()),!0}function or(e,t,n){const r=tt(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||tt(c.attrs.align)===r||(a=a.setNodeMarkup(i,void 0,{...c.attrs,align:r}),l=!0)}return l&&t?.(a.scrollIntoView()),!0}const Lu=e=>{const t=e?.type.spec.tableRole;return t==="cell"||t==="header_cell"};function Ru(e){if(!Lu(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=Y.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 Gr(e){if(!Ke(e))return null;try{return Ru(Fn(e))}catch{return null}}function xa(e,t){return t<0||t>=e.content.size?null:Ru(e.resolve(t))}function i1(e,t){const n=e.resolve(t),r=zt(n);return r&&Lu(r.nodeAfter)?r.pos:null}function Jr(e,t,n=!0){const r=e.nodeAt(t);if(!r)return null;const o=j.near(e.resolve(n?t+r.nodeSize-1:t+1),n?-1:1);return o instanceof j?o:null}const va=(e,t,n,r)=>{const o=e.nodeAt(t);if(!o)return null;const s=Y.get(o);return n<0||n>=s.height||r<0||r>=s.width?null:t+1+s.map[n*s.width+r]};function Ca(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=Y.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 c1=(e,t)=>{const n=Gr(e);if(!n)return!1;const r=e.tr;if(n.bottom>=n.map.height&&Ca(r,n.tablePos,n.map.height)==null)return!1;const o=va(r.doc,n.tablePos,n.bottom,n.col),s=o==null?null:Jr(r.doc,o);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1},u1=(e,t)=>{if(!Gr(e))return!1;const n=e.schema.nodes.hardbreak;return n?(e.selection instanceof j&&t?.(e.tr.replaceSelectionWith(n.create({html:"<br>"}),!1).scrollIntoView()),!0):!1},d1=(e,t)=>{const n=Gr(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(j.create(s.doc,o+1)).scrollIntoView()),!0},fy=(e,t)=>{const n=Gr(e);if(!n)return!1;const r=e.tr,o=Ca(r,n.tablePos,n.map.height),s=o==null?null:Jr(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?xa(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=Y.get(r),a=va(e,t,s.height-1,s.width-1);return a==null?null:{tablePos:t,cellPos:a,explicit:!1,ops:["rowBelow","colRight"],align:null}}function p1(e,t,n){const r=xa(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,Ca(o,r.tablePos,l)==null)return null;break}case"colLeft":case"colRight":{i=n==="colLeft"?r.col:r.col+1,Qs(o,a,i);const d=o.doc.nodeAt(r.tablePos);if(!d)return null;const f=Y.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;Cc(o,a,r.row),l=Math.min(r.row,r.map.height-2);break}case"deleteCol":{if(r.map.width<=1)return null;vc(o,a,r.col),i=Math.min(r.col,r.map.width-2);break}}const c=va(o.doc,r.tablePos,l,i),u=c==null?null:Jr(o.doc,c);return u&&o.setSelection(u),o.scrollIntoView()}function m1(e,t,n){const r=xa(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=Jr(s.doc,r.cellPos);return a&&s.setSelection(a),s.scrollIntoView()}const Mr=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},py=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 Du(e,t,n){return!ea(n)(e,t)&&n===1&&fy(e,t),!0}function _u(e){const{$from:t,$to:n}=e.selection,r=t.parent.textContent,o=[r.lastIndexOf(`
21
+ `?n:t}const Bb=/!\[(?!\[)[^\]\n]*\](?!\()/;function Kb(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 jb=e=>e?.type==="html"||e?.type==="paragraph"&&e.children?.length===1&&e.children[0]?.type==="html";function Hb(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=Ob(e,h),w=g??h,y=Pb(e,m);o.from[u]=w,o.to[d]=y,g==null&&(o.sealBefore[u]=!0),a=y;const C=e.slice(w,y),N=c.md;(y===e.length||io(e.slice(y)))&&(N?.type==="code"&&/^[ \t]*(`{3,}|~{3,})/.test(C)||jb(N))&&(o.eofOpen[d]=!0),/^[ \t]/.test(C)&&(o.indentStart[u]=!0);let M=!1,T=Bb.test(C);for(const D of c.made){const H=Kb(D);M||=H.def,T||=H.link}for(let D=u;D<=d;D++)o.def[D]=M,o.ref[D]=T}let l=null,i=0;for(let c=0;c<r;c++){const u=o.from[c];u!=null&&!io(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&&!io(e.slice(i))&&(o.sealAfter[l]=!0),n.forEach((c,u)=>Sn.set(c,{src:o,idx:u}))}function Fb(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&&Hb(o,s,r.content)}const qb=ve("amadeusVerbatimSource",()=>()=>(e,t)=>{e.data={...e.data,amadeusSource:String(t?.value??"")}});function Wb(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 vr(e,t){if(e===t)return!0;if(e.type!==t.type||!If.sameSet(e.marks,t.marks))return!1;if(e.isText)return e.text===t.text;if(!Wb(e,t)||e.childCount!==t.childCount)return!1;for(let n=0;n<e.childCount;n++)if(!vr(e.child(n),t.child(n)))return!1;return!0}const Bo=e=>e.type.name==="bullet_list"||e.type.name==="ordered_list",Ub=e=>Bo(e)||e.type.name==="footnote_definition",jl=e=>e.type.name==="paragraph"&&e.content.size===0;function Vb(e){let t=e.type.name==="paragraph"&&Po(e)!=null;return e.descendants(n=>(!t&&n.type.name==="paragraph"&&Po(n)!=null&&(t=!0),!t)),t}function Gb(e){const t=e.childCount;if(!t)return null;const n=[];e.forEach(p=>{n.push(p)});const r=n.map(p=>Sn.get(p)??null);if(!r.some(Boolean))return null;const o=(p,h,g)=>{if(r[p]||!h)return;const w=h.idx+g;w>=0&&w<h.src.nodes.length&&vr(n[p],h.src.nodes[w])&&(r[p]={src:h.src,idx:w})};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&&vr(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 w=new Set;return r.forEach((y,C)=>{if(!y){Vb(n[C])&&(h=!1);return}if(y.src!==p){y.src.def[y.idx]&&(h=!1);return}p.def[y.idx]&&(y.idx<g&&(h=!1),g=y.idx,w.add(y.idx))}),p.def.forEach((y,C)=>{y&&!w.has(C)&&(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 M=0;M<t;M++){if(!d[M])continue;const T=M;for(;M+1<t&&d[M+1]&&r[M+1].src===r[T].src&&r[M+1].idx===r[M].idx+1;)M++;h.push([T,M])}let g=!1;for(const[M,T]of h){const D=r[M].src,H=f(M)||D.from[r[M].idx]!=null&&!D.sealBefore[r[M].idx],W=m(T)||D.to[r[T].idx]!=null&&!D.sealAfter[r[T].idx];H||(d[M]=!1,g=!0),W||(d[T]=!1,g=!0)}if(g)continue;const w=M=>{let T=M-1;for(;T>=0&&jl(n[T]);)T--;return T},y=M=>{let T=M+1;for(;T<t&&jl(n[T]);)T++;return T};for(const[M,T]of h){const D=r[M].src,H=w(M);H>=0&&Bo(n[M])&&n[H].type===n[M].type&&(d[M]=!1,g=!0);const W=y(T);W<t&&Bo(n[T])&&n[W].type===n[T].type&&(d[T]=!1,g=!0),D.indentStart[r[M].idx]&&H>=0&&(Ub(n[H])||n[M].type.name==="code_block"&&n[H].type.name==="code_block")&&(d[M]=!1,g=!0),M===0&&/^---\r?\n/.test(D.text.slice(f(0)?0:D.from[r[0].idx]??0))&&(d[0]=!1,g=!0)}if(g)continue;if(!h.length)return null;const C=h.map(([M,T])=>{const D=r[M].src;return{a:M,b:T,src:D,from:f(M)?0:D.from[r[M].idx],to:m(T)?D.text.length:D.to[r[T].idx],tail:m(T)}}),N=new Map;return C.forEach((M,T)=>N.set(M.a,T)),{doc:e,runs:C,startAt:N,nonce:Math.random().toString(36).slice(2,10)}}return null}let Mn=null;const Su=(e,t)=>`${e.nonce}:${t}`;function Yb(e,t){e.openNode("root");const n=Mn&&Mn.doc===t?Mn: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,Su(n,o)),r=n.runs[o].b}}const Jb=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,amadeusVerbatim:n=>String(n.value??"")}}))}),Xb=ss("doc",()=>({content:"block+",parseMarkdown:{match:({type:e})=>e==="root",runner:Fb},toMarkdown:{match:e=>e.type.name==="doc",runner:Yb}})),Qb=[qb,Jb].flat();function Zb(e,t,n){const r=e.get(en);let o=null;try{o=Gb(t)}catch{o=null}if(!o)return n(r(t));Mn=o;let s;try{s=r(t)}finally{Mn=null}let l=n(s);for(let i=0;i<o.runs.length;i++){const c=Su(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 a1(e,t){const n=Math.min(e.childCount,t.childCount),r=(s,a)=>{if(s===a)return!0;if(!vr(s,a))return!1;const l=Sn.get(a);return l?Sn.set(s,l):Sn.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 Hl="amadeusEscaped",Cr="amadeusEscape",Mu="\0",ey=/[!-/:-@[-`{-~]/g,ty=/\u0000(?=[!-/:-@[-`{-~])/g;function Au(e){return e.includes(Mu)?e.replace(ty,"\\"):e}function ny(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?.[rl]:void 0;if(!l?.length){t(a),s.push(a);continue}o=!0;const{[rl]: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:Cr,value:d.slice(m,h)}:{...u,value:d.slice(m,h)}),m=h}}o&&(n.children=s)};t(e)}const ry=ve("amadeusLiteralEscape",()=>()=>ny),oy=at(Hl,()=>({inclusive:!1,priority:100,parseDOM:[{tag:"span[data-amx-esc]"}],toDOM:()=>["span",{"data-amx-esc":""},0],parseMarkdown:{match:e=>e.type===Cr,runner:(e,t,n)=>{e.openMark(n),e.addText(String(t.value??"")),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===Hl,runner:(e,t,n)=>(e.addNode(Cr,void 0,n.text??""),!0)}})),Nu=e=>String(e.value??"").replace(ey,t=>Mu+t);Nu.peek=()=>"\\";const sy=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,[Cr]:Nu}}))}),ay=[oy,sy].flat(),et=e=>Math.max(0,Math.min(Mi,Math.floor(e)||0)),ly=/^<span data-amadeus-align="(left|center|right)"><\/span>$/,iy=/^<span data-amadeus-align="(left|center|right)">$/,tt=e=>e==="center"||e==="right"?e:"left",Eu=e=>`<span data-amadeus-align="${e}"></span>`,Tu=e=>{const t=e?.[0];if(t?.type!=="html"||typeof t.value!="string")return{align:"left",children:e};const n=ly.exec(t.value.trim());if(n)return{align:tt(n[1]),children:e.slice(1)};const r=iy.exec(t.value.trim()),o=e?.[1];return r&&o?.type==="html"&&o.value?.trim()==="</span>"?{align:tt(r[1]),children:e.slice(2)}:{align:"left",children:e}},Fl=Be.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:et(Number(r.getAttribute("data-indent"))),align:tt(r.getAttribute("data-align")||r.style.textAlign),raw:Cb(r.getAttribute("data-md-raw"))})}],toDOM:r=>{const o={...t.get(Kr.key)(r)},s=et(r.attrs.indent),a=tt(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=Tu(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=et(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=Po(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=et(o.attrs.indent),l=tt(o.attrs.align),i=Cu(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,Eu(l)),a&&r.addNode("html",void 0,"&#9;".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()}}}}),ql=rt.extendSchema(e=>t=>{const n=e(t),r=t.get(Kn.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:tt(a.getAttribute("data-align")||a.style.textAlign),indent:et(Number(a.dataset.indent))}}})),toDOM:o=>{const s={...t.get(jr.key)(o),id:o.attrs.id||r(o)},a=tt(o.attrs.align);a!=="left"&&(s["data-align"]=a);const l=et(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=Tu(s.children);o.openNode(a,{level:s.depth,...l.align!=="left"?{align:l.align}:{},indent:Ur(s)}),l.children?.length&&o.next(l.children),o.closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(o,s)=>{const a=et(s.attrs.indent);a&&o.addNode("html",void 0,Vr(a));const l=tt(s.attrs.align),i=Cu(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,Eu(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()}}}}),cy=[...mb,...Vp,...ry,...wb],uy=Um.map(e=>e===ks?Xb:e===Be.node?Fl.node:e===Be.ctx?Fl.ctx:e===rt.node?ql.node:e===rt.ctx?ql.ctx:e===At.node?$l.node:e===At.ctx?$l.ctx:e===mt.node?Dl.node:e===mt.ctx?Dl.ctx:e===ht.node?_l.node:e===ht.ctx?_l.ctx:e===Ye.node?zl.node:e===Ye.ctx?zl.ctx:e===Ys?hb:e===Ge.mark?Bl.mark:e===Ge.ctx?Bl.ctx:Kl.has(e)?Kl.get(e):e),dy=[...uy.flatMap(e=>e===Wr.options?[...cy,e]:[e]),...ab,...Qb,...ay];function Iu(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 l1(e){return e.parent.type.name!=="paragraph"?null:Iu(e)?et(e.parent.attrs.indent):null}function Sr(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(!Iu(e.doc.resolve(i)))return!1;const c=et(l.attrs.indent),u=et(c+n);return u!==c&&(s.setNodeMarkup(i,void 0,{...l.attrs,indent:u}),a=!0),!1}),a&&t?.(s.scrollIntoView()),!0}function or(e,t,n){const r=tt(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||tt(c.attrs.align)===r||(a=a.setNodeMarkup(i,void 0,{...c.attrs,align:r}),l=!0)}return l&&t?.(a.scrollIntoView()),!0}const Lu=e=>{const t=e?.type.spec.tableRole;return t==="cell"||t==="header_cell"};function Ru(e){if(!Lu(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=J.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 Gr(e){if(!Ke(e))return null;try{return Ru(Fn(e))}catch{return null}}function xa(e,t){return t<0||t>=e.content.size?null:Ru(e.resolve(t))}function i1(e,t){const n=e.resolve(t),r=zt(n);return r&&Lu(r.nodeAfter)?r.pos:null}function Yr(e,t,n=!0){const r=e.nodeAt(t);if(!r)return null;const o=j.near(e.resolve(n?t+r.nodeSize-1:t+1),n?-1:1);return o instanceof j?o:null}const va=(e,t,n,r)=>{const o=e.nodeAt(t);if(!o)return null;const s=J.get(o);return n<0||n>=s.height||r<0||r>=s.width?null:t+1+s.map[n*s.width+r]};function Ca(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=J.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 c1=(e,t)=>{const n=Gr(e);if(!n)return!1;const r=e.tr;if(n.bottom>=n.map.height&&Ca(r,n.tablePos,n.map.height)==null)return!1;const o=va(r.doc,n.tablePos,n.bottom,n.col),s=o==null?null:Yr(r.doc,o);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1},u1=(e,t)=>{if(!Gr(e))return!1;const n=e.schema.nodes.hardbreak;return n?(e.selection instanceof j&&t?.(e.tr.replaceSelectionWith(n.create({html:"<br>"}),!1).scrollIntoView()),!0):!1},d1=(e,t)=>{const n=Gr(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(j.create(s.doc,o+1)).scrollIntoView()),!0},fy=(e,t)=>{const n=Gr(e);if(!n)return!1;const r=e.tr,o=Ca(r,n.tablePos,n.map.height),s=o==null?null:Yr(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?xa(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=J.get(r),a=va(e,t,s.height-1,s.width-1);return a==null?null:{tablePos:t,cellPos:a,explicit:!1,ops:["rowBelow","colRight"],align:null}}function p1(e,t,n){const r=xa(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,Ca(o,r.tablePos,l)==null)return null;break}case"colLeft":case"colRight":{i=n==="colLeft"?r.col:r.col+1,Qs(o,a,i);const d=o.doc.nodeAt(r.tablePos);if(!d)return null;const f=J.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;Cc(o,a,r.row),l=Math.min(r.row,r.map.height-2);break}case"deleteCol":{if(r.map.width<=1)return null;vc(o,a,r.col),i=Math.min(r.col,r.map.width-2);break}}const c=va(o.doc,r.tablePos,l,i),u=c==null?null:Yr(o.doc,c);return u&&o.setSelection(u),o.scrollIntoView()}function m1(e,t,n){const r=xa(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=Yr(s.doc,r.cellPos);return a&&s.setSelection(a),s.scrollIntoView()}const Mr=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},py=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 Du(e,t,n){return!ea(n)(e,t)&&n===1&&fy(e,t),!0}function _u(e){const{$from:t,$to:n}=e.selection,r=t.parent.textContent,o=[r.lastIndexOf(`
23
23
  `,t.parentOffset-1)+1];for(let s=t.parentOffset;s<n.parentOffset;s++)r[s]===`
24
24
  `&&o.push(s+1);return o.map(s=>t.start()+s)}function my(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
25
  `)){const a=e.tr;for(const l of _u(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 Du(e,t,1);if(!e.selection.empty&&!o.sameParent(s)&&!Mr(e)&&xu(e,t,1))return!0;if(Mr(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 Qi(e.schema.nodes.list_item)(e,t)||_t(e,t,o,1),!0}return o.parent.type.name==="paragraph"?_t(e,t,o,1)?!0:Sr(e,t,1):e.selection instanceof Ve&&e.selection.node.type.name==="paragraph"?Sr(e,t,1):(_t(e,t,o,1),!0)}function hy(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 _u(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 Du(e,t,-1);if(!e.selection.empty&&!n.sameParent(r)&&!Mr(e)&&xu(e,t,-1))return!0;if(Mr(e)){const o=e.schema.nodes.list_item;if(py(e)>0)return _t(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?ns(s):null;if(s&&a!=null)return t?.(e.tr.lift(s,a).scrollIntoView()),!0}return Xi(o)(e,t)||_t(e,t,n,-1),!0}return n.parent.type.name==="paragraph"?_t(e,t,n,-1)?!0:Sr(e,t,-1):e.selection instanceof Ve&&e.selection.node.type.name==="paragraph"?Sr(e,t,-1):(_t(e,t,n,-1),!0)}function Ko(e){if(!e)return!1;if(Array.isArray(e))return e.length>1?!1:Ko(e[0]);const t=e.content;return t?Ko(t):e.type==="text"}function gy(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-clipboard",...t}}),e}function Wl(e,t){const n=$f(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 zu=Q(e=>{const t=e.get(Lf);return e.update(Pi,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 Z({key:new fe("MILKDOWN_CLIPBOARD"),props:{handlePaste:(n,r,o)=>{const s=e.get(hr),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=Rf("code_block",t);return p.replaceSelectionWith(h.create({language:m})).setSelection(j.near(p.doc.resolve(Math.max(0,p.selection.from-2)))).insertText(i.replace(/\r\n?/g,`
26
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 Wl(n,o);const d=Bi.fromSchema(t);let f;if(u.length===0){const m=s(i);if(!m||typeof m=="string")return!1;f=Ki.fromSchema(t).serializeFragment(m.content)}else{const m=document.createElement("template");m.innerHTML=u,f=m.content.cloneNode(!0),m.remove()}return Wl(n,d.parseSlice(f))},clipboardTextSerializer:n=>{const r=e.get(en);if(Ko(n.content.toJSON()))return n.content.textBetween(0,n.content.size,`
27
27
 
28
- `);const o=t.topNodeType.createAndFill(void 0,n.content);return o?r(o):""}}})});gy(zu,{displayName:"Prose<clipboard>"});var Ar=200,Ne=function(){};Ne.prototype.append=function(t){return t.length?(t=Ne.from(t),!this.length&&t||t.length<Ar&&this.leafAppend(t)||this.length<Ar&&t.leafPrepend(this)||this.appendInner(t)):this};Ne.prototype.prepend=function(t){return t.length?Ne.from(t).append(this):this};Ne.prototype.appendInner=function(t){return new by(this,t)};Ne.prototype.slice=function(t,n){return t===void 0&&(t=0),n===void 0&&(n=this.length),t>=n?Ne.empty:this.sliceInner(Math.max(0,t),Math.min(this.length,n))};Ne.prototype.get=function(t){if(!(t<0||t>=this.length))return this.getInner(t)};Ne.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)};Ne.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};Ne.from=function(t){return t instanceof Ne?t:t&&t.length?new Ou(t):Ne.empty};var Ou=(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<=Ar)return new t(this.values.concat(o.flatten()))},t.prototype.leafPrepend=function(o){if(this.length+o.length<=Ar)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})(Ne);Ne.empty=new Ou([]);var by=(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})(Ne);const yy=500;class Ue{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 Qe(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 Qe(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 Ue(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 Qe(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>wy&&(l=ky(l,c),a-=c),new Ue(l.append(s),a)}remapping(t,n){let r=new Df;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 Ue(this.items.append(t.map(n=>new Qe(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 Qe(p,h,g))}else r.push(new Qe(p))},o);let c=[];for(let f=n;f<a;f++)c.push(new Qe(s.maps[f]));let u=this.items.slice(0,o).append(c).append(r),d=new Ue(u,l);return d.emptyItemCount()>yy&&(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 Qe(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 Ue(Ne.from(o.reverse()),s)}}Ue.empty=new Ue(Ne.empty,0);function ky(e,t){let n;return e.forEach((r,o)=>{if(r.selection&&t--==0)return n=o,!1}),e.slice(n)}class Qe{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 Qe(n.getMap().invert(),n,this.selection)}}}class xt{constructor(t,n,r,o,s){this.done=t,this.undone=n,this.prevRanges=r,this.prevTime=o,this.prevComposition=s}}const wy=20;function xy(e,t,n,r){let o=n.getMeta(nt),s;if(o)return o.historyState;n.getMeta(Pu)&&(e=new xt(e.done,e.undone,null,0,-1));let a=n.getMeta("appendedTransaction");if(n.steps.length==0)return e;if(a&&a.getMeta(nt))return a.getMeta(nt).redo?new xt(e.done.addTransform(n,void 0,r,cr(t)),e.undone,Ul(n.mapping.maps),e.prevTime,e.prevComposition):new xt(e.done,e.undone.addTransform(n,void 0,r,cr(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||!vy(n,e.prevRanges)),c=a?co(e.prevRanges,n.mapping):Ul(n.mapping.maps);return new xt(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,cr(t)),Ue.empty,c,n.time,l??e.prevComposition)}else return(s=n.getMeta("rebased"))?new xt(e.done.rebased(n,s),e.undone.rebased(n,s),co(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new xt(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),co(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function vy(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 Ul(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 co(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 Cy(e,t,n){let r=cr(t),o=nt.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 xt(n?l:s.remaining,n?s.remaining:l,null,0,-1);return s.transform.setSelection(a).setMeta(nt,{redo:n,historyState:i})}let uo=!1,Vl=null;function cr(e){let t=e.plugins;if(Vl!=t){uo=!1,Vl=t;for(let n=0;n<t.length;n++)if(t[n].spec.historyPreserveItems){uo=!0;break}}return uo}function Gl(e){return e.setMeta(Pu,!0)}const nt=new fe("history"),Pu=new fe("closeHistory");function Sy(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Z({key:nt,state:{init(){return new xt(Ue.empty,Ue.empty,null,0,-1)},apply(t,n,r){return xy(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(t,n){let r=n.inputType,o=r=="historyUndo"?Ku:r=="historyRedo"?ju:null;return!o||!t.editable?!1:(n.preventDefault(),o(t.state,t.dispatch))}}}})}function Bu(e,t){return(n,r)=>{let o=nt.getState(n);if(!o||(e?o.undone:o.done).eventCount==0)return!1;if(r){let s=Cy(o,n,e);s&&r(t?s.scrollIntoView():s)}return!0}}const Ku=Bu(!1,!0),ju=Bu(!0,!0);function h1(e){let t=nt.getState(e);return t?t.done.eventCount:0}function g1(e){let t=nt.getState(e);return t?t.undone.eventCount:0}function b1(e){return e.getMeta(nt)!=null}function un(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-history",...t}}),e}var Sa=F("Undo",()=>()=>Ku);un(Sa,{displayName:"Command<undo>"});var Ma=F("Redo",()=>()=>ju);un(Ma,{displayName:"Command<redo>"});var Aa=as({},"historyProviderConfig");un(Aa,{displayName:"Ctx<historyProviderConfig>"});var Hu=Q(e=>Sy(e.get(Aa.key)));un(Hu,{displayName:"Ctx<historyProviderPlugin>"});var Na=_e("historyKeymap",{Undo:{shortcuts:"Mod-z",command:e=>{const t=e.get(se);return()=>t.call(Sa.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:e=>{const t=e.get(se);return()=>t.call(Ma.key)}}});un(Na.ctx,{displayName:"KeymapCtx<history>"});un(Na.shortcuts,{displayName:"Keymap<history>"});var My=[Aa,Hu,Na,Sa,Ma].flat(),Ay=typeof global=="object"&&global&&global.Object===Object&&global,Ny=typeof self=="object"&&self&&self.Object===Object&&self,Fu=Ay||Ny||Function("return this")(),Nr=Fu.Symbol,qu=Object.prototype,Ey=qu.hasOwnProperty,Ty=qu.toString,gn=Nr?Nr.toStringTag:void 0;function Iy(e){var t=Ey.call(e,gn),n=e[gn];try{e[gn]=void 0;var r=!0}catch{}var o=Ty.call(e);return r&&(t?e[gn]=n:delete e[gn]),o}var Ly=Object.prototype,Ry=Ly.toString;function $y(e){return Ry.call(e)}var Dy="[object Null]",_y="[object Undefined]",Jl=Nr?Nr.toStringTag:void 0;function zy(e){return e==null?e===void 0?_y:Dy:Jl&&Jl in Object(e)?Iy(e):$y(e)}function Oy(e){return e!=null&&typeof e=="object"}var Py="[object Symbol]";function By(e){return typeof e=="symbol"||Oy(e)&&zy(e)==Py}var Ky=/\s/;function jy(e){for(var t=e.length;t--&&Ky.test(e.charAt(t)););return t}var Hy=/^\s+/;function Fy(e){return e&&e.slice(0,jy(e)+1).replace(Hy,"")}function jo(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Yl=NaN,qy=/^[-+]0x[0-9a-f]+$/i,Wy=/^0b[01]+$/i,Uy=/^0o[0-7]+$/i,Vy=parseInt;function Xl(e){if(typeof e=="number")return e;if(By(e))return Yl;if(jo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=jo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Fy(e);var n=Wy.test(e);return n||Uy.test(e)?Vy(e.slice(2),n?2:8):qy.test(e)?Yl:+e}var fo=function(){return Fu.Date.now()},Gy="Expected a function",Jy=Math.max,Yy=Math.min;function Xy(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(Gy);t=Xl(t)||0,jo(n)&&(u=!!n.leading,d="maxWait"in n,s=d?Jy(Xl(n.maxWait)||0,t):s,f="trailing"in n?!!n.trailing:f);function m(T){var D=r,H=o;return r=o=void 0,c=T,a=e.apply(H,D),a}function p(T){return c=T,l=setTimeout(w,t),u?m(T):a}function h(T){var D=T-i,H=T-c,W=t-D;return d?Yy(W,s-H):W}function g(T){var D=T-i,H=T-c;return i===void 0||D>=t||D<0||d&&H>=s}function w(){var T=fo();if(g(T))return y(T);l=setTimeout(w,h(T))}function y(T){return l=void 0,f&&r?m(T):(r=o=void 0,a)}function C(){l!==void 0&&clearTimeout(l),c=0,r=i=o=l=void 0}function N(){return l===void 0?a:y(fo())}function M(){var T=fo(),D=g(T);if(r=arguments,o=this,i=T,D){if(l===void 0)return p(i);if(d)return clearTimeout(l),l=setTimeout(w,t),m(i)}return l===void 0&&(l=setTimeout(w,t)),a}return M.cancel=C,M.flush=N,M}var Wu=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}},Er=_f(new Wu,"listener"),Qy=new fe("MILKDOWN_LISTENER"),Uu=e=>(e.inject(Er,new Wu),async()=>{await e.wait(zf);const{listeners:t}=e.get(Er);t.beforeMount.forEach(c=>c(e)),await e.wait(Of);const n=e.get(en);let r=null,o=null,s=null,a=null;const l=Xy(()=>{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 Z({key:Qy,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(Pf,c=>c.concat(i)),await e.wait(Bf),t.mounted.forEach(c=>c(e))});Uu.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var Yr=E.createContext({});function Zy(){const{dom:e,editor:t,setLoading:n,editorFactory:r}=E.useContext(Yr),o=E.useRef(null);return E.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 ek=()=>{const e=Zy();return Ei.createElement("div",{"data-milkdown-root":!0,ref:e})},Vu=({children:e})=>{const t=E.useRef(void 0),[n,r]=E.useState(void 0),o=E.useRef(void 0),[s,a]=E.useState(!0),l=E.useMemo(()=>({loading:s,dom:t,editor:o,setLoading:a,editorFactory:n,setEditorFactory:r}),[s,n]);return Ei.createElement(Yr.Provider,{value:l},e)};function tk(e,t=[]){const n=E.useContext(Yr),r=E.useCallback(e,t);return E.useLayoutEffect(()=>{n.setEditorFactory(()=>r)},[n,r]),{loading:n.loading,get:()=>n.editor.current}}function nk(){const e=E.useContext(Yr),t=E.useCallback(()=>e.editor.current,[e.editor]);return[e.loading,t]}const rk=Q(()=>new Z({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 j)||!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(j.create(n.doc,o)),e.dispatch(d.setStoredMarks(c.removeFromSet(i))),!0}}}));function po(e){const t=/^(.*)\|(\d+)$/.exec(e);return t?{label:t[1],width:Number(t[2])}:{label:e}}function ok(e,t){return`${e}|${t}`}class sk{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(Ve.create(this.view.state.doc,l))),this.view.focus())};Gp(this.view,this.dom,s,a)||(s.preventDefault(),a())}),Jp(this.dom,n,()=>this.openSource()),Kf(this.dom,this.img,()=>po(this.node.attrs.alt??"").label||Hf(this.node.attrs.src??"")),this.apply(t)}node;view;getPos;onDestroy;dom;img;drop=null;srcLine=null;apply(t){const{label:n,width:r}=po(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=jf(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 Ve&&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=`![${String(this.node.attrs.alt??"")}](${Zo(t)??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:Ti(o);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}=po(this.node.attrs.alt??""),o=this.view.state.tr.setNodeMarkup(n,void 0,{...this.node.attrs,alt:ok(r,t)});o.setSelection(Ve.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 ak(){return Q(()=>{const e=new Set;return new Z({view:()=>({update:()=>{for(const t of e)t.syncSelection()}}),props:{nodeViews:{image:(t,n,r)=>{let o;return o=new sk(t,n,r,()=>e.delete(o)),e.add(o),o}}}})})}De({"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 Qt="[!fold]-",lk=/^\[![\w-]+\]/;function ik(e,t){return e==="code_block"?!1:e!=="heading"||t.kind!=="ordered"}function Gu(e){return e.parent.textBetween(0,e.parentOffset,void 0,"")}const ck={"【":"[","】":"]","》":">","|":"|","·":"`","¥":"$","#":"#"};function uk(e){return/^\d{1,9}。$/.test(e)?`${e.slice(0,-1)}.`:e.replace(/[【】》|·¥#]/g,t=>ck[t]??t)}function dk(e){const t=uk(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 fk(e){const t=dk(Gu(e));return t?.kind==="fold"&&e.parentOffset<e.parent.content.size?{kind:"quote",rejoin:!0}:t}function pk(e,t,n){const r=e.state.selection.$from.start();n&&e.dispatch(e.state.tr.insertText(n)),e.dispatch(Gl(e.state.tr));const o=Kt(e,t,{from:r,to:e.state.selection.from});return e.dispatch(Gl(e.state.tr)),o||!!n}function Ea(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 Ql(e,t){const n=Gu(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 mk(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+=`
28
+ `);const o=t.topNodeType.createAndFill(void 0,n.content);return o?r(o):""}}})});gy(zu,{displayName:"Prose<clipboard>"});var Ar=200,Ne=function(){};Ne.prototype.append=function(t){return t.length?(t=Ne.from(t),!this.length&&t||t.length<Ar&&this.leafAppend(t)||this.length<Ar&&t.leafPrepend(this)||this.appendInner(t)):this};Ne.prototype.prepend=function(t){return t.length?Ne.from(t).append(this):this};Ne.prototype.appendInner=function(t){return new by(this,t)};Ne.prototype.slice=function(t,n){return t===void 0&&(t=0),n===void 0&&(n=this.length),t>=n?Ne.empty:this.sliceInner(Math.max(0,t),Math.min(this.length,n))};Ne.prototype.get=function(t){if(!(t<0||t>=this.length))return this.getInner(t)};Ne.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)};Ne.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};Ne.from=function(t){return t instanceof Ne?t:t&&t.length?new Ou(t):Ne.empty};var Ou=(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<=Ar)return new t(this.values.concat(o.flatten()))},t.prototype.leafPrepend=function(o){if(this.length+o.length<=Ar)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})(Ne);Ne.empty=new Ou([]);var by=(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})(Ne);const yy=500;class Ue{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 Qe(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 Qe(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 Ue(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 Qe(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>wy&&(l=ky(l,c),a-=c),new Ue(l.append(s),a)}remapping(t,n){let r=new Df;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 Ue(this.items.append(t.map(n=>new Qe(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 Qe(p,h,g))}else r.push(new Qe(p))},o);let c=[];for(let f=n;f<a;f++)c.push(new Qe(s.maps[f]));let u=this.items.slice(0,o).append(c).append(r),d=new Ue(u,l);return d.emptyItemCount()>yy&&(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 Qe(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 Ue(Ne.from(o.reverse()),s)}}Ue.empty=new Ue(Ne.empty,0);function ky(e,t){let n;return e.forEach((r,o)=>{if(r.selection&&t--==0)return n=o,!1}),e.slice(n)}class Qe{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 Qe(n.getMap().invert(),n,this.selection)}}}class xt{constructor(t,n,r,o,s){this.done=t,this.undone=n,this.prevRanges=r,this.prevTime=o,this.prevComposition=s}}const wy=20;function xy(e,t,n,r){let o=n.getMeta(nt),s;if(o)return o.historyState;n.getMeta(Pu)&&(e=new xt(e.done,e.undone,null,0,-1));let a=n.getMeta("appendedTransaction");if(n.steps.length==0)return e;if(a&&a.getMeta(nt))return a.getMeta(nt).redo?new xt(e.done.addTransform(n,void 0,r,cr(t)),e.undone,Ul(n.mapping.maps),e.prevTime,e.prevComposition):new xt(e.done,e.undone.addTransform(n,void 0,r,cr(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||!vy(n,e.prevRanges)),c=a?co(e.prevRanges,n.mapping):Ul(n.mapping.maps);return new xt(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,cr(t)),Ue.empty,c,n.time,l??e.prevComposition)}else return(s=n.getMeta("rebased"))?new xt(e.done.rebased(n,s),e.undone.rebased(n,s),co(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new xt(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),co(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function vy(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 Ul(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 co(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 Cy(e,t,n){let r=cr(t),o=nt.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 xt(n?l:s.remaining,n?s.remaining:l,null,0,-1);return s.transform.setSelection(a).setMeta(nt,{redo:n,historyState:i})}let uo=!1,Vl=null;function cr(e){let t=e.plugins;if(Vl!=t){uo=!1,Vl=t;for(let n=0;n<t.length;n++)if(t[n].spec.historyPreserveItems){uo=!0;break}}return uo}function Gl(e){return e.setMeta(Pu,!0)}const nt=new fe("history"),Pu=new fe("closeHistory");function Sy(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Z({key:nt,state:{init(){return new xt(Ue.empty,Ue.empty,null,0,-1)},apply(t,n,r){return xy(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(t,n){let r=n.inputType,o=r=="historyUndo"?Ku:r=="historyRedo"?ju:null;return!o||!t.editable?!1:(n.preventDefault(),o(t.state,t.dispatch))}}}})}function Bu(e,t){return(n,r)=>{let o=nt.getState(n);if(!o||(e?o.undone:o.done).eventCount==0)return!1;if(r){let s=Cy(o,n,e);s&&r(t?s.scrollIntoView():s)}return!0}}const Ku=Bu(!1,!0),ju=Bu(!0,!0);function h1(e){let t=nt.getState(e);return t?t.done.eventCount:0}function g1(e){let t=nt.getState(e);return t?t.undone.eventCount:0}function b1(e){return e.getMeta(nt)!=null}function un(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-history",...t}}),e}var Sa=F("Undo",()=>()=>Ku);un(Sa,{displayName:"Command<undo>"});var Ma=F("Redo",()=>()=>ju);un(Ma,{displayName:"Command<redo>"});var Aa=as({},"historyProviderConfig");un(Aa,{displayName:"Ctx<historyProviderConfig>"});var Hu=Q(e=>Sy(e.get(Aa.key)));un(Hu,{displayName:"Ctx<historyProviderPlugin>"});var Na=_e("historyKeymap",{Undo:{shortcuts:"Mod-z",command:e=>{const t=e.get(se);return()=>t.call(Sa.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:e=>{const t=e.get(se);return()=>t.call(Ma.key)}}});un(Na.ctx,{displayName:"KeymapCtx<history>"});un(Na.shortcuts,{displayName:"Keymap<history>"});var My=[Aa,Hu,Na,Sa,Ma].flat(),Ay=typeof global=="object"&&global&&global.Object===Object&&global,Ny=typeof self=="object"&&self&&self.Object===Object&&self,Fu=Ay||Ny||Function("return this")(),Nr=Fu.Symbol,qu=Object.prototype,Ey=qu.hasOwnProperty,Ty=qu.toString,gn=Nr?Nr.toStringTag:void 0;function Iy(e){var t=Ey.call(e,gn),n=e[gn];try{e[gn]=void 0;var r=!0}catch{}var o=Ty.call(e);return r&&(t?e[gn]=n:delete e[gn]),o}var Ly=Object.prototype,Ry=Ly.toString;function $y(e){return Ry.call(e)}var Dy="[object Null]",_y="[object Undefined]",Yl=Nr?Nr.toStringTag:void 0;function zy(e){return e==null?e===void 0?_y:Dy:Yl&&Yl in Object(e)?Iy(e):$y(e)}function Oy(e){return e!=null&&typeof e=="object"}var Py="[object Symbol]";function By(e){return typeof e=="symbol"||Oy(e)&&zy(e)==Py}var Ky=/\s/;function jy(e){for(var t=e.length;t--&&Ky.test(e.charAt(t)););return t}var Hy=/^\s+/;function Fy(e){return e&&e.slice(0,jy(e)+1).replace(Hy,"")}function jo(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Jl=NaN,qy=/^[-+]0x[0-9a-f]+$/i,Wy=/^0b[01]+$/i,Uy=/^0o[0-7]+$/i,Vy=parseInt;function Xl(e){if(typeof e=="number")return e;if(By(e))return Jl;if(jo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=jo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Fy(e);var n=Wy.test(e);return n||Uy.test(e)?Vy(e.slice(2),n?2:8):qy.test(e)?Jl:+e}var fo=function(){return Fu.Date.now()},Gy="Expected a function",Yy=Math.max,Jy=Math.min;function Xy(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(Gy);t=Xl(t)||0,jo(n)&&(u=!!n.leading,d="maxWait"in n,s=d?Yy(Xl(n.maxWait)||0,t):s,f="trailing"in n?!!n.trailing:f);function m(T){var D=r,H=o;return r=o=void 0,c=T,a=e.apply(H,D),a}function p(T){return c=T,l=setTimeout(w,t),u?m(T):a}function h(T){var D=T-i,H=T-c,W=t-D;return d?Jy(W,s-H):W}function g(T){var D=T-i,H=T-c;return i===void 0||D>=t||D<0||d&&H>=s}function w(){var T=fo();if(g(T))return y(T);l=setTimeout(w,h(T))}function y(T){return l=void 0,f&&r?m(T):(r=o=void 0,a)}function C(){l!==void 0&&clearTimeout(l),c=0,r=i=o=l=void 0}function N(){return l===void 0?a:y(fo())}function M(){var T=fo(),D=g(T);if(r=arguments,o=this,i=T,D){if(l===void 0)return p(i);if(d)return clearTimeout(l),l=setTimeout(w,t),m(i)}return l===void 0&&(l=setTimeout(w,t)),a}return M.cancel=C,M.flush=N,M}var Wu=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}},Er=_f(new Wu,"listener"),Qy=new fe("MILKDOWN_LISTENER"),Uu=e=>(e.inject(Er,new Wu),async()=>{await e.wait(zf);const{listeners:t}=e.get(Er);t.beforeMount.forEach(c=>c(e)),await e.wait(Of);const n=e.get(en);let r=null,o=null,s=null,a=null;const l=Xy(()=>{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 Z({key:Qy,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(Pf,c=>c.concat(i)),await e.wait(Bf),t.mounted.forEach(c=>c(e))});Uu.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var Jr=E.createContext({});function Zy(){const{dom:e,editor:t,setLoading:n,editorFactory:r}=E.useContext(Jr),o=E.useRef(null);return E.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 ek=()=>{const e=Zy();return Ei.createElement("div",{"data-milkdown-root":!0,ref:e})},Vu=({children:e})=>{const t=E.useRef(void 0),[n,r]=E.useState(void 0),o=E.useRef(void 0),[s,a]=E.useState(!0),l=E.useMemo(()=>({loading:s,dom:t,editor:o,setLoading:a,editorFactory:n,setEditorFactory:r}),[s,n]);return Ei.createElement(Jr.Provider,{value:l},e)};function tk(e,t=[]){const n=E.useContext(Jr),r=E.useCallback(e,t);return E.useLayoutEffect(()=>{n.setEditorFactory(()=>r)},[n,r]),{loading:n.loading,get:()=>n.editor.current}}function nk(){const e=E.useContext(Jr),t=E.useCallback(()=>e.editor.current,[e.editor]);return[e.loading,t]}const rk=Q(()=>new Z({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 j)||!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(j.create(n.doc,o)),e.dispatch(d.setStoredMarks(c.removeFromSet(i))),!0}}}));function po(e){const t=/^(.*)\|(\d+)$/.exec(e);return t?{label:t[1],width:Number(t[2])}:{label:e}}function ok(e,t){return`${e}|${t}`}class sk{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(Ve.create(this.view.state.doc,l))),this.view.focus())};Gp(this.view,this.dom,s,a)||(s.preventDefault(),a())}),Yp(this.dom,n,()=>this.openSource()),Kf(this.dom,this.img,()=>po(this.node.attrs.alt??"").label||Hf(this.node.attrs.src??"")),this.apply(t)}node;view;getPos;onDestroy;dom;img;drop=null;srcLine=null;apply(t){const{label:n,width:r}=po(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=jf(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 Ve&&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=`![${String(this.node.attrs.alt??"")}](${Zo(t)??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:Ti(o);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}=po(this.node.attrs.alt??""),o=this.view.state.tr.setNodeMarkup(n,void 0,{...this.node.attrs,alt:ok(r,t)});o.setSelection(Ve.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 ak(){return Q(()=>{const e=new Set;return new Z({view:()=>({update:()=>{for(const t of e)t.syncSelection()}}),props:{nodeViews:{image:(t,n,r)=>{let o;return o=new sk(t,n,r,()=>e.delete(o)),e.add(o),o}}}})})}De({"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 Qt="[!fold]-",lk=/^\[![\w-]+\]/;function ik(e,t){return e==="code_block"?!1:e!=="heading"||t.kind!=="ordered"}function Gu(e){return e.parent.textBetween(0,e.parentOffset,void 0,"")}const ck={"【":"[","】":"]","》":">","|":"|","·":"`","¥":"$","#":"#"};function uk(e){return/^\d{1,9}。$/.test(e)?`${e.slice(0,-1)}.`:e.replace(/[【】》|·¥#]/g,t=>ck[t]??t)}function dk(e){const t=uk(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 fk(e){const t=dk(Gu(e));return t?.kind==="fold"&&e.parentOffset<e.parent.content.size?{kind:"quote",rejoin:!0}:t}function pk(e,t,n){const r=e.state.selection.$from.start();n&&e.dispatch(e.state.tr.insertText(n)),e.dispatch(Gl(e.state.tr));const o=Kt(e,t,{from:r,to:e.state.selection.from});return e.dispatch(Gl(e.state.tr)),o||!!n}function Ea(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 Ql(e,t){const n=Gu(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 mk(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
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 hk(e){const{state:t}=e,n=t.selection.from;if(!Tr(t.selection.$from,["list_item","blockquote"]))return!1;const r=t.tr,o=ur(r,n,["list_item","blockquote"]);return r.steps.length?(r.setSelection(ce.near(r.doc.resolve(o))),e.dispatch(r.scrollIntoView()),!0):!1}function gk(e,t){const{state:n}=e,r=n.selection.to;if(r>=ce.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
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 bk(e){for(const t of e){if(t.name==="heading")return O("blocklabel.heading",{n:String(t.level??1)});if(t.name==="code_block")return O("blocklabel.code");if(t.name==="list_item"&&t.checked!=null)return O("blocklabel.todo");if(t.name==="ordered_list")return O("blocklabel.ordered");if(t.name==="bullet_list")return O("blocklabel.bullet");if(t.name==="blockquote")return O("blocklabel.quote")}return O("blocklabel.text")}function wn(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}const Tr=(e,t)=>t.some(n=>wn(e,n)!==null);function ur(e,t,n){let r=t;for(let o=0;o<32;o++){const s=e.doc.resolve(r);if(!Tr(s,n))break;const a=s.blockRange(),l=a?ns(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 Kt(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=wn(p,"list_item");if(h!==null&&(t.kind==="bullet"||t.kind==="ordered"||t.kind==="task")){const N=p.node(h);if(t.kind==="task")f.setNodeMarkup(p.before(h),void 0,{...N.attrs,checked:t.checked??!1});else{const M=h-1,T=p.node(M),D=t.kind==="bullet"?c:u;if(!D||M<1||!/_list$/.test(T.type.name))return!1;const H=t.kind==="ordered"?{order:t.order??1,spread:!1}:{spread:!1};f.setNodeMarkup(p.before(M),D,H),f.setNodeMarkup(p.before(h),void 0,{...N.attrs,checked:null})}return e.dispatch(f.scrollIntoView()),!0}if(t.kind==="heading"||t.kind==="text"){const N=t.kind==="heading"?l:a;if(!N||Tr(p,["list_item","blockquote"])&&(m=ur(f,m,["list_item","blockquote"]),p=f.doc.resolve(m),!p.parent.isTextblock))return!1;const M=p.index(-1);return p.node(-1).canReplaceWith(M,M+1,N)?(f.setBlockType(p.before(),p.after(),N,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 N=s.nodes.code_block;if(t.kind==="code"&&!N)return!1;let M=f.doc.resolve(m);if(t.kind==="code"&&Tr(M,["list_item"])&&(m=ur(f,m,["list_item"]),M=f.doc.resolve(m)),!M.parent.isTextblock)return!1;const T=f.doc.textBetween(M.pos,M.end(),`
31
31
  `,`
32
32
  `);T&&f.delete(M.pos,M.end()),M=f.doc.resolve(f.mapping.map(m));const D=M.before(),H=M.after();let W;if(t.kind==="math")f.insertText("$$ $$",D+1),f.setSelection(ce.near(f.doc.resolve(D+4))),W=f.mapping.map(H);else{const $=N.create({language:t.lang||null});f.replaceWith(D,H,$),f.setSelection(ce.near(f.doc.resolve(D+1))),W=D+$.nodeSize}return T&&f.insert(W,a.create(null,s.text(T))),e.dispatch(f.scrollIntoView()),!0}if(t.kind==="quote"||t.kind==="fold"){if(!i)return!1;if(wn(p,"blockquote")===null){if(wn(p,"list_item")!==null&&(m=ur(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 N=p.blockRange(),M=N&&wo(N,i);if(!M)return!1;const T=f.steps.length;if(f.wrap(N,M),m=f.mapping.slice(T).map(m),p=f.doc.resolve(m),t.rejoin){const D=wn(p,"blockquote");if(D!==null){const H=p.after(D);f.doc.resolve(H).nodeAfter?.type===i&&ar(f.doc,H)&&f.join(H);const W=p.before(D);f.doc.resolve(W).nodeBefore?.type===i&&ar(f.doc,W)&&f.join(W)}}}if(t.kind==="fold"&&!lk.test(p.parent.textContent)){const N=p.start();f.insertText(Qt,N),f.setSelection(ce.near(f.doc.resolve(N+Qt.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 w=p.blockRange(),y=w&&wo(w,g,t.kind==="ordered"?{order:t.order??1}:void 0);if(!y)return!1;if(f.wrap(w,y),t.kind==="task"){const N=f.doc.nodeAt(w.start+1);N&&N.type.name==="list_item"&&f.setNodeMarkup(w.start+1,void 0,{...N.attrs,checked:t.checked??!1})}const C=f.doc.resolve(w.start).nodeBefore;return C&&C.type===g&&ar(f.doc,w.start)&&f.join(w.start),e.dispatch(f.scrollIntoView()),!0}function y1(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 w=n.kind==="task"?{checked:n.checked??!1}:null,y=f.filter(N=>N.trim()),C=(y.length?y:[""]).map(N=>d.create(w,m(N)));p=[g.create(n.kind==="ordered"?{order:n.order??1}:null,C)]}else if(n.kind==="quote"||n.kind==="fold"){if(!i)return!1;p=[i.create(null,n.kind==="fold"?[a.create(null,s.text(Qt)),o]:[o])]}else return!1;const h=r.tr;try{h.replaceWith(t,t+o.nodeSize,p)}catch{return!1}return h.setSelection(ce.near(h.doc.resolve(Math.min(t+1,h.doc.content.size)))),e.dispatch(h.scrollIntoView()),!0}De({"structsrc.prefixAriaLabel":{zh:"Markdown 标记",en:"Markdown marker"}});const jt=new fe("amadeus-structural-source");function Ju(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 Ho(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}function Yu(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 Ju(t.parent,t.before());const r=Ho(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=Ho(t,"blockquote");if(o!==null){const s=t.node(o),a=t.before(o);return{source:"> ",widgetPos:n,decorateFrom:a,decorateTo:a+s.nodeSize,kind:"quote"}}return null}function yk(e){const{$from:t,$to:n}=e.selection;return t.parent.type.name!=="heading"||n.parent.type.name!=="heading"||t.before()!==n.before()?null:Ju(t.parent,t.before())}function Fo(e){e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(jt,{refresh:!0}))}function Xu(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(j.create(e.state.doc,t.widgetPos))),!0}function Ir(e){e.style.setProperty("--amx-prefix-ch",String(Math.max(2,e.value.length+.4)))}function kk(e,t,n){const r=Ea(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",!Xu(e,n)||!Kt(e,r,null))return t.value=t.dataset.original??n.source,Ir(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",Ir(a),a.focus({preventScroll:!0}),a.setSelectionRange(Math.min(o,a.value.length),Math.min(s,a.value.length)),!0}function wk(e,t){let n=!1;return Kt(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(j.create(o.doc,l+t.length)),n=!0})&&n}function xn(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=Ea(r);a?Kt(e,a,null):s=wk(e,r)}if(e.dispatch(e.state.tr.setMeta(jt,{openAt:null})),n){e.focus();const{$from:a}=e.state.selection;!s&&a.parent.isTextblock&&e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,a.start())).scrollIntoView())}}let qo=!1;function Zl(e,t){qo=!0;try{return e.someProp("handleKeyDown",n=>n(e,t))??!1}finally{qo=!1}}function xk(e,t,n){if(xn(e,t,!0),n.key==="Backspace"){Zl(e,n);return}const r=n.key==="ArrowDown"?1:-1;if(r>0&&!e.endOfTextblock("down")||Zl(e,n))return;const{$from:o}=e.state.selection;if(!o.parent.isTextblock)return;const s=r>0?o.after():o.before(),a=ce.findFrom(e.state.doc.resolve(s),r,!0);a&&e.dispatch(e.state.tr.setSelection(a).scrollIntoView())}function ei(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",O("structsrc.prefixAriaLabel")),n.setAttribute("autocomplete","off"),n.setAttribute("autocapitalize","off"),n.spellcheck=!1,Ir(n),n.addEventListener("focus",()=>{n.dataset.committed="0",Xu(e,t)});const r=o=>{o?.isComposing||kk(e,n,t)||Ea(n.value)||xn(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,Ir(n),xn(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??"");xn(e,n,!0),o.key==="Enter"&&c&&!o.isComposing&&e.someProp("handleKeyDown",u=>u(e,o))}}),n.addEventListener("blur",()=>{xn(e,n,!1),queueMicrotask(()=>Fo(e))}),n}function vk(e,t){const n=[],r=jt.getState(e)?.openAt,o=t.hasFocus()||t.dom.contains(document.activeElement),s=yk(e),a=s&&(o||r===s.widgetPos)?s:null;if(a){const l=a;n.push(J.widget(l.widgetPos,()=>ei(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}if(r!=null){const l=Yu(e);l&&l.kind!=="heading"&&l.widgetPos===r&&e.doc.nodeAt(l.decorateFrom)&&n.push(J.node(l.decorateFrom,l.decorateTo,{class:`amx-struct-source-open amx-struct-source-${l.kind}`}),J.widget(l.widgetPos,()=>ei(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}return n.length?me.create(e.doc,n):me.empty}function Ck(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(j.create(e.state.doc,r))),!0)}function ti(e,t=!1){if(qo||!Ck(e))return!1;const n=Yu(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"?Ho(s,"blockquote"):null;if((n.kind!=="quote"||a!==null&&s.node(a).childCount===1)&&Kt(e,{kind:"text"},null))return!0}e.dispatch(e.state.tr.setMeta(jt,{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(jt,{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 Sk(){return Q(()=>{let e=null;return new Z({key:jt,view:t=>(e=t,{destroy:()=>{e===t&&(e=null)}}),state:{init:()=>({openAt:null}),apply:(t,n)=>{const r=t.getMeta(jt);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?vk(t,e):me.empty,handleDOMEvents:{focus:t=>(queueMicrotask(()=>Fo(t)),!1),blur:t=>(queueMicrotask(()=>Fo(t)),!1)}}})})}function Wo(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 Qu(e){const t=Wo(e.$from);if(e.empty)return t;const n=Wo(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 Mk(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 Ak(e){return!e.code&&!e.tableCell}function Nk(e,t){return e==="instructions"||e==="columns"?t.topLevel:e==="card"?!t.listItem&&!t.column:!0}function k1(e){const t=e.node;return t?e.$from.depth===0&&!/^amadeus(CanvasCard|ColumnRow)$/.test(t.type.name):!1}function w1(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 Uo=new WeakMap;function x1(e,t){Uo.set(e,t)}function ni(e,t){const n=Uo.get(e);return Uo.delete(e),n===t}De({"wikiac.multiBlocks":{zh:"多个块",en:"Multiple blocks"}});const Ek=ue(()=>new Ye(/【【$/,(e,t,n,r)=>e.tr.insertText("[[",n,r),{inCodeMark:!1}));function qt(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 Jn=e=>({handleDOMEvents:{blur:()=>(e(null,!0),!1)}});function Tk(e){return Q(()=>new Z({props:Jn(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)||qt(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 Ik(e){return Q(()=>new Z({props:Jn(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=Wo(r);if(!Ak(o))return e(null);const s=r.parent.textBetween(0,r.parentOffset,void 0,""),a=s.lastIndexOf("/");if(a<0||qt(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 Lk(e){return Q(()=>new Z({props:Jn(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||qt(t.state,r.start()+s,n.head)||s>0&&tm.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 Rk=/^!\[\[[^\]\n|]+\.(png|jpe?g|gif|webp|svg|avif|bmp)(\|\d+)?\]\]$/i,ri=()=>!!document.activeElement?.closest?.(".inline-toolbar");function $k(e){const t=e.selection;return t instanceof Ve?t.node.type.name==="image":Rk.test(e.doc.textBetween(t.from,t.to))}const dr=new fe("amx-toolbar-dismissed");function Dk(e){return Q(()=>{let t=!1;const n=r=>{if(t||dr.getState(r.state))return e(null);const{selection:o,doc:s}=r.state;if(o.empty||!r.editable)return e(null);if(!r.hasFocus()&&!ri()){setTimeout(()=>{!r.isDestroyed&&!r.hasFocus()&&!ri()&&e(null)},0);return}if($k(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 w=i.depth;w>0;w--){const y=i.node(w);f.push({name:y.type.name,level:y.attrs.level,checked:y.attrs.checked??null})}const m=[];for(const w of["strong","emphasis","inlineCode","strike_through","amadeusUnderline","link"]){const y=r.state.schema.marks[w];if(!y)continue;let C=!0,N=!1;s.nodesBetween(a,l,M=>(M.isText&&(N=!0,y.isInSet(M.marks)||(C=!1)),!0)),N&&C&&m.push(w)}const p=new Set;s.nodesBetween(a,l,w=>((w.type.name==="paragraph"||w.type.name==="heading")&&p.add(w.attrs.align==="center"||w.attrs.align==="right"?w.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=(w,y)=>{const C=r.state.schema.marks[w];if(!C)return;const N=new Set;return s.nodesBetween(a,l,M=>(M.isText&&N.add(String(C.isInSet(M.marks)?.attrs[y]??"")),!0)),N.size===1&&[...N][0]||void 0};e({from:a,to:l,active:m,align:h,shape:Mk(Qu(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?O("wikiac.multiBlocks"):bk(f)})};return new Z({key:dr,state:{init:()=>!1,apply:(r,o,s,a)=>r.getMeta(dr)?!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})})})}De({"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.aria":{zh:"文字格式",en:"Text formatting"}});const _k=[{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"}],zk=[{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"}],Ok={turnInto:!0,format:!0,link:!0,color:!0,align:!0},Zu=[{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"}],Pk=Object.fromEntries(Zu.map(e=>[e.k,e.labelKey]));function Bk({left:e,top:t,bottom:n,kind:r,active:o,align:s,shape:a=Ok,fg:l,bg:i,onAct:c,onColor:u,onBg:d,onClose:f,onReturnFocus:m,onAsk:p,ai:h}){const{t:g}=rn(),[w,y]=E.useState(null),C=E.useRef(null),N=E.useRef(!1);E.useEffect(()=>{const $=te=>{if(te.key==="Escape"){te.preventDefault(),te.stopPropagation();const Te=C.current,ze=!!Te&&Te.contains(document.activeElement);if(w&&ze){const ge=Te.querySelector(`[data-panel="${w}"]`);y(null),ge?.focus();return}f(),ze&&m?.()}};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[f,m,w]),E.useEffect(()=>{!w||!N.current||(N.current=!1,C.current?.querySelector(".itb-panel button")?.focus())},[w]);const M=$=>o?.includes($)?" on":"",T=$=>te=>{te.preventDefault(),$()},D=$=>({onMouseDown:T($),onClick:te=>{te.detail===0&&$()}}),H=$=>({onMouseDown:T(()=>y(w===$?null:$)),onClick:te=>{te.detail===0&&(N.current=w!==$,y(w===$?null:$))},"aria-haspopup":"menu","aria-expanded":w===$,"data-panel":$}),W=$=>{const te=$.target.closest(".itb-row, .itb-panel");if(!te||!(te.classList.contains("itb-panel")?["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]:["ArrowRight","ArrowLeft","Home","End"]).includes($.key))return;const ge=[...te.querySelectorAll(":scope > button, :scope > * > button")],ie=ge.indexOf(document.activeElement),pe=$.key==="ArrowRight"||$.key==="ArrowDown",Ae=$.key==="Home"?0:$.key==="End"?ge.length-1:ie<0?0:(ie+(pe?1:-1)+ge.length)%ge.length;$.preventDefault(),$.stopPropagation(),ge[Ae]?.focus()};return b.jsxs(on,{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",innerRef:$=>{C.current=$},onKeyDown:W,children:[b.jsxs("div",{className:"itb-row",children:[p&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:"itb-btn itb-ask",title:g("itb.askTanguTitle"),"data-act":"ask",...D(p),children:g("itb.askTangu")}),!h&&b.jsx("span",{className:"itb-sep"})]}),h&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{className:"itb-btn itb-ask",title:g("itb.aiTitle"),"data-act":"ai",...H("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}`,...H("turn"),children:[r," ▾"]}),b.jsx("span",{className:"itb-sep"})]}),a.format&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:`itb-btn${M("strong")}`,style:{fontWeight:700},title:g("itb.bold"),"data-act":"bold","aria-label":g("itb.bold"),"aria-pressed":!!o?.includes("strong"),...D(()=>c("bold")),children:"B"}),b.jsx("button",{className:`itb-btn${M("emphasis")}`,style:{fontStyle:"italic"},title:g("itb.italic"),"data-act":"italic","aria-label":g("itb.italic"),"aria-pressed":!!o?.includes("emphasis"),...D(()=>c("italic")),children:"I"}),b.jsx("button",{className:`itb-btn${M("amadeusUnderline")}`,style:{textDecoration:"underline"},title:g("itb.underline"),"data-act":"underline","aria-label":g("itb.underline"),"aria-pressed":!!o?.includes("amadeusUnderline"),...D(()=>c("underline")),children:"U"}),b.jsx("button",{className:`itb-btn${M("strike_through")}`,style:{textDecoration:"line-through"},title:g("itb.strike"),"data-act":"strike","aria-label":g("itb.strike"),"aria-pressed":!!o?.includes("strike_through"),...D(()=>c("strike")),children:"S"}),b.jsx("button",{className:`itb-btn${M("inlineCode")}`,title:g("itb.code"),"data-act":"code","aria-label":g("itb.code"),"aria-pressed":!!o?.includes("inlineCode"),...D(()=>c("code")),children:"</>"})]}),a.link&&b.jsx("button",{className:`itb-btn${M("link")}`,title:g("itb.link"),"aria-label":g("itb.link"),"aria-pressed":!!o?.includes("link"),"data-act":"link",...D(()=>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,...H("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",...D(()=>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",...D(()=>c("alignLeft")),children:b.jsx(Ff,{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",...D(()=>c("alignCenter")),children:b.jsx(cm,{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",...D(()=>c("alignRight")),children:b.jsx(dm,{size:14})})]})]}),w==="turn"&&b.jsx("div",{className:"itb-panel",role:"menu","aria-label":g("itb.turnInto"),children:Zu.map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,...D(()=>{y(null),c($.k)}),children:g($.labelKey)},$.k))}),w==="ai"&&h&&b.jsxs("div",{className:"itb-panel itb-ai-menu",role:"menu","data-testid":"itb-ai-menu",children:[h.items.filter($=>!$.plugin).map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":$.id,...D(()=>{y(null),h.onPick($.id)}),children:$.label},$.id)),h.items.some($=>$.plugin)&&b.jsx("div",{className:"itb-color-head",children:g("itb.aiPlugins")}),h.items.filter($=>$.plugin).map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":$.id,...D(()=>{y(null),h.onPick($.id)}),children:$.label},$.id))]}),w==="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:_k.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",...D(()=>{y(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:zk.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",...D(()=>{y(null),d($.v)}),children:b.jsx("span",{className:"itb-swatch-bg",style:{background:$.v||"transparent"}})},$.v||"def"))})]})]})}const vn=["basic","ai","plugin"];function ed(e){return e.category??"basic"}function Kk(e,t){return t.trim()&&e.length?ed(e[0]):"basic"}function jk(e,t){if(t!=="ArrowLeft"&&t!=="ArrowRight")return null;const n=vn.indexOf(e);return vn[(n+(t==="ArrowRight"?1:-1)+vn.length)%vn.length]}function Hk(e,t,n){return!e||n!=="ArrowUp"&&n!=="ArrowDown"?null:Math.max(0,Math.min(e-1,t+(n==="ArrowDown"?1:-1)))}const Fk=8,qk=2;function Wk(e,t,n=Fk){const r=[];for(const l of e){if(l.alias&&!t.trim())continue;const i=ft(t,l.base),c=i!==null?i+1e3:ft(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,qk);return a.length?[...s.slice(0,n-a.length),...a]:s}De({"dateq.schedule":{zh:"日程",en:"Schedule"},"dateq.remind":{zh:"提醒",en:"Remind me"},"dateq.today":{zh:"今天",en:"Today"},"dateq.tomorrow":{zh:"明天",en:"Tomorrow"}});const St=e=>String(e).padStart(2,"0"),$n=e=>`${e.getFullYear()}-${St(e.getMonth()+1)}-${St(e.getDate())}`,Vo=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),Uk=/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/,Vk=/^(\d{4})年(\d{1,2})月(\d{1,2})(?:日|号)?$/,Gk=/^(\d{1,2})[-/.](\d{1,2})$/,Jk=/^(\d{1,2})月(\d{1,2})(?:日|号)?$/,Yk=/^(\d{4})(\d{2})(\d{2})$/,Xk=/^(\d{1,2})(?:日|号)?$/,Qk={昨天:-1,yesterday:-1,今天:0,today:0,明天:1,tomorrow:1,后天:2};function oi(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 Zk(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 $n(o)}return null}function si(e,t){const n=e.trim().toLowerCase(),r=Qk[n];if(r!==void 0)return $n(Vo(t,r));const o=(a,l,i)=>{const c=`${Number(a)}-${St(Number(l))}-${St(Number(i))}`;return Uf(c)?c:null};let s=Uk.exec(n);return s||(s=Vk.exec(n),s)||(s=Yk.exec(n),s)?o(s[1],s[2],s[3]):(s=Gk.exec(n),s||(s=Jk.exec(n),s)?o(t.getFullYear(),s[1],s[2]):(s=Xk.exec(n),s?Zk(Number(s[1]),t):null))}function ai(e,t=new Date){const n=e.normalize("NFKC").trim();if(!n)return null;const r=si(n,t);if(r)return r;const o=oi(n);if(o)return`${$n(t)}T${St(o.hour)}:${St(o.minute)}`;const s=/^(.+?)(?:[tT]|\s+)(\S.+)$/.exec(n)??/^(.+?(?:日|号))\s*(\d{1,2}(?:点|时).*)$/.exec(n);if(s){const a=si(s[1],t),l=oi(s[2]);if(a&&l)return`${a}T${St(l.hour)}:${St(l.minute)}`}return null}const ew=[{key:"dateq.today",words:["today","今天"],days:0},{key:"dateq.tomorrow",words:["tomorrow","明天"],days:1}],tw=["remind","提醒"];function nw(e,t=new Date){const n=e.trim(),r=u=>qf(Wf(u)),o=u=>{const d=u.includes("T")?u:`${u}T09:00`;return{insert:`@remind:${d}`,label:O("dateq.remind"),hint:r(d)}},s=$n(Vo(t,1));if(/^remind:/i.test(n)){const u=n.length===7?s:ai(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 ew){if(!l(u.words))continue;const d=$n(Vo(t,u.days));i.push({insert:`@${d}`,label:O(u.key),hint:r(d)})}if(l(tw)&&i.push(o(s)),i.length)return i;const c=ai(n,t);return c?[{insert:`@${c}`,label:O("dateq.schedule"),hint:r(c)},o(c)]:[]}let bn=null;function rw(){const e=En(s=>s.vaultRoot),t=En(s=>s.linkGraphVersion),n=`${e??""}\0${t}`,[r,o]=E.useState(()=>bn?.map??{});return E.useEffect(()=>{if(bn?.key===n){o(bn.map);return}let s=!0;return Oe?.pageAliases?.().then(a=>{bn={key:n,map:a??{}},s&&o(bn.map)}).catch(()=>{}),()=>{s=!1}},[n]),r}function ow(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 Go=e=>e.replace(/[[\]|#^]/g," ").replace(/\s+/g," ").trim();function sw(e){const t=[],n=new Set;return $r(Li(e),r=>{const o=/^ {0,3}(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/.exec(r);if(o){const s=Go(Ii(o[2]));s&&!n.has(s)&&(n.add(s),t.push({level:o[1].length,text:s}))}return r}),t}function aw(e){const t=[],n=new Set;return $r(Li(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:Ii(r.slice(0,o.index))})),r}),t}De({"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.create":{zh:"新建链接 “{q}”",en:"New link “{q}”"},"wiki.aliasOf":{zh:"别名 → {name}",en:"Alias → {name}"}});function lw(e,t){const[n,r]=E.useState(null);return E.useEffect(()=>{if(!e||!t){r(null);return}let o=!0;const s=l=>{if(o){if(l==null){r([]);return}r(t==="heading"?sw(l).map(i=>({label:i.text,insert:i.text,hint:`H${i.level}`})):aw(l).map(i=>({label:`^${i.id}`,insert:`^${i.id}`,hint:i.preview})))}},a=t==="heading"?rf(e):null;if(a)r(a.map(l=>({label:Go(l.text),insert:Go(l.text),hint:`H${l.level}`})).filter(l=>l.insert));else{const l=of(e);l!=null?s(l):Oe?.readTextFile?.(e).then(i=>s(i),()=>s(null))}return()=>{o=!1}},[e,t]),n}function mo(e){return(e.split(/[\\/]/).pop()??e).replace(/\.md$/i,"")}function iw(e){return e.split(/[\\/]/).pop()??e}function cw(e){const t=e.replace(/\\/g,"/"),n=t.lastIndexOf("/");return n===-1?"":t.slice(0,n)}const Ut=e=>e.file?e.base.toLowerCase():Ri(e.base);function li({query:e,left:t,top:n,anchorTop:r,getPageNames:o,getFiles:s,onPick:a,onPickRaw:l,onClose:i,editorFocused:c,sourcePath:u,agents:d=[],onPickAgent:f,allowCreate:m=!0,dates:p=!1}){const[h,g]=E.useState(0),[,w]=E.useState(0),y=!!f;E.useEffect(()=>y?Fe()?.subscribeAgents?.(()=>w(k=>k+1)):void 0,[y]);const C=y?Fe()?.agents?.()??d:d,{t:N}=rn(),M=En(k=>k.icons),T=rw(),D=o(),H=[...D.map(k=>({path:k,base:mo(k),file:!1})),...(s?.()??[]).map(k=>({path:k,base:iw(k),file:!0})),...D.flatMap(k=>(T[k]??[]).map(I=>({path:k,base:I,file:!1,alias:I})))],W=new Map;for(const k of H)k.alias||W.set(Ut(k),(W.get(Ut(k))??0)+1);const $=e.trim(),te=p?null:ow(e),Te=te?te.name?yo(te.name,D,u):u||null:null,ze=lw(Te,te?te.kind:null),ge=k=>{if(k.alias){const R={path:k.path,base:mo(k.path),file:!1};return`${(W.get(Ut(R))??0)<=1?R.base:k.path.replace(/\\/g,"/").replace(/\.md$/i,"")}|${k.alias}`}if((W.get(Ut(k))??0)<=1)return k.base;const I=k.path.replace(/\\/g,"/");return`${k.file?I:I.replace(/\.md$/i,"")}|${k.base}`},ie=[];if(te){const k=(ze??[]).map(I=>({it:I,s:ft(te.q,I.insert.replace(/^\^/,""))})).filter(I=>I.s!==null).sort((I,R)=>R.s-I.s).slice(0,8);for(const{it:I}of k)ie.push({key:`s:${I.insert}`,name:I.label,hint:I.hint,pick:()=>a(`${te.name}#${I.insert}`)})}else{if(f)for(const R of C.filter(re=>!$||ft($,re.name)!==null||ft($,re.slug)!==null).slice(0,6))ie.push({key:`agent:${R.slug}`,name:b.jsxs(b.Fragment,{children:[b.jsx(ji,{size:"1em","aria-hidden":"true"}),R.name]}),hint:N("wiki.agentTask"),section:"agent",pick:()=>f(R.slug)});const k=p?nw(e):[];for(const R of k)ie.push({key:`d:${R.insert}`,name:R.label,hint:R.hint,section:"date",pick:()=>l?.(R.insert)});for(const R of Wk(H,e))ie.push({key:(R.file?"f:":R.alias?`a:${R.alias}:`:"p:")+R.path,name:b.jsxs(b.Fragment,{children:[R.file?b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:/\.db$/i.test(R.base)?b.jsx(gr,{}):b.jsx(Vf,{})}):M[R.path]&&b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:M[R.path]}),R.base]}),hint:R.alias?N("wiki.aliasOf",{name:mo(R.path)}):(W.get(Ut(R))??0)>1?cw(R.path)||"/":void 0,section:"page",pick:()=>a(ge(R))});m&&$.length>0&&!Gf($)&&!/[#|^]/.test($)&&!H.some(R=>R.alias?R.alias.toLowerCase()===$.toLowerCase():Ut(R)===Ri($))&&ie.push({key:"create",name:N("wiki.create",{q:$}),create:!0,pick:()=>a($)})}const pe=ie.length;if(E.useEffect(()=>{g(0)},[e]),E.useLayoutEffect(()=>{if(pe===0)return;const k=I=>{I.isComposing||I.key==="Process"||I.keyCode===229||c&&!c()||(I.key==="ArrowDown"?(I.preventDefault(),I.stopPropagation(),g(R=>Math.min(R+1,pe-1))):I.key==="ArrowUp"?(I.preventDefault(),I.stopPropagation(),g(R=>Math.max(R-1,0))):I.key==="Enter"||I.key==="Tab"?(I.preventDefault(),I.stopPropagation(),ie[h]?.pick()):I.key==="Escape"&&(I.preventDefault(),I.stopPropagation(),i()))};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)}),pe===0)return null;const Ae=k=>k===h?I=>I?.scrollIntoView({block:"nearest"}):void 0;return b.jsx(on,{className:"wiki-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:k=>k.preventDefault(),children:ie.map((k,I)=>b.jsx(uw,{r:k,i:I,active:h,setActive:g,reveal:Ae,label:p&&k.section&&k.section!==ie[I-1]?.section?N(`wiki.sec.${k.section}`):void 0},k.key))})}function uw({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 dw=/(?:^|\s)#([\p{L}\p{N}_/-]+)$/u;function fw(e){return Q(()=>new Z({props:Jn(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=dw.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(qt(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 ii=[];function pw(e,t,n=8){const r=[];for(const o of e){const s=ft(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 mw({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=E.useState(ii),[c,u]=E.useState(0);E.useEffect(()=>{let p=!0;return Oe?.listTags?.().then(h=>{ii=h,p&&i(h)}).catch(()=>{}),()=>{p=!1}},[]),E.useEffect(()=>{u(0)},[e]);const d=pw(l,e),f=d.length;if(E.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(on,{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))})}const hw=/(?:^|[^A-Za-z0-9_:])(:([A-Za-z]{2,30}))$/;function gw(e){return Q(()=>new Z({props:Jn(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=hw.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(qt(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 bw({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=E.useState(0);E.useEffect(()=>{i(0)},[e]);const c=nm(e).slice(0,8),u=c.length;if(E.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(on,{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 yw=/[\p{L}\p{N}_/-]/u;function kw(e){let t="";return e.forEach(n=>{n.isText?t+=n.text??"":t+="".repeat(n.nodeSize)}),t}function v1(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=kw(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&&yw.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 td(e,t){let n=!1;for(let r=0;r<32;r++){const o=rm(e.state,t);if(o!=null){om(e,o),n=!0;continue}const s=sm(e.state,t);if(!s.length)break;am(e,s[0]),n=!0}return n}function ww(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 xw(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 vw=12;function Cw(e,t=vw){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=ww(e.parentElement);if(!o){window.scrollBy(0,n.top-t);return}const s=o.getBoundingClientRect(),a=o.currentCSSZoom||1;o.scrollTop+=(n.top-(s.top+xw(o)+t))/a}De({"footnote.backToRef":{zh:"回到引用处",en:"Back to reference"}});const Cn=new fe("amx-footnote"),nd="jumped",Ht="footnote_reference",gt="footnote_definition",Ta="[^\\s[\\]\\\\\\ufffc]{1,200}",Nt=e=>e.replace(/[\t\n\r ]+/g," ").trim().toLowerCase().toUpperCase();function Lr(e,t){const n=Nt(t);let r=null;return e.descendants((o,s)=>r?!1:o.type.name===gt&&Nt(String(o.attrs.label))===n?(r={pos:s,node:o},!1):!o.isTextblock),r}function C1(e,t){const n=Lr(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 ci=e=>e.type.name===gt&&e.childCount===1&&e.firstChild.isTextblock&&e.firstChild.content.size===0;function rd(e,t,n,r,o=""){const s=e.schema.nodes[Ht],a=e.schema.nodes[gt],l=e.schema.nodes.paragraph;if(!s||!a||!l||qt(e,t,n))return null;const i=e.tr.replaceWith(t,n,s.create({label:r}));if(o&&i.insertText(o,t+1),Lr(e.doc,r))return i;const c=i.doc.content.size;return i.insert(c,a.create({label:r},l.create())),i.setSelection(j.create(i.doc,c+2)).setMeta(Cn,nd).scrollIntoView()}const Sw=new Ye(new RegExp(`(?<![[!\\\\])\\[\\^(${Ta})\\]$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset===0&&o.parent.type.name==="paragraph"?null:rd(e,n,r,t[1])},{inCodeMark:!1}),Mw=new Ye(new RegExp(`^\\[\\^(${Ta})\\]([^:\\n])$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset!==0||o.parent.type.name!=="paragraph"?null:rd(e,n,r,t[1],t[2])},{inCodeMark:!1}),Aw=new Ye(new RegExp(`^\\[\\^(${Ta})\\]:[ \\u00a0]$`,"u"),(e,t,n,r)=>{const o=e.schema.nodes[gt],s=e.doc.resolve(n);if(!o||s.parentOffset!==0||s.parent.type.name!=="paragraph"||s.depth!==1||qt(e,n,r))return null;const a=t[1],l=[];e.doc.forEach((u,d)=>{ci(u)&&Nt(String(u.attrs.label))===Nt(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&&ci(f)&&i.delete(d,d+f.nodeSize)}return i},{inCodeMark:!1}),Nw=[ue(()=>Sw),ue(()=>Mw),ue(()=>Aw)];function ui(e){const t=new Map,n=[],r=[];if(e.descendants((s,a)=>{if(s.type.name===Ht){const l=Nt(String(s.attrs.label));t.has(l)||t.set(l,t.size+1),n.push({pos:a,node:s})}else s.type.name===gt&&r.push({pos:a,node:s});return!0}),!n.length&&!r.length)return me.empty;const o=s=>{const a=t.get(Nt(String(s.node.attrs.label)));return J.node(s.pos,s.pos+s.node.nodeSize,{"data-fn-num":a==null?"":String(a)},{fnNum:a??null})};return me.create(e,[...n,...r].map(o))}function Ew(e){return e.steps.some(t=>{const n=t.slice;let r=!1;return n?.content.descendants(o=>((o.type.name===Ht||o.type.name===gt)&&(r=!0),!r)),r})}const od=e=>{for(const t of e){const n=t.spec.fnNum;if(n!=null)return n}return null};class Tw{constructor(t,n){this.node=t,this.dom=document.createElement("sup"),this.dom.setAttribute("data-type",Ht),this.dom.contentEditable="false",this.render(n)}node;dom;render(t){const n=String(this.node.attrs.label),r=od(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 Iw{constructor(t,n){this.node=t,this.dom=document.createElement("dl"),this.dom.setAttribute("data-type",gt),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=O("footnote.backToRef")};r(),this.off=es(r),this.render(n)}node;dom;contentDOM;dt;off;render(t){const n=String(this.node.attrs.label),r=od(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 sd(e){if(!(e instanceof HTMLElement))return;const t=e.getBoundingClientRect();t.top>=0&&t.bottom<=window.innerHeight||Cw(e)}function Lw(e,t){let n=Lr(e.state.doc,t);if(!n||(td(e,n.pos)&&(n=Lr(e.state.doc,t)),!n))return!1;const r=n.pos+n.node.nodeSize-1;return e.dispatch(e.state.tr.setSelection(j.near(e.state.doc.resolve(r),-1))),e.focus(),sd(e.nodeDOM(n.pos)),!0}function Rw(e,t){const n=Nt(t);let r=-1;return e.state.doc.descendants((o,s)=>r>=0?!1:(o.type.name===Ht&&Nt(String(o.attrs.label))===n&&(r=s),r<0)),r<0?!1:(td(e,r),e.dispatch(e.state.tr.setSelection(j.near(e.state.doc.resolve(r+1)))),e.focus(),sd(e.nodeDOM(r)),!0)}const $w=Q(()=>new Z({key:Cn,state:{init:(e,t)=>({decos:ui(t.doc),jumped:!1}),apply:(e,t)=>{const n=e.getMeta(Cn)===nd||!e.docChanged&&!e.selectionSet&&t.jumped;let r=t.decos;return e.docChanged&&(r!==me.empty||Ew(e))&&(r=ui(e.doc)),r===t.decos&&n===t.jumped?t:{decos:r,jumped:n}}},props:{decorations:e=>Cn.getState(e)?.decos,handleKeyDown(e,t){if(t.key!=="Backspace"||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||!Cn.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?Jf(e.state,r=>{const o=Math.min(n.from+n.text.length,r.doc.content.size);e.dispatch(r.setSelection(j.near(r.doc.resolve(o))).scrollIntoView())}):!1},nodeViews:{[Ht]:(e,t,n,r)=>new Tw(e,r),[gt]:(e,t,n,r)=>new Iw(e,r)},handleClickOn(e,t,n,r,o,s){return!s||n.type.name!==Ht||o.button!==0||o.ctrlKey?!1:Lw(e,String(n.attrs.label))},handleDOMEvents:{mousedown(e,t){if(t.button!==0)return!1;const n=t.target?.closest?.(`dl[data-type="${gt}"] > dt`);if(!n||!e.dom.contains(n))return!1;const r=n.parentElement?.getAttribute("data-label")??"";return t.preventDefault(),Rw(e,r),!0}}}})),Dw="amadeus:open-tag",Dt=new fe("amadeus-tag-pill");function _w(e){const t=Dt.getState(e)?.focus??!1,{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=Dr(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(`
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 w=n.kind==="task"?{checked:n.checked??!1}:null,y=f.filter(N=>N.trim()),C=(y.length?y:[""]).map(N=>d.create(w,m(N)));p=[g.create(n.kind==="ordered"?{order:n.order??1}:null,C)]}else if(n.kind==="quote"||n.kind==="fold"){if(!i)return!1;p=[i.create(null,n.kind==="fold"?[a.create(null,s.text(Qt)),o]:[o])]}else return!1;const h=r.tr;try{h.replaceWith(t,t+o.nodeSize,p)}catch{return!1}return h.setSelection(ce.near(h.doc.resolve(Math.min(t+1,h.doc.content.size)))),e.dispatch(h.scrollIntoView()),!0}De({"structsrc.prefixAriaLabel":{zh:"Markdown 标记",en:"Markdown marker"}});const jt=new fe("amadeus-structural-source");function Yu(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 Ho(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}function Ju(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 Yu(t.parent,t.before());const r=Ho(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=Ho(t,"blockquote");if(o!==null){const s=t.node(o),a=t.before(o);return{source:"> ",widgetPos:n,decorateFrom:a,decorateTo:a+s.nodeSize,kind:"quote"}}return null}function yk(e){const{$from:t,$to:n}=e.selection;return t.parent.type.name!=="heading"||n.parent.type.name!=="heading"||t.before()!==n.before()?null:Yu(t.parent,t.before())}function Fo(e){e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(jt,{refresh:!0}))}function Xu(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(j.create(e.state.doc,t.widgetPos))),!0}function Ir(e){e.style.setProperty("--amx-prefix-ch",String(Math.max(2,e.value.length+.4)))}function kk(e,t,n){const r=Ea(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",!Xu(e,n)||!Kt(e,r,null))return t.value=t.dataset.original??n.source,Ir(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",Ir(a),a.focus({preventScroll:!0}),a.setSelectionRange(Math.min(o,a.value.length),Math.min(s,a.value.length)),!0}function wk(e,t){let n=!1;return Kt(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(j.create(o.doc,l+t.length)),n=!0})&&n}function xn(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=Ea(r);a?Kt(e,a,null):s=wk(e,r)}if(e.dispatch(e.state.tr.setMeta(jt,{openAt:null})),n){e.focus();const{$from:a}=e.state.selection;!s&&a.parent.isTextblock&&e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,a.start())).scrollIntoView())}}let qo=!1;function Zl(e,t){qo=!0;try{return e.someProp("handleKeyDown",n=>n(e,t))??!1}finally{qo=!1}}function xk(e,t,n){if(xn(e,t,!0),n.key==="Backspace"){Zl(e,n);return}const r=n.key==="ArrowDown"?1:-1;if(r>0&&!e.endOfTextblock("down")||Zl(e,n))return;const{$from:o}=e.state.selection;if(!o.parent.isTextblock)return;const s=r>0?o.after():o.before(),a=ce.findFrom(e.state.doc.resolve(s),r,!0);a&&e.dispatch(e.state.tr.setSelection(a).scrollIntoView())}function ei(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",O("structsrc.prefixAriaLabel")),n.setAttribute("autocomplete","off"),n.setAttribute("autocapitalize","off"),n.spellcheck=!1,Ir(n),n.addEventListener("focus",()=>{n.dataset.committed="0",Xu(e,t)});const r=o=>{o?.isComposing||kk(e,n,t)||Ea(n.value)||xn(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,Ir(n),xn(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??"");xn(e,n,!0),o.key==="Enter"&&c&&!o.isComposing&&e.someProp("handleKeyDown",u=>u(e,o))}}),n.addEventListener("blur",()=>{xn(e,n,!1),queueMicrotask(()=>Fo(e))}),n}function vk(e,t){const n=[],r=jt.getState(e)?.openAt,o=t.hasFocus()||t.dom.contains(document.activeElement),s=yk(e),a=s&&(o||r===s.widgetPos)?s:null;if(a){const l=a;n.push(Y.widget(l.widgetPos,()=>ei(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}if(r!=null){const l=Ju(e);l&&l.kind!=="heading"&&l.widgetPos===r&&e.doc.nodeAt(l.decorateFrom)&&n.push(Y.node(l.decorateFrom,l.decorateTo,{class:`amx-struct-source-open amx-struct-source-${l.kind}`}),Y.widget(l.widgetPos,()=>ei(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}return n.length?me.create(e.doc,n):me.empty}function Ck(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(j.create(e.state.doc,r))),!0)}function ti(e,t=!1){if(qo||!Ck(e))return!1;const n=Ju(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"?Ho(s,"blockquote"):null;if((n.kind!=="quote"||a!==null&&s.node(a).childCount===1)&&Kt(e,{kind:"text"},null))return!0}e.dispatch(e.state.tr.setMeta(jt,{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(jt,{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 Sk(){return Q(()=>{let e=null;return new Z({key:jt,view:t=>(e=t,{destroy:()=>{e===t&&(e=null)}}),state:{init:()=>({openAt:null}),apply:(t,n)=>{const r=t.getMeta(jt);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?vk(t,e):me.empty,handleDOMEvents:{focus:t=>(queueMicrotask(()=>Fo(t)),!1),blur:t=>(queueMicrotask(()=>Fo(t)),!1)}}})})}function Wo(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 Qu(e){const t=Wo(e.$from);if(e.empty)return t;const n=Wo(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 Mk(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 Ak(e){return!e.code&&!e.tableCell}function Nk(e,t){return e==="instructions"||e==="columns"?t.topLevel:e==="card"?!t.listItem&&!t.column:!0}function k1(e){const t=e.node;return t?e.$from.depth===0&&!/^amadeus(CanvasCard|ColumnRow)$/.test(t.type.name):!1}function w1(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 Uo=new WeakMap;function x1(e,t){Uo.set(e,t)}function ni(e,t){const n=Uo.get(e);return Uo.delete(e),n===t}De({"wikiac.multiBlocks":{zh:"多个块",en:"Multiple blocks"}});const Ek=ue(()=>new Je(/【【$/,(e,t,n,r)=>e.tr.insertText("[[",n,r),{inCodeMark:!1}));function qt(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 Yn=e=>({handleDOMEvents:{blur:()=>(e(null,!0),!1)}});function Tk(e){return Q(()=>new Z({props:Yn(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)||qt(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 Ik(e){return Q(()=>new Z({props:Yn(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=Wo(r);if(!Ak(o))return e(null);const s=r.parent.textBetween(0,r.parentOffset,void 0,""),a=s.lastIndexOf("/");if(a<0||qt(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 Lk(e){return Q(()=>new Z({props:Yn(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||qt(t.state,r.start()+s,n.head)||s>0&&tm.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 Rk=/^!\[\[[^\]\n|]+\.(png|jpe?g|gif|webp|svg|avif|bmp)(\|\d+)?\]\]$/i,ri=()=>!!document.activeElement?.closest?.(".inline-toolbar");function $k(e){const t=e.selection;return t instanceof Ve?t.node.type.name==="image":Rk.test(e.doc.textBetween(t.from,t.to))}const dr=new fe("amx-toolbar-dismissed");function Dk(e){return Q(()=>{let t=!1;const n=r=>{if(t||dr.getState(r.state))return e(null);const{selection:o,doc:s}=r.state;if(o.empty||!r.editable)return e(null);if(!r.hasFocus()&&!ri()){setTimeout(()=>{!r.isDestroyed&&!r.hasFocus()&&!ri()&&e(null)},0);return}if($k(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 w=i.depth;w>0;w--){const y=i.node(w);f.push({name:y.type.name,level:y.attrs.level,checked:y.attrs.checked??null})}const m=[];for(const w of["strong","emphasis","inlineCode","strike_through","amadeusUnderline","link"]){const y=r.state.schema.marks[w];if(!y)continue;let C=!0,N=!1;s.nodesBetween(a,l,M=>(M.isText&&(N=!0,y.isInSet(M.marks)||(C=!1)),!0)),N&&C&&m.push(w)}const p=new Set;s.nodesBetween(a,l,w=>((w.type.name==="paragraph"||w.type.name==="heading")&&p.add(w.attrs.align==="center"||w.attrs.align==="right"?w.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=(w,y)=>{const C=r.state.schema.marks[w];if(!C)return;const N=new Set;return s.nodesBetween(a,l,M=>(M.isText&&N.add(String(C.isInSet(M.marks)?.attrs[y]??"")),!0)),N.size===1&&[...N][0]||void 0};e({from:a,to:l,active:m,align:h,shape:Mk(Qu(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?O("wikiac.multiBlocks"):bk(f)})};return new Z({key:dr,state:{init:()=>!1,apply:(r,o,s,a)=>r.getMeta(dr)?!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})})})}De({"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.aria":{zh:"文字格式",en:"Text formatting"}});const _k=[{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"}],zk=[{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"}],Ok={turnInto:!0,format:!0,link:!0,color:!0,align:!0},Zu=[{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"}],Pk=Object.fromEntries(Zu.map(e=>[e.k,e.labelKey]));function Bk({left:e,top:t,bottom:n,kind:r,active:o,align:s,shape:a=Ok,fg:l,bg:i,onAct:c,onColor:u,onBg:d,onClose:f,onReturnFocus:m,onAsk:p,ai:h}){const{t:g}=rn(),[w,y]=E.useState(null),C=E.useRef(null),N=E.useRef(!1);E.useEffect(()=>{const $=te=>{if(te.key==="Escape"){te.preventDefault(),te.stopPropagation();const Te=C.current,ze=!!Te&&Te.contains(document.activeElement);if(w&&ze){const ge=Te.querySelector(`[data-panel="${w}"]`);y(null),ge?.focus();return}f(),ze&&m?.()}};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[f,m,w]),E.useEffect(()=>{!w||!N.current||(N.current=!1,C.current?.querySelector(".itb-panel button")?.focus())},[w]);const M=$=>o?.includes($)?" on":"",T=$=>te=>{te.preventDefault(),$()},D=$=>({onMouseDown:T($),onClick:te=>{te.detail===0&&$()}}),H=$=>({onMouseDown:T(()=>y(w===$?null:$)),onClick:te=>{te.detail===0&&(N.current=w!==$,y(w===$?null:$))},"aria-haspopup":"menu","aria-expanded":w===$,"data-panel":$}),W=$=>{const te=$.target.closest(".itb-row, .itb-panel");if(!te||!(te.classList.contains("itb-panel")?["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]:["ArrowRight","ArrowLeft","Home","End"]).includes($.key))return;const ge=[...te.querySelectorAll(":scope > button, :scope > * > button")],ie=ge.indexOf(document.activeElement),pe=$.key==="ArrowRight"||$.key==="ArrowDown",Ae=$.key==="Home"?0:$.key==="End"?ge.length-1:ie<0?0:(ie+(pe?1:-1)+ge.length)%ge.length;$.preventDefault(),$.stopPropagation(),ge[Ae]?.focus()};return b.jsxs(on,{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",innerRef:$=>{C.current=$},onKeyDown:W,children:[b.jsxs("div",{className:"itb-row",children:[p&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:"itb-btn itb-ask",title:g("itb.askTanguTitle"),"data-act":"ask",...D(p),children:g("itb.askTangu")}),!h&&b.jsx("span",{className:"itb-sep"})]}),h&&b.jsxs(b.Fragment,{children:[b.jsxs("button",{className:"itb-btn itb-ask",title:g("itb.aiTitle"),"data-act":"ai",...H("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}`,...H("turn"),children:[r," ▾"]}),b.jsx("span",{className:"itb-sep"})]}),a.format&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:`itb-btn${M("strong")}`,style:{fontWeight:700},title:g("itb.bold"),"data-act":"bold","aria-label":g("itb.bold"),"aria-pressed":!!o?.includes("strong"),...D(()=>c("bold")),children:"B"}),b.jsx("button",{className:`itb-btn${M("emphasis")}`,style:{fontStyle:"italic"},title:g("itb.italic"),"data-act":"italic","aria-label":g("itb.italic"),"aria-pressed":!!o?.includes("emphasis"),...D(()=>c("italic")),children:"I"}),b.jsx("button",{className:`itb-btn${M("amadeusUnderline")}`,style:{textDecoration:"underline"},title:g("itb.underline"),"data-act":"underline","aria-label":g("itb.underline"),"aria-pressed":!!o?.includes("amadeusUnderline"),...D(()=>c("underline")),children:"U"}),b.jsx("button",{className:`itb-btn${M("strike_through")}`,style:{textDecoration:"line-through"},title:g("itb.strike"),"data-act":"strike","aria-label":g("itb.strike"),"aria-pressed":!!o?.includes("strike_through"),...D(()=>c("strike")),children:"S"}),b.jsx("button",{className:`itb-btn${M("inlineCode")}`,title:g("itb.code"),"data-act":"code","aria-label":g("itb.code"),"aria-pressed":!!o?.includes("inlineCode"),...D(()=>c("code")),children:"</>"})]}),a.link&&b.jsx("button",{className:`itb-btn${M("link")}`,title:g("itb.link"),"aria-label":g("itb.link"),"aria-pressed":!!o?.includes("link"),"data-act":"link",...D(()=>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,...H("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",...D(()=>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",...D(()=>c("alignLeft")),children:b.jsx(Ff,{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",...D(()=>c("alignCenter")),children:b.jsx(cm,{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",...D(()=>c("alignRight")),children:b.jsx(dm,{size:14})})]})]}),w==="turn"&&b.jsx("div",{className:"itb-panel",role:"menu","aria-label":g("itb.turnInto"),children:Zu.map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,...D(()=>{y(null),c($.k)}),children:g($.labelKey)},$.k))}),w==="ai"&&h&&b.jsxs("div",{className:"itb-panel itb-ai-menu",role:"menu","data-testid":"itb-ai-menu",children:[h.items.filter($=>!$.plugin).map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":$.id,...D(()=>{y(null),h.onPick($.id)}),children:$.label},$.id)),h.items.some($=>$.plugin)&&b.jsx("div",{className:"itb-color-head",children:g("itb.aiPlugins")}),h.items.filter($=>$.plugin).map($=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":$.id,...D(()=>{y(null),h.onPick($.id)}),children:$.label},$.id))]}),w==="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:_k.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",...D(()=>{y(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:zk.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",...D(()=>{y(null),d($.v)}),children:b.jsx("span",{className:"itb-swatch-bg",style:{background:$.v||"transparent"}})},$.v||"def"))})]})]})}const vn=["basic","ai","plugin"];function ed(e){return e.category??"basic"}function Kk(e,t){return t.trim()&&e.length?ed(e[0]):"basic"}function jk(e,t){if(t!=="ArrowLeft"&&t!=="ArrowRight")return null;const n=vn.indexOf(e);return vn[(n+(t==="ArrowRight"?1:-1)+vn.length)%vn.length]}function Hk(e,t,n){return!e||n!=="ArrowUp"&&n!=="ArrowDown"?null:Math.max(0,Math.min(e-1,t+(n==="ArrowDown"?1:-1)))}const Fk=8,qk=2;function Wk(e,t,n=Fk){const r=[];for(const l of e){if(l.alias&&!t.trim())continue;const i=ft(t,l.base),c=i!==null?i+1e3:ft(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,qk);return a.length?[...s.slice(0,n-a.length),...a]:s}De({"dateq.schedule":{zh:"日程",en:"Schedule"},"dateq.remind":{zh:"提醒",en:"Remind me"},"dateq.today":{zh:"今天",en:"Today"},"dateq.tomorrow":{zh:"明天",en:"Tomorrow"}});const St=e=>String(e).padStart(2,"0"),$n=e=>`${e.getFullYear()}-${St(e.getMonth()+1)}-${St(e.getDate())}`,Vo=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),Uk=/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/,Vk=/^(\d{4})年(\d{1,2})月(\d{1,2})(?:日|号)?$/,Gk=/^(\d{1,2})[-/.](\d{1,2})$/,Yk=/^(\d{1,2})月(\d{1,2})(?:日|号)?$/,Jk=/^(\d{4})(\d{2})(\d{2})$/,Xk=/^(\d{1,2})(?:日|号)?$/,Qk={昨天:-1,yesterday:-1,今天:0,today:0,明天:1,tomorrow:1,后天:2};function oi(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 Zk(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 $n(o)}return null}function si(e,t){const n=e.trim().toLowerCase(),r=Qk[n];if(r!==void 0)return $n(Vo(t,r));const o=(a,l,i)=>{const c=`${Number(a)}-${St(Number(l))}-${St(Number(i))}`;return Uf(c)?c:null};let s=Uk.exec(n);return s||(s=Vk.exec(n),s)||(s=Jk.exec(n),s)?o(s[1],s[2],s[3]):(s=Gk.exec(n),s||(s=Yk.exec(n),s)?o(t.getFullYear(),s[1],s[2]):(s=Xk.exec(n),s?Zk(Number(s[1]),t):null))}function ai(e,t=new Date){const n=e.normalize("NFKC").trim();if(!n)return null;const r=si(n,t);if(r)return r;const o=oi(n);if(o)return`${$n(t)}T${St(o.hour)}:${St(o.minute)}`;const s=/^(.+?)(?:[tT]|\s+)(\S.+)$/.exec(n)??/^(.+?(?:日|号))\s*(\d{1,2}(?:点|时).*)$/.exec(n);if(s){const a=si(s[1],t),l=oi(s[2]);if(a&&l)return`${a}T${St(l.hour)}:${St(l.minute)}`}return null}const ew=[{key:"dateq.today",words:["today","今天"],days:0},{key:"dateq.tomorrow",words:["tomorrow","明天"],days:1}],tw=["remind","提醒"];function nw(e,t=new Date){const n=e.trim(),r=u=>qf(Wf(u)),o=u=>{const d=u.includes("T")?u:`${u}T09:00`;return{insert:`@remind:${d}`,label:O("dateq.remind"),hint:r(d)}},s=$n(Vo(t,1));if(/^remind:/i.test(n)){const u=n.length===7?s:ai(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 ew){if(!l(u.words))continue;const d=$n(Vo(t,u.days));i.push({insert:`@${d}`,label:O(u.key),hint:r(d)})}if(l(tw)&&i.push(o(s)),i.length)return i;const c=ai(n,t);return c?[{insert:`@${c}`,label:O("dateq.schedule"),hint:r(c)},o(c)]:[]}let bn=null;function rw(){const e=En(s=>s.vaultRoot),t=En(s=>s.linkGraphVersion),n=`${e??""}\0${t}`,[r,o]=E.useState(()=>bn?.map??{});return E.useEffect(()=>{if(bn?.key===n){o(bn.map);return}let s=!0;return Oe?.pageAliases?.().then(a=>{bn={key:n,map:a??{}},s&&o(bn.map)}).catch(()=>{}),()=>{s=!1}},[n]),r}function ow(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 Go=e=>e.replace(/[[\]|#^]/g," ").replace(/\s+/g," ").trim();function sw(e){const t=[],n=new Set;return $r(Li(e),r=>{const o=/^ {0,3}(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/.exec(r);if(o){const s=Go(Ii(o[2]));s&&!n.has(s)&&(n.add(s),t.push({level:o[1].length,text:s}))}return r}),t}function aw(e){const t=[],n=new Set;return $r(Li(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:Ii(r.slice(0,o.index))})),r}),t}De({"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.create":{zh:"新建链接 “{q}”",en:"New link “{q}”"},"wiki.aliasOf":{zh:"别名 → {name}",en:"Alias → {name}"}});function lw(e,t){const[n,r]=E.useState(null);return E.useEffect(()=>{if(!e||!t){r(null);return}let o=!0;const s=l=>{if(o){if(l==null){r([]);return}r(t==="heading"?sw(l).map(i=>({label:i.text,insert:i.text,hint:`H${i.level}`})):aw(l).map(i=>({label:`^${i.id}`,insert:`^${i.id}`,hint:i.preview})))}},a=t==="heading"?rf(e):null;if(a)r(a.map(l=>({label:Go(l.text),insert:Go(l.text),hint:`H${l.level}`})).filter(l=>l.insert));else{const l=of(e);l!=null?s(l):Oe?.readTextFile?.(e).then(i=>s(i),()=>s(null))}return()=>{o=!1}},[e,t]),n}function mo(e){return(e.split(/[\\/]/).pop()??e).replace(/\.md$/i,"")}function iw(e){return e.split(/[\\/]/).pop()??e}function cw(e){const t=e.replace(/\\/g,"/"),n=t.lastIndexOf("/");return n===-1?"":t.slice(0,n)}const Ut=e=>e.file?e.base.toLowerCase():Ri(e.base);function li({query:e,left:t,top:n,anchorTop:r,getPageNames:o,getFiles:s,onPick:a,onPickRaw:l,onClose:i,editorFocused:c,sourcePath:u,agents:d=[],onPickAgent:f,allowCreate:m=!0,dates:p=!1}){const[h,g]=E.useState(0),[,w]=E.useState(0),y=!!f;E.useEffect(()=>y?Fe()?.subscribeAgents?.(()=>w(k=>k+1)):void 0,[y]);const C=y?Fe()?.agents?.()??d:d,{t:N}=rn(),M=En(k=>k.icons),T=rw(),D=o(),H=[...D.map(k=>({path:k,base:mo(k),file:!1})),...(s?.()??[]).map(k=>({path:k,base:iw(k),file:!0})),...D.flatMap(k=>(T[k]??[]).map(I=>({path:k,base:I,file:!1,alias:I})))],W=new Map;for(const k of H)k.alias||W.set(Ut(k),(W.get(Ut(k))??0)+1);const $=e.trim(),te=p?null:ow(e),Te=te?te.name?yo(te.name,D,u):u||null:null,ze=lw(Te,te?te.kind:null),ge=k=>{if(k.alias){const R={path:k.path,base:mo(k.path),file:!1};return`${(W.get(Ut(R))??0)<=1?R.base:k.path.replace(/\\/g,"/").replace(/\.md$/i,"")}|${k.alias}`}if((W.get(Ut(k))??0)<=1)return k.base;const I=k.path.replace(/\\/g,"/");return`${k.file?I:I.replace(/\.md$/i,"")}|${k.base}`},ie=[];if(te){const k=(ze??[]).map(I=>({it:I,s:ft(te.q,I.insert.replace(/^\^/,""))})).filter(I=>I.s!==null).sort((I,R)=>R.s-I.s).slice(0,8);for(const{it:I}of k)ie.push({key:`s:${I.insert}`,name:I.label,hint:I.hint,pick:()=>a(`${te.name}#${I.insert}`)})}else{if(f)for(const R of C.filter(re=>!$||ft($,re.name)!==null||ft($,re.slug)!==null).slice(0,6))ie.push({key:`agent:${R.slug}`,name:b.jsxs(b.Fragment,{children:[b.jsx(ji,{size:"1em","aria-hidden":"true"}),R.name]}),hint:N("wiki.agentTask"),section:"agent",pick:()=>f(R.slug)});const k=p?nw(e):[];for(const R of k)ie.push({key:`d:${R.insert}`,name:R.label,hint:R.hint,section:"date",pick:()=>l?.(R.insert)});for(const R of Wk(H,e))ie.push({key:(R.file?"f:":R.alias?`a:${R.alias}:`:"p:")+R.path,name:b.jsxs(b.Fragment,{children:[R.file?b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:/\.db$/i.test(R.base)?b.jsx(gr,{}):b.jsx(Vf,{})}):M[R.path]&&b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:M[R.path]}),R.base]}),hint:R.alias?N("wiki.aliasOf",{name:mo(R.path)}):(W.get(Ut(R))??0)>1?cw(R.path)||"/":void 0,section:"page",pick:()=>a(ge(R))});m&&$.length>0&&!Gf($)&&!/[#|^]/.test($)&&!H.some(R=>R.alias?R.alias.toLowerCase()===$.toLowerCase():Ut(R)===Ri($))&&ie.push({key:"create",name:N("wiki.create",{q:$}),create:!0,pick:()=>a($)})}const pe=ie.length;if(E.useEffect(()=>{g(0)},[e]),E.useLayoutEffect(()=>{if(pe===0)return;const k=I=>{I.isComposing||I.key==="Process"||I.keyCode===229||c&&!c()||(I.key==="ArrowDown"?(I.preventDefault(),I.stopPropagation(),g(R=>Math.min(R+1,pe-1))):I.key==="ArrowUp"?(I.preventDefault(),I.stopPropagation(),g(R=>Math.max(R-1,0))):I.key==="Enter"||I.key==="Tab"?(I.preventDefault(),I.stopPropagation(),ie[h]?.pick()):I.key==="Escape"&&(I.preventDefault(),I.stopPropagation(),i()))};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)}),pe===0)return null;const Ae=k=>k===h?I=>I?.scrollIntoView({block:"nearest"}):void 0;return b.jsx(on,{className:"wiki-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:k=>k.preventDefault(),children:ie.map((k,I)=>b.jsx(uw,{r:k,i:I,active:h,setActive:g,reveal:Ae,label:p&&k.section&&k.section!==ie[I-1]?.section?N(`wiki.sec.${k.section}`):void 0},k.key))})}function uw({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 dw=/(?:^|\s)#([\p{L}\p{N}_/-]+)$/u;function fw(e){return Q(()=>new Z({props:Yn(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=dw.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(qt(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 ii=[];function pw(e,t,n=8){const r=[];for(const o of e){const s=ft(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 mw({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=E.useState(ii),[c,u]=E.useState(0);E.useEffect(()=>{let p=!0;return Oe?.listTags?.().then(h=>{ii=h,p&&i(h)}).catch(()=>{}),()=>{p=!1}},[]),E.useEffect(()=>{u(0)},[e]);const d=pw(l,e),f=d.length;if(E.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(on,{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))})}const hw=/(?:^|[^A-Za-z0-9_:])(:([A-Za-z]{2,30}))$/;function gw(e){return Q(()=>new Z({props:Yn(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=hw.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(qt(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 bw({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=E.useState(0);E.useEffect(()=>{i(0)},[e]);const c=nm(e).slice(0,8),u=c.length;if(E.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(on,{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 yw=/[\p{L}\p{N}_/-]/u;function kw(e){let t="";return e.forEach(n=>{n.isText?t+=n.text??"":t+="".repeat(n.nodeSize)}),t}function v1(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=kw(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&&yw.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 td(e,t){let n=!1;for(let r=0;r<32;r++){const o=rm(e.state,t);if(o!=null){om(e,o),n=!0;continue}const s=sm(e.state,t);if(!s.length)break;am(e,s[0]),n=!0}return n}function ww(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 xw(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 vw=12;function Cw(e,t=vw){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=ww(e.parentElement);if(!o){window.scrollBy(0,n.top-t);return}const s=o.getBoundingClientRect(),a=o.currentCSSZoom||1;o.scrollTop+=(n.top-(s.top+xw(o)+t))/a}De({"footnote.backToRef":{zh:"回到引用处",en:"Back to reference"}});const Cn=new fe("amx-footnote"),nd="jumped",Ht="footnote_reference",gt="footnote_definition",Ta="[^\\s[\\]\\\\\\ufffc]{1,200}",Nt=e=>e.replace(/[\t\n\r ]+/g," ").trim().toLowerCase().toUpperCase();function Lr(e,t){const n=Nt(t);let r=null;return e.descendants((o,s)=>r?!1:o.type.name===gt&&Nt(String(o.attrs.label))===n?(r={pos:s,node:o},!1):!o.isTextblock),r}function C1(e,t){const n=Lr(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 ci=e=>e.type.name===gt&&e.childCount===1&&e.firstChild.isTextblock&&e.firstChild.content.size===0;function rd(e,t,n,r,o=""){const s=e.schema.nodes[Ht],a=e.schema.nodes[gt],l=e.schema.nodes.paragraph;if(!s||!a||!l||qt(e,t,n))return null;const i=e.tr.replaceWith(t,n,s.create({label:r}));if(o&&i.insertText(o,t+1),Lr(e.doc,r))return i;const c=i.doc.content.size;return i.insert(c,a.create({label:r},l.create())),i.setSelection(j.create(i.doc,c+2)).setMeta(Cn,nd).scrollIntoView()}const Sw=new Je(new RegExp(`(?<![[!\\\\])\\[\\^(${Ta})\\]$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset===0&&o.parent.type.name==="paragraph"?null:rd(e,n,r,t[1])},{inCodeMark:!1}),Mw=new Je(new RegExp(`^\\[\\^(${Ta})\\]([^:\\n])$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset!==0||o.parent.type.name!=="paragraph"?null:rd(e,n,r,t[1],t[2])},{inCodeMark:!1}),Aw=new Je(new RegExp(`^\\[\\^(${Ta})\\]:[ \\u00a0]$`,"u"),(e,t,n,r)=>{const o=e.schema.nodes[gt],s=e.doc.resolve(n);if(!o||s.parentOffset!==0||s.parent.type.name!=="paragraph"||s.depth!==1||qt(e,n,r))return null;const a=t[1],l=[];e.doc.forEach((u,d)=>{ci(u)&&Nt(String(u.attrs.label))===Nt(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&&ci(f)&&i.delete(d,d+f.nodeSize)}return i},{inCodeMark:!1}),Nw=[ue(()=>Sw),ue(()=>Mw),ue(()=>Aw)];function ui(e){const t=new Map,n=[],r=[];if(e.descendants((s,a)=>{if(s.type.name===Ht){const l=Nt(String(s.attrs.label));t.has(l)||t.set(l,t.size+1),n.push({pos:a,node:s})}else s.type.name===gt&&r.push({pos:a,node:s});return!0}),!n.length&&!r.length)return me.empty;const o=s=>{const a=t.get(Nt(String(s.node.attrs.label)));return Y.node(s.pos,s.pos+s.node.nodeSize,{"data-fn-num":a==null?"":String(a)},{fnNum:a??null})};return me.create(e,[...n,...r].map(o))}function Ew(e){return e.steps.some(t=>{const n=t.slice;let r=!1;return n?.content.descendants(o=>((o.type.name===Ht||o.type.name===gt)&&(r=!0),!r)),r})}const od=e=>{for(const t of e){const n=t.spec.fnNum;if(n!=null)return n}return null};class Tw{constructor(t,n){this.node=t,this.dom=document.createElement("sup"),this.dom.setAttribute("data-type",Ht),this.dom.contentEditable="false",this.render(n)}node;dom;render(t){const n=String(this.node.attrs.label),r=od(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 Iw{constructor(t,n){this.node=t,this.dom=document.createElement("dl"),this.dom.setAttribute("data-type",gt),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=O("footnote.backToRef")};r(),this.off=es(r),this.render(n)}node;dom;contentDOM;dt;off;render(t){const n=String(this.node.attrs.label),r=od(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 sd(e){if(!(e instanceof HTMLElement))return;const t=e.getBoundingClientRect();t.top>=0&&t.bottom<=window.innerHeight||Cw(e)}function Lw(e,t){let n=Lr(e.state.doc,t);if(!n||(td(e,n.pos)&&(n=Lr(e.state.doc,t)),!n))return!1;const r=n.pos+n.node.nodeSize-1;return e.dispatch(e.state.tr.setSelection(j.near(e.state.doc.resolve(r),-1))),e.focus(),sd(e.nodeDOM(n.pos)),!0}function Rw(e,t){const n=Nt(t);let r=-1;return e.state.doc.descendants((o,s)=>r>=0?!1:(o.type.name===Ht&&Nt(String(o.attrs.label))===n&&(r=s),r<0)),r<0?!1:(td(e,r),e.dispatch(e.state.tr.setSelection(j.near(e.state.doc.resolve(r+1)))),e.focus(),sd(e.nodeDOM(r)),!0)}const $w=Q(()=>new Z({key:Cn,state:{init:(e,t)=>({decos:ui(t.doc),jumped:!1}),apply:(e,t)=>{const n=e.getMeta(Cn)===nd||!e.docChanged&&!e.selectionSet&&t.jumped;let r=t.decos;return e.docChanged&&(r!==me.empty||Ew(e))&&(r=ui(e.doc)),r===t.decos&&n===t.jumped?t:{decos:r,jumped:n}}},props:{decorations:e=>Cn.getState(e)?.decos,handleKeyDown(e,t){if(t.key!=="Backspace"||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||!Cn.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?Yf(e.state,r=>{const o=Math.min(n.from+n.text.length,r.doc.content.size);e.dispatch(r.setSelection(j.near(r.doc.resolve(o))).scrollIntoView())}):!1},nodeViews:{[Ht]:(e,t,n,r)=>new Tw(e,r),[gt]:(e,t,n,r)=>new Iw(e,r)},handleClickOn(e,t,n,r,o,s){return!s||n.type.name!==Ht||o.button!==0||o.ctrlKey?!1:Lw(e,String(n.attrs.label))},handleDOMEvents:{mousedown(e,t){if(t.button!==0)return!1;const n=t.target?.closest?.(`dl[data-type="${gt}"] > dt`);if(!n||!e.dom.contains(n))return!1;const r=n.parentElement?.getAttribute("data-label")??"";return t.preventDefault(),Rw(e,r),!0}}}})),Dw="amadeus:open-tag",Dt=new fe("amadeus-tag-pill");function _w(e){const t=Dt.getState(e)?.focus??!1,{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=Dr(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
36
  `,m-1)+1;const h=l.indexOf(`
37
- `,p);u=h===-1?l.length:h}const d=new RegExp(Qa.source,Qa.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(J.inline(i+h,i+p,{class:"amx-tag-pill","data-tag":m}))}return!1}),o.length?me.create(e.doc,o):me.empty}function zw(){return Q(()=>new Z({key:Dt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(Dt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{decorations:e=>_w(e),handleDOMEvents:{focus:e=>(Dt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(Dt,{focus:!0})),!1),blur:e=>(Dt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(Dt,{focus:!1})),!1),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(Dw,{detail:{tag:r}})),!0):!1}}}}))}function Ow(e,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 Pw={instructions:"forsion-instructions",task:"forsion-task",prompt:"forsion-prompt"},Bw=new Set(["v","id","agent","prompt","sessionId"]),ho=e=>typeof e=="string"&&e.length>0&&e.length<=256&&e===e.trim()&&!/[\u0000-\u0020\u007f]/.test(e);function Kw(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=>!Bw.has(r))||n.v!==1||!ho(n.id)||typeof n.prompt!="string"||n.agent!==void 0&&!ho(n.agent)||n.sessionId!==void 0&&!ho(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 ad(e){const t=JSON.stringify(e);if(!Kw(t))throw new Error("Invalid document agent block");return t}function jw(e,t=""){const n={v:1,id:crypto.randomUUID(),prompt:t,...e?{agent:e}:{}};return ad(n),n}function S1(e,t){const n=Math.max(2,...Array.from(t.matchAll(/`+/g),o=>o[0].length)),r="`".repeat(n+1);return`${r}${Pw[e]}
37
+ `,p);u=h===-1?l.length:h}const d=new RegExp(Qa.source,Qa.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(Y.inline(i+h,i+p,{class:"amx-tag-pill","data-tag":m}))}return!1}),o.length?me.create(e.doc,o):me.empty}function zw(){return Q(()=>new Z({key:Dt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(Dt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{decorations:e=>_w(e),handleDOMEvents:{focus:e=>(Dt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(Dt,{focus:!0})),!1),blur:e=>(Dt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(Dt,{focus:!1})),!1),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(Dw,{detail:{tag:r}})),!0):!1}}}}))}function Ow(e,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 Pw={instructions:"forsion-instructions",task:"forsion-task",prompt:"forsion-prompt"},Bw=new Set(["v","id","agent","prompt","sessionId"]),ho=e=>typeof e=="string"&&e.length>0&&e.length<=256&&e===e.trim()&&!/[\u0000-\u0020\u007f]/.test(e);function Kw(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=>!Bw.has(r))||n.v!==1||!ho(n.id)||typeof n.prompt!="string"||n.agent!==void 0&&!ho(n.agent)||n.sessionId!==void 0&&!ho(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 ad(e){const t=JSON.stringify(e);if(!Kw(t))throw new Error("Invalid document agent block");return t}function jw(e,t=""){const n={v:1,id:crypto.randomUUID(),prompt:t,...e?{agent:e}:{}};return ad(n),n}function S1(e,t){const n=Math.max(2,...Array.from(t.matchAll(/`+/g),o=>o[0].length)),r="`".repeat(n+1);return`${r}${Pw[e]}
38
38
  ${t}
39
- ${r}`}De({"mdtask.checkbox":{zh:"完成",en:"Done"}});function Hw(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 Fw=ve("amadeusEmptyTask",()=>()=>Hw);function Jo(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 di=new fe("amadeusTaskA11y"),qw="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";function ld(e,t){return J.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=qw;const s=()=>{o.setAttribute("aria-label",O("mdtask.checkbox"))};return s(),o.__off=es(s),o.addEventListener("click",a=>{if(a.preventDefault(),a.stopPropagation(),!n.editable)return;const l=r();if(l==null)return;const i=Jo(n.state,l);i&&n.dispatch(i)}),o},{side:-1,ignoreSelection:!0,key:`amxtask:${t?1:0}`,stopEvent:()=>!0,destroy:n=>{n.__off?.()}})}function id(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 Ww(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=id(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])=>ld(h,g)))})}),n}function fi(e,t){const n=t.target?.closest?.('li[data-item-type="task"]');return n?t.clientX-n.getBoundingClientRect().left>2?null:n:null}function Uw(){return Q(()=>new Z({key:di,state:{init:(e,t)=>me.create(t.doc,[...id(t.doc,0,t.doc.content.size)].map(([n,r])=>ld(n,r))),apply:Ww},props:{decorations:e=>di.getState(e),handleClick(e,t,n){if(!e.editable)return!1;const r=fi(e,n);if(!r)return!1;const o=Jo(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||!Yf())return!1;const n=fi(e,t);if(!n)return!1;const r=Jo(e.state,e.posAtDOM(n,0));return r?(t.preventDefault(),e.dispatch(r),!0):!1}}}}))}De({"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 Vw={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"},cd={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 Gw(e){const t=Vw[e]??e;return t in cd?t:null}function ud(e){const t=e.children?.[0];if(e.type==="blockquote"&&t?.type==="paragraph"&&t.position&&/^\[![\w-]+\][+-]?/.test(t.children?.[0]?.value??"")){const n=bu(t);n.length>1&&e.children.splice(0,1,...n)}e.children?.forEach(ud)}const Jw=ve("amadeusCalloutTitle",()=>()=>ud),dd=e=>e.replace(/^((?:[ \t]*>[ \t]?)+)\\\[!/gm,"$1[!"),fd=/^\[!([\w-]+)\]([+-])?/,Yw=/^(#{1,6}|[-*+]) /;function Dn(e){if(e.type.name!=="blockquote")return null;const t=e.firstChild,n=t&&t.isTextblock?fd.exec(t.textContent):null;if(!n||!t)return null;const r=/[ \u00a0]/.test(t.textContent[n[0].length]??"")?1:0,o=Yw.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 pd(e,t){e.doc.descendants((n,r)=>{const o=Dn(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 M1(e,t,n){pd(e,[[t,n]])}function Xw(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 pd(r,n),r.docChanged?r:null}function Ze(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=Dn(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 Qw=e=>{const t=Ze(e);return t&&t.collapsed?t:null},md="--amx-fold-scroll-buffer",Vt=e=>parseFloat(e.style.getPropertyValue(md))||0,go=(e,t)=>{e.style.setProperty(md,`${Math.max(0,Math.ceil(t))}px`)},yn=new WeakMap,sr=new WeakMap;function Zw(e,t){yn.get(e)?.(),sr.get(e)?.();const n=e.scrollTop,r=n+e.clientHeight;go(e,Vt(e)+e.scrollHeight),t();let o=0,s=!0;const a=performance.now(),l=()=>{const f=e.scrollHeight-Vt(e),m=Math.max(0,e.scrollTop+e.clientHeight-f);m<Vt(e)&&go(e,m),Vt(e)||(e.removeEventListener("scroll",l),sr.delete(e))},i=()=>{l(),Vt(e)&&(e.addEventListener("scroll",l,{passive:!0}),sr.set(e,()=>{e.removeEventListener("scroll",l),sr.delete(e)}))},c=()=>{e.removeEventListener("wheel",d),e.removeEventListener("touchmove",d),e.removeEventListener("keydown",d)},u=()=>{const f=Vt(e),m=e.scrollHeight-f;go(e,Math.max(0,r-m)),e.scrollTop=n,s&&performance.now()-a<260?o=requestAnimationFrame(u):(c(),yn.delete(e),i())},d=()=>{s&&(s=!1,cancelAnimationFrame(o),c(),yn.delete(e),requestAnimationFrame(()=>{yn.has(e)||i()}))};yn.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 e0=0;function pi(e,t){const n=e.state.doc.nodeAt(t.bqPos),r=!!n&&Dn(n)?.type==="fold",o=r?++e0:0;if(r){e.dispatch(e.state.tr.setMeta($e,{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?Zw(a,s):s(),r&&setTimeout(()=>{e.dom.isConnected&&e.dispatch(e.state.tr.setMeta($e,{foldEnd:o}))},matchMedia("(prefers-reduced-motion: reduce)").matches?0:230)}function fr(e){const t=e.state.selection;if(!t.empty||!e.hasFocus()||e.composing)return;const n=Ze(t.$from);if(!n||n.type!=="fold"||!n.inHead||$e.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 $e=new fe("amadeus-callout-src");function hd(e,t){if(!e.editable||t.isComposing)return!1;const{state:n}=e,r=Ze(n.selection.$from);if(!r||r.type!=="fold"||!r.inHead||$e.getState(n)?.srcAt===r.bqPos)return!1;const o=r.hidden[r.hidden.length-1][1];if(t.key==="Home"||t.key==="ArrowLeft"&&t.metaKey)return e.dispatch(n.tr.setSelection(j.create(n.doc,t.shiftKey?Math.max(o,n.selection.anchor):o,o))),fr(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=j.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(j.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(j.near(s.doc.resolve(a+2))).scrollIntoView()),!0}return!1}function mi(e){const t=e.selection;if(!t.empty)return null;const n=Ze(t.$from);if(!n||!n.inHead||$e.getState(e)?.srcAt===n.bqPos)return null;const r=n.hidden[n.hidden.length-1][1];return t.from<r?r:null}function t0(e,t,n){const r=e.doc.content.size;if(t<0||t>r)return null;const o=e.doc.resolve(t),s=Ze(o);if(!s||$e.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 n0(){return Q(()=>new Z({key:$e,state:{init:()=>({srcAt:null,animations:[]}),apply:(e,t)=>{const n=e.getMeta($e);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&&Dn(s)&&e.selection.from>o&&e.selection.to<o+s.nodeSize?o:null,animations:r}}},view(e){return fr(e),{update:fr}},appendTransaction(e,t,n){const r=Xw(e,n);if(r)return r;const o=n.selection;if(!o.empty)return null;const s=Ze(o.$from);if(s?.type==="fold"&&s.inHead&&$e.getState(n)?.srcAt!==s.bqPos){const u=s.hidden[s.hidden.length-1][1];if(o.from<u)return n.tr.setSelection(j.create(n.doc,u))}const a=Ze(o.$from,!0);if(!a)return null;if(a.type==="fold")return n.tr.setSelection(j.create(n.doc,a.headEnd));const l=u=>u.from<a.bqStart||u.from>=a.afterBq,i=j.near(n.doc.resolve(Math.min(a.afterBq,n.doc.content.size)),1);if(l(i))return n.tr.setSelection(i);const c=j.near(n.doc.resolve(Math.max(a.bqStart-1,0)),-1);return l(c)?n.tr.setSelection(c):n.tr.setSelection(j.create(n.doc,a.headEnd))},props:{handleDOMEvents:{blur:e=>($e.getState(e.state)?.srcAt!==null&&e.dispatch(e.state.tr.setMeta($e,{srcAt:null})),!1)},handleKeyDown(e,t){if(hd(e,t))return!0;if((t.key==="Enter"||t.key==="Delete")&&!t.isComposing&&!t.metaKey&&!t.ctrlKey&&!t.altKey){const r=mi(e.state);r!=null&&e.dispatch(e.state.tr.setSelection(j.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=t0(e.state,r.from+o,o);if(s!==null)return e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,s))),!0}return!1}if(t.key!=="Enter"||t.isComposing)return!1;const n=Qw(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?mi(e.state):null;if(o!=null&&t<o){const u=e.state.tr.insertText(r,o);return e.dispatch(u.setSelection(j.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(Qt)||!fd.test(c.slice(Qt.length))?!1:(e.dispatch(s.tr.insertText(r,t,n).delete(l,l+Qt.length).scrollIntoView()),!0)},handleClick(e,t){const n=Ze(e.state.doc.resolve(t));if(!n||!n.inHead||$e.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(j.create(e.state.doc,r))),e.focus(),fr(e),!0}return n.marker?(pi(e,n),!0):!1},handleDoubleClick(e,t){const n=Ze(e.state.doc.resolve(t));return!n||!n.inHead||n.type==="fold"||e.dispatch(e.state.tr.setMeta($e,{srcAt:n.bqPos})),!1},decorations(e){const t=[];return e.doc.descendants((n,r)=>{if(n.type.name!=="blockquote")return!0;const o=Dn(n);if(o){const{type:s,marker:a,token:l,hideLen:i,mark:c}=o,u=a==="-",d=$e.getState(e),f=d?.srcAt===r,m=s==="fold"?null:Gw(s);t.push(J.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(J.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(J.widget(r+2+i+(c?.len??0),()=>{const C=document.createElement("span");return C.className="callout-title-anchor",C.contentEditable="false",C.setAttribute("aria-hidden","true"),C.textContent="​",C},{side:-1,ignoreSelection:!0,key:`ca${r}`})),t.push(J.node(p,h,{class:"callout-toggle-title",...y?{"data-placeholder":O("mdcallout.title")}:{}}))}if(c&&t.push(J.node(p,h,{class:`callout-title-${c.cls}`})),s!=="fold"){const y=cd[m??"note"];if(t.push(J.widget(r+2,()=>{const C=document.createElement("span");return C.className="callout-icon",C.contentEditable="false",C.setAttribute("aria-hidden","true"),C.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>`,C},{side:-1,ignoreSelection:!0,key:`ci${r}:${m??"note"}`})),!f&&o.first.content.size===i+(c?.len??0)){const C=m?O(`mdcallout.type.${m}`):o.raw.charAt(0).toUpperCase()+o.raw.slice(1);t.push(J.widget(h-1,()=>{const N=document.createElement("span");return N.className="callout-default-title",N.contentEditable="false",N.textContent=C,N},{side:-1,ignoreSelection:!0,key:`cd${r}:${C}`}))}}f||(t.push(J.inline(r+2,r+2+i,{class:"callout-syntax"})),c&&t.push(J.inline(r+2+c.at,r+2+c.at+c.len,{class:`callout-syntax callout-syntax-${c.cls}`})));const g=r+2+s.length+3,w=s==="fold"?r+2:r+2+o.first.content.size;(s==="fold"||a)&&t.push(J.widget(w,y=>{const C=document.createElement("button");C.className=`callout-chevron${u?" collapsed":""}`,C.type="button",C.title=u?O("mdcallout.expand"):O("mdcallout.collapse"),C.setAttribute("aria-label",C.title),C.setAttribute("aria-expanded",String(!u)),C.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>',C.contentEditable="false",C.addEventListener("mousedown",T=>{T.preventDefault(),T.stopPropagation()});const N=()=>{const T=Ze(y.state.doc.resolve(r+2));T?.bqPos===r&&pi(y,T)},M=()=>{y.nodeDOM(r+1)?.querySelector(".callout-chevron")?.focus()};return C.addEventListener("keydown",T=>{T.key!==" "&&T.key!=="Enter"||(T.preventDefault(),T.stopPropagation(),document.addEventListener("keyup",M,{capture:!0,once:!0}),N())}),C.addEventListener("click",T=>{T.preventDefault(),T.stopPropagation(),N(),T.detail===0&&queueMicrotask(M)}),C},{side:s==="fold"?-1:1,ignoreSelection:!0,stopEvent:()=>!0,key:`cf${r}:${g}:${a??""}`})),s==="fold"&&(t.push(J.widget(r+2,y=>{const C=document.createElement("button");return C.type="button",C.className="amx-src-btn callout-source",C.contentEditable="false",C.textContent="</>",C.title=O("mdcallout.source"),C.setAttribute("aria-label",C.title),y.editable||(C.style.display="none"),C.onmousedown=N=>N.preventDefault(),C.onclick=N=>{N.preventDefault(),y.dispatch(y.state.tr.setMeta($e,{srcAt:r}).setSelection(j.create(y.state.doc,r+2))),y.focus()},C},{side:-1,stopEvent:()=>!0,key:`cs${r}`})),!u&&n.childCount===1&&t.push(J.widget(h,y=>{const C=document.createElement("button");return C.type="button",C.className="callout-empty",C.contentEditable="false",C.textContent=O("mdcallout.empty"),y.editable||(C.style.display="none"),C.onmousedown=N=>N.preventDefault(),C.onclick=()=>{const N=y.state.tr.insert(h,y.state.schema.nodes.paragraph.create());y.dispatch(N.setSelection(j.create(N.doc,h+1))),y.focus()},C},{side:-1,stopEvent:()=>!0,key:`ce${r}:${h}`})))}return!0}),t.length?me.create(e.doc,t):null}}}))}const Yt=Xf(Qf),hi=["javascript","typescript","python","bash","json","html","css","sql","java","go","rust","c","cpp","yaml","markdown","diff"],pr=[...hi,...Yt.listLanguages().filter(e=>!hi.includes(e)&&e!=="plaintext").sort()],r0=pr.filter(e=>!["markdown","ini","less","scss","vbnet","arduino","shell","python-repl","php-template"].includes(e)),o0=4096;let bo=0;function Yo(e){return["text","txt","plaintext"].includes(e.toLowerCase())}function s0(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 a0(e,t){const n=t.trim(),r={language:"",ranges:[]};if(!e||Yo(n))return r;try{let o=n,s;if(o){if(!Yt.registered(o))return r;bo++,s=Yt.highlight(o,e)}else{const c=e.slice(0,o0);if(o=s0(c),bo++,o)s=Yt.highlight(o,e);else{if(s=Yt.highlightAuto(c,{subset:r0}),!s.data?.language||(s.data.relevance??0)<3)return r;o=s.data.language,c.length<e.length&&(bo++,s=Yt.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}}De({"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 gi=new WeakMap;function gd(e){let t=gi.get(e);return t||(t=a0(e.textContent,String(e.attrs.language??"")),gi.set(e,t)),t}const Mt=new fe("amx-code-block");function bd(e,t,n){const r=n.wrapped.has(t),o=n.lineno.has(t)&&!r,s=n.collapsed.has(t),a=[J.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 gd(e).ranges)a.push(J.inline(t+1+l.from,t+1+l.to,{class:l.cls}));return a}function bi(e,t){const n=[];return e.descendants((r,o)=>r.type.name!=="code_block"?!0:(n.push(...bd(r,o,t)),!1)),n.length?me.create(e,n):me.empty}function l0(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,(w,y)=>w.type.name==="code_block"?(s.set(y,w),!1):w.isTextblock?(a.push([y,y+w.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,bd(c,i,n))}return r}const kn=[];function i0(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?O("amxcode.autoDetected",{language:r}):O("amxcode.langTitle");const c=document.createElement("option");c.value="";const u=r==="javascript"?"JS":r==="typescript"?"TS":r;c.textContent=r?O("amxcode.autoDetected",{language:u}):O("amxcode.auto"),i.appendChild(c);const d=document.createElement("option");d.value=Yo(n)?n:"plaintext",d.textContent=O("amxcode.plainText"),i.appendChild(d);const f=pr.includes(n)||!n||Yo(n),m=[...kn.filter(y=>pr.includes(y)),...pr.filter(y=>!kn.includes(y))];for(const y of f?m:[n,...m]){const C=document.createElement("option");C.value=y,C.textContent=y,i.appendChild(C)}i.value=n,i.addEventListener("change",()=>{const y=t();if(i.value){const N=kn.indexOf(i.value);N>=0&&kn.splice(N,1),kn.unshift(i.value)}if(y===null)return;const C=e.state.doc.nodeAt(y);C?.type.name==="code_block"&&e.dispatch(e.state.tr.setNodeMarkup(y,void 0,{...C.attrs,language:i.value}))});const p=document.createElement("button");p.className="amx-code-btn",p.textContent=O("amxcode.copy"),p.title=O("amxcode.copyTitle"),p.addEventListener("click",()=>{const y=t(),C=y===null?null:e.state.doc.nodeAt(y);C&&navigator.clipboard.writeText(C.textContent).then(()=>{p.textContent=O("amxcode.copied"),setTimeout(()=>{p.textContent=O("amxcode.copy")},1200)})});const h=document.createElement("button");h.className=`amx-code-btn${o?" on":""}`,h.textContent=O("amxcode.wrap"),h.title=O("amxcode.wrapTitle"),h.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y}))});const g=document.createElement("button");g.className=`amx-code-btn${s?" on":""}`,g.textContent=s?O("amxcode.linenoOff"):O("amxcode.lineno"),g.title=o?O("amxcode.linenoDisabled"):O("amxcode.linenoTitle"),g.disabled=o,g.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y,which:"lineno"}))});const w=document.createElement("button");if(w.className=`amx-code-btn${a?" on":""}`,w.textContent=a?O("amxcode.expand"):O("amxcode.collapse"),w.title=O("amxcode.collapseTitle"),w.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y,which:"collapse"}))}),l.append(i,p,h,g,w),ep(n)&&window.tangu?.pty){const y=document.createElement("button");y.className="amx-code-btn",y.textContent=O("amxcode.run"),y.title=O("amxcode.runTitle"),y.addEventListener("click",()=>{const C=t(),N=C===null?null:e.state.doc.nodeAt(C),M=N?tp(N.textContent):"";M&&np(M)}),l.append(y)}return l}class c0{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?"":gd(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=Mt.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"&&!!Zf("```forsion-button\n"+this.node.textContent+"\n```"),c=i?"button":`${t}:${n}:${s?1:0}:${a?1:0}:${l?1:0}:${sf()}`;if(c!==this.barSig){if(i)this.bar?.remove(),this.bar=null;else{const u=i0(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(`
39
+ ${r}`}De({"mdtask.checkbox":{zh:"完成",en:"Done"}});function Hw(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 Fw=ve("amadeusEmptyTask",()=>()=>Hw);function Yo(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 di=new fe("amadeusTaskA11y"),qw="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";function ld(e,t){return Y.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=qw;const s=()=>{o.setAttribute("aria-label",O("mdtask.checkbox"))};return s(),o.__off=es(s),o.addEventListener("click",a=>{if(a.preventDefault(),a.stopPropagation(),!n.editable)return;const l=r();if(l==null)return;const i=Yo(n.state,l);i&&n.dispatch(i)}),o},{side:-1,ignoreSelection:!0,key:`amxtask:${t?1:0}`,stopEvent:()=>!0,destroy:n=>{n.__off?.()}})}function id(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 Ww(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=id(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])=>ld(h,g)))})}),n}function fi(e,t){const n=t.target?.closest?.('li[data-item-type="task"]');return n?t.clientX-n.getBoundingClientRect().left>2?null:n:null}function Uw(){return Q(()=>new Z({key:di,state:{init:(e,t)=>me.create(t.doc,[...id(t.doc,0,t.doc.content.size)].map(([n,r])=>ld(n,r))),apply:Ww},props:{decorations:e=>di.getState(e),handleClick(e,t,n){if(!e.editable)return!1;const r=fi(e,n);if(!r)return!1;const o=Yo(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||!Jf())return!1;const n=fi(e,t);if(!n)return!1;const r=Yo(e.state,e.posAtDOM(n,0));return r?(t.preventDefault(),e.dispatch(r),!0):!1}}}}))}De({"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 Vw={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"},cd={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 Gw(e){const t=Vw[e]??e;return t in cd?t:null}function ud(e){const t=e.children?.[0];if(e.type==="blockquote"&&t?.type==="paragraph"&&t.position&&/^\[![\w-]+\][+-]?/.test(t.children?.[0]?.value??"")){const n=bu(t);n.length>1&&e.children.splice(0,1,...n)}e.children?.forEach(ud)}const Yw=ve("amadeusCalloutTitle",()=>()=>ud),dd=e=>e.replace(/^((?:[ \t]*>[ \t]?)+)\\\[!/gm,"$1[!"),fd=/^\[!([\w-]+)\]([+-])?/,Jw=/^(#{1,6}|[-*+]) /;function Dn(e){if(e.type.name!=="blockquote")return null;const t=e.firstChild,n=t&&t.isTextblock?fd.exec(t.textContent):null;if(!n||!t)return null;const r=/[ \u00a0]/.test(t.textContent[n[0].length]??"")?1:0,o=Jw.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 pd(e,t){e.doc.descendants((n,r)=>{const o=Dn(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 M1(e,t,n){pd(e,[[t,n]])}function Xw(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 pd(r,n),r.docChanged?r:null}function Ze(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=Dn(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 Qw=e=>{const t=Ze(e);return t&&t.collapsed?t:null},md="--amx-fold-scroll-buffer",Vt=e=>parseFloat(e.style.getPropertyValue(md))||0,go=(e,t)=>{e.style.setProperty(md,`${Math.max(0,Math.ceil(t))}px`)},yn=new WeakMap,sr=new WeakMap;function Zw(e,t){yn.get(e)?.(),sr.get(e)?.();const n=e.scrollTop,r=n+e.clientHeight;go(e,Vt(e)+e.scrollHeight),t();let o=0,s=!0;const a=performance.now(),l=()=>{const f=e.scrollHeight-Vt(e),m=Math.max(0,e.scrollTop+e.clientHeight-f);m<Vt(e)&&go(e,m),Vt(e)||(e.removeEventListener("scroll",l),sr.delete(e))},i=()=>{l(),Vt(e)&&(e.addEventListener("scroll",l,{passive:!0}),sr.set(e,()=>{e.removeEventListener("scroll",l),sr.delete(e)}))},c=()=>{e.removeEventListener("wheel",d),e.removeEventListener("touchmove",d),e.removeEventListener("keydown",d)},u=()=>{const f=Vt(e),m=e.scrollHeight-f;go(e,Math.max(0,r-m)),e.scrollTop=n,s&&performance.now()-a<260?o=requestAnimationFrame(u):(c(),yn.delete(e),i())},d=()=>{s&&(s=!1,cancelAnimationFrame(o),c(),yn.delete(e),requestAnimationFrame(()=>{yn.has(e)||i()}))};yn.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 e0=0;function pi(e,t){const n=e.state.doc.nodeAt(t.bqPos),r=!!n&&Dn(n)?.type==="fold",o=r?++e0:0;if(r){e.dispatch(e.state.tr.setMeta($e,{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?Zw(a,s):s(),r&&setTimeout(()=>{e.dom.isConnected&&e.dispatch(e.state.tr.setMeta($e,{foldEnd:o}))},matchMedia("(prefers-reduced-motion: reduce)").matches?0:230)}function fr(e){const t=e.state.selection;if(!t.empty||!e.hasFocus()||e.composing)return;const n=Ze(t.$from);if(!n||n.type!=="fold"||!n.inHead||$e.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 $e=new fe("amadeus-callout-src");function hd(e,t){if(!e.editable||t.isComposing)return!1;const{state:n}=e,r=Ze(n.selection.$from);if(!r||r.type!=="fold"||!r.inHead||$e.getState(n)?.srcAt===r.bqPos)return!1;const o=r.hidden[r.hidden.length-1][1];if(t.key==="Home"||t.key==="ArrowLeft"&&t.metaKey)return e.dispatch(n.tr.setSelection(j.create(n.doc,t.shiftKey?Math.max(o,n.selection.anchor):o,o))),fr(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=j.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(j.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(j.near(s.doc.resolve(a+2))).scrollIntoView()),!0}return!1}function mi(e){const t=e.selection;if(!t.empty)return null;const n=Ze(t.$from);if(!n||!n.inHead||$e.getState(e)?.srcAt===n.bqPos)return null;const r=n.hidden[n.hidden.length-1][1];return t.from<r?r:null}function t0(e,t,n){const r=e.doc.content.size;if(t<0||t>r)return null;const o=e.doc.resolve(t),s=Ze(o);if(!s||$e.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 n0(){return Q(()=>new Z({key:$e,state:{init:()=>({srcAt:null,animations:[]}),apply:(e,t)=>{const n=e.getMeta($e);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&&Dn(s)&&e.selection.from>o&&e.selection.to<o+s.nodeSize?o:null,animations:r}}},view(e){return fr(e),{update:fr}},appendTransaction(e,t,n){const r=Xw(e,n);if(r)return r;const o=n.selection;if(!o.empty)return null;const s=Ze(o.$from);if(s?.type==="fold"&&s.inHead&&$e.getState(n)?.srcAt!==s.bqPos){const u=s.hidden[s.hidden.length-1][1];if(o.from<u)return n.tr.setSelection(j.create(n.doc,u))}const a=Ze(o.$from,!0);if(!a)return null;if(a.type==="fold")return n.tr.setSelection(j.create(n.doc,a.headEnd));const l=u=>u.from<a.bqStart||u.from>=a.afterBq,i=j.near(n.doc.resolve(Math.min(a.afterBq,n.doc.content.size)),1);if(l(i))return n.tr.setSelection(i);const c=j.near(n.doc.resolve(Math.max(a.bqStart-1,0)),-1);return l(c)?n.tr.setSelection(c):n.tr.setSelection(j.create(n.doc,a.headEnd))},props:{handleDOMEvents:{blur:e=>($e.getState(e.state)?.srcAt!==null&&e.dispatch(e.state.tr.setMeta($e,{srcAt:null})),!1)},handleKeyDown(e,t){if(hd(e,t))return!0;if((t.key==="Enter"||t.key==="Delete")&&!t.isComposing&&!t.metaKey&&!t.ctrlKey&&!t.altKey){const r=mi(e.state);r!=null&&e.dispatch(e.state.tr.setSelection(j.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=t0(e.state,r.from+o,o);if(s!==null)return e.dispatch(e.state.tr.setSelection(j.create(e.state.doc,s))),!0}return!1}if(t.key!=="Enter"||t.isComposing)return!1;const n=Qw(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?mi(e.state):null;if(o!=null&&t<o){const u=e.state.tr.insertText(r,o);return e.dispatch(u.setSelection(j.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(Qt)||!fd.test(c.slice(Qt.length))?!1:(e.dispatch(s.tr.insertText(r,t,n).delete(l,l+Qt.length).scrollIntoView()),!0)},handleClick(e,t){const n=Ze(e.state.doc.resolve(t));if(!n||!n.inHead||$e.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(j.create(e.state.doc,r))),e.focus(),fr(e),!0}return n.marker?(pi(e,n),!0):!1},handleDoubleClick(e,t){const n=Ze(e.state.doc.resolve(t));return!n||!n.inHead||n.type==="fold"||e.dispatch(e.state.tr.setMeta($e,{srcAt:n.bqPos})),!1},decorations(e){const t=[];return e.doc.descendants((n,r)=>{if(n.type.name!=="blockquote")return!0;const o=Dn(n);if(o){const{type:s,marker:a,token:l,hideLen:i,mark:c}=o,u=a==="-",d=$e.getState(e),f=d?.srcAt===r,m=s==="fold"?null:Gw(s);t.push(Y.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(Y.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(Y.widget(r+2+i+(c?.len??0),()=>{const C=document.createElement("span");return C.className="callout-title-anchor",C.contentEditable="false",C.setAttribute("aria-hidden","true"),C.textContent="​",C},{side:-1,ignoreSelection:!0,key:`ca${r}`})),t.push(Y.node(p,h,{class:"callout-toggle-title",...y?{"data-placeholder":O("mdcallout.title")}:{}}))}if(c&&t.push(Y.node(p,h,{class:`callout-title-${c.cls}`})),s!=="fold"){const y=cd[m??"note"];if(t.push(Y.widget(r+2,()=>{const C=document.createElement("span");return C.className="callout-icon",C.contentEditable="false",C.setAttribute("aria-hidden","true"),C.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>`,C},{side:-1,ignoreSelection:!0,key:`ci${r}:${m??"note"}`})),!f&&o.first.content.size===i+(c?.len??0)){const C=m?O(`mdcallout.type.${m}`):o.raw.charAt(0).toUpperCase()+o.raw.slice(1);t.push(Y.widget(h-1,()=>{const N=document.createElement("span");return N.className="callout-default-title",N.contentEditable="false",N.textContent=C,N},{side:-1,ignoreSelection:!0,key:`cd${r}:${C}`}))}}f||(t.push(Y.inline(r+2,r+2+i,{class:"callout-syntax"})),c&&t.push(Y.inline(r+2+c.at,r+2+c.at+c.len,{class:`callout-syntax callout-syntax-${c.cls}`})));const g=r+2+s.length+3,w=s==="fold"?r+2:r+2+o.first.content.size;(s==="fold"||a)&&t.push(Y.widget(w,y=>{const C=document.createElement("button");C.className=`callout-chevron${u?" collapsed":""}`,C.type="button",C.title=u?O("mdcallout.expand"):O("mdcallout.collapse"),C.setAttribute("aria-label",C.title),C.setAttribute("aria-expanded",String(!u)),C.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>',C.contentEditable="false",C.addEventListener("mousedown",T=>{T.preventDefault(),T.stopPropagation()});const N=()=>{const T=Ze(y.state.doc.resolve(r+2));T?.bqPos===r&&pi(y,T)},M=()=>{y.nodeDOM(r+1)?.querySelector(".callout-chevron")?.focus()};return C.addEventListener("keydown",T=>{T.key!==" "&&T.key!=="Enter"||(T.preventDefault(),T.stopPropagation(),document.addEventListener("keyup",M,{capture:!0,once:!0}),N())}),C.addEventListener("click",T=>{T.preventDefault(),T.stopPropagation(),N(),T.detail===0&&queueMicrotask(M)}),C},{side:s==="fold"?-1:1,ignoreSelection:!0,stopEvent:()=>!0,key:`cf${r}:${g}:${a??""}`})),s==="fold"&&(t.push(Y.widget(r+2,y=>{const C=document.createElement("button");return C.type="button",C.className="amx-src-btn callout-source",C.contentEditable="false",C.textContent="</>",C.title=O("mdcallout.source"),C.setAttribute("aria-label",C.title),y.editable||(C.style.display="none"),C.onmousedown=N=>N.preventDefault(),C.onclick=N=>{N.preventDefault(),y.dispatch(y.state.tr.setMeta($e,{srcAt:r}).setSelection(j.create(y.state.doc,r+2))),y.focus()},C},{side:-1,stopEvent:()=>!0,key:`cs${r}`})),!u&&n.childCount===1&&t.push(Y.widget(h,y=>{const C=document.createElement("button");return C.type="button",C.className="callout-empty",C.contentEditable="false",C.textContent=O("mdcallout.empty"),y.editable||(C.style.display="none"),C.onmousedown=N=>N.preventDefault(),C.onclick=()=>{const N=y.state.tr.insert(h,y.state.schema.nodes.paragraph.create());y.dispatch(N.setSelection(j.create(N.doc,h+1))),y.focus()},C},{side:-1,stopEvent:()=>!0,key:`ce${r}:${h}`})))}return!0}),t.length?me.create(e.doc,t):null}}}))}const Jt=Xf(Qf),hi=["javascript","typescript","python","bash","json","html","css","sql","java","go","rust","c","cpp","yaml","markdown","diff"],pr=[...hi,...Jt.listLanguages().filter(e=>!hi.includes(e)&&e!=="plaintext").sort()],r0=pr.filter(e=>!["markdown","ini","less","scss","vbnet","arduino","shell","python-repl","php-template"].includes(e)),o0=4096;let bo=0;function Jo(e){return["text","txt","plaintext"].includes(e.toLowerCase())}function s0(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 a0(e,t){const n=t.trim(),r={language:"",ranges:[]};if(!e||Jo(n))return r;try{let o=n,s;if(o){if(!Jt.registered(o))return r;bo++,s=Jt.highlight(o,e)}else{const c=e.slice(0,o0);if(o=s0(c),bo++,o)s=Jt.highlight(o,e);else{if(s=Jt.highlightAuto(c,{subset:r0}),!s.data?.language||(s.data.relevance??0)<3)return r;o=s.data.language,c.length<e.length&&(bo++,s=Jt.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}}De({"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 gi=new WeakMap;function gd(e){let t=gi.get(e);return t||(t=a0(e.textContent,String(e.attrs.language??"")),gi.set(e,t)),t}const Mt=new fe("amx-code-block");function bd(e,t,n){const r=n.wrapped.has(t),o=n.lineno.has(t)&&!r,s=n.collapsed.has(t),a=[Y.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 gd(e).ranges)a.push(Y.inline(t+1+l.from,t+1+l.to,{class:l.cls}));return a}function bi(e,t){const n=[];return e.descendants((r,o)=>r.type.name!=="code_block"?!0:(n.push(...bd(r,o,t)),!1)),n.length?me.create(e,n):me.empty}function l0(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,(w,y)=>w.type.name==="code_block"?(s.set(y,w),!1):w.isTextblock?(a.push([y,y+w.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,bd(c,i,n))}return r}const kn=[];function i0(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?O("amxcode.autoDetected",{language:r}):O("amxcode.langTitle");const c=document.createElement("option");c.value="";const u=r==="javascript"?"JS":r==="typescript"?"TS":r;c.textContent=r?O("amxcode.autoDetected",{language:u}):O("amxcode.auto"),i.appendChild(c);const d=document.createElement("option");d.value=Jo(n)?n:"plaintext",d.textContent=O("amxcode.plainText"),i.appendChild(d);const f=pr.includes(n)||!n||Jo(n),m=[...kn.filter(y=>pr.includes(y)),...pr.filter(y=>!kn.includes(y))];for(const y of f?m:[n,...m]){const C=document.createElement("option");C.value=y,C.textContent=y,i.appendChild(C)}i.value=n,i.addEventListener("change",()=>{const y=t();if(i.value){const N=kn.indexOf(i.value);N>=0&&kn.splice(N,1),kn.unshift(i.value)}if(y===null)return;const C=e.state.doc.nodeAt(y);C?.type.name==="code_block"&&e.dispatch(e.state.tr.setNodeMarkup(y,void 0,{...C.attrs,language:i.value}))});const p=document.createElement("button");p.className="amx-code-btn",p.textContent=O("amxcode.copy"),p.title=O("amxcode.copyTitle"),p.addEventListener("click",()=>{const y=t(),C=y===null?null:e.state.doc.nodeAt(y);C&&navigator.clipboard.writeText(C.textContent).then(()=>{p.textContent=O("amxcode.copied"),setTimeout(()=>{p.textContent=O("amxcode.copy")},1200)})});const h=document.createElement("button");h.className=`amx-code-btn${o?" on":""}`,h.textContent=O("amxcode.wrap"),h.title=O("amxcode.wrapTitle"),h.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y}))});const g=document.createElement("button");g.className=`amx-code-btn${s?" on":""}`,g.textContent=s?O("amxcode.linenoOff"):O("amxcode.lineno"),g.title=o?O("amxcode.linenoDisabled"):O("amxcode.linenoTitle"),g.disabled=o,g.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y,which:"lineno"}))});const w=document.createElement("button");if(w.className=`amx-code-btn${a?" on":""}`,w.textContent=a?O("amxcode.expand"):O("amxcode.collapse"),w.title=O("amxcode.collapseTitle"),w.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Mt,{toggle:y,which:"collapse"}))}),l.append(i,p,h,g,w),ep(n)&&window.tangu?.pty){const y=document.createElement("button");y.className="amx-code-btn",y.textContent=O("amxcode.run"),y.title=O("amxcode.runTitle"),y.addEventListener("click",()=>{const C=t(),N=C===null?null:e.state.doc.nodeAt(C),M=N?tp(N.textContent):"";M&&np(M)}),l.append(y)}return l}class c0{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?"":gd(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=Mt.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"&&!!Zf("```forsion-button\n"+this.node.textContent+"\n```"),c=i?"button":`${t}:${n}:${s?1:0}:${a?1:0}:${l?1:0}:${sf()}`;if(c!==this.barSig){if(i)this.bar?.remove(),this.bar=null;else{const u=i0(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
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 u0(){return Q(()=>{const e=new Set;return new Z({key:Mt,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:bi(n.doc,r)}},apply(t,n){if(!t.docChanged&&!t.getMeta(Mt))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(Mt);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?bi(t.doc,l):l0(n.decos,t,l);return{...l,decos:i}}},props:{nodeViews:{code_block:(t,n,r)=>{let o;return o=new c0(t,n,r,()=>e.delete(o)),e.add(o),o}},decorations(t){return Mt.getState(t)?.decos??me.empty},handleTextInput:(t,n,r,o)=>hm(t,n,r,o),handleKeyDown:(t,n)=>n.key==="Backspace"&&!n.metaKey&&!n.ctrlKey&&!n.altKey&&!n.shiftKey&&!n.isComposing?gm(t):!1}})})}const d0=["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 Ct(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?d0.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 yd=e=>e.replace(/[?#].*$/,""),kd=e=>{try{return decodeURIComponent(e)}catch{return e}};function yi(e){const t=e.trim();if(!t||t.startsWith("#"))return"other";const n=Ct(t);return n?/^https?:/i.test(n)?"external":/\.md$/i.test(kd(yd(t)))?"note":"file":"other"}function ki(e,t,n=[]){const r=kd(yd(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 p0=ue(()=>new Ye(/\[([^[\]]+)\]\((\S+)\)$/,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=Ct(t[2]);return s?e.tr.replaceWith(n,r,e.schema.text(t[1],[o.create({href:s})])).removeStoredMark(o):null})),m0=/^ {0,3}(?:#{1,6}(?:\s|$)|[-*+]\s|\d{1,9}[.)]\s|>|```|~~~|\|.*\||(?:[-*_][ \t]*){3,}$|\[\^[^\]]+\]:)/,h0=/\*\*[^*\n]+\*\*|__[^_\n]+__|~~[^~\n]+~~|`[^`\n]+`|!?\[[^\]\n]*\]\([^)\n]*\)|\[\[[^\]\n]+\]\]|\$\$|%%/,g0=/^ {0,3}(?=[^\n]*\|)(?=[^\n]*-)[|:\- \t]+$/,b0=/^(?: {4}|\t)/;function y0(e){return e.replace(/\r\n?/g,`
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 u0(){return Q(()=>{const e=new Set;return new Z({key:Mt,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:bi(n.doc,r)}},apply(t,n){if(!t.docChanged&&!t.getMeta(Mt))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(Mt);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?bi(t.doc,l):l0(n.decos,t,l);return{...l,decos:i}}},props:{nodeViews:{code_block:(t,n,r)=>{let o;return o=new c0(t,n,r,()=>e.delete(o)),e.add(o),o}},decorations(t){return Mt.getState(t)?.decos??me.empty},handleTextInput:(t,n,r,o)=>hm(t,n,r,o),handleKeyDown:(t,n)=>n.key==="Backspace"&&!n.metaKey&&!n.ctrlKey&&!n.altKey&&!n.shiftKey&&!n.isComposing?gm(t):!1}})})}const d0=["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 Ct(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?d0.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 yd=e=>e.replace(/[?#].*$/,""),kd=e=>{try{return decodeURIComponent(e)}catch{return e}};function yi(e){const t=e.trim();if(!t||t.startsWith("#"))return"other";const n=Ct(t);return n?/^https?:/i.test(n)?"external":/\.md$/i.test(kd(yd(t)))?"note":"file":"other"}function ki(e,t,n=[]){const r=kd(yd(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 p0=ue(()=>new Je(/\[([^[\]]+)\]\((\S+)\)$/,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=Ct(t[2]);return s?e.tr.replaceWith(n,r,e.schema.text(t[1],[o.create({href:s})])).removeStoredMark(o):null})),m0=/^ {0,3}(?:#{1,6}(?:\s|$)|[-*+]\s|\d{1,9}[.)]\s|>|```|~~~|\|.*\||(?:[-*_][ \t]*){3,}$|\[\^[^\]]+\]:)/,h0=/\*\*[^*\n]+\*\*|__[^_\n]+__|~~[^~\n]+~~|`[^`\n]+`|!?\[[^\]\n]*\]\([^)\n]*\)|\[\[[^\]\n]+\]\]|\$\$|%%/,g0=/^ {0,3}(?=[^\n]*\|)(?=[^\n]*-)[|:\- \t]+$/,b0=/^(?: {4}|\t)/;function y0(e){return e.replace(/\r\n?/g,`
43
43
  `).split(`
44
44
  `).some(n=>m0.test(n)||g0.test(n)||b0.test(n)&&n.trim()!=="")?!0:h0.test(e)}function wd(e){return e.replace(/\r\n?/g,`
45
45
  `).replace(new RegExp("(?<!\\n)\\n(?!\\n)","g"),`
46
46
 
47
47
  `)}function k0(e,t){const n=e.trim();return t||!n||!/\s/.test(n)&&/^https?:\/\//i.test(n)?null:xd(e)?wd(e):e}function xd(e){return new RegExp("(?<!\\n)\\n(?!\\n)").test(e.replace(/\r\n?/g,`
48
- `).trim())&&!y0(e)}function w0(e,t){return t.length!==1||t[0]!=="paragraph"?"literal":e.trim()!==e?"inline-ws":"default"}const wi=",。;:!?、)」』】》",x0=new RegExp(`(?<![A-Za-z])(https?:\\/\\/[^\\s<>\\ufffc${wi}(「『【《]+)([ \\t\\u00a0\\u3000${wi}])$`,"i");function v0(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 C0=ue(()=>new Ye(x0,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=v0(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=Ct(s);return u?e.tr.addMark(n,i,o.create({href:u})).insertText(t[2],r).removeStoredMark(o):null}));let xi=null;function S0(e,t,n){xi??=Ai().use(Ni).use(Xo);let r;try{r=xi.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 M0={before:"",after:"",now:{line:1,column:1},lineShift:0};function A0(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,M0));return!/\s/.test(a)&&(s<0||s+1>=o.length)&&(a+=r?.after??""),a}function vd(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:S0(o,r?.before??"",A0(e,t,n,r))?o:null}const Cd=Zt.link;function Sd(e,t,n,r){const o=vd(e,t,n,r);return o==null?Cd(e,t,n,r):n.createTracker(r).move(o)}Sd.peek=(e,t,n,r)=>vd(e,t,n,r)!=null?"h":Cd.peek(e,t,n,r);const N0=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,link:Sd}}))}),E0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\#(?=[^\s#])/;function Md(e){return e.includes("\\#")?$r(e,t=>t.replace(E0,"$1#")):e}const T0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\==(?=[^\s=])/;function Ad(e){return e.includes("\\==")?$r(e,t=>t.replace(T0,"$1==")):e}De({"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 Nd(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 _n(e){return Au(yu(dd(Ui(Md(Ad(af(lf(e))))))))}function Ed(e,t){return Zb(e,t,_n)}function Td(e){return Au(yu(dd(Ui(Md(Ad(e))))))}const Ia="\0__amadeus_embed__",La="\0__amadeus_linkdb__",Ra="\0__amadeus_bookmark__",$a="\0__amadeus_template__",Da="\0__amadeus_image__",_a="\0__amadeus_column__",za="\0__amadeus_database__",Oa="\0__amadeus_drawing__",Id="\0__amadeus_card__",Ld="\0__amadeus_ai__",Rd="\0__amadeus_instructions__",$d="\0__amadeus_agent_task__",Dd="\0__amadeus_prompt__",Pa="\0__amadeus_noteview__",Ba="\0__amadeus_page__";function I0(e){const t=new fe("amx-placeholder-focus");return Q(()=>new Z({key:t,state:{init:()=>!1,apply:(n,r)=>{const o=n.getMeta(t);return o===void 0?r:o}},view:n=>{const r=()=>{t.getState(n.state)||n.dispatch(n.state.tr.setMeta(t,!0))},o=()=>{t.getState(n.state)&&n.dispatch(n.state.tr.setMeta(t,!1))};return n.dom.addEventListener("focus",r),n.dom.addEventListener("blur",o),queueMicrotask(()=>{!n.isDestroyed&&n.hasFocus()&&r()}),{destroy(){n.dom.removeEventListener("focus",r),n.dom.removeEventListener("blur",o)}}},props:{decorations(n){if(!t.getState(n))return null;const{doc:r}=n;return!(r.childCount===1&&!!r.firstChild?.isTextblock&&r.firstChild.content.size===0)||!r.firstChild?null:me.create(r,[J.node(0,r.firstChild.nodeSize,{class:"is-empty","data-placeholder":e()})])}}}))}function L0(e){if(!e)return null;for(const t of Array.from(e.files))if(t.type.startsWith("image/"))return t;return null}function R0(e){const t=e.state.selection;let n="",r=null;if(t instanceof Ve?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=Zo(l)??l;return!i||/^(?:https?:|data:|blob:)/i.test(i)?null:{reference:`![${String(r.attrs.alt??"")}](${i})`,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 $0(e,t){if(!e)return null;try{const l=e.getData(qi).trim();if(l&&(!t||l===t))return l}catch{}const n=Wp(),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 vi(e,t){const n=D0(e);if(!n)return e.endOfTextblock(t);let r;try{const s=t==="up"?ce.atStart(e.state.doc).from:ce.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 D0(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 Ci(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 _0(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 z0(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=_0(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 Ka({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:w=!1,unified:y=!1,attachmentPagePath:C,extraPlugins:N,onAskTangu:M,aiMenu:T}){const D=E.useRef(!1),H=E.useRef(C);H.current=C;const W=E.useRef(n);W.current=n;const $=E.useRef(r);$.current=r;const te=E.useRef(o);te.current=o;const Te=E.useRef(s);Te.current=s;const ze=E.useRef(a);ze.current=a;const ge=E.useRef(()=>!0);ge.current=i??(()=>!0);const ie=E.useRef(()=>{});ie.current=c??(()=>{});const[pe,Ae]=E.useState(null),[k,I]=E.useState(null),[R,re]=E.useState(null),U=E.useRef(null),[G,xe]=E.useState(null),We=E.useRef(null),[be,je]=E.useState(null),[Re,lt]=E.useState(null),[yt,Yn]=E.useState(null),Xr=E.useRef(null),Qr=E.useRef(null),Zr=E.useRef(null),dn=E.useRef(!1),fn=E.useRef(!1),[Xn,ee]=nk(),ja=Hi(),Hd=L=>{let S="";return ee()?.action(z=>{S=z.get(en)(L)}),Td(S)};tk(L=>{const S=(A,x)=>{const{state:P}=A,B=P.selection,oe=x.key.toLowerCase();if(p&&(x.metaKey||x.ctrlKey)&&(oe==="z"||oe==="y")){x.preventDefault(),x.stopPropagation();const ae=ja.getState();return oe==="y"||x.shiftKey?ae.redo():ae.undo(),!0}if(x.key===" "&&B.empty&&!x.metaKey&&!x.ctrlKey&&!x.altKey){const ae=fk(B.$from);if(ae&&ik(B.$from.parent.type.name,ae)&&pk(A,ae," "))return x.preventDefault(),!0}if(hd(A,x))return x.preventDefault(),!0;const Se=Zp(x);if(Se){const ae=em(P);if(ae)return x.preventDefault(),Me(ae,Se==="followNewTab"),!0}if(x.key==="Enter")return x.shiftKey?y?!1:(W.current.insertAfter(gk(A,Hd)??void 0),!0):!1;if(!x.metaKey&&!x.ctrlKey&&!x.altKey&&!x.shiftKey&&(x.key==="ArrowLeft"&&ti(A)||x.key==="Backspace"&&ti(A,!0)))return x.preventDefault(),!0;if(x.key==="Backspace"){if(y||!B.empty||B.$head.pos!==ce.atStart(P.doc).$head.pos)return!1;const ae=B.$head.parent,ye=P.schema.nodes.paragraph;return ae.type.name==="heading"&&ae.content.size>0&&ye?(A.dispatch(P.tr.setBlockType(B.$head.start(),B.$head.end(),ye)),!0):(hk(A)||(P.doc.textContent.trim()===""?W.current.deleteEmpty():W.current.mergePrev()),!0)}return x.key==="ArrowUp"?y?!1:(x.metaKey||x.ctrlKey)&&x.shiftKey?(W.current.moveDir("up"),!0):B.empty&&!x.metaKey&&!x.ctrlKey&&!x.shiftKey&&!x.altKey&&vi(A,"up")?(W.current.arrow("prev",Ci(A)),!0):!1:x.key==="ArrowDown"?y?!1:(x.metaKey||x.ctrlKey)&&x.shiftKey?(W.current.moveDir("down"),!0):B.empty&&!x.metaKey&&!x.ctrlKey&&!x.shiftKey&&!x.altKey&&vi(A,"down")?(W.current.arrow("next",Ci(A)),!0):!1:x.key==="Escape"&&p?(A.dom.blur(),Hp.getState().select(p),!0):!1},z=(A,x)=>{const P=()=>A.content.textBetween(0,A.content.size,`
48
+ `).trim())&&!y0(e)}function w0(e,t){return t.length!==1||t[0]!=="paragraph"?"literal":e.trim()!==e?"inline-ws":"default"}const wi=",。;:!?、)」』】》",x0=new RegExp(`(?<![A-Za-z])(https?:\\/\\/[^\\s<>\\ufffc${wi}(「『【《]+)([ \\t\\u00a0\\u3000${wi}])$`,"i");function v0(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 C0=ue(()=>new Je(x0,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=v0(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=Ct(s);return u?e.tr.addMark(n,i,o.create({href:u})).insertText(t[2],r).removeStoredMark(o):null}));let xi=null;function S0(e,t,n){xi??=Ai().use(Ni).use(Xo);let r;try{r=xi.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 M0={before:"",after:"",now:{line:1,column:1},lineShift:0};function A0(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,M0));return!/\s/.test(a)&&(s<0||s+1>=o.length)&&(a+=r?.after??""),a}function vd(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:S0(o,r?.before??"",A0(e,t,n,r))?o:null}const Cd=Zt.link;function Sd(e,t,n,r){const o=vd(e,t,n,r);return o==null?Cd(e,t,n,r):n.createTracker(r).move(o)}Sd.peek=(e,t,n,r)=>vd(e,t,n,r)!=null?"h":Cd.peek(e,t,n,r);const N0=Pn(e=>{e.update(Ft,t=>({...t,handlers:{...t.handlers,link:Sd}}))}),E0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\#(?=[^\s#])/;function Md(e){return e.includes("\\#")?$r(e,t=>t.replace(E0,"$1#")):e}const T0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\==(?=[^\s=])/;function Ad(e){return e.includes("\\==")?$r(e,t=>t.replace(T0,"$1==")):e}De({"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 Nd(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 _n(e){return Au(yu(dd(Ui(Md(Ad(af(lf(e))))))))}function Ed(e,t){return Zb(e,t,_n)}function Td(e){return Au(yu(dd(Ui(Md(Ad(e))))))}const Ia="\0__amadeus_embed__",La="\0__amadeus_linkdb__",Ra="\0__amadeus_bookmark__",$a="\0__amadeus_template__",Da="\0__amadeus_image__",_a="\0__amadeus_column__",za="\0__amadeus_database__",Oa="\0__amadeus_drawing__",Id="\0__amadeus_card__",Ld="\0__amadeus_ai__",Rd="\0__amadeus_instructions__",$d="\0__amadeus_agent_task__",Dd="\0__amadeus_prompt__",Pa="\0__amadeus_noteview__",Ba="\0__amadeus_page__";function I0(e){const t=new fe("amx-placeholder-focus");return Q(()=>new Z({key:t,state:{init:()=>!1,apply:(n,r)=>{const o=n.getMeta(t);return o===void 0?r:o}},view:n=>{const r=()=>{t.getState(n.state)||n.dispatch(n.state.tr.setMeta(t,!0))},o=()=>{t.getState(n.state)&&n.dispatch(n.state.tr.setMeta(t,!1))};return n.dom.addEventListener("focus",r),n.dom.addEventListener("blur",o),queueMicrotask(()=>{!n.isDestroyed&&n.hasFocus()&&r()}),{destroy(){n.dom.removeEventListener("focus",r),n.dom.removeEventListener("blur",o)}}},props:{decorations(n){if(!t.getState(n))return null;const{doc:r}=n;return!(r.childCount===1&&!!r.firstChild?.isTextblock&&r.firstChild.content.size===0)||!r.firstChild?null:me.create(r,[Y.node(0,r.firstChild.nodeSize,{class:"is-empty","data-placeholder":e()})])}}}))}function L0(e){if(!e)return null;for(const t of Array.from(e.files))if(t.type.startsWith("image/"))return t;return null}function R0(e){const t=e.state.selection;let n="",r=null;if(t instanceof Ve?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=Zo(l)??l;return!i||/^(?:https?:|data:|blob:)/i.test(i)?null:{reference:`![${String(r.attrs.alt??"")}](${i})`,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 $0(e,t){if(!e)return null;try{const l=e.getData(qi).trim();if(l&&(!t||l===t))return l}catch{}const n=Wp(),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 vi(e,t){const n=D0(e);if(!n)return e.endOfTextblock(t);let r;try{const s=t==="up"?ce.atStart(e.state.doc).from:ce.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 D0(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 Ci(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 _0(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 z0(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=_0(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 Ka({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:w=!1,unified:y=!1,attachmentPagePath:C,extraPlugins:N,onAskTangu:M,aiMenu:T}){const D=E.useRef(!1),H=E.useRef(C);H.current=C;const W=E.useRef(n);W.current=n;const $=E.useRef(r);$.current=r;const te=E.useRef(o);te.current=o;const Te=E.useRef(s);Te.current=s;const ze=E.useRef(a);ze.current=a;const ge=E.useRef(()=>!0);ge.current=i??(()=>!0);const ie=E.useRef(()=>{});ie.current=c??(()=>{});const[pe,Ae]=E.useState(null),[k,I]=E.useState(null),[R,re]=E.useState(null),U=E.useRef(null),[G,xe]=E.useState(null),We=E.useRef(null),[be,je]=E.useState(null),[Re,lt]=E.useState(null),[yt,Jn]=E.useState(null),Xr=E.useRef(null),Qr=E.useRef(null),Zr=E.useRef(null),dn=E.useRef(!1),fn=E.useRef(!1),[Xn,ee]=nk(),ja=Hi(),Hd=L=>{let S="";return ee()?.action(z=>{S=z.get(en)(L)}),Td(S)};tk(L=>{const S=(A,x)=>{const{state:P}=A,B=P.selection,oe=x.key.toLowerCase();if(p&&(x.metaKey||x.ctrlKey)&&(oe==="z"||oe==="y")){x.preventDefault(),x.stopPropagation();const ae=ja.getState();return oe==="y"||x.shiftKey?ae.redo():ae.undo(),!0}if(x.key===" "&&B.empty&&!x.metaKey&&!x.ctrlKey&&!x.altKey){const ae=fk(B.$from);if(ae&&ik(B.$from.parent.type.name,ae)&&pk(A,ae," "))return x.preventDefault(),!0}if(hd(A,x))return x.preventDefault(),!0;const Se=Zp(x);if(Se){const ae=em(P);if(ae)return x.preventDefault(),Me(ae,Se==="followNewTab"),!0}if(x.key==="Enter")return x.shiftKey?y?!1:(W.current.insertAfter(gk(A,Hd)??void 0),!0):!1;if(!x.metaKey&&!x.ctrlKey&&!x.altKey&&!x.shiftKey&&(x.key==="ArrowLeft"&&ti(A)||x.key==="Backspace"&&ti(A,!0)))return x.preventDefault(),!0;if(x.key==="Backspace"){if(y||!B.empty||B.$head.pos!==ce.atStart(P.doc).$head.pos)return!1;const ae=B.$head.parent,ye=P.schema.nodes.paragraph;return ae.type.name==="heading"&&ae.content.size>0&&ye?(A.dispatch(P.tr.setBlockType(B.$head.start(),B.$head.end(),ye)),!0):(hk(A)||(P.doc.textContent.trim()===""?W.current.deleteEmpty():W.current.mergePrev()),!0)}return x.key==="ArrowUp"?y?!1:(x.metaKey||x.ctrlKey)&&x.shiftKey?(W.current.moveDir("up"),!0):B.empty&&!x.metaKey&&!x.ctrlKey&&!x.shiftKey&&!x.altKey&&vi(A,"up")?(W.current.arrow("prev",Ci(A)),!0):!1:x.key==="ArrowDown"?y?!1:(x.metaKey||x.ctrlKey)&&x.shiftKey?(W.current.moveDir("down"),!0):B.empty&&!x.metaKey&&!x.ctrlKey&&!x.shiftKey&&!x.altKey&&vi(A,"down")?(W.current.arrow("next",Ci(A)),!0):!1:x.key==="Escape"&&p?(A.dom.blur(),Hp.getState().select(p),!0):!1},z=(A,x)=>{const P=()=>A.content.textBetween(0,A.content.size,`
49
49
 
50
- `),B=A.content.childCount===1?A.content.firstChild:null,oe=B?.type.name==="image"?B:B?.type.name==="paragraph"&&B.childCount===1&&B.firstChild?.type.name==="image"?B.firstChild:null;if(oe){const we=String(oe.attrs.src??"");return`![${String(oe.attrs.alt??"")}](${Zo(we)??we})`}const Se=x.state.selection,{$from:he,$to:ae}=Se;if(!(Se instanceof Ve||!he.sameParent(ae)||he.parentOffset===0&&ae.parentOffset===ae.parent.content.size))return P();let it=!1;if(A.content.forEach(we=>{we.type.name!=="paragraph"&&(it=!0)}),!it)return P();const mn=Se instanceof Ve&&Se.node.type.name==="list_item"&&/_list$/.test(he.parent.type.name)?X.from(he.parent.type.create(he.parent.attrs,A.content)):A.content,Lt=x.state.schema.topNodeType.createAndFill(void 0,mn);if(!Lt)return P();let Rt=!1;Lt.descendants(we=>(/^amadeusCanvasCard$|^amadeusColumn/.test(we.type.name)&&(Rt=!0),!Rt));let ke=kg(()=>{let we="";return ee()?.action($t=>{we=$t.get(en)(Lt)}),_n(we)});return Rt&&(ke=ke.replace(/^<!--\s*\/?a\s+[A-Za-z0-9_-]+\s*-->[ \t]*\n?/gm,"")),ko(ke).trim()||P()},_=async(A,x)=>{const P=await $.current(x);if(!P)return;const B=A.state.schema.nodes.image;B&&A.dispatch(A.state.tr.replaceSelectionWith(B.create({src:P})).scrollIntoView())},K=(A,x)=>{const P=A.state.selection,B=(x.clipboardData?.getData("text/plain")??"").trim(),oe=$0(x.clipboardData,B);if(oe)return B?!1:(x.preventDefault(),A.pasteText(oe));const Se=A.state.schema.marks.link;if(Se&&!P.empty&&P.$from.sameParent(P.$to)&&P.$from.parent.type.allowsMarkType(Se)&&B&&!/\s/.test(B)&&/^https?:\/\//i.test(B)){const ke=Ct(B);if(ke)return x.preventDefault(),A.dispatch(A.state.tr.addMark(P.from,P.to,Se.create({href:ke}))),!0}const he=L0(x.clipboardData);if(he)return x.preventDefault(),_(A,he),!0;const ae=Array.from(x.clipboardData?.files??[]);if(ae.length)return x.preventDefault(),te.current(ae),!0;if(y&&P.empty&&B&&!/\s/.test(B)&&/^https?:\/\//i.test(B)&&P.$from.parent.type.name==="paragraph"&&P.$from.parent.content.size===0){x.preventDefault();const ke=P.from,ct=ke+B.length;let we=null;try{we=A.coordsAtPos(ke)}catch{}return A.dispatch(A.state.tr.insertText(B,ke,P.to).setMeta("uiEvent","paste")),we&&Yn({url:B,from:ke,to:ct,left:we.left,top:we.bottom,anchorTop:we.top}),!0}const ye=x.clipboardData?.getData("text/plain")??"",it=x.clipboardData?.getData("text/html")??"",mn=!!P.$from.parent.type.spec.code;if(y&&ye&&!mn&&A.input?.shiftKey){x.preventDefault();const ke=ye.replace(/\r\n?/g,`
50
+ `),B=A.content.childCount===1?A.content.firstChild:null,oe=B?.type.name==="image"?B:B?.type.name==="paragraph"&&B.childCount===1&&B.firstChild?.type.name==="image"?B.firstChild:null;if(oe){const we=String(oe.attrs.src??"");return`![${String(oe.attrs.alt??"")}](${Zo(we)??we})`}const Se=x.state.selection,{$from:he,$to:ae}=Se;if(!(Se instanceof Ve||!he.sameParent(ae)||he.parentOffset===0&&ae.parentOffset===ae.parent.content.size))return P();let it=!1;if(A.content.forEach(we=>{we.type.name!=="paragraph"&&(it=!0)}),!it)return P();const mn=Se instanceof Ve&&Se.node.type.name==="list_item"&&/_list$/.test(he.parent.type.name)?X.from(he.parent.type.create(he.parent.attrs,A.content)):A.content,Lt=x.state.schema.topNodeType.createAndFill(void 0,mn);if(!Lt)return P();let Rt=!1;Lt.descendants(we=>(/^amadeusCanvasCard$|^amadeusColumn/.test(we.type.name)&&(Rt=!0),!Rt));let ke=kg(()=>{let we="";return ee()?.action($t=>{we=$t.get(en)(Lt)}),_n(we)});return Rt&&(ke=ke.replace(/^<!--\s*\/?a\s+[A-Za-z0-9_-]+\s*-->[ \t]*\n?/gm,"")),ko(ke).trim()||P()},_=async(A,x)=>{const P=await $.current(x);if(!P)return;const B=A.state.schema.nodes.image;B&&A.dispatch(A.state.tr.replaceSelectionWith(B.create({src:P})).scrollIntoView())},K=(A,x)=>{const P=A.state.selection,B=(x.clipboardData?.getData("text/plain")??"").trim(),oe=$0(x.clipboardData,B);if(oe)return B?!1:(x.preventDefault(),A.pasteText(oe));const Se=A.state.schema.marks.link;if(Se&&!P.empty&&P.$from.sameParent(P.$to)&&P.$from.parent.type.allowsMarkType(Se)&&B&&!/\s/.test(B)&&/^https?:\/\//i.test(B)){const ke=Ct(B);if(ke)return x.preventDefault(),A.dispatch(A.state.tr.addMark(P.from,P.to,Se.create({href:ke}))),!0}const he=L0(x.clipboardData);if(he)return x.preventDefault(),_(A,he),!0;const ae=Array.from(x.clipboardData?.files??[]);if(ae.length)return x.preventDefault(),te.current(ae),!0;if(y&&P.empty&&B&&!/\s/.test(B)&&/^https?:\/\//i.test(B)&&P.$from.parent.type.name==="paragraph"&&P.$from.parent.content.size===0){x.preventDefault();const ke=P.from,ct=ke+B.length;let we=null;try{we=A.coordsAtPos(ke)}catch{}return A.dispatch(A.state.tr.insertText(B,ke,P.to).setMeta("uiEvent","paste")),we&&Jn({url:B,from:ke,to:ct,left:we.left,top:we.bottom,anchorTop:we.top}),!0}const ye=x.clipboardData?.getData("text/plain")??"",it=x.clipboardData?.getData("text/html")??"",mn=!!P.$from.parent.type.spec.code;if(y&&ye&&!mn&&A.input?.shiftKey){x.preventDefault();const ke=ye.replace(/\r\n?/g,`
51
51
  `).split(`
52
- `),ct=A.state.schema.nodes.paragraph;if(ke.length===1||!ct)A.dispatch(A.state.tr.insertText(ke.join(" ")).scrollIntoView().setMeta("uiEvent","paste"));else{const we=X.from(ke.map($t=>ct.create(null,$t?A.state.schema.text($t):null)));A.dispatch(A.state.tr.replaceSelection(new Ie(we,1,1)).scrollIntoView().setMeta("uiEvent","paste"))}return!0}const Lt=P.$from,Rt=P.$to;if(y&&ye&&!it&&!mn&&!/[\r\n]/.test(ye)&&Lt.sameParent(Rt)&&Lt.parent.isTextblock&&(Lt.parentOffset>0||Rt.parentOffset<Rt.parent.content.size)){let ke=null;ee()?.action(we=>{ke=we.get(hr)(ye)??null});const ct=ke;if(ct){const we=[];ct.forEach(Qn=>{we.push(Qn.type.name)});const $t=w0(ye,we);if($t==="literal")return x.preventDefault(),A.dispatch(A.state.tr.insertText(ye).scrollIntoView().setMeta("uiEvent","paste")),!0;if($t==="inline-ws"){x.preventDefault();const{schema:Qn}=A.state,Ja=/^\s*/.exec(ye)[0],Ya=/\s*$/.exec(ye)[0],Zn=[];return Ja&&Zn.push(Qn.text(Ja)),ct.firstChild.forEach(tf=>{Zn.push(tf)}),Ya&&Zn.push(Qn.text(Ya)),A.dispatch(A.state.tr.replaceSelection(new Ie(X.from(Zn),0,0)).scrollIntoView().setMeta("uiEvent","paste")),!0}}}if(y&&ye&&!it&&!mn&&xd(ye)){const ke=new DataTransfer;return ke.setData("text/plain",wd(ye)),x.preventDefault(),A.pasteText(ke.getData("text/plain"),new ClipboardEvent("paste",{clipboardData:ke}))}return!1},V=(A,x)=>{if(!C||!Oe.copyAttachment)return!1;const P=R0(A),B=x;if(!P||!B.clipboardData)return!1;B.preventDefault(),B.clipboardData.clearData(),B.clipboardData.setData("text/plain",P.reference);try{B.clipboardData.setData(qi,P.reference)}catch{}return Oe.copyAttachment(C,P.ref,P.reference).then(oe=>{oe&&Fp(P.reference,P.ref)}),!0};let ne=!1;const Ce=()=>(ne=!0,queueMicrotask(()=>{ne=!1}),!1),Me=(A,x)=>{const P=x?{newTab:!0}:void 0;if(A.kind==="wiki")return Te.current(A.arg,P);const B=yi(A.href);if(B==="note")return Te.current(ki(A.href,H.current,ze.current()),P);if(B==="file"){H.current&&Oe.openAttachment(H.current,A.href);return}const oe=Ct(A.href);oe&&window.open(oe,"_blank","noopener")},He=(A,x,P)=>{if(P.button===2||ol&&P.ctrlKey)return!1;const B=P.target?.closest?.("a[href]");if(!B||!B.getAttribute("href"))return!1;const oe=yi(B.getAttribute("href"));if(oe==="file")return!1;if(oe==="note"){P.preventDefault();const he=P.button===1||(ol?P.metaKey:P.ctrlKey);return Te.current(ki(B.getAttribute("href"),H.current,ze.current()),he?{newTab:!0}:void 0),!0}const Se=Ct(B.getAttribute("href"));return Se?(P.preventDefault(),window.open(Se,"_blank","noopener"),!0):!1};return Bp.make().config(A=>{A.set(Kp,L),A.set(jp,e),A.update(Pi,x=>({...x,editable:()=>!w,handleKeyDown:w?void 0:S,handlePaste:w?void 0:K,handleDOMEvents:w?x.handleDOMEvents:{...x.handleDOMEvents,copy:V,drop:Ce},clipboardTextParser:w?void 0:(P,B,oe,Se)=>{if(!ne)return null;ne=!1;const he=k0(P,oe);if(he==null)return null;const ae=A.get(hr)(he);if(!ae||typeof ae=="string")return null;const ye=Ki.fromSchema(Se.state.schema).serializeFragment(ae.content);return Bi.fromSchema(Se.state.schema).parseSlice(ye)},handleClick:He,clipboardTextSerializer:z})),y?A.get(Er).updated((x,P)=>{!D.current||w||t(Ed(x,P))}):A.get(Er).markdownUpdated((x,P)=>{!D.current||w||t(_n(P))})}).use(tl("high",{pagePath:()=>H.current})).use(dy).use(zb).use(cb).use(Fw).use(Eg).use($g).use(Ag).use(N0).use(y?Qg:Zg).use(Jw).use(iu).use(Do).use(_o).use(Dg).use(_g).use(zg).use(ao).use(Tl).use(Il).use(Yp()).use(Fg()).use(My).use(Uu).use(I0(()=>O("mdblock.placeholder"))).use(Sk()).use(Xp((A,x)=>Te.current(A,x),A=>ge.current(A),A=>ie.current(A))).use(Qp(Me)).use(Q(()=>new Z({props:{attributes:()=>H.current?{"data-amx-src":H.current}:{}}}))).use(Q(()=>new Z({view:A=>{const x=()=>{A.dom.setAttribute("aria-label",O("mdblock.editorLabel"))};return x(),{destroy:es(x)}}}))).use(zw()).use(ak()).use(Tk((A,x)=>{if(!A){x||(Zr.current=null),dn.current=!1,Ae(null);return}if(Zr.current===A.from){dn.current=!1,Ae(null);return}dn.current=!0,Ae(A)})).use(Lk((A,x)=>{if(!A){x||(Xr.current=null),fn.current=!1,I(null);return}if(Xr.current===A.from){fn.current=!1;return}fn.current=!0,I(A)})).use(fw((A,x)=>{if(!A){x||(U.current=null),re(null);return}if(U.current===A.from){re(null);return}re(A)})).use(gw((A,x)=>{if(!A){x||(We.current=null),xe(null);return}if(We.current===A.from){xe(null);return}xe(A)})).use(Ik((A,x)=>{if(h){if(!A){x||(Qr.current=null),je(null);return}if(dn.current||fn.current){je(null);return}if(Qr.current===A.from){je(null);return}je(A)}})).use(Dk(A=>lt(h?A:null))).use(zu).use(Uw()).use(n0()).use(u0()).use(fm).use(rk).use(Q(A=>nl({"Mod-u":()=>(A.get(se).call(ao.key),!0),"Mod-Shift-s":()=>(A.get(se).call(Tn.key),!0),"Mod-k":()=>Va(),"Mod-Shift-v":(x,P,B)=>!B?.editable||!navigator.clipboard?.readText?!1:(navigator.clipboard.readText().then(oe=>{oe&&!B.isDestroyed&&B.pasteText(oe)}).catch(()=>{}),!0),"Mod-Shift-h":qg,"Alt-F10":()=>{const x=document.querySelector('[data-testid="inline-toolbar"] .itb-row button');return x?(x.focus(),!0):!1},"Mod-Shift-l":(x,P)=>or(x,P,"left"),"Mod-Shift-e":(x,P)=>or(x,P,"center"),"Mod-Shift-r":(x,P)=>or(x,P,"right")}))).use(Q(()=>nl({Tab:(A,x,P)=>y?!1:my(A,x,P),"Shift-Tab":(A,x)=>y?!1:hy(A,x)}))).use(p0).use(C0).use(Ek).use(Nw).use($w).use(tl("normal",{pagePath:()=>H.current})).use(N??[])},[]),E.useEffect(()=>{if(h)return h.current={consume:()=>{let L=!0;return ee()?.action(S=>{const z=S.get(le),{$from:_,empty:K}=z.state.selection;if(K){const V=Ql(_);V&&z.dispatch(z.state.tr.delete(V.from,V.to))}L=z.state.doc.textContent.trim()===""}),L},transform:L=>{let S=!1;return ee()?.action(z=>{const _=z.get(le),{$from:K,empty:V}=_.state.selection;S=Kt(_,L,V?Ql(K):null),_.focus()}),S}},()=>{h&&(h.current=null)}},[h,ee]),E.useEffect(()=>{const L=requestAnimationFrame(()=>{D.current=!0});return()=>cancelAnimationFrame(L)},[]);const Ha=L=>S=>!(S.target instanceof Element&&S.target.closest(L)),Fa=!!be;E.useEffect(()=>{if(!Fa)return;const L=Ha(".slash-menu"),S=_=>{L(_)&&je(null)},z=()=>je(null);return window.addEventListener("scroll",S,!0),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",z)}},[Fa]);const qa=!!Re;E.useEffect(()=>{if(!qa)return;const L=Ha(".inline-toolbar"),S=_=>{L(_)&&lt(null)},z=()=>lt(null);return window.addEventListener("scroll",S,!0),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",z)}},[qa]);const Wa=!!yt;E.useEffect(()=>{if(!Wa)return;const L=()=>Yn(null);return window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[Wa]);const Fd=L=>{const S=yt;Yn(null),S&&ee()?.action(z=>{const _=z.get(le);if(!(S.to>_.state.doc.content.size||_.state.doc.textBetween(S.from,S.to)!==S.url)){if(L==="bookmark"){const K=_.state.doc.resolve(S.to),V=K.after(K.depth),ne=_.state.tr,Ce=ne.doc.nodeAt(V),Me=_.state.schema.nodes.paragraph;Me&&!(Ce?.type.name==="paragraph"&&Ce.content.size===0)&&ne.insert(V,Me.create()),ne.setSelection(j.near(ne.doc.resolve(Math.min(V+1,ne.doc.content.size)))),_.dispatch(ne),_.focus();return}if(L==="embed"){const K=`![[${cf(S.url)}]]`,V=_.state.tr.insertText(K,S.from,S.to),ne=V.doc.resolve(Math.min(S.from+K.length,V.doc.content.size)),Ce=ne.after(ne.depth),Me=V.doc.nodeAt(Ce),He=_.state.schema.nodes.paragraph;He&&!(Me?.type.name==="paragraph"&&Me.content.size===0)&&V.insert(Ce,He.create()),V.setSelection(j.near(V.doc.resolve(Math.min(Ce+1,V.doc.content.size)))),_.dispatch(V)}else{const K=_.state.schema.marks.link,V=Rr(S.url),ne=_.state.tr.insertText(V,S.from,S.to);K&&ne.addMark(S.from,S.from+V.length,K.create({href:Ct(S.url)||S.url})),_.dispatch(ne)}_.focus()}})};E.useEffect(()=>{if(u==null||Xn)return;const L=ee();L&&(L.action(S=>{const z=S.get(le);if(z.focus(),u==="body-enter"){const ne=z.state.schema.nodes.paragraph,Ce=z.state.doc.firstChild;let Me=z.state.tr;ne&&!(Ce&&Ce.type===ne&&Ce.content.size===0)&&(Me=Me.insert(0,ne.create())),z.dispatch(Me.setSelection(j.near(Me.doc.resolve(1))).scrollIntoView());return}const _=u==="end"?ce.atEnd(z.state.doc):ce.atStart(z.state.doc);z.dispatch(z.state.tr.setSelection(_).scrollIntoView());const K=d!=null?z0(z,u,d):null;K!=null&&z.dispatch(z.state.tr.setSelection(j.near(z.state.doc.resolve(K))).scrollIntoView());const V=f?mk(z,f):null;V!=null&&z.dispatch(z.state.tr.setSelection(j.near(z.state.doc.resolve(V))).scrollIntoView())}),m())},[u,d,f,Xn,ee,m]),E.useEffect(()=>ja.subscribe((L,S)=>{L.pages===S.pages||Xn||ee()?.action(z=>{const _=z.get(le);_.dispatch(_.state.tr)})}),[Xn,ee]);const qd=L=>{const S=pe;S&&ee()?.action(_=>{const K=_.get(le),{doc:V}=K.state;if(S.closeAt!==void 0&&V.textBetween(S.closeAt,Math.min(S.closeAt+2,V.content.size))==="]]"){const ne=Ow(V.textBetween(S.to,S.closeAt,void 0,""),L),Ce=K.state.tr.insertText(ne,S.from,S.closeAt);K.dispatch(Ce.setSelection(j.create(Ce.doc,S.from+ne.length+2)))}else K.dispatch(K.state.tr.insertText(`${L}]]`,S.from,S.to));K.focus()}),Ae(null)},pn=()=>{let L=!1;return ee()?.action(S=>{L=S.get(le).hasFocus()}),L},Wd=()=>{let L=null;return ee()?.action(S=>{L=S.get(le).dom}),L},Ud=L=>{const S=k;S&&ee()?.action(_=>{const K=_.get(le);K.dispatch(K.state.tr.insertText(`[[${L}]]`,S.from-1,S.to)),K.focus()}),I(null)},Vd=L=>{if(!k||!y||!Fe()?.submitDocumentTask||Fe()?.hostExecution?.()===!1)return;const S=k;ee()?.action(z=>{const _=z.get(le),K=_.state.schema.nodes.code_block.create({language:"forsion-task"},_.state.schema.text(ad(jw(L))));_.dispatch(_.state.tr.replaceRangeWith(S.from-1,S.to,K).scrollIntoView()),_.focus()}),I(null)},Gd=L=>{const S=k;S&&ee()?.action(_=>{const K=_.get(le);K.dispatch(K.state.tr.insertText(`${L} `,S.from-1,S.to)),K.focus()}),I(null)},Jd=L=>{const S=R;S&&ee()?.action(z=>{const _=z.get(le),K=_.state.doc.textBetween(S.to,Math.min(S.to+1,_.state.doc.content.size),void 0,"");_.dispatch(_.state.tr.insertText(/^\s/.test(K)?L:`${L} `,S.from,S.to)),_.focus()}),re(null)},Yd=L=>{const S=G;S&&ee()?.action(z=>{const _=z.get(le);_.dispatch(_.state.tr.insertText(L,S.from-1,S.to)),_.focus()}),xe(null)},Ua=()=>{const L=a(),S=new Set(L),z=rp().filter(K=>S.has(K)),_=new Set(z);return[...z,...L.filter(K=>!_.has(K))]},It=(L,S)=>{ee()?.action(z=>{z.get(se).call(L,S),z.get(le).focus()})},Va=()=>{const L=ee();if(!L)return!1;let S=!1;return L.action(z=>{const _=z.get(le),K=Ge.type(z),{from:V,to:ne,empty:Ce,$from:Me}=_.state.selection;if(!Me.parent.isTextblock||Me.parent.type.spec.code)return;S=!0;const He=Bd(_.state.doc,V,ne,K),A=_.state.doc,x=He??{from:V,to:ne};(He?lp(O("mdblock.link.editTitle"),He.href,{label:O("mdblock.link.label"),altLabel:O("mdblock.link.remove")}):xo(O("mdblock.link.title"),"",{label:O("mdblock.link.label")})).then(B=>{const oe=B===null||B===to?null:Ct(B);B!==to&&!oe||ee()?.action(Se=>{const he=Se.get(le);if(he.state.doc!==A)return;const ae=Ge.type(Se);if(B===to)he.dispatch(he.state.tr.removeMark(x.from,x.to,ae));else if(x.to>x.from)he.dispatch(he.state.tr.removeMark(x.from,x.to,ae).addMark(x.from,x.to,ae.create({href:oe})));else if(oe){const ye=Rr(oe),it=he.state.tr.insertText(ye,x.from);it.addMark(x.from,x.from+ye.length,ae.create({href:oe})),he.dispatch(it.setSelection(j.create(it.doc,x.from+ye.length)).scrollIntoView())}he.focus()})})}),S},Xd=()=>{ee()?.action(L=>{const S=L.get(le),{from:z,to:_,empty:K}=S.state.selection;K||S.dispatch(S.state.tr.removeMark(z,_,null)),S.focus()})},eo=L=>{ee()?.action(S=>{const z=S.get(le);or(z.state,_=>z.dispatch(_),L),z.focus()})},Qd={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"}},Zd=L=>{let S=!1;return ee()?.action(z=>{const _=z.get(le),{state:K}=_;if(Qu(K.selection).tableCell)return;const{$from:V,$to:ne}=K.selection,Ce=V.before(V.depth),Me=ne.after(ne.depth),He=K.doc.textBetween(Ce,Me,`
52
+ `),ct=A.state.schema.nodes.paragraph;if(ke.length===1||!ct)A.dispatch(A.state.tr.insertText(ke.join(" ")).scrollIntoView().setMeta("uiEvent","paste"));else{const we=X.from(ke.map($t=>ct.create(null,$t?A.state.schema.text($t):null)));A.dispatch(A.state.tr.replaceSelection(new Ie(we,1,1)).scrollIntoView().setMeta("uiEvent","paste"))}return!0}const Lt=P.$from,Rt=P.$to;if(y&&ye&&!it&&!mn&&!/[\r\n]/.test(ye)&&Lt.sameParent(Rt)&&Lt.parent.isTextblock&&(Lt.parentOffset>0||Rt.parentOffset<Rt.parent.content.size)){let ke=null;ee()?.action(we=>{ke=we.get(hr)(ye)??null});const ct=ke;if(ct){const we=[];ct.forEach(Qn=>{we.push(Qn.type.name)});const $t=w0(ye,we);if($t==="literal")return x.preventDefault(),A.dispatch(A.state.tr.insertText(ye).scrollIntoView().setMeta("uiEvent","paste")),!0;if($t==="inline-ws"){x.preventDefault();const{schema:Qn}=A.state,Ya=/^\s*/.exec(ye)[0],Ja=/\s*$/.exec(ye)[0],Zn=[];return Ya&&Zn.push(Qn.text(Ya)),ct.firstChild.forEach(tf=>{Zn.push(tf)}),Ja&&Zn.push(Qn.text(Ja)),A.dispatch(A.state.tr.replaceSelection(new Ie(X.from(Zn),0,0)).scrollIntoView().setMeta("uiEvent","paste")),!0}}}if(y&&ye&&!it&&!mn&&xd(ye)){const ke=new DataTransfer;return ke.setData("text/plain",wd(ye)),x.preventDefault(),A.pasteText(ke.getData("text/plain"),new ClipboardEvent("paste",{clipboardData:ke}))}return!1},V=(A,x)=>{if(!C||!Oe.copyAttachment)return!1;const P=R0(A),B=x;if(!P||!B.clipboardData)return!1;B.preventDefault(),B.clipboardData.clearData(),B.clipboardData.setData("text/plain",P.reference);try{B.clipboardData.setData(qi,P.reference)}catch{}return Oe.copyAttachment(C,P.ref,P.reference).then(oe=>{oe&&Fp(P.reference,P.ref)}),!0};let ne=!1;const Ce=()=>(ne=!0,queueMicrotask(()=>{ne=!1}),!1),Me=(A,x)=>{const P=x?{newTab:!0}:void 0;if(A.kind==="wiki")return Te.current(A.arg,P);const B=yi(A.href);if(B==="note")return Te.current(ki(A.href,H.current,ze.current()),P);if(B==="file"){H.current&&Oe.openAttachment(H.current,A.href);return}const oe=Ct(A.href);oe&&window.open(oe,"_blank","noopener")},He=(A,x,P)=>{if(P.button===2||ol&&P.ctrlKey)return!1;const B=P.target?.closest?.("a[href]");if(!B||!B.getAttribute("href"))return!1;const oe=yi(B.getAttribute("href"));if(oe==="file")return!1;if(oe==="note"){P.preventDefault();const he=P.button===1||(ol?P.metaKey:P.ctrlKey);return Te.current(ki(B.getAttribute("href"),H.current,ze.current()),he?{newTab:!0}:void 0),!0}const Se=Ct(B.getAttribute("href"));return Se?(P.preventDefault(),window.open(Se,"_blank","noopener"),!0):!1};return Bp.make().config(A=>{A.set(Kp,L),A.set(jp,e),A.update(Pi,x=>({...x,editable:()=>!w,handleKeyDown:w?void 0:S,handlePaste:w?void 0:K,handleDOMEvents:w?x.handleDOMEvents:{...x.handleDOMEvents,copy:V,drop:Ce},clipboardTextParser:w?void 0:(P,B,oe,Se)=>{if(!ne)return null;ne=!1;const he=k0(P,oe);if(he==null)return null;const ae=A.get(hr)(he);if(!ae||typeof ae=="string")return null;const ye=Ki.fromSchema(Se.state.schema).serializeFragment(ae.content);return Bi.fromSchema(Se.state.schema).parseSlice(ye)},handleClick:He,clipboardTextSerializer:z})),y?A.get(Er).updated((x,P)=>{!D.current||w||t(Ed(x,P))}):A.get(Er).markdownUpdated((x,P)=>{!D.current||w||t(_n(P))})}).use(tl("high",{pagePath:()=>H.current})).use(dy).use(zb).use(cb).use(Fw).use(Eg).use($g).use(Ag).use(N0).use(y?Qg:Zg).use(Yw).use(iu).use(Do).use(_o).use(Dg).use(_g).use(zg).use(ao).use(Tl).use(Il).use(Jp()).use(Fg()).use(My).use(Uu).use(I0(()=>O("mdblock.placeholder"))).use(Sk()).use(Xp((A,x)=>Te.current(A,x),A=>ge.current(A),A=>ie.current(A))).use(Qp(Me)).use(Q(()=>new Z({props:{attributes:()=>H.current?{"data-amx-src":H.current}:{}}}))).use(Q(()=>new Z({view:A=>{const x=()=>{A.dom.setAttribute("aria-label",O("mdblock.editorLabel"))};return x(),{destroy:es(x)}}}))).use(zw()).use(ak()).use(Tk((A,x)=>{if(!A){x||(Zr.current=null),dn.current=!1,Ae(null);return}if(Zr.current===A.from){dn.current=!1,Ae(null);return}dn.current=!0,Ae(A)})).use(Lk((A,x)=>{if(!A){x||(Xr.current=null),fn.current=!1,I(null);return}if(Xr.current===A.from){fn.current=!1;return}fn.current=!0,I(A)})).use(fw((A,x)=>{if(!A){x||(U.current=null),re(null);return}if(U.current===A.from){re(null);return}re(A)})).use(gw((A,x)=>{if(!A){x||(We.current=null),xe(null);return}if(We.current===A.from){xe(null);return}xe(A)})).use(Ik((A,x)=>{if(h){if(!A){x||(Qr.current=null),je(null);return}if(dn.current||fn.current){je(null);return}if(Qr.current===A.from){je(null);return}je(A)}})).use(Dk(A=>lt(h?A:null))).use(zu).use(Uw()).use(n0()).use(u0()).use(fm).use(rk).use(Q(A=>nl({"Mod-u":()=>(A.get(se).call(ao.key),!0),"Mod-Shift-s":()=>(A.get(se).call(Tn.key),!0),"Mod-k":()=>Va(),"Mod-Shift-v":(x,P,B)=>!B?.editable||!navigator.clipboard?.readText?!1:(navigator.clipboard.readText().then(oe=>{oe&&!B.isDestroyed&&B.pasteText(oe)}).catch(()=>{}),!0),"Mod-Shift-h":qg,"Alt-F10":()=>{const x=document.querySelector('[data-testid="inline-toolbar"] .itb-row button');return x?(x.focus(),!0):!1},"Mod-Shift-l":(x,P)=>or(x,P,"left"),"Mod-Shift-e":(x,P)=>or(x,P,"center"),"Mod-Shift-r":(x,P)=>or(x,P,"right")}))).use(Q(()=>nl({Tab:(A,x,P)=>y?!1:my(A,x,P),"Shift-Tab":(A,x)=>y?!1:hy(A,x)}))).use(p0).use(C0).use(Ek).use(Nw).use($w).use(tl("normal",{pagePath:()=>H.current})).use(N??[])},[]),E.useEffect(()=>{if(h)return h.current={consume:()=>{let L=!0;return ee()?.action(S=>{const z=S.get(le),{$from:_,empty:K}=z.state.selection;if(K){const V=Ql(_);V&&z.dispatch(z.state.tr.delete(V.from,V.to))}L=z.state.doc.textContent.trim()===""}),L},transform:L=>{let S=!1;return ee()?.action(z=>{const _=z.get(le),{$from:K,empty:V}=_.state.selection;S=Kt(_,L,V?Ql(K):null),_.focus()}),S}},()=>{h&&(h.current=null)}},[h,ee]),E.useEffect(()=>{const L=requestAnimationFrame(()=>{D.current=!0});return()=>cancelAnimationFrame(L)},[]);const Ha=L=>S=>!(S.target instanceof Element&&S.target.closest(L)),Fa=!!be;E.useEffect(()=>{if(!Fa)return;const L=Ha(".slash-menu"),S=_=>{L(_)&&je(null)},z=()=>je(null);return window.addEventListener("scroll",S,!0),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",z)}},[Fa]);const qa=!!Re;E.useEffect(()=>{if(!qa)return;const L=Ha(".inline-toolbar"),S=_=>{L(_)&&lt(null)},z=()=>lt(null);return window.addEventListener("scroll",S,!0),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",z)}},[qa]);const Wa=!!yt;E.useEffect(()=>{if(!Wa)return;const L=()=>Jn(null);return window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[Wa]);const Fd=L=>{const S=yt;Jn(null),S&&ee()?.action(z=>{const _=z.get(le);if(!(S.to>_.state.doc.content.size||_.state.doc.textBetween(S.from,S.to)!==S.url)){if(L==="bookmark"){const K=_.state.doc.resolve(S.to),V=K.after(K.depth),ne=_.state.tr,Ce=ne.doc.nodeAt(V),Me=_.state.schema.nodes.paragraph;Me&&!(Ce?.type.name==="paragraph"&&Ce.content.size===0)&&ne.insert(V,Me.create()),ne.setSelection(j.near(ne.doc.resolve(Math.min(V+1,ne.doc.content.size)))),_.dispatch(ne),_.focus();return}if(L==="embed"){const K=`![[${cf(S.url)}]]`,V=_.state.tr.insertText(K,S.from,S.to),ne=V.doc.resolve(Math.min(S.from+K.length,V.doc.content.size)),Ce=ne.after(ne.depth),Me=V.doc.nodeAt(Ce),He=_.state.schema.nodes.paragraph;He&&!(Me?.type.name==="paragraph"&&Me.content.size===0)&&V.insert(Ce,He.create()),V.setSelection(j.near(V.doc.resolve(Math.min(Ce+1,V.doc.content.size)))),_.dispatch(V)}else{const K=_.state.schema.marks.link,V=Rr(S.url),ne=_.state.tr.insertText(V,S.from,S.to);K&&ne.addMark(S.from,S.from+V.length,K.create({href:Ct(S.url)||S.url})),_.dispatch(ne)}_.focus()}})};E.useEffect(()=>{if(u==null||Xn)return;const L=ee();L&&(L.action(S=>{const z=S.get(le);if(z.focus(),u==="body-enter"){const ne=z.state.schema.nodes.paragraph,Ce=z.state.doc.firstChild;let Me=z.state.tr;ne&&!(Ce&&Ce.type===ne&&Ce.content.size===0)&&(Me=Me.insert(0,ne.create())),z.dispatch(Me.setSelection(j.near(Me.doc.resolve(1))).scrollIntoView());return}const _=u==="end"?ce.atEnd(z.state.doc):ce.atStart(z.state.doc);z.dispatch(z.state.tr.setSelection(_).scrollIntoView());const K=d!=null?z0(z,u,d):null;K!=null&&z.dispatch(z.state.tr.setSelection(j.near(z.state.doc.resolve(K))).scrollIntoView());const V=f?mk(z,f):null;V!=null&&z.dispatch(z.state.tr.setSelection(j.near(z.state.doc.resolve(V))).scrollIntoView())}),m())},[u,d,f,Xn,ee,m]),E.useEffect(()=>ja.subscribe((L,S)=>{L.pages===S.pages||Xn||ee()?.action(z=>{const _=z.get(le);_.dispatch(_.state.tr)})}),[Xn,ee]);const qd=L=>{const S=pe;S&&ee()?.action(_=>{const K=_.get(le),{doc:V}=K.state;if(S.closeAt!==void 0&&V.textBetween(S.closeAt,Math.min(S.closeAt+2,V.content.size))==="]]"){const ne=Ow(V.textBetween(S.to,S.closeAt,void 0,""),L),Ce=K.state.tr.insertText(ne,S.from,S.closeAt);K.dispatch(Ce.setSelection(j.create(Ce.doc,S.from+ne.length+2)))}else K.dispatch(K.state.tr.insertText(`${L}]]`,S.from,S.to));K.focus()}),Ae(null)},pn=()=>{let L=!1;return ee()?.action(S=>{L=S.get(le).hasFocus()}),L},Wd=()=>{let L=null;return ee()?.action(S=>{L=S.get(le).dom}),L},Ud=L=>{const S=k;S&&ee()?.action(_=>{const K=_.get(le);K.dispatch(K.state.tr.insertText(`[[${L}]]`,S.from-1,S.to)),K.focus()}),I(null)},Vd=L=>{if(!k||!y||!Fe()?.submitDocumentTask||Fe()?.hostExecution?.()===!1)return;const S=k;ee()?.action(z=>{const _=z.get(le),K=_.state.schema.nodes.code_block.create({language:"forsion-task"},_.state.schema.text(ad(jw(L))));_.dispatch(_.state.tr.replaceRangeWith(S.from-1,S.to,K).scrollIntoView()),_.focus()}),I(null)},Gd=L=>{const S=k;S&&ee()?.action(_=>{const K=_.get(le);K.dispatch(K.state.tr.insertText(`${L} `,S.from-1,S.to)),K.focus()}),I(null)},Yd=L=>{const S=R;S&&ee()?.action(z=>{const _=z.get(le),K=_.state.doc.textBetween(S.to,Math.min(S.to+1,_.state.doc.content.size),void 0,"");_.dispatch(_.state.tr.insertText(/^\s/.test(K)?L:`${L} `,S.from,S.to)),_.focus()}),re(null)},Jd=L=>{const S=G;S&&ee()?.action(z=>{const _=z.get(le);_.dispatch(_.state.tr.insertText(L,S.from-1,S.to)),_.focus()}),xe(null)},Ua=()=>{const L=a(),S=new Set(L),z=rp().filter(K=>S.has(K)),_=new Set(z);return[...z,...L.filter(K=>!_.has(K))]},It=(L,S)=>{ee()?.action(z=>{z.get(se).call(L,S),z.get(le).focus()})},Va=()=>{const L=ee();if(!L)return!1;let S=!1;return L.action(z=>{const _=z.get(le),K=Ge.type(z),{from:V,to:ne,empty:Ce,$from:Me}=_.state.selection;if(!Me.parent.isTextblock||Me.parent.type.spec.code)return;S=!0;const He=Bd(_.state.doc,V,ne,K),A=_.state.doc,x=He??{from:V,to:ne};(He?lp(O("mdblock.link.editTitle"),He.href,{label:O("mdblock.link.label"),altLabel:O("mdblock.link.remove")}):xo(O("mdblock.link.title"),"",{label:O("mdblock.link.label")})).then(B=>{const oe=B===null||B===to?null:Ct(B);B!==to&&!oe||ee()?.action(Se=>{const he=Se.get(le);if(he.state.doc!==A)return;const ae=Ge.type(Se);if(B===to)he.dispatch(he.state.tr.removeMark(x.from,x.to,ae));else if(x.to>x.from)he.dispatch(he.state.tr.removeMark(x.from,x.to,ae).addMark(x.from,x.to,ae.create({href:oe})));else if(oe){const ye=Rr(oe),it=he.state.tr.insertText(ye,x.from);it.addMark(x.from,x.from+ye.length,ae.create({href:oe})),he.dispatch(it.setSelection(j.create(it.doc,x.from+ye.length)).scrollIntoView())}he.focus()})})}),S},Xd=()=>{ee()?.action(L=>{const S=L.get(le),{from:z,to:_,empty:K}=S.state.selection;K||S.dispatch(S.state.tr.removeMark(z,_,null)),S.focus()})},eo=L=>{ee()?.action(S=>{const z=S.get(le);or(z.state,_=>z.dispatch(_),L),z.focus()})},Qd={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"}},Zd=L=>{let S=!1;return ee()?.action(z=>{const _=z.get(le),{state:K}=_;if(Qu(K.selection).tableCell)return;const{$from:V,$to:ne}=K.selection,Ce=V.before(V.depth),Me=ne.after(ne.depth),He=K.doc.textBetween(Ce,Me,`
53
53
  `,`
54
- `).trim(),A=L==="codeblock"?K.schema.nodes.code_block?.create(null,He?K.schema.text(He):void 0):K.schema.nodes.paragraph?.create(null,K.schema.text(`$$ ${He} $$`));if(!A)return;const x=K.tr.replaceWith(Ce,Me,A);x.setSelection(j.near(x.doc.resolve(Ce+1))),_.dispatch(x.scrollIntoView()),_.focus(),S=!0}),S},Ga=L=>{const S=Pk[L];window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.turn.failed",{kind:S?O(S):L})}}))},ef=L=>{if(L==="codeblock"||L==="math"){Zd(L)||Ga(L);return}const S=Qd[L];if(S){let _=!1;ee()?.action(K=>{const V=K.get(le);_=Kt(V,S,null),V.focus()}),_||Ga(L);return}({bold:()=>It(zr.key),italic:()=>It(_r.key),underline:()=>It(ao.key),strike:()=>It(Tn.key),code:()=>It(Or.key),link:Va,clear:Xd,alignLeft:()=>eo("left"),alignCenter:()=>eo("center"),alignRight:()=>eo("right")})[L]?.()};return b.jsxs(b.Fragment,{children:[b.jsx(ek,{}),b.jsxs(Fi,{children:[pe&&!w&&b.jsx(li,{query:pe.query,left:pe.left,top:pe.top,anchorTop:pe.anchorTop,getPageNames:Ua,getFiles:l,onPick:qd,onClose:()=>{Zr.current=pe.from,dn.current=!1,Ae(null)},editorFocused:pn,sourcePath:C}),!pe&&k&&!w&&b.jsx(li,{query:k.query,left:k.left,top:k.top,anchorTop:k.anchorTop,getPageNames:Ua,getFiles:l,onPick:Ud,onPickRaw:Gd,agents:y&&Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1?Fe()?.agents?.():void 0,onPickAgent:y&&Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1?Vd:void 0,editorFocused:pn,dates:!0,allowCreate:!1,onClose:()=>{Xr.current=k.from,fn.current=!1,I(null)}}),R&&!pe&&!k&&!w&&b.jsx(mw,{query:R.query,left:R.left,top:R.top,anchorTop:R.anchorTop,onPick:Jd,editorFocused:pn,onClose:()=>{U.current=R.from,re(null)}}),G&&!pe&&!k&&!R&&!be&&!w&&b.jsx(bw,{query:G.query,left:G.left,top:G.top,anchorTop:G.anchorTop,onPick:Yd,editorFocused:pn,onClose:()=>{We.current=G.from,xe(null)}}),be&&g&&!pe&&!k&&!w&&b.jsx(W0,{query:be.query,left:be.left,top:be.top,anchorTop:be.anchorTop,hideKeys:y?K0:void 0,ctx:be.ctx,unified:y,editorFocused:pn,editorDom:Wd,onPick:L=>{je(null),ee()?.action(S=>{ni(S.get(le),be.from)}),g(L)},onClose:()=>{let L=!1;ee()?.action(S=>{const z=S.get(le);if(!ni(z,be.from))return;const{doc:_}=z.state;be.from<1||be.to>_.content.size||_.textBetween(be.from-1,be.from)!=="/"||(z.dispatch(z.state.tr.delete(be.from-1,be.to)),L=!0)}),L||(Qr.current=be.from),je(null)}}),yt&&!w&&b.jsx(q0,{left:yt.left,top:yt.top,anchorTop:yt.anchorTop,url:yt.url,onPick:Fd,onClose:()=>Yn(null)}),Re&&!pe&&!k&&!be&&!yt&&!w&&b.jsx(Bk,{left:Re.left,top:Re.top,bottom:Re.bottom,kind:Re.kind,active:Re.active,align:Re.align,shape:Re.shape,fg:Re.fg,bg:Re.bg,onAct:ef,onColor:L=>It(Tl.key,L||void 0),onBg:L=>It(Il.key,L||void 0),onClose:()=>{lt(null),ee()?.action(L=>{const S=L.get(le);S.dispatch(S.state.tr.setMeta(dr,!0))})},onReturnFocus:()=>ee()?.action(L=>L.get(le).focus()),onAsk:M?()=>{lt(null),ee()?.action(L=>M(L.get(le)))}:void 0,ai:T?{items:T.items,onPick:L=>{lt(null),ee()?.action(S=>T.onPick(L,S.get(le)))}}:void 0})]})]})}function _d({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:w=!1}){const y=Hi(),C=n.split("/").slice(0,-1).join("/"),N=E.useRef(t),[M,T]=E.useState(0),[D,H]=E.useState(!1),W=E.useRef(null);t!==N.current&&(N.current=t,T(k=>k+1));const $=k=>{const I=gf(k,C);N.current=I,r(I)},te=async k=>{if(!n)return null;try{const I=new Uint8Array(await k.arrayBuffer()),{opts:R}=await no(),{pageRel:re}=await Oe.saveAttachment(n,k.name||"pasted.png",I,R);return Ti(hf(C,re))}catch{return null}},Te=async k=>{if(!n)return;const I=[];for(const R of k)try{const re=new Uint8Array(await R.arrayBuffer()),{opts:U}=await no(),{base:G}=await Oe.saveAttachment(n,R.name||"file",re,U);I.push(`![[${G}]]`)}catch{}I.length&&(t.trim()===""?(r(I[0]),I.length>1&&y.getState().insertBlocksAfter(e,I.slice(1))):y.getState().insertBlocksAfter(e,I))},ze={insertAfter:o,deleteEmpty:s,mergePrev:a,arrow:l,moveDir:i,selfFocus:m},ge=(k,I)=>{const R=y.getState();if(R.activePage!==n||!R.blocks[e]){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.toast.staleTarget")}}));return}const re=(R.blocks[e].content??"").trim()==="";I&&re?r(k):o(k)},ie=async k=>{const I=k.scaffold;if(!W.current)return;const R=k.run?void 0:zd[I];if(R){W.current.transform(R)||Kd(k.label);return}const re=W.current.consume();if(k.run){try{const U=await k.run({pagePath:n,folder:er(n)});if(U!==""&&U!=null){if(typeof U!="string")throw new Error(O("mdblock.plugin.runNotString",{type:typeof U}));if(U.length>8192)throw new Error(O("mdblock.plugin.runTooLong"));if(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(U))throw new Error(O("mdblock.plugin.runControlChars"));ge(U,re),y.getState().syncFdChildren(n)}}catch(U){console.error("[plugin] slash item failed",U),window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.toast.slashFailed",{label:k.label,message:U instanceof Error?U.message:String(U)}),error:!0}}))}return}if(I===$a){window.dispatchEvent(new CustomEvent("amadeus:template-picker",{detail:{afterId:e,emptyBlock:re}}));return}if(I===Da){const U=document.createElement("input");U.type="file",U.accept="image/*",U.onchange=()=>{const G=U.files?.[0];G&&(async()=>{try{const xe=new Uint8Array(await G.arrayBuffer()),{opts:We}=await no(),{base:be}=await Oe.saveAttachment(n,G.name||"image.png",xe,We),je=`![[${be}]]`;ge(je,re)}catch{}})()},U.click();return}if(I===Ba){(async()=>{try{const U=y.getState(),G=await U.createChildNote(n,O("mdblock.default.childNote")),We=`[[${G.split("/").pop().replace(/\.md$/i,"")}]]`;ge(We,re),U.loadPage(G)}catch{}})();return}if(I===za){(async()=>{try{const U=O("mdblock.default.database"),G=new TextEncoder().encode(el(df(U))),{base:xe}=await Oe.saveAttachment(n,`${U}.db`,G,{mode:"vault",folder:er(n)}),We=`![[${xe}]]`;ge(We,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===Oa){(async()=>{try{const U=new TextEncoder().encode(ff(pf)),xe=`![[${(await Oe.saveAttachment(n,`${Nd(O("mdblock.default.drawing"))}.excalidraw.md`,U,{mode:"vault",folder:er(n)})).base.replace(/\.md$/i,"")}]]`;ge(xe,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===Pa){(async()=>{try{const U=er(n);let G=null;for(let Re=1;Re<=20&&G===null;Re++)try{const lt=O("mdblock.default.noteViewFolder");G=await Oe.createFolder(U,Re===1?lt:`${lt} ${Re}`)}catch{}if(G===null)return;const xe=O("mdblock.default.noteView"),We=new TextEncoder().encode(el(mf(xe,G))),{base:be}=await Oe.saveAttachment(n,`${xe}.db`,We,{mode:"vault",folder:U}),je=`![[${be}]]`;ge(je,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===_a){y.getState().splitToColumn(e,"right");return}if(I===La){H(!0);return}if(I===Ra){xo(O("mdblock.bookmark.title"),"",{label:O("mdblock.bookmark.label")}).then(U=>{const G=U?.trim();G&&/^https?:\/\/\S+$/i.test(G)&&(re?r(G):o(G))});return}if(I===Ia){if(!h)return;let U="";try{const G=await navigator.clipboard.readText(),xe=/!\[\[([^\]\n]+)\]\]/.exec(G);xe&&(U=xe[1].trim())}catch{}xo(O("mdblock.embed.title"),U,{label:O("mdblock.embed.label"),confirmLabel:O("mdblock.embed.confirm")}).then(G=>{const xe=G?.trim().replace(/^!?\[\[/,"").replace(/\]\]$/,"").trim();xe&&h(xe)});return}re?(r(I),setTimeout(()=>m("end"),0)):o(I)},pe=E.useRef(()=>{});pe.current=k=>{ie(k)};const Ae=E.useRef(k=>pe.current(k)).current;return E.useEffect(()=>()=>{An===Ae&&(An=null)},[Ae]),b.jsxs("div",{className:"md-block",onFocusCapture:()=>{w||(An=Ae)},children:[b.jsx(Vu,{children:b.jsx(Ka,{initial:uf(t,C),onChange:$,keys:ze,saveImage:te,saveFiles:Te,onOpenWiki:p,getPageNames:g,blockId:e,slashOpsRef:W,onSlashPick:ie,getFiles:()=>Pp()?y.getState().files:[],isWikiResolved:k=>!!yo(k,g(),n)||!!Op(k,y.getState().files,n),wikiIcon:k=>{const I=yo(k,g(),n);return I?y.getState().icons[I]:void 0},focusPlace:c,focusGoalX:u,focusAnchor:d,onFocused:f,attachmentPagePath:n,readOnly:w})},`${M}:${w?1:0}`),D&&!w&&b.jsx(Fi,{children:b.jsx(jd,{onClose:()=>H(!1),onPick:k=>{H(!1);const I=`![[${k}]]`;t.trim()===""?r(I):o(I)}})})]})}function O0({initial:e,onChange:t,readOnly:n=!1,immediate:r=!1}){const o=E.useRef(t);o.current=t;const s=E.useRef(e);s.current=e;const a=E.useRef(null),l=E.useRef(!1),i=E.useRef(null),c=p=>{const h=ko(_n(p));i.current!==h&&(i.current=h,l.current||o.current(h))},u=E.useRef(c);u.current=c;const d=E.useMemo(()=>r?[Q(p=>new Z({view:h=>{const g=()=>{if(h.isDestroyed||s.current===i.current)return;const w=p.get(hr)(Za(s.current));if(!(!w||w.eq(h.state.doc))){l.current=!0;try{h.dispatch(h.state.tr.replaceWith(0,h.state.doc.content.size,w.content).setMeta("addToHistory",!1))}finally{l.current=!1}}};return a.current=g,queueMicrotask(()=>{a.current===g&&g()}),{update:(w,y)=>{w.state.doc.eq(y.doc)||u.current(p.get(en)(w.state.doc))},destroy:()=>{a.current===g&&(a.current=null)}}}}))]:void 0,[r]);E.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(Vu,{children:b.jsx(Ka,{initial:Za(e),onChange:r?f:p=>t(ko(p)),extraPlugins:d,keys:m,saveImage:async()=>null,saveFiles:async()=>{},onOpenWiki:f,getPageNames:()=>[],focusPlace:null,onFocused:f,readOnly:n})})})}function P0(e){const t=n=>e("amadeus.default.tableColumn",{n});return`| ${t(1)} | ${t(2)} |
54
+ `).trim(),A=L==="codeblock"?K.schema.nodes.code_block?.create(null,He?K.schema.text(He):void 0):K.schema.nodes.paragraph?.create(null,K.schema.text(`$$ ${He} $$`));if(!A)return;const x=K.tr.replaceWith(Ce,Me,A);x.setSelection(j.near(x.doc.resolve(Ce+1))),_.dispatch(x.scrollIntoView()),_.focus(),S=!0}),S},Ga=L=>{const S=Pk[L];window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.turn.failed",{kind:S?O(S):L})}}))},ef=L=>{if(L==="codeblock"||L==="math"){Zd(L)||Ga(L);return}const S=Qd[L];if(S){let _=!1;ee()?.action(K=>{const V=K.get(le);_=Kt(V,S,null),V.focus()}),_||Ga(L);return}({bold:()=>It(zr.key),italic:()=>It(_r.key),underline:()=>It(ao.key),strike:()=>It(Tn.key),code:()=>It(Or.key),link:Va,clear:Xd,alignLeft:()=>eo("left"),alignCenter:()=>eo("center"),alignRight:()=>eo("right")})[L]?.()};return b.jsxs(b.Fragment,{children:[b.jsx(ek,{}),b.jsxs(Fi,{children:[pe&&!w&&b.jsx(li,{query:pe.query,left:pe.left,top:pe.top,anchorTop:pe.anchorTop,getPageNames:Ua,getFiles:l,onPick:qd,onClose:()=>{Zr.current=pe.from,dn.current=!1,Ae(null)},editorFocused:pn,sourcePath:C}),!pe&&k&&!w&&b.jsx(li,{query:k.query,left:k.left,top:k.top,anchorTop:k.anchorTop,getPageNames:Ua,getFiles:l,onPick:Ud,onPickRaw:Gd,agents:y&&Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1?Fe()?.agents?.():void 0,onPickAgent:y&&Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1?Vd:void 0,editorFocused:pn,dates:!0,allowCreate:!1,onClose:()=>{Xr.current=k.from,fn.current=!1,I(null)}}),R&&!pe&&!k&&!w&&b.jsx(mw,{query:R.query,left:R.left,top:R.top,anchorTop:R.anchorTop,onPick:Yd,editorFocused:pn,onClose:()=>{U.current=R.from,re(null)}}),G&&!pe&&!k&&!R&&!be&&!w&&b.jsx(bw,{query:G.query,left:G.left,top:G.top,anchorTop:G.anchorTop,onPick:Jd,editorFocused:pn,onClose:()=>{We.current=G.from,xe(null)}}),be&&g&&!pe&&!k&&!w&&b.jsx(W0,{query:be.query,left:be.left,top:be.top,anchorTop:be.anchorTop,hideKeys:y?K0:void 0,ctx:be.ctx,unified:y,editorFocused:pn,editorDom:Wd,onPick:L=>{je(null),ee()?.action(S=>{ni(S.get(le),be.from)}),g(L)},onClose:()=>{let L=!1;ee()?.action(S=>{const z=S.get(le);if(!ni(z,be.from))return;const{doc:_}=z.state;be.from<1||be.to>_.content.size||_.textBetween(be.from-1,be.from)!=="/"||(z.dispatch(z.state.tr.delete(be.from-1,be.to)),L=!0)}),L||(Qr.current=be.from),je(null)}}),yt&&!w&&b.jsx(q0,{left:yt.left,top:yt.top,anchorTop:yt.anchorTop,url:yt.url,onPick:Fd,onClose:()=>Jn(null)}),Re&&!pe&&!k&&!be&&!yt&&!w&&b.jsx(Bk,{left:Re.left,top:Re.top,bottom:Re.bottom,kind:Re.kind,active:Re.active,align:Re.align,shape:Re.shape,fg:Re.fg,bg:Re.bg,onAct:ef,onColor:L=>It(Tl.key,L||void 0),onBg:L=>It(Il.key,L||void 0),onClose:()=>{lt(null),ee()?.action(L=>{const S=L.get(le);S.dispatch(S.state.tr.setMeta(dr,!0))})},onReturnFocus:()=>ee()?.action(L=>L.get(le).focus()),onAsk:M?()=>{lt(null),ee()?.action(L=>M(L.get(le)))}:void 0,ai:T?{items:T.items,onPick:L=>{lt(null),ee()?.action(S=>T.onPick(L,S.get(le)))}}:void 0})]})]})}function _d({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:w=!1}){const y=Hi(),C=n.split("/").slice(0,-1).join("/"),N=E.useRef(t),[M,T]=E.useState(0),[D,H]=E.useState(!1),W=E.useRef(null);t!==N.current&&(N.current=t,T(k=>k+1));const $=k=>{const I=gf(k,C);N.current=I,r(I)},te=async k=>{if(!n)return null;try{const I=new Uint8Array(await k.arrayBuffer()),{opts:R}=await no(),{pageRel:re}=await Oe.saveAttachment(n,k.name||"pasted.png",I,R);return Ti(hf(C,re))}catch{return null}},Te=async k=>{if(!n)return;const I=[];for(const R of k)try{const re=new Uint8Array(await R.arrayBuffer()),{opts:U}=await no(),{base:G}=await Oe.saveAttachment(n,R.name||"file",re,U);I.push(`![[${G}]]`)}catch{}I.length&&(t.trim()===""?(r(I[0]),I.length>1&&y.getState().insertBlocksAfter(e,I.slice(1))):y.getState().insertBlocksAfter(e,I))},ze={insertAfter:o,deleteEmpty:s,mergePrev:a,arrow:l,moveDir:i,selfFocus:m},ge=(k,I)=>{const R=y.getState();if(R.activePage!==n||!R.blocks[e]){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.toast.staleTarget")}}));return}const re=(R.blocks[e].content??"").trim()==="";I&&re?r(k):o(k)},ie=async k=>{const I=k.scaffold;if(!W.current)return;const R=k.run?void 0:zd[I];if(R){W.current.transform(R)||Kd(k.label);return}const re=W.current.consume();if(k.run){try{const U=await k.run({pagePath:n,folder:er(n)});if(U!==""&&U!=null){if(typeof U!="string")throw new Error(O("mdblock.plugin.runNotString",{type:typeof U}));if(U.length>8192)throw new Error(O("mdblock.plugin.runTooLong"));if(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(U))throw new Error(O("mdblock.plugin.runControlChars"));ge(U,re),y.getState().syncFdChildren(n)}}catch(U){console.error("[plugin] slash item failed",U),window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.toast.slashFailed",{label:k.label,message:U instanceof Error?U.message:String(U)}),error:!0}}))}return}if(I===$a){window.dispatchEvent(new CustomEvent("amadeus:template-picker",{detail:{afterId:e,emptyBlock:re}}));return}if(I===Da){const U=document.createElement("input");U.type="file",U.accept="image/*",U.onchange=()=>{const G=U.files?.[0];G&&(async()=>{try{const xe=new Uint8Array(await G.arrayBuffer()),{opts:We}=await no(),{base:be}=await Oe.saveAttachment(n,G.name||"image.png",xe,We),je=`![[${be}]]`;ge(je,re)}catch{}})()},U.click();return}if(I===Ba){(async()=>{try{const U=y.getState(),G=await U.createChildNote(n,O("mdblock.default.childNote")),We=`[[${G.split("/").pop().replace(/\.md$/i,"")}]]`;ge(We,re),U.loadPage(G)}catch{}})();return}if(I===za){(async()=>{try{const U=O("mdblock.default.database"),G=new TextEncoder().encode(el(df(U))),{base:xe}=await Oe.saveAttachment(n,`${U}.db`,G,{mode:"vault",folder:er(n)}),We=`![[${xe}]]`;ge(We,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===Oa){(async()=>{try{const U=new TextEncoder().encode(ff(pf)),xe=`![[${(await Oe.saveAttachment(n,`${Nd(O("mdblock.default.drawing"))}.excalidraw.md`,U,{mode:"vault",folder:er(n)})).base.replace(/\.md$/i,"")}]]`;ge(xe,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===Pa){(async()=>{try{const U=er(n);let G=null;for(let Re=1;Re<=20&&G===null;Re++)try{const lt=O("mdblock.default.noteViewFolder");G=await Oe.createFolder(U,Re===1?lt:`${lt} ${Re}`)}catch{}if(G===null)return;const xe=O("mdblock.default.noteView"),We=new TextEncoder().encode(el(mf(xe,G))),{base:be}=await Oe.saveAttachment(n,`${xe}.db`,We,{mode:"vault",folder:U}),je=`![[${be}]]`;ge(je,re),y.getState().syncFdChildren(n)}catch{}})();return}if(I===_a){y.getState().splitToColumn(e,"right");return}if(I===La){H(!0);return}if(I===Ra){xo(O("mdblock.bookmark.title"),"",{label:O("mdblock.bookmark.label")}).then(U=>{const G=U?.trim();G&&/^https?:\/\/\S+$/i.test(G)&&(re?r(G):o(G))});return}if(I===Ia){if(!h)return;let U="";try{const G=await navigator.clipboard.readText(),xe=/!\[\[([^\]\n]+)\]\]/.exec(G);xe&&(U=xe[1].trim())}catch{}xo(O("mdblock.embed.title"),U,{label:O("mdblock.embed.label"),confirmLabel:O("mdblock.embed.confirm")}).then(G=>{const xe=G?.trim().replace(/^!?\[\[/,"").replace(/\]\]$/,"").trim();xe&&h(xe)});return}re?(r(I),setTimeout(()=>m("end"),0)):o(I)},pe=E.useRef(()=>{});pe.current=k=>{ie(k)};const Ae=E.useRef(k=>pe.current(k)).current;return E.useEffect(()=>()=>{An===Ae&&(An=null)},[Ae]),b.jsxs("div",{className:"md-block",onFocusCapture:()=>{w||(An=Ae)},children:[b.jsx(Vu,{children:b.jsx(Ka,{initial:uf(t,C),onChange:$,keys:ze,saveImage:te,saveFiles:Te,onOpenWiki:p,getPageNames:g,blockId:e,slashOpsRef:W,onSlashPick:ie,getFiles:()=>Pp()?y.getState().files:[],isWikiResolved:k=>!!yo(k,g(),n)||!!Op(k,y.getState().files,n),wikiIcon:k=>{const I=yo(k,g(),n);return I?y.getState().icons[I]:void 0},focusPlace:c,focusGoalX:u,focusAnchor:d,onFocused:f,attachmentPagePath:n,readOnly:w})},`${M}:${w?1:0}`),D&&!w&&b.jsx(Fi,{children:b.jsx(jd,{onClose:()=>H(!1),onPick:k=>{H(!1);const I=`![[${k}]]`;t.trim()===""?r(I):o(I)}})})]})}function O0({initial:e,onChange:t,readOnly:n=!1,immediate:r=!1}){const o=E.useRef(t);o.current=t;const s=E.useRef(e);s.current=e;const a=E.useRef(null),l=E.useRef(!1),i=E.useRef(null),c=p=>{const h=ko(_n(p));i.current!==h&&(i.current=h,l.current||o.current(h))},u=E.useRef(c);u.current=c;const d=E.useMemo(()=>r?[Q(p=>new Z({view:h=>{const g=()=>{if(h.isDestroyed||s.current===i.current)return;const w=p.get(hr)(Za(s.current));if(!(!w||w.eq(h.state.doc))){l.current=!0;try{h.dispatch(h.state.tr.replaceWith(0,h.state.doc.content.size,w.content).setMeta("addToHistory",!1))}finally{l.current=!1}}};return a.current=g,queueMicrotask(()=>{a.current===g&&g()}),{update:(w,y)=>{w.state.doc.eq(y.doc)||u.current(p.get(en)(w.state.doc))},destroy:()=>{a.current===g&&(a.current=null)}}}}))]:void 0,[r]);E.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(Vu,{children:b.jsx(Ka,{initial:Za(e),onChange:r?f:p=>t(ko(p)),extraPlugins:d,keys:m,saveImage:async()=>null,saveFiles:async()=>{},onOpenWiki:f,getPageNames:()=>[],focusPlace:null,onFocused:f,readOnly:n})})})}function P0(e){const t=n=>e("amadeus.default.tableColumn",{n});return`| ${t(1)} | ${t(2)} |
55
55
  | --- | --- |
56
56
  | | |`}const B0={embed:Ia,linkdb:La,bookmark:Ra,template:$a,image:Da,column:_a,database:za,drawing:Oa,noteview:Pa,page:Ba,card:Id,ai:Ld,instructions:Rd,agentTask:$d,prompt:Dd},zd={"":{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"}},Od=[{key:"ai",labelKey:"mdblock.slash.ai",hint:"AI",icon:b.jsx(ip,{width:"1em",height:"1em",strokeWidth:1.6}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Ld,kw:"ai 人工智能 写作 xiezuo 续写 xuxie 生成 tangu ask 问",unifiedOnly:!0,needsAi:!0},{key:"instructions",labelKey:"mdblock.slash.instructions",hint:"",icon:b.jsx(lm,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Rd,kw:"ai instructions instruction 指令 zhiling 页指令 维护规则",unifiedOnly:!0},{key:"agent-task",labelKey:"mdblock.slash.agentTask",hint:"",icon:b.jsx(ji,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:$d,kw:"ai agent task mention 任务 renwu 交办 提及",unifiedOnly:!0,needsDocumentTask:!0},{key:"prompt",labelKey:"mdblock.slash.prompt",hint:"",icon:b.jsx(cp,{size:"1em"}),groupKey:"mdblock.group.ai",category:"ai",scaffold:Dd,kw:"ai prompt 提示词 tishici 模板",unifiedOnly:!0,needsDocumentTask:!0},{key:"text",labelKey:"mdblock.slash.text",hint:"",icon:b.jsx(up,{}),groupKey:"mdblock.group.basic",scaffold:"",kw:"text 文本 paragraph zhengwen 正文"},{key:"h1",labelKey:"mdblock.slash.h1",hint:"#",icon:b.jsx(dp,{}),groupKey:"mdblock.group.basic",scaffold:"# ",kw:"h1 heading 标题 biaoti title 大标题"},{key:"h2",labelKey:"mdblock.slash.h2",hint:"##",icon:b.jsx(fp,{}),groupKey:"mdblock.group.basic",scaffold:"## ",kw:"h2 heading 标题 biaoti 中标题"},{key:"h3",labelKey:"mdblock.slash.h3",hint:"###",icon:b.jsx(pp,{}),groupKey:"mdblock.group.basic",scaffold:"### ",kw:"h3 heading 标题 biaoti 小标题"},{key:"h4",labelKey:"mdblock.slash.h4",hint:"####",icon:b.jsx(mp,{}),groupKey:"mdblock.group.basic",scaffold:"#### ",kw:"h4 heading 标题 biaoti 四级"},{key:"h5",labelKey:"mdblock.slash.h5",hint:"#####",icon:b.jsx(hp,{}),groupKey:"mdblock.group.basic",scaffold:"##### ",kw:"h5 heading 标题 biaoti 五级"},{key:"h6",labelKey:"mdblock.slash.h6",hint:"######",icon:b.jsx(gp,{}),groupKey:"mdblock.group.basic",scaffold:"###### ",kw:"h6 heading 标题 biaoti 六级"},{key:"ul",labelKey:"mdblock.slash.ul",hint:"-",icon:b.jsx(bp,{}),groupKey:"mdblock.group.list",scaffold:"- ",kw:"ul bullet list 无序 列表 liebiao"},{key:"ol",labelKey:"mdblock.slash.ol",hint:"1.",icon:b.jsx(yp,{}),groupKey:"mdblock.group.list",scaffold:"1. ",kw:"ol number list 有序 列表 编号"},{key:"todo",labelKey:"mdblock.slash.todo",hint:"[ ]",icon:b.jsx(kp,{}),groupKey:"mdblock.group.list",scaffold:"- [ ] ",kw:"todo task check 待办 任务 复选框 daiban renwu"},{key:"card",labelKey:"mdblock.slash.card",hint:"Canvas",icon:b.jsx(wp,{}),groupKey:"mdblock.group.basic",scaffold:Id,kw:"card 卡片 node 节点 canvas 画布",unifiedOnly:!0},{key:"quote",labelKey:"mdblock.slash.quote",hint:"|",icon:b.jsx(xp,{}),groupKey:"mdblock.group.advanced",scaffold:"| ",kw:"quote 引用 yinyong blockquote"},{key:"fold",labelKey:"mdblock.slash.fold",hint:">",icon:b.jsx(vp,{}),groupKey:"mdblock.group.advanced",scaffold:"> ",kw:"fold toggle 折叠 zhedie collapse 展开 详情 details"},{key:"code",labelKey:"mdblock.slash.code",hint:"```",icon:b.jsx(Cp,{}),groupKey:"mdblock.group.advanced",scaffold:"```\n\n```",kw:"code 代码 daima codeblock"},{key:"table",labelKey:"mdblock.slash.table",hint:"⊞",icon:b.jsx(Sp,{}),groupKey:"mdblock.group.advanced",scaffold:P0,kw:"table 表格 biaoge grid 网格"},{key:"divider",labelKey:"mdblock.slash.divider",hint:"---",icon:b.jsx(Mp,{}),groupKey:"mdblock.group.advanced",scaffold:`---
57
57
 
58
- `,kw:"divider hr 分割线 分隔 fenge"},{key:"math",labelKey:"mdblock.slash.math",hint:"$$",icon:b.jsx(Ap,{}),groupKey:"mdblock.group.advanced",scaffold:"$$ $$",kw:"math latex katex formula 数学 公式 gongshi"},{key:"wikilink",labelKey:"mdblock.slash.wikilink",hint:"[[",icon:b.jsx(Np,{}),groupKey:"mdblock.group.advanced",scaffold:"[[",kw:"link wiki note 链接 笔记 双链 lianjie shuanglian"},{key:"image",labelKey:"mdblock.slash.image",hint:"",icon:b.jsx(Ep,{}),groupKey:"mdblock.group.advanced",scaffold:Da,kw:"image picture photo 图片 tupian 插图"},{key:"columns",labelKey:"mdblock.slash.columns",hint:"⫿",icon:b.jsx(Tp,{}),groupKey:"mdblock.group.advanced",scaffold:_a,kw:"column split 分栏 分列 fenlan 并排"},{key:"page",labelKey:"mdblock.slash.page",hint:".fd",icon:b.jsx(Ip,{}),groupKey:"mdblock.group.advanced",scaffold:Ba,kw:"page 页面 子页面 subpage child yemian xinjian 新建页面 notion"},{key:"database",labelKey:"mdblock.slash.database",hint:".db",icon:b.jsx(gr,{}),groupKey:"mdblock.group.advanced",scaffold:za,kw:"database db 多维表 duoweibiao 数据库 shujuku 表格 base notion"},{key:"drawing",labelKey:"mdblock.slash.drawing",hint:"Excalidraw",icon:b.jsx(Lp,{}),groupKey:"mdblock.group.advanced",scaffold:Oa,kw:"drawing draw excalidraw 画板 huaban 手绘 白板 whiteboard 草图 sketch 流程图"},{key:"linkdb",labelKey:"mdblock.slash.linkdb",hint:"![[.db]]",icon:b.jsx(gr,{}),groupKey:"mdblock.group.advanced",scaffold:La,kw:"link database db 链接多维表 链接数据库 引用数据库 嵌入数据库 已有 lianjie duoweibiao shujuku"},{key:"noteview",labelKey:"mdblock.slash.noteview",hint:"Bases",icon:b.jsx(Rp,{}),groupKey:"mdblock.group.advanced",scaffold:Pa,kw:"noteview bases 笔记视图 bijishitu 行即笔记 folder page 多维表 notion"},{key:"template",labelKey:"mdblock.slash.template",hint:"templates/",icon:b.jsx($p,{}),groupKey:"mdblock.group.advanced",scaffold:$a,kw:"template 模板 muban 套用"},{key:"embed",labelKey:"mdblock.slash.embed",hint:"![[ ]]",icon:b.jsx(Dp,{}),groupKey:"mdblock.group.advanced",scaffold:Ia,kw:"embed 嵌入 引用 transclude block 块 qianru yinyong 复用"},{key:"bookmark",labelKey:"mdblock.slash.bookmark",hint:"https://",icon:b.jsx(_p,{}),groupKey:"mdblock.group.advanced",scaffold:Ra,kw:"bookmark link url 书签 链接 网页 网址 shuqian youtube 视频"},{key:"button",labelKey:"mdblock.slash.button",hint:"",icon:b.jsx(zp,{}),groupKey:"mdblock.group.advanced",scaffold:sp,kw:"button 按钮 anniu 自动化 automation 一键 yijian 快捷 notion"}],K0=new Set;function mr(e){return typeof e=="function"?e():e}function Pd({unified:e=!1}={}){const{t}=rn(),n=op(a=>a.slashItems),r=[...Od.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:mr(a.label),hint:a.hint??"",icon:ap(a.icon,"·"),group:mr(a.group)??t("mdblock.group.plugin"),scaffold:a.scaffold??"",run:a.run,kw:`${a.keywords??""} ${mr(a.label)}`}))],o=!!Fe()?.complete,s=!!Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1;return r.filter(a=>(e||!a.unifiedOnly)&&(o||!a.needsAi)&&(s||!a.needsDocumentTask))}let An=null;function j0(){return An}function H0(e){An=e}function F0(e,t){let n=null;for(const r of[t.label,...t.kw.split(/\s+/)]){const o=ft(e,r);o!==null&&(n=n===null?o:Math.max(n,o))}return n}function Bd(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 Kd(e){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.turn.failed",{kind:e})}}))}function Rr(e){try{return new URL(e).hostname.replace(/^www\./,"")||e}catch{return e}}function q0({left:e,top:t,anchorTop:n,url:r,onPick:o,onClose:s}){const{t:a}=rn(),l=[{k:"link",label:a("mdblock.pasteAs.link"),hint:Rr(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]=E.useState(-1),u=E.useRef(-1);return u.current=i,E.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(on,{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 W0({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}=rn(),[f,m]=E.useState(0),[p,h]=E.useState(null),g=`amx-slash-${E.useId().replace(/[^\w-]/g,"")}`,w=E.useRef(i);w.current=i;const y=Pd({unified:a}),C=E.useMemo(()=>y.filter(k=>!o?.has(k.key)&&(!s||Nk(k.key,s))),[y,o,s]),N=e.trim().toLowerCase(),M=N?C.map(k=>({it:k,s:F0(N,k)})).filter(k=>k.s!==null).sort((k,I)=>I.s-k.s).map(k=>k.it):C,T=p?.query===N?p.category:Kk(M,N),D=M.filter(k=>ed(k)===T),H=Array.from(new Set(D.map(k=>k.group))),W=N?D:H.flatMap(k=>D.filter(I=>I.group===k)),$=k=>{h({query:N,category:k}),m(0)};E.useEffect(()=>{m(0),h(null)},[e]);const te=E.useRef(null),[Te,ze]=E.useState(null),ge=Te?.query===N?Te.height:void 0;E.useLayoutEffect(()=>{const k=te.current?.offsetHeight??0;k>(ge??0)&&ze({query:N,height:k})});const ie=W.length?Math.min(f,W.length-1):-1;E.useEffect(()=>{const k=w.current?.();if(k)return k.setAttribute("aria-controls",`${g}-commands`),ie>=0?k.setAttribute("aria-activedescendant",`${g}-${ie}`):k.removeAttribute("aria-activedescendant"),()=>{k.removeAttribute("aria-activedescendant"),k.removeAttribute("aria-controls")}},[g,ie]),E.useEffect(()=>{const k=R=>{R.preventDefault(),R.stopPropagation()},I=R=>{if(R.isComposing||R.key==="Process"||R.keyCode===229||l&&!l())return;const re=!R.metaKey&&!R.ctrlKey&&!R.altKey&&!R.shiftKey;if(R.key==="Escape")k(R),u();else if(re&&R.key.startsWith("Arrow")){const U=jk(T,R.key);if(U!==null)k(R),$(U);else{const G=Hk(W.length,ie,R.key);G!==null&&(k(R),m(G))}}else if(R.key==="Enter"||R.key==="Tab"){const U=W[ie];U?(k(R),c(U)):u()}};return window.addEventListener("keydown",I,!0),()=>window.removeEventListener("keydown",I,!0)},[W,f,T,N,c,u,l]);const pe=(k,I)=>b.jsxs("button",{id:`${g}-${I}`,className:"slash-item","data-key":k.key,"aria-label":k.label,"data-active":I===ie||void 0,ref:I===ie?R=>R?.scrollIntoView({block:"nearest"}):void 0,onMouseEnter:()=>m(I),onMouseDown:R=>{R.preventDefault(),c(k)},role:"menuitem",children:[b.jsx("span",{className:"slash-icon","aria-hidden":!0,children:k.icon}),b.jsx("span",{className:"slash-label",children:k.label}),b.jsx("span",{className:"slash-hint",children:k.hint})]},k.key),Ae=[];return W.forEach((k,I)=>{let R=Ae.find(re=>re.name===k.group);R||(R={name:k.group,rows:[]},Ae.push(R)),R.rows.push({it:k,idx:I})}),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:u}),b.jsxs(on,{id:g,className:"slash-menu",x:t,y:n,anchorTop:r,style:{minHeight:ge},innerRef:k=>{te.current=k},onMouseDown:k=>k.preventDefault(),children:[b.jsx("div",{className:"slash-category-tabs",role:"tablist","aria-label":d("mdblock.category.label"),children:vn.map(k=>b.jsx("button",{type:"button",id:`${g}-tab-${k}`,className:"slash-category-tab",role:"tab","data-category":k,"aria-selected":T===k,"aria-controls":`${g}-panel`,tabIndex:-1,onMouseDown:I=>I.preventDefault(),onClick:()=>$(k),children:d(`mdblock.category.${k}`)},k))}),b.jsxs("div",{className:"slash-list",id:`${g}-panel`,role:"tabpanel","data-category":T,"aria-labelledby":`${g}-tab-${T}`,children:[W.length===0&&b.jsx("div",{className:"slash-empty",children:d(N?"mdblock.menu.noMatch":"mdblock.category.empty")}),b.jsx("div",{className:"slash-scroll",id:`${g}-commands`,role:"menu","aria-labelledby":`${g}-tab-${T}`,children:N||Ae.length<=1?W.map(pe):Ae.map(k=>b.jsxs("div",{className:"slash-group",children:[b.jsx("div",{className:"slash-group-label",children:k.name}),k.rows.map(({it:I,idx:R})=>pe(I,R))]},k.name))})]}),b.jsxs("div",{className:"slash-foot",children:[b.jsx("span",{children:d("mdblock.foot.category")}),W.length>0&&b.jsx("span",{children:d("mdblock.foot.select")}),W.length>0&&b.jsx("span",{children:d("mdblock.foot.insert")}),b.jsx("span",{children:d("mdblock.foot.close")})]})]})]})}function jd({onPick:e,onClose:t}){const{t:n}=rn(),[r,o]=E.useState(""),[s,a]=E.useState(0),l=En(p=>p.files);E.useEffect(()=>{En.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=ft(d,c(p));return{f:p,s:h!==null?h+1e3:ft(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 E.useEffect(()=>{a(0)},[r]),E.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(w=>Math.min(w+1,f.length-1));else if(g.key==="ArrowUp")p(g),a(w=>Math.max(w-1,0));else if(g.key==="Enter"){p(g);const w=f[s];w?e(m(w)):t()}else g.key==="Backspace"?(p(g),o(w=>w.slice(0,-1))):g.key.length===1&&!g.metaKey&&!g.ctrlKey&&!g.altKey&&(p(g),o(w=>w+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(gr,{})}),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")})]})]})]})}qp({id:"markdown",fileExtensions:[".md"],Editor:_d});const A1=Object.freeze(Object.defineProperty({__proto__:null,DbLinkPicker:jd,MarkdownBlock:_d,MilkdownInner:Ka,PREFIX_TRIGGERS:zd,PlainMarkdownEditor:O0,SLASH_ITEMS:Od,SLASH_SENTINELS:B0,getFocusedBlockApply:j0,hostLabel:Rr,linkExtent:Bd,normalizeFragmentMd:Td,normalizeSerializedMd:_n,serializeUnified:Ed,setFocusedBlockApply:H0,slashTurnFailed:Kd,stampedFileName:Nd,textOf:mr,useAllSlashItems:Pd},Symbol.toStringTag,{value:"Module"}));export{Ka as $,Gl as A,g1 as B,Ku as C,ju as D,Ct as E,Qt as F,yi as G,C1 as H,f1 as I,dm as J,p1 as K,m1 as L,i1 as M,s1 as N,Vu as O,O0 as P,ki as Q,k1 as R,w1 as S,cm as T,nk as U,Ed as V,_n as W,a1 as X,ur as Y,td as Z,Cw as _,o1 as a,jd as a0,zd as a1,Kd as a2,B0 as a3,S1 as a4,jw as a5,Nd as a6,H0 as a7,j0 as a8,v1 as a9,y1 as aa,xw as ab,vw as ac,Pd as ad,A1 as ae,r1 as b,Kt as c,Go as d,ad as e,u1 as f,c1 as g,Or as h,l1 as i,Jo as j,bm as k,Xi as l,hk as m,fk as n,ik as o,Kw as p,pk as q,my as r,t1 as s,d1 as t,n1 as u,hy as v,x1 as w,M1 as x,h1 as y,b1 as z};
58
+ `,kw:"divider hr 分割线 分隔 fenge"},{key:"math",labelKey:"mdblock.slash.math",hint:"$$",icon:b.jsx(Ap,{}),groupKey:"mdblock.group.advanced",scaffold:"$$ $$",kw:"math latex katex formula 数学 公式 gongshi"},{key:"wikilink",labelKey:"mdblock.slash.wikilink",hint:"[[",icon:b.jsx(Np,{}),groupKey:"mdblock.group.advanced",scaffold:"[[",kw:"link wiki note 链接 笔记 双链 lianjie shuanglian"},{key:"image",labelKey:"mdblock.slash.image",hint:"",icon:b.jsx(Ep,{}),groupKey:"mdblock.group.advanced",scaffold:Da,kw:"image picture photo 图片 tupian 插图"},{key:"columns",labelKey:"mdblock.slash.columns",hint:"⫿",icon:b.jsx(Tp,{}),groupKey:"mdblock.group.advanced",scaffold:_a,kw:"column split 分栏 分列 fenlan 并排"},{key:"page",labelKey:"mdblock.slash.page",hint:".fd",icon:b.jsx(Ip,{}),groupKey:"mdblock.group.advanced",scaffold:Ba,kw:"page 页面 子页面 subpage child yemian xinjian 新建页面 notion"},{key:"database",labelKey:"mdblock.slash.database",hint:".db",icon:b.jsx(gr,{}),groupKey:"mdblock.group.advanced",scaffold:za,kw:"database db 多维表 duoweibiao 数据库 shujuku 表格 base notion"},{key:"drawing",labelKey:"mdblock.slash.drawing",hint:"Excalidraw",icon:b.jsx(Lp,{}),groupKey:"mdblock.group.advanced",scaffold:Oa,kw:"drawing draw excalidraw 画板 huaban 手绘 白板 whiteboard 草图 sketch 流程图"},{key:"linkdb",labelKey:"mdblock.slash.linkdb",hint:"![[.db]]",icon:b.jsx(gr,{}),groupKey:"mdblock.group.advanced",scaffold:La,kw:"link database db 链接多维表 链接数据库 引用数据库 嵌入数据库 已有 lianjie duoweibiao shujuku"},{key:"noteview",labelKey:"mdblock.slash.noteview",hint:"Bases",icon:b.jsx(Rp,{}),groupKey:"mdblock.group.advanced",scaffold:Pa,kw:"noteview bases 笔记视图 bijishitu 行即笔记 folder page 多维表 notion"},{key:"template",labelKey:"mdblock.slash.template",hint:"templates/",icon:b.jsx($p,{}),groupKey:"mdblock.group.advanced",scaffold:$a,kw:"template 模板 muban 套用"},{key:"embed",labelKey:"mdblock.slash.embed",hint:"![[ ]]",icon:b.jsx(Dp,{}),groupKey:"mdblock.group.advanced",scaffold:Ia,kw:"embed 嵌入 引用 transclude block 块 qianru yinyong 复用"},{key:"bookmark",labelKey:"mdblock.slash.bookmark",hint:"https://",icon:b.jsx(_p,{}),groupKey:"mdblock.group.advanced",scaffold:Ra,kw:"bookmark link url 书签 链接 网页 网址 shuqian youtube 视频"},{key:"button",labelKey:"mdblock.slash.button",hint:"",icon:b.jsx(zp,{}),groupKey:"mdblock.group.advanced",scaffold:sp,kw:"button 按钮 anniu 自动化 automation 一键 yijian 快捷 notion"}],K0=new Set;function mr(e){return typeof e=="function"?e():e}function Pd({unified:e=!1}={}){const{t}=rn(),n=op(a=>a.slashItems),r=[...Od.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:mr(a.label),hint:a.hint??"",icon:ap(a.icon,"·"),group:mr(a.group)??t("mdblock.group.plugin"),scaffold:a.scaffold??"",run:a.run,kw:`${a.keywords??""} ${mr(a.label)}`}))],o=!!Fe()?.complete,s=!!Fe()?.submitDocumentTask&&Fe()?.hostExecution?.()!==!1;return r.filter(a=>(e||!a.unifiedOnly)&&(o||!a.needsAi)&&(s||!a.needsDocumentTask))}let An=null;function j0(){return An}function H0(e){An=e}function F0(e,t){let n=null;for(const r of[t.label,...t.kw.split(/\s+/)]){const o=ft(e,r);o!==null&&(n=n===null?o:Math.max(n,o))}return n}function Bd(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 Kd(e){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:O("mdblock.turn.failed",{kind:e})}}))}function Rr(e){try{return new URL(e).hostname.replace(/^www\./,"")||e}catch{return e}}function q0({left:e,top:t,anchorTop:n,url:r,onPick:o,onClose:s}){const{t:a}=rn(),l=[{k:"link",label:a("mdblock.pasteAs.link"),hint:Rr(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]=E.useState(-1),u=E.useRef(-1);return u.current=i,E.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(on,{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 W0({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}=rn(),[f,m]=E.useState(0),[p,h]=E.useState(null),g=`amx-slash-${E.useId().replace(/[^\w-]/g,"")}`,w=E.useRef(i);w.current=i;const y=Pd({unified:a}),C=E.useMemo(()=>y.filter(k=>!o?.has(k.key)&&(!s||Nk(k.key,s))),[y,o,s]),N=e.trim().toLowerCase(),M=N?C.map(k=>({it:k,s:F0(N,k)})).filter(k=>k.s!==null).sort((k,I)=>I.s-k.s).map(k=>k.it):C,T=p?.query===N?p.category:Kk(M,N),D=M.filter(k=>ed(k)===T),H=Array.from(new Set(D.map(k=>k.group))),W=N?D:H.flatMap(k=>D.filter(I=>I.group===k)),$=k=>{h({query:N,category:k}),m(0)};E.useEffect(()=>{m(0),h(null)},[e]);const te=E.useRef(null),[Te,ze]=E.useState(null),ge=Te?.query===N?Te.height:void 0;E.useLayoutEffect(()=>{const k=te.current?.offsetHeight??0;k>(ge??0)&&ze({query:N,height:k})});const ie=W.length?Math.min(f,W.length-1):-1;E.useEffect(()=>{const k=w.current?.();if(k)return k.setAttribute("aria-controls",`${g}-commands`),ie>=0?k.setAttribute("aria-activedescendant",`${g}-${ie}`):k.removeAttribute("aria-activedescendant"),()=>{k.removeAttribute("aria-activedescendant"),k.removeAttribute("aria-controls")}},[g,ie]),E.useEffect(()=>{const k=R=>{R.preventDefault(),R.stopPropagation()},I=R=>{if(R.isComposing||R.key==="Process"||R.keyCode===229||l&&!l())return;const re=!R.metaKey&&!R.ctrlKey&&!R.altKey&&!R.shiftKey;if(R.key==="Escape")k(R),u();else if(re&&R.key.startsWith("Arrow")){const U=jk(T,R.key);if(U!==null)k(R),$(U);else{const G=Hk(W.length,ie,R.key);G!==null&&(k(R),m(G))}}else if(R.key==="Enter"||R.key==="Tab"){const U=W[ie];U?(k(R),c(U)):u()}};return window.addEventListener("keydown",I,!0),()=>window.removeEventListener("keydown",I,!0)},[W,f,T,N,c,u,l]);const pe=(k,I)=>b.jsxs("button",{id:`${g}-${I}`,className:"slash-item","data-key":k.key,"aria-label":k.label,"data-active":I===ie||void 0,ref:I===ie?R=>R?.scrollIntoView({block:"nearest"}):void 0,onMouseEnter:()=>m(I),onMouseDown:R=>{R.preventDefault(),c(k)},role:"menuitem",children:[b.jsx("span",{className:"slash-icon","aria-hidden":!0,children:k.icon}),b.jsx("span",{className:"slash-label",children:k.label}),b.jsx("span",{className:"slash-hint",children:k.hint})]},k.key),Ae=[];return W.forEach((k,I)=>{let R=Ae.find(re=>re.name===k.group);R||(R={name:k.group,rows:[]},Ae.push(R)),R.rows.push({it:k,idx:I})}),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:u}),b.jsxs(on,{id:g,className:"slash-menu",x:t,y:n,anchorTop:r,style:{minHeight:ge},innerRef:k=>{te.current=k},onMouseDown:k=>k.preventDefault(),children:[b.jsx("div",{className:"slash-category-tabs",role:"tablist","aria-label":d("mdblock.category.label"),children:vn.map(k=>b.jsx("button",{type:"button",id:`${g}-tab-${k}`,className:"slash-category-tab",role:"tab","data-category":k,"aria-selected":T===k,"aria-controls":`${g}-panel`,tabIndex:-1,onMouseDown:I=>I.preventDefault(),onClick:()=>$(k),children:d(`mdblock.category.${k}`)},k))}),b.jsxs("div",{className:"slash-list",id:`${g}-panel`,role:"tabpanel","data-category":T,"aria-labelledby":`${g}-tab-${T}`,children:[W.length===0&&b.jsx("div",{className:"slash-empty",children:d(N?"mdblock.menu.noMatch":"mdblock.category.empty")}),b.jsx("div",{className:"slash-scroll",id:`${g}-commands`,role:"menu","aria-labelledby":`${g}-tab-${T}`,children:N||Ae.length<=1?W.map(pe):Ae.map(k=>b.jsxs("div",{className:"slash-group",children:[b.jsx("div",{className:"slash-group-label",children:k.name}),k.rows.map(({it:I,idx:R})=>pe(I,R))]},k.name))})]}),b.jsxs("div",{className:"slash-foot",children:[b.jsx("span",{children:d("mdblock.foot.category")}),W.length>0&&b.jsx("span",{children:d("mdblock.foot.select")}),W.length>0&&b.jsx("span",{children:d("mdblock.foot.insert")}),b.jsx("span",{children:d("mdblock.foot.close")})]})]})]})}function jd({onPick:e,onClose:t}){const{t:n}=rn(),[r,o]=E.useState(""),[s,a]=E.useState(0),l=En(p=>p.files);E.useEffect(()=>{En.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=ft(d,c(p));return{f:p,s:h!==null?h+1e3:ft(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 E.useEffect(()=>{a(0)},[r]),E.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(w=>Math.min(w+1,f.length-1));else if(g.key==="ArrowUp")p(g),a(w=>Math.max(w-1,0));else if(g.key==="Enter"){p(g);const w=f[s];w?e(m(w)):t()}else g.key==="Backspace"?(p(g),o(w=>w.slice(0,-1))):g.key.length===1&&!g.metaKey&&!g.ctrlKey&&!g.altKey&&(p(g),o(w=>w+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(gr,{})}),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")})]})]})]})}qp({id:"markdown",fileExtensions:[".md"],Editor:_d});const A1=Object.freeze(Object.defineProperty({__proto__:null,DbLinkPicker:jd,MarkdownBlock:_d,MilkdownInner:Ka,PREFIX_TRIGGERS:zd,PlainMarkdownEditor:O0,SLASH_ITEMS:Od,SLASH_SENTINELS:B0,getFocusedBlockApply:j0,hostLabel:Rr,linkExtent:Bd,normalizeFragmentMd:Td,normalizeSerializedMd:_n,serializeUnified:Ed,setFocusedBlockApply:H0,slashTurnFailed:Kd,stampedFileName:Nd,textOf:mr,useAllSlashItems:Pd},Symbol.toStringTag,{value:"Module"}));export{Ka as $,Gl as A,g1 as B,Ku as C,ju as D,Ct as E,Qt as F,yi as G,C1 as H,f1 as I,dm as J,p1 as K,m1 as L,i1 as M,s1 as N,Vu as O,O0 as P,ki as Q,k1 as R,w1 as S,cm as T,nk as U,Ed as V,_n as W,a1 as X,ur as Y,td as Z,Cw as _,o1 as a,jd as a0,zd as a1,Kd as a2,B0 as a3,S1 as a4,jw as a5,Nd as a6,H0 as a7,j0 as a8,v1 as a9,y1 as aa,xw as ab,vw as ac,Pd as ad,A1 as ae,r1 as b,Kt as c,Go as d,ad as e,u1 as f,c1 as g,Or as h,l1 as i,Yo as j,bm as k,Xi as l,hk as m,fk as n,ik as o,Kw as p,pk as q,my as r,t1 as s,d1 as t,n1 as u,hy as v,x1 as w,M1 as x,h1 as y,b1 as z};