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.
- package/lib/cjs/chunks/index4.cjs +1 -1
- package/lib/es/chunks/index4.mjs +98 -97
- package/lib/preview.css +2443 -1
- package/lib/style.css +3139 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
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;
|
package/lib/es/chunks/index4.mjs
CHANGED
|
@@ -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
|
|
5
|
-
import { createSmoothScroll as
|
|
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
|
|
8
|
-
e.removeEventListener("scroll",
|
|
9
|
-
}, 50),
|
|
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",
|
|
11
|
+
E.target === e ? (l.removeEventListener("scroll", o), l.scrollTo({
|
|
12
12
|
top: e.scrollTop / r
|
|
13
13
|
// behavior: 'smooth'
|
|
14
|
-
}),
|
|
14
|
+
}), b()) : (e.removeEventListener("scroll", o), e.scrollTo({
|
|
15
15
|
top: l.scrollTop * r
|
|
16
16
|
// behavior: 'smooth'
|
|
17
|
-
}),
|
|
17
|
+
}), b());
|
|
18
18
|
};
|
|
19
19
|
return [
|
|
20
20
|
() => {
|
|
21
|
-
|
|
21
|
+
b().finally(() => {
|
|
22
22
|
e.dispatchEvent(new Event("scroll"));
|
|
23
23
|
});
|
|
24
24
|
},
|
|
25
25
|
() => {
|
|
26
|
-
e.removeEventListener("scroll",
|
|
26
|
+
e.removeEventListener("scroll", o), l.removeEventListener("scroll", o);
|
|
27
27
|
}
|
|
28
28
|
];
|
|
29
|
-
}, he = (e, l,
|
|
30
|
-
const { view:
|
|
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((
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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 = (
|
|
44
|
+
}, R = (i, h) => {
|
|
44
45
|
let H = 1;
|
|
45
46
|
for (let t = s.length - 1; t - 1 >= 0; t--) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
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
|
|
54
|
-
if (
|
|
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:
|
|
67
|
+
const { scrollDOM: i, contentHeight: h } = o;
|
|
67
68
|
let H = w(l, "padding-block-start");
|
|
68
|
-
const t =
|
|
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,
|
|
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 -
|
|
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 >=
|
|
77
|
-
const
|
|
78
|
-
g = m(
|
|
79
|
-
const P = l.querySelector(`[data-line="${
|
|
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:
|
|
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((
|
|
96
|
+
), T = r.findLastIndex((p) => p <= A);
|
|
96
97
|
T = T === -1 ? 0 : T, A = r[T];
|
|
97
|
-
for (let
|
|
98
|
-
if (s[
|
|
99
|
-
if (
|
|
100
|
-
|
|
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 =
|
|
104
|
+
A = -1, T = -1;
|
|
104
105
|
break;
|
|
105
106
|
} else {
|
|
106
|
-
if (
|
|
107
|
-
|
|
107
|
+
if (p + 1 < r.length && s[p + 1].offsetTop < h) {
|
|
108
|
+
p++;
|
|
108
109
|
continue;
|
|
109
110
|
}
|
|
110
|
-
A = r[
|
|
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[
|
|
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,
|
|
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 ===
|
|
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 >
|
|
134
|
-
const A = R(t,
|
|
135
|
-
k = T ? T.offsetTop - w(T, "margin-block-start") : k, v = m(A),
|
|
136
|
-
} else a === l.firstElementChild?.firstElementChild ? (a === u && (d = u.offsetTop + u.offsetHeight + w(u, "margin-block-end")), S = C,
|
|
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 *
|
|
141
|
+
E(e, v + S * c, () => {
|
|
141
142
|
B--;
|
|
142
143
|
});
|
|
143
|
-
}, M = (
|
|
144
|
-
const { scrollDOM: h, contentHeight: H } =
|
|
145
|
-
if (H <= t || l.firstElementChild.clientHeight <= l.clientHeight ||
|
|
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
|
-
|
|
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"),
|
|
185
|
+
const l = q("scrollElementRef"), b = q("roorNodeRef"), o = D();
|
|
185
186
|
J(() => e.tocItem.active, (m) => {
|
|
186
|
-
m && e.onActive(e.tocItem,
|
|
187
|
+
m && e.onActive(e.tocItem, o.value);
|
|
187
188
|
}), K(() => {
|
|
188
|
-
e.tocItem.active && e.onActive(e.tocItem,
|
|
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 =
|
|
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:
|
|
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
|
|
319
|
+
const b = e.editorId, o = `#${b}-preview-wrapper`, E = X({
|
|
319
320
|
list: [],
|
|
320
321
|
show: !1,
|
|
321
|
-
scrollElement: e.scrollElement ||
|
|
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((
|
|
327
|
-
if (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
|
-
} =
|
|
334
|
+
} = n, c = {
|
|
334
335
|
level: k,
|
|
335
336
|
text: u,
|
|
336
337
|
line: d,
|
|
337
338
|
index: a + 1,
|
|
338
|
-
active: m.value ===
|
|
339
|
+
active: m.value === n
|
|
339
340
|
};
|
|
340
341
|
if (t.length === 0)
|
|
341
|
-
t.push(
|
|
342
|
+
t.push(c);
|
|
342
343
|
else {
|
|
343
344
|
let I = t[t.length - 1];
|
|
344
|
-
if (
|
|
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 = [
|
|
351
|
+
I.children = [c];
|
|
351
352
|
break;
|
|
352
353
|
}
|
|
353
|
-
if (I = v[v.length - 1],
|
|
354
|
-
v.push(
|
|
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(
|
|
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 ===
|
|
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:
|
|
372
|
+
activeHead: n,
|
|
372
373
|
activeIndex: a
|
|
373
|
-
} = t.reduce((d,
|
|
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:
|
|
378
|
-
level:
|
|
378
|
+
text: c.text,
|
|
379
|
+
level: c.level,
|
|
379
380
|
index: I + 1,
|
|
380
|
-
currentToken:
|
|
381
|
-
nextToken:
|
|
381
|
+
currentToken: c.currentToken,
|
|
382
|
+
nextToken: c.nextToken
|
|
382
383
|
}));
|
|
383
|
-
v instanceof HTMLElement && (g =
|
|
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(
|
|
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:
|
|
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 =
|
|
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
|
|
408
|
-
if (
|
|
409
|
-
u =
|
|
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((
|
|
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,
|
|
420
|
-
R.value.top =
|
|
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
|
-
},
|
|
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
|
|
428
|
-
f.value =
|
|
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
|
-
|
|
436
|
+
i(E.list);
|
|
436
437
|
}), K(() => {
|
|
437
|
-
r.value = y.value.getRootNode(), $.on(
|
|
438
|
+
r.value = y.value.getRootNode(), $.on(b, {
|
|
438
439
|
name: j,
|
|
439
|
-
callback:
|
|
440
|
-
}), $.on(
|
|
440
|
+
callback: i
|
|
441
|
+
}), $.on(b, {
|
|
441
442
|
name: U,
|
|
442
443
|
callback: h
|
|
443
|
-
}), $.emit(
|
|
444
|
+
}), $.emit(b, te), $.emit(b, le);
|
|
444
445
|
}), Z(() => {
|
|
445
|
-
$.remove(
|
|
446
|
+
$.remove(b, j, i), $.remove(b, U, h), s.value?.removeEventListener("scroll", M);
|
|
446
447
|
});
|
|
447
|
-
const H = (t,
|
|
448
|
-
e.onClick?.(t,
|
|
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 || ""],
|