md-editor-v3 4.7.0-beta.1 → 4.7.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- "use strict";var ht=Object.defineProperty;var vt=(e,l,o)=>l in e?ht(e,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[l]=o;var q=(e,l,o)=>(vt(e,typeof l!="symbol"?l+"":l,o),o);const t=require("vue"),r=require("./chunks/config.cjs"),le=require("@vavt/util"),z=require("./chunks/index2.cjs"),s=require("./chunks/index3.cjs"),pt=require("./chunks/dom.cjs"),k=require("./chunks/index.cjs"),ee=require("codemirror"),ae=require("@codemirror/view"),Ct=require("@codemirror/language-data"),kt=require("@codemirror/lang-markdown"),E=require("@codemirror/state"),se=require("@codemirror/commands"),re=require("@codemirror/language"),c=require("@lezer/highlight"),xt=require("@codemirror/autocomplete"),P=require("./chunks/index4.cjs"),bt=require("./MdCatalog.cjs"),et=require("./chunks/vue-tsx.cjs"),Nt=require("./NormalToolbar.cjs"),Vt=require("./ModalToolbar.cjs");require("medium-zoom");require("copy-to-clipboard");require("markdown-it");require("markdown-it-image-figures");require("markdown-it-task-lists");require("lru-cache");const $t=t.defineComponent({setup(){return()=>t.createVNode("div",{class:`${r.prefix}-divider`},null)}}),Tt={noPrettier:{type:Boolean},toolbars:{type:Array,default:()=>[]},toolbarsExclude:{type:Array,default:()=>[]},setting:{type:Object,default:()=>({})},screenfull:{type:Object,default:null},screenfullJs:{type:String,default:""},updateSetting:{type:Function,default:()=>{}},tableShape:{type:Array,default:()=>[6,4]},defToolbars:{type:Object},noUploadImg:{type:Boolean},showToolbarName:{type:Boolean}},yt=e=>{var u,d,v,$;const l=t.inject("editorId");let o=(d=(u=r.configOption.editorExtensions)==null?void 0:u.screenfull)==null?void 0:d.instance;const a=($=(v=r.configOption.editorExtensions)==null?void 0:v.screenfull)==null?void 0:$.js,i=t.ref(!1),n=N=>{if(!o){s.bus.emit(l,s.ERROR_CATCHER,{name:"fullscreen",message:"fullscreen is undefined"});return}o.isEnabled?(i.value=!0,(N===void 0?!o.isFullscreen:N)?o.request():o.exit()):console.error("browser does not support screenfull!")},f=()=>{o&&o.isEnabled&&o.on("change",()=>{(i.value||e.setting.fullscreen)&&(i.value=!1,e.updateSetting("fullscreen"))})},g=()=>{o=window.screenfull,f()};return t.onMounted(()=>{if(f(),!o){const N=document.createElement("script");N.src=a||r.screenfullUrl,N.onload=g,N.id=`${r.prefix}-screenfull`,pt.appendHandler(N,"screenfull")}}),t.onMounted(()=>{s.bus.on(l,{name:s.CHANGE_FULL_SCREEN,callback:n})}),{fullscreenHandler:n}},wt={tableShape:{type:Array,default:()=>[6,4]},onSelected:{type:Function,default:()=>{}}},Et=t.defineComponent({name:"TableShape",props:wt,setup(e){const l=t.reactive({x:-1,y:-1});return()=>t.createVNode("div",{class:`${r.prefix}-table-shape`,onMouseleave:()=>{l.x=-1,l.y=-1}},[new Array(e.tableShape[1]).fill("").map((o,a)=>t.createVNode("div",{class:`${r.prefix}-table-shape-row`,key:`table-shape-row-${a}`},[new Array(e.tableShape[0]).fill("").map((i,n)=>t.createVNode("div",{class:`${r.prefix}-table-shape-col`,key:`table-shape-col-${n}`,onMouseenter:()=>{l.x=a,l.y=n},onClick:()=>{e.onSelected(l)}},[t.createVNode("div",{class:[`${r.prefix}-table-shape-col-default`,a<=l.x&&n<=l.y&&`${r.prefix}-table-shape-col-include`]},null)]))]))])}}),St=Et,At={type:{type:String,default:"link"},visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},It=t.defineComponent({props:At,setup(e){const l=t.inject("usedLanguageText"),o=t.inject("editorId"),a=t.computed(()=>{var n,f;switch(e.type){case"link":return(n=l.value.linkModalTips)==null?void 0:n.linkTitle;case"image":return(f=l.value.linkModalTips)==null?void 0:f.imageTitle;default:return""}}),i=t.reactive({desc:"",url:""});return t.watch(()=>e.visible,n=>{n||setTimeout(()=>{i.desc="",i.url=""},200)}),()=>t.createVNode(k.MdModal,{title:a.value,visible:e.visible,onClose:e.onCancel},{default:()=>{var n,f,g,u,d;return[t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-desc-${o}`},[(n=l.value.linkModalTips)==null?void 0:n.descLabel]),t.createVNode("input",{placeholder:(f=l.value.linkModalTips)==null?void 0:f.descLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-desc-${o}`,type:"text",value:i.desc,onChange:v=>{i.desc=v.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-url-${o}`},[(g=l.value.linkModalTips)==null?void 0:g.urlLabel]),t.createVNode("input",{placeholder:(u=l.value.linkModalTips)==null?void 0:u.urlLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-url-${o}`,type:"text",value:i.url,onChange:v=>{i.url=v.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:[`${r.prefix}-btn`,`${r.prefix}-btn-row`],type:"button",onClick:()=>{e.onOk(i),i.desc="",i.url=""}},[(d=l.value.linkModalTips)==null?void 0:d.buttonOK])])]}})}}),Lt={visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Mt=t.defineComponent({props:Lt,setup(e){var v,$,N;const l=t.inject("usedLanguageText"),o=t.inject("editorId");let a=(N=($=(v=r.configOption)==null?void 0:v.editorExtensions)==null?void 0:$.cropper)==null?void 0:N.instance;const i=t.ref(),n=t.ref(),f=t.ref(),g=t.reactive({cropperInited:!1,imgSelected:!1,imgSrc:"",isFullscreen:!1});let u=null;t.watch(()=>e.visible,()=>{e.visible&&!g.cropperInited&&(a=a||window.Cropper,i.value.onchange=()=>{if(!a){s.bus.emit(o,s.ERROR_CATCHER,{name:"Cropper",message:"Cropper is undefined"});return}const m=i.value.files||[];if(g.imgSelected=!0,(m==null?void 0:m.length)>0){const p=new FileReader;p.onload=h=>{g.imgSrc=h.target.result,t.nextTick(()=>{u=new a(n.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`})})},p.readAsDataURL(m[0])}})}),t.watch(()=>[g.imgSelected],()=>{f.value.style=""}),t.watch(()=>g.isFullscreen,()=>{t.nextTick(()=>{u==null||u.destroy(),f.value.style="",n.value&&(u=new a(n.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`}))})});const d=()=>{u.clear(),u.destroy(),u=null,i.value.value="",g.imgSelected=!1};return()=>{var m;return t.createVNode(k.MdModal,{class:`${r.prefix}-modal-clip`,title:(m=l.value.clipModalTips)==null?void 0:m.title,visible:e.visible,onClose:e.onCancel,showAdjust:!0,isFullscreen:g.isFullscreen,onAdjust:p=>{g.isFullscreen=p},width:"668px",height:"421px"},{default:()=>{var p,h;return[t.createVNode("div",{class:`${r.prefix}-form-item ${r.prefix}-clip`},[t.createVNode("div",{class:`${r.prefix}-clip-main`},[g.imgSelected?t.createVNode("div",{class:`${r.prefix}-clip-cropper`},[t.createVNode("img",{src:g.imgSrc,ref:n,style:{display:"none"},alt:""},null),t.createVNode("div",{class:`${r.prefix}-clip-delete`,onClick:d},[t.createVNode(k.Icon,{name:"delete"},null)])]):t.createVNode("div",{class:`${r.prefix}-clip-upload`,onClick:()=>{i.value.click()}},[t.createVNode(k.Icon,{name:"upload"},null)])]),t.createVNode("div",{class:`${r.prefix}-clip-preview`},[t.createVNode("div",{class:`${r.prefix}-clip-preview-target`,ref:f},null)])]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:`${r.prefix}-btn`,type:"button",onClick:()=>{if(u){const b=u.getCroppedCanvas();s.bus.emit(o,s.UPLOAD_IMAGE,[s.base642File(b.toDataURL("image/png"))],e.onOk),d()}}},[((p=l.value.clipModalTips)==null?void 0:p.buttonUpload)||((h=l.value.linkModalTips)==null?void 0:h.buttonOK)])]),t.createVNode("input",{ref:i,accept:"image/*",type:"file",multiple:!1,style:{display:"none"}},null)]}})}}}),Rt={type:{type:String,default:"link"},linkVisible:{type:Boolean,default:!1},clipVisible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Dt=t.defineComponent({props:Rt,setup(e){return()=>t.createVNode(t.Fragment,null,[t.createVNode(It,{type:e.type,visible:e.linkVisible,onOk:e.onOk,onCancel:e.onCancel},null),t.createVNode(Mt,{visible:e.clipVisible,onOk:e.onOk,onCancel:e.onCancel},null)])}}),Ht=t.defineComponent({name:"MDEditorToolbar",props:Tt,setup(e){const l=t.inject("editorId"),o=t.inject("usedLanguageText"),a=t.inject("theme"),i=t.inject("language"),{fullscreenHandler:n}=yt(e),f=`${l}-toolbar-wrapper`,g=t.ref(),u=t.reactive({title:!1,catalog:!1,image:!1,table:!1,mermaid:!1,katex:!1}),d=(b,C)=>{s.bus.emit(l,s.REPLACE,b,C)},v=t.reactive({type:"link",linkVisible:!1,clipVisible:!1}),$=t.ref();t.onMounted(()=>{s.bus.on(l,{name:s.OPEN_MODALS,callback(b){v.type=b,v.linkVisible=!0}})});const N=t.computed(()=>{const b=e.toolbars.filter(S=>!e.toolbarsExclude.includes(S)),C=b.indexOf("="),V=C===-1?b:b.slice(0,C+1),T=C===-1?[]:b.slice(C,Number.MAX_SAFE_INTEGER);return[V,T]}),m=t.ref(),p=()=>{s.bus.emit(l,s.UPLOAD_IMAGE,Array.from(m.value.files||[])),m.value.value=""};t.onMounted(()=>{m.value.addEventListener("change",p)});const h=b=>{var C,V,T,S,A,Z,X,y,w,B,F,R,L,M,D,_,j,ne,Y,K,G,J,U,H,O,Q,ie,ge,be,he,ve,pe,Ce,ke,xe,Ne,Ve,$e,Te,ye,we,Ee,Se,Ae,Ie,Le,Me,Re,De,He,Oe,Pe,Fe,Be,qe,_e,je,Ge,Ue,Ke,We,ze,Ze,Xe,Ye,Je,Qe;if(r.allToolbar.includes(b))switch(b){case"-":return t.createVNode($t,null,null);case"bold":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(C=o.value.toolbarTips)==null?void 0:C.bold,onClick:()=>{d("bold")}},[t.createVNode(k.Icon,{name:"bold"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(V=o.value.toolbarTips)==null?void 0:V.bold])]);case"underline":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(T=o.value.toolbarTips)==null?void 0:T.underline,onClick:()=>{d("underline")}},[t.createVNode(k.Icon,{name:"underline"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(S=o.value.toolbarTips)==null?void 0:S.underline])]);case"italic":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(A=o.value.toolbarTips)==null?void 0:A.italic,onClick:()=>{d("italic")}},[t.createVNode(k.Icon,{name:"italic"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Z=o.value.toolbarTips)==null?void 0:Z.italic])]);case"strikeThrough":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(X=o.value.toolbarTips)==null?void 0:X.strikeThrough,onClick:()=>{d("strikeThrough")}},[t.createVNode(k.Icon,{name:"strike-through"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(y=o.value.toolbarTips)==null?void 0:y.strikeThrough])]);case"title":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.title,onChange:x=>{u.title=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h1")}},[(w=o.value.titleItem)==null?void 0:w.h1]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h2")}},[(B=o.value.titleItem)==null?void 0:B.h2]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h3")}},[(F=o.value.titleItem)==null?void 0:F.h3]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h4")}},[(R=o.value.titleItem)==null?void 0:R.h4]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h5")}},[(L=o.value.titleItem)==null?void 0:L.h5]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("h6")}},[(M=o.value.titleItem)==null?void 0:M.h6])])},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.title},[t.createVNode(k.Icon,{name:"title"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.title])])]}});case"sub":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(D=o.value.toolbarTips)==null?void 0:D.sub,onClick:()=>{d("sub")}},[t.createVNode(k.Icon,{name:"sub"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(_=o.value.toolbarTips)==null?void 0:_.sub])]);case"sup":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(j=o.value.toolbarTips)==null?void 0:j.sup,onClick:()=>{d("sup")}},[t.createVNode(k.Icon,{name:"sup"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ne=o.value.toolbarTips)==null?void 0:ne.sup])]);case"quote":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Y=o.value.toolbarTips)==null?void 0:Y.quote,onClick:()=>{d("quote")}},[t.createVNode(k.Icon,{name:"quote"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(K=o.value.toolbarTips)==null?void 0:K.quote])]);case"unorderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(G=o.value.toolbarTips)==null?void 0:G.unorderedList,onClick:()=>{d("unorderedList")}},[t.createVNode(k.Icon,{name:"unordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(J=o.value.toolbarTips)==null?void 0:J.unorderedList])]);case"orderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(U=o.value.toolbarTips)==null?void 0:U.orderedList,onClick:()=>{d("orderedList")}},[t.createVNode(k.Icon,{name:"ordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(H=o.value.toolbarTips)==null?void 0:H.orderedList])]);case"task":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(O=o.value.toolbarTips)==null?void 0:O.task,onClick:()=>{d("task")}},[t.createVNode(k.Icon,{name:"task"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Q=o.value.toolbarTips)==null?void 0:Q.task])]);case"codeRow":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ie=o.value.toolbarTips)==null?void 0:ie.codeRow,onClick:()=>{d("codeRow")}},[t.createVNode(k.Icon,{name:"code-row"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ge=o.value.toolbarTips)==null?void 0:ge.codeRow])]);case"code":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(be=o.value.toolbarTips)==null?void 0:be.code,onClick:()=>{d("code")}},[t.createVNode(k.Icon,{name:"code"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(he=o.value.toolbarTips)==null?void 0:he.code])]);case"link":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ve=o.value.toolbarTips)==null?void 0:ve.link,onClick:()=>{v.type="link",v.linkVisible=!0}},[t.createVNode(k.Icon,{name:"link"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(pe=o.value.toolbarTips)==null?void 0:pe.link])]);case"image":return e.noUploadImg?t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ce=o.value.toolbarTips)==null?void 0:Ce.image,onClick:()=>{v.type="image",v.linkVisible=!0}},[t.createVNode(k.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ke=o.value.toolbarTips)==null?void 0:ke.image])]):t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.image,onChange:x=>{u.image=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{v.type="image",v.linkVisible=!0}},[(xe=o.value.imgTitleItem)==null?void 0:xe.link]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{m.value.click()}},[(Ne=o.value.imgTitleItem)==null?void 0:Ne.upload]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{v.clipVisible=!0}},[(Ve=o.value.imgTitleItem)==null?void 0:Ve.clip2upload])])},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.image},[t.createVNode(k.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.image])])]}});case"table":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.table,onChange:x=>{u.table=x},key:"bar-table",overlay:t.createVNode(St,{tableShape:e.tableShape,onSelected:x=>{d("table",{selectedShape:x})}},null)},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.table},[t.createVNode(k.Icon,{name:"table"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.table])])]}});case"revoke":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:($e=o.value.toolbarTips)==null?void 0:$e.revoke,onClick:()=>{s.bus.emit(l,s.CTRL_Z)}},[t.createVNode(k.Icon,{name:"revoke"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Te=o.value.toolbarTips)==null?void 0:Te.revoke])]);case"next":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ye=o.value.toolbarTips)==null?void 0:ye.next,onClick:()=>{s.bus.emit(l,s.CTRL_SHIFT_Z)}},[t.createVNode(k.Icon,{name:"next"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(we=o.value.toolbarTips)==null?void 0:we.next])]);case"save":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ee=o.value.toolbarTips)==null?void 0:Ee.save,onClick:()=>{s.bus.emit(l,s.ON_SAVE)}},[t.createVNode(k.Icon,{name:"baocun"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Se=o.value.toolbarTips)==null?void 0:Se.save])]);case"prettier":return e.noPrettier?"":t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ae=o.value.toolbarTips)==null?void 0:Ae.prettier,onClick:()=>{d("prettier")}},[t.createVNode(k.Icon,{name:"prettier"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Ie=o.value.toolbarTips)==null?void 0:Ie.prettier])]);case"pageFullscreen":return!e.setting.fullscreen&&t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Le=o.value.toolbarTips)==null?void 0:Le.pageFullscreen,onClick:()=>{e.updateSetting("pageFullscreen")}},[t.createVNode(k.Icon,{name:e.setting.pageFullscreen?"suoxiao":"fangda"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Me=o.value.toolbarTips)==null?void 0:Me.pageFullscreen])]);case"fullscreen":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Re=o.value.toolbarTips)==null?void 0:Re.fullscreen,onClick:()=>{n()}},[t.createVNode(k.Icon,{name:e.setting.fullscreen?"fullscreen-exit":"fullscreen"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(De=o.value.toolbarTips)==null?void 0:De.fullscreen])]);case"preview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(He=o.value.toolbarTips)==null?void 0:He.preview,onClick:()=>{e.updateSetting("preview")}},[t.createVNode(k.Icon,{name:"preview"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Oe=o.value.toolbarTips)==null?void 0:Oe.preview])]);case"htmlPreview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Pe=o.value.toolbarTips)==null?void 0:Pe.htmlPreview,onClick:()=>{e.updateSetting("htmlPreview")}},[t.createVNode(k.Icon,{name:"coding"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Fe=o.value.toolbarTips)==null?void 0:Fe.htmlPreview])]);case"catalog":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Be=o.value.toolbarTips)==null?void 0:Be.catalog,onClick:()=>{s.bus.emit(l,s.CHANGE_CATALOG_VISIBLE)},key:"bar-catalog"},[t.createVNode(k.Icon,{name:"catalog"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(qe=o.value.toolbarTips)==null?void 0:qe.catalog])]);case"github":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(_e=o.value.toolbarTips)==null?void 0:_e.github,onClick:()=>le.linkTo("https://github.com/imzbf/md-editor-v3")},[t.createVNode(k.Icon,{name:"github"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(je=o.value.toolbarTips)==null?void 0:je.github])]);case"mermaid":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.mermaid,onChange:x=>{u.mermaid=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.mermaid=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("flow")}},[(Ge=o.value.mermaid)==null?void 0:Ge.flow]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("sequence")}},[(Ue=o.value.mermaid)==null?void 0:Ue.sequence]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("gantt")}},[(Ke=o.value.mermaid)==null?void 0:Ke.gantt]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("class")}},[(We=o.value.mermaid)==null?void 0:We.class]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("state")}},[(ze=o.value.mermaid)==null?void 0:ze.state]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("pie")}},[(Ze=o.value.mermaid)==null?void 0:Ze.pie]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("relationship")}},[(Xe=o.value.mermaid)==null?void 0:Xe.relationship]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("journey")}},[(Ye=o.value.mermaid)==null?void 0:Ye.journey])]),key:"bar-mermaid"},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.mermaid},[t.createVNode(k.Icon,{name:"mermaid"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.mermaid])])]}});case"katex":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.katex,onChange:x=>{u.katex=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.katex=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("katexInline")}},[(Je=o.value.katex)==null?void 0:Je.inline]),t.createVNode("li",{class:`${r.prefix}-menu-item`,onClick:()=>{d("katexBlock")}},[(Qe=o.value.katex)==null?void 0:Qe.block])]),key:"bar-katex"},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.katex},[t.createVNode(k.Icon,{name:"formula"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.katex])])]}})}else if(e.defToolbars instanceof Array){const x=e.defToolbars[b];return x?t.cloneVNode(x,{theme:a.value,language:i.value,insert(ue){s.bus.emit(l,s.REPLACE,"universal",{generate:ue})}}):""}else if(e.defToolbars&&e.defToolbars.children instanceof Array){const x=e.defToolbars.children[b];return x?t.cloneVNode(x,{theme:a.value,language:i.value,insert(ue){s.bus.emit(l,s.REPLACE,"universal",{generate:ue})}}):""}else return""};return t.watch(()=>e.toolbars,()=>{t.nextTick(()=>{g.value&&le.draggingScroll(g.value)})},{immediate:!0}),()=>{const b=N.value[0].map(V=>h(V)),C=N.value[1].map(V=>h(V));return t.createVNode(t.Fragment,null,[e.toolbars.length>0&&t.createVNode("div",{class:`${r.prefix}-toolbar-wrapper`,ref:g,id:f},[t.createVNode("div",{class:[`${r.prefix}-toolbar`,e.showToolbarName&&`${r.prefix}-stn`]},[t.createVNode("div",{class:`${r.prefix}-toolbar-left`,ref:$},[b]),t.createVNode("div",{class:`${r.prefix}-toolbar-right`},[C])])]),t.createVNode("input",{ref:m,accept:"image/*",type:"file",multiple:!0,style:{display:"none"}},null),t.createVNode(Dt,{linkVisible:v.linkVisible,clipVisible:v.clipVisible,type:v.type,onCancel:()=>{v.linkVisible=!1,v.clipVisible=!1},onOk:V=>{V&&d(v.type,{desc:V.desc,url:V.url}),v.linkVisible=!1,v.clipVisible=!1}},null)])}}}),Ot=(e,l)=>{const o=le.debounce(()=>{e.removeEventListener("scroll",a),e.addEventListener("scroll",a),l.removeEventListener("scroll",a),l.addEventListener("scroll",a)},50),a=i=>{const n=e.clientHeight,f=l.clientHeight,g=e.scrollHeight,u=l.scrollHeight,d=(g-n)/(u-f);i.target===e?(l.removeEventListener("scroll",a),l.scrollTo({top:e.scrollTop/d}),o()):(e.removeEventListener("scroll",a),e.scrollTo({top:l.scrollTop*d}),o())};return[()=>{o().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",a),l.removeEventListener("scroll",a)}]},Pt=(e,l,o)=>{const{view:a}=o,i=le.createSmoothScroll(),n=N=>a.lineBlockAt(a.state.doc.line(N).from).top,f=N=>a.lineBlockAt(a.state.doc.line(N).from).height;let g=[];const u=()=>{g=[];const N=Array.from(l.querySelectorAll("[data-line]")).map(b=>Number(b.dataset.line)+1),{lines:m}=a.state.doc;let p=1,h=N.shift()??m;for(let b=1;b<=m;b++)b===h&&(p=b,h=N.shift()||m+1),g.push({start:p,end:h-1})};let d=0,v=0;const $=le.throttle(N=>{var C,V,T,S,A,Z,X;if(!((C=l.firstElementChild)!=null&&C.firstElementChild))return;const m=a.lineBlockAtHeight(a.scrollDOM.scrollTop),{number:p}=a.state.doc.lineAt(m.from);if(p>g.length||a.state.doc.lines<g[g.length-1].end)return;let h=+getComputedStyle(l).paddingTop.replace("px","");const b=+getComputedStyle(l).paddingBottom.replace("px","");if(N.target===e){if(v!==0)return;d++;const y=g[p-1];let w=n(y.end)+f(y.end),B=0;const F=n(y.start),R=l.querySelector(`[data-line="${y.start-1}"]`)||((V=l.firstElementChild)==null?void 0:V.firstElementChild),L=l.querySelector(`[data-line="${y.end}"]`)||((T=l.lastElementChild)==null?void 0:T.lastElementChild);let M=0,D=0;F===0?R===L?(h=0,w=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight,B=a.scrollDOM.scrollTop/w,M=L.offsetTop+L.offsetHeight-l.clientHeight):(B=a.scrollDOM.scrollTop/w,M=L.offsetTop):w>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(B=(a.scrollDOM.scrollTop-F)/(a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight-F),D=R.offsetTop,M=l.scrollHeight-l.clientHeight-D+10):(B=(a.scrollDOM.scrollTop-F)/(w-F),D=R.offsetTop,M=L.offsetTop-D);const _=D-h+M*B;i(l,_,()=>{d--})}else{if(d!==0)return;v++;const y=Array.from(l.querySelectorAll("[data-line]")),w=l.scrollTop,B=l.scrollHeight;let F=y.length===0?1:Math.ceil(Number(y[y.length-1].dataset.line)*(w/B)),R=(S=l.firstElementChild)==null?void 0:S.firstElementChild;for(let H=F;H>=0;H--){const O=l.querySelector(`[data-line="${H}"]`);if(O&&O.offsetTop<=w){R=O,F=H;break}}let L=(A=l.firstElementChild)==null?void 0:A.firstElementChild,M=(Z=l.firstElementChild)==null?void 0:Z.lastElementChild;for(;y.length>0;){const H=y.indexOf(R);if(H+1>=y.length)break;const O=y[H+1];if(H===-1){M=O;break}const Q=R.offsetTop;if(Q>w){if(H===0){L=R,M=O;break}R=y[H-1];continue}const ie=O.offsetTop;if(Q<=w&&ie>w){L=R,M=O;break}R=O}const D=L.offsetTop;let _=M.offsetTop,j=0;const{start:ne,end:Y}=g[Number(L.dataset.line||0)],K=n(ne);let G=n(Y);const J=f(Y);let U=0;L===((X=l.firstElementChild)==null?void 0:X.firstElementChild)?(L===M?(_=M.offsetHeight-l.offsetHeight+h+b,U=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight):U=G+J-K,j=Math.max(w/_,0)):G>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(j=Math.max((w-D)/(l.scrollHeight-D-l.clientHeight),0),G=n(a.state.doc.lines)+f(a.state.doc.lines),U=8+G-K-e.clientHeight):(j=Math.max((w-D)/(_-D),0),U=G+J-K),i(e,K+U*j,()=>{v--})}},10);return[()=>{u(),e.addEventListener("scroll",$),l.addEventListener("scroll",$),e.dispatchEvent(new Event("scroll"))},()=>{g=[],e.removeEventListener("scroll",$),l.removeEventListener("scroll",$)}]},Ft=(e,l,o)=>{const a=t.inject("editorId");let i=()=>{},n=()=>{};const f=()=>{i();const g=document.querySelector(`#${a} .cm-scroller`),u=document.querySelector(`[id="${a}-preview-wrapper"][data-show="true"]`),d=document.querySelector(`[id="${a}-html-wrapper"][data-show="true"]`);(u||d)&&([n,i]=(u?Pt:Ot)(g,u||d,o.value)),e.scrollAuto&&n()};t.watch([l,t.toRef(e.setting,"preview"),t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"fullscreen"),t.toRef(e.setting,"pageFullscreen")],()=>{t.nextTick(f)}),t.watch(()=>e.scrollAuto,g=>{g?n():i()}),t.onMounted(f)},Bt=Ft,qt=(e,l,o)=>{var v,$,N,m,p,h;let a="",i=0,n=0,f=!0,g=!1;const u=l.getSelectedText(),d=(v=r.configOption.editorConfig)==null?void 0:v.mermaidTemplate;if(/^h[1-6]{1}$/.test(e)){const b=e.replace(/^h(\d)/,(C,V)=>new Array(Number(V)).fill("#",0,V).join(""));a=`${b} ${u}`,i=b.length+1}else if(e==="prettier"){const b=window.prettier||((N=($=r.configOption.editorExtensions)==null?void 0:$.prettier)==null?void 0:N.prettierInstance),C=[((m=window.prettierPlugins)==null?void 0:m.markdown)||((h=(p=r.configOption.editorExtensions)==null?void 0:p.prettier)==null?void 0:h.parserMarkdownInstance)];!b||C[0]===void 0?(s.bus.emit(o.editorId,s.ERROR_CATCHER,{name:"prettier",message:"prettier is undefined"}),a=l.getValue()):a=b.format(l.getValue(),{parser:"markdown",plugins:C}),f=!1,g=!0}else switch(e){case"bold":{a=`**${u}**`,i=2,n=-2;break}case"underline":{a=`<u>${u}</u>`,i=3,n=-4;break}case"italic":{a=`*${u}*`,i=1,n=-1;break}case"strikeThrough":{a=`~~${u}~~`,i=2,n=-2;break}case"sub":{a=`<sub>${u}</sub>`,i=5,n=-6;break}case"sup":{a=`<sup>${u}</sup>`,i=5,n=-6;break}case"codeRow":{a="`"+u+"`",i=1,n=-1;break}case"quote":{a=`> ${u}`,i=2;break}case"orderedList":{a=`1. ${u}`,i=3;break}case"unorderedList":{a=`- ${u}`,i=2;break}case"task":{a=`- [ ] ${u}`,i=6;break}case"code":{const b=o.text||u||"",C=o.mode||"language";a=`\`\`\`${C}
1
+ "use strict";var ht=Object.defineProperty;var vt=(e,l,o)=>l in e?ht(e,l,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[l]=o;var q=(e,l,o)=>(vt(e,typeof l!="symbol"?l+"":l,o),o);const t=require("vue"),r=require("./chunks/config.cjs"),le=require("@vavt/util"),z=require("./chunks/index2.cjs"),s=require("./chunks/index3.cjs"),pt=require("./chunks/dom.cjs"),k=require("./chunks/index.cjs"),ee=require("codemirror"),ae=require("@codemirror/view"),Ct=require("@codemirror/language-data"),kt=require("@codemirror/lang-markdown"),E=require("@codemirror/state"),se=require("@codemirror/commands"),re=require("@codemirror/language"),c=require("@lezer/highlight"),xt=require("@codemirror/autocomplete"),P=require("./chunks/index4.cjs"),bt=require("./MdCatalog.cjs"),et=require("./chunks/vue-tsx.cjs"),$t=require("./NormalToolbar.cjs"),Nt=require("./ModalToolbar.cjs");require("medium-zoom");require("copy-to-clipboard");require("markdown-it");require("markdown-it-image-figures");require("markdown-it-task-lists");require("lru-cache");const Vt=t.defineComponent({setup(){return()=>t.createVNode("div",{class:`${r.prefix}-divider`},null)}}),Tt={noPrettier:{type:Boolean},toolbars:{type:Array,default:()=>[]},toolbarsExclude:{type:Array,default:()=>[]},setting:{type:Object,default:()=>({})},screenfull:{type:Object,default:null},screenfullJs:{type:String,default:""},updateSetting:{type:Function,default:()=>{}},tableShape:{type:Array,default:()=>[6,4]},defToolbars:{type:Object},noUploadImg:{type:Boolean},showToolbarName:{type:Boolean}},yt=e=>{var u,d,v,V;const l=t.inject("editorId");let o=(d=(u=r.configOption.editorExtensions)==null?void 0:u.screenfull)==null?void 0:d.instance;const a=(V=(v=r.configOption.editorExtensions)==null?void 0:v.screenfull)==null?void 0:V.js,i=t.ref(!1),n=$=>{if(!o){s.bus.emit(l,s.ERROR_CATCHER,{name:"fullscreen",message:"fullscreen is undefined"});return}o.isEnabled?(i.value=!0,($===void 0?!o.isFullscreen:$)?o.request():o.exit()):console.error("browser does not support screenfull!")},f=()=>{o&&o.isEnabled&&o.on("change",()=>{(i.value||e.setting.fullscreen)&&(i.value=!1,e.updateSetting("fullscreen"))})},g=()=>{o=window.screenfull,f()};return t.onMounted(()=>{if(f(),!o){const $=document.createElement("script");$.src=a||r.screenfullUrl,$.onload=g,$.id=`${r.prefix}-screenfull`,pt.appendHandler($,"screenfull")}}),t.onMounted(()=>{s.bus.on(l,{name:s.CHANGE_FULL_SCREEN,callback:n})}),{fullscreenHandler:n}},wt={tableShape:{type:Array,default:()=>[6,4]},onSelected:{type:Function,default:()=>{}}},Et=t.defineComponent({name:"TableShape",props:wt,setup(e){const l=t.reactive({x:-1,y:-1});return()=>t.createVNode("div",{class:`${r.prefix}-table-shape`,onMouseleave:()=>{l.x=-1,l.y=-1}},[new Array(e.tableShape[1]).fill("").map((o,a)=>t.createVNode("div",{class:`${r.prefix}-table-shape-row`,key:`table-shape-row-${a}`},[new Array(e.tableShape[0]).fill("").map((i,n)=>t.createVNode("div",{class:`${r.prefix}-table-shape-col`,key:`table-shape-col-${n}`,onMouseenter:()=>{l.x=a,l.y=n},onClick:()=>{e.onSelected(l)}},[t.createVNode("div",{class:[`${r.prefix}-table-shape-col-default`,a<=l.x&&n<=l.y&&`${r.prefix}-table-shape-col-include`]},null)]))]))])}}),St=Et,At={type:{type:String,default:"link"},visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},It=t.defineComponent({props:At,setup(e){const l=t.inject("usedLanguageText"),o=t.inject("editorId"),a=t.computed(()=>{var n,f;switch(e.type){case"link":return(n=l.value.linkModalTips)==null?void 0:n.linkTitle;case"image":return(f=l.value.linkModalTips)==null?void 0:f.imageTitle;default:return""}}),i=t.reactive({desc:"",url:""});return t.watch(()=>e.visible,n=>{n||setTimeout(()=>{i.desc="",i.url=""},200)}),()=>t.createVNode(k.MdModal,{title:a.value,visible:e.visible,onClose:e.onCancel},{default:()=>{var n,f,g,u,d;return[t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-desc-${o}`},[(n=l.value.linkModalTips)==null?void 0:n.descLabel]),t.createVNode("input",{placeholder:(f=l.value.linkModalTips)==null?void 0:f.descLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-desc-${o}`,type:"text",value:i.desc,onChange:v=>{i.desc=v.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("label",{class:`${r.prefix}-label`,for:`link-url-${o}`},[(g=l.value.linkModalTips)==null?void 0:g.urlLabel]),t.createVNode("input",{placeholder:(u=l.value.linkModalTips)==null?void 0:u.urlLabelPlaceHolder,class:`${r.prefix}-input`,id:`link-url-${o}`,type:"text",value:i.url,onChange:v=>{i.url=v.target.value},autocomplete:"off"},null)]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:[`${r.prefix}-btn`,`${r.prefix}-btn-row`],type:"button",onClick:()=>{e.onOk(i),i.desc="",i.url=""}},[(d=l.value.linkModalTips)==null?void 0:d.buttonOK])])]}})}}),Lt={visible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Mt=t.defineComponent({props:Lt,setup(e){var v,V,$;const l=t.inject("usedLanguageText"),o=t.inject("editorId");let a=($=(V=(v=r.configOption)==null?void 0:v.editorExtensions)==null?void 0:V.cropper)==null?void 0:$.instance;const i=t.ref(),n=t.ref(),f=t.ref(),g=t.reactive({cropperInited:!1,imgSelected:!1,imgSrc:"",isFullscreen:!1});let u=null;t.watch(()=>e.visible,()=>{e.visible&&!g.cropperInited&&(a=a||window.Cropper,i.value.onchange=()=>{if(!a){s.bus.emit(o,s.ERROR_CATCHER,{name:"Cropper",message:"Cropper is undefined"});return}const m=i.value.files||[];if(g.imgSelected=!0,(m==null?void 0:m.length)>0){const p=new FileReader;p.onload=h=>{g.imgSrc=h.target.result,t.nextTick(()=>{u=new a(n.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`})})},p.readAsDataURL(m[0])}})}),t.watch(()=>[g.imgSelected],()=>{f.value.style=""}),t.watch(()=>g.isFullscreen,()=>{t.nextTick(()=>{u==null||u.destroy(),f.value.style="",n.value&&(u=new a(n.value,{viewMode:2,preview:`.${r.prefix}-clip-preview-target`}))})});const d=()=>{u.clear(),u.destroy(),u=null,i.value.value="",g.imgSelected=!1};return()=>{var m;return t.createVNode(k.MdModal,{class:`${r.prefix}-modal-clip`,title:(m=l.value.clipModalTips)==null?void 0:m.title,visible:e.visible,onClose:e.onCancel,showAdjust:!0,isFullscreen:g.isFullscreen,onAdjust:p=>{g.isFullscreen=p},width:"668px",height:"421px"},{default:()=>{var p,h;return[t.createVNode("div",{class:`${r.prefix}-form-item ${r.prefix}-clip`},[t.createVNode("div",{class:`${r.prefix}-clip-main`},[g.imgSelected?t.createVNode("div",{class:`${r.prefix}-clip-cropper`},[t.createVNode("img",{src:g.imgSrc,ref:n,style:{display:"none"},alt:""},null),t.createVNode("div",{class:`${r.prefix}-clip-delete`,onClick:d},[t.createVNode(k.Icon,{name:"delete"},null)])]):t.createVNode("div",{class:`${r.prefix}-clip-upload`,onClick:()=>{i.value.click()}},[t.createVNode(k.Icon,{name:"upload"},null)])]),t.createVNode("div",{class:`${r.prefix}-clip-preview`},[t.createVNode("div",{class:`${r.prefix}-clip-preview-target`,ref:f},null)])]),t.createVNode("div",{class:`${r.prefix}-form-item`},[t.createVNode("button",{class:`${r.prefix}-btn`,type:"button",onClick:()=>{if(u){const b=u.getCroppedCanvas();s.bus.emit(o,s.UPLOAD_IMAGE,[s.base642File(b.toDataURL("image/png"))],e.onOk),d()}}},[((p=l.value.clipModalTips)==null?void 0:p.buttonUpload)||((h=l.value.linkModalTips)==null?void 0:h.buttonOK)])]),t.createVNode("input",{ref:i,accept:"image/*",type:"file",multiple:!1,style:{display:"none"}},null)]}})}}}),Rt={type:{type:String,default:"link"},linkVisible:{type:Boolean,default:!1},clipVisible:{type:Boolean,default:!1},onCancel:{type:Function,default:()=>{}},onOk:{type:Function,default:()=>{}}},Dt=t.defineComponent({props:Rt,setup(e){return()=>t.createVNode(t.Fragment,null,[t.createVNode(It,{type:e.type,visible:e.linkVisible,onOk:e.onOk,onCancel:e.onCancel},null),t.createVNode(Mt,{visible:e.clipVisible,onOk:e.onOk,onCancel:e.onCancel},null)])}}),Ht=t.defineComponent({name:"MDEditorToolbar",props:Tt,setup(e){const l=t.inject("editorId"),o=t.inject("usedLanguageText"),a=t.inject("theme"),i=t.inject("language"),{fullscreenHandler:n}=yt(e),f=`${l}-toolbar-wrapper`,g=t.ref(),u=t.reactive({title:!1,catalog:!1,image:!1,table:!1,mermaid:!1,katex:!1}),d=(b,C)=>{s.bus.emit(l,s.REPLACE,b,C)},v=t.reactive({type:"link",linkVisible:!1,clipVisible:!1}),V=t.ref();t.onMounted(()=>{s.bus.on(l,{name:s.OPEN_MODALS,callback(b){v.type=b,v.linkVisible=!0}})});const $=t.computed(()=>{const b=e.toolbars.filter(S=>!e.toolbarsExclude.includes(S)),C=b.indexOf("="),N=C===-1?b:b.slice(0,C+1),T=C===-1?[]:b.slice(C,Number.MAX_SAFE_INTEGER);return[N,T]}),m=t.ref(),p=()=>{s.bus.emit(l,s.UPLOAD_IMAGE,Array.from(m.value.files||[])),m.value.value=""};t.onMounted(()=>{m.value.addEventListener("change",p)});const h=b=>{var C,N,T,S,A,Z,X,y,w,B,F,R,L,M,D,_,j,ne,Y,K,G,J,U,H,O,Q,ie,ge,be,he,ve,pe,Ce,ke,xe,$e,Ne,Ve,Te,ye,we,Ee,Se,Ae,Ie,Le,Me,Re,De,He,Oe,Pe,Fe,Be,qe,_e,je,Ge,Ue,Ke,We,ze,Ze,Xe,Ye,Je,Qe;if(r.allToolbar.includes(b))switch(b){case"-":return t.createVNode(Vt,null,null);case"bold":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(C=o.value.toolbarTips)==null?void 0:C.bold,onClick:()=>{d("bold")}},[t.createVNode(k.Icon,{name:"bold"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(N=o.value.toolbarTips)==null?void 0:N.bold])]);case"underline":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(T=o.value.toolbarTips)==null?void 0:T.underline,onClick:()=>{d("underline")}},[t.createVNode(k.Icon,{name:"underline"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(S=o.value.toolbarTips)==null?void 0:S.underline])]);case"italic":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(A=o.value.toolbarTips)==null?void 0:A.italic,onClick:()=>{d("italic")}},[t.createVNode(k.Icon,{name:"italic"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Z=o.value.toolbarTips)==null?void 0:Z.italic])]);case"strikeThrough":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(X=o.value.toolbarTips)==null?void 0:X.strikeThrough,onClick:()=>{d("strikeThrough")}},[t.createVNode(k.Icon,{name:"strike-through"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(y=o.value.toolbarTips)==null?void 0:y.strikeThrough])]);case"title":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.title,onChange:x=>{u.title=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h1")}},[(w=o.value.titleItem)==null?void 0:w.h1]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h2")}},[(B=o.value.titleItem)==null?void 0:B.h2]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h3")}},[(F=o.value.titleItem)==null?void 0:F.h3]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h4")}},[(R=o.value.titleItem)==null?void 0:R.h4]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h5")}},[(L=o.value.titleItem)==null?void 0:L.h5]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-title`,onClick:()=>{d("h6")}},[(M=o.value.titleItem)==null?void 0:M.h6])])},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.title},[t.createVNode(k.Icon,{name:"title"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.title])])]}});case"sub":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(D=o.value.toolbarTips)==null?void 0:D.sub,onClick:()=>{d("sub")}},[t.createVNode(k.Icon,{name:"sub"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(_=o.value.toolbarTips)==null?void 0:_.sub])]);case"sup":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(j=o.value.toolbarTips)==null?void 0:j.sup,onClick:()=>{d("sup")}},[t.createVNode(k.Icon,{name:"sup"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ne=o.value.toolbarTips)==null?void 0:ne.sup])]);case"quote":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Y=o.value.toolbarTips)==null?void 0:Y.quote,onClick:()=>{d("quote")}},[t.createVNode(k.Icon,{name:"quote"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(K=o.value.toolbarTips)==null?void 0:K.quote])]);case"unorderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(G=o.value.toolbarTips)==null?void 0:G.unorderedList,onClick:()=>{d("unorderedList")}},[t.createVNode(k.Icon,{name:"unordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(J=o.value.toolbarTips)==null?void 0:J.unorderedList])]);case"orderedList":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(U=o.value.toolbarTips)==null?void 0:U.orderedList,onClick:()=>{d("orderedList")}},[t.createVNode(k.Icon,{name:"ordered-list"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(H=o.value.toolbarTips)==null?void 0:H.orderedList])]);case"task":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(O=o.value.toolbarTips)==null?void 0:O.task,onClick:()=>{d("task")}},[t.createVNode(k.Icon,{name:"task"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Q=o.value.toolbarTips)==null?void 0:Q.task])]);case"codeRow":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ie=o.value.toolbarTips)==null?void 0:ie.codeRow,onClick:()=>{d("codeRow")}},[t.createVNode(k.Icon,{name:"code-row"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ge=o.value.toolbarTips)==null?void 0:ge.codeRow])]);case"code":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(be=o.value.toolbarTips)==null?void 0:be.code,onClick:()=>{d("code")}},[t.createVNode(k.Icon,{name:"code"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(he=o.value.toolbarTips)==null?void 0:he.code])]);case"link":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ve=o.value.toolbarTips)==null?void 0:ve.link,onClick:()=>{v.type="link",v.linkVisible=!0}},[t.createVNode(k.Icon,{name:"link"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(pe=o.value.toolbarTips)==null?void 0:pe.link])]);case"image":return e.noUploadImg?t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ce=o.value.toolbarTips)==null?void 0:Ce.image,onClick:()=>{v.type="image",v.linkVisible=!0}},[t.createVNode(k.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(ke=o.value.toolbarTips)==null?void 0:ke.image])]):t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.image,onChange:x=>{u.image=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.title=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{v.type="image",v.linkVisible=!0}},[(xe=o.value.imgTitleItem)==null?void 0:xe.link]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{m.value.click()}},[($e=o.value.imgTitleItem)==null?void 0:$e.upload]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-image`,onClick:()=>{v.clipVisible=!0}},[(Ne=o.value.imgTitleItem)==null?void 0:Ne.clip2upload])])},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.image},[t.createVNode(k.Icon,{name:"image"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.image])])]}});case"table":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.table,onChange:x=>{u.table=x},key:"bar-table",overlay:t.createVNode(St,{tableShape:e.tableShape,onSelected:x=>{d("table",{selectedShape:x})}},null)},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.table},[t.createVNode(k.Icon,{name:"table"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.table])])]}});case"revoke":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ve=o.value.toolbarTips)==null?void 0:Ve.revoke,onClick:()=>{s.bus.emit(l,s.CTRL_Z)}},[t.createVNode(k.Icon,{name:"revoke"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Te=o.value.toolbarTips)==null?void 0:Te.revoke])]);case"next":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(ye=o.value.toolbarTips)==null?void 0:ye.next,onClick:()=>{s.bus.emit(l,s.CTRL_SHIFT_Z)}},[t.createVNode(k.Icon,{name:"next"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(we=o.value.toolbarTips)==null?void 0:we.next])]);case"save":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ee=o.value.toolbarTips)==null?void 0:Ee.save,onClick:()=>{s.bus.emit(l,s.ON_SAVE)}},[t.createVNode(k.Icon,{name:"baocun"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Se=o.value.toolbarTips)==null?void 0:Se.save])]);case"prettier":return e.noPrettier?"":t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Ae=o.value.toolbarTips)==null?void 0:Ae.prettier,onClick:()=>{d("prettier")}},[t.createVNode(k.Icon,{name:"prettier"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Ie=o.value.toolbarTips)==null?void 0:Ie.prettier])]);case"pageFullscreen":return!e.setting.fullscreen&&t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Le=o.value.toolbarTips)==null?void 0:Le.pageFullscreen,onClick:()=>{e.updateSetting("pageFullscreen")}},[t.createVNode(k.Icon,{name:e.setting.pageFullscreen?"suoxiao":"fangda"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Me=o.value.toolbarTips)==null?void 0:Me.pageFullscreen])]);case"fullscreen":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Re=o.value.toolbarTips)==null?void 0:Re.fullscreen,onClick:()=>{n()}},[t.createVNode(k.Icon,{name:e.setting.fullscreen?"fullscreen-exit":"fullscreen"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(De=o.value.toolbarTips)==null?void 0:De.fullscreen])]);case"preview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(He=o.value.toolbarTips)==null?void 0:He.preview,onClick:()=>{e.updateSetting("preview")}},[t.createVNode(k.Icon,{name:"preview"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Oe=o.value.toolbarTips)==null?void 0:Oe.preview])]);case"htmlPreview":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Pe=o.value.toolbarTips)==null?void 0:Pe.htmlPreview,onClick:()=>{e.updateSetting("htmlPreview")}},[t.createVNode(k.Icon,{name:"coding"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(Fe=o.value.toolbarTips)==null?void 0:Fe.htmlPreview])]);case"catalog":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(Be=o.value.toolbarTips)==null?void 0:Be.catalog,onClick:()=>{s.bus.emit(l,s.CHANGE_CATALOG_VISIBLE)},key:"bar-catalog"},[t.createVNode(k.Icon,{name:"catalog"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(qe=o.value.toolbarTips)==null?void 0:qe.catalog])]);case"github":return t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(_e=o.value.toolbarTips)==null?void 0:_e.github,onClick:()=>le.linkTo("https://github.com/imzbf/md-editor-v3")},[t.createVNode(k.Icon,{name:"github"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(je=o.value.toolbarTips)==null?void 0:je.github])]);case"mermaid":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.mermaid,onChange:x=>{u.mermaid=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.mermaid=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("flow")}},[(Ge=o.value.mermaid)==null?void 0:Ge.flow]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("sequence")}},[(Ue=o.value.mermaid)==null?void 0:Ue.sequence]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("gantt")}},[(Ke=o.value.mermaid)==null?void 0:Ke.gantt]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("class")}},[(We=o.value.mermaid)==null?void 0:We.class]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("state")}},[(ze=o.value.mermaid)==null?void 0:ze.state]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("pie")}},[(Ze=o.value.mermaid)==null?void 0:Ze.pie]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("relationship")}},[(Xe=o.value.mermaid)==null?void 0:Xe.relationship]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-mermaid`,onClick:()=>{d("journey")}},[(Ye=o.value.mermaid)==null?void 0:Ye.journey])]),key:"bar-mermaid"},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.mermaid},[t.createVNode(k.Icon,{name:"mermaid"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.mermaid])])]}});case"katex":return t.createVNode(z.Dropdown,{relative:`#${f}`,visible:u.katex,onChange:x=>{u.katex=x},overlay:t.createVNode("ul",{class:`${r.prefix}-menu`,onClick:()=>{u.katex=!1}},[t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{d("katexInline")}},[(Je=o.value.katex)==null?void 0:Je.inline]),t.createVNode("li",{class:`${r.prefix}-menu-item ${r.prefix}-menu-item-katex`,onClick:()=>{d("katexBlock")}},[(Qe=o.value.katex)==null?void 0:Qe.block])]),key:"bar-katex"},{default:()=>{var x,I;return[t.createVNode("div",{class:`${r.prefix}-toolbar-item`,title:(x=o.value.toolbarTips)==null?void 0:x.katex},[t.createVNode(k.Icon,{name:"formula"},null),e.showToolbarName&&t.createVNode("div",{class:`${r.prefix}-toolbar-item-name`},[(I=o.value.toolbarTips)==null?void 0:I.katex])])]}})}else if(e.defToolbars instanceof Array){const x=e.defToolbars[b];return x?t.cloneVNode(x,{theme:a.value,language:i.value,insert(ue){s.bus.emit(l,s.REPLACE,"universal",{generate:ue})}}):""}else if(e.defToolbars&&e.defToolbars.children instanceof Array){const x=e.defToolbars.children[b];return x?t.cloneVNode(x,{theme:a.value,language:i.value,insert(ue){s.bus.emit(l,s.REPLACE,"universal",{generate:ue})}}):""}else return""};return t.watch(()=>e.toolbars,()=>{t.nextTick(()=>{g.value&&le.draggingScroll(g.value)})},{immediate:!0}),()=>{const b=$.value[0].map(N=>h(N)),C=$.value[1].map(N=>h(N));return t.createVNode(t.Fragment,null,[e.toolbars.length>0&&t.createVNode("div",{class:`${r.prefix}-toolbar-wrapper`,ref:g,id:f},[t.createVNode("div",{class:[`${r.prefix}-toolbar`,e.showToolbarName&&`${r.prefix}-stn`]},[t.createVNode("div",{class:`${r.prefix}-toolbar-left`,ref:V},[b]),t.createVNode("div",{class:`${r.prefix}-toolbar-right`},[C])])]),t.createVNode("input",{ref:m,accept:"image/*",type:"file",multiple:!0,style:{display:"none"}},null),t.createVNode(Dt,{linkVisible:v.linkVisible,clipVisible:v.clipVisible,type:v.type,onCancel:()=>{v.linkVisible=!1,v.clipVisible=!1},onOk:N=>{N&&d(v.type,{desc:N.desc,url:N.url}),v.linkVisible=!1,v.clipVisible=!1}},null)])}}}),Ot=(e,l)=>{const o=le.debounce(()=>{e.removeEventListener("scroll",a),e.addEventListener("scroll",a),l.removeEventListener("scroll",a),l.addEventListener("scroll",a)},50),a=i=>{const n=e.clientHeight,f=l.clientHeight,g=e.scrollHeight,u=l.scrollHeight,d=(g-n)/(u-f);i.target===e?(l.removeEventListener("scroll",a),l.scrollTo({top:e.scrollTop/d}),o()):(e.removeEventListener("scroll",a),e.scrollTo({top:l.scrollTop*d}),o())};return[()=>{o().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",a),l.removeEventListener("scroll",a)}]},Pt=(e,l,o)=>{const{view:a}=o,i=le.createSmoothScroll(),n=$=>a.lineBlockAt(a.state.doc.line($).from).top,f=$=>a.lineBlockAt(a.state.doc.line($).from).height;let g=[];const u=()=>{g=[];const $=Array.from(l.querySelectorAll("[data-line]")).map(b=>Number(b.dataset.line)+1),{lines:m}=a.state.doc;let p=1,h=$.shift()??m;for(let b=1;b<=m;b++)b===h&&(p=b,h=$.shift()||m+1),g.push({start:p,end:h-1})};let d=0,v=0;const V=le.throttle($=>{var C,N,T,S,A,Z,X;if(!((C=l.firstElementChild)!=null&&C.firstElementChild))return;const m=a.lineBlockAtHeight(a.scrollDOM.scrollTop),{number:p}=a.state.doc.lineAt(m.from);if(p>g.length||a.state.doc.lines<g[g.length-1].end)return;let h=+getComputedStyle(l).paddingTop.replace("px","");const b=+getComputedStyle(l).paddingBottom.replace("px","");if($.target===e){if(v!==0)return;d++;const y=g[p-1];let w=n(y.end)+f(y.end),B=0;const F=n(y.start),R=l.querySelector(`[data-line="${y.start-1}"]`)||((N=l.firstElementChild)==null?void 0:N.firstElementChild),L=l.querySelector(`[data-line="${y.end}"]`)||((T=l.lastElementChild)==null?void 0:T.lastElementChild);let M=0,D=0;F===0?R===L?(h=0,w=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight,B=a.scrollDOM.scrollTop/w,M=L.offsetTop+L.offsetHeight-l.clientHeight):(B=a.scrollDOM.scrollTop/w,M=L.offsetTop):w>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(B=(a.scrollDOM.scrollTop-F)/(a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight-F),D=R.offsetTop,M=l.scrollHeight-l.clientHeight-D+10):(B=(a.scrollDOM.scrollTop-F)/(w-F),D=R.offsetTop,M=L.offsetTop-D);const _=D-h+M*B;i(l,_,()=>{d--})}else{if(d!==0)return;v++;const y=Array.from(l.querySelectorAll("[data-line]")),w=l.scrollTop,B=l.scrollHeight;let F=y.length===0?1:Math.ceil(Number(y[y.length-1].dataset.line)*(w/B)),R=(S=l.firstElementChild)==null?void 0:S.firstElementChild;for(let H=F;H>=0;H--){const O=l.querySelector(`[data-line="${H}"]`);if(O&&O.offsetTop<=w){R=O,F=H;break}}let L=(A=l.firstElementChild)==null?void 0:A.firstElementChild,M=(Z=l.firstElementChild)==null?void 0:Z.lastElementChild;for(;y.length>0;){const H=y.indexOf(R);if(H+1>=y.length)break;const O=y[H+1];if(H===-1){M=O;break}const Q=R.offsetTop;if(Q>w){if(H===0){L=R,M=O;break}R=y[H-1];continue}const ie=O.offsetTop;if(Q<=w&&ie>w){L=R,M=O;break}R=O}const D=L.offsetTop;let _=M.offsetTop,j=0;const{start:ne,end:Y}=g[Number(L.dataset.line||0)],K=n(ne);let G=n(Y);const J=f(Y);let U=0;L===((X=l.firstElementChild)==null?void 0:X.firstElementChild)?(L===M?(_=M.offsetHeight-l.offsetHeight+h+b,U=a.contentDOM.offsetHeight-a.scrollDOM.offsetHeight):U=G+J-K,j=Math.max(w/_,0)):G>a.scrollDOM.scrollHeight-a.scrollDOM.clientHeight?(j=Math.max((w-D)/(l.scrollHeight-D-l.clientHeight),0),G=n(a.state.doc.lines)+f(a.state.doc.lines),U=8+G-K-e.clientHeight):(j=Math.max((w-D)/(_-D),0),U=G+J-K),i(e,K+U*j,()=>{v--})}},10);return[()=>{u(),e.addEventListener("scroll",V),l.addEventListener("scroll",V),e.dispatchEvent(new Event("scroll"))},()=>{g=[],e.removeEventListener("scroll",V),l.removeEventListener("scroll",V)}]},Ft=(e,l,o)=>{const a=t.inject("editorId");let i=()=>{},n=()=>{};const f=()=>{i();const g=document.querySelector(`#${a} .cm-scroller`),u=document.querySelector(`[id="${a}-preview-wrapper"][data-show="true"]`),d=document.querySelector(`[id="${a}-html-wrapper"][data-show="true"]`);(u||d)&&([n,i]=(u?Pt:Ot)(g,u||d,o.value)),e.scrollAuto&&n()};t.watch([l,t.toRef(e.setting,"preview"),t.toRef(e.setting,"htmlPreview"),t.toRef(e.setting,"fullscreen"),t.toRef(e.setting,"pageFullscreen")],()=>{t.nextTick(f)}),t.watch(()=>e.scrollAuto,g=>{g?n():i()}),t.onMounted(f)},Bt=Ft,qt=(e,l,o)=>{var v,V,$,m,p,h;let a="",i=0,n=0,f=!0,g=!1;const u=l.getSelectedText(),d=(v=r.configOption.editorConfig)==null?void 0:v.mermaidTemplate;if(/^h[1-6]{1}$/.test(e)){const b=e.replace(/^h(\d)/,(C,N)=>new Array(Number(N)).fill("#",0,N).join(""));a=`${b} ${u}`,i=b.length+1}else if(e==="prettier"){const b=window.prettier||(($=(V=r.configOption.editorExtensions)==null?void 0:V.prettier)==null?void 0:$.prettierInstance),C=[((m=window.prettierPlugins)==null?void 0:m.markdown)||((h=(p=r.configOption.editorExtensions)==null?void 0:p.prettier)==null?void 0:h.parserMarkdownInstance)];!b||C[0]===void 0?(s.bus.emit(o.editorId,s.ERROR_CATCHER,{name:"prettier",message:"prettier is undefined"}),a=l.getValue()):a=b.format(l.getValue(),{parser:"markdown",plugins:C}),f=!1,g=!0}else switch(e){case"bold":{a=`**${u}**`,i=2,n=-2;break}case"underline":{a=`<u>${u}</u>`,i=3,n=-4;break}case"italic":{a=`*${u}*`,i=1,n=-1;break}case"strikeThrough":{a=`~~${u}~~`,i=2,n=-2;break}case"sub":{a=`<sub>${u}</sub>`,i=5,n=-6;break}case"sup":{a=`<sup>${u}</sup>`,i=5,n=-6;break}case"codeRow":{a="`"+u+"`",i=1,n=-1;break}case"quote":{a=`> ${u}`,i=2;break}case"orderedList":{a=`1. ${u}`,i=3;break}case"unorderedList":{a=`- ${u}`,i=2;break}case"task":{a=`- [ ] ${u}`,i=6;break}case"code":{const b=o.text||u||"",C=o.mode||"language";a=`\`\`\`${C}
2
2
  ${b}
3
3
  \`\`\`
4
- `,i=3,n=3+C.length-a.length;break}case"table":{a="|";const{selectedShape:b={x:1,y:1}}=o,{x:C,y:V}=b;for(let T=0;T<=V;T++)a+=" col |";a+=`
5
- |`;for(let T=0;T<=V;T++)a+=" - |";for(let T=0;T<=C;T++){a+=`
6
- |`;for(let S=0;S<=V;S++)a+=" content |"}i=2,n=5-a.length;break}case"link":{const{desc:b,url:C}=o;a=`[${b}](${C})`,f=!1;break}case"image":{const{desc:b,url:C,urls:V}=o;V instanceof Array?a=V.reduce((T,S)=>T+`![${b}](${S})
4
+ `,i=3,n=3+C.length-a.length;break}case"table":{a="|";const{selectedShape:b={x:1,y:1}}=o,{x:C,y:N}=b;for(let T=0;T<=N;T++)a+=" col |";a+=`
5
+ |`;for(let T=0;T<=N;T++)a+=" - |";for(let T=0;T<=C;T++){a+=`
6
+ |`;for(let S=0;S<=N;S++)a+=" content |"}i=2,n=5-a.length;break}case"link":{const{desc:b,url:C}=o;a=`[${b}](${C})`,f=!1;break}case"image":{const{desc:b,url:C,urls:N}=o;N instanceof Array?a=N.reduce((T,S)=>T+`![${b}](${S})
7
7
  `,""):a=`![${b}](${C})
8
8
  `,f=!1;break}case"flow":{a=`\`\`\`mermaid
9
9
  ${(d==null?void 0:d.flow)||`flowchart TD
@@ -64,4 +64,4 @@ $$
64
64
  `,`
65
65
  $$`,"title")},...["note","abstract","info","tip","success","question","warning","failure","danger","bug","example","quote","hint","caution","error","attention"].map(i=>({label:`!!! ${i}`,type:"text",apply:ce("!!!",` ${i}`," Title",`
66
66
 
67
- !!!`,"title")}))]}};return xt.autocompletion({override:e?[l,...e]:[l]})},gt=uo,W=e=>{const l=new E.Compartment;return a=>(l.get(e.state)?e.dispatch({effects:l.reconfigure(a)}):e.dispatch({effects:E.StateEffect.appendConfig.of(l.of(a))}),!0)};class mo{constructor(l){q(this,"view");q(this,"maxLength",Number.MAX_SAFE_INTEGER);q(this,"toggleTabSize");q(this,"togglePlaceholder");q(this,"setExtensions");q(this,"toggleDisabled");q(this,"toggleReadOnly");q(this,"toggleMaxlength");this.view=l,this.toggleTabSize=W(this.view),this.togglePlaceholder=W(this.view),this.setExtensions=W(this.view),this.toggleDisabled=W(this.view),this.toggleReadOnly=W(this.view),this.toggleMaxlength=W(this.view)}getValue(){return this.view.state.doc.toString()}setValue(l,o=0,a=this.view.state.doc.length){this.view.dispatch({changes:{from:o,to:a,insert:l}})}getSelectedText(){const{from:l,to:o}=this.view.state.selection.main;return this.view.state.sliceDoc(l,o)}replaceSelectedText(l,o={select:!0,deviationStart:0,deviationEnd:0,replaceAll:!1},a){try{if(o.replaceAll){if(this.setValue(l),l.length>this.maxLength)throw new Error("The input text is too long");return}if(this.view.state.doc.length-this.getSelectedText().length+l.length>this.maxLength)throw new Error("The input text is too long");const{from:i}=this.view.state.selection.main;if(this.view.dispatch(this.view.state.replaceSelection(l)),o.select){const n=i+l.length+o.deviationEnd;this.view.dispatch({selection:E.EditorSelection.create([E.EditorSelection.range(i+o.deviationStart,n),E.EditorSelection.cursor(n)],1)})}this.view.focus()}catch(i){if(i.message==="The input text is too long")s.bus.emit(a,s.ERROR_CATCHER,{name:"overlength",message:i.message,data:l});else throw i}}setTabSize(l){this.toggleTabSize([E.EditorState.tabSize.of(l),re.indentUnit.of(" ".repeat(l))])}setPlaceholder(l){this.togglePlaceholder(ae.placeholder(l))}focus(l){if(this.view.focus(),!l)return;let o=0,a=0,i=0;switch(l){case"start":break;case"end":{o=a=i=this.getValue().length;break}default:o=l.rangeAnchor||l.cursorPos,a=l.rangeHead||l.cursorPos,i=l.cursorPos}this.view.dispatch({scrollIntoView:!0,selection:E.EditorSelection.create([E.EditorSelection.range(o,a),E.EditorSelection.cursor(i)],1)})}setDisabled(l){this.toggleDisabled([ae.EditorView.editable.of(!l)])}setReadOnly(l){this.toggleReadOnly([E.EditorState.readOnly.of(l)])}setMaxLength(l){this.maxLength=l,this.toggleMaxlength([E.EditorState.changeFilter.of(o=>o.newDoc.length<=l)])}}const fo=e=>{const l=t.inject("editorId");return a=>{if(!a.clipboardData)return;if(a.clipboardData.files.length>0){const{files:n}=a.clipboardData;s.bus.emit(l,s.UPLOAD_IMAGE,Array.from(n).filter(f=>/image\/.*/.test(f.type))),a.preventDefault();return}if(e.autoDetectCode&&a.clipboardData.types.includes("vscode-editor-data")){const n=JSON.parse(a.clipboardData.getData("vscode-editor-data"));s.bus.emit(l,s.REPLACE,"code",{mode:n.mode,text:a.clipboardData.getData("text/plain")}),a.preventDefault();return}const i=a.clipboardData.getData("text/plain");e.maxlength&&i.length+e.modelValue.length>e.maxlength&&s.bus.emit(l,s.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:i})}},go=fo,bo=e=>{const l=t.inject("editorId");t.onMounted(()=>{s.bus.on(l,{name:s.TEXTAREA_FOCUS,callback(o){var a;(a=e.value)==null||a.focus(o)}})})},ho=bo,vo=(e,l)=>{const o={key:"Ctrl-b",mac:"Cmd-b",run:()=>(s.bus.emit(e,s.REPLACE,"bold"),!0)},a={key:"Ctrl-s",mac:"Cmd-s",run:S=>(s.bus.emit(e,s.ON_SAVE,S.state.doc.toString()),!0),shift:()=>(s.bus.emit(e,s.REPLACE,"strikeThrough"),!0)},i={key:"Ctrl-u",mac:"Cmd-u",run:()=>(s.bus.emit(e,s.REPLACE,"underline"),!0),shift:()=>(s.bus.emit(e,s.REPLACE,"unorderedList"),!0)},n={key:"Ctrl-i",mac:"Cmd-i",run:()=>(s.bus.emit(e,s.REPLACE,"italic"),!0),shift:()=>(s.bus.emit(e,s.OPEN_MODALS,"image"),!0)},f={key:"Ctrl-1",mac:"Cmd-1",run:()=>(s.bus.emit(e,s.REPLACE,"h1"),!0)},g={key:"Ctrl-2",mac:"Cmd-2",run:()=>(s.bus.emit(e,s.REPLACE,"h2"),!0)},u={key:"Ctrl-3",mac:"Cmd-3",run:()=>(s.bus.emit(e,s.REPLACE,"h3"),!0)},d={key:"Ctrl-4",mac:"Cmd-4",run:()=>(s.bus.emit(e,s.REPLACE,"h4"),!0)},v={key:"Ctrl-5",mac:"Cmd-5",run:()=>(s.bus.emit(e,s.REPLACE,"h5"),!0)},$={key:"Ctrl-6",mac:"Cmd-6",run:()=>(s.bus.emit(e,s.REPLACE,"h6"),!0)},N={key:"Ctrl-ArrowUp",mac:"Cmd-ArrowUp",run:()=>(s.bus.emit(e,s.REPLACE,"sup"),!0)},m={key:"Ctrl-ArrowDown",mac:"Cmd-ArrowDown",run:()=>(s.bus.emit(e,s.REPLACE,"sub"),!0)},p={key:"Ctrl-o",mac:"Cmd-o",run:()=>(s.bus.emit(e,s.REPLACE,"orderedList"),!0)},h={key:"Ctrl-c",mac:"Cmd-c",shift:()=>(s.bus.emit(e,s.REPLACE,"code"),!0),any(S,A){return(A.ctrlKey||A.metaKey)&&A.altKey&&A.code==="KeyC"?(s.bus.emit(e,s.REPLACE,"codeRow"),!0):!1}},b={key:"Ctrl-l",mac:"Cmd-l",run:()=>(s.bus.emit(e,s.OPEN_MODALS,"link"),!0)},C={key:"Ctrl-f",mac:"Cmd-f",shift:()=>l.noPrettier?!1:(s.bus.emit(e,s.REPLACE,"prettier"),!0)},V={any:(S,A)=>(A.ctrlKey||A.metaKey)&&A.altKey&&A.shiftKey&&A.code==="KeyT"?(s.bus.emit(e,s.REPLACE,"table"),!0):!1},T={key:"Ctrl-d",mac:"Cmd-d",run:se.deleteLine,preventDefault:!0};return[o,T,a,i,n,f,g,u,d,v,$,N,m,p,h,b,C,V]},po=vo,Co=e=>{const l=t.inject("tabWidth"),o=t.inject("editorId"),a=t.inject("theme"),i=t.ref(),n=t.shallowRef(),f=new E.Compartment,g=new E.Compartment,u=new E.Compartment,d=po(o,e),v=go(e),$=[ae.keymap.of([...d,se.indentWithTab]),ee.minimalSetup,f.of(kt.markdown({codeLanguages:Ct.languages})),ee.EditorView.lineWrapping,ee.EditorView.updateListener.of(m=>{m.docChanged&&e.onChange(m.state.doc.toString())}),ee.EditorView.domEventHandlers({paste:v,blur:e.onBlur,focus:e.onFocus,drop:e.onDrop,input:m=>{e.onInput&&e.onInput(m);const{data:p}=m;e.maxlength&&e.modelValue.length+p.length>e.maxlength&&s.bus.emit(o,s.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:p})}})],N=()=>{const m=[...$,g.of(a.value==="light"?mt:nt),u.of(gt(e.completions))];return r.configOption.codeMirrorExtensions(a.value,m,[...d])};return t.onMounted(()=>{const m=new ee.EditorView({doc:e.modelValue,parent:i.value,extensions:[N()]}),p=new mo(m);n.value=p,setTimeout(()=>{p.setTabSize(l),p.setDisabled(e.disabled),p.setReadOnly(e.readonly),e.placeholder&&p.setPlaceholder(e.placeholder),typeof e.maxlength=="number"&&p.setMaxLength(e.maxlength),e.autofocus&&m.focus()},0),s.bus.on(o,{name:s.CTRL_Z,callback(){se.undo(m)}}),s.bus.on(o,{name:s.CTRL_SHIFT_Z,callback(){se.redo(m)}}),s.bus.on(o,{name:s.REPLACE,callback(h,b={}){var T;const{text:C,options:V}=qt(h,n.value,b);(T=n.value)==null||T.replaceSelectedText(C,V,o)}})}),t.watch(a,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:g.reconfigure(a.value==="light"?mt:nt)})},{deep:!0}),t.watch(()=>e.completions,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:u.reconfigure(gt(e.completions))})},{deep:!0}),t.watch(()=>e.modelValue,()=>{var m,p;((m=n.value)==null?void 0:m.getValue())!==e.modelValue&&((p=n.value)==null||p.setValue(e.modelValue))}),t.watch(()=>e.placeholder,()=>{var m;(m=n.value)==null||m.setPlaceholder(e.placeholder)}),t.watch(()=>e.disabled,()=>{var m;(m=n.value)==null||m.setDisabled(e.disabled)}),t.watch(()=>e.readonly,()=>{var m;(m=n.value)==null||m.setDisabled(e.readonly)}),t.watch(()=>e.maxlength,()=>{var m;e.maxlength&&((m=n.value)==null||m.setMaxLength(e.maxlength))}),ho(n),{inputWrapperRef:i,codeMirrorUt:n}},ko=Co,xo=t.defineComponent({name:"MDEditorContent",props:P.contentProps,setup(e){const l=t.inject("editorId"),o=t.ref(""),{inputWrapperRef:a,codeMirrorUt:i}=ko(e);return Bt(e,o,i),()=>t.createVNode("div",{class:`${r.prefix}-content`},[t.createVNode("div",{class:`${r.prefix}-input-wrapper`,ref:a},null),t.createVNode(P.ContentPreview,{modelValue:e.modelValue,setting:e.setting,onHtmlChanged:n=>{o.value=n,e.onHtmlChanged(n)},onGetCatalog:e.onGetCatalog,mdHeadingId:e.mdHeadingId,noMermaid:e.noMermaid,sanitize:e.sanitize,noKatex:e.noKatex,formatCopiedText:e.formatCopiedText,noHighlight:e.noHighlight,noImgZoomIn:e.noImgZoomIn},null),e.catalogVisible&&t.createVNode(bt,{theme:e.theme,class:`${r.prefix}-catalog-editor`,editorId:l,mdHeadingId:e.mdHeadingId,key:"internal-catalog"},null)])}}),No=t.defineComponent({props:{modelValue:{type:String,default:""}},setup(e){const l=t.inject("usedLanguageText");return()=>{var o,a;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`},[`${(o=l.value.footer)==null?void 0:o.markdownTotal}:`]),t.createVNode("span",null,[((a=e.modelValue)==null?void 0:a.length)||0])])}}}),Vo={checked:{type:Boolean,default:!1},onChange:{type:Function,default:()=>{}}},$o=t.defineComponent({props:Vo,setup(e){return()=>t.createVNode("div",{class:[`${r.prefix}-checkbox`,e.checked&&`${r.prefix}-checkbox-checked`],onClick:()=>{e.onChange(!e.checked)}},null)}}),To={scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}}},yo=t.defineComponent({props:To,setup(e){const l=t.inject("usedLanguageText");return()=>{var o;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`,onClick:()=>{e.onScrollAutoChange(!e.scrollAuto)}},[(o=l.value.footer)==null?void 0:o.scrollAuto]),t.createVNode($o,{checked:e.scrollAuto,onChange:e.onScrollAutoChange},null)])}}}),wo={modelValue:{type:String,default:""},footers:{type:Array,default:[]},scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}},defFooters:{type:Object}},Eo=t.defineComponent({name:"MDEditorFooter",props:wo,setup(e){const l=t.computed(()=>{const a=e.footers.indexOf("="),i=a===-1?e.footers:e.footers.slice(0,a),n=a===-1?[]:e.footers.slice(a,Number.MAX_SAFE_INTEGER);return[i,n]}),o=a=>{if(r.allFooter.includes(a))switch(a){case"markdownTotal":return t.createVNode(No,{modelValue:e.modelValue},null);case"scrollSwitch":return t.createVNode(yo,{scrollAuto:e.scrollAuto,onScrollAutoChange:e.onScrollAutoChange},null)}else return e.defFooters instanceof Array?e.defFooters[a]||"":e.defFooters&&e.defFooters.children instanceof Array&&e.defFooters.children[a]||""};return()=>{const a=l.value[0].map(n=>o(n)),i=l.value[1].map(n=>o(n));return t.createVNode("div",{class:`${r.prefix}-footer`},[t.createVNode("div",{class:`${r.prefix}-footer-left`},[a]),t.createVNode("div",{class:`${r.prefix}-footer-right`},[i])])}}}),So=t.defineComponent({name:"MdEditorV3",props:P.editorProps,emits:P.editorEmits,setup(e,l){const{editorId:o,noKatex:a,noMermaid:i,noPrettier:n,noUploadImg:f,noHighlight:g}=e,u=t.reactive({scrollAuto:e.scrollAuto});P.useOnSave(e,l),P.useProvide(e),P.useExpansion(e),P.useErrorCatcher(e,l);const[d,v]=P.useConfig(e,l),$=P.useCatalog(e);return t.onBeforeUnmount(()=>{s.bus.clear(o)}),P.useExpose(e,l,$,d,v),()=>{var p;const N=et.getSlot({props:e,ctx:l},"defToolbars"),m=et.getSlot({props:e,ctx:l},"defFooters");return t.createVNode("div",{id:o,class:[r.prefix,e.class,e.theme==="dark"&&`${r.prefix}-dark`,d.fullscreen||d.pageFullscreen?`${r.prefix}-fullscreen`:""],style:e.style},[t.createVNode(Ht,{noPrettier:n,toolbars:e.toolbars,toolbarsExclude:e.toolbarsExclude,setting:d,updateSetting:v,tableShape:e.tableShape,defToolbars:N,noUploadImg:f,showToolbarName:e.showToolbarName},null),t.createVNode(xo,{modelValue:e.modelValue,setting:d,mdHeadingId:e.mdHeadingId,noMermaid:i,noPrettier:n,sanitize:e.sanitize,placeholder:e.placeholder,noKatex:a,scrollAuto:u.scrollAuto,formatCopiedText:e.formatCopiedText,autofocus:e.autoFocus,disabled:e.disabled,readonly:e.readOnly,maxlength:e.maxLength,autoDetectCode:e.autoDetectCode,noHighlight:g,onChange:h=>{e.onChange?e.onChange(h):(l.emit("update:modelValue",h),l.emit("onChange",h))},onHtmlChanged:h=>{e.onHtmlChanged?e.onHtmlChanged(h):l.emit("onHtmlChanged",h)},onGetCatalog:h=>{e.onGetCatalog?e.onGetCatalog(h):l.emit("onGetCatalog",h)},onBlur:h=>{e.onBlur?e.onBlur(h):l.emit("onBlur",h)},onFocus:h=>{e.onFocus?e.onFocus(h):l.emit("onFocus",h)},onInput:h=>{e.onInput?e.onInput(h):l.emit("onInput",h)},completions:e.completions,catalogVisible:$.value,theme:e.theme,noImgZoomIn:e.noImgZoomIn,onDrop:h=>{e.onDrop?e.onDrop(h):l.emit("onDrop",h)}},null),((p=e.footers)==null?void 0:p.length)>0&&t.createVNode(Eo,{modelValue:e.modelValue,footers:e.footers,defFooters:m,scrollAuto:u.scrollAuto,onScrollAutoChange:h=>u.scrollAuto=h},null)])}}}),de=So;de.install=e=>(e.component(de.name,de),e.use(Nt).use(z.DropdownToolbar).use(Vt).use(bt).use(P.MdPreview),e);module.exports=de;
67
+ !!!`,"title")}))]}};return xt.autocompletion({override:e?[l,...e]:[l]})},gt=uo,W=e=>{const l=new E.Compartment;return a=>(l.get(e.state)?e.dispatch({effects:l.reconfigure(a)}):e.dispatch({effects:E.StateEffect.appendConfig.of(l.of(a))}),!0)};class mo{constructor(l){q(this,"view");q(this,"maxLength",Number.MAX_SAFE_INTEGER);q(this,"toggleTabSize");q(this,"togglePlaceholder");q(this,"setExtensions");q(this,"toggleDisabled");q(this,"toggleReadOnly");q(this,"toggleMaxlength");this.view=l,this.toggleTabSize=W(this.view),this.togglePlaceholder=W(this.view),this.setExtensions=W(this.view),this.toggleDisabled=W(this.view),this.toggleReadOnly=W(this.view),this.toggleMaxlength=W(this.view)}getValue(){return this.view.state.doc.toString()}setValue(l,o=0,a=this.view.state.doc.length){this.view.dispatch({changes:{from:o,to:a,insert:l}})}getSelectedText(){const{from:l,to:o}=this.view.state.selection.main;return this.view.state.sliceDoc(l,o)}replaceSelectedText(l,o={select:!0,deviationStart:0,deviationEnd:0,replaceAll:!1},a){try{if(o.replaceAll){if(this.setValue(l),l.length>this.maxLength)throw new Error("The input text is too long");return}if(this.view.state.doc.length-this.getSelectedText().length+l.length>this.maxLength)throw new Error("The input text is too long");const{from:i}=this.view.state.selection.main;if(this.view.dispatch(this.view.state.replaceSelection(l)),o.select){const n=i+l.length+o.deviationEnd;this.view.dispatch({selection:E.EditorSelection.create([E.EditorSelection.range(i+o.deviationStart,n),E.EditorSelection.cursor(n)],1)})}this.view.focus()}catch(i){if(i.message==="The input text is too long")s.bus.emit(a,s.ERROR_CATCHER,{name:"overlength",message:i.message,data:l});else throw i}}setTabSize(l){this.toggleTabSize([E.EditorState.tabSize.of(l),re.indentUnit.of(" ".repeat(l))])}setPlaceholder(l){this.togglePlaceholder(ae.placeholder(l))}focus(l){if(this.view.focus(),!l)return;let o=0,a=0,i=0;switch(l){case"start":break;case"end":{o=a=i=this.getValue().length;break}default:o=l.rangeAnchor||l.cursorPos,a=l.rangeHead||l.cursorPos,i=l.cursorPos}this.view.dispatch({scrollIntoView:!0,selection:E.EditorSelection.create([E.EditorSelection.range(o,a),E.EditorSelection.cursor(i)],1)})}setDisabled(l){this.toggleDisabled([ae.EditorView.editable.of(!l)])}setReadOnly(l){this.toggleReadOnly([E.EditorState.readOnly.of(l)])}setMaxLength(l){this.maxLength=l,this.toggleMaxlength([E.EditorState.changeFilter.of(o=>o.newDoc.length<=l)])}}const fo=e=>{const l=t.inject("editorId");return a=>{if(!a.clipboardData)return;if(a.clipboardData.files.length>0){const{files:n}=a.clipboardData;s.bus.emit(l,s.UPLOAD_IMAGE,Array.from(n).filter(f=>/image\/.*/.test(f.type))),a.preventDefault();return}if(e.autoDetectCode&&a.clipboardData.types.includes("vscode-editor-data")){const n=JSON.parse(a.clipboardData.getData("vscode-editor-data"));s.bus.emit(l,s.REPLACE,"code",{mode:n.mode,text:a.clipboardData.getData("text/plain")}),a.preventDefault();return}const i=a.clipboardData.getData("text/plain");e.maxlength&&i.length+e.modelValue.length>e.maxlength&&s.bus.emit(l,s.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:i})}},go=fo,bo=e=>{const l=t.inject("editorId");t.onMounted(()=>{s.bus.on(l,{name:s.TEXTAREA_FOCUS,callback(o){var a;(a=e.value)==null||a.focus(o)}})})},ho=bo,vo=(e,l)=>{const o={key:"Ctrl-b",mac:"Cmd-b",run:()=>(s.bus.emit(e,s.REPLACE,"bold"),!0)},a={key:"Ctrl-s",mac:"Cmd-s",run:S=>(s.bus.emit(e,s.ON_SAVE,S.state.doc.toString()),!0),shift:()=>(s.bus.emit(e,s.REPLACE,"strikeThrough"),!0)},i={key:"Ctrl-u",mac:"Cmd-u",run:()=>(s.bus.emit(e,s.REPLACE,"underline"),!0),shift:()=>(s.bus.emit(e,s.REPLACE,"unorderedList"),!0)},n={key:"Ctrl-i",mac:"Cmd-i",run:()=>(s.bus.emit(e,s.REPLACE,"italic"),!0),shift:()=>(s.bus.emit(e,s.OPEN_MODALS,"image"),!0)},f={key:"Ctrl-1",mac:"Cmd-1",run:()=>(s.bus.emit(e,s.REPLACE,"h1"),!0)},g={key:"Ctrl-2",mac:"Cmd-2",run:()=>(s.bus.emit(e,s.REPLACE,"h2"),!0)},u={key:"Ctrl-3",mac:"Cmd-3",run:()=>(s.bus.emit(e,s.REPLACE,"h3"),!0)},d={key:"Ctrl-4",mac:"Cmd-4",run:()=>(s.bus.emit(e,s.REPLACE,"h4"),!0)},v={key:"Ctrl-5",mac:"Cmd-5",run:()=>(s.bus.emit(e,s.REPLACE,"h5"),!0)},V={key:"Ctrl-6",mac:"Cmd-6",run:()=>(s.bus.emit(e,s.REPLACE,"h6"),!0)},$={key:"Ctrl-ArrowUp",mac:"Cmd-ArrowUp",run:()=>(s.bus.emit(e,s.REPLACE,"sup"),!0)},m={key:"Ctrl-ArrowDown",mac:"Cmd-ArrowDown",run:()=>(s.bus.emit(e,s.REPLACE,"sub"),!0)},p={key:"Ctrl-o",mac:"Cmd-o",run:()=>(s.bus.emit(e,s.REPLACE,"orderedList"),!0)},h={key:"Ctrl-c",mac:"Cmd-c",shift:()=>(s.bus.emit(e,s.REPLACE,"code"),!0),any(S,A){return(A.ctrlKey||A.metaKey)&&A.altKey&&A.code==="KeyC"?(s.bus.emit(e,s.REPLACE,"codeRow"),!0):!1}},b={key:"Ctrl-l",mac:"Cmd-l",run:()=>(s.bus.emit(e,s.OPEN_MODALS,"link"),!0)},C={key:"Ctrl-f",mac:"Cmd-f",shift:()=>l.noPrettier?!1:(s.bus.emit(e,s.REPLACE,"prettier"),!0)},N={any:(S,A)=>(A.ctrlKey||A.metaKey)&&A.altKey&&A.shiftKey&&A.code==="KeyT"?(s.bus.emit(e,s.REPLACE,"table"),!0):!1},T={key:"Ctrl-d",mac:"Cmd-d",run:se.deleteLine,preventDefault:!0};return[o,T,a,i,n,f,g,u,d,v,V,$,m,p,h,b,C,N]},po=vo,Co=e=>{const l=t.inject("tabWidth"),o=t.inject("editorId"),a=t.inject("theme"),i=t.ref(),n=t.shallowRef(),f=new E.Compartment,g=new E.Compartment,u=new E.Compartment,d=po(o,e),v=go(e),V=[ae.keymap.of([...d,se.indentWithTab]),ee.minimalSetup,f.of(kt.markdown({codeLanguages:Ct.languages})),ee.EditorView.lineWrapping,ee.EditorView.updateListener.of(m=>{m.docChanged&&e.onChange(m.state.doc.toString())}),ee.EditorView.domEventHandlers({paste:v,blur:e.onBlur,focus:e.onFocus,drop:e.onDrop,input:m=>{e.onInput&&e.onInput(m);const{data:p}=m;e.maxlength&&e.modelValue.length+p.length>e.maxlength&&s.bus.emit(o,s.ERROR_CATCHER,{name:"overlength",message:"The input text is too long",data:p})}})],$=()=>{const m=[...V,g.of(a.value==="light"?mt:nt),u.of(gt(e.completions))];return r.configOption.codeMirrorExtensions(a.value,m,[...d])};return t.onMounted(()=>{const m=new ee.EditorView({doc:e.modelValue,parent:i.value,extensions:[$()]}),p=new mo(m);n.value=p,setTimeout(()=>{p.setTabSize(l),p.setDisabled(e.disabled),p.setReadOnly(e.readonly),e.placeholder&&p.setPlaceholder(e.placeholder),typeof e.maxlength=="number"&&p.setMaxLength(e.maxlength),e.autofocus&&m.focus()},0),s.bus.on(o,{name:s.CTRL_Z,callback(){se.undo(m)}}),s.bus.on(o,{name:s.CTRL_SHIFT_Z,callback(){se.redo(m)}}),s.bus.on(o,{name:s.REPLACE,callback(h,b={}){var T;const{text:C,options:N}=qt(h,n.value,b);(T=n.value)==null||T.replaceSelectedText(C,N,o)}})}),t.watch(a,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:g.reconfigure(a.value==="light"?mt:nt)})},{deep:!0}),t.watch(()=>e.completions,()=>{var m;(m=n.value)==null||m.view.dispatch({effects:u.reconfigure(gt(e.completions))})},{deep:!0}),t.watch(()=>e.modelValue,()=>{var m,p;((m=n.value)==null?void 0:m.getValue())!==e.modelValue&&((p=n.value)==null||p.setValue(e.modelValue))}),t.watch(()=>e.placeholder,()=>{var m;(m=n.value)==null||m.setPlaceholder(e.placeholder)}),t.watch(()=>e.disabled,()=>{var m;(m=n.value)==null||m.setDisabled(e.disabled)}),t.watch(()=>e.readonly,()=>{var m;(m=n.value)==null||m.setDisabled(e.readonly)}),t.watch(()=>e.maxlength,()=>{var m;e.maxlength&&((m=n.value)==null||m.setMaxLength(e.maxlength))}),ho(n),{inputWrapperRef:i,codeMirrorUt:n}},ko=Co,xo=t.defineComponent({name:"MDEditorContent",props:P.contentProps,setup(e){const l=t.inject("editorId"),o=t.ref(""),{inputWrapperRef:a,codeMirrorUt:i}=ko(e);return Bt(e,o,i),()=>t.createVNode("div",{class:`${r.prefix}-content`},[t.createVNode("div",{class:`${r.prefix}-input-wrapper`,ref:a},null),t.createVNode(P.ContentPreview,{modelValue:e.modelValue,setting:e.setting,onHtmlChanged:n=>{o.value=n,e.onHtmlChanged(n)},onGetCatalog:e.onGetCatalog,mdHeadingId:e.mdHeadingId,noMermaid:e.noMermaid,sanitize:e.sanitize,noKatex:e.noKatex,formatCopiedText:e.formatCopiedText,noHighlight:e.noHighlight,noImgZoomIn:e.noImgZoomIn},null),e.catalogVisible&&t.createVNode(bt,{theme:e.theme,class:`${r.prefix}-catalog-editor`,editorId:l,mdHeadingId:e.mdHeadingId,key:"internal-catalog"},null)])}}),$o=t.defineComponent({props:{modelValue:{type:String,default:""}},setup(e){const l=t.inject("usedLanguageText");return()=>{var o,a;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`},[`${(o=l.value.footer)==null?void 0:o.markdownTotal}:`]),t.createVNode("span",null,[((a=e.modelValue)==null?void 0:a.length)||0])])}}}),No={checked:{type:Boolean,default:!1},onChange:{type:Function,default:()=>{}}},Vo=t.defineComponent({props:No,setup(e){return()=>t.createVNode("div",{class:[`${r.prefix}-checkbox`,e.checked&&`${r.prefix}-checkbox-checked`],onClick:()=>{e.onChange(!e.checked)}},null)}}),To={scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}}},yo=t.defineComponent({props:To,setup(e){const l=t.inject("usedLanguageText");return()=>{var o;return t.createVNode("div",{class:`${r.prefix}-footer-item`},[t.createVNode("label",{class:`${r.prefix}-footer-label`,onClick:()=>{e.onScrollAutoChange(!e.scrollAuto)}},[(o=l.value.footer)==null?void 0:o.scrollAuto]),t.createVNode(Vo,{checked:e.scrollAuto,onChange:e.onScrollAutoChange},null)])}}}),wo={modelValue:{type:String,default:""},footers:{type:Array,default:[]},scrollAuto:{type:Boolean},onScrollAutoChange:{type:Function,default:()=>{}},defFooters:{type:Object}},Eo=t.defineComponent({name:"MDEditorFooter",props:wo,setup(e){const l=t.computed(()=>{const a=e.footers.indexOf("="),i=a===-1?e.footers:e.footers.slice(0,a),n=a===-1?[]:e.footers.slice(a,Number.MAX_SAFE_INTEGER);return[i,n]}),o=a=>{if(r.allFooter.includes(a))switch(a){case"markdownTotal":return t.createVNode($o,{modelValue:e.modelValue},null);case"scrollSwitch":return t.createVNode(yo,{scrollAuto:e.scrollAuto,onScrollAutoChange:e.onScrollAutoChange},null)}else return e.defFooters instanceof Array?e.defFooters[a]||"":e.defFooters&&e.defFooters.children instanceof Array&&e.defFooters.children[a]||""};return()=>{const a=l.value[0].map(n=>o(n)),i=l.value[1].map(n=>o(n));return t.createVNode("div",{class:`${r.prefix}-footer`},[t.createVNode("div",{class:`${r.prefix}-footer-left`},[a]),t.createVNode("div",{class:`${r.prefix}-footer-right`},[i])])}}}),So=t.defineComponent({name:"MdEditorV3",props:P.editorProps,emits:P.editorEmits,setup(e,l){const{editorId:o,noKatex:a,noMermaid:i,noPrettier:n,noUploadImg:f,noHighlight:g}=e,u=t.reactive({scrollAuto:e.scrollAuto});P.useOnSave(e,l),P.useProvide(e),P.useExpansion(e),P.useErrorCatcher(e,l);const[d,v]=P.useConfig(e,l),V=P.useCatalog(e);return t.onBeforeUnmount(()=>{s.bus.clear(o)}),P.useExpose(e,l,V,d,v),()=>{var p;const $=et.getSlot({props:e,ctx:l},"defToolbars"),m=et.getSlot({props:e,ctx:l},"defFooters");return t.createVNode("div",{id:o,class:[r.prefix,e.class,e.theme==="dark"&&`${r.prefix}-dark`,d.fullscreen||d.pageFullscreen?`${r.prefix}-fullscreen`:""],style:e.style},[t.createVNode(Ht,{noPrettier:n,toolbars:e.toolbars,toolbarsExclude:e.toolbarsExclude,setting:d,updateSetting:v,tableShape:e.tableShape,defToolbars:$,noUploadImg:f,showToolbarName:e.showToolbarName},null),t.createVNode(xo,{modelValue:e.modelValue,setting:d,mdHeadingId:e.mdHeadingId,noMermaid:i,noPrettier:n,sanitize:e.sanitize,placeholder:e.placeholder,noKatex:a,scrollAuto:u.scrollAuto,formatCopiedText:e.formatCopiedText,autofocus:e.autoFocus,disabled:e.disabled,readonly:e.readOnly,maxlength:e.maxLength,autoDetectCode:e.autoDetectCode,noHighlight:g,onChange:h=>{e.onChange?e.onChange(h):(l.emit("update:modelValue",h),l.emit("onChange",h))},onHtmlChanged:h=>{e.onHtmlChanged?e.onHtmlChanged(h):l.emit("onHtmlChanged",h)},onGetCatalog:h=>{e.onGetCatalog?e.onGetCatalog(h):l.emit("onGetCatalog",h)},onBlur:h=>{e.onBlur?e.onBlur(h):l.emit("onBlur",h)},onFocus:h=>{e.onFocus?e.onFocus(h):l.emit("onFocus",h)},onInput:h=>{e.onInput?e.onInput(h):l.emit("onInput",h)},completions:e.completions,catalogVisible:V.value,theme:e.theme,noImgZoomIn:e.noImgZoomIn,onDrop:h=>{e.onDrop?e.onDrop(h):l.emit("onDrop",h)}},null),((p=e.footers)==null?void 0:p.length)>0&&t.createVNode(Eo,{modelValue:e.modelValue,footers:e.footers,defFooters:m,scrollAuto:u.scrollAuto,onScrollAutoChange:h=>u.scrollAuto=h},null)])}}}),de=So;de.install=e=>(e.component(de.name,de),e.use($t).use(z.DropdownToolbar).use(Nt).use(bt).use(P.MdPreview),e);module.exports=de;
@@ -523,32 +523,32 @@ const Sl = /* @__PURE__ */ P({
523
523
  u.title = !1;
524
524
  }
525
525
  }, [t("li", {
526
- class: `${n}-menu-item`,
526
+ class: `${n}-menu-item ${n}-menu-item-title`,
527
527
  onClick: () => {
528
528
  c("h1");
529
529
  }
530
530
  }, [(L = l.value.titleItem) == null ? void 0 : L.h1]), t("li", {
531
- class: `${n}-menu-item`,
531
+ class: `${n}-menu-item ${n}-menu-item-title`,
532
532
  onClick: () => {
533
533
  c("h2");
534
534
  }
535
535
  }, [(_ = l.value.titleItem) == null ? void 0 : _.h2]), t("li", {
536
- class: `${n}-menu-item`,
536
+ class: `${n}-menu-item ${n}-menu-item-title`,
537
537
  onClick: () => {
538
538
  c("h3");
539
539
  }
540
540
  }, [(U = l.value.titleItem) == null ? void 0 : U.h3]), t("li", {
541
- class: `${n}-menu-item`,
541
+ class: `${n}-menu-item ${n}-menu-item-title`,
542
542
  onClick: () => {
543
543
  c("h4");
544
544
  }
545
545
  }, [(O = l.value.titleItem) == null ? void 0 : O.h4]), t("li", {
546
- class: `${n}-menu-item`,
546
+ class: `${n}-menu-item ${n}-menu-item-title`,
547
547
  onClick: () => {
548
548
  c("h5");
549
549
  }
550
550
  }, [(H = l.value.titleItem) == null ? void 0 : H.h5]), t("li", {
551
- class: `${n}-menu-item`,
551
+ class: `${n}-menu-item ${n}-menu-item-title`,
552
552
  onClick: () => {
553
553
  c("h6");
554
554
  }
@@ -697,17 +697,17 @@ const Sl = /* @__PURE__ */ P({
697
697
  u.title = !1;
698
698
  }
699
699
  }, [t("li", {
700
- class: `${n}-menu-item`,
700
+ class: `${n}-menu-item ${n}-menu-item-image`,
701
701
  onClick: () => {
702
702
  v.type = "image", v.linkVisible = !0;
703
703
  }
704
704
  }, [(He = l.value.imgTitleItem) == null ? void 0 : He.link]), t("li", {
705
- class: `${n}-menu-item`,
705
+ class: `${n}-menu-item ${n}-menu-item-image`,
706
706
  onClick: () => {
707
707
  d.value.click();
708
708
  }
709
709
  }, [(Ne = l.value.imgTitleItem) == null ? void 0 : Ne.upload]), t("li", {
710
- class: `${n}-menu-item`,
710
+ class: `${n}-menu-item ${n}-menu-item-image`,
711
711
  onClick: () => {
712
712
  v.clipVisible = !0;
713
713
  }
@@ -886,42 +886,42 @@ const Sl = /* @__PURE__ */ P({
886
886
  u.mermaid = !1;
887
887
  }
888
888
  }, [t("li", {
889
- class: `${n}-menu-item`,
889
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
890
890
  onClick: () => {
891
891
  c("flow");
892
892
  }
893
893
  }, [(lt = l.value.mermaid) == null ? void 0 : lt.flow]), t("li", {
894
- class: `${n}-menu-item`,
894
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
895
895
  onClick: () => {
896
896
  c("sequence");
897
897
  }
898
898
  }, [(ot = l.value.mermaid) == null ? void 0 : ot.sequence]), t("li", {
899
- class: `${n}-menu-item`,
899
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
900
900
  onClick: () => {
901
901
  c("gantt");
902
902
  }
903
903
  }, [(at = l.value.mermaid) == null ? void 0 : at.gantt]), t("li", {
904
- class: `${n}-menu-item`,
904
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
905
905
  onClick: () => {
906
906
  c("class");
907
907
  }
908
908
  }, [(nt = l.value.mermaid) == null ? void 0 : nt.class]), t("li", {
909
- class: `${n}-menu-item`,
909
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
910
910
  onClick: () => {
911
911
  c("state");
912
912
  }
913
913
  }, [(rt = l.value.mermaid) == null ? void 0 : rt.state]), t("li", {
914
- class: `${n}-menu-item`,
914
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
915
915
  onClick: () => {
916
916
  c("pie");
917
917
  }
918
918
  }, [(it = l.value.mermaid) == null ? void 0 : it.pie]), t("li", {
919
- class: `${n}-menu-item`,
919
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
920
920
  onClick: () => {
921
921
  c("relationship");
922
922
  }
923
923
  }, [(st = l.value.mermaid) == null ? void 0 : st.relationship]), t("li", {
924
- class: `${n}-menu-item`,
924
+ class: `${n}-menu-item ${n}-menu-item-mermaid`,
925
925
  onClick: () => {
926
926
  c("journey");
927
927
  }
@@ -953,12 +953,12 @@ const Sl = /* @__PURE__ */ P({
953
953
  u.katex = !1;
954
954
  }
955
955
  }, [t("li", {
956
- class: `${n}-menu-item`,
956
+ class: `${n}-menu-item ${n}-menu-item-katex`,
957
957
  onClick: () => {
958
958
  c("katexInline");
959
959
  }
960
960
  }, [(ut = l.value.katex) == null ? void 0 : ut.inline]), t("li", {
961
- class: `${n}-menu-item`,
961
+ class: `${n}-menu-item ${n}-menu-item-katex`,
962
962
  onClick: () => {
963
963
  c("katexBlock");
964
964
  }