@page-speed/maps 0.1.5 → 0.1.7

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.
@@ -447,11 +447,55 @@ function MapLibre({
447
447
  }
448
448
  return getMapLibreStyleUrl("osm-bright", stadiaApiKey);
449
449
  }, [mapStyle, stadiaApiKey, styleUrl]);
450
+ const isInIframe = React3__default.useMemo(() => {
451
+ if (typeof window === "undefined") return false;
452
+ try {
453
+ return window.self !== window.top;
454
+ } catch {
455
+ return true;
456
+ }
457
+ }, []);
458
+ React3__default.useEffect(() => {
459
+ if (!isInIframe || !mapRef.current) return;
460
+ let lastHeight = 0;
461
+ let lastWidth = 0;
462
+ let resizeTimeout;
463
+ const handleResize = (entries) => {
464
+ clearTimeout(resizeTimeout);
465
+ const entry = entries[0];
466
+ if (!entry) return;
467
+ const { width, height } = entry.contentRect;
468
+ const widthChanged = Math.abs(width - lastWidth) > 1;
469
+ const heightChanged = Math.abs(height - lastHeight) > 1;
470
+ if (widthChanged || heightChanged) {
471
+ lastWidth = width;
472
+ lastHeight = height;
473
+ resizeTimeout = setTimeout(() => {
474
+ mapRef.current?.resize();
475
+ }, 250);
476
+ }
477
+ };
478
+ const parentElement = mapRef.current.getContainer().parentElement;
479
+ if (parentElement) {
480
+ const resizeObserver = new ResizeObserver(handleResize);
481
+ resizeObserver.observe(parentElement);
482
+ return () => {
483
+ clearTimeout(resizeTimeout);
484
+ resizeObserver.disconnect();
485
+ };
486
+ }
487
+ }, [isInIframe]);
450
488
  return /* @__PURE__ */ jsx(
451
489
  "div",
452
490
  {
453
491
  className: joinClassNames("relative w-full h-full", className),
454
- style: { width: "100%", height: "100%", ...style },
492
+ style: {
493
+ width: "100%",
494
+ height: "100%",
495
+ // Prevent content from pushing container size in iframes
496
+ ...isInIframe && { overflow: "hidden", position: "relative" },
497
+ ...style
498
+ },
455
499
  children: /* @__PURE__ */ jsxs(
456
500
  Map$1,
457
501
  {
@@ -463,7 +507,7 @@ function MapLibre({
463
507
  onMoveEnd: handleMoveEnd,
464
508
  onClick: handleMapClick,
465
509
  attributionControl: false,
466
- trackResize: true,
510
+ trackResize: !isInIframe,
467
511
  dragRotate: false,
468
512
  touchZoomRotate: false,
469
513
  children: [
@@ -526,10 +570,7 @@ function resolveActionKey(action, index) {
526
570
  }
527
571
  return `action:${index}`;
528
572
  }
529
- var FallbackIcon = ({
530
- size = 20,
531
- className
532
- }) => /* @__PURE__ */ jsx(
573
+ var FallbackIcon = ({ size = 20, className }) => /* @__PURE__ */ jsx(
533
574
  "svg",
534
575
  {
535
576
  width: size,
@@ -648,7 +689,7 @@ function MarkerMediaCarousel({
648
689
  {
649
690
  type: "button",
650
691
  "aria-label": "Show previous media",
651
- className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-[2]",
692
+ className: "absolute left-4 top-1/2 inline-flex size-10 -translate-y-1/2 items-center justify-center rounded-2xl bg-card text-card-foreground shadow-lg border-4 border-black hover:border-white hover:bg-black hover:text-white transition-all duration-500 z-2",
652
693
  onClick: () => {
653
694
  setActiveIndex(
654
695
  (current) => (current - 1 + totalItems) % totalItems
@@ -781,10 +822,16 @@ function GeoMap({
781
822
  const firstCoordinate = React3.useMemo(() => {
782
823
  const allCoords = [];
783
824
  normalizedStandaloneMarkers.forEach((marker) => {
784
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
825
+ allCoords.push({
826
+ latitude: marker.latitude,
827
+ longitude: marker.longitude
828
+ });
785
829
  });
786
830
  normalizedClusters.forEach((cluster) => {
787
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
831
+ allCoords.push({
832
+ latitude: cluster.latitude,
833
+ longitude: cluster.longitude
834
+ });
788
835
  });
789
836
  if (allCoords.length > 0) {
790
837
  const sum = allCoords.reduce(
@@ -810,10 +857,16 @@ function GeoMap({
810
857
  }
811
858
  const allCoords = [];
812
859
  normalizedStandaloneMarkers.forEach((marker) => {
813
- allCoords.push({ latitude: marker.latitude, longitude: marker.longitude });
860
+ allCoords.push({
861
+ latitude: marker.latitude,
862
+ longitude: marker.longitude
863
+ });
814
864
  });
815
865
  normalizedClusters.forEach((cluster) => {
816
- allCoords.push({ latitude: cluster.latitude, longitude: cluster.longitude });
866
+ allCoords.push({
867
+ latitude: cluster.latitude,
868
+ longitude: cluster.longitude
869
+ });
817
870
  });
818
871
  if (allCoords.length === 0) {
819
872
  return DEFAULT_VIEW_STATE.zoom;
@@ -1041,7 +1094,7 @@ function GeoMap({
1041
1094
  "div",
1042
1095
  {
1043
1096
  className: cn(
1044
- "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1097
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground shadow-2xl",
1045
1098
  panelClassName
1046
1099
  ),
1047
1100
  children: [
@@ -1115,7 +1168,7 @@ function GeoMap({
1115
1168
  "div",
1116
1169
  {
1117
1170
  className: cn(
1118
- "relative w-[min(24rem,calc(100vw-2rem))] overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1171
+ "relative w-80 overflow-hidden rounded-xl border border-border bg-card text-card-foreground p-4 shadow-2xl",
1119
1172
  panelClassName
1120
1173
  ),
1121
1174
  children: [
@@ -1153,6 +1206,14 @@ function GeoMap({
1153
1206
  }
1154
1207
  return null;
1155
1208
  };
1209
+ const isInIframe = React3.useMemo(() => {
1210
+ if (typeof window === "undefined") return false;
1211
+ try {
1212
+ return window.self !== window.top;
1213
+ } catch {
1214
+ return true;
1215
+ }
1216
+ }, []);
1156
1217
  return /* @__PURE__ */ jsxs(
1157
1218
  "div",
1158
1219
  {
@@ -1160,33 +1221,51 @@ function GeoMap({
1160
1221
  "relative overflow-hidden rounded-2xl border border-border bg-background",
1161
1222
  className
1162
1223
  ),
1224
+ style: {
1225
+ // Use CSS containment to prevent layout shifts in iframes
1226
+ ...isInIframe && { contain: "layout size" }
1227
+ },
1163
1228
  children: [
1164
- /* @__PURE__ */ jsx("div", { className: cn("h-[520px] w-full", mapWrapperClassName), children: /* @__PURE__ */ jsx(
1165
- MapLibre,
1229
+ /* @__PURE__ */ jsx(
1230
+ "div",
1166
1231
  {
1167
- stadiaApiKey,
1168
- mapStyle,
1169
- styleUrl,
1170
- mapLibreCssHref,
1171
- viewState: resolvedViewState,
1172
- onViewStateChange: applyViewState,
1173
- markers: mapMarkers,
1174
- onClick: (coord) => {
1175
- onMapClick?.(coord);
1176
- if (clearSelectionOnMapClick) {
1177
- clearSelection();
1178
- }
1232
+ className: cn(
1233
+ "w-full",
1234
+ // Default height, can be overridden by mapWrapperClassName
1235
+ mapWrapperClassName || "h-[520px]"
1236
+ ),
1237
+ style: {
1238
+ // Ensure proper height containment in iframes
1239
+ ...isInIframe && !mapWrapperClassName && { height: "520px", minHeight: "420px" }
1179
1240
  },
1180
- onMarkerDrag,
1181
- showNavigationControl,
1182
- showGeolocateControl,
1183
- navigationControlPosition,
1184
- geolocateControlPosition,
1185
- flyToOptions,
1186
- className: cn("h-full w-full", mapClassName),
1187
- children: mapChildren
1241
+ children: /* @__PURE__ */ jsx(
1242
+ MapLibre,
1243
+ {
1244
+ stadiaApiKey,
1245
+ mapStyle,
1246
+ styleUrl,
1247
+ mapLibreCssHref,
1248
+ viewState: resolvedViewState,
1249
+ onViewStateChange: applyViewState,
1250
+ markers: mapMarkers,
1251
+ onClick: (coord) => {
1252
+ onMapClick?.(coord);
1253
+ if (clearSelectionOnMapClick) {
1254
+ clearSelection();
1255
+ }
1256
+ },
1257
+ onMarkerDrag,
1258
+ showNavigationControl,
1259
+ showGeolocateControl,
1260
+ navigationControlPosition,
1261
+ geolocateControlPosition,
1262
+ flyToOptions,
1263
+ className: cn("h-full w-full", mapClassName),
1264
+ children: mapChildren
1265
+ }
1266
+ )
1188
1267
  }
1189
- ) }),
1268
+ ),
1190
1269
  selection.type !== "none" ? /* @__PURE__ */ jsx(
1191
1270
  "div",
1192
1271
  {