@page-speed/maps 0.1.6 → 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,11 +457,52 @@ function MapLibre({
457
457
  }
458
458
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
459
459
  }, [mapStyle, stadiaApiKey, styleUrl]);
460
+ const containerRef = React3__default.useRef(null);
461
+ React3__default.useEffect(() => {
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
+ }
475
+ }
476
+ };
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);
484
+ }
485
+ return () => {
486
+ clearInterval(interval);
487
+ if (resizeObserver) {
488
+ resizeObserver.disconnect();
489
+ }
490
+ };
491
+ }, []);
460
492
  return /* @__PURE__ */ jsx(
461
493
  "div",
462
494
  {
495
+ ref: containerRef,
463
496
  className: joinClassNames("relative w-full h-full", className),
464
- style: { width: "100%", height: "100%", ...style },
497
+ style: {
498
+ width: "100%",
499
+ height: "100%",
500
+ maxHeight: "100vh",
501
+ // Prevent excessive height
502
+ overflow: "hidden",
503
+ position: "relative",
504
+ ...style
505
+ },
465
506
  children: /* @__PURE__ */ jsxs(
466
507
  Map$1,
467
508
  {
@@ -1275,7 +1316,7 @@ function GeoMap({
1275
1316
  "div",
1276
1317
  {
1277
1318
  className: cn(
1278
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1319
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1279
1320
  panelClassName
1280
1321
  ),
1281
1322
  children: [
@@ -1349,7 +1390,7 @@ function GeoMap({
1349
1390
  "div",
1350
1391
  {
1351
1392
  className: cn(
1352
- "relative w-[320px] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1393
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1353
1394
  panelClassName
1354
1395
  ),
1355
1396
  children: [
@@ -1395,32 +1436,50 @@ function GeoMap({
1395
1436
  className
1396
1437
  ),
1397
1438
  children: [
1398
- /* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
1399
- MapLibre,
1439
+ /* @__PURE__ */ jsx(
1440
+ "div",
1400
1441
  {
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
- }
1442
+ className: cn(
1443
+ "w-full",
1444
+ // Default height, can be overridden by mapWrapperClassName
1445
+ mapWrapperClassName || "h-[520px]"
1446
+ ),
1447
+ style: {
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"
1413
1454
  },
1414
- onMarkerDrag,
1415
- showNavigationControl,
1416
- showGeolocateControl,
1417
- navigationControlPosition,
1418
- geolocateControlPosition,
1419
- flyToOptions,
1420
- className: cn("h-full w-full", mapClassName),
1421
- children: mapChildren
1455
+ children: /* @__PURE__ */ jsx(
1456
+ MapLibre,
1457
+ {
1458
+ stadiaApiKey,
1459
+ mapStyle,
1460
+ styleUrl,
1461
+ mapLibreCssHref,
1462
+ viewState: resolvedViewState,
1463
+ onViewStateChange: applyViewState,
1464
+ markers: mapMarkers,
1465
+ onClick: (coord) => {
1466
+ onMapClick?.(coord);
1467
+ if (clearSelectionOnMapClick) {
1468
+ clearSelection();
1469
+ }
1470
+ },
1471
+ onMarkerDrag,
1472
+ showNavigationControl,
1473
+ showGeolocateControl,
1474
+ navigationControlPosition,
1475
+ geolocateControlPosition,
1476
+ flyToOptions,
1477
+ className: cn("h-full w-full", mapClassName),
1478
+ children: mapChildren
1479
+ }
1480
+ )
1422
1481
  }
1423
- ) }),
1482
+ ),
1424
1483
  selection.type !== "none" ? /* @__PURE__ */ jsx(
1425
1484
  "div",
1426
1485
  {