mind-elixir
Version:
Mind elixir is a free open source mind map core.
1,936 lines • 79.2 kB
JavaScript
//#region \0rolldown/runtime.js
var e = Object.defineProperty, t = (t, n) => {
let r = {};
for (var i in t) e(r, i, {
get: t[i],
enumerable: !0
});
return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
}, n = 0, r = 1, i = 2, a = 3, o = {
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-border": "",
"--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"
}
}, s = {
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-border": "",
"--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"
}
};
//#endregion
//#region src/utils/index.ts
function c(e) {
return e.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
}
var l = function(e, t) {
if (t.id === e) return t;
if (t.children && t.children.length) {
for (let n = 0; n < t.children.length; n++) {
let r = l(e, t.children[n]);
if (r) return r;
}
return null;
}
return null;
}, u = (e, t) => {
if (e.parent = t, e.children) for (let t = 0; t < e.children.length; t++) u(e.children[t], e);
}, d = (e, t, n) => {
if (e.expanded = t, e.children) if (n === void 0 || n > 0) {
let r = n === void 0 ? void 0 : n - 1;
e.children.forEach((e) => {
d(e, t, r);
});
} else e.children.forEach((e) => {
d(e, !1);
});
};
function f(e) {
if (e.id = m(), e.children) for (let t = 0; t < e.children.length; t++) f(e.children[t]);
}
function p(e, t, n, r) {
let i = n - e, a = r - t, o = Math.atan2(a, i) * 180 / Math.PI, s = (o + 180 - 30) * Math.PI / 180, c = (o + 180 + 30) * Math.PI / 180;
return {
x1: n + Math.cos(s) * 12,
y1: r + Math.sin(s) * 12,
x2: n + Math.cos(c) * 12,
y2: r + Math.sin(c) * 12
};
}
function m() {
return Date.now().toString(36) + Math.random().toString(36).substring(2, 8);
}
var h = function() {
let e = m();
return {
topic: this.newTopicName,
id: e
};
};
function g(e) {
return JSON.parse(JSON.stringify(e, (e, t) => {
if (e !== "parent") return t;
}));
}
var _ = (e, t) => {
let n = 0, r = 0;
for (; t && t !== e;) n += t.offsetLeft, r += t.offsetTop, t = t.offsetParent;
return {
offsetLeft: n,
offsetTop: r
};
}, v = (e, t) => {
for (let n in t) e.setAttribute(n, t[n]);
}, y = (e) => e ? e.classList.contains("me-tpc") : !1, b = (e) => {
let t = new Set(e.map((e) => e.nodeObj));
return e.filter((e) => e.nodeObj.parent).filter((e) => {
let n = e.nodeObj.parent;
for (; n;) {
if (t.has(n)) return !1;
n = n.parent;
}
return !0;
});
}, x = (e) => {
let t = e.match(/translate3d\(([^,]+),\s*([^,]+)/);
return t ? {
x: parseFloat(t[1]),
y: parseFloat(t[2])
} : {
x: 0,
y: 0
};
}, S = function(e) {
for (let t = 0; t < e.length; t++) {
let { dom: n, evt: r, func: i } = e[t];
n.addEventListener(r, i);
}
return function() {
for (let t = 0; t < e.length; t++) {
let { dom: n, evt: r, func: i } = e[t];
n.removeEventListener(r, i);
}
};
}, C = (e, t) => {
let n = e.x - t.x, r = e.y - t.y;
return Math.sqrt(n * n + r * r);
}, w = function(e, t) {
if (!t) return T(e), e;
let n = e.querySelector(".insert-preview"), r = `insert-preview ${t} show`;
return n || (n = document.createElement("div"), e.appendChild(n)), n.className = r, e;
}, T = function(e) {
if (!e) return;
let t = e.querySelectorAll(".insert-preview");
for (let e of t || []) e.remove();
}, E = function(e, t) {
for (let n of t) {
let t = n.parentElement.parentElement.contains(e);
if (!(e && e.classList.contains("me-tpc") && e !== n && !t && e.nodeObj.parent)) return !1;
}
return !0;
}, D = function(e) {
let t = document.createElement("div");
return t.className = "mind-elixir-ghost", e.container.appendChild(t), t;
}, O = class {
mind;
isMoving = !1;
interval = null;
speed = 20;
constructor(e) {
this.mind = e;
}
move(e, t) {
this.isMoving || (this.isMoving = !0, this.interval = setInterval(() => {
this.mind.move(e * this.speed * this.mind.scaleVal, t * this.speed * this.mind.scaleVal);
}, 100));
}
stop() {
this.isMoving = !1, this.interval &&= (clearInterval(this.interval), null);
}
};
function ee(e) {
return {
isDragging: !1,
insertType: null,
meet: null,
ghost: D(e),
edgeMoveController: new O(e),
startX: 0,
startY: 0,
pointerId: null
};
}
var k = 5;
function te(e, t, n, r = !1) {
if (e.spacePressed) return !1;
let i = n.target;
if (!i?.classList.contains("me-tpc") || !i.nodeObj.parent) return !1;
if (t.startX = n.clientX, t.startY = n.clientY, t.pointerId = n.pointerId, e.dragged = e.currentNodes, r) {
re(e, t);
let r = e.container.getBoundingClientRect();
ne(t.ghost, n.clientX - r.x, n.clientY - r.y);
}
return !0;
}
function ne(e, t, n) {
e.style.transform = `translate(${t - 10}px, ${n - 10}px)`, e.style.display = "block";
}
function re(e, t) {
let { dragged: n } = e;
if (!n) return;
let r = document.activeElement;
r && r.isContentEditable && r.blur(), t.isDragging = !0, n.length > 1 ? t.ghost.innerHTML = n.length + "" : t.ghost.innerHTML = n[0].innerHTML;
for (let e of n) e.parentElement.parentElement.style.opacity = "0.5";
e.panHelper.clear();
}
function ie(e, t, n) {
let { dragged: r } = e;
if (!r || t.pointerId !== n.pointerId) return;
let i = n.clientX - t.startX, a = n.clientY - t.startY, o = Math.sqrt(i * i + a * a);
if (!t.isDragging && o > k && re(e, t), !t.isDragging) return;
let s = e.container.getBoundingClientRect();
ne(t.ghost, n.clientX - s.x, n.clientY - s.y), n.clientX < s.x + 50 ? t.edgeMoveController.move(1, 0) : n.clientX > s.x + s.width - 50 ? t.edgeMoveController.move(-1, 0) : n.clientY < s.y + 50 ? t.edgeMoveController.move(0, 1) : n.clientY > s.y + s.height - 50 ? t.edgeMoveController.move(0, -1) : t.edgeMoveController.stop(), T(t.meet);
let c = 12 * e.scaleVal;
if (e.direction === 3) {
let e = document.elementFromPoint(n.clientX - c, n.clientY);
if (E(e, r)) {
t.meet = e;
let r = e.getBoundingClientRect();
t.insertType = n.clientX > r.x + r.width ? "after" : "in";
} else {
let e = document.elementFromPoint(n.clientX + c, n.clientY);
if (E(e, r)) {
t.meet = e;
let r = e.getBoundingClientRect();
t.insertType = n.clientX < r.x ? "before" : "in";
} else t.insertType = null, t.meet = null;
}
t.meet && w(t.meet, t.insertType);
return;
}
let l = document.elementFromPoint(n.clientX, n.clientY - c);
if (E(l, r)) {
t.meet = l;
let e = l.getBoundingClientRect(), r = e.y;
t.insertType = n.clientY > r + e.height ? "after" : "in";
} else {
let e = document.elementFromPoint(n.clientX, n.clientY + c);
if (E(e, r)) {
t.meet = e;
let r = e.getBoundingClientRect().y;
t.insertType = n.clientY < r ? "before" : "in";
} else t.insertType = null, t.meet = null;
}
t.meet && w(t.meet, t.insertType);
}
function ae(e, t, n) {
let { dragged: r } = e;
if (!(!r || t.pointerId !== n.pointerId)) {
t.edgeMoveController.stop();
for (let e of r) e.parentElement.parentElement.style.opacity = "1";
t.ghost.style.display = "none", t.ghost.innerHTML = "", t.isDragging && t.meet && (T(t.meet), t.insertType === "before" ? e.moveNodesBefore(r, t.meet) : t.insertType === "after" ? e.moveNodesAfter(r, t.meet) : t.insertType === "in" && e.moveNodesIn(r, t.meet)), e.dragged = null, t.isDragging = !1, t.insertType = null, t.meet = null, t.pointerId = null;
}
}
function oe(e, t) {
let { dragged: n } = e;
if (n) {
t.edgeMoveController.stop();
for (let e of n) e.parentElement.parentElement.style.opacity = "1";
t.meet && T(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;
}
}
//#endregion
//#region src/types/index.ts
var A = {
LHS: "lhs",
RHS: "rhs",
DOWN: "down"
}, se = function() {
this.nodes.innerHTML = "", this.nodes.classList.toggle("down", this.direction === 3);
let e = this.createTopic(this.nodeData);
j.call(this, e, this.nodeData), e.draggable = !1;
let t = document.createElement("div");
t.className = "me-root", t.appendChild(e);
let n = this.nodeData.children || [];
if (this.direction === 2) {
let e = 0, t = 0;
n.map((n) => {
n.direction === 0 ? e += 1 : n.direction === 1 ? t += 1 : e <= t ? (n.direction = 0, e += 1) : (n.direction = 1, t += 1);
});
}
ce(this, n, t);
}, ce = function(e, t, n) {
if (e.direction === 3) {
let r = M(A.DOWN);
for (let n = 0; n < t.length; n++) {
let { grp: i } = e.createWrapper(t[n]);
r.appendChild(i);
}
e.nodes.appendChild(n), e.nodes.appendChild(r), e.nodes.appendChild(e.lines), e.nodes.appendChild(e.labelContainer);
return;
}
let r = M(A.LHS), i = M(A.RHS);
for (let n = 0; n < t.length; n++) {
let a = t[n], { grp: o } = e.createWrapper(a);
e.direction === 2 ? a.direction === 0 ? r.appendChild(o) : i.appendChild(o) : e.direction === 0 ? r.appendChild(o) : i.appendChild(o);
}
e.nodes.appendChild(r), e.nodes.appendChild(n), e.nodes.appendChild(i), e.nodes.appendChild(e.lines), e.nodes.appendChild(e.labelContainer);
}, le = function(e, t) {
let n = document.createElement("div");
n.className = "me-children";
for (let r = 0; r < t.length; r++) {
let i = t[r], { grp: a } = e.createWrapper(i);
n.appendChild(a);
}
return n;
}, ue = function(e, t) {
let n = (this?.el ? this.el : t || document).querySelector(`[data-nodeid="me${e}"]`);
if (!n) throw Error(`FindEle: Node ${e} not found, maybe it's collapsed.`);
return n;
}, j = function(e, t) {
if (e.innerHTML = "", t.style) {
let n = t.style;
for (let t in n) e.style[t] = n[t];
}
if (t.dangerouslySetInnerHTML) {
e.innerHTML = t.dangerouslySetInnerHTML;
return;
}
if (t.image) {
let n = t.image;
if (n.url && n.width && n.height) {
let t = document.createElement("img");
t.src = this.imageProxy ? this.imageProxy(n.url) : n.url, t.style.width = n.width + "px", t.style.height = n.height + "px", n.fit && (t.style.objectFit = n.fit), e.appendChild(t), e.image = t;
} else console.warn("Image url/width/height are required");
} else e.image &&= void 0;
{
let 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) {
let 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 &&= void 0;
if (t.icons && t.icons.length) {
let n = document.createElement("span");
n.className = "icons", n.innerHTML = t.icons.map((e) => `<span>${c(e)}</span>`).join(""), e.appendChild(n), e.icons = n;
} else e.icons &&= void 0;
if (t.tags && t.tags.length) {
let n = document.createElement("div");
n.className = "tags", t.tags.forEach((e) => {
let t = document.createElement("span");
typeof e == "string" ? t.textContent = e : (t.textContent = e.text, e.className && (t.className = e.className), e.style && Object.assign(t.style, e.style)), n.appendChild(t);
}), e.appendChild(n), e.tags = n;
} else e.tags &&= void 0;
}, de = function(e, t) {
let n = document.createElement("div");
n.className = "me-wrapper";
let { p: r, tpc: i } = this.createParent(e);
if (n.appendChild(r), !t && e.children && e.children.length > 0) {
let t = P(e.expanded);
if (r.appendChild(t), e.expanded !== !1) {
let t = le(this, e.children);
n.appendChild(t);
}
}
return {
grp: n,
top: r,
tpc: i
};
}, fe = function(e) {
let t = document.createElement("div");
t.className = "me-parent";
let n = this.createTopic(e);
return j.call(this, n, e), t.appendChild(n), {
p: t,
tpc: n
};
}, pe = function(e) {
let t = document.createElement("div");
return t.className = "me-children", t.append(...e), t;
}, me = function(e) {
let t = document.createElement("div");
return t.className = "me-tpc", t.nodeObj = e, t.dataset.nodeid = "me" + e.id, t;
}, M = function(e) {
let t = document.createElement("div");
return t.className = `me-main ${e}`, t;
}, N = function(e) {
let t = e.classList;
return t.contains(A.DOWN) ? A.DOWN : t.contains(A.LHS) ? A.LHS : A.RHS;
};
function he(e) {
let t = document.createRange();
t.selectNodeContents(e);
let n = window.getSelection();
n && (n.removeAllRanges(), n.addRange(t));
}
var ge = function(e) {
if (!e) return;
let t = document.createElement("div"), n = e.nodeObj, r = n.topic, { offsetLeft: i, offsetTop: a } = _(this.nodes, e);
this.nodes.appendChild(t), t.id = "input-box", t.textContent = r, t.contentEditable = "plaintext-only", t.spellcheck = !1;
let o = getComputedStyle(e);
t.style.cssText = `
left: ${i}px;
top: ${a}px;
min-width:${e.offsetWidth - 8}px;
color:${o.color};
font-size:${o.fontSize};
padding:${o.padding};
margin:${o.margin};
background-color:${o.backgroundColor !== "rgba(0, 0, 0, 0)" && o.backgroundColor};
border: ${o.border};
border-radius:${o.borderRadius}; `, this.direction === 0 && (t.style.right = "0"), e.style.opacity = "0", he(t), this.bus.fire("operation", {
name: "beginEdit",
target: e.nodeObj
}), t.addEventListener("keydown", (e) => {
if (e.stopPropagation(), e.isComposing) return;
let n = e.key;
if (n === "Enter" || n === "Tab") {
if (e.shiftKey) return;
e.preventDefault(), t.blur(), this.container.focus();
} else n === "Escape" && (e.preventDefault(), t.textContent = r, t.blur(), this.container.focus());
}), t.addEventListener("blur", () => {
if (!t) return;
e.style.opacity = "1";
let i = t.innerText?.trim() || "";
t.remove(), i !== r && i !== "" && (n.topic = i, this.markdown ? e.text.innerHTML = this.markdown(n.topic, n) : e.text.textContent = i, this.linkDiv(), this.bus.fire("operation", {
name: "finishEdit",
target: n,
origin: r
}));
});
}, P = function(e) {
let t = document.createElement("div");
return t.className = "me-epd" + (e === !1 ? "" : " minus"), t.expanded = e !== !1, t;
}, F = (e) => {
let t = e.parent?.children;
return {
siblings: t,
index: t?.indexOf(e) ?? 0
};
};
function _e(e) {
let { siblings: t, index: n } = F(e);
return t === void 0 ? 0 : (t.splice(n, 1), t.length);
}
function ve(e, t, n) {
let { siblings: r, index: i } = F(n);
r !== void 0 && (t === "before" ? r.splice(i, 0, e) : r.splice(i + 1, 0, e));
}
function ye(e, t) {
let { siblings: n, index: r } = F(e);
n !== void 0 && (n[r] = t, t.children = [e]);
}
function be(e, t, n) {
if (_e(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);
let { siblings: r, index: i } = F(n);
if (r === void 0) return;
e === "before" ? r.splice(i, 0, t) : r.splice(i + 1, 0, t);
}
}
//#endregion
//#region src/utils/domManipulation.ts
var xe = function({ map: e, direction: t }, n) {
if (t === 0) return 0;
if (t === 1) return 1;
if (t === 3) return 3;
if (t === 2) return (e.querySelector(".lhs")?.childElementCount || 0) <= (e.querySelector(".rhs")?.childElementCount || 0) ? (n.direction = 0, 0) : (n.direction = 1, 1);
}, Se = function(e, t, n) {
let r = n.children[0].children[0], i = t.parentElement;
if (i.classList.contains("me-parent")) {
if (I(r), i.children[1]) i.nextSibling.appendChild(n);
else {
let t = e.createChildren([n]);
i.appendChild(P(!0)), i.insertAdjacentElement("afterend", t);
}
e.linkDiv(n.offsetParent);
} else if (i.classList.contains("me-root")) {
let t = xe(e, r.nodeObj);
t === 3 ? e.container.querySelector(".me-main.down")?.appendChild(n) : t === 0 ? e.container.querySelector(".lhs")?.appendChild(n) : e.container.querySelector(".rhs")?.appendChild(n), e.linkDiv();
}
}, Ce = function(e, t) {
let n = e.parentNode;
if (t === 0) {
let e = n.parentNode.parentNode;
e.classList.contains("me-main") || (e.previousSibling.children[1].remove(), e.remove());
}
n.parentNode.remove();
}, we = /* @__PURE__ */ t({
addChild: () => Ae,
beginEdit: () => ze,
copyNodes: () => je,
insertParent: () => ke,
insertSibling: () => Oe,
moveDownNode: () => Pe,
moveNodesAfter: () => Re,
moveNodesBefore: () => Le,
moveNodesIn: () => Ie,
moveUpNode: () => Ne,
removeNodes: () => Fe,
reshapeNode: () => Ee,
rmSubline: () => I,
setNodeTopic: () => Be
}), Te = {
before: "beforebegin",
after: "afterend"
}, I = function(e) {
let t = e.parentElement.parentElement.lastElementChild;
t?.tagName === "svg" && t?.remove();
}, Ee = function(e, t) {
let n = e.nodeObj, r = g(n);
r.style && t.style && (t.style = Object.assign(r.style, t.style));
let i = Object.assign(n, t);
j.call(this, e, i), this.linkDiv(), this.bus.fire("operation", {
name: "reshapeNode",
target: i,
origin: r
});
}, De = function(e, t, n) {
if (!t) return null;
let r = t.nodeObj;
r.expanded === !1 && (e.expandNode(t, !0), t = e.findEle(r.id));
let i = n || e.generateNewObj();
r.children ? r.children.push(i) : r.children = [i], u(e.nodeData);
let { grp: a, top: o } = e.createWrapper(i);
return Se(e, t, a), {
newTop: o,
newNodeObj: i
};
}, Oe = function(e, t, n) {
let r = t || this.currentNode;
if (!r) return;
let i = r.nodeObj;
if (!i.parent) {
this.addChild();
return;
}
if (!i.parent?.parent && this.direction === 2) {
let e = this.map.querySelector(".lhs")?.childElementCount || 0, t = this.map.querySelector(".rhs")?.childElementCount || 0;
if (!e || !t) {
this.addChild(this.findEle(i.parent.id), n);
return;
}
}
let a = n || this.generateNewObj();
i.parent?.parent || (a.direction = +!r.closest(".me-main").classList.contains(A.LHS)), ve(a, e, i), u(this.nodeData);
let o = r.parentElement, { grp: s, top: c } = this.createWrapper(a);
o.parentElement.insertAdjacentElement(Te[e], s), this.linkDiv(s.offsetParent), n || this.editTopic(c.firstChild), this.bus.fire("operation", {
name: "insertSibling",
position: e,
target: a
}), this.selectNode(c.firstChild, !0);
}, ke = function(e, t) {
let n = e || this.currentNode;
if (!n) return;
I(n);
let r = n.nodeObj;
if (!r.parent) return;
let i = t || this.generateNewObj();
r.parent?.parent || (i.direction = +!n.closest(".me-main").classList.contains(A.LHS)), ye(r, i), u(this.nodeData);
let a = n.parentElement.parentElement, { grp: o, top: s } = this.createWrapper(i, !0);
s.appendChild(P(!0)), a.insertAdjacentElement("afterend", o);
let c = this.createChildren([a]);
s.insertAdjacentElement("afterend", c), this.linkDiv(), t || this.editTopic(s.firstChild), this.bus.fire("operation", {
name: "insertParent",
target: i
}), this.selectNode(s.firstChild, !0);
}, Ae = function(e, t) {
let n = e || this.currentNode;
if (!n) return;
let r = De(this, n, t);
if (!r) return;
let { newTop: i, newNodeObj: a } = r;
this.bus.fire("operation", {
name: "addChild",
target: a
}), t || this.editTopic(i.firstChild), this.selectNode(i.firstChild, !0);
}, je = function(e, t) {
let n = [];
for (let r = 0; r < e.length; r++) {
let i = e[r], a = g(i.nodeObj);
f(a);
let o = De(this, t, a);
if (!o) return;
let { newNodeObj: s } = o;
n.push(s);
}
this.bus.fire("operation", {
name: "copyNodes",
target: n
}), this.unselectNodes(this.currentNodes), this.selectNodes(n.map((e) => this.findEle(e.id)));
}, Me = function(e, t, n) {
let r = t.parent?.children;
if (r === void 0) return;
let i = e.direction === 2 && !t.parent?.parent, a = (e) => !i || e.direction === t.direction, o, s = !1;
for (let e of r) if (a(e)) {
if (e === t) {
if (n === -1) return o ? {
to: o,
type: "before"
} : void 0;
s = !0;
continue;
}
if (s) return {
to: e,
type: "after"
};
o = e;
}
}, Ne = function(e) {
let t = e || this.currentNode;
if (!t) return;
let n = t.nodeObj;
if (!n.parent) return;
let r = Me(this, n, -1);
r && L([t], r.type, this.findEle(r.to.id), this);
}, Pe = function(e) {
let t = e || this.currentNode;
if (!t) return;
let n = t.nodeObj;
if (!n.parent) return;
let r = Me(this, n, 1);
r && L([t], r.type, this.findEle(r.to.id), this);
}, Fe = function(e) {
if (e = b(e), e.length === 0) return;
for (let t of e) {
let e = t.nodeObj;
Ce(t, _e(e));
}
let t = e[e.length - 1];
this.selectNode(this.findEle(t.nodeObj.parent.id)), this.linkDiv(), this.bus.fire("operation", {
name: "removeNodes",
target: e.map((e) => e.nodeObj)
});
}, L = (e, t, n, r) => {
e = b(e);
let i = n.nodeObj;
t === "in" && i.expanded === !1 && (r.expandNode(n, !0), n = r.findEle(i.id), i = n.nodeObj), t === "after" && (e = e.reverse());
let a = /* @__PURE__ */ new Set();
for (let o of e) {
let e = o.nodeObj;
if (be(t, e, i), u(r.nodeData), t === "in") {
let e = o.parentElement.parentElement, t = e.parentElement;
Se(r, n, e), a.add(t);
} else {
I(o);
let e = o.parentElement.parentNode;
a.add(e.parentElement), n.parentElement.parentNode.insertAdjacentElement(Te[t], e);
}
}
for (let e of a) e.childElementCount === 0 && !e.classList.contains("me-main") && (e.previousSibling.children[1].remove(), e.remove());
r.linkDiv(), r.scrollIntoView(e[e.length - 1]);
let o = t === "before" ? "moveNodesBefore" : t === "after" ? "moveNodesAfter" : "moveNodesIn";
r.bus.fire("operation", {
name: o,
target: e.map((e) => e.nodeObj),
destination: i
});
}, Ie = function(e, t) {
L(e, "in", t, this);
}, Le = function(e, t) {
L(e, "before", t, this);
}, Re = function(e, t) {
L(e, "after", t, this);
}, ze = function(e) {
let t = e || this.currentNode;
t && (t.nodeObj.dangerouslySetInnerHTML || this.editTopic(t));
}, Be = function(e, t) {
e.text.textContent = t, e.nodeObj.topic = t, this.linkDiv();
}, Ve = /* @__PURE__ */ t({
cancelFocus: () => at,
clearSelection: () => qe,
disableEdit: () => Qe,
enableEdit: () => Ze,
expandNode: () => ut,
expandNodeAll: () => dt,
focusNode: () => it,
getData: () => Xe,
getDataString: () => Ye,
initDown: () => lt,
initLeft: () => ot,
initRight: () => st,
initSide: () => ct,
install: () => rt,
move: () => tt,
refresh: () => ft,
scale: () => $e,
scaleFit: () => et,
scrollIntoView: () => Ue,
selectNode: () => We,
selectNodes: () => Ge,
stringifyData: () => Je,
toCenter: () => nt,
unselectNodes: () => Ke
});
function He(e) {
return {
nodeData: e.isFocusMode ? e.nodeDataBackup : e.nodeData,
arrows: e.arrows,
summaries: e.summaries,
direction: e.direction,
theme: e.theme,
compact: e.compact,
meta: e.meta
};
}
var Ue = function(e, t = !1) {
let n = this.container, r = e.getBoundingClientRect(), i = n.getBoundingClientRect();
if (t || r.top > i.bottom - 50 || r.bottom < i.top + 50 || r.left > i.right - 50 || r.right < i.left + 50) {
let e = r.left + r.width / 2, t = r.top + r.height / 2, n = i.left + i.width / 2, a = i.top + i.height / 2, o = e - n, s = t - a;
this.move(-o, -s, !0);
}
}, We = function(e, t, n) {
this.clearSelection(), this.scrollIntoView(e), this.selection?.select(e), t && this.bus.fire("selectNewNode", e.nodeObj);
}, Ge = function(e) {
this.selection?.select(e);
}, Ke = function(e) {
this.selection?.deselect(e);
}, qe = function() {
this.unselectNodes(this.currentNodes), this.unselectSummary(), this.unselectArrow();
}, Je = function(e) {
return JSON.stringify(e, (e, t) => {
if (e !== "parent" || typeof t == "string") return t;
});
}, Ye = function() {
return Je(He(this));
}, Xe = function() {
return JSON.parse(this.getDataString());
}, Ze = function() {
this.editable = !0;
}, Qe = function() {
this.editable = !1;
}, $e = function(e, t = {
x: 0,
y: 0
}) {
if (e < this.scaleMin && e < this.scaleVal || e > this.scaleMax && e > this.scaleVal) return;
let n = this.container.getBoundingClientRect(), r = t.x ? t.x - n.left - n.width / 2 : 0, i = t.y ? t.y - n.top - n.height / 2 : 0, { dx: a, dy: o } = R(this), s = this.map.style.transform, { x: c, y: l } = x(s), u = c - a, d = l - o, f = this.scaleVal, p = (-r + u) * (1 - e / f), m = (-i + d) * (1 - e / f);
this.map.style.transform = `translate3d(${c - p}px, ${l - m}px, 0) scale(${e})`, this.scaleVal = e, this.bus.fire("scale", e);
}, et = function() {
let 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;
let { dx: r, dy: i } = R(this, !0);
this.map.style.transform = `translate3d(${r}px, ${i}px, 0) scale(${n})`, this.bus.fire("scale", n);
}, tt = function(e, t, n = !1) {
let { map: r, scaleVal: i, bus: a, container: o, nodes: s } = this;
if (n && r.style.transition === "transform 0.3s") return !1;
let c = r.style.transform, { x: l, y: u } = x(c), d = o.getBoundingClientRect(), f = s.getBoundingClientRect(), p = (d.left + d.right) / 2, m = (d.top + d.bottom) / 2;
return e > 0 ? e = Math.min(e, Math.max(0, p - f.left)) : e < 0 && (e = Math.max(e, Math.min(0, p - f.right))), t > 0 ? t = Math.min(t, Math.max(0, m - f.top)) : t < 0 && (t = Math.max(t, Math.min(0, m - f.bottom))), e === 0 && t === 0 ? !1 : (l += e, u += t, n && (r.style.transition = "transform 0.3s", setTimeout(() => {
r.style.transition = "none";
}, 300)), r.style.transform = `translate3d(${l}px, ${u}px, 0) scale(${i})`, a.fire("move", {
dx: e,
dy: t
}), !0);
}, R = (e, t = !1) => {
let { container: n, map: r, nodes: i } = e, a, o;
if (e.alignment === "nodes" || t || e.direction === 3) a = (n.offsetWidth - i.offsetWidth) / 2, o = (n.offsetHeight - i.offsetHeight) / 2, r.style.transformOrigin = "50% 50%";
else {
let e = r.querySelector(".me-root"), t = e.offsetTop, i = e.offsetLeft, s = e.offsetWidth, c = e.offsetHeight;
a = n.offsetWidth / 2 - i - s / 2, o = n.offsetHeight / 2 - t - c / 2, r.style.transformOrigin = `${i + s / 2}px 50%`;
}
return {
dx: a,
dy: o
};
}, nt = function() {
let { map: e, container: t } = this, { dx: n, dy: r } = R(this);
t.scrollTop = 0, t.scrollLeft = 0, e.style.transform = `translate3d(${n}px, ${r}px, 0) scale(${this.scaleVal})`;
}, rt = function(e) {
e(this);
}, it = function(e) {
e.nodeObj.parent && (this.clearSelection(), this.tempDirection === null && (this.tempDirection = this.direction), this.isFocusMode ||= (this.nodeDataBackup = this.nodeData, !0), this.nodeData = e.nodeObj, this.initRight(), this.toCenter());
}, at = function() {
this.isFocusMode = !1, this.tempDirection !== null && (this.nodeData = this.nodeDataBackup, this.direction = this.tempDirection, this.tempDirection = null, this.refresh(), this.toCenter());
}, ot = function() {
this.direction = 0, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, st = function() {
this.direction = 1, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, ct = function() {
this.direction = 2, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, lt = function() {
this.direction = 3, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, ut = function(e, t) {
let n = e.nodeObj;
n.expanded = typeof t == "boolean" ? t : n.expanded === !1;
let r = e.getBoundingClientRect(), i = {
x: r.left,
y: r.top
}, a = e.parentNode, o = a.children[1];
if (o.expanded = n.expanded, o.className = "me-epd" + (n.expanded ? " minus" : ""), I(e), n.expanded) {
let e = this.createChildren(n.children.map((e) => this.createWrapper(e).grp));
a.parentNode.appendChild(e);
} else a.parentNode.children[1].remove();
this.linkDiv(e.closest(".me-main > .me-wrapper"));
let s = e.getBoundingClientRect(), c = {
x: s.left,
y: s.top
}, l = i.x - c.x, u = i.y - c.y;
this.move(l, u), this.bus.fire("expandNode", n);
}, dt = function(e, t) {
let n = e.nodeObj, r = e.getBoundingClientRect(), i = {
x: r.left,
y: r.top
};
d(n, t ?? !n.expanded), this.refresh();
let a = this.findEle(n.id).getBoundingClientRect(), o = {
x: a.left,
y: a.top
}, s = i.x - o.x, c = i.y - o.y;
this.move(s, c);
}, ft = function(e) {
this.clearSelection(), e && (e = JSON.parse(JSON.stringify(e)), this.nodeData = e.nodeData, this.arrows = e.arrows || [], this.summaries = e.summaries || [], e.meta && (this.meta = e.meta)), u(this.nodeData), this.layout(), this.linkDiv();
}, pt = 40, mt = 10, ht = ({ deltaMode: e, deltaY: t, viewportHeight: n }) => e === WheelEvent.DOM_DELTA_LINE ? t * pt : e === WheelEvent.DOM_DELTA_PAGE ? t * n : t, gt = ({ deltaMode: e, deltaY: t, scaleSensitivity: n, viewportHeight: r }) => {
let i = -ht({
deltaMode: e,
deltaY: t,
viewportHeight: r
}) / mt * n;
return Math.max(-n, Math.min(n, i));
}, _t = (e, t, n) => {
t !== 0 && e.scale(e.scaleVal + t, n);
}, vt = (e, t) => {
_t(e, gt({
deltaMode: t.deltaMode,
deltaY: t.deltaY,
scaleSensitivity: e.scaleSensitivity,
viewportHeight: e.container.clientHeight || window.innerHeight
}), {
x: t.clientX,
y: t.clientY
});
};
//#endregion
//#region src/mouse.ts
function yt(e) {
let { panHelper: t, container: n } = e, r = null;
e.spacePressed = !1;
let i = {
lastTap: 0,
lastTapTarget: null,
DOUBLE_CLICK_THRESHOLD: 300,
detect(e, t) {
if (e.button !== 0) {
this.clear();
return;
}
let n = (/* @__PURE__ */ new Date()).getTime(), r = n - this.lastTap, i = r < this.DOUBLE_CLICK_THRESHOLD && r > 0 && this.lastTapTarget === e.target;
this.lastTap = n, this.lastTapTarget = e.target, i && t(e);
},
clear() {
this.lastTap = 0, this.lastTapTarget = null;
}
}, a = {
Idle: 0,
Pinch: 1,
DragWait: 2,
Drag: 3,
Pan: 4,
BoxSelect: 5
};
e.ptState = a.Idle;
let o = {
lastDistance: null,
activePointers: /* @__PURE__ */ new Map(),
handlePointerDown(e) {
if (e.pointerType !== "touch") return !1;
if (this.activePointers.set(e.pointerId, {
x: e.clientX,
y: e.clientY
}), this.activePointers.size >= 2) {
let [e, t] = Array.from(this.activePointers.values());
return this.lastDistance = C(e, t), !0;
}
return !1;
},
handlePointerMove(t) {
if (t.pointerType !== "touch" || !this.activePointers.has(t.pointerId)) return !1;
if (this.activePointers.set(t.pointerId, {
x: t.clientX,
y: t.clientY
}), this.activePointers.size >= 2) {
let [t, n] = Array.from(this.activePointers.values()), r = C(t, n);
if (this.lastDistance !== null && this.lastDistance > 0) {
let i = r / this.lastDistance;
e.scale(e.scaleVal * i, {
x: (t.x + n.x) / 2,
y: (t.y + n.y) / 2
});
}
return this.lastDistance = r, !0;
}
return !1;
},
handlePointerUp(e) {
e.pointerType === "touch" && (this.activePointers.delete(e.pointerId), this.activePointers.size < 2 && (this.lastDistance = null));
},
clear() {
this.activePointers.clear(), this.lastDistance = null;
}
}, s = ee(e), c = {
timer: null,
startPos: null,
pointerId: null,
DURATION: 500,
MOVE_THRESHOLD: 10,
clear() {
this.timer !== null && (clearTimeout(this.timer), this.timer = null, this.startPos = null, this.pointerId = null);
},
start(e, t) {
this.timer = window.setTimeout(() => {
t(e), this.timer = null, this.startPos = null, this.pointerId = null;
}, this.DURATION), this.startPos = {
x: e.clientX,
y: e.clientY
}, this.pointerId = e.pointerId;
},
handleMove(e) {
if (this.timer !== null && this.startPos !== null && e.pointerId === this.pointerId) {
let t = e.clientX - this.startPos.x, n = e.clientY - this.startPos.y;
Math.sqrt(t * t + n * n) > this.MOVE_THRESHOLD && this.clear();
}
}
}, l = (t, n) => {
if (t.closest("#input-box")) return !1;
let r = t.closest(".svg-label"), i = t.closest(".topiclinks, .summary"), a = r ? {
type: r.dataset.type,
element: document.getElementById(r.dataset.svgId)
} : i ? {
type: i.classList.contains("topiclinks") ? "arrow" : "summary",
element: t.closest("g")
} : null;
if (!a?.type || !a?.element) return !1;
let { type: o, element: s } = a;
return e.clearSelection(), o === "arrow" ? n ? e.editArrowLabel(s) : e.selectArrow(s) : n ? e.editSummary(s) : e.selectSummary(s), !0;
}, u = (n) => {
if (n.pointerType === "mouse" && n.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 (s?.isDragging) return;
let r = n.target;
r.classList.contains("me-epd") && (n.ctrlKey || n.metaKey ? e.expandNodeAll(r.previousSibling) : e.expandNode(r.previousSibling));
}, d = (t) => {
if (!e.editable) return;
let n = t.target;
if (y(n)) {
e.selectNode(n), e.beginEdit(n);
return;
}
l(n, !0);
}, f = (n) => {
if (n.pointerType === "touch" && o.handlePointerDown(n)) {
e.ptState = a.Pinch, c.clear(), t.clear(), (s.isDragging || s.pointerId !== null) && oe(e, s);
return;
}
if (e.ptState === a.Pinch) return;
let i = n.target;
if (e.editable && i.className === "map-container" && n.button === 0 && n.pointerType === "mouse") {
e.ptState = a.BoxSelect;
return;
}
if (t.handlePointerDown(n), t.mousedown && (e.ptState = a.Pan), n.button === 0 || n.pointerType === "touch") if (y(i)) {
e.selection?.cancel();
let t = e.currentNodes || [];
if (n.ctrlKey || n.metaKey || e.mobileMultiSelect ? t.includes(i) ? r = i : ((e.currentArrow || e.currentSummary) && e.clearSelection(), e.selection?.select(i)) : t.includes(i) || e.selectNode(i), !e.editable) return;
n.pointerType === "touch" ? (e.ptState = a.DragWait, c.start(n, (t) => {
te(e, s, t, !0) && (e.ptState = a.Drag, i.setPointerCapture(t.pointerId));
})) : te(e, s, n, !1) && (e.ptState = a.Drag, i.setPointerCapture(n.pointerId));
} else l(i, !1);
}, p = (n) => {
switch (e.ptState) {
case a.Pinch:
o.handlePointerMove(n);
break;
case a.DragWait:
c.handleMove(n), c.timer === null && (e.ptState = a.Pan, t.handlePointerMove(n));
break;
case a.Drag:
ie(e, s, n);
break;
case a.Pan: t.handlePointerMove(n);
}
}, m = (e) => {
e.preventDefault(), window.removeEventListener("contextmenu", m, !0);
}, h = (n) => {
n.pointerType === "touch" && o.handlePointerUp(n);
let l = s.isDragging, u = t.moved;
switch (e.ptState) {
case a.DragWait:
c.clear();
break;
case a.Drag:
ae(e, s, n);
break;
case a.Pan: t.handlePointerUp(n), t.moved && n.button === 2 && n.pointerType === "mouse" && (window.addEventListener("contextmenu", m, {
capture: !0,
once: !0
}), setTimeout(() => window.removeEventListener("contextmenu", m, !0), 300));
}
i.detect(n, d), (e.ptState !== a.Pinch || o.activePointers.size < 2) && (e.ptState = a.Idle), r &&= (!l && !u && e.selection?.deselect(r), null);
}, g = () => {
o.clear(), c.clear(), t.clear(), i.clear(), (s.isDragging || s.pointerId !== null) && oe(e, s), e.ptState = a.Idle, r = null;
};
return S([
{
dom: n,
evt: "pointerdown",
func: f
},
{
dom: n,
evt: "pointermove",
func: p
},
{
dom: n,
evt: "pointerup",
func: h
},
{
dom: n,
evt: "pointercancel",
func: g
},
{
dom: n,
evt: "click",
func: u
},
{
dom: n,
evt: "contextmenu",
func: (t) => {
t.preventDefault(), t.button === 2 && e.editable && setTimeout(() => {
if (e.panHelper.moved || e.ptState !== a.Idle && e.ptState !== a.Pan) return;
let n = t.target;
y(n) && !n.classList.contains("selected") && e.selectNode(n), e.bus.fire("showContextMenu", t);
}, 200);
}
},
{
dom: n,
evt: "wheel",
func: typeof e.handleWheel == "function" ? e.handleWheel : (t) => {
if (t.ctrlKey || t.metaKey) return t.stopPropagation(), t.preventDefault(), vt(e, t);
(t.shiftKey ? e.move(-t.deltaY, 0) : e.move(-t.deltaX, -t.deltaY)) && (t.stopPropagation(), t.preventDefault());
}
},
{
dom: n,
evt: "blur",
func: g
},
{
dom: n,
evt: "keydown",
func: (t) => {
t.code === "Space" && (e.spacePressed = !0, e.container.classList.add("space-pressed"));
}
},
{
dom: n,
evt: "keyup",
func: (t) => {
t.code === "Space" && (e.spacePressed = !1, e.container.classList.remove("space-pressed"));
}
}
]);
}
//#endregion
//#region src/utils/pubsub.ts
function bt() {
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) {
let n = this.handlers[e];
for (let e = 0; e < n.length; e++) n[e](...t);
}
},
removeListener: function(e, t) {
if (!this.handlers[e]) return;
let n = this.handlers[e];
if (!t) n.length = 0;
else if (n.length) for (let r = 0; r < n.length; r++) n[r] === t && this.handlers[e].splice(r, 1);
}
};
}
//#endregion
//#region src/utils/svg.ts
var z = "http://www.w3.org/2000/svg", B = function(e) {
let t = e.clientWidth, n = e.clientHeight, r = e.dataset, i = Number(r.x), a = Number(r.y), o = r.anchor, s = i;
o === "middle" ? s = i - t / 2 : o === "end" && (s = i - t), e.style.left = `${s}px`, e.style.top = `${a - n / 2}px`, e.style.visibility = "visible";
}, V = function(e, t, n, r) {
let { anchor: i = "middle", color: a, dataType: o, svgId: s } = r, c = document.createElement("div");
return c.className = "svg-label", c.style.color = a || "#666", c.id = "label-" + s, c.innerHTML = e, c.dataset.type = o, c.dataset.svgId = s, c.dataset.x = t.toString(), c.dataset.y = n.toString(), c.dataset.anchor = i, c;
}, xt = function(e, t, n) {
let r = document.createElementNS(z, "path");
return v(r, {
d: e,
stroke: t || "#666",
fill: "none",
"stroke-width": n
}), r;
}, H = function(e) {
let t = document.createElementNS(z, "svg");
return t.setAttribute("class", e), t.setAttribute("overflow", "visible"), t;
}, St = function() {
let e = document.createElementNS(z, "line");
return e.setAttribute("stroke", "#4dc4ff"), e.setAttribute("fill", "none"), e.setAttribute("stroke-width", "2"), e.setAttribute("opacity", "0.45"), e;
}, Ct = function(e, t, n, r) {
let i = document.createElementNS(z, "g");
return [
{
name: "line",
d: e
},
{
name: "arrow1",
d: t
},
{
name: "arrow2",
d: n
}
].forEach((e, t) => {
let n = e.d, a = document.createElementNS(z, "path"), o = {
d: n,
stroke: r?.stroke || "rgb(227, 125, 116)",
fill: "none",
"stroke-width": String(r?.strokeWidth || "2")
};
r?.opacity !== void 0 && (o.opacity = String(r.opacity)), v(a, o), t === 0 && a.setAttribute("stroke-dasharray", r?.strokeDasharray || "8,2");
let s = document.createElementNS(z, "path");
v(s, {
d: n,
stroke: "transparent",
fill: "none",
"stroke-width": "15"
}), i.appendChild(s), i.appendChild(a), i[e.name] = a;
}), i;
}, wt = function(e, t, n) {
if (!t) return;
let r = n.label;
t.style.opacity = "0";
let i = t.cloneNode(!0);
e.nodes.appendChild(i), i.id = "input-box", i.textContent = r, i.contentEditable = "plaintext-only", i.spellcheck = !1, i.style.cssText = `
left:${t.style.left};
top:${t.style.top};
max-width: 200px;
`, he(i), e.scrollIntoView(i), i.addEventListener("keydown", (t) => {
if (t.stopPropagation(), t.isComposing) return;
let n = t.key;
if (n === "Enter" || n === "Tab") {
if (t.shiftKey) return;
t.preventDefault(), i.blur(), e.container.focus();
}
}), i.addEventListener("blur", () => {
if (!i) return;
let a = i.innerText?.trim() || "";
n.label = a === "" ? r : a, t.style.opacity = "1", i.remove(), a !== r && (e.markdown ? t.innerHTML = e.markdown(n.label, n) : t.textContent = n.label, B(t), "parent" in n ? e.bus.fire("operation", {
name: "finishEditSummary",
target: n
}) : e.bus.fire("operation", {
name: "finishEditArrowLabel",
target: n
}));
});
}, Tt = function(e) {
let t = this.map.querySelector(".me-root"), n = t.offsetTop, r = t.offsetLeft, i = t.offsetWidth, a = t.offsetHeight, o = this.map.querySelectorAll(".me-main > .me-wrapper");
this.lines.innerHTML = "";
for (let t = 0; t < o.length; t++) {
let s = o[t], c = s.querySelector(".me-tpc"), { offsetLeft: l, offsetTop: u } = _(this.nodes, c), d = c.offsetWidth, f = c.offsetHeight, p = N(s.parentNode), m = this.generateMainBranch({
pT: n,
pL: r,
pW: i,
pH: a,
cT: u,
cL: l,
cW: d,
cH: f,
direction: p,
containerHeight: this.nodes.offsetHeight,
containerWidth: this.nodes.offsetWidth
}), h = this.theme.palette, g = c.nodeObj.branchColor || h[t % h.length];
if (c.style.borderColor = g, this.lines.appendChild(xt(m, g, "3")), e && e !== s) continue;
let v = H("subLines"), y = s.lastChild;
y.tagName === "svg" && y.remove(), s.appendChild(v), Et(this, v, g, s, p, !0);
}
this.labelContainer.innerHTML = "", this.renderArrow(), this.renderSummary(), this.bus.fire("linkDiv");
}, Et = function(e, t, n, r, i, a) {
let o = r.firstChild, s = r.children[1].children;
if (s.length === 0) return;
let c = o.offsetTop, l = o.offsetLeft, u = o.offsetWidth, d = o.offsetHeight;
for (let r = 0; r < s.length; r++) {
let o = s[r], f = o.firstChild, p = f.offsetTop, m = f.offsetLeft, h = f.offsetWidth, g = f.offsetHeight, _ = f.firstChild.nodeObj.branchColor || n, v = e.generateSubBranch({
pT: c,
pL: l,
pW: u,
pH: d,
cT: p,
cL: m,
cW: h,
cH: g,
direction: i,
isFirst: a
});
t.appendChild(xt(v, _, "2"));
let y = f.children[1];
if (y) {
if (!y.expanded) continue;
} else continue;
Et(e, t, _, o, i);
}
}, Dt = {
side: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169394918\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2021\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M851.91168 328.45312c-59.97056 0-108.6208 48.47104-108.91264 108.36992l-137.92768 38.4a109.14304 109.14304 0 0 0-63.46752-46.58688l1.39264-137.11872c47.29344-11.86816 82.31936-54.66624 82.31936-105.64096 0-60.15488-48.76288-108.91776-108.91776-108.91776s-108.91776 48.76288-108.91776 108.91776c0 49.18784 32.60928 90.75712 77.38368 104.27392l-1.41312 138.87488a109.19936 109.19936 0 0 0-63.50336 48.55808l-138.93632-39.48544 0.01024-0.72704c0-60.15488-48.76288-108.91776-108.91776-108.91776s-108.91776 48.75776-108.91776 108.91776c0 60.15488 48.76288 108.91264 108.91776 108.91264 39.3984 0 73.91232-20.92032 93.03552-52.2496l139.19232 39.552-0.00512 0.2304c0 25.8304 9.00096 49.5616 24.02816 68.23424l-90.14272 132.63872a108.7488 108.7488 0 0 0-34.2528-5.504c-60.15488 0-108.91776 48.768-108.91776 108.91776 0 60.16 48.76288 108.91776 108.91776 108.91776 60.16 0 108.92288-48.75776 108.92288-108.91776 0-27.14624-9.9328-51.968-26.36288-71.04l89.04704-131.03104a108.544 108.544 0 0 0 37.6832 6.70208 108.672 108.672 0 0 0 36.48512-6.272l93.13792 132.57216a108.48256 108.48256 0 0 0-24.69888 69.0688c0 60.16 48.768 108.92288 108.91776 108.92288 60.16 0 108.91776-48.76288 108.91776-108.92288 0-60.14976-48.75776-108.91776-108.91776-108.91776a108.80512 108.80512 0 0 0-36.69504 6.3488l-93.07136-132.48a108.48768 108.48768 0 0 0 24.79616-72.22784l136.09984-37.888c18.99008 31.93856 53.84192 53.3504 93.69088 53.3504 60.16 0 108.92288-48.75776 108.92288-108.91264-0.00512-60.15488-48.77312-108.92288-108.92288-108.92288z\" p-id=\"2022\"></path></svg>",
left: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169375313\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"1775\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M639 463.30000001L639 285.1c0-36.90000001-26.4-68.5-61.3-68.5l-150.2 0c-1.5 0-3 0.1-4.5 0.3-10.2-38.7-45.5-67.3-87.5-67.3-50 0-90.5 40.5-90.5 90.5s40.5 90.5 90.5 90.5c42 0 77.3-28.6 87.5-67.39999999 1.4 0.3 2.9 0.4 4.5 0.39999999L577.7 263.6c6.8 0 14.3 8.9 14.3 21.49999999l0 427.00000001c0 12.7-7.40000001 21.5-14.30000001 21.5l-150.19999999 0c-1.5 0-3 0.2-4.5 0.4-10.2-38.8-45.5-67.3-87.5-67.3-50 0-90.5 40.5-90.5 90.4 0 49.9 40.5 90.6 90.5 90.59999999 42 0 77.3-28.6 87.5-67.39999999 1.4 0.2 2.9 0.4 4.49999999 0.4L577.7 780.7c34.80000001 0 61.3-31.6 61.3-68.50000001L639 510.3l79.1 0c10.4 38.5 45.49999999 67 87.4 67 50 0 90.5-40.5 90.5-90.5s-40.5-90.5-90.5-90.5c-41.79999999 0-77.00000001 28.4-87.4 67L639 463.30000001z\" fill=\"currentColor\" p-id=\"1776\"></path></svg>",
right: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169667709\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"3037\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M385 560.69999999L385 738.9c0 36.90000001 26.4 68.5 61.3 68.5l150.2 0c1.5 0 3-0.1 4.5-0.3 10.2 38.7 45.5 67.3 87.5 67.3 50 0 90.5-40.5 90.5-90.5s-40.5-90.5-90.5-90.5c-42 0-77.3 28.6-87.5 67.39999999-1.4-0.3-2.9-0.4-4.5-0.39999999L446.3 760.4c-6.8 0-14.3-8.9-14.3-21.49999999l0-427.00000001c0-12.7 7.40000001-21.5 14.30000001-21.5l150.19999999 0c1.5 0 3-0.2 4.5-0.4 10.2 38.8 45.5 67.3 87.5 67.3 50 0 90.5-40.5 90.5-90.4 0-49.9-40.5-90.6-90.5-90.59999999-42 0-77.3 28.6-87.5 67.39999999-1.4-0.2-2.9-0.4-4.49999999-0.4L446.3 243.3c-34.80000001 0-61.3 31.6-61.3 68.50000001L385 513.7l-79.1 0c-10.4-38.5-45.49999999-67-87.4-67-50 0-90.5 40.5-90.5 90.5s40.5 90.5 90.5 90.5c41.79999999 0 77.00000001-28.4 87.4-67L385 560.69999999z\" fill=\"currentColor\" p-id=\"3038\"></path></svg>",
full: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169402629\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2170\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M639.328 416c8.032 0 16.096-3.008 22.304-9.056l202.624-197.184-0.8 143.808c-0.096 17.696 14.144 32.096 31.808 32.192 0.064 0 0.128 0 0.192 0 17.6 0 31.904-14.208 32-31.808l1.248-222.208c0-0.672-0.352-1.248-0.384-1.92 0.032-0.512 0.288-0.896 0.288-1.408 0.032-17.664-14.272-32-31.968-32.032L671.552 96l-0.032 0c-17.664 0-31.968 14.304-32 31.968C639.488 145.632 653.824 160 671.488 160l151.872 0.224-206.368 200.8c-12.672 12.32-12.928 32.608-0.64 45.248C622.656 412.736 630.976 416 639.328 416z\" p-id=\"2171\"></path><path d=\"M896.032 639.552 896.032 639.552c-17.696 0-32 14.304-32.032 31.968l-0.224 151.872-200.832-206.4c-12.32-12.64-32.576-12.96-45.248-0.64-12.672 12.352-12.928 32.608-0.64 45.248l197.184 202.624-143.808-0.8c-0.064 0-0.128 0-0.192 0-17.6 0-31.904 14.208-32 31.808-0.096 17.696 14.144 32.096 31.808 32.192l222.24 1.248c0.064 0 0.128 0 0.192 0 0.64 0 1.12-0.32 1.76-0.352 0.512 0.032 0.896 0.288 1.408 0.288l0.032 0c17.664 0 31.968-14.304 32-31.968L928 671.584C928.032 653.952 913.728 639.584 896.032 639.552z\" p-id=\"2172\"></path><path d=\"M209.76 159.744l143.808 0.8c0.064 0 0.128 0 0.192 0 17.6 0 31.904-14.208 32-31.808 0.096-17.696-14.144-32.096-31.808-32.192L131.68 95.328c-0.064 0-0.128 0-0.192 0-0.672 0-1.248 0.352-1.888 0.384-0.448 0-0.8-0.256-1.248-0.256 0 0-0.032 0-0.032 0-17.664 0-31.968 14.304-32 31.968L96 352.448c-0.032 17.664 14.272 32 31.968 32.032 0 0 0.032 0 0.032 0 17.664 0 31.968-14.304 32-31.968l0.224-151.936 200.832 206.4c6.272 6.464 14.624 9.696 22.944 9.696 8.032 0 16.096-3.008 22.304-9.056 12.672-12.32 12.96-32.608 0.64-45.248L209.76 159.744z\" p-id=\"2173\"></path><path d=\"M362.368 617.056l-202.624 197.184 0.8-143.808c0.096-17.696-14.144-32.096-31.808-32.192-0.064 0-0.128 0-0.192 0-17.6 0-31.904 14.208-32 31.808l-1.248 222.24c0 0.704 0.352 1.312 0.384 2.016 0 0.448-0.256 0.832-0.256 1.312-0.032 17.664 14.272 32 31.968 32.032L352.448 928c0 0 0.032 0 0.032 0 17.664 0 31.968-14.304 32-31.968s-14.272-32-31.968-32.032l-151.936-0.224 206.4-200.832c12.672-12.352 12.96-32.608 0.64-45.248S375.008 604.704 362.368 617.056z\" p-id=\"2174\"></path></svg>",
living: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169573443\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2883\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M514.133333 488.533333m-106.666666 0a106.666667 106.666667 0 1 0 213.333333 0 106.666667 106.666667 0 1 0-213.333333 0Z\" fill=\"currentColor\" p-id=\"2884\"></path><path d=\"M512 64C264.533333 64 64 264.533333 64 512c0 236.8 183.466667 428.8 416 445.866667v-134.4c-53.333333-59.733333-200.533333-230.4-200.533333-334.933334 0-130.133333 104.533333-234.666667 234.666666-234.666666s234.666667 104.533333 234.666667 234.666666c0 61.866667-49.066667 153.6-145.066667 270.933334l-59.733333 68.266666V960C776.533333 942.933333 960 748.8 960 512c0-247.466667-200.533333-448-448-448z\" fill=\"currentColor\" p-id=\"2885\"></path></svg>",
zoomin: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169419447\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2480\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M863.328 482.56l-317.344-1.12L545.984 162.816c0-17.664-14.336-32-32-32s-32 14.336-32 32l0 318.4L159.616 480.064c-0.032 0-0.064 0-0.096 0-17.632 0-31.936 14.24-32 31.904C127.424 529.632 141.728 544 159.392 544.064l322.592 1.152 0 319.168c0 17.696 14.336 32 32 32s32-14.304 32-32l0-318.944 317.088 1.12c0.064 0 0.096 0 0.128 0 17.632 0 31.936-14.24 32-31.904C895.264 496.992 880.96 482.624 863.328 482.56z\" p-id=\"2481\"></path></svg>",
zoomout: "<?xml version=\"1.0\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg t=\"1750169426515\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2730\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\"><path d=\"M863.744 544 163.424 544c-17.664 0-32-14.336-32-32s14.336-32 32-32l700.32 0c17.696 0 32 14.336 32 32S881.44 544 863.744 544z\" p-id=\"2731\"></path></svg>"
}, U = (e, t) => {
let n = document.createElement("span");
return n.id = e, n.innerHTML = Dt[t], n;
};
function Ot(e) {
let t = document.createElement("div"), n = U("fullscreen", "full"), r = U("toCenter", "living"), i = U("zoomout", "zoomout"), a = U("zoomin", "zoomin");
t.appendChild(n), t.appendChild(r), t.appendChild(i), t.appendChild(a), t.className = "mind-elixir-toolbar rb";
let o = null, s = () => {
let t = e.container.getBoundingClientRect(), n = x(e.map.style.transform), r = t.width / 2, i = t.height / 2;
o = {
containerRect: t,
currentTransform: n,
mapCenterX: (r - n.x) / e.scaleVal,
mapCenterY: (i - n.y) / e.scaleVal
};
};
return e.el.addEventListener("fullscreenchange", () => {
if (o) {
let t = e.container.getBoundingClientRect(), n = t.width / 2, r = t.height / 2, i = n - o.mapCenterX * e.scaleVal, a = r - o.mapCenterY * e.scaleVal, s = i - o.currentTransform.x, c = a - o.currentTransform.y;
e.move(s, c);
}
}), n.onclick = () => {
s(), document.fullscreenElement === e.el ? document.exitFullscreen() : e.el.requestFullscreen();
}, r.onclick = () => {
e.toCenter();
}, i.onclick = () => {
e.scale(e.scaleVal - e.scaleSensitivity);
}, a.onclick = () => {
e.scale(e.scaleVal + e.scaleSensitivity);
}, t;
}
function kt(e) {
let t = document.createElement("div"), n = U("tbltl", "left"), r = U("tbltr", "right"), i = U("tblts", "side");
return t.appendChild(n), t.appendChild(r), t.appendChild(i), t.className = "mind-elixir-toolbar lt", n.onclick = () => {
e.initLeft();
}, r.onclick = () => {
e.initRight();
}, i.onclick = () => {
e.initSide();
}, t;
}
function At(e) {
e.container.append(Ot(e)), e.container.append(kt(e));
}
//#endregion
//#region src/viselect/src/utils/arrayify.ts
var { abs: jt, max: Mt, min: Nt, ceil: Pt } = Math, Ft = function(e, t, n, r, i = 8) {
if (e === n) return `M ${e} ${t} V ${r}`;
let a = (t + r) / 2, o = n > e ? 1 : -1, s = Math.min(i, Math.abs(n - e) / 2, Math.abs(a - t), Math.abs(r - a));
return `M ${e} ${t} V ${a - s} Q ${e} ${a} ${e + o * s} ${a} H ${n - o * s} Q ${n} ${a} ${n} ${a + s} V ${r}`;
};
function It({ pT: e, pL: t, pW: n, pH: r, cT: i, cL: a, cW: o, cH: s, direction: c, containerHeight: l, containerWidth: u }) {
if (c === A.DOWN) {
let s = t + n / 2, c = a + o / 2;
return Ft(s, e + r, c, i);
}
let d = t + n / 2, f = e + r / 2, p;
p = c === A.LHS ? a + o : a;
let m = i + s / 2, h = (1 - Math.abs(m - f) / l) * .25 * (n / 2);
return d = c === A.LHS ? d - n / 10 - h : d + n / 10 + h, `M ${d} ${f} Q ${d} ${m} ${p} ${m}`;
}
function Lt({ pT: e, pL: t, pW: n, pH: r, cT: i, cL: a, cW: o, cH: s, direction: c, isFirst: l }) {
if (c === A.DOWN) return Ft(t + n / 2, e + r, a + o / 2, i);
let u = parseInt(this.container.style.getPropertyValue("--node-gap-x")), d = 0, f = 0;
d = l ? e + r / 2 : e + r;
let p = i + s, m = 0, h = 0, g = 0, _ = Math.abs(d - p) / 300 * u;
return c === A.LHS ? (g = t, m = g + u, h = g - u, f = a + u, `M ${m} ${d} C ${g} ${d} ${g + _} ${p} ${h} ${p} H ${f}`) : (g = t + n, m = g - u, h = g + u, f = a + o - u, `M ${m} ${d} C ${g} ${d} ${g - _} ${p} ${h} ${p} H ${f}`);
}
//#endregion
//#region src/utils/theme.ts
var Rt = function(e, t = !0) {
this.theme = e, this.generateMainBranch = this.theme.generateMainBranch || It, this.generateSubBranch = this.theme.generateSubBranch || Lt;
let n = {
...(this.theme.type === "dark" ? s : o).cssVar,
...this.theme.cssVar
};
this.compact && (n["--node-gap-x"] = "15px", n["--node-gap-y"] = "2px", n["--main-gap-x"] = "30px", n["--main-gap-y"] = "6px");
let r = Object.keys(n);
for (let e = 0; e < r.length; e++) {
let t = r[e];
this.container.style.setProperty(t, n[t]);
}
t && this.refresh();
}, zt = function(e) {
this.compact = e, this.theme && this.changeTheme(this.theme);
}, Bt = { create: function(e) {
return {
dom: e,
moved: !1,
sessionMoved: !1,
pointerdown: !1,
lastX: 0,
lastY: 0,
handlePointerMove(e) {
if (this.pointerdown) {
this.moved = !0, this.sessionMoved = !0;
let t = e.clientX - this.lastX, n = e.clientY - this.lastY;
this.lastX = e.clientX, this.lastY = e.clientY, this.cb && this.cb(t, n);
}
},
handlePointerDown(e) {
e.button === 0 && (this.pointerdown = !0, this.sessionMoved = !1, this.lastX = e.clientX, this.lastY = e.clientY, this.dom.setPointerCapture(e.pointerId));
},
handleClear(e) {
let t = this.pointerdown && this.sessionMoved;
this.pointerdown = !1, this.sessionMoved = !1, e.pointerId !== void 0 && this.dom.releasePointerCapture(e.pointerId), t && this.onEnd && this.onEnd();
},
cb: null,
onEnd: null,
init(e, t, n) {
this.cb = t, this.onEnd = n || null, this.handleClear = this.handleClear.bind(this), this.handlePointerMove = this.handlePointerMove.bind(this), this.handlePointerDown = this.handlePointerDown.bind(this), this.destroy = S([
{
dom: e,
evt: "pointermove",
func: this.handlePointerMove
},
{
dom: e,
evt: "pointerleave",
func: this.handleClear
},
{
dom: e,
evt: "pointerup",
func: this.handleClear
},
{
dom: this.dom,
evt: "pointerdown",
func: this.handlePointerDown
}
]);
},
destroy: null,
clear() {
this.moved = !1, this.pointerdown = !1;
}
};
} }, Vt = /* @__PURE__ */ t({
createArrow: () => Kt,
createArrowFrom: () => qt,
editArrowLabel: () => nn,
removeArrow: () => Jt,
renderArrow: () => tn,
reshapeArrow: () => an,
selectArrow: () => Yt,
tidyArrow: () => rn,
unselectArrow: () => Xt
}), Ht = "#4dc4ff";
function Ut(e, t, n, r, i, a, o, s) {
return {
x: e / 8 + n * 3 / 8 + i * 3 / 8 + o / 8,
y: t / 8 + r * 3 / 8 + a * 3 / 8 + s / 8
};
}
function Wt(e, t, n) {
e && (e.dataset.x = t.toString(), e.dataset.y = n.toString(), B(e));
}
function W(e, t, n, r, i) {
v(e, {
x1: t + "",
y1: n + "",
x2: r + "",
y2: i + ""
});
}
function G(e, t, n, r, i, a, o, s, c, l) {
let u = `M ${t} ${n} C ${r} ${i} ${a} ${o} ${s} ${c}`;
e.line.setAttribute("d", u);
let d = l.style || {};
e.line.setAttribute("stroke", d.stroke || "rgb(227, 125, 116)"), e.line.setAttribute("stroke-width", String(d.strokeWidth || "2")), e.line.setAttribute("stroke-dasharray", d.strokeDasharray || "8,2"), d.opacity !== void 0 && d.opacity !== null && d.opacity !== "" ? e.line.setAttribute("opacity", String(d.opacity)) : e.line.removeAttribute("opacity");
let f = e.querySelectorAll("path[stroke=\"transparent\"]");
f.length > 0 && f[0].setAttribute("d", u);
let m = p(a, o, s, c);
if (m) {
let t = `M ${m.x1} ${m.y1} L ${s} ${c} L ${m.x2} ${m.y2}`;
e.arrow1.setAttribute("d", t), f.length > 1 && f[1].setAttribute("d", t), e.arrow1.setAttribute("stroke", d.stroke || "rgb(227, 125, 116)"), e.arrow1.setAttribute("stroke-width", String(d.strokeWidth || "2")), d.opacity !== void 0 && d.opacity !== null && d.opacity !== "" ? e.arrow1.setAttribute("opacity", String(d.opacity)) : e.arrow1.removeAttribute("opacity");
}
if (l.bidirectional) {
let a = p(r, i, t, n);
if (a) {
let r = `M ${a.x1} ${a.y1} L ${t} ${n} L ${a.x2} ${a.y2}`;
e.arrow2.setAttribute("d", r), f.length > 2 && f[2].setAttribute("d", r);
}
} else e.arrow2.setAttribute("d", ""), f.length > 2 && f[2].setAttribute("d", "");
e.arrow2.setAttribute("stroke", d.stroke || "rgb(227, 125, 116)"), e.arrow2.setAttribute("stroke-width", String(d.strokeWidth || "2")), d.opacity !== void 0 && d.opacity !== null && d.opacity !== "" ? e.arrow2.setAttribute("opacity", String(d.opacity)) : e.arrow2.removeAttribute("opacity");
let { x: h, y: g } = Ut(t, n, r, i, a, o, s, c);
e.labelEl && Wt(e.labelEl, h, g);
let _ = e.labelEl;
_ && (_.style.color = d.labelColor || "rgb(235, 95, 82)"), $t(e);
}
function K(e, t, n) {
let { offsetLeft: r, offsetTop: i } = _(e.nodes, t), a = t.offsetWidth, o = t.offsetHeight, s = r + a / 2, c = i + o / 2;
return {
w: a,
h: o,
cx: s,
cy: c,
ctrlX: s + n.x,
ctrlY: c + n.y
};
}
function q(e) {
let t = e.w / 2, n = e.h / 2, r = e.ctrlX - e.cx, i = e.ctrlY - e.cy, a = Math.hypot(r, i);
if (a === 0 || t === 0 && n === 0) return {
x: e.cx,
y: e.cy
};
let o = r / a, s = i / a, c = Math.min(t / Math.abs(o), n / Math.abs(s));
return {
x: e.cx + o * c,
y: e.cy + s * c
};
}
var Gt = function(e, t, n) {
let r = _(e.nodes, t), i = _(e.nodes, n), a = r.offsetLeft + t.offsetWidth / 2, o = r.offsetTop + t.offsetHeight / 2, s = i.offsetLeft + n.offsetWidth / 2, c = i.offsetTop + n.offsetHeight / 2, l = s - a, u = c - o, d = Math.sqrt(l * l + u * u), f = Math.max(50, Math.min(200, d * .3)), p = Math.abs(l), m = Math.abs(u), h, g;
if (d < 150) {
let e = t.closest(".me-main"), n = e ? e.classList.contains("lhs") ? -1 : 1 : l > 0 ? -1 : 1;
h = {
x: 200 * n,
y: 0
}, g = {
x: 200 * n,
y: 0
};
} else if (p > m * 1.5) {
let e = l > 0 ? t.offsetWidth / 2 : -t.offsetWidth / 2, r = l > 0 ? -n.offsetWidth / 2 : n.offsetWidth / 2;
h = {
x: e + (l > 0 ? f : -f),
y: 0
}, g = {
x: r + (l > 0 ? -f : f),
y: 0
};
} else if (m > p * 1.5) {
let e = u > 0 ? t.offsetHeight / 2 : -t.offsetHeight / 2, r = u > 0 ? -n.offsetHeight / 2 : n.offsetHeight / 2;
h = {
x: 0,
y: e + (u > 0 ? f : -f)
}, g = {
x: 0,
y: r + (u > 0 ? -f : f)
};
} else {
let e = Math.atan2(u, l), r = t.offsetWidth / 2 * Math.cos(e), i = t.offsetHeight / 2 * Math.sin(e), a = -(n.offsetWidth / 2) * Math.cos(e), o = -(n.offsetHeight / 2) * Math.sin(e), s = f * .7 * (l > 0 ? 1 : -1), c = f * .7 * (u > 0 ? 1 : -1);
h = {
x: r + s,
y: i + c
}, g = {
x: a - s,
y: o - c
};
}
return {
delta1: {
x: Math.round(h.x),
y: Math.round(h.y)
},
delta2: {
x: Math.round(g.x),
y: Math.round(g.y)
}
};
}, J = function(e, t, n, r, i) {
if (!t || !n) return;
if (!r.delta1 || !r.delta2) {
let i = Gt(e, t, n);
r.delta1 = i.delta1, r.delta2 = i.delta2;
}
let a = K(e, t, r.delta1), o = K(e, n, r.delta2), { x: s, y: c } = q(a), { ctrlX: l, ctrlY: u } = a, { ctrlX: d, ctrlY: f } = o, { x: m, y: h } = q(o), g = p(d, f, m, h);
if (!g) return;
let _ = `M ${g.x1} ${g.y1} L ${m} ${h} L ${g.x2} ${g.y2}`, v = "";
if (r.bidirectional) {
let e = p(l, u, s, c);
if (!e) return;
v = `M ${e.x1} ${e.y1} L ${s} ${c} L ${e.x2} ${e.y2}`;
}
let y = Ct(`M ${s} ${c} C ${l} ${u} ${d} ${f} ${m} ${h}`, _, v, r.style), { x: b, y: x } = Ut(s, c, l, u, d, f, m, h), S = r.style?.labelColor || "rgb(235, 95, 82)", C = "a-" + r.id;
y.id = C;
let w = V(e.markdown ? e.markdown(r.label, r) : r.label, b, x, {
anchor: "middle",
color: S,
dataType: "arrow",
svgId: C
});
y.labelEl = w, y.arrowObj = r, y.dataset.linkid = r.id, e.labelContainer.appendChild(w), e.arrowSvg.appendChild(y), B(w), i || (e.arrows.push(r), e.currentArrow = y, en(e, r, a, o));
}, Kt = function(e, t, n = {}) {
let r = {
id: m(),
label: "Custom Link",
from: e.nodeObj.id,
to: t.nodeObj.id,
...n
};
J(this, e, t, r), this.bus.fire("operation", {
name: "createArrow",
target: r
});
}, qt = function(e) {
X(this);
let t = {
...e,
id: m()
};
J(this, this.findEle(t.from), this.findEle(t.to), t), this.bus.fire("operation", {
name: "createArrow",
target: t
});
}, Jt = function(e) {
let t;
if (t = e || this.currentArrow, !t) return;
X(this);
let n = g(t.arrowObj);
this.arrows = this.arrows.filter((e) => e.id !== n.id), t.labelEl?.remove(), t.remove(), this.bus.fire("operation", {
name: "removeArrow",
target: n
});
}, Yt = function(e) {
this.currentArrow = e;
let t = e.arrowObj, n = this.findEle(t.from), r = this.findEle(t.to), i = K(this, n, t.delta1), a = K(this, r, t.delta2);
this.editable ? en(this, t, i, a) : Zt(e, Ht), this.bus.fire("selectArrow", t);
}, Xt = function() {
X(this), this.currentArrow = null, this.bus.fire("unselectArrow");
}, Y = function(e, t) {
let n = document.createElementNS(z, "path");
return v(n, {
d: e,
stroke: t,
fill: "none",
"stroke-width": "6",
"stroke-linecap": "round",
"stroke-linejoin": "round"
}), n;
}, Zt = function(e, t) {
let n = document.createElementNS(z, "g");
n.setAttribute("class", "arrow-highlight"), n.setAttribute("opacity", "0.45");
let r = Y(e.line.getAttribute("d"), t);
n.appendChild(r);
let i = Y(e.arrow1.getAttribute("d"), t);
if (n.appendChild(i), e.arrow2.getAttribute("d")) {
let r = Y(e.arrow2.getAttribute("d"), t);
n.appendChild(r);
}
e.insertBefore(n, e.firstChild);
}, Qt = function(e) {
let t = e.querySelector(".arrow-highlight");
t && t.remove();
}, $t = function(e) {
let t = e.querySelector(".arrow-highlight");
if (!t) return;
let n = t.querySelectorAll("path");
n.length >= 1 && n[0].setAttribute("d", e.line.getAttribute("d")), n.length >= 2 && n[1].setAttribute("d", e.arrow1.getAttribute("d")), n.length >= 3 && e.arrow2.getAttribute("d") && n[2].setAttribute("d", e.arrow2.getAttribute("d"));
}, X = function(e) {
e.helper1?.destroy(), e.helper2?.destroy(), e.linkController.style.display = "none", e.P2.style.display = "none", e.P3.style.display = "none", e.currentArrow && Qt(e.currentArrow);
}, en = function(e, t, n, r) {
let { linkController: i, P2: a, P3: o, line1: s, line2: c, nodes: l, map: u, currentArrow: d, bus: f } = e;
if (!d) return;
i.style.display = "initial", a.style.display = "initial", o.style.display = "initial", l.appendChild(i), l.appendChild(a), l.appendChild(o), Zt(d, Ht);
let { x: p, y: m } = q(n), { ctrlX: h, ctrlY: _ } = n, { ctrlX: v, ctrlY: y } = r, { x: b, y: x } = q(r);
a.style.cssText = `top:${_}px;left:${h}px;`, o.style.cssText = `top:${y}px;left:${v}px;`, W(s, p, m, h, _), W(c, v, y, b, x), e.helper1 = Bt.create(a), e.helper2 = Bt.create(o);
let S = g(t), C = () => {
f.fire("operation", {
name: "reshapeArrow",
target: t,
origin: S
}), S = g(t);
};
e.helper1.init(u, (r, i) => {
h += r / e.scaleVal, _ += i / e.scaleVal;
let o = q({
...n,
ctrlX: h,
ctrlY: _
});
p = o.x, m = o.y, a.style.top = _ + "px", a.style.left = h + "px", G(d, p, m, h, _, v, y, b, x, t), W(s, p, m, h, _), t.delta1.x = Math.round(h - n.cx), t.delta1.y = Math.round(_ - n.cy), f.fire("updateArrowDelta", t);
}, C), e.helper2.init(u, (n, i) => {
v += n / e.scaleVal, y += i / e.scaleVal;
let a = q({
...r,
ctrlX: v,
ctrlY: y
});
b = a.x, x = a.y, o.style.top = y + "px", o.style.left = v + "px", G(d, p, m, h, _, v, y, b, x, t), W(c, v, y, b, x), t.delta2.x = Math.round(v - r.cx), t.delta2.y = Math.round(y - r.cy), f.fire("updateArrowDelta", t);
}, C);
};
function tn() {
this.arrowSvg.innerHTML = "", this.labelContainer.querySelectorAll(".svg-label[data-type=\"arrow\"]").forEach((e) => e.remove());
for (let e = 0; e < this.arrows.length; e++) {
let t = this.arrows[e];
try {
J(this, this.findEle(t.from), this.findEle(t.to), t, !0);
} catch {
console.warn("Node may not be expanded");
}
}
this.nodes.appendChild(this.arrowSvg);
}
function nn(e) {
X(this), e && e.labelEl && wt(this, e.labelEl, e.arrowObj);
}
function rn() {
this.arrows = this.arrows.filter((e) => l(e.from, this.nodeData) && l(e.to, this.nodeData));
}
var an = function(e, t) {
let n = g(e);
n.style && t.style && (t.style = Object.assign({}, n.style, t.style)), Object.assign(e, t);
let r = this.arrowSvg.querySelector(`g[data-linkid="${e.id}"]`);
if (r) {
if (t.label !== void 0 && r.labelEl) {
let t = this.markdown ? this.markdown(e.label, e) : e.label;
r.labelEl.innerHTML = t;
}
let n = this.findEle(e.from), i = this.findEle(e.to);
if (n && i) {
if (!e.delta1 || !e.delta2) {
let t = Gt(this, n, i);
e.delta1 = e.delta1 || t.delta1, e.delta2 = e.delta2 || t.delta2;
}
let t = K(this, n, e.delta1), a = K(this, i, e.delta2), { x: o, y: s } = q(t), { ctrlX: c, ctrlY: l } = t, { ctrlX: u, ctrlY: d } = a, { x: f, y: p } = q(a);
G(r, o, s, c, l, u, d, f, p, e), this.currentArrow?.arrowObj?.id === e.id && (this.P2.style.cssText = `top:${l}px;left:${c}px;`, this.P3.style.cssText = `top:${d}px;left:${u}px;`, W(this.line1, o, s, c, l), W(this.line2, u, d, f, p));
}
}
this.bus.fire("operation", {
name: "reshapeArrow",
target: e,
origin: n
});
}, on = /* @__PURE__ */ t({
createSummary: () => dn,
createSummaryFrom: () => fn,
editSummary: () => _n,
removeSummary: () => pn,
renderSummary: () => gn,
selectSummary: () => mn,
unselectSummary: () => hn
}), sn = function(e) {
if (e.length === 0) throw Error("No selected node.");
if (e.length === 1) {
let t = e[0].nodeObj, n = e[0].nodeObj.parent;
if (!n) throw Error("Can not select root node.");
let r = n.children.findIndex((e) => t === e);
return {
parent: n.id,
start: r,
end: r
};
}
let t = 0, n = e.map((e) => {
let n = e.nodeObj, r = [];
for (; n.parent;) {
let e = n.parent, t = e.children?.indexOf(n);
n = e, r.unshift({
node: n,
index: t
});
}
return r.length > t && (t = r.length), r;
}), r = 0;
findMcp: for (; r < t; r++) {
let e = n[0][r]?.node;
for (let t = 1; t < n.length; t++) if (n[t][r]?.node !== e) break findMcp;
}
if (!r) throw Error("Can not select root node.");
let i = n.map((e) => e[r - 1].index).sort((e, t) => e - t), a = i[0] || 0, o = i[i.length - 1] || 0, s = n[0][r - 1].node;
if (!s.parent) throw Error("Please select nodes in the same main topic.");
return {
parent: s.id,
start: a,
end: o
};
}, cn = function(e) {
let t = document.createElementNS(z, "g");
return t.setAttribute("id", e), t;
}, Z = function(e, t) {
let n = document.createElementNS(z, "path");
return v(n, {
d: e,
stroke: t || "#666",
fill: "none",
"stroke-linecap": "round",
"stroke-width": "2"
}), n;
}, ln = (e) => e.parentElement.parentElement, Q = function(e, t) {
let n = e.summaries.findIndex((e) => e.id === t);
return n !== -1 && (e.summaries.splice(n, 1), e.nodes.querySelector("#s-" + t)?.remove(), e.nodes.querySelector("#label-s-" + t)?.remove(), !0);
}, un = function(e, { parent: t, start: n }) {
let r = e.findEle(t), i = r.nodeObj, a;
return a = i.parent ? N(r.closest(".me-main")) : N(e.findEle(i.children[n].id).closest(".me-main")), a;
}, $ = function(e, t) {
let { id: n, label: r, parent: i, start: a, end: o, style: s } = t, { nodes: c, theme: l, summarySvg: u } = e, d = e.findEle(i).nodeObj, f = un(e, t), p = Infinity, m = 0, h = 0, g = 0, v = 0, y = Infinity, b = 0;
for (let t = a; t <= o; t++) {
let n = d.children?.[t];
if (!n) return console.warn("Child not found"), null;
let r = ln(e.findEle(n.id)), { offsetLeft: i, offsetTop: s } = _(c, r), l = a === o ? 10 : 20;
t === a && (h = s + l), t === o && (g = s + r.offsetHeight - l), t === a && (y = i + l), t === o && (b = i + r.offsetWidth - l), s + r.offsetHeight > v && (v = s + r.offsetHeight), i < p && (p = i), r.offsetWidth + i > m && (m = r.offsetWidth + i);
}
let x, S, C = s?.stroke || l.cssVar["--color"], w = s?.labelColor || l.cssVar["--color"], T = "s-" + n, E = e.markdown ? e.markdown(r, t) : r;
if (f === A.DOWN) {
let e = v + 10, t = (y + b) / 2;
x = Z(`M ${y} ${e - 10} c 0 5 5 10 10 10 L ${b - 10} ${e} c 5 0 10 -5 10 -10 M ${t} ${e} v 10`, C), S = V(E, t, e + 20, {
anchor: "middle",
color: w,
dataType: "summary",
svgId: T
});
} else {
let e = d.parent ? 10 : 0, t = h + e, n = g + e, r = (t + n) / 2;
f === A.LHS ? (x = Z(`M ${p + 10} ${t} c -5 0 -10 5 -10 10 L ${p} ${n - 10} c 0 5 5 10 10 10 M ${p} ${r} h -10`, C), S = V(E, p - 20, r, {
anchor: "end",
color: w,
dataType: "summary",
svgId: T
})) : (x = Z(`M ${m - 10} ${t} c 5 0 10 5 10 10 L ${m} ${n - 10} c 0 5 -5 10 -10 10 M ${m} ${r} h 10`, C), S = V(E, m + 20, r, {
anchor: "start",
color: w,
dataType: "summary",
svgId: T
}));
}
let D = cn(T);
return D.appendChild(x), e.labelContainer.appendChild(S), B(S), D.summaryObj = t, D.labelEl = S, u.appendChild(D), D;
}, dn = function(e = {}) {
if (!this.currentNodes) return;
let { currentNodes: t, summaries: n, bus: r } = this, { parent: i, start: a, end: o } = sn(t), s = {
id: m(),
parent: i,
start: a,
end: o,
label: "summary",
style: e.style
}, c = $(this, s);
n.push(s), this.editSummary(c), r.fire("operation", {
name: "createSummary",
target: s
});
}, fn = function(e) {
let t = m(), n = {
...e,
id: t
};
$(this, n), this.summaries.push(n), this.bus.fire("operation", {
name: "createSummary",
target: n
});
}, pn = function(e) {
let t = this.summaries.find((t) => t.id === e);
!t || !Q(this, e) || this.bus.fire("operation", {
name: "removeSummary",
target: t
});
}, mn = function(e) {
let t = e.labelEl;
t && t.classList.add("selected"), this.currentSummary = e, this.bus.fire("selectSummary", e.summaryObj);
}, hn = function() {
this.currentSummary?.labelEl?.classList.remove("selected"), this.currentSummary = null, this.bus.fire("unselectSummary");
}, gn = function() {
this.summarySvg.innerHTML = "";
let e = [];
this.summaries.forEach((t) => {
try {
$(this, t) === null && e.push(t.id);
} catch {
console.warn("Node may not be expanded");
}
}), e.forEach((e) => Q(this, e)), this.nodes.insertAdjacentElement("beforeend", this.summarySvg);
}, _n = function(e) {
e && e.labelEl && wt(this, e.labelEl, e.summaryObj);
};
//#endregion
//#region src/methods.ts
Object.keys(we);
var vn = {}, yn = {
getObjById: l,
generateNewObj: h,
layout: se,
linkDiv: Tt,
editTopic: ge,
createWrapper: de,
createParent: fe,
createChildren: pe,
createTopic: me,
findEle: ue,
changeTheme: Rt,
changeCompact: zt,
...Ve,
...vn,
...Vt,
...on,
async init(e) {
if (!this.pluginsInitialized) {
if (e = JSON.parse(JSON.stringify(e)), !e || !e.nodeData) return /* @__PURE__ */ Error("MindElixir: `data` is required");
e.direction !== void 0 && (this.direction = e.direction), e.compact !== void 0 && (this.compact = e.compact), this.changeTheme(e.theme || this.theme, !1), e.meta && (this.meta = e.meta), this.nodeData = e.nodeData, u(this.nodeData), this.arrows = e.arrows || [], this.summaries = e.summaries || [], this.tidyArrow(), this.container.style.opacity = "0", this.layout(), await document.fonts.ready, this.linkDiv(), this.toCenter(), this.container.style.opacity = "", this.toolBar && At(this), this.pluginsInitialized = !0;
}
},
destroy() {
this.pluginsInitialized = !0, this.disposable.forEach((e) => e()), this.el && (this.el.innerHTML = ""), this.el = void 0, this.nodeData = void 0, this.arrows = void 0, this.summaries = void 0, this.currentArrow = void 0, this.currentNodes = void 0, this.currentSummary = void 0, this.theme = void 0, this.direction = void 0, this.bus = void 0, this.container = void 0, this.map = void 0, this.lines = void 0, this.linkController = void 0, this.arrowSvg = void 0, this.P2 = void 0, this.P3 = void 0, this.line1 = void 0, this.line2 = void 0, this.nodes = void 0, this.selection?.destroy(), this.selection = void 0;
},
enableMobileMultiSelect(e) {
this.mobileMultiSelect = e;
}
}, bn = "6.0.0-next.4";
//#endregion
//#region src/utils/panHelper.ts
function xn(e) {
return {
x: 0,
y: 0,
moved: !1,
mousedown: !1,
handlePointerDown(t) {
this.moved = !1;
let n = t.target, r = e.mouseSelectionButton === 0 ? 2 : 0, i = e.spacePressed && t.button === 0 && t.pointerType === "mouse", a = !e.editable || t.button === r && t.pointerType === "mouse" || t.pointerType === "touch";
!i && !a || (this.x = t.clientX, this.y = t.clientY, n.className !== "circle" && n.contentEditable !== "plaintext-only" && (this.mousedown = !0, n.setPointerCapture(t.pointerId)));
},
handlePointerMove(t) {
if (!this.mousedown || t.target.contentEditable === "plaintext-only" && !e.spacePressed) return !1;
let n = t.clientX - this.x, r = t.clientY - this.y;
return this.x = t.clientX, this.y = t.clientY, this.moved = !0, e.move(n, r), !0;
},
handlePointerUp(e) {
if (!this.mousedown) return;
let t = e.target;
t.hasPointerCapture && t.hasPointerCapture(e.pointerId) && t.releasePointerCapture(e.pointerId), this.mousedown = !1;
},
clear() {
this.mousedown = !1, this.moved = !1;
}
};
}
//#endregion
//#region src/index.ts
var Sn = class {
static LEFT = 0;
static RIGHT = 1;
static SIDE = 2;
static DOWN = 3;
static THEME = o;
static DARK_THEME = s;
static version = bn;
static E = ue;
static new = (e) => ({ nodeData: {
id: m(),
topic: e || "new topic",
children: []
} });
get currentNode() {
return this.currentNodes[this.currentNodes.length - 1];
}
constructor({ el: e, direction: t, editable: n, contextMenu: r, toolBar: i, keypress: a, mouseSelectionButton: c, selectionContainer: l, before: u, newTopicName: d, allowUndo: f, generateMainBranch: p, generateSubBranch: m, overflowHidden: h, compact: g, theme: _, alignment: v, scaleSensitivity: y, scaleMax: b, scaleMin: x, handleWheel: S, markdown: C, imageProxy: w, pasteHandler: T, mobileMultiSelect: E }) {
let D = null, O = Object.prototype.toString.call(e);
if (O === "[object HTMLDivElement]" ? D = e : O === "[object String]" && (D = document.querySelector(e)), !D) throw Error("MindElixir: el is not a valid element");
D.style.position = "relative", D.innerHTML = "", this.el = D, this.disposable = [], this.pluginsInitialized = !1, this.before = u || {}, this.newTopicName = d || "New Node", this.contextMenu = r ?? !0, this.toolBar = i ?? !0, this.keypress = a ?? !0, this.mouseSelectionButton = c ?? 0, this.direction = t ?? 1, this.editable = n ?? !0, this.allowUndo = f ?? !0, this.scaleSensitivity = y ?? .1, this.scaleMax = b ?? 1.4, this.scaleMin = x ?? .2, this.generateMainBranch = p || It, this.generateSubBranch = m || Lt, this.overflowHidden = h ?? !1, this.compact = g ?? !1, this.alignment = v ?? "root", this.handleWheel = S ?? !0, this.markdown = C || void 0, this.imageProxy = w || void 0, this.currentNodes = [], this.currentArrow = null, this.scaleVal = 1, this.tempDirection = null, this.mobileMultiSelect = E ?? !1, this.panHelper = xn(this), this.bus = bt(), this.container = document.createElement("div"), this.selectionContainer = l || this.container, this.container.className = "map-container";
let ee = window.matchMedia("(prefers-color-scheme: dark)");
this.theme = _ || (ee.matches ? s : o);
let k = document.createElement("div");
k.className = "map-canvas", this.map = k, this.container.setAttribute("tabindex", "0"), this.container.appendChild(this.map), this.el.appendChild(this.container), this.nodes = document.createElement("div"), this.nodes.className = "me-nodes", this.lines = H("lines"), this.summarySvg = H("summary"), this.linkController = H("linkcontroller"), this.P2 = document.createElement("div"), this.P3 = document.createElement("div"), this.P2.className = this.P3.className = "circle", this.P2.style.display = this.P3.style.display = "none", this.line1 = St(), this.line2 = St(), this.linkController.appendChild(this.line1), this.linkController.appendChild(this.line2), this.arrowSvg = H("topiclinks"), this.labelContainer = document.createElement("div"), this.labelContainer.className = "label-container", this.map.appendChild(this.nodes), this.overflowHidden ? this.container.style.overflow = "hidden" : this.disposable.push(yt(this)), T && (this.pasteHandler = T);
}
};
Object.assign(Sn.prototype, yn);
//#endregion
export { s as DARK_THEME, a as DOWN, n as LEFT, r as RIGHT, i as SIDE, o as THEME, Sn as default, m as generateUUID };