@forsion/unit 2.12.2 → 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.
- package/README.md +61 -0
- package/backendWorker.mjs +6 -2
- package/main.mjs +991 -497
- package/package.json +1 -1
- package/release.json +5 -5
- package/web/assets/ArtificialView-XwHMLUFb.js +1 -0
- package/web/assets/{AutomationBuilder-sxWdUa0L.js → AutomationBuilder-hqs0QhMt.js} +1 -1
- package/web/assets/CalendarConfigView-DKib8Oed.js +1 -0
- package/web/assets/CalendarView-DJ5iOzvu.js +1 -0
- package/web/assets/CapabilityMenu-SwVlZ06x.js +1 -0
- package/web/assets/{CheckboxInput-BsaoUHZ0.js → CheckboxInput-BC-5a_C9.js} +1 -1
- package/web/assets/Chrome-HdfyYV3i.js +1 -0
- package/web/assets/{CodeView-j065KtVh.js → CodeView-CFL6yQ-6.js} +3 -3
- package/web/assets/DashboardGridView-B9DCWYVb.js +17 -0
- package/web/assets/{EventCard-BmDQkEj9.js → EventCard-B_ndpqH_.js} +1 -1
- package/web/assets/ExcalidrawCanvas-BQ4KKLJP.js +1 -0
- package/web/assets/{FloatingToc-CENybkAA.js → FloatingToc-Ce9GamvH.js} +1 -1
- package/web/assets/HomepageView-RCOfcVbE.js +1 -0
- package/web/assets/ImageStudioPanels-lkS_y2uM.js +3 -0
- package/web/assets/ImageStudioView-UPv52acl.js +1 -0
- package/web/assets/InlineFiles-CQbQumkf.js +1 -0
- package/web/assets/MarkdownBlock--__nPQGh.css +1 -0
- package/web/assets/MarkdownBlock-CkqiwPXa.js +58 -0
- package/web/assets/ModelPill-CY-rU1RU.js +2 -0
- package/web/assets/MuseLibraryView-CtTHlVnT.js +2 -0
- package/web/assets/{MuseView-d-iBk3sc.js → MuseView-CC2A7MBs.js} +2 -2
- package/web/assets/{PageHistoryPanel-CR-k1AM7.js → PageHistoryPanel-KhKT1DLy.js} +2 -2
- package/web/assets/PdfAnnotator-C_kglLCA.css +1 -0
- package/web/assets/PdfAnnotator-DUyrgY-t.js +505 -0
- package/web/assets/{ProductView-u2aezVsl.js → ProductView-CgsIYZqD.js} +1 -1
- package/web/assets/RightPanel-BHDgqTFs.js +4 -0
- package/web/assets/RunLocationPicker-BE5mxnab.css +1 -0
- package/web/assets/RunLocationPicker-DBnXYV5B.js +38 -0
- package/web/assets/{SidebarRow-BuSkKH5q.js → SidebarRow-BAJxbMcx.js} +1 -1
- package/web/assets/{SketchCard-D87GADyG.js → SketchCard-BGYz-bXP.js} +5 -5
- package/web/assets/{StudioGuestSurface-BijU_EEb.js → StudioGuestSurface-lt6znmkl.js} +1 -1
- package/web/assets/{TodoListView-DPPVpPUn.js → TodoListView-DPKhee6i.js} +1 -1
- package/web/assets/{Tooltip-DY4ISA-e.js → Tooltip-ZxrDqN4p.js} +1 -1
- package/web/assets/UnifiedPage-BX6ZQL0h.js +68 -0
- package/web/assets/UnifiedPage-CWXc_mo1.css +1 -0
- package/web/assets/{amadeus-manual.en-DWaN2fPs.js → amadeus-manual.en-DzRWr4BL.js} +18 -18
- package/web/assets/{amadeus-manual.zh--7D5TS8X.js → amadeus-manual.zh-DW32DkL7.js} +18 -18
- package/web/assets/{appStore-Dg9WALEA.js → appStore-DWP8UET9.js} +208 -122
- package/web/assets/appStore-wtOILggO.css +1 -0
- package/web/assets/{arrow-up-right-CpQs92mu.js → arrow-up-right-DrCXuWS7.js} +1 -1
- package/web/assets/{astryxBridge-BZhaZPs4.js → astryxBridge-D-m4_kYt.js} +3 -3
- package/web/assets/automationListSource-C8BNy6RY.js +1 -0
- package/web/assets/book-open-OLNm7OaB.js +1 -0
- package/web/assets/{calendarNavStore-C7fGRpoH.js → calendarNavStore-Cylfvv3s.js} +1 -1
- package/web/assets/{canvasPrefs-BeG4oEgP.js → canvasPrefs-8taQ42Cz.js} +1 -1
- package/web/assets/chatBoxSurface-CIlzs45H.js +1 -0
- package/web/assets/{circle-question-mark-WL3vbp-Z.js → circle-question-mark-XbAFplz1.js} +1 -1
- package/web/assets/{circle-x-D7s-M5sB.js → circle-x-fcReAZaE.js} +1 -1
- package/web/assets/{client-BSKpsyAw.js → client-0MPbodA6.js} +1 -1
- package/web/assets/{code-xml-BALV9u_c.js → code-xml-Cuna8Kh4.js} +1 -1
- package/web/assets/{codeStudioStore-C2mWfm32.js → codeStudioStore-BBU62GTy.js} +1 -1
- package/web/assets/codingNavigation-CZB4v1ZW.css +1 -0
- package/web/assets/codingNavigation-DDlPpPk5.js +47 -0
- package/web/assets/{create-4xUyKtAF.js → create-BGtEfCcg.js} +4 -4
- package/web/assets/dashboardSurface-BYM3C7WG.js +1 -0
- package/web/assets/{deskCapture-Df701U8L.js → deskCapture-BiUCmqfc.js} +1 -1
- package/web/assets/{diff2html-BV-zCH4d.js → diff2html-BNp2FTbk.js} +1 -1
- package/web/assets/{docx-preview-DW4IyU_Q.js → docx-preview-CFznGVOU.js} +1 -1
- package/web/assets/{emoji-DGaxpCIu.js → emoji-6zl4yfOS.js} +1 -1
- package/web/assets/floatingTocSurface-DreXPCa6.js +1 -0
- package/web/assets/{foldActions-B7KByFdN.js → foldActions-05QcQziQ.js} +1 -1
- package/web/assets/folder-BpsfOHD4.js +1 -0
- package/web/assets/{folder-plus-D1TDb7k9.js → folder-plus-BeQHr4AZ.js} +1 -1
- package/web/assets/gestures-DQBCcK4y.js +1 -0
- package/web/assets/{hand-Crrw-nSn.js → hand-Bko7ms15.js} +1 -1
- package/web/assets/{hard-drive-BbyVSbfP.js → hard-drive-BpuI5ebj.js} +1 -1
- package/web/assets/i18n-ecQQxiMQ.css +1 -0
- package/web/assets/i18n.generated-BuLjnmY8.js +15 -0
- package/web/assets/imageStudio--KF9gwHA.css +1 -0
- package/web/assets/imageStudio-BLVNKmEG.js +2 -0
- package/web/assets/{index-DKhyDkGB.js → index-BF10xp_K.js} +1 -1
- package/web/assets/{index-C7U6T-k8.js → index-BHm6K743.js} +1 -1
- package/web/assets/{index-CF4RV4mh.js → index-BM2o7PeV.js} +90 -90
- package/web/assets/{index-Brik2pf9.js → index-BgnNNv3e.js} +1 -1
- package/web/assets/{index--drOLtq7.js → index-C0Gy2NQ6.js} +1 -1
- package/web/assets/{index-CflzrdSt.js → index-C1doZp5H.js} +1 -1
- package/web/assets/{index-SZ5waGAq.js → index-C4L6vjd_.js} +1 -1
- package/web/assets/{index-Cmr7gVZQ.js → index-CD3yIkOA.js} +1 -1
- package/web/assets/{index-BYsdKR_1.js → index-CJeUgjPU.js} +1 -1
- package/web/assets/{index-CzM-C2Sd.js → index-CLHoq1w-.js} +1 -1
- package/web/assets/{index-tAXBa_fN.js → index-CUZI62qU.js} +1 -1
- package/web/assets/{index-C6GJulug.js → index-Cff42k7q.js} +1 -1
- package/web/assets/index-Ck_O3Jdd.js +1 -0
- package/web/assets/index-CuiYK18N.js +1 -0
- package/web/assets/{index-BRW82CsP.js → index-CwcOeZdT.js} +1 -1
- package/web/assets/{index-DUWR2nZi.js → index-D6AycQIz.js} +1 -1
- package/web/assets/{index-BCZZVJ_w.js → index-D7gVhvNY.js} +1 -1
- package/web/assets/{index-DjzSBM0U.js → index-D9UZQy42.js} +1 -1
- package/web/assets/{index-KL5Rj9kP.js → index-DuBQ0j2g.js} +1 -1
- package/web/assets/{index-Dg9oixs4.js → index-OD1gSX3h.js} +1 -1
- package/web/assets/{index-gPSbFSUn.js → index-Uo5tswys.js} +1 -1
- package/web/assets/{index-D1f_JwPH.js → index-o8cj0pRH.js} +1 -1
- package/web/assets/{index-OHi69jDq.js → index-rHjhbwvm.js} +1 -1
- package/web/assets/{index-CqyM6tQ0.js → index-rggq2czF.js} +1 -1
- package/web/assets/{index-Czu_bbDM.js → index-sCXThwqZ.js} +1 -1
- package/web/assets/{invitePage-lLQ-e0pj.js → invitePage-b0HGvMj6.js} +1 -1
- package/web/assets/{ipc-DQOD2UKk.js → ipc-CxAyeo8q.js} +1 -1
- package/web/assets/{jszip.min-DZxV9uZ_.js → jszip.min-B94KpE21.js} +1 -1
- package/web/assets/launchpad-C2c1MSVX.css +1 -0
- package/web/assets/{layout-grid-B_pjJwz4.js → layout-grid-BBVuEdWG.js} +1 -1
- package/web/assets/{linkFollow-C0_3k_PC.js → linkFollow-B7ivDZMM.js} +4 -4
- package/web/assets/{list-tree-DkAJYEXd.js → list-tree-4-0QDbLu.js} +1 -1
- package/web/assets/{listFold-BsOVn9UZ.js → listFold-DLuxXiIj.js} +1 -1
- package/web/assets/{lock-BnGHxjeE.js → lock-CnbZm4vo.js} +1 -1
- package/web/assets/{log-out-DBuMeqik.js → log-out-BEynWaHa.js} +1 -1
- package/web/assets/{main-NgUPPqDn.css → main-BiS_5wrB.css} +1 -1
- package/web/assets/main-sIq2N9Z5.js +20 -0
- package/web/assets/markdownEditorSurface-ZSJ3RHAv.js +3 -0
- package/web/assets/mdMarkStore-DQHDjG7s.js +2 -0
- package/web/assets/{mdMarks-Bq7Hl-4C.js → mdMarks-DbIcRa0O.js} +1 -1
- package/web/assets/{message-square-plus-BiAZAvcw.js → message-square-plus-CpiKDvle.js} +1 -1
- package/web/assets/{messages-BH5MfQdZ.js → messages-_jta1lSI.js} +1 -1
- package/web/assets/minus-C9ndHJ9O.js +1 -0
- package/web/assets/mobileEntry-CPmU_c4m.js +13 -0
- package/web/assets/nativeDownload-BYT082bY.js +1 -0
- package/web/assets/{pageChrome-xLNdFaSg.css → pageChrome-CovzZPdb.css} +1 -1
- package/web/assets/pageChrome-D3Niv1JM.js +1 -0
- package/web/assets/{pageTree-CZH2J6cc.js → pageTree-CgfvpzIj.js} +2 -2
- package/web/assets/{pen-tool-lkmBqliH.js → pen-tool-BXEFnU2i.js} +1 -1
- package/web/assets/{pencil-Cvk91P_Z.js → pencil-cqvCkekG.js} +1 -1
- package/web/assets/pluginChat-BbBukMuN.js +2 -0
- package/web/assets/{redo-2-DSi54z4e.js → redo-2-BO7wCDwy.js} +1 -1
- package/web/assets/{rotate-ccw-CUlnplr0.js → rotate-ccw-BvipPIjC.js} +1 -1
- package/web/assets/{sharePage-MM6UpPJ9.js → sharePage-XbN50US7.js} +2 -2
- package/web/assets/{shareViewer-CDZ8lTdy.js → shareViewer-BaYogetW.js} +1 -1
- package/web/assets/{star-CwDiGyUW.js → star-BQWMXnn7.js} +1 -1
- package/web/assets/tableSurface-BXqqidd1.js +1 -0
- package/web/assets/{terminal-DIXogYJY.js → terminal-l9k6RDrH.js} +1 -1
- package/web/assets/{terminalView-B3aZSsrQ.js → terminalView-Cpnt5_0P.js} +1 -1
- package/web/assets/theme-C6D3tMGV.css +1 -0
- package/web/assets/type-CFoaj2eD.js +1 -0
- package/web/assets/{undo-2-tUKCv5Gs.js → undo-2-DusxpdLa.js} +1 -1
- package/web/assets/{unitAccount-D8lVwaaT.js → unitAccount-DwutFPPw.js} +1 -1
- package/web/assets/{unitBridge-D547ublk.js → unitBridge-CcgQpkqV.js} +1 -1
- package/web/assets/{unitCloudTransport-BVF6lVp4.js → unitCloudTransport-vA7cLDts.js} +1 -1
- package/web/assets/{unitOwnerAccess-BfnEjsZb.js → unitOwnerAccess-LBlJ1YfA.js} +1 -1
- package/web/assets/{unitShim-DxetRgmP.js → unitShim-B_M9IrbC.js} +3 -3
- package/web/assets/{upload-BbeAsMuD.js → upload-ZrOj6tXA.js} +1 -1
- package/web/assets/userSpaces-uJOnsedR.js +1 -0
- package/web/assets/viewportLock-D3SNkwS2.js +631 -0
- package/web/assets/viewportLock-IP1zaVkz.css +1 -0
- package/web/assets/{workflow-DuoVRSSX.js → workflow-DPoG4QE2.js} +1 -1
- package/web/assets/{zoom-in-hr5bRpDL.js → zoom-in-lbTgzdQP.js} +1 -1
- package/web/index.html +232 -13
- package/web/assets/ArtificialView-B4ESD4iK.js +0 -1
- package/web/assets/CalendarConfigView-cCfo_EvZ.js +0 -1
- package/web/assets/CalendarView-wgLapctk.js +0 -1
- package/web/assets/CapabilityMenu-BQBsM638.js +0 -1
- package/web/assets/ChatView-BIUk0OJd.css +0 -1
- package/web/assets/ChatView-C-jCJnyS.js +0 -47
- package/web/assets/Chrome-CwFiDmre.js +0 -1
- package/web/assets/DashboardGridView-DXqe0vPd.js +0 -17
- package/web/assets/ExcalidrawCanvas-C3egkikA.js +0 -1
- package/web/assets/HomepageView-CRdhjLXu.js +0 -1
- package/web/assets/ImageStudioPanels-Dke7xf8E.js +0 -3
- package/web/assets/ImageStudioView-g38V8gaj.js +0 -1
- package/web/assets/InlineFiles-C_hjvn3u.js +0 -1
- package/web/assets/MarkdownBlock-DIjYEhTK.js +0 -56
- package/web/assets/ModelPill-BPlgovPo.js +0 -1
- package/web/assets/MuseLibraryView-CenyTTim.js +0 -2
- package/web/assets/PdfAnnotator-CGzC_o1Q.css +0 -1
- package/web/assets/PdfAnnotator-D79ip27w.js +0 -560
- package/web/assets/RightPanel-C3OJTIqT.js +0 -4
- package/web/assets/RunLocationPicker-BNcZ7KKF.css +0 -1
- package/web/assets/RunLocationPicker-CTYXUH2z.js +0 -34
- package/web/assets/UnifiedPage-CKNtVD_n.js +0 -57
- package/web/assets/UnifiedPage-DX_sTpyZ.css +0 -1
- package/web/assets/appStore-Di8LXuJ9.css +0 -1
- package/web/assets/automationListSource-DP5xZBxo.js +0 -1
- package/web/assets/chatBoxSurface-zvcyfrxE.js +0 -1
- package/web/assets/dashboardSurface-CFTH5z4c.js +0 -1
- package/web/assets/ellipsis-r1EcXsFq.js +0 -1
- package/web/assets/floatingTocSurface-C6RJ6i41.js +0 -1
- package/web/assets/folder-DlxnPmWY.js +0 -1
- package/web/assets/frame-_xBVYe3P.js +0 -1
- package/web/assets/gestures-CkW1Kfs9.js +0 -1
- package/web/assets/i18n-D-eU58uw.css +0 -1
- package/web/assets/i18n.generated-Bbsz16cl.js +0 -15
- package/web/assets/imageStudio-BqbNOvpu.css +0 -1
- package/web/assets/imageStudio-C_Rs630L.js +0 -2
- package/web/assets/index-BCubCwdT.js +0 -1
- package/web/assets/index-DZfZTksa.js +0 -1
- package/web/assets/main-Dki8NlsT.js +0 -21
- package/web/assets/markdownEditorSurface-B4PeUzed.js +0 -3
- package/web/assets/mdMarkStore-CsKl7C8O.js +0 -2
- package/web/assets/minus-Cyv1YzOU.js +0 -1
- package/web/assets/mobileEntry-Bd_nKr0D.js +0 -13
- package/web/assets/nativeDownload-D-f1_L2S.js +0 -1
- package/web/assets/pageChrome-C9_azUYW.js +0 -1
- package/web/assets/panel-left-rOc8As0s.js +0 -1
- package/web/assets/pen-line-m6_HvWZ9.js +0 -1
- package/web/assets/sticky-note-BIuPUSOU.js +0 -1
- package/web/assets/tableSurface-Y_JBQsuz.js +0 -1
- package/web/assets/theme-DfEi_DND.css +0 -1
- package/web/assets/type-Cqoabh7H.js +0 -1
- package/web/assets/userSpaces-DyyAn7vj.js +0 -1
- package/web/assets/viewportLock-C4SX-9PO.js +0 -103
- package/web/assets/viewportLock-DYSe7Jsn.css +0 -1
- package/web/assets/waves-horizontal-B8ZpHQ5H.js +0 -1
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import{d as T,r as De,be as Dn,bq as Va,bp as Ud,U as Vo,c3 as Qt,c4 as Go,c5 as wi,t as D,c6 as xi,P as vi,Q as Ci,R as Si,bW as Yo,q as Mi,u as nn,j as b,bQ as Ir,c7 as Ai,c8 as Ni,m as mo,n as Ei,am as Vd,ar as Gd,B as Xo,c9 as Ga,a6 as Yd,ca as ho,cb as Ya,cc as Xd,cd as Jd,bS as Qd,bZ as Zd,b_ as Xa,b$ as ef,aw as tf,ax as nf,c1 as rf,aO as of,bM as sf}from"./index-CF4RV4mh.js";import{z as Ti,lY as fe,lL as te,m3 as J,m2 as pe,lO as K,l_ as Q,mh as Te,nt as Jo,nu as af,lV as Qo,lX as or,lP as ce,nv as lf,nw as Ht,nx as _n,ny as rt,m_ as ie,nz as Ii,nA as Li,mc as ae,nB as Mn,nC as Zo,nD as cf,nE as ot,nF as uf,nG as df,lW as go,nH as ff,nI as es,nJ as Ri,nK as Ye,me as pf,nL as mf,lZ as Ue,mB as hf,nM as gf,nN as $i,nO as bf,nP as zn,lE as yf,lF as kf,m$ as Zt,nQ as wf,nR as xf,nS as Di,mZ as fr,nT as vf,nU as _i,nV as zi,nW as Cf,nX as Sf,nY as Mf,nZ as Af,n_ as Nf,n$ as Ef,o0 as Tf,o1 as If,m4 as Lf,o2 as Rf,a8 as rn,mC as $f,o3 as Dt,o4 as Df,iq as _f,o5 as zf,da as An,d4 as ze,o6 as pr,o7 as Of,lI as Pf,o8 as Bf,cl as Kf,o9 as jf,oa as Hf,l$ as Ff,ob as qf,oc as Wf,od as Uf,eS as Oi,mo as Pi,oe as Vf,aB as Gf,of as Yf,gQ as Xf,og as Jf,fa as bo,oh as Qr,S as Qf,iW as Zf,oi as ep,oj as tp,ok as np,ol as rp,om as op,on as sp,oo as ap,op as lp,iU as ip,iL as cp,oq as up,or as dp,os as fp,ot as pp,ou as mp,ov as hp,ow as gp,ox as bp,oy as yp,oz as kp,oA as wp,oB as xp,oC as vp,oD as Cp,oE as Sp,oF as Mp,ez as Ap,n0 as Np,eE as Qn,n1 as Zr,oG as Ep,oH as Tp,oI as Ip,oJ as Ja,lN as Qa,oK as Lp,oL as Bi,oM as Rp,oN as $p,oO as Dp,kg as _p}from"./appStore-Dg9WALEA.js";import{$ as Z,c as F,d as st,e as On,f as _e,g as ts,a as xe,h as Xe,b as Ee,i as ns,j as ue,k as zp}from"./index-BCubCwdT.js";import{s as Ki,b as Lr,L as Za,m as Op,d as Pp,a as Bp,u as ji,e as Kp,w as jp,l as Hp,f as Fp,g as qp,I as el}from"./linkFollow-C0_3k_PC.js";import{A as Wp}from"./mdMarks-Bq7Hl-4C.js";import{s as Up}from"./emoji-DGaxpCIu.js";import{b as Vp,t as Gp,m as Yp,g as Xp}from"./listFold-BsOVn9UZ.js";const Jp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],Qp=Ti("text-align-center",Jp);const Zp=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],em=Ti("text-align-end",Zp);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 rs="amadeus.notes.spellcheck",yo="amadeus:notes-spellcheck";function Hi(){try{return localStorage.getItem(rs)!=="0"}catch{return!0}}function _0(e){try{localStorage.setItem(rs,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(yo))}catch{}}function Fi(e){const t=n=>{(!n.key||n.key===rs)&&e()};return window.addEventListener(yo,e),window.addEventListener("storage",t),()=>{window.removeEventListener(yo,e),window.removeEventListener("storage",t)}}function z0(){return T.useSyncExternalStore(Fi,Hi,()=>!0)}const tl={spellcheck:"false"};function nl(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,tl))}),n.textContent.includes("$"))for(const s of Ki(Lr(n)))t.push(J.inline(o+s.from,o+s.to,tl));return!1}),t.length?pe.create(e,t):pe.empty}const rl=new fe("amadeus-spellcheck"),tm=Z(()=>new te({key:rl,state:{init:(e,t)=>nl(t.doc),apply:(e,t)=>e.docChanged?nl(e.doc):t},props:{decorations:e=>rl.getState(e),attributes:()=>({spellcheck:Hi()?"true":"false"})},view:e=>({destroy:Fi(()=>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 os="amadeus.notes.codeAutoPair",ko="amadeus:notes-code-autopair";function qi(){try{return localStorage.getItem(os)!=="0"}catch{return!0}}function O0(e){try{localStorage.setItem(os,e?"1":"0")}catch{}try{window.dispatchEvent(new Event(ko))}catch{}}function nm(e){const t=n=>{(!n.key||n.key===os)&&e()};return window.addEventListener(ko,e),window.addEventListener("storage",t),()=>{window.removeEventListener(ko,e),window.removeEventListener("storage",t)}}function P0(){return T.useSyncExternalStore(nm,qi,()=>!0)}const mr={"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"},rm=new Set(Object.values(mr)),ol=/[\p{L}\p{N}_]/u;function Wi(e,t,n){if(t!==n||!qi())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 om(e,t,n,r){const o=Wi(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(rm.has(r)&&s===r)return e.dispatch(e.state.tr.setSelection(K.create(e.state.doc,t+1))),!0;const l=mr[r];if(!l||ol.test(s)||l===r&&ol.test(a))return!1;const i=e.state.tr.insertText(r+l,t,n);return i.setSelection(K.create(i.doc,t+1)),e.dispatch(i),!0}function sm(e){const{from:t,to:n}=e.state.selection,r=Wi(e,t,n);if(!r||r.off===0)return!1;const o=r.text.charAt(r.off-1);return!mr[o]||r.text.charAt(r.off)!==mr[o]?!1:(e.dispatch(e.state.tr.delete(t-1,t+1)),!0)}function am(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=Q.empty,f=o.index(-1)?1:o.index(-2)?2:3;for(let k=o.depth-f;k>=o.depth-3;k--)d=Q.from(o.node(k).copy(d));let m=o.indexAfter(-1)<o.node(-2).childCount?1:o.indexAfter(-2)<o.node(-3).childCount?2:3;d=d.append(Q.from(e.createAndFill()));let p=o.before(o.depth-(f-1)),h=n.tr.replace(p,o.after(-m),new Te(d,4-f,0)),g=-1;h.doc.nodesBetween(p,h.doc.content.size,(k,y)=>{if(g>-1)return!1;k.isTextblock&&k.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 lf(c.doc,o.pos,2,u)?(r&&r(c.split(o.pos,2,u).scrollIntoView()),!0):!1}}function Ui(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?lm(t,n,e,s):im(t,n,s):!0:!1}}function lm(e,t,n,r){let o=e.tr,s=r.end,a=r.$to.end(r.depth);s<a&&(o.step(new Jo(s-1,a,s,a,new Te(Q.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new af(o.doc.resolve(r.$from.pos),o.doc.resolve(a),r.depth));const l=Qo(r);if(l==null)return!1;o.lift(r,l);let i=o.doc.resolve(o.mapping.map(s,-1)-1);return or(o.doc,i.pos)&&i.nodeBefore.type==i.nodeAfter.type&&o.join(i.pos),t(o.scrollIntoView()),!0}function im(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?Q.empty:Q.from(o))))return!1;let d=s.pos,f=d+a.nodeSize;return r.step(new Jo(d-(l?1:0),f+(i?1:0),d+1,f-1,new Te((l?Q.empty:Q.from(o.copy(Q.empty))).append(i?Q.empty:Q.from(o.copy(Q.empty))),l?0:1,i?0:1),l?0:1)),t(r.scrollIntoView()),!0}function Vi(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=Q.from(c?e.create():null),d=new Te(Q.from(e.create(null,Q.from(l.type.create(null,u)))),c?3:1,0),f=s.start,m=s.end;n(t.tr.step(new Jo(f-(c?3:1),m,f,m,d,1,!0)).scrollIntoView())}return!0}}function cm(e){const t=new Map;if(!e||!e.type)throw new Error("mdast-util-definitions expected node");return Dn(e,"definition",function(r){const o=sl(r.identifier);o&&!t.get(o)&&t.set(o,r)}),n;function n(r){const o=sl(r);return t.get(o)}}function sl(e){return String(e||"").toUpperCase()}function um(){return function(e){const t=cm(e);Dn(e,function(n,r,o){if(n.type==="definition"&&o!==void 0&&typeof r=="number")return o.children.splice(r,1),[Va,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},[Va,r]}})}}function Gi(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(Q.fromArray(n))}function x(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-commonmark",...t}}),e}var ss=On("emphasis");x(ss,{displayName:"Attr<emphasis>",group:"Emphasis"});var At=st("emphasis",e=>({attrs:{marker:{default:e.get(Ht).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:t=>t==="italic"}],toDOM:t=>["em",e.get(ss.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})}}}));x(At.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});x(At.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});var Rr=F("ToggleEmphasis",e=>()=>_n(At.type(e)));x(Rr,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});var as=ue(e=>ot(/(?:^|[^*])\*([^*]+)\*$/,At.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}));x(as,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});var ls=ue(e=>ot(/\b_(?![_\s])(.*?[^_\s])_\b/,At.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}));x(ls,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});var is=_e("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:e=>{const t=e.get(ae);return()=>t.call(Rr.key)}}});x(is.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});x(is.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});var cs=On("strong");x(cs,{displayName:"Attr<strong>",group:"Strong"});var on=st("strong",e=>({attrs:{marker:{default:e.get(Ht).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(cs.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})}}}));x(on.mark,{displayName:"MarkSchema<strong>",group:"Strong"});x(on.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});var $r=F("ToggleStrong",e=>()=>_n(on.type(e)));x($r,{displayName:"Command<toggleStrongCommand>",group:"Strong"});var us=ue(e=>ot(new RegExp("(?<![\\w:/])(?:\\*\\*|__)([^*_]+?)(?:\\*\\*|__)(?![\\w/])$"),on.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}));x(us,{displayName:"InputRule<strong>",group:"Strong"});var ds=_e("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:e=>{const t=e.get(ae);return()=>t.call($r.key)}}});x(ds.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});x(ds.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});var fs=On("inlineCode");x(fs,{displayName:"Attr<inlineCode>",group:"InlineCode"});var ut=st("inlineCode",e=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:t=>["code",e.get(fs.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)}}));x(ut.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});x(ut.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});var Dr=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,ut.type(e))?(n?.(o.removeMark(s,a,ut.type(e))),!0):(Object.keys(t.schema.marks).filter(l=>l!==ut.type.name).map(l=>t.schema.marks[l]).forEach(l=>{o.removeMark(s,a,l)}),n?.(o.addMark(s,a,ut.type(e).create())),!0)});x(Dr,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});var ps=ue(e=>ot(/(?:`)([^`]+)(?:`)$/,ut.type(e)));x(ps,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});var ms=_e("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:e=>{const t=e.get(ae);return()=>t.call(Dr.key)}}});x(ms.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});x(ms.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});var _r=On("link");x(_r,{displayName:"Attr<link>",group:"Link"});var Ve=st("link",e=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:t=>{if(!(t instanceof HTMLElement))throw rt(t);return{href:t.getAttribute("href"),title:t.getAttribute("title")}}}],toDOM:t=>["a",{...e.get(_r.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})}}}));x(Ve.mark,{displayName:"MarkSchema<link>",group:"Link"});var Yi=F("ToggleLink",e=>(t={})=>_n(Ve.type(e),t));x(Yi,{displayName:"Command<toggleLinkCommand>",group:"Link"});var Xi=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(Ve.type(e).isInSet(p.marks))return o=p,s=h,!1}),!o)return!1;const c=o.marks.find(({type:p})=>p===Ve.type(e));if(!c)return!1;const u=s,d=s+o.nodeSize,{tr:f}=n,m=Ve.type(e).create({...c.attrs,...t});return m?(r(f.removeMark(u,d,c).addMark(u,d,m).setSelection(new K(f.selection.$anchor)).scrollIntoView()),!0):!1});x(Xi,{displayName:"Command<updateLinkCommand>",group:"Link"});var hs=ts("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)}}}));x(hs,{displayName:"NodeSchema<doc>",group:"Doc"});function dm(e){return Ud(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 zr=xe("remark-preserve-empty-line",()=>()=>dm);x(zr.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});x(zr.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});var Or=Xe("paragraph");x(Or,{displayName:"Attr<paragraph>",group:"Paragraph"});var Pe=Ee("paragraph",e=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:t=>["p",e.get(Or.key)(t),0],parseMarkdown:{match:t=>t.type==="paragraph",runner:(t,n,r)=>{t.openNode(r),n.children?t.next(n.children):t.addText(n.value||""),t.closeNode()}},toMarkdown:{match:t=>t.type.name==="paragraph",runner:(t,n)=>{const r=e.get(ie).state?.doc.lastChild;t.openNode("paragraph"),(!n.content||n.content.size===0)&&n!==r&&fm(e)?t.addNode("html",void 0,"<br />"):Gi(t,n),t.closeNode()}}}));function fm(e){let t=!1;try{e.get(zr.id),t=!0}catch{t=!1}return t}x(Pe.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});x(Pe.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});var gs=F("TurnIntoText",e=>()=>Mn(Pe.type(e)));x(gs,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});var bs=_e("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:e=>{const t=e.get(ae);return()=>t.call(gs.key)}}});x(bs.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});x(bs.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});var pm=Array(6).fill(0).map((e,t)=>t+1);function mm(e){return e.textContent.toLowerCase().trim().replace(/\s+/g,"-")}var Pn=ns(mm,"headingIdGenerator");x(Pn,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});var Pr=Xe("heading");x(Pr,{displayName:"Attr<heading>",group:"Heading"});var nt=Ee("heading",e=>{const t=e.get(Pn.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:pm.map(n=>({tag:`h${n}`,getAttrs:r=>{if(!(r instanceof HTMLElement))throw rt(r);return{level:n,id:r.id}}})),toDOM:n=>[`h${n.attrs.level}`,{...e.get(Pr.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}),Gi(n,r),n.closeNode()}}}});x(nt.node,{displayName:"NodeSchema<heading>",group:"Heading"});x(nt.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});var Ji=ue(e=>Ri(/^(?<hashes>#+)\s$/,nt.type(e),t=>{const n=t.groups?.hashes?.length||0,{$from:r}=e.get(ie).state.selection,o=r.node();if(o.type.name==="heading"){let s=Number(o.attrs.level)+Number(n);return s>6&&(s=6),{level:s}}return{level:n}}));x(Ji,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});var bt=F("WrapInHeading",e=>t=>(t??=1,t<1?Mn(Pe.type(e)):Mn(nt.type(e),{level:t})));x(bt,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});var ys=F("DowngradeHeading",e=>()=>(t,n,r)=>{const{$from:o}=t.selection,s=o.node();if(s.type!==nt.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):Mn(Pe.type(e))(t,n,r)});x(ys,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});var ks=_e("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:e=>{const t=e.get(ae);return()=>t.call(bt.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:e=>{const t=e.get(ae);return()=>t.call(ys.key)}}});x(ks.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});x(ks.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});var Br=Xe("blockquote");x(Br,{displayName:"Attr<blockquote>",group:"Blockquote"});var St=Ee("blockquote",e=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:t=>["blockquote",e.get(Br.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()}}}));x(St.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});x(St.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});var Qi=ue(e=>es(/^\s*>\s$/,St.type(e)));x(Qi,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});var ws=F("WrapInBlockquote",e=>()=>Zo(St.type(e)));x(ws,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});var xs=_e("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:e=>{const t=e.get(ae);return()=>t.call(ws.key)}}});x(xs.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});x(xs.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});var vs=Xe("codeBlock",()=>({pre:{},code:{}}));x(vs,{displayName:"Attr<codeBlock>",group:"CodeBlock"});var Bn=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 rt(t);return{language:t.dataset.language}}}],toDOM:t=>{const n=e.get(vs.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})}}}));x(Bn.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});x(Bn.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});var Zi=ue(e=>Ri(/^```(?<language>[a-z]*)?[\s\n]$/,Bn.type(e),t=>({language:t.groups?.language??""})));x(Zi,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});var Cs=F("CreateCodeBlock",e=>(t="")=>Mn(Bn.type(e),{language:t}));x(Cs,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});var hm=F("UpdateCodeBlockLanguage",()=>({pos:e,language:t}={pos:-1,language:""})=>(n,r)=>e>=0?(r?.(n.tr.setNodeAttribute(e,"language",t)),!0):!1);x(hm,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});var Ss=_e("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:e=>{const t=e.get(ae);return()=>t.call(Cs.key)}}});x(Ss.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});x(Ss.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});var Ms=Xe("image");x(Ms,{displayName:"Attr<image>",group:"Image"});var sn=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 rt(t);return{src:t.getAttribute("src")||"",alt:t.getAttribute("alt")||"",title:t.getAttribute("title")||t.getAttribute("alt")||""}}}],toDOM:t=>["img",{...e.get(Ms.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})}}}));x(sn.node,{displayName:"NodeSchema<image>",group:"Image"});x(sn.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});var ec=F("InsertImage",e=>(t={})=>(n,r)=>{if(!r)return!0;const{src:o="",alt:s="",title:a=""}=t,l=sn.type(e).create({src:o,alt:s,title:a});return l&&r(n.tr.replaceSelectionWith(l).scrollIntoView()),!0});x(ec,{displayName:"Command<insertImageCommand>",group:"Image"});var tc=F("UpdateImage",e=>(t={})=>(n,r)=>{const o=uf(n.selection,sn.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});x(tc,{displayName:"Command<updateImageCommand>",group:"Image"});var gm=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,sn.type(e).create({src:l,alt:a,title:i})):null}));x(gm,{displayName:"InputRule<insertImageInputRule>",group:"Image"});var hr=Xe("hardbreak",e=>({"data-type":"hardbreak","data-is-inline":e.attrs.isInline}));x(hr,{displayName:"Attr<hardbreak>",group:"Hardbreak"});var Ge=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(hr.key)(t)," "]:["br",e.get(hr.key)(t)],parseMarkdown:{match:({type:t})=>t==="break",runner:(t,n,r)=>{t.addNode(r,{isInline:!!n.data?.isInline})}},leafText:()=>`
|
|
2
|
-
`,toMarkdown:{match:t=>t.type.name==="hardbreak",runner:(t,n)=>{n.attrs.isInline?t.addNode("text",void 0,`
|
|
3
|
-
`):t.addNode("break")}}}));x(Ge.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});x(Ge.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});var As=F("InsertHardbreak",e=>()=>(t,n)=>{const{selection:r,tr:o}=t;if(!(r instanceof K))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(Ge.type(e).create()).scrollIntoView()),!0});x(As,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});var Ns=_e("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:e=>{const t=e.get(ae);return()=>t.call(As.key)}}});x(Ns.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});x(Ns.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});var Es=Xe("hr");x(Es,{displayName:"Attr<hr>",group:"Hr"});var Kn=Ee("hr",e=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:t=>["hr",e.get(Es.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")}}}));x(Kn.node,{displayName:"NodeSchema<hr>",group:"Hr"});x(Kn.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});var nc=ue(e=>new Ye(/^(?:---|___\s|\*\*\*\s)$/,(t,n,r,o)=>{const{tr:s}=t;return n[0]&&s.replaceWith(r-1,o,Kn.type(e).create()),s}));x(nc,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});var rc=F("InsertHr",e=>()=>(t,n)=>{if(!n)return!0;const r=Pe.node.type(e).create(),{tr:o,selection:s}=t,{from:a}=s,l=Kn.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});x(rc,{displayName:"Command<insertHrCommand>",group:"Hr"});var Kr=Xe("bulletList");x(Kr,{displayName:"Attr<bulletList>",group:"BulletList"});var ft=Ee("bullet_list",e=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:t=>{if(!(t instanceof HTMLElement))throw rt(t);return{spread:t.dataset.spread==="true"}}}],toDOM:t=>["ul",{...e.get(Kr.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()}}}));x(ft.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});x(ft.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});var oc=ue(e=>es(/^\s*([-+*])\s$/,ft.type(e)));x(oc,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});var Ts=F("WrapInBulletList",e=>()=>Zo(ft.type(e)));x(Ts,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});var Is=_e("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:e=>{const t=e.get(ae);return()=>t.call(Ts.key)}}});x(Is.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});x(Is.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});var jr=Xe("orderedList");x(jr,{displayName:"Attr<orderedList>",group:"OrderedList"});var pt=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 rt(t);return{spread:t.dataset.spread,order:t.hasAttribute("start")?Number(t.getAttribute("start")):1}}}],toDOM:t=>["ol",{...e.get(jr.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()}}}));x(pt.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});x(pt.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});var sc=ue(e=>es(/^\s*(\d+)\.\s$/,pt.type(e),t=>({order:Number(t[1])}),(t,n)=>n.childCount+n.attrs.order===Number(t[1])));x(sc,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});var Ls=F("WrapInOrderedList",e=>()=>Zo(pt.type(e)));x(Ls,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});var Rs=_e("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:e=>{const t=e.get(ae);return()=>t.call(Ls.key)}}});x(Rs.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});x(Rs.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});var $s=Xe("listItem");x($s,{displayName:"Attr<listItem>",group:"ListItem"});var ht=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 rt(t);return{label:t.dataset.label,listType:t.dataset.listType,spread:t.dataset.spread==="true"}}}],toDOM:t=>["li",{...e.get($s.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()}}}));x(ht.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});x(ht.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});var Ds=F("SinkListItem",e=>()=>Vi(ht.type(e)));x(Ds,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});var _s=F("LiftListItem",e=>()=>Ui(ht.type(e)));x(_s,{displayName:"Command<liftListItemCommand>",group:"ListItem"});var zs=F("SplitListItem",e=>()=>am(ht.type(e)));x(zs,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function bm(e){return(t,n,r)=>{const{selection:o}=t;if(!(o instanceof K))return!1;const{empty:s,$from:a}=o;return!s||a.parentOffset!==0||a.node(-1).type!==ht.type(e)?!1:cf(t,n,r)}}var Os=F("LiftFirstListItem",e=>()=>bm(e));x(Os,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});var Ps=_e("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:e=>{const t=e.get(ae);return()=>t.call(zs.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:e=>{const t=e.get(ae);return()=>t.call(Ds.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:e=>{const t=e.get(ae);return()=>t.call(_s.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:e=>{const t=e.get(ae);return()=>t.call(Os.key)}}});x(Ps.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});x(Ps.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});var ac=ts("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)}}}));x(ac,{displayName:"NodeSchema<text>",group:"Text"});var Bs=Xe("html");x(Bs,{displayName:"Attr<html>",group:"Html"});var Ks=Ee("html",e=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:t=>{const n=document.createElement("span"),r={...e.get(Bs.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)}}}));x(Ks.node,{displayName:"NodeSchema<html>",group:"Html"});x(Ks.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});var ym=[hs,Or,Pe,Pn,Pr,nt,hr,Ge,Br,St,vs,Bn,Es,Kn,Ms,sn,Kr,ft,jr,pt,$s,ht,ss,At,cs,on,fs,ut,_r,Ve,Bs,Ks,ac].flat(),km=[Qi,oc,sc,Zi,nc,Ji].flat(),wm=[as,ls,ps,us],xm=F("IsMarkSelected",()=>e=>t=>{if(!e)return!1;const{doc:n,selection:r}=t;return n.rangeHasMark(r.from,r.to,e)}),vm=F("IsNoteSelected",()=>e=>t=>e?df(t,e).hasNode:!1),Cm=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)}),Sm=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}),Mm=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&&go(i,r,o);if(!c)return!1;s=s.wrap(i,c)}catch{return!1}return n?.(s),!0}),Am=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 ff?r:r.createAndFill(o);if(!a)return!1;s.replaceSelectionWith(a)}catch{return!1}return n?.(s),!0}),Nm=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(K.near(a))}catch{return!1}return n?.(s.scrollIntoView()),!0}),Em=[gs,ws,bt,ys,Cs,As,rc,ec,tc,Ls,Ts,Ds,zs,_s,Os,Rr,Dr,$r,Yi,Xi,xm,vm,Cm,Sm,Mm,Am,Nm],Tm=[xs,Ss,Ns,ks,Ps,Rs,Is,bs,is,ms,ds].flat(),Hr=xe("remarkAddOrderInList",()=>()=>e=>{Dn(e,"list",t=>{if(t.ordered){const n=t.start??1;t.children.forEach((r,o)=>{r.label=o+n})}})});x(Hr.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});x(Hr.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});var js=xe("remarkLineBreak",()=>()=>e=>{const t=/[\t ]*(?:\r?\n|\r)/g;Dn(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})});x(js.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});x(js.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});var Hs=xe("remarkInlineLink",()=>um);x(Hs.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});x(Hs.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});var Im=e=>!!e.children,Lm=e=>e.type==="html";function Rm(e,t){return n(e,0,null)[0];function n(r,o,s){if(Im(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 $m=["root","blockquote","listItem"],Fs=xe("remarkHTMLTransformer",()=>()=>e=>{Rm(e,(t,n,r)=>Lm(t)?(r&&$m.includes(r.type)&&(t.children=[{...t}],delete t.value,t.type="paragraph"),[t]):[t])});x(Fs.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});x(Fs.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});var qs=xe("remarkMarker",()=>()=>(e,t)=>{const n=r=>t.value.charAt(r.position.start.offset);Dn(e,r=>["strong","emphasis"].includes(r.type),r=>{r.marker=n(r)})});x(qs.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});x(qs.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});var lc=Z(()=>{let e=!1;const t=new te({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"}),pe.create(n.doc,[s,l])}return pe.empty}}});return t});x(lc,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});var Ws=Z(e=>new te({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 Ii))return;const{from:a}=s;return r.tr.setNodeMarkup(a,Ge.type(e),void 0,[])}if(s instanceof Li){let a=r.tr;const{from:l,to:i}=s;return r.doc.nodesBetween(l,i,(c,u)=>{c.type===Ge.type(e)&&(a=a.setNodeMarkup(u,Ge.type(e),void 0,[]))}),a}}}));x(Ws,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});var Us=ns(["table","code_block"],"hardbreakFilterNodes");x(Us,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});var ic=Z(e=>{const t=e.get(Us.key);return new te({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}})});x(ic,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});var cc=Z(e=>{const t=new fe("MILKDOWN_HEADING_ID"),n=r=>{if(r.composing)return;const o=e.get(Pn.key),s=r.state.tr.setMeta("addToHistory",!1);let a=!1;const l={};r.state.doc.descendants((i,c)=>{if(i.type===nt.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 te({key:t,view:r=>(n(r),{update:(o,s)=>{o.state.doc.eq(s.doc)||n(o)}})})});x(cc,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});var uc=Z(e=>{const t=(n,r,o)=>{if(!o.selection||n.some(d=>d.getMeta("addToHistory")===!1||!d.isGeneric))return null;const s=pt.type(e),a=ft.type(e),l=ht.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,k,y,v)=>{if(g.type===l){const E={...g.attrs};i(E,v)&&(c=c.setNodeMarkup(k,void 0,E))}return!1}))}else if(d.type===l&&m?.type===s){const h={...d.attrs};let g=!1;h.listType!=="ordered"&&(h.listType="ordered",g=!0),m?.maybeChild(0)&&(g=i(h,p,m?.attrs.order??1)),g&&(c=c.setNodeMarkup(f,void 0,h),u=!0)}}),u?c.setMeta("addToHistory",!1):null};return new te({key:new fe("MILKDOWN_KEEP_LIST_ORDER"),appendTransaction:t})});x(uc,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});var Dm=[Ws,Us,ic,lc,Hr,Hs,js,Fs,qs,zr,cc,uc].flat(),_m=[ym,km,wm,Em,Tm,Dm].flat();let wo,xo;if(typeof WeakMap<"u"){let e=new WeakMap;wo=t=>e.get(t),xo=(t,n)=>(e.set(t,n),n)}else{const e=[];let n=0;wo=r=>{for(let o=0;o<e.length;o+=2)if(e[o]==r)return e[o+1]},xo=(r,o)=>(n==10&&(n=0),e[n++]=r,e[n++]=o)}var X=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 wo(e)||xo(e,zm(e))}};function zm(e){if(e.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+e.type.name);const t=Om(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:k,colwidth:y}=h.attrs;for(let v=0;v<k;v++){if(v+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:k-v});break}const E=o+v*t;for(let S=0;S<g;S++){r[E+S]==0?r[E+S]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:g-S});const N=y&&y[S];if(N){const C=(E+S)%t*2,_=a[C];_==null||_!=N&&a[C+1]==1?(a[C]=N,a[C+1]=1):_==N&&a[C+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 X(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&&Pm(l,a,e),l}function Om(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 Pm(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=Bm(i)))[c]=u)}l&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Bm(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function al(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 ll(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 Km(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 jm(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Km}};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=>al(r,t)}],toDOM(r){return["td",ll(r,t),0]}},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>al(r,t)}],toDOM(r){return["th",ll(r,t),0]}}}}function He(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 wt=new fe("selectingCells");function _t(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 Be(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 jn(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=_t(t.$head)||Hm(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function Hm(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 vo(e){return e.parent.type.spec.tableRole=="row"&&!!e.nodeAfter}function Fm(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Vs(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function dc(e,t,n){const r=e.node(-1),o=X.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 zt(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 qm(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 Wm(e,t,n){const r=He(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 ct extends ce{constructor(t,n=t){const r=t.node(-1),o=X.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 mf(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(vo(r)&&vo(o)&&Vs(r,o)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?ct.rowSelection(r,o):s&&this.isColSelection()?ct.colSelection(r,o):new ct(r,o)}return K.between(r,o)}content(){const t=this.$anchorCell.node(-1),n=X.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 k=p.attrs;if(h>0&&(k=zt(k,0,h)),g>0&&(k=zt(k,k.colspan-g,g)),m.left<o.left){if(p=p.type.createAndFill(k),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(k)}`)}else p=p.type.create(k,p.content)}if(m.top<o.top||m.bottom>o.bottom){const k={...p.attrs,rowspan:Math.min(m.bottom,o.bottom)-Math.max(m.top,o.top)};m.top<o.top?p=p.type.createAndFill(k):p=p.type.create(k,p.content)}c.push(p)}a.push(t.child(i).copy(Q.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?t:a;return new Te(Q.from(l),1,1)}replace(t,n=Te.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?Te.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 Te(Q.from(n),0,0))}forEachCell(t){const n=this.$anchorCell.node(-1),r=X.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=X.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 ct(t,n)}isRowSelection(){const t=this.$anchorCell.node(-1),n=X.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 ct&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const r=t.node(-1),o=X.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 ct(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new ct(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new ct(t.resolve(n),t.resolve(r))}getBookmark(){return new Um(this.$anchorCell.pos,this.$headCell.pos)}};de.prototype.visible=!1;ce.jsonID("cell",de);var Um=class fc{constructor(t,n){this.anchor=t,this.head=n}map(t){return new fc(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&&Vs(n,r)?new de(n,r):ce.near(r,1)}};function Vm(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"}))}),pe.create(e.doc,t)}function Gm({$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 Ym({$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 Xm(e,t,n){const r=(t||e).selection,o=(t||e).doc;let s,a;if(r instanceof Ue&&(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=X.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 K&&Gm(r)?s=K.create(o,r.from):r instanceof K&&Ym(r)&&(s=K.create(o,r.$from.start(),r.$from.end()));return s&&(t||(t=e.tr)).setSelection(s),t}const Jm=new fe("fix-tables");function pc(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)?pc(e.child(l),i,n+1,r):i.nodesBetween(0,i.content.size,r,n+1),n+=i.nodeSize}}function Qm(e,t){let n;const r=(o,s)=>{o.type.spec.tableRole=="table"&&(n=Zm(e,o,s,n))};return t?t.doc!=e.doc&&pc(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Zm(e,t,n,r){const o=X.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,zt(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 k=He(e.schema)[m].createAndFill();k&&p.push(k)}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(Jm,{fixTables:!0})}function mc(e){const t=X.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 hc(e,t){const n=[],r=X.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 gc(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 Hn(e){return eh(t=>t.type.spec.tableRole==="table",e)}function eh(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 Vt(e,t){const n=Hn(t.$from);if(!n)return;const r=X.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 Gt(e,t){const n=Hn(t.$from);if(!n)return;const r=X.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 il(e,t,n=t){let r=t,o=n;for(let u=t;u>=0;u--){const d=Vt(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=Vt(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=Vt(u,e.selection);d&&d.length>0&&s.push(u)}r=s[0],o=s[s.length-1];const a=Vt(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=Vt(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 cl(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.rowspan+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.rowspan+u-1;f.node.attrs.rowspan>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=Vt(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 ul(e){return e[0].map((t,n)=>e.map(r=>r[n]))}function th(e){var t,n;const{tr:r,originIndex:o,targetIndex:s,select:a,pos:l}=e,i=Hn(r.doc.resolve(l));if(!i)return!1;const c=(t=il(r,o))===null||t===void 0?void 0:t.indexes,u=(n=il(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=nh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=X.get(d),m=i.start,p=s,h=f.positionAt(f.height-1,p,d),g=r.doc.resolve(m+h),k=f.positionAt(0,p,d),y=r.doc.resolve(m+k);return r.setSelection(de.colSelection(g,y)),!0}function nh(e,t,n,r){let o=ul(mc(e));return o=gc(o,t,n),o=ul(o),hc(e,o)}function rh(e){var t,n;const{tr:r,originIndex:o,targetIndex:s,select:a,pos:l}=e,i=Hn(r.doc.resolve(l));if(!i)return!1;const c=(t=cl(r,o))===null||t===void 0?void 0:t.indexes,u=(n=cl(r,s))===null||n===void 0?void 0:n.indexes;if(!c||!u||c.includes(s))return!1;const d=oh(i.node,c,u);if(r.replaceWith(i.pos,i.pos+i.node.nodeSize,d),!a)return!0;const f=X.get(d),m=i.start,p=s,h=f.positionAt(p,f.width-1,d),g=r.doc.resolve(m+h),k=f.positionAt(p,0,d),y=r.doc.resolve(m+k);return r.setSelection(de.rowSelection(g,y)),!0}function oh(e,t,n,r){let o=mc(e);return o=gc(o,t,n),hc(e,o)}function Nt(e){const t=e.selection,n=jn(e),r=n.node(-1),o=n.start(-1),s=X.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 Gs(e,{map:t,tableStart:n,table:r},o){let s=o>0?-1:0;Wm(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,qm(c.attrs,o-t.colCount(i))),a+=c.attrs.rowspan-1}else{const i=s==null?He(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 sh(e,t){if(!Be(e))return!1;if(t){const n=Nt(e);t(Gs(e.tr,n,n.left))}return!0}function ah(e,t){if(!Be(e))return!1;if(t){const n=Nt(e);t(Gs(e.tr,n,n.right))}return!0}function bc(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,zt(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 lh(e,t){if(!Be(e))return!1;if(t){const n=Nt(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let o=n.right-1;bc(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=X.get(s)}t(r)}return!0}function yc(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 ih(e,t){if(!Be(e))return!1;if(t){const n=Nt(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let o=n.bottom-1;yc(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=X.get(n.table)}t(r)}return!0}function ch(e,t){return function(n,r){if(!Be(n))return!1;const o=jn(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 uh(e){return function(t,n){if(!Be(t))return!1;if(n){const r=He(t.schema),o=Nt(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 dl(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 Ys(e,t){return t=t||{useDeprecatedLogic:!1},t.useDeprecatedLogic?uh(e):function(n,r){if(!Be(n))return!1;if(r){const o=He(n.schema),s=Nt(n),a=n.tr,l=dl("row",s,o),i=dl("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}}Ys("row",{useDeprecatedLogic:!0});Ys("column",{useDeprecatedLogic:!0});Ys("cell",{useDeprecatedLogic:!0});function dh(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 Xs(e){return function(t,n){if(!Be(t))return!1;const r=dh(jn(t),e);if(r==null)return!1;if(n){const o=t.doc.resolve(r);n(t.tr.setSelection(K.between(o,Fm(o))).scrollIntoView())}return!0}}function fh(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 Zn(e,t){const n=e.selection;if(!(n instanceof de))return!1;if(t){const r=e.tr,o=He(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 Te(o,0,0))}),r.docChanged&&t(r)}return!0}function ph(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return rh({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function mh(e){return(t,n)=>{const{from:r,to:o,select:s=!0,pos:a=t.selection.from}=e,l=t.tr;return th({tr:l,originIndex:r,targetIndex:o,select:s,pos:a})?(n?.(l),!0):!1}}function hh(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=Co(He(a).row,new Te(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(n||r?Co(He(a).row,new Te(t,n,r)).content:t);else return null;return gh(a,l)}function gh(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(Q.empty),n[o]<r){const s=He(e).cell.createAndFill(),a=[];for(let l=n[o];l<r;l++)a.push(s);t[o]=t[o].append(Q.from(a))}return{height:t.length,width:r,rows:t}}function Co(e,t){const n=e.createAndFill();return new hf(n).replace(0,n.content.size,t).doc}function bh({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(zt(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(Q.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(Q.from(i))}n=s,t=o}return{width:e,height:t,rows:n}}function yh(e,t,n,r,o,s,a){const l=e.doc.type.schema,i=He(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,Q.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 fl(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 pl(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,zt(f.attrs,a-m,f.attrs.colspan-(a-m))),e.insert(p+f.nodeSize,f.type.createAndFill(zt(f.attrs,0,a-m))),c+=f.attrs.rowspan-1}}return i}function ml(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=X.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=X.get(s),f=d.mapping.maps.length}yh(d,a,s,n,c,u,f)&&m(),fl(d,a,s,n,i,c,l,f)&&m(),fl(d,a,s,n,i,c,u,f)&&m(),pl(d,a,s,n,l,u,i,f)&&m(),pl(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 Te(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 kh=pf({ArrowLeft:er("horiz",-1),ArrowRight:er("horiz",1),ArrowUp:er("vert",-1),ArrowDown:er("vert",1),"Shift-ArrowLeft":tr("horiz",-1),"Shift-ArrowRight":tr("horiz",1),"Shift-ArrowUp":tr("vert",-1),"Shift-ArrowDown":tr("vert",1),Backspace:Zn,"Mod-Backspace":Zn,Delete:Zn,"Mod-Delete":Zn});function sr(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function er(e,t){return(n,r,o)=>{if(!o)return!1;const s=n.selection;if(s instanceof de)return sr(n,r,ce.near(s.$headCell,t));if(e!="horiz"&&!s.empty)return!1;const a=kc(o,e,t);if(a==null)return!1;if(e=="horiz")return sr(n,r,ce.near(n.doc.resolve(s.head+t),t));{const l=n.doc.resolve(a),i=dc(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),sr(n,r,c)}}}function tr(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=kc(o,e,t);if(i==null)return!1;a=new de(n.doc.resolve(i))}const l=dc(a.$headCell,e,t);return l?sr(n,r,new de(a.$anchorCell,l)):!1}}function wh(e,t){const n=e.state.doc,r=_t(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new de(r))),!0):!1}function xh(e,t,n){if(!Be(e.state))return!1;let r=hh(n);const o=e.state.selection;if(o instanceof de){r||(r={width:1,height:1,rows:[Q.from(Co(He(e.state.schema).cell,n))]});const s=o.$anchorCell.node(-1),a=o.$anchorCell.start(-1),l=X.get(s).rectBetween(o.$anchorCell.pos-a,o.$headCell.pos-a);return r=bh(r,l.right-l.left,l.bottom-l.top),ml(e.state,e.dispatch,a,l,r),!0}else if(r){const s=jn(e.state),a=s.start(-1);return ml(e.state,e.dispatch,a,X.get(s.node(-1)).findCell(s.pos-a),r),!0}else return!1}function vh(e,t){var n;if(t.button!=0||t.ctrlKey||t.metaKey)return;const r=hl(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=_t(e.state.selection.$anchor))!=null&&((n=eo(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=eo(e,c);const d=wt.getState(e.state)==null;if(!u||!Vs(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(wt,i.pos),e.dispatch(m)}}function a(){e.root.removeEventListener("mouseup",a),e.root.removeEventListener("dragstart",a),e.root.removeEventListener("mousemove",l),wt.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(wt,-1))}function l(i){const c=i,u=wt.getState(e.state);let d;if(u!=null)d=e.state.doc.resolve(u);else if(hl(e,c.target)!=r&&(d=eo(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 kc(e,t,n){if(!(e.state.selection instanceof K))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 hl(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName=="TD"||t.nodeName=="TH")return t;return null}function eo(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&&_t(e.state.doc.resolve(r))||_t(e.state.doc.resolve(o))}var Ch=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")),So(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,So(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function So(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],k=g?g+"px":"";if(a+=g||r,g||(l=!1),i)i.style.width!=k&&(i.style.width=k),i=i.nextSibling;else{const y=document.createElement("col");y.style.width=k,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 Oe=new fe("tableColumnResizing");function Sh({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=Ch,lastColumnResizable:o=!0}={}){const s=new te({key:Oe,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=He(l.schema).table.name;return r&&c&&(c[u]=(d,f)=>new r(d,n,f)),new Mh(-1,!1)},apply(a,l){return l.apply(a)}},props:{attributes:a=>{const l=Oe.getState(a);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(a,l)=>{Ah(a,l,e,o)},mouseleave:a=>{Nh(a)},mousedown:(a,l)=>{Eh(a,l,t,n)}},decorations:a=>{const l=Oe.getState(a);if(l&&l.activeHandle>-1)return $h(a,l.activeHandle)},nodeViews:{}}});return s}var Mh=class ar{constructor(t,n){this.activeHandle=t,this.dragging=n}apply(t){const n=this,r=t.getMeta(Oe);if(r&&r.setHandle!=null)return new ar(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ar(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return vo(t.doc.resolve(o))||(o=-1),new ar(o,n.dragging)}return n}};function Ah(e,t,n,r){if(!e.editable)return;const o=Oe.getState(e.state);if(o&&!o.dragging){const s=Ih(t.target);let a=-1;if(s){const{left:l,right:i}=s.getBoundingClientRect();t.clientX-l<=n?a=gl(e,t,"left",n):i-t.clientX<=n&&(a=gl(e,t,"right",n))}if(a!=o.activeHandle){if(!r&&a!==-1){const l=e.state.doc.resolve(a),i=l.node(-1),c=X.get(i),u=l.start(-1);if(c.colCount(l.pos-u)+l.nodeAfter.attrs.colspan-1==c.width-1)return}wc(e,a)}}}function Nh(e){if(!e.editable)return;const t=Oe.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&wc(e,-1)}function Eh(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=Oe.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;const l=e.state.doc.nodeAt(a.activeHandle),i=Th(e,a.activeHandle,l.attrs);e.dispatch(e.state.tr.setMeta(Oe,{setDragging:{startX:t.clientX,startWidth:i}}));function c(d){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=Oe.getState(e.state);f?.dragging&&(Lh(e,f.activeHandle,bl(f.dragging,d,n)),e.dispatch(e.state.tr.setMeta(Oe,{setDragging:null})))}function u(d){if(!d.which)return c(d);const f=Oe.getState(e.state);if(f&&f.dragging){const m=bl(f.dragging,d,n);yl(e,f.activeHandle,m,r)}}return yl(e,a.activeHandle,i,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),t.preventDefault(),!0}function Th(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 Ih(e){for(;e&&e.nodeName!="TD"&&e.nodeName!="TH";)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}function gl(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=_t(e.state.doc.resolve(a));if(!l)return-1;if(n=="right")return l.pos;const i=X.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 bl(e,t,n){const r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function wc(e,t){e.dispatch(e.state.tr.setMeta(Oe,{setHandle:t}))}function Lh(e,t,n){const r=e.state.doc.resolve(t),o=r.node(-1),s=X.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():Rh(f.colspan);p[m]=n,i.setNodeMarkup(a+d,null,{...f,colwidth:p})}i.docChanged&&e.dispatch(i)}function yl(e,t,n,r){const o=e.state.doc.resolve(t),s=o.node(-1),a=o.start(-1),l=X.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&&So(s,i.firstChild,i,r,l,n)}function Rh(e){return Array(e).fill(0)}function $h(e,t){const n=[],r=e.doc.resolve(t),o=r.node(-1);if(!o)return pe.empty;const s=X.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=Oe.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 pe.create(e.doc,n)}function Dh({allowTableNodeSelection:e=!1}={}){return new te({key:wt,state:{init(){return null},apply(t,n){const r=t.getMeta(wt);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:Vm,handleDOMEvents:{mousedown:vh},createSelectionBetween(t){return wt.getState(t.state)!=null?t.state.selection:null},handleTripleClick:wh,handleKeyDown:kh,handlePaste:xh},appendTransaction(t,n,r){return Xm(r,Qm(r,n),e)}})}var gr=typeof navigator<"u"?navigator:null,Js=gr&&gr.userAgent||"",_h=/Edge\/(\d+)/.exec(Js),zh=/MSIE \d/.exec(Js),Oh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Js),Ph=!!(zh||Oh||_h),Bh=!Ph&&!!gr&&/Apple Computer/.test(gr.vendor),xc=new fe("safari-ime-span"),Mo=!1,Kh={key:xc,props:{decorations:jh,handleDOMEvents:{compositionstart:()=>{Mo=!0},compositionend:()=>{Mo=!1}}}};function jh(e){const{$from:t,$to:n,to:r}=e.selection;if(Mo&&t.sameParent(n)){const o=J.widget(r,Hh,{ignoreSelection:!0,key:"safari-ime-span"});return pe.create(e.doc,[o])}}function Hh(e){const t=e.dom.ownerDocument.createElement("span");return t.className="ProseMirror-safari-ime-span",t}var Fh=new te(Bh?Kh:{key:xc});function q(e,t){return Object.assign(e,{meta:{package:"@milkdown/preset-gfm",...t}}),e}var Qs=On("strike_through");q(Qs,{displayName:"Attr<strikethrough>",group:"Strikethrough"});var an=st("strike_through",e=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:t=>t==="line-through"}],toDOM:t=>["del",e.get(Qs.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(an.mark,{displayName:"MarkSchema<strikethrough>",group:"Strikethrough"});q(an.ctx,{displayName:"MarkSchemaCtx<strikethrough>",group:"Strikethrough"});var Nn=F("ToggleStrikeThrough",e=>()=>_n(an.type(e)));q(Nn,{displayName:"Command<ToggleStrikethrough>",group:"Strikethrough"});var Zs=ue(e=>ot(new RegExp("(?<![\\w:/])(~{1,2})(.+?)\\1(?!\\w|\\/)"),an.type(e)));q(Zs,{displayName:"InputRule<strikethrough>",group:"Strikethrough"});var ea=_e("strikeThroughKeymap",{ToggleStrikethrough:{shortcuts:"Mod-Alt-x",command:e=>{const t=e.get(ae);return()=>t.call(Nn.key)}}});q(ea.ctx,{displayName:"KeymapCtx<strikethrough>",group:"Strikethrough"});q(ea.shortcuts,{displayName:"Keymap<strikethrough>",group:"Strikethrough"});var Fn=jm({tableGroup:"block",cellContent:"paragraph",cellAttributes:{alignment:{default:"left",getFromDOM:e=>e.style.textAlign||"left",setDOMAttr:(e,t)=>{t.style=`text-align: ${e||"left"}`}}}}),dt=Ee("table",()=>({...Fn.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(dt.node,{displayName:"NodeSchema<table>",group:"Table"});q(dt.ctx,{displayName:"NodeSchemaCtx<table>",group:"Table"});var qn=Ee("table_header_row",()=>({...Fn.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(qn.node,{displayName:"NodeSchema<tableHeaderRow>",group:"Table"});q(qn.ctx,{displayName:"NodeSchemaCtx<tableHeaderRow>",group:"Table"});var ln=Ee("table_row",()=>({...Fn.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(ln.node,{displayName:"NodeSchema<tableRow>",group:"Table"});q(ln.ctx,{displayName:"NodeSchemaCtx<tableRow>",group:"Table"});var Wn=Ee("table_cell",()=>({...Fn.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(Wn.node,{displayName:"NodeSchema<tableCell>",group:"Table"});q(Wn.ctx,{displayName:"NodeSchemaCtx<tableCell>",group:"Table"});var en=Ee("table_header",()=>({...Fn.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(en.node,{displayName:"NodeSchema<tableHeader>",group:"Table"});q(en.ctx,{displayName:"NodeSchemaCtx<tableHeader>",group:"Table"});function vc(e,t=3,n=3){const r=Array(n).fill(0).map(()=>Wn.type(e).createAndFill()),o=Array(n).fill(0).map(()=>en.type(e).createAndFill()),s=Array(t).fill(0).map((a,l)=>l===0?qn.type(e).create(null,o):ln.type(e).create(null,r));return dt.type(e).create(null,s)}function Cc(e){return(t,n)=>r=>{n=n??r.selection.from;const o=r.doc.resolve(n),s=bf(i=>i.type.name==="table")(o),a=s?{node:s.node,from:s.start}:void 0,l=e==="row";if(a){const i=X.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 $i(r.setSelection(d(u,m)))}}return r}}var qh=Cc("row"),Wh=Cc("col");function Sc(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 Wn.type(e).createAndFill({alignment:u?.attrs.alignment})});return t.insert(a,ln.type(e).create(null,l)),t}function Uh(e){const t=Hn(e.$from);if(!t)return;const n=X.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 Vh(e){const t=Uh(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 $i(e.setSelection(new de(o,n)))}}return e}var ta=F("GoToPrevTableCell",()=>()=>Xs(-1));q(ta,{displayName:"Command<goToPrevTableCellCommand>",group:"Table"});var na=F("GoToNextTableCell",()=>()=>Xs(1));q(na,{displayName:"Command<goToNextTableCellCommand>",group:"Table"});var ra=F("ExitTable",e=>()=>(t,n)=>{if(!Be(t))return!1;const{$head:r}=t.selection,o=gf(r,dt.type(e));if(!o)return!1;const{to:s}=o,a=t.tr.replaceWith(s,s,Pe.type(e).createAndFill());return a.setSelection(ce.near(a.doc.resolve(s),1)).scrollIntoView(),n?.(a),!0});q(ra,{displayName:"Command<breakTableCommand>",group:"Table"});var Mc=F("InsertTable",e=>({row:t,col:n}={})=>(r,o)=>{const{selection:s,tr:a}=r,{from:l}=s,i=vc(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(Mc,{displayName:"Command<insertTableCommand>",group:"Table"});var Ac=F("MoveRow",()=>({from:e,to:t,pos:n}={})=>ph({from:e??0,to:t??0,pos:n}));q(Ac,{displayName:"Command<moveRowCommand>",group:"Table"});var Nc=F("MoveCol",()=>({from:e,to:t,pos:n}={})=>mh({from:e??0,to:t??0,pos:n}));q(Nc,{displayName:"Command<moveColCommand>",group:"Table"});var Ec=F("SelectRow",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(qh(e.index,e.pos)(r))});q(Ec,{displayName:"Command<selectRowCommand>",group:"Table"});var Tc=F("SelectCol",()=>(e={index:0})=>(t,n)=>{const{tr:r}=t;return!!n?.(Wh(e.index,e.pos)(r))});q(Tc,{displayName:"Command<selectColCommand>",group:"Table"});var Ic=F("SelectTable",()=>()=>(e,t)=>{const{tr:n}=e;return!!t?.(Vh(n))});q(Ic,{displayName:"Command<selectTableCommand>",group:"Table"});var Lc=F("DeleteSelectedCells",()=>()=>(e,t)=>{const{selection:n}=e;if(!(n instanceof de))return!1;const r=n.isRowSelection(),o=n.isColSelection();return r&&o?fh(e,t):o?lh(e,t):ih(e,t)});q(Lc,{displayName:"Command<deleteSelectedCellsCommand>",group:"Table"});var Rc=F("AddColBefore",()=>()=>sh);q(Rc,{displayName:"Command<addColBeforeCommand>",group:"Table"});var $c=F("AddColAfter",()=>()=>ah);q($c,{displayName:"Command<addColAfterCommand>",group:"Table"});var Dc=F("AddRowBefore",e=>()=>(t,n)=>{if(!Be(t))return!1;if(n){const r=Nt(t);n(Sc(e,t.tr,r,r.top))}return!0});q(Dc,{displayName:"Command<addRowBeforeCommand>",group:"Table"});var _c=F("AddRowAfter",e=>()=>(t,n)=>{if(!Be(t))return!1;if(n){const r=Nt(t);n(Sc(e,t.tr,r,r.bottom))}return!0});q(_c,{displayName:"Command<addRowAfterCommand>",group:"Table"});var zc=F("SetAlign",()=>(e="left")=>ch("alignment",e));q(zc,{displayName:"Command<setAlignCommand>",group:"Table"});var Oc=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),dt.type(e)))return null;const a=vc(e,Math.max(Number(n.groups?.row??0),2),Number(n.groups?.col)),l=t.tr.replaceRangeWith(r,o,a);return l.setSelection(K.create(l.doc,r+3)).scrollIntoView()}));q(Oc,{displayName:"InputRule<insertTableInputRule>",group:"Table"});var Pc=zp(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 Pe.type(e).create();const f=c.firstChild;if(!(d>0&&f&&f.childCount===0))return c;if(u>=3){const g=c.child(1),k=[];for(let E=0;E<g.childCount;E++){const S=g.child(E);k.push(en.type(e).create(S.attrs,S.content,S.marks))}const y=f.type.create(f.attrs,k),v=[];for(let E=2;E<u;E++)v.push(c.child(E));return c.type.create(c.attrs,[y,...v])}const m=Array(d).fill(0).map(()=>en.type(e).createAndFill()),p=new Te(Q.from(m),0,0),h=f.replace(0,0,p);return c.replace(0,f.nodeSize,new Te(Q.from(h),0,0))}function s(c){const u=ln.type(e),d=[];let f=[],m=!1;function p(){if(f.length===0)return;const h=qn.type(e).createAndFill(),g=dt.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?Q.from(d):c}function a(c){let u=s(c),d=u!==c;const f=[];return u.forEach(m=>{if(m.type===dt.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?Q.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===Pe.type(e)&&m.content.size===0&&p&&p.type===dt.type(e)||u.push(m)}return u.length<d.length?Q.from(u):c}let i=a(t.content);return i=l(i),new Te(Q.from(i),t.openStart,t.openEnd)}}));q(Pc,{displayName:"PasteRule<table>",group:"Table"});var oa=_e("tableKeymap",{NextCell:{priority:100,shortcuts:["Mod-]","Tab"],command:e=>{const t=e.get(ae);return()=>t.call(na.key)}},PrevCell:{shortcuts:["Mod-[","Shift-Tab"],command:e=>{const t=e.get(ae);return()=>t.call(ta.key)}},ExitTable:{shortcuts:["Mod-Enter","Enter"],command:e=>{const t=e.get(ae);return()=>t.call(ra.key)}}});q(oa.ctx,{displayName:"KeymapCtx<table>",group:"Table"});q(oa.shortcuts,{displayName:"Keymap<table>",group:"Table"});var to="footnote_definition",kl="footnoteDefinition",sa=Ee("footnote_definition",()=>({group:"block",content:"block+",defining:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`dl[data-type="${to}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw rt(e);return{label:e.dataset.label}},contentElement:"dd"}],toDOM:e=>{const t=e.attrs.label;return["dl",{"data-label":t,"data-type":to},["dt",t],["dd",0]]},parseMarkdown:{match:({type:e})=>e===kl,runner:(e,t,n)=>{e.openNode(n,{label:t.label}).next(t.children).closeNode()}},toMarkdown:{match:e=>e.type.name===to,runner:(e,t)=>{e.openNode(kl,void 0,{label:t.attrs.label,identifier:t.attrs.label}).next(t.content).closeNode()}}}));q(sa.ctx,{displayName:"NodeSchemaCtx<footnodeDef>",group:"footnote"});q(sa.node,{displayName:"NodeSchema<footnodeDef>",group:"footnote"});var no="footnote_reference",aa=Ee("footnote_reference",()=>({group:"inline",inline:!0,atom:!0,attrs:{label:{default:"",validate:"string"}},parseDOM:[{tag:`sup[data-type="${no}"]`,getAttrs:e=>{if(!(e instanceof HTMLElement))throw rt(e);return{label:e.dataset.label}}}],toDOM:e=>{const t=e.attrs.label;return["sup",{"data-label":t,"data-type":no},t]},parseMarkdown:{match:({type:e})=>e==="footnoteReference",runner:(e,t,n)=>{e.addNode(n,{label:t.label})}},toMarkdown:{match:e=>e.type.name===no,runner:(e,t)=>{e.addNode("footnoteReference",void 0,void 0,{label:t.attrs.label,identifier:t.attrs.label})}}}));q(aa.ctx,{displayName:"NodeSchemaCtx<footnodeRef>",group:"footnote"});q(aa.node,{displayName:"NodeSchema<footnodeRef>",group:"footnote"});var la=ht.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 rt(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(la.node,{displayName:"NodeSchema<taskListItem>",group:"ListItem"});q(la.ctx,{displayName:"NodeSchemaCtx<taskListItem>",group:"ListItem"});var Bc=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(Bc,{displayName:"InputRule<wrapInTaskListInputRule>",group:"ListItem"});var Gh=[ea,oa].flat(),Yh=[Oc,Bc],Xh=[Zs],Jh=[Pc],Kc=Z(()=>Fh);q(Kc,{displayName:"Prose<autoInsertSpanPlugin>",group:"Prose"});var Qh=Z(()=>Sh({}));q(Qh,{displayName:"Prose<columnResizingPlugin>",group:"Prose"});var jc=Z(()=>Dh({allowTableNodeSelection:!0}));q(jc,{displayName:"Prose<tableEditingPlugin>",group:"Prose"});var Ot=xe("remarkGFM",()=>Vo);q(Ot.plugin,{displayName:"Remark<remarkGFMPlugin>",group:"Remark"});q(Ot.options,{displayName:"RemarkConfig<remarkGFMPlugin>",group:"Remark"});var Zh=new fe("MILKDOWN_KEEP_TABLE_ALIGN_PLUGIN");function eg(e,t){let n=0;return t.forEach((r,o,s)=>{r===e&&(n=s)}),n}var Hc=Z(()=>new te({key:Zh,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=eg(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(Hc,{displayName:"Prose<keepTableAlignPlugin>",group:"Prose"});var tg=[Hc,Kc,Ot,jc].flat(),ng=[la,dt,qn,ln,en,Wn,sa,aa,Qs,an].flat(),rg=[na,ta,ra,Mc,Ac,Nc,Ec,Tc,Ic,Lc,Dc,_c,Rc,$c,zc,Nn],og=[ng,Yh,Jh,Xh,Gh,rg,tg].flat();function sg(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 ag=1,lg=2,Ao=e=>`&#x${e.toString(16).toUpperCase()};`,ia=e=>e>=55296&&e<=57343,br=e=>!Number.isNaN(e)&&!ia(e)&&wi(e)&&Go(e)===void 0;function wl(e,t,n){return t===126||t===95?!0:t===42?Eo(e,n)!=="punct":!1}function xl(e,t){const n=Go(t);return n===ag?{inside:!0,outside:br(e)}:n===lg?{inside:!1,outside:br(e)}:{inside:!1,outside:!1}}const Fc=/(?:https?:\/\/|www\.)[^\s<]*$/i,qc=/^(?:https?:\/\/|www\.)/i,Wc=(e,t,n)=>e?.children?.[t.indexStack[t.indexStack.length-1]+n],Uc=(e,t)=>{const n=Wc(e,t,-1);return n?.type==="text"&&(n.value.charAt(n.value.length-2)==="\\"||Fc.test(n.value))},Vc=(e,t)=>{const n=Wc(e,t,1);return n?.type==="text"&&qc.test(n.value)},ca=new Set(["delete","strong","emphasis"]),tn=e=>Array.isArray(e?.children)&&e.children.every(t=>t.type==="text"?!t.value:ca.has(t.type)&&tn(t));let Pt=!1;function ig(e){Pt=!0;try{return e()}finally{Pt=!1}}const vl={inside:!1,outside:!1},Gc=(e,t,n,r)=>{if(tn(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=Pt?vl:xl(r.before.charCodeAt(r.before.length-1),i);c.inside&&(l=Ao(i)+l.slice(1));const u=l.charCodeAt(l.length-1),d=Pt?vl:xl(r.after.charCodeAt(0),u);d.inside&&(l=l.slice(0,-1)+Ao(u));const f=o.move("~~");return s(),n.attentionEncodeSurroundingInfo={after:d.outside&&!Vc(t,n),before:c.outside&&!Uc(t,n)},a+l+f};Gc.peek=e=>tn(e)?"":"~";function Yc(e){const t=(n,r,o,s)=>{if(tn(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&&(Pt||wl(n,c,!1)||Uc(r,o)||!br(s.before.charCodeAt(s.before.length-1)))&&(l.before=!1),l.after&&(Pt||wl(n,u,!0)||Vc(r,o)||!br(s.after.charCodeAt(0)))&&(l.after=!1)}return a};return t.peek=(n,r,o)=>tn(n)?"":e.peek(n,r,o),t}const cg=Yc(Qt.strong),ug=Yc(Qt.emphasis);function dg(e){const t=[];for(const n of e.children){const r=t[t.length-1];r&&ca.has(n.type)&&n.type===r.type?r.children=[...r.children,...n.children]:t.push(n)}return t}const No=new Set(["strong","emphasis"]),Xc=e=>e.type==="text"?!e.value:ca.has(e.type)&&tn(e);function Jc(e,t){let n=e;for(;;){const r=n.children??[];let o=t?r.length-1:0;for(;o>=0&&o<r.length&&Xc(r[o]);)o+=t?-1:1;if(o<0||o>=r.length)return null;if(!No.has(r[o].type))return{host:n,index:o};n=r[o]}}function Eo(e,t){const n=Jc(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(Go(s)!==void 0)return"punct";const a=t?o.codePointAt(o.length-(o.length>1&&ia(s)?2:1)):o.codePointAt(0);return!wi(a)||(t?Fc.test(o):qc.test(o))?"ok":"letter"}function Cl(e,t){const n=Jc(e,t);if(!n)return!1;const r=n.host.children,o=r[n.index].value,s=t?o.length-(o.length>1&&ia(o.charCodeAt(o.length-1))?2:1):0,a=o.codePointAt(s),l=[{type:"text",value:o.slice(0,s)},{type:To,value:Ao(a)},{type:"text",value:o.slice(s+(a>65535?2:1))}];return r.splice(n.index,1,...l.filter(i=>i.type===To||i.value)),!0}const To="amadeusCharRef",Qc=e=>e.value;Qc.peek=()=>"&";function Zc(e){if(Array.isArray(e?.children)){e.children=dg(e);for(let t=!Pt;t;){t=!1;const n=e.children.filter(r=>!Xc(r));for(let r=1;r<n.length;r++){const[o,s]=[n[r-1],n[r]];if(!No.has(o.type)||!No.has(s.type))continue;const a=Eo(o,!0),l=Eo(s,!1);if(a==="letter"&&l==="punct"?t=Cl(o,!0):a==="punct"&&l==="letter"&&(t=Cl(s,!1)),t)break}}for(const t of e.children)Zc(t)}}const fg=(e,t,n,r)=>(Zc(e),Qt.root(e,t,n,r)),pg=sg,mg={root:fg,text:pg,delete:Gc,strong:cg,emphasis:ug,[To]:Qc},hg=zn(e=>{e.update(Ht,t=>({...t,handlers:{...t.handlers,...mg}}))});function gg(){yf.call(this),kf.call(this,{singleTilde:!1})}const bg=xe("amadeusCjkFriendly",()=>gg),En="amadeusU",Tn="amadeusFg",In="amadeusBg",ua="amadeusKbd",da="amadeusSub",fa="amadeusSup",pa=new Map([["kbd",ua],["sub",da],["sup",fa]]),yr=e=>/^(#[0-9a-fA-F]{3,8}|rgba?\([\d.,%\s/]+\)|hsla?\([\d.,%\s/]+\)|[a-zA-Z]+|var\(--[\w-]+\))$/.test(e.trim());function eu(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<u>$/i.test(t))return{type:En};const n=/^<([a-z]+)>$/.exec(t),r=n&&pa.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 yr(s)?{type:Tn,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&&!yr(s)?null:{type:In,bg:s}}return null}function tu(e){if(e?.type!=="html"||typeof e.value!="string")return null;const t=e.value.trim();if(/^<\/u>$/i.test(t))return En;if(/^<\/span>$/i.test(t))return Tn;if(/^<\/mark>$/i.test(t))return In;const n=/^<\/([a-z]+)>$/.exec(t);return n&&pa.get(n[1])||null}const yg=16,Sl=new Set(pa.values()),kg=new Set(["paragraph","heading","tableCell"]);function wg(e){const t=new Map,n=new Set,r=o=>{for(const s of o){const a=eu(s)?.type;if(a&&Sl.has(a)){const i=(t.get(a)??0)+1;t.set(a,i),i>1&&n.add(a);continue}const l=tu(s);if(l&&Sl.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 nu(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=eu(s),l=a&&!t.has(a.type)?a:null,i=tu(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>=yg)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=kg.has(s.type)?new Set([...t,...wg(s.children)]):t;s.children=nu(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 qt(e,t){const n=(r,o,s,a)=>{const l=s.createTracker(a),i=s.enter("emphasis");let c=l.move(e(r));return c+=s.containerPhrasing(r,{...a,before:">",after:"<"}),c+=l.move(t),i(),c};return n.peek=()=>"<",n}function xg(){const e=this.data();return(e.toMarkdownExtensions||=[]).push({handlers:{[En]:qt(()=>"<u>","</u>"),[Tn]:qt(n=>`<span style="color:${n.color}">`,"</span>"),[In]:qt(n=>n.bg?`<mark style="background:${n.bg}">`:"<mark>","</mark>"),[ua]:qt(()=>"<kbd>","</kbd>"),[da]:qt(()=>"<sub>","</sub>"),[fa]:qt(()=>"<sup>","</sup>")}}),n=>{Array.isArray(n?.children)&&(n.children=nu(n.children))}}const vg=xe("amadeusInlineHtmlMarks",()=>xg),ru=st("amadeusUnderline",()=>({parseDOM:[{tag:"u"}],toDOM:()=>["u",0],parseMarkdown:{match:e=>e.type===En,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,En)}}}));function ma(e,t,n){return st(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 Cg=ma("amadeusKbd","kbd",ua),Sg=ma("amadeusSub","sub",da),Mg=ma("amadeusSup","sup",fa),ha={"#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"},ga={"#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 ou(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 su=e=>{const t={};for(const[n,r]of Object.entries(e))r in t||(t[r]=n);return t},Ag=su(ha),Ng=su(ga),au=(e,t,n,r)=>{const o=ou(r);return o&&e[o]&&(!n||e[o]===n)?o:n&&t[n]?t[n]:null};function Eg(e){const t=e.getAttribute("data-amx-fg");if(t&&yr(t))return{color:t};if(!e.style.color)return!1;const n=au(ha,Ag,e.getAttribute("data-hlc"),e.style.color);return n?{color:n}:!1}function Tg(e){const t=e.getAttribute("data-amx-bg");return t!==null&&(t===""||yr(t))?{bg:t}:{bg:au(ga,Ng,e.getAttribute("data-hl"),e.style.backgroundColor)??""}}const lu=(e,t)=>e[ou(t)??t.toLowerCase()],Io=st("amadeusColor",()=>({attrs:{color:{default:""}},parseDOM:[{tag:'span[style*="color"]',getAttrs:e=>Eg(e)}],toDOM:e=>{const t=String(e.attrs.color),n=lu(ha,t);return["span",{style:`color:${t}`,"data-amx-fg":t,...n?{"data-hlc":n}:{}},0]},parseMarkdown:{match:e=>e.type===Tn,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,Tn,void 0,{color:t.attrs.color})}}})),Lo=st("amadeusBg",()=>({attrs:{bg:{default:""}},parseDOM:[{tag:"mark",getAttrs:e=>Tg(e)}],toDOM:e=>{const t=String(e.attrs.bg);if(!t)return["mark",{"data-amx-bg":""},0];const n=lu(ga,t);return["mark",{style:`background:${t}`,"data-amx-bg":t,...n?{"data-hl":n}:{}},0]},parseMarkdown:{match:e=>e.type===In,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,In,void 0,{bg:t.attrs.bg})}}})),ro=F("AmadeusToggleUnderline",e=>()=>_n(ru.type(e)));function iu(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 cu(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 Ml=F("AmadeusApplyColor",e=>t=>t?iu(Io.type(e),{color:t}):cu(Io.type(e))),Al=F("AmadeusApplyBg",e=>t=>t?iu(Lo.type(e),{bg:t}):cu(Lo.type(e)));De({"obsinline.comment.title":{zh:"注释(点击编辑)",en:"Comment (click to edit)"}});function uu(e){if(e.indexOf("%%")===-1&&e.indexOf("==")===-1)return[];let t=e;for(const o of Ki(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 yt=new fe("amadeus-obsidian-inline");function Ig(e,t){const n=document.createElement("span");return n.className="amx-obs-cmt-badge",n.contentEditable="false",n.textContent="%%",n.title=D("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(K.create(e.state.doc,o)).setMeta(yt,{focus:!0})),e.focus()}),n}function Lg(e){const t=yt.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 uu(Lr(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=>Ig(m,u+2),{side:-1,ignoreSelection:!0,key:`obs-cmt:${u}`})))}return!1}),o.length?pe.create(e.doc,o):pe.empty}function Rg(){return Z(()=>new te({key:yt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(yt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{handleDOMEvents:{focus:e=>(yt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(yt,{focus:!0})),!1),blur:e=>(yt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(yt,{focus:!1})),!1)},decorations:e=>Lg(e)}}))}const $g=(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=uu(Lr(n.parent)).find(p=>p.kind==="hl"&&l+p.from<=o&&s<=l+p.to);if(i)return t?.(e.tr.delete(l+i.to-2,l+i.to).delete(l+i.from,l+i.from+2)),!0;if(a)return!0;const c=e.doc.textBetween(o,s,`
|
|
4
|
-
`,"");if(c.includes(`
|
|
5
|
-
`))return!0;const u=o+(c.length-c.trimStart().length),d=s-(c.length-c.trimEnd().length);if(d<=u)return!0;const f=e.schema.text("=="),m=e.tr.insert(d,f).insert(u,f);return m.setSelection(K.create(m.doc,u+2,d+2)),t?.(m),!0},Nl=e=>e?.type==="break",Dg=/^(?:\s*<br\b[^>]*>)+/i;function Ro(e){if(e?.type!=="html"||typeof e.value!="string")return{count:0,rest:""};const t=Dg.exec(e.value);return t?{count:(t[0].match(/<br\b/gi)??[]).length,rest:e.value.slice(t[0].length)}:{count:0,rest:""}}const du=e=>{const t=e.replace(/^\n+/,"");return t&&!t.includes("<")?t:null};function fu(e){const t=Array.isArray(e?.children)?e.children:[];if(!t.some(a=>Nl(a)||Ro(a).count>0||a?.type==="text"&&typeof a.value=="string"&&a.value.includes(`
|
|
6
|
-
`)))return[e];const r=[[]],o=a=>{r[r.length-1].push(a)};for(const a of t){if(Nl(a)){r.push([]);continue}const l=Ro(a);if(l.count>0){for(let c=0;c<l.count;c++)r.push([]);const i=du(l.rest);i?o({type:"text",value:i}):l.rest.trim()&&o({...a,value:l.rest});continue}if(a?.type==="text"&&typeof a.value=="string"&&a.value.includes(`
|
|
7
|
-
`)){a.value.split(`
|
|
8
|
-
`).forEach((c,u)=>{u>0&&r.push([]),c&&o({...a,value:c})});continue}o(a)}for(;r.length&&r[0].length===0;)r.shift();for(;r.length&&r[r.length-1].length===0;)r.pop();const s=e?.data?.amadeusRaw;if(typeof s=="string"&&r.length>1){const a=s.split(`
|
|
9
|
-
`);return r.map((l,i)=>({...e,children:l,data:{...e.data,amadeusRaw:a.length===r.length?a[i]:void 0}}))}return r.map(a=>({...e,children:a}))}function pu(e){if(!e.includes("<br"))return e;const t=e.split(`
|
|
10
|
-
`);let n=null;for(let r=0;r<t.length;r++){const o=/^ {0,3}(`{3,}|~{3,})/.exec(t[r]);if(o){const a=o[1][0];n?a===n&&(n=null):n=a;continue}if(n)continue;const s=/^(\s*(?:(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?|>\s?)*)<br\s*\/?>\s*$/i.exec(t[r]);if(s){const a=s[1].replace(/\s+$/,"");t[r]=/\[[ xX]\]$/.test(a)?`${a} `:a}}return t.join(`
|
|
11
|
-
`)}function _g(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 mu(e){if(!Array.isArray(e?.children))return;const t=[];let n=null;for(const r of e.children){for(let s=0;s<_g(n,r);s++)t.push({type:"paragraph",children:[]});if(n=r,r?.type==="paragraph"){t.push(...fu(r));continue}const o=Ro(r);if(o.count>0){for(let a=0;a<o.count;a++)t.push({type:"paragraph",children:[]});const s=du(o.rest);s?t.push({type:"paragraph",children:[{type:"text",value:s}]}):o.rest.trim()&&t.push({...r,value:o.rest});continue}mu(r),t.push(r)}e.children=t}const zg=(e,t)=>e?.type==="paragraph"&&t?.type==="paragraph"?0:void 0,Og=e=>Math.max(0,Math.floor((e-1)/2)),Pg=e=>Math.max(0,Math.floor(e/2)),Bg=e=>Math.max(0,Math.floor((e+1)/2));function mn(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 Kg(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=mn(e,"start"),a=mn(t[0],"start");s!=null&&a!=null&&r(o,Pg(a-s));let l=null;for(const c of t){const u=mn(c,"start");l!=null&&u!=null&&r(o,Og(u-l-1)),o.push(c),l=mn(c,"end")}const i=mn(e,"end");i!=null&&l!=null&&r(o,Bg(i-l-1)),e.children=o}const jg=xe("amadeusBlankLine",()=>()=>e=>Kg(e)),Hg=xe("amadeusSoftBreak",()=>function(){const t=this.data();return(t.toMarkdownExtensions||=[]).push({join:[zg]}),r=>mu(r)});function Fg(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 B0=xe("amadeusHardBreak",()=>()=>e=>Fg(e)),qg=/^[-*+]$/,Xt=e=>typeof e=="string"&&qg.test(e)?e:null;function Wg(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 Ug=xe("amadeusListBullet",()=>()=>(e,t)=>Wg(e,String(t?.value??""))),El=e=>e===!0||e==="true";function Vg(e,t,n,r){const o=El(e.spread);e.spread=o;for(const l of Array.isArray(e.children)?e.children:[])l?.type==="listItem"&&(l.spread=El(l.spread)&&o);const s=e.ordered?null:Xt(e.amadeusBullet);if(!s)return Qt.list(e,t,n,r);const a=n.options.bullet;n.options.bullet=s;try{return Qt.list(e,t,n,r)}finally{n.options.bullet=a}}const Gg=zn(e=>{e.update(Ht,t=>({...t,handlers:{...t.handlers,list:Vg}}))}),Yg=[Ug,Gg].flat(),Ie=e=>Math.max(0,Math.min(xi,Math.floor(e)||0)),Xg=/^<!-- amadeus-indent:([1-8]) -->$/,Jg=new Set(["heading","blockquote","list"]);function hu(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"?Xg.exec(s.value.trim()):null;if(a&&o&&Jg.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}hu(r)}}const Qg=xe("amadeusStructuralIndent",()=>()=>e=>hu(e)),Fr=e=>Ie(Number(e.data?.amadeusIndent??0)),qr=e=>`<!-- amadeus-indent:${Ie(e)} -->`,Tl=St.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},indent:{default:0}},parseDOM:[{tag:"blockquote",getAttrs:r=>({indent:Ie(Number(r.dataset.indent))})}],toDOM:r=>{const o=Ie(r.attrs.indent);return["blockquote",{...t.get(Br.key)(r),...o?{"data-indent":o}:{}},0]},parseMarkdown:{match:n.parseMarkdown.match,runner:(r,o,s)=>{r.openNode(s,{indent:Fr(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Ie(o.attrs.indent);s&&r.addNode("html",void 0,qr(s)),n.toMarkdown.runner(r,o)}}}}),Il=ft.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:Ie(Number(r.dataset.indent)),bullet:Xt(r.dataset.bullet)})}],toDOM:r=>{const o=Ie(r.attrs.indent),s=Xt(r.attrs.bullet);return["ul",{...t.get(Kr.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:Fr(o),bullet:Xt(o.data?.amadeusBullet)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Ie(o.attrs.indent);s&&r.addNode("html",void 0,qr(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()}}}}),Ll=pt.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:Ie(Number(r.dataset.indent))})}],toDOM:r=>{const o=Ie(r.attrs.indent);return["ol",{...t.get(jr.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:Fr(o)}).next(o.children).closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(r,o)=>{const s=Ie(o.attrs.indent);s&&r.addNode("html",void 0,qr(s)),n.toMarkdown.runner(r,o)}}}}),$o=new Set(["heading","blockquote","bullet_list","ordered_list"]);function gu(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"&&!$o.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=Ie(Number(l.attrs.indent??0)),d=Ie(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 Ue&&$o.has(e.selection.node.type.name)){const o=e.selection.node,s=e.selection.from,a=Ie(Number(o.attrs.indent??0)+r);return a!==Ie(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(!$o.has(s.type.name))continue;const a=n.before(o),l=Ie(Number(s.attrs.indent??0)+r);return l!==Ie(Number(s.attrs.indent??0))&&t?.(e.tr.setNodeMarkup(a,void 0,{...s.attrs,indent:l}).scrollIntoView()),!0}return!1}const bu=/^<br\b[^<>]*>$/i,Zg=e=>e!=null&&bu.test(e)?e:null,eb=new Set(["root","blockquote","listItem","footnoteDefinition"]);function tb(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 nb(e){const t=n=>{const r=n?.children;if(!Array.isArray(r))return;const o=!eb.has(n.type);for(let s=0;s<r.length;s++){const a=r[s];if(o&&a?.type==="html"&&typeof a.value=="string"&&bu.test(a.value)&&!tb(r,s)){r[s]={type:"break",data:{amadeusBr:a.value},position:a.position};continue}t(a)}};t(e)}const rb=xe("amadeusInlineBr",()=>()=>e=>nb(e)),Rl=Ge.extendSchema(e=>t=>{const n=e(t);return{...n,attrs:{...n.attrs??{},html:{default:null}},parseDOM:[{tag:"br[data-md-br]",getAttrs:r=>({html:Zg(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)}}}}),yu=e=>e.lastChild?.type.name==="hardbreak"&&typeof e.lastChild.attrs.html=="string",ob=Z(e=>new te({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=Ge.type(e);if(o.getMeta("hardbreak"))return s instanceof Ii?r.tr.setNodeMarkup(s.from,a,void 0,[]):null;if(s instanceof Li){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}})),oo=e=>String(e??"").toUpperCase();function sb(e,t){const n=e?.position?.start,r=e?.position?.end;if(typeof n?.offset!="number"||typeof r?.offset!="number")return null;const o=t.slice(n.offset,r.offset);if(n.column<=1||!o.includes(`
|
|
12
|
-
`))return o;const s=new RegExp(`^[ \\t>]{0,${n.column-1}}`);return o.split(`
|
|
13
|
-
`).map((a,l)=>l?a.replace(s,""):a).join(`
|
|
14
|
-
`)}const ab=e=>`[${e.label??e.identifier}]: ${e.url}${e.title?` "${e.title}"`:""}`;function lb(e,t,n){const r=e[0].position?.start,o=e[e.length-1].position?.end;let s;if(t?.type==="root"&&typeof r?.offset=="number"&&typeof o?.offset=="number"){let l=r.offset;for(;l>0&&(n[l-1]===" "||n[l-1]===" ");)l--;l>0&&n[l-1]!==`
|
|
15
|
-
`&&(l=r.offset),s=n.slice(l,o.offset)}else s=e.map(l=>sb(l,n)??ab(l)).join(`
|
|
16
|
-
`);s=s.replace(/\r\n?/g,`
|
|
17
|
-
`);const a=[];return s.split(`
|
|
18
|
-
`).forEach((l,i)=>{i&&a.push({type:"break"}),l&&a.push({type:"text",value:l})}),{type:"paragraph",children:a,data:{amadeusRaw:s},...r&&o?{position:{start:r,end:o}}:{}}}function ib(e,t){const n=new Map,r=s=>{if(s?.type==="definition"){const a=oo(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(lb(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(oo(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(oo(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 cb=xe("amadeusRefDefinitions",()=>()=>(e,t)=>ib(e,String(t?.value??""))),$l=e=>e.replace(/[\t ]+(?=\n|$)/g,"");function Do(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&&$l(e.textContent)===$l(t)?t:null}const ub=/^[ \t]{0,3}(\[((?:[^\\[\]]|\\[\s\S])+)\]:)/;let Dl=null;const db=e=>{Dl??=vi().use(Ci).use(Vo);const t=Dl.parse(e)?.children??[];return t.length>0&&t.every(n=>n?.type==="definition")},fb=e=>e==null||!ub.test(e.split(`
|
|
19
|
-
`)[0])||/(?:^|\n)[ \t\r]*(?:\n|$)/.test(e)?null:db(e)?e:null,pb=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}},_l=Ve.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:pb(o.getAttribute("data-md-ref"))}}}],toDOM:r=>{const{ref:o,...s}=r.attrs;return["a",{...t.get(_r.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 Un(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=>Un(ot(/(?:^|[^*])\*([^*]+)\*$/,At.type(e),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("*")?{}:{fullMatch:t.slice(1),start:n+1}}))),hb=/\b_(?![_\s])([^_]*[^_\s])_$/,gb=ue(e=>Un(ot(hb,At.type(e),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:t,start:n})=>t.startsWith("_")?{}:{fullMatch:t.slice(1),start:n+1}}))),bb=ue(e=>Un(ot(/(?:`)([^`]+)(?:`)$/,ut.type(e)))),yb=new RegExp("(?:(?<![:/])\\*\\*(?=[^*_]+?\\*\\*$)|(?<![\\w:/])__(?=[^*_]+?__$))([^*_]+?)(?:\\*\\*|__)$"),kb=ue(e=>Un(ot(yb,on.type(e),{getAttr:t=>({marker:t[0].startsWith("*")?"*":"_"})}))),wb=new RegExp("(?<![\\w:/~])(~~)([^\\s~](?:[^~]*[^\\s~])?)~~$"),xb=ue(e=>Un(ot(wb,an.type(e)))),vb=e=>(e.inject(Ot.options.key,{singleTilde:!1}),()=>()=>{e.remove(Ot.options.key)});function Cb(){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 Sb=xe("amadeusStrictTildeUnsafe",()=>Cb),zl=new Map([[as,mb],[ls,gb],[ps,bb],[us,kb]]),Mb=og.flatMap(e=>e===Zs?[xb]:e===Ot.options?[vb]:e===Ot.plugin?[e,...Sb]:[e]),vn=new WeakMap,so=e=>!/\S/.test(e);function Ab(e,t){let n=t;for(;n>0&&e[n-1]!==`
|
|
20
|
-
`;)n--;const r=e.slice(n,t);return r?/^ {1,3}$/.test(r)?n:null:t}function Nb(e,t){let n=t;for(;n<e.length&&(e[n]===" "||e[n]===" ");)n++;return n===e.length||e[n]===`
|
|
21
|
-
`?n:t}const Eb=/!\[(?!\[)[^\]\n]*\](?!\()/;function Tb(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 Ib=e=>e?.type==="html"||e?.type==="paragraph"&&e.children?.length===1&&e.children[0]?.type==="html";function Lb(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=Ab(e,h),k=g??h,y=Nb(e,m);o.from[u]=k,o.to[d]=y,g==null&&(o.sealBefore[u]=!0),a=y;const v=e.slice(k,y),E=c.md;(y===e.length||so(e.slice(y)))&&(E?.type==="code"&&/^[ \t]*(`{3,}|~{3,})/.test(v)||Ib(E))&&(o.eofOpen[d]=!0),/^[ \t]/.test(v)&&(o.indentStart[u]=!0);let S=!1,N=Eb.test(v);for(const C of c.made){const _=Tb(C);S||=_.def,N||=_.link}for(let C=u;C<=d;C++)o.def[C]=S,o.ref[C]=N}let l=null,i=0;for(let c=0;c<r;c++){const u=o.from[c];u!=null&&!so(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&&!so(e.slice(i))&&(o.sealAfter[l]=!0),n.forEach((c,u)=>vn.set(c,{src:o,idx:u}))}function Rb(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&&Lb(o,s,r.content)}const $b=xe("amadeusVerbatimSource",()=>()=>(e,t)=>{e.data={...e.data,amadeusSource:String(t?.value??"")}});function Db(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 kr(e,t){if(e===t)return!0;if(e.type!==t.type||!wf.sameSet(e.marks,t.marks))return!1;if(e.isText)return e.text===t.text;if(!Db(e,t)||e.childCount!==t.childCount)return!1;for(let n=0;n<e.childCount;n++)if(!kr(e.child(n),t.child(n)))return!1;return!0}const _o=e=>e.type.name==="bullet_list"||e.type.name==="ordered_list",_b=e=>_o(e)||e.type.name==="footnote_definition",Ol=e=>e.type.name==="paragraph"&&e.content.size===0;function zb(e){let t=e.type.name==="paragraph"&&Do(e)!=null;return e.descendants(n=>(!t&&n.type.name==="paragraph"&&Do(n)!=null&&(t=!0),!t)),t}function Ob(e){const t=e.childCount;if(!t)return null;const n=[];e.forEach(p=>{n.push(p)});const r=n.map(p=>vn.get(p)??null);if(!r.some(Boolean))return null;const o=(p,h,g)=>{if(r[p]||!h)return;const k=h.idx+g;k>=0&&k<h.src.nodes.length&&kr(n[p],h.src.nodes[k])&&(r[p]={src:h.src,idx:k})};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&&kr(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 k=new Set;return r.forEach((y,v)=>{if(!y){zb(n[v])&&(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,k.add(y.idx))}),p.def.forEach((y,v)=>{y&&!k.has(v)&&(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 S=0;S<t;S++){if(!d[S])continue;const N=S;for(;S+1<t&&d[S+1]&&r[S+1].src===r[N].src&&r[S+1].idx===r[S].idx+1;)S++;h.push([N,S])}let g=!1;for(const[S,N]of h){const C=r[S].src,_=f(S)||C.from[r[S].idx]!=null&&!C.sealBefore[r[S].idx],O=m(N)||C.to[r[N].idx]!=null&&!C.sealAfter[r[N].idx];_||(d[S]=!1,g=!0),O||(d[N]=!1,g=!0)}if(g)continue;const k=S=>{let N=S-1;for(;N>=0&&Ol(n[N]);)N--;return N},y=S=>{let N=S+1;for(;N<t&&Ol(n[N]);)N++;return N};for(const[S,N]of h){const C=r[S].src,_=k(S);_>=0&&_o(n[S])&&n[_].type===n[S].type&&(d[S]=!1,g=!0);const O=y(N);O<t&&_o(n[N])&&n[O].type===n[N].type&&(d[N]=!1,g=!0),C.indentStart[r[S].idx]&&_>=0&&(_b(n[_])||n[S].type.name==="code_block"&&n[_].type.name==="code_block")&&(d[S]=!1,g=!0),S===0&&/^---\r?\n/.test(C.text.slice(f(0)?0:C.from[r[0].idx]??0))&&(d[0]=!1,g=!0)}if(g)continue;if(!h.length)return null;const v=h.map(([S,N])=>{const C=r[S].src;return{a:S,b:N,src:C,from:f(S)?0:C.from[r[S].idx],to:m(N)?C.text.length:C.to[r[N].idx],tail:m(N)}}),E=new Map;return v.forEach((S,N)=>E.set(S.a,N)),{doc:e,runs:v,startAt:E,nonce:Math.random().toString(36).slice(2,10)}}return null}let Cn=null;const ku=(e,t)=>`${e.nonce}:${t}`;function Pb(e,t){e.openNode("root");const n=Cn&&Cn.doc===t?Cn: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,ku(n,o)),r=n.runs[o].b}}const Bb=zn(e=>{e.update(Ht,t=>({...t,handlers:{...t.handlers,amadeusVerbatim:n=>String(n.value??"")}}))}),Kb=ts("doc",()=>({content:"block+",parseMarkdown:{match:({type:e})=>e==="root",runner:Rb},toMarkdown:{match:e=>e.type.name==="doc",runner:Pb}})),jb=[$b,Bb].flat();function Hb(e,t,n){const r=e.get(Zt);let o=null;try{o=Ob(t)}catch{o=null}if(!o)return n(r(t));Cn=o;let s;try{s=r(t)}finally{Cn=null}let l=n(s);for(let i=0;i<o.runs.length;i++){const c=ku(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 K0(e,t){const n=Math.min(e.childCount,t.childCount),r=(s,a)=>{if(s===a)return!0;if(!kr(s,a))return!1;const l=vn.get(a);return l?vn.set(s,l):vn.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 Pl="amadeusEscaped",wr="amadeusEscape",wu="\0",Fb=/[!-/:-@[-`{-~]/g,qb=/\u0000(?=[!-/:-@[-`{-~])/g;function xu(e){return e.includes(wu)?e.replace(qb,"\\"):e}function Wb(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?.[Za]:void 0;if(!l?.length){t(a),s.push(a);continue}o=!0;const{[Za]: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:wr,value:d.slice(m,h)}:{...u,value:d.slice(m,h)}),m=h}}o&&(n.children=s)};t(e)}const Ub=xe("amadeusLiteralEscape",()=>()=>Wb),Vb=st(Pl,()=>({inclusive:!1,priority:100,parseDOM:[{tag:"span[data-amx-esc]"}],toDOM:()=>["span",{"data-amx-esc":""},0],parseMarkdown:{match:e=>e.type===wr,runner:(e,t,n)=>{e.openMark(n),e.addText(String(t.value??"")),e.closeMark(n)}},toMarkdown:{match:e=>e.type.name===Pl,runner:(e,t,n)=>(e.addNode(wr,void 0,n.text??""),!0)}})),vu=e=>String(e.value??"").replace(Fb,t=>wu+t);vu.peek=()=>"\\";const Gb=zn(e=>{e.update(Ht,t=>({...t,handlers:{...t.handlers,[wr]:vu}}))}),Yb=[Vb,Gb].flat(),Ze=e=>Math.max(0,Math.min(xi,Math.floor(e)||0)),Xb=/^<span data-amadeus-align="(left|center|right)"><\/span>$/,Jb=/^<span data-amadeus-align="(left|center|right)">$/,et=e=>e==="center"||e==="right"?e:"left",Cu=e=>`<span data-amadeus-align="${e}"></span>`,Su=e=>{const t=e?.[0];if(t?.type!=="html"||typeof t.value!="string")return{align:"left",children:e};const n=Xb.exec(t.value.trim());if(n)return{align:et(n[1]),children:e.slice(1)};const r=Jb.exec(t.value.trim()),o=e?.[1];return r&&o?.type==="html"&&o.value?.trim()==="</span>"?{align:et(r[1]),children:e.slice(2)}:{align:"left",children:e}},Bl=Pe.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:Ze(Number(r.getAttribute("data-indent"))),align:et(r.getAttribute("data-align")||r.style.textAlign),raw:fb(r.getAttribute("data-md-raw"))})}],toDOM:r=>{const o={...t.get(Or.key)(r)},s=Ze(r.attrs.indent),a=et(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=Su(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=Ze(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=Do(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=Ze(o.attrs.indent),l=et(o.attrs.align),i=yu(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,Cu(l)),a&&r.addNode("html",void 0,"	".repeat(a));const c=o.lastChild?.type.name==="hardbreak"&&!i;r.next(c?o.content.cut(0,o.content.size-o.lastChild.nodeSize):o.content),r.closeNode()}}}}),Kl=nt.extendSchema(e=>t=>{const n=e(t),r=t.get(Pn.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:et(a.getAttribute("data-align")||a.style.textAlign),indent:Ze(Number(a.dataset.indent))}}})),toDOM:o=>{const s={...t.get(Pr.key)(o),id:o.attrs.id||r(o)},a=et(o.attrs.align);a!=="left"&&(s["data-align"]=a);const l=Ze(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=Su(s.children);o.openNode(a,{level:s.depth,...l.align!=="left"?{align:l.align}:{},indent:Fr(s)}),l.children?.length&&o.next(l.children),o.closeNode()}},toMarkdown:{match:n.toMarkdown.match,runner:(o,s)=>{const a=Ze(s.attrs.indent);a&&o.addNode("html",void 0,qr(a));const l=et(s.attrs.align),i=yu(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,Cu(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()}}}}),Qb=[...rb,...Op,...Ub,...cb],Zb=_m.map(e=>e===hs?Kb:e===Pe.node?Bl.node:e===Pe.ctx?Bl.ctx:e===nt.node?Kl.node:e===nt.ctx?Kl.ctx:e===St.node?Tl.node:e===St.ctx?Tl.ctx:e===ft.node?Il.node:e===ft.ctx?Il.ctx:e===pt.node?Ll.node:e===pt.ctx?Ll.ctx:e===Ge.node?Rl.node:e===Ge.ctx?Rl.ctx:e===Ws?ob:e===Ve.mark?_l.mark:e===Ve.ctx?_l.ctx:zl.has(e)?zl.get(e):e),ey=[...Zb.flatMap(e=>e===Hr.options?[...Qb,e]:[e]),...Yg,...jb,...Yb];function Mu(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 j0(e){return e.parent.type.name!=="paragraph"?null:Mu(e)?Ze(e.parent.attrs.indent):null}function xr(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(!Mu(e.doc.resolve(i)))return!1;const c=Ze(l.attrs.indent),u=Ze(c+n);return u!==c&&(s.setNodeMarkup(i,void 0,{...l.attrs,indent:u}),a=!0),!1}),a&&t?.(s.scrollIntoView()),!0}function nr(e,t,n){const r=et(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||et(c.attrs.align)===r||(a=a.setNodeMarkup(i,void 0,{...c.attrs,align:r}),l=!0)}return l&&t?.(a.scrollIntoView()),!0}const Au=e=>{const t=e?.type.spec.tableRole;return t==="cell"||t==="header_cell"};function Nu(e){if(!Au(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=X.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 Wr(e){if(!Be(e))return null;try{return Nu(jn(e))}catch{return null}}function ba(e,t){return t<0||t>=e.content.size?null:Nu(e.resolve(t))}function H0(e,t){const n=e.resolve(t),r=_t(n);return r&&Au(r.nodeAfter)?r.pos:null}function Ur(e,t,n=!0){const r=e.nodeAt(t);if(!r)return null;const o=K.near(e.resolve(n?t+r.nodeSize-1:t+1),n?-1:1);return o instanceof K?o:null}const ya=(e,t,n,r)=>{const o=e.nodeAt(t);if(!o)return null;const s=X.get(o);return n<0||n>=s.height||r<0||r>=s.width?null:t+1+s.map[n*s.width+r]};function ka(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=X.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 F0=(e,t)=>{const n=Wr(e);if(!n)return!1;const r=e.tr;if(n.bottom>=n.map.height&&ka(r,n.tablePos,n.map.height)==null)return!1;const o=ya(r.doc,n.tablePos,n.bottom,n.col),s=o==null?null:Ur(r.doc,o);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1},q0=(e,t)=>{if(!Wr(e))return!1;const n=e.schema.nodes.hardbreak;return n?(e.selection instanceof K&&t?.(e.tr.replaceSelectionWith(n.create({html:"<br>"}),!1).scrollIntoView()),!0):!1},W0=(e,t)=>{const n=Wr(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(K.create(s.doc,o+1)).scrollIntoView()),!0},ty=(e,t)=>{const n=Wr(e);if(!n)return!1;const r=e.tr,o=ka(r,n.tablePos,n.map.height),s=o==null?null:Ur(r.doc,o+1,!1);return s?(t?.(r.setSelection(s).scrollIntoView()),!0):!1};function U0(e,t,n){const r=e.nodeAt(t);if(!r||r.type.spec.tableRole!=="table")return null;const o=n!=null?ba(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=X.get(r),a=ya(e,t,s.height-1,s.width-1);return a==null?null:{tablePos:t,cellPos:a,explicit:!1,ops:["rowBelow","colRight"],align:null}}function V0(e,t,n){const r=ba(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,ka(o,r.tablePos,l)==null)return null;break}case"colLeft":case"colRight":{i=n==="colLeft"?r.col:r.col+1,Gs(o,a,i);const d=o.doc.nodeAt(r.tablePos);if(!d)return null;const f=X.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;yc(o,a,r.row),l=Math.min(r.row,r.map.height-2);break}case"deleteCol":{if(r.map.width<=1)return null;bc(o,a,r.col),i=Math.min(r.col,r.map.width-2);break}}const c=ya(o.doc,r.tablePos,l,i),u=c==null?null:Ur(o.doc,c);return u&&o.setSelection(u),o.scrollIntoView()}function G0(e,t,n){const r=ba(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=Ur(s.doc,r.cellPos);return a&&s.setSelection(a),s.scrollIntoView()}const vr=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},Eu=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},ny=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 Tu(e,t,n){return!Xs(n)(e,t)&&n===1&&ty(e,t),!0}function Iu(e){const{$from:t,$to:n}=e.selection,r=t.parent.textContent,o=[r.lastIndexOf(`
|
|
23
|
-
`,t.parentOffset-1)+1];for(let s=t.parentOffset;s<n.parentOffset;s++)r[s]===`
|
|
24
|
-
`&&o.push(s+1);return o.map(s=>t.start()+s)}function ry(e,t,n,r){const{$from:o,$to:s}=e.selection;if(o.parent.type.name==="code_block"){if(!o.sameParent(s))return!0;if(!e.selection.empty&&o.parent.textContent.slice(o.parentOffset,s.parentOffset).includes(`
|
|
25
|
-
`)){const a=e.tr;for(const l of Iu(e).reverse())a.insertText(" ",l,l);return t?.(a.scrollIntoView()),!0}return t?.(e.tr.insertText(" ",o.pos,s.pos)),!0}if(Eu(e))return Tu(e,t,1);if(!e.selection.empty&&!o.sameParent(s)&&!vr(e)&&gu(e,t,1))return!0;if(vr(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 Vi(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:xr(e,t,1):e.selection instanceof Ue&&e.selection.node.type.name==="paragraph"?xr(e,t,1):($t(e,t,o,1),!0)}function oy(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 Iu(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(Eu(e))return Tu(e,t,-1);if(!e.selection.empty&&!n.sameParent(r)&&!vr(e)&&gu(e,t,-1))return!0;if(vr(e)){const o=e.schema.nodes.list_item;if(ny(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?Qo(s):null;if(s&&a!=null)return t?.(e.tr.lift(s,a).scrollIntoView()),!0}return Ui(o)(e,t)||$t(e,t,n,-1),!0}return n.parent.type.name==="paragraph"?$t(e,t,n,-1)?!0:xr(e,t,-1):e.selection instanceof Ue&&e.selection.node.type.name==="paragraph"?xr(e,t,-1):($t(e,t,n,-1),!0)}function zo(e){if(!e)return!1;if(Array.isArray(e))return e.length>1?!1:zo(e[0]);const t=e.content;return t?zo(t):e.type==="text"}function sy(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-clipboard",...t}}),e}function jl(e,t){const n=Cf(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 Lu=Z(e=>{const t=e.get(xf);return e.update(Di,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 te({key:new fe("MILKDOWN_CLIPBOARD"),props:{handlePaste:(n,r,o)=>{const s=e.get(fr),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=vf("code_block",t);return p.replaceSelectionWith(h.create({language:m})).setSelection(K.near(p.doc.resolve(Math.max(0,p.selection.from-2)))).insertText(i.replace(/\r\n?/g,`
|
|
26
|
-
`)),n.dispatch(p),!0}}const u=l.getData("text/html");if(u.length===0&&i.length===0)return!1;if(u.length>0&&o)return jl(n,o);const d=_i.fromSchema(t);let f;if(u.length===0){const m=s(i);if(!m||typeof m=="string")return!1;f=zi.fromSchema(t).serializeFragment(m.content)}else{const m=document.createElement("template");m.innerHTML=u,f=m.content.cloneNode(!0),m.remove()}return jl(n,d.parseSlice(f))},clipboardTextSerializer:n=>{const r=e.get(Zt);if(zo(n.content.toJSON()))return n.content.textBetween(0,n.content.size,`
|
|
27
|
-
|
|
28
|
-
`);const o=t.topNodeType.createAndFill(void 0,n.content);return o?r(o):""}}})});sy(Lu,{displayName:"Prose<clipboard>"});var Cr=200,Ne=function(){};Ne.prototype.append=function(t){return t.length?(t=Ne.from(t),!this.length&&t||t.length<Cr&&this.leafAppend(t)||this.length<Cr&&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 ay(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 Ru(t):Ne.empty};var Ru=(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<=Cr)return new t(this.values.concat(o.flatten()))},t.prototype.leafPrepend=function(o){if(this.length+o.length<=Cr)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 Ru([]);var ay=(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 ly=500;class We{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 Je(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 Je(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 We(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 Je(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>cy&&(l=iy(l,c),a-=c),new We(l.append(s),a)}remapping(t,n){let r=new Sf;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 We(this.items.append(t.map(n=>new Je(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 Je(p,h,g))}else r.push(new Je(p))},o);let c=[];for(let f=n;f<a;f++)c.push(new Je(s.maps[f]));let u=this.items.slice(0,o).append(c).append(r),d=new We(u,l);return d.emptyItemCount()>ly&&(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 Je(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 We(Ne.from(o.reverse()),s)}}We.empty=new We(Ne.empty,0);function iy(e,t){let n;return e.forEach((r,o)=>{if(r.selection&&t--==0)return n=o,!1}),e.slice(n)}class Je{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 Je(n.getMap().invert(),n,this.selection)}}}class kt{constructor(t,n,r,o,s){this.done=t,this.undone=n,this.prevRanges=r,this.prevTime=o,this.prevComposition=s}}const cy=20;function uy(e,t,n,r){let o=n.getMeta(tt),s;if(o)return o.historyState;n.getMeta($u)&&(e=new kt(e.done,e.undone,null,0,-1));let a=n.getMeta("appendedTransaction");if(n.steps.length==0)return e;if(a&&a.getMeta(tt))return a.getMeta(tt).redo?new kt(e.done.addTransform(n,void 0,r,lr(t)),e.undone,Hl(n.mapping.maps),e.prevTime,e.prevComposition):new kt(e.done,e.undone.addTransform(n,void 0,r,lr(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||!dy(n,e.prevRanges)),c=a?ao(e.prevRanges,n.mapping):Hl(n.mapping.maps);return new kt(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,lr(t)),We.empty,c,n.time,l??e.prevComposition)}else return(s=n.getMeta("rebased"))?new kt(e.done.rebased(n,s),e.undone.rebased(n,s),ao(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new kt(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),ao(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function dy(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 Hl(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 ao(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let o=t.map(e[r],1),s=t.map(e[r+1],-1);o<=s&&n.push(o,s)}return n}function fy(e,t,n){let r=lr(t),o=tt.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 kt(n?l:s.remaining,n?s.remaining:l,null,0,-1);return s.transform.setSelection(a).setMeta(tt,{redo:n,historyState:i})}let lo=!1,Fl=null;function lr(e){let t=e.plugins;if(Fl!=t){lo=!1,Fl=t;for(let n=0;n<t.length;n++)if(t[n].spec.historyPreserveItems){lo=!0;break}}return lo}function ql(e){return e.setMeta($u,!0)}const tt=new fe("history"),$u=new fe("closeHistory");function py(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new te({key:tt,state:{init(){return new kt(We.empty,We.empty,null,0,-1)},apply(t,n,r){return uy(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(t,n){let r=n.inputType,o=r=="historyUndo"?_u:r=="historyRedo"?zu:null;return!o||!t.editable?!1:(n.preventDefault(),o(t.state,t.dispatch))}}}})}function Du(e,t){return(n,r)=>{let o=tt.getState(n);if(!o||(e?o.undone:o.done).eventCount==0)return!1;if(r){let s=fy(o,n,e);s&&r(t?s.scrollIntoView():s)}return!0}}const _u=Du(!1,!0),zu=Du(!0,!0);function Y0(e){let t=tt.getState(e);return t?t.done.eventCount:0}function X0(e){let t=tt.getState(e);return t?t.undone.eventCount:0}function J0(e){return e.getMeta(tt)!=null}function cn(e,t){return Object.assign(e,{meta:{package:"@milkdown/plugin-history",...t}}),e}var wa=F("Undo",()=>()=>_u);cn(wa,{displayName:"Command<undo>"});var xa=F("Redo",()=>()=>zu);cn(xa,{displayName:"Command<redo>"});var va=ns({},"historyProviderConfig");cn(va,{displayName:"Ctx<historyProviderConfig>"});var Ou=Z(e=>py(e.get(va.key)));cn(Ou,{displayName:"Ctx<historyProviderPlugin>"});var Ca=_e("historyKeymap",{Undo:{shortcuts:"Mod-z",command:e=>{const t=e.get(ae);return()=>t.call(wa.key)}},Redo:{shortcuts:["Mod-y","Shift-Mod-z"],command:e=>{const t=e.get(ae);return()=>t.call(xa.key)}}});cn(Ca.ctx,{displayName:"KeymapCtx<history>"});cn(Ca.shortcuts,{displayName:"Keymap<history>"});var my=[va,Ou,Ca,wa,xa].flat(),hy=typeof global=="object"&&global&&global.Object===Object&&global,gy=typeof self=="object"&&self&&self.Object===Object&&self,Pu=hy||gy||Function("return this")(),Sr=Pu.Symbol,Bu=Object.prototype,by=Bu.hasOwnProperty,yy=Bu.toString,hn=Sr?Sr.toStringTag:void 0;function ky(e){var t=by.call(e,hn),n=e[hn];try{e[hn]=void 0;var r=!0}catch{}var o=yy.call(e);return r&&(t?e[hn]=n:delete e[hn]),o}var wy=Object.prototype,xy=wy.toString;function vy(e){return xy.call(e)}var Cy="[object Null]",Sy="[object Undefined]",Wl=Sr?Sr.toStringTag:void 0;function My(e){return e==null?e===void 0?Sy:Cy:Wl&&Wl in Object(e)?ky(e):vy(e)}function Ay(e){return e!=null&&typeof e=="object"}var Ny="[object Symbol]";function Ey(e){return typeof e=="symbol"||Ay(e)&&My(e)==Ny}var Ty=/\s/;function Iy(e){for(var t=e.length;t--&&Ty.test(e.charAt(t)););return t}var Ly=/^\s+/;function Ry(e){return e&&e.slice(0,Iy(e)+1).replace(Ly,"")}function Oo(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ul=NaN,$y=/^[-+]0x[0-9a-f]+$/i,Dy=/^0b[01]+$/i,_y=/^0o[0-7]+$/i,zy=parseInt;function Vl(e){if(typeof e=="number")return e;if(Ey(e))return Ul;if(Oo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Oo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Ry(e);var n=Dy.test(e);return n||_y.test(e)?zy(e.slice(2),n?2:8):$y.test(e)?Ul:+e}var io=function(){return Pu.Date.now()},Oy="Expected a function",Py=Math.max,By=Math.min;function Ky(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(Oy);t=Vl(t)||0,Oo(n)&&(u=!!n.leading,d="maxWait"in n,s=d?Py(Vl(n.maxWait)||0,t):s,f="trailing"in n?!!n.trailing:f);function m(N){var C=r,_=o;return r=o=void 0,c=N,a=e.apply(_,C),a}function p(N){return c=N,l=setTimeout(k,t),u?m(N):a}function h(N){var C=N-i,_=N-c,O=t-C;return d?By(O,s-_):O}function g(N){var C=N-i,_=N-c;return i===void 0||C>=t||C<0||d&&_>=s}function k(){var N=io();if(g(N))return y(N);l=setTimeout(k,h(N))}function y(N){return l=void 0,f&&r?m(N):(r=o=void 0,a)}function v(){l!==void 0&&clearTimeout(l),c=0,r=i=o=l=void 0}function E(){return l===void 0?a:y(io())}function S(){var N=io(),C=g(N);if(r=arguments,o=this,i=N,C){if(l===void 0)return p(i);if(d)return clearTimeout(l),l=setTimeout(k,t),m(i)}return l===void 0&&(l=setTimeout(k,t)),a}return S.cancel=v,S.flush=E,S}var Ku=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}},Mr=Mf(new Ku,"listener"),jy=new fe("MILKDOWN_LISTENER"),ju=e=>(e.inject(Mr,new Ku),async()=>{await e.wait(Af);const{listeners:t}=e.get(Mr);t.beforeMount.forEach(c=>c(e)),await e.wait(Nf);const n=e.get(Zt);let r=null,o=null,s=null,a=null;const l=Ky(()=>{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 te({key:jy,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(Ef,c=>c.concat(i)),await e.wait(Tf),t.mounted.forEach(c=>c(e))});ju.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};var Vr=T.createContext({});function Hy(){const{dom:e,editor:t,setLoading:n,editorFactory:r}=T.useContext(Vr),o=T.useRef(null);return T.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 Fy=()=>{const e=Hy();return Si.createElement("div",{"data-milkdown-root":!0,ref:e})},Hu=({children:e})=>{const t=T.useRef(void 0),[n,r]=T.useState(void 0),o=T.useRef(void 0),[s,a]=T.useState(!0),l=T.useMemo(()=>({loading:s,dom:t,editor:o,setLoading:a,editorFactory:n,setEditorFactory:r}),[s,n]);return Si.createElement(Vr.Provider,{value:l},e)};function qy(e,t=[]){const n=T.useContext(Vr),r=T.useCallback(e,t);return T.useLayoutEffect(()=>{n.setEditorFactory(()=>r)},[n,r]),{loading:n.loading,get:()=>n.editor.current}}function Wy(){const e=T.useContext(Vr),t=T.useCallback(()=>e.editor.current,[e.editor]);return[e.loading,t]}const Uy=Z(()=>new te({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 K)||!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(K.create(n.doc,o)),e.dispatch(d.setStoredMarks(c.removeFromSet(i))),!0}}}));function co(e){const t=/^(.*)\|(\d+)$/.exec(e);return t?{label:t[1],width:Number(t[2])}:{label:e}}function Vy(e,t){return`${e}|${t}`}class Gy{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(Ue.create(this.view.state.doc,l))),this.view.focus())};Pp(this.view,this.dom,s,a)||(s.preventDefault(),a())}),Bp(this.dom,n,()=>this.openSource()),If(this.dom,this.img,()=>co(this.node.attrs.alt??"").label||Rf(this.node.attrs.src??"")),this.apply(t)}node;view;getPos;onDestroy;dom;img;drop=null;srcLine=null;apply(t){const{label:n,width:r}=co(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=Lf(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 Ue&&n.from===t;r&&!this.dom.hasAttribute("data-selected")?this.selectNode():!r&&this.dom.hasAttribute("data-selected")&&this.deselectNode()}openSource(){if(this.srcLine){this.srcLine.focus(),this.srcLine.select();return}const t=String(this.node.attrs.src??""),n=document.createElement("input");n.className="embed-src-input amx-img-srcline",n.value=`??t})`;let r=!1;const o=s=>{if(r)return;r=!0;const a=n.value.trim();n.remove(),this.srcLine=null,s&&this.commitSource(a),this.view.focus()};n.addEventListener("keydown",s=>{s.stopPropagation(),s.key==="Enter"?(s.preventDefault(),o(!0)):s.key==="Escape"&&(s.preventDefault(),o(!1))}),n.addEventListener("blur",()=>o(!0)),this.dom.insertBefore(n,this.img),this.srcLine=n,n.focus(),n.select()}commitSource(t){const n=/^!\[([^\]]*)\]\((.*)\)$/.exec(t),r=this.getPos();if(!n||r==null)return;const o=n[2].trim();if(!o)return;const s=/^(https?:|data:|blob:)/i.test(o)?o:Mi(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}=co(this.node.attrs.alt??""),o=this.view.state.tr.setNodeMarkup(n,void 0,{...this.node.attrs,alt:Vy(r,t)});o.setSelection(Ue.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 Yy(){return Z(()=>{const e=new Set;return new te({view:()=>({update:()=>{for(const t of e)t.syncSelection()}}),props:{nodeViews:{image:(t,n,r)=>{let o;return o=new Gy(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 Jt="[!fold]-",Xy=/^\[![\w-]+\]/;function Jy(e,t){return e==="code_block"?!1:e!=="heading"||t.kind!=="ordered"}function Fu(e){return e.parent.textBetween(0,e.parentOffset,void 0,"")}const Qy={"【":"[","】":"]","》":">","|":"|","·":"`","¥":"$","#":"#"};function Zy(e){return/^\d{1,9}。$/.test(e)?`${e.slice(0,-1)}.`:e.replace(/[【】》|·¥#]/g,t=>Qy[t]??t)}function ek(e){const t=Zy(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 tk(e){const t=ek(Fu(e));return t?.kind==="fold"&&e.parentOffset<e.parent.content.size?{kind:"quote",rejoin:!0}:t}function nk(e,t,n){const r=e.state.selection.$from.start();n&&e.dispatch(e.state.tr.insertText(n)),e.dispatch(ql(e.state.tr));const o=Bt(e,t,{from:r,to:e.state.selection.from});return e.dispatch(ql(e.state.tr)),o||!!n}function Sa(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 Gl(e,t){const n=Fu(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 rk(e,t){const n=[];let r="";e.state.doc.descendants((l,i)=>(l.isText?(n.push({at:r.length,pos:i}),r+=l.text??""):l.isLeaf?(n.push({at:r.length,pos:i}),r+=""):l.isTextblock&&r&&(r+=`
|
|
29
|
-
`),!0));const o=r.lastIndexOf(t);if(o<0)return null;const s=o+t.length;let a=null;for(const l of n)l.at<=s&&(a=l.pos+(s-l.at));return a}function ok(e){const{state:t}=e,n=t.selection.from;if(!Ar(t.selection.$from,["list_item","blockquote"]))return!1;const r=t.tr,o=ir(r,n,["list_item","blockquote"]);return r.steps.length?(r.setSelection(ce.near(r.doc.resolve(o))),e.dispatch(r.scrollIntoView()),!0):!1}function sk(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
|
-
`,"").trim())return null;const a=t(s).trim();return a?(e.dispatch(n.tr.delete(r,n.doc.content.size).scrollIntoView()),a):null}function ak(e){for(const t of e){if(t.name==="heading")return D("blocklabel.heading",{n:String(t.level??1)});if(t.name==="code_block")return D("blocklabel.code");if(t.name==="list_item"&&t.checked!=null)return D("blocklabel.todo");if(t.name==="ordered_list")return D("blocklabel.ordered");if(t.name==="bullet_list")return D("blocklabel.bullet");if(t.name==="blockquote")return D("blocklabel.quote")}return D("blocklabel.text")}function kn(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}const Ar=(e,t)=>t.some(n=>kn(e,n)!==null);function ir(e,t,n){let r=t;for(let o=0;o<32;o++){const s=e.doc.resolve(r);if(!Ar(s,n))break;const a=s.blockRange(),l=a?Qo(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 Bt(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=kn(p,"list_item");if(h!==null&&(t.kind==="bullet"||t.kind==="ordered"||t.kind==="task")){const E=p.node(h);if(t.kind==="task")f.setNodeMarkup(p.before(h),void 0,{...E.attrs,checked:t.checked??!1});else{const S=h-1,N=p.node(S),C=t.kind==="bullet"?c:u;if(!C||S<1||!/_list$/.test(N.type.name))return!1;const _=t.kind==="ordered"?{order:t.order??1,spread:!1}:{spread:!1};f.setNodeMarkup(p.before(S),C,_),f.setNodeMarkup(p.before(h),void 0,{...E.attrs,checked:null})}return e.dispatch(f.scrollIntoView()),!0}if(t.kind==="heading"||t.kind==="text"){const E=t.kind==="heading"?l:a;if(!E||Ar(p,["list_item","blockquote"])&&(m=ir(f,m,["list_item","blockquote"]),p=f.doc.resolve(m),!p.parent.isTextblock))return!1;const S=p.index(-1);return p.node(-1).canReplaceWith(S,S+1,E)?(f.setBlockType(p.before(),p.after(),E,t.kind==="heading"?{level:t.level??1}:void 0),r?.(f,m),e.dispatch(f.scrollIntoView()),!0):!1}if(t.kind==="code"||t.kind==="math"){const E=s.nodes.code_block;if(t.kind==="code"&&!E)return!1;let S=f.doc.resolve(m);if(t.kind==="code"&&Ar(S,["list_item"])&&(m=ir(f,m,["list_item"]),S=f.doc.resolve(m)),!S.parent.isTextblock)return!1;const N=f.doc.textBetween(S.pos,S.end(),`
|
|
31
|
-
`,`
|
|
32
|
-
`);N&&f.delete(S.pos,S.end()),S=f.doc.resolve(f.mapping.map(m));const C=S.before(),_=S.after();let O;if(t.kind==="math")f.insertText("$$ $$",C+1),f.setSelection(ce.near(f.doc.resolve(C+4))),O=f.mapping.map(_);else{const L=E.create({language:t.lang||null});f.replaceWith(C,_,L),f.setSelection(ce.near(f.doc.resolve(C+1))),O=C+L.nodeSize}return N&&f.insert(O,a.create(null,s.text(N))),e.dispatch(f.scrollIntoView()),!0}if(t.kind==="quote"||t.kind==="fold"){if(!i)return!1;if(kn(p,"blockquote")===null){if(kn(p,"list_item")!==null&&(m=ir(f,m,["list_item"]),p=f.doc.resolve(m),!p.parent.isTextblock))return!1;p.parent.type===l&&(f.setBlockType(p.before(),p.after(),a),p=f.doc.resolve(m));const E=p.blockRange(),S=E&&go(E,i);if(!S)return!1;const N=f.steps.length;if(f.wrap(E,S),m=f.mapping.slice(N).map(m),p=f.doc.resolve(m),t.rejoin){const C=kn(p,"blockquote");if(C!==null){const _=p.after(C);f.doc.resolve(_).nodeAfter?.type===i&&or(f.doc,_)&&f.join(_);const O=p.before(C);f.doc.resolve(O).nodeBefore?.type===i&&or(f.doc,O)&&f.join(O)}}}if(t.kind==="fold"&&!Xy.test(p.parent.textContent)){const E=p.start();f.insertText(Jt,E),f.setSelection(ce.near(f.doc.resolve(E+Jt.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 k=p.blockRange(),y=k&&go(k,g,t.kind==="ordered"?{order:t.order??1}:void 0);if(!y)return!1;if(f.wrap(k,y),t.kind==="task"){const E=f.doc.nodeAt(k.start+1);E&&E.type.name==="list_item"&&f.setNodeMarkup(k.start+1,void 0,{...E.attrs,checked:t.checked??!1})}const v=f.doc.resolve(k.start).nodeBefore;return v&&v.type===g&&or(f.doc,k.start)&&f.join(k.start),e.dispatch(f.scrollIntoView()),!0}function Q0(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 k=n.kind==="task"?{checked:n.checked??!1}:null,y=f.filter(E=>E.trim()),v=(y.length?y:[""]).map(E=>d.create(k,m(E)));p=[g.create(n.kind==="ordered"?{order:n.order??1}:null,v)]}else if(n.kind==="quote"||n.kind==="fold"){if(!i)return!1;p=[i.create(null,n.kind==="fold"?[a.create(null,s.text(Jt)),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 Kt=new fe("amadeus-structural-source");function qu(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 Po(e,t){for(let n=e.depth;n>0;n--)if(e.node(n).type.name===t)return n;return null}function Wu(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 qu(t.parent,t.before());const r=Po(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=Po(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 lk(e){const{$from:t,$to:n}=e.selection;return t.parent.type.name!=="heading"||n.parent.type.name!=="heading"||t.before()!==n.before()?null:qu(t.parent,t.before())}function Bo(e){e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(Kt,{refresh:!0}))}function Uu(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(K.create(e.state.doc,t.widgetPos))),!0}function Nr(e){e.style.setProperty("--amx-prefix-ch",String(Math.max(2,e.value.length+.4)))}function ik(e,t,n){const r=Sa(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",!Uu(e,n)||!Bt(e,r,null))return t.value=t.dataset.original??n.source,Nr(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",Nr(a),a.focus({preventScroll:!0}),a.setSelectionRange(Math.min(o,a.value.length),Math.min(s,a.value.length)),!0}function ck(e,t){let n=!1;return Bt(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(K.create(o.doc,l+t.length)),n=!0})&&n}function wn(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=Sa(r);a?Bt(e,a,null):s=ck(e,r)}if(e.dispatch(e.state.tr.setMeta(Kt,{openAt:null})),n){e.focus();const{$from:a}=e.state.selection;!s&&a.parent.isTextblock&&e.dispatch(e.state.tr.setSelection(K.create(e.state.doc,a.start())).scrollIntoView())}}let Ko=!1;function Yl(e,t){Ko=!0;try{return e.someProp("handleKeyDown",n=>n(e,t))??!1}finally{Ko=!1}}function uk(e,t,n){if(wn(e,t,!0),n.key==="Backspace"){Yl(e,n);return}const r=n.key==="ArrowDown"?1:-1;if(r>0&&!e.endOfTextblock("down")||Yl(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 Xl(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",D("structsrc.prefixAriaLabel")),n.setAttribute("autocomplete","off"),n.setAttribute("autocapitalize","off"),n.spellcheck=!1,Nr(n),n.addEventListener("focus",()=>{n.dataset.committed="0",Uu(e,t)});const r=o=>{o?.isComposing||ik(e,n,t)||Sa(n.value)||wn(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(),uk(e,n,o);return}if(o.key==="Escape"){o.preventDefault(),n.value=n.dataset.original??t.source,Nr(n),wn(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??"");wn(e,n,!0),o.key==="Enter"&&c&&!o.isComposing&&e.someProp("handleKeyDown",u=>u(e,o))}}),n.addEventListener("blur",()=>{wn(e,n,!1),queueMicrotask(()=>Bo(e))}),n}function dk(e,t){const n=[],r=Kt.getState(e)?.openAt,o=t.hasFocus()||t.dom.contains(document.activeElement),s=lk(e),a=s&&(o||r===s.widgetPos)?s:null;if(a){const l=a;n.push(J.widget(l.widgetPos,()=>Xl(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}if(r!=null){const l=Wu(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,()=>Xl(t,l),{side:-1,key:`struct:${l.widgetPos}:${l.kind}`,ignoreSelection:!0,stopEvent:()=>!0}))}return n.length?pe.create(e.doc,n):pe.empty}function fk(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(K.create(e.state.doc,r))),!0)}function Jl(e,t=!1){if(Ko||!fk(e))return!1;const n=Wu(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"?Po(s,"blockquote"):null;if((n.kind!=="quote"||a!==null&&s.node(a).childCount===1)&&Bt(e,{kind:"text"},null))return!0}e.dispatch(e.state.tr.setMeta(Kt,{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(Kt,{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 pk(){return Z(()=>{let e=null;return new te({key:Kt,view:t=>(e=t,{destroy:()=>{e===t&&(e=null)}}),state:{init:()=>({openAt:null}),apply:(t,n)=>{const r=t.getMeta(Kt);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?dk(t,e):pe.empty,handleDOMEvents:{focus:t=>(queueMicrotask(()=>Bo(t)),!1),blur:t=>(queueMicrotask(()=>Bo(t)),!1)}}})})}function jo(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 Vu(e){const t=jo(e.$from);if(e.empty)return t;const n=jo(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 hk(e){return!e.code&&!e.tableCell}function gk(e,t){return e==="columns"?t.topLevel:e==="card"?!t.listItem&&!t.column:!0}function Z0(e){const t=e.node;return t?e.$from.depth===0&&!/^amadeus(CanvasCard|ColumnRow)$/.test(t.type.name):!1}function e1(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 Ho=new WeakMap;function t1(e,t){Ho.set(e,t)}function Ql(e,t){const n=Ho.get(e);return Ho.delete(e),n===t}De({"wikiac.multiBlocks":{zh:"多个块",en:"Multiple blocks"}});const bk=ue(()=>new Ye(/【【$/,(e,t,n,r)=>e.tr.insertText("[[",n,r),{inCodeMark:!1}));function Ft(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 Vn=e=>({handleDOMEvents:{blur:()=>(e(null,!0),!1)}});function yk(e){return Z(()=>new te({props:Vn(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)||Ft(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 kk(e){return Z(()=>new te({props:Vn(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=jo(r);if(!hk(o))return e(null);const s=r.parent.textBetween(0,r.parentOffset,void 0,""),a=s.lastIndexOf("/");if(a<0||Ft(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 wk(e){return Z(()=>new te({props:Vn(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||Ft(t.state,r.start()+s,n.head)||s>0&&Wp.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 xk=/^!\[\[[^\]\n|]+\.(png|jpe?g|gif|webp|svg|avif|bmp)(\|\d+)?\]\]$/i,Zl=()=>!!document.activeElement?.closest?.(".inline-toolbar");function vk(e){const t=e.selection;return t instanceof Ue?t.node.type.name==="image":xk.test(e.doc.textBetween(t.from,t.to))}const cr=new fe("amx-toolbar-dismissed");function Ck(e){return Z(()=>{let t=!1;const n=r=>{if(t||cr.getState(r.state))return e(null);const{selection:o,doc:s}=r.state;if(o.empty||!r.editable)return e(null);if(!r.hasFocus()&&!Zl()){setTimeout(()=>{!r.isDestroyed&&!r.hasFocus()&&!Zl()&&e(null)},0);return}if(vk(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 k=i.depth;k>0;k--){const y=i.node(k);f.push({name:y.type.name,level:y.attrs.level,checked:y.attrs.checked??null})}const m=[];for(const k of["strong","emphasis","inlineCode","strike_through","amadeusUnderline","link"]){const y=r.state.schema.marks[k];if(!y)continue;let v=!0,E=!1;s.nodesBetween(a,l,S=>(S.isText&&(E=!0,y.isInSet(S.marks)||(v=!1)),!0)),E&&v&&m.push(k)}const p=new Set;s.nodesBetween(a,l,k=>((k.type.name==="paragraph"||k.type.name==="heading")&&p.add(k.attrs.align==="center"||k.attrs.align==="right"?k.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=(k,y)=>{const v=r.state.schema.marks[k];if(!v)return;const E=new Set;return s.nodesBetween(a,l,S=>(S.isText&&E.add(String(v.isInSet(S.marks)?.attrs[y]??"")),!0)),E.size===1&&[...E][0]||void 0};e({from:a,to:l,active:m,align:h,shape:mk(Vu(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?D("wikiac.multiBlocks"):ak(f)})};return new te({key:cr,state:{init:()=>!1,apply:(r,o,s,a)=>r.getMeta(cr)?!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 Sk=[{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"}],Mk=[{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"}],Ak={turnInto:!0,format:!0,link:!0,color:!0,align:!0},Gu=[{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"}],Nk=Object.fromEntries(Gu.map(e=>[e.k,e.labelKey]));function Ek({left:e,top:t,bottom:n,kind:r,active:o,align:s,shape:a=Ak,fg:l,bg:i,onAct:c,onColor:u,onBg:d,onClose:f,onReturnFocus:m,onAsk:p,ai:h}){const{t:g}=nn(),[k,y]=T.useState(null),v=T.useRef(null),E=T.useRef(!1);T.useEffect(()=>{const L=oe=>{if(oe.key==="Escape"){oe.preventDefault(),oe.stopPropagation();const $e=v.current,H=!!$e&&$e.contains(document.activeElement);if(k&&H){const B=$e.querySelector(`[data-panel="${k}"]`);y(null),B?.focus();return}f(),H&&m?.()}};return window.addEventListener("keydown",L,!0),()=>window.removeEventListener("keydown",L,!0)},[f,m,k]),T.useEffect(()=>{!k||!E.current||(E.current=!1,v.current?.querySelector(".itb-panel button")?.focus())},[k]);const S=L=>o?.includes(L)?" on":"",N=L=>oe=>{oe.preventDefault(),L()},C=L=>({onMouseDown:N(L),onClick:oe=>{oe.detail===0&&L()}}),_=L=>({onMouseDown:N(()=>y(k===L?null:L)),onClick:oe=>{oe.detail===0&&(E.current=k!==L,y(k===L?null:L))},"aria-haspopup":"menu","aria-expanded":k===L,"data-panel":L}),O=L=>{const oe=L.target.closest(".itb-row, .itb-panel");if(!oe||!(oe.classList.contains("itb-panel")?["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]:["ArrowRight","ArrowLeft","Home","End"]).includes(L.key))return;const B=[...oe.querySelectorAll(":scope > button, :scope > * > button")],U=B.indexOf(document.activeElement),Ae=L.key==="ArrowRight"||L.key==="ArrowDown",Fe=L.key==="Home"?0:L.key==="End"?B.length-1:U<0?0:(U+(Ae?1:-1)+B.length)%B.length;L.preventDefault(),L.stopPropagation(),B[Fe]?.focus()};return b.jsxs(rn,{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:L=>{v.current=L},onKeyDown:O,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",...C(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",..._("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}`,..._("turn"),children:[r," ▾"]}),b.jsx("span",{className:"itb-sep"})]}),a.format&&b.jsxs(b.Fragment,{children:[b.jsx("button",{className:`itb-btn${S("strong")}`,style:{fontWeight:700},title:g("itb.bold"),"data-act":"bold","aria-label":g("itb.bold"),"aria-pressed":!!o?.includes("strong"),...C(()=>c("bold")),children:"B"}),b.jsx("button",{className:`itb-btn${S("emphasis")}`,style:{fontStyle:"italic"},title:g("itb.italic"),"data-act":"italic","aria-label":g("itb.italic"),"aria-pressed":!!o?.includes("emphasis"),...C(()=>c("italic")),children:"I"}),b.jsx("button",{className:`itb-btn${S("amadeusUnderline")}`,style:{textDecoration:"underline"},title:g("itb.underline"),"data-act":"underline","aria-label":g("itb.underline"),"aria-pressed":!!o?.includes("amadeusUnderline"),...C(()=>c("underline")),children:"U"}),b.jsx("button",{className:`itb-btn${S("strike_through")}`,style:{textDecoration:"line-through"},title:g("itb.strike"),"data-act":"strike","aria-label":g("itb.strike"),"aria-pressed":!!o?.includes("strike_through"),...C(()=>c("strike")),children:"S"}),b.jsx("button",{className:`itb-btn${S("inlineCode")}`,title:g("itb.code"),"data-act":"code","aria-label":g("itb.code"),"aria-pressed":!!o?.includes("inlineCode"),...C(()=>c("code")),children:"</>"})]}),a.link&&b.jsx("button",{className:`itb-btn${S("link")}`,title:g("itb.link"),"aria-label":g("itb.link"),"aria-pressed":!!o?.includes("link"),"data-act":"link",...C(()=>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,..._("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",...C(()=>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",...C(()=>c("alignLeft")),children:b.jsx($f,{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",...C(()=>c("alignCenter")),children:b.jsx(Qp,{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",...C(()=>c("alignRight")),children:b.jsx(em,{size:14})})]})]}),k==="turn"&&b.jsx("div",{className:"itb-panel",role:"menu","aria-label":g("itb.turnInto"),children:Gu.map(L=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,...C(()=>{y(null),c(L.k)}),children:g(L.labelKey)},L.k))}),k==="ai"&&h&&b.jsxs("div",{className:"itb-panel itb-ai-menu",role:"menu","data-testid":"itb-ai-menu",children:[h.items.filter(L=>!L.plugin).map(L=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":L.id,...C(()=>{y(null),h.onPick(L.id)}),children:L.label},L.id)),h.items.some(L=>L.plugin)&&b.jsx("div",{className:"itb-color-head",children:g("itb.aiPlugins")}),h.items.filter(L=>L.plugin).map(L=>b.jsx("button",{className:"itb-menu-item",role:"menuitem",tabIndex:-1,"data-ai":L.id,...C(()=>{y(null),h.onPick(L.id)}),children:L.label},L.id))]}),k==="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:Sk.map(L=>b.jsx("button",{className:"itb-swatch",title:g(L.nameKey),role:"menuitem",tabIndex:-1,"aria-label":`${g("itb.textColor")}: ${g(L.nameKey)}`,"data-fg":L.v||"default",...C(()=>{y(null),u(L.v)}),children:b.jsx("span",{className:"itb-swatch-a",style:{color:L.v||"var(--text)"},children:"A"})},L.v||"def"))}),b.jsx("div",{className:"itb-color-head",children:g("itb.bgColor")}),b.jsx("div",{className:"itb-swatches",children:Mk.map(L=>b.jsx("button",{className:"itb-swatch",title:g(L.nameKey),role:"menuitem",tabIndex:-1,"aria-label":`${g("itb.bgColor")}: ${g(L.nameKey)}`,"data-bg":L.v||"default",...C(()=>{y(null),d(L.v)}),children:b.jsx("span",{className:"itb-swatch-bg",style:{background:L.v||"transparent"}})},L.v||"def"))})]})]})}const Tk=8,Ik=2;function Lk(e,t,n=Tk){const r=[];for(const l of e){if(l.alias&&!t.trim())continue;const i=Dt(t,l.base),c=i!==null?i+1e3:Dt(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,Ik);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 vt=e=>String(e).padStart(2,"0"),Ln=e=>`${e.getFullYear()}-${vt(e.getMonth()+1)}-${vt(e.getDate())}`,Fo=(e,t)=>new Date(e.getFullYear(),e.getMonth(),e.getDate()+t),Rk=/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/,$k=/^(\d{4})年(\d{1,2})月(\d{1,2})(?:日|号)?$/,Dk=/^(\d{1,2})[-/.](\d{1,2})$/,_k=/^(\d{1,2})月(\d{1,2})(?:日|号)?$/,zk=/^(\d{4})(\d{2})(\d{2})$/,Ok=/^(\d{1,2})(?:日|号)?$/,Pk={昨天:-1,yesterday:-1,今天:0,today:0,明天:1,tomorrow:1,后天:2};function ei(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 Bk(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 Ln(o)}return null}function ti(e,t){const n=e.trim().toLowerCase(),r=Pk[n];if(r!==void 0)return Ln(Fo(t,r));const o=(a,l,i)=>{const c=`${Number(a)}-${vt(Number(l))}-${vt(Number(i))}`;return zf(c)?c:null};let s=Rk.exec(n);return s||(s=$k.exec(n),s)||(s=zk.exec(n),s)?o(s[1],s[2],s[3]):(s=Dk.exec(n),s||(s=_k.exec(n),s)?o(t.getFullYear(),s[1],s[2]):(s=Ok.exec(n),s?Bk(Number(s[1]),t):null))}function ni(e,t=new Date){const n=e.normalize("NFKC").trim();if(!n)return null;const r=ti(n,t);if(r)return r;const o=ei(n);if(o)return`${Ln(t)}T${vt(o.hour)}:${vt(o.minute)}`;const s=/^(.+?)(?:[tT]|\s+)(\S.+)$/.exec(n)??/^(.+?(?:日|号))\s*(\d{1,2}(?:点|时).*)$/.exec(n);if(s){const a=ti(s[1],t),l=ei(s[2]);if(a&&l)return`${a}T${vt(l.hour)}:${vt(l.minute)}`}return null}const Kk=[{key:"dateq.today",words:["today","今天"],days:0},{key:"dateq.tomorrow",words:["tomorrow","明天"],days:1}],jk=["remind","提醒"];function Hk(e,t=new Date){const n=e.trim(),r=u=>Df(_f(u)),o=u=>{const d=u.includes("T")?u:`${u}T09:00`;return{insert:`@remind:${d}`,label:D("dateq.remind"),hint:r(d)}},s=Ln(Fo(t,1));if(/^remind:/i.test(n)){const u=n.length===7?s:ni(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 Kk){if(!l(u.words))continue;const d=Ln(Fo(t,u.days));i.push({insert:`@${d}`,label:D(u.key),hint:r(d)})}if(l(jk)&&i.push(o(s)),i.length)return i;const c=ni(n,t);return c?[{insert:`@${c}`,label:D("dateq.schedule"),hint:r(c)},o(c)]:[]}let gn=null;function Fk(){const e=An(s=>s.vaultRoot),t=An(s=>s.linkGraphVersion),n=`${e??""}\0${t}`,[r,o]=T.useState(()=>gn?.map??{});return T.useEffect(()=>{if(gn?.key===n){o(gn.map);return}let s=!0;return ze?.pageAliases?.().then(a=>{gn={key:n,map:a??{}},s&&o(gn.map)}).catch(()=>{}),()=>{s=!1}},[n]),r}function qk(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 qo=e=>e.replace(/[[\]|#^]/g," ").replace(/\s+/g," ").trim();function Wk(e){const t=[],n=new Set;return Ir(Ni(e),r=>{const o=/^ {0,3}(#{1,6})[ \t]+(.+?)(?:[ \t]+#+)?[ \t]*$/.exec(r);if(o){const s=qo(Ai(o[2]));s&&!n.has(s)&&(n.add(s),t.push({level:o[1].length,text:s}))}return r}),t}function Uk(e){const t=[],n=new Set;return Ir(Ni(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:Ai(r.slice(0,o.index))})),r}),t}De({"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 Vk(e,t){const[n,r]=T.useState(null);return T.useEffect(()=>{if(!e||!t){r(null);return}let o=!0;const s=l=>{if(o){if(l==null){r([]);return}r(t==="heading"?Wk(l).map(i=>({label:i.text,insert:i.text,hint:`H${i.level}`})):Uk(l).map(i=>({label:`^${i.id}`,insert:`^${i.id}`,hint:i.preview})))}},a=t==="heading"?Vd(e):null;if(a)r(a.map(l=>({label:qo(l.text),insert:qo(l.text),hint:`H${l.level}`})).filter(l=>l.insert));else{const l=Gd(e);l!=null?s(l):ze?.readTextFile?.(e).then(i=>s(i),()=>s(null))}return()=>{o=!1}},[e,t]),n}function uo(e){return(e.split(/[\\/]/).pop()??e).replace(/\.md$/i,"")}function Gk(e){return e.split(/[\\/]/).pop()??e}function Yk(e){const t=e.replace(/\\/g,"/"),n=t.lastIndexOf("/");return n===-1?"":t.slice(0,n)}const Wt=e=>e.file?e.base.toLowerCase():Ei(e.base);function ri({query:e,left:t,top:n,anchorTop:r,getPageNames:o,getFiles:s,onPick:a,onPickRaw:l,onClose:i,editorFocused:c,sourcePath:u,allowCreate:d=!0,dates:f=!1}){const[m,p]=T.useState(0),{t:h}=nn(),g=An(H=>H.icons),k=Fk(),y=o(),v=[...y.map(H=>({path:H,base:uo(H),file:!1})),...(s?.()??[]).map(H=>({path:H,base:Gk(H),file:!0})),...y.flatMap(H=>(k[H]??[]).map(B=>({path:H,base:B,file:!1,alias:B})))],E=new Map;for(const H of v)H.alias||E.set(Wt(H),(E.get(Wt(H))??0)+1);const S=e.trim(),N=f?null:qk(e),C=N?N.name?mo(N.name,y,u):u||null:null,_=Vk(C,N?N.kind:null),O=H=>{if(H.alias){const U={path:H.path,base:uo(H.path),file:!1};return`${(E.get(Wt(U))??0)<=1?U.base:H.path.replace(/\\/g,"/").replace(/\.md$/i,"")}|${H.alias}`}if((E.get(Wt(H))??0)<=1)return H.base;const B=H.path.replace(/\\/g,"/");return`${H.file?B:B.replace(/\.md$/i,"")}|${H.base}`},L=[];if(N){const H=(_??[]).map(B=>({it:B,s:Dt(N.q,B.insert.replace(/^\^/,""))})).filter(B=>B.s!==null).sort((B,U)=>U.s-B.s).slice(0,8);for(const{it:B}of H)L.push({key:`s:${B.insert}`,name:B.label,hint:B.hint,pick:()=>a(`${N.name}#${B.insert}`)})}else{const H=f?Hk(e):[];for(const U of H)L.push({key:`d:${U.insert}`,name:U.label,hint:U.hint,section:"date",pick:()=>l?.(U.insert)});for(const U of Lk(v,e))L.push({key:(U.file?"f:":U.alias?`a:${U.alias}:`:"p:")+U.path,name:b.jsxs(b.Fragment,{children:[U.file?b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:/\.db$/i.test(U.base)?b.jsx(pr,{}):b.jsx(Of,{})}):g[U.path]&&b.jsx("span",{className:"wiki-item-ficon","aria-hidden":!0,children:g[U.path]}),U.base]}),hint:U.alias?h("wiki.aliasOf",{name:uo(U.path)}):(E.get(Wt(U))??0)>1?Yk(U.path)||"/":void 0,section:"page",pick:()=>a(O(U))});d&&S.length>0&&!Pf(S)&&!/[#|^]/.test(S)&&!v.some(U=>U.alias?U.alias.toLowerCase()===S.toLowerCase():Wt(U)===Ei(S))&&L.push({key:"create",name:h("wiki.create",{q:S}),create:!0,pick:()=>a(S)})}const oe=L.length;if(T.useEffect(()=>{p(0)},[e]),T.useLayoutEffect(()=>{if(oe===0)return;const H=B=>{B.isComposing||B.key==="Process"||B.keyCode===229||c&&!c()||(B.key==="ArrowDown"?(B.preventDefault(),B.stopPropagation(),p(U=>Math.min(U+1,oe-1))):B.key==="ArrowUp"?(B.preventDefault(),B.stopPropagation(),p(U=>Math.max(U-1,0))):B.key==="Enter"||B.key==="Tab"?(B.preventDefault(),B.stopPropagation(),L[m]?.pick()):B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),i()))};return window.addEventListener("keydown",H,!0),()=>window.removeEventListener("keydown",H,!0)}),oe===0)return null;const $e=H=>H===m?B=>B?.scrollIntoView({block:"nearest"}):void 0;return b.jsx(rn,{className:"wiki-suggest",x:t,y:n,anchorTop:r,role:"menu",onMouseDown:H=>H.preventDefault(),children:L.map((H,B)=>b.jsx(Xk,{r:H,i:B,active:m,setActive:p,reveal:$e,label:f&&H.section&&H.section!==L[B-1]?.section?h(H.section==="date"?"wiki.sec.date":"wiki.sec.page"):void 0},H.key))})}function Xk({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 Jk=/(?:^|\s)#([\p{L}\p{N}_/-]+)$/u;function Qk(e){return Z(()=>new te({props:Vn(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=Jk.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(Ft(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 oi=[];function Zk(e,t,n=8){const r=[];for(const o of e){const s=Dt(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 ew({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=T.useState(oi),[c,u]=T.useState(0);T.useEffect(()=>{let p=!0;return ze?.listTags?.().then(h=>{oi=h,p&&i(h)}).catch(()=>{}),()=>{p=!1}},[]),T.useEffect(()=>{u(0)},[e]);const d=Zk(l,e),f=d.length;if(T.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(rn,{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 tw=/(?:^|[^A-Za-z0-9_:])(:([A-Za-z]{2,30}))$/;function nw(e){return Z(()=>new te({props:Vn(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=tw.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(Ft(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 rw({query:e,left:t,top:n,anchorTop:r,onPick:o,onClose:s,editorFocused:a}){const[l,i]=T.useState(0);T.useEffect(()=>{i(0)},[e]);const c=Up(e).slice(0,8),u=c.length;if(T.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(rn,{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 ow=/[\p{L}\p{N}_/-]/u;function sw(e){let t="";return e.forEach(n=>{n.isText?t+=n.text??"":t+="".repeat(n.nodeSize)}),t}function n1(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=sw(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&&ow.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 Yu(e,t){let n=!1;for(let r=0;r<32;r++){const o=Vp(e.state,t);if(o!=null){Gp(e,o),n=!0;continue}const s=Yp(e.state,t);if(!s.length)break;Xp(e,s[0]),n=!0}return n}function aw(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 lw(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 iw=12;function cw(e,t=iw){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=aw(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+lw(o)+t))/a}De({"footnote.backToRef":{zh:"回到引用处",en:"Back to reference"}});const xn=new fe("amx-footnote"),Xu="jumped",jt="footnote_reference",mt="footnote_definition",Ma="[^\\s[\\]\\\\\\ufffc]{1,200}",Mt=e=>e.replace(/[\t\n\r ]+/g," ").trim().toLowerCase().toUpperCase();function Er(e,t){const n=Mt(t);let r=null;return e.descendants((o,s)=>r?!1:o.type.name===mt&&Mt(String(o.attrs.label))===n?(r={pos:s,node:o},!1):!o.isTextblock),r}function r1(e,t){const n=Er(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 si=e=>e.type.name===mt&&e.childCount===1&&e.firstChild.isTextblock&&e.firstChild.content.size===0;function Ju(e,t,n,r,o=""){const s=e.schema.nodes[jt],a=e.schema.nodes[mt],l=e.schema.nodes.paragraph;if(!s||!a||!l||Ft(e,t,n))return null;const i=e.tr.replaceWith(t,n,s.create({label:r}));if(o&&i.insertText(o,t+1),Er(e.doc,r))return i;const c=i.doc.content.size;return i.insert(c,a.create({label:r},l.create())),i.setSelection(K.create(i.doc,c+2)).setMeta(xn,Xu).scrollIntoView()}const uw=new Ye(new RegExp(`(?<![[!\\\\])\\[\\^(${Ma})\\]$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset===0&&o.parent.type.name==="paragraph"?null:Ju(e,n,r,t[1])},{inCodeMark:!1}),dw=new Ye(new RegExp(`^\\[\\^(${Ma})\\]([^:\\n])$`,"u"),(e,t,n,r)=>{const o=e.doc.resolve(n);return o.parentOffset!==0||o.parent.type.name!=="paragraph"?null:Ju(e,n,r,t[1],t[2])},{inCodeMark:!1}),fw=new Ye(new RegExp(`^\\[\\^(${Ma})\\]:[ \\u00a0]$`,"u"),(e,t,n,r)=>{const o=e.schema.nodes[mt],s=e.doc.resolve(n);if(!o||s.parentOffset!==0||s.parent.type.name!=="paragraph"||s.depth!==1||Ft(e,n,r))return null;const a=t[1],l=[];e.doc.forEach((u,d)=>{si(u)&&Mt(String(u.attrs.label))===Mt(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&&si(f)&&i.delete(d,d+f.nodeSize)}return i},{inCodeMark:!1}),pw=[ue(()=>uw),ue(()=>dw),ue(()=>fw)];function ai(e){const t=new Map,n=[],r=[];if(e.descendants((s,a)=>{if(s.type.name===jt){const l=Mt(String(s.attrs.label));t.has(l)||t.set(l,t.size+1),n.push({pos:a,node:s})}else s.type.name===mt&&r.push({pos:a,node:s});return!0}),!n.length&&!r.length)return pe.empty;const o=s=>{const a=t.get(Mt(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 pe.create(e,[...n,...r].map(o))}function mw(e){return e.steps.some(t=>{const n=t.slice;let r=!1;return n?.content.descendants(o=>((o.type.name===jt||o.type.name===mt)&&(r=!0),!r)),r})}const Qu=e=>{for(const t of e){const n=t.spec.fnNum;if(n!=null)return n}return null};class hw{constructor(t,n){this.node=t,this.dom=document.createElement("sup"),this.dom.setAttribute("data-type",jt),this.dom.contentEditable="false",this.render(n)}node;dom;render(t){const n=String(this.node.attrs.label),r=Qu(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 gw{constructor(t,n){this.node=t,this.dom=document.createElement("dl"),this.dom.setAttribute("data-type",mt),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=D("footnote.backToRef")};r(),this.off=Xo(r),this.render(n)}node;dom;contentDOM;dt;off;render(t){const n=String(this.node.attrs.label),r=Qu(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 Zu(e){if(!(e instanceof HTMLElement))return;const t=e.getBoundingClientRect();t.top>=0&&t.bottom<=window.innerHeight||cw(e)}function bw(e,t){let n=Er(e.state.doc,t);if(!n||(Yu(e,n.pos)&&(n=Er(e.state.doc,t)),!n))return!1;const r=n.pos+n.node.nodeSize-1;return e.dispatch(e.state.tr.setSelection(K.near(e.state.doc.resolve(r),-1))),e.focus(),Zu(e.nodeDOM(n.pos)),!0}function yw(e,t){const n=Mt(t);let r=-1;return e.state.doc.descendants((o,s)=>r>=0?!1:(o.type.name===jt&&Mt(String(o.attrs.label))===n&&(r=s),r<0)),r<0?!1:(Yu(e,r),e.dispatch(e.state.tr.setSelection(K.near(e.state.doc.resolve(r+1)))),e.focus(),Zu(e.nodeDOM(r)),!0)}const kw=Z(()=>new te({key:xn,state:{init:(e,t)=>({decos:ai(t.doc),jumped:!1}),apply:(e,t)=>{const n=e.getMeta(xn)===Xu||!e.docChanged&&!e.selectionSet&&t.jumped;let r=t.decos;return e.docChanged&&(r!==pe.empty||mw(e))&&(r=ai(e.doc)),r===t.decos&&n===t.jumped?t:{decos:r,jumped:n}}},props:{decorations:e=>xn.getState(e)?.decos,handleKeyDown(e,t){if(t.key!=="Backspace"||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||!xn.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?Bf(e.state,r=>{const o=Math.min(n.from+n.text.length,r.doc.content.size);e.dispatch(r.setSelection(K.near(r.doc.resolve(o))).scrollIntoView())}):!1},nodeViews:{[jt]:(e,t,n,r)=>new hw(e,r),[mt]:(e,t,n,r)=>new gw(e,r)},handleClickOn(e,t,n,r,o,s){return!s||n.type.name!==jt||o.button!==0||o.ctrlKey?!1:bw(e,String(n.attrs.label))},handleDOMEvents:{mousedown(e,t){if(t.button!==0)return!1;const n=t.target?.closest?.(`dl[data-type="${mt}"] > dt`);if(!n||!e.dom.contains(n))return!1;const r=n.parentElement?.getAttribute("data-label")??"";return t.preventDefault(),yw(e,r),!0}}}})),ww="amadeus:open-tag",Rt=new fe("amadeus-tag-pill");function xw(e){const t=Rt.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=Lr(s);if(!l.includes("#"))return!1;const i=a+1;let c=-1,u=-1;if(t&&n>=i&&r<=i+s.content.size){const m=Math.max(0,Math.min(l.length,n-i)),p=Math.max(0,Math.min(l.length,r-i));c=l.lastIndexOf(`
|
|
36
|
-
`,m-1)+1;const h=l.indexOf(`
|
|
37
|
-
`,p);u=h===-1?l.length:h}const d=new RegExp(Ga.source,Ga.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?pe.create(e.doc,o):pe.empty}function vw(){return Z(()=>new te({key:Rt,state:{init:()=>({focus:!1}),apply:(e,t)=>{const n=e.getMeta(Rt);return n&&typeof n.focus=="boolean"?{focus:n.focus}:t}},props:{decorations:e=>xw(e),handleDOMEvents:{focus:e=>(Rt.getState(e.state)?.focus||e.dispatch(e.state.tr.setMeta(Rt,{focus:!0})),!1),blur:e=>(Rt.getState(e.state)?.focus&&e.dispatch(e.state.tr.setMeta(Rt,{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(ww,{detail:{tag:r}})),!0):!1}}}}))}function Cw(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}De({"mdtask.checkbox":{zh:"完成",en:"Done"}});function Sw(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 Mw=xe("amadeusEmptyTask",()=>()=>Sw);function Wo(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 li=new fe("amadeusTaskA11y"),Aw="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";function ed(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=Aw;const s=()=>{o.setAttribute("aria-label",D("mdtask.checkbox"))};return s(),o.__off=Xo(s),o.addEventListener("click",a=>{if(a.preventDefault(),a.stopPropagation(),!n.editable)return;const l=r();if(l==null)return;const i=Wo(n.state,l);i&&n.dispatch(i)}),o},{side:-1,ignoreSelection:!0,key:`amxtask:${t?1:0}`,stopEvent:()=>!0,destroy:n=>{n.__off?.()}})}function td(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 Nw(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=td(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])=>ed(h,g)))})}),n}function ii(e,t){const n=t.target?.closest?.('li[data-item-type="task"]');return n?t.clientX-n.getBoundingClientRect().left>2?null:n:null}function Ew(){return Z(()=>new te({key:li,state:{init:(e,t)=>pe.create(t.doc,[...td(t.doc,0,t.doc.content.size)].map(([n,r])=>ed(n,r))),apply:Nw},props:{decorations:e=>li.getState(e),handleClick(e,t,n){if(!e.editable)return!1;const r=ii(e,n);if(!r)return!1;const o=Wo(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||!Kf())return!1;const n=ii(e,t);if(!n)return!1;const r=Wo(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 Tw={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"},nd={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 Iw(e){const t=Tw[e]??e;return t in nd?t:null}function rd(e){const t=e.children?.[0];if(e.type==="blockquote"&&t?.type==="paragraph"&&t.position&&/^\[![\w-]+\][+-]?/.test(t.children?.[0]?.value??"")){const n=fu(t);n.length>1&&e.children.splice(0,1,...n)}e.children?.forEach(rd)}const Lw=xe("amadeusCalloutTitle",()=>()=>rd),od=e=>e.replace(/^((?:[ \t]*>[ \t]?)+)\\\[!/gm,"$1[!"),sd=/^\[!([\w-]+)\]([+-])?/,Rw=/^(#{1,6}|[-*+]) /;function Rn(e){if(e.type.name!=="blockquote")return null;const t=e.firstChild,n=t&&t.isTextblock?sd.exec(t.textContent):null;if(!n||!t)return null;const r=/[ \u00a0]/.test(t.textContent[n[0].length]??"")?1:0,o=Rw.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 ad(e,t){e.doc.descendants((n,r)=>{const o=Rn(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 o1(e,t,n){ad(e,[[t,n]])}function $w(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 ad(r,n),r.docChanged?r:null}function Qe(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=Rn(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 Dw=e=>{const t=Qe(e);return t&&t.collapsed?t:null},ld="--amx-fold-scroll-buffer",Ut=e=>parseFloat(e.style.getPropertyValue(ld))||0,fo=(e,t)=>{e.style.setProperty(ld,`${Math.max(0,Math.ceil(t))}px`)},bn=new WeakMap,rr=new WeakMap;function _w(e,t){bn.get(e)?.(),rr.get(e)?.();const n=e.scrollTop,r=n+e.clientHeight;fo(e,Ut(e)+e.scrollHeight),t();let o=0,s=!0;const a=performance.now(),l=()=>{const f=e.scrollHeight-Ut(e),m=Math.max(0,e.scrollTop+e.clientHeight-f);m<Ut(e)&&fo(e,m),Ut(e)||(e.removeEventListener("scroll",l),rr.delete(e))},i=()=>{l(),Ut(e)&&(e.addEventListener("scroll",l,{passive:!0}),rr.set(e,()=>{e.removeEventListener("scroll",l),rr.delete(e)}))},c=()=>{e.removeEventListener("wheel",d),e.removeEventListener("touchmove",d),e.removeEventListener("keydown",d)},u=()=>{const f=Ut(e),m=e.scrollHeight-f;fo(e,Math.max(0,r-m)),e.scrollTop=n,s&&performance.now()-a<260?o=requestAnimationFrame(u):(c(),bn.delete(e),i())},d=()=>{s&&(s=!1,cancelAnimationFrame(o),c(),bn.delete(e),requestAnimationFrame(()=>{bn.has(e)||i()}))};bn.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 zw=0;function ci(e,t){const n=e.state.doc.nodeAt(t.bqPos),r=!!n&&Rn(n)?.type==="fold",o=r?++zw:0;if(r){e.dispatch(e.state.tr.setMeta(Re,{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?_w(a,s):s(),r&&setTimeout(()=>{e.dom.isConnected&&e.dispatch(e.state.tr.setMeta(Re,{foldEnd:o}))},matchMedia("(prefers-reduced-motion: reduce)").matches?0:230)}function id(e){const t=e.state.selection;if(!t.empty||!e.hasFocus())return;const n=Qe(t.$from);if(!n||n.type!=="fold"||!n.inHead||Re.getState(e.state)?.srcAt===n.bqPos||t.from!==n.hidden[n.hidden.length-1][1])return;const r=document.getSelection(),o=r?.anchorNode;if(!(o instanceof Element?o:o?.parentElement)?.closest(".callout-syntax"))return;const a=e.nodeDOM(n.bqStart);if(!(a instanceof HTMLElement))return;const l=document.createTreeWalker(a,NodeFilter.SHOW_TEXT);let i;for(;i=l.nextNode();){if(!i.textContent||i.parentElement?.closest(".callout-syntax,button")||e.posAtDOM(i,0)!==t.from)continue;const c=document.createRange();c.setStart(i,0),c.collapse(!0),r.removeAllRanges(),r.addRange(c);return}}const Re=new fe("amadeus-callout-src");function cd(e,t){if(!e.editable||t.isComposing)return!1;const{state:n}=e,r=Qe(n.selection.$from);if(!r||r.type!=="fold"||!r.inHead||Re.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(K.create(n.doc,t.shiftKey?Math.max(o,n.selection.anchor):o,o))),id(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=K.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(K.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(K.near(s.doc.resolve(a+2))).scrollIntoView()),!0}return!1}function ui(e){const t=e.selection;if(!t.empty)return null;const n=Qe(t.$from);if(!n||!n.inHead||Re.getState(e)?.srcAt===n.bqPos)return null;const r=n.hidden[n.hidden.length-1][1];return t.from<r?r:null}function Ow(e,t,n){const r=e.doc.content.size;if(t<0||t>r)return null;const o=e.doc.resolve(t),s=Qe(o);if(!s||Re.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 Pw(){return Z(()=>new te({key:Re,state:{init:()=>({srcAt:null,animations:[]}),apply:(e,t)=>{const n=e.getMeta(Re);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&&Rn(s)&&e.selection.from>o&&e.selection.to<o+s.nodeSize?o:null,animations:r}}},appendTransaction(e,t,n){const r=$w(e,n);if(r)return r;const o=n.selection;if(!o.empty)return null;const s=Qe(o.$from);if(s?.type==="fold"&&s.inHead&&Re.getState(n)?.srcAt!==s.bqPos){const u=s.hidden[s.hidden.length-1][1];if(o.from<u)return n.tr.setSelection(K.create(n.doc,u))}const a=Qe(o.$from,!0);if(!a)return null;if(a.type==="fold")return n.tr.setSelection(K.create(n.doc,a.headEnd));const l=u=>u.from<a.bqStart||u.from>=a.afterBq,i=K.near(n.doc.resolve(Math.min(a.afterBq,n.doc.content.size)),1);if(l(i))return n.tr.setSelection(i);const c=K.near(n.doc.resolve(Math.max(a.bqStart-1,0)),-1);return l(c)?n.tr.setSelection(c):n.tr.setSelection(K.create(n.doc,a.headEnd))},props:{handleDOMEvents:{blur:e=>(Re.getState(e.state)?.srcAt!==null&&e.dispatch(e.state.tr.setMeta(Re,{srcAt:null})),!1)},handleKeyDown(e,t){if(cd(e,t))return!0;if((t.key==="Enter"||t.key==="Delete")&&!t.isComposing&&!t.metaKey&&!t.ctrlKey&&!t.altKey){const r=ui(e.state);r!=null&&e.dispatch(e.state.tr.setSelection(K.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=Ow(e.state,r.from+o,o);if(s!==null)return e.dispatch(e.state.tr.setSelection(K.create(e.state.doc,s))),!0}return!1}if(t.key!=="Enter"||t.isComposing)return!1;const n=Dw(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?ui(e.state):null;if(o!=null&&t<o){const u=e.state.tr.insertText(r,o);return e.dispatch(u.setSelection(K.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(Jt)||!sd.test(c.slice(Jt.length))?!1:(e.dispatch(s.tr.insertText(r,t,n).delete(l,l+Jt.length).scrollIntoView()),!0)},handleClick(e,t){const n=Qe(e.state.doc.resolve(t));if(!n||!n.inHead||Re.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(K.create(e.state.doc,r))),e.focus(),id(e),!0}return n.marker?(ci(e,n),!0):!1},handleDoubleClick(e,t){const n=Qe(e.state.doc.resolve(t));return!n||!n.inHead||n.type==="fold"||e.dispatch(e.state.tr.setMeta(Re,{srcAt:n.bqPos})),!1},decorations(e){const t=[];return e.doc.descendants((n,r)=>{if(n.type.name!=="blockquote")return!0;const o=Rn(n);if(o){const{type:s,marker:a,token:l,hideLen:i,mark:c}=o,u=a==="-",d=Re.getState(e),f=d?.srcAt===r,m=s==="fold"?null:Iw(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);t.push(J.node(p,h,{class:"callout-toggle-title",...y?{"data-placeholder":D("mdcallout.title")}:{},...y&&e.selection.empty&&e.selection.from===r+2+o.first.content.size?{"data-empty-caret":""}:{}}))}if(c&&t.push(J.node(p,h,{class:`callout-title-${c.cls}`})),s!=="fold"){const y=nd[m??"note"];if(t.push(J.widget(r+2,()=>{const v=document.createElement("span");return v.className="callout-icon",v.contentEditable="false",v.setAttribute("aria-hidden","true"),v.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>`,v},{side:-1,ignoreSelection:!0,key:`ci${r}:${m??"note"}`})),!f&&o.first.content.size===i+(c?.len??0)){const v=m?D(`mdcallout.type.${m}`):o.raw.charAt(0).toUpperCase()+o.raw.slice(1);t.push(J.widget(h-1,()=>{const E=document.createElement("span");return E.className="callout-default-title",E.contentEditable="false",E.textContent=v,E},{side:-1,ignoreSelection:!0,key:`cd${r}:${v}`}))}}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,k=s==="fold"?r+2:r+2+o.first.content.size;(s==="fold"||a)&&t.push(J.widget(k,y=>{const v=document.createElement("button");v.className=`callout-chevron${u?" collapsed":""}`,v.type="button",v.title=u?D("mdcallout.expand"):D("mdcallout.collapse"),v.setAttribute("aria-label",v.title),v.setAttribute("aria-expanded",String(!u)),v.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>',v.contentEditable="false",v.addEventListener("mousedown",N=>{N.preventDefault(),N.stopPropagation()});const E=()=>{const N=Qe(y.state.doc.resolve(r+2));N?.bqPos===r&&ci(y,N)},S=()=>{y.nodeDOM(r+1)?.querySelector(".callout-chevron")?.focus()};return v.addEventListener("keydown",N=>{N.key!==" "&&N.key!=="Enter"||(N.preventDefault(),N.stopPropagation(),document.addEventListener("keyup",S,{capture:!0,once:!0}),E())}),v.addEventListener("click",N=>{N.preventDefault(),N.stopPropagation(),E(),N.detail===0&&queueMicrotask(S)}),v},{side:s==="fold"?-1:1,ignoreSelection:!0,stopEvent:()=>!0,key:`cf${r}:${g}:${a??""}`})),s==="fold"&&(t.push(J.widget(h-1,y=>{const v=document.createElement("button");return v.type="button",v.className="amx-src-btn callout-source",v.contentEditable="false",v.textContent="</>",v.title=D("mdcallout.source"),v.setAttribute("aria-label",v.title),y.editable||(v.style.display="none"),v.onmousedown=E=>E.preventDefault(),v.onclick=E=>{E.preventDefault(),y.dispatch(y.state.tr.setMeta(Re,{srcAt:r}).setSelection(K.create(y.state.doc,r+2))),y.focus()},v},{side:1,stopEvent:()=>!0,key:`cs${r}`})),!u&&n.childCount===1&&t.push(J.widget(h,y=>{const v=document.createElement("button");return v.type="button",v.className="callout-empty",v.contentEditable="false",v.textContent=D("mdcallout.empty"),y.editable||(v.style.display="none"),v.onmousedown=E=>E.preventDefault(),v.onclick=()=>{const E=y.state.tr.insert(h,y.state.schema.nodes.paragraph.create());y.dispatch(E.setSelection(K.create(E.doc,h+1))),y.focus()},v},{side:-1,stopEvent:()=>!0,key:`ce${r}:${h}`})))}return!0}),t.length?pe.create(e.doc,t):null}}}))}const Yt=jf(Hf),di=["javascript","typescript","python","bash","json","html","css","sql","java","go","rust","c","cpp","yaml","markdown","diff"],ur=[...di,...Yt.listLanguages().filter(e=>!di.includes(e)&&e!=="plaintext").sort()],Bw=ur.filter(e=>!["markdown","ini","less","scss","vbnet","arduino","shell","python-repl","php-template"].includes(e)),Kw=4096;let po=0;function Uo(e){return["text","txt","plaintext"].includes(e.toLowerCase())}function jw(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 Hw(e,t){const n=t.trim(),r={language:"",ranges:[]};if(!e||Uo(n))return r;try{let o=n,s;if(o){if(!Yt.registered(o))return r;po++,s=Yt.highlight(o,e)}else{const c=e.slice(0,Kw);if(o=jw(c),po++,o)s=Yt.highlight(o,e);else{if(s=Yt.highlightAuto(c,{subset:Bw}),!s.data?.language||(s.data.relevance??0)<3)return r;o=s.data.language,c.length<e.length&&(po++,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 fi=new WeakMap;function ud(e){let t=fi.get(e);return t||(t=Hw(e.textContent,String(e.attrs.language??"")),fi.set(e,t)),t}const Ct=new fe("amx-code-block");function dd(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(`
|
|
38
|
-
`).length)}:{}})];for(const l of ud(e).ranges)a.push(J.inline(t+1+l.from,t+1+l.to,{class:l.cls}));return a}function pi(e,t){const n=[];return e.descendants((r,o)=>r.type.name!=="code_block"?!0:(n.push(...dd(r,o,t)),!1)),n.length?pe.create(e,n):pe.empty}function Fw(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,(k,y)=>k.type.name==="code_block"?(s.set(y,k),!1):k.isTextblock?(a.push([y,y+k.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,dd(c,i,n))}return r}const yn=[];function qw(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?D("amxcode.autoDetected",{language:r}):D("amxcode.langTitle");const c=document.createElement("option");c.value="";const u=r==="javascript"?"JS":r==="typescript"?"TS":r;c.textContent=r?D("amxcode.autoDetected",{language:u}):D("amxcode.auto"),i.appendChild(c);const d=document.createElement("option");d.value=Uo(n)?n:"plaintext",d.textContent=D("amxcode.plainText"),i.appendChild(d);const f=ur.includes(n)||!n||Uo(n),m=[...yn.filter(y=>ur.includes(y)),...ur.filter(y=>!yn.includes(y))];for(const y of f?m:[n,...m]){const v=document.createElement("option");v.value=y,v.textContent=y,i.appendChild(v)}i.value=n,i.addEventListener("change",()=>{const y=t();if(i.value){const E=yn.indexOf(i.value);E>=0&&yn.splice(E,1),yn.unshift(i.value)}if(y===null)return;const v=e.state.doc.nodeAt(y);v?.type.name==="code_block"&&e.dispatch(e.state.tr.setNodeMarkup(y,void 0,{...v.attrs,language:i.value}))});const p=document.createElement("button");p.className="amx-code-btn",p.textContent=D("amxcode.copy"),p.title=D("amxcode.copyTitle"),p.addEventListener("click",()=>{const y=t(),v=y===null?null:e.state.doc.nodeAt(y);v&&navigator.clipboard.writeText(v.textContent).then(()=>{p.textContent=D("amxcode.copied"),setTimeout(()=>{p.textContent=D("amxcode.copy")},1200)})});const h=document.createElement("button");h.className=`amx-code-btn${o?" on":""}`,h.textContent=D("amxcode.wrap"),h.title=D("amxcode.wrapTitle"),h.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Ct,{toggle:y}))});const g=document.createElement("button");g.className=`amx-code-btn${s?" on":""}`,g.textContent=s?D("amxcode.linenoOff"):D("amxcode.lineno"),g.title=o?D("amxcode.linenoDisabled"):D("amxcode.linenoTitle"),g.disabled=o,g.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Ct,{toggle:y,which:"lineno"}))});const k=document.createElement("button");if(k.className=`amx-code-btn${a?" on":""}`,k.textContent=a?D("amxcode.expand"):D("amxcode.collapse"),k.title=D("amxcode.collapseTitle"),k.addEventListener("click",()=>{const y=t();y!==null&&e.dispatch(e.state.tr.setMeta(Ct,{toggle:y,which:"collapse"}))}),l.append(i,p,h,g,k),qf(n)&&window.tangu?.pty){const y=document.createElement("button");y.className="amx-code-btn",y.textContent=D("amxcode.run"),y.title=D("amxcode.runTitle"),y.addEventListener("click",()=>{const v=t(),E=v===null?null:e.state.doc.nodeAt(v),S=E?Wf(E.textContent):"";S&&Uf(S)}),l.append(y)}return l}class Ww{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?"":ud(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=Ct.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"&&!!Ff("```forsion-button\n"+this.node.textContent+"\n```"),c=i?"button":`${t}:${n}:${s?1:0}:${a?1:0}:${l?1:0}:${Yd()}`;if(c!==this.barSig){if(i)this.bar?.remove(),this.bar=null;else{const u=qw(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
|
-
`).length,d=Array.from({length:u},(f,m)=>String(m+1)).join(`
|
|
40
|
-
`);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 Uw(){return Z(()=>{const e=new Set;return new te({key:Ct,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:pi(n.doc,r)}},apply(t,n){if(!t.docChanged&&!t.getMeta(Ct))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(Ct);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?pi(t.doc,l):Fw(n.decos,t,l);return{...l,decos:i}}},props:{nodeViews:{code_block:(t,n,r)=>{let o;return o=new Ww(t,n,r,()=>e.delete(o)),e.add(o),o}},decorations(t){return Ct.getState(t)?.decos??pe.empty},handleTextInput:(t,n,r,o)=>om(t,n,r,o),handleKeyDown:(t,n)=>n.key==="Backspace"&&!n.metaKey&&!n.ctrlKey&&!n.altKey&&!n.shiftKey&&!n.isComposing?sm(t):!1}})})}const Vw=["http:","https:"],Gw=/^[^/?#]+\.(?: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 xt(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?Vw.includes(r[1].toLowerCase()+":")?t:null:t.startsWith("//")?"https:"+t:t.startsWith("/")||t.startsWith("#")||t.startsWith("./")||t.startsWith("../")||Gw.test(t)?t:/^[^\s/]+\.[^\s/]/.test(t)?"https://"+t:t}const fd=e=>e.replace(/[?#].*$/,""),pd=e=>{try{return decodeURIComponent(e)}catch{return e}};function mi(e){const t=e.trim();if(!t||t.startsWith("#"))return"other";const n=xt(t);return n?/^https?:/i.test(n)?"external":/\.md$/i.test(pd(fd(t)))?"note":"file":"other"}function hi(e,t,n=[]){const r=pd(fd(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 Yw=ue(()=>new Ye(/\[([^[\]]+)\]\((\S+)\)$/,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=xt(t[2]);return s?e.tr.replaceWith(n,r,e.schema.text(t[1],[o.create({href:s})])).removeStoredMark(o):null})),Xw=/^ {0,3}(?:#{1,6}(?:\s|$)|[-*+]\s|\d{1,9}[.)]\s|>|```|~~~|\|.*\||(?:[-*_][ \t]*){3,}$|\[\^[^\]]+\]:)/,Jw=/\*\*[^*\n]+\*\*|__[^_\n]+__|~~[^~\n]+~~|`[^`\n]+`|!?\[[^\]\n]*\]\([^)\n]*\)|\[\[[^\]\n]+\]\]|\$\$|%%/,Qw=/^ {0,3}(?=[^\n]*\|)(?=[^\n]*-)[|:\- \t]+$/,Zw=/^(?: {4}|\t)/;function e0(e){return e.replace(/\r\n?/g,`
|
|
41
|
-
`).split(`
|
|
42
|
-
`).some(n=>Xw.test(n)||Qw.test(n)||Zw.test(n)&&n.trim()!=="")?!0:Jw.test(e)}function md(e){return e.replace(/\r\n?/g,`
|
|
43
|
-
`).replace(new RegExp("(?<!\\n)\\n(?!\\n)","g"),`
|
|
44
|
-
|
|
45
|
-
`)}function t0(e,t){const n=e.trim();return t||!n||!/\s/.test(n)&&/^https?:\/\//i.test(n)?null:hd(e)?md(e):e}function hd(e){return new RegExp("(?<!\\n)\\n(?!\\n)").test(e.replace(/\r\n?/g,`
|
|
46
|
-
`).trim())&&!e0(e)}function n0(e,t){return t.length!==1||t[0]!=="paragraph"?"literal":e.trim()!==e?"inline-ws":"default"}const gi=",。;:!?、)」』】》",r0=new RegExp(`(?<![A-Za-z])(https?:\\/\\/[^\\s<>\\ufffc${gi}(「『【《]+)([ \\t\\u00a0\\u3000${gi}])$`,"i");function o0(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 s0=ue(()=>new Ye(r0,(e,t,n,r)=>{const o=e.schema.marks.link;if(!o)return null;const s=o0(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=xt(s);return u?e.tr.addMark(n,i,o.create({href:u})).insertText(t[2],r).removeStoredMark(o):null}));let bi=null;function a0(e,t,n){bi??=vi().use(Ci).use(Vo);let r;try{r=bi.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 l0={before:"",after:"",now:{line:1,column:1},lineShift:0};function i0(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,l0));return!/\s/.test(a)&&(s<0||s+1>=o.length)&&(a+=r?.after??""),a}function gd(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:a0(o,r?.before??"",i0(e,t,n,r))?o:null}const bd=Qt.link;function yd(e,t,n,r){const o=gd(e,t,n,r);return o==null?bd(e,t,n,r):n.createTracker(r).move(o)}yd.peek=(e,t,n,r)=>gd(e,t,n,r)!=null?"h":bd.peek(e,t,n,r);const c0=zn(e=>{e.update(Ht,t=>({...t,handlers:{...t.handlers,link:yd}}))}),u0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\#(?=[^\s#])/;function kd(e){return e.includes("\\#")?Ir(e,t=>t.replace(u0,"$1#")):e}const d0=/^((?:[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?|[ \t]*>[ \t]?)*[ \t]*)\\==(?=[^\s=])/;function wd(e){return e.includes("\\==")?Ir(e,t=>t.replace(d0,"$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.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 xd(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 xu(pu(od(ji(kd(wd(Xd(Jd(e))))))))}function vd(e,t){return Hb(e,t,$n)}function Cd(e){return xu(pu(od(ji(kd(wd(e))))))}const Aa="\0__amadeus_embed__",Na="\0__amadeus_linkdb__",Ea="\0__amadeus_bookmark__",Ta="\0__amadeus_template__",Ia="\0__amadeus_image__",La="\0__amadeus_column__",Ra="\0__amadeus_database__",$a="\0__amadeus_drawing__",Sd="\0__amadeus_card__",Md="\0__amadeus_ai__",Da="\0__amadeus_noteview__",_a="\0__amadeus_page__";function f0(e){const t=new fe("amx-placeholder-focus");return Z(()=>new te({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:pe.create(r,[J.node(0,r.firstChild.nodeSize,{class:"is-empty","data-placeholder":e()})])}}}))}function p0(e){if(!e)return null;for(const t of Array.from(e.files))if(t.type.startsWith("image/"))return t;return null}function m0(e){const t=e.state.selection;let n="",r=null;if(t instanceof Ue?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=Yo(l)??l;return!i||/^(?:https?:|data:|blob:)/i.test(i)?null:{reference:``,ref:i}}const o=/^!\[\[([^\]\n]+)\]\]$/.exec(n);if(!o)return null;let s=o[1].replace(/\|\d+\s*$/,"").trim();const a=s.indexOf("#");return a>0&&/\.[a-z0-9]{1,10}$/i.test(s.slice(0,a))&&(s=s.slice(0,a)),s?{reference:n,ref:s}:null}function h0(e,t){if(!e)return null;try{const l=e.getData(Bi).trim();if(l&&(!t||l===t))return l}catch{}const n=Dp(),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 yi(e,t){const n=g0(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 g0(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 ki(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 b0(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 y0(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=b0(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 za({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:k=!1,unified:y=!1,attachmentPagePath:v,extraPlugins:E,onAskTangu:S,aiMenu:N}){const C=T.useRef(!1),_=T.useRef(v);_.current=v;const O=T.useRef(n);O.current=n;const L=T.useRef(r);L.current=r;const oe=T.useRef(o);oe.current=o;const $e=T.useRef(s);$e.current=s;const H=T.useRef(a);H.current=a;const B=T.useRef(()=>!0);B.current=i??(()=>!0);const U=T.useRef(()=>{});U.current=c??(()=>{});const[Ae,Fe]=T.useState(null),[W,G]=T.useState(null),[ve,ke]=T.useState(null),V=T.useRef(null),[ee,we]=T.useState(null),qe=T.useRef(null),[he,Ke]=T.useState(null),[Le,at]=T.useState(null),[gt,Gn]=T.useState(null),Gr=T.useRef(null),Yr=T.useRef(null),Xr=T.useRef(null),un=T.useRef(!1),dn=T.useRef(!1),[Yn,ne]=Wy(),Oa=Oi(),$d=I=>{let A="";return ne()?.action(R=>{A=R.get(Zt)(I)}),Cd(A)};qy(I=>{const A=(M,w)=>{const{state:z}=M,P=z.selection,se=w.key.toLowerCase();if(p&&(w.metaKey||w.ctrlKey)&&(se==="z"||se==="y")){w.preventDefault(),w.stopPropagation();const le=Oa.getState();return se==="y"||w.shiftKey?le.redo():le.undo(),!0}if(w.key===" "&&P.empty&&!w.metaKey&&!w.ctrlKey&&!w.altKey){const le=tk(P.$from);if(le&&Jy(P.$from.parent.type.name,le)&&nk(M,le," "))return w.preventDefault(),!0}if(cd(M,w))return w.preventDefault(),!0;const Se=Fp(w);if(Se){const le=qp(z);if(le)return w.preventDefault(),Me(le,Se==="followNewTab"),!0}if(w.key==="Enter")return w.shiftKey?y?!1:(O.current.insertAfter(sk(M,$d)??void 0),!0):!1;if(!w.metaKey&&!w.ctrlKey&&!w.altKey&&!w.shiftKey&&(w.key==="ArrowLeft"&&Jl(M)||w.key==="Backspace"&&Jl(M,!0)))return w.preventDefault(),!0;if(w.key==="Backspace"){if(y||!P.empty||P.$head.pos!==ce.atStart(z.doc).$head.pos)return!1;const le=P.$head.parent,ge=z.schema.nodes.paragraph;return le.type.name==="heading"&&le.content.size>0&&ge?(M.dispatch(z.tr.setBlockType(P.$head.start(),P.$head.end(),ge)),!0):(ok(M)||(z.doc.textContent.trim()===""?O.current.deleteEmpty():O.current.mergePrev()),!0)}return w.key==="ArrowUp"?y?!1:(w.metaKey||w.ctrlKey)&&w.shiftKey?(O.current.moveDir("up"),!0):P.empty&&!w.metaKey&&!w.ctrlKey&&!w.shiftKey&&!w.altKey&&yi(M,"up")?(O.current.arrow("prev",ki(M)),!0):!1:w.key==="ArrowDown"?y?!1:(w.metaKey||w.ctrlKey)&&w.shiftKey?(O.current.moveDir("down"),!0):P.empty&&!w.metaKey&&!w.ctrlKey&&!w.shiftKey&&!w.altKey&&yi(M,"down")?(O.current.arrow("next",ki(M)),!0):!1:w.key==="Escape"&&p?(M.dom.blur(),Lp.getState().select(p),!0):!1},R=(M,w)=>{const z=()=>M.content.textBetween(0,M.content.size,`
|
|
47
|
-
|
|
48
|
-
`),P=M.content.childCount===1?M.content.firstChild:null,se=P?.type.name==="image"?P:P?.type.name==="paragraph"&&P.childCount===1&&P.firstChild?.type.name==="image"?P.firstChild:null;if(se){const ye=String(se.attrs.src??"");return`??ye})`}const Se=w.state.selection,{$from:me,$to:le}=Se;if(!(Se instanceof Ue||!me.sameParent(le)||me.parentOffset===0&&le.parentOffset===le.parent.content.size))return z();let lt=!1;if(M.content.forEach(ye=>{ye.type.name!=="paragraph"&&(lt=!0)}),!lt)return z();const pn=Se instanceof Ue&&Se.node.type.name==="list_item"&&/_list$/.test(me.parent.type.name)?Q.from(me.parent.type.create(me.parent.attrs,M.content)):M.content,Tt=w.state.schema.topNodeType.createAndFill(void 0,pn);if(!Tt)return z();let It=!1;Tt.descendants(ye=>(/^amadeusCanvasCard$|^amadeusColumn/.test(ye.type.name)&&(It=!0),!It));let be=ig(()=>{let ye="";return ne()?.action(Lt=>{ye=Lt.get(Zt)(Tt)}),$n(ye)});return It&&(be=be.replace(/^<!--\s*\/?a\s+[A-Za-z0-9_-]+\s*-->[ \t]*\n?/gm,"")),ho(be).trim()||z()},$=async(M,w)=>{const z=await L.current(w);if(!z)return;const P=M.state.schema.nodes.image;P&&M.dispatch(M.state.tr.replaceSelectionWith(P.create({src:z})).scrollIntoView())},j=(M,w)=>{const z=M.state.selection,P=(w.clipboardData?.getData("text/plain")??"").trim(),se=h0(w.clipboardData,P);if(se)return P?!1:(w.preventDefault(),M.pasteText(se));const Se=M.state.schema.marks.link;if(Se&&!z.empty&&z.$from.sameParent(z.$to)&&z.$from.parent.type.allowsMarkType(Se)&&P&&!/\s/.test(P)&&/^https?:\/\//i.test(P)){const be=xt(P);if(be)return w.preventDefault(),M.dispatch(M.state.tr.addMark(z.from,z.to,Se.create({href:be}))),!0}const me=p0(w.clipboardData);if(me)return w.preventDefault(),$(M,me),!0;const le=Array.from(w.clipboardData?.files??[]);if(le.length)return w.preventDefault(),oe.current(le),!0;if(y&&z.empty&&P&&!/\s/.test(P)&&/^https?:\/\//i.test(P)&&z.$from.parent.type.name==="paragraph"&&z.$from.parent.content.size===0){w.preventDefault();const be=z.from,it=be+P.length;let ye=null;try{ye=M.coordsAtPos(be)}catch{}return M.dispatch(M.state.tr.insertText(P,be,z.to).setMeta("uiEvent","paste")),ye&&Gn({url:P,from:be,to:it,left:ye.left,top:ye.bottom,anchorTop:ye.top}),!0}const ge=w.clipboardData?.getData("text/plain")??"",lt=w.clipboardData?.getData("text/html")??"",pn=!!z.$from.parent.type.spec.code;if(y&&ge&&!pn&&M.input?.shiftKey){w.preventDefault();const be=ge.replace(/\r\n?/g,`
|
|
49
|
-
`).split(`
|
|
50
|
-
`),it=M.state.schema.nodes.paragraph;if(be.length===1||!it)M.dispatch(M.state.tr.insertText(be.join(" ")).scrollIntoView().setMeta("uiEvent","paste"));else{const ye=Q.from(be.map(Lt=>it.create(null,Lt?M.state.schema.text(Lt):null)));M.dispatch(M.state.tr.replaceSelection(new Te(ye,1,1)).scrollIntoView().setMeta("uiEvent","paste"))}return!0}const Tt=z.$from,It=z.$to;if(y&&ge&&!lt&&!pn&&!/[\r\n]/.test(ge)&&Tt.sameParent(It)&&Tt.parent.isTextblock&&(Tt.parentOffset>0||It.parentOffset<It.parent.content.size)){let be=null;ne()?.action(ye=>{be=ye.get(fr)(ge)??null});const it=be;if(it){const ye=[];it.forEach(Xn=>{ye.push(Xn.type.name)});const Lt=n0(ge,ye);if(Lt==="literal")return w.preventDefault(),M.dispatch(M.state.tr.insertText(ge).scrollIntoView().setMeta("uiEvent","paste")),!0;if(Lt==="inline-ws"){w.preventDefault();const{schema:Xn}=M.state,Wa=/^\s*/.exec(ge)[0],Ua=/\s*$/.exec(ge)[0],Jn=[];return Wa&&Jn.push(Xn.text(Wa)),it.firstChild.forEach(Wd=>{Jn.push(Wd)}),Ua&&Jn.push(Xn.text(Ua)),M.dispatch(M.state.tr.replaceSelection(new Te(Q.from(Jn),0,0)).scrollIntoView().setMeta("uiEvent","paste")),!0}}}if(y&&ge&&!lt&&!pn&&hd(ge)){const be=new DataTransfer;return be.setData("text/plain",md(ge)),w.preventDefault(),M.pasteText(be.getData("text/plain"),new ClipboardEvent("paste",{clipboardData:be}))}return!1},Y=(M,w)=>{if(!v||!ze.copyAttachment)return!1;const z=m0(M),P=w;if(!z||!P.clipboardData)return!1;P.preventDefault(),P.clipboardData.clearData(),P.clipboardData.setData("text/plain",z.reference);try{P.clipboardData.setData(Bi,z.reference)}catch{}return ze.copyAttachment(v,z.ref,z.reference).then(se=>{se&&Rp(z.reference,z.ref)}),!0};let re=!1;const Ce=()=>(re=!0,queueMicrotask(()=>{re=!1}),!1),Me=(M,w)=>{const z=w?{newTab:!0}:void 0;if(M.kind==="wiki")return $e.current(M.arg,z);const P=mi(M.href);if(P==="note")return $e.current(hi(M.href,_.current,H.current()),z);if(P==="file"){_.current&&ze.openAttachment(_.current,M.href);return}const se=xt(M.href);se&&window.open(se,"_blank","noopener")},je=(M,w,z)=>{if(z.button===2||el&&z.ctrlKey)return!1;const P=z.target?.closest?.("a[href]");if(!P||!P.getAttribute("href"))return!1;const se=mi(P.getAttribute("href"));if(se==="file")return!1;if(se==="note"){z.preventDefault();const me=z.button===1||(el?z.metaKey:z.ctrlKey);return $e.current(hi(P.getAttribute("href"),_.current,H.current()),me?{newTab:!0}:void 0),!0}const Se=xt(P.getAttribute("href"));return Se?(z.preventDefault(),window.open(Se,"_blank","noopener"),!0):!1};return Ep.make().config(M=>{M.set(Tp,I),M.set(Ip,e),M.update(Di,w=>({...w,editable:()=>!k,handleKeyDown:k?void 0:A,handlePaste:k?void 0:j,handleDOMEvents:k?w.handleDOMEvents:{...w.handleDOMEvents,copy:Y,drop:Ce},clipboardTextParser:k?void 0:(z,P,se,Se)=>{if(!re)return null;re=!1;const me=t0(z,se);if(me==null)return null;const le=M.get(fr)(me);if(!le||typeof le=="string")return null;const ge=zi.fromSchema(Se.state.schema).serializeFragment(le.content);return _i.fromSchema(Se.state.schema).parseSlice(ge)},handleClick:je,clipboardTextSerializer:R})),y?M.get(Mr).updated((w,z)=>{!C.current||k||t(vd(w,z))}):M.get(Mr).markdownUpdated((w,z)=>{!C.current||k||t($n(z))})}).use(Ja("high",{pagePath:()=>_.current})).use(ey).use(Mb).use(Qg).use(Mw).use(bg).use(vg).use(hg).use(c0).use(y?jg:Hg).use(Lw).use(ru).use(Io).use(Lo).use(Cg).use(Sg).use(Mg).use(ro).use(Ml).use(Al).use(Kp()).use(Rg()).use(my).use(ju).use(f0(()=>D("mdblock.placeholder"))).use(pk()).use(jp((M,w)=>$e.current(M,w),M=>B.current(M),M=>U.current(M))).use(Hp(Me)).use(Z(()=>new te({props:{attributes:()=>_.current?{"data-amx-src":_.current}:{}}}))).use(Z(()=>new te({view:M=>{const w=()=>{M.dom.setAttribute("aria-label",D("mdblock.editorLabel"))};return w(),{destroy:Xo(w)}}}))).use(vw()).use(Yy()).use(yk((M,w)=>{if(!M){w||(Xr.current=null),un.current=!1,Fe(null);return}if(Xr.current===M.from){un.current=!1,Fe(null);return}un.current=!0,Fe(M)})).use(wk((M,w)=>{if(!M){w||(Gr.current=null),dn.current=!1,G(null);return}if(Gr.current===M.from){dn.current=!1;return}dn.current=!0,G(M)})).use(Qk((M,w)=>{if(!M){w||(V.current=null),ke(null);return}if(V.current===M.from){ke(null);return}ke(M)})).use(nw((M,w)=>{if(!M){w||(qe.current=null),we(null);return}if(qe.current===M.from){we(null);return}we(M)})).use(kk((M,w)=>{if(h){if(!M){w||(Yr.current=null),Ke(null);return}if(un.current||dn.current){Ke(null);return}if(Yr.current===M.from){Ke(null);return}Ke(M)}})).use(Ck(M=>at(h?M:null))).use(Lu).use(Ew()).use(Pw()).use(Uw()).use(tm).use(Uy).use(Z(M=>Qa({"Mod-u":()=>(M.get(ae).call(ro.key),!0),"Mod-Shift-s":()=>(M.get(ae).call(Nn.key),!0),"Mod-k":()=>Fa(),"Mod-Shift-v":(w,z,P)=>!P?.editable||!navigator.clipboard?.readText?!1:(navigator.clipboard.readText().then(se=>{se&&!P.isDestroyed&&P.pasteText(se)}).catch(()=>{}),!0),"Mod-Shift-h":$g,"Alt-F10":()=>{const w=document.querySelector('[data-testid="inline-toolbar"] .itb-row button');return w?(w.focus(),!0):!1},"Mod-Shift-l":(w,z)=>nr(w,z,"left"),"Mod-Shift-e":(w,z)=>nr(w,z,"center"),"Mod-Shift-r":(w,z)=>nr(w,z,"right")}))).use(Z(()=>Qa({Tab:(M,w,z)=>y?!1:ry(M,w,z),"Shift-Tab":(M,w)=>y?!1:oy(M,w)}))).use(Yw).use(s0).use(bk).use(pw).use(kw).use(Ja("normal",{pagePath:()=>_.current})).use(E??[])},[]),T.useEffect(()=>{if(h)return h.current={consume:()=>{let I=!0;return ne()?.action(A=>{const R=A.get(ie),{$from:$,empty:j}=R.state.selection;if(j){const Y=Gl($);Y&&R.dispatch(R.state.tr.delete(Y.from,Y.to))}I=R.state.doc.textContent.trim()===""}),I},transform:I=>{let A=!1;return ne()?.action(R=>{const $=R.get(ie),{$from:j,empty:Y}=$.state.selection;A=Bt($,I,Y?Gl(j):null),$.focus()}),A}},()=>{h&&(h.current=null)}},[h,ne]),T.useEffect(()=>{const I=requestAnimationFrame(()=>{C.current=!0});return()=>cancelAnimationFrame(I)},[]);const Pa=I=>A=>!(A.target instanceof Element&&A.target.closest(I)),Ba=!!he;T.useEffect(()=>{if(!Ba)return;const I=Pa(".slash-menu"),A=$=>{I($)&&Ke(null)},R=()=>Ke(null);return window.addEventListener("scroll",A,!0),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",R)}},[Ba]);const Ka=!!Le;T.useEffect(()=>{if(!Ka)return;const I=Pa(".inline-toolbar"),A=$=>{I($)&&at(null)},R=()=>at(null);return window.addEventListener("scroll",A,!0),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",R)}},[Ka]);const ja=!!gt;T.useEffect(()=>{if(!ja)return;const I=()=>Gn(null);return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[ja]);const Dd=I=>{const A=gt;Gn(null),A&&ne()?.action(R=>{const $=R.get(ie);if(!(A.to>$.state.doc.content.size||$.state.doc.textBetween(A.from,A.to)!==A.url)){if(I==="bookmark"){const j=$.state.doc.resolve(A.to),Y=j.after(j.depth),re=$.state.tr,Ce=re.doc.nodeAt(Y),Me=$.state.schema.nodes.paragraph;Me&&!(Ce?.type.name==="paragraph"&&Ce.content.size===0)&&re.insert(Y,Me.create()),re.setSelection(K.near(re.doc.resolve(Math.min(Y+1,re.doc.content.size)))),$.dispatch(re),$.focus();return}if(I==="embed"){const j=`![[${Qd(A.url)}]]`,Y=$.state.tr.insertText(j,A.from,A.to),re=Y.doc.resolve(Math.min(A.from+j.length,Y.doc.content.size)),Ce=re.after(re.depth),Me=Y.doc.nodeAt(Ce),je=$.state.schema.nodes.paragraph;je&&!(Me?.type.name==="paragraph"&&Me.content.size===0)&&Y.insert(Ce,je.create()),Y.setSelection(K.near(Y.doc.resolve(Math.min(Ce+1,Y.doc.content.size)))),$.dispatch(Y)}else{const j=$.state.schema.marks.link,Y=Tr(A.url),re=$.state.tr.insertText(Y,A.from,A.to);j&&re.addMark(A.from,A.from+Y.length,j.create({href:xt(A.url)||A.url})),$.dispatch(re)}$.focus()}})};T.useEffect(()=>{if(u==null||Yn)return;const I=ne();I&&(I.action(A=>{const R=A.get(ie);if(R.focus(),u==="body-enter"){const re=R.state.schema.nodes.paragraph,Ce=R.state.doc.firstChild;let Me=R.state.tr;re&&!(Ce&&Ce.type===re&&Ce.content.size===0)&&(Me=Me.insert(0,re.create())),R.dispatch(Me.setSelection(K.near(Me.doc.resolve(1))).scrollIntoView());return}const $=u==="end"?ce.atEnd(R.state.doc):ce.atStart(R.state.doc);R.dispatch(R.state.tr.setSelection($).scrollIntoView());const j=d!=null?y0(R,u,d):null;j!=null&&R.dispatch(R.state.tr.setSelection(K.near(R.state.doc.resolve(j))).scrollIntoView());const Y=f?rk(R,f):null;Y!=null&&R.dispatch(R.state.tr.setSelection(K.near(R.state.doc.resolve(Y))).scrollIntoView())}),m())},[u,d,f,Yn,ne,m]),T.useEffect(()=>Oa.subscribe((I,A)=>{I.pages===A.pages||Yn||ne()?.action(R=>{const $=R.get(ie);$.dispatch($.state.tr)})}),[Yn,ne]);const _d=I=>{const A=Ae;A&&ne()?.action($=>{const j=$.get(ie),{doc:Y}=j.state;if(A.closeAt!==void 0&&Y.textBetween(A.closeAt,Math.min(A.closeAt+2,Y.content.size))==="]]"){const re=Cw(Y.textBetween(A.to,A.closeAt,void 0,""),I),Ce=j.state.tr.insertText(re,A.from,A.closeAt);j.dispatch(Ce.setSelection(K.create(Ce.doc,A.from+re.length+2)))}else j.dispatch(j.state.tr.insertText(`${I}]]`,A.from,A.to));j.focus()}),Fe(null)},fn=()=>{let I=!1;return ne()?.action(A=>{I=A.get(ie).hasFocus()}),I},zd=()=>{let I=null;return ne()?.action(A=>{I=A.get(ie).dom}),I},Od=I=>{const A=W;A&&ne()?.action($=>{const j=$.get(ie);j.dispatch(j.state.tr.insertText(`[[${I}]]`,A.from-1,A.to)),j.focus()}),G(null)},Pd=I=>{const A=W;A&&ne()?.action($=>{const j=$.get(ie);j.dispatch(j.state.tr.insertText(`${I} `,A.from-1,A.to)),j.focus()}),G(null)},Bd=I=>{const A=ve;A&&ne()?.action(R=>{const $=R.get(ie),j=$.state.doc.textBetween(A.to,Math.min(A.to+1,$.state.doc.content.size),void 0,"");$.dispatch($.state.tr.insertText(/^\s/.test(j)?I:`${I} `,A.from,A.to)),$.focus()}),ke(null)},Kd=I=>{const A=ee;A&&ne()?.action(R=>{const $=R.get(ie);$.dispatch($.state.tr.insertText(I,A.from-1,A.to)),$.focus()}),we(null)},Ha=()=>{const I=a(),A=new Set(I),R=Vf().filter(j=>A.has(j)),$=new Set(R);return[...R,...I.filter(j=>!$.has(j))]},Et=(I,A)=>{ne()?.action(R=>{R.get(ae).call(I,A),R.get(ie).focus()})},Fa=()=>{const I=ne();if(!I)return!1;let A=!1;return I.action(R=>{const $=R.get(ie),j=Ve.type(R),{from:Y,to:re,empty:Ce,$from:Me}=$.state.selection;if(!Me.parent.isTextblock||Me.parent.type.spec.code)return;A=!0;const je=Id($.state.doc,Y,re,j),M=$.state.doc,w=je??{from:Y,to:re};(je?Jf(D("mdblock.link.editTitle"),je.href,{label:D("mdblock.link.label"),altLabel:D("mdblock.link.remove")}):bo(D("mdblock.link.title"),"",{label:D("mdblock.link.label")})).then(P=>{const se=P===null||P===Qr?null:xt(P);P!==Qr&&!se||ne()?.action(Se=>{const me=Se.get(ie);if(me.state.doc!==M)return;const le=Ve.type(Se);if(P===Qr)me.dispatch(me.state.tr.removeMark(w.from,w.to,le));else if(w.to>w.from)me.dispatch(me.state.tr.removeMark(w.from,w.to,le).addMark(w.from,w.to,le.create({href:se})));else if(se){const ge=Tr(se),lt=me.state.tr.insertText(ge,w.from);lt.addMark(w.from,w.from+ge.length,le.create({href:se})),me.dispatch(lt.setSelection(K.create(lt.doc,w.from+ge.length)).scrollIntoView())}me.focus()})})}),A},jd=()=>{ne()?.action(I=>{const A=I.get(ie),{from:R,to:$,empty:j}=A.state.selection;j||A.dispatch(A.state.tr.removeMark(R,$,null)),A.focus()})},Jr=I=>{ne()?.action(A=>{const R=A.get(ie);nr(R.state,$=>R.dispatch($),I),R.focus()})},Hd={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"}},Fd=I=>{let A=!1;return ne()?.action(R=>{const $=R.get(ie),{state:j}=$;if(Vu(j.selection).tableCell)return;const{$from:Y,$to:re}=j.selection,Ce=Y.before(Y.depth),Me=re.after(re.depth),je=j.doc.textBetween(Ce,Me,`
|
|
51
|
-
`,`
|
|
52
|
-
`).trim(),M=I==="codeblock"?j.schema.nodes.code_block?.create(null,je?j.schema.text(je):void 0):j.schema.nodes.paragraph?.create(null,j.schema.text(`$$ ${je} $$`));if(!M)return;const w=j.tr.replaceWith(Ce,Me,M);w.setSelection(K.near(w.doc.resolve(Ce+1))),$.dispatch(w.scrollIntoView()),$.focus(),A=!0}),A},qa=I=>{const A=Nk[I];window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:D("mdblock.turn.failed",{kind:A?D(A):I})}}))},qd=I=>{if(I==="codeblock"||I==="math"){Fd(I)||qa(I);return}const A=Hd[I];if(A){let $=!1;ne()?.action(j=>{const Y=j.get(ie);$=Bt(Y,A,null),Y.focus()}),$||qa(I);return}({bold:()=>Et($r.key),italic:()=>Et(Rr.key),underline:()=>Et(ro.key),strike:()=>Et(Nn.key),code:()=>Et(Dr.key),link:Fa,clear:jd,alignLeft:()=>Jr("left"),alignCenter:()=>Jr("center"),alignRight:()=>Jr("right")})[I]?.()};return b.jsxs(b.Fragment,{children:[b.jsx(Fy,{}),b.jsxs(Pi,{children:[Ae&&!k&&b.jsx(ri,{query:Ae.query,left:Ae.left,top:Ae.top,anchorTop:Ae.anchorTop,getPageNames:Ha,getFiles:l,onPick:_d,onClose:()=>{Xr.current=Ae.from,un.current=!1,Fe(null)},editorFocused:fn,sourcePath:v}),!Ae&&W&&!k&&b.jsx(ri,{query:W.query,left:W.left,top:W.top,anchorTop:W.anchorTop,getPageNames:Ha,getFiles:l,onPick:Od,onPickRaw:Pd,editorFocused:fn,dates:!0,allowCreate:!1,onClose:()=>{Gr.current=W.from,dn.current=!1,G(null)}}),ve&&!Ae&&!W&&!k&&b.jsx(ew,{query:ve.query,left:ve.left,top:ve.top,anchorTop:ve.anchorTop,onPick:Bd,editorFocused:fn,onClose:()=>{V.current=ve.from,ke(null)}}),ee&&!Ae&&!W&&!ve&&!he&&!k&&b.jsx(rw,{query:ee.query,left:ee.left,top:ee.top,anchorTop:ee.anchorTop,onPick:Kd,editorFocused:fn,onClose:()=>{qe.current=ee.from,we(null)}}),he&&g&&!Ae&&!W&&!k&&b.jsx(N0,{query:he.query,left:he.left,top:he.top,anchorTop:he.anchorTop,hideKeys:y?v0:void 0,ctx:he.ctx,unified:y,editorFocused:fn,editorDom:zd,onPick:I=>{Ke(null),ne()?.action(A=>{Ql(A.get(ie),he.from)}),g(I)},onClose:()=>{let I=!1;ne()?.action(A=>{const R=A.get(ie);if(!Ql(R,he.from))return;const{doc:$}=R.state;he.from<1||he.to>$.content.size||$.textBetween(he.from-1,he.from)!=="/"||(R.dispatch(R.state.tr.delete(he.from-1,he.to)),I=!0)}),I||(Yr.current=he.from),Ke(null)}}),gt&&!k&&b.jsx(A0,{left:gt.left,top:gt.top,anchorTop:gt.anchorTop,url:gt.url,onPick:Dd,onClose:()=>Gn(null)}),Le&&!Ae&&!W&&!he&&!gt&&!k&&b.jsx(Ek,{left:Le.left,top:Le.top,bottom:Le.bottom,kind:Le.kind,active:Le.active,align:Le.align,shape:Le.shape,fg:Le.fg,bg:Le.bg,onAct:qd,onColor:I=>Et(Ml.key,I||void 0),onBg:I=>Et(Al.key,I||void 0),onClose:()=>{at(null),ne()?.action(I=>{const A=I.get(ie);A.dispatch(A.state.tr.setMeta(cr,!0))})},onReturnFocus:()=>ne()?.action(I=>I.get(ie).focus()),onAsk:S?()=>{at(null),ne()?.action(I=>S(I.get(ie)))}:void 0,ai:N?{items:N.items,onPick:I=>{at(null),ne()?.action(A=>N.onPick(I,A.get(ie)))}}:void 0})]})]})}function Ad({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:k=!1}){const y=Oi(),v=n.split("/").slice(0,-1).join("/"),E=T.useRef(t),[S,N]=T.useState(0),[C,_]=T.useState(!1),O=T.useRef(null);t!==E.current&&(E.current=t,N(W=>W+1));const L=W=>{const G=sf(W,v);E.current=G,r(G)},oe=async W=>{if(!n)return null;try{const G=new Uint8Array(await W.arrayBuffer()),{opts:ve}=await Zr(),{pageRel:ke}=await ze.saveAttachment(n,W.name||"pasted.png",G,ve);return Mi(of(v,ke))}catch{return null}},$e=async W=>{if(!n)return;const G=[];for(const ve of W)try{const ke=new Uint8Array(await ve.arrayBuffer()),{opts:V}=await Zr(),{base:ee}=await ze.saveAttachment(n,ve.name||"file",ke,V);G.push(`![[${ee}]]`)}catch{}G.length&&(t.trim()===""?(r(G[0]),G.length>1&&y.getState().insertBlocksAfter(e,G.slice(1))):y.getState().insertBlocksAfter(e,G))},H={insertAfter:o,deleteEmpty:s,mergePrev:a,arrow:l,moveDir:i,selfFocus:m},B=(W,G)=>{const ve=y.getState();if(ve.activePage!==n||!ve.blocks[e]){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:D("mdblock.toast.staleTarget")}}));return}const ke=(ve.blocks[e].content??"").trim()==="";G&&ke?r(W):o(W)},U=async W=>{const G=W.scaffold;if(!O.current)return;const ve=W.run?void 0:Nd[G];if(ve){O.current.transform(ve)||Ld(W.label);return}const ke=O.current.consume();if(W.run){try{const V=await W.run({pagePath:n,folder:Qn(n)});if(V!==""&&V!=null){if(typeof V!="string")throw new Error(D("mdblock.plugin.runNotString",{type:typeof V}));if(V.length>8192)throw new Error(D("mdblock.plugin.runTooLong"));if(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(V))throw new Error(D("mdblock.plugin.runControlChars"));B(V,ke),y.getState().syncFdChildren(n)}}catch(V){console.error("[plugin] slash item failed",V),window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:D("mdblock.toast.slashFailed",{label:W.label,message:V instanceof Error?V.message:String(V)}),error:!0}}))}return}if(G===Ta){window.dispatchEvent(new CustomEvent("amadeus:template-picker",{detail:{afterId:e,emptyBlock:ke}}));return}if(G===Ia){const V=document.createElement("input");V.type="file",V.accept="image/*",V.onchange=()=>{const ee=V.files?.[0];ee&&(async()=>{try{const we=new Uint8Array(await ee.arrayBuffer()),{opts:qe}=await Zr(),{base:he}=await ze.saveAttachment(n,ee.name||"image.png",we,qe),Ke=`![[${he}]]`;B(Ke,ke)}catch{}})()},V.click();return}if(G===_a){(async()=>{try{const V=y.getState(),ee=await V.createChildNote(n,D("mdblock.default.childNote")),qe=`[[${ee.split("/").pop().replace(/\.md$/i,"")}]]`;B(qe,ke),V.loadPage(ee)}catch{}})();return}if(G===Ra){(async()=>{try{const V=D("mdblock.default.database"),ee=new TextEncoder().encode(Xa(ef(V))),{base:we}=await ze.saveAttachment(n,`${V}.db`,ee,{mode:"vault",folder:Qn(n)}),qe=`![[${we}]]`;B(qe,ke),y.getState().syncFdChildren(n)}catch{}})();return}if(G===$a){(async()=>{try{const V=new TextEncoder().encode(tf(nf)),we=`![[${(await ze.saveAttachment(n,`${xd(D("mdblock.default.drawing"))}.excalidraw.md`,V,{mode:"vault",folder:Qn(n)})).base.replace(/\.md$/i,"")}]]`;B(we,ke),y.getState().syncFdChildren(n)}catch{}})();return}if(G===Da){(async()=>{try{const V=Qn(n);let ee=null;for(let Le=1;Le<=20&&ee===null;Le++)try{const at=D("mdblock.default.noteViewFolder");ee=await ze.createFolder(V,Le===1?at:`${at} ${Le}`)}catch{}if(ee===null)return;const we=D("mdblock.default.noteView"),qe=new TextEncoder().encode(Xa(rf(we,ee))),{base:he}=await ze.saveAttachment(n,`${we}.db`,qe,{mode:"vault",folder:V}),Ke=`![[${he}]]`;B(Ke,ke),y.getState().syncFdChildren(n)}catch{}})();return}if(G===La){y.getState().splitToColumn(e,"right");return}if(G===Na){_(!0);return}if(G===Ea){bo(D("mdblock.bookmark.title"),"",{label:D("mdblock.bookmark.label")}).then(V=>{const ee=V?.trim();ee&&/^https?:\/\/\S+$/i.test(ee)&&(ke?r(ee):o(ee))});return}if(G===Aa){if(!h)return;let V="";try{const ee=await navigator.clipboard.readText(),we=/!\[\[([^\]\n]+)\]\]/.exec(ee);we&&(V=we[1].trim())}catch{}bo(D("mdblock.embed.title"),V,{label:D("mdblock.embed.label"),confirmLabel:D("mdblock.embed.confirm")}).then(ee=>{const we=ee?.trim().replace(/^!?\[\[/,"").replace(/\]\]$/,"").trim();we&&h(we)});return}ke?(r(G),setTimeout(()=>m("end"),0)):o(G)},Ae=T.useRef(()=>{});Ae.current=W=>{U(W)};const Fe=T.useRef(W=>Ae.current(W)).current;return T.useEffect(()=>()=>{Sn===Fe&&(Sn=null)},[Fe]),b.jsxs("div",{className:"md-block",onFocusCapture:()=>{k||(Sn=Fe)},children:[b.jsx(Hu,{children:b.jsx(za,{initial:Zd(t,v),onChange:L,keys:H,saveImage:oe,saveFiles:$e,onOpenWiki:p,getPageNames:g,blockId:e,slashOpsRef:O,onSlashPick:U,getFiles:()=>Np()?y.getState().files:[],isWikiResolved:W=>!!mo(W,g(),n)||!!Ap(W,y.getState().files,n),wikiIcon:W=>{const G=mo(W,g(),n);return G?y.getState().icons[G]:void 0},focusPlace:c,focusGoalX:u,focusAnchor:d,onFocused:f,attachmentPagePath:n,readOnly:k})},`${S}:${k?1:0}`),C&&!k&&b.jsx(Pi,{children:b.jsx(Rd,{onClose:()=>_(!1),onPick:W=>{_(!1);const G=`![[${W}]]`;t.trim()===""?r(G):o(G)}})})]})}function k0({initial:e,onChange:t,readOnly:n=!1,immediate:r=!1}){const o=T.useRef(t);o.current=t;const s=T.useRef(e);s.current=e;const a=T.useRef(null),l=T.useRef(!1),i=T.useRef(null),c=p=>{const h=ho($n(p));i.current!==h&&(i.current=h,l.current||o.current(h))},u=T.useRef(c);u.current=c;const d=T.useMemo(()=>r?[Z(p=>new te({view:h=>{const g=()=>{if(h.isDestroyed||s.current===i.current)return;const k=p.get(fr)(Ya(s.current));if(!(!k||k.eq(h.state.doc))){l.current=!0;try{h.dispatch(h.state.tr.replaceWith(0,h.state.doc.content.size,k.content).setMeta("addToHistory",!1))}finally{l.current=!1}}};return a.current=g,queueMicrotask(()=>{a.current===g&&g()}),{update:(k,y)=>{k.state.doc.eq(y.doc)||u.current(p.get(Zt)(k.state.doc))},destroy:()=>{a.current===g&&(a.current=null)}}}}))]:void 0,[r]);T.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(Hu,{children:b.jsx(za,{initial:Ya(e),onChange:r?f:p=>t(ho(p)),extraPlugins:d,keys:m,saveImage:async()=>null,saveFiles:async()=>{},onOpenWiki:f,getPageNames:()=>[],focusPlace:null,onFocused:f,readOnly:n})})})}function w0(e){const t=n=>e("amadeus.default.tableColumn",{n});return`| ${t(1)} | ${t(2)} |
|
|
53
|
-
| --- | --- |
|
|
54
|
-
| | |`}const x0={embed:Aa,linkdb:Na,bookmark:Ea,template:Ta,image:Ia,column:La,database:Ra,drawing:$a,noteview:Da,page:_a,card:Sd,ai:Md},Nd={"":{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"}},Ed=[{key:"ai",labelKey:"mdblock.slash.ai",hint:"AI",icon:b.jsx(Qf,{width:"1em",height:"1em",strokeWidth:1.6}),groupKey:"mdblock.group.basic",scaffold:Md,kw:"ai 人工智能 写作 xiezuo 续写 xuxie 生成 tangu ask 问",unifiedOnly:!0,needsAi:!0},{key:"text",labelKey:"mdblock.slash.text",hint:"",icon:b.jsx(Zf,{}),groupKey:"mdblock.group.basic",scaffold:"",kw:"text 文本 paragraph zhengwen 正文"},{key:"h1",labelKey:"mdblock.slash.h1",hint:"#",icon:b.jsx(ep,{}),groupKey:"mdblock.group.basic",scaffold:"# ",kw:"h1 heading 标题 biaoti title 大标题"},{key:"h2",labelKey:"mdblock.slash.h2",hint:"##",icon:b.jsx(tp,{}),groupKey:"mdblock.group.basic",scaffold:"## ",kw:"h2 heading 标题 biaoti 中标题"},{key:"h3",labelKey:"mdblock.slash.h3",hint:"###",icon:b.jsx(np,{}),groupKey:"mdblock.group.basic",scaffold:"### ",kw:"h3 heading 标题 biaoti 小标题"},{key:"h4",labelKey:"mdblock.slash.h4",hint:"####",icon:b.jsx(rp,{}),groupKey:"mdblock.group.basic",scaffold:"#### ",kw:"h4 heading 标题 biaoti 四级"},{key:"h5",labelKey:"mdblock.slash.h5",hint:"#####",icon:b.jsx(op,{}),groupKey:"mdblock.group.basic",scaffold:"##### ",kw:"h5 heading 标题 biaoti 五级"},{key:"h6",labelKey:"mdblock.slash.h6",hint:"######",icon:b.jsx(sp,{}),groupKey:"mdblock.group.basic",scaffold:"###### ",kw:"h6 heading 标题 biaoti 六级"},{key:"ul",labelKey:"mdblock.slash.ul",hint:"-",icon:b.jsx(ap,{}),groupKey:"mdblock.group.list",scaffold:"- ",kw:"ul bullet list 无序 列表 liebiao"},{key:"ol",labelKey:"mdblock.slash.ol",hint:"1.",icon:b.jsx(lp,{}),groupKey:"mdblock.group.list",scaffold:"1. ",kw:"ol number list 有序 列表 编号"},{key:"todo",labelKey:"mdblock.slash.todo",hint:"[ ]",icon:b.jsx(ip,{}),groupKey:"mdblock.group.list",scaffold:"- [ ] ",kw:"todo task check 待办 任务 复选框 daiban renwu"},{key:"card",labelKey:"mdblock.slash.card",hint:"Canvas",icon:b.jsx(cp,{}),groupKey:"mdblock.group.basic",scaffold:Sd,kw:"card 卡片 node 节点 canvas 画布",unifiedOnly:!0},{key:"quote",labelKey:"mdblock.slash.quote",hint:"|",icon:b.jsx(up,{}),groupKey:"mdblock.group.advanced",scaffold:"| ",kw:"quote 引用 yinyong blockquote"},{key:"fold",labelKey:"mdblock.slash.fold",hint:">",icon:b.jsx(dp,{}),groupKey:"mdblock.group.advanced",scaffold:"> ",kw:"fold toggle 折叠 zhedie collapse 展开 详情 details"},{key:"code",labelKey:"mdblock.slash.code",hint:"```",icon:b.jsx(fp,{}),groupKey:"mdblock.group.advanced",scaffold:"```\n\n```",kw:"code 代码 daima codeblock"},{key:"table",labelKey:"mdblock.slash.table",hint:"⊞",icon:b.jsx(pp,{}),groupKey:"mdblock.group.advanced",scaffold:w0,kw:"table 表格 biaoge grid 网格"},{key:"divider",labelKey:"mdblock.slash.divider",hint:"---",icon:b.jsx(mp,{}),groupKey:"mdblock.group.advanced",scaffold:`---
|
|
55
|
-
|
|
56
|
-
`,kw:"divider hr 分割线 分隔 fenge"},{key:"math",labelKey:"mdblock.slash.math",hint:"$$",icon:b.jsx(hp,{}),groupKey:"mdblock.group.advanced",scaffold:"$$ $$",kw:"math latex katex formula 数学 公式 gongshi"},{key:"wikilink",labelKey:"mdblock.slash.wikilink",hint:"[[",icon:b.jsx(gp,{}),groupKey:"mdblock.group.advanced",scaffold:"[[",kw:"link wiki note 链接 笔记 双链 lianjie shuanglian"},{key:"image",labelKey:"mdblock.slash.image",hint:"",icon:b.jsx(bp,{}),groupKey:"mdblock.group.advanced",scaffold:Ia,kw:"image picture photo 图片 tupian 插图"},{key:"columns",labelKey:"mdblock.slash.columns",hint:"⫿",icon:b.jsx(yp,{}),groupKey:"mdblock.group.advanced",scaffold:La,kw:"column split 分栏 分列 fenlan 并排"},{key:"page",labelKey:"mdblock.slash.page",hint:".fd",icon:b.jsx(kp,{}),groupKey:"mdblock.group.advanced",scaffold:_a,kw:"page 页面 子页面 subpage child yemian xinjian 新建页面 notion"},{key:"database",labelKey:"mdblock.slash.database",hint:".db",icon:b.jsx(pr,{}),groupKey:"mdblock.group.advanced",scaffold:Ra,kw:"database db 多维表 duoweibiao 数据库 shujuku 表格 base notion"},{key:"drawing",labelKey:"mdblock.slash.drawing",hint:"Excalidraw",icon:b.jsx(wp,{}),groupKey:"mdblock.group.advanced",scaffold:$a,kw:"drawing draw excalidraw 画板 huaban 手绘 白板 whiteboard 草图 sketch 流程图"},{key:"linkdb",labelKey:"mdblock.slash.linkdb",hint:"![[.db]]",icon:b.jsx(pr,{}),groupKey:"mdblock.group.advanced",scaffold:Na,kw:"link database db 链接多维表 链接数据库 引用数据库 嵌入数据库 已有 lianjie duoweibiao shujuku"},{key:"noteview",labelKey:"mdblock.slash.noteview",hint:"Bases",icon:b.jsx(xp,{}),groupKey:"mdblock.group.advanced",scaffold:Da,kw:"noteview bases 笔记视图 bijishitu 行即笔记 folder page 多维表 notion"},{key:"template",labelKey:"mdblock.slash.template",hint:"templates/",icon:b.jsx(vp,{}),groupKey:"mdblock.group.advanced",scaffold:Ta,kw:"template 模板 muban 套用"},{key:"embed",labelKey:"mdblock.slash.embed",hint:"![[ ]]",icon:b.jsx(Cp,{}),groupKey:"mdblock.group.advanced",scaffold:Aa,kw:"embed 嵌入 引用 transclude block 块 qianru yinyong 复用"},{key:"bookmark",labelKey:"mdblock.slash.bookmark",hint:"https://",icon:b.jsx(Sp,{}),groupKey:"mdblock.group.advanced",scaffold:Ea,kw:"bookmark link url 书签 链接 网页 网址 shuqian youtube 视频"},{key:"button",labelKey:"mdblock.slash.button",hint:"",icon:b.jsx(Mp,{}),groupKey:"mdblock.group.advanced",scaffold:Yf,kw:"button 按钮 anniu 自动化 automation 一键 yijian 快捷 notion"}],v0=new Set;function dr(e){return typeof e=="function"?e():e}function Td({unified:e=!1}={}){const{t}=nn(),n=Gf(s=>s.slashItems),r=[...Ed.map(({labelKey:s,groupKey:a,scaffold:l,...i})=>({...i,label:t(s),group:t(a),scaffold:typeof l=="function"?l(t):l})),...n.map(({item:s})=>({key:s.id,label:dr(s.label),hint:s.hint??"",icon:Xf(s.icon,"·"),group:dr(s.group)??t("mdblock.group.plugin"),scaffold:s.scaffold??"",run:s.run,kw:`${s.keywords??""} ${dr(s.label)}`}))],o=!!_p()?.complete;return r.filter(s=>(e||!s.unifiedOnly)&&(o||!s.needsAi))}let Sn=null;function C0(){return Sn}function S0(e){Sn=e}function M0(e,t){let n=null;for(const r of[t.label,...t.kw.split(/\s+/)]){const o=Dt(e,r);o!==null&&(n=n===null?o:Math.max(n,o))}return n}function Id(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 Ld(e){window.dispatchEvent(new CustomEvent("amadeus:toast",{detail:{text:D("mdblock.turn.failed",{kind:e})}}))}function Tr(e){try{return new URL(e).hostname.replace(/^www\./,"")||e}catch{return e}}function A0({left:e,top:t,anchorTop:n,url:r,onPick:o,onClose:s}){const{t:a}=nn(),l=[{k:"link",label:a("mdblock.pasteAs.link"),hint:Tr(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]=T.useState(-1),u=T.useRef(-1);return u.current=i,T.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(rn,{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 N0({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}=nn(),[f,m]=T.useState(0),p=`amx-slash-${T.useId().replace(/[^\w-]/g,"")}`,h=T.useRef(i);h.current=i;const g=Td({unified:a}),k=T.useMemo(()=>g.filter(C=>!o?.has(C.key)&&(!s||gk(C.key,s))),[g,o,s]),y=e.trim().toLowerCase(),v=y?k.map(C=>({it:C,s:M0(y,C)})).filter(C=>C.s!==null).sort((C,_)=>_.s-C.s).map(C=>C.it):k;T.useEffect(()=>{m(0)},[e]);const E=v.length?Math.min(f,v.length-1):-1;T.useEffect(()=>{const C=h.current?.();if(C)return C.setAttribute("aria-controls",p),E>=0?C.setAttribute("aria-activedescendant",`${p}-${E}`):C.removeAttribute("aria-activedescendant"),()=>{C.removeAttribute("aria-activedescendant"),C.removeAttribute("aria-controls")}},[p,E]),T.useEffect(()=>{const C=O=>{O.preventDefault(),O.stopPropagation()},_=O=>{if(O.isComposing||O.key==="Process"||O.keyCode===229||l&&!l())return;const L=!O.metaKey&&!O.ctrlKey&&!O.altKey&&!O.shiftKey;if(O.key==="Escape")C(O),u();else if(O.key==="ArrowDown"&&L)C(O),m(oe=>Math.max(0,Math.min(oe+1,v.length-1)));else if(O.key==="ArrowUp"&&L)C(O),m(oe=>Math.max(oe-1,0));else if(O.key==="Enter"||O.key==="Tab"){const oe=v[f];oe?(C(O),c(oe)):u()}};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[v,f,c,u,l]);const S=(C,_)=>b.jsxs("button",{id:`${p}-${_}`,className:"slash-item","data-active":_===f||void 0,ref:_===f?O=>O?.scrollIntoView({block:"nearest"}):void 0,onMouseEnter:()=>m(_),onMouseDown:O=>{O.preventDefault(),c(C)},role:"menuitem",children:[b.jsx("span",{className:"slash-icon","aria-hidden":!0,children:C.icon}),b.jsx("span",{className:"slash-label",children:C.label}),b.jsx("span",{className:"slash-hint",children:C.hint})]},C.key),N=[];return v.forEach((C,_)=>{let O=N.find(L=>L.name===C.group);O||(O={name:C.group,rows:[]},N.push(O)),O.rows.push({it:C,idx:_})}),b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"slash-backdrop",onMouseDown:u}),b.jsxs(rn,{id:p,className:"slash-menu",role:"menu",x:t,y:n,anchorTop:r,onMouseDown:C=>C.preventDefault(),children:[v.length===0&&b.jsx("div",{className:"slash-empty",children:d("mdblock.menu.noMatch")}),b.jsx("div",{className:"slash-scroll",children:y?v.map((C,_)=>S(C,_)):N.map(C=>b.jsxs("div",{className:"slash-group",children:[b.jsx("div",{className:"slash-group-label",children:C.name}),C.rows.map(({it:_,idx:O})=>S(_,O))]},C.name))}),v.length>0&&b.jsxs("div",{className:"slash-foot",children:[b.jsx("span",{children:d("mdblock.foot.select")}),b.jsx("span",{children:d("mdblock.foot.insert")}),b.jsx("span",{children:d("mdblock.foot.close")})]})]})]})}function Rd({onPick:e,onClose:t}){const{t:n}=nn(),[r,o]=T.useState(""),[s,a]=T.useState(0),l=An(p=>p.files);T.useEffect(()=>{An.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=Dt(d,c(p));return{f:p,s:h!==null?h+1e3:Dt(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 T.useEffect(()=>{a(0)},[r]),T.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(k=>Math.min(k+1,f.length-1));else if(g.key==="ArrowUp")p(g),a(k=>Math.max(k-1,0));else if(g.key==="Enter"){p(g);const k=f[s];k?e(m(k)):t()}else g.key==="Backspace"?(p(g),o(k=>k.slice(0,-1))):g.key.length===1&&!g.metaKey&&!g.ctrlKey&&!g.altKey&&(p(g),o(k=>k+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(pr,{})}),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")})]})]})]})}$p({id:"markdown",fileExtensions:[".md"],Editor:Ad});const s1=Object.freeze(Object.defineProperty({__proto__:null,DbLinkPicker:Rd,MarkdownBlock:Ad,MilkdownInner:za,PREFIX_TRIGGERS:Nd,PlainMarkdownEditor:k0,SLASH_ITEMS:Ed,SLASH_SENTINELS:x0,getFocusedBlockApply:C0,hostLabel:Tr,linkExtent:Id,normalizeFragmentMd:Cd,normalizeSerializedMd:$n,serializeUnified:vd,setFocusedBlockApply:S0,slashTurnFailed:Ld,stampedFileName:xd,textOf:dr,useAllSlashItems:Td},Symbol.toStringTag,{value:"Module"}));export{Nd as $,_u as A,zu as B,xt as C,mi as D,r1 as E,Jt as F,U0 as G,em as H,V0 as I,G0 as J,H0 as K,B0 as L,Hu as M,hi as N,Z0 as O,k0 as P,e1 as Q,Wy as R,vd as S,Qp as T,$n as U,K0 as V,ir as W,Yu as X,cw as Y,za as Z,Rd as _,P0 as a,Ld as a0,x0 as a1,xd as a2,S0 as a3,C0 as a4,Q0 as a5,n1 as a6,lw as a7,iw as a8,Td as a9,s1 as aa,O0 as b,Bt as c,qo as d,q0 as e,F0 as f,Dr as g,Wo as h,am as i,ok as j,tk as k,Ui as l,Jy as m,nk as n,ry as o,j0 as p,oy as q,t1 as r,_0 as s,W0 as t,z0 as u,o1 as v,Y0 as w,J0 as x,ql as y,X0 as z};
|