mind-elixir
Version:
Mind elixir is a free open source mind map core.
2,745 lines • 110 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 k(e) {
return {
isDragging: !1,
insertType: null,
meet: null,
ghost: D(e),
edgeMoveController: new O(e),
startX: 0,
startY: 0,
pointerId: null
};
}
var A = 5;
function j(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) {
N(e, t);
let r = e.container.getBoundingClientRect();
M(t.ghost, n.clientX - r.x, n.clientY - r.y);
}
return !0;
}
function M(e, t, n) {
e.style.transform = `translate(${t - 10}px, ${n - 10}px)`, e.style.display = "block";
}
function N(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 ee(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 > A && N(e, t), !t.isDragging) return;
let s = e.container.getBoundingClientRect();
M(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 te(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 ne(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 P = {
LHS: "lhs",
RHS: "rhs",
DOWN: "down"
}, re = function() {
this.nodes.innerHTML = "", this.nodes.classList.toggle("down", this.direction === 3);
let e = this.createTopic(this.nodeData);
F.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);
});
}
ie(this, n, t);
}, ie = function(e, t, n) {
if (e.direction === 3) {
let r = I(P.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 = I(P.LHS), i = I(P.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);
}, ae = 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;
}, oe = 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;
}, F = 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;
}, se = 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 = R(e.expanded);
if (r.appendChild(t), e.expanded !== !1) {
let t = ae(this, e.children);
n.appendChild(t);
}
}
return {
grp: n,
top: r,
tpc: i
};
}, ce = function(e) {
let t = document.createElement("div");
t.className = "me-parent";
let n = this.createTopic(e);
return F.call(this, n, e), t.appendChild(n), {
p: t,
tpc: n
};
}, le = function(e) {
let t = document.createElement("div");
return t.className = "me-children", t.append(...e), t;
}, ue = function(e) {
let t = document.createElement("div");
return t.className = "me-tpc", t.nodeObj = e, t.dataset.nodeid = "me" + e.id, t;
}, I = function(e) {
let t = document.createElement("div");
return t.className = `me-main ${e}`, t;
}, L = function(e) {
let t = e.classList;
return t.contains(P.DOWN) ? P.DOWN : t.contains(P.LHS) ? P.LHS : P.RHS;
};
function de(e) {
let t = document.createRange();
t.selectNodeContents(e);
let n = window.getSelection();
n && (n.removeAllRanges(), n.addRange(t));
}
var fe = function(e, t, n) {
let r = !1;
e.addEventListener("compositionend", () => {
r = !0, setTimeout(() => {
r = !1;
}, 0);
}), e.addEventListener("keydown", (i) => {
if (i.stopPropagation(), !(i.isComposing || i.keyCode === 229) && !(r && (i.key === "Enter" || i.key === "Escape"))) if (i.key === "Enter" || i.key === "Tab") {
if (i.shiftKey) return;
i.preventDefault(), e.blur(), t.focus();
} else i.key === "Escape" && (i.preventDefault(), e.textContent = n, e.blur(), t.focus());
});
}, pe = function(e) {
let { mei: t, editor: n, host: r, original: i, onCommit: a, onRestore: o } = e;
n.id = "input-box", n.textContent = i, n.contentEditable = "plaintext-only", n.spellcheck = !1, de(n), fe(n, t.container, i), r.style.opacity = "0", n.addEventListener("blur", () => {
let e = n.innerText?.trim() || "";
n.remove(), r.style.opacity = "1", o?.(), a(e);
});
}, me = function(e) {
if (!e) return;
let t = document.createElement("div"), n = e.nodeObj, r = n.topic, i = e.text, a = _(this.nodes, i), o = getComputedStyle(e), s = a.offsetLeft - parseFloat(o.paddingLeft || "0"), c = a.offsetTop - parseFloat(o.paddingTop || "0");
this.nodes.appendChild(t), t.style.cssText = `
left: ${s}px;
top: ${c}px;
min-width:${i.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.outline = "none", this.bus.fire("operation", {
name: "beginEdit",
target: e.nodeObj
}), pe({
mei: this,
editor: t,
host: i,
original: r,
onRestore: () => {
e.style.outline = "";
},
onCommit: (t) => {
t !== r && t !== "" && (n.topic = t, this.markdown ? e.text.innerHTML = this.markdown(n.topic, n) : e.text.textContent = t, this.linkDiv(), this.bus.fire("operation", {
name: "finishEdit",
target: n,
origin: r
}));
}
});
}, R = function(e) {
let t = document.createElement("div");
return t.className = "me-epd" + (e === !1 ? "" : " minus"), t.expanded = e !== !1, t;
}, z = (e) => {
let t = e.parent?.children;
return {
siblings: t,
index: t?.indexOf(e) ?? 0
};
};
function he(e) {
let { siblings: t, index: n } = z(e);
return t === void 0 ? 0 : (n === -1 || t.splice(n, 1), t.length);
}
function ge(e, t, n) {
let { siblings: r, index: i } = z(n);
r !== void 0 && (t === "before" ? r.splice(i, 0, e) : r.splice(i + 1, 0, e));
}
function _e(e, t) {
let { siblings: n, index: r } = z(e);
n !== void 0 && (n[r] = t, t.children = [e]);
}
function ve(e, t) {
let n = t, r = /* @__PURE__ */ new Set();
for (; n && !r.has(n);) {
if (n === e) return !0;
r.add(n), n = n.parent;
}
return !1;
}
function ye(e, t, n) {
if (ve(t, n)) return !1;
if (he(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 } = z(n);
if (r === void 0) return !1;
e === "before" ? r.splice(i, 0, t) : r.splice(i + 1, 0, t);
}
return !0;
}
//#endregion
//#region src/utils/domManipulation.ts
var be = 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);
}, xe = function(e, t, n) {
let r = n.children[0].children[0], i = t.parentElement;
if (i.classList.contains("me-parent")) {
if (B(r), i.children[1]) i.nextSibling.appendChild(n);
else {
let t = e.createChildren([n]);
i.appendChild(R(!0)), i.insertAdjacentElement("afterend", t);
}
e.linkDiv(n.offsetParent);
} else if (i.classList.contains("me-root")) {
let t = be(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();
}
}, Se = 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();
}, Ce = /* @__PURE__ */ t({
addChild: () => ke,
beginEdit: () => Re,
copyNodes: () => Ae,
insertParent: () => Oe,
insertSibling: () => De,
moveDownNode: () => Ne,
moveNodesAfter: () => Le,
moveNodesBefore: () => Ie,
moveNodesIn: () => Fe,
moveUpNode: () => Me,
removeNodes: () => Pe,
reshapeNode: () => Te,
rmSubline: () => B,
setNodeTopic: () => ze
}), we = {
before: "beforebegin",
after: "afterend"
}, B = function(e) {
let t = e.parentElement.parentElement.lastElementChild;
t?.tagName === "svg" && t?.remove();
}, Te = 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);
F.call(this, e, i), this.linkDiv(), this.bus.fire("operation", {
name: "reshapeNode",
target: i,
origin: r
});
}, Ee = function(e, t, n) {
if (!t) return null;
let r = t.nodeObj;
r.expanded === !1 && (e.expandNode(t, !0, { silent: !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 xe(e, t, a), {
newTop: o,
newNodeObj: i
};
}, De = 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(P.LHS)), ge(a, e, i), u(this.nodeData);
let o = r.parentElement, { grp: s, top: c } = this.createWrapper(a);
o.parentElement.insertAdjacentElement(we[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);
}, Oe = function(e, t) {
let n = e || this.currentNode;
if (!n) return;
B(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(P.LHS)), _e(r, i), u(this.nodeData);
let a = n.parentElement.parentElement, { grp: o, top: s } = this.createWrapper(i, !0);
s.appendChild(R(!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);
}, ke = function(e, t) {
let n = e || this.currentNode;
if (!n) return;
let r = Ee(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);
}, Ae = 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 = Ee(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)));
}, je = 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;
}
}, Me = function(e) {
let t = e || this.currentNode;
if (!t) return;
let n = t.nodeObj;
if (!n.parent) return;
let r = je(this, n, -1);
r && V([t], r.type, this.findEle(r.to.id), this);
}, Ne = function(e) {
let t = e || this.currentNode;
if (!t) return;
let n = t.nodeObj;
if (!n.parent) return;
let r = je(this, n, 1);
r && V([t], r.type, this.findEle(r.to.id), this);
}, Pe = function(e) {
if (e = b(e), e.length === 0) return;
for (let t of e) {
let e = t.nodeObj;
Se(t, he(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)
});
}, V = (e, t, n, r) => {
e = b(e);
let i = n.nodeObj;
for (let t of e) if (ve(t.nodeObj, i)) return !1;
t === "in" && i.expanded === !1 && (r.expandNode(n, !0, { silent: !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 (ye(t, e, i), t === "in") {
let e = o.parentElement.parentElement, t = e.parentElement;
xe(r, n, e), a.add(t);
} else {
B(o);
let e = o.parentElement.parentNode;
a.add(e.parentElement), n.parentElement.parentNode.insertAdjacentElement(we[t], e);
}
}
u(r.nodeData);
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";
return r.bus.fire("operation", {
name: o,
target: e.map((e) => e.nodeObj),
destination: i
}), !0;
}, Fe = function(e, t) {
return V(e, "in", t, this);
}, Ie = function(e, t) {
return V(e, "before", t, this);
}, Le = function(e, t) {
return V(e, "after", t, this);
}, Re = function(e) {
let t = e || this.currentNode;
t && (t.nodeObj.dangerouslySetInnerHTML || this.editTopic(t));
}, ze = function(e, t) {
e.text.textContent = t, e.nodeObj.topic = t, this.linkDiv();
}, Be = /* @__PURE__ */ t({
cancelFocus: () => it,
clearSelection: () => Ke,
disableEdit: () => Ze,
enableEdit: () => Xe,
expandNode: () => dt,
expandNodeAll: () => ft,
focusNode: () => rt,
getData: () => Ye,
getDataString: () => Je,
initDown: () => ct,
initLeft: () => at,
initRight: () => ot,
initSide: () => st,
install: () => nt,
move: () => et,
refresh: () => pt,
scale: () => Qe,
scaleFit: () => $e,
scrollIntoView: () => He,
selectNode: () => Ue,
selectNodes: () => We,
stringifyData: () => qe,
toCenter: () => tt,
unselectNodes: () => Ge
});
function Ve(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 He = 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);
}
}, Ue = function(e, t, n) {
this.clearSelection(), this.scrollIntoView(e), this.selection?.select(e), t && this.bus.fire("selectNewNode", e.nodeObj);
}, We = function(e) {
this.selection?.select(e);
}, Ge = function(e) {
this.selection?.deselect(e);
}, Ke = function() {
this.unselectNodes(this.currentNodes), this.unselectSummary(), this.unselectArrow();
}, qe = function(e) {
return JSON.stringify(e, (e, t) => {
if (e !== "parent" || typeof t == "string") return t;
});
}, Je = function() {
return qe(Ve(this));
}, Ye = function() {
return JSON.parse(this.getDataString());
}, Xe = function() {
this.editable = !0;
}, Ze = function() {
this.editable = !1;
}, Qe = 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 } = H(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);
}, $e = 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 } = H(this, !0);
this.map.style.transform = `translate3d(${r}px, ${i}px, 0) scale(${n})`, this.bus.fire("scale", n);
}, et = 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);
}, H = (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
};
}, tt = function() {
let { map: e, container: t } = this, { dx: n, dy: r } = H(this);
t.scrollTop = 0, t.scrollLeft = 0, e.style.transform = `translate3d(${n}px, ${r}px, 0) scale(${this.scaleVal})`;
}, nt = function(e) {
e(this);
}, rt = 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.clearHistory?.(), this.toCenter());
}, it = function() {
this.isFocusMode = !1, this.tempDirection !== null && (this.nodeData = this.nodeDataBackup, this.direction = this.tempDirection, this.tempDirection = null, this.refresh(), this.clearHistory?.(), this.toCenter());
}, at = function() {
this.direction = 0, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, ot = function() {
this.direction = 1, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, st = function() {
this.direction = 2, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, ct = function() {
this.direction = 3, this.refresh(), this.toCenter(), this.bus.fire("changeDirection", this.direction);
}, lt = (e) => e.expanded !== !1 || (e.children ?? []).some(lt), ut = (e, t, n) => {
if (e.expanded !== !1 !== t) return !0;
let r = e.children ?? [];
if (!r.length) return !1;
if (n !== void 0 && n <= 0) return r.some(lt);
let i = n === void 0 ? void 0 : n - 1;
return r.some((e) => ut(e, t, i));
}, dt = function(e, t, n) {
let r = e.nodeObj;
if (!r.children?.length) return;
let i = r.expanded !== !1, a = typeof t == "boolean" ? t : !i;
if (a === i) return;
r.expanded = a;
let o = e.getBoundingClientRect(), s = {
x: o.left,
y: o.top
}, c = e.parentNode, l = c.children[1];
if (l.expanded = r.expanded, l.className = "me-epd" + (r.expanded ? " minus" : ""), B(e), r.expanded) {
let e = this.createChildren(r.children.map((e) => this.createWrapper(e).grp));
c.parentNode.appendChild(e);
} else c.parentNode.children[1].remove();
this.linkDiv(e.closest(".me-main > .me-wrapper"));
let u = e.getBoundingClientRect(), d = {
x: u.left,
y: u.top
}, f = s.x - d.x, p = s.y - d.y;
this.move(f, p), this.bus.fire("operation", {
name: a ? "expandNode" : "collapseNode",
target: r,
silent: n?.silent
});
}, ft = function(e, t, n) {
let r = e.nodeObj, i = t ?? !r.expanded;
if (!ut(r, i)) return;
let a = e.getBoundingClientRect(), o = {
x: a.left,
y: a.top
};
d(r, i), this.refresh();
let s = this.findEle(r.id).getBoundingClientRect(), c = {
x: s.left,
y: s.top
}, l = o.x - c.x, u = o.y - c.y;
this.move(l, u), this.bus.fire("operation", {
name: i ? "expandNode" : "collapseNode",
target: r,
recursive: !0,
silent: n?.silent
});
}, pt = 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), this.isFocusMode = !1, this.nodeDataBackup = this.nodeData, this.bus.fire("refresh")), u(this.nodeData), this.layout(), this.linkDiv();
}, mt = 40, ht = 10, gt = ({ deltaMode: e, deltaY: t, viewportHeight: n }) => e === WheelEvent.DOM_DELTA_LINE ? t * mt : e === WheelEvent.DOM_DELTA_PAGE ? t * n : t, _t = ({ deltaMode: e, deltaY: t, scaleSensitivity: n, viewportHeight: r }) => {
let i = -gt({
deltaMode: e,
deltaY: t,
viewportHeight: r
}) / ht * n;
return Math.max(-n, Math.min(n, i));
}, vt = (e, t, n) => {
t !== 0 && e.scale(e.scaleVal + t, n);
}, yt = (e, t) => {
vt(e, _t({
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 bt(e) {
let { panHelper: t, container: n } = e, r = null, i = 0;
e.spacePressed = !1;
let a = {
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;
}
}, o = {
Idle: 0,
Pinch: 1,
DragWait: 2,
Drag: 3,
Pan: 4,
BoxSelect: 5
};
e.ptState = o.Idle;
let s = {
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;
}
}, c = k(e), l = {
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();
}
}
}, u = (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;
}, d = (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 (c?.isDragging) return;
let r = n.target;
r.classList.contains("me-epd") && (n.ctrlKey || n.metaKey ? e.expandNodeAll(r.previousSibling) : e.expandNode(r.previousSibling));
}, f = (t) => {
if (!e.editable) return;
let n = t.target;
if (y(n)) {
if (e.selectNode(n), n.image) {
let e = n.text.getBoundingClientRect(), { clientX: r, clientY: i } = t;
if (r < e.left || r > e.right || i < e.top || i > e.bottom) return;
}
e.beginEdit(n);
return;
}
u(n, !0);
}, p = (a) => {
if (a.pointerType === "touch" && s.handlePointerDown(a)) {
e.ptState = o.Pinch, l.clear(), t.clear(), (c.isDragging || c.pointerId !== null) && ne(e, c);
return;
}
if (e.ptState === o.Pinch) return;
let d = a.target, f = a.button === e.mouseSelectionButton;
if (d === n && (a.pointerType === "touch" || e.mouseSelectionButton === 2 && a.button === 0 && a.pointerType === "mouse") && e.clearSelection(), e.editable && !e.spacePressed && d === n && f && a.pointerType === "mouse") {
if (!a.ctrlKey && !a.metaKey && e.clearSelection(), i = 0, e.ptState = o.BoxSelect, !e.selection?.start(a)) {
e.ptState = o.Idle;
return;
}
return;
}
let p = y(d);
if (e.editable && p && d.nodeObj.parent && a.button === 0 && a.pointerType === "mouse" || (t.handlePointerDown(a), t.mousedown && (e.ptState = o.Pan)), a.button === 0 || a.pointerType === "touch") if (p) {
e.selection?.cancel();
let t = e.currentNodes || [];
if (a.ctrlKey || a.metaKey || e.mobileMultiSelect ? t.includes(d) ? r = d : ((e.currentArrow || e.currentSummary) && e.clearSelection(), e.selection?.select(d)) : t.includes(d) || e.selectNode(d), !e.editable) return;
a.pointerType === "touch" ? (e.ptState = o.DragWait, l.start(a, (t) => {
j(e, c, t, !0) && (e.ptState = o.Drag, d.setPointerCapture(t.pointerId));
})) : j(e, c, a, !1) && (e.ptState = o.Drag, d.setPointerCapture(a.pointerId));
} else u(d, !1);
}, m = (n) => {
switch (e.ptState) {
case o.Pinch:
s.handlePointerMove(n);
break;
case o.BoxSelect:
n.pointerType === "mouse" && e.selection?.move(n);
break;
case o.DragWait:
l.handleMove(n), l.timer === null && (e.ptState = o.Pan, t.handlePointerMove(n));
break;
case o.Drag:
ee(e, c, n);
break;
case o.Pan: t.handlePointerMove(n);
}
}, h = (e) => {
e.preventDefault(), e.stopImmediatePropagation(), window.removeEventListener("contextmenu", h, !0);
}, g = () => {
i = Date.now() + 500, window.addEventListener("contextmenu", h, {
capture: !0,
once: !0
}), window.setTimeout(() => window.removeEventListener("contextmenu", h, !0), 500);
}, _ = (n) => {
n.pointerType === "touch" && s.handlePointerUp(n);
let i = c.isDragging, u = t.moved;
switch (e.ptState) {
case o.BoxSelect:
(e.selection?.stop(n) ?? !1) && n.button === 2 && n.pointerType === "mouse" && g();
break;
case o.DragWait:
l.clear(), t.handlePointerUp(n);
break;
case o.Drag:
te(e, c, n), t.handlePointerUp(n);
break;
case o.Pan: t.handlePointerUp(n), t.moved && n.button === 2 && n.pointerType === "mouse" && (window.addEventListener("contextmenu", h, {
capture: !0,
once: !0
}), setTimeout(() => window.removeEventListener("contextmenu", h, !0), 300));
}
a.detect(n, f), (e.ptState !== o.Pinch || s.activePointers.size < 2) && (e.ptState = o.Idle), r &&= (!i && !u && e.selection?.deselect(r), null);
}, v = () => {
let n = e.ptState === o.BoxSelect;
s.clear(), n && e.selection?.cancel(), l.clear(), t.clear(), a.clear(), i = 0, (c.isDragging || c.pointerId !== null) && ne(e, c), e.ptState = o.Idle, r = null;
};
return S([
{
dom: n,
evt: "pointerdown",
func: p
},
{
dom: n,
evt: "pointermove",
func: m
},
{
dom: n,
evt: "pointerup",
func: _
},
{
dom: n,
evt: "pointercancel",
func: v
},
{
dom: n,
evt: "click",
func: d
},
{
dom: n,
evt: "contextmenu",
func: (t) => {
t.preventDefault(), t.button === 2 && e.editable && setTimeout(() => {
if (e.panHelper.moved || Date.now() < i || e.ptState !== o.Idle && e.ptState !== o.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(), yt(e, t);
(t.shiftKey ? e.move(-t.deltaY, 0) : e.move(-t.deltaX, -t.deltaY)) && (t.stopPropagation(), t.preventDefault());
}
},
{
dom: n,
evt: "blur",
func: v
},
{
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 xt() {
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 e = n.length - 1; e >= 0; e--) n[e] === t && n.splice(e, 1);
}
};
}
//#endregion
//#region src/utils/svg.ts
var U = "http://www.w3.org/2000/svg", W = 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";
}, G = 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, r.html ? c.innerHTML = e : c.textContent = e, c.dataset.type = o, c.dataset.svgId = s, c.dataset.x = t.toString(), c.dataset.y = n.toString(), c.dataset.anchor = i, c;
}, St = function(e, t, n) {
let r = document.createElementNS(U, "path");
return v(r, {
d: e,
stroke: t || "#666",
fill: "none",
"stroke-width": n
}), r;
}, K = function(e) {
let t = document.createElementNS(U, "svg");
return t.setAttribute("class", e), t.setAttribute("overflow", "visible"), t;
}, Ct = function() {
let e = document.createElementNS(U, "line");
return e.setAttribute("stroke", "#4dc4ff"), e.setAttribute("fill", "none"), e.setAttribute("stroke-width", "2"), e.setAttribute("opacity", "0.45"), e;
}, wt = function(e, t, n, r) {
let i = document.createElementNS(U, "g");
return [
{
name: "line",
d: e
},
{
name: "arrow1",
d: t
},
{
name: "arrow2",
d: n
}
].forEach((e, t) => {
let n = e.d, a = document.createElementNS(U, "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(U, "path");
v(s, {
d: n,
stroke: "transparent",
fill: "none",
"stroke-width": "15"
}), i.appendChild(s), i.appendChild(a), i[e.name] = a;
}), i;
}, Tt = function(e, t, n) {
if (!t) return;
let r = n.label, i = t.cloneNode(!0);
e.nodes.appendChild(i), i.style.cssText = `
left:${t.style.left};
top:${t.style.top};
max-width: 200px;
`, e.scrollIntoView(i), pe({
mei: e,
editor: i,
host: t,
original: r,
onCommit: (i) => {
n.label = i === "" ? r : i, i !== r && (e.markdown ? t.innerHTML = e.markdown(n.label, n) : t.textContent = n.label, W(t), "parent" in n ? (e.renderSummary(), e.bus.fire("operation", {
name: "finishEditSummary",
target: n
})) : e.bus.fire("operation", {
name: "finishEditArrowLabel",
target: n
}));
}
});
}, Et = (e, t, n) => {
let r = e[e.length - 1];
r && r.color === n ? r.d += " " + t : e.push({
d: t,
color: n
});
}, Dt = function(e) {
let t = this.map.querySelector(".me-root"), n = t.offsetTop, r = t.offsetLeft, i = t.offsetWidth, a = t.offsetHeight, o = this.nodes.offsetHeight, s = this.nodes.offsetWidth, c = this.map.querySelectorAll(".me-main > .me-wrapper");
this.lines.innerHTML = "";
let l = [];
for (let t = 0; t < c.length; t++) {
let n = c[t];
if (e && e !== n) {
l.push(null);
continue;
}
let r = K("subLines"), i = n.lastChild;
i.tagName === "svg" && i.remove(), n.appendChild(r), l.push(r);
}
let u = [], d = this.theme.palette;
for (let e = 0; e < c.length; e++) {
let t = c[e], f = t.querySelector(".me-tpc"), { offsetLeft: p, offsetTop: m } = _(this.nodes, f), h = f.offsetWidth, g = f.offsetHeight, v = L(t.parentNode), y = f.nodeObj.branchColor || d[e % d.length], b = this.generateMainBranch({
pT: n,
pL: r,
pW: i,
pH: a,
cT: m,
cL: p,
cW: h,
cH: g,
direction: v,
containerHeight: o,
containerWidth: s
}), x = null;
l[e] && (x = [], Ot(this, x, y, t, v, !0)), u.push({
el: t,
tpc: f,
svg: l[e],
d: b,
branchColor: y,
subPaths: x
});
}
let f = document.createDocumentFragment();
for (let e of u) {
if (e.tpc.style.borderColor = e.branchColor, f.appendChild(St(e.d, e.branchColor, "3")), !e.svg || !e.subPaths) continue;
let t = document.createDocumentFragment();
for (let n of e.subPaths) t.appendChild(St(n.d, n.color, "2"));
e.svg.appendChild(t);
}
this.lines.appendChild(f), this.labelContainer.innerHTML = "", this.renderArrow(), this.renderSummary(), this.bus.fire("linkDiv");
}, Ot = 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;
Et(t, e.generateSubBranch({
pT: c,
pL: l,
pW: u,
pH: d,
cT: p,
cL: m,
cW: h,
cH: g,
direction: i,
isFirst: a
}), _);
let v = f.children[1];
if (v) {
if (!v.expanded) continue;
} else continue;
Ot(e, t, _, o, i);
}
}, kt = class {
entries = [];
index = 0;
restorers = /* @__PURE__ */ new Map();
listeners = [];
register(e, t) {
return this.restorers.set(e, t), () => {
this.restorers.get(e) === t && this.restorers.delete(e);
};
}
subscribe(e) {
return this.listeners.push(e), () => {
let t = this.listeners.indexOf(e);
t !== -1 && this.listeners.splice(t, 1);
};
}
push(e, t, n, r) {
this.entries.length = this.index, this.entries.push({
doc: e,
before: t,
after: n,
meta: r,
time: Date.now()
}), this.index = this.entries.length, this.emit();
}
get canUndo() {
return this.index > 0;
}
get canRedo() {
return this.index < this.entries.length;
}
get size() {
return this.entries.length;
}
get currentIndex() {
return this.index;
}
getEntries() {
return this.entries;
}
undo() {
if (!this.canUndo) return null;
this.index--;
let e = this.entries[this.index];
return this.restorers.get(e.doc)?.(e, "undo"), this.emit(), e;
}
redo() {
if (!this.canRedo) return null;
let e = this.entries[this.index];
return this.index++, this.restorers.get(e.doc)?.(e, "redo"), this.emit(), e;
}
clear() {
this.entries.length = 0, this.index = 0, this.emit();
}
emit() {
this.listeners.forEach((e) => e());
}
}, At = {
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>"
}, q = (e, t) => {
let n = document.createElement("span");
return n.id = e, n.innerHTML = At[t], n;
};
function jt(e) {
let t = document.createElement("div"), n = q("fullscreen", "full"), r = q("toCenter", "living"), i = q("zoomout", "zoomout"), a = q("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
};
}, c = () => {
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);
}
}, l = e.el;
l.addEventListener("fullscreenchange", c);
let u = !1;
return 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);
}, {
element: t,
dispose: () => {
u || (u = !0, l.removeEventListener("fullscreenchange", c), o = null);
}
};
}
function Mt(e) {
let t = document.createElement("div"), n = q("tbltl", "left"), r = q("tbltr", "right"), i = q("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 Nt(e) {
let t = jt(e);
return e.container.append(t.element), e.container.append(Mt(e)), t.dispose;
}
//#endregion
//#region src/viselect/src/utils/arrayify.ts
var { abs: Pt, max: Ft, min: It, ceil: Lt } = Math, Rt = 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 zt({ pT: e, pL: t, pW: n, pH: r, cT: i, cL: a, cW: o, cH: s, direction: c, containerHeight: l, containerWidth: u }) {
if (c === P.DOWN) {
let s = t + n / 2, c = a + o / 2;
return Rt(s, e + r, c, i);
}
let d = t + n / 2, f = e + r / 2, p;
p = c === P.LHS ? a + o : a;
let m = i + s / 2, h = (1 - Math.abs(m - f) / l) * .25 * (n / 2);
return d = c === P.LHS ? d - n / 10 - h : d + n / 10 + h, `M ${d} ${f} Q ${d} ${m} ${p} ${m}`;
}
function Bt({ pT: e, pL: t, pW: n, pH: r, cT: i, cL: a, cW: o, cH: s, direction: c, isFirst: l }) {
if (c === P.DOWN) return Rt(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.min(Math.abs(d - p) / 300 * u, u);
return c === P.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 Vt = function(e, t = !0) {
this.theme = e, this.generateMainBranch = this.theme.generateMainBranch || zt, this.generateSubBranch = this.theme.generateSubBranch || Bt;
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();
}, Ht = function(e) {
this.compact = e, this.theme && this.changeTheme(this.theme);
}, Ut = { 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;
}
};
} }, Wt = /* @__PURE__ */ t({
createArrow: () => Xt,
createArrowFrom: () => Zt,
editArrowLabel: () => cn,
removeArrow: () => Qt,
renderArrow: () => sn,
reshapeArrow: () => un,
selectArrow: () => $t,
tidyArrow: () => ln,
unselectArrow: () => en
}), Gt = "#4dc4ff";
function Kt(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 qt(e, t, n) {
e && (e.dataset.x = t.toString(), e.dataset.y = n.toString(), W(e));
}
function J(e, t, n, r, i) {
v(e, {
x1: t + "",
y1: n + "",
x2: r + "",
y2: i + ""
});
}
function Y(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 } = Kt(t, n, r, i, a, o, s, c);
e.labelEl && qt(e.labelEl, h, g);
let _ = e.labelEl;
_ && (_.style.color = d.labelColor || "rgb(235, 95, 82)"), an(e);
}
function X(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 Z(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 Jt = 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)
}
};
}, Yt = function(e, t, n, r, i) {
if (!t || !n) return;
if (!r.delta1 || !r.delta2) {
let i = Jt(e, t, n);
r.delta1 = i.delta1, r.delta2 = i.delta2;
}
let a = X(e, t, r.delta1), o = X(e, n, r.delta2), { x: s, y: c } = Z(a), { ctrlX: l, ctrlY: u } = a, { ctrlX: d, ctrlY: f } = o, { x: m, y: h } = Z(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 = wt(`M ${s} ${c} C ${l} ${u} ${d} ${f} ${m} ${h}`, _, v, r.style), { x: b, y: x } = Kt(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 = G(e.markdown ? e.markdown(r.label, r) : r.label, b, x, {
anchor: "middle",
color: S,
dataType: "arrow",
svgId: C,
html: !!e.markdown
});
y.labelEl = w, y.arrowObj = r, y.dataset.linkid = r.id, e.labelContainer.appendChild(w), e.arrowSvg.appendChild(y), W(w), i || (e.arrows.push(r), Q(e), e.currentArrow = y, on(e, r, a, o));
}, Xt = function(e, t, n = {}) {
let r = {
id: m(),
label: "Custom Link",
from: e.nodeObj.id,
to: t.nodeObj.id,
...n
};
Yt(this, e, t, r), this.bus.fire("operation", {
name: "createArrow",
target: r
});
}, Zt = function(e) {
Q(this);
let t = {
...e,
id: m()
};
Yt(this, this.findEle(t.from), this.findEle(t.to), t), this.bus.fire("operation", {
name: "createArrow",
target: t
});
}, Qt = function(e) {
let t;
if (t = e || this.currentArrow, !t) return;
Q(this);
let n = g(t.arrowObj);
this.arrows = this.arrows.filter((e) => e.id !== n.id), t.labelEl?.remove(), t.remove(), this.currentArrow === t && this.unselectArrow(), this.bus.fire("operation", {
name: "removeArrow",
target: n
});
}, $t = function(e) {
this.currentArrow = e;
let t = e.arrowObj, n = this.findEle(t.from), r = this.findEle(t.to), i = X(this, n, t.delta1), a = X(this, r, t.delta2);
this.editable ? on(this, t, i, a) : nn(e, Gt), this.bus.fire("selectArrow", t);
}, en = function() {
Q(this), this.currentArrow = null, this.bus.fire("unselectArrow");
}, tn = function(e, t) {
let n = document.createElementNS(U, "path");
return v(n, {
d: e,
stroke: t,
fill: "none",
"stroke-width": "6",
"stroke-linecap": "round",
"stroke-linejoin": "round"
}), n;
}, nn = function(e, t) {
let n = document.createElementNS(U, "g");
n.setAttribute("class", "arrow-highlight"), n.setAttribute("opacity", "0.45");
let r = tn(e.line.getAttribute("d"), t);
n.appendChild(r);
let i = tn(e.arrow1.getAttribute("d"), t);
if (n.appendChild(i), e.arrow2.getAttribute("d")) {
let r = tn(e.arrow2.getAttribute("d"), t);
n.appendChild(r);
}
e.insertBefore(n, e.firstChild);
}, rn = function(e) {
let t = e.querySelector(".arrow-highlight");
t && t.remove();
}, an = 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"));
}, Q = 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 && rn(e.currentArrow);
}, on = 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), nn(d, Gt);
let { x: p, y: m } = Z(n), { ctrlX: h, ctrlY: _ } = n, { ctrlX: v, ctrlY: y } = r, { x: b, y: x } = Z(r);
a.style.cssText = `top:${_}px;left:${h}px;`, o.style.cssText = `top:${y}px;left:${v}px;`, J(s, p, m, h, _), J(c, v, y, b, x), e.helper1 = Ut.create(a), e.helper2 = Ut.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 = Z({
...n,
ctrlX: h,
ctrlY: _
});
p = o.x, m = o.y, a.style.top = _ + "px", a.style.left = h + "px", Y(d, p, m, h, _, v, y, b, x, t), J(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 = Z({
...r,
ctrlX: v,
ctrlY: y
});
b = a.x, x = a.y, o.style.top = y + "px", o.style.left = v + "px", Y(d, p, m, h, _, v, y, b, x, t), J(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 sn() {
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 {
Yt(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 cn(e) {
Q(this), e && e.labelEl && Tt(this, e.labelEl, e.arrowObj);
}
function ln() {
this.arrows = this.arrows.filter((e) => l(e.from, this.nodeData) && l(e.to, this.nodeData));
}
var un = 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) {
t.label !== void 0 && r.labelEl && (this.markdown ? r.labelEl.innerHTML = this.markdown(e.label, e) : r.labelEl.textContent = e.label);
let n = this.findEle(e.from), i = this.findEle(e.to);
if (n && i) {
if (!e.delta1 || !e.delta2) {
let t = Jt(this, n, i);
e.delta1 = e.delta1 || t.delta1, e.delta2 = e.delta2 || t.delta2;
}
let t = X(this, n, e.delta1), a = X(this, i, e.delta2), { x: o, y: s } = Z(t), { ctrlX: c, ctrlY: l } = t, { ctrlX: u, ctrlY: d } = a, { x: f, y: p } = Z(a);
Y(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;`, J(this.line1, o, s, c, l), J(this.line2, u, d, f, p));
}
}
this.bus.fire("operation", {
name: "reshapeArrow",
target: e,
origin: n
});
}, dn = /* @__PURE__ */ t({
createSummary: () => Sn,
createSummaryFrom: () => Cn,
editSummary: () => On,
removeSummary: () => wn,
renderSummary: () => Dn,
selectSummary: () => Tn,
unselectSummary: () => En
}), fn = function(e) {
if (e.length === 0) return null;
if (e.length === 1) {
let t = e[0].nodeObj, n = e[0].nodeObj.parent;
if (!n) return null;
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) return null;
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;
return s.parent ? {
parent: s.id,
start: a,
end: o
} : null;
}, pn = function(e) {
let t = document.createElementNS(U, "g");
return t.setAttribute("id", e), t;
}, mn = function(e, t) {
let n = document.createElementNS(U, "path");
return v(n, {
d: e,
stroke: t || "#666",
fill: "none",
"stroke-linecap": "round",
"stroke-width": "2"
}), n;
}, hn = (e) => e.parentElement.parentElement, gn = 12, _n = 20, vn = function(e, t) {
if (t.length === 0) return {
order: [],
contained: /* @__PURE__ */ new Map()
};
let n = /* @__PURE__ */ new Map();
for (let e of t) {
let t = n.get(e.parent);
t ? t.push(e) : n.set(e.parent, [e]);
}
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = [], o = (e) => {
r.set(e.id, e);
let t = e.children;
if (t) for (let e = 0; e < t.length; e++) i.set(t[e], e), o(t[e]);
let s = n.get(e.id);
s && (s.sort((e, t) => t.start - e.start || e.end - t.end), a.push(...s));
};
o(e);
let s = (e, t) => {
let n = r.get(t.parent);
if (!n) return !1;
let a = r.get(e.parent);
for (; a;) {
if (a === n) return e.start >= t.start && e.end <= t.end;
if (a.parent === n) {
let e = i.get(a);
return e !== void 0 && e >= t.start && e <= t.end;
}
a = a.parent;
}
return !1;
}, c = /* @__PURE__ */ new Map(), l = [];
for (let e of a) {
let t = [];
for (let n of l) s(n, e) && t.push(n);
c.set(e.id, t), l.push(e);
}
return {
order: a,
contained: c
};
}, yn = 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);
}, bn = function(e, { parent: t, start: n }) {
let r = e.findEle(t), i = r.nodeObj, a;
return a = i.parent ? L(r.closest(".me-main")) : L(e.findEle(i.children[n].id).closest(".me-main")), a;
}, xn = function(e, t, n = [], r) {
let { id: i, label: a, parent: o, start: s, end: c, style: l } = t, { nodes: u, theme: d, summarySvg: f } = e, p = e.findEle(o).nodeObj, m = bn(e, t), h = Infinity, g = 0, v = 0, y = 0, b = 0, x = Infinity, S = 0;
for (let t = s; t <= c; t++) {
let n = p.children?.[t];
if (!n) return console.warn("Child not found"), null;
let r = hn(e.findEle(n.id)), { offsetLeft: i, offsetTop: a } = _(u, r), o = s === c ? 10 : 20;
t === s && (v = a + o), t === c && (y = a + r.offsetHeight - o), t === s && (x = i + o), t === c && (S = i + r.offsetWidth - o), a + r.offsetHeight > b && (b = a + r.offsetHeight), i < h && (h = i), r.offsetWidth + i > g && (g = r.offsetWidth + i);
}
let C = 0;
if (n.length > 0 && r) if (m === P.DOWN) {
let e = -Infinity;
for (let t of n) {
let n = r.get(t.id);
n && n.bottom > e && (e = n.bottom);
}
e !== -Infinity && (C = Math.max(0, e - b + gn));
} else if (m === P.LHS) {
let e = Infinity;
for (let t of n) {
let n = r.get(t.id);
n && n.left < e && (e = n.left);
}
e !== Infinity && (C = Math.max(0, h + 10 - e + gn));
} else {
let e = -Infinity;
for (let t of n) {
let n = r.get(t.id);
n && n.right > e && (e = n.right);
}
e !== -Infinity && (C = Math.max(0, e - g + 10 + gn));
}
let w, T, E = l?.stroke || d.cssVar["--color"], D = l?.labelColor || d.cssVar["--color"], O = "s-" + i, k = e.markdown ? e.markdown(a, t) : a;
if (m === P.DOWN) {
let t = b + _n + C, n = (x + S) / 2;
w = mn(`M ${x} ${t - 10} c 0 5 5 10 10 10 L ${S - 10} ${t} c 5 0 10 -5 10 -10 M ${n} ${t} v 10`, E), T = G(k, n, t + 20, {
anchor: "middle",
color: D,
dataType: "summary",
svgId: O,
html: !!e.markdown
});
} else {
let t = p.parent ? 10 : 0, n = v + t, r = y + t, i = (n + r) / 2;
m === P.LHS ? (w = mn(`M ${h + 10 - C} ${n} c -5 0 -10 5 -10 10 L ${h - C} ${r - 10} c 0 5 5 10 10 10 M ${h - C} ${i} h -10`, E), T = G(k, h - 20 - C, i, {
anchor: "end",
color: D,
dataType: "summary",
svgId: O,
html: !!e.markdown
})) : (w = mn(`M ${g - 10 + C} ${n} c 5 0 10 5 10 10 L ${g + C} ${r - 10} c 0 5 -5 10 -10 10 M ${g + C} ${i} h 10`, E), T = G(k, g + 20 + C, i, {
anchor: "start",
color: D,
dataType: "summary",
svgId: O,
html: !!e.markdown
}));
}
let A = pn(O);
A.appendChild(w), e.labelContainer.appendChild(T), W(T), A.summaryObj = t, A.labelEl = T, f.appendChild(A);
let j = T.offsetWidth, M = T.offsetHeight, N;
if (m === P.DOWN) {
let e = b + _n + C, t = (x + S) / 2;
N = {
top: e - 10,
bottom: e + 20 + M / 2,
left: Math.min(x, t - j / 2),
right: Math.max(S, t + j / 2)
};
} else if (m === P.LHS) {
let e = p.parent ? 10 : 0, t = (v + e + y + e) / 2;
N = {
left: h - 20 - C - j,
right: h - C + 10,
top: Math.min(v + e, t - M / 2),
bottom: Math.max(y + e, t + M / 2)
};
} else {
let e = p.parent ? 10 : 0, t = (v + e + y + e) / 2;
N = {
left: g + C - 10,
right: g + 20 + C + j,
top: Math.min(v + e, t - M / 2),
bottom: Math.max(y + e, t + M / 2)
};
}
return r?.set(i, N), A;
}, Sn = function(e = {}) {
let { currentNodes: t, summaries: n, bus: r } = this, i = fn(t);
if (!i) return;
let { parent: a, start: o, end: s } = i, c = {
id: m(),
parent: a,
start: o,
end: s,
label: "summary",
style: e.style
};
n.push(c), this.renderSummary();
let l = this.nodes.querySelector("#s-" + c.id);
l && this.editSummary(l), r.fire("operation", {
name: "createSummary",
target: c
});
}, Cn = function(e) {
let t = m(), n = {
...e,
id: t
};
this.summaries.push(n), this.renderSummary(), this.bus.fire("operation", {
name: "createSummary",
target: n
});
}, wn = function(e) {
let t = this.summaries.find((t) => t.id === e);
!t || !yn(this, e) || (this.currentSummary?.summaryObj.id === e && this.unselectSummary(), this.renderSummary(), this.bus.fire("operation", {
name: "removeSummary",
target: t
}));
}, Tn = function(e) {
let t = e.labelEl;
t && t.classList.add("selected"), this.currentSummary = e, this.bus.fire("selectSummary", e.summaryObj);
}, En = function() {
this.currentSummary?.labelEl?.classList.remove("selected"), this.currentSummary = null, this.bus.fire("unselectSummary");
}, Dn = function() {
if (this.summarySvg.innerHTML = "", this.labelContainer.querySelectorAll(".svg-label[data-type=\"summary\"]").forEach((e) => e.remove()), this.summaries.length === 0) {
this.nodes.insertAdjacentElement("beforeend", this.summarySvg);
return;
}
let e = [], { order: t, contained: n } = vn(this.nodeData, this.summaries), r = /* @__PURE__ */ new Map();
for (let i of t) try {
xn(this, i, n.get(i.id) || [], r) === null && e.push(i.id);
} catch {
console.warn("Node may not be expanded");
}
e.forEach((e) => yn(this, e)), this.nodes.insertAdjacentElement("beforeend", this.summarySvg);
}, On = function(e) {
e && e.labelEl && Tt(this, e.labelEl, e.summaryObj);
};
//#endregion
//#region src/methods.ts
Object.keys(Ce);
var kn = {}, An = {
getObjById: l,
generateNewObj: h,
layout: re,
linkDiv: Dt,
editTopic: me,
createWrapper: se,
createParent: ce,
createChildren: le,
createTopic: ue,
findEle: oe,
changeTheme: Vt,
changeCompact: Ht,
...Be,
...kn,
...Wt,
...dn,
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(), this.pluginsInitialized = !0, await document.fonts.ready, this.container && (this.linkDiv(), this.toCenter(), this.container.style.opacity = "", this.toolBar && this.disposable.push(Nt(this)));
}
},
destroy() {
this.pluginsInitialized = !0;
let e = this.disposable || [];
this.disposable = [], e.forEach((e) => e()), this.helper1?.destroy?.(), this.helper2?.destroy?.(), 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.root = void 0, this.summarySvg = void 0, this.labelContainer = void 0, this.dragged = null, this.nodeDataBackup = void 0, this.meta = void 0, this.panHelper = void 0, this.helper1 = void 0, this.helper2 = void 0, this.historyStack = void 0, this.selection?.destroy(), this.selection = void 0;
},
enableMobileMultiSelect(e) {
this.mobileMultiSelect = e;
}
}, jn = "6.0.3";
//#endregion
//#region src/utils/panHelper.ts
function Mn(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/outliner/icons.ts
var Nn = {
home: "<path d=\"M3 9.5 12 3l9 6.5\"/><path d=\"M5 10v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V10\"/><path d=\"M9 21v-6h6v6\"/>",
ellipsis: "<circle cx=\"12\" cy=\"12\" r=\"1\"/><circle cx=\"19\" cy=\"12\" r=\"1\"/><circle cx=\"5\" cy=\"12\" r=\"1\"/>",
chevronDown: "<path d=\"m6 9 6 6 6-6\"/>",
chevronRight: "<path d=\"m9 18 6-6-6-6\"/>",
arrowLeft: "<path d=\"m12 19-7-7 7-7\"/><path d=\"M19 12H5\"/>",
arrowRight: "<path d=\"M5 12h14\"/><path d=\"m12 5 7 7-7 7\"/>",
trash: "<path d=\"M3 6h18\"/><path d=\"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6\"/><path d=\"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2\"/><path d=\"M10 11v6\"/><path d=\"M14 11v6\"/>"
}, Pn = (e, t) => `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${Nn[e] ?? ""}</svg>`, Fn = /* @__PURE__ */ new Map();
function $(e, t = 16) {
let n = `${e}:${t}`, r = Fn.get(n);
return r === void 0 && (r = Pn(e, t), Fn.set(n, r)), r;
}
//#endregion
//#region src/outliner/types.ts
var In = {
menuTitle: "操作菜单",
outdent: "取消缩进",
indent: "缩进",
delete: "删除",
untitled: "(无标题)",
zoomInAndDrag: "点击进入 / 拖拽移动"
}, Ln = (e) => {
e.children ||= [], e.children.forEach(Ln);
}, Rn = class {
el;
breadcrumbEl;
itemsEl;
root;
history;
mei;
suppressSync = !1;
syncDirty = !1;
syncQueued = !1;
readonly;
markdown;
i18n;
fileName;
onChange;
zoomedId = null;
editingId = null;
compositionJustEnded = !1;
openMenuId = null;
draggedId = null;
draggedContainer = null;
dropIndicator = null;
views = /* @__PURE__ */ new Map();
seen = /* @__PURE__ */ new Set();
breadcrumbSig = "";
disposers = [];
constructor(e) {
let t = typeof e.el == "string" ? document.querySelector(e.el) : e.el;
if (!t) throw Error("Outliner: el is not a valid element");
if (this.el = t, this.el.innerHTML = "", this.mei = e.mei, !this.mei.historyStack) throw Error("Outliner: mei.historyStack is missing — create the MindElixir instance with `allowUndo: true` and await `init`");
this.history = this.mei.historyStack, this.readonly = e.readonly ?? !1, this.markdown = e.markdown, this.i18n = {
...In,
...e.i18n
}, this.fileName = e.fileName, this.onChange = e.onChange, this.bindRoot(), this.breadcrumbEl = document.createElement("div"), this.breadcrumbEl.className = "outliner-breadcrumb", this.itemsEl = document.createElement("div"), this.itemsEl.className = "outliner-items";
let n = document.createElement("div");
n.className = "outliner-container", n.appendChild(this.breadcrumbEl), n.appendChild(this.itemsEl), this.el.appendChild(n), this.disposers.push(this.history.subscribe(this.requestSync));
let r = (e) => {
e.silent && this.scheduleSync();
}, i = this.mei.bus;
i.addListener("operation", r), this.disposers.push(() => i.removeListener("operation", r)), document.addEventListener("keydown", this.handleGlobalKeydown), this.disposers.push(() => document.removeEventListener("keydown", this.handleGlobalKeydown)), document.addEventListener("mousedown", this.handleDocumentMousedown), this.disposers.push(() => document.removeEventListener("mousedown", this.handleDocumentMousedown)), this.el.addEventListener("keydown", this.handleTopicKeydown), this.el.addEventListener("compositionend", this.handleCompositionEnd), this.disposers.push(() => this.el.removeEventListener("compositionend", this.handleCompositionEnd)), this.el.addEventListener("click", this.handleClick), this.el.addEventListener("focusin", this.handleFocusIn), this.el.addEventListener("focusout", this.handleFocusOut), this.el.addEventListener("dragstart", this.handleDragStart), this.el.addEventListener("dragend", this.handleDragEnd), this.el.addEventListener("dragover", this.handleDragOver), this.el.addEventListener("dragleave", this.handleDragLeave), this.el.addEventListener("drop", this.handleDrop), this.render();
}
getData() {
return JSON.parse(this.mei.stringifyData(this.root));
}
addChild(e) {
let t = this.meiEle(e);
if (!t) return;
this.flushEditingText();
let n = m();
this.mei.addChild(t, {
id: n,
topic: "",
children: []
}), this.focusItem(n);
}
destroy() {
this.disposers.forEach((e) => e()), this.disposers = [], this.el.removeEventListener("keydown", this.handleTopicKeydown), this.el.removeEventListener("keydown", this.handleGlobalKeydown), this.el.removeEventListener("click", this.handleClick), this.el.removeEventListener("focusin", this.handleFocusIn), this.el.removeEventListener("focusout", this.handleFocusOut), this.el.removeEventListener("dragstart", this.handleDragStart), this.el.removeEventListener("dragend", this.handleDragEnd), this.el.removeEventListener("dragover", this.handleDragOver), this.el.removeEventListener("dragleave", this.handleDragLeave), this.el.removeEventListener("drop", this.handleDrop), this.views.clear(), this.seen.clear(), this.dropIndicator = null, this.draggedContainer = null, this.syncDirty = !1, this.el.innerHTML = "";
}
focusItem(e) {
let t = this.itemsEl.querySelector(`[data-outline-item][data-item-id="${CSS.escape(e)}"]`);
if (!t) return;
let n = document.activeElement === t;
t.focus(), n && this.placeCaretAtEnd(t);
}
bindRoot() {
let e = this.mei.nodeData;
this.root !== e && (this.root = e), Ln(e);
}
byId(e) {
return l(e, this.root);
}
isRoot(e) {
return this.root.id === e;
}
parentOf(e) {
return this.byId(e)?.parent ?? null;
}
prevSiblingOf(e) {
let t = this.byId(e), n = t?.parent?.children;
if (!t || !n) return null;
let r = n.indexOf(t);
return r > 0 ? n[r - 1] : null;
}
pathTo(e) {
let t = [], n = this.byId(e);
for (; n && (t.unshift({
id: n.id,
topic: n.topic
}), n.id !== this.root.id);) n = n.parent ?? null;
return t;
}
meiEle(e) {
try {
return this.mei.findEle(e);
} catch {
return null;
}
}
requestSync = () => {
this.suppressSync || (this.syncDirty = !1, this.rerenderFromMei());
};
scheduleSync = () => {
this.suppressSync || (this.syncDirty = !0, !this.syncQueued && (this.syncQueued = !0, queueMicrotask(() => {
this.syncQueued = !1, this.syncDirty && (this.syncDirty = !1, this.rerenderFromMei());
})));
};
rerenderFromMei() {
if (this.suppressSync) return;
this.bindRoot(), this.zoomedId && !this.byId(this.zoomedId) && (this.zoomedId = null), this.flushEditingText();
let e = this.editingId ? this.views.get(this.editingId) : null;
this.openMenuId = null, this.render(), this.editingId && this.views.get(this.editingId) !== e && (this.editingId = null), this.emitChange();
}
emitChange() {
this.onChange?.(this.getData());
}
flushEditingText() {
let e = this.liveEditingText();
if (!e) return;
let t = this.byId(e.id);
t && t.topic !== e.text && this.setNodeTopicBound(e.id, e.text);
}
setNodeTopicBound(e, t) {
let n = this.meiEle(e);
if (n) {
this.suppressSync = !0;
try {
this.mei.reshapeNode(n, { topic: t });
} finally {
this.suppressSync = !1;
}
}
}
expandBound(e, t) {
let n = this.meiEle(e);
n && this.mei.expandNode(n, t);
}
applyOperation(e) {
if (this.readonly || this.isRoot(e.id)) return;
this.flushEditingText();
let t = this.meiEle(e.id);
if (!t) return;
let n = e.type === "addSibling" || e.type === "addSiblingBefore" ? m() : null, r = n ? {
id: n,
topic: e.newNodeContent ?? "",
children: []
} : void 0;
switch (e.type) {
case "addSibling":
this.mei.insertSibling("after", t, r);
break;
case "addSiblingBefore":
this.mei.insertSibling("before", t, r);
break;
case "indent": {
let n = this.prevSiblingOf(e.id), r = n ? this.meiEle(n.id) : null;
r && this.mei.moveNodesIn([t], r);
break;
}
case "outdent": {
let n = this.parentOf(e.id), r = n && !this.isRoot(n.id) ? this.meiEle(n.id) : null;
r && this.mei.moveNodesAfter([t], r);
break;
}
case "moveUp":
this.mei.moveUpNode(t);
break;
case "moveDown":
this.mei.moveDownNode(t);
break;
case "moveTo": {
let n = e.targetId ? this.meiEle(e.targetId) : null;
if (!n || this.isRoot(e.targetId) && e.dropPosition !== "inside") break;
e.dropPosition === "before" ? this.mei.moveNodesBefore([t], n) : e.dropPosition === "after" ? this.mei.moveNodesAfter([t], n) : this.mei.moveNodesIn([t], n);
break;
}
}
n ? this.focusItem(n) : e.shouldFocusCurrent && this.focusItem(e.id);
}
deleteItem(e) {
if (this.readonly || this.isRoot(e)) return;
let t = this.getTopicEl(e), n = null;
if (t) {
let r = Array.from(this.itemsEl.querySelectorAll("[data-outline-item]")), i = r.indexOf(t);
n = i > 0 ? r[i - 1].getAttribute("data-item-id") : this.parentOf(e)?.id ?? null;
}
this.flushEditingText();
let r = this.meiEle(e);
r && (this.mei.removeNodes([r]), n && this.focusItem(n));
}
render() {
this.zoomedId && !this.byId(this.zoomedId) && (this.zoomedId = null), this.renderBreadcrumb();
let e = this.zoomedId ? this.byId(this.zoomedId) : null, t = e ? e.children : [this.root];
this.seen.clear();
let n = null;
for (let e of t) n = this.syncItem(e, 0, this.zoomedId ?? void 0, t.length, this.itemsEl, n);
this.unmountUnseen();
}
renderBreadcrumb() {
let e = this.zoomedId ? this.pathTo(this.zoomedId) : [], t = `${this.fileName ?? ""}\u0000${e.map((e) => `${e.id}:${e.topic}`).join("\0")}`;
if (t === this.breadcrumbSig) return;
this.breadcrumbSig = t, this.breadcrumbEl.innerHTML = "";
let n = document.createElement("button");
n.className = "breadcrumb-item breadcrumb-root", n.innerHTML = `${$("home")}<span class="breadcrumb-text">${this.escapeText(this.fileName ?? "")}</span>`, n.addEventListener("click", () => this.zoomTo(null)), this.breadcrumbEl.appendChild(n), e.forEach((t, n) => {
let r = document.createElement("span");
r.className = "breadcrumb-segment";
let i = n === e.length - 1, a = this.escapeText(t.topic || this.i18n.untitled);
if (i) r.innerHTML = `<span class="breadcrumb-separator">/</span><span class="breadcrumb-item breadcrumb-current">${a}</span>`;
else {
let e = document.createElement("button");
e.className = "breadcrumb-item", e.innerHTML = a, e.addEventListener("click", () => this.zoomTo(t.id)), r.innerHTML = "<span class=\"breadcrumb-separator\">/</span>", r.appendChild(e);
}
this.breadcrumbEl.appendChild(r);
});
}
syncItem(e, t, n, r, i, a) {
let o = this.views.get(e.id);
o ? this.patchItemView(o, e, t, n, r) : (o = this.createItemView(e, t, n, r), this.views.set(e.id, o));
let s = a ? a.nextSibling : i.firstChild;
if (s !== o.container && i.insertBefore(o.container, s), this.seen.add(e.id), e.expanded !== !1) {
let n = o.wrapper;
for (let r of e.children) n = this.syncItem(r, t + 1, e.id, e.children.length, o.container, n);
}
return o.container;
}
unmountUnseen() {
for (let [e, t] of this.views) this.seen.has(e) || (t.container.remove(), this.views.delete(e), this.openMenuId === e && (this.openMenuId = null));
}
createItemView(e, t, n, r) {
let i = document.createElement("div");
i.className = "outline-item-container", i.dataset.itemId = e.id, this.readonly && (i.style.pointerEvents = "none");
let a = null;
t > 0 && (a = document.createElement("div"), a.className = "outline-item-vertical-line", a.style.left = `${t * 24 - 13}px`, a.style.height = "100%", i.appendChild(a));
let o = document.createElement("div");
o.className = "outline-item-wrapper", o.dataset.itemId = e.id, o.style.marginLeft = `${t * 24}px`, i.appendChild(o);
let s = document.createElement("div");
s.className = "outline-item-front";
let c = document.createElement("div");
c.className = `outline-item-dot${this.readonly ? "" : " outline-item-dot-zoomable"}`, c.title = this.i18n.zoomInAndDrag, this.readonly || (c.draggable = !0), s.appendChild(c), o.appendChild(s);
let l = document.createElement("div");
l.className = "outline-item-topic", l.dataset.outlineItem = "", l.dataset.itemId = e.id, this.readonly || (l.contentEditable = "plaintext-only"), this.writeTopicHtml(l, e.topic, e), o.appendChild(l);
let u = document.createElement("div");
u.className = "outline-item-btn-group";
let d = null, f = null;
this.readonly || (d = document.createElement("div"), d.className = "outline-item-menu-wrapper", f = document.createElement("button"), f.className = "outline-item-menu-btn", f.title = this.i18n.menuTitle, f.draggable = !1, f.innerHTML = $("ellipsis", 12), d.appendChild(f), u.appendChild(d));
let p = document.createElement("button");
return p.className = "outline-item-collapse-btn", p.dataset.state = e.children.length === 0 ? "hidden" : e.expanded === !1 ? "collapsed" : "expanded", p.innerHTML = $(e.expanded === !1 ? "chevronRight" : "chevronDown"), u.appendChild(p), o.appendChild(u), {
container: i,
wrapper: o,
line: a,
dot: c,
topic: l,
btnGroup: u,
menuWrapper: d,
menuBtn: f,
dropdown: null,
menuOpen: !1,
collapse: p,
topicText: e.topic,
topicDirty: !1,
item: e,
level: t,
parentId: n,
siblingCount: r
};
}
patchItemView(e, t, n, r, i) {
let a = e.level !== n;
e.item = t, e.level = n, e.parentId = r, e.siblingCount = i, a && (e.wrapper.style.marginLeft = `${n * 24}px`, e.line && (e.line.style.left = `${n * 24 - 13}px`)), this.editingId !== t.id && (e.topicDirty || e.topicText !== t.topic) && (this.writeTopicHtml(e.topic, t.topic, t), e.topicText = t.topic, e.topicDirty = !1);
let o = t.children.length === 0 ? "hidden" : t.expanded === !1 ? "collapsed" : "expanded";
e.collapse.dataset.state !== o && (e.collapse.dataset.state = o, e.collapse.innerHTML = $(t.expanded === !1 ? "chevronRight" : "chevronDown")), this.syncDropdown(e);
}
syncDropdown(e) {
let t = !!e.menuWrapper && this.openMenuId === e.item.id;
t && !e.dropdown ? (e.dropdown = this.createDropdown(e), e.menuWrapper.appendChild(e.dropdown)) : !t && e.dropdown && (e.dropdown.remove(), e.dropdown = null), e.menuOpen !== t && (e.wrapper.classList.toggle("menu-open", t), e.menuOpen = t);
}
createDropdown(e) {
let t = document.createElement("div");
t.className = "outline-item-menu-dropdown";
let n = (e, n, r, i = !1) => {
let a = document.createElement("button");
a.className = `outline-item-menu-item${i ? " outline-item-menu-item-danger" : ""}`, a.dataset.action = r, a.innerHTML = `${$(n, 12)}<span>${e}</span>`, t.appendChild(a);
};
return n(this.i18n.outdent, "arrowLeft", "outdent"), n(this.i18n.indent, "arrowRight", "indent"), (e.level > 0 || e.siblingCount > 1) && n(this.i18n.delete, "trash", "delete", !0), t;
}
toggleMenu(e) {
this.setOpenMenu(this.openMenuId === e ? null : e);
}
setOpenMenu(e) {
let t = this.openMenuId;
if (t !== e) {
if (this.openMenuId = e, t) {
let e = this.views.get(t);
e && this.syncDropdown(e);
}
if (e) {
let t = this.views.get(e);
t && this.syncDropdown(t);
}
}
}
runMenuAction(e) {
let t = this.openMenuId;
if (!t) return;
let n = this.views.get(t);
if (!n) return;
let { item: r, level: i, siblingCount: a } = n;
this.setOpenMenu(null), e === "outdent" ? this.applyOperation({
type: "outdent",
id: r.id,
shouldFocusCurrent: !0
}) : e === "indent" ? this.applyOperation({
type: "indent",
id: r.id,
shouldFocusCurrent: !0
}) : e === "delete" && (i > 0 || a > 1) && this.deleteItem(r.id);
}
handleDragStart = (e) => {
let t = e.target;
if (!t.closest?.(".outline-item-dot")) return;
let n = t.closest(".outline-item-container"), r = n?.dataset.itemId;
!n || !r || (e.stopPropagation(), this.draggedId = r, this.draggedContainer = n, e.dataTransfer && (e.dataTransfer.effectAllowed = "move"), n.style.opacity = "0.4");
};
handleDragEnd = () => {
this.clearDropIndicator(), this.draggedId = null, this.draggedContainer &&= (this.draggedContainer.style.opacity = "", null);
};
handleDragOver = (e) => {
let t = e.target.closest?.(".outline-item-wrapper");
if (!t) return;
e.stopPropagation(), e.preventDefault();
let n = () => t.classList.remove("drag-over", "drag-over-bottom", "drag-over-inside"), r = this.views.get(t.dataset.itemId ?? "");
if (!r || !this.draggedId || this.draggedId === r.item.id) {
n();
return;
}
let i = t.closest(".outline-item-container");
if (!this.draggedContainer || !i || this.draggedContainer.contains(i)) {
n(), e.dataTransfer && (e.dataTransfer.dropEffect = "none");
return;
}
e.dataTransfer && (e.dataTransfer.dropEffect = "move");
let a = t.getBoundingClientRect(), o = e.clientY - a.top, s = o < a.height * .25 ? "before" : o > a.height * .75 ? "after" : "inside";
(this.dropIndicator?.el !== t || this.dropIndicator.position !== s) && (this.clearDropIndicator(), t.classList.add(s === "before" ? "drag-over" : s === "after" ? "drag-over-bottom" : "drag-over-inside"), this.dropIndicator = {
el: t,
position: s
});
};
handleDragLeave = (e) => {
let t = e.target.closest?.(".outline-item-wrapper");
t && (e.stopPropagation(), t.contains(e.relatedTarget) || t.classList.remove("drag-over", "drag-over-bottom", "drag-over-inside"));
};
handleDrop = (e) => {
let t = e.target.closest?.(".outline-item-wrapper");
if (!t) return;
e.preventDefault(), e.stopPropagation();
let n = this.dropIndicator?.el === t ? this.dropIndicator.position : null;
this.clearDropIndicator();
let r = this.views.get(t.dataset.itemId ?? ""), i = this.draggedId;
!r || !i || i === r.item.id || !n || this.applyOperation({
type: "moveTo",
id: i,
targetId: r.item.id,
dropPosition: n,
shouldFocusCurrent: !0
});
};
clearDropIndicator() {
this.dropIndicator &&= (this.dropIndicator.el.classList.remove("drag-over", "drag-over-bottom", "drag-over-inside"), null);
}
writeTopicHtml(e, t, n) {
this.markdown ? e.innerHTML = this.markdown(t, n) : e.textContent = t;
}
escapeText(e) {
let t = document.createElement("div");
return t.textContent = e, t.innerHTML;
}
getTopicEl(e) {
return this.itemsEl.querySelector(`[data-outline-item][data-item-id="${CSS.escape(e)}"]`);
}
liveEditingText() {
if (!this.editingId) return null;
let e = this.getTopicEl(this.editingId);
return e ? {
id: this.editingId,
text: e.textContent ?? ""
} : null;
}
handleFocusIn = (e) => {
let t = e.target;
if (!t.matches?.("[data-outline-item]")) return;
let n = t.getAttribute("data-item-id"), r = this.byId(n);
if (!r) return;
this.editingId = n, t.textContent = r.topic;
let i = this.views.get(n);
i && (i.topicDirty = !0), this.placeCaretAtEnd(t);
};
placeCaretAtEnd(e) {
let t = document.createRange();
t.selectNodeContents(e), t.collapse(!1);
let n = window.getSelection();
n?.removeAllRanges(), n?.addRange(t);
}
markTopicClean(e, t) {
let n = this.views.get(e);
n && (n.topicText = t, n.topicDirty = !1);
}
handleFocusOut = (e) => {
let t = e.target;
if (!t.matches?.("[data-outline-item]")) return;
let n = t.getAttribute("data-item-id");
if (this.editingId !== n) return;
this.editingId = null;
let r = t.textContent ?? "", i = this.byId(n);
i && i.topic !== r && this.setNodeTopicBound(n, r);
let a = this.byId(n);
a && this.writeTopicHtml(t, a.topic, a), this.markTopicClean(n, a?.topic ?? r);
};
handleCompositionEnd = () => {
this.compositionJustEnded = !0, setTimeout(() => {
this.compositionJustEnded = !1;
}, 0);
};
handleTopicKeydown = (e) => {
if (e.isComposing || e.keyCode === 229 || this.compositionJustEnded && (e.key === "Enter" || e.key === "Escape")) return;
let t = e.target.closest?.("[data-outline-item]");
if (!t || this.readonly) return;
let n = t.getAttribute("data-item-id"), r = t.textContent?.trim();
if (e.key === "ArrowUp" && e.altKey) e.preventDefault(), this.applyOperation({
type: "moveUp",
id: n,
shouldFocusCurrent: !0
});
else if (e.key === "ArrowDown" && e.altKey) e.preventDefault(), this.applyOperation({
type: "moveDown",
id: n,
shouldFocusCurrent: !0
});
else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
e.preventDefault();
let n = Array.from(this.itemsEl.querySelectorAll("[data-outline-item]")), r = n.indexOf(t);
if (r === -1) return;
let i = n[r + (e.key === "ArrowUp" ? -1 : 1)];
i && (t.blur(), i.focus());
} else if (e.key === "Enter") {
if (e.preventDefault(), this.isRoot(n)) return;
if (e.shiftKey) {
this.applyOperation({
type: "addSiblingBefore",
id: n
});
return;
}
let r = t.textContent ?? "", i = window.getSelection(), a = r.length;
if (i && i.rangeCount > 0) {
let e = i.getRangeAt(0), n = e.cloneRange();
n.selectNodeContents(t), n.setEnd(e.endContainer, e.endOffset), a = n.toString().length;
}
let o = r.substring(0, a), s = r.substring(a);
if (o.trim() === "" && s.trim() === "") this.applyOperation({
type: "outdent",
id: n,
shouldFocusCurrent: !0
});
else if (s.trim() !== "") {
let e = this.meiEle(n);
if (!e) return;
let r = m(), i = this.byId(n);
t.textContent = o, o !== (i?.topic ?? "") && this.setNodeTopicBound(n, o), this.mei.insertSibling("after", e, {
id: r,
topic: s,
children: []
}), this.focusItem(r);
} else this.applyOperation({
type: "addSibling",
id: n
});
} else e.key === "Tab" ? (e.preventDefault(), this.applyOperation({
type: e.shiftKey ? "outdent" : "indent",
id: n,
shouldFocusCurrent: !0
})) : e.key === "Backspace" && r === "" && !this.isRoot(n) && (e.preventDefault(), this.deleteItem(n));
};
handleClick = (e) => {
let t = e.target;
if (!t.closest || t.closest(".breadcrumb-item")) return;
let n = t.closest(".outline-item-container")?.dataset.itemId, r = t.closest(".outline-item-menu-item");
if (r) {
e.stopPropagation(), this.runMenuAction(r.dataset.action ?? "");
return;
}
if (t.closest(".outline-item-menu-btn")) {
e.stopPropagation(), n && this.toggleMenu(n);
return;
}
if (t.closest(".outline-item-collapse-btn")) {
e.stopPropagation();
let t = n ? this.views.get(n) : void 0;
t && this.expandBound(t.item.id, t.item.expanded === !1);
return;
}
if (t.closest(".outline-item-dot")) {
e.stopPropagation(), n && this.zoomTo(n);
return;
}
this.setOpenMenu(null);
};
handleDocumentMousedown = (e) => {
this.openMenuId && (e.target.closest?.(".outline-item-menu-wrapper") || this.setOpenMenu(null));
};
handleGlobalKeydown = (e) => {
if (this.mei.container?.contains(e.target)) return;
let t = document.activeElement, n = !!t && (t.getAttribute("contenteditable") === "true" || t.isContentEditable), r = !!t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA"), i = e.metaKey || e.ctrlKey, a = e.key.toLowerCase();
if (n && i && a === "z" && !e.shiftKey) {
e.preventDefault();
let n = t.textContent || "", r = !1;
try {
r = document.execCommand("undo");
} catch {
r = !1;
}
setTimeout(() => {
let e = t.textContent || "";
(!r || n === e) && this.mei.undo();
}, 0);
return;
}
r || n || (i && a === "z" && !e.shiftKey ? (e.preventDefault(), this.mei.undo()) : i && (a === "y" || a === "z" && e.shiftKey) && (e.preventDefault(), this.mei.redo()));
};
zoomTo(e) {
this.setOpenMenu(null), this.zoomedId = e, this.syncDirty = !1, this.render();
}
}, zn = class {
static LEFT = 0;
static RIGHT = 1;
static SIDE = 2;
static DOWN = 3;
static THEME = o;
static DARK_THEME = s;
static version = jn;
static E = oe;
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, rtl: n, editable: r, contextMenu: i, toolBar: a, keypress: c, mouseSelectionButton: l, selectionContainer: u, before: d, newTopicName: f, allowUndo: p, generateMainBranch: m, generateSubBranch: h, overflowHidden: g, compact: _, theme: v, alignment: y, scaleSensitivity: b, scaleMax: x, scaleMin: S, handleWheel: C, markdown: w, imageProxy: T, pasteHandler: E, mobileMultiSelect: D }) {
let O = null, k = Object.prototype.toString.call(e);
if (k === "[object HTMLDivElement]" ? O = e : k === "[object String]" && (O = document.querySelector(e)), !O) throw Error("MindElixir: el is not a valid element");
O.style.position = "relative", O.innerHTML = "", this.el = O, this.disposable = [], this.pluginsInitialized = !1, this.before = d || {}, this.newTopicName = f || "New Node", this.contextMenu = i ?? !0, this.toolBar = a ?? !0, this.keypress = c ?? !0, this.mouseSelectionButton = l ?? 0, this.direction = t ?? 1, this.rtl = n ?? !1, this.editable = r ?? !0, this.allowUndo = p ?? !0, this.scaleSensitivity = b ?? .1, this.scaleMax = x ?? 1.4, this.scaleMin = S ?? .2, this.generateMainBranch = m || zt, this.generateSubBranch = h || Bt, this.overflowHidden = g ?? !1, this.compact = _ ?? !1, this.alignment = y ?? "root", this.handleWheel = C ?? !0, this.markdown = w || void 0, this.imageProxy = T || void 0, this.currentNodes = [], this.currentArrow = null, this.scaleVal = 1, this.tempDirection = null, this.mobileMultiSelect = D ?? !1, this.panHelper = Mn(this), this.bus = xt(), this.container = document.createElement("div"), this.selectionContainer = u || this.container, this.container.className = this.rtl ? "map-container rtl" : "map-container";
let A = window.matchMedia("(prefers-color-scheme: dark)");
this.theme = v || (A.matches ? s : o);
let j = document.createElement("div");
j.className = "map-canvas", this.map = j, 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 = K("lines"), this.summarySvg = K("summary"), this.linkController = K("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 = Ct(), this.line2 = Ct(), this.linkController.appendChild(this.line1), this.linkController.appendChild(this.line2), this.arrowSvg = K("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(bt(this)), E && (this.pasteHandler = E);
}
};
Object.assign(zn.prototype, An);
//#endregion
export { s as DARK_THEME, a as DOWN, kt as HistoryStack, n as LEFT, Rn as Outliner, r as RIGHT, i as SIDE, o as THEME, zn as default, m as generateUUID };