@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.
@@ -566,11 +566,55 @@ function MapLibre({
566
566
  }
567
567
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
568
568
  }, [mapStyle, stadiaApiKey, styleUrl]);
569
+ const isInIframe = React3__default.useMemo(() => {
570
+ if (typeof window === "undefined") return false;
571
+ try {
572
+ return window.self !== window.top;
573
+ } catch {
574
+ return true;
575
+ }
576
+ }, []);
577
+ React3__default.useEffect(() => {
578
+ if (!isInIframe || !mapRef.current) return;
579
+ let lastHeight = 0;
580
+ let lastWidth = 0;
581
+ let resizeTimeout;
582
+ const handleResize = (entries) => {
583
+ clearTimeout(resizeTimeout);
584
+ const entry = entries[0];
585
+ if (!entry) return;
586
+ const { width, height } = entry.contentRect;
587
+ const widthChanged = Math.abs(width - lastWidth) > 1;
588
+ const heightChanged = Math.abs(height - lastHeight) > 1;
589
+ if (widthChanged || heightChanged) {
590
+ lastWidth = width;
591
+ lastHeight = height;
592
+ resizeTimeout = setTimeout(() => {
593
+ mapRef.current?.resize();
594
+ }, 250);
595
+ }
596
+ };
597
+ const parentElement = mapRef.current.getContainer().parentElement;
598
+ if (parentElement) {
599
+ const resizeObserver = new ResizeObserver(handleResize);
600
+ resizeObserver.observe(parentElement);
601
+ return () => {
602
+ clearTimeout(resizeTimeout);
603
+ resizeObserver.disconnect();
604
+ };
605
+ }
606
+ }, [isInIframe]);
569
607
  return /* @__PURE__ */ jsx(
570
608
  "div",
571
609
  {
572
610
  className: joinClassNames("relative w-full h-full", className),
573
- style: { width: "100%", height: "100%", ...style },
611
+ style: {
612
+ width: "100%",
613
+ height: "100%",
614
+ // Prevent content from pushing container size in iframes
615
+ ...isInIframe && { overflow: "hidden", position: "relative" },
616
+ ...style
617
+ },
574
618
  children: /* @__PURE__ */ jsxs(
575
619
  Map$1,
576
620
  {
@@ -582,7 +626,7 @@ function MapLibre({
582
626
  onMoveEnd: handleMoveEnd,
583
627
  onClick: handleMapClick,
584
628
  attributionControl: false,
585
- trackResize: true,
629
+ trackResize: !isInIframe,
586
630
  dragRotate: false,
587
631
  touchZoomRotate: false,
588
632
  children: [
@@ -645,10 +689,7 @@ function resolveActionKey(action, index) {
645
689
  }
646
690
  return `action:${index}`;
647
691
  }
648
- var FallbackIcon = ({
649
- size = 20,
650
- className
651
- }) => /* @__PURE__ */ jsx(
692
+ var FallbackIcon = ({ size = 20, className }) => /* @__PURE__ */ jsx(
652
693
  "svg",
653
694
  {
654
695
  width: size,
@@ -767,7 +808,7 @@ function MarkerMediaCarousel({
767
808
  {
768
809
  type: "button",
769
810
  "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]",
811
+ 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
812
  onClick: () => {
772
813
  setActiveIndex(
773
814
  (current) => (current - 1 + totalItems) % totalItems
@@ -900,10 +941,16 @@ function GeoMap({
900
941
  const firstCoordinate = React3.useMemo(() => {
901
942
  const allCoords = [];
902
943
  normalizedStandaloneMarkers.forEach((marker) => {
903
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
944
+ allCoords.push({
945
+ latitude: marker.latitude,
946
+ longitude: marker.longitude
947
+ });
904
948
  });
905
949
  normalizedClusters.forEach((cluster) => {
906
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
950
+ allCoords.push({
951
+ latitude: cluster.latitude,
952
+ longitude: cluster.longitude
953
+ });
907
954
  });
908
955
  if (allCoords.length > 0) {
909
956
  const sum = allCoords.reduce(
@@ -929,10 +976,16 @@ function GeoMap({
929
976
  }
930
977
  const allCoords = [];
931
978
  normalizedStandaloneMarkers.forEach((marker) => {
932
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
979
+ allCoords.push({
980
+ latitude: marker.latitude,
981
+ longitude: marker.longitude
982
+ });
933
983
  });
934
984
  normalizedClusters.forEach((cluster) => {
935
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
985
+ allCoords.push({
986
+ latitude: cluster.latitude,
987
+ longitude: cluster.longitude
988
+ });
936
989
  });
937
990
  if (allCoords.length === 0) {
938
991
  return DEFAULT_VIEW_STATE.zoom;
@@ -1160,7 +1213,7 @@ function GeoMap({
1160
1213
  "div",
1161
1214
  {
1162
1215
  className: cn(
1163
- "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1216
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1164
1217
  panelClassName
1165
1218
  ),
1166
1219
  children: [
@@ -1234,7 +1287,7 @@ function GeoMap({
1234
1287
  "div",
1235
1288
  {
1236
1289
  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",
1290
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1238
1291
  panelClassName
1239
1292
  ),
1240
1293
  children: [
@@ -1272,6 +1325,14 @@ function GeoMap({
1272
1325
  }
1273
1326
  return null;
1274
1327
  };
1328
+ const isInIframe = React3.useMemo(() => {
1329
+ if (typeof window === "undefined") return false;
1330
+ try {
1331
+ return window.self !== window.top;
1332
+ } catch {
1333
+ return true;
1334
+ }
1335
+ }, []);
1275
1336
  return /* @__PURE__ */ jsxs(
1276
1337
  "div",
1277
1338
  {
@@ -1279,33 +1340,51 @@ function GeoMap({
1279
1340
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1280
1341
  className
1281
1342
  ),
1343
+ style: {
1344
+ // Use CSS containment to prevent layout shifts in iframes
1345
+ ...isInIframe && { contain: "layout size" }
1346
+ },
1282
1347
  children: [
1283
- /* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
1284
- MapLibre,
1348
+ /* @__PURE__ */ jsx(
1349
+ "div",
1285
1350
  {
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
- }
1351
+ className: cn(
1352
+ "w-full",
1353
+ // Default height, can be overridden by mapWrapperClassName
1354
+ mapWrapperClassName || "h-[520px]"
1355
+ ),
1356
+ style: {
1357
+ // Ensure proper height containment in iframes
1358
+ ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1298
1359
  },
1299
- onMarkerDrag,
1300
- showNavigationControl,
1301
- showGeolocateControl,
1302
- navigationControlPosition,
1303
- geolocateControlPosition,
1304
- flyToOptions,
1305
- className: cn("h-full w-full", mapClassName),
1306
- children: mapChildren
1360
+ children: /* @__PURE__ */ jsx(
1361
+ MapLibre,
1362
+ {
1363
+ stadiaApiKey,
1364
+ mapStyle,
1365
+ styleUrl,
1366
+ mapLibreCssHref,
1367
+ viewState: resolvedViewState,
1368
+ onViewStateChange: applyViewState,
1369
+ markers: mapMarkers,
1370
+ onClick: (coord) => {
1371
+ onMapClick?.(coord);
1372
+ if (clearSelectionOnMapClick) {
1373
+ clearSelection();
1374
+ }
1375
+ },
1376
+ onMarkerDrag,
1377
+ showNavigationControl,
1378
+ showGeolocateControl,
1379
+ navigationControlPosition,
1380
+ geolocateControlPosition,
1381
+ flyToOptions,
1382
+ className: cn("h-full w-full", mapClassName),
1383
+ children: mapChildren
1384
+ }
1385
+ )
1307
1386
  }
1308
- ) }),
1387
+ ),
1309
1388
  selection.type !== "none" ? /* @__PURE__ */ jsx(
1310
1389
  "div",
1311
1390
  {