bharat-choropleth-js 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 - 2026-09-05
4
+
5
+ ### Fixed
6
+
7
+ - Values keyed by a feature id the state registry does not know now match. A
8
+ feature was keyed by its id only if the registry recognised it, and otherwise
9
+ fell back to its *label* — so a dataset keyed by id against geometry outside
10
+ the registry, such as this repo's own historical Census bundle with its
11
+ `in-hs-*` ids, silently rendered as "No data" on every region while looking
12
+ perfectly healthy. Each key a caller writes is now recorded against the
13
+ canonical key it addresses, and a feature is matched by exact id, exact label,
14
+ then either resolved through the registry. Found by building a dashboard on
15
+ the historical bundle.
16
+
17
+ ### Changed
18
+
19
+ - The default data source now points at the `v0.3.0` boundary bundle. A release
20
+ pins the geometry a consumer receives, not only the renderer that draws it.
21
+
22
+ ### Added
23
+
24
+ - Exported `loadDistrictTopology` and `loadSubDistrictTopology`, so a custom
25
+ loader can fetch the prepared bundles without re-deriving their URL scheme.
26
+
27
+ ### Changed
28
+
29
+ - Repainting no longer re-unpacks the topology or refits the projection. The
30
+ zero-config facade calls `update({})` for every value written, and both steps
31
+ ran again each time even though neither reads a value. They are now held
32
+ against `states.geometry`, and the decoded features are passed into layer
33
+ preparation rather than unpacked a second time. Mirrors the React renderer.
34
+
35
+ ### Fixed
36
+
37
+ - The default data source now points at the `v0.2.0` boundary bundle. It was
38
+ still pinned to `v0.1.0`, which predates `data/generated/current-2019-subdistricts/`,
39
+ so every sub-district request 404'd — and because a 404 means "this district
40
+ has no sub-district level", the level 0.2.0 added was silently unreachable for
41
+ anyone using the default `dataBaseUrl`. Nothing errored; districts simply
42
+ stayed leaves. Self-hosted `dataBaseUrl` deployments were unaffected.
43
+
3
44
  ## 0.2.0
4
45
 
5
46
  - Added an optional sub-district level below districts — tehsils, taluks,
package/README.md CHANGED
@@ -9,7 +9,7 @@ An accessible SVG India state-to-district-to-sub-district choropleth with no fra
9
9
  ```html
10
10
  <div id="map"></div>
11
11
 
12
- <script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.1.0"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.2.0"></script>
13
13
  <script>
14
14
  var map = new BharatChoropleth("#map");
15
15
 
@@ -145,7 +145,18 @@ const map = new BharatChoropleth("#map");
145
145
  map.states["Goa"] = 6;
146
146
  ```
147
147
 
148
- The ESM entry also exports the full `IndiaChoropleth` engine, the `STATES` registry, `resolveState`, `ATTRIBUTION` and `DEFAULT_DATA_BASE_URL`, plus every type.
148
+ The ESM entry also exports the full `IndiaChoropleth` engine, the `STATES` registry, `resolveState`, `normalizeStateKey`, `ATTRIBUTION`, `DEFAULT_DATA_BASE_URL`, and the two bundle loaders `loadDistrictTopology` / `loadSubDistrictTopology`, plus every type.
149
+
150
+ The loaders are the ones the zero-config map uses, exported so a custom
151
+ `loadDistricts` or `loadSubDistricts` can fetch the prepared bundles without
152
+ re-deriving their URL scheme:
153
+
154
+ ```js
155
+ import { loadSubDistrictTopology, DEFAULT_DATA_BASE_URL } from "bharat-choropleth-js";
156
+
157
+ const geometry = await loadSubDistrictTopology(DEFAULT_DATA_BASE_URL, districtId);
158
+ // null means the bundle holds no sub-districts for this district — it is a leaf.
159
+ ```
149
160
 
150
161
  ## `IndiaChoropleth` (full-featured engine)
