diff --git a/src/data/entityContext.js b/src/data/entityContext.js new file mode 100644 index 000000000..78fe791bc --- /dev/null +++ b/src/data/entityContext.js @@ -0,0 +1,1249 @@ +import { getContextStore } from './contextStore.js'; + +/** + * One way to read any thing on the map, whichever layer holds it. + * + * Layers already list their loaded items through `getAnalystRecords()` (the + * records voice and the analyst answer from) and identify a clicked item + * through `resolvePickedContext()`. This module joins the two: it finds the + * record behind an identity, turns it into a card (title, kind, facts), lists + * the nearest items of the same kind and of other layers, and searches every + * enabled layer by name for the omnibar. + * + * It reads only; nothing here moves the camera or changes a layer. + */ + +/** + * How a layer's items are named and drawn, by layer id. `headline` names the + * fields that lead a card as its big figures, in order; `name` is what an + * item without a name of its own goes by. + */ +const AIRCRAFT = { kind: 'aircraft', icon: 'flight', moving: true, headline: ['altitudeM', 'speedMps', 'heading'] }; +const KINDS = Object.freeze({ + flights: AIRCRAFT, + military: AIRCRAFT, + 'local-adsb': AIRCRAFT, + 'ais-live-vessels': { kind: 'vessel', icon: 'directions_boat', moving: true, headline: ['speedKts', 'courseDeg', 'navStatus'] }, + satellites: { kind: 'satellite', icon: 'satellite_alt', moving: true, headline: ['altitudeM', 'speedMps'] }, + 'rocket-launches': { kind: 'launch', icon: 'rocket_launch' }, + 'local-firms': { kind: 'fire', icon: 'local_fire_department', headline: ['frp', 'confidence'], name: 'Fire detection' }, + 'fire-perimeters': { kind: 'fire perimeter', icon: 'local_fire_department', headline: ['acres', 'containedPct'] }, + earthquakes: { kind: 'earthquake', icon: 'earthquake', headline: ['magnitude', 'depthKm'] }, + 'weather-cyclones': { kind: 'storm', icon: 'cyclone', headline: ['windKt', 'pressureHpa'] }, + 'air-quality': { kind: 'air quality station', icon: 'air', headline: ['value', 'band'] }, + 'military-installations': { kind: 'installation', icon: 'factory' }, + 'local-dams': { kind: 'dam', icon: 'factory', headline: ['capacity'] }, + 'local-datacenters': { kind: 'data centre', icon: 'factory', headline: ['capacity'] }, + 'osm-places': { kind: 'place', icon: 'location_on' }, + transit: { kind: 'vehicle', icon: 'train', moving: true, headline: ['speedMps', 'courseDeg'] }, + bikeshare: { kind: 'bike station', icon: 'pedal_bike', headline: ['bikesAvailable', 'docksAvailable'] }, + 'alpr-cameras': { kind: 'plate reader', icon: 'videocam' }, + cctv: { kind: 'camera', icon: 'videocam' }, + 'drone-airspace': { kind: 'airspace', icon: 'pentagon', headline: ['lowerAltitude', 'upperAltitude'] }, + 'wildlife-sightings': { kind: 'sighting', icon: 'pets' }, +}); + +/** Fields a record may name itself by, best first. */ +const TITLE_FIELDS = [ + 'callsign', + 'name', + 'title', + 'label', + 'place', + 'registration', +]; +/** Fields that identify an item, for matching a click or a search. */ +const KEY_FIELDS = ['icao24', 'mmsi', 'noradId', 'usgsId', 'id']; +/** + * How many records to ask a layer for when all are wanted. Layers read a + * missing or unbounded count as their own small default, so this is a number + * above any layer's size. + */ +const ALL_RECORDS = 100_000; +/** Fields searched by the omnibar, besides the key fields. */ +const SEARCH_FIELDS = ['callsign', 'name', 'registration', 'place', 'operator', 'icao24', 'mmsi']; + +/** Never shown as facts: positions and identities already on the card. */ +const HIDDEN_FACTS = new Set([ + // Shown as the card's route line instead. + 'routeOrigin', + 'routeDestination', + 'routeFrom', + 'routeTo', + 'routeScheduled', + // Shown as the card's warning instead. + 'emergency', + 'emergencyKind', + 'emergencySource', + 'emergencyBroadcast', + 'tsunami', + 'warning', + 'alert', + 'advisory', + 'id', + 'lat', + 'lon', + 'latitude', + 'longitude', + 'name', + 'title', + 'label', + 'properties', + 'tags', + 'emergency', + 'emergencySource', + 'emergencyKind', + 'military', + // Repeats of what another fact already says, and feed bookkeeping. + 'vesselId', + 'typeCode', + 'group', + 'provider', + 'zone', + 'scale', + 'routeId', + 'building', +]); + +/** Facts that lead the list when a record has them, in this order. */ +const FACT_ORDER = [ + 'callsign', + 'registration', + 'operator', + 'aircraftClass', + 'routeOrigin', + 'routeDestination', + 'altitudeM', + 'speedMps', + 'speedKts', + 'heading', + 'courseDeg', + 'squawk', + 'emergencyBroadcast', + 'shipType', + 'destination', + 'magnitude', + 'depthKm', + 'place', + 'frp', + 'confidence', + 'acres', + 'containedPct', + 'windKt', + 'pressureHpa', + 'classification', + 'value', + 'band', + 'risk', + 'bikesAvailable', + 'docksAvailable', + 'lowerAltitude', + 'upperAltitude', + 'satellite', + 'sensor', + 'noradId', + 'satelliteClass', + 'mmsi', + 'icao24', + 'capacity', + 'output', + 'river', + 'class', + 'kind', + 'originCountry', +]; + +/** Plain labels for record fields. Unlisted fields are spelled out. */ +const FACT_LABELS = Object.freeze({ + callsign: 'Callsign', + registration: 'Registration', + operator: 'Operator', + aircraftClass: 'Aircraft class', + routeOrigin: 'From', + routeDestination: 'To', + altitudeM: 'Altitude', + speedMps: 'Speed', + speedKts: 'Speed', + heading: 'Heading', + courseDeg: 'Course', + verticalRateMps: 'Vertical rate', + squawk: 'Squawk', + emergencyBroadcast: 'Emergency', + onGround: 'On the ground', + originCountry: 'Country', + lastContactAtMs: 'Last contact', + shipType: 'Ship type', + destination: 'Destination', + navStatus: 'Status', + magnitude: 'Magnitude', + depthKm: 'Depth', + timeMs: 'Time', + place: 'Place', + frp: 'Fire power', + confidence: 'Confidence', + satellite: 'Satellite', + sensor: 'Sensor', + acqTime: 'Detected', + acres: 'Area', + containedPct: 'Contained', + discoveredTime: 'Discovered', + category: 'Type', + windKt: 'Wind', + pressureHpa: 'Pressure', + classification: 'Class', + basin: 'Basin', + value: 'Index', + band: 'Level', + risk: 'Health risk', + bikesAvailable: 'Bikes', + docksAvailable: 'Docks', + lowerAltitude: 'Floor', + upperAltitude: 'Ceiling', + timesOfUse: 'Active', + mode: 'Mode', + noradId: 'NORAD ID', + satelliteClass: 'Class', + mmsi: 'MMSI', + icao24: 'ICAO24', + capacity: 'Capacity', + output: 'Output', + river: 'River', + class: 'Class', + kind: 'Type', + 'addr:city': 'City', + 'addr:state': 'State', + 'addr:country': 'Country', + 'addr:street': 'Street', + start_date: 'Opened', + height: 'Height', + 'plant:source': 'Source', + 'plant:output:electricity': 'Output', + 'generator:source': 'Source', + 'capacity:it_load': 'IT load', + waterway: 'Waterway', + military: 'Military', + landuse: 'Land use', + power: 'Power', + telecom: 'Telecom', +}); + +/** OSM bookkeeping tags that say nothing about the place itself. */ +const NOISE_TAG = + /^(name:|alt_name|old_name|official_name|short_name|osm_|source|note|fixme|check_date|ref:|wikimedia|wikipedia|wikidata|website|url|image|layer$|area$|type$|id$|@)|:wikidata$|:wikipedia$/; + +const MAX_FACTS = 8; +const EARTH_RADIUS_KM = 6371; + +const text = (value) => { + if (value === null || value === undefined) return ''; + if (typeof value === 'object') return ''; + const shown = String(value).trim(); + return shown === 'undefined' || shown === 'null' ? '' : shown; +}; + +const finite = (value) => + value === null || value === undefined || value === '' + ? null + : Number.isFinite(Number(value)) + ? Number(value) + : null; + +/** What a layer's items are, and the glyph that stands for them. */ +export function entityKind(layerId) { + return KINDS[layerId] || { kind: 'feature', icon: 'location_on' }; +} + +/** Latitude and longitude of a record, whichever names it uses. */ +export function recordPosition(record) { + const lat = finite(record?.lat ?? record?.latitude); + const lon = finite(record?.lon ?? record?.longitude); + return lat === null || lon === null ? null : { lat, lon }; +} + +/** The name a person would use for a record. */ +export function recordTitle(record) { + for (const field of TITLE_FIELDS) { + const value = text(record?.[field]); + if (value) return value; + } + // An unnamed site goes by its operator before a bare database number. + const id = text(record?.id); + const operator = text(record?.operator); + if (operator && (!id || /^\d+$/.test(id))) return operator; + return id; +} + +/** A key that stays the same for one item across feed refreshes. */ +export function recordKey(layerId, record) { + for (const field of KEY_FIELDS) { + const value = text(record?.[field]); + if (value) return `${layerId}:${value}`; + } + const at = recordPosition(record); + return at ? `${layerId}:${at.lat.toFixed(4)},${at.lon.toFixed(4)}` : ''; +} + +/** Great-circle distance in kilometres. */ +export function distanceKm(a, b) { + const rad = Math.PI / 180; + const dLat = (b.lat - a.lat) * rad; + const dLon = (b.lon - a.lon) * rad; + const h = + Math.sin(dLat / 2) ** 2 + + Math.cos(a.lat * rad) * Math.cos(b.lat * rad) * Math.sin(dLon / 2) ** 2; + return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h))); +} + +/** Spell out a field name: `originCountry` → `Origin country`. */ +function spellOut(field) { + const words = String(field) + .replace(/[_:]+/g, ' ') + .replace(/([a-z0-9])([A-Z])/g, '$1 $2') + .toLowerCase() + .trim(); + return words ? words[0].toUpperCase() + words.slice(1) : ''; +} + +const isEpochMs = (value) => + Number.isFinite(value) && value > 1e11 && value < 1e13; + +/** + * A fact's value as shown, or '' to leave it out. Units follow the field + * name's suffix, the convention the layers' records already use. + * @param {string} field + * @param {*} value + * @param {object} [options] + * @param {number} [options.nowMs] + * @returns {{value: string, age?: number}|null} + */ +/** Codes the feeds use, in words. */ +const CODE_WORDS = Object.freeze({ + classification: { + TD: 'Tropical depression', + TS: 'Tropical storm', + HU: 'Hurricane', + MH: 'Major hurricane', + TY: 'Typhoon', + STY: 'Super typhoon', + TC: 'Tropical cyclone', + SD: 'Subtropical depression', + SS: 'Subtropical storm', + PTC: 'Post-tropical cyclone', + }, + category: { WF: 'Wildfire', RX: 'Prescribed burn' }, + basin: { + AL: 'Atlantic', + EP: 'Eastern Pacific', + CP: 'Central Pacific', + WP: 'Western Pacific', + IO: 'Indian Ocean', + SH: 'Southern Hemisphere', + }, +}); + +/** A feed's bare lowercase word as people write it: `data_center` → `Data center`. */ +function plainWord(shown) { + if (!/^[a-z][a-z_]*$/.test(shown)) return shown; + const words = shown.replace(/_/g, ' '); + return words[0].toUpperCase() + words.slice(1); +} + +/** An AIS ship type number as the kind of vessel it stands for. */ +function shipTypeName(code) { + const n = Number(code); + if (!Number.isInteger(n) || n < 1 || n > 99) return ''; + if (n === 30) return 'Fishing'; + if (n === 31 || n === 32 || n === 52) return 'Tug'; + if (n === 35) return 'Military'; + if (n === 36) return 'Sailing'; + if (n === 37) return 'Pleasure craft'; + if (n === 50) return 'Pilot vessel'; + if (n === 51) return 'Search and rescue'; + if (n === 55) return 'Law enforcement'; + if (n >= 40 && n <= 49) return 'High-speed craft'; + if (n >= 60 && n <= 69) return 'Passenger'; + if (n >= 70 && n <= 79) return 'Cargo'; + if (n >= 80 && n <= 89) return 'Tanker'; + return 'Other'; +} + +export function formatFact(field, value, { nowMs = Date.now(), kind = '' } = {}) { + if (field === 'shipType' && shipTypeName(value)) return { value: shipTypeName(value) }; + if (value === true) return { value: 'Yes' }; + if (value === false || value === null || value === undefined) return null; + const number = typeof value === 'number' ? value : null; + if (number !== null && !Number.isFinite(number)) return null; + const round = (n, digits = 0) => + n.toLocaleString('en-US', { maximumFractionDigits: digits }); + if (number !== null) { + if (/AtMs$|^timeMs$|^acqTime$|^observedMs$|^updatedTime$/.test(field) && isEpochMs(number)) + return { value: '', age: Math.max(0, nowMs - number) }; + // Any other moment reads as a date. + if (/(Time|Ms|At)$/.test(field) && isEpochMs(number)) + return { + value: new Date(number).toLocaleDateString('en-GB', { + day: 'numeric', + month: 'short', + year: 'numeric', + timeZone: 'UTC', + }), + }; + // Aviation altitudes read in feet; orbits in kilometres. + if (field === 'altitudeM') + return { + value: + number >= 100_000 + ? `${round(number / 1000)} km` + : `${round(number * 3.28084)} ft`, + }; + // Orbital speeds read in km/s, road and rail in km/h, the rest in knots. + if (field === 'speedMps' && number >= 2000) + return { value: `${round(number / 1000, 2)} km/s` }; + if (field === 'speedMps' && kind === 'vehicle') + return { value: `${round(number * 3.6)} km/h` }; + if (field === 'speedMps') return { value: `${round(number * 1.94384)} kt` }; + if (field === 'speedKts') return { value: `${round(number, 1)} kt` }; + if (field === 'verticalRateMps') + return { value: `${round(number * 196.85)} ft/min` }; + if (/^(heading|courseDeg)$/.test(field)) return { value: `${round(number)}°` }; + if (field === 'depthKm') return { value: `${round(number, 1)} km` }; + if (field === 'magnitude') return { value: `M ${round(number, 1)}` }; + if (field === 'frp') return { value: `${round(number, 1)} MW` }; + if (field === 'confidence' && number <= 1) + return { value: `${round(number * 100)}%` }; + if (/Pct$/.test(field)) return { value: `${round(number)}%` }; + if (/Kt$/.test(field)) return { value: `${round(number)} kt` }; + if (/Hpa$/.test(field)) return { value: `${round(number)} hPa` }; + if (field === 'acres') return { value: `${round(number)} acres` }; + if (/Km$/.test(field)) return { value: `${round(number, 1)} km` }; + if (/M$/.test(field)) return { value: `${round(number)} m` }; + return { value: round(number, 2) }; + } + const raw = text(value); + if (!raw) return null; + // Identifiers and names stay exactly as the feed gives them. + const verbatim = KEY_FIELDS.includes(field) || TITLE_FIELDS.includes(field); + const shown = CODE_WORDS[field]?.[raw] || (verbatim ? raw : plainWord(raw)); + return { value: shown.length > 80 ? `${shown.slice(0, 77)}…` : shown }; +} + +/** + * The facts a card lists for a record: known fields first, in a fixed order, + * then whatever else the record carries, up to a handful. + */ +export function recordFacts(record, { nowMs = Date.now(), skip = [], kind = '' } = {}) { + const facts = []; + let observedAgeMs = null; + const seen = new Set(skip); + const fields = [ + ...FACT_ORDER.filter((field) => field in (record || {})), + ...Object.keys(record || {}).filter((field) => !FACT_ORDER.includes(field)), + ]; + for (const field of fields) { + if (HIDDEN_FACTS.has(field) || seen.has(field)) continue; + seen.add(field); + const formatted = formatFact(field, record[field], { nowMs, kind }); + if (!formatted) continue; + if (formatted.age !== undefined) { + observedAgeMs ??= formatted.age; + continue; + } + if (facts.length < MAX_FACTS) + facts.push({ + field, + // An index goes by the scale it is on (AQHI, AQI). + label: + (field === 'value' && text(record.scale)) || + FACT_LABELS[field] || + spellOut(field), + value: formatted.value, + }); + } + return { facts, observedAgeMs }; +} + +/** Facts from a context-store record's properties (GeoJSON / OSM tags). */ +function propertyFacts(properties) { + const flat = { + ...(properties || {}), + ...(properties?.tags && typeof properties.tags === 'object' + ? properties.tags + : {}), + }; + const keep = {}; + for (const [field, value] of Object.entries(flat)) { + if (NOISE_TAG.test(field)) continue; + if (text(value)) keep[field] = value; + } + return recordFacts(keep); +} + +/** A reference link a record carries (Wikipedia, Wikidata or a website). */ +function recordLinks(record, properties) { + const flat = { + ...(properties || {}), + ...(properties?.tags && typeof properties.tags === 'object' + ? properties.tags + : {}), + ...(record || {}), + }; + const links = []; + const wikipedia = text(flat.wikipedia); + if (wikipedia) { + const [lang, ...title] = wikipedia.includes(':') + ? wikipedia.split(':') + : ['en', wikipedia]; + // The language part becomes the link's host, so only a language code is + // let through. + if (/^[a-z]{2,3}(-[a-z0-9]+)*$/.test(lang)) + links.push({ + kind: 'wikipedia', + label: 'Wikipedia', + href: `https://${lang}.wikipedia.org/wiki/${encodeURIComponent(title.join(':').replace(/ /g, '_'))}`, + }); + } + const wikidata = text(flat.wikidata); + if (/^Q\d+$/.test(wikidata)) + links.push({ + kind: 'wikidata', + label: 'Wikidata', + href: `https://www.wikidata.org/wiki/${wikidata}`, + }); + const website = text(flat.website); + if (/^https?:\/\//.test(website)) + links.push({ kind: 'website', label: 'Website', href: website }); + return links; +} + +/** Enabled layers, as the data manager lists them. */ +function enabledLayers(dataManager) { + try { + return (dataManager?.getAll?.() || []).filter((layer) => layer.enabled); + } catch { + return []; + } +} + +/** + * The items a layer has loaded, with a usable position. Empty while the layer + * is off or keeps no list. + */ +export function layerRecords(dataManager, layerId, maxCount = ALL_RECORDS) { + if (dataManager?.isEnabled && !dataManager.isEnabled(layerId)) return []; + let records = []; + try { + records = + dataManager?.layers?.get?.(layerId)?.module?.getAnalystRecords?.(maxCount) || + []; + } catch { + records = []; + } + return records.filter((record) => recordPosition(record)); +} + +function layerName(dataManager, layerId) { + const layer = dataManager?.layers?.get?.(layerId); + return text(layer?.name) || text(layer?.module?.name) || layerId; +} + +const sameText = (a, b) => + Boolean(a) && Boolean(b) && a.toLowerCase() === b.toLowerCase(); + +/** + * The layer record behind an identity from a click, a search or the store: + * matched by key, then by name, then as the nearest item to its position. + * @param {object} dataManager + * @param {{layerId: string, id?: string, label?: string, lat?: number|null, lon?: number|null}} identity + * @returns {object|null} + */ +export function findRecord(dataManager, identity) { + const { layerId } = identity || {}; + if (!layerId) return null; + const records = layerRecords(dataManager, layerId); + if (!records.length) return null; + const id = text(identity.id); + const bare = id.startsWith(`${layerId}:`) ? id.slice(layerId.length + 1) : id; + const at = + finite(identity.lat) !== null && finite(identity.lon) !== null + ? { lat: Number(identity.lat), lon: Number(identity.lon) } + : null; + const nearest = (pool) => { + let best = null; + let bestKm = Infinity; + for (const record of pool) { + const km = distanceKm(at, recordPosition(record)); + if (km < bestKm) { + best = record; + bestKm = km; + } + } + return { best, bestKm }; + }; + const byKey = records.filter((record) => + KEY_FIELDS.some((field) => { + const value = text(record[field]); + return value && (sameText(value, id) || sameText(value, bare)); + }), + ); + // Sites can share a key (many are keyed by a name such as an operator's): + // of several, the one where the identity says it is. + if (byKey.length === 1 || (byKey.length && !at)) return byKey[0]; + if (byKey.length) return nearest(byKey).best; + const label = text(identity.label); + const byName = records.filter((record) => + SEARCH_FIELDS.some((field) => sameText(text(record[field]), label)), + ); + if (byName.length === 1 || (byName.length && !at)) return byName[0]; + if (!at) return null; + // A moving item is matched by its key or name above; guessing the nearest + // could name another craft. + if (!byName.length && entityKind(layerId).moving) return null; + const { best, bestKm } = nearest(byName.length ? byName : records); + // A static item a click names sits where it was drawn. + return bestKm <= 1 ? best : null; +} + +/** The context-store record for an identity, when the layer keeps one. */ +function storeRecord(identity) { + try { + const store = getContextStore(); + const direct = store.entities.get(String(identity.id)); + if (direct?.layerId === identity.layerId) return direct; + // Of several stored sites with the same name, the one at the identity's + // position; a name alone picks the first. + const at = recordPosition(identity); + let best = null; + let bestKm = Infinity; + for (const record of store.entities.values()) { + if (record?.layerId !== identity.layerId) continue; + if (sameText(text(record.properties?.mmsi), text(identity.id))) return record; + if (!sameText(text(record.label), text(identity.label))) continue; + const where = recordPosition(record); + const km = at && where ? distanceKm(at, where) : best ? Infinity : 0; + if (km < bestKm) { + best = record; + bestKm = km; + } + } + if (best) return best; + } catch { + // No window in unit tests without a DOM. + } + return null; +} + +/** + * The card for one item. + * @param {object} dataManager + * @param {{layerId: string, id?: string, label?: string, lat?: number|null, lon?: number|null, record?: object}} identity + * @param {object} [options] + * @param {number} [options.nowMs] + * @returns {object|null} `{key, layerId, layerName, kind, icon, moving, title, lat, lon, facts, observedAgeMs, links, source}` + */ +/** What a transponder code means when it is one of the emergency codes. */ +const EMERGENCY_SQUAWKS = Object.freeze({ + 7500: 'Hijack (squawk 7500)', + 7600: 'Radio failure (squawk 7600)', + 7700: 'Emergency (squawk 7700)', +}); + +/** + * Warnings a record carries, most serious first: an aircraft emergency or + * emergency squawk, a tsunami flag, or a layer's own alert text. These lead + * the card, ahead of any facts. + * @param {?object} record + * @returns {string[]} + */ +export function recordWarnings(record) { + if (!record) return []; + const found = []; + const kind = text(record.emergencyKind); + if (record.emergency === true || (kind && kind.toLowerCase() !== 'none')) + found.push(kind ? `Emergency: ${kind}` : 'Emergency declared'); + const squawk = EMERGENCY_SQUAWKS[Number(record.squawk)]; + if (squawk && !found.length) found.push(squawk); + if (record.tsunami === true || Number(record.tsunami) === 1) found.push('Tsunami warning issued'); + // `alert` is left out: feeds use it for a level (an earthquake's PAGER + // colour), not a warning to read out. + for (const field of ['warning', 'advisory']) { + const value = text(record[field]); + if (value && !found.includes(value)) found.push(value); + } + return found; +} + +/** What a routine transponder code says, for the codes with a meaning. */ +const SQUAWK_MEANINGS = Object.freeze({ + 1200: 'VFR, no flight plan', + 7000: 'VFR conspicuity', + 2000: 'IFR, no code yet', + 7500: 'Hijack', + 7600: 'Radio failure', + 7700: 'Emergency', +}); + +/** Speed of sound (m/s) at a height, from the standard atmosphere. */ +function speedOfSound(heightM) { + const kelvin = heightM < 11_000 ? 288.15 - 0.0065 * heightM : 216.65; + return 20.05 * Math.sqrt(kelvin); +} + +/** + * What can be worked out about a flight beyond its raw fields: its phase of + * flight, flight level, Mach number, what its squawk means and how fresh its + * signal is. For the callouts on the aircraft card, which show these rather + * than repeat the facts listed below them. + * @param {?object} record + * @param {{nowMs?: number}} [options] + * @returns {Array<{label: string, value: string}>} + */ +export function aircraftInsights(record, { nowMs = Date.now() } = {}) { + if (!record) return []; + const out = []; + const altitudeM = finite(record.altitudeM); + const climbMps = finite(record.verticalRateMps); + const speedMps = finite(record.speedMps ?? (finite(record.speedKts) !== null ? record.speedKts * 0.514444 : null)); + if (record.onGround === true) out.push({ label: 'Phase', value: 'On the ground' }); + else if (climbMps !== null) { + const fpm = climbMps * 196.85; + out.push({ + label: 'Phase', + value: fpm > 300 ? `Climbing ${Math.round(fpm / 100) * 100} ft/min` : fpm < -300 ? `Descending ${Math.round(-fpm / 100) * 100} ft/min` : 'Cruising, level', + }); + } + if (altitudeM !== null && altitudeM > 900) out.push({ label: 'Flight level', value: `FL${String(Math.round(altitudeM * 3.28084 / 1000) * 10).padStart(3, '0')}` }); + if (speedMps !== null && altitudeM !== null && speedMps > 60) + out.push({ label: 'Mach', value: `M ${(speedMps / speedOfSound(altitudeM)).toFixed(2)}` }); + const squawk = Number(record.squawk); + if (SQUAWK_MEANINGS[squawk]) out.push({ label: `Squawk ${record.squawk}`, value: SQUAWK_MEANINGS[squawk] }); + const seen = finite(record.lastContactAtMs ?? record.timeMs); + if (seen !== null) { + const seconds = Math.max(0, Math.round((nowMs - seen) / 1000)); + out.push({ label: 'Signal', value: seconds < 90 ? `${seconds} s ago` : `${Math.round(seconds / 60)} min ago` }); + } + return out; +} + +export function describeEntity(dataManager, identity, { nowMs = Date.now() } = {}) { + if (!identity?.layerId) return null; + const { layerId } = identity; + const kind = entityKind(layerId); + const record = identity.record || findRecord(dataManager, identity); + // Sites drawn from GeoJSON keep their full tags in the context store; the + // layer's record holds only a summary of them. + const stored = + record && kind.moving + ? null + : storeRecord({ ...identity, label: identity.label || recordTitle(record) }); + if (!record && !stored && !identity.label) return null; + + const at = + recordPosition(record) || + recordPosition(stored) || + recordPosition(identity); + const fromRecord = record ? recordFacts(record, { nowMs, kind: kind.kind }) : null; + const fromStore = stored ? propertyFacts(stored.properties) : null; + const facts = [...(fromRecord?.facts || [])]; + for (const fact of fromStore?.facts || []) { + if (facts.length >= MAX_FACTS) break; + const same = facts.some( + (known) => + known.label.toLowerCase() === fact.label.toLowerCase() || + known.value.toLowerCase() === fact.value.toLowerCase(), + ); + if (!same) facts.push(fact); + } + // An item with only a database number goes by what it is. + const ownTitle = recordTitle(record); + const title = + (kind.name && (!ownTitle || ownTitle === text(record?.id)) ? kind.name : ownTitle) || + text(stored?.label) || + text(stored?.properties?.name) || + text(identity.label) || + layerName(dataManager, layerId); + const key = record + ? recordKey(layerId, record) + : `${layerId}:${text(identity.id) || title}`; + return { + key, + layerId, + layerName: text(stored?.layerName) || layerName(dataManager, layerId), + kind: kind.kind, + icon: kind.icon, + moving: Boolean(kind.moving), + // The fields that lead the card as its big figures. + headline: kind.headline || [], + title, + lat: at?.lat ?? null, + lon: at?.lon ?? null, + altitudeM: finite(record?.altitudeM ?? identity.altitudeM), + facts: facts.filter((fact) => fact.value !== title), + warnings: recordWarnings(record), + // For the aircraft card's model and route line. + aircraftClass: kind.kind === 'aircraft' ? text(record?.aircraftClass) || null : null, + insights: kind.kind === 'aircraft' ? aircraftInsights(record, { nowMs }) : [], + operator: text(record?.operator) || null, + heading: finite(record?.heading ?? record?.course), + speedMps: finite(record?.speedMps ?? (finite(record?.speedKts) !== null ? record.speedKts * 0.514444 : null)), + route: + text(record?.routeOrigin) || text(record?.routeDestination) + ? { + from: text(record?.routeOrigin) || '—', + to: text(record?.routeDestination) || '—', + verified: true, + // Airport positions, when known, for the route globe. + fromAt: record?.routeFrom || null, + toAt: record?.routeTo || null, + } + : record?.routeScheduled + ? { + // Scheduled for the flight number but not where the plane is: + // shown as unverified, and never drawn on the globe. + from: text(record.routeScheduled.from) || '—', + to: text(record.routeScheduled.to) || '—', + verified: false, + fromAt: null, + toAt: null, + } + : null, + observedAgeMs: fromRecord?.observedAgeMs ?? null, + links: recordLinks(record, stored?.properties), + source: text(stored?.source) || null, + // What the card was built from: the layer's own record, the store's + // properties, or only the click's identity. + basis: record ? 'record' : stored ? 'store' : 'identity', + identity: { + layerId, + id: record ? recordKey(layerId, record).slice(layerId.length + 1) : text(identity.id), + label: title, + lat: at?.lat ?? null, + lon: at?.lon ?? null, + }, + }; +} + +/** + * What is near an item: the closest items of its own layer, and the closest + * item of each other enabled layer. + * @param {object} dataManager + * @param {{layerId: string, key: string, lat: number|null, lon: number|null}} card + * @param {object} [options] + * @param {number} [options.limit] + * @param {number} [options.radiusKm] + * @returns {{same: Array, other: Array}} + */ +export function nearbyEntities( + dataManager, + card, + { limit = 5, radiusKm = 500 } = {}, +) { + const empty = { same: [], other: [] }; + if (!card || card.lat === null || card.lon === null) return empty; + const here = { lat: card.lat, lon: card.lon }; + const row = (layerId, record, km) => ({ + key: recordKey(layerId, record), + layerId, + layerName: layerName(dataManager, layerId), + icon: entityKind(layerId).icon, + kind: entityKind(layerId).kind, + title: recordTitle(record) || layerName(dataManager, layerId), + distanceKm: km, + identity: { + layerId, + id: recordKey(layerId, record).slice(layerId.length + 1), + label: recordTitle(record), + ...recordPosition(record), + record, + }, + }); + const nearest = (layerId, count) => { + const found = []; + for (const record of layerRecords(dataManager, layerId)) { + const key = recordKey(layerId, record); + if (key === card.key) continue; + const km = distanceKm(here, recordPosition(record)); + if (km > radiusKm) continue; + found.push({ record, km }); + } + return found + .sort((a, b) => a.km - b.km) + .slice(0, count) + .map(({ record, km }) => row(layerId, record, km)); + }; + const same = nearest(card.layerId, limit); + const other = enabledLayers(dataManager) + .filter((layer) => layer.id !== card.layerId) + .map((layer) => nearest(layer.id, 1)[0]) + .filter(Boolean) + .sort((a, b) => a.distanceKm - b.distanceKm) + .slice(0, limit); + return { same, other }; +} + +/** + * What the loaded layers have within a radius of a point, in the groups every + * Context card lists: aircraft, vessels, and the closest item of each other + * enabled layer. Each group is nearest first; `count` is how many are inside + * the radius, of which `items` holds the first few. + * @param {object} dataManager + * @param {{lat: number, lon: number}} here + * @param {object} [options] + * @param {number} [options.radiusKm] + * @param {number} [options.limit] Rows per group. + * @param {string} [options.excludeKey] A record to leave out (the selected one). + * @returns {{flights: {count: number, items: Array}, vessels: {count: number, items: Array}, other: Array}} + */ +export function nearbyByKind( + dataManager, + here, + { radiusKm = 250, limit = 4, excludeKey = '', query = '' } = {}, +) { + const needle = text(query).toLowerCase(); + const groups = { flights: { count: 0, items: [] }, vessels: { count: 0, items: [] }, other: [] }; + if (!here || !Number.isFinite(here.lat) || !Number.isFinite(here.lon)) return groups; + const found = { aircraft: [], vessel: [] }; + const other = []; + for (const layer of enabledLayers(dataManager)) { + const kind = entityKind(layer.id).kind; + const group = found[kind]; + let closest = null; + for (const record of layerRecords(dataManager, layer.id)) { + if (excludeKey && recordKey(layer.id, record) === excludeKey) continue; + const km = distanceKm(here, recordPosition(record)); + if (!(km <= radiusKm)) continue; + if (needle && !recordMatches(record, needle, layer.name)) continue; + if (group) group.push({ layerId: layer.id, record, km }); + // A search lists every match, not only each layer's closest item. + else if (needle) other.push({ layerId: layer.id, record, km }); + else if (!closest || km < closest.km) closest = { layerId: layer.id, record, km }; + } + if (closest) other.push(closest); + } + const row = ({ layerId, record, km }) => ({ + key: recordKey(layerId, record), + layerId, + layerName: layerName(dataManager, layerId), + icon: entityKind(layerId).icon, + title: recordTitle(record) || layerName(dataManager, layerId), + distanceKm: km, + identity: { + layerId, + id: recordKey(layerId, record).slice(layerId.length + 1), + label: recordTitle(record), + ...recordPosition(record), + record, + }, + }); + const nearest = (rows) => ({ + count: rows.length, + items: rows + .sort((a, b) => a.km - b.km) + .slice(0, limit) + .map(row), + }); + groups.flights = nearest(found.aircraft); + groups.vessels = nearest(found.vessel); + groups.other = other + .sort((a, b) => a.km - b.km) + .slice(0, limit) + .map(row); + return groups; +} + +/** Counts of records by a label, largest first, the tail folded into "Other". */ +function tallyBy(records, labelOf, { keep = 4 } = {}) { + const counts = new Map(); + for (const record of records) { + const label = labelOf(record) || 'Unknown'; + counts.set(label, (counts.get(label) || 0) + 1); + } + const sorted = [...counts].sort((a, b) => b[1] - a[1]); + const parts = sorted.slice(0, keep).map(([label, count]) => ({ label, count })); + const rest = sorted.slice(keep).reduce((sum, [, count]) => sum + count, 0); + if (rest) { + // A label that is itself "Other" takes the tail, so the name shows once. + const other = parts.find((part) => part.label === 'Other'); + if (other) other.count += rest; + else parts.push({ label: 'Other', count: rest }); + } + return parts.sort((a, b) => b.count - a.count); +} + +const AIRCRAFT_CLASS_NAMES = { + airliner: 'Airliners', + widebody: 'Widebodies', + bizjet: 'Business jets', + light: 'Light aircraft', + helicopter: 'Helicopters', + turboprop: 'Turboprops', + fastjet: 'Fast jets', + quadjet: 'Four-engine jets', +}; + +/** + * What a layer's items are made of, for Context: one or two ways of splitting + * them, each a list of labelled counts that add up to `total`. Aircraft split + * into civilian in the air, military in the air and on the ground, then by + * type of aircraft; vessels by type of ship; satellites by class; earthquakes + * by magnitude. Counts cover the records the layer hands out (it may cap + * them), inside `rect` when one is given. + * @param {object} dataManager + * @param {string} layerId + * @param {{rect?: ?{west: number, south: number, east: number, north: number}}} [options] + * @returns {?{total: number, splits: Array<{title: string, parts: Array<{label: string, count: number}>}>}} + * null when the layer has nothing to split or no split is known for it. + */ +export function layerBreakdown(dataManager, layerId, { rect = null } = {}) { + const kind = entityKind(layerId).kind; + if (!['aircraft', 'vessel', 'satellite', 'earthquake'].includes(kind)) return null; + let records = layerRecords(dataManager, layerId); + if (rect) { + const wraps = rect.west > rect.east; + records = records.filter((record) => { + const at = recordPosition(record); + return ( + at.lat >= rect.south && + at.lat <= rect.north && + (wraps ? at.lon >= rect.west || at.lon <= rect.east : at.lon >= rect.west && at.lon <= rect.east) + ); + }); + } + if (!records.length) return null; + const splits = []; + if (kind === 'aircraft') { + const ground = records.filter((record) => record.onGround === true).length; + const military = records.filter((record) => record.onGround !== true && record.military === true).length; + splits.push({ + title: 'Status', + parts: [ + { label: 'Civilian, in the air', count: records.length - ground - military }, + { label: 'Military, in the air', count: military }, + { label: 'On the ground', count: ground }, + ].filter((part) => part.count), + }); + splits.push({ title: 'Type', parts: tallyBy(records, (record) => AIRCRAFT_CLASS_NAMES[record.aircraftClass] || plainWord(text(record.aircraftClass))) }); + } else if (kind === 'vessel') { + splits.push({ title: 'Type', parts: tallyBy(records, (record) => shipTypeName(record.shipType)) }); + } else if (kind === 'satellite') { + splits.push({ title: 'Class', parts: tallyBy(records, (record) => plainWord(text(record.satelliteClass || record.group))) }); + } else { + const band = (record) => { + const m = finite(record.magnitude); + return m === null ? '' : m >= 6 ? 'M6 and above' : m >= 5 ? 'M5 to 6' : m >= 4 ? 'M4 to 5' : 'Below M4'; + }; + splits.push({ title: 'Magnitude', parts: tallyBy(records, band) }); + } + return { total: records.length, splits: splits.filter((split) => split.parts.length) }; +} + +/** + * Whether a record holds the searched text in any of its text fields, or in + * its layer's name. + * @param {object} record + * @param {string} needle Lower case; '' matches everything. + * @param {string} [layerLabel] + * @returns {boolean} + */ +export function recordMatches(record, needle, layerLabel = '') { + if (!needle) return true; + if (text(layerLabel).toLowerCase().includes(needle)) return true; + for (const value of Object.values(record || {})) { + if (typeof value === 'string' && value.toLowerCase().includes(needle)) return true; + } + return false; +} + +/** + * Items in enabled layers whose name or id starts with the typed text, best + * first. A whole-word match beats a match inside a word. + * @param {object} dataManager + * @param {string} query + * @param {object} [options] + * @param {number} [options.limit] + * @param {{lat: number, lon: number}|null} [options.near] Ties go to the closer item. + * @returns {Array} + */ +export function searchEntities(dataManager, query, { limit = 4, near = null } = {}) { + const needle = text(query).toLowerCase(); + if (needle.length < 2) return []; + const inWord = new RegExp( + `(^|[^a-z0-9])${needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, + ); + const found = []; + for (const layer of enabledLayers(dataManager)) { + for (const record of layerRecords(dataManager, layer.id)) { + let score = 0; + for (const field of [...SEARCH_FIELDS, ...KEY_FIELDS]) { + const value = text(record[field]).toLowerCase(); + if (!value) continue; + const hit = + value === needle + ? 3 + : value.startsWith(needle) + ? 2 + : needle.length >= 3 && inWord.test(value) + ? 1 + : 0; + score = Math.max(score, hit); + } + if (!score) continue; + const at = recordPosition(record); + found.push({ + score, + km: near ? distanceKm(near, at) : 0, + key: recordKey(layer.id, record), + layerId: layer.id, + layerName: layerName(dataManager, layer.id), + icon: entityKind(layer.id).icon, + title: recordTitle(record) || layer.id, + identity: { + layerId: layer.id, + id: recordKey(layer.id, record).slice(layer.id.length + 1), + label: recordTitle(record), + ...at, + record, + }, + }); + } + } + const seen = new Set(); + return found + .sort((a, b) => b.score - a.score || a.km - b.km) + .filter((item) => !seen.has(item.key) && seen.add(item.key)) + .slice(0, limit); +} + +/** + * What the loaded layers have inside a view: for each enabled layer with + * anything in the rectangle, how many and the few closest to the view's + * centre, as rows the Context panel can open. Layers with the most in view + * come first. + * @param {object} dataManager + * @param {{west: number, south: number, east: number, north: number}} rect Degrees. + * @param {{lat: number, lon: number}} center + * @param {object} [options] + * @param {number} [options.perLayer] Closest items to list for each layer. + * @returns {Array<{layerId: string, layerName: string, icon: string, count: number, items: Array}>} + */ +export function viewSummary(dataManager, rect, center, { perLayer = 3, query = '' } = {}) { + if (!rect || !center) return []; + const needle = text(query).toLowerCase(); + const wraps = rect.west > rect.east; + const inside = (at) => + at && + at.lat >= rect.south && + at.lat <= rect.north && + (wraps ? at.lon >= rect.west || at.lon <= rect.east : at.lon >= rect.west && at.lon <= rect.east); + const groups = []; + for (const layer of enabledLayers(dataManager)) { + const found = []; + for (const record of layerRecords(dataManager, layer.id)) { + const at = recordPosition(record); + if (!inside(at)) continue; + if (needle && !recordMatches(record, needle, layer.name)) continue; + found.push({ record, km: distanceKm(center, at) }); + } + if (!found.length) continue; + found.sort((a, b) => a.km - b.km); + groups.push({ + layerId: layer.id, + layerName: layerName(dataManager, layer.id), + icon: entityKind(layer.id).icon, + count: found.length, + items: found.slice(0, perLayer).map(({ record, km }) => ({ + key: recordKey(layer.id, record), + title: recordTitle(record) || layerName(dataManager, layer.id), + distanceKm: km, + identity: { + layerId: layer.id, + id: recordKey(layer.id, record).slice(layer.id.length + 1), + label: recordTitle(record), + ...recordPosition(record), + record, + }, + })), + }); + } + return groups.sort((a, b) => b.count - a.count); +} + +/** + * A layer's items inside an area that pass a test, closest to the area's + * middle first: how many, and the first few as rows the omnibox and Context + * can open. The area is a rectangle in degrees, or a radius around a point. + * @param {object} dataManager + * @param {string} layerId + * @param {object} area + * @param {{lat: number, lon: number}} area.center + * @param {?{west: number, south: number, east: number, north: number}} [area.rect] + * @param {number} [area.radiusKm] Used when there is no rectangle. + * @param {(record: object) => boolean} [area.test] + * @param {number} [area.limit] + * @returns {{count: number, items: Array}} + */ +export function layerMatches(dataManager, layerId, { center, rect = null, radiusKm = 60, test = () => true, limit = 8 }) { + const found = []; + const wraps = rect && rect.west > rect.east; + for (const record of layerRecords(dataManager, layerId)) { + const at = recordPosition(record); + if (!at) continue; + if (rect) { + const inLon = wraps ? at.lon >= rect.west || at.lon <= rect.east : at.lon >= rect.west && at.lon <= rect.east; + if (!inLon || at.lat < rect.south || at.lat > rect.north) continue; + } + const km = distanceKm(center, at); + if (!rect && km > radiusKm) continue; + if (!test(record)) continue; + found.push({ record, km }); + } + found.sort((a, b) => a.km - b.km); + return { + count: found.length, + items: found.slice(0, limit).map(({ record, km }) => ({ + key: recordKey(layerId, record), + title: recordTitle(record) || layerName(dataManager, layerId), + icon: entityKind(layerId).icon, + distanceKm: km, + identity: { + layerId, + id: recordKey(layerId, record).slice(layerId.length + 1), + label: recordTitle(record), + ...recordPosition(record), + record, + }, + })), + }; +} + +/** + * Loaded records near a point that carry a warning (an aircraft squawking an + * emergency, a quake with a tsunami flag, an advisory), nearest first. These + * are what each feed broadcasts, not confirmed incidents. + */ +export function alertsNear(dataManager, here, { radiusKm = 400, limit = 4 } = {}) { + if (!here || !Number.isFinite(here.lat) || !Number.isFinite(here.lon)) return []; + const found = []; + for (const layer of enabledLayers(dataManager)) { + for (const record of layerRecords(dataManager, layer.id)) { + const warnings = recordWarnings(record); + if (!warnings.length) continue; + const km = distanceKm(here, recordPosition(record)); + if (!(km <= radiusKm)) continue; + found.push({ + key: recordKey(layer.id, record), + icon: entityKind(layer.id).icon, + title: recordTitle(record) || layerName(dataManager, layer.id), + text: warnings[0], + distanceKm: km, + identity: { + layerId: layer.id, + id: recordKey(layer.id, record).slice(layer.id.length + 1), + label: recordTitle(record), + ...recordPosition(record), + record, + }, + }); + } + } + return found.sort((a, b) => a.distanceKm - b.distanceKm).slice(0, limit); +} diff --git a/src/data/entityContext.test.mjs b/src/data/entityContext.test.mjs new file mode 100644 index 000000000..bfaf8fc1b --- /dev/null +++ b/src/data/entityContext.test.mjs @@ -0,0 +1,204 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { + aircraftInsights, + describeEntity, + findRecord, + formatFact, + layerBreakdown, + nearbyEntities, + recordTitle, + recordWarnings, + searchEntities, + viewSummary, +} from './entityContext.js'; + +/** A data manager over fixed layer records. */ +function manager(layers) { + const map = new Map( + Object.entries(layers).map(([id, { name, records }]) => [ + id, + { id, name, enabled: true, module: { getAnalystRecords: () => records } }, + ]), + ); + return { + layers: map, + isEnabled: (id) => map.get(id)?.enabled === true, + getAll: () => [...map.values()], + }; +} + +const flights = Array.from({ length: 2500 }, (_, i) => ({ + id: `FLT${i}`, + icao24: `a${String(i).padStart(5, '0')}`, + callsign: `FLT${i}`, + lat: 34 + i * 0.001, + lon: -118, + altitudeM: 10000, +})); +const dams = [ + { id: 'Grand Coulee Dam', name: 'Grand Coulee Dam', lat: 47.957, lon: -118.981, operator: 'Bureau of Reclamation' }, + { id: '123456', name: null, lat: 47.9, lon: -118.9, operator: 'Some Utility' }, +]; +const dm = manager({ + flights: { name: 'Live Flights', records: flights }, + 'local-dams': { name: 'Dams', records: dams }, +}); + +test('a click identity finds its record by key, past the first 2000 records', () => { + const record = findRecord(dm, { layerId: 'flights', id: 'a02400', lat: 0, lon: 0 }); + assert.equal(record?.callsign, 'FLT2400'); +}); + +test('a moving item never borrows a nearby craft when its key is unknown', () => { + const record = findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.0004, lon: -118.05 }); + assert.equal(record, null); +}); + +test('an unnamed site goes by its operator, not its database number', () => { + assert.equal(recordTitle(dams[1]), 'Some Utility'); +}); + +test('a card lists facts with units and keeps the title out of them', () => { + const card = describeEntity(dm, { layerId: 'flights', id: 'a00001' }); + assert.equal(card.title, 'FLT1'); + assert.equal(card.kind, 'aircraft'); + assert.ok(card.facts.some((fact) => fact.label === 'Altitude' && fact.value === '32,808 ft')); + assert.ok(!card.facts.some((fact) => fact.value === 'FLT1')); +}); + +test('nearby lists the closest of the same kind and one of each other layer', () => { + const card = describeEntity(dm, { layerId: 'local-dams', id: 'Grand Coulee Dam' }); + const { same, other } = nearbyEntities(dm, card, { radiusKm: 2000 }); + assert.equal(same[0].title, 'Some Utility'); + assert.equal(other.length, 1); + assert.equal(other[0].layerId, 'flights'); +}); + +test('search ranks an exact name first and needs two characters', () => { + assert.deepEqual(searchEntities(dm, 'f'), []); + const [first] = searchEntities(dm, 'FLT12'); + assert.equal(first.title, 'FLT12'); + assert.equal(searchEntities(dm, 'coulee')[0]?.title, 'Grand Coulee Dam'); +}); + +test('fact formatting follows the field suffix', () => { + assert.equal(formatFact('speedMps', 100).value, '194 kt'); + // Orbital speeds read in km/s, road and rail in km/h. + assert.equal(formatFact('speedMps', 7670).value, '7.67 km/s'); + assert.equal(formatFact('speedMps', 10, { kind: 'vehicle' }).value, '36 km/h'); + // Units follow the field's suffix; feed codes and bare words read as words. + assert.equal(formatFact('containedPct', 96).value, '96%'); + assert.equal(formatFact('windKt', 30).value, '30 kt'); + assert.equal(formatFact('pressureHpa', 1009).value, '1,009 hPa'); + assert.equal(formatFact('classification', 'TD').value, 'Tropical depression'); + assert.equal(formatFact('telecom', 'data_center').value, 'Data center'); + assert.equal(formatFact('icao24', 'abcdef').value, 'abcdef'); + assert.equal(formatFact('shipType', 70).value, 'Cargo'); + assert.equal(formatFact('shipType', 'Tanker').value, 'Tanker'); + assert.equal(formatFact('discoveredTime', Date.UTC(2026, 5, 29)).value, '29 Jun 2026'); + assert.equal(formatFact('updatedTime', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000); + assert.equal(formatFact('altitudeM', 420000).value, '420 km'); + assert.equal(formatFact('confidence', 0.82).value, '82%'); + assert.equal(formatFact('onGround', false), null); + assert.equal(formatFact('lastContactAtMs', 1_700_000_000_000, { nowMs: 1_700_000_060_000 }).age, 60_000); +}); + +test('warnings lead with an emergency, then the squawk code, and stay out of the facts', () => { + assert.deepEqual(recordWarnings({ emergency: true, emergencyKind: 'medical' }), ['Emergency: medical']); + assert.deepEqual(recordWarnings({ squawk: '7600' }), ['Radio failure (squawk 7600)']); + assert.deepEqual(recordWarnings({ squawk: '1200', emergencyKind: 'none' }), []); + assert.deepEqual(recordWarnings({ tsunami: 1 }), ['Tsunami warning issued']); + const urgent = manager({ + flights: { name: 'Live Flights', records: [{ id: 'X1', icao24: 'x00001', callsign: 'X1', lat: 1, lon: 1, emergency: true, emergencyKind: 'fuel' }] }, + }); + const card = describeEntity(urgent, { layerId: 'flights', id: 'x00001' }); + assert.deepEqual(card.warnings, ['Emergency: fuel']); + assert.ok(!card.facts.some((fact) => /emergency/i.test(fact.label))); +}); + +test('the view summary counts each layer inside the view, closest to the middle first', () => { + const groups = viewSummary( + dm, + { west: -119, south: 34, east: -117, north: 34.5 }, + { lat: 34.1, lon: -118 }, + { perLayer: 2 }, + ); + assert.equal(groups.length, 1); + assert.equal(groups[0].layerId, 'flights'); + assert.equal(groups[0].count, 501); + assert.equal(groups[0].items[0].title, 'FLT100'); +}); + +test('flight insights work out phase, flight level, Mach, squawk meaning and signal age', () => { + const insights = aircraftInsights( + { altitudeM: 10668, verticalRateMps: 0, speedMps: 230, squawk: '7000', lastContactAtMs: 1_000_000 }, + { nowMs: 1_012_000 }, + ); + const value = (label) => insights.find((item) => item.label === label)?.value; + assert.equal(value('Phase'), 'Cruising, level'); + assert.equal(value('Flight level'), 'FL350'); + assert.equal(value('Mach'), 'M 0.78'); + assert.equal(value('Squawk 7000'), 'VFR conspicuity'); + assert.equal(value('Signal'), '12 s ago'); + assert.equal(aircraftInsights({ onGround: true })[0].value, 'On the ground'); + assert.match(aircraftInsights({ verticalRateMps: -8 })[0].value, /^Descending 1600 ft\/min$/); +}); + +test('a layer breakdown splits aircraft by status and type, inside a view when given', () => { + const craft = [ + { id: 'A', lat: 10, lon: 10, onGround: false, military: false, aircraftClass: 'airliner' }, + { id: 'B', lat: 10, lon: 11, onGround: false, military: true, aircraftClass: 'fastjet' }, + { id: 'C', lat: 10, lon: 12, onGround: true, military: true, aircraftClass: 'airliner' }, + { id: 'D', lat: 60, lon: 12, onGround: false, military: false, aircraftClass: 'airliner' }, + ]; + const data = manager({ flights: { name: 'Live Flights', records: craft }, 'local-dams': { name: 'Dams', records: dams } }); + const all = layerBreakdown(data, 'flights'); + assert.equal(all.total, 4); + assert.deepEqual(all.splits[0].parts, [ + { label: 'Civilian, in the air', count: 2 }, + { label: 'Military, in the air', count: 1 }, + { label: 'On the ground', count: 1 }, + ]); + assert.deepEqual(all.splits[1].parts, [ + { label: 'Airliners', count: 3 }, + { label: 'Fast jets', count: 1 }, + ]); + const near = layerBreakdown(data, 'flights', { rect: { west: 9, east: 13, south: 9, north: 11 } }); + assert.equal(near.total, 3); + assert.equal(layerBreakdown(data, 'local-dams'), null); +}); + +test('a moving item with an unknown key is not matched to a craft right beside it', () => { + // About 110 m from FLT0: well inside any nearest-item reach. + assert.equal(findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.001, lon: -118 }), null); +}); + +test('sites that share a key are told apart by where the identity says they are', () => { + const sites = [ + { id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -52.942, lon: -70.849 }, + { id: 'Amazon Web Services', name: 'Amazon Web Services', lat: -33.557, lon: -70.813 }, + ]; + const data = manager({ 'local-datacenters': { name: 'Datacenters', records: sites } }); + const identity = { layerId: 'local-datacenters', id: 'Amazon Web Services', label: 'Amazon Web Services', lat: -33.557, lon: -70.813 }; + assert.equal(findRecord(data, identity), sites[1]); + const card = describeEntity(data, identity); + assert.equal(card.lat, -33.557); + // The card's own identity finds the same site again, as its refresh does. + assert.equal(findRecord(data, card.identity), sites[1]); +}); + +test('a link is built only from a language code, and a level is not a warning', () => { + const site = { id: 'X', name: 'X', lat: 1, lon: 1, wikipedia: 'evil.example/a#:Y' }; + const data = manager({ 'local-dams': { name: 'Dams', records: [site] } }); + assert.deepEqual(describeEntity(data, { layerId: 'local-dams', id: 'X', lat: 1, lon: 1 }).links, []); + assert.deepEqual(recordWarnings({ alert: 'green' }), []); +}); + +test('a breakdown names "Other" once', () => { + const ships = [30, 30, 70, 70, 70, 80, 80, 60, 37, 52, 52, 90, 90, 90].map((shipType, i) => ({ id: `S${i}`, mmsi: String(i), lat: 1, lon: 1 + i * 0.01, shipType })); + const data = manager({ 'ais-live-vessels': { name: 'Vessels', records: ships } }); + const labels = layerBreakdown(data, 'ais-live-vessels').splits[0].parts.map((part) => part.label); + assert.equal(labels.filter((label) => label === 'Other').length <= 1, true); + assert.equal(new Set(labels).size, labels.length); +}); diff --git a/src/layers/flights/queries.js b/src/layers/flights/queries.js index 91ed4ea95..6f6feec98 100644 --- a/src/layers/flights/queries.js +++ b/src/layers/flights/queries.js @@ -246,6 +246,19 @@ export function createQueries({ * routeDestination: string|null}} */ + /** An airport at one end of a route, when it has a position. */ + function routeEnd(airport) { + const lat = Number(airport?.lat ?? airport?.latitude); + const lon = Number(airport?.lon ?? airport?.longitude); + if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null; + return { + code: String(airport?.code ?? '').trim() || null, + name: String(airport?.name ?? airport?.municipality ?? '').trim() || null, + lat, + lon, + }; + } + function mapAnalystRecord( icao24, info, @@ -293,6 +306,16 @@ export function createQueries({ lastContactAtMs: num(info?.lastContactEpochMs), routeOrigin: routeOk ? text(info?.route?.origin?.code) : null, routeDestination: routeOk ? text(info?.route?.destination?.code) : null, + // The airports themselves, for the context card's route globe. + routeFrom: routeOk ? routeEnd(info?.route?.origin) : null, + routeTo: routeOk ? routeEnd(info?.route?.destination) : null, + // The scheduled route when it does not fit where the plane is (often + // another leg of the same flight number): the card shows it marked + // unverified, everything else still treats the flight as routeless. + routeScheduled: + !routeOk && info?.route?.origin?.code && info?.route?.destination?.code + ? { from: text(info.route.origin.code), to: text(info.route.destination.code) } + : null, }; } const methods = { @@ -748,6 +771,15 @@ export function createQueries({ return result; }, + /** + * Ask for an aircraft's scheduled route (origin and destination airports), + * as tracking does; it lands on the record when the lookup answers. + * @param {string} icao24 + */ + requestRoute(icao24) { + if (icao24) parts.enrichment._requestRouteEnrichment(String(icao24).trim().toLowerCase()); + }, + /** * Start camera-tracking an aircraft by ICAO24 address. * @param {string} icao24 - ICAO 24-bit transponder address. diff --git a/src/ui/contextLayerTabs.js b/src/ui/contextLayerTabs.js new file mode 100644 index 000000000..857f4bb84 --- /dev/null +++ b/src/ui/contextLayerTabs.js @@ -0,0 +1,82 @@ +import { computed, ref } from 'vue'; + +// Context's layer tabs: when a layer that has its own settings is on, those +// settings move out of the panel they normally live in (Visual) into a tab +// in the Context panel, so they sit beside what they affect. +// Each tab's content is teleported into `#context-tab-`; when the layer +// goes off the content returns to its usual panel. +const AIRCRAFT = ['flights', 'military', 'local-adsb']; + +// Layers that draw labels and cards through the world overlay, which the +// Dense settings (density, allocation, fade, outside) govern. +export const LABEL_LAYERS = new Set([ + 'satellites', + 'ais-live-vessels', + 'rocket-launches', + 'cctv', + 'transit', + 'bikeshare', + 'radio', + 'local-adsb', + 'earthquakes', + 'local-firms', + 'fire-perimeters', + 'weather-cyclones', + 'air-quality', + 'alpr-cameras', + 'drone-airspace', + 'military-installations', + 'telegeography-submarine-cables', + 'osm-places', + 's2-ghostmaps', + 'directions', +]); + +// Which of the layers that are on each tab acts on. +export const TAB_AFFECTS = { + labels: (on) => [...on].filter((id) => LABEL_LAYERS.has(id)), + aircraft: (on) => [...on].filter((id) => AIRCRAFT.includes(id)), +}; + +export const LAYER_TABS = [ + // Labels and cards the world overlay draws for the label layers. + { id: 'labels', label: 'Labels', icon: 'label', when: (on) => TAB_AFFECTS.labels(on).length > 0 }, + { id: 'aircraft', label: '3D aircraft', icon: 'flight', when: (on) => TAB_AFFECTS.aircraft(on).length > 0 }, +]; + +/** Ids of the layers that are on; Context refreshes it. */ +export const enabledLayerIds = ref(new Set()); + +export function setEnabledLayers(ids) { + const next = new Set(ids); + const prev = enabledLayerIds.value; + if (next.size === prev.size && [...next].every((id) => prev.has(id))) return; + enabledLayerIds.value = next; +} + +/** Whether Context is mounted and can host tab content. */ +export const contextReady = ref(false); + +/** The tabs available now. */ +export const availableTabs = computed(() => + contextReady.value ? LAYER_TABS.filter((tab) => tab.when(enabledLayerIds.value)) : [], +); + +export const hasTab = (id) => availableTabs.value.some((tab) => tab.id === id); + +/** The tab Context shows: 'view' (the card) or a layer tab's id. */ +export const activeTab = ref('view'); + +// Each tab's content lands in an element made here, before any panel mounts, +// so a panel that mounts ahead of Context still has a real target; Context +// places these elements in its tab panes when it mounts. +const targets = new Map(); +export function tabTarget(id) { + if (!targets.has(id) && globalThis.document) { + const el = document.createElement('div'); + el.className = 'context-tab-body'; + el.dataset.tab = id; + targets.set(id, el); + } + return targets.get(id) ?? 'body'; +} diff --git a/src/ui/contextRadius.js b/src/ui/contextRadius.js new file mode 100644 index 000000000..5b858dfe0 --- /dev/null +++ b/src/ui/contextRadius.js @@ -0,0 +1,43 @@ +import { ref } from 'vue'; + +// How far out Context looks for what is "nearby": one distance for every +// nearby block (flights, vessels, hazards, alerts, other loaded items). The +// control in the Context panel steps through a few distances; the choice is +// kept for the next visit. +const KEY = 'gev.contextRadiusKm'; + +/** The distances the control steps through, in km. */ +export const CONTEXT_RADIUS_STEPS = Object.freeze([25, 50, 100, 250, 500, 1000, 2500]); +export const DEFAULT_CONTEXT_RADIUS_KM = 250; + +/** The step closest to a distance; the default for anything unusable. */ +export function nearestRadiusStep(km) { + const value = Number(km); + if (!Number.isFinite(value) || value <= 0) return DEFAULT_CONTEXT_RADIUS_KM; + return CONTEXT_RADIUS_STEPS.reduce((best, step) => + Math.abs(step - value) < Math.abs(best - value) ? step : best, + ); +} + +function read() { + try { + const saved = globalThis.localStorage?.getItem(KEY); + return saved === null || saved === undefined + ? DEFAULT_CONTEXT_RADIUS_KM + : nearestRadiusStep(saved); + } catch { + return DEFAULT_CONTEXT_RADIUS_KM; + } +} + +/** The radius every nearby block uses, in km. */ +export const contextRadiusKm = ref(read()); + +export function setContextRadiusKm(km) { + contextRadiusKm.value = nearestRadiusStep(km); + try { + globalThis.localStorage?.setItem(KEY, String(contextRadiusKm.value)); + } catch { + // Without storage the choice lasts for this visit. + } +} diff --git a/src/ui/contextSearch.js b/src/ui/contextSearch.js new file mode 100644 index 000000000..7988a2585 --- /dev/null +++ b/src/ui/contextSearch.js @@ -0,0 +1,24 @@ +import { computed, ref } from 'vue'; + +// The Context panel's own search: one field in its header that narrows what +// the panel is showing (the selected item's details, and every list of what +// is nearby or in view) to what holds the typed text. + +/** Whether the search field is showing. */ +export const contextSearchOpen = ref(false); +/** The text as typed. */ +export const contextSearchText = ref(''); +/** The text to match against: trimmed, lower case, '' when not searching. */ +export const contextNeedle = computed(() => (contextSearchOpen.value ? contextSearchText.value.trim().toLowerCase() : '')); + +/** Whether any of the given strings holds the searched text (true when not searching). */ +export function matchesContextSearch(...parts) { + const needle = contextNeedle.value; + if (!needle) return true; + return parts.some((part) => part !== null && part !== undefined && String(part).toLowerCase().includes(needle)); +} + +export function closeContextSearch() { + contextSearchOpen.value = false; + contextSearchText.value = ''; +} diff --git a/src/ui/entityContextBridge.js b/src/ui/entityContextBridge.js new file mode 100644 index 000000000..f62903ff9 --- /dev/null +++ b/src/ui/entityContextBridge.js @@ -0,0 +1,215 @@ +import * as Cesium from 'cesium'; +import { pickWorldFromScreen } from '../annotations/annotationResolver.js'; +import { resolvePickedContext } from '../data/pickedContext.js'; +import { isPointerFree } from '../data/inputOwnership.js'; +import { useCockpitStore } from './stores/cockpit.js'; +import { useEntityCardStore } from './stores/entityCard.js'; +import { useOmnibarStore } from './stores/omnibar.js'; +import { useVoiceStore } from './stores/voice.js'; + +/** Camera distance (m) that frames an item of each kind. */ +const FRAME_RANGE = Object.freeze({ + aircraft: 30_000, + vessel: 9_000, + satellite: 2_500_000, + earthquake: 120_000, + storm: 1_500_000, + fire: 20_000, + 'fire perimeter': 40_000, +}); +const DEFAULT_RANGE = 8_000; +/** Items the voice runtime can keep the camera on. */ +const FOLLOWABLE = new Set(['flights', 'military', 'ais-live-vessels', 'satellites']); + +/** + * Connects the Context panel's entity card to the globe: a click on anything a + * layer can identify opens its card, and the card's actions fly to it, follow + * it or ask GEV about it. Layers keep their own click behaviour; this listens + * alongside them. + * @param {object} options + * @param {object} options.viewer Cesium viewer. + * @param {() => object} options.getDataManager Layer lifecycle. + * @param {object} options.pinia + * @returns {() => void} disconnects + */ +export function installEntityContext({ viewer, getDataManager, pinia }) { + const store = useEntityCardStore(pinia); + const omnibar = useOmnibarStore(pinia); + const voice = useVoiceStore(pinia); + const cockpitStore = useCockpitStore(pinia); + const doc = globalThis.document; + + function openPanel() { + const button = doc?.querySelector( + '.ui-rail--right .ui-rail__item[data-rail-item="global-context-panel"]', + ); + if (button && button.getAttribute('aria-pressed') !== 'true') button.click(); + } + + function flyTo(card) { + if (!Number.isFinite(card?.lat) || !Number.isFinite(card?.lon)) return; + const height = Number.isFinite(card.altitudeM) ? card.altitudeM : 0; + const range = FRAME_RANGE[card.kind] ?? DEFAULT_RANGE; + viewer.camera.flyToBoundingSphere( + new Cesium.BoundingSphere( + Cesium.Cartesian3.fromDegrees(card.lon, card.lat, Math.max(0, height)), + 1, + ), + { + offset: new Cesium.HeadingPitchRange( + viewer.camera.heading, + Cesium.Math.toRadians(card.kind === 'satellite' ? -90 : -45), + range, + ), + duration: 2, + }, + ); + } + + function follow(card) { + const run = omnibar.runner; + if (!run || !FOLLOWABLE.has(card.layerId)) return flyTo(card); + void run('track_entity', { + query: card.identity.id || card.title, + layerId: card.layerId, + }); + } + + // Aircraft can be flown from, and a satellite ridden in the orbital view: + // track the craft, then enter Cockpit on it. + const COCKPIT_LAYERS = new Set(['flights', 'military', 'local-adsb', 'satellites']); + async function cockpit(card) { + const run = omnibar.runner; + if (!run || !COCKPIT_LAYERS.has(card.layerId)) return; + await run('track_entity', { query: card.identity.id || card.title, layerId: card.layerId }); + if (card.layerId !== 'satellites') { + await run('control_cockpit', { action: 'enter' }); + return; + } + // A satellite is ridden through the app's own Cockpit entry, which offers + // the orbital view once the satellite is tracked. Wait for it to say so; + // if it never does (a class that cannot be ridden), nothing is entered. + for (let tries = 0; tries < 40; tries++) { + const presence = cockpitStore.presence; + if (presence?.entryAvailable && presence.entryKind === 'satellite') { + doc?.getElementById('cockpit-entry')?.click(); + return; + } + await new Promise((resolve) => setTimeout(resolve, 100)); + } + } + + function askText(prompt) { + voice.controls?.emit('chat-restore'); + voice.controls?.emit('chat-prompt', prompt); + voice.controls?.emit('chat-submit'); + } + + function ask(card) { + const where = + Number.isFinite(card.lat) && Number.isFinite(card.lon) + ? ` at ${card.lat.toFixed(3)}, ${card.lon.toFixed(3)}` + : ''; + const prompt = `Tell me about the ${card.kind} ${card.title} (${card.layerName})${where}, and what is around it.`; + voice.controls?.emit('chat-restore'); + voice.controls?.emit('chat-prompt', prompt); + voice.controls?.emit('chat-submit'); + } + + store.connect({ + dataManager: getDataManager, + openPanel, + flyTo, + follow, + ask, + askText, + cockpit, + canCockpit: (card) => Boolean(omnibar.runner) && COCKPIT_LAYERS.has(card?.layerId), + canFollow: (card) => FOLLOWABLE.has(card?.layerId), + // Where the camera is, so a search prefers what is close by. + here: () => { + const at = viewer.camera.positionCartographic; + return at + ? { + lat: Cesium.Math.toDegrees(at.latitude), + lon: Cesium.Math.toDegrees(at.longitude), + } + : null; + }, + }); + + // What the camera shows, for the Context panel to describe when nothing is + // picked: the ground under the middle of the screen, the view's bounds and + // the height. Read when the camera settles, not every frame. + const readView = () => { + const camera = viewer.camera; + const height = camera.positionCartographic?.height ?? 0; + const middle = pickWorldFromScreen(viewer, 0.5, 0.5); + const center = middle + ? { lat: middle.lat, lon: middle.lon } + : { + lat: Cesium.Math.toDegrees(camera.positionCartographic.latitude), + lon: Cesium.Math.toDegrees(camera.positionCartographic.longitude), + }; + const r = camera.computeViewRectangle?.(viewer.scene.globe.ellipsoid); + const rect = r + ? { + west: Cesium.Math.toDegrees(r.west), + south: Cesium.Math.toDegrees(r.south), + east: Cesium.Math.toDegrees(r.east), + north: Cesium.Math.toDegrees(r.north), + } + : { west: -180, south: -90, east: 180, north: 90 }; + store.setView({ center, rect, heightM: height }); + }; + const removeMoveEnd = viewer.camera.moveEnd.addEventListener(readView); + // A camera that keeps moving (following an aircraft, a long fly-to) never + // settles, so also read it on large changes, at most once a second. + let lastRead = 0; + const removeChanged = viewer.camera.changed.addEventListener(() => { + const now = performance.now(); + if (now - lastRead < 1000) return; + lastRead = now; + readView(); + }); + setTimeout(readView, 0); + + const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); + handler.setInputAction(({ position }) => { + // A tool that owns the pointer (draw, measure) keeps its clicks. + if (!isPointerFree()) return; + let picked = null; + try { + picked = viewer.scene.pick(position); + } catch { + picked = null; + } + const identity = resolvePickedContext(picked, { + dataManager: getDataManager(), + }); + // A click on open ground or sea selects nothing and leaves the card as it is. + if (identity) store.select(identity); + }, Cesium.ScreenSpaceEventType.LEFT_CLICK); + + // Layers that select through the context store (GeoJSON sites, fires, + // installations) announce it; their selection opens the card too. + const onSelected = ({ detail: record }) => { + if (!record?.layerId) return; + store.select({ + layerId: record.layerId, + id: record.id, + label: record.label || record.properties?.name, + lat: record.latitude, + lon: record.longitude, + }); + }; + globalThis.addEventListener?.('gev:entity-selected', onSelected); + + return () => { + handler.destroy(); + removeMoveEnd(); + removeChanged(); + globalThis.removeEventListener?.('gev:entity-selected', onSelected); + store.connect(null); + }; +} diff --git a/src/ui/spotConditions.js b/src/ui/spotConditions.js new file mode 100644 index 000000000..9d723562e --- /dev/null +++ b/src/ui/spotConditions.js @@ -0,0 +1,172 @@ +import { distanceKm } from '../data/entityContext.js'; +import { createUsgsEarthquakeSource } from '../layers/earthquakes/source.js'; +import { createCycloneSource } from '../layers/cyclones/source.js'; +import { createWfigsPerimeterSource } from '../layers/perimeters/source.js'; +import { createFirmsSource } from '../layers/firms/source.js'; + +// What is going on around one spot on the map: the weather there now and the +// local headlines (the app's regional brief, the same one Cockpit shows), and +// the natural hazards near it from the feeds the hazard layers read +// (earthquakes, tropical storms, wildfire perimeters, satellite fire hits). +// The feeds are global snapshots, so each is fetched once and kept for a few +// minutes whichever spot asks; the brief is kept per spot. + +const BRIEF_TTL_MS = 10 * 60_000; +const FEED_TTL_MS = 5 * 60_000; + +const briefs = new Map(); +/** The regional brief for a spot: `{weather, articles, place, newsSource}`. */ +export function regionalBrief(lat, lon) { + const key = `${lat.toFixed(2)},${lon.toFixed(2)}`; + const kept = briefs.get(key); + if (kept && Date.now() - kept.at < BRIEF_TTL_MS) return kept.promise; + const query = `latitude=${lat.toFixed(5)}&longitude=${lon.toFixed(5)}`; + const promise = fetch(`/api/regional-brief?${query}`) + .then((response) => (response.ok ? response.json() : null)) + .catch(() => null); + briefs.set(key, { at: Date.now(), promise }); + if (briefs.size > 40) briefs.delete(briefs.keys().next().value); + return promise; +} + +const feeds = new Map(); +function snapshot(name, load) { + const kept = feeds.get(name); + if (kept && Date.now() - kept.at < FEED_TTL_MS) return kept.promise; + const promise = load().catch(() => null); + feeds.set(name, { at: Date.now(), promise }); + return promise; +} +const quakes = () => snapshot('quakes', () => createUsgsEarthquakeSource().getSnapshot()); +const storms = () => snapshot('storms', () => createCycloneSource().getSnapshot()); +const perimeters = () => snapshot('perimeters', () => createWfigsPerimeterSource().getSnapshot()); +const fires = () => snapshot('fires', () => createFirmsSource().getSnapshot()); + +const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; +/** The compass point from one spot to another, like "NE". */ +export function compassPoint(from, to) { + const rad = Math.PI / 180; + const y = Math.sin((to.lon - from.lon) * rad) * Math.cos(to.lat * rad); + const x = + Math.cos(from.lat * rad) * Math.sin(to.lat * rad) - + Math.sin(from.lat * rad) * Math.cos(to.lat * rad) * Math.cos((to.lon - from.lon) * rad); + const deg = (Math.atan2(y, x) / rad + 360) % 360; + return compassName(deg); +} + +/** The compass point for a bearing in degrees. */ +export function compassName(deg) { + return COMPASS[Math.round((((deg % 360) + 360) % 360) / 45) % 8]; +} + +// The middle of a perimeter's first ring, close enough for "how far". +function perimeterMiddle(row) { + const ring = row?.polygons?.[0]?.[0]; + if (!Array.isArray(ring) || !ring.length) return null; + let lat = 0; + let lon = 0; + for (const [x, y] of ring) { + lon += x; + lat += y; + } + return { lat: lat / ring.length, lon: lon / ring.length }; +} + +/** + * Hazards within a radius of a spot, nearest first within each kind: + * `[{kind, icon, title, detail, distanceKm, at}]`. Every kind uses the same + * radius, the one Context's radius control sets. + */ +export async function hazardsNear(lat, lon, radiusKm = 250) { + const here = { lat, lon }; + const [quakeRows, stormSnap, perimeterRows, fireSnap] = await Promise.all([ + quakes(), + storms(), + perimeters(), + fires(), + ]); + const found = []; + const add = (row) => { + row.distanceKm = distanceKm(here, row.at); + row.direction = compassPoint(here, row.at); + found.push(row); + }; + + for (const quake of Array.isArray(quakeRows) ? quakeRows : []) { + const at = { lat: quake.lat, lon: quake.lon }; + if (!(distanceKm(here, at) <= radiusKm)) continue; + add({ + kind: 'quake', + icon: 'earthquake', + title: Number.isFinite(Number.parseFloat(quake.mag)) ? `M${Number(quake.mag).toFixed(1)} earthquake` : 'Earthquake', + detail: quake.place || '', + time: quake.time, + at, + }); + } + for (const storm of stormSnap?.storms || []) { + const at = { lat: storm.position?.latitude, lon: storm.position?.longitude }; + if (!(distanceKm(here, at) <= radiusKm)) continue; + add({ + kind: 'storm', + icon: 'cyclone', + title: [storm.classification, storm.name].filter(Boolean).join(' '), + detail: storm.windKt ? `${storm.windKt} kt winds` : '', + time: Date.parse(storm.positionAt) || null, + at, + }); + } + for (const fire of Array.isArray(perimeterRows) ? perimeterRows : []) { + const at = perimeterMiddle(fire); + if (!at || !(distanceKm(here, at) <= radiusKm)) continue; + const acres = Number(fire.acres); + add({ + kind: 'wildfire', + icon: 'local_fire_department', + title: fire.name || 'Wildfire', + detail: [ + Number.isFinite(acres) ? `${Math.round(acres).toLocaleString()} acres` : '', + Number.isFinite(fire.containedPct) ? `${fire.containedPct}% contained` : '', + fire.category === 'RX' ? 'prescribed burn' : '', + ] + .filter(Boolean) + .join(' · '), + time: fire.updatedTime || fire.discoveredTime || null, + at, + }); + } + // Satellite fire hits are many small points: count the close ones. + const hits = (Array.isArray(fireSnap?.fires) ? fireSnap.fires : []) + .map((fire) => ({ lat: Number(fire.lat ?? fire.latitude), lon: Number(fire.lon ?? fire.longitude) })) + .filter((at) => distanceKm(here, at) <= radiusKm); + if (hits.length) { + const nearest = hits.reduce((a, b) => (distanceKm(here, a) <= distanceKm(here, b) ? a : b)); + add({ + kind: 'hotspots', + icon: 'local_fire_department', + title: `${hits.length} satellite fire ${hits.length === 1 ? 'hit' : 'hits'}`, + detail: 'last day', + time: null, + at: nearest, + }); + } + const order = { storm: 0, wildfire: 1, hotspots: 2, quake: 3 }; + return found.sort((a, b) => order[a.kind] - order[b.kind] || a.distanceKm - b.distanceKm); +} + +/** Title-case copy for a WMO weather code, and the icon that goes with it. */ +export function weatherLook(code) { + const value = Number(code); + if (!Number.isFinite(value)) return { label: 'Conditions unknown', icon: 'partly_cloudy_day' }; + if (value === 0) return { label: 'Clear', icon: 'sunny' }; + if (value <= 2) return { label: 'Partly cloudy', icon: 'partly_cloudy_day' }; + if (value === 3) return { label: 'Overcast', icon: 'cloud' }; + if (value === 45 || value === 48) return { label: 'Fog', icon: 'foggy' }; + if (value >= 51 && value <= 57) return { label: 'Drizzle', icon: 'rainy' }; + if (value >= 61 && value <= 67) return { label: 'Rain', icon: 'rainy' }; + if (value >= 71 && value <= 77) return { label: 'Snow', icon: 'weather_snowy' }; + if (value >= 80 && value <= 82) return { label: 'Rain showers', icon: 'rainy' }; + if (value >= 85 && value <= 86) return { label: 'Snow showers', icon: 'weather_snowy' }; + if (value >= 95) return { label: 'Thunderstorm', icon: 'thunderstorm' }; + return { label: 'Mixed conditions', icon: 'partly_cloudy_day' }; +} diff --git a/src/ui/stores/entityCard.js b/src/ui/stores/entityCard.js new file mode 100644 index 000000000..ffee353e3 --- /dev/null +++ b/src/ui/stores/entityCard.js @@ -0,0 +1,258 @@ +import { defineStore } from 'pinia'; +import { markRaw, ref, shallowRef } from 'vue'; +import { sourceLabel } from '../layerNames.js'; +import { + alertsNear, + describeEntity, + layerBreakdown, + nearbyByKind, + layerMatches, + searchEntities, + viewSummary, +} from '../../data/entityContext.js'; + +/** How often an open card re-reads its item, so moving things stay current. */ +const REFRESH_MS = 2000; + +/** + * The thing the Context panel is about: whatever was last clicked on the + * globe, chosen in the omnibar, or picked from the card's nearby list. + * + * The shell connects `{dataManager(), flyTo(card), follow(card), openPanel()}`; + * until then nothing can be selected. + */ +export const useEntityCardStore = defineStore('gev-entity-card', () => { + const shell = shallowRef(null); + /** The card model from `describeEntity`, or null. */ + const card = shallowRef(null); + /** True once a moving item has dropped out of its feed. */ + const lost = ref(false); + /** Bumped on each refresh, so ages shown on the card tick. */ + const tick = ref(0); + /** + * What the camera shows, for the panel to describe when nothing is picked: + * `{center: {lat, lon}, rect: {west, south, east, north}, heightM}`. + */ + const view = shallowRef(null); + let timer = null; + + function connect(next) { + shell.value = next ? markRaw(next) : null; + if (!next) clear(); + } + + const dataManager = () => shell.value?.dataManager?.() || null; + + function read(identity) { + const next = describeEntity(dataManager(), identity); + if (!next) return false; + card.value = markRaw(next); + lost.value = false; + tick.value++; + return true; + } + + /** + * Where a card's data comes from, for its footer: the item's own source, + * else its layer's live feed (the name the layer list shows). + */ + function sourceOf(current) { + if (!current) return ''; + if (current.source) return current.source; + const dm = shell.value?.dataManager?.(); + const layer = dm?.getAll?.().find((row) => row.id === current.layerId); + const stats = layer?.stats || {}; + const raw = stats.sourceVerbatim === true && stats.source ? stats.source : sourceLabel(stats.source || layer?.source); + return raw || ''; + } + const canCockpit = () => Boolean(shell.value?.canCockpit?.(card.value)); + function cockpit() { + if (card.value) shell.value?.cockpit?.(card.value); + } + + function setView(next) { + view.value = next ? markRaw(next) : null; + } + /** Ask a flight's layer for its route, so the card can draw it. */ + function requestRoute(identity) { + if (!identity?.id || !['flights'].includes(identity.layerId)) return; + const layer = shell.value?.dataManager?.()?.layers?.get?.(identity.layerId); + try { + layer?.module?.requestRoute?.(identity.id); + } catch { + // No route then; the card shows without one. + } + } + + /** A layer's items in an area that pass a test (see layerMatches). */ + function matchesIn(layerId, area) { + const dm = shell.value?.dataManager?.(); + if (!dm || !dm.isEnabled?.(layerId)) return null; + return layerMatches(dm, layerId, area); + } + + /** What the loaded layers have in the current view, by layer. */ + function inView(options) { + const dm = shell.value?.dataManager?.(); + if (!dm || !view.value) return []; + return viewSummary(dm, view.value.rect, view.value.center, options); + } + /** Ask GEV about the view, with what is in it. */ + function askAboutView(summary) { + const where = view.value; + if (!where) return; + const counts = summary.map((group) => `${group.count} ${group.layerName}`).join(', '); + shell.value?.askText?.( + `What am I looking at? The view is centred on ${where.center.lat.toFixed(4)}, ${where.center.lon.toFixed(4)} from about ${Math.round(where.heightM)} m up${counts ? `, showing ${counts}` : ''}. What is here and what stands out?`, + ); + } + + /** What is loaded around a ground point, as the card's nearby lists. */ + /** The layers that are on, as the data manager lists them. */ + function liveLayers() { + const dm = shell.value?.dataManager?.(); + try { + return (dm?.getAll?.() || []).filter((row) => row.enabled); + } catch { + return []; + } + } + + /** What a layer's items are made of (see layerBreakdown). */ + function breakdown(layerId, options) { + return layerBreakdown(shell.value?.dataManager?.(), layerId, options); + } + + /** Loaded records near a point that broadcast a warning. */ + function alertsAt(lat, lon, options) { + return alertsNear(shell.value?.dataManager?.(), { lat, lon }, options); + } + + /** + * What the loaded layers have within a radius of a point, grouped the way + * every card lists it: `{flights, vessels, other}` (see nearbyByKind). + */ + function nearbyGroups(lat, lon, options) { + return nearbyByKind(shell.value?.dataManager?.(), { lat, lon }, options); + } + + /** Whether a card's layer is known to the layer manager and switched off. */ + function layerOff(layerId) { + const dm = dataManager(); + const id = layerId; + if (!dm?.isEnabled || !dm.layers?.has?.(id)) return false; + return dm.isEnabled(id) === false; + } + + function refresh() { + const current = card.value; + if (!current) return; + // A card does not outlive its layer: turning the layer off (or clearing + // all layers) closes it and lets go of the camera. + if (layerOff(current.layerId)) return clear(); + const next = describeEntity(dataManager(), current.identity); + // Keep showing the last reading when the item drops out of its feed. + if (!next || next.key !== current.key || next.basis !== 'record') { + lost.value = current.basis === 'record'; + tick.value++; + return; + } + card.value = markRaw(next); + lost.value = false; + tick.value++; + } + + /** + * Show an item on the card. + * @param {object} identity `{layerId, id, label, lat, lon, record?}` + * @param {object} [options] + * @param {boolean} [options.fly] Also fly the camera to it. + * @returns {boolean} Whether a card could be made. + */ + /** Things that move are followed as soon as they are picked. */ + const AUTO_FOLLOW = new Set(['flights', 'military', 'local-adsb', 'satellites', 'ais-live-vessels']); + /** The key of the item the camera is following, if any. */ + const following = ref(null); + + /** + * @param {object} identity + * @param {{fly?: boolean, follow?: boolean}} [options] `follow: false` + * keeps the camera where it is even for an aircraft. + */ + function select(identity, { fly = false, follow: autoFollow = true } = {}) { + if (!read(identity)) return false; + clearInterval(timer); + timer = setInterval(refresh, REFRESH_MS); + shell.value?.openPanel?.(); + const current = card.value; + const followNow = autoFollow && AUTO_FOLLOW.has(current?.layerId) && shell.value?.canFollow?.(current); + if (followNow) { + // Tracking can announce the craft again; following what is already + // followed would loop, so it only starts once per item. + if (following.value !== current.key) { + following.value = current.key; + shell.value?.follow?.(current); + } + } else { + if (following.value && following.value !== current?.key) following.value = null; + if (fly) shell.value?.flyTo?.(current); + } + requestRoute(current?.identity); + return true; + } + + function clear() { + following.value = null; + clearInterval(timer); + timer = null; + card.value = null; + lost.value = false; + } + + const flyTo = () => card.value && shell.value?.flyTo?.(card.value); + const follow = () => { + if (!card.value) return; + following.value = card.value.key; + shell.value?.follow?.(card.value); + }; + const isFollowing = () => Boolean(card.value && following.value === card.value.key); + const ask = () => card.value && shell.value?.ask?.(card.value); + const canFollow = () => Boolean(shell.value?.canFollow?.(card.value)); + /** Loaded items whose name or id matches typed text, for the omnibar. */ + const search = (query, options) => + shell.value + ? searchEntities(dataManager(), query, { + near: shell.value.here?.() || null, + ...options, + }) + : []; + + return { + card, + lost, + tick, + connect, + select, + clear, + refresh, + flyTo, + follow, + ask, + canFollow, + isFollowing, + following, + search, + nearbyGroups, + alertsAt, + liveLayers, + breakdown, + view, + setView, + matchesIn, + sourceOf, + canCockpit, + cockpit, + inView, + askAboutView, + }; +}); diff --git a/src/ui/styles/context-dock.css b/src/ui/styles/context-dock.css new file mode 100644 index 000000000..7e07f08e2 --- /dev/null +++ b/src/ui/styles/context-dock.css @@ -0,0 +1,185 @@ +/* ── Context expanded ─────────────────────────────────────────────────── + Expanded, Context becomes a full-height column over the right edge of the + screen. The globe and HUD stay where they are, under it. */ +:root { + --context-dock-width: clamp(360px, 30vw, 460px); +} + +/* The column: edge to edge, top to bottom, no rail beside it. */ +body.context-docked #right-context-rail { + z-index: 170; + top: 0 !important; + right: 0 !important; + bottom: 0 !important; + width: var(--context-dock-width) !important; + max-height: none !important; + height: 100vh !important; +} + +body.context-docked #right-context-rail > .gev-panel-rail { + display: none; +} + +body.context-docked #right-context-rail > :not(#global-context-panel):not(.gev-panel-rail) { + display: none !important; +} + +body.context-docked #right-context-rail > #global-context-panel { + flex: 1 1 auto !important; + width: 100% !important; + height: 100% !important; + max-height: none !important; +} + +body.context-docked #global-context-panel .global-context-panel-inner { + height: 100%; + padding: 22px 24px 16px; + background: rgba(10, 11, 16, 0.94); + border: 0; + border-left: 1px solid rgba(255, 255, 255, 0.08); + border-radius: 0; + box-shadow: -18px 0 40px rgba(0, 0, 0, 0.35); +} + +body.context-docked #global-context-panel .panel-glow { + display: none; +} + +/* The expand button sits beside the collapse button in the header. */ +.context-dock-btn { + display: grid; + flex: none; + place-items: center; + width: 28px; + height: 28px; + margin-inline-end: 6px; + padding: 0; + color: var(--text-secondary); + background: transparent; + border: 1px solid var(--glass-border); + border-radius: var(--btn-radius); + cursor: pointer; +} + +.context-dock-btn .material-symbols-outlined { + font-size: 16px; +} + +.context-dock-btn:hover, +.context-dock-btn:focus-visible, +.context-dock-btn[aria-pressed='true'] { + color: var(--accent); + border-color: var(--accent-dim); + background: var(--accent-dim); +} + +/* Phones keep their sheets; the dock is a desktop layout. */ +body.mobile-shell .context-dock-btn { + display: none; +} + +/* Context's own search field, under the header: narrows what the panel shows. + Sized and framed like the tab bar beneath it. */ +.context-search { + position: sticky; + top: 0; + z-index: 2; + display: flex; + flex: none; + box-sizing: border-box; + align-items: center; + gap: 8px; + min-height: 34px; + margin: 0 0 0.5rem; + padding: 0 6px 0 10px; + color: rgba(199, 214, 222, 0.65); + background: rgba(16, 22, 28, 0.94); + border: 1px solid rgba(54, 220, 255, 0.35); + border-radius: 10px; + backdrop-filter: blur(8px); +} + +.context-search:focus-within { + color: #7af0ff; + border-color: rgba(54, 220, 255, 0.7); + box-shadow: 0 0 0 3px rgba(54, 220, 255, 0.1); +} + +.context-search .material-symbols-outlined { + font-size: 17px; +} + +.context-search__input::placeholder { + color: rgba(199, 214, 222, 0.45); +} + +.context-search__input { + flex: 1; + min-width: 0; + height: 100%; + padding: 0; + color: var(--text-primary, #e8eaed); + font: inherit; + font-size: 0.74rem; + line-height: 32px; + background: transparent; + border: 0; + outline: 0; +} + +.context-search__input::-webkit-search-cancel-button { + display: none; +} + +.context-search__clear { + display: grid; + flex: none; + place-items: center; + width: 24px; + height: 24px; + padding: 0; + color: rgba(199, 214, 222, 0.65); + background: transparent; + border: 0; + border-radius: 50%; + cursor: pointer; +} + +.context-search__clear:hover, +.context-search__clear:focus-visible { + color: var(--accent); +} + +.entity-card__no-match { + margin: 0 0 0.7rem; + color: rgba(199, 214, 222, 0.6); + font-size: 0.66rem; +} + +.context-search__input:focus, +.context-search__input:focus-visible { + outline: 0; + box-shadow: none; +} + +/* While a search is typed, what cannot match steps aside so the matches lead: + the weather, the view's own figures, the route and altitude graph, and the + layer switches. The radius stays: it sets how far the search looks. */ +.context-searching :is( + .spot-conditions__weather, + .spot-conditions__loading, + .spot-conditions__source, + .view-context__facts, + .view-context__live, + .view-context__total, + .view-context__actions, + .view-context__towns:has(.view-context__chip--layer), + .altitude-graph, + .entity-card__route, + .entity-card__route-stats, + .entity-card__route-places, + .entity-card__route-note, + .entity-card__links + ) { + display: none; +} diff --git a/src/ui/styles/context-tabs.css b/src/ui/styles/context-tabs.css new file mode 100644 index 000000000..1dd7c23e4 --- /dev/null +++ b/src/ui/styles/context-tabs.css @@ -0,0 +1,125 @@ +/* ── Context layer tabs ───────────────────────────────────────────────── + Settings for the layers that are on, as tabs beside the card. */ +.context-tabs { + display: flex; + flex: none; + min-height: 34px; + box-sizing: border-box; + gap: 4px; + margin: 0 0 0.7rem; + padding: 3px; + overflow-x: auto; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 10px; + scrollbar-width: none; +} + +.context-tabs::-webkit-scrollbar { + display: none; +} + +.context-tabs__tab { + display: inline-flex; + flex: none; + min-height: 26px; + align-items: center; + gap: 0.3rem; + max-width: 9.5rem; + padding: 0.3rem 0.55rem; + color: rgba(199, 214, 222, 0.65); + font-family: var(--font-mono); + font-size: 0.56rem; + letter-spacing: 0.08rem; + text-transform: uppercase; + background: none; + border: 1px solid transparent; + border-radius: 7px; + cursor: pointer; +} + +.context-tabs__tab .material-symbols-outlined { + font-size: 14px; +} + +.context-tabs__label { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.context-tabs__tab:hover { + color: #fff; + background: rgba(255, 255, 255, 0.05); +} + +.context-tabs__tab.active { + color: #7af0ff; + background: rgba(54, 220, 255, 0.12); + border-color: rgba(54, 220, 255, 0.35); +} + +.context-tab-pane[hidden] { + display: none !important; +} + +/* Controls moved in from Visual show their rows openly here. */ +.context-tab-pane .pp-toggle-group { + margin: 0; +} + +/* Two even tabs: Inspector and Properties. */ +.context-tabs__tab { + flex: 1 1 0; + justify-content: center; + max-width: none; +} + +.context-props[hidden] { + display: none !important; +} + +.context-props__section + .context-props__section { + margin-top: 0.9rem; +} + +.context-props__heading { + display: flex; + align-items: center; + gap: 0.4rem; + margin: 0 0 0.45rem; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.14rem; + text-transform: uppercase; +} + +.context-props__heading .material-symbols-outlined { + font-size: 14px; +} + +.context-props__layers { + display: flex; + flex-wrap: wrap; + gap: 0.25rem 0.75rem; + margin: -0.15rem 0 0.5rem; + padding: 0; + list-style: none; +} + +.context-props__layers li { + display: inline-flex; + align-items: center; + gap: 0.35rem; + color: rgba(214, 228, 236, 0.8); + font-size: 0.66rem; +} + +.context-props__layers i { + width: 7px; + height: 7px; + border-radius: 50%; + box-shadow: 0 0 6px currentColor; +} diff --git a/src/ui/styles/entity-card.css b/src/ui/styles/entity-card.css new file mode 100644 index 000000000..bea47e724 --- /dev/null +++ b/src/ui/styles/entity-card.css @@ -0,0 +1,1752 @@ +/* ── Context panel: the card for one thing on the map ────────────────── + Sits at the top of the Context panel, above the mode switch. Glass like + the omnibar sheet; the title in the mono face the HUD uses. */ +.entity-card { + margin: 0 0 0.75rem; + padding: 0.7rem 0.75rem 0.6rem; + color: rgba(225, 236, 242, 0.92); + background: rgba(40, 44, 52, 0.55); + border: 1px solid rgba(255, 255, 255, 0.09); + border-radius: 10px; +} + +.entity-card__head { + display: flex; + align-items: center; + gap: 0.5rem; +} + +.entity-card__icon { + display: grid; + flex: none; + place-items: center; + width: 1.9rem; + height: 1.9rem; + color: #36dcff; + font-size: 1.1rem; + background: rgba(29, 69, 81, 0.35); + border: 1px solid rgba(48, 194, 224, 0.35); + border-radius: 7px; +} + +.entity-card__kind { + display: flex; + flex: 1; + flex-direction: column; + min-width: 0; + font-size: 0.62rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.entity-card__kind > span:first-child { + color: rgba(225, 236, 242, 0.85); +} + +.entity-card__layer { + overflow: hidden; + color: rgba(199, 214, 222, 0.5); + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-card__status { + flex: none; + padding: 0.12rem 0.45rem; + font-size: 0.58rem; + white-space: nowrap; + border: 1px solid currentColor; + border-radius: 999px; +} + +.entity-card__status--live { + color: #5ee6a0; +} + +.entity-card__status--live::before { + display: inline-block; + width: 5px; + height: 5px; + margin-right: 0.3rem; + vertical-align: middle; + background: currentColor; + border-radius: 50%; + content: ''; + animation: entity-card-pulse 1.6s ease-in-out infinite; +} + +.entity-card__status--aged { + color: rgba(199, 214, 222, 0.6); +} + +.entity-card__status--lost { + color: #ff9f43; +} + +.entity-card__close { + display: grid; + flex: none; + place-items: center; + width: 1.5rem; + height: 1.5rem; + padding: 0; + color: rgba(199, 214, 222, 0.6); + background: none; + border: 0; + border-radius: 6px; + cursor: pointer; +} + +.entity-card__close:hover, +.entity-card__close:focus-visible { + color: #fff; + background: rgba(255, 255, 255, 0.08); +} + +.entity-card__close .material-symbols-outlined { + font-size: 1rem; +} + +.entity-card__title { + margin: 0.55rem 0 0.1rem; + overflow-wrap: anywhere; + font-family: var(--font-mono); + font-size: 1rem; + font-weight: 600; + letter-spacing: 0.02rem; +} + +.entity-card__where { + margin: 0 0 0.5rem; + color: rgba(199, 214, 222, 0.5); + font-family: var(--font-mono); + font-size: 0.62rem; + white-space: pre; +} + +.entity-card__facts { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 0.4rem 0.75rem; + margin: 0 0 0.55rem; +} + +.entity-card__fact { + min-width: 0; +} + +.entity-card__fact dt { + color: rgba(199, 214, 222, 0.5); + font-size: 0.56rem; + letter-spacing: 0.05rem; + text-transform: uppercase; +} + +.entity-card__fact dd { + margin: 0.1rem 0 0; + overflow: hidden; + font-family: var(--font-mono); + font-size: 0.72rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-card__empty { + margin: 0 0 0.55rem; + color: rgba(199, 214, 222, 0.55); + font-size: 0.68rem; +} + +.entity-card__links { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + margin: 0 0 0.55rem; +} + +.entity-card__links a { + padding: 0.15rem 0.5rem; + color: #36dcff; + font-size: 0.64rem; + text-decoration: none; + border: 1px solid rgba(48, 194, 224, 0.35); + border-radius: 999px; +} + +.entity-card__links a:hover, +.entity-card__links a:focus-visible { + background: rgba(48, 194, 224, 0.12); +} + +.entity-card__actions { + display: flex; + gap: 0.35rem; + padding-top: 0.5rem; + border-top: 1px solid rgba(255, 255, 255, 0.07); +} + +.entity-card__action { + display: inline-flex; + flex: 1; + align-items: center; + justify-content: center; + gap: 0.3rem; + height: 1.9rem; + padding: 0 0.4rem; + color: rgba(225, 236, 242, 0.88); + font-size: 0.66rem; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 7px; + cursor: pointer; + transition: + background 140ms ease, + border-color 140ms ease; +} + +.entity-card__action .material-symbols-outlined { + font-size: 0.95rem; +} + +.entity-card__action:hover, +.entity-card__action:focus-visible { + background: rgba(48, 194, 224, 0.12); + border-color: rgba(48, 194, 224, 0.45); +} + +.entity-card__action--ask { + color: #ffb877; +} + +.entity-card__action--ask:hover, +.entity-card__action--ask:focus-visible { + background: rgba(255, 159, 67, 0.12); + border-color: rgba(255, 159, 67, 0.5); +} + +.entity-card__nearby { + margin-top: 0.65rem; +} + +.entity-card__nearby h4 { + margin: 0 0 0.25rem; + color: rgba(199, 214, 222, 0.5); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.entity-card__nearby ul { + margin: 0; + padding: 0; + list-style: none; +} + +.entity-card__nearby button { + display: flex; + align-items: center; + gap: 0.5rem; + width: 100%; + padding: 0.3rem 0.35rem; + color: rgba(225, 236, 242, 0.85); + font-size: 0.68rem; + text-align: left; + background: none; + border: 0; + border-radius: 6px; + cursor: pointer; +} + +.entity-card__nearby button:hover, +.entity-card__nearby button:focus-visible { + background: rgba(255, 255, 255, 0.06); +} + +.entity-card__nearby .material-symbols-outlined { + color: rgba(199, 214, 222, 0.6); + font-size: 0.95rem; +} + +.entity-card__row-title { + display: flex; + flex: 1; + flex-direction: column; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-card__row-title small { + color: rgba(199, 214, 222, 0.45); + font-size: 0.56rem; +} + +.entity-card__row-meta { + flex: none; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.6rem; +} + +.entity-card-enter-active, +.entity-card-leave-active { + transition: + opacity 200ms ease, + transform 220ms cubic-bezier(0.22, 1, 0.36, 1); +} + +.entity-card-enter-from, +.entity-card-leave-to { + opacity: 0; + transform: translateY(-6px); +} + +@keyframes entity-card-pulse { + 50% { + opacity: 0.35; + } +} + +@media (prefers-reduced-motion: reduce) { + .entity-card-enter-active, + .entity-card-leave-active { + transition: opacity 120ms ease; + } + + .entity-card-enter-from, + .entity-card-leave-to { + transform: none; + } + + .entity-card__status--live::before { + animation: none; + } +} + +/* Context is one card for whatever is picked: the old Contacts and Space + Missions modes and the Radio strip are out of it. Their markup stays, as + their controls still find their buttons by id, but none of it shows. */ +#global-context-panel + :is( + .global-context-modes, + #context-mode-standby, + #context-flights-view, + #context-missions-view, + #radio-panel + ) { + display: none !important; +} + +/* ── In view: what the panel shows while nothing is picked ───────────── */ +.view-context { + margin: 0 0 0.75rem; + padding: 0.7rem 0.75rem 0.6rem; + color: rgba(225, 236, 242, 0.92); + background: rgba(40, 44, 52, 0.55); + border: 1px solid rgba(255, 255, 255, 0.09); + border-radius: 10px; +} + +.view-context__head { + display: flex; + align-items: center; + gap: 0.5rem; +} + +.view-context__icon { + display: grid; + flex: none; + place-items: center; + width: 1.9rem; + height: 1.9rem; + color: #36dcff; + font-size: 1.1rem; + background: rgba(29, 69, 81, 0.35); + border: 1px solid rgba(48, 194, 224, 0.35); + border-radius: 7px; +} + +.view-context__kind { + display: flex; + flex-direction: column; + font-size: 0.62rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.view-context__sub { + color: rgba(199, 214, 222, 0.5); +} + +.view-context__title { + margin: 0.55rem 0 0.1rem; + overflow-wrap: anywhere; + font-family: var(--font-mono); + font-size: 1rem; + font-weight: 600; +} + +.view-context__where { + margin: 0 0 0.55rem; + color: rgba(199, 214, 222, 0.5); + font-family: var(--font-mono); + font-size: 0.62rem; + white-space: pre; +} + +.view-context__total, +.view-context__empty { + margin: 0 0 0.4rem; + color: rgba(199, 214, 222, 0.7); + font-size: 0.68rem; + line-height: 1.45; +} + +.view-context__group + .view-context__group { + margin-top: 0.45rem; +} + +.view-context__group h4 { + display: flex; + align-items: center; + gap: 0.4rem; + margin: 0 0 0.15rem; + color: rgba(199, 214, 222, 0.6); + font-size: 0.58rem; + font-weight: 500; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.view-context__group h4 .material-symbols-outlined { + font-size: 0.95rem; +} + +.view-context__count { + margin-inline-start: auto; + color: #36dcff; + font-family: var(--font-mono); +} + +.view-context__group ul { + margin: 0; + padding: 0; + list-style: none; +} + +.view-context__group button { + display: flex; + align-items: center; + gap: 0.5rem; + width: 100%; + padding: 0.28rem 0.35rem 0.28rem 1.75rem; + color: rgba(225, 236, 242, 0.85); + font-size: 0.68rem; + text-align: left; + background: none; + border: 0; + border-radius: 6px; + cursor: pointer; +} + +.view-context__group button:hover, +.view-context__group button:focus-visible { + background: rgba(255, 255, 255, 0.06); +} + +.view-context__row-title { + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.view-context__row-meta { + flex: none; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.6rem; +} + +.view-context__actions { + display: flex; + margin-top: 0.6rem; + padding-top: 0.5rem; + border-top: 1px solid rgba(255, 255, 255, 0.07); +} + +.context-empty { + display: grid; + justify-items: start; + gap: 6px; + padding: 14px 4px 6px; + color: var(--text-secondary); + font: 12px/1.45 var(--font-sans); +} + +.context-empty .material-symbols-outlined { + color: var(--accent); + font-size: 22px; +} + +.context-empty strong { + color: var(--text-primary); + font: 600 11px/1.2 var(--font-mono); + letter-spacing: 0.14em; + text-transform: uppercase; +} + +/* A warning leads the card, above the name: an emergency, a tsunami flag. */ +.entity-card__warning { + display: flex; + align-items: flex-start; + gap: 0.4rem; + margin: 0.55rem 0 0; + padding: 0.4rem 0.55rem; + color: #ffd6d0; + font-size: 0.68rem; + font-weight: 600; + line-height: 1.35; + background: rgba(255, 75, 62, 0.16); + border: 1px solid rgba(255, 75, 62, 0.55); + border-radius: 7px; +} + +.entity-card__warning .material-symbols-outlined { + flex: none; + color: #ff6b5e; + font-size: 1rem; +} + +/* Where the card's data comes from, and how fresh it is. */ +.entity-card__source { + margin: 0.6rem 0 0; + padding-top: 0.45rem; + color: rgba(199, 214, 222, 0.5); + font-size: 0.6rem; + border-top: 1px solid rgba(255, 255, 255, 0.07); +} + +.entity-card__source span { + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +/* Open, Context fills the right column top to bottom, its card scrolling + inside rather than the panel growing and shrinking with each selection. */ +#right-context-rail > #global-context-panel:not(.collapsed), +#right-context-rail.layout-focus > #global-context-panel:not(.collapsed) { + flex: 0 0 var(--right-stack-max-height, auto); + height: var(--right-stack-max-height, auto); + max-height: var(--right-stack-max-height, 100%); +} + +#right-context-rail + > #global-context-panel:not(.collapsed) + .global-context-panel-inner { + height: 100%; +} + +/* The icon font's own rules (display: block, 24px) beat the badge's; keep + the glyph centred in its square at the badge's size. */ +.entity-card__head .entity-card__icon.material-symbols-outlined, +.view-context__head .view-context__icon.material-symbols-outlined { + display: grid; + place-items: center; + box-sizing: border-box; + width: 1.9rem; + height: 1.9rem; + font-size: 1.1rem; + line-height: 1; + overflow: hidden; +} + +/* The aircraft's model, turning at the top of its card on a soft spotlight. */ + +/* Origin to destination, as one line with the craft on it. */ +.entity-card__route { + display: flex; + align-items: center; + gap: 0.5rem; + margin: 0.15rem 0 0.55rem; + font-family: var(--font-mono); + font-size: 0.85rem; +} + +.entity-card__route-line { + position: relative; + display: grid; + flex: 1; + place-items: center; + height: 1rem; + background: linear-gradient( + 90deg, + rgba(199, 214, 222, 0.35) 50%, + transparent 0 + ) + center / 7px 1px repeat-x; +} + +.entity-card__route-line .material-symbols-outlined { + padding: 0 0.25rem; + color: #36dcff; + font-size: 0.95rem; + background: rgba(40, 44, 52, 1); + transform: rotate(90deg); +} + +/* Headline figures: big numbers, small labels. */ +.entity-card__tiles { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 0.35rem; + margin: 0.2rem 0 0.55rem; +} + +.entity-card__tile { + display: grid; + gap: 0.2rem; + padding: 0.45rem 0.4rem; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 8px; +} + +.entity-card__tile span { + color: rgba(199, 214, 222, 0.5); + font-size: 0.54rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.entity-card__tile strong { + overflow: hidden; + color: rgba(236, 244, 248, 0.95); + font-family: var(--font-mono); + font-size: 0.76rem; + font-weight: 600; + letter-spacing: -0.02em; + text-overflow: ellipsis; + white-space: nowrap; +} + +/* The callout on the turning model, in the frame's top-left corner. The + leader sits under the text: a dot near the craft lights first, the line + draws from it up to the corner, then the label and value fade in. */ + +/* The parts legend and the scan caption, bottom right of the model. */ + +/* ── Card, second pass ────────────────────────────────────────────────── + One surface: inside Context the card is the panel's content, not a box in + a box. Identity leads (kind, name, who and what), then status and place, + the model, headline figures, details, actions, what is near, the source. */ +#global-context-panel .entity-card, +#global-context-panel .view-context { + margin: 0; + padding: 0.15rem 0 0.4rem; + background: none; + border: 0; + border-radius: 0; +} + +.entity-card__head { + align-items: flex-start; + gap: 0.6rem; +} + +.entity-card__name { + display: grid; + flex: 1; + gap: 0.12rem; + min-width: 0; +} + +#entity-card .entity-card__kind { + display: block; + color: rgba(199, 214, 222, 0.5); + font-size: 0.56rem; + letter-spacing: 0.08rem; + text-transform: uppercase; +} + +#entity-card .entity-card__title { + margin: 0; + font-size: 1.15rem; + line-height: 1.1; + letter-spacing: 0.03rem; +} + +.entity-card__subtitle { + overflow: hidden; + color: rgba(225, 236, 242, 0.72); + font-size: 0.7rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-card__meta { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.35rem 0.6rem; + margin: 0.55rem 0 0.15rem; +} + +#entity-card .entity-card__where { + margin: 0; + font-size: 0.6rem; +} + +/* The model sits edge to edge under the name, framed by hairlines. */ + +/* Tiles: the number leads, its unit sits small beside it. */ +#entity-card .entity-card__tile strong { + display: flex; + align-items: baseline; + gap: 0.2rem; + font-size: 0.95rem; + letter-spacing: -0.01em; +} + +#entity-card .entity-card__tile small { + color: rgba(199, 214, 222, 0.6); + font-size: 0.6rem; + font-weight: 500; +} + +/* Sections get a quiet heading with a hairline under it. */ +.entity-card__section { + margin-top: 0.75rem; +} + +.entity-card__section > h4, +#entity-card .entity-card__nearby h4 { + display: flex; + align-items: center; + gap: 0.4rem; + margin: 0 0 0.35rem; + padding-bottom: 0.3rem; + color: rgba(199, 214, 222, 0.55); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.08rem; + text-transform: uppercase; + border-bottom: 1px solid rgba(255, 255, 255, 0.06); +} + +.entity-card__section > h4 span { + padding: 0 0.3rem; + color: rgba(54, 220, 255, 0.85); + font-family: var(--font-mono); + background: rgba(54, 220, 255, 0.1); + border-radius: 999px; +} + +/* Actions: the three moves in a row, then asking GEV across the width. */ +#entity-card .entity-card__actions { + display: grid; + gap: 0.35rem; + margin-top: 0.8rem; + padding-top: 0; + border-top: 0; +} + +.entity-card__action-row { + display: flex; + gap: 0.35rem; +} + +#entity-card .entity-card__action--ask { + width: 100%; + height: 2.1rem; + color: #ffb86b; + background: rgba(255, 159, 67, 0.08); + border-color: rgba(255, 159, 67, 0.35); +} + +#entity-card .entity-card__action--ask:hover, +#entity-card .entity-card__action--ask:focus-visible { + background: rgba(255, 159, 67, 0.16); + border-color: rgba(255, 159, 67, 0.6); +} + +/* ── Callout states ────────────────────────────────────────────────────── + Enter 0-2.3 s (dot, leader, text), hold to 5.2 s (dot breathes, timer + fills), exit over 1 s (text, then leader back into the dot, then dot). */ + +/* Exit: text first, then the leader retracts toward the dot, then the dot. */ + +/* The route on its small globe, and the Route / Model switch above it. */ + +/* In view, richer: region, the view's figures as tiles, places in view and + layer switches as chips. */ +.view-context__region { + margin: 0 0 0.15rem; + color: rgba(225, 236, 242, 0.7); + font-size: 0.7rem; +} + +.view-context__facts { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.35rem; + margin: 0.4rem 0 0.7rem; +} + +.view-context__fact { + display: grid; + gap: 0.18rem; + padding: 0.45rem 0.5rem; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 8px; +} + +.view-context__fact span { + color: rgba(199, 214, 222, 0.5); + font-size: 0.54rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.view-context__fact strong { + overflow: hidden; + color: rgba(236, 244, 248, 0.95); + font-family: var(--font-mono); + font-size: 0.78rem; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; +} + +.view-context__towns { + margin: 0.2rem 0 0.7rem; +} + +.view-context__towns h4 { + margin: 0 0 0.35rem; + padding-bottom: 0.3rem; + color: rgba(199, 214, 222, 0.55); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.08rem; + text-transform: uppercase; + border-bottom: 1px solid rgba(255, 255, 255, 0.06); +} + +.view-context__chips { + display: flex; + flex-wrap: wrap; + gap: 0.3rem; +} + +.view-context__chips button { + display: inline-flex; + align-items: center; + gap: 0.2rem; + padding: 0.28rem 0.6rem; + color: rgba(225, 236, 242, 0.85); + font-size: 0.66rem; + background: rgba(255, 255, 255, 0.05); + border: 1px solid rgba(255, 255, 255, 0.09); + border-radius: 999px; + cursor: pointer; +} + +.view-context__chips button:hover, +.view-context__chips button:focus-visible { + color: #fff; + background: rgba(54, 220, 255, 0.12); + border-color: rgba(54, 220, 255, 0.4); +} + +.view-context__chips .material-symbols-outlined { + font-size: 0.85rem; +} + +/* A scheduled route that does not fit the plane's position: amber, dashed, + with a note, so it cannot pass for the flight's actual route. */ +.entity-card__route--unverified strong { + color: #ffb86b; +} + +.entity-card__route--unverified .entity-card__route-line { + background-image: linear-gradient( + 90deg, + rgba(255, 184, 107, 0.55) 50%, + transparent 0 + ); +} + +.entity-card__route--unverified + .entity-card__route-line + .material-symbols-outlined { + color: #ffb86b; +} + +.entity-card__route-note { + display: flex; + align-items: center; + gap: 0.3rem; + margin: -0.3rem 0 0.55rem; + color: rgba(255, 184, 107, 0.85); + font-size: 0.6rem; +} + +.entity-card__route-note .material-symbols-outlined { + font-size: 0.85rem; +} + +/* Route progress: the line filled from the origin up to the plane, which + sits at its share of the way, and dashed beyond it to the destination. */ +.entity-card__route--progress .entity-card__route-line { + display: block; + background: + linear-gradient(90deg, #36dcff, #36dcff) left center / + var(--route-share, 0%) 2px no-repeat, + linear-gradient(90deg, rgba(199, 214, 222, 0.35) 50%, transparent 0) + center / 7px 1px repeat-x; + transition: background-size 600ms ease; +} + +.entity-card__route--progress + .entity-card__route-line + .material-symbols-outlined { + position: absolute; + top: 50%; + left: var(--route-share, 0%); + padding: 0 0.15rem; + transform: translate(-50%, -50%) rotate(90deg); + transition: left 600ms ease; +} + +.entity-card__route-stats { + display: flex; + justify-content: space-between; + gap: 0.5rem; + margin: -0.3rem 0 0.6rem; + color: rgba(199, 214, 222, 0.6); + font-family: var(--font-mono); + font-size: 0.58rem; +} + +/* The route globe's corner label: each airport's code over its city and + state, on a soft scrim so it reads over the imagery. */ + +/* The airports' cities, under the progress bar: origin left, destination right. */ +.entity-card__route-places { + display: flex; + justify-content: space-between; + gap: 0.75rem; + margin: -0.35rem 0 0.65rem; + color: rgba(225, 236, 242, 0.75); + font-size: 0.64rem; +} + +.entity-card__route-places span { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-card__route-places span:last-child { + text-align: right; +} + +/* While the preview takes turns, a hairline under the active tab fills until + the switch; a tab the viewer picked stays put and shows no timer. */ +/* The minimap's compass, top right: north at the top (the view is north up), + the cyan needle on the course to the destination, its bearing beneath. */ + +/* Follow, while the camera is on the craft. */ +#entity-card .entity-card__action--on { + color: #36dcff; + background: rgba(54, 220, 255, 0.12); + border-color: rgba(54, 220, 255, 0.45); +} + +/* ── Context refinements: one heading style, one tile style, even rhythm ── */ +.view-context__towns h4, +.view-context__group h4, +.spot-conditions__block h4, +.entity-card__section h4, +.entity-card__nearby h4 { + margin: 0 0 0.4rem; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.14rem; + text-transform: uppercase; +} + +.view-context__towns, +.view-context__groups, +.spot-conditions__block, +.entity-card__section { + margin-top: 0.85rem; +} + +.view-context__fact, +.entity-card__tile, +.spot-conditions__weather { + border-radius: 8px; + border-color: rgba(255, 255, 255, 0.07); +} + +.view-context__title { + letter-spacing: 0.02em; +} + +.view-context__where { + margin-bottom: 0.2rem; +} + +/* Place chips match the omnibox's chips. */ +.view-context__chips button { + border-radius: 999px; +} + +/* ── In view: the layers that are on ── */ +.view-context__live { + margin-top: 0.85rem; +} + +.view-context__live h4 { + display: flex; + align-items: center; + gap: 0.4rem; + margin: 0 0 0.4rem; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.14rem; + text-transform: uppercase; +} + +.view-context__live h4 .view-context__count { + margin-inline-start: auto; +} + +.view-context__live ul { + display: grid; + gap: 0.25rem; + margin: 0; + padding: 0; + list-style: none; +} + +.view-context__live-row { + display: flex; + align-items: center; + gap: 0.55rem; + padding: 0.4rem 0.45rem 0.4rem 0.55rem; + background: rgba(255, 255, 255, 0.035); + border: 1px solid rgba(255, 255, 255, 0.06); +} + +.view-context__live-icon { + flex: none; + font-size: 0.95rem; +} + +.view-context__live-main { + display: grid; + flex: 1 1 auto; + gap: 0.08rem; + min-width: 0; +} + +.view-context__live-name { + overflow: hidden; + color: rgba(236, 244, 248, 0.94); + font-size: 0.72rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.view-context__live-meta { + overflow: hidden; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.58rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.view-context__live-state { + flex: none; + padding: 0.12rem 0.4rem; + font-family: var(--font-mono); + font-size: 0.52rem; + letter-spacing: 0.1rem; + text-transform: uppercase; + border: 1px solid currentColor; + border-radius: 999px; +} + +.view-context__live-state--live { + color: #4be3a0; +} +.view-context__live-state--loading { + color: #36dcff; +} +.view-context__live-state--stale { + color: #ffb547; +} +.view-context__live-state--error { + color: #ff5c6c; +} + +.view-context__live-off { + display: grid; + flex: none; + place-items: center; + width: 22px; + height: 22px; + padding: 0; + color: rgba(199, 214, 222, 0.5); + background: none; + border: 1px solid transparent; + border-radius: 6px; + cursor: pointer; +} + +.view-context__live-off .material-symbols-outlined { + font-size: 14px; +} + +.view-context__live-off:hover, +.view-context__live-off:focus-visible { + color: #fff; + border-color: rgba(255, 255, 255, 0.18); +} + +/* ── Selected camera: thumbnail, facts, More info ── */ +.cctv-preview { + display: grid; + gap: 0.5rem; + margin: 0.5rem 0 0.75rem; +} + +.cctv-preview__frame { + position: relative; + display: grid; + place-items: center; + aspect-ratio: 16 / 9; + overflow: hidden; + background: #05080b; + border: 1px solid rgba(255, 255, 255, 0.08); + border-radius: 8px; +} + +.cctv-preview__frame img { + width: 100%; + height: 100%; + object-fit: cover; +} + +.cctv-preview__frame.is-empty span:first-child { + color: rgba(199, 214, 222, 0.5); + font-family: var(--font-mono); + font-size: 0.58rem; + letter-spacing: 0.12rem; + text-transform: uppercase; +} + +.cctv-preview__badge { + position: absolute; + left: 6px; + bottom: 6px; + padding: 2px 7px; + color: #4be3a0; + font-family: var(--font-mono); + font-size: 0.5rem; + letter-spacing: 0.1rem; + background: rgba(5, 8, 11, 0.8); + border: 1px solid rgba(75, 227, 160, 0.45); + border-radius: 999px; +} + +.cctv-preview__name { + margin: 0; + color: rgba(236, 244, 248, 0.94); + font-size: 0.78rem; +} + +.cctv-preview__facts { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.35rem; + margin: 0; +} + +.cctv-preview__facts div { + padding: 0.35rem 0.5rem; + background: rgba(255, 255, 255, 0.035); + border: 1px solid rgba(255, 255, 255, 0.06); + border-radius: 7px; +} + +.cctv-preview__facts dt { + color: rgba(199, 214, 222, 0.5); + font-size: 0.52rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.cctv-preview__facts dd { + overflow: hidden; + margin: 0.1rem 0 0; + color: rgba(236, 244, 248, 0.92); + font-family: var(--font-mono); + font-size: 0.68rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.cctv-preview__more { + justify-content: center; +} + +.cctv-preview__expand { + position: absolute; + top: 6px; + right: 6px; + display: grid; + place-items: center; + width: 26px; + height: 26px; + padding: 0; + color: rgba(236, 244, 248, 0.9); + background: rgba(5, 8, 11, 0.7); + border: 1px solid rgba(255, 255, 255, 0.18); + border-radius: 7px; + cursor: pointer; +} + +.cctv-preview__expand .material-symbols-outlined { + font-size: 15px; +} + +.cctv-preview__expand:hover, +.cctv-preview__expand:focus-visible { + color: #7af0ff; + border-color: rgba(54, 220, 255, 0.6); +} + +/* ── Bigger camera view ── */ +.cctv-popup { + position: fixed; + inset: 0; + z-index: 400; + display: grid; + place-items: center; + padding: 2rem; + background: rgba(2, 4, 8, 0.55); + backdrop-filter: blur(3px); + -webkit-backdrop-filter: blur(3px); + animation: cctv-popup-in 160ms ease; +} + +@keyframes cctv-popup-in { + from { + opacity: 0; + } +} + +.cctv-popup__card { + display: grid; + gap: 0.6rem; + width: min(960px, 92vw); + margin: 0; + padding: 0.7rem; + background: rgba(12, 12, 20, 0.92); + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 14px; + box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); +} + +.cctv-popup__head { + display: flex; + align-items: center; + gap: 0.55rem; + padding: 0 0.2rem; + color: rgba(236, 244, 248, 0.94); + font-family: var(--font-mono); + font-size: 0.8rem; + letter-spacing: 0.04em; +} + +.cctv-popup__head > .material-symbols-outlined { + color: #36dcff; + font-size: 18px; +} + +.cctv-popup__badge { + padding: 2px 8px; + color: #4be3a0; + font-size: 0.55rem; + letter-spacing: 0.1rem; + border: 1px solid rgba(75, 227, 160, 0.45); + border-radius: 999px; +} + +.cctv-popup__close { + display: grid; + place-items: center; + width: 28px; + height: 28px; + margin-inline-start: auto; + padding: 0; + color: rgba(236, 244, 248, 0.8); + background: none; + border: 1px solid rgba(255, 255, 255, 0.14); + border-radius: 8px; + cursor: pointer; +} + +.cctv-popup__close:hover { + color: #fff; + border-color: rgba(255, 255, 255, 0.3); +} + +.cctv-popup__card img { + width: 100%; + max-height: 72vh; + object-fit: contain; + background: #000; + border-radius: 8px; +} + +.cctv-popup__card figcaption { + display: flex; + flex-wrap: wrap; + gap: 0.3rem 1.1rem; + padding: 0 0.2rem 0.1rem; + color: rgba(199, 214, 222, 0.6); + font-family: var(--font-mono); + font-size: 0.6rem; + letter-spacing: 0.08rem; + text-transform: uppercase; +} + +.cctv-popup__card figcaption b { + color: rgba(236, 244, 248, 0.92); + font-weight: 500; +} + +/* CCTV, open, fills the right column top to bottom like Context. */ +#right-context-rail > #cctv-panel:not(.collapsed), +#right-context-rail.layout-focus > #cctv-panel:not(.collapsed) { + flex: 0 0 var(--right-stack-max-height, auto); + height: var(--right-stack-max-height, auto); + max-height: var(--right-stack-max-height, 100%); +} + +#right-context-rail > #cctv-panel:not(.collapsed) > .cctv-panel-inner, +#right-context-rail > #cctv-panel:not(.collapsed) > [class$='-inner'] { + height: 100%; +} + +/* ── Hero tile ─────────────────────────────────────────────────────────── + One slot at the top of every card: an aircraft's route globe and turning + model, a camera's frame, or a quiet placeholder with the item's icon and + name. */ +.entity-hero { + position: relative; + margin: 0 0 0.6rem; + overflow: hidden; + border-radius: 10px; +} + +/* Both previews fill the tile, one over the other; the hidden one keeps its + size, so showing it needs no layout and no fresh canvas. */ + +.entity-hero .cctv-preview { + margin: 0; +} + +.entity-hero__placeholder { + display: grid; + grid-template-columns: auto 1fr; + align-items: center; + gap: 0.9rem; + min-height: 84px; + padding: 0.7rem 0.9rem; + background: + radial-gradient( + ellipse 45% 90% at 12% 50%, + rgba(54, 220, 255, 0.1), + transparent 70% + ), + rgba(255, 255, 255, 0.025); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 10px; +} + +.entity-hero__placeholder--bare { + grid-template-columns: 1fr; + justify-items: center; + gap: 0.3rem; + text-align: center; +} + +.entity-hero__glyph.material-symbols-outlined { + display: grid; + place-items: center; + width: 3.2rem; + height: 3.2rem; + color: #36dcff; + font-size: 1.9rem; + background: rgba(54, 220, 255, 0.08); + border: 1px solid rgba(54, 220, 255, 0.18); + border-radius: 50%; +} + +.entity-hero__figures { + display: flex; + flex-wrap: wrap; + gap: 0.4rem 1.1rem; + min-width: 0; +} + +.entity-hero__figure { + display: grid; + gap: 0.15rem; + min-width: 0; +} + +.entity-hero__figure strong { + overflow: hidden; + color: rgba(240, 247, 250, 0.98); + font-family: var(--font-mono); + font-size: 1.15rem; + font-weight: 600; + line-height: 1.05; + text-overflow: ellipsis; + white-space: nowrap; +} + +.entity-hero__figure strong small { + margin-inline-start: 0.2rem; + color: rgba(199, 214, 222, 0.7); + font-size: 0.62rem; + font-weight: 500; +} + +.entity-hero__figure span, +.entity-hero__kind { + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.52rem; + letter-spacing: 0.12rem; + text-transform: uppercase; +} + +/* ── Cockpit leads an aircraft's actions ─────────────────────────────── */ +#entity-card .entity-card__action--primary { + width: 100%; + height: 2.3rem; + color: #04131a; + font-size: 0.74rem; + font-weight: 600; + letter-spacing: 0.04rem; + background: #36dcff; + border-color: #36dcff; + box-shadow: 0 0 18px rgba(54, 220, 255, 0.28); +} + +#entity-card .entity-card__action--primary:hover, +#entity-card .entity-card__action--primary:focus-visible { + color: #04131a; + background: #7be8ff; + border-color: #7be8ff; +} + +/* Following is a state, not the main action: outlined, not filled. */ +#entity-card .entity-card__action--on { + background: transparent; +} + +/* ── Worldwide counts (globe view, nothing selected) ─────────────────── */ +.view-context__world { + margin: 0.6rem 0 0.75rem; +} + +.view-context__world h4 { + margin: 0 0 0.4rem; + color: rgba(199, 214, 222, 0.55); + font-family: var(--font-mono); + font-size: 0.56rem; + font-weight: 500; + letter-spacing: 0.14rem; + text-transform: uppercase; +} + +.view-context__world-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.35rem; +} + +.view-context__world-tile { + display: grid; + grid-template-columns: auto 1fr; + align-items: center; + gap: 0.05rem 0.5rem; + padding: 0.5rem 0.6rem; + color: inherit; + font: inherit; + text-align: start; + background: rgba(255, 255, 255, 0.04); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 8px; +} + +.view-context__world-tile .material-symbols-outlined { + grid-row: 1 / 3; + color: #36dcff; + font-size: 1.3rem; +} + +.view-context__world-tile strong { + color: rgba(240, 247, 250, 0.98); + font-family: var(--font-mono); + font-size: 1rem; + font-weight: 600; + line-height: 1.1; +} + +.view-context__world-tile span:last-child { + overflow: hidden; + color: rgba(199, 214, 222, 0.6); + font-size: 0.58rem; + letter-spacing: 0.04rem; + text-overflow: ellipsis; + text-transform: uppercase; + white-space: nowrap; +} + +.view-context__world-tile.is-off { + cursor: pointer; + border-style: dashed; +} + +.view-context__world-tile.is-off .material-symbols-outlined, +.view-context__world-tile.is-off strong { + color: rgba(199, 214, 222, 0.45); +} + +.view-context__world-tile.is-off:hover, +.view-context__world-tile.is-off:focus-visible { + background: rgba(54, 220, 255, 0.08); + border-color: rgba(54, 220, 255, 0.3); +} + +/* An aircraft's altitude as a filled graph, graded by height: bright at + the top, fading towards the baseline. */ +.altitude-graph { + margin: 0 0 0.7rem; + padding: 0.5rem 0.6rem 0.45rem; + border: 1px solid rgba(160, 200, 220, 0.14); + border-radius: 8px; + background: rgba(255, 255, 255, 0.025); +} + +.altitude-graph__head, +.altitude-graph__foot { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: 0.5rem; + margin: 0; +} + +.altitude-graph__label, +.altitude-graph__foot { + color: rgba(199, 214, 222, 0.6); + font-family: var(--font-mono); + font-size: 0.56rem; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.altitude-graph__now { + color: #eef6fa; + font-family: var(--font-mono); + font-size: 0.78rem; + font-weight: 600; +} + +.altitude-graph__plot { + position: relative; + height: 3.4rem; + margin: 0.35rem 0 0.3rem; + border-bottom: 1px solid rgba(160, 200, 220, 0.22); + background: repeating-linear-gradient( + to bottom, + rgba(160, 200, 220, 0.08) 0 1px, + transparent 1px 25% + ); +} + +.altitude-graph__plot svg { + display: block; + width: 100%; + height: 100%; +} + +.altitude-graph__stop--high { + stop-color: var(--accent); + stop-opacity: 0.75; +} + +.altitude-graph__stop--mid { + stop-color: var(--accent); + stop-opacity: 0.3; +} + +.altitude-graph__stop--low { + stop-color: var(--accent); + stop-opacity: 0.04; +} + +.altitude-graph__line { + fill: none; + stroke: var(--accent); + stroke-width: 1.5; + stroke-linejoin: round; + vector-effect: non-scaling-stroke; +} + +.altitude-graph__head-dot { + position: absolute; + right: -3px; + width: 7px; + height: 7px; + border-radius: 50%; + background: var(--accent); + box-shadow: 0 0 6px var(--accent); + transform: translateY(-50%); +} + +.altitude-graph__scale { + position: absolute; + top: 1px; + left: 2px; + color: rgba(199, 214, 222, 0.45); + font-family: var(--font-mono); + font-size: 0.5rem; +} + +.altitude-graph[data-trend='up'] .altitude-graph__change { + color: #7fe0a8; +} + +.altitude-graph[data-trend='down'] .altitude-graph__change { + color: #f0b46a; +} + +.altitude-graph__scale--low { + top: auto; + bottom: 1px; +} + +/* What a layer that is on is made of: under its row, a bar per split whose + segments are the parts, and a legend with each part's count. */ +.view-context__live-item { + background: rgba(255, 255, 255, 0.035); + border: 1px solid rgba(255, 255, 255, 0.06); +} + +.view-context__live-item > .view-context__live-row { + background: none; + border: 0; +} + +.view-context__split { + display: grid; + gap: 0.45rem; + padding: 0 0.55rem 0.55rem; +} + +.view-context__split-basis { + margin: 0; + color: rgba(199, 214, 222, 0.5); + font-family: var(--font-mono); + font-size: 0.54rem; + letter-spacing: 0.06em; + text-transform: uppercase; +} + +.view-context__split-bar { + display: flex; + gap: 2px; + height: 6px; + overflow: hidden; + border-radius: 3px; + background: rgba(255, 255, 255, 0.06); +} + +.view-context__split-bar i { + min-width: 2px; +} + +.view-context__split-legend { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 0.15rem 0.6rem; + margin: 0.3rem 0 0; + padding: 0; + list-style: none; +} + +.view-context__split-legend li { + display: flex; + align-items: center; + gap: 0.3rem; + min-width: 0; + color: rgba(199, 214, 222, 0.75); + font-size: 0.6rem; +} + +.view-context__split-legend i { + flex: none; + width: 6px; + height: 6px; + border-radius: 50%; +} + +.view-context__split-legend span { + flex: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.view-context__split-legend strong { + color: #eef6fa; + font-family: var(--font-mono); + font-weight: 600; +} + +/* The compact graph: caption, figure and a short line, nothing else. */ +.altitude-graph--compact { + padding-bottom: 0.5rem; +} + +.altitude-graph--compact .altitude-graph__plot { + height: 1.9rem; + margin-bottom: 0; + background: none; +} + +/* "Layers on" leads the view, under the place name. */ +.view-context__live { + margin: 0.6rem 0 0.7rem; +} diff --git a/src/ui/styles/spot-conditions.css b/src/ui/styles/spot-conditions.css new file mode 100644 index 000000000..a45f05bf3 --- /dev/null +++ b/src/ui/styles/spot-conditions.css @@ -0,0 +1,332 @@ +/* ── Conditions around a spot (entity card, In view) ────────────────────── */ +.spot-conditions { + display: grid; + gap: 0.6rem; + margin: 0.5rem 0 0.75rem; +} + +.spot-conditions__weather { + display: grid; + grid-template-columns: auto 1fr; + align-items: center; + gap: 0.3rem 0.65rem; + padding: 0.6rem 0.7rem; + background: linear-gradient(135deg, rgba(54, 220, 255, 0.09), rgba(255, 255, 255, 0.025)); + border: 1px solid rgba(54, 220, 255, 0.16); + border-radius: 10px; +} + +.spot-conditions__weather-icon { + color: #36dcff; + font-size: 2rem; +} + +.spot-conditions__weather-now { + display: grid; + gap: 0.1rem; +} + +.spot-conditions__weather-now strong { + color: rgba(240, 247, 250, 0.98); + font-family: var(--font-mono); + font-size: 1.35rem; + font-weight: 600; + line-height: 1; +} + +.spot-conditions__weather-now span { + color: rgba(199, 214, 222, 0.72); + font-size: 0.68rem; +} + +.spot-conditions__weather-facts { + display: grid; + grid-column: 1 / -1; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 0.3rem; + margin: 0.25rem 0 0; +} + +.spot-conditions__weather-facts div { + display: grid; + gap: 0.1rem; + min-width: 0; +} + +.spot-conditions__weather-facts dt { + color: rgba(199, 214, 222, 0.5); + font-size: 0.52rem; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.spot-conditions__weather-facts dd { + overflow: hidden; + margin: 0; + color: rgba(236, 244, 248, 0.92); + font-family: var(--font-mono); + font-size: 0.66rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.spot-conditions__loading, +.spot-conditions__none { + margin: 0; + color: rgba(199, 214, 222, 0.55); + font-size: 0.66rem; +} + +.spot-conditions__block h4 { + display: flex; + align-items: center; + gap: 0.4rem; + margin: 0 0 0.25rem; + color: rgba(199, 214, 222, 0.6); + font-size: 0.58rem; + font-weight: 500; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.spot-conditions__block h4 .material-symbols-outlined { + font-size: 0.95rem; +} + +.spot-conditions__count { + margin-inline-start: auto; + color: rgba(199, 214, 222, 0.6); + font-family: var(--font-mono); +} + +.spot-conditions__count--hot { + color: #ffb547; +} + +.spot-conditions__query { + overflow: hidden; + margin-inline-start: auto; + max-width: 50%; + color: rgba(199, 214, 222, 0.45); + text-overflow: ellipsis; + text-transform: none; + white-space: nowrap; +} + +.spot-conditions__block ul { + display: grid; + gap: 0.2rem; + margin: 0; + padding: 0; + list-style: none; +} + +.spot-conditions__block button, +.spot-conditions__block a { + display: flex; + align-items: center; + gap: 0.5rem; + width: 100%; + padding: 0.4rem 0.5rem; + color: inherit; + text-align: start; + text-decoration: none; + background: rgba(255, 255, 255, 0.035); + border: 1px solid rgba(255, 255, 255, 0.06); + border-left: 2px solid var(--hazard-tone, rgba(54, 220, 255, 0.5)); + border-radius: 7px; + cursor: pointer; +} + +.spot-conditions__block button:hover, +.spot-conditions__block a:hover, +.spot-conditions__block button:focus-visible, +.spot-conditions__block a:focus-visible { + background: rgba(54, 220, 255, 0.08); + border-color: rgba(54, 220, 255, 0.25); + border-left-color: var(--hazard-tone, #36dcff); +} + +.spot-conditions__block button > .material-symbols-outlined { + color: var(--hazard-tone, #36dcff); + font-size: 1.05rem; +} + +.spot-conditions__hazard--quake { --hazard-tone: #ffd166; } +.spot-conditions__hazard--storm { --hazard-tone: #c792ff; } +.spot-conditions__hazard--wildfire, +.spot-conditions__hazard--hotspots { --hazard-tone: #ff7a45; } +.spot-conditions__hazard--alert { --hazard-tone: #ff5c6c; } + +.spot-conditions__row-main { + display: grid; + flex: 1 1 auto; + gap: 0.08rem; + min-width: 0; +} + +.spot-conditions__row-title { + overflow: hidden; + color: rgba(236, 244, 248, 0.94); + font-size: 0.7rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.spot-conditions__row-title--wrap { + display: -webkit-box; + white-space: normal; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; +} + +.spot-conditions__row-detail { + overflow: hidden; + color: rgba(199, 214, 222, 0.55); + font-size: 0.6rem; + text-overflow: ellipsis; + white-space: nowrap; +} + +.spot-conditions__row-layer { + display: inline-flex; + align-items: center; + gap: 5px; + margin-top: 2px; + color: rgba(199, 214, 222, 0.5); + font-family: var(--font-mono); + font-size: 0.55rem; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +.spot-conditions__row-dot { + width: 6px; + height: 6px; + border: 1px solid rgba(199, 214, 222, 0.55); + border-radius: 50%; +} + +.spot-conditions__row-layer.is-on { + color: rgba(0, 212, 255, 0.85); +} + +.spot-conditions__row-layer.is-on .spot-conditions__row-dot { + background: #00d4ff; + border-color: #00d4ff; + box-shadow: 0 0 5px rgba(0, 212, 255, 0.7); +} + +.spot-conditions__row-meta { + flex: none; + color: rgba(199, 214, 222, 0.7); + font-family: var(--font-mono); + font-size: 0.6rem; +} + +.spot-conditions__source { + margin: 0; + color: rgba(199, 214, 222, 0.4); + font-size: 0.55rem; +} + +/* The hazard tone as an L along the left edge and the bottom-left corner, + in place of a solid left edge. */ +.spot-conditions__block button, +.spot-conditions__block a { + position: relative; + border-radius: 0; + border-left-width: 1px; + border-left-color: rgba(255, 255, 255, 0.06); +} + +.spot-conditions__block button::before, +.spot-conditions__block a::before { + content: ''; + position: absolute; + inset: -1px auto -1px -1px; + width: 9px; + border-radius: 0; + pointer-events: none; + --tone: var(--hazard-tone, rgba(54, 220, 255, 0.6)); + background: + linear-gradient(var(--tone), var(--tone)) left bottom / 9px 1.5px no-repeat, + linear-gradient(var(--tone), var(--tone)) left bottom / 1.5px 100% no-repeat; +} + +.spot-conditions__block button:hover, +.spot-conditions__block a:hover, +.spot-conditions__block button:focus-visible, +.spot-conditions__block a:focus-visible { + border-left-color: rgba(54, 220, 255, 0.25); +} + +/* A grey rule under each list: hazards, alerts, news. */ +.spot-conditions__block { + padding-bottom: 0.65rem; + border-bottom: 1px solid rgba(255, 255, 255, 0.08); +} + +/* Local time beside the weather on a selected item's card. */ +.spot-conditions__weather--timed { + grid-template-columns: auto 1fr auto; +} + +.spot-conditions__weather-wait { + grid-column: 1 / 3; +} + +.spot-conditions__time { + display: grid; + gap: 0.1rem; + justify-items: end; + grid-column: 3; +} + +.spot-conditions__time strong { + color: rgba(240, 247, 250, 0.98); + font-family: var(--font-mono); + font-size: 1.05rem; + font-weight: 600; + line-height: 1; +} + +.spot-conditions__time span { + color: rgba(199, 214, 222, 0.6); + font-size: 0.56rem; + letter-spacing: 0.05rem; + text-transform: uppercase; +} + +/* The one distance every nearby block looks out to. */ +.spot-conditions__radius { + display: grid; + grid-template-columns: auto 1fr auto; + align-items: center; + gap: 0.6rem; + padding: 0.4rem 0.6rem; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 8px; +} + +.spot-conditions__radius-label { + color: rgba(199, 214, 222, 0.6); + font-size: 0.58rem; + font-weight: 500; + letter-spacing: 0.06rem; + text-transform: uppercase; +} + +.spot-conditions__radius-slider { + width: 100%; + min-width: 0; +} + +.spot-conditions__radius-value { + min-width: 4.2rem; + color: #36dcff; + font-family: var(--font-mono); + font-size: 0.7rem; + text-align: end; +} diff --git a/src/ui/styles/sun-dial.css b/src/ui/styles/sun-dial.css new file mode 100644 index 000000000..fe2cc2ab7 --- /dev/null +++ b/src/ui/styles/sun-dial.css @@ -0,0 +1,110 @@ +/* ── Sundial (Context, nothing selected) ──────────────────────────────── */ +.sun-dial { + margin: 0.5rem 0 0.6rem; + padding: 0.35rem 0.3rem 0.45rem; + background: + radial-gradient(90% 70% at 50% 45%, rgba(54, 220, 255, 0.06), transparent 70%), + rgba(255, 255, 255, 0.025); + border: 1px solid rgba(255, 255, 255, 0.07); + border-radius: 8px; +} + +.sun-dial svg { + display: block; + width: 100%; + height: auto; +} + +.sun-dial__hours line { + stroke: rgba(54, 220, 255, 0.38); + stroke-width: 0.5; +} + +.sun-dial__hours line.major { + stroke: rgba(122, 240, 255, 0.7); + stroke-width: 0.8; +} + +.sun-dial__ticks line { + stroke: rgba(54, 220, 255, 0.3); + stroke-width: 0.4; +} + +.sun-dial__ticks line.major { + stroke: rgba(122, 240, 255, 0.65); + stroke-width: 0.7; +} + +.sun-dial__hours text, +.sun-dial__pole { + fill: rgba(196, 244, 255, 0.85); + font-family: var(--font-mono); + font-size: 7px; + font-weight: 500; + letter-spacing: 0.04em; + text-anchor: middle; +} + +.sun-dial__pole { + fill: #ff6b5e; + font-size: 8px; + font-weight: 700; +} + +.sun-dial figcaption { + margin-top: 0.2rem; + color: rgba(199, 214, 222, 0.62); + font-family: var(--font-mono); + font-size: 0.58rem; + letter-spacing: 0.05rem; + text-align: center; +} + +/* Night: the plate under starlight. */ +.sun-dial--night svg { + filter: saturate(0.4) brightness(0.6); +} + +/* Small compass beside the dial, in the same cyan instrument style. */ +.sun-dial__compass-ring { + fill: rgba(5, 14, 20, 0.85); + stroke: rgba(54, 220, 255, 0.5); + stroke-width: 0.8; +} + +.sun-dial__compass-inner { + fill: none; + stroke: rgba(54, 220, 255, 0.18); + stroke-width: 0.5; + stroke-dasharray: 1.5 2; +} + +.sun-dial__compass-tick { + stroke: rgba(122, 240, 255, 0.7); + stroke-width: 0.8; +} + +.sun-dial__compass-north { + fill: #ff6b5e; +} + +.sun-dial__compass-south { + fill: rgba(196, 244, 255, 0.55); +} + +.sun-dial__compass-sun { + fill: #ffd166; + filter: drop-shadow(0 0 2px rgba(255, 209, 102, 0.9)); +} + +.sun-dial__compass-label { + fill: rgba(196, 244, 255, 0.75); + font-family: var(--font-mono); + font-size: 6.5px; + text-anchor: middle; +} + +.sun-dial__compass-label.north { + fill: #ff6b5e; + font-weight: 700; +} diff --git a/src/ui/views/ContextView.vue b/src/ui/views/ContextView.vue index 1c0684002..980ba990e 100644 --- a/src/ui/views/ContextView.vue +++ b/src/ui/views/ContextView.vue @@ -1,5 +1,5 @@