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