col-browser 2.2.3 → 2.2.5

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