md-editor-v3 6.0.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/MdEditor.cjs +5 -5
- package/lib/cjs/chunks/dom.cjs +1 -1
- package/lib/cjs/chunks/index3.cjs +39 -39
- package/lib/es/MdEditor.mjs +219 -219
- package/lib/es/chunks/dom.mjs +132 -92
- package/lib/es/chunks/index3.mjs +375 -383
- package/lib/preview.css +1 -1
- package/lib/style.css +1 -1
- package/lib/types/MdEditor/type.d.ts +1 -0
- package/lib/types/MdEditor/utils/dom.d.ts +6 -0
- package/package.json +2 -2
package/lib/es/chunks/dom.mjs
CHANGED
|
@@ -1,119 +1,159 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import I from "@vavt/copy2clipboard";
|
|
2
|
+
import { p as i } from "./config.mjs";
|
|
3
|
+
const j = {
|
|
4
|
+
copy: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy ${i}-icon"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,
|
|
5
|
+
"collapse-tips": `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-chevron-left ${i}-icon"><circle cx="12" cy="12" r="10"/><path d="m14 16-4-4 4-4"/></svg>`,
|
|
6
|
+
pin: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin ${i}-icon"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg>`,
|
|
7
|
+
"pin-off": `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pin-off ${i}-icon"><path d="M12 17v5"/><path d="M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89"/><path d="m2 2 20 20"/><path d="M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11"/></svg>`,
|
|
8
|
+
check: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check ${i}-icon"><path d="M20 6 9 17l-5-5"/></svg>`
|
|
9
|
+
}, p = (d, s) => typeof s[d] == "string" ? s[d] : j[d], z = (d, s) => {
|
|
10
|
+
const e = (c) => {
|
|
11
|
+
const t = d.parentElement || document.body, n = t.offsetWidth, r = t.offsetHeight, { clientWidth: l, clientHeight: u } = document.documentElement, a = c.offsetX, w = c.offsetY, g = (y) => {
|
|
12
|
+
let h = y.x + document.body.scrollLeft - document.body.clientLeft - a, m = y.y + document.body.scrollTop - document.body.clientTop - w;
|
|
13
|
+
h = h < 1 ? 1 : h < l - n - 1 ? h : l - n - 1, m = m < 1 ? 1 : m < u - r - 1 ? m : u - r - 1, s ? s(h, m) : (t.style.left = `${h}px`, t.style.top = `${m}px`);
|
|
12
14
|
};
|
|
13
|
-
document.addEventListener("mousemove",
|
|
15
|
+
document.addEventListener("mousemove", g);
|
|
14
16
|
const v = () => {
|
|
15
|
-
document.removeEventListener("mousemove",
|
|
17
|
+
document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", v);
|
|
16
18
|
};
|
|
17
19
|
document.addEventListener("mouseup", v);
|
|
18
20
|
};
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
+
return d.addEventListener("mousedown", e), () => {
|
|
22
|
+
d.removeEventListener("mousedown", e);
|
|
21
23
|
};
|
|
22
|
-
},
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
}, A = (d, s, e = "") => {
|
|
25
|
+
const c = document.getElementById(s.id);
|
|
26
|
+
if (c)
|
|
27
|
+
e !== "" && (Reflect.get(window, e) ? s.onload?.call(c, new Event("load")) : s.onload && c.addEventListener("load", s.onload));
|
|
26
28
|
else {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const n =
|
|
29
|
+
const t = { ...s };
|
|
30
|
+
t.onload = null;
|
|
31
|
+
const n = D(d, t);
|
|
30
32
|
s.onload && n.addEventListener("load", s.onload), document.head.appendChild(n);
|
|
31
33
|
}
|
|
32
|
-
},
|
|
33
|
-
document.getElementById(s.id)?.remove(),
|
|
34
|
-
},
|
|
35
|
-
const
|
|
36
|
-
return Object.keys(s).forEach((
|
|
37
|
-
s[
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
const
|
|
41
|
-
|
|
34
|
+
}, b = (d, s) => {
|
|
35
|
+
document.getElementById(s.id)?.remove(), A(d, s);
|
|
36
|
+
}, D = (d, s) => {
|
|
37
|
+
const e = document.createElement(d);
|
|
38
|
+
return Object.keys(s).forEach((c) => {
|
|
39
|
+
s[c] !== void 0 && (e[c] = s[c]);
|
|
40
|
+
}), e;
|
|
41
|
+
}, V = (d, s) => {
|
|
42
|
+
const e = /* @__PURE__ */ new Map();
|
|
43
|
+
return d?.forEach((c) => {
|
|
44
|
+
let t = c.querySelector(`.${i}-mermaid-action`);
|
|
45
|
+
t ? t.querySelector(`.${i}-mermaid-copy`) || t.insertAdjacentHTML(
|
|
46
|
+
"beforeend",
|
|
47
|
+
`<span class="${i}-mermaid-copy">${p("copy", s.customIcon)}</span>`
|
|
48
|
+
) : (c.insertAdjacentHTML(
|
|
49
|
+
"beforeend",
|
|
50
|
+
`<div class="${i}-mermaid-action"><span class="${i}-mermaid-copy">${p("copy", s.customIcon)}</span></div>`
|
|
51
|
+
), t = c.querySelector(`.${i}-mermaid-action`));
|
|
52
|
+
const n = t.querySelector(`.${i}-mermaid-copy`);
|
|
53
|
+
let r = -1;
|
|
54
|
+
const l = () => {
|
|
55
|
+
clearTimeout(r), I(c.dataset.content || "").then(() => {
|
|
56
|
+
n.innerHTML = p("check", s.customIcon);
|
|
57
|
+
}).catch(() => {
|
|
58
|
+
n.innerHTML = p("copy", s.customIcon);
|
|
59
|
+
}).finally(() => {
|
|
60
|
+
r = window.setTimeout(() => {
|
|
61
|
+
n.innerHTML = p("copy", s.customIcon);
|
|
62
|
+
}, 1500);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
n.addEventListener("click", l), e.set(c, {
|
|
66
|
+
removeClick: () => {
|
|
67
|
+
n.removeEventListener("click", l);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}), () => {
|
|
71
|
+
e.forEach(({ removeClick: c }) => {
|
|
72
|
+
c?.();
|
|
73
|
+
}), e.clear();
|
|
74
|
+
};
|
|
75
|
+
}, R = /* @__PURE__ */ (() => {
|
|
76
|
+
const d = (e) => {
|
|
77
|
+
if (!e)
|
|
42
78
|
return () => {
|
|
43
79
|
};
|
|
44
|
-
const
|
|
45
|
-
let
|
|
80
|
+
const c = e.firstChild;
|
|
81
|
+
let t = 1, n = 0, r = 0, l = !1, u, a, w, g = 1;
|
|
46
82
|
const v = () => {
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
),
|
|
53
|
-
},
|
|
54
|
-
if (
|
|
55
|
-
n =
|
|
56
|
-
else if (
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
) /
|
|
61
|
-
|
|
62
|
-
const M = (
|
|
63
|
-
n -=
|
|
83
|
+
c.style.transform = `translate(${n}px, ${r}px) scale(${t})`;
|
|
84
|
+
}, y = (o) => {
|
|
85
|
+
o.touches.length === 1 ? (l = !0, u = o.touches[0].clientX - n, a = o.touches[0].clientY - r) : o.touches.length === 2 && (w = Math.hypot(
|
|
86
|
+
o.touches[0].clientX - o.touches[1].clientX,
|
|
87
|
+
o.touches[0].clientY - o.touches[1].clientY
|
|
88
|
+
), g = t);
|
|
89
|
+
}, h = (o) => {
|
|
90
|
+
if (o.preventDefault(), l && o.touches.length === 1)
|
|
91
|
+
n = o.touches[0].clientX - u, r = o.touches[0].clientY - a, v();
|
|
92
|
+
else if (o.touches.length === 2) {
|
|
93
|
+
const E = Math.hypot(
|
|
94
|
+
o.touches[0].clientX - o.touches[1].clientX,
|
|
95
|
+
o.touches[0].clientY - o.touches[1].clientY
|
|
96
|
+
) / w, f = t;
|
|
97
|
+
t = g * (1 + (E - 1));
|
|
98
|
+
const M = (o.touches[0].clientX + o.touches[1].clientX) / 2, k = (o.touches[0].clientY + o.touches[1].clientY) / 2, H = c.getBoundingClientRect(), X = (M - H.left) / f, S = (k - H.top) / f;
|
|
99
|
+
n -= X * (t - f), r -= S * (t - f), v();
|
|
64
100
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
const L = 0.02,
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
n -= M /
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
|
|
101
|
+
}, m = () => {
|
|
102
|
+
l = !1;
|
|
103
|
+
}, $ = (o) => {
|
|
104
|
+
o.preventDefault();
|
|
105
|
+
const L = 0.02, E = t;
|
|
106
|
+
o.deltaY < 0 ? t += L : t = Math.max(0.1, t - L);
|
|
107
|
+
const f = c.getBoundingClientRect(), M = o.clientX - f.left, k = o.clientY - f.top;
|
|
108
|
+
n -= M / E * (t - E), r -= k / E * (t - E), v();
|
|
109
|
+
}, x = (o) => {
|
|
110
|
+
l = !0, u = o.clientX - n, a = o.clientY - r;
|
|
111
|
+
}, C = (o) => {
|
|
112
|
+
l && (n = o.clientX - u, r = o.clientY - a, v());
|
|
113
|
+
}, T = () => {
|
|
114
|
+
l = !1;
|
|
115
|
+
}, Y = () => {
|
|
116
|
+
l = !1;
|
|
81
117
|
};
|
|
82
|
-
return
|
|
83
|
-
|
|
118
|
+
return e.addEventListener("touchstart", y, { passive: !1 }), e.addEventListener("touchmove", h, { passive: !1 }), e.addEventListener("touchend", m), e.addEventListener("wheel", $, { passive: !1 }), e.addEventListener("mousedown", x), e.addEventListener("mousemove", C), e.addEventListener("mouseup", T), e.addEventListener("mouseleave", Y), () => {
|
|
119
|
+
e.removeEventListener("touchstart", y), e.removeEventListener("touchmove", h), e.removeEventListener("touchend", m), e.removeEventListener("wheel", $), e.removeEventListener("mousedown", x), e.removeEventListener("mousemove", C), e.removeEventListener("mouseup", T), e.removeEventListener("mouseleave", Y);
|
|
84
120
|
};
|
|
85
121
|
};
|
|
86
|
-
return (
|
|
87
|
-
const
|
|
88
|
-
return
|
|
89
|
-
let
|
|
90
|
-
|
|
122
|
+
return (e, c) => {
|
|
123
|
+
const t = /* @__PURE__ */ new Map();
|
|
124
|
+
return e?.forEach((n) => {
|
|
125
|
+
let r = n.querySelector(`.${i}-mermaid-action`);
|
|
126
|
+
r ? r.querySelector(`.${i}-mermaid-zoom`) || r.insertAdjacentHTML(
|
|
127
|
+
"beforeend",
|
|
128
|
+
`<span class="${i}-mermaid-zoom">${p("pin-off", c.customIcon)}</span>`
|
|
129
|
+
) : (n.insertAdjacentHTML(
|
|
91
130
|
"beforeend",
|
|
92
|
-
`<div class="${
|
|
93
|
-
),
|
|
94
|
-
const r = () => {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
131
|
+
`<div class="${i}-mermaid-action"><span class="${i}-mermaid-zoom">${p("pin-off", c.customIcon)}</span></div>`
|
|
132
|
+
), r = n.querySelector(`.${i}-mermaid-action`));
|
|
133
|
+
const l = r.querySelector(`.${i}-mermaid-zoom`), u = () => {
|
|
134
|
+
const a = t.get(n);
|
|
135
|
+
if (a?.removeEvent)
|
|
136
|
+
a.removeEvent(), n.removeAttribute("data-grab"), t.set(n, { removeClick: a.removeClick }), l.innerHTML = p("pin-off", c.customIcon);
|
|
98
137
|
else {
|
|
99
|
-
const
|
|
100
|
-
n.setAttribute("data-grab", ""),
|
|
138
|
+
const w = d(n);
|
|
139
|
+
n.setAttribute("data-grab", ""), t.set(n, { removeEvent: w, removeClick: a?.removeClick }), l.innerHTML = p("pin", c.customIcon);
|
|
101
140
|
}
|
|
102
141
|
};
|
|
103
|
-
|
|
104
|
-
removeClick: () =>
|
|
142
|
+
l.addEventListener("click", u), t.set(n, {
|
|
143
|
+
removeClick: () => l.removeEventListener("click", u)
|
|
105
144
|
});
|
|
106
145
|
}), () => {
|
|
107
|
-
|
|
108
|
-
n?.(),
|
|
109
|
-
}),
|
|
146
|
+
t.forEach(({ removeEvent: n, removeClick: r }) => {
|
|
147
|
+
n?.(), r?.();
|
|
148
|
+
}), t.clear();
|
|
110
149
|
};
|
|
111
150
|
};
|
|
112
151
|
})();
|
|
113
152
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
p as S,
|
|
154
|
+
A as a,
|
|
155
|
+
V as c,
|
|
156
|
+
z as k,
|
|
157
|
+
b as u,
|
|
158
|
+
R as z
|
|
119
159
|
};
|