col-browser 2.4.0 → 2.6.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 (45) hide show
  1. package/README.md +34 -2
  2. package/es/bibtex.js +1 -1
  3. package/es/chunks/{BibTex-79CCKAOK.js → BibTex-DRE71Hg-.js} +2 -2
  4. package/es/chunks/{BibTex-79CCKAOK.js.map → BibTex-DRE71Hg-.js.map} +1 -1
  5. package/es/chunks/{DatasetCitation-BXtAmjdZ.js → DatasetCitation-Cep2dces.js} +2 -2
  6. package/es/chunks/{DatasetCitation-BXtAmjdZ.js.map → DatasetCitation-Cep2dces.js.map} +1 -1
  7. package/es/chunks/{DatasetlogoWithFallback-Dava2uqZ.js → DatasetlogoWithFallback-Bb-kmHts.js} +2 -2
  8. package/es/chunks/{DatasetlogoWithFallback-Dava2uqZ.js.map → DatasetlogoWithFallback-Bb-kmHts.js.map} +1 -1
  9. package/es/chunks/Distributions-Czffme5Y.js +1185 -0
  10. package/es/chunks/Distributions-Czffme5Y.js.map +1 -0
  11. package/es/chunks/{MergedDataBadge-C1CgoRFz.js → MergedDataBadge-DK53L3R8.js} +2 -2
  12. package/es/chunks/{MergedDataBadge-C1CgoRFz.js.map → MergedDataBadge-DK53L3R8.js.map} +1 -1
  13. package/es/chunks/{TaxonBreakdown-DeWamLu_.js → TaxonBreakdown-DqdQ18QM.js} +2 -2
  14. package/es/chunks/{TaxonBreakdown-DeWamLu_.js.map → TaxonBreakdown-DqdQ18QM.js.map} +1 -1
  15. package/es/chunks/{XrGutter-CU7_QPAp.js → XrGutter-COJhHpia.js} +2 -2
  16. package/es/chunks/{XrGutter-CU7_QPAp.js.map → XrGutter-COJhHpia.js.map} +1 -1
  17. package/es/chunks/config--bs_09I6.js +32 -0
  18. package/es/chunks/config--bs_09I6.js.map +1 -0
  19. package/es/chunks/{dataset-BL6g4w0G.js → dataset-BZpjo3Yq.js} +2 -2
  20. package/es/chunks/{dataset-BL6g4w0G.js.map → dataset-BZpjo3Yq.js.map} +1 -1
  21. package/es/chunks/{enumeration-DM8Hb36g.js → enumeration-CV8i_q_O.js} +2 -2
  22. package/es/chunks/{enumeration-DM8Hb36g.js.map → enumeration-CV8i_q_O.js.map} +1 -1
  23. package/es/chunks/{sector-Qeo1zPxr.js → sector-ucUgPp75.js} +2 -2
  24. package/es/chunks/{sector-Qeo1zPxr.js.map → sector-ucUgPp75.js.map} +1 -1
  25. package/es/config.js +1 -1
  26. package/es/index.js +1 -1
  27. package/es/search.js +5 -5
  28. package/es/sourceDataset.js +4 -4
  29. package/es/sourceDatasetList.js +4 -4
  30. package/es/taxon.js +758 -754
  31. package/es/taxon.js.map +1 -1
  32. package/es/taxonBreakdown.js +2 -2
  33. package/es/taxonDistribution.js +21 -19
  34. package/es/taxonDistribution.js.map +1 -1
  35. package/es/tree.js +5 -5
  36. package/package.json +1 -1
  37. package/types/index.d.ts +25 -0
  38. package/umd/col-browser.js +67 -25
  39. package/umd/col-browser.js.map +1 -1
  40. package/umd/col-browser.min.js +4 -4
  41. package/umd/col-browser.min.js.map +1 -1
  42. package/es/chunks/Distributions-Bd4hFYdS.js +0 -1169
  43. package/es/chunks/Distributions-Bd4hFYdS.js.map +0 -1
  44. package/es/chunks/config-D1NH4DTr.js +0 -22
  45. package/es/chunks/config-D1NH4DTr.js.map +0 -1
