@classic-homes/maps-react 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React25 = require('react');
3
+ var React26 = require('react');
4
4
  var clsx = require('clsx');
5
5
  var tailwindMerge = require('tailwind-merge');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
35
35
  return Object.freeze(n);
36
36
  }
37
37
 
38
- var React25__namespace = /*#__PURE__*/_interopNamespace(React25);
38
+ var React26__namespace = /*#__PURE__*/_interopNamespace(React26);
39
39
  var maplibregl__default = /*#__PURE__*/_interopDefault(maplibregl);
40
40
  var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
41
41
 
@@ -43,7 +43,7 @@ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
43
43
  function cn(...inputs) {
44
44
  return tailwindMerge.twMerge(clsx.clsx(inputs));
45
45
  }
46
- var MapSkeleton = React25__namespace.forwardRef(
46
+ var MapSkeleton = React26__namespace.forwardRef(
47
47
  ({ height = 400, className, ...props }, ref) => {
48
48
  const heightStyle = typeof height === "number" ? `${height}px` : height;
49
49
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -97,7 +97,7 @@ var MapSkeleton = React25__namespace.forwardRef(
97
97
  }
98
98
  );
99
99
  MapSkeleton.displayName = "MapSkeleton";
100
- var MapError = React25__namespace.forwardRef(
100
+ var MapError = React26__namespace.forwardRef(
101
101
  ({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
102
102
  const heightStyle = typeof height === "number" ? `${height}px` : height;
103
103
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -153,7 +153,7 @@ var MapError = React25__namespace.forwardRef(
153
153
  }
154
154
  );
155
155
  MapError.displayName = "MapError";
156
- var MapEmpty = React25__namespace.forwardRef(
156
+ var MapEmpty = React26__namespace.forwardRef(
157
157
  ({ message = "No map data to display", height = 400, className, ...props }, ref) => {
158
158
  const heightStyle = typeof height === "number" ? `${height}px` : height;
159
159
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -196,7 +196,7 @@ var MapEmpty = React25__namespace.forwardRef(
196
196
  }
197
197
  );
198
198
  MapEmpty.displayName = "MapEmpty";
199
- var MapContainer = React25__namespace.forwardRef(
199
+ var MapContainer = React26__namespace.forwardRef(
200
200
  ({
201
201
  title,
202
202
  description,
@@ -245,8 +245,8 @@ var MapContainer = React25__namespace.forwardRef(
245
245
  );
246
246
  MapContainer.displayName = "MapContainer";
247
247
  function useMapTheme(preference = "auto") {
248
- const [isDark, setIsDark] = React25.useState(false);
249
- const updateTheme = React25.useCallback(() => {
248
+ const [isDark, setIsDark] = React26.useState(false);
249
+ const updateTheme = React26.useCallback(() => {
250
250
  if (preference !== "auto") {
251
251
  setIsDark(preference === "dark");
252
252
  return;
@@ -256,7 +256,7 @@ function useMapTheme(preference = "auto") {
256
256
  setIsDark(hasDarkClass);
257
257
  }
258
258
  }, [preference]);
259
- React25.useEffect(() => {
259
+ React26.useEffect(() => {
260
260
  updateTheme();
261
261
  if (preference !== "auto" || typeof document === "undefined") return;
262
262
  const observer = new MutationObserver((mutations) => {
@@ -286,8 +286,8 @@ function useMapTheme(preference = "auto") {
286
286
  };
287
287
  }
288
288
  function useReducedMotion() {
289
- const [prefersReducedMotion2, setPrefersReducedMotion] = React25.useState(false);
290
- React25.useEffect(() => {
289
+ const [prefersReducedMotion2, setPrefersReducedMotion] = React26.useState(false);
290
+ React26.useEffect(() => {
291
291
  if (typeof window === "undefined") return;
292
292
  const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
293
293
  setPrefersReducedMotion(mediaQuery.matches);
@@ -301,9 +301,9 @@ function useReducedMotion() {
301
301
  }, []);
302
302
  return prefersReducedMotion2;
303
303
  }
304
- var MapContext = React25__namespace.createContext(null);
304
+ var MapContext = React26__namespace.createContext(null);
305
305
  function useMap() {
306
- const context = React25__namespace.useContext(MapContext);
306
+ const context = React26__namespace.useContext(MapContext);
307
307
  if (!context) {
308
308
  throw new Error("useMap must be used within a Map component");
309
309
  }
@@ -313,7 +313,7 @@ function useMapInstance() {
313
313
  const { map, loaded } = useMap();
314
314
  return loaded ? map : null;
315
315
  }
316
- var Map2 = React25__namespace.forwardRef(
316
+ var Map2 = React26__namespace.forwardRef(
317
317
  ({
318
318
  // Base props
319
319
  title,
@@ -367,108 +367,56 @@ var Map2 = React25__namespace.forwardRef(
367
367
  onZoom,
368
368
  onError
369
369
  }, ref) => {
370
- const containerRef = React25__namespace.useRef(null);
371
- const mapRef = React25__namespace.useRef(null);
372
- const [mapLoaded, setMapLoaded] = React25__namespace.useState(false);
373
- const [mapError, setMapError] = React25__namespace.useState(null);
374
- const [styleVersion, setStyleVersion] = React25__namespace.useState(0);
375
- const activeStyleOverrideRef = React25__namespace.useRef(
370
+ const containerRef = React26__namespace.useRef(null);
371
+ const mapRef = React26__namespace.useRef(null);
372
+ const [mapLoaded, setMapLoaded] = React26__namespace.useState(false);
373
+ const [mapError, setMapError] = React26__namespace.useState(null);
374
+ const [styleVersion, setStyleVersion] = React26__namespace.useState(0);
375
+ const activeStyleOverrideRef = React26__namespace.useRef(
376
376
  null
377
377
  );
378
- const setMapStyle = React25__namespace.useCallback((style) => {
378
+ const positioningCoordinatorRef = React26__namespace.useRef(null);
379
+ if (!positioningCoordinatorRef.current) {
380
+ positioningCoordinatorRef.current = mapsCore.createPositioningCoordinator();
381
+ }
382
+ const positioningCoordinator = positioningCoordinatorRef.current;
383
+ const setMapStyle = React26__namespace.useCallback((style) => {
379
384
  activeStyleOverrideRef.current = style;
380
385
  mapRef.current?.setStyle(style);
381
386
  }, []);
382
- const customControlRegistryRef = React25__namespace.useRef({
383
- "top-left": [],
384
- "top-right": [],
385
- "bottom-left": [],
386
- "bottom-right": []
387
- });
388
- const [, forceUpdate] = React25__namespace.useReducer((x) => x + 1, 0);
389
387
  const prefersReducedMotion2 = useReducedMotion();
390
388
  const { style: themeStyle } = useMapTheme(themePref);
391
- const onLoadRef = React25__namespace.useRef(onLoad);
389
+ const onLoadRef = React26__namespace.useRef(onLoad);
392
390
  onLoadRef.current = onLoad;
393
- const onErrorRef = React25__namespace.useRef(onError);
391
+ const onErrorRef = React26__namespace.useRef(onError);
394
392
  onErrorRef.current = onError;
395
393
  const mapStyle = customStyle || themeStyle;
396
- const controlOffsets = React25__namespace.useMemo(() => {
397
- const offsets = {
398
- "top-left": 0,
399
- "top-right": 0,
400
- "bottom-left": 0,
401
- "bottom-right": 0
402
- };
403
- if (navigationControl) {
404
- offsets[navigationControlPosition] += 100;
405
- }
406
- if (scaleControl) {
407
- offsets[scaleControlPosition] += 28;
408
- }
409
- if (fullscreenControl) {
410
- offsets[fullscreenControlPosition] += 38;
411
- }
412
- if (geolocateControl) {
413
- offsets[geolocateControlPosition] += 38;
414
- }
415
- if (attributionControl) {
416
- offsets["bottom-right"] += 32;
417
- }
418
- return offsets;
419
- }, [
420
- navigationControl,
421
- navigationControlPosition,
422
- scaleControl,
423
- scaleControlPosition,
424
- fullscreenControl,
425
- fullscreenControlPosition,
426
- geolocateControl,
427
- geolocateControlPosition,
428
- attributionControl
429
- ]);
430
- const registerControl = React25__namespace.useCallback(
431
- (id, position, height2) => {
432
- const registry = customControlRegistryRef.current;
433
- const positionControls = registry[position] || [];
434
- const existingIndex = positionControls.findIndex((c) => c.id === id);
435
- if (existingIndex >= 0) {
436
- positionControls[existingIndex].height = height2;
437
- } else {
438
- positionControls.push({ id, height: height2 });
439
- forceUpdate();
440
- }
441
- registry[position] = positionControls;
442
- let offset = 0;
443
- for (const control of positionControls) {
444
- if (control.id === id) break;
445
- offset += control.height + 8;
446
- }
447
- return offset;
448
- },
449
- []
450
- );
451
- const unregisterControl = React25__namespace.useCallback((id, position) => {
452
- const registry = customControlRegistryRef.current;
453
- const positionControls = registry[position] || [];
454
- registry[position] = positionControls.filter((c) => c.id !== id);
455
- forceUpdate();
456
- }, []);
457
- const getCustomControlOffset = React25__namespace.useCallback((id, position) => {
458
- const registry = customControlRegistryRef.current;
459
- const positionControls = registry[position] || [];
460
- let offset = 0;
461
- for (const control of positionControls) {
462
- if (control.id === id) break;
463
- offset += control.height + 8;
464
- }
465
- return offset;
466
- }, []);
467
394
  const accessibleDescription = description || mapsCore.generateMapDescription(title, {
468
395
  center,
469
396
  zoom
470
397
  });
471
- React25__namespace.useEffect(() => {
398
+ React26__namespace.useEffect(() => {
399
+ if (!containerRef.current || !positioningCoordinator) return;
400
+ const updateDimensions = () => {
401
+ if (!containerRef.current) return;
402
+ positioningCoordinator.setMapDimensions({
403
+ width: containerRef.current.offsetWidth,
404
+ height: containerRef.current.offsetHeight
405
+ });
406
+ };
407
+ updateDimensions();
408
+ const resizeObserver = new ResizeObserver(updateDimensions);
409
+ resizeObserver.observe(containerRef.current);
410
+ return () => {
411
+ resizeObserver.disconnect();
412
+ };
413
+ }, [positioningCoordinator]);
414
+ React26__namespace.useEffect(() => {
415
+ return () => {
416
+ positioningCoordinator.destroy();
417
+ };
418
+ }, [positioningCoordinator]);
419
+ React26__namespace.useEffect(() => {
472
420
  if (!containerRef.current || mapRef.current) return;
473
421
  try {
474
422
  const map = new maplibregl__default.default.Map({
@@ -503,12 +451,45 @@ var Map2 = React25__namespace.forwardRef(
503
451
  }),
504
452
  navigationControlPosition
505
453
  );
454
+ positioningCoordinator.register({
455
+ id: "maplibre-navigation-control",
456
+ type: "navigation",
457
+ isBuiltIn: true,
458
+ dimensions: { width: 29, height: 91 },
459
+ position: {
460
+ primary: navigationControlPosition
461
+ },
462
+ priority: "critical",
463
+ zLayer: "base"
464
+ });
506
465
  }
507
466
  if (scaleControl) {
508
467
  map.addControl(new maplibregl__default.default.ScaleControl({ unit: "metric" }), scaleControlPosition);
468
+ positioningCoordinator.register({
469
+ id: "maplibre-scale-control",
470
+ type: "scale",
471
+ isBuiltIn: true,
472
+ dimensions: { width: 100, height: 20 },
473
+ position: {
474
+ primary: scaleControlPosition
475
+ },
476
+ priority: "critical",
477
+ zLayer: "base"
478
+ });
509
479
  }
510
480
  if (fullscreenControl) {
511
481
  map.addControl(new maplibregl__default.default.FullscreenControl(), fullscreenControlPosition);
482
+ positioningCoordinator.register({
483
+ id: "maplibre-fullscreen-control",
484
+ type: "custom",
485
+ isBuiltIn: true,
486
+ dimensions: { width: 29, height: 29 },
487
+ position: {
488
+ primary: fullscreenControlPosition
489
+ },
490
+ priority: "critical",
491
+ zLayer: "base"
492
+ });
512
493
  }
513
494
  if (geolocateControl) {
514
495
  map.addControl(
@@ -518,6 +499,17 @@ var Map2 = React25__namespace.forwardRef(
518
499
  }),
519
500
  geolocateControlPosition
520
501
  );
502
+ positioningCoordinator.register({
503
+ id: "maplibre-geolocate-control",
504
+ type: "custom",
505
+ isBuiltIn: true,
506
+ dimensions: { width: 29, height: 29 },
507
+ position: {
508
+ primary: geolocateControlPosition
509
+ },
510
+ priority: "critical",
511
+ zLayer: "base"
512
+ });
521
513
  }
522
514
  map.on("load", () => {
523
515
  setMapLoaded(true);
@@ -548,8 +540,8 @@ var Map2 = React25__namespace.forwardRef(
548
540
  onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
549
541
  }
550
542
  }, []);
551
- const styleInitialized = React25__namespace.useRef(false);
552
- React25__namespace.useEffect(() => {
543
+ const styleInitialized = React26__namespace.useRef(false);
544
+ React26__namespace.useEffect(() => {
553
545
  if (!mapRef.current || !mapLoaded) return;
554
546
  if (!styleInitialized.current) {
555
547
  styleInitialized.current = true;
@@ -558,12 +550,12 @@ var Map2 = React25__namespace.forwardRef(
558
550
  if (activeStyleOverrideRef.current) return;
559
551
  mapRef.current.setStyle(mapStyle);
560
552
  }, [mapStyle, mapLoaded]);
561
- React25__namespace.useEffect(() => {
553
+ React26__namespace.useEffect(() => {
562
554
  if (customStyle) {
563
555
  activeStyleOverrideRef.current = null;
564
556
  }
565
557
  }, [customStyle]);
566
- React25__namespace.useEffect(() => {
558
+ React26__namespace.useEffect(() => {
567
559
  const map = mapRef.current;
568
560
  if (!map || !mapLoaded) return;
569
561
  const createEventParams = (e) => ({
@@ -680,12 +672,9 @@ var Map2 = React25__namespace.forwardRef(
680
672
  value: {
681
673
  map: mapRef.current,
682
674
  loaded: mapLoaded,
683
- controlOffsets,
684
- registerControl,
685
- unregisterControl,
686
- getCustomControlOffset,
687
675
  styleVersion,
688
- setMapStyle
676
+ setMapStyle,
677
+ positioningCoordinator
689
678
  },
690
679
  children: [
691
680
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: "absolute inset-0" }),
@@ -718,9 +707,9 @@ var Source = ({
718
707
  children
719
708
  }) => {
720
709
  const { map, loaded, styleVersion } = useMap();
721
- const sourceAdded = React25__namespace.useRef(false);
722
- const initialFitDone = React25__namespace.useRef(false);
723
- const fitBoundsParamsRef = React25__namespace.useRef({
710
+ const sourceAdded = React26__namespace.useRef(false);
711
+ const initialFitDone = React26__namespace.useRef(false);
712
+ const fitBoundsParamsRef = React26__namespace.useRef({
724
713
  shouldFitBounds,
725
714
  data,
726
715
  fitBoundsPadding,
@@ -736,7 +725,7 @@ var Source = ({
736
725
  fitBoundsAnimate,
737
726
  type
738
727
  };
739
- const performFitBounds = React25__namespace.useCallback(
728
+ const performFitBounds = React26__namespace.useCallback(
740
729
  (cancelledRef) => {
741
730
  const params = fitBoundsParamsRef.current;
742
731
  if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
@@ -780,7 +769,7 @@ var Source = ({
780
769
  },
781
770
  [map]
782
771
  );
783
- React25__namespace.useEffect(() => {
772
+ React26__namespace.useEffect(() => {
784
773
  if (!map || !loaded || sourceAdded.current) return;
785
774
  if (map.getSource(id)) {
786
775
  sourceAdded.current = true;
@@ -930,7 +919,7 @@ var Source = ({
930
919
  styleVersion
931
920
  // re-add source after basemap style changes
932
921
  ]);
933
- React25__namespace.useEffect(() => {
922
+ React26__namespace.useEffect(() => {
934
923
  if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
935
924
  const source = map.getSource(id);
936
925
  if (!source) return;
@@ -962,7 +951,7 @@ var Source = ({
962
951
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
963
952
  };
964
953
  Source.displayName = "Source";
965
- var Marker = React25__namespace.forwardRef(
954
+ var Marker = React26__namespace.forwardRef(
966
955
  ({
967
956
  id,
968
957
  coordinates,
@@ -978,27 +967,27 @@ var Marker = React25__namespace.forwardRef(
978
967
  children
979
968
  }, ref) => {
980
969
  const { map, loaded } = useMap();
981
- const markerRef = React25__namespace.useRef(null);
982
- const elementRef = React25__namespace.useRef(null);
983
- const originalLngLatRef = React25__namespace.useRef();
984
- const clickHandlerRef = React25__namespace.useRef(null);
985
- const [mounted, setMounted] = React25__namespace.useState(false);
986
- const onClickRef = React25__namespace.useRef(onClick);
970
+ const markerRef = React26__namespace.useRef(null);
971
+ const elementRef = React26__namespace.useRef(null);
972
+ const originalLngLatRef = React26__namespace.useRef();
973
+ const clickHandlerRef = React26__namespace.useRef(null);
974
+ const [mounted, setMounted] = React26__namespace.useState(false);
975
+ const onClickRef = React26__namespace.useRef(onClick);
987
976
  onClickRef.current = onClick;
988
- const onDragRef = React25__namespace.useRef(onDrag);
977
+ const onDragRef = React26__namespace.useRef(onDrag);
989
978
  onDragRef.current = onDrag;
990
- const onDragEndRef = React25__namespace.useRef(onDragEnd);
979
+ const onDragEndRef = React26__namespace.useRef(onDragEnd);
991
980
  onDragEndRef.current = onDragEnd;
992
- React25__namespace.useEffect(() => {
981
+ React26__namespace.useEffect(() => {
993
982
  setMounted(true);
994
983
  return () => setMounted(false);
995
984
  }, []);
996
- React25__namespace.useEffect(() => {
985
+ React26__namespace.useEffect(() => {
997
986
  if (children && !elementRef.current) {
998
987
  elementRef.current = document.createElement("div");
999
988
  }
1000
989
  }, [children]);
1001
- React25__namespace.useEffect(() => {
990
+ React26__namespace.useEffect(() => {
1002
991
  if (!map || !loaded || !mounted) return;
1003
992
  if (markerRef.current) return;
1004
993
  const markerOptions = {
@@ -1082,17 +1071,17 @@ var Marker = React25__namespace.forwardRef(
1082
1071
  }
1083
1072
  };
1084
1073
  }, [map, loaded, mounted]);
1085
- React25__namespace.useEffect(() => {
1074
+ React26__namespace.useEffect(() => {
1086
1075
  if (markerRef.current) {
1087
1076
  markerRef.current.setLngLat(coordinates);
1088
1077
  }
1089
1078
  }, [coordinates]);
1090
- React25__namespace.useEffect(() => {
1079
+ React26__namespace.useEffect(() => {
1091
1080
  if (markerRef.current) {
1092
1081
  markerRef.current.setDraggable(draggable);
1093
1082
  }
1094
1083
  }, [draggable]);
1095
- React25__namespace.useEffect(() => {
1084
+ React26__namespace.useEffect(() => {
1096
1085
  if (markerRef.current && rotation !== void 0) {
1097
1086
  markerRef.current.setRotation(rotation);
1098
1087
  }
@@ -1138,7 +1127,7 @@ function panToFitPopup(map, popup, padding) {
1138
1127
  });
1139
1128
  }
1140
1129
  }
1141
- var Popup = React25__namespace.forwardRef(
1130
+ var Popup = React26__namespace.forwardRef(
1142
1131
  ({
1143
1132
  coordinates,
1144
1133
  closeButton = true,
@@ -1156,25 +1145,25 @@ var Popup = React25__namespace.forwardRef(
1156
1145
  children
1157
1146
  }, ref) => {
1158
1147
  const { map, loaded } = useMap();
1159
- const popupRef = React25__namespace.useRef(null);
1160
- const onOpenRef = React25__namespace.useRef(onOpen);
1148
+ const popupRef = React26__namespace.useRef(null);
1149
+ const onOpenRef = React26__namespace.useRef(onOpen);
1161
1150
  onOpenRef.current = onOpen;
1162
- const onCloseRef = React25__namespace.useRef(onClose);
1151
+ const onCloseRef = React26__namespace.useRef(onClose);
1163
1152
  onCloseRef.current = onClose;
1164
- const coordinatesRef = React25__namespace.useRef(coordinates);
1153
+ const coordinatesRef = React26__namespace.useRef(coordinates);
1165
1154
  coordinatesRef.current = coordinates;
1166
- const containerRef = React25__namespace.useRef(null);
1155
+ const containerRef = React26__namespace.useRef(null);
1167
1156
  if (!containerRef.current && typeof document !== "undefined") {
1168
1157
  containerRef.current = document.createElement("div");
1169
1158
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1170
1159
  }
1171
- const [contentReady, setContentReady] = React25__namespace.useState(false);
1172
- const contentCallbackRef = React25__namespace.useCallback((node) => {
1160
+ const [contentReady, setContentReady] = React26__namespace.useState(false);
1161
+ const contentCallbackRef = React26__namespace.useCallback((node) => {
1173
1162
  if (node && containerRef.current) {
1174
1163
  setContentReady(true);
1175
1164
  }
1176
1165
  }, []);
1177
- React25__namespace.useEffect(() => {
1166
+ React26__namespace.useEffect(() => {
1178
1167
  if (!map || !loaded || !containerRef.current) return;
1179
1168
  const popup = new maplibregl__default.default.Popup({
1180
1169
  closeButton,
@@ -1214,7 +1203,7 @@ var Popup = React25__namespace.forwardRef(
1214
1203
  maxWidth,
1215
1204
  focusAfterOpen
1216
1205
  ]);
1217
- React25__namespace.useEffect(() => {
1206
+ React26__namespace.useEffect(() => {
1218
1207
  if (!popupRef.current || !ref) return;
1219
1208
  if (typeof ref === "function") {
1220
1209
  ref(popupRef.current);
@@ -1222,12 +1211,12 @@ var Popup = React25__namespace.forwardRef(
1222
1211
  ref.current = popupRef.current;
1223
1212
  }
1224
1213
  }, [ref]);
1225
- React25__namespace.useEffect(() => {
1214
+ React26__namespace.useEffect(() => {
1226
1215
  if (popupRef.current) {
1227
1216
  popupRef.current.setLngLat(coordinates);
1228
1217
  }
1229
1218
  }, [coordinates]);
1230
- React25__namespace.useEffect(() => {
1219
+ React26__namespace.useEffect(() => {
1231
1220
  if (!map || !popupRef.current || !contentReady) return;
1232
1221
  let rafHandle;
1233
1222
  if (open) {
@@ -1256,7 +1245,7 @@ var Popup = React25__namespace.forwardRef(
1256
1245
  }
1257
1246
  );
1258
1247
  Popup.displayName = "Popup";
1259
- var PopupCard = React25__namespace.forwardRef(
1248
+ var PopupCard = React26__namespace.forwardRef(
1260
1249
  ({ className, children, ...props }, ref) => {
1261
1250
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
1262
1251
  }
@@ -1276,7 +1265,7 @@ var badgeVariants = classVarianceAuthority.cva("text-xs px-1.5 py-0.5 rounded fo
1276
1265
  badgeVariant: "secondary"
1277
1266
  }
1278
1267
  });
1279
- var PopupHeader = React25__namespace.forwardRef(
1268
+ var PopupHeader = React26__namespace.forwardRef(
1280
1269
  ({ className, title, badge, badgeVariant, ...props }, ref) => {
1281
1270
  return /* @__PURE__ */ jsxRuntime.jsxs(
1282
1271
  "div",
@@ -1296,13 +1285,13 @@ var PopupHeader = React25__namespace.forwardRef(
1296
1285
  }
1297
1286
  );
1298
1287
  PopupHeader.displayName = "PopupHeader";
1299
- var PopupContent = React25__namespace.forwardRef(
1288
+ var PopupContent = React26__namespace.forwardRef(
1300
1289
  ({ className, children, ...props }, ref) => {
1301
1290
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
1302
1291
  }
1303
1292
  );
1304
1293
  PopupContent.displayName = "PopupContent";
1305
- var PopupFooter = React25__namespace.forwardRef(
1294
+ var PopupFooter = React26__namespace.forwardRef(
1306
1295
  ({ className, children, ...props }, ref) => {
1307
1296
  return /* @__PURE__ */ jsxRuntime.jsx(
1308
1297
  "div",
@@ -1337,14 +1326,14 @@ function useLayer({
1337
1326
  hoverThrottleMs = 0
1338
1327
  }) {
1339
1328
  const { map, loaded, styleVersion } = useMap();
1340
- const [layerAdded, setLayerAdded] = React25__namespace.useState(false);
1341
- const hoveredFeatureId = React25__namespace.useRef(null);
1342
- const lastHoverCallTime = React25__namespace.useRef(0);
1343
- const lastMousePosition = React25__namespace.useRef(null);
1344
- React25__namespace.useEffect(() => {
1329
+ const [layerAdded, setLayerAdded] = React26__namespace.useState(false);
1330
+ const hoveredFeatureId = React26__namespace.useRef(null);
1331
+ const lastHoverCallTime = React26__namespace.useRef(0);
1332
+ const lastMousePosition = React26__namespace.useRef(null);
1333
+ React26__namespace.useEffect(() => {
1345
1334
  hoveredFeatureId.current = null;
1346
1335
  }, [styleVersion]);
1347
- React25__namespace.useEffect(() => {
1336
+ React26__namespace.useEffect(() => {
1348
1337
  if (!map || !loaded) return;
1349
1338
  if (!map.getSource(source)) {
1350
1339
  let timeoutId = null;
@@ -1415,24 +1404,24 @@ function useLayer({
1415
1404
  }
1416
1405
  };
1417
1406
  }, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
1418
- React25__namespace.useEffect(() => {
1407
+ React26__namespace.useEffect(() => {
1419
1408
  if (!map || !layerAdded) return;
1420
1409
  if (!map.getLayer(id)) return;
1421
1410
  map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1422
1411
  }, [map, id, visible, layerAdded]);
1423
- React25__namespace.useEffect(() => {
1412
+ React26__namespace.useEffect(() => {
1424
1413
  if (!map || !layerAdded) return;
1425
1414
  if (!map.getLayer(id)) return;
1426
1415
  Object.entries(paint).forEach(([key, value]) => {
1427
1416
  map.setPaintProperty(id, key, value);
1428
1417
  });
1429
1418
  }, [map, id, paint, layerAdded]);
1430
- React25__namespace.useEffect(() => {
1419
+ React26__namespace.useEffect(() => {
1431
1420
  if (!map || !layerAdded || !filter) return;
1432
1421
  if (!map.getLayer(id)) return;
1433
1422
  map.setFilter(id, filter);
1434
1423
  }, [map, id, filter, layerAdded]);
1435
- React25__namespace.useEffect(() => {
1424
+ React26__namespace.useEffect(() => {
1436
1425
  if (!map || !layerAdded) return;
1437
1426
  const createFeatureParams = (e) => {
1438
1427
  const feature = e.features?.[0];
@@ -1568,7 +1557,7 @@ var FillLayer = ({
1568
1557
  fillTranslate,
1569
1558
  fillAntialias
1570
1559
  }) => {
1571
- const paint = React25__namespace.useMemo(() => {
1560
+ const paint = React26__namespace.useMemo(() => {
1572
1561
  const p = {};
1573
1562
  if (fillColor !== void 0) p["fill-color"] = fillColor;
1574
1563
  if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
@@ -1589,7 +1578,7 @@ var FillLayer = ({
1589
1578
  fillAntialias,
1590
1579
  opacity
1591
1580
  ]);
1592
- const layout = React25__namespace.useMemo(() => ({}), []);
1581
+ const layout = React26__namespace.useMemo(() => ({}), []);
1593
1582
  useLayer({
1594
1583
  id,
1595
1584
  source,
@@ -1633,7 +1622,7 @@ var LineLayer = ({
1633
1622
  lineOffset,
1634
1623
  lineGradient
1635
1624
  }) => {
1636
- const paint = React25__namespace.useMemo(() => {
1625
+ const paint = React26__namespace.useMemo(() => {
1637
1626
  const p = {};
1638
1627
  if (lineColor !== void 0) p["line-color"] = lineColor;
1639
1628
  if (lineWidth !== void 0) p["line-width"] = lineWidth;
@@ -1658,7 +1647,7 @@ var LineLayer = ({
1658
1647
  lineGradient,
1659
1648
  opacity
1660
1649
  ]);
1661
- const layout = React25__namespace.useMemo(() => {
1650
+ const layout = React26__namespace.useMemo(() => {
1662
1651
  const l = {};
1663
1652
  if (lineCap !== void 0) l["line-cap"] = lineCap;
1664
1653
  if (lineJoin !== void 0) l["line-join"] = lineJoin;
@@ -1707,7 +1696,7 @@ var CircleLayer = ({
1707
1696
  circlePitchScale,
1708
1697
  circleTranslate
1709
1698
  }) => {
1710
- const paint = React25__namespace.useMemo(() => {
1699
+ const paint = React26__namespace.useMemo(() => {
1711
1700
  const p = {};
1712
1701
  if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1713
1702
  if (circleColor !== void 0) p["circle-color"] = circleColor;
@@ -1736,7 +1725,7 @@ var CircleLayer = ({
1736
1725
  circleTranslate,
1737
1726
  opacity
1738
1727
  ]);
1739
- const layout = React25__namespace.useMemo(() => ({}), []);
1728
+ const layout = React26__namespace.useMemo(() => ({}), []);
1740
1729
  useLayer({
1741
1730
  id,
1742
1731
  source,
@@ -1796,7 +1785,7 @@ var SymbolLayer = ({
1796
1785
  symbolSpacing,
1797
1786
  symbolSortKey
1798
1787
  }) => {
1799
- const paint = React25__namespace.useMemo(() => {
1788
+ const paint = React26__namespace.useMemo(() => {
1800
1789
  const p = {};
1801
1790
  if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1802
1791
  if (iconColor !== void 0) p["icon-color"] = iconColor;
@@ -1817,7 +1806,7 @@ var SymbolLayer = ({
1817
1806
  textHaloColor,
1818
1807
  textHaloWidth
1819
1808
  ]);
1820
- const layout = React25__namespace.useMemo(() => {
1809
+ const layout = React26__namespace.useMemo(() => {
1821
1810
  const l = {};
1822
1811
  if (iconImage !== void 0) l["icon-image"] = iconImage;
1823
1812
  if (iconSize !== void 0) l["icon-size"] = iconSize;
@@ -1898,7 +1887,7 @@ var FillExtrusionLayer = ({
1898
1887
  fillExtrusionTranslate,
1899
1888
  fillExtrusionVerticalGradient
1900
1889
  }) => {
1901
- const paint = React25__namespace.useMemo(() => {
1890
+ const paint = React26__namespace.useMemo(() => {
1902
1891
  const p = {};
1903
1892
  if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
1904
1893
  if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
@@ -1924,7 +1913,7 @@ var FillExtrusionLayer = ({
1924
1913
  fillExtrusionVerticalGradient,
1925
1914
  opacity
1926
1915
  ]);
1927
- const layout = React25__namespace.useMemo(() => ({}), []);
1916
+ const layout = React26__namespace.useMemo(() => ({}), []);
1928
1917
  useLayer({
1929
1918
  id,
1930
1919
  source,
@@ -1963,7 +1952,7 @@ var HeatmapLayer = ({
1963
1952
  heatmapRadius,
1964
1953
  heatmapOpacity
1965
1954
  }) => {
1966
- const paint = React25__namespace.useMemo(() => {
1955
+ const paint = React26__namespace.useMemo(() => {
1967
1956
  const p = {};
1968
1957
  if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
1969
1958
  if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
@@ -1975,7 +1964,7 @@ var HeatmapLayer = ({
1975
1964
  }
1976
1965
  return p;
1977
1966
  }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
1978
- const layout = React25__namespace.useMemo(() => ({}), []);
1967
+ const layout = React26__namespace.useMemo(() => ({}), []);
1979
1968
  useLayer({
1980
1969
  id,
1981
1970
  source,
@@ -1995,6 +1984,127 @@ var HeatmapLayer = ({
1995
1984
  return null;
1996
1985
  };
1997
1986
  HeatmapLayer.displayName = "HeatmapLayer";
1987
+ function useControlPosition(ref, options) {
1988
+ const {
1989
+ id,
1990
+ type,
1991
+ position,
1992
+ fallbacks,
1993
+ priority = "normal",
1994
+ zLayer = "interactive",
1995
+ hasExpandedState = false,
1996
+ isBuiltIn = false
1997
+ } = options;
1998
+ const { positioningCoordinator } = useMap();
1999
+ const [offset, setOffset] = React26__namespace.useState(null);
2000
+ React26__namespace.useEffect(() => {
2001
+ if (!ref.current || !positioningCoordinator) return;
2002
+ const element = ref.current;
2003
+ const initialOffset = positioningCoordinator.register({
2004
+ id,
2005
+ type,
2006
+ isBuiltIn,
2007
+ dimensions: {
2008
+ width: element.offsetWidth || 200,
2009
+ height: element.offsetHeight || 100
2010
+ },
2011
+ position: {
2012
+ primary: position,
2013
+ fallbacks
2014
+ },
2015
+ priority,
2016
+ zLayer,
2017
+ hasExpandedState,
2018
+ isExpanded: false
2019
+ });
2020
+ setOffset(initialOffset);
2021
+ const unsubscribe = positioningCoordinator.subscribe((event) => {
2022
+ const newOffset = event.offsets.get(id);
2023
+ if (newOffset) {
2024
+ setOffset(newOffset);
2025
+ }
2026
+ });
2027
+ const resizeObserver = new ResizeObserver(() => {
2028
+ if (!element) return;
2029
+ positioningCoordinator.update(id, {
2030
+ dimensions: {
2031
+ width: element.offsetWidth,
2032
+ height: element.offsetHeight
2033
+ }
2034
+ });
2035
+ });
2036
+ resizeObserver.observe(element);
2037
+ return () => {
2038
+ resizeObserver.disconnect();
2039
+ unsubscribe();
2040
+ positioningCoordinator.unregister(id);
2041
+ };
2042
+ }, [
2043
+ id,
2044
+ type,
2045
+ position,
2046
+ fallbacks,
2047
+ priority,
2048
+ zLayer,
2049
+ hasExpandedState,
2050
+ isBuiltIn,
2051
+ positioningCoordinator,
2052
+ ref
2053
+ ]);
2054
+ React26__namespace.useEffect(() => {
2055
+ if (!positioningCoordinator) return;
2056
+ positioningCoordinator.update(id, {
2057
+ position: {
2058
+ primary: position,
2059
+ fallbacks
2060
+ },
2061
+ priority,
2062
+ zLayer
2063
+ });
2064
+ }, [id, position, fallbacks, priority, zLayer, positioningCoordinator]);
2065
+ const setExpanded = React26__namespace.useCallback(
2066
+ (isExpanded) => {
2067
+ if (positioningCoordinator) {
2068
+ positioningCoordinator.setExpanded(id, isExpanded);
2069
+ }
2070
+ },
2071
+ [id, positioningCoordinator]
2072
+ );
2073
+ const style = React26__namespace.useMemo(() => {
2074
+ if (!offset) {
2075
+ return {
2076
+ position: "absolute",
2077
+ visibility: "hidden"
2078
+ };
2079
+ }
2080
+ const resolvedPosition = offset.position;
2081
+ const isLeftPosition = resolvedPosition.includes("left") || resolvedPosition.includes("center");
2082
+ const isCenterHorizontal = resolvedPosition.includes("center");
2083
+ const baseStyle = {
2084
+ position: "absolute",
2085
+ zIndex: offset.zIndex
2086
+ };
2087
+ if (isCenterHorizontal) {
2088
+ baseStyle.left = offset.x;
2089
+ } else if (isLeftPosition) {
2090
+ baseStyle.left = offset.x;
2091
+ } else {
2092
+ baseStyle.right = offset.x;
2093
+ }
2094
+ if (resolvedPosition.startsWith("bottom")) {
2095
+ baseStyle.bottom = offset.y;
2096
+ } else {
2097
+ baseStyle.top = offset.y;
2098
+ }
2099
+ return baseStyle;
2100
+ }, [offset]);
2101
+ return {
2102
+ offset,
2103
+ setExpanded,
2104
+ style,
2105
+ visible: offset?.visible ?? false
2106
+ };
2107
+ }
1998
2108
  var legendIdCounter = 0;
1999
2109
  var Legend = ({
2000
2110
  title,
@@ -2009,30 +2119,17 @@ var Legend = ({
2009
2119
  class: className,
2010
2120
  onItemClick
2011
2121
  }) => {
2012
- const { controlOffsets, registerControl, unregisterControl } = useMap();
2013
- const [isCollapsed, setIsCollapsed] = React25__namespace.useState(initialCollapsed);
2014
- const [customControlOffset, setCustomControlOffset] = React25__namespace.useState(0);
2015
- const legendRef = React25__namespace.useRef(null);
2016
- const legendIdRef = React25__namespace.useRef(`legend-${++legendIdCounter}`);
2017
- React25__namespace.useEffect(() => {
2018
- if (!legendRef.current || !registerControl) return;
2019
- const updatePosition = () => {
2020
- if (!legendRef.current) return;
2021
- const height = legendRef.current.offsetHeight;
2022
- const offset = registerControl(legendIdRef.current, position, height);
2023
- setCustomControlOffset(offset);
2024
- };
2025
- updatePosition();
2026
- const observer = new ResizeObserver(updatePosition);
2027
- observer.observe(legendRef.current);
2028
- return () => {
2029
- observer.disconnect();
2030
- unregisterControl?.(legendIdRef.current, position);
2031
- };
2032
- }, [position, registerControl, unregisterControl]);
2033
- const verticalOffsetStyle = React25__namespace.useMemo(() => {
2034
- return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
2035
- }, [customControlOffset, position]);
2122
+ const [isCollapsed, setIsCollapsed] = React26__namespace.useState(initialCollapsed);
2123
+ const legendRef = React26__namespace.useRef(null);
2124
+ const legendIdRef = React26__namespace.useRef(`legend-${++legendIdCounter}`);
2125
+ const { style, visible } = useControlPosition(legendRef, {
2126
+ id: legendIdRef.current,
2127
+ type: "legend",
2128
+ position,
2129
+ priority: "normal",
2130
+ zLayer: "interactive",
2131
+ hasExpandedState: collapsible
2132
+ });
2036
2133
  const handleItemClick = (item, index) => {
2037
2134
  if (onItemClick) {
2038
2135
  onItemClick(item, index);
@@ -2043,26 +2140,22 @@ var Legend = ({
2043
2140
  setIsCollapsed(!isCollapsed);
2044
2141
  }
2045
2142
  };
2046
- const gradientStyle = React25__namespace.useMemo(() => {
2143
+ const gradientStyle = React26__namespace.useMemo(() => {
2047
2144
  if (type !== "gradient" || gradient.length === 0) return "";
2048
2145
  const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
2049
2146
  return `linear-gradient(to right, ${stops})`;
2050
2147
  }, [type, gradient]);
2051
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2052
- const computedPositionClasses = React25__namespace.useMemo(() => {
2053
- return mapsCore.computePositionClasses(position, hasControlsAtPosition);
2054
- }, [position, hasControlsAtPosition]);
2055
2148
  return /* @__PURE__ */ jsxRuntime.jsxs(
2056
2149
  "div",
2057
2150
  {
2058
2151
  ref: legendRef,
2059
2152
  className: cn(
2060
- "absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2153
+ "absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2061
2154
  "text-sm min-w-[140px] max-w-[280px]",
2062
- computedPositionClasses,
2155
+ !visible && "invisible",
2063
2156
  className
2064
2157
  ),
2065
- style: verticalOffsetStyle,
2158
+ style,
2066
2159
  children: [
2067
2160
  (title || collapsible) && /* @__PURE__ */ jsxRuntime.jsxs(
2068
2161
  "button",
@@ -2148,45 +2241,31 @@ var LegendGroup = ({
2148
2241
  allowCollapseAll = false,
2149
2242
  class: className
2150
2243
  }) => {
2151
- const { controlOffsets, registerControl, unregisterControl } = useMap();
2152
- const containerRef = React25__namespace.useRef(null);
2153
- const groupIdRef = React25__namespace.useRef(`legend-group-${++legendGroupIdCounter}`);
2154
- const [customControlOffset, setCustomControlOffset] = React25__namespace.useState(0);
2244
+ const containerRef = React26__namespace.useRef(null);
2245
+ const groupIdRef = React26__namespace.useRef(`legend-group-${++legendGroupIdCounter}`);
2155
2246
  const getInitialExpanded = () => {
2156
2247
  if (controlledExpanded !== void 0) return controlledExpanded;
2157
2248
  if (defaultExpanded) return defaultExpanded;
2158
2249
  return legends[0]?.id || null;
2159
2250
  };
2160
- const [internalExpanded, setInternalExpanded] = React25__namespace.useState(getInitialExpanded);
2251
+ const [internalExpanded, setInternalExpanded] = React26__namespace.useState(getInitialExpanded);
2161
2252
  const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
2253
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2254
+ id: groupIdRef.current,
2255
+ type: "legend-group",
2256
+ position,
2257
+ priority: "normal",
2258
+ zLayer: "interactive",
2259
+ hasExpandedState: true
2260
+ });
2162
2261
  const handleToggle = (id) => {
2163
2262
  const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
2164
2263
  if (controlledExpanded === void 0) {
2165
2264
  setInternalExpanded(newExpanded);
2166
2265
  }
2266
+ setExpanded(newExpanded !== null);
2167
2267
  onExpandedChange?.(newExpanded);
2168
2268
  };
2169
- React25__namespace.useEffect(() => {
2170
- if (!containerRef.current || !registerControl) return;
2171
- const timeoutId = setTimeout(() => {
2172
- if (containerRef.current) {
2173
- const height = containerRef.current.offsetHeight;
2174
- const offset = registerControl(groupIdRef.current, position, height);
2175
- setCustomControlOffset(offset);
2176
- }
2177
- }, 50);
2178
- return () => {
2179
- clearTimeout(timeoutId);
2180
- unregisterControl?.(groupIdRef.current, position);
2181
- };
2182
- }, [position, expandedId, registerControl, unregisterControl]);
2183
- const verticalOffsetStyle = React25__namespace.useMemo(() => {
2184
- return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
2185
- }, [customControlOffset, position]);
2186
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2187
- const computedPositionClasses = React25__namespace.useMemo(() => {
2188
- return mapsCore.computePositionClasses(position, hasControlsAtPosition);
2189
- }, [position, hasControlsAtPosition]);
2190
2269
  const getGradientStyle = (legend) => {
2191
2270
  if (legend.type !== "gradient" || !legend.gradient?.length) return "";
2192
2271
  const stops = legend.gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
@@ -2200,12 +2279,12 @@ var LegendGroup = ({
2200
2279
  {
2201
2280
  ref: containerRef,
2202
2281
  className: cn(
2203
- "absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2282
+ "absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2204
2283
  "text-sm min-w-[160px] max-w-[280px]",
2205
- computedPositionClasses,
2284
+ !visible && "invisible",
2206
2285
  className
2207
2286
  ),
2208
- style: verticalOffsetStyle,
2287
+ style,
2209
2288
  children: legends.map((legend, legendIndex) => {
2210
2289
  const isExpanded = expandedId === legend.id;
2211
2290
  const isFirst = legendIndex === 0;
@@ -2306,6 +2385,7 @@ var LegendGroup = ({
2306
2385
  };
2307
2386
  LegendGroup.displayName = "LegendGroup";
2308
2387
  var coordDisplayIdCounter = 0;
2388
+ var NAV_CONTROL_WIDTH = 29;
2309
2389
  var CoordinateDisplay = ({
2310
2390
  position = "bottom-right",
2311
2391
  format = "decimal",
@@ -2314,33 +2394,40 @@ var CoordinateDisplay = ({
2314
2394
  showBearing = false,
2315
2395
  class: className
2316
2396
  }) => {
2317
- const { map, loaded, controlOffsets, registerControl, unregisterControl } = useMap();
2318
- const [cursorLngLat, setCursorLngLat] = React25__namespace.useState(null);
2319
- const [currentZoom, setCurrentZoom] = React25__namespace.useState(0);
2320
- const [currentBearing, setCurrentBearing] = React25__namespace.useState(0);
2321
- const [customControlOffset, setCustomControlOffset] = React25__namespace.useState(0);
2322
- const controlRef = React25__namespace.useRef(null);
2323
- const controlIdRef = React25__namespace.useRef(`coord-display-${++coordDisplayIdCounter}`);
2324
- React25__namespace.useEffect(() => {
2325
- if (!controlRef.current || !registerControl) return;
2326
- const updatePosition = () => {
2327
- if (!controlRef.current) return;
2328
- const height = controlRef.current.offsetHeight;
2329
- const offset = registerControl(controlIdRef.current, position, height);
2330
- setCustomControlOffset(offset);
2331
- };
2332
- updatePosition();
2333
- const observer = new ResizeObserver(updatePosition);
2334
- observer.observe(controlRef.current);
2335
- return () => {
2336
- observer.disconnect();
2337
- unregisterControl?.(controlIdRef.current, position);
2338
- };
2339
- }, [position, registerControl, unregisterControl]);
2340
- const verticalOffsetStyle = React25__namespace.useMemo(() => {
2341
- return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
2342
- }, [customControlOffset, position]);
2343
- const formatCoord = React25__namespace.useCallback(
2397
+ const { map, loaded } = useMap();
2398
+ const [cursorLngLat, setCursorLngLat] = React26__namespace.useState(null);
2399
+ const [currentZoom, setCurrentZoom] = React26__namespace.useState(0);
2400
+ const [currentBearing, setCurrentBearing] = React26__namespace.useState(0);
2401
+ const controlRef = React26__namespace.useRef(null);
2402
+ const controlIdRef = React26__namespace.useRef(`coord-display-${++coordDisplayIdCounter}`);
2403
+ const { style, visible } = useControlPosition(controlRef, {
2404
+ id: controlIdRef.current,
2405
+ type: "coordinate-display",
2406
+ position,
2407
+ priority: "critical",
2408
+ zLayer: "base"
2409
+ });
2410
+ const adjustedStyle = React26__namespace.useMemo(() => {
2411
+ if (!style) return style;
2412
+ if (position === "top-right") {
2413
+ const rightOffset = NAV_CONTROL_WIDTH + mapsCore.STACK_GAP + mapsCore.EDGE_MARGIN;
2414
+ return {
2415
+ ...style,
2416
+ top: mapsCore.EDGE_MARGIN,
2417
+ right: rightOffset
2418
+ };
2419
+ }
2420
+ if (position === "bottom-right") {
2421
+ const ATTRIBUTION_HEIGHT = 32;
2422
+ const bottomOffset = mapsCore.EDGE_MARGIN + ATTRIBUTION_HEIGHT;
2423
+ return {
2424
+ ...style,
2425
+ bottom: bottomOffset
2426
+ };
2427
+ }
2428
+ return style;
2429
+ }, [position, style]);
2430
+ const formatCoord = React26__namespace.useCallback(
2344
2431
  (lngLat) => {
2345
2432
  return mapsCore.formatCoordinates(lngLat, precision, format);
2346
2433
  },
@@ -2353,11 +2440,7 @@ var CoordinateDisplay = ({
2353
2440
  const normalized = (bearing % 360 + 360) % 360;
2354
2441
  return `${normalized.toFixed(0)}\xB0`;
2355
2442
  };
2356
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2357
- const computedPositionClasses = React25__namespace.useMemo(() => {
2358
- return mapsCore.computePositionClasses(position, hasControlsAtPosition);
2359
- }, [position, hasControlsAtPosition]);
2360
- React25__namespace.useEffect(() => {
2443
+ React26__namespace.useEffect(() => {
2361
2444
  if (!map || !loaded) return;
2362
2445
  setCurrentZoom(map.getZoom());
2363
2446
  setCurrentBearing(map.getBearing());
@@ -2384,14 +2467,14 @@ var CoordinateDisplay = ({
2384
2467
  {
2385
2468
  ref: controlRef,
2386
2469
  className: cn(
2387
- "absolute z-10 bg-card rounded px-2 py-1",
2470
+ "absolute bg-card rounded px-2 py-1",
2388
2471
  "text-xs font-mono text-muted-foreground",
2389
2472
  "border border-black dark:border-gray-400 shadow-sm",
2390
2473
  "flex items-center gap-3",
2391
- computedPositionClasses,
2474
+ !visible && "invisible",
2392
2475
  className
2393
2476
  ),
2394
- style: verticalOffsetStyle,
2477
+ style: adjustedStyle,
2395
2478
  children: [
2396
2479
  cursorLngLat ? /* @__PURE__ */ jsxRuntime.jsx("span", { title: "Cursor coordinates", children: formatCoord(cursorLngLat) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground/60", children: "Move cursor over map" }),
2397
2480
  showZoom && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -2423,17 +2506,16 @@ var BasemapSwitcher = ({
2423
2506
  position = "bottom-right",
2424
2507
  class: className
2425
2508
  }) => {
2426
- const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
2427
- const [isOpen, setIsOpen] = React25__namespace.useState(false);
2428
- const [internalActiveId, setInternalActiveId] = React25__namespace.useState(
2509
+ const { setMapStyle } = useMap();
2510
+ const [isOpen, setIsOpen] = React26__namespace.useState(false);
2511
+ const [internalActiveId, setInternalActiveId] = React26__namespace.useState(
2429
2512
  defaultBasemapId
2430
2513
  );
2431
- const [customControlOffset, setCustomControlOffset] = React25__namespace.useState(0);
2432
- const containerRef = React25__namespace.useRef(null);
2433
- const panelRef = React25__namespace.useRef(null);
2434
- const switcherIdRef = React25__namespace.useRef(`basemap-switcher-${++switcherIdCounter}`);
2514
+ const containerRef = React26__namespace.useRef(null);
2515
+ const panelRef = React26__namespace.useRef(null);
2516
+ const switcherIdRef = React26__namespace.useRef(`basemap-switcher-${++switcherIdCounter}`);
2435
2517
  const sourceBasemaps = basemaps ?? mapsCore.FREE_BASEMAPS;
2436
- const availableBasemaps = React25__namespace.useMemo(() => {
2518
+ const availableBasemaps = React26__namespace.useMemo(() => {
2437
2519
  const available = mapsCore.getAvailableBasemaps(sourceBasemaps, apiKeys);
2438
2520
  if (extraBasemaps?.length) {
2439
2521
  return [...available, ...mapsCore.getAvailableBasemaps(extraBasemaps, apiKeys)];
@@ -2441,66 +2523,59 @@ var BasemapSwitcher = ({
2441
2523
  return available;
2442
2524
  }, [sourceBasemaps, extraBasemaps, apiKeys]);
2443
2525
  const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
2444
- React25__namespace.useEffect(() => {
2445
- if (!containerRef.current || !registerControl) return;
2446
- const updatePosition = () => {
2447
- if (!containerRef.current) return;
2448
- const height = containerRef.current.offsetHeight;
2449
- const offset = registerControl(switcherIdRef.current, position, height);
2450
- setCustomControlOffset(offset);
2451
- };
2452
- updatePosition();
2453
- const observer = new ResizeObserver(updatePosition);
2454
- observer.observe(containerRef.current);
2455
- return () => {
2456
- observer.disconnect();
2457
- unregisterControl?.(switcherIdRef.current, position);
2458
- };
2459
- }, [position, registerControl, unregisterControl]);
2460
- React25__namespace.useEffect(() => {
2526
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2527
+ id: switcherIdRef.current,
2528
+ type: "basemap-switcher",
2529
+ position,
2530
+ priority: "normal",
2531
+ zLayer: "interactive",
2532
+ hasExpandedState: true
2533
+ });
2534
+ React26__namespace.useEffect(() => {
2461
2535
  if (!isOpen) return;
2462
2536
  const handleMouseDown = (e) => {
2463
2537
  if (containerRef.current && !containerRef.current.contains(e.target)) {
2464
2538
  setIsOpen(false);
2539
+ setExpanded(false);
2465
2540
  }
2466
2541
  };
2467
2542
  document.addEventListener("mousedown", handleMouseDown);
2468
2543
  return () => document.removeEventListener("mousedown", handleMouseDown);
2469
- }, [isOpen]);
2470
- React25__namespace.useEffect(() => {
2544
+ }, [isOpen, setExpanded]);
2545
+ React26__namespace.useEffect(() => {
2471
2546
  if (!isOpen) return;
2472
2547
  const handleKeyDown = (e) => {
2473
2548
  if (e.key === "Escape") {
2474
2549
  setIsOpen(false);
2550
+ setExpanded(false);
2475
2551
  }
2476
2552
  };
2477
2553
  document.addEventListener("keydown", handleKeyDown);
2478
2554
  return () => document.removeEventListener("keydown", handleKeyDown);
2479
- }, [isOpen]);
2555
+ }, [isOpen, setExpanded]);
2480
2556
  const handleSelect = (basemap) => {
2481
- const style = mapsCore.resolveBasemapStyle(basemap, apiKeys);
2482
- if (!style) return;
2557
+ const resolvedStyle = mapsCore.resolveBasemapStyle(basemap, apiKeys);
2558
+ if (!resolvedStyle) return;
2483
2559
  if (!activeBasemapId) {
2484
2560
  setInternalActiveId(basemap.id);
2485
2561
  }
2486
- setMapStyle?.(style);
2562
+ setMapStyle?.(resolvedStyle);
2487
2563
  onBasemapChange?.(basemap);
2488
2564
  setIsOpen(false);
2565
+ setExpanded(false);
2566
+ };
2567
+ const handleToggle = () => {
2568
+ const newState = !isOpen;
2569
+ setIsOpen(newState);
2570
+ setExpanded(newState);
2489
2571
  };
2490
- const verticalOffsetStyle = React25__namespace.useMemo(() => {
2491
- return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
2492
- }, [customControlOffset, position]);
2493
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2494
- const computedPositionClasses = React25__namespace.useMemo(() => {
2495
- return mapsCore.computePositionClasses(position, hasControlsAtPosition);
2496
- }, [position, hasControlsAtPosition]);
2497
2572
  const isTop = position.startsWith("top");
2498
2573
  return /* @__PURE__ */ jsxRuntime.jsxs(
2499
2574
  "div",
2500
2575
  {
2501
2576
  ref: containerRef,
2502
- className: cn("absolute z-10", computedPositionClasses, className),
2503
- style: verticalOffsetStyle,
2577
+ className: cn("absolute", !visible && "invisible", className),
2578
+ style,
2504
2579
  children: [
2505
2580
  isOpen && /* @__PURE__ */ jsxRuntime.jsx(
2506
2581
  "div",
@@ -2575,7 +2650,7 @@ var BasemapSwitcher = ({
2575
2650
  "hover:bg-muted transition-colors cursor-pointer",
2576
2651
  "text-foreground"
2577
2652
  ),
2578
- onClick: () => setIsOpen(!isOpen),
2653
+ onClick: handleToggle,
2579
2654
  "aria-label": "Switch basemap",
2580
2655
  "aria-expanded": isOpen,
2581
2656
  "aria-haspopup": "true",
@@ -2618,22 +2693,28 @@ var LayerManager = ({
2618
2693
  onLayerChange,
2619
2694
  class: className
2620
2695
  }) => {
2621
- const { controlOffsets, registerControl, unregisterControl } = useMap();
2622
2696
  const { isDark } = useMapTheme();
2623
- const [isOpen, setIsOpen] = React25__namespace.useState(false);
2624
- const [layerStates, setLayerStates] = React25__namespace.useState(
2697
+ const [isOpen, setIsOpen] = React26__namespace.useState(false);
2698
+ const [layerStates, setLayerStates] = React26__namespace.useState(
2625
2699
  () => mapsCore.createInitialLayerStates(layers, initialActiveLayers)
2626
2700
  );
2627
- const [searchQuery, setSearchQuery] = React25__namespace.useState("");
2628
- const [activeCategory, setActiveCategory] = React25__namespace.useState("all");
2629
- const [customControlOffset, setCustomControlOffset] = React25__namespace.useState(0);
2630
- const [expandedOpacity, setExpandedOpacity] = React25__namespace.useState(null);
2631
- const [draggedId, setDraggedId] = React25__namespace.useState(null);
2632
- const [dragOver, setDragOver] = React25__namespace.useState(null);
2633
- const containerRef = React25__namespace.useRef(null);
2634
- const managerIdRef = React25__namespace.useRef(`layer-manager-${++managerIdCounter}`);
2635
- const lastLayerIdsRef = React25__namespace.useRef(new Set(layers.map((l) => l.id)));
2636
- React25__namespace.useEffect(() => {
2701
+ const [searchQuery, setSearchQuery] = React26__namespace.useState("");
2702
+ const [activeCategory, setActiveCategory] = React26__namespace.useState("all");
2703
+ const [expandedOpacity, setExpandedOpacity] = React26__namespace.useState(null);
2704
+ const [draggedId, setDraggedId] = React26__namespace.useState(null);
2705
+ const [dragOver, setDragOver] = React26__namespace.useState(null);
2706
+ const containerRef = React26__namespace.useRef(null);
2707
+ const managerIdRef = React26__namespace.useRef(`layer-manager-${++managerIdCounter}`);
2708
+ const lastLayerIdsRef = React26__namespace.useRef(new Set(layers.map((l) => l.id)));
2709
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2710
+ id: managerIdRef.current,
2711
+ type: "layer-manager",
2712
+ position,
2713
+ priority: "high",
2714
+ zLayer: "interactive",
2715
+ hasExpandedState: true
2716
+ });
2717
+ React26__namespace.useEffect(() => {
2637
2718
  const currentLayerIds = new Set(layers.map((l) => l.id));
2638
2719
  const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
2639
2720
  const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
@@ -2664,8 +2745,8 @@ var LayerManager = ({
2664
2745
  lastLayerIdsRef.current = currentLayerIds;
2665
2746
  }
2666
2747
  }, [layers, initialActiveLayers]);
2667
- const categories = React25__namespace.useMemo(() => mapsCore.getLayerCategories(layers), [layers]);
2668
- const filteredLayers = React25__namespace.useMemo(() => {
2748
+ const categories = React26__namespace.useMemo(() => mapsCore.getLayerCategories(layers), [layers]);
2749
+ const filteredLayers = React26__namespace.useMemo(() => {
2669
2750
  let result = layers;
2670
2751
  if (searchQuery) {
2671
2752
  result = mapsCore.searchLayers(result, searchQuery);
@@ -2679,47 +2760,33 @@ var LayerManager = ({
2679
2760
  return orderA - orderB;
2680
2761
  });
2681
2762
  }, [layers, searchQuery, activeCategory, layerStates]);
2682
- const layerGroups = React25__namespace.useMemo(
2763
+ const layerGroups = React26__namespace.useMemo(
2683
2764
  () => showCategories ? mapsCore.groupLayersByCategory(filteredLayers) : null,
2684
2765
  [filteredLayers, showCategories]
2685
2766
  );
2686
- React25__namespace.useEffect(() => {
2687
- if (!containerRef.current || !registerControl) return;
2688
- const updatePosition = () => {
2689
- if (!containerRef.current) return;
2690
- const height = containerRef.current.offsetHeight;
2691
- const offset = registerControl(managerIdRef.current, position, height);
2692
- setCustomControlOffset(offset);
2693
- };
2694
- updatePosition();
2695
- const observer = new ResizeObserver(updatePosition);
2696
- observer.observe(containerRef.current);
2697
- return () => {
2698
- observer.disconnect();
2699
- unregisterControl?.(managerIdRef.current, position);
2700
- };
2701
- }, [position, registerControl, unregisterControl]);
2702
- React25__namespace.useEffect(() => {
2767
+ React26__namespace.useEffect(() => {
2703
2768
  if (!isOpen) return;
2704
2769
  const handleMouseDown = (e) => {
2705
2770
  if (containerRef.current && !containerRef.current.contains(e.target)) {
2706
2771
  setIsOpen(false);
2772
+ setExpanded(false);
2707
2773
  }
2708
2774
  };
2709
2775
  document.addEventListener("mousedown", handleMouseDown);
2710
2776
  return () => document.removeEventListener("mousedown", handleMouseDown);
2711
- }, [isOpen]);
2712
- React25__namespace.useEffect(() => {
2777
+ }, [isOpen, setExpanded]);
2778
+ React26__namespace.useEffect(() => {
2713
2779
  if (!isOpen) return;
2714
2780
  const handleKeyDown = (e) => {
2715
2781
  if (e.key === "Escape") {
2716
2782
  setIsOpen(false);
2783
+ setExpanded(false);
2717
2784
  }
2718
2785
  };
2719
2786
  document.addEventListener("keydown", handleKeyDown);
2720
2787
  return () => document.removeEventListener("keydown", handleKeyDown);
2721
- }, [isOpen]);
2722
- const handleToggleLayer = React25__namespace.useCallback(
2788
+ }, [isOpen, setExpanded]);
2789
+ const handleToggleLayer = React26__namespace.useCallback(
2723
2790
  (layerId) => {
2724
2791
  setLayerStates((prev) => {
2725
2792
  const newStates = mapsCore.toggleLayerVisibility(prev, layerId);
@@ -2732,7 +2799,7 @@ var LayerManager = ({
2732
2799
  },
2733
2800
  [onLayerChange]
2734
2801
  );
2735
- const handleOpacityChange = React25__namespace.useCallback(
2802
+ const handleOpacityChange = React26__namespace.useCallback(
2736
2803
  (layerId, opacity) => {
2737
2804
  setLayerStates((prev) => {
2738
2805
  const newStates = mapsCore.setLayerOpacity(prev, layerId, opacity);
@@ -2745,12 +2812,12 @@ var LayerManager = ({
2745
2812
  },
2746
2813
  [onLayerChange]
2747
2814
  );
2748
- const handleDragStart = React25__namespace.useCallback((e, layerId) => {
2815
+ const handleDragStart = React26__namespace.useCallback((e, layerId) => {
2749
2816
  setDraggedId(layerId);
2750
2817
  e.dataTransfer.effectAllowed = "move";
2751
2818
  e.dataTransfer.setData("text/plain", layerId);
2752
2819
  }, []);
2753
- const handleDragOver = React25__namespace.useCallback(
2820
+ const handleDragOver = React26__namespace.useCallback(
2754
2821
  (e, layerId) => {
2755
2822
  e.preventDefault();
2756
2823
  e.dataTransfer.dropEffect = "move";
@@ -2770,14 +2837,14 @@ var LayerManager = ({
2770
2837
  },
2771
2838
  [draggedId, dragOver]
2772
2839
  );
2773
- const handleDragLeave = React25__namespace.useCallback(() => {
2840
+ const handleDragLeave = React26__namespace.useCallback(() => {
2774
2841
  setDragOver(null);
2775
2842
  }, []);
2776
- const handleDragEnd = React25__namespace.useCallback(() => {
2843
+ const handleDragEnd = React26__namespace.useCallback(() => {
2777
2844
  setDraggedId(null);
2778
2845
  setDragOver(null);
2779
2846
  }, []);
2780
- const handleDrop = React25__namespace.useCallback(
2847
+ const handleDrop = React26__namespace.useCallback(
2781
2848
  (e, targetLayerId) => {
2782
2849
  e.preventDefault();
2783
2850
  const sourceLayerId = e.dataTransfer.getData("text/plain");
@@ -2807,13 +2874,6 @@ var LayerManager = ({
2807
2874
  },
2808
2875
  [layerStates, onLayerChange, dragOver]
2809
2876
  );
2810
- const verticalOffsetStyle = React25__namespace.useMemo(() => {
2811
- return mapsCore.computeVerticalOffsetStyle(position, customControlOffset);
2812
- }, [customControlOffset, position]);
2813
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2814
- const computedPositionClasses = React25__namespace.useMemo(() => {
2815
- return mapsCore.computePositionClasses(position, hasControlsAtPosition);
2816
- }, [position, hasControlsAtPosition]);
2817
2877
  const isTop = position.startsWith("top");
2818
2878
  const renderLayer = (layer, state) => {
2819
2879
  if (!state.visible) return null;
@@ -3024,6 +3084,11 @@ var LayerManager = ({
3024
3084
  ] }) });
3025
3085
  };
3026
3086
  const visibleLayerStates = mapsCore.getLayerStatesArray(layerStates).filter((s) => s.visible);
3087
+ const handleToggle = () => {
3088
+ const newState = !isOpen;
3089
+ setIsOpen(newState);
3090
+ setExpanded(newState);
3091
+ };
3027
3092
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3028
3093
  visibleLayerStates.map((state) => {
3029
3094
  const layer = layers.find((l) => l.id === state.id);
@@ -3033,8 +3098,8 @@ var LayerManager = ({
3033
3098
  "div",
3034
3099
  {
3035
3100
  ref: containerRef,
3036
- className: cn("absolute z-10", computedPositionClasses, className),
3037
- style: verticalOffsetStyle,
3101
+ className: cn("absolute", !visible && "invisible", className),
3102
+ style,
3038
3103
  children: [
3039
3104
  isOpen && /* @__PURE__ */ jsxRuntime.jsxs(
3040
3105
  "div",
@@ -3112,7 +3177,7 @@ var LayerManager = ({
3112
3177
  if (catLayers.length === 0) return null;
3113
3178
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3114
3179
  /* @__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 }),
3115
- catLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React25__namespace.Fragment, { children: [
3180
+ catLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React26__namespace.Fragment, { children: [
3116
3181
  renderLayerItem(layer),
3117
3182
  renderOpacitySlider(layer.id)
3118
3183
  ] }, layer.id))
@@ -3120,7 +3185,7 @@ var LayerManager = ({
3120
3185
  })
3121
3186
  ) : (
3122
3187
  // Flat list
3123
- filteredLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React25__namespace.Fragment, { children: [
3188
+ filteredLayers.map((layer) => /* @__PURE__ */ jsxRuntime.jsxs(React26__namespace.Fragment, { children: [
3124
3189
  renderLayerItem(layer),
3125
3190
  renderOpacitySlider(layer.id)
3126
3191
  ] }, layer.id))
@@ -3140,7 +3205,7 @@ var LayerManager = ({
3140
3205
  "hover:bg-muted transition-colors cursor-pointer",
3141
3206
  "text-foreground"
3142
3207
  ),
3143
- onClick: () => setIsOpen(!isOpen),
3208
+ onClick: handleToggle,
3144
3209
  "aria-label": "Toggle layer manager",
3145
3210
  "aria-expanded": isOpen,
3146
3211
  "aria-haspopup": "true",
@@ -3180,9 +3245,9 @@ var DeckOverlay = ({
3180
3245
  deckProps = {}
3181
3246
  }) => {
3182
3247
  const { map, loaded } = useMap();
3183
- const overlayRef = React25__namespace.useRef(null);
3184
- const MapboxOverlayRef = React25__namespace.useRef(null);
3185
- React25__namespace.useEffect(() => {
3248
+ const overlayRef = React26__namespace.useRef(null);
3249
+ const MapboxOverlayRef = React26__namespace.useRef(null);
3250
+ React26__namespace.useEffect(() => {
3186
3251
  if (!map || !loaded) return;
3187
3252
  let cancelled = false;
3188
3253
  const initOverlay = async () => {
@@ -3222,12 +3287,12 @@ var DeckOverlay = ({
3222
3287
  }
3223
3288
  };
3224
3289
  }, [map, loaded, interleaved]);
3225
- React25__namespace.useEffect(() => {
3290
+ React26__namespace.useEffect(() => {
3226
3291
  if (overlayRef.current && "setProps" in overlayRef.current) {
3227
3292
  overlayRef.current.setProps({ layers });
3228
3293
  }
3229
3294
  }, [layers]);
3230
- React25__namespace.useEffect(() => {
3295
+ React26__namespace.useEffect(() => {
3231
3296
  if (overlayRef.current && "setProps" in overlayRef.current) {
3232
3297
  overlayRef.current.setProps({
3233
3298
  onHover,
@@ -3235,7 +3300,7 @@ var DeckOverlay = ({
3235
3300
  });
3236
3301
  }
3237
3302
  }, [onHover, onClick]);
3238
- React25__namespace.useEffect(() => {
3303
+ React26__namespace.useEffect(() => {
3239
3304
  if (overlayRef.current && effects && "setProps" in overlayRef.current) {
3240
3305
  overlayRef.current.setProps({ effects });
3241
3306
  }