md-editor-rt
Version:
Markdown editor for react, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...
122 lines (121 loc) • 6.71 kB
JavaScript
import { p as g } from "./config.mjs";
const B = {
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 ${g}-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>`,
"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 ${g}-icon"><circle cx="12" cy="12" r="10"/><path d="m14 16-4-4 4-4"/></svg>`,
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"><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>',
"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"><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>'
}, x = (d, c) => typeof c[d] == "string" ? c[d] : B[d], I = (d, c) => {
const e = (l) => {
const s = d.parentElement || document.body, o = s.offsetWidth, n = s.offsetHeight, { clientWidth: r, clientHeight: i } = document.documentElement, h = l.offsetX, E = l.offsetY, m = (w) => {
let a = w.x + document.body.scrollLeft - document.body.clientLeft - h, u = w.y + document.body.scrollTop - document.body.clientTop - E;
a = a < 1 ? 1 : a < r - o - 1 ? a : r - o - 1, u = u < 1 ? 1 : u < i - n - 1 ? u : i - n - 1, c ? c(a, u) : (s.style.left = a + "px", s.style.top = u + "px");
};
document.addEventListener("mousemove", m);
const p = () => {
document.removeEventListener("mousemove", m), document.removeEventListener("mouseup", p);
};
document.addEventListener("mouseup", p);
};
return d.addEventListener("mousedown", e), () => {
d.removeEventListener("mousedown", e);
};
}, S = (d, c, e = "") => {
var s;
const l = document.getElementById(c.id);
if (l)
e !== "" && (Reflect.get(window, e) ? (s = c.onload) == null || s.call(l, new Event("load")) : c.onload && l.addEventListener("load", c.onload));
else {
const o = { ...c };
o.onload = null;
const n = A(d, o);
c.onload && n.addEventListener("load", c.onload), document.head.appendChild(n);
}
}, V = (d, c) => {
const e = document.getElementById(c.id);
e == null || e.remove(), S(d, c);
}, A = (d, c) => {
const e = document.createElement(d);
return Object.keys(c).forEach((l) => {
c[l] !== void 0 && (e[l] = c[l]);
}), e;
}, z = /* @__PURE__ */ (() => {
const d = (e) => {
if (!e)
return () => {
};
const l = e.firstChild;
let s = 1, o = 0, n = 0, r = !1, i, h, E, m = 1;
const p = () => {
l.style.transform = `translate(${o}px, ${n}px) scale(${s})`;
}, w = (t) => {
t.touches.length === 1 ? (r = !0, i = t.touches[0].clientX - o, h = t.touches[0].clientY - n) : t.touches.length === 2 && (E = Math.hypot(
t.touches[0].clientX - t.touches[1].clientX,
t.touches[0].clientY - t.touches[1].clientY
), m = s);
}, a = (t) => {
if (t.preventDefault(), r && t.touches.length === 1)
o = t.touches[0].clientX - i, n = t.touches[0].clientY - h, p();
else if (t.touches.length === 2) {
const f = Math.hypot(
t.touches[0].clientX - t.touches[1].clientX,
t.touches[0].clientY - t.touches[1].clientY
) / E, v = s;
s = m * (1 + (f - 1));
const M = (t.touches[0].clientX + t.touches[1].clientX) / 2, y = (t.touches[0].clientY + t.touches[1].clientY) / 2, T = l.getBoundingClientRect(), D = (M - T.left) / v, $ = (y - T.top) / v;
o -= D * (s - v), n -= $ * (s - v), p();
}
}, u = () => {
r = !1;
}, k = (t) => {
t.preventDefault();
const L = 0.02, f = s;
t.deltaY < 0 ? s += L : s = Math.max(0.1, s - L);
const v = l.getBoundingClientRect(), M = t.clientX - v.left, y = t.clientY - v.top;
o -= M / f * (s - f), n -= y / f * (s - f), p();
}, Y = (t) => {
r = !0, i = t.clientX - o, h = t.clientY - n;
}, X = (t) => {
r && (o = t.clientX - i, n = t.clientY - h, p());
}, C = () => {
r = !1;
}, H = () => {
r = !1;
};
return e.addEventListener("touchstart", w, { passive: !1 }), e.addEventListener("touchmove", a, { passive: !1 }), e.addEventListener("touchend", u), e.addEventListener("wheel", k, { passive: !1 }), e.addEventListener("mousedown", Y), e.addEventListener("mousemove", X), e.addEventListener("mouseup", C), e.addEventListener("mouseleave", H), () => {
e.removeEventListener("touchstart", w), e.removeEventListener("touchmove", a), e.removeEventListener("touchend", u), e.removeEventListener("wheel", k), e.removeEventListener("mousedown", Y), e.removeEventListener("mousemove", X), e.removeEventListener("mouseup", C), e.removeEventListener("mouseleave", H);
};
};
return (e, l) => {
const s = /* @__PURE__ */ new Map();
return e == null || e.forEach((o) => {
let n = o.querySelector(`.${g}-mermaid-action`);
n || (o.insertAdjacentHTML(
"beforeend",
`<div class="${g}-mermaid-action">${x("pin-off", l.customIcon)}</div>`
), n = o.querySelector(`.${g}-mermaid-action`));
const r = () => {
const i = s.get(o);
if (i != null && i.removeEvent)
i.removeEvent(), o.removeAttribute("data-grab"), s.set(o, { removeClick: i.removeClick }), n.innerHTML = x("pin-off", l.customIcon);
else {
const h = d(o);
o.setAttribute("data-grab", ""), s.set(o, { removeEvent: h, removeClick: i == null ? void 0 : i.removeClick }), n.innerHTML = x("pin", l.customIcon);
}
};
n.addEventListener("click", r), s.set(o, {
removeClick: () => n.removeEventListener("click", r)
});
}), () => {
s.forEach(({ removeEvent: o, removeClick: n }) => {
o == null || o(), n == null || n();
}), s.clear();
};
};
})();
export {
x as S,
S as a,
I as k,
V as u,
z
};