import { G as Gt, K as Wt, i as Vt, f as Kt, W as Xt, U as Ht, p as w, o as wt, a0 as Yt, q as it, ba as Zt, ar as Jt, as as Qt, at as te, A as ee, H as ne, s as se, bb as ie, F as re } from "./index-CNUFa5l3.js";
var It = (t, n) => ie(t, "a", -n), Et = 1e-10;
function nt(t, n) {
  let s = ae(t), e = s.filter((o) => le(o, t)), i = 0, r = 0, a = [];
  if (e.length > 1) {
    let o = zt(e);
    for (let h = 0; h < e.length; ++h) {
      let u = e[h];
      u.angle = Math.atan2(u.x - o.x, u.y - o.y);
    }
    e.sort((h, u) => u.angle - h.angle);
    let c = e[e.length - 1];
    for (let h = 0; h < e.length; ++h) {
      let u = e[h];
      r += (c.x + u.x) * (u.y - c.y);
      let x = {
        x: (u.x + c.x) / 2,
        y: (u.y + c.y) / 2
      }, f = null;
      for (let m = 0; m < u.parentIndex.length; ++m) if (c.parentIndex.includes(u.parentIndex[m])) {
        let y = t[u.parentIndex[m]], _ = Math.atan2(u.x - y.x, u.y - y.y), E = Math.atan2(c.x - y.x, c.y - y.y), d = E - _;
        d < 0 && (d += 2 * Math.PI);
        let b = E - d / 2, v = W(x, {
          x: y.x + y.radius * Math.sin(b),
          y: y.y + y.radius * Math.cos(b)
        });
        v > y.radius * 2 && (v = y.radius * 2), (f == null || f.width > v) && (f = {
          circle: y,
          width: v,
          p1: u,
          p2: c,
          large: v > y.radius,
          sweep: !0
        });
      }
      f != null && (a.push(f), i += at(f.circle.radius, f.width), c = u);
    }
  } else {
    let o = t[0];
    for (let h = 1; h < t.length; ++h) t[h].radius < o.radius && (o = t[h]);
    let c = !1;
    for (let h = 0; h < t.length; ++h) if (W(t[h], o) > Math.abs(o.radius - t[h].radius)) {
      c = !0;
      break;
    }
    c ? i = r = 0 : (i = o.radius * o.radius * Math.PI, a.push({
      circle: o,
      p1: {
        x: o.x,
        y: o.y + o.radius
      },
      p2: {
        x: o.x - Et,
        y: o.y + o.radius
      },
      width: o.radius * 2,
      large: !0,
      sweep: !0
    }));
  }
  return r /= 2, n && (n.area = i + r, n.arcArea = i, n.polygonArea = r, n.arcs = a, n.innerPoints = e, n.intersectionPoints = s), i + r;
}
function le(t, n) {
  return n.every((s) => W(t, s) < s.radius + Et);
}
function ae(t) {
  let n = [];
  for (let s = 0; s < t.length; ++s) for (let e = s + 1; e < t.length; ++e) {
    let i = St(t[s], t[e]);
    for (let r of i) r.parentIndex = [s, e], n.push(r);
  }
  return n;
}
function at(t, n) {
  return t * t * Math.acos(1 - n / t) - (t - n) * Math.sqrt(n * (2 * t - n));
}
function W(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);
  let e = t - (s * s - n * n + t * t) / (2 * s), i = n - (s * s - t * t + n * n) / (2 * s);
  return at(t, e) + at(n, i);
}
function St(t, n) {
  let s = W(t, n), e = t.radius, i = n.radius;
  if (s >= e + i || s <= Math.abs(e - i)) return [];
  let r = (e * e - i * i + s * s) / (2 * s), a = Math.sqrt(e * e - r * r), o = t.x + r * (n.x - t.x) / s, c = t.y + r * (n.y - t.y) / s, h = -(n.y - t.y) * (a / s), u = -(n.x - t.x) * (a / s);
  return [{
    x: o + h,
    y: c - u
  }, {
    x: o - h,
    y: c + u
  }];
}
function zt(t) {
  let n = {
    x: 0,
    y: 0
  };
  for (let 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 = {});
  let i = e.maxIterations || 100, r = e.tolerance || 1e-10, a = t(n), o = t(s), c = s - n;
  if (a * o > 0) throw "Initial bisect points must have opposite signs";
  if (a === 0) return n;
  if (o === 0) return s;
  for (let h = 0; h < i; ++h) {
    c /= 2;
    let u = n + c, x = t(u);
    if (x * a >= 0 && (n = u), Math.abs(c) < r || x === 0) return u;
  }
  return n + c;
}
function ot(t) {
  let n = Array(t);
  for (let s = 0; s < t; ++s) n[s] = 0;
  return n;
}
function kt(t, n) {
  return ot(t).map(() => ot(n));
}
function Q(t, n) {
  let s = 0;
  for (let e = 0; e < t.length; ++e) s += t[e] * n[e];
  return s;
}
function ht(t) {
  return Math.sqrt(Q(t, t));
}
function ut(t, n, s) {
  for (let e = 0; e < n.length; ++e) t[e] = n[e] * s;
}
function H(t, n, s, e, i) {
  for (let r = 0; r < t.length; ++r) t[r] = n * s[r] + e * i[r];
}
function Tt(t, n, s) {
  s || (s = {});
  let e = s.maxIterations || n.length * 200, i = s.nonZeroDelta || 1.05, r = s.zeroDelta || 1e-3, a = s.minErrorDelta || 1e-6, o = s.minErrorDelta || 1e-5, c = s.rho === void 0 ? 1 : s.rho, h = s.chi === void 0 ? 2 : s.chi, u = s.psi === void 0 ? -0.5 : s.psi, x = s.sigma === void 0 ? 0.5 : s.sigma, f, m = n.length, y = Array(m + 1);
  y[0] = n, y[0].fx = t(n), y[0].id = 0;
  for (let k = 0; k < m; ++k) {
    let l = n.slice();
    l[k] = l[k] ? l[k] * i : r, y[k + 1] = l, y[k + 1].fx = t(l), y[k + 1].id = k + 1;
  }
  function _(k) {
    for (let l = 0; l < k.length; l++) y[m][l] = k[l];
    y[m].fx = k.fx;
  }
  let E = (k, l) => k.fx - l.fx, d = n.slice(), b = n.slice(), v = n.slice(), g = n.slice();
  for (let k = 0; k < e; ++k) {
    if (y.sort(E), s.history) {
      let M = y.map((p) => {
        let A = p.slice();
        return A.fx = p.fx, A.id = p.id, A;
      });
      M.sort((p, A) => p.id - A.id), s.history.push({
        x: y[0].slice(),
        fx: y[0].fx,
        simplex: M
      });
    }
    f = 0;
    for (let M = 0; M < m; ++M) f = Math.max(f, Math.abs(y[0][M] - y[1][M]));
    if (Math.abs(y[0].fx - y[m].fx) < a && f < o) break;
    for (let M = 0; M < m; ++M) {
      d[M] = 0;
      for (let p = 0; p < m; ++p) d[M] += y[p][M];
      d[M] /= m;
    }
    let l = y[m];
    if (H(b, 1 + c, d, -c, l), b.fx = t(b), b.fx < y[0].fx) H(g, 1 + h, d, -h, l), g.fx = t(g), g.fx < b.fx ? _(g) : _(b);
    else if (b.fx >= y[m - 1].fx) {
      let M = !1;
      if (b.fx > l.fx ? (H(v, 1 + u, d, -u, l), v.fx = t(v), v.fx < l.fx ? _(v) : M = !0) : (H(v, 1 - u * c, d, u * c, l), v.fx = t(v), v.fx < b.fx ? _(v) : M = !0), M) {
        if (x >= 1) break;
        for (let p = 1; p < y.length; ++p) H(y[p], 1 - x, y[0], x, y[p]), y[p].fx = t(y[p]);
      }
    } else _(b);
  }
  return y.sort(E), {
    fx: y[0].fx,
    x: y[0]
  };
}
function he(t, n, s, e, i, r, a) {
  let o = s.fx, c = Q(s.fxprime, n), h = o, u = o, x = c, f = 0;
  i || (i = 1), r || (r = 1e-6), a || (a = 0.1);
  function m(y, _, E) {
    for (let d = 0; d < 16; ++d) if (i = (y + _) / 2, H(e.x, 1, s.x, i, n), h = e.fx = t(e.x, e.fxprime), x = Q(e.fxprime, n), h > o + r * i * c || h >= E) _ = i;
    else {
      if (Math.abs(x) <= -a * c) return i;
      x * (_ - y) >= 0 && (_ = y), y = i, E = h;
    }
    return 0;
  }
  for (let y = 0; y < 10; ++y) {
    if (H(e.x, 1, s.x, i, n), h = e.fx = t(e.x, e.fxprime), x = Q(e.fxprime, n), h > o + r * i * c || y && h >= u) return m(f, i, u);
    if (Math.abs(x) <= -a * c) return i;
    if (x >= 0) return m(i, f, h);
    u = h, f = i, i *= 2;
  }
  return i;
}
function ue(t, n, s) {
  let e = {
    x: n.slice(),
    fx: 0,
    fxprime: n.slice()
  }, i = {
    x: n.slice(),
    fx: 0,
    fxprime: n.slice()
  }, r = n.slice(), a, o, c = 1, h;
  s || (s = {}), h = s.maxIterations || n.length * 20, e.fx = t(e.x, e.fxprime), a = e.fxprime.slice(), ut(a, e.fxprime, -1);
  for (let u = 0; u < h; ++u) {
    if (c = he(t, a, e, i, c), s.history && s.history.push({
      x: e.x.slice(),
      fx: e.fx,
      fxprime: e.fxprime.slice(),
      alpha: c
    }), !c) ut(a, e.fxprime, -1);
    else {
      H(r, 1, i.fxprime, -1, e.fxprime);
      let x = Q(e.fxprime, e.fxprime), f = Math.max(0, Q(r, i.fxprime) / x);
      H(a, f, a, -1, i.fxprime), o = e, e = i, i = o;
    }
    if (ht(e.fxprime) <= 1e-5) break;
  }
  return s.history && s.history.push({
    x: e.x.slice(),
    fx: e.fx,
    fxprime: e.fxprime.slice(),
    alpha: c
  }), e;
}
function At(t, n = {}) {
  n.maxIterations = n.maxIterations || 500;
  let s = n.initialLayout || ye, e = n.lossFunction || tt, i = ce(t, n), r = s(i, n), a = Object.keys(r), o = [];
  for (let h of a) o.push(r[h].x), o.push(r[h].y);
  let c = Tt((h) => {
    let u = {};
    for (let x = 0; x < a.length; ++x) {
      let f = a[x];
      u[f] = {
        x: h[2 * x],
        y: h[2 * x + 1],
        radius: r[f].radius
      };
    }
    return e(u, i);
  }, o, n).x;
  for (let h = 0; h < a.length; ++h) {
    let u = a[h];
    r[u].x = c[2 * h], r[u].y = c[2 * h + 1];
  }
  return r;
}
var $t = 1e-10;
function ct(t, n, s) {
  return Math.min(t, n) * Math.min(t, n) * Math.PI <= s + $t ? Math.abs(t - n) : oe((e) => yt(t, n, e) - s, 0, t + n);
}
function ce(t, n = {}) {
  let s = n.distinct, e = t.map((o) => Object.assign({}, o));
  function i(o) {
    return o.join(";");
  }
  if (s) {
    let o = /* @__PURE__ */ new Map();
    for (let c of e) for (let h = 0; h < c.sets.length; h++) {
      let u = String(c.sets[h]);
      o.set(u, c.size + (o.get(u) || 0));
      for (let x = h + 1; x < c.sets.length; x++) {
        let f = String(c.sets[x]), m = `${u};${f}`, y = `${f};${u}`;
        o.set(m, c.size + (o.get(m) || 0)), o.set(y, c.size + (o.get(y) || 0));
      }
    }
    for (let c of e) c.sets.length < 3 && (c.size = o.get(i(c.sets)));
  }
  let r = [], a = /* @__PURE__ */ new Set();
  for (let o of e) if (o.sets.length === 1) r.push(o.sets[0]);
  else if (o.sets.length === 2) {
    let c = o.sets[0], h = o.sets[1];
    a.add(i(o.sets)), a.add(i([h, c]));
  }
  r.sort((o, c) => o === c ? 0 : o < c ? -1 : 1);
  for (let o = 0; o < r.length; ++o) {
    let c = r[o];
    for (let h = o + 1; h < r.length; ++h) {
      let u = r[h];
      a.has(i([c, u])) || e.push({
        sets: [c, u],
        size: 0
      });
    }
  }
  return e;
}
function fe(t, n, s) {
  let e = kt(n.length, n.length), i = kt(n.length, n.length);
  return t.filter((r) => r.sets.length === 2).forEach((r) => {
    let a = s[r.sets[0]], o = s[r.sets[1]], c = ct(Math.sqrt(n[a].size / Math.PI), Math.sqrt(n[o].size / Math.PI), r.size);
    e[a][o] = e[o][a] = c;
    let h = 0;
    r.size + 1e-10 >= Math.min(n[a].size, n[o].size) ? h = 1 : r.size <= 1e-10 && (h = -1), i[a][o] = i[o][a] = h;
  }), {
    distances: e,
    constraints: i
  };
}
function de(t, n, s, e) {
  for (let r = 0; r < n.length; ++r) n[r] = 0;
  let i = 0;
  for (let r = 0; r < s.length; ++r) {
    let a = t[2 * r], o = t[2 * r + 1];
    for (let c = r + 1; c < s.length; ++c) {
      let h = t[2 * c], u = t[2 * c + 1], x = s[r][c], f = e[r][c], m = (h - a) * (h - a) + (u - o) * (u - o), y = Math.sqrt(m), _ = m - x * x;
      f > 0 && y <= x || f < 0 && y >= x || (i += 2 * _ * _, n[2 * r] += 4 * _ * (a - h), n[2 * r + 1] += 4 * _ * (o - u), n[2 * c] += 4 * _ * (h - a), n[2 * c + 1] += 4 * _ * (u - o));
    }
  }
  return i;
}
function ye(t, n = {}) {
  let s = xe(t, n), e = n.lossFunction || tt;
  if (t.length >= 8) {
    let i = ge(t, n), r = e(i, t), a = e(s, t);
    r + 1e-8 < a && (s = i);
  }
  return s;
}
function ge(t, n = {}) {
  let s = n.restarts || 10, e = [], i = {};
  for (let f of t) f.sets.length === 1 && (i[f.sets[0]] = e.length, e.push(f));
  let { distances: r, constraints: a } = fe(t, e, i), o = ht(r.map(ht)) / r.length;
  r = r.map((f) => f.map((m) => m / o));
  let c = (f, m) => de(f, m, r, a), h = null;
  for (let f = 0; f < s; ++f) {
    let m = ue(c, ot(r.length * 2).map(Math.random), n);
    (!h || m.fx < h.fx) && (h = m);
  }
  let u = h.x, x = {};
  for (let f = 0; f < e.length; ++f) {
    let m = e[f];
    x[m.sets[0]] = {
      x: u[2 * f] * o,
      y: u[2 * f + 1] * o,
      radius: Math.sqrt(m.size / Math.PI)
    };
  }
  if (n.history) for (let f of n.history) ut(f.x, o);
  return x;
}
function xe(t, n) {
  let s = n && n.lossFunction ? n.lossFunction : tt, e = {}, i = {};
  for (let x of t) if (x.sets.length === 1) {
    let f = x.sets[0];
    e[f] = {
      x: 1e10,
      y: 1e10,
      rowid: e.length,
      size: x.size,
      radius: Math.sqrt(x.size / Math.PI)
    }, i[f] = [];
  }
  t = t.filter((x) => x.sets.length === 2);
  for (let x of t) {
    let f = x.weight == null ? 1 : x.weight, m = x.sets[0], y = x.sets[1];
    x.size + $t >= Math.min(e[m].size, e[y].size) && (f = 0), i[m].push({
      set: y,
      size: x.size,
      weight: f
    }), i[y].push({
      set: m,
      size: x.size,
      weight: f
    });
  }
  let r = [];
  Object.keys(i).forEach((x) => {
    let f = 0;
    for (let m = 0; m < i[x].length; ++m) f += i[x][m].size * i[x][m].weight;
    r.push({
      set: x,
      size: f
    });
  });
  function a(x, f) {
    return f.size - x.size;
  }
  r.sort(a);
  let o = {};
  function c(x) {
    return x.set in o;
  }
  function h(x, f) {
    e[f].x = x.x, e[f].y = x.y, o[f] = !0;
  }
  h({
    x: 0,
    y: 0
  }, r[0].set);
  for (let x = 1; x < r.length; ++x) {
    let f = r[x].set, m = i[f].filter(c), y = e[f];
    if (m.sort(a), m.length === 0) throw "ERROR: missing pairwise overlap information";
    let _ = [];
    for (var u = 0; u < m.length; ++u) {
      let b = e[m[u].set], v = ct(y.radius, b.radius, m[u].size);
      _.push({
        x: b.x + v,
        y: b.y
      }), _.push({
        x: b.x - v,
        y: b.y
      }), _.push({
        y: b.y + v,
        x: b.x
      }), _.push({
        y: b.y - v,
        x: b.x
      });
      for (let g = u + 1; g < m.length; ++g) {
        let k = e[m[g].set], l = ct(y.radius, k.radius, m[g].size), M = St({
          x: b.x,
          y: b.y,
          radius: v
        }, {
          x: k.x,
          y: k.y,
          radius: l
        });
        _.push(...M);
      }
    }
    let E = 1e50, d = _[0];
    for (let b of _) {
      e[f].x = b.x, e[f].y = b.y;
      let v = s(e, t);
      v < E && (E = v, d = b);
    }
    h(d, f);
  }
  return e;
}
function tt(t, n) {
  let s = 0;
  for (let e of n) {
    if (e.sets.length === 1) continue;
    let i;
    if (e.sets.length === 2) {
      let a = t[e.sets[0]], o = t[e.sets[1]];
      i = yt(a.radius, o.radius, W(a, o));
    } else i = nt(e.sets.map((a) => t[a]));
    let r = e.weight == null ? 1 : e.weight;
    s += r * (i - e.size) * (i - e.size);
  }
  return s;
}
function Rt(t, n) {
  let s = 0;
  for (let e of n) {
    if (e.sets.length === 1) continue;
    let i;
    if (e.sets.length === 2) {
      let o = t[e.sets[0]], c = t[e.sets[1]];
      i = yt(o.radius, c.radius, W(o, c));
    } else i = nt(e.sets.map((o) => t[o]));
    let r = e.weight == null ? 1 : e.weight, a = Math.log((i + 1) / (e.size + 1));
    s += r * a * a;
  }
  return s;
}
function pe(t, n, s) {
  if (s == null ? t.sort((i, r) => r.radius - i.radius) : t.sort(s), t.length > 0) {
    let i = t[0].x, r = t[0].y;
    for (let a of t) a.x -= i, a.y -= r;
  }
  if (t.length === 2 && W(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) {
    let i = Math.atan2(t[1].x, t[1].y) - n, r = Math.cos(i), a = Math.sin(i);
    for (let o of t) {
      let c = o.x, h = o.y;
      o.x = r * c - a * h, o.y = a * c + r * h;
    }
  }
  if (t.length > 2) {
    let i = Math.atan2(t[2].x, t[2].y) - n;
    for (; i < 0; ) i += 2 * Math.PI;
    for (; i > 2 * Math.PI; ) i -= 2 * Math.PI;
    if (i > Math.PI) {
      let r = t[1].y / (1e-10 + t[1].x);
      for (let a of t) {
        var e = (a.x + r * a.y) / (1 + r * r);
        a.x = 2 * e - a.x, a.y = 2 * e * r - a.y;
      }
    }
  }
}
function me(t) {
  t.forEach((i) => {
    i.parent = i;
  });
  function n(i) {
    return i.parent !== i && (i.parent = n(i.parent)), i.parent;
  }
  function s(i, r) {
    let a = n(i);
    a.parent = n(r);
  }
  for (let i = 0; i < t.length; ++i) for (let r = i + 1; r < t.length; ++r) {
    let a = t[i].radius + t[r].radius;
    W(t[i], t[r]) + 1e-10 < a && s(t[r], t[i]);
  }
  let e = /* @__PURE__ */ new Map();
  for (let i = 0; i < t.length; ++i) {
    let r = n(t[i]).parent.setid;
    e.has(r) || e.set(r, []), e.get(r).push(t[i]);
  }
  return t.forEach((i) => {
    delete i.parent;
  }), Array.from(e.values());
}
function ft(t) {
  let n = (s) => ({
    max: t.reduce((e, i) => Math.max(e, i[s] + i.radius), -1 / 0),
    min: t.reduce((e, i) => Math.min(e, i[s] - i.radius), 1 / 0)
  });
  return {
    xRange: n("x"),
    yRange: n("y")
  };
}
function Nt(t, n, s) {
  n ?? (n = Math.PI / 2);
  let e = Ot(t).map((h) => Object.assign({}, h)), i = me(e);
  for (let h of i) {
    pe(h, n, s);
    let u = ft(h);
    h.size = (u.xRange.max - u.xRange.min) * (u.yRange.max - u.yRange.min), h.bounds = u;
  }
  i.sort((h, u) => u.size - h.size), e = i[0];
  let r = e.bounds, a = (r.xRange.max - r.xRange.min) / 50;
  function o(h, u, x) {
    if (!h) return;
    let f = h.bounds, m, y;
    if (u) m = r.xRange.max - f.xRange.min + a;
    else {
      m = r.xRange.max - f.xRange.max;
      let _ = (f.xRange.max - f.xRange.min) / 2 - (r.xRange.max - r.xRange.min) / 2;
      _ < 0 && (m += _);
    }
    if (x) y = r.yRange.max - f.yRange.min + a;
    else {
      y = r.yRange.max - f.yRange.max;
      let _ = (f.yRange.max - f.yRange.min) / 2 - (r.yRange.max - r.yRange.min) / 2;
      _ < 0 && (y += _);
    }
    for (let _ of h) _.x += m, _.y += y, e.push(_);
  }
  let c = 1;
  for (; c < i.length; ) o(i[c], !0, !1), o(i[c + 1], !1, !0), o(i[c + 2], !0, !0), c += 3, r = ft(e);
  return Ft(e);
}
function Dt(t, n, s, e, i) {
  let r = Ot(t);
  n -= 2 * e, s -= 2 * e;
  let { xRange: a, yRange: o } = ft(r);
  if (a.max === a.min || o.max === o.min) return console.log("not scaling solution: zero size detected"), t;
  let c, h;
  if (i) {
    let m = Math.sqrt(i / Math.PI) * 2;
    c = n / m, h = s / m;
  } else c = n / (a.max - a.min), h = s / (o.max - o.min);
  let u = Math.min(h, c), x = (n - (a.max - a.min) * u) / 2, f = (s - (o.max - o.min) * u) / 2;
  return Ft(r.map((m) => ({
    radius: u * m.radius,
    x: e + x + (m.x - a.min) * u,
    y: e + f + (m.y - o.min) * u,
    setid: m.setid
  })));
}
function Ft(t) {
  let n = {};
  for (let s of t) n[s.setid] = s;
  return n;
}
function Ot(t) {
  return Object.keys(t).map((n) => Object.assign(t[n], { setid: n }));
}
function be(t = {}) {
  let n = !1, s = 600, e = 350, i = 15, r = 1e3, a = Math.PI / 2, o = !0, c = null, h = !0, u = !0, x = null, f = null, m = !1, y = null, _ = t && t.symmetricalTextCentre ? t.symmetricalTextCentre : !1, E = {}, d = t && t.colourScheme ? t.colourScheme : t && t.colorScheme ? t.colorScheme : [
    "#1f77b4",
    "#ff7f0e",
    "#2ca02c",
    "#d62728",
    "#9467bd",
    "#8c564b",
    "#e377c2",
    "#7f7f7f",
    "#bcbd22",
    "#17becf"
  ], b = 0, v = function(M) {
    if (M in E) return E[M];
    var p = E[M] = d[b];
    return b += 1, b >= d.length && (b = 0), p;
  }, g = At, k = tt;
  function l(M) {
    let p = M.datum(), A = /* @__PURE__ */ new Set();
    p.forEach((I) => {
      I.size == 0 && I.sets.length == 1 && A.add(I.sets[0]);
    }), p = p.filter((I) => !I.sets.some((F) => A.has(F)));
    let O = {}, B = {};
    if (p.length > 0) {
      let I = g(p, {
        lossFunction: k,
        distinct: m
      });
      o && (I = Nt(I, a, f)), O = Dt(I, s, e, i, c), B = Pt(O, p, _);
    }
    let C = {};
    p.forEach((I) => {
      I.label && (C[I.sets] = I.label);
    });
    function U(I) {
      if (I.sets in C) return C[I.sets];
      if (I.sets.length == 1) return "" + I.sets[0];
    }
    M.selectAll("svg").data([O]).enter().append("svg");
    let V = M.select("svg");
    n ? V.attr("viewBox", `0 0 ${s} ${e}`) : V.attr("width", s).attr("height", e);
    let T = {}, z = !1;
    V.selectAll(".venn-area path").each(function(I) {
      let F = this.getAttribute("d");
      I.sets.length == 1 && F && !m && (z = !0, T[I.sets[0]] = Ie(F));
    });
    function $(I) {
      return (F) => _t(I.sets.map((G) => {
        let J = T[G], X = O[G];
        return J || (J = {
          x: s / 2,
          y: e / 2,
          radius: 1
        }), X || (X = {
          x: s / 2,
          y: e / 2,
          radius: 1
        }), {
          x: J.x * (1 - F) + X.x * F,
          y: J.y * (1 - F) + X.y * F,
          radius: J.radius * (1 - F) + X.radius * F
        };
      }), y);
    }
    let S = V.selectAll(".venn-area").data(p, (I) => I.sets), P = S.enter().append("g").attr("class", (I) => `venn-area venn-${I.sets.length == 1 ? "circle" : "intersection"}${I.colour || I.color ? " venn-coloured" : ""}`).attr("data-venn-sets", (I) => I.sets.join("_")), R = P.append("path"), j = P.append("text").attr("class", "label").text((I) => U(I)).attr("text-anchor", "middle").attr("dy", ".35em").attr("x", s / 2).attr("y", e / 2);
    u && (R.style("fill-opacity", "0").filter((I) => I.sets.length == 1).style("fill", (I) => I.colour ? I.colour : I.color ? I.color : v(I.sets)).style("fill-opacity", ".25"), j.style("fill", (I) => I.colour || I.color ? "#FFF" : t.textFill ? t.textFill : I.sets.length == 1 ? v(I.sets) : "#444"));
    function N(I) {
      return typeof I.transition == "function" ? I.transition("venn").duration(r) : I;
    }
    let q = M;
    z && typeof q.transition == "function" ? (q = N(M), q.selectAll("path").attrTween("d", $)) : q.selectAll("path").attr("d", (I) => _t(I.sets.map((F) => O[F])), y);
    let L = q.selectAll("text").filter((I) => I.sets in B).text((I) => U(I)).attr("x", (I) => Math.floor(B[I.sets].x)).attr("y", (I) => Math.floor(B[I.sets].y));
    h && (z ? "on" in L ? L.on("end", rt(O, U)) : L.each("end", rt(O, U)) : L.each(rt(O, U)));
    let D = N(S.exit()).remove();
    typeof S.transition == "function" && D.selectAll("path").attrTween("d", $);
    let Y = D.selectAll("text").attr("x", s / 2).attr("y", e / 2);
    return x !== null && (j.style("font-size", "0px"), L.style("font-size", x), Y.style("font-size", "0px")), {
      circles: O,
      textCentres: B,
      nodes: S,
      enter: P,
      update: q,
      exit: D
    };
  }
  return l.wrap = function(M) {
    return arguments.length ? (h = M, l) : h;
  }, l.useViewBox = function() {
    return n = !0, l;
  }, l.width = function(M) {
    return arguments.length ? (s = M, l) : s;
  }, l.height = function(M) {
    return arguments.length ? (e = M, l) : e;
  }, l.padding = function(M) {
    return arguments.length ? (i = M, l) : i;
  }, l.distinct = function(M) {
    return arguments.length ? (m = M, l) : m;
  }, l.colours = function(M) {
    return arguments.length ? (v = M, l) : v;
  }, l.colors = function(M) {
    return arguments.length ? (v = M, l) : v;
  }, l.fontSize = function(M) {
    return arguments.length ? (x = M, l) : x;
  }, l.round = function(M) {
    return arguments.length ? (y = M, l) : y;
  }, l.duration = function(M) {
    return arguments.length ? (r = M, l) : r;
  }, l.layoutFunction = function(M) {
    return arguments.length ? (g = M, l) : g;
  }, l.normalize = function(M) {
    return arguments.length ? (o = M, l) : o;
  }, l.scaleToFit = function(M) {
    return arguments.length ? (c = M, l) : c;
  }, l.styled = function(M) {
    return arguments.length ? (u = M, l) : u;
  }, l.orientation = function(M) {
    return arguments.length ? (a = M, l) : a;
  }, l.orientationOrder = function(M) {
    return arguments.length ? (f = M, l) : f;
  }, l.lossFunction = function(M) {
    return arguments.length ? (k = M === "default" ? tt : M === "logRatio" ? Rt : M, l) : k;
  }, l;
}
function rt(t, n) {
  return function(s) {
    let e = this, i = t[s.sets[0]].radius || 50, r = n(s) || "", a = r.split(/\s+/).reverse(), o = (r.length + a.length) / 3, c = a.pop(), h = [c], u = 0, x = 1.1;
    e.textContent = null;
    let f = [];
    function m(b) {
      let v = e.ownerDocument.createElementNS(e.namespaceURI, "tspan");
      return v.textContent = b, f.push(v), e.append(v), v;
    }
    let y = m(c);
    for (; c = a.pop(), c; ) {
      h.push(c);
      let b = h.join(" ");
      y.textContent = b, b.length > o && y.getComputedTextLength() > i && (h.pop(), y.textContent = h.join(" "), h = [c], y = m(c), u++);
    }
    let _ = 0.35 - u * x / 2, E = e.getAttribute("x"), d = e.getAttribute("y");
    f.forEach((b, v) => {
      b.setAttribute("x", E), b.setAttribute("y", d), b.setAttribute("dy", `${_ + v * x}em`);
    });
  };
}
function lt(t, n, s) {
  let e = n[0].radius - W(n[0], t);
  for (let i = 1; i < n.length; ++i) {
    let r = n[i].radius - W(n[i], t);
    r <= e && (e = r);
  }
  for (let i = 0; i < s.length; ++i) {
    let r = W(s[i], t) - s[i].radius;
    r <= e && (e = r);
  }
  return e;
}
function Ct(t, n, s) {
  let e = [];
  for (let u of t) e.push({
    x: u.x,
    y: u.y
  }), e.push({
    x: u.x + u.radius / 2,
    y: u.y
  }), e.push({
    x: u.x - u.radius / 2,
    y: u.y
  }), e.push({
    x: u.x,
    y: u.y + u.radius / 2
  }), e.push({
    x: u.x,
    y: u.y - u.radius / 2
  });
  let i = e[0], r = lt(e[0], t, n);
  for (let u = 1; u < e.length; ++u) {
    let x = lt(e[u], t, n);
    x >= r && (i = e[u], r = x);
  }
  let a = Tt((u) => -1 * lt({
    x: u[0],
    y: u[1]
  }, t, n), [i.x, i.y], {
    maxIterations: 500,
    minErrorDelta: 1e-10
  }).x, o = {
    x: s ? 0 : a[0],
    y: a[1]
  }, c = !0;
  for (let u of t) if (W(o, u) > u.radius) {
    c = !1;
    break;
  }
  for (let u of n) if (W(o, u) < u.radius) {
    c = !1;
    break;
  }
  if (c) return o;
  if (t.length == 1) return {
    x: t[0].x,
    y: t[0].y
  };
  let h = {};
  return nt(t, h), h.arcs.length === 0 ? {
    x: 0,
    y: -1e3,
    disjoint: !0
  } : h.arcs.length == 1 ? {
    x: h.arcs[0].circle.x,
    y: h.arcs[0].circle.y
  } : n.length ? Ct(t, []) : zt(h.arcs.map((u) => u.p1));
}
function ve(t) {
  let n = {}, s = Object.keys(t);
  for (let e of s) n[e] = [];
  for (let e = 0; e < s.length; e++) {
    let i = s[e], r = t[i];
    for (let a = e + 1; a < s.length; ++a) {
      let o = s[a], c = t[o], h = W(r, c);
      h + c.radius <= r.radius + 1e-10 ? n[o].push(i) : h + r.radius <= c.radius + 1e-10 && n[i].push(o);
    }
  }
  return n;
}
function Pt(t, n, s) {
  let e = {}, i = ve(t);
  for (let r = 0; r < n.length; ++r) {
    let a = n[r].sets, o = {}, c = {};
    for (let f = 0; f < a.length; ++f) {
      o[a[f]] = !0;
      let m = i[a[f]];
      for (let y = 0; y < m.length; ++y) c[m[y]] = !0;
    }
    let h = [], u = [];
    for (let f in t) f in o ? h.push(t[f]) : f in c || u.push(t[f]);
    let x = Ct(h, u, s);
    e[a] = x, x.disjoint && n[r].size > 0 && console.log("WARNING: area " + a + " not represented on screen");
  }
  return e;
}
function Me(t, n, s) {
  let 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 Ie(t) {
  let n = t.split(" ");
  return {
    x: Number.parseFloat(n[1]),
    y: Number.parseFloat(n[2]),
    radius: -Number.parseFloat(n[4])
  };
}
function Lt(t) {
  if (t.length === 0) return [];
  let n = {};
  return nt(t, n), n.arcs;
}
function jt(t, n) {
  if (t.length === 0) return "M 0 0";
  let s = 10 ** (n || 0), e = n == null ? (r) => r : (r) => Math.round(r * s) / s;
  if (t.length == 1) {
    let r = t[0].circle;
    return Me(e(r.x), e(r.y), e(r.radius));
  }
  let i = [
    `
M`,
    e(t[0].p2.x),
    e(t[0].p2.y)
  ];
  for (let r of t) {
    let a = e(r.circle.radius);
    i.push(`
A`, a, a, 0, +!!r.large, +!!r.sweep, e(r.p1.x), e(r.p1.y));
  }
  return i.join(" ");
}
function _t(t, n) {
  return jt(Lt(t), n);
}
function ke(t, n = {}) {
  let { lossFunction: s, layoutFunction: e = At, normalize: i = !0, orientation: r = Math.PI / 2, orientationOrder: a, width: o = 600, height: c = 350, padding: h = 15, scaleToFit: u = !1, symmetricalTextCentre: x = !1, distinct: f, round: m = 2 } = n, y = e(t, {
    lossFunction: s === "default" || !s ? tt : s === "logRatio" ? Rt : s,
    distinct: f
  });
  i && (y = Nt(y, r, a));
  let _ = Dt(y, o, c, h, u), E = Pt(_, t, x), d = new Map(Object.keys(_).map((g) => [g, {
    set: g,
    x: _[g].x,
    y: _[g].y,
    radius: _[g].radius
  }])), b = t.map((g) => {
    let k = g.sets.map((M) => d.get(M)), l = Lt(k);
    return {
      circles: k,
      arcs: l,
      path: jt(l, m),
      area: g,
      has: new Set(g.sets)
    };
  });
  function v(g) {
    let k = "";
    for (let l of b) l.has.size > g.length && g.every((M) => l.has.has(M)) && (k += " " + l.path);
    return k;
  }
  return b.map(({ circles: g, arcs: k, path: l, area: M }) => ({
    data: M,
    text: E[M.sets],
    circles: g,
    arcs: k,
    path: l,
    distinctPath: l + v(M.sets)
  }));
}
var dt = function() {
  var t = /* @__PURE__ */ w(function(d, b, v, g) {
    for (v || (v = {}), g = d.length; g--; v[d[g]] = b) ;
    return v;
  }, "o"), n = [5, 8], s = [
    7,
    8,
    11,
    12,
    17,
    19,
    22,
    24
  ], e = [1, 17], i = [1, 18], r = [
    7,
    8,
    11,
    12,
    14,
    15,
    16,
    17,
    19,
    20,
    21,
    22,
    24,
    27
  ], a = [1, 31], o = [1, 39], c = [
    7,
    8,
    11,
    12,
    17,
    19,
    22,
    24,
    27
  ], h = [1, 57], u = [1, 56], x = [1, 58], f = [1, 59], m = [1, 60], y = [
    7,
    8,
    11,
    12,
    16,
    17,
    19,
    20,
    22,
    24,
    27,
    31,
    32,
    33
  ], _ = {
    trace: /* @__PURE__ */ w(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__ */ w(function(d, b, v, g, k, l, M) {
      var p = l.length - 1;
      switch (k) {
        case 1:
          return l[p - 1];
        case 2:
        case 3:
        case 4:
          this.$ = [];
          break;
        case 5:
          l[p - 1].push(l[p]), this.$ = l[p - 1];
          break;
        case 6:
          this.$ = [];
          break;
        case 7:
        case 22:
        case 32:
        case 36:
        case 37:
        case 38:
        case 39:
        case 40:
          this.$ = l[p];
          break;
        case 8:
          g.setDiagramTitle(l[p].substr(6)), this.$ = l[p].substr(6);
          break;
        case 9:
          g.addSubsetData([l[p]], void 0, void 0), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 10:
          g.addSubsetData([l[p - 1]], l[p], void 0), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 11:
          g.addSubsetData([l[p - 2]], void 0, parseFloat(l[p])), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 12:
          g.addSubsetData([l[p - 3]], l[p - 2], parseFloat(l[p])), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 13:
          if (l[p].length < 2) throw Error("union requires multiple identifiers");
          g.validateUnionIdentifiers && g.validateUnionIdentifiers(l[p]), g.addSubsetData(l[p], void 0, void 0), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 14:
          if (l[p - 1].length < 2) throw Error("union requires multiple identifiers");
          g.validateUnionIdentifiers && g.validateUnionIdentifiers(l[p - 1]), g.addSubsetData(l[p - 1], l[p], void 0), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 15:
          if (l[p - 2].length < 2) throw Error("union requires multiple identifiers");
          g.validateUnionIdentifiers && g.validateUnionIdentifiers(l[p - 2]), g.addSubsetData(l[p - 2], void 0, parseFloat(l[p])), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 16:
          if (l[p - 3].length < 2) throw Error("union requires multiple identifiers");
          g.validateUnionIdentifiers && g.validateUnionIdentifiers(l[p - 3]), g.addSubsetData(l[p - 3], l[p - 2], parseFloat(l[p])), g.setIndentMode && g.setIndentMode(!0);
          break;
        case 17:
        case 18:
        case 19:
          g.addTextData(l[p - 1], l[p], void 0);
          break;
        case 20:
        case 21:
          g.addTextData(l[p - 2], l[p - 1], l[p]);
          break;
        case 23:
          g.addStyleData(l[p - 1], l[p]);
          break;
        case 24:
        case 25:
        case 26:
          var A = g.getCurrentSets();
          if (!A) throw Error("text requires set");
          g.addTextData(A, l[p], void 0);
          break;
        case 27:
        case 28:
          var A = g.getCurrentSets();
          if (!A) throw Error("text requires set");
          g.addTextData(A, l[p - 1], l[p]);
          break;
        case 29:
        case 41:
          this.$ = [l[p]];
          break;
        case 30:
        case 42:
          this.$ = [...l[p - 2], l[p]];
          break;
        case 31:
          this.$ = [l[p - 2], l[p]];
          break;
        case 33:
          this.$ = l[p].join(" ");
          break;
        case 34:
          this.$ = [l[p]];
          break;
        case 35:
          l[p - 1].push(l[p]), this.$ = l[p - 1];
          break;
        case 43:
        case 44:
          this.$ = l[p];
          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: i
      },
      {
        13: 20,
        18: 19,
        20: e,
        21: i
      },
      {
        13: 20,
        18: 21,
        20: e,
        21: i
      },
      {
        16: [1, 25],
        20: [1, 23],
        21: [1, 24],
        23: 22
      },
      {
        13: 20,
        18: 26,
        20: e,
        21: i
      },
      t(s, [2, 9], {
        14: [1, 27],
        15: [1, 28]
      }),
      t(r, [2, 43]),
      t(r, [2, 44]),
      t(s, [2, 13], {
        14: [1, 29],
        15: [1, 30],
        27: a
      }),
      t(r, [2, 41]),
      {
        16: [1, 34],
        20: [1, 32],
        21: [1, 33],
        27: a
      },
      t(s, [2, 22]),
      t(s, [2, 24], { 14: [1, 35] }),
      t(s, [2, 25], { 14: [1, 36] }),
      t(s, [2, 26]),
      {
        20: o,
        25: 37,
        26: 38,
        27: a
      },
      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: i
      },
      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(c, [2, 29]),
      { 15: [1, 48] },
      { 16: [1, 49] },
      t(s, [2, 11]),
      { 16: [1, 50] },
      t(s, [2, 15]),
      t(r, [2, 42]),
      t(s, [2, 20]),
      t(s, [2, 21]),
      {
        20: o,
        26: 51
      },
      {
        16: h,
        20: u,
        21: [1, 53],
        28: 52,
        29: 54,
        30: 55,
        31: x,
        32: f,
        33: m
      },
      t(s, [2, 12]),
      t(s, [2, 16]),
      t(c, [2, 30]),
      t(c, [2, 31]),
      t(c, [2, 32]),
      t(c, [2, 33], {
        30: 61,
        16: h,
        20: u,
        31: x,
        32: f,
        33: m
      }),
      t(y, [2, 34]),
      t(y, [2, 36]),
      t(y, [2, 37]),
      t(y, [2, 38]),
      t(y, [2, 39]),
      t(y, [2, 40]),
      t(y, [2, 35])
    ],
    defaultActions: { 6: [2, 1] },
    parseError: /* @__PURE__ */ w(function(d, b) {
      if (b.recoverable) this.trace(d);
      else {
        var v = Error(d);
        throw v.hash = b, v;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ w(function(d) {
      var b = this, v = [0], g = [], k = [null], l = [], M = this.table, p = "", A = 0, O = 0, B = 0, C = 2, U = 1, V = l.slice.call(arguments, 1), T = Object.create(this.lexer), z = { yy: {} };
      for (var $ in this.yy) Object.prototype.hasOwnProperty.call(this.yy, $) && (z.yy[$] = this.yy[$]);
      T.setInput(d, z.yy), z.yy.lexer = T, z.yy.parser = this, T.yylloc === void 0 && (T.yylloc = {});
      var S = T.yylloc;
      l.push(S);
      var P = T.options && T.options.ranges;
      typeof z.yy.parseError == "function" ? this.parseError = z.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function R(K) {
        v.length -= 2 * K, k.length -= K, l.length -= K;
      }
      w(R, "popStack");
      function j() {
        var K = g.pop() || T.lex() || U;
        return typeof K != "number" && (K instanceof Array && (g = K, K = g.pop()), K = b.symbols_[K] || K), K;
      }
      w(j, "lex");
      for (var N, q, L, D, Y, I = {}, F, G, J, X; ; ) {
        if (L = v[v.length - 1], this.defaultActions[L] ? D = this.defaultActions[L] : (N ?? (N = j()), D = M[L] && M[L][N]), D === void 0 || !D.length || !D[0]) {
          var Mt = "";
          for (F in X = [], M[L]) this.terminals_[F] && F > C && X.push("'" + this.terminals_[F] + "'");
          Mt = T.showPosition ? "Parse error on line " + (A + 1) + `:
` + T.showPosition() + `
Expecting ` + X.join(", ") + ", got '" + (this.terminals_[N] || N) + "'" : "Parse error on line " + (A + 1) + ": Unexpected " + (N == U ? "end of input" : "'" + (this.terminals_[N] || N) + "'"), this.parseError(Mt, {
            text: T.match,
            token: this.terminals_[N] || N,
            line: T.yylineno,
            loc: S,
            expected: X
          });
        }
        if (D[0] instanceof Array && D.length > 1) throw Error("Parse Error: multiple actions possible at state: " + L + ", token: " + N);
        switch (D[0]) {
          case 1:
            v.push(N), k.push(T.yytext), l.push(T.yylloc), v.push(D[1]), N = null, q ? (N = q, q = null) : (O = T.yyleng, p = T.yytext, A = T.yylineno, S = T.yylloc, B > 0);
            break;
          case 2:
            if (G = this.productions_[D[1]][1], I.$ = k[k.length - G], I._$ = {
              first_line: l[l.length - (G || 1)].first_line,
              last_line: l[l.length - 1].last_line,
              first_column: l[l.length - (G || 1)].first_column,
              last_column: l[l.length - 1].last_column
            }, P && (I._$.range = [l[l.length - (G || 1)].range[0], l[l.length - 1].range[1]]), Y = this.performAction.apply(I, [
              p,
              O,
              A,
              z.yy,
              D[1],
              k,
              l
            ].concat(V)), Y !== void 0) return Y;
            G && (v = v.slice(0, -1 * G * 2), k = k.slice(0, -1 * G), l = l.slice(0, -1 * G)), v.push(this.productions_[D[1]][0]), k.push(I.$), l.push(I._$), J = M[v[v.length - 2]][v[v.length - 1]], v.push(J);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  };
  _.lexer = /* @__PURE__ */ function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ w(function(d, b) {
        if (this.yy.parser) this.yy.parser.parseError(d, b);
        else throw Error(d);
      }, "parseError"),
      setInput: /* @__PURE__ */ w(function(d, b) {
        return this.yy = b || this.yy || {}, this._input = d, this._more = this._backtrack = this.done = !1, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
          first_line: 1,
          first_column: 0,
          last_line: 1,
          last_column: 0
        }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
      }, "setInput"),
      input: /* @__PURE__ */ w(function() {
        var d = this._input[0];
        return this.yytext += d, this.yyleng++, this.offset++, this.match += d, this.matched += d, d.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), d;
      }, "input"),
      unput: /* @__PURE__ */ w(function(d) {
        var b = d.length, v = d.split(/(?:\r\n?|\n)/g);
        this._input = d + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - b), this.offset -= b;
        var g = 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), v.length - 1 && (this.yylineno -= v.length - 1);
        var k = 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: v ? (v.length === g.length ? this.yylloc.first_column : 0) + g[g.length - v.length].length - v[0].length : this.yylloc.first_column - b
        }, this.options.ranges && (this.yylloc.range = [k[0], k[0] + this.yyleng - b]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ w(function() {
        return this._more = !0, this;
      }, "more"),
      reject: /* @__PURE__ */ w(function() {
        if (this.options.backtrack_lexer) this._backtrack = !0;
        else return this.parseError("Lexical error on line " + (this.yylineno + 1) + `. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
        return this;
      }, "reject"),
      less: /* @__PURE__ */ w(function(d) {
        this.unput(this.match.slice(d));
      }, "less"),
      pastInput: /* @__PURE__ */ w(function() {
        var d = this.matched.substr(0, this.matched.length - this.match.length);
        return (d.length > 20 ? "..." : "") + d.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ w(function() {
        var d = this.match;
        return d.length < 20 && (d += this._input.substr(0, 20 - d.length)), (d.substr(0, 20) + (d.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ w(function() {
        var d = this.pastInput(), b = Array(d.length + 1).join("-");
        return d + this.upcomingInput() + `
` + b + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ w(function(d, b) {
        var v, g, k;
        if (this.options.backtrack_lexer && (k = {
          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 && (k.yylloc.range = this.yylloc.range.slice(0))), g = d[0].match(/(?:\r\n?|\n).*/g), g && (this.yylineno += g.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: g ? g[g.length - 1].length - g[g.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + d[0].length
        }, this.yytext += d[0], this.match += d[0], this.matches = d, 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(d[0].length), this.matched += d[0], v = this.performAction.call(this, this.yy, this, b, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), v) return v;
        if (this._backtrack) {
          for (var l in k) this[l] = k[l];
          return !1;
        }
        return !1;
      }, "test_match"),
      next: /* @__PURE__ */ w(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = !0);
        var d, b, v, g;
        this._more || (this.yytext = "", this.match = "");
        for (var k = this._currentRules(), l = 0; l < k.length; l++) if (v = this._input.match(this.rules[k[l]]), v && (!b || v[0].length > b[0].length)) {
          if (b = v, g = l, this.options.backtrack_lexer) {
            if (d = this.test_match(v, k[l]), d !== !1) return d;
            if (this._backtrack) {
              b = !1;
              continue;
            } else return !1;
          } else if (!this.options.flex) break;
        }
        return b ? (d = this.test_match(b, k[g]), d === !1 ? !1 : d) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      lex: /* @__PURE__ */ w(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ w(function(d) {
        this.conditionStack.push(d);
      }, "begin"),
      popState: /* @__PURE__ */ w(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ w(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__ */ w(function(d) {
        return d = this.conditionStack.length - 1 - Math.abs(d || 0), d >= 0 ? this.conditionStack[d] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ w(function(d) {
        this.begin(d);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ w(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ w(function(d, b, v, g) {
        switch (v) {
          case 0:
            break;
          case 1:
            break;
          case 2:
            break;
          case 3:
            if (d.getIndentMode && d.getIndentMode()) return d.consumeIndentText = !0, this.begin("INITIAL"), 22;
            break;
          case 4:
            break;
          case 5:
            d.setIndentMode && d.setIndentMode(!1), this.begin("INITIAL"), this.unput(b.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 (d.consumeIndentText) d.consumeIndentText = !1;
            else return 19;
            break;
          case 15:
            return 24;
          case 16:
            return b.yytext = b.yytext.slice(2, -2), 14;
          case 17:
            return b.yytext = b.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
        }
      }
    };
  }();
  function E() {
    this.yy = {};
  }
  return w(E, "Parser"), E.prototype = _, _.Parser = E, new E();
}();
dt.parser = dt;
var _e = dt, gt = [], xt = [], pt = [], mt = /* @__PURE__ */ new Set(), bt, vt = !1, we = /* @__PURE__ */ w((t, n, s) => {
  let e = st(t).sort(), i = s ?? 10 / t.length ** 2;
  bt = e, e.length === 1 && mt.add(e[0]), gt.push({
    sets: e,
    size: i,
    label: n ? et(n) : void 0
  });
}, "addSubsetData"), Ee = /* @__PURE__ */ w(() => gt, "getSubsetData"), et = /* @__PURE__ */ w((t) => {
  let n = t.trim();
  return n.length >= 2 && n.startsWith('"') && n.endsWith('"') ? n.slice(1, -1) : n;
}, "normalizeText"), Se = /* @__PURE__ */ w((t) => t && et(t), "normalizeStyleValue"), ze = /* @__PURE__ */ w((t, n, s) => {
  let e = et(n);
  xt.push({
    sets: st(t).sort(),
    id: e,
    label: s ? et(s) : void 0
  });
}, "addTextData"), Te = /* @__PURE__ */ w((t, n) => {
  let s = st(t).sort(), e = {};
  for (let [i, r] of n) e[i] = Se(r) ?? r;
  pt.push({
    targets: s,
    styles: e
  });
}, "addStyleData"), Ae = /* @__PURE__ */ w(() => pt, "getStyleData"), st = /* @__PURE__ */ w((t) => t.map((n) => et(n)), "normalizeIdentifierList"), $e = /* @__PURE__ */ w((t) => {
  let n = st(t).filter((s) => !mt.has(s));
  if (n.length > 0) throw Error(`unknown set identifier: ${n.join(", ")}`);
}, "validateUnionIdentifiers"), Re = /* @__PURE__ */ w(() => xt, "getTextData"), Ne = /* @__PURE__ */ w(() => bt, "getCurrentSets"), De = /* @__PURE__ */ w(() => vt, "getIndentMode"), Fe = /* @__PURE__ */ w((t) => {
  vt = t;
}, "setIndentMode"), Oe = re.venn;
function qt() {
  return se(Oe, wt().venn);
}
w(qt, "getConfig");
var Ce = {
  getConfig: qt,
  clear: /* @__PURE__ */ w(() => {
    ne(), gt.length = 0, xt.length = 0, pt.length = 0, mt.clear(), bt = void 0, vt = !1;
  }, "customClear"),
  setAccTitle: Ht,
  getAccTitle: Xt,
  setDiagramTitle: Kt,
  getDiagramTitle: Vt,
  getAccDescription: Wt,
  setAccDescription: Gt,
  addSubsetData: we,
  getSubsetData: Ee,
  addTextData: ze,
  addStyleData: Te,
  validateUnionIdentifiers: $e,
  getTextData: Re,
  getStyleData: Ae,
  getCurrentSets: Ne,
  getIndentMode: De,
  setIndentMode: Fe
}, Pe = /* @__PURE__ */ w((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");
function Ut(t) {
  let n = /* @__PURE__ */ new Map();
  for (let s of t) {
    let e = s.targets.join("|"), i = n.get(e);
    i ? Object.assign(i, s.styles) : n.set(e, { ...s.styles });
  }
  return n;
}
w(Ut, "buildStyleByKey");
var Le = /* @__PURE__ */ w((t, n, s, e) => {
  var U, V, T;
  let i = e.db, r = (U = i.getConfig) == null ? void 0 : U.call(i), { themeVariables: a, look: o, handDrawnSeed: c } = wt(), h = o === "handDrawn", u = [
    a.venn1,
    a.venn2,
    a.venn3,
    a.venn4,
    a.venn5,
    a.venn6,
    a.venn7,
    a.venn8
  ].filter(Boolean), x = (V = i.getDiagramTitle) == null ? void 0 : V.call(i), f = i.getSubsetData(), m = i.getTextData(), y = Ut(i.getStyleData()), _ = (r == null ? void 0 : r.width) ?? 800, E = (r == null ? void 0 : r.height) ?? 450, d = _ / 1600, b = x ? 48 * d : 0, v = a.primaryTextColor ?? a.textColor, g = Yt(n);
  g.attr("viewBox", `0 0 ${_} ${E}`), x && g.append("text").text(x).attr("class", "venn-title").attr("font-size", `${32 * d}px`).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("x", "50%").attr("y", 32 * d).style("fill", a.vennTitleTextColor || a.titleColor);
  let k = it(document.createElement("div")), l = be().width(_).height(E - b);
  k.datum(f).call(l);
  let M = h ? Zt.svg(k.select("svg").node()) : void 0, p = ke(f, {
    width: _,
    height: E - b,
    padding: (r == null ? void 0 : r.padding) ?? 15
  }), A = /* @__PURE__ */ new Map();
  for (let z of p) {
    let $ = Z([...z.data.sets].sort());
    A.set($, z);
  }
  m.length > 0 && Bt(r, A, k, m, d, y);
  let O = Jt(a.background || "#f4f4f4");
  k.selectAll(".venn-circle").each(function(z, $) {
    var Y;
    let S = it(this), P = Z([...z.sets].sort()), R = y.get(P), j = (R == null ? void 0 : R.fill) || u[$ % u.length] || a.primaryColor;
    S.classed(`venn-set-${$ % 8}`, !0);
    let N = (R == null ? void 0 : R["fill-opacity"]) ?? 0.1, q = (R == null ? void 0 : R.stroke) || j, L = (R == null ? void 0 : R["stroke-width"]) || `${5 * d}`;
    if (h && M) {
      let I = A.get(P);
      if (I && I.circles.length > 0) {
        let F = I.circles[0], G = M.circle(F.x, F.y, F.radius * 2, {
          roughness: 0.7,
          seed: c,
          fill: It(j, 0.7),
          fillStyle: "hachure",
          fillWeight: 2,
          hachureGap: 8,
          hachureAngle: -41 + $ * 60,
          stroke: q,
          strokeWidth: parseFloat(String(L))
        });
        S.select("path").remove(), (Y = S.node()) == null || Y.insertBefore(G, S.select("text").node());
      }
    } else S.select("path").style("fill", j).style("fill-opacity", N).style("stroke", q).style("stroke-width", L).style("stroke-opacity", 0.95);
    let D = (R == null ? void 0 : R.color) || (O ? Qt(j, 30) : te(j, 30));
    S.select("text").style("font-size", `${48 * d}px`).style("fill", D);
  }), h && M ? k.selectAll(".venn-intersection").each(function(z) {
    var j;
    let $ = it(this), S = Z([...z.sets].sort()), P = y.get(S), R = P == null ? void 0 : P.fill;
    if (R) {
      let N = $.select("path"), q = N.attr("d");
      if (q) {
        let L = M.path(q, {
          roughness: 0.7,
          seed: c,
          fill: It(R, 0.3),
          fillStyle: "cross-hatch",
          fillWeight: 2,
          hachureGap: 6,
          hachureAngle: 60,
          stroke: "none"
        }), D = N.node();
        (j = D == null ? void 0 : D.parentNode) == null || j.insertBefore(L, D), N.remove();
      }
    } else $.select("path").style("fill-opacity", 0);
    $.select("text").style("font-size", `${48 * d}px`).style("fill", (P == null ? void 0 : P.color) ?? a.vennSetTextColor ?? v);
  }) : (k.selectAll(".venn-intersection text").style("font-size", `${48 * d}px`).style("fill", (z) => {
    var S;
    let $ = Z([...z.sets].sort());
    return ((S = y.get($)) == null ? void 0 : S.color) ?? a.vennSetTextColor ?? v;
  }), k.selectAll(".venn-intersection path").style("fill-opacity", (z) => {
    var S;
    let $ = Z([...z.sets].sort());
    return +!!((S = y.get($)) != null && S.fill);
  }).style("fill", (z) => {
    var S;
    let $ = Z([...z.sets].sort());
    return ((S = y.get($)) == null ? void 0 : S.fill) ?? "transparent";
  }));
  let B = g.append("g").attr("transform", `translate(0, ${b})`), C = k.select("svg").node();
  if (C && "childNodes" in C) for (let z of [...C.childNodes]) (T = B.node()) == null || T.appendChild(z);
  ee(g, E, _, (r == null ? void 0 : r.useMaxWidth) ?? !0);
}, "draw");
function Z(t) {
  return t.join("|");
}
w(Z, "stableSetsKey");
function Bt(t, n, s, e, i, r) {
  var h;
  let a = (t == null ? void 0 : t.useDebugLayout) ?? !1, o = s.select("svg").append("g").attr("class", "venn-text-nodes"), c = /* @__PURE__ */ new Map();
  for (let u of e) {
    let x = Z(u.sets), f = c.get(x);
    f ? f.push(u) : c.set(x, [u]);
  }
  for (let [u, x] of c.entries()) {
    let f = n.get(u);
    if (!(f != null && f.text)) continue;
    let m = f.text.x, y = f.text.y, _ = Math.min(...f.circles.map((C) => C.radius)), E = Math.min(...f.circles.map((C) => C.radius - Math.hypot(m - C.x, y - C.y))), d = Number.isFinite(E) ? Math.max(0, E) : 0;
    d === 0 && Number.isFinite(_) && (d = _ * 0.6);
    let b = o.append("g").attr("class", "venn-text-area").attr("font-size", `${40 * i}px`);
    a && b.append("circle").attr("class", "venn-text-debug-circle").attr("cx", m).attr("cy", y).attr("r", d).attr("fill", "none").attr("stroke", "purple").attr("stroke-width", 1.5 * i).attr("stroke-dasharray", `${6 * i} ${4 * i}`);
    let v = Math.max(80 * i, d * 2 * 0.95), g = Math.max(60 * i, d * 2 * 0.95), k = (f.data.label && f.data.label.length > 0 ? Math.min(32 * i, d * 0.25) : 0) + (x.length <= 2 ? 30 * i : 0), l = m - v / 2, M = y - g / 2 + k, p = Math.max(1, Math.ceil(Math.sqrt(x.length))), A = Math.max(1, Math.ceil(x.length / p)), O = v / p, B = g / A;
    for (let [C, U] of x.entries()) {
      let V = C % p, T = Math.floor(C / p), z = l + O * (V + 0.5), $ = M + B * (T + 0.5);
      a && b.append("rect").attr("class", "venn-text-debug-cell").attr("x", l + O * V).attr("y", M + B * T).attr("width", O).attr("height", B).attr("fill", "none").attr("stroke", "teal").attr("stroke-width", 1 * i).attr("stroke-dasharray", `${4 * i} ${3 * i}`);
      let S = O * 0.9, P = B * 0.9, R = b.append("foreignObject").attr("class", "venn-text-node-fo").attr("width", S).attr("height", P).attr("x", z - S / 2).attr("y", $ - P / 2).attr("overflow", "visible"), j = (h = r.get(U.id)) == null ? void 0 : h.color, N = R.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);
      j && N.style("color", j);
    }
  }
}
w(Bt, "renderTextNodes");
var qe = {
  parser: _e,
  db: Ce,
  renderer: { draw: Le },
  styles: Pe
};
export {
  qe as diagram
};
