bharat-choropleth-js 0.1.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 ADDED
@@ -0,0 +1,69 @@
1
+ # Changelog
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
+
44
+ ## 0.2.0
45
+
46
+ - Added an optional sub-district level below districts — tehsils, taluks,
47
+ mandals and blocks. On `IndiaChoropleth`, `loadSubDistricts` is called only
48
+ after a district is activated, with `subDistrictDrillDownId` and
49
+ `onSubDistrictDrillDownChange` to drive it from outside.
50
+ - A `loadSubDistricts` that resolves `null` marks that district a leaf: the map
51
+ stays on the district view and selects it rather than opening an empty level,
52
+ and the district is not asked again. Omit the option and every district stays
53
+ a leaf, exactly as before.
54
+ - The zero-config `BharatChoropleth` gained `subDistricts`, which defaults to on
55
+ when the map is using the bundled data source and off when you supply your own
56
+ geometry — the same rule `districts` already follows.
57
+ - `drillDown(null)` returns to the national map from any depth. It is the
58
+ state-level control, so it does not merely step back one level.
59
+ - Exported `MapLevel` and `SubDistrictLoader`.
60
+ - **Possibly breaking for TypeScript callers:** `level` on `TooltipContext` and
61
+ `InsightContext` widened from `"state" | "district"` to `MapLevel`, which adds
62
+ `"subdistrict"`. A `switch` over it that the compiler checks for
63
+ exhaustiveness now needs the third case. Nothing changes at runtime for a
64
+ two-level map.
65
+
66
+ ## 0.1.0
67
+
68
+ - Initial public release of the framework-free India state and district
69
+ choropleth renderer.
package/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # `bharat-choropleth-js`
2
2
 
