import { d as e } from "./step-CAR_1X2-.js";
import { t } from "./line-D7LDytlD.js";
import { h as n } from "./chunk-5PVQY5BW-De02jDY6.js";
import { i as r, r as i, t as a } from "./src-CiYEh6Gu.js";
import { D as o, b as s, c, s as l } from "./chunk-ICPOFSXX-BGDNDwyb.js";
import "./dist-6KEP7Sv7.js";
import "./chunk-U2HBQHQK-zQDW-w6z.js";
import "./chunk-BSJP7CBP-B_RLxeu-.js";
import "./chunk-ZZ45TVLE-DR9n48w9.js";
import { t as u } from "./graphlib-Ci0_poOu.js";
import { t as d } from "./dagre-JZb6Mrnp.js";
import "./chunk-55IACEB6-DSXI62eA.js";
import "./chunk-EDXVE4YY-D0-mRfD4.js";
import "./chunk-X2U36JSP-vovBAHWP.js";
import "./chunk-5FUZZQ4R-CJuRfR98.js";
import "./chunk-ENJZ2VHE-DJN4zRqT.js";
import "./chunk-336JU56O-C3Hg1JN3.js";
import { i as f, n as p, t as m } from "./chunk-OYMX7WX6-BU5_-8yG.js";
//#region ../../node_modules/.pnpm/mermaid@11.14.0/node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-FHFEXIEX.mjs
var h = /* @__PURE__ */ i((e) => e.append("circle").attr("class", "start-state").attr("r", s().state.sizeUnit).attr("cx", s().state.padding + s().state.sizeUnit).attr("cy", s().state.padding + s().state.sizeUnit), "drawStartState"), g = /* @__PURE__ */ i((e) => e.append("line").style("stroke", "grey").style("stroke-dasharray", "3").attr("x1", s().state.textHeight).attr("class", "divider").attr("x2", s().state.textHeight * 2).attr("y1", 0).attr("y2", 0), "drawDivider"), _ = /* @__PURE__ */ i((e, t) => {
	let n = e.append("text").attr("x", 2 * s().state.padding).attr("y", s().state.textHeight + 2 * s().state.padding).attr("font-size", s().state.fontSize).attr("class", "state-title").text(t.id), r = n.node().getBBox();
	return e.insert("rect", ":first-child").attr("x", s().state.padding).attr("y", s().state.padding).attr("width", r.width + 2 * s().state.padding).attr("height", r.height + 2 * s().state.padding).attr("rx", s().state.radius), n;
}, "drawSimpleState"), v = /* @__PURE__ */ i((e, t) => {
	let n = /* @__PURE__ */ i(function(e, t, n) {
		let r = e.append("tspan").attr("x", 2 * s().state.padding).text(t);
		n || r.attr("dy", s().state.textHeight);
	}, "addTspan"), r = e.append("text").attr("x", 2 * s().state.padding).attr("y", s().state.textHeight + 1.3 * s().state.padding).attr("font-size", s().state.fontSize).attr("class", "state-title").text(t.descriptions[0]).node().getBBox(), a = r.height, o = e.append("text").attr("x", s().state.padding).attr("y", a + s().state.padding * .4 + s().state.dividerMargin + s().state.textHeight).attr("class", "state-description"), c = !0, l = !0;
	t.descriptions.forEach(function(e) {
		c || (n(o, e, l), l = !1), c = !1;
	});
	let u = e.append("line").attr("x1", s().state.padding).attr("y1", s().state.padding + a + s().state.dividerMargin / 2).attr("y2", s().state.padding + a + s().state.dividerMargin / 2).attr("class", "descr-divider"), d = o.node().getBBox(), f = Math.max(d.width, r.width);
	return u.attr("x2", f + 3 * s().state.padding), e.insert("rect", ":first-child").attr("x", s().state.padding).attr("y", s().state.padding).attr("width", f + 2 * s().state.padding).attr("height", d.height + a + 2 * s().state.padding).attr("rx", s().state.radius), e;
}, "drawDescrState"), y = /* @__PURE__ */ i((e, t, n) => {
	let r = s().state.padding, i = 2 * s().state.padding, a = e.node().getBBox(), o = a.width, c = a.x, l = e.append("text").attr("x", 0).attr("y", s().state.titleShift).attr("font-size", s().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 = c - r, u > o && (f = (o - d) / 2 + r), Math.abs(c - p.x) < r && u > o && (f = c - (u - o) / 2);
	let m = 1 - s().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 + s().state.textHeight + s().state.titleShift + 1).attr("rx", "0"), l.attr("x", f + r), u <= o && l.attr("x", c + (d - i) / 2 - u / 2 + r), e.insert("rect", ":first-child").attr("x", f).attr("y", s().state.titleShift - s().state.textHeight - s().state.padding).attr("width", d).attr("height", s().state.textHeight * 3).attr("rx", s().state.radius), e.insert("rect", ":first-child").attr("x", f).attr("y", s().state.titleShift - s().state.textHeight - s().state.padding).attr("width", d).attr("height", p.height + 3 + 2 * s().state.textHeight).attr("rx", s().state.radius), e;
}, "addTitleAndBox"), b = /* @__PURE__ */ i((e) => (e.append("circle").attr("class", "end-state-outer").attr("r", s().state.sizeUnit + s().state.miniPadding).attr("cx", s().state.padding + s().state.sizeUnit + s().state.miniPadding).attr("cy", s().state.padding + s().state.sizeUnit + s().state.miniPadding), e.append("circle").attr("class", "end-state-inner").attr("r", s().state.sizeUnit).attr("cx", s().state.padding + s().state.sizeUnit + 2).attr("cy", s().state.padding + s().state.sizeUnit + 2)), "drawEndState"), x = /* @__PURE__ */ i((e, t) => {
	let n = s().state.forkWidth, r = s().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", s().state.padding).attr("y", s().state.padding);
}, "drawForkJoinState"), S = /* @__PURE__ */ i((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 c = o.split(l.lineBreakRegex), u = 1.25 * s().state.noteMargin;
	for (let e of c) {
		let r = e.trim();
		if (r.length > 0) {
			let e = a.append("tspan");
			if (e.text(r), u === 0) {
				let t = e.node().getBBox();
				u += t.height;
			}
			i += u, e.attr("x", t + s().state.noteMargin), e.attr("y", n + i + 1.25 * s().state.noteMargin);
		}
	}
	return {
		textWidth: a.node().getBBox().width,
		textHeight: i
	};
}, "_drawLongText"), C = /* @__PURE__ */ i((e, t) => {
	t.attr("class", "state-note");
	let n = t.append("rect").attr("x", 0).attr("y", s().state.padding), { textWidth: r, textHeight: i } = S(e, 0, 0, t.append("g"));
	return n.attr("height", i + 2 * s().state.noteMargin), n.attr("width", r + s().state.noteMargin * 2), n;
}, "drawNote"), w = /* @__PURE__ */ i(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 * s().state.padding, r.height = a.height + 2 * s().state.padding, r;
}, "drawState"), T = 0, E = /* @__PURE__ */ i(function(a, c, u) {
	let d = /* @__PURE__ */ i(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");
	c.points = c.points.filter((e) => !Number.isNaN(e.y));
	let f = c.points, p = t().x(function(e) {
		return e.x;
	}).y(function(e) {
		return e.y;
	}).curve(e), h = a.append("path").attr("d", p(f)).attr("id", "edge" + T).attr("class", "transition"), g = "";
	if (s().state.arrowMarkerAbsolute && (g = o(!0)), h.attr("marker-end", "url(" + g + "#" + d(m.relationType.DEPENDENCY) + "End)"), u.title !== void 0) {
		let e = a.append("g").attr("class", "stateLabel"), { x: t, y: i } = n.calcLabelPosition(c.points), o = l.getRows(u.title), d = 0, f = [], p = 0, m = 0;
		for (let n = 0; n <= o.length; n++) {
			let a = e.append("text").attr("text-anchor", "middle").text(o[n]).attr("x", t).attr("y", i + d), s = a.node().getBBox();
			p = Math.max(p, s.width), m = Math.min(m, s.x), r.info(s.x, t, i + d), d === 0 && (d = a.node().getBBox().height, r.info("Title height", d, i)), f.push(a);
		}
		let h = d * o.length;
		if (o.length > 1) {
			let e = (o.length - 1) * d * .5;
			f.forEach((t, n) => t.attr("y", i + n * d - e)), h = d * o.length;
		}
		let g = e.node().getBBox();
		e.insert("rect", ":first-child").attr("class", "box").attr("x", t - p / 2 - s().state.padding / 2).attr("y", i - h / 2 - s().state.padding / 2 - 3.5).attr("width", p + s().state.padding).attr("height", h + s().state.padding), r.info(g);
	}
	T++;
}, "drawEdge"), D, O = {}, k = /* @__PURE__ */ i(function() {}, "setConf"), A = /* @__PURE__ */ i(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__ */ i(function(e, t, n, i) {
	D = s().state;
	let o = s().securityLevel, l;
	o === "sandbox" && (l = a("#i" + t));
	let u = a(o === "sandbox" ? l.nodes()[0].contentDocument.body : "body"), d = o === "sandbox" ? l.nodes()[0].contentDocument : document;
	r.debug("Rendering diagram " + e);
	let f = u.select(`[id='${t}']`);
	A(f), N(i.db.getRootDoc(), f.append("g").attr("id", t + "-root"), void 0, !1, u, d, i);
	let p = D.padding, m = f.node().getBBox(), h = m.width + p * 2, g = m.height + p * 2;
	c(f, g, h * 1.75, D.useMaxWidth), f.attr("viewBox", `${m.x - D.padding}  ${m.y - D.padding} ` + h + " " + g);
}, "draw"), M = /* @__PURE__ */ i((e) => e ? e.length * D.fontSizeFactor : 1, "getLabelWidth"), N = /* @__PURE__ */ i((e, t, n, i, a, o, s) => {
	let c = new u({
		compound: !0,
		multigraph: !0
	}), f, p = !0;
	for (f = 0; f < e.length; f++) if (e[f].stmt === "relation") {
		p = !1;
		break;
	}
	n ? c.setGraph({
		rankdir: "LR",
		multigraph: !0,
		compound: !0,
		ranker: "tight-tree",
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		isMultiGraph: !0
	}) : c.setGraph({
		rankdir: "TB",
		multigraph: !0,
		compound: !0,
		ranksep: p ? 1 : D.edgeLengthFactor,
		nodeSep: p ? 1 : 50,
		ranker: "tight-tree",
		isMultiGraph: !0
	}), c.setDefaultEdgeLabel(function() {
		return {};
	});
	let m = s.db.getStates(), h = s.db.getRelations(), g = Object.keys(m);
	for (let e of g) {
		let r = m[e];
		n && (r.parentId = n);
		let l;
		if (r.doc) {
			let e = t.append("g").attr("id", r.id).attr("class", "stateGroup");
			l = N(r.doc, e, r.id, !i, a, o, s);
			{
				e = y(e, r, i);
				let t = e.node().getBBox();
				l.width = t.width, l.height = t.height + D.padding / 2, O[r.id] = { y: D.compositTitleSize };
			}
		} else l = w(t, r, c);
		if (r.note) {
			let e = w(t, {
				descriptions: [],
				id: r.id + "-note",
				note: r.note,
				type: "note"
			}, c);
			r.note.position === "left of" ? (c.setNode(l.id + "-note", e), c.setNode(l.id, l)) : (c.setNode(l.id, l), c.setNode(l.id + "-note", e)), c.setParent(l.id, l.id + "-group"), c.setParent(l.id + "-note", l.id + "-group");
		} else c.setNode(l.id, l);
	}
	r.debug("Count=", c.nodeCount(), c);
	let _ = 0;
	h.forEach(function(e) {
		_++, r.debug("Setting edge", e), c.setEdge(e.id1, e.id2, {
			relation: e,
			width: M(e.title),
			height: D.labelHeight * l.getRows(e.title).length,
			labelpos: "c"
		}, "id" + _);
	}), d(c), r.debug("Graph after layout", c.nodes());
	let v = t.node();
	c.nodes().forEach(function(e) {
		e !== void 0 && c.node(e) !== void 0 ? (r.warn("Node " + e + ": " + JSON.stringify(c.node(e))), a.select("#" + v.id + " #" + e).attr("transform", "translate(" + (c.node(e).x - c.node(e).width / 2) + "," + (c.node(e).y + (O[e] ? O[e].y : 0) - c.node(e).height / 2) + " )"), a.select("#" + v.id + " #" + e).attr("data-x-shift", c.node(e).x - c.node(e).width / 2), o.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);
		})) : r.debug("No Node " + e + ": " + JSON.stringify(c.node(e)));
	});
	let b = v.getBBox();
	c.edges().forEach(function(e) {
		e !== void 0 && c.edge(e) !== void 0 && (r.debug("Edge " + e.v + " -> " + e.w + ": " + JSON.stringify(c.edge(e))), E(t, c.edge(e), c.edge(e).relation));
	}), b = v.getBBox();
	let x = {
		id: n || "root",
		label: n || "root",
		width: 0,
		height: 0
	};
	return x.width = b.width + 2 * D.padding, x.height = b.height + 2 * D.padding, r.debug("Doc rendered", x, c), x;
}, "renderDoc"), P = {
	parser: p,
	get db() {
		return new m(1);
	},
	renderer: {
		setConf: k,
		draw: j
	},
	styles: f,
	init: /* @__PURE__ */ i((e) => {
		e.state ||= {}, e.state.arrowMarkerAbsolute = e.arrowMarkerAbsolute;
	}, "init")
};
//#endregion
export { P as diagram };
