@burdenoff/microfe-healthybowl 2026.802.1 → 2026.802.2
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/healthybowl/components/FieldMap.js +220 -220
- package/dist/healthybowl/components/FieldMap.js.map +1 -1
- package/dist/healthybowl/components/WeatherMap.js +87 -86
- package/dist/healthybowl/components/WeatherMap.js.map +1 -1
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js +195 -185
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/fields/FieldMapPage.js +723 -723
- package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
- package/dist/healthybowl/pages/satellite/NdviHeatmapMap.js +19 -19
- package/dist/healthybowl/utils/geo.js +4 -1
- package/dist/healthybowl/utils/geo.js.map +1 -1
- package/dist/healthybowl/utils/index.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WeatherMap.js","names":[],"sources":["../../../src/healthybowl/components/WeatherMap.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type FC, type FormEvent } from 'react';\nimport L from 'leaflet';\nimport { LocateFixed, MapPinned, Search, X } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { geocodePlace } from '../utils/geocode';\nimport { useToast } from '../hooks/useToast';\nimport { ToastContainer } from './Toast';\n\ninterface WeatherMapProps {\n /** Resolved place name (from the weather data) used to center the map. */\n location: string;\n /** Backend-resolved farm/weather coordinates. Preferred over client-side geocoding. */\n center?: { lat: number; lng: number } | null;\n}\n\nconst LEAFLET_CSS = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';\n// SRI for leaflet@1.9.4/dist/leaflet.css (immutable versioned URL) — guards against a CDN compromise.\nconst LEAFLET_CSS_SRI = 'sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=';\nconst FARM_WEATHER_ZOOM = 7;\nconst USER_LOCATION_ZOOM = 10;\nconst SEARCH_LOCATION_ZOOM = 10;\n\nconst isUsableCoordinate = (value?: { lat: number; lng: number } | null): value is { lat: number; lng: number } =>\n Boolean(\n value &&\n Number.isFinite(value.lat) &&\n Number.isFinite(value.lng) &&\n value.lat >= -90 &&\n value.lat <= 90 &&\n value.lng >= -180 &&\n value.lng <= 180 &&\n (value.lat !== 0 || value.lng !== 0)\n );\n\n/**\n * Inject Leaflet's stylesheet at runtime. The MFE library build doesn't deliver\n * a component's bundled CSS to the host shell (the host styles come from its own\n * Tailwind), so we load Leaflet's CSS from a CDN instead — consistent with the\n * map being an inherently online feature (tiles + radar).\n */\nfunction ensureLeafletCss(): void {\n if (document.getElementById('leaflet-css')) return;\n const link = document.createElement('link');\n link.id = 'leaflet-css';\n link.rel = 'stylesheet';\n link.href = LEAFLET_CSS;\n link.integrity = LEAFLET_CSS_SRI;\n link.crossOrigin = 'anonymous';\n document.head.appendChild(link);\n}\n\n/**\n * Interactive weather map: OpenStreetMap base + live precipitation radar overlay\n * (RainViewer, keyless), centered on backend-resolved farm coordinates when\n * available, then client-geocoded from the weather location as a fallback.\n */\nexport const WeatherMap: FC<WeatherMapProps> = ({ location, center }) => {\n const { t } = useI18n();\n const { toasts, toast, dismiss } = useToast();\n const containerRef = useRef<HTMLDivElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const farmCenterRef = useRef<L.LatLng | null>(null);\n const userLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const userAccuracyCircleRef = useRef<L.Circle | null>(null);\n const searchedPlaceMarkerRef = useRef<L.CircleMarker | null>(null);\n const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');\n const [hasFarmCenter, setHasFarmCenter] = useState(false);\n const [locating, setLocating] = useState(false);\n const [searchQuery, setSearchQuery] = useState('');\n const [searching, setSearching] = useState(false);\n const [searchedPlace, setSearchedPlace] = useState<string | null>(null);\n const [radarUpdatedAt, setRadarUpdatedAt] = useState<Date | null>(null);\n const streetsLayerLabel = t('healthybowl.weather.map.layers.streets', 'Streets');\n const terrainLayerLabel = t('healthybowl.weather.map.layers.terrain', 'Terrain');\n const radarLayerLabel = t('healthybowl.weather.map.layers.radar', 'Live radar');\n\n // Depend on the primitive coordinates, not the `center` object: the parent\n // re-renders on every weather/radar refresh and hands us a fresh {lat,lng}\n // object with identical values. Keying the map-creation effect on the object\n // reference re-created the whole Leaflet map on each refresh, snapping the view\n // back to the farm and wiping any place the user had searched for.\n const usableCenter = isUsableCoordinate(center) ? center : null;\n const centerLat = usableCenter ? usableCenter.lat : null;\n const centerLng = usableCenter ? usableCenter.lng : null;\n\n const clearUserLocation = useCallback(() => {\n const map = mapRef.current;\n if (userLocationMarkerRef.current && map) map.removeLayer(userLocationMarkerRef.current);\n if (userAccuracyCircleRef.current && map) map.removeLayer(userAccuracyCircleRef.current);\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n }, []);\n\n const removeSearchedPlaceMarker = useCallback(() => {\n const map = mapRef.current;\n if (searchedPlaceMarkerRef.current && map) map.removeLayer(searchedPlaceMarkerRef.current);\n searchedPlaceMarkerRef.current = null;\n }, []);\n\n const clearSearchedPlace = useCallback(() => {\n removeSearchedPlaceMarker();\n setSearchedPlace(null);\n }, [removeSearchedPlaceMarker]);\n\n const focusFarm = useCallback(() => {\n const map = mapRef.current;\n const farmCenter = farmCenterRef.current;\n if (!map || !farmCenter) return;\n map.flyTo(farmCenter, FARM_WEATHER_ZOOM, { duration: 0.6 });\n }, []);\n\n const handleLocateMe = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n if (typeof navigator === 'undefined' || !navigator.geolocation) {\n toast({\n title: t('healthybowl.weather.map.toast.locationUnsupported.title', 'Location unavailable'),\n description: t(\n 'healthybowl.weather.map.toast.locationUnsupported.description',\n 'This browser does not support device location.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n setLocating(true);\n navigator.geolocation.getCurrentPosition(\n (position) => {\n const latlng: L.LatLngExpression = [position.coords.latitude, position.coords.longitude];\n clearUserLocation();\n userAccuracyCircleRef.current = L.circle(latlng, {\n radius: Math.max(10, position.coords.accuracy || 0),\n color: '#2563eb',\n fillColor: '#3b82f6',\n fillOpacity: 0.12,\n opacity: 0.45,\n weight: 1,\n }).addTo(map);\n userLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 7,\n color: '#ffffff',\n weight: 2,\n fillColor: '#2563eb',\n fillOpacity: 1,\n }).addTo(map);\n map.flyTo(latlng, Math.max(map.getZoom(), USER_LOCATION_ZOOM), { duration: 0.75 });\n setLocating(false);\n },\n (error) => {\n const blocked = error.code === error.PERMISSION_DENIED;\n toast({\n title: blocked\n ? t('healthybowl.weather.map.toast.locationBlocked.title', 'Location blocked')\n : t('healthybowl.weather.map.toast.locationFailed.title', 'Could not get location'),\n description: blocked\n ? t(\n 'healthybowl.weather.map.toast.locationBlocked.description',\n 'Allow location access in the browser, then try again.'\n )\n : t(\n 'healthybowl.weather.map.toast.locationFailed.description',\n 'Make sure GPS is enabled and the page is open over HTTPS.'\n ),\n variant: 'warning',\n });\n setLocating(false);\n },\n { enableHighAccuracy: true, timeout: 12000, maximumAge: 60000 }\n );\n }, [clearUserLocation, t, toast]);\n\n const handleSearchPlace = useCallback(\n async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n const map = mapRef.current;\n const place = searchQuery.trim();\n if (!place) {\n toast({\n title: t('healthybowl.weather.map.toast.searchRequired.title', 'Place required'),\n description: t(\n 'healthybowl.weather.map.toast.searchRequired.description',\n 'Enter a city, village, district, or region to view it on the map.'\n ),\n variant: 'warning',\n });\n return;\n }\n if (!map) return;\n\n setSearching(true);\n try {\n const hit = await geocodePlace(place);\n if (!hit) {\n toast({\n title: t('healthybowl.weather.map.toast.searchNotFound.title', 'Place not found'),\n description: t(\n 'healthybowl.weather.map.toast.searchNotFound.description',\n 'Try a more specific location name, such as city and state.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const label = [hit.name, hit.admin1, hit.country].filter(Boolean).join(', ') || place;\n const latlng: L.LatLngExpression = [hit.latitude, hit.longitude];\n removeSearchedPlaceMarker();\n const popupEl = document.createElement('span');\n popupEl.textContent = label;\n searchedPlaceMarkerRef.current = L.circleMarker(latlng, {\n radius: 8,\n color: '#ffffff',\n weight: 2,\n fillColor: '#0ea5e9',\n fillOpacity: 1,\n })\n .addTo(map)\n .bindPopup(popupEl)\n .openPopup();\n map.flyTo(latlng, Math.max(map.getZoom(), SEARCH_LOCATION_ZOOM), { duration: 0.75 });\n setSearchedPlace(label);\n } catch (err) {\n toast({\n title: t('healthybowl.weather.map.toast.searchFailed.title', 'Search failed'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setSearching(false);\n }\n },\n [removeSearchedPlaceMarker, searchQuery, t, toast]\n );\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return undefined;\n ensureLeafletCss();\n const controller = new AbortController();\n let map: L.Map | undefined;\n let cancelled = false;\n setStatus('loading');\n setHasFarmCenter(false);\n setRadarUpdatedAt(null);\n setSearchedPlace(null);\n farmCenterRef.current = null;\n\n void (async () => {\n const backendCenter = centerLat !== null && centerLng !== null ? { lat: centerLat, lng: centerLng } : null;\n const hit = backendCenter ? null : await geocodePlace(location, controller.signal);\n const located: [number, number] | null = backendCenter\n ? [backendCenter.lat, backendCenter.lng]\n : hit\n ? [hit.latitude, hit.longitude]\n : null;\n if (cancelled || !containerRef.current) return;\n const mapCenter: L.LatLngExpression = located ?? [20, 0];\n // z7 keeps the RainViewer radar at its native resolution (it has no tiles past z7)\n // while still framing the farm and its surrounding weather system.\n const zoom = located ? FARM_WEATHER_ZOOM : 2;\n farmCenterRef.current = located ? L.latLng(located[0], located[1]) : null;\n setHasFarmCenter(Boolean(located));\n\n map = L.map(el, { center: mapCenter, zoom, scrollWheelZoom: true });\n mapRef.current = map;\n const streetsLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n attribution: '© OpenStreetMap contributors',\n maxZoom: 18,\n });\n const terrainLayer = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {\n attribution: '© OpenTopoMap (CC-BY-SA) · © OpenStreetMap contributors',\n maxZoom: 17,\n });\n streetsLayer.addTo(map);\n const layerControl = L.control\n .layers(\n {\n [streetsLayerLabel]: streetsLayer,\n [terrainLayerLabel]: terrainLayer,\n },\n undefined,\n { collapsed: false }\n )\n .addTo(map);\n L.control.scale({ imperial: false }).addTo(map);\n\n if (located) {\n const icon = L.divIcon({\n className: 'hb-weather-marker',\n html:\n '<div style=\"width:16px;height:16px;border-radius:50% 50% 50% 0;transform:rotate(-45deg);' +\n 'background:var(--color-action-primary-bg, #16a34a);border:2px solid #fff;box-shadow:0 1px 4px rgba(0,0,0,.4)\"></div>',\n iconSize: [16, 16],\n iconAnchor: [8, 16],\n });\n // bindPopup treats a string as HTML; pass a text node so the place name\n // can never be interpreted as markup (defense-in-depth against a tainted value).\n const popupEl = document.createElement('span');\n popupEl.textContent = location || 'Your farm';\n L.marker(mapCenter, { icon }).addTo(map).bindPopup(popupEl);\n }\n\n // Live precipitation radar overlay (RainViewer — free, keyless).\n try {\n const res = await fetch('https://api.rainviewer.com/public/weather-maps.json', { signal: controller.signal });\n const data = (await res.json()) as {\n host?: string;\n radar?: { past?: Array<{ path?: string; time?: number }> };\n };\n const frames = data.radar?.past ?? [];\n const latest = frames[frames.length - 1];\n // The map may have been removed during the await — guard before touching it.\n if (!cancelled && map && data.host && latest?.path) {\n // RainViewer radar only has tiles up to z7; cap maxNativeZoom so Leaflet\n // upscales from z7 instead of requesting the \"Zoom Level Not Supported\" placeholder.\n const radarLayer = L.tileLayer(`${data.host}${latest.path}/256/{z}/{x}/{y}/4/1_1.png`, {\n opacity: 0.55,\n maxZoom: 18,\n maxNativeZoom: 7,\n }).addTo(map);\n layerControl.addOverlay(radarLayer, radarLayerLabel);\n if (typeof latest.time === 'number') setRadarUpdatedAt(new Date(latest.time * 1000));\n }\n } catch {\n /* radar overlay is best-effort */\n }\n\n if (!cancelled) {\n setStatus('ready');\n window.setTimeout(() => map?.invalidateSize(), 80);\n }\n })().catch(() => {\n if (!cancelled) setStatus('error');\n });\n\n return () => {\n cancelled = true;\n controller.abort();\n clearUserLocation();\n removeSearchedPlaceMarker();\n map?.remove();\n mapRef.current = null;\n farmCenterRef.current = null;\n };\n }, [\n centerLat,\n centerLng,\n clearUserLocation,\n location,\n radarLayerLabel,\n removeSearchedPlaceMarker,\n streetsLayerLabel,\n terrainLayerLabel,\n ]);\n\n return (\n <div className=\"relative\">\n <div className=\"mb-3 flex flex-wrap items-center gap-2\">\n <form onSubmit={handleSearchPlace} className=\"flex min-w-[min(100%,22rem)] flex-1 flex-wrap items-center gap-2\">\n <div className=\"relative min-w-[12rem] flex-1\">\n <Search className=\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-text-secondary\" />\n <input\n type=\"search\"\n value={searchQuery}\n onChange={(event) => setSearchQuery(event.target.value)}\n disabled={status !== 'ready' || searching}\n placeholder={t('healthybowl.weather.map.search.placeholder', 'Search city or place...')}\n aria-label={t('healthybowl.weather.map.search.label', 'Search map by place')}\n className=\"h-9 w-full rounded-md border border-border-subtle bg-bg-surface py-2 pl-9 pr-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-60\"\n />\n </div>\n <Button type=\"submit\" variant=\"outline\" size=\"sm\" disabled={status !== 'ready' || searching}>\n <Search className=\"h-4 w-4\" />{' '}\n {searching\n ? t('healthybowl.weather.map.search.searching', 'Searching...')\n : t('healthybowl.weather.map.search.action', 'Search')}\n </Button>\n {searchedPlace && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={clearSearchedPlace}\n aria-label={t('healthybowl.weather.map.search.clear', 'Clear searched place')}\n title={t('healthybowl.weather.map.search.clear', 'Clear searched place')}\n >\n <X className=\"h-4 w-4\" />\n </Button>\n )}\n </form>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={focusFarm}\n disabled={!hasFarmCenter || status === 'loading'}\n title={t('healthybowl.weather.map.actions.focusFarm.title', 'Focus the weather map on the farm')}\n aria-label={t('healthybowl.weather.map.actions.focusFarm.title', 'Focus the weather map on the farm')}\n >\n <MapPinned className=\"h-4 w-4\" /> {t('healthybowl.weather.map.actions.focusFarm', 'Farm')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={handleLocateMe}\n disabled={locating || status !== 'ready'}\n title={t('healthybowl.weather.map.actions.locateMe.title', 'Go to my current location')}\n aria-label={t('healthybowl.weather.map.actions.locateMe.title', 'Go to my current location')}\n >\n <LocateFixed className=\"h-4 w-4\" />{' '}\n {locating\n ? t('healthybowl.weather.map.actions.locating', 'Locating...')\n : t('healthybowl.weather.map.actions.locateMe', 'My location')}\n </Button>\n </div>\n <div\n ref={containerRef}\n className=\"h-[60vh] max-h-[460px] w-full overflow-hidden rounded-md border border-border-subtle bg-bg-sunken\"\n />\n {status === 'loading' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/60 text-sm text-text-secondary\">\n Loading map…\n </div>\n )}\n {status === 'error' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/80 px-4 text-center text-sm text-text-secondary\">\n Weather map needs an internet connection and couldn’t load.\n </div>\n )}\n {status === 'ready' && !hasFarmCenter && (\n <div className=\"pointer-events-none absolute left-1/2 top-16 z-[400] -translate-x-1/2 rounded-full bg-bg-surface/90 px-3 py-1.5 text-xs text-text-secondary shadow-sm\">\n {t('healthybowl.weather.map.noLocation', 'No farm coordinates available')}\n </div>\n )}\n <p className=\"mt-2 text-xs text-text-secondary\">\n Live precipitation radar via RainViewer · base map © OpenStreetMap\n {location ? ` · centered on ${location}` : ''}\n {searchedPlace ? ` · viewing ${searchedPlace}` : ''}\n {radarUpdatedAt\n ? ` · radar ${radarUpdatedAt.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`\n : ''}\n </p>\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;mCAgBM,IAAc,oDAEd,IAAkB,uDAClB,IAAoB,GACpB,IAAqB,IACrB,IAAuB,IAEvB,KAAsB,MAC1B,GACE,KACA,OAAO,SAAS,EAAM,IAAI,IAC1B,OAAO,SAAS,EAAM,IAAI,IAC1B,EAAM,OAAO,OACb,EAAM,OAAO,MACb,EAAM,OAAO,QACb,EAAM,OAAO,QACZ,EAAM,QAAQ,KAAK,EAAM,QAAQ;AAStC,SAAS,KAAyB;AAChC,KAAI,SAAS,eAAe,cAAc,CAAE;CAC5C,IAAM,IAAO,SAAS,cAAc,OAAO;AAM3C,CALA,EAAK,KAAK,eACV,EAAK,MAAM,cACX,EAAK,OAAO,GACZ,EAAK,YAAY,GACjB,EAAK,cAAc,aACnB,SAAS,KAAK,YAAY,EAAK;;AAQjC,IAAa,KAAmC,EAAE,aAAU,gBAAa;CACvE,IAAM,EAAE,SAAM,GAAS,EACjB,EAAE,WAAQ,UAAO,eAAY,GAAU,EACvC,IAAe,EAAuB,KAAK,EAC3C,IAAS,EAAqB,KAAK,EACnC,IAAgB,EAAwB,KAAK,EAC7C,IAAwB,EAA8B,KAAK,EAC3D,IAAwB,EAAwB,KAAK,EACrD,IAAyB,EAA8B,KAAK,EAC5D,CAAC,GAAQ,KAAa,EAAwC,UAAU,EACxE,CAAC,GAAe,KAAoB,EAAS,GAAM,EACnD,CAAC,GAAU,KAAe,EAAS,GAAM,EACzC,CAAC,GAAa,KAAkB,EAAS,GAAG,EAC5C,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAe,KAAoB,EAAwB,KAAK,EACjE,CAAC,GAAgB,KAAqB,EAAsB,KAAK,EACjE,IAAoB,EAAE,0CAA0C,UAAU,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MACvC,OAAO,EAAE,mDAAmD,oCAAoC;MAChG,cAAY,EAAE,mDAAmD,oCAAoC;gBANvG;OAQE,kBAAC,GAAD,EAAW,WAAU,WAAY,CAAA;;OAAE,EAAE,6CAA6C,OAAO;OAClF;;KACT,kBAAC,GAAD;MACE,SAAQ;MACR,MAAK;MACL,SAAS;MACT,UAAU,KAAY,MAAW;MACjC,OAAO,EAAE,kDAAkD,4BAA4B;MACvF,cAAY,EAAE,kDAAkD,4BAA4B;gBAN9F;OAQE,kBAAC,GAAD,EAAa,WAAU,WAAY,CAAA;OAAC;OACnC,IACG,EAAE,4CAA4C,cAAc,GAC5D,EAAE,4CAA4C,cAAc;OACzD;;KACL;;GACN,kBAAC,OAAD;IACE,KAAK;IACL,WAAU;IACV,CAAA;GACD,MAAW,aACV,kBAAC,OAAD;IAAK,WAAU;cAAgI;IAEzI,CAAA;GAEP,MAAW,WACV,kBAAC,OAAD;IAAK,WAAU;cAAiJ;IAE1J,CAAA;GAEP,MAAW,WAAW,CAAC,KACtB,kBAAC,OAAD;IAAK,WAAU;cACZ,EAAE,sCAAsC,gCAAgC;IACrE,CAAA;GAER,kBAAC,KAAD;IAAG,WAAU;cAAb;KAAgD;KAE7C,IAAW,kBAAkB,MAAa;KAC1C,IAAgB,cAAc,MAAkB;KAChD,IACG,YAAY,EAAe,mBAAmB,EAAE,EAAE;MAAE,MAAM;MAAW,QAAQ;MAAW,CAAC,KACzF;KACF;;GACJ,kBAAC,GAAD;IAAwB;IAAQ,WAAW;IAAW,CAAA;GAClD"}
|
|
1
|
+
{"version":3,"file":"WeatherMap.js","names":[],"sources":["../../../src/healthybowl/components/WeatherMap.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type FC, type FormEvent } from 'react';\nimport { isUsableCoordinate } from '../utils/geo';\nimport L from 'leaflet';\nimport { LocateFixed, MapPinned, Search, X } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { geocodePlace } from '../utils/geocode';\nimport { useToast } from '../hooks/useToast';\nimport { ToastContainer } from './Toast';\n\ninterface WeatherMapProps {\n /** Resolved place name (from the weather data) used to center the map. */\n location: string;\n /** Backend-resolved farm/weather coordinates. Preferred over client-side geocoding. */\n center?: { lat: number; lng: number } | null;\n}\n\nconst LEAFLET_CSS = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';\n// SRI for leaflet@1.9.4/dist/leaflet.css (immutable versioned URL) — guards against a CDN compromise.\nconst LEAFLET_CSS_SRI = 'sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=';\nconst FARM_WEATHER_ZOOM = 7;\nconst USER_LOCATION_ZOOM = 10;\nconst SEARCH_LOCATION_ZOOM = 10;\n\n/**\n * Inject Leaflet's stylesheet at runtime. The MFE library build doesn't deliver\n * a component's bundled CSS to the host shell (the host styles come from its own\n * Tailwind), so we load Leaflet's CSS from a CDN instead — consistent with the\n * map being an inherently online feature (tiles + radar).\n */\nfunction ensureLeafletCss(): void {\n if (document.getElementById('leaflet-css')) return;\n const link = document.createElement('link');\n link.id = 'leaflet-css';\n link.rel = 'stylesheet';\n link.href = LEAFLET_CSS;\n link.integrity = LEAFLET_CSS_SRI;\n link.crossOrigin = 'anonymous';\n document.head.appendChild(link);\n}\n\n/**\n * Interactive weather map: OpenStreetMap base + live precipitation radar overlay\n * (RainViewer, keyless), centered on backend-resolved farm coordinates when\n * available, then client-geocoded from the weather location as a fallback.\n */\nexport const WeatherMap: FC<WeatherMapProps> = ({ location, center }) => {\n const { t } = useI18n();\n const { toasts, toast, dismiss } = useToast();\n const containerRef = useRef<HTMLDivElement>(null);\n const mapRef = useRef<L.Map | null>(null);\n const farmCenterRef = useRef<L.LatLng | null>(null);\n const userLocationMarkerRef = useRef<L.CircleMarker | null>(null);\n const userAccuracyCircleRef = useRef<L.Circle | null>(null);\n const searchedPlaceMarkerRef = useRef<L.CircleMarker | null>(null);\n const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');\n const [hasFarmCenter, setHasFarmCenter] = useState(false);\n const [locating, setLocating] = useState(false);\n const [searchQuery, setSearchQuery] = useState('');\n const [searching, setSearching] = useState(false);\n const [searchedPlace, setSearchedPlace] = useState<string | null>(null);\n const [radarUpdatedAt, setRadarUpdatedAt] = useState<Date | null>(null);\n const streetsLayerLabel = t('healthybowl.weather.map.layers.streets', 'Streets');\n const terrainLayerLabel = t('healthybowl.weather.map.layers.terrain', 'Terrain');\n const radarLayerLabel = t('healthybowl.weather.map.layers.radar', 'Live radar');\n\n // Depend on the primitive coordinates, not the `center` object: the parent\n // re-renders on every weather/radar refresh and hands us a fresh {lat,lng}\n // object with identical values. Keying the map-creation effect on the object\n // reference re-created the whole Leaflet map on each refresh, snapping the view\n // back to the farm and wiping any place the user had searched for.\n const usableCenter = isUsableCoordinate(center) ? center : null;\n const centerLat = usableCenter ? usableCenter.lat : null;\n const centerLng = usableCenter ? usableCenter.lng : null;\n\n const clearUserLocation = useCallback(() => {\n const map = mapRef.current;\n if (userLocationMarkerRef.current && map) map.removeLayer(userLocationMarkerRef.current);\n if (userAccuracyCircleRef.current && map) map.removeLayer(userAccuracyCircleRef.current);\n userLocationMarkerRef.current = null;\n userAccuracyCircleRef.current = null;\n }, []);\n\n const removeSearchedPlaceMarker = useCallback(() => {\n const map = mapRef.current;\n if (searchedPlaceMarkerRef.current && map) map.removeLayer(searchedPlaceMarkerRef.current);\n searchedPlaceMarkerRef.current = null;\n }, []);\n\n const clearSearchedPlace = useCallback(() => {\n removeSearchedPlaceMarker();\n setSearchedPlace(null);\n }, [removeSearchedPlaceMarker]);\n\n const focusFarm = useCallback(() => {\n const map = mapRef.current;\n const farmCenter = farmCenterRef.current;\n if (!map || !farmCenter) return;\n map.flyTo(farmCenter, FARM_WEATHER_ZOOM, { duration: 0.6 });\n }, []);\n\n const handleLocateMe = useCallback(() => {\n const map = mapRef.current;\n if (!map) return;\n if (typeof navigator === 'undefined' || !navigator.geolocation) {\n toast({\n title: t('healthybowl.weather.map.toast.locationUnsupported.title', 'Location unavailable'),\n description: t(\n 'healthybowl.weather.map.toast.locationUnsupported.description',\n 'This browser does not support device location.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n setLocating(true);\n navigator.geolocation.getCurrentPosition(\n (position) => {\n const latlng: L.LatLngExpression = [position.coords.latitude, position.coords.longitude];\n clearUserLocation();\n userAccuracyCircleRef.current = L.circle(latlng, {\n radius: Math.max(10, position.coords.accuracy || 0),\n color: '#2563eb',\n fillColor: '#3b82f6',\n fillOpacity: 0.12,\n opacity: 0.45,\n weight: 1,\n }).addTo(map);\n userLocationMarkerRef.current = L.circleMarker(latlng, {\n radius: 7,\n color: '#ffffff',\n weight: 2,\n fillColor: '#2563eb',\n fillOpacity: 1,\n }).addTo(map);\n map.flyTo(latlng, Math.max(map.getZoom(), USER_LOCATION_ZOOM), { duration: 0.75 });\n setLocating(false);\n },\n (error) => {\n const blocked = error.code === error.PERMISSION_DENIED;\n toast({\n title: blocked\n ? t('healthybowl.weather.map.toast.locationBlocked.title', 'Location blocked')\n : t('healthybowl.weather.map.toast.locationFailed.title', 'Could not get location'),\n description: blocked\n ? t(\n 'healthybowl.weather.map.toast.locationBlocked.description',\n 'Allow location access in the browser, then try again.'\n )\n : t(\n 'healthybowl.weather.map.toast.locationFailed.description',\n 'Make sure GPS is enabled and the page is open over HTTPS.'\n ),\n variant: 'warning',\n });\n setLocating(false);\n },\n { enableHighAccuracy: true, timeout: 12000, maximumAge: 60000 }\n );\n }, [clearUserLocation, t, toast]);\n\n const handleSearchPlace = useCallback(\n async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n const map = mapRef.current;\n const place = searchQuery.trim();\n if (!place) {\n toast({\n title: t('healthybowl.weather.map.toast.searchRequired.title', 'Place required'),\n description: t(\n 'healthybowl.weather.map.toast.searchRequired.description',\n 'Enter a city, village, district, or region to view it on the map.'\n ),\n variant: 'warning',\n });\n return;\n }\n if (!map) return;\n\n setSearching(true);\n try {\n const hit = await geocodePlace(place);\n if (!hit) {\n toast({\n title: t('healthybowl.weather.map.toast.searchNotFound.title', 'Place not found'),\n description: t(\n 'healthybowl.weather.map.toast.searchNotFound.description',\n 'Try a more specific location name, such as city and state.'\n ),\n variant: 'warning',\n });\n return;\n }\n\n const label = [hit.name, hit.admin1, hit.country].filter(Boolean).join(', ') || place;\n const latlng: L.LatLngExpression = [hit.latitude, hit.longitude];\n removeSearchedPlaceMarker();\n const popupEl = document.createElement('span');\n popupEl.textContent = label;\n searchedPlaceMarkerRef.current = L.circleMarker(latlng, {\n radius: 8,\n color: '#ffffff',\n weight: 2,\n fillColor: '#0ea5e9',\n fillOpacity: 1,\n })\n .addTo(map)\n .bindPopup(popupEl)\n .openPopup();\n map.flyTo(latlng, Math.max(map.getZoom(), SEARCH_LOCATION_ZOOM), { duration: 0.75 });\n setSearchedPlace(label);\n } catch (err) {\n toast({\n title: t('healthybowl.weather.map.toast.searchFailed.title', 'Search failed'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setSearching(false);\n }\n },\n [removeSearchedPlaceMarker, searchQuery, t, toast]\n );\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return undefined;\n ensureLeafletCss();\n const controller = new AbortController();\n let map: L.Map | undefined;\n let cancelled = false;\n setStatus('loading');\n setHasFarmCenter(false);\n setRadarUpdatedAt(null);\n setSearchedPlace(null);\n farmCenterRef.current = null;\n\n void (async () => {\n const backendCenter = centerLat !== null && centerLng !== null ? { lat: centerLat, lng: centerLng } : null;\n const hit = backendCenter ? null : await geocodePlace(location, controller.signal);\n const located: [number, number] | null = backendCenter\n ? [backendCenter.lat, backendCenter.lng]\n : hit\n ? [hit.latitude, hit.longitude]\n : null;\n if (cancelled || !containerRef.current) return;\n const mapCenter: L.LatLngExpression = located ?? [20, 0];\n // z7 keeps the RainViewer radar at its native resolution (it has no tiles past z7)\n // while still framing the farm and its surrounding weather system.\n const zoom = located ? FARM_WEATHER_ZOOM : 2;\n farmCenterRef.current = located ? L.latLng(located[0], located[1]) : null;\n setHasFarmCenter(Boolean(located));\n\n map = L.map(el, { center: mapCenter, zoom, scrollWheelZoom: true });\n mapRef.current = map;\n const streetsLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n attribution: '© OpenStreetMap contributors',\n maxZoom: 18,\n });\n const terrainLayer = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {\n attribution: '© OpenTopoMap (CC-BY-SA) · © OpenStreetMap contributors',\n maxZoom: 17,\n });\n streetsLayer.addTo(map);\n const layerControl = L.control\n .layers(\n {\n [streetsLayerLabel]: streetsLayer,\n [terrainLayerLabel]: terrainLayer,\n },\n undefined,\n { collapsed: false }\n )\n .addTo(map);\n L.control.scale({ imperial: false }).addTo(map);\n\n if (located) {\n const icon = L.divIcon({\n className: 'hb-weather-marker',\n html:\n '<div style=\"width:16px;height:16px;border-radius:50% 50% 50% 0;transform:rotate(-45deg);' +\n 'background:var(--color-action-primary-bg, #16a34a);border:2px solid #fff;box-shadow:0 1px 4px rgba(0,0,0,.4)\"></div>',\n iconSize: [16, 16],\n iconAnchor: [8, 16],\n });\n // bindPopup treats a string as HTML; pass a text node so the place name\n // can never be interpreted as markup (defense-in-depth against a tainted value).\n const popupEl = document.createElement('span');\n popupEl.textContent = location || 'Your farm';\n L.marker(mapCenter, { icon }).addTo(map).bindPopup(popupEl);\n }\n\n // Live precipitation radar overlay (RainViewer — free, keyless).\n try {\n const res = await fetch('https://api.rainviewer.com/public/weather-maps.json', { signal: controller.signal });\n const data = (await res.json()) as {\n host?: string;\n radar?: { past?: Array<{ path?: string; time?: number }> };\n };\n const frames = data.radar?.past ?? [];\n const latest = frames[frames.length - 1];\n // The map may have been removed during the await — guard before touching it.\n if (!cancelled && map && data.host && latest?.path) {\n // RainViewer radar only has tiles up to z7; cap maxNativeZoom so Leaflet\n // upscales from z7 instead of requesting the \"Zoom Level Not Supported\" placeholder.\n const radarLayer = L.tileLayer(`${data.host}${latest.path}/256/{z}/{x}/{y}/4/1_1.png`, {\n opacity: 0.55,\n maxZoom: 18,\n maxNativeZoom: 7,\n }).addTo(map);\n layerControl.addOverlay(radarLayer, radarLayerLabel);\n if (typeof latest.time === 'number') setRadarUpdatedAt(new Date(latest.time * 1000));\n }\n } catch {\n /* radar overlay is best-effort */\n }\n\n if (!cancelled) {\n setStatus('ready');\n window.setTimeout(() => map?.invalidateSize(), 80);\n }\n })().catch(() => {\n if (!cancelled) setStatus('error');\n });\n\n return () => {\n cancelled = true;\n controller.abort();\n clearUserLocation();\n removeSearchedPlaceMarker();\n map?.remove();\n mapRef.current = null;\n farmCenterRef.current = null;\n };\n }, [\n centerLat,\n centerLng,\n clearUserLocation,\n location,\n radarLayerLabel,\n removeSearchedPlaceMarker,\n streetsLayerLabel,\n terrainLayerLabel,\n ]);\n\n return (\n <div className=\"relative\">\n <div className=\"mb-3 flex flex-wrap items-center gap-2\">\n <form onSubmit={handleSearchPlace} className=\"flex min-w-[min(100%,22rem)] flex-1 flex-wrap items-center gap-2\">\n <div className=\"relative min-w-[12rem] flex-1\">\n <Search className=\"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-text-secondary\" />\n <input\n type=\"search\"\n value={searchQuery}\n onChange={(event) => setSearchQuery(event.target.value)}\n disabled={status !== 'ready' || searching}\n placeholder={t('healthybowl.weather.map.search.placeholder', 'Search city or place...')}\n aria-label={t('healthybowl.weather.map.search.label', 'Search map by place')}\n className=\"h-9 w-full rounded-md border border-border-subtle bg-bg-surface py-2 pl-9 pr-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)] disabled:cursor-not-allowed disabled:opacity-60\"\n />\n </div>\n <Button type=\"submit\" variant=\"outline\" size=\"sm\" disabled={status !== 'ready' || searching}>\n <Search className=\"h-4 w-4\" />{' '}\n {searching\n ? t('healthybowl.weather.map.search.searching', 'Searching...')\n : t('healthybowl.weather.map.search.action', 'Search')}\n </Button>\n {searchedPlace && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={clearSearchedPlace}\n aria-label={t('healthybowl.weather.map.search.clear', 'Clear searched place')}\n title={t('healthybowl.weather.map.search.clear', 'Clear searched place')}\n >\n <X className=\"h-4 w-4\" />\n </Button>\n )}\n </form>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={focusFarm}\n disabled={!hasFarmCenter || status === 'loading'}\n title={t('healthybowl.weather.map.actions.focusFarm.title', 'Focus the weather map on the farm')}\n aria-label={t('healthybowl.weather.map.actions.focusFarm.title', 'Focus the weather map on the farm')}\n >\n <MapPinned className=\"h-4 w-4\" /> {t('healthybowl.weather.map.actions.focusFarm', 'Farm')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={handleLocateMe}\n disabled={locating || status !== 'ready'}\n title={t('healthybowl.weather.map.actions.locateMe.title', 'Go to my current location')}\n aria-label={t('healthybowl.weather.map.actions.locateMe.title', 'Go to my current location')}\n >\n <LocateFixed className=\"h-4 w-4\" />{' '}\n {locating\n ? t('healthybowl.weather.map.actions.locating', 'Locating...')\n : t('healthybowl.weather.map.actions.locateMe', 'My location')}\n </Button>\n </div>\n <div\n ref={containerRef}\n className=\"h-[60vh] max-h-[460px] w-full overflow-hidden rounded-md border border-border-subtle bg-bg-sunken\"\n />\n {status === 'loading' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/60 text-sm text-text-secondary\">\n Loading map…\n </div>\n )}\n {status === 'error' && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-bg-surface/80 px-4 text-center text-sm text-text-secondary\">\n Weather map needs an internet connection and couldn’t load.\n </div>\n )}\n {status === 'ready' && !hasFarmCenter && (\n <div className=\"pointer-events-none absolute left-1/2 top-16 z-[400] -translate-x-1/2 rounded-full bg-bg-surface/90 px-3 py-1.5 text-xs text-text-secondary shadow-sm\">\n {t('healthybowl.weather.map.noLocation', 'No farm coordinates available')}\n </div>\n )}\n <p className=\"mt-2 text-xs text-text-secondary\">\n Live precipitation radar via RainViewer · base map © OpenStreetMap\n {location ? ` · centered on ${location}` : ''}\n {searchedPlace ? ` · viewing ${searchedPlace}` : ''}\n {radarUpdatedAt\n ? ` · radar ${radarUpdatedAt.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`\n : ''}\n </p>\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;mCAiBM,IAAc,oDAEd,IAAkB,uDAClB,IAAoB,GACpB,IAAqB,IACrB,IAAuB;AAQ7B,SAAS,IAAyB;AAChC,KAAI,SAAS,eAAe,cAAc,CAAE;CAC5C,IAAM,IAAO,SAAS,cAAc,OAAO;AAM3C,CALA,EAAK,KAAK,eACV,EAAK,MAAM,cACX,EAAK,OAAO,GACZ,EAAK,YAAY,GACjB,EAAK,cAAc,aACnB,SAAS,KAAK,YAAY,EAAK;;AAQjC,IAAa,KAAmC,EAAE,aAAU,gBAAa;CACvE,IAAM,EAAE,SAAM,GAAS,EACjB,EAAE,WAAQ,UAAO,gBAAY,GAAU,EACvC,IAAe,EAAuB,KAAK,EAC3C,IAAS,EAAqB,KAAK,EACnC,IAAgB,EAAwB,KAAK,EAC7C,IAAwB,EAA8B,KAAK,EAC3D,IAAwB,EAAwB,KAAK,EACrD,IAAyB,EAA8B,KAAK,EAC5D,CAAC,GAAQ,KAAa,EAAwC,UAAU,EACxE,CAAC,GAAe,KAAoB,EAAS,GAAM,EACnD,CAAC,GAAU,KAAe,EAAS,GAAM,EACzC,CAAC,GAAa,KAAkB,EAAS,GAAG,EAC5C,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAe,KAAoB,EAAwB,KAAK,EACjE,CAAC,GAAgB,KAAqB,EAAsB,KAAK,EACjE,IAAoB,EAAE,0CAA0C,UAAU,EAC1E,IAAoB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