3
- An accessible SVG India state-to-district choropleth with no framework dependency. Drop one `<script>` tag into any HTML page, or import it as an ES module from a bundler. Same behavior, CSS classes, and stylesheet as the React [`bharat-choropleth`](https://www.npmjs.com/package/bharat-choropleth) package.
3
+ An accessible SVG India state-to-district-to-sub-district choropleth with no framework dependency. Drop one `<script>` tag into any HTML page, or import it as an ES module from a bundler. Same behavior, CSS classes, and stylesheet as the React [`bharat-choropleth`](https://www.npmjs.com/package/bharat-choropleth) package.
4
+
5
+ ![Bharat Choropleth national map](https://raw.githubusercontent.com/shashankbudem/bharat-choropleth/main/previews/country-desktop.png)
4
6
 
5
7
  ## One script tag
6
8
 
7
9
  ```html
8
10
  <div id="map"></div>
9
11
 
10
- <script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/bharat-choropleth-js@0.2.0"></script>
11
13
  <script>
12
14
  var map = new BharatChoropleth("#map");
13
15
 
@@ -26,7 +28,7 @@ That's the whole setup. No stylesheet link, no build step, no `await`, no bounda
26
28
  - **The script tag injects its own CSS.** (Bundler users import `bharat-choropleth-js/style.css` instead, so their pipeline can extract and hash it — see [From a bundler](#from-a-bundler).)
27
29
  - **Boundary data is fetched, not bundled.** The package ships no geometry; the prepared current-vintage state bundle is downloaded from `dataBaseUrl` on construction. Set `dataBaseUrl` to self-host — see [Boundary data](#boundary-data).
28
30
  - **Values set before the data arrives are applied when it arrives.** Every line above runs while the download is still in flight; nothing is dropped and nothing needs awaiting. `map.ready` is a promise if you want one.
29
- - **Clicking a state drills into its districts**, fetched from the same base URL. Pass `districts: false` to turn that off.
31
+ - **Clicking a state drills into its districts**, and a district into its sub-districts (tehsils / taluks / mandals / blocks), fetched from the same base URL. Pass `districts: false` or `subDistricts: false` to turn either off.
30
32
 
31
33
  See the [complete example](https://github.com/shashankbudem/bharat-choropleth/tree/main/packages/js/example) in the repository. To run it locally, serve the **repo root** over HTTP (`npx serve`), then open `/packages/js/example/bharat-choropleth.html`.
32
34
 
@@ -66,6 +68,7 @@ var map = new BharatChoropleth({ container: "#map", showRegionValues: true });
66
68
  | `geometry` | fetched from `dataBaseUrl` | Inline GeoJSON/TopoJSON, a URL string, or a promise of either. |
67
69
  | `dataBaseUrl` | jsDelivr copy of `data/generated` | Base URL for the prepared bundles. Point at your own copy to self-host. |
68
70
  | `districts` | `true` with default data, else `false` | Click-to-drill-down into districts. |
71
+ | `subDistricts` | `true` with default data, else `false` | Click-to-drill-down from a district into its sub-districts. Districts the bundle has none for stay leaves. |
69
72
  | `fontColor` / `borderColor` | — | Sets the `--india-map-text` / `--india-map-stroke` CSS variables. |
70
73
  | `borderWidth` | `2.5` | Region border thickness in px. Sets `--india-map-border-width`. |
71
74
  | `selectionWidth` | `3` | Selection ring thickness in px; its halo is drawn at twice this. Sets `--india-map-selection-width`. |
@@ -88,7 +91,7 @@ Every thickness is a CSS variable, so you can theme without touching the rendere
88
91
 
89
92
  Every other [`IndiaChoroplethOptions`](https://github.com/shashankbudem/bharat-choropleth/blob/main/packages/js/src/types.ts) field (`referenceOverlay`, `loadDistricts`, `onRegionClick`, `formatValue`, `renderTooltip`, `showLegend`, ...) is accepted and forwarded.
90
93
 
91
- Methods: `setValues`, `getValues`, `select(id)`, `drillDown(name | null)`, `getSelected()`, `getInspected()`, `destroy()`. The full engine is at `map.engine` (`null` until the data loads — `await map.ready` first).
94
+ Methods: `setValues`, `getValues`, `select(id)`, `drillDown(name | null)`, `drillDownSubDistrict(id | null)`, `getSelected()`, `getInspected()`, `destroy()`. The full engine is at `map.engine` (`null` until the data loads — `await map.ready` first).
92
95
 
93
96
  ## Hover and focus detail
94
97
 
@@ -112,9 +115,9 @@ var map = new BharatChoropleth("#map", {
112
115
 
113
116
  The package deliberately bundles no geographic boundaries; it downloads them. By default that means the prepared bundles in this repo's `data/generated`, served over jsDelivr, which must be attributed as:
114
117
 
115
- > State/UT and district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).
118
+ > State/UT, district and sub-district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).
116
119
 
117
- For production, offline or air-gapped use, copy `data/generated/current-2019-states/` and `data/generated/current-2019-districts/` next to your app and point at them — no third-party CDN request at runtime:
120
+ For production, offline or air-gapped use, copy `data/generated/current-2019-states/`, `data/generated/current-2019-districts/` and `data/generated/current-2019-subdistricts/` next to your app and point at them — no third-party CDN request at runtime:
118
121
 
119
122
  ```js
120
123
  var map = new BharatChoropleth("#map", { dataBaseUrl: "/maps" });
@@ -142,7 +145,18 @@ const map = new BharatChoropleth("#map");
142
145
  map.states["Goa"] = 6;
143
146
  ```
144
147
 
145
- 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
+ ```
146
160
 
147
161
  ## `IndiaChoropleth` (full-featured engine)
148
162
 
@@ -164,10 +178,13 @@ It requires an explicit `states` layer with `getId`/`getLabel`/`getValue` access
164
178
  - `update(partialOptions)` — merge new options (new data, controlled `selectedId`/`drillDownId`, swapped callbacks) and re-render.
165
179
  - `select(id | null)` — select a region at the current level without changing drill-down.
166
180
  - `drillDown(id | null)` — drill into a state, or pass `null` to return to the state view.
181
+ - `drillDownSubDistrict(id | null)` — drill into a district's sub-districts, or pass `null` to return to the district view. Only meaningful while a state is drilled into, so its district layer has to have loaded first.
167
182
  - `getSelected()` / `getInspected()` — read the current `MapRegion | null`.
168
183
  - `destroy()` — remove all DOM content and cancel any in-flight loads. Call this before discarding the instance.
169
184
 
170
- Controlled vs. uncontrolled state works the same way as the React version: pass `selectedId`/`drillDownId` (and keep passing them via `update()`) for controlled usage, or `defaultSelectedId`/`defaultDrillDownId` to let the instance manage its own.
185
+ Controlled vs. uncontrolled state works the same way as the React version: pass `selectedId`/`drillDownId`/`subDistrictDrillDownId` (and keep passing them via `update()`) for controlled usage, or `defaultSelectedId`/`defaultDrillDownId`/`defaultSubDistrictDrillDownId` to let the instance manage its own. A district id means nothing outside the state it came from, so changing `drillDownId` clears the level below it.
186
+
187
+ `loadSubDistricts` may return `null` for a district with no sub-district level; that district is left as a leaf rather than opening an empty view, and stops offering the level once it has answered.
171
188
 
172
189
  ## Design notes
173
190
 
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var Ut=`.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(e){let n=this._partials,r=0;for(let i=0;i<this._n&&i<32;i++){let o=n[i],a=e+o,l=Math.abs(e)<Math.abs(o)?e-(a-o):o-(a-e);l&&(n[r++]=l),e=a}return n[r]=e,this._n=r+1,this}valueOf(){let e=this._partials,n=this._n,r,i,o,a=0;if(n>0){for(a=e[--n];n>0&&(r=a,i=e[--n],a=r+i,o=i-(a-r),!o););n>0&&(o<0&&e[n-1]<0||o>0&&e[n-1]>0)&&(i=o*2,r=a+i,i==r-a&&(a=r))}return a}};function*hr(t){for(let e of t)yield*e}function pe(t){return Array.from(hr(t))}var P=1e-6,Vt=1e-12,I=Math.PI,$=I/2,dt=I/4,q=I*2,U=180/I,B=I/180,M=Math.abs,je=Math.atan,re=Math.atan2,D=Math.cos;var Wt=Math.exp;var Kt=Math.log;var T=Math.sin,Yt=Math.sign||function(t){return t>0?1:t<0?-1:0},Y=Math.sqrt,Xt=Math.tan;function Jt(t){return t>1?0:t<-1?I:Math.acos(t)}function ie(t){return t>1?$:t<-1?-$:Math.asin(t)}function z(){}function $e(t,e){t&&Qt.hasOwnProperty(t.type)&&Qt[t.type](t,e)}var Zt={Feature:function(t,e){$e(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,i=n.length;++r<i;)$e(n[r].geometry,e)}},Qt={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)t=n[r],e.point(t[0],t[1],t[2])},LineString:function(t,e){ut(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)ut(n[r],e,0)},Polygon:function(t,e){en(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)en(n[r],e)},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,i=n.length;++r<i;)$e(n[r],e)}};function ut(t,e,n){var r=-1,i=t.length-n,o;for(e.lineStart();++r<i;)o=t[r],e.point(o[0],o[1],o[2]);e.lineEnd()}function en(t,e){var n=-1,r=t.length;for(e.polygonStart();++n<r;)ut(t[n],e,1);e.polygonEnd()}function ae(t,e){t&&Zt.hasOwnProperty(t.type)?Zt[t.type](t,e):$e(t,e)}function we(t){return[re(t[1],t[0]),ie(t[2])]}function Z(t){var e=t[0],n=t[1],r=D(n);return[r*D(e),r*T(e),T(n)]}function Se(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function fe(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function qe(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function _e(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function ke(t){var e=Y(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}function Ie(t,e){function n(r,i){return r=t(r,i),e(r[0],r[1])}return t.invert&&e.invert&&(n.invert=function(r,i){return r=e.invert(r,i),r&&t.invert(r[0],r[1])}),n}function ht(t,e){return M(t)>I&&(t-=Math.round(t/q)*q),[t,e]}ht.invert=ht;function pt(t,e,n){return(t%=q)?e||n?Ie(nn(t),rn(e,n)):nn(t):e||n?rn(e,n):ht}function tn(t){return function(e,n){return e+=t,M(e)>I&&(e-=Math.round(e/q)*q),[e,n]}}function nn(t){var e=tn(t);return e.invert=tn(-t),e}function rn(t,e){var n=D(t),r=T(t),i=D(e),o=T(e);function a(l,h){var d=D(h),s=D(l)*d,c=T(l)*d,u=T(h),p=u*n+s*r;return[re(c*i-p*o,s*n-u*r),ie(p*i+c*o)]}return a.invert=function(l,h){var d=D(h),s=D(l)*d,c=T(l)*d,u=T(h),p=u*i-c*o;return[re(c*i+u*o,s*n+p*r),ie(p*n-s*r)]},a}function on(t){t=pt(t[0]*B,t[1]*B,t.length>2?t[2]*B:0);function e(n){return n=t(n[0]*B,n[1]*B),n[0]*=U,n[1]*=U,n}return e.invert=function(n){return n=t.invert(n[0]*B,n[1]*B),n[0]*=U,n[1]*=U,n},e}function sn(t,e,n,r,i,o){if(n){var a=D(e),l=T(e),h=r*n;i==null?(i=e+r*q,o=e-h/2):(i=an(a,i),o=an(a,o),(r>0?i<o:i>o)&&(i+=r*q));for(var d,s=i;r>0?s>o:s<o;s-=h)d=we([a,-l*D(s),-l*T(s)]),t.point(d[0],d[1])}}function an(t,e){e=Z(e),e[0]-=t,ke(e);var n=Jt(-e[1]);return((-e[2]<0?-n:n)+q-P)%q}function ze(){var t=[],e;return{point:function(n,r,i){e.push([n,r,i])},lineStart:function(){t.push(e=[])},lineEnd:z,rejoin:function(){t.length>1&&t.push(t.pop().concat(t.shift()))},result:function(){var n=t;return t=[],e=null,n}}}function me(t,e){return M(t[0]-e[0])<P&&M(t[1]-e[1])<P}function He(t,e,n,r){this.x=t,this.z=e,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}function Ue(t,e,n,r,i){var o=[],a=[],l,h;if(t.forEach(function(f){if(!((m=f.length-1)<=0)){var m,v=f[0],b=f[m],y;if(me(v,b)){if(!v[2]&&!b[2]){for(i.lineStart(),l=0;l<m;++l)i.point((v=f[l])[0],v[1]);i.lineEnd();return}b[0]+=2*P}o.push(y=new He(v,f,null,!0)),a.push(y.o=new He(v,null,y,!1)),o.push(y=new He(b,f,null,!1)),a.push(y.o=new He(b,null,y,!0))}}),!!o.length){for(a.sort(e),ln(o),ln(a),l=0,h=a.length;l<h;++l)a[l].e=n=!n;for(var d=o[0],s,c;;){for(var u=d,p=!0;u.v;)if((u=u.n)===d)return;s=u.z,i.lineStart();do{if(u.v=u.o.v=!0,u.e){if(p)for(l=0,h=s.length;l<h;++l)i.point((c=s[l])[0],c[1]);else r(u.x,u.n.x,1,i);u=u.n}else{if(p)for(s=u.p.z,l=s.length-1;l>=0;--l)i.point((c=s[l])[0],c[1]);else r(u.x,u.p.x,-1,i);u=u.p}u=u.o,s=u.z,p=!p}while(!u.v);i.lineEnd()}}}function ln(t){if(e=t.length){for(var e,n=0,r=t[0],i;++n<e;)r.n=i=t[n],i.p=r,r=i;r.n=i=t[0],i.p=r}}function ft(t){return M(t[0])<=I?t[0]:Yt(t[0])*((M(t[0])+I)%q-I)}function cn(t,e){var n=ft(e),r=e[1],i=T(r),o=[T(n),-D(n),0],a=0,l=0,h=new K;i===1?r=$+P:i===-1&&(r=-$-P);for(var d=0,s=t.length;d<s;++d)if(u=(c=t[d]).length)for(var c,u,p=c[u-1],f=ft(p),m=p[1]/2+dt,v=T(m),b=D(m),y=0;y<u;++y,f=E,v=k,b=L,p=x){var x=c[y],E=ft(x),w=x[1]/2+dt,k=T(w),L=D(w),S=E-f,C=S>=0?1:-1,O=C*S,_=O>I,V=v*k;if(h.add(re(V*C*T(O),b*L+V*D(O))),a+=_?S+C*q:S,_^f>=n^E>=n){var F=fe(Z(p),Z(x));ke(F);var A=fe(o,F);ke(A);var g=(_^S>=0?-1:1)*ie(A[2]);(r>g||r===g&&(F[0]||F[1]))&&(l+=_^S>=0?1:-1)}}return(a<-P||a<P&&h<-Vt)^l&1}function Ve(t,e,n,r){return function(i){var o=e(i),a=ze(),l=e(a),h=!1,d,s,c,u={point:p,lineStart:m,lineEnd:v,polygonStart:function(){u.point=b,u.lineStart=y,u.lineEnd=x,s=[],d=[]},polygonEnd:function(){u.point=p,u.lineStart=m,u.lineEnd=v,s=pe(s);var E=cn(d,r);s.length?(h||(i.polygonStart(),h=!0),Ue(s,fr,E,n,i)):E&&(h||(i.polygonStart(),h=!0),i.lineStart(),n(null,null,1,i),i.lineEnd()),h&&(i.polygonEnd(),h=!1),s=d=null},sphere:function(){i.polygonStart(),i.lineStart(),n(null,null,1,i),i.lineEnd(),i.polygonEnd()}};function p(E,w){t(E,w)&&i.point(E,w)}function f(E,w){o.point(E,w)}function m(){u.point=f,o.lineStart()}function v(){u.point=p,o.lineEnd()}function b(E,w){c.push([E,w]),l.point(E,w)}function y(){l.lineStart(),c=[]}function x(){b(c[0][0],c[0][1]),l.lineEnd();var E=l.clean(),w=a.result(),k,L=w.length,S,C,O;if(c.pop(),d.push(c),c=null,!!L){if(E&1){if(C=w[0],(S=C.length-1)>0){for(h||(i.polygonStart(),h=!0),i.lineStart(),k=0;k<S;++k)i.point((O=C[k])[0],O[1]);i.lineEnd()}return}L>1&&E&2&&w.push(w.pop().concat(w.shift())),s.push(w.filter(pr))}}return u}}function pr(t){return t.length>1}function fr(t,e){return((t=t.x)[0]<0?t[1]-$-P:$-t[1])-((e=e.x)[0]<0?e[1]-$-P:$-e[1])}var mt=Ve(function(){return!0},mr,vr,[-I,-$]);function mr(t){var e=NaN,n=NaN,r=NaN,i;return{lineStart:function(){t.lineStart(),i=1},point:function(o,a){var l=o>0?I:-I,h=M(o-e);M(h-I)<P?(t.point(e,n=(n+a)/2>0?$:-$),t.point(r,n),t.lineEnd(),t.lineStart(),t.point(l,n),t.point(o,n),i=0):r!==l&&h>=I&&(M(e-r)<P&&(e-=r*P),M(o-l)<P&&(o-=l*P),n=gr(e,n,o,a),t.point(r,n),t.lineEnd(),t.lineStart(),t.point(l,n),i=0),t.point(e=o,n=a),r=l},lineEnd:function(){t.lineEnd(),e=n=NaN},clean:function(){return 2-i}}}function gr(t,e,n,r){var i,o,a=T(t-n);return M(a)>P?je((T(e)*(o=D(r))*T(n)-T(r)*(i=D(e))*T(t))/(i*o*a)):(e+r)/2}function vr(t,e,n,r){var i;if(t==null)i=n*$,r.point(-I,i),r.point(0,i),r.point(I,i),r.point(I,0),r.point(I,-i),r.point(0,-i),r.point(-I,-i),r.point(-I,0),r.point(-I,i);else if(M(t[0]-e[0])>P){var o=t[0]<e[0]?I:-I;i=n*o/2,r.point(-o,i),r.point(0,i),r.point(o,i)}else r.point(e[0],e[1])}function dn(t){var e=D(t),n=2*B,r=e>0,i=M(e)>P;function o(s,c,u,p){sn(p,t,n,u,s,c)}function a(s,c){return D(s)*D(c)>e}function l(s){var c,u,p,f,m;return{lineStart:function(){f=p=!1,m=1},point:function(v,b){var y=[v,b],x,E=a(v,b),w=r?E?0:d(v,b):E?d(v+(v<0?I:-I),b):0;if(!c&&(f=p=E)&&s.lineStart(),E!==p&&(x=h(c,y),(!x||me(c,x)||me(y,x))&&(y[2]=1)),E!==p)m=0,E?(s.lineStart(),x=h(y,c),s.point(x[0],x[1])):(x=h(c,y),s.point(x[0],x[1],2),s.lineEnd()),c=x;else if(i&&c&&r^E){var k;!(w&u)&&(k=h(y,c,!0))&&(m=0,r?(s.lineStart(),s.point(k[0][0],k[0][1]),s.point(k[1][0],k[1][1]),s.lineEnd()):(s.point(k[1][0],k[1][1]),s.lineEnd(),s.lineStart(),s.point(k[0][0],k[0][1],3)))}E&&(!c||!me(c,y))&&s.point(y[0],y[1]),c=y,p=E,u=w},lineEnd:function(){p&&s.lineEnd(),c=null},clean:function(){return m|(f&&p)<<1}}}function h(s,c,u){var p=Z(s),f=Z(c),m=[1,0,0],v=fe(p,f),b=Se(v,v),y=v[0],x=b-y*y;if(!x)return!u&&s;var E=e*b/x,w=-e*y/x,k=fe(m,v),L=_e(m,E),S=_e(v,w);qe(L,S);var C=k,O=Se(L,C),_=Se(C,C),V=O*O-_*(Se(L,L)-1);if(!(V<0)){var F=Y(V),A=_e(C,(-O-F)/_);if(qe(A,L),A=we(A),!u)return A;var g=s[0],R=c[0],j=s[1],W=c[1],X;R<g&&(X=g,g=R,R=X);var Ee=R-g,te=M(Ee-I)<P,le=te||Ee<P;if(!te&&W<j&&(X=j,j=W,W=X),le?te?j+W>0^A[1]<(M(A[0]-g)<P?j:W):j<=A[1]&&A[1]<=W:Ee>I^(g<=A[0]&&A[0]<=R)){var ne=_e(C,(-O+F)/_);return qe(ne,L),[A,we(ne)]}}}function d(s,c){var u=r?t:I-t,p=0;return s<-u?p|=1:s>u&&(p|=2),c<-u?p|=4:c>u&&(p|=8),p}return Ve(a,l,o,r?[0,-t]:[-I,t-I])}function un(t,e,n,r,i,o){var a=t[0],l=t[1],h=e[0],d=e[1],s=0,c=1,u=h-a,p=d-l,f;if(f=n-a,!(!u&&f>0)){if(f/=u,u<0){if(f<s)return;f<c&&(c=f)}else if(u>0){if(f>c)return;f>s&&(s=f)}if(f=i-a,!(!u&&f<0)){if(f/=u,u<0){if(f>c)return;f>s&&(s=f)}else if(u>0){if(f<s)return;f<c&&(c=f)}if(f=r-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&&(t[0]=a+s*u,t[1]=l+s*p),c<1&&(e[0]=a+c*u,e[1]=l+c*p),!0}}}}}var Re=1e9,We=-Re;function gt(t,e,n,r){function i(d,s){return t<=d&&d<=n&&e<=s&&s<=r}function o(d,s,c,u){var p=0,f=0;if(d==null||(p=a(d,c))!==(f=a(s,c))||h(d,s)<0^c>0)do u.point(p===0||p===3?t:n,p>1?r:e);while((p=(p+c+4)%4)!==f);else u.point(s[0],s[1])}function a(d,s){return M(d[0]-t)<P?s>0?0:3:M(d[0]-n)<P?s>0?2:1:M(d[1]-e)<P?s>0?1:0:s>0?3:2}function l(d,s){return h(d.x,s.x)}function h(d,s){var c=a(d,1),u=a(s,1);return c!==u?c-u: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=ze(),u,p,f,m,v,b,y,x,E,w,k,L={point:S,lineStart:V,lineEnd:F,polygonStart:O,polygonEnd:_};function S(g,R){i(g,R)&&s.point(g,R)}function C(){for(var g=0,R=0,j=p.length;R<j;++R)for(var W=p[R],X=1,Ee=W.length,te=W[0],le,ne,Ne=te[0],he=te[1];X<Ee;++X)le=Ne,ne=he,te=W[X],Ne=te[0],he=te[1],ne<=r?he>r&&(Ne-le)*(r-ne)>(he-ne)*(t-le)&&++g:he<=r&&(Ne-le)*(r-ne)<(he-ne)*(t-le)&&--g;return g}function O(){s=c,u=[],p=[],k=!0}function _(){var g=C(),R=k&&g,j=(u=pe(u)).length;(R||j)&&(d.polygonStart(),R&&(d.lineStart(),o(null,null,1,d),d.lineEnd()),j&&Ue(u,l,g,o,d),d.polygonEnd()),s=d,u=p=f=null}function V(){L.point=A,p&&p.push(f=[]),w=!0,E=!1,y=x=NaN}function F(){u&&(A(m,v),b&&E&&c.rejoin(),u.push(c.result())),L.point=S,E&&s.lineEnd()}function A(g,R){var j=i(g,R);if(p&&f.push([g,R]),w)m=g,v=R,b=j,w=!1,j&&(s.lineStart(),s.point(g,R));else if(j&&E)s.point(g,R);else{var W=[y=Math.max(We,Math.min(Re,y)),x=Math.max(We,Math.min(Re,x))],X=[g=Math.max(We,Math.min(Re,g)),R=Math.max(We,Math.min(Re,R))];un(W,X,t,e,n,r)?(E||(s.lineStart(),s.point(W[0],W[1])),s.point(X[0],X[1]),j||s.lineEnd(),k=!1):j&&(s.lineStart(),s.point(g,R),k=!1)}y=g,x=R,E=j}return L}}var Pe=t=>t;var vt=new K,yt=new K,hn,pn,bt,xt,se={point:z,lineStart:z,lineEnd:z,polygonStart:function(){se.lineStart=yr,se.lineEnd=xr},polygonEnd:function(){se.lineStart=se.lineEnd=se.point=z,vt.add(M(yt)),yt=new K},result:function(){var t=vt/2;return vt=new K,t}};function yr(){se.point=br}function br(t,e){se.point=fn,hn=bt=t,pn=xt=e}function fn(t,e){yt.add(xt*t-bt*e),bt=t,xt=e}function xr(){fn(hn,pn)}var Et=se;var ge=1/0,Ke=ge,Ce=-ge,Ye=Ce,Er={point:wr,lineStart:z,lineEnd:z,polygonStart:z,polygonEnd:z,result:function(){var t=[[ge,Ke],[Ce,Ye]];return Ce=Ye=-(Ke=ge=1/0),t}};function wr(t,e){t<ge&&(ge=t),t>Ce&&(Ce=t),e<Ke&&(Ke=e),e>Ye&&(Ye=e)}var ve=Er;var wt=0,St=0,Me=0,Xe=0,Je=0,ye=0,_t=0,kt=0,Le=0,vn,yn,Q,ee,J={point:ce,lineStart:mn,lineEnd:gn,polygonStart:function(){J.lineStart=kr,J.lineEnd=Ir},polygonEnd:function(){J.point=ce,J.lineStart=mn,J.lineEnd=gn},result:function(){var t=Le?[_t/Le,kt/Le]:ye?[Xe/ye,Je/ye]:Me?[wt/Me,St/Me]:[NaN,NaN];return wt=St=Me=Xe=Je=ye=_t=kt=Le=0,t}};function ce(t,e){wt+=t,St+=e,++Me}function mn(){J.point=Sr}function Sr(t,e){J.point=_r,ce(Q=t,ee=e)}function _r(t,e){var n=t-Q,r=e-ee,i=Y(n*n+r*r);Xe+=i*(Q+t)/2,Je+=i*(ee+e)/2,ye+=i,ce(Q=t,ee=e)}function gn(){J.point=ce}function kr(){J.point=Rr}function Ir(){bn(vn,yn)}function Rr(t,e){J.point=bn,ce(vn=Q=t,yn=ee=e)}function bn(t,e){var n=t-Q,r=e-ee,i=Y(n*n+r*r);Xe+=i*(Q+t)/2,Je+=i*(ee+e)/2,ye+=i,i=ee*t-Q*e,_t+=i*(Q+t),kt+=i*(ee+e),Le+=i*3,ce(Q=t,ee=e)}var It=J;function Ze(t){this._context=t}Ze.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,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(t,e){switch(this._point){case 0:{this._context.moveTo(t,e),this._point=1;break}case 1:{this._context.lineTo(t,e);break}default:{this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,q);break}}},result:z};var Pt=new K,Rt,xn,En,De,Ae,Qe={point:z,lineStart:function(){Qe.point=Pr},lineEnd:function(){Rt&&wn(xn,En),Qe.point=z},polygonStart:function(){Rt=!0},polygonEnd:function(){Rt=null},result:function(){var t=+Pt;return Pt=new K,t}};function Pr(t,e){Qe.point=wn,xn=De=t,En=Ae=e}function wn(t,e){De-=t,Ae-=e,Pt.add(Y(De*De+Ae*Ae)),De=t,Ae=e}var Ct=Qe;var Sn,et,_n,kn,be=class{constructor(e){this._append=e==null?In:Cr(e),this._radius=4.5,this._=""}pointRadius(e){return this._radius=+e,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(e,n){switch(this._point){case 0:{this._append`M${e},${n}`,this._point=1;break}case 1:{this._append`L${e},${n}`;break}default:{if(this._append`M${e},${n}`,this._radius!==_n||this._append!==et){let r=this._radius,i=this._;this._="",this._append`m0,${r}a${r},${r} 0 1,1 0,${-2*r}a${r},${r} 0 1,1 0,${2*r}z`,_n=r,et=this._append,kn=this._,this._=i}this._+=kn;break}}}result(){let e=this._;return this._="",e.length?e:null}};function In(t){let e=1;this._+=t[0];for(let n=t.length;e<n;++e)this._+=arguments[e]+t[e]}function Cr(t){let e=Math.floor(t);if(!(e>=0))throw new RangeError(`invalid digits: ${t}`);if(e>15)return In;if(e!==Sn){let n=10**e;Sn=e,et=function(i){let o=1;this._+=i[0];for(let a=i.length;o<a;++o)this._+=Math.round(arguments[o]*n)/n+i[o]}}return et}function tt(t,e){let n=3,r=4.5,i,o;function a(l){return l&&(typeof r=="function"&&o.pointRadius(+r.apply(this,arguments)),ae(l,i(o))),o.result()}return a.area=function(l){return ae(l,i(Et)),Et.result()},a.measure=function(l){return ae(l,i(Ct)),Ct.result()},a.bounds=function(l){return ae(l,i(ve)),ve.result()},a.centroid=function(l){return ae(l,i(It)),It.result()},a.projection=function(l){return arguments.length?(i=l==null?(t=null,Pe):(t=l).stream,a):t},a.context=function(l){return arguments.length?(o=l==null?(e=null,new be(n)):new Ze(e=l),typeof r!="function"&&o.pointRadius(r),a):e},a.pointRadius=function(l){return arguments.length?(r=typeof l=="function"?l:(o.pointRadius(+l),+l),a):r},a.digits=function(l){if(!arguments.length)return n;if(l==null)n=null;else{let h=Math.floor(l);if(!(h>=0))throw new RangeError(`invalid digits: ${l}`);n=h}return e===null&&(o=new be(n)),a},a.projection(t).digits(n).context(e)}function Te(t){return function(e){var n=new Mt;for(var r in t)n[r]=t[r];return n.stream=e,n}}function Mt(){}Mt.prototype={constructor:Mt,point:function(t,e){this.stream.point(t,e)},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 Lt(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),r!=null&&t.clipExtent(null),ae(n,t.stream(ve)),e(ve.result()),r!=null&&t.clipExtent(r),t}function Dt(t,e,n){return Lt(t,function(r){var i=e[1][0]-e[0][0],o=e[1][1]-e[0][1],a=Math.min(i/(r[1][0]-r[0][0]),o/(r[1][1]-r[0][1])),l=+e[0][0]+(i-a*(r[1][0]+r[0][0]))/2,h=+e[0][1]+(o-a*(r[1][1]+r[0][1]))/2;t.scale(150*a).translate([l,h])},n)}function Rn(t,e,n){return Dt(t,[[0,0],e],n)}function Pn(t,e,n){return Lt(t,function(r){var i=+e,o=i/(r[1][0]-r[0][0]),a=(i-o*(r[1][0]+r[0][0]))/2,l=-o*r[0][1];t.scale(150*o).translate([a,l])},n)}function Cn(t,e,n){return Lt(t,function(r){var i=+e,o=i/(r[1][1]-r[0][1]),a=-o*r[0][0],l=(i-o*(r[1][1]+r[0][1]))/2;t.scale(150*o).translate([a,l])},n)}var Mn=16,Mr=D(30*B);function At(t,e){return+e?Dr(t,e):Lr(t)}function Lr(t){return Te({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}function Dr(t,e){function n(r,i,o,a,l,h,d,s,c,u,p,f,m,v){var b=d-r,y=s-i,x=b*b+y*y;if(x>4*e&&m--){var E=a+u,w=l+p,k=h+f,L=Y(E*E+w*w+k*k),S=ie(k/=L),C=M(M(k)-1)<P||M(o-c)<P?(o+c)/2:re(w,E),O=t(C,S),_=O[0],V=O[1],F=_-r,A=V-i,g=y*F-b*A;(g*g/x>e||M((b*F+y*A)/x-.5)>.3||a*u+l*p+h*f<Mr)&&(n(r,i,o,a,l,h,_,V,C,E/=L,w/=L,k,m,v),v.point(_,V),n(_,V,C,E,w,k,d,s,c,u,p,f,m,v))}}return function(r){var i,o,a,l,h,d,s,c,u,p,f,m,v={point:b,lineStart:y,lineEnd:E,polygonStart:function(){r.polygonStart(),v.lineStart=w},polygonEnd:function(){r.polygonEnd(),v.lineStart=y}};function b(S,C){S=t(S,C),r.point(S[0],S[1])}function y(){c=NaN,v.point=x,r.lineStart()}function x(S,C){var O=Z([S,C]),_=t(S,C);n(c,u,s,p,f,m,c=_[0],u=_[1],s=S,p=O[0],f=O[1],m=O[2],Mn,r),r.point(c,u)}function E(){v.point=b,r.lineEnd()}function w(){y(),v.point=k,v.lineEnd=L}function k(S,C){x(i=S,C),o=c,a=u,l=p,h=f,d=m,v.point=x}function L(){n(c,u,s,p,f,m,o,a,i,l,h,d,Mn,r),v.lineEnd=E,E()}return v}}var Ar=Te({point:function(t,e){this.stream.point(t*B,e*B)}});function Tr(t){return Te({point:function(e,n){var r=t(e,n);return this.stream.point(r[0],r[1])}})}function Br(t,e,n,r,i){function o(a,l){return a*=r,l*=i,[e+t*a,n-t*l]}return o.invert=function(a,l){return[(a-e)/t*r,(n-l)/t*i]},o}function Ln(t,e,n,r,i,o){if(!o)return Br(t,e,n,r,i);var a=D(o),l=T(o),h=a*t,d=l*t,s=a/t,c=l/t,u=(l*n-a*e)/t,p=(l*e+a*n)/t;function f(m,v){return m*=r,v*=i,[h*m-d*v+e,n-d*m-h*v]}return f.invert=function(m,v){return[r*(s*m-c*v+u),i*(p-c*m-s*v)]},f}function Tt(t){return Or(function(){return t})()}function Or(t){var e,n=150,r=480,i=250,o=0,a=0,l=0,h=0,d=0,s,c=0,u=1,p=1,f=null,m=mt,v=null,b,y,x,E=Pe,w=.5,k,L,S,C,O;function _(g){return S(g[0]*B,g[1]*B)}function V(g){return g=S.invert(g[0],g[1]),g&&[g[0]*U,g[1]*U]}_.stream=function(g){return C&&O===g?C:C=Ar(Tr(s)(m(k(E(O=g)))))},_.preclip=function(g){return arguments.length?(m=g,f=void 0,A()):m},_.postclip=function(g){return arguments.length?(E=g,v=b=y=x=null,A()):E},_.clipAngle=function(g){return arguments.length?(m=+g?dn(f=g*B):(f=null,mt),A()):f*U},_.clipExtent=function(g){return arguments.length?(E=g==null?(v=b=y=x=null,Pe):gt(v=+g[0][0],b=+g[0][1],y=+g[1][0],x=+g[1][1]),A()):v==null?null:[[v,b],[y,x]]},_.scale=function(g){return arguments.length?(n=+g,F()):n},_.translate=function(g){return arguments.length?(r=+g[0],i=+g[1],F()):[r,i]},_.center=function(g){return arguments.length?(o=g[0]%360*B,a=g[1]%360*B,F()):[o*U,a*U]},_.rotate=function(g){return arguments.length?(l=g[0]%360*B,h=g[1]%360*B,d=g.length>2?g[2]%360*B:0,F()):[l*U,h*U,d*U]},_.angle=function(g){return arguments.length?(c=g%360*B,F()):c*U},_.reflectX=function(g){return arguments.length?(u=g?-1:1,F()):u<0},_.reflectY=function(g){return arguments.length?(p=g?-1:1,F()):p<0},_.precision=function(g){return arguments.length?(k=At(L,w=g*g),A()):Y(w)},_.fitExtent=function(g,R){return Dt(_,g,R)},_.fitSize=function(g,R){return Rn(_,g,R)},_.fitWidth=function(g,R){return Pn(_,g,R)},_.fitHeight=function(g,R){return Cn(_,g,R)};function F(){var g=Ln(n,0,0,u,p,c).apply(null,e(o,a)),R=Ln(n,r-g[0],i-g[1],u,p,c);return s=pt(l,h,d),L=Ie(e,R),S=Ie(s,L),k=At(L,w),A()}function A(){return C=O=null,_}return function(){return e=t.apply(this,arguments),_.invert=e.invert&&V,F()}}function nt(t,e){return[t,Kt(Xt(($+e)/2))]}nt.invert=function(t,e){return[t,2*je(Wt(e))-$]};function Bt(){return Fr(nt).scale(961/q)}function Fr(t){var e=Tt(t),n=e.center,r=e.scale,i=e.translate,o=e.clipExtent,a=null,l,h,d;e.scale=function(c){return arguments.length?(r(c),s()):r()},e.translate=function(c){return arguments.length?(i(c),s()):i()},e.center=function(c){return arguments.length?(n(c),s()):n()},e.clipExtent=function(c){return arguments.length?(c==null?a=l=h=d=null:(a=+c[0][0],l=+c[0][1],h=+c[1][0],d=+c[1][1]),s()):a==null?null:[[a,l],[h,d]]};function s(){var c=I*r(),u=e(on(e.rotate()).invert([0,0]));return o(a==null?[[u[0]-c,u[1]-c],[u[0]+c,u[1]+c]]:t===nt?[[Math.max(u[0]-c,a),l],[Math.min(u[0]+c,h),d]]:[[a,Math.max(u[1]-c,l)],[h,Math.min(u[1]+c,d)]])}return s()}function Ot(t){return t}function rt(t){if(t==null)return Ot;var e,n,r=t.scale[0],i=t.scale[1],o=t.translate[0],a=t.translate[1];return function(l,h){h||(e=n=0);var d=2,s=l.length,c=new Array(s);for(c[0]=(e+=l[0])*r+o,c[1]=(n+=l[1])*i+a;d<s;)c[d]=l[d],++d;return c}}function Dn(t,e){for(var n,r=t.length,i=r-e;i<--r;)n=t[i],t[i++]=t[r],t[r]=n}function Ft(t,e){return typeof e=="string"&&(e=t.objects[e]),e.type==="GeometryCollection"?{type:"FeatureCollection",features:e.geometries.map(function(n){return An(t,n)})}:An(t,e)}function An(t,e){var n=e.id,r=e.bbox,i=e.properties==null?{}:e.properties,o=Gt(t,e);return n==null&&r==null?{type:"Feature",properties:i,geometry:o}:r==null?{type:"Feature",id:n,properties:i,geometry:o}:{type:"Feature",id:n,bbox:r,properties:i,geometry:o}}function Gt(t,e){var n=rt(t.transform),r=t.arcs;function i(s,c){c.length&&c.pop();for(var u=r[s<0?~s:s],p=0,f=u.length;p<f;++p)c.push(n(u[p],p));s<0&&Dn(c,f)}function o(s){return n(s)}function a(s){for(var c=[],u=0,p=s.length;u<p;++u)i(s[u],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 h(s){return s.map(l)}function d(s){var c=s.type,u;switch(c){case"GeometryCollection":return{type:c,geometries:s.geometries.map(d)};case"Point":u=o(s.coordinates);break;case"MultiPoint":u=s.coordinates.map(o);break;case"LineString":u=a(s.arcs);break;case"MultiLineString":u=s.arcs.map(a);break;case"Polygon":u=h(s.arcs);break;case"MultiPolygon":u=s.arcs.map(h);break;default:return null}return{type:c,coordinates:u}}return d(e)}function oe(t){if("type"in t&&t.type==="FeatureCollection")return t;let e=t,n=typeof e.object=="string"?e.topology.objects[e.object]:e.object;if(!n)throw new Error("The named TopoJSON object does not exist in this topology.");let r=Ft(e.topology,n);return r.type==="FeatureCollection"?r:{type:"FeatureCollection",features:[r]}}function Tn(t){return t.reduce((e,n)=>e+(n??0),0)}function it(t,e,n,r){if(t===null||r<=0)return null;if(r===1||n===e)return r-1;let i=Math.round((t-e)/(n-e)*(r-1));return Math.min(Math.max(i,0),r-1)}function Bn(t,e,n,r){let i=t.length;return t.map((o,a)=>{let l=e.filter(h=>it(h,n,r,i)===a);return{index:a,color:o,from:l.length?Math.min(...l):null,to:l.length?Math.max(...l):null,matches:l.length}})}function On(t,e){if(t.matches===0||t.from===null||t.to===null)return"No regions in this band";let n=t.from===t.to?e(t.from):`${e(t.from)} to ${e(t.to)}`;return`Highlight ${t.matches} ${t.matches===1?"region":"regions"}, ${n}`}function Fn(t,e,n,r=4){let i=0;t.right>e.right-r&&(i=e.right-r-t.right),t.left+i<e.left+r&&(i=e.left+r-t.left);let o=t.top<e.top+r?"below":"above";return{dx:i,side:o}}var $r=["puducherry"];function jn(t){let e=t.toLowerCase();return $r.some(n=>e.includes(n))}function ot(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(let[o,a]of t)o<e&&(e=o),o>r&&(r=o),a<n&&(n=a),a>i&&(i=a);return[e,n,r,i]}function at(t){let e=0;for(let n of t){if(n.length===0)continue;let[r,i,o,a]=ot(n),l=Math.max(o-r,a-i);l>e&&(e=l)}return e}function Gn(t){let e=0;for(let n=0;n<t.length;n++){let[r,i]=t[n],[o,a]=t[(n+1)%t.length];e+=r*a-o*i}return e/2}function $n(t,e){let n=null,r=0;for(let h of t){if(h.length<3)continue;let d=Math.abs(Gn(h));d>r&&(r=d,n=h)}if(!n||r===0)return e;let i=Gn(n),o=0,a=0;for(let h=0;h<n.length;h++){let[d,s]=n[h],[c,u]=n[(h+1)%n.length],p=d*u-c*s;o+=(d+c)*p,a+=(s+u)*p}let l=[o/(6*i),a/(6*i)];return Number.isFinite(l[0])&&Number.isFinite(l[1])?l:e}function qr(t,e){let[n,r]=t,[i,o,a,l]=e,h=Math.max(i-n,0)+Math.max(n-a,0),d=Math.max(o-r,0)+Math.max(r-l,0);return Math.hypot(h,d)}function qn(t,e){let n=1/0;for(let r of e){let i=qr(t,r);i<n&&(n=i)}return n}var zr=[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 zn(t){let{anchor:e,clearance:n,halfSize:r,viewBox:i,centre:o,isBlocked:a}=t,l=e[0]-o[0],h=e[1]-o[1],d=l===0&&h===0?0:Math.atan2(h,l);for(let s of zr){let c=d+s,u=[Nn(e[0]+Math.cos(c)*n,r[0],i[0]-r[0]),Nn(e[1]+Math.sin(c)*n,r[1],i[1]-r[1])];if(!a(u))return u}return null}function Nn(t,e,n){return Math.min(Math.max(t,e),n)}function Hn(t,e,n=8){let r=()=>t.map(o=>[...o]);if(e<=0)return r();let i=at(t);return i<=0||i>=e?r():t.map(o=>{let[a,l,h,d]=ot(o),s=Math.max(h-a,d-l),c=s<=0?1:Math.min(e/s,n),u=(a+h)/2,p=(l+d)/2;return o.map(([f,m])=>[u+(f-u)*c,p+(m-p)*c])})}function Hr(t){let e=[...t].sort((h,d)=>h[0]-d[0]||h[1]-d[1]),n=[];for(let h of e){let d=n.at(-1);(!d||d[0]!==h[0]||d[1]!==h[1])&&n.push(h)}if(n.length<3)return n.map(h=>[...h]);let r=(h,d,s)=>(d[0]-h[0])*(s[1]-h[1])-(d[1]-h[1])*(s[0]-h[0]),i=h=>{let d=[];for(let s of h){for(;d.length>=2&&r(d[d.length-2],d[d.length-1],s)<=0;)d.pop();d.push(s)}return d},o=i(n),a=i([...n].reverse()),l=[...o.slice(0,-1),...a.slice(0,-1)];return l.length>=3?l:n.map(h=>[...h])}function Un(t,e){if(t.length<2||e<=0)return null;let n=at(t);if(n<=0||n>=e)return null;let r=Hr(t.flat());return r.length>=3?r:null}function Nt(t){let e="";for(let n of t)if(n.length!==0){e+=`M${n[0][0]},${n[0][1]}`;for(let r=1;r<n.length;r++)e+=`L${n[r][0]},${n[r][1]}`;e+="Z"}return e}var Ur="http://www.w3.org/2000/svg",H={width:960,height:640,padding:28},Be=["#d9f1ed","#b9e3dd","#8fd1c8","#5bb9ae","#2f9c90","#147b71","#075b55"],st=new Intl.NumberFormat("en-IN").format,Vn=12,jt=22,Vr=14,lt=7;function Wn(t,e){let n=t.geometry;if(!n)return[];let r=n.type==="Polygon"?[n.coordinates]:n.type==="MultiPolygon"?n.coordinates:[],i=[];for(let o of r)for(let a of o){let l=[];for(let h of a){let d=e(h);d&&Number.isFinite(d[0])&&Number.isFinite(d[1])&&l.push([d[0],d[1]])}l.length>0&&i.push(l)}return i}var Wr=0;function Kn(t,e,n,r,i){if(typeof i=="function"){let a={min:n,max:r,feature:e.feature,id:e.id};return i(t,a)}let o=it(t,n,r,i.length);return o===null?"var(--india-map-empty)":i[o]??"var(--india-map-empty)"}function Yn(t){return typeof t.colorScale=="function"?Be:t.colorScale??Be}function Xn(t){return Bt().fitExtent([[H.padding,H.padding],[H.width-H.padding,H.height-H.padding]],t)}function Jn(t,e,n=0){let r=oe(t.geometry),i=tt(e);return r.features.map(o=>{let a=i.centroid(o),l=i.bounds(o),h=[(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2],d={id:t.getId(o),label:t.getLabel(o),value:t.getValue(o),meta:t.getMeta?.(o),feature:o},s=n>0&&!jn(d.id),c=s?Hn(Wn(o,e),n):Wn(o,e),u=Un(c,jt);return{...d,path:s?Nt(c):i(o)??"",hitPath:u?Nt([u]):null,centroid:c.length>0?$n(c,a.every(Number.isFinite)?a:h):a.every(Number.isFinite)?a:h,partBounds:c.map(ot),extent:at(c)}})}function Zn(t,e){let n=tt(e);return oe(t.geometry).features.map(r=>({id:t.getId(r),label:t.getLabel(r),description:t.getDescription(r),path:n(r)??""}))}function Kr(t){let e=t%100;return e>=11&&e<=13?`${t}th`:`${t}${["th","st","nd","rd"][t%10]??"th"}`}function Yr(t,e){let n=document.createDocumentFragment(),r=document.createElement("strong");r.textContent=t.label;let i=document.createElement("b");if(i.textContent=t.value===null?"No data":e(t.value),n.append(r,i),t.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(t.share,1.5)}%`,o.append(a);let l=document.createElement("small"),h=[`${t.share.toFixed(1)}% of total`];t.rank!==null&&h.push(`${Kr(t.rank)} of ${t.rankedCount}`),l.textContent=h.join(" \xB7 "),n.append(o,l)}return n}function N(t,e){let n=document.createElement(t);for(let[r,i]of Object.entries(e??{}))n.setAttribute(r,i);return n}function G(t,e){let n=document.createElementNS(Ur,t);for(let[r,i]of Object.entries(e??{}))n.setAttribute(r,i);return n}function Xr(t,e){typeof e=="string"?t.textContent=e:t.appendChild(e)}var de=class{containerEl;options;instanceId=`india-choropleth-${++Wr}`;tooltipId=`${this.instanceId}-tooltip`;hatchId=`${this.instanceId}-hatch`;activeDrillDownId;activeSelectedId;inspectedId=null;loadedDistricts=null;loadedDistrictReferenceOverlay=null;loadingState=null;loadError=null;districtGeneration=0;overlayGeneration=0;restoreFocusId=null;destroyed=!1;attemptedDistrictLoadForId=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(e,n){let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error(`IndiaChoropleth: container ${typeof e=="string"?`"${e}"`:""} was not found.`);this.containerEl=r,this.options=n,this.activeDrillDownId=n.drillDownId!==void 0?n.drillDownId:n.defaultDrillDownId??null,this.activeSelectedId=n.selectedId!==void 0?n.selectedId:n.defaultSelectedId??null,this.buildShell(),this.renderStructure()}update(e){"loadDistricts"in e&&e.loadDistricts!==this.options.loadDistricts&&(this.attemptedDistrictLoadForId=null),"loadDistrictReferenceOverlay"in e&&e.loadDistrictReferenceOverlay!==this.options.loadDistrictReferenceOverlay&&(this.attemptedOverlayLoadForId=null),this.options={...this.options,...e},"drillDownId"in e&&e.drillDownId!==void 0&&(this.activeDrillDownId=e.drillDownId),"selectedId"in e&&e.selectedId!==void 0&&(this.activeSelectedId=e.selectedId),this.renderStructure()}select(e){let n=this.derived.regions.find(r=>r.id===e)??null;this.setActiveSelectedId(n?.id??null),n&&this.options.onSelectedChange?.(n,this.derived.level),this.applyInteractionState()}drillDown(e){if(e===null){this.goBack();return}let n=this.derived.stateRegions.find(r=>r.id===e);n&&(this.setActiveDrillDownId(e),this.options.onDrillDownChange?.(e,n),this.renderStructure())}getSelected(){return this.derived.selected}getInspected(){return this.derived.inspected}destroy(){this.destroyed=!0,this.districtGeneration+=1,this.overlayGeneration+=1,this.pathRefs.clear(),this.containerEl.textContent=""}setActiveDrillDownId(e){this.options.drillDownId===void 0&&(this.activeDrillDownId=e)}setActiveSelectedId(e){this.options.selectedId===void 0&&(this.activeSelectedId=e)}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 e=this.options,n=oe(e.states.geometry),r=e.referenceOverlay?oe(e.referenceOverlay.geometry):null,i=Xn({type:"FeatureCollection",features:[...n.features,...r?.features??[]]}),o=Jn(e.states,i,e.minPartExtent??0),a=e.referenceOverlay?Zn(e.referenceOverlay,i):[],l=o.find(S=>S.id===this.activeDrillDownId)??null,d=!!(l&&this.activeDrillDownId)?"district":"state",s=this.loadedDistricts?.stateId===this.activeDrillDownId?this.loadedDistricts.layer:null,c=this.loadedDistrictReferenceOverlay?.stateId===this.activeDrillDownId?this.loadedDistrictReferenceOverlay.overlay:null,u=s?oe(s.geometry):null,p=c?oe(c.geometry):null,f=u?Xn({type:"FeatureCollection",features:[...u.features,...p?.features??[]]}):null,m=d==="district"&&s&&f?Jn(s,f,e.minDistrictPartExtent??e.minPartExtent??0):d==="state"?o:[],v=d==="district"&&c&&f?Zn(c,f):[],b=m.find(S=>S.id===this.activeSelectedId)??null,y=m.find(S=>S.id===this.inspectedId)??null;this.inspectedId&&!y&&(this.inspectedId=null);let x=m.map(S=>S.value).filter(S=>S!==null),E=Tn(x),w=x.length?Math.min(...x):0,k=x.length?Math.max(...x):0;this.derived={stateRegions:o,referenceRegions:a,drilledState:l,level:d,regions:m,visibleReferenceRegions:d==="state"?a:v,selected:b,inspected:y,total:E,min:w,max:k,canDrill:!!(e.loadDistricts&&d==="state"),mergedReferenceIds:new Set(e.referenceOverlayMergeIds??[]),buckets:Bn(Yn(e),m.map(S=>S.value),w,k)};let L=[d,this.activeDrillDownId??"",typeof e.colorScale=="function"?"function":(e.colorScale??Be).join(",")].join("|");L!==this.bandsKey&&(this.bandsKey=L,this.activeBucket=null),this.activeBucket!==null&&this.activeBucket>=this.derived.buckets.length&&(this.activeBucket=null)}loadDistrictsFor(e){let n=this.options;if(!n.loadDistricts){this.loadedDistricts=null,this.loadingState=null,this.loadError=null;return}let r=this.derived.stateRegions.find(o=>o.id===e);if(!r)return;let i=++this.districtGeneration;this.loadingState=e,this.loadError=null,this.loadedDistricts=null,n.loadDistricts(e,r).then(o=>{this.destroyed||i!==this.districtGeneration||(this.loadedDistricts={stateId:e,layer:o},this.loadingState=null,this.renderStructure())}).catch(o=>{this.destroyed||i!==this.districtGeneration||(this.loadError=o instanceof Error?o:new Error("Unable to load districts."),this.loadingState=null,this.renderStructure())})}loadDistrictReferenceOverlayFor(e){let n=this.options;if(!n.loadDistrictReferenceOverlay){this.loadedDistrictReferenceOverlay=null;return}let r=this.derived.stateRegions.find(o=>o.id===e);if(!r)return;let i=++this.overlayGeneration;this.loadedDistrictReferenceOverlay=null,n.loadDistrictReferenceOverlay(e,r).then(o=>{this.destroyed||i!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:e,overlay:o},this.renderStructure())}).catch(()=>{this.destroyed||i!==this.overlayGeneration||(this.loadedDistrictReferenceOverlay={stateId:e,overlay:null},this.renderStructure())})}inspect(e){let n=e?.id??null;n===null&&this.inspectedId===null||(this.inspectedId=n,this.derived.inspected=e,this.options.onInspect?.(e??null,this.derived.level),this.applyInteractionState())}toViewBox(e){let n=this.canvasEl.querySelector("svg");if(!n)return null;let r=n.getBoundingClientRect();if(r.width===0||r.height===0)return null;let i=Math.min(r.width/H.width,r.height/H.height),o=(r.width-H.width*i)/2,a=(r.height-H.height*i)/2;return[(e.clientX-r.left-o)/i,(e.clientY-r.top-a)/i]}smallRegionNear(e){let n=null,r=1/0;for(let i of this.derived.regions){if(i.extent<=0||i.extent>=jt)continue;let o=qn(e,i.partBounds);o<=Vr&&o<r&&(r=o,n=i)}return n}activate(e){let n=this.options;n.onRegionClick?.(e,this.derived.level),this.setActiveSelectedId(e.id),n.onSelectedChange?.(e,this.derived.level),this.derived.level==="state"&&n.loadDistricts?(this.setActiveSelectedId(null),this.setActiveDrillDownId(e.id),n.onDrillDownChange?.(e.id,e),this.renderStructure()):this.applyInteractionState()}goBack(){let e=this.derived.drilledState??void 0;this.setActiveDrillDownId(null),this.setActiveSelectedId(e?.id??null),this.inspectedId=e?.id??null,this.restoreFocusId=e?.id??null,this.options.onDrillDownChange?.(null,e),this.renderStructure()}renderStructure(){if(this.destroyed)return;this.recompute();let e=this.options;this.activeDrillDownId&&e.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&&e.loadDistrictReferenceOverlay&&this.attemptedOverlayLoadForId!==this.activeDrillDownId&&(this.attemptedOverlayLoadForId=this.activeDrillDownId,this.loadDistrictReferenceOverlayFor(this.activeDrillDownId)),(!this.activeDrillDownId||!e.loadDistrictReferenceOverlay)&&(this.loadedDistrictReferenceOverlay=null,this.attemptedOverlayLoadForId=null);let n=e.interactive!==!1;if(this.rootEl.className=["india-choropleth",!n&&"india-choropleth--static",e.className].filter(Boolean).join(" "),this.loadingState?this.rootEl.setAttribute("aria-busy","true"):this.rootEl.removeAttribute("aria-busy"),this.renderToolbar(),this.renderCanvas(),this.renderLegend(),this.restoreFocusId&&this.derived.level==="state"){let r=this.restoreFocusId;this.restoreFocusId=null,this.pathRefs.get(r)?.focus()}}renderToolbar(){let e=this.options;if(this.toolbarEl.textContent="",e.showBreadcrumb===!1)return;let n=N("nav",{class:"india-choropleth__breadcrumb","aria-label":"Map hierarchy"});if(this.derived.drilledState){let r=N("button",{class:"india-choropleth__back",type:"button"});r.textContent="All states",r.addEventListener("click",()=>this.goBack());let i=N("span",{"aria-hidden":"true"});i.textContent="/";let o=N("span",{"aria-current":"page"});o.textContent=this.derived.drilledState.label,n.append(r,i,o)}else{let r=N("span");r.textContent="All states",n.append(r)}this.toolbarEl.append(n)}renderCanvas(){let e=this.options,n=e.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)&&(!this.loadedDistricts||this.loadedDistricts.stateId!==this.activeDrillDownId||this.loadError),o=!i&&this.derived.regions.length===0;if(i||o){let m=N("div",{class:"india-choropleth__status",role:i&&this.loadError?"alert":"status"});m.textContent=o?"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(m),this.applyInteractionState();return}let a=G("svg",{class:"india-choropleth__svg",viewBox:`0 0 ${H.width} ${H.height}`,role:"group","aria-label":e.ariaLabel??"Interactive choropleth map"});if(this.svgRootEl=a,n&&(a.addEventListener("keydown",m=>{m.key==="Escape"&&(m.preventDefault(),this.inspect(null))}),a.addEventListener("click",m=>{if(m.target!==a)return;let v=this.toViewBox(m),b=v?this.smallRegionNear(v):null;if(b){this.activate(b);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=G("defs"),v=G("pattern",{id:this.hatchId,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"});v.append(G("rect",{width:"8",height:"8",fill:"var(--india-map-reference-bg)"}),G("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:"var(--india-map-reference-hatch)","stroke-width":"2"})),m.append(v),a.append(m);let b=G("g",{class:"india-choropleth__reference-fill",role:"group","aria-label":"Non-statistical reference context."});for(let y of this.derived.visibleReferenceRegions)b.append(G("path",{d:y.path,fill:e.referenceOverlayFill==="solid"?"var(--india-map-reference-bg)":`url(#${this.hatchId})`,"aria-label":`${y.label}.${y.description?` ${y.description}`:""}`,role:"img"}));a.append(b)}let l=n?this.derived.regions.filter(m=>m.hitPath):[];if(l.length>0){let m=G("g",{class:"india-choropleth__hit-areas","aria-hidden":"true"});for(let v of l){let b=G("path",{d:v.hitPath,fill:"none","pointer-events":"all",tabindex:"-1"});b.addEventListener("mouseenter",()=>this.inspect(v)),b.addEventListener("mouseleave",()=>this.inspect(null)),b.addEventListener("click",()=>this.activate(v)),m.append(b)}a.append(m)}let h=m=>it(m.value,this.derived.min,this.derived.max,Yn(e).length);for(let m of this.derived.regions){let v=this.derived.canDrill?"Activate to view districts.":"Activate to select.",b=m.value===null?"No data":(e.formatValue??st)(m.value),y=G("path",{class:"india-choropleth__region",d:m.path,fill:Kn(m.value,m,this.derived.min,this.derived.max,e.colorScale??Be),tabindex:n?"0":"-1","aria-label":`${m.label}, ${b}. ${v}`});n&&y.setAttribute("role","button"),this.derived.mergedReferenceIds.has(m.id)&&y.classList.add("india-choropleth__region--reference-merged"),n&&(y.setAttribute("aria-pressed",m.id===this.derived.selected?.id?"true":"false"),y.addEventListener("mouseenter",()=>this.inspect(m)),y.addEventListener("mouseleave",()=>this.inspect(null)),y.addEventListener("focus",()=>this.inspect(m)),y.addEventListener("blur",()=>this.inspect(null)),y.addEventListener("click",()=>this.activate(m)),y.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),this.activate(m))})),a.append(y),this.pathRefs.set(m.id,y),this.bucketEls.push({el:y,bucket:h(m)})}let d=this.derived.regions.filter(m=>m.extent>0&&m.extent<lt);if(d.length>0){let m=G("g",{class:"india-choropleth__small-markers","aria-hidden":"true"});for(let v of d){let b=G("circle",{cx:String(v.centroid[0]),cy:String(v.centroid[1]),r:String(lt/2),fill:Kn(v.value,v,this.derived.min,this.derived.max,e.colorScale??Be)});n&&(b.addEventListener("mouseenter",()=>this.inspect(v)),b.addEventListener("mouseleave",()=>this.inspect(null)),b.addEventListener("click",()=>this.activate(v))),this.bucketEls.push({el:b,bucket:h(v)}),m.append(b)}a.append(m)}if(e.showRegionValues){let m=G("g",{class:`india-choropleth__region-values${this.derived.level==="district"?" india-choropleth__region-values--district":""}`,"aria-hidden":"true"}),v=G("g",{class:"india-choropleth__value-leaders","aria-hidden":"true"});for(let b of this.derived.regions){if(!b.centroid.every(Number.isFinite))continue;let y=b.value===null?"\u2014":(e.formatValue??st)(b.value),x=this.placeRegionValue(b,y);if(!x)continue;let E=G("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:h(b)}),x.leader){let w=G("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:w,bucket:h(b)}),v.append(w)}}a.append(v,m)}if(this.derived.visibleReferenceRegions.length>0){let m=G("g",{class:"india-choropleth__reference-outline","aria-hidden":"true"});for(let v of this.derived.visibleReferenceRegions)m.append(G("path",{d:v.path,fill:"none"}));a.append(m)}let s=G("g",{class:"india-choropleth__selection","aria-hidden":"true"}),c=G("path",{class:"india-choropleth__selection-halo",fill:"none"}),u=G("path",{class:"india-choropleth__selection-ring",fill:"none"});s.append(c,u),a.append(s),this.selectionGroupEl=s,this.selectionPathEls=[c,u],this.canvasEl.append(a);let p=N("div",{class:"india-choropleth__tooltip-anchor"});p.style.display="none";let f=N("div",{id:this.tooltipId,class:"india-choropleth__tooltip"});p.append(f),this.canvasEl.append(p),this.tooltipAnchorEl=p,this.tooltipContentEl=f,this.applyInteractionState()}placeRegionValue(e,n){let r=e.extent>0&&e.extent<jt,i=Math.max(n.length*3.1,3),o=5.5,a=e.partBounds.some(([f,m,v,b])=>v-f>=i*2&&b-m>=o*2);if(!r&&a)return{at:e.centroid};let l=r?zn({anchor:e.centroid,clearance:Math.max(e.extent,lt)/2+4+i,halfSize:[i,o],viewBox:[H.width,H.height],centre:[H.width/2,H.height/2],isBlocked:f=>this.coversAnotherRegion(e,f,i,o)}):null;if(!l)return a?{at:e.centroid}:null;let h=Math.max(e.extent,lt)/2+1,d=l[0]-e.centroid[0],s=l[1]-e.centroid[1],c=Math.hypot(d,s);if(c<=h+i)return{at:l};let u=[e.centroid[0]+d/c*h,e.centroid[1]+s/c*h],p=[l[0]-d/c*(i+1.5),l[1]-s/c*(i+1.5)];return{at:l,leader:[u,p]}}coversAnotherRegion(e,n,r,i){let o=[n,[n[0]-r,n[1]-i],[n[0]+r,n[1]+i],[n[0]+r,n[1]-i],[n[0]-r,n[1]+i]];for(let a of this.derived.regions)if(a.id!==e.id){for(let l of o)if(a.partBounds.some(([h,d,s,c])=>l[0]>=h&&l[0]<=s&&l[1]>=d&&l[1]<=c))return!0}return!1}renderLegend(){let e=this.options;if(this.legendEl&&(this.legendEl.remove(),this.legendEl=null),e.showLegend===!1)return;let[n,r]=e.legendLabels??["Lower","Higher"],i=N("div",{class:"india-choropleth__legend",role:"group","aria-label":`Color scale: ${n} to ${r} values`}),o=N("span");o.textContent=n;let a=e.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=On(d,e.formatValue??st);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 h=N("span");if(h.textContent=r,i.append(o,l,h),this.derived.visibleReferenceRegions.length>0){let d=N("i",{class:`india-choropleth__reference-key${e.referenceOverlayFill==="solid"?" india-choropleth__reference-key--solid":""}`,"aria-hidden":"true"}),s=N("span");s.textContent=e.referenceOverlayLegendLabel??"Reference context \xB7 data unavailable",i.append(d,s)}this.insightsEl?this.rootEl.insertBefore(i,this.insightsEl):this.rootEl.append(i),this.legendEl=i,a&&i.addEventListener("keydown",d=>{d.key==="Escape"&&(d.preventDefault(),this.activeBucket=null,this.applyInteractionState())}),this.applyLegendState()}renderInsights(){let e=this.options;if(this.insightsEl&&(this.insightsEl.remove(),this.insightsEl=null),!e.renderInsights)return;let n=N("aside",{class:"india-choropleth__insights","aria-live":"polite"});e.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 e=this.options.interactive!==!1;for(let[n,r]of this.pathRefs){let i=n===this.derived.inspected?.id,o=n===this.derived.selected?.id;r.classList.toggle("india-choropleth__region--inspected",i),r.classList.toggle("india-choropleth__region--selected",o),e&&(r.setAttribute("aria-pressed",o?"true":"false"),i?r.setAttribute("aria-describedby",this.tooltipId):r.removeAttribute("aria-describedby"))}for(let{el:n,bucket:r}of this.bucketEls)n.classList.toggle("india-choropleth__dimmed",this.activeBucket!==null&&r!==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[e,n]of this.swatchEls.entries()){let r=this.activeBucket===e;n.classList.toggle("india-choropleth__swatch--active",r),n.classList.toggle("india-choropleth__swatch--muted",this.activeBucket!==null&&!r),n.setAttribute("aria-pressed",r?"true":"false")}}renderTooltip(){if(!this.tooltipAnchorEl||!this.tooltipContentEl)return;let e=this.derived.inspected;if(!e){this.tooltipAnchorEl.style.display="none";return}let n=this.toTooltipContext(e);this.tooltipAnchorEl.style.display="",this.tooltipAnchorEl.style.left=`${e.centroid[0]/H.width*100}%`,this.tooltipAnchorEl.style.top=`${e.centroid[1]/H.height*100}%`,this.tooltipContentEl.textContent="";let r=this.options.renderTooltip?this.options.renderTooltip(n):Yr(n,this.options.formatValue??st);Xr(this.tooltipContentEl,r),this.positionTooltip()}renderSelectionRing(){let e=this.selectionGroupEl;if(!e)return;let n=this.derived.selected;if(!n){e.style.display="none";return}e.style.display="";for(let r of this.selectionPathEls)r.setAttribute("d",n.path);e.classList.toggle("india-choropleth__selection--lifted",n.id===this.derived.inspected?.id)}positionTooltip(){let e=this.tooltipAnchorEl;if(!e)return;e.style.removeProperty("--india-map-tooltip-dx"),e.style.removeProperty("--india-map-tooltip-dy");let n=e.getBoundingClientRect(),r=this.canvasEl.getBoundingClientRect();if(n.width===0||r.width===0)return;let{dx:i,side:o}=Fn(n,r,Vn);i!==0&&e.style.setProperty("--india-map-tooltip-dx",`${Math.round(i)}px`),o==="below"&&e.style.setProperty("--india-map-tooltip-dy",`${Vn}px`)}toTooltipContext(e){let n=this.derived.regions.filter(i=>i.value!==null),r=e.value===null?null:n.filter(i=>(i.value??0)>(e.value??0)).length+1;return{...e,level:this.derived.level,total:this.derived.total,share:e.value===null||this.derived.total===0?null:e.value/this.derived.total*100,rank:r,rankedCount:n.length}}computeInsightContext(){let e=this.derived.inspected??this.derived.selected;return e?{...this.toTooltipContext(e),selected:e.id===this.derived.selected?.id}:null}};var ct="https://cdn.jsdelivr.net/gh/shashankbudem/bharat-choropleth@v0.1.0/data/generated",Qn="State/UT and district boundaries derived from datta07/INDIAN-SHAPEFILES (MIT).";function er(t){return t.replace(/\/+$/,"")}function tr(t){return`${er(t)}/current-2019-states/states.topo.json`}function Jr(t,e){return`${er(t)}/current-2019-districts/districts/${e}.topo.json`}async function nr(t,e){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(t,{signal:e});if(!n.ok)throw new Error(`BharatChoropleth: failed to load boundary data from ${t} (HTTP ${n.status}). Set \`dataBaseUrl\` to your own copy of data/generated, or pass \`geometry\` directly.`);return n.json()}function $t(t,e){if(!t||typeof t!="object")throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.");let n=t;if(n.type==="FeatureCollection"||"topology"in n&&"object"in n)return t;if(n.type==="Topology"&&n.objects&&typeof n.objects=="object"){let r=n.objects,i=e in r?e:Object.keys(r)[0];if(!i)throw new Error("BharatChoropleth: the TopoJSON topology contains no objects.");return{topology:t,object:i}}throw new Error("BharatChoropleth: boundary data must be TopoJSON or a GeoJSON FeatureCollection.")}async function rr(t,e,n){return typeof t=="string"?$t(await nr(t,n),e):t instanceof Promise?$t(await t,e):t}function ir(t){return typeof t=="object"&&t!==null&&!(t instanceof Promise)}async function or(t,e,n){return $t(await nr(Jr(t,e),n),"districts")}var qt=[{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"}],Zr={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 Fe(t){return t.toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function zt(t){return t.replace(/-/g,"")}var xe=new Map,Oe=new Map;for(let t of qt)for(let e of[t.slug,Fe(t.name),t.id]){xe.has(e)||xe.set(e,t);let n=zt(e);Oe.has(n)||Oe.set(n,t)}for(let[t,e]of Object.entries(Zr)){let n=xe.get(e);if(!n)continue;xe.has(t)||xe.set(t,n);let r=zt(t);Oe.has(r)||Oe.set(r,n)}function ue(t){let e=Fe(t);return xe.get(e)??Oe.get(zt(e))}function ar(t,e){if(!t.includes("_"))return;let n=t.replace(/_([a-z])/g,(r,i)=>i.toUpperCase());return n!==t&&n in e?n:void 0}function lr(t){return typeof t=="object"&&t!==null&&t.nodeType===1}var sr=["#bharat-choropleth","#map"];function Qr(t){if(lr(t))return t;if(typeof t=="string"){let e=document.querySelector(t);if(e)return e;throw new Error(`BharatChoropleth: container "${t}" was not found.`)}for(let e of sr){let n=document.querySelector(e);if(n)return n}throw new Error(`BharatChoropleth: no container given and none of ${sr.join(", ")} exist. Pass an element or selector: new BharatChoropleth("#map").`)}var Ge=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(e,n={}){let i=typeof e=="object"&&e!==null&&!lr(e)?{...e}:{...n,container:e??n.container};this.options=i,this.containerEl=Qr(i.container),this.dataBaseUrl=i.dataBaseUrl??ct,this.usingDefaultData=i.geometry===void 0,this.getId=i.getId??(o=>String(o.properties?.id??o.properties?.name)),this.getLabel=i.getLabel??(o=>String(o.properties?.name??o.properties?.id));for(let[o,a]of Object.entries(i.values??{})){let l=this.keyFor(o);this.values.set(l,a),this.writtenAs.set(l,o)}return this._colorScale=i.colorScale,this._fontColor=i.fontColor,this._borderColor=i.borderColor,this._borderWidth=i.borderWidth,this._selectionWidth=i.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)}),ir(i.geometry)?(this.abortController=null,this.ready=Promise.resolve(this),this.mount(i.geometry)):(this.abortController=typeof AbortController=="function"?new AbortController:null,this.showLoading(),this.ready=rr(i.geometry??tr(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 h=ar(a,o);return h?Reflect.get(o,h,l):this.getValue(a)}return Reflect.get(o,a,l)},set:(o,a,l,h)=>{if(typeof a=="string"&&!(a in o)){let d=ar(a,o);return d?Reflect.set(o,d,l,h):(this.setValue(a,l),!0)}return Reflect.set(o,a,l,h)}}),this.proxied}proxied;keyFor(e){return ue(e)?.id??Fe(e)}keyForFeature(e){let n=this.getId(e);return ue(n)?.id??ue(this.getLabel(e))?.id??Fe(this.getLabel(e))}getValue(e){return this.values.get(this.keyFor(e))??null}setValue(e,n){let r=this.keyFor(e);this.values.set(r,n),this.writtenAs.has(r)||this.writtenAs.set(r,e),this.engineInstance&&(this.labelByKey.has(r)?this.engineInstance.update({}):this.warnUnknown(e))}warnUnknown(e){console.warn(`BharatChoropleth: "${e}" is not a recognized state/UT \u2014 its value is ignored.`)}mount(e){this.clearPlaceholder();for(let y of oe(e).features){let x=this.keyForFeature(y);this.labelByKey.set(x,this.getLabel(y)),this.values.has(x)||this.values.set(x,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:r,dataBaseUrl:i,districts:o,getId:a,getLabel:l,values:h,fontColor:d,borderColor:s,borderWidth:c,selectionWidth:u,colorScale:p,onReady:f,onError:m,...v}=this.options,b=o??this.usingDefaultData;this.engineInstance=new de(this.containerEl,{...v,colorScale:p,loadDistricts:v.loadDistricts??(b?this.defaultDistrictLoader:void 0),states:{geometry:e,getId:this.getId,getLabel:this.getLabel,getValue:y=>this.values.get(this.keyForFeature(y))??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)),f?.(this.proxied??this)}defaultDistrictLoader=async e=>({geometry:await or(this.dataBaseUrl,e,this.abortController?.signal),getId:r=>String(r.properties?.id??r.properties?.name),getLabel:r=>String(r.properties?.name??r.properties?.id),getValue:r=>this.values.get(this.keyFor(this.getLabel(r)))??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(e){this.clearPlaceholder();let n=document.createElement("div");n.className="bharat-choropleth__status bharat-choropleth__status--error",n.setAttribute("role","alert"),n.textContent=e.message,this.containerEl.appendChild(n),this.loadingEl=n,this.options.onError?this.options.onError(e):console.error(e)}clearPlaceholder(){this.loadingEl?.remove(),this.loadingEl=null}get engine(){return this.engineInstance}get states(){return this.statesAccessor}setValues(e){for(let[n,r]of Object.entries(e)){let i=this.keyFor(n);this.values.set(i,r),this.writtenAs.has(i)||this.writtenAs.set(i,n),this.engineInstance&&!this.labelByKey.has(i)&&this.warnUnknown(n)}this.engineInstance?.update({})}getValues(){let e={};for(let[n,r]of this.labelByKey)e[r]=this.values.get(n)??null;return e}get mapRootEl(){return this.containerEl.querySelector(".india-choropleth")??this.containerEl}get fontColor(){return this._fontColor}set fontColor(e){this._fontColor=e,this.engineInstance&&(e?this.mapRootEl.style.setProperty("--india-map-text",e):this.mapRootEl.style.removeProperty("--india-map-text"))}get borderColor(){return this._borderColor}set borderColor(e){this._borderColor=e,this.engineInstance&&(e?this.mapRootEl.style.setProperty("--india-map-stroke",e):this.mapRootEl.style.removeProperty("--india-map-stroke"))}get borderWidth(){return this._borderWidth}set borderWidth(e){this._borderWidth=e,this.setWidthVar("--india-map-border-width",e)}get selectionWidth(){return this._selectionWidth}set selectionWidth(e){this._selectionWidth=e,this.setWidthVar("--india-map-selection-width",e)}setWidthVar(e,n){this.engineInstance&&(n===void 0?this.mapRootEl.style.removeProperty(e):this.mapRootEl.style.setProperty(e,String(n)))}get colorScale(){return this._colorScale}set colorScale(e){this._colorScale=e,this.options.colorScale=e,this.engineInstance?.update({colorScale:e})}select(e){this.engineInstance?.select(e)}drillDown(e){let n=e===null?null:ue(e)?.id??e;this.engineInstance?.drillDown(n)}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 cr="bharat-choropleth-styles";function dr(){if(typeof document>"u"||document.getElementById(cr))return;let t=document.createElement("style");t.id=cr,t.textContent=Ut,document.head.appendChild(t)}dr();var Ht=globalThis;Ht.BharatChoropleth=Ge;Ht.IndiaChoropleth=de;Ht.BharatChoroplethLib={BharatChoropleth:Ge,IndiaChoropleth:de,STATES:qt,resolveState:ue,ATTRIBUTION:Qn,DEFAULT_DATA_BASE_URL:ct,injectStyles:dr};})();
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