@matechat/core 1.7.0 → 1.8.0-alpha.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/Bubble/index.js +6 -6
- package/Input/index.js +4 -4
- package/MarkdownCard/MermaidService-B6BcjbW_.js +127 -0
- package/MarkdownCard/index.css +1 -1
- package/MarkdownCard/index.js +361 -334
- package/package.json +1 -1
- package/MarkdownCard/MermaidService-cIIuQ-0H.js +0 -103
package/package.json
CHANGED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
class f {
|
|
2
|
-
constructor(t = {}) {
|
|
3
|
-
this.config = t, this.mermaidInstance = null, this.isLoading = !1, this.lastValidResult = "", this.viewStateMap = /* @__PURE__ */ new WeakMap(), this.containerHeight = 400;
|
|
4
|
-
}
|
|
5
|
-
async loadMermaid() {
|
|
6
|
-
if (this.mermaidInstance)
|
|
7
|
-
return this.mermaidInstance;
|
|
8
|
-
if (this.isLoading)
|
|
9
|
-
return new Promise((t) => {
|
|
10
|
-
const e = () => {
|
|
11
|
-
this.mermaidInstance ? t(this.mermaidInstance) : setTimeout(e, 50);
|
|
12
|
-
};
|
|
13
|
-
e();
|
|
14
|
-
});
|
|
15
|
-
this.isLoading = !0;
|
|
16
|
-
try {
|
|
17
|
-
const { default: t } = await import("mermaid");
|
|
18
|
-
return t.initialize({
|
|
19
|
-
theme: this.config.theme || "default",
|
|
20
|
-
startOnLoad: !1,
|
|
21
|
-
suppressErrorRendering: !0,
|
|
22
|
-
...this.config
|
|
23
|
-
}), this.mermaidInstance = t, t;
|
|
24
|
-
} catch (t) {
|
|
25
|
-
throw console.error("Failed to load mermaid:", t), new Error("Failed to load mermaid library");
|
|
26
|
-
} finally {
|
|
27
|
-
this.isLoading = !1;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async renderToContainer(t, e, s = "light") {
|
|
31
|
-
const i = await this.renderMermaid(e, s);
|
|
32
|
-
t.innerHTML = i;
|
|
33
|
-
const a = t.querySelector("svg");
|
|
34
|
-
a && (this.initViewState(t, a), this.applyTransform(t, a), a.addEventListener("mousedown", (r) => this.onSvgMouseDown(r, t, a)));
|
|
35
|
-
}
|
|
36
|
-
initViewState(t, e) {
|
|
37
|
-
let s = e.getAttribute("viewBox"), i = 0, a = 0;
|
|
38
|
-
if (s) {
|
|
39
|
-
const l = s.split(/\s+/);
|
|
40
|
-
i = parseFloat(l[2]), a = parseFloat(l[3]);
|
|
41
|
-
} else
|
|
42
|
-
i = e.width.baseVal.value || e.getBoundingClientRect().width, a = e.height.baseVal.value || e.getBoundingClientRect().height;
|
|
43
|
-
const r = t.clientWidth || 0, n = this.containerHeight;
|
|
44
|
-
let o = 1;
|
|
45
|
-
i && a && r && n && (o = Math.min(r / i, n / a, 1)), this.viewStateMap.set(t, {
|
|
46
|
-
scale: o,
|
|
47
|
-
offsetX: 0,
|
|
48
|
-
offsetY: 0,
|
|
49
|
-
dragging: !1,
|
|
50
|
-
dragStart: { x: 0, y: 0 },
|
|
51
|
-
lastOffset: { x: 0, y: 0 }
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
applyTransform(t, e) {
|
|
55
|
-
const s = this.viewStateMap.get(t);
|
|
56
|
-
s && (e.style.position = "absolute", e.style.left = "50%", e.style.top = "50%", e.style.transform = `translate(-50%, -50%) translate(${s.offsetX}px, ${s.offsetY}px) scale(${s.scale})`, e.style.transformOrigin = "center center", e.style.cursor = s.dragging ? "grabbing" : "grab");
|
|
57
|
-
}
|
|
58
|
-
zoomIn(t) {
|
|
59
|
-
const e = t.querySelector("svg"), s = this.viewStateMap.get(t);
|
|
60
|
-
e && s && (s.scale = Math.min(s.scale + 0.2, 3), this.applyTransform(t, e));
|
|
61
|
-
}
|
|
62
|
-
zoomOut(t) {
|
|
63
|
-
const e = t.querySelector("svg"), s = this.viewStateMap.get(t);
|
|
64
|
-
e && s && (s.scale = Math.max(s.scale - 0.2, 0.2), this.applyTransform(t, e));
|
|
65
|
-
}
|
|
66
|
-
reset(t) {
|
|
67
|
-
const e = t.querySelector("svg");
|
|
68
|
-
e && (this.initViewState(t, e), this.applyTransform(t, e));
|
|
69
|
-
}
|
|
70
|
-
onSvgMouseDown(t, e, s) {
|
|
71
|
-
const i = this.viewStateMap.get(e);
|
|
72
|
-
if (!i) return;
|
|
73
|
-
i.dragging = !0, i.dragStart = { x: t.clientX, y: t.clientY }, i.lastOffset = { x: i.offsetX, y: i.offsetY };
|
|
74
|
-
const a = (n) => this.onSvgMouseMove(n, e, s), r = () => this.onSvgMouseUp(e, s, a, r);
|
|
75
|
-
document.addEventListener("mousemove", a), document.addEventListener("mouseup", r), this.applyTransform(e, s);
|
|
76
|
-
}
|
|
77
|
-
onSvgMouseMove(t, e, s) {
|
|
78
|
-
const i = this.viewStateMap.get(e);
|
|
79
|
-
!i || !i.dragging || (i.offsetX = i.lastOffset.x + (t.clientX - i.dragStart.x), i.offsetY = i.lastOffset.y + (t.clientY - i.dragStart.y), this.applyTransform(e, s));
|
|
80
|
-
}
|
|
81
|
-
onSvgMouseUp(t, e, s, i) {
|
|
82
|
-
const a = this.viewStateMap.get(t);
|
|
83
|
-
a && (a.dragging = !1, document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", i), this.applyTransform(t, e));
|
|
84
|
-
}
|
|
85
|
-
async renderMermaid(t, e = "light") {
|
|
86
|
-
try {
|
|
87
|
-
const s = await this.loadMermaid();
|
|
88
|
-
this.config.theme !== e && (this.config.theme = e, s.initialize({
|
|
89
|
-
startOnLoad: !1,
|
|
90
|
-
suppressErrorRendering: !0,
|
|
91
|
-
theme: e === "dark" ? "dark" : "default",
|
|
92
|
-
...this.config
|
|
93
|
-
}));
|
|
94
|
-
const i = `mc_mermaid_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, { svg: a } = await s.render(i, t);
|
|
95
|
-
return this.lastValidResult = a, a;
|
|
96
|
-
} catch {
|
|
97
|
-
return this.lastValidResult;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export {
|
|
102
|
-
f as MermaidService
|
|
103
|
-
};
|