col-browser 2.2.3 → 2.2.4

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