@@ -0,0 +1,1185 @@
1
+ var it = Object.defineProperty;
2
+ var ct = (e, n, r) => n in e ? it(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r;
3
+ var X = (e, n, r) => ct(e, typeof n != "symbol" ? n + "" : n, r);
4
+ import { j as s } from "./jsx-runtime-BzflLqGi.js";
5
+ import * as Oe from "react";
6
+ import lt, { useState as k, useRef as C, useMemo as ae, useEffect as P } from "react";
7
+ import { Spin as dt, Popover as ut, Radio as fe } from "antd";
8
+ import { isArray as Ee, get as H, keyBy as pt, startCase as ft } from "lodash-es";
9
+ import { c as re, p as ht } from "./router-CssZk5qZ.js";
10
+ import { c as R } from "./config--bs_09I6.js";
11
+ import { E as mt } from "./ErrorMsg-K8k5PPTp.js";
12
+ import { I as gt } from "./AntdIcon-B1nMlqyh.js";
13
+ import { M as yt } from "./MergedDataBadge-DK53L3R8.js";
14
+ import { P as bt } from "./PresentationItem-C4yZ555-.js";
15
+ import V from "maplibre-gl";
16
+ import "maplibre-gl/dist/maplibre-gl.css";
17
+ import { r as xt, w as vt } from "./storage-BgdCo9fV.js";
18
+ var St = { icon: { tag: "svg", attrs: { viewBox: "64 64 896 896", focusable: "false" }, children: [{ tag: "path", attrs: { d: "M832 64H192c-17.7 0-32 14.3-32 32v832c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-260 72h96v209.9L621.5 312 572 347.4V136zm220 752H232V136h280v296.9c0 3.3 1 6.6 3 9.3a15.9 15.9 0 0022.3 3.7l83.8-59.9 81.4 59.4c2.7 2 6 3.1 9.4 3.1 8.8 0 16-7.2 16-16V136h64v752z" } }] }, name: "book", theme: "outlined" };
19
+ function ye() {
20
+ return ye = Object.assign ? Object.assign.bind() : function(e) {
21
+ for (var n = 1; n < arguments.length; n++) {
22
+ var r = arguments[n];
23
+ for (var a in r)
24
+ Object.prototype.hasOwnProperty.call(r, a) && (e[a] = r[a]);
25
+ }
26
+ return e;
27
+ }, ye.apply(this, arguments);
28
+ }
29
+ const jt = (e, n) => /* @__PURE__ */ Oe.createElement(gt, ye({}, e, {
30
+ ref: n,
31
+ icon: St
32
+ })), De = /* @__PURE__ */ Oe.forwardRef(jt);
33
+ process.env.NODE_ENV !== "production" && (De.displayName = "BookOutlined");
34
+ class It extends lt.Component {
35
+ constructor(r) {
36
+ super(r);
37
+ X(this, "getData", () => {
38
+ const { referenceId: r, datasetKey: a, references: o } = this.props;
39
+ if (r) {
40
+ const c = Ee(r) ? r : [r], u = [];
41
+ this.setState({ loading: !0 }), Promise.allSettled(
42
+ c.map(
43
+ (f) => H(o, f) ? Promise.resolve(u.push(o[f])) : re(
44
+ `${R.dataApi}dataset/${a}/reference/${f}`
45
+ ).then((d) => u.push(d.data)).catch((d) => this.setState({ error: d }))
46
+ )
47
+ ).then(() => this.setState({ reference: u, loading: !1 }));
48
+ }
49
+ });
50
+ X(this, "getContent", () => {
51
+ const { error: r, reference: a, loading: o } = this.state;
52
+ return o ? /* @__PURE__ */ s.jsx(dt, {}) : r ? /* @__PURE__ */ s.jsx(mt, { error: r }) : a.length === 1 ? a[0].citation : /* @__PURE__ */ s.jsx("ul", { children: a.map((c) => /* @__PURE__ */ s.jsx("li", { children: c.citation }, c.id)) });
53
+ });
54
+ X(this, "scrollToReference", (r, a) => {
55
+ const o = document.getElementById(`col-reference-${a}`);
56
+ o && (r.preventDefault(), o.scrollIntoView({ behavior: "smooth", block: "start" }));
57
+ });
58
+ X(this, "render", () => {
59
+ const { referenceId: r, referenceIndexMap: a, trigger: o } = this.props, c = this.props.maxInline || 4, u = Ee(r) ? r : [r];
60
+ let f = a && H(a, u[0]) ? (() => {
61
+ const d = u.slice(0, c), h = u.length - d.length;
62
+ return [
63
+ ...d.map((p) => /* @__PURE__ */ s.jsx(
64
+ "a",
65
+ {
66
+ className: "col-reference-link",
67
+ href: `#col-reference-${p}`,
68
+ onClick: (y) => this.scrollToReference(y, p),
69
+ children: `[${a[p]}]`
70
+ },
71
+ p
72
+ )),
73
+ h > 0 ? /* @__PURE__ */ s.jsx("span", { className: "col-reference-link", children: ` +${h}` }, "overflow") : null
74
+ ];
75
+ })() : /* @__PURE__ */ s.jsx(De, { style: { cursor: "pointer" } });
76
+ return r ? /* @__PURE__ */ s.jsx("div", { id: `reference_${r}`, style: this.props.style, children: /* @__PURE__ */ s.jsx(
77
+ ut,
78
+ {
79
+ getPopupContainer: () => document.getElementById(`reference_${r}`),
80
+ placement: this.props.placement || "left",
81
+ title: "Reference",
82
+ onOpenChange: (d) => d && this.getData(),
83
+ content: /* @__PURE__ */ s.jsx(
84
+ "div",
85
+ {
86
+ style: {
87
+ maxWidth: "500px",
88
+ maxHeight: "60vh",
89
+ overflowY: "auto"
90
+ },
91
+ children: this.getContent()
92
+ }
93
+ ),
94
+ trigger: o || "hover",
95
+ children: f
96
+ }
97
+ ) }, `reference_${r}`) : "";
98
+ });
99
+ this.state = {
100
+ reference: [],
101
+ loading: !1,
102
+ error: null
103
+ };
104
+ }
105
+ }
106
+ const ce = [
107
+ "subspecies",
108
+ "variety",
109
+ "subvariety",
110
+ "form",
111
+ "subform",
112
+ "infraspecific name"
113
+ ], ze = (e, n) => {
114
+ const r = n.indexOf(e);
115
+ return r === -1 ? [] : ce.filter((a) => n.indexOf(a) > r);
116
+ }, wt = 16, Lt = (e) => {
117
+ var n, r;
118
+ return ((n = e == null ? void 0 : e.area) == null ? void 0 : n.gazetteer) !== "text" && !!((r = e == null ? void 0 : e.area) != null && r.globalId);
119
+ }, kt = async (e, n, r) => {
120
+ const a = new Array(e.length);
121
+ let o = 0;
122
+ const c = Array.from({ length: Math.min(r, e.length) }, async () => {
123
+ for (; ; ) {
124
+ const u = o++;
125
+ if (u >= e.length) return;
126
+ a[u] = await n(e[u], u);
127
+ }
128
+ });
129
+ return await Promise.all(c), a;
130
+ }, Ct = async (e, n, r) => {
131
+ var f;
132
+ if (r.length === 0) return [];
133
+ const a = new URLSearchParams();
134
+ a.append("TAXON_ID", n), r.forEach((d) => a.append("rank", d)), ["accepted", "provisionally accepted"].forEach(
135
+ (d) => a.append("status", d)
136
+ ), a.append("limit", "1000");
137
+ const o = `${R.dataApi}dataset/${e}/nameusage/search?${a}`, c = await re(o);
138
+ return (((f = c == null ? void 0 : c.data) == null ? void 0 : f.result) || []).filter((d) => {
139
+ var h;
140
+ return (h = d == null ? void 0 : d.usage) == null ? void 0 : h.id;
141
+ }).map((d) => {
142
+ var h, p, y, M, E, L;
143
+ return {
144
+ id: d.usage.id,
145
+ scientificName: ((p = (h = d.usage) == null ? void 0 : h.name) == null ? void 0 : p.scientificName) || ((y = d.usage) == null ? void 0 : y.label) || d.usage.id,
146
+ rank: (E = (M = d.usage) == null ? void 0 : M.name) == null ? void 0 : E.rank,
147
+ parentId: (L = d.usage) == null ? void 0 : L.parentId
148
+ };
149
+ });
150
+ }, Rt = async (e, n) => {
151
+ const r = `${R.dataApi}dataset/${e}/taxon/${encodeURIComponent(n)}/distribution`;
152
+ try {
153
+ const a = await re(r);
154
+ return Array.isArray(a == null ? void 0 : a.data) ? a.data : [];
155
+ } catch {
156
+ return [];
157
+ }
158
+ }, Et = async ({ datasetKey: e, focalTaxon: n, rankOrder: r }) => {
159
+ var d;
160
+ const a = ze((d = n == null ? void 0 : n.name) == null ? void 0 : d.rank, r);
161
+ let o = !1, c = [];
162
+ try {
163
+ c = await Ct(e, n.id, a);
164
+ } catch {
165
+ return o = !0, { taxa: [], descendantsFailed: o };
166
+ }
167
+ const u = await kt(
168
+ c,
169
+ (h) => Rt(e, h.id),
170
+ wt
171
+ );
172
+ return { taxa: c.map((h, p) => {
173
+ const y = u[p] || [];
174
+ return { ...h, distributions: y, mappable: y.filter(Lt) };
175
+ }), descendantsFailed: o };
176
+ }, Fe = [
177
+ "#E58606",
178
+ "#5D69B1",
179
+ "#52BCA3",
180
+ "#99C945",
181
+ "#CC61B0",
182
+ "#24796C",
183
+ "#DAA51B",
184
+ "#2F8AC4",
185
+ "#764E9F",
186
+ "#ED645A",
187
+ "#CC3A8E",
188
+ "#A5AA99"
189
+ ], Be = (e, n) => {
190
+ const r = n.indexOf(e);
191
+ return r === -1 ? n.length : r;
192
+ }, Ft = (e, n) => {
193
+ const r = [...e].sort((o, c) => {
194
+ const u = Be(o.rank, n), f = Be(c.rank, n);
195
+ return u !== f ? u - f : o.scientificName.localeCompare(c.scientificName);
196
+ }), a = {};
197
+ return r.forEach((o, c) => {
198
+ a[o.id] = Fe[c % Fe.length];
199
+ }), a;
200
+ }, Bt = (e) => e ?? R.basemapStyle, Mt = /(^|\.)cartocdn\.com$/i, Gt = (e = R.cartoKey) => {
201
+ if (e)
202
+ return (n) => {
203
+ let r;
204
+ try {
205
+ r = new URL(n);
206
+ } catch {
207
+ return { url: n };
208
+ }
209
+ return !Mt.test(r.hostname) || r.searchParams.has("key") ? { url: n } : (r.searchParams.set("key", e), { url: r.toString() });
210
+ };
211
+ }, Nt = {
212
+ position: "absolute",
213
+ bottom: 8,
214
+ left: 8,
215
+ zIndex: 1e3,
216
+ background: "#fff",
217
+ borderRadius: 4,
218
+ boxShadow: "0 1px 4px rgba(0,0,0,0.2)",
219
+ padding: "6px 8px",
220
+ fontSize: 12,
221
+ lineHeight: 1.5,
222
+ maxWidth: 260
223
+ }, $t = {
224
+ maxHeight: 240,
225
+ overflowY: "auto"
226
+ }, He = {
227
+ fontWeight: 600,
228
+ marginTop: 4
229
+ }, _t = {
230
+ ...He,
231
+ marginTop: 0
232
+ }, Ve = {
233
+ display: "flex",
234
+ alignItems: "center",
235
+ gap: 6,
236
+ paddingLeft: 4
237
+ }, At = (e) => ({
238
+ display: "inline-block",
239
+ width: 12,
240
+ height: 12,
241
+ background: e,
242
+ border: "1px solid rgba(0,0,0,0.15)",
243
+ borderRadius: 2,
244
+ flex: "0 0 auto"
245
+ }), Pt = {
246
+ marginTop: 6,
247
+ cursor: "pointer",
248
+ color: "#1890ff",
249
+ fontSize: 11
250
+ }, Ot = {
251
+ marginTop: 4,
252
+ borderTop: "1px solid #eee",
253
+ paddingTop: 4,
254
+ color: "#666"
255
+ }, Ue = {
256
+ fontWeight: 600,
257
+ marginTop: 4
258
+ }, Dt = {
259
+ ...Ue,
260
+ marginTop: 0
261
+ }, zt = {
262
+ fontStyle: "italic",
263
+ paddingLeft: 4
264
+ }, Me = (e) => e.reduce((n, r) => n + r.taxa.length, 0), Ht = () => /* @__PURE__ */ s.jsxs("div", { style: Ve, children: [
265
+ /* @__PURE__ */ s.jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", children: /* @__PURE__ */ s.jsx(
266
+ "polygon",
267
+ {
268
+ points: "3,1 9,1 11,6 9,11 3,11 1,6",
269
+ fill: "#de1e6e",
270
+ stroke: "rgba(0,0,0,0.25)",
271
+ strokeWidth: "0.75"
272
+ }
273
+ ) }),
274
+ /* @__PURE__ */ s.jsx("span", { children: "GBIF occurrences" })
275
+ ] }), Vt = ({ visibleGroups: e, unmappableGroups: n, showGbif: r }) => {
276
+ const [a, o] = k(!1), c = Me(e), u = Me(n);
277
+ return c === 0 && u === 0 && !r ? null : /* @__PURE__ */ s.jsxs("div", { style: Nt, children: [
278
+ /* @__PURE__ */ s.jsxs("div", { style: $t, children: [
279
+ e.map((f, d) => /* @__PURE__ */ s.jsxs("div", { children: [
280
+ /* @__PURE__ */ s.jsx("div", { style: d === 0 ? _t : He, children: f.label }),
281
+ f.taxa.map((h) => /* @__PURE__ */ s.jsxs("div", { style: Ve, children: [
282
+ /* @__PURE__ */ s.jsx("span", { style: At(h.color) }),
283
+ /* @__PURE__ */ s.jsx("span", { style: { fontStyle: "italic" }, children: h.displayName || h.scientificName })
284
+ ] }, h.id))
285
+ ] }, f.rank)),
286
+ r && /* @__PURE__ */ s.jsx(Ht, {})
287
+ ] }),
288
+ u > 0 && /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
289
+ /* @__PURE__ */ s.jsxs(
290
+ "div",
291
+ {
292
+ style: Pt,
293
+ onClick: () => o((f) => !f),
294
+ children: [
295
+ a ? "− Hide" : "+",
296
+ " ",
297
+ u,
298
+ " without map data"
299
+ ]
300
+ }
301
+ ),
302
+ a && /* @__PURE__ */ s.jsx("div", { style: Ot, children: n.map((f, d) => /* @__PURE__ */ s.jsxs("div", { children: [
303
+ /* @__PURE__ */ s.jsx(
304
+ "div",
305
+ {
306
+ style: d === 0 ? Dt : Ue,
307
+ children: f.label
308
+ }
309
+ ),
310
+ f.taxa.map((h) => /* @__PURE__ */ s.jsx("div", { style: zt, children: h.displayName || h.scientificName }, h.id))
311
+ ] }, f.rank)) })
312
+ ] })
313
+ ] });
314
+ }, Ut = [
315
+ "establishmentMeans",
316
+ "degreeOfEstablishment",
317
+ "pathway",
318
+ "threatStatus",
319
+ "year",
320
+ "lifeStage"
321
+ ], Ke = [
322
+ { key: "nativeendemic", label: "Native endemic", color: "#0F8554" },
323
+ { key: "native", label: "Native", color: "#87C55F" },
324
+ { key: "nativereintroduced", label: "Native reintroduced", color: "#C9DB74" },
325
+ { key: "introduced", label: "Introduced", color: "#FE88B1" },
326
+ {
327
+ key: "introducedassistedcolonisation",
328
+ label: "Introduced assisted colonisation",
329
+ color: "#DCB0F2"
330
+ },
331
+ { key: "vagrant", label: "Vagrant", color: "#F6CF71" },
332
+ { key: "uncertain", label: "Uncertain", color: "#8BE0A4" }
333
+ ], We = Object.fromEntries(
334
+ Ke.map((e) => [e.key, e.color])
335
+ ), le = "#66C5CC", Kt = (e) => String(e || "").toLowerCase().replace(/[^a-z]/g, ""), Te = (e) => {
336
+ const n = e == null ? void 0 : e.establishmentMeans;
337
+ if (n == null || n === "") return null;
338
+ const r = Kt(n);
339
+ return We[r] ? r : "uncertain";
340
+ }, Wt = (e) => {
341
+ const n = Te(e);
342
+ return n == null ? le : We[n];
343
+ }, qe = "gbif-visible", Tt = (e) => xt(qe, e), Ge = (e) => vt(qe, e), qt = "/v2/map/occurrence/density/{z}/{x}/{y}@1x.png?srs=EPSG%3A3857&style=iNaturalist.poly&bin=hex&hexPerTile=64&hasCoordinate=true&hasGeospatialIssue=false&occurrenceStatus=PRESENT&checklistKey={checklistKey}&taxonKey={taxonKey}", Q = "col-focal-distributions", T = "col-focal-fill", he = "col-focal-line", ie = "col-gbif-occurrences", A = "col-gbif-occurrences", me = (e) => `col-descendant-${e}`, ee = (e) => `col-descendant-fill-${e}`, te = (e) => `col-descendant-line-${e}`, ge = /* @__PURE__ */ new Map(), Ne = (e, n) => {
344
+ const r = `${e}:${n}`;
345
+ if (ge.has(r)) return ge.get(r);
346
+ const a = `${R.dataApi}vocab/area/${r}`, o = re(a, {
347
+ headers: { Accept: "application/geo+json" }
348
+ }).then(
349
+ (c) => c.data,
350
+ () => null
351
+ );
352
+ return ge.set(r, o), o;
353
+ }, ne = (e) => String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), Ye = (e) => {
354
+ var a, o;
355
+ const n = ((a = e == null ? void 0 : e.area) == null ? void 0 : a.name) || ((o = e == null ? void 0 : e.area) == null ? void 0 : o.globalId) || "", r = Ut.map((c) => [c, e == null ? void 0 : e[c]]).filter(([, c]) => c != null && c !== "").map(
356
+ ([c, u]) => `<div><strong>${ne(c)}:</strong> ${ne(u)}</div>`
357
+ ).join("");
358
+ return `<div style="min-width:180px"><div style="font-weight:600;margin-bottom:4px">${ne(
359
+ n
360
+ )}</div>${r}</div>`;
361
+ }, Yt = (e, n) => `<div style="font-weight:600;font-style:italic;margin-bottom:4px">${ne(
362
+ e.scientificName
363
+ )}</div><div style="color:#888;margin-bottom:4px">${ne(e.rank || "")}</div>` + Ye(n), Zt = {
364
+ subspecies: "subspecies",
365
+ variety: "varieties",
366
+ subvariety: "subvarieties",
367
+ form: "forms",
368
+ subform: "subforms",
369
+ "infraspecific name": "infraspecific names"
370
+ }, $e = (e) => Zt[e] || e, Ze = (e) => {
371
+ if (!e) return "";
372
+ const n = e.trim().split(/\s+/);
373
+ return n[n.length - 1];
374
+ }, Jt = () => /* @__PURE__ */ s.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
375
+ /* @__PURE__ */ s.jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", children: /* @__PURE__ */ s.jsx(
376
+ "polygon",
377
+ {
378
+ points: "3,1 9,1 11,6 9,11 3,11 1,6",
379
+ fill: "#de1e6e",
380
+ stroke: "rgba(0,0,0,0.25)",
381
+ strokeWidth: "0.75"
382
+ }
383
+ ) }),
384
+ /* @__PURE__ */ s.jsx("span", { children: "GBIF occurrences" })
385
+ ] }), Xt = (e) => {
386
+ var u;
387
+ let n = 1 / 0, r = 1 / 0, a = -1 / 0, o = -1 / 0;
388
+ const c = (f) => {
389
+ if (typeof f[0] == "number") {
390
+ const [d, h] = f;
391
+ d < n && (n = d), d > a && (a = d), h < r && (r = h), h > o && (o = h);
392
+ } else
393
+ for (let d = 0; d < f.length; d++) c(f[d]);
394
+ };
395
+ for (let f = 0; f < e.length; f++) {
396
+ const d = (u = e[f]) == null ? void 0 : u.geometry;
397
+ d != null && d.coordinates && c(d.coordinates);
398
+ }
399
+ return n === 1 / 0 ? null : [
400
+ [n, r],
401
+ [a, o]
402
+ ];
403
+ }, _e = (e) => e ? e.type === "FeatureCollection" ? e.features || [] : [e] : [], Ae = () => {
404
+ var e;
405
+ return typeof ((e = V) == null ? void 0 : e.supported) == "function" ? V.supported() : typeof WebGLRenderingContext < "u";
406
+ }, Qt = ({
407
+ records: e,
408
+ onUnmappable: n,
409
+ datasetKey: r,
410
+ focalTaxon: a,
411
+ rankOrder: o,
412
+ gbifChecklistKey: c,
413
+ // true | null → show GBIF layer; false → GBIF API returned 0 occurrences,
414
+ // grey out the toggle and skip loading tiles. Defaults to true so the
415
+ // component works without the count check.
416
+ gbifAvailable: u = !0,
417
+ // MapLibre style URL or inline style object; falls back to the global
418
+ // `configure({ basemapStyle })` value. Changing it rebuilds the map.
419
+ basemapStyle: f
420
+ }) => {
421
+ var Re;
422
+ const d = C(null), h = C(null), p = C(null), y = C(null), M = C(/* @__PURE__ */ new Map()), E = C(/* @__PURE__ */ new Map()), L = C(/* @__PURE__ */ new Map()), O = C(!1), G = C(!1), N = C(/* @__PURE__ */ new Set()), [S, F] = k(null), [D, v] = k(!1), [x, $] = k({
423
+ status: "idle",
424
+ // idle | loading | ready | empty | error
425
+ taxa: []
426
+ }), [U, q] = k(!0), se = !!c && (!e || e.length === 0), [I, z] = k(
427
+ () => Tt(!0)
428
+ ), [_, be] = k(/* @__PURE__ */ new Set()), [Je, xe] = k(!1), de = C(!1), Xe = () => {
429
+ z((t) => {
430
+ const l = !t;
431
+ return Ge(l), l;
432
+ });
433
+ }, ve = () => {
434
+ z(!0), Ge(!0);
435
+ }, Se = ae(() => {
436
+ if (!(e != null && e.length)) return [];
437
+ const t = /* @__PURE__ */ new Set();
438
+ return e.forEach((l) => {
439
+ const i = Te(l);
440
+ i != null && t.add(i);
441
+ }), Ke.filter((l) => t.has(l.key));
442
+ }, [e]), Y = ae(() => x.status !== "ready" ? {} : Ft(
443
+ x.taxa.filter((t) => t.mappable.length > 0),
444
+ o || []
445
+ ), [x, o]), ue = ae(() => {
446
+ if (x.status !== "ready")
447
+ return { visibleGroups: [], unmappableGroups: [] };
448
+ const t = (m) => ({
449
+ ...m,
450
+ color: Y[m.id],
451
+ displayName: Ze(m.scientificName)
452
+ }), l = (m) => {
453
+ const j = {};
454
+ return m.forEach((b) => {
455
+ (j[b.rank] = j[b.rank] || []).push(t(b));
456
+ }), ce.filter((b) => j[b]).map((b) => ({
457
+ rank: b,
458
+ label: $e(b),
459
+ taxa: j[b]
460
+ }));
461
+ }, i = l(
462
+ x.taxa.filter(
463
+ (m) => m.mappable.length > 0 && _.has(m.id)
464
+ )
465
+ ), g = l(
466
+ x.taxa.filter((m) => m.mappable.length === 0)
467
+ );
468
+ return { visibleGroups: i, unmappableGroups: g };
469
+ }, [x, Y, _]), je = ue.visibleGroups.length > 0, oe = Bt(f), Ie = R.cartoKey, Qe = `${typeof oe == "string" ? oe : JSON.stringify(oe)}|${Ie || ""}`;
470
+ P(() => {
471
+ if (!d.current || p.current || !Ae()) return;
472
+ const t = new V.Map({
473
+ container: d.current,
474
+ style: oe,
475
+ transformRequest: Gt(Ie),
476
+ center: [0, 20],
477
+ zoom: 1,
478
+ minZoom: 0,
479
+ attributionControl: !1,
480
+ renderWorldCopies: !0
481
+ });
482
+ t.addControl(
483
+ new V.AttributionControl({ compact: !0 }),
484
+ "bottom-right"
485
+ ), t.addControl(
486
+ new V.NavigationControl({ showCompass: !1 }),
487
+ "top-left"
488
+ ), t.addControl(
489
+ new V.FullscreenControl({ container: h.current }),
490
+ "top-right"
491
+ ), p.current = t, t.on("load", () => {
492
+ F(t);
493
+ const i = t.getContainer().querySelector(".maplibregl-ctrl-attrib");
494
+ i && i.classList.remove("maplibregl-compact-show");
495
+ });
496
+ const l = typeof ResizeObserver < "u" ? new ResizeObserver(() => t.resize()) : null;
497
+ return l && l.observe(d.current), () => {
498
+ l && l.disconnect(), y.current && (y.current.remove(), y.current = null), t.remove(), p.current = null, O.current = !1, G.current = !1, N.current = /* @__PURE__ */ new Set(), F(null);
499
+ };
500
+ }, [Qe]), P(() => {
501
+ const t = S;
502
+ if (!t || !(e != null && e.length)) return;
503
+ let l = !1;
504
+ return v(!1), Promise.allSettled(
505
+ e.map(
506
+ (i) => Ne(i.area.gazetteer, i.area.id).then((g) => ({
507
+ record: i,
508
+ geojson: g
509
+ }))
510
+ )
511
+ ).then((i) => {
512
+ if (l || p.current !== t) return;
513
+ const g = [], m = /* @__PURE__ */ new Map();
514
+ let j = 0;
515
+ i.forEach((w, B) => {
516
+ if (w.status !== "fulfilled" || !w.value.geojson) {
517
+ j += 1;
518
+ return;
519
+ }
520
+ const { record: K, geojson: W } = w.value, pe = Wt(K), Z = `focal-${B}`;
521
+ m.set(Z, K), _e(W).forEach((J) => {
522
+ g.push({
523
+ ...J,
524
+ properties: {
525
+ ...J.properties || {},
526
+ _recordKey: Z,
527
+ _color: pe
528
+ }
529
+ });
530
+ });
531
+ }), M.current = m;
532
+ const b = { type: "FeatureCollection", features: g };
533
+ if (t.getSource(Q))
534
+ t.getSource(Q).setData(b);
535
+ else {
536
+ const w = t.getLayer(A) ? A : void 0;
537
+ t.addSource(Q, { type: "geojson", data: b }), t.addLayer(
538
+ {
539
+ id: T,
540
+ type: "fill",
541
+ source: Q,
542
+ paint: {
543
+ "fill-color": ["coalesce", ["get", "_color"], le],
544
+ "fill-opacity": 0.65
545
+ }
546
+ },
547
+ w
548
+ ), t.addLayer(
549
+ {
550
+ id: he,
551
+ type: "line",
552
+ source: Q,
553
+ paint: {
554
+ "line-color": ["coalesce", ["get", "_color"], le],
555
+ "line-width": 1
556
+ }
557
+ },
558
+ w
559
+ ), t.on("click", T, et), t.on("mouseenter", T, we), t.on("mouseleave", T, Le), O.current = !0;
560
+ }
561
+ if (g.length > 0) {
562
+ const w = Xt(g);
563
+ w && t.fitBounds(w, { padding: 20, animate: !1 });
564
+ }
565
+ typeof n == "function" && n(j), v(!0);
566
+ }), () => {
567
+ l = !0;
568
+ };
569
+ }, [S, e]);
570
+ const et = (t) => {
571
+ var j, b;
572
+ const l = p.current;
573
+ if (!l) return;
574
+ const i = (j = t.features) == null ? void 0 : j[0], g = (b = i == null ? void 0 : i.properties) == null ? void 0 : b._recordKey, m = g ? M.current.get(g) : null;
575
+ m && (y.current && y.current.remove(), y.current = new V.Popup({ closeButton: !0, maxWidth: "320px" }).setLngLat(t.lngLat).setHTML(Ye(m)).addTo(l));
576
+ }, we = () => {
577
+ const t = p.current;
578
+ t && (t.getCanvas().style.cursor = "pointer");
579
+ }, Le = () => {
580
+ const t = p.current;
581
+ t && (t.getCanvas().style.cursor = "");
582
+ };
583
+ P(() => {
584
+ const t = p.current;
585
+ if (!t || !O.current) return;
586
+ const l = U ? "visible" : "none";
587
+ t.getLayer(T) && t.setLayoutProperty(T, "visibility", l), t.getLayer(he) && t.setLayoutProperty(he, "visibility", l);
588
+ }, [U, D]), P(() => {
589
+ const t = S;
590
+ if (!t || ((() => {
591
+ t.getLayer(A) && t.removeLayer(A), t.getSource(ie) && t.removeSource(ie), G.current = !1;
592
+ })(), !c || !(a != null && a.id)) || u === !1) return;
593
+ const i = (R.gbifApi + qt).replace("{checklistKey}", encodeURIComponent(c)).replace("{taxonKey}", encodeURIComponent(a.id)), g = R.gbifPortal + "/occurrence/search?checklist_key=" + encodeURIComponent(c) + "&taxon_key=" + encodeURIComponent(a.id);
594
+ t.addSource(ie, {
595
+ type: "raster",
596
+ tiles: [i],
597
+ tileSize: 256,
598
+ attribution: '<a href="' + g + '" target="_blank" rel="noopener">GBIF</a> occurrence data'
599
+ }), t.addLayer({
600
+ id: A,
601
+ type: "raster",
602
+ source: ie,
603
+ paint: { "raster-opacity": 0.9 },
604
+ layout: { visibility: I ? "visible" : "none" }
605
+ }), G.current = !0;
606
+ }, [S, c, a == null ? void 0 : a.id, u]), P(() => {
607
+ const t = p.current;
608
+ if (!t || !G.current) return;
609
+ const l = I ? "visible" : "none";
610
+ t.getLayer(A) && t.setLayoutProperty(A, "visibility", l);
611
+ }, [I]);
612
+ const ke = (t) => _.has(t) ? "visible" : "none";
613
+ P(() => {
614
+ const t = S;
615
+ if (!t || (N.current.forEach((i) => {
616
+ t.getLayer(ee(i)) && t.removeLayer(ee(i)), t.getLayer(te(i)) && t.removeLayer(te(i)), t.getSource(me(i)) && t.removeSource(me(i));
617
+ }), N.current = /* @__PURE__ */ new Set(), E.current = /* @__PURE__ */ new Map(), L.current = /* @__PURE__ */ new Map(), x.status !== "ready")) return;
618
+ const l = Y;
619
+ x.taxa.forEach((i) => {
620
+ i.mappable.length !== 0 && (E.current.set(i.id, i), Promise.allSettled(
621
+ i.mappable.map(
622
+ (g) => Ne(g.area.gazetteer, g.area.id).then((m) => ({
623
+ record: g,
624
+ geojson: m
625
+ }))
626
+ )
627
+ ).then((g) => {
628
+ if (p.current !== t) return;
629
+ const m = [];
630
+ g.forEach((B, K) => {
631
+ if (B.status !== "fulfilled" || !B.value.geojson) return;
632
+ const { record: W, geojson: pe } = B.value, Z = `desc-${i.id}-${K}`;
633
+ L.current.set(Z, { taxon: i, record: W }), _e(pe).forEach((J) => {
634
+ m.push({
635
+ ...J,
636
+ properties: {
637
+ ...J.properties || {},
638
+ _recordKey: Z
639
+ }
640
+ });
641
+ });
642
+ });
643
+ const j = l[i.id] || le, b = { type: "FeatureCollection", features: m }, w = me(i.id);
644
+ if (p.current.getSource(w))
645
+ p.current.getSource(w).setData(b);
646
+ else {
647
+ p.current.addSource(w, { type: "geojson", data: b });
648
+ const B = ee(i.id), K = te(i.id), W = p.current.getLayer(A) ? A : void 0;
649
+ p.current.addLayer(
650
+ {
651
+ id: B,
652
+ type: "fill",
653
+ source: w,
654
+ paint: { "fill-color": j, "fill-opacity": 0.55 },
655
+ layout: { visibility: ke(i.id) }
656
+ },
657
+ W
658
+ ), p.current.addLayer(
659
+ {
660
+ id: K,
661
+ type: "line",
662
+ source: w,
663
+ paint: { "line-color": j, "line-width": 2 },
664
+ layout: { visibility: ke(i.id) }
665
+ },
666
+ W
667
+ ), p.current.on("click", B, tt), p.current.on("mouseenter", B, we), p.current.on("mouseleave", B, Le), N.current.add(i.id);
668
+ }
669
+ }));
670
+ });
671
+ }, [S, x, Y]);
672
+ const tt = (t) => {
673
+ var j, b;
674
+ const l = p.current;
675
+ if (!l) return;
676
+ const i = (j = t.features) == null ? void 0 : j[0], g = (b = i == null ? void 0 : i.properties) == null ? void 0 : b._recordKey, m = g ? L.current.get(g) : null;
677
+ m && (y.current && y.current.remove(), y.current = new V.Popup({ closeButton: !0, maxWidth: "320px" }).setLngLat(t.lngLat).setHTML(Yt(m.taxon, m.record)).addTo(l));
678
+ };
679
+ P(() => {
680
+ const t = p.current;
681
+ t && N.current.forEach((l) => {
682
+ const i = _.has(l) ? "visible" : "none";
683
+ t.getLayer(ee(l)) && t.setLayoutProperty(ee(l), "visibility", i), t.getLayer(te(l)) && t.setLayoutProperty(te(l), "visibility", i);
684
+ });
685
+ }, [_, x]);
686
+ const Ce = () => {
687
+ var i;
688
+ if (de.current || !r || !a || !o) return;
689
+ const t = (i = a == null ? void 0 : a.name) == null ? void 0 : i.rank;
690
+ !t || t !== "species" && !ce.includes(t) || ze(t, o).length === 0 || (de.current = !0, $({ status: "loading", taxa: [] }), Et({ datasetKey: r, focalTaxon: a, rankOrder: o }).then(
691
+ ({ taxa: g, descendantsFailed: m }) => {
692
+ if (m) {
693
+ $({ status: "error", taxa: [] });
694
+ return;
695
+ }
696
+ if (g.length === 0) {
697
+ $({ status: "empty", taxa: [] });
698
+ return;
699
+ }
700
+ $({ status: "ready", taxa: g });
701
+ }
702
+ ));
703
+ }, nt = () => {
704
+ xe(!0), Ce();
705
+ }, rt = ae(() => {
706
+ if (x.status !== "ready") return [];
707
+ const t = {};
708
+ return x.taxa.filter((l) => l.mappable.length > 0).forEach((l) => {
709
+ (t[l.rank] = t[l.rank] || []).push(l);
710
+ }), ce.filter((l) => t[l]).map((l) => ({
711
+ rank: l,
712
+ label: $e(l),
713
+ taxa: t[l].slice().sort(
714
+ (i, g) => i.scientificName.localeCompare(g.scientificName)
715
+ )
716
+ }));
717
+ }, [x]), st = (t) => {
718
+ be((l) => {
719
+ const i = new Set(l);
720
+ return i.has(t) ? i.delete(t) : i.add(t), i;
721
+ });
722
+ }, ot = (t) => {
723
+ be((l) => {
724
+ const i = new Set(l), g = t.every((m) => l.has(m.id));
725
+ return t.forEach((m) => {
726
+ g ? i.delete(m.id) : i.add(m.id);
727
+ }), i;
728
+ });
729
+ };
730
+ if (!Ae())
731
+ return /* @__PURE__ */ s.jsx(
732
+ "div",
733
+ {
734
+ style: {
735
+ padding: 12,
736
+ background: "#fafafa",
737
+ border: "1px solid #eee",
738
+ borderRadius: 4,
739
+ color: "#666",
740
+ fontSize: 12
741
+ },
742
+ children: "Maps require WebGL, which your browser doesn't support."
743
+ }
744
+ );
745
+ if (se && !I)
746
+ return /* @__PURE__ */ s.jsxs(
747
+ "div",
748
+ {
749
+ className: "col-distributions-map col-distributions-map--collapsed",
750
+ style: {
751
+ display: "flex",
752
+ alignItems: "center",
753
+ gap: 6,
754
+ padding: "8px 12px",
755
+ background: "#fafafa",
756
+ border: "1px solid #eee",
757
+ borderRadius: 4,
758
+ color: "#666",
759
+ fontSize: 12
760
+ },
761
+ children: [
762
+ /* @__PURE__ */ s.jsx("span", { children: "No curated distribution data." }),
763
+ /* @__PURE__ */ s.jsx(
764
+ "a",
765
+ {
766
+ role: "button",
767
+ tabIndex: 0,
768
+ style: { cursor: "pointer" },
769
+ onClick: ve,
770
+ onKeyDown: (t) => {
771
+ (t.key === "Enter" || t.key === " ") && (t.preventDefault(), ve());
772
+ },
773
+ children: "Show GBIF occurrences"
774
+ }
775
+ )
776
+ ]
777
+ }
778
+ );
779
+ const at = ((Re = a == null ? void 0 : a.name) == null ? void 0 : Re.scientificName) || "This taxon";
780
+ return /* @__PURE__ */ s.jsxs(
781
+ "div",
782
+ {
783
+ className: "col-distributions-map",
784
+ ref: h,
785
+ style: { position: "relative" },
786
+ children: [
787
+ /* @__PURE__ */ s.jsx(
788
+ "div",
789
+ {
790
+ ref: d,
791
+ className: "col-distributions-map__canvas",
792
+ style: { height: 360, width: "100%", background: "#f5f5f5" }
793
+ }
794
+ ),
795
+ /* @__PURE__ */ s.jsx(
796
+ en,
797
+ {
798
+ open: Je,
799
+ onOpen: nt,
800
+ onClose: () => xe(!1),
801
+ focalName: at,
802
+ focalReady: D,
803
+ focalVisible: U,
804
+ onToggleFocal: () => q((t) => !t),
805
+ gbifEnabled: !!c,
806
+ gbifVisible: I,
807
+ gbifAvailable: u,
808
+ onToggleGbif: Xe,
809
+ descendantStatus: x.status,
810
+ descendantsByRank: rt,
811
+ descendantColors: Y,
812
+ visibleTaxonIds: _,
813
+ onToggleTaxon: st,
814
+ onToggleRankGroup: ot,
815
+ onRetry: () => {
816
+ de.current = !1, $({ status: "idle", taxa: [] }), Ce();
817
+ }
818
+ }
819
+ ),
820
+ !je && (Se.length > 0 || c && u !== !1 && I) && /* @__PURE__ */ s.jsxs(
821
+ "div",
822
+ {
823
+ style: {
824
+ position: "absolute",
825
+ bottom: 8,
826
+ left: 8,
827
+ zIndex: 1,
828
+ background: "#fff",
829
+ borderRadius: 4,
830
+ boxShadow: "0 1px 4px rgba(0,0,0,0.2)",
831
+ padding: "6px 8px",
832
+ fontSize: 12,
833
+ lineHeight: 1.5
834
+ },
835
+ children: [
836
+ Se.map((t) => /* @__PURE__ */ s.jsxs(
837
+ "div",
838
+ {
839
+ style: { display: "flex", alignItems: "center", gap: 6 },
840
+ children: [
841
+ /* @__PURE__ */ s.jsx(
842
+ "span",
843
+ {
844
+ style: {
845
+ display: "inline-block",
846
+ width: 12,
847
+ height: 12,
848
+ background: t.color,
849
+ border: "1px solid rgba(0,0,0,0.15)",
850
+ borderRadius: 2
851
+ }
852
+ }
853
+ ),
854
+ /* @__PURE__ */ s.jsx("span", { children: t.label })
855
+ ]
856
+ },
857
+ t.key
858
+ )),
859
+ c && u !== !1 && I && /* @__PURE__ */ s.jsx(Jt, {})
860
+ ]
861
+ }
862
+ ),
863
+ je && /* @__PURE__ */ s.jsx(
864
+ Vt,
865
+ {
866
+ visibleGroups: ue.visibleGroups,
867
+ unmappableGroups: ue.unmappableGroups,
868
+ showGbif: !!c && u !== !1 && I
869
+ }
870
+ )
871
+ ]
872
+ }
873
+ );
874
+ }, en = ({
875
+ open: e,
876
+ onOpen: n,
877
+ onClose: r,
878
+ focalName: a,
879
+ focalReady: o,
880
+ focalVisible: c,
881
+ onToggleFocal: u,
882
+ gbifEnabled: f,
883
+ gbifVisible: d,
884
+ gbifAvailable: h,
885
+ onToggleGbif: p,
886
+ descendantStatus: y,
887
+ descendantsByRank: M,
888
+ descendantColors: E,
889
+ visibleTaxonIds: L,
890
+ onToggleTaxon: O,
891
+ onToggleRankGroup: G,
892
+ onRetry: N
893
+ }) => e ? /* @__PURE__ */ s.jsxs(
894
+ "div",
895
+ {
896
+ style: {
897
+ position: "absolute",
898
+ // Aligns with the collapsed "+" button, below the fullscreen control.
899
+ top: 48,
900
+ right: 10,
901
+ zIndex: 2,
902
+ background: "#fff",
903
+ borderRadius: 4,
904
+ boxShadow: "0 1px 4px rgba(0,0,0,0.2)",
905
+ padding: "6px 10px",
906
+ fontSize: 12,
907
+ lineHeight: 1.5,
908
+ maxHeight: 320,
909
+ overflowY: "auto",
910
+ minWidth: 160
911
+ },
912
+ onMouseLeave: r,
913
+ children: [
914
+ /* @__PURE__ */ s.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
915
+ /* @__PURE__ */ s.jsx(
916
+ "input",
917
+ {
918
+ type: "checkbox",
919
+ checked: c,
920
+ disabled: !o,
921
+ onChange: u
922
+ }
923
+ ),
924
+ /* @__PURE__ */ s.jsx("span", { style: { fontStyle: "italic" }, children: a })
925
+ ] }),
926
+ f && /* @__PURE__ */ s.jsxs(
927
+ "div",
928
+ {
929
+ style: {
930
+ display: "flex",
931
+ alignItems: "center",
932
+ gap: 6,
933
+ opacity: h === !1 ? 0.5 : 1
934
+ },
935
+ title: h === !1 ? "GBIF has no occurrence records for this taxon." : void 0,
936
+ children: [
937
+ /* @__PURE__ */ s.jsx(
938
+ "input",
939
+ {
940
+ type: "checkbox",
941
+ checked: h === !1 ? !1 : d,
942
+ disabled: h === !1,
943
+ onChange: p
944
+ }
945
+ ),
946
+ /* @__PURE__ */ s.jsx("span", { children: "GBIF occurrences" })
947
+ ]
948
+ }
949
+ ),
950
+ y === "loading" && /* @__PURE__ */ s.jsx("div", { style: { marginTop: 6, color: "#888" }, children: "Loading descendants…" }),
951
+ y === "error" && /* @__PURE__ */ s.jsxs("div", { style: { marginTop: 6, color: "#888" }, children: [
952
+ "Couldn't load descendants.",
953
+ " ",
954
+ /* @__PURE__ */ s.jsx("a", { onClick: N, style: { cursor: "pointer" }, children: "Retry" })
955
+ ] }),
956
+ y === "ready" && M.map((S) => {
957
+ const F = S.taxa.every((v) => L.has(v.id)), D = S.taxa.some((v) => L.has(v.id));
958
+ return /* @__PURE__ */ s.jsxs("div", { style: { marginTop: 6 }, children: [
959
+ /* @__PURE__ */ s.jsxs(
960
+ "label",
961
+ {
962
+ style: {
963
+ display: "flex",
964
+ alignItems: "center",
965
+ gap: 6,
966
+ fontWeight: 600
967
+ },
968
+ children: [
969
+ /* @__PURE__ */ s.jsx(
970
+ "input",
971
+ {
972
+ type: "checkbox",
973
+ checked: F,
974
+ ref: (v) => {
975
+ v && (v.indeterminate = !F && D);
976
+ },
977
+ onChange: () => G(S.taxa)
978
+ }
979
+ ),
980
+ S.label
981
+ ]
982
+ }
983
+ ),
984
+ /* @__PURE__ */ s.jsx("div", { style: { paddingLeft: 18 }, children: S.taxa.map((v) => /* @__PURE__ */ s.jsxs(
985
+ "label",
986
+ {
987
+ style: {
988
+ display: "flex",
989
+ alignItems: "center",
990
+ gap: 6
991
+ },
992
+ children: [
993
+ /* @__PURE__ */ s.jsx(
994
+ "input",
995
+ {
996
+ type: "checkbox",
997
+ checked: L.has(v.id),
998
+ onChange: () => O(v.id)
999
+ }
1000
+ ),
1001
+ /* @__PURE__ */ s.jsx(
1002
+ "span",
1003
+ {
1004
+ style: {
1005
+ display: "inline-block",
1006
+ width: 10,
1007
+ height: 10,
1008
+ background: E[v.id],
1009
+ border: "1px solid rgba(0,0,0,0.15)",
1010
+ borderRadius: 2
1011
+ }
1012
+ }
1013
+ ),
1014
+ /* @__PURE__ */ s.jsx("span", { style: { fontStyle: "italic" }, children: Ze(v.scientificName) })
1015
+ ]
1016
+ },
1017
+ v.id
1018
+ )) })
1019
+ ] }, S.rank);
1020
+ })
1021
+ ]
1022
+ }
1023
+ ) : /* @__PURE__ */ s.jsx(
1024
+ "button",
1025
+ {
1026
+ type: "button",
1027
+ onClick: n,
1028
+ onMouseEnter: n,
1029
+ title: "Layers",
1030
+ style: {
1031
+ position: "absolute",
1032
+ // Sits just below the maplibre fullscreen control (top-right).
1033
+ top: 48,
1034
+ right: 10,
1035
+ zIndex: 2,
1036
+ width: 30,
1037
+ height: 30,
1038
+ background: "#fff",
1039
+ border: "1px solid rgba(0,0,0,0.2)",
1040
+ borderRadius: 4,
1041
+ cursor: "pointer",
1042
+ fontSize: 18,
1043
+ lineHeight: "26px",
1044
+ padding: 0,
1045
+ boxShadow: "0 1px 4px rgba(0,0,0,0.2)"
1046
+ },
1047
+ children: "+"
1048
+ }
1049
+ ), tn = (e) => {
1050
+ var n, r;
1051
+ return ((n = e == null ? void 0 : e.area) == null ? void 0 : n.gazetteer) !== "text" && !!((r = e == null ? void 0 : e.area) != null && r.globalId);
1052
+ }, Pe = ({ datasetKey: e, data: n }) => {
1053
+ const [r, a] = k({});
1054
+ return P(() => {
1055
+ let o = !1;
1056
+ for (let c = 0; c < n.length; c++)
1057
+ if (n[c].gazetteer === "iso") {
1058
+ o = !0;
1059
+ break;
1060
+ }
1061
+ o && re(`${R.dataApi}vocab/country`).then((c) => {
1062
+ a(pt(c.data, "alpha3"));
1063
+ });
1064
+ }, []), /* @__PURE__ */ s.jsx("div", { children: n.map((o, c) => /* @__PURE__ */ s.jsxs("span", { children: [
1065
+ (o == null ? void 0 : o.merged) && /* @__PURE__ */ s.jsx(
1066
+ yt,
1067
+ {
1068
+ createdBy: o == null ? void 0 : o.createdBy,
1069
+ datasetKey: o.datasetKey,
1070
+ sourceDatasetKey: o == null ? void 0 : o.sourceDatasetKey,
1071
+ verbatimSourceKey: o == null ? void 0 : o.verbatimSourceKey,
1072
+ style: { marginRight: "4px" }
1073
+ }
1074
+ ),
1075
+ (H(r, `[${H(o, "area.name")}].name`) ? ft(H(r, `[${H(o, "area.name")}].name`)) : null) || H(o, "area.name") || H(o, "area.globalId"),
1076
+ " ",
1077
+ o.referenceId && /* @__PURE__ */ s.jsx(
1078
+ It,
1079
+ {
1080
+ datasetKey: e,
1081
+ referenceId: o.referenceId,
1082
+ placement: "bottom"
1083
+ }
1084
+ ),
1085
+ c < n.length - 1 && ", "
1086
+ ] }, c)) });
1087
+ }, yn = ({
1088
+ datasetKey: e,
1089
+ data: n,
1090
+ style: r,
1091
+ showDistributionMap: a,
1092
+ focalTaxon: o,
1093
+ rankOrder: c,
1094
+ gbifChecklistKey: u,
1095
+ basemapStyle: f,
1096
+ label: d,
1097
+ md: h
1098
+ }) => {
1099
+ const p = n.filter(tn), y = n.length - p.length, M = !!u, E = n.length > 0, [L, O] = k("map"), [G, N] = k(0), [S, F] = k(null);
1100
+ P(() => {
1101
+ if (!u || !(o != null && o.id)) {
1102
+ F(null);
1103
+ return;
1104
+ }
1105
+ F(null);
1106
+ let I = !1;
1107
+ return ht.get(`${R.gbifApi}/v1/occurrence/search`, {
1108
+ params: {
1109
+ checklistKey: u,
1110
+ taxonKey: o.id,
1111
+ hasCoordinate: !0,
1112
+ hasGeospatialIssue: !1,
1113
+ occurrenceStatus: "PRESENT",
1114
+ limit: 0
1115
+ }
1116
+ }).then(
1117
+ (z) => {
1118
+ var _;
1119
+ I || F(((_ = z == null ? void 0 : z.data) == null ? void 0 : _.count) ?? 0);
1120
+ },
1121
+ () => {
1122
+ I || F(null);
1123
+ }
1124
+ ), () => {
1125
+ I = !0;
1126
+ };
1127
+ }, [u, o == null ? void 0 : o.id]);
1128
+ const D = M ? S === null || S > 0 : !1, v = p.length > 0 && G >= p.length, x = a && (p.length > 0 || D) && !(p.length > 0 && v && !D);
1129
+ if (!x && !E) return null;
1130
+ const $ = y + G, U = E;
1131
+ let q;
1132
+ if (!x)
1133
+ q = /* @__PURE__ */ s.jsx(Pe, { datasetKey: e, data: n });
1134
+ else {
1135
+ const I = U ? L : "map";
1136
+ q = /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
1137
+ U ? /* @__PURE__ */ s.jsxs(
1138
+ fe.Group,
1139
+ {
1140
+ size: "small",
1141
+ value: I,
1142
+ onChange: (z) => O(z.target.value),
1143
+ style: { marginBottom: 8 },
1144
+ children: [
1145
+ /* @__PURE__ */ s.jsx(fe.Button, { value: "map", children: "Map" }),
1146
+ /* @__PURE__ */ s.jsx(fe.Button, { value: "list", children: "List" })
1147
+ ]
1148
+ }
1149
+ ) : (
1150
+ // Reserve the vertical space the Map/List toggle would occupy so the
1151
+ // map's top edge lines up with the "Distributions" label.
1152
+ /* @__PURE__ */ s.jsx("div", { style: { height: 24, marginBottom: 8 } })
1153
+ ),
1154
+ I === "map" ? /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
1155
+ /* @__PURE__ */ s.jsx(
1156
+ Qt,
1157
+ {
1158
+ records: p,
1159
+ onUnmappable: N,
1160
+ datasetKey: e,
1161
+ focalTaxon: o,
1162
+ rankOrder: c,
1163
+ gbifChecklistKey: u,
1164
+ gbifAvailable: D,
1165
+ basemapStyle: f
1166
+ }
1167
+ ),
1168
+ U && $ > 0 && /* @__PURE__ */ s.jsx("div", { style: { marginTop: 6 }, children: /* @__PURE__ */ s.jsxs("a", { onClick: () => O("list"), style: { cursor: "pointer" }, children: [
1169
+ "+",
1170
+ $,
1171
+ " distribution",
1172
+ $ === 1 ? "" : "s",
1173
+ " not on map"
1174
+ ] }) })
1175
+ ] }) : /* @__PURE__ */ s.jsx(Pe, { datasetKey: e, data: n })
1176
+ ] });
1177
+ }
1178
+ const se = /* @__PURE__ */ s.jsx("div", { style: r, children: q });
1179
+ return d ? /* @__PURE__ */ s.jsx(bt, { md: h, label: d, children: se }) : se;
1180
+ };
1181
+ export {
1182
+ yn as D,
1183
+ It as R
1184
+ };
1185
+ //# sourceMappingURL=Distributions-Czffme5Y.js.map