@classic-homes/maps-react 0.5.3 → 0.6.1

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as React26 from 'react';
1
+ import * as React6 from 'react';
2
2
  import { useState, useEffect, useCallback } from 'react';
3
3
  import { clsx } from 'clsx';
4
4
  import { twMerge } from 'tailwind-merge';
@@ -7,7 +7,7 @@ import maplibregl from 'maplibre-gl';
7
7
  import 'maplibre-gl/dist/maplibre-gl.css';
8
8
  import '@classic-homes/maps-core/styles/controls.css';
9
9
  import '@classic-homes/maps-core/styles/marker.css';
10
- import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, DEFAULT_BASEMAP, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, getChangedPaintProps, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, STACK_GAP, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
10
+ import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, DEFAULT_BASEMAP, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, getChangedPaintProps, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, getGridNavigationIndex, STACK_GAP, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
11
11
  export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, DEFAULT_BASEMAP, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createHoverExpression, createInitialLayerStates, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getLayerCategories, getLayerStyleForTheme, getLayersByCategory, getSelectionStyle, groupLayersByCategory, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, resolveLayerSourceUrl, searchLayers, setLayerOpacity, toggleLayerVisibility, validateGeoJSON } from '@classic-homes/maps-core';
12
12
  import * as ReactDOM from 'react-dom';
13
13
  import { panToFitPopup, normalizePadding } from '@classic-homes/maps-core/utils';
@@ -20,7 +20,7 @@ import { Switch } from '@classic-homes/theme-react';
20
20
  function cn(...inputs) {
21
21
  return twMerge(clsx(inputs));
22
22
  }
