md-editor-v3 4.12.0 → 4.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/lib/cjs/DropdownToolbar.cjs +3 -1
  2. package/lib/cjs/MdCatalog.cjs +270 -1
  3. package/lib/cjs/MdEditor.cjs +3101 -58
  4. package/lib/cjs/MdModal.cjs +3 -1
  5. package/lib/cjs/MdPreview.cjs +3 -1
  6. package/lib/cjs/ModalToolbar.cjs +124 -1
  7. package/lib/cjs/NormalToolbar.cjs +61 -1
  8. package/lib/cjs/chunks/config.cjs +290 -1
  9. package/lib/cjs/chunks/dom.cjs +64 -1
  10. package/lib/cjs/chunks/index.cjs +1863 -8
  11. package/lib/cjs/chunks/index2.cjs +198 -1
  12. package/lib/cjs/chunks/index3.cjs +270 -1
  13. package/lib/cjs/chunks/index4.cjs +141 -2
  14. package/lib/cjs/chunks/vue-tsx.cjs +10 -1
  15. package/lib/cjs/config.cjs +12 -1
  16. package/lib/cjs/index.cjs +25 -1
  17. package/lib/es/DropdownToolbar.mjs +2 -2
  18. package/lib/es/MdCatalog.mjs +164 -114
  19. package/lib/es/MdEditor.mjs +2292 -1677
  20. package/lib/es/MdModal.mjs +2 -2
  21. package/lib/es/MdPreview.mjs +2 -2
  22. package/lib/es/ModalToolbar.mjs +55 -38
  23. package/lib/es/NormalToolbar.mjs +26 -18
  24. package/lib/es/chunks/config.mjs +73 -54
  25. package/lib/es/chunks/dom.mjs +57 -24
  26. package/lib/es/chunks/index.mjs +1093 -611
  27. package/lib/es/chunks/index2.mjs +126 -78
  28. package/lib/es/chunks/index3.mjs +185 -111
  29. package/lib/es/chunks/index4.mjs +124 -73
  30. package/lib/es/chunks/vue-tsx.mjs +8 -8
  31. package/lib/es/config.mjs +11 -10
  32. package/lib/es/index.mjs +23 -23
  33. package/lib/preview.css +200 -1
  34. package/lib/style.css +592 -1
  35. package/lib/types/DropdownToolbar/DropdownToolbar.d.ts +1 -1
  36. package/lib/types/DropdownToolbar/index.d.ts +39 -61
  37. package/lib/types/MdCatalog/CatalogLink.d.ts +1 -1
  38. package/lib/types/MdCatalog/MdCatalog.d.ts +1 -1
  39. package/lib/types/MdCatalog/index.d.ts +47 -60
  40. package/lib/types/MdEditor/Editor.d.ts +1 -1
  41. package/lib/types/MdEditor/components/Checkbox/index.d.ts +1 -1
  42. package/lib/types/MdEditor/components/Divider/index.d.ts +1 -1
  43. package/lib/types/MdEditor/components/Dropdown/index.d.ts +1 -1
  44. package/lib/types/MdEditor/components/Icon/Icon.d.ts +1 -1
  45. package/lib/types/MdEditor/components/Icon/index.d.ts +1 -1
  46. package/lib/types/MdEditor/components/Modal/Modal.d.ts +2 -2
  47. package/lib/types/MdEditor/components/Modal/index.d.ts +59 -63
  48. package/lib/types/MdEditor/components/Popper/index.d.ts +1 -1
  49. package/lib/types/MdEditor/index.d.ts +238 -104
  50. package/lib/types/MdEditor/layouts/Content/ContentPreview.d.ts +1 -1
  51. package/lib/types/MdEditor/layouts/Content/index.d.ts +1 -1
  52. package/lib/types/MdEditor/layouts/Footer/MarkdownTotal.d.ts +1 -1
  53. package/lib/types/MdEditor/layouts/Footer/ScrollAuto.d.ts +1 -1
  54. package/lib/types/MdEditor/layouts/Footer/index.d.ts +1 -1
  55. package/lib/types/MdEditor/layouts/Modals/Clip.d.ts +1 -1
  56. package/lib/types/MdEditor/layouts/Modals/Link.d.ts +1 -1
  57. package/lib/types/MdEditor/layouts/Modals/index.d.ts +1 -1
  58. package/lib/types/MdEditor/layouts/Toolbar/TableShape.d.ts +1 -1
  59. package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +1 -1
  60. package/lib/types/MdEditor/utils/vue-tsx.d.ts +1 -1
  61. package/lib/types/MdPreview/MdPreview.d.ts +1 -1
  62. package/lib/types/MdPreview/index.d.ts +119 -73
  63. package/lib/types/ModalToolbar/ModalToolbar.d.ts +1 -1
  64. package/lib/types/ModalToolbar/index.d.ts +64 -66
  65. package/lib/types/NormalToolbar/NormalToolbar.d.ts +1 -1
  66. package/lib/types/NormalToolbar/index.d.ts +30 -58
  67. package/lib/umd/index.js +42 -42
  68. package/package.json +4 -4
