@sckyzo/cosmos-charts 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +107 -22
  3. package/THIRD_PARTY_NOTICES.md +81 -0
  4. package/dist/BarChart.cjs +137 -0
  5. package/dist/BarChart.cjs.map +1 -0
  6. package/dist/BarChart.js +135 -0
  7. package/dist/BarChart.js.map +1 -0
  8. package/dist/BoxPlotChart.cjs +214 -0
  9. package/dist/BoxPlotChart.cjs.map +1 -0
  10. package/dist/BoxPlotChart.js +212 -0
  11. package/dist/BoxPlotChart.js.map +1 -0
  12. package/dist/BumpChart.cjs +328 -0
  13. package/dist/BumpChart.cjs.map +1 -0
  14. package/dist/BumpChart.js +326 -0
  15. package/dist/BumpChart.js.map +1 -0
  16. package/dist/CalendarChart.cjs +216 -0
  17. package/dist/CalendarChart.cjs.map +1 -0
  18. package/dist/CalendarChart.js +214 -0
  19. package/dist/CalendarChart.js.map +1 -0
  20. package/dist/DonutChart.cjs +122 -0
  21. package/dist/DonutChart.cjs.map +1 -0
  22. package/dist/DonutChart.js +120 -0
  23. package/dist/DonutChart.js.map +1 -0
  24. package/dist/FunnelChart.cjs +422 -0
  25. package/dist/FunnelChart.cjs.map +1 -0
  26. package/dist/FunnelChart.js +420 -0
  27. package/dist/FunnelChart.js.map +1 -0
  28. package/dist/GradientRadial.cjs +51 -0
  29. package/dist/GradientRadial.cjs.map +1 -0
  30. package/dist/GradientRadial.js +49 -0
  31. package/dist/GradientRadial.js.map +1 -0
  32. package/dist/HeatmapChart.cjs +146 -0
  33. package/dist/HeatmapChart.cjs.map +1 -0
  34. package/dist/HeatmapChart.js +144 -0
  35. package/dist/HeatmapChart.js.map +1 -0
  36. package/dist/LineAreaChart.cjs +98 -0
  37. package/dist/LineAreaChart.cjs.map +1 -0
  38. package/dist/LineAreaChart.js +96 -0
  39. package/dist/LineAreaChart.js.map +1 -0
  40. package/dist/MixedChart.cjs +195 -0
  41. package/dist/MixedChart.cjs.map +1 -0
  42. package/dist/MixedChart.js +193 -0
  43. package/dist/MixedChart.js.map +1 -0
  44. package/dist/RadarChart.cjs +109 -0
  45. package/dist/RadarChart.cjs.map +1 -0
  46. package/dist/RadarChart.js +107 -0
  47. package/dist/RadarChart.js.map +1 -0
  48. package/dist/RadialBarChart.cjs +99 -0
  49. package/dist/RadialBarChart.cjs.map +1 -0
  50. package/dist/RadialBarChart.js +97 -0
  51. package/dist/RadialBarChart.js.map +1 -0
  52. package/dist/RangeBarChart.cjs +218 -0
  53. package/dist/RangeBarChart.cjs.map +1 -0
  54. package/dist/RangeBarChart.js +216 -0
  55. package/dist/RangeBarChart.js.map +1 -0
  56. package/dist/RealtimeChart.cjs +173 -0
  57. package/dist/RealtimeChart.cjs.map +1 -0
  58. package/dist/RealtimeChart.js +171 -0
  59. package/dist/RealtimeChart.js.map +1 -0
  60. package/dist/ScatterChart.cjs +134 -0
  61. package/dist/ScatterChart.cjs.map +1 -0
  62. package/dist/ScatterChart.js +131 -0
  63. package/dist/ScatterChart.js.map +1 -0
  64. package/dist/SemiCircleGauge.cjs +142 -0
  65. package/dist/SemiCircleGauge.cjs.map +1 -0
  66. package/dist/SemiCircleGauge.js +140 -0
  67. package/dist/SemiCircleGauge.js.map +1 -0
  68. package/dist/Sparkline.cjs +117 -0
  69. package/dist/Sparkline.cjs.map +1 -0
  70. package/dist/Sparkline.js +115 -0
  71. package/dist/Sparkline.js.map +1 -0
  72. package/dist/StrokedGauge.cjs +94 -0
  73. package/dist/StrokedGauge.cjs.map +1 -0
  74. package/dist/StrokedGauge.js +92 -0
  75. package/dist/StrokedGauge.js.map +1 -0
  76. package/dist/TreemapChart.cjs +263 -0
  77. package/dist/TreemapChart.cjs.map +1 -0
  78. package/dist/TreemapChart.js +261 -0
  79. package/dist/TreemapChart.js.map +1 -0
  80. package/dist/WaterfallChart.cjs +235 -0
  81. package/dist/WaterfallChart.cjs.map +1 -0
  82. package/dist/WaterfallChart.js +233 -0
  83. package/dist/WaterfallChart.js.map +1 -0
  84. package/dist/WorldMap.cjs +2088 -0
  85. package/dist/WorldMap.cjs.map +1 -0
  86. package/dist/WorldMap.js +603 -0
  87. package/dist/WorldMap.js.map +1 -0
  88. package/dist/chunk-3N43QT36.js +60 -0
  89. package/dist/chunk-3N43QT36.js.map +1 -0
  90. package/dist/chunk-5C2RLJYZ.js +11 -0
  91. package/dist/chunk-5C2RLJYZ.js.map +1 -0
  92. package/dist/chunk-6ALKZLN2.js +127 -0
  93. package/dist/chunk-6ALKZLN2.js.map +1 -0
  94. package/dist/chunk-6BKLL7LZ.cjs +30 -0
  95. package/dist/chunk-6BKLL7LZ.cjs.map +1 -0
  96. package/dist/chunk-6NRRABPF.cjs +64 -0
  97. package/dist/chunk-6NRRABPF.cjs.map +1 -0
  98. package/dist/chunk-AAYHG7YK.cjs +30 -0
  99. package/dist/chunk-AAYHG7YK.cjs.map +1 -0
  100. package/dist/chunk-AOSO5QHL.js +19 -0
  101. package/dist/chunk-AOSO5QHL.js.map +1 -0
  102. package/dist/chunk-BFEDLXVW.js +12 -0
  103. package/dist/chunk-BFEDLXVW.js.map +1 -0
  104. package/dist/chunk-DBZQI4HM.cjs +14 -0
  105. package/dist/chunk-DBZQI4HM.cjs.map +1 -0
  106. package/dist/chunk-F2PMFYJ5.cjs +40 -0
  107. package/dist/chunk-F2PMFYJ5.cjs.map +1 -0
  108. package/dist/chunk-FUZW3H5X.js +38 -0
  109. package/dist/chunk-FUZW3H5X.js.map +1 -0
  110. package/dist/chunk-GDZLYYL2.js +27 -0
  111. package/dist/chunk-GDZLYYL2.js.map +1 -0
  112. package/dist/chunk-GVTMZYOM.cjs +30 -0
  113. package/dist/chunk-GVTMZYOM.cjs.map +1 -0
  114. package/dist/chunk-GZRMVE4X.cjs +131 -0
  115. package/dist/chunk-GZRMVE4X.cjs.map +1 -0
  116. package/dist/chunk-HMH6DI7U.js +27 -0
  117. package/dist/chunk-HMH6DI7U.js.map +1 -0
  118. package/dist/chunk-ICL5K2CW.js +280 -0
  119. package/dist/chunk-ICL5K2CW.js.map +1 -0
  120. package/dist/chunk-IW6EWB26.cjs +21 -0
  121. package/dist/chunk-IW6EWB26.cjs.map +1 -0
  122. package/dist/chunk-K3R7JGOW.cjs +18 -0
  123. package/dist/chunk-K3R7JGOW.cjs.map +1 -0
  124. package/dist/chunk-LT3UC65O.cjs +68 -0
  125. package/dist/chunk-LT3UC65O.cjs.map +1 -0
  126. package/dist/chunk-MN4CDVOS.cjs +63 -0
  127. package/dist/chunk-MN4CDVOS.cjs.map +1 -0
  128. package/dist/chunk-OCD6JIIX.js +23 -0
  129. package/dist/chunk-OCD6JIIX.js.map +1 -0
  130. package/dist/chunk-RILUG7JB.js +44 -0
  131. package/dist/chunk-RILUG7JB.js.map +1 -0
  132. package/dist/chunk-RLHGPHC7.cjs +51 -0
  133. package/dist/chunk-RLHGPHC7.cjs.map +1 -0
  134. package/dist/chunk-SGG7XKOY.js +58 -0
  135. package/dist/chunk-SGG7XKOY.js.map +1 -0
  136. package/dist/chunk-T3K6Q34U.cjs +82 -0
  137. package/dist/chunk-T3K6Q34U.cjs.map +1 -0
  138. package/dist/chunk-TPH5T3DA.cjs +282 -0
  139. package/dist/chunk-TPH5T3DA.cjs.map +1 -0
  140. package/dist/chunk-TYQWZR3S.cjs +13 -0
  141. package/dist/chunk-TYQWZR3S.cjs.map +1 -0
  142. package/dist/chunk-UATB2IRY.js +51 -0
  143. package/dist/chunk-UATB2IRY.js.map +1 -0
  144. package/dist/chunk-UJIV5PVI.js +13 -0
  145. package/dist/chunk-UJIV5PVI.js.map +1 -0
  146. package/dist/chunk-URNXLVSK.js +44 -0
  147. package/dist/chunk-URNXLVSK.js.map +1 -0
  148. package/dist/chunk-VIOSQN4Z.js +79 -0
  149. package/dist/chunk-VIOSQN4Z.js.map +1 -0
  150. package/dist/chunk-X3YZP5WF.cjs +46 -0
  151. package/dist/chunk-X3YZP5WF.cjs.map +1 -0
  152. package/dist/chunk-YWYF5CCJ.js +61 -0
  153. package/dist/chunk-YWYF5CCJ.js.map +1 -0
  154. package/dist/chunk-Z4LZFMDH.cjs +60 -0
  155. package/dist/chunk-Z4LZFMDH.cjs.map +1 -0
  156. package/dist/index.cjs +154 -1166
  157. package/dist/index.cjs.map +1 -1
  158. package/dist/index.d.cts +470 -80
  159. package/dist/index.d.ts +470 -80
  160. package/dist/index.js +23 -1144
  161. package/dist/index.js.map +1 -1
  162. package/dist/theme.cjs +88 -0
  163. package/dist/theme.cjs.map +1 -0
  164. package/dist/theme.js +84 -0
  165. package/dist/theme.js.map +1 -0
  166. package/package.json +23 -12
