import { w as e } from "./src-9kyTNi70.js";
import { b as t } from "./chunk-NNHCCRGN-BB1q5NkR.js";
import { t as n } from "./mermaid-parser.core-D6xVjl2t.js";
import { n as r, r as i } from "./src-DsDbTxqE.js";
import { H as a, K as o, U as s, Y as c, a as l, b as u, f as d, v as f, w as p, x as m, y as h, z as g } from "./chunk-CSCIHK7Q-C4xvUEFK.js";
import { _, i as ee, t as te } from "./chunk-5ZQYHXKU-BD_i0OiX.js";
import { t as ne } from "./chunk-4BX2VUAB-IxoWB_EX.js";
//#region node_modules/mermaid/dist/chunks/mermaid.core/diagram-KO2AKTUF.mjs
var v = "position frame", y = "frame positioned", b = "position relation", x = "relation positioned", re = /* @__PURE__ */ r(function(e) {
	i.debug("options str", e);
}, "setOptions"), ie = /* @__PURE__ */ r(function() {
	return {};
}, "getOptions"), ae = /* @__PURE__ */ r(function() {
	S(), l();
}, "clear");
function S() {
	C = {};
}
r(S, "reset");
var oe = d.eventmodeling, se = /* @__PURE__ */ r(() => ee({
	...oe,
	...u().eventmodeling
}), "getConfig"), C = {};
function w() {
	let e = ce, { ast: t } = C, n = D();
	if (!t) throw Error("No data for EventModel");
	return t.frames.forEach((r, a) => {
		let o = P(r, t.dataEntities, n);
		e = J(e, {
			$kind: v,
			index: a,
			frame: r,
			textProps: o
		});
		let s;
		V(r) ? (i.debug("source frame", r.sourceFrames), s = t.frames.filter((e) => r.sourceFrames.some((t) => t.$refText === e.name)), s.forEach((t) => {
			e = J(e, {
				$kind: b,
				index: a,
				frame: r,
				sourceFrame: t
			});
		})) : e = J(e, {
			$kind: b,
			index: a,
			frame: r
		});
	}), e = {
		...e,
		sortedSwimlanesArray: R(e.swimlanes)
	}, e;
}
r(w, "getState");
function T(e) {
	C.ast = e;
}
r(T, "setAst");
var E = {
	swimlaneMinHeight: 70,
	swimlanePadding: 15,
	swimlaneGap: 10,
	boxPadding: 10,
	boxOverlap: 90,
	boxDefaultY: 0,
	boxMinWidth: 80,
	boxMaxWidth: 450,
	boxMinHeight: 80,
	boxMaxHeight: 750,
	contentStartX: 250,
	textMaxWidth: 430,
	boxTextFontWeight: "bold",
	boxTextPadding: 10,
	swimlaneTextFontWeight: "bold",
	labelUiAutomation: "UI/Automation",
	labelUiAutomationPrefix: "UI/A: ",
	labelCommandReadModel: "Command/Read Model",
	labelCommandReadModelPrefix: "C/RM: ",
	labelEvents: "Events",
	labelEventsPrefix: "Stream: "
};
function D() {
	return E;
}
r(D, "getDiagramProps");
var ce = {
	boxes: [],
	swimlanes: {},
	relations: [],
	maxR: 0,
	sortedSwimlanesArray: []
};
function O(e) {
	let t = e.split(".");
	if (t.length === 2) return t[0];
}
r(O, "extractNamespace");
function k(e) {
	let t = e.split(".");
	return t.length === 2 ? t[1] : e;
}
r(k, "extractName");
function A(e, t) {
	if (!(!t || t.length === 0)) return Object.values(e).find((e) => e.namespace === t);
}
r(A, "findSwimlaneByNamespace");
function j(e, t, n) {
	return Math.max(t, ...Object.keys(e).filter((e) => {
		let r = Number.parseInt(e);
		return r > t && r < n;
	}).map((e) => Number.parseInt(e))) + 1;
}
r(j, "findNextAvailableIndex");
function M(e, t) {
	let n = O(e.entityIdentifier), r = A(t, n);
	switch (e.modelEntityType) {
		case "ui":
		case "pcr":
		case "processor": return r ? {
			index: r.index,
			label: r.namespace || E.labelUiAutomation
		} : n ? {
			index: j(t, 0, 100),
			label: E.labelUiAutomationPrefix + n
		} : {
			index: 0,
			label: E.labelUiAutomation
		};
		case "rmo":
		case "readmodel":
		case "cmd":
		case "command": return r ? {
			index: r.index,
			label: r.namespace || E.labelCommandReadModel
		} : n ? {
			index: j(t, 100, 200),
			label: E.labelCommandReadModelPrefix + n
		} : {
			index: 100,
			label: E.labelCommandReadModel
		};
		default: return r ? {
			index: r.index,
			label: r.namespace || E.labelEvents
		} : n ? {
			index: j(t, 200, 300),
			label: E.labelEventsPrefix + n
		} : {
			index: 200,
			label: E.labelEvents
		};
	}
}
r(M, "calculateSwimlaneProps");
function N(e) {
	let { themeVariables: t } = u();
	switch (e.modelEntityType) {
		case "ui": return {
			fill: t.emUiFill ?? "white",
			stroke: t.emUiStroke ?? "#dbdada"
		};
		case "pcr":
		case "processor": return {
			fill: t.emProcessorFill ?? "#edb3f6",
			stroke: t.emProcessorStroke ?? "#b88cbf"
		};
		case "rmo":
		case "readmodel": return {
			fill: t.emReadModelFill ?? "#d3f1a2",
			stroke: t.emReadModelStroke ?? "#a3b732"
		};
		case "cmd":
		case "command": return {
			fill: t.emCommandFill ?? "#bcd6fe",
			stroke: t.emCommandStroke ?? "#679ac3"
		};
		case "evt":
		case "event": return {
			fill: t.emEventFill ?? "#ffb778",
			stroke: t.emEventStroke ?? "#c19a0f"
		};
		default: return {
			fill: "red",
			stroke: "black"
		};
	}
}
r(N, "calculateEntityVisualProps");
function P(e, t, n) {
	let r = u(), a = g(k(e.entityIdentifier) ?? "", r), o, s = {
		fontSize: 16,
		fontWeight: 700,
		fontFamily: "\"trebuchet ms\", verdana, arial, sans-serif",
		joinWith: "<br/>"
	}, c = `<b>${_(a, n.textMaxWidth, s)}</b>`;
	if (e.dataInlineValue && (o = e.dataInlineValue, o = o.substring(o.indexOf("{") + 1), o = o.substring(0, o.lastIndexOf("}") - 1), o = g(o, r), o = _(o, n.textMaxWidth, s), o = o.replaceAll(" ", "&nbsp;")), e.dataReference) {
		let i = t.find((t) => t.name === e.dataReference?.$refText);
		i && (o = i.dataBlockValue, o = o.substring(o.indexOf("{\n") + 2), o = o.substring(0, o.lastIndexOf("}") - 1), o = g(o, r), o = _(o, n.textMaxWidth, s), o = o.replaceAll(" ", "&nbsp;"), o += "<br/>");
	}
	let l = o !== void 0;
	l && (c += `<br/><br/><code style="text-align: left; display: block;max-width:${n.textMaxWidth}px">${o}</code>`);
	let d = {
		fontSize: s.fontSize,
		fontWeight: s.fontWeight,
		fontFamily: s.fontFamily
	}, f = te(c, d), p = l ? f.width / 3 : f.width, m = {
		content: c,
		width: p,
		height: f.height
	};
	return i.debug(`[${e.name}] ${e.entityIdentifier} text`, m), m;
}
r(P, "calculateTextProps");
function F(e, t) {
	let n = t, r = N(n.frame), i = {
		width: n.textProps.width + 2 * E.boxTextPadding,
		height: n.textProps.height + 2 * E.boxTextPadding
	};
	return [{
		$kind: y,
		frame: n.frame,
		index: n.index,
		visual: r,
		dimension: i,
		textProps: n.textProps
	}];
}
r(F, "decidePositionFrame");
function I(e, t, n) {
	return t === void 0 ? E.contentStartX : t.index === e.index && e.r ? e.r + E.boxPadding : n === void 0 ? E.contentStartX : n.r - E.boxOverlap + E.boxPadding;
}
r(I, "calculateX");
function L(e, t) {
	let n = [...e.map((e) => e.r), t];
	return Math.max(...n);
}
r(L, "calculateMaxRight");
function R(e) {
	return Object.values(e).sort((e, t) => e.index - t.index);
}
r(R, "sortedSwimlanesArray");
function z(e, t) {
	let n = t, r = M(n.frame, e.swimlanes), i;
	i = r.index in e.swimlanes ? e.swimlanes[r.index] : {
		index: r.index,
		label: r.label,
		r: 0,
		y: r.index * E.swimlaneMinHeight + E.swimlaneGap,
		height: E.swimlaneMinHeight,
		maxHeight: E.swimlaneMinHeight
	};
	let a = e.boxes.length > 0 ? e.boxes[e.boxes.length - 1] : void 0, o = e.previousSwimlaneNumber === void 0 ? void 0 : e.swimlanes[e.previousSwimlaneNumber], s = {
		width: Math.max(E.boxMinWidth, Math.min(E.boxMaxWidth, n.dimension.width)) + 2 * E.boxPadding,
		height: Math.max(E.boxMinHeight, Math.min(E.boxMaxHeight, n.dimension.height)) + 2 * E.boxPadding
	}, c = I(i, o, a), l = c + s.width + E.boxPadding, u = L(Object.values(e.swimlanes), l);
	i.r = c + s.width, i.maxHeight = Math.max(i.maxHeight, s.height), i.height = Math.max(E.swimlaneMinHeight, i.maxHeight) + 2 * E.swimlanePadding;
	let d = {
		x: c,
		y: E.swimlanePadding + i.y,
		r: l,
		dimension: s,
		leftSibling: !1,
		swimlane: i,
		visual: n.visual,
		text: n.textProps.content,
		frame: n.frame,
		index: n.index
	}, f = {
		...e,
		boxes: [...e.boxes, d],
		swimlanes: {
			...e.swimlanes,
			[`${i.index}`]: i
		},
		previousSwimlaneNumber: r.index,
		previousFrame: n.frame,
		maxR: u
	}, p = R(f.swimlanes);
	p.length > 0 && (p[0].y = 0);
	for (let e = 1; e < p.length; e++) {
		let t = p[e], n = p[e - 1];
		t.y = n.y + n.height + E.swimlaneGap;
	}
	return f;
}
r(z, "evolveFramePositioned");
function B(e, t) {
	return e === 0 && t.sourceFrames.length === 0;
}
r(B, "isFirstFrame");
function V(e) {
	return e.sourceFrames !== void 0 && e.sourceFrames !== null && e.sourceFrames.length > 0;
}
r(V, "hasSourceFrame");
function H(e, t) {
	if (t != null) return e.find((e) => e.frame.name === t.name);
}
r(H, "findBoxByFrame");
function U(e, t, n) {
	if (!(n < 0)) for (let r = n; r >= 0; r--) {
		let n = e[r];
		if (n.swimlane.index !== t) return n;
	}
}
r(U, "findBoxByLineIndex");
function W(e, n) {
	let r = n;
	if (t(r.frame) || B(r.index, r.frame)) return [];
	let i = H(e.boxes, r.frame);
	if (i === void 0) throw Error(`Target box not found for frame ${r.frame.name}`);
	let a;
	return a = r.sourceFrame ? H(e.boxes, r.sourceFrame) : U(e.boxes, i.swimlane.index, r.index - 1), a === void 0 ? [] : [{
		$kind: x,
		frame: r.frame,
		index: r.index,
		sourceBox: a,
		targetBox: i
	}];
}
r(W, "decidePositionRelation");
function G(e, t) {
	let n = t, r = {
		visual: {
			fill: "none",
			stroke: "#000"
		},
		source: {
			x: n.sourceBox.x,
			y: n.sourceBox.y
		},
		target: {
			x: n.targetBox.x,
			y: n.targetBox.y
		},
		sourceBox: n.sourceBox,
		targetBox: n.targetBox
	};
	return {
		...e,
		relations: [...e.relations, r]
	};
}
r(G, "evolveRelationPositioned");
var le = {
	[v]: F,
	[b]: W
}, ue = {
	[y]: z,
	[x]: G
};
function K(e, t) {
	let n = le[t.$kind];
	if (n == null) return [];
	let r = n(e, t);
	return i.debug("decided events", r), r;
}
r(K, "decide");
function q(e, t) {
	let n = t.reduce((e, t) => {
		let n = ue[t.$kind];
		return n == null ? e : n(e, t);
	}, e);
	return i.debug("evolve events", {
		state: e,
		newState: n,
		events: t
	}), n;
}
r(q, "evolve");
function J(e, t) {
	return q(e, K(e, t));
}
r(J, "dispatch");
var Y = {
	getConfig: se,
	setOptions: re,
	getOptions: ie,
	clear: ae,
	setAccTitle: s,
	getAccTitle: h,
	getAccDescription: f,
	setAccDescription: a,
	setDiagramTitle: o,
	getDiagramTitle: p,
	setAst: T,
	getDiagramProps: D,
	getState: w
}, de = { parse: /* @__PURE__ */ r(async (e) => {
	let t = await n("eventmodeling", e);
	i.debug(t), Y.setAst(t), ne(t, Y);
}, "parse") }, fe = m()?.eventmodeling;
function X(e, t) {
	return (n) => {
		let r = n.swimlane.y + t.swimlanePadding, i = e.append("g").attr("class", "em-box");
		i.append("rect").attr("x", n.x).attr("y", r).attr("rx", "3").attr("width", n.dimension.width).attr("height", n.dimension.height).attr("stroke", n.visual.stroke).attr("fill", n.visual.fill), i.append("foreignObject").attr("x", n.x + t.boxPadding).attr("y", r + 10).attr("width", n.dimension.width - 2 * t.boxPadding).attr("height", n.dimension.height - 2 * t.boxPadding).append("xhtml:div").style("display", "table").style("height", "100%").style("width", "100%").append("span").style("display", "table-cell").style("text-align", "center").style("vertical-align", "middle").html(n.text);
	};
}
r(X, "renderD3Box");
function Z(e, t) {
	return e > t;
}
r(Z, "dirUpwards");
function Q(e, t, n, r) {
	return (a) => {
		let o = a.sourceBox.swimlane.y + t.swimlanePadding, s = a.targetBox.swimlane.y + t.swimlanePadding, c = Z(o, s), l = a.sourceBox.x + a.sourceBox.dimension.width * 2 / 3, u = a.targetBox.x + a.targetBox.dimension.width / 3, d, f;
		i.debug(`rendering relation up=${c} for `, {
			sourceBox: a.sourceBox,
			targetBox: a.targetBox
		}), c ? (d = o, f = s + a.targetBox.dimension.height) : (d = o + a.sourceBox.dimension.height, f = s);
		let p = r.emRelationStroke ?? a.visual.stroke;
		e.append("path").attr("class", "em-relation").attr("fill", a.visual.fill).attr("stroke", p).attr("stroke-width", "1").attr("marker-end", `url(#${n})`).attr("d", `M${l} ${d} L${u} ${f}`);
	};
}
r(Q, "renderD3Relation");
function $(e, t, n, r) {
	return (i) => {
		let a = e.append("g").attr("class", "em-swimlane"), o = r.emSwimlaneBackgroundOdd ?? "rgb(250,250,250)", s = r.emSwimlaneBackgroundStroke ?? "rgb(240,240,240)";
		a.append("rect").attr("x", 0).attr("y", i.y).attr("rx", "3").attr("width", t + n.swimlanePadding).attr("height", i.height).attr("fill", o).attr("stroke", s), a.append("text").attr("font-weight", n.swimlaneTextFontWeight).attr("x", 30).attr("y", i.y + 30).text(i.label);
	};
}
r($, "renderD3Swimlane");
var pe = {
	parser: de,
	db: Y,
	renderer: { draw: /* @__PURE__ */ r(function(t, n, r, a) {
		if (i.debug("in eventmodeling renderer", t + "\n", "id:", n, r), !fe) throw Error("EventModeling config not found");
		let o = a.db, { themeVariables: s, eventmodeling: l } = m(), u = e(`[id="${n}"]`), d = o.getDiagramProps(), f = o.getState(), p = `em-arrowhead-${n}`, h = s.emArrowhead ?? "#000000";
		f.sortedSwimlanesArray.forEach($(u, f.maxR, d, s)), f.boxes.forEach(X(u, d)), f.relations.forEach(Q(u, d, p, s)), u.append("defs").append("marker").attr("id", p).attr("markerWidth", "10").attr("markerHeight", "7").attr("refX", "10").attr("refY", "3.5").attr("orient", "auto").append("polygon").attr("points", "0 0, 10 3.5, 0 7").attr("fill", h), c(void 0, u, l?.padding ?? 30, l?.useMaxWidth);
	}, "draw") },
	styles: /* @__PURE__ */ r((e) => "", "getStyles")
};
//#endregion
export { pe as diagram };

//# sourceMappingURL=diagram-KO2AKTUF-D6IGOcZR.js.map