col-browser 2.6.4 → 2.6.6

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