@motionstudies/web 0.1.0-alpha.5 → 0.1.0-alpha.7

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/README.md CHANGED
@@ -5,7 +5,7 @@ Shared packages for the Motion Studies transport instrument. The source workspac
5
5
  - `@motionstudies/core`: transport contracts, indexing, interpolation and visual theme contracts; no browser or Node dependencies.
6
6
  - `@motionstudies/three`: `NationalNetworkScene`, `HubPulseScene`, `StationFlowScene`, camera framing and label-mode contracts. React, React Three Fiber and Three.js are peers; rendering internals are not public subpaths.
7
7
  - `@motionstudies/web`: picker, button tooltips, theme application, mounting, progressive loaders, observed operations and recording. Import `tokens.css` and `mobile-picker.css` for isolated widgets. `shell.css` is an optional full-page study shell scoped to `.motion-study`; `mountMotionStudy` applies that class. Fonts and edition layouts belong to consumers.
8
- - `@motionstudies/data`: Node-only GTFS readers, network chunking, merging and station ranking. ZIP reading requires `unzip` on the host. Source selection, provenance overrides and compilation commands belong to each edition.
8
+ - `@motionstudies/data`: Node-only GTFS readers, ADS-B heatmap compilation, air endpoint enrichment, network chunking, merging and station ranking. ZIP reading requires `unzip` on the host. Source selection, provenance overrides and compilation commands belong to each edition.
9
9
 
