@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.
package/dist/index.js CHANGED
@@ -457,53 +457,50 @@ 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
- }, []);
460
+ const containerRef = React3__default.useRef(null);
468
461
  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);
462
+ if (!mapRef.current || !containerRef.current) return;
463
+ const enforceContainerHeight = () => {
464
+ const container = containerRef.current;
465
+ const map = mapRef.current;
466
+ if (!container || !map) return;
467
+ const rect = container.getBoundingClientRect();
468
+ const maxHeight = Math.min(rect.height, window.innerHeight);
469
+ const canvas = map.getCanvas();
470
+ if (canvas && canvas.style.height) {
471
+ const canvasHeight = parseInt(canvas.style.height);
472
+ if (canvasHeight > maxHeight || canvasHeight > 2e3) {
473
+ map.resize();
474
+ }
486
475
  }
487
476
  };
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
- };
477
+ const interval = setInterval(enforceContainerHeight, 1e3);
478
+ let resizeObserver = null;
479
+ if (typeof ResizeObserver !== "undefined") {
480
+ resizeObserver = new ResizeObserver(() => {
481
+ enforceContainerHeight();
482
+ });
483
+ resizeObserver.observe(containerRef.current);
496
484
  }
497
- }, [isInIframe]);
485
+ return () => {
486
+ clearInterval(interval);
487
+ if (resizeObserver) {
488
+ resizeObserver.disconnect();
489
+ }
490
+ };
491
+ }, []);
498
492
  return /* @__PURE__ */ jsx(
499
493
  "div",
500
494
  {
495
+ ref: containerRef,
501
496
  className: joinClassNames("relative w-full h-full", className),
502
497
  style: {
503
498
  width: "100%",
504
499
  height: "100%",
505
- // Prevent content from pushing container size in iframes
506
- ...isInIframe && { overflow: "hidden", position: "relative" },
500
+ maxHeight: "100vh",
501
+ // Prevent excessive height
502
+ overflow: "hidden",
503
+ position: "relative",
507
504
  ...style
508
505
  },
509
506
  children: /* @__PURE__ */ jsxs(
@@ -517,7 +514,7 @@ function MapLibre({
517
514
  onMoveEnd: handleMoveEnd,
518
515
  onClick: handleMapClick,
519
516
  attributionControl: false,
520
- trackResize: !isInIframe,
517
+ trackResize: true,
521
518
  dragRotate: false,
522
519
  touchZoomRotate: false,
523
520
  children: [
@@ -1431,14 +1428,6 @@ function GeoMap({
1431
1428
  }
1432
1429
  return null;
1433
1430
  };
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
- }, []);
1442
1431
  return /* @__PURE__ */ jsxs(
1443
1432
  "div",
1444
1433
  {
@@ -1446,10 +1435,6 @@ function GeoMap({
1446
1435
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1447
1436
  className
1448
1437
  ),
1449
- style: {
1450
- // Use CSS containment to prevent layout shifts in iframes
1451
- ...isInIframe && { contain: "layout size" }
1452
- },
1453
1438
  children: [
1454
1439
  /* @__PURE__ */ jsx(
1455
1440
  "div",
@@ -1460,8 +1445,12 @@ function GeoMap({
1460
1445
  mapWrapperClassName || "h-[520px]"
1461
1446
  ),
1462
1447
  style: {
1463
- // Ensure proper height containment in iframes
1464
- ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1448
+ // CRITICAL: Always use explicit height to prevent MapLibre canvas expansion
1449
+ height: mapWrapperClassName ? void 0 : "520px",
1450
+ maxHeight: "100vh",
1451
+ // Prevent excessive growth
1452
+ position: "relative",
1453
+ overflow: "hidden"
1465
1454
  },
1466
1455
  children: /* @__PURE__ */ jsx(
1467
1456
  MapLibre,