var _a, _b, _c;
import "./purify.es-DT70lfR0.js";
import { n as ordinal } from "./ordinal-B43ZeR68.js";
import { t as colors_default } from "./colors-CQAOa8cK.js";
import { r as __name, t as select_default } from "./src-Bf2iLOlr.js";
import { B as setAccTitle, C as getDiagramTitle, G as setupGraphViewbox, U as setDiagramTitle, _ as getAccDescription, a as clear, b as getConfig2, s as common_default, u as defaultConfig2, v as getAccTitle, z as setAccDescription } from "./chunk-ABZYJK2D-D0cLy8Bb.js";
var Tableau10_default = colors_default("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
function max(t, l) {
  let u;
  if (l === void 0) for (let l2 of t) l2 != null && (u < l2 || u === void 0 && l2 >= l2) && (u = l2);
  else {
    let d = -1;
    for (let f of t) (f = l(f, ++d, t)) != null && (u < f || u === void 0 && f >= f) && (u = f);
  }
  return u;
}
function min(t, l) {
  let u;
  if (l === void 0) for (let l2 of t) l2 != null && (u > l2 || u === void 0 && l2 >= l2) && (u = l2);
  else {
    let d = -1;
    for (let f of t) (f = l(f, ++d, t)) != null && (u > f || u === void 0 && f >= f) && (u = f);
  }
  return u;
}
function sum(t, l) {
  let u = 0;
  if (l === void 0) for (let l2 of t) (l2 = +l2) && (u += l2);
  else {
    let d = -1;
    for (let f of t) (f = +l(f, ++d, t)) && (u += f);
  }
  return u;
}
function targetDepth(t) {
  return t.target.depth;
}
function left(t) {
  return t.depth;
}
function right(t, l) {
  return l - 1 - t.height;
}
function justify(t, l) {
  return t.sourceLinks.length ? t.depth : l - 1;
}
function center(t) {
  return t.targetLinks.length ? t.depth : t.sourceLinks.length ? min(t.sourceLinks, targetDepth) - 1 : 0;
}
function constant(t) {
  return function() {
    return t;
  };
}
function ascendingSourceBreadth(t, l) {
  return ascendingBreadth(t.source, l.source) || t.index - l.index;
}
function ascendingTargetBreadth(t, l) {
  return ascendingBreadth(t.target, l.target) || t.index - l.index;
}
function ascendingBreadth(t, l) {
  return t.y0 - l.y0;
}
function value(t) {
  return t.value;
}
function defaultId(t) {
  return t.index;
}
function defaultNodes(t) {
  return t.nodes;
}
function defaultLinks(t) {
  return t.links;
}
function find(t, l) {
  let u = t.get(l);
  if (!u) throw Error("missing: " + l);
  return u;
}
function computeLinkBreadths({ nodes: t }) {
  for (let l of t) {
    let t2 = l.y0, u = t2;
    for (let u2 of l.sourceLinks) u2.y0 = t2 + u2.width / 2, t2 += u2.width;
    for (let t3 of l.targetLinks) t3.y1 = u + t3.width / 2, u += t3.width;
  }
}
function Sankey() {
  let t = 0, l = 0, u = 1, d = 1, f = 24, p = 8, m, h = defaultId, g = justify, _, v, b = defaultNodes, S = defaultLinks, C = 6;
  function w() {
    let t2 = {
      nodes: b.apply(null, arguments),
      links: S.apply(null, arguments)
    };
    return T(t2), k(t2), A(t2), j(t2), W(t2), computeLinkBreadths(t2), t2;
  }
  w.update = function(t2) {
    return computeLinkBreadths(t2), t2;
  }, w.nodeId = function(t2) {
    return arguments.length ? (h = typeof t2 == "function" ? t2 : constant(t2), w) : h;
  }, w.nodeAlign = function(t2) {
    return arguments.length ? (g = typeof t2 == "function" ? t2 : constant(t2), w) : g;
  }, w.nodeSort = function(t2) {
    return arguments.length ? (_ = t2, w) : _;
  }, w.nodeWidth = function(t2) {
    return arguments.length ? (f = +t2, w) : f;
  }, w.nodePadding = function(t2) {
    return arguments.length ? (p = m = +t2, w) : p;
  }, w.nodes = function(t2) {
    return arguments.length ? (b = typeof t2 == "function" ? t2 : constant(t2), w) : b;
  }, w.links = function(t2) {
    return arguments.length ? (S = typeof t2 == "function" ? t2 : constant(t2), w) : S;
  }, w.linkSort = function(t2) {
    return arguments.length ? (v = t2, w) : v;
  }, w.size = function(f2) {
    return arguments.length ? (t = l = 0, u = +f2[0], d = +f2[1], w) : [u - t, d - l];
  }, w.extent = function(f2) {
    return arguments.length ? (t = +f2[0][0], u = +f2[1][0], l = +f2[0][1], d = +f2[1][1], w) : [[t, l], [u, d]];
  }, w.iterations = function(t2) {
    return arguments.length ? (C = +t2, w) : C;
  };
  function T({ nodes: t2, links: l2 }) {
    for (let [l3, u3] of t2.entries()) u3.index = l3, u3.sourceLinks = [], u3.targetLinks = [];
    let u2 = new Map(t2.map((l3, u3) => [h(l3, u3, t2), l3]));
    for (let [t3, d2] of l2.entries()) {
      d2.index = t3;
      let { source: l3, target: f2 } = d2;
      typeof l3 != "object" && (l3 = d2.source = find(u2, l3)), typeof f2 != "object" && (f2 = d2.target = find(u2, f2)), l3.sourceLinks.push(d2), f2.targetLinks.push(d2);
    }
    if (v != null) for (let { sourceLinks: l3, targetLinks: u3 } of t2) l3.sort(v), u3.sort(v);
  }
  function k({ nodes: t2 }) {
    for (let l2 of t2) l2.value = l2.fixedValue === void 0 ? Math.max(sum(l2.sourceLinks, value), sum(l2.targetLinks, value)) : l2.fixedValue;
  }
  function A({ nodes: t2 }) {
    let l2 = t2.length, u2 = new Set(t2), d2 = /* @__PURE__ */ new Set(), f2 = 0;
    for (; u2.size; ) {
      for (let t3 of u2) {
        t3.depth = f2;
        for (let { target: l3 } of t3.sourceLinks) d2.add(l3);
      }
      if (++f2 > l2) throw Error("circular link");
      u2 = d2, d2 = /* @__PURE__ */ new Set();
    }
  }
  function j({ nodes: t2 }) {
    let l2 = t2.length, u2 = new Set(t2), d2 = /* @__PURE__ */ new Set(), f2 = 0;
    for (; u2.size; ) {
      for (let t3 of u2) {
        t3.height = f2;
        for (let { source: l3 } of t3.targetLinks) d2.add(l3);
      }
      if (++f2 > l2) throw Error("circular link");
      u2 = d2, d2 = /* @__PURE__ */ new Set();
    }
  }
  function N({ nodes: l2 }) {
    let d2 = max(l2, (t2) => t2.depth) + 1, p2 = (u - t - f) / (d2 - 1), m2 = Array(d2);
    for (let u2 of l2) {
      let l3 = Math.max(0, Math.min(d2 - 1, Math.floor(g.call(null, u2, d2))));
      u2.layer = l3, u2.x0 = t + l3 * p2, u2.x1 = u2.x0 + f, m2[l3] ? m2[l3].push(u2) : m2[l3] = [u2];
    }
    if (_) for (let t2 of m2) t2.sort(_);
    return m2;
  }
  function U(t2) {
    let u2 = min(t2, (t3) => (d - l - (t3.length - 1) * m) / sum(t3, value));
    for (let f2 of t2) {
      let t3 = l;
      for (let l2 of f2) {
        l2.y0 = t3, l2.y1 = t3 + l2.value * u2, t3 = l2.y1 + m;
        for (let t4 of l2.sourceLinks) t4.width = t4.value * u2;
      }
      t3 = (d - t3 + m) / (f2.length + 1);
      for (let l2 = 0; l2 < f2.length; ++l2) {
        let u3 = f2[l2];
        u3.y0 += t3 * (l2 + 1), u3.y1 += t3 * (l2 + 1);
      }
      Z(f2);
    }
  }
  function W(t2) {
    let u2 = N(t2);
    m = Math.min(p, (d - l) / (max(u2, (t3) => t3.length) - 1)), U(u2);
    for (let t3 = 0; t3 < C; ++t3) {
      let l2 = 0.99 ** t3, d2 = Math.max(1 - l2, (t3 + 1) / C);
      K(u2, l2, d2), G(u2, l2, d2);
    }
  }
  function G(t2, l2, u2) {
    for (let d2 = 1, f2 = t2.length; d2 < f2; ++d2) {
      let f3 = t2[d2];
      for (let t3 of f3) {
        let u3 = 0, d3 = 0;
        for (let { source: l3, value: f5 } of t3.targetLinks) {
          let p2 = f5 * (t3.layer - l3.layer);
          u3 += Q(l3, t3) * p2, d3 += p2;
        }
        if (!(d3 > 0)) continue;
        let f4 = (u3 / d3 - t3.y0) * l2;
        t3.y0 += f4, t3.y1 += f4, X(t3);
      }
      _ === void 0 && f3.sort(ascendingBreadth), q(f3, u2);
    }
  }
  function K(t2, l2, u2) {
    for (let d2 = t2.length - 2; d2 >= 0; --d2) {
      let f2 = t2[d2];
      for (let t3 of f2) {
        let u3 = 0, d3 = 0;
        for (let { target: l3, value: f4 } of t3.sourceLinks) {
          let p2 = f4 * (l3.layer - t3.layer);
          u3 += $(t3, l3) * p2, d3 += p2;
        }
        if (!(d3 > 0)) continue;
        let f3 = (u3 / d3 - t3.y0) * l2;
        t3.y0 += f3, t3.y1 += f3, X(t3);
      }
      _ === void 0 && f2.sort(ascendingBreadth), q(f2, u2);
    }
  }
  function q(t2, u2) {
    let f2 = t2.length >> 1, p2 = t2[f2];
    Y(t2, p2.y0 - m, f2 - 1, u2), J(t2, p2.y1 + m, f2 + 1, u2), Y(t2, d, t2.length - 1, u2), J(t2, l, 0, u2);
  }
  function J(t2, l2, u2, d2) {
    for (; u2 < t2.length; ++u2) {
      let f2 = t2[u2], p2 = (l2 - f2.y0) * d2;
      p2 > 1e-6 && (f2.y0 += p2, f2.y1 += p2), l2 = f2.y1 + m;
    }
  }
  function Y(t2, l2, u2, d2) {
    for (; u2 >= 0; --u2) {
      let f2 = t2[u2], p2 = (f2.y1 - l2) * d2;
      p2 > 1e-6 && (f2.y0 -= p2, f2.y1 -= p2), l2 = f2.y0 - m;
    }
  }
  function X({ sourceLinks: t2, targetLinks: l2 }) {
    if (v === void 0) {
      for (let { source: { sourceLinks: t3 } } of l2) t3.sort(ascendingTargetBreadth);
      for (let { target: { targetLinks: l3 } } of t2) l3.sort(ascendingSourceBreadth);
    }
  }
  function Z(t2) {
    if (v === void 0) for (let { sourceLinks: l2, targetLinks: u2 } of t2) l2.sort(ascendingTargetBreadth), u2.sort(ascendingSourceBreadth);
  }
  function Q(t2, l2) {
    let u2 = t2.y0 - (t2.sourceLinks.length - 1) * m / 2;
    for (let { target: d2, width: f2 } of t2.sourceLinks) {
      if (d2 === l2) break;
      u2 += f2 + m;
    }
    for (let { source: d2, width: f2 } of l2.targetLinks) {
      if (d2 === t2) break;
      u2 -= f2;
    }
    return u2;
  }
  function $(t2, l2) {
    let u2 = l2.y0 - (l2.targetLinks.length - 1) * m / 2;
    for (let { source: d2, width: f2 } of l2.targetLinks) {
      if (d2 === t2) break;
      u2 += f2 + m;
    }
    for (let { target: d2, width: f2 } of t2.sourceLinks) {
      if (d2 === l2) break;
      u2 -= f2;
    }
    return u2;
  }
  return w;
}
var pi = Math.PI, tau = 2 * pi, epsilon = 1e-6, tauEpsilon = tau - epsilon;
function Path() {
  this._x0 = this._y0 = this._x1 = this._y1 = null, this._ = "";
}
function path() {
  return new Path();
}
Path.prototype = path.prototype = {
  constructor: Path,
  moveTo: function(t, l) {
    this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +l);
  },
  closePath: function() {
    this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._ += "Z");
  },
  lineTo: function(t, l) {
    this._ += "L" + (this._x1 = +t) + "," + (this._y1 = +l);
  },
  quadraticCurveTo: function(t, l, u, d) {
    this._ += "Q" + +t + "," + +l + "," + (this._x1 = +u) + "," + (this._y1 = +d);
  },
  bezierCurveTo: function(t, l, u, d, f, p) {
    this._ += "C" + +t + "," + +l + "," + +u + "," + +d + "," + (this._x1 = +f) + "," + (this._y1 = +p);
  },
  arcTo: function(t, l, u, d, f) {
    t = +t, l = +l, u = +u, d = +d, f = +f;
    var p = this._x1, m = this._y1, h = u - t, g = d - l, _ = p - t, v = m - l, b = _ * _ + v * v;
    if (f < 0) throw Error("negative radius: " + f);
    if (this._x1 === null) this._ += "M" + (this._x1 = t) + "," + (this._y1 = l);
    else if (b > epsilon) if (!(Math.abs(v * h - g * _) > epsilon) || !f) this._ += "L" + (this._x1 = t) + "," + (this._y1 = l);
    else {
      var S = u - p, C = d - m, w = h * h + g * g, T = S * S + C * C, E = Math.sqrt(w), D = Math.sqrt(b), O = f * Math.tan((pi - Math.acos((w + b - T) / (2 * E * D))) / 2), k = O / D, A = O / E;
      Math.abs(k - 1) > epsilon && (this._ += "L" + (t + k * _) + "," + (l + k * v)), this._ += "A" + f + "," + f + ",0,0," + +(v * S > _ * C) + "," + (this._x1 = t + A * h) + "," + (this._y1 = l + A * g);
    }
  },
  arc: function(t, l, u, d, f, p) {
    t = +t, l = +l, u = +u, p = !!p;
    var m = u * Math.cos(d), h = u * Math.sin(d), g = t + m, _ = l + h, v = 1 ^ p, b = p ? d - f : f - d;
    if (u < 0) throw Error("negative radius: " + u);
    this._x1 === null ? this._ += "M" + g + "," + _ : (Math.abs(this._x1 - g) > epsilon || Math.abs(this._y1 - _) > epsilon) && (this._ += "L" + g + "," + _), u && (b < 0 && (b = b % tau + tau), b > tauEpsilon ? this._ += "A" + u + "," + u + ",0,1," + v + "," + (t - m) + "," + (l - h) + "A" + u + "," + u + ",0,1," + v + "," + (this._x1 = g) + "," + (this._y1 = _) : b > epsilon && (this._ += "A" + u + "," + u + ",0," + +(b >= pi) + "," + v + "," + (this._x1 = t + u * Math.cos(f)) + "," + (this._y1 = l + u * Math.sin(f))));
  },
  rect: function(t, l, u, d) {
    this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +l) + "h" + +u + "v" + +d + "h" + -u + "Z";
  },
  toString: function() {
    return this._;
  }
};
var path_default = path;
function constant_default(t) {
  return function() {
    return t;
  };
}
function x(t) {
  return t[0];
}
function y(t) {
  return t[1];
}
var slice = Array.prototype.slice;
function linkSource(t) {
  return t.source;
}
function linkTarget(t) {
  return t.target;
}
function link(t) {
  var l = linkSource, u = linkTarget, d = x, f = y, p = null;
  function m() {
    var m2, h = slice.call(arguments), g = l.apply(this, h), _ = u.apply(this, h);
    if (p || (p = m2 = path_default()), t(p, +d.apply(this, (h[0] = g, h)), +f.apply(this, h), +d.apply(this, (h[0] = _, h)), +f.apply(this, h)), m2) return p = null, m2 + "" || null;
  }
  return m.source = function(t2) {
    return arguments.length ? (l = t2, m) : l;
  }, m.target = function(t2) {
    return arguments.length ? (u = t2, m) : u;
  }, m.x = function(t2) {
    return arguments.length ? (d = typeof t2 == "function" ? t2 : constant_default(+t2), m) : d;
  }, m.y = function(t2) {
    return arguments.length ? (f = typeof t2 == "function" ? t2 : constant_default(+t2), m) : f;
  }, m.context = function(t2) {
    return arguments.length ? (p = t2 ?? null, m) : p;
  }, m;
}
function curveHorizontal(t, l, u, d, f) {
  t.moveTo(l, u), t.bezierCurveTo(l = (l + d) / 2, u, l, f, d, f);
}
function linkHorizontal() {
  return link(curveHorizontal);
}
function horizontalSource(t) {
  return [t.source.x1, t.y0];
}
function horizontalTarget(t) {
  return [t.target.x0, t.y1];
}
function sankeyLinkHorizontal_default() {
  return linkHorizontal().source(horizontalSource).target(horizontalTarget);
}
var parser = (function() {
  var t = /* @__PURE__ */ __name(function(t2, l2, u, d2) {
    for (u || (u = {}), d2 = t2.length; d2--; u[t2[d2]] = l2) ;
    return u;
  }, "o"), l = [1, 9], d = [1, 10], f = [
    1,
    5,
    10,
    12
  ], p = {
    trace: /* @__PURE__ */ __name(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__ */ __name(function(t2, l2, u, d2, f2, p2, m2) {
      var h = p2.length - 1;
      switch (f2) {
        case 7:
          let t3 = d2.findOrCreateNode(p2[h - 4].trim().replaceAll('""', '"')), l3 = d2.findOrCreateNode(p2[h - 2].trim().replaceAll('""', '"')), u2 = parseFloat(p2[h].trim());
          d2.addLink(t3, l3, u2);
          break;
        case 8:
        case 9:
        case 11:
          this.$ = p2[h];
          break;
        case 10:
          this.$ = p2[h - 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: l,
        20: d
      },
      {
        1: [2, 6],
        7: 11,
        10: [1, 12]
      },
      t(d, [2, 4], {
        9: 13,
        5: [1, 14]
      }),
      { 12: [1, 15] },
      t(f, [2, 8]),
      t(f, [2, 9]),
      { 19: [1, 16] },
      t(f, [2, 11]),
      { 1: [2, 1] },
      { 1: [2, 5] },
      t(d, [2, 2]),
      {
        6: 17,
        8: 5,
        15: 6,
        16: 7,
        17: 8,
        18: l,
        20: d
      },
      {
        15: 18,
        16: 7,
        17: 8,
        18: l,
        20: d
      },
      { 18: [1, 19] },
      t(d, [2, 3]),
      { 12: [1, 20] },
      t(f, [2, 10]),
      {
        15: 21,
        16: 7,
        17: 8,
        18: l,
        20: d
      },
      t([
        1,
        5,
        10
      ], [2, 7])
    ],
    defaultActions: {
      11: [2, 1],
      12: [2, 5]
    },
    parseError: /* @__PURE__ */ __name(function(t2, l2) {
      if (l2.recoverable) this.trace(t2);
      else {
        var u = Error(t2);
        throw u.hash = l2, u;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ __name(function(t2) {
      var l2 = this, d2 = [0], f2 = [], p2 = [null], m2 = [], h = this.table, g = "", _ = 0, v = 0, b = 0, S = 2, C = 1, w = m2.slice.call(arguments, 1), T = Object.create(this.lexer), E = { yy: {} };
      for (var D in this.yy) Object.prototype.hasOwnProperty.call(this.yy, D) && (E.yy[D] = this.yy[D]);
      T.setInput(t2, E.yy), E.yy.lexer = T, E.yy.parser = this, T.yylloc === void 0 && (T.yylloc = {});
      var O = T.yylloc;
      m2.push(O);
      var k = T.options && T.options.ranges;
      typeof E.yy.parseError == "function" ? this.parseError = E.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function A(t3) {
        d2.length -= 2 * t3, p2.length -= t3, m2.length -= t3;
      }
      __name(A, "popStack");
      function j() {
        var t3 = f2.pop() || T.lex() || C;
        return typeof t3 != "number" && (t3 instanceof Array && (f2 = t3, t3 = f2.pop()), t3 = l2.symbols_[t3] || t3), t3;
      }
      __name(j, "lex");
      for (var M, N, P, F, I, L = {}, R, z, B, V; ; ) {
        if (P = d2[d2.length - 1], this.defaultActions[P] ? F = this.defaultActions[P] : (M ?? (M = j()), F = h[P] && h[P][M]), F === void 0 || !F.length || !F[0]) {
          var H = "";
          for (R in V = [], h[P]) this.terminals_[R] && R > S && V.push("'" + this.terminals_[R] + "'");
          H = T.showPosition ? "Parse error on line " + (_ + 1) + ":\n" + T.showPosition() + "\nExpecting " + V.join(", ") + ", got '" + (this.terminals_[M] || M) + "'" : "Parse error on line " + (_ + 1) + ": Unexpected " + (M == C ? "end of input" : "'" + (this.terminals_[M] || M) + "'"), this.parseError(H, {
            text: T.match,
            token: this.terminals_[M] || M,
            line: T.yylineno,
            loc: O,
            expected: V
          });
        }
        if (F[0] instanceof Array && F.length > 1) throw Error("Parse Error: multiple actions possible at state: " + P + ", token: " + M);
        switch (F[0]) {
          case 1:
            d2.push(M), p2.push(T.yytext), m2.push(T.yylloc), d2.push(F[1]), M = null, N ? (M = N, N = null) : (v = T.yyleng, g = T.yytext, _ = T.yylineno, O = T.yylloc, b > 0 && b--);
            break;
          case 2:
            if (z = this.productions_[F[1]][1], L.$ = p2[p2.length - z], L._$ = {
              first_line: m2[m2.length - (z || 1)].first_line,
              last_line: m2[m2.length - 1].last_line,
              first_column: m2[m2.length - (z || 1)].first_column,
              last_column: m2[m2.length - 1].last_column
            }, k && (L._$.range = [m2[m2.length - (z || 1)].range[0], m2[m2.length - 1].range[1]]), I = this.performAction.apply(L, [
              g,
              v,
              _,
              E.yy,
              F[1],
              p2,
              m2
            ].concat(w)), I !== void 0) return I;
            z && (d2 = d2.slice(0, -1 * z * 2), p2 = p2.slice(0, -1 * z), m2 = m2.slice(0, -1 * z)), d2.push(this.productions_[F[1]][0]), p2.push(L.$), m2.push(L._$), B = h[d2[d2.length - 2]][d2[d2.length - 1]], d2.push(B);
            break;
          case 3:
            return true;
        }
      }
      return true;
    }, "parse")
  };
  p.lexer = /* @__PURE__ */ (function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ __name(function(t2, l2) {
        if (this.yy.parser) this.yy.parser.parseError(t2, l2);
        else throw Error(t2);
      }, "parseError"),
      setInput: /* @__PURE__ */ __name(function(t2, l2) {
        return this.yy = l2 || this.yy || {}, this._input = t2, this._more = this._backtrack = this.done = false, 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__ */ __name(function() {
        var t2 = this._input[0];
        return this.yytext += t2, this.yyleng++, this.offset++, this.match += t2, this.matched += t2, t2.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), t2;
      }, "input"),
      unput: /* @__PURE__ */ __name(function(t2) {
        var l2 = t2.length, u = t2.split(/(?:\r\n?|\n)/g);
        this._input = t2 + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - l2), this.offset -= l2;
        var d2 = 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 f2 = 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 === d2.length ? this.yylloc.first_column : 0) + d2[d2.length - u.length].length - u[0].length : this.yylloc.first_column - l2
        }, this.options.ranges && (this.yylloc.range = [f2[0], f2[0] + this.yyleng - l2]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ __name(function() {
        return this._more = true, this;
      }, "more"),
      reject: /* @__PURE__ */ __name(function() {
        if (this.options.backtrack_lexer) this._backtrack = true;
        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__ */ __name(function(t2) {
        this.unput(this.match.slice(t2));
      }, "less"),
      pastInput: /* @__PURE__ */ __name(function() {
        var t2 = this.matched.substr(0, this.matched.length - this.match.length);
        return (t2.length > 20 ? "..." : "") + t2.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ __name(function() {
        var t2 = this.match;
        return t2.length < 20 && (t2 += this._input.substr(0, 20 - t2.length)), (t2.substr(0, 20) + (t2.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ __name(function() {
        var t2 = this.pastInput(), l2 = Array(t2.length + 1).join("-");
        return t2 + this.upcomingInput() + "\n" + l2 + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ __name(function(t2, l2) {
        var u, d2, f2;
        if (this.options.backtrack_lexer && (f2 = {
          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 && (f2.yylloc.range = this.yylloc.range.slice(0))), d2 = t2[0].match(/(?:\r\n?|\n).*/g), d2 && (this.yylineno += d2.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: d2 ? d2[d2.length - 1].length - d2[d2.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + t2[0].length
        }, this.yytext += t2[0], this.match += t2[0], this.matches = t2, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = false, this._backtrack = false, this._input = this._input.slice(t2[0].length), this.matched += t2[0], u = this.performAction.call(this, this.yy, this, l2, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = false), u) return u;
        if (this._backtrack) {
          for (var p2 in f2) this[p2] = f2[p2];
          return false;
        }
        return false;
      }, "test_match"),
      next: /* @__PURE__ */ __name(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = true);
        var t2, l2, u, d2;
        this._more || (this.yytext = "", this.match = "");
        for (var f2 = this._currentRules(), p2 = 0; p2 < f2.length; p2++) if (u = this._input.match(this.rules[f2[p2]]), u && (!l2 || u[0].length > l2[0].length)) {
          if (l2 = u, d2 = p2, this.options.backtrack_lexer) {
            if (t2 = this.test_match(u, f2[p2]), t2 !== false) return t2;
            if (this._backtrack) {
              l2 = false;
              continue;
            } else return false;
          } else if (!this.options.flex) break;
        }
        return l2 ? (t2 = this.test_match(l2, f2[d2]), t2 === false ? false : t2) : 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__ */ __name(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ __name(function(t2) {
        this.conditionStack.push(t2);
      }, "begin"),
      popState: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ __name(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__ */ __name(function(t2) {
        return t2 = this.conditionStack.length - 1 - Math.abs(t2 || 0), t2 >= 0 ? this.conditionStack[t2] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ __name(function(t2) {
        this.begin(t2);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": true },
      performAction: /* @__PURE__ */ __name(function(t2, l2, u, d2) {
        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: false
        },
        escaped_text: {
          rules: [7, 8],
          inclusive: false
        },
        INITIAL: {
          rules: [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8
          ],
          inclusive: true
        }
      }
    };
  })();
  function m() {
    this.yy = {};
  }
  return __name(m, "Parser"), m.prototype = p, p.Parser = m, new m();
})();
parser.parser = parser;
var sankey_default = parser, links = [], nodes = [], nodesMap = /* @__PURE__ */ new Map(), clear2 = /* @__PURE__ */ __name(() => {
  links = [], nodes = [], nodesMap = /* @__PURE__ */ new Map(), clear();
}, "clear"), SankeyLink = (_a = class {
  constructor(t, l, u = 0) {
    this.source = t, this.target = l, this.value = u;
  }
}, __name(_a, "SankeyLink"), _a), addLink = /* @__PURE__ */ __name((t, l, u) => {
  links.push(new SankeyLink(t, l, u));
}, "addLink"), SankeyNode = (_b = class {
  constructor(t) {
    this.ID = t;
  }
}, __name(_b, "SankeyNode"), _b), sankeyDB_default = {
  nodesMap,
  getConfig: /* @__PURE__ */ __name(() => getConfig2().sankey, "getConfig"),
  getNodes: /* @__PURE__ */ __name(() => nodes, "getNodes"),
  getLinks: /* @__PURE__ */ __name(() => links, "getLinks"),
  getGraph: /* @__PURE__ */ __name(() => ({
    nodes: nodes.map((t) => ({ id: t.ID })),
    links: links.map((t) => ({
      source: t.source.ID,
      target: t.target.ID,
      value: t.value
    }))
  }), "getGraph"),
  addLink,
  findOrCreateNode: /* @__PURE__ */ __name((t) => {
    t = common_default.sanitizeText(t, getConfig2());
    let l = nodesMap.get(t);
    return l === void 0 && (l = new SankeyNode(t), nodesMap.set(t, l), nodes.push(l)), l;
  }, "findOrCreateNode"),
  getAccTitle,
  setAccTitle,
  getAccDescription,
  setAccDescription,
  getDiagramTitle,
  setDiagramTitle,
  clear: clear2
}, Uid = (_c = class {
  static next(l) {
    return new _c(l + ++_c.count);
  }
  constructor(t) {
    this.id = t, this.href = `#${t}`;
  }
  toString() {
    return "url(" + this.href + ")";
  }
}, __name(_c, "Uid"), _c.count = 0, _c), alignmentsMap = {
  left,
  right,
  center,
  justify
}, sankeyRenderer_default = { draw: /* @__PURE__ */ __name(function(l, f, p, h) {
  let { securityLevel: g, sankey: _ } = getConfig2(), b = defaultConfig2.sankey, C;
  g === "sandbox" && (C = select_default("#i" + f));
  let w = select_default(g === "sandbox" ? C.nodes()[0].contentDocument.body : "body"), E = g === "sandbox" ? w.select(`[id="${f}"]`) : select_default(`[id="${f}"]`), D = (_ == null ? void 0 : _.width) ?? b.width, O = (_ == null ? void 0 : _.height) ?? b.width, k = (_ == null ? void 0 : _.useMaxWidth) ?? b.useMaxWidth, A = (_ == null ? void 0 : _.nodeAlignment) ?? b.nodeAlignment, j = (_ == null ? void 0 : _.prefix) ?? b.prefix, M = (_ == null ? void 0 : _.suffix) ?? b.suffix, N = (_ == null ? void 0 : _.showValues) ?? b.showValues, P = h.db.getGraph(), F = alignmentsMap[A];
  Sankey().nodeId((t) => t.id).nodeWidth(10).nodePadding(10 + (N ? 15 : 0)).nodeAlign(F).extent([[0, 0], [D, O]])(P);
  let I = ordinal(Tableau10_default);
  E.append("g").attr("class", "nodes").selectAll(".node").data(P.nodes).join("g").attr("class", "node").attr("id", (t) => (t.uid = Uid.next("node-")).id).attr("transform", function(t) {
    return "translate(" + t.x0 + "," + t.y0 + ")";
  }).attr("x", (t) => t.x0).attr("y", (t) => t.y0).append("rect").attr("height", (t) => t.y1 - t.y0).attr("width", (t) => t.x1 - t.x0).attr("fill", (t) => I(t.id));
  let L = /* @__PURE__ */ __name(({ id: t, value: l2 }) => N ? `${t}
${j}${Math.round(l2 * 100) / 100}${M}` : t, "getText");
  E.append("g").attr("class", "node-labels").attr("font-size", 14).selectAll("text").data(P.nodes).join("text").attr("x", (t) => t.x0 < D / 2 ? t.x1 + 6 : t.x0 - 6).attr("y", (t) => (t.y1 + t.y0) / 2).attr("dy", `${N ? "0" : "0.35"}em`).attr("text-anchor", (t) => t.x0 < D / 2 ? "start" : "end").text(L);
  let R = E.append("g").attr("class", "links").attr("fill", "none").attr("stroke-opacity", 0.5).selectAll(".link").data(P.links).join("g").attr("class", "link").style("mix-blend-mode", "multiply"), z = (_ == null ? void 0 : _.linkColor) ?? "gradient";
  if (z === "gradient") {
    let t = R.append("linearGradient").attr("id", (t2) => (t2.uid = Uid.next("linearGradient-")).id).attr("gradientUnits", "userSpaceOnUse").attr("x1", (t2) => t2.source.x1).attr("x2", (t2) => t2.target.x0);
    t.append("stop").attr("offset", "0%").attr("stop-color", (t2) => I(t2.source.id)), t.append("stop").attr("offset", "100%").attr("stop-color", (t2) => I(t2.target.id));
  }
  let B;
  switch (z) {
    case "gradient":
      B = /* @__PURE__ */ __name((t) => t.uid, "coloring");
      break;
    case "source":
      B = /* @__PURE__ */ __name((t) => I(t.source.id), "coloring");
      break;
    case "target":
      B = /* @__PURE__ */ __name((t) => I(t.target.id), "coloring");
      break;
    default:
      B = z;
  }
  R.append("path").attr("d", sankeyLinkHorizontal_default()).attr("stroke", B).attr("stroke-width", (t) => Math.max(1, t.width)), setupGraphViewbox(void 0, E, 0, k);
}, "draw") }, prepareTextForParsing = /* @__PURE__ */ __name((t) => t.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g, "").replaceAll(/([\n\r])+/g, "\n").trim(), "prepareTextForParsing"), styles_default = /* @__PURE__ */ __name((t) => `.label {
      font-family: ${t.fontFamily};
    }`, "getStyles"), originalParse = sankey_default.parse.bind(sankey_default);
sankey_default.parse = (t) => originalParse(prepareTextForParsing(t));
var diagram = {
  styles: styles_default,
  parser: sankey_default,
  db: sankeyDB_default,
  renderer: sankeyRenderer_default
};
export {
  diagram
};
