@page-speed/maps 0.1.7 → 0.1.8

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,53 +566,50 @@ 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
- }, []);
569
+ const containerRef = React3__default.useRef(null);
577
570
  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);
571
+ if (!mapRef.current || !containerRef.current) return;
572
+ const enforceContainerHeight = () => {
573
+ const container = containerRef.current;
574
+ const map = mapRef.current;
575
+ if (!container || !map) return;
576
+ const rect = container.getBoundingClientRect();
577
+ const maxHeight = Math.min(rect.height, window.innerHeight);
578
+ const canvas = map.getCanvas();
579
+ if (canvas && canvas.style.height) {
580
+ const canvasHeight = parseInt(canvas.style.height);
581
+ if (canvasHeight > maxHeight || canvasHeight > 2e3) {
582
+ map.resize();
583
+ }
595
584
  }
596
585
  };
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
- };
586
+ const interval = setInterval(enforceContainerHeight, 1e3);
587
+ let resizeObserver = null;
588
+ if (typeof ResizeObserver !== "undefined") {
589
+ resizeObserver = new ResizeObserver(() => {
590
+ enforceContainerHeight();
591
+ });
592
+ resizeObserver.observe(containerRef.current);
605
593
  }
606
- }, [isInIframe]);
594
+ return () => {
595
+ clearInterval(interval);
596
+ if (resizeObserver) {
597
+ resizeObserver.disconnect();
598
+ }
599
+ };
600
+ }, []);
607
601
  return /* @__PURE__ */ jsx(
608
602
  "div",
609
603
  {
604
+ ref: containerRef,
610
605
  className: joinClassNames("relative w-full h-full", className),
611
606
  style: {
612
607
  width: "100%",
613
608
  height: "100%",
614
- // Prevent content from pushing container size in iframes
615
- ...isInIframe && { overflow: "hidden", position: "relative" },
609
+ maxHeight: "100vh",
610
+ // Prevent excessive height
611
+ overflow: "hidden",
612
+ position: "relative",
616
613
  ...style
617
614
  },
618
615
  children: /* @__PURE__ */ jsxs(
@@ -626,7 +623,7 @@ function MapLibre({
626
623
  onMoveEnd: handleMoveEnd,
627
624
  onClick: handleMapClick,
628
625
  attributionControl: false,
629
- trackResize: !isInIframe,
626
+ trackResize: true,
630
627
  dragRotate: false,
631
628
  touchZoomRotate: false,
632
629
  children: [
@@ -1325,14 +1322,6 @@ function GeoMap({
1325
1322
  }
1326
1323
  return null;
1327
1324
  };
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
- }, []);
1336
1325
  return /* @__PURE__ */ jsxs(
1337
1326
  "div",
1338
1327
  {
@@ -1340,10 +1329,6 @@ function GeoMap({
1340
1329
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1341
1330
  className
1342
1331
  ),
1343
- style: {
1344
- // Use CSS containment to prevent layout shifts in iframes
1345
- ...isInIframe && { contain: "layout size" }
1346
- },
1347
1332
  children: [
1348
1333
  /* @__PURE__ */ jsx(
1349
1334
  "div",
@@ -1354,8 +1339,12 @@ function GeoMap({
1354
1339
  mapWrapperClassName || "h-[520px]"
1355
1340
  ),
1356
1341
  style: {
1357
- // Ensure proper height containment in iframes
1358
- ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1342
+ // CRITICAL: Always use explicit height to prevent MapLibre canvas expansion
1343
+ height: mapWrapperClassName ? void 0 : "520px",
1344
+ maxHeight: "100vh",
1345
+ // Prevent excessive growth
1346
+ position: "relative",
1347
+ overflow: "hidden"
1359
1348
  },
1360
1349
  children: /* @__PURE__ */ jsx(
1361
1350
  MapLibre,