/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/parliament-svg@3.0.0/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";import{s as hastH}from"hastscript";import roundTo from"lodash/round.js";import sl from"sainte-lague";const pi=Math.PI,round=t=>roundTo(t,10),seatSum=t=>{let o=0;for(const e in t)o+=t[e].seats;return o},merge=t=>{let o=[];for(const e of t)o=o.concat(e);return o},coords=(t,o)=>({x:round(t*Math.cos(o/t-pi)),y:round(t*Math.sin(o/t-pi))}),calculateSeatDistance=(t,o,e)=>pi*o*e/(t-o)/(1+pi*(o-1)*o/2/(t-o)),score=(t,o,e)=>Math.abs(calculateSeatDistance(t,o,e)*o/e-5/7),calculateNumberOfRings=(t,o)=>{let e=Math.floor(Math.log(t)/Math.log(2))||1,n=score(t,e,o),r=0;for(score(t,e+1,o)<n&&(r=1),score(t,e-1,o)<n&&e>1&&(r=-1);score(t,e+r,o)<n&&e>0;)n=score(t,e+r,o),e+=r;return e},nextRing=(t,o)=>{let e,n;for(const r in t)n=round((o[r]||0)/t[r].length),(!e||n<e)&&(e=n);for(const r in t)if(n=round((o[r]||0)/t[r].length),n===e)return r},generatePoints=(t,o)=>{const e=seatSum(t),n=calculateNumberOfRings(e,o),r=calculateSeatDistance(e,n,o);let s=[];for(let t=1;t<=n;t++)s[t]=o-(t-1)*r;s=sl(s,e);const a=[];let l,c,i,u;for(let t=1;t<=n;t++){u=[],l=o-(t-1)*r,c=pi*l/(s[t]-1||1);for(let o=0;o<=s[t]-1;o++)i=coords(l,o*c),i.r=.4*r,u.push(i);a.push(u)}const f=Array(a.length).fill(0);for(const o in t)for(let e=0;e<t[o].seats;e++)u=nextRing(a,f),a[u][f[u]].fill=t[o].colour,a[u][f[u]].party=o,f[u]++;return merge(a)},pointToSVG=t=>o=>t("circle",{cx:o.x,cy:o.y,r:o.r,fill:o.fill,class:o.party}),defaults={seatCount:!1,hFunction:hastH},generate=(t,o={})=>{const{seatCount:e,hFunction:n}=Object.assign({},defaults,o);if("boolean"!=typeof e)throw new Error("`seatCount` option must be a boolean");if("function"!=typeof n)throw new Error("`hFunction` option must be a function");const r=20,s=generatePoints(t,r),a=s[0].r/.4,l=s.map(pointToSVG(n));e&&l.push(n("text",{x:0,y:0,"text-anchor":"middle",style:{"font-family":"Helvetica","font-size":"5px"},class:"seatNumber"},l.length));return n("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:[-20-a/2,-20-a/2,40+a,r+a].join(",")},l)};export default generate;
//# sourceMappingURL=/sm/f315315bf8e7a724f1bf2d707f54acbb99d17e8068eb26823daa87adba3299b1.map