Shared types and helpers: vehicles, freshness, distance, clocks.
Bars show time since the last GPS ping; the ticks are freshnessOf's defaults: stale after 2 min, offline after 10 min.
$ npx shadcn@latest add @highcommand/fleet-coreCopies the source into your project and pulls in what it needs. First time? Add the registry to components.json.
freshnessOf(ageMs: number, staleAfterMs?: number, offlineAfterMs?: number): Freshness`live`, `stale` or `offline` for a ping this many ms old, using the stale/offline cutoffs (defaults 2 and 10 minutes).
formatAge(ageMs: number): string"45s", "4m", "2h", "3d"
formatClock(ms: number): string"2:05 PM" in the viewer's locale.
plainSpaces(s: string): stringNode and browsers disagree on the spaces Intl puts in times (U+202F vs U+0020), which breaks SSR hydration. Normalize to plain spaces.
lerpAngle(from: number, to: number, t: number): numberShortest-path interpolation between two headings, result in [0, 360).
distanceMeters(a: LngLat, b: LngLat): numberGreat-circle distance in meters.
countByFreshness(vehicles: Vehicle[], now: number, staleAfterMs?: number, offlineAfterMs?: number): Record<Freshness, number>How many vehicles are live, stale and offline at `now` (epoch ms), from each vehicle's `lastSeen`.
toFeatureCollection(vehicles: Vehicle[], now: number, staleAfterMs?: number, offlineAfterMs?: number, visible?: Freshness[] | undefined): FeatureCollection<Point, GeoJsonProperties>GeoJSON points for a MapLibre source (properties: id, label, freshness, age text, heading when known); `visible` keeps only those freshness states.
useNow(tickMs?: number, override?: number | undefined): numberCurrent time that re-renders every `tickMs`. Pass `override` to freeze it (replays, tests). Starts at 0 until mounted so SSR output is stable.
Install this free piece now; the Pro pieces drop in on top of it, in the same app. Pro is $79 once.