@page-speed/maps 0.1.5 → 0.1.7

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.
@@ -468,11 +468,55 @@ function MapLibre({
468
468
  }
469
469
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
470
470
  }, [mapStyle, stadiaApiKey, styleUrl]);
471
+ const isInIframe = React3__namespace.default.useMemo(() => {
472
+ if (typeof window === "undefined") return false;
473
+ try {
474
+ return window.self !== window.top;
475
+ } catch {
476
+ return true;
477
+ }
478
+ }, []);
479
+ React3__namespace.default.useEffect(() => {
480
+ if (!isInIframe || !mapRef.current) return;
481
+ let lastHeight = 0;
482
+ let lastWidth = 0;
483
+ let resizeTimeout;
484
+ const handleResize = (entries) => {
485
+ clearTimeout(resizeTimeout);
486
+ const entry = entries[0];
487
+ if (!entry) return;
488
+ const { width, height } = entry.contentRect;
489
+ const widthChanged = Math.abs(width - lastWidth) > 1;
490
+ const heightChanged = Math.abs(height - lastHeight) > 1;
491
+ if (widthChanged || heightChanged) {
492
+ lastWidth = width;
493
+ lastHeight = height;
494
+ resizeTimeout = setTimeout(() => {
495
+ mapRef.current?.resize();
496
+ }, 250);
497
+ }
498
+ };
499
+ const parentElement = mapRef.current.getContainer().parentElement;
500
+ if (parentElement) {
501
+ const resizeObserver = new ResizeObserver(handleResize);
502
+ resizeObserver.observe(parentElement);
503
+ return () => {
504
+ clearTimeout(resizeTimeout);
505
+ resizeObserver.disconnect();
506
+ };
507
+ }
508
+ }, [isInIframe]);
471
509
  return /* @__PURE__ */ jsxRuntime.jsx(
472
510
  "div",
473
511
  {
474
512
  className: joinClassNames("relative w-full h-full", className),
475
- style: { width: "100%", height: "100%", ...style },
513
+ style: {
514
+ width: "100%",
515
+ height: "100%",
516
+ // Prevent content from pushing container size in iframes
517
+ ...isInIframe && { overflow: "hidden", position: "relative" },
518
+ ...style
519
+ },
476
520
  children: /* @__PURE__ */ jsxRuntime.jsxs(
477
521
  maplibre.Map,
478
522
  {
@@ -484,7 +528,7 @@ function MapLibre({
484
528
  onMoveEnd: handleMoveEnd,
485
529
  onClick: handleMapClick,
486
530
  attributionControl: false,
487
- trackResize: true,
531
+ trackResize: !isInIframe,
488
532
  dragRotate: false,
489
533
  touchZoomRotate: false,
490
534
  children: [
@@ -547,10 +591,7 @@ function resolveActionKey(action, index) {
547
591
  }
548
592
  return `action:${index}`;
549
593
  }
550
- var FallbackIcon = ({
551
- size = 20,
552
- className
553
- }) => /* @__PURE__ */ jsxRuntime.jsx(
594
+ var FallbackIcon = ({ size = 20, className }) => /* @__PURE__ */ jsxRuntime.jsx(
554
595
  "svg",
555
596
  {
556
597
  width: size,
@@ -669,7 +710,7 @@ function MarkerMediaCarousel({
669
710
  {
670
711
  type: "button",
671
712
  "aria-label": "Show previous media",
672
- className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-[2]",
713
+ className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-2",
673
714
  onClick: () => {
674
715
  setActiveIndex(
675
716
  (current) => (current - 1 + totalItems) % totalItems
@@ -802,10 +843,16 @@ function GeoMap({
802
843
  const firstCoordinate = React3__namespace.useMemo(() => {
803
844
  const allCoords = [];
804
845
  normalizedStandaloneMarkers.forEach((marker) => {
805
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
846
+ allCoords.push({
847
+ latitude: marker.latitude,
848
+ longitude: marker.longitude
849
+ });
806
850
  });
807
851
  normalizedClusters.forEach((cluster) => {
808
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
852
+ allCoords.push({
853
+ latitude: cluster.latitude,
854
+ longitude: cluster.longitude
855
+ });
809
856
  });
810
857
  if (allCoords.length > 0) {
811
858
  const sum = allCoords.reduce(
@@ -831,10 +878,16 @@ function GeoMap({
831
878
  }
832
879
  const allCoords = [];
833
880
  normalizedStandaloneMarkers.forEach((marker) => {
834
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
881
+ allCoords.push({
882
+ latitude: marker.latitude,
883
+ longitude: marker.longitude
884
+ });
835
885
  });
836
886
  normalizedClusters.forEach((cluster) => {
837
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
887
+ allCoords.push({
888
+ latitude: cluster.latitude,
889
+ longitude: cluster.longitude
890
+ });
838
891
  });
839
892
  if (allCoords.length === 0) {
840
893
  return DEFAULT_VIEW_STATE.zoom;
@@ -1062,7 +1115,7 @@ function GeoMap({
1062
1115
  "div",
1063
1116
  {
1064
1117
  className: cn(
1065
- "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1118
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1066
1119
  panelClassName
1067
1120
  ),
1068
1121
  children: [
@@ -1136,7 +1189,7 @@ function GeoMap({
1136
1189
  "div",
1137
1190
  {
1138
1191
  className: cn(
1139
- "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1192
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1140
1193
  panelClassName
1141
1194
  ),
1142
1195
  children: [
@@ -1174,6 +1227,14 @@ function GeoMap({
1174
1227
  }
1175
1228
  return null;
1176
1229
  };
1230
+ const isInIframe = React3__namespace.useMemo(() => {
1231
+ if (typeof window === "undefined") return false;
1232
+ try {
1233
+ return window.self !== window.top;
1234
+ } catch {
1235
+ return true;
1236
+ }
1237
+ }, []);
1177
1238
  return /* @__PURE__ */ jsxRuntime.jsxs(
1178
1239
  "div",
1179
1240
  {
@@ -1181,33 +1242,51 @@ function GeoMap({
1181
1242
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1182
1243
  className
1183
1244
  ),
1245
+ style: {
1246
+ // Use CSS containment to prevent layout shifts in iframes
1247
+ ...isInIframe && { contain: "layout size" }
1248
+ },
1184
1249
  children: [
1185
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsxRuntime.jsx(
1186
- MapLibre,
1250
+ /* @__PURE__ */ jsxRuntime.jsx(
1251
+ "div",
1187
1252
  {
1188
- stadiaApiKey,
1189
- mapStyle,
1190
- styleUrl,
1191
- mapLibreCssHref,
1192
- viewState: resolvedViewState,
1193
- onViewStateChange: applyViewState,
1194
- markers: mapMarkers,
1195
- onClick: (coord) => {
1196
- onMapClick?.(coord);
1197
- if (clearSelectionOnMapClick) {
1198
- clearSelection();
1199
- }
1253
+ className: cn(
1254
+ "w-full",
1255
+ // Default height, can be overridden by mapWrapperClassName
1256
+ mapWrapperClassName || "h-[520px]"
1257
+ ),
1258
+ style: {
1259
+ // Ensure proper height containment in iframes
1260
+ ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1200
1261
  },
1201
- onMarkerDrag,
1202
- showNavigationControl,
1203
- showGeolocateControl,
1204
- navigationControlPosition,
1205
- geolocateControlPosition,
1206
- flyToOptions,
1207
- className: cn("h-full w-full", mapClassName),
1208
- children: mapChildren
1262
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1263
+ MapLibre,
1264
+ {
1265
+ stadiaApiKey,
1266
+ mapStyle,
1267
+ styleUrl,
1268
+ mapLibreCssHref,
1269
+ viewState: resolvedViewState,
1270
+ onViewStateChange: applyViewState,
1271
+ markers: mapMarkers,
1272
+ onClick: (coord) => {
1273
+ onMapClick?.(coord);
1274
+ if (clearSelectionOnMapClick) {
1275
+ clearSelection();
1276
+ }
1277
+ },
1278
+ onMarkerDrag,
1279
+ showNavigationControl,
1280
+ showGeolocateControl,
1281
+ navigationControlPosition,
1282
+ geolocateControlPosition,
1283
+ flyToOptions,
1284
+ className: cn("h-full w-full", mapClassName),
1285
+ children: mapChildren
1286
+ }
1287
+ )
1209
1288
  }
1210
- ) }),
1289
+ ),
1211
1290
  selection.type !== "none" ? /* @__PURE__ */ jsxRuntime.jsx(
1212
1291
  "div",
1213
1292
  {