md-editor-v3 6.5.6 → 7.0.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/MdEditor.cjs +1 -1
- package/lib/cjs/chunks/config.cjs +14 -1
- package/lib/cjs/chunks/index2.cjs +1 -1
- package/lib/cjs/chunks/index3.cjs +1 -1
- package/lib/cjs/chunks/index4.cjs +45 -45
- package/lib/cjs/chunks/index5.cjs +7 -2
- package/lib/es/MdEditor.mjs +5 -4
- package/lib/es/chunks/config.mjs +919 -69
- package/lib/es/chunks/event-bus.mjs +5 -5
- package/lib/es/chunks/index2.mjs +11 -11
- package/lib/es/chunks/index3.mjs +60 -57
- package/lib/es/chunks/index4.mjs +701 -635
- package/lib/es/chunks/index5.mjs +199 -32
- package/lib/preview.css +2 -2
- package/lib/style.css +4 -4
- package/lib/types/index.d.ts +12 -12
- package/package.json +3 -2
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";const r=require("vue"),O=require("@vavt/util"),m=require("./config.cjs"),h=require("./event-bus.cjs"),k=require("./dom.cjs"),ce=require("@vavt/copy2clipboard"),de=require("markdown-it"),ue=require("markdown-it-image-figures"),fe=require("markdown-it-sub"),me=require("markdown-it-sup"),pe=require("./index5.cjs"),he=require("medium-zoom"),H={hljs:`${m.prefix}-hljs`,hlcss:`${m.prefix}-hlCss`,prettier:`${m.prefix}-prettier`,prettierMD:`${m.prefix}-prettierMD`,cropperjs:`${m.prefix}-cropper`,croppercss:`${m.prefix}-cropperCss`,screenfull:`${m.prefix}-screenfull`,mermaidM:`${m.prefix}-mermaid-m`,mermaid:`${m.prefix}-mermaid`,katexjs:`${m.prefix}-katex`,katexcss:`${m.prefix}-katexCss`,echarts:`${m.prefix}-echarts`},W=(e,t)=>{h.bus.emit(e,h.REPLACE,t)},ge=(e,t,a)=>{const{editorId:o}=a,n=r.reactive({buildFinished:!1,html:""});r.watch(()=>e.modelValue,()=>{n.buildFinished=!1}),r.onMounted(()=>{h.bus.on(o,{name:h.BUILD_FINISHED,callback(u){n.buildFinished=!0,n.html=u}}),h.bus.on(o,{name:h.ON_SAVE,callback(){const u=new Promise(c=>{if(n.buildFinished)c(n.html);else{const d=f=>{c(f),h.bus.remove(o,h.BUILD_FINISHED,d)};h.bus.on(o,{name:h.BUILD_FINISHED,callback:d})}});e.onSave?e.onSave(e.modelValue,u):t.emit("onSave",e.modelValue,u)}})})},te=(e,{editorId:t,rootRef:a,setting:o})=>{const n=m.globalConfig.editorExtensions.highlight,u=m.globalConfig.editorExtensionsAttrs.highlight;r.provide("editorId",t),r.provide("rootRef",a),r.provide("theme",r.computed(()=>e.theme)),r.provide("language",r.computed(()=>e.language)),r.provide("highlight",r.computed(()=>{const{js:d}=n,f={...m.codeCss,...n.css},{js:l,css:s={}}=u||{},i=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,p=f[e.codeTheme]?f[e.codeTheme][i]:m.codeCss.atom[i],g=f[e.codeTheme]&&s[e.codeTheme]?s[e.codeTheme][i]:s.atom?s.atom[i]:{};return{js:{src:d,...l},css:{href:p,...g}}})),r.provide("showCodeRowNumber",e.showCodeRowNumber);const c=r.computed(()=>{const d={...m.staticTextDefault,...m.globalConfig.editorConfig.languageUserDefined};return O.deepMerge(O.deepClone(m.staticTextDefault["en-US"]),d[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}},ve=(e,t)=>(r.provide("tabWidth",e.tabWidth),r.provide("disabled",r.computed(()=>e.disabled)),r.provide("contentDisabled",r.computed(()=>e.disabled||e.readOnly)),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)),te(e,t)),be=e=>{const{noPrettier:t,noUploadImg:a}=e,{editorExtensions:o,editorExtensionsAttrs:n}=m.globalConfig,u=t||o.prettier.prettierInstance,c=t||o.prettier.parserMarkdownInstance,d=a||o.cropper.instance;r.onMounted(()=>{if(!d){const{js:f={},css:l={}}=n.cropper||{};k.appendHandler("link",{...l,rel:"stylesheet",href:o.cropper.css,id:H.croppercss}),k.appendHandler("script",{...f,src:o.cropper.js,id:H.cropperjs})}if(!u){const{standaloneJs:f={}}=n.prettier||{};k.appendHandler("script",{...f,src:o.prettier.standaloneJs,id:H.prettier})}if(!c){const{parserMarkdownJs:f={}}=n.prettier||{};k.appendHandler("script",{...f,src:o.prettier.parserMarkdownJs,id:H.prettierMD})}})},ye=(e,t,a)=>{const{editorId:o}=a;r.onMounted(()=>{h.bus.on(o,{name:h.ERROR_CATCHER,callback:n=>{e.onError?.(n),t.emit("onError",n)}})})},Ce=(e,t,a)=>{const{editorId:o}=a,n=r.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),u=r.reactive({...n}),c=(l,s)=>{const i=s===void 0?!n[l]:s;switch(l){case"preview":{n.htmlPreview=!1,n.previewOnly=!1;break}case"htmlPreview":{n.preview=!1,n.previewOnly=!1;break}case"previewOnly":{i?!n.preview&&!n.htmlPreview&&(n.preview=!0):(u.preview||(n.preview=!1),u.htmlPreview||(n.htmlPreview=!1));break}}u[l]=i,n[l]=i};let d="";const f=()=>{n.pageFullscreen||n.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=d};return r.watch(()=>[n.pageFullscreen,n.fullscreen],f),r.onMounted(()=>{h.bus.on(o,{name:h.UPLOAD_IMAGE,callback(l,s){const i=p=>{W(o,{direct:"image",params:{desc:"",urls:p}}),s?.()};e.onUploadImg?e.onUploadImg(l,i):t.emit("onUploadImg",l,i)}}),d=document.body.style.overflow,f()}),[n,c]},xe=(e,t)=>{const{editorId:a}=t,o=r.ref(!1);return r.onMounted(()=>{h.bus.on(a,{name:h.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?o.value=!o.value:o.value=n}})}),o},we=(e,t,a)=>{const{editorId:o,catalogVisible:n,setting:u,updateSetting:c,codeRef:d}=a;r.watch(()=>u.pageFullscreen,l=>{h.bus.emit(o,h.PAGE_FULL_SCREEN_CHANGED,l)}),r.watch(()=>u.fullscreen,l=>{h.bus.emit(o,h.FULL_SCREEN_CHANGED,l)}),r.watch(()=>u.preview,l=>{h.bus.emit(o,h.PREVIEW_CHANGED,l)}),r.watch(()=>u.previewOnly,l=>{h.bus.emit(o,h.PREVIEW_ONLY_CHANGED,l)}),r.watch(()=>u.htmlPreview,l=>{h.bus.emit(o,h.HTML_PREVIEW_CHANGED,l)}),r.watch(n,l=>{h.bus.emit(o,h.CATALOG_VISIBLE_CHANGED,l)});const f={on(l,s){switch(l){case"pageFullscreen":{h.bus.on(o,{name:h.PAGE_FULL_SCREEN_CHANGED,callback(i){s(i)}});break}case"fullscreen":{h.bus.on(o,{name:h.FULL_SCREEN_CHANGED,callback(i){s(i)}});break}case"preview":{h.bus.on(o,{name:h.PREVIEW_CHANGED,callback(i){s(i)}});break}case"previewOnly":{h.bus.on(o,{name:h.PREVIEW_ONLY_CHANGED,callback(i){s(i)}});break}case"htmlPreview":{h.bus.on(o,{name:h.HTML_PREVIEW_CHANGED,callback(i){s(i)}});break}case"catalog":{h.bus.on(o,{name:h.CATALOG_VISIBLE_CHANGED,callback(i){s(i)}});break}}},togglePageFullscreen(l){c("pageFullscreen",l)},toggleFullscreen(l){h.bus.emit(o,h.CHANGE_FULL_SCREEN,l)},togglePreview(l){c("preview",l)},togglePreviewOnly(l){c("previewOnly",l)},toggleHtmlPreview(l){c("htmlPreview",l)},toggleCatalog(l){h.bus.emit(o,h.CHANGE_CATALOG_VISIBLE,l)},triggerSave(){h.bus.emit(o,h.ON_SAVE)},insert(l){W(o,{direct:"universal",params:{generate:l},source:"programmatic"})},focus(l){d.value?.focus(l)},rerender(){h.bus.emit(o,h.RERENDER)},getSelectedText(){return d.value?.getSelectedText()},resetHistory(){d.value?.resetHistory()},domEventHandlers(l){h.bus.emit(o,h.EVENT_LISTENER,l)},execCommand(l){W(o,{direct:l,source:"programmatic"})},getEditorView(){return d.value?.getEditorView()}};t.expose(f)},ne=e=>{const t=r.useId();return e.id||e.editorId||`${m.prefix}-${t}`},Ee=(e,t,a)=>{const o=r.inject("editorId"),n=r.inject("rootRef"),u=r.inject("usedLanguageText"),c=r.inject("setting"),d=()=>{n.value.querySelectorAll(`#${o} .${m.prefix}-preview .${m.prefix}-code`).forEach(s=>{let i=-1;const p=s.querySelector(`.${m.prefix}-copy-button:not([data-processed])`);p&&(p.onclick=g=>{g.preventDefault(),clearTimeout(i);const b=(s.querySelector("input:checked + pre code")||s.querySelector("pre code")).textContent,{text:y,successTips:E,failTips:C}=u.value.copyCode;let x=E;ce(e.formatCopiedText(b||"")).catch(()=>{x=C}).finally(()=>{p.dataset.isIcon?p.dataset.tips=x:p.textContent=x,i=window.setTimeout(()=>{p.dataset.isIcon?p.dataset.tips=y:p.textContent=y},1500)})},p.setAttribute("data-processed","true"))})},f=()=>{r.nextTick(d)},l=s=>{s&&r.nextTick(d)};r.watch([t,a],f),r.watch(()=>c.value.preview,l),r.watch(()=>c.value.htmlPreview,l),r.onMounted(d)},$e=e=>{const t=r.inject("editorId"),a=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:u,echartsConfig:c}=m.globalConfig;let d=n.echarts.instance;const f=r.shallowRef(-1),l=()=>{!e.noEcharts&&d&&(f.value=f.value+1)};r.watch(()=>a.value,()=>{l()}),r.onMounted(()=>{if(e.noEcharts||d)return;const b=n.echarts.js;k.appendHandler("script",{...u.echarts?.js,src:b,id:H.echarts,onload(){d=window.echarts,l()}},"echarts")});let s=[],i=[],p=[];const g=(b=!1)=>{if(!s.length){b&&(i.forEach(x=>{x.dispose?.()}),p.forEach(x=>{x.disconnect?.()}),i=[],p=[]);return}const y=[],E=[],C=[];s.forEach((x,$)=>{const w=i[$],I=p[$];if(b||!x||!x.isConnected||(o?.value?!o.value.contains(x):!1)){w?.dispose?.(),I?.disconnect?.();return}y.push(x),w&&E.push(w),I&&C.push(I)}),s=y,i=E,p=C},v=()=>{if(g(),!e.noEcharts&&d){const b=o.value;if(!b)return;Array.from(b.querySelectorAll(`#${t} div.${m.prefix}-echarts:not([data-processed])`)).forEach(E=>{if(E.dataset.closed==="false")return!1;try{const C=n.echarts.parseOption(E.innerText,{editorId:t,element:E}),x=c(C),$=d.init(E,a.value);$.setOption(x),E.setAttribute("data-processed",""),s.push(E),i.push($);const w=new ResizeObserver(()=>{$.resize()});w.observe(E),p.push(w)}catch(C){h.bus.emit(t,h.ERROR_CATCHER,{name:"echarts",message:C?.message,error:C})}})}};return r.onBeforeUnmount(()=>{g(!0)}),{reRenderEcharts:f,replaceEcharts:v}},Te=e=>{const t=r.inject("highlight"),a=r.shallowRef(m.globalConfig.editorExtensions.highlight.instance);return r.onMounted(()=>{e.noHighlight||a.value||(k.appendHandler("link",{...t.value.css,rel:"stylesheet",id:H.hlcss}),k.appendHandler("script",{...t.value.js,id:H.hljs,onload(){a.value=window.hljs}},"hljs"))}),r.watch(()=>t.value.css,()=>{e.noHighlight||m.globalConfig.editorExtensions.highlight.instance||k.updateHandler("link",{...t.value.css,rel:"stylesheet",id:H.hlcss})}),a},Ie=e=>{const t=r.shallowRef(m.globalConfig.editorExtensions.katex.instance);return r.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:a,editorExtensionsAttrs:o}=m.globalConfig;k.appendHandler("script",{...o.katex?.js,src:a.katex.js,id:H.katexjs,onload(){t.value=window.katex}},"katex"),k.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:a.katex.css,id:H.katexcss})}),t};class Se{constructor(t){this.options=t}options;cache=new Map;isExpired(t){return t.expiresAt<=Date.now()}deleteExpired(t,a){const o=a??this.cache.get(t);return!o||!this.isExpired(o)?!1:(this.cache.delete(t),!0)}trim(){for(const[t,a]of this.cache)if(!this.deleteExpired(t,a))break;for(;this.cache.size>this.options.max;){const t=this.cache.keys().next().value;if(t===void 0)break;this.cache.delete(t)}}get(t){const a=this.cache.get(t);if(!(!a||this.deleteExpired(t,a)))return this.cache.delete(t),this.cache.set(t,a),a.value}set(t,a){this.cache.delete(t),this.cache.set(t,{value:a,expiresAt:Date.now()+this.options.ttl}),this.trim()}clear(){this.cache.clear()}}const q=new Se({max:1e3,ttl:6e5}),ke=e=>{const t=r.inject("editorId"),a=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:u,mermaidConfig:c}=m.globalConfig;let d=n.mermaid.instance;const f=r.shallowRef(-1),l=()=>{if(!e.noMermaid&&d){const i=a.value==="dark"?{startOnLoad:!1,theme:"dark"}:{startOnLoad:!1,theme:"base",themeVariables:{background:"#ffffff",primaryColor:"#ffffff",primaryTextColor:"#1f2329",primaryBorderColor:"#b7c0cc",secondaryColor:"#f7f8fa",tertiaryColor:"#f7f8fa",lineColor:"#596273",edgeLabelBackground:"#ffffff",clusterBkg:"#ffffff",clusterBorder:"#b7c0cc"}};d.initialize(c(i)),f.value=f.value+1}};return r.watch(()=>a.value,()=>{q.clear(),l()}),r.onMounted(()=>{if(e.noMermaid||d)return;const i=n.mermaid.js;/\.mjs/.test(i)?(k.appendHandler("link",{...u.mermaid?.js,rel:"modulepreload",href:i,id:H.mermaidM}),import(i).then(p=>{d=p.default,l()}).catch(p=>{h.bus.emit(t,h.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${p.message}`,error:p})})):k.appendHandler("script",{...u.mermaid?.js,src:i,id:H.mermaid,onload(){d=window.mermaid,l()}},"mermaid")}),{reRenderRef:f,replaceMermaid:async()=>{if(!e.noMermaid&&d){const i=o.value;if(!i)return;const p=i.querySelectorAll(`div.${m.prefix}-mermaid`);if(p.length===0)return;const g=document.createElement("div"),v=document.body.offsetWidth>1366?document.body.offsetWidth:1366,b=document.body.offsetHeight>768?document.body.offsetHeight:768;g.style.width=v+"px",g.style.height=b+"px",g.style.position="fixed",g.style.zIndex="-10000",g.style.top="-10000px",g.style.left="-10000px",document.body.appendChild(g);try{await Promise.allSettled(Array.from(p).map(y=>(async C=>{if(C.dataset.closed==="false")return!1;const x=C.innerText;let $=q.get(x);if(!$){const w=O.randomId();let I={svg:""};try{I=await d.render(w,x,g),$=await e.sanitizeMermaid(I.svg);const T=document.createElement("p");T.className=`${m.prefix}-mermaid`,T.setAttribute("data-processed",""),T.setAttribute("data-content",x),T.innerHTML=$,T.children[0]?.removeAttribute("height"),q.set(x,T.innerHTML),C.dataset.line!==void 0&&(T.dataset.line=C.dataset.line),C.replaceWith(T)}catch(T){h.bus.emit(t,h.ERROR_CATCHER,{name:"mermaid",message:T.message,error:T})}}})(y)))}finally{g.remove()}}}}},Re=(e,t)=>{t=t||{};const a=3,o=t.marker||"!",n=o.charCodeAt(0),u=o.length;let c="",d="";const f=(s,i,p,g,v)=>{const b=s[i];return b.type==="admonition_open"?s[i].attrPush(["class",`${m.prefix}-admonition ${m.prefix}-admonition-${b.info}`]):b.type==="admonition_title_open"&&s[i].attrPush(["class",`${m.prefix}-admonition-title`]),v.renderToken(s,i,p)},l=s=>{const i=s.trim().split(" ",2);d="",c=i[0],i.length>1&&(d=s.substring(c.length+2))};e.block.ruler.before("code","admonition",(s,i,p,g)=>{let v,b,y,E=!1,C=s.bMarks[i]+s.tShift[i],x=s.eMarks[i];if(n!==s.src.charCodeAt(C))return!1;for(v=C+1;v<=x&&o[(v-C)%u]===s.src[v];v++);const $=Math.floor((v-C)/u);if($!==a)return!1;v-=(v-C)%u;const w=s.src.slice(C,v),I=s.src.slice(v,x);if(l(I),g)return!0;for(b=i;b++,!(b>=p||(C=s.bMarks[b]+s.tShift[b],x=s.eMarks[b],C<x&&s.sCount[b]<s.blkIndent));)if(n===s.src.charCodeAt(C)&&!(s.sCount[b]-s.blkIndent>=4)){for(v=C+1;v<=x&&o[(v-C)%u]===s.src[v];v++);if(!(Math.floor((v-C)/u)<$)&&(v-=(v-C)%u,v=s.skipSpaces(v),!(v<x))){E=!0;break}}const T=s.parentType,R=s.lineMax;return s.parentType="root",s.lineMax=b,y=s.push("admonition_open","div",1),y.markup=w,y.block=!0,y.info=c,y.map=[i,b],d&&(y=s.push("admonition_title_open","p",1),y.markup=w+" "+c,y.map=[i,b],y=s.push("inline","",0),y.content=d,y.map=[i,s.line-1],y.children=[],y=s.push("admonition_title_close","p",-1),y.markup=w+" "+c),s.md.block.tokenize(s,i+1,b),y=s.push("admonition_close","div",-1),y.markup=s.src.slice(C,v),y.block=!0,s.parentType=T,s.lineMax=R,s.line=b+(E?1:0),!0},{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.admonition_open=f,e.renderer.rules.admonition_title_open=f,e.renderer.rules.admonition_title_close=f,e.renderer.rules.admonition_close=f},G=(e,t,a)=>`<${e.tag}${a.renderAttrs(e)}>${t}</${e.tag}>`,J=(e,t)=>{const a=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const n=e.attrIndex(o[0]);n<0?a.push(o):(a[n]=a[n].slice(),a[n][1]+=` ${o[1]}`)}),a},Ae=e=>Array.from(e).map(t=>/[A-Za-z0-9_-]/.test(t)?t:`_${t.codePointAt(0).toString(16)}_`).join(""),He=(e,t)=>{const a=e.renderer.rules.fence,o=e.utils.unescapeAll,n=/\[(\w*)(?::([\w ]*))?\]/,u=/::(open|close)/,c=Ae(t.editorId),d=p=>p.info?o(p.info).trim():"",f=p=>{const g=d(p),[v=null,b=""]=(n.exec(g)||[]).slice(1);return[v,b]},l=p=>{const g=d(p);return g?g.split(/(\s+)/g)[0]:""},s=p=>{const g=p.info.match(u)||[],v=g[1]==="open"||g[1]!=="close"&&t.codeFoldable&&p.content.trim().split(`
|
|
2
|
-
`).length<t.autoFoldThreshold,b=g[1]||t.codeFoldable?"details":"div",y=g[1]||t.codeFoldable?"summary":"div";return{open:v,tagContainer:b,tagHeader:y}},
|
|
3
|
-
<${
|
|
4
|
-
<${
|
|
5
|
-
<div class="${
|
|
6
|
-
<div class="${
|
|
7
|
-
<span class="${
|
|
8
|
-
<span class="${
|
|
9
|
-
${t.extraTools instanceof Function?t.extraTools({lang:
|
|
10
|
-
${
|
|
1
|
+
"use strict";const r=require("vue"),h=require("./event-bus.cjs"),O=require("@vavt/util"),p=require("./config.cjs"),H=require("./dom.cjs"),ve=require("@vavt/copy2clipboard"),be=require("markdown-it"),ye=require("markdown-it-image-figures"),xe=require("markdown-it-sub"),Ce=require("markdown-it-sup"),ne=require("./index5.cjs"),we=require("medium-zoom"),Ee=(e,t,a)=>{const{editorId:o}=a,n={rerender(){h.bus.emit(o,h.RERENDER)}};t.expose(n)},A={hljs:`${p.prefix}-hljs`,hlcss:`${p.prefix}-hlCss`,prettier:`${p.prefix}-prettier`,prettierMD:`${p.prefix}-prettierMD`,cropperjs:`${p.prefix}-cropper`,croppercss:`${p.prefix}-cropperCss`,screenfull:`${p.prefix}-screenfull`,mermaidM:`${p.prefix}-mermaid-m`,mermaid:`${p.prefix}-mermaid`,katexjs:`${p.prefix}-katex`,katexcss:`${p.prefix}-katexCss`,echarts:`${p.prefix}-echarts`},Y=(e,t)=>{h.bus.emit(e,h.REPLACE,t)},Ie=(e,t,a)=>{const{editorId:o}=a,n=r.reactive({buildFinished:!1,html:""});r.watch(()=>e.modelValue,()=>{n.buildFinished=!1}),r.onMounted(()=>{h.bus.on(o,{name:h.BUILD_FINISHED,callback(d){n.buildFinished=!0,n.html=d}}),h.bus.on(o,{name:h.ON_SAVE,callback(){const d=new Promise(c=>{if(n.buildFinished)c(n.html);else{const u=f=>{c(f),h.bus.remove(o,h.BUILD_FINISHED,u)};h.bus.on(o,{name:h.BUILD_FINISHED,callback:u})}});e.onSave?e.onSave(e.modelValue,d):t.emit("onSave",e.modelValue,d)}})})},se=(e,{editorId:t,rootRef:a,setting:o})=>{const n=p.globalConfig.editorExtensions.highlight,d=p.globalConfig.editorExtensionsAttrs.highlight;r.provide("editorId",t),r.provide("rootRef",a),r.provide("theme",r.computed(()=>e.theme)),r.provide("language",r.computed(()=>e.language)),r.provide("highlight",r.computed(()=>{const{js:u}=n,f={...p.codeCss,...n.css},{js:i,css:s={}}=d||{},l=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,m=f[e.codeTheme]?f[e.codeTheme][l]:p.codeCss.atom[l],g=f[e.codeTheme]&&s[e.codeTheme]?s[e.codeTheme][l]:s.atom?s.atom[l]:{};return{js:{src:u,...i},css:{href:m,...g}}})),r.provide("showCodeRowNumber",e.showCodeRowNumber);const c=r.computed(()=>{const u={...p.staticTextDefault,...p.globalConfig.editorConfig.languageUserDefined};return O.deepMerge(O.deepClone(p.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}},$e=(e,t)=>(r.provide("tabWidth",e.tabWidth),r.provide("disabled",r.computed(()=>e.disabled)),r.provide("contentDisabled",r.computed(()=>e.disabled||e.readOnly)),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)),se(e,t)),Te=e=>{const{noPrettier:t,noUploadImg:a}=e,{editorExtensions:o,editorExtensionsAttrs:n}=p.globalConfig,d=t||o.prettier.prettierInstance,c=t||o.prettier.parserMarkdownInstance,u=a||o.cropper.instance;r.onMounted(()=>{if(!u){const{js:f={},css:i={}}=n.cropper||{};H.appendHandler("link",{...i,rel:"stylesheet",href:o.cropper.css,id:A.croppercss}),H.appendHandler("script",{...f,src:o.cropper.js,id:A.cropperjs})}if(!d){const{standaloneJs:f={}}=n.prettier||{};H.appendHandler("script",{...f,src:o.prettier.standaloneJs,id:A.prettier})}if(!c){const{parserMarkdownJs:f={}}=n.prettier||{};H.appendHandler("script",{...f,src:o.prettier.parserMarkdownJs,id:A.prettierMD})}})},Se=(e,t,a)=>{const{editorId:o}=a;r.onMounted(()=>{h.bus.on(o,{name:h.ERROR_CATCHER,callback:n=>{e.onError?.(n),t.emit("onError",n)}})})},ke=(e,t,a)=>{const{editorId:o}=a,n=r.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),d=r.reactive({...n}),c=(i,s)=>{const l=s===void 0?!n[i]:s;switch(i){case"preview":{n.htmlPreview=!1,n.previewOnly=!1;break}case"htmlPreview":{n.preview=!1,n.previewOnly=!1;break}case"previewOnly":{l?!n.preview&&!n.htmlPreview&&(n.preview=!0):(d.preview||(n.preview=!1),d.htmlPreview||(n.htmlPreview=!1));break}}d[i]=l,n[i]=l};let u="";const f=()=>{n.pageFullscreen||n.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=u};return r.watch(()=>[n.pageFullscreen,n.fullscreen],f),r.onMounted(()=>{h.bus.on(o,{name:h.UPLOAD_IMAGE,callback(i,s){const l=m=>{Y(o,{direct:"image",params:{desc:"",urls:m}}),s?.()};e.onUploadImg?e.onUploadImg(i,l):t.emit("onUploadImg",i,l)}}),u=document.body.style.overflow,f()}),[n,c]},He=(e,t)=>{const{editorId:a}=t,o=r.ref(!1);return r.onMounted(()=>{h.bus.on(a,{name:h.CHANGE_CATALOG_VISIBLE,callback:n=>{n===void 0?o.value=!o.value:o.value=n}})}),o},Re=(e,t,a)=>{const{editorId:o,catalogVisible:n,setting:d,updateSetting:c,codeRef:u}=a;r.watch(()=>d.pageFullscreen,i=>{h.bus.emit(o,h.PAGE_FULL_SCREEN_CHANGED,i)}),r.watch(()=>d.fullscreen,i=>{h.bus.emit(o,h.FULL_SCREEN_CHANGED,i)}),r.watch(()=>d.preview,i=>{h.bus.emit(o,h.PREVIEW_CHANGED,i)}),r.watch(()=>d.previewOnly,i=>{h.bus.emit(o,h.PREVIEW_ONLY_CHANGED,i)}),r.watch(()=>d.htmlPreview,i=>{h.bus.emit(o,h.HTML_PREVIEW_CHANGED,i)}),r.watch(n,i=>{h.bus.emit(o,h.CATALOG_VISIBLE_CHANGED,i)});const f={on(i,s){switch(i){case"pageFullscreen":{h.bus.on(o,{name:h.PAGE_FULL_SCREEN_CHANGED,callback(l){s(l)}});break}case"fullscreen":{h.bus.on(o,{name:h.FULL_SCREEN_CHANGED,callback(l){s(l)}});break}case"preview":{h.bus.on(o,{name:h.PREVIEW_CHANGED,callback(l){s(l)}});break}case"previewOnly":{h.bus.on(o,{name:h.PREVIEW_ONLY_CHANGED,callback(l){s(l)}});break}case"htmlPreview":{h.bus.on(o,{name:h.HTML_PREVIEW_CHANGED,callback(l){s(l)}});break}case"catalog":{h.bus.on(o,{name:h.CATALOG_VISIBLE_CHANGED,callback(l){s(l)}});break}}},togglePageFullscreen(i){c("pageFullscreen",i)},toggleFullscreen(i){h.bus.emit(o,h.CHANGE_FULL_SCREEN,i)},togglePreview(i){c("preview",i)},togglePreviewOnly(i){c("previewOnly",i)},toggleHtmlPreview(i){c("htmlPreview",i)},toggleCatalog(i){h.bus.emit(o,h.CHANGE_CATALOG_VISIBLE,i)},triggerSave(){h.bus.emit(o,h.ON_SAVE)},insert(i){Y(o,{direct:"universal",params:{generate:i},source:"programmatic"})},focus(i){u.value?.focus(i)},rerender(){h.bus.emit(o,h.RERENDER)},getSelectedText(){return u.value?.getSelectedText()},resetHistory(){u.value?.resetHistory()},domEventHandlers(i){h.bus.emit(o,h.EVENT_LISTENER,i)},execCommand(i){Y(o,{direct:i,source:"programmatic"})},getEditorView(){return u.value?.getEditorView()}};t.expose(f)},ce=e=>{const t=r.useId();return e.id||e.editorId||`${p.prefix}-${t}`},Ae=(e,t,a)=>{const o=r.inject("editorId"),n=r.inject("rootRef"),d=r.inject("usedLanguageText"),c=r.inject("setting"),u=()=>{n.value.querySelectorAll(`#${o} .${p.prefix}-preview .${p.prefix}-code`).forEach(s=>{let l=-1;const m=s.querySelector(`.${p.prefix}-copy-button:not([data-processed])`);m&&(m.onclick=g=>{g.preventDefault(),clearTimeout(l);const b=(s.querySelector("input:checked + pre code")||s.querySelector("pre code")).textContent,{text:y,successTips:E,failTips:x}=d.value.copyCode;let C=E;ve(e.formatCopiedText(b||"")).catch(()=>{C=x}).finally(()=>{m.dataset.isIcon?m.dataset.tips=C:m.textContent=C,l=window.setTimeout(()=>{m.dataset.isIcon?m.dataset.tips=y:m.textContent=y},1500)})},m.setAttribute("data-processed","true"))})},f=()=>{r.nextTick(u)},i=s=>{s&&r.nextTick(u)};r.watch([t,a],f),r.watch(()=>c.value.preview,i),r.watch(()=>c.value.htmlPreview,i),r.onMounted(u)},Le=e=>{const t=r.inject("editorId"),a=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:d,echartsConfig:c}=p.globalConfig;let u=n.echarts.instance;const f=r.shallowRef(-1),i=()=>{!e.noEcharts&&u&&(f.value=f.value+1)};r.watch(()=>a.value,()=>{i()}),r.onMounted(()=>{if(e.noEcharts||u)return;const b=n.echarts.js;H.appendHandler("script",{...d.echarts?.js,src:b,id:A.echarts,onload(){u=window.echarts,i()}},"echarts")});let s=[],l=[],m=[];const g=(b=!1)=>{if(!s.length){b&&(l.forEach(C=>{C.dispose?.()}),m.forEach(C=>{C.disconnect?.()}),l=[],m=[]);return}const y=[],E=[],x=[];s.forEach((C,I)=>{const w=l[I],T=m[I];if(b||!C||!C.isConnected||(o?.value?!o.value.contains(C):!1)){w?.dispose?.(),T?.disconnect?.();return}y.push(C),w&&E.push(w),T&&x.push(T)}),s=y,l=E,m=x},v=()=>{if(g(),!e.noEcharts&&u){const b=o.value;if(!b)return;Array.from(b.querySelectorAll(`#${t} div.${p.prefix}-echarts:not([data-processed])`)).forEach(E=>{if(E.dataset.closed==="false")return!1;try{const x=n.echarts.parseOption(E.innerText,{editorId:t,element:E}),C=c(x),I=u.init(E,a.value);I.setOption(C),E.setAttribute("data-processed",""),s.push(E),l.push(I);const w=new ResizeObserver(()=>{I.resize()});w.observe(E),m.push(w)}catch(x){h.bus.emit(t,h.ERROR_CATCHER,{name:"echarts",message:x?.message,error:x})}})}};return r.onBeforeUnmount(()=>{g(!0)}),{reRenderEcharts:f,replaceEcharts:v}},_e=e=>{const t=r.inject("highlight"),a=r.shallowRef(p.globalConfig.editorExtensions.highlight.instance);return r.onMounted(()=>{e.noHighlight||a.value||(H.appendHandler("link",{...t.value.css,rel:"stylesheet",id:A.hlcss}),H.appendHandler("script",{...t.value.js,id:A.hljs,onload(){a.value=window.hljs}},"hljs"))}),r.watch(()=>t.value.css,()=>{e.noHighlight||p.globalConfig.editorExtensions.highlight.instance||H.updateHandler("link",{...t.value.css,rel:"stylesheet",id:A.hlcss})}),a},Fe=e=>{const t=r.shallowRef(p.globalConfig.editorExtensions.katex.instance);return r.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:a,editorExtensionsAttrs:o}=p.globalConfig;H.appendHandler("script",{...o.katex?.js,src:a.katex.js,id:A.katexjs,onload(){t.value=window.katex}},"katex"),H.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:a.katex.css,id:A.katexcss})}),t};class Me{constructor(t){this.options=t}options;cache=new Map;isExpired(t){return t.expiresAt<=Date.now()}deleteExpired(t,a){const o=a??this.cache.get(t);return!o||!this.isExpired(o)?!1:(this.cache.delete(t),!0)}trim(){for(const[t,a]of this.cache)if(!this.deleteExpired(t,a))break;for(;this.cache.size>this.options.max;){const t=this.cache.keys().next().value;if(t===void 0)break;this.cache.delete(t)}}get(t){const a=this.cache.get(t);if(!(!a||this.deleteExpired(t,a)))return this.cache.delete(t),this.cache.set(t,a),a.value}set(t,a){this.cache.delete(t),this.cache.set(t,{value:a,expiresAt:Date.now()+this.options.ttl}),this.trim()}clear(){this.cache.clear()}}const Z=new Me({max:1e3,ttl:6e5}),Pe=e=>{const t=r.inject("editorId"),a=r.inject("theme"),o=r.inject("rootRef"),{editorExtensions:n,editorExtensionsAttrs:d,mermaidConfig:c}=p.globalConfig;let u=n.mermaid.instance;const f=r.shallowRef(-1),i=()=>{if(!e.noMermaid&&u){const l=a.value==="dark"?{startOnLoad:!1,theme:"dark"}:{startOnLoad:!1,theme:"base",themeVariables:{background:"#ffffff",primaryColor:"#ffffff",primaryTextColor:"#1f2329",primaryBorderColor:"#b7c0cc",secondaryColor:"#f7f8fa",tertiaryColor:"#f7f8fa",lineColor:"#596273",edgeLabelBackground:"#ffffff",clusterBkg:"#ffffff",clusterBorder:"#b7c0cc"}};u.initialize(c(l)),f.value=f.value+1}};return r.watch(()=>a.value,()=>{Z.clear(),i()}),r.onMounted(()=>{if(e.noMermaid||u)return;const l=n.mermaid.js;/\.mjs/.test(l)?(H.appendHandler("link",{...d.mermaid?.js,rel:"modulepreload",href:l,id:A.mermaidM}),import(l).then(m=>{u=m.default,i()}).catch(m=>{h.bus.emit(t,h.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${m.message}`,error:m})})):H.appendHandler("script",{...d.mermaid?.js,src:l,id:A.mermaid,onload(){u=window.mermaid,i()}},"mermaid")}),{reRenderRef:f,replaceMermaid:async()=>{if(!e.noMermaid&&u){const l=o.value;if(!l)return;const m=l.querySelectorAll(`div.${p.prefix}-mermaid`);if(m.length===0)return;const g=document.createElement("div"),v=document.body.offsetWidth>1366?document.body.offsetWidth:1366,b=document.body.offsetHeight>768?document.body.offsetHeight:768;g.style.width=v+"px",g.style.height=b+"px",g.style.position="fixed",g.style.zIndex="-10000",g.style.top="-10000px",g.style.left="-10000px",document.body.appendChild(g);try{await Promise.allSettled(Array.from(m).map(y=>(async x=>{if(x.dataset.closed==="false")return!1;const C=x.innerText;let I=Z.get(C);if(!I){const w=O.randomId();let T={svg:""};try{T=await u.render(w,C,g),I=await e.sanitizeMermaid(T.svg);const $=document.createElement("p");$.className=`${p.prefix}-mermaid`,$.setAttribute("data-processed",""),$.setAttribute("data-content",C),$.innerHTML=I,$.children[0]?.removeAttribute("height"),Z.set(C,$.innerHTML),x.dataset.line!==void 0&&($.dataset.line=x.dataset.line),x.replaceWith($)}catch($){h.bus.emit(t,h.ERROR_CATCHER,{name:"mermaid",message:$.message,error:$})}}})(y)))}finally{g.remove()}}}}},Ne=(e,t)=>{t=t||{};const a=3,o=t.marker||"!",n=o.charCodeAt(0),d=o.length;let c="",u="";const f=(s,l,m,g,v)=>{const b=s[l];return b.type==="admonition_open"?s[l].attrPush(["class",`${p.prefix}-admonition ${p.prefix}-admonition-${b.info}`]):b.type==="admonition_title_open"&&s[l].attrPush(["class",`${p.prefix}-admonition-title`]),v.renderToken(s,l,m)},i=s=>{const l=s.trim().split(" ",2);u="",c=l[0],l.length>1&&(u=s.substring(c.length+2))};e.block.ruler.before("code","admonition",(s,l,m,g)=>{let v,b,y,E=!1,x=s.bMarks[l]+s.tShift[l],C=s.eMarks[l];if(n!==s.src.charCodeAt(x))return!1;for(v=x+1;v<=C&&o[(v-x)%d]===s.src[v];v++);const I=Math.floor((v-x)/d);if(I!==a)return!1;v-=(v-x)%d;const w=s.src.slice(x,v),T=s.src.slice(v,C);if(i(T),g)return!0;for(b=l;b++,!(b>=m||(x=s.bMarks[b]+s.tShift[b],C=s.eMarks[b],x<C&&s.sCount[b]<s.blkIndent));)if(n===s.src.charCodeAt(x)&&!(s.sCount[b]-s.blkIndent>=4)){for(v=x+1;v<=C&&o[(v-x)%d]===s.src[v];v++);if(!(Math.floor((v-x)/d)<I)&&(v-=(v-x)%d,v=s.skipSpaces(v),!(v<C))){E=!0;break}}const $=s.parentType,R=s.lineMax;return s.parentType="root",s.lineMax=b,y=s.push("admonition_open","div",1),y.markup=w,y.block=!0,y.info=c,y.map=[l,b],u&&(y=s.push("admonition_title_open","p",1),y.markup=w+" "+c,y.map=[l,b],y=s.push("inline","",0),y.content=u,y.map=[l,s.line-1],y.children=[],y=s.push("admonition_title_close","p",-1),y.markup=w+" "+c),s.md.block.tokenize(s,l+1,b),y=s.push("admonition_close","div",-1),y.markup=s.src.slice(x,v),y.block=!0,s.parentType=$,s.lineMax=R,s.line=b+(E?1:0),!0},{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.admonition_open=f,e.renderer.rules.admonition_title_open=f,e.renderer.rules.admonition_title_close=f,e.renderer.rules.admonition_close=f},je=/^\s*\d+(?:\s*-\s*\d+)?(?:\s*,\s*\d+(?:\s*-\s*\d+)?)*\s*$/,Oe=e=>{const t=e.search(/\s/);let a="",o=!1;for(let n=0;n<e.length;n+=1){const d=e[n];if(a){if(o){o=!1;continue}if(d==="\\"){o=!0;continue}d===a&&(a="");continue}if(d==='"'||d==="'"||d==="`"){a=d;continue}if(d!=="{")continue;const c=e.indexOf("}",n+1);if(c===-1)break;const u=e.slice(n+1,c);if(!je.test(u))continue;const f=e[n-1]||"",i=e[c+1]||"",s=!i||/\s/.test(i),l=(t===-1||n<t)&&(!f||!/[\s="'`]/.test(f))&&s,m=(!f||/\s/.test(f))&&s;if(l||m)return{endIndex:c+1,startIndex:n,value:u}}return null},J=(e,t="")=>{const a=`${e}${t?` ${t}`:""}`.trim(),o=Oe(a),n=o?`${a.slice(0,o.startIndex)} ${a.slice(o.endIndex)}`.trim():a,d=n.search(/\s/),c=d===-1?n:n.slice(0,d),u=d===-1?"":n.slice(d).trim(),f=o?o.value.split(",").reduce((i,s)=>{const[l,m]=s.split("-").map(v=>Number.parseInt(v.trim(),10)),g=m??l;return l>0&&g>=l&&i.push({start:l,end:g}),i},[]):[];return{attrs:u,language:c,lineHighlightRanges:f}},K=(e,t,a)=>`<${e.tag}${a.renderAttrs(e)}>${t}</${e.tag}>`,oe=(e,t)=>{const a=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const n=e.attrIndex(o[0]);n<0?a.push(o):(a[n]=a[n].slice(),a[n][1]+=` ${o[1]}`)}),a},De=e=>Array.from(e).map(t=>/[A-Za-z0-9_-]/.test(t)?t:`_${t.codePointAt(0).toString(16)}_`).join(""),Be=(e,t)=>{const a=e.renderer.rules.fence,o=e.utils.unescapeAll,n=/\[(\w*)(?::([\w ]*))?\]/,d=/::(open|close)/,c=De(t.editorId),u=m=>m.info?o(m.info).trim():"",f=m=>{const g=u(m),[v=null,b=""]=(n.exec(g)||[]).slice(1);return[v,b]},i=m=>J(u(m)).language,s=m=>{const g=m.info.match(d)||[],v=g[1]==="open"||g[1]!=="close"&&t.codeFoldable&&m.content.trim().split(`
|
|
2
|
+
`).length<t.autoFoldThreshold,b=g[1]||t.codeFoldable?"details":"div",y=g[1]||t.codeFoldable?"summary":"div";return{open:v,tagContainer:b,tagHeader:y}},l=(m,g,v,b,y)=>{if(m[g].hidden)return"";const E=t.usedLanguageTextRef.value?.copyCode.text||"",x=t.customIconRef.value.copy,C=e.utils.escapeHtml(E),I=x||C,w=!!x,T=`<span class="${p.prefix}-collapse-tips">${H.StrIcon("collapse-tips",t.customIconRef.value)}</span>`,[$]=f(m[g]);if($===null){const{open:S,tagContainer:L,tagHeader:z}=s(m[g]),j=[["class",`${p.prefix}-code`]];S&&j.push(["open",""]);const W={attrs:oe(m[g],j)};m[g].info=m[g].info.replace(d,"");const{attrs:pe,language:he}=J(u(m[g])),te=[he,pe].filter(Boolean).join(" "),ge=a(m,g,v,b,y);return`
|
|
3
|
+
<${L} ${y.renderAttrs(W)}>
|
|
4
|
+
<${z} class="${p.prefix}-code-head">
|
|
5
|
+
<div class="${p.prefix}-code-flag"><span></span><span></span><span></span></div>
|
|
6
|
+
<div class="${p.prefix}-code-action">
|
|
7
|
+
<span class="${p.prefix}-code-lang">${e.utils.escapeHtml(te)}</span>
|
|
8
|
+
<span class="${p.prefix}-copy-button" data-tips="${C}"${w?" data-is-icon=true":""}>${I}</span>
|
|
9
|
+
${t.extraTools instanceof Function?t.extraTools({lang:te}):t.extraTools||""}
|
|
10
|
+
${L==="details"?T:""}
|
|
11
11
|
</div>
|
|
12
|
-
</${
|
|
13
|
-
${
|
|
14
|
-
</${
|
|
15
|
-
`}let R,M,
|
|
12
|
+
</${z}>
|
|
13
|
+
${ge}
|
|
14
|
+
</${L}>
|
|
15
|
+
`}let R,_,M,F,D="",B="",V="";const{open:Q,tagContainer:k,tagHeader:G}=s(m[g]),P=[["class",`${p.prefix}-code`]];Q&&P.push(["open",""]);const U={attrs:oe(m[g],P)};for(let S=g;S<m.length&&(R=m[S],[_,M]=f(R),_===$);S++){R.info=R.info.replace(n,"").replace(d,""),R.hidden=!0;const L=`${p.prefix}-codetab-${c}-${g}-${S-g}`;F=S-g>0?"":"checked",D+=`
|
|
16
16
|
<li>
|
|
17
17
|
<input
|
|
18
18
|
type="radio"
|
|
19
|
-
id="label-${
|
|
20
|
-
name="${
|
|
21
|
-
class="${
|
|
22
|
-
${
|
|
19
|
+
id="label-${p.prefix}-codetab-label-1-${c}-${g}-${S-g}"
|
|
20
|
+
name="${p.prefix}-codetab-label-${c}-${g}"
|
|
21
|
+
class="${L}"
|
|
22
|
+
${F}
|
|
23
23
|
>
|
|
24
24
|
<label
|
|
25
|
-
for="label-${
|
|
26
|
-
onclick="this.getRootNode().querySelectorAll('.${
|
|
25
|
+
for="label-${p.prefix}-codetab-label-1-${c}-${g}-${S-g}"
|
|
26
|
+
onclick="this.getRootNode().querySelectorAll('.${L}').forEach(e => e.click())"
|
|
27
27
|
>
|
|
28
|
-
${e.utils.escapeHtml(
|
|
28
|
+
${e.utils.escapeHtml(M||i(R))}
|
|
29
29
|
</label>
|
|
30
30
|
</li>`,B+=`
|
|
31
31
|
<div role="tabpanel">
|
|
32
32
|
<input
|
|
33
33
|
type="radio"
|
|
34
|
-
name="${
|
|
35
|
-
class="${
|
|
36
|
-
${
|
|
34
|
+
name="${p.prefix}-codetab-pre-${c}-${g}"
|
|
35
|
+
class="${L}"
|
|
36
|
+
${F}
|
|
37
37
|
role="presentation">
|
|
38
|
-
${a(
|
|
38
|
+
${a(m,S,v,b,y)}
|
|
39
39
|
</div>`,V+=`
|
|
40
40
|
<input
|
|
41
41
|
type="radio"
|
|
42
|
-
name="${
|
|
43
|
-
class="${
|
|
44
|
-
${
|
|
42
|
+
name="${p.prefix}-codetab-lang-${c}-${g}"
|
|
43
|
+
class="${L}"
|
|
44
|
+
${F}
|
|
45
45
|
role="presentation">
|
|
46
|
-
<span class=${
|
|
47
|
-
<${
|
|
48
|
-
<${
|
|
49
|
-
<div class="${
|
|
50
|
-
<ul class="${
|
|
46
|
+
<span class=${p.prefix}-code-lang role="note">${e.utils.escapeHtml(i(R))}</span>`}const{attrs:ee,language:N}=J(u(m[g])),q=[N,ee].filter(Boolean).join(" ");return`
|
|
47
|
+
<${k} ${y.renderAttrs(U)}>
|
|
48
|
+
<${G} class="${p.prefix}-code-head">
|
|
49
|
+
<div class="${p.prefix}-code-flag">
|
|
50
|
+
<ul class="${p.prefix}-codetab-label" role="tablist">${D}</ul>
|
|
51
51
|
</div>
|
|
52
|
-
<div class="${
|
|
53
|
-
<span class="${
|
|
54
|
-
<span class="${
|
|
55
|
-
${t.extraTools instanceof Function?t.extraTools({lang:
|
|
56
|
-
${
|
|
52
|
+
<div class="${p.prefix}-code-action">
|
|
53
|
+
<span class="${p.prefix}-codetab-lang">${V}</span>
|
|
54
|
+
<span class="${p.prefix}-copy-button" data-tips="${C}"${w?" data-is-icon=true":""}>${I}</span>
|
|
55
|
+
${t.extraTools instanceof Function?t.extraTools({lang:q}):t.extraTools||""}
|
|
56
|
+
${k==="details"?T:""}
|
|
57
57
|
</div>
|
|
58
|
-
</${
|
|
58
|
+
</${G}>
|
|
59
59
|
${B}
|
|
60
|
-
</${
|
|
61
|
-
`};e.renderer.rules.fence=
|
|
62
|
-
`)})));let
|
|
63
|
-
`)}))},
|
|
64
|
-
`),g=
|
|
65
|
-
`))):h.bus.emit(a,h.TASK_STATE_CHANGED,
|
|
60
|
+
</${k}>
|
|
61
|
+
`};e.renderer.rules.fence=l,e.renderer.rules.code_block=l},Ve=(e,t)=>{e.core.ruler.after("block","echarts-token-attrs",o=>{o.tokens.forEach(n=>{if(!(n.type!=="fence"||n.info!=="echarts")&&(n.tag="div",n.attrJoin("class",`${p.prefix}-echarts`),n.attrSet("data-echarts-theme",t.themeRef.value),n.attrSet("style","width: 100%; aspect-ratio: 4 / 3;"),n.map&&n.level===0)){const d=n.map[1]-1,u=!!o.env.srcLines?.[d]?.trim()?.startsWith("```");n.attrSet("data-closed",`${u}`),n.attrSet("data-line",String(n.map[0]))}})});const a=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,n,d,c,u)=>{const f=o[n],i=f.content.trim();return f.info==="echarts"?K(f,e.utils.escapeHtml(i),u):a(o,n,d,c,u)}},Ge=(e,t)=>{e.renderer.rules.heading_open=(a,o)=>{const n=a[o],d=a[o+1].children?.reduce((u,f)=>u+(["text","code_inline","math_inline"].includes(f.type)&&f.content||""),"")||"",c=n.markup.length;return t.headsRef.value.push({text:d,level:c,line:n.map[0],currentToken:n,nextToken:a[o+1]}),n.map&&n.level===0&&n.attrSet("id",t.mdHeadingId({text:d,level:c,index:t.headsRef.value.length,currentToken:n,nextToken:a[o+1]})),e.renderer.renderToken(a,o,t)},e.renderer.rules.heading_close=(a,o,n,d,c)=>c.renderToken(a,o,n)},re={block:[{open:"$$",close:"$$"},{open:"\\[",close:"\\]"}],inline:[{open:"$$",close:"$$"},{open:"$",close:"$"},{open:"\\[",close:"\\]"},{open:"\\(",close:"\\)"}]},Ue=e=>(t,a)=>{const o=e.delimiters;for(const n of o){if(!t.src.startsWith(n.open,t.pos))continue;const d=t.pos+n.open.length;let c=d;for(;(c=t.src.indexOf(n.close,c))!==-1;){let u=0,f=c-1;for(;f>=0&&t.src[f]==="\\";)u++,f--;if(u%2===0)break;c+=n.close.length}if(c!==-1){if(c-d===0)return a||(t.pending+=n.open+n.close),t.pos=c+n.close.length,!0;if(!a){const u=t.push("math_inline",e.tag,0);u.attrSet("class",e.className),u.markup=n.open,u.content=t.src.slice(d,c)}return t.pos=c+n.close.length,!0}}return!1},qe=e=>(t,a,o,n)=>{const d=e.delimiters,c=t.bMarks[a]+t.tShift[a],u=t.eMarks[a],f=(i,s,l)=>{t.line=s;const m=t.push("math_block",e.tag,0);return m.attrSet("class",e.className),m.block=!0,m.content=i,m.map=[a,t.line],m.markup=l,!0};for(const i of d){const s=c;if(t.src.slice(s,s+i.open.length)!==i.open)continue;const l=s+i.open.length,m=t.src.slice(l,u).trim(),g=m==="",v=m===i.close,b=m.endsWith(i.close);if(!g&&!v&&!b)continue;if(n)return!0;if(v)return f("",a+1,i.open);if(!g&&b){const w=m.slice(0,-i.close.length);return f(w,a+1,i.open)}let y=a+1,E=!1,x="";for(;y<o;y++){const w=t.bMarks[y]+t.tShift[y],T=t.eMarks[y];if(w<T&&t.tShift[y]<t.blkIndent)break;if(t.src.slice(w,T).trim().endsWith(i.close)){const R=t.src.slice(0,T).lastIndexOf(i.close);x=t.src.slice(w,R),E=!0;break}}if(!E)continue;const I=t.getLines(a+1,y,t.tShift[a],!0)+(x.trim()?x:"");return f(I,y+1,i.open)}return!1},ze=(e,{katexRef:t,inlineDelimiters:a,blockDelimiters:o})=>{const n=(u,f,i=!1)=>{if(!t.value)return K(u,e.utils.escapeHtml(u.content),f);const s=t.value.renderToString(u.content,p.globalConfig.katexConfig({throwOnError:!1,displayMode:i}));return u.attrSet("data-processed",""),K(u,String(s),f)},d=(u,f,i,s,l)=>n(u[f],l),c=(u,f,i,s,l)=>n(u[f],l,!0);e.inline.ruler.before("escape","math_inline",Ue({delimiters:a||re.inline,className:`${p.prefix}-katex-inline`,tag:"span"})),e.block.ruler.after("blockquote","math_block",qe({delimiters:o||re.block,className:`${p.prefix}-katex-block`,tag:"p"}),{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.math_inline=d,e.renderer.rules.math_block=c},We=(e,t)=>{e.core.ruler.after("block","mermaid-token-attrs",o=>{o.tokens.forEach(n=>{if(!(n.type!=="fence"||n.info!=="mermaid")&&(n.tag="div",n.attrJoin("class",`${p.prefix}-mermaid`),n.attrSet("data-mermaid-theme",t.themeRef.value),n.map&&n.level===0)){const d=n.map[1]-1,u=!!o.env.srcLines?.[d]?.trim()?.startsWith("```");n.attrSet("data-closed",`${u}`),n.attrSet("data-line",String(n.map[0]))}})});const a=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,n,d,c,u)=>{const f=o[n],i=f.content.trim();if(f.info==="mermaid"){const s=Z.get(i);return s?(f.tag="p",f.attrSet("data-processed",""),f.attrSet("data-content",i),K(f,s,u)):K(f,e.utils.escapeHtml(i),u)}return a(o,n,d,c,u)}},ae=(e,t,a)=>{const o=e.attrIndex(t),n=[t,a];o<0?e.attrPush(n):(e.attrs=e.attrs||[],e.attrs[o]=n)},Ke=e=>e.type==="inline",Ze=e=>e.type==="paragraph_open",Je=e=>e.type==="list_item_open",Xe=e=>e.content.indexOf("[ ] ")===0||e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0,Ye=(e,t)=>Ke(e[t])&&Ze(e[t-1])&&Je(e[t-2])&&Xe(e[t]),Qe=(e,t)=>{const a=e[t].level-1;for(let o=t-1;o>=0;o--)if(e[o].level===a)return o;return-1},et=e=>{const t=new e("html_inline","",0);return t.content="<label>",t},tt=e=>{const t=new e("html_inline","",0);return t.content="</label>",t},nt=(e,t,a)=>{const o=new a("html_inline","",0);return o.content='<label class="task-list-item-label" for="'+t+'">'+e+"</label>",o.attrs=[["for",t]],o},ot=(e,t,a)=>{const o=new t("html_inline","",0),n=a.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},rt=(e,t,a)=>{if(e.children=e.children||[],e.children.unshift(ot(e,t,a)),e.children[1].content=e.children[1].content.slice(3),e.content=e.content.slice(3),a.label)if(a.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(nt(e.content,o,t))}else e.children.unshift(et(t)),e.children.push(tt(t))},at=(e,t={})=>{e.core.ruler.after("inline","github-task-lists",a=>{const o=a.tokens;for(let n=2;n<o.length;n++)Ye(o,n)&&(rt(o[n],a.Token,t),ae(o[n-2],"class","task-list-item"+(t.enabled?" enabled":" ")),ae(o[Qe(o,n-2)],"class","contains-task-list"))})},it=e=>{e.core.ruler.push("init-line-number",t=>(t.tokens.forEach(a=>{a.map&&a.attrSet("data-line",a.map[0].toString())}),!0))},lt=(e,t)=>{const{editorConfig:a,markdownItConfig:o,markdownItPlugins:n,editorExtensions:d}=p.globalConfig,c=r.inject("editorId"),u=r.inject("language"),f=r.inject("usedLanguageText"),i=r.inject("showCodeRowNumber"),s=r.inject("theme"),l=r.inject("customIcon"),m=r.inject("rootRef"),g=r.inject("setting"),v=r.ref([]),b=_e(e),y=Fe(e),{reRenderRef:E,replaceMermaid:x}=Pe(e),{reRenderEcharts:C,replaceEcharts:I}=Le(e),w=be({html:!1,breaks:!0,linkify:!0});o(w,{editorId:c});const T=[{type:"image",plugin:ye,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:Ne,options:{}},{type:"taskList",plugin:at,options:{}},{type:"heading",plugin:Ge,options:{mdHeadingId:e.mdHeadingId,headsRef:v}},{type:"code",plugin:Be,options:{editorId:c,usedLanguageTextRef:f,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,customIconRef:l}},{type:"sub",plugin:xe,options:{}},{type:"sup",plugin:Ce,options:{}}];e.noKatex||T.push({type:"katex",plugin:ze,options:{katexRef:y}}),e.noMermaid||T.push({type:"mermaid",plugin:We,options:{themeRef:s}}),e.noEcharts||T.push({type:"echarts",plugin:Ve,options:{themeRef:s}}),n(T,{editorId:c}).forEach(k=>{w.use(k.plugin,k.options)});const $=w.options.highlight;w.set({highlight:(k,G,P)=>{const U=J(G,P),{attrs:ee,language:N,lineHighlightRanges:q}=U;let S="";if($){const j=$(k,N,ee);if(j){const W=ne.prepareCustomCodeHighlight(j,k,{lineHighlightRanges:q,showLineNumber:i});if(W.shouldReturnDirectly)return W.html;S=W.html}}S||(!e.noHighlight&&b.value?b.value.getLanguage(N)?S=b.value.highlight(k,{language:N,ignoreIllegals:!0}).value:S=b.value.highlightAuto(k).value:S=w.utils.escapeHtml(k));const L=w.utils.escapeHtml(N);let z=`<span class="${p.prefix}-code-block">${S.replace(/^\n+|\n+$/g,"")}</span>`;return(i||q.length)&&(z=ne.generateCodeBlock(S,k,{lineHighlightRanges:q,showLineNumber:i})),`<pre><code class="language-${L}" language="${L}">${z}</code></pre>`}}),it(w);const R=r.ref(`_article-key_${O.randomId()}`),_=r.ref(e.sanitize(w.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
62
|
+
`)})));let M=()=>{},F=()=>{};const D=()=>{const k=m.value?.querySelectorAll(`#${c} p.${p.prefix}-mermaid:not([data-closed=false])`);F(),F=H.copyMermaid(k,{customIcon:l.value}),d.mermaid?.enableZoom&&(M(),M=H.zoomMermaid(k,{customIcon:l.value}))},B=()=>{h.bus.emit(c,h.BUILD_FINISHED,_.value),e.onHtmlChanged(_.value),e.onGetCatalog(v.value),h.bus.emit(c,h.CATALOG_CHANGED,v.value),r.nextTick(()=>{x().then(D),I()})},V=()=>{v.value=[],_.value=e.sanitize(w.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
63
|
+
`)}))},Q=r.computed(()=>(e.noKatex||!!y.value)&&(e.noHighlight||!!b.value));return r.watch([r.toRef(e,"modelValue"),Q,E,u],(k,G,P)=>{const U=window.setTimeout(()=>{V()},t?0:a.renderDelay);P(()=>{clearTimeout(U)})}),r.watch(()=>g.value.preview,()=>{g.value.preview&&r.nextTick(()=>{x().then(D),I(),h.bus.emit(c,h.CATALOG_CHANGED,v.value)})}),r.watch([_,C],()=>{B()}),r.onMounted(B),r.onMounted(()=>{h.bus.on(c,{name:h.PUSH_CATALOG,callback(){h.bus.emit(c,h.CATALOG_CHANGED,v.value)}}),h.bus.on(c,{name:h.RERENDER,callback:()=>{R.value=`_article-key_${O.randomId()}`,V()}})}),r.onBeforeUnmount(()=>{M(),F()}),{html:_,key:R}},st=(e,t)=>{const a=r.inject("editorId"),o=r.inject("setting"),{noImgZoomIn:n}=e,d=O.debounce(()=>{const c=document.querySelectorAll(`#${a}-preview img:not(.not-zoom):not(.medium-zoom-image)`);c.length!==0&&we(c,{background:"#00000073"})});r.onMounted(async()=>{!n&&o.value.preview&&await d()}),r.watch([t,()=>o.value.preview],async()=>{!n&&o.value.preview&&await d()})},ie={checked:{regexp:/- \[x\]/,value:"- [ ]"},unChecked:{regexp:/- \[\s\]/,value:"- [x]"}},ct=(e,t)=>{const a=r.inject("editorId"),o=r.inject("rootRef");let n=()=>{};const d=()=>{if(!o.value)return!1;const c=o.value.querySelectorAll(".task-list-item.enabled"),u=f=>{f.preventDefault();const i=f.target.checked?"unChecked":"checked",s=f.target.parentElement?.dataset.line;if(!s)return;const l=Number(s),m=e.modelValue.split(`
|
|
64
|
+
`),g=m[Number(l)].replace(ie[i].regexp,ie[i].value);e.previewOnly?(m[Number(l)]=g,e.onChange(m.join(`
|
|
65
|
+
`))):h.bus.emit(a,h.TASK_STATE_CHANGED,l+1,g)};c.forEach(f=>{f.addEventListener("click",u)}),n=()=>{c.forEach(f=>{f.removeEventListener("click",u)})}};r.onBeforeUnmount(()=>{n()}),r.watch([t],()=>{n(),r.nextTick(d)},{immediate:!0})},dt=(e,t,a)=>{const o=r.inject("setting"),n=()=>{r.nextTick(()=>{e.onRemount?.()})},d=c=>{c&&n()};r.watch([t,a],n),r.watch(()=>o.value.preview,d),r.watch(()=>o.value.htmlPreview,d),r.onMounted(n)},de={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},previewComponent:{type:[Object,Function],default:void 0}},ut={...de,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}},le=e=>{const a=new DOMParser().parseFromString(e,"text/html");return Array.from(a.body.childNodes)},ft=(e,t)=>e.nodeType!==t.nodeType?!1:e.nodeType===Node.TEXT_NODE||e.nodeType===Node.COMMENT_NODE?e.textContent===t.textContent:e.nodeType===Node.ELEMENT_NODE?e.outerHTML===t.outerHTML:e.isEqualNode?e.isEqualNode(t):!1,mt=r.defineComponent({name:"UpdateOnDemand",props:{id:{type:String,required:!0},class:{type:[String,Array,Object],required:!0},html:{type:String,required:!0}},setup(e){const t=r.ref(),a=e.html,o=(n,d)=>{if(!t.value)return;const c=t.value,u=Array.from(c.childNodes),f=Math.min(n.length,d.length);let i=-1;for(let l=0;l<f;l++)if(!ft(n[l],d[l])){i=l;break}if(i===-1)if(d.length>n.length)i=n.length;else if(n.length>d.length)i=d.length;else return;const s=Math.min(i,u.length);for(let l=u.length-1;l>=s;l--)u[l].remove();for(let l=i;l<n.length;l++)c.appendChild(n[l].cloneNode(!0))};return r.watch(()=>e.html,(n,d)=>{const c=le(n),u=le(d||"");o(c,u)}),()=>r.createVNode("div",{id:e.id,class:e.class,innerHTML:a,ref:t},null)}}),ue=r.defineComponent({name:"ContentPreview",props:de,setup(e){const t=r.inject("editorId"),a=r.inject("setting"),o=r.inject("previewTheme"),n=r.inject("showCodeRowNumber"),{html:d,key:c}=lt(e,e.previewOnly);Ae(e,d,c),st(e,d),ct(e,d),dt(e,d,c);const u=r.computed(()=>[`${p.prefix}-preview`,`${o?.value}-theme`,n&&`${p.prefix}-scrn`].filter(Boolean)),f=()=>{const i=`${t}-preview`;return e.previewComponent?r.h(e.previewComponent,{key:c.value,html:d.value,id:i,class:u.value}):r.createVNode(mt,{key:c.value,html:d.value,id:i,class:u.value},null)};return()=>r.createVNode(r.Fragment,null,[a.value.preview&&(e.previewOnly?f():r.createVNode("div",{id:`${t}-preview-wrapper`,class:`${p.prefix}-preview-wrapper`,key:"content-preview-wrapper"},[f()])),a.value.htmlPreview&&r.createVNode("div",{id:`${t}-html-wrapper`,class:`${p.prefix}-preview-wrapper`,key:"html-preview-wrapper"},[r.createVNode("div",{class:`${p.prefix}-html`},[d.value])])])}}),pt=({text:e})=>e,fe={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:pt},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},previewComponent:{type:[Object,Function],default:void 0}},ht={...fe,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:p.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:p.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}},me=["onHtmlChanged","onGetCatalog","onChange","onRemount","update:modelValue"],gt=[...me,"onSave","onUploadImg","onError","onBlur","onFocus","onInput","onDrop","onInputBoxWidthChange"],X=r.defineComponent({name:"MdPreview",props:fe,emits:me,setup(e,t){const{noKatex:a,noMermaid:o,noHighlight:n}=e,d=r.ref(),c=ce(e);se(e,{rootRef:d,editorId:c}),Ee(e,t,{editorId:c}),r.onBeforeUnmount(()=>{h.bus.clear(c)});const u=l=>{e.onChange?.(l),t.emit("onChange",l),t.emit("update:modelValue",l)},f=l=>{e.onHtmlChanged?.(l),t.emit("onHtmlChanged",l)},i=l=>{e.onGetCatalog?.(l),t.emit("onGetCatalog",l)},s=()=>{e.onRemount?.(),t.emit("onRemount")};return()=>r.createVNode("div",{id:c,class:[p.prefix,e.class,`${p.prefix}-previewOnly`],"data-theme":e.theme,style:e.style,ref:d},[r.createVNode(ue,{modelValue:e.modelValue,onChange:u,onHtmlChanged:f,onGetCatalog:i,mdHeadingId:e.mdHeadingId,noMermaid:o,sanitize:e.sanitize,noKatex:a,formatCopiedText:e.formatCopiedText,noHighlight:n,noImgZoomIn:e.noImgZoomIn,previewOnly:!0,sanitizeMermaid:e.sanitizeMermaid,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,onRemount:s,noEcharts:e.noEcharts,previewComponent:e.previewComponent},null)])}});X.install=e=>(e.component(X.name,X),e);exports.CDN_IDS=A;exports.ContentPreview=ue;exports.MdPreview=X;exports.contentProps=ut;exports.editorEmits=gt;exports.editorProps=ht;exports.emitReplace=Y;exports.useCatalog=He;exports.useConfig=ke;exports.useEditorId=ce;exports.useErrorCatcher=Se;exports.useExpansion=Te;exports.useExpose=Re;exports.useOnSave=Ie;exports.useProvide=$e;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
`),
|
|
1
|
+
"use strict";const d=require("./config.cjs"),w=/^<\s*(\/?)\s*([a-zA-Z][a-zA-Z0-9:_-]*)(?:\s[\s\S]*?)?\s*(\/?)>$/,A=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),S=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"),L=e=>{const n=e.replace(/\r\n?/g,`
|
|
2
|
+
`),t=n.endsWith(`
|
|
3
|
+
`)?n.slice(0,-1):n;return t?t.split(`
|
|
4
|
+
`):[""]},p=(e,n)=>{if(e.startsWith("<!--",n)){const s=e.indexOf("-->",n+4);return s===-1?-1:s+2}if(e.startsWith("<![CDATA[",n)){const s=e.indexOf("]]>",n+9);return s===-1?-1:s+2}let t="";for(let s=n+1;s<e.length;s+=1){const r=e[s];if(t){r===t&&(t="");continue}if(r==='"'||r==="'")t=r;else if(r===">")return s}return-1},x=e=>{const n=w.exec(e);if(!n)return null;const t=n[2].toLowerCase();return{isClosing:n[1]==="/",isSelfClosing:n[3]==="/"||A.has(t),name:t,source:e}},f=(e,n)=>{const t=e.indexOf("<",n);if(t===-1)return null;const s=p(e,t);return s===-1?null:{endIndex:s,parsedTag:x(e.slice(t,s+1)),startIndex:t}},H=e=>e.map(n=>n.openingTag).join(""),E=e=>[...e].reverse().map(n=>`</${n.name}>`).join(""),k=e=>{let n=0;for(;n<e.length;){const t=f(e,n),s=t?.startIndex??e.length;if(e.slice(n,s).trim())return!0;if(!t)return!1;n=t.endIndex+1}return!1},B=e=>{const n=f(e,0);if(!n||n.startIndex!==0||n.parsedTag?.name!=="pre"||n.parsedTag.isClosing||n.parsedTag.isSelfClosing)return null;let t=0,s=-1,r=n.endIndex+1;for(;r<e.length;){const i=f(e,r);if(!i)break;const o=i.parsedTag;if(!o){r=i.endIndex+1;continue}if(o.name==="pre"&&o.isClosing&&t===0)break;if(o.name==="code")if(o.isClosing){if(t>0&&(t-=1,t===0))return{endIndex:i.startIndex,startIndex:s}}else o.isSelfClosing||(t===0&&(s=i.endIndex+1),t+=1);r=i.endIndex+1}return null},M=e=>{const n=e.replace(/\r\n?/g,`
|
|
5
|
+
`),t=[""],s=[];let r=0,i=0;for(;i<n.length;){const o=n[i];if(o==="<"){const l=p(n,i);if(l===-1){t[r]+=n.slice(i);break}const g=n.slice(i,l+1),c=x(g);if(t[r]+=g,c)if(c.isClosing){for(let a=s.length-1;a>=0;a-=1)if(s[a].name===c.name){s.splice(a,1);break}}else c.isSelfClosing||s.push({name:c.name,openingTag:c.source});i=l+1;continue}if(o===`
|
|
6
|
+
`){t[r]+=E(s),t.push(H(s)),r+=1,i+=1;continue}t[r]+=o,i+=1}return t},y=(e,n="image.png")=>{const t=e.split(","),s=t[0].match(/:(.*?);/);if(s){const r=s[1],i=atob(t[1]);let o=i.length;const l=new Uint8Array(o);for(;o--;)l[o]=i.charCodeAt(o);return new File([l],n,{type:r})}return null},I=(e,n,t={})=>{const{lineHighlightRanges:s=[],showLineNumber:r=!1}=t,i=L(n),o=M(e);for(;o.length>i.length&&!k(o[o.length-1]);)o.pop();const l=o.length===i.length,g=i.map((a,h)=>{const m=l?o[h]:S(a),u=h+1,C=s.some(({start:$,end:R})=>u>=$&&u<=R),T=[`${d.prefix}-code-line`,r?`${d.prefix}-code-line-numbered`:"",C?`${d.prefix}-code-line-highlight`:""].filter(Boolean).join(" "),b=r?`<span rn-wrapper aria-hidden="true" data-line-number="${u}"></span>`:"";return[`<span class="${T}">`,b,`<span class="${d.prefix}-code-line-content">${m}</span>`,"</span>"].join("")}),c=r?` style="--md-code-line-number-width: ${Math.max(2,String(i.length).length)+.5}ch;"`:"";return`<span class="${d.prefix}-code-block-lines"${c}>${g.join(`
|
|
7
|
+
`)}</span>`},D=(e,n,t={})=>{const s=B(e);if(!s)return null;const r=I(e.slice(s.startIndex,s.endIndex),n,t);return`${e.slice(0,s.startIndex)}${r}${e.slice(s.endIndex)}`},G=(e,n,t={})=>{const{lineHighlightRanges:s=[],showLineNumber:r=!1}=t;return!r&&!s.length?{html:e,shouldReturnDirectly:!0}:e.startsWith("<pre")?{html:D(e,n,t)??e,shouldReturnDirectly:!0}:{html:e,shouldReturnDirectly:!1}},N=(e,n)=>{if(!e||!n)return 0;const t=e?.getBoundingClientRect();if(n===document.documentElement)return t.top-n.clientTop;const s=n?.getBoundingClientRect();return t.top-s.top},j=(()=>{let e=0;return()=>++e})();exports.base642File=y;exports.generateCodeBlock=I;exports.getRelativeTop=N;exports.getZIndexIncrement=j;exports.prepareCustomCodeHighlight=G;
|
package/lib/es/MdEditor.mjs
CHANGED
|
@@ -2633,7 +2633,7 @@ const Xe = (e) => e.extension instanceof Function ? e.extension(e.options) : e.e
|
|
|
2633
2633
|
let y = h.x - p;
|
|
2634
2634
|
y / g < le ? y = g * le : y > g - g * le && (y = g - g * le);
|
|
2635
2635
|
const I = `${y / g * 100}%`;
|
|
2636
|
-
c.width = I, d.insetInlineStart = I, s.resizedWidth = I, e.
|
|
2636
|
+
c.width = I, d.insetInlineStart = I, s.resizedWidth = I, e.onInputBoxWidthChange?.(I);
|
|
2637
2637
|
}, v = (h) => {
|
|
2638
2638
|
h.target === o.value && document.addEventListener("mousemove", u);
|
|
2639
2639
|
}, m = () => {
|
|
@@ -3111,7 +3111,7 @@ const Xe = (e) => e.extension instanceof Function ? e.extension(e.options) : e.e
|
|
|
3111
3111
|
}, E = (C) => {
|
|
3112
3112
|
e.onDrop?.(C), t.emit("onDrop", C);
|
|
3113
3113
|
}, $ = (C) => {
|
|
3114
|
-
e.
|
|
3114
|
+
e.onInputBoxWidthChange?.(C), t.emit("onInputBoxWidthChange", C);
|
|
3115
3115
|
}, V = () => {
|
|
3116
3116
|
e.onRemount?.(), t.emit("onRemount");
|
|
3117
3117
|
}, _ = (C) => {
|
|
@@ -3119,7 +3119,8 @@ const Xe = (e) => e.extension instanceof Function ? e.extension(e.options) : e.e
|
|
|
3119
3119
|
};
|
|
3120
3120
|
return () => a("div", {
|
|
3121
3121
|
id: m,
|
|
3122
|
-
class: [l, e.class,
|
|
3122
|
+
class: [l, e.class, h.fullscreen || h.pageFullscreen ? `${l}-fullscreen` : ""],
|
|
3123
|
+
"data-theme": e.theme,
|
|
3123
3124
|
style: e.style,
|
|
3124
3125
|
ref: c
|
|
3125
3126
|
}, [e.toolbars.length > 0 && a(ol, {
|
|
@@ -3151,7 +3152,7 @@ const Xe = (e) => e.extension instanceof Function ? e.extension(e.options) : e.e
|
|
|
3151
3152
|
noImgZoomIn: e.noImgZoomIn,
|
|
3152
3153
|
onDrop: E,
|
|
3153
3154
|
inputBoxWidth: e.inputBoxWidth,
|
|
3154
|
-
|
|
3155
|
+
onInputBoxWidthChange: $,
|
|
3155
3156
|
sanitizeMermaid: e.sanitizeMermaid,
|
|
3156
3157
|
transformImgUrl: e.transformImgUrl,
|
|
3157
3158
|
codeFoldable: e.codeFoldable,
|