@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.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as React25 from 'react';
1
+ import * as React26 from 'react';
2
2
  import { useState, useEffect, useCallback } from 'react';
3
3
  import { clsx } from 'clsx';
4
4
  import { twMerge } from 'tailwind-merge';
@@ -7,7 +7,7 @@ import maplibregl from 'maplibre-gl';
7
7
  import 'maplibre-gl/dist/maplibre-gl.css';
8
8
  import '@classic-homes/maps-core/styles/controls.css';
9
9
  import '@classic-homes/maps-core/styles/marker.css';
10
- import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
10
+ import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, STACK_GAP, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
11
11
  export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createInitialLayerStates, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getLayerCategories, getLayerStyleForTheme, getLayersByCategory, getSelectionStyle, groupLayersByCategory, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, resolveLayerSourceUrl, searchLayers, setLayerOpacity, toggleLayerVisibility, validateGeoJSON } from '@classic-homes/maps-core';
12
12
  import * as ReactDOM from 'react-dom';
13
13
  import { cva } from 'class-variance-authority';
@@ -19,7 +19,7 @@ import { Switch } from '@classic-homes/theme-react';
19
19
  function cn(...inputs) {
20
20
  return twMerge(clsx(inputs));
21
21
  }
22
- var MapSkeleton = React25.forwardRef(
22
+ var MapSkeleton = React26.forwardRef(
23
23
  ({ height = 400, className, ...props }, ref) => {
24
24
  const heightStyle = typeof height === "number" ? `${height}px` : height;
25
25
  return /* @__PURE__ */ jsxs(
@@ -73,7 +73,7 @@ var MapSkeleton = React25.forwardRef(
73
73
  }
74
74
  );
75
75
  MapSkeleton.displayName = "MapSkeleton";
76
- var MapError = React25.forwardRef(
76
+ var MapError = React26.forwardRef(
77
77
  ({ message = "Failed to load map", height = 400, onRetry, className, ...props }, ref) => {
78
78
  const heightStyle = typeof height === "number" ? `${height}px` : height;
79
79
  return /* @__PURE__ */ jsx(
@@ -129,7 +129,7 @@ var MapError = React25.forwardRef(
129
129
  }
130
130
  );
131
131
  MapError.displayName = "MapError";
132
- var MapEmpty = React25.forwardRef(
132
+ var MapEmpty = React26.forwardRef(
133
133
  ({ message = "No map data to display", height = 400, className, ...props }, ref) => {
134
134
  const heightStyle = typeof height === "number" ? `${height}px` : height;
135
135
  return /* @__PURE__ */ jsx(
@@ -172,7 +172,7 @@ var MapEmpty = React25.forwardRef(
172
172
  }
173
173
  );
174
174
  MapEmpty.displayName = "MapEmpty";
175
- var MapContainer = React25.forwardRef(
175
+ var MapContainer = React26.forwardRef(
176
176
  ({
177
177
  title,
178
178
  description,
@@ -277,9 +277,9 @@ function useReducedMotion() {
277
277
  }, []);
278
278
  return prefersReducedMotion2;
279
279
  }
280
- var MapContext = React25.createContext(null);
280
+ var MapContext = React26.createContext(null);
281
281
  function useMap() {
282
- const context = React25.useContext(MapContext);
282
+ const context = React26.useContext(MapContext);
283
283
  if (!context) {
284
284
  throw new Error("useMap must be used within a Map component");
285
285
  }
@@ -289,7 +289,7 @@ function useMapInstance() {
289
289
  const { map, loaded } = useMap();
290
290
  return loaded ? map : null;
291
291
  }
292
- var Map2 = React25.forwardRef(
292
+ var Map2 = React26.forwardRef(
293
293
  ({
294
294
  // Base props
295
295
  title,
@@ -343,108 +343,56 @@ var Map2 = React25.forwardRef(
343
343
  onZoom,
344
344
  onError
345
345
  }, ref) => {
346
- const containerRef = React25.useRef(null);
347
- const mapRef = React25.useRef(null);
348
- const [mapLoaded, setMapLoaded] = React25.useState(false);
349
- const [mapError, setMapError] = React25.useState(null);
350
- const [styleVersion, setStyleVersion] = React25.useState(0);
351
- const activeStyleOverrideRef = React25.useRef(
346
+ const containerRef = React26.useRef(null);
347
+ const mapRef = React26.useRef(null);
348
+ const [mapLoaded, setMapLoaded] = React26.useState(false);
349
+ const [mapError, setMapError] = React26.useState(null);
350
+ const [styleVersion, setStyleVersion] = React26.useState(0);
351
+ const activeStyleOverrideRef = React26.useRef(
352
352
  null
353
353
  );
354
- const setMapStyle = React25.useCallback((style) => {
354
+ const positioningCoordinatorRef = React26.useRef(null);
355
+ if (!positioningCoordinatorRef.current) {
356
+ positioningCoordinatorRef.current = createPositioningCoordinator();
357
+ }
358
+ const positioningCoordinator = positioningCoordinatorRef.current;
359
+ const setMapStyle = React26.useCallback((style) => {
355
360
  activeStyleOverrideRef.current = style;
356
361
  mapRef.current?.setStyle(style);
357
362
  }, []);
358
- const customControlRegistryRef = React25.useRef({
359
- "top-left": [],
360
- "top-right": [],
361
- "bottom-left": [],
362
- "bottom-right": []
363
- });
364
- const [, forceUpdate] = React25.useReducer((x) => x + 1, 0);
365
363
  const prefersReducedMotion2 = useReducedMotion();
366
364
  const { style: themeStyle } = useMapTheme(themePref);
367
- const onLoadRef = React25.useRef(onLoad);
365
+ const onLoadRef = React26.useRef(onLoad);
368
366
  onLoadRef.current = onLoad;
369
- const onErrorRef = React25.useRef(onError);
367
+ const onErrorRef = React26.useRef(onError);
370
368
  onErrorRef.current = onError;
371
369
  const mapStyle = customStyle || themeStyle;
372
- const controlOffsets = React25.useMemo(() => {
373
- const offsets = {
374
- "top-left": 0,
375
- "top-right": 0,
376
- "bottom-left": 0,
377
- "bottom-right": 0
378
- };
379
- if (navigationControl) {
380
- offsets[navigationControlPosition] += 100;
381
- }
382
- if (scaleControl) {
383
- offsets[scaleControlPosition] += 28;
384
- }
385
- if (fullscreenControl) {
386
- offsets[fullscreenControlPosition] += 38;
387
- }
388
- if (geolocateControl) {
389
- offsets[geolocateControlPosition] += 38;
390
- }
391
- if (attributionControl) {
392
- offsets["bottom-right"] += 32;
393
- }
394
- return offsets;
395
- }, [
396
- navigationControl,
397
- navigationControlPosition,
398
- scaleControl,
399
- scaleControlPosition,
400
- fullscreenControl,
401
- fullscreenControlPosition,
402
- geolocateControl,
403
- geolocateControlPosition,
404
- attributionControl
405
- ]);
406
- const registerControl = React25.useCallback(
407
- (id, position, height2) => {
408
- const registry = customControlRegistryRef.current;
409
- const positionControls = registry[position] || [];
410
- const existingIndex = positionControls.findIndex((c) => c.id === id);
411
- if (existingIndex >= 0) {
412
- positionControls[existingIndex].height = height2;
413
- } else {
414
- positionControls.push({ id, height: height2 });
415
- forceUpdate();
416
- }
417
- registry[position] = positionControls;
418
- let offset = 0;
419
- for (const control of positionControls) {
420
- if (control.id === id) break;
421
- offset += control.height + 8;
422
- }
423
- return offset;
424
- },
425
- []
426
- );
427
- const unregisterControl = React25.useCallback((id, position) => {
428
- const registry = customControlRegistryRef.current;
429
- const positionControls = registry[position] || [];
430
- registry[position] = positionControls.filter((c) => c.id !== id);
431
- forceUpdate();
432
- }, []);
433
- const getCustomControlOffset = React25.useCallback((id, position) => {
434
- const registry = customControlRegistryRef.current;
435
- const positionControls = registry[position] || [];
436
- let offset = 0;
437
- for (const control of positionControls) {
438
- if (control.id === id) break;
439
- offset += control.height + 8;
440
- }
441
- return offset;
442
- }, []);
443
370
  const accessibleDescription = description || generateMapDescription(title, {
444
371
  center,
445
372
  zoom
446
373
  });
447
- React25.useEffect(() => {
374
+ React26.useEffect(() => {
375
+ if (!containerRef.current || !positioningCoordinator) return;
376
+ const updateDimensions = () => {
377
+ if (!containerRef.current) return;
378
+ positioningCoordinator.setMapDimensions({
379
+ width: containerRef.current.offsetWidth,
380
+ height: containerRef.current.offsetHeight
381
+ });
382
+ };
383
+ updateDimensions();
384
+ const resizeObserver = new ResizeObserver(updateDimensions);
385
+ resizeObserver.observe(containerRef.current);
386
+ return () => {
387
+ resizeObserver.disconnect();
388
+ };
389
+ }, [positioningCoordinator]);
390
+ React26.useEffect(() => {
391
+ return () => {
392
+ positioningCoordinator.destroy();
393
+ };
394
+ }, [positioningCoordinator]);
395
+ React26.useEffect(() => {
448
396
  if (!containerRef.current || mapRef.current) return;
449
397
  try {
450
398
  const map = new maplibregl.Map({
@@ -479,12 +427,45 @@ var Map2 = React25.forwardRef(
479
427
  }),
480
428
  navigationControlPosition
481
429
  );
430
+ positioningCoordinator.register({
431
+ id: "maplibre-navigation-control",
432
+ type: "navigation",
433
+ isBuiltIn: true,
434
+ dimensions: { width: 29, height: 91 },
435
+ position: {
436
+ primary: navigationControlPosition
437
+ },
438
+ priority: "critical",
439
+ zLayer: "base"
440
+ });
482
441
  }
483
442
  if (scaleControl) {
484
443
  map.addControl(new maplibregl.ScaleControl({ unit: "metric" }), scaleControlPosition);
444
+ positioningCoordinator.register({
445
+ id: "maplibre-scale-control",
446
+ type: "scale",
447
+ isBuiltIn: true,
448
+ dimensions: { width: 100, height: 20 },
449
+ position: {
450
+ primary: scaleControlPosition
451
+ },
452
+ priority: "critical",
453
+ zLayer: "base"
454
+ });
485
455
  }
486
456
  if (fullscreenControl) {
487
457
  map.addControl(new maplibregl.FullscreenControl(), fullscreenControlPosition);
458
+ positioningCoordinator.register({
459
+ id: "maplibre-fullscreen-control",
460
+ type: "custom",
461
+ isBuiltIn: true,
462
+ dimensions: { width: 29, height: 29 },
463
+ position: {
464
+ primary: fullscreenControlPosition
465
+ },
466
+ priority: "critical",
467
+ zLayer: "base"
468
+ });
488
469
  }
489
470
  if (geolocateControl) {
490
471
  map.addControl(
@@ -494,6 +475,17 @@ var Map2 = React25.forwardRef(
494
475
  }),
495
476
  geolocateControlPosition
496
477
  );
478
+ positioningCoordinator.register({
479
+ id: "maplibre-geolocate-control",
480
+ type: "custom",
481
+ isBuiltIn: true,
482
+ dimensions: { width: 29, height: 29 },
483
+ position: {
484
+ primary: geolocateControlPosition
485
+ },
486
+ priority: "critical",
487
+ zLayer: "base"
488
+ });
497
489
  }
498
490
  map.on("load", () => {
499
491
  setMapLoaded(true);
@@ -524,8 +516,8 @@ var Map2 = React25.forwardRef(
524
516
  onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
525
517
  }
526
518
  }, []);
527
- const styleInitialized = React25.useRef(false);
528
- React25.useEffect(() => {
519
+ const styleInitialized = React26.useRef(false);
520
+ React26.useEffect(() => {
529
521
  if (!mapRef.current || !mapLoaded) return;
530
522
  if (!styleInitialized.current) {
531
523
  styleInitialized.current = true;
@@ -534,12 +526,12 @@ var Map2 = React25.forwardRef(
534
526
  if (activeStyleOverrideRef.current) return;
535
527
  mapRef.current.setStyle(mapStyle);
536
528
  }, [mapStyle, mapLoaded]);
537
- React25.useEffect(() => {
529
+ React26.useEffect(() => {
538
530
  if (customStyle) {
539
531
  activeStyleOverrideRef.current = null;
540
532
  }
541
533
  }, [customStyle]);
542
- React25.useEffect(() => {
534
+ React26.useEffect(() => {
543
535
  const map = mapRef.current;
544
536
  if (!map || !mapLoaded) return;
545
537
  const createEventParams = (e) => ({
@@ -656,12 +648,9 @@ var Map2 = React25.forwardRef(
656
648
  value: {
657
649
  map: mapRef.current,
658
650
  loaded: mapLoaded,
659
- controlOffsets,
660
- registerControl,
661
- unregisterControl,
662
- getCustomControlOffset,
663
651
  styleVersion,
664
- setMapStyle
652
+ setMapStyle,
653
+ positioningCoordinator
665
654
  },
666
655
  children: [
667
656
  /* @__PURE__ */ jsx("div", { ref: containerRef, className: "absolute inset-0" }),
@@ -694,9 +683,9 @@ var Source = ({
694
683
  children
695
684
  }) => {
696
685
  const { map, loaded, styleVersion } = useMap();
697
- const sourceAdded = React25.useRef(false);
698
- const initialFitDone = React25.useRef(false);
699
- const fitBoundsParamsRef = React25.useRef({
686
+ const sourceAdded = React26.useRef(false);
687
+ const initialFitDone = React26.useRef(false);
688
+ const fitBoundsParamsRef = React26.useRef({
700
689
  shouldFitBounds,
701
690
  data,
702
691
  fitBoundsPadding,
@@ -712,7 +701,7 @@ var Source = ({
712
701
  fitBoundsAnimate,
713
702
  type
714
703
  };
715
- const performFitBounds = React25.useCallback(
704
+ const performFitBounds = React26.useCallback(
716
705
  (cancelledRef) => {
717
706
  const params = fitBoundsParamsRef.current;
718
707
  if (cancelledRef.current || !params.shouldFitBounds || initialFitDone.current) return;
@@ -756,7 +745,7 @@ var Source = ({
756
745
  },
757
746
  [map]
758
747
  );
759
- React25.useEffect(() => {
748
+ React26.useEffect(() => {
760
749
  if (!map || !loaded || sourceAdded.current) return;
761
750
  if (map.getSource(id)) {
762
751
  sourceAdded.current = true;
@@ -906,7 +895,7 @@ var Source = ({
906
895
  styleVersion
907
896
  // re-add source after basemap style changes
908
897
  ]);
909
- React25.useEffect(() => {
898
+ React26.useEffect(() => {
910
899
  if (!map || !loaded || !sourceAdded.current || type !== "geojson") return;
911
900
  const source = map.getSource(id);
912
901
  if (!source) return;
@@ -938,7 +927,7 @@ var Source = ({
938
927
  return /* @__PURE__ */ jsx(Fragment, { children });
939
928
  };
940
929
  Source.displayName = "Source";
941
- var Marker = React25.forwardRef(
930
+ var Marker = React26.forwardRef(
942
931
  ({
943
932
  id,
944
933
  coordinates,
@@ -954,27 +943,27 @@ var Marker = React25.forwardRef(
954
943
  children
955
944
  }, ref) => {
956
945
  const { map, loaded } = useMap();
957
- const markerRef = React25.useRef(null);
958
- const elementRef = React25.useRef(null);
959
- const originalLngLatRef = React25.useRef();
960
- const clickHandlerRef = React25.useRef(null);
961
- const [mounted, setMounted] = React25.useState(false);
962
- const onClickRef = React25.useRef(onClick);
946
+ const markerRef = React26.useRef(null);
947
+ const elementRef = React26.useRef(null);
948
+ const originalLngLatRef = React26.useRef();
949
+ const clickHandlerRef = React26.useRef(null);
950
+ const [mounted, setMounted] = React26.useState(false);
951
+ const onClickRef = React26.useRef(onClick);
963
952
  onClickRef.current = onClick;
964
- const onDragRef = React25.useRef(onDrag);
953
+ const onDragRef = React26.useRef(onDrag);
965
954
  onDragRef.current = onDrag;
966
- const onDragEndRef = React25.useRef(onDragEnd);
955
+ const onDragEndRef = React26.useRef(onDragEnd);
967
956
  onDragEndRef.current = onDragEnd;
968
- React25.useEffect(() => {
957
+ React26.useEffect(() => {
969
958
  setMounted(true);
970
959
  return () => setMounted(false);
971
960
  }, []);
972
- React25.useEffect(() => {
961
+ React26.useEffect(() => {
973
962
  if (children && !elementRef.current) {
974
963
  elementRef.current = document.createElement("div");
975
964
  }
976
965
  }, [children]);
977
- React25.useEffect(() => {
966
+ React26.useEffect(() => {
978
967
  if (!map || !loaded || !mounted) return;
979
968
  if (markerRef.current) return;
980
969
  const markerOptions = {
@@ -1058,17 +1047,17 @@ var Marker = React25.forwardRef(
1058
1047
  }
1059
1048
  };
1060
1049
  }, [map, loaded, mounted]);
1061
- React25.useEffect(() => {
1050
+ React26.useEffect(() => {
1062
1051
  if (markerRef.current) {
1063
1052
  markerRef.current.setLngLat(coordinates);
1064
1053
  }
1065
1054
  }, [coordinates]);
1066
- React25.useEffect(() => {
1055
+ React26.useEffect(() => {
1067
1056
  if (markerRef.current) {
1068
1057
  markerRef.current.setDraggable(draggable);
1069
1058
  }
1070
1059
  }, [draggable]);
1071
- React25.useEffect(() => {
1060
+ React26.useEffect(() => {
1072
1061
  if (markerRef.current && rotation !== void 0) {
1073
1062
  markerRef.current.setRotation(rotation);
1074
1063
  }
@@ -1114,7 +1103,7 @@ function panToFitPopup(map, popup, padding) {
1114
1103
  });
1115
1104
  }
1116
1105
  }
1117
- var Popup = React25.forwardRef(
1106
+ var Popup = React26.forwardRef(
1118
1107
  ({
1119
1108
  coordinates,
1120
1109
  closeButton = true,
@@ -1132,25 +1121,25 @@ var Popup = React25.forwardRef(
1132
1121
  children
1133
1122
  }, ref) => {
1134
1123
  const { map, loaded } = useMap();
1135
- const popupRef = React25.useRef(null);
1136
- const onOpenRef = React25.useRef(onOpen);
1124
+ const popupRef = React26.useRef(null);
1125
+ const onOpenRef = React26.useRef(onOpen);
1137
1126
  onOpenRef.current = onOpen;
1138
- const onCloseRef = React25.useRef(onClose);
1127
+ const onCloseRef = React26.useRef(onClose);
1139
1128
  onCloseRef.current = onClose;
1140
- const coordinatesRef = React25.useRef(coordinates);
1129
+ const coordinatesRef = React26.useRef(coordinates);
1141
1130
  coordinatesRef.current = coordinates;
1142
- const containerRef = React25.useRef(null);
1131
+ const containerRef = React26.useRef(null);
1143
1132
  if (!containerRef.current && typeof document !== "undefined") {
1144
1133
  containerRef.current = document.createElement("div");
1145
1134
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1146
1135
  }
1147
- const [contentReady, setContentReady] = React25.useState(false);
1148
- const contentCallbackRef = React25.useCallback((node) => {
1136
+ const [contentReady, setContentReady] = React26.useState(false);
1137
+ const contentCallbackRef = React26.useCallback((node) => {
1149
1138
  if (node && containerRef.current) {
1150
1139
  setContentReady(true);
1151
1140
  }
1152
1141
  }, []);
1153
- React25.useEffect(() => {
1142
+ React26.useEffect(() => {
1154
1143
  if (!map || !loaded || !containerRef.current) return;
1155
1144
  const popup = new maplibregl.Popup({
1156
1145
  closeButton,
@@ -1190,7 +1179,7 @@ var Popup = React25.forwardRef(
1190
1179
  maxWidth,
1191
1180
  focusAfterOpen
1192
1181
  ]);
1193
- React25.useEffect(() => {
1182
+ React26.useEffect(() => {
1194
1183
  if (!popupRef.current || !ref) return;
1195
1184
  if (typeof ref === "function") {
1196
1185
  ref(popupRef.current);
@@ -1198,12 +1187,12 @@ var Popup = React25.forwardRef(
1198
1187
  ref.current = popupRef.current;
1199
1188
  }
1200
1189
  }, [ref]);
1201
- React25.useEffect(() => {
1190
+ React26.useEffect(() => {
1202
1191
  if (popupRef.current) {
1203
1192
  popupRef.current.setLngLat(coordinates);
1204
1193
  }
1205
1194
  }, [coordinates]);
1206
- React25.useEffect(() => {
1195
+ React26.useEffect(() => {
1207
1196
  if (!map || !popupRef.current || !contentReady) return;
1208
1197
  let rafHandle;
1209
1198
  if (open) {
@@ -1232,7 +1221,7 @@ var Popup = React25.forwardRef(
1232
1221
  }
1233
1222
  );
1234
1223
  Popup.displayName = "Popup";
1235
- var PopupCard = React25.forwardRef(
1224
+ var PopupCard = React26.forwardRef(
1236
1225
  ({ className, children, ...props }, ref) => {
1237
1226
  return /* @__PURE__ */ jsx("div", { ref, className: cn("bg-popover text-popover-foreground", className), ...props, children });
1238
1227
  }
@@ -1252,7 +1241,7 @@ var badgeVariants = cva("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0
1252
1241
  badgeVariant: "secondary"
1253
1242
  }
1254
1243
  });
1255
- var PopupHeader = React25.forwardRef(
1244
+ var PopupHeader = React26.forwardRef(
1256
1245
  ({ className, title, badge, badgeVariant, ...props }, ref) => {
1257
1246
  return /* @__PURE__ */ jsxs(
1258
1247
  "div",
@@ -1272,13 +1261,13 @@ var PopupHeader = React25.forwardRef(
1272
1261
  }
1273
1262
  );
1274
1263
  PopupHeader.displayName = "PopupHeader";
1275
- var PopupContent = React25.forwardRef(
1264
+ var PopupContent = React26.forwardRef(
1276
1265
  ({ className, children, ...props }, ref) => {
1277
1266
  return /* @__PURE__ */ jsx("div", { ref, className: cn("px-4 py-3 text-sm", className), ...props, children });
1278
1267
  }
1279
1268
  );
1280
1269
  PopupContent.displayName = "PopupContent";
1281
- var PopupFooter = React25.forwardRef(
1270
+ var PopupFooter = React26.forwardRef(
1282
1271
  ({ className, children, ...props }, ref) => {
1283
1272
  return /* @__PURE__ */ jsx(
1284
1273
  "div",
@@ -1313,14 +1302,14 @@ function useLayer({
1313
1302
  hoverThrottleMs = 0
1314
1303
  }) {
1315
1304
  const { map, loaded, styleVersion } = useMap();
1316
- const [layerAdded, setLayerAdded] = React25.useState(false);
1317
- const hoveredFeatureId = React25.useRef(null);
1318
- const lastHoverCallTime = React25.useRef(0);
1319
- const lastMousePosition = React25.useRef(null);
1320
- React25.useEffect(() => {
1305
+ const [layerAdded, setLayerAdded] = React26.useState(false);
1306
+ const hoveredFeatureId = React26.useRef(null);
1307
+ const lastHoverCallTime = React26.useRef(0);
1308
+ const lastMousePosition = React26.useRef(null);
1309
+ React26.useEffect(() => {
1321
1310
  hoveredFeatureId.current = null;
1322
1311
  }, [styleVersion]);
1323
- React25.useEffect(() => {
1312
+ React26.useEffect(() => {
1324
1313
  if (!map || !loaded) return;
1325
1314
  if (!map.getSource(source)) {
1326
1315
  let timeoutId = null;
@@ -1391,24 +1380,24 @@ function useLayer({
1391
1380
  }
1392
1381
  };
1393
1382
  }, [map, loaded, id, source, sourceLayer, type, beforeId, styleVersion]);
1394
- React25.useEffect(() => {
1383
+ React26.useEffect(() => {
1395
1384
  if (!map || !layerAdded) return;
1396
1385
  if (!map.getLayer(id)) return;
1397
1386
  map.setLayoutProperty(id, "visibility", visible ? "visible" : "none");
1398
1387
  }, [map, id, visible, layerAdded]);
1399
- React25.useEffect(() => {
1388
+ React26.useEffect(() => {
1400
1389
  if (!map || !layerAdded) return;
1401
1390
  if (!map.getLayer(id)) return;
1402
1391
  Object.entries(paint).forEach(([key, value]) => {
1403
1392
  map.setPaintProperty(id, key, value);
1404
1393
  });
1405
1394
  }, [map, id, paint, layerAdded]);
1406
- React25.useEffect(() => {
1395
+ React26.useEffect(() => {
1407
1396
  if (!map || !layerAdded || !filter) return;
1408
1397
  if (!map.getLayer(id)) return;
1409
1398
  map.setFilter(id, filter);
1410
1399
  }, [map, id, filter, layerAdded]);
1411
- React25.useEffect(() => {
1400
+ React26.useEffect(() => {
1412
1401
  if (!map || !layerAdded) return;
1413
1402
  const createFeatureParams = (e) => {
1414
1403
  const feature = e.features?.[0];
@@ -1544,7 +1533,7 @@ var FillLayer = ({
1544
1533
  fillTranslate,
1545
1534
  fillAntialias
1546
1535
  }) => {
1547
- const paint = React25.useMemo(() => {
1536
+ const paint = React26.useMemo(() => {
1548
1537
  const p = {};
1549
1538
  if (fillColor !== void 0) p["fill-color"] = fillColor;
1550
1539
  if (fillOpacity !== void 0) p["fill-opacity"] = fillOpacity;
@@ -1565,7 +1554,7 @@ var FillLayer = ({
1565
1554
  fillAntialias,
1566
1555
  opacity
1567
1556
  ]);
1568
- const layout = React25.useMemo(() => ({}), []);
1557
+ const layout = React26.useMemo(() => ({}), []);
1569
1558
  useLayer({
1570
1559
  id,
1571
1560
  source,
@@ -1609,7 +1598,7 @@ var LineLayer = ({
1609
1598
  lineOffset,
1610
1599
  lineGradient
1611
1600
  }) => {
1612
- const paint = React25.useMemo(() => {
1601
+ const paint = React26.useMemo(() => {
1613
1602
  const p = {};
1614
1603
  if (lineColor !== void 0) p["line-color"] = lineColor;
1615
1604
  if (lineWidth !== void 0) p["line-width"] = lineWidth;
@@ -1634,7 +1623,7 @@ var LineLayer = ({
1634
1623
  lineGradient,
1635
1624
  opacity
1636
1625
  ]);
1637
- const layout = React25.useMemo(() => {
1626
+ const layout = React26.useMemo(() => {
1638
1627
  const l = {};
1639
1628
  if (lineCap !== void 0) l["line-cap"] = lineCap;
1640
1629
  if (lineJoin !== void 0) l["line-join"] = lineJoin;
@@ -1683,7 +1672,7 @@ var CircleLayer = ({
1683
1672
  circlePitchScale,
1684
1673
  circleTranslate
1685
1674
  }) => {
1686
- const paint = React25.useMemo(() => {
1675
+ const paint = React26.useMemo(() => {
1687
1676
  const p = {};
1688
1677
  if (circleRadius !== void 0) p["circle-radius"] = circleRadius;
1689
1678
  if (circleColor !== void 0) p["circle-color"] = circleColor;
@@ -1712,7 +1701,7 @@ var CircleLayer = ({
1712
1701
  circleTranslate,
1713
1702
  opacity
1714
1703
  ]);
1715
- const layout = React25.useMemo(() => ({}), []);
1704
+ const layout = React26.useMemo(() => ({}), []);
1716
1705
  useLayer({
1717
1706
  id,
1718
1707
  source,
@@ -1772,7 +1761,7 @@ var SymbolLayer = ({
1772
1761
  symbolSpacing,
1773
1762
  symbolSortKey
1774
1763
  }) => {
1775
- const paint = React25.useMemo(() => {
1764
+ const paint = React26.useMemo(() => {
1776
1765
  const p = {};
1777
1766
  if (iconOpacity !== void 0) p["icon-opacity"] = iconOpacity;
1778
1767
  if (iconColor !== void 0) p["icon-color"] = iconColor;
@@ -1793,7 +1782,7 @@ var SymbolLayer = ({
1793
1782
  textHaloColor,
1794
1783
  textHaloWidth
1795
1784
  ]);
1796
- const layout = React25.useMemo(() => {
1785
+ const layout = React26.useMemo(() => {
1797
1786
  const l = {};
1798
1787
  if (iconImage !== void 0) l["icon-image"] = iconImage;
1799
1788
  if (iconSize !== void 0) l["icon-size"] = iconSize;
@@ -1874,7 +1863,7 @@ var FillExtrusionLayer = ({
1874
1863
  fillExtrusionTranslate,
1875
1864
  fillExtrusionVerticalGradient
1876
1865
  }) => {
1877
- const paint = React25.useMemo(() => {
1866
+ const paint = React26.useMemo(() => {
1878
1867
  const p = {};
1879
1868
  if (fillExtrusionHeight !== void 0) p["fill-extrusion-height"] = fillExtrusionHeight;
1880
1869
  if (fillExtrusionBase !== void 0) p["fill-extrusion-base"] = fillExtrusionBase;
@@ -1900,7 +1889,7 @@ var FillExtrusionLayer = ({
1900
1889
  fillExtrusionVerticalGradient,
1901
1890
  opacity
1902
1891
  ]);
1903
- const layout = React25.useMemo(() => ({}), []);
1892
+ const layout = React26.useMemo(() => ({}), []);
1904
1893
  useLayer({
1905
1894
  id,
1906
1895
  source,
@@ -1939,7 +1928,7 @@ var HeatmapLayer = ({
1939
1928
  heatmapRadius,
1940
1929
  heatmapOpacity
1941
1930
  }) => {
1942
- const paint = React25.useMemo(() => {
1931
+ const paint = React26.useMemo(() => {
1943
1932
  const p = {};
1944
1933
  if (heatmapIntensity !== void 0) p["heatmap-intensity"] = heatmapIntensity;
1945
1934
  if (heatmapWeight !== void 0) p["heatmap-weight"] = heatmapWeight;
@@ -1951,7 +1940,7 @@ var HeatmapLayer = ({
1951
1940
  }
1952
1941
  return p;
1953
1942
  }, [heatmapIntensity, heatmapWeight, heatmapColor, heatmapRadius, heatmapOpacity, opacity]);
1954
- const layout = React25.useMemo(() => ({}), []);
1943
+ const layout = React26.useMemo(() => ({}), []);
1955
1944
  useLayer({
1956
1945
  id,
1957
1946
  source,
@@ -1971,6 +1960,127 @@ var HeatmapLayer = ({
1971
1960
  return null;
1972
1961
  };
1973
1962
  HeatmapLayer.displayName = "HeatmapLayer";
1963
+ function useControlPosition(ref, options) {
1964
+ const {
1965
+ id,
1966
+ type,
1967
+ position,
1968
+ fallbacks,
1969
+ priority = "normal",
1970
+ zLayer = "interactive",
1971
+ hasExpandedState = false,
1972
+ isBuiltIn = false
1973
+ } = options;
1974
+ const { positioningCoordinator } = useMap();
1975
+ const [offset, setOffset] = React26.useState(null);
1976
+ React26.useEffect(() => {
1977
+ if (!ref.current || !positioningCoordinator) return;
1978
+ const element = ref.current;
1979
+ const initialOffset = positioningCoordinator.register({
1980
+ id,
1981
+ type,
1982
+ isBuiltIn,
1983
+ dimensions: {
1984
+ width: element.offsetWidth || 200,
1985
+ height: element.offsetHeight || 100
1986
+ },
1987
+ position: {
1988
+ primary: position,
1989
+ fallbacks
1990
+ },
1991
+ priority,
1992
+ zLayer,
1993
+ hasExpandedState,
1994
+ isExpanded: false
1995
+ });
1996
+ setOffset(initialOffset);
1997
+ const unsubscribe = positioningCoordinator.subscribe((event) => {
1998
+ const newOffset = event.offsets.get(id);
1999
+ if (newOffset) {
2000
+ setOffset(newOffset);
2001
+ }
2002
+ });
2003
+ const resizeObserver = new ResizeObserver(() => {
2004
+ if (!element) return;
2005
+ positioningCoordinator.update(id, {
2006
+ dimensions: {
2007
+ width: element.offsetWidth,
2008
+ height: element.offsetHeight
2009
+ }
2010
+ });
2011
+ });
2012
+ resizeObserver.observe(element);
2013
+ return () => {
2014
+ resizeObserver.disconnect();
2015
+ unsubscribe();
2016
+ positioningCoordinator.unregister(id);
2017
+ };
2018
+ }, [
2019
+ id,
2020
+ type,
2021
+ position,
2022
+ fallbacks,
2023
+ priority,
2024
+ zLayer,
2025
+ hasExpandedState,
2026
+ isBuiltIn,
2027
+ positioningCoordinator,
2028
+ ref
2029
+ ]);
2030
+ React26.useEffect(() => {
2031
+ if (!positioningCoordinator) return;
2032
+ positioningCoordinator.update(id, {
2033
+ position: {
2034
+ primary: position,
2035
+ fallbacks
2036
+ },
2037
+ priority,
2038
+ zLayer
2039
+ });
2040
+ }, [id, position, fallbacks, priority, zLayer, positioningCoordinator]);
2041
+ const setExpanded = React26.useCallback(
2042
+ (isExpanded) => {
2043
+ if (positioningCoordinator) {
2044
+ positioningCoordinator.setExpanded(id, isExpanded);
2045
+ }
2046
+ },
2047
+ [id, positioningCoordinator]
2048
+ );
2049
+ const style = React26.useMemo(() => {
2050
+ if (!offset) {
2051
+ return {
2052
+ position: "absolute",
2053
+ visibility: "hidden"
2054
+ };
2055
+ }
2056
+ const resolvedPosition = offset.position;
2057
+ const isLeftPosition = resolvedPosition.includes("left") || resolvedPosition.includes("center");
2058
+ const isCenterHorizontal = resolvedPosition.includes("center");
2059
+ const baseStyle = {
2060
+ position: "absolute",
2061
+ zIndex: offset.zIndex
2062
+ };
2063
+ if (isCenterHorizontal) {
2064
+ baseStyle.left = offset.x;
2065
+ } else if (isLeftPosition) {
2066
+ baseStyle.left = offset.x;
2067
+ } else {
2068
+ baseStyle.right = offset.x;
2069
+ }
2070
+ if (resolvedPosition.startsWith("bottom")) {
2071
+ baseStyle.bottom = offset.y;
2072
+ } else {
2073
+ baseStyle.top = offset.y;
2074
+ }
2075
+ return baseStyle;
2076
+ }, [offset]);
2077
+ return {
2078
+ offset,
2079
+ setExpanded,
2080
+ style,
2081
+ visible: offset?.visible ?? false
2082
+ };
2083
+ }
1974
2084
  var legendIdCounter = 0;
1975
2085
  var Legend = ({
1976
2086
  title,
@@ -1985,30 +2095,17 @@ var Legend = ({
1985
2095
  class: className,
1986
2096
  onItemClick
1987
2097
  }) => {
1988
- const { controlOffsets, registerControl, unregisterControl } = useMap();
1989
- const [isCollapsed, setIsCollapsed] = React25.useState(initialCollapsed);
1990
- const [customControlOffset, setCustomControlOffset] = React25.useState(0);
1991
- const legendRef = React25.useRef(null);
1992
- const legendIdRef = React25.useRef(`legend-${++legendIdCounter}`);
1993
- React25.useEffect(() => {
1994
- if (!legendRef.current || !registerControl) return;
1995
- const updatePosition = () => {
1996
- if (!legendRef.current) return;
1997
- const height = legendRef.current.offsetHeight;
1998
- const offset = registerControl(legendIdRef.current, position, height);
1999
- setCustomControlOffset(offset);
2000
- };
2001
- updatePosition();
2002
- const observer = new ResizeObserver(updatePosition);
2003
- observer.observe(legendRef.current);
2004
- return () => {
2005
- observer.disconnect();
2006
- unregisterControl?.(legendIdRef.current, position);
2007
- };
2008
- }, [position, registerControl, unregisterControl]);
2009
- const verticalOffsetStyle = React25.useMemo(() => {
2010
- return computeVerticalOffsetStyle(position, customControlOffset);
2011
- }, [customControlOffset, position]);
2098
+ const [isCollapsed, setIsCollapsed] = React26.useState(initialCollapsed);
2099
+ const legendRef = React26.useRef(null);
2100
+ const legendIdRef = React26.useRef(`legend-${++legendIdCounter}`);
2101
+ const { style, visible } = useControlPosition(legendRef, {
2102
+ id: legendIdRef.current,
2103
+ type: "legend",
2104
+ position,
2105
+ priority: "normal",
2106
+ zLayer: "interactive",
2107
+ hasExpandedState: collapsible
2108
+ });
2012
2109
  const handleItemClick = (item, index) => {
2013
2110
  if (onItemClick) {
2014
2111
  onItemClick(item, index);
@@ -2019,26 +2116,22 @@ var Legend = ({
2019
2116
  setIsCollapsed(!isCollapsed);
2020
2117
  }
2021
2118
  };
2022
- const gradientStyle = React25.useMemo(() => {
2119
+ const gradientStyle = React26.useMemo(() => {
2023
2120
  if (type !== "gradient" || gradient.length === 0) return "";
2024
2121
  const stops = gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
2025
2122
  return `linear-gradient(to right, ${stops})`;
2026
2123
  }, [type, gradient]);
2027
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2028
- const computedPositionClasses = React25.useMemo(() => {
2029
- return computePositionClasses(position, hasControlsAtPosition);
2030
- }, [position, hasControlsAtPosition]);
2031
2124
  return /* @__PURE__ */ jsxs(
2032
2125
  "div",
2033
2126
  {
2034
2127
  ref: legendRef,
2035
2128
  className: cn(
2036
- "absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2129
+ "absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2037
2130
  "text-sm min-w-[140px] max-w-[280px]",
2038
- computedPositionClasses,
2131
+ !visible && "invisible",
2039
2132
  className
2040
2133
  ),
2041
- style: verticalOffsetStyle,
2134
+ style,
2042
2135
  children: [
2043
2136
  (title || collapsible) && /* @__PURE__ */ jsxs(
2044
2137
  "button",
@@ -2124,45 +2217,31 @@ var LegendGroup = ({
2124
2217
  allowCollapseAll = false,
2125
2218
  class: className
2126
2219
  }) => {
2127
- const { controlOffsets, registerControl, unregisterControl } = useMap();
2128
- const containerRef = React25.useRef(null);
2129
- const groupIdRef = React25.useRef(`legend-group-${++legendGroupIdCounter}`);
2130
- const [customControlOffset, setCustomControlOffset] = React25.useState(0);
2220
+ const containerRef = React26.useRef(null);
2221
+ const groupIdRef = React26.useRef(`legend-group-${++legendGroupIdCounter}`);
2131
2222
  const getInitialExpanded = () => {
2132
2223
  if (controlledExpanded !== void 0) return controlledExpanded;
2133
2224
  if (defaultExpanded) return defaultExpanded;
2134
2225
  return legends[0]?.id || null;
2135
2226
  };
2136
- const [internalExpanded, setInternalExpanded] = React25.useState(getInitialExpanded);
2227
+ const [internalExpanded, setInternalExpanded] = React26.useState(getInitialExpanded);
2137
2228
  const expandedId = controlledExpanded !== void 0 ? controlledExpanded : internalExpanded;
2229
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2230
+ id: groupIdRef.current,
2231
+ type: "legend-group",
2232
+ position,
2233
+ priority: "normal",
2234
+ zLayer: "interactive",
2235
+ hasExpandedState: true
2236
+ });
2138
2237
  const handleToggle = (id) => {
2139
2238
  const newExpanded = expandedId === id ? allowCollapseAll ? null : id : id;
2140
2239
  if (controlledExpanded === void 0) {
2141
2240
  setInternalExpanded(newExpanded);
2142
2241
  }
2242
+ setExpanded(newExpanded !== null);
2143
2243
  onExpandedChange?.(newExpanded);
2144
2244
  };
2145
- React25.useEffect(() => {
2146
- if (!containerRef.current || !registerControl) return;
2147
- const timeoutId = setTimeout(() => {
2148
- if (containerRef.current) {
2149
- const height = containerRef.current.offsetHeight;
2150
- const offset = registerControl(groupIdRef.current, position, height);
2151
- setCustomControlOffset(offset);
2152
- }
2153
- }, 50);
2154
- return () => {
2155
- clearTimeout(timeoutId);
2156
- unregisterControl?.(groupIdRef.current, position);
2157
- };
2158
- }, [position, expandedId, registerControl, unregisterControl]);
2159
- const verticalOffsetStyle = React25.useMemo(() => {
2160
- return computeVerticalOffsetStyle(position, customControlOffset);
2161
- }, [customControlOffset, position]);
2162
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2163
- const computedPositionClasses = React25.useMemo(() => {
2164
- return computePositionClasses(position, hasControlsAtPosition);
2165
- }, [position, hasControlsAtPosition]);
2166
2245
  const getGradientStyle = (legend) => {
2167
2246
  if (legend.type !== "gradient" || !legend.gradient?.length) return "";
2168
2247
  const stops = legend.gradient.map((stop) => `${stop.color} ${stop.position * 100}%`).join(", ");
@@ -2176,12 +2255,12 @@ var LegendGroup = ({
2176
2255
  {
2177
2256
  ref: containerRef,
2178
2257
  className: cn(
2179
- "absolute z-10 bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2258
+ "absolute bg-card rounded-lg shadow-lg border border-black dark:border-gray-400",
2180
2259
  "text-sm min-w-[160px] max-w-[280px]",
2181
- computedPositionClasses,
2260
+ !visible && "invisible",
2182
2261
  className
2183
2262
  ),
2184
- style: verticalOffsetStyle,
2263
+ style,
2185
2264
  children: legends.map((legend, legendIndex) => {
2186
2265
  const isExpanded = expandedId === legend.id;
2187
2266
  const isFirst = legendIndex === 0;
@@ -2282,6 +2361,7 @@ var LegendGroup = ({
2282
2361
  };
2283
2362
  LegendGroup.displayName = "LegendGroup";
2284
2363
  var coordDisplayIdCounter = 0;
2364
+ var NAV_CONTROL_WIDTH = 29;
2285
2365
  var CoordinateDisplay = ({
2286
2366
  position = "bottom-right",
2287
2367
  format = "decimal",
@@ -2290,33 +2370,40 @@ var CoordinateDisplay = ({
2290
2370
  showBearing = false,
2291
2371
  class: className
2292
2372
  }) => {
2293
- const { map, loaded, controlOffsets, registerControl, unregisterControl } = useMap();
2294
- const [cursorLngLat, setCursorLngLat] = React25.useState(null);
2295
- const [currentZoom, setCurrentZoom] = React25.useState(0);
2296
- const [currentBearing, setCurrentBearing] = React25.useState(0);
2297
- const [customControlOffset, setCustomControlOffset] = React25.useState(0);
2298
- const controlRef = React25.useRef(null);
2299
- const controlIdRef = React25.useRef(`coord-display-${++coordDisplayIdCounter}`);
2300
- React25.useEffect(() => {
2301
- if (!controlRef.current || !registerControl) return;
2302
- const updatePosition = () => {
2303
- if (!controlRef.current) return;
2304
- const height = controlRef.current.offsetHeight;
2305
- const offset = registerControl(controlIdRef.current, position, height);
2306
- setCustomControlOffset(offset);
2307
- };
2308
- updatePosition();
2309
- const observer = new ResizeObserver(updatePosition);
2310
- observer.observe(controlRef.current);
2311
- return () => {
2312
- observer.disconnect();
2313
- unregisterControl?.(controlIdRef.current, position);
2314
- };
2315
- }, [position, registerControl, unregisterControl]);
2316
- const verticalOffsetStyle = React25.useMemo(() => {
2317
- return computeVerticalOffsetStyle(position, customControlOffset);
2318
- }, [customControlOffset, position]);
2319
- const formatCoord = React25.useCallback(
2373
+ const { map, loaded } = useMap();
2374
+ const [cursorLngLat, setCursorLngLat] = React26.useState(null);
2375
+ const [currentZoom, setCurrentZoom] = React26.useState(0);
2376
+ const [currentBearing, setCurrentBearing] = React26.useState(0);
2377
+ const controlRef = React26.useRef(null);
2378
+ const controlIdRef = React26.useRef(`coord-display-${++coordDisplayIdCounter}`);
2379
+ const { style, visible } = useControlPosition(controlRef, {
2380
+ id: controlIdRef.current,
2381
+ type: "coordinate-display",
2382
+ position,
2383
+ priority: "critical",
2384
+ zLayer: "base"
2385
+ });
2386
+ const adjustedStyle = React26.useMemo(() => {
2387
+ if (!style) return style;
2388
+ if (position === "top-right") {
2389
+ const rightOffset = NAV_CONTROL_WIDTH + STACK_GAP + EDGE_MARGIN;
2390
+ return {
2391
+ ...style,
2392
+ top: EDGE_MARGIN,
2393
+ right: rightOffset
2394
+ };
2395
+ }
2396
+ if (position === "bottom-right") {
2397
+ const ATTRIBUTION_HEIGHT = 32;
2398
+ const bottomOffset = EDGE_MARGIN + ATTRIBUTION_HEIGHT;
2399
+ return {
2400
+ ...style,
2401
+ bottom: bottomOffset
2402
+ };
2403
+ }
2404
+ return style;
2405
+ }, [position, style]);
2406
+ const formatCoord = React26.useCallback(
2320
2407
  (lngLat) => {
2321
2408
  return formatCoordinates(lngLat, precision, format);
2322
2409
  },
@@ -2329,11 +2416,7 @@ var CoordinateDisplay = ({
2329
2416
  const normalized = (bearing % 360 + 360) % 360;
2330
2417
  return `${normalized.toFixed(0)}\xB0`;
2331
2418
  };
2332
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2333
- const computedPositionClasses = React25.useMemo(() => {
2334
- return computePositionClasses(position, hasControlsAtPosition);
2335
- }, [position, hasControlsAtPosition]);
2336
- React25.useEffect(() => {
2419
+ React26.useEffect(() => {
2337
2420
  if (!map || !loaded) return;
2338
2421
  setCurrentZoom(map.getZoom());
2339
2422
  setCurrentBearing(map.getBearing());
@@ -2360,14 +2443,14 @@ var CoordinateDisplay = ({
2360
2443
  {
2361
2444
  ref: controlRef,
2362
2445
  className: cn(
2363
- "absolute z-10 bg-card rounded px-2 py-1",
2446
+ "absolute bg-card rounded px-2 py-1",
2364
2447
  "text-xs font-mono text-muted-foreground",
2365
2448
  "border border-black dark:border-gray-400 shadow-sm",
2366
2449
  "flex items-center gap-3",
2367
- computedPositionClasses,
2450
+ !visible && "invisible",
2368
2451
  className
2369
2452
  ),
2370
- style: verticalOffsetStyle,
2453
+ style: adjustedStyle,
2371
2454
  children: [
2372
2455
  cursorLngLat ? /* @__PURE__ */ jsx("span", { title: "Cursor coordinates", children: formatCoord(cursorLngLat) }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground/60", children: "Move cursor over map" }),
2373
2456
  showZoom && /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -2399,17 +2482,16 @@ var BasemapSwitcher = ({
2399
2482
  position = "bottom-right",
2400
2483
  class: className
2401
2484
  }) => {
2402
- const { controlOffsets, registerControl, unregisterControl, setMapStyle } = useMap();
2403
- const [isOpen, setIsOpen] = React25.useState(false);
2404
- const [internalActiveId, setInternalActiveId] = React25.useState(
2485
+ const { setMapStyle } = useMap();
2486
+ const [isOpen, setIsOpen] = React26.useState(false);
2487
+ const [internalActiveId, setInternalActiveId] = React26.useState(
2405
2488
  defaultBasemapId
2406
2489
  );
2407
- const [customControlOffset, setCustomControlOffset] = React25.useState(0);
2408
- const containerRef = React25.useRef(null);
2409
- const panelRef = React25.useRef(null);
2410
- const switcherIdRef = React25.useRef(`basemap-switcher-${++switcherIdCounter}`);
2490
+ const containerRef = React26.useRef(null);
2491
+ const panelRef = React26.useRef(null);
2492
+ const switcherIdRef = React26.useRef(`basemap-switcher-${++switcherIdCounter}`);
2411
2493
  const sourceBasemaps = basemaps ?? FREE_BASEMAPS;
2412
- const availableBasemaps = React25.useMemo(() => {
2494
+ const availableBasemaps = React26.useMemo(() => {
2413
2495
  const available = getAvailableBasemaps(sourceBasemaps, apiKeys);
2414
2496
  if (extraBasemaps?.length) {
2415
2497
  return [...available, ...getAvailableBasemaps(extraBasemaps, apiKeys)];
@@ -2417,66 +2499,59 @@ var BasemapSwitcher = ({
2417
2499
  return available;
2418
2500
  }, [sourceBasemaps, extraBasemaps, apiKeys]);
2419
2501
  const currentActiveId = activeBasemapId ?? internalActiveId ?? availableBasemaps[0]?.id;
2420
- React25.useEffect(() => {
2421
- if (!containerRef.current || !registerControl) return;
2422
- const updatePosition = () => {
2423
- if (!containerRef.current) return;
2424
- const height = containerRef.current.offsetHeight;
2425
- const offset = registerControl(switcherIdRef.current, position, height);
2426
- setCustomControlOffset(offset);
2427
- };
2428
- updatePosition();
2429
- const observer = new ResizeObserver(updatePosition);
2430
- observer.observe(containerRef.current);
2431
- return () => {
2432
- observer.disconnect();
2433
- unregisterControl?.(switcherIdRef.current, position);
2434
- };
2435
- }, [position, registerControl, unregisterControl]);
2436
- React25.useEffect(() => {
2502
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2503
+ id: switcherIdRef.current,
2504
+ type: "basemap-switcher",
2505
+ position,
2506
+ priority: "normal",
2507
+ zLayer: "interactive",
2508
+ hasExpandedState: true
2509
+ });
2510
+ React26.useEffect(() => {
2437
2511
  if (!isOpen) return;
2438
2512
  const handleMouseDown = (e) => {
2439
2513
  if (containerRef.current && !containerRef.current.contains(e.target)) {
2440
2514
  setIsOpen(false);
2515
+ setExpanded(false);
2441
2516
  }
2442
2517
  };
2443
2518
  document.addEventListener("mousedown", handleMouseDown);
2444
2519
  return () => document.removeEventListener("mousedown", handleMouseDown);
2445
- }, [isOpen]);
2446
- React25.useEffect(() => {
2520
+ }, [isOpen, setExpanded]);
2521
+ React26.useEffect(() => {
2447
2522
  if (!isOpen) return;
2448
2523
  const handleKeyDown = (e) => {
2449
2524
  if (e.key === "Escape") {
2450
2525
  setIsOpen(false);
2526
+ setExpanded(false);
2451
2527
  }
2452
2528
  };
2453
2529
  document.addEventListener("keydown", handleKeyDown);
2454
2530
  return () => document.removeEventListener("keydown", handleKeyDown);
2455
- }, [isOpen]);
2531
+ }, [isOpen, setExpanded]);
2456
2532
  const handleSelect = (basemap) => {
2457
- const style = resolveBasemapStyle(basemap, apiKeys);
2458
- if (!style) return;
2533
+ const resolvedStyle = resolveBasemapStyle(basemap, apiKeys);
2534
+ if (!resolvedStyle) return;
2459
2535
  if (!activeBasemapId) {
2460
2536
  setInternalActiveId(basemap.id);
2461
2537
  }
2462
- setMapStyle?.(style);
2538
+ setMapStyle?.(resolvedStyle);
2463
2539
  onBasemapChange?.(basemap);
2464
2540
  setIsOpen(false);
2541
+ setExpanded(false);
2542
+ };
2543
+ const handleToggle = () => {
2544
+ const newState = !isOpen;
2545
+ setIsOpen(newState);
2546
+ setExpanded(newState);
2465
2547
  };
2466
- const verticalOffsetStyle = React25.useMemo(() => {
2467
- return computeVerticalOffsetStyle(position, customControlOffset);
2468
- }, [customControlOffset, position]);
2469
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2470
- const computedPositionClasses = React25.useMemo(() => {
2471
- return computePositionClasses(position, hasControlsAtPosition);
2472
- }, [position, hasControlsAtPosition]);
2473
2548
  const isTop = position.startsWith("top");
2474
2549
  return /* @__PURE__ */ jsxs(
2475
2550
  "div",
2476
2551
  {
2477
2552
  ref: containerRef,
2478
- className: cn("absolute z-10", computedPositionClasses, className),
2479
- style: verticalOffsetStyle,
2553
+ className: cn("absolute", !visible && "invisible", className),
2554
+ style,
2480
2555
  children: [
2481
2556
  isOpen && /* @__PURE__ */ jsx(
2482
2557
  "div",
@@ -2551,7 +2626,7 @@ var BasemapSwitcher = ({
2551
2626
  "hover:bg-muted transition-colors cursor-pointer",
2552
2627
  "text-foreground"
2553
2628
  ),
2554
- onClick: () => setIsOpen(!isOpen),
2629
+ onClick: handleToggle,
2555
2630
  "aria-label": "Switch basemap",
2556
2631
  "aria-expanded": isOpen,
2557
2632
  "aria-haspopup": "true",
@@ -2594,22 +2669,28 @@ var LayerManager = ({
2594
2669
  onLayerChange,
2595
2670
  class: className
2596
2671
  }) => {
2597
- const { controlOffsets, registerControl, unregisterControl } = useMap();
2598
2672
  const { isDark } = useMapTheme();
2599
- const [isOpen, setIsOpen] = React25.useState(false);
2600
- const [layerStates, setLayerStates] = React25.useState(
2673
+ const [isOpen, setIsOpen] = React26.useState(false);
2674
+ const [layerStates, setLayerStates] = React26.useState(
2601
2675
  () => createInitialLayerStates(layers, initialActiveLayers)
2602
2676
  );
2603
- const [searchQuery, setSearchQuery] = React25.useState("");
2604
- const [activeCategory, setActiveCategory] = React25.useState("all");
2605
- const [customControlOffset, setCustomControlOffset] = React25.useState(0);
2606
- const [expandedOpacity, setExpandedOpacity] = React25.useState(null);
2607
- const [draggedId, setDraggedId] = React25.useState(null);
2608
- const [dragOver, setDragOver] = React25.useState(null);
2609
- const containerRef = React25.useRef(null);
2610
- const managerIdRef = React25.useRef(`layer-manager-${++managerIdCounter}`);
2611
- const lastLayerIdsRef = React25.useRef(new Set(layers.map((l) => l.id)));
2612
- React25.useEffect(() => {
2677
+ const [searchQuery, setSearchQuery] = React26.useState("");
2678
+ const [activeCategory, setActiveCategory] = React26.useState("all");
2679
+ const [expandedOpacity, setExpandedOpacity] = React26.useState(null);
2680
+ const [draggedId, setDraggedId] = React26.useState(null);
2681
+ const [dragOver, setDragOver] = React26.useState(null);
2682
+ const containerRef = React26.useRef(null);
2683
+ const managerIdRef = React26.useRef(`layer-manager-${++managerIdCounter}`);
2684
+ const lastLayerIdsRef = React26.useRef(new Set(layers.map((l) => l.id)));
2685
+ const { style, visible, setExpanded } = useControlPosition(containerRef, {
2686
+ id: managerIdRef.current,
2687
+ type: "layer-manager",
2688
+ position,
2689
+ priority: "high",
2690
+ zLayer: "interactive",
2691
+ hasExpandedState: true
2692
+ });
2693
+ React26.useEffect(() => {
2613
2694
  const currentLayerIds = new Set(layers.map((l) => l.id));
2614
2695
  const hasNewLayers = layers.some((l) => !lastLayerIdsRef.current.has(l.id));
2615
2696
  const hasRemovedLayers = Array.from(lastLayerIdsRef.current).some(
@@ -2640,8 +2721,8 @@ var LayerManager = ({
2640
2721
  lastLayerIdsRef.current = currentLayerIds;
2641
2722
  }
2642
2723
  }, [layers, initialActiveLayers]);
2643
- const categories = React25.useMemo(() => getLayerCategories(layers), [layers]);
2644
- const filteredLayers = React25.useMemo(() => {
2724
+ const categories = React26.useMemo(() => getLayerCategories(layers), [layers]);
2725
+ const filteredLayers = React26.useMemo(() => {
2645
2726
  let result = layers;
2646
2727
  if (searchQuery) {
2647
2728
  result = searchLayers(result, searchQuery);
@@ -2655,47 +2736,33 @@ var LayerManager = ({
2655
2736
  return orderA - orderB;
2656
2737
  });
2657
2738
  }, [layers, searchQuery, activeCategory, layerStates]);
2658
- const layerGroups = React25.useMemo(
2739
+ const layerGroups = React26.useMemo(
2659
2740
  () => showCategories ? groupLayersByCategory(filteredLayers) : null,
2660
2741
  [filteredLayers, showCategories]
2661
2742
  );
2662
- React25.useEffect(() => {
2663
- if (!containerRef.current || !registerControl) return;
2664
- const updatePosition = () => {
2665
- if (!containerRef.current) return;
2666
- const height = containerRef.current.offsetHeight;
2667
- const offset = registerControl(managerIdRef.current, position, height);
2668
- setCustomControlOffset(offset);
2669
- };
2670
- updatePosition();
2671
- const observer = new ResizeObserver(updatePosition);
2672
- observer.observe(containerRef.current);
2673
- return () => {
2674
- observer.disconnect();
2675
- unregisterControl?.(managerIdRef.current, position);
2676
- };
2677
- }, [position, registerControl, unregisterControl]);
2678
- React25.useEffect(() => {
2743
+ React26.useEffect(() => {
2679
2744
  if (!isOpen) return;
2680
2745
  const handleMouseDown = (e) => {
2681
2746
  if (containerRef.current && !containerRef.current.contains(e.target)) {
2682
2747
  setIsOpen(false);
2748
+ setExpanded(false);
2683
2749
  }
2684
2750
  };
2685
2751
  document.addEventListener("mousedown", handleMouseDown);
2686
2752
  return () => document.removeEventListener("mousedown", handleMouseDown);
2687
- }, [isOpen]);
2688
- React25.useEffect(() => {
2753
+ }, [isOpen, setExpanded]);
2754
+ React26.useEffect(() => {
2689
2755
  if (!isOpen) return;
2690
2756
  const handleKeyDown = (e) => {
2691
2757
  if (e.key === "Escape") {
2692
2758
  setIsOpen(false);
2759
+ setExpanded(false);
2693
2760
  }
2694
2761
  };
2695
2762
  document.addEventListener("keydown", handleKeyDown);
2696
2763
  return () => document.removeEventListener("keydown", handleKeyDown);
2697
- }, [isOpen]);
2698
- const handleToggleLayer = React25.useCallback(
2764
+ }, [isOpen, setExpanded]);
2765
+ const handleToggleLayer = React26.useCallback(
2699
2766
  (layerId) => {
2700
2767
  setLayerStates((prev) => {
2701
2768
  const newStates = toggleLayerVisibility(prev, layerId);
@@ -2708,7 +2775,7 @@ var LayerManager = ({
2708
2775
  },
2709
2776
  [onLayerChange]
2710
2777
  );
2711
- const handleOpacityChange = React25.useCallback(
2778
+ const handleOpacityChange = React26.useCallback(
2712
2779
  (layerId, opacity) => {
2713
2780
  setLayerStates((prev) => {
2714
2781
  const newStates = setLayerOpacity(prev, layerId, opacity);
@@ -2721,12 +2788,12 @@ var LayerManager = ({
2721
2788
  },
2722
2789
  [onLayerChange]
2723
2790
  );
2724
- const handleDragStart = React25.useCallback((e, layerId) => {
2791
+ const handleDragStart = React26.useCallback((e, layerId) => {
2725
2792
  setDraggedId(layerId);
2726
2793
  e.dataTransfer.effectAllowed = "move";
2727
2794
  e.dataTransfer.setData("text/plain", layerId);
2728
2795
  }, []);
2729
- const handleDragOver = React25.useCallback(
2796
+ const handleDragOver = React26.useCallback(
2730
2797
  (e, layerId) => {
2731
2798
  e.preventDefault();
2732
2799
  e.dataTransfer.dropEffect = "move";
@@ -2746,14 +2813,14 @@ var LayerManager = ({
2746
2813
  },
2747
2814
  [draggedId, dragOver]
2748
2815
  );
2749
- const handleDragLeave = React25.useCallback(() => {
2816
+ const handleDragLeave = React26.useCallback(() => {
2750
2817
  setDragOver(null);
2751
2818
  }, []);
2752
- const handleDragEnd = React25.useCallback(() => {
2819
+ const handleDragEnd = React26.useCallback(() => {
2753
2820
  setDraggedId(null);
2754
2821
  setDragOver(null);
2755
2822
  }, []);
2756
- const handleDrop = React25.useCallback(
2823
+ const handleDrop = React26.useCallback(
2757
2824
  (e, targetLayerId) => {
2758
2825
  e.preventDefault();
2759
2826
  const sourceLayerId = e.dataTransfer.getData("text/plain");
@@ -2783,13 +2850,6 @@ var LayerManager = ({
2783
2850
  },
2784
2851
  [layerStates, onLayerChange, dragOver]
2785
2852
  );
2786
- const verticalOffsetStyle = React25.useMemo(() => {
2787
- return computeVerticalOffsetStyle(position, customControlOffset);
2788
- }, [customControlOffset, position]);
2789
- const hasControlsAtPosition = (controlOffsets?.[position] ?? 0) > 0;
2790
- const computedPositionClasses = React25.useMemo(() => {
2791
- return computePositionClasses(position, hasControlsAtPosition);
2792
- }, [position, hasControlsAtPosition]);
2793
2853
  const isTop = position.startsWith("top");
2794
2854
  const renderLayer = (layer, state) => {
2795
2855
  if (!state.visible) return null;
@@ -3000,6 +3060,11 @@ var LayerManager = ({
3000
3060
  ] }) });
3001
3061
  };
3002
3062
  const visibleLayerStates = getLayerStatesArray(layerStates).filter((s) => s.visible);
3063
+ const handleToggle = () => {
3064
+ const newState = !isOpen;
3065
+ setIsOpen(newState);
3066
+ setExpanded(newState);
3067
+ };
3003
3068
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3004
3069
  visibleLayerStates.map((state) => {
3005
3070
  const layer = layers.find((l) => l.id === state.id);
@@ -3009,8 +3074,8 @@ var LayerManager = ({
3009
3074
  "div",
3010
3075
  {
3011
3076
  ref: containerRef,
3012
- className: cn("absolute z-10", computedPositionClasses, className),
3013
- style: verticalOffsetStyle,
3077
+ className: cn("absolute", !visible && "invisible", className),
3078
+ style,
3014
3079
  children: [
3015
3080
  isOpen && /* @__PURE__ */ jsxs(
3016
3081
  "div",
@@ -3088,7 +3153,7 @@ var LayerManager = ({
3088
3153
  if (catLayers.length === 0) return null;
3089
3154
  return /* @__PURE__ */ jsxs("div", { children: [
3090
3155
  /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider", children: CATEGORY_META[cat].label }),
3091
- catLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
3156
+ catLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
3092
3157
  renderLayerItem(layer),
3093
3158
  renderOpacitySlider(layer.id)
3094
3159
  ] }, layer.id))
@@ -3096,7 +3161,7 @@ var LayerManager = ({
3096
3161
  })
3097
3162
  ) : (
3098
3163
  // Flat list
3099
- filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React25.Fragment, { children: [
3164
+ filteredLayers.map((layer) => /* @__PURE__ */ jsxs(React26.Fragment, { children: [
3100
3165
  renderLayerItem(layer),
3101
3166
  renderOpacitySlider(layer.id)
3102
3167
  ] }, layer.id))
@@ -3116,7 +3181,7 @@ var LayerManager = ({
3116
3181
  "hover:bg-muted transition-colors cursor-pointer",
3117
3182
  "text-foreground"
3118
3183
  ),
3119
- onClick: () => setIsOpen(!isOpen),
3184
+ onClick: handleToggle,
3120
3185
  "aria-label": "Toggle layer manager",
3121
3186
  "aria-expanded": isOpen,
3122
3187
  "aria-haspopup": "true",
@@ -3156,9 +3221,9 @@ var DeckOverlay = ({
3156
3221
  deckProps = {}
3157
3222
  }) => {
3158
3223
  const { map, loaded } = useMap();
3159
- const overlayRef = React25.useRef(null);
3160
- const MapboxOverlayRef = React25.useRef(null);
3161
- React25.useEffect(() => {
3224
+ const overlayRef = React26.useRef(null);
3225
+ const MapboxOverlayRef = React26.useRef(null);
3226
+ React26.useEffect(() => {
3162
3227
  if (!map || !loaded) return;
3163
3228
  let cancelled = false;
3164
3229
  const initOverlay = async () => {
@@ -3198,12 +3263,12 @@ var DeckOverlay = ({
3198
3263
  }
3199
3264
  };
3200
3265
  }, [map, loaded, interleaved]);
3201
- React25.useEffect(() => {
3266
+ React26.useEffect(() => {
3202
3267
  if (overlayRef.current && "setProps" in overlayRef.current) {
3203
3268
  overlayRef.current.setProps({ layers });
3204
3269
  }
3205
3270
  }, [layers]);
3206
- React25.useEffect(() => {
3271
+ React26.useEffect(() => {
3207
3272
  if (overlayRef.current && "setProps" in overlayRef.current) {
3208
3273
  overlayRef.current.setProps({
3209
3274
  onHover,
@@ -3211,7 +3276,7 @@ var DeckOverlay = ({
3211
3276
  });
3212
3277
  }
3213
3278
  }, [onHover, onClick]);
3214
- React25.useEffect(() => {
3279
+ React26.useEffect(() => {
3215
3280
  if (overlayRef.current && effects && "setProps" in overlayRef.current) {
3216
3281
  overlayRef.current.setProps({ effects });
3217
3282
  }