strata-react 1.0.32 → 1.0.35

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.
Files changed (63) hide show
  1. package/README.md +11 -1
  2. package/UPGRADING.md +2 -0
  3. package/dist/components/conversation.d.ts +67 -0
  4. package/dist/components/cursor.d.ts +44 -0
  5. package/dist/components/dialog.d.ts +1 -1
  6. package/dist/components/folder-picker.d.ts +42 -0
  7. package/dist/components/lightbox.d.ts +34 -0
  8. package/dist/components/line-chart.d.ts +92 -3
  9. package/dist/components/markable-text.d.ts +56 -0
  10. package/dist/components/media-group.d.ts +25 -0
  11. package/dist/components/media-player.d.ts +80 -2
  12. package/dist/components/media.d.ts +6 -1
  13. package/dist/components/region-editor.d.ts +55 -0
  14. package/dist/components/sequence-timeline.d.ts +50 -0
  15. package/dist/components/transcript-view.d.ts +36 -0
  16. package/dist/components/tree.d.ts +41 -0
  17. package/dist/components/waveform.d.ts +66 -0
  18. package/dist/cursor-DDGBPiTJ.js +290 -0
  19. package/dist/cursor-DDGBPiTJ.js.map +1 -0
  20. package/dist/field-7Z4N5r5g.js +178 -0
  21. package/dist/field-7Z4N5r5g.js.map +1 -0
  22. package/dist/{geo-C0jcFp4q.js → format-B32-PVi2.js} +2 -119
  23. package/dist/format-B32-PVi2.js.map +1 -0
  24. package/dist/hls/index.d.ts +19 -0
  25. package/dist/hls.js +84 -0
  26. package/dist/hls.js.map +1 -0
  27. package/dist/index.d.ts +19 -2
  28. package/dist/index.js +9511 -6296
  29. package/dist/index.js.map +1 -1
  30. package/dist/lib/geo.d.ts +17 -1
  31. package/dist/lib/marks.d.ts +6 -0
  32. package/dist/lib/region.d.ts +46 -0
  33. package/dist/lib/rich-text.d.ts +44 -0
  34. package/dist/lib/sequence.d.ts +34 -0
  35. package/dist/lib/transcript.d.ts +28 -0
  36. package/dist/lib/waveform.d.ts +36 -0
  37. package/dist/map/fan.d.ts +15 -0
  38. package/dist/map/index.d.ts +3 -1
  39. package/dist/map/markers.d.ts +60 -0
  40. package/dist/map/route-map.d.ts +53 -1
  41. package/dist/map.js +626 -40
  42. package/dist/map.js.map +1 -1
  43. package/dist/panorama/gl.d.ts +16 -0
  44. package/dist/panorama/index.d.ts +2 -0
  45. package/dist/panorama/panorama-viewer.d.ts +56 -0
  46. package/dist/panorama/projection.d.ts +45 -0
  47. package/dist/panorama.js +657 -0
  48. package/dist/panorama.js.map +1 -0
  49. package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
  50. package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
  51. package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
  52. package/dist/run-DzyLrZlA.js.map +1 -0
  53. package/dist/testing.js +2 -2
  54. package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
  55. package/dist/theme-CFNi6WUO.js.map +1 -0
  56. package/dist/value-controls-D6O9TsM6.js +356 -0
  57. package/dist/value-controls-D6O9TsM6.js.map +1 -0
  58. package/dist/visual-cli.js +1 -1
  59. package/dist/visual.js +1 -1
  60. package/package.json +19 -4
  61. package/dist/geo-C0jcFp4q.js.map +0 -1
  62. package/dist/run-BqZGKhW9.js.map +0 -1
  63. package/dist/theme-BgTOESmN.js.map +0 -1
package/dist/map.js CHANGED
@@ -1,9 +1,13 @@
1
- import { _ as cn, a as useColorScheme } from "./theme-BgTOESmN.js";
2
- import { a as format, t as geo } from "./geo-C0jcFp4q.js";
1
+ import { a as useColorScheme, c as Tooltip$1 } from "./theme-CFNi6WUO.js";
2
+ import { c as cn } from "./field-7Z4N5r5g.js";
3
+ import { i as format } from "./format-B32-PVi2.js";
4
+ import { n as useSharedCursor, r as geo } from "./cursor-DDGBPiTJ.js";
3
5
  import * as React from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { Button } from "react-aria-components";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
8
  import L from "leaflet";
6
9
  import leafletCss from "leaflet/dist/leaflet.css?inline";
10
+ import { createPortal } from "react-dom";
7
11
  // src/map/map-styles.ts
8
12
  var strata = `
9
13
  .strata-map .leaflet-container { background: var(--surface-sunken); color: var(--foreground); font: inherit; }
@@ -20,6 +24,9 @@ var strata = `
20
24
  .strata-map .leaflet-tooltip::before { display: none; }
21
25
  .strata-map[data-dark-treatment] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9); }
22
26
  .strata-map .strata-map-arrow { background: none; border: 0; }
