@page-speed/maps 0.1.7 → 0.1.9

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.cjs CHANGED
@@ -478,53 +478,50 @@ function MapLibre({
478
478
  }
479
479
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
480
480
  }, [mapStyle, stadiaApiKey, styleUrl]);
481
- const isInIframe = React3__namespace.default.useMemo(() => {
482
- if (typeof window === "undefined") return false;
483
- try {
484
- return window.self !== window.top;
485
- } catch {
486
- return true;
487
- }
488
- }, []);
481
+ const containerRef = React3__namespace.default.useRef(null);
489
482
  React3__namespace.default.useEffect(() => {
490
- if (!isInIframe || !mapRef.current) return;
491
- let lastHeight = 0;
492
- let lastWidth = 0;
493
- let resizeTimeout;
494
- const handleResize = (entries) => {
495
- clearTimeout(resizeTimeout);
496
- const entry = entries[0];
497
- if (!entry) return;
498
- const { width, height } = entry.contentRect;
499
- const widthChanged = Math.abs(width - lastWidth) > 1;
500
- const heightChanged = Math.abs(height - lastHeight) > 1;
501
- if (widthChanged || heightChanged) {
502
- lastWidth = width;
503
- lastHeight = height;
504
- resizeTimeout = setTimeout(() => {
505
- mapRef.current?.resize();
506
- }, 250);
483
+ if (!mapRef.current || !containerRef.current) return;
484
+ const enforceContainerHeight = () => {
485
+ const container = containerRef.current;
486
+ const map = mapRef.current;
487
+ if (!container || !map) return;
488
+ const rect = container.getBoundingClientRect();
489
+ const maxHeight = Math.min(rect.height, window.innerHeight);
490
+ const canvas = map.getCanvas();
491
+ if (canvas && canvas.style.height) {
492
+ const canvasHeight = parseInt(canvas.style.height);
493
+ if (canvasHeight > maxHeight || canvasHeight > 2e3) {
494
+ map.resize();
495
+ }
507
496
  }
508
497
  };
509
- const parentElement = mapRef.current.getContainer().parentElement;
510
- if (parentElement) {
511
- const resizeObserver = new ResizeObserver(handleResize);
512
- resizeObserver.observe(parentElement);
513
- return () => {
514
- clearTimeout(resizeTimeout);
515
- resizeObserver.disconnect();
516
- };
498
+ const interval = setInterval(enforceContainerHeight, 1e3);
499
+ let resizeObserver = null;
500
+ if (typeof ResizeObserver !== "undefined") {
501
+ resizeObserver = new ResizeObserver(() => {
502
+ enforceContainerHeight();
503
+ });
504
+ resizeObserver.observe(containerRef.current);
517
505
  }
518
- }, [isInIframe]);
506
+ return () => {
507
+ clearInterval(interval);
508
+ if (resizeObserver) {
509
+ resizeObserver.disconnect();
510
+ }
511
+ };
512
+ }, []);
519
513
  return /* @__PURE__ */ jsxRuntime.jsx(
520
514
  "div",
521
515
  {
516
+ ref: containerRef,
522
517
  className: joinClassNames("relative w-full h-full", className),
523
518
  style: {
524
519
  width: "100%",
525
520
  height: "100%",
526
- // Prevent content from pushing container size in iframes
527
- ...isInIframe && { overflow: "hidden", position: "relative" },
521
+ maxHeight: "100vh",
522
+ // Prevent excessive height
523
+ overflow: "hidden",
524
+ position: "relative",
528
525
  ...style
529
526
  },
530
527
  children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -538,7 +535,7 @@ function MapLibre({
538
535
  onMoveEnd: handleMoveEnd,
539
536
  onClick: handleMapClick,
540
537
  attributionControl: false,
541
- trackResize: !isInIframe,
538
+ trackResize: true,
542
539
  dragRotate: false,
543
540
  touchZoomRotate: false,
544
541
  children: [
@@ -1011,9 +1008,25 @@ function GeoMap({
1011
1008
  clearSelectionOnMapClick = true,
1012
1009
  mapChildren,
1013
1010
  optixFlowConfig,
1011
+ mapSize,
1014
1012
  IconComponent = FallbackIcon,
1015
1013
  ImgComponent = FallbackImg
1016
1014
  }) {
1015
+ const [isMobile, setIsMobile] = React3__namespace.useState(false);
1016
+ React3__namespace.useEffect(() => {
1017
+ const checkMobile = () => {
1018
+ setIsMobile(window.innerWidth < 768);
1019
+ };
1020
+ checkMobile();
1021
+ window.addEventListener("resize", checkMobile);
1022
+ return () => window.removeEventListener("resize", checkMobile);
1023
+ }, []);
1024
+ const calculatedHeight = React3__namespace.useMemo(() => {
1025
+ if (mapSize) {
1026
+ return isMobile ? mapSize.mobile : mapSize.desktop;
1027
+ }
1028
+ return isMobile ? 420 : 520;
1029
+ }, [mapSize, isMobile]);
1017
1030
  const normalizedStandaloneMarkers = React3__namespace.useMemo(
1018
1031
  () => markers.map((marker, index) => ({
1019
1032
  ...marker,
@@ -1122,14 +1135,17 @@ function GeoMap({
1122
1135
  const latDiff = Math.max(...lats) - Math.min(...lats);
1123
1136
  const lngDiff = Math.max(...lngs) - Math.min(...lngs);
1124
1137
  const maxDiff = Math.max(latDiff, lngDiff);
1125
- if (maxDiff > 10) return 3;
1126
- if (maxDiff > 5) return 5;
1127
- if (maxDiff > 2) return 7;
1128
- if (maxDiff > 1) return 9;
1129
- if (maxDiff > 0.5) return 10;
1130
- if (maxDiff > 0.1) return 12;
1131
- return 13;
1132
- }, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom]);
1138
+ const heightFactor = calculatedHeight / 520;
1139
+ const paddingFactor = 0.85;
1140
+ if (maxDiff > 10) return Math.max(2, 3 * heightFactor * paddingFactor);
1141
+ if (maxDiff > 5) return Math.max(4, 5 * heightFactor * paddingFactor);
1142
+ if (maxDiff > 2) return Math.max(6, 7 * heightFactor * paddingFactor);
1143
+ if (maxDiff > 1) return Math.max(8, 9 * heightFactor * paddingFactor);
1144
+ if (maxDiff > 0.5) return Math.max(9, 10 * heightFactor * paddingFactor);
1145
+ if (maxDiff > 0.1) return Math.max(11, 12 * heightFactor * paddingFactor);
1146
+ if (maxDiff > 0.01) return Math.max(12, 13 * heightFactor * paddingFactor);
1147
+ return Math.max(11, 12 * heightFactor * paddingFactor);
1148
+ }, [normalizedClusters, normalizedStandaloneMarkers, markerFocusZoom, calculatedHeight]);
1133
1149
  const [uncontrolledViewState, setUncontrolledViewState] = React3__namespace.useState({
1134
1150
  latitude: defaultViewState?.latitude ?? firstCoordinate.latitude,
1135
1151
  longitude: defaultViewState?.longitude ?? firstCoordinate.longitude,
@@ -1452,37 +1468,38 @@ function GeoMap({
1452
1468
  }
1453
1469
  return null;
1454
1470
  };
1455
- const isInIframe = React3__namespace.useMemo(() => {
1456
- if (typeof window === "undefined") return false;
1457
- try {
1458
- return window.self !== window.top;
1459
- } catch {
1460
- return true;
1461
- }
1462
- }, []);
1463
1471
  return /* @__PURE__ */ jsxRuntime.jsxs(
1464
1472
  "div",
1465
1473
  {
1466
1474
  className: cn(
1467
- "relative overflow-hidden rounded-2xl border border-border bg-background",
1475
+ "relative rounded-2xl border border-border bg-background",
1476
+ // Remove overflow-hidden from outer container to allow panel to overflow
1468
1477
  className
1469
1478
  ),
1470
1479
  style: {
1471
- // Use CSS containment to prevent layout shifts in iframes
1472
- ...isInIframe && { contain: "layout size" }
1480
+ // If className includes height settings, they'll override via CSS specificity
1481
+ height: className?.includes("h-[") || className?.includes("min-h-[") || className?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
1482
+ // Explicitly allow overflow for marker panels
1483
+ overflow: "visible"
1473
1484
  },
1474
1485
  children: [
1475
1486
  /* @__PURE__ */ jsxRuntime.jsx(
1476
1487
  "div",
1477
1488
  {
1478
1489
  className: cn(
1479
- "w-full",
1480
- // Default height, can be overridden by mapWrapperClassName
1481
- mapWrapperClassName || "h-[520px]"
1490
+ "w-full rounded-2xl",
1491
+ // Only apply default height class if mapWrapperClassName not provided
1492
+ !mapWrapperClassName && `h-[${calculatedHeight}px]`,
1493
+ mapWrapperClassName
1482
1494
  ),
1483
1495
  style: {
1484
- // Ensure proper height containment in iframes
1485
- ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1496
+ // If mapWrapperClassName includes height, let it handle the height
1497
+ height: mapWrapperClassName?.includes("h-[") || mapWrapperClassName?.includes("min-h-[") || mapWrapperClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`,
1498
+ maxHeight: "100vh",
1499
+ // Prevent excessive growth
1500
+ position: "relative",
1501
+ // Keep overflow hidden only on the map wrapper to contain the canvas
1502
+ overflow: "hidden"
1486
1503
  },
1487
1504
  children: /* @__PURE__ */ jsxRuntime.jsx(
1488
1505
  MapLibre,
@@ -1507,6 +1524,10 @@ function GeoMap({
1507
1524
  geolocateControlPosition,
1508
1525
  flyToOptions,
1509
1526
  className: cn("h-full w-full", mapClassName),
1527
+ style: {
1528
+ // Pass the calculated height to MapLibre for better zoom calculations
1529
+ height: mapClassName?.includes("h-[") || mapClassName?.includes("min-h-[") || mapClassName?.includes("max-h-[") ? void 0 : `${calculatedHeight}px`
1530
+ },
1510
1531
  children: mapChildren
1511
1532
  }
1512
1533
  )
@@ -1516,9 +1537,13 @@ function GeoMap({
1516
1537
  "div",
1517
1538
  {
1518
1539
  className: cn(
1519
- "pointer-events-none absolute z-20",
1540
+ "pointer-events-none absolute z-30",
1520
1541
  PANEL_POSITION_CLASS[panelPosition]
1521
1542
  ),
1543
+ style: {
1544
+ // Ensure panel can overflow and has higher z-index
1545
+ zIndex: 30
1546
+ },
1522
1547
  children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto", children: renderMarkerPanel() })
1523
1548
  }
1524
1549
  ) : null