import { t as e } from "./dagre-BM10A37c.js";
import { T as t, h as n } from "./chunk-GEFDOKGD-8e2771NL.js";
import { t as r } from "./graphlib-DOjl69i0.js";
import { g as i, h as a, p as o } from "./src-DI0MZP4m.js";
import { D as s, b as c, c as l, s as u } from "./chunk-7R4GIKGN-C19ZEV_b.js";
import { t as d } from "./line-DfLnhEwA.js";
import "./chunk-PU5JKC2W-CeOPBYeP.js";
import "./chunk-MX3YWQON-CVZUx3EI.js";
import "./chunk-YBOYWFTD-BAPGCoDq.js";
import "./chunk-55IACEB6-CLgZJbYv.js";
import "./chunk-KX2RTZJC-BDcxmH0D.js";
import "./chunk-PQ6SQG4A-BggLWIDB.js";
import "./chunk-KYZI473N-B9L8Kk83.js";
import "./chunk-O4XLMI2P-BlC0d_Zr.js";
import "./chunk-GLR3WWYH-ShSppUzV.js";
import { i as f, n as p, t as m } from "./chunk-NQ4KR5QH-BWRGvKed.js";
//#region node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-RAJIS63D.mjs
var h = /* @__PURE__ */ a((e) => e.append("circle").attr("class", "start-state").attr("r", c().state.sizeUnit).attr("cx", c().state.padding + c().state.sizeUnit).attr("cy", c().state.padding + c().state.sizeUnit), "drawStartState"), g = /* @__PURE__ */ a((e) => e.append("line").style("stroke", "grey").style("stroke-dasharray", "3").attr("x1", c().state.textHeight).attr("class", "divider").attr("x2", c().state.textHeight * 2).attr("y1", 0).attr("y2", 0), "drawDivider"), _ = /* @__PURE__ */ a((e, t) => {
	let n = e.append("text").attr("x", 2 * c().state.padding).attr("y", c().state.textHeight + 2 * c().state.padding).attr("font-size", c().state.fontSize).attr("class", "state-title").text(t.id), r = n.node().getBBox();
	return e.insert("rect", ":first-child").attr("x", c().state.padding).attr("y", c().state.padding).attr("width", r.width + 2 * c().state.padding).attr("height", r.height + 2 * c().state.padding).attr("rx", c().state.radius), n;
}, "drawSimpleState"), v = /* @__PURE__ */ a((e, t) => {
	let n = /* @__PURE__ */ a(function(e, t, n) {
		let r = e.append("tspan").attr("x", 2 * c().state.padding).text(t);
		n || r.attr("dy", c().state.textHeight);
	}, "addTspan"), r = e.append("text").attr("x", 2 * c().state.padding).attr("y", c().state.textHeight + 1.3 * c().state.padding).attr("font-size", c().state.fontSize).attr("class", "state-title").text(t.descriptions[0]).node().getBBox(), i = r.height, o = e.append("text").attr("x", c().state.padding).attr("y", i + c().state.padding * .4 + c().state.dividerMargin + c().state.textHeight).attr("class", "state-description"), s = !0, l = !0;
	t.descriptions.forEach(function(e) {
		s || (n(o, e, l), l = !1), s = !1;
	});
	let u = e.append("line").attr("x1", c().state.padding).attr("y1", c().state.padding + i + c().state.dividerMargin / 2).attr("y2", c().state.padding + i + c().state.dividerMargin / 2).attr("class", "descr-divider"), d = o.node().getBBox(), f = Math.max(d.width, r.width);
	return u.attr("x2", f + 3 * c().state.padding), e.insert("rect", ":first-child").attr("x", c().state.padding).attr("y", c().state.padding).attr("width", f + 2 * c().state.padding).attr("height", d.height + i + 2 * c().state.padding).attr("rx", c().state.radius), e;
}, "drawDescrState"), y = /* @__PURE__ */ a((e, t, n) => {
	let r = c().state.padding, i = 2 * c().state.padding, a = e.node().getBBox(), o = a.width, s = a.x, l = e.append("text").attr("x", 0).attr("y", c().state.titleShift).attr("font-size", c().state.fontSize).attr("class", "state-title").text(t.id), u = l.node().getBBox().width + i, d = Math.max(u, o);
	d === o && (d += i);
	let f, p = e.node().getBBox();
	t.doc, f = s - r, u > o && (f = (o - d) / 2 + r), Math.abs(s - p.x) < r && u > o && (f = s - (u - o) / 2);
	let m = 1 - c().state.textHeight;
	return e.insert("rect", ":first-child").attr("x", f).attr("y", m).attr("class", n ? "alt-composit" : "composit").attr("width", d).attr("height", p.height + c().state.textHeight + c().state.titleShift + 1).attr("rx", "0"), l.attr("x", f + r), u <= o && l.attr("x", s + (d - i) / 2 - u / 2 + r), e.insert("rect", ":first-child").attr("x", f).attr("y", c().state.titleShift - c().state.textHeight - c().state.padding).attr("width", d).attr("height", c().state.textHeight * 3).attr("rx", c().state.radius), e.insert("rect", ":first-child").attr("x", f).attr("y", c().state.titleShift - c().state.textHeight - c().state.padding).attr("width", d).attr("height", p.height + 3 + 2 * c().state.textHeight).attr("rx", c().state.radius), e;
}, "addTitleAndBox"), b = /* @__PURE__ */ a((e) => (e.append("circle").attr("class", "end-state-outer").attr("r", c().state.sizeUnit + c().state.miniPadding).attr("cx", c().state.padding + c().state.sizeUnit + c().state.miniPadding).attr("cy", c().state.padding + c().state.sizeUnit + c().state.miniPadding), e.append("circle").attr("class", "end-state-inner").attr("r", c().state.sizeUnit).attr("cx", c().state.padding + c().state.sizeUnit + 2).attr("cy", c().state.padding + c().state.sizeUnit + 2)), "drawEndState"), x = /* @__PURE__ */ a((e, t) => {
	let n = c().state.forkWidth, r = c().state.forkHeight;
	if (t.parentId) {
		let e = n;
		n = r, r = e;
	}
	return e.append("rect").style("stroke", "black").style("fill", "black").attr("width", n).attr("height", r).attr("x", c().state.padding).attr("y", c().state.padding);
}, "drawForkJoinState"), S = /* @__PURE__ */ a((e, t, n, r) => {
	let i = 0, a = r.append("text");
	a.style("text-anchor", "start"), a.attr("class", "noteText");
	let o = e.replace(/\r\n/g, "<br/>");
	o = o.replace(/\n/g, "<br/>");
	let s = o.split(u.lineBreakRegex), l = 1.25 * c().state.noteMargin;
	for (let e of s) {
		let r = e.trim();
		if (r.length > 0) {
			let e = a.append("tspan");
			if (e.text(r), l === 0) {
				let t = e.node().getBBox();
				l += t.height;
			}
			i += l, e.attr("x", t + c().state.noteMargin), e.attr("y", n + i + 1.25 * c().state.noteMargin);
		}
	}
	return {
		textWidth: a.node().getBBox().width,
		textHeight: i
	};
}, "_drawLongText"), C = /* @__PURE__ */ a((e, t) => {
	t.attr("class", "state-note");
	let n = t.append("rect").attr("x", 0).attr("y", c().state.padding), { textWidth: r, textHeight: i } = S(e, 0, 0, t.append("g"));
	return n.attr("height", i + 2 * c().state.noteMargin), n.attr("width", r + c().state.noteMargin * 2), n;
}, "drawNote"), w = /* @__PURE__ */ a(function(e, t) {
	let n = t.id, r = {
		id: n,
		label: t.id,
		width: 0,
		height: 0
	}, i = e.append("g").attr("id", n).attr("class", "stateGroup");
	t.type === "start" && h(i), t.type === "end" && b(i), (t.type === "fork" || t.type === "join") && x(i, t), t.type === "note" && C(t.note.text, i), t.type === "divider" && g(i), t.type === "default" && t.descriptions.length === 0 && _(i, t), t.type === "default" && t.descriptions.length > 0 && v(i, t);
	let a = i.node().getBBox();
	return r.width = a.width + 2 * c().state.padding, r.height = a.height + 2 * c().state.padding, r;
}, "drawState"), T = 0, E = /* @__PURE__ */ a(function(e, r, o) {
	let l = /* @__PURE__ */ a(function(e) {
		switch (e) {
			case m.relationType.AGGREGATION: return "aggregation";
			case m.relationType.EXTENSION: return "extension";
			case m.relationType.COMPOSITION: return "composition";
			case m.relationType.DEPENDENCY: return "dependency";
		}
	}, "getRelationType");
	r.points = r.points.filter((e) => !Number.isNaN(e.y));
	let f = r.points, p = d().x(function(e) {
		return e.x;
	}).y(function(e) {
		return e.y;
	}).curve(t), h = e.append("path").attr("d", p(f)).attr("id", "edge" + T).attr("class", "transition"), g = "";
	if (c().state.arrowMarkerAbsolute && (g = s(!0)), h.attr("marker-end", "url(" + g + "#" + l(m.relationType.DEPENDENCY) + "End)"), o.title !== void 0) {
		let t = e.append("g").attr("class", "stateLabel"), { x: a, y: s } = n.calcLabelPosition(r.points), l = u.getRows(o.title), d = 0, f = [], p = 0, m = 0;
		for (let e = 0; e <= l.length; e++) {
			let n = t.append("text").attr("text-anchor", "middle").text(l[e]).attr("x", a).attr("y", s + d), r = n.node().getBBox();
			p = Math.max(p, r.width), m = Math.min(m, r.x), i.info(r.x, a, s + d), d === 0 && (d = n.node().getBBox().height, i.info("Title height", d, s)), f.push(n);
		}
		let h = d * l.length;
		if (l.length > 1) {
			let e = (l.length - 1) * d * .5;
			f.forEach((t, n) => t.attr("y", s + n * d - e)), h = d * l.length;
		}
		let g = t.node().getBBox();
		t.insert("rect", ":first-child").attr("class", "box").attr("x", a - p / 2 - c().state.padding / 2).attr("y", s - h / 2 - c().state.padding / 2 - 3.5).attr("width", p + c().state.padding).attr("height", h + c().state.padding), i.info(g);
	}
	T++;
}, "drawEdge"), D, O = {}, k = /* @__PURE__ */ a(function() {}, "setConf"), A = /* @__PURE__ */ a(function(e) {
	e.append("defs").append("marker").attr("id", "dependencyEnd").attr("refX", 19).attr("refY", 7).attr("markerWidth", 20).attr("markerHeight", 28).attr("orient", "auto").append("path").attr("d", "M 19,7 L9,13 L14,7 L9,1 Z");
}, "insertMarkers"), j = /* @__PURE__ */ a(function(e, t, n, r) {
	D = c().state;
	let a = c().securityLevel, s;
	a === "sandbox" && (s = o("#i" + t));
	let u = o(a === "sandbox" ? s.nodes()[0].contentDocument.body : "body"), d = a === "sandbox" ? s.nodes()[0].contentDocument : document;
	i.debug("Rendering diagram " + e);
	let f = u.select(`[id='${t}']`);
	A(f), N(r.db.getRootDoc(), f, void 0, !1, u, d, r);
	let p = D.padding, m = f.node().getBBox(), h = m.width + p * 2, g = m.height + p * 2;
	l(f, g, h * 1.75, D.useMaxWidth), f.attr("viewBox", `${m.x - D.padding}  ${m.y - D.padding} ` + h + " " + g);
}, "draw"), M = /* @__PURE__ */ a((e) => e ? e.length * D.fontSizeFactor : 1, "getLabelWidth"), N = /* @__PURE__ */ a((t, n, a, o, s, c, l) => {
	let d = new r({
		compound: !0,
		multigraph: !0
	}), f, p = !0;
	for (f = 0; f < t.length; f++) if (t[f].stmt === "relation") {
		p = !1;
		break;
	}
	a ? d.setGraph({
		rankdir: "LR",
		multigraph: !0,
		compound: !0,
		ranker: "tight-tree",
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		isMultiGraph: !0
	}) : d.setGraph({
		rankdir: "TB",
		multigraph: !0,
		compound: !0,
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		ranker: "tight-tree",
		isMultiGraph: !0
	}), d.setDefaultEdgeLabel(function() {
		return {};
	});
	let m = l.db.getStates(), h = l.db.getRelations(), g = Object.keys(m);
	for (let e of g) {
		let t = m[e];
		a && (t.parentId = a);
		let r;
		if (t.doc) {
			let e = n.append("g").attr("id", t.id).attr("class", "stateGroup");
			r = N(t.doc, e, t.id, !o, s, c, l);
			{
				e = y(e, t, o);
				let n = e.node().getBBox();
				r.width = n.width, r.height = n.height + D.padding / 2, O[t.id] = { y: D.compositTitleSize };
			}
		} else r = w(n, t, d);
		if (t.note) {
			let e = w(n, {
				descriptions: [],
				id: t.id + "-note",
				note: t.note,
				type: "note"
			}, d);
			t.note.position === "left of" ? (d.setNode(r.id + "-note", e), d.setNode(r.id, r)) : (d.setNode(r.id, r), d.setNode(r.id + "-note", e)), d.setParent(r.id, r.id + "-group"), d.setParent(r.id + "-note", r.id + "-group");
		} else d.setNode(r.id, r);
	}
	i.debug("Count=", d.nodeCount(), d);
	let _ = 0;
	h.forEach(function(e) {
		_++, i.debug("Setting edge", e), d.setEdge(e.id1, e.id2, {
			relation: e,
			width: M(e.title),
			height: D.labelHeight * u.getRows(e.title).length,
			labelpos: "c"
		}, "id" + _);
	}), e(d), i.debug("Graph after layout", d.nodes());
	let v = n.node();
	d.nodes().forEach(function(e) {
		e !== void 0 && d.node(e) !== void 0 ? (i.warn("Node " + e + ": " + JSON.stringify(d.node(e))), s.select("#" + v.id + " #" + e).attr("transform", "translate(" + (d.node(e).x - d.node(e).width / 2) + "," + (d.node(e).y + (O[e] ? O[e].y : 0) - d.node(e).height / 2) + " )"), s.select("#" + v.id + " #" + e).attr("data-x-shift", d.node(e).x - d.node(e).width / 2), c.querySelectorAll("#" + v.id + " #" + e + " .divider").forEach((e) => {
			let t = e.parentElement, n = 0, r = 0;
			t && (t.parentElement && (n = t.parentElement.getBBox().width), r = parseInt(t.getAttribute("data-x-shift"), 10), Number.isNaN(r) && (r = 0)), e.setAttribute("x1", 0 - r + 8), e.setAttribute("x2", n - r - 8);
		})) : i.debug("No Node " + e + ": " + JSON.stringify(d.node(e)));
	});
	let b = v.getBBox();
	d.edges().forEach(function(e) {
		e !== void 0 && d.edge(e) !== void 0 && (i.debug("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(d.edge(e))), E(n, d.edge(e), d.edge(e).relation));
	}), b = v.getBBox();
	let x = {
		id: a || "root",
		label: a || "root",
		width: 0,
		height: 0
	};
	return x.width = b.width + 2 * D.padding, x.height = b.height + 2 * D.padding, i.debug("Doc rendered", x, d), x;
}, "renderDoc"), P = {
	parser: p,
	get db() {
		return new m(1);
	},
	renderer: {
		setConf: k,
		draw: j
	},
	styles: f,
	init: /* @__PURE__ */ a((e) => {
		e.state ||= {}, e.state.arrowMarkerAbsolute = e.arrowMarkerAbsolute;
	}, "init")
};
//#endregion
export { P as diagram };
