import { __name as e } from "./chunk-AGHRB4JF.js";
import { clear as t, common_default as n, defaultConfig2 as r, getAccDescription as i, getAccTitle as a, getConfig2 as o, getDiagramTitle as s, setAccDescription as c, setAccTitle as l, setDiagramTitle as u, setupGraphViewbox as d } from "./chunk-ICPOFSXX.js";
import f from "../../../../d3-selection/src/select.js";
import p from "../../../../d3-scale/src/ordinal.js";
import m from "../../../../d3-scale-chromatic/src/categorical/Tableau10.js";
import "../../../../d3/src/index.js";
import { center as h, justify as g, left as _, right as v } from "../../../../d3-sankey/src/align.js";
import y from "../../../../d3-sankey/src/sankey.js";
import b from "../../../../d3-sankey/src/sankeyLinkHorizontal.js";
//#region ../../node_modules/mermaid/dist/chunks/mermaid.core/sankeyDiagram-XADWPNL6.mjs
var x = (function() {
	var t = /* @__PURE__ */ e(function(e, t, n, r) {
		for (n ||= {}, r = e.length; r--; n[e[r]] = t);
		return n;
	}, "o"), n = [1, 9], r = [1, 10], i = [
		1,
		5,
		10,
		12
	], a = {
		trace: /* @__PURE__ */ e(function() {}, "trace"),
		yy: {},
		symbols_: {
			error: 2,
			start: 3,
			SANKEY: 4,
			NEWLINE: 5,
			csv: 6,
			opt_eof: 7,
			record: 8,
			csv_tail: 9,
			EOF: 10,
			"field[source]": 11,
			COMMA: 12,
			"field[target]": 13,
			"field[value]": 14,
			field: 15,
			escaped: 16,
			non_escaped: 17,
			DQUOTE: 18,
			ESCAPED_TEXT: 19,
			NON_ESCAPED_TEXT: 20,
			$accept: 0,
			$end: 1
		},
		terminals_: {
			2: "error",
			4: "SANKEY",
			5: "NEWLINE",
			10: "EOF",
			11: "field[source]",
			12: "COMMA",
			13: "field[target]",
			14: "field[value]",
			18: "DQUOTE",
			19: "ESCAPED_TEXT",
			20: "NON_ESCAPED_TEXT"
		},
		productions_: [
			0,
			[3, 4],
			[6, 2],
			[9, 2],
			[9, 0],
			[7, 1],
			[7, 0],
			[8, 5],
			[15, 1],
			[15, 1],
			[16, 3],
			[17, 1]
		],
		performAction: /* @__PURE__ */ e(function(e, t, n, r, i, a, o) {
			var s = a.length - 1;
			switch (i) {
				case 7:
					let e = r.findOrCreateNode(a[s - 4].trim().replaceAll("\"\"", "\"")), t = r.findOrCreateNode(a[s - 2].trim().replaceAll("\"\"", "\"")), n = parseFloat(a[s].trim());
					r.addLink(e, t, n);
					break;
				case 8:
				case 9:
				case 11:
					this.$ = a[s];
					break;
				case 10:
					this.$ = a[s - 1];
					break;
			}
		}, "anonymous"),
		table: [
			{
				3: 1,
				4: [1, 2]
			},
			{ 1: [3] },
			{ 5: [1, 3] },
			{
				6: 4,
				8: 5,
				15: 6,
				16: 7,
				17: 8,
				18: n,
				20: r
			},
			{
				1: [2, 6],
				7: 11,
				10: [1, 12]
			},
			t(r, [2, 4], {
				9: 13,
				5: [1, 14]
			}),
			{ 12: [1, 15] },
			t(i, [2, 8]),
			t(i, [2, 9]),
			{ 19: [1, 16] },
			t(i, [2, 11]),
			{ 1: [2, 1] },
			{ 1: [2, 5] },
			t(r, [2, 2]),
			{
				6: 17,
				8: 5,
				15: 6,
				16: 7,
				17: 8,
				18: n,
				20: r
			},
			{
				15: 18,
				16: 7,
				17: 8,
				18: n,
				20: r
			},
			{ 18: [1, 19] },
			t(r, [2, 3]),
			{ 12: [1, 20] },
			t(i, [2, 10]),
			{
				15: 21,
				16: 7,
				17: 8,
				18: n,
				20: r
			},
			t([
				1,
				5,
				10
			], [2, 7])
		],
		defaultActions: {
			11: [2, 1],
			12: [2, 5]
		},
		parseError: /* @__PURE__ */ e(function(e, t) {
			if (t.recoverable) this.trace(e);
			else {
				var n = Error(e);
				throw n.hash = t, n;
			}
		}, "parseError"),
		parse: /* @__PURE__ */ e(function(t) {
			var n = this, r = [0], i = [], a = [null], o = [], s = this.table, c = "", l = 0, u = 0, d = 0, f = 2, p = 1, m = o.slice.call(arguments, 1), h = Object.create(this.lexer), g = { yy: {} };
			for (var _ in this.yy) Object.prototype.hasOwnProperty.call(this.yy, _) && (g.yy[_] = this.yy[_]);
			h.setInput(t, g.yy), g.yy.lexer = h, g.yy.parser = this, h.yylloc === void 0 && (h.yylloc = {});
			var v = h.yylloc;
			o.push(v);
			var y = h.options && h.options.ranges;
			typeof g.yy.parseError == "function" ? this.parseError = g.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
			function b(e) {
				r.length -= 2 * e, a.length -= e, o.length -= e;
			}
			e(b, "popStack");
			function x() {
				var e = i.pop() || h.lex() || p;
				return typeof e != "number" && (e instanceof Array && (i = e, e = i.pop()), e = n.symbols_[e] || e), e;
			}
			e(x, "lex");
			for (var S, C, w, T, E, D = {}, O, k, A, j;;) {
				if (w = r[r.length - 1], this.defaultActions[w] ? T = this.defaultActions[w] : (S ??= x(), T = s[w] && s[w][S]), T === void 0 || !T.length || !T[0]) {
					var M = "";
					for (O in j = [], s[w]) this.terminals_[O] && O > f && j.push("'" + this.terminals_[O] + "'");
					M = h.showPosition ? "Parse error on line " + (l + 1) + ":\n" + h.showPosition() + "\nExpecting " + j.join(", ") + ", got '" + (this.terminals_[S] || S) + "'" : "Parse error on line " + (l + 1) + ": Unexpected " + (S == p ? "end of input" : "'" + (this.terminals_[S] || S) + "'"), this.parseError(M, {
						text: h.match,
						token: this.terminals_[S] || S,
						line: h.yylineno,
						loc: v,
						expected: j
					});
				}
				if (T[0] instanceof Array && T.length > 1) throw Error("Parse Error: multiple actions possible at state: " + w + ", token: " + S);
				switch (T[0]) {
					case 1:
						r.push(S), a.push(h.yytext), o.push(h.yylloc), r.push(T[1]), S = null, C ? (S = C, C = null) : (u = h.yyleng, c = h.yytext, l = h.yylineno, v = h.yylloc, d > 0 && d--);
						break;
					case 2:
						if (k = this.productions_[T[1]][1], D.$ = a[a.length - k], D._$ = {
							first_line: o[o.length - (k || 1)].first_line,
							last_line: o[o.length - 1].last_line,
							first_column: o[o.length - (k || 1)].first_column,
							last_column: o[o.length - 1].last_column
						}, y && (D._$.range = [o[o.length - (k || 1)].range[0], o[o.length - 1].range[1]]), E = this.performAction.apply(D, [
							c,
							u,
							l,
							g.yy,
							T[1],
							a,
							o
						].concat(m)), E !== void 0) return E;
						k && (r = r.slice(0, -1 * k * 2), a = a.slice(0, -1 * k), o = o.slice(0, -1 * k)), r.push(this.productions_[T[1]][0]), a.push(D.$), o.push(D._$), A = s[r[r.length - 2]][r[r.length - 1]], r.push(A);
						break;
					case 3: return !0;
				}
			}
			return !0;
		}, "parse")
	};
	a.lexer = /* @__PURE__ */ (function() {
		return {
			EOF: 1,
			parseError: /* @__PURE__ */ e(function(e, t) {
				if (this.yy.parser) this.yy.parser.parseError(e, t);
				else throw Error(e);
			}, "parseError"),
			setInput: /* @__PURE__ */ e(function(e, t) {
				return this.yy = t || this.yy || {}, this._input = e, this._more = this._backtrack = this.done = !1, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
					first_line: 1,
					first_column: 0,
					last_line: 1,
					last_column: 0
				}, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
			}, "setInput"),
			input: /* @__PURE__ */ e(function() {
				var e = this._input[0];
				return this.yytext += e, this.yyleng++, this.offset++, this.match += e, this.matched += e, e.match(/(?:\r\n?|\n).*/g) ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), e;
			}, "input"),
			unput: /* @__PURE__ */ e(function(e) {
				var t = e.length, n = e.split(/(?:\r\n?|\n)/g);
				this._input = e + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - t), this.offset -= t;
				var r = this.match.split(/(?:\r\n?|\n)/g);
				this.match = this.match.substr(0, this.match.length - 1), this.matched = this.matched.substr(0, this.matched.length - 1), n.length - 1 && (this.yylineno -= n.length - 1);
				var i = this.yylloc.range;
				return this.yylloc = {
					first_line: this.yylloc.first_line,
					last_line: this.yylineno + 1,
					first_column: this.yylloc.first_column,
					last_column: n ? (n.length === r.length ? this.yylloc.first_column : 0) + r[r.length - n.length].length - n[0].length : this.yylloc.first_column - t
				}, this.options.ranges && (this.yylloc.range = [i[0], i[0] + this.yyleng - t]), this.yyleng = this.yytext.length, this;
			}, "unput"),
			more: /* @__PURE__ */ e(function() {
				return this._more = !0, this;
			}, "more"),
			reject: /* @__PURE__ */ e(function() {
				if (this.options.backtrack_lexer) this._backtrack = !0;
				else return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
					text: "",
					token: null,
					line: this.yylineno
				});
				return this;
			}, "reject"),
			less: /* @__PURE__ */ e(function(e) {
				this.unput(this.match.slice(e));
			}, "less"),
			pastInput: /* @__PURE__ */ e(function() {
				var e = this.matched.substr(0, this.matched.length - this.match.length);
				return (e.length > 20 ? "..." : "") + e.substr(-20).replace(/\n/g, "");
			}, "pastInput"),
			upcomingInput: /* @__PURE__ */ e(function() {
				var e = this.match;
				return e.length < 20 && (e += this._input.substr(0, 20 - e.length)), (e.substr(0, 20) + (e.length > 20 ? "..." : "")).replace(/\n/g, "");
			}, "upcomingInput"),
			showPosition: /* @__PURE__ */ e(function() {
				var e = this.pastInput(), t = Array(e.length + 1).join("-");
				return e + this.upcomingInput() + "\n" + t + "^";
			}, "showPosition"),
			test_match: /* @__PURE__ */ e(function(e, t) {
				var n, r, i;
				if (this.options.backtrack_lexer && (i = {
					yylineno: this.yylineno,
					yylloc: {
						first_line: this.yylloc.first_line,
						last_line: this.last_line,
						first_column: this.yylloc.first_column,
						last_column: this.yylloc.last_column
					},
					yytext: this.yytext,
					match: this.match,
					matches: this.matches,
					matched: this.matched,
					yyleng: this.yyleng,
					offset: this.offset,
					_more: this._more,
					_input: this._input,
					yy: this.yy,
					conditionStack: this.conditionStack.slice(0),
					done: this.done
				}, this.options.ranges && (i.yylloc.range = this.yylloc.range.slice(0))), r = e[0].match(/(?:\r\n?|\n).*/g), r && (this.yylineno += r.length), this.yylloc = {
					first_line: this.yylloc.last_line,
					last_line: this.yylineno + 1,
					first_column: this.yylloc.last_column,
					last_column: r ? r[r.length - 1].length - r[r.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + e[0].length
				}, this.yytext += e[0], this.match += e[0], this.matches = e, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = !1, this._backtrack = !1, this._input = this._input.slice(e[0].length), this.matched += e[0], n = this.performAction.call(this, this.yy, this, t, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), n) return n;
				if (this._backtrack) {
					for (var a in i) this[a] = i[a];
					return !1;
				}
				return !1;
			}, "test_match"),
			next: /* @__PURE__ */ e(function() {
				if (this.done) return this.EOF;
				this._input || (this.done = !0);
				var e, t, n, r;
				this._more || (this.yytext = "", this.match = "");
				for (var i = this._currentRules(), a = 0; a < i.length; a++) if (n = this._input.match(this.rules[i[a]]), n && (!t || n[0].length > t[0].length)) {
					if (t = n, r = a, this.options.backtrack_lexer) {
						if (e = this.test_match(n, i[a]), e !== !1) return e;
						if (this._backtrack) {
							t = !1;
							continue;
						} else return !1;
					} else if (!this.options.flex) break;
				}
				return t ? (e = this.test_match(t, i[r]), e === !1 ? !1 : e) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
					text: "",
					token: null,
					line: this.yylineno
				});
			}, "next"),
			lex: /* @__PURE__ */ e(function() {
				return this.next() || this.lex();
			}, "lex"),
			begin: /* @__PURE__ */ e(function(e) {
				this.conditionStack.push(e);
			}, "begin"),
			popState: /* @__PURE__ */ e(function() {
				return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
			}, "popState"),
			_currentRules: /* @__PURE__ */ e(function() {
				return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
			}, "_currentRules"),
			topState: /* @__PURE__ */ e(function(e) {
				return e = this.conditionStack.length - 1 - Math.abs(e || 0), e >= 0 ? this.conditionStack[e] : "INITIAL";
			}, "topState"),
			pushState: /* @__PURE__ */ e(function(e) {
				this.begin(e);
			}, "pushState"),
			stateStackSize: /* @__PURE__ */ e(function() {
				return this.conditionStack.length;
			}, "stateStackSize"),
			options: { "case-insensitive": !0 },
			performAction: /* @__PURE__ */ e(function(e, t, n, r) {
				switch (n) {
					case 0: return this.pushState("csv"), 4;
					case 1: return this.pushState("csv"), 4;
					case 2: return 10;
					case 3: return 5;
					case 4: return 12;
					case 5: return this.pushState("escaped_text"), 18;
					case 6: return 20;
					case 7: return this.popState("escaped_text"), 18;
					case 8: return 19;
				}
			}, "anonymous"),
			rules: [
				/^(?:sankey-beta\b)/i,
				/^(?:sankey\b)/i,
				/^(?:$)/i,
				/^(?:((\u000D\u000A)|(\u000A)))/i,
				/^(?:(\u002C))/i,
				/^(?:(\u0022))/i,
				/^(?:([\u0020-\u0021\u0023-\u002B\u002D-\u007E])*)/i,
				/^(?:(\u0022)(?!(\u0022)))/i,
				/^(?:(([\u0020-\u0021\u0023-\u002B\u002D-\u007E])|(\u002C)|(\u000D)|(\u000A)|(\u0022)(\u0022))*)/i
			],
			conditions: {
				csv: {
					rules: [
						2,
						3,
						4,
						5,
						6,
						7,
						8
					],
					inclusive: !1
				},
				escaped_text: {
					rules: [7, 8],
					inclusive: !1
				},
				INITIAL: {
					rules: [
						0,
						1,
						2,
						3,
						4,
						5,
						6,
						7,
						8
					],
					inclusive: !0
				}
			}
		};
	})();
	function o() {
		this.yy = {};
	}
	return e(o, "Parser"), o.prototype = a, a.Parser = o, new o();
})();
x.parser = x;
var S = x, C = [], w = [], T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ e(() => {
	C = [], w = [], T = /* @__PURE__ */ new Map(), t();
}, "clear"), D = class {
	constructor(e, t, n = 0) {
		this.source = e, this.target = t, this.value = n;
	}
	static {
		e(this, "SankeyLink");
	}
}, O = /* @__PURE__ */ e((e, t, n) => {
	C.push(new D(e, t, n));
}, "addLink"), k = class {
	constructor(e) {
		this.ID = e;
	}
	static {
		e(this, "SankeyNode");
	}
}, A = {
	nodesMap: T,
	getConfig: /* @__PURE__ */ e(() => o().sankey, "getConfig"),
	getNodes: /* @__PURE__ */ e(() => w, "getNodes"),
	getLinks: /* @__PURE__ */ e(() => C, "getLinks"),
	getGraph: /* @__PURE__ */ e(() => ({
		nodes: w.map((e) => ({ id: e.ID })),
		links: C.map((e) => ({
			source: e.source.ID,
			target: e.target.ID,
			value: e.value
		}))
	}), "getGraph"),
	addLink: O,
	findOrCreateNode: /* @__PURE__ */ e((e) => {
		e = n.sanitizeText(e, o());
		let t = T.get(e);
		return t === void 0 && (t = new k(e), T.set(e, t), w.push(t)), t;
	}, "findOrCreateNode"),
	getAccTitle: a,
	setAccTitle: l,
	getAccDescription: i,
	setAccDescription: c,
	getDiagramTitle: s,
	setDiagramTitle: u,
	clear: E
}, j = class t {
	static {
		e(this, "Uid");
	}
	static {
		this.count = 0;
	}
	static next(e) {
		return new t(e + ++t.count);
	}
	constructor(e) {
		this.id = e, this.href = `#${e}`;
	}
	toString() {
		return "url(" + this.href + ")";
	}
}, M = {
	left: _,
	right: v,
	center: h,
	justify: g
}, N = { draw: /* @__PURE__ */ e(function(t, n, i, a) {
	let { securityLevel: s, sankey: c } = o(), l = r.sankey, u;
	s === "sandbox" && (u = f("#i" + n));
	let h = f(s === "sandbox" ? u.nodes()[0].contentDocument.body : "body"), g = s === "sandbox" ? h.select(`[id="${n}"]`) : f(`[id="${n}"]`), _ = c?.width ?? l.width, v = c?.height ?? l.width, x = c?.useMaxWidth ?? l.useMaxWidth, S = c?.nodeAlignment ?? l.nodeAlignment, C = c?.prefix ?? l.prefix, w = c?.suffix ?? l.suffix, T = c?.showValues ?? l.showValues, E = a.db.getGraph(), D = M[S];
	y().nodeId((e) => e.id).nodeWidth(10).nodePadding(10 + (T ? 15 : 0)).nodeAlign(D).extent([[0, 0], [_, v]])(E);
	let O = p(m);
	g.append("g").attr("class", "nodes").selectAll(".node").data(E.nodes).join("g").attr("class", "node").attr("id", (e) => (e.uid = j.next("node-")).id).attr("transform", function(e) {
		return "translate(" + e.x0 + "," + e.y0 + ")";
	}).attr("x", (e) => e.x0).attr("y", (e) => e.y0).append("rect").attr("height", (e) => e.y1 - e.y0).attr("width", (e) => e.x1 - e.x0).attr("fill", (e) => O(e.id));
	let k = /* @__PURE__ */ e(({ id: e, value: t }) => T ? `${e}
${C}${Math.round(t * 100) / 100}${w}` : e, "getText");
	g.append("g").attr("class", "node-labels").attr("font-size", 14).selectAll("text").data(E.nodes).join("text").attr("x", (e) => e.x0 < _ / 2 ? e.x1 + 6 : e.x0 - 6).attr("y", (e) => (e.y1 + e.y0) / 2).attr("dy", `${T ? "0" : "0.35"}em`).attr("text-anchor", (e) => e.x0 < _ / 2 ? "start" : "end").text(k);
	let A = g.append("g").attr("class", "links").attr("fill", "none").attr("stroke-opacity", .5).selectAll(".link").data(E.links).join("g").attr("class", "link").style("mix-blend-mode", "multiply"), N = c?.linkColor ?? "gradient";
	if (N === "gradient") {
		let e = A.append("linearGradient").attr("id", (e) => (e.uid = j.next("linearGradient-")).id).attr("gradientUnits", "userSpaceOnUse").attr("x1", (e) => e.source.x1).attr("x2", (e) => e.target.x0);
		e.append("stop").attr("offset", "0%").attr("stop-color", (e) => O(e.source.id)), e.append("stop").attr("offset", "100%").attr("stop-color", (e) => O(e.target.id));
	}
	let P;
	switch (N) {
		case "gradient":
			P = /* @__PURE__ */ e((e) => e.uid, "coloring");
			break;
		case "source":
			P = /* @__PURE__ */ e((e) => O(e.source.id), "coloring");
			break;
		case "target":
			P = /* @__PURE__ */ e((e) => O(e.target.id), "coloring");
			break;
		default: P = N;
	}
	A.append("path").attr("d", b()).attr("stroke", P).attr("stroke-width", (e) => Math.max(1, e.width)), d(void 0, g, 0, x);
}, "draw") }, P = /* @__PURE__ */ e((e) => e.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g, "").replaceAll(/([\n\r])+/g, "\n").trim(), "prepareTextForParsing"), F = /* @__PURE__ */ e((e) => `.label {
      font-family: ${e.fontFamily};
    }`, "getStyles"), I = S.parse.bind(S);
S.parse = (e) => I(P(e));
var L = {
	styles: F,
	parser: S,
	db: A,
	renderer: N
};
//#endregion
export { L as diagram };
