import { w as e } from "./src-9kyTNi70.js";
import { n as t, r as n } from "./src-DsDbTxqE.js";
import { O as r, c as i, s as a, x as o } from "./chunk-CSCIHK7Q-C4xvUEFK.js";
import { et as s, g as c } from "./chunk-5ZQYHXKU-BD_i0OiX.js";
import { t as l } from "./line-DNk5Q4Hr.js";
import "./chunk-O5CBEL6O-BiQWlWIi.js";
import "./chunk-BSJP7CBP-Y4RvC_3X.js";
import "./chunk-L5ZTLDWV-jNHhGxZV.js";
import { t as u } from "./graphlib-VMWSbyYi.js";
import { t as d } from "./dagre-3-RnF0EK.js";
import "./chunk-55IACEB6-BpIr1sIL.js";
import "./chunk-2J33WTMH-B3cYBZRx.js";
import "./chunk-NZK2D7GU-qBKLQFVS.js";
import "./chunk-3OPIFGDE-BK8q8aNY.js";
import "./chunk-KSCS5N6A-BJWFOkTk.js";
import "./chunk-LZXEDZCA-DEwnX69d.js";
import { i as f, n as p, t as m } from "./chunk-AQP2D5EJ-CB56zi8m.js";
//#region node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-AJRCARHV.mjs
var h = /* @__PURE__ */ t((e) => e.append("circle").attr("class", "start-state").attr("r", o().state.sizeUnit).attr("cx", o().state.padding + o().state.sizeUnit).attr("cy", o().state.padding + o().state.sizeUnit), "drawStartState"), g = /* @__PURE__ */ t((e) => e.append("line").style("stroke", "grey").style("stroke-dasharray", "3").attr("x1", o().state.textHeight).attr("class", "divider").attr("x2", o().state.textHeight * 2).attr("y1", 0).attr("y2", 0), "drawDivider"), _ = /* @__PURE__ */ t((e, t) => {
	let n = e.append("text").attr("x", 2 * o().state.padding).attr("y", o().state.textHeight + 2 * o().state.padding).attr("font-size", o().state.fontSize).attr("class", "state-title").text(t.id), r = n.node().getBBox();
	return e.insert("rect", ":first-child").attr("x", o().state.padding).attr("y", o().state.padding).attr("width", r.width + 2 * o().state.padding).attr("height", r.height + 2 * o().state.padding).attr("rx", o().state.radius), n;
}, "drawSimpleState"), v = /* @__PURE__ */ t((e, n) => {
	let r = /* @__PURE__ */ t(function(e, t, n) {
		let r = e.append("tspan").attr("x", 2 * o().state.padding).text(t);
		n || r.attr("dy", o().state.textHeight);
	}, "addTspan"), i = e.append("text").attr("x", 2 * o().state.padding).attr("y", o().state.textHeight + 1.3 * o().state.padding).attr("font-size", o().state.fontSize).attr("class", "state-title").text(n.descriptions[0]).node().getBBox(), a = i.height, s = e.append("text").attr("x", o().state.padding).attr("y", a + o().state.padding * .4 + o().state.dividerMargin + o().state.textHeight).attr("class", "state-description"), c = !0, l = !0;
	n.descriptions.forEach(function(e) {
		c || (r(s, e, l), l = !1), c = !1;
	});
	let u = e.append("line").attr("x1", o().state.padding).attr("y1", o().state.padding + a + o().state.dividerMargin / 2).attr("y2", o().state.padding + a + o().state.dividerMargin / 2).attr("class", "descr-divider"), d = s.node().getBBox(), f = Math.max(d.width, i.width);
	return u.attr("x2", f + 3 * o().state.padding), e.insert("rect", ":first-child").attr("x", o().state.padding).attr("y", o().state.padding).attr("width", f + 2 * o().state.padding).attr("height", d.height + a + 2 * o().state.padding).attr("rx", o().state.radius), e;
}, "drawDescrState"), y = /* @__PURE__ */ t((e, t, n) => {
	let r = o().state.padding, i = 2 * o().state.padding, a = e.node().getBBox(), s = a.width, c = a.x, l = e.append("text").attr("x", 0).attr("y", o().state.titleShift).attr("font-size", o().state.fontSize).attr("class", "state-title").text(t.id), u = l.node().getBBox().width + i, d = Math.max(u, s);
	d === s && (d += i);
	let f, p = e.node().getBBox();
	t.doc, f = c - r, u > s && (f = (s - d) / 2 + r), Math.abs(c - p.x) < r && u > s && (f = c - (u - s) / 2);
	let m = 1 - o().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 + o().state.textHeight + o().state.titleShift + 1).attr("rx", "0"), l.attr("x", f + r), u <= s && l.attr("x", c + (d - i) / 2 - u / 2 + r), e.insert("rect", ":first-child").attr("x", f).attr("y", o().state.titleShift - o().state.textHeight - o().state.padding).attr("width", d).attr("height", o().state.textHeight * 3).attr("rx", o().state.radius), e.insert("rect", ":first-child").attr("x", f).attr("y", o().state.titleShift - o().state.textHeight - o().state.padding).attr("width", d).attr("height", p.height + 3 + 2 * o().state.textHeight).attr("rx", o().state.radius), e;
}, "addTitleAndBox"), b = /* @__PURE__ */ t((e) => (e.append("circle").attr("class", "end-state-outer").attr("r", o().state.sizeUnit + o().state.miniPadding).attr("cx", o().state.padding + o().state.sizeUnit + o().state.miniPadding).attr("cy", o().state.padding + o().state.sizeUnit + o().state.miniPadding), e.append("circle").attr("class", "end-state-inner").attr("r", o().state.sizeUnit).attr("cx", o().state.padding + o().state.sizeUnit + 2).attr("cy", o().state.padding + o().state.sizeUnit + 2)), "drawEndState"), x = /* @__PURE__ */ t((e, t) => {
	let n = o().state.forkWidth, r = o().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", o().state.padding).attr("y", o().state.padding);
}, "drawForkJoinState"), S = /* @__PURE__ */ t((e, t, n, r) => {
	let i = 0, s = r.append("text");
	s.style("text-anchor", "start"), s.attr("class", "noteText");
	let c = e.replace(/\r\n/g, "<br/>");
	c = c.replace(/\n/g, "<br/>");
	let l = c.split(a.lineBreakRegex), u = 1.25 * o().state.noteMargin;
	for (let e of l) {
		let r = e.trim();
		if (r.length > 0) {
			let e = s.append("tspan");
			if (e.text(r), u === 0) {
				let t = e.node().getBBox();
				u += t.height;
			}
			i += u, e.attr("x", t + o().state.noteMargin), e.attr("y", n + i + 1.25 * o().state.noteMargin);
		}
	}
	return {
		textWidth: s.node().getBBox().width,
		textHeight: i
	};
}, "_drawLongText"), C = /* @__PURE__ */ t((e, t) => {
	t.attr("class", "state-note");
	let n = t.append("rect").attr("x", 0).attr("y", o().state.padding), { textWidth: r, textHeight: i } = S(e, 0, 0, t.append("g"));
	return n.attr("height", i + 2 * o().state.noteMargin), n.attr("width", r + o().state.noteMargin * 2), n;
}, "drawNote"), w = /* @__PURE__ */ t(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 * o().state.padding, r.height = a.height + 2 * o().state.padding, r;
}, "drawState"), T = 0, E = /* @__PURE__ */ t(function(e, i, u) {
	let d = /* @__PURE__ */ t(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");
	i.points = i.points.filter((e) => !Number.isNaN(e.y));
	let f = i.points, p = l().x(function(e) {
		return e.x;
	}).y(function(e) {
		return e.y;
	}).curve(s), h = e.append("path").attr("d", p(f)).attr("id", "edge" + T).attr("class", "transition"), g = "";
	if (o().state.arrowMarkerAbsolute && (g = r(!0)), h.attr("marker-end", "url(" + g + "#" + d(m.relationType.DEPENDENCY) + "End)"), u.title !== void 0) {
		let t = e.append("g").attr("class", "stateLabel"), { x: r, y: s } = c.calcLabelPosition(i.points), l = a.getRows(u.title), d = 0, f = [], p = 0, m = 0;
		for (let e = 0; e <= l.length; e++) {
			let i = t.append("text").attr("text-anchor", "middle").text(l[e]).attr("x", r).attr("y", s + d), a = i.node().getBBox();
			p = Math.max(p, a.width), m = Math.min(m, a.x), n.info(a.x, r, s + d), d === 0 && (d = i.node().getBBox().height, n.info("Title height", d, s)), f.push(i);
		}
		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", r - p / 2 - o().state.padding / 2).attr("y", s - h / 2 - o().state.padding / 2 - 3.5).attr("width", p + o().state.padding).attr("height", h + o().state.padding), n.info(g);
	}
	T++;
}, "drawEdge"), D, O = {}, k = /* @__PURE__ */ t(function() {}, "setConf"), A = /* @__PURE__ */ t(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__ */ t(function(t, r, a, s) {
	D = o().state;
	let c = o().securityLevel, l;
	c === "sandbox" && (l = e("#i" + r));
	let u = e(c === "sandbox" ? l.nodes()[0].contentDocument.body : "body"), d = c === "sandbox" ? l.nodes()[0].contentDocument : document;
	n.debug("Rendering diagram " + t);
	let f = u.select(`[id='${r}']`);
	A(f), N(s.db.getRootDoc(), f.append("g").attr("id", r + "-root"), void 0, !1, u, d, s);
	let p = D.padding, m = f.node().getBBox(), h = m.width + p * 2, g = m.height + p * 2;
	i(f, g, h * 1.75, D.useMaxWidth), f.attr("viewBox", `${m.x - D.padding}  ${m.y - D.padding} ` + h + " " + g);
}, "draw"), M = /* @__PURE__ */ t((e) => e ? e.length * D.fontSizeFactor : 1, "getLabelWidth"), N = /* @__PURE__ */ t((e, t, r, i, o, s, c) => {
	let l = new u({
		compound: !0,
		multigraph: !0
	}), f, p = !0;
	for (f = 0; f < e.length; f++) if (e[f].stmt === "relation") {
		p = !1;
		break;
	}
	r ? l.setGraph({
		rankdir: "LR",
		multigraph: !0,
		compound: !0,
		ranker: "tight-tree",
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		isMultiGraph: !0
	}) : l.setGraph({
		rankdir: "TB",
		multigraph: !0,
		compound: !0,
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		ranker: "tight-tree",
		isMultiGraph: !0
	}), l.setDefaultEdgeLabel(function() {
		return {};
	});
	let m = c.db.getStates(), h = c.db.getRelations(), g = Object.keys(m);
	for (let e of g) {
		let n = m[e];
		r && (n.parentId = r);
		let a;
		if (n.doc) {
			let e = t.append("g").attr("id", n.id).attr("class", "stateGroup");
			a = N(n.doc, e, n.id, !i, o, s, c);
			{
				e = y(e, n, i);
				let t = e.node().getBBox();
				a.width = t.width, a.height = t.height + D.padding / 2, O[n.id] = { y: D.compositTitleSize };
			}
		} else a = w(t, n, l);
		if (n.note) {
			let e = w(t, {
				descriptions: [],
				id: n.id + "-note",
				note: n.note,
				type: "note"
			}, l);
			n.note.position === "left of" ? (l.setNode(a.id + "-note", e), l.setNode(a.id, a)) : (l.setNode(a.id, a), l.setNode(a.id + "-note", e)), l.setParent(a.id, a.id + "-group"), l.setParent(a.id + "-note", a.id + "-group");
		} else l.setNode(a.id, a);
	}
	n.debug("Count=", l.nodeCount(), l);
	let _ = 0;
	h.forEach(function(e) {
		_++, n.debug("Setting edge", e), l.setEdge(e.id1, e.id2, {
			relation: e,
			width: M(e.title),
			height: D.labelHeight * a.getRows(e.title).length,
			labelpos: "c"
		}, "id" + _);
	}), d(l), n.debug("Graph after layout", l.nodes());
	let v = t.node();
	l.nodes().forEach(function(e) {
		e !== void 0 && l.node(e) !== void 0 ? (n.warn("Node " + e + ": " + JSON.stringify(l.node(e))), o.select("#" + v.id + " #" + e).attr("transform", "translate(" + (l.node(e).x - l.node(e).width / 2) + "," + (l.node(e).y + (O[e] ? O[e].y : 0) - l.node(e).height / 2) + " )"), o.select("#" + v.id + " #" + e).attr("data-x-shift", l.node(e).x - l.node(e).width / 2), s.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);
		})) : n.debug("No Node " + e + ": " + JSON.stringify(l.node(e)));
	});
	let b = v.getBBox();
	l.edges().forEach(function(e) {
		e !== void 0 && l.edge(e) !== void 0 && (n.debug("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(l.edge(e))), E(t, l.edge(e), l.edge(e).relation));
	}), b = v.getBBox();
	let x = {
		id: r || "root",
		label: r || "root",
		width: 0,
		height: 0
	};
	return x.width = b.width + 2 * D.padding, x.height = b.height + 2 * D.padding, n.debug("Doc rendered", x, l), x;
}, "renderDoc"), P = {
	parser: p,
	get db() {
		return new m(1);
	},
	renderer: {
		setConf: k,
		draw: j
	},
	styles: f,
	init: /* @__PURE__ */ t((e) => {
		e.state ||= {}, e.state.arrowMarkerAbsolute = e.arrowMarkerAbsolute;
	}, "init")
};
//#endregion
export { P as diagram };

//# sourceMappingURL=stateDiagram-AJRCARHV-_9kgzyIF.js.map