@@ -0,0 +1,603 @@
1
+ "use client";
2
+ import { TooltipCard } from './chunk-VIOSQN4Z.js';
3
+ import { PANEL, TEXT, TRACK, SEQUENTIAL, MUTED, BORDER } from './chunk-UATB2IRY.js';
4
+ import { geoNaturalEarth1, geoPath } from 'd3-geo';
5
+ import { useRef, useMemo, useState } from 'react';
6
+ import { feature } from 'topojson-client';
7
+ import { jsxs, jsx } from 'react/jsx-runtime';
8
+
9
+ // src/world-map-codes.ts
10
+ var NUMERIC_TO_ALPHA2 = {
11
+ "004": "AF",
12
+ "008": "AL",
13
+ "010": "AQ",
14
+ "012": "DZ",
15
+ "016": "AS",
16
+ "020": "AD",
17
+ "024": "AO",
18
+ "028": "AG",
19
+ "031": "AZ",
20
+ "032": "AR",
21
+ "036": "AU",
22
+ "040": "AT",
23
+ "044": "BS",
24
+ "048": "BH",
25
+ "050": "BD",
26
+ "051": "AM",
27
+ "052": "BB",
28
+ "056": "BE",
29
+ "060": "BM",
30
+ "064": "BT",
31
+ "068": "BO",
32
+ "070": "BA",
33
+ "072": "BW",
34
+ "074": "BV",
35
+ "076": "BR",
36
+ "084": "BZ",
37
+ "086": "IO",
38
+ "090": "SB",
39
+ "092": "VG",
40
+ "096": "BN",
41
+ "100": "BG",
42
+ "104": "MM",
43
+ "108": "BI",
44
+ "112": "BY",
45
+ "116": "KH",
46
+ "120": "CM",
47
+ "124": "CA",
48
+ "132": "CV",
49
+ "136": "KY",
50
+ "140": "CF",
51
+ "144": "LK",
52
+ "148": "TD",
53
+ "152": "CL",
54
+ "156": "CN",
55
+ "158": "TW",
56
+ "162": "CX",
57
+ "166": "CC",
58
+ "170": "CO",
59
+ "174": "KM",
60
+ "175": "YT",
61
+ "178": "CG",
62
+ "180": "CD",
63
+ "184": "CK",
64
+ "188": "CR",
65
+ "191": "HR",
66
+ "192": "CU",
67
+ "196": "CY",
68
+ "203": "CZ",
69
+ "204": "BJ",
70
+ "208": "DK",
71
+ "212": "DM",
72
+ "214": "DO",
73
+ "218": "EC",
74
+ "222": "SV",
75
+ "226": "GQ",
76
+ "231": "ET",
77
+ "232": "ER",
78
+ "233": "EE",
79
+ "234": "FO",
80
+ "238": "FK",
81
+ "239": "GS",
82
+ "242": "FJ",
83
+ "246": "FI",
84
+ "248": "AX",
85
+ "250": "FR",
86
+ "254": "GF",
87
+ "258": "PF",
88
+ "260": "TF",
89
+ "262": "DJ",
90
+ "266": "GA",
91
+ "268": "GE",
92
+ "270": "GM",
93
+ "275": "PS",
94
+ "276": "DE",
95
+ "288": "GH",
96
+ "292": "GI",
97
+ "296": "KI",
98
+ "300": "GR",
99
+ "304": "GL",
100
+ "308": "GD",
101
+ "312": "GP",
102
+ "316": "GU",
103
+ "320": "GT",
104
+ "324": "GN",
105
+ "328": "GY",
106
+ "332": "HT",
107
+ "334": "HM",
108
+ "336": "VA",
109
+ "340": "HN",
110
+ "344": "HK",
111
+ "348": "HU",
112
+ "352": "IS",
113
+ "356": "IN",
114
+ "360": "ID",
115
+ "364": "IR",
116
+ "368": "IQ",
117
+ "372": "IE",
118
+ "376": "IL",
119
+ "380": "IT",
120
+ "384": "CI",
121
+ "388": "JM",
122
+ "392": "JP",
123
+ "398": "KZ",
124
+ "400": "JO",
125
+ "404": "KE",
126
+ "408": "KP",
127
+ "410": "KR",
128
+ "414": "KW",
129
+ "417": "KG",
130
+ "418": "LA",
131
+ "422": "LB",
132
+ "426": "LS",
133
+ "428": "LV",
134
+ "430": "LR",
135
+ "434": "LY",
136
+ "438": "LI",
137
+ "440": "LT",
138
+ "442": "LU",
139
+ "446": "MO",
140
+ "450": "MG",
141
+ "454": "MW",
142
+ "458": "MY",
143
+ "462": "MV",
144
+ "466": "ML",
145
+ "470": "MT",
146
+ "474": "MQ",
147
+ "478": "MR",
148
+ "480": "MU",
149
+ "484": "MX",
150
+ "492": "MC",
151
+ "496": "MN",
152
+ "498": "MD",
153
+ "499": "ME",
154
+ "500": "MS",
155
+ "504": "MA",
156
+ "508": "MZ",
157
+ "512": "OM",
158
+ "516": "NA",
159
+ "520": "NR",
160
+ "524": "NP",
161
+ "528": "NL",
162
+ "531": "CW",
163
+ "533": "AW",
164
+ "534": "SX",
165
+ "535": "BQ",
166
+ "540": "NC",
167
+ "548": "VU",
168
+ "554": "NZ",
169
+ "558": "NI",
170
+ "562": "NE",
171
+ "566": "NG",
172
+ "570": "NU",
173
+ "574": "NF",
174
+ "578": "NO",
175
+ "580": "MP",
176
+ "581": "UM",
177
+ "583": "FM",
178
+ "584": "MH",
179
+ "585": "PW",
180
+ "586": "PK",
181
+ "591": "PA",
182
+ "598": "PG",
183
+ "600": "PY",
184
+ "604": "PE",
185
+ "608": "PH",
186
+ "612": "PN",
187
+ "616": "PL",
188
+ "620": "PT",
189
+ "624": "GW",
190
+ "626": "TL",
191
+ "630": "PR",
192
+ "634": "QA",
193
+ "638": "RE",
194
+ "642": "RO",
195
+ "643": "RU",
196
+ "646": "RW",
197
+ "652": "BL",
198
+ "654": "SH",
199
+ "659": "KN",
200
+ "660": "AI",
201
+ "662": "LC",
202
+ "663": "MF",
203
+ "666": "PM",
204
+ "670": "VC",
205
+ "674": "SM",
206
+ "678": "ST",
207
+ "682": "SA",
208
+ "686": "SN",
209
+ "688": "RS",
210
+ "690": "SC",
211
+ "694": "SL",
212
+ "702": "SG",
213
+ "703": "SK",
214
+ "704": "VN",
215
+ "705": "SI",
216
+ "706": "SO",
217
+ "710": "ZA",
218
+ "716": "ZW",
219
+ "724": "ES",
220
+ "728": "SS",
221
+ "729": "SD",
222
+ "732": "EH",
223
+ "740": "SR",
224
+ "744": "SJ",
225
+ "748": "SZ",
226
+ "752": "SE",
227
+ "756": "CH",
228
+ "760": "SY",
229
+ "762": "TJ",
230
+ "764": "TH",
231
+ "768": "TG",
232
+ "772": "TK",
233
+ "776": "TO",
234
+ "780": "TT",
235
+ "784": "AE",
236
+ "788": "TN",
237
+ "792": "TR",
238
+ "795": "TM",
239
+ "796": "TC",
240
+ "798": "TV",
241
+ "800": "UG",
242
+ "804": "UA",
243
+ "807": "MK",
244
+ "818": "EG",
245
+ "826": "GB",
246
+ "831": "GG",
247
+ "832": "JE",
248
+ "833": "IM",
249
+ "834": "TZ",
250
+ "840": "US",
251
+ "850": "VI",
252
+ "854": "BF",
253
+ "858": "UY",
254
+ "860": "UZ",
255
+ "862": "VE",
256
+ "876": "WF",
257
+ "882": "WS",
258
+ "887": "YE",
259
+ "894": "ZM"
260
+ };
261
+
262
+ // src/world-map.ts
263
+ var STEPS = 5;
264
+ var clamp = (value, min, max) => Math.min(Math.max(value, min ?? -Infinity), max ?? Infinity);
265
+ var scaleOf = (values, min, max) => {
266
+ const [low, high] = min !== void 0 && max !== void 0 && min > max ? [max, min] : [min, max];
267
+ const sorted = values.filter(Number.isFinite).map((value) => clamp(value, low, high)).sort((a, b) => a - b);
268
+ if (sorted.length === 0) return void 0;
269
+ const thresholds = [1, 2, 3, 4].map((q) => sorted[Math.floor(sorted.length * q / STEPS)]);
270
+ return { thresholds, bounds: [low ?? sorted[0], ...thresholds], min: low, max: high };
271
+ };
272
+ var stepOf = (value, scale) => {
273
+ const clamped = clamp(value, scale.min, scale.max);
274
+ return scale.thresholds.filter((threshold) => clamped >= threshold).length;
275
+ };
276
+ var ranked = (countries) => countries.filter((country) => country.value !== void 0).sort((a, b) => b.value - a.value || a.name.localeCompare(b.name));
277
+ var walk = (order, current, delta) => {
278
+ const index = order.findIndex((country) => country.code === current);
279
+ if (index < 0) return order[0];
280
+ return order[Math.min(Math.max(index + delta, 0), order.length - 1)];
281
+ };
282
+ var VIEW_WIDTH = 960;
283
+ var MARGIN = 2;
284
+ var ANTARCTICA = "010";
285
+ var TIP_GAP = 6;
286
+ var POINTER_GAP = 14;
287
+ var HIDDEN = {
288
+ position: "absolute",
289
+ width: 1,
290
+ height: 1,
291
+ margin: -1,
292
+ padding: 0,
293
+ overflow: "hidden",
294
+ clipPath: "inset(50%)",
295
+ whiteSpace: "nowrap",
296
+ border: 0
297
+ };
298
+ var shapesOf = (geography) => {
299
+ const countries = geography.objects.countries;
300
+ if (!countries) {
301
+ throw new Error("WorldMap: `geography` has no `countries` object");
302
+ }
303
+ const collection = feature(geography, countries);
304
+ const features = (collection.type === "FeatureCollection" ? collection.features : [collection]).filter((item) => String(item.id).padStart(3, "0") !== ANTARCTICA);
305
+ const world = { type: "FeatureCollection", features };
306
+ const projection = geoNaturalEarth1().fitWidth(VIEW_WIDTH - 2 * MARGIN, world);
307
+ const [x, y] = projection.translate();
308
+ projection.translate([x + MARGIN, y + MARGIN]);
309
+ const path = geoPath(projection);
310
+ const [, [, bottom]] = path.bounds(world);
311
+ const shapes = features.flatMap((item) => {
312
+ const d = path(item);
313
+ if (!d) return [];
314
+ const name = item.properties?.name;
315
+ return [
316
+ {
317
+ code: item.id === void 0 ? void 0 : NUMERIC_TO_ALPHA2[String(item.id).padStart(3, "0")],
318
+ name: typeof name === "string" ? name : "",
319
+ d
320
+ }
321
+ ];
322
+ });
323
+ return { shapes, viewHeight: Math.ceil(bottom) + MARGIN };
324
+ };
325
+ var WorldMap = ({
326
+ data,
327
+ geography,
328
+ formatValue = String,
329
+ label,
330
+ min,
331
+ max,
332
+ showLegend = true,
333
+ onSelect,
334
+ ariaLabel,
335
+ height,
336
+ width
337
+ }) => {
338
+ const frame = useRef(null);
339
+ const { shapes, viewHeight } = useMemo(() => shapesOf(geography), [geography]);
340
+ const [hover, setHover] = useState();
341
+ const [focus, setFocus] = useState();
342
+ const [lastKey, setLastKey] = useState();
343
+ const valued = shapes.map((shape) => {
344
+ const value = shape.code === void 0 ? void 0 : data[shape.code];
345
+ return { ...shape, value: Number.isFinite(value) ? value : void 0 };
346
+ });
347
+ const order = ranked(
348
+ valued.filter((country) => country.code !== void 0)
349
+ );
350
+ const scale = scaleOf(
351
+ order.map((country) => country.value),
352
+ min,
353
+ max
354
+ );
355
+ const countries = valued.map((country) => ({
356
+ ...country,
357
+ step: scale && country.value !== void 0 ? stepOf(country.value, scale) : void 0
358
+ }));
359
+ const byCode = new Map(
360
+ countries.flatMap((country) => country.code ? [[country.code, country]] : [])
361
+ );
362
+ const interactive = order.length > 0;
363
+ const stepColor = (step) => step === void 0 ? TRACK : SEQUENTIAL[step];
364
+ const name = ariaLabel ?? (interactive ? `World map, ${label ?? "value"} by country, from ${formatValue(order[order.length - 1].value)} to ${formatValue(order[0].value)}` : "World map");
365
+ const tip = hover ?? focus;
366
+ const tipCountry = tip && byCode.get(tip.code);
367
+ const anchor = (code, x, top, bottom, gap) => {
368
+ const host = frame.current.getBoundingClientRect();
369
+ const middle = x - host.left;
370
+ const align = middle < host.width / 3 ? "start" : middle > 2 * host.width / 3 ? "end" : "center";
371
+ return {
372
+ code,
373
+ x: middle,
374
+ top: top - host.top - gap,
375
+ bottom: bottom - host.top + gap,
376
+ align,
377
+ // Not enough room above for the card: it goes under.
378
+ below: top - host.top < 90
379
+ };
380
+ };
381
+ const tipAtPointer = (code, event) => anchor(code, event.clientX, event.clientY, event.clientY, POINTER_GAP - TIP_GAP);
382
+ const tipAtCountry = (code) => {
383
+ const element = frame.current?.querySelector(`[data-code="${code}"]`);
384
+ if (!element) return void 0;
385
+ const box = element.getBoundingClientRect();
386
+ const middle = box.top + box.height / 2;
387
+ return anchor(code, box.left + box.width / 2, middle, middle, 0);
388
+ };
389
+ const goTo = (country) => {
390
+ if (!country) return;
391
+ setLastKey(country.code);
392
+ setFocus(tipAtCountry(country.code));
393
+ };
394
+ const keyDown = (event) => {
395
+ const current = focus?.code ?? lastKey;
396
+ const targets = {
397
+ ArrowRight: () => walk(order, current, 1),
398
+ ArrowDown: () => walk(order, current, 1),
399
+ ArrowLeft: () => walk(order, current, -1),
400
+ ArrowUp: () => walk(order, current, -1),
401
+ Home: () => order[0],
402
+ End: () => order[order.length - 1]
403
+ };
404
+ if (targets[event.key]) {
405
+ event.preventDefault();
406
+ goTo(targets[event.key]());
407
+ } else if (onSelect && (event.key === "Enter" || event.key === " ") && focus) {
408
+ event.preventDefault();
409
+ onSelect(focus.code);
410
+ }
411
+ };
412
+ const focusIn = (event) => {
413
+ if (event.target === event.currentTarget && event.currentTarget.matches(":focus-visible")) {
414
+ goTo(order.find((country) => country.code === lastKey) ?? order[0]);
415
+ }
416
+ };
417
+ const focusOut = (event) => {
418
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocus(void 0);
419
+ };
420
+ const tipStyle = tip && {
421
+ position: "absolute",
422
+ left: tip.x,
423
+ top: tip.below ? tip.bottom : tip.top,
424
+ transform: `translate(${{ start: "0", center: "-50%", end: "-100%" }[tip.align]}, ${tip.below ? "0" : "-100%"})`,
425
+ zIndex: 10,
426
+ pointerEvents: "none"
427
+ };
428
+ const active = tipCountry?.value === void 0 ? void 0 : tipCountry;
429
+ const legend = showLegend && scale && /* @__PURE__ */ jsx(Legend, { scale, format: formatValue });
430
+ return /* @__PURE__ */ jsxs(
431
+ "div",
432
+ {
433
+ "data-world-map": "",
434
+ style: {
435
+ position: "relative",
436
+ display: "flex",
437
+ flexDirection: "column",
438
+ gap: "0.75rem",
439
+ width: width ?? "100%",
440
+ height,
441
+ maxWidth: "100%",
442
+ minWidth: 0
443
+ },
444
+ children: [
445
+ /* @__PURE__ */ jsxs(
446
+ "div",
447
+ {
448
+ ref: frame,
449
+ role: interactive ? "application" : void 0,
450
+ "aria-label": interactive ? name : void 0,
451
+ tabIndex: interactive ? 0 : void 0,
452
+ onKeyDown: interactive ? keyDown : void 0,
453
+ onFocus: interactive ? focusIn : void 0,
454
+ onBlur: interactive ? focusOut : void 0,
455
+ style: {
456
+ position: "relative",
457
+ flex: height === void 0 ? void 0 : "1 1 0",
458
+ minHeight: 0,
459
+ // The country outline and the tooltip show where the keyboard is.
460
+ outline: "none"
461
+ },
462
+ children: [
463
+ /* @__PURE__ */ jsxs(
464
+ "svg",
465
+ {
466
+ role: "img",
467
+ "aria-label": name,
468
+ viewBox: `0 0 ${VIEW_WIDTH} ${viewHeight}`,
469
+ style: {
470
+ display: "block",
471
+ width: "100%",
472
+ height: height === void 0 ? "auto" : "100%"
473
+ },
474
+ children: [
475
+ countries.map((country, i) => {
476
+ const code = country.code;
477
+ const has = code !== void 0 && country.value !== void 0;
478
+ return /* @__PURE__ */ jsx(
479
+ "path",
480
+ {
481
+ d: country.d,
482
+ "data-code": has ? code : void 0,
483
+ "data-step": country.step,
484
+ fill: stepColor(country.step),
485
+ stroke: PANEL,
486
+ strokeWidth: 0.5,
487
+ strokeLinejoin: "round",
488
+ style: has && onSelect ? { cursor: "pointer" } : void 0,
489
+ onMouseEnter: has ? (event) => setHover(tipAtPointer(code, event)) : void 0,
490
+ onMouseMove: has ? (event) => setHover(tipAtPointer(code, event)) : void 0,
491
+ onMouseLeave: has ? () => setHover(void 0) : void 0,
492
+ onClick: has && onSelect ? () => onSelect(code) : void 0
493
+ },
494
+ i
495
+ );
496
+ }),
497
+ active && // The same outline for the pointer and the keyboard, in the text color:
498
+ // an accent one would vanish on the darkest steps. Drawn last to sit
499
+ // above the neighbors' borders.
500
+ /* @__PURE__ */ jsx(
501
+ "path",
502
+ {
503
+ d: active.d,
504
+ "data-world-active": "",
505
+ fill: "none",
506
+ stroke: TEXT,
507
+ strokeWidth: 1.6,
508
+ strokeLinejoin: "round",
509
+ pointerEvents: "none"
510
+ }
511
+ )
512
+ ]
513
+ }
514
+ ),
515
+ tip && tipCountry && tipCountry.value !== void 0 && tipStyle && /* @__PURE__ */ jsx("div", { "data-world-tooltip": "", "aria-hidden": true, style: tipStyle, children: /* @__PURE__ */ jsx(
516
+ TooltipCard,
517
+ {
518
+ title: tipCountry.name,
519
+ rows: [
520
+ {
521
+ name: label ?? "Value",
522
+ value: formatValue(tipCountry.value),
523
+ color: stepColor(tipCountry.step)
524
+ }
525
+ ]
526
+ }
527
+ ) }),
528
+ interactive && /* @__PURE__ */ jsx("span", { "data-world-status": "", role: "status", "aria-live": "polite", style: HIDDEN, children: focus && tipCountry && tipCountry.value !== void 0 ? `${tipCountry.name}, ${label ?? "Value"}: ${formatValue(tipCountry.value)}` : "" })
529
+ ]
530
+ }
531
+ ),
532
+ interactive && /* @__PURE__ */ jsx("div", { style: HIDDEN, children: /* @__PURE__ */ jsxs("table", { "data-world-table": "", children: [
533
+ /* @__PURE__ */ jsx("caption", { children: name }),
534
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
535
+ /* @__PURE__ */ jsx("th", { scope: "col", children: "Country" }),
536
+ /* @__PURE__ */ jsx("th", { scope: "col", children: label ?? "Value" })
537
+ ] }) }),
538
+ /* @__PURE__ */ jsx("tbody", { children: order.map((country) => /* @__PURE__ */ jsxs("tr", { children: [
539
+ /* @__PURE__ */ jsx("th", { scope: "row", children: country.name }),
540
+ /* @__PURE__ */ jsx("td", { children: formatValue(country.value) })
541
+ ] }, country.code)) })
542
+ ] }) }),
543
+ legend
544
+ ]
545
+ }
546
+ );
547
+ };
548
+ var Legend = ({ scale, format }) => /* @__PURE__ */ jsxs(
549
+ "ul",
550
+ {
551
+ "data-world-legend": "",
552
+ style: {
553
+ display: "flex",
554
+ flexWrap: "wrap",
555
+ alignItems: "flex-end",
556
+ columnGap: 2,
557
+ rowGap: "0.5rem",
558
+ margin: 0,
559
+ padding: 0,
560
+ listStyle: "none",
561
+ fontSize: "var(--text-2xs, 0.6875rem)",
562
+ color: MUTED
563
+ },
564
+ children: [
565
+ SEQUENTIAL.map((color, i) => /* @__PURE__ */ jsxs("li", { style: { display: "flex", flexDirection: "column", gap: 4, minWidth: "2.75rem" }, children: [
566
+ /* @__PURE__ */ jsx(
567
+ "span",
568
+ {
569
+ "aria-hidden": true,
570
+ "data-world-swatch": "",
571
+ style: { height: 10, borderRadius: 2, background: color }
572
+ }
573
+ ),
574
+ /* @__PURE__ */ jsxs("span", { style: { fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap" }, children: [
575
+ format(scale.bounds[i]),
576
+ "+"
577
+ ] })
578
+ ] }, i)),
579
+ /* @__PURE__ */ jsxs("li", { style: { display: "flex", flexDirection: "column", gap: 4, marginLeft: "0.75rem" }, children: [
580
+ /* @__PURE__ */ jsx(
581
+ "span",
582
+ {
583
+ "aria-hidden": true,
584
+ "data-world-swatch": "",
585
+ style: {
586
+ width: "1.75rem",
587
+ height: 10,
588
+ borderRadius: 2,
589
+ background: TRACK,
590
+ border: `1px solid ${BORDER}`,
591
+ boxSizing: "border-box"
592
+ }
593
+ }
594
+ ),
595
+ /* @__PURE__ */ jsx("span", { style: { whiteSpace: "nowrap" }, children: "No data" })
596
+ ] })
597
+ ]
598
+ }
599
+ );
600
+
601
+ export { WorldMap };
602
+ //# sourceMappingURL=WorldMap.js.map
603
+ //# sourceMappingURL=WorldMap.js.map