@page-speed/maps 0.1.4 → 0.1.6

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