10
10
  ```tsx
11
11
  import { MobilePicker } from '@motionstudies/web/components/MobilePicker'
@@ -25,6 +25,16 @@ Build release candidates with `npm run build:packages`. Distribution manifests a
25
25
 
26
26
  Source workspace manifests always stay private. `npm run check:release` builds public candidates, tests their packed consumer and records the tested tarball hashes; `npm run release:dry-run` inspects the publication without writing to npm. The manual main-branch `release.yml` workflow publishes those same tarballs with public access and provenance. See [release instructions](https://github.com/emmettl/motionstudies/blob/main/docs/RELEASING.md) for bootstrap-token and trusted-publisher setup. All four shared packages are MIT-licensed; each distribution includes `LICENSE`.
27
27
 
28
+ ## Now and browser location
29
+
30
+ `useNowClock` from `@motionstudies/web/use-now-clock` follows the wall clock on each animation frame, so returning from a suspended tab catches up immediately. Call `start()` from a Now button, set the consumer's playback rate to 1, and render its `time` while `active`. With `NationalNetworkScene`, pass `isPlaying={false}` while this external clock owns time. Call `stop()` before pausing, seeking or changing speed, and retain the last clock time for ordinary playback. Clear moving vehicle selections on entry to keep the camera still; panning and zooming remain available.
31
+
32
+ Supply a resolver `(instant: Date) => number | null` that maps the instant into the edition's service-time coordinates. The edition owns timezone, service date, daylight-saving rules and source coverage. Now is appropriate when the data gives a meaningful sense of this place at this time; exact live vehicle positions are not required. An edition may explicitly map the current local clock onto a suitable representative weekday or seasonal timetable, with a quiet label such as “Typical weekday · realtime pace”. Historical or modelled sources need that same meaningful relationship to the present; merely having timestamps is insufficient. Return null outside the chosen data's coverage: the hook stops, retains the last valid time and exposes `unavailable`. Do not silently relabel a recording as live or wrap a partial study window. Timetable and observed-data labels remain the consumer's responsibility; 1× playback does not imply a live vehicle feed.
33
+
34
+ `useBrowserLocation` from `@motionstudies/web/use-browser-location` requests a single position only when `locate()` is called. It exposes `location`, `status` and `clear()`; it neither stores nor sends coordinates. Render localized messages for denied, timeout and unavailable states. Clearing or unmounting discards late responses. A secure browser context and user permission are required.
35
+
36
+ Pass an in-coverage position as `NationalNetworkScene`'s `userLocation` for a steady glowing dot. Use the existing `focus-location` camera command once after locating, with `[longitude, latitude]` and a suitable `distanceScale`. Validate coverage in the consumer and preserve the view when the user is outside it. Show the reported `accuracy` in accessible text; the dot is an approximate position. The marker hides in diagram layouts. The lab's **Now** specimen uses a clearly labelled synthetic UTC timetable and covers clock, permission and out-of-coverage behavior. Public editions still require independent adoption and releases.
37
+
28
38
  ## Selection labels
29
39
 
30
40
  `NationalNetworkScene` gives the selected station first label priority, followed by the selected route's terminal stops (including branches), then intermediate stops. Selected services use their own endpoints. Priority precedes retained labels and ordinary rank/tier admission; clearing selection restores edition ranking. This is built in for every consumer, including geographic and diagram layouts. Supply complete enabled infrastructure as `referenceSnapshot` to preserve endpoints through timetable gaps; its stop indexes need not match the active snapshot. See the [edition behaviour contract](https://github.com/emmettl/motionstudies/blob/main/docs/EDITIONS.md#selection-and-station-labels).
@@ -73,3 +83,19 @@ Empty messages also appear on the flaps, in the widest column (the destination/o
73
83
  Rail and other transport consumers can share the same time filtering through `movementBoardWindow(study, horizon)` and `movementsForBoard(entries, window, maxRows)` from `@motionstudies/core/domain/movement-board`. Format the returned numeric times when mapping them into `SplitFlapBoard` cells. The lab's rail board follows the same study clock and horizon as its airport card.
74
84
 
75
85
  `@motionstudies/data/air-endpoints` provides offline `enrichAirEndpoints` for existing air manifests, chunks and opening snapshots. Supply cached same-date global ADSB.lol heatmaps, an OurAirports CSV and the service date's local UTC offset. It associates only unambiguous low-altitude endpoints near a reference airport; cruise-only traces and uncertain routes stay unknown. Optional `AirEndpoint` origin/destination fields carry airport identity, observed boundary time and `observed-endpoint` evidence. `airportBoardMovements` maps full manifest entries to board rows without confusing playback chunk boundaries with flight endpoints. Input hashes and source/licence attribution are recorded in fixture metadata. These fields describe inferred observations, never flight schedules, gates or live status.
86
+
87
+ ## Optional live airport feed
88
+
89
+ `AirportBoard` from `@motionstudies/web/components/AirportBoard` adds Study/Now controls around an existing `AirportHeroCard` configuration. Pass `studyCard` with the usual card props and `live={{ baseUrl, edition, airport }}` for the shared service. Import `airport-hero-card.css`. `labels` localizes the wrapper's control and availability messages. The lower-level `useAirportFeed` hook and core `domain/live-airport` contract are also public exports.
90
+
91
+ Live timestamps are Unix seconds and use the airport's timezone for display, independently of recorded service time. The wrapper does not pass live flight IDs to the recorded scene's selection callback. The recorded card remains mounted while hidden; the edition still owns playback and can pause its study when appropriate. Only Now mode fetches flight boards; checking capabilities does not query the paid provider. Stale results carry their retrieval time and disappear when expired. Source data never falls back to synthetic or recorded flights under a live label.
92
+
93
+ See [service architecture and operations](../docs/LIVE-AIRPORTS.md). The Worker is deployed separately; npm publication and edition adoption remain explicit release steps.
94
+
95
+ ## Shared recorded air compilation
96
+
97
+ `@motionstudies/data/adsb-heatmap` consolidates the offline heatmap pipeline previously copied between editions. `ingestAdsbHeatmaps` reads cached gzip slices, decodes observations, filters transport-scale tracks, splits flights, and writes either an opening snapshot or an indexed day with overlapping chunks. Source hashes, chunk hashes and ODbL attribution accompany the output. It makes no network requests.
98
+
99
+ The same `decodeAdsbHeatmap` now powers `enrichAirEndpoints`; endpoint inference retains full coordinate precision, while playback compilation retains the existing five-decimal coordinates. `transportAirTracks` and `chunkAirSnapshot` are also available for consumers that assemble their own pipeline. All functions have public TypeScript declarations and work in the packed Node package.
100
+
101
+ Editions supply geographic bounds, service date, explicit UTC offset, optional timezone, input files and output paths. Flight IDs and chunk overlap retain the existing contracts. The default splits known callsign changes and gaps over 30 minutes. Set `splitTracks: false` only when reproducing a legacy opening snapshot with one ID per aircraft. See [adoption and compatibility](../docs/AIR-DATA.md).
@@ -0,0 +1,27 @@
1
+ import { type AirportHeroCardProps } from './AirportHeroCard.tsx';
2
+ declare const defaults: {
3
+ study: string;
4
+ now: string;
5
+ checking: string;
6
+ unavailable: string;
7
+ returnToStudy: string;
8
+ loading: string;
9
+ updated: string;
10
+ stale: string;
11
+ localTime: string;
12
+ scheduled: string;
13
+ revised: string;
14
+ note: string;
15
+ };
16
+ export interface AirportBoardProps {
17
+ readonly studyCard: AirportHeroCardProps;
18
+ readonly live: {
19
+ readonly baseUrl: string;
20
+ readonly edition: string;
21
+ readonly airport: string;
22
+ };
23
+ readonly labels?: Partial<typeof defaults>;
24
+ }
25
+ /** Optional live enhancement. Keeps the study clock and recorded flight selection separate. */
26
+ export declare function AirportBoard({ studyCard, live, labels }: AirportBoardProps): import("react").JSX.Element;
27
+ export {};
@@ -0,0 +1,28 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { AirportHeroCard } from './AirportHeroCard.js';
4
+ import { useAirportFeed } from '../use-airport-feed.js';
5
+ import { useNowClock } from '../use-now-clock.js';
6
+ const defaults = {
7
+ study: 'Study', now: 'Now', checking: 'Checking live availability…', unavailable: 'Live updates unavailable.',
8
+ returnToStudy: 'Return to study', loading: 'Loading current airport board…', updated: 'Retrieved', stale: 'Updates delayed',
9
+ localTime: 'Local time', scheduled: 'Scheduled', revised: 'Revised', note: 'AeroDataBox · Scheduled or revised times as supplied. Revisions may be estimated or actual. All times local. Coverage may be incomplete.',
10
+ };
11
+ /** Optional live enhancement. Keeps the study clock and recorded flight selection separate. */
12
+ export function AirportBoard({ studyCard, live, labels }) {
13
+ const copy = { ...defaults, ...labels };
14
+ const clock = useNowClock((instant) => Math.floor(instant.getTime() / 1000));
15
+ const feed = useAirportFeed(live.baseUrl, live.edition, live.airport, clock.active);
16
+ const [selected, setSelected] = useState();
17
+ const response = feed.response, snapshot = response?.snapshot;
18
+ const now = clock.time ?? snapshot?.fetchedAt ?? 0;
19
+ const usable = snapshot && snapshot.expiresAt > now && ['fresh', 'stale'].includes(response.status);
20
+ const stale = usable && (response?.status === 'stale' || now >= snapshot.freshUntil);
21
+ const timeZone = snapshot?.airport.timeZone ?? 'UTC';
22
+ const formatter = new Intl.DateTimeFormat(undefined, { timeZone, hour: '2-digit', minute: '2-digit', hourCycle: 'h23' });
23
+ const formatTime = (time) => formatter.format(new Date(time * 1000));
24
+ const dateLabel = new Intl.DateTimeFormat(undefined, { timeZone, day: '2-digit', month: 'short', year: 'numeric' }).format(new Date(now * 1000));
25
+ function stop() { clock.stop(); setSelected(undefined); }
26
+ const selectedFlight = usable ? [...snapshot.departures, ...snapshot.arrivals].find((flight) => flight.id === selected) : undefined;
27
+ return _jsxs("div", { className: "ms-airport-board", children: [_jsxs("div", { className: "ms-airport-board__modes", role: "group", "aria-label": `${copy.study} / ${copy.now}`, children: [_jsx("button", { type: "button", "aria-pressed": !clock.active, onClick: stop, children: copy.study }), _jsx("button", { type: "button", "aria-pressed": clock.active, disabled: !clock.active && !feed.available, onClick: clock.start, children: copy.now }), !clock.active && _jsx("span", { children: feed.checking ? copy.checking : !feed.available ? copy.unavailable : null })] }), _jsx("div", { hidden: clock.active, children: _jsx(AirportHeroCard, { ...studyCard }) }), clock.active && _jsx(_Fragment, { children: usable ? _jsxs(_Fragment, { children: [_jsx(AirportHeroCard, { airport: snapshot.airport, study: { time: now, windowStart: snapshot.windowStart, windowEnd: snapshot.windowEnd }, departures: snapshot.departures.map((f) => ({ ...f, time: f.revisedTime ?? f.scheduledTime, stand: f.gate })), arrivals: snapshot.arrivals.map((f) => ({ ...f, time: f.revisedTime ?? f.scheduledTime, stand: f.gate })), formatTime: formatTime, dateLabel: dateLabel, labels: { ...studyCard.labels, studyTime: copy.localTime }, maxRows: studyCard.maxRows, horizon: studyCard.horizon, selectedFlightId: selected, onSelectFlight: setSelected, note: _jsxs(_Fragment, { children: [_jsxs("span", { role: "status", children: [stale ? `${copy.stale} · ` : '', copy.updated, " ", formatTime(snapshot.fetchedAt), " \u00B7 "] }), copy.note] }) }, snapshot.airport.iata), selectedFlight && _jsxs("p", { className: "ms-airport-board__detail", children: [selectedFlight.service, " \u00B7 ", selectedFlight.place ?? '—', " \u00B7 ", selectedFlight.status ?? '—', selectedFlight.scheduledTime !== undefined && _jsxs(_Fragment, { children: [" \u00B7 ", copy.scheduled, " ", formatTime(selectedFlight.scheduledTime)] }), selectedFlight.revisedTime !== undefined && _jsxs(_Fragment, { children: [" \u00B7 ", copy.revised, " ", formatTime(selectedFlight.revisedTime)] })] })] }) : _jsxs("div", { className: "ms-airport-board__unavailable", role: "status", children: [_jsx("p", { children: feed.loading || feed.checking ? copy.loading : copy.unavailable }), _jsx("button", { type: "button", onClick: stop, children: copy.returnToStudy })] }) })] });
28
+ }
@@ -1,4 +1,4 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId, useState } from 'react';
3
3
  import { formatServiceTime } from '@motionstudies/core/domain/network';
4
4
  import { movementBoardWindow, movementsForBoard } from '@motionstudies/core/domain/movement-board';
@@ -20,12 +20,12 @@ export function AirportHeroCard({ airport, departures, arrivals, note, study, ho
20
20
  const entries = movementsForBoard(direction === 'departures' ? departures : arrivals, window, maxRows);
21
21
  const rows = entries.map((entry) => ({ id: entry.id, tone: entry.tone,
22
22
  cells: { time: formatTime(entry.time), service: entry.service, place: entry.place, stand: entry.stand, status: entry.status } }));
23
- return _jsxs("section", { className: `ms-airport-hero ${className}`, "aria-labelledby": titleId, children: [_jsxs("div", { className: "ms-airport-hero__masthead", children: [_jsxs("span", { className: "ms-airport-hero__eyebrow", children: [_jsx("span", { "aria-hidden": "true", children: "\u2197" }), " ", copy.airport, " / ", airport.city] }), _jsxs("span", { className: "ms-airport-hero__clock", children: [dateLabel && _jsxs(_Fragment, { children: [dateLabel, " \u00B7 "] }), copy.studyTime, " ", Number.isFinite(study.time) ? formatTime(study.time) : '—'] })] }), _jsxs("div", { className: "ms-airport-hero__identity", children: [_jsx("strong", { className: "ms-airport-hero__code", children: airport.iata }), _jsx("h2", { id: titleId, children: airport.name }), _jsx("span", { className: "ms-airport-hero__runway", "aria-hidden": "true" })] }), _jsx("div", { className: "ms-airport-hero__directions", role: "group", "aria-label": `${copy.departures} / ${copy.arrivals}`, children: ['departures', 'arrivals'].map((value) => _jsxs("button", { type: "button", "aria-pressed": direction === value, "aria-controls": boardId, onClick: () => setDirection(value), children: [_jsx("span", { "aria-hidden": "true", children: value === 'departures' ? '↗' : '↘' }), " ", copy[value]] }, value)) }), _jsx("p", { className: "ms-airport-hero__window", children: window ? `${copy.boardWindow} ${formatTime(window.start)}–${formatTime(window.end)}` : copy.outsideWindow }), _jsx("div", { id: boardId, children: error ? _jsxs("div", { className: "ms-airport-hero__message", role: "status", children: [error, onRetry && _jsx("button", { type: "button", onClick: onRetry, children: copy.retry })] })
23
+ return _jsxs("section", { className: `ms-airport-hero ${className}`, "aria-labelledby": titleId, children: [_jsxs("div", { className: "ms-airport-hero__masthead", children: [_jsxs("span", { className: "ms-airport-hero__eyebrow", children: [_jsx("span", { "aria-hidden": "true", children: "\u2197" }), " ", copy.airport, " / ", airport.city] }), dateLabel && _jsx("span", { className: "ms-airport-hero__date", children: dateLabel })] }), _jsxs("div", { className: "ms-airport-hero__identity", children: [_jsx("strong", { className: "ms-airport-hero__code", children: airport.iata }), _jsx("h2", { id: titleId, children: airport.name }), _jsxs("div", { className: "ms-airport-hero__clock", children: [_jsx("span", { className: "ms-airport-hero__clock-label", children: copy.studyTime }), ' ', _jsx("strong", { className: "ms-airport-hero__clock-value", children: Number.isFinite(study.time) ? formatTime(study.time) : '—' })] })] }), _jsxs("div", { className: "ms-airport-hero__board-header", children: [_jsx("div", { className: "ms-airport-hero__directions", role: "group", "aria-label": `${copy.departures} / ${copy.arrivals}`, children: ['departures', 'arrivals'].map((value) => _jsxs("button", { type: "button", "aria-pressed": direction === value, "aria-controls": boardId, onClick: () => setDirection(value), children: [_jsx("span", { "aria-hidden": "true", children: value === 'departures' ? '↗' : '↘' }), " ", copy[value]] }, value)) }), _jsx("p", { className: "ms-airport-hero__window", children: window ? `${copy.boardWindow} ${formatTime(window.start)}–${formatTime(window.end)}` : copy.outsideWindow })] }), _jsx("div", { id: boardId, children: error ? _jsxs("div", { className: "ms-airport-hero__message", role: "status", children: [error, onRetry && _jsx("button", { type: "button", onClick: onRetry, children: copy.retry })] })
24
24
  : _jsx(SplitFlapBoard, { label: `${airport.iata} ${copy[direction]}`, columns: [
25
25
  { key: 'time', label: copy.time, characters: 5 },
26
26
  { key: 'service', label: copy.service, characters: 7 },
27
- { key: 'place', label: direction === 'departures' ? copy.destination : copy.origin, characters: 16 },
27
+ { key: 'place', label: direction === 'departures' ? copy.destination : copy.origin, characters: 18 },
28
28
  { key: 'stand', label: copy.stand, characters: 3 },
29
- { key: 'status', label: copy.status, characters: 10 },
29
+ { key: 'status', label: copy.status, characters: 11 },
30
30
  ], rows: rows, loading: loading, loadingMessage: copy.loading, loadingRows: rows.length || Math.min(maxRows, 5), emptyMessage: direction === 'departures' ? copy.emptyDepartures : copy.emptyArrivals, selectionColumn: "service", onSelectRow: onSelectFlight, selectedRowId: selectedFlightId }) }), _jsx("div", { className: "ms-airport-hero__note", children: note })] });
31
31
  }
@@ -1,21 +1,42 @@
1
1
  @import './split-flap-board.css';
2
2
 
3
- .ms-airport-hero { --airport-accent: #edc96b; color: #f0ecdd; background: linear-gradient(125deg, #292d27, #191d19 65%); border: 1px solid #4b4d40; border-radius: 12px; padding: clamp(16px, 3vw, 30px); box-shadow: 0 20px 60px #0003; font-family: ui-sans-serif, system-ui, sans-serif; min-width: 0; }
4
- .ms-airport-hero__masthead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
3
+ .ms-airport-hero { --airport-accent: #edc96b; container-type: inline-size; color: #f0ecdd; background: linear-gradient(125deg, #292d27, #191d19 65%); border: 1px solid #4b4d40; border-radius: 12px; padding: clamp(16px, 3vw, 30px); box-shadow: 0 20px 60px #0003; font-family: ui-sans-serif, system-ui, sans-serif; min-width: 0; }
4
+ .ms-airport-hero__masthead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; }
5
5
  .ms-airport-hero__eyebrow { color: var(--airport-accent); text-transform: uppercase; font-size: 10px; letter-spacing: .18em; }
6
6
  .ms-airport-hero__eyebrow > span { font-size: 18px; margin-right: 6px; }
7
- .ms-airport-hero__clock { color: #bebfac; font: 12px/1.5 ui-monospace, monospace; }
8
- .ms-airport-hero__window { color: #bebfac; font: 11px/1.5 ui-monospace, monospace; margin: 0 0 12px; }
9
- .ms-airport-hero__identity { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 24px; padding: 22px 0 26px; }
10
- .ms-airport-hero__code { color: var(--airport-accent); font-size: clamp(54px, 8vw, 88px); font-weight: 650; line-height: .95; letter-spacing: -.065em; }
11
- .ms-airport-hero__identity h2 { flex: 1; min-width: 140px; max-width: 300px; color: #f0ecdd; font: 400 clamp(20px, 3vw, 27px)/1.15 ui-sans-serif, system-ui, sans-serif; letter-spacing: -.025em; margin: 0; overflow-wrap: anywhere; }
12
- .ms-airport-hero__runway { margin-left: auto; width: 54px; height: 62px; border-inline: 1px solid #797c6166; transform: skewY(-20deg); background: repeating-linear-gradient(to bottom, #b5b79266 0 8px, transparent 8px 16px) center / 2px 100% no-repeat; }
13
- .ms-airport-hero__directions { display: flex; gap: 22px; border-bottom: 1px solid #4b4d40; margin-bottom: 16px; }
14
- .ms-airport-hero__directions button { padding: 10px 0 12px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: #b8baaa; font: 500 13px/1.4 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
7
+ .ms-airport-hero__date { color: #bebfac; font: 11px/1.5 ui-monospace, monospace; letter-spacing: .06em; }
8
+ .ms-airport-hero__identity { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 18px 24px; padding: 18px 0 20px; }
9
+ .ms-airport-hero__code { color: var(--airport-accent); font-size: clamp(54px, 10cqi, 82px); font-weight: 650; line-height: .95; letter-spacing: -.065em; }
10
+ .ms-airport-hero__identity h2 { max-width: 300px; color: #f0ecdd; font: 400 clamp(20px, 3.3cqi, 27px)/1.15 ui-sans-serif, system-ui, sans-serif; letter-spacing: -.025em; margin: 0; overflow-wrap: anywhere; }
11
+ .ms-airport-hero__clock { padding-left: 24px; border-left: 1px solid #797c6155; text-align: right; }
12
+ .ms-airport-hero__clock-label { display: block; color: #bebfac; font-size: 10px; line-height: 1.5; letter-spacing: .12em; text-transform: uppercase; }
13
+ .ms-airport-hero__clock-value { display: block; margin-top: 4px; color: #f0ecdd; font: 400 42px/1.1 ui-monospace, monospace; font-variant-numeric: tabular-nums; letter-spacing: -.06em; white-space: nowrap; }
14
+ .ms-airport-hero__board-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0 20px; border-bottom: 1px solid #4b4d40; margin-bottom: 14px; }
15
+ .ms-airport-hero__directions { display: flex; gap: 22px; }
16
+ .ms-airport-hero__directions button { min-height: 44px; padding: 10px 0 12px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: #b8baaa; font: 500 13px/1.4 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
15
17
  .ms-airport-hero__directions button[aria-pressed='true'] { color: var(--airport-accent); border-bottom-color: var(--airport-accent); }
16
18
  .ms-airport-hero__directions button:hover { color: #f0ecdd; }
19
+ .ms-airport-hero__window { color: #bebfac; font: 11px/1.5 ui-monospace, monospace; font-variant-numeric: tabular-nums; margin: 8px 0; }
17
20
  .ms-airport-hero button:focus-visible { outline: 2px solid var(--airport-accent); outline-offset: 4px; }
21
+ .ms-airport-hero .ms-flap { font-size: 17px; }
22
+ .ms-airport-hero .ms-split-flap-board__table th { color: #c4c3b0; font-size: 11px; letter-spacing: .12em; padding-bottom: 5px; }
18
23
  .ms-airport-hero__message { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 30px 0; margin: 0; font-size: 14px; color: #c5c7b6; }
19
24
  .ms-airport-hero__message button { background: #30352a; border: 1px solid #666b50; border-radius: 4px; color: var(--airport-accent); padding: 6px 12px; font: inherit; cursor: pointer; }
20
25
  .ms-airport-hero__note { color: #b8baaa; font-size: 11px; line-height: 1.6; margin-top: 14px; }
21
- @media (max-width: 480px) { .ms-airport-hero__runway { display: none; } .ms-airport-hero__directions { gap: 18px; } }
26
+ @container (max-width: 600px) {
27
+ .ms-airport-hero__identity { grid-template-columns: auto minmax(0, 1fr); gap: 16px; }
28
+ .ms-airport-hero__clock { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 0 0; border-left: 0; border-top: 1px solid #797c6155; text-align: left; }
29
+ .ms-airport-hero__clock-value { margin-top: 0; font-size: 32px; }
30
+ }
31
+ @container (max-width: 440px) {
32
+ .ms-airport-hero__board-header { gap: 4px; }
33
+ .ms-airport-hero__directions { width: 100%; gap: 20px; }
34
+ .ms-airport-hero__window { margin: 6px 0 10px; }
35
+ }
36
+ .ms-airport-board__modes { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; color: #b8baaa; font: 12px/1.5 ui-sans-serif, system-ui, sans-serif; }
37
+ .ms-airport-board__modes button, .ms-airport-board__unavailable button { min-height: 44px; padding: 8px 16px; border: 1px solid #4b4d40; border-radius: 6px; color: #f0ecdd; background: #1d211c; font: inherit; cursor: pointer; }
38
+ .ms-airport-board__modes button[aria-pressed='true'] { border-color: #edc96b; color: #edc96b; }
39
+ .ms-airport-board__modes button:disabled { opacity: .5; cursor: default; }
40
+ .ms-airport-board__modes button:focus-visible, .ms-airport-board__unavailable button:focus-visible { outline: 2px solid #edc96b; outline-offset: 3px; }
41
+ .ms-airport-board__unavailable { padding: 28px; border: 1px solid #4b4d40; border-radius: 12px; color: #f0ecdd; background: #1d211c; font: 14px/1.6 ui-sans-serif, system-ui, sans-serif; }
42
+ .ms-airport-board__detail { color: #b8baaa; font: 13px/1.6 ui-sans-serif, system-ui, sans-serif; overflow-wrap: anywhere; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionstudies/web",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Browser controls and loaders for Motion Studies.",
@@ -20,6 +20,16 @@
20
20
  "tag": "next"
21
21
  },
22
22
  "exports": {
23
+ "./use-now-clock": {
24
+ "types": "./use-now-clock.d.ts",
25
+ "import": "./use-now-clock.js",
26
+ "default": "./use-now-clock.js"
27
+ },
28
+ "./use-browser-location": {
29
+ "types": "./use-browser-location.d.ts",
30
+ "import": "./use-browser-location.js",
31
+ "default": "./use-browser-location.js"
32
+ },
23
33
  "./components/SplitFlapBoard": {
24
34
  "types": "./components/SplitFlapBoard.d.ts",
25
35
  "import": "./components/SplitFlapBoard.js",
@@ -89,6 +99,16 @@
89
99
  "types": "./components/ButtonTooltips.d.ts",
90
100
  "import": "./components/ButtonTooltips.js",
91
101
  "default": "./components/ButtonTooltips.js"
102
+ },
103
+ "./use-airport-feed": {
104
+ "types": "./use-airport-feed.d.ts",
105
+ "import": "./use-airport-feed.js",
106
+ "default": "./use-airport-feed.js"
107
+ },
108
+ "./components/AirportBoard": {
109
+ "types": "./components/AirportBoard.d.ts",
110
+ "import": "./components/AirportBoard.js",
111
+ "default": "./components/AirportBoard.js"
92
112
  }
93
113
  },
94
114
  "files": [
@@ -104,7 +124,7 @@
104
124
  "**/*.css"
105
125
  ],
106
126
  "dependencies": {
107
- "@motionstudies/core": "0.1.0-alpha.5"
127
+ "@motionstudies/core": "0.1.0-alpha.7"
108
128
  },
109
129
  "peerDependencies": {
110
130
  "react": "^19.2.8",
@@ -0,0 +1,9 @@
1
+ import { type AirportFeedResponse } from '@motionstudies/core/domain/live-airport';
2
+ export interface AirportFeedState {
3
+ readonly available: boolean;
4
+ readonly checking: boolean;
5
+ readonly loading: boolean;
6
+ readonly response?: AirportFeedResponse;
7
+ }
8
+ /** Fetch capabilities without paid work; poll boards only while Now is selected. */
9
+ export declare function useAirportFeed(baseUrl: string, edition: string, airport: string, enabled: boolean): AirportFeedState;
@@ -0,0 +1,72 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { isAirportFeedResponse } from '@motionstudies/core/domain/live-airport';
3
+ /** Fetch capabilities without paid work; poll boards only while Now is selected. */
4
+ export function useAirportFeed(baseUrl, edition, airport, enabled) {
5
+ const source = `${baseUrl.replace(/\/$/, '')}/api/airports/v1/${encodeURIComponent(edition)}`;
6
+ const identity = `${source}/${airport}/${enabled}`;
7
+ const empty = { available: false, checking: true, loading: false };
8
+ const [stored, setStored] = useState({ ...empty, identity });
9
+ const state = stored.identity === identity ? stored : empty;
10
+ useEffect(() => {
11
+ const controller = new AbortController();
12
+ let timer, failures = 0;
13
+ const update = (patch) => {
14
+ if (!controller.signal.aborted)
15
+ setStored((old) => ({ ...(old.identity === identity ? old : empty), ...patch, identity }));
16
+ };
17
+ update(empty);
18
+ const tick = async () => {
19
+ let delay = 60_000;
20
+ if (document.hidden) {
21
+ timer = window.setTimeout(() => void tick(), delay);
22
+ return;
23
+ }
24
+ try {
25
+ const options = { cache: 'no-store', signal: AbortSignal.any([controller.signal, AbortSignal.timeout(20_000)]) };
26
+ const capabilitiesResponse = await fetch(`${source}/capabilities`, options);
27
+ if (!capabilitiesResponse.ok)
28
+ throw new Error('Capabilities unavailable');
29
+ const capabilities = await capabilitiesResponse.json();
30
+ if (capabilities.version !== 1 || typeof capabilities.enabled !== 'boolean' || !Array.isArray(capabilities.airports))
31
+ throw new Error('Invalid capabilities');
32
+ const available = capabilities.enabled && capabilities.airports.includes(airport);
33
+ update({ available, checking: false });
34
+ if (!available) {
35
+ update({ loading: false, response: { version: 1, status: 'disabled', reason: 'disabled', retryAfterSeconds: 60 } });
36
+ }
37
+ else if (enabled) {
38
+ update({ loading: true });
39
+ const r = await fetch(`${source}/${encodeURIComponent(airport)}/board`, options);
40
+ const response = await r.json();
41
+ if (!isAirportFeedResponse(response))
42
+ throw new Error('Invalid board');
43
+ if (response.snapshot && (response.snapshot.airport.iata !== airport || response.snapshot.fetchedAt > Date.now() / 1000 + 60))
44
+ throw new Error('Mismatched board');
45
+ update({ response, loading: false, available: response.status !== 'disabled' });
46
+ // Check capabilities every minute even when the upstream circuit is paused.
47
+ }
48
+ failures = 0;
49
+ }
50
+ catch {
51
+ failures += 1;
52
+ delay = Math.min(300_000, 30_000 * 2 ** Math.min(failures, 4));
53
+ if (!controller.signal.aborted)
54
+ setStored((old) => {
55
+ const snapshot = old.identity === identity ? old.response?.snapshot : undefined;
56
+ return { identity, available: old.identity === identity && old.available, checking: false, loading: false,
57
+ response: { version: 1, status: snapshot && snapshot.expiresAt > Date.now() / 1000 ? 'stale' : 'unavailable', reason: 'provider', retryAfterSeconds: delay / 1000,
58
+ ...(snapshot && snapshot.expiresAt > Date.now() / 1000 ? { snapshot } : {}) } };
59
+ });
60
+ }
61
+ finally {
62
+ if (!controller.signal.aborted)
63
+ timer = window.setTimeout(() => void tick(), delay);
64
+ }
65
+ };
66
+ void tick();
67
+ return () => { controller.abort(); window.clearTimeout(timer); };
68
+ // empty is deliberately reconstructed only when the source effect restarts.
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, [identity, source, airport, enabled]);
71
+ return state;
72
+ }
@@ -0,0 +1,13 @@
1
+ export interface BrowserLocation {
2
+ readonly longitude: number;
3
+ readonly latitude: number;
4
+ readonly accuracy: number;
5
+ }
6
+ export type BrowserLocationStatus = 'idle' | 'locating' | 'ready' | 'denied' | 'timeout' | 'unavailable';
7
+ /** One explicit request, kept in memory. Clearing or unmounting ignores late replies. */
8
+ export declare function useBrowserLocation(): {
9
+ location: BrowserLocation | undefined;
10
+ status: BrowserLocationStatus;
11
+ locate: () => void;
12
+ clear: () => void;
13
+ };
@@ -0,0 +1,39 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ /** One explicit request, kept in memory. Clearing or unmounting ignores late replies. */
3
+ export function useBrowserLocation() {
4
+ const [location, setLocation] = useState();
5
+ const [status, setStatus] = useState('idle');
6
+ const request = useRef(0);
7
+ useEffect(() => () => { request.current += 1; }, []);
8
+ const clear = useCallback(() => {
9
+ request.current += 1;
10
+ setLocation(undefined);
11
+ setStatus('idle');
12
+ }, []);
13
+ const locate = useCallback(() => {
14
+ const id = ++request.current;
15
+ setLocation(undefined);
16
+ if (!navigator.geolocation) {
17
+ setStatus('unavailable');
18
+ return;
19
+ }
20
+ setStatus('locating');
21
+ navigator.geolocation.getCurrentPosition(({ coords }) => {
22
+ if (request.current !== id)
23
+ return;
24
+ if (!Number.isFinite(coords.longitude) || !Number.isFinite(coords.latitude) ||
25
+ Math.abs(coords.longitude) > 180 || Math.abs(coords.latitude) > 90 ||
26
+ !Number.isFinite(coords.accuracy) || coords.accuracy < 0) {
27
+ setStatus('unavailable');
28
+ return;
29
+ }
30
+ setLocation({ longitude: coords.longitude, latitude: coords.latitude, accuracy: coords.accuracy });
31
+ setStatus('ready');
32
+ }, (error) => {
33
+ if (request.current !== id)
34
+ return;
35
+ setStatus(error.code === 1 ? 'denied' : error.code === 3 ? 'timeout' : 'unavailable');
36
+ }, { enableHighAccuracy: false, maximumAge: 0, timeout: 10_000 });
37
+ }, []);
38
+ return { location, status, locate, clear };
39
+ }
@@ -0,0 +1,11 @@
1
+ /** The consumer maps an instant into its own service date, timezone and data window.
2
+ * The consumer may explicitly choose a representative timetable for the present.
3
+ * Return null when its data cannot meaningfully represent that instant.
4
+ */
5
+ export declare function useNowClock(resolveTime: (instant: Date) => number | null): {
6
+ active: boolean;
7
+ time: number | null;
8
+ unavailable: boolean;
9
+ start: () => void;
10
+ stop: () => void;
11
+ };
@@ -0,0 +1,45 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ /** The consumer maps an instant into its own service date, timezone and data window.
3
+ * The consumer may explicitly choose a representative timetable for the present.
4
+ * Return null when its data cannot meaningfully represent that instant.
5
+ */
6
+ export function useNowClock(resolveTime) {
7
+ const [active, setActive] = useState(false);
8
+ const [time, setTime] = useState(null);
9
+ const [unavailable, setUnavailable] = useState(false);
10
+ const running = useRef(false);
11
+ const resolver = useRef(resolveTime);
12
+ useLayoutEffect(() => { resolver.current = resolveTime; }, [resolveTime]);
13
+ const update = useCallback(() => {
14
+ const next = resolver.current(new Date());
15
+ if (next === null || !Number.isFinite(next)) {
16
+ running.current = false;
17
+ setActive(false);
18
+ setUnavailable(true);
19
+ return false;
20
+ }
21
+ setTime(next);
22
+ return true;
23
+ }, []);
24
+ const start = useCallback(() => {
25
+ setUnavailable(false);
26
+ running.current = update();
27
+ setActive(running.current);
28
+ }, [update]);
29
+ const stop = useCallback(() => {
30
+ running.current = false;
31
+ setActive(false);
32
+ }, []);
33
+ useEffect(() => {
34
+ if (!active)
35
+ return;
36
+ let frame;
37
+ const tick = () => {
38
+ if (running.current && update())
39
+ frame = requestAnimationFrame(tick);
40
+ };
41
+ frame = requestAnimationFrame(tick);
42
+ return () => cancelAnimationFrame(frame);
43
+ }, [active, update]);
44
+ return { active, time, unavailable, start, stop };
45
+ }