@page-speed/maps 0.1.6 → 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.
@@ -447,11 +447,55 @@ function MapLibre({
447
447
  }
448
448
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
449
449
  }, [mapStyle, stadiaApiKey, styleUrl]);
450
+ const isInIframe = React3__default.useMemo(() => {
451
+ if (typeof window === "undefined") return false;
452
+ try {
453
+ return window.self !== window.top;
454
+ } catch {
455
+ return true;
456
+ }
457
+ }, []);
458
+ React3__default.useEffect(() => {
459
+ if (!isInIframe || !mapRef.current) return;
460
+ let lastHeight = 0;
461
+ let lastWidth = 0;
462
+ let resizeTimeout;
463
+ const handleResize = (entries) => {
464
+ clearTimeout(resizeTimeout);
465
+ const entry = entries[0];
466
+ if (!entry) return;
467
+ const { width, height } = entry.contentRect;
468
+ const widthChanged = Math.abs(width - lastWidth) > 1;
469
+ const heightChanged = Math.abs(height - lastHeight) > 1;
470
+ if (widthChanged || heightChanged) {
471
+ lastWidth = width;
472
+ lastHeight = height;
473
+ resizeTimeout = setTimeout(() => {
474
+ mapRef.current?.resize();
475
+ }, 250);
476
+ }
477
+ };
478
+ const parentElement = mapRef.current.getContainer().parentElement;
479
+ if (parentElement) {
480
+ const resizeObserver = new ResizeObserver(handleResize);
481
+ resizeObserver.observe(parentElement);
482
+ return () => {
483
+ clearTimeout(resizeTimeout);
484
+ resizeObserver.disconnect();
485
+ };
486
+ }
487
+ }, [isInIframe]);
450
488
  return /* @__PURE__ */ jsx(
451
489
  "div",
452
490
  {
453
491
  className: joinClassNames("relative w-full h-full", className),
454
- style: { width: "100%", height: "100%", ...style },
492
+ style: {
493
+ width: "100%",
494
+ height: "100%",
495
+ // Prevent content from pushing container size in iframes
496
+ ...isInIframe && { overflow: "hidden", position: "relative" },
497
+ ...style
498
+ },
455
499
  children: /* @__PURE__ */ jsxs(
456
500
  Map$1,
457
501
  {
@@ -463,7 +507,7 @@ function MapLibre({
463
507
  onMoveEnd: handleMoveEnd,
464
508
  onClick: handleMapClick,
465
509
  attributionControl: false,
466
- trackResize: true,
510
+ trackResize: !isInIframe,
467
511
  dragRotate: false,
468
512
  touchZoomRotate: false,
469
513
  children: [
@@ -1050,7 +1094,7 @@ function GeoMap({
1050
1094
  "div",
1051
1095
  {
1052
1096
  className: cn(
1053
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1097
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1054
1098
  panelClassName
1055
1099
  ),
1056
1100
  children: [
@@ -1124,7 +1168,7 @@ function GeoMap({
1124
1168
  "div",
1125
1169
  {
1126
1170
  className: cn(
1127
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1171
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1128
1172
  panelClassName
1129
1173
  ),
1130
1174
  children: [
@@ -1162,6 +1206,14 @@ function GeoMap({
1162
1206
  }
1163
1207
  return null;
1164
1208
  };
1209
+ const isInIframe = React3.useMemo(() => {
1210
+ if (typeof window === "undefined") return false;
1211
+ try {
1212
+ return window.self !== window.top;
1213
+ } catch {
1214
+ return true;
1215
+ }
1216
+ }, []);
1165
1217
  return /* @__PURE__ */ jsxs(
1166
1218
  "div",
1167
1219
  {
@@ -1169,33 +1221,51 @@ function GeoMap({
1169
1221
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1170
1222
  className
1171
1223
  ),
1224
+ style: {
1225
+ // Use CSS containment to prevent layout shifts in iframes
1226
+ ...isInIframe && { contain: "layout size" }
1227
+ },
1172
1228
  children: [
1173
- /* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
1174
- MapLibre,
1229
+ /* @__PURE__ */ jsx(
1230
+ "div",
1175
1231
  {
1176
- stadiaApiKey,
1177
- mapStyle,
1178
- styleUrl,
1179
- mapLibreCssHref,
1180
- viewState: resolvedViewState,
1181
- onViewStateChange: applyViewState,
1182
- markers: mapMarkers,
1183
- onClick: (coord) => {
1184
- onMapClick?.(coord);
1185
- if (clearSelectionOnMapClick) {
1186
- clearSelection();
1187
- }
1232
+ className: cn(
1233
+ "w-full",
1234
+ // Default height, can be overridden by mapWrapperClassName
1235
+ mapWrapperClassName || "h-[520px]"
1236
+ ),
1237
+ style: {
1238
+ // Ensure proper height containment in iframes
1239
+ ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1188
1240
  },
1189
- onMarkerDrag,
1190
- showNavigationControl,
1191
- showGeolocateControl,
1192
- navigationControlPosition,
1193
- geolocateControlPosition,
1194
- flyToOptions,
1195
- className: cn("h-full w-full", mapClassName),
1196
- children: mapChildren
1241
+ children: /* @__PURE__ */ jsx(
1242
+ MapLibre,
1243
+ {
1244
+ stadiaApiKey,
1245
+ mapStyle,
1246
+ styleUrl,
1247
+ mapLibreCssHref,
1248
+ viewState: resolvedViewState,
1249
+ onViewStateChange: applyViewState,
1250
+ markers: mapMarkers,
1251
+ onClick: (coord) => {
1252
+ onMapClick?.(coord);
1253
+ if (clearSelectionOnMapClick) {
1254
+ clearSelection();
1255
+ }
1256
+ },
1257
+ onMarkerDrag,
1258
+ showNavigationControl,
1259
+ showGeolocateControl,
1260
+ navigationControlPosition,
1261
+ geolocateControlPosition,
1262
+ flyToOptions,
1263
+ className: cn("h-full w-full", mapClassName),
1264
+ children: mapChildren
1265
+ }
1266
+ )
1197
1267
  }
1198
- ) }),
1268
+ ),
1199
1269
  selection.type !== "none" ? /* @__PURE__ */ jsx(
1200
1270
  "div",
1201
1271
  {