@page-speed/maps 0.1.3 → 0.1.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.
Files changed (54) hide show
  1. package/README.md +120 -0
  2. package/dist/components/geo-map.cjs +1228 -0
  3. package/dist/components/geo-map.cjs.map +1 -0
  4. package/dist/components/geo-map.d.cts +138 -0
  5. package/dist/components/geo-map.d.ts +138 -0
  6. package/dist/components/geo-map.js +1207 -0
  7. package/dist/components/geo-map.js.map +1 -0
  8. package/dist/components/index.cjs +1350 -0
  9. package/dist/components/index.cjs.map +1 -0
  10. package/dist/components/index.d.cts +5 -0
  11. package/dist/components/index.d.ts +5 -0
  12. package/dist/components/index.js +1326 -0
  13. package/dist/components/index.js.map +1 -0
  14. package/dist/components/map-marker.cjs +137 -0
  15. package/dist/components/map-marker.cjs.map +1 -0
  16. package/dist/components/map-marker.d.cts +76 -0
  17. package/dist/components/map-marker.d.ts +76 -0
  18. package/dist/components/map-marker.js +130 -0
  19. package/dist/components/map-marker.js.map +1 -0
  20. package/dist/core/MapLibre.cjs +46 -20
  21. package/dist/core/MapLibre.cjs.map +1 -1
  22. package/dist/core/MapLibre.js +46 -20
  23. package/dist/core/MapLibre.js.map +1 -1
  24. package/dist/core/index.cjs +46 -20
  25. package/dist/core/index.cjs.map +1 -1
  26. package/dist/core/index.js +46 -20
  27. package/dist/core/index.js.map +1 -1
  28. package/dist/index.cjs +964 -39
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +945 -39
  33. package/dist/index.js.map +1 -1
  34. package/dist/types/index.d.cts +5 -5
  35. package/dist/types/index.d.ts +5 -5
  36. package/dist/utils/cn.cjs +13 -0
  37. package/dist/utils/cn.cjs.map +1 -0
  38. package/dist/utils/cn.d.cts +16 -0
  39. package/dist/utils/cn.d.ts +16 -0
  40. package/dist/utils/cn.js +11 -0
  41. package/dist/utils/cn.js.map +1 -0
  42. package/dist/utils/index.cjs +63 -0
  43. package/dist/utils/index.cjs.map +1 -1
  44. package/dist/utils/index.d.cts +4 -0
  45. package/dist/utils/index.d.ts +4 -0
  46. package/dist/utils/index.js +42 -1
  47. package/dist/utils/index.js.map +1 -1
  48. package/dist/utils/simple-pressable.cjs +63 -0
  49. package/dist/utils/simple-pressable.cjs.map +1 -0
  50. package/dist/utils/simple-pressable.d.cts +20 -0
  51. package/dist/utils/simple-pressable.d.ts +20 -0
  52. package/dist/utils/simple-pressable.js +41 -0
  53. package/dist/utils/simple-pressable.js.map +1 -0
  54. package/package.json +29 -2
