@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.
package/dist/index.js CHANGED
@@ -457,11 +457,55 @@ function MapLibre({
457
457
  }
458
458
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
459
459
  }, [mapStyle, stadiaApiKey, styleUrl]);
460
+ const isInIframe = React3__default.useMemo(() => {
461
+ if (typeof window === "undefined") return false;
462
+ try {
463
+ return window.self !== window.top;
464
+ } catch {
465
+ return true;
466
+ }
467
+ }, []);
468
+ React3__default.useEffect(() => {
469
+ if (!isInIframe || !mapRef.current) return;
470
+ let lastHeight = 0;
471
+ let lastWidth = 0;
472
+ let resizeTimeout;
473
+ const handleResize = (entries) => {
474
+ clearTimeout(resizeTimeout);
475
+ const entry = entries[0];
476
+ if (!entry) return;
477
+ const { width, height } = entry.contentRect;
478
+ const widthChanged = Math.abs(width - lastWidth) > 1;
479
+ const heightChanged = Math.abs(height - lastHeight) > 1;
480
+ if (widthChanged || heightChanged) {
481
+ lastWidth = width;
482
+ lastHeight = height;
483
+ resizeTimeout = setTimeout(() => {
484
+ mapRef.current?.resize();
485
+ }, 250);
486
+ }
487
+ };
488
+ const parentElement = mapRef.current.getContainer().parentElement;
489
+ if (parentElement) {
490
+ const resizeObserver = new ResizeObserver(handleResize);
491
+ resizeObserver.observe(parentElement);
492
+ return () => {
493
+ clearTimeout(resizeTimeout);
494
+ resizeObserver.disconnect();
495
+ };
496
+ }
497
+ }, [isInIframe]);
460
498
  return /* @__PURE__ */ jsx(
461
499
  "div",
462
500
  {
463
501
  className: joinClassNames("relative w-full h-full", className),
464
- style: { width: "100%", height: "100%", ...style },
502
+ style: {
503
+ width: "100%",
504
+ height: "100%",
505
+ // Prevent content from pushing container size in iframes
506
+ ...isInIframe && { overflow: "hidden", position: "relative" },
507
+ ...style
508
+ },
465
509
  children: /* @__PURE__ */ jsxs(
466
510
  Map$1,
467
511
  {
@@ -473,7 +517,7 @@ function MapLibre({
473
517
  onMoveEnd: handleMoveEnd,
474
518
  onClick: handleMapClick,
475
519
  attributionControl: false,
476
- trackResize: true,
520
+ trackResize: !isInIframe,
477
521
  dragRotate: false,
478
522
  touchZoomRotate: false,
479
523
  children: [
@@ -1275,7 +1319,7 @@ function GeoMap({
1275
1319
  "div",
1276
1320
  {
1277
1321
  className: cn(
1278
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1322
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1279
1323
  panelClassName
1280
1324
  ),
1281
1325
  children: [
@@ -1349,7 +1393,7 @@ function GeoMap({
1349
1393
  "div",
1350
1394
  {
1351
1395
  className: cn(
1352
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1396
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1353
1397
  panelClassName
1354
1398
  ),
1355
1399
  children: [
@@ -1387,6 +1431,14 @@ function GeoMap({
1387
1431
  }
1388
1432
  return null;
1389
1433
  };
1434
+ const isInIframe = React3.useMemo(() => {
1435
+ if (typeof window === "undefined") return false;
1436
+ try {
1437
+ return window.self !== window.top;
1438
+ } catch {
1439
+ return true;
1440
+ }
1441
+ }, []);
1390
1442
  return /* @__PURE__ */ jsxs(
1391
1443
  "div",
1392
1444
  {
@@ -1394,33 +1446,51 @@ function GeoMap({
1394
1446
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1395
1447
  className
1396
1448
  ),
1449
+ style: {
1450
+ // Use CSS containment to prevent layout shifts in iframes
1451
+ ...isInIframe && { contain: "layout size" }
1452
+ },
1397
1453
  children: [
1398
- /* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
1399
- MapLibre,
1454
+ /* @__PURE__ */ jsx(
1455
+ "div",
1400
1456
  {
1401
- stadiaApiKey,
1402
- mapStyle,
1403
- styleUrl,
1404
- mapLibreCssHref,
1405
- viewState: resolvedViewState,
1406
- onViewStateChange: applyViewState,
1407
- markers: mapMarkers,
1408
- onClick: (coord) => {
1409
- onMapClick?.(coord);
1410
- if (clearSelectionOnMapClick) {
1411
- clearSelection();
1412
- }
1457
+ className: cn(
1458
+ "w-full",
1459
+ // Default height, can be overridden by mapWrapperClassName
1460
+ mapWrapperClassName || "h-[520px]"
1461
+ ),
1462
+ style: {
1463
+ // Ensure proper height containment in iframes
1464
+ ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1413
1465
  },
1414
- onMarkerDrag,
1415
- showNavigationControl,
1416
- showGeolocateControl,
1417
- navigationControlPosition,
1418
- geolocateControlPosition,
1419
- flyToOptions,
1420
- className: cn("h-full w-full", mapClassName),
1421
- children: mapChildren
1466
+ children: /* @__PURE__ */ jsx(
1467
+ MapLibre,
1468
+ {
1469
+ stadiaApiKey,
1470
+ mapStyle,
1471
+ styleUrl,
1472
+ mapLibreCssHref,
1473
+ viewState: resolvedViewState,
1474
+ onViewStateChange: applyViewState,
1475
+ markers: mapMarkers,
1476
+ onClick: (coord) => {
1477
+ onMapClick?.(coord);
1478
+ if (clearSelectionOnMapClick) {
1479
+ clearSelection();
1480
+ }
1481
+ },
1482
+ onMarkerDrag,
1483
+ showNavigationControl,
1484
+ showGeolocateControl,
1485
+ navigationControlPosition,
1486
+ geolocateControlPosition,
1487
+ flyToOptions,
1488
+ className: cn("h-full w-full", mapClassName),
1489
+ children: mapChildren
1490
+ }
1491
+ )
1422
1492
  }
1423
- ) }),
1493
+ ),
1424
1494
  selection.type !== "none" ? /* @__PURE__ */ jsx(
1425
1495
  "div",
1426
1496
  {