Skip to content

armgit / mapcn

Public Imported from GitHub
0

Beautiful map components. 100% Free, Zero config, one command setup.

TypeScript

update blocks: refactor delivery-tracker, polish markers and colors

anmolbe9376887885
diff --git a/public/r/analytics-map.json b/public/r/analytics-map.json
index 0927458..12baac5 100644
--- a/public/r/analytics-map.json
+++ b/public/r/analytics-map.json
@@ -15,13 +15,13 @@
"files": [
{
"path": "src/registry/blocks/analytics-map/page.tsx",
- "content": "\"use client\";\n\nimport {\n Map,\n MapControls,\n MapGeoJSON,\n MapMarker,\n MarkerContent,\n MarkerTooltip,\n} from \"@/components/ui/map\";\nimport { OverviewCard } from \"./components/overview-card\";\nimport { BreakdownCard } from \"./components/breakdown-card\";\nimport {\n locations,\n visitedPagesRows,\n countriesRows,\n referrersRows,\n browsersRows,\n} from \"./data\";\n\nconst MAP_HEIGHT = \"38rem\";\n\n// Country borders from a public CDN, or swap in your own GeoJSON.\nconst WORLD_GEOJSON =\n \"https://cdn.jsdelivr.net/gh/nvkelso/[email protected]/geojson/ne_110m_admin_0_countries.geojson\";\n\nexport default function Page() {\n return (\n <div\n className=\"bg-background relative min-h-screen\"\n style={{ \"--map-height\": MAP_HEIGHT } as React.CSSProperties}\n >\n <div className=\"bg-card relative h-(--map-height)\">\n <Map\n center={[-2, 16]}\n zoom={1.4}\n scrollZoom={false}\n maxZoom={4}\n minZoom={1.4}\n renderWorldCopies\n blank\n >\n <MapGeoJSON data={WORLD_GEOJSON} linePaint={false} />\n <MapControls className=\"bottom-2\" />\n {locations.map((location) => (\n <MapMarker\n key={location.city}\n longitude={location.lng}\n latitude={location.lat}\n >\n <MarkerContent className=\"group\">\n <div\n className=\"bg-muted-foreground/80 group-hover:bg-muted-foreground/90 rounded-full transition-[transform,background-color] group-hover:scale-110\"\n style={{\n width: location.size * 3,\n height: location.size * 3,\n }}\n />\n </MarkerContent>\n <MarkerTooltip\n offset={20}\n className=\"bg-popover text-popover-foreground border\"\n >\n <p className=\"font-medium\">{location.city}</p>\n <p className=\"text-muted-foreground mt-0.5\">\n {location.size} active users\n </p>\n </MarkerTooltip>\n </MapMarker>\n ))}\n </Map>\n <div\n className=\"via-background/30 to-background pointer-events-none absolute inset-x-0 bottom-0 h-40 bg-linear-to-b from-transparent\"\n aria-hidden\n />\n <OverviewCard />\n </div>\n\n <div className=\"grid gap-4 p-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4\">\n <BreakdownCard title=\"Visited pages\" rows={visitedPagesRows} />\n <BreakdownCard title=\"Referrers\" rows={referrersRows} />\n <BreakdownCard title=\"Countries\" rows={countriesRows} />\n <BreakdownCard title=\"Browsers\" rows={browsersRows} />\n </div>\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport {\n Map,\n MapControls,\n MapGeoJSON,\n MapMarker,\n MarkerContent,\n MarkerTooltip,\n} from \"@/components/ui/map\";\nimport { OverviewCard } from \"./components/overview-card\";\nimport { BreakdownCard } from \"./components/breakdown-card\";\nimport {\n locations,\n visitedPagesRows,\n countriesRows,\n referrersRows,\n browsersRows,\n} from \"./data\";\n\nconst MAP_HEIGHT = \"38rem\";\n\n// Country borders from a public CDN, or swap in your own GeoJSON.\nconst WORLD_GEOJSON =\n \"https://cdn.jsdelivr.net/gh/nvkelso/[email protected]/geojson/ne_110m_admin_0_countries.geojson\";\n\nexport default function Page() {\n return (\n <div\n className=\"bg-background relative min-h-screen\"\n style={{ \"--map-height\": MAP_HEIGHT } as React.CSSProperties}\n >\n <div className=\"bg-card relative h-(--map-height)\">\n <Map\n center={[-2, 16]}\n zoom={1.4}\n maxZoom={4}\n minZoom={1.4}\n scrollZoom={false}\n dragRotate={false}\n pitchWithRotate={false}\n renderWorldCopies\n blank\n >\n <MapGeoJSON data={WORLD_GEOJSON} linePaint={false} />\n <MapControls className=\"bottom-2\" />\n {locations.map((location) => (\n <MapMarker\n key={location.city}\n longitude={location.lng}\n latitude={location.lat}\n >\n <MarkerContent className=\"group\">\n <div\n className=\"bg-chart-2/80 group-hover:bg-chart-2/90 rounded-full transition-[transform,background-color] group-hover:scale-110\"\n style={{\n width: location.size * 3,\n height: location.size * 3,\n }}\n />\n </MarkerContent>\n <MarkerTooltip\n offset={20}\n className=\"bg-popover text-popover-foreground border\"\n >\n <p className=\"font-medium\">{location.city}</p>\n <p className=\"text-muted-foreground mt-0.5\">\n {location.size} active users\n </p>\n </MarkerTooltip>\n </MapMarker>\n ))}\n </Map>\n <div\n className=\"via-background/30 to-background pointer-events-none absolute inset-x-0 bottom-0 h-40 bg-linear-to-b from-transparent\"\n aria-hidden\n />\n <OverviewCard />\n </div>\n\n <div className=\"grid gap-4 p-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4\">\n <BreakdownCard title=\"Visited pages\" rows={visitedPagesRows} />\n <BreakdownCard title=\"Referrers\" rows={referrersRows} />\n <BreakdownCard title=\"Countries\" rows={countriesRows} />\n <BreakdownCard title=\"Browsers\" rows={browsersRows} />\n </div>\n </div>\n );\n}\n",
"type": "registry:page",
"target": "app/analytics/page.tsx"
},
{
"path": "src/registry/blocks/analytics-map/data.ts",
- "content": "import { type ChartConfig } from \"@/components/ui/chart\";\n\nexport interface LocationPoint {\n city: string;\n lng: number;\n lat: number;\n size: number;\n}\n\nexport interface BreakdownRow {\n label: string;\n value: number;\n}\n\nexport const locations: LocationPoint[] = [\n { city: \"San Francisco\", lng: -122.4194, lat: 37.7749, size: 16 },\n { city: \"New York\", lng: -74.006, lat: 40.7128, size: 15 },\n { city: \"Toronto\", lng: -79.3832, lat: 43.6532, size: 11 },\n { city: \"Mexico City\", lng: -99.1332, lat: 19.4326, size: 10 },\n { city: \"Sao Paulo\", lng: -46.6333, lat: -23.5505, size: 12 },\n { city: \"Buenos Aires\", lng: -58.3816, lat: -34.6037, size: 9 },\n { city: \"London\", lng: -0.1276, lat: 51.5074, size: 14 },\n { city: \"Berlin\", lng: 13.405, lat: 52.52, size: 11 },\n { city: \"Paris\", lng: 2.3522, lat: 48.8566, size: 13 },\n { city: \"Madrid\", lng: -3.7038, lat: 40.4168, size: 10 },\n { city: \"Cairo\", lng: 31.2357, lat: 30.0444, size: 9 },\n { city: \"Lagos\", lng: 3.3792, lat: 6.5244, size: 10 },\n { city: \"Mumbai\", lng: 72.8777, lat: 19.076, size: 13 },\n { city: \"Dubai\", lng: 55.2708, lat: 25.2048, size: 11 },\n { city: \"Seoul\", lng: 126.978, lat: 37.5665, size: 12 },\n { city: \"Singapore\", lng: 103.8198, lat: 1.3521, size: 10 },\n { city: \"Tokyo\", lng: 139.6917, lat: 35.6895, size: 12 },\n { city: \"Sydney\", lng: 151.2093, lat: -33.8688, size: 9 },\n { city: \"Auckland\", lng: 174.7633, lat: -36.8485, size: 8 },\n];\n\nexport const usersPerDay = [\n { day: \"1\", users: 420 },\n { day: \"2\", users: 468 },\n { day: \"3\", users: 512 },\n { day: \"4\", users: 390 },\n { day: \"5\", users: 540 },\n { day: \"6\", users: 305 },\n { day: \"7\", users: 268 },\n { day: \"8\", users: 498 },\n { day: \"9\", users: 610 },\n { day: \"10\", users: 472 },\n { day: \"11\", users: 845 },\n { day: \"12\", users: 690 },\n { day: \"13\", users: 360 },\n { day: \"14\", users: 322 },\n { day: \"15\", users: 588 },\n { day: \"16\", users: 654 },\n { day: \"17\", users: 720 },\n { day: \"18\", users: 505 },\n { day: \"19\", users: 932 },\n { day: \"20\", users: 410 },\n { day: \"21\", users: 372 },\n { day: \"22\", users: 640 },\n { day: \"23\", users: 712 },\n { day: \"24\", users: 598 },\n { day: \"25\", users: 1040 },\n { day: \"26\", users: 805 },\n { day: \"27\", users: 445 },\n { day: \"28\", users: 398 },\n { day: \"29\", users: 702 },\n { day: \"30\", users: 868 },\n];\n\nexport const usersPerDayChartConfig = {\n users: {\n label: \"Users\",\n color: \"var(--color-neutral-500)\",\n },\n} satisfies ChartConfig;\n\nexport const deviceCategoryData = [\n { name: \"Desktop\", value: 73.3, fill: \"var(--color-neutral-500)\" },\n { name: \"Mobile\", value: 25.0, fill: \"var(--color-neutral-400)\" },\n { name: \"Tablet\", value: 1.7, fill: \"var(--color-neutral-300)\" },\n];\n\nexport const deviceCategoryChartConfig = {\n desktop: { label: \"Desktop\", color: \"var(--color-neutral-500)\" },\n mobile: { label: \"Mobile\", color: \"var(--color-neutral-400)\" },\n tablet: { label: \"Tablet\", color: \"var(--color-neutral-300)\" },\n} satisfies ChartConfig;\n\nexport const visitedPagesRows: BreakdownRow[] = [\n { label: \"Home\", value: 31 },\n { label: \"Pricing\", value: 23 },\n { label: \"Docs / Basic Map\", value: 18 },\n { label: \"Installation\", value: 12 },\n { label: \"Components\", value: 9 },\n { label: \"Blog\", value: 6 },\n];\n\nexport const countriesRows: BreakdownRow[] = [\n { label: \"United States\", value: 27 },\n { label: \"India\", value: 14 },\n { label: \"United Kingdom\", value: 8 },\n { label: \"Germany\", value: 6 },\n { label: \"Japan\", value: 4 },\n { label: \"Australia\", value: 2 },\n];\n\nexport const referrersRows: BreakdownRow[] = [\n { label: \"google\", value: 38 },\n { label: \"direct\", value: 26 },\n { label: \"github.com\", value: 19 },\n { label: \"x.com\", value: 11 },\n { label: \"ui.shadcn.com\", value: 8 },\n { label: \"other\", value: 5 },\n];\n\nexport const browsersRows: BreakdownRow[] = [\n { label: \"Chrome\", value: 52 },\n { label: \"Safari\", value: 21 },\n { label: \"Firefox\", value: 14 },\n { label: \"Edge\", value: 8 },\n { label: \"Other\", value: 5 },\n];\n",
+ "content": "import { type ChartConfig } from \"@/components/ui/chart\";\n\nexport interface LocationPoint {\n city: string;\n lng: number;\n lat: number;\n size: number;\n}\n\nexport interface BreakdownRow {\n label: string;\n value: number;\n}\n\nexport const locations: LocationPoint[] = [\n { city: \"San Francisco\", lng: -122.4194, lat: 37.7749, size: 16 },\n { city: \"New York\", lng: -74.006, lat: 40.7128, size: 15 },\n { city: \"Toronto\", lng: -79.3832, lat: 43.6532, size: 11 },\n { city: \"Mexico City\", lng: -99.1332, lat: 19.4326, size: 10 },\n { city: \"Sao Paulo\", lng: -46.6333, lat: -23.5505, size: 12 },\n { city: \"Buenos Aires\", lng: -58.3816, lat: -34.6037, size: 9 },\n { city: \"London\", lng: -0.1276, lat: 51.5074, size: 14 },\n { city: \"Berlin\", lng: 13.405, lat: 52.52, size: 11 },\n { city: \"Paris\", lng: 2.3522, lat: 48.8566, size: 13 },\n { city: \"Madrid\", lng: -3.7038, lat: 40.4168, size: 10 },\n { city: \"Cairo\", lng: 31.2357, lat: 30.0444, size: 9 },\n { city: \"Lagos\", lng: 3.3792, lat: 6.5244, size: 10 },\n { city: \"Mumbai\", lng: 72.8777, lat: 19.076, size: 13 },\n { city: \"Dubai\", lng: 55.2708, lat: 25.2048, size: 11 },\n { city: \"Seoul\", lng: 126.978, lat: 37.5665, size: 12 },\n { city: \"Singapore\", lng: 103.8198, lat: 1.3521, size: 10 },\n { city: \"Tokyo\", lng: 139.6917, lat: 35.6895, size: 12 },\n { city: \"Sydney\", lng: 151.2093, lat: -33.8688, size: 9 },\n { city: \"Auckland\", lng: 174.7633, lat: -36.8485, size: 8 },\n];\n\nexport const usersPerDay = [\n { day: \"1\", users: 420 },\n { day: \"2\", users: 468 },\n { day: \"3\", users: 512 },\n { day: \"4\", users: 390 },\n { day: \"5\", users: 540 },\n { day: \"6\", users: 305 },\n { day: \"7\", users: 268 },\n { day: \"8\", users: 498 },\n { day: \"9\", users: 610 },\n { day: \"10\", users: 472 },\n { day: \"11\", users: 845 },\n { day: \"12\", users: 690 },\n { day: \"13\", users: 360 },\n { day: \"14\", users: 322 },\n { day: \"15\", users: 588 },\n { day: \"16\", users: 654 },\n { day: \"17\", users: 720 },\n { day: \"18\", users: 505 },\n { day: \"19\", users: 932 },\n { day: \"20\", users: 410 },\n { day: \"21\", users: 372 },\n { day: \"22\", users: 640 },\n { day: \"23\", users: 712 },\n { day: \"24\", users: 598 },\n { day: \"25\", users: 1040 },\n { day: \"26\", users: 805 },\n { day: \"27\", users: 445 },\n { day: \"28\", users: 398 },\n { day: \"29\", users: 702 },\n { day: \"30\", users: 868 },\n];\n\nexport const usersPerDayChartConfig = {\n users: {\n label: \"Users\",\n color: \"var(--chart-2)\",\n },\n} satisfies ChartConfig;\n\nexport const deviceCategoryData = [\n { name: \"Desktop\", value: 73.3, fill: \"var(--chart-1)\" },\n { name: \"Mobile\", value: 25.0, fill: \"var(--chart-2)\" },\n { name: \"Tablet\", value: 1.7, fill: \"var(--chart-3)\" },\n];\n\nexport const deviceCategoryChartConfig = {\n desktop: { label: \"Desktop\", color: \"var(--chart-1)\" },\n mobile: { label: \"Mobile\", color: \"var(--chart-2)\" },\n tablet: { label: \"Tablet\", color: \"var(--chart-3)\" },\n} satisfies ChartConfig;\n\nexport const visitedPagesRows: BreakdownRow[] = [\n { label: \"Home\", value: 31 },\n { label: \"Pricing\", value: 23 },\n { label: \"Docs / Basic Map\", value: 18 },\n { label: \"Installation\", value: 12 },\n { label: \"Components\", value: 9 },\n { label: \"Blog\", value: 6 },\n];\n\nexport const countriesRows: BreakdownRow[] = [\n { label: \"United States\", value: 27 },\n { label: \"India\", value: 14 },\n { label: \"United Kingdom\", value: 8 },\n { label: \"Germany\", value: 6 },\n { label: \"Japan\", value: 4 },\n { label: \"Australia\", value: 2 },\n];\n\nexport const referrersRows: BreakdownRow[] = [\n { label: \"google\", value: 38 },\n { label: \"direct\", value: 26 },\n { label: \"github.com\", value: 19 },\n { label: \"x.com\", value: 11 },\n { label: \"ui.shadcn.com\", value: 8 },\n { label: \"other\", value: 5 },\n];\n\nexport const browsersRows: BreakdownRow[] = [\n { label: \"Chrome\", value: 52 },\n { label: \"Safari\", value: 21 },\n { label: \"Firefox\", value: 14 },\n { label: \"Edge\", value: 8 },\n { label: \"Other\", value: 5 },\n];\n",
"type": "registry:component",
"target": "app/analytics/data.ts"
},
@@ -33,7 +33,7 @@
},
{
"path": "src/registry/blocks/analytics-map/components/breakdown-card.tsx",
- "content": "\"use client\";\n\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { type BreakdownRow } from \"../data\";\n\ninterface BreakdownCardProps {\n title: string;\n rows: BreakdownRow[];\n}\n\nexport function BreakdownCard({ title, rows }: BreakdownCardProps) {\n const maxRowValue =\n rows.length > 0 ? Math.max(...rows.map((row) => row.value)) : 0;\n\n return (\n <Card className=\"gap-2\">\n <CardHeader>\n <CardTitle className=\"text-sm font-medium\">{title}</CardTitle>\n </CardHeader>\n\n <CardContent>\n <div className=\"text-muted-foreground mb-2 flex items-center justify-between text-[11px] tracking-wider uppercase\">\n <span>{title}</span>\n <span>Visitors</span>\n </div>\n <div className=\"space-y-1.5\">\n {rows.map((row) => {\n const pct = maxRowValue ? (row.value / maxRowValue) * 100 : 0;\n return (\n <div\n key={row.label}\n className=\"relative flex items-center justify-between overflow-hidden rounded-md px-2 py-1.5 text-xs\"\n >\n <div\n className=\"bg-muted-foreground/20 absolute inset-y-0 left-0 rounded-md\"\n style={{ width: `${pct}%` }}\n aria-hidden\n />\n <span className=\"text-foreground/90 relative truncate pr-2\">\n {row.label}\n </span>\n <span className=\"text-foreground relative font-medium tabular-nums\">\n {row.value.toLocaleString()}\n </span>\n </div>\n );\n })}\n </div>\n </CardContent>\n </Card>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport { type BreakdownRow } from \"../data\";\n\ninterface BreakdownCardProps {\n title: string;\n rows: BreakdownRow[];\n}\n\nexport function BreakdownCard({ title, rows }: BreakdownCardProps) {\n const maxRowValue =\n rows.length > 0 ? Math.max(...rows.map((row) => row.value)) : 0;\n\n return (\n <Card className=\"gap-2\">\n <CardHeader>\n <CardTitle className=\"text-sm font-medium\">{title}</CardTitle>\n </CardHeader>\n\n <CardContent>\n <div className=\"text-muted-foreground mb-2 flex items-center justify-between text-[11px] tracking-wider uppercase\">\n <span>{title}</span>\n <span>Visitors</span>\n </div>\n <div className=\"space-y-1.5\">\n {rows.map((row) => {\n const pct = maxRowValue ? (row.value / maxRowValue) * 100 : 0;\n return (\n <div\n key={row.label}\n className=\"relative flex items-center justify-between overflow-hidden rounded-md px-2 py-1.5 text-xs\"\n >\n <div\n className=\"bg-chart-2/20 absolute inset-y-0 left-0 rounded-md\"\n style={{ width: `${pct}%` }}\n aria-hidden\n />\n <span className=\"text-foreground/90 relative truncate pr-2\">\n {row.label}\n </span>\n <span className=\"text-foreground relative font-medium tabular-nums\">\n {row.value.toLocaleString()}\n </span>\n </div>\n );\n })}\n </div>\n </CardContent>\n </Card>\n );\n}\n",
"type": "registry:component",
"target": "app/analytics/components/breakdown-card.tsx"
}
diff --git a/public/r/choropleth.json b/public/r/choropleth.json
index 9afc36a..fe87315 100644
--- a/public/r/choropleth.json
+++ b/public/r/choropleth.json
@@ -13,13 +13,13 @@
"files": [
{
"path": "src/registry/blocks/choropleth/page.tsx",
- "content": "\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { useTheme } from \"next-themes\";\n\nimport { Map, MapControls, MapGeoJSON, MapPopup } from \"@/components/ui/map\";\nimport { useWorldData } from \"@/lib/use-world-data\";\nimport { mapConfig, visitorsByCountry, type Theme } from \"./data\";\n\n// WebGL paint can't read CSS variables, so we build a concrete value→color\n// expression per theme. The hovered country is highlighted in place via the\n// `hover` feature-state, restricted to countries that actually have data.\nfunction buildFillColor(theme: Theme): unknown[] {\n const { base, ramp, hover } = mapConfig.colors[theme];\n const [s0, s1, s2, s3, s4] = mapConfig.scaleStops;\n const ramped = [\n \"interpolate\",\n [\"linear\"],\n [\"coalesce\", [\"get\", \"visitors\"], 0],\n s0,\n base,\n s1,\n ramp[0],\n s2,\n ramp[1],\n s3,\n ramp[2],\n s4,\n ramp[3],\n ];\n return [\n \"case\",\n [\n \"all\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n [\">\", [\"coalesce\", [\"get\", \"visitors\"], 0], 0],\n ],\n hover,\n ramped,\n ];\n}\n\ninterface HoverInfo {\n name: string;\n visitors: number;\n lng: number;\n lat: number;\n}\n\ninterface CountryProperties {\n NAME_LONG: string;\n visitors: number;\n}\n\ntype CountryFeatureCollection = GeoJSON.FeatureCollection<\n GeoJSON.Geometry,\n CountryProperties\n>;\n\nfunction Legend({ theme }: { theme: Theme }) {\n const gradient = `linear-gradient(to right, ${mapConfig.colors[theme].ramp.join(\", \")})`;\n\n return (\n <div className=\"bg-card/90 absolute bottom-4 left-4 z-10 rounded-lg border px-3 py-2.5 backdrop-blur-sm\">\n <p className=\"text-foreground text-xs font-medium\">Visitors by country</p>\n <div\n className=\"mt-2 h-2 w-40 rounded-full\"\n style={{ backgroundImage: gradient }}\n suppressHydrationWarning\n />\n <div className=\"text-muted-foreground flex items-center justify-between pt-1.5 text-[10px]\">\n <span>Low</span>\n <span>High</span>\n </div>\n </div>\n );\n}\n\nexport default function Page() {\n const { resolvedTheme } = useTheme();\n const theme: Theme = resolvedTheme === \"dark\" ? \"dark\" : \"light\";\n const [hover, setHover] = useState<HoverInfo | null>(null);\n const world = useWorldData();\n\n const countries = useMemo<CountryFeatureCollection | null>(() => {\n if (!world) return null;\n return {\n type: \"FeatureCollection\",\n features: world.features.map((f) => ({\n ...f,\n properties: {\n NAME_LONG: f.properties.NAME_LONG,\n visitors: visitorsByCountry[f.properties.NAME_LONG] ?? 0,\n },\n })),\n };\n }, [world]);\n\n // Recompute paint only when the theme changes; MapGeoJSON recolors in place.\n const fillPaint = useMemo(\n () => ({\n \"fill-color\": buildFillColor(theme) as never,\n \"fill-opacity\": 0.92,\n }),\n [theme],\n );\n return (\n <div className=\"bg-card relative h-screen overflow-hidden\">\n <Map\n blank\n center={mapConfig.view.center}\n zoom={mapConfig.view.zoom}\n minZoom={mapConfig.view.minZoom}\n maxZoom={mapConfig.view.maxZoom}\n dragRotate={false}\n pitchWithRotate={false}\n loading={!countries}\n >\n {countries && (\n <MapGeoJSON<CountryProperties>\n data={countries}\n promoteId=\"NAME_LONG\"\n fillPaint={fillPaint}\n interactive\n onHover={(e) => {\n const visitors = e?.feature.properties.visitors ?? 0;\n // Only countries with data are interactive.\n if (!e || visitors <= 0) {\n setHover(null);\n return;\n }\n setHover({\n name: e.feature.properties.NAME_LONG,\n visitors,\n lng: e.longitude,\n lat: e.latitude,\n });\n }}\n />\n )}\n <MapControls className=\"bottom-2\" />\n {hover && (\n <MapPopup\n longitude={hover.lng}\n latitude={hover.lat}\n offset={12}\n closeOnClick={false}\n className=\"pointer-events-none p-2\"\n >\n <p className=\"text-xs font-medium\">{hover.name}</p>\n <div className=\"flex items-center justify-between gap-4 pt-1\">\n <span className=\"text-muted-foreground flex items-center gap-1.5 text-[11px]\">\n <span\n className=\"size-2 rounded-full\"\n style={{ backgroundColor: mapConfig.colors[theme].hover }}\n />\n Visitors\n </span>\n <span className=\"text-foreground text-xs font-semibold tabular-nums\">\n {hover.visitors.toLocaleString()}\n </span>\n </div>\n </MapPopup>\n )}\n </Map>\n\n <Legend theme={theme} />\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { useTheme } from \"next-themes\";\n\nimport { Map, MapControls, MapGeoJSON, MapPopup } from \"@/components/ui/map\";\nimport { useWorldData } from \"@/lib/use-world-data\";\nimport { mapConfig, visitorsByCountry, type Theme } from \"./data\";\n\n// WebGL paint can't read CSS variables, so we build a concrete value→color\n// expression per theme. The hovered country is highlighted in place via the\n// `hover` feature-state, restricted to countries that actually have data.\nfunction buildFillColor(theme: Theme): unknown[] {\n const { base, ramp, hover } = mapConfig.colors[theme];\n const [s0, s1, s2, s3, s4] = mapConfig.scaleStops;\n const ramped = [\n \"interpolate\",\n [\"linear\"],\n [\"coalesce\", [\"get\", \"visitors\"], 0],\n s0,\n base,\n s1,\n ramp[0],\n s2,\n ramp[1],\n s3,\n ramp[2],\n s4,\n ramp[3],\n ];\n return [\n \"case\",\n [\n \"all\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n [\">\", [\"coalesce\", [\"get\", \"visitors\"], 0], 0],\n ],\n hover,\n ramped,\n ];\n}\n\ninterface HoverInfo {\n name: string;\n visitors: number;\n lng: number;\n lat: number;\n}\n\ninterface CountryProperties {\n NAME_LONG: string;\n visitors: number;\n}\n\ntype CountryFeatureCollection = GeoJSON.FeatureCollection<\n GeoJSON.Geometry,\n CountryProperties\n>;\n\nfunction Legend({ theme }: { theme: Theme }) {\n const gradient = `linear-gradient(to right, ${mapConfig.colors[theme].ramp.join(\", \")})`;\n\n return (\n <div className=\"bg-card/90 absolute bottom-4 left-4 z-10 rounded-lg border px-3 py-2.5 backdrop-blur-sm\">\n <p className=\"text-foreground text-xs font-medium\">Visitors by country</p>\n <div\n className=\"mt-2 h-2 w-40 rounded-full\"\n style={{ backgroundImage: gradient }}\n suppressHydrationWarning\n />\n <div className=\"text-muted-foreground flex items-center justify-between pt-1.5 text-[10px]\">\n <span>Low</span>\n <span>High</span>\n </div>\n </div>\n );\n}\n\nexport default function Page() {\n const { resolvedTheme } = useTheme();\n const theme: Theme = resolvedTheme === \"dark\" ? \"dark\" : \"light\";\n const [hover, setHover] = useState<HoverInfo | null>(null);\n const world = useWorldData();\n\n const countries = useMemo<CountryFeatureCollection | null>(() => {\n if (!world) return null;\n return {\n type: \"FeatureCollection\",\n features: world.features.map((f) => ({\n ...f,\n properties: {\n NAME_LONG: f.properties.NAME_LONG,\n visitors: visitorsByCountry[f.properties.NAME_LONG] ?? 0,\n },\n })),\n };\n }, [world]);\n\n // Recompute paint only when the theme changes; MapGeoJSON recolors in place.\n const fillPaint = useMemo(\n () => ({\n \"fill-color\": buildFillColor(theme) as never,\n \"fill-opacity\": 0.92,\n }),\n [theme],\n );\n return (\n <div className=\"bg-card relative h-screen overflow-hidden\">\n <Map\n blank\n center={mapConfig.view.center}\n zoom={mapConfig.view.zoom}\n minZoom={mapConfig.view.minZoom}\n maxZoom={mapConfig.view.maxZoom}\n scrollZoom={false}\n dragRotate={false}\n pitchWithRotate={false}\n loading={!countries}\n >\n {countries && (\n <MapGeoJSON<CountryProperties>\n data={countries}\n promoteId=\"NAME_LONG\"\n fillPaint={fillPaint}\n interactive\n onHover={(e) => {\n const visitors = e?.feature.properties.visitors ?? 0;\n // Only countries with data are interactive.\n if (!e || visitors <= 0) {\n setHover(null);\n return;\n }\n setHover({\n name: e.feature.properties.NAME_LONG,\n visitors,\n lng: e.longitude,\n lat: e.latitude,\n });\n }}\n />\n )}\n <MapControls className=\"bottom-2\" />\n {hover && (\n <MapPopup\n longitude={hover.lng}\n latitude={hover.lat}\n offset={12}\n closeOnClick={false}\n className=\"pointer-events-none p-2\"\n >\n <p className=\"text-xs font-medium\">{hover.name}</p>\n <div className=\"flex items-center justify-between gap-4 pt-1\">\n <span className=\"text-muted-foreground flex items-center gap-1.5 text-[11px]\">\n <span\n className=\"size-2 rounded-full\"\n style={{ backgroundColor: mapConfig.colors[theme].hover }}\n />\n Visitors\n </span>\n <span className=\"text-foreground text-xs font-semibold tabular-nums\">\n {hover.visitors.toLocaleString()}\n </span>\n </div>\n </MapPopup>\n )}\n </Map>\n\n <Legend theme={theme} />\n </div>\n );\n}\n",
"type": "registry:page",
"target": "app/choropleth/page.tsx"
},
{
"path": "src/registry/blocks/choropleth/data.ts",
- "content": "/** Visitor counts keyed by the feature `NAME_LONG`. */\nexport const visitorsByCountry: Record<string, number> = {\n // High\n Germany: 15,\n \"United States\": 14,\n China: 10,\n \"United Kingdom\": 12,\n India: 12,\n Japan: 12,\n Canada: 10,\n // Mid\n France: 9,\n Brazil: 9,\n Netherlands: 8,\n \"Russian Federation\": 8,\n Australia: 7,\n Indonesia: 7,\n Italy: 6,\n Sweden: 6,\n \"South Africa\": 6,\n Mexico: 5,\n // Low\n Poland: 4,\n Argentina: 4,\n Spain: 3,\n Egypt: 3,\n Greece: 2,\n};\n\nexport const MAX_VISITORS = 15;\n\nexport type Theme = \"light\" | \"dark\";\n\n/** Resolved colors for the choropleth, per theme. */\ninterface ChoroplethColors {\n /** Fill for countries with no data (value 0). */\n base: string;\n /** Sequential fill ramp from low → high, mapped to `scaleStops`. */\n ramp: [string, string, string, string];\n /** Fill for the hovered country. */\n hover: string;\n}\n\n/**\n * Central map config — colors, the value→color scale, and the initial view.\n * WebGL paint can't read CSS variables, so colors are concrete values per\n * theme. The ramp is a single-hue grayscale scale tuned for contrast on each\n * theme's basemap.\n */\nexport const mapConfig = {\n view: {\n center: [12, 28] as [number, number],\n zoom: 1.4,\n minZoom: 1,\n maxZoom: 4,\n },\n scaleStops: [0, 1, 5, 10, MAX_VISITORS] as const,\n colors: {\n light: {\n base: \"#eef0f3\",\n ramp: [\"#d4d4d4\", \"#9e9e9e\", \"#6b6b6b\", \"#3d3d3d\"],\n hover: \"#0a0a0a\",\n },\n dark: {\n base: \"#2a2a2a\",\n ramp: [\"#3d3d3d\", \"#6b6b6b\", \"#9e9e9e\", \"#d4d4d4\"],\n hover: \"#ffffff\",\n },\n } satisfies Record<Theme, ChoroplethColors>,\n};\n",
+ "content": "/** Visitor counts keyed by the feature `NAME_LONG`. */\nexport const visitorsByCountry: Record<string, number> = {\n \"United States\": 100,\n Canada: 70,\n Brazil: 65,\n \"United Kingdom\": 95,\n Germany: 80,\n France: 55,\n India: 90,\n China: 45,\n Japan: 35,\n Australia: 25,\n \"South Africa\": 20,\n Egypt: 15,\n};\nexport type Theme = \"light\" | \"dark\";\n\n/** Resolved colors for the choropleth, per theme. */\ninterface ChoroplethColors {\n /** Fill for countries with no data (value 0). */\n base: string;\n /** Sequential fill ramp from low → high, mapped to `scaleStops`. */\n ramp: [string, string, string, string];\n /** Fill for the hovered country. */\n hover: string;\n}\n\n/**\n * Central map config — colors, the value→color scale, and the initial view.\n * WebGL paint can't read CSS variables, so colors are concrete values per\n * theme. The no-data fill stays muted, while the ramp uses hex equivalents of\n * the grayscale chart tokens from globals.css. Values move toward darker chart\n * colors in light mode and toward chart-1 in dark mode.\n */\nexport const mapConfig = {\n view: {\n center: [12, 28] as [number, number],\n zoom: 1.4,\n minZoom: 1,\n maxZoom: 4,\n },\n scaleStops: [0, 25, 50, 75, 100] as const,\n colors: {\n light: {\n base: \"#f0f0f0\",\n ramp: [\"#d4d4d4\", \"#a3a3a3\", \"#737373\", \"#404040\"],\n hover: \"#0a0a0a\",\n },\n dark: {\n base: \"#2a2a2a\",\n ramp: [\"#404040\", \"#737373\", \"#a3a3a3\", \"#d4d4d4\"],\n hover: \"#ffffff\",\n },\n } satisfies Record<Theme, ChoroplethColors>,\n};\n",
"type": "registry:component",
"target": "app/choropleth/data.ts"
},
diff --git a/public/r/delivery-tracker.json b/public/r/delivery-tracker.json
index 4f651e5..9c939b8 100644
--- a/public/r/delivery-tracker.json
+++ b/public/r/delivery-tracker.json
@@ -15,13 +15,19 @@
"files": [
{
"path": "src/registry/blocks/delivery-tracker/page.tsx",
- "content": "\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useTheme } from \"next-themes\";\nimport { Clock3, Utensils, Truck, UserRound } from \"lucide-react\";\n\nimport {\n Map,\n MapMarker,\n MapRoute,\n MarkerContent,\n MarkerTooltip,\n} from \"@/components/ui/map\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface DeliveryMeal {\n name: string;\n price: string;\n quantity: number;\n}\n\ninterface OsrmRouteData {\n coordinates: [number, number][];\n duration: number;\n distance: number;\n}\n\nconst deliveryMeals: DeliveryMeal[] = [\n {\n name: \"Spicy Tofu Grain Bowl\",\n price: \"$44.00\",\n quantity: 1,\n },\n {\n name: \"Herb Chicken Rice Box\",\n price: \"$58.00\",\n quantity: 2,\n },\n {\n name: \"Roasted Veggie Wrap\",\n price: \"$29.00\",\n quantity: 1,\n },\n];\n\nconst pickup = { lng: -122.4185, lat: 37.7645 };\nconst dropoff = { lng: -122.434, lat: 37.7475 };\n\nfunction formatDistance(meters?: number) {\n if (!meters) return \"--\";\n if (meters < 1000) return `${Math.round(meters)} m`;\n return `${(meters / 1000).toFixed(1)} km`;\n}\n\nfunction formatDuration(seconds?: number) {\n if (!seconds) return \"--\";\n const minutes = Math.round(seconds / 60);\n if (minutes < 60) return `${minutes} min`;\n const hours = Math.floor(minutes / 60);\n const remainingMinutes = minutes % 60;\n return `${hours}h ${remainingMinutes}m`;\n}\n\nexport default function Page() {\n const [routeData, setRouteData] = useState<OsrmRouteData | null>(null);\n const [loading, setLoading] = useState(true);\n const { resolvedTheme } = useTheme();\n const remainingRouteColor = resolvedTheme === \"dark\" ? \"#9ca3af\" : \"#6b7280\";\n\n useEffect(() => {\n async function fetchRoute() {\n setLoading(true);\n try {\n const response = await fetch(\n `https://router.project-osrm.org/route/v1/driving/${pickup.lng},${pickup.lat};${dropoff.lng},${dropoff.lat}?overview=full&geometries=geojson`,\n );\n const data = await response.json();\n const route = data?.routes?.[0];\n if (!route?.geometry?.coordinates) return;\n\n setRouteData({\n coordinates: route.geometry.coordinates as [number, number][],\n duration: route.duration as number,\n distance: route.distance as number,\n });\n } catch (error) {\n console.error(\"Failed to fetch route:\", error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchRoute();\n }, []);\n\n const progressCoordinates = useMemo(() => {\n const progressCount = Math.max(\n 2,\n Math.floor(\n (routeData?.coordinates?.length ?? 0) * (routeData ? 0.62 : 0.66),\n ),\n );\n return routeData?.coordinates?.slice(0, progressCount) ?? [];\n }, [routeData]);\n\n const courierPosition = progressCoordinates[progressCoordinates.length - 1];\n\n return (\n <div className=\"p-8\">\n <div className=\"bg-sidebar mx-auto grid max-w-7xl rounded-xl border md:h-[600px] md:grid-cols-[1.05fr_1fr]\">\n <div className=\"flex flex-col p-5 md:p-6\">\n <div className=\"space-y-1\">\n <h3 className=\"text-2xl font-semibold tracking-tight\">\n Track Delivery\n </h3>\n <p className=\"text-muted-foreground text-sm\">Mon Feb 10 - 2-3 PM</p>\n </div>\n\n <Card className=\"mt-5\">\n <CardHeader>\n <CardTitle className=\"font-medium\">\n Order items ({deliveryMeals.length})\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-5\">\n {deliveryMeals.map((meal) => (\n <div key={meal.name} className=\"flex items-center gap-3\">\n <div className=\"bg-muted grid size-8 place-items-center rounded-full text-xs font-medium\">\n <Utensils className=\"text-muted-foreground size-4\" />\n </div>\n <div className=\"min-w-4 flex-1\">\n <p className=\"truncate pb-1 text-sm font-medium\">\n {meal.name}\n </p>\n <p className=\"text-muted-foreground text-xs\">\n {meal.price}\n </p>\n </div>\n <Badge\n variant=\"secondary\"\n className=\"h-6 rounded-full px-2.5\"\n >\n x{meal.quantity}\n </Badge>\n </div>\n ))}\n <div className=\"border-border/60 flex items-center justify-between border-t pt-3 text-sm\">\n <span className=\"text-muted-foreground\">Bundle total</span>\n <span className=\"font-medium\">$189.00</span>\n </div>\n </CardContent>\n </Card>\n\n <div className=\"mt-4 grid gap-3 sm:grid-cols-2\">\n <Card>\n <CardContent className=\"space-y-2\">\n <p className=\"text-muted-foreground text-sm font-medium\">\n Pickup confirmed\n </p>\n <p className=\"text-sm font-medium\">Mon, Feb 10 at 1:48 PM</p>\n </CardContent>\n </Card>\n <Card>\n <CardContent className=\"space-y-2\">\n <p className=\"text-muted-foreground text-sm font-medium\">\n Remaining travel\n </p>\n <p className=\"text-sm font-medium\">\n {formatDuration(routeData?.duration)}\n </p>\n </CardContent>\n </Card>\n </div>\n\n <div className=\"mt-6 flex flex-wrap items-center gap-2\">\n <Button size=\"sm\" className=\"gap-1.5\">\n <Clock3 className=\"size-4\" />\n View timeline\n </Button>\n <Button variant=\"outline\" size=\"sm\" className=\"gap-1.5\">\n <UserRound className=\"size-4\" />\n Contact courier\n </Button>\n </div>\n </div>\n\n <div className=\"relative h-[400px] overflow-hidden rounded-xl shadow-sm md:h-full\">\n <Map\n loading={loading}\n center={[-122.4263, 37.756]}\n zoom={13.6}\n minZoom={10}\n maxZoom={16}\n >\n <MapRoute\n id=\"delivery-full-route\"\n coordinates={routeData?.coordinates ?? []}\n color={remainingRouteColor}\n width={5.2}\n opacity={0.5}\n interactive={false}\n />\n <MapRoute\n id=\"delivery-progress-route\"\n coordinates={progressCoordinates}\n color=\"#3b82f6\"\n width={6}\n opacity={0.95}\n interactive={false}\n />\n\n {courierPosition && (\n <MapMarker\n longitude={courierPosition[0]}\n latitude={courierPosition[1]}\n offset={[0, 10]}\n >\n <MarkerContent>\n <div className=\"relative grid size-9 place-items-center rounded-full bg-blue-500 shadow-md dark:bg-blue-600\">\n <Truck className=\"size-4 text-white\" />\n </div>\n </MarkerContent>\n <MarkerTooltip>\n <div className=\"space-y-0.5 text-xs\">\n <p className=\"font-medium\">\n Order {formatDuration(routeData?.duration)} away\n </p>\n <p className=\"text-background/70\">\n Route {formatDistance(routeData?.distance)}\n </p>\n </div>\n </MarkerTooltip>\n </MapMarker>\n )}\n\n <MapMarker longitude={pickup.lng} latitude={pickup.lat}>\n <MarkerContent>\n <div className=\"size-4 rounded-full border-2 border-white bg-emerald-500 shadow-sm\" />\n </MarkerContent>\n <MarkerTooltip>Origin</MarkerTooltip>\n </MapMarker>\n\n <MapMarker longitude={dropoff.lng} latitude={dropoff.lat}>\n <MarkerContent>\n <div className=\"size-4 rounded-full border-2 border-white bg-rose-500 shadow-sm\" />\n </MarkerContent>\n <MarkerTooltip>Destination</MarkerTooltip>\n </MapMarker>\n </Map>\n </div>\n </div>\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useTheme } from \"next-themes\";\nimport { Clock3, House, Store, Utensils, Truck, UserRound } from \"lucide-react\";\n\nimport { Map, MapMarker, MapRoute, MarkerContent } from \"@/components/ui/map\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nimport {\n buildRouteUrl,\n deliveryMeals,\n dropoff,\n mapView,\n pickup,\n progressFraction,\n routeStyle,\n type OsrmRouteData,\n} from \"./data\";\n\nfunction formatDistance(meters?: number) {\n if (!meters) return \"--\";\n if (meters < 1000) return `${Math.round(meters)} m`;\n return `${(meters / 1000).toFixed(1)} km`;\n}\n\nfunction formatDuration(seconds?: number) {\n if (!seconds) return \"--\";\n const minutes = Math.round(seconds / 60);\n if (minutes < 60) return `${minutes} min`;\n const hours = Math.floor(minutes / 60);\n const remainingMinutes = minutes % 60;\n return `${hours}h ${remainingMinutes}m`;\n}\n\nexport default function Page() {\n const [routeData, setRouteData] = useState<OsrmRouteData | null>(null);\n const [loading, setLoading] = useState(true);\n const { resolvedTheme } = useTheme();\n const remainingRouteColor =\n resolvedTheme === \"dark\"\n ? routeStyle.remaining.color.dark\n : routeStyle.remaining.color.light;\n\n useEffect(() => {\n async function fetchRoute() {\n setLoading(true);\n try {\n const response = await fetch(buildRouteUrl(pickup, dropoff));\n const data = await response.json();\n const route = data?.routes?.[0];\n if (!route?.geometry?.coordinates) return;\n\n setRouteData({\n coordinates: route.geometry.coordinates as [number, number][],\n duration: route.duration as number,\n distance: route.distance as number,\n });\n } catch (error) {\n console.error(\"Failed to fetch route:\", error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchRoute();\n }, []);\n\n const progressCoordinates = useMemo(() => {\n const total = routeData?.coordinates?.length ?? 0;\n const progressCount = Math.max(2, Math.floor(total * progressFraction));\n return routeData?.coordinates?.slice(0, progressCount) ?? [];\n }, [routeData]);\n\n const courierPosition = progressCoordinates[progressCoordinates.length - 1];\n\n return (\n <div className=\"flex min-h-screen items-center justify-center p-8\">\n <div className=\"bg-sidebar mx-auto grid w-[1200px] rounded-xl border md:grid-cols-[1.05fr_1fr]\">\n <div className=\"flex flex-col p-5 md:p-6\">\n <div className=\"space-y-1\">\n <h3 className=\"text-2xl font-semibold tracking-tight\">\n Track Delivery\n </h3>\n <p className=\"text-muted-foreground text-sm\">Mon Feb 10 - 2-3 PM</p>\n </div>\n\n <Card className=\"mt-5\">\n <CardHeader>\n <CardTitle className=\"font-medium\">\n Order items ({deliveryMeals.length})\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-5\">\n {deliveryMeals.map((meal) => (\n <div key={meal.name} className=\"flex items-center gap-3\">\n <div className=\"bg-muted grid size-8 place-items-center rounded-full text-xs\">\n <Utensils className=\"text-muted-foreground size-4\" />\n </div>\n <div className=\"min-w-4 flex-1\">\n <p className=\"truncate pb-1 text-sm font-medium\">\n {meal.name}\n </p>\n <p className=\"text-muted-foreground text-xs\">\n {meal.price}\n </p>\n </div>\n <Badge\n variant=\"secondary\"\n className=\"h-6 rounded-full px-2.5\"\n >\n x{meal.quantity}\n </Badge>\n </div>\n ))}\n <div className=\"border-border/60 flex items-center justify-between border-t pt-3 text-sm\">\n <span className=\"text-muted-foreground\">Bundle total</span>\n <span className=\"font-medium\">$189.00</span>\n </div>\n </CardContent>\n </Card>\n\n <div className=\"mt-4 grid gap-3 sm:grid-cols-2\">\n <Card>\n <CardContent className=\"space-y-2\">\n <p className=\"text-muted-foreground text-sm\">\n Pickup confirmed\n </p>\n <p className=\"text-sm font-medium\">Mon, Feb 10 at 1:48 PM</p>\n </CardContent>\n </Card>\n <Card>\n <CardContent className=\"space-y-2\">\n <p className=\"text-muted-foreground text-sm\">\n Remaining travel\n </p>\n <p className=\"text-sm font-medium\">\n {formatDuration(routeData?.duration)}\n <span className=\"text-muted-foreground font-normal\">\n {\" · \"}\n {formatDistance(routeData?.distance)}\n </span>\n </p>\n </CardContent>\n </Card>\n </div>\n\n <div className=\"mt-6 flex flex-wrap items-center gap-2\">\n <Button size=\"sm\">\n <Clock3 />\n View timeline\n </Button>\n <Button variant=\"outline\" size=\"sm\">\n <UserRound />\n Contact courier\n </Button>\n </div>\n </div>\n\n <div className=\"relative h-[450px] overflow-hidden rounded-xl shadow-sm md:h-full\">\n <Map\n loading={loading}\n center={mapView.center}\n zoom={mapView.zoom}\n minZoom={mapView.minZoom}\n maxZoom={mapView.maxZoom}\n >\n <MapRoute\n id=\"delivery-full-route\"\n coordinates={routeData?.coordinates ?? []}\n color={remainingRouteColor}\n width={routeStyle.remaining.width}\n opacity={routeStyle.remaining.opacity}\n interactive={false}\n />\n <MapRoute\n id=\"delivery-progress-route\"\n coordinates={progressCoordinates}\n color={routeStyle.progress.color}\n width={routeStyle.progress.width}\n opacity={routeStyle.progress.opacity}\n interactive={false}\n />\n\n {courierPosition && (\n <MapMarker\n longitude={courierPosition[0]}\n latitude={courierPosition[1]}\n offset={[0, 10]}\n >\n <MarkerContent>\n <div\n className=\"relative grid size-9 place-items-center rounded-full shadow-md\"\n style={{ backgroundColor: routeStyle.progress.color }}\n >\n <Truck className=\"size-4 text-white\" />\n <div className=\"bg-popover text-popover-foreground absolute bottom-full left-1/2 mb-2.5 -translate-x-1/2 rounded-md border px-2 py-1 text-xs font-medium whitespace-nowrap shadow-md\">\n {formatDuration(routeData?.duration)} away\n <span className=\"bg-popover absolute top-full left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rotate-45 border-r border-b\" />\n </div>\n </div>\n </MarkerContent>\n </MapMarker>\n )}\n\n <MapMarker longitude={pickup.lng} latitude={pickup.lat}>\n <MarkerContent>\n <div className=\"grid size-7 place-items-center rounded-full bg-emerald-500 shadow-md\">\n <Store className=\"size-3.5 text-white\" />\n </div>\n </MarkerContent>\n </MapMarker>\n\n <MapMarker longitude={dropoff.lng} latitude={dropoff.lat}>\n <MarkerContent>\n <div className=\"grid size-7 place-items-center rounded-full bg-rose-500 shadow-md\">\n <House className=\"size-3.5 text-white\" />\n </div>\n </MarkerContent>\n </MapMarker>\n </Map>\n </div>\n </div>\n </div>\n );\n}\n",
"type": "registry:page",
"target": "app/delivery/page.tsx"
+ },
+ {
+ "path": "src/registry/blocks/delivery-tracker/data.ts",
+ "content": "export interface DeliveryMeal {\n name: string;\n price: string;\n quantity: number;\n}\n\nexport interface OsrmRouteData {\n coordinates: [number, number][];\n duration: number;\n distance: number;\n}\n\nexport const deliveryMeals: DeliveryMeal[] = [\n { name: \"Spicy Tofu Grain Bowl\", price: \"$44.00\", quantity: 1 },\n { name: \"Herb Chicken Rice Box\", price: \"$58.00\", quantity: 2 },\n { name: \"Roasted Veggie Wrap\", price: \"$29.00\", quantity: 1 },\n];\n\n/** Pickup (origin) and dropoff (destination) coordinates. */\nexport const pickup = { lng: -122.4185, lat: 37.7645 };\nexport const dropoff = { lng: -122.434, lat: 37.7475 };\n\n/** Initial map viewport. */\nexport const mapView = {\n center: [-122.4263, 37.756] as [number, number],\n zoom: 13.6,\n minZoom: 12,\n maxZoom: 15,\n};\n\n/** Fraction of the route the courier has already covered (0–1). */\nexport const progressFraction = 0.62;\n\n/**\n * OSRM demo routing endpoint. Swap in your own routing service by returning a\n * URL that responds with GeoJSON route geometry.\n */\nexport function buildRouteUrl(\n from: { lng: number; lat: number },\n to: { lng: number; lat: number },\n) {\n return `https://router.project-osrm.org/route/v1/driving/${from.lng},${from.lat};${to.lng},${to.lat}?overview=full&geometries=geojson`;\n}\n\n/**\n * Route line styling. WebGL paint can't read CSS variables, so colors are\n * concrete hex. `progress` highlights the covered path; `remaining` is themed\n * for the road still ahead.\n */\nexport const routeStyle = {\n progress: { color: \"#3b82f6\", width: 6, opacity: 0.95 },\n remaining: {\n width: 5.2,\n opacity: 0.5,\n color: { light: \"#6b7280\", dark: \"#9ca3af\" },\n },\n} as const;\n",
+ "type": "registry:component",
+ "target": "app/delivery/data.ts"
}
],
"meta": {
- "iframeHeight": "680px"
+ "iframeHeight": "720px"
},
"categories": [
"tracking",
diff --git a/public/r/map.json b/public/r/map.json
index 18dc497..79762b0 100644
--- a/public/r/map.json
+++ b/public/r/map.json
@@ -11,7 +11,7 @@
"files": [
{
"path": "src/registry/map.tsx",
- "content": "\"use client\";\n\nimport MapLibreGL, { type PopupOptions, type MarkerOptions } from \"maplibre-gl\";\nimport \"maplibre-gl/dist/maplibre-gl.css\";\nimport {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { X, Minus, Plus, Locate, Maximize, Loader2 } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nconst defaultStyles = {\n dark: \"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json\",\n light: \"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json\",\n};\n\n// A tile-less, dependency-free style with a transparent background. Use it for\n// data visualizations (choropleths, world arcs, dot maps) where you draw your\n// own layers and don't need a street basemap. The easiest way to opt in is the\n// `blank` prop:\n// <Map blank>...</Map>\n// The transparent background lets the themed container show through.\nconst blankMapStyle: MapLibreGL.StyleSpecification = {\n version: 8,\n sources: {},\n layers: [\n {\n id: \"background\",\n type: \"background\",\n paint: { \"background-color\": \"rgba(0, 0, 0, 0)\" },\n },\n ],\n};\n\nfunction mergeHoverPaint<T extends Record<string, unknown>>(\n paint: T,\n hoverPaint: T | undefined,\n): T {\n if (!hoverPaint) return paint;\n const merged: Record<string, unknown> = { ...paint };\n for (const [key, hoverValue] of Object.entries(hoverPaint)) {\n if (hoverValue === undefined) continue;\n const baseValue = merged[key];\n merged[key] =\n baseValue === undefined\n ? hoverValue\n : [\n \"case\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n hoverValue,\n baseValue,\n ];\n }\n return merged as T;\n}\n\ntype Theme = \"light\" | \"dark\";\n\n// Check document class for theme (works with next-themes, etc.)\nfunction getDocumentTheme(): Theme | null {\n if (typeof document === \"undefined\") return null;\n if (document.documentElement.classList.contains(\"dark\")) return \"dark\";\n if (document.documentElement.classList.contains(\"light\")) return \"light\";\n return null;\n}\n\n// Get system preference\nfunction getSystemTheme(): Theme {\n if (typeof window === \"undefined\") return \"light\";\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"dark\"\n : \"light\";\n}\n\nfunction useResolvedTheme(themeProp?: \"light\" | \"dark\"): Theme {\n const [detectedTheme, setDetectedTheme] = useState<Theme>(\n () => getDocumentTheme() ?? getSystemTheme(),\n );\n\n useEffect(() => {\n if (themeProp) return; // Skip detection if theme is provided via prop\n\n // Watch for document class changes (e.g., next-themes toggling dark class)\n const observer = new MutationObserver(() => {\n const docTheme = getDocumentTheme();\n if (docTheme) {\n setDetectedTheme(docTheme);\n }\n });\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\"],\n });\n\n // Also watch for system preference changes\n const mediaQuery = window.matchMedia(\"(prefers-color-scheme: dark)\");\n const handleSystemChange = (e: MediaQueryListEvent) => {\n // Only use system preference if no document class is set\n if (!getDocumentTheme()) {\n setDetectedTheme(e.matches ? \"dark\" : \"light\");\n }\n };\n mediaQuery.addEventListener(\"change\", handleSystemChange);\n\n return () => {\n observer.disconnect();\n mediaQuery.removeEventListener(\"change\", handleSystemChange);\n };\n }, [themeProp]);\n\n return themeProp ?? detectedTheme;\n}\n\ntype MapContextValue = {\n map: MapLibreGL.Map | null;\n isLoaded: boolean;\n resolvedTheme: Theme;\n};\n\nconst MapContext = createContext<MapContextValue | null>(null);\n\nfunction useMap() {\n const context = useContext(MapContext);\n if (!context) {\n throw new Error(\"useMap must be used within a Map component\");\n }\n return context;\n}\n\n/** Map viewport state */\ntype MapViewport = {\n /** Center coordinates [longitude, latitude] */\n center: [number, number];\n /** Zoom level */\n zoom: number;\n /** Bearing (rotation) in degrees */\n bearing: number;\n /** Pitch (tilt) in degrees */\n pitch: number;\n};\n\ntype MapStyleOption = string | MapLibreGL.StyleSpecification;\n\ntype MapRef = MapLibreGL.Map;\n\ntype MapProps = {\n children?: ReactNode;\n /** Additional CSS classes for the map container */\n className?: string;\n /**\n * Theme for the map. If not provided, automatically detects system preference.\n * Pass your theme value here.\n */\n theme?: Theme;\n /** Custom map styles for light and dark themes. Overrides the default Carto styles. */\n styles?: {\n light?: MapStyleOption;\n dark?: MapStyleOption;\n };\n /**\n * Use a transparent, tile-less basemap instead of the default Carto street\n * basemap — a blank canvas. Used alone it renders nothing; add your own\n * layers on top (`<MapGeoJSON>`, `<MapArc>`, markers, etc.). Ideal for data\n * visualizations (choropleths, arcs, dot maps).\n * Ignored when an explicit `styles` prop is provided.\n */\n blank?: boolean;\n /** Map projection type. Use `{ type: \"globe\" }` for 3D globe view. */\n projection?: MapLibreGL.ProjectionSpecification;\n /**\n * Controlled viewport. When provided with onViewportChange,\n * the map becomes controlled and viewport is driven by this prop.\n */\n viewport?: Partial<MapViewport>;\n /**\n * Callback fired continuously as the viewport changes (pan, zoom, rotate, pitch).\n * Can be used standalone to observe changes, or with `viewport` prop\n * to enable controlled mode where the map viewport is driven by your state.\n */\n onViewportChange?: (viewport: MapViewport) => void;\n /** Show a loading indicator on the map */\n loading?: boolean;\n} & Omit<MapLibreGL.MapOptions, \"container\" | \"style\">;\n\nfunction DefaultLoader() {\n return (\n <div className=\"bg-background/50 absolute inset-0 z-10 flex items-center justify-center backdrop-blur-xs\">\n <div className=\"flex gap-1\">\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full\" />\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full [animation-delay:150ms]\" />\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full [animation-delay:300ms]\" />\n </div>\n </div>\n );\n}\n\nfunction getViewport(map: MapLibreGL.Map): MapViewport {\n const center = map.getCenter();\n return {\n center: [center.lng, center.lat],\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n };\n}\n\nconst Map = forwardRef<MapRef, MapProps>(function Map(\n {\n children,\n className,\n theme: themeProp,\n styles,\n blank = false,\n projection,\n viewport,\n onViewportChange,\n loading = false,\n ...props\n },\n ref,\n) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [mapInstance, setMapInstance] = useState<MapLibreGL.Map | null>(null);\n const [isLoaded, setIsLoaded] = useState(false);\n const [isStyleLoaded, setIsStyleLoaded] = useState(false);\n const currentStyleRef = useRef<MapStyleOption | null>(null);\n const styleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const internalUpdateRef = useRef(false);\n const resolvedTheme = useResolvedTheme(themeProp);\n\n const isControlled = viewport !== undefined && onViewportChange !== undefined;\n\n const onViewportChangeRef = useRef(onViewportChange);\n onViewportChangeRef.current = onViewportChange;\n\n const mapStyles = useMemo(() => {\n // Explicit styles win. Otherwise `blank` opts into the transparent\n // tile-less basemap; with neither, fall back to the Carto defaults.\n if (styles) {\n return {\n dark: styles.dark ?? defaultStyles.dark,\n light: styles.light ?? defaultStyles.light,\n };\n }\n if (blank) {\n return { dark: blankMapStyle, light: blankMapStyle };\n }\n return defaultStyles;\n }, [styles, blank]);\n\n // Expose the map instance to the parent component\n useImperativeHandle(ref, () => mapInstance as MapLibreGL.Map, [mapInstance]);\n\n const clearStyleTimeout = useCallback(() => {\n if (styleTimeoutRef.current) {\n clearTimeout(styleTimeoutRef.current);\n styleTimeoutRef.current = null;\n }\n }, []);\n\n // Initialize the map\n useEffect(() => {\n if (!containerRef.current) return;\n\n const initialStyle =\n resolvedTheme === \"dark\" ? mapStyles.dark : mapStyles.light;\n currentStyleRef.current = initialStyle;\n\n const map = new MapLibreGL.Map({\n container: containerRef.current,\n style: initialStyle,\n renderWorldCopies: false,\n attributionControl: {\n compact: true,\n },\n ...props,\n ...viewport,\n });\n\n const styleDataHandler = () => {\n clearStyleTimeout();\n // Delay to ensure style is fully processed before allowing layer operations\n // This is a workaround to avoid race conditions with the style loading\n // else we have to force update every layer on setStyle change\n styleTimeoutRef.current = setTimeout(() => {\n setIsStyleLoaded(true);\n if (projection) {\n map.setProjection(projection);\n }\n }, 100);\n };\n const loadHandler = () => setIsLoaded(true);\n\n // Viewport change handler - skip if triggered by internal update\n const handleMove = () => {\n if (internalUpdateRef.current) return;\n onViewportChangeRef.current?.(getViewport(map));\n };\n\n map.on(\"load\", loadHandler);\n map.on(\"styledata\", styleDataHandler);\n map.on(\"move\", handleMove);\n setMapInstance(map);\n\n return () => {\n clearStyleTimeout();\n map.off(\"load\", loadHandler);\n map.off(\"styledata\", styleDataHandler);\n map.off(\"move\", handleMove);\n map.remove();\n setIsLoaded(false);\n setIsStyleLoaded(false);\n setMapInstance(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Sync controlled viewport to map\n useEffect(() => {\n if (!mapInstance || !isControlled || !viewport) return;\n if (mapInstance.isMoving()) return;\n\n const current = getViewport(mapInstance);\n const next = {\n center: viewport.center ?? current.center,\n zoom: viewport.zoom ?? current.zoom,\n bearing: viewport.bearing ?? current.bearing,\n pitch: viewport.pitch ?? current.pitch,\n };\n\n if (\n next.center[0] === current.center[0] &&\n next.center[1] === current.center[1] &&\n next.zoom === current.zoom &&\n next.bearing === current.bearing &&\n next.pitch === current.pitch\n ) {\n return;\n }\n\n internalUpdateRef.current = true;\n mapInstance.jumpTo(next);\n internalUpdateRef.current = false;\n }, [mapInstance, isControlled, viewport]);\n\n // Handle style change\n useEffect(() => {\n if (!mapInstance || !resolvedTheme) return;\n\n const newStyle =\n resolvedTheme === \"dark\" ? mapStyles.dark : mapStyles.light;\n\n if (currentStyleRef.current === newStyle) return;\n\n clearStyleTimeout();\n currentStyleRef.current = newStyle;\n setIsStyleLoaded(false);\n\n mapInstance.setStyle(newStyle, { diff: true });\n }, [mapInstance, resolvedTheme, mapStyles, clearStyleTimeout]);\n\n // Sync projection when the prop changes after mount.\n useEffect(() => {\n if (!mapInstance || !isStyleLoaded || !projection) return;\n mapInstance.setProjection(projection);\n }, [mapInstance, isStyleLoaded, projection]);\n\n const contextValue = useMemo(\n () => ({\n map: mapInstance,\n isLoaded: isLoaded && isStyleLoaded,\n resolvedTheme,\n }),\n [mapInstance, isLoaded, isStyleLoaded, resolvedTheme],\n );\n\n return (\n <MapContext.Provider value={contextValue}>\n <div\n ref={containerRef}\n className={cn(\"relative h-full w-full\", className)}\n >\n {(!isLoaded || loading) && <DefaultLoader />}\n {/* SSR-safe: children render only when map is loaded on client */}\n {mapInstance && children}\n </div>\n </MapContext.Provider>\n );\n});\n\ntype MarkerContextValue = {\n marker: MapLibreGL.Marker;\n map: MapLibreGL.Map | null;\n};\n\nconst MarkerContext = createContext<MarkerContextValue | null>(null);\n\nfunction useMarkerContext() {\n const context = useContext(MarkerContext);\n if (!context) {\n throw new Error(\"Marker components must be used within MapMarker\");\n }\n return context;\n}\n\ntype MapMarkerProps = {\n /** Longitude coordinate for marker position */\n longitude: number;\n /** Latitude coordinate for marker position */\n latitude: number;\n /** Marker subcomponents (MarkerContent, MarkerPopup, MarkerTooltip, MarkerLabel) */\n children: ReactNode;\n /** Callback when marker is clicked */\n onClick?: (e: MouseEvent) => void;\n /** Callback when mouse enters marker */\n onMouseEnter?: (e: MouseEvent) => void;\n /** Callback when mouse leaves marker */\n onMouseLeave?: (e: MouseEvent) => void;\n /** Callback when marker drag starts (requires draggable: true) */\n onDragStart?: (lngLat: { lng: number; lat: number }) => void;\n /** Callback during marker drag (requires draggable: true) */\n onDrag?: (lngLat: { lng: number; lat: number }) => void;\n /** Callback when marker drag ends (requires draggable: true) */\n onDragEnd?: (lngLat: { lng: number; lat: number }) => void;\n} & Omit<MarkerOptions, \"element\">;\n\nfunction MapMarker({\n longitude,\n latitude,\n children,\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n draggable = false,\n ...markerOptions\n}: MapMarkerProps) {\n const { map } = useMap();\n\n const callbacksRef = useRef({\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n });\n callbacksRef.current = {\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n };\n\n const marker = useMemo(() => {\n const markerInstance = new MapLibreGL.Marker({\n ...markerOptions,\n element: document.createElement(\"div\"),\n draggable,\n }).setLngLat([longitude, latitude]);\n\n const handleClick = (e: MouseEvent) => callbacksRef.current.onClick?.(e);\n const handleMouseEnter = (e: MouseEvent) =>\n callbacksRef.current.onMouseEnter?.(e);\n const handleMouseLeave = (e: MouseEvent) =>\n callbacksRef.current.onMouseLeave?.(e);\n\n markerInstance.getElement()?.addEventListener(\"click\", handleClick);\n markerInstance\n .getElement()\n ?.addEventListener(\"mouseenter\", handleMouseEnter);\n markerInstance\n .getElement()\n ?.addEventListener(\"mouseleave\", handleMouseLeave);\n\n const handleDragStart = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDragStart?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n const handleDrag = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDrag?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n const handleDragEnd = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDragEnd?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n\n markerInstance.on(\"dragstart\", handleDragStart);\n markerInstance.on(\"drag\", handleDrag);\n markerInstance.on(\"dragend\", handleDragEnd);\n\n return markerInstance;\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n marker.addTo(map);\n\n return () => {\n marker.remove();\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n const { offset, rotation, rotationAlignment, pitchAlignment } = markerOptions;\n\n useEffect(() => {\n const current = marker.getLngLat();\n if (current.lng !== longitude || current.lat !== latitude) {\n marker.setLngLat([longitude, latitude]);\n }\n\n if (marker.isDraggable() !== draggable) {\n marker.setDraggable(draggable);\n }\n\n const currentOffset = marker.getOffset();\n const newOffset = offset ?? [0, 0];\n const [newOffsetX, newOffsetY] = Array.isArray(newOffset)\n ? newOffset\n : [newOffset.x, newOffset.y];\n if (currentOffset.x !== newOffsetX || currentOffset.y !== newOffsetY) {\n marker.setOffset(newOffset);\n }\n\n if (marker.getRotation() !== (rotation ?? 0)) {\n marker.setRotation(rotation ?? 0);\n }\n if (marker.getRotationAlignment() !== (rotationAlignment ?? \"auto\")) {\n marker.setRotationAlignment(rotationAlignment ?? \"auto\");\n }\n if (marker.getPitchAlignment() !== (pitchAlignment ?? \"auto\")) {\n marker.setPitchAlignment(pitchAlignment ?? \"auto\");\n }\n }, [\n marker,\n longitude,\n latitude,\n draggable,\n offset,\n rotation,\n rotationAlignment,\n pitchAlignment,\n ]);\n\n return (\n <MarkerContext.Provider value={{ marker, map }}>\n {children}\n </MarkerContext.Provider>\n );\n}\n\ntype MarkerContentProps = {\n /** Custom marker content. Defaults to a blue dot if not provided */\n children?: ReactNode;\n /** Additional CSS classes for the marker container */\n className?: string;\n};\n\nfunction MarkerContent({ children, className }: MarkerContentProps) {\n const { marker } = useMarkerContext();\n\n return createPortal(\n <div className={cn(\"relative cursor-pointer\", className)}>\n {children || <DefaultMarkerIcon />}\n </div>,\n marker.getElement(),\n );\n}\n\nfunction DefaultMarkerIcon() {\n return (\n <div className=\"relative h-4 w-4 rounded-full border-2 border-white bg-blue-500 shadow-lg\" />\n );\n}\n\nfunction PopupCloseButton({ onClick }: { onClick: () => void }) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n aria-label=\"Close popup\"\n className=\"focus-visible:ring-ring hover:bg-muted text-foreground absolute top-1 right-1 z-10 inline-flex size-5 cursor-pointer items-center justify-center rounded-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset\"\n >\n <X className=\"size-3.5\" />\n </button>\n );\n}\n\ntype MarkerPopupProps = {\n /** Popup content */\n children: ReactNode;\n /** Additional CSS classes for the popup container */\n className?: string;\n /** Show a close button in the popup (default: false) */\n closeButton?: boolean;\n} & Omit<PopupOptions, \"className\" | \"closeButton\">;\n\nfunction MarkerPopup({\n children,\n className,\n closeButton = false,\n ...popupOptions\n}: MarkerPopupProps) {\n const { marker, map } = useMarkerContext();\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const popup = useMemo(() => {\n const popupInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeButton: false,\n })\n .setMaxWidth(\"none\")\n .setDOMContent(container);\n\n return popupInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n popup.setDOMContent(container);\n marker.setPopup(popup);\n\n return () => {\n marker.setPopup(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync popup options when they change.\n useEffect(() => {\n popup.setOffset(offset ?? 16);\n if (maxWidth) {\n popup.setMaxWidth(maxWidth);\n }\n }, [popup, offset, maxWidth]);\n\n const handleClose = () => popup.remove();\n\n return createPortal(\n <div\n className={cn(\n \"bg-popover text-popover-foreground relative max-w-62 rounded-md border p-3 shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {closeButton && <PopupCloseButton onClick={handleClose} />}\n {children}\n </div>,\n container,\n );\n}\n\ntype MarkerTooltipProps = {\n /** Tooltip content */\n children: ReactNode;\n /** Additional CSS classes for the tooltip container */\n className?: string;\n} & Omit<PopupOptions, \"className\" | \"closeButton\" | \"closeOnClick\">;\n\nfunction MarkerTooltip({\n children,\n className,\n ...popupOptions\n}: MarkerTooltipProps) {\n const { marker, map } = useMarkerContext();\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const tooltip = useMemo(() => {\n const tooltipInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeOnClick: true,\n closeButton: false,\n }).setMaxWidth(\"none\");\n\n return tooltipInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n tooltip.setDOMContent(container);\n\n const handleMouseEnter = () => {\n tooltip.setLngLat(marker.getLngLat()).addTo(map);\n };\n const handleMouseLeave = () => tooltip.remove();\n\n marker.getElement()?.addEventListener(\"mouseenter\", handleMouseEnter);\n marker.getElement()?.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n marker.getElement()?.removeEventListener(\"mouseenter\", handleMouseEnter);\n marker.getElement()?.removeEventListener(\"mouseleave\", handleMouseLeave);\n tooltip.remove();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync tooltip options when they change.\n useEffect(() => {\n tooltip.setOffset(offset ?? 16);\n if (maxWidth) {\n tooltip.setMaxWidth(maxWidth);\n }\n }, [tooltip, offset, maxWidth]);\n\n return createPortal(\n <div\n className={cn(\n \"bg-foreground text-background pointer-events-none rounded-md px-2 py-1 text-xs text-balance shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {children}\n </div>,\n container,\n );\n}\n\ntype MarkerLabelProps = {\n /** Label text content */\n children: ReactNode;\n /** Additional CSS classes for the label */\n className?: string;\n /** Position of the label relative to the marker (default: \"top\") */\n position?: \"top\" | \"bottom\";\n};\n\nfunction MarkerLabel({\n children,\n className,\n position = \"top\",\n}: MarkerLabelProps) {\n const positionClasses = {\n top: \"bottom-full mb-1\",\n bottom: \"top-full mt-1\",\n };\n\n return (\n <div\n className={cn(\n \"absolute left-1/2 -translate-x-1/2 whitespace-nowrap\",\n \"text-foreground text-[10px] font-medium\",\n positionClasses[position],\n className,\n )}\n >\n {children}\n </div>\n );\n}\n\ntype MapControlsProps = {\n /** Position of the controls on the map (default: \"bottom-right\") */\n position?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n /** Show zoom in/out buttons (default: true) */\n showZoom?: boolean;\n /** Show compass button to reset bearing (default: false) */\n showCompass?: boolean;\n /** Show locate button to find user's location (default: false) */\n showLocate?: boolean;\n /** Show fullscreen toggle button (default: false) */\n showFullscreen?: boolean;\n /** Additional CSS classes for the controls container */\n className?: string;\n /** Callback with user coordinates when located */\n onLocate?: (coords: { longitude: number; latitude: number }) => void;\n};\n\nconst positionClasses = {\n \"top-left\": \"top-2 left-2\",\n \"top-right\": \"top-2 right-2\",\n \"bottom-left\": \"bottom-2 left-2\",\n \"bottom-right\": \"bottom-10 right-2\",\n};\n\nfunction ControlGroup({ children }: { children: React.ReactNode }) {\n return (\n <div className=\"border-border bg-background [&>button:not(:last-child)]:border-border flex flex-col overflow-hidden rounded-md border shadow-sm [&>button:not(:last-child)]:border-b\">\n {children}\n </div>\n );\n}\n\nfunction ControlButton({\n onClick,\n label,\n children,\n disabled = false,\n}: {\n onClick: () => void;\n label: string;\n children: React.ReactNode;\n disabled?: boolean;\n}) {\n return (\n <button\n onClick={onClick}\n aria-label={label}\n type=\"button\"\n className={cn(\n \"flex size-8 items-center justify-center transition-all\",\n \"first:rounded-t-md last:rounded-b-md\",\n \"hover:bg-accent dark:hover:bg-accent/40\",\n \"focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n )}\n disabled={disabled}\n >\n {children}\n </button>\n );\n}\n\nfunction MapControls({\n position = \"bottom-right\",\n showZoom = true,\n showCompass = false,\n showLocate = false,\n showFullscreen = false,\n className,\n onLocate,\n}: MapControlsProps) {\n const { map } = useMap();\n const [waitingForLocation, setWaitingForLocation] = useState(false);\n\n const handleZoomIn = useCallback(() => {\n map?.zoomTo(map.getZoom() + 1, { duration: 300 });\n }, [map]);\n\n const handleZoomOut = useCallback(() => {\n map?.zoomTo(map.getZoom() - 1, { duration: 300 });\n }, [map]);\n\n const handleResetBearing = useCallback(() => {\n map?.resetNorthPitch({ duration: 300 });\n }, [map]);\n\n const handleLocate = useCallback(() => {\n setWaitingForLocation(true);\n if (\"geolocation\" in navigator) {\n navigator.geolocation.getCurrentPosition(\n (pos) => {\n const coords = {\n longitude: pos.coords.longitude,\n latitude: pos.coords.latitude,\n };\n map?.flyTo({\n center: [coords.longitude, coords.latitude],\n zoom: 14,\n duration: 1500,\n });\n onLocate?.(coords);\n setWaitingForLocation(false);\n },\n (error) => {\n console.error(\"Error getting location:\", error);\n setWaitingForLocation(false);\n },\n );\n }\n }, [map, onLocate]);\n\n const handleFullscreen = useCallback(() => {\n const container = map?.getContainer();\n if (!container) return;\n if (document.fullscreenElement) {\n document.exitFullscreen();\n } else {\n container.requestFullscreen();\n }\n }, [map]);\n\n return (\n <div\n className={cn(\n \"absolute z-10 flex flex-col gap-1.5\",\n positionClasses[position],\n className,\n )}\n >\n {showZoom && (\n <ControlGroup>\n <ControlButton onClick={handleZoomIn} label=\"Zoom in\">\n <Plus className=\"size-4\" />\n </ControlButton>\n <ControlButton onClick={handleZoomOut} label=\"Zoom out\">\n <Minus className=\"size-4\" />\n </ControlButton>\n </ControlGroup>\n )}\n {showCompass && (\n <ControlGroup>\n <CompassButton onClick={handleResetBearing} />\n </ControlGroup>\n )}\n {showLocate && (\n <ControlGroup>\n <ControlButton\n onClick={handleLocate}\n label=\"Find my location\"\n disabled={waitingForLocation}\n >\n {waitingForLocation ? (\n <Loader2 className=\"size-4 animate-spin\" />\n ) : (\n <Locate className=\"size-4\" />\n )}\n </ControlButton>\n </ControlGroup>\n )}\n {showFullscreen && (\n <ControlGroup>\n <ControlButton onClick={handleFullscreen} label=\"Toggle fullscreen\">\n <Maximize className=\"size-4\" />\n </ControlButton>\n </ControlGroup>\n )}\n </div>\n );\n}\n\nfunction CompassButton({ onClick }: { onClick: () => void }) {\n const { map } = useMap();\n const compassRef = useRef<SVGSVGElement>(null);\n\n useEffect(() => {\n if (!map || !compassRef.current) return;\n\n const compass = compassRef.current;\n\n const updateRotation = () => {\n const bearing = map.getBearing();\n const pitch = map.getPitch();\n compass.style.transform = `rotateX(${pitch}deg) rotateZ(${-bearing}deg)`;\n };\n\n map.on(\"rotate\", updateRotation);\n map.on(\"pitch\", updateRotation);\n updateRotation();\n\n return () => {\n map.off(\"rotate\", updateRotation);\n map.off(\"pitch\", updateRotation);\n };\n }, [map]);\n\n return (\n <ControlButton onClick={onClick} label=\"Reset bearing to north\">\n <svg\n ref={compassRef}\n viewBox=\"0 0 24 24\"\n className=\"size-5 transition-transform duration-200\"\n style={{ transformStyle: \"preserve-3d\" }}\n >\n <path d=\"M12 2L16 12H12V2Z\" className=\"fill-red-500\" />\n <path d=\"M12 2L8 12H12V2Z\" className=\"fill-red-300\" />\n <path d=\"M12 22L16 12H12V22Z\" className=\"fill-muted-foreground/60\" />\n <path d=\"M12 22L8 12H12V22Z\" className=\"fill-muted-foreground/30\" />\n </svg>\n </ControlButton>\n );\n}\n\ntype MapPopupProps = {\n /** Longitude coordinate for popup position */\n longitude: number;\n /** Latitude coordinate for popup position */\n latitude: number;\n /** Callback when popup is closed */\n onClose?: () => void;\n /** Popup content */\n children: ReactNode;\n /** Additional CSS classes for the popup container */\n className?: string;\n /** Show a close button in the popup (default: false) */\n closeButton?: boolean;\n} & Omit<PopupOptions, \"className\" | \"closeButton\">;\n\nfunction MapPopup({\n longitude,\n latitude,\n onClose,\n children,\n className,\n closeButton = false,\n ...popupOptions\n}: MapPopupProps) {\n const { map } = useMap();\n const onCloseRef = useRef(onClose);\n onCloseRef.current = onClose;\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const popup = useMemo(() => {\n const popupInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeButton: false,\n })\n .setMaxWidth(\"none\")\n .setLngLat([longitude, latitude]);\n\n return popupInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n const onCloseProp = () => onCloseRef.current?.();\n\n popup.on(\"close\", onCloseProp);\n\n popup.setDOMContent(container);\n popup.addTo(map);\n\n return () => {\n popup.off(\"close\", onCloseProp);\n if (popup.isOpen()) {\n popup.remove();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync popup position and options when they change.\n useEffect(() => {\n const current = popup.getLngLat();\n if (!current || current.lng !== longitude || current.lat !== latitude) {\n popup.setLngLat([longitude, latitude]);\n }\n popup.setOffset(offset ?? 16);\n if (maxWidth) {\n popup.setMaxWidth(maxWidth);\n }\n }, [popup, longitude, latitude, offset, maxWidth]);\n\n const handleClose = () => {\n popup.remove();\n };\n\n return createPortal(\n <div\n className={cn(\n \"bg-popover text-popover-foreground relative max-w-62 rounded-md border p-3 shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {closeButton && <PopupCloseButton onClick={handleClose} />}\n {children}\n </div>,\n container,\n );\n}\n\ntype MapRouteProps = {\n /** Optional unique identifier for the route layer */\n id?: string;\n /** Array of [longitude, latitude] coordinate pairs defining the route */\n coordinates: [number, number][];\n /** Line color as CSS color value (default: \"#4285F4\") */\n color?: string;\n /** Line width in pixels (default: 3) */\n width?: number;\n /** Line opacity from 0 to 1 (default: 0.8) */\n opacity?: number;\n /** Dash pattern [dash length, gap length] for dashed lines */\n dashArray?: [number, number];\n /** Callback when the route line is clicked */\n onClick?: () => void;\n /** Callback when mouse enters the route line */\n onMouseEnter?: () => void;\n /** Callback when mouse leaves the route line */\n onMouseLeave?: () => void;\n /** Whether the route is interactive - shows pointer cursor on hover (default: true) */\n interactive?: boolean;\n};\n\nfunction MapRoute({\n id: propId,\n coordinates,\n color = \"#4285F4\",\n width = 3,\n opacity = 0.8,\n dashArray,\n onClick,\n onMouseEnter,\n onMouseLeave,\n interactive = true,\n}: MapRouteProps) {\n const { map, isLoaded } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `route-source-${id}`;\n const layerId = `route-layer-${id}`;\n\n // Add source and layer on mount\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data: {\n type: \"Feature\",\n properties: {},\n geometry: { type: \"LineString\", coordinates: [] },\n },\n });\n\n map.addLayer({\n id: layerId,\n type: \"line\",\n source: sourceId,\n layout: { \"line-join\": \"round\", \"line-cap\": \"round\" },\n paint: {\n \"line-color\": color,\n \"line-width\": width,\n \"line-opacity\": opacity,\n ...(dashArray && { \"line-dasharray\": dashArray }),\n },\n });\n\n return () => {\n try {\n if (map.getLayer(layerId)) map.removeLayer(layerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // When coordinates change, update the source data\n useEffect(() => {\n if (!isLoaded || !map || coordinates.length < 2) return;\n\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n if (source) {\n source.setData({\n type: \"Feature\",\n properties: {},\n geometry: { type: \"LineString\", coordinates },\n });\n }\n }, [isLoaded, map, coordinates, sourceId]);\n\n useEffect(() => {\n if (!isLoaded || !map || !map.getLayer(layerId)) return;\n\n map.setPaintProperty(layerId, \"line-color\", color);\n map.setPaintProperty(layerId, \"line-width\", width);\n map.setPaintProperty(layerId, \"line-opacity\", opacity);\n map.setPaintProperty(layerId, \"line-dasharray\", dashArray);\n }, [isLoaded, map, layerId, color, width, opacity, dashArray]);\n\n // Handle click and hover events\n useEffect(() => {\n if (!isLoaded || !map || !interactive) return;\n\n const handleClick = () => {\n onClick?.();\n };\n const handleMouseEnter = () => {\n map.getCanvas().style.cursor = \"pointer\";\n onMouseEnter?.();\n };\n const handleMouseLeave = () => {\n map.getCanvas().style.cursor = \"\";\n onMouseLeave?.();\n };\n\n map.on(\"click\", layerId, handleClick);\n map.on(\"mouseenter\", layerId, handleMouseEnter);\n map.on(\"mouseleave\", layerId, handleMouseLeave);\n\n return () => {\n map.off(\"click\", layerId, handleClick);\n map.off(\"mouseenter\", layerId, handleMouseEnter);\n map.off(\"mouseleave\", layerId, handleMouseLeave);\n };\n }, [\n isLoaded,\n map,\n layerId,\n onClick,\n onMouseEnter,\n onMouseLeave,\n interactive,\n ]);\n\n return null;\n}\n\ntype MapGeoJSONData<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> =\n | GeoJSON.FeatureCollection<GeoJSON.Geometry, P>\n | GeoJSON.Feature<GeoJSON.Geometry, P>\n | GeoJSON.Geometry\n | string;\n\ntype MapFillPaint = NonNullable<MapLibreGL.FillLayerSpecification[\"paint\"]>;\ntype MapLinePaint = NonNullable<MapLibreGL.LineLayerSpecification[\"paint\"]>;\n\n/** A rendered feature with strongly-typed `properties`. */\ntype MapGeoJSONFeature<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = Omit<MapLibreGL.MapGeoJSONFeature, \"properties\"> & { properties: P };\n\n/** Event payload passed to MapGeoJSON interaction callbacks. */\ntype MapGeoJSONEvent<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** The feature under the cursor, with its typed GeoJSON properties. */\n feature: MapGeoJSONFeature<P>;\n /** Longitude of the cursor at the time of the event. */\n longitude: number;\n /** Latitude of the cursor at the time of the event. */\n latitude: number;\n /** The underlying MapLibre mouse event for advanced use cases. */\n originalEvent: MapLibreGL.MapLayerMouseEvent;\n};\n\ntype MapGeoJSONProps<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** GeoJSON data (FeatureCollection, Feature, Geometry) or a URL to fetch it from. */\n data: MapGeoJSONData<P>;\n /** Optional unique identifier prefix for the source/layers. Auto-generated if not provided. */\n id?: string;\n /**\n * Feature property to promote to the feature `id`. Required for hover\n * feature-state (`fillHoverPaint`) and stable `onHover`/`onClick` payloads.\n */\n promoteId?: string;\n /**\n * Paint for the polygon fill layer. Merged on top of a theme-aware monochrome\n * surface tone (`fill-color`). Pass `false` to omit the fill layer entirely\n * (e.g. outlines only).\n */\n fillPaint?: MapFillPaint | false;\n /**\n * Paint for the outline layer. Merged on top of a theme-aware hairline\n * default (`line-color` = page background, `line-width` = 0.5). Pass `false`\n * to omit the outline layer.\n */\n linePaint?: MapLinePaint | false;\n /**\n * Paint merged onto the fill layer for the feature under the cursor, applied\n * as a `case` expression keyed on hover feature-state. Requires `promoteId`.\n */\n fillHoverPaint?: MapFillPaint;\n /** Callback when a feature is clicked. */\n onClick?: (e: MapGeoJSONEvent<P>) => void;\n /** Callback fired when the hovered feature changes; `null` when the cursor leaves. */\n onHover?: (e: MapGeoJSONEvent<P> | null) => void;\n /** Whether features respond to mouse events (default: false). */\n interactive?: boolean;\n /** Optional MapLibre layer id to insert the layers before (z-order control). */\n beforeId?: string;\n};\n\n// Theme-aware monochrome defaults so MapGeoJSON reads\n// clearly on the light/dark surface out of the box: a visible neutral-gray fill\n// with page-background separators between shapes. Override either via\n// `fillPaint` / `linePaint`.\nconst GEOJSON_DEFAULT_COLORS = {\n light: { fill: \"#d4d4d4\", line: \"#fafafa\" },\n dark: { fill: \"#404040\", line: \"#0a0a0a\" },\n} satisfies Record<Theme, { fill: string; line: string }>;\n\n/**\n * Renders arbitrary GeoJSON as fill + outline layers on the map. Composes like\n * `MapRoute` / `MapArc` — drop it inside `<Map>` (typically with `blank`) for\n * choropleths and region/data maps. For full control over expressions and\n * multiple layers, manage layers directly via `useMap()` instead.\n */\nfunction MapGeoJSON<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n>({\n data,\n id: propId,\n promoteId,\n fillPaint,\n linePaint,\n fillHoverPaint,\n onClick,\n onHover,\n interactive = false,\n beforeId,\n}: MapGeoJSONProps<P>) {\n const { map, isLoaded, resolvedTheme } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `geojson-source-${id}`;\n const fillLayerId = `geojson-fill-${id}`;\n const lineLayerId = `geojson-line-${id}`;\n\n const defaults = GEOJSON_DEFAULT_COLORS[resolvedTheme];\n\n const showFill = fillPaint !== false;\n const showLine = linePaint !== false;\n\n const mergedFillPaint = useMemo(\n () =>\n mergeHoverPaint(\n { \"fill-color\": defaults.fill, ...(fillPaint || {}) },\n fillHoverPaint,\n ),\n [defaults.fill, fillPaint, fillHoverPaint],\n );\n const mergedLinePaint = useMemo(\n () => ({\n \"line-color\": defaults.line,\n \"line-width\": 0.5,\n ...(linePaint || {}),\n }),\n [defaults.line, linePaint],\n );\n const latestRef = useRef({ onClick, onHover });\n latestRef.current = { onClick, onHover };\n\n // Add source on mount.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data,\n ...(promoteId ? { promoteId } : {}),\n });\n\n return () => {\n try {\n if (map.getLayer(lineLayerId)) map.removeLayer(lineLayerId);\n if (map.getLayer(fillLayerId)) map.removeLayer(fillLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // style may be mid-reload\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // Sync data when it changes.\n useEffect(() => {\n if (!isLoaded || !map) return;\n const source = map.getSource(sourceId) as\n | MapLibreGL.GeoJSONSource\n | undefined;\n source?.setData(data as never);\n }, [isLoaded, map, data, sourceId]);\n\n // Sync layers and paint when visibility or styling changes.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n const source = map.getSource(sourceId);\n if (!source) return;\n\n if (showFill && !map.getLayer(fillLayerId)) {\n map.addLayer(\n {\n id: fillLayerId,\n type: \"fill\",\n source: sourceId,\n paint: mergedFillPaint,\n },\n beforeId,\n );\n } else if (!showFill && map.getLayer(fillLayerId)) {\n map.removeLayer(fillLayerId);\n }\n\n if (showLine && !map.getLayer(lineLayerId)) {\n map.addLayer(\n {\n id: lineLayerId,\n type: \"line\",\n source: sourceId,\n paint: mergedLinePaint,\n },\n beforeId,\n );\n } else if (!showLine && map.getLayer(lineLayerId)) {\n map.removeLayer(lineLayerId);\n }\n\n if (showFill && map.getLayer(fillLayerId)) {\n for (const [key, value] of Object.entries(mergedFillPaint)) {\n map.setPaintProperty(\n fillLayerId,\n key as keyof MapFillPaint,\n value as never,\n );\n }\n }\n if (showLine && map.getLayer(lineLayerId)) {\n for (const [key, value] of Object.entries(mergedLinePaint)) {\n map.setPaintProperty(\n lineLayerId,\n key as keyof MapLinePaint,\n value as never,\n );\n }\n }\n }, [\n isLoaded,\n map,\n sourceId,\n fillLayerId,\n lineLayerId,\n showFill,\n showLine,\n mergedFillPaint,\n mergedLinePaint,\n beforeId,\n ]);\n\n // Interaction handlers (bound to the fill layer).\n useEffect(() => {\n if (!isLoaded || !map || !interactive || !showFill) return;\n\n let hoveredId: string | number | null = null;\n\n const setHover = (next: string | number | null) => {\n if (next === hoveredId) return;\n const sourceExists = !!map.getSource(sourceId);\n if (hoveredId != null && sourceExists) {\n map.setFeatureState(\n { source: sourceId, id: hoveredId },\n { hover: false },\n );\n }\n hoveredId = next;\n if (next != null && sourceExists) {\n map.setFeatureState({ source: sourceId, id: next }, { hover: true });\n }\n };\n\n const handleMouseMove = (e: MapLibreGL.MapLayerMouseEvent) => {\n const feature = e.features?.[0];\n if (!feature) return;\n map.getCanvas().style.cursor = \"pointer\";\n\n const featureId = feature.id;\n if (featureId === hoveredId) return;\n setHover(featureId ?? null);\n latestRef.current.onHover?.({\n feature: feature as unknown as MapGeoJSONFeature<P>,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n const handleMouseLeave = () => {\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n latestRef.current.onHover?.(null);\n };\n\n const handleClick = (e: MapLibreGL.MapLayerMouseEvent) => {\n const feature = e.features?.[0];\n if (!feature) return;\n latestRef.current.onClick?.({\n feature: feature as unknown as MapGeoJSONFeature<P>,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n map.on(\"mousemove\", fillLayerId, handleMouseMove);\n map.on(\"mouseleave\", fillLayerId, handleMouseLeave);\n map.on(\"click\", fillLayerId, handleClick);\n\n return () => {\n map.off(\"mousemove\", fillLayerId, handleMouseMove);\n map.off(\"mouseleave\", fillLayerId, handleMouseLeave);\n map.off(\"click\", fillLayerId, handleClick);\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n };\n }, [isLoaded, map, fillLayerId, sourceId, interactive, showFill]);\n\n return null;\n}\n\n/** A single arc to render inside <MapArc data={...}>. */\ntype MapArcDatum = {\n /** Unique identifier for this arc. Required for hover state tracking and event payloads. */\n id: string | number;\n /** Start coordinate as [longitude, latitude]. */\n from: [number, number];\n /** End coordinate as [longitude, latitude]. */\n to: [number, number];\n};\n\n/** Event payload passed to MapArc interaction callbacks. */\ntype MapArcEvent<T extends MapArcDatum = MapArcDatum> = {\n /** The arc datum that was hovered or clicked. */\n arc: T;\n /** Longitude of the cursor at the time of the event. */\n longitude: number;\n /** Latitude of the cursor at the time of the event. */\n latitude: number;\n /** The underlying MapLibre mouse event for advanced use cases. */\n originalEvent: MapLibreGL.MapMouseEvent;\n};\n\ntype MapArcLinePaint = NonNullable<MapLibreGL.LineLayerSpecification[\"paint\"]>;\ntype MapArcLineLayout = NonNullable<\n MapLibreGL.LineLayerSpecification[\"layout\"]\n>;\n\ntype MapArcProps<T extends MapArcDatum = MapArcDatum> = {\n /** Array of arcs to render. Each arc must have a unique `id`. */\n data: T[];\n /** Optional unique identifier prefix for the arc source/layers. Auto-generated if not provided. */\n id?: string;\n /**\n * How far each arc bows away from a straight line. `0` renders straight\n * lines; higher values bend further. Negative values bend to the opposite\n * side. Arcs are computed as a quadratic Bézier in lng/lat space; the\n * destination longitude is unwrapped relative to the origin so that arcs\n * cross the antimeridian via the shorter great-circle direction. (default: 0.2)\n */\n curvature?: number;\n /** Number of samples used to render each curve. Higher = smoother. (default: 64) */\n samples?: number;\n /**\n * MapLibre paint properties for the arc layer. Merged on top of sensible\n * defaults (`line-color: #4285F4`, `line-width: 2`, `line-opacity: 0.85`).\n * Any value can be a MapLibre expression for per-feature styling, every\n * field on each arc datum (besides `from`/`to`) is exposed via `[\"get\", ...]`.\n */\n paint?: MapArcLinePaint;\n /** MapLibre layout properties for the arc layer. Defaults to rounded joins/caps. */\n layout?: MapArcLineLayout;\n /**\n * Paint properties applied to the arc currently under the cursor. Each key\n * is merged into `paint` as a `case` expression keyed on per-feature hover\n * state, so only the hovered arc changes appearance.\n */\n hoverPaint?: MapArcLinePaint;\n /** Callback when an arc is clicked. */\n onClick?: (e: MapArcEvent<T>) => void;\n /**\n * Callback fired when the hovered arc changes. Receives the cursor's\n * lng/lat at the moment of entry, and `null` when the cursor leaves the\n * last hovered arc.\n */\n onHover?: (e: MapArcEvent<T> | null) => void;\n /** Whether arcs respond to mouse events (default: true). */\n interactive?: boolean;\n /** Optional MapLibre layer id to insert the arc layers before (z-order control). */\n beforeId?: string;\n};\n\nconst DEFAULT_ARC_CURVATURE = 0.2;\nconst DEFAULT_ARC_SAMPLES = 64;\nconst ARC_HIT_MIN_WIDTH = 12;\nconst ARC_HIT_PADDING = 6;\n\nconst DEFAULT_ARC_PAINT: MapArcLinePaint = {\n \"line-color\": \"#4285F4\",\n \"line-width\": 2,\n \"line-opacity\": 0.85,\n};\n\nconst DEFAULT_ARC_LAYOUT: MapArcLineLayout = {\n \"line-join\": \"round\",\n \"line-cap\": \"round\",\n};\n\nfunction buildArcCoordinates(\n from: [number, number],\n to: [number, number],\n curvature: number,\n samples: number,\n): [number, number][] {\n const [x0, y0] = from;\n const [xTo, y2] = to;\n // Unwrap the destination longitude so |dx| <= 180. This makes arcs that\n // straddle the antimeridian (e.g. Tokyo -> San Francisco) bow the short way\n // across the Pacific instead of the long way around the globe. Resulting\n // longitudes may fall outside [-180, 180]; MapLibre renders them correctly\n // on the globe projection, and on mercator when world copies are enabled.\n const rawDx = xTo - x0;\n const x2 = rawDx > 180 ? xTo - 360 : rawDx < -180 ? xTo + 360 : xTo;\n const dx = x2 - x0;\n const dy = y2 - y0;\n const distance = Math.hypot(dx, dy);\n\n if (distance === 0 || curvature === 0) return [from, [x2, y2]];\n\n const mx = (x0 + x2) / 2;\n const my = (y0 + y2) / 2;\n const nx = -dy / distance;\n const ny = dx / distance;\n const offset = distance * curvature;\n const cx = mx + nx * offset;\n const cy = my + ny * offset;\n\n const points: [number, number][] = [];\n const segments = Math.max(2, Math.floor(samples));\n for (let i = 0; i <= segments; i += 1) {\n const t = i / segments;\n const inv = 1 - t;\n const x = inv * inv * x0 + 2 * inv * t * cx + t * t * x2;\n const y = inv * inv * y0 + 2 * inv * t * cy + t * t * y2;\n points.push([x, y]);\n }\n return points;\n}\n\nfunction MapArc<T extends MapArcDatum = MapArcDatum>({\n data,\n id: propId,\n curvature = DEFAULT_ARC_CURVATURE,\n samples = DEFAULT_ARC_SAMPLES,\n paint,\n layout,\n hoverPaint,\n onClick,\n onHover,\n interactive = true,\n beforeId,\n}: MapArcProps<T>) {\n const { map, isLoaded } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `arc-source-${id}`;\n const layerId = `arc-layer-${id}`;\n const hitLayerId = `arc-hit-layer-${id}`;\n\n const mergedPaint = useMemo(\n () => mergeHoverPaint({ ...DEFAULT_ARC_PAINT, ...paint }, hoverPaint),\n [paint, hoverPaint],\n );\n const mergedLayout = useMemo(\n () => ({ ...DEFAULT_ARC_LAYOUT, ...layout }),\n [layout],\n );\n\n const hitWidth = useMemo(() => {\n const w = paint?.[\"line-width\"] ?? DEFAULT_ARC_PAINT[\"line-width\"];\n const base = typeof w === \"number\" ? w : ARC_HIT_MIN_WIDTH;\n return Math.max(base + ARC_HIT_PADDING, ARC_HIT_MIN_WIDTH);\n }, [paint]);\n\n const geoJSON = useMemo<GeoJSON.FeatureCollection<GeoJSON.LineString>>(\n () => ({\n type: \"FeatureCollection\",\n features: data.map((arc) => {\n const { from, to, ...properties } = arc;\n return {\n type: \"Feature\",\n properties,\n geometry: {\n type: \"LineString\",\n coordinates: buildArcCoordinates(from, to, curvature, samples),\n },\n };\n }),\n }),\n [data, curvature, samples],\n );\n\n const latestRef = useRef({ data, onClick, onHover });\n latestRef.current = { data, onClick, onHover };\n\n // Add source and layers on mount.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data: geoJSON,\n promoteId: \"id\",\n });\n\n map.addLayer(\n {\n id: hitLayerId,\n type: \"line\",\n source: sourceId,\n layout: DEFAULT_ARC_LAYOUT,\n paint: {\n \"line-color\": \"rgba(0, 0, 0, 0)\",\n \"line-width\": hitWidth,\n \"line-opacity\": 1,\n },\n },\n beforeId,\n );\n\n map.addLayer(\n {\n id: layerId,\n type: \"line\",\n source: sourceId,\n layout: mergedLayout,\n paint: mergedPaint,\n },\n beforeId,\n );\n\n return () => {\n try {\n if (map.getLayer(layerId)) map.removeLayer(layerId);\n if (map.getLayer(hitLayerId)) map.removeLayer(hitLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // Sync features when data / curvature / samples change.\n useEffect(() => {\n if (!isLoaded || !map) return;\n const source = map.getSource(sourceId) as\n | MapLibreGL.GeoJSONSource\n | undefined;\n source?.setData(geoJSON);\n }, [isLoaded, map, geoJSON, sourceId]);\n\n // Sync paint/layout when they change.\n useEffect(() => {\n if (!isLoaded || !map || !map.getLayer(layerId)) return;\n for (const [key, value] of Object.entries(mergedPaint)) {\n map.setPaintProperty(\n layerId,\n key as keyof MapArcLinePaint,\n value as never,\n );\n }\n for (const [key, value] of Object.entries(mergedLayout)) {\n map.setLayoutProperty(\n layerId,\n key as keyof MapArcLineLayout,\n value as never,\n );\n }\n if (map.getLayer(hitLayerId)) {\n map.setPaintProperty(hitLayerId, \"line-width\", hitWidth);\n }\n }, [isLoaded, map, layerId, hitLayerId, mergedPaint, mergedLayout, hitWidth]);\n\n // Interaction handlers\n useEffect(() => {\n if (!isLoaded || !map || !interactive) return;\n\n let hoveredId: string | number | null = null;\n\n const setHover = (next: string | number | null) => {\n if (next === hoveredId) return;\n const sourceExists = !!map.getSource(sourceId);\n if (hoveredId != null && sourceExists) {\n map.setFeatureState(\n { source: sourceId, id: hoveredId },\n { hover: false },\n );\n }\n hoveredId = next;\n if (next != null && sourceExists) {\n map.setFeatureState({ source: sourceId, id: next }, { hover: true });\n }\n };\n\n const findArc = (featureId: string | number | undefined) =>\n featureId == null\n ? undefined\n : latestRef.current.data.find(\n (arc) => String(arc.id) === String(featureId),\n );\n\n const handleMouseMove = (e: MapLibreGL.MapLayerMouseEvent) => {\n const featureId = e.features?.[0]?.id as string | number | undefined;\n if (featureId == null || featureId === hoveredId) return;\n\n setHover(featureId);\n map.getCanvas().style.cursor = \"pointer\";\n\n const arc = findArc(featureId);\n if (arc) {\n latestRef.current.onHover?.({\n arc: arc as T,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n }\n };\n\n const handleMouseLeave = () => {\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n latestRef.current.onHover?.(null);\n };\n\n const handleClick = (e: MapLibreGL.MapLayerMouseEvent) => {\n const arc = findArc(e.features?.[0]?.id as string | number | undefined);\n if (!arc) return;\n latestRef.current.onClick?.({\n arc: arc as T,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n map.on(\"mousemove\", hitLayerId, handleMouseMove);\n map.on(\"mouseleave\", hitLayerId, handleMouseLeave);\n map.on(\"click\", hitLayerId, handleClick);\n\n return () => {\n map.off(\"mousemove\", hitLayerId, handleMouseMove);\n map.off(\"mouseleave\", hitLayerId, handleMouseLeave);\n map.off(\"click\", hitLayerId, handleClick);\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n };\n }, [isLoaded, map, hitLayerId, sourceId, interactive]);\n\n return null;\n}\n\ntype MapClusterLayerProps<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** GeoJSON FeatureCollection data or URL to fetch GeoJSON from */\n data: string | GeoJSON.FeatureCollection<GeoJSON.Point, P>;\n /** Maximum zoom level to cluster points on (default: 14) */\n clusterMaxZoom?: number;\n /** Radius of each cluster when clustering points in pixels (default: 50) */\n clusterRadius?: number;\n /** Colors for cluster circles: [small, medium, large] based on point count (default: [\"#22c55e\", \"#eab308\", \"#ef4444\"]) */\n clusterColors?: [string, string, string];\n /** Point count thresholds for color/size steps: [medium, large] (default: [100, 750]) */\n clusterThresholds?: [number, number];\n /** Color for unclustered individual points (default: \"#3b82f6\") */\n pointColor?: string;\n /** Callback when an unclustered point is clicked */\n onPointClick?: (\n feature: GeoJSON.Feature<GeoJSON.Point, P>,\n coordinates: [number, number],\n ) => void;\n /** Callback when a cluster is clicked. If not provided, zooms into the cluster */\n onClusterClick?: (\n clusterId: number,\n coordinates: [number, number],\n pointCount: number,\n ) => void;\n};\n\nconst DEFAULT_CLUSTER_COLORS: [string, string, string] = [\n \"#22c55e\",\n \"#eab308\",\n \"#ef4444\",\n];\nconst DEFAULT_CLUSTER_THRESHOLDS: [number, number] = [100, 750];\n\nfunction MapClusterLayer<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n>({\n data,\n clusterMaxZoom = 14,\n clusterRadius = 50,\n clusterColors = DEFAULT_CLUSTER_COLORS,\n clusterThresholds = DEFAULT_CLUSTER_THRESHOLDS,\n pointColor = \"#3b82f6\",\n onPointClick,\n onClusterClick,\n}: MapClusterLayerProps<P>) {\n const { map, isLoaded } = useMap();\n const id = useId();\n const sourceId = `cluster-source-${id}`;\n const clusterLayerId = `clusters-${id}`;\n const clusterCountLayerId = `cluster-count-${id}`;\n const unclusteredLayerId = `unclustered-point-${id}`;\n\n const stylePropsRef = useRef({\n clusterColors,\n clusterThresholds,\n pointColor,\n });\n\n // Add source and layers on mount\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n // Add clustered GeoJSON source\n map.addSource(sourceId, {\n type: \"geojson\",\n data,\n cluster: true,\n clusterMaxZoom,\n clusterRadius,\n });\n\n // Add cluster circles layer\n map.addLayer({\n id: clusterLayerId,\n type: \"circle\",\n source: sourceId,\n filter: [\"has\", \"point_count\"],\n paint: {\n \"circle-color\": [\n \"step\",\n [\"get\", \"point_count\"],\n clusterColors[0],\n clusterThresholds[0],\n clusterColors[1],\n clusterThresholds[1],\n clusterColors[2],\n ],\n \"circle-radius\": [\n \"step\",\n [\"get\", \"point_count\"],\n 20,\n clusterThresholds[0],\n 30,\n clusterThresholds[1],\n 40,\n ],\n \"circle-stroke-width\": 1,\n \"circle-stroke-color\": \"#fff\",\n \"circle-opacity\": 0.85,\n },\n });\n\n // Add cluster count text layer\n map.addLayer({\n id: clusterCountLayerId,\n type: \"symbol\",\n source: sourceId,\n filter: [\"has\", \"point_count\"],\n layout: {\n \"text-field\": \"{point_count_abbreviated}\",\n \"text-font\": [\"Open Sans\"],\n \"text-size\": 12,\n },\n paint: {\n \"text-color\": \"#fff\",\n },\n });\n\n // Add unclustered point layer\n map.addLayer({\n id: unclusteredLayerId,\n type: \"circle\",\n source: sourceId,\n filter: [\"!\", [\"has\", \"point_count\"]],\n paint: {\n \"circle-color\": pointColor,\n \"circle-radius\": 5,\n \"circle-stroke-width\": 2,\n \"circle-stroke-color\": \"#fff\",\n },\n });\n\n return () => {\n try {\n if (map.getLayer(clusterCountLayerId))\n map.removeLayer(clusterCountLayerId);\n if (map.getLayer(unclusteredLayerId))\n map.removeLayer(unclusteredLayerId);\n if (map.getLayer(clusterLayerId)) map.removeLayer(clusterLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map, sourceId]);\n\n // Update source data when data prop changes (only for non-URL data)\n useEffect(() => {\n if (!isLoaded || !map || typeof data === \"string\") return;\n\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n if (source) {\n source.setData(data);\n }\n }, [isLoaded, map, data, sourceId]);\n\n // Update layer styles when props change\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n const prev = stylePropsRef.current;\n const colorsChanged =\n prev.clusterColors !== clusterColors ||\n prev.clusterThresholds !== clusterThresholds;\n\n // Update cluster layer colors and sizes\n if (map.getLayer(clusterLayerId) && colorsChanged) {\n map.setPaintProperty(clusterLayerId, \"circle-color\", [\n \"step\",\n [\"get\", \"point_count\"],\n clusterColors[0],\n clusterThresholds[0],\n clusterColors[1],\n clusterThresholds[1],\n clusterColors[2],\n ]);\n map.setPaintProperty(clusterLayerId, \"circle-radius\", [\n \"step\",\n [\"get\", \"point_count\"],\n 20,\n clusterThresholds[0],\n 30,\n clusterThresholds[1],\n 40,\n ]);\n }\n\n // Update unclustered point layer color\n if (map.getLayer(unclusteredLayerId) && prev.pointColor !== pointColor) {\n map.setPaintProperty(unclusteredLayerId, \"circle-color\", pointColor);\n }\n\n stylePropsRef.current = { clusterColors, clusterThresholds, pointColor };\n }, [\n isLoaded,\n map,\n clusterLayerId,\n unclusteredLayerId,\n clusterColors,\n clusterThresholds,\n pointColor,\n ]);\n\n // Handle click events\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n // Cluster click handler - zoom into cluster\n const handleClusterClick = async (\n e: MapLibreGL.MapMouseEvent & {\n features?: MapLibreGL.MapGeoJSONFeature[];\n },\n ) => {\n const features = map.queryRenderedFeatures(e.point, {\n layers: [clusterLayerId],\n });\n if (!features.length) return;\n\n const feature = features[0];\n const clusterId = feature.properties?.cluster_id as number;\n const pointCount = feature.properties?.point_count as number;\n const coordinates = (feature.geometry as GeoJSON.Point).coordinates as [\n number,\n number,\n ];\n\n if (onClusterClick) {\n onClusterClick(clusterId, coordinates, pointCount);\n } else {\n // Default behavior: zoom to cluster expansion zoom\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n const zoom = await source.getClusterExpansionZoom(clusterId);\n map.easeTo({\n center: coordinates,\n zoom,\n });\n }\n };\n\n // Unclustered point click handler\n const handlePointClick = (\n e: MapLibreGL.MapMouseEvent & {\n features?: MapLibreGL.MapGeoJSONFeature[];\n },\n ) => {\n if (!onPointClick || !e.features?.length) return;\n\n const feature = e.features[0];\n const coordinates = (\n feature.geometry as GeoJSON.Point\n ).coordinates.slice() as [number, number];\n\n // Handle world copies\n while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {\n coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;\n }\n\n onPointClick(\n feature as unknown as GeoJSON.Feature<GeoJSON.Point, P>,\n coordinates,\n );\n };\n\n // Cursor style handlers\n const handleMouseEnterCluster = () => {\n map.getCanvas().style.cursor = \"pointer\";\n };\n const handleMouseLeaveCluster = () => {\n map.getCanvas().style.cursor = \"\";\n };\n const handleMouseEnterPoint = () => {\n if (onPointClick) {\n map.getCanvas().style.cursor = \"pointer\";\n }\n };\n const handleMouseLeavePoint = () => {\n map.getCanvas().style.cursor = \"\";\n };\n\n map.on(\"click\", clusterLayerId, handleClusterClick);\n map.on(\"click\", unclusteredLayerId, handlePointClick);\n map.on(\"mouseenter\", clusterLayerId, handleMouseEnterCluster);\n map.on(\"mouseleave\", clusterLayerId, handleMouseLeaveCluster);\n map.on(\"mouseenter\", unclusteredLayerId, handleMouseEnterPoint);\n map.on(\"mouseleave\", unclusteredLayerId, handleMouseLeavePoint);\n\n return () => {\n map.off(\"click\", clusterLayerId, handleClusterClick);\n map.off(\"click\", unclusteredLayerId, handlePointClick);\n map.off(\"mouseenter\", clusterLayerId, handleMouseEnterCluster);\n map.off(\"mouseleave\", clusterLayerId, handleMouseLeaveCluster);\n map.off(\"mouseenter\", unclusteredLayerId, handleMouseEnterPoint);\n map.off(\"mouseleave\", unclusteredLayerId, handleMouseLeavePoint);\n };\n }, [\n isLoaded,\n map,\n clusterLayerId,\n unclusteredLayerId,\n sourceId,\n onClusterClick,\n onPointClick,\n ]);\n\n return null;\n}\n\nexport {\n Map,\n useMap,\n MapMarker,\n MarkerContent,\n MarkerPopup,\n MarkerTooltip,\n MarkerLabel,\n MapPopup,\n MapControls,\n MapRoute,\n MapArc,\n MapGeoJSON,\n MapClusterLayer,\n};\n\nexport type { MapRef, MapViewport, MapArcDatum, MapArcEvent, MapGeoJSONEvent };\n",
+ "content": "\"use client\";\n\nimport MapLibreGL, { type PopupOptions, type MarkerOptions } from \"maplibre-gl\";\nimport \"maplibre-gl/dist/maplibre-gl.css\";\nimport {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { X, Minus, Plus, Locate, Maximize, Loader2 } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nconst defaultStyles = {\n dark: \"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json\",\n light: \"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json\",\n};\n\n// A tile-less, dependency-free style with a transparent background. Use it for\n// data visualizations (choropleths, world arcs, dot maps) where you draw your\n// own layers and don't need a street basemap. The easiest way to opt in is the\n// `blank` prop:\n// <Map blank>...</Map>\n// The transparent background lets the themed container show through.\nconst blankMapStyle: MapLibreGL.StyleSpecification = {\n version: 8,\n sources: {},\n layers: [\n {\n id: \"background\",\n type: \"background\",\n paint: { \"background-color\": \"rgba(0, 0, 0, 0)\" },\n },\n ],\n};\n\nfunction mergeHoverPaint<T extends Record<string, unknown>>(\n paint: T,\n hoverPaint: T | undefined,\n): T {\n if (!hoverPaint) return paint;\n const merged: Record<string, unknown> = { ...paint };\n for (const [key, hoverValue] of Object.entries(hoverPaint)) {\n if (hoverValue === undefined) continue;\n const baseValue = merged[key];\n merged[key] =\n baseValue === undefined\n ? hoverValue\n : [\n \"case\",\n [\"boolean\", [\"feature-state\", \"hover\"], false],\n hoverValue,\n baseValue,\n ];\n }\n return merged as T;\n}\n\ntype Theme = \"light\" | \"dark\";\n\n// Check document class for theme (works with next-themes, etc.)\nfunction getDocumentTheme(): Theme | null {\n if (typeof document === \"undefined\") return null;\n if (document.documentElement.classList.contains(\"dark\")) return \"dark\";\n if (document.documentElement.classList.contains(\"light\")) return \"light\";\n return null;\n}\n\n// Get system preference\nfunction getSystemTheme(): Theme {\n if (typeof window === \"undefined\") return \"light\";\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"dark\"\n : \"light\";\n}\n\nfunction useResolvedTheme(themeProp?: \"light\" | \"dark\"): Theme {\n const [detectedTheme, setDetectedTheme] = useState<Theme>(\n () => getDocumentTheme() ?? getSystemTheme(),\n );\n\n useEffect(() => {\n if (themeProp) return; // Skip detection if theme is provided via prop\n\n // Watch for document class changes (e.g., next-themes toggling dark class)\n const observer = new MutationObserver(() => {\n const docTheme = getDocumentTheme();\n if (docTheme) {\n setDetectedTheme(docTheme);\n }\n });\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\"],\n });\n\n // Also watch for system preference changes\n const mediaQuery = window.matchMedia(\"(prefers-color-scheme: dark)\");\n const handleSystemChange = (e: MediaQueryListEvent) => {\n // Only use system preference if no document class is set\n if (!getDocumentTheme()) {\n setDetectedTheme(e.matches ? \"dark\" : \"light\");\n }\n };\n mediaQuery.addEventListener(\"change\", handleSystemChange);\n\n return () => {\n observer.disconnect();\n mediaQuery.removeEventListener(\"change\", handleSystemChange);\n };\n }, [themeProp]);\n\n return themeProp ?? detectedTheme;\n}\n\ntype MapContextValue = {\n map: MapLibreGL.Map | null;\n isLoaded: boolean;\n resolvedTheme: Theme;\n};\n\nconst MapContext = createContext<MapContextValue | null>(null);\n\nfunction useMap() {\n const context = useContext(MapContext);\n if (!context) {\n throw new Error(\"useMap must be used within a Map component\");\n }\n return context;\n}\n\n/** Map viewport state */\ntype MapViewport = {\n /** Center coordinates [longitude, latitude] */\n center: [number, number];\n /** Zoom level */\n zoom: number;\n /** Bearing (rotation) in degrees */\n bearing: number;\n /** Pitch (tilt) in degrees */\n pitch: number;\n};\n\ntype MapStyleOption = string | MapLibreGL.StyleSpecification;\n\ntype MapRef = MapLibreGL.Map;\n\ntype MapProps = {\n children?: ReactNode;\n /** Additional CSS classes for the map container */\n className?: string;\n /**\n * Theme for the map. If not provided, automatically detects system preference.\n * Pass your theme value here.\n */\n theme?: Theme;\n /** Custom map styles for light and dark themes. Overrides the default Carto styles. */\n styles?: {\n light?: MapStyleOption;\n dark?: MapStyleOption;\n };\n /**\n * Use a transparent, tile-less basemap instead of the default Carto street\n * basemap — a blank canvas. Used alone it renders nothing; add your own\n * layers on top (`<MapGeoJSON>`, `<MapArc>`, markers, etc.). Ideal for data\n * visualizations (choropleths, arcs, dot maps).\n * Ignored when an explicit `styles` prop is provided.\n */\n blank?: boolean;\n /** Map projection type. Use `{ type: \"globe\" }` for 3D globe view. */\n projection?: MapLibreGL.ProjectionSpecification;\n /**\n * Controlled viewport. When provided with onViewportChange,\n * the map becomes controlled and viewport is driven by this prop.\n */\n viewport?: Partial<MapViewport>;\n /**\n * Callback fired continuously as the viewport changes (pan, zoom, rotate, pitch).\n * Can be used standalone to observe changes, or with `viewport` prop\n * to enable controlled mode where the map viewport is driven by your state.\n */\n onViewportChange?: (viewport: MapViewport) => void;\n /** Show a loading indicator on the map */\n loading?: boolean;\n} & Omit<MapLibreGL.MapOptions, \"container\" | \"style\">;\n\nfunction DefaultLoader() {\n return (\n <div className=\"bg-background/50 absolute inset-0 z-10 flex items-center justify-center backdrop-blur-xs\">\n <div className=\"flex gap-1\">\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full\" />\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full [animation-delay:150ms]\" />\n <span className=\"bg-muted-foreground/60 size-1.5 animate-pulse rounded-full [animation-delay:300ms]\" />\n </div>\n </div>\n );\n}\n\nfunction getViewport(map: MapLibreGL.Map): MapViewport {\n const center = map.getCenter();\n return {\n center: [center.lng, center.lat],\n zoom: map.getZoom(),\n bearing: map.getBearing(),\n pitch: map.getPitch(),\n };\n}\n\nconst Map = forwardRef<MapRef, MapProps>(function Map(\n {\n children,\n className,\n theme: themeProp,\n styles,\n blank = false,\n projection,\n viewport,\n onViewportChange,\n loading = false,\n ...props\n },\n ref,\n) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [mapInstance, setMapInstance] = useState<MapLibreGL.Map | null>(null);\n const [isLoaded, setIsLoaded] = useState(false);\n const [isStyleLoaded, setIsStyleLoaded] = useState(false);\n const currentStyleRef = useRef<MapStyleOption | null>(null);\n const styleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const internalUpdateRef = useRef(false);\n const resolvedTheme = useResolvedTheme(themeProp);\n\n const isControlled = viewport !== undefined && onViewportChange !== undefined;\n\n const onViewportChangeRef = useRef(onViewportChange);\n onViewportChangeRef.current = onViewportChange;\n\n const mapStyles = useMemo(() => {\n // Explicit styles win. Otherwise `blank` opts into the transparent\n // tile-less basemap; with neither, fall back to the Carto defaults.\n if (styles) {\n return {\n dark: styles.dark ?? defaultStyles.dark,\n light: styles.light ?? defaultStyles.light,\n };\n }\n if (blank) {\n return { dark: blankMapStyle, light: blankMapStyle };\n }\n return defaultStyles;\n }, [styles, blank]);\n\n // Expose the map instance to the parent component\n useImperativeHandle(ref, () => mapInstance as MapLibreGL.Map, [mapInstance]);\n\n const clearStyleTimeout = useCallback(() => {\n if (styleTimeoutRef.current) {\n clearTimeout(styleTimeoutRef.current);\n styleTimeoutRef.current = null;\n }\n }, []);\n\n // Initialize the map\n useEffect(() => {\n if (!containerRef.current) return;\n\n const initialStyle =\n resolvedTheme === \"dark\" ? mapStyles.dark : mapStyles.light;\n currentStyleRef.current = initialStyle;\n\n const map = new MapLibreGL.Map({\n container: containerRef.current,\n style: initialStyle,\n renderWorldCopies: false,\n attributionControl: {\n compact: true,\n },\n ...props,\n ...viewport,\n });\n\n const styleDataHandler = () => {\n clearStyleTimeout();\n // Delay to ensure style is fully processed before allowing layer operations\n // This is a workaround to avoid race conditions with the style loading\n // else we have to force update every layer on setStyle change\n styleTimeoutRef.current = setTimeout(() => {\n setIsStyleLoaded(true);\n if (projection) {\n map.setProjection(projection);\n }\n }, 100);\n };\n const loadHandler = () => setIsLoaded(true);\n\n // Viewport change handler - skip if triggered by internal update\n const handleMove = () => {\n if (internalUpdateRef.current) return;\n onViewportChangeRef.current?.(getViewport(map));\n };\n\n map.on(\"load\", loadHandler);\n map.on(\"styledata\", styleDataHandler);\n map.on(\"move\", handleMove);\n setMapInstance(map);\n\n return () => {\n clearStyleTimeout();\n map.off(\"load\", loadHandler);\n map.off(\"styledata\", styleDataHandler);\n map.off(\"move\", handleMove);\n map.remove();\n setIsLoaded(false);\n setIsStyleLoaded(false);\n setMapInstance(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Sync controlled viewport to map\n useEffect(() => {\n if (!mapInstance || !isControlled || !viewport) return;\n if (mapInstance.isMoving()) return;\n\n const current = getViewport(mapInstance);\n const next = {\n center: viewport.center ?? current.center,\n zoom: viewport.zoom ?? current.zoom,\n bearing: viewport.bearing ?? current.bearing,\n pitch: viewport.pitch ?? current.pitch,\n };\n\n if (\n next.center[0] === current.center[0] &&\n next.center[1] === current.center[1] &&\n next.zoom === current.zoom &&\n next.bearing === current.bearing &&\n next.pitch === current.pitch\n ) {\n return;\n }\n\n internalUpdateRef.current = true;\n mapInstance.jumpTo(next);\n internalUpdateRef.current = false;\n }, [mapInstance, isControlled, viewport]);\n\n // Handle style change\n useEffect(() => {\n if (!mapInstance || !resolvedTheme) return;\n\n const newStyle =\n resolvedTheme === \"dark\" ? mapStyles.dark : mapStyles.light;\n\n if (currentStyleRef.current === newStyle) return;\n\n clearStyleTimeout();\n currentStyleRef.current = newStyle;\n setIsStyleLoaded(false);\n\n mapInstance.setStyle(newStyle, { diff: true });\n }, [mapInstance, resolvedTheme, mapStyles, clearStyleTimeout]);\n\n // Sync projection when the prop changes after mount.\n useEffect(() => {\n if (!mapInstance || !isStyleLoaded || !projection) return;\n mapInstance.setProjection(projection);\n }, [mapInstance, isStyleLoaded, projection]);\n\n const contextValue = useMemo(\n () => ({\n map: mapInstance,\n isLoaded: isLoaded && isStyleLoaded,\n resolvedTheme,\n }),\n [mapInstance, isLoaded, isStyleLoaded, resolvedTheme],\n );\n\n return (\n <MapContext.Provider value={contextValue}>\n <div\n ref={containerRef}\n className={cn(\"relative h-full w-full\", className)}\n >\n {(!isLoaded || loading) && <DefaultLoader />}\n {/* SSR-safe: children render only when map is loaded on client */}\n {mapInstance && children}\n </div>\n </MapContext.Provider>\n );\n});\n\ntype MarkerContextValue = {\n marker: MapLibreGL.Marker;\n map: MapLibreGL.Map | null;\n};\n\nconst MarkerContext = createContext<MarkerContextValue | null>(null);\n\nfunction useMarkerContext() {\n const context = useContext(MarkerContext);\n if (!context) {\n throw new Error(\"Marker components must be used within MapMarker\");\n }\n return context;\n}\n\ntype MapMarkerProps = {\n /** Longitude coordinate for marker position */\n longitude: number;\n /** Latitude coordinate for marker position */\n latitude: number;\n /** Marker subcomponents (MarkerContent, MarkerPopup, MarkerTooltip, MarkerLabel) */\n children: ReactNode;\n /** Callback when marker is clicked */\n onClick?: (e: MouseEvent) => void;\n /** Callback when mouse enters marker */\n onMouseEnter?: (e: MouseEvent) => void;\n /** Callback when mouse leaves marker */\n onMouseLeave?: (e: MouseEvent) => void;\n /** Callback when marker drag starts (requires draggable: true) */\n onDragStart?: (lngLat: { lng: number; lat: number }) => void;\n /** Callback during marker drag (requires draggable: true) */\n onDrag?: (lngLat: { lng: number; lat: number }) => void;\n /** Callback when marker drag ends (requires draggable: true) */\n onDragEnd?: (lngLat: { lng: number; lat: number }) => void;\n} & Omit<MarkerOptions, \"element\">;\n\nfunction MapMarker({\n longitude,\n latitude,\n children,\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n draggable = false,\n ...markerOptions\n}: MapMarkerProps) {\n const { map } = useMap();\n\n const callbacksRef = useRef({\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n });\n callbacksRef.current = {\n onClick,\n onMouseEnter,\n onMouseLeave,\n onDragStart,\n onDrag,\n onDragEnd,\n };\n\n const marker = useMemo(() => {\n const markerInstance = new MapLibreGL.Marker({\n ...markerOptions,\n element: document.createElement(\"div\"),\n draggable,\n }).setLngLat([longitude, latitude]);\n\n const handleClick = (e: MouseEvent) => callbacksRef.current.onClick?.(e);\n const handleMouseEnter = (e: MouseEvent) =>\n callbacksRef.current.onMouseEnter?.(e);\n const handleMouseLeave = (e: MouseEvent) =>\n callbacksRef.current.onMouseLeave?.(e);\n\n markerInstance.getElement()?.addEventListener(\"click\", handleClick);\n markerInstance\n .getElement()\n ?.addEventListener(\"mouseenter\", handleMouseEnter);\n markerInstance\n .getElement()\n ?.addEventListener(\"mouseleave\", handleMouseLeave);\n\n const handleDragStart = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDragStart?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n const handleDrag = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDrag?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n const handleDragEnd = () => {\n const lngLat = markerInstance.getLngLat();\n callbacksRef.current.onDragEnd?.({ lng: lngLat.lng, lat: lngLat.lat });\n };\n\n markerInstance.on(\"dragstart\", handleDragStart);\n markerInstance.on(\"drag\", handleDrag);\n markerInstance.on(\"dragend\", handleDragEnd);\n\n return markerInstance;\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n marker.addTo(map);\n\n return () => {\n marker.remove();\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n const { offset, rotation, rotationAlignment, pitchAlignment } = markerOptions;\n\n useEffect(() => {\n const current = marker.getLngLat();\n if (current.lng !== longitude || current.lat !== latitude) {\n marker.setLngLat([longitude, latitude]);\n }\n\n if (marker.isDraggable() !== draggable) {\n marker.setDraggable(draggable);\n }\n\n const currentOffset = marker.getOffset();\n const newOffset = offset ?? [0, 0];\n const [newOffsetX, newOffsetY] = Array.isArray(newOffset)\n ? newOffset\n : [newOffset.x, newOffset.y];\n if (currentOffset.x !== newOffsetX || currentOffset.y !== newOffsetY) {\n marker.setOffset(newOffset);\n }\n\n if (marker.getRotation() !== (rotation ?? 0)) {\n marker.setRotation(rotation ?? 0);\n }\n if (marker.getRotationAlignment() !== (rotationAlignment ?? \"auto\")) {\n marker.setRotationAlignment(rotationAlignment ?? \"auto\");\n }\n if (marker.getPitchAlignment() !== (pitchAlignment ?? \"auto\")) {\n marker.setPitchAlignment(pitchAlignment ?? \"auto\");\n }\n }, [\n marker,\n longitude,\n latitude,\n draggable,\n offset,\n rotation,\n rotationAlignment,\n pitchAlignment,\n ]);\n\n return (\n <MarkerContext.Provider value={{ marker, map }}>\n {children}\n </MarkerContext.Provider>\n );\n}\n\ntype MarkerContentProps = {\n /** Custom marker content. Defaults to a blue dot if not provided */\n children?: ReactNode;\n /** Additional CSS classes for the marker container */\n className?: string;\n};\n\nfunction MarkerContent({ children, className }: MarkerContentProps) {\n const { marker } = useMarkerContext();\n\n return createPortal(\n <div className={cn(\"relative cursor-pointer\", className)}>\n {children || <DefaultMarkerIcon />}\n </div>,\n marker.getElement(),\n );\n}\n\nfunction DefaultMarkerIcon() {\n return (\n <div className=\"relative h-4 w-4 rounded-full border-2 border-white bg-blue-500 shadow-lg\" />\n );\n}\n\nfunction PopupCloseButton({ onClick }: { onClick: () => void }) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n aria-label=\"Close popup\"\n className=\"focus-visible:ring-ring hover:bg-muted text-foreground absolute top-1 right-1 z-10 inline-flex size-5 cursor-pointer items-center justify-center rounded-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset\"\n >\n <X className=\"size-3.5\" />\n </button>\n );\n}\n\ntype MarkerPopupProps = {\n /** Popup content */\n children: ReactNode;\n /** Additional CSS classes for the popup container */\n className?: string;\n /** Show a close button in the popup (default: false) */\n closeButton?: boolean;\n} & Omit<PopupOptions, \"className\" | \"closeButton\">;\n\nfunction MarkerPopup({\n children,\n className,\n closeButton = false,\n ...popupOptions\n}: MarkerPopupProps) {\n const { marker, map } = useMarkerContext();\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const popup = useMemo(() => {\n const popupInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeButton: false,\n })\n .setMaxWidth(\"none\")\n .setDOMContent(container);\n\n return popupInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n popup.setDOMContent(container);\n marker.setPopup(popup);\n\n return () => {\n marker.setPopup(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync popup options when they change.\n useEffect(() => {\n popup.setOffset(offset ?? 16);\n if (maxWidth) {\n popup.setMaxWidth(maxWidth);\n }\n }, [popup, offset, maxWidth]);\n\n const handleClose = () => popup.remove();\n\n return createPortal(\n <div\n className={cn(\n \"bg-popover text-popover-foreground relative max-w-62 rounded-md border p-3 shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {closeButton && <PopupCloseButton onClick={handleClose} />}\n {children}\n </div>,\n container,\n );\n}\n\ntype MarkerTooltipProps = {\n /** Tooltip content */\n children: ReactNode;\n /** Additional CSS classes for the tooltip container */\n className?: string;\n} & Omit<PopupOptions, \"className\" | \"closeButton\" | \"closeOnClick\">;\n\nfunction MarkerTooltip({\n children,\n className,\n ...popupOptions\n}: MarkerTooltipProps) {\n const { marker, map } = useMarkerContext();\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const tooltip = useMemo(() => {\n const tooltipInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeOnClick: true,\n closeButton: false,\n }).setMaxWidth(\"none\");\n\n return tooltipInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n tooltip.setDOMContent(container);\n\n const handleMouseEnter = () => {\n tooltip.setLngLat(marker.getLngLat()).addTo(map);\n };\n const handleMouseLeave = () => tooltip.remove();\n\n marker.getElement()?.addEventListener(\"mouseenter\", handleMouseEnter);\n marker.getElement()?.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n marker.getElement()?.removeEventListener(\"mouseenter\", handleMouseEnter);\n marker.getElement()?.removeEventListener(\"mouseleave\", handleMouseLeave);\n tooltip.remove();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync tooltip options when they change.\n useEffect(() => {\n tooltip.setOffset(offset ?? 16);\n if (maxWidth) {\n tooltip.setMaxWidth(maxWidth);\n }\n }, [tooltip, offset, maxWidth]);\n\n return createPortal(\n <div\n className={cn(\n \"bg-foreground text-background pointer-events-none rounded-md px-2 py-1 text-xs text-balance shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {children}\n </div>,\n container,\n );\n}\n\ntype MarkerLabelProps = {\n /** Label text content */\n children: ReactNode;\n /** Additional CSS classes for the label */\n className?: string;\n /** Position of the label relative to the marker (default: \"top\") */\n position?: \"top\" | \"bottom\";\n};\n\nfunction MarkerLabel({\n children,\n className,\n position = \"top\",\n}: MarkerLabelProps) {\n const positionClasses = {\n top: \"bottom-full mb-1\",\n bottom: \"top-full mt-1\",\n };\n\n return (\n <div\n className={cn(\n \"absolute left-1/2 -translate-x-1/2 whitespace-nowrap\",\n \"text-foreground text-[10px] font-medium\",\n positionClasses[position],\n className,\n )}\n >\n {children}\n </div>\n );\n}\n\ntype MapControlsProps = {\n /** Position of the controls on the map (default: \"bottom-right\") */\n position?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n /** Show zoom in/out buttons (default: true) */\n showZoom?: boolean;\n /** Show compass button to reset bearing (default: false) */\n showCompass?: boolean;\n /** Show locate button to find user's location (default: false) */\n showLocate?: boolean;\n /** Show fullscreen toggle button (default: false) */\n showFullscreen?: boolean;\n /** Additional CSS classes for the controls container */\n className?: string;\n /** Callback with user coordinates when located */\n onLocate?: (coords: { longitude: number; latitude: number }) => void;\n};\n\nconst positionClasses = {\n \"top-left\": \"top-2 left-2\",\n \"top-right\": \"top-2 right-2\",\n \"bottom-left\": \"bottom-2 left-2\",\n \"bottom-right\": \"bottom-10 right-2\",\n};\n\nfunction ControlGroup({ children }: { children: React.ReactNode }) {\n return (\n <div className=\"border-border bg-background [&>button:not(:last-child)]:border-border flex flex-col overflow-hidden rounded-md border shadow-sm [&>button:not(:last-child)]:border-b\">\n {children}\n </div>\n );\n}\n\nfunction ControlButton({\n onClick,\n label,\n children,\n disabled = false,\n}: {\n onClick: () => void;\n label: string;\n children: React.ReactNode;\n disabled?: boolean;\n}) {\n return (\n <button\n onClick={onClick}\n aria-label={label}\n type=\"button\"\n className={cn(\n \"flex size-8 items-center justify-center transition-all\",\n \"first:rounded-t-md last:rounded-b-md\",\n \"hover:bg-accent dark:hover:bg-accent/40\",\n \"focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset\",\n \"disabled:pointer-events-none disabled:opacity-50\",\n )}\n disabled={disabled}\n >\n {children}\n </button>\n );\n}\n\nfunction MapControls({\n position = \"bottom-right\",\n showZoom = true,\n showCompass = false,\n showLocate = false,\n showFullscreen = false,\n className,\n onLocate,\n}: MapControlsProps) {\n const { map } = useMap();\n const [waitingForLocation, setWaitingForLocation] = useState(false);\n\n const handleZoomIn = useCallback(() => {\n map?.zoomTo(map.getZoom() + 1, { duration: 300 });\n }, [map]);\n\n const handleZoomOut = useCallback(() => {\n map?.zoomTo(map.getZoom() - 1, { duration: 300 });\n }, [map]);\n\n const handleResetBearing = useCallback(() => {\n map?.resetNorthPitch({ duration: 300 });\n }, [map]);\n\n const handleLocate = useCallback(() => {\n setWaitingForLocation(true);\n if (\"geolocation\" in navigator) {\n navigator.geolocation.getCurrentPosition(\n (pos) => {\n const coords = {\n longitude: pos.coords.longitude,\n latitude: pos.coords.latitude,\n };\n map?.flyTo({\n center: [coords.longitude, coords.latitude],\n zoom: 14,\n duration: 1500,\n });\n onLocate?.(coords);\n setWaitingForLocation(false);\n },\n (error) => {\n console.error(\"Error getting location:\", error);\n setWaitingForLocation(false);\n },\n );\n }\n }, [map, onLocate]);\n\n const handleFullscreen = useCallback(() => {\n const container = map?.getContainer();\n if (!container) return;\n if (document.fullscreenElement) {\n document.exitFullscreen();\n } else {\n container.requestFullscreen();\n }\n }, [map]);\n\n return (\n <div\n className={cn(\n \"absolute z-10 flex flex-col gap-1.5\",\n positionClasses[position],\n className,\n )}\n >\n {showZoom && (\n <ControlGroup>\n <ControlButton onClick={handleZoomIn} label=\"Zoom in\">\n <Plus className=\"size-4\" />\n </ControlButton>\n <ControlButton onClick={handleZoomOut} label=\"Zoom out\">\n <Minus className=\"size-4\" />\n </ControlButton>\n </ControlGroup>\n )}\n {showCompass && (\n <ControlGroup>\n <CompassButton onClick={handleResetBearing} />\n </ControlGroup>\n )}\n {showLocate && (\n <ControlGroup>\n <ControlButton\n onClick={handleLocate}\n label=\"Find my location\"\n disabled={waitingForLocation}\n >\n {waitingForLocation ? (\n <Loader2 className=\"size-4 animate-spin\" />\n ) : (\n <Locate className=\"size-4\" />\n )}\n </ControlButton>\n </ControlGroup>\n )}\n {showFullscreen && (\n <ControlGroup>\n <ControlButton onClick={handleFullscreen} label=\"Toggle fullscreen\">\n <Maximize className=\"size-4\" />\n </ControlButton>\n </ControlGroup>\n )}\n </div>\n );\n}\n\nfunction CompassButton({ onClick }: { onClick: () => void }) {\n const { map } = useMap();\n const compassRef = useRef<SVGSVGElement>(null);\n\n useEffect(() => {\n if (!map || !compassRef.current) return;\n\n const compass = compassRef.current;\n\n const updateRotation = () => {\n const bearing = map.getBearing();\n const pitch = map.getPitch();\n compass.style.transform = `rotateX(${pitch}deg) rotateZ(${-bearing}deg)`;\n };\n\n map.on(\"rotate\", updateRotation);\n map.on(\"pitch\", updateRotation);\n updateRotation();\n\n return () => {\n map.off(\"rotate\", updateRotation);\n map.off(\"pitch\", updateRotation);\n };\n }, [map]);\n\n return (\n <ControlButton onClick={onClick} label=\"Reset bearing to north\">\n <svg\n ref={compassRef}\n viewBox=\"0 0 24 24\"\n className=\"size-5 transition-transform duration-200\"\n style={{ transformStyle: \"preserve-3d\" }}\n >\n <path d=\"M12 2L16 12H12V2Z\" className=\"fill-red-500\" />\n <path d=\"M12 2L8 12H12V2Z\" className=\"fill-red-300\" />\n <path d=\"M12 22L16 12H12V22Z\" className=\"fill-muted-foreground/60\" />\n <path d=\"M12 22L8 12H12V22Z\" className=\"fill-muted-foreground/30\" />\n </svg>\n </ControlButton>\n );\n}\n\ntype MapPopupProps = {\n /** Longitude coordinate for popup position */\n longitude: number;\n /** Latitude coordinate for popup position */\n latitude: number;\n /** Callback when popup is closed */\n onClose?: () => void;\n /** Popup content */\n children: ReactNode;\n /** Additional CSS classes for the popup container */\n className?: string;\n /** Show a close button in the popup (default: false) */\n closeButton?: boolean;\n} & Omit<PopupOptions, \"className\" | \"closeButton\">;\n\nfunction MapPopup({\n longitude,\n latitude,\n onClose,\n children,\n className,\n closeButton = false,\n ...popupOptions\n}: MapPopupProps) {\n const { map } = useMap();\n const onCloseRef = useRef(onClose);\n onCloseRef.current = onClose;\n const container = useMemo(() => document.createElement(\"div\"), []);\n const { offset, maxWidth } = popupOptions;\n\n const popup = useMemo(() => {\n const popupInstance = new MapLibreGL.Popup({\n offset: 16,\n ...popupOptions,\n closeButton: false,\n })\n .setMaxWidth(\"none\")\n .setLngLat([longitude, latitude]);\n\n return popupInstance;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!map) return;\n\n const onCloseProp = () => onCloseRef.current?.();\n\n popup.on(\"close\", onCloseProp);\n\n popup.setDOMContent(container);\n popup.addTo(map);\n\n return () => {\n popup.off(\"close\", onCloseProp);\n if (popup.isOpen()) {\n popup.remove();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [map]);\n\n // Sync popup position and options when they change.\n useEffect(() => {\n const current = popup.getLngLat();\n if (!current || current.lng !== longitude || current.lat !== latitude) {\n popup.setLngLat([longitude, latitude]);\n }\n popup.setOffset(offset ?? 16);\n if (maxWidth) {\n popup.setMaxWidth(maxWidth);\n }\n }, [popup, longitude, latitude, offset, maxWidth]);\n\n const handleClose = () => {\n popup.remove();\n };\n\n return createPortal(\n <div\n className={cn(\n \"bg-popover text-popover-foreground relative max-w-62 rounded-md border p-3 shadow-md\",\n \"animate-in fade-in-0 zoom-in-95 duration-200 ease-out\",\n className,\n )}\n >\n {closeButton && <PopupCloseButton onClick={handleClose} />}\n {children}\n </div>,\n container,\n );\n}\n\ntype MapRouteProps = {\n /** Optional unique identifier for the route layer */\n id?: string;\n /** Array of [longitude, latitude] coordinate pairs defining the route */\n coordinates: [number, number][];\n /** Line color as CSS color value (default: \"#4285F4\") */\n color?: string;\n /** Line width in pixels (default: 3) */\n width?: number;\n /** Line opacity from 0 to 1 (default: 0.8) */\n opacity?: number;\n /** Dash pattern [dash length, gap length] for dashed lines */\n dashArray?: [number, number];\n /** Callback when the route line is clicked */\n onClick?: () => void;\n /** Callback when mouse enters the route line */\n onMouseEnter?: () => void;\n /** Callback when mouse leaves the route line */\n onMouseLeave?: () => void;\n /** Whether the route is interactive - shows pointer cursor on hover (default: true) */\n interactive?: boolean;\n};\n\nfunction MapRoute({\n id: propId,\n coordinates,\n color = \"#4285F4\",\n width = 3,\n opacity = 0.8,\n dashArray,\n onClick,\n onMouseEnter,\n onMouseLeave,\n interactive = true,\n}: MapRouteProps) {\n const { map, isLoaded } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `route-source-${id}`;\n const layerId = `route-layer-${id}`;\n\n // Add source and layer on mount\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data: {\n type: \"Feature\",\n properties: {},\n geometry: { type: \"LineString\", coordinates: [] },\n },\n });\n\n map.addLayer({\n id: layerId,\n type: \"line\",\n source: sourceId,\n layout: { \"line-join\": \"round\", \"line-cap\": \"round\" },\n paint: {\n \"line-color\": color,\n \"line-width\": width,\n \"line-opacity\": opacity,\n ...(dashArray && { \"line-dasharray\": dashArray }),\n },\n });\n\n return () => {\n try {\n if (map.getLayer(layerId)) map.removeLayer(layerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // When coordinates change, update the source data\n useEffect(() => {\n if (!isLoaded || !map || coordinates.length < 2) return;\n\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n if (source) {\n source.setData({\n type: \"Feature\",\n properties: {},\n geometry: { type: \"LineString\", coordinates },\n });\n }\n }, [isLoaded, map, coordinates, sourceId]);\n\n useEffect(() => {\n if (!isLoaded || !map || !map.getLayer(layerId)) return;\n\n map.setPaintProperty(layerId, \"line-color\", color);\n map.setPaintProperty(layerId, \"line-width\", width);\n map.setPaintProperty(layerId, \"line-opacity\", opacity);\n map.setPaintProperty(layerId, \"line-dasharray\", dashArray);\n }, [isLoaded, map, layerId, color, width, opacity, dashArray]);\n\n // Handle click and hover events\n useEffect(() => {\n if (!isLoaded || !map || !interactive) return;\n\n const handleClick = () => {\n onClick?.();\n };\n const handleMouseEnter = () => {\n map.getCanvas().style.cursor = \"pointer\";\n onMouseEnter?.();\n };\n const handleMouseLeave = () => {\n map.getCanvas().style.cursor = \"\";\n onMouseLeave?.();\n };\n\n map.on(\"click\", layerId, handleClick);\n map.on(\"mouseenter\", layerId, handleMouseEnter);\n map.on(\"mouseleave\", layerId, handleMouseLeave);\n\n return () => {\n map.off(\"click\", layerId, handleClick);\n map.off(\"mouseenter\", layerId, handleMouseEnter);\n map.off(\"mouseleave\", layerId, handleMouseLeave);\n };\n }, [\n isLoaded,\n map,\n layerId,\n onClick,\n onMouseEnter,\n onMouseLeave,\n interactive,\n ]);\n\n return null;\n}\n\ntype MapGeoJSONData<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> =\n | GeoJSON.FeatureCollection<GeoJSON.Geometry, P>\n | GeoJSON.Feature<GeoJSON.Geometry, P>\n | GeoJSON.Geometry\n | string;\n\ntype MapFillPaint = NonNullable<MapLibreGL.FillLayerSpecification[\"paint\"]>;\ntype MapLinePaint = NonNullable<MapLibreGL.LineLayerSpecification[\"paint\"]>;\n\n/** A rendered feature with strongly-typed `properties`. */\ntype MapGeoJSONFeature<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = Omit<MapLibreGL.MapGeoJSONFeature, \"properties\"> & { properties: P };\n\n/** Event payload passed to MapGeoJSON interaction callbacks. */\ntype MapGeoJSONEvent<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** The feature under the cursor, with its typed GeoJSON properties. */\n feature: MapGeoJSONFeature<P>;\n /** Longitude of the cursor at the time of the event. */\n longitude: number;\n /** Latitude of the cursor at the time of the event. */\n latitude: number;\n /** The underlying MapLibre mouse event for advanced use cases. */\n originalEvent: MapLibreGL.MapLayerMouseEvent;\n};\n\ntype MapGeoJSONProps<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** GeoJSON data (FeatureCollection, Feature, Geometry) or a URL to fetch it from. */\n data: MapGeoJSONData<P>;\n /** Optional unique identifier prefix for the source/layers. Auto-generated if not provided. */\n id?: string;\n /**\n * Feature property to promote to the feature `id`. Required for hover\n * feature-state (`fillHoverPaint`) and stable `onHover`/`onClick` payloads.\n */\n promoteId?: string;\n /**\n * Paint for the polygon fill layer. Merged on top of a theme-aware monochrome\n * surface tone (`fill-color`). Pass `false` to omit the fill layer entirely\n * (e.g. outlines only).\n */\n fillPaint?: MapFillPaint | false;\n /**\n * Paint for the outline layer. Merged on top of a hairline default\n * (`line-color` = a near-surface neutral, `line-width` = 0.5) for thin\n * separators. Override `line-color` if your container differs, or pass\n * `false` to omit the layer.\n */\n linePaint?: MapLinePaint | false;\n /**\n * Paint merged onto the fill layer for the feature under the cursor, applied\n * as a `case` expression keyed on hover feature-state. Requires `promoteId`.\n */\n fillHoverPaint?: MapFillPaint;\n /** Callback when a feature is clicked. */\n onClick?: (e: MapGeoJSONEvent<P>) => void;\n /** Callback fired when the hovered feature changes; `null` when the cursor leaves. */\n onHover?: (e: MapGeoJSONEvent<P> | null) => void;\n /** Whether features respond to mouse events (default: false). */\n interactive?: boolean;\n /** Optional MapLibre layer id to insert the layers before (z-order control). */\n beforeId?: string;\n};\n\n// Monochrome defaults: a neutral-gray fill (hex of the grayscale chart tokens)\n// with a fixed near-surface line for thin separators. Colors are hardcoded (not\n// theme tokens), tuned for a typical light/dark surface. Override via\n// `fillPaint` / `linePaint`.\nconst GEOJSON_DEFAULT_COLORS = {\n light: { fill: \"#d4d4d4\", line: \"#ffffff\" },\n dark: { fill: \"#404040\", line: \"#171717\" },\n} satisfies Record<Theme, { fill: string; line: string }>;\n\n/**\n * Renders arbitrary GeoJSON as fill + outline layers on the map. Composes like\n * `MapRoute` / `MapArc` — drop it inside `<Map>` (typically with `blank`) for\n * choropleths and region/data maps. For full control over expressions and\n * multiple layers, manage layers directly via `useMap()` instead.\n */\nfunction MapGeoJSON<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n>({\n data,\n id: propId,\n promoteId,\n fillPaint,\n linePaint,\n fillHoverPaint,\n onClick,\n onHover,\n interactive = false,\n beforeId,\n}: MapGeoJSONProps<P>) {\n const { map, isLoaded, resolvedTheme } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `geojson-source-${id}`;\n const fillLayerId = `geojson-fill-${id}`;\n const lineLayerId = `geojson-line-${id}`;\n\n const defaults = GEOJSON_DEFAULT_COLORS[resolvedTheme];\n\n const showFill = fillPaint !== false;\n const showLine = linePaint !== false;\n\n const mergedFillPaint = useMemo(\n () =>\n mergeHoverPaint(\n { \"fill-color\": defaults.fill, ...(fillPaint || {}) },\n fillHoverPaint,\n ),\n [defaults.fill, fillPaint, fillHoverPaint],\n );\n const mergedLinePaint = useMemo(\n () => ({\n \"line-color\": defaults.line,\n \"line-width\": 0.5,\n ...(linePaint || {}),\n }),\n [defaults.line, linePaint],\n );\n const latestRef = useRef({ onClick, onHover });\n latestRef.current = { onClick, onHover };\n\n // Add source on mount.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data,\n ...(promoteId ? { promoteId } : {}),\n });\n\n return () => {\n try {\n if (map.getLayer(lineLayerId)) map.removeLayer(lineLayerId);\n if (map.getLayer(fillLayerId)) map.removeLayer(fillLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // style may be mid-reload\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // Sync data when it changes.\n useEffect(() => {\n if (!isLoaded || !map) return;\n const source = map.getSource(sourceId) as\n | MapLibreGL.GeoJSONSource\n | undefined;\n source?.setData(data as never);\n }, [isLoaded, map, data, sourceId]);\n\n // Sync layers and paint when visibility or styling changes.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n const source = map.getSource(sourceId);\n if (!source) return;\n\n if (showFill && !map.getLayer(fillLayerId)) {\n map.addLayer(\n {\n id: fillLayerId,\n type: \"fill\",\n source: sourceId,\n paint: mergedFillPaint,\n },\n beforeId,\n );\n } else if (!showFill && map.getLayer(fillLayerId)) {\n map.removeLayer(fillLayerId);\n }\n\n if (showLine && !map.getLayer(lineLayerId)) {\n map.addLayer(\n {\n id: lineLayerId,\n type: \"line\",\n source: sourceId,\n paint: mergedLinePaint,\n },\n beforeId,\n );\n } else if (!showLine && map.getLayer(lineLayerId)) {\n map.removeLayer(lineLayerId);\n }\n\n if (showFill && map.getLayer(fillLayerId)) {\n for (const [key, value] of Object.entries(mergedFillPaint)) {\n map.setPaintProperty(\n fillLayerId,\n key as keyof MapFillPaint,\n value as never,\n );\n }\n }\n if (showLine && map.getLayer(lineLayerId)) {\n for (const [key, value] of Object.entries(mergedLinePaint)) {\n map.setPaintProperty(\n lineLayerId,\n key as keyof MapLinePaint,\n value as never,\n );\n }\n }\n }, [\n isLoaded,\n map,\n sourceId,\n fillLayerId,\n lineLayerId,\n showFill,\n showLine,\n mergedFillPaint,\n mergedLinePaint,\n beforeId,\n ]);\n\n // Interaction handlers (bound to the fill layer).\n useEffect(() => {\n if (!isLoaded || !map || !interactive || !showFill) return;\n\n let hoveredId: string | number | null = null;\n\n const setHover = (next: string | number | null) => {\n if (next === hoveredId) return;\n const sourceExists = !!map.getSource(sourceId);\n if (hoveredId != null && sourceExists) {\n map.setFeatureState(\n { source: sourceId, id: hoveredId },\n { hover: false },\n );\n }\n hoveredId = next;\n if (next != null && sourceExists) {\n map.setFeatureState({ source: sourceId, id: next }, { hover: true });\n }\n };\n\n const handleMouseMove = (e: MapLibreGL.MapLayerMouseEvent) => {\n const feature = e.features?.[0];\n if (!feature) return;\n map.getCanvas().style.cursor = \"pointer\";\n\n const featureId = feature.id;\n if (featureId === hoveredId) return;\n setHover(featureId ?? null);\n latestRef.current.onHover?.({\n feature: feature as unknown as MapGeoJSONFeature<P>,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n const handleMouseLeave = () => {\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n latestRef.current.onHover?.(null);\n };\n\n const handleClick = (e: MapLibreGL.MapLayerMouseEvent) => {\n const feature = e.features?.[0];\n if (!feature) return;\n latestRef.current.onClick?.({\n feature: feature as unknown as MapGeoJSONFeature<P>,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n map.on(\"mousemove\", fillLayerId, handleMouseMove);\n map.on(\"mouseleave\", fillLayerId, handleMouseLeave);\n map.on(\"click\", fillLayerId, handleClick);\n\n return () => {\n map.off(\"mousemove\", fillLayerId, handleMouseMove);\n map.off(\"mouseleave\", fillLayerId, handleMouseLeave);\n map.off(\"click\", fillLayerId, handleClick);\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n };\n }, [isLoaded, map, fillLayerId, sourceId, interactive, showFill]);\n\n return null;\n}\n\n/** A single arc to render inside <MapArc data={...}>. */\ntype MapArcDatum = {\n /** Unique identifier for this arc. Required for hover state tracking and event payloads. */\n id: string | number;\n /** Start coordinate as [longitude, latitude]. */\n from: [number, number];\n /** End coordinate as [longitude, latitude]. */\n to: [number, number];\n};\n\n/** Event payload passed to MapArc interaction callbacks. */\ntype MapArcEvent<T extends MapArcDatum = MapArcDatum> = {\n /** The arc datum that was hovered or clicked. */\n arc: T;\n /** Longitude of the cursor at the time of the event. */\n longitude: number;\n /** Latitude of the cursor at the time of the event. */\n latitude: number;\n /** The underlying MapLibre mouse event for advanced use cases. */\n originalEvent: MapLibreGL.MapMouseEvent;\n};\n\ntype MapArcLinePaint = NonNullable<MapLibreGL.LineLayerSpecification[\"paint\"]>;\ntype MapArcLineLayout = NonNullable<\n MapLibreGL.LineLayerSpecification[\"layout\"]\n>;\n\ntype MapArcProps<T extends MapArcDatum = MapArcDatum> = {\n /** Array of arcs to render. Each arc must have a unique `id`. */\n data: T[];\n /** Optional unique identifier prefix for the arc source/layers. Auto-generated if not provided. */\n id?: string;\n /**\n * How far each arc bows away from a straight line. `0` renders straight\n * lines; higher values bend further. Negative values bend to the opposite\n * side. Arcs are computed as a quadratic Bézier in lng/lat space; the\n * destination longitude is unwrapped relative to the origin so that arcs\n * cross the antimeridian via the shorter great-circle direction. (default: 0.2)\n */\n curvature?: number;\n /** Number of samples used to render each curve. Higher = smoother. (default: 64) */\n samples?: number;\n /**\n * MapLibre paint properties for the arc layer. Merged on top of sensible\n * defaults (`line-color: #4285F4`, `line-width: 2`, `line-opacity: 0.85`).\n * Any value can be a MapLibre expression for per-feature styling, every\n * field on each arc datum (besides `from`/`to`) is exposed via `[\"get\", ...]`.\n */\n paint?: MapArcLinePaint;\n /** MapLibre layout properties for the arc layer. Defaults to rounded joins/caps. */\n layout?: MapArcLineLayout;\n /**\n * Paint properties applied to the arc currently under the cursor. Each key\n * is merged into `paint` as a `case` expression keyed on per-feature hover\n * state, so only the hovered arc changes appearance.\n */\n hoverPaint?: MapArcLinePaint;\n /** Callback when an arc is clicked. */\n onClick?: (e: MapArcEvent<T>) => void;\n /**\n * Callback fired when the hovered arc changes. Receives the cursor's\n * lng/lat at the moment of entry, and `null` when the cursor leaves the\n * last hovered arc.\n */\n onHover?: (e: MapArcEvent<T> | null) => void;\n /** Whether arcs respond to mouse events (default: true). */\n interactive?: boolean;\n /** Optional MapLibre layer id to insert the arc layers before (z-order control). */\n beforeId?: string;\n};\n\nconst DEFAULT_ARC_CURVATURE = 0.2;\nconst DEFAULT_ARC_SAMPLES = 64;\nconst ARC_HIT_MIN_WIDTH = 12;\nconst ARC_HIT_PADDING = 6;\n\nconst DEFAULT_ARC_PAINT: MapArcLinePaint = {\n \"line-color\": \"#4285F4\",\n \"line-width\": 2,\n \"line-opacity\": 0.85,\n};\n\nconst DEFAULT_ARC_LAYOUT: MapArcLineLayout = {\n \"line-join\": \"round\",\n \"line-cap\": \"round\",\n};\n\nfunction buildArcCoordinates(\n from: [number, number],\n to: [number, number],\n curvature: number,\n samples: number,\n): [number, number][] {\n const [x0, y0] = from;\n const [xTo, y2] = to;\n // Unwrap the destination longitude so |dx| <= 180. This makes arcs that\n // straddle the antimeridian (e.g. Tokyo -> San Francisco) bow the short way\n // across the Pacific instead of the long way around the globe. Resulting\n // longitudes may fall outside [-180, 180]; MapLibre renders them correctly\n // on the globe projection, and on mercator when world copies are enabled.\n const rawDx = xTo - x0;\n const x2 = rawDx > 180 ? xTo - 360 : rawDx < -180 ? xTo + 360 : xTo;\n const dx = x2 - x0;\n const dy = y2 - y0;\n const distance = Math.hypot(dx, dy);\n\n if (distance === 0 || curvature === 0) return [from, [x2, y2]];\n\n const mx = (x0 + x2) / 2;\n const my = (y0 + y2) / 2;\n const nx = -dy / distance;\n const ny = dx / distance;\n const offset = distance * curvature;\n const cx = mx + nx * offset;\n const cy = my + ny * offset;\n\n const points: [number, number][] = [];\n const segments = Math.max(2, Math.floor(samples));\n for (let i = 0; i <= segments; i += 1) {\n const t = i / segments;\n const inv = 1 - t;\n const x = inv * inv * x0 + 2 * inv * t * cx + t * t * x2;\n const y = inv * inv * y0 + 2 * inv * t * cy + t * t * y2;\n points.push([x, y]);\n }\n return points;\n}\n\nfunction MapArc<T extends MapArcDatum = MapArcDatum>({\n data,\n id: propId,\n curvature = DEFAULT_ARC_CURVATURE,\n samples = DEFAULT_ARC_SAMPLES,\n paint,\n layout,\n hoverPaint,\n onClick,\n onHover,\n interactive = true,\n beforeId,\n}: MapArcProps<T>) {\n const { map, isLoaded } = useMap();\n const autoId = useId();\n const id = propId ?? autoId;\n const sourceId = `arc-source-${id}`;\n const layerId = `arc-layer-${id}`;\n const hitLayerId = `arc-hit-layer-${id}`;\n\n const mergedPaint = useMemo(\n () => mergeHoverPaint({ ...DEFAULT_ARC_PAINT, ...paint }, hoverPaint),\n [paint, hoverPaint],\n );\n const mergedLayout = useMemo(\n () => ({ ...DEFAULT_ARC_LAYOUT, ...layout }),\n [layout],\n );\n\n const hitWidth = useMemo(() => {\n const w = paint?.[\"line-width\"] ?? DEFAULT_ARC_PAINT[\"line-width\"];\n const base = typeof w === \"number\" ? w : ARC_HIT_MIN_WIDTH;\n return Math.max(base + ARC_HIT_PADDING, ARC_HIT_MIN_WIDTH);\n }, [paint]);\n\n const geoJSON = useMemo<GeoJSON.FeatureCollection<GeoJSON.LineString>>(\n () => ({\n type: \"FeatureCollection\",\n features: data.map((arc) => {\n const { from, to, ...properties } = arc;\n return {\n type: \"Feature\",\n properties,\n geometry: {\n type: \"LineString\",\n coordinates: buildArcCoordinates(from, to, curvature, samples),\n },\n };\n }),\n }),\n [data, curvature, samples],\n );\n\n const latestRef = useRef({ data, onClick, onHover });\n latestRef.current = { data, onClick, onHover };\n\n // Add source and layers on mount.\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n map.addSource(sourceId, {\n type: \"geojson\",\n data: geoJSON,\n promoteId: \"id\",\n });\n\n map.addLayer(\n {\n id: hitLayerId,\n type: \"line\",\n source: sourceId,\n layout: DEFAULT_ARC_LAYOUT,\n paint: {\n \"line-color\": \"rgba(0, 0, 0, 0)\",\n \"line-width\": hitWidth,\n \"line-opacity\": 1,\n },\n },\n beforeId,\n );\n\n map.addLayer(\n {\n id: layerId,\n type: \"line\",\n source: sourceId,\n layout: mergedLayout,\n paint: mergedPaint,\n },\n beforeId,\n );\n\n return () => {\n try {\n if (map.getLayer(layerId)) map.removeLayer(layerId);\n if (map.getLayer(hitLayerId)) map.removeLayer(hitLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map]);\n\n // Sync features when data / curvature / samples change.\n useEffect(() => {\n if (!isLoaded || !map) return;\n const source = map.getSource(sourceId) as\n | MapLibreGL.GeoJSONSource\n | undefined;\n source?.setData(geoJSON);\n }, [isLoaded, map, geoJSON, sourceId]);\n\n // Sync paint/layout when they change.\n useEffect(() => {\n if (!isLoaded || !map || !map.getLayer(layerId)) return;\n for (const [key, value] of Object.entries(mergedPaint)) {\n map.setPaintProperty(\n layerId,\n key as keyof MapArcLinePaint,\n value as never,\n );\n }\n for (const [key, value] of Object.entries(mergedLayout)) {\n map.setLayoutProperty(\n layerId,\n key as keyof MapArcLineLayout,\n value as never,\n );\n }\n if (map.getLayer(hitLayerId)) {\n map.setPaintProperty(hitLayerId, \"line-width\", hitWidth);\n }\n }, [isLoaded, map, layerId, hitLayerId, mergedPaint, mergedLayout, hitWidth]);\n\n // Interaction handlers\n useEffect(() => {\n if (!isLoaded || !map || !interactive) return;\n\n let hoveredId: string | number | null = null;\n\n const setHover = (next: string | number | null) => {\n if (next === hoveredId) return;\n const sourceExists = !!map.getSource(sourceId);\n if (hoveredId != null && sourceExists) {\n map.setFeatureState(\n { source: sourceId, id: hoveredId },\n { hover: false },\n );\n }\n hoveredId = next;\n if (next != null && sourceExists) {\n map.setFeatureState({ source: sourceId, id: next }, { hover: true });\n }\n };\n\n const findArc = (featureId: string | number | undefined) =>\n featureId == null\n ? undefined\n : latestRef.current.data.find(\n (arc) => String(arc.id) === String(featureId),\n );\n\n const handleMouseMove = (e: MapLibreGL.MapLayerMouseEvent) => {\n const featureId = e.features?.[0]?.id as string | number | undefined;\n if (featureId == null || featureId === hoveredId) return;\n\n setHover(featureId);\n map.getCanvas().style.cursor = \"pointer\";\n\n const arc = findArc(featureId);\n if (arc) {\n latestRef.current.onHover?.({\n arc: arc as T,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n }\n };\n\n const handleMouseLeave = () => {\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n latestRef.current.onHover?.(null);\n };\n\n const handleClick = (e: MapLibreGL.MapLayerMouseEvent) => {\n const arc = findArc(e.features?.[0]?.id as string | number | undefined);\n if (!arc) return;\n latestRef.current.onClick?.({\n arc: arc as T,\n longitude: e.lngLat.lng,\n latitude: e.lngLat.lat,\n originalEvent: e,\n });\n };\n\n map.on(\"mousemove\", hitLayerId, handleMouseMove);\n map.on(\"mouseleave\", hitLayerId, handleMouseLeave);\n map.on(\"click\", hitLayerId, handleClick);\n\n return () => {\n map.off(\"mousemove\", hitLayerId, handleMouseMove);\n map.off(\"mouseleave\", hitLayerId, handleMouseLeave);\n map.off(\"click\", hitLayerId, handleClick);\n setHover(null);\n map.getCanvas().style.cursor = \"\";\n };\n }, [isLoaded, map, hitLayerId, sourceId, interactive]);\n\n return null;\n}\n\ntype MapClusterLayerProps<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n> = {\n /** GeoJSON FeatureCollection data or URL to fetch GeoJSON from */\n data: string | GeoJSON.FeatureCollection<GeoJSON.Point, P>;\n /** Maximum zoom level to cluster points on (default: 14) */\n clusterMaxZoom?: number;\n /** Radius of each cluster when clustering points in pixels (default: 50) */\n clusterRadius?: number;\n /** Colors for cluster circles: [small, medium, large] based on point count (default: [\"#22c55e\", \"#eab308\", \"#ef4444\"]) */\n clusterColors?: [string, string, string];\n /** Point count thresholds for color/size steps: [medium, large] (default: [100, 750]) */\n clusterThresholds?: [number, number];\n /** Color for unclustered individual points (default: \"#3b82f6\") */\n pointColor?: string;\n /** Callback when an unclustered point is clicked */\n onPointClick?: (\n feature: GeoJSON.Feature<GeoJSON.Point, P>,\n coordinates: [number, number],\n ) => void;\n /** Callback when a cluster is clicked. If not provided, zooms into the cluster */\n onClusterClick?: (\n clusterId: number,\n coordinates: [number, number],\n pointCount: number,\n ) => void;\n};\n\nconst DEFAULT_CLUSTER_COLORS: [string, string, string] = [\n \"#22c55e\",\n \"#eab308\",\n \"#ef4444\",\n];\nconst DEFAULT_CLUSTER_THRESHOLDS: [number, number] = [100, 750];\n\nfunction MapClusterLayer<\n P extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,\n>({\n data,\n clusterMaxZoom = 14,\n clusterRadius = 50,\n clusterColors = DEFAULT_CLUSTER_COLORS,\n clusterThresholds = DEFAULT_CLUSTER_THRESHOLDS,\n pointColor = \"#3b82f6\",\n onPointClick,\n onClusterClick,\n}: MapClusterLayerProps<P>) {\n const { map, isLoaded } = useMap();\n const id = useId();\n const sourceId = `cluster-source-${id}`;\n const clusterLayerId = `clusters-${id}`;\n const clusterCountLayerId = `cluster-count-${id}`;\n const unclusteredLayerId = `unclustered-point-${id}`;\n\n const stylePropsRef = useRef({\n clusterColors,\n clusterThresholds,\n pointColor,\n });\n\n // Add source and layers on mount\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n // Add clustered GeoJSON source\n map.addSource(sourceId, {\n type: \"geojson\",\n data,\n cluster: true,\n clusterMaxZoom,\n clusterRadius,\n });\n\n // Add cluster circles layer\n map.addLayer({\n id: clusterLayerId,\n type: \"circle\",\n source: sourceId,\n filter: [\"has\", \"point_count\"],\n paint: {\n \"circle-color\": [\n \"step\",\n [\"get\", \"point_count\"],\n clusterColors[0],\n clusterThresholds[0],\n clusterColors[1],\n clusterThresholds[1],\n clusterColors[2],\n ],\n \"circle-radius\": [\n \"step\",\n [\"get\", \"point_count\"],\n 20,\n clusterThresholds[0],\n 30,\n clusterThresholds[1],\n 40,\n ],\n \"circle-stroke-width\": 1,\n \"circle-stroke-color\": \"#fff\",\n \"circle-opacity\": 0.85,\n },\n });\n\n // Add cluster count text layer\n map.addLayer({\n id: clusterCountLayerId,\n type: \"symbol\",\n source: sourceId,\n filter: [\"has\", \"point_count\"],\n layout: {\n \"text-field\": \"{point_count_abbreviated}\",\n \"text-font\": [\"Open Sans\"],\n \"text-size\": 12,\n },\n paint: {\n \"text-color\": \"#fff\",\n },\n });\n\n // Add unclustered point layer\n map.addLayer({\n id: unclusteredLayerId,\n type: \"circle\",\n source: sourceId,\n filter: [\"!\", [\"has\", \"point_count\"]],\n paint: {\n \"circle-color\": pointColor,\n \"circle-radius\": 5,\n \"circle-stroke-width\": 2,\n \"circle-stroke-color\": \"#fff\",\n },\n });\n\n return () => {\n try {\n if (map.getLayer(clusterCountLayerId))\n map.removeLayer(clusterCountLayerId);\n if (map.getLayer(unclusteredLayerId))\n map.removeLayer(unclusteredLayerId);\n if (map.getLayer(clusterLayerId)) map.removeLayer(clusterLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n } catch {\n // ignore\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLoaded, map, sourceId]);\n\n // Update source data when data prop changes (only for non-URL data)\n useEffect(() => {\n if (!isLoaded || !map || typeof data === \"string\") return;\n\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n if (source) {\n source.setData(data);\n }\n }, [isLoaded, map, data, sourceId]);\n\n // Update layer styles when props change\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n const prev = stylePropsRef.current;\n const colorsChanged =\n prev.clusterColors !== clusterColors ||\n prev.clusterThresholds !== clusterThresholds;\n\n // Update cluster layer colors and sizes\n if (map.getLayer(clusterLayerId) && colorsChanged) {\n map.setPaintProperty(clusterLayerId, \"circle-color\", [\n \"step\",\n [\"get\", \"point_count\"],\n clusterColors[0],\n clusterThresholds[0],\n clusterColors[1],\n clusterThresholds[1],\n clusterColors[2],\n ]);\n map.setPaintProperty(clusterLayerId, \"circle-radius\", [\n \"step\",\n [\"get\", \"point_count\"],\n 20,\n clusterThresholds[0],\n 30,\n clusterThresholds[1],\n 40,\n ]);\n }\n\n // Update unclustered point layer color\n if (map.getLayer(unclusteredLayerId) && prev.pointColor !== pointColor) {\n map.setPaintProperty(unclusteredLayerId, \"circle-color\", pointColor);\n }\n\n stylePropsRef.current = { clusterColors, clusterThresholds, pointColor };\n }, [\n isLoaded,\n map,\n clusterLayerId,\n unclusteredLayerId,\n clusterColors,\n clusterThresholds,\n pointColor,\n ]);\n\n // Handle click events\n useEffect(() => {\n if (!isLoaded || !map) return;\n\n // Cluster click handler - zoom into cluster\n const handleClusterClick = async (\n e: MapLibreGL.MapMouseEvent & {\n features?: MapLibreGL.MapGeoJSONFeature[];\n },\n ) => {\n const features = map.queryRenderedFeatures(e.point, {\n layers: [clusterLayerId],\n });\n if (!features.length) return;\n\n const feature = features[0];\n const clusterId = feature.properties?.cluster_id as number;\n const pointCount = feature.properties?.point_count as number;\n const coordinates = (feature.geometry as GeoJSON.Point).coordinates as [\n number,\n number,\n ];\n\n if (onClusterClick) {\n onClusterClick(clusterId, coordinates, pointCount);\n } else {\n // Default behavior: zoom to cluster expansion zoom\n const source = map.getSource(sourceId) as MapLibreGL.GeoJSONSource;\n const zoom = await source.getClusterExpansionZoom(clusterId);\n map.easeTo({\n center: coordinates,\n zoom,\n });\n }\n };\n\n // Unclustered point click handler\n const handlePointClick = (\n e: MapLibreGL.MapMouseEvent & {\n features?: MapLibreGL.MapGeoJSONFeature[];\n },\n ) => {\n if (!onPointClick || !e.features?.length) return;\n\n const feature = e.features[0];\n const coordinates = (\n feature.geometry as GeoJSON.Point\n ).coordinates.slice() as [number, number];\n\n // Handle world copies\n while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {\n coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;\n }\n\n onPointClick(\n feature as unknown as GeoJSON.Feature<GeoJSON.Point, P>,\n coordinates,\n );\n };\n\n // Cursor style handlers\n const handleMouseEnterCluster = () => {\n map.getCanvas().style.cursor = \"pointer\";\n };\n const handleMouseLeaveCluster = () => {\n map.getCanvas().style.cursor = \"\";\n };\n const handleMouseEnterPoint = () => {\n if (onPointClick) {\n map.getCanvas().style.cursor = \"pointer\";\n }\n };\n const handleMouseLeavePoint = () => {\n map.getCanvas().style.cursor = \"\";\n };\n\n map.on(\"click\", clusterLayerId, handleClusterClick);\n map.on(\"click\", unclusteredLayerId, handlePointClick);\n map.on(\"mouseenter\", clusterLayerId, handleMouseEnterCluster);\n map.on(\"mouseleave\", clusterLayerId, handleMouseLeaveCluster);\n map.on(\"mouseenter\", unclusteredLayerId, handleMouseEnterPoint);\n map.on(\"mouseleave\", unclusteredLayerId, handleMouseLeavePoint);\n\n return () => {\n map.off(\"click\", clusterLayerId, handleClusterClick);\n map.off(\"click\", unclusteredLayerId, handlePointClick);\n map.off(\"mouseenter\", clusterLayerId, handleMouseEnterCluster);\n map.off(\"mouseleave\", clusterLayerId, handleMouseLeaveCluster);\n map.off(\"mouseenter\", unclusteredLayerId, handleMouseEnterPoint);\n map.off(\"mouseleave\", unclusteredLayerId, handleMouseLeavePoint);\n };\n }, [\n isLoaded,\n map,\n clusterLayerId,\n unclusteredLayerId,\n sourceId,\n onClusterClick,\n onPointClick,\n ]);\n\n return null;\n}\n\nexport {\n Map,\n useMap,\n MapMarker,\n MarkerContent,\n MarkerPopup,\n MarkerTooltip,\n MarkerLabel,\n MapPopup,\n MapControls,\n MapRoute,\n MapArc,\n MapGeoJSON,\n MapClusterLayer,\n};\n\nexport type { MapRef, MapViewport, MapArcDatum, MapArcEvent, MapGeoJSONEvent };\n",
"type": "registry:ui",
"target": "components/ui/map.tsx"
}
diff --git a/public/r/registry.json b/public/r/registry.json
index 87a22ac..ea811a2 100644
--- a/public/r/registry.json
+++ b/public/r/registry.json
@@ -326,6 +326,11 @@
"path": "src/registry/blocks/delivery-tracker/page.tsx",
"type": "registry:page",
"target": "app/delivery/page.tsx"
+ },
+ {
+ "path": "src/registry/blocks/delivery-tracker/data.ts",
+ "type": "registry:component",
+ "target": "app/delivery/data.ts"
}
],
"categories": [
@@ -333,7 +338,7 @@
"delivery"
],
"meta": {
- "iframeHeight": "680px"
+ "iframeHeight": "720px"
}
}
]
diff --git a/public/r/store-locator.json b/public/r/store-locator.json
index 1fc054b..4972bea 100644
--- a/public/r/store-locator.json
+++ b/public/r/store-locator.json
@@ -32,7 +32,7 @@
},
{
"path": "src/registry/blocks/store-locator/components/locator-map.tsx",
- "content": "\"use client\";\n\nimport { useEffect } from \"react\";\nimport { Clock, MapPin, Phone } from \"lucide-react\";\n\nimport {\n Map,\n MapControls,\n MapMarker,\n MapPopup,\n MarkerContent,\n MarkerTooltip,\n useMap,\n} from \"@/components/ui/map\";\nimport { SidebarTrigger } from \"@/components/ui/sidebar\";\nimport { cn } from \"@/lib/utils\";\nimport type { Store } from \"../data\";\n\ninterface LocatorMapProps {\n stores: Store[];\n selectedId: string | null;\n onSelect: (id: string) => void;\n onClearSelection: () => void;\n center: [number, number];\n}\n\nfunction FlyToSelected({ store }: { store?: Store }) {\n const { map } = useMap();\n\n useEffect(() => {\n if (!map || !store) return;\n map.flyTo({\n center: [store.lng, store.lat],\n zoom: 14,\n duration: 800,\n essential: true,\n });\n }, [map, store]);\n\n return null;\n}\n\nfunction StorePin({ active }: { active: boolean }) {\n return (\n <div\n className={cn(\n \"text-background flex items-center justify-center rounded-full shadow-md transition-all\",\n active\n ? \"bg-foreground/80 size-9 scale-110\"\n : \"bg-foreground hover:bg-muted-foreground size-7\",\n )}\n >\n <MapPin className={cn(active ? \"size-4.5\" : \"size-3.5\")} />\n </div>\n );\n}\n\nexport function LocatorMap({\n stores,\n selectedId,\n onSelect,\n onClearSelection,\n center,\n}: LocatorMapProps) {\n const selected = stores.find((store) => store.id === selectedId);\n\n return (\n <div className=\"relative h-full\">\n <SidebarTrigger className=\"bg-background absolute top-3 left-3 z-10 border shadow-sm md:hidden\" />\n\n <Map center={center} zoom={12} minZoom={10} maxZoom={17}>\n <MapControls showFullscreen />\n <FlyToSelected store={selected} />\n\n {stores.map((store) => (\n <MapMarker\n key={store.id}\n longitude={store.lng}\n latitude={store.lat}\n onClick={() => onSelect(store.id)}\n >\n <MarkerContent>\n <StorePin active={store.id === selectedId} />\n </MarkerContent>\n <MarkerTooltip\n offset={24}\n className=\"bg-foreground text-background\"\n >\n {store.name}\n </MarkerTooltip>\n </MapMarker>\n ))}\n\n {selected && (\n <MapPopup\n longitude={selected.lng}\n latitude={selected.lat}\n offset={26}\n closeButton\n closeOnClick={false}\n onClose={onClearSelection}\n className=\"min-w-56\"\n focusAfterOpen={false}\n >\n <p className=\"text-popover-foreground pr-5 font-medium\">\n {selected.name}\n </p>\n <span\n className={cn(\n \"mt-1 flex items-center gap-1.5 text-xs font-medium\",\n selected.openNow ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n <span\n className={cn(\n \"size-1.5 rounded-full\",\n selected.openNow ? \"bg-emerald-500\" : \"bg-neutral-500\",\n )}\n />\n {selected.openNow ? \"Open now\" : \"Closed\"}\n </span>\n\n <div className=\"text-muted-foreground mt-2.5 space-y-1.5 text-xs tabular-nums\">\n <p className=\"flex items-center gap-1.5\">\n <MapPin className=\"size-3.5 shrink-0\" />\n {selected.address}, {selected.neighborhood}\n </p>\n <p className=\"flex items-center gap-1.5\">\n <Clock className=\"size-3.5 shrink-0\" />\n {selected.hours}\n </p>\n <p className=\"flex items-center gap-1.5\">\n <Phone className=\"size-3.5 shrink-0\" />\n {selected.phone}\n </p>\n </div>\n </MapPopup>\n )}\n </Map>\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { useEffect } from \"react\";\nimport { Clock, MapPin, Phone } from \"lucide-react\";\n\nimport {\n Map,\n MapControls,\n MapMarker,\n MapPopup,\n MarkerContent,\n MarkerTooltip,\n useMap,\n} from \"@/components/ui/map\";\nimport { SidebarTrigger } from \"@/components/ui/sidebar\";\nimport { cn } from \"@/lib/utils\";\nimport type { Store } from \"../data\";\n\ninterface LocatorMapProps {\n stores: Store[];\n selectedId: string | null;\n onSelect: (id: string) => void;\n onClearSelection: () => void;\n center: [number, number];\n}\n\nfunction FlyToSelected({ store }: { store?: Store }) {\n const { map } = useMap();\n\n useEffect(() => {\n if (!map || !store) return;\n map.flyTo({\n center: [store.lng, store.lat],\n zoom: 14,\n duration: 800,\n essential: true,\n });\n }, [map, store]);\n\n return null;\n}\n\nfunction StorePin({ active }: { active: boolean }) {\n return (\n <div\n className={cn(\n \"text-background flex items-center justify-center rounded-full shadow-md transition-all\",\n active\n ? \"bg-foreground/80 size-9 scale-110\"\n : \"bg-foreground hover:bg-muted-foreground size-7\",\n )}\n >\n <MapPin className={cn(active ? \"size-4.5\" : \"size-3.5\")} />\n </div>\n );\n}\n\nexport function LocatorMap({\n stores,\n selectedId,\n onSelect,\n onClearSelection,\n center,\n}: LocatorMapProps) {\n const selected = stores.find((store) => store.id === selectedId);\n\n return (\n <div className=\"relative h-full\">\n <SidebarTrigger className=\"bg-background absolute top-3 left-3 z-10 border shadow-sm md:hidden\" />\n\n <Map center={center} zoom={12} minZoom={10} maxZoom={17}>\n <MapControls showFullscreen showCompass />\n <FlyToSelected store={selected} />\n\n {stores.map((store) => (\n <MapMarker\n key={store.id}\n longitude={store.lng}\n latitude={store.lat}\n onClick={() => onSelect(store.id)}\n >\n <MarkerContent>\n <StorePin active={store.id === selectedId} />\n </MarkerContent>\n <MarkerTooltip\n offset={24}\n className=\"bg-foreground text-background\"\n >\n {store.name}\n </MarkerTooltip>\n </MapMarker>\n ))}\n\n {selected && (\n <MapPopup\n longitude={selected.lng}\n latitude={selected.lat}\n offset={26}\n closeButton\n closeOnClick={false}\n onClose={onClearSelection}\n className=\"min-w-56\"\n focusAfterOpen={false}\n >\n <p className=\"text-popover-foreground pr-5 font-medium\">\n {selected.name}\n </p>\n <span\n className={cn(\n \"mt-1 flex items-center gap-1.5 text-xs font-medium\",\n selected.openNow ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n <span\n className={cn(\n \"size-1.5 rounded-full\",\n selected.openNow ? \"bg-emerald-500\" : \"bg-neutral-500\",\n )}\n />\n {selected.openNow ? \"Open now\" : \"Closed\"}\n </span>\n\n <div className=\"text-muted-foreground mt-2.5 space-y-1.5 text-xs tabular-nums\">\n <p className=\"flex items-center gap-1.5\">\n <MapPin className=\"size-3.5 shrink-0\" />\n {selected.address}, {selected.neighborhood}\n </p>\n <p className=\"flex items-center gap-1.5\">\n <Clock className=\"size-3.5 shrink-0\" />\n {selected.hours}\n </p>\n <p className=\"flex items-center gap-1.5\">\n <Phone className=\"size-3.5 shrink-0\" />\n {selected.phone}\n </p>\n </div>\n </MapPopup>\n )}\n </Map>\n </div>\n );\n}\n",
"type": "registry:component",
"target": "app/store-locator/components/locator-map.tsx"
}
diff --git a/registry.json b/registry.json
index a330859..ea811a2 100644
--- a/registry.json
+++ b/registry.json
@@ -326,6 +326,11 @@
"path": "src/registry/blocks/delivery-tracker/page.tsx",
"type": "registry:page",
"target": "app/delivery/page.tsx"
+ },
+ {
+ "path": "src/registry/blocks/delivery-tracker/data.ts",
+ "type": "registry:component",
+ "target": "app/delivery/data.ts"
}
],
"categories": [
diff --git a/src/registry/blocks/analytics-map/data.ts b/src/registry/blocks/analytics-map/data.ts
index ef95e53..6643971 100644
--- a/src/registry/blocks/analytics-map/data.ts
+++ b/src/registry/blocks/analytics-map/data.ts
@@ -70,7 +70,7 @@ export const usersPerDay = [
export const usersPerDayChartConfig = {
users: {
label: "Users",
- color: "var(--chart-1)",
+ color: "var(--chart-2)",
},
} satisfies ChartConfig;
diff --git a/src/registry/blocks/choropleth/data.ts b/src/registry/blocks/choropleth/data.ts
index 05185e2..9da86fd 100644
--- a/src/registry/blocks/choropleth/data.ts
+++ b/src/registry/blocks/choropleth/data.ts
@@ -42,13 +42,13 @@ export const mapConfig = {
scaleStops: [0, 25, 50, 75, 100] as const,
colors: {
light: {
- base: "#eef0f3",
- ramp: ["#d4d4d4", "#737373", "#525252", "#404040"],
+ base: "#f0f0f0",
+ ramp: ["#d4d4d4", "#a3a3a3", "#737373", "#404040"],
hover: "#0a0a0a",
},
dark: {
base: "#2a2a2a",
- ramp: ["#404040", "#525252", "#737373", "#d4d4d4"],
+ ramp: ["#404040", "#737373", "#a3a3a3", "#d4d4d4"],
hover: "#ffffff",
},
} satisfies Record<Theme, ChoroplethColors>,
diff --git a/src/registry/blocks/delivery-tracker/data.ts b/src/registry/blocks/delivery-tracker/data.ts
new file mode 100644
index 0000000..2649969
--- /dev/null
+++ b/src/registry/blocks/delivery-tracker/data.ts
@@ -0,0 +1,57 @@
+export interface DeliveryMeal {
+ name: string;
+ price: string;
+ quantity: number;
+}
+
+export interface OsrmRouteData {
+ coordinates: [number, number][];
+ duration: number;
+ distance: number;
+}
+
+export const deliveryMeals: DeliveryMeal[] = [
+ { name: "Spicy Tofu Grain Bowl", price: "$44.00", quantity: 1 },
+ { name: "Herb Chicken Rice Box", price: "$58.00", quantity: 2 },
+ { name: "Roasted Veggie Wrap", price: "$29.00", quantity: 1 },
+];
+
+/** Pickup (origin) and dropoff (destination) coordinates. */
+export const pickup = { lng: -122.4185, lat: 37.7645 };
+export const dropoff = { lng: -122.434, lat: 37.7475 };
+
+/** Initial map viewport. */
+export const mapView = {
+ center: [-122.4263, 37.756] as [number, number],
+ zoom: 13.6,
+ minZoom: 12,
+ maxZoom: 15,
+};
+
+/** Fraction of the route the courier has already covered (0–1). */
+export const progressFraction = 0.62;
+
+/**
+ * OSRM demo routing endpoint. Swap in your own routing service by returning a
+ * URL that responds with GeoJSON route geometry.
+ */
+export function buildRouteUrl(
+ from: { lng: number; lat: number },
+ to: { lng: number; lat: number },
+) {
+ return `https://router.project-osrm.org/route/v1/driving/${from.lng},${from.lat};${to.lng},${to.lat}?overview=full&geometries=geojson`;
+}
+
+/**
+ * Route line styling. WebGL paint can't read CSS variables, so colors are
+ * concrete hex. `progress` highlights the covered path; `remaining` is themed
+ * for the road still ahead.
+ */
+export const routeStyle = {
+ progress: { color: "#3b82f6", width: 6, opacity: 0.95 },
+ remaining: {
+ width: 5.2,
+ opacity: 0.5,
+ color: { light: "#6b7280", dark: "#9ca3af" },
+ },
+} as const;
diff --git a/src/registry/blocks/delivery-tracker/page.tsx b/src/registry/blocks/delivery-tracker/page.tsx
index 07d6e01..183505c 100644
--- a/src/registry/blocks/delivery-tracker/page.tsx
+++ b/src/registry/blocks/delivery-tracker/page.tsx
@@ -2,51 +2,22 @@
import { useEffect, useMemo, useState } from "react";
import { useTheme } from "next-themes";
-import { Clock3, Utensils, Truck, UserRound } from "lucide-react";
+import { Clock3, House, Store, Utensils, Truck, UserRound } from "lucide-react";
-import {
- Map,
- MapMarker,
- MapRoute,
- MarkerContent,
- MarkerTooltip,
-} from "@/registry/map";
+import { Map, MapMarker, MapRoute, MarkerContent } from "@/registry/map";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
-
-interface DeliveryMeal {
- name: string;
- price: string;
- quantity: number;
-}
-
-interface OsrmRouteData {
- coordinates: [number, number][];
- duration: number;
- distance: number;
-}
-
-const deliveryMeals: DeliveryMeal[] = [
- {
- name: "Spicy Tofu Grain Bowl",
- price: "$44.00",
- quantity: 1,
- },
- {
- name: "Herb Chicken Rice Box",
- price: "$58.00",
- quantity: 2,
- },
- {
- name: "Roasted Veggie Wrap",
- price: "$29.00",
- quantity: 1,
- },
-];
-
-const pickup = { lng: -122.4185, lat: 37.7645 };
-const dropoff = { lng: -122.434, lat: 37.7475 };
+import {
+ buildRouteUrl,
+ deliveryMeals,
+ dropoff,
+ mapView,
+ pickup,
+ progressFraction,
+ routeStyle,
+ type OsrmRouteData,
+} from "./data";
function formatDistance(meters?: number) {
if (!meters) return "--";
@@ -67,15 +38,16 @@ export default function Page() {
const [routeData, setRouteData] = useState<OsrmRouteData | null>(null);
const [loading, setLoading] = useState(true);
const { resolvedTheme } = useTheme();
- const remainingRouteColor = resolvedTheme === "dark" ? "#9ca3af" : "#6b7280";
+ const remainingRouteColor =
+ resolvedTheme === "dark"
+ ? routeStyle.remaining.color.dark
+ : routeStyle.remaining.color.light;
useEffect(() => {
async function fetchRoute() {
setLoading(true);
try {
- const response = await fetch(
- `https://router.project-osrm.org/route/v1/driving/${pickup.lng},${pickup.lat};${dropoff.lng},${dropoff.lat}?overview=full&geometries=geojson`,
- );
+ const response = await fetch(buildRouteUrl(pickup, dropoff));
const data = await response.json();
const route = data?.routes?.[0];
if (!route?.geometry?.coordinates) return;
@@ -96,12 +68,8 @@ export default function Page() {
}, []);
const progressCoordinates = useMemo(() => {
- const progressCount = Math.max(
- 2,
- Math.floor(
- (routeData?.coordinates?.length ?? 0) * (routeData ? 0.62 : 0.66),
- ),
- );
+ const total = routeData?.coordinates?.length ?? 0;
+ const progressCount = Math.max(2, Math.floor(total * progressFraction));
return routeData?.coordinates?.slice(0, progressCount) ?? [];
}, [routeData]);
@@ -169,6 +137,10 @@ export default function Page() {
</p>
<p className="text-sm font-medium">
{formatDuration(routeData?.duration)}
+ <span className="text-muted-foreground font-normal">
+ {" · "}
+ {formatDistance(routeData?.distance)}
+ </span>
</p>
</CardContent>
</Card>
@@ -189,25 +161,25 @@ export default function Page() {
<div className="relative h-[450px] overflow-hidden rounded-xl shadow-sm md:h-full">
<Map
loading={loading}
- center={[-122.4263, 37.756]}
- zoom={13.6}
- minZoom={12}
- maxZoom={15}
+ center={mapView.center}
+ zoom={mapView.zoom}
+ minZoom={mapView.minZoom}
+ maxZoom={mapView.maxZoom}
>
<MapRoute
id="delivery-full-route"
coordinates={routeData?.coordinates ?? []}
color={remainingRouteColor}
- width={5.2}
- opacity={0.5}
+ width={routeStyle.remaining.width}
+ opacity={routeStyle.remaining.opacity}
interactive={false}
/>
<MapRoute
id="delivery-progress-route"
coordinates={progressCoordinates}
- color="#3b82f6"
- width={6}
- opacity={0.95}
+ color={routeStyle.progress.color}
+ width={routeStyle.progress.width}
+ opacity={routeStyle.progress.opacity}
interactive={false}
/>
@@ -218,35 +190,34 @@ export default function Page() {
offset={[0, 10]}
>
<MarkerContent>
- <div className="relative grid size-9 place-items-center rounded-full bg-blue-500 shadow-md dark:bg-blue-600">
+ <div
+ className="relative grid size-9 place-items-center rounded-full shadow-md"
+ style={{ backgroundColor: routeStyle.progress.color }}
+ >
<Truck className="size-4 text-white" />
+ <div className="bg-popover text-popover-foreground absolute bottom-full left-1/2 mb-2.5 -translate-x-1/2 rounded-md border px-2 py-1 text-xs font-medium whitespace-nowrap shadow-md">
+ {formatDuration(routeData?.duration)} away
+ <span className="bg-popover absolute top-full left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rotate-45 border-r border-b" />
+ </div>
</div>
</MarkerContent>
- <MarkerTooltip>
- <div className="space-y-0.5 text-xs">
- <p className="font-medium">
- Order {formatDuration(routeData?.duration)} away
- </p>
- <p className="text-background/70">
- Route {formatDistance(routeData?.distance)}
- </p>
- </div>
- </MarkerTooltip>
</MapMarker>
)}
<MapMarker longitude={pickup.lng} latitude={pickup.lat}>
<MarkerContent>
- <div className="size-4 rounded-full border-2 border-white bg-emerald-500 shadow-sm" />
+ <div className="grid size-7 place-items-center rounded-full bg-emerald-500 shadow-md">
+ <Store className="size-3.5 text-white" />
+ </div>
</MarkerContent>
- <MarkerTooltip>Origin</MarkerTooltip>
</MapMarker>
<MapMarker longitude={dropoff.lng} latitude={dropoff.lat}>
<MarkerContent>
- <div className="size-4 rounded-full border-2 border-white bg-rose-500 shadow-sm" />
+ <div className="grid size-7 place-items-center rounded-full bg-rose-500 shadow-md">
+ <House className="size-3.5 text-white" />
+ </div>
</MarkerContent>
- <MarkerTooltip>Destination</MarkerTooltip>
</MapMarker>
</Map>
</div>
diff --git a/src/registry/map.tsx b/src/registry/map.tsx
index c5b8f53..f57fe41 100644
--- a/src/registry/map.tsx
+++ b/src/registry/map.tsx
@@ -1273,9 +1273,10 @@ type MapGeoJSONProps<
*/
fillPaint?: MapFillPaint | false;
/**
- * Paint for the outline layer. Merged on top of a theme-aware hairline
- * default (`line-color` = page background, `line-width` = 0.5). Pass `false`
- * to omit the outline layer.
+ * Paint for the outline layer. Merged on top of a hairline default
+ * (`line-color` = a near-surface neutral, `line-width` = 0.5) for thin
+ * separators. Override `line-color` if your container differs, or pass
+ * `false` to omit the layer.
*/
linePaint?: MapLinePaint | false;
/**
@@ -1293,9 +1294,9 @@ type MapGeoJSONProps<
beforeId?: string;
};
-// Theme-aware monochrome defaults so MapGeoJSON reads
-// clearly on the light/dark surface out of the box: a visible neutral-gray fill
-// with page-background separators between shapes. Override either via
+// Monochrome defaults: a neutral-gray fill (hex of the grayscale chart tokens)
+// with a fixed near-surface line for thin separators. Colors are hardcoded (not
+// theme tokens), tuned for a typical light/dark surface. Override via
// `fillPaint` / `linePaint`.
const GEOJSON_DEFAULT_COLORS = {
light: { fill: "#d4d4d4", line: "#ffffff" },