27
+ .strata-map .strata-map-marker, .strata-map .strata-map-crosshair { background: none; border: 0; display: grid; place-items: center; }
28
+ .strata-map .strata-map-reset { display: grid; place-items: center; }
29
+ .strata-map .strata-map-picking, .strata-map .strata-map-picking .leaflet-interactive { cursor: crosshair; }
23
30
  `;
24
31
  var installed = false;
25
32
  /** Puts Leaflet's stylesheet and the token overrides in the document head, once. */
@@ -31,6 +38,232 @@ function installMapStyles() {
31
38
  el.textContent = leafletCss + strata;
32
39
  document.head.appendChild(el);
33
40
  }
41
+ // src/map/fan.ts
42
+ /** Move apart markers closer than `gap` pixels. Output is in input order. */
43
+ function fanOut(items, gap = 26) {
44
+ const parent = items.map((_, i) => i);
45
+ const find = (i) => parent[i] === i ? i : parent[i] = find(parent[i]);
46
+ const cells = /* @__PURE__ */ new Map();
47
+ const key = (cx, cy) => `${cx},${cy}`;
48
+ items.forEach((p, i) => {
49
+ const [cx, cy] = [Math.floor(p.x / gap), Math.floor(p.y / gap)];
50
+ for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) for (const j of cells.get(key(cx + dx, cy + dy)) ?? []) if (Math.hypot(items[j].x - p.x, items[j].y - p.y) < gap) parent[find(i)] = find(j);
51
+ const own = cells.get(key(cx, cy));
52
+ if (own) own.push(i);
53
+ else cells.set(key(cx, cy), [i]);
54
+ });
55
+ const groups = /* @__PURE__ */ new Map();
56
+ items.forEach((_, i) => {
57
+ const r = find(i);
58
+ const g = groups.get(r);
59
+ if (g) g.push(i);
60
+ else groups.set(r, [i]);
61
+ });
62
+ const out = items.map((p) => ({
63
+ id: p.id,
64
+ x: p.x,
65
+ y: p.y,
66
+ fanned: false
67
+ }));
68
+ for (const members of groups.values()) {
69
+ const n = members.length;
70
+ if (n < 2) continue;
71
+ const cx = members.reduce((s, i) => s + items[i].x, 0) / n;
72
+ const cy = members.reduce((s, i) => s + items[i].y, 0) / n;
73
+ const place = (i, radius, angle) => {
74
+ out[i] = {
75
+ id: items[i].id,
76
+ x: cx + radius * Math.sin(angle),
77
+ y: cy - radius * Math.cos(angle),
78
+ fanned: true
79
+ };
80
+ };
81
+ if (n <= 6) {
82
+ const radius = gap / (2 * Math.sin(Math.PI / n));
83
+ members.forEach((i, k) => place(i, radius, 2 * Math.PI * k / n));
84
+ } else {
85
+ let k = 0;
86
+ for (let ring = 1; k < n; ring++) {
87
+ const radius = ring * gap;
88
+ const fit = Math.max(1, Math.floor(2 * Math.PI * radius / gap));
89
+ const here = Math.min(fit, n - k);
90
+ for (let m = 0; m < here; m++) place(members[k + m], radius, 2 * Math.PI * m / here);
91
+ k += here;
92
+ }
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+ // src/map/markers.tsx
98
+ var alongCache = /* @__PURE__ */ new WeakMap();
99
+ /** The running distance at each point of a route, kept per route array so a long route is walked once. */
100
+ function alongOf(points) {
101
+ let a = alongCache.get(points);
102
+ if (!a) {
103
+ a = geo.cumulative(points);
104
+ alongCache.set(points, a);
105
+ }
106
+ return a;
107
+ }
108
+ /** Where a marker really is: its place, or the middle of its stretch. Null when its route is not on the map. */
109
+ function markerPlace(m, routes) {
110
+ if (Array.isArray(m.at)) return m.at;
111
+ const at = m.at;
112
+ const route = routes.find((r) => r.id === at.routeId);
113
+ return route ? geo.pointAlong(route.points, (at.from + at.to) / 2, alongOf(route.points)) : null;
114
+ }
115
+ /** The markers near the view, with the overlapping ones fanned apart for this zoom. */
116
+ function placeMarkers(map, markers, routes) {
117
+ const near = map.getBounds().pad(.25);
118
+ const zoom = map.getZoom();
119
+ const here = [];
120
+ for (const marker of markers) {
121
+ const at = markerPlace(marker, routes);
122
+ if (at && near.contains([at[0], at[1]])) here.push({
123
+ marker,
124
+ at
125
+ });
126
+ }
127
+ const fanned = fanOut(here.map((h) => ({
128
+ id: h.marker.id,
129
+ ...map.project([h.at[0], h.at[1]], zoom)
130
+ })));
131
+ return here.map((h, i) => {
132
+ const f = fanned[i];
133
+ const shown = f.fanned ? map.unproject([f.x, f.y], zoom) : null;
134
+ return {
135
+ marker: h.marker,
136
+ at: h.at,
137
+ shown: shown ? [shown.lat, shown.lng] : h.at,
138
+ fanned: f.fanned
139
+ };
140
+ });
141
+ }
142
+ var state = (m) => m.highlighted ? "highlighted" : m.selected ? "selected" : "marker";
143
+ /** One marker: a Leaflet marker holding a node that React fills with a labelled button. */
144
+ function Pin({ map, placed, active, onActivate, onMove, register, onSelect, card }) {
145
+ const { marker, shown } = placed;
146
+ const host = React.useMemo(() => {
147
+ const el = document.createElement("div");
148
+ el.className = "strata-map-pin";
149
+ return el;
150
+ }, []);
151
+ const layer = React.useRef(null);
152
+ React.useEffect(() => {
153
+ const m = L.marker([shown[0], shown[1]], {
154
+ icon: L.divIcon({
155
+ className: "strata-map-marker",
156
+ html: host,
157
+ iconSize: [28, 28],
158
+ iconAnchor: [14, 14]
159
+ }),
160
+ interactive: false,
161
+ keyboard: false
162
+ }).addTo(map);
163
+ layer.current = m;
164
+ return () => {
165
+ layer.current = null;
166
+ m.remove();
167
+ };
168
+ }, [map, host]);
169
+ React.useEffect(() => {
170
+ layer.current?.setLatLng([shown[0], shown[1]]);
171
+ }, [shown]);
172
+ React.useEffect(() => {
173
+ layer.current?.setZIndexOffset(marker.selected ? 1e3 : marker.highlighted ? 500 : 0);
174
+ }, [marker.selected, marker.highlighted]);
175
+ const kind = state(marker);
176
+ const swatch = marker.colour ?? (kind === "highlighted" ? "var(--success)" : kind === "selected" ? "var(--foreground)" : "var(--primary)");
177
+ return createPortal(/* @__PURE__ */ jsx(Tooltip$1, {
178
+ label: card ? card(marker) : marker.label,
179
+ side: "top",
180
+ children: /* @__PURE__ */ jsx(Button, {
181
+ ref: (el) => register(marker.id, el),
182
+ "aria-label": marker.label,
183
+ "aria-pressed": marker.selected ?? false,
184
+ excludeFromTabOrder: !active,
185
+ onFocus: () => onActivate(marker.id),
186
+ onPress: () => onSelect?.(marker.id),
187
+ onKeyDown: (e) => {
188
+ const to = e.key === "ArrowRight" || e.key === "ArrowDown" ? "next" : e.key === "ArrowLeft" || e.key === "ArrowUp" ? "previous" : e.key === "Home" ? "first" : e.key === "End" ? "last" : null;
189
+ if (!to) return;
190
+ e.preventDefault();
191
+ e.stopPropagation();
192
+ onMove(marker.id, to);
193
+ },
194
+ className: "pointer-events-auto grid size-7 cursor-pointer place-items-center rounded-pill outline-offset-1 focus-visible:outline-2 focus-visible:outline-ring",
195
+ children: /* @__PURE__ */ jsx(Shape, {
196
+ kind,
197
+ colour: swatch
198
+ })
199
+ })
200
+ }), host);
201
+ }
202
+ /** The drawn shape of a marker state: a circle, a ringed larger circle, a diamond. Shapes carry the meaning as colour does. */
203
+ function Shape({ kind, colour }) {
204
+ return /* @__PURE__ */ jsx("span", {
205
+ "aria-hidden": true,
206
+ className: cn("block border-2 border-background", kind === "highlighted" ? "size-3.5 rotate-45 rounded-sm" : "rounded-pill", kind === "selected" ? "size-4 ring-2 ring-foreground" : kind === "marker" ? "size-3.5" : ""),
207
+ style: { background: colour }
208
+ });
209
+ }
210
+ /** The pins for the markers near the view, as one roving group: one tab stop, arrows between them. */
211
+ function MarkerLayer({ map, placed, onSelect, card }) {
212
+ const [activeId, setActiveId] = React.useState(null);
213
+ const els = React.useRef(/* @__PURE__ */ new Map());
214
+ const ids = placed.map((p) => p.marker.id);
215
+ const active = activeId !== null && ids.includes(activeId) ? activeId : ids[0] ?? null;
216
+ const register = React.useCallback((id, el) => {
217
+ if (el) els.current.set(id, el);
218
+ else els.current.delete(id);
219
+ }, []);
220
+ const move = (id, to) => {
221
+ const i = ids.indexOf(id);
222
+ const next = to === "first" ? 0 : to === "last" ? ids.length - 1 : Math.min(ids.length - 1, Math.max(0, i + (to === "next" ? 1 : -1)));
223
+ setActiveId(ids[next]);
224
+ els.current.get(ids[next])?.focus();
225
+ };
226
+ return /* @__PURE__ */ jsx(Fragment, { children: placed.map((p) => /* @__PURE__ */ jsx(Pin, {
227
+ map,
228
+ placed: p,
229
+ active: p.marker.id === active,
230
+ onActivate: setActiveId,
231
+ onMove: move,
232
+ register,
233
+ onSelect,
234
+ card
235
+ }, p.marker.id)) });
236
+ }
237
+ /** The key to the marker states that are on the map, each with its shape and its words. */
238
+ function MarkerKey({ markers, words }) {
239
+ const kinds = [
240
+ "marker",
241
+ "selected",
242
+ "highlighted"
243
+ ].filter((k) => markers.some((m) => state(m) === k));
244
+ const text = {
245
+ marker: words?.marker ?? "Item",
246
+ selected: words?.selected ?? "Selected",
247
+ highlighted: words?.highlighted ?? "Highlighted"
248
+ };
249
+ if (!kinds.length) return null;
250
+ return /* @__PURE__ */ jsx("div", {
251
+ className: "rounded-control border border-border bg-background px-2 py-1.5 type-caption text-foreground",
252
+ children: /* @__PURE__ */ jsx("ul", {
253
+ className: "grid gap-0.5",
254
+ children: kinds.map((k) => /* @__PURE__ */ jsxs("li", {
255
+ className: "flex items-center gap-2",
256
+ children: [/* @__PURE__ */ jsx("span", {
257
+ className: "grid size-4 place-items-center",
258
+ children: /* @__PURE__ */ jsx(Shape, {
259
+ kind: k,
260
+ colour: k === "highlighted" ? "var(--success)" : k === "selected" ? "var(--foreground)" : "var(--primary)"
261
+ })
262
+ }), text[k]]
263
+ }, k))
264
+ })
265
+ });
266
+ }
34
267
  // src/map/route-map.tsx
35
268
  /** The smallest and largest value, without spreading the array (a long recording passes the engine's argument limit). */
36
269
  function extent(values) {
@@ -55,6 +288,72 @@ function useSlow(value, ms = 1e3) {
55
288
  }, [ms]);
56
289
  return slow;
57
290
  }
291
+ /** How many moves of the map the component itself is making right now (see `onViewChange`). */
292
+ var quiet = /* @__PURE__ */ new WeakMap();
293
+ /** Run a move the component makes itself, so `onViewChange` does not report it. Leaflet's events are synchronous with animation off. */
294
+ function silently(map, fn) {
295
+ quiet.set(map, (quiet.get(map) ?? 0) + 1);
296
+ try {
297
+ return fn();
298
+ } finally {
299
+ quiet.set(map, (quiet.get(map) ?? 1) - 1);
300
+ }
301
+ }
302
+ /** The route nearest a place, by distance from it to the route (not to a vertex). */
303
+ function nearestRoute(routes, at) {
304
+ let best = null;
305
+ for (const r of routes) {
306
+ const s = geo.snap(r.points, at, alongOf(r.points));
307
+ if (s && (!best || s.offset < best.distanceM)) best = {
308
+ routeId: r.id,
309
+ index: s.index,
310
+ distanceM: s.offset,
311
+ alongM: s.metres,
312
+ position: s.position
313
+ };
314
+ }
315
+ return best;
316
+ }
317
+ var RESET_ICON = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.75\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M2 6V2h4M10 2h4v4M14 10v4h-4M6 14H2v-4\"/></svg>";
318
+ var CROSS_ICON = "<svg width=\"32\" height=\"32\" viewBox=\"0 0 32 32\" aria-hidden=\"true\" fill=\"none\" stroke-linecap=\"round\"><path d=\"M16 4v24M4 16h24\" stroke=\"var(--background)\" stroke-width=\"5\"/><path d=\"M16 4v24M4 16h24\" stroke=\"var(--foreground)\" stroke-width=\"2\"/></svg>";
319
+ /** Leaflet's control group gets a reset: fit the routes again. A link with a button role, as Leaflet's own zoom buttons are. */
320
+ function resetControl(onReset) {
321
+ const control = new L.Control({ position: "topleft" });
322
+ control.onAdd = () => {
323
+ const bar = L.DomUtil.create("div", "leaflet-bar leaflet-control");
324
+ const a = L.DomUtil.create("a", "strata-map-reset", bar);
325
+ a.href = "#";
326
+ a.setAttribute("role", "button");
327
+ a.setAttribute("aria-label", "Reset view");
328
+ a.title = "Reset view";
329
+ a.innerHTML = RESET_ICON;
330
+ L.DomEvent.disableClickPropagation(bar);
331
+ L.DomEvent.on(a, "click", (e) => {
332
+ L.DomEvent.preventDefault(e);
333
+ onReset();
334
+ });
335
+ L.DomEvent.on(a, "keydown", (e) => {
336
+ if (e.key === " ") {
337
+ L.DomEvent.preventDefault(e);
338
+ onReset();
339
+ }
340
+ });
341
+ return bar;
342
+ };
343
+ return control;
344
+ }
345
+ /** Put the routes in view (or, with a zoom set, centre the routes at it). */
346
+ function showRoutes(map, routes, zoom) {
347
+ const box = geo.bounds(routes.flatMap((r) => r.points));
348
+ if (!box) return false;
349
+ if (zoom !== void 0) map.setView([(box[0][0] + box[1][0]) / 2, (box[0][1] + box[1][1]) / 2], zoom, { animate: false });
350
+ else map.fitBounds([tuple(box[0]), tuple(box[1])], {
351
+ padding: [24, 24],
352
+ animate: false,
353
+ maxZoom: 17
354
+ });
355
+ return true;
356
+ }
58
357
  var SINGLE = "\0position";
59
358
  var PALETTE = [
60
359
  1,
@@ -72,13 +371,15 @@ var PALETTE = [
72
371
  * call, which flickers when the position changes every frame.
73
372
  */
74
373
  function centre(map, target, z) {
75
- if (map.getZoom() !== z) map.setView(tuple(target), z, { animate: false });
76
- const want = map.project(tuple(target), z).subtract(map.getSize().divideBy(2)).round();
77
- const have = map.getPixelBounds().min.round();
78
- const move = want.subtract(have);
79
- if (move.x || move.y) map.panBy(move, {
80
- animate: false,
81
- noMoveStart: true
374
+ silently(map, () => {
375
+ if (map.getZoom() !== z) map.setView(tuple(target), z, { animate: false });
376
+ const want = map.project(tuple(target), z).subtract(map.getSize().divideBy(2)).round();
377
+ const have = map.getPixelBounds().min.round();
378
+ const move = want.subtract(have);
379
+ if (move.x || move.y) map.panBy(move, {
380
+ animate: false,
381
+ noMoveStart: true
382
+ });
82
383
  });
83
384
  }
84
385
  /** The colour a CSS value (a `var()`, a role) resolves to on `el`, so an SVG attribute gets a real one. Falls back to the value itself. */
@@ -107,16 +408,42 @@ function stepRuns(points, values, stepOf) {
107
408
  }
108
409
  var arrowHtml = (bearing, colour, halo) => `<svg width="26" height="26" viewBox="0 0 26 26" aria-hidden="true" style="transform: rotate(${bearing.toFixed(0)}deg)"><path d="M6 17 L13 9 L20 17" fill="none" stroke="${halo}" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/><path d="M6 17 L13 9 L20 17" fill="none" stroke="${colour}" stroke-width="3.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
