@motionstudies/core 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,42 @@
1
+ /** Live boards use Unix seconds throughout, independent of an edition's recorded service day. */
2
+ export interface LiveAirportMovement {
3
+ readonly id: string;
4
+ readonly service: string;
5
+ readonly scheduledTime?: number;
6
+ /** Provider revision: may be estimated or actual; do not relabel as confirmed. */
7
+ readonly revisedTime?: number;
8
+ readonly place?: string;
9
+ readonly gate?: string;
10
+ readonly status?: string;
11
+ readonly tone?: 'neutral' | 'accent' | 'warning';
12
+ }
13
+ export interface LiveAirportSnapshot {
14
+ readonly airport: {
15
+ readonly iata: string;
16
+ readonly name: string;
17
+ readonly city: string;
18
+ readonly timeZone: string;
19
+ };
20
+ readonly fetchedAt: number;
21
+ readonly freshUntil: number;
22
+ readonly expiresAt: number;
23
+ readonly windowStart: number;
24
+ readonly windowEnd: number;
25
+ readonly departures: readonly LiveAirportMovement[];
26
+ readonly arrivals: readonly LiveAirportMovement[];
27
+ }
28
+ export type AirportFeedReason = 'disabled' | 'not-configured' | 'subscription' | 'budget' | 'provider' | 'rate-limit';
29
+ export interface AirportFeedResponse {
30
+ readonly version: 1;
31
+ readonly status: 'fresh' | 'stale' | 'unavailable' | 'disabled';
32
+ readonly reason?: AirportFeedReason;
33
+ readonly retryAfterSeconds: number;
34
+ readonly snapshot?: LiveAirportSnapshot;
35
+ }
36
+ export interface AirportFeedCapabilities {
37
+ readonly version: 1;
38
+ readonly enabled: boolean;
39
+ readonly airports: readonly string[];
40
+ }
41
+ /** Validate the network boundary before publishing data to a card. */
42
+ export declare function isAirportFeedResponse(value: unknown): value is AirportFeedResponse;
@@ -0,0 +1,32 @@
1
+ const record = (value) => !!value && typeof value === 'object';
2
+ const finite = (value) => typeof value === 'number' && Number.isFinite(value);
3
+ function movement(value) {
4
+ return record(value) && typeof value.id === 'string' && typeof value.service === 'string'
5
+ && ['scheduledTime', 'revisedTime'].every((key) => value[key] === undefined || finite(value[key]))
6
+ && ['place', 'gate', 'status'].every((key) => value[key] === undefined || typeof value[key] === 'string')
7
+ && (value.tone === undefined || ['neutral', 'accent', 'warning'].includes(String(value.tone)));
8
+ }
9
+ /** Validate the network boundary before publishing data to a card. */
10
+ export function isAirportFeedResponse(value) {
11
+ if (!record(value) || value.version !== 1 || !['fresh', 'stale', 'unavailable', 'disabled'].includes(String(value.status))
12
+ || !finite(value.retryAfterSeconds) || value.retryAfterSeconds < 0)
13
+ return false;
14
+ if (value.status === 'disabled' || value.status === 'unavailable')
15
+ return value.snapshot === undefined;
16
+ const s = value.snapshot;
17
+ try {
18
+ if (!record(s) || !record(s.airport) || typeof s.airport.timeZone !== 'string')
19
+ return false;
20
+ new Intl.DateTimeFormat('en', { timeZone: s.airport.timeZone }).format(0);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ return record(s) && record(s.airport)
26
+ && ['iata', 'name', 'city', 'timeZone'].every((key) => typeof s.airport[key] === 'string')
27
+ && ['fetchedAt', 'freshUntil', 'expiresAt', 'windowStart', 'windowEnd'].every((key) => finite(s[key]))
28
+ && Number(s.fetchedAt) <= Number(s.freshUntil) && Number(s.freshUntil) <= Number(s.expiresAt)
29
+ && Number(s.windowStart) < Number(s.windowEnd)
30
+ && Array.isArray(s.departures) && s.departures.every(movement)
31
+ && Array.isArray(s.arrivals) && s.arrivals.every(movement);
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionstudies/core",
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": "Transport contracts and motion primitives for Motion Studies.",
@@ -144,6 +144,11 @@
144
144
  "types": "./domain/train-time-index.d.ts",
145
145
  "import": "./domain/train-time-index.js",
146
146
  "default": "./domain/train-time-index.js"
147
+ },
148
+ "./domain/live-airport": {
149
+ "types": "./domain/live-airport.d.ts",
150
+ "import": "./domain/live-airport.js",
151
+ "default": "./domain/live-airport.js"
147
152
  }
148
153
  },
149
154
  "files": [