@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.
@@ -587,53 +587,50 @@ function MapLibre({
587
587
  }
588
588
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
589
589
  }, [mapStyle, stadiaApiKey, styleUrl]);
590
- const isInIframe = React3__namespace.default.useMemo(() => {
591
- if (typeof window === "undefined") return false;
592
- try {
593
- return window.self !== window.top;
594
- } catch {
595
- return true;
596
- }
597
- }, []);
590
+ const containerRef = React3__namespace.default.useRef(null);
598
591
  React3__namespace.default.useEffect(() => {
599
- if (!isInIframe || !mapRef.current) return;
600
- let lastHeight = 0;
601
- let lastWidth = 0;
602
- let resizeTimeout;
603
- const handleResize = (entries) => {
604
- clearTimeout(resizeTimeout);
605
- const entry = entries[0];
606
- if (!entry) return;
607
- const { width, height } = entry.contentRect;
608
- const widthChanged = Math.abs(width - lastWidth) > 1;
609
- const heightChanged = Math.abs(height - lastHeight) > 1;
610
- if (widthChanged || heightChanged) {
611
- lastWidth = width;
612
- lastHeight = height;
613
- resizeTimeout = setTimeout(() => {
614
- mapRef.current?.resize();
615
- }, 250);
592
+ if (!mapRef.current || !containerRef.current) return;
593
+ const enforceContainerHeight = () => {
594
+ const container = containerRef.current;
595
+ const map = mapRef.current;
596
+ if (!container || !map) return;
597
+ const rect = container.getBoundingClientRect();
598
+ const maxHeight = Math.min(rect.height, window.innerHeight);
599
+ const canvas = map.getCanvas();
600
+ if (canvas && canvas.style.height) {
601
+ const canvasHeight = parseInt(canvas.style.height);
602
+ if (canvasHeight > maxHeight || canvasHeight > 2e3) {
603
+ map.resize();
604
+ }
616
605
  }
617
606
  };
618
- const parentElement = mapRef.current.getContainer().parentElement;
619
- if (parentElement) {
620
- const resizeObserver = new ResizeObserver(handleResize);
621
- resizeObserver.observe(parentElement);
622
- return () => {
623
- clearTimeout(resizeTimeout);
624
- resizeObserver.disconnect();
625
- };
607
+ const interval = setInterval(enforceContainerHeight, 1e3);
608
+ let resizeObserver = null;
609
+ if (typeof ResizeObserver !== "undefined") {
610
+ resizeObserver = new ResizeObserver(() => {
611
+ enforceContainerHeight();
612
+ });
613
+ resizeObserver.observe(containerRef.current);
626
614
  }
627
- }, [isInIframe]);
615
+ return () => {
616
+ clearInterval(interval);
617
+ if (resizeObserver) {
618
+ resizeObserver.disconnect();
619
+ }
620
+ };
621
+ }, []);
628
622
  return /* @__PURE__ */ jsxRuntime.jsx(
629
623
  "div",
630
624
  {
625
+ ref: containerRef,
631
626
  className: joinClassNames("relative w-full h-full", className),
632
627
  style: {
633
628
  width: "100%",
634
629
  height: "100%",
635
- // Prevent content from pushing container size in iframes
636
- ...isInIframe && { overflow: "hidden", position: "relative" },
630
+ maxHeight: "100vh",
631
+ // Prevent excessive height
632
+ overflow: "hidden",
633
+ position: "relative",
637
634
  ...style
638
635
  },
639
636
  children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -647,7 +644,7 @@ function MapLibre({
647
644
  onMoveEnd: handleMoveEnd,
648
645
  onClick: handleMapClick,
649
646
  attributionControl: false,
650
- trackResize: !isInIframe,
647
+ trackResize: true,
651
648
  dragRotate: false,
652
649
  touchZoomRotate: false,
653
650
  children: [
@@ -1346,14 +1343,6 @@ function GeoMap({
1346
1343
  }
1347
1344
  return null;
1348
1345
  };
1349
- const isInIframe = React3__namespace.useMemo(() => {
1350
- if (typeof window === "undefined") return false;
1351
- try {
1352
- return window.self !== window.top;
1353
- } catch {
1354
- return true;
1355
- }
1356
- }, []);
1357
1346
  return /* @__PURE__ */ jsxRuntime.jsxs(
1358
1347
  "div",
1359
1348
  {
@@ -1361,10 +1350,6 @@ function GeoMap({
1361
1350
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1362
1351
  className
1363
1352
  ),
1364
- style: {
1365
- // Use CSS containment to prevent layout shifts in iframes
1366
- ...isInIframe && { contain: "layout size" }
1367
- },
1368
1353
  children: [
1369
1354
  /* @__PURE__ */ jsxRuntime.jsx(
1370
1355
  "div",
@@ -1375,8 +1360,12 @@ function GeoMap({
1375
1360
  mapWrapperClassName || "h-[520px]"
1376
1361
  ),
1377
1362
  style: {
1378
- // Ensure proper height containment in iframes
1379
- ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1363
+ // CRITICAL: Always use explicit height to prevent MapLibre canvas expansion
1364
+ height: mapWrapperClassName ? void 0 : "520px",
1365
+ maxHeight: "100vh",
1366
+ // Prevent excessive growth
1367
+ position: "relative",
1368
+ overflow: "hidden"
1380
1369
  },
1381
1370
  children: /* @__PURE__ */ jsxRuntime.jsx(
1382
1371
  MapLibre,