import { Z as H, a as Z, i as q, n as J, o as tt, r as et, s as nt, t as st, u as L } from "./vendor/recharts.js";
import { n as s } from "./chunk-AGHRB4JF.js";
import { B as it, C as rt, K as at, V as ot, W as lt, _ as ct, a as ht, b as W, s as ut, u as yt, v as ft } from "./chunk-ICPOFSXX.js";
var G = (function() {
  var r = /* @__PURE__ */ s(function(t, i, a, e) {
    for (a = a || {}, e = t.length; e--; a[t[e]] = i) ;
    return a;
  }, "o"), c = [1, 9], d = [1, 10], O = [
    1,
    5,
    10,
    12
  ], w = {
    trace: /* @__PURE__ */ s(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__ */ s(function(i, a, e, l, h, o, T) {
      var x = o.length - 1;
      switch (h) {
        case 7:
          const S = l.findOrCreateNode(o[x - 4].trim().replaceAll('""', '"')), E = l.findOrCreateNode(o[x - 2].trim().replaceAll('""', '"')), k = parseFloat(o[x].trim());
          l.addLink(S, E, k);
          break;
        case 8:
        case 9:
        case 11:
          this.$ = o[x];
          break;
        case 10:
          this.$ = o[x - 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: c,
        20: d
      },
      {
        1: [2, 6],
        7: 11,
        10: [1, 12]
      },
      r(d, [2, 4], {
        9: 13,
        5: [1, 14]
      }),
      { 12: [1, 15] },
      r(O, [2, 8]),
      r(O, [2, 9]),
      { 19: [1, 16] },
      r(O, [2, 11]),
      { 1: [2, 1] },
      { 1: [2, 5] },
      r(d, [2, 2]),
      {
        6: 17,
        8: 5,
        15: 6,
        16: 7,
        17: 8,
        18: c,
        20: d
      },
      {
        15: 18,
        16: 7,
        17: 8,
        18: c,
        20: d
      },
      { 18: [1, 19] },
      r(d, [2, 3]),
      { 12: [1, 20] },
      r(O, [2, 10]),
      {
        15: 21,
        16: 7,
        17: 8,
        18: c,
        20: d
      },
      r([
        1,
        5,
        10
      ], [2, 7])
    ],
    defaultActions: {
      11: [2, 1],
      12: [2, 5]
    },
    parseError: /* @__PURE__ */ s(function(i, a) {
      if (a.recoverable) this.trace(i);
      else {
        var e = new Error(i);
        throw e.hash = a, e;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ s(function(i) {
      var a = this, e = [0], l = [], h = [null], o = [], T = this.table, x = "", S = 0, E = 0, k = 0, F = 2, A = 1, R = o.slice.call(arguments, 1), u = Object.create(this.lexer), _ = { yy: {} };
      for (var v in this.yy) Object.prototype.hasOwnProperty.call(this.yy, v) && (_.yy[v] = this.yy[v]);
      u.setInput(i, _.yy), _.yy.lexer = u, _.yy.parser = this, typeof u.yylloc > "u" && (u.yylloc = {});
      var n = u.yylloc;
      o.push(n);
      var p = u.options && u.options.ranges;
      typeof _.yy.parseError == "function" ? this.parseError = _.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function Q(m) {
        e.length = e.length - 2 * m, h.length = h.length - m, o.length = o.length - m;
      }
      s(Q, "popStack");
      function B() {
        var m = l.pop() || u.lex() || A;
        return typeof m != "number" && (m instanceof Array && (l = m, m = l.pop()), m = a.symbols_[m] || m), m;
      }
      s(B, "lex");
      for (var y, U, I, g, V, N = {}, P, b, X, C; ; ) {
        if (I = e[e.length - 1], this.defaultActions[I] ? g = this.defaultActions[I] : ((y === null || typeof y > "u") && (y = B()), g = T[I] && T[I][y]), typeof g > "u" || !g.length || !g[0]) {
          var z = "";
          C = [];
          for (P in T[I]) this.terminals_[P] && P > F && C.push("'" + this.terminals_[P] + "'");
          u.showPosition ? z = "Parse error on line " + (S + 1) + `:
` + u.showPosition() + `
Expecting ` + C.join(", ") + ", got '" + (this.terminals_[y] || y) + "'" : z = "Parse error on line " + (S + 1) + ": Unexpected " + (y == A ? "end of input" : "'" + (this.terminals_[y] || y) + "'"), this.parseError(z, {
            text: u.match,
            token: this.terminals_[y] || y,
            line: u.yylineno,
            loc: n,
            expected: C
          });
        }
        if (g[0] instanceof Array && g.length > 1) throw new Error("Parse Error: multiple actions possible at state: " + I + ", token: " + y);
        switch (g[0]) {
          case 1:
            e.push(y), h.push(u.yytext), o.push(u.yylloc), e.push(g[1]), y = null, U ? (y = U, U = null) : (E = u.yyleng, x = u.yytext, S = u.yylineno, n = u.yylloc, k > 0 && k--);
            break;
          case 2:
            if (b = this.productions_[g[1]][1], N.$ = h[h.length - b], N._$ = {
              first_line: o[o.length - (b || 1)].first_line,
              last_line: o[o.length - 1].last_line,
              first_column: o[o.length - (b || 1)].first_column,
              last_column: o[o.length - 1].last_column
            }, p && (N._$.range = [o[o.length - (b || 1)].range[0], o[o.length - 1].range[1]]), V = this.performAction.apply(N, [
              x,
              E,
              S,
              _.yy,
              g[1],
              h,
              o
            ].concat(R)), typeof V < "u") return V;
            b && (e = e.slice(0, -1 * b * 2), h = h.slice(0, -1 * b), o = o.slice(0, -1 * b)), e.push(this.productions_[g[1]][0]), h.push(N.$), o.push(N._$), X = T[e[e.length - 2]][e[e.length - 1]], e.push(X);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  };
  w.lexer = /* @__PURE__ */ (function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ s(function(i, a) {
        if (this.yy.parser) this.yy.parser.parseError(i, a);
        else throw new Error(i);
      }, "parseError"),
      setInput: /* @__PURE__ */ s(function(t, i) {
        return this.yy = i || this.yy || {}, this._input = t, 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__ */ s(function() {
        var t = this._input[0];
        return this.yytext += t, this.yyleng++, this.offset++, this.match += t, this.matched += t, t.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), t;
      }, "input"),
      unput: /* @__PURE__ */ s(function(t) {
        var i = t.length, a = t.split(/(?:\r\n?|\n)/g);
        this._input = t + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - i), this.offset -= i;
        var e = 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), a.length - 1 && (this.yylineno -= a.length - 1);
        var l = 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: a ? (a.length === e.length ? this.yylloc.first_column : 0) + e[e.length - a.length].length - a[0].length : this.yylloc.first_column - i
        }, this.options.ranges && (this.yylloc.range = [l[0], l[0] + this.yyleng - i]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ s(function() {
        return this._more = !0, this;
      }, "more"),
      reject: /* @__PURE__ */ s(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).
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
        return this;
      }, "reject"),
      less: /* @__PURE__ */ s(function(t) {
        this.unput(this.match.slice(t));
      }, "less"),
      pastInput: /* @__PURE__ */ s(function() {
        var t = this.matched.substr(0, this.matched.length - this.match.length);
        return (t.length > 20 ? "..." : "") + t.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ s(function() {
        var t = this.match;
        return t.length < 20 && (t += this._input.substr(0, 20 - t.length)), (t.substr(0, 20) + (t.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ s(function() {
        var t = this.pastInput(), i = new Array(t.length + 1).join("-");
        return t + this.upcomingInput() + `
` + i + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ s(function(t, i) {
        var a, e, l;
        if (this.options.backtrack_lexer && (l = {
          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 && (l.yylloc.range = this.yylloc.range.slice(0))), e = t[0].match(/(?:\r\n?|\n).*/g), e && (this.yylineno += e.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: e ? e[e.length - 1].length - e[e.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + t[0].length
        }, this.yytext += t[0], this.match += t[0], this.matches = t, 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(t[0].length), this.matched += t[0], a = this.performAction.call(this, this.yy, this, i, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), a) return a;
        if (this._backtrack) {
          for (var h in l) this[h] = l[h];
          return !1;
        }
        return !1;
      }, "test_match"),
      next: /* @__PURE__ */ s(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = !0);
        var t, i, a, e;
        this._more || (this.yytext = "", this.match = "");
        for (var l = this._currentRules(), h = 0; h < l.length; h++)
          if (a = this._input.match(this.rules[l[h]]), a && (!i || a[0].length > i[0].length)) {
            if (i = a, e = h, this.options.backtrack_lexer) {
              if (t = this.test_match(a, l[h]), t !== !1) return t;
              if (this._backtrack) {
                i = !1;
                continue;
              } else return !1;
            } else if (!this.options.flex) break;
          }
        return i ? (t = this.test_match(i, l[e]), t !== !1 ? t : !1) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      lex: /* @__PURE__ */ s(function() {
        var i = this.next();
        return i || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ s(function(i) {
        this.conditionStack.push(i);
      }, "begin"),
      popState: /* @__PURE__ */ s(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ s(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__ */ s(function(i) {
        return i = this.conditionStack.length - 1 - Math.abs(i || 0), i >= 0 ? this.conditionStack[i] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ s(function(i) {
        this.begin(i);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ s(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ s(function(i, a, e, l) {
        switch (e) {
          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 f() {
    this.yy = {};
  }
  return s(f, "Parser"), f.prototype = w, w.Parser = f, new f();
})();
G.parser = G;
var $ = G, j = [], D = [], M = /* @__PURE__ */ new Map(), pt = /* @__PURE__ */ s(() => {
  j = [], D = [], M = /* @__PURE__ */ new Map(), ht();
}, "clear"), dt = class {
  constructor(r, c, d = 0) {
    this.source = r, this.target = c, this.value = d;
  }
  static {
    s(this, "SankeyLink");
  }
}, gt = /* @__PURE__ */ s((r, c, d) => {
  j.push(new dt(r, c, d));
}, "addLink"), mt = class {
  constructor(r) {
    this.ID = r;
  }
  static {
    s(this, "SankeyNode");
  }
}, _t = {
  nodesMap: M,
  getConfig: /* @__PURE__ */ s(() => W().sankey, "getConfig"),
  getNodes: /* @__PURE__ */ s(() => D, "getNodes"),
  getLinks: /* @__PURE__ */ s(() => j, "getLinks"),
  getGraph: /* @__PURE__ */ s(() => ({
    nodes: D.map((r) => ({ id: r.ID })),
    links: j.map((r) => ({
      source: r.source.ID,
      target: r.target.ID,
      value: r.value
    }))
  }), "getGraph"),
  addLink: gt,
  findOrCreateNode: /* @__PURE__ */ s((r) => {
    r = ut.sanitizeText(r, W());
    let c = M.get(r);
    return c === void 0 && (c = new mt(r), M.set(r, c), D.push(c)), c;
  }, "findOrCreateNode"),
  getAccTitle: ft,
  setAccTitle: ot,
  getAccDescription: ct,
  setAccDescription: it,
  getDiagramTitle: rt,
  setDiagramTitle: lt,
  clear: pt
}, K = class Y {
  static {
    s(this, "Uid");
  }
  static {
    this.count = 0;
  }
  static next(c) {
    return new Y(c + ++Y.count);
  }
  constructor(c) {
    this.id = c, this.href = `#${c}`;
  }
  toString() {
    return "url(" + this.href + ")";
  }
}, xt = {
  left: Z,
  right: tt,
  center: et,
  justify: q
}, kt = { draw: /* @__PURE__ */ s(function(r, c, d, O) {
  const { securityLevel: w, sankey: f } = W(), t = yt.sankey;
  let i;
  w === "sandbox" && (i = L("#i" + c));
  const a = w === "sandbox" ? L(i.nodes()[0].contentDocument.body) : L("body"), e = w === "sandbox" ? a.select(`[id="${c}"]`) : L(`[id="${c}"]`), l = f?.width ?? t.width, h = f?.height ?? t.width, o = f?.useMaxWidth ?? t.useMaxWidth, T = f?.nodeAlignment ?? t.nodeAlignment, x = f?.prefix ?? t.prefix, S = f?.suffix ?? t.suffix, E = f?.showValues ?? t.showValues, k = O.db.getGraph(), F = xt[T];
  J().nodeId((n) => n.id).nodeWidth(10).nodePadding(10 + (E ? 15 : 0)).nodeAlign(F).extent([[0, 0], [l, h]])(k);
  const A = H(nt);
  e.append("g").attr("class", "nodes").selectAll(".node").data(k.nodes).join("g").attr("class", "node").attr("id", (n) => (n.uid = K.next("node-")).id).attr("transform", function(n) {
    return "translate(" + n.x0 + "," + n.y0 + ")";
  }).attr("x", (n) => n.x0).attr("y", (n) => n.y0).append("rect").attr("height", (n) => n.y1 - n.y0).attr("width", (n) => n.x1 - n.x0).attr("fill", (n) => A(n.id));
  const R = /* @__PURE__ */ s(({ id: n, value: p }) => E ? `${n}
${x}${Math.round(p * 100) / 100}${S}` : n, "getText");
  e.append("g").attr("class", "node-labels").attr("font-size", 14).selectAll("text").data(k.nodes).join("text").attr("x", (n) => n.x0 < l / 2 ? n.x1 + 6 : n.x0 - 6).attr("y", (n) => (n.y1 + n.y0) / 2).attr("dy", `${E ? "0" : "0.35"}em`).attr("text-anchor", (n) => n.x0 < l / 2 ? "start" : "end").text(R);
  const u = e.append("g").attr("class", "links").attr("fill", "none").attr("stroke-opacity", 0.5).selectAll(".link").data(k.links).join("g").attr("class", "link").style("mix-blend-mode", "multiply"), _ = f?.linkColor ?? "gradient";
  if (_ === "gradient") {
    const n = u.append("linearGradient").attr("id", (p) => (p.uid = K.next("linearGradient-")).id).attr("gradientUnits", "userSpaceOnUse").attr("x1", (p) => p.source.x1).attr("x2", (p) => p.target.x0);
    n.append("stop").attr("offset", "0%").attr("stop-color", (p) => A(p.source.id)), n.append("stop").attr("offset", "100%").attr("stop-color", (p) => A(p.target.id));
  }
  let v;
  switch (_) {
    case "gradient":
      v = /* @__PURE__ */ s((n) => n.uid, "coloring");
      break;
    case "source":
      v = /* @__PURE__ */ s((n) => A(n.source.id), "coloring");
      break;
    case "target":
      v = /* @__PURE__ */ s((n) => A(n.target.id), "coloring");
      break;
    default:
      v = _;
  }
  u.append("path").attr("d", st()).attr("stroke", v).attr("stroke-width", (n) => Math.max(1, n.width)), at(void 0, e, 0, o);
}, "draw") }, vt = /* @__PURE__ */ s((r) => r.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g, "").replaceAll(/([\n\r])+/g, `
`).trim(), "prepareTextForParsing"), bt = /* @__PURE__ */ s((r) => `.label {
      font-family: ${r.fontFamily};
    }`, "getStyles"), St = $.parse.bind($);
$.parse = (r) => St(vt(r));
var Tt = {
  styles: bt,
  parser: $,
  db: _t,
  renderer: kt
};
export {
  Tt as diagram
};

//# sourceMappingURL=sankeyDiagram-XADWPNL6.js.map