import { a7 as qt, a8 as Vt, ap as Wt, ao as Xt, a9 as Yt, aa as Gt, _ as I, aB as wt, aU as Kt, a5 as rt, bB as Zt, bl as Ht, bm as Qt, bn as Jt, ab as te, av as ee, aD as ne, aE as se, bC as re } from "./index-Bh-wTBlD.js";
const Mt = (t, n) => re(t, "a", -n), It = 1e-10;
function nt(t, n) {
  const s = ae(t), e = s.filter((l) => ie(l, t));
  let r = 0, i = 0;
  const h = [];
  if (e.length > 1) {
    const l = St(e);
    for (let o = 0; o < e.length; ++o) {
      const c = e[o];
      c.angle = Math.atan2(c.x - l.x, c.y - l.y);
    }
    e.sort((o, c) => c.angle - o.angle);
    let u = e[e.length - 1];
    for (let o = 0; o < e.length; ++o) {
      const c = e[o];
      i += (u.x + c.x) * (c.y - u.y);
      const x = { x: (c.x + u.x) / 2, y: (c.y + u.y) / 2 };
      let d = null;
      for (let b = 0; b < c.parentIndex.length; ++b)
        if (u.parentIndex.includes(c.parentIndex[b])) {
          const g = t[c.parentIndex[b]], w = Math.atan2(c.x - g.x, c.y - g.y), D = Math.atan2(u.x - g.x, u.y - g.y);
          let E = D - w;
          E < 0 && (E += 2 * Math.PI);
          const k = D - E / 2;
          let f = V(x, {
            x: g.x + g.radius * Math.sin(k),
            y: g.y + g.radius * Math.cos(k)
          });
          f > g.radius * 2 && (f = g.radius * 2), (d == null || d.width > f) && (d = { circle: g, width: f, p1: c, p2: u, large: f > g.radius, sweep: !0 });
        }
      d != null && (h.push(d), r += ot(d.circle.radius, d.width), u = c);
    }
  } else {
    let l = t[0];
    for (let o = 1; o < t.length; ++o)
      t[o].radius < l.radius && (l = t[o]);
    let u = !1;
    for (let o = 0; o < t.length; ++o)
      if (V(t[o], l) > Math.abs(l.radius - t[o].radius)) {
        u = !0;
        break;
      }
    u ? r = i = 0 : (r = l.radius * l.radius * Math.PI, h.push({
      circle: l,
      p1: { x: l.x, y: l.y + l.radius },
      p2: { x: l.x - It, y: l.y + l.radius },
      width: l.radius * 2,
      large: !0,
      sweep: !0
    }));
  }
  return i /= 2, n && (n.area = r + i, n.arcArea = r, n.polygonArea = i, n.arcs = h, n.innerPoints = e, n.intersectionPoints = s), r + i;
}
function ie(t, n) {
  return n.every((s) => V(t, s) < s.radius + It);
}
function ae(t) {
  const n = [];
  for (let s = 0; s < t.length; ++s)
    for (let e = s + 1; e < t.length; ++e) {
      const r = Et(t[s], t[e]);
      for (const i of r)
        i.parentIndex = [s, e], n.push(i);
    }
  return n;
}
function ot(t, n) {
  return t * t * Math.acos(1 - n / t) - (t - n) * Math.sqrt(n * (2 * t - n));
}
function V(t, n) {
  return Math.sqrt((t.x - n.x) * (t.x - n.x) + (t.y - n.y) * (t.y - n.y));
}
function yt(t, n, s) {
  if (s >= t + n)
    return 0;
  if (s <= Math.abs(t - n))
    return Math.PI * Math.min(t, n) * Math.min(t, n);
  const e = t - (s * s - n * n + t * t) / (2 * s), r = n - (s * s - t * t + n * n) / (2 * s);
  return ot(t, e) + ot(n, r);
}
function Et(t, n) {
  const s = V(t, n), e = t.radius, r = n.radius;
  if (s >= e + r || s <= Math.abs(e - r))
    return [];
  const i = (e * e - r * r + s * s) / (2 * s), h = Math.sqrt(e * e - i * i), l = t.x + i * (n.x - t.x) / s, u = t.y + i * (n.y - t.y) / s, o = -(n.y - t.y) * (h / s), c = -(n.x - t.x) * (h / s);
  return [
    { x: l + o, y: u - c },
    { x: l - o, y: u + c }
  ];
}
function St(t) {
  const n = { x: 0, y: 0 };
  for (const s of t)
    n.x += s.x, n.y += s.y;
  return n.x /= t.length, n.y /= t.length, n;
}
function oe(t, n, s, e) {
  e = e || {};
  const r = e.maxIterations || 100, i = e.tolerance || 1e-10, h = t(n), l = t(s);
  let u = s - n;
  if (h * l > 0)
    throw "Initial bisect points must have opposite signs";
  if (h === 0) return n;
  if (l === 0) return s;
  for (let o = 0; o < r; ++o) {
    u /= 2;
    const c = n + u, x = t(c);
    if (x * h >= 0 && (n = c), Math.abs(u) < i || x === 0)
      return c;
  }
  return n + u;
}
function lt(t) {
  const n = new Array(t);
  for (let s = 0; s < t; ++s)
    n[s] = 0;
  return n;
}
function kt(t, n) {
  return lt(t).map(() => lt(n));
}
function J(t, n) {
  let s = 0;
  for (let e = 0; e < t.length; ++e)
    s += t[e] * n[e];
  return s;
}
function ct(t) {
  return Math.sqrt(J(t, t));
}
function ut(t, n, s) {
  for (let e = 0; e < n.length; ++e)
    t[e] = n[e] * s;
}
function K(t, n, s, e, r) {
  for (let i = 0; i < t.length; ++i)
    t[i] = n * s[i] + e * r[i];
}
function Tt(t, n, s) {
  s = s || {};
  const e = s.maxIterations || n.length * 200, r = s.nonZeroDelta || 1.05, i = s.zeroDelta || 1e-3, h = s.minErrorDelta || 1e-6, l = s.minErrorDelta || 1e-5, u = s.rho !== void 0 ? s.rho : 1, o = s.chi !== void 0 ? s.chi : 2, c = s.psi !== void 0 ? s.psi : -0.5, x = s.sigma !== void 0 ? s.sigma : 0.5;
  let d;
  const b = n.length, g = new Array(b + 1);
  g[0] = n, g[0].fx = t(n), g[0].id = 0;
  for (let y = 0; y < b; ++y) {
    const p = n.slice();
    p[y] = p[y] ? p[y] * r : i, g[y + 1] = p, g[y + 1].fx = t(p), g[y + 1].id = y + 1;
  }
  function w(y) {
    for (let p = 0; p < y.length; p++)
      g[b][p] = y[p];
    g[b].fx = y.fx;
  }
  const D = (y, p) => y.fx - p.fx, E = n.slice(), k = n.slice(), f = n.slice(), m = n.slice();
  for (let y = 0; y < e; ++y) {
    if (g.sort(D), s.history) {
      const a = g.map((_) => {
        const M = _.slice();
        return M.fx = _.fx, M.id = _.id, M;
      });
      a.sort((_, M) => _.id - M.id), s.history.push({
        x: g[0].slice(),
        fx: g[0].fx,
        simplex: a
      });
    }
    d = 0;
    for (let a = 0; a < b; ++a)
      d = Math.max(d, Math.abs(g[0][a] - g[1][a]));
    if (Math.abs(g[0].fx - g[b].fx) < h && d < l)
      break;
    for (let a = 0; a < b; ++a) {
      E[a] = 0;
      for (let _ = 0; _ < b; ++_)
        E[a] += g[_][a];
      E[a] /= b;
    }
    const p = g[b];
    if (K(k, 1 + u, E, -u, p), k.fx = t(k), k.fx < g[0].fx)
      K(m, 1 + o, E, -o, p), m.fx = t(m), m.fx < k.fx ? w(m) : w(k);
    else if (k.fx >= g[b - 1].fx) {
      let a = !1;
      if (k.fx > p.fx ? (K(f, 1 + c, E, -c, p), f.fx = t(f), f.fx < p.fx ? w(f) : a = !0) : (K(f, 1 - c * u, E, c * u, p), f.fx = t(f), f.fx < k.fx ? w(f) : a = !0), a) {
        if (x >= 1) break;
        for (let _ = 1; _ < g.length; ++_)
          K(g[_], 1 - x, g[0], x, g[_]), g[_].fx = t(g[_]);
      }
    } else
      w(k);
  }
  return g.sort(D), { fx: g[0].fx, x: g[0] };
}
function le(t, n, s, e, r, i, h) {
  const l = s.fx, u = J(s.fxprime, n);
  let o = l, c = l, x = u, d = 0;
  r = r || 1, i = i || 1e-6, h = h || 0.1;
  function b(g, w, D) {
    for (let E = 0; E < 16; ++E)
      if (r = (g + w) / 2, K(e.x, 1, s.x, r, n), o = e.fx = t(e.x, e.fxprime), x = J(e.fxprime, n), o > l + i * r * u || o >= D)
        w = r;
      else {
        if (Math.abs(x) <= -h * u)
          return r;
        x * (w - g) >= 0 && (w = g), g = r, D = o;
      }
    return 0;
  }
  for (let g = 0; g < 10; ++g) {
    if (K(e.x, 1, s.x, r, n), o = e.fx = t(e.x, e.fxprime), x = J(e.fxprime, n), o > l + i * r * u || g && o >= c)
      return b(d, r, c);
    if (Math.abs(x) <= -h * u)
      return r;
    if (x >= 0)
      return b(r, d, o);
    c = o, d = r, r *= 2;
  }
  return r;
}
function ce(t, n, s) {
  let e = { x: n.slice(), fx: 0, fxprime: n.slice() }, r = { x: n.slice(), fx: 0, fxprime: n.slice() };
  const i = n.slice();
  let h, l, u = 1, o;
  s = s || {}, o = s.maxIterations || n.length * 20, e.fx = t(e.x, e.fxprime), h = e.fxprime.slice(), ut(h, e.fxprime, -1);
  for (let c = 0; c < o; ++c) {
    if (u = le(t, h, e, r, u), s.history && s.history.push({
      x: e.x.slice(),
      fx: e.fx,
      fxprime: e.fxprime.slice(),
      alpha: u
    }), !u)
      ut(h, e.fxprime, -1);
    else {
      K(i, 1, r.fxprime, -1, e.fxprime);
      const x = J(e.fxprime, e.fxprime), d = Math.max(0, J(i, r.fxprime) / x);
      K(h, d, h, -1, r.fxprime), l = e, e = r, r = l;
    }
    if (ct(e.fxprime) <= 1e-5)
      break;
  }
  return s.history && s.history.push({
    x: e.x.slice(),
    fx: e.fx,
    fxprime: e.fxprime.slice(),
    alpha: u
  }), e;
}
function zt(t, n = {}) {
  n.maxIterations = n.maxIterations || 500;
  const s = n.initialLayout || de, e = n.lossFunction || tt, r = ue(t, n), i = s(r, n), h = Object.keys(i), l = [];
  for (const o of h)
    l.push(i[o].x), l.push(i[o].y);
  const u = Tt(
    (o) => {
      const c = {};
      for (let x = 0; x < h.length; ++x) {
        const d = h[x];
        c[d] = {
          x: o[2 * x],
          y: o[2 * x + 1],
          radius: i[d].radius
          // size : circles[setid].size
        };
      }
      return e(c, r);
    },
    l,
    n
  ).x;
  for (let o = 0; o < h.length; ++o) {
    const c = h[o];
    i[c].x = u[2 * o], i[c].y = u[2 * o + 1];
  }
  return i;
}
const At = 1e-10;
function ht(t, n, s) {
  return Math.min(t, n) * Math.min(t, n) * Math.PI <= s + At ? Math.abs(t - n) : oe((e) => yt(t, n, e) - s, 0, t + n);
}
function ue(t, n = {}) {
  const s = n.distinct, e = t.map((l) => Object.assign({}, l));
  function r(l) {
    return l.join(";");
  }
  if (s) {
    const l = /* @__PURE__ */ new Map();
    for (const u of e)
      for (let o = 0; o < u.sets.length; o++) {
        const c = String(u.sets[o]);
        l.set(c, u.size + (l.get(c) || 0));
        for (let x = o + 1; x < u.sets.length; x++) {
          const d = String(u.sets[x]), b = `${c};${d}`, g = `${d};${c}`;
          l.set(b, u.size + (l.get(b) || 0)), l.set(g, u.size + (l.get(g) || 0));
        }
      }
    for (const u of e)
      u.sets.length < 3 && (u.size = l.get(r(u.sets)));
  }
  const i = [], h = /* @__PURE__ */ new Set();
  for (const l of e)
    if (l.sets.length === 1)
      i.push(l.sets[0]);
    else if (l.sets.length === 2) {
      const u = l.sets[0], o = l.sets[1];
      h.add(r(l.sets)), h.add(r([o, u]));
    }
  i.sort((l, u) => l === u ? 0 : l < u ? -1 : 1);
  for (let l = 0; l < i.length; ++l) {
    const u = i[l];
    for (let o = l + 1; o < i.length; ++o) {
      const c = i[o];
      h.has(r([u, c])) || e.push({ sets: [u, c], size: 0 });
    }
  }
  return e;
}
function he(t, n, s) {
  const e = kt(n.length, n.length), r = kt(n.length, n.length);
  return t.filter((i) => i.sets.length === 2).forEach((i) => {
    const h = s[i.sets[0]], l = s[i.sets[1]], u = Math.sqrt(n[h].size / Math.PI), o = Math.sqrt(n[l].size / Math.PI), c = ht(u, o, i.size);
    e[h][l] = e[l][h] = c;
    let x = 0;
    i.size + 1e-10 >= Math.min(n[h].size, n[l].size) ? x = 1 : i.size <= 1e-10 && (x = -1), r[h][l] = r[l][h] = x;
  }), { distances: e, constraints: r };
}
function fe(t, n, s, e) {
  for (let i = 0; i < n.length; ++i)
    n[i] = 0;
  let r = 0;
  for (let i = 0; i < s.length; ++i) {
    const h = t[2 * i], l = t[2 * i + 1];
    for (let u = i + 1; u < s.length; ++u) {
      const o = t[2 * u], c = t[2 * u + 1], x = s[i][u], d = e[i][u], b = (o - h) * (o - h) + (c - l) * (c - l), g = Math.sqrt(b), w = b - x * x;
      d > 0 && g <= x || d < 0 && g >= x || (r += 2 * w * w, n[2 * i] += 4 * w * (h - o), n[2 * i + 1] += 4 * w * (l - c), n[2 * u] += 4 * w * (o - h), n[2 * u + 1] += 4 * w * (c - l));
    }
  }
  return r;
}
function de(t, n = {}) {
  let s = ge(t, n);
  const e = n.lossFunction || tt;
  if (t.length >= 8) {
    const r = ye(t, n), i = e(r, t), h = e(s, t);
    i + 1e-8 < h && (s = r);
  }
  return s;
}
function ye(t, n = {}) {
  const s = n.restarts || 10, e = [], r = {};
  for (const d of t)
    d.sets.length === 1 && (r[d.sets[0]] = e.length, e.push(d));
  let { distances: i, constraints: h } = he(t, e, r);
  const l = ct(i.map(ct)) / i.length;
  i = i.map((d) => d.map((b) => b / l));
  const u = (d, b) => fe(d, b, i, h);
  let o = null;
  for (let d = 0; d < s; ++d) {
    const b = lt(i.length * 2).map(Math.random), g = ce(u, b, n);
    (!o || g.fx < o.fx) && (o = g);
  }
  const c = o.x, x = {};
  for (let d = 0; d < e.length; ++d) {
    const b = e[d];
    x[b.sets[0]] = {
      x: c[2 * d] * l,
      y: c[2 * d + 1] * l,
      radius: Math.sqrt(b.size / Math.PI)
    };
  }
  if (n.history)
    for (const d of n.history)
      ut(d.x, l);
  return x;
}
function ge(t, n) {
  const s = n && n.lossFunction ? n.lossFunction : tt, e = {}, r = {};
  for (const x of t)
    if (x.sets.length === 1) {
      const d = x.sets[0];
      e[d] = {
        x: 1e10,
        y: 1e10,
        rowid: e.length,
        size: x.size,
        radius: Math.sqrt(x.size / Math.PI)
      }, r[d] = [];
    }
  t = t.filter((x) => x.sets.length === 2);
  for (const x of t) {
    let d = x.weight != null ? x.weight : 1;
    const b = x.sets[0], g = x.sets[1];
    x.size + At >= Math.min(e[b].size, e[g].size) && (d = 0), r[b].push({ set: g, size: x.size, weight: d }), r[g].push({ set: b, size: x.size, weight: d });
  }
  const i = [];
  Object.keys(r).forEach((x) => {
    let d = 0;
    for (let b = 0; b < r[x].length; ++b)
      d += r[x][b].size * r[x][b].weight;
    i.push({ set: x, size: d });
  });
  function h(x, d) {
    return d.size - x.size;
  }
  i.sort(h);
  const l = {};
  function u(x) {
    return x.set in l;
  }
  function o(x, d) {
    e[d].x = x.x, e[d].y = x.y, l[d] = !0;
  }
  o({ x: 0, y: 0 }, i[0].set);
  for (let x = 1; x < i.length; ++x) {
    const d = i[x].set, b = r[d].filter(u), g = e[d];
    if (b.sort(h), b.length === 0)
      throw "ERROR: missing pairwise overlap information";
    const w = [];
    for (var c = 0; c < b.length; ++c) {
      const k = e[b[c].set], f = ht(g.radius, k.radius, b[c].size);
      w.push({ x: k.x + f, y: k.y }), w.push({ x: k.x - f, y: k.y }), w.push({ y: k.y + f, x: k.x }), w.push({ y: k.y - f, x: k.x });
      for (let m = c + 1; m < b.length; ++m) {
        const y = e[b[m].set], p = ht(g.radius, y.radius, b[m].size), a = Et(
          { x: k.x, y: k.y, radius: f },
          { x: y.x, y: y.y, radius: p }
        );
        w.push(...a);
      }
    }
    let D = 1e50, E = w[0];
    for (const k of w) {
      e[d].x = k.x, e[d].y = k.y;
      const f = s(e, t);
      f < D && (D = f, E = k);
    }
    o(E, d);
  }
  return e;
}
function tt(t, n) {
  let s = 0;
  for (const e of n) {
    if (e.sets.length === 1)
      continue;
    let r;
    if (e.sets.length === 2) {
      const h = t[e.sets[0]], l = t[e.sets[1]];
      r = yt(h.radius, l.radius, V(h, l));
    } else
      r = nt(e.sets.map((h) => t[h]));
    const i = e.weight != null ? e.weight : 1;
    s += i * (r - e.size) * (r - e.size);
  }
  return s;
}
function Dt(t, n) {
  let s = 0;
  for (const e of n) {
    if (e.sets.length === 1)
      continue;
    let r;
    if (e.sets.length === 2) {
      const l = t[e.sets[0]], u = t[e.sets[1]];
      r = yt(l.radius, u.radius, V(l, u));
    } else
      r = nt(e.sets.map((l) => t[l]));
    const i = e.weight != null ? e.weight : 1, h = Math.log((r + 1) / (e.size + 1));
    s += i * h * h;
  }
  return s;
}
function xe(t, n, s) {
  if (s == null ? t.sort((r, i) => i.radius - r.radius) : t.sort(s), t.length > 0) {
    const r = t[0].x, i = t[0].y;
    for (const h of t)
      h.x -= r, h.y -= i;
  }
  if (t.length === 2 && V(t[0], t[1]) < Math.abs(t[1].radius - t[0].radius) && (t[1].x = t[0].x + t[0].radius - t[1].radius - 1e-10, t[1].y = t[0].y), t.length > 1) {
    const r = Math.atan2(t[1].x, t[1].y) - n, i = Math.cos(r), h = Math.sin(r);
    for (const l of t) {
      const u = l.x, o = l.y;
      l.x = i * u - h * o, l.y = h * u + i * o;
    }
  }
  if (t.length > 2) {
    let r = Math.atan2(t[2].x, t[2].y) - n;
    for (; r < 0; )
      r += 2 * Math.PI;
    for (; r > 2 * Math.PI; )
      r -= 2 * Math.PI;
    if (r > Math.PI) {
      const i = t[1].y / (1e-10 + t[1].x);
      for (const h of t) {
        var e = (h.x + i * h.y) / (1 + i * i);
        h.x = 2 * e - h.x, h.y = 2 * e * i - h.y;
      }
    }
  }
}
function pe(t) {
  t.forEach((r) => {
    r.parent = r;
  });
  function n(r) {
    return r.parent !== r && (r.parent = n(r.parent)), r.parent;
  }
  function s(r, i) {
    const h = n(r), l = n(i);
    h.parent = l;
  }
  for (let r = 0; r < t.length; ++r)
    for (let i = r + 1; i < t.length; ++i) {
      const h = t[r].radius + t[i].radius;
      V(t[r], t[i]) + 1e-10 < h && s(t[i], t[r]);
    }
  const e = /* @__PURE__ */ new Map();
  for (let r = 0; r < t.length; ++r) {
    const i = n(t[r]).parent.setid;
    e.has(i) || e.set(i, []), e.get(i).push(t[r]);
  }
  return t.forEach((r) => {
    delete r.parent;
  }), Array.from(e.values());
}
function ft(t) {
  const n = (s) => {
    const e = t.reduce((i, h) => Math.max(i, h[s] + h.radius), Number.NEGATIVE_INFINITY), r = t.reduce((i, h) => Math.min(i, h[s] - h.radius), Number.POSITIVE_INFINITY);
    return { max: e, min: r };
  };
  return { xRange: n("x"), yRange: n("y") };
}
function Rt(t, n, s) {
  n == null && (n = Math.PI / 2);
  let e = $t(t).map((o) => Object.assign({}, o));
  const r = pe(e);
  for (const o of r) {
    xe(o, n, s);
    const c = ft(o);
    o.size = (c.xRange.max - c.xRange.min) * (c.yRange.max - c.yRange.min), o.bounds = c;
  }
  r.sort((o, c) => c.size - o.size), e = r[0];
  let i = e.bounds;
  const h = (i.xRange.max - i.xRange.min) / 50;
  function l(o, c, x) {
    if (!o)
      return;
    const d = o.bounds;
    let b, g;
    if (c)
      b = i.xRange.max - d.xRange.min + h;
    else {
      b = i.xRange.max - d.xRange.max;
      const w = (d.xRange.max - d.xRange.min) / 2 - (i.xRange.max - i.xRange.min) / 2;
      w < 0 && (b += w);
    }
    if (x)
      g = i.yRange.max - d.yRange.min + h;
    else {
      g = i.yRange.max - d.yRange.max;
      const w = (d.yRange.max - d.yRange.min) / 2 - (i.yRange.max - i.yRange.min) / 2;
      w < 0 && (g += w);
    }
    for (const w of o)
      w.x += b, w.y += g, e.push(w);
  }
  let u = 1;
  for (; u < r.length; )
    l(r[u], !0, !1), l(r[u + 1], !1, !0), l(r[u + 2], !0, !0), u += 3, i = ft(e);
  return Ot(e);
}
function Nt(t, n, s, e, r) {
  const i = $t(t);
  n -= 2 * e, s -= 2 * e;
  const { xRange: h, yRange: l } = ft(i);
  if (h.max === h.min || l.max === l.min)
    return console.log("not scaling solution: zero size detected"), t;
  let u, o;
  if (r) {
    const b = Math.sqrt(r / Math.PI) * 2;
    u = n / b, o = s / b;
  } else
    u = n / (h.max - h.min), o = s / (l.max - l.min);
  const c = Math.min(o, u), x = (n - (h.max - h.min) * c) / 2, d = (s - (l.max - l.min) * c) / 2;
  return Ot(
    i.map((b) => ({
      radius: c * b.radius,
      x: e + x + (b.x - h.min) * c,
      y: e + d + (b.y - l.min) * c,
      setid: b.setid
    }))
  );
}
function Ot(t) {
  const n = {};
  for (const s of t)
    n[s.setid] = s;
  return n;
}
function $t(t) {
  return Object.keys(t).map((n) => Object.assign(t[n], { setid: n }));
}
function me(t = {}) {
  let n = !1, s = 600, e = 350, r = 15, i = 1e3, h = Math.PI / 2, l = !0, u = null, o = !0, c = !0, x = null, d = null, b = !1, g = null, w = t && t.symmetricalTextCentre ? t.symmetricalTextCentre : !1, D = {}, E = t && t.colourScheme ? t.colourScheme : t && t.colorScheme ? t.colorScheme : [
    "#1f77b4",
    "#ff7f0e",
    "#2ca02c",
    "#d62728",
    "#9467bd",
    "#8c564b",
    "#e377c2",
    "#7f7f7f",
    "#bcbd22",
    "#17becf"
  ], k = 0, f = function(a) {
    if (a in D)
      return D[a];
    var _ = D[a] = E[k];
    return k += 1, k >= E.length && (k = 0), _;
  }, m = zt, y = tt;
  function p(a) {
    let _ = a.datum();
    const M = /* @__PURE__ */ new Set();
    _.forEach((v) => {
      v.size == 0 && v.sets.length == 1 && M.add(v.sets[0]);
    }), _ = _.filter((v) => !v.sets.some((R) => M.has(R)));
    let S = {}, B = {};
    if (_.length > 0) {
      let v = m(_, { lossFunction: y, distinct: b });
      l && (v = Rt(v, h, d)), S = Nt(v, s, e, r, u), B = Pt(S, _, w);
    }
    const j = {};
    _.forEach((v) => {
      v.label && (j[v.sets] = v.label);
    });
    function U(v) {
      if (v.sets in j)
        return j[v.sets];
      if (v.sets.length == 1)
        return "" + v.sets[0];
    }
    a.selectAll("svg").data([S]).enter().append("svg");
    const X = a.select("svg");
    n ? X.attr("viewBox", `0 0 ${s} ${e}`) : X.attr("width", s).attr("height", e);
    const z = {};
    let A = !1;
    X.selectAll(".venn-area path").each(function(v) {
      const R = this.getAttribute("d");
      v.sets.length == 1 && R && !b && (A = !0, z[v.sets[0]] = Me(R));
    });
    function N(v) {
      return (R) => {
        const Q = v.sets.map((H) => {
          let G = z[H], C = S[H];
          return G || (G = { x: s / 2, y: e / 2, radius: 1 }), C || (C = { x: s / 2, y: e / 2, radius: 1 }), {
            x: G.x * (1 - R) + C.x * R,
            y: G.y * (1 - R) + C.y * R,
            radius: G.radius * (1 - R) + C.radius * R
          };
        });
        return _t(Q, g);
      };
    }
    const O = X.selectAll(".venn-area").data(_, (v) => v.sets), L = O.enter().append("g").attr(
      "class",
      (v) => `venn-area venn-${v.sets.length == 1 ? "circle" : "intersection"}${v.colour || v.color ? " venn-coloured" : ""}`
    ).attr("data-venn-sets", (v) => v.sets.join("_")), W = L.append("path"), F = L.append("text").attr("class", "label").text((v) => U(v)).attr("text-anchor", "middle").attr("dy", ".35em").attr("x", s / 2).attr("y", e / 2);
    c && (W.style("fill-opacity", "0").filter((v) => v.sets.length == 1).style("fill", (v) => v.colour ? v.colour : v.color ? v.color : f(v.sets)).style("fill-opacity", ".25"), F.style("fill", (v) => v.colour || v.color ? "#FFF" : t.textFill ? t.textFill : v.sets.length == 1 ? f(v.sets) : "#444"));
    function T(v) {
      return typeof v.transition == "function" ? v.transition("venn").duration(i) : v;
    }
    let P = a;
    A && typeof P.transition == "function" ? (P = T(a), P.selectAll("path").attrTween("d", N)) : P.selectAll("path").attr("d", (v) => _t(v.sets.map((R) => S[R])), g);
    const $ = P.selectAll("text").filter((v) => v.sets in B).text((v) => U(v)).attr("x", (v) => Math.floor(B[v.sets].x)).attr("y", (v) => Math.floor(B[v.sets].y));
    o && (A ? "on" in $ ? $.on("end", it(S, U)) : $.each("end", it(S, U)) : $.each(it(S, U)));
    const q = T(O.exit()).remove();
    typeof O.transition == "function" && q.selectAll("path").attrTween("d", N);
    const Y = q.selectAll("text").attr("x", s / 2).attr("y", e / 2);
    return x !== null && (F.style("font-size", "0px"), $.style("font-size", x), Y.style("font-size", "0px")), { circles: S, textCentres: B, nodes: O, enter: L, update: P, exit: q };
  }
  return p.wrap = function(a) {
    return arguments.length ? (o = a, p) : o;
  }, p.useViewBox = function() {
    return n = !0, p;
  }, p.width = function(a) {
    return arguments.length ? (s = a, p) : s;
  }, p.height = function(a) {
    return arguments.length ? (e = a, p) : e;
  }, p.padding = function(a) {
    return arguments.length ? (r = a, p) : r;
  }, p.distinct = function(a) {
    return arguments.length ? (b = a, p) : b;
  }, p.colours = function(a) {
    return arguments.length ? (f = a, p) : f;
  }, p.colors = function(a) {
    return arguments.length ? (f = a, p) : f;
  }, p.fontSize = function(a) {
    return arguments.length ? (x = a, p) : x;
  }, p.round = function(a) {
    return arguments.length ? (g = a, p) : g;
  }, p.duration = function(a) {
    return arguments.length ? (i = a, p) : i;
  }, p.layoutFunction = function(a) {
    return arguments.length ? (m = a, p) : m;
  }, p.normalize = function(a) {
    return arguments.length ? (l = a, p) : l;
  }, p.scaleToFit = function(a) {
    return arguments.length ? (u = a, p) : u;
  }, p.styled = function(a) {
    return arguments.length ? (c = a, p) : c;
  }, p.orientation = function(a) {
    return arguments.length ? (h = a, p) : h;
  }, p.orientationOrder = function(a) {
    return arguments.length ? (d = a, p) : d;
  }, p.lossFunction = function(a) {
    return arguments.length ? (y = a === "default" ? tt : a === "logRatio" ? Dt : a, p) : y;
  }, p;
}
function it(t, n) {
  return function(s) {
    const e = this, r = t[s.sets[0]].radius || 50, i = n(s) || "", h = i.split(/\s+/).reverse(), l = (i.length + h.length) / 3;
    let u = h.pop(), o = [u], c = 0;
    const x = 1.1;
    e.textContent = null;
    const d = [];
    function b(k) {
      const f = e.ownerDocument.createElementNS(e.namespaceURI, "tspan");
      return f.textContent = k, d.push(f), e.append(f), f;
    }
    let g = b(u);
    for (; u = h.pop(), !!u; ) {
      o.push(u);
      const k = o.join(" ");
      g.textContent = k, k.length > l && g.getComputedTextLength() > r && (o.pop(), g.textContent = o.join(" "), o = [u], g = b(u), c++);
    }
    const w = 0.35 - c * x / 2, D = e.getAttribute("x"), E = e.getAttribute("y");
    d.forEach((k, f) => {
      k.setAttribute("x", D), k.setAttribute("y", E), k.setAttribute("dy", `${w + f * x}em`);
    });
  };
}
function at(t, n, s) {
  let e = n[0].radius - V(n[0], t);
  for (let r = 1; r < n.length; ++r) {
    const i = n[r].radius - V(n[r], t);
    i <= e && (e = i);
  }
  for (let r = 0; r < s.length; ++r) {
    const i = V(s[r], t) - s[r].radius;
    i <= e && (e = i);
  }
  return e;
}
function Ft(t, n, s) {
  const e = [];
  for (const c of t)
    e.push({ x: c.x, y: c.y }), e.push({ x: c.x + c.radius / 2, y: c.y }), e.push({ x: c.x - c.radius / 2, y: c.y }), e.push({ x: c.x, y: c.y + c.radius / 2 }), e.push({ x: c.x, y: c.y - c.radius / 2 });
  let r = e[0], i = at(e[0], t, n);
  for (let c = 1; c < e.length; ++c) {
    const x = at(e[c], t, n);
    x >= i && (r = e[c], i = x);
  }
  const h = Tt(
    (c) => -1 * at({ x: c[0], y: c[1] }, t, n),
    [r.x, r.y],
    { maxIterations: 500, minErrorDelta: 1e-10 }
  ).x, l = { x: s ? 0 : h[0], y: h[1] };
  let u = !0;
  for (const c of t)
    if (V(l, c) > c.radius) {
      u = !1;
      break;
    }
  for (const c of n)
    if (V(l, c) < c.radius) {
      u = !1;
      break;
    }
  if (u)
    return l;
  if (t.length == 1)
    return { x: t[0].x, y: t[0].y };
  const o = {};
  return nt(t, o), o.arcs.length === 0 ? { x: 0, y: -1e3, disjoint: !0 } : o.arcs.length == 1 ? { x: o.arcs[0].circle.x, y: o.arcs[0].circle.y } : n.length ? Ft(t, []) : St(o.arcs.map((c) => c.p1));
}
function be(t) {
  const n = {}, s = Object.keys(t);
  for (const e of s)
    n[e] = [];
  for (let e = 0; e < s.length; e++) {
    const r = s[e], i = t[r];
    for (let h = e + 1; h < s.length; ++h) {
      const l = s[h], u = t[l], o = V(i, u);
      o + u.radius <= i.radius + 1e-10 ? n[l].push(r) : o + i.radius <= u.radius + 1e-10 && n[r].push(l);
    }
  }
  return n;
}
function Pt(t, n, s) {
  const e = {}, r = be(t);
  for (let i = 0; i < n.length; ++i) {
    const h = n[i].sets, l = {}, u = {};
    for (let d = 0; d < h.length; ++d) {
      l[h[d]] = !0;
      const b = r[h[d]];
      for (let g = 0; g < b.length; ++g)
        u[b[g]] = !0;
    }
    const o = [], c = [];
    for (let d in t)
      d in l ? o.push(t[d]) : d in u || c.push(t[d]);
    const x = Ft(o, c, s);
    e[h] = x, x.disjoint && n[i].size > 0 && console.log("WARNING: area " + h + " not represented on screen");
  }
  return e;
}
function ve(t, n, s) {
  const e = [];
  return e.push(`
M`, t, n), e.push(`
m`, -s, 0), e.push(`
a`, s, s, 0, 1, 0, s * 2, 0), e.push(`
a`, s, s, 0, 1, 0, -s * 2, 0), e.join(" ");
}
function Me(t) {
  const n = t.split(" ");
  return { x: Number.parseFloat(n[1]), y: Number.parseFloat(n[2]), radius: -Number.parseFloat(n[4]) };
}
function Ct(t) {
  if (t.length === 0)
    return [];
  const n = {};
  return nt(t, n), n.arcs;
}
function jt(t, n) {
  if (t.length === 0)
    return "M 0 0";
  const s = Math.pow(10, n || 0), e = n != null ? (i) => Math.round(i * s) / s : (i) => i;
  if (t.length == 1) {
    const i = t[0].circle;
    return ve(e(i.x), e(i.y), e(i.radius));
  }
  const r = [`
M`, e(t[0].p2.x), e(t[0].p2.y)];
  for (const i of t) {
    const h = e(i.circle.radius);
    r.push(`
A`, h, h, 0, i.large ? 1 : 0, i.sweep ? 1 : 0, e(i.p1.x), e(i.p1.y));
  }
  return r.join(" ");
}
function _t(t, n) {
  return jt(Ct(t), n);
}
function ke(t, n = {}) {
  const {
    lossFunction: s,
    layoutFunction: e = zt,
    normalize: r = !0,
    orientation: i = Math.PI / 2,
    orientationOrder: h,
    width: l = 600,
    height: u = 350,
    padding: o = 15,
    scaleToFit: c = !1,
    symmetricalTextCentre: x = !1,
    distinct: d,
    round: b = 2
  } = n;
  let g = e(t, {
    lossFunction: s === "default" || !s ? tt : s === "logRatio" ? Dt : s,
    distinct: d
  });
  r && (g = Rt(g, i, h));
  const w = Nt(g, l, u, o, c), D = Pt(w, t, x), E = new Map(
    Object.keys(w).map((m) => [
      m,
      {
        set: m,
        x: w[m].x,
        y: w[m].y,
        radius: w[m].radius
      }
    ])
  ), k = t.map((m) => {
    const y = m.sets.map((_) => E.get(_)), p = Ct(y), a = jt(p, b);
    return { circles: y, arcs: p, path: a, area: m, has: new Set(m.sets) };
  });
  function f(m) {
    let y = "";
    for (const p of k)
      p.has.size > m.length && m.every((a) => p.has.has(a)) && (y += " " + p.path);
    return y;
  }
  return k.map(({ circles: m, arcs: y, path: p, area: a }) => ({
    data: a,
    text: D[a.sets],
    circles: m,
    arcs: y,
    path: p,
    distinctPath: p + f(a.sets)
  }));
}
var dt = function() {
  var t = /* @__PURE__ */ I(function(k, f, m, y) {
    for (m = m || {}, y = k.length; y--; m[k[y]] = f) ;
    return m;
  }, "o"), n = [5, 8], s = [7, 8, 11, 12, 17, 19, 22, 24], e = [1, 17], r = [1, 18], i = [7, 8, 11, 12, 14, 15, 16, 17, 19, 20, 21, 22, 24, 27], h = [1, 31], l = [1, 39], u = [7, 8, 11, 12, 17, 19, 22, 24, 27], o = [1, 57], c = [1, 56], x = [1, 58], d = [1, 59], b = [1, 60], g = [7, 8, 11, 12, 16, 17, 19, 20, 22, 24, 27, 31, 32, 33], w = {
    trace: /* @__PURE__ */ I(function() {
    }, "trace"),
    yy: {},
    symbols_: { error: 2, start: 3, optNewlines: 4, VENN: 5, document: 6, EOF: 7, NEWLINE: 8, line: 9, statement: 10, TITLE: 11, SET: 12, identifier: 13, BRACKET_LABEL: 14, COLON: 15, NUMERIC: 16, UNION: 17, identifierList: 18, TEXT: 19, IDENTIFIER: 20, STRING: 21, INDENT_TEXT: 22, indentedTextTail: 23, STYLE: 24, stylesOpt: 25, styleField: 26, COMMA: 27, styleValue: 28, valueTokens: 29, valueToken: 30, HEXCOLOR: 31, RGBCOLOR: 32, RGBACOLOR: 33, $accept: 0, $end: 1 },
    terminals_: { 2: "error", 5: "VENN", 7: "EOF", 8: "NEWLINE", 11: "TITLE", 12: "SET", 14: "BRACKET_LABEL", 15: "COLON", 16: "NUMERIC", 17: "UNION", 19: "TEXT", 20: "IDENTIFIER", 21: "STRING", 22: "INDENT_TEXT", 24: "STYLE", 27: "COMMA", 31: "HEXCOLOR", 32: "RGBCOLOR", 33: "RGBACOLOR" },
    productions_: [0, [3, 4], [4, 0], [4, 2], [6, 0], [6, 2], [9, 1], [9, 1], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 2], [10, 3], [10, 4], [10, 5], [10, 3], [10, 3], [10, 3], [10, 4], [10, 4], [10, 2], [10, 3], [23, 1], [23, 1], [23, 1], [23, 2], [23, 2], [25, 1], [25, 3], [26, 3], [28, 1], [28, 1], [29, 1], [29, 2], [30, 1], [30, 1], [30, 1], [30, 1], [30, 1], [18, 1], [18, 3], [13, 1], [13, 1]],
    performAction: /* @__PURE__ */ I(function(k, f, m, y, p, a, _) {
      var M = a.length - 1;
      switch (p) {
        case 1:
          return a[M - 1];
        case 2:
        case 3:
        case 4:
          this.$ = [];
          break;
        case 5:
          a[M - 1].push(a[M]), this.$ = a[M - 1];
          break;
        case 6:
          this.$ = [];
          break;
        case 7:
        case 22:
        case 32:
        case 36:
        case 37:
        case 38:
        case 39:
        case 40:
          this.$ = a[M];
          break;
        case 8:
          y.setDiagramTitle(a[M].substr(6)), this.$ = a[M].substr(6);
          break;
        case 9:
          y.addSubsetData([a[M]], void 0, void 0), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 10:
          y.addSubsetData([a[M - 1]], a[M], void 0), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 11:
          y.addSubsetData([a[M - 2]], void 0, parseFloat(a[M])), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 12:
          y.addSubsetData([a[M - 3]], a[M - 2], parseFloat(a[M])), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 13:
          if (a[M].length < 2)
            throw new Error("union requires multiple identifiers");
          y.validateUnionIdentifiers && y.validateUnionIdentifiers(a[M]), y.addSubsetData(a[M], void 0, void 0), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 14:
          if (a[M - 1].length < 2)
            throw new Error("union requires multiple identifiers");
          y.validateUnionIdentifiers && y.validateUnionIdentifiers(a[M - 1]), y.addSubsetData(a[M - 1], a[M], void 0), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 15:
          if (a[M - 2].length < 2)
            throw new Error("union requires multiple identifiers");
          y.validateUnionIdentifiers && y.validateUnionIdentifiers(a[M - 2]), y.addSubsetData(a[M - 2], void 0, parseFloat(a[M])), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 16:
          if (a[M - 3].length < 2)
            throw new Error("union requires multiple identifiers");
          y.validateUnionIdentifiers && y.validateUnionIdentifiers(a[M - 3]), y.addSubsetData(a[M - 3], a[M - 2], parseFloat(a[M])), y.setIndentMode && y.setIndentMode(!0);
          break;
        case 17:
        case 18:
        case 19:
          y.addTextData(a[M - 1], a[M], void 0);
          break;
        case 20:
        case 21:
          y.addTextData(a[M - 2], a[M - 1], a[M]);
          break;
        case 23:
          y.addStyleData(a[M - 1], a[M]);
          break;
        case 24:
        case 25:
        case 26:
          var S = y.getCurrentSets();
          if (!S) throw new Error("text requires set");
          y.addTextData(S, a[M], void 0);
          break;
        case 27:
        case 28:
          var S = y.getCurrentSets();
          if (!S) throw new Error("text requires set");
          y.addTextData(S, a[M - 1], a[M]);
          break;
        case 29:
        case 41:
          this.$ = [a[M]];
          break;
        case 30:
        case 42:
          this.$ = [...a[M - 2], a[M]];
          break;
        case 31:
          this.$ = [a[M - 2], a[M]];
          break;
        case 33:
          this.$ = a[M].join(" ");
          break;
        case 34:
          this.$ = [a[M]];
          break;
        case 35:
          a[M - 1].push(a[M]), this.$ = a[M - 1];
          break;
        case 43:
        case 44:
          this.$ = a[M];
          break;
      }
    }, "anonymous"),
    table: [t(n, [2, 2], { 3: 1, 4: 2 }), { 1: [3] }, { 5: [1, 3], 8: [1, 4] }, t(s, [2, 4], { 6: 5 }), t(n, [2, 3]), { 7: [1, 6], 8: [1, 8], 9: 7, 10: 9, 11: [1, 10], 12: [1, 11], 17: [1, 12], 19: [1, 13], 22: [1, 14], 24: [1, 15] }, { 1: [2, 1] }, t(s, [2, 5]), t(s, [2, 6]), t(s, [2, 7]), t(s, [2, 8]), { 13: 16, 20: e, 21: r }, { 13: 20, 18: 19, 20: e, 21: r }, { 13: 20, 18: 21, 20: e, 21: r }, { 16: [1, 25], 20: [1, 23], 21: [1, 24], 23: 22 }, { 13: 20, 18: 26, 20: e, 21: r }, t(s, [2, 9], { 14: [1, 27], 15: [1, 28] }), t(i, [2, 43]), t(i, [2, 44]), t(s, [2, 13], { 14: [1, 29], 15: [1, 30], 27: h }), t(i, [2, 41]), { 16: [1, 34], 20: [1, 32], 21: [1, 33], 27: h }, t(s, [2, 22]), t(s, [2, 24], { 14: [1, 35] }), t(s, [2, 25], { 14: [1, 36] }), t(s, [2, 26]), { 20: l, 25: 37, 26: 38, 27: h }, t(s, [2, 10], { 15: [1, 40] }), { 16: [1, 41] }, t(s, [2, 14], { 15: [1, 42] }), { 16: [1, 43] }, { 13: 44, 20: e, 21: r }, t(s, [2, 17], { 14: [1, 45] }), t(s, [2, 18], { 14: [1, 46] }), t(s, [2, 19]), t(s, [2, 27]), t(s, [2, 28]), t(s, [2, 23], { 27: [1, 47] }), t(u, [2, 29]), { 15: [1, 48] }, { 16: [1, 49] }, t(s, [2, 11]), { 16: [1, 50] }, t(s, [2, 15]), t(i, [2, 42]), t(s, [2, 20]), t(s, [2, 21]), { 20: l, 26: 51 }, { 16: o, 20: c, 21: [1, 53], 28: 52, 29: 54, 30: 55, 31: x, 32: d, 33: b }, t(s, [2, 12]), t(s, [2, 16]), t(u, [2, 30]), t(u, [2, 31]), t(u, [2, 32]), t(u, [2, 33], { 30: 61, 16: o, 20: c, 31: x, 32: d, 33: b }), t(g, [2, 34]), t(g, [2, 36]), t(g, [2, 37]), t(g, [2, 38]), t(g, [2, 39]), t(g, [2, 40]), t(g, [2, 35])],
    defaultActions: { 6: [2, 1] },
    parseError: /* @__PURE__ */ I(function(k, f) {
      if (f.recoverable)
        this.trace(k);
      else {
        var m = new Error(k);
        throw m.hash = f, m;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ I(function(k) {
      var f = this, m = [0], y = [], p = [null], a = [], _ = this.table, M = "", S = 0, B = 0, j = 2, U = 1, X = a.slice.call(arguments, 1), z = Object.create(this.lexer), A = { yy: {} };
      for (var N in this.yy)
        Object.prototype.hasOwnProperty.call(this.yy, N) && (A.yy[N] = this.yy[N]);
      z.setInput(k, A.yy), A.yy.lexer = z, A.yy.parser = this, typeof z.yylloc > "u" && (z.yylloc = {});
      var O = z.yylloc;
      a.push(O);
      var L = z.options && z.options.ranges;
      typeof A.yy.parseError == "function" ? this.parseError = A.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function W(C) {
        m.length = m.length - 2 * C, p.length = p.length - C, a.length = a.length - C;
      }
      I(W, "popStack");
      function F() {
        var C;
        return C = y.pop() || z.lex() || U, typeof C != "number" && (C instanceof Array && (y = C, C = y.pop()), C = f.symbols_[C] || C), C;
      }
      I(F, "lex");
      for (var T, P, $, q, Y = {}, v, R, Q, H; ; ) {
        if (P = m[m.length - 1], this.defaultActions[P] ? $ = this.defaultActions[P] : ((T === null || typeof T > "u") && (T = F()), $ = _[P] && _[P][T]), typeof $ > "u" || !$.length || !$[0]) {
          var G = "";
          H = [];
          for (v in _[P])
            this.terminals_[v] && v > j && H.push("'" + this.terminals_[v] + "'");
          z.showPosition ? G = "Parse error on line " + (S + 1) + `:
` + z.showPosition() + `
Expecting ` + H.join(", ") + ", got '" + (this.terminals_[T] || T) + "'" : G = "Parse error on line " + (S + 1) + ": Unexpected " + (T == U ? "end of input" : "'" + (this.terminals_[T] || T) + "'"), this.parseError(G, {
            text: z.match,
            token: this.terminals_[T] || T,
            line: z.yylineno,
            loc: O,
            expected: H
          });
        }
        if ($[0] instanceof Array && $.length > 1)
          throw new Error("Parse Error: multiple actions possible at state: " + P + ", token: " + T);
        switch ($[0]) {
          case 1:
            m.push(T), p.push(z.yytext), a.push(z.yylloc), m.push($[1]), T = null, B = z.yyleng, M = z.yytext, S = z.yylineno, O = z.yylloc;
            break;
          case 2:
            if (R = this.productions_[$[1]][1], Y.$ = p[p.length - R], Y._$ = {
              first_line: a[a.length - (R || 1)].first_line,
              last_line: a[a.length - 1].last_line,
              first_column: a[a.length - (R || 1)].first_column,
              last_column: a[a.length - 1].last_column
            }, L && (Y._$.range = [
              a[a.length - (R || 1)].range[0],
              a[a.length - 1].range[1]
            ]), q = this.performAction.apply(Y, [
              M,
              B,
              S,
              A.yy,
              $[1],
              p,
              a
            ].concat(X)), typeof q < "u")
              return q;
            R && (m = m.slice(0, -1 * R * 2), p = p.slice(0, -1 * R), a = a.slice(0, -1 * R)), m.push(this.productions_[$[1]][0]), p.push(Y.$), a.push(Y._$), Q = _[m[m.length - 2]][m[m.length - 1]], m.push(Q);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  }, D = /* @__PURE__ */ function() {
    var k = {
      EOF: 1,
      parseError: /* @__PURE__ */ I(function(f, m) {
        if (this.yy.parser)
          this.yy.parser.parseError(f, m);
        else
          throw new Error(f);
      }, "parseError"),
      // resets the lexer, sets new input
      setInput: /* @__PURE__ */ I(function(f, m) {
        return this.yy = m || this.yy || {}, this._input = f, 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"),
      // consumes and returns one char from the input
      input: /* @__PURE__ */ I(function() {
        var f = this._input[0];
        this.yytext += f, this.yyleng++, this.offset++, this.match += f, this.matched += f;
        var m = f.match(/(?:\r\n?|\n).*/g);
        return m ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), f;
      }, "input"),
      // unshifts one char (or a string) into the input
      unput: /* @__PURE__ */ I(function(f) {
        var m = f.length, y = f.split(/(?:\r\n?|\n)/g);
        this._input = f + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - m), this.offset -= m;
        var p = 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), y.length - 1 && (this.yylineno -= y.length - 1);
        var a = 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: y ? (y.length === p.length ? this.yylloc.first_column : 0) + p[p.length - y.length].length - y[0].length : this.yylloc.first_column - m
        }, this.options.ranges && (this.yylloc.range = [a[0], a[0] + this.yyleng - m]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      // When called from action, caches matched text and appends it on next action
      more: /* @__PURE__ */ I(function() {
        return this._more = !0, this;
      }, "more"),
      // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
      reject: /* @__PURE__ */ I(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"),
      // retain first n characters of the match
      less: /* @__PURE__ */ I(function(f) {
        this.unput(this.match.slice(f));
      }, "less"),
      // displays already matched input, i.e. for error messages
      pastInput: /* @__PURE__ */ I(function() {
        var f = this.matched.substr(0, this.matched.length - this.match.length);
        return (f.length > 20 ? "..." : "") + f.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      // displays upcoming input, i.e. for error messages
      upcomingInput: /* @__PURE__ */ I(function() {
        var f = this.match;
        return f.length < 20 && (f += this._input.substr(0, 20 - f.length)), (f.substr(0, 20) + (f.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      // displays the character position where the lexing error occurred, i.e. for error messages
      showPosition: /* @__PURE__ */ I(function() {
        var f = this.pastInput(), m = new Array(f.length + 1).join("-");
        return f + this.upcomingInput() + `
` + m + "^";
      }, "showPosition"),
      // test the lexed token: return FALSE when not a match, otherwise return token
      test_match: /* @__PURE__ */ I(function(f, m) {
        var y, p, a;
        if (this.options.backtrack_lexer && (a = {
          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 && (a.yylloc.range = this.yylloc.range.slice(0))), p = f[0].match(/(?:\r\n?|\n).*/g), p && (this.yylineno += p.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: p ? p[p.length - 1].length - p[p.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + f[0].length
        }, this.yytext += f[0], this.match += f[0], this.matches = f, 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(f[0].length), this.matched += f[0], y = this.performAction.call(this, this.yy, this, m, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), y)
          return y;
        if (this._backtrack) {
          for (var _ in a)
            this[_] = a[_];
          return !1;
        }
        return !1;
      }, "test_match"),
      // return next match in input
      next: /* @__PURE__ */ I(function() {
        if (this.done)
          return this.EOF;
        this._input || (this.done = !0);
        var f, m, y, p;
        this._more || (this.yytext = "", this.match = "");
        for (var a = this._currentRules(), _ = 0; _ < a.length; _++)
          if (y = this._input.match(this.rules[a[_]]), y && (!m || y[0].length > m[0].length)) {
            if (m = y, p = _, this.options.backtrack_lexer) {
              if (f = this.test_match(y, a[_]), f !== !1)
                return f;
              if (this._backtrack) {
                m = !1;
                continue;
              } else
                return !1;
            } else if (!this.options.flex)
              break;
          }
        return m ? (f = this.test_match(m, a[p]), f !== !1 ? f : !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"),
      // return next match that has a token
      lex: /* @__PURE__ */ I(function() {
        var f = this.next();
        return f || this.lex();
      }, "lex"),
      // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
      begin: /* @__PURE__ */ I(function(f) {
        this.conditionStack.push(f);
      }, "begin"),
      // pop the previously active lexer condition state off the condition stack
      popState: /* @__PURE__ */ I(function() {
        var f = this.conditionStack.length - 1;
        return f > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      // produce the lexer rule set which is active for the currently active lexer condition state
      _currentRules: /* @__PURE__ */ I(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"),
      // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
      topState: /* @__PURE__ */ I(function(f) {
        return f = this.conditionStack.length - 1 - Math.abs(f || 0), f >= 0 ? this.conditionStack[f] : "INITIAL";
      }, "topState"),
      // alias for begin(condition)
      pushState: /* @__PURE__ */ I(function(f) {
        this.begin(f);
      }, "pushState"),
      // return the number of states currently on the stack
      stateStackSize: /* @__PURE__ */ I(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ I(function(f, m, y, p) {
        switch (y) {
          case 0:
            break;
          case 1:
            break;
          case 2:
            break;
          case 3:
            if (f.getIndentMode && f.getIndentMode())
              return f.consumeIndentText = !0, this.begin("INITIAL"), 22;
            break;
          case 4:
            break;
          case 5:
            f.setIndentMode && f.setIndentMode(!1), this.begin("INITIAL"), this.unput(m.yytext);
            break;
          case 6:
            return this.begin("bol"), 8;
          case 7:
            break;
          case 8:
            break;
          case 9:
            return 7;
          case 10:
            return 11;
          case 11:
            return 5;
          case 12:
            return 12;
          case 13:
            return 17;
          case 14:
            if (f.consumeIndentText)
              f.consumeIndentText = !1;
            else
              return 19;
            break;
          case 15:
            return 24;
          case 16:
            return m.yytext = m.yytext.slice(2, -2), 14;
          case 17:
            return m.yytext = m.yytext.slice(1, -1).trim(), 14;
          case 18:
            return 16;
          case 19:
            return 31;
          case 20:
            return 33;
          case 21:
            return 32;
          case 22:
            return 20;
          case 23:
            return 21;
          case 24:
            return 27;
          case 25:
            return 15;
        }
      }, "anonymous"),
      rules: [/^(?:%%(?!\{)[^\n]*)/i, /^(?:[^\}]%%[^\n]*)/i, /^(?:[ \t]+(?=[\n\r]))/i, /^(?:[ \t]+(?=text\b))/i, /^(?:[ \t]+)/i, /^(?:[^ \t\n\r])/i, /^(?:[\n\r]+)/i, /^(?:%%[^\n]*)/i, /^(?:[ \t]+)/i, /^(?:$)/i, /^(?:title\s[^#\n;]+)/i, /^(?:venn-beta\b)/i, /^(?:set\b)/i, /^(?:union\b)/i, /^(?:text\b)/i, /^(?:style\b)/i, /^(?:\["[^\"]*"\])/i, /^(?:\[[^\]\"]+\])/i, /^(?:[+-]?(\d+(\.\d+)?|\.\d+))/i, /^(?:#[0-9a-fA-F]{3,8})/i, /^(?:rgba\(\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*\))/i, /^(?:rgb\(\s*[0-9.]+\s*[,]\s*[0-9.]+\s*[,]\s*[0-9.]+\s*\))/i, /^(?:[A-Za-z_][A-Za-z0-9\-_]*)/i, /^(?:"[^\"]*")/i, /^(?:,)/i, /^(?::)/i],
      conditions: { bol: { rules: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], inclusive: !0 }, INITIAL: { rules: [0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], inclusive: !0 } }
    };
    return k;
  }();
  w.lexer = D;
  function E() {
    this.yy = {};
  }
  return I(E, "Parser"), E.prototype = w, w.Parser = E, new E();
}();
dt.parser = dt;
var _e = dt, gt = [], xt = [], pt = [], mt = /* @__PURE__ */ new Set(), bt, vt = !1, we = /* @__PURE__ */ I((t, n, s) => {
  const e = st(t).sort(), r = s ?? 10 / Math.pow(t.length, 2);
  bt = e, e.length === 1 && mt.add(e[0]), gt.push({
    sets: e,
    size: r,
    label: n ? et(n) : void 0
  });
}, "addSubsetData"), Ie = /* @__PURE__ */ I(() => gt, "getSubsetData"), et = /* @__PURE__ */ I((t) => {
  const n = t.trim();
  return n.length >= 2 && n.startsWith('"') && n.endsWith('"') ? n.slice(1, -1) : n;
}, "normalizeText"), Ee = /* @__PURE__ */ I((t) => t && et(t), "normalizeStyleValue"), Se = /* @__PURE__ */ I((t, n, s) => {
  const e = et(n);
  xt.push({
    sets: st(t).sort(),
    id: e,
    label: s ? et(s) : void 0
  });
}, "addTextData"), Te = /* @__PURE__ */ I((t, n) => {
  const s = st(t).sort(), e = {};
  for (const [r, i] of n)
    e[r] = Ee(i) ?? i;
  pt.push({ targets: s, styles: e });
}, "addStyleData"), ze = /* @__PURE__ */ I(() => pt, "getStyleData"), st = /* @__PURE__ */ I((t) => t.map((n) => et(n)), "normalizeIdentifierList"), Ae = /* @__PURE__ */ I((t) => {
  const n = st(t).filter((s) => !mt.has(s));
  if (n.length > 0)
    throw new Error(`unknown set identifier: ${n.join(", ")}`);
}, "validateUnionIdentifiers"), De = /* @__PURE__ */ I(() => xt, "getTextData"), Re = /* @__PURE__ */ I(() => bt, "getCurrentSets"), Ne = /* @__PURE__ */ I(() => vt, "getIndentMode"), Oe = /* @__PURE__ */ I((t) => {
  vt = t;
}, "setIndentMode"), $e = se.venn;
function Lt() {
  return ne($e, wt().venn);
}
I(Lt, "getConfig");
var Fe = /* @__PURE__ */ I(() => {
  ee(), gt.length = 0, xt.length = 0, pt.length = 0, mt.clear(), bt = void 0, vt = !1;
}, "customClear"), Pe = {
  getConfig: Lt,
  clear: Fe,
  setAccTitle: Gt,
  getAccTitle: Yt,
  setDiagramTitle: Xt,
  getDiagramTitle: Wt,
  getAccDescription: Vt,
  setAccDescription: qt,
  addSubsetData: we,
  getSubsetData: Ie,
  addTextData: Se,
  addStyleData: Te,
  validateUnionIdentifiers: Ae,
  getTextData: De,
  getStyleData: ze,
  getCurrentSets: Re,
  getIndentMode: Ne,
  setIndentMode: Oe
}, Ce = /* @__PURE__ */ I((t) => `
  .venn-title {
    font-size: 32px;
    fill: ${t.vennTitleTextColor};
    font-family: ${t.fontFamily};
  }

  .venn-circle text {
    font-size: 48px;
    font-family: ${t.fontFamily};
  }

  .venn-intersection text {
    font-size: 48px;
    fill: ${t.vennSetTextColor};
    font-family: ${t.fontFamily};
  }

  .venn-text-node {
    font-family: ${t.fontFamily};
    color: ${t.vennSetTextColor};
  }
`, "getStyles"), je = Ce;
function Bt(t) {
  const n = /* @__PURE__ */ new Map();
  for (const s of t) {
    const e = s.targets.join("|"), r = n.get(e);
    r ? Object.assign(r, s.styles) : n.set(e, { ...s.styles });
  }
  return n;
}
I(Bt, "buildStyleByKey");
var Le = /* @__PURE__ */ I((t, n, s, e) => {
  var r, i, h;
  const l = e.db, u = (r = l.getConfig) == null ? void 0 : r.call(l), { themeVariables: o, look: c, handDrawnSeed: x } = wt(), d = c === "handDrawn", b = [
    o.venn1,
    o.venn2,
    o.venn3,
    o.venn4,
    o.venn5,
    o.venn6,
    o.venn7,
    o.venn8
  ].filter(Boolean), g = (i = l.getDiagramTitle) == null ? void 0 : i.call(l), w = l.getSubsetData(), D = l.getTextData(), E = Bt(l.getStyleData()), k = (u == null ? void 0 : u.width) ?? 800, f = (u == null ? void 0 : u.height) ?? 450, m = k / 1600, y = g ? 48 * m : 0, p = o.primaryTextColor ?? o.textColor, a = Kt(n);
  a.attr("viewBox", `0 0 ${k} ${f}`), g && a.append("text").text(g).attr("class", "venn-title").attr("font-size", `${32 * m}px`).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("x", "50%").attr("y", 32 * m).style("fill", o.vennTitleTextColor || o.titleColor);
  const _ = rt(document.createElement("div")), M = me().width(k).height(f - y);
  _.datum(w).call(M);
  const S = d ? Zt.svg(_.select("svg").node()) : void 0, B = ke(w, {
    width: k,
    height: f - y,
    padding: (u == null ? void 0 : u.padding) ?? 15
  }), j = /* @__PURE__ */ new Map();
  for (const A of B) {
    const N = Z([...A.data.sets].sort());
    j.set(N, A);
  }
  D.length > 0 && Ut(u, j, _, D, m, E);
  const U = Ht(o.background || "#f4f4f4");
  _.selectAll(".venn-circle").each(function(A, N) {
    var O;
    const L = rt(this), W = Z([...A.sets].sort()), F = E.get(W), T = (F == null ? void 0 : F.fill) || b[N % b.length] || o.primaryColor;
    L.classed(`venn-set-${N % 8}`, !0);
    const P = (F == null ? void 0 : F["fill-opacity"]) ?? 0.1, $ = (F == null ? void 0 : F.stroke) || T, q = (F == null ? void 0 : F["stroke-width"]) || `${5 * m}`;
    if (d && S) {
      const v = j.get(W);
      if (v && v.circles.length > 0) {
        const R = v.circles[0], Q = S.circle(R.x, R.y, R.radius * 2, {
          roughness: 0.7,
          seed: x,
          fill: Mt(T, 0.7),
          fillStyle: "hachure",
          fillWeight: 2,
          hachureGap: 8,
          hachureAngle: -41 + N * 60,
          stroke: $,
          strokeWidth: parseFloat(String(q))
        });
        L.select("path").remove(), (O = L.node()) == null || O.insertBefore(Q, L.select("text").node());
      }
    } else
      L.select("path").style("fill", T).style("fill-opacity", P).style("stroke", $).style("stroke-width", q).style("stroke-opacity", 0.95);
    const Y = (F == null ? void 0 : F.color) || (U ? Qt(T, 30) : Jt(T, 30));
    L.select("text").style("font-size", `${48 * m}px`).style("fill", Y);
  }), d && S ? _.selectAll(".venn-intersection").each(function(A) {
    var N;
    const O = rt(this), L = Z([...A.sets].sort()), W = E.get(L), F = W == null ? void 0 : W.fill;
    if (F) {
      const T = O.select("path"), P = T.attr("d");
      if (P) {
        const $ = S.path(P, {
          roughness: 0.7,
          seed: x,
          fill: Mt(F, 0.3),
          fillStyle: "cross-hatch",
          fillWeight: 2,
          hachureGap: 6,
          hachureAngle: 60,
          stroke: "none"
        }), q = T.node();
        (N = q == null ? void 0 : q.parentNode) == null || N.insertBefore($, q), T.remove();
      }
    } else
      O.select("path").style("fill-opacity", 0);
    O.select("text").style("font-size", `${48 * m}px`).style("fill", (W == null ? void 0 : W.color) ?? o.vennSetTextColor ?? p);
  }) : (_.selectAll(".venn-intersection text").style("font-size", `${48 * m}px`).style("fill", (A) => {
    var N;
    const O = Z([...A.sets].sort());
    return ((N = E.get(O)) == null ? void 0 : N.color) ?? o.vennSetTextColor ?? p;
  }), _.selectAll(".venn-intersection path").style("fill-opacity", (A) => {
    var N;
    const O = Z([...A.sets].sort());
    return (N = E.get(O)) != null && N.fill ? 1 : 0;
  }).style("fill", (A) => {
    var N;
    const O = Z([...A.sets].sort());
    return ((N = E.get(O)) == null ? void 0 : N.fill) ?? "transparent";
  }));
  const X = a.append("g").attr("transform", `translate(0, ${y})`), z = _.select("svg").node();
  if (z && "childNodes" in z)
    for (const A of [...z.childNodes])
      (h = X.node()) == null || h.appendChild(A);
  te(a, f, k, (u == null ? void 0 : u.useMaxWidth) ?? !0);
}, "draw");
function Z(t) {
  return t.join("|");
}
I(Z, "stableSetsKey");
function Ut(t, n, s, e, r, i) {
  var h;
  const l = (t == null ? void 0 : t.useDebugLayout) ?? !1, u = s.select("svg").append("g").attr("class", "venn-text-nodes"), o = /* @__PURE__ */ new Map();
  for (const c of e) {
    const x = Z(c.sets), d = o.get(x);
    d ? d.push(c) : o.set(x, [c]);
  }
  for (const [c, x] of o.entries()) {
    const d = n.get(c);
    if (!(d != null && d.text))
      continue;
    const b = d.text.x, g = d.text.y, w = Math.min(...d.circles.map((j) => j.radius)), D = Math.min(
      ...d.circles.map((j) => j.radius - Math.hypot(b - j.x, g - j.y))
    );
    let E = Number.isFinite(D) ? Math.max(0, D) : 0;
    E === 0 && Number.isFinite(w) && (E = w * 0.6);
    const k = u.append("g").attr("class", "venn-text-area").attr("font-size", `${40 * r}px`);
    l && k.append("circle").attr("class", "venn-text-debug-circle").attr("cx", b).attr("cy", g).attr("r", E).attr("fill", "none").attr("stroke", "purple").attr("stroke-width", 1.5 * r).attr("stroke-dasharray", `${6 * r} ${4 * r}`);
    const f = Math.max(80 * r, E * 2 * 0.95), m = Math.max(60 * r, E * 2 * 0.95), y = (d.data.label && d.data.label.length > 0 ? Math.min(32 * r, E * 0.25) : 0) + (x.length <= 2 ? 30 * r : 0), p = b - f / 2, a = g - m / 2 + y, _ = Math.max(1, Math.ceil(Math.sqrt(x.length))), M = Math.max(1, Math.ceil(x.length / _)), S = f / _, B = m / M;
    for (const [j, U] of x.entries()) {
      const X = j % _, z = Math.floor(j / _), A = p + S * (X + 0.5), N = a + B * (z + 0.5);
      l && k.append("rect").attr("class", "venn-text-debug-cell").attr("x", p + S * X).attr("y", a + B * z).attr("width", S).attr("height", B).attr("fill", "none").attr("stroke", "teal").attr("stroke-width", 1 * r).attr("stroke-dasharray", `${4 * r} ${3 * r}`);
      const O = S * 0.9, L = B * 0.9, W = k.append("foreignObject").attr("class", "venn-text-node-fo").attr("width", O).attr("height", L).attr("x", A - O / 2).attr("y", N - L / 2).attr("overflow", "visible"), F = (h = i.get(U.id)) == null ? void 0 : h.color, T = W.append("xhtml:span").attr("class", "venn-text-node").style("display", "flex").style("width", "100%").style("height", "100%").style("white-space", "normal").style("align-items", "center").style("justify-content", "center").style("text-align", "center").style("overflow-wrap", "normal").style("word-break", "normal").text(U.label ?? U.id);
      F && T.style("color", F);
    }
  }
}
I(Ut, "renderTextNodes");
var Be = { draw: Le }, qe = {
  parser: _e,
  db: Pe,
  renderer: Be,
  styles: je
};
export {
  qe as diagram
};