109
410
  /** A map of one or more routes with a position that moves along them, on tiles the app supplies, themed from its roles. Leaflet, behind `strata-react/map`. */
110
- function RouteMap({ label, routes, tiles, position = null, positionLabel = "Current position", positions, followId, follow = false, zoom, selectedId = null, onSelect, colourScale, colourScaleLabel, formatValue = plain, summary, units = "metric", scrollZoom = false, topEnd, bottomStart, className }) {
411
+ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Current position", positions, followId, follow = false, zoom, markers, onMarkerSelect, renderMarkerCard, markerKey, cursor: cursorProp, onViewChange, settle = 250, reportAppMoves = false, view, picking = false, onPick, onPickCancel, pickBanner, selectedId = null, onSelect, colourScale, colourScaleLabel, formatValue = plain, summary, units = "metric", scrollZoom = false, topEnd, bottomStart, className }) {
111
412
  const { scheme } = useColorScheme();
112
413
  const host = React.useRef(null);
113
414
  const root = React.useRef(null);
114
415
  const [map, setMap] = React.useState(null);
115
416
  const summaryId = React.useId();
116
- const latest = React.useRef({ onSelect });
117
- latest.current = { onSelect };
417
+ const latest = React.useRef({
418
+ onSelect,
419
+ onViewChange,
420
+ reportAppMoves,
421
+ settle,
422
+ picking,
423
+ onPick,
424
+ onPickCancel,
425
+ routes,
426
+ units,
427
+ view,
428
+ zoom
429
+ });
430
+ latest.current = {
431
+ onSelect,
432
+ onViewChange,
433
+ reportAppMoves,
434
+ settle,
435
+ picking,
436
+ onPick,
437
+ onPickCancel,
438
+ routes,
439
+ units,
440
+ view,
441
+ zoom
442
+ };
443
+ const [announced, setAnnounced] = React.useState("");
444
+ const [ready, setReady] = React.useState(false);
118
445
  const selectable = Boolean(onSelect);
119
- const markers = React.useRef(/* @__PURE__ */ new Map());
446
+ const posMarkers = React.useRef(/* @__PURE__ */ new Map());
120
447
  const source = (scheme === "dark" ? tiles.dark : void 0) ?? tiles.light;
121
448
  const treated = scheme === "dark" && !tiles.dark;
122
449
  const stops = React.useMemo(() => colourScale ? [...colourScale].sort((a, b) => a.at - b.at) : [], [colourScale]);
@@ -140,9 +467,10 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
140
467
  setMap(m);
141
468
  return () => {
142
469
  ro.disconnect();
143
- markers.current.clear();
470
+ posMarkers.current.clear();
144
471
  m.remove();
145
472
  setMap(null);
473
+ setReady(false);
146
474
  };
147
475
  }, []);