23
- var MapSkeleton = React26.forwardRef(
23
+ var MapSkeleton = React6.forwardRef(
24
24
  ({ height = 400, className, ...props }, ref) => {
25
25
  const heightStyle = typeof height === "number" ? `${height}px` : height;
26
26
  return /* @__PURE__ */ jsxs(
@@ -74,7 +74,7 @@ var MapSkeleton = React26.forwardRef(
74
74
  }
75
75
  );
76
76
  MapSkeleton.displayName = "MapSkeleton";
77
- var MapError = React26.forwardRef(
77
+ var MapError = React6.forwardRef(
78
78
  ({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
79
79
  const heightStyle = typeof height === "number" ? `${height}px` : height;
80
80
  return /* @__PURE__ */ jsx(
@@ -120,7 +120,7 @@ var MapError = React26.forwardRef(
120
120
  "button",
121
121
  {
122
122
  onClick: onRetry,
123
- className: "mt-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
123
+ className: "mt-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
124
124
  children: "Retry"
125
125
  }
126
126
  )
@@ -130,7 +130,7 @@ var MapError = React26.forwardRef(
130
130
  }
131
131
  );
132
132
  MapError.displayName = "MapError";
133
- var MapEmpty = React26.forwardRef(
133
+ var MapEmpty = React6.forwardRef(
134
134
  ({ message = "No map data to display", height = 400, className, ...props }, ref) => {
135
135
  const heightStyle = typeof height === "number" ? `${height}px` : height;
136
136
  return /* @__PURE__ */ jsx(
@@ -173,7 +173,7 @@ var MapEmpty = React26.forwardRef(
173
173
  }
174
174
  );
175
175
  MapEmpty.displayName = "MapEmpty";
176
- var MapContainer = React26.forwardRef(
176
+ var MapContainer = React6.forwardRef(
177
177
  ({
178
178
  title,
179
179
  description,
@@ -279,9 +279,9 @@ function useReducedMotion() {
279
279
  }, []);
280
280
  return prefersReducedMotion;
281
281
  }
282
- var MapContext = React26.createContext(null);
282
+ var MapContext = React6.createContext(null);
283
283
  function useMap() {
284
- const context = React26.useContext(MapContext);
284
+ const context = React6.useContext(MapContext);
285
285
  if (!context) {
286
286
  throw new Error("useMap must be used within a Map component");
287
287
  }
@@ -291,7 +291,11 @@ function useMapInstance() {
291
291
  const { map, loaded } = useMap();
292
292
  return loaded ? map : null;
293
293
  }
294
- var Map2 = React26.forwardRef(
294
+ function getStyleKey(style) {
295
+ if (!style) return "";
296
+ return typeof style === "string" ? style : JSON.stringify(style);
297
+ }
298
+ var Map2 = React6.forwardRef(
295
299
  ({
296
300
  // Base props
297
301
  title,
@@ -346,30 +350,30 @@ var Map2 = React26.forwardRef(
346
350
  onZoom,
347
351
  onError
348
352
  }, ref) => {
349
- const containerRef = React26.useRef(null);
350
- const mapRef = React26.useRef(null);
351
- const [mapLoaded, setMapLoaded] = React26.useState(false);
352
- const [mapError, setMapError] = React26.useState(null);
353
- const [initAttempt, setInitAttempt] = React26.useState(0);
354
- const retryInit = React26.useCallback(() => {
353
+ const containerRef = React6.useRef(null);
354
+ const mapRef = React6.useRef(null);
355
+ const [mapLoaded, setMapLoaded] = React6.useState(false);
356
+ const [mapError, setMapError] = React6.useState(null);
357
+ const [initAttempt, setInitAttempt] = React6.useState(0);
358
+ const retryInit = React6.useCallback(() => {
355
359
  setMapError(null);
356
360
  setInitAttempt((attempt) => attempt + 1);
357
361
  }, []);
358
- const [styleVersion, setStyleVersion] = React26.useState(0);
359
- const styleVersionRef = React26.useRef(0);
360
- const bumpStyleVersion = React26.useCallback(() => {
362
+ const [styleVersion, setStyleVersion] = React6.useState(0);
363
+ const styleVersionRef = React6.useRef(0);
364
+ const bumpStyleVersion = React6.useCallback(() => {
361
365
  styleVersionRef.current += 1;
362
366
  setStyleVersion(styleVersionRef.current);
363
367
  }, []);
364
- const activeStyleOverrideRef = React26.useRef(
368
+ const activeStyleOverrideRef = React6.useRef(
365
369
  null
366
370
  );
367
- const positioningCoordinatorRef = React26.useRef(null);
371
+ const positioningCoordinatorRef = React6.useRef(null);
368
372
  if (!positioningCoordinatorRef.current) {
369
373
  positioningCoordinatorRef.current = createPositioningCoordinator();
370
374
  }
371
375
  const positioningCoordinator = positioningCoordinatorRef.current;
372
- const setMapStyle = React26.useCallback(
376
+ const setMapStyle = React6.useCallback(
373
377
  (style) => {
374
378
  activeStyleOverrideRef.current = style;
375
379
  const map = mapRef.current;
@@ -384,16 +388,20 @@ var Map2 = React26.forwardRef(
384
388
  );
385
389
  const prefersReducedMotion = useReducedMotion();
386
390
  const { style: themeStyle } = useMapTheme(themePref);
387
- const onLoadRef = React26.useRef(onLoad);
391
+ const onLoadRef = React6.useRef(onLoad);
388
392
  onLoadRef.current = onLoad;
389
- const onErrorRef = React26.useRef(onError);
393
+ const onErrorRef = React6.useRef(onError);
390
394
  onErrorRef.current = onError;
391
395
  const mapStyle = customStyle || themeStyle;
396
+ const mapStyleKey = React6.useMemo(() => getStyleKey(mapStyle), [mapStyle]);
397
+ const customStyleKey = React6.useMemo(() => getStyleKey(customStyle), [customStyle]);
398
+ const mapStyleRef = React6.useRef(mapStyle);
399
+ mapStyleRef.current = mapStyle;
392
400
  const accessibleDescription = description || generateMapDescription(title, {
393
401
  center,
394
402
  zoom
395
403
  });
396
- React26.useEffect(() => {
404
+ React6.useEffect(() => {
397
405
  if (!containerRef.current || !positioningCoordinator) return;
398
406
  const updateDimensions = () => {
399
407
  if (!containerRef.current) return;
@@ -409,12 +417,12 @@ var Map2 = React26.forwardRef(
409
417
  resizeObserver.disconnect();
410
418
  };
411
419
  }, [positioningCoordinator]);
412
- React26.useEffect(() => {
420
+ React6.useEffect(() => {
413
421
  return () => {
414
422
  positioningCoordinator.destroy();
415
423
  };
416
424
  }, [positioningCoordinator]);
417
- React26.useEffect(() => {
425
+ React6.useEffect(() => {
418
426
  if (!containerRef.current || mapRef.current) return;
419
427
  try {
420
428
  const map = new maplibregl.Map({
@@ -573,7 +581,7 @@ var Map2 = React26.forwardRef(
573
581
  });
574
582
  }
575
583
  }, [initAttempt]);
576
- React26.useEffect(() => {
584
+ React6.useEffect(() => {
577
585
  const map = mapRef.current;
578
586
  if (!map || !mapLoaded) return;
579
587
  map.on("style.load", bumpStyleVersion);
@@ -581,22 +589,22 @@ var Map2 = React26.forwardRef(
581
589
  map.off("style.load", bumpStyleVersion);
582
590
  };
583
591
  }, [mapLoaded, bumpStyleVersion]);
584
- const styleInitialized = React26.useRef(false);
585
- React26.useEffect(() => {
592
+ const styleInitialized = React6.useRef(false);
593
+ React6.useEffect(() => {
586
594
  if (!mapRef.current || !mapLoaded) return;
587
595
  if (!styleInitialized.current) {
588
596
  styleInitialized.current = true;
589
597
  return;
590
598
  }
591
599
  if (activeStyleOverrideRef.current) return;
592
- mapRef.current.setStyle(mapStyle);
593
- }, [mapStyle, mapLoaded]);
594
- React26.useEffect(() => {
595
- if (customStyle) {
600
+ mapRef.current.setStyle(mapStyleRef.current);
601
+ }, [mapStyleKey, mapLoaded]);
602
+ React6.useEffect(() => {
603
+ if (customStyleKey) {
596
604
  activeStyleOverrideRef.current = null;
597
605
  }
598
- }, [customStyle]);
599
- React26.useEffect(() => {
606
+ }, [customStyleKey]);
607
+ React6.useEffect(() => {
600
608
  const map = mapRef.current;
601
609
  if (!map || !mapLoaded) return;
602
610
  const createEventParams = (e) => ({
@@ -695,7 +703,7 @@ var Map2 = React26.forwardRef(
695
703
  onZoom
696
704
  ]);
697
705
  const combinedError = error || mapError;
698
- const contextValue = React26.useMemo(
706
+ const contextValue = React6.useMemo(
699
707
  () => ({
700
708
  map: mapRef.current,
701
709
  loaded: mapLoaded,
@@ -727,6 +735,53 @@ var Map2 = React26.forwardRef(
727
735
  }
728
736
  );
729
737
  Map2.displayName = "Map";
738
+ function createSourceRegistry() {
739
+ const versions = /* @__PURE__ */ new Map();
740
+ const stacking = /* @__PURE__ */ new Map();
741
+ const listeners = /* @__PURE__ */ new Set();
742
+ let counter = 0;
743
+ const notify = () => {
744
+ for (const listener of [...listeners]) listener();
745
+ };
746
+ return {
747
+ version: (id) => versions.get(id) ?? 0,
748
+ added(id) {
749
+ versions.set(id, ++counter);
750
+ notify();
751
+ },
752
+ removed(id, layersAbove) {
753
+ stacking.set(id, layersAbove ?? /* @__PURE__ */ new Map());
754
+ if (versions.delete(id)) notify();
755
+ },
756
+ layersAbove: (sourceId, layerId) => stacking.get(sourceId)?.get(layerId) ?? [],
757
+ subscribe(listener) {
758
+ listeners.add(listener);
759
+ return () => {
760
+ listeners.delete(listener);
761
+ };
762
+ }
763
+ };
764
+ }
765
+ var registries = /* @__PURE__ */ new WeakMap();
766
+ function getSourceRegistry(map) {
767
+ let registry = registries.get(map);
768
+ if (!registry) {
769
+ registry = createSourceRegistry();
770
+ registries.set(map, registry);
771
+ }
772
+ return registry;
773
+ }
774
+ var noopSubscribe = () => () => {
775
+ };
776
+ var zero = () => 0;
777
+ function useSourceVersion(map, sourceId) {
778
+ const registry = map ? getSourceRegistry(map) : null;
779
+ const getSnapshot = React6.useCallback(
780
+ () => registry ? registry.version(sourceId) : 0,
781
+ [registry, sourceId]
782
+ );
783
+ return React6.useSyncExternalStore(registry?.subscribe ?? noopSubscribe, getSnapshot, zero);
784
+ }
730
785
  var Source = ({
731
786
  id,
732
787
  type,
@@ -747,10 +802,9 @@ var Source = ({
747
802
  children
748
803
  }) => {
749
804
  const { map, loaded, styleVersion } = useMap();
750
- const initialFitDone = React26.useRef(false);
751
- const lastStyleVersionRef = React26.useRef(styleVersion);
752
- const appliedDataRef = React26.useRef(void 0);
753
- const fitBoundsParamsRef = React26.useRef({
805
+ const initialFitDone = React6.useRef(false);
806
+ const appliedDataRef = React6.useRef(void 0);
807
+ const fitBoundsParamsRef = React6.useRef({
754
808
  shouldFitBounds,
755
809
  data,
756
810
  fitBoundsPadding,
@@ -766,7 +820,7 @@ var Source = ({
766
820
  fitBoundsAnimate,
767
821
  type
768
822
  };
769
- const performFitBounds = React26.useCallback(
823
+ const performFitBounds = React6.useCallback(
770
824
  (cancelledRef) => {
771
825
  const params = fitBoundsParamsRef.current;
772
826
  if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
@@ -810,12 +864,8 @@ var Source = ({
810
864
  },
811
865
  [map]
812
866
  );
813
- React26.useEffect(() => {
867
+ React6.useEffect(() => {
814
868
  if (!map || !loaded) return;
815
- if (styleVersion !== lastStyleVersionRef.current) {
816
- lastStyleVersionRef.current = styleVersion;
817
- initialFitDone.current = false;
818
- }
819
869
  if (map.getSource(id)) {
820
870
  return;
821
871
  }
@@ -904,6 +954,8 @@ var Source = ({
904
954
  map.once("idle", handleIdle);
905
955
  map.addSource(id, sourceConfig);
906
956
  appliedDataRef.current = type === "geojson" ? data : void 0;
957
+ const registry = getSourceRegistry(map);
958
+ registry.added(id);
907
959
  const source = map.getSource(id);
908
960
  if (source && map.isSourceLoaded(id)) {
909
961
  map.off("sourcedata", handleSourceData);
@@ -922,11 +974,14 @@ var Source = ({
922
974
  return () => {
923
975
  cleanupListeners();
924
976
  if (map) {
977
+ const layersAbove = /* @__PURE__ */ new Map();
925
978
  try {
926
979
  const style = map.getStyle();
927
980
  if (style?.layers) {
928
- style.layers.forEach((layer) => {
981
+ const ids = style.layers.map((layer) => layer.id);
982
+ style.layers.forEach((layer, index) => {
929
983
  if ("source" in layer && layer.source === id) {
984
+ layersAbove.set(layer.id, ids.slice(index + 1));
930
985
  if (map.getLayer(layer.id)) {
931
986
  map.removeLayer(layer.id);
932
987
  }
@@ -938,6 +993,7 @@ var Source = ({
938
993
  }
939
994
  } catch {
940
995
  }
996
+ registry.removed(id, layersAbove);
941
997
  }
942
998
  };
943
999
  } catch (err) {
@@ -962,7 +1018,7 @@ var Source = ({
962
1018
  styleVersion
963
1019
  // re-add source after basemap style changes
964
1020
  ]);
965
- React26.useEffect(() => {
1021
+ React6.useEffect(() => {
966
1022
  if (!map || !loaded || type !== "geojson") return;
967
1023
  const source = map.getSource(id);
968
1024
  if (!source) return;
@@ -996,7 +1052,7 @@ var Source = ({
996
1052
  return /* @__PURE__ */ jsx(Fragment, { children });
997
1053
  };
998
1054
  Source.displayName = "Source";
999
- var Marker = React26.forwardRef(
1055
+ var Marker = React6.forwardRef(
1000
1056
  ({
1001
1057
  id,
1002
1058
  coordinates,
@@ -1012,30 +1068,30 @@ var Marker = React26.forwardRef(
1012
1068
  children
1013
1069
  }, ref) => {
1014
1070
  const { map, loaded } = useMap();
1015
- const markerRef = React26.useRef(null);
1016
- const elementRef = React26.useRef(null);
1017
- const originalLngLatRef = React26.useRef();
1018
- const clickHandlerRef = React26.useRef(null);
1019
- const dragStartHandlerRef = React26.useRef(null);
1020
- const dragHandlerRef = React26.useRef(null);
1021
- const dragEndHandlerRef = React26.useRef(null);
1022
- const [mounted, setMounted] = React26.useState(false);
1023
- const onClickRef = React26.useRef(onClick);
1071
+ const markerRef = React6.useRef(null);
1072
+ const elementRef = React6.useRef(null);
1073
+ const originalLngLatRef = React6.useRef();
1074
+ const clickHandlerRef = React6.useRef(null);
1075
+ const dragStartHandlerRef = React6.useRef(null);
1076
+ const dragHandlerRef = React6.useRef(null);
1077
+ const dragEndHandlerRef = React6.useRef(null);
1078
+ const [mounted, setMounted] = React6.useState(false);
1079
+ const onClickRef = React6.useRef(onClick);
1024
1080
  onClickRef.current = onClick;
1025
- const onDragRef = React26.useRef(onDrag);
1081
+ const onDragRef = React6.useRef(onDrag);
1026
1082
  onDragRef.current = onDrag;
1027
- const onDragEndRef = React26.useRef(onDragEnd);
1083
+ const onDragEndRef = React6.useRef(onDragEnd);
1028
1084
  onDragEndRef.current = onDragEnd;
1029
- React26.useEffect(() => {
1085
+ React6.useEffect(() => {
1030
1086
  setMounted(true);
1031
1087
  return () => setMounted(false);
1032
1088
  }, []);
1033
- React26.useEffect(() => {
1089
+ React6.useEffect(() => {
1034
1090
  if (children && !elementRef.current) {
1035
1091
  elementRef.current = document.createElement("div");
1036
1092
  }
1037
1093
  }, [children]);
1038
- React26.useEffect(() => {
1094
+ React6.useEffect(() => {
1039
1095
  if (!map || !loaded || !mounted) return;
1040
1096
  if (markerRef.current) return;
1041
1097
  const markerOptions = {
@@ -1139,12 +1195,12 @@ var Marker = React26.forwardRef(
1139
1195
  }
1140
1196
  };
1141
1197
  }, [map, loaded, mounted]);
1142
- React26.useEffect(() => {
1198
+ React6.useEffect(() => {
1143
1199
  if (markerRef.current) {
1144
1200
  markerRef.current.setLngLat(coordinates);
1145
1201
  }
1146
1202
  }, [coordinates]);
1147
- React26.useEffect(() => {
1203
+ React6.useEffect(() => {
1148
1204
  const marker = markerRef.current;
1149
1205
  if (!marker) return;
1150
1206
  marker.setDraggable(draggable);
@@ -1192,12 +1248,12 @@ var Marker = React26.forwardRef(
1192
1248
  marker.on("dragend", handleDragEnd);
1193
1249
  }
1194
1250
  }, [draggable, id]);
1195
- React26.useEffect(() => {
1251
+ React6.useEffect(() => {
1196
1252
  if (markerRef.current && rotation !== void 0) {
1197
1253
  markerRef.current.setRotation(rotation);
1198
1254
  }
1199
1255
  }, [rotation]);
1200
- React26.useEffect(() => {
1256
+ React6.useEffect(() => {
1201
1257
  if (markerRef.current && offset) {
1202
1258
  markerRef.current.setOffset(offset);
1203
1259
  }
@@ -1210,13 +1266,13 @@ var Marker = React26.forwardRef(
1210
1266
  );
1211
1267
  Marker.displayName = "Marker";
1212
1268
  function useStructuralValue(next) {
1213
- const ref = React26.useRef(next);
1269
+ const ref = React6.useRef(next);
1214
1270
  if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1215
1271
  ref.current = next;
1216
1272
  }
1217
1273
  return ref.current;
1218
1274
  }
1219
- var Popup = React26.forwardRef(
1275
+ var Popup = React6.forwardRef(
1220
1276
  ({
1221
1277
  coordinates: coordinatesProp,
1222
1278
  closeButton = true,
@@ -1237,26 +1293,26 @@ var Popup = React26.forwardRef(
1237
1293
  const coordinates = useStructuralValue(coordinatesProp);
1238
1294
  const offset = useStructuralValue(offsetProp);
1239
1295
  const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1240
- const popupRef = React26.useRef(null);
1241
- const onOpenRef = React26.useRef(onOpen);
1296
+ const popupRef = React6.useRef(null);
1297
+ const onOpenRef = React6.useRef(onOpen);
1242
1298
  onOpenRef.current = onOpen;
1243
- const onCloseRef = React26.useRef(onClose);
1299
+ const onCloseRef = React6.useRef(onClose);
1244
1300
  onCloseRef.current = onClose;
1245
- const coordinatesRef = React26.useRef(coordinates);
1301
+ const coordinatesRef = React6.useRef(coordinates);
1246
1302
  coordinatesRef.current = coordinates;
1247
- const containerRef = React26.useRef(null);
1303
+ const containerRef = React6.useRef(null);
1248
1304
  if (!containerRef.current && typeof document !== "undefined") {
1249
1305
  containerRef.current = document.createElement("div");
1250
1306
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1251
1307
  }
1252
- const [contentReady, setContentReady] = React26.useState(false);
1253
- const [popupVersion, setPopupVersion] = React26.useState(0);
1254
- const contentCallbackRef = React26.useCallback((node) => {
1308
+ const [contentReady, setContentReady] = React6.useState(false);
1309
+ const [popupVersion, setPopupVersion] = React6.useState(0);
1310
+ const contentCallbackRef = React6.useCallback((node) => {
1255
1311
  if (node && containerRef.current) {
1256
1312
  setContentReady(true);
1257
1313
  }
1258
1314
  }, []);
1259
- React26.useEffect(() => {
1315
+ React6.useEffect(() => {
1260
1316
  if (!map || !loaded || !containerRef.current) return;
1261
1317
  const popup = new maplibregl.Popup({
1262
1318
  closeButton,
@@ -1297,7 +1353,7 @@ var Popup = React26.forwardRef(
1297
1353
  maxWidth,
1298
1354
  focusAfterOpen
1299
1355
  ]);
1300
- React26.useEffect(() => {
1356
+ React6.useEffect(() => {
1301
1357
  if (!popupRef.current || !ref) return;
1302
1358
  if (typeof ref === "function") {
1303
1359
  ref(popupRef.current);
@@ -1305,16 +1361,17 @@ var Popup = React26.forwardRef(
1305
1361
  ref.current = popupRef.current;
1306
1362
  }
1307
1363
  }, [ref, popupVersion]);
1308
- React26.useEffect(() => {
1364
+ React6.useEffect(() => {
1309
1365
  if (popupRef.current) {
1310
1366
  popupRef.current.setLngLat(coordinates);
1311
1367
  }
1312
1368
  }, [coordinates]);
1313
- React26.useEffect(() => {
1369
+ React6.useEffect(() => {
1314
1370
  if (!map || !popupRef.current || !contentReady) return;
1315
1371
  let rafHandle;
1316
1372
  if (open) {
1317
- popupRef.current.setLngLat(coordinates).addTo(map);
1373
+ popupRef.current.setLngLat(coordinates);
1374
+ if (!popupRef.current.isOpen()) popupRef.current.addTo(map);
1318
1375
  if (autoPan) {
1319
1376
  rafHandle = requestAnimationFrame(() => {
1320
1377
  if (popupRef.current && map) {
@@ -1339,7 +1396,7 @@ var Popup = React26.forwardRef(
1339
1396
  }
1340
1397
  );
1341
1398
  Popup.displayName = "Popup";
1342
- var PopupCard = React26.forwardRef(
1399
+ var PopupCard = React6.forwardRef(
1343
1400
  ({ className, children, ...props }, ref) => {
1344
1401
  return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
1345
1402
  }
@@ -1359,7 +1416,7 @@ var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0
1359
1416
  badgeVariant: "secondary"
1360
1417
  }
1361
1418
  });
1362
- var PopupHeader = React26.forwardRef(
1419
+ var PopupHeader = React6.forwardRef(
1363
1420
  ({ className, title, badge, badgeVariant, ...props }, ref) => {
1364
1421
  return /* @__PURE__ */ jsxs(
1365
1422
  "div",
@@ -1379,13 +1436,13 @@ var PopupHeader = React26.forwardRef(
1379
1436
  }
1380
1437
  );
1381
1438
  PopupHeader.displayName = "PopupHeader";
1382
- var PopupContent = React26.forwardRef(
1439
+ var PopupContent = React6.forwardRef(
1383
1440
  ({ className, children, ...props }, ref) => {
1384
1441
  return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
1385
1442
  }
1386
1443
  );
1387
1444
  PopupContent.displayName = "PopupContent";
1388
- var PopupFooter = React26.forwardRef(
1445
+ var PopupFooter = React6.forwardRef(
1389
1446
  ({ className, children, ...props }, ref) => {
1390
1447
  return /* @__PURE__ */ jsx(
1391
1448
  "div",
@@ -1402,6 +1459,11 @@ var PopupFooter = React26.forwardRef(
1402
1459
  }
1403
1460
  );
1404
1461
  PopupFooter.displayName = "PopupFooter";
1462
+ function withoutVisibility(layout) {
1463
+ const next = { ...layout ?? {} };
1464
+ delete next.visibility;
1465
+ return next;
1466
+ }
1405
1467
  function useLayer({
1406
1468
  id,
1407
1469
  source,
@@ -1420,91 +1482,115 @@ function useLayer({
1420
1482
  hoverThrottleMs = 0
1421
1483
  }) {
1422
1484
  const { map, loaded, styleVersion } = useMap();
1423
- const [layerAdded, setLayerAdded] = React26.useState(false);
1424
- const hoveredFeatureId = React26.useRef(null);
1425
- const lastHoverCallTime = React26.useRef(0);
1426
- const lastMousePosition = React26.useRef(null);
1427
- React26.useEffect(() => {
1485
+ const sourceVersion = useSourceVersion(map, source);
1486
+ const [layerAdded, setLayerAdded] = React6.useState(false);
1487
+ const hoveredFeatureId = React6.useRef(null);
1488
+ const lastHoverCallTime = React6.useRef(0);
1489
+ const lastMousePosition = React6.useRef(null);
1490
+ const lastAppliedPaintRef = React6.useRef(void 0);
1491
+ const lastAppliedLayoutRef = React6.useRef(void 0);
1492
+ const latestRef = React6.useRef({ visible, minZoom, maxZoom, filter, paint, layout });
1493
+ latestRef.current = { visible, minZoom, maxZoom, filter, paint, layout };
1494
+ const restoreLayerRef = React6.useRef(null);
1495
+ React6.useEffect(() => {
1428
1496
  hoveredFeatureId.current = null;
1429
1497
  }, [styleVersion]);
1430
- React26.useEffect(() => {
1498
+ React6.useEffect(() => {
1431
1499
  if (!map || !loaded) return;
1432
- if (!map.getSource(source)) {
1433
- let timeoutId = null;
1434
- const checkSource = () => {
1435
- if (map.getSource(source)) {
1436
- if (timeoutId) clearTimeout(timeoutId);
1437
- addLayer();
1438
- map.off("sourcedata", checkSource);
1439
- }
1440
- };
1441
- timeoutId = setTimeout(() => {
1442
- if (!map.getSource(source)) {
1443
- console.warn(
1444
- `[maps-react] Layer "${id}" is waiting for source "${source}" which has not been added after 5 seconds. Ensure the Source component with id="${source}" is rendered before or alongside this layer.`
1445
- );
1446
- }
1447
- }, 5e3);
1448
- map.on("sourcedata", checkSource);
1449
- return () => {
1450
- if (timeoutId) clearTimeout(timeoutId);
1451
- map.off("sourcedata", checkSource);
1452
- };
1500
+ let added = false;
1501
+ let timeoutId = null;
1502
+ const stopWaiting = () => {
1503
+ if (timeoutId) clearTimeout(timeoutId);
1504
+ timeoutId = null;
1505
+ map.off("sourcedata", checkSource);
1506
+ };
1507
+ function checkSource() {
1508
+ if (map.getSource(source)) {
1509
+ stopWaiting();
1510
+ addLayer();
1511
+ }
1453
1512
  }
1454
- addLayer();
1455
- function addLayer() {
1513
+ function addLayer(insertBefore = beforeId) {
1456
1514
  if (map.getLayer(id)) {
1515
+ added = true;
1457
1516
  setLayerAdded(true);
1458
1517
  return;
1459
1518
  }
1519
+ const { visible: visible2, minZoom: minZoom2, maxZoom: maxZoom2, filter: filter2, paint: paint2, layout: layout2 } = latestRef.current;
1460
1520
  try {
1461
1521
  const layerConfig = {
1462
1522
  id,
1463
1523
  type,
1464
1524
  source,
1465
- paint,
1525
+ paint: paint2,
1466
1526
  layout: {
1467
- visibility: visible ? "visible" : "none",
1468
- ...layout
1527
+ visibility: visible2 ? "visible" : "none",
1528
+ ...layout2
1469
1529
  }
1470
1530
  };
1471
1531
  if (sourceLayer) {
1472
1532
  layerConfig["source-layer"] = sourceLayer;
1473
1533
  }
1474
- if (minZoom !== void 0) {
1475
- layerConfig.minzoom = minZoom;
1534
+ if (minZoom2 !== void 0) {
1535
+ layerConfig.minzoom = minZoom2;
1476
1536
  }
1477
- if (maxZoom !== void 0) {
1478
- layerConfig.maxzoom = maxZoom;
1537
+ if (maxZoom2 !== void 0) {
1538
+ layerConfig.maxzoom = maxZoom2;
1479
1539
  }
1480
- if (filter) {
1481
- layerConfig.filter = filter;
1540
+ if (filter2) {
1541
+ layerConfig.filter = filter2;
1482
1542
  }
1483
- map.addLayer(layerConfig, beforeId);
1543
+ map.addLayer(layerConfig, insertBefore);
1544
+ added = true;
1545
+ lastAppliedPaintRef.current = { ...paint2 };
1546
+ lastAppliedLayoutRef.current = withoutVisibility(layout2);
1484
1547
  setLayerAdded(true);
1485
1548
  } catch (err) {
1486
1549
  console.error(`[maps-react] Failed to add layer "${id}":`, err);
1487
1550
  }
1488
1551
  }
1552
+ restoreLayerRef.current = () => {
1553
+ if (map.getLayer(id) || !map.getSource(source)) return;
1554
+ hoveredFeatureId.current = null;
1555
+ stopWaiting();
1556
+ const above = beforeId ? void 0 : getSourceRegistry(map).layersAbove(source, id).find((layerId) => map.getLayer(layerId));
1557
+ addLayer(beforeId ?? above);
1558
+ };
1559
+ if (map.getSource(source)) {
1560
+ addLayer();
1561
+ } else {
1562
+ timeoutId = setTimeout(() => {
1563
+ if (!map.getSource(source)) {
1564
+ console.warn(
1565
+ `[maps-react] Layer "${id}" is waiting for source "${source}" which has not been added after 5 seconds. Ensure the Source component with id="${source}" is rendered before or alongside this layer.`
1566
+ );
1567
+ }
1568
+ }, 5e3);
1569
+ map.on("sourcedata", checkSource);
1570
+ }
1489
1571
  return () => {
1490
- if (map) {
1572
+ restoreLayerRef.current = null;
1573
+ stopWaiting();
1574
+ if (added) {
1491
1575
  try {
1492
1576
  if (map.getLayer(id)) {
1493
1577
  map.removeLayer(id);
1494
1578
  }
1495
1579
  } catch {
1496
1580
  }
1497
- setLayerAdded(false);
1498
1581
  }
1582
+ setLayerAdded(false);
1499
1583
  };
1500
1584
  }, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
1501
- React26.useEffect(() => {
1585
+ React6.useEffect(() => {
1586
+ if (sourceVersion) restoreLayerRef.current?.();
1587
+ }, [sourceVersion]);
1588
+ React6.useEffect(() => {
1502
1589
  if (!map || !layerAdded) return;
1503
1590
  if (!map.getLayer(id)) return;
1504
1591
  map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1505
1592
  }, [map, id, visible, layerAdded]);
1506
- const lastAppliedPaintRef = React26.useRef(void 0);
1507
- React26.useEffect(() => {
1593
+ React6.useEffect(() => {
1508
1594
  if (!map || !layerAdded) return;
1509
1595
  if (!map.getLayer(id)) return;
1510
1596
  const diff = getChangedPaintProps(lastAppliedPaintRef.current, paint);
@@ -1520,12 +1606,10 @@ function useLayer({
1520
1606
  } catch {
1521
1607
  }
1522
1608
  }, [map, id, paint, layerAdded]);
1523
- const lastAppliedLayoutRef = React26.useRef(void 0);
1524
- React26.useEffect(() => {
1609
+ React6.useEffect(() => {
1525
1610
  if (!map || !layerAdded) return;
1526
1611
  if (!map.getLayer(id)) return;
1527
- const next = { ...layout };
1528
- delete next.visibility;
1612
+ const next = withoutVisibility(layout);
1529
1613
  const diff = getChangedPaintProps(lastAppliedLayoutRef.current, next);
1530
1614
  if (!diff.hasChanges) return;
1531
1615
  try {
@@ -1539,17 +1623,17 @@ function useLayer({
1539
1623
  } catch {
1540
1624
  }
1541
1625
  }, [map, id, layout, layerAdded]);
1542
- React26.useEffect(() => {
1626
+ React6.useEffect(() => {
1543
1627
  if (!map || !layerAdded) return;
1544
1628
  if (!map.getLayer(id)) return;
1545
1629
  map.setLayerZoomRange(id, minZoom ?? 0, maxZoom ?? 24);
1546
1630
  }, [map, id, minZoom, maxZoom, layerAdded]);
1547
- React26.useEffect(() => {
1631
+ React6.useEffect(() => {
1548
1632
  if (!map || !layerAdded) return;
1549
1633
  if (!map.getLayer(id)) return;
1550
1634
  map.setFilter(id, filter ?? null);
1551
1635
  }, [map, id, filter, layerAdded]);
1552
- React26.useEffect(() => {
1636
+ React6.useEffect(() => {
1553
1637
  if (!map || !layerAdded) return;
1554
1638
  const createFeatureParams = (e) => {
1555
1639
  const feature = e.features?.[0];
@@ -1701,7 +1785,7 @@ var FillLayer = ({
1701
1785
  fillTranslate,
1702
1786
  fillAntialias
1703
1787
  }) => {
1704
- const paint = React26.useMemo(() => {
1788
+ const paint = React6.useMemo(() => {
1705
1789
  const p = {};
1706
1790
  if (fillColor !== void 0) p["fill-color"] = fillColor;
1707
1791
  if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
@@ -1722,7 +1806,7 @@ var FillLayer = ({
1722
1806
  fillAntialias,
1723
1807
  opacity
1724
1808
  ]);
1725
- const layout = React26.useMemo(() => ({}), []);
1809
+ const layout = React6.useMemo(() => ({}), []);
1726
1810
  useLayer({
1727
1811
  id,
1728
1812
  source,
@@ -1766,7 +1850,7 @@ var LineLayer = ({
1766
1850
  lineOffset,
1767
1851
  lineGradient
1768
1852
  }) => {
1769
- const paint = React26.useMemo(() => {
1853
+ const paint = React6.useMemo(() => {
1770
1854
  const p = {};
1771
1855
  if (lineColor !== void 0) p["line-color"] = lineColor;
1772
1856
  if (lineWidth !== void 0) p["line-width"] = lineWidth;
@@ -1791,7 +1875,7 @@ var LineLayer = ({
1791
1875
  lineGradient,
1792
1876
  opacity
1793
1877
  ]);
1794
- const layout = React26.useMemo(() => {
1878
+ const layout = React6.useMemo(() => {
1795
1879
  const l = {};
1796
1880
  if (lineCap !== void 0) l["line-cap"] = lineCap;
1797
1881
  if (lineJoin !== void 0) l["line-join"] = lineJoin;
@@ -1840,7 +1924,7 @@ var CircleLayer = ({
1840
1924
  circlePitchScale,
1841
1925
  circleTranslate
1842
1926
  }) => {
1843
- const paint = React26.useMemo(() => {
1927
+ const paint = React6.useMemo(() => {
1844
1928
  const p = {};
1845
1929
  if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1846
1930
  if (circleColor !== void 0) p["circle-color"] = circleColor;
@@ -1869,7 +1953,7 @@ var CircleLayer = ({
1869
1953
  circleTranslate,
1870
1954
  opacity
1871
1955
  ]);
1872
- const layout = React26.useMemo(() => ({}), []);
1956
+ const layout = React6.useMemo(() => ({}), []);
1873
1957
  useLayer({
1874
1958
  id,
1875
1959
  source,
@@ -1929,7 +2013,7 @@ var SymbolLayer = ({
1929
2013
  symbolSpacing,
1930
2014
  symbolSortKey
1931
2015
  }) => {
1932
- const paint = React26.useMemo(() => {
2016
+ const paint = React6.useMemo(() => {
1933
2017
  const p = {};
1934
2018
  if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1935
2019
  if (iconColor !== void 0) p["icon-color"] = iconColor;
@@ -1950,7 +2034,7 @@ var SymbolLayer = ({
1950
2034
  textHaloColor,
1951
2035
  textHaloWidth
1952
2036
  ]);
1953
- const layout = React26.useMemo(() => {
2037
+ const layout = React6.useMemo(() => {
1954
2038
  const l = {};
1955
2039
  if (iconImage !== void 0) l["icon-image"] = iconImage;
1956
2040
  if (iconSize !== void 0) l["icon-size"] = iconSize;
@@ -2031,7 +2115,7 @@ var FillExtrusionLayer = ({
2031
2115
  fillExtrusionTranslate,
2032
2116
  fillExtrusionVerticalGradient
2033
2117
  }) => {
2034
- const paint = React26.useMemo(() => {
2118
+ const paint = React6.useMemo(() => {
2035
2119
  const p = {};
2036
2120
  if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
2037
2121
  if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
@@ -2057,7 +2141,7 @@ var FillExtrusionLayer = ({
2057
2141
  fillExtrusionVerticalGradient,
2058
2142
  opacity
2059
2143
  ]);
2060
- const layout = React26.useMemo(() => ({}), []);
2144
+ const layout = React6.useMemo(() => ({}), []);
2061
2145
  useLayer({
2062
2146
  id,
2063
2147
  source,
@@ -2096,7 +2180,7 @@ var HeatmapLayer = ({
2096
2180
  heatmapRadius,
2097
2181
  heatmapOpacity
2098
2182
  }) => {
2099
- const paint = React26.useMemo(() => {
2183
+ const paint = React6.useMemo(() => {
2100
2184
  const p = {};
2101
2185
  if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
2102
2186
  if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
@@ -2108,7 +2192,7 @@ var HeatmapLayer = ({
2108
2192
  }
2109
2193
  return p;
2110
2194
  }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
2111
- const layout = React26.useMemo(() => ({}), []);
2195
+ const layout = React6.useMemo(() => ({}), []);
2112
2196
  useLayer({
2113
2197
  id,
2114
2198
  source,
@@ -2140,8 +2224,8 @@ function useControlPosition(ref, options) {
2140
2224
  isBuiltIn = false
2141
2225
  } = options;
2142
2226
  const { positioningCoordinator } = useMap();
2143
- const [offset, setOffset] = React26.useState(null);
2144
- React26.useEffect(() => {
2227
+ const [offset, setOffset] = React6.useState(null);
2228
+ React6.useEffect(() => {
2145
2229
  if (!ref.current || !positioningCoordinator) return;
2146
2230
  const element = ref.current;
2147
2231
  const initialOffset = positioningCoordinator.register({
@@ -2195,7 +2279,7 @@ function useControlPosition(ref, options) {
2195
2279
  positioningCoordinator,
2196
2280
  ref
2197
2281
  ]);
2198
- React26.useEffect(() => {
2282
+ React6.useEffect(() => {
2199
2283
  if (!positioningCoordinator) return;
2200
2284
  positioningCoordinator.update(id, {
2201
2285
  position: {
@@ -2206,7 +2290,7 @@ function useControlPosition(ref, options) {
2206
2290
  zLayer
2207
2291
  });
2208
2292
  }, [id, position, fallbacks, priority, zLayer, positioningCoordinator]);
2209
- const setExpanded = React26.useCallback(
2293
+ const setExpanded = React6.useCallback(
2210
2294
  (isExpanded) => {
2211
2295
  if (positioningCoordinator) {
2212
2296
  positioningCoordinator.setExpanded(id, isExpanded);
@@ -2214,7 +2298,7 @@ function useControlPosition(ref, options) {
2214
2298
  },
2215
2299
  [id, positioningCoordinator]
2216
2300
  );
2217
- const style = React26.useMemo(() => {
2301
+ const style = React6.useMemo(() => {
2218
2302
  if (!offset) {
2219
2303
  return {
2220
2304
  position: "absolute",
@@ -2262,9 +2346,9 @@ var Legend = ({
2262
2346
  class: className,
2263
2347
  onItemClick
2264
2348
  }) => {
2265
- const [isCollapsed, setIsCollapsed] = React26.useState(initialCollapsed);
2266
- const legendRef = React26.useRef(null);
2267
- const generatedId = React26.useId();
2349
+ const [isCollapsed, setIsCollapsed] = React6.useState(initialCollapsed);
2350
+ const legendRef = React6.useRef(null);
2351
+ const generatedId = React6.useId();
2268
2352
  const legendId = `legend-${generatedId}`;
2269
2353
  const { style, visible } = useControlPosition(legendRef, {
2270
2354
  id: legendId,
@@ -2284,7 +2368,7 @@ var Legend = ({
2284
2368
  setIsCollapsed(!isCollapsed);
2285
2369
  }
2286
2370
  };
2287
- const gradientStyle = React26.useMemo(() => {
2371
+ const gradientStyle = React6.useMemo(() => {
2288
2372
  if (type !== "gradient" || gradient.length === 0) return "";
2289
2373
  const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
2290
2374
  return `linear-gradient(to right, ${stops})`;
@@ -2385,14 +2469,14 @@ var LegendGroup = ({
2385
2469
  allowCollapseAll = false,
2386
2470
  class: className
2387
2471
  }) => {
2388
- const containerRef = React26.useRef(null);
2389
- const groupIdRef = React26.useRef(`legend-group-${++legendGroupIdCounter}`);
2472
+ const containerRef = React6.useRef(null);
2473
+ const groupIdRef = React6.useRef(`legend-group-${++legendGroupIdCounter}`);
2390
2474
  const getInitialExpanded = () => {
2391
2475
  if (controlledExpanded !== void 0) return controlledExpanded;
2392
2476
  if (defaultExpanded) return defaultExpanded;
2393
2477
  return legends[0]?.id || null;
2394
2478
  };
2395
- const [internalExpanded, setInternalExpanded] = React26.useState(getInitialExpanded);
2479
+ const [internalExpanded, setInternalExpanded] = React6.useState(getInitialExpanded);
2396
2480
  const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
2397
2481
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2398
2482
  id: groupIdRef.current,
@@ -2441,7 +2525,7 @@ var LegendGroup = ({
2441
2525
  type: "button",
2442
2526
  className: cn(
2443
2527
  "w-full flex items-center justify-between px-3 py-2 font-medium text-card-foreground",
2444
- "cursor-pointer hover:bg-muted transition-colors",
2528
+ "cursor-pointer hover:bg-muted",
2445
2529
  isFirst && "rounded-t-lg",
2446
2530
  isLast && !isExpanded && "rounded-b-lg"
2447
2531
  ),
@@ -2538,11 +2622,11 @@ var CoordinateDisplay = ({
2538
2622
  class: className
2539
2623
  }) => {
2540
2624
  const { map, loaded } = useMap();
2541
- const [cursorLngLat, setCursorLngLat] = React26.useState(null);
2542
- const [currentZoom, setCurrentZoom] = React26.useState(0);
2543
- const [currentBearing, setCurrentBearing] = React26.useState(0);
2544
- const controlRef = React26.useRef(null);
2545
- const uniqueId = React26.useId();
2625
+ const [cursorLngLat, setCursorLngLat] = React6.useState(null);
2626
+ const [currentZoom, setCurrentZoom] = React6.useState(0);
2627
+ const [currentBearing, setCurrentBearing] = React6.useState(0);
2628
+ const controlRef = React6.useRef(null);
2629
+ const uniqueId = React6.useId();
2546
2630
  const controlId = `coord-display${uniqueId}`;
2547
2631
  const { style, visible } = useControlPosition(controlRef, {
2548
2632
  id: controlId,
@@ -2551,7 +2635,7 @@ var CoordinateDisplay = ({
2551
2635
  priority: "critical",
2552
2636
  zLayer: "base"
2553
2637
  });
2554
- const adjustedStyle = React26.useMemo(() => {
2638
+ const adjustedStyle = React6.useMemo(() => {
2555
2639
  if (!style) return style;
2556
2640
  if (position === "top-right") {
2557
2641
  const rightOffset = NAV_CONTROL_WIDTH + STACK_GAP + EDGE_MARGIN;
@@ -2571,7 +2655,7 @@ var CoordinateDisplay = ({
2571
2655
  }
2572
2656
  return style;
2573
2657
  }, [position, style]);
2574
- const formatCoord = React26.useCallback(
2658
+ const formatCoord = React6.useCallback(
2575
2659
  (lngLat) => {
2576
2660
  return formatCoordinates(lngLat, precision, format);
2577
2661
  },
@@ -2584,7 +2668,7 @@ var CoordinateDisplay = ({
2584
2668
  const normalized = (bearing % 360 + 360) % 360;
2585
2669
  return `${normalized.toFixed(0)}\xB0`;
2586
2670
  };
2587
- React26.useEffect(() => {
2671
+ React6.useEffect(() => {
2588
2672
  if (!map || !loaded) return;
2589
2673
  setCurrentZoom(map.getZoom());
2590
2674
  setCurrentBearing(map.getBearing());
@@ -2651,16 +2735,19 @@ var BasemapSwitcher = ({
2651
2735
  class: className
2652
2736
  }) => {
2653
2737
  const { setMapStyle } = useMap();
2654
- const [isOpen, setIsOpen] = React26.useState(false);
2655
- const [internalActiveId, setInternalActiveId] = React26.useState(
2738
+ const [isOpen, setIsOpen] = React6.useState(false);
2739
+ const [internalActiveId, setInternalActiveId] = React6.useState(
2656
2740
  defaultBasemapId
2657
2741
  );
2658
- const containerRef = React26.useRef(null);
2659
- const panelRef = React26.useRef(null);
2660
- const generatedId = React26.useId();
2742
+ const containerRef = React6.useRef(null);
2743
+ const panelRef = React6.useRef(null);
2744
+ const toggleRef = React6.useRef(null);
2745
+ const optionRefs = React6.useRef([]);
2746
+ const [tabStopIndex, setTabStopIndex] = React6.useState(0);
2747
+ const generatedId = React6.useId();
2661
2748
  const switcherId = `basemap-switcher-${generatedId}`;
2662
2749
  const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
2663
- const availableBasemaps = React26.useMemo(() => {
2750
+ const availableBasemaps = React6.useMemo(() => {
2664
2751
  const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
2665
2752
  if (extraBasemaps?.length) {
2666
2753
  return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
@@ -2668,6 +2755,15 @@ var BasemapSwitcher = ({
2668
2755
  return available;
2669
2756
  }, [sourceBasemaps, extraBasemaps, apiKeys]);
2670
2757
  const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
2758
+ const activeIndex = Math.max(
2759
+ 0,
2760
+ availableBasemaps.findIndex((basemap) => basemap.id === currentActiveId)
2761
+ );
2762
+ React6.useEffect(() => {
2763
+ if (!isOpen) return;
2764
+ setTabStopIndex(activeIndex);
2765
+ optionRefs.current[activeIndex]?.focus();
2766
+ }, [isOpen]);
2671
2767
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2672
2768
  id: switcherId,
2673
2769
  type: "basemap-switcher",
@@ -2676,7 +2772,7 @@ var BasemapSwitcher = ({
2676
2772
  zLayer: "interactive",
2677
2773
  hasExpandedState: true
2678
2774
  });
2679
- React26.useEffect(() => {
2775
+ React6.useEffect(() => {
2680
2776
  if (!isOpen) return;
2681
2777
  const handleMouseDown = (e) => {
2682
2778
  if (containerRef.current && !containerRef.current.contains(e.target)) {
@@ -2687,12 +2783,13 @@ var BasemapSwitcher = ({
2687
2783
  document.addEventListener("mousedown", handleMouseDown);
2688
2784
  return () => document.removeEventListener("mousedown", handleMouseDown);
2689
2785
  }, [isOpen, setExpanded]);
2690
- React26.useEffect(() => {
2786
+ React6.useEffect(() => {
2691
2787
  if (!isOpen) return;
2692
2788
  const handleKeyDown = (e) => {
2693
2789
  if (e.key === "Escape") {
2694
2790
  setIsOpen(false);
2695
2791
  setExpanded(false);
2792
+ toggleRef.current?.focus();
2696
2793
  }
2697
2794
  };
2698
2795
  document.addEventListener("keydown", handleKeyDown);
@@ -2713,6 +2810,14 @@ var BasemapSwitcher = ({
2713
2810
  onBasemapChange?.(basemap);
2714
2811
  setIsOpen(false);
2715
2812
  setExpanded(false);
2813
+ toggleRef.current?.focus();
2814
+ };
2815
+ const handleOptionsKeyDown = (e) => {
2816
+ const next = getGridNavigationIndex(e.key, tabStopIndex, availableBasemaps.length, columns);
2817
+ if (next === null) return;
2818
+ e.preventDefault();
2819
+ setTabStopIndex(next);
2820
+ optionRefs.current[next]?.focus();
2716
2821
  };
2717
2822
  const handleToggle = () => {
2718
2823
  const newState = !isOpen;
@@ -2744,25 +2849,32 @@ var BasemapSwitcher = ({
2744
2849
  children: /* @__PURE__ */ jsx(
2745
2850
  "div",
2746
2851
  {
2747
- role: "group",
2852
+ role: "radiogroup",
2748
2853
  "aria-label": "Select basemap",
2749
2854
  className: "grid gap-1.5",
2750
2855
  style: {
2751
2856
  gridTemplateColumns: `repeat(${columns}, 1fr)`
2752
2857
  },
2753
- children: availableBasemaps.map((basemap) => {
2858
+ onKeyDown: handleOptionsKeyDown,
2859
+ children: availableBasemaps.map((basemap, index) => {
2754
2860
  const isActive = basemap.id === currentActiveId;
2755
2861
  const thumbUrl = resolveBasemapThumbnail(basemap, apiKeys);
2756
2862
  return /* @__PURE__ */ jsxs(
2757
2863
  "button",
2758
2864
  {
2865
+ ref: (el) => {
2866
+ optionRefs.current[index] = el;
2867
+ },
2759
2868
  type: "button",
2760
- "aria-pressed": isActive,
2869
+ role: "radio",
2870
+ "aria-checked": isActive,
2871
+ tabIndex: index === tabStopIndex ? 0 : -1,
2761
2872
  className: cn(
2762
2873
  "flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
2763
- "hover:bg-muted transition-colors",
2874
+ "hover:bg-muted",
2764
2875
  isActive && "ring-2 ring-primary"
2765
2876
  ),
2877
+ onFocus: () => setTabStopIndex(index),
2766
2878
  onClick: () => handleSelect(basemap),
2767
2879
  title: basemap.name,
2768
2880
  children: [
@@ -2792,11 +2904,12 @@ var BasemapSwitcher = ({
2792
2904
  /* @__PURE__ */ jsx(
2793
2905
  "button",
2794
2906
  {
2907
+ ref: toggleRef,
2795
2908
  type: "button",
2796
2909
  className: cn(
2797
2910
  "w-[40px] h-[40px] flex items-center justify-center",
2798
2911
  "bg-card rounded shadow-lg border border-black dark:border-gray-400",
2799
- "hover:bg-muted transition-colors cursor-pointer",
2912
+ "hover:bg-muted cursor-pointer",
2800
2913
  "text-foreground"
2801
2914
  ),
2802
2915
  onClick: handleToggle,
@@ -2842,20 +2955,20 @@ var LayerManager = ({
2842
2955
  class: className
2843
2956
  }) => {
2844
2957
  const { isDark } = useMapTheme();
2845
- const [isOpen, setIsOpen] = React26.useState(false);
2846
- const [layerStates, setLayerStates] = React26.useState(
2958
+ const [isOpen, setIsOpen] = React6.useState(false);
2959
+ const [layerStates, setLayerStates] = React6.useState(
2847
2960
  () => createInitialLayerStates(layers, initialActiveLayers)
2848
2961
  );
2849
- const [searchQuery, setSearchQuery] = React26.useState("");
2850
- const [activeCategory, setActiveCategory] = React26.useState("all");
2851
- const [expandedOpacity, setExpandedOpacity] = React26.useState(null);
2852
- const [draggedId, setDraggedId] = React26.useState(null);
2853
- const [dragOver, setDragOver] = React26.useState(null);
2854
- const containerRef = React26.useRef(null);
2855
- const uniqueId = React26.useId();
2962
+ const [searchQuery, setSearchQuery] = React6.useState("");
2963
+ const [activeCategory, setActiveCategory] = React6.useState("all");
2964
+ const [expandedOpacity, setExpandedOpacity] = React6.useState(null);
2965
+ const [draggedId, setDraggedId] = React6.useState(null);
2966
+ const [dragOver, setDragOver] = React6.useState(null);
2967
+ const containerRef = React6.useRef(null);
2968
+ const uniqueId = React6.useId();
2856
2969
  const managerId = `layer-manager${uniqueId}`;
2857
- const lastLayerIdsRef = React26.useRef(new Set(layers.map((l) => l.id)));
2858
- const tilesCacheRef = React26.useRef(/* @__PURE__ */ new Map());
2970
+ const lastLayerIdsRef = React6.useRef(new Set(layers.map((l) => l.id)));
2971
+ const tilesCacheRef = React6.useRef(/* @__PURE__ */ new Map());
2859
2972
  const getTiles = (url) => {
2860
2973
  let tiles = tilesCacheRef.current.get(url);
2861
2974
  if (!tiles) {
@@ -2872,7 +2985,7 @@ var LayerManager = ({
2872
2985
  zLayer: "interactive",
2873
2986
  hasExpandedState: true
2874
2987
  });
2875
- React26.useEffect(() => {
2988
+ React6.useEffect(() => {
2876
2989
  const currentLayerIds = new Set(layers.map((l) => l.id));
2877
2990
  const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
2878
2991
  const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
@@ -2903,8 +3016,8 @@ var LayerManager = ({
2903
3016
  lastLayerIdsRef.current = currentLayerIds;
2904
3017
  }
2905
3018
  }, [layers, initialActiveLayers]);
2906
- const categories = React26.useMemo(() => getLayerCategories(layers), [layers]);
2907
- const filteredLayers = React26.useMemo(() => {
3019
+ const categories = React6.useMemo(() => getLayerCategories(layers), [layers]);
3020
+ const filteredLayers = React6.useMemo(() => {
2908
3021
  let result = layers;
2909
3022
  if (searchQuery) {
2910
3023
  result = searchLayers(result, searchQuery);
@@ -2918,11 +3031,11 @@ var LayerManager = ({
2918
3031
  return orderA - orderB;
2919
3032
  });
2920
3033
  }, [layers, searchQuery, activeCategory, layerStates]);
2921
- const layerGroups = React26.useMemo(
3034
+ const layerGroups = React6.useMemo(
2922
3035
  () => showCategories ? groupLayersByCategory(filteredLayers) : null,
2923
3036
  [filteredLayers, showCategories]
2924
3037
  );
2925
- React26.useEffect(() => {
3038
+ React6.useEffect(() => {
2926
3039
  if (!isOpen) return;
2927
3040
  const handleMouseDown = (e) => {
2928
3041
  if (containerRef.current && !containerRef.current.contains(e.target)) {
@@ -2933,7 +3046,7 @@ var LayerManager = ({
2933
3046
  document.addEventListener("mousedown", handleMouseDown);
2934
3047
  return () => document.removeEventListener("mousedown", handleMouseDown);
2935
3048
  }, [isOpen, setExpanded]);
2936
- React26.useEffect(() => {
3049
+ React6.useEffect(() => {
2937
3050
  if (!isOpen) return;
2938
3051
  const handleKeyDown = (e) => {
2939
3052
  if (e.key === "Escape") {
@@ -2944,7 +3057,7 @@ var LayerManager = ({
2944
3057
  document.addEventListener("keydown", handleKeyDown);
2945
3058
  return () => document.removeEventListener("keydown", handleKeyDown);
2946
3059
  }, [isOpen, setExpanded]);
2947
- const handleToggleLayer = React26.useCallback(
3060
+ const handleToggleLayer = React6.useCallback(
2948
3061
  (layerId) => {
2949
3062
  setLayerStates((prev) => {
2950
3063
  const newStates = toggleLayerVisibility(prev, layerId);
@@ -2957,7 +3070,7 @@ var LayerManager = ({
2957
3070
  },
2958
3071
  [onLayerChange]
2959
3072
  );
2960
- const handleOpacityChange = React26.useCallback(
3073
+ const handleOpacityChange = React6.useCallback(
2961
3074
  (layerId, opacity) => {
2962
3075
  setLayerStates((prev) => {
2963
3076
  const newStates = setLayerOpacity(prev, layerId, opacity);
@@ -2970,12 +3083,12 @@ var LayerManager = ({
2970
3083
  },
2971
3084
  [onLayerChange]
2972
3085
  );
2973
- const handleDragStart = React26.useCallback((e, layerId) => {
3086
+ const handleDragStart = React6.useCallback((e, layerId) => {
2974
3087
  setDraggedId(layerId);
2975
3088
  e.dataTransfer.effectAllowed = "move";
2976
3089
  e.dataTransfer.setData("text/plain", layerId);
2977
3090
  }, []);
2978
- const handleDragOver = React26.useCallback(
3091
+ const handleDragOver = React6.useCallback(
2979
3092
  (e, layerId) => {
2980
3093
  e.preventDefault();
2981
3094
  e.dataTransfer.dropEffect = "move";
@@ -2995,14 +3108,14 @@ var LayerManager = ({
2995
3108
  },
2996
3109
  [draggedId, dragOver]
2997
3110
  );
2998
- const handleDragLeave = React26.useCallback(() => {
3111
+ const handleDragLeave = React6.useCallback(() => {
2999
3112
  setDragOver(null);
3000
3113
  }, []);
3001
- const handleDragEnd = React26.useCallback(() => {
3114
+ const handleDragEnd = React6.useCallback(() => {
3002
3115
  setDraggedId(null);
3003
3116
  setDragOver(null);
3004
3117
  }, []);
3005
- const handleDrop = React26.useCallback(
3118
+ const handleDrop = React6.useCallback(
3006
3119
  (e, targetLayerId) => {
3007
3120
  e.preventDefault();
3008
3121
  const sourceLayerId = e.dataTransfer.getData("text/plain");
@@ -3338,7 +3451,7 @@ var LayerManager = ({
3338
3451
  if (catLayers.length === 0) return null;
3339
3452
  return /* @__PURE__ */ jsxs("div", { children: [
3340
3453
  /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider", children: CATEGORY_META[cat].label }),
3341
- catLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
3454
+ catLayers.map((layer) => /* @__PURE__ */ jsxs(React6.Fragment, { children: [
3342
3455
  renderLayerItem(layer),
3343
3456
  renderOpacitySlider(layer.id)
3344
3457
  ] }, layer.id))
@@ -3346,7 +3459,7 @@ var LayerManager = ({
3346
3459
  })
3347
3460
  ) : (
3348
3461
  // Flat list
3349
- filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
3462
+ filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React6.Fragment, { children: [
3350
3463
  renderLayerItem(layer),
3351
3464
  renderOpacitySlider(layer.id)
3352
3465
  ] }, layer.id))
@@ -3363,7 +3476,7 @@ var LayerManager = ({
3363
3476
  className: cn(
3364
3477
  "w-[40px] h-[40px] flex items-center justify-center",
3365
3478
  "bg-card rounded shadow-lg border border-black dark:border-gray-400",
3366
- "hover:bg-muted transition-colors cursor-pointer",
3479
+ "hover:bg-muted cursor-pointer",
3367
3480
  "text-foreground"
3368
3481
  ),
3369
3482
  onClick: handleToggle,
@@ -3407,8 +3520,8 @@ var CustomControl = ({
3407
3520
  style: userStyle,
3408
3521
  children
3409
3522
  }) => {
3410
- const controlRef = React26.useRef(null);
3411
- const generatedId = React26.useId();
3523
+ const controlRef = React6.useRef(null);
3524
+ const generatedId = React6.useId();
3412
3525
  const controlId = id ?? `custom-control-${generatedId}`;
3413
3526
  const { style, visible, setExpanded } = useControlPosition(controlRef, {
3414
3527
  id: controlId,
@@ -3419,14 +3532,14 @@ var CustomControl = ({
3419
3532
  zLayer,
3420
3533
  hasExpandedState
3421
3534
  });
3422
- const mergedStyle = React26.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
3423
- const contextValue = React26.useMemo(() => ({ setExpanded }), [setExpanded]);
3535
+ const mergedStyle = React6.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
3536
+ const contextValue = React6.useMemo(() => ({ setExpanded }), [setExpanded]);
3424
3537
  return /* @__PURE__ */ jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
3425
3538
  };
3426
3539
  CustomControl.displayName = "CustomControl";
3427
- var CustomControlContext = React26.createContext(null);
3540
+ var CustomControlContext = React6.createContext(null);
3428
3541
  function useCustomControl() {
3429
- const context = React26.useContext(CustomControlContext);
3542
+ const context = React6.useContext(CustomControlContext);
3430
3543
  if (!context) {
3431
3544
  throw new Error("useCustomControl must be used within a CustomControl");
3432
3545
  }
@@ -3442,11 +3555,11 @@ var DeckOverlay = ({
3442
3555
  deckProps = {}
3443
3556
  }) => {
3444
3557
  const { map, loaded } = useMap();
3445
- const overlayRef = React26.useRef(null);
3446
- const MapboxOverlayRef = React26.useRef(null);
3447
- const layersRef = React26.useRef(layers);
3558
+ const overlayRef = React6.useRef(null);
3559
+ const MapboxOverlayRef = React6.useRef(null);
3560
+ const layersRef = React6.useRef(layers);
3448
3561
  layersRef.current = layers;
3449
- React26.useEffect(() => {
3562
+ React6.useEffect(() => {
3450
3563
  if (!map || !loaded) return;
3451
3564
  let cancelled = false;
3452
3565
  const initOverlay = async () => {
@@ -3486,12 +3599,12 @@ var DeckOverlay = ({
3486
3599
  }
3487
3600
  };
3488
3601
  }, [map, loaded, interleaved]);
3489
- React26.useEffect(() => {
3602
+ React6.useEffect(() => {
3490
3603
  if (overlayRef.current && "setProps" in overlayRef.current) {
3491
3604
  overlayRef.current.setProps({ layers });
3492
3605
  }
3493
3606
  }, [layers]);
3494
- React26.useEffect(() => {
3607
+ React6.useEffect(() => {
3495
3608
  if (overlayRef.current && "setProps" in overlayRef.current) {
3496
3609
  overlayRef.current.setProps({
3497
3610
  onHover,
@@ -3500,7 +3613,7 @@ var DeckOverlay = ({
3500
3613
  });
3501
3614
  }
3502
3615
  }, [onHover, onClick, getCursor]);
3503
- React26.useEffect(() => {
3616
+ React6.useEffect(() => {
3504
3617
  if (overlayRef.current && effects && "setProps" in overlayRef.current) {
3505
3618
  overlayRef.current.setProps({ effects });
3506
3619
  }