@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.cjs CHANGED
@@ -1,19 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var React26 = require('react');
3
+ var React6 = require('react');
4
4
  var clsx = require('clsx');
5
5
  var tailwindMerge = require('tailwind-merge');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var maplibregl = require('maplibre-gl');
8
- require('maplibre-gl/dist/maplibre-gl.css');
9
- require('@classic-homes/maps-core/styles/controls.css');
10
- require('@classic-homes/maps-core/styles/marker.css');
11
8
  var mapsCore = require('@classic-homes/maps-core');
12
9
  var ReactDOM = require('react-dom');
13
10
  var utils = require('@classic-homes/maps-core/utils');
14
11
  var classVarianceAuthority = require('class-variance-authority');
15
- require('@classic-homes/maps-core/styles/basemap-switcher.css');
16
- require('@classic-homes/maps-core/styles/layer-manager.css');
17
12
  var themeReact = require('@classic-homes/theme-react');
18
13
 
19
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -36,7 +31,7 @@ function _interopNamespace(e) {
36
31
  return Object.freeze(n);
37
32
  }
38
33
 
39
- var React26__namespace = /*#__PURE__*/_interopNamespace(React26);
34
+ var React6__namespace = /*#__PURE__*/_interopNamespace(React6);
40
35
  var maplibregl__default = /*#__PURE__*/_interopDefault(maplibregl);
41
36
  var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
42
37
 
@@ -44,7 +39,7 @@ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
44
39
  function cn(...inputs) {
45
40
  return tailwindMerge.twMerge(clsx.clsx(inputs));
46
41
  }
