md-editor-v3 6.2.1 → 6.3.0

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