@carto/ps-react-ui 4.16.0 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { L as r, c as a, a as t, d as l, g as o, h as d, r as L, s as g, b as n, e as c, f as u, i, j as p, k as S, l as y, m as G, u as b, n as h, o as C, p as f } from "../legend-store-registry-CVYzhR1-.js";
1
+ import { L as r, c as a, a as t, d as l, g as o, h as d, r as L, s as g, b as n, e as c, f as u, i, j as p, k as S, l as y, m as G, u as b, n as h, o as C, p as f } from "../legend-store-registry-Bo8U_qWM.js";
2
2
  export {
3
3
  r as LegendContext,
4
4
  a as clearAllLegendStores,
@@ -1,36 +1,36 @@
1
- import { createContext as x, useContext as P } from "react";
1
+ import { createContext as P, useContext as A, isValidElement as j } from "react";
2
2
  import { c as B } from "react/compiler-runtime";
3
- import { useStore as k } from "zustand";
4
- import { createStore as A } from "zustand/vanilla";
5
- import { devtools as $ } from "zustand/middleware";
3
+ import { useStore as C } from "zustand";
4
+ import { createStore as $ } from "zustand/vanilla";
5
+ import { devtools as q } from "zustand/middleware";
6
6
  import { useShallow as D } from "zustand/react/shallow";
7
- const q = x(null);
8
- function ee() {
9
- const e = P(q);
7
+ const z = P(null);
8
+ function oe() {
9
+ const e = A(z);
10
10
  if (e == null)
11
11
  throw new Error("useLegendId() must be called inside <Legend.Provider>. If you are calling from outside the Provider tree, use the hooks (useLegendStore, useLegendShallow) directly with an explicit id.");
12
12
  return e;
13
13
  }
14
14
  const S = (e, r) => e.order - r.order;
15
- function C(e) {
15
+ function E(e) {
16
16
  return Object.values(e.groups).sort(S);
17
17
  }
18
18
  function O(e, r) {
19
19
  return Object.values(e.layers).filter((n) => n.groupId === r).sort(S);
20
20
  }
21
- function re(e) {
21
+ function se(e) {
22
22
  return Object.values(e.layers).sort(S);
23
23
  }
24
- function oe(e) {
24
+ function te(e) {
25
25
  const r = Object.values(e.groups);
26
26
  return r.length > 0 && r.every((n) => n.collapsed);
27
27
  }
28
- function se(e) {
28
+ function ne(e) {
29
29
  return Object.keys(e.groups).length > 0;
30
30
  }
31
- function te(e) {
31
+ function le(e) {
32
32
  const r = (o) => O(e, o).filter((s) => s.visible), n = [];
33
- for (const o of C(e)) {
33
+ for (const o of E(e)) {
34
34
  const s = r(o.id);
35
35
  s.length > 0 && n.push({
36
36
  group: o,
@@ -42,26 +42,26 @@ function te(e) {
42
42
  layers: t
43
43
  }), n;
44
44
  }
45
- function ne(e, r) {
45
+ function ce(e, r) {
46
46
  const n = e.layers[r];
47
47
  return n ? n.variables.length > 0 || (n.sections?.length ?? 0) > 0 || // Truthiness matches the render condition — an empty-string note renders
48
48
  // no footer, so it must not enable the collapse affordance.
49
49
  !!n.helperText : !1;
50
50
  }
51
- function le(e, r) {
51
+ function ue(e, r) {
52
52
  let n = !1, t = !1;
53
53
  for (const o of O(e, r))
54
54
  o.visible ? n = !0 : t = !0;
55
55
  return n && t ? "mixed" : t ? "hidden" : "visible";
56
56
  }
57
- const g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set(), H = () => {
57
+ const p = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Set(), H = () => {
58
58
  try {
59
59
  return !1;
60
60
  } catch {
61
61
  return !1;
62
62
  }
63
- }, z = (e) => Math.min(1, Math.max(0, e));
64
- function j(e, r) {
63
+ }, _ = (e) => Math.min(1, Math.max(0, e));
64
+ function w(e, r) {
65
65
  return e.visible === r ? null : r ? (
66
66
  // Showing: restore the pre-hide collapsed state (default expand).
67
67
  {
@@ -78,7 +78,7 @@ function j(e, r) {
78
78
  }
79
79
  );
80
80
  }
81
- function _(e, r) {
81
+ function R(e, r) {
82
82
  return e.visible ? {
83
83
  collapsed: r
84
84
  } : {
@@ -86,16 +86,16 @@ function _(e, r) {
86
86
  collapsedBeforeHide: r
87
87
  };
88
88
  }
89
- function w(e, r, n) {
90
- const t = e.findIndex((a) => a.id === r);
89
+ function k(e, r, n) {
90
+ const t = e.findIndex((i) => i.id === r);
91
91
  if (t === -1) return null;
92
92
  const o = Math.max(0, Math.min(e.length - 1, n));
93
93
  if (o === t) return null;
94
94
  const s = [...e], [l] = s.splice(t, 1);
95
95
  s.splice(o, 0, l);
96
96
  const c = /* @__PURE__ */ new Map();
97
- return s.forEach((a, u) => {
98
- a.order !== u && c.set(a.id, u);
97
+ return s.forEach((i, u) => {
98
+ i.order !== u && c.set(i.id, u);
99
99
  }), c.size > 0 ? c : null;
100
100
  }
101
101
  function h(e, r, n) {
@@ -110,7 +110,7 @@ function h(e, r, n) {
110
110
  }
111
111
  } : {};
112
112
  }
113
- function R(e, r, n) {
113
+ function T(e, r, n) {
114
114
  const t = e.groups[r];
115
115
  return t ? {
116
116
  groups: {
@@ -122,7 +122,7 @@ function R(e, r, n) {
122
122
  }
123
123
  } : {};
124
124
  }
125
- function T(e, r) {
125
+ function U(e, r) {
126
126
  if (!r || !e || e === r) return r;
127
127
  const n = r.map((o) => {
128
128
  const s = e.find((l) => l.id === o.id);
@@ -136,13 +136,17 @@ function T(e, r) {
136
136
  return l.id === o.id && l.title === o.title && l.options === o.options && l.active === o.active;
137
137
  }) ? e : n;
138
138
  }
139
- function b(e, r) {
139
+ function F(e, r) {
140
+ return !j(e) || !j(r) || e.type !== r.type || e.key !== r.key ? !1 : v(e.props, r.props);
141
+ }
142
+ function v(e, r) {
140
143
  const n = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(r)]);
141
144
  for (const t of n)
142
- if (!Object.is(e[t], r[t])) return !1;
145
+ if (!Object.is(e[t], r[t]) && !F(e[t], r[t]))
146
+ return !1;
143
147
  return !0;
144
148
  }
145
- function L(e, r) {
149
+ function b(e, r) {
146
150
  const n = /* @__PURE__ */ new Map();
147
151
  for (const t of e) {
148
152
  const o = r(t.merged), s = n.get(o);
@@ -153,14 +157,14 @@ function L(e, r) {
153
157
  o.merged.order = s;
154
158
  });
155
159
  }
156
- function E(e, r, n) {
160
+ function V(e, r, n) {
157
161
  return {
158
162
  ...r,
159
163
  visible: e?.visible ?? r.visible ?? !0,
160
164
  opacity: e?.opacity ?? r.opacity ?? 1,
161
165
  collapsed: e?.collapsed ?? r.collapsed ?? !1,
162
166
  collapsedBeforeHide: e?.collapsedBeforeHide,
163
- sections: T(e?.sections, r.sections),
167
+ sections: U(e?.sections, r.sections),
164
168
  order: e?.order ?? r.order ?? n
165
169
  };
166
170
  }
@@ -173,36 +177,36 @@ function M(e, r, n) {
173
177
  };
174
178
  }
175
179
  function I(e, r, n) {
176
- const t = r.map((u, i) => ({
177
- index: i,
178
- merged: E(e.layers[u.id], u, i)
180
+ const t = r.map((u, a) => ({
181
+ index: a,
182
+ merged: V(e.layers[u.id], u, a)
179
183
  }));
180
- L(t, (u) => u.groupId);
181
- const o = n.map((u, i) => ({
182
- index: i,
183
- merged: M(e.groups[u.id], u, i)
184
+ b(t, (u) => u.groupId);
185
+ const o = n.map((u, a) => ({
186
+ index: a,
187
+ merged: M(e.groups[u.id], u, a)
184
188
  }));
185
- L(o, () => {
189
+ b(o, () => {
186
190
  });
187
191
  let s = t.length !== Object.keys(e.layers).length;
188
192
  const l = {};
189
193
  for (const {
190
194
  merged: u
191
195
  } of t) {
192
- const i = e.layers[u.id];
193
- i && b(i, u) ? l[u.id] = i : (l[u.id] = u, s = !0);
196
+ const a = e.layers[u.id];
197
+ a && v(a, u) ? l[u.id] = a : (l[u.id] = u, s = !0);
194
198
  }
195
199
  let c = o.length !== Object.keys(e.groups).length;
196
- const a = {};
200
+ const i = {};
197
201
  for (const {
198
202
  merged: u
199
203
  } of o) {
200
- const i = e.groups[u.id];
201
- i && b(i, u) ? a[u.id] = i : (a[u.id] = u, c = !0);
204
+ const a = e.groups[u.id];
205
+ a && v(a, u) ? i[u.id] = a : (i[u.id] = u, c = !0);
202
206
  }
203
207
  return !s && !c ? {} : {
204
208
  layers: s ? l : e.layers,
205
- groups: c ? a : e.groups
209
+ groups: c ? i : e.groups
206
210
  };
207
211
  }
208
212
  function m(e, r, n) {
@@ -212,19 +216,19 @@ function m(e, r, n) {
212
216
  ...l
213
217
  }
214
218
  }));
215
- L(t, n);
219
+ b(t, n);
216
220
  let o = t.length !== Object.keys(e).length;
217
221
  const s = {};
218
222
  for (const {
219
223
  merged: l
220
224
  } of t) {
221
225
  const c = e[l.id];
222
- c && b(c, l) ? s[l.id] = c : (s[l.id] = l, o = !0);
226
+ c && v(c, l) ? s[l.id] = c : (s[l.id] = l, o = !0);
223
227
  }
224
228
  return o ? s : null;
225
229
  }
226
- function U(e, r) {
227
- const n = Object.values(e.layers).filter((s) => s.groupId === r.groupId && s.id !== r.id).length, t = E(e.layers[r.id], r, n), o = m(e.layers, {
230
+ function J(e, r) {
231
+ const n = Object.values(e.layers).filter((s) => s.groupId === r.groupId && s.id !== r.id).length, t = V(e.layers[r.id], r, n), o = m(e.layers, {
228
232
  ...e.layers,
229
233
  [r.id]: t
230
234
  }, (s) => s.groupId);
@@ -232,7 +236,7 @@ function U(e, r) {
232
236
  layers: o
233
237
  } : {};
234
238
  }
235
- function F(e, r) {
239
+ function K(e, r) {
236
240
  if (!e.layers[r]) return {};
237
241
  const n = {
238
242
  ...e.layers
@@ -243,7 +247,7 @@ function F(e, r) {
243
247
  layers: t
244
248
  } : {};
245
249
  }
246
- function J(e, r) {
250
+ function N(e, r) {
247
251
  const n = Object.values(e.groups).filter((s) => s.id !== r.id).length, t = M(e.groups[r.id], r, n), o = m(e.groups, {
248
252
  ...e.groups,
249
253
  [r.id]: t
@@ -253,7 +257,7 @@ function J(e, r) {
253
257
  groups: o
254
258
  } : {};
255
259
  }
256
- function K(e, r) {
260
+ function Q(e, r) {
257
261
  if (!e.groups[r]) return {};
258
262
  const n = {
259
263
  ...e.groups
@@ -282,86 +286,86 @@ function K(e, r) {
282
286
  } : {}
283
287
  };
284
288
  }
285
- function ce(e, r = {}) {
289
+ function ie(e, r = {}) {
286
290
  const n = I({
287
291
  layers: {},
288
292
  groups: {}
289
293
  }, r.layers ?? [], r.groups ?? []);
290
- return A()($((t) => ({
294
+ return $()(q((t) => ({
291
295
  layers: n.layers ?? {},
292
296
  groups: n.groups ?? {},
293
297
  setVisibility: (o, s) => t((l) => {
294
- const c = l.layers[o], a = c && j(c, s);
295
- return a ? h(l, o, a) : {};
298
+ const c = l.layers[o], i = c && w(c, s);
299
+ return i ? h(l, o, i) : {};
296
300
  }, !1, "setVisibility"),
297
301
  setOpacity: (o, s) => t((l) => h(l, o, {
298
- opacity: z(s)
302
+ opacity: _(s)
299
303
  }), !1, "setOpacity"),
300
304
  setCollapsed: (o, s) => t((l) => {
301
305
  const c = l.layers[o];
302
- return c ? h(l, o, _(c, s)) : {};
306
+ return c ? h(l, o, R(c, s)) : {};
303
307
  }, !1, "setCollapsed"),
304
308
  setSectionValue: (o, s, l) => t((c) => {
305
- const a = c.layers[o], u = a?.sections?.find((d) => d.id === s);
306
- if (!a?.sections || !u || u.active === l || !u.options.includes(l))
309
+ const i = c.layers[o], u = i?.sections?.find((d) => d.id === s);
310
+ if (!i?.sections || !u || u.active === l || !u.options.includes(l))
307
311
  return {};
308
- const i = a.sections.map((d) => d.id === s ? {
312
+ const a = i.sections.map((d) => d.id === s ? {
309
313
  ...d,
310
314
  active: l
311
315
  } : d);
312
316
  return h(c, o, {
313
- sections: i
317
+ sections: a
314
318
  });
315
319
  }, !1, "setSectionValue"),
316
320
  moveLayer: (o, s) => t((l) => {
317
321
  const c = l.layers[o];
318
322
  if (!c) return {};
319
- const a = O(l, c.groupId), u = w(a, o, s);
323
+ const i = O(l, c.groupId), u = k(i, o, s);
320
324
  if (!u) return {};
321
- const i = {
325
+ const a = {
322
326
  ...l.layers
323
327
  };
324
- for (const [d, p] of u)
325
- i[d] = {
326
- ...i[d],
327
- order: p
328
+ for (const [d, g] of u)
329
+ a[d] = {
330
+ ...a[d],
331
+ order: g
328
332
  };
329
333
  return {
330
- layers: i
334
+ layers: a
331
335
  };
332
336
  }, !1, "moveLayer"),
333
337
  setGroupVisibility: (o, s) => t((l) => {
334
338
  const c = l.groups[o];
335
339
  if (!c) return {};
336
- const a = Object.values(l.layers).filter((f) => f.groupId === o), u = a.some((f) => f.visible);
337
- if (a.length === 0 || !s && !u) return {};
338
- const i = {
340
+ const i = Object.values(l.layers).filter((f) => f.groupId === o), u = i.some((f) => f.visible);
341
+ if (i.length === 0 || !s && !u) return {};
342
+ const a = {
339
343
  ...l.layers
340
344
  };
341
345
  let d = !1;
342
- for (const f of a) {
343
- const G = j(f, s);
344
- G && (i[f.id] = {
346
+ for (const f of i) {
347
+ const G = w(f, s);
348
+ G && (a[f.id] = {
345
349
  ...f,
346
350
  ...G
347
351
  }, d = !0);
348
352
  }
349
353
  if (!d) return {};
350
- let p = null;
351
- return !s && u ? p = {
354
+ let g = null;
355
+ return !s && u ? g = {
352
356
  collapsed: !0,
353
357
  collapsedBeforeHide: c.collapsed
354
- } : s && !u && (p = {
358
+ } : s && !u && (g = {
355
359
  collapsed: c.collapsedBeforeHide ?? !1,
356
360
  collapsedBeforeHide: void 0
357
361
  }), {
358
- layers: i,
359
- ...p ? {
362
+ layers: a,
363
+ ...g ? {
360
364
  groups: {
361
365
  ...l.groups,
362
366
  [o]: {
363
367
  ...c,
364
- ...p
368
+ ...g
365
369
  }
366
370
  }
367
371
  } : {}
@@ -369,8 +373,8 @@ function ce(e, r = {}) {
369
373
  }, !1, "setGroupVisibility"),
370
374
  setGroupCollapsed: (o, s) => t((l) => {
371
375
  if (!l.groups[o]) return {};
372
- const a = Object.values(l.layers).filter((i) => i.groupId === o), u = a.length > 0 && a.every((i) => !i.visible);
373
- return R(l, o, u ? {
376
+ const i = Object.values(l.layers).filter((a) => a.groupId === o), u = i.length > 0 && i.every((a) => !a.visible);
377
+ return T(l, o, u ? {
374
378
  collapsed: s,
375
379
  collapsedBeforeHide: s
376
380
  } : {
@@ -379,86 +383,86 @@ function ce(e, r = {}) {
379
383
  }, !1, "setGroupCollapsed"),
380
384
  moveGroup: (o, s) => t((l) => {
381
385
  if (!l.groups[o]) return {};
382
- const c = w(C(l), o, s);
386
+ const c = k(E(l), o, s);
383
387
  if (!c) return {};
384
- const a = {
388
+ const i = {
385
389
  ...l.groups
386
390
  };
387
- for (const [u, i] of c)
388
- a[u] = {
389
- ...a[u],
390
- order: i
391
+ for (const [u, a] of c)
392
+ i[u] = {
393
+ ...i[u],
394
+ order: a
391
395
  };
392
396
  return {
393
- groups: a
397
+ groups: i
394
398
  };
395
399
  }, !1, "moveGroup"),
396
- setLegendLayer: (o) => t((s) => U(s, o), !1, "setLegendLayer"),
397
- removeLegendLayer: (o) => t((s) => F(s, o), !1, "removeLegendLayer"),
398
- setLegendGroup: (o) => t((s) => J(s, o), !1, "setLegendGroup"),
399
- removeLegendGroup: (o) => t((s) => K(s, o), !1, "removeLegendGroup"),
400
+ setLegendLayer: (o) => t((s) => J(s, o), !1, "setLegendLayer"),
401
+ removeLegendLayer: (o) => t((s) => K(s, o), !1, "removeLegendLayer"),
402
+ setLegendGroup: (o) => t((s) => N(s, o), !1, "setLegendGroup"),
403
+ removeLegendGroup: (o) => t((s) => Q(s, o), !1, "removeLegendGroup"),
400
404
  _sync: (o, s) => t((l) => I(l, o, s), !1, "_sync")
401
405
  }), {
402
406
  name: `legend-${e}`,
403
407
  enabled: H()
404
408
  }));
405
409
  }
406
- function V(e) {
407
- const r = g.get(e);
410
+ function x(e) {
411
+ const r = p.get(e);
408
412
  if (!r) throw new Error(`[legend] Legend store "${e}" not found.`);
409
413
  return r;
410
414
  }
411
- function ue(e) {
412
- return g.has(e);
413
- }
414
415
  function ae(e) {
415
- g.delete(e);
416
+ return p.has(e);
416
417
  }
417
- function ie() {
418
- g.clear(), y.clear(), v.clear();
418
+ function de(e) {
419
+ p.delete(e);
419
420
  }
420
- function de(e, r) {
421
- g.set(e, r);
421
+ function fe() {
422
+ p.clear(), y.clear(), L.clear();
422
423
  }
423
- function fe(e, r) {
424
- g.set(e, r);
425
- const n = (y.get(e) ?? 0) + 1;
426
- y.set(e, n), n > 1 && H() && !v.has(e) && (console.warn(`[legend] Duplicate <Legend.Provider id="${e}"> detected. Multiple providers sharing an id will race on prop sync. Use unique ids per legend panel.`), v.add(e));
424
+ function pe(e, r) {
425
+ p.set(e, r);
427
426
  }
428
427
  function ge(e, r) {
428
+ p.set(e, r);
429
+ const n = (y.get(e) ?? 0) + 1;
430
+ y.set(e, n), n > 1 && H() && !L.has(e) && (console.warn(`[legend] Duplicate <Legend.Provider id="${e}"> detected. Multiple providers sharing an id will race on prop sync. Use unique ids per legend panel.`), L.add(e));
431
+ }
432
+ function ye(e, r) {
429
433
  const n = (y.get(e) ?? 1) - 1;
430
- n <= 0 ? (y.delete(e), r.keepAlive || g.delete(e)) : y.set(e, n);
434
+ n <= 0 ? (y.delete(e), r.keepAlive || p.delete(e)) : y.set(e, n);
431
435
  }
432
- function pe(e, r) {
436
+ function me(e, r) {
433
437
  const n = B(2);
434
438
  let t;
435
- return n[0] !== e ? (t = V(e), n[0] = e, n[1] = t) : t = n[1], k(t, r);
439
+ return n[0] !== e ? (t = x(e), n[0] = e, n[1] = t) : t = n[1], C(t, r);
436
440
  }
437
- function ye(e, r) {
441
+ function he(e, r) {
438
442
  const n = B(2);
439
443
  let t;
440
- return n[0] !== e ? (t = V(e), n[0] = e, n[1] = t) : t = n[1], k(t, D(r));
444
+ return n[0] !== e ? (t = x(e), n[0] = e, n[1] = t) : t = n[1], C(t, D(r));
441
445
  }
442
446
  export {
443
- q as L,
444
- ce as a,
445
- le as b,
446
- ie as c,
447
- ae as d,
448
- se as e,
449
- ne as f,
450
- V as g,
451
- ue as h,
447
+ z as L,
448
+ ie as a,
449
+ ue as b,
450
+ fe as c,
451
+ de as d,
452
+ ne as e,
453
+ ce as f,
454
+ x as g,
455
+ ae as h,
452
456
  O as i,
453
- C as j,
454
- re as k,
455
- te as l,
456
- de as m,
457
- ee as n,
458
- ye as o,
459
- pe as p,
460
- fe as r,
461
- oe as s,
462
- ge as u
457
+ E as j,
458
+ se as k,
459
+ le as l,
460
+ pe as m,
461
+ oe as n,
462
+ he as o,
463
+ me as p,
464
+ ge as r,
465
+ te as s,
466
+ ye as u
463
467
  };
464
- //# sourceMappingURL=legend-store-registry-CVYzhR1-.js.map
468
+ //# sourceMappingURL=legend-store-registry-Bo8U_qWM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legend-store-registry-Bo8U_qWM.js","sources":["../src/legend/stores/legend-context.ts","../src/legend/stores/selectors.ts","../src/legend/stores/legend-store-registry.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\n/** @experimental This API is new and may change in a future release. */\nexport const LegendContext = createContext<string | null>(null)\n\n/** @experimental This API is new and may change in a future release. */\nexport function useLegendId(): string {\n const id = useContext(LegendContext)\n if (id == null) {\n throw new Error(\n 'useLegendId() must be called inside <Legend.Provider>. ' +\n 'If you are calling from outside the Provider tree, use the hooks ' +\n '(useLegendStore, useLegendShallow) directly with an explicit id.',\n )\n }\n return id\n}\n","import type { LegendGroup, LegendLayer, LegendState } from './types'\n\nconst byOrder = <T extends { order: number }>(a: T, b: T): number =>\n a.order - b.order\n\n/**\n * Groups sorted by `order`.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectOrderedGroups(state: LegendState): LegendGroup[] {\n return Object.values(state.groups).sort(byOrder)\n}\n\n/**\n * Layers belonging to `groupId` (pass `undefined` for ungrouped, top-level\n * layers), sorted by `order`.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectLayersByGroup(\n state: LegendState,\n groupId: string | undefined,\n): LegendLayer[] {\n return Object.values(state.layers)\n .filter((l) => l.groupId === groupId)\n .sort(byOrder)\n}\n\n/**\n * All layers sorted by `order`, regardless of group.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectOrderedLayers(state: LegendState): LegendLayer[] {\n return Object.values(state.layers).sort(byOrder)\n}\n\n/**\n * `true` when every group is collapsed (`false` with no groups) — drives the\n * \"Collapse all groups\" / \"Expand all groups\" menu label flip.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectAllGroupsCollapsed(state: LegendState): boolean {\n const groups = Object.values(state.groups)\n return groups.length > 0 && groups.every((g) => g.collapsed)\n}\n\n/**\n * Whether the legend has groups — gates panel-level group actions.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectHasGroups(state: LegendState): boolean {\n return Object.keys(state.groups).length > 0\n}\n\n/**\n * Visible layers grouped for the enabled-layers menu.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectVisibleLayersGrouped(\n state: LegendState,\n): { group?: LegendGroup; layers: LegendLayer[] }[] {\n const visible = (groupId: string | undefined) =>\n selectLayersByGroup(state, groupId).filter((l) => l.visible)\n const sections: { group?: LegendGroup; layers: LegendLayer[] }[] = []\n for (const group of selectOrderedGroups(state)) {\n const layers = visible(group.id)\n if (layers.length > 0) sections.push({ group, layers })\n }\n const ungrouped = visible(undefined)\n if (ungrouped.length > 0) sections.push({ layers: ungrouped })\n return sections\n}\n\n/**\n * Whether a layer has any collapsible body — something the row's `Collapse`\n * can actually fold. A layer with no variables, sections, or helper note\n * renders an empty body, so there is nothing to collapse. Gates the row's\n * title-area collapse affordance (chevron + click).\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectLayerCollapsible(\n state: LegendState,\n layerId: string,\n): boolean {\n const layer = state.layers[layerId]\n if (!layer) return false\n return (\n layer.variables.length > 0 ||\n (layer.sections?.length ?? 0) > 0 ||\n // Truthiness matches the render condition — an empty-string note renders\n // no footer, so it must not enable the collapse affordance.\n Boolean(layer.helperText)\n )\n}\n\n/**\n * Tri-state visibility — derived for groups from their member layers, and the\n * state contract of a controlled `Legend.VisibilityToggle` for any custom\n * element kind.\n */\nexport type LegendVisibility = 'visible' | 'hidden' | 'mixed'\n\n/**\n * Tri-state group visibility: `'visible'` when every member layer is visible\n * (also for empty groups), `'hidden'` when none is, `'mixed'` otherwise.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function selectGroupVisibility(\n state: LegendState,\n groupId: string,\n): LegendVisibility {\n let anyVisible = false\n let anyHidden = false\n for (const layer of selectLayersByGroup(state, groupId)) {\n if (layer.visible) anyVisible = true\n else anyHidden = true\n }\n if (anyVisible && anyHidden) return 'mixed'\n return anyHidden ? 'hidden' : 'visible'\n}\n","import { isValidElement } from 'react'\nimport { useStore, type StoreApi } from 'zustand'\nimport { createStore } from 'zustand/vanilla'\nimport { devtools } from 'zustand/middleware'\nimport { useShallow } from 'zustand/react/shallow'\nimport type {\n LegendConfigSection,\n LegendGroup,\n LegendGroupInput,\n LegendInit,\n LegendLayer,\n LegendLayerInput,\n LegendState,\n LegendStoreApi,\n} from './types'\nimport { selectLayersByGroup, selectOrderedGroups } from './selectors'\n\n// Per-panel legend store registry. One store per `<Legend.Provider id>`.\n// Mirrors the widgets-v2 registry pattern (keyed Map + refcounted mounts),\n// without the chart-pipeline machinery.\nconst legendStores = new Map<string, LegendStoreApi>()\nconst legendMountCounts = new Map<string, number>()\nconst warnedDuplicates = new Set<string>()\n\nconst isDev = (): boolean => {\n try {\n return Boolean(\n (import.meta as unknown as { env?: { DEV?: boolean } }).env?.DEV,\n )\n } catch {\n return false\n }\n}\n\nconst clamp01 = (n: number): number => Math.min(1, Math.max(0, n))\n\n// ─── Pure state helpers ─────────────────────────────────────────────────────\n\n/**\n * Visibility↔collapse coupling. Hiding snapshots the current collapsed state\n * and collapses; showing restores the snapshot (manual choices persist) and\n * defaults to expanded. Idempotent: returns `null` when `visible` is already\n * the requested value, so a double-hide can't overwrite the real snapshot.\n */\nfunction visibilityPatch(\n entity: {\n visible: boolean\n collapsed: boolean\n collapsedBeforeHide?: boolean\n },\n visible: boolean,\n): {\n visible: boolean\n collapsed: boolean\n collapsedBeforeHide: boolean | undefined\n} | null {\n if (entity.visible === visible) return null\n return visible\n ? // Showing: restore the pre-hide collapsed state (default expand).\n {\n visible,\n collapsed: entity.collapsedBeforeHide ?? false,\n collapsedBeforeHide: undefined,\n }\n : // Hiding: snapshot, then collapse.\n {\n visible,\n collapsed: true,\n collapsedBeforeHide: entity.collapsed,\n }\n}\n\n/**\n * Manual collapse. While hidden, the snapshot follows the manual choice so\n * the next show keeps it.\n */\nfunction collapsePatch(\n entity: { visible: boolean },\n collapsed: boolean,\n): { collapsed: boolean; collapsedBeforeHide?: boolean } {\n return entity.visible\n ? { collapsed }\n : { collapsed, collapsedBeforeHide: collapsed }\n}\n\n/**\n * Reorder one entity within its **ordered** bucket: splice it out, insert at\n * the clamped index, and return the dense `order` rewrites (only the entries\n * whose order actually changes). `null` when the position doesn't change or\n * the id isn't in the bucket. Powers `moveLayer` / `moveGroup`.\n */\nfunction movePatch<T extends { id: string; order: number }>(\n bucket: T[],\n id: string,\n toIndex: number,\n): Map<string, number> | null {\n const fromIndex = bucket.findIndex((e) => e.id === id)\n if (fromIndex === -1) return null\n const clamped = Math.max(0, Math.min(bucket.length - 1, toIndex))\n if (clamped === fromIndex) return null\n const next = [...bucket]\n const [moved] = next.splice(fromIndex, 1)\n next.splice(clamped, 0, moved!)\n const orders = new Map<string, number>()\n next.forEach((entity, index) => {\n if (entity.order !== index) orders.set(entity.id, index)\n })\n return orders.size > 0 ? orders : null\n}\n\nfunction updateLayer(\n state: LegendState,\n id: string,\n patch: Partial<LegendLayer>,\n): Partial<LegendState> {\n const layer = state.layers[id]\n if (!layer) return {}\n return { layers: { ...state.layers, [id]: { ...layer, ...patch } } }\n}\n\nfunction updateGroup(\n state: LegendState,\n id: string,\n patch: Partial<LegendGroup>,\n): Partial<LegendState> {\n const group = state.groups[id]\n if (!group) return {}\n return { groups: { ...state.groups, [id]: { ...group, ...patch } } }\n}\n\n/**\n * Merge incoming config-select sections while preserving the user's picked\n * `active` for any section id that still exists and whose pick is still among\n * the new `options` (the structure — ids, titles, options, order — always\n * follows the props). Returns the previous array when the merge lands on the\n * same content, so unchanged syncs keep entity identity (bail-out).\n */\nfunction mergeSections(\n prev: LegendConfigSection[] | undefined,\n next: LegendConfigSection[] | undefined,\n): LegendConfigSection[] | undefined {\n if (!next || !prev || prev === next) return next\n const merged = next.map((section) => {\n const prevSection = prev.find((p) => p.id === section.id)\n return prevSection &&\n prevSection.active !== section.active &&\n section.options.includes(prevSection.active)\n ? { ...section, active: prevSection.active }\n : section\n })\n const sameAsPrev =\n prev.length === merged.length &&\n merged.every((m, i) => {\n const p = prev[i]!\n return (\n p.id === m.id &&\n p.title === m.title &&\n p.options === m.options &&\n p.active === m.active\n )\n })\n return sameAsPrev ? prev : merged\n}\n\n/**\n * Same-type, same-key React elements with shallow-equal props count as\n * equal, so a ReactNode field (e.g. `LegendGroup.icon`) re-created inline on\n * every render (`icon={<MyIcon />}`) doesn't look \"changed\" on every sync. A\n * different `key` is treated as a real change, same as a different type.\n */\nfunction reactElementEqual(a: unknown, b: unknown): boolean {\n if (!isValidElement(a) || !isValidElement(b)) return false\n if (a.type !== b.type || a.key !== b.key) return false\n return shallowEqualEntity(\n a.props as Record<string, unknown>,\n b.props as Record<string, unknown>,\n )\n}\n\n/**\n * Shallow equality over the union of both objects' keys — `Object.is` per\n * value, except React elements, which fall back to {@link reactElementEqual}.\n */\nfunction shallowEqualEntity<T extends object>(a: T, b: T): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]) as Set<keyof T>\n for (const key of keys) {\n if (Object.is(a[key], b[key])) continue\n if (!reactElementEqual(a[key], b[key])) return false\n }\n return true\n}\n\n/**\n * Reassign `order` to dense indexes `0..n-1` within each sibling bucket,\n * sorted by current order with ties broken by input position. This is the\n * only boundary where external (possibly duplicated) orders enter, so the\n * stored orders stay dense and unique within each bucket.\n */\nfunction normalizeOrders<T extends { order: number }>(\n entries: { merged: T; index: number }[],\n bucketOf: (e: T) => string | undefined,\n): void {\n const buckets = new Map<string | undefined, { merged: T; index: number }[]>()\n for (const entry of entries) {\n const key = bucketOf(entry.merged)\n const bucket = buckets.get(key)\n if (bucket) bucket.push(entry)\n else buckets.set(key, [entry])\n }\n for (const bucket of buckets.values()) {\n bucket\n .sort((a, b) => a.merged.order - b.merged.order || a.index - b.index)\n .forEach((entry, i) => {\n entry.merged.order = i\n })\n }\n}\n\n/**\n * Seed/merge one layer: static fields follow the input; interactive state\n * (`visible`/`opacity`/`collapsed`/`order`/`collapsedBeforeHide` + section\n * actives) sticks to the store entry when present. Shared by `_sync` (per\n * entry) and the imperative `setLegendLayer`.\n */\nfunction mergeLayerEntity(\n prev: LegendLayer | undefined,\n input: LegendLayerInput,\n fallbackOrder: number,\n): LegendLayer {\n return {\n ...input,\n visible: prev?.visible ?? input.visible ?? true,\n opacity: prev?.opacity ?? input.opacity ?? 1,\n collapsed: prev?.collapsed ?? input.collapsed ?? false,\n collapsedBeforeHide: prev?.collapsedBeforeHide,\n sections: mergeSections(prev?.sections, input.sections),\n order: prev?.order ?? input.order ?? fallbackOrder,\n } as LegendLayer\n}\n\n/** Group counterpart of {@link mergeLayerEntity}. */\nfunction mergeGroupEntity(\n prev: LegendGroup | undefined,\n input: LegendGroupInput,\n fallbackOrder: number,\n): LegendGroup {\n return {\n ...input,\n collapsed: prev?.collapsed ?? input.collapsed ?? false,\n collapsedBeforeHide: prev?.collapsedBeforeHide,\n order: prev?.order ?? input.order ?? fallbackOrder,\n } as LegendGroup\n}\n\n/**\n * Merge incoming definitions while preserving interactive state of known\n * entities: static fields (name, subtitle, variables, attributes, …) follow\n * the props; `visible`/`opacity`/`collapsed`/`order` stick to what's in the\n * store. New entities are seeded; vanished ones are dropped. Sibling orders\n * are normalized to dense indexes.\n *\n * Unchanged entities keep their previous object identity (`variables`\n * compared by reference), and when nothing changed at all the sync is a\n * no-op (`{}`), so stable consumer props never produce a state update.\n */\nfunction syncState(\n state: LegendState,\n layerInputs: LegendLayerInput[],\n groupInputs: LegendGroupInput[],\n): Partial<LegendState> {\n const layerEntries = layerInputs.map((input, index) => ({\n index,\n merged: mergeLayerEntity(state.layers[input.id], input, index),\n }))\n normalizeOrders(layerEntries, (l) => l.groupId)\n\n const groupEntries = groupInputs.map((input, index) => ({\n index,\n merged: mergeGroupEntity(state.groups[input.id], input, index),\n }))\n normalizeOrders(groupEntries, () => undefined)\n\n // Reference preservation: reuse the previous entity object when nothing\n // about it changed, so subscribers see stable identities.\n let layersChanged = layerEntries.length !== Object.keys(state.layers).length\n const layers: Record<string, LegendLayer> = {}\n for (const { merged } of layerEntries) {\n const prev = state.layers[merged.id]\n if (prev && shallowEqualEntity(prev, merged)) {\n layers[merged.id] = prev\n } else {\n layers[merged.id] = merged\n layersChanged = true\n }\n }\n\n let groupsChanged = groupEntries.length !== Object.keys(state.groups).length\n const groups: Record<string, LegendGroup> = {}\n for (const { merged } of groupEntries) {\n const prev = state.groups[merged.id]\n if (prev && shallowEqualEntity(prev, merged)) {\n groups[merged.id] = prev\n } else {\n groups[merged.id] = merged\n groupsChanged = true\n }\n }\n\n if (!layersChanged && !groupsChanged) return {}\n return {\n layers: layersChanged ? layers : state.layers,\n groups: groupsChanged ? groups : state.groups,\n }\n}\n\n/**\n * Rebuild a layer/group record from a candidate map, normalizing dense order\n * per bucket and preserving the previous object identity for entries that are\n * unchanged. Returns `null` when nothing changed (so callers can bail with\n * `{}`).\n */\nfunction rebuildRecord<\n T extends { id: string; order: number; groupId?: string },\n>(\n prev: Record<string, T>,\n next: Record<string, T>,\n bucketOf: (e: T) => string | undefined,\n): Record<string, T> | null {\n const entries = Object.values(next).map((e, index) => ({\n index,\n merged: { ...e },\n }))\n normalizeOrders(entries, bucketOf)\n let changed = entries.length !== Object.keys(prev).length\n const out: Record<string, T> = {}\n for (const { merged } of entries) {\n const before = prev[merged.id]\n if (before && shallowEqualEntity(before, merged)) {\n out[merged.id] = before\n } else {\n out[merged.id] = merged\n changed = true\n }\n }\n return changed ? out : null\n}\n\n/** Add or update a single layer (imperative `setLegendLayer`). */\nfunction upsertLayerState(\n state: LegendState,\n input: LegendLayerInput,\n): Partial<LegendState> {\n const siblingCount = Object.values(state.layers).filter(\n (l) => l.groupId === input.groupId && l.id !== input.id,\n ).length\n const merged = mergeLayerEntity(state.layers[input.id], input, siblingCount)\n const layers = rebuildRecord(\n state.layers,\n { ...state.layers, [input.id]: merged },\n (l) => l.groupId,\n )\n return layers ? { layers } : {}\n}\n\n/** Remove a single layer, re-densifying its sibling orders. */\nfunction removeLayerState(\n state: LegendState,\n id: string,\n): Partial<LegendState> {\n if (!state.layers[id]) return {}\n const next = { ...state.layers }\n delete next[id]\n const layers = rebuildRecord(state.layers, next, (l) => l.groupId)\n return layers ? { layers } : {}\n}\n\n/** Add or update a single group (imperative `setLegendGroup`). */\nfunction upsertGroupState(\n state: LegendState,\n input: LegendGroupInput,\n): Partial<LegendState> {\n const count = Object.values(state.groups).filter(\n (g) => g.id !== input.id,\n ).length\n const merged = mergeGroupEntity(state.groups[input.id], input, count)\n const groups = rebuildRecord(\n state.groups,\n { ...state.groups, [input.id]: merged },\n () => undefined,\n )\n return groups ? { groups } : {}\n}\n\n/**\n * Remove a group; its member layers are un-grouped (`groupId` cleared) so they\n * survive as ungrouped rows. Re-densifies both group and layer orders.\n */\nfunction removeGroupState(\n state: LegendState,\n id: string,\n): Partial<LegendState> {\n if (!state.groups[id]) return {}\n const nextGroups = { ...state.groups }\n delete nextGroups[id]\n const groups = rebuildRecord(state.groups, nextGroups, () => undefined)\n\n const members = Object.values(state.layers).filter((l) => l.groupId === id)\n if (members.length === 0) return groups ? { groups } : {}\n\n const nextLayers = { ...state.layers }\n for (const member of members) {\n nextLayers[member.id] = { ...member, groupId: undefined }\n }\n const layers = rebuildRecord(state.layers, nextLayers, (l) => l.groupId)\n return {\n ...(groups ? { groups } : {}),\n ...(layers ? { layers } : {}),\n }\n}\n\n// ─── Store factory ────────────────────────────────────────────────────────────\n\n/**\n * @internal — used by Provider; not part of the public API.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function createLegendStore(\n id: string,\n init: LegendInit = {},\n): LegendStoreApi {\n // Seed through the same merge/normalize path as `_sync`, so a later sync\n // with identical input is a guaranteed no-op (stable identities).\n const seeded = syncState(\n { layers: {}, groups: {} } as LegendState,\n init.layers ?? [],\n init.groups ?? [],\n )\n\n return createStore<LegendState>()(\n devtools(\n (set) => ({\n layers: seeded.layers ?? {},\n groups: seeded.groups ?? {},\n\n setVisibility: (lid, visible) =>\n set(\n (s) => {\n const layer = s.layers[lid]\n const patch = layer && visibilityPatch(layer, visible)\n return patch ? updateLayer(s, lid, patch) : {}\n },\n false,\n 'setVisibility',\n ),\n setOpacity: (lid, opacity) =>\n set(\n (s) => updateLayer(s, lid, { opacity: clamp01(opacity) }),\n false,\n 'setOpacity',\n ),\n setCollapsed: (lid, collapsed) =>\n set(\n (s) => {\n const layer = s.layers[lid]\n return layer\n ? updateLayer(s, lid, collapsePatch(layer, collapsed))\n : {}\n },\n false,\n 'setCollapsed',\n ),\n setSectionValue: (lid, sectionId, value) =>\n set(\n (s) => {\n const layer = s.layers[lid]\n const section = layer?.sections?.find((x) => x.id === sectionId)\n if (\n !layer?.sections ||\n !section ||\n section.active === value ||\n !section.options.includes(value)\n ) {\n return {}\n }\n const sections = layer.sections.map((x) =>\n x.id === sectionId ? { ...x, active: value } : x,\n )\n return updateLayer(s, lid, { sections })\n },\n false,\n 'setSectionValue',\n ),\n\n moveLayer: (lid, toIndex) =>\n set(\n (s) => {\n const layer = s.layers[lid]\n if (!layer) return {}\n const bucket = selectLayersByGroup(s, layer.groupId)\n const orders = movePatch(bucket, lid, toIndex)\n if (!orders) return {}\n const layers = { ...s.layers }\n for (const [id, order] of orders) {\n layers[id] = { ...layers[id]!, order }\n }\n return { layers }\n },\n false,\n 'moveLayer',\n ),\n\n setGroupVisibility: (gid, visible) =>\n set(\n (s) => {\n const group = s.groups[gid]\n if (!group) return {}\n const members = Object.values(s.layers).filter(\n (l) => l.groupId === gid,\n )\n const anyVisible = members.some((l) => l.visible)\n // Idempotence on the derived state: hide needs a visible member,\n // show needs a fully-hidden group (mixed acts in both directions\n // except show-from-mixed still shows the hidden remainder).\n if (members.length === 0 || (!visible && !anyVisible)) return {}\n\n // Cascade: each member runs the standard visibility↔collapse\n // coupling, so per-layer collapse snapshots survive a group\n // hide/show; members already at the target are untouched.\n const layers = { ...s.layers }\n let layersChanged = false\n for (const member of members) {\n const patch = visibilityPatch(member, visible)\n if (patch) {\n layers[member.id] = { ...member, ...patch }\n layersChanged = true\n }\n }\n if (!layersChanged) return {}\n\n // Group-level collapse coupling, only on real derived\n // transitions: any-visible→hidden snapshots + collapses;\n // hidden→visible restores the snapshot.\n let groupPatch: Partial<LegendGroup> | null = null\n if (!visible && anyVisible) {\n groupPatch = {\n collapsed: true,\n collapsedBeforeHide: group.collapsed,\n }\n } else if (visible && !anyVisible) {\n groupPatch = {\n collapsed: group.collapsedBeforeHide ?? false,\n collapsedBeforeHide: undefined,\n }\n }\n return {\n layers,\n ...(groupPatch\n ? {\n groups: {\n ...s.groups,\n [gid]: { ...group, ...groupPatch },\n },\n }\n : {}),\n }\n },\n false,\n 'setGroupVisibility',\n ),\n setGroupCollapsed: (gid, collapsed) =>\n set(\n (s) => {\n const group = s.groups[gid]\n if (!group) return {}\n // Group visibility is derived from members; while the group is\n // hidden the snapshot follows the manual choice (layer parity).\n const members = Object.values(s.layers).filter(\n (l) => l.groupId === gid,\n )\n const hidden =\n members.length > 0 && members.every((l) => !l.visible)\n return updateGroup(\n s,\n gid,\n hidden\n ? { collapsed, collapsedBeforeHide: collapsed }\n : { collapsed },\n )\n },\n false,\n 'setGroupCollapsed',\n ),\n\n moveGroup: (gid, toIndex) =>\n set(\n (s) => {\n if (!s.groups[gid]) return {}\n const orders = movePatch(selectOrderedGroups(s), gid, toIndex)\n if (!orders) return {}\n const groups = { ...s.groups }\n for (const [id, order] of orders) {\n groups[id] = { ...groups[id]!, order }\n }\n return { groups }\n },\n false,\n 'moveGroup',\n ),\n\n setLegendLayer: (input) =>\n set((s) => upsertLayerState(s, input), false, 'setLegendLayer'),\n removeLegendLayer: (lid) =>\n set((s) => removeLayerState(s, lid), false, 'removeLegendLayer'),\n setLegendGroup: (input) =>\n set((s) => upsertGroupState(s, input), false, 'setLegendGroup'),\n removeLegendGroup: (gid) =>\n set((s) => removeGroupState(s, gid), false, 'removeLegendGroup'),\n\n _sync: (layerInputs, groupInputs) =>\n set((s) => syncState(s, layerInputs, groupInputs), false, '_sync'),\n }),\n { name: `legend-${id}`, enabled: isDev() },\n ),\n )\n}\n\n// ─── Registry ───────────────────────────────────────────────────────────────\n\n/** @experimental This API is new and may change in a future release. */\nexport function getLegendStore(id: string): LegendStoreApi {\n const store = legendStores.get(id)\n if (!store) throw new Error(`[legend] Legend store \"${id}\" not found.`)\n return store\n}\n\n/** @experimental This API is new and may change in a future release. */\nexport function hasLegendStore(id: string): boolean {\n return legendStores.has(id)\n}\n\n/** @experimental This API is new and may change in a future release. */\nexport function deleteLegendStore(id: string): void {\n legendStores.delete(id)\n}\n\n/** @experimental This API is new and may change in a future release. */\nexport function clearAllLegendStores(): void {\n legendStores.clear()\n legendMountCounts.clear()\n warnedDuplicates.clear()\n}\n\n/**\n * @internal — used by Provider's lazy init so children can resolve the store first render.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function setLegendStoreEntry(id: string, store: LegendStoreApi): void {\n legendStores.set(id, store)\n}\n\n/**\n * @internal — registers a Provider mount and warns on duplicate ids in dev.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function registerLegendStore(id: string, store: LegendStoreApi): void {\n legendStores.set(id, store)\n const count = (legendMountCounts.get(id) ?? 0) + 1\n legendMountCounts.set(id, count)\n if (count > 1 && isDev() && !warnedDuplicates.has(id)) {\n // eslint-disable-next-line no-console\n console.warn(\n `[legend] Duplicate <Legend.Provider id=\"${id}\"> detected. ` +\n `Multiple providers sharing an id will race on prop sync. ` +\n `Use unique ids per legend panel.`,\n )\n warnedDuplicates.add(id)\n }\n}\n\n/**\n * @internal — Provider unmount counterpart; removes the entry on last unmount.\n *\n * @experimental This API is new and may change in a future release.\n */\nexport function unregisterLegendStore(\n id: string,\n options: { keepAlive: boolean },\n): void {\n const count = (legendMountCounts.get(id) ?? 1) - 1\n if (count <= 0) {\n legendMountCounts.delete(id)\n if (!options.keepAlive) legendStores.delete(id)\n } else {\n legendMountCounts.set(id, count)\n }\n}\n\n// ─── Hooks ────────────────────────────────────────────────────────────────────\n\n/** @experimental This API is new and may change in a future release. */\nexport function useLegendStore<T>(\n id: string,\n selector: (state: LegendState) => T,\n): T {\n const store = getLegendStore(id) as unknown as StoreApi<LegendState>\n return useStore(store, selector)\n}\n\n/** @experimental This API is new and may change in a future release. */\nexport function useLegendShallow<T>(\n id: string,\n selector: (state: LegendState) => T,\n): T {\n const store = getLegendStore(id) as unknown as StoreApi<LegendState>\n return useStore(store, useShallow(selector))\n}\n"],"names":["LegendContext","createContext","useLegendId","id","useContext","Error","byOrder","a","b","order","selectOrderedGroups","state","Object","values","groups","sort","selectLayersByGroup","groupId","layers","filter","l","selectOrderedLayers","selectAllGroupsCollapsed","length","every","g","collapsed","selectHasGroups","keys","selectVisibleLayersGrouped","visible","sections","group","push","ungrouped","undefined","selectLayerCollapsible","layerId","layer","variables","Boolean","helperText","selectGroupVisibility","anyVisible","anyHidden","legendStores","Map","legendMountCounts","warnedDuplicates","Set","isDev","import","clamp01","n","Math","min","max","visibilityPatch","entity","collapsedBeforeHide","collapsePatch","movePatch","bucket","toIndex","fromIndex","findIndex","e","clamped","next","moved","splice","orders","forEach","index","set","size","updateLayer","patch","updateGroup","mergeSections","prev","merged","map","section","prevSection","find","p","active","options","includes","m","i","title","reactElementEqual","isValidElement","type","key","shallowEqualEntity","props","is","normalizeOrders","entries","bucketOf","buckets","entry","get","mergeLayerEntity","input","fallbackOrder","opacity","mergeGroupEntity","syncState","layerInputs","groupInputs","layerEntries","groupEntries","layersChanged","groupsChanged","rebuildRecord","changed","out","before","upsertLayerState","siblingCount","removeLayerState","upsertGroupState","count","removeGroupState","nextGroups","members","nextLayers","member","createLegendStore","init","seeded","createStore","devtools","setVisibility","lid","s","setOpacity","setCollapsed","setSectionValue","sectionId","value","x","moveLayer","setGroupVisibility","gid","some","groupPatch","setGroupCollapsed","hidden","moveGroup","setLegendLayer","removeLegendLayer","setLegendGroup","removeLegendGroup","_sync","name","enabled","getLegendStore","store","hasLegendStore","has","deleteLegendStore","delete","clearAllLegendStores","clear","setLegendStoreEntry","registerLegendStore","console","warn","add","unregisterLegendStore","keepAlive","useLegendStore","selector","$","_c","t0","useStore","useLegendShallow","useShallow"],"mappings":";;;;;;AAGO,MAAMA,IAAgBC,EAA6B,IAAI;AAGvD,SAAAC,KAAA;AACL,QAAAC,IAAWC,EAAWJ,CAAa;AACnC,MAAIG,KAAM;AACR,UAAM,IAAIE,MACR,0LAGF;AACD,SACMF;AAAE;ACbX,MAAMG,IAAU,CAA8BC,GAAMC,MAClDD,EAAEE,QAAQD,EAAEC;AAOP,SAASC,EAAoBC,GAAmC;AACrE,SAAOC,OAAOC,OAAOF,EAAMG,MAAM,EAAEC,KAAKT,CAAO;AACjD;AAQO,SAASU,EACdL,GACAM,GACe;AACf,SAAOL,OAAOC,OAAOF,EAAMO,MAAM,EAC9BC,OAAQC,CAAAA,MAAMA,EAAEH,YAAYA,CAAO,EACnCF,KAAKT,CAAO;AACjB;AAOO,SAASe,GAAoBV,GAAmC;AACrE,SAAOC,OAAOC,OAAOF,EAAMO,MAAM,EAAEH,KAAKT,CAAO;AACjD;AAQO,SAASgB,GAAyBX,GAA6B;AACpE,QAAMG,IAASF,OAAOC,OAAOF,EAAMG,MAAM;AACzC,SAAOA,EAAOS,SAAS,KAAKT,EAAOU,MAAOC,CAAAA,MAAMA,EAAEC,SAAS;AAC7D;AAOO,SAASC,GAAgBhB,GAA6B;AAC3D,SAAOC,OAAOgB,KAAKjB,EAAMG,MAAM,EAAES,SAAS;AAC5C;AAOO,SAASM,GACdlB,GACkD;AAClD,QAAMmB,IAAUA,CAACb,MACfD,EAAoBL,GAAOM,CAAO,EAAEE,OAAQC,CAAAA,MAAMA,EAAEU,OAAO,GACvDC,IAA6D,CAAA;AACnE,aAAWC,KAAStB,EAAoBC,CAAK,GAAG;AAC9C,UAAMO,IAASY,EAAQ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