@@ -0,0 +1,1228 @@
1
+ 'use strict';
2
+
3
+ var React3 = require('react');
4
+ var maplibre = require('react-map-gl/maplibre');
5
+ var clsx = require('clsx');
6
+ var tailwindMerge = require('tailwind-merge');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
28
+
29
+ // src/utils/getMapLibreStyleUrl.ts
30
+ var MAPLIBRE_DEFAULT_STYLE_URL = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
31
+ var DEFAULT_STADIA_STYLE_URL = "https://tiles.stadiamaps.com/styles/osm_bright.json";
32
+ var STYLE_MAP = {
33
+ default: DEFAULT_STADIA_STYLE_URL,
34
+ "alidade-smooth": "https://tiles.stadiamaps.com/styles/alidade_smooth.json",
35
+ "alidade-smooth-dark": "https://tiles.stadiamaps.com/styles/alidade_smooth_dark.json",
36
+ "maplibre-default": MAPLIBRE_DEFAULT_STYLE_URL,
37
+ "osm-bright": "https://tiles.stadiamaps.com/styles/osm_bright.json",
38
+ "stadia-outdoors": "https://tiles.stadiamaps.com/styles/outdoors.json",
39
+ "stamen-toner": "https://tiles.stadiamaps.com/styles/stamen_toner.json",
40
+ "stamen-terrain": "https://tiles.stadiamaps.com/styles/stamen_terrain.json",
41
+ "stamen-watercolor": "https://tiles.stadiamaps.com/styles/stamen_watercolor.json"
42
+ };
43
+ var HTTP_URL_REGEX = /^https?:\/\//i;
44
+ function isStadiaMapsUrl(url) {
45
+ try {
46
+ const parsed = new URL(url);
47
+ return parsed.hostname === "tiles.stadiamaps.com";
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+ function assertStadiaApiKey(stadiaApiKey) {
53
+ if (!stadiaApiKey.trim()) {
54
+ throw new Error(
55
+ "A non-empty stadiaApiKey is required for Stadia Maps style URLs."
56
+ );
57
+ }
58
+ }
59
+ function appendStadiaApiKey(styleUrl, stadiaApiKey) {
60
+ if (!isStadiaMapsUrl(styleUrl)) {
61
+ return styleUrl;
62
+ }
63
+ assertStadiaApiKey(stadiaApiKey);
64
+ const parsed = new URL(styleUrl);
65
+ if (!parsed.searchParams.has("api_key")) {
66
+ parsed.searchParams.set("api_key", stadiaApiKey);
67
+ }
68
+ return parsed.toString();
69
+ }
70
+ function getMapLibreStyleUrl(value, stadiaApiKey) {
71
+ const normalizedApiKey = stadiaApiKey.trim();
72
+ if (!value || typeof value !== "string") {
73
+ if (!normalizedApiKey) {
74
+ return MAPLIBRE_DEFAULT_STYLE_URL;
75
+ }
76
+ return appendStadiaApiKey(DEFAULT_STADIA_STYLE_URL, normalizedApiKey);
77
+ }
78
+ if (STYLE_MAP[value]) {
79
+ const mappedStyleUrl = STYLE_MAP[value];
80
+ if (isStadiaMapsUrl(mappedStyleUrl) && !normalizedApiKey) {
81
+ return MAPLIBRE_DEFAULT_STYLE_URL;
82
+ }
83
+ return appendStadiaApiKey(mappedStyleUrl, normalizedApiKey);
84
+ }
85
+ if (HTTP_URL_REGEX.test(value)) {
86
+ if (isStadiaMapsUrl(value) && !normalizedApiKey) {
87
+ return MAPLIBRE_DEFAULT_STYLE_URL;
88
+ }
89
+ return appendStadiaApiKey(value, normalizedApiKey);
90
+ }
91
+ if (!normalizedApiKey) {
92
+ return MAPLIBRE_DEFAULT_STYLE_URL;
93
+ }
94
+ return appendStadiaApiKey(DEFAULT_STADIA_STYLE_URL, normalizedApiKey);
95
+ }
96
+ function cn(...inputs) {
97
+ return tailwindMerge.twMerge(clsx.clsx(inputs));
98
+ }
99
+ var SimplePressable = React3__namespace.forwardRef(({ children, className, href, onClick, ...props }, ref) => {
100
+ if (href) {
101
+ const isExternal = href.startsWith("http://") || href.startsWith("https://");
102
+ return /* @__PURE__ */ jsxRuntime.jsx(
103
+ "a",
104
+ {
105
+ ref,
106
+ href,
107
+ className,
108
+ target: isExternal ? "_blank" : props.target,
109
+ rel: isExternal ? "noopener noreferrer" : props.rel,
110
+ onClick,
111
+ ...props,
112
+ children
113
+ }
114
+ );
115
+ }
116
+ if (onClick) {
117
+ return /* @__PURE__ */ jsxRuntime.jsx(
118
+ "button",
119
+ {
120
+ ref,
121
+ type: "button",
122
+ className,
123
+ onClick,
124
+ ...props,
125
+ children
126
+ }
127
+ );
128
+ }
129
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children });
130
+ });
131
+ SimplePressable.displayName = "SimplePressable";
132
+ var DEFAULT_MAPLIBRE_CSS_HREF = "https://cdn.jsdelivr.net/npm/maplibre-gl@5.18.0/dist/maplibre-gl.css";
133
+ var MAPLIBRE_STYLESHEET_ID = "page-speed-maplibre-gl-css";
134
+ var DEFAULT_FLY_TO_OPTIONS = Object.freeze({});
135
+ var VIEW_STATE_COORDINATE_EPSILON = 1e-6;
136
+ var VIEW_STATE_ZOOM_EPSILON = 0.01;
137
+ var DEFAULT_FLY_TO_EASING = (t) => 1 - Math.pow(1 - t, 3);
138
+ function joinClassNames(...classNames) {
139
+ return classNames.filter(Boolean).join(" ");
140
+ }
141
+ function hasMeaningfulViewStateDelta(previous, next) {
142
+ return Math.abs(previous.latitude - next.latitude) > VIEW_STATE_COORDINATE_EPSILON || Math.abs(previous.longitude - next.longitude) > VIEW_STATE_COORDINATE_EPSILON || Math.abs(previous.zoom - next.zoom) > VIEW_STATE_ZOOM_EPSILON;
143
+ }
144
+ function ensureMapLibreStylesheet(href) {
145
+ if (typeof document === "undefined") {
146
+ return;
147
+ }
148
+ const existingLink = document.getElementById(MAPLIBRE_STYLESHEET_ID);
149
+ if (existingLink instanceof HTMLLinkElement) {
150
+ if (existingLink.getAttribute("href") !== href) {
151
+ existingLink.setAttribute("href", href);
152
+ }
153
+ return;
154
+ }
155
+ const matchingLink = Array.from(
156
+ document.querySelectorAll("link[rel='stylesheet']")
157
+ ).find((link) => link.getAttribute("href") === href);
158
+ if (matchingLink instanceof HTMLLinkElement) {
159
+ matchingLink.id = MAPLIBRE_STYLESHEET_ID;
160
+ return;
161
+ }
162
+ const stylesheet = document.createElement("link");
163
+ stylesheet.id = MAPLIBRE_STYLESHEET_ID;
164
+ stylesheet.rel = "stylesheet";
165
+ stylesheet.href = href;
166
+ stylesheet.dataset.pageSpeedMaps = "maplibre-css";
167
+ document.head.appendChild(stylesheet);
168
+ }
169
+ function DefaultMarker({ marker }) {
170
+ return /* @__PURE__ */ jsxRuntime.jsxs(
171
+ "div",
172
+ {
173
+ style: {
174
+ cursor: marker.draggable ? "grab" : "pointer",
175
+ transform: "translate(-50%, -100%)",
176
+ display: "inline-flex",
177
+ alignItems: "center",
178
+ justifyContent: "center",
179
+ position: "relative"
180
+ },
181
+ onClick: marker.onClick,
182
+ children: [
183
+ /* @__PURE__ */ jsxRuntime.jsx(
184
+ "svg",
185
+ {
186
+ "aria-hidden": "true",
187
+ width: "32",
188
+ height: "32",
189
+ viewBox: "0 0 24 24",
190
+ fill: marker.color || "#3B82F6",
191
+ style: { filter: "drop-shadow(0 2px 8px rgba(0,0,0,0.35))" },
192
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 2C8.13 2 5 5.13 5 9c0 4.85 6.13 12.24 6.39 12.55a.75.75 0 0 0 1.16 0C12.87 21.24 19 13.85 19 9c0-3.87-3.13-7-7-7Zm0 9.75A2.75 2.75 0 1 1 12 6.25a2.75 2.75 0 0 1 0 5.5Z" })
193
+ }
194
+ ),
195
+ marker.label ? /* @__PURE__ */ jsxRuntime.jsx(
196
+ "div",
197
+ {
198
+ style: {
199
+ position: "absolute",
200
+ bottom: -28,
201
+ left: "50%",
202
+ transform: "translateX(-50%)",
203
+ background: "#FFFFFF",
204
+ borderRadius: 6,
205
+ padding: "2px 8px",
206
+ fontSize: 12,
207
+ fontWeight: 500,
208
+ whiteSpace: "nowrap",
209
+ boxShadow: "0 3px 10px rgba(0, 0, 0, 0.2)"
210
+ },
211
+ children: marker.label
212
+ }
213
+ ) : null
214
+ ]
215
+ }
216
+ );
217
+ }
218
+ function normalizeMarkers(markers) {
219
+ return markers.map((marker, index) => {
220
+ if (marker.lat !== void 0 && marker.lng !== void 0) {
221
+ return marker;
222
+ }
223
+ const basicMarker = marker;
224
+ return {
225
+ id: basicMarker.id ?? index,
226
+ lat: basicMarker.latitude,
227
+ lng: basicMarker.longitude,
228
+ color: basicMarker.color,
229
+ draggable: basicMarker.draggable,
230
+ label: basicMarker.label,
231
+ element: basicMarker.element,
232
+ onClick: basicMarker.onClick
233
+ };
234
+ });
235
+ }
236
+ function MapLibre({
237
+ stadiaApiKey,
238
+ mapLibreCssHref,
239
+ viewState,
240
+ onViewStateChange,
241
+ mapStyle,
242
+ center = viewState ? { lat: viewState.latitude ?? 0, lng: viewState.longitude ?? 0 } : { lat: 0, lng: 0 },
243
+ zoom = viewState?.zoom ?? 14,
244
+ styleUrl,
245
+ markers = [],
246
+ onMoveEnd,
247
+ onClick,
248
+ onMarkerDrag,
249
+ className,
250
+ style,
251
+ children,
252
+ showNavigationControl = true,
253
+ showGeolocateControl = false,
254
+ navigationControlPosition = "bottom-right",
255
+ geolocateControlPosition = "top-left",
256
+ flyToOptions = DEFAULT_FLY_TO_OPTIONS
257
+ }) {
258
+ const mapRef = React3__namespace.default.useRef(null);
259
+ const resolvedMapLibreCssHref = mapLibreCssHref && mapLibreCssHref.trim().length > 0 ? mapLibreCssHref : DEFAULT_MAPLIBRE_CSS_HREF;
260
+ const [internalViewState, setInternalViewState] = React3__namespace.default.useState({
261
+ latitude: viewState?.latitude ?? center.lat,
262
+ longitude: viewState?.longitude ?? center.lng,
263
+ zoom: viewState?.zoom ?? zoom
264
+ });
265
+ const isUserInteracting = React3__namespace.default.useRef(false);
266
+ const isMarkerDragging = React3__namespace.default.useRef(false);
267
+ const dragAnimationFrame = React3__namespace.default.useRef(null);
268
+ const lastReportedViewState = React3__namespace.default.useRef(null);
269
+ const resolvedFlyToOptions = React3__namespace.default.useMemo(
270
+ () => ({
271
+ speed: flyToOptions.speed ?? 0.8,
272
+ curve: flyToOptions.curve ?? 1.2,
273
+ bearing: flyToOptions.bearing ?? 0,
274
+ easing: flyToOptions.easing ?? DEFAULT_FLY_TO_EASING
275
+ }),
276
+ [
277
+ flyToOptions.bearing,
278
+ flyToOptions.curve,
279
+ flyToOptions.easing,
280
+ flyToOptions.speed
281
+ ]
282
+ );
283
+ React3__namespace.default.useEffect(() => {
284
+ ensureMapLibreStylesheet(resolvedMapLibreCssHref);
285
+ }, [resolvedMapLibreCssHref]);
286
+ React3__namespace.default.useEffect(() => {
287
+ if (!mapRef.current || !viewState || isUserInteracting.current || isMarkerDragging.current) {
288
+ return;
289
+ }
290
+ setInternalViewState((previous) => {
291
+ const next = {
292
+ latitude: viewState.latitude ?? previous.latitude,
293
+ longitude: viewState.longitude ?? previous.longitude,
294
+ zoom: viewState.zoom ?? previous.zoom
295
+ };
296
+ const hasChanged = hasMeaningfulViewStateDelta(previous, next);
297
+ if (!hasChanged) {
298
+ return previous;
299
+ }
300
+ const isEchoedMoveState = !!lastReportedViewState.current && !hasMeaningfulViewStateDelta(lastReportedViewState.current, next);
301
+ if (!isEchoedMoveState) {
302
+ mapRef.current?.flyTo({
303
+ center: [next.longitude, next.latitude],
304
+ zoom: next.zoom,
305
+ speed: resolvedFlyToOptions.speed,
306
+ curve: resolvedFlyToOptions.curve,
307
+ bearing: resolvedFlyToOptions.bearing,
308
+ easing: resolvedFlyToOptions.easing,
309
+ essential: true
310
+ });
311
+ }
312
+ return next;
313
+ });
314
+ }, [
315
+ resolvedFlyToOptions,
316
+ viewState?.latitude,
317
+ viewState?.longitude,
318
+ viewState?.zoom
319
+ ]);
320
+ const handleMoveStart = React3__namespace.default.useCallback(() => {
321
+ isUserInteracting.current = true;
322
+ }, []);
323
+ const handleMove = React3__namespace.default.useCallback(
324
+ (event) => {
325
+ const nextViewState = event.viewState;
326
+ setInternalViewState({
327
+ latitude: nextViewState.latitude,
328
+ longitude: nextViewState.longitude,
329
+ zoom: nextViewState.zoom
330
+ });
331
+ const roundedViewState = {
332
+ latitude: Number(nextViewState.latitude.toFixed(6)),
333
+ longitude: Number(nextViewState.longitude.toFixed(6)),
334
+ zoom: Number(nextViewState.zoom.toFixed(2))
335
+ };
336
+ lastReportedViewState.current = roundedViewState;
337
+ onViewStateChange?.(roundedViewState);
338
+ },
339
+ [onViewStateChange]
340
+ );
341
+ const handleMoveEnd = React3__namespace.default.useCallback(
342
+ (event) => {
343
+ isUserInteracting.current = false;
344
+ if (!onMoveEnd) {
345
+ return;
346
+ }
347
+ const map = event.target;
348
+ const nextCenter = map.getCenter();
349
+ const nextZoom = map.getZoom();
350
+ const bounds = map.getBounds();
351
+ onMoveEnd(
352
+ {
353
+ lat: Number(nextCenter.lat.toFixed(6)),
354
+ lng: Number(nextCenter.lng.toFixed(6))
355
+ },
356
+ Number(nextZoom.toFixed(2)),
357
+ bounds
358
+ );
359
+ },
360
+ [onMoveEnd]
361
+ );
362
+ const handleMapClick = React3__namespace.default.useCallback(
363
+ (event) => {
364
+ if (!onClick) {
365
+ return;
366
+ }
367
+ onClick({ latitude: event.lngLat.lat, longitude: event.lngLat.lng });
368
+ },
369
+ [onClick]
370
+ );
371
+ const normalizedMarkers = React3__namespace.default.useMemo(
372
+ () => normalizeMarkers(markers),
373
+ [markers]
374
+ );
375
+ const markerElements = React3__namespace.default.useMemo(
376
+ () => normalizedMarkers.map((marker) => /* @__PURE__ */ jsxRuntime.jsx(
377
+ maplibre.Marker,
378
+ {
379
+ longitude: marker.lng,
380
+ latitude: marker.lat,
381
+ draggable: marker.draggable,
382
+ onDragStart: () => {
383
+ isMarkerDragging.current = true;
384
+ },
385
+ onDrag: (event) => {
386
+ if (!mapRef.current) {
387
+ return;
388
+ }
389
+ const nextLngLat = event.lngLat;
390
+ if (!nextLngLat || nextLngLat.lng === void 0 || nextLngLat.lat === void 0) {
391
+ return;
392
+ }
393
+ const draggedLng = nextLngLat.lng;
394
+ const draggedLat = nextLngLat.lat;
395
+ if (dragAnimationFrame.current) {
396
+ cancelAnimationFrame(dragAnimationFrame.current);
397
+ }
398
+ dragAnimationFrame.current = requestAnimationFrame(() => {
399
+ if (!mapRef.current) {
400
+ return;
401
+ }
402
+ const bounds = mapRef.current.getBounds();
403
+ const viewportWidth = bounds.getEast() - bounds.getWest();
404
+ const viewportHeight = bounds.getNorth() - bounds.getSouth();
405
+ const edgePadding = 0.1;
406
+ const westThreshold = bounds.getWest() + viewportWidth * edgePadding;
407
+ const eastThreshold = bounds.getEast() - viewportWidth * edgePadding;
408
+ const southThreshold = bounds.getSouth() + viewportHeight * edgePadding;
409
+ const northThreshold = bounds.getNorth() - viewportHeight * edgePadding;
410
+ const nearWestEdge = draggedLng < westThreshold;
411
+ const nearEastEdge = draggedLng > eastThreshold;
412
+ const nearSouthEdge = draggedLat < southThreshold;
413
+ const nearNorthEdge = draggedLat > northThreshold;
414
+ if (!nearWestEdge && !nearEastEdge && !nearSouthEdge && !nearNorthEdge) {
415
+ return;
416
+ }
417
+ let panLng = draggedLng;
418
+ let panLat = draggedLat;
419
+ const offsetAmount = 0.2;
420
+ if (nearWestEdge) {
421
+ panLng = draggedLng - viewportWidth * offsetAmount;
422
+ }
423
+ if (nearEastEdge) {
424
+ panLng = draggedLng + viewportWidth * offsetAmount;
425
+ }
426
+ if (nearSouthEdge) {
427
+ panLat = draggedLat - viewportHeight * offsetAmount;
428
+ }
429
+ if (nearNorthEdge) {
430
+ panLat = draggedLat + viewportHeight * offsetAmount;
431
+ }
432
+ mapRef.current?.easeTo({
433
+ center: [panLng, panLat],
434
+ duration: 200
435
+ });
436
+ });
437
+ },
438
+ onDragEnd: (event) => {
439
+ isMarkerDragging.current = false;
440
+ if (dragAnimationFrame.current) {
441
+ cancelAnimationFrame(dragAnimationFrame.current);
442
+ dragAnimationFrame.current = null;
443
+ }
444
+ if (!onMarkerDrag) {
445
+ return;
446
+ }
447
+ const nextLngLat = event.lngLat;
448
+ if (!nextLngLat || nextLngLat.lng === void 0 || nextLngLat.lat === void 0) {
449
+ return;
450
+ }
451
+ onMarkerDrag(marker.id ?? null, {
452
+ latitude: nextLngLat.lat,
453
+ longitude: nextLngLat.lng
454
+ });
455
+ },
456
+ children: marker.element ? typeof marker.element === "function" ? marker.element() : marker.element : /* @__PURE__ */ jsxRuntime.jsx(DefaultMarker, { marker })
457
+ },
458
+ marker.id
459
+ )),
460
+ [normalizedMarkers, onMarkerDrag]
461
+ );
462
+ const resolvedMapStyleUrl = React3__namespace.default.useMemo(() => {
463
+ if (styleUrl) {
464
+ return appendStadiaApiKey(styleUrl, stadiaApiKey);
465
+ }
466
+ if (mapStyle) {
467
+ return getMapLibreStyleUrl(mapStyle, stadiaApiKey);
468
+ }
469
+ return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
470
+ }, [mapStyle, stadiaApiKey, styleUrl]);
471
+ return /* @__PURE__ */ jsxRuntime.jsx(
472
+ "div",
473
+ {
474
+ className: joinClassNames("relative w-full h-full", className),
475
+ style: { width: "100%", height: "100%", ...style },
476
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
477
+ maplibre.Map,
478
+ {
479
+ ref: mapRef,
480
+ ...internalViewState,
481
+ mapStyle: resolvedMapStyleUrl,
482
+ onMoveStart: handleMoveStart,
483
+ onMove: handleMove,
484
+ onMoveEnd: handleMoveEnd,
485
+ onClick: handleMapClick,
486
+ attributionControl: false,
487
+ trackResize: true,
488
+ dragRotate: false,
489
+ touchZoomRotate: false,
490
+ children: [
491
+ showGeolocateControl ? /* @__PURE__ */ jsxRuntime.jsx(maplibre.GeolocateControl, { position: geolocateControlPosition }) : null,
492
+ showNavigationControl ? /* @__PURE__ */ jsxRuntime.jsx(maplibre.NavigationControl, { position: navigationControlPosition }) : null,
493
+ markerElements,
494
+ children
495
+ ]
496
+ }
497
+ )
498
+ }
499
+ );
500
+ }
501
+ var PANEL_POSITION_CLASS = {
502
+ "top-left": "left-4 top-4",
503
+ "top-right": "right-4 top-4",
504
+ "bottom-left": "bottom-4 left-4",
505
+ "bottom-right": "bottom-4 right-4"
506
+ };
507
+ var DEFAULT_VIEW_STATE = {
508
+ latitude: 39.5,
509
+ longitude: -98.35,
510
+ zoom: 3
511
+ };
512
+ var VIDEO_FILE_EXTENSION_REGEX = /\.(mp4|webm|ogg|mov|m4v|m3u8)(\?.*)?$/i;
513
+ function resolveMediaType(item) {
514
+ if (item.type) {
515
+ return item.type;
516
+ }
517
+ return VIDEO_FILE_EXTENSION_REGEX.test(item.src) ? "video" : "image";
518
+ }
519
+ function normalizeId(value, fallback) {
520
+ if (value === null || value === void 0 || value === "") {
521
+ return fallback;
522
+ }
523
+ return String(value);
524
+ }
525
+ function buildClusterCenter(markers) {
526
+ if (!markers.length) {
527
+ return null;
528
+ }
529
+ const total = markers.reduce(
530
+ (accumulator, marker) => ({
531
+ latitude: accumulator.latitude + marker.latitude,
532
+ longitude: accumulator.longitude + marker.longitude
533
+ }),
534
+ { latitude: 0, longitude: 0 }
535
+ );
536
+ return {
537
+ latitude: total.latitude / markers.length,
538
+ longitude: total.longitude / markers.length
539
+ };
540
+ }
541
+ function resolveActionKey(action, index) {
542
+ if (typeof action.label === "string" && action.label.trim().length > 0) {
543
+ return `label:${action.label}:${index}`;
544
+ }
545
+ if (action.href) {
546
+ return `href:${action.href}:${index}`;
547
+ }
548
+ return `action:${index}`;
549
+ }
550
+ var FallbackIcon = ({
551
+ size = 20,
552
+ className
553
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
554
+ "svg",
555
+ {
556
+ width: size,
557
+ height: size,
558
+ viewBox: "0 0 24 24",
559
+ fill: "none",
560
+ stroke: "currentColor",
561
+ strokeWidth: "2",
562
+ strokeLinecap: "round",
563
+ strokeLinejoin: "round",
564
+ className,
565
+ children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" })
566
+ }
567
+ );
568
+ var FallbackImg = ({ src, alt, className, loading }) => /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt, className, loading });
569
+ function MarkerActions({ actions }) {
570
+ if (!actions || actions.length === 0) {
571
+ return null;
572
+ }
573
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex flex-wrap gap-2", children: actions.map((action, index) => {
574
+ const {
575
+ label,
576
+ icon,
577
+ iconAfter,
578
+ children,
579
+ href,
580
+ onClick,
581
+ className: actionClassName,
582
+ variant,
583
+ size,
584
+ asButton,
585
+ ...rest
586
+ } = action;
587
+ const buttonStyles = cn(
588
+ "inline-flex items-center gap-2 px-4 py-2 rounded-md font-medium transition-colors",
589
+ variant === "outline" ? "border border-border bg-background hover:bg-muted" : "bg-primary text-primary-foreground hover:bg-primary/90",
590
+ size === "sm" && "text-sm px-3 py-1.5",
591
+ size === "icon" && "p-2",
592
+ actionClassName
593
+ );
594
+ return /* @__PURE__ */ jsxRuntime.jsx(
595
+ SimplePressable,
596
+ {
597
+ href,
598
+ onClick,
599
+ className: buttonStyles,
600
+ ...rest,
601
+ children: children ?? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
602
+ icon,
603
+ label,
604
+ iconAfter
605
+ ] })
606
+ },
607
+ resolveActionKey(action, index)
608
+ );
609
+ }) });
610
+ }
611
+ function MarkerMediaCarousel({
612
+ mediaItems,
613
+ optixFlowConfig,
614
+ IconComponent = FallbackIcon,
615
+ ImgComponent = FallbackImg
616
+ }) {
617
+ const [activeIndex, setActiveIndex] = React3__namespace.useState(0);
618
+ const totalItems = mediaItems.length;
619
+ const mediaResetKey = React3__namespace.useMemo(
620
+ () => mediaItems.map((item, index) => {
621
+ const itemId = normalizeId(item.id, `media-${index}`);
622
+ return `${itemId}:${item.src}:${item.type ?? ""}:${item.poster ?? ""}`;
623
+ }).join("|"),
624
+ [mediaItems]
625
+ );
626
+ const activeItemIndex = Math.min(activeIndex, Math.max(0, totalItems - 1));
627
+ React3__namespace.useEffect(() => {
628
+ setActiveIndex(0);
629
+ }, [mediaResetKey]);
630
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative border-b border-border/60 bg-muted/40", children: [
631
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative aspect-video w-full overflow-hidden", children: mediaItems.map((item, index) => {
632
+ const isActive = index === activeItemIndex;
633
+ const mediaType = resolveMediaType(item);
634
+ return /* @__PURE__ */ jsxRuntime.jsx(
635
+ "div",
636
+ {
637
+ "aria-hidden": !isActive,
638
+ className: cn(
639
+ "absolute inset-0 transition-opacity duration-500 ease-in-out",
640
+ isActive ? "opacity-100 z-1" : "opacity-0 z-0 pointer-events-none"
641
+ ),
642
+ children: mediaType === "video" ? /* @__PURE__ */ jsxRuntime.jsx(
643
+ "video",
644
+ {
645
+ className: "h-full w-full object-cover",
646
+ controls: isActive,
647
+ preload: "metadata",
648
+ poster: item.poster,
649
+ tabIndex: isActive ? 0 : -1,
650
+ children: /* @__PURE__ */ jsxRuntime.jsx("source", { src: item.src })
651
+ }
652
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
653
+ ImgComponent,
654
+ {
655
+ src: item.src,
656
+ alt: item.alt ?? "Map marker media",
657
+ className: "h-full w-full object-cover",
658
+ loading: "eager",
659
+ optixFlowConfig
660
+ }
661
+ )
662
+ },
663
+ normalizeId(item.id, `media-slide-${index}`)
664
+ );
665
+ }) }),
666
+ totalItems > 1 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
667
+ /* @__PURE__ */ jsxRuntime.jsx(
668
+ "button",
669
+ {
670
+ type: "button",
671
+ "aria-label": "Show previous media",
672
+ className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-[2]",
673
+ onClick: () => {
674
+ setActiveIndex(
675
+ (current) => (current - 1 + totalItems) % totalItems
676
+ );
677
+ },
678
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { name: "lucide/arrow-left", size: 18 })
679
+ }
680
+ ),
681
+ /* @__PURE__ */ jsxRuntime.jsx(
682
+ "button",
683
+ {
684
+ type: "button",
685
+ "aria-label": "Show next media",
686
+ className: "absolute right-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-2",
687
+ onClick: () => {
688
+ setActiveIndex((current) => (current + 1) % totalItems);
689
+ },
690
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { name: "lucide/arrow-right", size: 18 })
691
+ }
692
+ ),
693
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute bottom-2 left-1/2 flex -translate-x-1/2 items-center gap-1.5 z-[2]", children: mediaItems.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
694
+ "button",
695
+ {
696
+ type: "button",
697
+ "aria-label": `Show media item ${index + 1}`,
698
+ className: cn(
699
+ "h-2 rounded-full transition-all duration-300",
700
+ index === activeItemIndex ? "w-6 bg-card" : "w-2 bg-card opacity-50 hover:opacity-100"
701
+ ),
702
+ onClick: () => setActiveIndex(index)
703
+ },
704
+ normalizeId(item.id, `media-dot-${index}`)
705
+ )) })
706
+ ] }) : null
707
+ ] });
708
+ }
709
+ function getMarkerTitle(marker, markerIndex) {
710
+ if (marker.title !== void 0 && marker.title !== null) {
711
+ return marker.title;
712
+ }
713
+ if (marker.label !== void 0 && marker.label !== null) {
714
+ return marker.label;
715
+ }
716
+ return `Location ${markerIndex + 1}`;
717
+ }
718
+ function GeoMap({
719
+ className,
720
+ mapWrapperClassName,
721
+ mapClassName,
722
+ panelClassName,
723
+ panelPosition = "top-left",
724
+ stadiaApiKey = "",
725
+ mapStyle = "osm-bright",
726
+ styleUrl,
727
+ mapLibreCssHref,
728
+ markers = [],
729
+ clusters = [],
730
+ viewState,
731
+ defaultViewState,
732
+ onViewStateChange,
733
+ onMapClick,
734
+ onMarkerDrag,
735
+ showNavigationControl = true,
736
+ showGeolocateControl = false,
737
+ navigationControlPosition = "top-right",
738
+ geolocateControlPosition = "top-left",
739
+ flyToOptions,
740
+ markerFocusZoom = 14,
741
+ clusterFocusZoom = 5,
742
+ selectedMarkerId,
743
+ initialSelectedMarkerId,
744
+ onSelectionChange,
745
+ clearSelectionOnMapClick = true,
746
+ mapChildren,
747
+ optixFlowConfig,
748
+ IconComponent = FallbackIcon,
749
+ ImgComponent = FallbackImg
750
+ }) {
751
+ const normalizedStandaloneMarkers = React3__namespace.useMemo(
752
+ () => markers.map((marker, index) => ({
753
+ ...marker,
754
+ id: normalizeId(marker.id, `marker-${index}`)
755
+ })),
756
+ [markers]
757
+ );
758
+ const normalizedClusters = React3__namespace.useMemo(() => {
759
+ const results = [];
760
+ clusters.forEach((cluster, clusterIndex) => {
761
+ const clusterId = normalizeId(cluster.id, `cluster-${clusterIndex}`);
762
+ const normalizedClusterMarkers = cluster.markers.map(
763
+ (marker, markerIndex) => ({
764
+ ...marker,
765
+ id: normalizeId(marker.id, `${clusterId}-marker-${markerIndex}`),
766
+ clusterId
767
+ })
768
+ );
769
+ const clusterCenter = cluster.latitude !== void 0 && cluster.longitude !== void 0 ? { latitude: cluster.latitude, longitude: cluster.longitude } : buildClusterCenter(normalizedClusterMarkers);
770
+ if (!clusterCenter) {
771
+ return;
772
+ }
773
+ results.push({
774
+ ...cluster,
775
+ id: clusterId,
776
+ latitude: clusterCenter.latitude,
777
+ longitude: clusterCenter.longitude,
778
+ markers: normalizedClusterMarkers
779
+ });
780
+ });
781
+ return results;
782
+ }, [clusters]);
783
+ const markerLookup = React3__namespace.useMemo(() => {
784
+ const lookup = /* @__PURE__ */ new Map();
785
+ normalizedStandaloneMarkers.forEach((marker) => {
786
+ lookup.set(marker.id, marker);
787
+ });
788
+ normalizedClusters.forEach((cluster) => {
789
+ cluster.markers.forEach((marker) => {
790
+ lookup.set(marker.id, marker);
791
+ });
792
+ });
793
+ return lookup;
794
+ }, [normalizedClusters, normalizedStandaloneMarkers]);
795
+ const clusterLookup = React3__namespace.useMemo(() => {
796
+ const lookup = /* @__PURE__ */ new Map();
797
+ normalizedClusters.forEach((cluster) => {
798
+ lookup.set(cluster.id, cluster);
799
+ });
800
+ return lookup;
801
+ }, [normalizedClusters]);
802
+ const firstCoordinate = React3__namespace.useMemo(() => {
803
+ const allCoords = [];
804
+ normalizedStandaloneMarkers.forEach((marker) => {
805
+ allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
806
+ });
807
+ normalizedClusters.forEach((cluster) => {
808
+ allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
809
+ });
810
+ if (allCoords.length > 0) {
811
+ const sum = allCoords.reduce(
812
+ (acc, coord) => ({
813
+ latitude: acc.latitude + coord.latitude,
814
+ longitude: acc.longitude + coord.longitude
815
+ }),
816
+ { latitude: 0, longitude: 0 }
817
+ );
818
+ return {
819
+ latitude: sum.latitude / allCoords.length,
820
+ longitude: sum.longitude / allCoords.length
821
+ };
822
+ }
823
+ return {
824
+ latitude: DEFAULT_VIEW_STATE.latitude,
825
+ longitude: DEFAULT_VIEW_STATE.longitude
826
+ };
827
+ }, [normalizedClusters, normalizedStandaloneMarkers]);
828
+ const calculatedZoom = React3__namespace.useMemo(() => {
829
+ if (normalizedStandaloneMarkers.length + normalizedClusters.length <= 1) {
830
+ return markerFocusZoom;
831
+ }
832
+ const allCoords = [];
833
+ normalizedStandaloneMarkers.forEach((marker) => {
834
+ allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
835
+ });
836
+ normalizedClusters.forEach((cluster) => {
837
+ allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
838
+ });
839
+ if (allCoords.length === 0) {
840
+ return DEFAULT_VIEW_STATE.zoom;
841
+ }
842
+ const lats = allCoords.map((c) => c.latitude);
843
+ const lngs = allCoords.map((c) => c.longitude);
844
+ const latDiff = Math.max(...lats) - Math.min(...lats);
845
+ const lngDiff = Math.max(...lngs) - Math.min(...lngs);
846
+ const maxDiff = Math.max(latDiff, lngDiff);
847
+ if (maxDiff > 10) return 3;
848
+ if (maxDiff > 5) return 5;
849
+ if (maxDiff > 2) return 7;
850
+ if (maxDiff > 1) return 9;
851
+ if (maxDiff > 0.5) return 10;
852
+ if (maxDiff > 0.1) return 12;
853
+ return 13;
854
+ }, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom]);
855
+ const [uncontrolledViewState, setUncontrolledViewState] = React3__namespace.useState({
856
+ latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
857
+ longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
858
+ zoom: defaultViewState?.zoom ?? calculatedZoom
859
+ });
860
+ React3__namespace.useEffect(() => {
861
+ if (!viewState && !defaultViewState) {
862
+ setUncontrolledViewState({
863
+ latitude: firstCoordinate.latitude,
864
+ longitude: firstCoordinate.longitude,
865
+ zoom: calculatedZoom
866
+ });
867
+ }
868
+ }, [firstCoordinate, calculatedZoom, viewState, defaultViewState]);
869
+ const isControlledViewState = viewState !== void 0;
870
+ const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
871
+ const applyViewState = React3__namespace.useCallback(
872
+ (nextState) => {
873
+ if (!isControlledViewState) {
874
+ setUncontrolledViewState((current) => {
875
+ const next = { ...current, ...nextState };
876
+ const hasChanged = current.latitude !== next.latitude || current.longitude !== next.longitude || current.zoom !== next.zoom;
877
+ return hasChanged ? next : current;
878
+ });
879
+ }
880
+ onViewStateChange?.(nextState);
881
+ },
882
+ [isControlledViewState, onViewStateChange]
883
+ );
884
+ const [selection, setSelection] = React3__namespace.useState(() => {
885
+ if (initialSelectedMarkerId !== void 0 && initialSelectedMarkerId !== null) {
886
+ return {
887
+ type: "marker",
888
+ markerId: String(initialSelectedMarkerId)
889
+ };
890
+ }
891
+ return { type: "none" };
892
+ });
893
+ React3__namespace.useEffect(() => {
894
+ if (selectedMarkerId === void 0 || selectedMarkerId === null) {
895
+ return;
896
+ }
897
+ setSelection({
898
+ type: "marker",
899
+ markerId: String(selectedMarkerId)
900
+ });
901
+ }, [selectedMarkerId]);
902
+ const selectedMarker = selection.markerId ? markerLookup.get(selection.markerId) : void 0;
903
+ const selectedCluster = selection.clusterId ? clusterLookup.get(selection.clusterId) : void 0;
904
+ React3__namespace.useEffect(() => {
905
+ if (selection.type === "marker" && selection.markerId && !selectedMarker) {
906
+ setSelection({ type: "none" });
907
+ onSelectionChange?.({ type: "none" });
908
+ }
909
+ }, [onSelectionChange, selectedMarker, selection]);
910
+ const emitSelectionChange = React3__namespace.useCallback(
911
+ (nextSelection) => {
912
+ if (nextSelection.type === "none") {
913
+ onSelectionChange?.({ type: "none" });
914
+ return;
915
+ }
916
+ if (nextSelection.type === "marker") {
917
+ const parentCluster = nextSelection.marker.clusterId ? clusterLookup.get(nextSelection.marker.clusterId) : void 0;
918
+ onSelectionChange?.({
919
+ type: "marker",
920
+ marker: nextSelection.marker,
921
+ cluster: parentCluster
922
+ });
923
+ return;
924
+ }
925
+ onSelectionChange?.({
926
+ type: "cluster",
927
+ cluster: nextSelection.cluster
928
+ });
929
+ },
930
+ [clusterLookup, onSelectionChange]
931
+ );
932
+ const selectMarker = React3__namespace.useCallback(
933
+ (marker) => {
934
+ setSelection({
935
+ type: "marker",
936
+ markerId: marker.id,
937
+ clusterId: marker.clusterId
938
+ });
939
+ applyViewState({
940
+ latitude: marker.latitude,
941
+ longitude: marker.longitude,
942
+ zoom: markerFocusZoom
943
+ });
944
+ emitSelectionChange({ type: "marker", marker });
945
+ },
946
+ [applyViewState, emitSelectionChange, markerFocusZoom]
947
+ );
948
+ const selectCluster = React3__namespace.useCallback(
949
+ (cluster) => {
950
+ setSelection({
951
+ type: "cluster",
952
+ clusterId: cluster.id
953
+ });
954
+ applyViewState({
955
+ latitude: cluster.latitude,
956
+ longitude: cluster.longitude,
957
+ zoom: clusterFocusZoom
958
+ });
959
+ emitSelectionChange({ type: "cluster", cluster });
960
+ },
961
+ [applyViewState, clusterFocusZoom, emitSelectionChange]
962
+ );
963
+ const clearSelection = React3__namespace.useCallback(() => {
964
+ setSelection({ type: "none" });
965
+ emitSelectionChange({ type: "none" });
966
+ }, [emitSelectionChange]);
967
+ const mapMarkers = React3__namespace.useMemo(() => {
968
+ const resolvedMarkers = [];
969
+ normalizedClusters.forEach((cluster) => {
970
+ const isSelected = selection.type === "cluster" && selection.clusterId === cluster.id;
971
+ resolvedMarkers.push({
972
+ id: `cluster-pin:${cluster.id}`,
973
+ latitude: cluster.latitude,
974
+ longitude: cluster.longitude,
975
+ element: () => {
976
+ const customMarkerElement = cluster.markerElement;
977
+ const markerBody = typeof customMarkerElement === "function" ? customMarkerElement({
978
+ isSelected,
979
+ count: cluster.markers.length
980
+ }) : customMarkerElement;
981
+ return /* @__PURE__ */ jsxRuntime.jsx(
982
+ "button",
983
+ {
984
+ type: "button",
985
+ className: "group cursor-pointer",
986
+ onClick: (event) => {
987
+ event.preventDefault();
988
+ event.stopPropagation();
989
+ selectCluster(cluster);
990
+ },
991
+ "aria-label": `View ${cluster.markers.length} clustered locations`,
992
+ children: markerBody ?? /* @__PURE__ */ jsxRuntime.jsx(
993
+ "span",
994
+ {
995
+ className: cn(
996
+ "inline-flex min-h-10 min-w-10 items-center justify-center rounded-full border-2 border-white px-2 text-xs font-semibold text-white shadow-lg transition-transform duration-200 group-hover:scale-105",
997
+ isSelected && "ring-4 ring-primary/30",
998
+ cluster.pinClassName
999
+ ),
1000
+ style: {
1001
+ backgroundColor: cluster.pinColor ?? "var(--foreground)"
1002
+ },
1003
+ children: cluster.markers.length
1004
+ }
1005
+ )
1006
+ }
1007
+ );
1008
+ }
1009
+ });
1010
+ });
1011
+ normalizedStandaloneMarkers.forEach((marker) => {
1012
+ const isSelected = selection.type === "marker" && selection.markerId === marker.id;
1013
+ const customMarkerElement = marker.markerElement;
1014
+ resolvedMarkers.push({
1015
+ id: marker.id,
1016
+ latitude: marker.latitude,
1017
+ longitude: marker.longitude,
1018
+ draggable: marker.draggable,
1019
+ element: () => {
1020
+ const markerBody = typeof customMarkerElement === "function" ? customMarkerElement({ isSelected }) : customMarkerElement;
1021
+ return /* @__PURE__ */ jsxRuntime.jsx(
1022
+ "button",
1023
+ {
1024
+ type: "button",
1025
+ className: "group cursor-pointer",
1026
+ onClick: (event) => {
1027
+ event.preventDefault();
1028
+ event.stopPropagation();
1029
+ selectMarker(marker);
1030
+ },
1031
+ "aria-label": typeof marker.title === "string" ? `View ${marker.title}` : "View location details",
1032
+ children: markerBody ?? /* @__PURE__ */ jsxRuntime.jsx(
1033
+ "span",
1034
+ {
1035
+ className: cn(
1036
+ "inline-flex h-4 w-4 rounded-full border-2 border-white shadow-md transition-transform duration-200 group-hover:scale-110",
1037
+ isSelected && "h-5 w-5 ring-4 ring-primary/30",
1038
+ marker.pinClassName
1039
+ ),
1040
+ style: {
1041
+ backgroundColor: marker.pinColor ?? "#f43f5e"
1042
+ }
1043
+ }
1044
+ )
1045
+ }
1046
+ );
1047
+ }
1048
+ });
1049
+ });
1050
+ return resolvedMarkers;
1051
+ }, [
1052
+ normalizedClusters,
1053
+ normalizedStandaloneMarkers,
1054
+ selectCluster,
1055
+ selectMarker,
1056
+ selection
1057
+ ]);
1058
+ const renderMarkerPanel = () => {
1059
+ if (selectedMarker) {
1060
+ const markerMediaItems = selectedMarker.mediaItems ?? [];
1061
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1062
+ "div",
1063
+ {
1064
+ className: cn(
1065
+ "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1066
+ panelClassName
1067
+ ),
1068
+ children: [
1069
+ /* @__PURE__ */ jsxRuntime.jsx(
1070
+ "button",
1071
+ {
1072
+ type: "button",
1073
+ "aria-label": "Close marker details",
1074
+ className: "flex size-12 items-center justify-center rounded-bl-lg rounded-br-0 rounded-t-0 bg-black text-white transition-all duration-500 absolute top-0 right-0 z-10 cursor-pointer ring-4 ring-white",
1075
+ onClick: clearSelection,
1076
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { name: "lucide/x", size: 20 })
1077
+ }
1078
+ ),
1079
+ markerMediaItems.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
1080
+ MarkerMediaCarousel,
1081
+ {
1082
+ mediaItems: markerMediaItems,
1083
+ optixFlowConfig,
1084
+ IconComponent,
1085
+ ImgComponent
1086
+ }
1087
+ ) : null,
1088
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 p-4", children: [
1089
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-start justify-between gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 space-y-1", children: [
1090
+ selectedMarker.eyebrow ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-semibold uppercase tracking-wide", children: selectedMarker.eyebrow }) : null,
1091
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold leading-tight", children: selectedMarker.title ?? selectedMarker.label ?? "Location" })
1092
+ ] }) }),
1093
+ selectedMarker.summary ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm leading-relaxed", children: selectedMarker.summary }) : null,
1094
+ selectedMarker.locationLine ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center justify-start text-sm gap-2", children: [
1095
+ /* @__PURE__ */ jsxRuntime.jsx(
1096
+ IconComponent,
1097
+ {
1098
+ name: "lucide:map-pin",
1099
+ className: "opacity-50",
1100
+ size: 18
1101
+ }
1102
+ ),
1103
+ typeof selectedMarker.locationLine === "string" ? /* @__PURE__ */ jsxRuntime.jsx(
1104
+ SimplePressable,
1105
+ {
1106
+ href: selectedMarker.locationUrl,
1107
+ className: cn(
1108
+ "transition-all duration-500",
1109
+ "font-medium opacity-75 hover:opacity-100",
1110
+ selectedMarker.locationUrl ? "underline underline-offset-4" : ""
1111
+ ),
1112
+ children: selectedMarker.locationLine
1113
+ }
1114
+ ) : selectedMarker.locationLine
1115
+ ] }) : null,
1116
+ selectedMarker.hoursLine ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center justify-start text-sm gap-2", children: [
1117
+ /* @__PURE__ */ jsxRuntime.jsx(
1118
+ IconComponent,
1119
+ {
1120
+ name: "lucide:clock",
1121
+ className: "opacity-50",
1122
+ size: 18
1123
+ }
1124
+ ),
1125
+ typeof selectedMarker.hoursLine === "string" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium", children: selectedMarker.hoursLine }) : selectedMarker.hoursLine
1126
+ ] }) : null,
1127
+ selectedMarker.markerContentComponent ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative", children: selectedMarker.markerContentComponent }) : null,
1128
+ /* @__PURE__ */ jsxRuntime.jsx(MarkerActions, { actions: selectedMarker.actions })
1129
+ ] })
1130
+ ]
1131
+ }
1132
+ );
1133
+ }
1134
+ if (selectedCluster) {
1135
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1136
+ "div",
1137
+ {
1138
+ className: cn(
1139
+ "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1140
+ panelClassName
1141
+ ),
1142
+ children: [
1143
+ /* @__PURE__ */ jsxRuntime.jsx(
1144
+ "button",
1145
+ {
1146
+ type: "button",
1147
+ "aria-label": "Close cluster details",
1148
+ className: "flex size-8 items-center justify-center rounded-full border border-border bg-card text-card-foreground transition hover:bg-muted hover:text-foreground absolute top-2 right-2 z-10",
1149
+ onClick: clearSelection,
1150
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { name: "lucide/x", size: 20 })
1151
+ }
1152
+ ),
1153
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-3 flex items-start justify-between gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
1154
+ selectedCluster.label ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: selectedCluster.label }) : null,
1155
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold leading-tight text-foreground", children: selectedCluster.title ?? "Clustered Locations" }),
1156
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: selectedCluster.summary ?? `${selectedCluster.markers.length} location${selectedCluster.markers.length === 1 ? "" : "s"} in this cluster.` })
1157
+ ] }) }),
1158
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-56 space-y-2 overflow-y-auto pr-1", children: selectedCluster.markers.map((marker, markerIndex) => /* @__PURE__ */ jsxRuntime.jsxs(
1159
+ "button",
1160
+ {
1161
+ type: "button",
1162
+ className: "w-full rounded-lg border border-border/60 p-3 text-left transition hover:border-border hover:bg-muted/50",
1163
+ onClick: () => selectMarker(marker),
1164
+ children: [
1165
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "line-clamp-1 text-sm font-semibold text-foreground", children: getMarkerTitle(marker, markerIndex) }),
1166
+ marker.summary ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 line-clamp-2 text-xs text-muted-foreground", children: marker.summary }) : null
1167
+ ]
1168
+ },
1169
+ marker.id
1170
+ )) })
1171
+ ]
1172
+ }
1173
+ );
1174
+ }
1175
+ return null;
1176
+ };
1177
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1178
+ "div",
1179
+ {
1180
+ className: cn(
1181
+ "relative overflow-hidden rounded-2xl border border-border bg-background",
1182
+ className
1183
+ ),
1184
+ children: [
1185
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsxRuntime.jsx(
1186
+ MapLibre,
1187
+ {
1188
+ stadiaApiKey,
1189
+ mapStyle,
1190
+ styleUrl,
1191
+ mapLibreCssHref,
1192
+ viewState: resolvedViewState,
1193
+ onViewStateChange: applyViewState,
1194
+ markers: mapMarkers,
1195
+ onClick: (coord) => {
1196
+ onMapClick?.(coord);
1197
+ if (clearSelectionOnMapClick) {
1198
+ clearSelection();
1199
+ }
1200
+ },
1201
+ onMarkerDrag,
1202
+ showNavigationControl,
1203
+ showGeolocateControl,
1204
+ navigationControlPosition,
1205
+ geolocateControlPosition,
1206
+ flyToOptions,
1207
+ className: cn("h-full w-full", mapClassName),
1208
+ children: mapChildren
1209
+ }
1210
+ ) }),
1211
+ selection.type !== "none" ? /* @__PURE__ */ jsxRuntime.jsx(
1212
+ "div",
1213
+ {
1214
+ className: cn(
1215
+ "pointer-events-none absolute z-20",
1216
+ PANEL_POSITION_CLASS[panelPosition]
1217
+ ),
1218
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto", children: renderMarkerPanel() })
1219
+ }
1220
+ ) : null
1221
+ ]
1222
+ }
1223
+ );
1224
+ }
1225
+
1226
+ exports.GeoMap = GeoMap;
1227
+ //# sourceMappingURL=geo-map.cjs.map
1228
+ //# sourceMappingURL=geo-map.cjs.map