148
476
  React.useEffect(() => {
@@ -180,7 +508,8 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
180
508
  if (stops.length && r.values?.length) range = ` ${colourScaleLabel ?? "Value"} from ${formatValue(extent(r.values)[0])} to ${formatValue(extent(r.values)[1])}.`;
181
509
  return `${r.label}: ${format.distance(total, units)}${shape}.${range}${here}`;
182
510
  });
183
- return `Map with ${routes.length === 1 ? "one route" : `${routes.length} routes`}. ${parts.join(" ")}`;
511
+ const items = markers?.length ? ` ${markers.length === 1 ? "One marker" : `${markers.length} markers`}${markers.some((m) => m.selected) ? `, selected: ${markers.filter((m) => m.selected).map((m) => m.label).join(", ")}` : ""}.` : "";
512
+ return `Map with ${routes.length === 1 ? "one route" : `${routes.length} routes`}. ${parts.join(" ")}${items}`;
184
513
  }, [
185
514
  summary,
186
515
  routes,
@@ -188,7 +517,8 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
188
517
  units,
189
518
  stops.length,
190
519
  colourScaleLabel,
191
- formatValue
520
+ formatValue,
521
+ markers
192
522
  ]);
193
523
  React.useEffect(() => {
194
524
  if (!map) return;
@@ -242,7 +572,7 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
242
572
  opacity: dim ? .55 : 1,
243
573
  lineCap: "round",
244
574
  lineJoin: "round",
245
- interactive: selectable,
575
+ interactive: selectable && !picking,
246
576
  bubblingMouseEvents: false
247
577
  };
248
578
  const lines = [];
@@ -304,7 +634,7 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
304
634
  }
