@peerproblem/sw3-ui 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +109 -2
- package/agent/components/accordion.md +95 -0
- package/agent/components/action-square.md +106 -0
- package/agent/components/agent-bridge.md +87 -0
- package/agent/components/agent-console.md +123 -0
- package/agent/components/alert-dialog.md +82 -0
- package/agent/components/app-shell.md +105 -0
- package/agent/components/area-chart.md +56 -0
- package/agent/components/async-options.md +47 -0
- package/agent/components/autocomplete.md +69 -0
- package/agent/components/avatar.md +88 -0
- package/agent/components/badge.md +51 -0
- package/agent/components/bar-chart.md +56 -0
- package/agent/components/bar-list.md +49 -0
- package/agent/components/breadcrumbs.md +43 -0
- package/agent/components/button.md +109 -0
- package/agent/components/calendar.md +114 -0
- package/agent/components/canvas.md +105 -0
- package/agent/components/card.md +78 -0
- package/agent/components/carousel.md +113 -0
- package/agent/components/chart-card.md +41 -0
- package/agent/components/chart-surface.md +56 -0
- package/agent/components/checkbox.md +88 -0
- package/agent/components/citation-chip.md +61 -0
- package/agent/components/collapsible.md +69 -0
- package/agent/components/color-picker.md +82 -0
- package/agent/components/combobox.md +104 -0
- package/agent/components/command.md +92 -0
- package/agent/components/dashboard-grid.md +73 -0
- package/agent/components/date-input.md +87 -0
- package/agent/components/date-picker.md +122 -0
- package/agent/components/dialog.md +97 -0
- package/agent/components/donut-chart.md +50 -0
- package/agent/components/drawer.md +101 -0
- package/agent/components/empty-state.md +52 -0
- package/agent/components/field.md +80 -0
- package/agent/components/file-input.md +84 -0
- package/agent/components/hover-card.md +64 -0
- package/agent/components/image-cropper.md +77 -0
- package/agent/components/input.md +49 -0
- package/agent/components/label.md +53 -0
- package/agent/components/line-chart.md +60 -0
- package/agent/components/listbox.md +84 -0
- package/agent/components/map-view.md +104 -0
- package/agent/components/menu.md +117 -0
- package/agent/components/menubar.md +67 -0
- package/agent/components/meter.md +59 -0
- package/agent/components/navigation-menu.md +98 -0
- package/agent/components/number-input.md +81 -0
- package/agent/components/otp-input.md +67 -0
- package/agent/components/pagination.md +80 -0
- package/agent/components/password-input.md +67 -0
- package/agent/components/pill-button.md +116 -0
- package/agent/components/popover.md +85 -0
- package/agent/components/poster-card.md +61 -0
- package/agent/components/preferences.md +92 -0
- package/agent/components/progress.md +63 -0
- package/agent/components/provider.md +47 -0
- package/agent/components/radio.md +91 -0
- package/agent/components/rating.md +66 -0
- package/agent/components/reorder.md +61 -0
- package/agent/components/resizable.md +87 -0
- package/agent/components/scatter-chart.md +49 -0
- package/agent/components/scroll-area.md +81 -0
- package/agent/components/segmented-control.md +56 -0
- package/agent/components/select.md +130 -0
- package/agent/components/separator.md +60 -0
- package/agent/components/shortcuts.md +50 -0
- package/agent/components/sidebar-nav.md +68 -0
- package/agent/components/skeleton.md +58 -0
- package/agent/components/slider.md +79 -0
- package/agent/components/sparkline.md +39 -0
- package/agent/components/squircle.md +58 -0
- package/agent/components/stat.md +58 -0
- package/agent/components/switch.md +48 -0
- package/agent/components/table.md +58 -0
- package/agent/components/tabs.md +108 -0
- package/agent/components/textarea.md +68 -0
- package/agent/components/time-input.md +84 -0
- package/agent/components/timeline.md +91 -0
- package/agent/components/toast.md +85 -0
- package/agent/components/toggle.md +76 -0
- package/agent/components/token-input.md +66 -0
- package/agent/components/toolbar.md +76 -0
- package/agent/components/tooltip.md +83 -0
- package/agent/components/tracker.md +47 -0
- package/agent/components/tree.md +87 -0
- package/agent/components/treemap.md +72 -0
- package/agent/components/trend-chart.md +80 -0
- package/agent/components/trigger-menu.md +67 -0
- package/agent/components/typography.md +51 -0
- package/agent/components/waterfall.md +78 -0
- package/agent/components/week-schedule.md +113 -0
- package/agent/llms/actions-and-layout.txt +1749 -0
- package/agent/llms/agents.txt +505 -0
- package/agent/llms/charts.txt +778 -0
- package/agent/llms/dashboards.txt +457 -0
- package/agent/llms/extend.txt +132 -0
- package/agent/llms/extras.txt +527 -0
- package/agent/llms/forms.txt +2152 -0
- package/agent/llms/foundations.txt +674 -0
- package/agent/llms/hooks.txt +178 -0
- package/agent/llms/maps.txt +229 -0
- package/agent/llms/overlays-and-navigation.txt +1167 -0
- package/agent/llms-full.txt +8717 -0
- package/agent/llms.txt +145 -0
- package/agent/registry.json +11289 -0
- package/agent/tokens.md +66 -0
- package/dist/agent/index.d.ts +235 -0
- package/dist/agent/index.js +21 -0
- package/dist/card-Ipm-Cj5f.d.ts +490 -0
- package/dist/charts/index.d.ts +289 -0
- package/dist/charts/index.js +815 -0
- package/dist/check/cli.d.ts +1 -0
- package/dist/check/cli.js +48 -0
- package/dist/check/rendered.d.ts +11 -0
- package/dist/check/rendered.js +77 -0
- package/dist/check/source.d.ts +13 -0
- package/dist/check/source.js +182 -0
- package/dist/chunk-3DXBM65D.js +65 -0
- package/dist/chunk-3H5X4ZP6.js +55 -0
- package/dist/chunk-6XC4BC5C.js +92 -0
- package/dist/chunk-7H6TEAWD.js +507 -0
- package/dist/chunk-I63ZTJOI.js +1089 -0
- package/dist/chunk-JCIRUM4W.js +33 -0
- package/dist/chunk-LTBEHZ3P.js +25 -0
- package/dist/chunk-QDPPLO4U.js +60 -0
- package/dist/chunk-U2XFBPU4.js +56 -0
- package/dist/chunk-UY2WH5AY.js +681 -0
- package/dist/extras.d.ts +203 -0
- package/dist/extras.js +904 -0
- package/dist/icons-BJiGEAnU.d.ts +68 -0
- package/dist/index.d.ts +3737 -0
- package/dist/index.js +14477 -0
- package/dist/map/index.d.ts +115 -0
- package/dist/map/index.js +394 -0
- package/dist/meta/index.d.ts +3314 -0
- package/dist/meta/index.js +5106 -0
- package/dist/rules-1RIZ_JZr.d.ts +38 -0
- package/dist/styles.css +4037 -0
- package/dist/themes/calm.css +42 -0
- package/dist/themes/frost.css +40 -0
- package/package.json +142 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Map } from 'maplibre-gl';
|
|
4
|
+
import * as GeoJSON from 'geojson';
|
|
5
|
+
import { CardProps } from '../index.js';
|
|
6
|
+
import 'motion/react';
|
|
7
|
+
|
|
8
|
+
type LngLat = [number, number];
|
|
9
|
+
interface MapRoute {
|
|
10
|
+
id?: string;
|
|
11
|
+
/** [lng, lat] pairs — the GeoJSON LineString coordinates. */
|
|
12
|
+
coordinates: LngLat[];
|
|
13
|
+
/** CSS color. Default: the accent token. */
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Line width in px. Default 5. */
|
|
16
|
+
width?: number;
|
|
17
|
+
dashed?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface MapArea {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
/** GeoJSON geometry in [longitude, latitude] order. Polygon rings must be closed. */
|
|
23
|
+
geometry: GeoJSON.Polygon | GeoJSON.MultiPolygon;
|
|
24
|
+
tone?: 'accent' | 'warning' | 'danger';
|
|
25
|
+
/** Use a dashed line for an estimated or illustrative boundary. */
|
|
26
|
+
boundary?: 'defined' | 'approximate';
|
|
27
|
+
description?: string;
|
|
28
|
+
}
|
|
29
|
+
declare const pointKinds: {
|
|
30
|
+
readonly pin: {
|
|
31
|
+
readonly label: "Place";
|
|
32
|
+
readonly path: "M7 13s3.75-4.2 3.75-7.25a3.75 3.75 0 1 0-7.5 0C3.25 8.8 7 13 7 13ZM8.2 6a1.2 1.2 0 1 1-2.4 0 1.2 1.2 0 1 1 2.4 0Z";
|
|
33
|
+
};
|
|
34
|
+
readonly impact: {
|
|
35
|
+
readonly label: "Impact";
|
|
36
|
+
readonly path: "M4 4l6 6m0-6-6 6";
|
|
37
|
+
};
|
|
38
|
+
readonly incident: {
|
|
39
|
+
readonly label: "Incident";
|
|
40
|
+
readonly path: "M7 3v4.5m0 3.5h.01";
|
|
41
|
+
};
|
|
42
|
+
readonly shelter: {
|
|
43
|
+
readonly label: "Shelter";
|
|
44
|
+
readonly path: "M3 6.5 7 3l4 3.5v4.75H3Z";
|
|
45
|
+
};
|
|
46
|
+
readonly closure: {
|
|
47
|
+
readonly label: "Closure";
|
|
48
|
+
readonly path: "M3 7h8";
|
|
49
|
+
};
|
|
50
|
+
readonly resource: {
|
|
51
|
+
readonly label: "Resource";
|
|
52
|
+
readonly path: "M3 7h8M7 3v8";
|
|
53
|
+
};
|
|
54
|
+
readonly origin: {
|
|
55
|
+
readonly label: "Origin";
|
|
56
|
+
readonly path: "M11.25 7a4.25 4.25 0 1 1-8.5 0 4.25 4.25 0 1 1 8.5 0ZM7 7h.01";
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
type MapPointKind = keyof typeof pointKinds;
|
|
60
|
+
type MapMarkerKind = 'default' | 'start' | 'end' | MapPointKind;
|
|
61
|
+
interface MapMarker {
|
|
62
|
+
lngLat: LngLat;
|
|
63
|
+
label?: string;
|
|
64
|
+
kind?: MapMarkerKind;
|
|
65
|
+
/** Detail shown in the location list for a categorized point. */
|
|
66
|
+
description?: string;
|
|
67
|
+
/** Optional plain-text popup. The location list provides a keyboard trigger. */
|
|
68
|
+
popup?: {
|
|
69
|
+
title?: string;
|
|
70
|
+
description: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
type Basemap = 'auto' | 'light' | 'dark' | 'bright' | (string & {});
|
|
74
|
+
interface MapViewProps extends Omit<CardProps, 'children' | 'onLoad'> {
|
|
75
|
+
/** Lines to draw (GeoJSON LineStrings), e.g. a route or a track. */
|
|
76
|
+
routes?: MapRoute[];
|
|
77
|
+
/** Or pass any GeoJSON Feature/FeatureCollection of LineStrings. */
|
|
78
|
+
geojson?: GeoJSON.Feature | GeoJSON.FeatureCollection;
|
|
79
|
+
markers?: MapMarker[];
|
|
80
|
+
/** Named regions such as closure or coverage areas. */
|
|
81
|
+
areas?: readonly MapArea[];
|
|
82
|
+
/** Heading and accessible name for the list of areas. */
|
|
83
|
+
areaListLabel?: string;
|
|
84
|
+
/** Heading and accessible name for the categorized marker list. */
|
|
85
|
+
markerListLabel?: string;
|
|
86
|
+
/** Bundled MapLibre worker URL, configured before the first map creates workers. */
|
|
87
|
+
workerUrl?: string;
|
|
88
|
+
center?: LngLat;
|
|
89
|
+
zoom?: number;
|
|
90
|
+
/** Zoom to fit all routes and markers. Default true. */
|
|
91
|
+
fitToData?: boolean;
|
|
92
|
+
/** Draw the routes on with a motion animation when the map loads. */
|
|
93
|
+
animateRoutes?: boolean;
|
|
94
|
+
/** Map height in px. Default 360. */
|
|
95
|
+
height?: number;
|
|
96
|
+
/** `auto` follows the theme. Or pass any MapLibre style URL. */
|
|
97
|
+
basemap?: Basemap;
|
|
98
|
+
/** Allow pan/zoom. Default true. */
|
|
99
|
+
interactive?: boolean;
|
|
100
|
+
/** Overlay content (e.g. a Stat) pinned to the top-left. */
|
|
101
|
+
overlay?: ReactNode;
|
|
102
|
+
/** Additional map buttons below the zoom controls in the top-right corner. */
|
|
103
|
+
controls?: ReactNode;
|
|
104
|
+
/** Called with the MapLibre map once it has loaded, for advanced use. */
|
|
105
|
+
onLoad?(map: Map): void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* MapView — a MapLibre GL map (https://maplibre.org) with GeoJSON lines,
|
|
109
|
+
* markers and token colors, framed in a squircle Card.
|
|
110
|
+
* Remember to import 'maplibre-gl/dist/maplibre-gl.css' once in your app.
|
|
111
|
+
*/
|
|
112
|
+
declare function MapView({ routes, geojson, markers, markerListLabel, areas, areaListLabel, center, zoom, fitToData, animateRoutes, height, basemap, interactive, overlay, controls, onLoad, workerUrl, className, radius, bordered, style, ...card }: MapViewProps): react.JSX.Element;
|
|
113
|
+
|
|
114
|
+
export { MapView };
|
|
115
|
+
export type { Basemap, LngLat, MapArea, MapMarker, MapMarkerKind, MapPointKind, MapRoute, MapViewProps };
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
Button
|
|
4
|
+
} from "../chunk-U2XFBPU4.js";
|
|
5
|
+
import {
|
|
6
|
+
Card,
|
|
7
|
+
cx,
|
|
8
|
+
resolveRadius,
|
|
9
|
+
useSquircle
|
|
10
|
+
} from "../chunk-UY2WH5AY.js";
|
|
11
|
+
import "../chunk-JCIRUM4W.js";
|
|
12
|
+
import {
|
|
13
|
+
color
|
|
14
|
+
} from "../chunk-6XC4BC5C.js";
|
|
15
|
+
|
|
16
|
+
// src/map/map-view.tsx
|
|
17
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
18
|
+
import * as maplibregl from "maplibre-gl";
|
|
19
|
+
import { animate } from "motion";
|
|
20
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
var areaFillOpacity = 0.11;
|
|
22
|
+
function areaCoordinates({ geometry }) {
|
|
23
|
+
return geometry.type === "Polygon" ? geometry.coordinates.flat() : geometry.coordinates.flat(2);
|
|
24
|
+
}
|
|
25
|
+
function boundsFor(coordinates) {
|
|
26
|
+
const bounds = new maplibregl.LngLatBounds();
|
|
27
|
+
for (const coordinate of coordinates) bounds.extend(coordinate);
|
|
28
|
+
return bounds;
|
|
29
|
+
}
|
|
30
|
+
var pointKinds = {
|
|
31
|
+
pin: { label: "Place", path: "M7 13s3.75-4.2 3.75-7.25a3.75 3.75 0 1 0-7.5 0C3.25 8.8 7 13 7 13ZM8.2 6a1.2 1.2 0 1 1-2.4 0 1.2 1.2 0 1 1 2.4 0Z" },
|
|
32
|
+
impact: { label: "Impact", path: "M4 4l6 6m0-6-6 6" },
|
|
33
|
+
incident: { label: "Incident", path: "M7 3v4.5m0 3.5h.01" },
|
|
34
|
+
shelter: { label: "Shelter", path: "M3 6.5 7 3l4 3.5v4.75H3Z" },
|
|
35
|
+
closure: { label: "Closure", path: "M3 7h8" },
|
|
36
|
+
resource: { label: "Resource", path: "M3 7h8M7 3v8" },
|
|
37
|
+
origin: { label: "Origin", path: "M11.25 7a4.25 4.25 0 1 1-8.5 0 4.25 4.25 0 1 1 8.5 0ZM7 7h.01" }
|
|
38
|
+
};
|
|
39
|
+
var pointIconViewBox = "0 0 14 14";
|
|
40
|
+
var pointIconNamespace = "http://www.w3.org/2000/svg";
|
|
41
|
+
function createPointIcon(path) {
|
|
42
|
+
const icon = document.createElementNS(pointIconNamespace, "svg");
|
|
43
|
+
icon.setAttribute("viewBox", pointIconViewBox);
|
|
44
|
+
icon.setAttribute("aria-hidden", "true");
|
|
45
|
+
icon.classList.add("sw-map-point-icon");
|
|
46
|
+
const shape = document.createElementNS(pointIconNamespace, "path");
|
|
47
|
+
shape.setAttribute("d", path);
|
|
48
|
+
icon.appendChild(shape);
|
|
49
|
+
return icon;
|
|
50
|
+
}
|
|
51
|
+
function isPointKind(kind) {
|
|
52
|
+
return kind !== void 0 && Object.hasOwn(pointKinds, kind);
|
|
53
|
+
}
|
|
54
|
+
var STYLES = {
|
|
55
|
+
light: "https://tiles.openfreemap.org/styles/positron",
|
|
56
|
+
dark: "https://tiles.openfreemap.org/styles/dark",
|
|
57
|
+
bright: "https://tiles.openfreemap.org/styles/bright"
|
|
58
|
+
};
|
|
59
|
+
function isDark() {
|
|
60
|
+
const t = document.documentElement.getAttribute("data-theme");
|
|
61
|
+
if (t) return t === "dark";
|
|
62
|
+
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
|
|
63
|
+
}
|
|
64
|
+
function cssVar(el, name, fallback) {
|
|
65
|
+
const v = getComputedStyle(el).getPropertyValue(name).trim();
|
|
66
|
+
return v || fallback;
|
|
67
|
+
}
|
|
68
|
+
function toFeatures(routes = [], geojson) {
|
|
69
|
+
const fromRoutes = routes.map((r, i) => ({
|
|
70
|
+
type: "Feature",
|
|
71
|
+
id: i,
|
|
72
|
+
properties: { id: r.id ?? `route-${i}`, color: r.color, width: r.width ?? 5, dashed: !!r.dashed },
|
|
73
|
+
geometry: { type: "LineString", coordinates: r.coordinates }
|
|
74
|
+
}));
|
|
75
|
+
const extra = [];
|
|
76
|
+
if (geojson) {
|
|
77
|
+
const list = geojson.type === "FeatureCollection" ? geojson.features : [geojson];
|
|
78
|
+
for (const f of list) if (f.geometry?.type === "LineString") extra.push({ ...f, properties: { width: 5, ...f.properties } });
|
|
79
|
+
}
|
|
80
|
+
return [...fromRoutes, ...extra];
|
|
81
|
+
}
|
|
82
|
+
function MapView({
|
|
83
|
+
routes,
|
|
84
|
+
geojson,
|
|
85
|
+
markers,
|
|
86
|
+
markerListLabel = "Map locations",
|
|
87
|
+
areas,
|
|
88
|
+
areaListLabel = "Map areas",
|
|
89
|
+
center,
|
|
90
|
+
zoom = 13,
|
|
91
|
+
fitToData = true,
|
|
92
|
+
animateRoutes,
|
|
93
|
+
height = 360,
|
|
94
|
+
basemap = "auto",
|
|
95
|
+
interactive = true,
|
|
96
|
+
overlay,
|
|
97
|
+
controls,
|
|
98
|
+
onLoad,
|
|
99
|
+
workerUrl,
|
|
100
|
+
className,
|
|
101
|
+
radius = "lg",
|
|
102
|
+
bordered = false,
|
|
103
|
+
style,
|
|
104
|
+
...card
|
|
105
|
+
}) {
|
|
106
|
+
const el = useRef(null);
|
|
107
|
+
const mapRef = useRef(null);
|
|
108
|
+
const popupRef = useRef(null);
|
|
109
|
+
const zoomControl = useRef(null);
|
|
110
|
+
const zoomShape = useSquircle({ radius: "sm" });
|
|
111
|
+
const measureZoomControl = zoomShape.ref;
|
|
112
|
+
const [dark, setDark] = useState(false);
|
|
113
|
+
const listId = useId();
|
|
114
|
+
const areaListId = useId();
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (basemap !== "auto") return;
|
|
117
|
+
setDark(isDark());
|
|
118
|
+
const mo = new MutationObserver(() => setDark(isDark()));
|
|
119
|
+
mo.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
120
|
+
const mq = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
121
|
+
const on = () => setDark(isDark());
|
|
122
|
+
mq?.addEventListener("change", on);
|
|
123
|
+
return () => {
|
|
124
|
+
mo.disconnect();
|
|
125
|
+
mq?.removeEventListener("change", on);
|
|
126
|
+
};
|
|
127
|
+
}, [basemap]);
|
|
128
|
+
const styleUrl = basemap === "auto" ? STYLES[dark ? "dark" : "light"] : STYLES[basemap] ?? basemap;
|
|
129
|
+
const features = toFeatures(routes, geojson);
|
|
130
|
+
const officialBasemap = Object.values(STYLES).includes(styleUrl);
|
|
131
|
+
const routeKey = JSON.stringify(features);
|
|
132
|
+
const areaKey = JSON.stringify(areas);
|
|
133
|
+
const markerKey = JSON.stringify(markers);
|
|
134
|
+
const areaCoords = (areas ?? []).flatMap(areaCoordinates);
|
|
135
|
+
const allCoords = [
|
|
136
|
+
...features.flatMap((f) => f.geometry.coordinates),
|
|
137
|
+
...(markers ?? []).map((m) => m.lngLat),
|
|
138
|
+
...areaCoords
|
|
139
|
+
];
|
|
140
|
+
const coordsKey = JSON.stringify(allCoords);
|
|
141
|
+
const locations = markers?.flatMap((marker) => isPointKind(marker.kind) || marker.popup ? [marker] : []) ?? [];
|
|
142
|
+
function showPopup(marker, trigger) {
|
|
143
|
+
const map = mapRef.current;
|
|
144
|
+
if (!map || !marker.popup) return;
|
|
145
|
+
popupRef.current?.remove();
|
|
146
|
+
const body = document.createElement("div");
|
|
147
|
+
const title = document.createElement("strong");
|
|
148
|
+
title.textContent = marker.popup.title ?? marker.label ?? "Location";
|
|
149
|
+
const detail = document.createElement("p");
|
|
150
|
+
detail.textContent = marker.popup.description;
|
|
151
|
+
body.append(title, detail);
|
|
152
|
+
const popup = new maplibregl.Popup({ className: "sw-map-popup" }).setLngLat(marker.lngLat).setDOMContent(body).addTo(map);
|
|
153
|
+
popupRef.current = popup;
|
|
154
|
+
const element = popup.getElement();
|
|
155
|
+
element.dataset.sw = "map-popup";
|
|
156
|
+
const onKey = (event) => {
|
|
157
|
+
if (event.key !== "Escape") return;
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
popup.remove();
|
|
160
|
+
trigger?.focus();
|
|
161
|
+
};
|
|
162
|
+
element.addEventListener("keydown", onKey);
|
|
163
|
+
const closeButton = element.querySelector(".maplibregl-popup-close-button");
|
|
164
|
+
closeButton?.addEventListener("click", () => trigger?.focus());
|
|
165
|
+
if (trigger) closeButton?.focus();
|
|
166
|
+
popup.on("close", () => {
|
|
167
|
+
element.removeEventListener("keydown", onKey);
|
|
168
|
+
if (popupRef.current === popup) popupRef.current = null;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
const container = el.current;
|
|
173
|
+
if (!container) return;
|
|
174
|
+
if (workerUrl) maplibregl.setWorkerUrl(workerUrl);
|
|
175
|
+
let width = container.clientWidth;
|
|
176
|
+
let height2 = container.clientHeight;
|
|
177
|
+
const map = new maplibregl.Map({
|
|
178
|
+
container,
|
|
179
|
+
style: styleUrl,
|
|
180
|
+
center: center ?? allCoords[0] ?? [0, 0],
|
|
181
|
+
zoom,
|
|
182
|
+
interactive,
|
|
183
|
+
trackResize: false,
|
|
184
|
+
attributionControl: officialBasemap ? false : { compact: true }
|
|
185
|
+
});
|
|
186
|
+
mapRef.current = map;
|
|
187
|
+
if (interactive) {
|
|
188
|
+
map.addControl(new maplibregl.NavigationControl({ showCompass: false }), "top-right");
|
|
189
|
+
const controls2 = container.querySelector(".maplibregl-ctrl-top-right .maplibregl-ctrl-group");
|
|
190
|
+
if (controls2) {
|
|
191
|
+
controls2.dataset.sw = "map-zoom";
|
|
192
|
+
zoomControl.current = controls2;
|
|
193
|
+
measureZoomControl(controls2);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const theme = isDark() ? "dark" : "light";
|
|
197
|
+
const accent = cssVar(container, "--sw-accent", color.accent[theme]);
|
|
198
|
+
const halo = cssVar(container, "--sw-background", color.background[theme]);
|
|
199
|
+
let routeAnimation;
|
|
200
|
+
map.on("load", () => {
|
|
201
|
+
if (areas?.length) {
|
|
202
|
+
const tones = {
|
|
203
|
+
accent,
|
|
204
|
+
warning: cssVar(container, "--sw-warning", color.warning[theme]),
|
|
205
|
+
danger: cssVar(container, "--sw-danger", color.danger[theme])
|
|
206
|
+
};
|
|
207
|
+
const data2 = {
|
|
208
|
+
type: "FeatureCollection",
|
|
209
|
+
features: areas.map(({ id, geometry, tone = "accent", boundary = "defined" }) => ({
|
|
210
|
+
type: "Feature",
|
|
211
|
+
id,
|
|
212
|
+
geometry,
|
|
213
|
+
properties: { color: tones[tone], boundary }
|
|
214
|
+
}))
|
|
215
|
+
};
|
|
216
|
+
const layers = map.getStyle().layers;
|
|
217
|
+
let above = 0;
|
|
218
|
+
for (const [index, layer] of layers.entries()) {
|
|
219
|
+
if (["background", "fill", "fill-extrusion", "raster"].includes(layer.type)) above = index + 1;
|
|
220
|
+
}
|
|
221
|
+
const before = layers.slice(above).find((layer) => layer.type === "symbol" && layer.layout?.["text-field"])?.id;
|
|
222
|
+
map.addSource("sw-areas", { type: "geojson", data: data2 });
|
|
223
|
+
map.addLayer({ id: "sw-areas-fill", type: "fill", source: "sw-areas", paint: {
|
|
224
|
+
"fill-color": ["get", "color"],
|
|
225
|
+
"fill-opacity": areaFillOpacity
|
|
226
|
+
} }, before);
|
|
227
|
+
for (const boundary of ["defined", "approximate"]) {
|
|
228
|
+
map.addLayer({
|
|
229
|
+
id: `sw-areas-${boundary}`,
|
|
230
|
+
type: "line",
|
|
231
|
+
source: "sw-areas",
|
|
232
|
+
filter: ["==", ["get", "boundary"], boundary],
|
|
233
|
+
layout: { "line-join": "round", "line-cap": "round" },
|
|
234
|
+
paint: {
|
|
235
|
+
"line-color": ["get", "color"],
|
|
236
|
+
"line-width": ["interpolate", ["linear"], ["zoom"], 8, 1, 14, 1.5],
|
|
237
|
+
"line-opacity": theme === "dark" ? 0.66 : 0.84,
|
|
238
|
+
...boundary === "approximate" && { "line-dasharray": [4, 3] }
|
|
239
|
+
}
|
|
240
|
+
}, before);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const data = { type: "FeatureCollection", features };
|
|
244
|
+
map.addSource("sw-routes", { type: "geojson", data: animateRoutes ? { type: "FeatureCollection", features: [] } : data });
|
|
245
|
+
const color2 = ["coalesce", ["get", "color"], accent];
|
|
246
|
+
map.addLayer({ id: "sw-routes-halo", type: "line", source: "sw-routes", layout: { "line-join": "round", "line-cap": "round" }, paint: { "line-color": halo, "line-width": ["+", ["get", "width"], 4], "line-opacity": 0.9 } });
|
|
247
|
+
map.addLayer({ id: "sw-routes", type: "line", source: "sw-routes", filter: ["!=", ["get", "dashed"], true], layout: { "line-join": "round", "line-cap": "round" }, paint: { "line-color": color2, "line-width": ["get", "width"] } });
|
|
248
|
+
map.addLayer({ id: "sw-routes-dashed", type: "line", source: "sw-routes", filter: ["==", ["get", "dashed"], true], layout: { "line-join": "round", "line-cap": "butt" }, paint: { "line-color": color2, "line-width": ["get", "width"], "line-dasharray": [1.5, 1.5] } });
|
|
249
|
+
if (animateRoutes) {
|
|
250
|
+
const src = map.getSource("sw-routes");
|
|
251
|
+
routeAnimation = animate(0, 1, {
|
|
252
|
+
duration: 1.6,
|
|
253
|
+
ease: [0.4, 0, 0.2, 1],
|
|
254
|
+
onUpdate: (t) => {
|
|
255
|
+
src.setData({
|
|
256
|
+
type: "FeatureCollection",
|
|
257
|
+
features: features.map((f) => {
|
|
258
|
+
const c = f.geometry.coordinates;
|
|
259
|
+
const n = Math.max(2, Math.ceil(c.length * t));
|
|
260
|
+
return { ...f, geometry: { ...f.geometry, coordinates: c.slice(0, n) } };
|
|
261
|
+
})
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
onLoad?.(map);
|
|
267
|
+
});
|
|
268
|
+
const ro = new ResizeObserver(() => {
|
|
269
|
+
const nextWidth = container.clientWidth;
|
|
270
|
+
const nextHeight = container.clientHeight;
|
|
271
|
+
if (!nextWidth || !nextHeight || nextWidth === width && nextHeight === height2) return;
|
|
272
|
+
width = nextWidth;
|
|
273
|
+
height2 = nextHeight;
|
|
274
|
+
map.resize().redraw();
|
|
275
|
+
});
|
|
276
|
+
ro.observe(container);
|
|
277
|
+
return () => {
|
|
278
|
+
ro.disconnect();
|
|
279
|
+
routeAnimation?.stop();
|
|
280
|
+
popupRef.current?.remove();
|
|
281
|
+
map.remove();
|
|
282
|
+
mapRef.current = null;
|
|
283
|
+
zoomControl.current = null;
|
|
284
|
+
measureZoomControl(null);
|
|
285
|
+
};
|
|
286
|
+
}, [styleUrl, routeKey, areaKey, interactive, measureZoomControl, workerUrl]);
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
const controls2 = zoomControl.current;
|
|
289
|
+
if (controls2 && zoomShape.paths.d) controls2.style.clipPath = `path('${zoomShape.paths.d}')`;
|
|
290
|
+
}, [styleUrl, routeKey, areaKey, interactive, zoomShape.paths.d, workerUrl]);
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
const map = mapRef.current;
|
|
293
|
+
if (!map) return;
|
|
294
|
+
const domMarkers = (markers ?? []).map((marker) => {
|
|
295
|
+
const { kind, lngLat, label, popup } = marker;
|
|
296
|
+
const node = document.createElement("div");
|
|
297
|
+
node.className = "sw-map-marker";
|
|
298
|
+
node.dataset.sw = "map-marker";
|
|
299
|
+
node.dataset.kind = kind ?? "default";
|
|
300
|
+
const point = isPointKind(kind) ? pointKinds[kind] : void 0;
|
|
301
|
+
if (point) {
|
|
302
|
+
node.dataset.point = "";
|
|
303
|
+
node.setAttribute("aria-hidden", "true");
|
|
304
|
+
node.appendChild(createPointIcon(point.path));
|
|
305
|
+
}
|
|
306
|
+
if (point || label) {
|
|
307
|
+
const caption = document.createElement("span");
|
|
308
|
+
caption.className = "sw-map-marker__label";
|
|
309
|
+
caption.textContent = point?.label ?? label ?? "";
|
|
310
|
+
if (point && label) {
|
|
311
|
+
const name = document.createElement("span");
|
|
312
|
+
name.className = "sw-map-marker__name";
|
|
313
|
+
name.textContent = ` \xB7 ${label}`;
|
|
314
|
+
caption.appendChild(name);
|
|
315
|
+
}
|
|
316
|
+
node.appendChild(caption);
|
|
317
|
+
}
|
|
318
|
+
if (popup) {
|
|
319
|
+
node.dataset.popup = "";
|
|
320
|
+
node.addEventListener("click", (event) => {
|
|
321
|
+
event.stopPropagation();
|
|
322
|
+
showPopup(marker);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return new maplibregl.Marker({ element: node, anchor: "center" }).setLngLat(lngLat).addTo(map);
|
|
326
|
+
});
|
|
327
|
+
return () => {
|
|
328
|
+
popupRef.current?.remove();
|
|
329
|
+
domMarkers.forEach((marker) => marker.remove());
|
|
330
|
+
};
|
|
331
|
+
}, [styleUrl, routeKey, areaKey, interactive, markerKey, workerUrl]);
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
const map = mapRef.current;
|
|
334
|
+
if (!map || !fitToData || !allCoords.length) return;
|
|
335
|
+
if (allCoords.length === 1) {
|
|
336
|
+
if (!center) map.jumpTo({ center: allCoords[0] });
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
map.fitBounds(boundsFor(allCoords), { padding: 48, duration: 0, maxZoom: 16 });
|
|
340
|
+
}, [styleUrl, routeKey, areaKey, interactive, coordsKey, fitToData, workerUrl]);
|
|
341
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
342
|
+
/* @__PURE__ */ jsxs(Card, { "data-sw": "map", padding: "none", radius, bordered, clipContent: resolveRadius(radius) > 0, className: cx("sw-map", className), style: { ...style, height }, ...card, children: [
|
|
343
|
+
/* @__PURE__ */ jsx("div", { ref: el, className: "sw-map__canvas" }),
|
|
344
|
+
overlay && /* @__PURE__ */ jsx("div", { className: "sw-map__overlay", children: overlay }),
|
|
345
|
+
controls && /* @__PURE__ */ jsx("div", { "data-sw": "map-controls", "data-after-zoom": interactive ? "" : void 0, className: "sw-map__controls", children: controls })
|
|
346
|
+
] }),
|
|
347
|
+
officialBasemap && /* @__PURE__ */ jsxs("p", { "data-sw": "map-attribution", className: "sw-map-attribution", children: [
|
|
348
|
+
"\xA9 ",
|
|
349
|
+
/* @__PURE__ */ jsx("a", { href: "https://www.openmaptiles.org/", children: "OpenMapTiles" }),
|
|
350
|
+
" \xB7 Data from ",
|
|
351
|
+
/* @__PURE__ */ jsx("a", { href: "https://www.openstreetmap.org/copyright", children: "OpenStreetMap" })
|
|
352
|
+
] }),
|
|
353
|
+
areas && areas.length > 0 && /* @__PURE__ */ jsxs("div", { "data-sw": "map-areas", className: "sw-map-locations", children: [
|
|
354
|
+
/* @__PURE__ */ jsx("p", { id: areaListId, className: "sw-map-locations__heading", children: areaListLabel }),
|
|
355
|
+
/* @__PURE__ */ jsx("ul", { "aria-labelledby": areaListId, role: "list", className: "sw-map-locations__list", children: areas.map((area) => {
|
|
356
|
+
const { id, label, description, tone = "accent", boundary = "defined" } = area;
|
|
357
|
+
return /* @__PURE__ */ jsxs("li", { "data-sw": "map-area", "data-tone": tone, "data-boundary": boundary, className: "sw-map-location sw-map-area", children: [
|
|
358
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "sw-map-area__swatch" }),
|
|
359
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
360
|
+
/* @__PURE__ */ jsx("span", { className: "sw-map-location__name", children: label }),
|
|
361
|
+
boundary === "approximate" && /* @__PURE__ */ jsx("span", { className: "sw-map-area__boundary", children: "Approximate boundary" }),
|
|
362
|
+
description && /* @__PURE__ */ jsx("p", { className: "sw-map-location__description", children: description }),
|
|
363
|
+
interactive && /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", "aria-label": `Zoom to ${label}`, onClick: () => {
|
|
364
|
+
const map = mapRef.current;
|
|
365
|
+
const bounds = boundsFor(areaCoordinates(area));
|
|
366
|
+
if (!map || bounds.isEmpty()) return;
|
|
367
|
+
map.fitBounds(bounds, { padding: 56, maxZoom: 16 });
|
|
368
|
+
map.getCanvas().focus();
|
|
369
|
+
}, children: "Zoom to area" })
|
|
370
|
+
] })
|
|
371
|
+
] }, id);
|
|
372
|
+
}) })
|
|
373
|
+
] }),
|
|
374
|
+
locations.length > 0 && /* @__PURE__ */ jsxs("div", { "data-sw": "map-locations", className: "sw-map-locations", children: [
|
|
375
|
+
/* @__PURE__ */ jsx("p", { id: listId, className: "sw-map-locations__heading", children: markerListLabel }),
|
|
376
|
+
/* @__PURE__ */ jsx("ul", { "aria-labelledby": listId, role: "list", className: "sw-map-locations__list", children: locations.map((marker, index) => {
|
|
377
|
+
const { kind, label, description, lngLat, popup } = marker;
|
|
378
|
+
const group = isPointKind(kind) ? pointKinds[kind] : void 0;
|
|
379
|
+
return /* @__PURE__ */ jsxs("li", { "data-sw": "map-location", "data-kind": kind, className: "sw-map-location", children: [
|
|
380
|
+
group && /* @__PURE__ */ jsx("span", { className: "sw-map-location__glyph", "aria-hidden": "true", children: /* @__PURE__ */ jsx("svg", { className: "sw-map-point-icon", viewBox: pointIconViewBox, children: /* @__PURE__ */ jsx("path", { d: group.path }) }) }),
|
|
381
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
382
|
+
group && /* @__PURE__ */ jsx("span", { className: "sw-map-location__kind", children: group.label }),
|
|
383
|
+
label && /* @__PURE__ */ jsx("span", { className: "sw-map-location__name", children: label }),
|
|
384
|
+
description && /* @__PURE__ */ jsx("p", { className: "sw-map-location__description", children: description }),
|
|
385
|
+
popup && /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", "aria-label": `Show details for ${label ?? popup.title ?? group?.label ?? "location"}`, onClick: (event) => showPopup(marker, event.currentTarget), children: "Show details" })
|
|
386
|
+
] })
|
|
387
|
+
] }, `${kind}-${lngLat.join(",")}-${index}`);
|
|
388
|
+
}) })
|
|
389
|
+
] })
|
|
390
|
+
] });
|
|
391
|
+
}
|
|
392
|
+
export {
|
|
393
|
+
MapView
|
|
394
|
+
};
|