//#region ../../node_modules/@upsetjs/venn.js/build/venn.esm.js
var e = 1e-10;
function t(t, o) {
	let s = r(t), l = s.filter((e) => n(e, t)), u = 0, d = 0, f = [];
	if (l.length > 1) {
		let e = c(l);
		for (let t = 0; t < l.length; ++t) {
			let n = l[t];
			n.angle = Math.atan2(n.x - e.x, n.y - e.y);
		}
		l.sort((e, t) => t.angle - e.angle);
		let n = l[l.length - 1];
		for (let e = 0; e < l.length; ++e) {
			let r = l[e];
			d += (n.x + r.x) * (r.y - n.y);
			let o = {
				x: (r.x + n.x) / 2,
				y: (r.y + n.y) / 2
			}, s = null;
			for (let e = 0; e < r.parentIndex.length; ++e) if (n.parentIndex.includes(r.parentIndex[e])) {
				let i = t[r.parentIndex[e]], c = Math.atan2(r.x - i.x, r.y - i.y), l = Math.atan2(n.x - i.x, n.y - i.y), u = l - c;
				u < 0 && (u += 2 * Math.PI);
				let d = l - u / 2, f = a(o, {
					x: i.x + i.radius * Math.sin(d),
					y: i.y + i.radius * Math.cos(d)
				});
				f > i.radius * 2 && (f = i.radius * 2), (s == null || s.width > f) && (s = {
					circle: i,
					width: f,
					p1: r,
					p2: n,
					large: f > i.radius,
					sweep: !0
				});
			}
			s != null && (f.push(s), u += i(s.circle.radius, s.width), n = r);
		}
	} else {
		let n = t[0];
		for (let e = 1; e < t.length; ++e) t[e].radius < n.radius && (n = t[e]);
		let r = !1;
		for (let e = 0; e < t.length; ++e) if (a(t[e], n) > Math.abs(n.radius - t[e].radius)) {
			r = !0;
			break;
		}
		r ? u = d = 0 : (u = n.radius * n.radius * Math.PI, f.push({
			circle: n,
			p1: {
				x: n.x,
				y: n.y + n.radius
			},
			p2: {
				x: n.x - e,
				y: n.y + n.radius
			},
			width: n.radius * 2,
			large: !0,
			sweep: !0
		}));
	}
	return d /= 2, o && (o.area = u + d, o.arcArea = u, o.polygonArea = d, o.arcs = f, o.innerPoints = l, o.intersectionPoints = s), u + d;
}
function n(t, n) {
	return n.every((n) => a(t, n) < n.radius + e);
}
function r(e) {
	let t = [];
	for (let n = 0; n < e.length; ++n) for (let r = n + 1; r < e.length; ++r) {
		let i = s(e[n], e[r]);
		for (let e of i) e.parentIndex = [n, r], t.push(e);
	}
	return t;
}
function i(e, t) {
	return e * e * Math.acos(1 - t / e) - (e - t) * Math.sqrt(t * (2 * e - t));
}
function a(e, t) {
	return Math.sqrt((e.x - t.x) * (e.x - t.x) + (e.y - t.y) * (e.y - t.y));
}
function o(e, t, n) {
	if (n >= e + t) return 0;
	if (n <= Math.abs(e - t)) return Math.PI * Math.min(e, t) * Math.min(e, t);
	let r = e - (n * n - t * t + e * e) / (2 * n), a = t - (n * n - e * e + t * t) / (2 * n);
	return i(e, r) + i(t, a);
}
function s(e, t) {
	let n = a(e, t), r = e.radius, i = t.radius;
	if (n >= r + i || n <= Math.abs(r - i)) return [];
	let o = (r * r - i * i + n * n) / (2 * n), s = Math.sqrt(r * r - o * o), c = e.x + o * (t.x - e.x) / n, l = e.y + o * (t.y - e.y) / n, u = -(t.y - e.y) * (s / n), d = -(t.x - e.x) * (s / n);
	return [{
		x: c + u,
		y: l - d
	}, {
		x: c - u,
		y: l + d
	}];
}
function c(e) {
	let t = {
		x: 0,
		y: 0
	};
	for (let n of e) t.x += n.x, t.y += n.y;
	return t.x /= e.length, t.y /= e.length, t;
}
function l(e, t, n, r) {
	r ||= {};
	let i = r.maxIterations || 100, a = r.tolerance || 1e-10, o = e(t), s = e(n), c = n - t;
	if (o * s > 0) throw "Initial bisect points must have opposite signs";
	if (o === 0) return t;
	if (s === 0) return n;
	for (let n = 0; n < i; ++n) {
		c /= 2;
		let n = t + c, r = e(n);
		if (r * o >= 0 && (t = n), Math.abs(c) < a || r === 0) return n;
	}
	return t + c;
}
function u(e) {
	let t = Array(e);
	for (let n = 0; n < e; ++n) t[n] = 0;
	return t;
}
function d(e, t) {
	return u(e).map(() => u(t));
}
function f(e, t) {
	let n = 0;
	for (let r = 0; r < e.length; ++r) n += e[r] * t[r];
	return n;
}
function p(e) {
	return Math.sqrt(f(e, e));
}
function m(e, t, n) {
	for (let r = 0; r < t.length; ++r) e[r] = t[r] * n;
}
function h(e, t, n, r, i) {
	for (let a = 0; a < e.length; ++a) e[a] = t * n[a] + r * i[a];
}
function g(e, t, n) {
	n ||= {};
	let r = n.maxIterations || t.length * 200, i = n.nonZeroDelta || 1.05, a = n.zeroDelta || .001, o = n.minErrorDelta || 1e-6, s = n.minErrorDelta || 1e-5, c = n.rho === void 0 ? 1 : n.rho, l = n.chi === void 0 ? 2 : n.chi, u = n.psi === void 0 ? -.5 : n.psi, d = n.sigma === void 0 ? .5 : n.sigma, f, p = t.length, m = Array(p + 1);
	m[0] = t, m[0].fx = e(t), m[0].id = 0;
	for (let n = 0; n < p; ++n) {
		let r = t.slice();
		r[n] = r[n] ? r[n] * i : a, m[n + 1] = r, m[n + 1].fx = e(r), m[n + 1].id = n + 1;
	}
	function g(e) {
		for (let t = 0; t < e.length; t++) m[p][t] = e[t];
		m[p].fx = e.fx;
	}
	let _ = (e, t) => e.fx - t.fx, v = t.slice(), y = t.slice(), b = t.slice(), x = t.slice();
	for (let t = 0; t < r; ++t) {
		if (m.sort(_), n.history) {
			let e = m.map((e) => {
				let t = e.slice();
				return t.fx = e.fx, t.id = e.id, t;
			});
			e.sort((e, t) => e.id - t.id), n.history.push({
				x: m[0].slice(),
				fx: m[0].fx,
				simplex: e
			});
		}
		f = 0;
		for (let e = 0; e < p; ++e) f = Math.max(f, Math.abs(m[0][e] - m[1][e]));
		if (Math.abs(m[0].fx - m[p].fx) < o && f < s) break;
		for (let e = 0; e < p; ++e) {
			v[e] = 0;
			for (let t = 0; t < p; ++t) v[e] += m[t][e];
			v[e] /= p;
		}
		let t = m[p];
		if (h(y, 1 + c, v, -c, t), y.fx = e(y), y.fx < m[0].fx) h(x, 1 + l, v, -l, t), x.fx = e(x), x.fx < y.fx ? g(x) : g(y);
		else if (y.fx >= m[p - 1].fx) {
			let n = !1;
			if (y.fx > t.fx ? (h(b, 1 + u, v, -u, t), b.fx = e(b), b.fx < t.fx ? g(b) : n = !0) : (h(b, 1 - u * c, v, u * c, t), b.fx = e(b), b.fx < y.fx ? g(b) : n = !0), n) {
				if (d >= 1) break;
				for (let t = 1; t < m.length; ++t) h(m[t], 1 - d, m[0], d, m[t]), m[t].fx = e(m[t]);
			}
		} else g(y);
	}
	return m.sort(_), {
		fx: m[0].fx,
		x: m[0]
	};
}
function _(e, t, n, r, i, a, o) {
	let s = n.fx, c = f(n.fxprime, t), l = s, u = s, d = c, p = 0;
	i ||= 1, a ||= 1e-6, o ||= .1;
	function m(u, p, m) {
		for (let g = 0; g < 16; ++g) if (i = (u + p) / 2, h(r.x, 1, n.x, i, t), l = r.fx = e(r.x, r.fxprime), d = f(r.fxprime, t), l > s + a * i * c || l >= m) p = i;
		else {
			if (Math.abs(d) <= -o * c) return i;
			d * (p - u) >= 0 && (p = u), u = i, m = l;
		}
		return 0;
	}
	for (let g = 0; g < 10; ++g) {
		if (h(r.x, 1, n.x, i, t), l = r.fx = e(r.x, r.fxprime), d = f(r.fxprime, t), l > s + a * i * c || g && l >= u) return m(p, i, u);
		if (Math.abs(d) <= -o * c) return i;
		if (d >= 0) return m(i, p, l);
		u = l, p = i, i *= 2;
	}
	return i;
}
function v(e, t, n) {
	let r = {
		x: t.slice(),
		fx: 0,
		fxprime: t.slice()
	}, i = {
		x: t.slice(),
		fx: 0,
		fxprime: t.slice()
	}, a = t.slice(), o, s, c = 1, l;
	n ||= {}, l = n.maxIterations || t.length * 20, r.fx = e(r.x, r.fxprime), o = r.fxprime.slice(), m(o, r.fxprime, -1);
	for (let t = 0; t < l; ++t) {
		if (c = _(e, o, r, i, c), n.history && n.history.push({
			x: r.x.slice(),
			fx: r.fx,
			fxprime: r.fxprime.slice(),
			alpha: c
		}), !c) m(o, r.fxprime, -1);
		else {
			h(a, 1, i.fxprime, -1, r.fxprime);
			let e = f(r.fxprime, r.fxprime), t = Math.max(0, f(a, i.fxprime) / e);
			h(o, t, o, -1, i.fxprime), s = r, r = i, i = s;
		}
		if (p(r.fxprime) <= 1e-5) break;
	}
	return n.history && n.history.push({
		x: r.x.slice(),
		fx: r.fx,
		fxprime: r.fxprime.slice(),
		alpha: c
	}), r;
}
function y(e, t = {}) {
	t.maxIterations = t.maxIterations || 500;
	let n = t.initialLayout || T, r = t.lossFunction || O, i = S(e, t), a = n(i, t), o = Object.keys(a), s = [];
	for (let e of o) s.push(a[e].x), s.push(a[e].y);
	let c = g((e) => {
		let t = {};
		for (let n = 0; n < o.length; ++n) {
			let r = o[n];
			t[r] = {
				x: e[2 * n],
				y: e[2 * n + 1],
				radius: a[r].radius
			};
		}
		return r(t, i);
	}, s, t).x;
	for (let e = 0; e < o.length; ++e) {
		let t = o[e];
		a[t].x = c[2 * e], a[t].y = c[2 * e + 1];
	}
	return a;
}
var b = 1e-10;
function x(e, t, n) {
	return Math.min(e, t) * Math.min(e, t) * Math.PI <= n + b ? Math.abs(e - t) : l((r) => o(e, t, r) - n, 0, e + t);
}
function S(e, t = {}) {
	let n = t.distinct, r = e.map((e) => Object.assign({}, e));
	function i(e) {
		return e.join(";");
	}
	if (n) {
		let e = /* @__PURE__ */ new Map();
		for (let t of r) for (let n = 0; n < t.sets.length; n++) {
			let r = String(t.sets[n]);
			e.set(r, t.size + (e.get(r) || 0));
			for (let i = n + 1; i < t.sets.length; i++) {
				let n = String(t.sets[i]), a = `${r};${n}`, o = `${n};${r}`;
				e.set(a, t.size + (e.get(a) || 0)), e.set(o, t.size + (e.get(o) || 0));
			}
		}
		for (let t of r) t.sets.length < 3 && (t.size = e.get(i(t.sets)));
	}
	let a = [], o = /* @__PURE__ */ new Set();
	for (let e of r) if (e.sets.length === 1) a.push(e.sets[0]);
	else if (e.sets.length === 2) {
		let t = e.sets[0], n = e.sets[1];
		o.add(i(e.sets)), o.add(i([n, t]));
	}
	a.sort((e, t) => e === t ? 0 : e < t ? -1 : 1);
	for (let e = 0; e < a.length; ++e) {
		let t = a[e];
		for (let n = e + 1; n < a.length; ++n) {
			let e = a[n];
			o.has(i([t, e])) || r.push({
				sets: [t, e],
				size: 0
			});
		}
	}
	return r;
}
function C(e, t, n) {
	let r = d(t.length, t.length), i = d(t.length, t.length);
	return e.filter((e) => e.sets.length === 2).forEach((e) => {
		let a = n[e.sets[0]], o = n[e.sets[1]], s = x(Math.sqrt(t[a].size / Math.PI), Math.sqrt(t[o].size / Math.PI), e.size);
		r[a][o] = r[o][a] = s;
		let c = 0;
		e.size + 1e-10 >= Math.min(t[a].size, t[o].size) ? c = 1 : e.size <= 1e-10 && (c = -1), i[a][o] = i[o][a] = c;
	}), {
		distances: r,
		constraints: i
	};
}
function w(e, t, n, r) {
	for (let e = 0; e < t.length; ++e) t[e] = 0;
	let i = 0;
	for (let a = 0; a < n.length; ++a) {
		let o = e[2 * a], s = e[2 * a + 1];
		for (let c = a + 1; c < n.length; ++c) {
			let l = e[2 * c], u = e[2 * c + 1], d = n[a][c], f = r[a][c], p = (l - o) * (l - o) + (u - s) * (u - s), m = Math.sqrt(p), h = p - d * d;
			f > 0 && m <= d || f < 0 && m >= d || (i += 2 * h * h, t[2 * a] += 4 * h * (o - l), t[2 * a + 1] += 4 * h * (s - u), t[2 * c] += 4 * h * (l - o), t[2 * c + 1] += 4 * h * (u - s));
		}
	}
	return i;
}
function T(e, t = {}) {
	let n = D(e, t), r = t.lossFunction || O;
	if (e.length >= 8) {
		let i = E(e, t), a = r(i, e), o = r(n, e);
		a + 1e-8 < o && (n = i);
	}
	return n;
}
function E(e, t = {}) {
	let n = t.restarts || 10, r = [], i = {};
	for (let t of e) t.sets.length === 1 && (i[t.sets[0]] = r.length, r.push(t));
	let { distances: a, constraints: o } = C(e, r, i), s = p(a.map(p)) / a.length;
	a = a.map((e) => e.map((e) => e / s));
	let c = (e, t) => w(e, t, a, o), l = null;
	for (let e = 0; e < n; ++e) {
		let e = v(c, u(a.length * 2).map(Math.random), t);
		(!l || e.fx < l.fx) && (l = e);
	}
	let d = l.x, f = {};
	for (let e = 0; e < r.length; ++e) {
		let t = r[e];
		f[t.sets[0]] = {
			x: d[2 * e] * s,
			y: d[2 * e + 1] * s,
			radius: Math.sqrt(t.size / Math.PI)
		};
	}
	if (t.history) for (let e of t.history) m(e.x, s);
	return f;
}
function D(e, t) {
	let n = t && t.lossFunction ? t.lossFunction : O, r = {}, i = {};
	for (let t of e) if (t.sets.length === 1) {
		let e = t.sets[0];
		r[e] = {
			x: 1e10,
			y: 1e10,
			rowid: r.length,
			size: t.size,
			radius: Math.sqrt(t.size / Math.PI)
		}, i[e] = [];
	}
	e = e.filter((e) => e.sets.length === 2);
	for (let t of e) {
		let e = t.weight == null ? 1 : t.weight, n = t.sets[0], a = t.sets[1];
		t.size + b >= Math.min(r[n].size, r[a].size) && (e = 0), i[n].push({
			set: a,
			size: t.size,
			weight: e
		}), i[a].push({
			set: n,
			size: t.size,
			weight: e
		});
	}
	let a = [];
	Object.keys(i).forEach((e) => {
		let t = 0;
		for (let n = 0; n < i[e].length; ++n) t += i[e][n].size * i[e][n].weight;
		a.push({
			set: e,
			size: t
		});
	});
	function o(e, t) {
		return t.size - e.size;
	}
	a.sort(o);
	let c = {};
	function l(e) {
		return e.set in c;
	}
	function u(e, t) {
		r[t].x = e.x, r[t].y = e.y, c[t] = !0;
	}
	u({
		x: 0,
		y: 0
	}, a[0].set);
	for (let t = 1; t < a.length; ++t) {
		let c = a[t].set, f = i[c].filter(l), p = r[c];
		if (f.sort(o), f.length === 0) throw "ERROR: missing pairwise overlap information";
		let m = [];
		for (var d = 0; d < f.length; ++d) {
			let e = r[f[d].set], t = x(p.radius, e.radius, f[d].size);
			m.push({
				x: e.x + t,
				y: e.y
			}), m.push({
				x: e.x - t,
				y: e.y
			}), m.push({
				y: e.y + t,
				x: e.x
			}), m.push({
				y: e.y - t,
				x: e.x
			});
			for (let n = d + 1; n < f.length; ++n) {
				let i = r[f[n].set], a = x(p.radius, i.radius, f[n].size), o = s({
					x: e.x,
					y: e.y,
					radius: t
				}, {
					x: i.x,
					y: i.y,
					radius: a
				});
				m.push(...o);
			}
		}
		let h = 1e50, g = m[0];
		for (let t of m) {
			r[c].x = t.x, r[c].y = t.y;
			let i = n(r, e);
			i < h && (h = i, g = t);
		}
		u(g, c);
	}
	return r;
}
function O(e, n) {
	let r = 0;
	for (let i of n) {
		if (i.sets.length === 1) continue;
		let n;
		if (i.sets.length === 2) {
			let t = e[i.sets[0]], r = e[i.sets[1]];
			n = o(t.radius, r.radius, a(t, r));
		} else n = t(i.sets.map((t) => e[t]));
		let s = i.weight == null ? 1 : i.weight;
		r += s * (n - i.size) * (n - i.size);
	}
	return r;
}
function k(e, n) {
	let r = 0;
	for (let i of n) {
		if (i.sets.length === 1) continue;
		let n;
		if (i.sets.length === 2) {
			let t = e[i.sets[0]], r = e[i.sets[1]];
			n = o(t.radius, r.radius, a(t, r));
		} else n = t(i.sets.map((t) => e[t]));
		let s = i.weight == null ? 1 : i.weight, c = Math.log((n + 1) / (i.size + 1));
		r += s * c * c;
	}
	return r;
}
function A(e, t, n) {
	if (n == null ? e.sort((e, t) => t.radius - e.radius) : e.sort(n), e.length > 0) {
		let t = e[0].x, n = e[0].y;
		for (let r of e) r.x -= t, r.y -= n;
	}
	if (e.length === 2 && a(e[0], e[1]) < Math.abs(e[1].radius - e[0].radius) && (e[1].x = e[0].x + e[0].radius - e[1].radius - 1e-10, e[1].y = e[0].y), e.length > 1) {
		let n = Math.atan2(e[1].x, e[1].y) - t, r = Math.cos(n), i = Math.sin(n);
		for (let t of e) {
			let e = t.x, n = t.y;
			t.x = r * e - i * n, t.y = i * e + r * n;
		}
	}
	if (e.length > 2) {
		let n = Math.atan2(e[2].x, e[2].y) - t;
		for (; n < 0;) n += 2 * Math.PI;
		for (; n > 2 * Math.PI;) n -= 2 * Math.PI;
		if (n > Math.PI) {
			let t = e[1].y / (1e-10 + e[1].x);
			for (let n of e) {
				var r = (n.x + t * n.y) / (1 + t * t);
				n.x = 2 * r - n.x, n.y = 2 * r * t - n.y;
			}
		}
	}
}
function j(e) {
	e.forEach((e) => {
		e.parent = e;
	});
	function t(e) {
		return e.parent !== e && (e.parent = t(e.parent)), e.parent;
	}
	function n(e, n) {
		let r = t(e);
		r.parent = t(n);
	}
	for (let t = 0; t < e.length; ++t) for (let r = t + 1; r < e.length; ++r) {
		let i = e[t].radius + e[r].radius;
		a(e[t], e[r]) + 1e-10 < i && n(e[r], e[t]);
	}
	let r = /* @__PURE__ */ new Map();
	for (let n = 0; n < e.length; ++n) {
		let i = t(e[n]).parent.setid;
		r.has(i) || r.set(i, []), r.get(i).push(e[n]);
	}
	return e.forEach((e) => {
		delete e.parent;
	}), Array.from(r.values());
}
function M(e) {
	let t = (t) => ({
		max: e.reduce((e, n) => Math.max(e, n[t] + n.radius), -Infinity),
		min: e.reduce((e, n) => Math.min(e, n[t] - n.radius), Infinity)
	});
	return {
		xRange: t("x"),
		yRange: t("y")
	};
}
function N(e, t, n) {
	t ??= Math.PI / 2;
	let r = I(e).map((e) => Object.assign({}, e)), i = j(r);
	for (let e of i) {
		A(e, t, n);
		let r = M(e);
		e.size = (r.xRange.max - r.xRange.min) * (r.yRange.max - r.yRange.min), e.bounds = r;
	}
	i.sort((e, t) => t.size - e.size), r = i[0];
	let a = r.bounds, o = (a.xRange.max - a.xRange.min) / 50;
	function s(e, t, n) {
		if (!e) return;
		let i = e.bounds, s, c;
		if (t) s = a.xRange.max - i.xRange.min + o;
		else {
			s = a.xRange.max - i.xRange.max;
			let e = (i.xRange.max - i.xRange.min) / 2 - (a.xRange.max - a.xRange.min) / 2;
			e < 0 && (s += e);
		}
		if (n) c = a.yRange.max - i.yRange.min + o;
		else {
			c = a.yRange.max - i.yRange.max;
			let e = (i.yRange.max - i.yRange.min) / 2 - (a.yRange.max - a.yRange.min) / 2;
			e < 0 && (c += e);
		}
		for (let t of e) t.x += s, t.y += c, r.push(t);
	}
	let c = 1;
	for (; c < i.length;) s(i[c], !0, !1), s(i[c + 1], !1, !0), s(i[c + 2], !0, !0), c += 3, a = M(r);
	return F(r);
}
function P(e, t, n, r, i) {
	let a = I(e);
	t -= 2 * r, n -= 2 * r;
	let { xRange: o, yRange: s } = M(a);
	if (o.max === o.min || s.max === s.min) return console.log("not scaling solution: zero size detected"), e;
	let c, l;
	if (i) {
		let e = Math.sqrt(i / Math.PI) * 2;
		c = t / e, l = n / e;
	} else c = t / (o.max - o.min), l = n / (s.max - s.min);
	let u = Math.min(l, c), d = (t - (o.max - o.min) * u) / 2, f = (n - (s.max - s.min) * u) / 2;
	return F(a.map((e) => ({
		radius: u * e.radius,
		x: r + d + (e.x - o.min) * u,
		y: r + f + (e.y - s.min) * u,
		setid: e.setid
	})));
}
function F(e) {
	let t = {};
	for (let n of e) t[n.setid] = n;
	return t;
}
function I(e) {
	return Object.keys(e).map((t) => Object.assign(e[t], { setid: t }));
}
function L(e = {}) {
	let t = !1, n = 600, r = 350, i = 15, a = 1e3, o = Math.PI / 2, s = !0, c = null, l = !0, u = !0, d = null, f = null, p = !1, m = null, h = e && e.symmetricalTextCentre ? e.symmetricalTextCentre : !1, g = {}, _ = e && e.colourScheme ? e.colourScheme : e && e.colorScheme ? e.colorScheme : [
		"#1f77b4",
		"#ff7f0e",
		"#2ca02c",
		"#d62728",
		"#9467bd",
		"#8c564b",
		"#e377c2",
		"#7f7f7f",
		"#bcbd22",
		"#17becf"
	], v = 0, b = function(e) {
		if (e in g) return g[e];
		var t = g[e] = _[v];
		return v += 1, v >= _.length && (v = 0), t;
	}, x = y, S = O;
	function C(g) {
		let _ = g.datum(), v = /* @__PURE__ */ new Set();
		_.forEach((e) => {
			e.size == 0 && e.sets.length == 1 && v.add(e.sets[0]);
		}), _ = _.filter((e) => !e.sets.some((e) => v.has(e)));
		let y = {}, C = {};
		if (_.length > 0) {
			let e = x(_, {
				lossFunction: S,
				distinct: p
			});
			s && (e = N(e, o, f)), y = P(e, n, r, i, c), C = H(y, _, h);
		}
		let w = {};
		_.forEach((e) => {
			e.label && (w[e.sets] = e.label);
		});
		function T(e) {
			if (e.sets in w) return w[e.sets];
			if (e.sets.length == 1) return "" + e.sets[0];
		}
		g.selectAll("svg").data([y]).enter().append("svg");
		let E = g.select("svg");
		t ? E.attr("viewBox", `0 0 ${n} ${r}`) : E.attr("width", n).attr("height", r);
		let D = {}, O = !1;
		E.selectAll(".venn-area path").each(function(e) {
			let t = this.getAttribute("d");
			e.sets.length == 1 && t && !p && (O = !0, D[e.sets[0]] = W(t));
		});
		function k(e) {
			return (t) => q(e.sets.map((e) => {
				let i = D[e], a = y[e];
				return i ||= {
					x: n / 2,
					y: r / 2,
					radius: 1
				}, a ||= {
					x: n / 2,
					y: r / 2,
					radius: 1
				}, {
					x: i.x * (1 - t) + a.x * t,
					y: i.y * (1 - t) + a.y * t,
					radius: i.radius * (1 - t) + a.radius * t
				};
			}), m);
		}
		let A = E.selectAll(".venn-area").data(_, (e) => e.sets), j = A.enter().append("g").attr("class", (e) => `venn-area venn-${e.sets.length == 1 ? "circle" : "intersection"}${e.colour || e.color ? " venn-coloured" : ""}`).attr("data-venn-sets", (e) => e.sets.join("_")), M = j.append("path"), F = j.append("text").attr("class", "label").text((e) => T(e)).attr("text-anchor", "middle").attr("dy", ".35em").attr("x", n / 2).attr("y", r / 2);
		u && (M.style("fill-opacity", "0").filter((e) => e.sets.length == 1).style("fill", (e) => e.colour ? e.colour : e.color ? e.color : b(e.sets)).style("fill-opacity", ".25"), F.style("fill", (t) => t.colour || t.color ? "#FFF" : e.textFill ? e.textFill : t.sets.length == 1 ? b(t.sets) : "#444"));
		function I(e) {
			return typeof e.transition == "function" ? e.transition("venn").duration(a) : e;
		}
		let L = g;
		O && typeof L.transition == "function" ? (L = I(g), L.selectAll("path").attrTween("d", k)) : L.selectAll("path").attr("d", (e) => q(e.sets.map((e) => y[e])), m);
		let z = L.selectAll("text").filter((e) => e.sets in C).text((e) => T(e)).attr("x", (e) => Math.floor(C[e.sets].x)).attr("y", (e) => Math.floor(C[e.sets].y));
		l && (O ? "on" in z ? z.on("end", R(y, T)) : z.each("end", R(y, T)) : z.each(R(y, T)));
		let B = I(A.exit()).remove();
		typeof A.transition == "function" && B.selectAll("path").attrTween("d", k);
		let V = B.selectAll("text").attr("x", n / 2).attr("y", r / 2);
		return d !== null && (F.style("font-size", "0px"), z.style("font-size", d), V.style("font-size", "0px")), {
			circles: y,
			textCentres: C,
			nodes: A,
			enter: j,
			update: L,
			exit: B
		};
	}
	return C.wrap = function(e) {
		return arguments.length ? (l = e, C) : l;
	}, C.useViewBox = function() {
		return t = !0, C;
	}, C.width = function(e) {
		return arguments.length ? (n = e, C) : n;
	}, C.height = function(e) {
		return arguments.length ? (r = e, C) : r;
	}, C.padding = function(e) {
		return arguments.length ? (i = e, C) : i;
	}, C.distinct = function(e) {
		return arguments.length ? (p = e, C) : p;
	}, C.colours = function(e) {
		return arguments.length ? (b = e, C) : b;
	}, C.colors = function(e) {
		return arguments.length ? (b = e, C) : b;
	}, C.fontSize = function(e) {
		return arguments.length ? (d = e, C) : d;
	}, C.round = function(e) {
		return arguments.length ? (m = e, C) : m;
	}, C.duration = function(e) {
		return arguments.length ? (a = e, C) : a;
	}, C.layoutFunction = function(e) {
		return arguments.length ? (x = e, C) : x;
	}, C.normalize = function(e) {
		return arguments.length ? (s = e, C) : s;
	}, C.scaleToFit = function(e) {
		return arguments.length ? (c = e, C) : c;
	}, C.styled = function(e) {
		return arguments.length ? (u = e, C) : u;
	}, C.orientation = function(e) {
		return arguments.length ? (o = e, C) : o;
	}, C.orientationOrder = function(e) {
		return arguments.length ? (f = e, C) : f;
	}, C.lossFunction = function(e) {
		return arguments.length ? (S = e === "default" ? O : e === "logRatio" ? k : e, C) : S;
	}, C;
}
function R(e, t) {
	return function(n) {
		let r = this, i = e[n.sets[0]].radius || 50, a = t(n) || "", o = a.split(/\s+/).reverse(), s = (a.length + o.length) / 3, c = o.pop(), l = [c], u = 0, d = 1.1;
		r.textContent = null;
		let f = [];
		function p(e) {
			let t = r.ownerDocument.createElementNS(r.namespaceURI, "tspan");
			return t.textContent = e, f.push(t), r.append(t), t;
		}
		let m = p(c);
		for (; c = o.pop(), c;) {
			l.push(c);
			let e = l.join(" ");
			m.textContent = e, e.length > s && m.getComputedTextLength() > i && (l.pop(), m.textContent = l.join(" "), l = [c], m = p(c), u++);
		}
		let h = .35 - u * d / 2, g = r.getAttribute("x"), _ = r.getAttribute("y");
		f.forEach((e, t) => {
			e.setAttribute("x", g), e.setAttribute("y", _), e.setAttribute("dy", `${h + t * d}em`);
		});
	};
}
function z(e, t, n) {
	let r = t[0].radius - a(t[0], e);
	for (let n = 1; n < t.length; ++n) {
		let i = t[n].radius - a(t[n], e);
		i <= r && (r = i);
	}
	for (let t = 0; t < n.length; ++t) {
		let i = a(n[t], e) - n[t].radius;
		i <= r && (r = i);
	}
	return r;
}
function B(e, n, r) {
	let i = [];
	for (let t of e) i.push({
		x: t.x,
		y: t.y
	}), i.push({
		x: t.x + t.radius / 2,
		y: t.y
	}), i.push({
		x: t.x - t.radius / 2,
		y: t.y
	}), i.push({
		x: t.x,
		y: t.y + t.radius / 2
	}), i.push({
		x: t.x,
		y: t.y - t.radius / 2
	});
	let o = i[0], s = z(i[0], e, n);
	for (let t = 1; t < i.length; ++t) {
		let r = z(i[t], e, n);
		r >= s && (o = i[t], s = r);
	}
	let l = g((t) => -1 * z({
		x: t[0],
		y: t[1]
	}, e, n), [o.x, o.y], {
		maxIterations: 500,
		minErrorDelta: 1e-10
	}).x, u = {
		x: r ? 0 : l[0],
		y: l[1]
	}, d = !0;
	for (let t of e) if (a(u, t) > t.radius) {
		d = !1;
		break;
	}
	for (let e of n) if (a(u, e) < e.radius) {
		d = !1;
		break;
	}
	if (d) return u;
	if (e.length == 1) return {
		x: e[0].x,
		y: e[0].y
	};
	let f = {};
	return t(e, f), f.arcs.length === 0 ? {
		x: 0,
		y: -1e3,
		disjoint: !0
	} : f.arcs.length == 1 ? {
		x: f.arcs[0].circle.x,
		y: f.arcs[0].circle.y
	} : n.length ? B(e, []) : c(f.arcs.map((e) => e.p1));
}
function V(e) {
	let t = {}, n = Object.keys(e);
	for (let e of n) t[e] = [];
	for (let r = 0; r < n.length; r++) {
		let i = n[r], o = e[i];
		for (let s = r + 1; s < n.length; ++s) {
			let r = n[s], c = e[r], l = a(o, c);
			l + c.radius <= o.radius + 1e-10 ? t[r].push(i) : l + o.radius <= c.radius + 1e-10 && t[i].push(r);
		}
	}
	return t;
}
function H(e, t, n) {
	let r = {}, i = V(e);
	for (let a = 0; a < t.length; ++a) {
		let o = t[a].sets, s = {}, c = {};
		for (let e = 0; e < o.length; ++e) {
			s[o[e]] = !0;
			let t = i[o[e]];
			for (let e = 0; e < t.length; ++e) c[t[e]] = !0;
		}
		let l = [], u = [];
		for (let t in e) t in s ? l.push(e[t]) : t in c || u.push(e[t]);
		let d = B(l, u, n);
		r[o] = d, d.disjoint && t[a].size > 0 && console.log("WARNING: area " + o + " not represented on screen");
	}
	return r;
}
function U(e, t, n) {
	let r = [];
	return r.push("\nM", e, t), r.push("\nm", -n, 0), r.push("\na", n, n, 0, 1, 0, n * 2, 0), r.push("\na", n, n, 0, 1, 0, -n * 2, 0), r.join(" ");
}
function W(e) {
	let t = e.split(" ");
	return {
		x: Number.parseFloat(t[1]),
		y: Number.parseFloat(t[2]),
		radius: -Number.parseFloat(t[4])
	};
}
function G(e) {
	if (e.length === 0) return [];
	let n = {};
	return t(e, n), n.arcs;
}
function K(e, t) {
	if (e.length === 0) return "M 0 0";
	let n = 10 ** (t || 0), r = t == null ? (e) => e : (e) => Math.round(e * n) / n;
	if (e.length == 1) {
		let t = e[0].circle;
		return U(r(t.x), r(t.y), r(t.radius));
	}
	let i = [
		"\nM",
		r(e[0].p2.x),
		r(e[0].p2.y)
	];
	for (let t of e) {
		let e = r(t.circle.radius);
		i.push("\nA", e, e, 0, +!!t.large, +!!t.sweep, r(t.p1.x), r(t.p1.y));
	}
	return i.join(" ");
}
function q(e, t) {
	return K(G(e), t);
}
function J(e, t = {}) {
	let { lossFunction: n, layoutFunction: r = y, normalize: i = !0, orientation: a = Math.PI / 2, orientationOrder: o, width: s = 600, height: c = 350, padding: l = 15, scaleToFit: u = !1, symmetricalTextCentre: d = !1, distinct: f, round: p = 2 } = t, m = r(e, {
		lossFunction: n === "default" || !n ? O : n === "logRatio" ? k : n,
		distinct: f
	});
	i && (m = N(m, a, o));
	let h = P(m, s, c, l, u), g = H(h, e, d), _ = new Map(Object.keys(h).map((e) => [e, {
		set: e,
		x: h[e].x,
		y: h[e].y,
		radius: h[e].radius
	}])), v = e.map((e) => {
		let t = e.sets.map((e) => _.get(e)), n = G(t);
		return {
			circles: t,
			arcs: n,
			path: K(n, p),
			area: e,
			has: new Set(e.sets)
		};
	});
	function b(e) {
		let t = "";
		for (let n of v) n.has.size > e.length && e.every((e) => n.has.has(e)) && (t += " " + n.path);
		return t;
	}
	return v.map(({ circles: e, arcs: t, path: n, area: r }) => ({
		data: r,
		text: g[r.sets],
		circles: e,
		arcs: t,
		path: n,
		distinctPath: n + b(r.sets)
	}));
}
//#endregion
export { L as VennDiagram, J as layout };