@@ -1,8 +1,1863 @@
1
- "use strict";const c=require("vue"),u=require("./config.cjs"),d=require("./index4.cjs"),x=require("./dom.cjs"),D=require("medium-zoom"),_=require("@vavt/util"),j=require("copy-to-clipboard"),G=require("markdown-it"),V=require("markdown-it-image-figures"),U=require("markdown-it-task-lists"),q=require("markdown-it-xss"),z=require("lru-cache"),W=(e,i)=>{const l=c.inject("editorId"),{noImgZoomIn:t}=e,n=_.debounce(()=>{const a=document.querySelectorAll(`#${l}-preview img`);a.length!==0&&D(a,{background:"#00000073"})});c.watch([i,c.toRef(e.setting,"preview")],()=>{!t&&e.setting.preview&&n()},{immediate:!0})},K=(e,i)=>{if(typeof i[e]=="string")return i[e];const l=`<i class="${u.prefix}-iconfont ${u.prefix}-icon-${e}"></i>`;switch(u.configOption.iconfontType){case"svg":return`<svg class="${u.prefix}-icon" aria-hidden="true"><use xlink:href="#${u.prefix}-icon-${e}"></use></svg>`;default:return l}},Z=(e,i,l)=>{const t=c.inject("editorId"),n=c.inject("usedLanguageText"),a=c.inject("customIcon"),o=()=>{document.querySelectorAll(`#${t}-preview pre`).forEach(p=>{var b,h;let r=-1;(b=p.querySelector(".copy-button"))==null||b.remove();const f=((h=n.value.copyCode)==null?void 0:h.text)||"复制代码",w=document.createElement("span");w.setAttribute("class","copy-button"),w.dataset.tips=f,w.innerHTML=K("copy",a.value),w.addEventListener("click",()=>{var k,$;clearTimeout(r);const v=p.querySelector("code").innerText,g=j(e.formatCopiedText(v)),E=((k=n.value.copyCode)==null?void 0:k.successTips)||"已复制!",y=(($=n.value.copyCode)==null?void 0:$.failTips)||"已复制!";w.dataset.tips=g?E:y,r=window.setTimeout(()=>{w.dataset.tips=f},1500)}),p.appendChild(w)})},m=()=>{c.nextTick(o)},s=p=>{p&&c.nextTick(o)};c.watch([i,l],m),c.watch(()=>e.setting.preview,s),c.watch(()=>e.setting.htmlPreview,s),c.watch(()=>n.value,o),c.onMounted(o)},J=e=>{var a;const i=(a=u.configOption.editorExtensions)==null?void 0:a.highlight,l=i==null?void 0:i.instance,t=c.inject("highlight"),n=c.shallowRef(l);return c.onMounted(()=>{if(!e.noHighlight&&!n.value){const o=document.createElement("script");o.src=t.value.js,o.onload=()=>{n.value=window.hljs},o.id=`${u.prefix}-hljs`,x.appendHandler(o,"hljs");const m=document.createElement("link");m.rel="stylesheet",m.href=t.value.css,m.id=`${u.prefix}-hlCss`,x.appendHandler(m)}}),c.watch(()=>t.value.css,o=>{x.updateHandler(`${u.prefix}-hlCss`,"href",o)}),n},X=e=>{const i=c.inject("theme"),{editorExtensions:l,mermaidConfig:t}=u.configOption,n=l==null?void 0:l.mermaid,a=c.shallowRef(n==null?void 0:n.instance),o=c.shallowRef(-1),m=new z.LRUCache({max:1e3,ttl:6e5}),s=()=>{const r=a.value;!e.noMermaid&&r&&(r.initialize(t({startOnLoad:!1,theme:i.value==="dark"?"dark":"default"})),o.value=o.value+1)};return c.watch(()=>i.value,()=>{m.clear(),s()}),c.onMounted(()=>{if(!e.noMermaid&&!(n!=null&&n.instance)){const r=(n==null?void 0:n.js)||u.mermaidUrl;if(/\.mjs/.test(r))import(r).then(f=>{a.value=f.default,s()});else{const f=document.createElement("script");f.id=`${u.prefix}-mermaid`,f.src=r,f.onload=()=>{a.value=window.mermaid,s()},x.appendHandler(f,"mermaid")}}}),{mermaidRef:a,reRenderRef:o,replaceMermaid:()=>{c.nextTick(()=>{if(!e.noMermaid&&a.value){const r=document.querySelectorAll(`div.${u.prefix}-mermaid`),f=document.createElement("div");f.style.width=document.body.offsetWidth+"px",f.style.height=document.body.offsetHeight+"px",f.style.position="fixed",f.style.zIndex="-10000",f.style.top="-10000";let w=r.length;w>0&&document.body.appendChild(f),r.forEach(async b=>{let h=m.get(b.innerText);if(!h){const g=_.uuid(),E=a.value.renderAsync||a.value.render;let y="";try{y=await E(g,b.innerText,f)}catch{}h=await e.sanitizeMermaid(typeof y=="string"?y:y.svg),m.set(b.innerText,h)}const v=document.createElement("p");v.className=`${u.prefix}-mermaid`,v.setAttribute("data-processed",""),v.innerHTML=h,b.dataset.line!==void 0&&(v.dataset.line=b.dataset.line),b.replaceWith(v),--w===0&&f.remove()})}})}}},Q=e=>{var n;const i=(n=u.configOption.editorExtensions)==null?void 0:n.katex,l=i==null?void 0:i.instance,t=c.shallowRef(l);return c.onMounted(()=>{if(!e.noKatex&&!t.value){const a=document.createElement("script");a.src=(i==null?void 0:i.js)||u.katexUrl.js,a.onload=()=>{t.value=window.katex},a.id=`${u.prefix}-katex`;const o=document.createElement("link");o.rel="stylesheet",o.href=(i==null?void 0:i.css)||u.katexUrl.css,o.id=`${u.prefix}-katexCss`,x.appendHandler(a,"katex"),x.appendHandler(o)}}),t},Y=(e,i)=>{const l=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(t,n,a,o,m)=>{const s=t[n],p=s.content.trim();if(s.info==="mermaid"){let r;return t[n].map&&t[n].level===0&&(r=t[n].map[0],t[n].attrSet("data-line",String(r))),`<div class="${u.prefix}-mermaid" ${r!==void 0?"data-line="+r:""} data-mermaid-theme=${i.themeRef.value}>${p}</div>`}return l(t,n,a,o,m)}},ee=Y,M=(e,i)=>{let l=!0,t=!0;const n=e.posMax,a=i>0?e.src.charCodeAt(i-1):-1,o=i+1<=n?e.src.charCodeAt(i+1):-1;return(a===32||a===9||o>=48&&o<=57)&&(t=!1),(o===32||o===9)&&(l=!1),{can_open:l,can_close:t}},te=(e,i)=>{let l,t,n,a;if(e.src[e.pos]!=="$")return!1;if(n=M(e,e.pos),!n.can_open)return i||(e.pending+="$"),e.pos+=1,!0;const o=e.pos+1;for(l=o;(l=e.src.indexOf("$",l))!==-1;){for(a=l-1;e.src[a]==="\\";)a-=1;if((l-a)%2==1)break;l+=1}return l===-1?(i||(e.pending+="$"),e.pos=o,!0):l-o===0?(i||(e.pending+="$$"),e.pos=o+1,!0):(n=M(e,l),n.can_close?(i||(t=e.push("math_inline","math",0),t.markup="$",t.content=e.src.slice(o,l)),e.pos=l+1,!0):(i||(e.pending+="$"),e.pos=o,!0))},ne=(e,i,l,t)=>{let n,a,o,m,s=!1,p=e.bMarks[i]+e.tShift[i],r=e.eMarks[i];if(p+2>r||e.src.slice(p,p+2)!=="$$")return!1;if(p+=2,n=e.src.slice(p,r),t)return!0;for(n.trim().slice(-2)==="$$"&&(n=n.trim().slice(0,-2),s=!0),o=i;!s&&(o++,!(o>=l||(p=e.bMarks[o]+e.tShift[o],r=e.eMarks[o],p<r&&e.tShift[o]<e.blkIndent)));)e.src.slice(p,r).trim().slice(-2)==="$$"&&(m=e.src.slice(0,r).lastIndexOf("$$"),a=e.src.slice(p,m),s=!0);e.line=o+1;const f=e.push("math_block","math",0);return f.block=!0,f.content=(n&&n.trim()?n+`
2
- `:"")+e.getLines(i+1,o,e.tShift[i],!0)+(a&&a.trim()?a:""),f.map=[i,e.line],f.markup="$$",!0},oe=(e,i)=>{const l=n=>{if(i.katexRef.value){const a=i.katexRef.value.renderToString(n,{throwOnError:!1});return`<span class="${u.prefix}-katex-inline" data-processed>${a}</span>`}else return`<span class="${u.prefix}-katex-inline">${n}</span>`},t=(n,a)=>{if(i.katexRef.value){const o=i.katexRef.value.renderToString(n,{throwOnError:!1,displayMode:!0});return`<p class="${u.prefix}-katex-block" data-line=${a} data-processed>${o}</p>`}else return`<p class="${u.prefix}-katex-block" data-line=${a}>${n}</p>`};e.inline.ruler.after("escape","math_inline",te),e.block.ruler.after("blockquote","math_block",ne,{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.math_inline=(n,a)=>l(n[a].content),e.renderer.rules.math_block=(n,a)=>t(n[a].content,n[a].map[0])+`
3
- `},re=oe,ie=(e,i)=>{i=i||{};const l=3,t=i.marker||"!",n=t.charCodeAt(0),a=t.length;let o="",m="";const s=(r,f,w,b,h)=>{const v=r[f];return v.type==="admonition_open"?(r[f].attrPush(["class",`${u.prefix}-admonition ${u.prefix}-admonition-${v.info}`]),r[f].attrSet("data-line",String(r[f].map[0]))):v.type==="admonition_title_open"&&r[f].attrPush(["class",`${u.prefix}-admonition-title`]),h.renderToken(r,f,w)},p=r=>{const f=r.trim().split(" ",2);m="",o=f[0],f.length>1&&(m=r.substring(o.length+2)),(m===""||!m)&&(m=o)};e.block.ruler.before("code","admonition",(r,f,w,b)=>{let h,v,g,E=!1,y=r.bMarks[f]+r.tShift[f],k=r.eMarks[f];if(n!==r.src.charCodeAt(y))return!1;for(h=y+1;h<=k&&t[(h-y)%a]===r.src[h];h++);const $=Math.floor((h-y)/a);if($!==l)return!1;h-=(h-y)%a;const C=r.src.slice(y,h),I=r.src.slice(h,k);if(p(I),b)return!0;for(v=f;v++,!(v>=w||(y=r.bMarks[v]+r.tShift[v],k=r.eMarks[v],y<k&&r.sCount[v]<r.blkIndent));)if(n===r.src.charCodeAt(y)&&!(r.sCount[v]-r.blkIndent>=4)){for(h=y+1;h<=k&&t[(h-y)%a]===r.src[h];h++);if(!(Math.floor((h-y)/a)<$)&&(h-=(h-y)%a,h=r.skipSpaces(h),!(h<k))){E=!0;break}}const P=r.parentType,S=r.lineMax;return r.parentType="root",r.lineMax=v,g=r.push("admonition_open","div",1),g.markup=C,g.block=!0,g.info=o,g.map=[f,v],g=r.push("admonition_title_open","p",1),g.markup=C+" "+o,g.map=[f,v],g=r.push("inline","",0),g.content=m,g.map=[f,r.line-1],g.children=[],g=r.push("admonition_title_close","p",-1),g.markup=C+" "+o,r.md.block.tokenize(r,f+1,v),g=r.push("admonition_close","div",-1),g.markup=r.src.slice(y,h),g.block=!0,r.parentType=P,r.lineMax=S,r.line=v+(E?1:0),!0},{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.admonition_open=s,e.renderer.rules.admonition_title_open=s,e.renderer.rules.admonition_title_close=s,e.renderer.rules.admonition_close=s},le=ie,ae=(e,i)=>{e.renderer.rules.heading_open=(l,t)=>{var m;const n=l[t],a=((m=l[t+1].children)==null?void 0:m.reduce((s,p)=>s+(p.content||""),""))||"",o=n.markup.length;return i.headsRef.value.push({text:a,level:o}),n.map&&n.level===0&&(n.attrSet("data-line",String(n.map[0])),n.attrSet("id",i.mdHeadingId(a,o,i.headsRef.value.length))),e.renderer.renderToken(l,t,i)},e.renderer.rules.heading_close=(l,t,n,a,o)=>o.renderToken(l,t,n)},ce=ae,se=(e,i)=>{const l=e.renderer.rules.fence,t=e.utils.unescapeAll,n=/\[(\w*)(?::([\w ]*))?\]/;function a(p){return p.info?t(p.info).trim():""}function o(p){const r=a(p),[f=null,w=""]=(n.exec(r)||[]).slice(1);return[f,w]}function m(p){const r=a(p);return r?r.split(/(\s+)/g)[0]:""}const s=(p,r,f,w,b)=>{if(p[r].hidden)return"";const[h,v]=o(p[r]);if(h===null)return l(p,r,f,w,b);let g,E,y,k,$="",C="";for(let I=r;I<p.length&&(g=p[I],[E,y]=o(g),E===h);I++)g.info=g.info.replace(n,""),g.hidden=!0,k=I-r>0?"":" checked",$+=`<li><input type="radio" name="label-group-${i.editorId}-${r}"${k}><label for="group-${i.editorId}-${r}-tab-${I-r}" onclick="this.previousElementSibling.click()">${y||m(g)}</label></li>
4
- `,C+=`<input type="radio" id="group-${i.editorId}-${r}-tab-${I-r}" name="group-${i.editorId}-${r}"${k}>
5
- `+l(p,I,f,w,b);return`<div class="code-tabs">
6
- <ul>
7
- `+$+`</ul>
8
- `+C+"</div>"};e.renderer.rules.fence=s},ue=se,de=e=>{["paragraph_open","table_open","ordered_list_open","bullet_list_open","blockquote_open","hr","html_block","fence"].forEach(i=>{const l=e.renderer.rules[i];l?e.renderer.rules[i]=(t,n,a,o,m)=>{let s;const p=l(t,n,a,o,m);return t[n].map&&t[n].level===0&&!/^<!--/.test(p)?(s=t[n].map[0],p.replace(/^(<[^>]*)/,`$1 data-line="${s}"`)):p}:e.renderer.rules[i]=(t,n,a,o,m)=>{let s;return t[n].map&&t[n].level===0&&(s=t[n].map[0],t[n].attrSet("data-line",String(s))),m.renderToken(t,n,a)}})},pe=(e,i)=>{const{editorConfig:l,markdownItConfig:t,markdownItPlugins:n}=u.configOption,a=c.inject("editorId"),o=c.inject("showCodeRowNumber"),m=c.inject("theme"),s=c.ref([]),p=J(e),r=Q(e),{reRenderRef:f,replaceMermaid:w}=X(e),b=G({html:!0,breaks:!0});t(b,{editorId:a});const h=[{type:"katex",plugin:re,options:{katexRef:r}},{type:"image",plugin:V,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:le,options:{}},{type:"taskList",plugin:U,options:{}},{type:"heading",plugin:ce,options:{mdHeadingId:e.mdHeadingId,headsRef:s}},{type:"codeTabs",plugin:ue,options:{editorId:a}},{type:"xss",plugin:q,options:{xss(C){return{whiteList:Object.assign({},C.getDefaultWhiteList(),{input:["class","disabled","type","checked"],iframe:["class","width","height","src","title","border","frameborder","framespacing","allow","allowfullscreen"]})}}}}];e.noMermaid||h.push({type:"mermaid",plugin:ee,options:{themeRef:m}}),n(h,{editorId:a}).forEach(C=>{b.use(C.plugin,C.options)});const v=b.options.highlight;b.set({highlight:(C,I,P)=>{if(v){const T=v(C,I,P);if(T)return T}let S;!e.noHighlight&&p.value?p.value.getLanguage(I)?S=p.value.highlight(C,{language:I,ignoreIllegals:!0}).value:S=p.value.highlightAuto(C).value:S=b.utils.escapeHtml(C);const O=o?d.generateCodeRowNumber(S.replace(/^\n+|\n+$/g,"")):`<span class="code-block">${S.replace(/^\n+|\n+$/g,"")}</span>`;return`<pre><code class="language-${I}" language=${I}>${O}</code></pre>`}}),de(b);const g=c.ref(`_article-key_${_.uuid()}`),E=c.ref(e.sanitize(b.render(e.modelValue))),y=()=>{d.bus.emit(a,d.BUILD_FINISHED,E.value),e.onHtmlChanged(E.value),e.onGetCatalog(s.value),d.bus.emit(a,d.CATALOG_CHANGED,s.value),w()};c.onMounted(y);const k=()=>{s.value=[],E.value=e.sanitize(b.render(e.modelValue)),y()},$=c.computed(()=>(e.noKatex||r.value)&&(e.noHighlight||p.value));return c.watch([c.toRef(e,"modelValue"),$,f],_.debounce(k,(l==null?void 0:l.renderDelay)!==void 0?l==null?void 0:l.renderDelay:i?0:500)),c.onMounted(()=>{d.bus.on(a,{name:d.PUSH_CATALOG,callback(){d.bus.emit(a,d.CATALOG_CHANGED,s.value)}}),d.bus.on(a,{name:d.RERENDER,callback:()=>{k(),g.value=`_article-key_${_.uuid()}`}})}),{html:E,key:g}},me=pe,A={modelValue:{type:String,default:""},setting:{type:Object,default:()=>({preview:!0})},onHtmlChanged:{type:Function,default:()=>{}},onGetCatalog:{type:Function,default:()=>{}},mdHeadingId:{type:Function,default:()=>""},noMermaid:{type:Boolean,default:!1},sanitize:{type:Function,default:e=>e},noKatex:{type:Boolean,default:!1},formatCopiedText:{type:Function,default:e=>e},noHighlight:{type:Boolean,default:!1},previewOnly:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean},sanitizeMermaid:{type:Function}},fe={...A,updateModelValue:{type:Function,default:()=>{}},onChange:{type:Function,default:()=>{}},placeholder:{type:String,default:""},scrollAuto:{type:Boolean},autofocus:{type:Boolean},disabled:{type:Boolean},readonly:{type:Boolean},maxlength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function,default:()=>{}},onFocus:{type:Function,default:()=>{}},noPrettier:{type:Boolean},completions:{type:Array},catalogVisible:{type:Boolean},theme:{type:String,default:"light"},onInput:{type:Function},onDrop:{type:Function,default:()=>{}},inputBoxWitdh:{type:String},onInputBoxWitdhChange:{type:Function}},R=c.defineComponent({name:"ContentPreview",props:A,setup(e){const i=c.inject("editorId"),l=c.inject("previewTheme"),t=c.inject("showCodeRowNumber"),{html:n,key:a}=me(e,e.previewOnly);return Z(e,n,a),W(e,n),()=>c.createVNode(c.Fragment,null,[e.setting.preview&&c.createVNode("div",{id:`${i}-preview-wrapper`,class:`${u.prefix}-preview-wrapper`,key:"content-preview-wrapper"},[c.createVNode("div",{key:a.value,id:`${i}-preview`,class:[`${u.prefix}-preview`,`${l==null?void 0:l.value}-theme`,t&&`${u.prefix}-scrn`],innerHTML:n.value},null)]),!e.previewOnly&&e.setting.htmlPreview&&c.createVNode("div",{id:`${i}-html-wrapper`,class:`${u.prefix}-preview-wrapper`,key:"html-preview-wrapper"},[c.createVNode("div",{class:`${u.prefix}-html`},[n.value])])])}}),he=(e,i)=>{const{editorId:l}=e,t=c.reactive({buildFinished:!1,html:""});c.watch(()=>e.modelValue,()=>{t.buildFinished=!1}),c.onMounted(()=>{d.bus.on(l,{name:d.BUILD_FINISHED,callback(n){t.buildFinished=!0,t.html=n}}),d.bus.on(l,{name:d.ON_SAVE,callback(){const n=new Promise(a=>{if(t.buildFinished)a(t.html);else{const o=m=>{a(m),d.bus.remove(l,d.BUILD_FINISHED,o)};d.bus.on(l,{name:d.BUILD_FINISHED,callback:o})}});e.onSave?e.onSave(e.modelValue,n):i.emit("onSave",e.modelValue,n)}})})},F=e=>{var n,a;const{editorId:i}=e,l=(a=(n=u.configOption)==null?void 0:n.editorExtensions)==null?void 0:a.highlight;c.provide("editorId",i),c.provide("theme",c.computed(()=>e.theme)),c.provide("language",c.computed(()=>e.language)),c.provide("highlight",c.computed(()=>{const o={...u.codeCss,...l==null?void 0:l.css},m=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme;return{js:(l==null?void 0:l.js)||u.highlightUrl,css:o[e.codeTheme]?o[e.codeTheme][m]:u.codeCss.atom[m]}})),c.provide("showCodeRowNumber",e.showCodeRowNumber);const t=c.computed(()=>{var m,s;const o={...u.staticTextDefault,...(s=(m=u.configOption)==null?void 0:m.editorConfig)==null?void 0:s.languageUserDefined};return o[e.language]?o[e.language]:u.staticTextDefault["zh-CN"]});c.provide("usedLanguageText",t),c.provide("previewTheme",c.computed(()=>e.previewTheme)),c.provide("customIcon",c.computed(()=>e.customIcon))},ge=e=>{F(e),c.provide("tabWidth",e.tabWidth)},L=e=>{c.onMounted(()=>{var i,l;if(!e.noIconfont)if(u.configOption.iconfontType==="svg"){const t=document.createElement("script");t.src=((i=u.configOption.editorExtensions)==null?void 0:i.iconfont)||u.iconfontSvgUrl,t.id=`${u.prefix}-icon`,x.appendHandler(t)}else{const t=document.createElement("link");t.rel="stylesheet",t.href=((l=u.configOption.editorExtensions)==null?void 0:l.iconfontClass)||u.iconfontClassUrl,t.id=`${u.prefix}-icon-class`,x.appendHandler(t)}})},ve=e=>{var m,s,p,r,f,w;const{noPrettier:i,noUploadImg:l}=e,{editorExtensions:t}=u.configOption,n=i||!!((s=(m=u.configOption.editorExtensions)==null?void 0:m.prettier)!=null&&s.prettierInstance),a=i||!!((r=(p=u.configOption.editorExtensions)==null?void 0:p.prettier)!=null&&r.parserMarkdownInstance),o=l||!!((w=(f=u.configOption.editorExtensions)==null?void 0:f.cropper)!=null&&w.instance);c.onMounted(()=>{var E,y,k,$;const b=document.createElement("script"),h=document.createElement("script");b.src=((E=t==null?void 0:t.prettier)==null?void 0:E.standaloneJs)||u.prettierUrl.main,b.id=`${u.prefix}-prettier`,h.src=((y=t==null?void 0:t.prettier)==null?void 0:y.parserMarkdownJs)||u.prettierUrl.markdown,h.id=`${u.prefix}-prettierMD`;const v=document.createElement("link");v.rel="stylesheet",v.href=((k=t==null?void 0:t.cropper)==null?void 0:k.css)||u.cropperUrl.css,v.id=`${u.prefix}-cropperCss`;const g=document.createElement("script");g.src=(($=t==null?void 0:t.cropper)==null?void 0:$.js)||u.cropperUrl.js,g.id=`${u.prefix}-cropper`,o||(x.appendHandler(v),x.appendHandler(g)),n||x.appendHandler(b),a||x.appendHandler(h)}),L(e)},ye=(e,i)=>{const{editorId:l}=e;c.onMounted(()=>{d.bus.on(l,{name:d.ERROR_CATCHER,callback:t=>{e.onError instanceof Function?e.onError(t):i.emit("onError",t)}})})},be=(e,i)=>{const{editorId:l}=e,t=c.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview}),n=(m,s)=>{t[m]=s===void 0?!t[m]:s,m==="preview"&&t.preview?t.htmlPreview=!1:m==="htmlPreview"&&t.htmlPreview&&(t.preview=!1)};let a="";const o=()=>{t.pageFullscreen||t.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=a};return c.watch(()=>[t.pageFullscreen,t.fullscreen],o),c.onMounted(()=>{d.bus.on(l,{name:d.UPLOAD_IMAGE,callback(m,s){const p=r=>{d.bus.emit(l,d.REPLACE,"image",{desc:"",urls:r}),s&&s()};e.onUploadImg?e.onUploadImg(m,p):i.emit("onUploadImg",m,p)}}),a=document.body.style.overflow,o()}),[t,n]},we=e=>{const{editorId:i}=e,l=c.ref(!1);return c.onMounted(()=>{d.bus.on(i,{name:d.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?l.value=!l.value:l.value=n}})}),c.computed(()=>!e.toolbarsExclude.includes("catalog")&&e.toolbars.includes("catalog")&&l.value)},ke=(e,i,l,t,n,a)=>{const{editorId:o}=e;c.watch(()=>t.pageFullscreen,s=>{d.bus.emit(o,d.PAGE_FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.fullscreen,s=>{d.bus.emit(o,d.FULL_SCREEN_CHANGED,s)}),c.watch(()=>t.preview,s=>{d.bus.emit(o,d.PREVIEW_CHANGED,s)}),c.watch(()=>t.htmlPreview,s=>{d.bus.emit(o,d.HTML_PREVIEW_CHANGED,s)}),c.watch(l,s=>{d.bus.emit(o,d.CATALOG_VISIBLE_CHANGED,s)});const m={on(s,p){switch(s){case"pageFullscreen":{d.bus.on(o,{name:d.PAGE_FULL_SCREEN_CHANGED,callback(r){p(r)}});break}case"fullscreen":{d.bus.on(o,{name:d.FULL_SCREEN_CHANGED,callback(r){p(r)}});break}case"preview":{d.bus.on(o,{name:d.PREVIEW_CHANGED,callback(r){p(r)}});break}case"htmlPreview":{d.bus.on(o,{name:d.HTML_PREVIEW_CHANGED,callback(r){p(r)}});break}case"catalog":{d.bus.on(o,{name:d.CATALOG_VISIBLE_CHANGED,callback(r){p(r)}});break}}},togglePageFullscreen(s){n("pageFullscreen",s)},toggleFullscreen(s){d.bus.emit(o,d.CHANGE_FULL_SCREEN,s)},togglePreview(s){n("preview",s)},toggleHtmlPreview(s){n("htmlPreview",s)},toggleCatalog(s){d.bus.emit(o,d.CHANGE_CATALOG_VISIBLE,s)},triggerSave(){d.bus.emit(o,d.ON_SAVE)},insert(s){d.bus.emit(o,d.REPLACE,"universal",{generate:s})},focus(s){var p;(p=a.value)==null||p.focus(s)},rerender(){d.bus.emit(o,d.RERENDER)},getSelectedText(){var s;return(s=a.value)==null?void 0:s.getSelectedText()},resetHistory(){var s;(s=a.value)==null||s.resetHistory()},domEventHandlers(s){d.bus.emit(o,d.EVENT_LISTENER,s)}};i.expose(m)},Ee=e=>e,N={modelValue:{type:String,default:""},theme:{type:String,default:"light"},class:{type:String,default:""},language:{type:String,default:"zh-CN"},onHtmlChanged:{type:Function},onGetCatalog:{type:Function},editorId:{type:String,default:()=>d.getNextId("md-editor-v3_")},showCodeRowNumber:{type:Boolean,default:!1},previewTheme:{type:String,default:"default"},style:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:Ee},sanitize:{type:Function,default:e=>e},noMermaid:{type:Boolean,default:!1},noKatex:{type:Boolean,default:!1},codeTheme:{type:String,default:"atom"},noIconfont:{type:Boolean},formatCopiedText:{type:Function,default:e=>e},codeStyleReverse:{type:Boolean,default:!0},codeStyleReverseList:{type:Array,default:["default","mk-cute"]},noHighlight:{type:Boolean,default:!1},noImgZoomIn:{type:Boolean,default:!1},customIcon:{type:Object,default:{}},sanitizeMermaid:{type:Function,default:e=>Promise.resolve(e)}},Ce={...N,onChange:{type:Function},onSave:{type:Function},onUploadImg:{type:Function},pageFullscreen:{type:Boolean,default:!1},preview:{type:Boolean,default:!0},htmlPreview:{type:Boolean,default:!1},toolbars:{type:Array,default:u.allToolbar},toolbarsExclude:{type:Array,default:[]},noPrettier:{type:Boolean,default:!1},tabWidth:{type:Number,default:2},tableShape:{type:Array,default:()=>[6,4]},placeholder:{type:String,default:""},defToolbars:{type:[String,Object]},onError:{type:Function},footers:{type:Array,default:u.allFooter},scrollAuto:{type:Boolean,default:!0},defFooters:{type:[String,Object]},noUploadImg:{type:Boolean},autoFocus:{type:Boolean},disabled:{type:Boolean},readOnly:{type:Boolean},maxLength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function},onFocus:{type:Function},completions:{type:Array},showToolbarName:{type:Boolean,default:!1},onInput:{type:Function},onDrop:{type:Function},inputBoxWitdh:{type:String,default:"50%"},onInputBoxWitdhChange:{type:Function}},B=["onHtmlChanged","onGetCatalog"],Ie=[...B,"onChange","onSave","onUploadImg","onError","update:modelValue","onBlur","onFocus","onInput","onDrop","onInputBoxWitdhChange"],$e=(e,i)=>{const{editorId:l}=e,t={rerender(){d.bus.emit(l,d.RERENDER)}};i.expose(t)},H=c.defineComponent({name:"MdPreview",props:N,emits:B,setup(e,i){const{editorId:l,noKatex:t,noMermaid:n,noHighlight:a}=e;return F(e),L(e),$e(e,i),c.onBeforeUnmount(()=>{d.bus.clear(l)}),()=>c.createVNode("div",{id:l,class:[u.prefix,e.class,e.theme==="dark"&&`${u.prefix}-dark`,`${u.prefix}-previewOnly`],style:e.style},[c.createVNode(R,{modelValue:e.modelValue,onHtmlChanged:o=>{e.onHtmlChanged?e.onHtmlChanged(o):i.emit("onHtmlChanged",o)},onGetCatalog:o=>{e.onGetCatalog?e.onGetCatalog(o):i.emit("onGetCatalog",o)},mdHeadingId:e.mdHeadingId,noMermaid:n,sanitize:e.sanitize,noKatex:t,formatCopiedText:e.formatCopiedText,noHighlight:a,noImgZoomIn:e.noImgZoomIn,previewOnly:!0,sanitizeMermaid:e.sanitizeMermaid},null)])}});H.install=e=>(e.component(H.name,H),e);exports.ContentPreview=R;exports.MdPreview=H;exports.contentProps=fe;exports.editorEmits=Ie;exports.editorProps=Ce;exports.useCatalog=we;exports.useConfig=be;exports.useErrorCatcher=ye;exports.useExpansion=ve;exports.useExpose=ke;exports.useOnSave=he;exports.useProvide=ge;
1
+ "use strict";
2
+ const vue = require("vue");
3
+ const config = require("./config.cjs");
4
+ const index = require("./index4.cjs");
5
+ const dom = require("./dom.cjs");
6
+ const mediumZoom = require("medium-zoom");
7
+ const util = require("@vavt/util");
8
+ const copy = require("copy-to-clipboard");
9
+ const mdit = require("markdown-it");
10
+ const ImageFiguresPlugin = require("markdown-it-image-figures");
11
+ const TaskListPlugin = require("markdown-it-task-lists");
12
+ const XSSPlugin = require("markdown-it-xss");
13
+ const lruCache = require("lru-cache");
14
+ const userZoom = (props, html) => {
15
+ const editorId = vue.inject("editorId");
16
+ const { noImgZoomIn } = props;
17
+ let zoomHander = () => {
18
+ };
19
+ vue.watch(
20
+ [html, vue.toRef(props.setting, "preview")],
21
+ () => {
22
+ if (!noImgZoomIn && props.setting.preview) {
23
+ zoomHander();
24
+ }
25
+ },
26
+ {
27
+ immediate: true
28
+ }
29
+ );
30
+ vue.onMounted(() => {
31
+ zoomHander = util.debounce(() => {
32
+ const imgs = document.querySelectorAll(`#${editorId}-preview img`);
33
+ if (imgs.length === 0) {
34
+ return;
35
+ }
36
+ mediumZoom(imgs, {
37
+ background: "#00000073"
38
+ });
39
+ });
40
+ });
41
+ };
42
+ const StrIcon = (name, customIcon) => {
43
+ if (typeof customIcon[name] === "string") {
44
+ return customIcon[name];
45
+ }
46
+ const defaultStr = `<i class="${config.prefix}-iconfont ${config.prefix}-icon-${name}"></i>`;
47
+ switch (config.configOption.iconfontType) {
48
+ case "svg": {
49
+ return `<svg class="${config.prefix}-icon" aria-hidden="true"><use xlink:href="#${config.prefix}-icon-${name}"></use></svg>`;
50
+ }
51
+ default: {
52
+ return defaultStr;
53
+ }
54
+ }
55
+ };
56
+ const useCopyCode = (props, html, key) => {
57
+ const editorId = vue.inject("editorId");
58
+ const ult = vue.inject("usedLanguageText");
59
+ const customIcon = vue.inject("customIcon");
60
+ const initCopyEntry = () => {
61
+ document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
62
+ var _a, _b;
63
+ let clearTimer = -1;
64
+ (_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
65
+ const copyBtnText = ((_b = ult.value.copyCode) == null ? void 0 : _b.text) || "复制代码";
66
+ const copyButton = document.createElement("span");
67
+ copyButton.setAttribute("class", "copy-button");
68
+ copyButton.dataset.tips = copyBtnText;
69
+ copyButton.innerHTML = StrIcon("copy", customIcon.value);
70
+ copyButton.addEventListener("click", () => {
71
+ var _a2, _b2;
72
+ clearTimeout(clearTimer);
73
+ const codeText = pre.querySelector("code").innerText;
74
+ const success = copy(props.formatCopiedText(codeText));
75
+ const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "已复制!";
76
+ const failTip = ((_b2 = ult.value.copyCode) == null ? void 0 : _b2.failTips) || "已复制!";
77
+ copyButton.dataset.tips = success ? succssTip : failTip;
78
+ clearTimer = window.setTimeout(() => {
79
+ copyButton.dataset.tips = copyBtnText;
80
+ }, 1500);
81
+ });
82
+ pre.appendChild(copyButton);
83
+ });
84
+ };
85
+ const htmlChanged = () => {
86
+ vue.nextTick(initCopyEntry);
87
+ };
88
+ const settingPreviewChanged = (nVal) => {
89
+ if (nVal) {
90
+ vue.nextTick(initCopyEntry);
91
+ }
92
+ };
93
+ vue.watch([html, key], htmlChanged);
94
+ vue.watch(() => props.setting.preview, settingPreviewChanged);
95
+ vue.watch(() => props.setting.htmlPreview, settingPreviewChanged);
96
+ vue.watch(() => ult.value, initCopyEntry);
97
+ vue.onMounted(initCopyEntry);
98
+ };
99
+ const useHighlight = (props) => {
100
+ var _a;
101
+ const hljsConf = (_a = config.configOption.editorExtensions) == null ? void 0 : _a.highlight;
102
+ const hljs = hljsConf == null ? void 0 : hljsConf.instance;
103
+ const highlightUrl = vue.inject("highlight");
104
+ const hljsRef = vue.shallowRef(hljs);
105
+ vue.onMounted(() => {
106
+ if (props.noHighlight) {
107
+ return;
108
+ }
109
+ if (!hljsRef.value) {
110
+ const highlightScript = document.createElement("script");
111
+ highlightScript.src = highlightUrl.value.js;
112
+ highlightScript.onload = () => {
113
+ hljsRef.value = window.hljs;
114
+ };
115
+ highlightScript.id = `${config.prefix}-hljs`;
116
+ dom.appendHandler(highlightScript, "hljs");
117
+ const highlightLink = document.createElement("link");
118
+ highlightLink.rel = "stylesheet";
119
+ highlightLink.href = highlightUrl.value.css;
120
+ highlightLink.id = `${config.prefix}-hlCss`;
121
+ dom.appendHandler(highlightLink);
122
+ }
123
+ });
124
+ vue.watch(
125
+ () => highlightUrl.value.css,
126
+ (url) => {
127
+ dom.updateHandler(`${config.prefix}-hlCss`, "href", url);
128
+ }
129
+ );
130
+ return hljsRef;
131
+ };
132
+ const useMermaid = (props) => {
133
+ const theme = vue.inject("theme");
134
+ const { editorExtensions, mermaidConfig } = config.configOption;
135
+ const mermaidConf = editorExtensions == null ? void 0 : editorExtensions.mermaid;
136
+ const mermaidRef = vue.shallowRef(mermaidConf == null ? void 0 : mermaidConf.instance);
137
+ const reRenderRef = vue.shallowRef(-1);
138
+ const mermaidCache = new lruCache.LRUCache({
139
+ max: 1e3,
140
+ // 缓存10分钟
141
+ ttl: 6e5
142
+ });
143
+ const configMermaid = () => {
144
+ const mermaid = mermaidRef.value;
145
+ if (!props.noMermaid && mermaid) {
146
+ mermaid.initialize(
147
+ mermaidConfig({
148
+ startOnLoad: false,
149
+ theme: theme.value === "dark" ? "dark" : "default"
150
+ })
151
+ );
152
+ reRenderRef.value = reRenderRef.value + 1;
153
+ }
154
+ };
155
+ vue.watch(
156
+ () => theme.value,
157
+ () => {
158
+ mermaidCache.clear();
159
+ configMermaid();
160
+ }
161
+ );
162
+ vue.onMounted(() => {
163
+ if (props.noMermaid) {
164
+ return;
165
+ }
166
+ if (!(mermaidConf == null ? void 0 : mermaidConf.instance)) {
167
+ const jsSrc = (mermaidConf == null ? void 0 : mermaidConf.js) || config.mermaidUrl;
168
+ if (/\.mjs/.test(jsSrc)) {
169
+ import(
170
+ /* @vite-ignore */
171
+ /* webpackIgnore: true */
172
+ jsSrc
173
+ ).then((module2) => {
174
+ mermaidRef.value = module2.default;
175
+ configMermaid();
176
+ });
177
+ } else {
178
+ const mermaidScript = document.createElement("script");
179
+ mermaidScript.id = `${config.prefix}-mermaid`;
180
+ mermaidScript.src = jsSrc;
181
+ mermaidScript.onload = () => {
182
+ mermaidRef.value = window.mermaid;
183
+ configMermaid();
184
+ };
185
+ dom.appendHandler(mermaidScript, "mermaid");
186
+ }
187
+ }
188
+ });
189
+ const replaceMermaid = () => {
190
+ vue.nextTick(() => {
191
+ if (!props.noMermaid && mermaidRef.value) {
192
+ const mermaidSourceEles = document.querySelectorAll(
193
+ `div.${config.prefix}-mermaid`
194
+ );
195
+ const svgContainingElement = document.createElement("div");
196
+ svgContainingElement.style.width = document.body.offsetWidth + "px";
197
+ svgContainingElement.style.height = document.body.offsetHeight + "px";
198
+ svgContainingElement.style.position = "fixed";
199
+ svgContainingElement.style.zIndex = "-10000";
200
+ svgContainingElement.style.top = "-10000";
201
+ let count = mermaidSourceEles.length;
202
+ if (count > 0) {
203
+ document.body.appendChild(svgContainingElement);
204
+ }
205
+ mermaidSourceEles.forEach(async (item) => {
206
+ let mermaidHtml = mermaidCache.get(item.innerText);
207
+ if (!mermaidHtml) {
208
+ const idRand = util.uuid();
209
+ const render = mermaidRef.value.renderAsync || mermaidRef.value.render;
210
+ let svg = "";
211
+ try {
212
+ svg = await render(idRand, item.innerText, svgContainingElement);
213
+ } catch (error) {
214
+ }
215
+ mermaidHtml = await props.sanitizeMermaid(
216
+ typeof svg === "string" ? svg : svg.svg
217
+ );
218
+ mermaidCache.set(item.innerText, mermaidHtml);
219
+ }
220
+ const p = document.createElement("p");
221
+ p.className = `${config.prefix}-mermaid`;
222
+ p.setAttribute("data-processed", "");
223
+ p.innerHTML = mermaidHtml;
224
+ if (item.dataset.line !== void 0) {
225
+ p.dataset.line = item.dataset.line;
226
+ }
227
+ item.replaceWith(p);
228
+ if (--count === 0) {
229
+ svgContainingElement.remove();
230
+ }
231
+ });
232
+ }
233
+ });
234
+ };
235
+ return { mermaidRef, reRenderRef, replaceMermaid };
236
+ };
237
+ const useKatex = (props) => {
238
+ var _a;
239
+ const katexConf = (_a = config.configOption.editorExtensions) == null ? void 0 : _a.katex;
240
+ const katexIns = katexConf == null ? void 0 : katexConf.instance;
241
+ const katex = vue.shallowRef(katexIns);
242
+ vue.onMounted(() => {
243
+ if (!props.noKatex && !katex.value) {
244
+ const katexScript = document.createElement("script");
245
+ katexScript.src = (katexConf == null ? void 0 : katexConf.js) || config.katexUrl.js;
246
+ katexScript.onload = () => {
247
+ katex.value = window.katex;
248
+ };
249
+ katexScript.id = `${config.prefix}-katex`;
250
+ const katexLink = document.createElement("link");
251
+ katexLink.rel = "stylesheet";
252
+ katexLink.href = (katexConf == null ? void 0 : katexConf.css) || config.katexUrl.css;
253
+ katexLink.id = `${config.prefix}-katexCss`;
254
+ dom.appendHandler(katexScript, "katex");
255
+ dom.appendHandler(katexLink);
256
+ }
257
+ });
258
+ return katex;
259
+ };
260
+ const MermaidPlugin = (md, options) => {
261
+ const temp = md.renderer.rules.fence.bind(md.renderer.rules);
262
+ md.renderer.rules.fence = (tokens, idx, ops, env, slf) => {
263
+ const token = tokens[idx];
264
+ const code = token.content.trim();
265
+ if (token.info === "mermaid") {
266
+ let line;
267
+ if (tokens[idx].map && tokens[idx].level === 0) {
268
+ line = tokens[idx].map[0];
269
+ tokens[idx].attrSet("data-line", String(line));
270
+ }
271
+ return `<div class="${config.prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-mermaid-theme=${options.themeRef.value}>${code}</div>`;
272
+ }
273
+ return temp(tokens, idx, ops, env, slf);
274
+ };
275
+ };
276
+ const MermaidPlugin$1 = MermaidPlugin;
277
+ const isValidDelim = (state, pos) => {
278
+ let can_open = true, can_close = true;
279
+ const max = state.posMax;
280
+ const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
281
+ const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
282
+ if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
283
+ can_close = false;
284
+ }
285
+ if (nextChar === 32 || nextChar === 9) {
286
+ can_open = false;
287
+ }
288
+ return {
289
+ can_open,
290
+ can_close
291
+ };
292
+ };
293
+ const math_inline = (state, silent) => {
294
+ let match, token, res, pos;
295
+ if (state.src[state.pos] !== "$") {
296
+ return false;
297
+ }
298
+ res = isValidDelim(state, state.pos);
299
+ if (!res.can_open) {
300
+ if (!silent) {
301
+ state.pending += "$";
302
+ }
303
+ state.pos += 1;
304
+ return true;
305
+ }
306
+ const start = state.pos + 1;
307
+ match = start;
308
+ while ((match = state.src.indexOf("$", match)) !== -1) {
309
+ pos = match - 1;
310
+ while (state.src[pos] === "\\") {
311
+ pos -= 1;
312
+ }
313
+ if ((match - pos) % 2 == 1) {
314
+ break;
315
+ }
316
+ match += 1;
317
+ }
318
+ if (match === -1) {
319
+ if (!silent) {
320
+ state.pending += "$";
321
+ }
322
+ state.pos = start;
323
+ return true;
324
+ }
325
+ if (match - start === 0) {
326
+ if (!silent) {
327
+ state.pending += "$$";
328
+ }
329
+ state.pos = start + 1;
330
+ return true;
331
+ }
332
+ res = isValidDelim(state, match);
333
+ if (!res.can_close) {
334
+ if (!silent) {
335
+ state.pending += "$";
336
+ }
337
+ state.pos = start;
338
+ return true;
339
+ }
340
+ if (!silent) {
341
+ token = state.push("math_inline", "math", 0);
342
+ token.markup = "$";
343
+ token.content = state.src.slice(start, match);
344
+ }
345
+ state.pos = match + 1;
346
+ return true;
347
+ };
348
+ const math_block = (state, start, end, silent) => {
349
+ let firstLine, lastLine, next, lastPos, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start];
350
+ if (pos + 2 > max) {
351
+ return false;
352
+ }
353
+ if (state.src.slice(pos, pos + 2) !== "$$") {
354
+ return false;
355
+ }
356
+ pos += 2;
357
+ firstLine = state.src.slice(pos, max);
358
+ if (silent) {
359
+ return true;
360
+ }
361
+ if (firstLine.trim().slice(-2) === "$$") {
362
+ firstLine = firstLine.trim().slice(0, -2);
363
+ found = true;
364
+ }
365
+ for (next = start; !found; ) {
366
+ next++;
367
+ if (next >= end) {
368
+ break;
369
+ }
370
+ pos = state.bMarks[next] + state.tShift[next];
371
+ max = state.eMarks[next];
372
+ if (pos < max && state.tShift[next] < state.blkIndent) {
373
+ break;
374
+ }
375
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
376
+ lastPos = state.src.slice(0, max).lastIndexOf("$$");
377
+ lastLine = state.src.slice(pos, lastPos);
378
+ found = true;
379
+ }
380
+ }
381
+ state.line = next + 1;
382
+ const token = state.push("math_block", "math", 0);
383
+ token.block = true;
384
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
385
+ token.map = [start, state.line];
386
+ token.markup = "$$";
387
+ return true;
388
+ };
389
+ const KatexPlugin = (md, options) => {
390
+ const katexInline = (str) => {
391
+ if (options.katexRef.value) {
392
+ const html = options.katexRef.value.renderToString(str, {
393
+ throwOnError: false
394
+ });
395
+ return `<span class="${config.prefix}-katex-inline" data-processed>${html}</span>`;
396
+ } else {
397
+ return `<span class="${config.prefix}-katex-inline">${str}</span>`;
398
+ }
399
+ };
400
+ const katexBlock = (str, lineNum) => {
401
+ if (options.katexRef.value) {
402
+ const html = options.katexRef.value.renderToString(str, {
403
+ throwOnError: false,
404
+ displayMode: true
405
+ });
406
+ return `<p class="${config.prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
407
+ } else {
408
+ return `<p class="${config.prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
409
+ }
410
+ };
411
+ md.inline.ruler.after("escape", "math_inline", math_inline);
412
+ md.block.ruler.after("blockquote", "math_block", math_block, {
413
+ alt: ["paragraph", "reference", "blockquote", "list"]
414
+ });
415
+ md.renderer.rules.math_inline = (tokens, idx) => {
416
+ return katexInline(tokens[idx].content);
417
+ };
418
+ md.renderer.rules.math_block = (tokens, idx) => {
419
+ return katexBlock(tokens[idx].content, tokens[idx].map[0]) + "\n";
420
+ };
421
+ };
422
+ const KatexPlugin$1 = KatexPlugin;
423
+ const AdmonitionPlugin = (md, options) => {
424
+ options = options || {};
425
+ const markers = 3, markerStr = options.marker || "!", markerChar = markerStr.charCodeAt(0), markerLen = markerStr.length;
426
+ let type = "", title = "";
427
+ const render = (tokens, idx, _options, _env, self) => {
428
+ const token = tokens[idx];
429
+ if (token.type === "admonition_open") {
430
+ tokens[idx].attrPush([
431
+ "class",
432
+ `${config.prefix}-admonition ${config.prefix}-admonition-${token.info}`
433
+ ]);
434
+ tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
435
+ } else if (token.type === "admonition_title_open") {
436
+ tokens[idx].attrPush(["class", `${config.prefix}-admonition-title`]);
437
+ }
438
+ return self.renderToken(tokens, idx, _options);
439
+ };
440
+ const validate = (params) => {
441
+ const array = params.trim().split(" ", 2);
442
+ title = "";
443
+ type = array[0];
444
+ if (array.length > 1) {
445
+ title = params.substring(type.length + 2);
446
+ }
447
+ if (title === "" || !title) {
448
+ title = type;
449
+ }
450
+ };
451
+ md.block.ruler.before(
452
+ "code",
453
+ "admonition",
454
+ (state, startLine, endLine, silent) => {
455
+ let pos, nextLine, token, autoClosed = false, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
456
+ if (markerChar !== state.src.charCodeAt(start)) {
457
+ return false;
458
+ }
459
+ for (pos = start + 1; pos <= max; pos++) {
460
+ if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
461
+ break;
462
+ }
463
+ }
464
+ const markerCount = Math.floor((pos - start) / markerLen);
465
+ if (markerCount !== markers) {
466
+ return false;
467
+ }
468
+ pos -= (pos - start) % markerLen;
469
+ const markup = state.src.slice(start, pos);
470
+ const params = state.src.slice(pos, max);
471
+ validate(params);
472
+ if (silent) {
473
+ return true;
474
+ }
475
+ nextLine = startLine;
476
+ for (; ; ) {
477
+ nextLine++;
478
+ if (nextLine >= endLine) {
479
+ break;
480
+ }
481
+ start = state.bMarks[nextLine] + state.tShift[nextLine];
482
+ max = state.eMarks[nextLine];
483
+ if (start < max && state.sCount[nextLine] < state.blkIndent) {
484
+ break;
485
+ }
486
+ if (markerChar !== state.src.charCodeAt(start)) {
487
+ continue;
488
+ }
489
+ if (state.sCount[nextLine] - state.blkIndent >= 4) {
490
+ continue;
491
+ }
492
+ for (pos = start + 1; pos <= max; pos++) {
493
+ if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
494
+ break;
495
+ }
496
+ }
497
+ if (Math.floor((pos - start) / markerLen) < markerCount) {
498
+ continue;
499
+ }
500
+ pos -= (pos - start) % markerLen;
501
+ pos = state.skipSpaces(pos);
502
+ if (pos < max) {
503
+ continue;
504
+ }
505
+ autoClosed = true;
506
+ break;
507
+ }
508
+ const oldParent = state.parentType;
509
+ const oldLineMax = state.lineMax;
510
+ state.parentType = "root";
511
+ state.lineMax = nextLine;
512
+ token = state.push("admonition_open", "div", 1);
513
+ token.markup = markup;
514
+ token.block = true;
515
+ token.info = type;
516
+ token.map = [startLine, nextLine];
517
+ token = state.push("admonition_title_open", "p", 1);
518
+ token.markup = markup + " " + type;
519
+ token.map = [startLine, nextLine];
520
+ token = state.push("inline", "", 0);
521
+ token.content = title;
522
+ token.map = [startLine, state.line - 1];
523
+ token.children = [];
524
+ token = state.push("admonition_title_close", "p", -1);
525
+ token.markup = markup + " " + type;
526
+ state.md.block.tokenize(state, startLine + 1, nextLine);
527
+ token = state.push("admonition_close", "div", -1);
528
+ token.markup = state.src.slice(start, pos);
529
+ token.block = true;
530
+ state.parentType = oldParent;
531
+ state.lineMax = oldLineMax;
532
+ state.line = nextLine + (autoClosed ? 1 : 0);
533
+ return true;
534
+ },
535
+ {
536
+ alt: ["paragraph", "reference", "blockquote", "list"]
537
+ }
538
+ );
539
+ md.renderer.rules["admonition_open"] = render;
540
+ md.renderer.rules["admonition_title_open"] = render;
541
+ md.renderer.rules["admonition_title_close"] = render;
542
+ md.renderer.rules["admonition_close"] = render;
543
+ };
544
+ const AdmonitionPlugin$1 = AdmonitionPlugin;
545
+ const HeadingPlugin = (md, options) => {
546
+ md.renderer.rules.heading_open = (tokens, idx) => {
547
+ var _a;
548
+ const token = tokens[idx];
549
+ const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
550
+ return p + (c.content || "");
551
+ }, "")) || "";
552
+ const level = token.markup.length;
553
+ options.headsRef.value.push({
554
+ text,
555
+ level
556
+ });
557
+ if (token.map && token.level === 0) {
558
+ token.attrSet("data-line", String(token.map[0]));
559
+ token.attrSet(
560
+ "id",
561
+ options.mdHeadingId(text, level, options.headsRef.value.length)
562
+ );
563
+ }
564
+ return md.renderer.renderToken(tokens, idx, options);
565
+ };
566
+ md.renderer.rules.heading_close = (tokens, idx, opts, _env, self) => {
567
+ return self.renderToken(tokens, idx, opts);
568
+ };
569
+ };
570
+ const HeadingPlugin$1 = HeadingPlugin;
571
+ const codetabs = (md, _opts) => {
572
+ const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
573
+ function getInfo(token) {
574
+ return token.info ? unescapeAll(token.info).trim() : "";
575
+ }
576
+ function getGroupAndTab(token) {
577
+ const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
578
+ return [group, tab];
579
+ }
580
+ function getLangName(token) {
581
+ const info = getInfo(token);
582
+ return info ? info.split(/(\s+)/g)[0] : "";
583
+ }
584
+ const fenceGroup = (tokens, idx, options, env, slf) => {
585
+ if (tokens[idx].hidden) {
586
+ return "";
587
+ }
588
+ const [GROUP, _] = getGroupAndTab(tokens[idx]);
589
+ if (GROUP === null) {
590
+ return defaultRender(tokens, idx, options, env, slf);
591
+ }
592
+ let token, group, tab, checked, labels = "", pres = "";
593
+ for (let i = idx; i < tokens.length; i++) {
594
+ token = tokens[i];
595
+ [group, tab] = getGroupAndTab(token);
596
+ if (group !== GROUP) {
597
+ break;
598
+ }
599
+ token.info = token.info.replace(re, "");
600
+ token.hidden = true;
601
+ checked = i - idx > 0 ? "" : " checked";
602
+ labels += `<li><input type="radio" name="label-group-${_opts.editorId}-${idx}"${checked}><label for="group-${_opts.editorId}-${idx}-tab-${i - idx}" onclick="this.previousElementSibling.click()">${tab || getLangName(token)}</label></li>
603
+ `;
604
+ pres += `<input type="radio" id="group-${_opts.editorId}-${idx}-tab-${i - idx}" name="group-${_opts.editorId}-${idx}"${checked}>
605
+ ` + defaultRender(tokens, i, options, env, slf);
606
+ }
607
+ return '<div class="code-tabs">\n<ul>\n' + labels + "</ul>\n" + pres + "</div>";
608
+ };
609
+ md.renderer.rules.fence = fenceGroup;
610
+ };
611
+ const CodeTabsPlugin = codetabs;
612
+ const initLineNumber = (md) => {
613
+ [
614
+ "paragraph_open",
615
+ "table_open",
616
+ "ordered_list_open",
617
+ "bullet_list_open",
618
+ "blockquote_open",
619
+ "hr",
620
+ "html_block",
621
+ "fence"
622
+ ].forEach((rule) => {
623
+ const backup = md.renderer.rules[rule];
624
+ if (!backup) {
625
+ md.renderer.rules[rule] = (tokens, idx, options, _env, self) => {
626
+ let line;
627
+ if (tokens[idx].map && tokens[idx].level === 0) {
628
+ line = tokens[idx].map[0];
629
+ tokens[idx].attrSet("data-line", String(line));
630
+ }
631
+ return self.renderToken(tokens, idx, options);
632
+ };
633
+ } else {
634
+ md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
635
+ let line;
636
+ const _htmlCode = backup(tokens, idx, options, env, self);
637
+ if (tokens[idx].map && tokens[idx].level === 0 && !/^<!--/.test(_htmlCode)) {
638
+ line = tokens[idx].map[0];
639
+ return _htmlCode.replace(/^(<[^>]*)/, `$1 data-line="${line}"`);
640
+ }
641
+ return _htmlCode;
642
+ };
643
+ }
644
+ });
645
+ };
646
+ const useMarkdownIt = (props, previewOnly) => {
647
+ const { editorConfig, markdownItConfig, markdownItPlugins } = config.configOption;
648
+ const editorId = vue.inject("editorId");
649
+ const showCodeRowNumber = vue.inject("showCodeRowNumber");
650
+ const themeRef = vue.inject("theme");
651
+ const headsRef = vue.ref([]);
652
+ const hljsRef = useHighlight(props);
653
+ const katexRef = useKatex(props);
654
+ const { reRenderRef, replaceMermaid } = useMermaid(props);
655
+ const md = mdit({
656
+ html: true,
657
+ breaks: true
658
+ });
659
+ markdownItConfig(md, {
660
+ editorId
661
+ });
662
+ const plugins = [
663
+ {
664
+ type: "katex",
665
+ plugin: KatexPlugin$1,
666
+ options: { katexRef }
667
+ },
668
+ {
669
+ type: "image",
670
+ plugin: ImageFiguresPlugin,
671
+ options: { figcaption: true, classes: "md-zoom" }
672
+ },
673
+ {
674
+ type: "admonition",
675
+ plugin: AdmonitionPlugin$1,
676
+ options: {}
677
+ },
678
+ {
679
+ type: "taskList",
680
+ plugin: TaskListPlugin,
681
+ options: {}
682
+ },
683
+ {
684
+ type: "heading",
685
+ plugin: HeadingPlugin$1,
686
+ options: { mdHeadingId: props.mdHeadingId, headsRef }
687
+ },
688
+ {
689
+ type: "codeTabs",
690
+ plugin: CodeTabsPlugin,
691
+ options: { editorId }
692
+ },
693
+ {
694
+ type: "xss",
695
+ plugin: XSSPlugin,
696
+ options: {
697
+ // https://github.com/leizongmin/js-xss/blob/master/README.zh.md
698
+ xss(xss) {
699
+ return {
700
+ whiteList: Object.assign({}, xss.getDefaultWhiteList(), {
701
+ // 支持任务列表
702
+ input: ["class", "disabled", "type", "checked"],
703
+ // 主要支持youtobe、腾讯视频、哔哩哔哩等内嵌视频代码
704
+ iframe: [
705
+ "class",
706
+ "width",
707
+ "height",
708
+ "src",
709
+ "title",
710
+ "border",
711
+ "frameborder",
712
+ "framespacing",
713
+ "allow",
714
+ "allowfullscreen"
715
+ ]
716
+ })
717
+ };
718
+ }
719
+ }
720
+ }
721
+ ];
722
+ if (!props.noMermaid) {
723
+ plugins.push({
724
+ type: "mermaid",
725
+ plugin: MermaidPlugin$1,
726
+ options: { themeRef }
727
+ });
728
+ }
729
+ markdownItPlugins(plugins, {
730
+ editorId
731
+ }).forEach((item) => {
732
+ md.use(item.plugin, item.options);
733
+ });
734
+ const userDefHighlight = md.options.highlight;
735
+ md.set({
736
+ highlight: (str, language, attrs) => {
737
+ if (userDefHighlight) {
738
+ const result = userDefHighlight(str, language, attrs);
739
+ if (result) {
740
+ return result;
741
+ }
742
+ }
743
+ let codeHtml;
744
+ if (!props.noHighlight && hljsRef.value) {
745
+ const hljsLang = hljsRef.value.getLanguage(language);
746
+ if (hljsLang) {
747
+ codeHtml = hljsRef.value.highlight(str, {
748
+ language,
749
+ ignoreIllegals: true
750
+ }).value;
751
+ } else {
752
+ codeHtml = hljsRef.value.highlightAuto(str).value;
753
+ }
754
+ } else {
755
+ codeHtml = md.utils.escapeHtml(str);
756
+ }
757
+ const codeSpan = showCodeRowNumber ? index.generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
758
+ return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
759
+ }
760
+ });
761
+ initLineNumber(md);
762
+ const key = vue.ref(`_article-key_${util.uuid()}`);
763
+ const html = vue.ref(props.sanitize(md.render(props.modelValue)));
764
+ const updatedTodo = () => {
765
+ index.bus.emit(editorId, index.BUILD_FINISHED, html.value);
766
+ props.onHtmlChanged(html.value);
767
+ props.onGetCatalog(headsRef.value);
768
+ index.bus.emit(editorId, index.CATALOG_CHANGED, headsRef.value);
769
+ replaceMermaid();
770
+ };
771
+ vue.onMounted(updatedTodo);
772
+ const markHtml = () => {
773
+ headsRef.value = [];
774
+ html.value = props.sanitize(md.render(props.modelValue));
775
+ updatedTodo();
776
+ };
777
+ const needReRender = vue.computed(() => {
778
+ return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
779
+ });
780
+ vue.watch(
781
+ [vue.toRef(props, "modelValue"), needReRender, reRenderRef],
782
+ util.debounce(
783
+ markHtml,
784
+ (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500
785
+ )
786
+ );
787
+ vue.onMounted(() => {
788
+ index.bus.on(editorId, {
789
+ name: index.PUSH_CATALOG,
790
+ callback() {
791
+ index.bus.emit(editorId, index.CATALOG_CHANGED, headsRef.value);
792
+ }
793
+ });
794
+ index.bus.on(editorId, {
795
+ name: index.RERENDER,
796
+ callback: () => {
797
+ markHtml();
798
+ key.value = `_article-key_${util.uuid()}`;
799
+ }
800
+ });
801
+ });
802
+ return { html, key };
803
+ };
804
+ const useMarkdownIt$1 = useMarkdownIt;
805
+ const contentPreviewProps = {
806
+ modelValue: {
807
+ type: String,
808
+ default: ""
809
+ },
810
+ setting: {
811
+ type: Object,
812
+ default: () => ({ preview: true })
813
+ },
814
+ onHtmlChanged: {
815
+ type: Function,
816
+ default: () => {
817
+ }
818
+ },
819
+ onGetCatalog: {
820
+ type: Function,
821
+ default: () => {
822
+ }
823
+ },
824
+ mdHeadingId: {
825
+ type: Function,
826
+ default: () => ""
827
+ },
828
+ noMermaid: {
829
+ type: Boolean,
830
+ default: false
831
+ },
832
+ sanitize: {
833
+ type: Function,
834
+ default: (html) => html
835
+ },
836
+ // 不使用该函数功能
837
+ noKatex: {
838
+ type: Boolean,
839
+ default: false
840
+ },
841
+ formatCopiedText: {
842
+ type: Function,
843
+ default: (text) => text
844
+ },
845
+ noHighlight: {
846
+ type: Boolean,
847
+ default: false
848
+ },
849
+ previewOnly: {
850
+ type: Boolean,
851
+ default: false
852
+ },
853
+ noImgZoomIn: {
854
+ type: Boolean
855
+ },
856
+ sanitizeMermaid: {
857
+ type: Function
858
+ }
859
+ };
860
+ const contentProps = {
861
+ ...contentPreviewProps,
862
+ updateModelValue: {
863
+ type: Function,
864
+ default: () => {
865
+ }
866
+ },
867
+ onChange: {
868
+ type: Function,
869
+ default: () => {
870
+ }
871
+ },
872
+ placeholder: {
873
+ type: String,
874
+ default: ""
875
+ },
876
+ scrollAuto: {
877
+ type: Boolean
878
+ },
879
+ autofocus: {
880
+ type: Boolean
881
+ },
882
+ disabled: {
883
+ type: Boolean
884
+ },
885
+ readonly: {
886
+ type: Boolean
887
+ },
888
+ maxlength: {
889
+ type: Number
890
+ },
891
+ autoDetectCode: {
892
+ type: Boolean
893
+ },
894
+ /**
895
+ * 输入框失去焦点时触发事件
896
+ */
897
+ onBlur: {
898
+ type: Function,
899
+ default: () => {
900
+ }
901
+ },
902
+ /**
903
+ * 输入框获得焦点时触发事件
904
+ */
905
+ onFocus: {
906
+ type: Function,
907
+ default: () => {
908
+ }
909
+ },
910
+ noPrettier: {
911
+ type: Boolean
912
+ },
913
+ completions: {
914
+ type: Array
915
+ },
916
+ catalogVisible: {
917
+ type: Boolean
918
+ },
919
+ theme: {
920
+ type: String,
921
+ default: "light"
922
+ },
923
+ onInput: {
924
+ type: Function
925
+ },
926
+ onDrop: {
927
+ type: Function,
928
+ default: () => {
929
+ }
930
+ },
931
+ inputBoxWitdh: {
932
+ type: String
933
+ },
934
+ onInputBoxWitdhChange: {
935
+ type: Function
936
+ }
937
+ };
938
+ const ContentPreview = /* @__PURE__ */ vue.defineComponent({
939
+ name: "ContentPreview",
940
+ props: contentPreviewProps,
941
+ setup(props) {
942
+ const editorId = vue.inject("editorId");
943
+ const previewTheme = vue.inject("previewTheme");
944
+ const showCodeRowNumber = vue.inject("showCodeRowNumber");
945
+ const {
946
+ html,
947
+ key
948
+ } = useMarkdownIt$1(props, props.previewOnly);
949
+ useCopyCode(props, html, key);
950
+ userZoom(props, html);
951
+ return () => {
952
+ return vue.createVNode(vue.Fragment, null, [props.setting.preview && vue.createVNode("div", {
953
+ "id": `${editorId}-preview-wrapper`,
954
+ "class": `${config.prefix}-preview-wrapper`,
955
+ "key": "content-preview-wrapper"
956
+ }, [vue.createVNode("div", {
957
+ "key": key.value,
958
+ "id": `${editorId}-preview`,
959
+ "class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
960
+ "innerHTML": html.value
961
+ }, null)]), !props.previewOnly && props.setting.htmlPreview && vue.createVNode("div", {
962
+ "id": `${editorId}-html-wrapper`,
963
+ "class": `${config.prefix}-preview-wrapper`,
964
+ "key": "html-preview-wrapper"
965
+ }, [vue.createVNode("div", {
966
+ "class": `${config.prefix}-html`
967
+ }, [html.value])])]);
968
+ };
969
+ }
970
+ });
971
+ const useOnSave = (props, context) => {
972
+ const { editorId } = props;
973
+ const state = vue.reactive({
974
+ // 是否已编译成html
975
+ buildFinished: false,
976
+ // 存储当前最新的html
977
+ html: ""
978
+ });
979
+ vue.watch(
980
+ () => props.modelValue,
981
+ () => {
982
+ state.buildFinished = false;
983
+ }
984
+ );
985
+ vue.onMounted(() => {
986
+ index.bus.on(editorId, {
987
+ name: index.BUILD_FINISHED,
988
+ callback(html) {
989
+ state.buildFinished = true;
990
+ state.html = html;
991
+ }
992
+ });
993
+ index.bus.on(editorId, {
994
+ name: index.ON_SAVE,
995
+ callback() {
996
+ const htmlPromise = new Promise((rev) => {
997
+ if (state.buildFinished) {
998
+ rev(state.html);
999
+ } else {
1000
+ const buildFinishedCallback = (html) => {
1001
+ rev(html);
1002
+ index.bus.remove(editorId, index.BUILD_FINISHED, buildFinishedCallback);
1003
+ };
1004
+ index.bus.on(editorId, {
1005
+ name: index.BUILD_FINISHED,
1006
+ callback: buildFinishedCallback
1007
+ });
1008
+ }
1009
+ });
1010
+ if (props.onSave) {
1011
+ props.onSave(props.modelValue, htmlPromise);
1012
+ } else {
1013
+ context.emit("onSave", props.modelValue, htmlPromise);
1014
+ }
1015
+ }
1016
+ });
1017
+ });
1018
+ };
1019
+ const useProvidePreview = (props) => {
1020
+ var _a, _b;
1021
+ const { editorId } = props;
1022
+ const highlightConfig = (_b = (_a = config.configOption) == null ? void 0 : _a.editorExtensions) == null ? void 0 : _b.highlight;
1023
+ vue.provide("editorId", editorId);
1024
+ vue.provide(
1025
+ "theme",
1026
+ vue.computed(() => props.theme)
1027
+ );
1028
+ vue.provide(
1029
+ "language",
1030
+ vue.computed(() => props.language)
1031
+ );
1032
+ vue.provide(
1033
+ "highlight",
1034
+ vue.computed(() => {
1035
+ const cssList = {
1036
+ ...config.codeCss,
1037
+ ...highlightConfig == null ? void 0 : highlightConfig.css
1038
+ };
1039
+ const theme = props.codeStyleReverse && props.codeStyleReverseList.includes(props.previewTheme) ? "dark" : props.theme;
1040
+ return {
1041
+ js: (highlightConfig == null ? void 0 : highlightConfig.js) || config.highlightUrl,
1042
+ css: cssList[props.codeTheme] ? cssList[props.codeTheme][theme] : config.codeCss.atom[theme]
1043
+ };
1044
+ })
1045
+ );
1046
+ vue.provide("showCodeRowNumber", props.showCodeRowNumber);
1047
+ const usedLanguageText = vue.computed(() => {
1048
+ var _a2, _b2;
1049
+ const allText = {
1050
+ ...config.staticTextDefault,
1051
+ ...(_b2 = (_a2 = config.configOption) == null ? void 0 : _a2.editorConfig) == null ? void 0 : _b2.languageUserDefined
1052
+ };
1053
+ if (allText[props.language]) {
1054
+ return allText[props.language];
1055
+ } else {
1056
+ return config.staticTextDefault["zh-CN"];
1057
+ }
1058
+ });
1059
+ vue.provide("usedLanguageText", usedLanguageText);
1060
+ vue.provide(
1061
+ "previewTheme",
1062
+ vue.computed(() => props.previewTheme)
1063
+ );
1064
+ vue.provide(
1065
+ "customIcon",
1066
+ vue.computed(() => props.customIcon)
1067
+ );
1068
+ };
1069
+ const useProvide = (props) => {
1070
+ useProvidePreview(props);
1071
+ vue.provide("tabWidth", props.tabWidth);
1072
+ };
1073
+ const useExpansionPreview = (props) => {
1074
+ vue.onMounted(() => {
1075
+ var _a, _b;
1076
+ if (!props.noIconfont) {
1077
+ if (config.configOption.iconfontType === "svg") {
1078
+ const iconfontScript = document.createElement("script");
1079
+ iconfontScript.src = ((_a = config.configOption.editorExtensions) == null ? void 0 : _a.iconfont) || config.iconfontSvgUrl;
1080
+ iconfontScript.id = `${config.prefix}-icon`;
1081
+ dom.appendHandler(iconfontScript);
1082
+ } else {
1083
+ const iconfontLink = document.createElement("link");
1084
+ iconfontLink.rel = "stylesheet";
1085
+ iconfontLink.href = ((_b = config.configOption.editorExtensions) == null ? void 0 : _b.iconfontClass) || config.iconfontClassUrl;
1086
+ iconfontLink.id = `${config.prefix}-icon-class`;
1087
+ dom.appendHandler(iconfontLink);
1088
+ }
1089
+ }
1090
+ });
1091
+ };
1092
+ const useExpansion = (props) => {
1093
+ var _a, _b, _c, _d, _e, _f;
1094
+ const { noPrettier, noUploadImg } = props;
1095
+ const { editorExtensions } = config.configOption;
1096
+ const noPrettierScript = noPrettier || !!((_b = (_a = config.configOption.editorExtensions) == null ? void 0 : _a.prettier) == null ? void 0 : _b.prettierInstance);
1097
+ const noParserMarkdownScript = noPrettier || !!((_d = (_c = config.configOption.editorExtensions) == null ? void 0 : _c.prettier) == null ? void 0 : _d.parserMarkdownInstance);
1098
+ const noCropperScript = noUploadImg || !!((_f = (_e = config.configOption.editorExtensions) == null ? void 0 : _e.cropper) == null ? void 0 : _f.instance);
1099
+ vue.onMounted(() => {
1100
+ var _a2, _b2, _c2, _d2;
1101
+ const prettierScript = document.createElement("script");
1102
+ const prettierMDScript = document.createElement("script");
1103
+ prettierScript.src = ((_a2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _a2.standaloneJs) || config.prettierUrl.main;
1104
+ prettierScript.id = `${config.prefix}-prettier`;
1105
+ prettierMDScript.src = ((_b2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _b2.parserMarkdownJs) || config.prettierUrl.markdown;
1106
+ prettierMDScript.id = `${config.prefix}-prettierMD`;
1107
+ const cropperLink = document.createElement("link");
1108
+ cropperLink.rel = "stylesheet";
1109
+ cropperLink.href = ((_c2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _c2.css) || config.cropperUrl.css;
1110
+ cropperLink.id = `${config.prefix}-cropperCss`;
1111
+ const cropperScript = document.createElement("script");
1112
+ cropperScript.src = ((_d2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _d2.js) || config.cropperUrl.js;
1113
+ cropperScript.id = `${config.prefix}-cropper`;
1114
+ if (!noCropperScript) {
1115
+ dom.appendHandler(cropperLink);
1116
+ dom.appendHandler(cropperScript);
1117
+ }
1118
+ if (!noPrettierScript) {
1119
+ dom.appendHandler(prettierScript);
1120
+ }
1121
+ if (!noParserMarkdownScript) {
1122
+ dom.appendHandler(prettierMDScript);
1123
+ }
1124
+ });
1125
+ useExpansionPreview(props);
1126
+ };
1127
+ const useErrorCatcher = (props, context) => {
1128
+ const { editorId } = props;
1129
+ vue.onMounted(() => {
1130
+ index.bus.on(editorId, {
1131
+ name: index.ERROR_CATCHER,
1132
+ callback: (err) => {
1133
+ if (props.onError instanceof Function) {
1134
+ props.onError(err);
1135
+ } else {
1136
+ context.emit("onError", err);
1137
+ }
1138
+ }
1139
+ });
1140
+ });
1141
+ };
1142
+ const useConfig = (props, context) => {
1143
+ const { editorId } = props;
1144
+ const setting = vue.reactive({
1145
+ pageFullscreen: props.pageFullscreen,
1146
+ fullscreen: false,
1147
+ preview: props.preview,
1148
+ htmlPreview: props.preview ? false : props.htmlPreview
1149
+ });
1150
+ const updateSetting = (k, v) => {
1151
+ setting[k] = v === void 0 ? !setting[k] : v;
1152
+ if (k === "preview" && setting.preview) {
1153
+ setting.htmlPreview = false;
1154
+ } else if (k === "htmlPreview" && setting.htmlPreview) {
1155
+ setting.preview = false;
1156
+ }
1157
+ };
1158
+ let bodyOverflowHistory = "";
1159
+ const adjustBody = () => {
1160
+ if (setting.pageFullscreen || setting.fullscreen) {
1161
+ document.body.style.overflow = "hidden";
1162
+ } else {
1163
+ document.body.style.overflow = bodyOverflowHistory;
1164
+ }
1165
+ };
1166
+ vue.watch(() => [setting.pageFullscreen, setting.fullscreen], adjustBody);
1167
+ vue.onMounted(() => {
1168
+ index.bus.on(editorId, {
1169
+ name: index.UPLOAD_IMAGE,
1170
+ callback(files, cb) {
1171
+ const insertHanlder = (urls) => {
1172
+ index.bus.emit(editorId, index.REPLACE, "image", {
1173
+ desc: "",
1174
+ urls
1175
+ });
1176
+ cb && cb();
1177
+ };
1178
+ if (props.onUploadImg) {
1179
+ props.onUploadImg(files, insertHanlder);
1180
+ } else {
1181
+ context.emit("onUploadImg", files, insertHanlder);
1182
+ }
1183
+ }
1184
+ });
1185
+ bodyOverflowHistory = document.body.style.overflow;
1186
+ adjustBody();
1187
+ });
1188
+ return [setting, updateSetting];
1189
+ };
1190
+ const useCatalog = (props) => {
1191
+ const { editorId } = props;
1192
+ const catalogShow = vue.ref(false);
1193
+ vue.onMounted(() => {
1194
+ index.bus.on(editorId, {
1195
+ name: index.CHANGE_CATALOG_VISIBLE,
1196
+ callback: (v) => {
1197
+ if (v === void 0) {
1198
+ catalogShow.value = !catalogShow.value;
1199
+ } else {
1200
+ catalogShow.value = v;
1201
+ }
1202
+ }
1203
+ });
1204
+ });
1205
+ const catalogVisible = vue.computed(() => {
1206
+ return !props.toolbarsExclude.includes("catalog") && props.toolbars.includes("catalog") && catalogShow.value;
1207
+ });
1208
+ return catalogVisible;
1209
+ };
1210
+ const useExpose$1 = (props, ctx, catalogVisible, setting, updateSetting, codeRef) => {
1211
+ const { editorId } = props;
1212
+ vue.watch(
1213
+ () => setting.pageFullscreen,
1214
+ (newVal) => {
1215
+ index.bus.emit(editorId, index.PAGE_FULL_SCREEN_CHANGED, newVal);
1216
+ }
1217
+ );
1218
+ vue.watch(
1219
+ () => setting.fullscreen,
1220
+ (newVal) => {
1221
+ index.bus.emit(editorId, index.FULL_SCREEN_CHANGED, newVal);
1222
+ }
1223
+ );
1224
+ vue.watch(
1225
+ () => setting.preview,
1226
+ (newVal) => {
1227
+ index.bus.emit(editorId, index.PREVIEW_CHANGED, newVal);
1228
+ }
1229
+ );
1230
+ vue.watch(
1231
+ () => setting.htmlPreview,
1232
+ (newVal) => {
1233
+ index.bus.emit(editorId, index.HTML_PREVIEW_CHANGED, newVal);
1234
+ }
1235
+ );
1236
+ vue.watch(catalogVisible, (newVal) => {
1237
+ index.bus.emit(editorId, index.CATALOG_VISIBLE_CHANGED, newVal);
1238
+ });
1239
+ const exposeParam = {
1240
+ on(eventName, callBack) {
1241
+ switch (eventName) {
1242
+ case "pageFullscreen": {
1243
+ index.bus.on(editorId, {
1244
+ name: index.PAGE_FULL_SCREEN_CHANGED,
1245
+ callback(status) {
1246
+ callBack(status);
1247
+ }
1248
+ });
1249
+ break;
1250
+ }
1251
+ case "fullscreen": {
1252
+ index.bus.on(editorId, {
1253
+ name: index.FULL_SCREEN_CHANGED,
1254
+ callback(status) {
1255
+ callBack(status);
1256
+ }
1257
+ });
1258
+ break;
1259
+ }
1260
+ case "preview": {
1261
+ index.bus.on(editorId, {
1262
+ name: index.PREVIEW_CHANGED,
1263
+ callback(status) {
1264
+ callBack(status);
1265
+ }
1266
+ });
1267
+ break;
1268
+ }
1269
+ case "htmlPreview": {
1270
+ index.bus.on(editorId, {
1271
+ name: index.HTML_PREVIEW_CHANGED,
1272
+ callback(status) {
1273
+ callBack(status);
1274
+ }
1275
+ });
1276
+ break;
1277
+ }
1278
+ case "catalog": {
1279
+ index.bus.on(editorId, {
1280
+ name: index.CATALOG_VISIBLE_CHANGED,
1281
+ callback(status) {
1282
+ callBack(status);
1283
+ }
1284
+ });
1285
+ break;
1286
+ }
1287
+ }
1288
+ },
1289
+ togglePageFullscreen(status) {
1290
+ updateSetting("pageFullscreen", status);
1291
+ },
1292
+ toggleFullscreen(status) {
1293
+ index.bus.emit(editorId, index.CHANGE_FULL_SCREEN, status);
1294
+ },
1295
+ togglePreview(status) {
1296
+ updateSetting("preview", status);
1297
+ },
1298
+ toggleHtmlPreview(status) {
1299
+ updateSetting("htmlPreview", status);
1300
+ },
1301
+ toggleCatalog(status) {
1302
+ index.bus.emit(editorId, index.CHANGE_CATALOG_VISIBLE, status);
1303
+ },
1304
+ triggerSave() {
1305
+ index.bus.emit(editorId, index.ON_SAVE);
1306
+ },
1307
+ insert(generate) {
1308
+ index.bus.emit(editorId, index.REPLACE, "universal", { generate });
1309
+ },
1310
+ focus(options) {
1311
+ var _a;
1312
+ (_a = codeRef.value) == null ? void 0 : _a.focus(options);
1313
+ },
1314
+ rerender() {
1315
+ index.bus.emit(editorId, index.RERENDER);
1316
+ },
1317
+ getSelectedText() {
1318
+ var _a;
1319
+ return (_a = codeRef.value) == null ? void 0 : _a.getSelectedText();
1320
+ },
1321
+ resetHistory() {
1322
+ var _a;
1323
+ (_a = codeRef.value) == null ? void 0 : _a.resetHistory();
1324
+ },
1325
+ domEventHandlers(handlers) {
1326
+ index.bus.emit(editorId, index.EVENT_LISTENER, handlers);
1327
+ }
1328
+ };
1329
+ ctx.expose(exposeParam);
1330
+ };
1331
+ const mdHeadingId = (text) => text;
1332
+ const mdPreviewProps = {
1333
+ /**
1334
+ * markdown content.
1335
+ *
1336
+ * @default ''
1337
+ */
1338
+ modelValue: {
1339
+ type: String,
1340
+ default: ""
1341
+ },
1342
+ /**
1343
+ * 主题,支持light和dark
1344
+ *
1345
+ * @default 'light'
1346
+ */
1347
+ theme: {
1348
+ type: String,
1349
+ default: "light"
1350
+ },
1351
+ /**
1352
+ * 外层类名
1353
+ *
1354
+ * @default ''
1355
+ */
1356
+ class: {
1357
+ type: String,
1358
+ default: ""
1359
+ },
1360
+ /**
1361
+ * 预设语言名称
1362
+ *
1363
+ * @default 'zh-CN'
1364
+ */
1365
+ language: {
1366
+ type: String,
1367
+ default: "zh-CN"
1368
+ },
1369
+ /**
1370
+ * html变化事件
1371
+ */
1372
+ onHtmlChanged: {
1373
+ type: Function
1374
+ },
1375
+ /**
1376
+ * 获取目录结构
1377
+ */
1378
+ onGetCatalog: {
1379
+ type: Function
1380
+ },
1381
+ /**
1382
+ * 编辑器唯一标识
1383
+ *
1384
+ * @default 'md-editor-v3'
1385
+ */
1386
+ editorId: {
1387
+ type: String,
1388
+ default: () => index.getNextId("md-editor-v3_")
1389
+ },
1390
+ /**
1391
+ * 预览中代码是否显示行号
1392
+ *
1393
+ * @default false
1394
+ */
1395
+ showCodeRowNumber: {
1396
+ type: Boolean,
1397
+ default: false
1398
+ },
1399
+ /**
1400
+ * 预览内容样式
1401
+ *
1402
+ * @default 'default'
1403
+ */
1404
+ previewTheme: {
1405
+ type: String,
1406
+ default: "default"
1407
+ },
1408
+ /**
1409
+ * 编辑器样式
1410
+ */
1411
+ style: {
1412
+ type: Object,
1413
+ default: () => ({})
1414
+ },
1415
+ /**
1416
+ * 标题的id生成方式
1417
+ *
1418
+ * @default (text: string) => text
1419
+ */
1420
+ mdHeadingId: {
1421
+ type: Function,
1422
+ default: mdHeadingId
1423
+ },
1424
+ /**
1425
+ *
1426
+ * 不能保证文本正确的情况,在marked编译md文本后通过该方法处理
1427
+ * 推荐DOMPurify、sanitize-html
1428
+ *
1429
+ * @default (text: string) => text
1430
+ */
1431
+ sanitize: {
1432
+ type: Function,
1433
+ default: (html) => html
1434
+ },
1435
+ /**
1436
+ * 不使用该mermaid
1437
+ *
1438
+ * @default false
1439
+ */
1440
+ noMermaid: {
1441
+ type: Boolean,
1442
+ default: false
1443
+ },
1444
+ /**
1445
+ * 不使用katex
1446
+ *
1447
+ * @default false
1448
+ */
1449
+ noKatex: {
1450
+ type: Boolean,
1451
+ default: false
1452
+ },
1453
+ /**
1454
+ * 代码主题
1455
+ *
1456
+ * @default 'atom'
1457
+ */
1458
+ codeTheme: {
1459
+ type: String,
1460
+ default: "atom"
1461
+ },
1462
+ /**
1463
+ * 不插入iconfont链接
1464
+ *
1465
+ * @default false
1466
+ */
1467
+ noIconfont: {
1468
+ type: Boolean
1469
+ },
1470
+ /**
1471
+ * 复制代码格式化方法
1472
+ *
1473
+ * @default (text) => text
1474
+ */
1475
+ formatCopiedText: {
1476
+ type: Function,
1477
+ default: (text) => text
1478
+ },
1479
+ /**
1480
+ * 某些预览主题的代码模块背景是暗色系
1481
+ * 将这个属性设置为true,会自动在该主题下的light模式下使用暗色系的代码风格
1482
+ *
1483
+ * @default true
1484
+ */
1485
+ codeStyleReverse: {
1486
+ type: Boolean,
1487
+ default: true
1488
+ },
1489
+ /**
1490
+ * 需要自动调整的预览主题
1491
+ *
1492
+ * @default ['default', 'mk-cute']
1493
+ */
1494
+ codeStyleReverseList: {
1495
+ type: Array,
1496
+ default: ["default", "mk-cute"]
1497
+ },
1498
+ noHighlight: {
1499
+ type: Boolean,
1500
+ default: false
1501
+ },
1502
+ /**
1503
+ * 是否关闭编辑器默认的放大缩小功能
1504
+ */
1505
+ noImgZoomIn: {
1506
+ type: Boolean,
1507
+ default: false
1508
+ },
1509
+ /**
1510
+ * 自定义的图标
1511
+ */
1512
+ customIcon: {
1513
+ type: Object,
1514
+ default: {}
1515
+ },
1516
+ sanitizeMermaid: {
1517
+ type: Function,
1518
+ default: (h) => Promise.resolve(h)
1519
+ }
1520
+ };
1521
+ const editorProps = {
1522
+ ...mdPreviewProps,
1523
+ /**
1524
+ * input回调事件
1525
+ */
1526
+ onChange: {
1527
+ type: Function
1528
+ },
1529
+ /**
1530
+ * input回调事件
1531
+ */
1532
+ onSave: {
1533
+ type: Function
1534
+ },
1535
+ /**
1536
+ * 上传图片事件
1537
+ */
1538
+ onUploadImg: {
1539
+ type: Function
1540
+ },
1541
+ /**
1542
+ * 是否页面内全屏
1543
+ *
1544
+ * @default false
1545
+ */
1546
+ pageFullscreen: {
1547
+ type: Boolean,
1548
+ default: false
1549
+ },
1550
+ /**
1551
+ * 是否展开预览
1552
+ *
1553
+ * @default true
1554
+ */
1555
+ preview: {
1556
+ type: Boolean,
1557
+ default: true
1558
+ },
1559
+ /**
1560
+ * 是否展开html预览
1561
+ *
1562
+ * @default false
1563
+ */
1564
+ htmlPreview: {
1565
+ type: Boolean,
1566
+ default: false
1567
+ },
1568
+ /**
1569
+ * 仅预览模式,不显示toolbar和编辑框
1570
+ *
1571
+ * @4.0.0开始移除该设置,使用组件MdPreview替换
1572
+ *
1573
+ * @default false
1574
+ */
1575
+ // previewOnly: {
1576
+ // type: Boolean as PropType<boolean>,
1577
+ // default: false
1578
+ // },
1579
+ /**
1580
+ * 工具栏选择显示
1581
+ *
1582
+ * @default allToolbar
1583
+ */
1584
+ toolbars: {
1585
+ type: Array,
1586
+ default: config.allToolbar
1587
+ },
1588
+ /**
1589
+ * 工具栏选择不显示
1590
+ *
1591
+ * @default []
1592
+ */
1593
+ toolbarsExclude: {
1594
+ type: Array,
1595
+ default: []
1596
+ },
1597
+ /**
1598
+ * 格式化md
1599
+ *
1600
+ * @default true
1601
+ */
1602
+ noPrettier: {
1603
+ type: Boolean,
1604
+ default: false
1605
+ },
1606
+ /**
1607
+ * 一个tab等于空格数
1608
+ *
1609
+ * @default 2
1610
+ */
1611
+ tabWidth: {
1612
+ type: Number,
1613
+ default: 2
1614
+ },
1615
+ /**
1616
+ * 表格预设格子数
1617
+ *
1618
+ * @default [6, 4]
1619
+ */
1620
+ tableShape: {
1621
+ type: Array,
1622
+ default: () => [6, 4]
1623
+ },
1624
+ /**
1625
+ * 空提示
1626
+ *
1627
+ * @default ''
1628
+ */
1629
+ placeholder: {
1630
+ type: String,
1631
+ default: ""
1632
+ },
1633
+ /**
1634
+ * 自定义的工具栏列表
1635
+ */
1636
+ defToolbars: {
1637
+ type: [String, Object]
1638
+ },
1639
+ /**
1640
+ * 内部错误捕获
1641
+ */
1642
+ onError: {
1643
+ type: Function
1644
+ },
1645
+ /**
1646
+ * 页脚列表显示顺序
1647
+ */
1648
+ footers: {
1649
+ type: Array,
1650
+ default: config.allFooter
1651
+ },
1652
+ /**
1653
+ * 是否默认激活输入框和预览框同步滚动
1654
+ *
1655
+ * @default true
1656
+ */
1657
+ scrollAuto: {
1658
+ type: Boolean,
1659
+ default: true
1660
+ },
1661
+ /**
1662
+ * 自定义的也叫工具组件列表
1663
+ */
1664
+ defFooters: {
1665
+ type: [String, Object]
1666
+ },
1667
+ /**
1668
+ * 是否禁用上传图片
1669
+ *
1670
+ * @default false
1671
+ */
1672
+ noUploadImg: {
1673
+ type: Boolean
1674
+ },
1675
+ /**
1676
+ * 文本区域自动获得焦点
1677
+ *
1678
+ * @default false
1679
+ */
1680
+ autoFocus: {
1681
+ type: Boolean
1682
+ },
1683
+ /**
1684
+ * 禁用文本区域
1685
+ *
1686
+ * @default false
1687
+ */
1688
+ disabled: {
1689
+ type: Boolean
1690
+ },
1691
+ /**
1692
+ * 文本区域为只读
1693
+ *
1694
+ * @default false
1695
+ */
1696
+ readOnly: {
1697
+ type: Boolean
1698
+ },
1699
+ /**
1700
+ * 文本区域允许的最大字符数
1701
+ */
1702
+ maxLength: {
1703
+ type: Number
1704
+ },
1705
+ /**
1706
+ * 是否启用自动识别粘贴代码类别
1707
+ * 目前支持 vscode 复制的代码识别
1708
+ *
1709
+ * @default false
1710
+ */
1711
+ autoDetectCode: {
1712
+ type: Boolean
1713
+ },
1714
+ /**
1715
+ * 输入框失去焦点时触发事件
1716
+ */
1717
+ onBlur: {
1718
+ type: Function
1719
+ },
1720
+ /**
1721
+ * 输入框获得焦点时触发事件
1722
+ */
1723
+ onFocus: {
1724
+ type: Function
1725
+ },
1726
+ /**
1727
+ * @codemirror/autocomplete匹配关键词的方法列表
1728
+ *
1729
+ * 它会被像下面这样嵌入编辑器
1730
+ *
1731
+ * import { autocompletion } from '@codemirror/autocomplete';
1732
+ * autocompletion({
1733
+ * override: [...completions]
1734
+ * })
1735
+ */
1736
+ completions: {
1737
+ type: Array
1738
+ },
1739
+ /**
1740
+ * 是否在工具栏下面显示对应的文字名称
1741
+ *
1742
+ * @default false
1743
+ */
1744
+ showToolbarName: {
1745
+ type: Boolean,
1746
+ default: false
1747
+ },
1748
+ /**
1749
+ * 字符输入事件
1750
+ */
1751
+ onInput: {
1752
+ type: Function
1753
+ },
1754
+ onDrop: {
1755
+ type: Function
1756
+ },
1757
+ /**
1758
+ * 输入框的默认宽度
1759
+ *
1760
+ * @example '100px'/'50%'
1761
+ * @default '50%
1762
+ */
1763
+ inputBoxWitdh: {
1764
+ type: String,
1765
+ default: "50%"
1766
+ },
1767
+ /**
1768
+ * 输入框宽度变化事件
1769
+ */
1770
+ onInputBoxWitdhChange: {
1771
+ type: Function
1772
+ }
1773
+ };
1774
+ const mdPreviewEmits = ["onHtmlChanged", "onGetCatalog"];
1775
+ const editorEmits = [
1776
+ ...mdPreviewEmits,
1777
+ "onChange",
1778
+ "onSave",
1779
+ "onUploadImg",
1780
+ "onError",
1781
+ "update:modelValue",
1782
+ "onBlur",
1783
+ "onFocus",
1784
+ "onInput",
1785
+ "onDrop",
1786
+ "onInputBoxWitdhChange"
1787
+ ];
1788
+ const useExpose = (props, ctx) => {
1789
+ const { editorId } = props;
1790
+ const exposeParam = {
1791
+ rerender() {
1792
+ index.bus.emit(editorId, index.RERENDER);
1793
+ }
1794
+ };
1795
+ ctx.expose(exposeParam);
1796
+ };
1797
+ const MdPreview = /* @__PURE__ */ vue.defineComponent({
1798
+ name: "MdPreview",
1799
+ props: mdPreviewProps,
1800
+ emits: mdPreviewEmits,
1801
+ setup(props, ctx) {
1802
+ const {
1803
+ editorId,
1804
+ noKatex,
1805
+ noMermaid,
1806
+ noHighlight
1807
+ } = props;
1808
+ useProvidePreview(props);
1809
+ useExpansionPreview(props);
1810
+ useExpose(props, ctx);
1811
+ vue.onBeforeUnmount(() => {
1812
+ index.bus.clear(editorId);
1813
+ });
1814
+ return () => {
1815
+ return vue.createVNode("div", {
1816
+ "id": editorId,
1817
+ "class": [config.prefix, props.class, props.theme === "dark" && `${config.prefix}-dark`, `${config.prefix}-previewOnly`],
1818
+ "style": props.style
1819
+ }, [vue.createVNode(ContentPreview, {
1820
+ "modelValue": props.modelValue,
1821
+ "onHtmlChanged": (html) => {
1822
+ if (props.onHtmlChanged) {
1823
+ props.onHtmlChanged(html);
1824
+ } else {
1825
+ ctx.emit("onHtmlChanged", html);
1826
+ }
1827
+ },
1828
+ "onGetCatalog": (list) => {
1829
+ if (props.onGetCatalog) {
1830
+ props.onGetCatalog(list);
1831
+ } else {
1832
+ ctx.emit("onGetCatalog", list);
1833
+ }
1834
+ },
1835
+ "mdHeadingId": props.mdHeadingId,
1836
+ "noMermaid": noMermaid,
1837
+ "sanitize": props.sanitize,
1838
+ "noKatex": noKatex,
1839
+ "formatCopiedText": props.formatCopiedText,
1840
+ "noHighlight": noHighlight,
1841
+ "noImgZoomIn": props.noImgZoomIn,
1842
+ "previewOnly": true,
1843
+ "sanitizeMermaid": props.sanitizeMermaid
1844
+ }, null)]);
1845
+ };
1846
+ }
1847
+ });
1848
+ MdPreview.install = (app) => {
1849
+ app.component(MdPreview.name, MdPreview);
1850
+ return app;
1851
+ };
1852
+ exports.ContentPreview = ContentPreview;
1853
+ exports.MdPreview = MdPreview;
1854
+ exports.contentProps = contentProps;
1855
+ exports.editorEmits = editorEmits;
1856
+ exports.editorProps = editorProps;
1857
+ exports.useCatalog = useCatalog;
1858
+ exports.useConfig = useConfig;
1859
+ exports.useErrorCatcher = useErrorCatcher;
1860
+ exports.useExpansion = useExpansion;
1861
+ exports.useExpose = useExpose$1;
1862
+ exports.useOnSave = useOnSave;
1863
+ exports.useProvide = useProvide;