305
635
  }
306
636
  });
307
- for (const { marker } of markers.current.values()) marker.bringToFront();
637
+ for (const { marker } of posMarkers.current.values()) marker.bringToFront();
308
638
  return () => void group.remove();
309
639
  }, [
310
640
  map,
@@ -312,7 +642,8 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
312
642
  scheme,
313
643
  selectedId,
314
644
  stops,
315
- selectable
645
+ selectable,
646
+ picking
316
647
  ]);
317
648
  const target = React.useMemo(() => {
318
649
  if (!follow) return null;
@@ -340,17 +671,14 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
340
671
  const fit = () => {
341
672
  const size = map.getSize();
342
673
  if (fitted.current === routeKey || size.x === 0 || size.y === 0) return;
343
- const box = geo.bounds(routes.flatMap((r) => r.points));
344
- if (!box) return;
674
+ if (!geo.bounds(routes.flatMap((r) => r.points)) && !latest.current.view) return;
345
675
  fitted.current = routeKey;
346
- const view = latestView.current;
347
- if (view.zoom !== void 0) {
348
- const centre = view.centred && view.target || [(box[0][0] + box[1][0]) / 2, (box[0][1] + box[1][1]) / 2];
349
- map.setView(tuple(centre), view.zoom, { animate: false });
350
- } else map.fitBounds([tuple(box[0]), tuple(box[1])], {
351
- padding: [24, 24],
352
- animate: false,
353
- maxZoom: 17
676
+ const v = latestView.current;
677
+ setReady(true);
678
+ silently(map, () => {
679
+ if (latest.current.view) map.setView(tuple(latest.current.view.center), latest.current.view.zoom, { animate: false });
680
+ else if (v.zoom !== void 0 && v.centred && v.target) map.setView(tuple(v.target), v.zoom, { animate: false });
681
+ else showRoutes(map, latest.current.routes, v.zoom);
354
682
  });
355
683
  };
356
684
  fit();
@@ -358,12 +686,12 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
358
686
  return () => void map.off("resize", fit);
359
687
  }, [map, routeKey]);
360
688
  React.useEffect(() => {
361
- if (map && zoom !== void 0 && fitted.current !== null && map.getZoom() !== zoom) map.setZoom(zoom, { animate: false });
689
+ if (map && zoom !== void 0 && fitted.current !== null && map.getZoom() !== zoom) silently(map, () => map.setZoom(zoom, { animate: false }));
362
690
  }, [map, zoom]);
363
691
  React.useEffect(() => {
364
692
  if (!map) return;
365
693
  const el = map.getContainer();
366
- const live = markers.current;
694
+ const live = posMarkers.current;
367
695
  const seen = /* @__PURE__ */ new Set();
368
696
  for (const p of all) {
369
697
  if (!p.at) continue;
@@ -401,7 +729,7 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
401
729
  if (follow === "centre") {
402
730
  const z = zoom ?? (fitted.current === null ? void 0 : map.getZoom());
403
731
  if (z !== void 0) centre(map, target, z);
404
- } else if (!map.getBounds().pad(-.2).contains(tuple(target))) map.panTo(tuple(target), { animate: false });
732
+ } else if (!map.getBounds().pad(-.2).contains(tuple(target))) silently(map, () => map.panTo(tuple(target), { animate: false }));
405
733
  }, [
406
734
  map,
407
735
  all,
@@ -411,6 +739,241 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
411
739
  target,
412
740
  zoom
413
741
  ]);
742
+ React.useEffect(() => {
743
+ if (!map) return;
744
+ const control = resetControl(() => {
745
+ const view = latest.current.view;
746
+ if (view) map.setView(tuple(view.center), view.zoom, { animate: false });
747
+ else showRoutes(map, latest.current.routes, latest.current.zoom);
748
+ });
749
+ control.addTo(map);
750
+ return () => void control.remove();
751
+ }, [map]);
752
+ React.useEffect(() => {
753
+ if (!map) return;
754
+ let timer;
755
+ const send = () => {
756
+ timer = void 0;
757
+ const b = map.getBounds();
758
+ const c = map.getCenter();
759
+ latest.current.onViewChange?.({
760
+ bounds: [[b.getSouth(), b.getWest()], [b.getNorth(), b.getEast()]],
761
+ zoom: map.getZoom(),
762
+ center: [c.lat, c.lng]
763
+ });
764
+ };
765
+ const moved = () => {
766
+ if (!latest.current.onViewChange) return;
767
+ if (!latest.current.reportAppMoves && (quiet.get(map) ?? 0) > 0) return;
768
+ window.clearTimeout(timer);
769
+ timer = window.setTimeout(send, latest.current.settle);
770
+ };
771
+ map.on("moveend zoomend", moved);
772
+ if (fitted.current !== null && latest.current.reportAppMoves) moved();
773
+ return () => {
774
+ map.off("moveend zoomend", moved);
775
+ window.clearTimeout(timer);
776
+ };
777
+ }, [map]);
778
+ const [viewLat, viewLng, viewZoom] = view ? [
779
+ view.center[0],
780
+ view.center[1],
781
+ view.zoom
782
+ ] : [
783
+ null,
784
+ null,
785
+ null
786
+ ];
787
+ React.useEffect(() => {
788
+ if (!map || viewLat === null || viewLng === null || viewZoom === null || fitted.current === null) return;
789
+ const c = map.getCenter();
790
+ if (map.getZoom() === viewZoom && Math.abs(c.lat - viewLat) < 1e-7 && Math.abs(c.lng - viewLng) < 1e-7) return;
791
+ silently(map, () => map.setView([viewLat, viewLng], viewZoom, { animate: false }));
792
+ }, [
793
+ map,
794
+ viewLat,
795
+ viewLng,
796
+ viewZoom
797
+ ]);
798
+ const shared = useSharedCursor();
799
+ const cursorOn = Boolean(cursorProp) && shared !== null;
800
+ const cursorRouteId = typeof cursorProp === "object" && cursorProp.routeId ? cursorProp.routeId : routes[0]?.id;
801
+ const cursorRoute = routes.find((r) => r.id === cursorRouteId) ?? null;
802
+ const setPointer = shared?.setPointer;
803
+ React.useEffect(() => {
804
+ if (!map || !cursorOn || !cursorRoute || !setPointer) return;
805
+ const along = alongOf(cursorRoute.points);
806
+ const onMove = (e) => {
807
+ if (latest.current.picking) return;
808
+ const snap = geo.snap(cursorRoute.points, [e.latlng.lat, e.latlng.lng], along);
809
+ if (!snap) return;
810
+ const apart = map.latLngToContainerPoint(e.latlng).distanceTo(map.latLngToContainerPoint(tuple(snap.position)));
811
+ setPointer(apart <= 24 ? snap.metres : null);
812
+ };
813
+ const onOut = () => setPointer(null);
814
+ map.on("mousemove", onMove);
815
+ map.on("mouseout", onOut);
816
+ return () => {
817
+ map.off("mousemove", onMove);
818
+ map.off("mouseout", onOut);
819
+ setPointer(null);
820
+ };
821
+ }, [
822
+ map,
823
+ cursorOn,
824
+ cursorRoute,
825
+ setPointer
826
+ ]);
827
+ const otherAlong = cursorOn ? shared?.other ?? null : null;
828
+ const ring = React.useRef(null);
829
+ React.useEffect(() => {
830
+ if (!map) return;
831
+ const at = otherAlong !== null && cursorRoute ? geo.pointAlong(cursorRoute.points, otherAlong, alongOf(cursorRoute.points)) : null;
832
+ if (!at) {
833
+ ring.current?.remove();
834
+ ring.current = null;
835
+ return;
836
+ }
837
+ if (!ring.current) {
838
+ const el = map.getContainer();
839
+ ring.current = L.circleMarker(tuple(at), {
840
+ radius: 9,
841
+ weight: 3,
842
+ fillOpacity: 0,
843
+ interactive: false,
844
+ color: resolveColour(el, "var(--foreground)")
845
+ }).addTo(map);
846
+ } else ring.current.setLatLng(tuple(at));
847
+ }, [
848
+ map,
849
+ otherAlong,
850
+ cursorRoute
851
+ ]);
852
+ React.useEffect(() => () => void (ring.current = null), [map]);
853
+ const [tick, setTick] = React.useState(0);
854
+ React.useEffect(() => {
855
+ if (!map || !markers?.length) return;
856
+ const again = () => setTick((t) => t + 1);
857
+ map.on("moveend zoomend resize", again);
858
+ return () => void map.off("moveend zoomend resize", again);
859
+ }, [map, markers?.length]);
860
+ const placed = React.useMemo(() => map && ready && markers?.length ? placeMarkers(map, markers, routes) : [], [
861
+ map,
862
+ ready,
863
+ markers,
864
+ routes,
865
+ tick
866
+ ]);
867
+ React.useEffect(() => {
868
+ if (!map || !markers?.length) return;
869
+ const group = L.featureGroup().addTo(map);
870
+ const el = map.getContainer();
871
+ for (const m of markers) {
872
+ if (Array.isArray(m.at)) continue;
873
+ const at = m.at;
874
+ const index = routes.findIndex((r) => r.id === at.routeId);
875
+ if (index < 0) continue;
876
+ const route = routes[index];
877
+ const part = geo.slice(route.points, at.from, at.to, alongOf(route.points));
878
+ if (part.length < 2) continue;
879
+ const colour = m.colour ?? (m.highlighted ? "var(--success)" : m.selected ? "var(--foreground)" : route.colour ?? PALETTE[index % PALETTE.length]);
880
+ L.polyline(part.map(tuple), {
881
+ color: resolveColour(el, colour),
882
+ weight: (route.weight ?? 4) + (m.selected ? 5 : 3),
883
+ opacity: m.selected ? 1 : .8,
884
+ lineCap: "round",
885
+ interactive: false
886
+ }).addTo(group);
887
+ }
888
+ for (const p of placed) if (p.fanned) L.polyline([tuple(p.at), tuple(p.shown)], {
889
+ color: resolveColour(el, "var(--muted-foreground)"),
890
+ weight: 1,
891
+ dashArray: "2 3",
892
+ interactive: false
893
+ }).addTo(group);
894
+ for (const { marker } of posMarkers.current.values()) marker.bringToFront();
895
+ return () => void group.remove();
896
+ }, [
897
+ map,
898
+ markers,
899
+ routes,
900
+ placed,
901
+ scheme
902
+ ]);
903
+ React.useEffect(() => {
904
+ if (!map || !picking) return;
905
+ const el = map.getContainer();
906
+ el.classList.add("strata-map-picking");
907
+ map.keyboard.disable();
908
+ setAnnounced("Choose a place on the map. Arrow keys move the crosshair, Shift for bigger steps, Enter chooses, Escape cancels.");
909
+ let cross = null;
910
+ const showCross = (at) => {
911
+ if (!cross) cross = L.marker(at, {
912
+ interactive: false,
913
+ keyboard: false,
914
+ icon: L.divIcon({
915
+ className: "strata-map-crosshair",
916
+ html: CROSS_ICON,
917
+ iconSize: [32, 32],
918
+ iconAnchor: [16, 16]
919
+ })
920
+ }).addTo(map);
921
+ else cross.setLatLng(at);
922
+ };
923
+ const choose = (ll) => {
924
+ const at = [ll.lat, ll.lng];
925
+ const nearest = nearestRoute(latest.current.routes, at);
926
+ const route = nearest ? latest.current.routes.find((r) => r.id === nearest.routeId) : void 0;
927
+ setAnnounced(`Picked ${at[0].toFixed(5)}, ${at[1].toFixed(5)}.${nearest && route ? ` Nearest: ${route.label}, ${format.distance(nearest.alongM, latest.current.units)} along, ${format.distance(nearest.distanceM, latest.current.units)} from the route.` : ""}`);
928
+ latest.current.onPick?.(at, { nearest });
929
+ };
930
+ const onClick = (e) => {
931
+ cross?.remove();
932
+ cross = null;
933
+ choose(e.latlng);
934
+ };
935
+ const onKey = (e) => {
936
+ if (e.key === "Escape") {
937
+ e.preventDefault();
938
+ e.stopPropagation();
939
+ latest.current.onPickCancel?.();
940
+ return;
941
+ }
942
+ if (e.key === "Enter") {
943
+ e.preventDefault();
944
+ e.stopPropagation();
945
+ choose(cross ? cross.getLatLng() : map.getCenter());
946
+ return;
947
+ }
948
+ const step = e.shiftKey ? 50 : 10;
949
+ const d = {
950
+ ArrowLeft: [-step, 0],
951
+ ArrowRight: [step, 0],
952
+ ArrowUp: [0, -step],
953
+ ArrowDown: [0, step]
954
+ }[e.key];
955
+ if (!d) return;
956
+ e.preventDefault();
957
+ e.stopPropagation();
958
+ let to = map.latLngToContainerPoint(cross ? cross.getLatLng() : map.getCenter()).add(d);
959
+ const size = map.getSize();
960
+ const inside = L.point(Math.min(Math.max(to.x, 16), size.x - 16), Math.min(Math.max(to.y, 16), size.y - 16));
961
+ if (!inside.equals(to)) {
962
+ map.panBy(to.subtract(inside), { animate: false });
963
+ to = inside;
964
+ }
965
+ showCross(map.containerPointToLatLng(to));
966
+ };
967
+ map.on("click", onClick);
968
+ el.addEventListener("keydown", onKey);
969
+ return () => {
970
+ map.off("click", onClick);
971
+ el.removeEventListener("keydown", onKey);
972
+ cross?.remove();
973
+ el.classList.remove("strata-map-picking");
974
+ map.keyboard.enable();
975
+ };
976
+ }, [map, picking]);
414
977
  return /* @__PURE__ */ jsxs("div", {
415
978
  ref: root,
416
979
  "data-dark-treatment": treated ? "" : void 0,
@@ -425,17 +988,40 @@ function RouteMap({ label, routes, tiles, position = null, positionLabel = "Curr
425
988
  className: "sr-only",
426
989
  children: text
427
990
  }),
991
+ /* @__PURE__ */ jsx("p", {
992
+ role: "status",
993
+ "aria-live": "polite",
994
+ className: "sr-only",
995
+ children: announced
996
+ }),
997
+ map && placed.length > 0 && /* @__PURE__ */ jsx(MarkerLayer, {
998
+ map,
999
+ placed,
1000
+ onSelect: onMarkerSelect,
1001
+ card: renderMarkerCard
1002
+ }),
428
1003
  topEnd && /* @__PURE__ */ jsx("div", {
429
1004
  className: "absolute top-2 right-2 z-1000",
430
1005
  children: topEnd
431
1006
  }),
432
- (stops.length > 0 || bottomStart) && /* @__PURE__ */ jsxs("div", {
1007
+ picking && pickBanner && /* @__PURE__ */ jsx("div", {
1008
+ className: "absolute top-2 left-1/2 z-1000 max-w-[60%] -translate-x-1/2",
1009
+ children: pickBanner
1010
+ }),
1011
+ (stops.length > 0 || bottomStart || markers?.length && markerKey !== false) && /* @__PURE__ */ jsxs("div", {
433
1012
  className: "absolute bottom-6 left-2 z-1000 grid max-w-[60%] gap-2",
434
- children: [stops.length > 0 && /* @__PURE__ */ jsx(ColourKey, {
435
- stops,
436
- label: colourScaleLabel,
437
- formatValue
438
- }), bottomStart]
1013
+ children: [
1014
+ stops.length > 0 && /* @__PURE__ */ jsx(ColourKey, {
1015
+ stops,
1016
+ label: colourScaleLabel,
1017
+ formatValue
1018
+ }),
1019
+ markers && markers.length > 0 && markerKey !== false && /* @__PURE__ */ jsx(MarkerKey, {
1020
+ markers,
1021
+ words: markerKey
1022
+ }),
1023
+ bottomStart
1024
+ ]
439
1025
  })
440
1026
  ]
441
1027
  });
@@ -469,6 +1055,6 @@ function ColourKey({ stops, label, formatValue }) {
469
1055
  })]
470
1056
  });
471
1057
  }
472
- export { RouteMap };
1058
+ export { RouteMap, fanOut };
473
1059
 
474
1060
  //# sourceMappingURL=map.js.map