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