@optimum-intelligence/opti-ui 0.7.4 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,24 +86,28 @@ function hasValidPositions(coords, min) {
86
86
  };
87
87
  return check(coords) && count >= min;
88
88
  }
89
- /** Grows `bounds` by every `[lng, lat]` pair nested in `coords`. */
90
- function extend(bounds, coords) {
91
- if (!Array.isArray(coords)) return bounds;
92
- if (typeof coords[0] === "number") {
93
- const [x, y] = coords;
94
- return bounds ? [
95
- Math.min(bounds[0], x),
96
- Math.min(bounds[1], y),
97
- Math.max(bounds[2], x),
98
- Math.max(bounds[3], y)
99
- ] : [
100
- x,
101
- y,
102
- x,
103
- y
104
- ];
105
- }
106
- return coords.reduce(extend, bounds);
89
+ /** `[w, s, e, n]` around every `[lng, lat]` pair nested in `coords`, or null when there is none. */
90
+ function boundsOf(coords) {
91
+ let w = Infinity, s = Infinity, e = -Infinity, n = -Infinity;
92
+ const visit = (value) => {
93
+ if (!Array.isArray(value)) return;
94
+ if (typeof value[0] !== "number") {
95
+ for (const child of value) visit(child);
96
+ return;
97
+ }
98
+ const [x, y] = value;
99
+ if (x < w) w = x;
100
+ if (x > e) e = x;
101
+ if (y < s) s = y;
102
+ if (y > n) n = y;
103
+ };
104
+ visit(coords);
105
+ return w <= e ? [
106
+ w,
107
+ s,
108
+ e,
109
+ n
110
+ ] : null;
107
111
  }
108
112
  var toneColors = {
109
113
  neutral: {
@@ -159,7 +163,7 @@ var dimmed = (hasSelection, dim) => hasSelection ? [
159
163
  * and keeps the `selected` feature state in sync (also after a style switch re-adds the source).
160
164
  */
161
165
  function useDataPart(partName, sourceId, options) {
162
- const $ = c(36);
166
+ const $ = c(62);
163
167
  const ctx = useMapContext(partName);
164
168
  const { items, selectedIds: t0, layerIds, coordinates, minPositions: t1, onItemClick, onItemHover } = options;
165
169
  let t2;
@@ -171,7 +175,6 @@ function useDataPart(partName, sourceId, options) {
171
175
  const selectedIds = t2;
172
176
  const minPositions = t1 === void 0 ? 1 : t1;
173
177
  const { register, setHandlers, map } = ctx;
174
- const selected = new Set(selectedIds);
175
178
  let t3;
176
179
  if ($[2] !== selectedIds) {
177
180
  t3 = selectedIds.join("\0");
@@ -180,83 +183,124 @@ function useDataPart(partName, sourceId, options) {
180
183
  } else t3 = $[3];
181
184
  const selectedKey = t3;
182
185
  let t4;
183
- if ($[4] !== coordinates || $[5] !== minPositions) {
184
- t4 = (item) => hasValidPositions(coordinates(item), minPositions);
185
- $[4] = coordinates;
186
- $[5] = minPositions;
187
- $[6] = t4;
188
- } else t4 = $[6];
189
- const valid = new Set(items.filter(t4));
190
- const invalidIds = items.filter((item_0) => !valid.has(item_0)).map(_temp).join(", ");
191
186
  let t5;
192
187
  let t6;
193
- if ($[7] !== invalidIds || $[8] !== partName) {
194
- t5 = () => {
188
+ if ($[4] !== coordinates || $[5] !== items || $[6] !== minPositions) {
189
+ let t7;
190
+ if ($[10] !== coordinates || $[11] !== minPositions) {
191
+ t7 = (item) => hasValidPositions(coordinates(item), minPositions);
192
+ $[10] = coordinates;
193
+ $[11] = minPositions;
194
+ $[12] = t7;
195
+ } else t7 = $[12];
196
+ const drawable = items.filter(t7);
197
+ const set = new Set(drawable);
198
+ t4 = set;
199
+ t5 = items.filter((item_0) => !set.has(item_0)).map(_temp).join(", ");
200
+ t6 = boundsOf(drawable.map(coordinates));
201
+ $[4] = coordinates;
202
+ $[5] = items;
203
+ $[6] = minPositions;
204
+ $[7] = t4;
205
+ $[8] = t5;
206
+ $[9] = t6;
207
+ } else {
208
+ t4 = $[7];
209
+ t5 = $[8];
210
+ t6 = $[9];
211
+ }
212
+ let t7;
213
+ if ($[13] !== t4 || $[14] !== t5 || $[15] !== t6) {
214
+ t7 = {
215
+ valid: t4,
216
+ invalidIds: t5,
217
+ bounds: t6
218
+ };
219
+ $[13] = t4;
220
+ $[14] = t5;
221
+ $[15] = t6;
222
+ $[16] = t7;
223
+ } else t7 = $[16];
224
+ const { valid, invalidIds, bounds } = t7;
225
+ let t8;
226
+ if ($[17] !== selectedKey) {
227
+ t8 = new Set(selectedKey ? selectedKey.split("\0") : []);
228
+ $[17] = selectedKey;
229
+ $[18] = t8;
230
+ } else t8 = $[18];
231
+ const selected = t8;
232
+ let t9;
233
+ if ($[19] !== coordinates || $[20] !== selected || $[21] !== valid) {
234
+ t9 = boundsOf([...valid].filter((item_2) => selected.has(item_2.id)).map(coordinates));
235
+ $[19] = coordinates;
236
+ $[20] = selected;
237
+ $[21] = valid;
238
+ $[22] = t9;
239
+ } else t9 = $[22];
240
+ const selectedBounds = t9;
241
+ let t10;
242
+ let t11;
243
+ if ($[23] !== invalidIds || $[24] !== partName) {
244
+ t10 = () => {
195
245
  if (invalidIds && process.env.NODE_ENV !== "production") console.warn(`${partName}: skipped items with invalid coordinates: ${invalidIds}`);
196
246
  };
197
- t6 = [partName, invalidIds];
198
- $[7] = invalidIds;
199
- $[8] = partName;
200
- $[9] = t5;
201
- $[10] = t6;
247
+ t11 = [partName, invalidIds];
248
+ $[23] = invalidIds;
249
+ $[24] = partName;
250
+ $[25] = t10;
251
+ $[26] = t11;
202
252
  } else {
203
- t5 = $[9];
204
- t6 = $[10];
205
- }
206
- React.useEffect(t5, t6);
207
- let bounds = null;
208
- let selectedBounds = null;
209
- for (const item_2 of valid) {
210
- bounds = extend(bounds, coordinates(item_2));
211
- if (selected.has(item_2.id)) selectedBounds = extend(selectedBounds, coordinates(item_2));
253
+ t10 = $[25];
254
+ t11 = $[26];
212
255
  }
256
+ React.useEffect(t10, t11);
213
257
  const boundsKey = `${bounds}|${selectedBounds}|${layerIds}`;
214
- let t7;
215
- if ($[11] !== bounds || $[12] !== layerIds || $[13] !== register || $[14] !== selectedBounds || $[15] !== sourceId) {
216
- t7 = () => {
258
+ let t12;
259
+ if ($[27] !== bounds || $[28] !== layerIds || $[29] !== register || $[30] !== selectedBounds || $[31] !== sourceId) {
260
+ t12 = () => {
217
261
  register(sourceId, {
218
262
  layerIds,
219
263
  bounds,
220
264
  selectedBounds
221
265
  });
222
266
  };
223
- $[11] = bounds;
224
- $[12] = layerIds;
225
- $[13] = register;
226
- $[14] = selectedBounds;
227
- $[15] = sourceId;
228
- $[16] = t7;
229
- } else t7 = $[16];
230
- let t8;
231
- if ($[17] !== boundsKey || $[18] !== register || $[19] !== sourceId) {
232
- t8 = [
267
+ $[27] = bounds;
268
+ $[28] = layerIds;
269
+ $[29] = register;
270
+ $[30] = selectedBounds;
271
+ $[31] = sourceId;
272
+ $[32] = t12;
273
+ } else t12 = $[32];
274
+ let t13;
275
+ if ($[33] !== boundsKey || $[34] !== register || $[35] !== sourceId) {
276
+ t13 = [
233
277
  register,
234
278
  sourceId,
235
279
  boundsKey
236
280
  ];
237
- $[17] = boundsKey;
238
- $[18] = register;
239
- $[19] = sourceId;
240
- $[20] = t8;
241
- } else t8 = $[20];
242
- React.useEffect(t7, t8);
243
- let t10;
244
- let t9;
245
- if ($[21] !== register || $[22] !== sourceId) {
246
- t9 = () => () => register(sourceId, null);
247
- t10 = [register, sourceId];
248
- $[21] = register;
249
- $[22] = sourceId;
250
- $[23] = t10;
251
- $[24] = t9;
281
+ $[33] = boundsKey;
282
+ $[34] = register;
283
+ $[35] = sourceId;
284
+ $[36] = t13;
285
+ } else t13 = $[36];
286
+ React.useEffect(t12, t13);
287
+ let t14;
288
+ let t15;
289
+ if ($[37] !== register || $[38] !== sourceId) {
290
+ t14 = () => () => register(sourceId, null);
291
+ t15 = [register, sourceId];
292
+ $[37] = register;
293
+ $[38] = sourceId;
294
+ $[39] = t14;
295
+ $[40] = t15;
252
296
  } else {
253
- t10 = $[23];
254
- t9 = $[24];
297
+ t14 = $[39];
298
+ t15 = $[40];
255
299
  }
256
- React.useEffect(t9, t10);
257
- let t11;
258
- if ($[25] !== items || $[26] !== onItemClick || $[27] !== onItemHover || $[28] !== setHandlers || $[29] !== sourceId) {
259
- t11 = () => {
300
+ React.useEffect(t14, t15);
301
+ let t16;
302
+ if ($[41] !== items || $[42] !== onItemClick || $[43] !== onItemHover || $[44] !== setHandlers || $[45] !== sourceId) {
303
+ t16 = () => {
260
304
  const byId = (id) => items.find((item_3) => item_3.id === id);
261
305
  setHandlers(sourceId, {
262
306
  onClick: (id_0, event) => {
@@ -266,73 +310,97 @@ function useDataPart(partName, sourceId, options) {
266
310
  onHover: (id_1, event_0) => onItemHover?.(id_1 == null ? null : byId(id_1) ?? null, event_0)
267
311
  });
268
312
  };
269
- $[25] = items;
270
- $[26] = onItemClick;
271
- $[27] = onItemHover;
272
- $[28] = setHandlers;
273
- $[29] = sourceId;
274
- $[30] = t11;
275
- } else t11 = $[30];
276
- React.useEffect(t11);
277
- let t12;
278
- let t13;
279
- if ($[31] !== setHandlers || $[32] !== sourceId) {
280
- t12 = () => () => setHandlers(sourceId, null);
281
- t13 = [setHandlers, sourceId];
282
- $[31] = setHandlers;
283
- $[32] = sourceId;
284
- $[33] = t12;
285
- $[34] = t13;
313
+ $[41] = items;
314
+ $[42] = onItemClick;
315
+ $[43] = onItemHover;
316
+ $[44] = setHandlers;
317
+ $[45] = sourceId;
318
+ $[46] = t16;
319
+ } else t16 = $[46];
320
+ React.useEffect(t16);
321
+ let t17;
322
+ let t18;
323
+ if ($[47] !== setHandlers || $[48] !== sourceId) {
324
+ t17 = () => () => setHandlers(sourceId, null);
325
+ t18 = [setHandlers, sourceId];
326
+ $[47] = setHandlers;
327
+ $[48] = sourceId;
328
+ $[49] = t17;
329
+ $[50] = t18;
286
330
  } else {
287
- t12 = $[33];
288
- t13 = $[34];
331
+ t17 = $[49];
332
+ t18 = $[50];
289
333
  }
290
- React.useEffect(t12, t13);
291
- let t14;
292
- if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
293
- t14 = /* @__PURE__ */ new Set();
294
- $[35] = t14;
295
- } else t14 = $[35];
296
- const applied = React.useRef(t14);
297
- React.useEffect(() => {
298
- const instance = map?.getMap();
299
- if (!instance) return;
300
- const drawn = new Set([...valid].map(_temp2));
301
- const target = new Set((selectedKey ? selectedKey.split("\0") : []).filter((id_2) => drawn.has(id_2)));
302
- const sync = () => {
303
- if (!instance.getSource(sourceId)) return;
304
- const prev = applied.current;
305
- for (const id_3 of prev) if (!target.has(id_3)) instance.setFeatureState({
306
- source: sourceId,
307
- id: id_3
308
- }, { selected: false });
309
- for (const id_4 of target) if (!prev.has(id_4)) instance.setFeatureState({
310
- source: sourceId,
311
- id: id_4
312
- }, { selected: true });
313
- applied.current = target;
314
- };
315
- sync();
316
- const onData = (e) => {
317
- if (e.sourceId !== sourceId || e.sourceDataType !== "metadata") return;
318
- applied.current = /* @__PURE__ */ new Set();
334
+ React.useEffect(t17, t18);
335
+ let t19;
336
+ if ($[51] === Symbol.for("react.memo_cache_sentinel")) {
337
+ t19 = /* @__PURE__ */ new Set();
338
+ $[51] = t19;
339
+ } else t19 = $[51];
340
+ const applied = React.useRef(t19);
341
+ let t20;
342
+ let t21;
343
+ if ($[52] !== map || $[53] !== selectedKey || $[54] !== sourceId || $[55] !== valid) {
344
+ t20 = () => {
345
+ const instance = map?.getMap();
346
+ if (!instance) return;
347
+ const drawn = new Set([...valid].map(_temp2));
348
+ const target = new Set((selectedKey ? selectedKey.split("\0") : []).filter((id_2) => drawn.has(id_2)));
349
+ const sync = () => {
350
+ if (!instance.getSource(sourceId)) return;
351
+ const prev = applied.current;
352
+ for (const id_3 of prev) if (!target.has(id_3)) instance.setFeatureState({
353
+ source: sourceId,
354
+ id: id_3
355
+ }, { selected: false });
356
+ for (const id_4 of target) if (!prev.has(id_4)) instance.setFeatureState({
357
+ source: sourceId,
358
+ id: id_4
359
+ }, { selected: true });
360
+ applied.current = target;
361
+ };
319
362
  sync();
363
+ const onData = (e) => {
364
+ if (e.sourceId !== sourceId || e.sourceDataType !== "metadata") return;
365
+ applied.current = /* @__PURE__ */ new Set();
366
+ sync();
367
+ };
368
+ instance.on("sourcedata", onData);
369
+ return () => {
370
+ instance.off("sourcedata", onData);
371
+ };
320
372
  };
321
- instance.on("sourcedata", onData);
322
- return () => {
323
- instance.off("sourcedata", onData);
373
+ t21 = [
374
+ map,
375
+ sourceId,
376
+ valid,
377
+ selectedKey
378
+ ];
379
+ $[52] = map;
380
+ $[53] = selectedKey;
381
+ $[54] = sourceId;
382
+ $[55] = valid;
383
+ $[56] = t20;
384
+ $[57] = t21;
385
+ } else {
386
+ t20 = $[56];
387
+ t21 = $[57];
388
+ }
389
+ React.useEffect(t20, t21);
390
+ const t22 = selectedIds.length > 0;
391
+ let t23;
392
+ if ($[58] !== ctx.colors || $[59] !== t22 || $[60] !== valid) {
393
+ t23 = {
394
+ colors: ctx.colors,
395
+ hasSelection: t22,
396
+ valid
324
397
  };
325
- }, [
326
- map,
327
- sourceId,
328
- valid,
329
- selectedKey
330
- ]);
331
- return {
332
- colors: ctx.colors,
333
- hasSelection: selectedIds.length > 0,
334
- valid
335
- };
398
+ $[58] = ctx.colors;
399
+ $[59] = t22;
400
+ $[60] = valid;
401
+ $[61] = t23;
402
+ } else t23 = $[61];
403
+ return t23;
336
404
  }
337
405
  /** A source id that is safe in MapLibre layer ids. */
338
406
  function _temp2(item_5) {
@@ -528,11 +596,11 @@ function MapRoot(t0) {
528
596
  empty = entries.length > 0 && entries.every(_temp4);
529
597
  const corners = _temp5;
530
598
  const boundsKey = _temp7;
531
- dataKey = fit === "none" ? "" : boundsKey(extend(null, entries.map((t14) => {
599
+ dataKey = fit === "none" ? "" : boundsKey(boundsOf(entries.map((t14) => {
532
600
  const [, part_3] = t14;
533
601
  return corners(part_3.bounds);
534
602
  })));
535
- t12 = fit === "selected" ? boundsKey(extend(null, entries.map((t15) => {
603
+ t12 = fit === "selected" ? boundsKey(boundsOf(entries.map((t15) => {
536
604
  const [, part_4] = t15;
537
605
  return corners(part_4.selectedBounds);
538
606
  }))) : "";
@@ -636,18 +704,18 @@ function MapRoot(t0) {
636
704
  handlers.current[next_0.source]?.onHover?.(String(next_0.id), event_0);
637
705
  }
638
706
  hovered.current = next_0;
639
- setCursor(next_0 ? "pointer" : "");
640
707
  };
641
708
  $[46] = t18;
642
709
  } else t18 = $[46];
643
710
  const setHover = t18;
711
+ const zoomToCluster = _temp0;
644
712
  let t19;
645
713
  let t20;
646
714
  if ($[47] !== expanded) {
647
715
  t19 = () => {
648
716
  if (!expanded) return;
649
- const onKeyDown = (event_1) => {
650
- if (event_1.key === "Escape" && !event_1.defaultPrevented) setExpanded(false);
717
+ const onKeyDown = (event_2) => {
718
+ if (event_2.key === "Escape" && !event_2.defaultPrevented) setExpanded(false);
651
719
  };
652
720
  document.addEventListener("keydown", onKeyDown);
653
721
  return () => document.removeEventListener("keydown", onKeyDown);
@@ -714,10 +782,10 @@ function MapRoot(t0) {
714
782
  t26 = element && /* @__PURE__ */ jsx(Map, {
715
783
  ...props,
716
784
  mapLib: loadMapLib(),
717
- ref: (instance_1) => {
718
- setMap(instance_1);
719
- if (typeof ref === "function") ref(instance_1);
720
- else if (ref) ref.current = instance_1;
785
+ ref: (instance_2) => {
786
+ setMap(instance_2);
787
+ if (typeof ref === "function") ref(instance_2);
788
+ else if (ref) ref.current = instance_2;
721
789
  },
722
790
  mapStyle,
723
791
  initialViewState,
@@ -728,24 +796,28 @@ function MapRoot(t0) {
728
796
  "NavigationControl.ZoomIn": text.zoomIn,
729
797
  "NavigationControl.ZoomOut": text.zoomOut
730
798
  },
731
- onClick: (event_2) => {
732
- const feature = event_2.features?.[0];
733
- const owner = feature && ownerOf(feature.layer.id);
734
- if (feature && owner && feature.id != null) handlers.current[owner]?.onClick?.(String(feature.id), event_2);
735
- onClick?.(event_2);
736
- },
737
- onMouseMove: (event_3) => {
799
+ onClick: (event_3) => {
738
800
  const feature_0 = event_3.features?.[0];
739
- const owner_0 = feature_0 && ownerOf(feature_0.layer.id);
740
- setHover(feature_0 && owner_0 && feature_0.id != null ? {
801
+ const owner = feature_0 && ownerOf(feature_0.layer.id);
802
+ if (feature_0 && owner && feature_0.properties.cluster) zoomToCluster(feature_0, event_3);
803
+ else if (feature_0 && owner && feature_0.id != null) handlers.current[owner]?.onClick?.(String(feature_0.id), event_3);
804
+ onClick?.(event_3);
805
+ },
806
+ onMouseMove: (event_4) => {
807
+ const feature_1 = event_4.features?.[0];
808
+ const owner_0 = feature_1 && ownerOf(feature_1.layer.id);
809
+ const cluster = !!feature_1?.properties.cluster;
810
+ setHover(feature_1 && owner_0 && !cluster && feature_1.id != null ? {
741
811
  source: owner_0,
742
- id: feature_0.id
743
- } : null, event_3);
744
- onMouseMove?.(event_3);
812
+ id: feature_1.id
813
+ } : null, event_4);
814
+ setCursor(feature_1 && owner_0 && (cluster || feature_1.id != null) ? "pointer" : "");
815
+ onMouseMove?.(event_4);
745
816
  },
746
- onMouseOut: (event_4) => {
747
- setHover(null, event_4);
748
- onMouseOut?.(event_4);
817
+ onMouseOut: (event_5) => {
818
+ setHover(null, event_5);
819
+ setCursor("");
820
+ onMouseOut?.(event_5);
749
821
  },
750
822
  children: /* @__PURE__ */ jsxs(MapContext, {
751
823
  value: {
@@ -767,7 +839,7 @@ function MapRoot(t0) {
767
839
  position: controlsPosition || "top-right",
768
840
  expanded,
769
841
  label: expanded ? text.collapse : text.expand,
770
- onToggle: () => setExpanded(_temp9)
842
+ onToggle: () => setExpanded(_temp1)
771
843
  }),
772
844
  /* @__PURE__ */ jsx(AttributionControl, {
773
845
  compact: true,
@@ -824,9 +896,20 @@ function MapRoot(t0) {
824
896
  return t27;
825
897
  }
826
898
  /** The expand button as a MapLibre control, so it stacks with the zoom buttons in the same corner. */
827
- function _temp9(value_0) {
899
+ function _temp1(value_0) {
828
900
  return !value_0;
829
901
  }
902
+ function _temp0(feature, event_1) {
903
+ const instance_1 = event_1.target;
904
+ const source = instance_1.getSource(feature.source);
905
+ const center = feature.geometry.coordinates;
906
+ source?.getClusterExpansionZoom(feature.properties.cluster_id).then((zoom) => instance_1.easeTo({
907
+ center,
908
+ zoom,
909
+ duration: 400
910
+ }, { originalEvent: event_1.originalEvent }), _temp9);
911
+ }
912
+ function _temp9() {}
830
913
  function _temp8(h) {
831
914
  return h ? `${h.source}|${h.id}` : "";
832
915
  }
@@ -850,7 +933,7 @@ function _temp3(t0) {
850
933
  function ExpandControl(t0) {
851
934
  const $ = c(12);
852
935
  const { position, expanded, label, onToggle } = t0;
853
- const [host] = React.useState(_temp0);
936
+ const [host] = React.useState(_temp10);
854
937
  let t1;
855
938
  if ($[0] !== host) {
856
939
  t1 = () => ({
@@ -900,7 +983,7 @@ function ExpandControl(t0) {
900
983
  } else t5 = $[11];
901
984
  return t5;
902
985
  }
903
- function _temp0() {
986
+ function _temp10() {
904
987
  const element = document.createElement("div");
905
988
  element.className = "maplibregl-ctrl maplibregl-ctrl-group";
906
989
  return element;
@@ -950,7 +1033,7 @@ function MapRoutes(t0) {
950
1033
  items,
951
1034
  selectedIds,
952
1035
  layerIds: t5,
953
- coordinates: _temp1,
1036
+ coordinates: _temp11,
954
1037
  minPositions: 2,
955
1038
  onItemClick,
956
1039
  onItemHover
@@ -1184,7 +1267,7 @@ function MapRoutes(t0) {
1184
1267
  const layers = t27;
1185
1268
  let t28;
1186
1269
  if ($[62] !== layers) {
1187
- t28 = layers.map(_temp10);
1270
+ t28 = layers.map(_temp12);
1188
1271
  $[62] = layers;
1189
1272
  $[63] = t28;
1190
1273
  } else t28 = $[63];
@@ -1204,10 +1287,10 @@ function MapRoutes(t0) {
1204
1287
  } else t29 = $[67];
1205
1288
  return t29;
1206
1289
  }
1207
- function _temp10(layer) {
1290
+ function _temp12(layer) {
1208
1291
  return /* @__PURE__ */ jsx(Layer, { ...layer }, layer.id);
1209
1292
  }
1210
- function _temp1(item) {
1293
+ function _temp11(item) {
1211
1294
  return item.coordinates;
1212
1295
  }
1213
1296
  /**
@@ -1246,7 +1329,7 @@ function MapAreas(t0) {
1246
1329
  items,
1247
1330
  selectedIds,
1248
1331
  layerIds: t4,
1249
- coordinates: _temp11,
1332
+ coordinates: _temp13,
1250
1333
  onItemClick,
1251
1334
  onItemHover
1252
1335
  };
@@ -1378,13 +1461,14 @@ function MapAreas(t0) {
1378
1461
  } else t17 = $[37];
1379
1462
  return t17;
1380
1463
  }
1381
- function _temp11(item) {
1464
+ function _temp13(item) {
1382
1465
  return item.geometry.coordinates;
1383
1466
  }
1384
1467
  /**
1385
1468
  * Many simple points (sensors, stops, events) as one circle layer. Items with a `label` get it drawn in
1386
- * the circle by a symbol layer on the same source, so thousands of numbered stops stay fast. For a few
1387
- * dozen styled pins with HTML content, use `Map.Marker` instead.
1469
+ * the circle by a symbol layer on the same source from `labelMinZoom` on, so thousands of numbered stops
1470
+ * stay fast. With `cluster`, dense areas become count bubbles. For a few dozen styled pins with HTML
1471
+ * content, use `Map.Marker` instead.
1388
1472
  *
1389
1473
  * @example
1390
1474
  * <Map.Points items={sensors.map((s) => ({ id: s.id, coordinates: s.position, tone: s.ok ? 'success' : 'danger' }))} />
@@ -1395,46 +1479,72 @@ function _temp11(item) {
1395
1479
  * items={trucks.flatMap((truck, t) =>
1396
1480
  * truck.stops.map((stop, i) => ({ id: stop.id, coordinates: stop.position, colorIndex: t, label: i + 1 })),
1397
1481
  * )}
1482
+ * labelMinZoom={11}
1398
1483
  * />
1484
+ *
1485
+ * @example
1486
+ * // A fleet's stops over two months, merged into count bubbles at low zoom.
1487
+ * <Map.Points items={stops} cluster={{ radius: 40 }} onItemClick={(stop) => setPicked(stop)} />
1399
1488
  */
1400
1489
  function MapPoints(t0) {
1401
- const $ = c(43);
1402
- const { items, selectedIds, onItemClick, onItemHover } = t0;
1490
+ const $ = c(78);
1491
+ const { items, selectedIds, labelMinZoom: t1, cluster: t2, onItemClick, onItemHover } = t0;
1492
+ const labelMinZoom = t1 === void 0 ? 12 : t1;
1493
+ const cluster = t2 === void 0 ? false : t2;
1403
1494
  const sourceId = usePartId("points");
1404
1495
  const circleId = `${sourceId}-circle`;
1405
1496
  const labelId = `${sourceId}-label`;
1406
- let t1;
1407
- if ($[0] !== circleId || $[1] !== labelId) {
1408
- t1 = [circleId, labelId];
1409
- $[0] = circleId;
1410
- $[1] = labelId;
1411
- $[2] = t1;
1412
- } else t1 = $[2];
1413
- let t2;
1414
- if ($[3] !== items || $[4] !== onItemClick || $[5] !== onItemHover || $[6] !== selectedIds || $[7] !== t1) {
1415
- t2 = {
1497
+ const clusterId = `${sourceId}-cluster`;
1498
+ const countId = `${sourceId}-count`;
1499
+ let t3;
1500
+ if ($[0] !== cluster) {
1501
+ t3 = cluster === true ? {} : cluster || {};
1502
+ $[0] = cluster;
1503
+ $[1] = t3;
1504
+ } else t3 = $[1];
1505
+ const { radius: t4, maxZoom: t5 } = t3;
1506
+ const clusterRadius = t4 === void 0 ? 50 : t4;
1507
+ const clusterMaxZoom = t5 === void 0 ? 14 : t5;
1508
+ let t6;
1509
+ if ($[2] !== circleId || $[3] !== cluster || $[4] !== clusterId || $[5] !== labelId) {
1510
+ t6 = cluster ? [
1511
+ circleId,
1512
+ labelId,
1513
+ clusterId
1514
+ ] : [circleId, labelId];
1515
+ $[2] = circleId;
1516
+ $[3] = cluster;
1517
+ $[4] = clusterId;
1518
+ $[5] = labelId;
1519
+ $[6] = t6;
1520
+ } else t6 = $[6];
1521
+ let t7;
1522
+ if ($[7] !== items || $[8] !== onItemClick || $[9] !== onItemHover || $[10] !== selectedIds || $[11] !== t6) {
1523
+ t7 = {
1416
1524
  items,
1417
1525
  selectedIds,
1418
- layerIds: t1,
1419
- coordinates: _temp12,
1526
+ layerIds: t6,
1527
+ coordinates: _temp14,
1420
1528
  onItemClick,
1421
1529
  onItemHover
1422
1530
  };
1423
- $[3] = items;
1424
- $[4] = onItemClick;
1425
- $[5] = onItemHover;
1426
- $[6] = selectedIds;
1427
- $[7] = t1;
1428
- $[8] = t2;
1429
- } else t2 = $[8];
1430
- const { colors, hasSelection, valid } = useDataPart("Map.Points", sourceId, t2);
1531
+ $[7] = items;
1532
+ $[8] = onItemClick;
1533
+ $[9] = onItemHover;
1534
+ $[10] = selectedIds;
1535
+ $[11] = t6;
1536
+ $[12] = t7;
1537
+ } else t7 = $[12];
1538
+ const { colors, hasSelection, valid } = useDataPart("Map.Points", sourceId, t7);
1539
+ let casing;
1431
1540
  let data;
1541
+ let dim;
1432
1542
  let opacity;
1433
- let t3;
1434
- if ($[9] !== colors || $[10] !== hasSelection || $[11] !== items || $[12] !== valid) {
1435
- let t4;
1436
- if ($[16] !== colors || $[17] !== valid) {
1437
- t4 = (item_0, index) => valid.has(item_0) ? [{
1543
+ let t8;
1544
+ if ($[13] !== colors || $[14] !== hasSelection || $[15] !== items || $[16] !== valid) {
1545
+ let t9;
1546
+ if ($[22] !== colors || $[23] !== valid) {
1547
+ t9 = (item_0, index) => valid.has(item_0) ? [{
1438
1548
  type: "Feature",
1439
1549
  properties: {
1440
1550
  id: item_0.id,
@@ -1446,59 +1556,91 @@ function MapPoints(t0) {
1446
1556
  coordinates: item_0.coordinates
1447
1557
  }
1448
1558
  }] : [];
1449
- $[16] = colors;
1450
- $[17] = valid;
1451
- $[18] = t4;
1452
- } else t4 = $[18];
1559
+ $[22] = colors;
1560
+ $[23] = valid;
1561
+ $[24] = t9;
1562
+ } else t9 = $[24];
1453
1563
  data = {
1454
1564
  type: "FeatureCollection",
1455
- features: items.flatMap(t4)
1565
+ features: items.flatMap(t9)
1456
1566
  };
1457
- let t5;
1458
- if ($[19] !== colors || $[20] !== hasSelection) {
1459
- t5 = dimmed(hasSelection, colors.number("--oui-map-dim-opacity", .35));
1460
- $[19] = colors;
1461
- $[20] = hasSelection;
1462
- $[21] = t5;
1463
- } else t5 = $[21];
1464
- opacity = t5;
1465
- t3 = data.features.some(_temp13);
1466
- $[9] = colors;
1467
- $[10] = hasSelection;
1468
- $[11] = items;
1469
- $[12] = valid;
1470
- $[13] = data;
1471
- $[14] = opacity;
1472
- $[15] = t3;
1567
+ let t10;
1568
+ if ($[25] !== colors || $[26] !== hasSelection) {
1569
+ dim = colors.number("--oui-map-dim-opacity", .35);
1570
+ t10 = dimmed(hasSelection, dim);
1571
+ $[25] = colors;
1572
+ $[26] = hasSelection;
1573
+ $[27] = dim;
1574
+ $[28] = t10;
1575
+ } else {
1576
+ dim = $[27];
1577
+ t10 = $[28];
1578
+ }
1579
+ opacity = t10;
1580
+ let t11;
1581
+ if ($[29] !== colors) {
1582
+ t11 = colors.color("var(--oui-map-casing-color)");
1583
+ $[29] = colors;
1584
+ $[30] = t11;
1585
+ } else t11 = $[30];
1586
+ casing = t11;
1587
+ t8 = data.features.some(_temp15);
1588
+ $[13] = colors;
1589
+ $[14] = hasSelection;
1590
+ $[15] = items;
1591
+ $[16] = valid;
1592
+ $[17] = casing;
1593
+ $[18] = data;
1594
+ $[19] = dim;
1595
+ $[20] = opacity;
1596
+ $[21] = t8;
1473
1597
  } else {
1474
- data = $[13];
1475
- opacity = $[14];
1476
- t3 = $[15];
1598
+ casing = $[17];
1599
+ data = $[18];
1600
+ dim = $[19];
1601
+ opacity = $[20];
1602
+ t8 = $[21];
1477
1603
  }
1478
- const hasLabels = t3;
1479
- let t4;
1480
- if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
1481
- t4 = [
1604
+ const hasLabels = t8;
1605
+ let t9;
1606
+ if ($[31] === Symbol.for("react.memo_cache_sentinel")) {
1607
+ t9 = [
1482
1608
  "case",
1483
1609
  ACTIVE,
1484
1610
  2,
1485
1611
  0
1486
1612
  ];
1487
- $[22] = t4;
1488
- } else t4 = $[22];
1489
- let t5;
1490
- if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
1491
- t5 = ["has", "label"];
1492
- $[23] = t5;
1493
- } else t5 = $[23];
1494
- let t6;
1495
- if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
1496
- t6 = [
1613
+ $[31] = t9;
1614
+ } else t9 = $[31];
1615
+ const grow = t9;
1616
+ let t10;
1617
+ let t11;
1618
+ if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
1619
+ t10 = ["zoom"];
1620
+ t11 = [
1621
+ "+",
1622
+ grow,
1623
+ 5
1624
+ ];
1625
+ $[32] = t10;
1626
+ $[33] = t11;
1627
+ } else {
1628
+ t10 = $[32];
1629
+ t11 = $[33];
1630
+ }
1631
+ let t12;
1632
+ if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
1633
+ t12 = ["has", "label"];
1634
+ $[34] = t12;
1635
+ } else t12 = $[34];
1636
+ let t13;
1637
+ if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
1638
+ t13 = [
1497
1639
  "+",
1498
- t4,
1640
+ grow,
1499
1641
  [
1500
1642
  "case",
1501
- t5,
1643
+ t12,
1502
1644
  [
1503
1645
  "step",
1504
1646
  ["length", ["get", "label"]],
@@ -1509,51 +1651,82 @@ function MapPoints(t0) {
1509
1651
  5
1510
1652
  ]
1511
1653
  ];
1512
- $[24] = t6;
1513
- } else t6 = $[24];
1514
- const radius = t6;
1515
- let t7;
1516
- if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
1517
- t7 = ["get", "color"];
1518
- $[25] = t7;
1519
- } else t7 = $[25];
1520
- let t8;
1521
- if ($[26] !== colors) {
1522
- t8 = colors.color("var(--oui-map-casing-color)");
1523
- $[26] = colors;
1524
- $[27] = t8;
1525
- } else t8 = $[27];
1526
- let t9;
1527
- if ($[28] !== opacity || $[29] !== t8) {
1528
- t9 = {
1529
- "circle-color": t7,
1654
+ $[35] = t13;
1655
+ } else t13 = $[35];
1656
+ let t14;
1657
+ if ($[36] !== labelMinZoom) {
1658
+ t14 = [
1659
+ "step",
1660
+ t10,
1661
+ t11,
1662
+ labelMinZoom,
1663
+ t13
1664
+ ];
1665
+ $[36] = labelMinZoom;
1666
+ $[37] = t14;
1667
+ } else t14 = $[37];
1668
+ const radius = t14;
1669
+ const clusterOpacity = hasSelection ? dim : 1;
1670
+ const sourceKey = cluster ? `cluster-${clusterRadius}-${clusterMaxZoom}` : "plain";
1671
+ let t15;
1672
+ if ($[38] !== cluster || $[39] !== clusterMaxZoom || $[40] !== clusterRadius) {
1673
+ t15 = cluster ? {
1674
+ cluster: true,
1675
+ clusterRadius,
1676
+ clusterMaxZoom
1677
+ } : {};
1678
+ $[38] = cluster;
1679
+ $[39] = clusterMaxZoom;
1680
+ $[40] = clusterRadius;
1681
+ $[41] = t15;
1682
+ } else t15 = $[41];
1683
+ const clusterProps = t15;
1684
+ let t16;
1685
+ if ($[42] !== cluster) {
1686
+ t16 = cluster && { filter: ["!", ["has", "point_count"]] };
1687
+ $[42] = cluster;
1688
+ $[43] = t16;
1689
+ } else t16 = $[43];
1690
+ let t17;
1691
+ if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
1692
+ t17 = ["get", "color"];
1693
+ $[44] = t17;
1694
+ } else t17 = $[44];
1695
+ let t18;
1696
+ if ($[45] !== casing || $[46] !== opacity || $[47] !== radius) {
1697
+ t18 = {
1698
+ "circle-color": t17,
1530
1699
  "circle-radius": radius,
1531
- "circle-stroke-color": t8,
1700
+ "circle-stroke-color": casing,
1532
1701
  "circle-stroke-width": 1.5,
1533
1702
  "circle-opacity": opacity,
1534
1703
  "circle-stroke-opacity": opacity
1535
1704
  };
1536
- $[28] = opacity;
1537
- $[29] = t8;
1538
- $[30] = t9;
1539
- } else t9 = $[30];
1540
- let t10;
1541
- if ($[31] !== circleId || $[32] !== t9) {
1542
- t10 = /* @__PURE__ */ jsx(Layer, {
1705
+ $[45] = casing;
1706
+ $[46] = opacity;
1707
+ $[47] = radius;
1708
+ $[48] = t18;
1709
+ } else t18 = $[48];
1710
+ let t19;
1711
+ if ($[49] !== circleId || $[50] !== t16 || $[51] !== t18) {
1712
+ t19 = /* @__PURE__ */ jsx(Layer, {
1543
1713
  id: circleId,
1544
1714
  type: "circle",
1545
- paint: t9
1715
+ ...t16,
1716
+ paint: t18
1546
1717
  });
1547
- $[31] = circleId;
1548
- $[32] = t9;
1549
- $[33] = t10;
1550
- } else t10 = $[33];
1551
- let t11;
1552
- if ($[34] !== hasLabels || $[35] !== labelId || $[36] !== opacity) {
1553
- t11 = hasLabels && /* @__PURE__ */ jsx(Layer, {
1718
+ $[49] = circleId;
1719
+ $[50] = t16;
1720
+ $[51] = t18;
1721
+ $[52] = t19;
1722
+ } else t19 = $[52];
1723
+ let t20;
1724
+ if ($[53] !== hasLabels || $[54] !== labelId || $[55] !== labelMinZoom || $[56] !== opacity) {
1725
+ t20 = hasLabels && /* @__PURE__ */ jsx(Layer, {
1554
1726
  id: labelId,
1555
1727
  type: "symbol",
1556
1728
  filter: ["has", "label"],
1729
+ minzoom: labelMinZoom,
1557
1730
  layout: {
1558
1731
  "text-field": ["get", "label"],
1559
1732
  "text-font": LABEL_FONT,
@@ -1568,32 +1741,99 @@ function MapPoints(t0) {
1568
1741
  "text-opacity": opacity
1569
1742
  }
1570
1743
  });
1571
- $[34] = hasLabels;
1572
- $[35] = labelId;
1573
- $[36] = opacity;
1574
- $[37] = t11;
1575
- } else t11 = $[37];
1576
- let t12;
1577
- if ($[38] !== data || $[39] !== sourceId || $[40] !== t10 || $[41] !== t11) {
1578
- t12 = /* @__PURE__ */ jsxs(Source, {
1744
+ $[53] = hasLabels;
1745
+ $[54] = labelId;
1746
+ $[55] = labelMinZoom;
1747
+ $[56] = opacity;
1748
+ $[57] = t20;
1749
+ } else t20 = $[57];
1750
+ let t21;
1751
+ if ($[58] !== casing || $[59] !== cluster || $[60] !== clusterId || $[61] !== clusterOpacity || $[62] !== colors) {
1752
+ t21 = cluster && /* @__PURE__ */ jsx(Layer, {
1753
+ id: clusterId,
1754
+ type: "circle",
1755
+ filter: ["has", "point_count"],
1756
+ paint: {
1757
+ "circle-color": colors.color("var(--oui-map-cluster-color)"),
1758
+ "circle-radius": [
1759
+ "step",
1760
+ ["get", "point_count"],
1761
+ 12,
1762
+ 10,
1763
+ 15,
1764
+ 100,
1765
+ 19,
1766
+ 1e3,
1767
+ 24
1768
+ ],
1769
+ "circle-stroke-color": casing,
1770
+ "circle-stroke-width": 2,
1771
+ "circle-opacity": clusterOpacity,
1772
+ "circle-stroke-opacity": clusterOpacity
1773
+ }
1774
+ });
1775
+ $[58] = casing;
1776
+ $[59] = cluster;
1777
+ $[60] = clusterId;
1778
+ $[61] = clusterOpacity;
1779
+ $[62] = colors;
1780
+ $[63] = t21;
1781
+ } else t21 = $[63];
1782
+ let t22;
1783
+ if ($[64] !== cluster || $[65] !== clusterOpacity || $[66] !== colors || $[67] !== countId) {
1784
+ t22 = cluster && /* @__PURE__ */ jsx(Layer, {
1785
+ id: countId,
1786
+ type: "symbol",
1787
+ filter: ["has", "point_count"],
1788
+ layout: {
1789
+ "text-field": ["get", "point_count_abbreviated"],
1790
+ "text-font": LABEL_FONT,
1791
+ "text-size": 11,
1792
+ "text-allow-overlap": true,
1793
+ "text-ignore-placement": true
1794
+ },
1795
+ paint: {
1796
+ "text-color": colors.color("var(--oui-map-cluster-text-color)"),
1797
+ "text-opacity": clusterOpacity
1798
+ }
1799
+ });
1800
+ $[64] = cluster;
1801
+ $[65] = clusterOpacity;
1802
+ $[66] = colors;
1803
+ $[67] = countId;
1804
+ $[68] = t22;
1805
+ } else t22 = $[68];
1806
+ let t23;
1807
+ if ($[69] !== clusterProps || $[70] !== data || $[71] !== sourceId || $[72] !== sourceKey || $[73] !== t19 || $[74] !== t20 || $[75] !== t21 || $[76] !== t22) {
1808
+ t23 = /* @__PURE__ */ jsxs(Source, {
1579
1809
  id: sourceId,
1580
1810
  type: "geojson",
1581
1811
  data,
1582
1812
  promoteId: "id",
1583
- children: [t10, t11]
1584
- });
1585
- $[38] = data;
1586
- $[39] = sourceId;
1587
- $[40] = t10;
1588
- $[41] = t11;
1589
- $[42] = t12;
1590
- } else t12 = $[42];
1591
- return t12;
1813
+ ...clusterProps,
1814
+ children: [
1815
+ t19,
1816
+ t20,
1817
+ t21,
1818
+ t22
1819
+ ]
1820
+ }, sourceKey);
1821
+ $[69] = clusterProps;
1822
+ $[70] = data;
1823
+ $[71] = sourceId;
1824
+ $[72] = sourceKey;
1825
+ $[73] = t19;
1826
+ $[74] = t20;
1827
+ $[75] = t21;
1828
+ $[76] = t22;
1829
+ $[77] = t23;
1830
+ } else t23 = $[77];
1831
+ return t23;
1592
1832
  }
1593
- function _temp13(feature) {
1833
+ function _temp15(feature) {
1594
1834
  return "label" in feature.properties;
1595
1835
  }
1596
- function _temp12(item) {
1836
+ function _temp14(item) {
1597
1837
  return item.coordinates;
1598
1838
  }
1599
1839
  /**
@@ -1936,7 +2176,7 @@ function MapLegend(t0) {
1936
2176
  const labels = React.use(MapContext)?.labels ?? defaultLabels;
1937
2177
  let t6;
1938
2178
  if ($[13] !== items) {
1939
- t6 = items.every(_temp14);
2179
+ t6 = items.every(_temp16);
1940
2180
  $[13] = items;
1941
2181
  $[14] = t6;
1942
2182
  } else t6 = $[14];
@@ -1965,7 +2205,7 @@ function MapLegend(t0) {
1965
2205
  t9 = onVisibilityChange && showAllToggle && /* @__PURE__ */ jsx("button", {
1966
2206
  type: "button",
1967
2207
  className: "oui-map-legend__toggle-all",
1968
- onClick: () => onVisibilityChange(items.map(_temp15), !allVisible),
2208
+ onClick: () => onVisibilityChange(items.map(_temp17), !allVisible),
1969
2209
  children: allVisible ? labels.hideAll : labels.showAll
1970
2210
  });
1971
2211
  $[21] = allVisible;
@@ -2064,10 +2304,10 @@ function MapLegend(t0) {
2064
2304
  } else t12 = $[49];
2065
2305
  return t12;
2066
2306
  }
2067
- function _temp15(item_0) {
2307
+ function _temp17(item_0) {
2068
2308
  return item_0.id;
2069
2309
  }
2070
- function _temp14(item) {
2310
+ function _temp16(item) {
2071
2311
  return item.visible !== false;
2072
2312
  }
2073
2313
  /**
@@ -2157,7 +2397,7 @@ function MapBaseLayerSwitch(t0) {
2157
2397
  }
2158
2398
  let t3;
2159
2399
  if ($[23] !== baseLayers) {
2160
- t3 = baseLayers.map(_temp16);
2400
+ t3 = baseLayers.map(_temp18);
2161
2401
  $[23] = baseLayers;
2162
2402
  $[24] = t3;
2163
2403
  } else t3 = $[24];
@@ -2201,7 +2441,7 @@ function MapBaseLayerSwitch(t0) {
2201
2441
  * </Map.Overlay>
2202
2442
  * </Map.Root>
2203
2443
  */
2204
- function _temp16(layer_0) {
2444
+ function _temp18(layer_0) {
2205
2445
  return {
2206
2446
  value: layer_0.id,
2207
2447
  label: layer_0.label