mind-elixir
Version:
Mind elixir is a free open source mind map core.
1,319 lines • 113 kB
JavaScript
const ts = 0, ns = 1, os = 2, be = {
name: "Latte",
type: "light",
palette: ["#dd7878", "#ea76cb", "#8839ef", "#e64553", "#fe640b", "#df8e1d", "#40a02b", "#209fb5", "#1e66f5", "#7287fd"],
cssVar: {
"--node-gap-x": "30px",
"--node-gap-y": "10px",
"--main-gap-x": "65px",
"--main-gap-y": "45px",
"--root-radius": "30px",
"--main-radius": "20px",
"--root-color": "#ffffff",
"--root-bgcolor": "#4c4f69",
"--root-border-color": "rgba(0, 0, 0, 0)",
"--main-color": "#444446",
"--main-bgcolor": "#ffffff",
"--main-bgcolor-transparent": "rgba(255, 255, 255, 0.8)",
"--topic-padding": "3px",
"--color": "#777777",
"--bgcolor": "#f6f6f6",
"--selected": "#4dc4ff",
"--accent-color": "#e64553",
"--panel-color": "#444446",
"--panel-bgcolor": "#ffffff",
"--panel-border-color": "#eaeaea",
"--map-padding": "50px 80px"
}
}, ve = {
name: "Dark",
type: "dark",
palette: ["#848FA0", "#748BE9", "#D2F9FE", "#4145A5", "#789AFA", "#706CF4", "#EF987F", "#775DD5", "#FCEECF", "#DA7FBC"],
cssVar: {
"--node-gap-x": "30px",
"--node-gap-y": "10px",
"--main-gap-x": "65px",
"--main-gap-y": "45px",
"--root-radius": "30px",
"--main-radius": "20px",
"--root-color": "#ffffff",
"--root-bgcolor": "#2d3748",
"--root-border-color": "rgba(255, 255, 255, 0.1)",
"--main-color": "#ffffff",
"--main-bgcolor": "#4c4f69",
"--main-bgcolor-transparent": "rgba(76, 79, 105, 0.8)",
"--topic-padding": "3px",
"--color": "#cccccc",
"--bgcolor": "#252526",
"--selected": "#4dc4ff",
"--accent-color": "#789AFA",
"--panel-color": "#ffffff",
"--panel-bgcolor": "#2d3748",
"--panel-border-color": "#696969",
"--map-padding": "50px 80px"
}
};
function ge(e) {
return e.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
}
const le = function(e, t) {
if (t.id === e)
return t;
if (t.children && t.children.length) {
for (let n = 0; n < t.children.length; n++) {
const o = le(e, t.children[n]);
if (o) return o;
}
return null;
} else
return null;
}, G = (e, t) => {
if (e.parent = t, e.children)
for (let n = 0; n < e.children.length; n++)
G(e.children[n], e);
}, U = (e, t, n) => {
if (e.expanded = t, e.children)
if (n === void 0 || n > 0) {
const o = n !== void 0 ? n - 1 : void 0;
e.children.forEach((s) => {
U(s, t, o);
});
} else
e.children.forEach((o) => {
U(o, !1);
});
};
function xe(e) {
if (e.id = z(), e.children)
for (let t = 0; t < e.children.length; t++)
xe(e.children[t]);
}
function ce(e, t, n, o) {
const s = n - e, i = o - t, c = Math.atan2(i, s) * 180 / Math.PI, r = 12, a = 30, d = (c + 180 - a) * Math.PI / 180, h = (c + 180 + a) * Math.PI / 180;
return {
x1: n + Math.cos(d) * r,
y1: o + Math.sin(d) * r,
x2: n + Math.cos(h) * r,
y2: o + Math.sin(h) * r
};
}
function z() {
return ((/* @__PURE__ */ new Date()).getTime().toString(16) + Math.random().toString(16).substring(2)).substring(2, 18);
}
const pt = function() {
const e = z();
return {
topic: this.newTopicName,
id: e
};
};
function we(e) {
return JSON.parse(
JSON.stringify(e, (n, o) => {
if (n !== "parent")
return o;
})
);
}
const $ = (e, t) => {
let n = 0, o = 0;
for (; t && t !== e; )
n += t.offsetLeft, o += t.offsetTop, t = t.offsetParent;
return { offsetLeft: n, offsetTop: o };
}, A = (e, t) => {
for (const n in t)
e.setAttribute(n, t[n]);
}, ee = (e) => e ? e.tagName === "ME-TPC" : !1, Ee = (e) => e.filter((t) => t.nodeObj.parent).filter((t, n, o) => {
for (let s = 0; s < o.length; s++) {
if (t === o[s]) continue;
const { parent: i } = t.nodeObj;
if (i === o[s].nodeObj)
return !1;
}
return !0;
}), Ce = (e) => {
const t = /translate3d\(([^,]+),\s*([^,]+)/, n = e.match(t);
return n ? { x: parseFloat(n[1]), y: parseFloat(n[2]) } : { x: 0, y: 0 };
}, Je = function(e) {
for (let t = 0; t < e.length; t++) {
const { dom: n, evt: o, func: s } = e[t];
n.addEventListener(o, s);
}
return function() {
for (let n = 0; n < e.length; n++) {
const { dom: o, evt: s, func: i } = e[n];
o.removeEventListener(s, i);
}
};
}, Me = (e, t) => {
const n = e.x - t.x, o = e.y - t.y;
return Math.sqrt(n * n + o * o);
}, gt = function(e, t) {
if (!t)
return de(e), e;
let n = e.querySelector(".insert-preview");
const o = `insert-preview ${t} show`;
return n || (n = document.createElement("div"), e.appendChild(n)), n.className = o, e;
}, de = function(e) {
if (!e) return;
const t = e.querySelectorAll(".insert-preview");
for (const n of t || [])
n.remove();
}, Pe = function(e, t) {
for (const n of t) {
const o = n.parentElement.parentElement.contains(e);
if (!(e && e.tagName === "ME-TPC" && e !== n && !o && e.nodeObj.parent)) return !1;
}
return !0;
}, mt = function(e) {
const t = document.createElement("div");
return t.className = "mind-elixir-ghost", e.container.appendChild(t), t;
};
class yt {
mind;
isMoving = !1;
interval = null;
speed = 20;
constructor(t) {
this.mind = t;
}
move(t, n) {
this.isMoving || (this.isMoving = !0, this.interval = setInterval(() => {
this.mind.move(t * this.speed * this.mind.scaleVal, n * this.speed * this.mind.scaleVal);
}, 100));
}
stop() {
this.isMoving = !1, this.interval && (clearInterval(this.interval), this.interval = null);
}
}
function bt(e) {
return {
isDragging: !1,
insertType: null,
meet: null,
ghost: mt(e),
edgeMoveController: new yt(e),
startX: 0,
startY: 0,
pointerId: null
};
}
const vt = 5;
function Oe(e, t, n, o = !1) {
if (e.spacePressed) return !1;
const s = n.target;
return s?.tagName !== "ME-TPC" || !s.nodeObj.parent ? !1 : (t.startX = n.clientX, t.startY = n.clientY, t.pointerId = n.pointerId, e.dragged = e.currentNodes, o && Qe(e, t), !0);
}
function Ze(e, t, n) {
e.style.transform = `translate(${t - 10}px, ${n - 10}px)`, e.style.display = "block";
}
function Qe(e, t) {
const { dragged: n } = e;
if (!n) return;
const o = document.activeElement;
o && o.isContentEditable && o.blur(), t.isDragging = !0, n.length > 1 ? t.ghost.innerHTML = n.length + "" : t.ghost.innerHTML = n[0].innerHTML;
for (const s of n)
s.parentElement.parentElement.style.opacity = "0.5";
e.panHelper.clear();
}
function xt(e, t, n) {
const { dragged: o } = e;
if (!o || t.pointerId !== n.pointerId) return;
const s = n.clientX - t.startX, i = n.clientY - t.startY, l = Math.sqrt(s * s + i * i);
if (!t.isDragging && l > vt && Qe(e, t), !t.isDragging) return;
const c = e.container.getBoundingClientRect();
Ze(t.ghost, n.clientX - c.x, n.clientY - c.y), n.clientX < c.x + 50 ? t.edgeMoveController.move(1, 0) : n.clientX > c.x + c.width - 50 ? t.edgeMoveController.move(-1, 0) : n.clientY < c.y + 50 ? t.edgeMoveController.move(0, 1) : n.clientY > c.y + c.height - 50 ? t.edgeMoveController.move(0, -1) : t.edgeMoveController.stop(), de(t.meet);
const r = 12 * e.scaleVal, a = document.elementFromPoint(n.clientX, n.clientY - r);
if (Pe(a, o)) {
t.meet = a;
const d = a.getBoundingClientRect(), h = d.y;
n.clientY > h + d.height ? t.insertType = "after" : t.insertType = "in";
} else {
const d = document.elementFromPoint(n.clientX, n.clientY + r);
if (Pe(d, o)) {
t.meet = d;
const u = d.getBoundingClientRect().y;
n.clientY < u ? t.insertType = "before" : t.insertType = "in";
} else
t.insertType = null, t.meet = null;
}
t.meet && gt(t.meet, t.insertType);
}
function wt(e, t, n) {
const { dragged: o } = e;
if (!(!o || t.pointerId !== n.pointerId)) {
t.edgeMoveController.stop();
for (const s of o)
s.parentElement.parentElement.style.opacity = "1";
t.ghost.style.display = "none", t.ghost.innerHTML = "", t.isDragging && t.meet && (de(t.meet), t.insertType === "before" ? e.moveNodeBefore(o, t.meet) : t.insertType === "after" ? e.moveNodeAfter(o, t.meet) : t.insertType === "in" && e.moveNodeIn(o, t.meet)), e.dragged = null, t.isDragging = !1, t.insertType = null, t.meet = null, t.pointerId = null;
}
}
function ue(e, t) {
const { dragged: n } = e;
if (n) {
t.edgeMoveController.stop();
for (const o of n)
o.parentElement.parentElement.style.opacity = "1";
t.meet && de(t.meet), t.ghost.style.display = "none", t.ghost.innerHTML = "", e.dragged = null, t.isDragging = !1, t.insertType = null, t.meet = null, t.pointerId = null;
}
}
function Et(e) {
return () => {
};
}
const B = {
LHS: "lhs",
RHS: "rhs"
}, Ct = function() {
this.nodes.innerHTML = "";
const e = this.createTopic(this.nodeData);
Se.call(this, e, this.nodeData), e.draggable = !1;
const t = document.createElement("me-root");
t.appendChild(e);
const n = this.nodeData.children || [];
if (this.direction === 2) {
let o = 0, s = 0;
n.map((i) => {
i.direction === 0 ? o += 1 : i.direction === 1 ? s += 1 : o <= s ? (i.direction = 0, o += 1) : (i.direction = 1, s += 1);
});
}
St(this, n, t);
}, St = function(e, t, n) {
const o = document.createElement("me-main");
o.className = B.LHS;
const s = document.createElement("me-main");
s.className = B.RHS;
for (let i = 0; i < t.length; i++) {
const l = t[i], { grp: c } = e.createWrapper(l);
e.direction === 2 ? l.direction === 0 ? o.appendChild(c) : s.appendChild(c) : e.direction === 0 ? o.appendChild(c) : s.appendChild(c);
}
e.nodes.appendChild(o), e.nodes.appendChild(n), e.nodes.appendChild(s), e.nodes.appendChild(e.lines), e.nodes.appendChild(e.labelContainer);
}, Nt = function(e, t) {
const n = document.createElement("me-children");
for (let o = 0; o < t.length; o++) {
const s = t[o], { grp: i } = e.createWrapper(s);
n.appendChild(i);
}
return n;
}, et = function(e, t) {
const o = (this?.el ? this.el : t || document).querySelector(`[data-nodeid="me${e}"]`);
if (!o) throw new Error(`FindEle: Node ${e} not found, maybe it's collapsed.`);
return o;
}, Se = function(e, t) {
if (e.innerHTML = "", t.style) {
const n = t.style;
for (const o in n)
e.style[o] = n[o];
}
if (t.dangerouslySetInnerHTML) {
e.innerHTML = t.dangerouslySetInnerHTML;
return;
}
if (t.image) {
const n = t.image;
if (n.url && n.width && n.height) {
const o = document.createElement("img");
o.src = this.imageProxy ? this.imageProxy(n.url) : n.url, o.style.width = n.width + "px", o.style.height = n.height + "px", n.fit && (o.style.objectFit = n.fit), e.appendChild(o), e.image = o;
}
} else e.image && (e.image = void 0);
{
const n = document.createElement("span");
n.className = "text", this.markdown ? n.innerHTML = this.markdown(t.topic, t) : n.textContent = t.topic, e.appendChild(n), e.text = n;
}
if (t.hyperLink) {
const n = document.createElement("a");
n.className = "hyper-link", n.target = "_blank", n.innerText = "🔗", n.href = t.hyperLink, e.appendChild(n), e.link = n;
} else e.link && (e.link = void 0);
if (t.icons && t.icons.length) {
const n = document.createElement("span");
n.className = "icons", n.innerHTML = t.icons.map((o) => `<span>${ge(o)}</span>`).join(""), e.appendChild(n), e.icons = n;
} else e.icons && (e.icons = void 0);
if (t.tags && t.tags.length) {
const n = document.createElement("div");
n.className = "tags", t.tags.forEach((o) => {
const s = document.createElement("span");
typeof o == "string" ? s.textContent = o : (s.textContent = o.text, o.className && (s.className = o.className), o.style && Object.assign(s.style, o.style)), n.appendChild(s);
}), e.appendChild(n), e.tags = n;
} else e.tags && (e.tags = void 0);
}, Tt = function(e, t) {
const n = document.createElement("me-wrapper"), { p: o, tpc: s } = this.createParent(e);
if (n.appendChild(o), !t && e.children && e.children.length > 0) {
const i = Ne(e.expanded);
if (o.appendChild(i), e.expanded !== !1) {
const l = Nt(this, e.children);
n.appendChild(l);
}
}
return { grp: n, top: o, tpc: s };
}, _t = function(e) {
const t = document.createElement("me-parent"), n = this.createTopic(e);
return Se.call(this, n, e), t.appendChild(n), { p: t, tpc: n };
}, kt = function(e) {
const t = document.createElement("me-children");
return t.append(...e), t;
}, Lt = function(e) {
const t = document.createElement("me-tpc");
return t.nodeObj = e, t.dataset.nodeid = "me" + e.id, t;
};
function tt(e) {
const t = document.createRange();
t.selectNodeContents(e);
const n = window.getSelection();
n && (n.removeAllRanges(), n.addRange(t));
}
const Dt = function(e) {
if (!e) return;
const t = document.createElement("div"), n = e.nodeObj, o = n.topic, { offsetLeft: s, offsetTop: i } = $(this.nodes, e);
this.nodes.appendChild(t), t.id = "input-box", t.textContent = o, t.contentEditable = "plaintext-only", t.spellcheck = !1;
const l = getComputedStyle(e);
t.style.cssText = `
left: ${s}px;
top: ${i}px;
min-width:${e.offsetWidth - 8}px;
color:${l.color};
font-size:${l.fontSize};
padding:${l.padding};
margin:${l.margin};
background-color:${l.backgroundColor !== "rgba(0, 0, 0, 0)" && l.backgroundColor};
border: ${l.border};
border-radius:${l.borderRadius}; `, this.direction === 0 && (t.style.right = "0"), tt(t), this.bus.fire("operation", {
name: "beginEdit",
obj: e.nodeObj
}), t.addEventListener("keydown", (c) => {
c.stopPropagation();
const r = c.key;
if (r === "Enter" || r === "Tab") {
if (c.shiftKey) return;
c.preventDefault(), t.blur(), this.container.focus();
} else r === "Escape" && (c.preventDefault(), t.textContent = o, t.blur(), this.container.focus());
}), t.addEventListener("blur", () => {
if (!t) return;
t.remove();
const c = t.innerText?.trim() || "";
c === o || c === "" || (n.topic = c, this.markdown ? e.text.innerHTML = this.markdown(n.topic, n) : e.text.textContent = c, this.linkDiv(), this.bus.fire("operation", {
name: "finishEdit",
obj: n,
origin: o
}));
});
}, Ne = function(e) {
const t = document.createElement("me-epd");
return t.expanded = e !== !1, t.className = e !== !1 ? "minus" : "", t;
}, J = (e) => {
const t = e.parent?.children, n = t?.indexOf(e) ?? 0;
return { siblings: t, index: n };
};
function At(e) {
const { siblings: t, index: n } = J(e);
if (t === void 0) return;
const o = t[n];
n === 0 ? (t[n] = t[t.length - 1], t[t.length - 1] = o) : (t[n] = t[n - 1], t[n - 1] = o);
}
function Mt(e) {
const { siblings: t, index: n } = J(e);
if (t === void 0) return;
const o = t[n];
n === t.length - 1 ? (t[n] = t[0], t[0] = o) : (t[n] = t[n + 1], t[n + 1] = o);
}
function nt(e) {
const { siblings: t, index: n } = J(e);
return t === void 0 ? 0 : (t.splice(n, 1), t.length);
}
function Pt(e, t, n) {
const { siblings: o, index: s } = J(n);
o !== void 0 && (t === "before" ? o.splice(s, 0, e) : o.splice(s + 1, 0, e));
}
function Ot(e, t) {
const { siblings: n, index: o } = J(e);
n !== void 0 && (n[o] = t, t.children = [e]);
}
function $t(e, t, n) {
if (nt(t), n.parent?.parent || (t.direction = n.direction), e === "in")
n.children ? n.children.push(t) : n.children = [t];
else {
t.direction !== void 0 && (t.direction = n.direction);
const { siblings: o, index: s } = J(n);
if (o === void 0) return;
e === "before" ? o.splice(s, 0, t) : o.splice(s + 1, 0, t);
}
}
const Ht = function({ map: e, direction: t }, n) {
if (t === 0)
return 0;
if (t === 1)
return 1;
if (t === 2) {
const o = e.querySelector(".lhs")?.childElementCount || 0, s = e.querySelector(".rhs")?.childElementCount || 0;
return o <= s ? (n.direction = 0, 0) : (n.direction = 1, 1);
}
}, ot = function(e, t, n) {
const o = n.children[0].children[0], s = t.parentElement;
if (s.tagName === "ME-PARENT") {
if (ne(o), s.children[1])
s.nextSibling.appendChild(n);
else {
const i = e.createChildren([n]);
s.appendChild(Ne(!0)), s.insertAdjacentElement("afterend", i);
}
e.linkDiv(n.offsetParent);
} else s.tagName === "ME-ROOT" && (Ht(e, o.nodeObj) === 0 ? e.container.querySelector(".lhs")?.appendChild(n) : e.container.querySelector(".rhs")?.appendChild(n), e.linkDiv());
}, jt = function(e, t) {
const n = e.parentNode;
if (t === 0) {
const o = n.parentNode.parentNode;
o.tagName !== "ME-MAIN" && (o.previousSibling.children[1].remove(), o.remove());
}
n.parentNode.remove();
}, st = {
before: "beforebegin",
after: "afterend"
}, ne = function(e) {
const n = e.parentElement.parentElement.lastElementChild;
n?.tagName === "svg" && n?.remove();
}, It = function(e, t) {
const n = e.nodeObj, o = we(n);
o.style && t.style && (t.style = Object.assign(o.style, t.style));
const s = Object.assign(n, t);
Se.call(this, e, s), this.linkDiv(), this.bus.fire("operation", {
name: "reshapeNode",
obj: s,
origin: o
});
}, Te = function(e, t, n) {
if (!t) return null;
const o = t.nodeObj;
o.expanded === !1 && (e.expandNode(t, !0), t = e.findEle(o.id));
const s = n || e.generateNewObj();
o.children ? o.children.push(s) : o.children = [s], G(e.nodeData);
const { grp: i, top: l } = e.createWrapper(s);
return ot(e, t, i), { newTop: l, newNodeObj: s };
}, Rt = function(e, t, n) {
const o = t || this.currentNode;
if (!o) return;
const s = o.nodeObj;
if (s.parent) {
if (!s.parent?.parent && this.direction === 2) {
const a = this.map.querySelector(".lhs")?.childElementCount || 0, d = this.map.querySelector(".rhs")?.childElementCount || 0;
if (!a || !d) {
this.addChild(this.findEle(s.parent.id), n);
return;
}
}
} else {
this.addChild();
return;
}
const i = n || this.generateNewObj();
if (!s.parent?.parent) {
const a = o.closest("me-main").className === B.LHS ? 0 : 1;
i.direction = a;
}
Pt(i, e, s), G(this.nodeData);
const l = o.parentElement, { grp: c, top: r } = this.createWrapper(i);
l.parentElement.insertAdjacentElement(st[e], c), this.linkDiv(c.offsetParent), n || this.editTopic(r.firstChild), this.bus.fire("operation", {
name: "insertSibling",
type: e,
obj: i
}), this.selectNode(r.firstChild, !0);
}, Bt = function(e, t) {
const n = e || this.currentNode;
if (!n) return;
ne(n);
const o = n.nodeObj;
if (!o.parent)
return;
const s = t || this.generateNewObj();
Ot(o, s), G(this.nodeData);
const i = n.parentElement.parentElement, { grp: l, top: c } = this.createWrapper(s, !0);
c.appendChild(Ne(!0)), i.insertAdjacentElement("afterend", l);
const r = this.createChildren([i]);
c.insertAdjacentElement("afterend", r), this.linkDiv(), t || this.editTopic(c.firstChild), this.selectNode(c.firstChild, !0), this.bus.fire("operation", {
name: "insertParent",
obj: s
});
}, Wt = function(e, t) {
const n = e || this.currentNode;
if (!n) return;
const o = Te(this, n, t);
if (!o) return;
const { newTop: s, newNodeObj: i } = o;
this.bus.fire("operation", {
name: "addChild",
obj: i
}), t || this.editTopic(s.firstChild), this.selectNode(s.firstChild, !0);
}, Yt = function(e, t) {
const n = we(e.nodeObj);
xe(n);
const o = Te(this, t, n);
if (!o) return;
const { newNodeObj: s } = o;
this.selectNode(this.findEle(s.id)), this.bus.fire("operation", {
name: "copyNode",
obj: s
});
}, Xt = function(e, t) {
const n = [];
for (let o = 0; o < e.length; o++) {
const s = e[o], i = we(s.nodeObj);
xe(i);
const l = Te(this, t, i);
if (!l) return;
const { newNodeObj: c } = l;
n.push(c);
}
this.unselectNodes(this.currentNodes), this.selectNodes(n.map((o) => this.findEle(o.id))), this.bus.fire("operation", {
name: "copyNodes",
objs: n
});
}, Ft = function(e) {
const t = e || this.currentNode;
if (!t) return;
const n = t.nodeObj;
At(n);
const o = t.parentNode.parentNode;
o.parentNode.insertBefore(o, o.previousSibling), this.linkDiv(), this.bus.fire("operation", {
name: "moveUpNode",
obj: n
});
}, Gt = function(e) {
const t = e || this.currentNode;
if (!t) return;
const n = t.nodeObj;
Mt(n);
const o = t.parentNode.parentNode;
o.nextSibling ? o.nextSibling.insertAdjacentElement("afterend", o) : o.parentNode.prepend(o), this.linkDiv(), this.bus.fire("operation", {
name: "moveDownNode",
obj: n
});
}, zt = function(e) {
if (e = Ee(e), e.length === 0) return;
for (const n of e) {
const o = n.nodeObj, s = nt(o);
jt(n, s);
}
const t = e[e.length - 1];
this.selectNode(this.findEle(t.nodeObj.parent.id)), this.linkDiv(), this.bus.fire("operation", {
name: "removeNodes",
objs: e.map((n) => n.nodeObj)
});
}, _e = (e, t, n, o) => {
e = Ee(e);
let s = n.nodeObj;
t === "in" && s.expanded === !1 && (o.expandNode(n, !0), n = o.findEle(s.id), s = n.nodeObj), t === "after" && (e = e.reverse());
const i = [];
for (const c of e) {
const r = c.nodeObj;
if ($t(t, r, s), G(o.nodeData), t === "in") {
const a = c.parentElement;
ot(o, n, a.parentElement);
} else {
ne(c);
const a = c.parentElement.parentNode;
i.includes(a.parentElement) || i.push(a.parentElement), n.parentElement.parentNode.insertAdjacentElement(st[t], a);
}
}
for (const c of i)
c.childElementCount === 0 && c.tagName !== "ME-MAIN" && (c.previousSibling.children[1].remove(), c.remove());
o.linkDiv(), o.scrollIntoView(e[e.length - 1]);
const l = t === "before" ? "moveNodeBefore" : t === "after" ? "moveNodeAfter" : "moveNodeIn";
o.bus.fire("operation", {
name: l,
objs: e.map((c) => c.nodeObj),
toObj: s
});
}, Kt = function(e, t) {
_e(e, "in", t, this);
}, Vt = function(e, t) {
_e(e, "before", t, this);
}, qt = function(e, t) {
_e(e, "after", t, this);
}, Ut = function(e) {
const t = e || this.currentNode;
t && (t.nodeObj.dangerouslySetInnerHTML || this.editTopic(t));
}, Jt = function(e, t) {
e.text.textContent = t, e.nodeObj.topic = t, this.linkDiv();
}, it = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
addChild: Wt,
beginEdit: Ut,
copyNode: Yt,
copyNodes: Xt,
insertParent: Bt,
insertSibling: Rt,
moveDownNode: Gt,
moveNodeAfter: qt,
moveNodeBefore: Vt,
moveNodeIn: Kt,
moveUpNode: Ft,
removeNodes: zt,
reshapeNode: It,
rmSubline: ne,
setNodeTopic: Jt
}, Symbol.toStringTag, { value: "Module" }));
function Zt(e) {
return {
nodeData: e.isFocusMode ? e.nodeDataBackup : e.nodeData,
arrows: e.arrows,
summaries: e.summaries,
direction: e.direction,
theme: e.theme
};
}
const Qt = function(e) {
const t = this.container, n = e.getBoundingClientRect(), o = t.getBoundingClientRect();
if (n.top > o.bottom - 50 || n.bottom < o.top + 50 || n.left > o.right - 50 || n.right < o.left + 50) {
const i = n.left + n.width / 2, l = n.top + n.height / 2, c = o.left + o.width / 2, r = o.top + o.height / 2, a = i - c, d = l - r;
this.move(-a, -d, !0);
}
}, en = function(e, t, n) {
this.clearSelection(), this.scrollIntoView(e), this.selection?.select(e), t && this.bus.fire("selectNewNode", e.nodeObj);
}, tn = function(e) {
this.selection?.select(e);
}, nn = function(e) {
this.selection?.deselect(e);
}, on = function() {
this.unselectNodes(this.currentNodes), this.unselectSummary(), this.unselectArrow();
}, ke = function(e) {
return JSON.stringify(e, (t, n) => {
if (!(t === "parent" && typeof n != "string"))
return n;
});
}, sn = function() {
const e = Zt(this);
return ke(e);
}, rn = function() {
return JSON.parse(this.getDataString());
}, ln = function() {
this.editable = !0;
}, cn = function() {
this.editable = !1;
}, an = function(e, t = { x: 0, y: 0 }) {
if (e < this.scaleMin && e < this.scaleVal || e > this.scaleMax && e > this.scaleVal) return;
const n = this.container.getBoundingClientRect(), o = t.x ? t.x - n.left - n.width / 2 : 0, s = t.y ? t.y - n.top - n.height / 2 : 0, { dx: i, dy: l } = Le(this), c = this.map.style.transform, { x: r, y: a } = Ce(c), d = r - i, h = a - l, u = this.scaleVal, y = (-o + d) * (1 - e / u), b = (-s + h) * (1 - e / u);
this.map.style.transform = `translate3d(${r - y}px, ${a - b}px, 0) scale(${e})`, this.scaleVal = e, this.bus.fire("scale", e);
}, dn = function() {
const e = this.nodes.offsetHeight / this.container.offsetHeight, t = this.nodes.offsetWidth / this.container.offsetWidth, n = 1 / Math.max(1, Math.max(e, t));
this.scaleVal = n;
const { dx: o, dy: s } = Le(this, !0);
this.map.style.transform = `translate3d(${o}px, ${s}px, 0) scale(${n})`, this.bus.fire("scale", n);
}, hn = function(e, t, n = !1) {
const { map: o, scaleVal: s, bus: i, container: l, nodes: c } = this;
if (n && o.style.transition === "transform 0.3s")
return;
const r = o.style.transform;
let { x: a, y: d } = Ce(r);
const h = l.getBoundingClientRect(), u = c.getBoundingClientRect(), y = u.left < h.right && u.right > h.left, b = u.top < h.bottom && u.bottom > h.top;
if (y) {
const p = u.left + e, g = u.right + e;
(p >= h.right || g <= h.left) && (e = 0);
}
if (b) {
const p = u.top + t, g = u.bottom + t;
(p >= h.bottom || g <= h.top) && (t = 0);
}
a += e, d += t, n && (o.style.transition = "transform 0.3s", setTimeout(() => {
o.style.transition = "none";
}, 300)), o.style.transform = `translate3d(${a}px, ${d}px, 0) scale(${s})`, i.fire("move", { dx: e, dy: t });
}, Le = (e, t = !1) => {
const { container: n, map: o, nodes: s } = e;
let i, l;
if (e.alignment === "nodes" || t)
i = (n.offsetWidth - s.offsetWidth) / 2, l = (n.offsetHeight - s.offsetHeight) / 2, o.style.transformOrigin = "50% 50%";
else {
const c = o.querySelector("me-root"), r = c.offsetTop, a = c.offsetLeft, d = c.offsetWidth, h = c.offsetHeight;
i = n.offsetWidth / 2 - a - d / 2, l = n.offsetHeight / 2 - r - h / 2, o.style.transformOrigin = `${a + d / 2}px 50%`;
}
return { dx: i, dy: l };
}, fn = function() {
const { map: e, container: t } = this, { dx: n, dy: o } = Le(this);
t.scrollTop = 0, t.scrollLeft = 0, e.style.transform = `translate3d(${n}px, ${o}px, 0) scale(${this.scaleVal})`;
}, un = function(e) {
e(this);
}, pn = function(e) {
e.nodeObj.parent && (this.clearSelection(), this.tempDirection === null && (this.tempDirection = this.direction), this.isFocusMode || (this.nodeDataBackup = this.nodeData, this.isFocusMode = !0), this.nodeData = e.nodeObj, this.initRight(), this.toCenter());
}, gn = function() {
this.isFocusMode = !1, this.tempDirection !== null && (this.nodeData = this.nodeDataBackup, this.direction = this.tempDirection, this.tempDirection = null, this.refresh(), this.toCenter());
}, mn = function() {
this.direction = 0, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, yn = function() {
this.direction = 1, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, bn = function() {
this.direction = 2, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, vn = function(e, t) {
const n = e.nodeObj;
typeof t == "boolean" ? n.expanded = t : n.expanded !== !1 ? n.expanded = !1 : n.expanded = !0;
const o = e.getBoundingClientRect(), s = {
x: o.left,
y: o.top
}, i = e.parentNode, l = i.children[1];
if (l.expanded = n.expanded, l.className = n.expanded ? "minus" : "", ne(e), n.expanded) {
const h = this.createChildren(
n.children.map((u) => this.createWrapper(u).grp)
);
i.parentNode.appendChild(h);
} else
i.parentNode.children[1].remove();
this.linkDiv(e.closest("me-main > me-wrapper"));
const c = e.getBoundingClientRect(), r = {
x: c.left,
y: c.top
}, a = s.x - r.x, d = s.y - r.y;
this.move(a, d), this.bus.fire("expandNode", n);
}, xn = function(e, t) {
const n = e.nodeObj, o = e.getBoundingClientRect(), s = {
x: o.left,
y: o.top
};
U(n, t ?? !n.expanded), this.refresh();
const i = this.findEle(n.id).getBoundingClientRect(), l = {
x: i.left,
y: i.top
}, c = s.x - l.x, r = s.y - l.y;
this.move(c, r);
}, wn = function(e) {
this.clearSelection(), e && (e = JSON.parse(JSON.stringify(e)), this.nodeData = e.nodeData, this.arrows = e.arrows || [], this.summaries = e.summaries || [], e.theme && this.changeTheme(e.theme)), G(this.nodeData), this.layout(), this.linkDiv();
}, En = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
cancelFocus: gn,
clearSelection: on,
disableEdit: cn,
enableEdit: ln,
expandNode: vn,
expandNodeAll: xn,
focusNode: pn,
getData: rn,
getDataString: sn,
initLeft: mn,
initRight: yn,
initSide: bn,
install: un,
move: hn,
refresh: wn,
scale: an,
scaleFit: dn,
scrollIntoView: Qt,
selectNode: en,
selectNodes: tn,
stringifyData: ke,
toCenter: fn,
unselectNodes: nn
}, Symbol.toStringTag, { value: "Module" })), $e = "MIND-ELIXIR-WAIT-COPY", Cn = 40, Sn = 10, Nn = ({ deltaMode: e, deltaY: t, viewportHeight: n }) => e === WheelEvent.DOM_DELTA_LINE ? t * Cn : e === WheelEvent.DOM_DELTA_PAGE ? t * n : t, Tn = ({ deltaMode: e, deltaY: t, scaleSensitivity: n, viewportHeight: o }) => {
const i = -Nn({ deltaMode: e, deltaY: t, viewportHeight: o }) / Sn * n;
return Math.max(-n, Math.min(n, i));
}, rt = (e, t, n) => {
t !== 0 && e.scale(e.scaleVal + t, n);
}, _n = (e, t) => {
const n = e.map.querySelectorAll(`.${t}>me-wrapper>me-parent>me-tpc`);
n.length !== 0 && e.selectNode(n[Math.ceil(n.length / 2) - 1]);
}, kn = (e) => {
e.selectNode(e.map.querySelector("me-root>me-tpc"));
}, Ln = function(e, t) {
const n = t.parentElement.parentElement.parentElement.previousSibling;
if (n) {
const o = n.firstChild;
e.selectNode(o);
}
}, Dn = function(e, t) {
const n = t.parentElement.nextSibling;
if (n && n.firstChild) {
const o = n.firstChild.firstChild.firstChild;
e.selectNode(o);
}
}, He = function(e, t) {
const n = e.currentNode || e.currentNodes?.[0];
if (!n) return;
const o = n.nodeObj, s = n.offsetParent.offsetParent.parentElement;
o.parent ? s.className === t ? Dn(e, n) : o.parent?.parent ? Ln(e, n) : kn(e) : _n(e, t);
}, je = function(e, t) {
const n = e.currentNode;
if (!n || !n.nodeObj.parent) return;
const s = t + "Sibling", i = n.parentElement.parentElement[s];
i ? e.selectNode(i.firstChild.firstChild) : e.selectNode(n);
}, Ie = function(e, t, n) {
const o = t === "in" ? e.scaleSensitivity : -e.scaleSensitivity;
rt(e, o, n);
}, An = (e, t) => {
const n = Tn({
deltaMode: t.deltaMode,
deltaY: t.deltaY,
scaleSensitivity: e.scaleSensitivity,
viewportHeight: e.container.clientHeight || window.innerHeight
});
rt(e, n, { x: t.clientX, y: t.clientY });
};
function Mn(e, t) {
t = t === !0 ? {} : t;
const n = () => {
e.currentArrow ? e.removeArrow() : e.currentSummary ? e.removeSummary(e.currentSummary.summaryObj.id) : e.currentNodes && e.removeNodes(e.currentNodes);
};
let o = !1, s = null;
const i = (r) => {
const a = e.nodeData;
if (r.key === "0")
for (const d of a.children)
U(d, !1);
if (r.key === "=")
for (const d of a.children)
U(d, !0);
if (["1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(r.key))
for (const d of a.children)
U(d, !0, Number(r.key) - 1);
e.refresh(), e.toCenter(), o = !1, s && (clearTimeout(s), s = null, e.container.removeEventListener("keydown", i));
}, l = {
Enter: (r) => {
r.shiftKey ? e.insertSibling("before") : r.ctrlKey || r.metaKey ? e.insertParent() : e.insertSibling("after");
},
Tab: () => {
e.addChild();
},
F1: () => {
e.toCenter();
},
F2: () => {
e.currentSummary ? e.editSummary(e.currentSummary) : e.currentArrow ? e.editArrowLabel(e.currentArrow) : e.beginEdit();
},
ArrowUp: (r) => {
if (r.altKey)
e.moveUpNode();
else {
if (r.metaKey || r.ctrlKey)
return e.initSide();
je(e, "previous");
}
},
ArrowDown: (r) => {
r.altKey ? e.moveDownNode() : je(e, "next");
},
ArrowLeft: (r) => {
if (r.metaKey || r.ctrlKey)
return e.initLeft();
He(e, B.LHS);
},
ArrowRight: (r) => {
if (r.metaKey || r.ctrlKey)
return e.initRight();
He(e, B.RHS);
},
PageUp: () => e.moveUpNode(),
PageDown: () => {
e.moveDownNode();
},
"=": (r) => {
(r.metaKey || r.ctrlKey) && Ie(e, "in");
},
"-": (r) => {
(r.metaKey || r.ctrlKey) && Ie(e, "out");
},
0: (r) => {
if (r.metaKey || r.ctrlKey) {
if (o)
return;
e.scale(1);
}
},
k: (r) => {
(r.metaKey || r.ctrlKey) && (o = !0, s && (clearTimeout(s), e.container.removeEventListener("keydown", i)), s = window.setTimeout(() => {
o = !1, s = null;
}, 2e3), e.container.addEventListener("keydown", i));
},
Delete: n,
Backspace: n,
...t
};
e.container.onkeydown = (r) => {
if ((r.ctrlKey || r.metaKey) && ["c", "v", "x"].includes(r.key) || r.preventDefault(), !e.editable) return;
const d = l[r.key];
d && d(r);
};
const c = (r) => {
if (r.target instanceof HTMLElement && r.target.id === "input-box" || e.currentNodes.length === 0) return !1;
if (r.clipboardData) {
const a = Ee(e.currentNodes).map((h) => h.nodeObj), d = ke({
magic: $e,
data: a
});
return r.clipboardData.setData("text/plain", d), r.preventDefault(), !0;
}
return !1;
};
e.container.addEventListener("copy", c), e.container.addEventListener("cut", (r) => {
c(r) && n();
}), e.container.addEventListener("paste", (r) => {
const a = r.clipboardData?.getData("text/plain");
if (a)
try {
const d = JSON.parse(a);
if (d && d.magic === $e && Array.isArray(d.data)) {
const h = d.data, u = h.map((y) => ({ nodeObj: y }));
h.length > 0 && e.currentNode && (e.copyNodes(u, e.currentNode), r.preventDefault());
return;
}
} catch {
}
e.pasteHandler && e.pasteHandler(r);
});
}
function Pn(e) {
const { panHelper: t } = e;
let n = 0, o = null;
e.spacePressed = !1;
let s = null;
const i = /* @__PURE__ */ new Map(), l = bt(e);
let c = null, r = null, a = null, d = null;
const h = 500, u = 10, y = () => {
c !== null && (clearTimeout(c), c = null, r = null, a = null, d = null);
}, b = (f, x) => {
f.hasPointerCapture && f.hasPointerCapture(x) && f.releasePointerCapture(x);
}, p = (f, x) => {
if (f.id === "input-box" || f.closest("#input-box")) return !1;
const T = f.closest(".svg-label");
if (T) {
const D = T.dataset.svgId, Z = T.dataset.type, Q = document.getElementById(D);
if (Q) {
if (Z === "arrow")
return x ? e.editArrowLabel(Q) : e.selectArrow(Q), !0;
if (Z === "summary")
return x ? e.editSummary(Q) : e.selectSummary(Q), !0;
}
}
if (f.closest(".topiclinks")) {
const D = f.closest("g");
if (D)
return x ? e.editArrowLabel(D) : e.selectArrow(D), !0;
}
if (f.closest(".summary")) {
const D = f.closest("g");
if (D)
return x ? e.editSummary(D) : e.selectSummary(D), !0;
}
return !1;
}, g = (f) => {
if (f.pointerType === "mouse" && f.button !== 0) return;
if (e.helper1?.moved) {
e.helper1.clear();
return;
}
if (e.helper2?.moved) {
e.helper2.clear();
return;
}
if (t.moved) {
t.clear();
return;
}
if (l?.isDragging)
return;
const x = f.target;
if (x.tagName === "ME-EPD")
f.ctrlKey || f.metaKey ? e.expandNodeAll(x.previousSibling) : e.expandNode(x.previousSibling);
else if (!e.editable)
return;
p(x, !1);
}, m = (f) => {
if (!e.editable) return;
const x = f.target;
ee(x) && e.beginEdit(x), p(x, !0);
}, v = (f) => {
f.code === "Space" && (e.spacePressed = !0, e.container.classList.add("space-pressed"));
}, E = (f) => {
f.code === "Space" && (e.spacePressed = !1, e.container.classList.remove("space-pressed"));
}, k = (f) => {
if (f.pointerType === "touch" && (i.set(f.pointerId, { x: f.clientX, y: f.clientY }), i.size === 2)) {
const [D, Z] = Array.from(i.values());
s = Me(D, Z), y();
}
t.moved = !1;
const x = f.target, T = e.mouseSelectionButton === 0 ? 2 : 0;
if (e.editable && (f.button === 0 || f.pointerType === "touch") && ee(x)) {
e.selection?.cancel();
const D = e.currentNodes || [];
if (f.ctrlKey || f.metaKey)
if (D.includes(x)) {
e.selection?.deselect(x);
return;
} else
e.selection?.select(x);
else D.includes(x) || e.selectNode(x);
}
if (e.editable && (f.button === 0 || f.pointerType === "touch")) {
if (f.pointerType === "touch" && i.size > 1)
(l.isDragging || l.pointerId !== null) && ue(e, l);
else if (f.pointerType === "touch" && i.size === 1)
(ee(x) || x.closest("me-tpc")) && (r = { x: f.clientX, y: f.clientY }, a = x, d = f.pointerId, c = window.setTimeout(() => {
Oe(e, l, f, !0) && (a && a.setPointerCapture(f.pointerId), Ze(l.ghost, f.clientX, f.clientY)), c = null, r = null, a = null, d = null;
}, h));
else if (f.pointerType === "mouse" && Oe(e, l, f, !1)) {
x.setPointerCapture(f.pointerId);
return;
}
}
const P = e.spacePressed && f.button === 0 && f.pointerType === "mouse", Y = !e.editable || f.button === T && f.pointerType === "mouse" || f.pointerType === "touch";
!P && !Y || (t.x = f.clientX, t.y = f.clientY, x.className !== "circle" && x.contentEditable !== "plaintext-only" && (t.mousedown = !0, x.setPointerCapture(f.pointerId)));
}, _ = (f) => {
if (f.pointerType === "touch" && i.has(f.pointerId)) {
if (i.set(f.pointerId, { x: f.clientX, y: f.clientY }), c !== null && r !== null && f.pointerId === d) {
const x = f.clientX - r.x, T = f.clientY - r.y;
Math.sqrt(x * x + T * T) > u && y();
}
if (i.size >= 2) {
const [x, T] = Array.from(i.values()), P = Me(x, T);
if (s == null)
s = P;
else {
if (s > 0) {
const Y = P / s;
e.scale(e.scaleVal * Y, {
x: (x.x + T.x) / 2,
y: (x.y + T.y) / 2
});
}
s = P;
}
return;
}
}
if (!(l && l.pointerId !== null && (xt(e, l, f), l.isDragging))) {
if (f.target.contentEditable !== "plaintext-only" || e.spacePressed && t.mousedown) {
const x = f.clientX - t.x, T = f.clientY - t.y;
t.onMove(x, T);
}
t.x = f.clientX, t.y = f.clientY;
}
}, C = (f) => {
if (f.pointerType === "touch" && (i.delete(f.pointerId), i.size < 2 && (s = null), y()), l && l.pointerId !== null) {
const T = l.isDragging;
if (wt(e, l, f), b(f.target, f.pointerId), T)
return;
}
if (f.pointerType === "touch" && i.size === 0 && !t.moved) {
const T = (/* @__PURE__ */ new Date()).getTime(), P = T - n;
P < 300 && P > 0 && o === f.target && m(f), n = T, o = f.target;
}
t.mousedown && (b(f.target, f.pointerId), t.clear());
}, w = () => {
y(), t.mousedown && t.clear(), l && (l.isDragging || l.pointerId !== null) && ue(e, l);
}, N = (f) => {
f.pointerType === "touch" && (i.delete(f.pointerId), i.size < 2 && (s = null), y()), l && l.pointerId === f.pointerId && ue(e, l), C(f);
}, S = (f) => {
if (f.preventDefault(), f.button !== 2 || !e.editable) return;
const x = f.target;
ee(x) && !x.classList.contains("selected") && e.selectNode(x), setTimeout(() => {
e.panHelper.moved || e.bus.fire("showContextMenu", f);
}, 200);
}, M = (f) => {
if (f.stopPropagation(), f.preventDefault(), f.ctrlKey || f.metaKey) return An(e, f);
if (f.shiftKey) return e.move(-f.deltaY, 0);
e.move(-f.deltaX, -f.deltaY);
}, { container: L } = e;
return Je([
{ dom: L, evt: "pointerdown", func: k },
{ dom: L, evt: "pointermove", func: _ },
{ dom: L, evt: "pointerup", func: C },
{ dom: L, evt: "pointercancel", func: N },
{ dom: L, evt: "click", func: g },
{ dom: L, evt: "dblclick", func: m },
{ dom: L, evt: "contextmenu", func: S },
{ dom: L, evt: "wheel", func: typeof e.handleWheel == "function" ? e.handleWheel : M },
{ dom: L, evt: "blur", func: w },
{ dom: L, evt: "keydown", func: v },
{ dom: L, evt: "keyup", func: E }
]);
}
function On() {
return {
handlers: {},
addListener: function(e, t) {
this.handlers[e] === void 0 && (this.handlers[e] = []), this.handlers[e].push(t);
},
fire: function(e, ...t) {
if (this.handlers[e] instanceof Array) {
const n = this.handlers[e];
for (let o = 0; o < n.length; o++)
n[o](...t);
}
},
removeListener: function(e, t) {
if (!this.handlers[e]) return;
const n = this.handlers[e];
if (!t)
n.length = 0;
else if (n.length)
for (let o = 0; o < n.length; o++)
n[o] === t && this.handlers[e].splice(o, 1);
}
};
}
const H = "http://www.w3.org/2000/svg", he = function(e) {
const t = e.clientWidth, n = e.clientHeight, o = e.dataset, s = Number(o.x), i = Number(o.y), l = o.anchor;
let c = s;
l === "middle" ? c = s - t / 2 : l === "end" && (c = s - t), e.style.left = `${c}px`, e.style.top = `${i - n / 2}px`, e.style.visibility = "visible";
}, me = function(e, t, n, o) {
const { anchor: s = "middle", color: i, dataType: l, svgId: c } = o, r = document.createElement("div");
r.className = "svg-label", r.style.color = i || "#666";
const a = "label-" + c;
return r.id = a, r.innerHTML = e, r.dataset.type = l, r.dataset.svgId = c, r.dataset.x = t.toString(), r.dataset.y = n.toString(), r.dataset.anchor = s, r;
}, lt = function(e, t, n) {
const o = document.createElementNS(H, "path");
return A(o, {
d: e,
stroke: t || "#666",
fill: "none",
"stroke-width": n
}), o;
}, te = function(e) {
const t = document.createElementNS(H, "svg");
return t.setAttribute("class", e), t.setAttribute("overflow", "visible"), t;
}, Re = function() {
const e = document.createElementNS(H, "line");
return e.setAttribute("stroke", "#4dc4ff"), e.setAttribute("fill", "none"), e.setAttribute("stroke-width", "2"), e.setAttribute("opacity", "0.45"), e;
}, $n = function(e, t, n, o) {
const s = document.createElementNS(H, "g");
return [
{
name: "line",
d: e
},
{
name: "arrow1",
d: t
},
{
name: "arrow2",
d: n
}
].forEach((l, c) => {
const r = l.d, a = document.createElementNS(H, "path"), d = {
d: r,
stroke: o?.stroke || "rgb(227, 125, 116)",
fill: "none",
"stroke-linecap": o?.strokeLinecap || "cap",
"stroke-width": String(o?.strokeWidth || "2")
};
o?.opacity !== void 0 && (d.opacity = String(o.opacity)), A(a, d), c === 0 && a.setAttribute("stroke-dasharray", o?.strokeDasharray || "8,2");
const h = document.createElementNS(H, "path");
A(h, {
d: r,
stroke: "transparent",
fill: "none",
"stroke-width": "15"
}), s.appendChild(h), s.appendChild(a), s[l.name] = a;
}), s;
}, ct = function(e, t, n) {
if (!t) return;
const o = n.label, s = t.cloneNode(!0);
e.nodes.appendChild(s), s.id = "input-box", s.textContent = o, s.contentEditable = "plaintext-only", s.spellcheck = !1, s.style.cssText = `
left:${t.style.left};
top:${t.style.top};
max-width: 200px;
`, tt(s), e.scrollIntoView(s), s.addEventListener("keydown", (i) => {
i.stopPropagation();
const l = i.key;
if (l === "Enter" || l === "Tab") {
if (i.shiftKey) return;
i.preventDefault(), s.blur(), e.container.focus();
}
}), s.addEventListener("blur", () => {
if (!s) return;
const i = s.innerText?.trim() || "";
i === "" ? n.label = o : n.label = i, s.remove(), i !== o && (e.markdown ? t.innerHTML = e.markdown(n.label, n) : t.textContent = n.label, he(t), "parent" in n ? e.bus.fire("operation", {
name: "finishEditSummary",
obj: n
}) : e.bus.fire("operation", {
name: "finishEditArrowLabel",
obj: n
}));
});
}, Hn = function(e) {
const t = this.map.querySelector("me-root"), n = t.offsetTop, o = t.offsetLeft, s = t.offsetWidth, i = t.offsetHeight, l = this.map.querySelectorAll("me-main > me-wrapper");
this.lines.innerHTML = "";
for (let c = 0; c < l.length; c++) {
const r = l[c], a = r.querySelector("me-tpc"), { offsetLeft: d, offsetTop: h } = $(this.nodes, a), u = a.offsetWidth, y = a.offsetHeight, b = r.parentNode.className, p = this.generateMainBranch({ pT: n, pL: o, pW: s, pH: i, cT: h, cL: d, cW: u, cH: y, direction: b, containerHeight: this.nodes.offsetHeight }), g = this.theme.palette, m = a.nodeObj.branchColor || g[c % g.length];
if (a.style.borderColor = m, this.lines.appendChild(lt(p, m, "3")), e && e !== r)
continue;
const v = te("subLines"), E = r.lastChild;
E.tagName === "svg" && E.remove(), r.appendChild(v), at(this, v, m, r, b, !0);
}
this.labelContainer.innerHTML = "", this.renderArrow(), this.renderSummary(), this.bus.fire("linkDiv");
}, at = function(e, t, n, o, s, i) {
const l = o.firstChild, c = o.children[1].children;
if (c.length === 0) return;
const r = l.offsetTop, a = l.offsetLeft, d = l.offsetWidth, h = l.offsetHeight;
for (let u = 0; u < c.length; u++) {
const y = c[u], b = y.firstChild, p = b.offsetTop, g = b.offsetLeft, m = b.offsetWidth, v = b.offsetHeight, E = b.firstChild.nodeObj.branchColor || n, k = e.generateSubBranch({ pT: r, pL: a, pW: d, pH: h, cT: p, cL: g, cW: m, cH: v, direction: s, isFirst: i });
t.appendChild(lt(k, E, "2"));
const _ = b.children[1];
if (_) {
if (!_.expanded) continue;
} else
continue;
at(e, t, E, y, s);
}
}, jn = {
addChild: "Add child",
addParent: "Add parent",
addSibling: "Add sibling",
removeNode: "Remove node",
focus: "Focus Mode",
cancelFocus: "Cancel Focus Mode",
moveUp: "Move up",
moveDown: "Move down",
link: "Link",
linkBidirectional: "Bidirectional Link",
clickTips: "Please click the target node",
summary: "Summary"
};
function In(e, t) {
const n = {
focus: !0,
link: !0,
locale: jn
};
t = t === !0 ? n : Object.assign(n, t);
const o = (C) => {
const w = document.createElement("div");
return w.innerText = C, w.className = "tips", w;
}, s = (C, w, N) => {
const S = document.createElement("li");
return S.id = C, S.innerHTML = `<span>${ge(w)}</span><span ${N ? 'class="key"' : ""}>${ge(N)}</span>`, S;
}, i = t.locale, l = s("cm-add_child", i.addChild, "Tab"), c = s("cm-add_parent", i.addParent, "Ctrl + Enter"), r = s("cm-add_sibling", i.addSibling, "Enter"), a = s("cm-remove_child", i.removeNode, "Delete"), d = s("cm-fucus", i.focus, ""), h = s("cm-unfucus", i.cancelFocus, ""), u = s("cm-up", i.moveUp, "PgUp"), y = s("cm-down", i.moveDown, "Pgdn"), b = s("cm-link", i.link, ""), p = s("cm-link-bidirectional", i.linkBidirectional, ""), g = s("cm-summary", i.summary, ""), m = document.createElement("ul");
if (m.className = "menu-list", m.appendChild(l), m.appendChild(c), m.appendChild(r), m.appendChild(a), t.focus && (m.appendChild(d), m.appendChild(h)), m.appendChild(u), m.appendChild(y), m.appendChild(g), t.link && (m.appendChild(b), m.appendChild(p)), t && t.extend)
for (let C = 0; C < t.extend.length; C++) {
const w = t.extend[C], N = s(w.name, w.name, w.key || "");
m.appendChild(N), N.onclick = (S) => {
w.onclick(S);
};
}
const v = document.createElement("div");
v.className = "context-menu", v.appendChild(m), v.hidden = !0, e.container.append(v);
let E = !0;
const k = (C) => {
const w = C.target;
if (ee(w)) {
w.parentElement.tagName === "ME-ROOT" ? E = !0 : E = !1, E ? (d.className = "disabled", u.className = "disabled", y.className = "disabled", c.className = "disabled", r.className = "disabled", a.className = "disabled") : (d.className = "", u.className = "", y.className = "", c.className = "", r.className = "", a.className = ""), v.hidden = !1, m.style.top = "", m.style.bottom = "", m.style.left = "", m.style.right = "";
const N = m.offsetHeight, S = m.offsetWidth, M = m.getBoundingClientRect(), L = C.clientY - M.top, I = C.clientX - M.left;
N + L > window.innerHeight ? (m.style.top = "", m.style.bottom = "0px") : (m.style.bottom = "", m.style.top = L + 15 + "px"), S + I > window.innerWidth ? (m.style.left = "", m.style.right = "0px") : (m.style.right = "", m.style.left = I + 10 + "px");
}
};
e.bus.addListener("showContextMenu", k), v.onclick = (C) => {
C.target === v && (v.hidden = !0);
}, l.onclick = () => {
e.addChild(), v.hidden = !0;
}, c.onclick = () => {
e.insertParent(), v.hidden = !0;
}, r.onclick = () => {
E || (e.insertSibling("after"), v.hidden = !0);
}, a.onclick = () => {
E || (e.removeNodes(e.currentNodes || []), v.hidden = !0);
}, d.onclick = () => {
E || (e.focusNode(e.currentNode), v.hidden = !0);
}, h.onclick = () => {
e.cancelFocus(), v.hidden = !0;
}, u.onclick = () => {
E || (e.moveUpNode(), v.hidden = !0);
}, y.onclick = () => {
E || (e.moveDownNode(), v.hidden = !0);
};
const _ = (C) => {
v.hidden = !0;
const w = e.currentNode, N = o(i.clickTips);
e.container.appendChild(N)