@classic-homes/maps-react 0.2.8 → 0.2.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 +8 -41
- package/dist/index.js +7 -40
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ require('@classic-homes/maps-core/styles/controls.css');
|
|
|
10
10
|
require('@classic-homes/maps-core/styles/marker.css');
|
|
11
11
|
var mapsCore = require('@classic-homes/maps-core');
|
|
12
12
|
var ReactDOM = require('react-dom');
|
|
13
|
+
var utils = require('@classic-homes/maps-core/utils');
|
|
13
14
|
var classVarianceAuthority = require('class-variance-authority');
|
|
14
15
|
require('@classic-homes/maps-core/styles/basemap-switcher.css');
|
|
15
16
|
require('@classic-homes/maps-core/styles/layer-manager.css');
|
|
@@ -287,7 +288,7 @@ function useMapTheme(preference = "auto") {
|
|
|
287
288
|
};
|
|
288
289
|
}
|
|
289
290
|
function useReducedMotion() {
|
|
290
|
-
const [
|
|
291
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = React26.useState(false);
|
|
291
292
|
React26.useEffect(() => {
|
|
292
293
|
if (typeof window === "undefined") return;
|
|
293
294
|
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
@@ -300,7 +301,7 @@ function useReducedMotion() {
|
|
|
300
301
|
mediaQuery.removeEventListener("change", handleChange);
|
|
301
302
|
};
|
|
302
303
|
}, []);
|
|
303
|
-
return
|
|
304
|
+
return prefersReducedMotion;
|
|
304
305
|
}
|
|
305
306
|
var MapContext = React26__namespace.createContext(null);
|
|
306
307
|
function useMap() {
|
|
@@ -391,7 +392,7 @@ var Map2 = React26__namespace.forwardRef(
|
|
|
391
392
|
});
|
|
392
393
|
}
|
|
393
394
|
}, []);
|
|
394
|
-
const
|
|
395
|
+
const prefersReducedMotion = useReducedMotion();
|
|
395
396
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
396
397
|
const onLoadRef = React26__namespace.useRef(onLoad);
|
|
397
398
|
onLoadRef.current = onLoad;
|
|
@@ -532,7 +533,7 @@ var Map2 = React26__namespace.forwardRef(
|
|
|
532
533
|
if (bounds) {
|
|
533
534
|
map.fitBounds(bounds, {
|
|
534
535
|
padding: boundsPadding,
|
|
535
|
-
animate: animation && !
|
|
536
|
+
animate: animation && !prefersReducedMotion
|
|
536
537
|
});
|
|
537
538
|
}
|
|
538
539
|
onLoadRef.current?.({ type: "load", loaded: true });
|
|
@@ -768,7 +769,7 @@ var Source = ({
|
|
|
768
769
|
console.warn("[maps-react] Source: Invalid bounds calculated, skipping fitBounds");
|
|
769
770
|
return;
|
|
770
771
|
}
|
|
771
|
-
const
|
|
772
|
+
const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
772
773
|
const rafHandle = requestAnimationFrame(() => {
|
|
773
774
|
if (cancelledRef.current || initialFitDone.current) return;
|
|
774
775
|
try {
|
|
@@ -784,7 +785,7 @@ var Source = ({
|
|
|
784
785
|
map.flyTo({
|
|
785
786
|
center: [centerLng, centerLat],
|
|
786
787
|
zoom: Math.max(zoom, 1),
|
|
787
|
-
animate: params.fitBoundsAnimate && !
|
|
788
|
+
animate: params.fitBoundsAnimate && !prefersReducedMotion,
|
|
788
789
|
padding: params.fitBoundsPadding
|
|
789
790
|
});
|
|
790
791
|
initialFitDone.current = true;
|
|
@@ -1187,40 +1188,6 @@ var Marker = React26__namespace.forwardRef(
|
|
|
1187
1188
|
}
|
|
1188
1189
|
);
|
|
1189
1190
|
Marker.displayName = "Marker";
|
|
1190
|
-
function normalizePadding(padding) {
|
|
1191
|
-
if (typeof padding === "number") {
|
|
1192
|
-
return { top: padding, right: padding, bottom: padding, left: padding };
|
|
1193
|
-
}
|
|
1194
|
-
return padding;
|
|
1195
|
-
}
|
|
1196
|
-
function prefersReducedMotion() {
|
|
1197
|
-
if (typeof window === "undefined") return false;
|
|
1198
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1199
|
-
}
|
|
1200
|
-
function panToFitPopup(map, popup, padding) {
|
|
1201
|
-
const popupEl = popup.getElement();
|
|
1202
|
-
if (!popupEl) return;
|
|
1203
|
-
const mapContainer = map.getContainer();
|
|
1204
|
-
const mapRect = mapContainer.getBoundingClientRect();
|
|
1205
|
-
const popupRect = popupEl.getBoundingClientRect();
|
|
1206
|
-
let dx = 0;
|
|
1207
|
-
let dy = 0;
|
|
1208
|
-
if (popupRect.left < mapRect.left + padding.left) {
|
|
1209
|
-
dx = popupRect.left - mapRect.left - padding.left;
|
|
1210
|
-
} else if (popupRect.right > mapRect.right - padding.right) {
|
|
1211
|
-
dx = popupRect.right - mapRect.right + padding.right;
|
|
1212
|
-
}
|
|
1213
|
-
if (popupRect.top < mapRect.top + padding.top) {
|
|
1214
|
-
dy = popupRect.top - mapRect.top - padding.top;
|
|
1215
|
-
} else if (popupRect.bottom > mapRect.bottom - padding.bottom) {
|
|
1216
|
-
dy = popupRect.bottom - mapRect.bottom + padding.bottom;
|
|
1217
|
-
}
|
|
1218
|
-
if (dx !== 0 || dy !== 0) {
|
|
1219
|
-
map.panBy([dx, dy], {
|
|
1220
|
-
animate: !prefersReducedMotion()
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
1191
|
var Popup = React26__namespace.forwardRef(
|
|
1225
1192
|
({
|
|
1226
1193
|
coordinates,
|
|
@@ -1318,7 +1285,7 @@ var Popup = React26__namespace.forwardRef(
|
|
|
1318
1285
|
if (autoPan) {
|
|
1319
1286
|
rafHandle = requestAnimationFrame(() => {
|
|
1320
1287
|
if (popupRef.current && map) {
|
|
1321
|
-
panToFitPopup(map, popupRef.current, normalizePadding(autoPanPadding));
|
|
1288
|
+
utils.panToFitPopup(map, popupRef.current, utils.normalizePadding(autoPanPadding));
|
|
1322
1289
|
}
|
|
1323
1290
|
});
|
|
1324
1291
|
}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import '@classic-homes/maps-core/styles/marker.css';
|
|
|
10
10
|
import { createPositioningCoordinator, generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, DEFAULT_BASEMAP, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, EDGE_MARGIN, formatCoordinates, getAvailableBasemaps, FREE_BASEMAPS, resolveBasemapThumbnail, createInitialLayerStates, getLayerCategories, searchLayers, groupLayersByCategory, toggleLayerVisibility, setLayerOpacity, getLayerStatesArray, reorderLayers, CATEGORY_META, resolveBasemapStyle, STACK_GAP, getLayerStyleForTheme, resolveLayerSourceUrl } from '@classic-homes/maps-core';
|
|
11
11
|
export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, DEFAULT_BASEMAP, FLOOD_ZONES, FREE_BASEMAPS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, THEME_DARK, THEME_LIGHT, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createHoverExpression, createInitialLayerStates, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getAvailableBasemaps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getLayerCategories, getLayerStyleForTheme, getLayersByCategory, getSelectionStyle, groupLayersByCategory, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, resolveBasemapStyle, resolveLayerSourceUrl, searchLayers, setLayerOpacity, toggleLayerVisibility, validateGeoJSON } from '@classic-homes/maps-core';
|
|
12
12
|
import * as ReactDOM from 'react-dom';
|
|
13
|
+
import { panToFitPopup, normalizePadding } from '@classic-homes/maps-core/utils';
|
|
13
14
|
import { cva } from 'class-variance-authority';
|
|
14
15
|
import '@classic-homes/maps-core/styles/basemap-switcher.css';
|
|
15
16
|
import '@classic-homes/maps-core/styles/layer-manager.css';
|
|
@@ -263,7 +264,7 @@ function useMapTheme(preference = "auto") {
|
|
|
263
264
|
};
|
|
264
265
|
}
|
|
265
266
|
function useReducedMotion() {
|
|
266
|
-
const [
|
|
267
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
|
|
267
268
|
useEffect(() => {
|
|
268
269
|
if (typeof window === "undefined") return;
|
|
269
270
|
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
@@ -276,7 +277,7 @@ function useReducedMotion() {
|
|
|
276
277
|
mediaQuery.removeEventListener("change", handleChange);
|
|
277
278
|
};
|
|
278
279
|
}, []);
|
|
279
|
-
return
|
|
280
|
+
return prefersReducedMotion;
|
|
280
281
|
}
|
|
281
282
|
var MapContext = React26.createContext(null);
|
|
282
283
|
function useMap() {
|
|
@@ -367,7 +368,7 @@ var Map2 = React26.forwardRef(
|
|
|
367
368
|
});
|
|
368
369
|
}
|
|
369
370
|
}, []);
|
|
370
|
-
const
|
|
371
|
+
const prefersReducedMotion = useReducedMotion();
|
|
371
372
|
const { style: themeStyle } = useMapTheme(themePref);
|
|
372
373
|
const onLoadRef = React26.useRef(onLoad);
|
|
373
374
|
onLoadRef.current = onLoad;
|
|
@@ -508,7 +509,7 @@ var Map2 = React26.forwardRef(
|
|
|
508
509
|
if (bounds) {
|
|
509
510
|
map.fitBounds(bounds, {
|
|
510
511
|
padding: boundsPadding,
|
|
511
|
-
animate: animation && !
|
|
512
|
+
animate: animation && !prefersReducedMotion
|
|
512
513
|
});
|
|
513
514
|
}
|
|
514
515
|
onLoadRef.current?.({ type: "load", loaded: true });
|
|
@@ -744,7 +745,7 @@ var Source = ({
|
|
|
744
745
|
console.warn("[maps-react] Source: Invalid bounds calculated, skipping fitBounds");
|
|
745
746
|
return;
|
|
746
747
|
}
|
|
747
|
-
const
|
|
748
|
+
const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
748
749
|
const rafHandle = requestAnimationFrame(() => {
|
|
749
750
|
if (cancelledRef.current || initialFitDone.current) return;
|
|
750
751
|
try {
|
|
@@ -760,7 +761,7 @@ var Source = ({
|
|
|
760
761
|
map.flyTo({
|
|
761
762
|
center: [centerLng, centerLat],
|
|
762
763
|
zoom: Math.max(zoom, 1),
|
|
763
|
-
animate: params.fitBoundsAnimate && !
|
|
764
|
+
animate: params.fitBoundsAnimate && !prefersReducedMotion,
|
|
764
765
|
padding: params.fitBoundsPadding
|
|
765
766
|
});
|
|
766
767
|
initialFitDone.current = true;
|
|
@@ -1163,40 +1164,6 @@ var Marker = React26.forwardRef(
|
|
|
1163
1164
|
}
|
|
1164
1165
|
);
|
|
1165
1166
|
Marker.displayName = "Marker";
|
|
1166
|
-
function normalizePadding(padding) {
|
|
1167
|
-
if (typeof padding === "number") {
|
|
1168
|
-
return { top: padding, right: padding, bottom: padding, left: padding };
|
|
1169
|
-
}
|
|
1170
|
-
return padding;
|
|
1171
|
-
}
|
|
1172
|
-
function prefersReducedMotion() {
|
|
1173
|
-
if (typeof window === "undefined") return false;
|
|
1174
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1175
|
-
}
|
|
1176
|
-
function panToFitPopup(map, popup, padding) {
|
|
1177
|
-
const popupEl = popup.getElement();
|
|
1178
|
-
if (!popupEl) return;
|
|
1179
|
-
const mapContainer = map.getContainer();
|
|
1180
|
-
const mapRect = mapContainer.getBoundingClientRect();
|
|
1181
|
-
const popupRect = popupEl.getBoundingClientRect();
|
|
1182
|
-
let dx = 0;
|
|
1183
|
-
let dy = 0;
|
|
1184
|
-
if (popupRect.left < mapRect.left + padding.left) {
|
|
1185
|
-
dx = popupRect.left - mapRect.left - padding.left;
|
|
1186
|
-
} else if (popupRect.right > mapRect.right - padding.right) {
|
|
1187
|
-
dx = popupRect.right - mapRect.right + padding.right;
|
|
1188
|
-
}
|
|
1189
|
-
if (popupRect.top < mapRect.top + padding.top) {
|
|
1190
|
-
dy = popupRect.top - mapRect.top - padding.top;
|
|
1191
|
-
} else if (popupRect.bottom > mapRect.bottom - padding.bottom) {
|
|
1192
|
-
dy = popupRect.bottom - mapRect.bottom + padding.bottom;
|
|
1193
|
-
}
|
|
1194
|
-
if (dx !== 0 || dy !== 0) {
|
|
1195
|
-
map.panBy([dx, dy], {
|
|
1196
|
-
animate: !prefersReducedMotion()
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
1167
|
var Popup = React26.forwardRef(
|
|
1201
1168
|
({
|
|
1202
1169
|
coordinates,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/maps-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "React MapLibre components for Classic Theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maps",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"require": "./dist/index.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"sideEffects": false,
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|
|
31
32
|
],
|