import { f as xt, i as kt, G as bt, K as vt, U as Lt, W as Et, p, Z as it, $ as wt, q as tt, au as At, a as St, H as Mt } from "./index-CNUFa5l3.js";
import { s as It } from "./ordinal-D9ksOc8y-CrGveXkB.js";
function $t(t) {
  for (var r = t.length / 6 | 0, s = Array(r), l = 0; l < r; ) s[l] = "#" + t.slice(l * 6, ++l * 6);
  return s;
}
var Pt = $t("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
function ht(t, r) {
  let s;
  if (r === void 0) for (let l of t) l != null && (s < l || s === void 0 && l >= l) && (s = l);
  else {
    let l = -1;
    for (let h of t) (h = r(h, ++l, t)) != null && (s < h || s === void 0 && h >= h) && (s = h);
  }
  return s;
}
function pt(t, r) {
  let s;
  if (r === void 0) for (let l of t) l != null && (s > l || s === void 0 && l >= l) && (s = l);
  else {
    let l = -1;
    for (let h of t) (h = r(h, ++l, t)) != null && (s > h || s === void 0 && h >= h) && (s = h);
  }
  return s;
}
function et(t, r) {
  let s = 0;
  if (r === void 0) for (let l of t) (l = +l) && (s += l);
  else {
    let l = -1;
    for (let h of t) (h = +r(h, ++l, t)) && (s += h);
  }
  return s;
}
function Nt(t) {
  return t.target.depth;
}
function Ct(t) {
  return t.depth;
}
function Ot(t, r) {
  return r - 1 - t.height;
}
function _t(t, r) {
  return t.sourceLinks.length ? t.depth : r - 1;
}
function Tt(t) {
  return t.targetLinks.length ? t.depth : t.sourceLinks.length ? pt(t.sourceLinks, Nt) - 1 : 0;
}
function X(t) {
  return function() {
    return t;
  };
}
function ut(t, r) {
  return Q(t.source, r.source) || t.index - r.index;
}
function ct(t, r) {
  return Q(t.target, r.target) || t.index - r.index;
}
function Q(t, r) {
  return t.y0 - r.y0;
}
function nt(t) {
  return t.value;
}
function Dt(t) {
  return t.index;
}
function jt(t) {
  return t.nodes;
}
function zt(t) {
  return t.links;
}
function ft(t, r) {
  let s = t.get(r);
  if (!s) throw Error("missing: " + r);
  return s;
}
function yt({ nodes: t }) {
  for (let r of t) {
    let s = r.y0, l = s;
    for (let h of r.sourceLinks) h.y0 = s + h.width / 2, s += h.width;
    for (let h of r.targetLinks) h.y1 = l + h.width / 2, l += h.width;
  }
}
function Ft() {
  let t = 0, r = 0, s = 1, l = 1, h = 24, f = 8, n, y = Dt, u = _t, d, m, g = jt, A = zt, v = 6;
  function x() {
    let i = {
      nodes: g.apply(null, arguments),
      links: A.apply(null, arguments)
    };
    return $(i), I(i), T(i), C(i), S(i), yt(i), i;
  }
  x.update = function(i) {
    return yt(i), i;
  }, x.nodeId = function(i) {
    return arguments.length ? (y = typeof i == "function" ? i : X(i), x) : y;
  }, x.nodeAlign = function(i) {
    return arguments.length ? (u = typeof i == "function" ? i : X(i), x) : u;
  }, x.nodeSort = function(i) {
    return arguments.length ? (d = i, x) : d;
  }, x.nodeWidth = function(i) {
    return arguments.length ? (h = +i, x) : h;
  }, x.nodePadding = function(i) {
    return arguments.length ? (f = n = +i, x) : f;
  }, x.nodes = function(i) {
    return arguments.length ? (g = typeof i == "function" ? i : X(i), x) : g;
  }, x.links = function(i) {
    return arguments.length ? (A = typeof i == "function" ? i : X(i), x) : A;
  }, x.linkSort = function(i) {
    return arguments.length ? (m = i, x) : m;
  }, x.size = function(i) {
    return arguments.length ? (t = r = 0, s = +i[0], l = +i[1], x) : [s - t, l - r];
  }, x.extent = function(i) {
    return arguments.length ? (t = +i[0][0], s = +i[1][0], r = +i[0][1], l = +i[1][1], x) : [[t, r], [s, l]];
  }, x.iterations = function(i) {
    return arguments.length ? (v = +i, x) : v;
  };
  function $({ nodes: i, links: c }) {
    for (let [o, a] of i.entries()) a.index = o, a.sourceLinks = [], a.targetLinks = [];
    let e = new Map(i.map((o, a) => [y(o, a, i), o]));
    for (let [o, a] of c.entries()) {
      a.index = o;
      let { source: _, target: b } = a;
      typeof _ != "object" && (_ = a.source = ft(e, _)), typeof b != "object" && (b = a.target = ft(e, b)), _.sourceLinks.push(a), b.targetLinks.push(a);
    }
    if (m != null) for (let { sourceLinks: o, targetLinks: a } of i) o.sort(m), a.sort(m);
  }
  function I({ nodes: i }) {
    for (let c of i) c.value = c.fixedValue === void 0 ? Math.max(et(c.sourceLinks, nt), et(c.targetLinks, nt)) : c.fixedValue;
  }
  function T({ nodes: i }) {
    let c = i.length, e = new Set(i), o = /* @__PURE__ */ new Set(), a = 0;
    for (; e.size; ) {
      for (let _ of e) {
        _.depth = a;
        for (let { target: b } of _.sourceLinks) o.add(b);
      }
      if (++a > c) throw Error("circular link");
      e = o, o = /* @__PURE__ */ new Set();
    }
  }
  function C({ nodes: i }) {
    let c = i.length, e = new Set(i), o = /* @__PURE__ */ new Set(), a = 0;
    for (; e.size; ) {
      for (let _ of e) {
        _.height = a;
        for (let { source: b } of _.targetLinks) o.add(b);
      }
      if (++a > c) throw Error("circular link");
      e = o, o = /* @__PURE__ */ new Set();
    }
  }
  function P({ nodes: i }) {
    let c = ht(i, (a) => a.depth) + 1, e = (s - t - h) / (c - 1), o = Array(c);
    for (let a of i) {
      let _ = Math.max(0, Math.min(c - 1, Math.floor(u.call(null, a, c))));
      a.layer = _, a.x0 = t + _ * e, a.x1 = a.x0 + h, o[_] ? o[_].push(a) : o[_] = [a];
    }
    if (d) for (let a of o) a.sort(d);
    return o;
  }
  function k(i) {
    let c = pt(i, (e) => (l - r - (e.length - 1) * n) / et(e, nt));
    for (let e of i) {
      let o = r;
      for (let a of e) {
        a.y0 = o, a.y1 = o + a.value * c, o = a.y1 + n;
        for (let _ of a.sourceLinks) _.width = _.value * c;
      }
      o = (l - o + n) / (e.length + 1);
      for (let a = 0; a < e.length; ++a) {
        let _ = e[a];
        _.y0 += o * (a + 1), _.y1 += o * (a + 1);
      }
      F(e);
    }
  }
  function S(i) {
    let c = P(i);
    n = Math.min(f, (l - r) / (ht(c, (e) => e.length) - 1)), k(c);
    for (let e = 0; e < v; ++e) {
      let o = 0.99 ** e, a = Math.max(1 - o, (e + 1) / v);
      j(c, o, a), D(c, o, a);
    }
  }
  function D(i, c, e) {
    for (let o = 1, a = i.length; o < a; ++o) {
      let _ = i[o];
      for (let b of _) {
        let E = 0, G = 0;
        for (let { source: V, value: K } of b.targetLinks) {
          let at = K * (b.layer - V.layer);
          E += M(V, b) * at, G += at;
        }
        if (!(G > 0)) continue;
        let R = (E / G - b.y0) * c;
        b.y0 += R, b.y1 += R, L(b);
      }
      d === void 0 && _.sort(Q), U(_, e);
    }
  }
  function j(i, c, e) {
    for (let o = i.length - 2; o >= 0; --o) {
      let a = i[o];
      for (let _ of a) {
        let b = 0, E = 0;
        for (let { target: R, value: V } of _.sourceLinks) {
          let K = V * (R.layer - _.layer);
          b += w(_, R) * K, E += K;
        }
        if (!(E > 0)) continue;
        let G = (b / E - _.y0) * c;
        _.y0 += G, _.y1 += G, L(_);
      }
      d === void 0 && a.sort(Q), U(a, e);
    }
  }
  function U(i, c) {
    let e = i.length >> 1, o = i[e];
    z(i, o.y0 - n, e - 1, c), N(i, o.y1 + n, e + 1, c), z(i, l, i.length - 1, c), N(i, r, 0, c);
  }
  function N(i, c, e, o) {
    for (; e < i.length; ++e) {
      let a = i[e], _ = (c - a.y0) * o;
      _ > 1e-6 && (a.y0 += _, a.y1 += _), c = a.y1 + n;
    }
  }
  function z(i, c, e, o) {
    for (; e >= 0; --e) {
      let a = i[e], _ = (a.y1 - c) * o;
      _ > 1e-6 && (a.y0 -= _, a.y1 -= _), c = a.y0 - n;
    }
  }
  function L({ sourceLinks: i, targetLinks: c }) {
    if (m === void 0) {
      for (let { source: { sourceLinks: e } } of c) e.sort(ct);
      for (let { target: { targetLinks: e } } of i) e.sort(ut);
    }
  }
  function F(i) {
    if (m === void 0) for (let { sourceLinks: c, targetLinks: e } of i) c.sort(ct), e.sort(ut);
  }
  function M(i, c) {
    let e = i.y0 - (i.sourceLinks.length - 1) * n / 2;
    for (let { target: o, width: a } of i.sourceLinks) {
      if (o === c) break;
      e += a + n;
    }
    for (let { source: o, width: a } of c.targetLinks) {
      if (o === i) break;
      e -= a;
    }
    return e;
  }
  function w(i, c) {
    let e = c.y0 - (c.targetLinks.length - 1) * n / 2;
    for (let { source: o, width: a } of c.targetLinks) {
      if (o === i) break;
      e += a + n;
    }
    for (let { target: o, width: a } of i.sourceLinks) {
      if (o === c) break;
      e -= a;
    }
    return e;
  }
  return x;
}
var rt = Math.PI, st = 2 * rt, W = 1e-6, Wt = st - W;
function ot() {
  this._x0 = this._y0 = this._x1 = this._y1 = null, this._ = "";
}
function mt() {
  return new ot();
}
ot.prototype = mt.prototype = {
  constructor: ot,
  moveTo: function(t, r) {
    this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +r);
  },
  closePath: function() {
    this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._ += "Z");
  },
  lineTo: function(t, r) {
    this._ += "L" + (this._x1 = +t) + "," + (this._y1 = +r);
  },
  quadraticCurveTo: function(t, r, s, l) {
    this._ += "Q" + +t + "," + +r + "," + (this._x1 = +s) + "," + (this._y1 = +l);
  },
  bezierCurveTo: function(t, r, s, l, h, f) {
    this._ += "C" + +t + "," + +r + "," + +s + "," + +l + "," + (this._x1 = +h) + "," + (this._y1 = +f);
  },
  arcTo: function(t, r, s, l, h) {
    t = +t, r = +r, s = +s, l = +l, h = +h;
    var f = this._x1, n = this._y1, y = s - t, u = l - r, d = f - t, m = n - r, g = d * d + m * m;
    if (h < 0) throw Error("negative radius: " + h);
    if (this._x1 === null) this._ += "M" + (this._x1 = t) + "," + (this._y1 = r);
    else if (g > W) if (!(Math.abs(m * y - u * d) > W) || !h) this._ += "L" + (this._x1 = t) + "," + (this._y1 = r);
    else {
      var A = s - f, v = l - n, x = y * y + u * u, $ = A * A + v * v, I = Math.sqrt(x), T = Math.sqrt(g), C = h * Math.tan((rt - Math.acos((x + g - $) / (2 * I * T))) / 2), P = C / T, k = C / I;
      Math.abs(P - 1) > W && (this._ += "L" + (t + P * d) + "," + (r + P * m)), this._ += "A" + h + "," + h + ",0,0," + +(m * A > d * v) + "," + (this._x1 = t + k * y) + "," + (this._y1 = r + k * u);
    }
  },
  arc: function(t, r, s, l, h, f) {
    t = +t, r = +r, s = +s, f = !!f;
    var n = s * Math.cos(l), y = s * Math.sin(l), u = t + n, d = r + y, m = 1 ^ f, g = f ? l - h : h - l;
    if (s < 0) throw Error("negative radius: " + s);
    this._x1 === null ? this._ += "M" + u + "," + d : (Math.abs(this._x1 - u) > W || Math.abs(this._y1 - d) > W) && (this._ += "L" + u + "," + d), s && (g < 0 && (g = g % st + st), g > Wt ? this._ += "A" + s + "," + s + ",0,1," + m + "," + (t - n) + "," + (r - y) + "A" + s + "," + s + ",0,1," + m + "," + (this._x1 = u) + "," + (this._y1 = d) : g > W && (this._ += "A" + s + "," + s + ",0," + +(g >= rt) + "," + m + "," + (this._x1 = t + s * Math.cos(h)) + "," + (this._y1 = r + s * Math.sin(h))));
  },
  rect: function(t, r, s, l) {
    this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +r) + "h" + +s + "v" + +l + "h" + -s + "Z";
  },
  toString: function() {
    return this._;
  }
};
function dt(t) {
  return function() {
    return t;
  };
}
function Ut(t) {
  return t[0];
}
function Gt(t) {
  return t[1];
}
var qt = Array.prototype.slice;
function Bt(t) {
  return t.source;
}
function Rt(t) {
  return t.target;
}
function Vt(t) {
  var r = Bt, s = Rt, l = Ut, h = Gt, f = null;
  function n() {
    var y, u = qt.call(arguments), d = r.apply(this, u), m = s.apply(this, u);
    if (f || (f = y = mt()), t(f, +l.apply(this, (u[0] = d, u)), +h.apply(this, u), +l.apply(this, (u[0] = m, u)), +h.apply(this, u)), y) return f = null, y + "" || null;
  }
  return n.source = function(y) {
    return arguments.length ? (r = y, n) : r;
  }, n.target = function(y) {
    return arguments.length ? (s = y, n) : s;
  }, n.x = function(y) {
    return arguments.length ? (l = typeof y == "function" ? y : dt(+y), n) : l;
  }, n.y = function(y) {
    return arguments.length ? (h = typeof y == "function" ? y : dt(+y), n) : h;
  }, n.context = function(y) {
    return arguments.length ? (f = y ?? null, n) : f;
  }, n;
}
function Kt(t, r, s, l, h) {
  t.moveTo(r, s), t.bezierCurveTo(r = (r + l) / 2, s, r, h, l, h);
}
function Xt() {
  return Vt(Kt);
}
function Zt(t) {
  return [t.source.x1, t.y0];
}
function Ht(t) {
  return [t.target.x0, t.y1];
}
function Qt() {
  return Xt().source(Zt).target(Ht);
}
var lt = function() {
  var t = /* @__PURE__ */ p(function(n, y, u, d) {
    for (u || (u = {}), d = n.length; d--; u[n[d]] = y) ;
    return u;
  }, "o"), r = [1, 9], s = [1, 10], l = [
    1,
    5,
    10,
    12
  ], h = {
    trace: /* @__PURE__ */ p(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__ */ p(function(n, y, u, d, m, g, A) {
      var v = g.length - 1;
      switch (m) {
        case 7:
          let x = d.findOrCreateNode(g[v - 4].trim().replaceAll('""', '"')), $ = d.findOrCreateNode(g[v - 2].trim().replaceAll('""', '"')), I = parseFloat(g[v].trim());
          d.addLink(x, $, I);
          break;
        case 8:
        case 9:
        case 11:
          this.$ = g[v];
          break;
        case 10:
          this.$ = g[v - 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: r,
        20: s
      },
      {
        1: [2, 6],
        7: 11,
        10: [1, 12]
      },
      t(s, [2, 4], {
        9: 13,
        5: [1, 14]
      }),
      { 12: [1, 15] },
      t(l, [2, 8]),
      t(l, [2, 9]),
      { 19: [1, 16] },
      t(l, [2, 11]),
      { 1: [2, 1] },
      { 1: [2, 5] },
      t(s, [2, 2]),
      {
        6: 17,
        8: 5,
        15: 6,
        16: 7,
        17: 8,
        18: r,
        20: s
      },
      {
        15: 18,
        16: 7,
        17: 8,
        18: r,
        20: s
      },
      { 18: [1, 19] },
      t(s, [2, 3]),
      { 12: [1, 20] },
      t(l, [2, 10]),
      {
        15: 21,
        16: 7,
        17: 8,
        18: r,
        20: s
      },
      t([
        1,
        5,
        10
      ], [2, 7])
    ],
    defaultActions: {
      11: [2, 1],
      12: [2, 5]
    },
    parseError: /* @__PURE__ */ p(function(n, y) {
      if (y.recoverable) this.trace(n);
      else {
        var u = Error(n);
        throw u.hash = y, u;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ p(function(n) {
      var y = this, u = [0], d = [], m = [null], g = [], A = this.table, v = "", x = 0, $ = 0, I = 0, T = 2, C = 1, P = g.slice.call(arguments, 1), k = Object.create(this.lexer), S = { yy: {} };
      for (var D in this.yy) Object.prototype.hasOwnProperty.call(this.yy, D) && (S.yy[D] = this.yy[D]);
      k.setInput(n, S.yy), S.yy.lexer = k, S.yy.parser = this, k.yylloc === void 0 && (k.yylloc = {});
      var j = k.yylloc;
      g.push(j);
      var U = k.options && k.options.ranges;
      typeof S.yy.parseError == "function" ? this.parseError = S.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function N(E) {
        u.length -= 2 * E, m.length -= E, g.length -= E;
      }
      p(N, "popStack");
      function z() {
        var E = d.pop() || k.lex() || C;
        return typeof E != "number" && (E instanceof Array && (d = E, E = d.pop()), E = y.symbols_[E] || E), E;
      }
      p(z, "lex");
      for (var L, F, M, w, i, c = {}, e, o, a, _; ; ) {
        if (M = u[u.length - 1], this.defaultActions[M] ? w = this.defaultActions[M] : (L ?? (L = z()), w = A[M] && A[M][L]), w === void 0 || !w.length || !w[0]) {
          var b = "";
          for (e in _ = [], A[M]) this.terminals_[e] && e > T && _.push("'" + this.terminals_[e] + "'");
          b = k.showPosition ? "Parse error on line " + (x + 1) + `:
` + k.showPosition() + `
Expecting ` + _.join(", ") + ", got '" + (this.terminals_[L] || L) + "'" : "Parse error on line " + (x + 1) + ": Unexpected " + (L == C ? "end of input" : "'" + (this.terminals_[L] || L) + "'"), this.parseError(b, {
            text: k.match,
            token: this.terminals_[L] || L,
            line: k.yylineno,
            loc: j,
            expected: _
          });
        }
        if (w[0] instanceof Array && w.length > 1) throw Error("Parse Error: multiple actions possible at state: " + M + ", token: " + L);
        switch (w[0]) {
          case 1:
            u.push(L), m.push(k.yytext), g.push(k.yylloc), u.push(w[1]), L = null, F ? (L = F, F = null) : ($ = k.yyleng, v = k.yytext, x = k.yylineno, j = k.yylloc, I > 0);
            break;
          case 2:
            if (o = this.productions_[w[1]][1], c.$ = m[m.length - o], c._$ = {
              first_line: g[g.length - (o || 1)].first_line,
              last_line: g[g.length - 1].last_line,
              first_column: g[g.length - (o || 1)].first_column,
              last_column: g[g.length - 1].last_column
            }, U && (c._$.range = [g[g.length - (o || 1)].range[0], g[g.length - 1].range[1]]), i = this.performAction.apply(c, [
              v,
              $,
              x,
              S.yy,
              w[1],
              m,
              g
            ].concat(P)), i !== void 0) return i;
            o && (u = u.slice(0, -1 * o * 2), m = m.slice(0, -1 * o), g = g.slice(0, -1 * o)), u.push(this.productions_[w[1]][0]), m.push(c.$), g.push(c._$), a = A[u[u.length - 2]][u[u.length - 1]], u.push(a);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  };
  h.lexer = /* @__PURE__ */ function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ p(function(n, y) {
        if (this.yy.parser) this.yy.parser.parseError(n, y);
        else throw Error(n);
      }, "parseError"),
      setInput: /* @__PURE__ */ p(function(n, y) {
        return this.yy = y || this.yy || {}, this._input = n, 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__ */ p(function() {
        var n = this._input[0];
        return this.yytext += n, this.yyleng++, this.offset++, this.match += n, this.matched += n, n.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), n;
      }, "input"),
      unput: /* @__PURE__ */ p(function(n) {
        var y = n.length, u = n.split(/(?:\r\n?|\n)/g);
        this._input = n + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - y), this.offset -= y;
        var d = 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), u.length - 1 && (this.yylineno -= u.length - 1);
        var m = 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: u ? (u.length === d.length ? this.yylloc.first_column : 0) + d[d.length - u.length].length - u[0].length : this.yylloc.first_column - y
        }, this.options.ranges && (this.yylloc.range = [m[0], m[0] + this.yyleng - y]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ p(function() {
        return this._more = !0, this;
      }, "more"),
      reject: /* @__PURE__ */ p(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__ */ p(function(n) {
        this.unput(this.match.slice(n));
      }, "less"),
      pastInput: /* @__PURE__ */ p(function() {
        var n = this.matched.substr(0, this.matched.length - this.match.length);
        return (n.length > 20 ? "..." : "") + n.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ p(function() {
        var n = this.match;
        return n.length < 20 && (n += this._input.substr(0, 20 - n.length)), (n.substr(0, 20) + (n.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ p(function() {
        var n = this.pastInput(), y = Array(n.length + 1).join("-");
        return n + this.upcomingInput() + `
` + y + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ p(function(n, y) {
        var u, d, m;
        if (this.options.backtrack_lexer && (m = {
          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 && (m.yylloc.range = this.yylloc.range.slice(0))), d = n[0].match(/(?:\r\n?|\n).*/g), d && (this.yylineno += d.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: d ? d[d.length - 1].length - d[d.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + n[0].length
        }, this.yytext += n[0], this.match += n[0], this.matches = n, 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(n[0].length), this.matched += n[0], u = this.performAction.call(this, this.yy, this, y, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), u) return u;
        if (this._backtrack) {
          for (var g in m) this[g] = m[g];
          return !1;
        }
        return !1;
      }, "test_match"),
      next: /* @__PURE__ */ p(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = !0);
        var n, y, u, d;
        this._more || (this.yytext = "", this.match = "");
        for (var m = this._currentRules(), g = 0; g < m.length; g++) if (u = this._input.match(this.rules[m[g]]), u && (!y || u[0].length > y[0].length)) {
          if (y = u, d = g, this.options.backtrack_lexer) {
            if (n = this.test_match(u, m[g]), n !== !1) return n;
            if (this._backtrack) {
              y = !1;
              continue;
            } else return !1;
          } else if (!this.options.flex) break;
        }
        return y ? (n = this.test_match(y, m[d]), n === !1 ? !1 : n) : 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__ */ p(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ p(function(n) {
        this.conditionStack.push(n);
      }, "begin"),
      popState: /* @__PURE__ */ p(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ p(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__ */ p(function(n) {
        return n = this.conditionStack.length - 1 - Math.abs(n || 0), n >= 0 ? this.conditionStack[n] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ p(function(n) {
        this.begin(n);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ p(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ p(function(n, y, u, d) {
        switch (u) {
          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 p(f, "Parser"), f.prototype = h, h.Parser = f, new f();
}();
lt.parser = lt;
var Y = lt, J = [], Z = [], H = /* @__PURE__ */ new Map(), Yt = /* @__PURE__ */ p(() => {
  J = [], Z = [], H = /* @__PURE__ */ new Map(), Mt();
}, "clear"), q, Jt = (q = class {
  constructor(r, s, l = 0) {
    this.source = r, this.target = s, this.value = l;
  }
}, p(q, "SankeyLink"), q), te = /* @__PURE__ */ p((t, r, s) => {
  J.push(new Jt(t, r, s));
}, "addLink"), B, ee = (B = class {
  constructor(r) {
    this.ID = r;
  }
}, p(B, "SankeyNode"), B), ne = {
  nodesMap: H,
  getConfig: /* @__PURE__ */ p(() => it().sankey, "getConfig"),
  getNodes: /* @__PURE__ */ p(() => Z, "getNodes"),
  getLinks: /* @__PURE__ */ p(() => J, "getLinks"),
  getGraph: /* @__PURE__ */ p(() => ({
    nodes: Z.map((t) => ({ id: t.ID })),
    links: J.map((t) => ({
      source: t.source.ID,
      target: t.target.ID,
      value: t.value
    }))
  }), "getGraph"),
  addLink: te,
  findOrCreateNode: /* @__PURE__ */ p((t) => {
    t = St.sanitizeText(t, it());
    let r = H.get(t);
    return r === void 0 && (r = new ee(t), H.set(t, r), Z.push(r)), r;
  }, "findOrCreateNode"),
  getAccTitle: Et,
  setAccTitle: Lt,
  getAccDescription: vt,
  setAccDescription: bt,
  getDiagramTitle: kt,
  setDiagramTitle: xt,
  clear: Yt
}, O, gt = (O = class {
  static next(r) {
    return new O(r + ++O.count);
  }
  constructor(r) {
    this.id = r, this.href = `#${r}`;
  }
  toString() {
    return "url(" + this.href + ")";
  }
}, p(O, "Uid"), O.count = 0, O), ie = {
  left: Ct,
  right: Ot,
  center: Tt,
  justify: _t
}, re = /* @__PURE__ */ p((t) => {
  let r = 0, s = 0;
  for (let l of t) {
    let h = l.value ?? 0;
    h > r && (r = h, s = l.layer ?? 0);
  }
  return s;
}, "findCentralNodeLayer"), se = { draw: /* @__PURE__ */ p(function(t, r, s, l) {
  let { securityLevel: h, sankey: f } = it(), n = wt.sankey, y;
  h === "sandbox" && (y = tt("#i" + r));
  let u = tt(h === "sandbox" ? y.nodes()[0].contentDocument.body : "body"), d = h === "sandbox" ? u.select(`[id="${r}"]`) : tt(`[id="${r}"]`), m = (f == null ? void 0 : f.width) ?? n.width, g = (f == null ? void 0 : f.height) ?? n.width, A = (f == null ? void 0 : f.useMaxWidth) ?? n.useMaxWidth, v = (f == null ? void 0 : f.nodeAlignment) ?? n.nodeAlignment, x = (f == null ? void 0 : f.prefix) ?? n.prefix, $ = (f == null ? void 0 : f.suffix) ?? n.suffix, I = (f == null ? void 0 : f.showValues) ?? n.showValues, T = (f == null ? void 0 : f.nodeWidth) ?? n.nodeWidth ?? 10, C = (f == null ? void 0 : f.nodePadding) ?? n.nodePadding ?? 12, P = (f == null ? void 0 : f.labelStyle) ?? n.labelStyle ?? "legacy", k = (f == null ? void 0 : f.nodeColors) ?? {}, S = l.db.getGraph(), D = ie[v];
  Ft().nodeId((e) => e.id).nodeWidth(T).nodePadding(C + (I ? 15 : 0)).nodeAlign(D).extent([[0, 0], [m, g]])(S);
  let j = re(S.nodes), U = It(Pt), N = /* @__PURE__ */ p((e) => k[e] ?? U(e), "getNodeColor");
  d.append("g").attr("class", "nodes").selectAll(".node").data(S.nodes).join("g").attr("class", "node").attr("id", (e) => (e.uid = gt.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) => N(e.id));
  let z = /* @__PURE__ */ p(({ id: e, value: o }) => I ? `${e}
${x}${Math.round(o * 100) / 100}${$}` : e, "getText"), L = /* @__PURE__ */ p((e) => P === "outlined" ? (e.layer ?? 0) < j ? {
    x: e.x0 - 6,
    anchor: "end"
  } : {
    x: e.x1 + 6,
    anchor: "start"
  } : e.x0 < m / 2 ? {
    x: e.x1 + 6,
    anchor: "start"
  } : {
    x: e.x0 - 6,
    anchor: "end"
  }, "getLabelPosition"), F = d.append("g").attr("class", "node-labels").attr("font-size", 14), M = /* @__PURE__ */ p((e) => F.selectAll(e ? `.${e}` : "text").data(S.nodes).join("text").attr("class", e ?? null).attr("x", (o) => L(o).x).attr("y", (o) => (o.y1 + o.y0) / 2).attr("dy", `${I ? "0" : "0.35"}em`).attr("text-anchor", (o) => L(o).anchor).text(z), "appendLabel");
  P === "outlined" ? (M("sankey-label-bg"), M("sankey-label-fg")) : M();
  let w = d.append("g").attr("class", "links").attr("fill", "none").attr("stroke-opacity", 0.5).selectAll(".link").data(S.links).join("g").attr("class", "link").style("mix-blend-mode", "multiply"), i = (f == null ? void 0 : f.linkColor) ?? "gradient";
  if (i === "gradient") {
    let e = w.append("linearGradient").attr("id", (o) => (o.uid = gt.next("linearGradient-")).id).attr("gradientUnits", "userSpaceOnUse").attr("x1", (o) => o.source.x1).attr("x2", (o) => o.target.x0);
    e.append("stop").attr("offset", "0%").attr("stop-color", (o) => N(o.source.id)), e.append("stop").attr("offset", "100%").attr("stop-color", (o) => N(o.target.id));
  }
  let c;
  switch (i) {
    case "gradient":
      c = /* @__PURE__ */ p((e) => e.uid, "coloring");
      break;
    case "source":
      c = /* @__PURE__ */ p((e) => N(e.source.id), "coloring");
      break;
    case "target":
      c = /* @__PURE__ */ p((e) => N(e.target.id), "coloring");
      break;
    default:
      c = i;
  }
  w.append("path").attr("d", Qt()).attr("stroke", c).attr("stroke-width", (e) => Math.max(1, e.width)), At(void 0, d, 0, A);
}, "draw") }, oe = /* @__PURE__ */ p((t) => t.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g, "").replaceAll(/([\n\r])+/g, `
`).trim(), "prepareTextForParsing"), le = /* @__PURE__ */ p((t) => `.label {
    font-family: ${t.fontFamily};
  }

  .node-labels {
    font-family: ${t.fontFamily};
  }

  /* Outlined label style - background stroke for better readability */
  .sankey-label-bg {
    stroke: ${t.mainBkg || t.background || "#fff"};
    stroke-width: 4px;
    stroke-linejoin: round;
    paint-order: stroke;
  }

  /* Foreground label text */
  .sankey-label-fg {
    fill: ${t.textColor};
  }

  /* Node styling */
  .node rect {
    shape-rendering: crispEdges;
  }

  /* Link styling */
  .link {
    fill: none;
    stroke-opacity: 0.5;
    mix-blend-mode: multiply;
  }
`, "getStyles"), ae = Y.parse.bind(Y);
Y.parse = (t) => ae(oe(t));
var ce = {
  styles: le,
  parser: Y,
  db: ne,
  renderer: se
};
export {
  ce as diagram
};