151
162
 
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var Ke=`.india-choropleth {
1
+ "use strict";(()=>{var We=`.india-choropleth {
2
2
  --india-map-stroke: #fff;
3
3
  --india-map-stroke-active: #0f1b38;
4
4
  /* Border widths, in screen pixels (the strokes are non-scaling). Override any
@@ -122,5 +122,5 @@ button.india-choropleth__swatch[aria-disabled="true"] { cursor: default; }
122
122
  being fetched, and for the message if that fetch fails. */
123
123
  .bharat-choropleth__status { padding: 1.25rem; border-radius: .625rem; background: var(--india-map-empty, #eef1f7); color: var(--india-map-muted, #53617b); font: 500 .875rem/1.45 system-ui, sans-serif; text-align: center; }
124
124
  .bharat-choropleth__status--error { background: #fdeceb; color: #8a1c14; }
125
- `;var K=class{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){let n=this._partials,i=0;for(let r=0;r<this._n&&r<32;r++){let o=n[r],a=t+o,l=Math.abs(t)<Math.abs(o)?t-(a-o):o-(a-t);l&&(n[i++]=l),t=a}return n[i]=t,this._n=i+1,this}valueOf(){let t=this._partials,n=this._n,i,r,o,a=0;if(n>0){for(a=t[--n];n>0&&(i=a,r=t[--n],a=i+r,o=r-(a-i),!o););n>0&&(o<0&&t[n-1]<0||o>0&&t[n-1]>0)&&(r=o*2,i=a+r,r==i-a&&(a=i))}return a}};function*pi(e){for(let t of e)yield*t}function pt(e){return Array.from(pi(e))}var k=1e-6,Ye=1e-12,_=Math.PI,$=_/2,ue=_/4,q=_*2,V=180/_,F=_/180,M=Math.abs,jt=Math.atan,rt=Math.atan2,T=Math.cos;var Xe=Math.exp;var Je=Math.log;var B=Math.sin,Ze=Math.sign||function(e){return e>0?1:e<0?-1:0},Y=Math.sqrt,Qe=Math.tan;function tn(e){return e>1?0:e<-1?_:Math.acos(e)}function ot(e){return e>1?$:e<-1?-$:Math.asin(e)}function z(){}function $t(e,t){e&&nn.hasOwnProperty(e.type)&&nn[e.type](e,t)}var en={Feature:function(e,t){$t(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,i=-1,r=n.length;++i<r;)$t(n[i].geometry,t)}},nn={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)e=n[i],t.point(e[0],e[1],e[2])},LineString:function(e,t){he(e.coordinates,t,0)},MultiLineString:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)he(n[i],t,0)},Polygon:function(e,t){rn(e.coordinates,t)},MultiPolygon:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)rn(n[i],t)},GeometryCollection:function(e,t){for(var n=e.geometries,i=-1,r=n.length;++i<r;)$t(n[i],t)}};function he(e,t,n){var i=-1,r=e.length-n,o;for(t.lineStart();++i<r;)o=e[i],t.point(o[0],o[1],o[2]);t.lineEnd()}function rn(e,t){var n=-1,i=e.length;for(t.polygonStart();++n<i;)he(e[n],t,1);t.polygonEnd()}function at(e,t){e&&en.hasOwnProperty(e.type)?en[e.type](e,t):$t(e,t)}function St(e){return[rt(e[1],e[0]),ot(e[2])]}function Z(e){var t=e[0],n=e[1],i=T(n);return[i*T(t),i*B(t),B(n)]}function Et(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function ft(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function qt(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function Dt(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function _t(e){var t=Y(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}function It(e,t){function n(i,r){return i=e(i,r),t(i[0],i[1])}return e.invert&&t.invert&&(n.invert=function(i,r){return i=t.invert(i,r),i&&e.invert(i[0],i[1])}),n}function pe(e,t){return M(e)>_&&(e-=Math.round(e/q)*q),[e,t]}pe.invert=pe;function fe(e,t,n){return(e%=q)?t||n?It(an(e),sn(t,n)):an(e):t||n?sn(t,n):pe}function on(e){return function(t,n){return t+=e,M(t)>_&&(t-=Math.round(t/q)*q),[t,n]}}function an(e){var t=on(e);return t.invert=on(-e),t}function sn(e,t){var n=T(e),i=B(e),r=T(t),o=B(t);function a(l,u){var d=T(u),s=T(l)*d,c=B(l)*d,h=B(u),f=h*n+s*i;return[rt(c*r-f*o,s*n-h*i),ot(f*r+c*o)]}return a.invert=function(l,u){var d=T(u),s=T(l)*d,c=B(l)*d,h=B(u),f=h*r-c*o;return[rt(c*r+h*o,s*n+f*i),ot(f*n-s*i)]},a}function ln(e){e=fe(e[0]*F,e[1]*F,e.length>2?e[2]*F:0);function t(n){return n=e(n[0]*F,n[1]*F),n[0]*=V,n[1]*=V,n}return t.invert=function(n){return n=e.invert(n[0]*F,n[1]*F),n[0]*=V,n[1]*=V,n},t}function dn(e,t,n,i,r,o){if(n){var a=T(t),l=B(t),u=i*n;r==null?(r=t+i*q,o=t-u/2):(r=cn(a,r),o=cn(a,o),(i>0?r<o:r>o)&&(r+=i*q));for(var d,s=r;i>0?s>o:s<o;s-=u)d=St([a,-l*T(s),-l*B(s)]),e.point(d[0],d[1])}}function cn(e,t){t=Z(t),t[0]-=e,_t(t);var n=tn(-t[1]);return((-t[2]<0?-n:n)+q-k)%q}function zt(){var e=[],t;return{point:function(n,i,r){t.push([n,i,r])},lineStart:function(){e.push(t=[])},lineEnd:z,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function mt(e,t){return M(e[0]-t[0])<k&&M(e[1]-t[1])<k}function Ht(e,t,n,i){this.x=e,this.z=t,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Ut(e,t,n,i,r){var o=[],a=[],l,u;if(e.forEach(function(m){if(!((S=m.length-1)<=0)){var S,w=m[0],g=m[S],v;if(mt(w,g)){if(!w[2]&&!g[2]){for(r.lineStart(),l=0;l<S;++l)r.point((w=m[l])[0],w[1]);r.lineEnd();return}g[0]+=2*k}o.push(v=new Ht(w,m,null,!0)),a.push(v.o=new Ht(w,null,v,!1)),o.push(v=new Ht(g,m,null,!1)),a.push(v.o=new Ht(g,null,v,!0))}}),!!o.length){for(a.sort(t),un(o),un(a),l=0,u=a.length;l<u;++l)a[l].e=n=!n;for(var d=o[0],s,c;;){for(var h=d,f=!0;h.v;)if((h=h.n)===d)return;s=h.z,r.lineStart();do{if(h.v=h.o.v=!0,h.e){if(f)for(l=0,u=s.length;l<u;++l)r.point((c=s[l])[0],c[1]);else i(h.x,h.n.x,1,r);h=h.n}else{if(f)for(s=h.p.z,l=s.length-1;l>=0;--l)r.point((c=s[l])[0],c[1]);else i(h.x,h.p.x,-1,r);h=h.p}h=h.o,s=h.z,f=!f}while(!h.v);r.lineEnd()}}}function un(e){if(t=e.length){for(var t,n=0,i=e[0],r;++n<t;)i.n=r=e[n],r.p=i,i=r;i.n=r=e[0],r.p=i}}function me(e){return M(e[0])<=_?e[0]:Ze(e[0])*((M(e[0])+_)%q-_)}function hn(e,t){var n=me(t),i=t[1],r=B(i),o=[B(n),-T(n),0],a=0,l=0,u=new K;r===1?i=$+k:r===-1&&(i=-$-k);for(var d=0,s=e.length;d<s;++d)if(h=(c=e[d]).length)for(var c,h,f=c[h-1],m=me(f),S=f[1]/2+ue,w=B(S),g=T(S),v=0;v<h;++v,m=b,w=E,g=C,f=y){var y=c[v],b=me(y),x=y[1]/2+ue,E=B(x),C=T(x),P=b-m,R=P>=0?1:-1,L=R*P,D=L>_,U=w*E;if(u.add(rt(U*R*B(L),g*C+U*T(L))),a+=D?P+R*q:P,D^m>=n^b>=n){var O=ft(Z(f),Z(y));_t(O);var A=ft(o,O);_t(A);var p=(D^P>=0?-1:1)*ot(A[2]);(i>p||i===p&&(O[0]||O[1]))&&(l+=D^P>=0?1:-1)}}return(a<-k||a<k&&u<-Ye)^l&1}function Vt(e,t,n,i){return function(r){var o=t(r),a=zt(),l=t(a),u=!1,d,s,c,h={point:f,lineStart:S,lineEnd:w,polygonStart:function(){h.point=g,h.lineStart=v,h.lineEnd=y,s=[],d=[]},polygonEnd:function(){h.point=f,h.lineStart=S,h.lineEnd=w,s=pt(s);var b=hn(d,i);s.length?(u||(r.polygonStart(),u=!0),Ut(s,mi,b,n,r)):b&&(u||(r.polygonStart(),u=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),u&&(r.polygonEnd(),u=!1),s=d=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function f(b,x){e(b,x)&&r.point(b,x)}function m(b,x){o.point(b,x)}function S(){h.point=m,o.lineStart()}function w(){h.point=f,o.lineEnd()}function g(b,x){c.push([b,x]),l.point(b,x)}function v(){l.lineStart(),c=[]}function y(){g(c[0][0],c[0][1]),l.lineEnd();var b=l.clean(),x=a.result(),E,C=x.length,P,R,L;if(c.pop(),d.push(c),c=null,!!C){if(b&1){if(R=x[0],(P=R.length-1)>0){for(u||(r.polygonStart(),u=!0),r.lineStart(),E=0;E<P;++E)r.point((L=R[E])[0],L[1]);r.lineEnd()}return}C>1&&b&2&&x.push(x.pop().concat(x.shift())),s.push(x.filter(fi))}}return h}}function fi(e){return e.length>1}function mi(e,t){return((e=e.x)[0]<0?e[1]-$-k:$-e[1])-((t=t.x)[0]<0?t[1]-$-k:$-t[1])}var ge=Vt(function(){return!0},gi,bi,[-_,-$]);function gi(e){var t=NaN,n=NaN,i=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(o,a){var l=o>0?_:-_,u=M(o-t);M(u-_)<k?(e.point(t,n=(n+a)/2>0?$:-$),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),e.point(o,n),r=0):i!==l&&u>=_&&(M(t-i)<k&&(t-=i*k),M(o-l)<k&&(o-=l*k),n=vi(t,n,o,a),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),r=0),e.point(t=o,n=a),i=l},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-r}}}function vi(e,t,n,i){var r,o,a=B(e-n);return M(a)>k?jt((B(t)*(o=T(i))*B(n)-B(i)*(r=T(t))*B(e))/(r*o*a)):(t+i)/2}function bi(e,t,n,i){var r;if(e==null)r=n*$,i.point(-_,r),i.point(0,r),i.point(_,r),i.point(_,0),i.point(_,-r),i.point(0,-r),i.point(-_,-r),i.point(-_,0),i.point(-_,r);else if(M(e[0]-t[0])>k){var o=e[0]<t[0]?_:-_;r=n*o/2,i.point(-o,r),i.point(0,r),i.point(o,r)}else i.point(t[0],t[1])}function pn(e){var t=T(e),n=2*F,i=t>0,r=M(t)>k;function o(s,c,h,f){dn(f,e,n,h,s,c)}function a(s,c){return T(s)*T(c)>t}function l(s){var c,h,f,m,S;return{lineStart:function(){m=f=!1,S=1},point:function(w,g){var v=[w,g],y,b=a(w,g),x=i?b?0:d(w,g):b?d(w+(w<0?_:-_),g):0;if(!c&&(m=f=b)&&s.lineStart(),b!==f&&(y=u(c,v),(!y||mt(c,y)||mt(v,y))&&(v[2]=1)),b!==f)S=0,b?(s.lineStart(),y=u(v,c),s.point(y[0],y[1])):(y=u(c,v),s.point(y[0],y[1],2),s.lineEnd()),c=y;else if(r&&c&&i^b){var E;!(x&h)&&(E=u(v,c,!0))&&(S=0,i?(s.lineStart(),s.point(E[0][0],E[0][1]),s.point(E[1][0],E[1][1]),s.lineEnd()):(s.point(E[1][0],E[1][1]),s.lineEnd(),s.lineStart(),s.point(E[0][0],E[0][1],3)))}b&&(!c||!mt(c,v))&&s.point(v[0],v[1]),c=v,f=b,h=x},lineEnd:function(){f&&s.lineEnd(),c=null},clean:function(){return S|(m&&f)<<1}}}function u(s,c,h){var f=Z(s),m=Z(c),S=[1,0,0],w=ft(f,m),g=Et(w,w),v=w[0],y=g-v*v;if(!y)return!h&&s;var b=t*g/y,x=-t*v/y,E=ft(S,w),C=Dt(S,b),P=Dt(w,x);qt(C,P);var R=E,L=Et(C,R),D=Et(R,R),U=L*L-D*(Et(C,C)-1);if(!(U<0)){var O=Y(U),A=Dt(R,(-L-O)/D);if(qt(A,C),A=St(A),!h)return A;var p=s[0],I=c[0],j=s[1],W=c[1],X;I<p&&(X=p,p=I,I=X);var wt=I-p,nt=M(wt-_)<k,lt=nt||wt<k;if(!nt&&W<j&&(X=j,j=W,W=X),lt?nt?j+W>0^A[1]<(M(A[0]-p)<k?j:W):j<=A[1]&&A[1]<=W:wt>_^(p<=A[0]&&A[0]<=I)){var it=Dt(R,(-L+O)/D);return qt(it,C),[A,St(it)]}}}function d(s,c){var h=i?e:_-e,f=0;return s<-h?f|=1:s>h&&(f|=2),c<-h?f|=4:c>h&&(f|=8),f}return Vt(a,l,o,i?[0,-e]:[-_,e-_])}function fn(e,t,n,i,r,o){var a=e[0],l=e[1],u=t[0],d=t[1],s=0,c=1,h=u-a,f=d-l,m;if(m=n-a,!(!h&&m>0)){if(m/=h,h<0){if(m<s)return;m<c&&(c=m)}else if(h>0){if(m>c)return;m>s&&(s=m)}if(m=r-a,!(!h&&m<0)){if(m/=h,h<0){if(m>c)return;m>s&&(s=m)}else if(h>0){if(m<s)return;m<c&&(c=m)}if(m=i-l,!(!f&&m>0)){if(m/=f,f<0){if(m<s)return;m<c&&(c=m)}else if(f>0){if(m>c)return;m>s&&(s=m)}if(m=o-l,!(!f&&m<0)){if(m/=f,f<0){if(m>c)return;m>s&&(s=m)}else if(f>0){if(m<s)return;m<c&&(c=m)}return s>0&&(e[0]=a+s*h,e[1]=l+s*f),c<1&&(t[0]=a+c*h,t[1]=l+c*f),!0}}}}}var kt=1e9,Wt=-kt;function ve(e,t,n,i){function r(d,s){return e<=d&&d<=n&&t<=s&&s<=i}function o(d,s,c,h){var f=0,m=0;if(d==null||(f=a(d,c))!==(m=a(s,c))||u(d,s)<0^c>0)do h.point(f===0||f===3?e:n,f>1?i:t);while((f=(f+c+4)%4)!==m);else h.point(s[0],s[1])}function a(d,s){return M(d[0]-e)<k?s>0?0:3:M(d[0]-n)<k?s>0?2:1:M(d[1]-t)<k?s>0?1:0:s>0?3:2}function l(d,s){return u(d.x,s.x)}function u(d,s){var c=a(d,1),h=a(s,1);return c!==h?c-h:c===0?s[1]-d[1]:c===1?d[0]-s[0]:c===2?d[1]-s[1]:s[0]-d[0]}return function(d){var s=d,c=zt(),h,f,m,S,w,g,v,y,b,x,E,C={point:P,lineStart:U,lineEnd:O,polygonStart:L,polygonEnd:D};function P(p,I){r(p,I)&&s.point(p,I)}function R(){for(var p=0,I=0,j=f.length;I<j;++I)for(var W=f[I],X=1,wt=W.length,nt=W[0],lt,it,Nt=nt[0],ht=nt[1];X<wt;++X)lt=Nt,it=ht,nt=W[X],Nt=nt[0],ht=nt[1],it<=i?ht>i&&(Nt-lt)*(i-it)>(ht-it)*(e-lt)&&++p:ht<=i&&(Nt-lt)*(i-it)<(ht-it)*(e-lt)&&--p;return p}function L(){s=c,h=[],f=[],E=!0}function D(){var p=R(),I=E&&p,j=(h=pt(h)).length;(I||j)&&(d.polygonStart(),I&&(d.lineStart(),o(null,null,1,d),d.lineEnd()),j&&Ut(h,l,p,o,d),d.polygonEnd()),s=d,h=f=m=null}function U(){C.point=A,f&&f.push(m=[]),x=!0,b=!1,v=y=NaN}function O(){h&&(A(S,w),g&&b&&c.rejoin(),h.push(c.result())),C.point=P,b&&s.lineEnd()}function A(p,I){var j=r(p,I);if(f&&m.push([p,I]),x)S=p,w=I,g=j,x=!1,j&&(s.lineStart(),s.point(p,I));else if(j&&b)s.point(p,I);else{var W=[v=Math.max(Wt,Math.min(kt,v)),y=Math.max(Wt,Math.min(kt,y))],X=[p=Math.max(Wt,Math.min(kt,p)),I=Math.max(Wt,Math.min(kt,I))];fn(W,X,e,t,n,i)?(b||(s.lineStart(),s.point(W[0],W[1])),s.point(X[0],X[1]),j||s.lineEnd(),E=!1):j&&(s.lineStart(),s.point(p,I),E=!1)}v=p,y=I,b=j}return C}}var Rt=e=>e;var be=new K,ye=new K,mn,gn,xe,we,st={point:z,lineStart:z,lineEnd:z,polygonStart:function(){st.lineStart=yi,st.lineEnd=wi},polygonEnd:function(){st.lineStart=st.lineEnd=st.point=z,be.add(M(ye)),ye=new K},result:function(){var e=be/2;return be=new K,e}};function yi(){st.point=xi}function xi(e,t){st.point=vn,mn=xe=e,gn=we=t}function vn(e,t){ye.add(we*e-xe*t),xe=e,we=t}function wi(){vn(mn,gn)}var Se=st;var gt=1/0,Kt=gt,Pt=-gt,Yt=Pt,Si={point:Ei,lineStart:z,lineEnd:z,polygonStart:z,polygonEnd:z,result:function(){var e=[[gt,Kt],[Pt,Yt]];return Pt=Yt=-(Kt=gt=1/0),e}};function Ei(e,t){e<gt&&(gt=e),e>Pt&&(Pt=e),t<Kt&&(Kt=t),t>Yt&&(Yt=t)}var vt=Si;var Ee=0,De=0,Ct=0,Xt=0,Jt=0,bt=0,_e=0,Ie=0,Mt=0,xn,wn,Q,tt,J={point:ct,lineStart:bn,lineEnd:yn,polygonStart:function(){J.lineStart=Ii,J.lineEnd=ki},polygonEnd:function(){J.point=ct,J.lineStart=bn,J.lineEnd=yn},result:function(){var e=Mt?[_e/Mt,Ie/Mt]:bt?[Xt/bt,Jt/bt]:Ct?[Ee/Ct,De/Ct]:[NaN,NaN];return Ee=De=Ct=Xt=Jt=bt=_e=Ie=Mt=0,e}};function ct(e,t){Ee+=e,De+=t,++Ct}function bn(){J.point=Di}function Di(e,t){J.point=_i,ct(Q=e,tt=t)}function _i(e,t){var n=e-Q,i=t-tt,r=Y(n*n+i*i);Xt+=r*(Q+e)/2,Jt+=r*(tt+t)/2,bt+=r,ct(Q=e,tt=t)}function yn(){J.point=ct}function Ii(){J.point=Ri}function ki(){Sn(xn,wn)}function Ri(e,t){J.point=Sn,ct(xn=Q=e,wn=tt=t)}function Sn(e,t){var n=e-Q,i=t-tt,r=Y(n*n+i*i);Xt+=r*(Q+e)/2,Jt+=r*(tt+t)/2,bt+=r,r=tt*e-Q*t,_e+=r*(Q+e),Ie+=r*(tt+t),Mt+=r*3,ct(Q=e,tt=t)}var ke=J;function Zt(e){this._context=e}Zt.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,q);break}}},result:z};var Pe=new K,Re,En,Dn,Lt,At,Qt={point:z,lineStart:function(){Qt.point=Pi},lineEnd:function(){Re&&_n(En,Dn),Qt.point=z},polygonStart:function(){Re=!0},polygonEnd:function(){Re=null},result:function(){var e=+Pe;return Pe=new K,e}};function Pi(e,t){Qt.point=_n,En=Lt=e,Dn=At=t}function _n(e,t){Lt-=e,At-=t,Pe.add(Y(Lt*Lt+At*At)),Lt=e,At=t}var Ce=Qt;var In,te,kn,Rn,yt=class{constructor(t){this._append=t==null?Pn:Ci(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==kn||this._append!==te){let i=this._radius,r=this._;this._="",this._append`m0,${i}a${i},${i} 0 1,1 0,${-2*i}a${i},${i} 0 1,1 0,${2*i}z`,kn=i,te=this._append,Rn=this._,this._=r}this._+=Rn;break}}}result(){let t=this._;return this._="",t.length?t:null}};function Pn(e){let t=1;this._+=e[0];for(let n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function Ci(e){let t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return Pn;if(t!==In){let n=10**t;In=t,te=function(r){let o=1;this._+=r[0];for(let a=r.length;o<a;++o)this._+=Math.round(arguments[o]*n)/n+r[o]}}return te}function ee(e,t){let n=3,i=4.5,r,o;function a(l){return l&&(typeof i=="function"&&o.pointRadius(+i.apply(this,arguments)),at(l,r(o))),o.result()}return a.area=function(l){return at(l,r(Se)),Se.result()},a.measure=function(l){return at(l,r(Ce)),Ce.result()},a.bounds=function(l){return at(l,r(vt)),vt.result()},a.centroid=function(l){return at(l,r(ke)),ke.result()},a.projection=function(l){return arguments.length?(r=l==null?(e=null,Rt):(e=l).stream,a):e},a.context=function(l){return arguments.length?(o=l==null?(t=null,new yt(n)):new Zt(t=l),typeof i!="function"&&o.pointRadius(i),a):t},a.pointRadius=function(l){return arguments.length?(i=typeof l=="function"?l:(o.pointRadius(+l),+l),a):i},a.digits=function(l){if(!arguments.length)return n;if(l==null)n=null;else{let u=Math.floor(l);if(!(u>=0))throw new RangeError(`invalid digits: ${l}`);n=u}return t===null&&(o=new yt(n)),a},a.projection(e).digits(n).context(t)}function Tt(e){return function(t){var n=new Me;for(var i in e)n[i]=e[i];return n.stream=t,n}}function Me(){}Me.prototype={constructor:Me,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function Le(e,t,n){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),at(n,e.stream(vt)),t(vt.result()),i!=null&&e.clipExtent(i),e}function Ae(e,t,n){return Le(e,function(i){var r=t[1][0]-t[0][0],o=t[1][1]-t[0][1],a=Math.min(r/(i[1][0]-i[0][0]),o/(i[1][1]-i[0][1])),l=+t[0][0]+(r-a*(i[1][0]+i[0][0]))/2,u=+t[0][1]+(o-a*(i[1][1]+i[0][1]))/2;e.scale(150*a).translate([l,u])},n)}function Cn(e,t,n){return Ae(e,[[0,0],t],n)}function Mn(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][0]-i[0][0]),a=(r-o*(i[1][0]+i[0][0]))/2,l=-o*i[0][1];e.scale(150*o).translate([a,l])},n)}function Ln(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][1]-i[0][1]),a=-o*i[0][0],l=(r-o*(i[1][1]+i[0][1]))/2;e.scale(150*o).translate([a,l])},n)}var An=16,Mi=T(30*F);function Te(e,t){return+t?Ai(e,t):Li(e)}function Li(e){return Tt({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function Ai(e,t){function n(i,r,o,a,l,u,d,s,c,h,f,m,S,w){var g=d-i,v=s-r,y=g*g+v*v;if(y>4*t&&S--){var b=a+h,x=l+f,E=u+m,C=Y(b*b+x*x+E*E),P=ot(E/=C),R=M(M(E)-1)<k||M(o-c)<k?(o+c)/2:rt(x,b),L=e(R,P),D=L[0],U=L[1],O=D-i,A=U-r,p=v*O-g*A;(p*p/y>t||M((g*O+v*A)/y-.5)>.3||a*h+l*f+u*m<Mi)&&(n(i,r,o,a,l,u,D,U,R,b/=C,x/=C,E,S,w),w.point(D,U),n(D,U,R,b,x,E,d,s,c,h,f,m,S,w))}}return function(i){var r,o,a,l,u,d,s,c,h,f,m,S,w={point:g,lineStart:v,lineEnd:b,polygonStart:function(){i.polygonStart(),w.lineStart=x},polygonEnd:function(){i.polygonEnd(),w.lineStart=v}};function g(P,R){P=e(P,R),i.point(P[0],P[1])}function v(){c=NaN,w.point=y,i.lineStart()}function y(P,R){var L=Z([P,R]),D=e(P,R);n(c,h,s,f,m,S,c=D[0],h=D[1],s=P,f=L[0],m=L[1],S=L[2],An,i),i.point(c,h)}function b(){w.point=g,i.lineEnd()}function x(){v(),w.point=E,w.lineEnd=C}function E(P,R){y(r=P,R),o=c,a=h,l=f,u=m,d=S,w.point=y}function C(){n(c,h,s,f,m,S,o,a,r,l,u,d,An,i),w.lineEnd=b,b()}return w}}var Ti=Tt({point:function(e,t){this.stream.point(e*F,t*F)}});function Bi(e){return Tt({point:function(t,n){var i=e(t,n);return this.stream.point(i[0],i[1])}})}function Fi(e,t,n,i,r){function o(a,l){return a*=i,l*=r,[t+e*a,n-e*l]}return o.invert=function(a,l){return[(a-t)/e*i,(n-l)/e*r]},o}function Tn(e,t,n,i,r,o){if(!o)return Fi(e,t,n,i,r);var a=T(o),l=B(o),u=a*e,d=l*e,s=a/e,c=l/e,h=(l*n-a*t)/e,f=(l*t+a*n)/e;function m(S,w){return S*=i,w*=r,[u*S-d*w+t,n-d*S-u*w]}return m.invert=function(S,w){return[i*(s*S-c*w+h),r*(f-c*S-s*w)]},m}function Be(e){return Oi(function(){return e})()}function Oi(e){var t,n=150,i=480,r=250,o=0,a=0,l=0,u=0,d=0,s,c=0,h=1,f=1,m=null,S=ge,w=null,g,v,y,b=Rt,x=.5,E,C,P,R,L;function D(p){return P(p[0]*F,p[1]*F)}function U(p){return p=P.invert(p[0],p[1]),p&&[p[0]*V,p[1]*V]}D.stream=function(p){return R&&L===p?R:R=Ti(Bi(s)(S(E(b(L=p)))))},D.preclip=function(p){return arguments.length?(S=p,m=void 0,A()):S},D.postclip=function(p){return arguments.length?(b=p,w=g=v=y=null,A()):b},D.clipAngle=function(p){return arguments.length?(S=+p?pn(m=p*F):(m=null,ge),A()):m*V},D.clipExtent=function(p){return arguments.length?(b=p==null?(w=g=v=y=null,Rt):ve(w=+p[0][0],g=+p[0][1],v=+p[1][0],y=+p[1][1]),A()):w==null?null:[[w,g],[v,y]]},D.scale=function(p){return arguments.length?(n=+p,O()):n},D.translate=function(p){return arguments.length?(i=+p[0],r=+p[1],O()):[i,r]},D.center=function(p){return arguments.length?(o=p[0]%360*F,a=p[1]%360*F,O()):[o*V,a*V]},D.rotate=function(p){return arguments.length?(l=p[0]%360*F,u=p[1]%360*F,d=p.length>2?p[2]%360*F:0,O()):[l*V,u*V,d*V]},D.angle=function(p){return arguments.length?(c=p%360*F,O()):c*V},D.reflectX=function(p){return arguments.length?(h=p?-1:1,O()):h<0},D.reflectY=function(p){return arguments.length?(f=p?-1:1,O()):f<0},D.precision=function(p){return arguments.length?(E=Te(C,x=p*p),A()):Y(x)},D.fitExtent=function(p,I){return Ae(D,p,I)},D.fitSize=function(p,I){return Cn(D,p,I)},D.fitWidth=function(p,I){return Mn(D,p,I)},D.fitHeight=function(p,I){return Ln(D,p,I)};function O(){var p=Tn(n,0,0,h,f,c).apply(null,t(o,a)),I=Tn(n,i-p[0],r-p[1],h,f,c);return s=fe(l,u,d),C=It(t,I),P=It(s,C),E=Te(C,x),A()}function A(){return R=L=null,D}return function(){return t=e.apply(this,arguments),D.invert=t.invert&&U,O()}}function ne(e,t){return[e,Je(Qe(($+t)/2))]}ne.invert=function(e,t){return[e,2*jt(Xe(t))-$]};function Fe(){return Gi(ne).scale(961/q)}function Gi(e){var t=Be(e),n=t.center,i=t.scale,r=t.translate,o=t.clipExtent,a=null,l,u,d;t.scale=function(c){return arguments.length?(i(c),s()):i()},t.translate=function(c){return arguments.length?(r(c),s()):r()},t.center=function(c){return arguments.length?(n(c),s()):n()},t.clipExtent=function(c){return arguments.length?(c==null?a=l=u=d=null:(a=+c[0][0],l=+c[0][1],u=+c[1][0],d=+c[1][1]),s()):a==null?null:[[a,l],[u,d]]};function s(){var c=_*i(),h=t(ln(t.rotate()).invert([0,0]));return o(a==null?[[h[0]-c,h[1]-c],[h[0]+c,h[1]+c]]:e===ne?[[Math.max(h[0]-c,a),l],[Math.min(h[0]+c,u),d]]:[[a,Math.max(h[1]-c,l)],[u,Math.min(h[1]+c,d)]])}return s()}function Oe(e){return e}function ie(e){if(e==null)return Oe;var t,n,i=e.scale[0],r=e.scale[1],o=e.translate[0],a=e.translate[1];return function(l,u){u||(t=n=0);var d=2,s=l.length,c=new Array(s);for(c[0]=(t+=l[0])*i+o,c[1]=(n+=l[1])*r+a;d<s;)c[d]=l[d],++d;return c}}function Bn(e,t){for(var n,i=e.length,r=i-t;r<--i;)n=e[r],e[r++]=e[i],e[i]=n}function Ge(e,t){return typeof t=="string"&&(t=e.objects[t]),t.type==="GeometryCollection"?{type:"FeatureCollection",features:t.geometries.map(function(n){return Fn(e,n)})}:Fn(e,t)}function Fn(e,t){var n=t.id,i=t.bbox,r=t.properties==null?{}:t.properties,o=Ne(e,t);return n==null&&i==null?{type:"Feature",properties:r,geometry:o}:i==null?{type:"Feature",id:n,properties:r,geometry:o}:{type:"Feature",id:n,bbox:i,properties:r,geometry:o}}function Ne(e,t){var n=ie(e.transform),i=e.arcs;function r(s,c){c.length&&c.pop();for(var h=i[s<0?~s:s],f=0,m=h.length;f<m;++f)c.push(n(h[f],f));s<0&&Bn(c,m)}function o(s){return n(s)}function a(s){for(var c=[],h=0,f=s.length;h<f;++h)r(s[h],c);return c.length<2&&c.push(c[0]),c}function l(s){for(var c=a(s);c.length<4;)c.push(c[0]);return c}function u(s){return s.map(l)}function d(s){var c=s.type,h;switch(c){case"GeometryCollection":return{type:c,geometries:s.geometries.map(d)};case"Point":h=o(s.coordinates);break;case"MultiPoint":h=s.coordinates.map(o);break;case"LineString":h=a(s.arcs);break;case"MultiLineString":h=s.arcs.map(a);break;case"Polygon":h=u(s.arcs);break;case"MultiPolygon":h=s.arcs.map(u);break;default:return null}return{type:c,coordinates:h}}return d(t)}function et(e){if("type"in e&&e.type==="FeatureCollection")return e;let t=e,n=typeof t.object=="string"?t.topology.objects[t.object]:t.object;if(!n)throw new Error("The named TopoJSON object does not exist in this topology.");let i=Ge(t.topology,n);return i.type==="FeatureCollection"?i:{type:"FeatureCollection",features:[i]}}function On(e){return e.reduce((t,n)=>t+(n??0),0)}function re(e,t,n,i){if(e===null||i<=0)return null;if(i===1||n===t)return i-1;let r=Math.round((e-t)/(n-t)*(i-1));return Math.min(Math.max(r,0),i-1)}function Gn(e,t,n,i){let r=e.length;return e.map((o,a)=>{let l=t.filter(u=>re(u,n,i,r)===a);return{index:a,color:o,from:l.length?Math.min(...l):null,to:l.length?Math.max(...l):null,matches:l.length}})}function Nn(e,t){if(e.matches===0||e.from===null||e.to===null)return"No regions in this band";let n=e.from===e.to?t(e.from):`${t(e.from)} to ${t(e.to)}`;return`Highlight ${e.matches} ${e.matches===1?"region":"regions"}, ${n}`}function jn(e,t,n,i=4){let r=0;e.right>t.right-i&&(r=t.right-i-e.right),e.left+r<t.left+i&&(r=t.left+i-e.left);let o=e.top<t.top+i?"below":"above";return{dx:r,side:o}}var qi=["puducherry"];function zn(e){let t=e.toLowerCase();return qi.some(n=>t.includes(n))}function oe(e){let t=1/0,n=1/0,i=-1/0,r=-1/0;for(let[o,a]of e)o<t&&(t=o),o>i&&(i=o),a<n&&(n=a),a>r&&(r=a);return[t,n,i,r]}function ae(e){let t=0;for(let n of e){if(n.length===0)continue;let[i,r,o,a]=oe(n),l=Math.max(o-i,a-r);l>t&&(t=l)}return t}function $n(e){let t=0;for(let n=0;n<e.length;n++){let[i,r]=e[n],[o,a]=e[(n+1)%e.length];t+=i*a-o*r}return t/2}function Hn(e,t){let n=null,i=0;for(let u of e){if(u.length<3)continue;let d=Math.abs($n(u));d>i&&(i=d,n=u)}if(!n||i===0)return t;let r=$n(n),o=0,a=0;for(let u=0;u<n.length;u++){let[d,s]=n[u],[c,h]=n[(u+1)%n.length],f=d*h-c*s;o+=(d+c)*f,a+=(s+h)*f}let l=[o/(6*r),a/(6*r)];return Number.isFinite(l[0])&&Number.isFinite(l[1])?l:t}function zi(e,t){let[n,i]=e,[r,o,a,l]=t,u=Math.max(r-n,0)+Math.max(n-a,0),d=Math.max(o-i,0)+Math.max(i-l,0);return Math.hypot(u,d)}function Un(e,t){let n=1/0;for(let i of t){let r=zi(e,i);r<n&&(n=r)}return n}var Hi=[0,Math.PI/6,-Math.PI/6,Math.PI/3,-Math.PI/3,Math.PI/2,-Math.PI/2,2*Math.PI/3,-(2*Math.PI)/3,5*Math.PI/6,-(5*Math.PI)/6,Math.PI];function Vn(e){let{anchor:t,clearance:n,halfSize:i,viewBox:r,centre:o,isBlocked:a}=e,l=t[0]-o[0],u=t[1]-o[1],d=l===0&&u===0?0:Math.atan2(u,l);for(let s of Hi){let c=d+s,h=[qn(t[0]+Math.cos(c)*n,i[0],r[0]-i[0]),qn(t[1]+Math.sin(c)*n,i[1],r[1]-i[1])];if(!a(h))return h}return null}function qn(e,t,n){return Math.min(Math.max(e,t),n)}function Wn(e,t,n=8){let i=()=>e.map(o=>[...o]);if(t<=0)return i();let r=ae(e);return r<=0||r>=t?i():e.map(o=>{let[a,l,u,d]=oe(o),s=Math.max(u-a,d-l),c=s<=0?1:Math.min(t/s,n),h=(a+u)/2,f=(l+d)/2;return o.map(([m,S])=>[h+(m-h)*c,f+(S-f)*c])})}function Ui(e){let t=[...e].sort((u,d)=>u[0]-d[0]||u[1]-d[1]),n=[];for(let u of t){let d=n.at(-1);(!d||d[0]!==u[0]||d[1]!==u[1])&&n.push(u)}if(n.length<3)return n.map(u=>[...u]);let i=(u,d,s)=>(d[0]-u[0])*(s[1]-u[1])-(d[1]-u[1])*(s[0]-u[0]),r=u=>{let d=[];for(let s of u){for(;d.length>=2&&i(d[d.length-2],d[d.length-1],s)<=0;)d.pop();d.push(s)}return d},o=r(n),a=r([...n].reverse()),l=[...o.slice(0,-1),...a.slice(0,-1)];return l.length>=3?l:n.map(u=>[...u])}function Kn(e,t){if(e.length<2||t<=0)return null;let n=ae(e);if(n<=0||n>=t)return null;let i=Ui(e.flat());return i.length>=3?i:null}function je(e){let t="";for(let n of e)if(n.length!==0){t+=`M${n[0][0]},${n[0][1]}`;for(let i=1;i<n.length;i++)t+=`L${n[i][0]},${n[i][1]}`;t+="Z"}return t}var Vi="http://www.w3.org/2000/svg",H={width:960,height:640,padding:28},Bt=["#d9f1ed","#b9e3dd","#8fd1c8","#5bb9ae","#2f9c90","#147b71","#075b55"],se=new Intl.NumberFormat("en-IN").format,Yn=12,ze=22,Wi=14,le=7;function Xn(e,t){let n=e.geometry;if(!n)return[];let i=n.type==="Polygon"?[n.coordinates]:n.type==="MultiPolygon"?n.coordinates:[],r=[];for(let o of i)for(let a of o){let l=[];for(let u of a){let d=t(u);d&&Number.isFinite(d[0])&&Number.isFinite(d[1])&&l.push([d[0],d[1]])}l.length>0&&r.push(l)}return r}var Ki=0;function Jn(e,t,n,i,r){if(typeof r=="function"){let a={min:n,max:i,feature:t.feature,id:t.id};return r(e,a)}let o=re(e,n,i,r.length);return o===null?"var(--india-map-empty)":r[o]??"var(--india-map-empty)"}function Zn(e){return typeof e.colorScale=="function"?Bt:e.colorScale??Bt}function $e(e){return Fe().fitExtent([[H.padding,H.padding],[H.width-H.padding,H.height-H.padding]],e)}function qe(e,t,n=0){let i=et(e.geometry),r=ee(t);return i.features.map(o=>{let a=r.centroid(o),l=r.bounds(o),u=[(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2],d={id:e.getId(o),label:e.getLabel(o),value:e.getValue(o),meta:e.getMeta?.(o),feature:o},s=n>0&&!zn(d.id),c=s?Wn(Xn(o,t),n):Xn(o,t),h=Kn(c,ze);return{...d,path:s?je(c):r(o)??"",hitPath:h?je([h]):null,centroid:c.length>0?Hn(c,a.every(Number.isFinite)?a:u):a.every(Number.isFinite)?a:u,partBounds:c.map(oe),extent:ae(c)}})}function Qn(e,t){let n=ee(t);return et(e.geometry).features.map(i=>({id:e.getId(i),label:e.getLabel(i),description:e.getDescription(i),path:n(i)??""}))}function Yi(e){let t=e%100;return t>=11&&t<=13?`${e}th`:`${e}${["th","st","nd","rd"][e%10]??"th"}`}function Xi(e,t){let n=document.createDocumentFragment(),i=document.createElement("strong");i.textContent=e.label;let r=document.createElement("b");if(r.textContent=e.value===null?"No data":t(e.value),n.append(i,r),e.share!==null){let o=document.createElement("span");o.className="india-choropleth__tooltip-bar",o.setAttribute("aria-hidden","true");let a=document.createElement("span");a.style.width=`${Math.max(e.share,1.5)}%`,o.append(a);let l=document.createElement("small"),u=[`${e.share.toFixed(1)}% of total`];e.rank!==null&&u.push(`${Yi(e.rank)} of ${e.rankedCount}`),l.textContent=u.join(" \xB7 "),n.append(o,l)}return n}function G(e,t){let n=document.createElement(e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function N(e,t){let n=document.createElementNS(Vi,e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function Ji(e,t){typeof t=="string"?e.textContent=t:e.appendChild(t)}var dt=class{containerEl;options;instanceId=`india-choropleth-${++Ki}`;tooltipId=`${this.instanceId}-tooltip`;hatchId=`${this.instanceId}-hatch`;activeDrillDownId;activeSubDrillDownId;activeSelectedId;inspectedId=null;loadedDistricts=null;loadedSubDistricts=null;leafDistrictIds=new Set;loadedDistrictReferenceOverlay=null;loadingState=null;loadingDistrict=null;loadError=null;subLoadError=null;districtGeneration=0;subDistrictGeneration=0;overlayGeneration=0;restoreFocusId=null;destroyed=!1;attemptedDistrictLoadForId=null;attemptedSubDistrictLoadForId=null;attemptedOverlayLoadForId=null;pathRefs=new Map;derived;rootEl;toolbarEl;canvasEl;legendEl=null;swatchEls=[];bucketEls=[];activeBucket=null;bandsKey=null;insightsEl=null;tooltipAnchorEl=null;tooltipContentEl=null;svgRootEl=null;selectionGroupEl=null;selectionPathEls=[];constructor(t,n){let i=typeof t=="string"?document.querySelector(t):t;if(!i)throw new Error(`IndiaChoropleth: container ${typeof t=="string"?`"${t}"`:""} was not found.`);this.containerEl=i,this.options=n,this.activeDrillDownId=n.drillDownId!==void 0?n.drillDownId:n.defaultDrillDownId??null,this.activeSubDrillDownId=n.subDistrictDrillDownId!==void 0?n.subDistrictDrillDownId:n.defaultSubDistrictDrillDownId??null,this.activeSelectedId=n.selectedId!==void 0?n.selectedId:n.defaultSelectedId??null,this.buildShell(),this.renderStructure()}update(t){"loadDistricts"in t&&t.loadDistricts!==this.options.loadDistricts&&(this.attemptedDistrictLoadForId=null),"loadSubDistricts"in t&&t.loadSubDistricts!==this.options.loadSubDistricts&&(this.attemptedSubDistrictLoadForId=null,this.leafDistrictIds.clear()),"loadDistrictReferenceOverlay"in t&&t.loadDistrictReferenceOverlay!==this.options.loadDistrictReferenceOverlay&&(this.attemptedOverlayLoadForId=null),this.options={...this.options,...t},"drillDownId"in t&&t.drillDownId!==void 0&&(t.drillDownId!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.activeDrillDownId=t.drillDownId),"subDistrictDrillDownId"in t&&t.subDistrictDrillDownId!==void 0&&(this.activeSubDrillDownId=t.subDistrictDrillDownId),"selectedId"in t&&t.selectedId!==void 0&&(this.activeSelectedId=t.selectedId),this.renderStructure()}select(t){let n=this.derived.regions.find(i=>i.id===t)??null;this.setActiveSelectedId(n?.id??null),n&&this.options.onSelectedChange?.(n,this.derived.level),this.applyInteractionState()}drillDown(t){if(t===null){this.goToStates();return}let n=this.derived.stateRegions.find(i=>i.id===t);n&&(t!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(t),this.options.onDrillDownChange?.(t,n),this.renderStructure())}drillDownSubDistrict(t){if(t===null){this.derived.level==="subdistrict"&&this.goBack();return}let n=this.derived.districtRegions.find(i=>i.id===t);n&&(this.setActiveSubDrillDownId(t),this.options.onSubDistrictDrillDownChange?.(t,n),this.renderStructure())}getSelected(){return this.derived.selected}getInspected(){return this.derived.inspected}destroy(){this.destroyed=!0,this.districtGeneration+=1,this.subDistrictGeneration+=1,this.overlayGeneration+=1,this.pathRefs.clear(),this.containerEl.textContent=""}setActiveDrillDownId(t){this.options.drillDownId===void 0&&(this.activeDrillDownId=t)}setActiveSubDrillDownId(t){this.options.subDistrictDrillDownId===void 0&&(this.activeSubDrillDownId=t)}setActiveSelectedId(t){this.options.selectedId===void 0&&(this.activeSelectedId=t)}buildShell(){this.rootEl=G("section"),this.toolbarEl=G("div",{class:"india-choropleth__toolbar"}),this.canvasEl=G("div",{class:"india-choropleth__canvas"}),this.canvasEl.addEventListener("mouseleave",()=>{this.options.interactive!==!1&&this.inspect(null)}),this.rootEl.append(this.toolbarEl,this.canvasEl),this.containerEl.textContent="",this.containerEl.appendChild(this.rootEl)}recompute(){let t=this.options,n=et(t.states.geometry),i=t.referenceOverlay?et(t.referenceOverlay.geometry):null,r=$e({type:"FeatureCollection",features:[...n.features,...i?.features??[]]}),o=qe(t.states,r,t.minPartExtent??0),a=t.referenceOverlay?Qn(t.referenceOverlay,r):[],l=o.find(p=>p.id===this.activeDrillDownId)??null,u=!!(l&&this.activeDrillDownId),d=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,s=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,c=d?et(d.geometry):null,h=s?et(s.geometry):null,f=c?$e({type:"FeatureCollection",features:[...c.features,...h?.features??[]]}):null,m=d&&f?qe(d,f,t.minDistrictPartExtent??t.minPartExtent??0):[],S=m.find(p=>p.id===this.activeSubDrillDownId)??null,g=!!(u&&S&&this.activeSubDrillDownId)?"subdistrict":u?"district":"state",v=this.loadedSubDistricts?.districtId===this.activeSubDrillDownId?this.loadedSubDistricts.layer:null,y=v?et(v.geometry):null,b=y?$e(y):null,x=v&&b?qe(v,b,t.minDistrictPartExtent??t.minPartExtent??0):[],E=g==="subdistrict"?x:g==="district"?m:o,C=g==="district"&&s&&f?Qn(s,f):[],P=E.find(p=>p.id===this.activeSelectedId)??null,R=E.find(p=>p.id===this.inspectedId)??null;this.inspectedId&&!R&&(this.inspectedId=null);let L=E.map(p=>p.value).filter(p=>p!==null),D=On(L),U=L.length?Math.min(...L):0,O=L.length?Math.max(...L):0;this.derived={stateRegions:o,referenceRegions:a,drilledState:l,drilledDistrict:S,districtRegions:m,level:g,regions:E,visibleReferenceRegions:g==="state"?a:C,selected:P,inspected:R,total:D,min:U,max:O,canDrill:g==="state"?!!t.loadDistricts:g==="district"?!!t.loadSubDistricts:!1,mergedReferenceIds:new Set(t.referenceOverlayMergeIds??[]),buckets:Gn(Zn(t),E.map(p=>p.value),U,O)};let A=[g,this.activeDrillDownId??"",this.activeSubDrillDownId??"",typeof t.colorScale=="function"?"function":(t.colorScale??Bt).join(",")].join("|");A!==this.bandsKey&&(this.bandsKey=A,this.activeBucket=null),this.activeBucket!==null&&this.activeBucket>=this.derived.buckets.length&&(this.activeBucket=null)}loadDistrictsFor(t){let n=this.options;if(!n.loadDistricts){this.loadedDistricts=null,this.loadingState=null,this.loadError=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.districtGeneration;this.loadingState=t,this.loadError=null,this.loadedDistricts=null,n.loadDistricts(t,i).then(o=>{this.destroyed||r!==this.districtGeneration||(this.loadedDistricts={stateId:t,layer:o},this.loadingState=null,this.renderStructure())}).catch(o=>{this.destroyed||r!==this.districtGeneration||(this.loadError=o instanceof Error?o:new Error("Unable to load districts."),this.loadingState=null,this.renderStructure())})}loadSubDistrictsFor(t){let n=this.options;if(!n.loadSubDistricts){this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null;return}let i=this.derived.districtRegions.find(o=>o.id===t);if(!i||!this.activeDrillDownId)return;let r=++this.subDistrictGeneration;this.loadingDistrict=t,this.subLoadError=null,this.loadedSubDistricts=null,n.loadSubDistricts(t,i,this.activeDrillDownId).then(o=>{if(!(this.destroyed||r!==this.subDistrictGeneration)){if(this.loadingDistrict=null,!o){this.leafDistrictIds.add(t),this.setActiveSubDrillDownId(null),this.setActiveSelectedId(i.id),n.onSubDistrictDrillDownChange?.(null,i),this.renderStructure();return}this.loadedSubDistricts={districtId:t,layer:o},this.renderStructure()}}).catch(o=>{this.destroyed||r!==this.subDistrictGeneration||(this.subLoadError=o instanceof Error?o:new Error("Unable to load sub-districts."),this.loadingDistrict=null,this.renderStructure())})}loadDistrictReferenceOverlayFor(t){let n=this.options;if(!n.loadDistrictReferenceOverlay){this.loadedDistrictReferenceOverlay=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.overlayGeneration;this.loadedDistrictReferenceOverlay=null,n.loadDistrictReferenceOverlay(t,i).then(o=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:o},this.renderStructure())}).catch(()=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:null},this.renderStructure())})}inspect(t){let n=t?.id??null;n===null&&this.inspectedId===null||(this.inspectedId=n,this.derived.inspected=t,this.options.onInspect?.(t??null,this.derived.level),this.applyInteractionState())}toViewBox(t){let n=this.canvasEl.querySelector("svg");if(!n)return null;let i=n.getBoundingClientRect();if(i.width===0||i.height===0)return null;let r=Math.min(i.width/H.width,i.height/H.height),o=(i.width-H.width*r)/2,a=(i.height-H.height*r)/2;return[(t.clientX-i.left-o)/r,(t.clientY-i.top-a)/r]}smallRegionNear(t){let n=null,i=1/0;for(let r of this.derived.regions){if(r.extent<=0||r.extent>=ze)continue;let o=Un(t,r.partBounds);o<=Wi&&o<i&&(i=o,n=r)}return n}activate(t){let n=this.options;if(n.onRegionClick?.(t,this.derived.level),this.setActiveSelectedId(t.id),n.onSelectedChange?.(t,this.derived.level),this.derived.level==="state"&&n.loadDistricts){this.setActiveSelectedId(null),this.setActiveDrillDownId(t.id),n.onDrillDownChange?.(t.id,t),this.renderStructure();return}if(this.derived.level==="district"&&n.loadSubDistricts&&!this.leafDistrictIds.has(t.id)){this.setActiveSelectedId(null),this.setActiveSubDrillDownId(t.id),n.onSubDistrictDrillDownChange?.(t.id,t),this.renderStructure();return}this.applyInteractionState()}goBack(){if(this.derived.level==="subdistrict"){let t=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,this.options.onSubDistrictDrillDownChange?.(null,t),this.renderStructure();return}this.goToStates()}goToStates(){let t=this.derived.drilledState??void 0,n=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,n&&this.options.onSubDistrictDrillDownChange?.(null,n),this.options.onDrillDownChange?.(null,t),this.renderStructure()}renderStructure(){if(this.destroyed)return;this.recompute();let t=this.options;this.activeDrillDownId&&t.loadDistricts&&this.attemptedDistrictLoadForId!==this.activeDrillDownId&&(this.attemptedDistrictLoadForId=this.activeDrillDownId,this.loadDistrictsFor(this.activeDrillDownId)),this.activeDrillDownId||(this.loadedDistricts=null,this.loadingState=null,this.loadError=null,this.attemptedDistrictLoadForId=null),this.activeDrillDownId&&t.loadDistrictReferenceOverlay&&this.attemptedOverlayLoadForId!==this.activeDrillDownId&&(this.attemptedOverlayLoadForId=this.activeDrillDownId,this.loadDistrictReferenceOverlayFor(this.activeDrillDownId)),(!this.activeDrillDownId||!t.loadDistrictReferenceOverlay)&&(this.loadedDistrictReferenceOverlay=null,this.attemptedOverlayLoadForId=null),this.activeSubDrillDownId&&t.loadSubDistricts&&this.attemptedSubDistrictLoadForId!==this.activeSubDrillDownId&&this.derived.districtRegions.some(i=>i.id===this.activeSubDrillDownId)&&(this.attemptedSubDistrictLoadForId=this.activeSubDrillDownId,this.loadSubDistrictsFor(this.activeSubDrillDownId)),this.activeSubDrillDownId||(this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null,this.attemptedSubDistrictLoadForId=null);let n=t.interactive!==!1;if(this.rootEl.className=["india-choropleth",!n&&"india-choropleth--static",t.className].filter(Boolean).join(" "),this.loadingState||this.loadingDistrict?this.rootEl.setAttribute("aria-busy","true"):this.rootEl.removeAttribute("aria-busy"),this.renderToolbar(),this.renderCanvas(),this.renderLegend(),this.restoreFocusId&&this.derived.regions.some(i=>i.id===this.restoreFocusId)){let i=this.restoreFocusId;this.restoreFocusId=null,this.pathRefs.get(i)?.focus()}}renderToolbar(){let t=this.options;if(this.toolbarEl.textContent="",t.showBreadcrumb===!1)return;let n=G("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"}),i=()=>{let a=G("span",{"aria-hidden":"true"});return a.textContent="/",a};if(!this.derived.drilledState){let a=G("span");a.textContent="All states",n.append(a),this.toolbarEl.append(n);return}let r=G("button",{class:"india-choropleth__back",type:"button"});if(r.textContent="All states",r.addEventListener("click",()=>this.goToStates()),n.append(r,i()),this.derived.level==="subdistrict"&&this.derived.drilledDistrict){let a=G("button",{class:"india-choropleth__back",type:"button"});a.textContent=this.derived.drilledState.label,a.addEventListener("click",()=>this.goBack());let l=G("span",{"aria-current":"page"});l.textContent=this.derived.drilledDistrict.label,n.append(a,i(),l)}else{let a=G("span",{"aria-current":"page"});a.textContent=this.derived.drilledState.label,n.append(a)}this.toolbarEl.append(n)}renderCanvas(){let t=this.options,n=t.interactive!==!1;this.canvasEl.textContent="",this.pathRefs.clear(),this.bucketEls=[],this.svgRootEl=null,this.tooltipAnchorEl=null,this.tooltipContentEl=null,this.selectionGroupEl=null,this.selectionPathEls=[];let i=!!(this.derived.drilledState&&this.activeDrillDownId),r=this.derived.level==="subdistrict",o=r&&(!this.loadedSubDistricts||this.loadedSubDistricts.districtId!==this.activeSubDrillDownId||this.subLoadError),a=!o&&i&&(!this.loadedDistricts||this.loadedDistricts.stateId!==this.activeDrillDownId||this.loadError),l=!o&&!a&&this.derived.regions.length===0;if(o||a||l){let g=o&&this.subLoadError||a&&this.loadError,v=G("div",{class:"india-choropleth__status",role:g?"alert":"status"});v.textContent=o?this.subLoadError?this.subLoadError.message:this.loadingDistrict?"Loading sub-districts\u2026":"Sub-district data is unavailable for this district.":l?r?"No sub-district data is available for this district.":"No district data is available for this state.":this.loadError?this.loadError.message:this.loadingState?"Loading districts\u2026":"District data is unavailable for this state.",this.canvasEl.append(v),this.applyInteractionState();return}let u=N("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${H.width} ${H.height}`,role:"group","aria-label":t.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=u,n&&(u.addEventListener("keydown",g=>{g.key==="Escape"&&(g.preventDefault(),this.inspect(null))}),u.addEventListener("click",g=>{if(g.target!==u)return;let v=this.toViewBox(g),y=v?this.smallRegionNear(v):null;if(y){this.activate(y);return}this.options.onBackgroundClick?.(),this.activeSelectedId!==null&&(this.setActiveSelectedId(null),this.options.onSelectedChange?.(null,this.derived.level),this.applyInteractionState())})),this.derived.visibleReferenceRegions.length>0){let g=N("defs"),v=N("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});v.append(N("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),N("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),g.append(v),u.append(g);let y=N("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let b of this.derived.visibleReferenceRegions)y.append(N("path",{d:b.path,fill:t.referenceOverlayFill==="solid"?"var(--india-map-reference-bg)":`url(#${this.hatchId})`,"aria-label":`${b.label}.${b.description?` ${b.description}`:""}`,role:"img"}));u.append(y)}let d=n?this.derived.regions.filter(g=>g.hitPath):[];if(d.length>0){let g=N("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let v of d){let y=N("path",{d:v.hitPath,fill:"none","pointer-events":"all",tabindex:"-1"});y.addEventListener("mouseenter",()=>this.inspect(v)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(v)),g.append(y)}u.append(g)}let s=g=>re(g.value,this.derived.min,this.derived.max,Zn(t).length);for(let g of this.derived.regions){let y=this.derived.canDrill&&!(this.derived.level==="district"&&this.leafDistrictIds.has(g.id))?this.derived.level==="state"?"Activate to view districts.":"Activate to view sub-districts.":"Activate to select.",b=g.value===null?"No data":(t.formatValue??se)(g.value),x=N("path",{class:"india-choropleth__region",d:g.path,fill:Jn(g.value,g,this.derived.min,this.derived.max,t.colorScale??Bt),tabindex:n?"0":"-1","aria-label":`${g.label}, ${b}. ${y}`});n&&x.setAttribute("role","button"),this.derived.mergedReferenceIds.has(g.id)&&x.classList.add("india-choropleth__region--reference-merged"),n&&(x.setAttribute("aria-pressed",g.id===this.derived.selected?.id?"true":"false"),x.addEventListener("mouseenter",()=>this.inspect(g)),x.addEventListener("mouseleave",()=>this.inspect(null)),x.addEventListener("focus",()=>this.inspect(g)),x.addEventListener("blur",()=>this.inspect(null)),x.addEventListener("click",()=>this.activate(g)),x.addEventListener("keydown",E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),this.activate(g))})),u.append(x),this.pathRefs.set(g.id,x),this.bucketEls.push({el:x,bucket:s(g)})}let c=this.derived.regions.filter(g=>g.extent>0&&g.extent<le);if(c.length>0){let g=N("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let v of c){let y=N("circle",{cx:String(v.centroid[0]),cy:String(v.centroid[1]),r:String(le/2),fill:Jn(v.value,v,this.derived.min,this.derived.max,t.colorScale??Bt)});n&&(y.addEventListener("mouseenter",()=>this.inspect(v)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(v))),this.bucketEls.push({el:y,bucket:s(v)}),g.append(y)}u.append(g)}if(t.showRegionValues){let g=N("g",{class:`india-choropleth__region-values${this.derived.level==="state"?"":" india-choropleth__region-values--district"}`,"aria-hidden":"true"}),v=N("g",{class:"india-choropleth__value-leaders","aria-hidden":"true"});for(let y of this.derived.regions){if(!y.centroid.every(Number.isFinite))continue;let b=y.value===null?"\u2014":(t.formatValue??se)(y.value),x=this.placeRegionValue(y,b);if(!x)continue;let E=N("text",{x:String(x.at[0]),y:String(x.at[1]),"text-anchor":"middle","dominant-baseline":"central"});if(E.textContent=b,g.append(E),this.bucketEls.push({el:E,bucket:s(y)}),x.leader){let C=N("line",{x1:String(x.leader[0][0]),y1:String(x.leader[0][1]),x2:String(x.leader[1][0]),y2:String(x.leader[1][1])});this.bucketEls.push({el:C,bucket:s(y)}),v.append(C)}}u.append(v,g)}if(this.derived.visibleReferenceRegions.length>0){let g=N("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let v of this.derived.visibleReferenceRegions)g.append(N("path",{d:v.path,fill:"none"}));u.append(g)}let h=N("g",{class:"india-choropleth__selection","aria-hidden":"true"}),f=N("path",{class:"india-choropleth__selection-halo",fill:"none"}),m=N("path",{class:"india-choropleth__selection-ring",fill:"none"});h.append(f,m),u.append(h),this.selectionGroupEl=h,this.selectionPathEls=[f,m],this.canvasEl.append(u);let S=G("div",{class:"india-choropleth__tooltip-anchor"});S.style.display="none";let w=G("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});S.append(w),this.canvasEl.append(S),this.tooltipAnchorEl=S,this.tooltipContentEl=w,this.applyInteractionState()}placeRegionValue(t,n){let i=t.extent>0&&t.extent<ze,r=Math.max(n.length*3.1,3),o=5.5,a=t.partBounds.some(([m,S,w,g])=>w-m>=r*2&&g-S>=o*2);if(!i&&a)return{at:t.centroid};let l=i?Vn({anchor:t.centroid,clearance:Math.max(t.extent,le)/2+4+r,halfSize:[r,o],viewBox:[H.width,H.height],centre:[H.width/2,H.height/2],isBlocked:m=>this.coversAnotherRegion(t,m,r,o)}):null;if(!l)return a?{at:t.centroid}:null;let u=Math.max(t.extent,le)/2+1,d=l[0]-t.centroid[0],s=l[1]-t.centroid[1],c=Math.hypot(d,s);if(c<=u+r)return{at:l};let h=[t.centroid[0]+d/c*u,t.centroid[1]+s/c*u],f=[l[0]-d/c*(r+1.5),l[1]-s/c*(r+1.5)];return{at:l,leader:[h,f]}}coversAnotherRegion(t,n,i,r){let o=[n,[n[0]-i,n[1]-r],[n[0]+i,n[1]+r],[n[0]+i,n[1]-r],[n[0]-i,n[1]+r]];for(let a of this.derived.regions)if(a.id!==t.id){for(let l of o)if(a.partBounds.some(([u,d,s,c])=>l[0]>=u&&l[0]<=s&&l[1]>=d&&l[1]<=c))return!0}return!1}renderLegend(){let t=this.options;if(this.legendEl&&(this.legendEl.remove(),this.legendEl=null),t.showLegend===!1)return;let[n,i]=t.legendLabels??["Lower","Higher"],r=G("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${i} values`}),o=G("span");o.textContent=n;let a=t.interactive!==!1,l=G("div",{class:"india-choropleth__swatches"});a||l.setAttribute("aria-hidden","true"),this.swatchEls=[];for(let d of this.derived.buckets){let s=G(a?"button":"i",{class:"india-choropleth__swatch"});if(s.style.backgroundColor=d.color,a){s.setAttribute("type","button");let c=Nn(d,t.formatValue??se);s.setAttribute("aria-label",c),s.setAttribute("title",c),d.matches===0&&s.setAttribute("aria-disabled","true"),s.addEventListener("click",()=>{d.matches!==0&&(this.activeBucket=this.activeBucket===d.index?null:d.index,this.applyInteractionState())}),this.swatchEls.push(s)}l.append(s)}let u=G("span");if(u.textContent=i,r.append(o,l,u),this.derived.visibleReferenceRegions.length>0){let d=G("i",{class:`india-choropleth__reference-key${t.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),s=G("span");s.textContent=t.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",r.append(d,s)}this.insightsEl?this.rootEl.insertBefore(r,this.insightsEl):this.rootEl.append(r),this.legendEl=r,a&&r.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),this.activeBucket=null,this.applyInteractionState())}),this.applyLegendState()}renderInsights(){let t=this.options;if(this.insightsEl&&(this.insightsEl.remove(),this.insightsEl=null),!t.renderInsights)return;let n=G("aside",{class:"india-choropleth__insights","aria-live":"polite"});t.renderInsights(this.computeInsightContext(),n),this.rootEl.append(n),this.insightsEl=n}applyInteractionState(){if(this.destroyed)return;this.derived.selected=this.derived.regions.find(n=>n.id===this.activeSelectedId)??null,this.derived.inspected=this.derived.regions.find(n=>n.id===this.inspectedId)??null;let t=this.options.interactive!==!1;for(let[n,i]of this.pathRefs){let r=n===this.derived.inspected?.id,o=n===this.derived.selected?.id;i.classList.toggle("india-choropleth__region--inspected",r),i.classList.toggle("india-choropleth__region--selected",o),t&&(i.setAttribute("aria-pressed",o?"true":"false"),r?i.setAttribute("aria-describedby",this.tooltipId):i.removeAttribute("aria-describedby"))}for(let{el:n,bucket:i}of this.bucketEls)n.classList.toggle("india-choropleth__dimmed",this.activeBucket!==null&&i!==this.activeBucket);this.svgRootEl?.classList.toggle("india-choropleth__svg--filtered",this.activeBucket!==null),this.applyLegendState(),this.renderSelectionRing(),this.renderTooltip(),this.renderInsights(),this.options.onInsight?.(this.computeInsightContext())}applyLegendState(){if(this.legendEl)for(let[t,n]of this.swatchEls.entries()){let i=this.activeBucket===t;n.classList.toggle("india-choropleth__swatch--active",i),n.classList.toggle("india-choropleth__swatch--muted",this.activeBucket!==null&&!i),n.setAttribute("aria-pressed",i?"true":"false")}}renderTooltip(){if(!this.tooltipAnchorEl||!this.tooltipContentEl)return;let t=this.derived.inspected;if(!t){this.tooltipAnchorEl.style.display="none";return}let n=this.toTooltipContext(t);this.tooltipAnchorEl.style.display="",this.tooltipAnchorEl.style.left=`${t.centroid[0]/H.width*100}%`,this.tooltipAnchorEl.style.top=`${t.centroid[1]/H.height*100}%`,this.tooltipContentEl.textContent="";let i=this.options.renderTooltip?this.options.renderTooltip(n):Xi(n,this.options.formatValue??se);Ji(this.tooltipContentEl,i),this.positionTooltip()}renderSelectionRing(){let t=this.selectionGroupEl;if(!t)return;let n=this.derived.selected;if(!n){t.style.display="none";return}t.style.display="";for(let i of this.selectionPathEls)i.setAttribute("d",n.path);t.classList.toggle("india-choropleth__selection--lifted",n.id===this.derived.inspected?.id)}positionTooltip(){let t=this.tooltipAnchorEl;if(!t)return;t.style.removeProperty("--india-map-tooltip-dx"),t.style.removeProperty("--india-map-tooltip-dy");let n=t.getBoundingClientRect(),i=this.canvasEl.getBoundingClientRect();if(n.width===0||i.width===0)return;let{dx:r,side:o}=jn(n,i,Yn);r!==0&&t.style.setProperty("--india-map-tooltip-dx",`${Math.round(r)}px`),o==="below"&&t.style.setProperty("--india-map-tooltip-dy",`${Yn}px`)}toTooltipContext(t){let n=this.derived.regions.filter(r=>r.value!==null),i=t.value===null?null:n.filter(r=>(r.value??0)>(t.value??0)).length+1;return{...t,level:this.derived.level,total:this.derived.total,share:t.value===null||this.derived.total===0?null:t.value/this.derived.total*100,rank:i,rankedCount:n.length}}computeInsightContext(){let t=this.derived.inspected??this.derived.selected;return t?{...this.toTooltipContext(t),selected:t.id===this.derived.selected?.id}:null}};var de="https://cdn.jsdelivr.net/gh/shashankbudem/bharat-choropleth@v0.1.0/data/generated",ti="State/UT, district and sub-district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).";function He(e){return e.replace(/\/+$/,"")}function ei(e){return`${He(e)}/current-2019-states/states.topo.json`}function Zi(e,t){return`${He(e)}/current-2019-districts/districts/${t}.topo.json`}function Qi(e,t){return`${He(e)}/current-2019-subdistricts/subdistricts/${t}.topo.json`}async function ni(e,t){if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let n=await fetch(e,{signal:t});if(!n.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${e} (HTTP ${n.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return n.json()}function ce(e,t){if(!e||typeof e!="object")throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.");let n=e;if(n.type==="FeatureCollection"||"topology"in n&&"object"in n)return e;if(n.type==="Topology"&&n.objects&&typeof n.objects=="object"){let i=n.objects,r=t in i?t:Object.keys(i)[0];if(!r)throw new Error("BharatChoropleth: the TopoJSON topology contains no objects.");return{topology:e,object:r}}throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.")}async function ii(e,t,n){return typeof e=="string"?ce(await ni(e,n),t):e instanceof Promise?ce(await e,t):e}function ri(e){return typeof e=="object"&&e!==null&&!(e instanceof Promise)}async function oi(e,t,n){return ce(await ni(Zi(e,t),n),"districts")}async function ai(e,t,n){let i=Qi(e,t);if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let r=await fetch(i,{signal:n});if(r.status===404)return null;if(!r.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${i} (HTTP ${r.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return ce(await r.json(),"subdistricts")}var Ue=[{id:"in-cs-01-jammu-and-kashmir",name:"Jammu & Kashmir",slug:"jammu-and-kashmir"},{id:"in-cs-02-himachal-pradesh",name:"Himachal Pradesh",slug:"himachal-pradesh"},{id:"in-cs-03-punjab",name:"Punjab",slug:"punjab"},{id:"in-cs-04-chandigarh",name:"Chandigarh",slug:"chandigarh"},{id:"in-cs-05-uttarakhand",name:"Uttarakhand",slug:"uttarakhand"},{id:"in-cs-06-haryana",name:"Haryana",slug:"haryana"},{id:"in-cs-07-delhi",name:"Delhi",slug:"delhi"},{id:"in-cs-08-rajasthan",name:"Rajasthan",slug:"rajasthan"},{id:"in-cs-09-uttar-pradesh",name:"Uttar Pradesh",slug:"uttar-pradesh"},{id:"in-cs-10-bihar",name:"Bihar",slug:"bihar"},{id:"in-cs-11-sikkim",name:"Sikkim",slug:"sikkim"},{id:"in-cs-12-arunachal-pradesh",name:"Arunachal Pradesh",slug:"arunachal-pradesh"},{id:"in-cs-13-nagaland",name:"Nagaland",slug:"nagaland"},{id:"in-cs-14-manipur",name:"Manipur",slug:"manipur"},{id:"in-cs-15-mizoram",name:"Mizoram",slug:"mizoram"},{id:"in-cs-16-tripura",name:"Tripura",slug:"tripura"},{id:"in-cs-17-meghalaya",name:"Meghalaya",slug:"meghalaya"},{id:"in-cs-18-assam",name:"Assam",slug:"assam"},{id:"in-cs-19-west-bengal",name:"West Bengal",slug:"west-bengal"},{id:"in-cs-20-jharkhand",name:"Jharkhand",slug:"jharkhand"},{id:"in-cs-21-odisha",name:"Odisha",slug:"odisha"},{id:"in-cs-22-chhattisgarh",name:"Chhattisgarh",slug:"chhattisgarh"},{id:"in-cs-23-madhya-pradesh",name:"Madhya Pradesh",slug:"madhya-pradesh"},{id:"in-cs-24-gujarat",name:"Gujarat",slug:"gujarat"},{id:"in-cs-26-dadra-and-nagar-haveli-and-daman-and-diu",name:"Dadra and Nagar Haveli and Daman and Diu",slug:"dadra-and-nagar-haveli-and-daman-and-diu"},{id:"in-cs-27-maharashtra",name:"Maharashtra",slug:"maharashtra"},{id:"in-cs-28-andhra-pradesh",name:"Andhra Pradesh",slug:"andhra-pradesh"},{id:"in-cs-29-karnataka",name:"Karnataka",slug:"karnataka"},{id:"in-cs-30-goa",name:"Goa",slug:"goa"},{id:"in-cs-31-lakshadweep",name:"Lakshadweep",slug:"lakshadweep"},{id:"in-cs-32-kerala",name:"Kerala",slug:"kerala"},{id:"in-cs-33-tamil-nadu",name:"Tamil Nadu",slug:"tamil-nadu"},{id:"in-cs-34-puducherry",name:"Puducherry",slug:"puducherry"},{id:"in-cs-35-andaman-and-nicobar",name:"Andaman & Nicobar",slug:"andaman-and-nicobar"},{id:"in-cs-36-telangana",name:"Telangana",slug:"telangana"},{id:"in-cs-37-ladakh",name:"Ladakh",slug:"ladakh"}],tr={orissa:"odisha",pondicherry:"puducherry",uttaranchal:"uttarakhand","nct-of-delhi":"delhi","new-delhi":"delhi","delhi-nct":"delhi","jammu-kashmir":"jammu-and-kashmir","j-and-k":"jammu-and-kashmir",jk:"jammu-and-kashmir","andaman-nicobar":"andaman-and-nicobar","andaman-and-nicobar-islands":"andaman-and-nicobar","dadra-and-nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu","daman-and-diu":"dadra-and-nagar-haveli-and-daman-and-diu",dnhdd:"dadra-and-nagar-haveli-and-daman-and-diu","nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu"};function Ot(e){return e.toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ve(e){return e.replace(/-/g,"")}var xt=new Map,Ft=new Map;for(let e of Ue)for(let t of[e.slug,Ot(e.name),e.id]){xt.has(t)||xt.set(t,e);let n=Ve(t);Ft.has(n)||Ft.set(n,e)}for(let[e,t]of Object.entries(tr)){let n=xt.get(t);if(!n)continue;xt.has(e)||xt.set(e,n);let i=Ve(e);Ft.has(i)||Ft.set(i,n)}function ut(e){let t=Ot(e);return xt.get(t)??Ft.get(Ve(t))}function si(e,t){if(!e.includes("_"))return;let n=e.replace(/_([a-z])/g,(i,r)=>r.toUpperCase());return n!==e&&n in t?n:void 0}function ci(e){return typeof e=="object"&&e!==null&&e.nodeType===1}var li=["#bharat-choropleth","#map"];function er(e){if(ci(e))return e;if(typeof e=="string"){let t=document.querySelector(e);if(t)return t;throw new Error(`BharatChoropleth: container "${e}" was not found.`)}for(let t of li){let n=document.querySelector(t);if(n)return n}throw new Error(`BharatChoropleth: no container given and none of ${li.join(", ")} exist. Pass an element or selector: new BharatChoropleth("#map").`)}var Gt=class{ready;engineInstance=null;containerEl;options;dataBaseUrl;usingDefaultData;values=new Map;labelByKey=new Map;writtenAs=new Map;statesAccessor;abortController;getId;getLabel;loadingEl=null;destroyed=!1;_fontColor;_borderColor;_borderWidth;_selectionWidth;_colorScale;constructor(t,n={}){let r=typeof t=="object"&&t!==null&&!ci(t)?{...t}:{...n,container:t??n.container};this.options=r,this.containerEl=er(r.container),this.dataBaseUrl=r.dataBaseUrl??de,this.usingDefaultData=r.geometry===void 0,this.getId=r.getId??(o=>String(o.properties?.id??o.properties?.name)),this.getLabel=r.getLabel??(o=>String(o.properties?.name??o.properties?.id));for(let[o,a]of Object.entries(r.values??{})){let l=this.keyFor(o);this.values.set(l,a),this.writtenAs.set(l,o)}return this._colorScale=r.colorScale,this._fontColor=r.fontColor,this._borderColor=r.borderColor,this._borderWidth=r.borderWidth,this._selectionWidth=r.selectionWidth,this.statesAccessor=new Proxy({},{get:(o,a)=>typeof a=="string"?this.getValue(a):void 0,has:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a)),ownKeys:()=>[...this.labelByKey.values()],getOwnPropertyDescriptor:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a))?{enumerable:!0,configurable:!0,value:this.getValue(a)}:void 0,set:(o,a,l)=>typeof a!="string"?!1:(this.setValue(a,l),!0)}),ri(r.geometry)?(this.abortController=null,this.ready=Promise.resolve(this),this.mount(r.geometry)):(this.abortController=typeof AbortController=="function"?new AbortController:null,this.showLoading(),this.ready=ii(r.geometry??ei(this.dataBaseUrl),"states",this.abortController?.signal).then(o=>this.destroyed?this.proxied??this:(this.mount(o),this.proxied??this)).catch(o=>{if(this.destroyed||o.name==="AbortError")return this.proxied??this;throw this.showError(o),o}),this.ready.catch(()=>{})),this.proxied=new Proxy(this,{get:(o,a,l)=>{if(typeof a=="string"&&!(a in o)){let u=si(a,o);return u?Reflect.get(o,u,l):this.getValue(a)}return Reflect.get(o,a,l)},set:(o,a,l,u)=>{if(typeof a=="string"&&!(a in o)){let d=si(a,o);return d?Reflect.set(o,d,l,u):(this.setValue(a,l),!0)}return Reflect.set(o,a,l,u)}}),this.proxied}proxied;keyFor(t){return ut(t)?.id??Ot(t)}keyForFeature(t){let n=this.getId(t);return ut(n)?.id??ut(this.getLabel(t))?.id??Ot(this.getLabel(t))}getValue(t){return this.values.get(this.keyFor(t))??null}setValue(t,n){let i=this.keyFor(t);this.values.set(i,n),this.writtenAs.has(i)||this.writtenAs.set(i,t),this.engineInstance&&(this.labelByKey.has(i)?this.engineInstance.update({}):this.warnUnknown(t))}warnUnknown(t){console.warn(`BharatChoropleth: "${t}" is not a recognized state/UT \u2014 its value is ignored.`)}mount(t){this.clearPlaceholder();for(let b of et(t).features){let x=this.keyForFeature(b);this.labelByKey.set(x,this.getLabel(b)),this.values.has(x)||this.values.set(x,null)}for(let[b,x]of this.values)!this.labelByKey.has(b)&&x!==null&&this.warnUnknown(this.writtenAs.get(b)??b);let{container:n,geometry:i,dataBaseUrl:r,districts:o,subDistricts:a,getId:l,getLabel:u,values:d,fontColor:s,borderColor:c,borderWidth:h,selectionWidth:f,colorScale:m,onReady:S,onError:w,...g}=this.options,v=o??this.usingDefaultData,y=a??this.usingDefaultData;this.engineInstance=new dt(this.containerEl,{...g,colorScale:m,loadDistricts:g.loadDistricts??(v?this.defaultDistrictLoader:void 0),loadSubDistricts:g.loadSubDistricts??(y?this.defaultSubDistrictLoader:void 0),states:{geometry:t,getId:this.getId,getLabel:this.getLabel,getValue:b=>this.values.get(this.keyForFeature(b))??null}}),this._fontColor&&this.mapRootEl.style.setProperty("--india-map-text",this._fontColor),this._borderColor&&this.mapRootEl.style.setProperty("--india-map-stroke",this._borderColor),this._borderWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-border-width",String(this._borderWidth)),this._selectionWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-selection-width",String(this._selectionWidth)),S?.(this.proxied??this)}defaultDistrictLoader=async t=>({geometry:await oi(this.dataBaseUrl,t,this.abortController?.signal),getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.values.get(this.keyFor(this.getLabel(i)))??null});defaultSubDistrictLoader=async t=>{let n=await ai(this.dataBaseUrl,t,this.abortController?.signal);return n?{geometry:n,getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.values.get(this.keyFor(this.getLabel(i)))??null}:null};showLoading(){this.loadingEl=document.createElement("div"),this.loadingEl.className="bharat-choropleth__status",this.loadingEl.setAttribute("role","status"),this.loadingEl.textContent="Loading map\u2026",this.containerEl.appendChild(this.loadingEl)}showError(t){this.clearPlaceholder();let n=document.createElement("div");n.className="bharat-choropleth__status bharat-choropleth__status--error",n.setAttribute("role","alert"),n.textContent=t.message,this.containerEl.appendChild(n),this.loadingEl=n,this.options.onError?this.options.onError(t):console.error(t)}clearPlaceholder(){this.loadingEl?.remove(),this.loadingEl=null}get engine(){return this.engineInstance}get states(){return this.statesAccessor}setValues(t){for(let[n,i]of Object.entries(t)){let r=this.keyFor(n);this.values.set(r,i),this.writtenAs.has(r)||this.writtenAs.set(r,n),this.engineInstance&&!this.labelByKey.has(r)&&this.warnUnknown(n)}this.engineInstance?.update({})}getValues(){let t={};for(let[n,i]of this.labelByKey)t[i]=this.values.get(n)??null;return t}get mapRootEl(){return this.containerEl.querySelector(".india-choropleth")??this.containerEl}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-text",t):this.mapRootEl.style.removeProperty("--india-map-text"))}get borderColor(){return this._borderColor}set borderColor(t){this._borderColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-stroke",t):this.mapRootEl.style.removeProperty("--india-map-stroke"))}get borderWidth(){return this._borderWidth}set borderWidth(t){this._borderWidth=t,this.setWidthVar("--india-map-border-width",t)}get selectionWidth(){return this._selectionWidth}set selectionWidth(t){this._selectionWidth=t,this.setWidthVar("--india-map-selection-width",t)}setWidthVar(t,n){this.engineInstance&&(n===void 0?this.mapRootEl.style.removeProperty(t):this.mapRootEl.style.setProperty(t,String(n)))}get colorScale(){return this._colorScale}set colorScale(t){this._colorScale=t,this.options.colorScale=t,this.engineInstance?.update({colorScale:t})}select(t){this.engineInstance?.select(t)}drillDown(t){let n=t===null?null:ut(t)?.id??t;this.engineInstance?.drillDown(n)}drillDownSubDistrict(t){this.engineInstance?.drillDownSubDistrict(t)}getSelected(){return this.engineInstance?.getSelected()??null}getInspected(){return this.engineInstance?.getInspected()??null}destroy(){this.destroyed=!0,this.abortController?.abort(),this.clearPlaceholder(),this.engineInstance?.destroy(),this.engineInstance=null}};var di="bharat-choropleth-styles";function ui(){if(typeof document>"u"||document.getElementById(di))return;let e=document.createElement("style");e.id=di,e.textContent=Ke,document.head.appendChild(e)}ui();var We=globalThis;We.BharatChoropleth=Gt;We.IndiaChoropleth=dt;We.BharatChoroplethLib={BharatChoropleth:Gt,IndiaChoropleth:dt,STATES:Ue,resolveState:ut,ATTRIBUTION:ti,DEFAULT_DATA_BASE_URL:de,injectStyles:ui};})();
125
+ `;var W=class{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){let n=this._partials,i=0;for(let r=0;r<this._n&&r<32;r++){let o=n[r],a=t+o,l=Math.abs(t)<Math.abs(o)?t-(a-o):o-(a-t);l&&(n[i++]=l),t=a}return n[i]=t,this._n=i+1,this}valueOf(){let t=this._partials,n=this._n,i,r,o,a=0;if(n>0){for(a=t[--n];n>0&&(i=a,r=t[--n],a=i+r,o=r-(a-i),!o););n>0&&(o<0&&t[n-1]<0||o>0&&t[n-1]>0)&&(r=o*2,i=a+r,r==i-a&&(a=i))}return a}};function*pi(e){for(let t of e)yield*t}function ft(e){return Array.from(pi(e))}var R=1e-6,Ye=1e-12,_=Math.PI,q=_/2,ue=_/4,z=_*2,V=180/_,O=_/180,L=Math.abs,jt=Math.atan,ot=Math.atan2,T=Math.cos;var Xe=Math.exp;var Je=Math.log;var F=Math.sin,Ze=Math.sign||function(e){return e>0?1:e<0?-1:0},Y=Math.sqrt,Qe=Math.tan;function tn(e){return e>1?0:e<-1?_:Math.acos(e)}function at(e){return e>1?q:e<-1?-q:Math.asin(e)}function H(){}function $t(e,t){e&&nn.hasOwnProperty(e.type)&&nn[e.type](e,t)}var en={Feature:function(e,t){$t(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,i=-1,r=n.length;++i<r;)$t(n[i].geometry,t)}},nn={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)e=n[i],t.point(e[0],e[1],e[2])},LineString:function(e,t){he(e.coordinates,t,0)},MultiLineString:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)he(n[i],t,0)},Polygon:function(e,t){rn(e.coordinates,t)},MultiPolygon:function(e,t){for(var n=e.coordinates,i=-1,r=n.length;++i<r;)rn(n[i],t)},GeometryCollection:function(e,t){for(var n=e.geometries,i=-1,r=n.length;++i<r;)$t(n[i],t)}};function he(e,t,n){var i=-1,r=e.length-n,o;for(t.lineStart();++i<r;)o=e[i],t.point(o[0],o[1],o[2]);t.lineEnd()}function rn(e,t){var n=-1,i=e.length;for(t.polygonStart();++n<i;)he(e[n],t,1);t.polygonEnd()}function lt(e,t){e&&en.hasOwnProperty(e.type)?en[e.type](e,t):$t(e,t)}function Et(e){return[ot(e[1],e[0]),at(e[2])]}function tt(e){var t=e[0],n=e[1],i=T(n);return[i*T(t),i*F(t),F(n)]}function Dt(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function gt(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function qt(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function _t(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function It(e){var t=Y(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}function kt(e,t){function n(i,r){return i=e(i,r),t(i[0],i[1])}return e.invert&&t.invert&&(n.invert=function(i,r){return i=t.invert(i,r),i&&e.invert(i[0],i[1])}),n}function pe(e,t){return L(e)>_&&(e-=Math.round(e/z)*z),[e,t]}pe.invert=pe;function fe(e,t,n){return(e%=z)?t||n?kt(an(e),sn(t,n)):an(e):t||n?sn(t,n):pe}function on(e){return function(t,n){return t+=e,L(t)>_&&(t-=Math.round(t/z)*z),[t,n]}}function an(e){var t=on(e);return t.invert=on(-e),t}function sn(e,t){var n=T(e),i=F(e),r=T(t),o=F(t);function a(l,u){var d=T(u),s=T(l)*d,c=F(l)*d,h=F(u),p=h*n+s*i;return[ot(c*r-p*o,s*n-h*i),at(p*r+c*o)]}return a.invert=function(l,u){var d=T(u),s=T(l)*d,c=F(l)*d,h=F(u),p=h*r-c*o;return[ot(c*r+h*o,s*n+p*i),at(p*n-s*i)]},a}function ln(e){e=fe(e[0]*O,e[1]*O,e.length>2?e[2]*O:0);function t(n){return n=e(n[0]*O,n[1]*O),n[0]*=V,n[1]*=V,n}return t.invert=function(n){return n=e.invert(n[0]*O,n[1]*O),n[0]*=V,n[1]*=V,n},t}function dn(e,t,n,i,r,o){if(n){var a=T(t),l=F(t),u=i*n;r==null?(r=t+i*z,o=t-u/2):(r=cn(a,r),o=cn(a,o),(i>0?r<o:r>o)&&(r+=i*z));for(var d,s=r;i>0?s>o:s<o;s-=u)d=Et([a,-l*T(s),-l*F(s)]),e.point(d[0],d[1])}}function cn(e,t){t=tt(t),t[0]-=e,It(t);var n=tn(-t[1]);return((-t[2]<0?-n:n)+z-R)%z}function zt(){var e=[],t;return{point:function(n,i,r){t.push([n,i,r])},lineStart:function(){e.push(t=[])},lineEnd:H,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function mt(e,t){return L(e[0]-t[0])<R&&L(e[1]-t[1])<R}function Ht(e,t,n,i){this.x=e,this.z=t,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Ut(e,t,n,i,r){var o=[],a=[],l,u;if(e.forEach(function(f){if(!((S=f.length-1)<=0)){var S,w=f[0],m=f[S],b;if(mt(w,m)){if(!w[2]&&!m[2]){for(r.lineStart(),l=0;l<S;++l)r.point((w=f[l])[0],w[1]);r.lineEnd();return}m[0]+=2*R}o.push(b=new Ht(w,f,null,!0)),a.push(b.o=new Ht(w,null,b,!1)),o.push(b=new Ht(m,f,null,!1)),a.push(b.o=new Ht(m,null,b,!0))}}),!!o.length){for(a.sort(t),un(o),un(a),l=0,u=a.length;l<u;++l)a[l].e=n=!n;for(var d=o[0],s,c;;){for(var h=d,p=!0;h.v;)if((h=h.n)===d)return;s=h.z,r.lineStart();do{if(h.v=h.o.v=!0,h.e){if(p)for(l=0,u=s.length;l<u;++l)r.point((c=s[l])[0],c[1]);else i(h.x,h.n.x,1,r);h=h.n}else{if(p)for(s=h.p.z,l=s.length-1;l>=0;--l)r.point((c=s[l])[0],c[1]);else i(h.x,h.p.x,-1,r);h=h.p}h=h.o,s=h.z,p=!p}while(!h.v);r.lineEnd()}}}function un(e){if(t=e.length){for(var t,n=0,i=e[0],r;++n<t;)i.n=r=e[n],r.p=i,i=r;i.n=r=e[0],r.p=i}}function ge(e){return L(e[0])<=_?e[0]:Ze(e[0])*((L(e[0])+_)%z-_)}function hn(e,t){var n=ge(t),i=t[1],r=F(i),o=[F(n),-T(n),0],a=0,l=0,u=new W;r===1?i=q+R:r===-1&&(i=-q-R);for(var d=0,s=e.length;d<s;++d)if(h=(c=e[d]).length)for(var c,h,p=c[h-1],f=ge(p),S=p[1]/2+ue,w=F(S),m=T(S),b=0;b<h;++b,f=y,w=E,m=P,p=v){var v=c[b],y=ge(v),x=v[1]/2+ue,E=F(x),P=T(x),k=y-f,M=k>=0?1:-1,B=M*k,D=B>_,$=w*E;if(u.add(ot($*M*F(B),m*P+$*T(B))),a+=D?k+M*z:k,D^f>=n^y>=n){var G=gt(tt(p),tt(v));It(G);var A=gt(o,G);It(A);var g=(D^k>=0?-1:1)*at(A[2]);(i>g||i===g&&(G[0]||G[1]))&&(l+=D^k>=0?1:-1)}}return(a<-R||a<R&&u<-Ye)^l&1}function Vt(e,t,n,i){return function(r){var o=t(r),a=zt(),l=t(a),u=!1,d,s,c,h={point:p,lineStart:S,lineEnd:w,polygonStart:function(){h.point=m,h.lineStart=b,h.lineEnd=v,s=[],d=[]},polygonEnd:function(){h.point=p,h.lineStart=S,h.lineEnd=w,s=ft(s);var y=hn(d,i);s.length?(u||(r.polygonStart(),u=!0),Ut(s,gi,y,n,r)):y&&(u||(r.polygonStart(),u=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),u&&(r.polygonEnd(),u=!1),s=d=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function p(y,x){e(y,x)&&r.point(y,x)}function f(y,x){o.point(y,x)}function S(){h.point=f,o.lineStart()}function w(){h.point=p,o.lineEnd()}function m(y,x){c.push([y,x]),l.point(y,x)}function b(){l.lineStart(),c=[]}function v(){m(c[0][0],c[0][1]),l.lineEnd();var y=l.clean(),x=a.result(),E,P=x.length,k,M,B;if(c.pop(),d.push(c),c=null,!!P){if(y&1){if(M=x[0],(k=M.length-1)>0){for(u||(r.polygonStart(),u=!0),r.lineStart(),E=0;E<k;++E)r.point((B=M[E])[0],B[1]);r.lineEnd()}return}P>1&&y&2&&x.push(x.pop().concat(x.shift())),s.push(x.filter(fi))}}return h}}function fi(e){return e.length>1}function gi(e,t){return((e=e.x)[0]<0?e[1]-q-R:q-e[1])-((t=t.x)[0]<0?t[1]-q-R:q-t[1])}var me=Vt(function(){return!0},mi,yi,[-_,-q]);function mi(e){var t=NaN,n=NaN,i=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(o,a){var l=o>0?_:-_,u=L(o-t);L(u-_)<R?(e.point(t,n=(n+a)/2>0?q:-q),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),e.point(o,n),r=0):i!==l&&u>=_&&(L(t-i)<R&&(t-=i*R),L(o-l)<R&&(o-=l*R),n=vi(t,n,o,a),e.point(i,n),e.lineEnd(),e.lineStart(),e.point(l,n),r=0),e.point(t=o,n=a),i=l},lineEnd:function(){e.lineEnd(),t=n=NaN},clean:function(){return 2-r}}}function vi(e,t,n,i){var r,o,a=F(e-n);return L(a)>R?jt((F(t)*(o=T(i))*F(n)-F(i)*(r=T(t))*F(e))/(r*o*a)):(t+i)/2}function yi(e,t,n,i){var r;if(e==null)r=n*q,i.point(-_,r),i.point(0,r),i.point(_,r),i.point(_,0),i.point(_,-r),i.point(0,-r),i.point(-_,-r),i.point(-_,0),i.point(-_,r);else if(L(e[0]-t[0])>R){var o=e[0]<t[0]?_:-_;r=n*o/2,i.point(-o,r),i.point(0,r),i.point(o,r)}else i.point(t[0],t[1])}function pn(e){var t=T(e),n=2*O,i=t>0,r=L(t)>R;function o(s,c,h,p){dn(p,e,n,h,s,c)}function a(s,c){return T(s)*T(c)>t}function l(s){var c,h,p,f,S;return{lineStart:function(){f=p=!1,S=1},point:function(w,m){var b=[w,m],v,y=a(w,m),x=i?y?0:d(w,m):y?d(w+(w<0?_:-_),m):0;if(!c&&(f=p=y)&&s.lineStart(),y!==p&&(v=u(c,b),(!v||mt(c,v)||mt(b,v))&&(b[2]=1)),y!==p)S=0,y?(s.lineStart(),v=u(b,c),s.point(v[0],v[1])):(v=u(c,b),s.point(v[0],v[1],2),s.lineEnd()),c=v;else if(r&&c&&i^y){var E;!(x&h)&&(E=u(b,c,!0))&&(S=0,i?(s.lineStart(),s.point(E[0][0],E[0][1]),s.point(E[1][0],E[1][1]),s.lineEnd()):(s.point(E[1][0],E[1][1]),s.lineEnd(),s.lineStart(),s.point(E[0][0],E[0][1],3)))}y&&(!c||!mt(c,b))&&s.point(b[0],b[1]),c=b,p=y,h=x},lineEnd:function(){p&&s.lineEnd(),c=null},clean:function(){return S|(f&&p)<<1}}}function u(s,c,h){var p=tt(s),f=tt(c),S=[1,0,0],w=gt(p,f),m=Dt(w,w),b=w[0],v=m-b*b;if(!v)return!h&&s;var y=t*m/v,x=-t*b/v,E=gt(S,w),P=_t(S,y),k=_t(w,x);qt(P,k);var M=E,B=Dt(P,M),D=Dt(M,M),$=B*B-D*(Dt(P,P)-1);if(!($<0)){var G=Y($),A=_t(M,(-B-G)/D);if(qt(A,P),A=Et(A),!h)return A;var g=s[0],I=c[0],C=s[1],K=c[1],X;I<g&&(X=g,g=I,I=X);var St=I-g,it=L(St-_)<R,dt=it||St<R;if(!it&&K<C&&(X=C,C=K,K=X),dt?it?C+K>0^A[1]<(L(A[0]-g)<R?C:K):C<=A[1]&&A[1]<=K:St>_^(g<=A[0]&&A[0]<=I)){var rt=_t(M,(-B+G)/D);return qt(rt,P),[A,Et(rt)]}}}function d(s,c){var h=i?e:_-e,p=0;return s<-h?p|=1:s>h&&(p|=2),c<-h?p|=4:c>h&&(p|=8),p}return Vt(a,l,o,i?[0,-e]:[-_,e-_])}function fn(e,t,n,i,r,o){var a=e[0],l=e[1],u=t[0],d=t[1],s=0,c=1,h=u-a,p=d-l,f;if(f=n-a,!(!h&&f>0)){if(f/=h,h<0){if(f<s)return;f<c&&(c=f)}else if(h>0){if(f>c)return;f>s&&(s=f)}if(f=r-a,!(!h&&f<0)){if(f/=h,h<0){if(f>c)return;f>s&&(s=f)}else if(h>0){if(f<s)return;f<c&&(c=f)}if(f=i-l,!(!p&&f>0)){if(f/=p,p<0){if(f<s)return;f<c&&(c=f)}else if(p>0){if(f>c)return;f>s&&(s=f)}if(f=o-l,!(!p&&f<0)){if(f/=p,p<0){if(f>c)return;f>s&&(s=f)}else if(p>0){if(f<s)return;f<c&&(c=f)}return s>0&&(e[0]=a+s*h,e[1]=l+s*p),c<1&&(t[0]=a+c*h,t[1]=l+c*p),!0}}}}}var Rt=1e9,Kt=-Rt;function ve(e,t,n,i){function r(d,s){return e<=d&&d<=n&&t<=s&&s<=i}function o(d,s,c,h){var p=0,f=0;if(d==null||(p=a(d,c))!==(f=a(s,c))||u(d,s)<0^c>0)do h.point(p===0||p===3?e:n,p>1?i:t);while((p=(p+c+4)%4)!==f);else h.point(s[0],s[1])}function a(d,s){return L(d[0]-e)<R?s>0?0:3:L(d[0]-n)<R?s>0?2:1:L(d[1]-t)<R?s>0?1:0:s>0?3:2}function l(d,s){return u(d.x,s.x)}function u(d,s){var c=a(d,1),h=a(s,1);return c!==h?c-h:c===0?s[1]-d[1]:c===1?d[0]-s[0]:c===2?d[1]-s[1]:s[0]-d[0]}return function(d){var s=d,c=zt(),h,p,f,S,w,m,b,v,y,x,E,P={point:k,lineStart:$,lineEnd:G,polygonStart:B,polygonEnd:D};function k(g,I){r(g,I)&&s.point(g,I)}function M(){for(var g=0,I=0,C=p.length;I<C;++I)for(var K=p[I],X=1,St=K.length,it=K[0],dt,rt,Nt=it[0],pt=it[1];X<St;++X)dt=Nt,rt=pt,it=K[X],Nt=it[0],pt=it[1],rt<=i?pt>i&&(Nt-dt)*(i-rt)>(pt-rt)*(e-dt)&&++g:pt<=i&&(Nt-dt)*(i-rt)<(pt-rt)*(e-dt)&&--g;return g}function B(){s=c,h=[],p=[],E=!0}function D(){var g=M(),I=E&&g,C=(h=ft(h)).length;(I||C)&&(d.polygonStart(),I&&(d.lineStart(),o(null,null,1,d),d.lineEnd()),C&&Ut(h,l,g,o,d),d.polygonEnd()),s=d,h=p=f=null}function $(){P.point=A,p&&p.push(f=[]),x=!0,y=!1,b=v=NaN}function G(){h&&(A(S,w),m&&y&&c.rejoin(),h.push(c.result())),P.point=k,y&&s.lineEnd()}function A(g,I){var C=r(g,I);if(p&&f.push([g,I]),x)S=g,w=I,m=C,x=!1,C&&(s.lineStart(),s.point(g,I));else if(C&&y)s.point(g,I);else{var K=[b=Math.max(Kt,Math.min(Rt,b)),v=Math.max(Kt,Math.min(Rt,v))],X=[g=Math.max(Kt,Math.min(Rt,g)),I=Math.max(Kt,Math.min(Rt,I))];fn(K,X,e,t,n,i)?(y||(s.lineStart(),s.point(K[0],K[1])),s.point(X[0],X[1]),C||s.lineEnd(),E=!1):C&&(s.lineStart(),s.point(g,I),E=!1)}b=g,v=I,y=C}return P}}var Pt=e=>e;var ye=new W,be=new W,gn,mn,xe,we,ct={point:H,lineStart:H,lineEnd:H,polygonStart:function(){ct.lineStart=bi,ct.lineEnd=wi},polygonEnd:function(){ct.lineStart=ct.lineEnd=ct.point=H,ye.add(L(be)),be=new W},result:function(){var e=ye/2;return ye=new W,e}};function bi(){ct.point=xi}function xi(e,t){ct.point=vn,gn=xe=e,mn=we=t}function vn(e,t){be.add(we*e-xe*t),xe=e,we=t}function wi(){vn(gn,mn)}var Se=ct;var vt=1/0,Wt=vt,Ct=-vt,Yt=Ct,Si={point:Ei,lineStart:H,lineEnd:H,polygonStart:H,polygonEnd:H,result:function(){var e=[[vt,Wt],[Ct,Yt]];return Ct=Yt=-(Wt=vt=1/0),e}};function Ei(e,t){e<vt&&(vt=e),e>Ct&&(Ct=e),t<Wt&&(Wt=t),t>Yt&&(Yt=t)}var yt=Si;var Ee=0,De=0,Mt=0,Xt=0,Jt=0,bt=0,_e=0,Ie=0,Lt=0,xn,wn,et,nt,J={point:ut,lineStart:yn,lineEnd:bn,polygonStart:function(){J.lineStart=Ii,J.lineEnd=ki},polygonEnd:function(){J.point=ut,J.lineStart=yn,J.lineEnd=bn},result:function(){var e=Lt?[_e/Lt,Ie/Lt]:bt?[Xt/bt,Jt/bt]:Mt?[Ee/Mt,De/Mt]:[NaN,NaN];return Ee=De=Mt=Xt=Jt=bt=_e=Ie=Lt=0,e}};function ut(e,t){Ee+=e,De+=t,++Mt}function yn(){J.point=Di}function Di(e,t){J.point=_i,ut(et=e,nt=t)}function _i(e,t){var n=e-et,i=t-nt,r=Y(n*n+i*i);Xt+=r*(et+e)/2,Jt+=r*(nt+t)/2,bt+=r,ut(et=e,nt=t)}function bn(){J.point=ut}function Ii(){J.point=Ri}function ki(){Sn(xn,wn)}function Ri(e,t){J.point=Sn,ut(xn=et=e,wn=nt=t)}function Sn(e,t){var n=e-et,i=t-nt,r=Y(n*n+i*i);Xt+=r*(et+e)/2,Jt+=r*(nt+t)/2,bt+=r,r=nt*e-et*t,_e+=r*(et+e),Ie+=r*(nt+t),Lt+=r*3,ut(et=e,nt=t)}var ke=J;function Zt(e){this._context=e}Zt.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,z);break}}},result:H};var Pe=new W,Re,En,Dn,At,Tt,Qt={point:H,lineStart:function(){Qt.point=Pi},lineEnd:function(){Re&&_n(En,Dn),Qt.point=H},polygonStart:function(){Re=!0},polygonEnd:function(){Re=null},result:function(){var e=+Pe;return Pe=new W,e}};function Pi(e,t){Qt.point=_n,En=At=e,Dn=Tt=t}function _n(e,t){At-=e,Tt-=t,Pe.add(Y(At*At+Tt*Tt)),At=e,Tt=t}var Ce=Qt;var In,te,kn,Rn,xt=class{constructor(t){this._append=t==null?Pn:Ci(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==kn||this._append!==te){let i=this._radius,r=this._;this._="",this._append`m0,${i}a${i},${i} 0 1,1 0,${-2*i}a${i},${i} 0 1,1 0,${2*i}z`,kn=i,te=this._append,Rn=this._,this._=r}this._+=Rn;break}}}result(){let t=this._;return this._="",t.length?t:null}};function Pn(e){let t=1;this._+=e[0];for(let n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function Ci(e){let t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return Pn;if(t!==In){let n=10**t;In=t,te=function(r){let o=1;this._+=r[0];for(let a=r.length;o<a;++o)this._+=Math.round(arguments[o]*n)/n+r[o]}}return te}function ee(e,t){let n=3,i=4.5,r,o;function a(l){return l&&(typeof i=="function"&&o.pointRadius(+i.apply(this,arguments)),lt(l,r(o))),o.result()}return a.area=function(l){return lt(l,r(Se)),Se.result()},a.measure=function(l){return lt(l,r(Ce)),Ce.result()},a.bounds=function(l){return lt(l,r(yt)),yt.result()},a.centroid=function(l){return lt(l,r(ke)),ke.result()},a.projection=function(l){return arguments.length?(r=l==null?(e=null,Pt):(e=l).stream,a):e},a.context=function(l){return arguments.length?(o=l==null?(t=null,new xt(n)):new Zt(t=l),typeof i!="function"&&o.pointRadius(i),a):t},a.pointRadius=function(l){return arguments.length?(i=typeof l=="function"?l:(o.pointRadius(+l),+l),a):i},a.digits=function(l){if(!arguments.length)return n;if(l==null)n=null;else{let u=Math.floor(l);if(!(u>=0))throw new RangeError(`invalid digits: ${l}`);n=u}return t===null&&(o=new xt(n)),a},a.projection(e).digits(n).context(t)}function Ft(e){return function(t){var n=new Me;for(var i in e)n[i]=e[i];return n.stream=t,n}}function Me(){}Me.prototype={constructor:Me,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function Le(e,t,n){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),lt(n,e.stream(yt)),t(yt.result()),i!=null&&e.clipExtent(i),e}function Ae(e,t,n){return Le(e,function(i){var r=t[1][0]-t[0][0],o=t[1][1]-t[0][1],a=Math.min(r/(i[1][0]-i[0][0]),o/(i[1][1]-i[0][1])),l=+t[0][0]+(r-a*(i[1][0]+i[0][0]))/2,u=+t[0][1]+(o-a*(i[1][1]+i[0][1]))/2;e.scale(150*a).translate([l,u])},n)}function Cn(e,t,n){return Ae(e,[[0,0],t],n)}function Mn(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][0]-i[0][0]),a=(r-o*(i[1][0]+i[0][0]))/2,l=-o*i[0][1];e.scale(150*o).translate([a,l])},n)}function Ln(e,t,n){return Le(e,function(i){var r=+t,o=r/(i[1][1]-i[0][1]),a=-o*i[0][0],l=(r-o*(i[1][1]+i[0][1]))/2;e.scale(150*o).translate([a,l])},n)}var An=16,Mi=T(30*O);function Te(e,t){return+t?Ai(e,t):Li(e)}function Li(e){return Ft({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function Ai(e,t){function n(i,r,o,a,l,u,d,s,c,h,p,f,S,w){var m=d-i,b=s-r,v=m*m+b*b;if(v>4*t&&S--){var y=a+h,x=l+p,E=u+f,P=Y(y*y+x*x+E*E),k=at(E/=P),M=L(L(E)-1)<R||L(o-c)<R?(o+c)/2:ot(x,y),B=e(M,k),D=B[0],$=B[1],G=D-i,A=$-r,g=b*G-m*A;(g*g/v>t||L((m*G+b*A)/v-.5)>.3||a*h+l*p+u*f<Mi)&&(n(i,r,o,a,l,u,D,$,M,y/=P,x/=P,E,S,w),w.point(D,$),n(D,$,M,y,x,E,d,s,c,h,p,f,S,w))}}return function(i){var r,o,a,l,u,d,s,c,h,p,f,S,w={point:m,lineStart:b,lineEnd:y,polygonStart:function(){i.polygonStart(),w.lineStart=x},polygonEnd:function(){i.polygonEnd(),w.lineStart=b}};function m(k,M){k=e(k,M),i.point(k[0],k[1])}function b(){c=NaN,w.point=v,i.lineStart()}function v(k,M){var B=tt([k,M]),D=e(k,M);n(c,h,s,p,f,S,c=D[0],h=D[1],s=k,p=B[0],f=B[1],S=B[2],An,i),i.point(c,h)}function y(){w.point=m,i.lineEnd()}function x(){b(),w.point=E,w.lineEnd=P}function E(k,M){v(r=k,M),o=c,a=h,l=p,u=f,d=S,w.point=v}function P(){n(c,h,s,p,f,S,o,a,r,l,u,d,An,i),w.lineEnd=y,y()}return w}}var Ti=Ft({point:function(e,t){this.stream.point(e*O,t*O)}});function Fi(e){return Ft({point:function(t,n){var i=e(t,n);return this.stream.point(i[0],i[1])}})}function Bi(e,t,n,i,r){function o(a,l){return a*=i,l*=r,[t+e*a,n-e*l]}return o.invert=function(a,l){return[(a-t)/e*i,(n-l)/e*r]},o}function Tn(e,t,n,i,r,o){if(!o)return Bi(e,t,n,i,r);var a=T(o),l=F(o),u=a*e,d=l*e,s=a/e,c=l/e,h=(l*n-a*t)/e,p=(l*t+a*n)/e;function f(S,w){return S*=i,w*=r,[u*S-d*w+t,n-d*S-u*w]}return f.invert=function(S,w){return[i*(s*S-c*w+h),r*(p-c*S-s*w)]},f}function Fe(e){return Oi(function(){return e})()}function Oi(e){var t,n=150,i=480,r=250,o=0,a=0,l=0,u=0,d=0,s,c=0,h=1,p=1,f=null,S=me,w=null,m,b,v,y=Pt,x=.5,E,P,k,M,B;function D(g){return k(g[0]*O,g[1]*O)}function $(g){return g=k.invert(g[0],g[1]),g&&[g[0]*V,g[1]*V]}D.stream=function(g){return M&&B===g?M:M=Ti(Fi(s)(S(E(y(B=g)))))},D.preclip=function(g){return arguments.length?(S=g,f=void 0,A()):S},D.postclip=function(g){return arguments.length?(y=g,w=m=b=v=null,A()):y},D.clipAngle=function(g){return arguments.length?(S=+g?pn(f=g*O):(f=null,me),A()):f*V},D.clipExtent=function(g){return arguments.length?(y=g==null?(w=m=b=v=null,Pt):ve(w=+g[0][0],m=+g[0][1],b=+g[1][0],v=+g[1][1]),A()):w==null?null:[[w,m],[b,v]]},D.scale=function(g){return arguments.length?(n=+g,G()):n},D.translate=function(g){return arguments.length?(i=+g[0],r=+g[1],G()):[i,r]},D.center=function(g){return arguments.length?(o=g[0]%360*O,a=g[1]%360*O,G()):[o*V,a*V]},D.rotate=function(g){return arguments.length?(l=g[0]%360*O,u=g[1]%360*O,d=g.length>2?g[2]%360*O:0,G()):[l*V,u*V,d*V]},D.angle=function(g){return arguments.length?(c=g%360*O,G()):c*V},D.reflectX=function(g){return arguments.length?(h=g?-1:1,G()):h<0},D.reflectY=function(g){return arguments.length?(p=g?-1:1,G()):p<0},D.precision=function(g){return arguments.length?(E=Te(P,x=g*g),A()):Y(x)},D.fitExtent=function(g,I){return Ae(D,g,I)},D.fitSize=function(g,I){return Cn(D,g,I)},D.fitWidth=function(g,I){return Mn(D,g,I)},D.fitHeight=function(g,I){return Ln(D,g,I)};function G(){var g=Tn(n,0,0,h,p,c).apply(null,t(o,a)),I=Tn(n,i-g[0],r-g[1],h,p,c);return s=fe(l,u,d),P=kt(t,I),k=kt(s,P),E=Te(P,x),A()}function A(){return M=B=null,D}return function(){return t=e.apply(this,arguments),D.invert=t.invert&&$,G()}}function ne(e,t){return[e,Je(Qe((q+t)/2))]}ne.invert=function(e,t){return[e,2*jt(Xe(t))-q]};function Be(){return Gi(ne).scale(961/z)}function Gi(e){var t=Fe(e),n=t.center,i=t.scale,r=t.translate,o=t.clipExtent,a=null,l,u,d;t.scale=function(c){return arguments.length?(i(c),s()):i()},t.translate=function(c){return arguments.length?(r(c),s()):r()},t.center=function(c){return arguments.length?(n(c),s()):n()},t.clipExtent=function(c){return arguments.length?(c==null?a=l=u=d=null:(a=+c[0][0],l=+c[0][1],u=+c[1][0],d=+c[1][1]),s()):a==null?null:[[a,l],[u,d]]};function s(){var c=_*i(),h=t(ln(t.rotate()).invert([0,0]));return o(a==null?[[h[0]-c,h[1]-c],[h[0]+c,h[1]+c]]:e===ne?[[Math.max(h[0]-c,a),l],[Math.min(h[0]+c,u),d]]:[[a,Math.max(h[1]-c,l)],[u,Math.min(h[1]+c,d)]])}return s()}function Oe(e){return e}function ie(e){if(e==null)return Oe;var t,n,i=e.scale[0],r=e.scale[1],o=e.translate[0],a=e.translate[1];return function(l,u){u||(t=n=0);var d=2,s=l.length,c=new Array(s);for(c[0]=(t+=l[0])*i+o,c[1]=(n+=l[1])*r+a;d<s;)c[d]=l[d],++d;return c}}function Fn(e,t){for(var n,i=e.length,r=i-t;r<--i;)n=e[r],e[r++]=e[i],e[i]=n}function Ge(e,t){return typeof t=="string"&&(t=e.objects[t]),t.type==="GeometryCollection"?{type:"FeatureCollection",features:t.geometries.map(function(n){return Bn(e,n)})}:Bn(e,t)}function Bn(e,t){var n=t.id,i=t.bbox,r=t.properties==null?{}:t.properties,o=Ne(e,t);return n==null&&i==null?{type:"Feature",properties:r,geometry:o}:i==null?{type:"Feature",id:n,properties:r,geometry:o}:{type:"Feature",id:n,bbox:i,properties:r,geometry:o}}function Ne(e,t){var n=ie(e.transform),i=e.arcs;function r(s,c){c.length&&c.pop();for(var h=i[s<0?~s:s],p=0,f=h.length;p<f;++p)c.push(n(h[p],p));s<0&&Fn(c,f)}function o(s){return n(s)}function a(s){for(var c=[],h=0,p=s.length;h<p;++h)r(s[h],c);return c.length<2&&c.push(c[0]),c}function l(s){for(var c=a(s);c.length<4;)c.push(c[0]);return c}function u(s){return s.map(l)}function d(s){var c=s.type,h;switch(c){case"GeometryCollection":return{type:c,geometries:s.geometries.map(d)};case"Point":h=o(s.coordinates);break;case"MultiPoint":h=s.coordinates.map(o);break;case"LineString":h=a(s.arcs);break;case"MultiLineString":h=s.arcs.map(a);break;case"Polygon":h=u(s.arcs);break;case"MultiPolygon":h=s.arcs.map(u);break;default:return null}return{type:c,coordinates:h}}return d(t)}function Z(e){if("type"in e&&e.type==="FeatureCollection")return e;let t=e,n=typeof t.object=="string"?t.topology.objects[t.object]:t.object;if(!n)throw new Error("The named TopoJSON object does not exist in this topology.");let i=Ge(t.topology,n);return i.type==="FeatureCollection"?i:{type:"FeatureCollection",features:[i]}}function On(e){return e.reduce((t,n)=>t+(n??0),0)}function re(e,t,n,i){if(e===null||i<=0)return null;if(i===1||n===t)return i-1;let r=Math.round((e-t)/(n-t)*(i-1));return Math.min(Math.max(r,0),i-1)}function Gn(e,t,n,i){let r=e.length;return e.map((o,a)=>{let l=t.filter(u=>re(u,n,i,r)===a);return{index:a,color:o,from:l.length?Math.min(...l):null,to:l.length?Math.max(...l):null,matches:l.length}})}function Nn(e,t){if(e.matches===0||e.from===null||e.to===null)return"No regions in this band";let n=e.from===e.to?t(e.from):`${t(e.from)} to ${t(e.to)}`;return`Highlight ${e.matches} ${e.matches===1?"region":"regions"}, ${n}`}function jn(e,t,n,i=4){let r=0;e.right>t.right-i&&(r=t.right-i-e.right),e.left+r<t.left+i&&(r=t.left+i-e.left);let o=e.top<t.top+i?"below":"above";return{dx:r,side:o}}var qi=["puducherry"];function zn(e){let t=e.toLowerCase();return qi.some(n=>t.includes(n))}function oe(e){let t=1/0,n=1/0,i=-1/0,r=-1/0;for(let[o,a]of e)o<t&&(t=o),o>i&&(i=o),a<n&&(n=a),a>r&&(r=a);return[t,n,i,r]}function ae(e){let t=0;for(let n of e){if(n.length===0)continue;let[i,r,o,a]=oe(n),l=Math.max(o-i,a-r);l>t&&(t=l)}return t}function $n(e){let t=0;for(let n=0;n<e.length;n++){let[i,r]=e[n],[o,a]=e[(n+1)%e.length];t+=i*a-o*r}return t/2}function Hn(e,t){let n=null,i=0;for(let u of e){if(u.length<3)continue;let d=Math.abs($n(u));d>i&&(i=d,n=u)}if(!n||i===0)return t;let r=$n(n),o=0,a=0;for(let u=0;u<n.length;u++){let[d,s]=n[u],[c,h]=n[(u+1)%n.length],p=d*h-c*s;o+=(d+c)*p,a+=(s+h)*p}let l=[o/(6*r),a/(6*r)];return Number.isFinite(l[0])&&Number.isFinite(l[1])?l:t}function zi(e,t){let[n,i]=e,[r,o,a,l]=t,u=Math.max(r-n,0)+Math.max(n-a,0),d=Math.max(o-i,0)+Math.max(i-l,0);return Math.hypot(u,d)}function Un(e,t){let n=1/0;for(let i of t){let r=zi(e,i);r<n&&(n=r)}return n}var Hi=[0,Math.PI/6,-Math.PI/6,Math.PI/3,-Math.PI/3,Math.PI/2,-Math.PI/2,2*Math.PI/3,-(2*Math.PI)/3,5*Math.PI/6,-(5*Math.PI)/6,Math.PI];function Vn(e){let{anchor:t,clearance:n,halfSize:i,viewBox:r,centre:o,isBlocked:a}=e,l=t[0]-o[0],u=t[1]-o[1],d=l===0&&u===0?0:Math.atan2(u,l);for(let s of Hi){let c=d+s,h=[qn(t[0]+Math.cos(c)*n,i[0],r[0]-i[0]),qn(t[1]+Math.sin(c)*n,i[1],r[1]-i[1])];if(!a(h))return h}return null}function qn(e,t,n){return Math.min(Math.max(e,t),n)}function Kn(e,t,n=8){let i=()=>e.map(o=>[...o]);if(t<=0)return i();let r=ae(e);return r<=0||r>=t?i():e.map(o=>{let[a,l,u,d]=oe(o),s=Math.max(u-a,d-l),c=s<=0?1:Math.min(t/s,n),h=(a+u)/2,p=(l+d)/2;return o.map(([f,S])=>[h+(f-h)*c,p+(S-p)*c])})}function Ui(e){let t=[...e].sort((u,d)=>u[0]-d[0]||u[1]-d[1]),n=[];for(let u of t){let d=n.at(-1);(!d||d[0]!==u[0]||d[1]!==u[1])&&n.push(u)}if(n.length<3)return n.map(u=>[...u]);let i=(u,d,s)=>(d[0]-u[0])*(s[1]-u[1])-(d[1]-u[1])*(s[0]-u[0]),r=u=>{let d=[];for(let s of u){for(;d.length>=2&&i(d[d.length-2],d[d.length-1],s)<=0;)d.pop();d.push(s)}return d},o=r(n),a=r([...n].reverse()),l=[...o.slice(0,-1),...a.slice(0,-1)];return l.length>=3?l:n.map(u=>[...u])}function Wn(e,t){if(e.length<2||t<=0)return null;let n=ae(e);if(n<=0||n>=t)return null;let i=Ui(e.flat());return i.length>=3?i:null}function je(e){let t="";for(let n of e)if(n.length!==0){t+=`M${n[0][0]},${n[0][1]}`;for(let i=1;i<n.length;i++)t+=`L${n[i][0]},${n[i][1]}`;t+="Z"}return t}var Vi="http://www.w3.org/2000/svg",U={width:960,height:640,padding:28},Bt=["#d9f1ed","#b9e3dd","#8fd1c8","#5bb9ae","#2f9c90","#147b71","#075b55"],se=new Intl.NumberFormat("en-IN").format,Yn=12,ze=22,Ki=14,le=7;function Xn(e,t){let n=e.geometry;if(!n)return[];let i=n.type==="Polygon"?[n.coordinates]:n.type==="MultiPolygon"?n.coordinates:[],r=[];for(let o of i)for(let a of o){let l=[];for(let u of a){let d=t(u);d&&Number.isFinite(d[0])&&Number.isFinite(d[1])&&l.push([d[0],d[1]])}l.length>0&&r.push(l)}return r}var Wi=0;function Jn(e,t,n,i,r){if(typeof r=="function"){let a={min:n,max:i,feature:t.feature,id:t.id};return r(e,a)}let o=re(e,n,i,r.length);return o===null?"var(--india-map-empty)":r[o]??"var(--india-map-empty)"}function Zn(e){return typeof e.colorScale=="function"?Bt:e.colorScale??Bt}function $e(e){return Be().fitExtent([[U.padding,U.padding],[U.width-U.padding,U.height-U.padding]],e)}function qe(e,t,n=0,i=Z(e.geometry)){let r=ee(t);return i.features.map(o=>{let a=r.centroid(o),l=r.bounds(o),u=[(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2],d={id:e.getId(o),label:e.getLabel(o),value:e.getValue(o),meta:e.getMeta?.(o),feature:o},s=n>0&&!zn(d.id),c=s?Kn(Xn(o,t),n):Xn(o,t),h=Wn(c,ze);return{...d,path:s?je(c):r(o)??"",hitPath:h?je([h]):null,centroid:c.length>0?Hn(c,a.every(Number.isFinite)?a:u):a.every(Number.isFinite)?a:u,partBounds:c.map(oe),extent:ae(c)}})}function Qn(e,t){let n=ee(t);return Z(e.geometry).features.map(i=>({id:e.getId(i),label:e.getLabel(i),description:e.getDescription(i),path:n(i)??""}))}function Yi(e){let t=e%100;return t>=11&&t<=13?`${e}th`:`${e}${["th","st","nd","rd"][e%10]??"th"}`}function Xi(e,t){let n=document.createDocumentFragment(),i=document.createElement("strong");i.textContent=e.label;let r=document.createElement("b");if(r.textContent=e.value===null?"No data":t(e.value),n.append(i,r),e.share!==null){let o=document.createElement("span");o.className="india-choropleth__tooltip-bar",o.setAttribute("aria-hidden","true");let a=document.createElement("span");a.style.width=`${Math.max(e.share,1.5)}%`,o.append(a);let l=document.createElement("small"),u=[`${e.share.toFixed(1)}% of total`];e.rank!==null&&u.push(`${Yi(e.rank)} of ${e.rankedCount}`),l.textContent=u.join(" \xB7 "),n.append(o,l)}return n}function N(e,t){let n=document.createElement(e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function j(e,t){let n=document.createElementNS(Vi,e);for(let[i,r]of Object.entries(t??{}))n.setAttribute(i,r);return n}function Ji(e,t){typeof t=="string"?e.textContent=t:e.appendChild(t)}var ht=class{containerEl;options;instanceId=`india-choropleth-${++Wi}`;tooltipId=`${this.instanceId}-tooltip`;hatchId=`${this.instanceId}-hatch`;activeDrillDownId;activeSubDrillDownId;activeSelectedId;inspectedId=null;loadedDistricts=null;loadedSubDistricts=null;leafDistrictIds=new Set;loadedDistrictReferenceOverlay=null;loadingState=null;loadingDistrict=null;loadError=null;subLoadError=null;districtGeneration=0;subDistrictGeneration=0;overlayGeneration=0;restoreFocusId=null;destroyed=!1;projectionCache=null;attemptedDistrictLoadForId=null;attemptedSubDistrictLoadForId=null;attemptedOverlayLoadForId=null;pathRefs=new Map;derived;rootEl;toolbarEl;canvasEl;legendEl=null;swatchEls=[];bucketEls=[];activeBucket=null;bandsKey=null;insightsEl=null;tooltipAnchorEl=null;tooltipContentEl=null;svgRootEl=null;selectionGroupEl=null;selectionPathEls=[];constructor(t,n){let i=typeof t=="string"?document.querySelector(t):t;if(!i)throw new Error(`IndiaChoropleth: container ${typeof t=="string"?`"${t}"`:""} was not found.`);this.containerEl=i,this.options=n,this.activeDrillDownId=n.drillDownId!==void 0?n.drillDownId:n.defaultDrillDownId??null,this.activeSubDrillDownId=n.subDistrictDrillDownId!==void 0?n.subDistrictDrillDownId:n.defaultSubDistrictDrillDownId??null,this.activeSelectedId=n.selectedId!==void 0?n.selectedId:n.defaultSelectedId??null,this.buildShell(),this.renderStructure()}update(t){"loadDistricts"in t&&t.loadDistricts!==this.options.loadDistricts&&(this.attemptedDistrictLoadForId=null),"loadSubDistricts"in t&&t.loadSubDistricts!==this.options.loadSubDistricts&&(this.attemptedSubDistrictLoadForId=null,this.leafDistrictIds.clear()),"loadDistrictReferenceOverlay"in t&&t.loadDistrictReferenceOverlay!==this.options.loadDistrictReferenceOverlay&&(this.attemptedOverlayLoadForId=null),this.options={...this.options,...t},"drillDownId"in t&&t.drillDownId!==void 0&&(t.drillDownId!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.activeDrillDownId=t.drillDownId),"subDistrictDrillDownId"in t&&t.subDistrictDrillDownId!==void 0&&(this.activeSubDrillDownId=t.subDistrictDrillDownId),"selectedId"in t&&t.selectedId!==void 0&&(this.activeSelectedId=t.selectedId),this.renderStructure()}select(t){let n=this.derived.regions.find(i=>i.id===t)??null;this.setActiveSelectedId(n?.id??null),n&&this.options.onSelectedChange?.(n,this.derived.level),this.applyInteractionState()}drillDown(t){if(t===null){this.goToStates();return}let n=this.derived.stateRegions.find(i=>i.id===t);n&&(t!==this.activeDrillDownId&&this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(t),this.options.onDrillDownChange?.(t,n),this.renderStructure())}drillDownSubDistrict(t){if(t===null){this.derived.level==="subdistrict"&&this.goBack();return}let n=this.derived.districtRegions.find(i=>i.id===t);n&&(this.setActiveSubDrillDownId(t),this.options.onSubDistrictDrillDownChange?.(t,n),this.renderStructure())}getSelected(){return this.derived.selected}getInspected(){return this.derived.inspected}destroy(){this.destroyed=!0,this.districtGeneration+=1,this.subDistrictGeneration+=1,this.overlayGeneration+=1,this.pathRefs.clear(),this.containerEl.textContent=""}setActiveDrillDownId(t){this.options.drillDownId===void 0&&(this.activeDrillDownId=t)}setActiveSubDrillDownId(t){this.options.subDistrictDrillDownId===void 0&&(this.activeSubDrillDownId=t)}setActiveSelectedId(t){this.options.selectedId===void 0&&(this.activeSelectedId=t)}buildShell(){this.rootEl=N("section"),this.toolbarEl=N("div",{class:"india-choropleth__toolbar"}),this.canvasEl=N("div",{class:"india-choropleth__canvas"}),this.canvasEl.addEventListener("mouseleave",()=>{this.options.interactive!==!1&&this.inspect(null)}),this.rootEl.append(this.toolbarEl,this.canvasEl),this.containerEl.textContent="",this.containerEl.appendChild(this.rootEl)}recompute(){let t=this.options,n=t.referenceOverlay?.geometry??null,i=this.projectionCache,r,o;if(i&&i.geometry===t.states.geometry&&i.referenceGeometry===n)r=i.collection,o=i.projection;else{r=Z(t.states.geometry);let C=n?Z(n).features:[];o=$e({type:"FeatureCollection",features:[...r.features,...C]}),this.projectionCache={geometry:t.states.geometry,referenceGeometry:n,collection:r,projection:o}}let a=n?Z(n):null,l=qe(t.states,o,t.minPartExtent??0,r),u=t.referenceOverlay?Qn(t.referenceOverlay,o):[],d=l.find(C=>C.id===this.activeDrillDownId)??null,s=!!(d&&this.activeDrillDownId),c=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,h=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,p=c?Z(c.geometry):null,f=h?Z(h.geometry):null,S=p?$e({type:"FeatureCollection",features:[...p.features,...f?.features??[]]}):null,w=c&&S?qe(c,S,t.minDistrictPartExtent??t.minPartExtent??0):[],m=w.find(C=>C.id===this.activeSubDrillDownId)??null,v=!!(s&&m&&this.activeSubDrillDownId)?"subdistrict":s?"district":"state",y=this.loadedSubDistricts?.districtId===this.activeSubDrillDownId?this.loadedSubDistricts.layer:null,x=y?Z(y.geometry):null,E=x?$e(x):null,P=y&&E?qe(y,E,t.minDistrictPartExtent??t.minPartExtent??0):[],k=v==="subdistrict"?P:v==="district"?w:l,M=v==="district"&&h&&S?Qn(h,S):[],B=k.find(C=>C.id===this.activeSelectedId)??null,D=k.find(C=>C.id===this.inspectedId)??null;this.inspectedId&&!D&&(this.inspectedId=null);let $=k.map(C=>C.value).filter(C=>C!==null),G=On($),A=$.length?Math.min(...$):0,g=$.length?Math.max(...$):0;this.derived={stateRegions:l,referenceRegions:u,drilledState:d,drilledDistrict:m,districtRegions:w,level:v,regions:k,visibleReferenceRegions:v==="state"?u:M,selected:B,inspected:D,total:G,min:A,max:g,canDrill:v==="state"?!!t.loadDistricts:v==="district"?!!t.loadSubDistricts:!1,mergedReferenceIds:new Set(t.referenceOverlayMergeIds??[]),buckets:Gn(Zn(t),k.map(C=>C.value),A,g)};let I=[v,this.activeDrillDownId??"",this.activeSubDrillDownId??"",typeof t.colorScale=="function"?"function":(t.colorScale??Bt).join(",")].join("|");I!==this.bandsKey&&(this.bandsKey=I,this.activeBucket=null),this.activeBucket!==null&&this.activeBucket>=this.derived.buckets.length&&(this.activeBucket=null)}loadDistrictsFor(t){let n=this.options;if(!n.loadDistricts){this.loadedDistricts=null,this.loadingState=null,this.loadError=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.districtGeneration;this.loadingState=t,this.loadError=null,this.loadedDistricts=null,n.loadDistricts(t,i).then(o=>{this.destroyed||r!==this.districtGeneration||(this.loadedDistricts={stateId:t,layer:o},this.loadingState=null,this.renderStructure())}).catch(o=>{this.destroyed||r!==this.districtGeneration||(this.loadError=o instanceof Error?o:new Error("Unable to load districts."),this.loadingState=null,this.renderStructure())})}loadSubDistrictsFor(t){let n=this.options;if(!n.loadSubDistricts){this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null;return}let i=this.derived.districtRegions.find(o=>o.id===t);if(!i||!this.activeDrillDownId)return;let r=++this.subDistrictGeneration;this.loadingDistrict=t,this.subLoadError=null,this.loadedSubDistricts=null,n.loadSubDistricts(t,i,this.activeDrillDownId).then(o=>{if(!(this.destroyed||r!==this.subDistrictGeneration)){if(this.loadingDistrict=null,!o){this.leafDistrictIds.add(t),this.setActiveSubDrillDownId(null),this.setActiveSelectedId(i.id),n.onSubDistrictDrillDownChange?.(null,i),this.renderStructure();return}this.loadedSubDistricts={districtId:t,layer:o},this.renderStructure()}}).catch(o=>{this.destroyed||r!==this.subDistrictGeneration||(this.subLoadError=o instanceof Error?o:new Error("Unable to load sub-districts."),this.loadingDistrict=null,this.renderStructure())})}loadDistrictReferenceOverlayFor(t){let n=this.options;if(!n.loadDistrictReferenceOverlay){this.loadedDistrictReferenceOverlay=null;return}let i=this.derived.stateRegions.find(o=>o.id===t);if(!i)return;let r=++this.overlayGeneration;this.loadedDistrictReferenceOverlay=null,n.loadDistrictReferenceOverlay(t,i).then(o=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:o},this.renderStructure())}).catch(()=>{this.destroyed||r!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:t,overlay:null},this.renderStructure())})}inspect(t){let n=t?.id??null;n===null&&this.inspectedId===null||(this.inspectedId=n,this.derived.inspected=t,this.options.onInspect?.(t??null,this.derived.level),this.applyInteractionState())}toViewBox(t){let n=this.canvasEl.querySelector("svg");if(!n)return null;let i=n.getBoundingClientRect();if(i.width===0||i.height===0)return null;let r=Math.min(i.width/U.width,i.height/U.height),o=(i.width-U.width*r)/2,a=(i.height-U.height*r)/2;return[(t.clientX-i.left-o)/r,(t.clientY-i.top-a)/r]}smallRegionNear(t){let n=null,i=1/0;for(let r of this.derived.regions){if(r.extent<=0||r.extent>=ze)continue;let o=Un(t,r.partBounds);o<=Ki&&o<i&&(i=o,n=r)}return n}activate(t){let n=this.options;if(n.onRegionClick?.(t,this.derived.level),this.setActiveSelectedId(t.id),n.onSelectedChange?.(t,this.derived.level),this.derived.level==="state"&&n.loadDistricts){this.setActiveSelectedId(null),this.setActiveDrillDownId(t.id),n.onDrillDownChange?.(t.id,t),this.renderStructure();return}if(this.derived.level==="district"&&n.loadSubDistricts&&!this.leafDistrictIds.has(t.id)){this.setActiveSelectedId(null),this.setActiveSubDrillDownId(t.id),n.onSubDistrictDrillDownChange?.(t.id,t),this.renderStructure();return}this.applyInteractionState()}goBack(){if(this.derived.level==="subdistrict"){let t=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,this.options.onSubDistrictDrillDownChange?.(null,t),this.renderStructure();return}this.goToStates()}goToStates(){let t=this.derived.drilledState??void 0,n=this.derived.drilledDistrict??void 0;this.setActiveSubDrillDownId(null),this.setActiveDrillDownId(null),this.setActiveSelectedId(t?.id??null),this.inspectedId=t?.id??null,this.restoreFocusId=t?.id??null,n&&this.options.onSubDistrictDrillDownChange?.(null,n),this.options.onDrillDownChange?.(null,t),this.renderStructure()}renderStructure(){if(this.destroyed)return;this.recompute();let t=this.options;this.activeDrillDownId&&t.loadDistricts&&this.attemptedDistrictLoadForId!==this.activeDrillDownId&&(this.attemptedDistrictLoadForId=this.activeDrillDownId,this.loadDistrictsFor(this.activeDrillDownId)),this.activeDrillDownId||(this.loadedDistricts=null,this.loadingState=null,this.loadError=null,this.attemptedDistrictLoadForId=null),this.activeDrillDownId&&t.loadDistrictReferenceOverlay&&this.attemptedOverlayLoadForId!==this.activeDrillDownId&&(this.attemptedOverlayLoadForId=this.activeDrillDownId,this.loadDistrictReferenceOverlayFor(this.activeDrillDownId)),(!this.activeDrillDownId||!t.loadDistrictReferenceOverlay)&&(this.loadedDistrictReferenceOverlay=null,this.attemptedOverlayLoadForId=null),this.activeSubDrillDownId&&t.loadSubDistricts&&this.attemptedSubDistrictLoadForId!==this.activeSubDrillDownId&&this.derived.districtRegions.some(i=>i.id===this.activeSubDrillDownId)&&(this.attemptedSubDistrictLoadForId=this.activeSubDrillDownId,this.loadSubDistrictsFor(this.activeSubDrillDownId)),this.activeSubDrillDownId||(this.loadedSubDistricts=null,this.loadingDistrict=null,this.subLoadError=null,this.attemptedSubDistrictLoadForId=null);let n=t.interactive!==!1;if(this.rootEl.className=["india-choropleth",!n&&"india-choropleth--static",t.className].filter(Boolean).join(" "),this.loadingState||this.loadingDistrict?this.rootEl.setAttribute("aria-busy","true"):this.rootEl.removeAttribute("aria-busy"),this.renderToolbar(),this.renderCanvas(),this.renderLegend(),this.restoreFocusId&&this.derived.regions.some(i=>i.id===this.restoreFocusId)){let i=this.restoreFocusId;this.restoreFocusId=null,this.pathRefs.get(i)?.focus()}}renderToolbar(){let t=this.options;if(this.toolbarEl.textContent="",t.showBreadcrumb===!1)return;let n=N("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"}),i=()=>{let a=N("span",{"aria-hidden":"true"});return a.textContent="/",a};if(!this.derived.drilledState){let a=N("span");a.textContent="All states",n.append(a),this.toolbarEl.append(n);return}let r=N("button",{class:"india-choropleth__back",type:"button"});if(r.textContent="All states",r.addEventListener("click",()=>this.goToStates()),n.append(r,i()),this.derived.level==="subdistrict"&&this.derived.drilledDistrict){let a=N("button",{class:"india-choropleth__back",type:"button"});a.textContent=this.derived.drilledState.label,a.addEventListener("click",()=>this.goBack());let l=N("span",{"aria-current":"page"});l.textContent=this.derived.drilledDistrict.label,n.append(a,i(),l)}else{let a=N("span",{"aria-current":"page"});a.textContent=this.derived.drilledState.label,n.append(a)}this.toolbarEl.append(n)}renderCanvas(){let t=this.options,n=t.interactive!==!1;this.canvasEl.textContent="",this.pathRefs.clear(),this.bucketEls=[],this.svgRootEl=null,this.tooltipAnchorEl=null,this.tooltipContentEl=null,this.selectionGroupEl=null,this.selectionPathEls=[];let i=!!(this.derived.drilledState&&this.activeDrillDownId),r=this.derived.level==="subdistrict",o=r&&(!this.loadedSubDistricts||this.loadedSubDistricts.districtId!==this.activeSubDrillDownId||this.subLoadError),a=!o&&i&&(!this.loadedDistricts||this.loadedDistricts.stateId!==this.activeDrillDownId||this.loadError),l=!o&&!a&&this.derived.regions.length===0;if(o||a||l){let m=o&&this.subLoadError||a&&this.loadError,b=N("div",{class:"india-choropleth__status",role:m?"alert":"status"});b.textContent=o?this.subLoadError?this.subLoadError.message:this.loadingDistrict?"Loading sub-districts\u2026":"Sub-district data is unavailable for this district.":l?r?"No sub-district data is available for this district.":"No district data is available for this state.":this.loadError?this.loadError.message:this.loadingState?"Loading districts\u2026":"District data is unavailable for this state.",this.canvasEl.append(b),this.applyInteractionState();return}let u=j("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${U.width} ${U.height}`,role:"group","aria-label":t.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=u,n&&(u.addEventListener("keydown",m=>{m.key==="Escape"&&(m.preventDefault(),this.inspect(null))}),u.addEventListener("click",m=>{if(m.target!==u)return;let b=this.toViewBox(m),v=b?this.smallRegionNear(b):null;if(v){this.activate(v);return}this.options.onBackgroundClick?.(),this.activeSelectedId!==null&&(this.setActiveSelectedId(null),this.options.onSelectedChange?.(null,this.derived.level),this.applyInteractionState())})),this.derived.visibleReferenceRegions.length>0){let m=j("defs"),b=j("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});b.append(j("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),j("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),m.append(b),u.append(m);let v=j("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let y of this.derived.visibleReferenceRegions)v.append(j("path",{d:y.path,fill:t.referenceOverlayFill==="solid"?"var(--india-map-reference-bg)":`url(#${this.hatchId})`,"aria-label":`${y.label}.${y.description?` ${y.description}`:""}`,role:"img"}));u.append(v)}let d=n?this.derived.regions.filter(m=>m.hitPath):[];if(d.length>0){let m=j("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let b of d){let v=j("path",{d:b.hitPath,fill:"none","pointer-events":"all",tabindex:"-1"});v.addEventListener("mouseenter",()=>this.inspect(b)),v.addEventListener("mouseleave",()=>this.inspect(null)),v.addEventListener("click",()=>this.activate(b)),m.append(v)}u.append(m)}let s=m=>re(m.value,this.derived.min,this.derived.max,Zn(t).length);for(let m of this.derived.regions){let v=this.derived.canDrill&&!(this.derived.level==="district"&&this.leafDistrictIds.has(m.id))?this.derived.level==="state"?"Activate to view districts.":"Activate to view sub-districts.":"Activate to select.",y=m.value===null?"No data":(t.formatValue??se)(m.value),x=j("path",{class:"india-choropleth__region",d:m.path,fill:Jn(m.value,m,this.derived.min,this.derived.max,t.colorScale??Bt),tabindex:n?"0":"-1","aria-label":`${m.label}, ${y}. ${v}`});n&&x.setAttribute("role","button"),this.derived.mergedReferenceIds.has(m.id)&&x.classList.add("india-choropleth__region--reference-merged"),n&&(x.setAttribute("aria-pressed",m.id===this.derived.selected?.id?"true":"false"),x.addEventListener("mouseenter",()=>this.inspect(m)),x.addEventListener("mouseleave",()=>this.inspect(null)),x.addEventListener("focus",()=>this.inspect(m)),x.addEventListener("blur",()=>this.inspect(null)),x.addEventListener("click",()=>this.activate(m)),x.addEventListener("keydown",E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),this.activate(m))})),u.append(x),this.pathRefs.set(m.id,x),this.bucketEls.push({el:x,bucket:s(m)})}let c=this.derived.regions.filter(m=>m.extent>0&&m.extent<le);if(c.length>0){let m=j("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let b of c){let v=j("circle",{cx:String(b.centroid[0]),cy:String(b.centroid[1]),r:String(le/2),fill:Jn(b.value,b,this.derived.min,this.derived.max,t.colorScale??Bt)});n&&(v.addEventListener("mouseenter",()=>this.inspect(b)),v.addEventListener("mouseleave",()=>this.inspect(null)),v.addEventListener("click",()=>this.activate(b))),this.bucketEls.push({el:v,bucket:s(b)}),m.append(v)}u.append(m)}if(t.showRegionValues){let m=j("g",{class:`india-choropleth__region-values${this.derived.level==="state"?"":" india-choropleth__region-values--district"}`,"aria-hidden":"true"}),b=j("g",{class:"india-choropleth__value-leaders","aria-hidden":"true"});for(let v of this.derived.regions){if(!v.centroid.every(Number.isFinite))continue;let y=v.value===null?"\u2014":(t.formatValue??se)(v.value),x=this.placeRegionValue(v,y);if(!x)continue;let E=j("text",{x:String(x.at[0]),y:String(x.at[1]),"text-anchor":"middle","dominant-baseline":"central"});if(E.textContent=y,m.append(E),this.bucketEls.push({el:E,bucket:s(v)}),x.leader){let P=j("line",{x1:String(x.leader[0][0]),y1:String(x.leader[0][1]),x2:String(x.leader[1][0]),y2:String(x.leader[1][1])});this.bucketEls.push({el:P,bucket:s(v)}),b.append(P)}}u.append(b,m)}if(this.derived.visibleReferenceRegions.length>0){let m=j("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let b of this.derived.visibleReferenceRegions)m.append(j("path",{d:b.path,fill:"none"}));u.append(m)}let h=j("g",{class:"india-choropleth__selection","aria-hidden":"true"}),p=j("path",{class:"india-choropleth__selection-halo",fill:"none"}),f=j("path",{class:"india-choropleth__selection-ring",fill:"none"});h.append(p,f),u.append(h),this.selectionGroupEl=h,this.selectionPathEls=[p,f],this.canvasEl.append(u);let S=N("div",{class:"india-choropleth__tooltip-anchor"});S.style.display="none";let w=N("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});S.append(w),this.canvasEl.append(S),this.tooltipAnchorEl=S,this.tooltipContentEl=w,this.applyInteractionState()}placeRegionValue(t,n){let i=t.extent>0&&t.extent<ze,r=Math.max(n.length*3.1,3),o=5.5,a=t.partBounds.some(([f,S,w,m])=>w-f>=r*2&&m-S>=o*2);if(!i&&a)return{at:t.centroid};let l=i?Vn({anchor:t.centroid,clearance:Math.max(t.extent,le)/2+4+r,halfSize:[r,o],viewBox:[U.width,U.height],centre:[U.width/2,U.height/2],isBlocked:f=>this.coversAnotherRegion(t,f,r,o)}):null;if(!l)return a?{at:t.centroid}:null;let u=Math.max(t.extent,le)/2+1,d=l[0]-t.centroid[0],s=l[1]-t.centroid[1],c=Math.hypot(d,s);if(c<=u+r)return{at:l};let h=[t.centroid[0]+d/c*u,t.centroid[1]+s/c*u],p=[l[0]-d/c*(r+1.5),l[1]-s/c*(r+1.5)];return{at:l,leader:[h,p]}}coversAnotherRegion(t,n,i,r){let o=[n,[n[0]-i,n[1]-r],[n[0]+i,n[1]+r],[n[0]+i,n[1]-r],[n[0]-i,n[1]+r]];for(let a of this.derived.regions)if(a.id!==t.id){for(let l of o)if(a.partBounds.some(([u,d,s,c])=>l[0]>=u&&l[0]<=s&&l[1]>=d&&l[1]<=c))return!0}return!1}renderLegend(){let t=this.options;if(this.legendEl&&(this.legendEl.remove(),this.legendEl=null),t.showLegend===!1)return;let[n,i]=t.legendLabels??["Lower","Higher"],r=N("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${i} values`}),o=N("span");o.textContent=n;let a=t.interactive!==!1,l=N("div",{class:"india-choropleth__swatches"});a||l.setAttribute("aria-hidden","true"),this.swatchEls=[];for(let d of this.derived.buckets){let s=N(a?"button":"i",{class:"india-choropleth__swatch"});if(s.style.backgroundColor=d.color,a){s.setAttribute("type","button");let c=Nn(d,t.formatValue??se);s.setAttribute("aria-label",c),s.setAttribute("title",c),d.matches===0&&s.setAttribute("aria-disabled","true"),s.addEventListener("click",()=>{d.matches!==0&&(this.activeBucket=this.activeBucket===d.index?null:d.index,this.applyInteractionState())}),this.swatchEls.push(s)}l.append(s)}let u=N("span");if(u.textContent=i,r.append(o,l,u),this.derived.visibleReferenceRegions.length>0){let d=N("i",{class:`india-choropleth__reference-key${t.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),s=N("span");s.textContent=t.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",r.append(d,s)}this.insightsEl?this.rootEl.insertBefore(r,this.insightsEl):this.rootEl.append(r),this.legendEl=r,a&&r.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),this.activeBucket=null,this.applyInteractionState())}),this.applyLegendState()}renderInsights(){let t=this.options;if(this.insightsEl&&(this.insightsEl.remove(),this.insightsEl=null),!t.renderInsights)return;let n=N("aside",{class:"india-choropleth__insights","aria-live":"polite"});t.renderInsights(this.computeInsightContext(),n),this.rootEl.append(n),this.insightsEl=n}applyInteractionState(){if(this.destroyed)return;this.derived.selected=this.derived.regions.find(n=>n.id===this.activeSelectedId)??null,this.derived.inspected=this.derived.regions.find(n=>n.id===this.inspectedId)??null;let t=this.options.interactive!==!1;for(let[n,i]of this.pathRefs){let r=n===this.derived.inspected?.id,o=n===this.derived.selected?.id;i.classList.toggle("india-choropleth__region--inspected",r),i.classList.toggle("india-choropleth__region--selected",o),t&&(i.setAttribute("aria-pressed",o?"true":"false"),r?i.setAttribute("aria-describedby",this.tooltipId):i.removeAttribute("aria-describedby"))}for(let{el:n,bucket:i}of this.bucketEls)n.classList.toggle("india-choropleth__dimmed",this.activeBucket!==null&&i!==this.activeBucket);this.svgRootEl?.classList.toggle("india-choropleth__svg--filtered",this.activeBucket!==null),this.applyLegendState(),this.renderSelectionRing(),this.renderTooltip(),this.renderInsights(),this.options.onInsight?.(this.computeInsightContext())}applyLegendState(){if(this.legendEl)for(let[t,n]of this.swatchEls.entries()){let i=this.activeBucket===t;n.classList.toggle("india-choropleth__swatch--active",i),n.classList.toggle("india-choropleth__swatch--muted",this.activeBucket!==null&&!i),n.setAttribute("aria-pressed",i?"true":"false")}}renderTooltip(){if(!this.tooltipAnchorEl||!this.tooltipContentEl)return;let t=this.derived.inspected;if(!t){this.tooltipAnchorEl.style.display="none";return}let n=this.toTooltipContext(t);this.tooltipAnchorEl.style.display="",this.tooltipAnchorEl.style.left=`${t.centroid[0]/U.width*100}%`,this.tooltipAnchorEl.style.top=`${t.centroid[1]/U.height*100}%`,this.tooltipContentEl.textContent="";let i=this.options.renderTooltip?this.options.renderTooltip(n):Xi(n,this.options.formatValue??se);Ji(this.tooltipContentEl,i),this.positionTooltip()}renderSelectionRing(){let t=this.selectionGroupEl;if(!t)return;let n=this.derived.selected;if(!n){t.style.display="none";return}t.style.display="";for(let i of this.selectionPathEls)i.setAttribute("d",n.path);t.classList.toggle("india-choropleth__selection--lifted",n.id===this.derived.inspected?.id)}positionTooltip(){let t=this.tooltipAnchorEl;if(!t)return;t.style.removeProperty("--india-map-tooltip-dx"),t.style.removeProperty("--india-map-tooltip-dy");let n=t.getBoundingClientRect(),i=this.canvasEl.getBoundingClientRect();if(n.width===0||i.width===0)return;let{dx:r,side:o}=jn(n,i,Yn);r!==0&&t.style.setProperty("--india-map-tooltip-dx",`${Math.round(r)}px`),o==="below"&&t.style.setProperty("--india-map-tooltip-dy",`${Yn}px`)}toTooltipContext(t){let n=this.derived.regions.filter(r=>r.value!==null),i=t.value===null?null:n.filter(r=>(r.value??0)>(t.value??0)).length+1;return{...t,level:this.derived.level,total:this.derived.total,share:t.value===null||this.derived.total===0?null:t.value/this.derived.total*100,rank:i,rankedCount:n.length}}computeInsightContext(){let t=this.derived.inspected??this.derived.selected;return t?{...this.toTooltipContext(t),selected:t.id===this.derived.selected?.id}:null}};var de="https://cdn.jsdelivr.net/gh/shashankbudem/bharat-choropleth@v0.3.0/data/generated",ti="State/UT, district and sub-district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).";function He(e){return e.replace(/\/+$/,"")}function ei(e){return`${He(e)}/current-2019-states/states.topo.json`}function Zi(e,t){return`${He(e)}/current-2019-districts/districts/${t}.topo.json`}function Qi(e,t){return`${He(e)}/current-2019-subdistricts/subdistricts/${t}.topo.json`}async function ni(e,t){if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let n=await fetch(e,{signal:t});if(!n.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${e} (HTTP ${n.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return n.json()}function ce(e,t){if(!e||typeof e!="object")throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.");let n=e;if(n.type==="FeatureCollection"||"topology"in n&&"object"in n)return e;if(n.type==="Topology"&&n.objects&&typeof n.objects=="object"){let i=n.objects,r=t in i?t:Object.keys(i)[0];if(!r)throw new Error("BharatChoropleth: the TopoJSON topology contains no objects.");return{topology:e,object:r}}throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.")}async function ii(e,t,n){return typeof e=="string"?ce(await ni(e,n),t):e instanceof Promise?ce(await e,t):e}function ri(e){return typeof e=="object"&&e!==null&&!(e instanceof Promise)}async function oi(e,t,n){return ce(await ni(Zi(e,t),n),"districts")}async function ai(e,t,n){let i=Qi(e,t);if(typeof fetch!="function")throw new Error("BharatChoropleth: no global fetch is available, so boundary data cannot be downloaded. Pass `geometry` with data you loaded yourself.");let r=await fetch(i,{signal:n});if(r.status===404)return null;if(!r.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${i} (HTTP ${r.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return ce(await r.json(),"subdistricts")}var Ue=[{id:"in-cs-01-jammu-and-kashmir",name:"Jammu & Kashmir",slug:"jammu-and-kashmir"},{id:"in-cs-02-himachal-pradesh",name:"Himachal Pradesh",slug:"himachal-pradesh"},{id:"in-cs-03-punjab",name:"Punjab",slug:"punjab"},{id:"in-cs-04-chandigarh",name:"Chandigarh",slug:"chandigarh"},{id:"in-cs-05-uttarakhand",name:"Uttarakhand",slug:"uttarakhand"},{id:"in-cs-06-haryana",name:"Haryana",slug:"haryana"},{id:"in-cs-07-delhi",name:"Delhi",slug:"delhi"},{id:"in-cs-08-rajasthan",name:"Rajasthan",slug:"rajasthan"},{id:"in-cs-09-uttar-pradesh",name:"Uttar Pradesh",slug:"uttar-pradesh"},{id:"in-cs-10-bihar",name:"Bihar",slug:"bihar"},{id:"in-cs-11-sikkim",name:"Sikkim",slug:"sikkim"},{id:"in-cs-12-arunachal-pradesh",name:"Arunachal Pradesh",slug:"arunachal-pradesh"},{id:"in-cs-13-nagaland",name:"Nagaland",slug:"nagaland"},{id:"in-cs-14-manipur",name:"Manipur",slug:"manipur"},{id:"in-cs-15-mizoram",name:"Mizoram",slug:"mizoram"},{id:"in-cs-16-tripura",name:"Tripura",slug:"tripura"},{id:"in-cs-17-meghalaya",name:"Meghalaya",slug:"meghalaya"},{id:"in-cs-18-assam",name:"Assam",slug:"assam"},{id:"in-cs-19-west-bengal",name:"West Bengal",slug:"west-bengal"},{id:"in-cs-20-jharkhand",name:"Jharkhand",slug:"jharkhand"},{id:"in-cs-21-odisha",name:"Odisha",slug:"odisha"},{id:"in-cs-22-chhattisgarh",name:"Chhattisgarh",slug:"chhattisgarh"},{id:"in-cs-23-madhya-pradesh",name:"Madhya Pradesh",slug:"madhya-pradesh"},{id:"in-cs-24-gujarat",name:"Gujarat",slug:"gujarat"},{id:"in-cs-26-dadra-and-nagar-haveli-and-daman-and-diu",name:"Dadra and Nagar Haveli and Daman and Diu",slug:"dadra-and-nagar-haveli-and-daman-and-diu"},{id:"in-cs-27-maharashtra",name:"Maharashtra",slug:"maharashtra"},{id:"in-cs-28-andhra-pradesh",name:"Andhra Pradesh",slug:"andhra-pradesh"},{id:"in-cs-29-karnataka",name:"Karnataka",slug:"karnataka"},{id:"in-cs-30-goa",name:"Goa",slug:"goa"},{id:"in-cs-31-lakshadweep",name:"Lakshadweep",slug:"lakshadweep"},{id:"in-cs-32-kerala",name:"Kerala",slug:"kerala"},{id:"in-cs-33-tamil-nadu",name:"Tamil Nadu",slug:"tamil-nadu"},{id:"in-cs-34-puducherry",name:"Puducherry",slug:"puducherry"},{id:"in-cs-35-andaman-and-nicobar",name:"Andaman & Nicobar",slug:"andaman-and-nicobar"},{id:"in-cs-36-telangana",name:"Telangana",slug:"telangana"},{id:"in-cs-37-ladakh",name:"Ladakh",slug:"ladakh"}],tr={orissa:"odisha",pondicherry:"puducherry",uttaranchal:"uttarakhand","nct-of-delhi":"delhi","new-delhi":"delhi","delhi-nct":"delhi","jammu-kashmir":"jammu-and-kashmir","j-and-k":"jammu-and-kashmir",jk:"jammu-and-kashmir","andaman-nicobar":"andaman-and-nicobar","andaman-and-nicobar-islands":"andaman-and-nicobar","dadra-and-nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu","daman-and-diu":"dadra-and-nagar-haveli-and-daman-and-diu",dnhdd:"dadra-and-nagar-haveli-and-daman-and-diu","nagar-haveli":"dadra-and-nagar-haveli-and-daman-and-diu"};function st(e){return e.toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ve(e){return e.replace(/-/g,"")}var wt=new Map,Ot=new Map;for(let e of Ue)for(let t of[e.slug,st(e.name),e.id]){wt.has(t)||wt.set(t,e);let n=Ve(t);Ot.has(n)||Ot.set(n,e)}for(let[e,t]of Object.entries(tr)){let n=wt.get(t);if(!n)continue;wt.has(e)||wt.set(e,n);let i=Ve(e);Ot.has(i)||Ot.set(i,n)}function Q(e){let t=st(e);return wt.get(t)??Ot.get(Ve(t))}function si(e,t){if(!e.includes("_"))return;let n=e.replace(/_([a-z])/g,(i,r)=>r.toUpperCase());return n!==e&&n in t?n:void 0}function ci(e){return typeof e=="object"&&e!==null&&e.nodeType===1}var li=["#bharat-choropleth","#map"];function er(e){if(ci(e))return e;if(typeof e=="string"){let t=document.querySelector(e);if(t)return t;throw new Error(`BharatChoropleth: container "${e}" was not found.`)}for(let t of li){let n=document.querySelector(t);if(n)return n}throw new Error(`BharatChoropleth: no container given and none of ${li.join(", ")} exist. Pass an element or selector: new BharatChoropleth("#map").`)}var Gt=class{ready;engineInstance=null;containerEl;options;dataBaseUrl;usingDefaultData;values=new Map;exactKeys=new Map;labelByKey=new Map;writtenAs=new Map;statesAccessor;abortController;getId;getLabel;loadingEl=null;destroyed=!1;_fontColor;_borderColor;_borderWidth;_selectionWidth;_colorScale;constructor(t,n={}){let r=typeof t=="object"&&t!==null&&!ci(t)?{...t}:{...n,container:t??n.container};this.options=r,this.containerEl=er(r.container),this.dataBaseUrl=r.dataBaseUrl??de,this.usingDefaultData=r.geometry===void 0,this.getId=r.getId??(o=>String(o.properties?.id??o.properties?.name)),this.getLabel=r.getLabel??(o=>String(o.properties?.name??o.properties?.id));for(let[o,a]of Object.entries(r.values??{})){let l=this.keyFor(o);this.values.set(l,a),this.exactKeys.set(o,l),this.writtenAs.set(l,o)}return this._colorScale=r.colorScale,this._fontColor=r.fontColor,this._borderColor=r.borderColor,this._borderWidth=r.borderWidth,this._selectionWidth=r.selectionWidth,this.statesAccessor=new Proxy({},{get:(o,a)=>typeof a=="string"?this.getValue(a):void 0,has:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a)),ownKeys:()=>[...new Set(this.labelByKey.values())],getOwnPropertyDescriptor:(o,a)=>typeof a=="string"&&this.values.has(this.keyFor(a))?{enumerable:!0,configurable:!0,value:this.getValue(a)}:void 0,set:(o,a,l)=>typeof a!="string"?!1:(this.setValue(a,l),!0)}),ri(r.geometry)?(this.abortController=null,this.ready=Promise.resolve(this),this.mount(r.geometry)):(this.abortController=typeof AbortController=="function"?new AbortController:null,this.showLoading(),this.ready=ii(r.geometry??ei(this.dataBaseUrl),"states",this.abortController?.signal).then(o=>this.destroyed?this.proxied??this:(this.mount(o),this.proxied??this)).catch(o=>{if(this.destroyed||o.name==="AbortError")return this.proxied??this;throw this.showError(o),o}),this.ready.catch(()=>{})),this.proxied=new Proxy(this,{get:(o,a,l)=>{if(typeof a=="string"&&!(a in o)){let u=si(a,o);return u?Reflect.get(o,u,l):this.getValue(a)}return Reflect.get(o,a,l)},set:(o,a,l,u)=>{if(typeof a=="string"&&!(a in o)){let d=si(a,o);return d?Reflect.set(o,d,l,u):(this.setValue(a,l),!0)}return Reflect.set(o,a,l,u)}}),this.proxied}proxied;keyFor(t){return Q(t)?.id??st(t)}keysForFeature(t){let n=this.getId(t),i=this.getLabel(t);return[n,i,Q(n)?.id,Q(i)?.id,st(n),st(i)].filter(r=>typeof r=="string"&&r.length>0)}keyForFeature(t){let n=this.getId(t);return Q(n)?.id??Q(this.getLabel(t))?.id??st(this.getLabel(t))}getValue(t){return this.values.get(this.keyFor(t))??null}valueForFeature(t,n){for(let i of[this.exactKeys.get(t),this.exactKeys.get(n),Q(t)?.id,Q(n)?.id,st(t),st(n)])if(i!==void 0&&this.values.has(i))return this.values.get(i)??null;return null}setValue(t,n){let i=this.keyFor(t);this.values.set(i,n),this.exactKeys.set(t,i),this.writtenAs.has(i)||this.writtenAs.set(i,t),this.engineInstance&&(this.labelByKey.has(i)?this.engineInstance.update({}):this.warnUnknown(t))}warnUnknown(t){console.warn(`BharatChoropleth: "${t}" is not a recognized state/UT \u2014 its value is ignored.`)}mount(t){this.clearPlaceholder();for(let y of Z(t).features){let x=this.getLabel(y),E=this.keyForFeature(y);for(let P of this.keysForFeature(y))this.labelByKey.set(P,x);this.labelByKey.set(E,x),this.values.has(E)||this.values.set(E,null)}for(let[y,x]of this.values)!this.labelByKey.has(y)&&x!==null&&this.warnUnknown(this.writtenAs.get(y)??y);let{container:n,geometry:i,dataBaseUrl:r,districts:o,subDistricts:a,getId:l,getLabel:u,values:d,fontColor:s,borderColor:c,borderWidth:h,selectionWidth:p,colorScale:f,onReady:S,onError:w,...m}=this.options,b=o??this.usingDefaultData,v=a??this.usingDefaultData;this.engineInstance=new ht(this.containerEl,{...m,colorScale:f,loadDistricts:m.loadDistricts??(b?this.defaultDistrictLoader:void 0),loadSubDistricts:m.loadSubDistricts??(v?this.defaultSubDistrictLoader:void 0),states:{geometry:t,getId:this.getId,getLabel:this.getLabel,getValue:y=>this.valueForFeature(this.getId(y),this.getLabel(y))}}),this._fontColor&&this.mapRootEl.style.setProperty("--india-map-text",this._fontColor),this._borderColor&&this.mapRootEl.style.setProperty("--india-map-stroke",this._borderColor),this._borderWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-border-width",String(this._borderWidth)),this._selectionWidth!==void 0&&this.mapRootEl.style.setProperty("--india-map-selection-width",String(this._selectionWidth)),S?.(this.proxied??this)}defaultDistrictLoader=async t=>({geometry:await oi(this.dataBaseUrl,t,this.abortController?.signal),getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.valueForFeature(String(i.properties?.id??""),this.getLabel(i))});defaultSubDistrictLoader=async t=>{let n=await ai(this.dataBaseUrl,t,this.abortController?.signal);return n?{geometry:n,getId:i=>String(i.properties?.id??i.properties?.name),getLabel:i=>String(i.properties?.name??i.properties?.id),getValue:i=>this.valueForFeature(String(i.properties?.id??""),this.getLabel(i))}:null};showLoading(){this.loadingEl=document.createElement("div"),this.loadingEl.className="bharat-choropleth__status",this.loadingEl.setAttribute("role","status"),this.loadingEl.textContent="Loading map\u2026",this.containerEl.appendChild(this.loadingEl)}showError(t){this.clearPlaceholder();let n=document.createElement("div");n.className="bharat-choropleth__status bharat-choropleth__status--error",n.setAttribute("role","alert"),n.textContent=t.message,this.containerEl.appendChild(n),this.loadingEl=n,this.options.onError?this.options.onError(t):console.error(t)}clearPlaceholder(){this.loadingEl?.remove(),this.loadingEl=null}get engine(){return this.engineInstance}get states(){return this.statesAccessor}setValues(t){for(let[n,i]of Object.entries(t)){let r=this.keyFor(n);this.values.set(r,i),this.exactKeys.set(n,r),this.writtenAs.has(r)||this.writtenAs.set(r,n),this.engineInstance&&!this.labelByKey.has(r)&&this.warnUnknown(n)}this.engineInstance?.update({})}getValues(){let t={};for(let[n,i]of this.labelByKey)t[i]=this.values.get(n)??null;return t}get mapRootEl(){return this.containerEl.querySelector(".india-choropleth")??this.containerEl}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-text",t):this.mapRootEl.style.removeProperty("--india-map-text"))}get borderColor(){return this._borderColor}set borderColor(t){this._borderColor=t,this.engineInstance&&(t?this.mapRootEl.style.setProperty("--india-map-stroke",t):this.mapRootEl.style.removeProperty("--india-map-stroke"))}get borderWidth(){return this._borderWidth}set borderWidth(t){this._borderWidth=t,this.setWidthVar("--india-map-border-width",t)}get selectionWidth(){return this._selectionWidth}set selectionWidth(t){this._selectionWidth=t,this.setWidthVar("--india-map-selection-width",t)}setWidthVar(t,n){this.engineInstance&&(n===void 0?this.mapRootEl.style.removeProperty(t):this.mapRootEl.style.setProperty(t,String(n)))}get colorScale(){return this._colorScale}set colorScale(t){this._colorScale=t,this.options.colorScale=t,this.engineInstance?.update({colorScale:t})}select(t){this.engineInstance?.select(t)}drillDown(t){let n=t===null?null:Q(t)?.id??t;this.engineInstance?.drillDown(n)}drillDownSubDistrict(t){this.engineInstance?.drillDownSubDistrict(t)}getSelected(){return this.engineInstance?.getSelected()??null}getInspected(){return this.engineInstance?.getInspected()??null}destroy(){this.destroyed=!0,this.abortController?.abort(),this.clearPlaceholder(),this.engineInstance?.destroy(),this.engineInstance=null}};var di="bharat-choropleth-styles";function ui(){if(typeof document>"u"||document.getElementById(di))return;let e=document.createElement("style");e.id=di,e.textContent=We,document.head.appendChild(e)}ui();var Ke=globalThis;Ke.BharatChoropleth=Gt;Ke.IndiaChoropleth=ht;Ke.BharatChoroplethLib={BharatChoropleth:Gt,IndiaChoropleth:ht,STATES:Ue,resolveState:Q,ATTRIBUTION:ti,DEFAULT_DATA_BASE_URL:de,injectStyles:ui};})();
126
126
  //# sourceMappingURL=bharat-choropleth.min.js.map