md-editor-v3 6.5.3 → 6.5.4
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/index3.cjs +1 -1
- package/lib/cjs/chunks/index4.cjs +42 -42
- package/lib/es/chunks/index3.mjs +183 -184
- package/lib/es/chunks/index4.mjs +649 -647
- package/lib/types/index.d.ts +5 -5
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("vue"),R=require("./config.cjs"),
|
|
1
|
+
"use strict";const o=require("vue"),R=require("./config.cjs"),x=require("./event-bus.cjs"),F=require("./index5.cjs"),P=require("@vavt/util"),G=`.${R.prefix}-preview > [data-line]`,D=(e,l)=>+getComputedStyle(e).getPropertyValue(l).replace("px",""),j=(e,l)=>{const I=P.debounce(()=>{e.removeEventListener("scroll",c),e.addEventListener("scroll",c),l.removeEventListener("scroll",c),l.addEventListener("scroll",c)},50),c=k=>{const u=e.clientHeight,y=l.clientHeight,m=e.scrollHeight,d=l.scrollHeight,s=(m-u)/(d-y);k.target===e?(l.removeEventListener("scroll",c),l.scrollTo({top:e.scrollTop/s}),I()):(e.removeEventListener("scroll",c),e.scrollTo({top:l.scrollTop*s}),I())};return[()=>{I().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",c),l.removeEventListener("scroll",c)}]},U=(e,l,I)=>{const{view:c}=I,k=P.createSmoothScroll(),u=r=>c.lineBlockAt(c.state.doc.line(r+1).from).top,y=r=>c.lineBlockAt(c.state.doc.line(r+1).from).bottom;let m=[],d=[],s=[];const N=()=>{m=[],d=Array.from(l.querySelectorAll(G)),s=d.map(n=>Number(n.dataset.line));const r=[...s],{lines:h}=c.state.doc;r[0]!==0&&r.unshift(0);let C=r.shift()||0,t=r.shift()||h;for(let n=0;n<h;n++)n===t&&(C=n,t=r.shift()||h),m.push({start:C,end:t-1})},w=(r,h)=>{let C=1;for(let t=d.length-1;t-1>=0;t--){const n=d[t];if(n.offsetTop<=h){C=Number(n.dataset.line);break}}for(let t=m.length-1;t>=0;t--)if(u(m[t].start)<=r){C=C<m[t].start?C:m[t].start;break}return C};let A=0,$=0;const V=()=>{if($!==0)return!1;A++;const{scrollDOM:r}=c;let h=D(l,"padding-block-start");const C=c.lineBlockAtHeight(r.scrollTop),{number:t}=c.state.doc.lineAt(C.from),n=m[t-1];if(!n)return!1;let H=1;const f=l.querySelector(`[data-line="${n.start}"]`)||l.firstElementChild?.firstElementChild,v=l.querySelector(`[data-line="${n.end+1}"]`)||l.lastElementChild?.lastElementChild,g=r.scrollHeight-r.clientHeight,i=l.scrollHeight-l.clientHeight;let T=u(n.start),p=y(n.end),a=f.offsetTop,S=v.offsetTop-a;T===0&&(a=0,f===v?(h=0,S=0):S=v.offsetTop),H=(r.scrollTop-T)/(p-T);const M=v==l.lastElementChild?.lastElementChild?v.offsetTop+v.clientHeight:v.offsetTop;if(p>=g||M>i){const L=w(g,i);T=u(L),H=(r.scrollTop-T)/(g-T);const E=l.querySelector(`[data-line="${L}"]`);T>0&&E&&(a=E.offsetTop),S=i-a+D(l,"padding-block-start")}const q=a-h+S*H;k(l,q,()=>{A--})},B=()=>{if(A!==0)return;$++;const{scrollDOM:r}=c,h=l.scrollTop,C=l.scrollHeight,t=r.scrollHeight-r.clientHeight,n=l.scrollHeight-l.clientHeight;let H=l.firstElementChild?.firstElementChild,f=l.firstElementChild?.lastElementChild;if(s.length>0){let L=Math.ceil(s[s.length-1]*(h/C)),E=s.findLastIndex(b=>b<=L);E=E===-1?0:E,L=s[E];for(let b=E;b>=0&&b<s.length;)if(d[b].offsetTop>h){if(b-1>=0){b--;continue}L=-1,E=-1;break}else{if(b+1<s.length&&d[b+1].offsetTop<h){b++;continue}L=s[b],E=b;break}switch(E){case-1:{H=l.firstElementChild?.firstElementChild,f=d[0];break}case s.length-1:{H=d[E],f=l.firstElementChild?.lastElementChild;break}default:H=d[E],f=d[E+1]}}let v=H===l.firstElementChild?.firstElementChild?0:H.offsetTop-D(H,"margin-block-start"),g=f.offsetTop,i=0;const{start:T,end:p}=m[Number(H.dataset.line||0)];let a=u(T);const S=u(p+1===c.state.doc.lines?p:p+1);let M=0;const q=f==l.lastElementChild?.lastElementChild?f.offsetTop+f.offsetHeight:f.offsetTop;if(S>t||q>n){const L=w(t,n),E=l.querySelector(`[data-line="${L}"]`);v=E?E.offsetTop-D(E,"margin-block-start"):v,a=u(L),i=(h-v)/(n-v),M=t-a}else H===l.firstElementChild?.firstElementChild?(H===f&&(g=f.offsetTop+f.offsetHeight+D(f,"margin-block-end")),M=S,a=0,i=Math.max(h/g,0)):(i=Math.max((h-v)/(g-v),0),M=S-a);k(e,a+M*i,()=>{$--})},O=r=>{const{scrollDOM:h,contentHeight:C}=c,t=h.clientHeight;if(C<=t||l.firstElementChild.clientHeight<=l.clientHeight||c.state.doc.lines<=m[m.length-1]?.end)return!1;r.target===e?V():B()};return[()=>{N(),e.addEventListener("scroll",O),l.addEventListener("scroll",O),e.dispatchEvent(new Event("scroll"))},()=>{e.removeEventListener("scroll",O),l.removeEventListener("scroll",O)}]},z={tocItem:{type:Object,default:()=>({})},mdHeadingId:{type:Function,default:()=>{}},onActive:{type:Function,default:()=>{}},onClick:{type:Function,default:()=>{}},scrollElementOffsetTop:{type:Number,default:0}},W=o.defineComponent({props:z,setup(e){const l=o.inject("scrollElementRef"),I=o.inject("roorNodeRef"),c=o.ref();o.watch(()=>e.tocItem.active,u=>{u&&e.onActive(e.tocItem,c.value)}),o.onMounted(()=>{e.tocItem.active&&e.onActive(e.tocItem,c.value)});const k=u=>{if(u.stopPropagation(),e.onClick(u,e.tocItem),u.defaultPrevented)return;const y=e.mdHeadingId({text:e.tocItem.text,level:e.tocItem.level,index:e.tocItem.index,currentToken:e.tocItem.currentToken,nextToken:e.tocItem.nextToken}),m=I.value.getElementById(y),d=l.value;if(m&&d){let s=m.offsetParent,N=m.offsetTop;if(d.contains(s))for(;s&&d!=s;)N+=s?.offsetTop,s=s?.offsetParent;const w=m.previousElementSibling;let A=0;w||(A=D(m,"margin-block-start")),d?.scrollTo({top:N-e.scrollElementOffsetTop-A,behavior:"smooth"})}};return()=>o.createVNode("div",{ref:c,class:[`${R.prefix}-catalog-link`,e.tocItem.active&&`${R.prefix}-catalog-active`],onClick:k},[o.createVNode("span",{title:e.tocItem.text},[e.tocItem.text]),e.tocItem.children&&e.tocItem.children.length>0&&o.createVNode("div",{class:`${R.prefix}-catalog-wrapper`},[e.tocItem.children.map(u=>o.createVNode(W,{mdHeadingId:e.mdHeadingId,key:`${e.tocItem.text}-link-${u.level}-${u.text}`,tocItem:u,onActive:e.onActive,onClick:e.onClick,scrollElementOffsetTop:e.scrollElementOffsetTop},null))])])}}),J={editorId:{type:String,default:void 0},class:{type:String,default:""},mdHeadingId:{type:Function,default:({text:e})=>e},scrollElement:{type:[String,Object],default:void 0},theme:{type:String,default:"light"},offsetTop:{type:Number,default:20},scrollElementOffsetTop:{type:Number,default:0},onClick:{type:Function,default:void 0},onActive:{type:Function,default:void 0},isScrollElementInShadow:{type:Boolean,default:!1},syncWith:{type:String,default:"preview"},catalogMaxDepth:{type:Number,default:void 0}},_=o.defineComponent({name:"MdCatalog",props:J,emits:["onClick","onActive"],setup(e,l){const I=e.editorId,c=`#${I}-preview-wrapper`,k=o.reactive({list:[],show:!1,scrollElement:e.scrollElement||c}),u=o.shallowRef(),y=o.ref(),m=o.ref(),d=o.ref(),s=o.ref(),N=o.shallowRef(),w=o.ref({});o.provide("scrollElementRef",m),o.provide("roorNodeRef",s);const A=o.computed(()=>{const t=[];return k.list.forEach((n,H)=>{if(e.catalogMaxDepth&&n.level>e.catalogMaxDepth)return;const{text:f,level:v,line:g}=n,i={level:v,text:f,line:g,index:H+1,active:u.value===n};if(t.length===0)t.push(i);else{let T=t[t.length-1];if(i.level>T.level)for(let p=T.level+1;p<=6;p++){const{children:a}=T;if(!a){T.children=[i];break}if(T=a[a.length-1],i.level<=T.level){a.push(i);break}}else t.push(i)}}),t}),$=()=>{if(k.scrollElement instanceof HTMLElement)return k.scrollElement;let t=document;return(k.scrollElement===c||e.isScrollElementInShadow)&&(t=y.value?.getRootNode()),t.querySelector(k.scrollElement)},V=t=>{if(t.length===0)return u.value=void 0,k.list=[],!1;const{activeHead:n,activeIndex:H}=t.reduce((g,i,T)=>{let p=0;if(e.syncWith==="preview"){const a=s.value?.getElementById(e.mdHeadingId({text:i.text,level:i.level,index:T+1,currentToken:i.currentToken,nextToken:i.nextToken}));a instanceof HTMLElement&&(p=F.getRelativeTop(a,m.value))}else{const a=N.value;if(a){const S=a.lineBlockAt(a.state.doc.line(i.line+1).from).top,M=a.scrollDOM.scrollTop;p=S-M}}return p<e.offsetTop&&p>g.minTop?{activeHead:i,activeIndex:T,minTop:p}:g},{activeHead:t[0],activeIndex:0,minTop:Number.MIN_SAFE_INTEGER});let f=n;const{catalogMaxDepth:v}=e;if(v&&f.level>v){for(let g=H;g>=0;g--){const i=t[g];if(i.level<=v){f=i;break}}if(f.level>v){const g=t.find(i=>i.level<=v);g&&(f=g)}}u.value=f,k.list=t},B=(t,n)=>{w.value.top=n.offsetTop+D(n,"padding-block-start")+"px",e.onActive?.(t,n),l.emit("onActive",t,n)},O=()=>{V(k.list)},r=t=>{if(d.value?.removeEventListener("scroll",O),e.syncWith==="editor")d.value=N.value?.scrollDOM;else{const n=$();m.value=n,d.value=n===document.documentElement?document:n}V(t),d.value?.addEventListener("scroll",O)},h=t=>{N.value=t};o.watch([()=>e.syncWith,N,()=>e.catalogMaxDepth],()=>{r(k.list)}),o.onMounted(()=>{s.value=y.value.getRootNode(),x.bus.on(I,{name:x.CATALOG_CHANGED,callback:r}),x.bus.on(I,{name:x.GET_EDITOR_VIEW,callback:h}),x.bus.emit(I,x.PUSH_CATALOG),x.bus.emit(I,x.SEND_EDITOR_VIEW)}),o.onBeforeUnmount(()=>{x.bus.remove(I,x.CATALOG_CHANGED,r),x.bus.remove(I,x.GET_EDITOR_VIEW,h),d.value?.removeEventListener("scroll",O)});const C=(t,n)=>{e.onClick?.(t,n),l.emit("onClick",t,n)};return()=>o.createVNode("div",{class:[`${R.prefix}-catalog`,e.theme==="dark"&&`${R.prefix}-catalog-dark`,e.class||""],ref:y},[A.value.length>0&&o.createVNode(o.Fragment,null,[o.createVNode("div",{class:`${R.prefix}-catalog-indicator`,style:w.value},null),o.createVNode("div",{class:`${R.prefix}-catalog-container`},[A.value.map(t=>o.createVNode(W,{mdHeadingId:e.mdHeadingId,tocItem:t,key:`link-${t.level}-${t.text}`,onActive:B,onClick:C,scrollElementOffsetTop:e.scrollElementOffsetTop},null))])])])}});_.install=e=>(e.component(_.name,_),e);exports.MdCatalog=_;exports.scrollAuto=U;exports.scrollAutoWithScale=j;
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";const n=require("vue"),j=require("@vavt/util"),h=require("./config.cjs"),p=require("./event-bus.cjs"),S=require("./dom.cjs"),re=require("@vavt/copy2clipboard"),ie=require("markdown-it"),ae=require("markdown-it-image-figures"),le=require("markdown-it-sub"),se=require("markdown-it-sup"),ce=require("./index5.cjs"),de=require("medium-zoom"),A={hljs:`${h.prefix}-hljs`,hlcss:`${h.prefix}-hlCss`,prettier:`${h.prefix}-prettier`,prettierMD:`${h.prefix}-prettierMD`,cropperjs:`${h.prefix}-cropper`,croppercss:`${h.prefix}-cropperCss`,screenfull:`${h.prefix}-screenfull`,mermaidM:`${h.prefix}-mermaid-m`,mermaid:`${h.prefix}-mermaid`,katexjs:`${h.prefix}-katex`,katexcss:`${h.prefix}-katexCss`,echarts:`${h.prefix}-echarts`},ue=(e,t,a)=>{const{editorId:o}=a,r=n.reactive({buildFinished:!1,html:""});n.watch(()=>e.modelValue,()=>{r.buildFinished=!1}),n.onMounted(()=>{p.bus.on(o,{name:p.BUILD_FINISHED,callback(m){r.buildFinished=!0,r.html=m}}),p.bus.on(o,{name:p.ON_SAVE,callback(){const m=new Promise(u=>{if(r.buildFinished)u(r.html);else{const f=c=>{u(c),p.bus.remove(o,p.BUILD_FINISHED,f)};p.bus.on(o,{name:p.BUILD_FINISHED,callback:f})}});e.onSave?e.onSave(e.modelValue,m):t.emit("onSave",e.modelValue,m)}})})},Y=(e,{editorId:t,rootRef:a,setting:o})=>{const r=h.globalConfig.editorExtensions.highlight,m=h.globalConfig.editorExtensionsAttrs.highlight;n.provide("editorId",t),n.provide("rootRef",a),n.provide("theme",n.computed(()=>e.theme)),n.provide("language",n.computed(()=>e.language)),n.provide("highlight",n.computed(()=>{const{js:f}=r,c={...h.codeCss,...r.css},{js:l,css:s={}}=m||{},i=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,d=c[e.codeTheme]?c[e.codeTheme][i]:h.codeCss.atom[i],x=c[e.codeTheme]&&s[e.codeTheme]?s[e.codeTheme][i]:s.atom?s.atom[i]:{};return{js:{src:f,...l},css:{href:d,...x}}})),n.provide("showCodeRowNumber",e.showCodeRowNumber);const u=n.computed(()=>{const f={...h.staticTextDefault,...h.globalConfig.editorConfig.languageUserDefined};return j.deepMerge(j.deepClone(h.staticTextDefault["en-US"]),f[e.language]||{})});return n.provide("usedLanguageText",u),n.provide("previewTheme",n.computed(()=>e.previewTheme)),n.provide("customIcon",n.computed(()=>e.customIcon)),n.provide("setting",n.computed(()=>o?{...o}:{preview:!0,htmlPreview:!1,previewOnly:!1,pageFullscreen:!1,fullscreen:!1})),{editorId:t}},fe=(e,t)=>(n.provide("tabWidth",e.tabWidth),n.provide("disabled",n.computed(()=>e.disabled)),n.provide("showToolbarName",n.computed(()=>e.showToolbarName)),n.provide("noUploadImg",e.noUploadImg),n.provide("tableShape",n.computed(()=>e.tableShape)),n.provide("noPrettier",e.noPrettier),n.provide("codeTheme",n.computed(()=>e.codeTheme)),n.provide("updateSetting",t.updateSetting),n.provide("catalogVisible",n.computed(()=>t.catalogVisible.value)),n.provide("defToolbars",t.defToolbars),n.provide("floatingToolbars",n.computed(()=>e.floatingToolbars)),Y(e,t)),me=e=>{const{noPrettier:t,noUploadImg:a}=e,{editorExtensions:o,editorExtensionsAttrs:r}=h.globalConfig,m=t||o.prettier.prettierInstance,u=t||o.prettier.parserMarkdownInstance,f=a||o.cropper.instance;n.onMounted(()=>{if(!f){const{js:c={},css:l={}}=r.cropper||{};S.appendHandler("link",{...l,rel:"stylesheet",href:o.cropper.css,id:A.croppercss}),S.appendHandler("script",{...c,src:o.cropper.js,id:A.cropperjs})}if(!m){const{standaloneJs:c={}}=r.prettier||{};S.appendHandler("script",{...c,src:o.prettier.standaloneJs,id:A.prettier})}if(!u){const{parserMarkdownJs:c={}}=r.prettier||{};S.appendHandler("script",{...c,src:o.prettier.parserMarkdownJs,id:A.prettierMD})}})},pe=(e,t,a)=>{const{editorId:o}=a;n.onMounted(()=>{p.bus.on(o,{name:p.ERROR_CATCHER,callback:r=>{e.onError?.(r),t.emit("onError",r)}})})},he=(e,t,a)=>{const{editorId:o}=a,r=n.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),m=n.reactive({...r}),u=(l,s)=>{const i=s===void 0?!r[l]:s;switch(l){case"preview":{r.htmlPreview=!1,r.previewOnly=!1;break}case"htmlPreview":{r.preview=!1,r.previewOnly=!1;break}case"previewOnly":{i?!r.preview&&!r.htmlPreview&&(r.preview=!0):(m.preview||(r.preview=!1),m.htmlPreview||(r.htmlPreview=!1));break}}m[l]=i,r[l]=i};let f="";const c=()=>{r.pageFullscreen||r.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=f};return n.watch(()=>[r.pageFullscreen,r.fullscreen],c),n.onMounted(()=>{p.bus.on(o,{name:p.UPLOAD_IMAGE,callback(l,s){const i=d=>{p.bus.emit(o,p.REPLACE,"image",{desc:"",urls:d}),s?.()};e.onUploadImg?e.onUploadImg(l,i):t.emit("onUploadImg",l,i)}}),f=document.body.style.overflow,c()}),[r,u]},ge=(e,t)=>{const{editorId:a}=t,o=n.ref(!1);return n.onMounted(()=>{p.bus.on(a,{name:p.CHANGE_CATALOG_VISIBLE,callback:r=>{r===void 0?o.value=!o.value:o.value=r}})}),o},ve=(e,t,a)=>{const{editorId:o,catalogVisible:r,setting:m,updateSetting:u,codeRef:f}=a;n.watch(()=>m.pageFullscreen,l=>{p.bus.emit(o,p.PAGE_FULL_SCREEN_CHANGED,l)}),n.watch(()=>m.fullscreen,l=>{p.bus.emit(o,p.FULL_SCREEN_CHANGED,l)}),n.watch(()=>m.preview,l=>{p.bus.emit(o,p.PREVIEW_CHANGED,l)}),n.watch(()=>m.previewOnly,l=>{p.bus.emit(o,p.PREVIEW_ONLY_CHANGED,l)}),n.watch(()=>m.htmlPreview,l=>{p.bus.emit(o,p.HTML_PREVIEW_CHANGED,l)}),n.watch(r,l=>{p.bus.emit(o,p.CATALOG_VISIBLE_CHANGED,l)});const c={on(l,s){switch(l){case"pageFullscreen":{p.bus.on(o,{name:p.PAGE_FULL_SCREEN_CHANGED,callback(i){s(i)}});break}case"fullscreen":{p.bus.on(o,{name:p.FULL_SCREEN_CHANGED,callback(i){s(i)}});break}case"preview":{p.bus.on(o,{name:p.PREVIEW_CHANGED,callback(i){s(i)}});break}case"previewOnly":{p.bus.on(o,{name:p.PREVIEW_ONLY_CHANGED,callback(i){s(i)}});break}case"htmlPreview":{p.bus.on(o,{name:p.HTML_PREVIEW_CHANGED,callback(i){s(i)}});break}case"catalog":{p.bus.on(o,{name:p.CATALOG_VISIBLE_CHANGED,callback(i){s(i)}});break}}},togglePageFullscreen(l){u("pageFullscreen",l)},toggleFullscreen(l){p.bus.emit(o,p.CHANGE_FULL_SCREEN,l)},togglePreview(l){u("preview",l)},togglePreviewOnly(l){u("previewOnly",l)},toggleHtmlPreview(l){u("htmlPreview",l)},toggleCatalog(l){p.bus.emit(o,p.CHANGE_CATALOG_VISIBLE,l)},triggerSave(){p.bus.emit(o,p.ON_SAVE)},insert(l){p.bus.emit(o,p.REPLACE,"universal",{generate:l})},focus(l){f.value?.focus(l)},rerender(){p.bus.emit(o,p.RERENDER)},getSelectedText(){return f.value?.getSelectedText()},resetHistory(){f.value?.resetHistory()},domEventHandlers(l){p.bus.emit(o,p.EVENT_LISTENER,l)},execCommand(l){p.bus.emit(o,p.REPLACE,l)},getEditorView(){return f.value?.getEditorView()}};t.expose(c)},Q=e=>{const t=n.useId();return e.id||e.editorId||`${h.prefix}-${t}`},be=(e,t,a)=>{const o=n.inject("editorId"),r=n.inject("rootRef"),m=n.inject("usedLanguageText"),u=n.inject("setting"),f=()=>{r.value.querySelectorAll(`#${o} .${h.prefix}-preview .${h.prefix}-code`).forEach(s=>{let i=-1;const d=s.querySelector(`.${h.prefix}-copy-button:not([data-processed])`);d&&(d.onclick=x=>{x.preventDefault(),clearTimeout(i);const b=(s.querySelector("input:checked + pre code")||s.querySelector("pre code")).textContent,{text:g,successTips:$,failTips:y}=m.value.copyCode;let C=$;re(e.formatCopiedText(b||"")).catch(()=>{C=y}).finally(()=>{d.dataset.isIcon?d.dataset.tips=C:d.innerHTML=C,i=window.setTimeout(()=>{d.dataset.isIcon?d.dataset.tips=g:d.innerHTML=g},1500)})},d.setAttribute("data-processed","true"))})},c=()=>{n.nextTick(f)},l=s=>{s&&n.nextTick(f)};n.watch([t,a],c),n.watch(()=>u.value.preview,l),n.watch(()=>u.value.htmlPreview,l),n.onMounted(f)},ye=e=>{const t=n.inject("editorId"),a=n.inject("theme"),o=n.inject("rootRef"),{editorExtensions:r,editorExtensionsAttrs:m,echartsConfig:u}=h.globalConfig;let f=r.echarts.instance;const c=n.shallowRef(-1),l=()=>{!e.noEcharts&&f&&(c.value=c.value+1)};n.watch(()=>a.value,()=>{l()}),n.onMounted(()=>{if(e.noEcharts||f)return;const b=r.echarts.js;S.appendHandler("script",{...m.echarts?.js,src:b,id:A.echarts,onload(){f=window.echarts,l()}},"echarts")});let s=[],i=[],d=[];const x=(b=!1)=>{if(!s.length){b&&(i.forEach(C=>{C.dispose?.()}),d.forEach(C=>{C.disconnect?.()}),i=[],d=[]);return}const g=[],$=[],y=[];s.forEach((C,T)=>{const w=i[T],k=d[T];if(b||!C||!C.isConnected||(o?.value?!o.value.contains(C):!1)){w?.dispose?.(),k?.disconnect?.();return}g.push(C),w&&$.push(w),k&&y.push(k)}),s=g,i=$,d=y},v=()=>{x(),!e.noEcharts&&f&&Array.from(o.value.querySelectorAll(`#${t} div.${h.prefix}-echarts:not([data-processed])`)).forEach(g=>{if(g.dataset.closed==="false")return!1;try{const $=r.echarts.parseOption(g.innerText,{editorId:t,element:g}),y=u($),C=f.init(g,a.value);C.setOption(y),g.setAttribute("data-processed",""),s.push(g),i.push(C);const T=new ResizeObserver(()=>{C.resize()});T.observe(g),d.push(T)}catch($){p.bus.emit(t,p.ERROR_CATCHER,{name:"echarts",message:$?.message,error:$})}})};return n.onBeforeUnmount(()=>{x(!0)}),{reRenderEcharts:c,replaceEcharts:v}},Ce=e=>{const t=n.inject("highlight"),a=n.shallowRef(h.globalConfig.editorExtensions.highlight.instance);return n.onMounted(()=>{e.noHighlight||a.value||(S.appendHandler("link",{...t.value.css,rel:"stylesheet",id:A.hlcss}),S.appendHandler("script",{...t.value.js,id:A.hljs,onload(){a.value=window.hljs}},"hljs"))}),n.watch(()=>t.value.css,()=>{e.noHighlight||h.globalConfig.editorExtensions.highlight.instance||S.updateHandler("link",{...t.value.css,rel:"stylesheet",id:A.hlcss})}),a},xe=e=>{const t=n.shallowRef(h.globalConfig.editorExtensions.katex.instance);return n.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:a,editorExtensionsAttrs:o}=h.globalConfig;S.appendHandler("script",{...o.katex?.js,src:a.katex.js,id:A.katexjs,onload(){t.value=window.katex}},"katex"),S.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:a.katex.css,id:A.katexcss})}),t};class we{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 U=new we({max:1e3,ttl:6e5}),Ee=e=>{const t=n.inject("editorId"),a=n.inject("theme"),o=n.inject("rootRef"),{editorExtensions:r,editorExtensionsAttrs:m,mermaidConfig:u}=h.globalConfig;let f=r.mermaid.instance;const c=n.shallowRef(-1),l=()=>{if(!e.noMermaid&&f){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"}};f.initialize(u(i)),c.value=c.value+1}};return n.watch(()=>a.value,()=>{U.clear(),l()}),n.onMounted(()=>{if(e.noMermaid||f)return;const i=r.mermaid.js;/\.mjs/.test(i)?(S.appendHandler("link",{...m.mermaid?.js,rel:"modulepreload",href:i,id:A.mermaidM}),import(i).then(d=>{f=d.default,l()}).catch(d=>{p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${d.message}`,error:d})})):S.appendHandler("script",{...m.mermaid?.js,src:i,id:A.mermaid,onload(){f=window.mermaid,l()}},"mermaid")}),{reRenderRef:c,replaceMermaid:async()=>{if(!e.noMermaid&&f){const i=o.value.querySelectorAll(`div.${h.prefix}-mermaid`),d=document.createElement("div"),x=document.body.offsetWidth>1366?document.body.offsetWidth:1366,v=document.body.offsetHeight>768?document.body.offsetHeight:768;d.style.width=x+"px",d.style.height=v+"px",d.style.position="fixed",d.style.zIndex="-10000",d.style.top="-10000";let b=i.length;b>0&&document.body.appendChild(d),await Promise.allSettled(Array.from(i).map(g=>(async y=>{if(y.dataset.closed==="false")return!1;const C=y.innerText;let T=U.get(C);if(!T){const w=j.randomId();let k={svg:""};try{k=await f.render(w,C,d),T=await e.sanitizeMermaid(k.svg);const I=document.createElement("p");I.className=`${h.prefix}-mermaid`,I.setAttribute("data-processed",""),I.setAttribute("data-content",C),I.innerHTML=T,I.children[0]?.removeAttribute("height"),U.set(C,I.innerHTML),y.dataset.line!==void 0&&(I.dataset.line=y.dataset.line),y.replaceWith(I)}catch(I){p.bus.emit(t,p.ERROR_CATCHER,{name:"mermaid",message:I.message,error:I})}--b===0&&d.remove()}})(g)))}}}},$e=(e,t)=>{t=t||{};const a=3,o=t.marker||"!",r=o.charCodeAt(0),m=o.length;let u="",f="";const c=(s,i,d,x,v)=>{const b=s[i];return b.type==="admonition_open"?s[i].attrPush(["class",`${h.prefix}-admonition ${h.prefix}-admonition-${b.info}`]):b.type==="admonition_title_open"&&s[i].attrPush(["class",`${h.prefix}-admonition-title`]),v.renderToken(s,i,d)},l=s=>{const i=s.trim().split(" ",2);f="",u=i[0],i.length>1&&(f=s.substring(u.length+2))};e.block.ruler.before("code","admonition",(s,i,d,x)=>{let v,b,g,$=!1,y=s.bMarks[i]+s.tShift[i],C=s.eMarks[i];if(r!==s.src.charCodeAt(y))return!1;for(v=y+1;v<=C&&o[(v-y)%m]===s.src[v];v++);const T=Math.floor((v-y)/m);if(T!==a)return!1;v-=(v-y)%m;const w=s.src.slice(y,v),k=s.src.slice(v,C);if(l(k),x)return!0;for(b=i;b++,!(b>=d||(y=s.bMarks[b]+s.tShift[b],C=s.eMarks[b],y<C&&s.sCount[b]<s.blkIndent));)if(r===s.src.charCodeAt(y)&&!(s.sCount[b]-s.blkIndent>=4)){for(v=y+1;v<=C&&o[(v-y)%m]===s.src[v];v++);if(!(Math.floor((v-y)/m)<T)&&(v-=(v-y)%m,v=s.skipSpaces(v),!(v<C))){$=!0;break}}const I=s.parentType,H=s.lineMax;return s.parentType="root",s.lineMax=b,g=s.push("admonition_open","div",1),g.markup=w,g.block=!0,g.info=u,g.map=[i,b],f&&(g=s.push("admonition_title_open","p",1),g.markup=w+" "+u,g.map=[i,b],g=s.push("inline","",0),g.content=f,g.map=[i,s.line-1],g.children=[],g=s.push("admonition_title_close","p",-1),g.markup=w+" "+u),s.md.block.tokenize(s,i+1,b),g=s.push("admonition_close","div",-1),g.markup=s.src.slice(y,v),g.block=!0,s.parentType=I,s.lineMax=H,s.line=b+($?1:0),!0},{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.admonition_open=c,e.renderer.rules.admonition_title_open=c,e.renderer.rules.admonition_title_close=c,e.renderer.rules.admonition_close=c},z=(e,t)=>{const a=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const r=e.attrIndex(o[0]);r<0?a.push(o):(a[r]=a[r].slice(),a[r][1]+=` ${o[1]}`)}),a},Ie=(e,t)=>{const a=e.renderer.rules.fence,o=e.utils.unescapeAll,r=/\[(\w*)(?::([\w ]*))?\]/,m=/::(open|close)/,u=i=>i.info?o(i.info).trim():"",f=i=>{const d=u(i),[x=null,v=""]=(r.exec(d)||[]).slice(1);return[x,v]},c=i=>{const d=u(i);return d?d.split(/(\s+)/g)[0]:""},l=i=>{const d=i.info.match(m)||[],x=d[1]==="open"||d[1]!=="close"&&t.codeFoldable&&i.content.trim().split(`
|
|
2
|
-
`).length<t.autoFoldThreshold,
|
|
3
|
-
<${
|
|
1
|
+
"use strict";const n=require("vue"),O=require("@vavt/util"),h=require("./config.cjs"),m=require("./event-bus.cjs"),S=require("./dom.cjs"),le=require("@vavt/copy2clipboard"),se=require("markdown-it"),ce=require("markdown-it-image-figures"),de=require("markdown-it-sub"),ue=require("markdown-it-sup"),fe=require("./index5.cjs"),pe=require("medium-zoom"),H={hljs:`${h.prefix}-hljs`,hlcss:`${h.prefix}-hlCss`,prettier:`${h.prefix}-prettier`,prettierMD:`${h.prefix}-prettierMD`,cropperjs:`${h.prefix}-cropper`,croppercss:`${h.prefix}-cropperCss`,screenfull:`${h.prefix}-screenfull`,mermaidM:`${h.prefix}-mermaid-m`,mermaid:`${h.prefix}-mermaid`,katexjs:`${h.prefix}-katex`,katexcss:`${h.prefix}-katexCss`,echarts:`${h.prefix}-echarts`},me=(e,t,i)=>{const{editorId:o}=i,r=n.reactive({buildFinished:!1,html:""});n.watch(()=>e.modelValue,()=>{r.buildFinished=!1}),n.onMounted(()=>{m.bus.on(o,{name:m.BUILD_FINISHED,callback(p){r.buildFinished=!0,r.html=p}}),m.bus.on(o,{name:m.ON_SAVE,callback(){const p=new Promise(d=>{if(r.buildFinished)d(r.html);else{const f=c=>{d(c),m.bus.remove(o,m.BUILD_FINISHED,f)};m.bus.on(o,{name:m.BUILD_FINISHED,callback:f})}});e.onSave?e.onSave(e.modelValue,p):t.emit("onSave",e.modelValue,p)}})})},Q=(e,{editorId:t,rootRef:i,setting:o})=>{const r=h.globalConfig.editorExtensions.highlight,p=h.globalConfig.editorExtensionsAttrs.highlight;n.provide("editorId",t),n.provide("rootRef",i),n.provide("theme",n.computed(()=>e.theme)),n.provide("language",n.computed(()=>e.language)),n.provide("highlight",n.computed(()=>{const{js:f}=r,c={...h.codeCss,...r.css},{js:l,css:s={}}=p||{},a=e.codeStyleReverse&&e.codeStyleReverseList.includes(e.previewTheme)?"dark":e.theme,u=c[e.codeTheme]?c[e.codeTheme][a]:h.codeCss.atom[a],g=c[e.codeTheme]&&s[e.codeTheme]?s[e.codeTheme][a]:s.atom?s.atom[a]:{};return{js:{src:f,...l},css:{href:u,...g}}})),n.provide("showCodeRowNumber",e.showCodeRowNumber);const d=n.computed(()=>{const f={...h.staticTextDefault,...h.globalConfig.editorConfig.languageUserDefined};return O.deepMerge(O.deepClone(h.staticTextDefault["en-US"]),f[e.language]||{})});return n.provide("usedLanguageText",d),n.provide("previewTheme",n.computed(()=>e.previewTheme)),n.provide("customIcon",n.computed(()=>e.customIcon)),n.provide("setting",n.computed(()=>o?{...o}:{preview:!0,htmlPreview:!1,previewOnly:!1,pageFullscreen:!1,fullscreen:!1})),{editorId:t}},he=(e,t)=>(n.provide("tabWidth",e.tabWidth),n.provide("disabled",n.computed(()=>e.disabled)),n.provide("showToolbarName",n.computed(()=>e.showToolbarName)),n.provide("noUploadImg",e.noUploadImg),n.provide("tableShape",n.computed(()=>e.tableShape)),n.provide("noPrettier",e.noPrettier),n.provide("codeTheme",n.computed(()=>e.codeTheme)),n.provide("updateSetting",t.updateSetting),n.provide("catalogVisible",n.computed(()=>t.catalogVisible.value)),n.provide("defToolbars",t.defToolbars),n.provide("floatingToolbars",n.computed(()=>e.floatingToolbars)),Q(e,t)),ge=e=>{const{noPrettier:t,noUploadImg:i}=e,{editorExtensions:o,editorExtensionsAttrs:r}=h.globalConfig,p=t||o.prettier.prettierInstance,d=t||o.prettier.parserMarkdownInstance,f=i||o.cropper.instance;n.onMounted(()=>{if(!f){const{js:c={},css:l={}}=r.cropper||{};S.appendHandler("link",{...l,rel:"stylesheet",href:o.cropper.css,id:H.croppercss}),S.appendHandler("script",{...c,src:o.cropper.js,id:H.cropperjs})}if(!p){const{standaloneJs:c={}}=r.prettier||{};S.appendHandler("script",{...c,src:o.prettier.standaloneJs,id:H.prettier})}if(!d){const{parserMarkdownJs:c={}}=r.prettier||{};S.appendHandler("script",{...c,src:o.prettier.parserMarkdownJs,id:H.prettierMD})}})},ve=(e,t,i)=>{const{editorId:o}=i;n.onMounted(()=>{m.bus.on(o,{name:m.ERROR_CATCHER,callback:r=>{e.onError?.(r),t.emit("onError",r)}})})},be=(e,t,i)=>{const{editorId:o}=i,r=n.reactive({pageFullscreen:e.pageFullscreen,fullscreen:!1,preview:e.preview,htmlPreview:e.preview?!1:e.htmlPreview,previewOnly:!1}),p=n.reactive({...r}),d=(l,s)=>{const a=s===void 0?!r[l]:s;switch(l){case"preview":{r.htmlPreview=!1,r.previewOnly=!1;break}case"htmlPreview":{r.preview=!1,r.previewOnly=!1;break}case"previewOnly":{a?!r.preview&&!r.htmlPreview&&(r.preview=!0):(p.preview||(r.preview=!1),p.htmlPreview||(r.htmlPreview=!1));break}}p[l]=a,r[l]=a};let f="";const c=()=>{r.pageFullscreen||r.fullscreen?document.body.style.overflow="hidden":document.body.style.overflow=f};return n.watch(()=>[r.pageFullscreen,r.fullscreen],c),n.onMounted(()=>{m.bus.on(o,{name:m.UPLOAD_IMAGE,callback(l,s){const a=u=>{m.bus.emit(o,m.REPLACE,"image",{desc:"",urls:u}),s?.()};e.onUploadImg?e.onUploadImg(l,a):t.emit("onUploadImg",l,a)}}),f=document.body.style.overflow,c()}),[r,d]},ye=(e,t)=>{const{editorId:i}=t,o=n.ref(!1);return n.onMounted(()=>{m.bus.on(i,{name:m.CHANGE_CATALOG_VISIBLE,callback:r=>{r===void 0?o.value=!o.value:o.value=r}})}),o},Ce=(e,t,i)=>{const{editorId:o,catalogVisible:r,setting:p,updateSetting:d,codeRef:f}=i;n.watch(()=>p.pageFullscreen,l=>{m.bus.emit(o,m.PAGE_FULL_SCREEN_CHANGED,l)}),n.watch(()=>p.fullscreen,l=>{m.bus.emit(o,m.FULL_SCREEN_CHANGED,l)}),n.watch(()=>p.preview,l=>{m.bus.emit(o,m.PREVIEW_CHANGED,l)}),n.watch(()=>p.previewOnly,l=>{m.bus.emit(o,m.PREVIEW_ONLY_CHANGED,l)}),n.watch(()=>p.htmlPreview,l=>{m.bus.emit(o,m.HTML_PREVIEW_CHANGED,l)}),n.watch(r,l=>{m.bus.emit(o,m.CATALOG_VISIBLE_CHANGED,l)});const c={on(l,s){switch(l){case"pageFullscreen":{m.bus.on(o,{name:m.PAGE_FULL_SCREEN_CHANGED,callback(a){s(a)}});break}case"fullscreen":{m.bus.on(o,{name:m.FULL_SCREEN_CHANGED,callback(a){s(a)}});break}case"preview":{m.bus.on(o,{name:m.PREVIEW_CHANGED,callback(a){s(a)}});break}case"previewOnly":{m.bus.on(o,{name:m.PREVIEW_ONLY_CHANGED,callback(a){s(a)}});break}case"htmlPreview":{m.bus.on(o,{name:m.HTML_PREVIEW_CHANGED,callback(a){s(a)}});break}case"catalog":{m.bus.on(o,{name:m.CATALOG_VISIBLE_CHANGED,callback(a){s(a)}});break}}},togglePageFullscreen(l){d("pageFullscreen",l)},toggleFullscreen(l){m.bus.emit(o,m.CHANGE_FULL_SCREEN,l)},togglePreview(l){d("preview",l)},togglePreviewOnly(l){d("previewOnly",l)},toggleHtmlPreview(l){d("htmlPreview",l)},toggleCatalog(l){m.bus.emit(o,m.CHANGE_CATALOG_VISIBLE,l)},triggerSave(){m.bus.emit(o,m.ON_SAVE)},insert(l){m.bus.emit(o,m.REPLACE,"universal",{generate:l})},focus(l){f.value?.focus(l)},rerender(){m.bus.emit(o,m.RERENDER)},getSelectedText(){return f.value?.getSelectedText()},resetHistory(){f.value?.resetHistory()},domEventHandlers(l){m.bus.emit(o,m.EVENT_LISTENER,l)},execCommand(l){m.bus.emit(o,m.REPLACE,l)},getEditorView(){return f.value?.getEditorView()}};t.expose(c)},ee=e=>{const t=n.useId();return e.id||e.editorId||`${h.prefix}-${t}`},xe=(e,t,i)=>{const o=n.inject("editorId"),r=n.inject("rootRef"),p=n.inject("usedLanguageText"),d=n.inject("setting"),f=()=>{r.value.querySelectorAll(`#${o} .${h.prefix}-preview .${h.prefix}-code`).forEach(s=>{let a=-1;const u=s.querySelector(`.${h.prefix}-copy-button:not([data-processed])`);u&&(u.onclick=g=>{g.preventDefault(),clearTimeout(a);const y=(s.querySelector("input:checked + pre code")||s.querySelector("pre code")).textContent,{text:v,successTips:$,failTips:C}=p.value.copyCode;let x=$;le(e.formatCopiedText(y||"")).catch(()=>{x=C}).finally(()=>{u.dataset.isIcon?u.dataset.tips=x:u.textContent=x,a=window.setTimeout(()=>{u.dataset.isIcon?u.dataset.tips=v:u.textContent=v},1500)})},u.setAttribute("data-processed","true"))})},c=()=>{n.nextTick(f)},l=s=>{s&&n.nextTick(f)};n.watch([t,i],c),n.watch(()=>d.value.preview,l),n.watch(()=>d.value.htmlPreview,l),n.onMounted(f)},we=e=>{const t=n.inject("editorId"),i=n.inject("theme"),o=n.inject("rootRef"),{editorExtensions:r,editorExtensionsAttrs:p,echartsConfig:d}=h.globalConfig;let f=r.echarts.instance;const c=n.shallowRef(-1),l=()=>{!e.noEcharts&&f&&(c.value=c.value+1)};n.watch(()=>i.value,()=>{l()}),n.onMounted(()=>{if(e.noEcharts||f)return;const y=r.echarts.js;S.appendHandler("script",{...p.echarts?.js,src:y,id:H.echarts,onload(){f=window.echarts,l()}},"echarts")});let s=[],a=[],u=[];const g=(y=!1)=>{if(!s.length){y&&(a.forEach(x=>{x.dispose?.()}),u.forEach(x=>{x.disconnect?.()}),a=[],u=[]);return}const v=[],$=[],C=[];s.forEach((x,T)=>{const w=a[T],I=u[T];if(y||!x||!x.isConnected||(o?.value?!o.value.contains(x):!1)){w?.dispose?.(),I?.disconnect?.();return}v.push(x),w&&$.push(w),I&&C.push(I)}),s=v,a=$,u=C},b=()=>{g(),!e.noEcharts&&f&&Array.from(o.value.querySelectorAll(`#${t} div.${h.prefix}-echarts:not([data-processed])`)).forEach(v=>{if(v.dataset.closed==="false")return!1;try{const $=r.echarts.parseOption(v.innerText,{editorId:t,element:v}),C=d($),x=f.init(v,i.value);x.setOption(C),v.setAttribute("data-processed",""),s.push(v),a.push(x);const T=new ResizeObserver(()=>{x.resize()});T.observe(v),u.push(T)}catch($){m.bus.emit(t,m.ERROR_CATCHER,{name:"echarts",message:$?.message,error:$})}})};return n.onBeforeUnmount(()=>{g(!0)}),{reRenderEcharts:c,replaceEcharts:b}},Ee=e=>{const t=n.inject("highlight"),i=n.shallowRef(h.globalConfig.editorExtensions.highlight.instance);return n.onMounted(()=>{e.noHighlight||i.value||(S.appendHandler("link",{...t.value.css,rel:"stylesheet",id:H.hlcss}),S.appendHandler("script",{...t.value.js,id:H.hljs,onload(){i.value=window.hljs}},"hljs"))}),n.watch(()=>t.value.css,()=>{e.noHighlight||h.globalConfig.editorExtensions.highlight.instance||S.updateHandler("link",{...t.value.css,rel:"stylesheet",id:H.hlcss})}),i},$e=e=>{const t=n.shallowRef(h.globalConfig.editorExtensions.katex.instance);return n.onMounted(()=>{if(e.noKatex||t.value)return;const{editorExtensions:i,editorExtensionsAttrs:o}=h.globalConfig;S.appendHandler("script",{...o.katex?.js,src:i.katex.js,id:H.katexjs,onload(){t.value=window.katex}},"katex"),S.appendHandler("link",{...o.katex?.css,rel:"stylesheet",href:i.katex.css,id:H.katexcss})}),t};class Te{constructor(t){this.options=t}options;cache=new Map;isExpired(t){return t.expiresAt<=Date.now()}deleteExpired(t,i){const o=i??this.cache.get(t);return!o||!this.isExpired(o)?!1:(this.cache.delete(t),!0)}trim(){for(const[t,i]of this.cache)if(!this.deleteExpired(t,i))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 i=this.cache.get(t);if(!(!i||this.deleteExpired(t,i)))return this.cache.delete(t),this.cache.set(t,i),i.value}set(t,i){this.cache.delete(t),this.cache.set(t,{value:i,expiresAt:Date.now()+this.options.ttl}),this.trim()}clear(){this.cache.clear()}}const U=new Te({max:1e3,ttl:6e5}),Ie=e=>{const t=n.inject("editorId"),i=n.inject("theme"),o=n.inject("rootRef"),{editorExtensions:r,editorExtensionsAttrs:p,mermaidConfig:d}=h.globalConfig;let f=r.mermaid.instance;const c=n.shallowRef(-1),l=()=>{if(!e.noMermaid&&f){const a=i.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"}};f.initialize(d(a)),c.value=c.value+1}};return n.watch(()=>i.value,()=>{U.clear(),l()}),n.onMounted(()=>{if(e.noMermaid||f)return;const a=r.mermaid.js;/\.mjs/.test(a)?(S.appendHandler("link",{...p.mermaid?.js,rel:"modulepreload",href:a,id:H.mermaidM}),import(a).then(u=>{f=u.default,l()}).catch(u=>{m.bus.emit(t,m.ERROR_CATCHER,{name:"mermaid",message:`Failed to load mermaid module: ${u.message}`,error:u})})):S.appendHandler("script",{...p.mermaid?.js,src:a,id:H.mermaid,onload(){f=window.mermaid,l()}},"mermaid")}),{reRenderRef:c,replaceMermaid:async()=>{if(!e.noMermaid&&f){const a=o.value.querySelectorAll(`div.${h.prefix}-mermaid`),u=document.createElement("div"),g=document.body.offsetWidth>1366?document.body.offsetWidth:1366,b=document.body.offsetHeight>768?document.body.offsetHeight:768;u.style.width=g+"px",u.style.height=b+"px",u.style.position="fixed",u.style.zIndex="-10000",u.style.top="-10000";let y=a.length;y>0&&document.body.appendChild(u),await Promise.allSettled(Array.from(a).map(v=>(async C=>{if(C.dataset.closed==="false")return!1;const x=C.innerText;let T=U.get(x);if(!T){const w=O.randomId();let I={svg:""};try{I=await f.render(w,x,u),T=await e.sanitizeMermaid(I.svg);const E=document.createElement("p");E.className=`${h.prefix}-mermaid`,E.setAttribute("data-processed",""),E.setAttribute("data-content",x),E.innerHTML=T,E.children[0]?.removeAttribute("height"),U.set(x,E.innerHTML),C.dataset.line!==void 0&&(E.dataset.line=C.dataset.line),C.replaceWith(E)}catch(E){m.bus.emit(t,m.ERROR_CATCHER,{name:"mermaid",message:E.message,error:E})}--y===0&&u.remove()}})(v)))}}}},ke=(e,t)=>{t=t||{};const i=3,o=t.marker||"!",r=o.charCodeAt(0),p=o.length;let d="",f="";const c=(s,a,u,g,b)=>{const y=s[a];return y.type==="admonition_open"?s[a].attrPush(["class",`${h.prefix}-admonition ${h.prefix}-admonition-${y.info}`]):y.type==="admonition_title_open"&&s[a].attrPush(["class",`${h.prefix}-admonition-title`]),b.renderToken(s,a,u)},l=s=>{const a=s.trim().split(" ",2);f="",d=a[0],a.length>1&&(f=s.substring(d.length+2))};e.block.ruler.before("code","admonition",(s,a,u,g)=>{let b,y,v,$=!1,C=s.bMarks[a]+s.tShift[a],x=s.eMarks[a];if(r!==s.src.charCodeAt(C))return!1;for(b=C+1;b<=x&&o[(b-C)%p]===s.src[b];b++);const T=Math.floor((b-C)/p);if(T!==i)return!1;b-=(b-C)%p;const w=s.src.slice(C,b),I=s.src.slice(b,x);if(l(I),g)return!0;for(y=a;y++,!(y>=u||(C=s.bMarks[y]+s.tShift[y],x=s.eMarks[y],C<x&&s.sCount[y]<s.blkIndent));)if(r===s.src.charCodeAt(C)&&!(s.sCount[y]-s.blkIndent>=4)){for(b=C+1;b<=x&&o[(b-C)%p]===s.src[b];b++);if(!(Math.floor((b-C)/p)<T)&&(b-=(b-C)%p,b=s.skipSpaces(b),!(b<x))){$=!0;break}}const E=s.parentType,A=s.lineMax;return s.parentType="root",s.lineMax=y,v=s.push("admonition_open","div",1),v.markup=w,v.block=!0,v.info=d,v.map=[a,y],f&&(v=s.push("admonition_title_open","p",1),v.markup=w+" "+d,v.map=[a,y],v=s.push("inline","",0),v.content=f,v.map=[a,s.line-1],v.children=[],v=s.push("admonition_title_close","p",-1),v.markup=w+" "+d),s.md.block.tokenize(s,a+1,y),v=s.push("admonition_close","div",-1),v.markup=s.src.slice(C,b),v.block=!0,s.parentType=E,s.lineMax=A,s.line=y+($?1:0),!0},{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.admonition_open=c,e.renderer.rules.admonition_title_open=c,e.renderer.rules.admonition_title_close=c,e.renderer.rules.admonition_close=c},K=(e,t)=>{const i=e.attrs?e.attrs.slice():[];return t.forEach(o=>{const r=e.attrIndex(o[0]);r<0?i.push(o):(i[r]=i[r].slice(),i[r][1]+=` ${o[1]}`)}),i},Se=e=>Array.from(e).map(t=>/[A-Za-z0-9_-]/.test(t)?t:`_${t.codePointAt(0).toString(16)}_`).join(""),Ae=(e,t)=>{const i=e.renderer.rules.fence,o=e.utils.unescapeAll,r=/\[(\w*)(?::([\w ]*))?\]/,p=/::(open|close)/,d=Se(t.editorId),f=u=>u.info?o(u.info).trim():"",c=u=>{const g=f(u),[b=null,y=""]=(r.exec(g)||[]).slice(1);return[b,y]},l=u=>{const g=f(u);return g?g.split(/(\s+)/g)[0]:""},s=u=>{const g=u.info.match(p)||[],b=g[1]==="open"||g[1]!=="close"&&t.codeFoldable&&u.content.trim().split(`
|
|
2
|
+
`).length<t.autoFoldThreshold,y=g[1]||t.codeFoldable?"details":"div",v=g[1]||t.codeFoldable?"summary":"div";return{open:b,tagContainer:y,tagHeader:v}},a=(u,g,b,y,v)=>{if(u[g].hidden)return"";const $=t.usedLanguageTextRef.value?.copyCode.text||"",C=t.customIconRef.value.copy,x=e.utils.escapeHtml($),T=C||x,w=!!C,I=`<span class="${h.prefix}-collapse-tips">${S.StrIcon("collapse-tips",t.customIconRef.value)}</span>`,[E]=c(u[g]);if(E===null){const{open:k,tagContainer:F,tagHeader:G}=s(u[g]),N=[["class",`${h.prefix}-code`]];k&&N.push(["open",""]);const ie={attrs:K(u[g],N)};u[g].info=u[g].info.replace(p,"");const ae=i(u,g,b,y,v);return`
|
|
3
|
+
<${F} ${v.renderAttrs(ie)}>
|
|
4
4
|
<${G} class="${h.prefix}-code-head">
|
|
5
5
|
<div class="${h.prefix}-code-flag"><span></span><span></span><span></span></div>
|
|
6
6
|
<div class="${h.prefix}-code-action">
|
|
7
|
-
<span class="${h.prefix}-code-lang">${e.utils.escapeHtml(
|
|
8
|
-
<span class="${h.prefix}-copy-button" data-tips="${
|
|
9
|
-
${t.extraTools instanceof Function?t.extraTools({lang:
|
|
10
|
-
${
|
|
7
|
+
<span class="${h.prefix}-code-lang">${e.utils.escapeHtml(u[g].info.trim())}</span>
|
|
8
|
+
<span class="${h.prefix}-copy-button" data-tips="${x}"${w?" data-is-icon=true":""}>${T}</span>
|
|
9
|
+
${t.extraTools instanceof Function?t.extraTools({lang:u[g].info.trim()}):t.extraTools||""}
|
|
10
|
+
${F==="details"?I:""}
|
|
11
11
|
</div>
|
|
12
12
|
</${G}>
|
|
13
|
-
${
|
|
14
|
-
</${
|
|
15
|
-
`}let
|
|
13
|
+
${ae}
|
|
14
|
+
</${F}>
|
|
15
|
+
`}let A,L,P,M,D="",B="",V="";const{open:z,tagContainer:j,tagHeader:R}=s(u[g]),_=[["class",`${h.prefix}-code`]];z&&_.push(["open",""]);const W={attrs:K(u[g],_)};for(let k=g;k<u.length&&(A=u[k],[L,P]=c(A),L===E);k++){A.info=A.info.replace(r,"").replace(p,""),A.hidden=!0;const F=`${h.prefix}-codetab-${d}-${g}-${k-g}`;M=k-g>0?"":"checked",D+=`
|
|
16
16
|
<li>
|
|
17
17
|
<input
|
|
18
18
|
type="radio"
|
|
19
|
-
id="label-${h.prefix}-codetab-label-1-${
|
|
20
|
-
name="${h.prefix}-codetab-label-${
|
|
21
|
-
class="${
|
|
22
|
-
${
|
|
19
|
+
id="label-${h.prefix}-codetab-label-1-${d}-${g}-${k-g}"
|
|
20
|
+
name="${h.prefix}-codetab-label-${d}-${g}"
|
|
21
|
+
class="${F}"
|
|
22
|
+
${M}
|
|
23
23
|
>
|
|
24
24
|
<label
|
|
25
|
-
for="label-${h.prefix}-codetab-label-1-${
|
|
26
|
-
onclick="this.getRootNode().querySelectorAll('.${
|
|
25
|
+
for="label-${h.prefix}-codetab-label-1-${d}-${g}-${k-g}"
|
|
26
|
+
onclick="this.getRootNode().querySelectorAll('.${F}').forEach(e => e.click())"
|
|
27
27
|
>
|
|
28
|
-
${e.utils.escapeHtml(
|
|
28
|
+
${e.utils.escapeHtml(P||l(A))}
|
|
29
29
|
</label>
|
|
30
|
-
</li>`,
|
|
30
|
+
</li>`,B+=`
|
|
31
31
|
<div role="tabpanel">
|
|
32
32
|
<input
|
|
33
33
|
type="radio"
|
|
34
|
-
name="${h.prefix}-codetab-pre-${
|
|
35
|
-
class="${
|
|
36
|
-
${
|
|
34
|
+
name="${h.prefix}-codetab-pre-${d}-${g}"
|
|
35
|
+
class="${F}"
|
|
36
|
+
${M}
|
|
37
37
|
role="presentation">
|
|
38
|
-
${
|
|
39
|
-
</div>`,
|
|
38
|
+
${i(u,k,b,y,v)}
|
|
39
|
+
</div>`,V+=`
|
|
40
40
|
<input
|
|
41
41
|
type="radio"
|
|
42
|
-
name="${h.prefix}-codetab-lang-${
|
|
43
|
-
class="${
|
|
44
|
-
${
|
|
42
|
+
name="${h.prefix}-codetab-lang-${d}-${g}"
|
|
43
|
+
class="${F}"
|
|
44
|
+
${M}
|
|
45
45
|
role="presentation">
|
|
46
|
-
<span class=${h.prefix}-code-lang role="note">${e.utils.escapeHtml(
|
|
47
|
-
<${
|
|
48
|
-
<${
|
|
46
|
+
<span class=${h.prefix}-code-lang role="note">${e.utils.escapeHtml(l(A))}</span>`}return`
|
|
47
|
+
<${j} ${v.renderAttrs(W)}>
|
|
48
|
+
<${R} class="${h.prefix}-code-head">
|
|
49
49
|
<div class="${h.prefix}-code-flag">
|
|
50
|
-
<ul class="${h.prefix}-codetab-label" role="tablist">${
|
|
50
|
+
<ul class="${h.prefix}-codetab-label" role="tablist">${D}</ul>
|
|
51
51
|
</div>
|
|
52
52
|
<div class="${h.prefix}-code-action">
|
|
53
|
-
<span class="${h.prefix}-codetab-lang">${
|
|
54
|
-
<span class="${h.prefix}-copy-button" data-tips="${
|
|
55
|
-
${t.extraTools instanceof Function?t.extraTools({lang:
|
|
56
|
-
${
|
|
53
|
+
<span class="${h.prefix}-codetab-lang">${V}</span>
|
|
54
|
+
<span class="${h.prefix}-copy-button" data-tips="${x}"${w?" data-is-icon=true":""}>${T}</span>
|
|
55
|
+
${t.extraTools instanceof Function?t.extraTools({lang:u[g].info.trim()}):t.extraTools||""}
|
|
56
|
+
${j==="details"?I:""}
|
|
57
57
|
</div>
|
|
58
|
-
</${
|
|
59
|
-
${
|
|
60
|
-
</${
|
|
61
|
-
`};e.renderer.rules.fence=
|
|
62
|
-
`)})));let
|
|
63
|
-
`)}))},
|
|
64
|
-
`),
|
|
65
|
-
`))):
|
|
58
|
+
</${R}>
|
|
59
|
+
${B}
|
|
60
|
+
</${j}>
|
|
61
|
+
`};e.renderer.rules.fence=a,e.renderer.rules.code_block=a},Re=(e,t)=>{const i=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,r,p,d,f)=>{const c=o[r],l=c.content.trim();if(c.info==="echarts"){if(c.attrSet("class",`${h.prefix}-echarts`),c.attrSet("data-echarts-theme",t.themeRef.value),c.map&&c.level===0){const s=c.map[1]-1,u=!!d.srcLines[s]?.trim()?.startsWith("```");c.attrSet("data-closed",`${u}`),c.attrSet("data-line",String(c.map[0]))}return`<div ${f.renderAttrs(c)} style="width: 100%; aspect-ratio: 4 / 3;">${e.utils.escapeHtml(l)}</div>`}return i(o,r,p,d,f)}},He=(e,t)=>{e.renderer.rules.heading_open=(i,o)=>{const r=i[o],p=i[o+1].children?.reduce((f,c)=>f+(["text","code_inline","math_inline"].includes(c.type)&&c.content||""),"")||"",d=r.markup.length;return t.headsRef.value.push({text:p,level:d,line:r.map[0],currentToken:r,nextToken:i[o+1]}),r.map&&r.level===0&&r.attrSet("id",t.mdHeadingId({text:p,level:d,index:t.headsRef.value.length,currentToken:r,nextToken:i[o+1]})),e.renderer.renderToken(i,o,t)},e.renderer.rules.heading_close=(i,o,r,p,d)=>d.renderToken(i,o,r)},Z={block:[{open:"$$",close:"$$"},{open:"\\[",close:"\\]"}],inline:[{open:"$$",close:"$$"},{open:"$",close:"$"},{open:"\\[",close:"\\]"},{open:"\\(",close:"\\)"}]},Fe=e=>(t,i)=>{const o=e.delimiters;for(const r of o){if(!t.src.startsWith(r.open,t.pos))continue;const p=t.pos+r.open.length;let d=p;for(;(d=t.src.indexOf(r.close,d))!==-1;){let f=0,c=d-1;for(;c>=0&&t.src[c]==="\\";)f++,c--;if(f%2===0)break;d+=r.close.length}if(d!==-1){if(d-p===0)return i||(t.pending+=r.open+r.close),t.pos=d+r.close.length,!0;if(!i){const f=t.push("math_inline","math",0);f.markup=r.open,f.content=t.src.slice(p,d)}return t.pos=d+r.close.length,!0}}return!1},Le=e=>(t,i,o,r)=>{const p=e.delimiters,d=t.bMarks[i]+t.tShift[i],f=t.eMarks[i],c=(l,s,a)=>{t.line=s;const u=t.push("math_block","math",0);return u.block=!0,u.content=l,u.map=[i,t.line],u.markup=a,!0};for(const l of p){const s=d;if(t.src.slice(s,s+l.open.length)!==l.open)continue;const a=s+l.open.length,u=t.src.slice(a,f).trim(),g=u==="",b=u===l.close,y=u.endsWith(l.close);if(!g&&!b&&!y)continue;if(r)return!0;if(b)return c("",i+1,l.open);if(!g&&y){const w=u.slice(0,-l.close.length);return c(w,i+1,l.open)}let v=i+1,$=!1,C="";for(;v<o;v++){const w=t.bMarks[v]+t.tShift[v],I=t.eMarks[v];if(w<I&&t.tShift[v]<t.blkIndent)break;if(t.src.slice(w,I).trim().endsWith(l.close)){const A=t.src.slice(0,I).lastIndexOf(l.close);C=t.src.slice(w,A),$=!0;break}}if(!$)continue;const T=t.getLines(i+1,v,t.tShift[i],!0)+(C.trim()?C:"");return c(T,v+1,l.open)}return!1},Me=(e,{katexRef:t,inlineDelimiters:i,blockDelimiters:o})=>{const r=(f,c,l,s,a=!1)=>{const u={attrs:K(f,[["class",c]])},g=s.renderAttrs(u);if(!t.value)return`<${l} ${g}>${f.content}</${l}>`;const b=t.value.renderToString(f.content,h.globalConfig.katexConfig({throwOnError:!1,displayMode:a}));return`<${l} ${g} data-processed>${b}</${l}>`},p=(f,c,l,s,a)=>r(f[c],`${h.prefix}-katex-inline`,"span",a),d=(f,c,l,s,a)=>r(f[c],`${h.prefix}-katex-block`,"p",a,!0);e.inline.ruler.before("escape","math_inline",Fe({delimiters:i||Z.inline})),e.block.ruler.after("blockquote","math_block",Le({delimiters:o||Z.block}),{alt:["paragraph","reference","blockquote","list"]}),e.renderer.rules.math_inline=p,e.renderer.rules.math_block=d},_e=(e,t)=>{const i=e.renderer.rules.fence.bind(e.renderer.rules);e.renderer.rules.fence=(o,r,p,d,f)=>{const c=o[r],l=c.content.trim();if(c.info==="mermaid"){if(c.attrSet("class",`${h.prefix}-mermaid`),c.attrSet("data-mermaid-theme",t.themeRef.value),c.map&&c.level===0){const a=c.map[1]-1,g=!!d.srcLines[a]?.trim()?.startsWith("```");c.attrSet("data-closed",`${g}`),c.attrSet("data-line",String(c.map[0]))}const s=U.get(l);return s?(c.attrSet("data-processed",""),c.attrSet("data-content",l),`<p ${f.renderAttrs(c)}>${s}</p>`):`<div ${f.renderAttrs(c)}>${e.utils.escapeHtml(l)}</div>`}return i(o,r,p,d,f)}},J=(e,t,i)=>{const o=e.attrIndex(t),r=[t,i];o<0?e.attrPush(r):(e.attrs=e.attrs||[],e.attrs[o]=r)},Pe=e=>e.type==="inline",je=e=>e.type==="paragraph_open",Ne=e=>e.type==="list_item_open",Oe=e=>e.content.indexOf("[ ] ")===0||e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0,De=(e,t)=>Pe(e[t])&&je(e[t-1])&&Ne(e[t-2])&&Oe(e[t]),Be=(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},Ve=e=>{const t=new e("html_inline","",0);return t.content="<label>",t},Ge=e=>{const t=new e("html_inline","",0);return t.content="</label>",t},Ue=(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},qe=(e,t,i)=>{const o=new t("html_inline","",0),r=i.enabled?" ":' disabled="" ';return e.content.indexOf("[ ] ")===0?o.content='<input class="task-list-item-checkbox"'+r+'type="checkbox">':(e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0)&&(o.content='<input class="task-list-item-checkbox" checked=""'+r+'type="checkbox">'),o},ze=(e,t,i)=>{if(e.children=e.children||[],e.children.unshift(qe(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(Ue(e.content,o,t))}else e.children.unshift(Ve(t)),e.children.push(Ge(t))},We=(e,t={})=>{e.core.ruler.after("inline","github-task-lists",i=>{const o=i.tokens;for(let r=2;r<o.length;r++)De(o,r)&&(ze(o[r],i.Token,t),J(o[r-2],"class","task-list-item"+(t.enabled?" enabled":" ")),J(o[Be(o,r-2)],"class","contains-task-list"))})},Ke=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))},Ze=(e,t)=>{const{editorConfig:i,markdownItConfig:o,markdownItPlugins:r,editorExtensions:p}=h.globalConfig,d=n.inject("editorId"),f=n.inject("language"),c=n.inject("usedLanguageText"),l=n.inject("showCodeRowNumber"),s=n.inject("theme"),a=n.inject("customIcon"),u=n.inject("rootRef"),g=n.inject("setting"),b=n.ref([]),y=Ee(e),v=$e(e),{reRenderRef:$,replaceMermaid:C}=Ie(e),{reRenderEcharts:x,replaceEcharts:T}=we(e),w=se({html:!0,breaks:!0,linkify:!0});o(w,{editorId:d});const I=[{type:"image",plugin:ce,options:{figcaption:!0,classes:"md-zoom"}},{type:"admonition",plugin:ke,options:{}},{type:"taskList",plugin:We,options:{}},{type:"heading",plugin:He,options:{mdHeadingId:e.mdHeadingId,headsRef:b}},{type:"code",plugin:Ae,options:{editorId:d,usedLanguageTextRef:c,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,customIconRef:a}},{type:"sub",plugin:de,options:{}},{type:"sup",plugin:ue,options:{}}];e.noKatex||I.push({type:"katex",plugin:Me,options:{katexRef:v}}),e.noMermaid||I.push({type:"mermaid",plugin:_e,options:{themeRef:s}}),e.noEcharts||I.push({type:"echarts",plugin:Re,options:{themeRef:s}}),r(I,{editorId:d}).forEach(R=>{w.use(R.plugin,R.options)});const E=w.options.highlight;w.set({highlight:(R,_,W)=>{if(E){const N=E(R,_,W);if(N)return N}let k;!e.noHighlight&&y.value?y.value.getLanguage(_)?k=y.value.highlight(R,{language:_,ignoreIllegals:!0}).value:k=y.value.highlightAuto(R).value:k=w.utils.escapeHtml(R);const F=w.utils.escapeHtml(_),G=l?fe.generateCodeRowNumber(k.replace(/^\n+|\n+$/g,""),R.replace(/^\n+|\n+$/g,"")):`<span class="${h.prefix}-code-block">${k.replace(/^\n+|\n+$/g,"")}</span>`;return`<pre><code class="language-${F}" language="${F}">${G}</code></pre>`}}),Ke(w);const A=n.ref(`_article-key_${O.randomId()}`),L=n.ref(e.sanitize(w.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
62
|
+
`)})));let P=()=>{},M=()=>{};const D=()=>{const R=u.value?.querySelectorAll(`#${d} p.${h.prefix}-mermaid:not([data-closed=false])`);M(),M=S.copyMermaid(R,{customIcon:a.value}),p.mermaid?.enableZoom&&(P(),P=S.zoomMermaid(R,{customIcon:a.value}))},B=()=>{m.bus.emit(d,m.BUILD_FINISHED,L.value),e.onHtmlChanged(L.value),e.onGetCatalog(b.value),m.bus.emit(d,m.CATALOG_CHANGED,b.value),n.nextTick(()=>{C().then(D),T()})},V=()=>{b.value=[],L.value=e.sanitize(w.render(e.modelValue,{srcLines:e.modelValue.split(`
|
|
63
|
+
`)}))},z=n.computed(()=>(e.noKatex||!!v.value)&&(e.noHighlight||!!y.value));let j=-1;return n.watch([n.toRef(e,"modelValue"),z,$,f],()=>{j=window.setTimeout(()=>{V()},t?0:i.renderDelay)}),n.watch(()=>g.value.preview,()=>{g.value.preview&&n.nextTick(()=>{C().then(D),T(),m.bus.emit(d,m.CATALOG_CHANGED,b.value)})}),n.watch([L,x],()=>{B()}),n.onMounted(B),n.onMounted(()=>{m.bus.on(d,{name:m.PUSH_CATALOG,callback(){m.bus.emit(d,m.CATALOG_CHANGED,b.value)}}),m.bus.on(d,{name:m.RERENDER,callback:()=>{A.value=`_article-key_${O.randomId()}`,V()}})}),n.onBeforeUnmount(()=>{P(),M(),clearTimeout(j)}),{html:L,key:A}},Je=(e,t)=>{const i=n.inject("editorId"),o=n.inject("setting"),{noImgZoomIn:r}=e,p=O.debounce(()=>{const d=document.querySelectorAll(`#${i}-preview img:not(.not-zoom):not(.medium-zoom-image)`);d.length!==0&&pe(d,{background:"#00000073"})});n.onMounted(async()=>{!r&&o.value.preview&&await p()}),n.watch([t,()=>o.value.preview],async()=>{!r&&o.value.preview&&await p()})},X={checked:{regexp:/- \[x\]/,value:"- [ ]"},unChecked:{regexp:/- \[\s\]/,value:"- [x]"}},Xe=(e,t)=>{const i=n.inject("editorId"),o=n.inject("rootRef");let r=()=>{};const p=()=>{if(!o.value)return!1;const d=o.value.querySelectorAll(".task-list-item.enabled"),f=c=>{c.preventDefault();const l=c.target.checked?"unChecked":"checked",s=c.target.parentElement?.dataset.line;if(!s)return;const a=Number(s),u=e.modelValue.split(`
|
|
64
|
+
`),g=u[Number(a)].replace(X[l].regexp,X[l].value);e.previewOnly?(u[Number(a)]=g,e.onChange(u.join(`
|
|
65
|
+
`))):m.bus.emit(i,m.TASK_STATE_CHANGED,a+1,g)};d.forEach(c=>{c.addEventListener("click",f)}),r=()=>{d.forEach(c=>{c.removeEventListener("click",f)})}};n.onBeforeUnmount(()=>{r()}),n.watch([t],()=>{r(),n.nextTick(p)},{immediate:!0})},Ye=(e,t,i)=>{const o=n.inject("setting"),r=()=>{n.nextTick(()=>{e.onRemount?.()})},p=d=>{d&&r()};n.watch([t,i],r),n.watch(()=>o.value.preview,p),n.watch(()=>o.value.htmlPreview,p),n.onMounted(r)},te={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}},Qe={...te,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}},Y=e=>{const i=new DOMParser().parseFromString(e,"text/html");return Array.from(i.body.childNodes)},et=(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,tt=n.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=n.ref(),i=e.html,o=(r,p)=>{if(!t.value)return;const d=t.value,f=Array.from(d.childNodes),c=Math.min(r.length,p.length);let l=-1;for(let a=0;a<c;a++)if(!et(r[a],p[a])){l=a;break}if(l===-1)if(p.length>r.length)l=r.length;else if(r.length>p.length)l=p.length;else return;const s=Math.min(l,f.length);for(let a=f.length-1;a>=s;a--)f[a].remove();for(let a=l;a<r.length;a++)d.appendChild(r[a].cloneNode(!0))};return n.watch(()=>e.html,(r,p)=>{const d=Y(r),f=Y(p||"");o(d,f)}),()=>n.createVNode("div",{id:e.id,class:e.class,innerHTML:i,ref:t},null)}}),ne=n.defineComponent({name:"ContentPreview",props:te,setup(e){const t=n.inject("editorId"),i=n.inject("setting"),o=n.inject("previewTheme"),r=n.inject("showCodeRowNumber"),{html:p,key:d}=Ze(e,e.previewOnly);xe(e,p,d),Je(e,p),Xe(e,p),Ye(e,p,d);const f=n.computed(()=>[`${h.prefix}-preview`,`${o?.value}-theme`,r&&`${h.prefix}-scrn`].filter(Boolean)),c=()=>{const l=`${t}-preview`;return e.previewComponent?n.h(e.previewComponent,{key:d.value,html:p.value,id:l,class:f.value}):n.createVNode(tt,{key:d.value,html:p.value,id:l,class:f.value},null)};return()=>n.createVNode(n.Fragment,null,[i.value.preview&&(e.previewOnly?c():n.createVNode("div",{id:`${t}-preview-wrapper`,class:`${h.prefix}-preview-wrapper`,key:"content-preview-wrapper"},[c()])),i.value.htmlPreview&&n.createVNode("div",{id:`${t}-html-wrapper`,class:`${h.prefix}-preview-wrapper`,key:"html-preview-wrapper"},[n.createVNode("div",{class:`${h.prefix}-html`},[p.value])])])}}),nt=({text:e})=>e,oe={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:nt},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}},ot={...oe,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:h.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:h.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}},re=["onHtmlChanged","onGetCatalog","onChange","onRemount","update:modelValue"],rt=[...re,"onSave","onUploadImg","onError","onBlur","onFocus","onInput","onDrop","oninputBoxWidthChange"],it=(e,t,i)=>{const{editorId:o}=i,r={rerender(){m.bus.emit(o,m.RERENDER)}};t.expose(r)},q=n.defineComponent({name:"MdPreview",props:oe,emits:re,setup(e,t){const{noKatex:i,noMermaid:o,noHighlight:r}=e,p=n.ref(),d=ee(e);Q(e,{rootRef:p,editorId:d}),it(e,t,{editorId:d}),n.onBeforeUnmount(()=>{m.bus.clear(d)});const f=a=>{e.onChange?.(a),t.emit("onChange",a),t.emit("update:modelValue",a)},c=a=>{e.onHtmlChanged?.(a),t.emit("onHtmlChanged",a)},l=a=>{e.onGetCatalog?.(a),t.emit("onGetCatalog",a)},s=()=>{e.onRemount?.(),t.emit("onRemount")};return()=>n.createVNode("div",{id:d,class:[h.prefix,e.class,e.theme==="dark"&&`${h.prefix}-dark`,`${h.prefix}-previewOnly`],style:e.style,ref:p},[n.createVNode(ne,{modelValue:e.modelValue,onChange:f,onHtmlChanged:c,onGetCatalog:l,mdHeadingId:e.mdHeadingId,noMermaid:o,sanitize:e.sanitize,noKatex:i,formatCopiedText:e.formatCopiedText,noHighlight:r,noImgZoomIn:e.noImgZoomIn,previewOnly:!0,sanitizeMermaid:e.sanitizeMermaid,codeFoldable:e.codeFoldable,autoFoldThreshold:e.autoFoldThreshold,onRemount:s,noEcharts:e.noEcharts,previewComponent:e.previewComponent},null)])}});q.install=e=>(e.component(q.name,q),e);exports.CDN_IDS=H;exports.ContentPreview=ne;exports.MdPreview=q;exports.contentProps=Qe;exports.editorEmits=rt;exports.editorProps=ot;exports.useCatalog=ye;exports.useConfig=be;exports.useEditorId=ee;exports.useErrorCatcher=ve;exports.useExpansion=ge;exports.useExpose=Ce;exports.useOnSave=me;exports.useProvide=he;
|