47
- var MapSkeleton = React26__namespace.forwardRef(
42
+ var MapSkeleton = React6__namespace.forwardRef(
48
43
  ({ height = 400, className, ...props }, ref) => {
49
44
  const heightStyle = typeof height === "number" ? `${height}px` : height;
50
45
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -98,7 +93,7 @@ var MapSkeleton = React26__namespace.forwardRef(
98
93
  }
99
94
  );
100
95
  MapSkeleton.displayName = "MapSkeleton";
101
- var MapError = React26__namespace.forwardRef(
96
+ var MapError = React6__namespace.forwardRef(
102
97
  ({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
103
98
  const heightStyle = typeof height === "number" ? `${height}px` : height;
104
99
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -144,7 +139,7 @@ var MapError = React26__namespace.forwardRef(
144
139
  "button",
145
140
  {
146
141
  onClick: onRetry,
147
- 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",
142
+ 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",
148
143
  children: "Retry"
149
144
  }
150
145
  )
@@ -154,7 +149,7 @@ var MapError = React26__namespace.forwardRef(
154
149
  }
155
150
  );
156
151
  MapError.displayName = "MapError";
157
- var MapEmpty = React26__namespace.forwardRef(
152
+ var MapEmpty = React6__namespace.forwardRef(
158
153
  ({ message = "No map data to display", height = 400, className, ...props }, ref) => {
159
154
  const heightStyle = typeof height === "number" ? `${height}px` : height;
160
155
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -197,7 +192,7 @@ var MapEmpty = React26__namespace.forwardRef(
197
192
  }
198
193
  );
199
194
  MapEmpty.displayName = "MapEmpty";
200
- var MapContainer = React26__namespace.forwardRef(
195
+ var MapContainer = React6__namespace.forwardRef(
201
196
  ({
202
197
  title,
203
198
  description,
@@ -246,8 +241,8 @@ var MapContainer = React26__namespace.forwardRef(
246
241
  );
247
242
  MapContainer.displayName = "MapContainer";
248
243
  function useMapTheme(preference = "auto") {
249
- const [isDark, setIsDark] = React26.useState(false);
250
- const updateTheme = React26.useCallback(() => {
244
+ const [isDark, setIsDark] = React6.useState(false);
245
+ const updateTheme = React6.useCallback(() => {
251
246
  if (preference !== "auto") {
252
247
  setIsDark(preference === "dark");
253
248
  return;
@@ -257,7 +252,7 @@ function useMapTheme(preference = "auto") {
257
252
  setIsDark(hasDarkClass);
258
253
  }
259
254
  }, [preference]);
260
- React26.useEffect(() => {
255
+ React6.useEffect(() => {
261
256
  updateTheme();
262
257
  if (preference !== "auto" || typeof document === "undefined") return;
263
258
  const observer = new MutationObserver((mutations) => {
@@ -288,8 +283,8 @@ function useMapTheme(preference = "auto") {
288
283
  };
289
284
  }
290
285
  function useReducedMotion() {
291
- const [prefersReducedMotion, setPrefersReducedMotion] = React26.useState(false);
292
- React26.useEffect(() => {
286
+ const [prefersReducedMotion, setPrefersReducedMotion] = React6.useState(false);
287
+ React6.useEffect(() => {
293
288
  if (typeof window === "undefined") return;
294
289
  const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
295
290
  setPrefersReducedMotion(mediaQuery.matches);
@@ -303,9 +298,9 @@ function useReducedMotion() {
303
298
  }, []);
304
299
  return prefersReducedMotion;
305
300
  }
306
- var MapContext = React26__namespace.createContext(null);
301
+ var MapContext = React6__namespace.createContext(null);
307
302
  function useMap() {
308
- const context = React26__namespace.useContext(MapContext);
303
+ const context = React6__namespace.useContext(MapContext);
309
304
  if (!context) {
310
305
  throw new Error("useMap must be used within a Map component");
311
306
  }
@@ -315,7 +310,11 @@ function useMapInstance() {
315
310
  const { map, loaded } = useMap();
316
311
  return loaded ? map : null;
317
312
  }
318
- var Map2 = React26__namespace.forwardRef(
313
+ function getStyleKey(style) {
314
+ if (!style) return "";
315
+ return typeof style === "string" ? style : JSON.stringify(style);
316
+ }
317
+ var Map2 = React6__namespace.forwardRef(
319
318
  ({
320
319
  // Base props
321
320
  title,
@@ -370,30 +369,30 @@ var Map2 = React26__namespace.forwardRef(
370
369
  onZoom,
371
370
  onError
372
371
  }, ref) => {
373
- const containerRef = React26__namespace.useRef(null);
374
- const mapRef = React26__namespace.useRef(null);
375
- const [mapLoaded, setMapLoaded] = React26__namespace.useState(false);
376
- const [mapError, setMapError] = React26__namespace.useState(null);
377
- const [initAttempt, setInitAttempt] = React26__namespace.useState(0);
378
- const retryInit = React26__namespace.useCallback(() => {
372
+ const containerRef = React6__namespace.useRef(null);
373
+ const mapRef = React6__namespace.useRef(null);
374
+ const [mapLoaded, setMapLoaded] = React6__namespace.useState(false);
375
+ const [mapError, setMapError] = React6__namespace.useState(null);
376
+ const [initAttempt, setInitAttempt] = React6__namespace.useState(0);
377
+ const retryInit = React6__namespace.useCallback(() => {
379
378
  setMapError(null);
380
379
  setInitAttempt((attempt) => attempt + 1);
381
380
  }, []);
382
- const [styleVersion, setStyleVersion] = React26__namespace.useState(0);
383
- const styleVersionRef = React26__namespace.useRef(0);
384
- const bumpStyleVersion = React26__namespace.useCallback(() => {
381
+ const [styleVersion, setStyleVersion] = React6__namespace.useState(0);
382
+ const styleVersionRef = React6__namespace.useRef(0);
383
+ const bumpStyleVersion = React6__namespace.useCallback(() => {
385
384
  styleVersionRef.current += 1;
386
385
  setStyleVersion(styleVersionRef.current);
387
386
  }, []);
388
- const activeStyleOverrideRef = React26__namespace.useRef(
387
+ const activeStyleOverrideRef = React6__namespace.useRef(
389
388
  null
390
389
  );
391
- const positioningCoordinatorRef = React26__namespace.useRef(null);
390
+ const positioningCoordinatorRef = React6__namespace.useRef(null);
392
391
  if (!positioningCoordinatorRef.current) {
393
392
  positioningCoordinatorRef.current = mapsCore.createPositioningCoordinator();
394
393
  }
395
394
  const positioningCoordinator = positioningCoordinatorRef.current;
396
- const setMapStyle = React26__namespace.useCallback(
395
+ const setMapStyle = React6__namespace.useCallback(
397
396
  (style) => {
398
397
  activeStyleOverrideRef.current = style;
399
398
  const map = mapRef.current;
@@ -408,16 +407,20 @@ var Map2 = React26__namespace.forwardRef(
408
407
  );
409
408
  const prefersReducedMotion = useReducedMotion();
410
409
  const { style: themeStyle } = useMapTheme(themePref);
411
- const onLoadRef = React26__namespace.useRef(onLoad);
410
+ const onLoadRef = React6__namespace.useRef(onLoad);
412
411
  onLoadRef.current = onLoad;
413
- const onErrorRef = React26__namespace.useRef(onError);
412
+ const onErrorRef = React6__namespace.useRef(onError);
414
413
  onErrorRef.current = onError;
415
414
  const mapStyle = customStyle || themeStyle;
415
+ const mapStyleKey = React6__namespace.useMemo(() => getStyleKey(mapStyle), [mapStyle]);
416
+ const customStyleKey = React6__namespace.useMemo(() => getStyleKey(customStyle), [customStyle]);
417
+ const mapStyleRef = React6__namespace.useRef(mapStyle);
418
+ mapStyleRef.current = mapStyle;
416
419
  const accessibleDescription = description || mapsCore.generateMapDescription(title, {
417
420
  center,
418
421
  zoom
419
422
  });
420
- React26__namespace.useEffect(() => {
423
+ React6__namespace.useEffect(() => {
421
424
  if (!containerRef.current || !positioningCoordinator) return;
422
425
  const updateDimensions = () => {
423
426
  if (!containerRef.current) return;
@@ -433,12 +436,12 @@ var Map2 = React26__namespace.forwardRef(
433
436
  resizeObserver.disconnect();
434
437
  };
435
438
  }, [positioningCoordinator]);
436
- React26__namespace.useEffect(() => {
439
+ React6__namespace.useEffect(() => {
437
440
  return () => {
438
441
  positioningCoordinator.destroy();
439
442
  };
440
443
  }, [positioningCoordinator]);
441
- React26__namespace.useEffect(() => {
444
+ React6__namespace.useEffect(() => {
442
445
  if (!containerRef.current || mapRef.current) return;
443
446
  try {
444
447
  const map = new maplibregl__default.default.Map({
@@ -597,7 +600,7 @@ var Map2 = React26__namespace.forwardRef(
597
600
  });
598
601
  }
599
602
  }, [initAttempt]);
600
- React26__namespace.useEffect(() => {
603
+ React6__namespace.useEffect(() => {
601
604
  const map = mapRef.current;
602
605
  if (!map || !mapLoaded) return;
603
606
  map.on("style.load", bumpStyleVersion);
@@ -605,22 +608,22 @@ var Map2 = React26__namespace.forwardRef(
605
608
  map.off("style.load", bumpStyleVersion);
606
609
  };
607
610
  }, [mapLoaded, bumpStyleVersion]);
608
- const styleInitialized = React26__namespace.useRef(false);
609
- React26__namespace.useEffect(() => {
611
+ const styleInitialized = React6__namespace.useRef(false);
612
+ React6__namespace.useEffect(() => {
610
613
  if (!mapRef.current || !mapLoaded) return;
611
614
  if (!styleInitialized.current) {
612
615
  styleInitialized.current = true;
613
616
  return;
614
617
  }
615
618
  if (activeStyleOverrideRef.current) return;
616
- mapRef.current.setStyle(mapStyle);
617
- }, [mapStyle, mapLoaded]);
618
- React26__namespace.useEffect(() => {
619
- if (customStyle) {
619
+ mapRef.current.setStyle(mapStyleRef.current);
620
+ }, [mapStyleKey, mapLoaded]);
621
+ React6__namespace.useEffect(() => {
622
+ if (customStyleKey) {
620
623
  activeStyleOverrideRef.current = null;
621
624
  }
622
- }, [customStyle]);
623
- React26__namespace.useEffect(() => {
625
+ }, [customStyleKey]);
626
+ React6__namespace.useEffect(() => {
624
627
  const map = mapRef.current;
625
628
  if (!map || !mapLoaded) return;
626
629
  const createEventParams = (e) => ({
@@ -719,7 +722,7 @@ var Map2 = React26__namespace.forwardRef(
719
722
  onZoom
720
723
  ]);
721
724
  const combinedError = error || mapError;
722
- const contextValue = React26__namespace.useMemo(
725
+ const contextValue = React6__namespace.useMemo(
723
726
  () => ({
724
727
  map: mapRef.current,
725
728
  loaded: mapLoaded,
@@ -751,6 +754,53 @@ var Map2 = React26__namespace.forwardRef(
751
754
  }
752
755
  );
753
756
  Map2.displayName = "Map";
757
+ function createSourceRegistry() {
758
+ const versions = /* @__PURE__ */ new Map();
759
+ const stacking = /* @__PURE__ */ new Map();
760
+ const listeners = /* @__PURE__ */ new Set();
761
+ let counter = 0;
762
+ const notify = () => {
763
+ for (const listener of [...listeners]) listener();
764
+ };
765
+ return {
766
+ version: (id) => versions.get(id) ?? 0,
767
+ added(id) {
768
+ versions.set(id, ++counter);
769
+ notify();
770
+ },
771
+ removed(id, layersAbove) {
772
+ stacking.set(id, layersAbove ?? /* @__PURE__ */ new Map());
773
+ if (versions.delete(id)) notify();
774
+ },
775
+ layersAbove: (sourceId, layerId) => stacking.get(sourceId)?.get(layerId) ?? [],
776
+ subscribe(listener) {
777
+ listeners.add(listener);
778
+ return () => {
779
+ listeners.delete(listener);
780
+ };
781
+ }
782
+ };
783
+ }
784
+ var registries = /* @__PURE__ */ new WeakMap();
785
+ function getSourceRegistry(map) {
786
+ let registry = registries.get(map);
787
+ if (!registry) {
788
+ registry = createSourceRegistry();
789
+ registries.set(map, registry);
790
+ }
791
+ return registry;
792
+ }
793
+ var noopSubscribe = () => () => {
794
+ };
795
+ var zero = () => 0;
796
+ function useSourceVersion(map, sourceId) {
797
+ const registry = map ? getSourceRegistry(map) : null;
798
+ const getSnapshot = React6__namespace.useCallback(
799
+ () => registry ? registry.version(sourceId) : 0,
800
+ [registry, sourceId]
801
+ );
802
+ return React6__namespace.useSyncExternalStore(registry?.subscribe ?? noopSubscribe, getSnapshot, zero);
803
+ }
754
804
  var Source = ({
755
805
  id,
756
806
  type,
@@ -771,10 +821,9 @@ var Source = ({
771
821
  children
772
822
  }) => {
773
823
  const { map, loaded, styleVersion } = useMap();
774
- const initialFitDone = React26__namespace.useRef(false);
775
- const lastStyleVersionRef = React26__namespace.useRef(styleVersion);
776
- const appliedDataRef = React26__namespace.useRef(void 0);
777
- const fitBoundsParamsRef = React26__namespace.useRef({
824
+ const initialFitDone = React6__namespace.useRef(false);
825
+ const appliedDataRef = React6__namespace.useRef(void 0);
826
+ const fitBoundsParamsRef = React6__namespace.useRef({
778
827
  shouldFitBounds,
779
828
  data,
780
829
  fitBoundsPadding,
@@ -790,7 +839,7 @@ var Source = ({
790
839
  fitBoundsAnimate,
791
840
  type
792
841
  };
793
- const performFitBounds = React26__namespace.useCallback(
842
+ const performFitBounds = React6__namespace.useCallback(
794
843
  (cancelledRef) => {
795
844
  const params = fitBoundsParamsRef.current;
796
845
  if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
@@ -834,12 +883,8 @@ var Source = ({
834
883
  },
835
884
  [map]
836
885
  );
837
- React26__namespace.useEffect(() => {
886
+ React6__namespace.useEffect(() => {
838
887
  if (!map || !loaded) return;
839
- if (styleVersion !== lastStyleVersionRef.current) {
840
- lastStyleVersionRef.current = styleVersion;
841
- initialFitDone.current = false;
842
- }
843
888
  if (map.getSource(id)) {
844
889
  return;
845
890
  }
@@ -928,6 +973,8 @@ var Source = ({
928
973
  map.once("idle", handleIdle);
929
974
  map.addSource(id, sourceConfig);
930
975
  appliedDataRef.current = type === "geojson" ? data : void 0;
976
+ const registry = getSourceRegistry(map);
977
+ registry.added(id);
931
978
  const source = map.getSource(id);
932
979
  if (source && map.isSourceLoaded(id)) {
933
980
  map.off("sourcedata", handleSourceData);
@@ -946,11 +993,14 @@ var Source = ({
946
993
  return () => {
947
994
  cleanupListeners();
948
995
  if (map) {
996
+ const layersAbove = /* @__PURE__ */ new Map();
949
997
  try {
950
998
  const style = map.getStyle();
951
999
  if (style?.layers) {
952
- style.layers.forEach((layer) => {
1000
+ const ids = style.layers.map((layer) => layer.id);
1001
+ style.layers.forEach((layer, index) => {
953
1002
  if ("source" in layer && layer.source === id) {
1003
+ layersAbove.set(layer.id, ids.slice(index + 1));
954
1004
  if (map.getLayer(layer.id)) {
955
1005
  map.removeLayer(layer.id);
956
1006
  }
@@ -962,6 +1012,7 @@ var Source = ({
962
1012
  }
963
1013
  } catch {
964
1014
  }
1015
+ registry.removed(id, layersAbove);
965
1016
  }
966
1017
  };
967
1018
  } catch (err) {
@@ -986,7 +1037,7 @@ var Source = ({
986
1037
  styleVersion
987
1038
  // re-add source after basemap style changes
988
1039
  ]);
989
- React26__namespace.useEffect(() => {
1040
+ React6__namespace.useEffect(() => {
990
1041
  if (!map || !loaded || type !== "geojson") return;
991
1042
  const source = map.getSource(id);
992
1043
  if (!source) return;
@@ -1020,7 +1071,7 @@ var Source = ({
1020
1071
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1021
1072
  };
1022
1073
  Source.displayName = "Source";
1023
- var Marker = React26__namespace.forwardRef(
1074
+ var Marker = React6__namespace.forwardRef(
1024
1075
  ({
1025
1076
  id,
1026
1077
  coordinates,
@@ -1036,30 +1087,30 @@ var Marker = React26__namespace.forwardRef(
1036
1087
  children
1037
1088
  }, ref) => {
1038
1089
  const { map, loaded } = useMap();
1039
- const markerRef = React26__namespace.useRef(null);
1040
- const elementRef = React26__namespace.useRef(null);
1041
- const originalLngLatRef = React26__namespace.useRef();
1042
- const clickHandlerRef = React26__namespace.useRef(null);
1043
- const dragStartHandlerRef = React26__namespace.useRef(null);
1044
- const dragHandlerRef = React26__namespace.useRef(null);
1045
- const dragEndHandlerRef = React26__namespace.useRef(null);
1046
- const [mounted, setMounted] = React26__namespace.useState(false);
1047
- const onClickRef = React26__namespace.useRef(onClick);
1090
+ const markerRef = React6__namespace.useRef(null);
1091
+ const elementRef = React6__namespace.useRef(null);
1092
+ const originalLngLatRef = React6__namespace.useRef();
1093
+ const clickHandlerRef = React6__namespace.useRef(null);
1094
+ const dragStartHandlerRef = React6__namespace.useRef(null);
1095
+ const dragHandlerRef = React6__namespace.useRef(null);
1096
+ const dragEndHandlerRef = React6__namespace.useRef(null);
1097
+ const [mounted, setMounted] = React6__namespace.useState(false);
1098
+ const onClickRef = React6__namespace.useRef(onClick);
1048
1099
  onClickRef.current = onClick;
1049
- const onDragRef = React26__namespace.useRef(onDrag);
1100
+ const onDragRef = React6__namespace.useRef(onDrag);
1050
1101
  onDragRef.current = onDrag;
1051
- const onDragEndRef = React26__namespace.useRef(onDragEnd);
1102
+ const onDragEndRef = React6__namespace.useRef(onDragEnd);
1052
1103
  onDragEndRef.current = onDragEnd;
1053
- React26__namespace.useEffect(() => {
1104
+ React6__namespace.useEffect(() => {
1054
1105
  setMounted(true);
1055
1106
  return () => setMounted(false);
1056
1107
  }, []);
1057
- React26__namespace.useEffect(() => {
1108
+ React6__namespace.useEffect(() => {
1058
1109
  if (children && !elementRef.current) {
1059
1110
  elementRef.current = document.createElement("div");
1060
1111
  }
1061
1112
  }, [children]);
1062
- React26__namespace.useEffect(() => {
1113
+ React6__namespace.useEffect(() => {
1063
1114
  if (!map || !loaded || !mounted) return;
1064
1115
  if (markerRef.current) return;
1065
1116
  const markerOptions = {
@@ -1163,12 +1214,12 @@ var Marker = React26__namespace.forwardRef(
1163
1214
  }
1164
1215
  };
1165
1216
  }, [map, loaded, mounted]);
1166
- React26__namespace.useEffect(() => {
1217
+ React6__namespace.useEffect(() => {
1167
1218
  if (markerRef.current) {
1168
1219
  markerRef.current.setLngLat(coordinates);
1169
1220
  }
1170
1221
  }, [coordinates]);
1171
- React26__namespace.useEffect(() => {
1222
+ React6__namespace.useEffect(() => {
1172
1223
  const marker = markerRef.current;
1173
1224
  if (!marker) return;
1174
1225
  marker.setDraggable(draggable);
@@ -1216,12 +1267,12 @@ var Marker = React26__namespace.forwardRef(
1216
1267
  marker.on("dragend", handleDragEnd);
1217
1268
  }
1218
1269
  }, [draggable, id]);
1219
- React26__namespace.useEffect(() => {
1270
+ React6__namespace.useEffect(() => {
1220
1271
  if (markerRef.current && rotation !== void 0) {
1221
1272
  markerRef.current.setRotation(rotation);
1222
1273
  }
1223
1274
  }, [rotation]);
1224
- React26__namespace.useEffect(() => {
1275
+ React6__namespace.useEffect(() => {
1225
1276
  if (markerRef.current && offset) {
1226
1277
  markerRef.current.setOffset(offset);
1227
1278
  }
@@ -1234,13 +1285,13 @@ var Marker = React26__namespace.forwardRef(
1234
1285
  );
1235
1286
  Marker.displayName = "Marker";
1236
1287
  function useStructuralValue(next) {
1237
- const ref = React26__namespace.useRef(next);
1288
+ const ref = React6__namespace.useRef(next);
1238
1289
  if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1239
1290
  ref.current = next;
1240
1291
  }
1241
1292
  return ref.current;
1242
1293
  }
1243
- var Popup = React26__namespace.forwardRef(
1294
+ var Popup = React6__namespace.forwardRef(
1244
1295
  ({
1245
1296
  coordinates: coordinatesProp,
1246
1297
  closeButton = true,
@@ -1261,26 +1312,26 @@ var Popup = React26__namespace.forwardRef(
1261
1312
  const coordinates = useStructuralValue(coordinatesProp);
1262
1313
  const offset = useStructuralValue(offsetProp);
1263
1314
  const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1264
- const popupRef = React26__namespace.useRef(null);
1265
- const onOpenRef = React26__namespace.useRef(onOpen);
1315
+ const popupRef = React6__namespace.useRef(null);
1316
+ const onOpenRef = React6__namespace.useRef(onOpen);
1266
1317
  onOpenRef.current = onOpen;
1267
- const onCloseRef = React26__namespace.useRef(onClose);
1318
+ const onCloseRef = React6__namespace.useRef(onClose);
1268
1319
  onCloseRef.current = onClose;
1269
- const coordinatesRef = React26__namespace.useRef(coordinates);
1320
+ const coordinatesRef = React6__namespace.useRef(coordinates);
1270
1321
  coordinatesRef.current = coordinates;
1271
- const containerRef = React26__namespace.useRef(null);
1322
+ const containerRef = React6__namespace.useRef(null);
1272
1323
  if (!containerRef.current && typeof document !== "undefined") {
1273
1324
  containerRef.current = document.createElement("div");
1274
1325
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1275
1326
  }
1276
- const [contentReady, setContentReady] = React26__namespace.useState(false);
1277
- const [popupVersion, setPopupVersion] = React26__namespace.useState(0);
1278
- const contentCallbackRef = React26__namespace.useCallback((node) => {
1327
+ const [contentReady, setContentReady] = React6__namespace.useState(false);
1328
+ const [popupVersion, setPopupVersion] = React6__namespace.useState(0);
1329
+ const contentCallbackRef = React6__namespace.useCallback((node) => {
1279
1330
  if (node && containerRef.current) {
1280
1331
  setContentReady(true);
1281
1332
  }
1282
1333
  }, []);
1283
- React26__namespace.useEffect(() => {
1334
+ React6__namespace.useEffect(() => {
1284
1335
  if (!map || !loaded || !containerRef.current) return;
1285
1336
  const popup = new maplibregl__default.default.Popup({
1286
1337
  closeButton,
@@ -1321,7 +1372,7 @@ var Popup = React26__namespace.forwardRef(
1321
1372
  maxWidth,
1322
1373
  focusAfterOpen
1323
1374
  ]);
1324
- React26__namespace.useEffect(() => {
1375
+ React6__namespace.useEffect(() => {
1325
1376
  if (!popupRef.current || !ref) return;
1326
1377
  if (typeof ref === "function") {
1327
1378
  ref(popupRef.current);
@@ -1329,16 +1380,17 @@ var Popup = React26__namespace.forwardRef(
1329
1380
  ref.current = popupRef.current;
1330
1381
  }
1331
1382
  }, [ref, popupVersion]);
1332
- React26__namespace.useEffect(() => {
1383
+ React6__namespace.useEffect(() => {
1333
1384
  if (popupRef.current) {
1334
1385
  popupRef.current.setLngLat(coordinates);
1335
1386
  }
1336
1387
  }, [coordinates]);
1337
- React26__namespace.useEffect(() => {
1388
+ React6__namespace.useEffect(() => {
1338
1389
  if (!map || !popupRef.current || !contentReady) return;
1339
1390
  let rafHandle;
1340
1391
  if (open) {
1341
- popupRef.current.setLngLat(coordinates).addTo(map);
1392
+ popupRef.current.setLngLat(coordinates);
1393
+ if (!popupRef.current.isOpen()) popupRef.current.addTo(map);
1342
1394
  if (autoPan) {
1343
1395
  rafHandle = requestAnimationFrame(() => {
1344
1396
  if (popupRef.current && map) {
@@ -1363,7 +1415,7 @@ var Popup = React26__namespace.forwardRef(
1363
1415
  }
1364
1416
  );
1365
1417
  Popup.displayName = "Popup";
1366
- var PopupCard = React26__namespace.forwardRef(
1418
+ var PopupCard = React6__namespace.forwardRef(
1367
1419
  ({ className, children, ...props }, ref) => {
1368
1420
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
1369
1421
  }
@@ -1383,7 +1435,7 @@ var badgeVariants = classVarianceAuthority.cva("text-xs px-1.5 py-0.5 rounded fo
1383
1435
  badgeVariant: "secondary"
1384
1436
  }
1385
1437
  });
1386
- var PopupHeader = React26__namespace.forwardRef(
1438
+ var PopupHeader = React6__namespace.forwardRef(
1387
1439
  ({ className, title, badge, badgeVariant, ...props }, ref) => {
1388
1440
  return /* @__PURE__ */ jsxRuntime.jsxs(
1389
1441
  "div",
@@ -1403,13 +1455,13 @@ var PopupHeader = React26__namespace.forwardRef(
1403
1455
  }
1404
1456
  );
1405
1457
  PopupHeader.displayName = "PopupHeader";
1406
- var PopupContent = React26__namespace.forwardRef(
1458
+ var PopupContent = React6__namespace.forwardRef(
1407
1459
  ({ className, children, ...props }, ref) => {
1408
1460
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
1409
1461
  }
1410
1462
  );
1411
1463
  PopupContent.displayName = "PopupContent";
1412
- var PopupFooter = React26__namespace.forwardRef(
1464
+ var PopupFooter = React6__namespace.forwardRef(
1413
1465
  ({ className, children, ...props }, ref) => {
1414
1466
  return /* @__PURE__ */ jsxRuntime.jsx(
1415
1467
  "div",
@@ -1426,6 +1478,11 @@ var PopupFooter = React26__namespace.forwardRef(
1426
1478
  }
1427
1479
  );
1428
1480
  PopupFooter.displayName = "PopupFooter";
1481
+ function withoutVisibility(layout) {
1482
+ const next = { ...layout ?? {} };
1483
+ delete next.visibility;
1484
+ return next;
1485
+ }
1429
1486
  function useLayer({
1430
1487
  id,
1431
1488
  source,
@@ -1444,91 +1501,115 @@ function useLayer({
1444
1501
  hoverThrottleMs = 0
1445
1502
  }) {
1446
1503
  const { map, loaded, styleVersion } = useMap();
1447
- const [layerAdded, setLayerAdded] = React26__namespace.useState(false);
1448
- const hoveredFeatureId = React26__namespace.useRef(null);
1449
- const lastHoverCallTime = React26__namespace.useRef(0);
1450
- const lastMousePosition = React26__namespace.useRef(null);
1451
- React26__namespace.useEffect(() => {
1504
+ const sourceVersion = useSourceVersion(map, source);
1505
+ const [layerAdded, setLayerAdded] = React6__namespace.useState(false);
1506
+ const hoveredFeatureId = React6__namespace.useRef(null);
1507
+ const lastHoverCallTime = React6__namespace.useRef(0);
1508
+ const lastMousePosition = React6__namespace.useRef(null);
1509
+ const lastAppliedPaintRef = React6__namespace.useRef(void 0);
1510
+ const lastAppliedLayoutRef = React6__namespace.useRef(void 0);
1511
+ const latestRef = React6__namespace.useRef({ visible, minZoom, maxZoom, filter, paint, layout });
1512
+ latestRef.current = { visible, minZoom, maxZoom, filter, paint, layout };
1513
+ const restoreLayerRef = React6__namespace.useRef(null);
1514
+ React6__namespace.useEffect(() => {
1452
1515
  hoveredFeatureId.current = null;
1453
1516
  }, [styleVersion]);
1454
- React26__namespace.useEffect(() => {
1517
+ React6__namespace.useEffect(() => {
1455
1518
  if (!map || !loaded) return;
1456
- if (!map.getSource(source)) {
1457
- let timeoutId = null;
1458
- const checkSource = () => {
1459
- if (map.getSource(source)) {
1460
- if (timeoutId) clearTimeout(timeoutId);
1461
- addLayer();
1462
- map.off("sourcedata", checkSource);
1463
- }
1464
- };
1465
- timeoutId = setTimeout(() => {
1466
- if (!map.getSource(source)) {
1467
- console.warn(
1468
- `[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.`
1469
- );
1470
- }
1471
- }, 5e3);
1472
- map.on("sourcedata", checkSource);
1473
- return () => {
1474
- if (timeoutId) clearTimeout(timeoutId);
1475
- map.off("sourcedata", checkSource);
1476
- };
1519
+ let added = false;
1520
+ let timeoutId = null;
1521
+ const stopWaiting = () => {
1522
+ if (timeoutId) clearTimeout(timeoutId);
1523
+ timeoutId = null;
1524
+ map.off("sourcedata", checkSource);
1525
+ };
1526
+ function checkSource() {
1527
+ if (map.getSource(source)) {
1528
+ stopWaiting();
1529
+ addLayer();
1530
+ }
1477
1531
  }
1478
- addLayer();
1479
- function addLayer() {
1532
+ function addLayer(insertBefore = beforeId) {
1480
1533
  if (map.getLayer(id)) {
1534
+ added = true;
1481
1535
  setLayerAdded(true);
1482
1536
  return;
1483
1537
  }
1538
+ const { visible: visible2, minZoom: minZoom2, maxZoom: maxZoom2, filter: filter2, paint: paint2, layout: layout2 } = latestRef.current;
1484
1539
  try {
1485
1540
  const layerConfig = {
1486
1541
  id,
1487
1542
  type,
1488
1543
  source,
1489
- paint,
1544
+ paint: paint2,
1490
1545
  layout: {
1491
- visibility: visible ? "visible" : "none",
1492
- ...layout
1546
+ visibility: visible2 ? "visible" : "none",
1547
+ ...layout2
1493
1548
  }
1494
1549
  };
1495
1550
  if (sourceLayer) {
1496
1551
  layerConfig["source-layer"] = sourceLayer;
1497
1552
  }
1498
- if (minZoom !== void 0) {
1499
- layerConfig.minzoom = minZoom;
1553
+ if (minZoom2 !== void 0) {
1554
+ layerConfig.minzoom = minZoom2;
1500
1555
  }
1501
- if (maxZoom !== void 0) {
1502
- layerConfig.maxzoom = maxZoom;
1556
+ if (maxZoom2 !== void 0) {
1557
+ layerConfig.maxzoom = maxZoom2;
1503
1558
  }
1504
- if (filter) {
1505
- layerConfig.filter = filter;
1559
+ if (filter2) {
1560
+ layerConfig.filter = filter2;
1506
1561
  }
1507
- map.addLayer(layerConfig, beforeId);
1562
+ map.addLayer(layerConfig, insertBefore);
1563
+ added = true;
1564
+ lastAppliedPaintRef.current = { ...paint2 };
1565
+ lastAppliedLayoutRef.current = withoutVisibility(layout2);
1508
1566
  setLayerAdded(true);
1509
1567
  } catch (err) {
1510
1568
  console.error(`[maps-react] Failed to add layer "${id}":`, err);
1511
1569
  }
1512
1570
  }
1571
+ restoreLayerRef.current = () => {
1572
+ if (map.getLayer(id) || !map.getSource(source)) return;
1573
+ hoveredFeatureId.current = null;
1574
+ stopWaiting();
1575
+ const above = beforeId ? void 0 : getSourceRegistry(map).layersAbove(source, id).find((layerId) => map.getLayer(layerId));
1576
+ addLayer(beforeId ?? above);
1577
+ };
1578
+ if (map.getSource(source)) {
1579
+ addLayer();
1580
+ } else {
1581
+ timeoutId = setTimeout(() => {
1582
+ if (!map.getSource(source)) {
1583
+ console.warn(
1584
+ `[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.`
1585
+ );
1586
+ }
1587
+ }, 5e3);
1588
+ map.on("sourcedata", checkSource);
1589
+ }
1513
1590
  return () => {
1514
- if (map) {
1591
+ restoreLayerRef.current = null;
1592
+ stopWaiting();
1593
+ if (added) {
1515
1594
  try {
1516
1595
  if (map.getLayer(id)) {
1517
1596
  map.removeLayer(id);
1518
1597
  }
1519
1598
  } catch {
1520
1599
  }
1521
- setLayerAdded(false);
1522
1600
  }
1601
+ setLayerAdded(false);
1523
1602
  };
1524
1603
  }, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
1525
- React26__namespace.useEffect(() => {
1604
+ React6__namespace.useEffect(() => {
1605
+ if (sourceVersion) restoreLayerRef.current?.();
1606
+ }, [sourceVersion]);
1607
+ React6__namespace.useEffect(() => {
1526
1608
  if (!map || !layerAdded) return;
1527
1609
  if (!map.getLayer(id)) return;
1528
1610
  map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1529
1611
  }, [map, id, visible, layerAdded]);
1530
- const lastAppliedPaintRef = React26__namespace.useRef(void 0);
1531
- React26__namespace.useEffect(() => {
1612
+ React6__namespace.useEffect(() => {
1532
1613
  if (!map || !layerAdded) return;
1533
1614
  if (!map.getLayer(id)) return;
1534
1615
  const diff = mapsCore.getChangedPaintProps(lastAppliedPaintRef.current, paint);
@@ -1544,12 +1625,10 @@ function useLayer({
1544
1625
  } catch {
1545
1626
  }
1546
1627
  }, [map, id, paint, layerAdded]);
1547
- const lastAppliedLayoutRef = React26__namespace.useRef(void 0);
1548
- React26__namespace.useEffect(() => {
1628
+ React6__namespace.useEffect(() => {
1549
1629
  if (!map || !layerAdded) return;
1550
1630
  if (!map.getLayer(id)) return;
1551
- const next = { ...layout };
1552
- delete next.visibility;
1631
+ const next = withoutVisibility(layout);
1553
1632
  const diff = mapsCore.getChangedPaintProps(lastAppliedLayoutRef.current, next);
1554
1633
  if (!diff.hasChanges) return;
1555
1634
  try {
@@ -1563,17 +1642,17 @@ function useLayer({
1563
1642
  } catch {
1564
1643
  }
1565
1644
  }, [map, id, layout, layerAdded]);
1566
- React26__namespace.useEffect(() => {
1645
+ React6__namespace.useEffect(() => {
1567
1646
  if (!map || !layerAdded) return;
1568
1647
  if (!map.getLayer(id)) return;
1569
1648
  map.setLayerZoomRange(id, minZoom ?? 0, maxZoom ?? 24);
1570
1649
  }, [map, id, minZoom, maxZoom, layerAdded]);
1571
- React26__namespace.useEffect(() => {
1650
+ React6__namespace.useEffect(() => {
1572
1651
  if (!map || !layerAdded) return;
1573
1652
  if (!map.getLayer(id)) return;
1574
1653
  map.setFilter(id, filter ?? null);
1575
1654
  }, [map, id, filter, layerAdded]);
1576
- React26__namespace.useEffect(() => {
1655
+ React6__namespace.useEffect(() => {
1577
1656
  if (!map || !layerAdded) return;
1578
1657
  const createFeatureParams = (e) => {
1579
1658
  const feature = e.features?.[0];
@@ -1725,7 +1804,7 @@ var FillLayer = ({
1725
1804
  fillTranslate,
1726
1805
  fillAntialias
1727
1806
  }) => {
1728
- const paint = React26__namespace.useMemo(() => {
1807
+ const paint = React6__namespace.useMemo(() => {
1729
1808
  const p = {};
1730
1809
  if (fillColor !== void 0) p["fill-color"] = fillColor;
1731
1810
  if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
@@ -1746,7 +1825,7 @@ var FillLayer = ({
1746
1825
  fillAntialias,
1747
1826
  opacity
1748
1827
  ]);
1749
- const layout = React26__namespace.useMemo(() => ({}), []);
1828
+ const layout = React6__namespace.useMemo(() => ({}), []);
1750
1829
  useLayer({
1751
1830
  id,
1752
1831
  source,
@@ -1790,7 +1869,7 @@ var LineLayer = ({
1790
1869
  lineOffset,
1791
1870
  lineGradient
1792
1871
  }) => {
1793
- const paint = React26__namespace.useMemo(() => {
1872
+ const paint = React6__namespace.useMemo(() => {
1794
1873
  const p = {};
1795
1874
  if (lineColor !== void 0) p["line-color"] = lineColor;
1796
1875
  if (lineWidth !== void 0) p["line-width"] = lineWidth;
@@ -1815,7 +1894,7 @@ var LineLayer = ({
1815
1894
  lineGradient,
1816
1895
  opacity
1817
1896
  ]);
1818
- const layout = React26__namespace.useMemo(() => {
1897
+ const layout = React6__namespace.useMemo(() => {
1819
1898
  const l = {};
1820
1899
  if (lineCap !== void 0) l["line-cap"] = lineCap;
1821
1900
  if (lineJoin !== void 0) l["line-join"] = lineJoin;
@@ -1864,7 +1943,7 @@ var CircleLayer = ({
1864
1943
  circlePitchScale,
1865
1944
  circleTranslate
1866
1945
  }) => {
1867
- const paint = React26__namespace.useMemo(() => {
1946
+ const paint = React6__namespace.useMemo(() => {
1868
1947
  const p = {};
1869
1948
  if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1870
1949
  if (circleColor !== void 0) p["circle-color"] = circleColor;
@@ -1893,7 +1972,7 @@ var CircleLayer = ({
1893
1972
  circleTranslate,
1894
1973
  opacity
1895
1974
  ]);
1896
- const layout = React26__namespace.useMemo(() => ({}), []);
1975
+ const layout = React6__namespace.useMemo(() => ({}), []);
1897
1976
  useLayer({
1898
1977
  id,
1899
1978
  source,
@@ -1953,7 +2032,7 @@ var SymbolLayer = ({
1953
2032
  symbolSpacing,
1954
2033
  symbolSortKey
1955
2034
  }) => {
1956
- const paint = React26__namespace.useMemo(() => {
2035
+ const paint = React6__namespace.useMemo(() => {
1957
2036
  const p = {};
1958
2037
  if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1959
2038
  if (iconColor !== void 0) p["icon-color"] = iconColor;
@@ -1974,7 +2053,7 @@ var SymbolLayer = ({
1974
2053
  textHaloColor,
1975
2054
  textHaloWidth
1976
2055
  ]);
1977
- const layout = React26__namespace.useMemo(() => {
2056
+ const layout = React6__namespace.useMemo(() => {
1978
2057
  const l = {};
1979
2058
  if (iconImage !== void 0) l["icon-image"] = iconImage;
1980
2059
  if (iconSize !== void 0) l["icon-size"] = iconSize;
@@ -2055,7 +2134,7 @@ var FillExtrusionLayer = ({
2055
2134
  fillExtrusionTranslate,
2056
2135
  fillExtrusionVerticalGradient
2057
2136
  }) => {
2058
- const paint = React26__namespace.useMemo(() => {
2137
+ const paint = React6__namespace.useMemo(() => {
2059
2138
  const p = {};
2060
2139
  if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
2061
2140
  if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
@@ -2081,7 +2160,7 @@ var FillExtrusionLayer = ({
2081
2160
  fillExtrusionVerticalGradient,
2082
2161
  opacity
2083
2162
  ]);
2084
- const layout = React26__namespace.useMemo(() => ({}), []);
2163
+ const layout = React6__namespace.useMemo(() => ({}), []);
2085
2164
  useLayer({
2086
2165
  id,
2087
2166
  source,
@@ -2120,7 +2199,7 @@ var HeatmapLayer = ({
2120
2199
  heatmapRadius,
2121
2200
  heatmapOpacity
2122
2201
  }) => {
2123
- const paint = React26__namespace.useMemo(() => {
2202
+ const paint = React6__namespace.useMemo(() => {
2124
2203
  const p = {};
2125
2204
  if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
2126
2205
  if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
@@ -2132,7 +2211,7 @@ var HeatmapLayer = ({
2132
2211
  }
2133
2212
  return p;
2134
2213
  }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
2135
- const layout = React26__namespace.useMemo(() => ({}), []);
2214
+ const layout = React6__namespace.useMemo(() => ({}), []);
2136
2215
  useLayer({
2137
2216
  id,
2138
2217
  source,
@@ -2164,8 +2243,8 @@ function useControlPosition(ref, options) {
2164
2243
  isBuiltIn = false
2165
2244
  } = options;
2166
2245
  const { positioningCoordinator } = useMap();
2167
- const [offset, setOffset] = React26__namespace.useState(null);
2168
- React26__namespace.useEffect(() => {
2246
+ const [offset, setOffset] = React6__namespace.useState(null);
2247
+ React6__namespace.useEffect(() => {
2169
2248
  if (!ref.current || !positioningCoordinator) return;
2170
2249
  const element = ref.current;
2171
2250
  const initialOffset = positioningCoordinator.register({
@@ -2219,7 +2298,7 @@ function useControlPosition(ref, options) {
2219
2298
  positioningCoordinator,
2220
2299
  ref
2221
2300
  ]);
2222
- React26__namespace.useEffect(() => {
2301
+ React6__namespace.useEffect(() => {
2223
2302
  if (!positioningCoordinator) return;
2224
2303
  positioningCoordinator.update(id, {
2225
2304
  position: {
@@ -2230,7 +2309,7 @@ function useControlPosition(ref, options) {
2230
2309
  zLayer
2231
2310
  });
2232
2311
  }, [id, position, fallbacks, priority, zLayer, positioningCoordinator]);
2233
- const setExpanded = React26__namespace.useCallback(
2312
+ const setExpanded = React6__namespace.useCallback(
2234
2313
  (isExpanded) => {
2235
2314
  if (positioningCoordinator) {
2236
2315
  positioningCoordinator.setExpanded(id, isExpanded);
@@ -2238,7 +2317,7 @@ function useControlPosition(ref, options) {
2238
2317
  },
2239
2318
  [id, positioningCoordinator]
2240
2319
  );
2241
- const style = React26__namespace.useMemo(() => {
2320
+ const style = React6__namespace.useMemo(() => {
2242
2321
  if (!offset) {
2243
2322
  return {
2244
2323
  position: "absolute",
@@ -2286,9 +2365,9 @@ var Legend = ({
2286
2365
  class: className,
2287
2366
  onItemClick
2288
2367
  }) => {
2289
- const [isCollapsed, setIsCollapsed] = React26__namespace.useState(initialCollapsed);
2290
- const legendRef = React26__namespace.useRef(null);
2291
- const generatedId = React26__namespace.useId();
2368
+ const [isCollapsed, setIsCollapsed] = React6__namespace.useState(initialCollapsed);
2369
+ const legendRef = React6__namespace.useRef(null);
2370
+ const generatedId = React6__namespace.useId();
2292
2371
  const legendId = `legend-${generatedId}`;
2293
2372
  const { style, visible } = useControlPosition(legendRef, {
2294
2373
  id: legendId,
@@ -2308,7 +2387,7 @@ var Legend = ({
2308
2387
  setIsCollapsed(!isCollapsed);
2309
2388
  }
2310
2389
  };
2311
- const gradientStyle = React26__namespace.useMemo(() => {
2390
+ const gradientStyle = React6__namespace.useMemo(() => {
2312
2391
  if (type !== "gradient" || gradient.length === 0) return "";
2313
2392
  const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
2314
2393
  return `linear-gradient(to right, ${stops})`;
@@ -2409,14 +2488,14 @@ var LegendGroup = ({
2409
2488
  allowCollapseAll = false,
2410
2489
  class: className
2411
2490
  }) => {
2412
- const containerRef = React26__namespace.useRef(null);
2413
- const groupIdRef = React26__namespace.useRef(`legend-group-${++legendGroupIdCounter}`);
2491
+ const containerRef = React6__namespace.useRef(null);
2492
+ const groupIdRef = React6__namespace.useRef(`legend-group-${++legendGroupIdCounter}`);
2414
2493
  const getInitialExpanded = () => {
2415
2494
  if (controlledExpanded !== void 0) return controlledExpanded;
2416
2495
  if (defaultExpanded) return defaultExpanded;
2417
2496
  return legends[0]?.id || null;
2418
2497
  };
2419
- const [internalExpanded, setInternalExpanded] = React26__namespace.useState(getInitialExpanded);
2498
+ const [internalExpanded, setInternalExpanded] = React6__namespace.useState(getInitialExpanded);
2420
2499
  const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
2421
2500
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2422
2501
  id: groupIdRef.current,
@@ -2465,7 +2544,7 @@ var LegendGroup = ({
2465
2544
  type: "button",
2466
2545
  className: cn(
2467
2546
  "w-full flex items-center justify-between px-3 py-2 font-medium text-card-foreground",
2468
- "cursor-pointer hover:bg-muted transition-colors",
2547
+ "cursor-pointer hover:bg-muted",
2469
2548
  isFirst && "rounded-t-lg",
2470
2549
  isLast && !isExpanded && "rounded-b-lg"
2471
2550
  ),
@@ -2562,11 +2641,11 @@ var CoordinateDisplay = ({
2562
2641
  class: className
2563
2642
  }) => {
2564
2643
  const { map, loaded } = useMap();
2565
- const [cursorLngLat, setCursorLngLat] = React26__namespace.useState(null);
2566
- const [currentZoom, setCurrentZoom] = React26__namespace.useState(0);
2567
- const [currentBearing, setCurrentBearing] = React26__namespace.useState(0);
2568
- const controlRef = React26__namespace.useRef(null);
2569
- const uniqueId = React26__namespace.useId();
2644
+ const [cursorLngLat, setCursorLngLat] = React6__namespace.useState(null);
2645
+ const [currentZoom, setCurrentZoom] = React6__namespace.useState(0);
2646
+ const [currentBearing, setCurrentBearing] = React6__namespace.useState(0);
2647
+ const controlRef = React6__namespace.useRef(null);
2648
+ const uniqueId = React6__namespace.useId();
2570
2649
  const controlId = `coord-display${uniqueId}`;
2571
2650
  const { style, visible } = useControlPosition(controlRef, {
2572
2651
  id: controlId,
@@ -2575,7 +2654,7 @@ var CoordinateDisplay = ({
2575
2654
  priority: "critical",
2576
2655
  zLayer: "base"
2577
2656
  });
2578
- const adjustedStyle = React26__namespace.useMemo(() => {
2657
+ const adjustedStyle = React6__namespace.useMemo(() => {
2579
2658
  if (!style) return style;
2580
2659
  if (position === "top-right") {
2581
2660
  const rightOffset = NAV_CONTROL_WIDTH + mapsCore.STACK_GAP + mapsCore.EDGE_MARGIN;
@@ -2595,7 +2674,7 @@ var CoordinateDisplay = ({
2595
2674
  }
2596
2675
  return style;
2597
2676
  }, [position, style]);
2598
- const formatCoord = React26__namespace.useCallback(
2677
+ const formatCoord = React6__namespace.useCallback(
2599
2678
  (lngLat) => {
2600
2679
  return mapsCore.formatCoordinates(lngLat, precision, format);
2601
2680
  },
@@ -2608,7 +2687,7 @@ var CoordinateDisplay = ({
2608
2687
  const normalized = (bearing % 360 + 360) % 360;
2609
2688
  return `${normalized.toFixed(0)}\xB0`;
2610
2689
  };
2611
- React26__namespace.useEffect(() => {
2690
+ React6__namespace.useEffect(() => {
2612
2691
  if (!map || !loaded) return;
2613
2692
  setCurrentZoom(map.getZoom());
2614
2693
  setCurrentBearing(map.getBearing());
@@ -2675,16 +2754,19 @@ var BasemapSwitcher = ({
2675
2754
  class: className
2676
2755
  }) => {
2677
2756
  const { setMapStyle } = useMap();
2678
- const [isOpen, setIsOpen] = React26__namespace.useState(false);
2679
- const [internalActiveId, setInternalActiveId] = React26__namespace.useState(
2757
+ const [isOpen, setIsOpen] = React6__namespace.useState(false);
2758
+ const [internalActiveId, setInternalActiveId] = React6__namespace.useState(
2680
2759
  defaultBasemapId
2681
2760
  );
2682
- const containerRef = React26__namespace.useRef(null);
2683
- const panelRef = React26__namespace.useRef(null);
2684
- const generatedId = React26__namespace.useId();
2761
+ const containerRef = React6__namespace.useRef(null);
2762
+ const panelRef = React6__namespace.useRef(null);
2763
+ const toggleRef = React6__namespace.useRef(null);
2764
+ const optionRefs = React6__namespace.useRef([]);
2765
+ const [tabStopIndex, setTabStopIndex] = React6__namespace.useState(0);
2766
+ const generatedId = React6__namespace.useId();
2685
2767
  const switcherId = `basemap-switcher-${generatedId}`;
2686
2768
  const sourceBasemaps = basemaps ?? mapsCore.FREE_BASEMAPS;
2687
- const availableBasemaps = React26__namespace.useMemo(() => {
2769
+ const availableBasemaps = React6__namespace.useMemo(() => {
2688
2770
  const available = mapsCore.getAvailableBasemaps(sourceBasemaps, apiKeys);
2689
2771
  if (extraBasemaps?.length) {
2690
2772
  return [...available, ...mapsCore.getAvailableBasemaps(extraBasemaps, apiKeys)];
@@ -2692,6 +2774,15 @@ var BasemapSwitcher = ({
2692
2774
  return available;
2693
2775
  }, [sourceBasemaps, extraBasemaps, apiKeys]);
2694
2776
  const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
2777
+ const activeIndex = Math.max(
2778
+ 0,
2779
+ availableBasemaps.findIndex((basemap) => basemap.id === currentActiveId)
2780
+ );
2781
+ React6__namespace.useEffect(() => {
2782
+ if (!isOpen) return;
2783
+ setTabStopIndex(activeIndex);
2784
+ optionRefs.current[activeIndex]?.focus();
2785
+ }, [isOpen]);
2695
2786
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2696
2787
  id: switcherId,
2697
2788
  type: "basemap-switcher",
@@ -2700,7 +2791,7 @@ var BasemapSwitcher = ({
2700
2791
  zLayer: "interactive",
2701
2792
  hasExpandedState: true
2702
2793
  });
2703
- React26__namespace.useEffect(() => {
2794
+ React6__namespace.useEffect(() => {
2704
2795
  if (!isOpen) return;
2705
2796
  const handleMouseDown = (e) => {
2706
2797
  if (containerRef.current && !containerRef.current.contains(e.target)) {
@@ -2711,12 +2802,13 @@ var BasemapSwitcher = ({
2711
2802
  document.addEventListener("mousedown", handleMouseDown);
2712
2803
  return () => document.removeEventListener("mousedown", handleMouseDown);
2713
2804
  }, [isOpen, setExpanded]);
2714
- React26__namespace.useEffect(() => {
2805
+ React6__namespace.useEffect(() => {
2715
2806
  if (!isOpen) return;
2716
2807
  const handleKeyDown = (e) => {
2717
2808
  if (e.key === "Escape") {
2718
2809
  setIsOpen(false);
2719
2810
  setExpanded(false);
2811
+ toggleRef.current?.focus();
2720
2812
  }
2721
2813
  };
2722
2814
  document.addEventListener("keydown", handleKeyDown);
@@ -2737,6 +2829,14 @@ var BasemapSwitcher = ({
2737
2829
  onBasemapChange?.(basemap);
2738
2830
  setIsOpen(false);
2739
2831
  setExpanded(false);
2832
+ toggleRef.current?.focus();
2833
+ };
2834
+ const handleOptionsKeyDown = (e) => {
2835
+ const next = mapsCore.getGridNavigationIndex(e.key, tabStopIndex, availableBasemaps.length, columns);
2836
+ if (next === null) return;
2837
+ e.preventDefault();
2838
+ setTabStopIndex(next);
2839
+ optionRefs.current[next]?.focus();
2740
2840
  };
2741
2841
  const handleToggle = () => {
2742
2842
  const newState = !isOpen;
@@ -2768,25 +2868,32 @@ var BasemapSwitcher = ({
2768
2868
  children: /* @__PURE__ */ jsxRuntime.jsx(
2769
2869
  "div",
2770
2870
  {
2771
- role: "group",
2871
+ role: "radiogroup",
2772
2872
  "aria-label": "Select basemap",
2773
2873
  className: "grid gap-1.5",
2774
2874
  style: {
2775
2875
  gridTemplateColumns: `repeat(${columns}, 1fr)`
2776
2876
  },
2777
- children: availableBasemaps.map((basemap) => {
2877
+ onKeyDown: handleOptionsKeyDown,
2878
+ children: availableBasemaps.map((basemap, index) => {
2778
2879
  const isActive = basemap.id === currentActiveId;
2779
2880
  const thumbUrl = mapsCore.resolveBasemapThumbnail(basemap, apiKeys);
2780
2881
  return /* @__PURE__ */ jsxRuntime.jsxs(
2781
2882
  "button",
2782
2883
  {
2884
+ ref: (el) => {
2885
+ optionRefs.current[index] = el;
2886
+ },
2783
2887
  type: "button",
2784
- "aria-pressed": isActive,
2888
+ role: "radio",
2889
+ "aria-checked": isActive,
2890
+ tabIndex: index === tabStopIndex ? 0 : -1,
2785
2891
  className: cn(
2786
2892
  "flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
2787
- "hover:bg-muted transition-colors",
2893
+ "hover:bg-muted",
2788
2894
  isActive && "ring-2 ring-primary"
2789
2895
  ),
2896
+ onFocus: () => setTabStopIndex(index),
2790
2897
  onClick: () => handleSelect(basemap),
2791
2898
  title: basemap.name,
2792
2899
  children: [
@@ -2816,11 +2923,12 @@ var BasemapSwitcher = ({
2816
2923
  /* @__PURE__ */ jsxRuntime.jsx(
2817
2924
  "button",
2818
2925
  {
2926
+ ref: toggleRef,
2819
2927
  type: "button",
2820
2928
  className: cn(
2821
2929
  "w-[40px] h-[40px] flex items-center justify-center",
2822
2930
  "bg-card rounded shadow-lg border border-black dark:border-gray-400",
2823
- "hover:bg-muted transition-colors cursor-pointer",
2931
+ "hover:bg-muted cursor-pointer",
2824
2932
  "text-foreground"
2825
2933
  ),
2826
2934
  onClick: handleToggle,
@@ -2866,20 +2974,20 @@ var LayerManager = ({
2866
2974
  class: className
2867
2975
  }) => {
2868
2976
  const { isDark } = useMapTheme();
2869
- const [isOpen, setIsOpen] = React26__namespace.useState(false);
2870
- const [layerStates, setLayerStates] = React26__namespace.useState(
2977
+ const [isOpen, setIsOpen] = React6__namespace.useState(false);
2978
+ const [layerStates, setLayerStates] = React6__namespace.useState(
2871
2979
  () => mapsCore.createInitialLayerStates(layers, initialActiveLayers)
2872
2980
  );
2873
- const [searchQuery, setSearchQuery] = React26__namespace.useState("");
2874
- const [activeCategory, setActiveCategory] = React26__namespace.useState("all");
2875
- const [expandedOpacity, setExpandedOpacity] = React26__namespace.useState(null);
2876
- const [draggedId, setDraggedId] = React26__namespace.useState(null);
2877
- const [dragOver, setDragOver] = React26__namespace.useState(null);
2878
- const containerRef = React26__namespace.useRef(null);
2879
- const uniqueId = React26__namespace.useId();
2981
+ const [searchQuery, setSearchQuery] = React6__namespace.useState("");
2982
+ const [activeCategory, setActiveCategory] = React6__namespace.useState("all");
2983
+ const [expandedOpacity, setExpandedOpacity] = React6__namespace.useState(null);
2984
+ const [draggedId, setDraggedId] = React6__namespace.useState(null);
2985
+ const [dragOver, setDragOver] = React6__namespace.useState(null);
2986
+ const containerRef = React6__namespace.useRef(null);
2987
+ const uniqueId = React6__namespace.useId();
2880
2988
  const managerId = `layer-manager${uniqueId}`;
2881
- const lastLayerIdsRef = React26__namespace.useRef(new Set(layers.map((l) => l.id)));
2882
- const tilesCacheRef = React26__namespace.useRef(/* @__PURE__ */ new Map());
2989
+ const lastLayerIdsRef = React6__namespace.useRef(new Set(layers.map((l) => l.id)));
2990
+ const tilesCacheRef = React6__namespace.useRef(/* @__PURE__ */ new Map());
2883
2991
  const getTiles = (url) => {
2884
2992
  let tiles = tilesCacheRef.current.get(url);
2885
2993
  if (!tiles) {
@@ -2896,7 +3004,7 @@ var LayerManager = ({
2896
3004
  zLayer: "interactive",
2897
3005
  hasExpandedState: true
2898
3006
  });
2899
- React26__namespace.useEffect(() => {
3007
+ React6__namespace.useEffect(() => {
2900
3008
  const currentLayerIds = new Set(layers.map((l) => l.id));
2901
3009
  const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
2902
3010
  const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
@@ -2927,8 +3035,8 @@ var LayerManager = ({
2927
3035
  lastLayerIdsRef.current = currentLayerIds;
2928
3036
  }
2929
3037
  }, [layers, initialActiveLayers]);
2930
- const categories = React26__namespace.useMemo(() => mapsCore.getLayerCategories(layers), [layers]);
2931
- const filteredLayers = React26__namespace.useMemo(() => {
3038
+ const categories = React6__namespace.useMemo(() => mapsCore.getLayerCategories(layers), [layers]);
3039
+ const filteredLayers = React6__namespace.useMemo(() => {
2932
3040
  let result = layers;
2933
3041
  if (searchQuery) {
2934
3042
  result = mapsCore.searchLayers(result, searchQuery);
@@ -2942,11 +3050,11 @@ var LayerManager = ({
2942
3050
  return orderA - orderB;
2943
3051
  });
2944
3052
  }, [layers, searchQuery, activeCategory, layerStates]);
2945
- const layerGroups = React26__namespace.useMemo(
3053
+ const layerGroups = React6__namespace.useMemo(
2946
3054
  () => showCategories ? mapsCore.groupLayersByCategory(filteredLayers) : null,
2947
3055
  [filteredLayers, showCategories]
2948
3056
  );
2949
- React26__namespace.useEffect(() => {
3057
+ React6__namespace.useEffect(() => {
2950
3058
  if (!isOpen) return;
2951
3059
  const handleMouseDown = (e) => {
2952
3060
  if (containerRef.current && !containerRef.current.contains(e.target)) {
@@ -2957,7 +3065,7 @@ var LayerManager = ({
2957
3065
  document.addEventListener("mousedown", handleMouseDown);
2958
3066
  return () => document.removeEventListener("mousedown", handleMouseDown);
2959
3067
  }, [isOpen, setExpanded]);
2960
- React26__namespace.useEffect(() => {
3068
+ React6__namespace.useEffect(() => {
2961
3069
  if (!isOpen) return;
2962
3070
  const handleKeyDown = (e) => {
2963
3071
  if (e.key === "Escape") {
@@ -2968,7 +3076,7 @@ var LayerManager = ({
2968
3076
  document.addEventListener("keydown", handleKeyDown);
2969
3077
  return () => document.removeEventListener("keydown", handleKeyDown);
2970
3078
  }, [isOpen, setExpanded]);
2971
- const handleToggleLayer = React26__namespace.useCallback(
3079
+ const handleToggleLayer = React6__namespace.useCallback(
2972
3080
  (layerId) => {
2973
3081
  setLayerStates((prev) => {
2974
3082
  const newStates = mapsCore.toggleLayerVisibility(prev, layerId);
@@ -2981,7 +3089,7 @@ var LayerManager = ({
2981
3089
  },
2982
3090
  [onLayerChange]
2983
3091
  );
2984
- const handleOpacityChange = React26__namespace.useCallback(
3092
+ const handleOpacityChange = React6__namespace.useCallback(
2985
3093
  (layerId, opacity) => {
2986
3094
  setLayerStates((prev) => {
2987
3095
  const newStates = mapsCore.setLayerOpacity(prev, layerId, opacity);
@@ -2994,12 +3102,12 @@ var LayerManager = ({
2994
3102
  },
2995
3103
  [onLayerChange]
2996
3104
  );
2997
- const handleDragStart = React26__namespace.useCallback((e, layerId) => {
3105
+ const handleDragStart = React6__namespace.useCallback((e, layerId) => {
2998
3106
  setDraggedId(layerId);
2999
3107
  e.dataTransfer.effectAllowed = "move";
3000
3108
  e.dataTransfer.setData("text/plain", layerId);
3001
3109
  }, []);
3002
- const handleDragOver = React26__namespace.useCallback(
3110
+ const handleDragOver = React6__namespace.useCallback(
3003
3111
  (e, layerId) => {
3004
3112
  e.preventDefault();
3005
3113
  e.dataTransfer.dropEffect = "move";
@@ -3019,14 +3127,14 @@ var LayerManager = ({
3019
3127
  },
3020
3128
  [draggedId, dragOver]
3021
3129
  );
3022
- const handleDragLeave = React26__namespace.useCallback(() => {
3130
+ const handleDragLeave = React6__namespace.useCallback(() => {
3023
3131
  setDragOver(null);
3024
3132
  }, []);
3025
- const handleDragEnd = React26__namespace.useCallback(() => {
3133
+ const handleDragEnd = React6__namespace.useCallback(() => {
3026
3134
  setDraggedId(null);
3027
3135
  setDragOver(null);
3028
3136
  }, []);
3029
- const handleDrop = React26__namespace.useCallback(
3137
+ const handleDrop = React6__namespace.useCallback(
3030
3138
  (e, targetLayerId) => {
3031
3139
  e.preventDefault();
3032
3140
  const sourceLayerId = e.dataTransfer.getData("text/plain");
@@ -3362,7 +3470,7 @@ var LayerManager = ({
3362
3470
  if (catLayers.length === 0) return null;
3363
3471
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3364
3472
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider", children: mapsCore.CATEGORY_META[cat].label }),
3365
- catLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React26__namespace.Fragment, { children: [
3473
+ catLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React6__namespace.Fragment, { children: [
3366
3474
  renderLayerItem(layer),
3367
3475
  renderOpacitySlider(layer.id)
3368
3476
  ] }, layer.id))
@@ -3370,7 +3478,7 @@ var LayerManager = ({
3370
3478
  })
3371
3479
  ) : (
3372
3480
  // Flat list
3373
- filteredLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React26__namespace.Fragment, { children: [
3481
+ filteredLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React6__namespace.Fragment, { children: [
3374
3482
  renderLayerItem(layer),
3375
3483
  renderOpacitySlider(layer.id)
3376
3484
  ] }, layer.id))
@@ -3387,7 +3495,7 @@ var LayerManager = ({
3387
3495
  className: cn(
3388
3496
  "w-[40px] h-[40px] flex items-center justify-center",
3389
3497
  "bg-card rounded shadow-lg border border-black dark:border-gray-400",
3390
- "hover:bg-muted transition-colors cursor-pointer",
3498
+ "hover:bg-muted cursor-pointer",
3391
3499
  "text-foreground"
3392
3500
  ),
3393
3501
  onClick: handleToggle,
@@ -3431,8 +3539,8 @@ var CustomControl = ({
3431
3539
  style: userStyle,
3432
3540
  children
3433
3541
  }) => {
3434
- const controlRef = React26__namespace.useRef(null);
3435
- const generatedId = React26__namespace.useId();
3542
+ const controlRef = React6__namespace.useRef(null);
3543
+ const generatedId = React6__namespace.useId();
3436
3544
  const controlId = id ?? `custom-control-${generatedId}`;
3437
3545
  const { style, visible, setExpanded } = useControlPosition(controlRef, {
3438
3546
  id: controlId,
@@ -3443,14 +3551,14 @@ var CustomControl = ({
3443
3551
  zLayer,
3444
3552
  hasExpandedState
3445
3553
  });
3446
- const mergedStyle = React26__namespace.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
3447
- const contextValue = React26__namespace.useMemo(() => ({ setExpanded }), [setExpanded]);
3554
+ const mergedStyle = React6__namespace.useMemo(() => ({ ...style, ...userStyle }), [style, userStyle]);
3555
+ const contextValue = React6__namespace.useMemo(() => ({ setExpanded }), [setExpanded]);
3448
3556
  return /* @__PURE__ */ jsxRuntime.jsx(CustomControlContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: controlRef, className: cn(!visible && "invisible", className), style: mergedStyle, children }) });
3449
3557
  };
3450
3558
  CustomControl.displayName = "CustomControl";
3451
- var CustomControlContext = React26__namespace.createContext(null);
3559
+ var CustomControlContext = React6__namespace.createContext(null);
3452
3560
  function useCustomControl() {
3453
- const context = React26__namespace.useContext(CustomControlContext);
3561
+ const context = React6__namespace.useContext(CustomControlContext);
3454
3562
  if (!context) {
3455
3563
  throw new Error("useCustomControl must be used within a CustomControl");
3456
3564
  }
@@ -3466,11 +3574,11 @@ var DeckOverlay = ({
3466
3574
  deckProps = {}
3467
3575
  }) => {
3468
3576
  const { map, loaded } = useMap();
3469
- const overlayRef = React26__namespace.useRef(null);
3470
- const MapboxOverlayRef = React26__namespace.useRef(null);
3471
- const layersRef = React26__namespace.useRef(layers);
3577
+ const overlayRef = React6__namespace.useRef(null);
3578
+ const MapboxOverlayRef = React6__namespace.useRef(null);
3579
+ const layersRef = React6__namespace.useRef(layers);
3472
3580
  layersRef.current = layers;
3473
- React26__namespace.useEffect(() => {
3581
+ React6__namespace.useEffect(() => {
3474
3582
  if (!map || !loaded) return;
3475
3583
  let cancelled = false;
3476
3584
  const initOverlay = async () => {
@@ -3510,12 +3618,12 @@ var DeckOverlay = ({
3510
3618
  }
3511
3619
  };
3512
3620
  }, [map, loaded, interleaved]);
3513
- React26__namespace.useEffect(() => {
3621
+ React6__namespace.useEffect(() => {
3514
3622
  if (overlayRef.current && "setProps" in overlayRef.current) {
3515
3623
  overlayRef.current.setProps({ layers });
3516
3624
  }
3517
3625
  }, [layers]);
3518
- React26__namespace.useEffect(() => {
3626
+ React6__namespace.useEffect(() => {
3519
3627
  if (overlayRef.current && "setProps" in overlayRef.current) {
3520
3628
  overlayRef.current.setProps({
3521
3629
  onHover,
@@ -3524,7 +3632,7 @@ var DeckOverlay = ({
3524
3632
  });
3525
3633
  }
3526
3634
  }, [onHover, onClick, getCursor]);
3527
- React26__namespace.useEffect(() => {
3635
+ React6__namespace.useEffect(() => {
3528
3636
  if (overlayRef.current && effects && "setProps" in overlayRef.current) {
3529
3637
  overlayRef.current.setProps({ effects });
3530
3638
  }