import { __name as e, log as t } from "./chunk-AGHRB4JF.js";
import { clear as n, configureSvgSize as r, getAccDescription as i, getAccTitle as a, getConfig2 as o, getDiagramTitle as s, sanitizeText as c, setAccDescription as l, setAccTitle as u, setDiagramTitle as d } from "./chunk-ICPOFSXX.js";
import { selectSvgElement as f } from "./chunk-426QAEUC.js";
import { populateCommonDb as p } from "./chunk-4BX2VUAB.js";
import { parse as m } from "../../../../@mermaid-js/parser/dist/mermaid-parser.core.js";
//#region ../../node_modules/mermaid/dist/chunks/mermaid.core/wardleyDiagram-NUSXRM2D.mjs
var h = /* @__PURE__ */ e((e, t) => {
	let n = e <= 1 ? e * 100 : e;
	if (n < 0 || n > 100) throw Error(`${t} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${e}`);
	return n;
}, "toPercent"), g = /* @__PURE__ */ e((e, t, n) => ({
	x: h(t, `${n} evolution`),
	y: h(e, `${n} visibility`)
}), "toCoordinates"), _ = /* @__PURE__ */ e((e) => {
	if (e) {
		if (e === "+<>") return "bidirectional";
		if (e === "+<") return "backward";
		if (e === "+>") return "forward";
	}
}, "getFlowFromPort"), v = /* @__PURE__ */ e((e) => {
	if (!e?.startsWith("+")) return {};
	let t = /^\+'([^']*)'/.exec(e)?.[1];
	return e.includes("<>") ? {
		flow: "bidirectional",
		label: t
	} : e.includes("<") ? {
		flow: "backward",
		label: t
	} : e.includes(">") ? {
		flow: "forward",
		label: t
	} : { label: t };
}, "extractFlowFromArrow"), y = /* @__PURE__ */ e((e, t) => {
	if (p(e, t), e.size && t.setSize(e.size.width, e.size.height), e.evolution) {
		let n = e.evolution.stages.map((e) => e.secondName ? `${e.name.trim()} / ${e.secondName.trim()}` : e.name.trim()), r = e.evolution.stages.filter((e) => e.boundary !== void 0).map((e) => e.boundary);
		t.updateAxes({
			stages: n,
			stageBoundaries: r
		});
	}
	if (e.anchors.forEach((e) => {
		let n = g(e.visibility, e.evolution, `Anchor "${e.name}"`);
		t.addNode(e.name, e.name, n.x, n.y, "anchor");
	}), e.components.forEach((e) => {
		let n = g(e.visibility, e.evolution, `Component "${e.name}"`), r = e.label ? (e.label.negX ? -1 : 1) * e.label.offsetX : void 0, i = e.label ? (e.label.negY ? -1 : 1) * e.label.offsetY : void 0, a = e.decorator?.strategy;
		t.addNode(e.name, e.name, n.x, n.y, "component", r, i, e.inertia, a);
	}), e.notes.forEach((e) => {
		let n = g(e.visibility, e.evolution, `Note "${e.text}"`);
		t.addNote(e.text, n.x, n.y);
	}), e.pipelines.forEach((e) => {
		let n = t.getNode(e.parent);
		if (!n || typeof n.y != "number") throw Error(`Pipeline "${e.parent}" must reference an existing component with coordinates.`);
		let r = n.y;
		t.startPipeline(e.parent), e.components.forEach((n) => {
			let i = `${e.parent}_${n.name}`, a = n.label ? (n.label.negX ? -1 : 1) * n.label.offsetX : void 0, o = n.label ? (n.label.negY ? -1 : 1) * n.label.offsetY : void 0, s = h(n.evolution, `Pipeline component "${n.name}" evolution`);
			t.addNode(i, n.name, s, r, "pipeline-component", a, o), t.addPipelineComponent(e.parent, i);
		});
	}), e.links.forEach((e) => {
		let n = !!e.arrow && (e.arrow.includes("-.->") || e.arrow.includes(".-.")), r = _(e.fromPort) ?? _(e.toPort), { flow: i, label: a } = v(e.arrow);
		!r && i && (r = i);
		let o = e.linkLabel, s = a ?? o;
		t.addLink(e.from, e.to, n, s, r);
	}), e.evolves.forEach((e) => {
		let n = t.getNode(e.component);
		if (n?.y !== void 0) {
			let r = h(e.target, `Evolve target for "${e.component}"`);
			t.addTrend(e.component, r, n.y);
		}
	}), e.annotations.length > 0) {
		let n = e.annotations[0], r = g(n.x, n.y, "Annotations box");
		t.setAnnotationsBox(r.x, r.y);
	}
	e.annotation.forEach((e) => {
		let n = g(e.x, e.y, `Annotation ${e.number}`);
		t.addAnnotation(e.number, [{
			x: n.x,
			y: n.y
		}], e.text);
	}), e.accelerators.forEach((e) => {
		let n = g(e.x, e.y, `Accelerator "${e.name}"`);
		t.addAccelerator(e.name, n.x, n.y);
	}), e.deaccelerators.forEach((e) => {
		let n = g(e.x, e.y, `Deaccelerator "${e.name}"`);
		t.addDeaccelerator(e.name, n.x, n.y);
	});
}, "populateDb"), b = {
	parser: { yy: void 0 },
	parse: /* @__PURE__ */ e(async (e) => {
		let n = await m("wardley", e);
		t.debug(n);
		let r = b.parser?.yy;
		if (!r || typeof r.addNode != "function") throw Error("parser.parser?.yy was not a WardleyDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");
		y(n, r);
	}, "parse")
}, x = new class {
	constructor() {
		this.nodes = /* @__PURE__ */ new Map(), this.links = [], this.trends = /* @__PURE__ */ new Map(), this.pipelines = /* @__PURE__ */ new Map(), this.annotations = [], this.notes = [], this.accelerators = [], this.deaccelerators = [], this.axes = {};
	}
	static {
		e(this, "WardleyBuilder");
	}
	addNode(e) {
		let t = this.nodes.get(e.id) ?? {
			id: e.id,
			label: e.label
		}, n = {
			...t,
			...e,
			className: e.className ?? t.className,
			labelOffsetX: e.labelOffsetX ?? t.labelOffsetX,
			labelOffsetY: e.labelOffsetY ?? t.labelOffsetY
		};
		this.nodes.set(e.id, n);
	}
	addLink(e) {
		this.links.push(e);
	}
	addTrend(e) {
		this.trends.set(e.nodeId, e);
	}
	startPipeline(e) {
		this.pipelines.set(e, {
			nodeId: e,
			componentIds: []
		});
		let t = this.nodes.get(e);
		t && (t.isPipelineParent = !0);
	}
	addPipelineComponent(e, t) {
		let n = this.pipelines.get(e);
		n && n.componentIds.push(t);
		let r = this.nodes.get(t);
		r && (r.inPipeline = !0);
	}
	addAnnotation(e) {
		this.annotations.push(e);
	}
	addNote(e) {
		this.notes.push(e);
	}
	addAccelerator(e) {
		this.accelerators.push(e);
	}
	addDeaccelerator(e) {
		this.deaccelerators.push(e);
	}
	setAnnotationsBox(e, t) {
		this.annotationsBox = {
			x: e,
			y: t
		};
	}
	setAxes(e) {
		this.axes = {
			...this.axes,
			...e
		};
	}
	setSize(e, t) {
		this.size = {
			width: e,
			height: t
		};
	}
	getNode(e) {
		return this.nodes.get(e);
	}
	build() {
		let e = [];
		for (let t of this.nodes.values()) {
			if (typeof t.x != "number" || typeof t.y != "number") throw Error(`Node "${t.label}" is missing coordinates`);
			e.push(t);
		}
		return {
			nodes: e,
			links: [...this.links],
			trends: [...this.trends.values()],
			pipelines: [...this.pipelines.values()],
			annotations: [...this.annotations],
			notes: [...this.notes],
			accelerators: [...this.accelerators],
			deaccelerators: [...this.deaccelerators],
			annotationsBox: this.annotationsBox,
			axes: { ...this.axes },
			size: this.size
		};
	}
	clear() {
		this.nodes.clear(), this.links = [], this.trends.clear(), this.pipelines.clear(), this.annotations = [], this.notes = [], this.accelerators = [], this.deaccelerators = [], this.annotationsBox = void 0, this.axes = {}, this.size = void 0;
	}
}();
function S(e) {
	let t = o();
	return c(e.trim(), t);
}
e(S, "textSanitizer");
function C() {
	return o()["wardley-beta"];
}
e(C, "getConfig");
function w(e, t, n, r, i, a, o, s, c) {
	x.addNode({
		id: e,
		label: S(t),
		x: n,
		y: r,
		className: i,
		labelOffsetX: a,
		labelOffsetY: o,
		inertia: s,
		sourceStrategy: c
	});
}
e(w, "addNode");
function T(e, t, n = !1, r, i) {
	x.addLink({
		source: e,
		target: t,
		dashed: n,
		label: r,
		flow: i
	});
}
e(T, "addLink");
function E(e, t, n) {
	x.addTrend({
		nodeId: e,
		targetX: t,
		targetY: n
	});
}
e(E, "addTrend");
function D(e, t, n) {
	x.addAnnotation({
		number: e,
		coordinates: t,
		text: n ? S(n) : void 0
	});
}
e(D, "addAnnotation");
function O(e, t, n) {
	x.addNote({
		text: S(e),
		x: t,
		y: n
	});
}
e(O, "addNote");
function k(e, t, n) {
	x.addAccelerator({
		name: S(e),
		x: t,
		y: n
	});
}
e(k, "addAccelerator");
function A(e, t, n) {
	x.addDeaccelerator({
		name: S(e),
		x: t,
		y: n
	});
}
e(A, "addDeaccelerator");
function j(e, t) {
	x.setAnnotationsBox(e, t);
}
e(j, "setAnnotationsBox");
function M(e, t) {
	x.setSize(e, t);
}
e(M, "setSize");
function N(e) {
	x.startPipeline(e);
}
e(N, "startPipeline");
function P(e, t) {
	x.addPipelineComponent(e, t);
}
e(P, "addPipelineComponent");
function F(e) {
	let t = {};
	e.xLabel && (t.xLabel = S(e.xLabel)), e.yLabel && (t.yLabel = S(e.yLabel)), e.stages && (t.stages = e.stages.map((e) => S(e))), e.stageBoundaries && (t.stageBoundaries = e.stageBoundaries), x.setAxes(t);
}
e(F, "updateAxes");
function I(e) {
	return x.getNode(e);
}
e(I, "getNode");
function L() {
	return x.build();
}
e(L, "getWardleyData");
function R() {
	x.clear(), n();
}
e(R, "clear");
var z = {
	getConfig: C,
	addNode: w,
	addLink: T,
	addTrend: E,
	addAnnotation: D,
	addNote: O,
	addAccelerator: k,
	addDeaccelerator: A,
	setAnnotationsBox: j,
	setSize: M,
	startPipeline: N,
	addPipelineComponent: P,
	updateAxes: F,
	getNode: I,
	getWardleyData: L,
	clear: R,
	setAccTitle: u,
	getAccTitle: a,
	setDiagramTitle: d,
	getDiagramTitle: s,
	getAccDescription: i,
	setAccDescription: l
}, B = [
	"Genesis",
	"Custom Built",
	"Product",
	"Commodity"
], V = /* @__PURE__ */ e(() => {
	let { themeVariables: e } = o();
	return {
		backgroundColor: e.wardley?.backgroundColor ?? e.background ?? "#fff",
		axisColor: e.wardley?.axisColor ?? "#000",
		axisTextColor: e.wardley?.axisTextColor ?? e.primaryTextColor ?? "#222",
		gridColor: e.wardley?.gridColor ?? "rgba(100, 100, 100, 0.2)",
		componentFill: e.wardley?.componentFill ?? "#fff",
		componentStroke: e.wardley?.componentStroke ?? "#000",
		componentLabelColor: e.wardley?.componentLabelColor ?? e.primaryTextColor ?? "#222",
		linkStroke: e.wardley?.linkStroke ?? "#000",
		evolutionStroke: e.wardley?.evolutionStroke ?? "#dc3545",
		annotationStroke: e.wardley?.annotationStroke ?? "#000",
		annotationTextColor: e.wardley?.annotationTextColor ?? e.primaryTextColor ?? "#222",
		annotationFill: e.wardley?.annotationFill ?? e.background ?? "#fff"
	};
}, "getTheme"), H = /* @__PURE__ */ e(() => {
	let e = o()["wardley-beta"];
	return {
		width: e?.width ?? 900,
		height: e?.height ?? 600,
		padding: e?.padding ?? 48,
		nodeRadius: e?.nodeRadius ?? 6,
		nodeLabelOffset: e?.nodeLabelOffset ?? 8,
		axisFontSize: e?.axisFontSize ?? 12,
		labelFontSize: e?.labelFontSize ?? 10,
		showGrid: e?.showGrid ?? !1,
		useMaxWidth: e?.useMaxWidth ?? !0
	};
}, "getConfigValues"), U = {
	parser: b,
	db: z,
	renderer: { draw: /* @__PURE__ */ e((n, i, a, o) => {
		t.debug("Rendering Wardley map\n" + n);
		let s = H(), c = V(), l = s.nodeRadius * 1.6, u = o.db, d = u.getWardleyData(), p = u.getDiagramTitle(), m = d.size?.width ?? s.width, h = d.size?.height ?? s.height, g = f(i);
		g.selectAll("*").remove(), r(g, h, m, s.useMaxWidth), g.attr("viewBox", `0 0 ${m} ${h}`);
		let _ = g.append("g").attr("class", "wardley-map"), v = g.append("defs");
		v.append("marker").attr("id", `arrow-${i}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 6).attr("markerHeight", 6).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", c.evolutionStroke).attr("stroke", "none"), v.append("marker").attr("id", `link-arrow-end-${i}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", c.linkStroke).attr("stroke", "none"), v.append("marker").attr("id", `link-arrow-start-${i}`).attr("viewBox", "0 0 10 10").attr("refX", 1).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 10 0 L 0 5 L 10 10 z").attr("fill", c.linkStroke).attr("stroke", "none"), _.append("rect").attr("class", "wardley-background").attr("width", m).attr("height", h).attr("fill", c.backgroundColor);
		let y = m - s.padding * 2, b = h - s.padding * 2;
		p && _.append("text").attr("class", "wardley-title").attr("x", m / 2).attr("y", s.padding / 2).attr("fill", c.axisTextColor).attr("font-size", s.axisFontSize * 1.05).attr("font-weight", "bold").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(p);
		let x = /* @__PURE__ */ e((e) => s.padding + e / 100 * y, "projectX"), S = /* @__PURE__ */ e((e) => h - s.padding - e / 100 * b, "projectY"), C = _.append("g").attr("class", "wardley-axes");
		C.append("line").attr("x1", s.padding).attr("x2", m - s.padding).attr("y1", h - s.padding).attr("y2", h - s.padding).attr("stroke", c.axisColor).attr("stroke-width", 1), C.append("line").attr("x1", s.padding).attr("x2", s.padding).attr("y1", s.padding).attr("y2", h - s.padding).attr("stroke", c.axisColor).attr("stroke-width", 1);
		let w = d.axes.xLabel ?? "Evolution", T = d.axes.yLabel ?? "Visibility";
		C.append("text").attr("class", "wardley-axis-label wardley-axis-label-x").attr("x", s.padding + y / 2).attr("y", h - s.padding / 4).attr("fill", c.axisTextColor).attr("font-size", s.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").text(w), C.append("text").attr("class", "wardley-axis-label wardley-axis-label-y").attr("x", s.padding / 3).attr("y", s.padding + b / 2).attr("fill", c.axisTextColor).attr("font-size", s.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").attr("transform", `rotate(-90 ${s.padding / 3} ${s.padding + b / 2})`).text(T);
		let E = d.axes.stages && d.axes.stages.length > 0 ? d.axes.stages : B;
		if (E.length > 0) {
			let e = _.append("g").attr("class", "wardley-stages"), t = d.axes.stageBoundaries, n = [];
			if (t && t.length === E.length) {
				let e = 0;
				t.forEach((t) => {
					n.push({
						start: e,
						end: t
					}), e = t;
				});
			} else {
				let e = 1 / E.length;
				E.forEach((t, r) => {
					n.push({
						start: r * e,
						end: (r + 1) * e
					});
				});
			}
			E.forEach((t, r) => {
				let i = n[r], a = s.padding + i.start * y, o = (a + (s.padding + i.end * y)) / 2;
				r > 0 && e.append("line").attr("x1", a).attr("x2", a).attr("y1", s.padding).attr("y2", h - s.padding).attr("stroke", "#000").attr("stroke-width", 1).attr("stroke-dasharray", "5 5").attr("opacity", .8), e.append("text").attr("class", "wardley-stage-label").attr("x", o).attr("y", h - s.padding / 1.5).attr("fill", c.axisTextColor).attr("font-size", s.axisFontSize - 2).attr("text-anchor", "middle").text(t);
			});
		}
		if (s.showGrid) {
			let e = _.append("g").attr("class", "wardley-grid");
			for (let t = 1; t < 4; t++) {
				let n = t / 4, r = s.padding + y * n;
				e.append("line").attr("x1", r).attr("x2", r).attr("y1", s.padding).attr("y2", h - s.padding).attr("stroke", c.gridColor).attr("stroke-dasharray", "2 6"), e.append("line").attr("x1", s.padding).attr("x2", m - s.padding).attr("y1", h - s.padding - b * n).attr("y2", h - s.padding - b * n).attr("stroke", c.gridColor).attr("stroke-dasharray", "2 6");
			}
		}
		let D = /* @__PURE__ */ new Map();
		if (d.nodes.forEach((e) => {
			D.set(e.id, {
				x: x(e.x),
				y: S(e.y),
				node: e
			});
		}), d.pipelines.length > 0) {
			let e = _.append("g").attr("class", "wardley-pipelines"), t = _.append("g").attr("class", "wardley-pipeline-links");
			d.pipelines.forEach((n) => {
				if (n.componentIds.length === 0) return;
				let r = n.componentIds.map((e) => ({
					id: e,
					pos: D.get(e),
					node: d.nodes.find((t) => t.id === e)
				})).filter((e) => e.pos && e.node).sort((e, t) => e.node.x - t.node.x);
				for (let e = 0; e < r.length - 1; e++) {
					let n = r[e], i = r[e + 1];
					t.append("line").attr("class", "wardley-pipeline-evolution-link").attr("x1", n.pos.x).attr("y1", n.pos.y).attr("x2", i.pos.x).attr("y2", i.pos.y).attr("stroke", c.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4");
				}
				let i = Infinity, a = -Infinity, o = 0;
				if (n.componentIds.forEach((e) => {
					let t = D.get(e);
					t && (i = Math.min(i, t.x), a = Math.max(a, t.x), o = t.y);
				}), i !== Infinity && a !== -Infinity) {
					let t = s.nodeRadius * 4, r = o - t / 2, u = D.get(n.nodeId);
					u && (u.x = (i + a) / 2, u.y = r - l / 6), e.append("rect").attr("class", "wardley-pipeline-box").attr("x", i - 15).attr("y", r).attr("width", a - i + 30).attr("height", t).attr("fill", "none").attr("stroke", c.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
				}
			});
		}
		let O = _.append("g").attr("class", "wardley-links"), k = /* @__PURE__ */ new Map();
		d.pipelines.forEach((e) => {
			k.set(e.nodeId, new Set(e.componentIds));
		});
		let A = d.links.filter((e) => !(!D.has(e.source) || !D.has(e.target) || k.get(e.target)?.has(e.source)));
		O.selectAll("line").data(A).enter().append("line").attr("class", (e) => `wardley-link${e.dashed ? " wardley-link--dashed" : ""}`).attr("x1", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = d.nodes.find((t) => t.id === e.source).isPipelineParent ? l / Math.sqrt(2) : s.nodeRadius, i = n.x - t.x, a = n.y - t.y, o = Math.sqrt(i * i + a * a);
			return t.x + i / o * r;
		}).attr("y1", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = d.nodes.find((t) => t.id === e.source).isPipelineParent ? l / Math.sqrt(2) : s.nodeRadius, i = n.x - t.x, a = n.y - t.y, o = Math.sqrt(i * i + a * a);
			return t.y + a / o * r;
		}).attr("x2", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = d.nodes.find((t) => t.id === e.target).isPipelineParent ? l / Math.sqrt(2) : s.nodeRadius, i = t.x - n.x, a = t.y - n.y, o = Math.sqrt(i * i + a * a);
			return n.x + i / o * r;
		}).attr("y2", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = d.nodes.find((t) => t.id === e.target).isPipelineParent ? l / Math.sqrt(2) : s.nodeRadius, i = t.x - n.x, a = t.y - n.y, o = Math.sqrt(i * i + a * a);
			return n.y + a / o * r;
		}).attr("stroke", c.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", (e) => e.dashed ? "6 6" : null).attr("marker-end", (e) => e.flow === "forward" || e.flow === "bidirectional" ? `url(#link-arrow-end-${i})` : null).attr("marker-start", (e) => e.flow === "backward" || e.flow === "bidirectional" ? `url(#link-arrow-start-${i})` : null), O.selectAll("text").data(A.filter((e) => e.label)).enter().append("text").attr("class", "wardley-link-label").attr("x", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = (t.x + n.x) / 2, i = n.y - t.y, a = n.x - t.x;
			return r + i / Math.sqrt(a * a + i * i) * 8;
		}).attr("y", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = (t.y + n.y) / 2, i = n.x - t.x, a = n.y - t.y, o = Math.sqrt(i * i + a * a);
			return r + -i / o * 8;
		}).attr("fill", c.axisTextColor).attr("font-size", s.labelFontSize).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("transform", (e) => {
			let t = D.get(e.source), n = D.get(e.target), r = (t.x + n.x) / 2, i = (t.y + n.y) / 2, a = n.x - t.x, o = n.y - t.y, s = Math.sqrt(a * a + o * o), c = o / s, l = -a / s, u = r + c * 8, d = i + l * 8, f = Math.atan2(o, a) * 180 / Math.PI;
			return (f > 90 || f < -90) && (f += 180), `rotate(${f} ${u} ${d})`;
		}).text((e) => e.label);
		let j = _.append("g").attr("class", "wardley-trends"), M = d.trends.map((e) => {
			let t = D.get(e.nodeId);
			if (!t) return null;
			let n = x(e.targetX), r = S(e.targetY), i = n - t.x, a = r - t.y, o = Math.sqrt(i * i + a * a), c = s.nodeRadius + 2;
			return {
				origin: t,
				targetX: n,
				targetY: r,
				adjustedX2: o > c ? n - i / o * c : n,
				adjustedY2: o > c ? r - a / o * c : r
			};
		}).filter((e) => e !== null);
		j.selectAll("line").data(M).enter().append("line").attr("class", "wardley-trend").attr("x1", (e) => e.origin.x).attr("y1", (e) => e.origin.y).attr("x2", (e) => e.adjustedX2).attr("y2", (e) => e.adjustedY2).attr("stroke", c.evolutionStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4").attr("marker-end", `url(#arrow-${i})`);
		let N = _.append("g").attr("class", "wardley-nodes").selectAll("g").data(d.nodes).enter().append("g").attr("class", (e) => ["wardley-node", e.className ? `wardley-node--${e.className}` : ""].filter(Boolean).join(" "));
		N.filter((e) => e.sourceStrategy === "outsource").append("circle").attr("class", "wardley-outsource-overlay").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y).attr("r", s.nodeRadius * 2).attr("fill", "#666").attr("stroke", c.componentStroke).attr("stroke-width", 1), N.filter((e) => e.sourceStrategy === "buy").append("circle").attr("class", "wardley-buy-overlay").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y).attr("r", s.nodeRadius * 2).attr("fill", "#ccc").attr("stroke", c.componentStroke).attr("stroke-width", 1), N.filter((e) => e.sourceStrategy === "build").append("circle").attr("class", "wardley-build-overlay").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y).attr("r", s.nodeRadius * 2).attr("fill", "#eee").attr("stroke", "#000").attr("stroke-width", 1);
		let P = N.filter((e) => e.sourceStrategy === "market");
		P.append("circle").attr("class", "wardley-market-overlay").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y).attr("r", s.nodeRadius * 2).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 1), N.filter((e) => !e.isPipelineParent && e.sourceStrategy !== "market" && e.className !== "anchor").append("circle").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y).attr("r", s.nodeRadius).attr("fill", c.componentFill).attr("stroke", c.componentStroke).attr("stroke-width", 1);
		let F = s.nodeRadius * .7, I = s.nodeRadius * 1.2;
		if (P.append("line").attr("class", "wardley-market-line").attr("x1", (e) => D.get(e.id).x).attr("y1", (e) => D.get(e.id).y - I).attr("x2", (e) => D.get(e.id).x - I * Math.cos(Math.PI / 6)).attr("y2", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("stroke", c.componentStroke).attr("stroke-width", 1), P.append("line").attr("class", "wardley-market-line").attr("x1", (e) => D.get(e.id).x - I * Math.cos(Math.PI / 6)).attr("y1", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("x2", (e) => D.get(e.id).x + I * Math.cos(Math.PI / 6)).attr("y2", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("stroke", c.componentStroke).attr("stroke-width", 1), P.append("line").attr("class", "wardley-market-line").attr("x1", (e) => D.get(e.id).x + I * Math.cos(Math.PI / 6)).attr("y1", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("x2", (e) => D.get(e.id).x).attr("y2", (e) => D.get(e.id).y - I).attr("stroke", c.componentStroke).attr("stroke-width", 1), P.append("circle").attr("class", "wardley-market-dot").attr("cx", (e) => D.get(e.id).x).attr("cy", (e) => D.get(e.id).y - I).attr("r", F).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 2), P.append("circle").attr("class", "wardley-market-dot").attr("cx", (e) => D.get(e.id).x - I * Math.cos(Math.PI / 6)).attr("cy", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("r", F).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 2), P.append("circle").attr("class", "wardley-market-dot").attr("cx", (e) => D.get(e.id).x + I * Math.cos(Math.PI / 6)).attr("cy", (e) => D.get(e.id).y + I * Math.sin(Math.PI / 6)).attr("r", F).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 2), N.filter((e) => e.isPipelineParent === !0).append("rect").attr("x", (e) => D.get(e.id).x - l / 2).attr("y", (e) => D.get(e.id).y - l / 2).attr("width", l).attr("height", l).attr("fill", c.componentFill).attr("stroke", c.componentStroke).attr("stroke-width", 1), N.filter((e) => e.inertia === !0).append("line").attr("class", "wardley-inertia").attr("x1", (e) => {
			let t = D.get(e.id), n = e.isPipelineParent ? l / 2 + 15 : s.nodeRadius + 15;
			return e.sourceStrategy && (n += s.nodeRadius + 10), t.x + n;
		}).attr("y1", (e) => {
			let t = D.get(e.id), n = e.isPipelineParent ? l : s.nodeRadius * 2;
			return t.y - n / 2;
		}).attr("x2", (e) => {
			let t = D.get(e.id), n = e.isPipelineParent ? l / 2 + 15 : s.nodeRadius + 15;
			return e.sourceStrategy && (n += s.nodeRadius + 10), t.x + n;
		}).attr("y2", (e) => {
			let t = D.get(e.id), n = e.isPipelineParent ? l : s.nodeRadius * 2;
			return t.y + n / 2;
		}).attr("stroke", c.componentStroke).attr("stroke-width", 6), N.append("text").attr("x", (e) => {
			let t = D.get(e.id);
			if (e.className === "anchor") return e.labelOffsetX === void 0 ? t.x : t.x + e.labelOffsetX;
			let n = s.nodeLabelOffset;
			e.sourceStrategy && e.labelOffsetX === void 0 && (n += 10);
			let r = e.labelOffsetX ?? n;
			return t.x + r;
		}).attr("y", (e) => {
			let t = D.get(e.id);
			if (e.className === "anchor") return e.labelOffsetY === void 0 ? t.y - 3 : t.y + e.labelOffsetY;
			let n = -s.nodeLabelOffset;
			e.sourceStrategy && e.labelOffsetY === void 0 && (n -= 10);
			let r = e.labelOffsetY ?? n;
			return t.y + r;
		}).attr("class", "wardley-node-label").attr("fill", (e) => e.className === "evolved" ? c.evolutionStroke : e.className === "anchor" ? "#000" : c.componentLabelColor).attr("font-size", s.labelFontSize).attr("font-weight", (e) => e.className === "anchor" ? "bold" : "normal").attr("text-anchor", (e) => e.className === "anchor" ? "middle" : "start").attr("dominant-baseline", (e) => e.className === "anchor" ? "middle" : "auto").text((e) => e.label), d.annotations.length > 0) {
			let e = _.append("g").attr("class", "wardley-annotations");
			if (d.annotations.forEach((t) => {
				let n = t.coordinates.map((e) => ({
					x: x(e.x),
					y: S(e.y)
				}));
				if (n.length > 1) for (let t = 0; t < n.length - 1; t++) e.append("line").attr("class", "wardley-annotation-line").attr("x1", n[t].x).attr("y1", n[t].y).attr("x2", n[t + 1].x).attr("y2", n[t + 1].y).attr("stroke", c.axisColor).attr("stroke-width", 1.5).attr("stroke-dasharray", "4 4");
				n.forEach((n) => {
					let r = e.append("g").attr("class", "wardley-annotation");
					r.append("circle").attr("cx", n.x).attr("cy", n.y).attr("r", 10).attr("fill", "white").attr("stroke", c.axisColor).attr("stroke-width", 1.5), r.append("text").attr("x", n.x).attr("y", n.y).attr("text-anchor", "middle").attr("dominant-baseline", "central").attr("font-size", 10).attr("fill", c.axisTextColor).attr("font-weight", "bold").text(t.number);
				});
			}), d.annotationsBox) {
				let t = x(d.annotationsBox.x), n = S(d.annotationsBox.y), r = e.append("g").attr("class", "wardley-annotations-box"), i = [...d.annotations].filter((e) => e.text).sort((e, t) => e.number - t.number), a = [];
				if (i.forEach((e, i) => {
					let o = r.append("text").attr("x", t + 10).attr("y", n + 10 + (i + 1) * 16).attr("font-size", 11).attr("fill", c.axisTextColor).attr("text-anchor", "start").attr("dominant-baseline", "middle").text(`${e.number}. ${e.text}`);
					a.push(o);
				}), a.length > 0) {
					let e = 0, o = 0;
					a.forEach((t) => {
						let n = t.node(), r = n.getComputedTextLength();
						e = Math.max(e, r);
						let i = n.getBBox();
						o = Math.max(o, i.height);
					});
					let l = e + 20 + 105, u = i.length * 16 + 20 + o / 2, d = s.padding, f = m - s.padding - l, p = s.padding, g = h - s.padding - u;
					t = Math.max(d, Math.min(t, f)), n = Math.max(p, Math.min(n, g)), a.forEach((e, r) => {
						e.attr("x", t + 10).attr("y", n + 10 + (r + 1) * 16);
					}), r.insert("rect", "text").attr("x", t).attr("y", n).attr("width", l).attr("height", u).attr("fill", "white").attr("stroke", c.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
				}
			}
		}
		if (d.notes.length > 0) {
			let e = _.append("g").attr("class", "wardley-notes");
			d.notes.forEach((t) => {
				let n = x(t.x), r = S(t.y);
				e.append("text").attr("x", n).attr("y", r).attr("text-anchor", "start").attr("font-size", 11).attr("fill", c.axisTextColor).attr("font-weight", "bold").text(t.text);
			});
		}
		if (d.accelerators.length > 0) {
			let e = _.append("g").attr("class", "wardley-accelerators");
			d.accelerators.forEach((t) => {
				let n = x(t.x), r = S(t.y), i = `
        M ${n} ${r - 30 / 2}
        L ${n + 60 - 20} ${r - 30 / 2}
        L ${n + 60 - 20} ${r - 30 / 2 - 8}
        L ${n + 60} ${r}
        L ${n + 60 - 20} ${r + 30 / 2 + 8}
        L ${n + 60 - 20} ${r + 30 / 2}
        L ${n} ${r + 30 / 2}
        Z
      `;
				e.append("path").attr("d", i).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 1), e.append("text").attr("x", n + 60 / 2).attr("y", r + 30 / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", c.axisTextColor).attr("font-weight", "bold").text(t.name);
			});
		}
		if (d.deaccelerators.length > 0) {
			let e = _.append("g").attr("class", "wardley-deaccelerators");
			d.deaccelerators.forEach((t) => {
				let n = x(t.x), r = S(t.y), i = `
        M ${n + 60} ${r - 30 / 2}
        L ${n + 20} ${r - 30 / 2}
        L ${n + 20} ${r - 30 / 2 - 8}
        L ${n} ${r}
        L ${n + 20} ${r + 30 / 2 + 8}
        L ${n + 20} ${r + 30 / 2}
        L ${n + 60} ${r + 30 / 2}
        Z
      `;
				e.append("path").attr("d", i).attr("fill", "white").attr("stroke", c.componentStroke).attr("stroke-width", 1), e.append("text").attr("x", n + 60 / 2).attr("y", r + 30 / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", c.axisTextColor).attr("font-weight", "bold").text(t.name);
			});
		}
	}, "draw") },
	styles: /* @__PURE__ */ e(() => "", "styles")
};
//#endregion
export { U as diagram };
