md-editor-v3 6.5.1 → 6.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";const n=require("vue"),R=require("./config.cjs"),y=require("./event-bus.cjs"),G=require("./index5.cjs"),W=require("@vavt/util"),P=`.${R.prefix}-preview > [data-line]`,D=(e,l)=>+getComputedStyle(e).getPropertyValue(l).replace("px",""),j=(e,l)=>{const p=W.debounce(()=>{e.removeEventListener("scroll",c),e.addEventListener("scroll",c),l.removeEventListener("scroll",c),l.addEventListener("scroll",c)},50),c=I=>{const m=e.clientHeight,L=l.clientHeight,d=e.scrollHeight,s=l.scrollHeight,a=(d-m)/(s-L);I.target===e?(l.removeEventListener("scroll",c),l.scrollTo({top:e.scrollTop/a}),p()):(e.removeEventListener("scroll",c),e.scrollTo({top:l.scrollTop*a}),p())};return[()=>{p().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",c),l.removeEventListener("scroll",c)}]},U=(e,l,p)=>{const{view:c}=p,I=W.createSmoothScroll(),m=r=>c.lineBlockAt(c.state.doc.line(r+1).from).top,L=r=>c.lineBlockAt(c.state.doc.line(r+1).from).bottom;let d=[],s=[],a=[];const N=()=>{d=[],s=Array.from(l.querySelectorAll(P)),a=s.map(o=>Number(o.dataset.line));const r=[...a],{lines:g}=c.state.doc;let H=r.shift()||0,t=r.shift()||g;for(let o=0;o<g;o++)o===t&&(H=o,t=r.shift()||g),d.push({start:H,end:t-1})},w=(r,g)=>{let H=1;for(let t=s.length-1;t-1>=0;t--){const o=s[t],f=s[t-1];if(o.offsetTop+o.offsetHeight>g&&f.offsetTop<g){H=Number(f.dataset.line);break}}for(let t=d.length-1;t>=0;t--){const o=L(d[t].end),f=m(d[t].start);if(o>r&&f<=r){H=H<d[t].start?H:d[t].start;break}}return H};let A=0,$=0;const V=()=>{if($!==0)return!1;A++;const{scrollDOM:r,contentHeight:g}=c;let H=D(l,"padding-block-start");const t=c.lineBlockAtHeight(r.scrollTop),{number:o}=c.state.doc.lineAt(t.from),f=d[o-1];if(!f)return!1;let v=1;const k=l.querySelector(`[data-line="${f.start}"]`)||l.firstElementChild?.firstElementChild,u=l.querySelector(`[data-line="${f.end+1}"]`)||l.lastElementChild?.lastElementChild,i=r.scrollHeight-r.clientHeight,b=l.scrollHeight-l.clientHeight;let T=m(f.start),h=L(f.end),x=k.offsetTop,S=u.offsetTop-x;T===0&&(x=0,k===u?(H=0,h=g-r.offsetHeight,S=b):S=u.offsetTop),v=(r.scrollTop-T)/(h-T);const M=u==l.lastElementChild?.lastElementChild?u.offsetTop+u.clientHeight:u.offsetTop;if(h>=i||M>b){const C=w(i,b);T=m(C),v=(r.scrollTop-T)/(i-T);const q=l.querySelector(`[data-line="${C}"]`);T>0&&q&&(x=q.offsetTop),S=b-x+D(l,"padding-block-start")}const E=x-H+S*v;I(l,E,()=>{A--})},B=()=>{if(A!==0)return;$++;const{scrollDOM:r}=c,g=l.scrollTop,H=l.scrollHeight,t=r.scrollHeight-r.clientHeight,o=l.scrollHeight-l.clientHeight;let f=l.firstElementChild?.firstElementChild,v=l.firstElementChild?.lastElementChild;if(a.length>0){let M=Math.ceil(a[a.length-1]*(g/H)),E=a.findLastIndex(C=>C<=M);E=E===-1?0:E,M=a[E];for(let C=E;C>=0&&C<a.length;)if(s[C].offsetTop>g){if(C-1>=0){C--;continue}M=-1,E=C;break}else{if(C+1<a.length&&s[C+1].offsetTop<g){C++;continue}M=a[C],E=C;break}switch(E){case-1:{f=l.firstElementChild?.firstElementChild,v=s[E];break}case a.length-1:{f=s[E],v=l.firstElementChild?.lastElementChild;break}default:f=s[E],v=s[E+1===s.length?E:E+1]}}let k=f===l.firstElementChild?.firstElementChild?0:f.offsetTop-D(f,"margin-block-start"),u=v.offsetTop,i=0;const{start:b,end:T}=d[Number(f.dataset.line||0)];let h=m(b);const x=m(T+1===c.state.doc.lines?T:T+1);let S=0;if(x>t||v.offsetTop+v.offsetHeight>o){const M=w(t,o),E=l.querySelector(`[data-line="${M}"]`);k=E?E.offsetTop-D(E,"margin-block-start"):k,h=m(M),i=(g-k)/(o-k),S=t-h}else f===l.firstElementChild?.firstElementChild?(f===v&&(u=v.offsetTop+v.offsetHeight+D(v,"margin-block-end")),S=x,i=Math.max(g/u,0)):(i=Math.max((g-k)/(u-k),0),S=x-h);I(e,h+S*i,()=>{$--})},O=r=>{const{scrollDOM:g,contentHeight:H}=c,t=g.clientHeight;if(H<=t||l.firstElementChild.clientHeight<=l.clientHeight||c.state.doc.lines<=d[d.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}},F=n.defineComponent({props:z,setup(e){const l=n.inject("scrollElementRef"),p=n.inject("roorNodeRef"),c=n.ref();n.watch(()=>e.tocItem.active,m=>{m&&e.onActive(e.tocItem,c.value)}),n.onMounted(()=>{e.tocItem.active&&e.onActive(e.tocItem,c.value)});const I=m=>{if(m.stopPropagation(),e.onClick(m,e.tocItem),m.defaultPrevented)return;const L=e.mdHeadingId({text:e.tocItem.text,level:e.tocItem.level,index:e.tocItem.index,currentToken:e.tocItem.currentToken,nextToken:e.tocItem.nextToken}),d=p.value.getElementById(L),s=l.value;if(d&&s){let a=d.offsetParent,N=d.offsetTop;if(s.contains(a))for(;a&&s!=a;)N+=a?.offsetTop,a=a?.offsetParent;const w=d.previousElementSibling;let A=0;w||(A=D(d,"margin-block-start")),s?.scrollTo({top:N-e.scrollElementOffsetTop-A,behavior:"smooth"})}};return()=>n.createVNode("div",{ref:c,class:[`${R.prefix}-catalog-link`,e.tocItem.active&&`${R.prefix}-catalog-active`],onClick:I},[n.createVNode("span",{title:e.tocItem.text},[e.tocItem.text]),e.tocItem.children&&e.tocItem.children.length>0&&n.createVNode("div",{class:`${R.prefix}-catalog-wrapper`},[e.tocItem.children.map(m=>n.createVNode(F,{mdHeadingId:e.mdHeadingId,key:`${e.tocItem.text}-link-${m.level}-${m.text}`,tocItem:m,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}},_=n.defineComponent({name:"MdCatalog",props:J,emits:["onClick","onActive"],setup(e,l){const p=e.editorId,c=`#${p}-preview-wrapper`,I=n.reactive({list:[],show:!1,scrollElement:e.scrollElement||c}),m=n.shallowRef(),L=n.ref(),d=n.ref(),s=n.ref(),a=n.ref(),N=n.shallowRef(),w=n.ref({});n.provide("scrollElementRef",d),n.provide("roorNodeRef",a);const A=n.computed(()=>{const t=[];return I.list.forEach((o,f)=>{if(e.catalogMaxDepth&&o.level>e.catalogMaxDepth)return;const{text:v,level:k,line:u}=o,i={level:k,text:v,line:u,index:f+1,active:m.value===o};if(t.length===0)t.push(i);else{let b=t[t.length-1];if(i.level>b.level)for(let T=b.level+1;T<=6;T++){const{children:h}=b;if(!h){b.children=[i];break}if(b=h[h.length-1],i.level<=b.level){h.push(i);break}}else t.push(i)}}),t}),$=()=>{if(I.scrollElement instanceof HTMLElement)return I.scrollElement;let t=document;return(I.scrollElement===c||e.isScrollElementInShadow)&&(t=L.value?.getRootNode()),t.querySelector(I.scrollElement)},V=t=>{if(t.length===0)return m.value=void 0,I.list=[],!1;const{activeHead:o,activeIndex:f}=t.reduce((u,i,b)=>{let T=0;if(e.syncWith==="preview"){const h=a.value?.getElementById(e.mdHeadingId({text:i.text,level:i.level,index:b+1,currentToken:i.currentToken,nextToken:i.nextToken}));h instanceof HTMLElement&&(T=G.getRelativeTop(h,d.value))}else{const h=N.value;if(h){const x=h.lineBlockAt(h.state.doc.line(i.line+1).from).top,S=h.scrollDOM.scrollTop;T=x-S}}return T<e.offsetTop&&T>u.minTop?{activeHead:i,activeIndex:b,minTop:T}:u},{activeHead:t[0],activeIndex:0,minTop:Number.MIN_SAFE_INTEGER});let v=o;const{catalogMaxDepth:k}=e;if(k&&v.level>k){for(let u=f;u>=0;u--){const i=t[u];if(i.level<=k){v=i;break}}if(v.level>k){const u=t.find(i=>i.level<=k);u&&(v=u)}}m.value=v,I.list=t},B=(t,o)=>{w.value.top=o.offsetTop+D(o,"padding-block-start")+"px",e.onActive?.(t,o),l.emit("onActive",t,o)},O=()=>{V(I.list)},r=t=>{if(s.value?.removeEventListener("scroll",O),e.syncWith==="editor")s.value=N.value?.scrollDOM;else{const o=$();d.value=o,s.value=o===document.documentElement?document:o}V(t),s.value?.addEventListener("scroll",O)},g=t=>{N.value=t};n.watch([()=>e.syncWith,N,()=>e.catalogMaxDepth],()=>{r(I.list)}),n.onMounted(()=>{a.value=L.value.getRootNode(),y.bus.on(p,{name:y.CATALOG_CHANGED,callback:r}),y.bus.on(p,{name:y.GET_EDITOR_VIEW,callback:g}),y.bus.emit(p,y.PUSH_CATALOG),y.bus.emit(p,y.SEND_EDITOR_VIEW)}),n.onBeforeUnmount(()=>{y.bus.remove(p,y.CATALOG_CHANGED,r),y.bus.remove(p,y.GET_EDITOR_VIEW,g),s.value?.removeEventListener("scroll",O)});const H=(t,o)=>{e.onClick?.(t,o),l.emit("onClick",t,o)};return()=>n.createVNode("div",{class:[`${R.prefix}-catalog`,e.theme==="dark"&&`${R.prefix}-catalog-dark`,e.class||""],ref:L},[A.value.length>0&&n.createVNode(n.Fragment,null,[n.createVNode("div",{class:`${R.prefix}-catalog-indicator`,style:w.value},null),n.createVNode("div",{class:`${R.prefix}-catalog-container`},[A.value.map(t=>n.createVNode(F,{mdHeadingId:e.mdHeadingId,tocItem:t,key:`link-${t.level}-${t.text}`,onActive:B,onClick:H,scrollElementOffsetTop:e.scrollElementOffsetTop},null))])])])}});_.install=e=>(e.component(_.name,_),e);exports.MdCatalog=_;exports.scrollAuto=U;exports.scrollAutoWithScale=j;
1
+ "use strict";const o=require("vue"),R=require("./config.cjs"),y=require("./event-bus.cjs"),G=require("./index5.cjs"),W=require("@vavt/util"),P=`.${R.prefix}-preview > [data-line]`,D=(e,l)=>+getComputedStyle(e).getPropertyValue(l).replace("px",""),j=(e,l)=>{const C=W.debounce(()=>{e.removeEventListener("scroll",i),e.addEventListener("scroll",i),l.removeEventListener("scroll",i),l.addEventListener("scroll",i)},50),i=I=>{const m=e.clientHeight,L=l.clientHeight,d=e.scrollHeight,s=l.scrollHeight,a=(d-m)/(s-L);I.target===e?(l.removeEventListener("scroll",i),l.scrollTo({top:e.scrollTop/a}),C()):(e.removeEventListener("scroll",i),e.scrollTo({top:l.scrollTop*a}),C())};return[()=>{C().finally(()=>{e.dispatchEvent(new Event("scroll"))})},()=>{e.removeEventListener("scroll",i),l.removeEventListener("scroll",i)}]},U=(e,l,C)=>{const{view:i}=C,I=W.createSmoothScroll(),m=c=>i.lineBlockAt(i.state.doc.line(c+1).from).top,L=c=>i.lineBlockAt(i.state.doc.line(c+1).from).bottom;let d=[],s=[],a=[];const N=()=>{d=[],s=Array.from(l.querySelectorAll(P)),a=s.map(n=>Number(n.dataset.line));const c=[...a],{lines:g}=i.state.doc;c[0]!==0&&c.unshift(0);let H=c.shift()||0,t=c.shift()||g;for(let n=0;n<g;n++)n===t&&(H=n,t=c.shift()||g),d.push({start:H,end:t-1})},w=(c,g)=>{let H=1;for(let t=s.length-1;t-1>=0;t--){const n=s[t],f=s[t-1];if(n.offsetTop+n.offsetHeight>g&&f.offsetTop<g){H=Number(f.dataset.line);break}}for(let t=d.length-1;t>=0;t--){const n=L(d[t].end),f=m(d[t].start);if(n>c&&f<=c){H=H<d[t].start?H:d[t].start;break}}return H};let A=0,$=0;const V=()=>{if($!==0)return!1;A++;const{scrollDOM:c,contentHeight:g}=i;let H=D(l,"padding-block-start");const t=i.lineBlockAtHeight(c.scrollTop),{number:n}=i.state.doc.lineAt(t.from),f=d[n-1];if(!f)return!1;let v=1;const k=l.querySelector(`[data-line="${f.start}"]`)||l.firstElementChild?.firstElementChild,u=l.querySelector(`[data-line="${f.end+1}"]`)||l.lastElementChild?.lastElementChild,r=c.scrollHeight-c.clientHeight,b=l.scrollHeight-l.clientHeight;let T=m(f.start),h=L(f.end),x=k.offsetTop,S=u.offsetTop-x;T===0&&(x=0,k===u?(H=0,h=g-c.offsetHeight,S=b):S=u.offsetTop),v=(c.scrollTop-T)/(h-T);const M=u==l.lastElementChild?.lastElementChild?u.offsetTop+u.clientHeight:u.offsetTop;if(h>=r||M>b){const p=w(r,b);T=m(p),v=(c.scrollTop-T)/(r-T);const q=l.querySelector(`[data-line="${p}"]`);T>0&&q&&(x=q.offsetTop),S=b-x+D(l,"padding-block-start")}const E=x-H+S*v;I(l,E,()=>{A--})},B=()=>{if(A!==0)return;$++;const{scrollDOM:c}=i,g=l.scrollTop,H=l.scrollHeight,t=c.scrollHeight-c.clientHeight,n=l.scrollHeight-l.clientHeight;let f=l.firstElementChild?.firstElementChild,v=l.firstElementChild?.lastElementChild;if(a.length>0){let M=Math.ceil(a[a.length-1]*(g/H)),E=a.findLastIndex(p=>p<=M);E=E===-1?0:E,M=a[E];for(let p=E;p>=0&&p<a.length;)if(s[p].offsetTop>g){if(p-1>=0){p--;continue}M=-1,E=-1;break}else{if(p+1<a.length&&s[p+1].offsetTop<g){p++;continue}M=a[p],E=p;break}switch(E){case-1:{f=l.firstElementChild?.firstElementChild,v=s[0];break}case a.length-1:{f=s[E],v=l.firstElementChild?.lastElementChild;break}default:f=s[E],v=s[E+1===s.length?E:E+1]}}let k=f===l.firstElementChild?.firstElementChild?0:f.offsetTop-D(f,"margin-block-start"),u=v.offsetTop,r=0;const{start:b,end:T}=d[Number(f.dataset.line||0)];let h=m(b);const x=m(T+1===i.state.doc.lines?T:T+1);let S=0;if(x>t||v.offsetTop+v.offsetHeight>n){const M=w(t,n),E=l.querySelector(`[data-line="${M}"]`);k=E?E.offsetTop-D(E,"margin-block-start"):k,h=m(M),r=(g-k)/(n-k),S=t-h}else f===l.firstElementChild?.firstElementChild?(f===v&&(u=v.offsetTop+v.offsetHeight+D(v,"margin-block-end")),S=x,r=Math.max(g/u,0)):(r=Math.max((g-k)/(u-k),0),S=x-h);I(e,h+S*r,()=>{$--})},O=c=>{const{scrollDOM:g,contentHeight:H}=i,t=g.clientHeight;if(H<=t||l.firstElementChild.clientHeight<=l.clientHeight||i.state.doc.lines<=d[d.length-1]?.end)return!1;c.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}},F=o.defineComponent({props:z,setup(e){const l=o.inject("scrollElementRef"),C=o.inject("roorNodeRef"),i=o.ref();o.watch(()=>e.tocItem.active,m=>{m&&e.onActive(e.tocItem,i.value)}),o.onMounted(()=>{e.tocItem.active&&e.onActive(e.tocItem,i.value)});const I=m=>{if(m.stopPropagation(),e.onClick(m,e.tocItem),m.defaultPrevented)return;const L=e.mdHeadingId({text:e.tocItem.text,level:e.tocItem.level,index:e.tocItem.index,currentToken:e.tocItem.currentToken,nextToken:e.tocItem.nextToken}),d=C.value.getElementById(L),s=l.value;if(d&&s){let a=d.offsetParent,N=d.offsetTop;if(s.contains(a))for(;a&&s!=a;)N+=a?.offsetTop,a=a?.offsetParent;const w=d.previousElementSibling;let A=0;w||(A=D(d,"margin-block-start")),s?.scrollTo({top:N-e.scrollElementOffsetTop-A,behavior:"smooth"})}};return()=>o.createVNode("div",{ref:i,class:[`${R.prefix}-catalog-link`,e.tocItem.active&&`${R.prefix}-catalog-active`],onClick:I},[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(m=>o.createVNode(F,{mdHeadingId:e.mdHeadingId,key:`${e.tocItem.text}-link-${m.level}-${m.text}`,tocItem:m,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 C=e.editorId,i=`#${C}-preview-wrapper`,I=o.reactive({list:[],show:!1,scrollElement:e.scrollElement||i}),m=o.shallowRef(),L=o.ref(),d=o.ref(),s=o.ref(),a=o.ref(),N=o.shallowRef(),w=o.ref({});o.provide("scrollElementRef",d),o.provide("roorNodeRef",a);const A=o.computed(()=>{const t=[];return I.list.forEach((n,f)=>{if(e.catalogMaxDepth&&n.level>e.catalogMaxDepth)return;const{text:v,level:k,line:u}=n,r={level:k,text:v,line:u,index:f+1,active:m.value===n};if(t.length===0)t.push(r);else{let b=t[t.length-1];if(r.level>b.level)for(let T=b.level+1;T<=6;T++){const{children:h}=b;if(!h){b.children=[r];break}if(b=h[h.length-1],r.level<=b.level){h.push(r);break}}else t.push(r)}}),t}),$=()=>{if(I.scrollElement instanceof HTMLElement)return I.scrollElement;let t=document;return(I.scrollElement===i||e.isScrollElementInShadow)&&(t=L.value?.getRootNode()),t.querySelector(I.scrollElement)},V=t=>{if(t.length===0)return m.value=void 0,I.list=[],!1;const{activeHead:n,activeIndex:f}=t.reduce((u,r,b)=>{let T=0;if(e.syncWith==="preview"){const h=a.value?.getElementById(e.mdHeadingId({text:r.text,level:r.level,index:b+1,currentToken:r.currentToken,nextToken:r.nextToken}));h instanceof HTMLElement&&(T=G.getRelativeTop(h,d.value))}else{const h=N.value;if(h){const x=h.lineBlockAt(h.state.doc.line(r.line+1).from).top,S=h.scrollDOM.scrollTop;T=x-S}}return T<e.offsetTop&&T>u.minTop?{activeHead:r,activeIndex:b,minTop:T}:u},{activeHead:t[0],activeIndex:0,minTop:Number.MIN_SAFE_INTEGER});let v=n;const{catalogMaxDepth:k}=e;if(k&&v.level>k){for(let u=f;u>=0;u--){const r=t[u];if(r.level<=k){v=r;break}}if(v.level>k){const u=t.find(r=>r.level<=k);u&&(v=u)}}m.value=v,I.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(I.list)},c=t=>{if(s.value?.removeEventListener("scroll",O),e.syncWith==="editor")s.value=N.value?.scrollDOM;else{const n=$();d.value=n,s.value=n===document.documentElement?document:n}V(t),s.value?.addEventListener("scroll",O)},g=t=>{N.value=t};o.watch([()=>e.syncWith,N,()=>e.catalogMaxDepth],()=>{c(I.list)}),o.onMounted(()=>{a.value=L.value.getRootNode(),y.bus.on(C,{name:y.CATALOG_CHANGED,callback:c}),y.bus.on(C,{name:y.GET_EDITOR_VIEW,callback:g}),y.bus.emit(C,y.PUSH_CATALOG),y.bus.emit(C,y.SEND_EDITOR_VIEW)}),o.onBeforeUnmount(()=>{y.bus.remove(C,y.CATALOG_CHANGED,c),y.bus.remove(C,y.GET_EDITOR_VIEW,g),s.value?.removeEventListener("scroll",O)});const H=(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:L},[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(F,{mdHeadingId:e.mdHeadingId,tocItem:t,key:`link-${t.level}-${t.text}`,onActive:B,onClick:H,scrollElementOffsetTop:e.scrollElementOffsetTop},null))])])])}});_.install=e=>(e.component(_.name,_),e);exports.MdCatalog=_;exports.scrollAuto=U;exports.scrollAutoWithScale=j;
@@ -1,57 +1,58 @@
1
1
  import { defineComponent as z, inject as q, ref as D, watch as J, onMounted as K, createVNode as N, reactive as X, shallowRef as G, provide as V, computed as Y, onBeforeUnmount as Z, Fragment as ee } from "vue";
2
2
  import { p as O } from "./config.mjs";
3
3
  import { b as $, j, G as U, k as te, S as le } from "./event-bus.mjs";
4
- import { a as oe } from "./index5.mjs";
5
- import { createSmoothScroll as ne, debounce as ie } from "@vavt/util";
4
+ import { a as ne } from "./index5.mjs";
5
+ import { createSmoothScroll as oe, debounce as ie } from "@vavt/util";
6
6
  const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).getPropertyValue(l).replace("px", ""), ve = (e, l) => {
7
- const p = ie(() => {
8
- e.removeEventListener("scroll", n), e.addEventListener("scroll", n), l.removeEventListener("scroll", n), l.addEventListener("scroll", n);
9
- }, 50), n = (E) => {
7
+ const b = ie(() => {
8
+ e.removeEventListener("scroll", o), e.addEventListener("scroll", o), l.removeEventListener("scroll", o), l.addEventListener("scroll", o);
9
+ }, 50), o = (E) => {
10
10
  const m = e.clientHeight, y = l.clientHeight, f = e.scrollHeight, s = l.scrollHeight, r = (f - m) / (s - y);
11
- E.target === e ? (l.removeEventListener("scroll", n), l.scrollTo({
11
+ E.target === e ? (l.removeEventListener("scroll", o), l.scrollTo({
12
12
  top: e.scrollTop / r
13
13
  // behavior: 'smooth'
14
- }), p()) : (e.removeEventListener("scroll", n), e.scrollTo({
14
+ }), b()) : (e.removeEventListener("scroll", o), e.scrollTo({
15
15
  top: l.scrollTop * r
16
16
  // behavior: 'smooth'
17
- }), p());
17
+ }), b());
18
18
  };
19
19
  return [
20
20
  () => {
21
- p().finally(() => {
21
+ b().finally(() => {
22
22
  e.dispatchEvent(new Event("scroll"));
23
23
  });
24
24
  },
25
25
  () => {
26
- e.removeEventListener("scroll", n), l.removeEventListener("scroll", n);
26
+ e.removeEventListener("scroll", o), l.removeEventListener("scroll", o);
27
27
  }
28
28
  ];
29
- }, he = (e, l, p) => {
30
- const { view: n } = p, E = ne(), m = (c) => n.lineBlockAt(n.state.doc.line(c + 1).from).top, y = (c) => n.lineBlockAt(n.state.doc.line(c + 1).from).bottom;
29
+ }, he = (e, l, b) => {
30
+ const { view: o } = b, E = oe(), m = (i) => o.lineBlockAt(o.state.doc.line(i + 1).from).top, y = (i) => o.lineBlockAt(o.state.doc.line(i + 1).from).bottom;
31
31
  let f = [], s = [], r = [];
32
32
  const L = () => {
33
33
  f = [], s = Array.from(
34
34
  l.querySelectorAll(ce)
35
- ), r = s.map((o) => Number(o.dataset.line));
36
- const c = [...r], { lines: h } = n.state.doc;
37
- let H = c.shift() || 0, t = c.shift() || h;
38
- for (let o = 0; o < h; o++)
39
- o === t && (H = o, t = c.shift() || h), f.push({
35
+ ), r = s.map((n) => Number(n.dataset.line));
36
+ const i = [...r], { lines: h } = o.state.doc;
37
+ i[0] !== 0 && i.unshift(0);
38
+ let H = i.shift() || 0, t = i.shift() || h;
39
+ for (let n = 0; n < h; n++)
40
+ n === t && (H = n, t = i.shift() || h), f.push({
40
41
  start: H,
41
42
  end: t - 1
42
43
  });
43
- }, R = (c, h) => {
44
+ }, R = (i, h) => {
44
45
  let H = 1;
45
46
  for (let t = s.length - 1; t - 1 >= 0; t--) {
46
- const o = s[t], a = s[t - 1];
47
- if (o.offsetTop + o.offsetHeight > h && a.offsetTop < h) {
47
+ const n = s[t], a = s[t - 1];
48
+ if (n.offsetTop + n.offsetHeight > h && a.offsetTop < h) {
48
49
  H = Number(a.dataset.line);
49
50
  break;
50
51
  }
51
52
  }
52
53
  for (let t = f.length - 1; t >= 0; t--) {
53
- const o = y(f[t].end), a = m(f[t].start);
54
- if (o > c && a <= c) {
54
+ const n = y(f[t].end), a = m(f[t].start);
55
+ if (n > i && a <= i) {
55
56
  H = H < f[t].start ? H : f[t].start;
56
57
  break;
57
58
  }
@@ -63,20 +64,20 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
63
64
  if (B !== 0)
64
65
  return !1;
65
66
  x++;
66
- const { scrollDOM: c, contentHeight: h } = n;
67
+ const { scrollDOM: i, contentHeight: h } = o;
67
68
  let H = w(l, "padding-block-start");
68
- const t = n.lineBlockAtHeight(c.scrollTop), { number: o } = n.state.doc.lineAt(t.from), a = f[o - 1];
69
+ const t = o.lineBlockAtHeight(i.scrollTop), { number: n } = o.state.doc.lineAt(t.from), a = f[n - 1];
69
70
  if (!a)
70
71
  return !1;
71
72
  let u = 1;
72
- const k = l.querySelector(`[data-line="${a.start}"]`) || l.firstElementChild?.firstElementChild, d = l.querySelector(`[data-line="${a.end + 1}"]`) || l.lastElementChild?.lastElementChild, i = c.scrollHeight - c.clientHeight, I = l.scrollHeight - l.clientHeight;
73
+ const k = l.querySelector(`[data-line="${a.start}"]`) || l.firstElementChild?.firstElementChild, d = l.querySelector(`[data-line="${a.end + 1}"]`) || l.lastElementChild?.lastElementChild, c = i.scrollHeight - i.clientHeight, I = l.scrollHeight - l.clientHeight;
73
74
  let g = m(a.start), v = y(a.end), C = k.offsetTop, S = d.offsetTop - C;
74
- g === 0 && (C = 0, k === d ? (H = 0, v = h - c.offsetHeight, S = I) : S = d.offsetTop), u = (c.scrollTop - g) / (v - g);
75
+ g === 0 && (C = 0, k === d ? (H = 0, v = h - i.offsetHeight, S = I) : S = d.offsetTop), u = (i.scrollTop - g) / (v - g);
75
76
  const A = d == l.lastElementChild?.lastElementChild ? d.offsetTop + d.clientHeight : d.offsetTop;
76
- if (v >= i || A > I) {
77
- const b = R(i, I);
78
- g = m(b), u = (c.scrollTop - g) / (i - g);
79
- const P = l.querySelector(`[data-line="${b}"]`);
77
+ if (v >= c || A > I) {
78
+ const p = R(c, I);
79
+ g = m(p), u = (i.scrollTop - g) / (c - g);
80
+ const P = l.querySelector(`[data-line="${p}"]`);
80
81
  g > 0 && P && (C = P.offsetTop), S = I - C + w(l, "padding-block-start");
81
82
  }
82
83
  const T = C - H + S * u;
@@ -87,32 +88,32 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
87
88
  if (x !== 0)
88
89
  return;
89
90
  B++;
90
- const { scrollDOM: c } = n, h = l.scrollTop, H = l.scrollHeight, t = c.scrollHeight - c.clientHeight, o = l.scrollHeight - l.clientHeight;
91
+ const { scrollDOM: i } = o, h = l.scrollTop, H = l.scrollHeight, t = i.scrollHeight - i.clientHeight, n = l.scrollHeight - l.clientHeight;
91
92
  let a = l.firstElementChild?.firstElementChild, u = l.firstElementChild?.lastElementChild;
92
93
  if (r.length > 0) {
93
94
  let A = Math.ceil(
94
95
  r[r.length - 1] * (h / H)
95
- ), T = r.findLastIndex((b) => b <= A);
96
+ ), T = r.findLastIndex((p) => p <= A);
96
97
  T = T === -1 ? 0 : T, A = r[T];
97
- for (let b = T; b >= 0 && b < r.length; )
98
- if (s[b].offsetTop > h) {
99
- if (b - 1 >= 0) {
100
- b--;
98
+ for (let p = T; p >= 0 && p < r.length; )
99
+ if (s[p].offsetTop > h) {
100
+ if (p - 1 >= 0) {
101
+ p--;
101
102
  continue;
102
103
  }
103
- A = -1, T = b;
104
+ A = -1, T = -1;
104
105
  break;
105
106
  } else {
106
- if (b + 1 < r.length && s[b + 1].offsetTop < h) {
107
- b++;
107
+ if (p + 1 < r.length && s[p + 1].offsetTop < h) {
108
+ p++;
108
109
  continue;
109
110
  }
110
- A = r[b], T = b;
111
+ A = r[p], T = p;
111
112
  break;
112
113
  }
113
114
  switch (T) {
114
115
  case -1: {
115
- a = l.firstElementChild?.firstElementChild, u = s[T];
116
+ a = l.firstElementChild?.firstElementChild, u = s[0];
116
117
  break;
117
118
  }
118
119
  case r.length - 1: {
@@ -123,28 +124,28 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
123
124
  a = s[T], u = s[T + 1 === s.length ? T : T + 1];
124
125
  }
125
126
  }
126
- let k = a === l.firstElementChild?.firstElementChild ? 0 : a.offsetTop - w(a, "margin-block-start"), d = u.offsetTop, i = 0;
127
+ let k = a === l.firstElementChild?.firstElementChild ? 0 : a.offsetTop - w(a, "margin-block-start"), d = u.offsetTop, c = 0;
127
128
  const { start: I, end: g } = f[Number(a.dataset.line || 0)];
128
129
  let v = m(I);
129
130
  const C = m(
130
- g + 1 === n.state.doc.lines ? g : g + 1
131
+ g + 1 === o.state.doc.lines ? g : g + 1
131
132
  );
132
133
  let S = 0;
133
- if (C > t || u.offsetTop + u.offsetHeight > o) {
134
- const A = R(t, o), T = l.querySelector(`[data-line="${A}"]`);
135
- k = T ? T.offsetTop - w(T, "margin-block-start") : k, v = m(A), i = (h - k) / (o - k), S = t - v;
136
- } else a === l.firstElementChild?.firstElementChild ? (a === u && (d = u.offsetTop + u.offsetHeight + w(u, "margin-block-end")), S = C, i = Math.max(h / d, 0)) : (i = Math.max(
134
+ if (C > t || u.offsetTop + u.offsetHeight > n) {
135
+ const A = R(t, n), T = l.querySelector(`[data-line="${A}"]`);
136
+ k = T ? T.offsetTop - w(T, "margin-block-start") : k, v = m(A), c = (h - k) / (n - k), S = t - v;
137
+ } else a === l.firstElementChild?.firstElementChild ? (a === u && (d = u.offsetTop + u.offsetHeight + w(u, "margin-block-end")), S = C, c = Math.max(h / d, 0)) : (c = Math.max(
137
138
  (h - k) / (d - k),
138
139
  0
139
140
  ), S = C - v);
140
- E(e, v + S * i, () => {
141
+ E(e, v + S * c, () => {
141
142
  B--;
142
143
  });
143
- }, M = (c) => {
144
- const { scrollDOM: h, contentHeight: H } = n, t = h.clientHeight;
145
- if (H <= t || l.firstElementChild.clientHeight <= l.clientHeight || n.state.doc.lines <= f[f.length - 1]?.end)
144
+ }, M = (i) => {
145
+ const { scrollDOM: h, contentHeight: H } = o, t = h.clientHeight;
146
+ if (H <= t || l.firstElementChild.clientHeight <= l.clientHeight || o.state.doc.lines <= f[f.length - 1]?.end)
146
147
  return !1;
147
- c.target === e ? _() : F();
148
+ i.target === e ? _() : F();
148
149
  };
149
150
  return [
150
151
  () => {
@@ -181,11 +182,11 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
181
182
  }, Q = /* @__PURE__ */ z({
182
183
  props: se,
183
184
  setup(e) {
184
- const l = q("scrollElementRef"), p = q("roorNodeRef"), n = D();
185
+ const l = q("scrollElementRef"), b = q("roorNodeRef"), o = D();
185
186
  J(() => e.tocItem.active, (m) => {
186
- m && e.onActive(e.tocItem, n.value);
187
+ m && e.onActive(e.tocItem, o.value);
187
188
  }), K(() => {
188
- e.tocItem.active && e.onActive(e.tocItem, n.value);
189
+ e.tocItem.active && e.onActive(e.tocItem, o.value);
189
190
  });
190
191
  const E = (m) => {
191
192
  if (m.stopPropagation(), e.onClick(m, e.tocItem), m.defaultPrevented)
@@ -196,7 +197,7 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
196
197
  index: e.tocItem.index,
197
198
  currentToken: e.tocItem.currentToken,
198
199
  nextToken: e.tocItem.nextToken
199
- }), f = p.value.getElementById(y), s = l.value;
200
+ }), f = b.value.getElementById(y), s = l.value;
200
201
  if (f && s) {
201
202
  let r = f.offsetParent, L = f.offsetTop;
202
203
  if (s.contains(r))
@@ -211,7 +212,7 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
211
212
  }
212
213
  };
213
214
  return () => N("div", {
214
- ref: n,
215
+ ref: o,
215
216
  class: [`${O}-catalog-link`, e.tocItem.active && `${O}-catalog-active`],
216
217
  onClick: E
217
218
  }, [N("span", {
@@ -315,81 +316,81 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
315
316
  props: re,
316
317
  emits: ["onClick", "onActive"],
317
318
  setup(e, l) {
318
- const p = e.editorId, n = `#${p}-preview-wrapper`, E = X({
319
+ const b = e.editorId, o = `#${b}-preview-wrapper`, E = X({
319
320
  list: [],
320
321
  show: !1,
321
- scrollElement: e.scrollElement || n
322
+ scrollElement: e.scrollElement || o
322
323
  }), m = G(), y = D(), f = D(), s = D(), r = D(), L = G(), R = D({});
323
324
  V("scrollElementRef", f), V("roorNodeRef", r);
324
325
  const x = Y(() => {
325
326
  const t = [];
326
- return E.list.forEach((o, a) => {
327
- if (e.catalogMaxDepth && o.level > e.catalogMaxDepth)
327
+ return E.list.forEach((n, a) => {
328
+ if (e.catalogMaxDepth && n.level > e.catalogMaxDepth)
328
329
  return;
329
330
  const {
330
331
  text: u,
331
332
  level: k,
332
333
  line: d
333
- } = o, i = {
334
+ } = n, c = {
334
335
  level: k,
335
336
  text: u,
336
337
  line: d,
337
338
  index: a + 1,
338
- active: m.value === o
339
+ active: m.value === n
339
340
  };
340
341
  if (t.length === 0)
341
- t.push(i);
342
+ t.push(c);
342
343
  else {
343
344
  let I = t[t.length - 1];
344
- if (i.level > I.level)
345
+ if (c.level > I.level)
345
346
  for (let g = I.level + 1; g <= 6; g++) {
346
347
  const {
347
348
  children: v
348
349
  } = I;
349
350
  if (!v) {
350
- I.children = [i];
351
+ I.children = [c];
351
352
  break;
352
353
  }
353
- if (I = v[v.length - 1], i.level <= I.level) {
354
- v.push(i);
354
+ if (I = v[v.length - 1], c.level <= I.level) {
355
+ v.push(c);
355
356
  break;
356
357
  }
357
358
  }
358
359
  else
359
- t.push(i);
360
+ t.push(c);
360
361
  }
361
362
  }), t;
362
363
  }), B = () => {
363
364
  if (E.scrollElement instanceof HTMLElement)
364
365
  return E.scrollElement;
365
366
  let t = document;
366
- return (E.scrollElement === n || e.isScrollElementInShadow) && (t = y.value?.getRootNode()), t.querySelector(E.scrollElement);
367
+ return (E.scrollElement === o || e.isScrollElementInShadow) && (t = y.value?.getRootNode()), t.querySelector(E.scrollElement);
367
368
  }, _ = (t) => {
368
369
  if (t.length === 0)
369
370
  return m.value = void 0, E.list = [], !1;
370
371
  const {
371
- activeHead: o,
372
+ activeHead: n,
372
373
  activeIndex: a
373
- } = t.reduce((d, i, I) => {
374
+ } = t.reduce((d, c, I) => {
374
375
  let g = 0;
375
376
  if (e.syncWith === "preview") {
376
377
  const v = r.value?.getElementById(e.mdHeadingId({
377
- text: i.text,
378
- level: i.level,
378
+ text: c.text,
379
+ level: c.level,
379
380
  index: I + 1,
380
- currentToken: i.currentToken,
381
- nextToken: i.nextToken
381
+ currentToken: c.currentToken,
382
+ nextToken: c.nextToken
382
383
  }));
383
- v instanceof HTMLElement && (g = oe(v, f.value));
384
+ v instanceof HTMLElement && (g = ne(v, f.value));
384
385
  } else {
385
386
  const v = L.value;
386
387
  if (v) {
387
- const C = v.lineBlockAt(v.state.doc.line(i.line + 1).from).top, S = v.scrollDOM.scrollTop;
388
+ const C = v.lineBlockAt(v.state.doc.line(c.line + 1).from).top, S = v.scrollDOM.scrollTop;
388
389
  g = C - S;
389
390
  }
390
391
  }
391
392
  return g < e.offsetTop && g > d.minTop ? {
392
- activeHead: i,
393
+ activeHead: c,
393
394
  activeIndex: I,
394
395
  minTop: g
395
396
  } : d;
@@ -398,54 +399,54 @@ const ce = `.${O}-preview > [data-line]`, w = (e, l) => +getComputedStyle(e).get
398
399
  activeIndex: 0,
399
400
  minTop: Number.MIN_SAFE_INTEGER
400
401
  });
401
- let u = o;
402
+ let u = n;
402
403
  const {
403
404
  catalogMaxDepth: k
404
405
  } = e;
405
406
  if (k && u.level > k) {
406
407
  for (let d = a; d >= 0; d--) {
407
- const i = t[d];
408
- if (i.level <= k) {
409
- u = i;
408
+ const c = t[d];
409
+ if (c.level <= k) {
410
+ u = c;
410
411
  break;
411
412
  }
412
413
  }
413
414
  if (u.level > k) {
414
- const d = t.find((i) => i.level <= k);
415
+ const d = t.find((c) => c.level <= k);
415
416
  d && (u = d);
416
417
  }
417
418
  }
418
419
  m.value = u, E.list = t;
419
- }, F = (t, o) => {
420
- R.value.top = o.offsetTop + w(o, "padding-block-start") + "px", e.onActive?.(t, o), l.emit("onActive", t, o);
420
+ }, F = (t, n) => {
421
+ R.value.top = n.offsetTop + w(n, "padding-block-start") + "px", e.onActive?.(t, n), l.emit("onActive", t, n);
421
422
  }, M = () => {
422
423
  _(E.list);
423
- }, c = (t) => {
424
+ }, i = (t) => {
424
425
  if (s.value?.removeEventListener("scroll", M), e.syncWith === "editor")
425
426
  s.value = L.value?.scrollDOM;
426
427
  else {
427
- const o = B();
428
- f.value = o, s.value = o === document.documentElement ? document : o;
428
+ const n = B();
429
+ f.value = n, s.value = n === document.documentElement ? document : n;
429
430
  }
430
431
  _(t), s.value?.addEventListener("scroll", M);
431
432
  }, h = (t) => {
432
433
  L.value = t;
433
434
  };
434
435
  J([() => e.syncWith, L, () => e.catalogMaxDepth], () => {
435
- c(E.list);
436
+ i(E.list);
436
437
  }), K(() => {
437
- r.value = y.value.getRootNode(), $.on(p, {
438
+ r.value = y.value.getRootNode(), $.on(b, {
438
439
  name: j,
439
- callback: c
440
- }), $.on(p, {
440
+ callback: i
441
+ }), $.on(b, {
441
442
  name: U,
442
443
  callback: h
443
- }), $.emit(p, te), $.emit(p, le);
444
+ }), $.emit(b, te), $.emit(b, le);
444
445
  }), Z(() => {
445
- $.remove(p, j, c), $.remove(p, U, h), s.value?.removeEventListener("scroll", M);
446
+ $.remove(b, j, i), $.remove(b, U, h), s.value?.removeEventListener("scroll", M);
446
447
  });
447
- const H = (t, o) => {
448
- e.onClick?.(t, o), l.emit("onClick", t, o);
448
+ const H = (t, n) => {
449
+ e.onClick?.(t, n), l.emit("onClick", t, n);
449
450
  };
450
451
  return () => N("div", {
451
452
  class: [`${O}-catalog`, e.theme === "dark" && `${O}-catalog-dark`, e.class || ""],