md-editor-v3 6.0.1 → 6.1.0-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.
- package/lib/cjs/chunks/dom.cjs +1 -1
- package/lib/cjs/chunks/index3.cjs +39 -39
- package/lib/es/chunks/dom.mjs +132 -92
- package/lib/es/chunks/index3.mjs +375 -383
- package/lib/preview.css +1 -1
- package/lib/style.css +1 -1
- package/lib/types/MdEditor/type.d.ts +1 -0
- package/lib/types/MdEditor/utils/dom.d.ts +6 -0
- package/package.json +2 -2
package/lib/cjs/chunks/dom.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const j=require("@vavt/copy2clipboard"),i=require("./config.cjs"),q={copy:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy ${i.prefix}-icon"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,"collapse-tips":`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-chevron-left ${i.prefix}-icon"><circle cx="12" cy="12" r="10"/><path d="m14 16-4-4 4-4"/></svg>`,pin:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin ${i.prefix}-icon"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg>`,"pin-off":`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin-off ${i.prefix}-icon"><path d="M12 17v5"/><path d="M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89"/><path d="m2 2 20 20"/><path d="M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11"/></svg>`,check:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check ${i.prefix}-icon"><path d="M20 6 9 17l-5-5"/></svg>`},p=(d,c)=>typeof c[d]=="string"?c[d]:q[d],A=(d,c)=>{const e=s=>{const t=d.parentElement||document.body,n=t.offsetWidth,r=t.offsetHeight,{clientWidth:l,clientHeight:u}=document.documentElement,a=s.offsetX,w=s.offsetY,g=y=>{let h=y.x+document.body.scrollLeft-document.body.clientLeft-a,m=y.y+document.body.scrollTop-document.body.clientTop-w;h=h<1?1:h<l-n-1?h:l-n-1,m=m<1?1:m<u-r-1?m:u-r-1,c?c(h,m):(t.style.left=`${h}px`,t.style.top=`${m}px`)};document.addEventListener("mousemove",g);const f=()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",f)};document.addEventListener("mouseup",f)};return d.addEventListener("mousedown",e),()=>{d.removeEventListener("mousedown",e)}},X=(d,c,e="")=>{const s=document.getElementById(c.id);if(s)e!==""&&(Reflect.get(window,e)?c.onload?.call(s,new Event("load")):c.onload&&s.addEventListener("load",c.onload));else{const t={...c};t.onload=null;const n=B(d,t);c.onload&&n.addEventListener("load",c.onload),document.head.appendChild(n)}},D=(d,c)=>{document.getElementById(c.id)?.remove(),X(d,c)},B=(d,c)=>{const e=document.createElement(d);return Object.keys(c).forEach(s=>{c[s]!==void 0&&(e[s]=c[s])}),e},z=(d,c)=>{const e=new Map;return d?.forEach(s=>{let t=s.querySelector(`.${i.prefix}-mermaid-action`);t?t.querySelector(`.${i.prefix}-mermaid-copy`)||t.insertAdjacentHTML("beforeend",`<span class="${i.prefix}-mermaid-copy">${p("copy",c.customIcon)}</span>`):(s.insertAdjacentHTML("beforeend",`<div class="${i.prefix}-mermaid-action"><span class="${i.prefix}-mermaid-copy">${p("copy",c.customIcon)}</span></div>`),t=s.querySelector(`.${i.prefix}-mermaid-action`));const n=t.querySelector(`.${i.prefix}-mermaid-copy`);let r=-1;const l=()=>{clearTimeout(r),j(s.dataset.content||"").then(()=>{n.innerHTML=p("check",c.customIcon)}).catch(()=>{n.innerHTML=p("copy",c.customIcon)}).finally(()=>{r=window.setTimeout(()=>{n.innerHTML=p("copy",c.customIcon)},1500)})};n.addEventListener("click",l),e.set(s,{removeClick:()=>{n.removeEventListener("click",l)}})}),()=>{e.forEach(({removeClick:s})=>{s?.()}),e.clear()}},b=(()=>{const d=e=>{if(!e)return()=>{};const s=e.firstChild;let t=1,n=0,r=0,l=!1,u,a,w,g=1;const f=()=>{s.style.transform=`translate(${n}px, ${r}px) scale(${t})`},y=o=>{o.touches.length===1?(l=!0,u=o.touches[0].clientX-n,a=o.touches[0].clientY-r):o.touches.length===2&&(w=Math.hypot(o.touches[0].clientX-o.touches[1].clientX,o.touches[0].clientY-o.touches[1].clientY),g=t)},h=o=>{if(o.preventDefault(),l&&o.touches.length===1)n=o.touches[0].clientX-u,r=o.touches[0].clientY-a,f();else if(o.touches.length===2){const E=Math.hypot(o.touches[0].clientX-o.touches[1].clientX,o.touches[0].clientY-o.touches[1].clientY)/w,v=t;t=g*(1+(E-1));const x=(o.touches[0].clientX+o.touches[1].clientX)/2,M=(o.touches[0].clientY+o.touches[1].clientY)/2,Y=s.getBoundingClientRect(),S=(x-Y.left)/v,I=(M-Y.top)/v;n-=S*(t-v),r-=I*(t-v),f()}},m=()=>{l=!1},k=o=>{o.preventDefault();const L=.02,E=t;o.deltaY<0?t+=L:t=Math.max(.1,t-L);const v=s.getBoundingClientRect(),x=o.clientX-v.left,M=o.clientY-v.top;n-=x/E*(t-E),r-=M/E*(t-E),f()},$=o=>{l=!0,u=o.clientX-n,a=o.clientY-r},C=o=>{l&&(n=o.clientX-u,r=o.clientY-a,f())},H=()=>{l=!1},T=()=>{l=!1};return e.addEventListener("touchstart",y,{passive:!1}),e.addEventListener("touchmove",h,{passive:!1}),e.addEventListener("touchend",m),e.addEventListener("wheel",k,{passive:!1}),e.addEventListener("mousedown",$),e.addEventListener("mousemove",C),e.addEventListener("mouseup",H),e.addEventListener("mouseleave",T),()=>{e.removeEventListener("touchstart",y),e.removeEventListener("touchmove",h),e.removeEventListener("touchend",m),e.removeEventListener("wheel",k),e.removeEventListener("mousedown",$),e.removeEventListener("mousemove",C),e.removeEventListener("mouseup",H),e.removeEventListener("mouseleave",T)}};return(e,s)=>{const t=new Map;return e?.forEach(n=>{let r=n.querySelector(`.${i.prefix}-mermaid-action`);r?r.querySelector(`.${i.prefix}-mermaid-zoom`)||r.insertAdjacentHTML("beforeend",`<span class="${i.prefix}-mermaid-zoom">${p("pin-off",s.customIcon)}</span>`):(n.insertAdjacentHTML("beforeend",`<div class="${i.prefix}-mermaid-action"><span class="${i.prefix}-mermaid-zoom">${p("pin-off",s.customIcon)}</span></div>`),r=n.querySelector(`.${i.prefix}-mermaid-action`));const l=r.querySelector(`.${i.prefix}-mermaid-zoom`),u=()=>{const a=t.get(n);if(a?.removeEvent)a.removeEvent(),n.removeAttribute("data-grab"),t.set(n,{removeClick:a.removeClick}),l.innerHTML=p("pin-off",s.customIcon);else{const w=d(n);n.setAttribute("data-grab",""),t.set(n,{removeEvent:w,removeClick:a?.removeClick}),l.innerHTML=p("pin",s.customIcon)}};l.addEventListener("click",u),t.set(n,{removeClick:()=>l.removeEventListener("click",u)})}),()=>{t.forEach(({removeEvent:n,removeClick:r})=>{n?.(),r?.()}),t.clear()}}})();exports.StrIcon=p;exports.appendHandler=X;exports.copyMermaid=z;exports.keyMove=A;exports.updateHandler=D;exports.zoomMermaid=b;
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
"use strict";const r=require("vue"),_=require("@vavt/util"),f=require("./config.cjs"),p=require("./event-bus.cjs"),I=require("./dom.cjs"),re=require("@vavt/copy2clipboard"),ae=require("markdown-it"),ie=require("markdown-it-image-figures"),le=require("markdown-it-sub"),se=require("markdown-it-sup"),ce=require("./index5.cjs"),de=require("lru-cache"),ue=require("medium-zoom"),S={hljs:`${f.prefix}-hljs`,hlcss:`${f.prefix}-hlCss`,prettier:`${f.prefix}-prettier`,prettierMD:`${f.prefix}-prettierMD`,cropperjs:`${f.prefix}-cropper`,croppercss:`${f.prefix}-cropperCss`,screenfull:`${f.prefix}-screenfull`,mermaidM:`${f.prefix}-mermaid-m`,mermaid:`${f.prefix}-mermaid`,katexjs:`${f.prefix}-katex`,katexcss:`${f.prefix}-katexCss`,echarts:`${f.prefix}-echarts`},me=(e,t,i)=>{const{editorId:o}=i,n=r.reactive({buildFinished:!1,html:""});r.watch(()=>e.modelValue,()=>{n.buildFinished=!1}),r.onMounted(()=>{p.bus.on(o,{name:p.BUILD_FINISHED,callback(h){n.buildFinished=!0,n.html=h}}),p.bus.on(o,{name:p.ON_SAVE,callback(){const h=new Promise(c=>{if(n.buildFinished)c(n.html);else{const u=s=>{c(s),p.bus.remove(o,p.BUILD_FINISHED,u)};p.bus.on(o,{name:p.BUILD_FINISHED,callback:u})}});e.onSave?e.onSave(e.modelValue,h):t.emit("onSave",e.modelValue,h)}})})},J=(e,{editorId:t,rootRef:i,setting:o})=>{const n=f.globalConfig.editorExtensions.highlight,h=f.globalConfig.editorExtensionsAttrs.highlight;r.provide("editorId",t),r.provide("rootRef",i),r.provide("theme",r.computed(()=>e.theme)),r.provide("language",r.computed(()=>e.language)),r.provide("highlight",r.computed(()=>{const{js:u}=n,s={...f.codeCss,...n.css},{js:m,css:l={}}=h||{},a=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,d=s[e.codeTheme]?s[e.codeTheme][a]:f.codeCss.atom[a],v=s[e.codeTheme]&&l[e.codeTheme]?l[e.codeTheme][a]:l.atom?l.atom[a]:{};return{js:{src:u,...m},css:{href:d,...v}}})),r.provide("showCodeRowNumber",e.showCodeRowNumber);const c=r.computed(()=>{const u={...f.staticTextDefault,...f.globalConfig.editorConfig.languageUserDefined};return _.deepMerge(_.deepClone(f.staticTextDefault["en-US"]),u[e.language]||{})});return r.provide("usedLanguageText",c),r.provide("previewTheme",r.computed(()=>e.previewTheme)),r.provide("customIcon",r.computed(()=>e.customIcon)),r.provide("setting",r.computed(()=>o?{...o}:{preview:!0,htmlPreview:!1,previewOnly:!1,pageFullscreen:!1,fullscreen:!1})),{editorId:t}},pe=(e,t)=>(r.provide("tabWidth",e.tabWidth),r.provide("disabled",r.computed(()=>e.disabled)),r.provide("showToolbarName",r.computed(()=>e.showToolbarName)),r.provide("noUploadImg",e.noUploadImg),r.provide("tableShape",r.computed(()=>e.tableShape)),r.provide("noPrettier",e.noPrettier),r.provide("codeTheme",r.computed(()=>e.codeTheme)),r.provide("updateSetting",t.updateSetting),r.provide("catalogVisible",r.computed(()=>t.catalogVisible.value)),r.provide("defToolbars",t.defToolbars),r.provide("floatingToolbars",r.computed(()=>e.floatingToolbars)),J(e,t)),fe=e=>{const{noPrettier:t,noUploadImg:i}=e,{editorExtensions:o,editorExtensionsAttrs:n}=f.globalConfig,h=t||o.prettier.prettierInstance,c=t||o.prettier.parserMarkdownInstance,u=i||o.cropper.instance;r.onMounted(()=>{if(!u){const{js:s={},css:m={}}=n.cropper||{};I.appendHandler("link",{...m,rel:"stylesheet",href:o.cropper.css,id:S.croppercss}),I.appendHandler("script",{...s,src:o.cropper.js,id:S.cropperjs})}if(!h){const{standaloneJs:s={}}=n.prettier||{};I.appendHandler("script",{...s,src:o.prettier.standaloneJs,id:S.prettier})}if(!c){const{parserMarkdownJs:s={}}=n.prettier||{};I.appendHandler("script",{...s,src:o.prettier.parserMarkdownJs,id:S.prettierMD})}})},he=(e,t,i)=>{const{editorId:o}=i;r.onMounted(()=>{p.bus.on(o,{name:p.ERROR_CATCHER,callback:n=>{e.onError?.(n),t.emit("onError",n)}})})},ge=(e,t,i)=>{const{editorId:o}=i,n=r.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),h=r.reactive({...n}),c=(m,l)=>{const a=l===void 0?!n[m]:l;switch(m){case"preview":{n.htmlPreview=!1,n.previewOnly=!1;break}case"htmlPreview":{n.preview=!1,n.previewOnly=!1;break}case"previewOnly":{a?!n.preview&&!n.htmlPreview&&(n.preview=!0):(h.preview||(n.preview=!1),h.htmlPreview||(n.htmlPreview=!1));break}}h[m]=a,n[m]=a};let u="";const s=()=>{n.pageFullscreen||n.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=u};return r.watch(()=>[n.pageFullscreen,n.fullscreen],s),r.onMounted(()=>{p.bus.on(o,{name:p.UPLOAD_IMAGE,callback(m,l){const a=d=>{p.bus.emit(o,p.REPLACE,"image",{desc:"",urls:d}),l?.()};e.onUploadImg?e.onUploadImg(m,a):t.emit("onUploadImg",m,a)}}),u=document.body.style.overflow,s()}),[n,c]},ve=(e,t)=>{const{editorId:i}=t,o=r.ref(!1);return r.onMounted(()=>{p.bus.on(i,{name:p.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?o.value=!o.value:o.value=n}})}),o},be=(e,t,i)=>{const{editorId:o,catalogVisible:n,setting:h,updateSetting:c,codeRef:u}=i;r.watch(()=>h.pageFullscreen,m=>{p.bus.emit(o,p.PAGE_FULL_SCREEN_CHANGED,m)}),r.watch(()=>h.fullscreen,m=>{p.bus.emit(o,p.FULL_SCREEN_CHANGED,m)}),r.watch(()=>h.preview,m=>{p.bus.emit(o,p.PREVIEW_CHANGED,m)}),r.watch(()=>h.previewOnly,m=>{p.bus.emit(o,p.PREVIEW_ONLY_CHANGED,m)}),r.watch(()=>h.htmlPreview,m=>{p.bus.emit(o,p.HTML_PREVIEW_CHANGED,m)}),r.watch(n,m=>{p.bus.emit(o,p.CATALOG_VISIBLE_CHANGED,m)});const s={on(m,l){switch(m){case"pageFullscreen":{p.bus.on(o,{name:p.PAGE_FULL_SCREEN_CHANGED,callback(a){l(a)}});break}case"fullscreen":{p.bus.on(o,{name:p.FULL_SCREEN_CHANGED,callback(a){l(a)}});break}case"preview":{p.bus.on(o,{name:p.PREVIEW_CHANGED,callback(a){l(a)}});break}case"previewOnly":{p.bus.on(o,{name:p.PREVIEW_ONLY_CHANGED,callback(a){l(a)}});break}case"htmlPreview":{p.bus.on(o,{name:p.HTML_PREVIEW_CHANGED,callback(a){l(a)}});break}case"catalog":{p.bus.on(o,{name:p.CATALOG_VISIBLE_CHANGED,callback(a){l(a)}});break}}},togglePageFullscreen(m){c("pageFullscreen",m)},toggleFullscreen(m){p.bus.emit(o,p.CHANGE_FULL_SCREEN,m)},togglePreview(m){c("preview",m)},togglePreviewOnly(m){c("previewOnly",m)},toggleHtmlPreview(m){c("htmlPreview",m)},toggleCatalog(m){p.bus.emit(o,p.CHANGE_CATALOG_VISIBLE,m)},triggerSave(){p.bus.emit(o,p.ON_SAVE)},insert(m){p.bus.emit(o,p.REPLACE,"universal",{generate:m})},focus(m){u.value?.focus(m)},rerender(){p.bus.emit(o,p.RERENDER)},getSelectedText(){return u.value?.getSelectedText()},resetHistory(){u.value?.resetHistory()},domEventHandlers(m){p.bus.emit(o,p.EVENT_LISTENER,m)},execCommand(m){p.bus.emit(o,p.REPLACE,m)},getEditorView(){return u.value?.getEditorView()}};t.expose(s)},X=e=>{const t=r.useId();return e.id||e.editorId||`${f.prefix}-${t}`},ye=(e,t,i)=>{const o=r.inject("editorId"),n=r.inject("rootRef"),h=r.inject("usedLanguageText"),c=r.inject("setting"),u=()=>{n.value.querySelectorAll(`#${o} .${f.prefix}-preview .${f.prefix}-code`).forEach(l=>{let a=-1;const d=l.querySelector(`.${f.prefix}-copy-button`);d&&(d.onclick=v=>{v.preventDefault(),clearTimeout(a);const b=(l.querySelector("input:checked + pre code")||l.querySelector("pre code")).textContent,{text:y,successTips:k,failTips:w}=h.value.copyCode;let x=k;re(e.formatCopiedText(b||"")).catch(()=>{x=w}).finally(()=>{d.dataset.isIcon?d.dataset.tips=x:d.innerHTML=x,a=window.setTimeout(()=>{d.dataset.isIcon?d.dataset.tips=y:d.innerHTML=y},1500)})})})},s=()=>{r.nextTick(u)},m=l=>{l&&r.nextTick(u)};r.watch([t,i],s),r.watch(()=>c.value.preview,m),r.watch(()=>c.value.htmlPreview,m),r.onMounted(u)},we=e=>{const t=r.inject("editorId"),i=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:h}=f.globalConfig;let c=n.echarts.instance;const u=r.shallowRef(-1),s=()=>{!e.noEcharts&&c&&(u.value=u.value+1)};r.watch(()=>i.value,()=>{s()}),r.onMounted(()=>{if(e.noEcharts||c)return;const g=n.echarts.js;I.appendHandler("script",{...h.echarts?.js,src:g,id:S.echarts,onload(){c=window.echarts,s()}},"echarts")});let m,l=[],a=[];const d=()=>{l.forEach(g=>{g.dispose()}),a.forEach(g=>{g.disconnect()}),l=[],m=[],a=[]},v=()=>{d(),!e.noEcharts&&c&&(m=Array.from(o.value.querySelectorAll(`#${t} div.${f.prefix}-echarts:not([data-processed])`)),m.forEach(g=>{if(g.dataset.closed==="false")return!1;try{const b=new Function(`return ${g.innerText}`)(),y=c.init(g,i.value);y.setOption(b),g.setAttribute("data-processed",""),l.push(y);const k=new ResizeObserver(()=>{y.resize()});k.observe(g),a.push(k)}catch(b){p.bus.emit(t,p.ERROR_CATCHER,{name:"echarts",message:b?.message,error:b})}}))};return r.onBeforeUnmount(()=>{d()}),{reRenderEcharts:u,replaceEcharts:v}},xe=e=>{const t=r.inject("highlight"),i=r.shallowRef(f.globalConfig.editorExtensions.highlight.instance);return r.onMounted(()=>{e.noHighlight||i.value||(I.appendHandler("link",{...t.value.css,rel:"stylesheet",id:S.hlcss}),I.appendHandler("script",{...t.value.js,id:S.hljs,onload(){i.value=window.hljs}},"hljs"))}),r.watch(()=>t.value.css,()=>{e.noHighlight||f.globalConfig.editorExtensions.highlight.instance||I.updateHandler("link",{...t.value.css,rel:"stylesheet",id:S.hlcss})}),i},Ce=e=>{const t=r.shallowRef(f.globalConfig.editorExtensions.katex.instance);return r.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:i,editorExtensionsAttrs:o}=f.globalConfig;I.appendHandler("script",{...o.katex?.js,src:i.katex.js,id:S.katexjs,onload(){t.value=window.katex}},"katex"),I.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:i.katex.css,id:S.katexcss})}),t},G=new de.LRUCache({max:1e3,ttl:6e5}),Ee=e=>{const t=r.inject("editorId"),i=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:h,mermaidConfig:c}=f.globalConfig;let u=n.mermaid.instance;const s=r.shallowRef(-1),m=()=>{!e.noMermaid&&u&&(u.initialize(c({startOnLoad:!1,theme:i.value==="dark"?"dark":"default"})),s.value=s.value+1)};return r.watch(()=>i.value,()=>{G.clear(),m()}),r.onMounted(()=>{if(e.noMermaid||u)return;const a=n.mermaid.js;/\.mjs/.test(a)?(I.appendHandler("link",{...h.mermaid?.js,rel:"modulepreload",href:a,id:S.mermaidM}),import(a).then(d=>{u=d.default,m()}).catch(d=>{p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${d.message}`,error:d})})):I.appendHandler("script",{...h.mermaid?.js,src:a,id:S.mermaid,onload(){u=window.mermaid,m()}},"mermaid")}),{reRenderRef:s,replaceMermaid:async()=>{if(!e.noMermaid&&u){const a=o.value.querySelectorAll(`div.${f.prefix}-mermaid`),d=document.createElement("div"),v=document.body.offsetWidth>1366?document.body.offsetWidth:1366,g=document.body.offsetHeight>768?document.body.offsetHeight:768;d.style.width=v+"px",d.style.height=g+"px",d.style.position="fixed",d.style.zIndex="-10000",d.style.top="-10000";let b=a.length;b>0&&document.body.appendChild(d),await Promise.allSettled(Array.from(a).map(y=>(async w=>{if(w.dataset.closed==="false")return!1;const x=w.innerText;let A=G.get(x);if(!A){const E=_.randomId();let $={svg:""};try{$=await u.render(E,x,d),A=await e.sanitizeMermaid($.svg);const C=document.createElement("p");C.className=`${f.prefix}-mermaid`,C.setAttribute("data-processed",""),C.innerHTML=A,C.children[0]?.removeAttribute("height"),G.set(x,C.innerHTML),w.dataset.line!==void 0&&(C.dataset.line=w.dataset.line),w.replaceWith(C)}catch(C){p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:C.message,error:C})}--b===0&&d.remove()}})(y)))}}}},$e=(e,t)=>{t=t||{};const i=3,o=t.marker||"!",n=o.charCodeAt(0),h=o.length;let c="",u="";const s=(l,a,d,v,g)=>{const b=l[a];return b.type==="admonition_open"?l[a].attrPush(["class",`${f.prefix}-admonition ${f.prefix}-admonition-${b.info}`]):b.type==="admonition_title_open"&&l[a].attrPush(["class",`${f.prefix}-admonition-title`]),g.renderToken(l,a,d)},m=l=>{const a=l.trim().split(" ",2);u="",c=a[0],a.length>1&&(u=l.substring(c.length+2))};e.block.ruler.before("code","admonition",(l,a,d,v)=>{let g,b,y,k=!1,w=l.bMarks[a]+l.tShift[a],x=l.eMarks[a];if(n!==l.src.charCodeAt(w))return!1;for(g=w+1;g<=x&&o[(g-w)%h]===l.src[g];g++);const A=Math.floor((g-w)/h);if(A!==i)return!1;g-=(g-w)%h;const E=l.src.slice(w,g),$=l.src.slice(g,x);if(m($),v)return!0;for(b=a;b++,!(b>=d||(w=l.bMarks[b]+l.tShift[b],x=l.eMarks[b],w<x&&l.sCount[b]<l.blkIndent));)if(n===l.src.charCodeAt(w)&&!(l.sCount[b]-l.blkIndent>=4)){for(g=w+1;g<=x&&o[(g-w)%h]===l.src[g];g++);if(!(Math.floor((g-w)/h)<A)&&(g-=(g-w)%h,g=l.skipSpaces(g),!(g<x))){k=!0;break}}const C=l.parentType,F=l.lineMax;return l.parentType="root",l.lineMax=b,y=l.push("admonition_open","div",1),y.markup=E,y.block=!0,y.info=c,y.map=[a,b],u&&(y=l.push("admonition_title_open","p",1),y.markup=E+" "+c,y.map=[a,b],y=l.push("inline","",0),y.content=u,y.map=[a,l.line-1],y.children=[],y=l.push("admonition_title_close","p",-1),y.markup=E+" "+c),l.md.block.tokenize(l,a+1,b),y=l.push("admonition_close","div",-1),y.markup=l.src.slice(w,g),y.block=!0,l.parentType=C,l.lineMax=F,l.line=b+(k?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},q=(e,t)=>{const i=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const n=e.attrIndex(o[0]);n<0?i.push(o):(i[n]=i[n].slice(),i[n][1]+=` ${o[1]}`)}),i},Ie=(e,t)=>{const i=e.renderer.rules.fence,o=e.utils.unescapeAll,n=/\[(\w*)(?::([\w ]*))?\]/,h=/::(open|close)/,c=a=>a.info?o(a.info).trim():"",u=a=>{const d=c(a),[v=null,g=""]=(n.exec(d)||[]).slice(1);return[v,g]},s=a=>{const d=c(a);return d?d.split(/(\s+)/g)[0]:""},m=a=>{const d=a.info.match(h)||[],v=d[1]==="open"||d[1]!=="close"&&t.codeFoldable&&a.content.trim().split(`
|
|
2
|
-
`).length<t.autoFoldThreshold,g=d[1]||t.codeFoldable?"details":"div",b=d[1]||t.codeFoldable?"summary":"div";return{open:v,tagContainer:g,tagHeader:b}},l=(a,d,v,g,b)=>{if(a[d].hidden)return"";const y=t.usedLanguageTextRef.value?.copyCode.text,
|
|
3
|
-
<${
|
|
4
|
-
<${
|
|
1
|
+
"use strict";const r=require("vue"),N=require("@vavt/util"),f=require("./config.cjs"),p=require("./event-bus.cjs"),I=require("./dom.cjs"),re=require("@vavt/copy2clipboard"),ae=require("markdown-it"),ie=require("markdown-it-image-figures"),le=require("markdown-it-sub"),se=require("markdown-it-sup"),ce=require("./index5.cjs"),de=require("lru-cache"),ue=require("medium-zoom"),S={hljs:`${f.prefix}-hljs`,hlcss:`${f.prefix}-hlCss`,prettier:`${f.prefix}-prettier`,prettierMD:`${f.prefix}-prettierMD`,cropperjs:`${f.prefix}-cropper`,croppercss:`${f.prefix}-cropperCss`,screenfull:`${f.prefix}-screenfull`,mermaidM:`${f.prefix}-mermaid-m`,mermaid:`${f.prefix}-mermaid`,katexjs:`${f.prefix}-katex`,katexcss:`${f.prefix}-katexCss`,echarts:`${f.prefix}-echarts`},me=(e,t,i)=>{const{editorId:o}=i,n=r.reactive({buildFinished:!1,html:""});r.watch(()=>e.modelValue,()=>{n.buildFinished=!1}),r.onMounted(()=>{p.bus.on(o,{name:p.BUILD_FINISHED,callback(h){n.buildFinished=!0,n.html=h}}),p.bus.on(o,{name:p.ON_SAVE,callback(){const h=new Promise(c=>{if(n.buildFinished)c(n.html);else{const u=s=>{c(s),p.bus.remove(o,p.BUILD_FINISHED,u)};p.bus.on(o,{name:p.BUILD_FINISHED,callback:u})}});e.onSave?e.onSave(e.modelValue,h):t.emit("onSave",e.modelValue,h)}})})},Y=(e,{editorId:t,rootRef:i,setting:o})=>{const n=f.globalConfig.editorExtensions.highlight,h=f.globalConfig.editorExtensionsAttrs.highlight;r.provide("editorId",t),r.provide("rootRef",i),r.provide("theme",r.computed(()=>e.theme)),r.provide("language",r.computed(()=>e.language)),r.provide("highlight",r.computed(()=>{const{js:u}=n,s={...f.codeCss,...n.css},{js:m,css:l={}}=h||{},a=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,d=s[e.codeTheme]?s[e.codeTheme][a]:f.codeCss.atom[a],v=s[e.codeTheme]&&l[e.codeTheme]?l[e.codeTheme][a]:l.atom?l.atom[a]:{};return{js:{src:u,...m},css:{href:d,...v}}})),r.provide("showCodeRowNumber",e.showCodeRowNumber);const c=r.computed(()=>{const u={...f.staticTextDefault,...f.globalConfig.editorConfig.languageUserDefined};return N.deepMerge(N.deepClone(f.staticTextDefault["en-US"]),u[e.language]||{})});return r.provide("usedLanguageText",c),r.provide("previewTheme",r.computed(()=>e.previewTheme)),r.provide("customIcon",r.computed(()=>e.customIcon)),r.provide("setting",r.computed(()=>o?{...o}:{preview:!0,htmlPreview:!1,previewOnly:!1,pageFullscreen:!1,fullscreen:!1})),{editorId:t}},pe=(e,t)=>(r.provide("tabWidth",e.tabWidth),r.provide("disabled",r.computed(()=>e.disabled)),r.provide("showToolbarName",r.computed(()=>e.showToolbarName)),r.provide("noUploadImg",e.noUploadImg),r.provide("tableShape",r.computed(()=>e.tableShape)),r.provide("noPrettier",e.noPrettier),r.provide("codeTheme",r.computed(()=>e.codeTheme)),r.provide("updateSetting",t.updateSetting),r.provide("catalogVisible",r.computed(()=>t.catalogVisible.value)),r.provide("defToolbars",t.defToolbars),r.provide("floatingToolbars",r.computed(()=>e.floatingToolbars)),Y(e,t)),fe=e=>{const{noPrettier:t,noUploadImg:i}=e,{editorExtensions:o,editorExtensionsAttrs:n}=f.globalConfig,h=t||o.prettier.prettierInstance,c=t||o.prettier.parserMarkdownInstance,u=i||o.cropper.instance;r.onMounted(()=>{if(!u){const{js:s={},css:m={}}=n.cropper||{};I.appendHandler("link",{...m,rel:"stylesheet",href:o.cropper.css,id:S.croppercss}),I.appendHandler("script",{...s,src:o.cropper.js,id:S.cropperjs})}if(!h){const{standaloneJs:s={}}=n.prettier||{};I.appendHandler("script",{...s,src:o.prettier.standaloneJs,id:S.prettier})}if(!c){const{parserMarkdownJs:s={}}=n.prettier||{};I.appendHandler("script",{...s,src:o.prettier.parserMarkdownJs,id:S.prettierMD})}})},he=(e,t,i)=>{const{editorId:o}=i;r.onMounted(()=>{p.bus.on(o,{name:p.ERROR_CATCHER,callback:n=>{e.onError?.(n),t.emit("onError",n)}})})},ge=(e,t,i)=>{const{editorId:o}=i,n=r.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),h=r.reactive({...n}),c=(m,l)=>{const a=l===void 0?!n[m]:l;switch(m){case"preview":{n.htmlPreview=!1,n.previewOnly=!1;break}case"htmlPreview":{n.preview=!1,n.previewOnly=!1;break}case"previewOnly":{a?!n.preview&&!n.htmlPreview&&(n.preview=!0):(h.preview||(n.preview=!1),h.htmlPreview||(n.htmlPreview=!1));break}}h[m]=a,n[m]=a};let u="";const s=()=>{n.pageFullscreen||n.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=u};return r.watch(()=>[n.pageFullscreen,n.fullscreen],s),r.onMounted(()=>{p.bus.on(o,{name:p.UPLOAD_IMAGE,callback(m,l){const a=d=>{p.bus.emit(o,p.REPLACE,"image",{desc:"",urls:d}),l?.()};e.onUploadImg?e.onUploadImg(m,a):t.emit("onUploadImg",m,a)}}),u=document.body.style.overflow,s()}),[n,c]},ve=(e,t)=>{const{editorId:i}=t,o=r.ref(!1);return r.onMounted(()=>{p.bus.on(i,{name:p.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?o.value=!o.value:o.value=n}})}),o},be=(e,t,i)=>{const{editorId:o,catalogVisible:n,setting:h,updateSetting:c,codeRef:u}=i;r.watch(()=>h.pageFullscreen,m=>{p.bus.emit(o,p.PAGE_FULL_SCREEN_CHANGED,m)}),r.watch(()=>h.fullscreen,m=>{p.bus.emit(o,p.FULL_SCREEN_CHANGED,m)}),r.watch(()=>h.preview,m=>{p.bus.emit(o,p.PREVIEW_CHANGED,m)}),r.watch(()=>h.previewOnly,m=>{p.bus.emit(o,p.PREVIEW_ONLY_CHANGED,m)}),r.watch(()=>h.htmlPreview,m=>{p.bus.emit(o,p.HTML_PREVIEW_CHANGED,m)}),r.watch(n,m=>{p.bus.emit(o,p.CATALOG_VISIBLE_CHANGED,m)});const s={on(m,l){switch(m){case"pageFullscreen":{p.bus.on(o,{name:p.PAGE_FULL_SCREEN_CHANGED,callback(a){l(a)}});break}case"fullscreen":{p.bus.on(o,{name:p.FULL_SCREEN_CHANGED,callback(a){l(a)}});break}case"preview":{p.bus.on(o,{name:p.PREVIEW_CHANGED,callback(a){l(a)}});break}case"previewOnly":{p.bus.on(o,{name:p.PREVIEW_ONLY_CHANGED,callback(a){l(a)}});break}case"htmlPreview":{p.bus.on(o,{name:p.HTML_PREVIEW_CHANGED,callback(a){l(a)}});break}case"catalog":{p.bus.on(o,{name:p.CATALOG_VISIBLE_CHANGED,callback(a){l(a)}});break}}},togglePageFullscreen(m){c("pageFullscreen",m)},toggleFullscreen(m){p.bus.emit(o,p.CHANGE_FULL_SCREEN,m)},togglePreview(m){c("preview",m)},togglePreviewOnly(m){c("previewOnly",m)},toggleHtmlPreview(m){c("htmlPreview",m)},toggleCatalog(m){p.bus.emit(o,p.CHANGE_CATALOG_VISIBLE,m)},triggerSave(){p.bus.emit(o,p.ON_SAVE)},insert(m){p.bus.emit(o,p.REPLACE,"universal",{generate:m})},focus(m){u.value?.focus(m)},rerender(){p.bus.emit(o,p.RERENDER)},getSelectedText(){return u.value?.getSelectedText()},resetHistory(){u.value?.resetHistory()},domEventHandlers(m){p.bus.emit(o,p.EVENT_LISTENER,m)},execCommand(m){p.bus.emit(o,p.REPLACE,m)},getEditorView(){return u.value?.getEditorView()}};t.expose(s)},Q=e=>{const t=r.useId();return e.id||e.editorId||`${f.prefix}-${t}`},ye=(e,t,i)=>{const o=r.inject("editorId"),n=r.inject("rootRef"),h=r.inject("usedLanguageText"),c=r.inject("setting"),u=()=>{n.value.querySelectorAll(`#${o} .${f.prefix}-preview .${f.prefix}-code`).forEach(l=>{let a=-1;const d=l.querySelector(`.${f.prefix}-copy-button`);d&&(d.onclick=v=>{v.preventDefault(),clearTimeout(a);const b=(l.querySelector("input:checked + pre code")||l.querySelector("pre code")).textContent,{text:y,successTips:T,failTips:w}=h.value.copyCode;let E=T;re(e.formatCopiedText(b||"")).catch(()=>{E=w}).finally(()=>{d.dataset.isIcon?d.dataset.tips=E:d.innerHTML=E,a=window.setTimeout(()=>{d.dataset.isIcon?d.dataset.tips=y:d.innerHTML=y},1500)})})})},s=()=>{r.nextTick(u)},m=l=>{l&&r.nextTick(u)};r.watch([t,i],s),r.watch(()=>c.value.preview,m),r.watch(()=>c.value.htmlPreview,m),r.onMounted(u)},we=e=>{const t=r.inject("editorId"),i=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:h}=f.globalConfig;let c=n.echarts.instance;const u=r.shallowRef(-1),s=()=>{!e.noEcharts&&c&&(u.value=u.value+1)};r.watch(()=>i.value,()=>{s()}),r.onMounted(()=>{if(e.noEcharts||c)return;const g=n.echarts.js;I.appendHandler("script",{...h.echarts?.js,src:g,id:S.echarts,onload(){c=window.echarts,s()}},"echarts")});let m,l=[],a=[];const d=()=>{l.forEach(g=>{g.dispose()}),a.forEach(g=>{g.disconnect()}),l=[],m=[],a=[]},v=()=>{d(),!e.noEcharts&&c&&(m=Array.from(o.value.querySelectorAll(`#${t} div.${f.prefix}-echarts:not([data-processed])`)),m.forEach(g=>{if(g.dataset.closed==="false")return!1;try{const b=new Function(`return ${g.innerText}`)(),y=c.init(g,i.value);y.setOption(b),g.setAttribute("data-processed",""),l.push(y);const T=new ResizeObserver(()=>{y.resize()});T.observe(g),a.push(T)}catch(b){p.bus.emit(t,p.ERROR_CATCHER,{name:"echarts",message:b?.message,error:b})}}))};return r.onBeforeUnmount(()=>{d()}),{reRenderEcharts:u,replaceEcharts:v}},Ce=e=>{const t=r.inject("highlight"),i=r.shallowRef(f.globalConfig.editorExtensions.highlight.instance);return r.onMounted(()=>{e.noHighlight||i.value||(I.appendHandler("link",{...t.value.css,rel:"stylesheet",id:S.hlcss}),I.appendHandler("script",{...t.value.js,id:S.hljs,onload(){i.value=window.hljs}},"hljs"))}),r.watch(()=>t.value.css,()=>{e.noHighlight||f.globalConfig.editorExtensions.highlight.instance||I.updateHandler("link",{...t.value.css,rel:"stylesheet",id:S.hlcss})}),i},xe=e=>{const t=r.shallowRef(f.globalConfig.editorExtensions.katex.instance);return r.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:i,editorExtensionsAttrs:o}=f.globalConfig;I.appendHandler("script",{...o.katex?.js,src:i.katex.js,id:S.katexjs,onload(){t.value=window.katex}},"katex"),I.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:i.katex.css,id:S.katexcss})}),t},U=new de.LRUCache({max:1e3,ttl:6e5}),Ee=e=>{const t=r.inject("editorId"),i=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:h,mermaidConfig:c}=f.globalConfig;let u=n.mermaid.instance;const s=r.shallowRef(-1),m=()=>{!e.noMermaid&&u&&(u.initialize(c({startOnLoad:!1,theme:i.value==="dark"?"dark":"default"})),s.value=s.value+1)};return r.watch(()=>i.value,()=>{U.clear(),m()}),r.onMounted(()=>{if(e.noMermaid||u)return;const a=n.mermaid.js;/\.mjs/.test(a)?(I.appendHandler("link",{...h.mermaid?.js,rel:"modulepreload",href:a,id:S.mermaidM}),import(a).then(d=>{u=d.default,m()}).catch(d=>{p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${d.message}`,error:d})})):I.appendHandler("script",{...h.mermaid?.js,src:a,id:S.mermaid,onload(){u=window.mermaid,m()}},"mermaid")}),{reRenderRef:s,replaceMermaid:async()=>{if(!e.noMermaid&&u){const a=o.value.querySelectorAll(`div.${f.prefix}-mermaid`),d=document.createElement("div"),v=document.body.offsetWidth>1366?document.body.offsetWidth:1366,g=document.body.offsetHeight>768?document.body.offsetHeight:768;d.style.width=v+"px",d.style.height=g+"px",d.style.position="fixed",d.style.zIndex="-10000",d.style.top="-10000";let b=a.length;b>0&&document.body.appendChild(d),await Promise.allSettled(Array.from(a).map(y=>(async w=>{if(w.dataset.closed==="false")return!1;const E=w.innerText;let R=U.get(E);if(!R){const C=N.randomId();let A={svg:""};try{A=await u.render(C,E,d),R=await e.sanitizeMermaid(A.svg);const $=document.createElement("p");$.className=`${f.prefix}-mermaid`,$.setAttribute("data-processed",""),$.setAttribute("data-content",E),$.innerHTML=R,$.children[0]?.removeAttribute("height"),U.set(E,$.innerHTML),w.dataset.line!==void 0&&($.dataset.line=w.dataset.line),w.replaceWith($)}catch($){p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:$.message,error:$})}--b===0&&d.remove()}})(y)))}}}},$e=(e,t)=>{t=t||{};const i=3,o=t.marker||"!",n=o.charCodeAt(0),h=o.length;let c="",u="";const s=(l,a,d,v,g)=>{const b=l[a];return b.type==="admonition_open"?l[a].attrPush(["class",`${f.prefix}-admonition ${f.prefix}-admonition-${b.info}`]):b.type==="admonition_title_open"&&l[a].attrPush(["class",`${f.prefix}-admonition-title`]),g.renderToken(l,a,d)},m=l=>{const a=l.trim().split(" ",2);u="",c=a[0],a.length>1&&(u=l.substring(c.length+2))};e.block.ruler.before("code","admonition",(l,a,d,v)=>{let g,b,y,T=!1,w=l.bMarks[a]+l.tShift[a],E=l.eMarks[a];if(n!==l.src.charCodeAt(w))return!1;for(g=w+1;g<=E&&o[(g-w)%h]===l.src[g];g++);const R=Math.floor((g-w)/h);if(R!==i)return!1;g-=(g-w)%h;const C=l.src.slice(w,g),A=l.src.slice(g,E);if(m(A),v)return!0;for(b=a;b++,!(b>=d||(w=l.bMarks[b]+l.tShift[b],E=l.eMarks[b],w<E&&l.sCount[b]<l.blkIndent));)if(n===l.src.charCodeAt(w)&&!(l.sCount[b]-l.blkIndent>=4)){for(g=w+1;g<=E&&o[(g-w)%h]===l.src[g];g++);if(!(Math.floor((g-w)/h)<R)&&(g-=(g-w)%h,g=l.skipSpaces(g),!(g<E))){T=!0;break}}const $=l.parentType,H=l.lineMax;return l.parentType="root",l.lineMax=b,y=l.push("admonition_open","div",1),y.markup=C,y.block=!0,y.info=c,y.map=[a,b],u&&(y=l.push("admonition_title_open","p",1),y.markup=C+" "+c,y.map=[a,b],y=l.push("inline","",0),y.content=u,y.map=[a,l.line-1],y.children=[],y=l.push("admonition_title_close","p",-1),y.markup=C+" "+c),l.md.block.tokenize(l,a+1,b),y=l.push("admonition_close","div",-1),y.markup=l.src.slice(w,g),y.block=!0,l.parentType=$,l.lineMax=H,l.line=b+(T?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},z=(e,t)=>{const i=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const n=e.attrIndex(o[0]);n<0?i.push(o):(i[n]=i[n].slice(),i[n][1]+=` ${o[1]}`)}),i},Ie=(e,t)=>{const i=e.renderer.rules.fence,o=e.utils.unescapeAll,n=/\[(\w*)(?::([\w ]*))?\]/,h=/::(open|close)/,c=a=>a.info?o(a.info).trim():"",u=a=>{const d=c(a),[v=null,g=""]=(n.exec(d)||[]).slice(1);return[v,g]},s=a=>{const d=c(a);return d?d.split(/(\s+)/g)[0]:""},m=a=>{const d=a.info.match(h)||[],v=d[1]==="open"||d[1]!=="close"&&t.codeFoldable&&a.content.trim().split(`
|
|
2
|
+
`).length<t.autoFoldThreshold,g=d[1]||t.codeFoldable?"details":"div",b=d[1]||t.codeFoldable?"summary":"div";return{open:v,tagContainer:g,tagHeader:b}},l=(a,d,v,g,b)=>{if(a[d].hidden)return"";const y=t.usedLanguageTextRef.value?.copyCode.text,T=t.customIconRef.value.copy||y,w=!!t.customIconRef.value.copy,E=`<span class="${f.prefix}-collapse-tips">${I.StrIcon("collapse-tips",t.customIconRef.value)}</span>`,[R]=u(a[d]);if(R===null){const{open:x,tagContainer:k,tagHeader:G}=m(a[d]),M=[["class",`${f.prefix}-code`]];x&&M.push(["open",""]);const W={attrs:z(a[d],M)};a[d].info=a[d].info.replace(h,"");const O=i(a,d,v,g,b);return`
|
|
3
|
+
<${k} ${b.renderAttrs(W)}>
|
|
4
|
+
<${G} class="${f.prefix}-code-head">
|
|
5
5
|
<div class="${f.prefix}-code-flag"><span></span><span></span><span></span></div>
|
|
6
6
|
<div class="${f.prefix}-code-action">
|
|
7
7
|
<span class="${f.prefix}-code-lang">${e.utils.escapeHtml(a[d].info.trim())}</span>
|
|
8
|
-
<span class="${f.prefix}-copy-button" data-tips="${y}"${w?" data-is-icon=true":""}>${
|
|
8
|
+
<span class="${f.prefix}-copy-button" data-tips="${y}"${w?" data-is-icon=true":""}>${T}</span>
|
|
9
9
|
${t.extraTools instanceof Function?t.extraTools({lang:a[d].info.trim()}):t.extraTools||""}
|
|
10
|
-
${
|
|
10
|
+
${k==="details"?E:""}
|
|
11
11
|
</div>
|
|
12
|
-
</${
|
|
13
|
-
${
|
|
14
|
-
</${
|
|
15
|
-
`}let
|
|
12
|
+
</${G}>
|
|
13
|
+
${O}
|
|
14
|
+
</${k}>
|
|
15
|
+
`}let C,A,$,H,F="",P="",L="";const{open:D,tagContainer:_,tagHeader:j}=m(a[d]),B=[["class",`${f.prefix}-code`]];D&&B.push(["open",""]);const V={attrs:z(a[d],B)};for(let x=d;x<a.length&&(C=a[x],[A,$]=u(C),A===R);x++){C.info=C.info.replace(n,"").replace(h,""),C.hidden=!0;const k=`${f.prefix}-codetab-${t.editorId}-${d}-${x-d}`;H=x-d>0?"":"checked",F+=`
|
|
16
16
|
<li>
|
|
17
17
|
<input
|
|
18
18
|
type="radio"
|
|
19
|
-
id="label-${f.prefix}-codetab-label-1-${t.editorId}-${d}-${
|
|
19
|
+
id="label-${f.prefix}-codetab-label-1-${t.editorId}-${d}-${x-d}"
|
|
20
20
|
name="${f.prefix}-codetab-label-${t.editorId}-${d}"
|
|
21
|
-
class="${
|
|
22
|
-
${
|
|
21
|
+
class="${k}"
|
|
22
|
+
${H}
|
|
23
23
|
>
|
|
24
24
|
<label
|
|
25
|
-
for="label-${f.prefix}-codetab-label-1-${t.editorId}-${d}-${
|
|
26
|
-
onclick="this.getRootNode().querySelectorAll('.${
|
|
25
|
+
for="label-${f.prefix}-codetab-label-1-${t.editorId}-${d}-${x-d}"
|
|
26
|
+
onclick="this.getRootNode().querySelectorAll('.${k}').forEach(e => e.click())"
|
|
27
27
|
>
|
|
28
|
-
${e.utils.escapeHtml(
|
|
28
|
+
${e.utils.escapeHtml($||s(C))}
|
|
29
29
|
</label>
|
|
30
|
-
</li>`,
|
|
30
|
+
</li>`,P+=`
|
|
31
31
|
<div role="tabpanel">
|
|
32
32
|
<input
|
|
33
33
|
type="radio"
|
|
34
34
|
name="${f.prefix}-codetab-pre-${t.editorId}-${d}"
|
|
35
|
-
class="${
|
|
36
|
-
${
|
|
35
|
+
class="${k}"
|
|
36
|
+
${H}
|
|
37
37
|
role="presentation">
|
|
38
|
-
${i(a,
|
|
39
|
-
</div>`,
|
|
38
|
+
${i(a,x,v,g,b)}
|
|
39
|
+
</div>`,L+=`
|
|
40
40
|
<input
|
|
41
41
|
type="radio"
|
|
42
42
|
name="${f.prefix}-codetab-lang-${t.editorId}-${d}"
|
|
43
|
-
class="${
|
|
44
|
-
${
|
|
43
|
+
class="${k}"
|
|
44
|
+
${H}
|
|
45
45
|
role="presentation">
|
|
46
|
-
<span class=${f.prefix}-code-lang role="note">${e.utils.escapeHtml(s(
|
|
47
|
-
<${
|
|
48
|
-
<${
|
|
46
|
+
<span class=${f.prefix}-code-lang role="note">${e.utils.escapeHtml(s(C))}</span>`}return`
|
|
47
|
+
<${_} ${b.renderAttrs(V)}>
|
|
48
|
+
<${j} class="${f.prefix}-code-head">
|
|
49
49
|
<div class="${f.prefix}-code-flag">
|
|
50
|
-
<ul class="${f.prefix}-codetab-label" role="tablist">${
|
|
50
|
+
<ul class="${f.prefix}-codetab-label" role="tablist">${F}</ul>
|
|
51
51
|
</div>
|
|
52
52
|
<div class="${f.prefix}-code-action">
|
|
53
|
-
<span class="${f.prefix}-codetab-lang">${
|
|
54
|
-
<span class="${f.prefix}-copy-button" data-tips="${y}"${w?" data-is-icon=true":""}>${
|
|
53
|
+
<span class="${f.prefix}-codetab-lang">${L}</span>
|
|
54
|
+
<span class="${f.prefix}-copy-button" data-tips="${y}"${w?" data-is-icon=true":""}>${T}</span>
|
|
55
55
|
${t.extraTools instanceof Function?t.extraTools({lang:a[d].info.trim()}):t.extraTools||""}
|
|
56
|
-
${
|
|
56
|
+
${_==="details"?E:""}
|
|
57
57
|
</div>
|
|
58
|
-
</${
|
|
59
|
-
${
|
|
60
|
-
</${
|
|
61
|
-
`};e.renderer.rules.fence=l,e.renderer.rules.code_block=l},ke=(e,t)=>{const i=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,n,h,c,u)=>{const s=o[n],m=s.content.trim();if(s.info==="echarts"){if(s.attrSet("class",`${f.prefix}-echarts`),s.attrSet("data-echarts-theme",t.themeRef.value),s.map&&s.level===0){const l=s.map[1]-1,d=!!c.srcLines[l]?.trim()?.startsWith("```");s.attrSet("data-closed",`${d}`),s.attrSet("data-line",String(s.map[0]))}return`<div ${u.renderAttrs(s)} style="width: 100%; aspect-ratio: 4 / 3;">${e.utils.escapeHtml(m)}</div>`}return i(o,n,h,c,u)}},Te=(e,t)=>{e.renderer.rules.heading_open=(i,o)=>{const n=i[o],h=i[o+1].children?.reduce((u,s)=>u+(["text","code_inline","math_inline"].includes(s.type)&&s.content||""),"")||"",c=n.markup.length;return t.headsRef.value.push({text:h,level:c,line:n.map[0],currentToken:n,nextToken:i[o+1]}),n.map&&n.level===0&&n.attrSet("id",t.mdHeadingId({text:h,level:c,index:t.headsRef.value.length,currentToken:n,nextToken:i[o+1]})),e.renderer.renderToken(i,o,t)},e.renderer.rules.heading_close=(i,o,n,h,c)=>c.renderToken(i,o,n)},
|
|
62
|
-
`:"")+t.getLines(i+1,s,t.tShift[i],!0)+(u&&u.trim()?u:""),g.map=[i,t.line],g.markup=v.open,!0}return!1},Ae=(e,{katexRef:t,inlineDelimiters:i,blockDelimiters:o})=>{const n=(c,u,s,m,l)=>{const a=c[u],d={attrs:
|
|
63
|
-
`)}))),
|
|
64
|
-
`)}))},
|
|
65
|
-
`),v=d[Number(a)].replace(
|
|
66
|
-
`))):p.bus.emit(i,p.TASK_STATE_CHANGED,a+1,v)};c.forEach(s=>{s.addEventListener("click",u)}),n=()=>{c.forEach(s=>{s.removeEventListener("click",u)})}};r.onBeforeUnmount(()=>{n()}),r.watch([t],()=>{n(),r.nextTick(h)},{immediate:!0})},Ke=(e,t,i)=>{const o=r.inject("setting"),n=()=>{r.nextTick(()=>{e.onRemount?.()})},h=c=>{c&&n()};r.watch([t,i],n),r.watch(()=>o.value.preview,h),r.watch(()=>o.value.htmlPreview,h),r.onMounted(n)},
|
|
58
|
+
</${j}>
|
|
59
|
+
${P}
|
|
60
|
+
</${_}>
|
|
61
|
+
`};e.renderer.rules.fence=l,e.renderer.rules.code_block=l},ke=(e,t)=>{const i=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,n,h,c,u)=>{const s=o[n],m=s.content.trim();if(s.info==="echarts"){if(s.attrSet("class",`${f.prefix}-echarts`),s.attrSet("data-echarts-theme",t.themeRef.value),s.map&&s.level===0){const l=s.map[1]-1,d=!!c.srcLines[l]?.trim()?.startsWith("```");s.attrSet("data-closed",`${d}`),s.attrSet("data-line",String(s.map[0]))}return`<div ${u.renderAttrs(s)} style="width: 100%; aspect-ratio: 4 / 3;">${e.utils.escapeHtml(m)}</div>`}return i(o,n,h,c,u)}},Te=(e,t)=>{e.renderer.rules.heading_open=(i,o)=>{const n=i[o],h=i[o+1].children?.reduce((u,s)=>u+(["text","code_inline","math_inline"].includes(s.type)&&s.content||""),"")||"",c=n.markup.length;return t.headsRef.value.push({text:h,level:c,line:n.map[0],currentToken:n,nextToken:i[o+1]}),n.map&&n.level===0&&n.attrSet("id",t.mdHeadingId({text:h,level:c,index:t.headsRef.value.length,currentToken:n,nextToken:i[o+1]})),e.renderer.renderToken(i,o,t)},e.renderer.rules.heading_close=(i,o,n,h,c)=>c.renderToken(i,o,n)},K={block:[{open:"$$",close:"$$"},{open:"\\[",close:"\\]"}],inline:[{open:"$$",close:"$$"},{open:"$",close:"$"},{open:"\\[",close:"\\]"},{open:"\\(",close:"\\)"}]},Se=e=>(t,i)=>{const o=e.delimiters;let n,h,c;for(const u of o)if(t.src.startsWith(u.open,t.pos)){const s=t.pos+u.open.length;for(n=s;(n=t.src.indexOf(u.close,n))!==-1;){for(c=n-1;t.src[c]==="\\";)c-=1;if((n-c)%2===1)break;n+=u.close.length}if(n===-1)return i||(t.pending+=u.open),t.pos=s,!0;if(n-s===0)return i||(t.pending+=u.open+u.close),t.pos=s+u.close.length,!0;if(!i){const m=t.src.slice(s,n);h=t.push("math_inline","math",0),h.markup=u.open,h.content=m}return t.pos=n+u.close.length,!0}return!1},Re=e=>(t,i,o,n)=>{const h=e.delimiters;let c,u,s,m,l=!1,a=t.bMarks[i]+t.tShift[i],d=t.eMarks[i];for(const v of h)if(t.src.slice(a,a+v.open.length)===v.open&&t.src.slice(d-v.close.length,d)===v.close){if(a+=v.open.length,c=t.src.slice(a,d),n)return!0;for(c.trim().slice(-v.close.length)===v.close&&(c=c.trim().slice(0,-v.close.length),l=!0),s=i;!l&&(s++,!(s>=o||(a=t.bMarks[s]+t.tShift[s],d=t.eMarks[s],a<d&&t.tShift[s]<t.blkIndent)));)t.src.slice(a,d).trim().slice(-v.close.length)===v.close&&(m=t.src.slice(0,d).lastIndexOf(v.close),u=t.src.slice(a,m),l=!0);t.line=s+1;const g=t.push("math_block","math",0);return g.block=!0,g.content=(c&&c.trim()?c+`
|
|
62
|
+
`:"")+t.getLines(i+1,s,t.tShift[i],!0)+(u&&u.trim()?u:""),g.map=[i,t.line],g.markup=v.open,!0}return!1},Ae=(e,{katexRef:t,inlineDelimiters:i,blockDelimiters:o})=>{const n=(c,u,s,m,l)=>{const a=c[u],d={attrs:z(a,[["class",`${f.prefix}-katex-inline`]])};if(t.value){const v=t.value.renderToString(a.content,f.globalConfig.katexConfig({throwOnError:!1}));return`<span ${l.renderAttrs(d)} data-processed>${v}</span>`}else return`<span ${l.renderAttrs(d)}>${a.content}</span>`},h=(c,u,s,m,l)=>{const a=c[u],d={attrs:z(a,[["class",`${f.prefix}-katex-block`]])};if(t.value){const v=t.value.renderToString(a.content,f.globalConfig.katexConfig({throwOnError:!1,displayMode:!0}));return`<p ${l.renderAttrs(d)} data-processed>${v}</p>`}else return`<p ${l.renderAttrs(d)}>${a.content}</p>`};e.inline.ruler.before("escape","math_inline",Se({delimiters:i||K.inline})),e.block.ruler.after("blockquote","math_block",Re({delimiters:o||K.block}),{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.math_inline=n,e.renderer.rules.math_block=h},He=(e,t)=>{const i=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,n,h,c,u)=>{const s=o[n],m=s.content.trim();if(s.info==="mermaid"){if(s.attrSet("class",`${f.prefix}-mermaid`),s.attrSet("data-mermaid-theme",t.themeRef.value),s.map&&s.level===0){const a=s.map[1]-1,v=!!c.srcLines[a]?.trim()?.startsWith("```");s.attrSet("data-closed",`${v}`),s.attrSet("data-line",String(s.map[0]))}const l=U.get(m);return l?(s.attrSet("data-processed",""),s.attrSet("data-content",m),`<p ${u.renderAttrs(s)}>${l}</p>`):`<div ${u.renderAttrs(s)}>${e.utils.escapeHtml(m)}</div>`}return i(o,n,h,c,u)}},Z=(e,t,i)=>{const o=e.attrIndex(t),n=[t,i];o<0?e.attrPush(n):(e.attrs=e.attrs||[],e.attrs[o]=n)},Fe=e=>e.type==="inline",Me=e=>e.type==="paragraph_open",Pe=e=>e.type==="list_item_open",Le=e=>e.content.indexOf("[ ] ")===0||e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0,_e=(e,t)=>Fe(e[t])&&Me(e[t-1])&&Pe(e[t-2])&&Le(e[t]),Ne=(e,t)=>{const i=e[t].level-1;for(let o=t-1;o>=0;o--)if(e[o].level===i)return o;return-1},je=e=>{const t=new e("html_inline","",0);return t.content="<label>",t},Oe=e=>{const t=new e("html_inline","",0);return t.content="</label>",t},De=(e,t,i)=>{const o=new i("html_inline","",0);return o.content='<label class="task-list-item-label" for="'+t+'">'+e+"</label>",o.attrs=[["for",t]],o},Be=(e,t,i)=>{const o=new t("html_inline","",0),n=i.enabled?" ":' disabled="" ';return e.content.indexOf("[ ] ")===0?o.content='<input class="task-list-item-checkbox"'+n+'type="checkbox">':(e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0)&&(o.content='<input class="task-list-item-checkbox" checked=""'+n+'type="checkbox">'),o},Ve=(e,t,i)=>{if(e.children=e.children||[],e.children.unshift(Be(e,t,i)),e.children[1].content=e.children[1].content.slice(3),e.content=e.content.slice(3),i.label)if(i.labelAfter){e.children.pop();const o="task-item-"+Math.ceil(Math.random()*(1e4*1e3)-1e3);e.children[0].content=e.children[0].content.slice(0,-1)+' id="'+o+'">',e.children.push(De(e.content,o,t))}else e.children.unshift(je(t)),e.children.push(Oe(t))},Ge=(e,t={})=>{e.core.ruler.after("inline","github-task-lists",i=>{const o=i.tokens;for(let n=2;n<o.length;n++)_e(o,n)&&(Ve(o[n],i.Token,t),Z(o[n-2],"class","task-list-item"+(t.enabled?" enabled":" ")),Z(o[Ne(o,n-2)],"class","contains-task-list"))})},Ue=e=>{e.core.ruler.push("init-line-number",t=>(t.tokens.forEach(i=>{i.map&&(i.attrs||(i.attrs=[]),i.attrs.push(["data-line",i.map[0].toString()]))}),!0))},qe=(e,t)=>{const{editorConfig:i,markdownItConfig:o,markdownItPlugins:n,editorExtensions:h}=f.globalConfig,c=r.inject("editorId"),u=r.inject("language"),s=r.inject("usedLanguageText"),m=r.inject("showCodeRowNumber"),l=r.inject("theme"),a=r.inject("customIcon"),d=r.inject("rootRef"),v=r.inject("setting"),g=r.ref([]),b=Ce(e),y=xe(e),{reRenderRef:T,replaceMermaid:w}=Ee(e),{reRenderEcharts:E,replaceEcharts:R}=we(e),C=ae({html:!0,breaks:!0,linkify:!0});o(C,{editorId:c});const A=[{type:"image",plugin:ie,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:$e,options:{}},{type:"taskList",plugin:Ge,options:{}},{type:"heading",plugin:Te,options:{mdHeadingId:e.mdHeadingId,headsRef:g}},{type:"code",plugin:Ie,options:{editorId:c,usedLanguageTextRef:s,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,customIconRef:a}},{type:"sub",plugin:le,options:{}},{type:"sup",plugin:se,options:{}}];e.noKatex||A.push({type:"katex",plugin:Ae,options:{katexRef:y}}),e.noMermaid||A.push({type:"mermaid",plugin:He,options:{themeRef:l}}),e.noEcharts||A.push({type:"echarts",plugin:ke,options:{themeRef:l}}),n(A,{editorId:c}).forEach(x=>{C.use(x.plugin,x.options)});const $=C.options.highlight;C.set({highlight:(x,k,G)=>{if($){const O=$(x,k,G);if(O)return O}let M;!e.noHighlight&&b.value?b.value.getLanguage(k)?M=b.value.highlight(x,{language:k,ignoreIllegals:!0}).value:M=b.value.highlightAuto(x).value:M=C.utils.escapeHtml(x);const W=m?ce.generateCodeRowNumber(M.replace(/^\n+|\n+$/g,""),x.replace(/^\n+|\n+$/g,"")):`<span class="${f.prefix}-code-block">${M.replace(/^\n+|\n+$/g,"")}</span>`;return`<pre><code class="language-${k}" language=${k}>${W}</code></pre>`}}),Ue(C);const H=r.ref(`_article-key_${N.randomId()}`),F=r.ref(e.sanitize(C.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
63
|
+
`)})));let P=()=>{},L=()=>{};const D=()=>{const x=d.value?.querySelectorAll(`#${c} p.${f.prefix}-mermaid:not([data-closed=false])`);L(),L=I.copyMermaid(x,{customIcon:a.value}),h.mermaid?.enableZoom&&(P(),P=I.zoomMermaid(x,{customIcon:a.value}))},_=()=>{p.bus.emit(c,p.BUILD_FINISHED,F.value),e.onHtmlChanged(F.value),e.onGetCatalog(g.value),p.bus.emit(c,p.CATALOG_CHANGED,g.value),r.nextTick(()=>{w().then(D),R()})},j=()=>{g.value=[],F.value=e.sanitize(C.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
64
|
+
`)}))},B=r.computed(()=>(e.noKatex||!!y.value)&&(e.noHighlight||!!b.value));let V=-1;return r.watch([r.toRef(e,"modelValue"),B,T,u],()=>{V=window.setTimeout(()=>{j()},t?0:i.renderDelay)}),r.watch(()=>v.value.preview,()=>{v.value.preview&&r.nextTick(()=>{w().then(D),R(),p.bus.emit(c,p.CATALOG_CHANGED,g.value)})}),r.watch([F,E],()=>{_()}),r.onMounted(_),r.onMounted(()=>{p.bus.on(c,{name:p.PUSH_CATALOG,callback(){p.bus.emit(c,p.CATALOG_CHANGED,g.value)}}),p.bus.on(c,{name:p.RERENDER,callback:()=>{H.value=`_article-key_${N.randomId()}`,j()}})}),r.onBeforeUnmount(()=>{P(),L(),clearTimeout(V)}),{html:F,key:H}},ze=(e,t)=>{const i=r.inject("editorId"),o=r.inject("setting"),{noImgZoomIn:n}=e,h=N.debounce(()=>{const c=document.querySelectorAll(`#${i}-preview img:not(.not-zoom):not(.medium-zoom-image)`);c.length!==0&&ue(c,{background:"#00000073"})});r.onMounted(async()=>{!n&&o.value.preview&&await h()}),r.watch([t,()=>o.value.preview],async()=>{!n&&o.value.preview&&await h()})},J={checked:{regexp:/- \[x\]/,value:"- [ ]"},unChecked:{regexp:/- \[\s\]/,value:"- [x]"}},We=(e,t)=>{const i=r.inject("editorId"),o=r.inject("rootRef");let n=()=>{};const h=()=>{if(!o.value)return!1;const c=o.value.querySelectorAll(".task-list-item.enabled"),u=s=>{s.preventDefault();const m=s.target.checked?"unChecked":"checked",l=s.target.parentElement?.dataset.line;if(!l)return;const a=Number(l),d=e.modelValue.split(`
|
|
65
|
+
`),v=d[Number(a)].replace(J[m].regexp,J[m].value);e.previewOnly?(d[Number(a)]=v,e.onChange(d.join(`
|
|
66
|
+
`))):p.bus.emit(i,p.TASK_STATE_CHANGED,a+1,v)};c.forEach(s=>{s.addEventListener("click",u)}),n=()=>{c.forEach(s=>{s.removeEventListener("click",u)})}};r.onBeforeUnmount(()=>{n()}),r.watch([t],()=>{n(),r.nextTick(h)},{immediate:!0})},Ke=(e,t,i)=>{const o=r.inject("setting"),n=()=>{r.nextTick(()=>{e.onRemount?.()})},h=c=>{c&&n()};r.watch([t,i],n),r.watch(()=>o.value.preview,h),r.watch(()=>o.value.htmlPreview,h),r.onMounted(n)},ee={modelValue:{type:String,default:""},onChange:{type:Function,default:()=>{}},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},codeFoldable:{type:Boolean},autoFoldThreshold:{type:Number},onRemount:{type:Function},noEcharts:{type:Boolean}},Ze={...ee,updateModelValue:{type:Function,default:()=>{}},placeholder:{type:String,default:""},scrollAuto:{type:Boolean},autofocus:{type:Boolean},readonly:{type:Boolean},maxlength:{type:Number},autoDetectCode:{type:Boolean},onBlur:{type:Function,default:()=>{}},onFocus:{type:Function,default:()=>{}},completions:{type:Array},onInput:{type:Function},onDrop:{type:Function,default:()=>{}},inputBoxWidth:{type:String},oninputBoxWidthChange:{type:Function},transformImgUrl:{type:Function,default:e=>e},catalogLayout:{type:String},catalogMaxDepth:{type:Number}},Je=e=>{const i=new DOMParser().parseFromString(e,"text/html");return Array.from(i.body.childNodes)},Xe=(e,t)=>{const i=[],o=[];if(e.forEach((n,h)=>{const c=t[h];if(!c){i.push({index:h,newNode:n});return}(n.nodeType!==c.nodeType||n.textContent!==c.textContent||n.nodeType===1&&n.outerHTML!==c.outerHTML)&&i.push({index:h,newNode:n})}),t.length>e.length)for(let n=e.length;n<t.length;n++)o.push(t[n]);return{updates:i,deletes:o}},X=r.defineComponent({name:"UpdateOnDemand",props:{html:{type:String,required:!0}},setup(e){const t=r.inject("editorId"),i=r.inject("previewTheme"),o=r.inject("showCodeRowNumber"),n=r.ref(),h=e.html,c=(u,s)=>{n.value&&(s.forEach(m=>{m.remove()}),u.forEach(({index:m,newNode:l})=>{const a=n.value?.childNodes[m];a?n.value?.replaceChild(l.cloneNode(!0),a):n.value?.appendChild(l.cloneNode(!0))}))};return r.watch(()=>e.html,u=>{const s=Je(u),m=Array.from(n.value?.childNodes||[]),{updates:l,deletes:a}=Xe(s,m);c(l,a)}),()=>r.createVNode("div",{id:`${t}-preview`,class:[`${f.prefix}-preview`,`${i?.value}-theme`,o&&`${f.prefix}-scrn`],innerHTML:h,ref:n},null)}}),te=r.defineComponent({name:"ContentPreview",props:ee,setup(e){const t=r.inject("editorId"),i=r.inject("setting"),{html:o,key:n}=qe(e,e.previewOnly);return ye(e,o,n),ze(e,o),We(e,o),Ke(e,o,n),()=>r.createVNode(r.Fragment,null,[i.value.preview&&(e.previewOnly?r.createVNode(X,{key:n.value,html:o.value},null):r.createVNode("div",{id:`${t}-preview-wrapper`,class:`${f.prefix}-preview-wrapper`,key:"content-preview-wrapper"},[r.createVNode(X,{key:n.value,html:o.value},null)])),i.value.htmlPreview&&r.createVNode("div",{id:`${t}-html-wrapper`,class:`${f.prefix}-preview-wrapper`,key:"html-preview-wrapper"},[r.createVNode("div",{class:`${f.prefix}-html`},[o.value])])])}}),Ye=({text:e})=>e,ne={modelValue:{type:String,default:""},onChange:{type:Function,default:void 0},theme:{type:String,default:"light"},class:{type:String,default:""},language:{type:String,default:"zh-CN"},onHtmlChanged:{type:Function,default:void 0},onGetCatalog:{type:Function,default:void 0},editorId:{type:String,default:void 0},id:{type:String,default:void 0},showCodeRowNumber:{type:Boolean,default:!0},previewTheme:{type:String,default:"default"},style:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:Ye},sanitize:{type:Function,default:e=>e},noMermaid:{type:Boolean,default:!1},noKatex:{type:Boolean,default:!1},codeTheme:{type:String,default:"atom"},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)},codeFoldable:{type:Boolean,default:!0},autoFoldThreshold:{type:Number,default:30},onRemount:{type:Function,default:void 0},noEcharts:{type:Boolean,default:!1}},Qe={...ne,onSave:{type:Function,default:void 0},onUploadImg:{type:Function,default:void 0},pageFullscreen:{type:Boolean,default:!1},preview:{type:Boolean,default:!0},htmlPreview:{type:Boolean,default:!1},toolbars:{type:Array,default:f.allToolbar},floatingToolbars:{type:Array,default:[]},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],default:void 0},onError:{type:Function,default:void 0},footers:{type:Array,default:f.allFooter},scrollAuto:{type:Boolean,default:!0},defFooters:{type:[String,Object],default:void 0},noUploadImg:{type:Boolean,default:!1},autoFocus:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},readOnly:{type:Boolean,default:!1},maxLength:{type:Number,default:void 0},autoDetectCode:{type:Boolean,default:!1},onBlur:{type:Function,default:void 0},onFocus:{type:Function,default:void 0},completions:{type:Array,default:void 0},showToolbarName:{type:Boolean,default:!1},onInput:{type:Function,default:void 0},onDrop:{type:Function,default:void 0},inputBoxWidth:{type:String,default:"50%"},oninputBoxWidthChange:{type:Function,default:void 0},transformImgUrl:{type:Function,default:e=>e},catalogLayout:{type:String,default:"fixed"},catalogMaxDepth:{type:Number,default:void 0}},oe=["onHtmlChanged","onGetCatalog","onChange","onRemount","update:modelValue"],et=[...oe,"onSave","onUploadImg","onError","onBlur","onFocus","onInput","onDrop","oninputBoxWidthChange"],tt=(e,t,i)=>{const{editorId:o}=i,n={rerender(){p.bus.emit(o,p.RERENDER)}};t.expose(n)},q=r.defineComponent({name:"MdPreview",props:ne,emits:oe,setup(e,t){const{noKatex:i,noMermaid:o,noHighlight:n}=e,h=r.ref(),c=Q(e);return Y(e,{rootRef:h,editorId:c}),tt(e,t,{editorId:c}),r.onBeforeUnmount(()=>{p.bus.clear(c)}),()=>r.createVNode("div",{id:c,class:[f.prefix,e.class,e.theme==="dark"&&`${f.prefix}-dark`,`${f.prefix}-previewOnly`],style:e.style,ref:h},[r.createVNode(te,{modelValue:e.modelValue,onChange:u=>{e.onChange?.(u),t.emit("onChange",u),t.emit("update:modelValue",u)},onHtmlChanged:u=>{e.onHtmlChanged?.(u),t.emit("onHtmlChanged",u)},onGetCatalog:u=>{e.onGetCatalog?.(u),t.emit("onGetCatalog",u)},mdHeadingId:e.mdHeadingId,noMermaid:o,sanitize:e.sanitize,noKatex:i,formatCopiedText:e.formatCopiedText,noHighlight:n,noImgZoomIn:e.noImgZoomIn,previewOnly:!0,sanitizeMermaid:e.sanitizeMermaid,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,onRemount:()=>{e.onRemount?.(),t.emit("onRemount")},noEcharts:e.noEcharts},null)])}});q.install=e=>(e.component(q.name,q),e);exports.CDN_IDS=S;exports.ContentPreview=te;exports.MdPreview=q;exports.contentProps=Ze;exports.editorEmits=et;exports.editorProps=Qe;exports.useCatalog=ve;exports.useConfig=ge;exports.useEditorId=Q;exports.useErrorCatcher=he;exports.useExpansion=fe;exports.useExpose=be;exports.useOnSave=me;exports.useProvide=pe;
|
package/lib/es/chunks/dom.mjs
CHANGED
|
@@ -1,119 +1,159 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import I from "@vavt/copy2clipboard";
|
|
2
|
+
import { p as i } from "./config.mjs";
|
|
3
|
+
const j = {
|
|
4
|
+
copy: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy ${i}-icon"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,
|
|
5
|
+
"collapse-tips": `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-chevron-left ${i}-icon"><circle cx="12" cy="12" r="10"/><path d="m14 16-4-4 4-4"/></svg>`,
|
|
6
|
+
pin: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin ${i}-icon"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg>`,
|
|
7
|
+
"pin-off": `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin-off ${i}-icon"><path d="M12 17v5"/><path d="M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89"/><path d="m2 2 20 20"/><path d="M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11"/></svg>`,
|
|
8
|
+
check: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check ${i}-icon"><path d="M20 6 9 17l-5-5"/></svg>`
|
|
9
|
+
}, p = (d, s) => typeof s[d] == "string" ? s[d] : j[d], z = (d, s) => {
|
|
10
|
+
const e = (c) => {
|
|
11
|
+
const t = d.parentElement || document.body, n = t.offsetWidth, r = t.offsetHeight, { clientWidth: l, clientHeight: u } = document.documentElement, a = c.offsetX, w = c.offsetY, g = (y) => {
|
|
12
|
+
let h = y.x + document.body.scrollLeft - document.body.clientLeft - a, m = y.y + document.body.scrollTop - document.body.clientTop - w;
|
|
13
|
+
h = h < 1 ? 1 : h < l - n - 1 ? h : l - n - 1, m = m < 1 ? 1 : m < u - r - 1 ? m : u - r - 1, s ? s(h, m) : (t.style.left = `${h}px`, t.style.top = `${m}px`);
|
|
12
14
|
};
|
|
13
|
-
document.addEventListener("mousemove",
|
|
15
|
+
document.addEventListener("mousemove", g);
|
|
14
16
|
const v = () => {
|
|
15
|
-
document.removeEventListener("mousemove",
|
|
17
|
+
document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", v);
|
|
16
18
|
};
|
|
17
19
|
document.addEventListener("mouseup", v);
|
|
18
20
|
};
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
+
return d.addEventListener("mousedown", e), () => {
|
|
22
|
+
d.removeEventListener("mousedown", e);
|
|
21
23
|
};
|
|
22
|
-
},
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
}, A = (d, s, e = "") => {
|
|
25
|
+
const c = document.getElementById(s.id);
|
|
26
|
+
if (c)
|
|
27
|
+
e !== "" && (Reflect.get(window, e) ? s.onload?.call(c, new Event("load")) : s.onload && c.addEventListener("load", s.onload));
|
|
26
28
|
else {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const n =
|
|
29
|
+
const t = { ...s };
|
|
30
|
+
t.onload = null;
|
|
31
|
+
const n = D(d, t);
|
|
30
32
|
s.onload && n.addEventListener("load", s.onload), document.head.appendChild(n);
|
|
31
33
|
}
|
|
32
|
-
},
|
|
33
|
-
document.getElementById(s.id)?.remove(),
|
|
34
|
-
},
|
|
35
|
-
const
|
|
36
|
-
return Object.keys(s).forEach((
|
|
37
|
-
s[
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
const
|
|
41
|
-
|
|
34
|
+
}, b = (d, s) => {
|
|
35
|
+
document.getElementById(s.id)?.remove(), A(d, s);
|
|
36
|
+
}, D = (d, s) => {
|
|
37
|
+
const e = document.createElement(d);
|
|
38
|
+
return Object.keys(s).forEach((c) => {
|
|
39
|
+
s[c] !== void 0 && (e[c] = s[c]);
|
|
40
|
+
}), e;
|
|
41
|
+
}, V = (d, s) => {
|
|
42
|
+
const e = /* @__PURE__ */ new Map();
|
|
43
|
+
return d?.forEach((c) => {
|
|
44
|
+
let t = c.querySelector(`.${i}-mermaid-action`);
|
|
45
|
+
t ? t.querySelector(`.${i}-mermaid-copy`) || t.insertAdjacentHTML(
|
|
46
|
+
"beforeend",
|
|
47
|
+
`<span class="${i}-mermaid-copy">${p("copy", s.customIcon)}</span>`
|
|
48
|
+
) : (c.insertAdjacentHTML(
|
|
49
|
+
"beforeend",
|
|
50
|
+
`<div class="${i}-mermaid-action"><span class="${i}-mermaid-copy">${p("copy", s.customIcon)}</span></div>`
|
|
51
|
+
), t = c.querySelector(`.${i}-mermaid-action`));
|
|
52
|
+
const n = t.querySelector(`.${i}-mermaid-copy`);
|
|
53
|
+
let r = -1;
|
|
54
|
+
const l = () => {
|
|
55
|
+
clearTimeout(r), I(c.dataset.content || "").then(() => {
|
|
56
|
+
n.innerHTML = p("check", s.customIcon);
|
|
57
|
+
}).catch(() => {
|
|
58
|
+
n.innerHTML = p("copy", s.customIcon);
|
|
59
|
+
}).finally(() => {
|
|
60
|
+
r = window.setTimeout(() => {
|
|
61
|
+
n.innerHTML = p("copy", s.customIcon);
|
|
62
|
+
}, 1500);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
n.addEventListener("click", l), e.set(c, {
|
|
66
|
+
removeClick: () => {
|
|
67
|
+
n.removeEventListener("click", l);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}), () => {
|
|
71
|
+
e.forEach(({ removeClick: c }) => {
|
|
72
|
+
c?.();
|
|
73
|
+
}), e.clear();
|
|
74
|
+
};
|
|
75
|
+
}, R = /* @__PURE__ */ (() => {
|
|
76
|
+
const d = (e) => {
|
|
77
|
+
if (!e)
|
|
42
78
|
return () => {
|
|
43
79
|
};
|
|
44
|
-
const
|
|
45
|
-
let
|
|
80
|
+
const c = e.firstChild;
|
|
81
|
+
let t = 1, n = 0, r = 0, l = !1, u, a, w, g = 1;
|
|
46
82
|
const v = () => {
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
),
|
|
53
|
-
},
|
|
54
|
-
if (
|
|
55
|
-
n =
|
|
56
|
-
else if (
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
) /
|
|
61
|
-
|
|
62
|
-
const M = (
|
|
63
|
-
n -=
|
|
83
|
+
c.style.transform = `translate(${n}px, ${r}px) scale(${t})`;
|
|
84
|
+
}, y = (o) => {
|
|
85
|
+
o.touches.length === 1 ? (l = !0, u = o.touches[0].clientX - n, a = o.touches[0].clientY - r) : o.touches.length === 2 && (w = Math.hypot(
|
|
86
|
+
o.touches[0].clientX - o.touches[1].clientX,
|
|
87
|
+
o.touches[0].clientY - o.touches[1].clientY
|
|
88
|
+
), g = t);
|
|
89
|
+
}, h = (o) => {
|
|
90
|
+
if (o.preventDefault(), l && o.touches.length === 1)
|
|
91
|
+
n = o.touches[0].clientX - u, r = o.touches[0].clientY - a, v();
|
|
92
|
+
else if (o.touches.length === 2) {
|
|
93
|
+
const E = Math.hypot(
|
|
94
|
+
o.touches[0].clientX - o.touches[1].clientX,
|
|
95
|
+
o.touches[0].clientY - o.touches[1].clientY
|
|
96
|
+
) / w, f = t;
|
|
97
|
+
t = g * (1 + (E - 1));
|
|
98
|
+
const M = (o.touches[0].clientX + o.touches[1].clientX) / 2, k = (o.touches[0].clientY + o.touches[1].clientY) / 2, H = c.getBoundingClientRect(), X = (M - H.left) / f, S = (k - H.top) / f;
|
|
99
|
+
n -= X * (t - f), r -= S * (t - f), v();
|
|
64
100
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
const L = 0.02,
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
n -= M /
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
101
|
+
}, m = () => {
|
|
102
|
+
l = !1;
|
|
103
|
+
}, $ = (o) => {
|
|
104
|
+
o.preventDefault();
|
|
105
|
+
const L = 0.02, E = t;
|
|
106
|
+
o.deltaY < 0 ? t += L : t = Math.max(0.1, t - L);
|
|
107
|
+
const f = c.getBoundingClientRect(), M = o.clientX - f.left, k = o.clientY - f.top;
|
|
108
|
+
n -= M / E * (t - E), r -= k / E * (t - E), v();
|
|
109
|
+
}, x = (o) => {
|
|
110
|
+
l = !0, u = o.clientX - n, a = o.clientY - r;
|
|
111
|
+
}, C = (o) => {
|
|
112
|
+
l && (n = o.clientX - u, r = o.clientY - a, v());
|
|
113
|
+
}, T = () => {
|
|
114
|
+
l = !1;
|
|
115
|
+
}, Y = () => {
|
|
116
|
+
l = !1;
|
|
81
117
|
};
|
|
82
|
-
return
|
|
83
|
-
|
|
118
|
+
return e.addEventListener("touchstart", y, { passive: !1 }), e.addEventListener("touchmove", h, { passive: !1 }), e.addEventListener("touchend", m), e.addEventListener("wheel", $, { passive: !1 }), e.addEventListener("mousedown", x), e.addEventListener("mousemove", C), e.addEventListener("mouseup", T), e.addEventListener("mouseleave", Y), () => {
|
|
119
|
+
e.removeEventListener("touchstart", y), e.removeEventListener("touchmove", h), e.removeEventListener("touchend", m), e.removeEventListener("wheel", $), e.removeEventListener("mousedown", x), e.removeEventListener("mousemove", C), e.removeEventListener("mouseup", T), e.removeEventListener("mouseleave", Y);
|
|
84
120
|
};
|
|
85
121
|
};
|
|
86
|
-
return (
|
|
87
|
-
const
|
|
88
|
-
return
|
|
89
|
-
let
|
|
90
|
-
|
|
122
|
+
return (e, c) => {
|
|
123
|
+
const t = /* @__PURE__ */ new Map();
|
|
124
|
+
return e?.forEach((n) => {
|
|
125
|
+
let r = n.querySelector(`.${i}-mermaid-action`);
|
|
126
|
+
r ? r.querySelector(`.${i}-mermaid-zoom`) || r.insertAdjacentHTML(
|
|
127
|
+
"beforeend",
|
|
128
|
+
`<span class="${i}-mermaid-zoom">${p("pin-off", c.customIcon)}</span>`
|
|
129
|
+
) : (n.insertAdjacentHTML(
|
|
91
130
|
"beforeend",
|
|
92
|
-
`<div class="${
|
|
93
|
-
),
|
|
94
|
-
const r = () => {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
131
|
+
`<div class="${i}-mermaid-action"><span class="${i}-mermaid-zoom">${p("pin-off", c.customIcon)}</span></div>`
|
|
132
|
+
), r = n.querySelector(`.${i}-mermaid-action`));
|
|
133
|
+
const l = r.querySelector(`.${i}-mermaid-zoom`), u = () => {
|
|
134
|
+
const a = t.get(n);
|
|
135
|
+
if (a?.removeEvent)
|
|
136
|
+
a.removeEvent(), n.removeAttribute("data-grab"), t.set(n, { removeClick: a.removeClick }), l.innerHTML = p("pin-off", c.customIcon);
|
|
98
137
|
else {
|
|
99
|
-
const
|
|
100
|
-
n.setAttribute("data-grab", ""),
|
|
138
|
+
const w = d(n);
|
|
139
|
+
n.setAttribute("data-grab", ""), t.set(n, { removeEvent: w, removeClick: a?.removeClick }), l.innerHTML = p("pin", c.customIcon);
|
|
101
140
|
}
|
|
102
141
|
};
|
|
103
|
-
|
|
104
|
-
removeClick: () =>
|
|
142
|
+
l.addEventListener("click", u), t.set(n, {
|
|
143
|
+
removeClick: () => l.removeEventListener("click", u)
|
|
105
144
|
});
|
|
106
145
|
}), () => {
|
|
107
|
-
|
|
108
|
-
n?.(),
|
|
109
|
-
}),
|
|
146
|
+
t.forEach(({ removeEvent: n, removeClick: r }) => {
|
|
147
|
+
n?.(), r?.();
|
|
148
|
+
}), t.clear();
|
|
110
149
|
};
|
|
111
150
|
};
|
|
112
151
|
})();
|
|
113
152
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
p as S,
|
|
154
|
+
A as a,
|
|
155
|
+
V as c,
|
|
156
|
+
z as k,
|
|
157
|
+
b as u,
|
|
158
|
+
R as z
|
|
119
159
|
};
|