Compare commits

...
Author SHA1 Message Date
German Khokhlov 664de45868 Play the opening 30% faster 2026-11-23 23:30:33 +04:00
German Khokhlov c4a846b8ad Keep the opening out of embeds, Street Level and moved cameras; fix review findings
- Embeds, inline panels, Street Level links and rejected share codes skip the opening.
- The opening yields to a camera move made between its frames and keeps the view's roll.
- A click skips it; the welcome waits for the cover to fade after a skip.
- The first HUD summary is not spent while the opening plays.
- Home countries follow tzdata backward links; the table is regenerated and checked.
- QA scripts open the cockpit and Street Level checks with intro=0.
2026-11-23 23:14:09 +04:00
German Khokhlov f4d936989b Turn the opening at planet size, then close in; keep its frames out of the address 2026-11-23 19:32:44 +04:00
German Khokhlov dd18c5ad11 Slow the opening's approach so the imagery keeps up 2026-11-23 18:37:20 +04:00
German Khokhlov 31ce6cbf79 A link to only a view opens with the opening too, stopping at that view
The app writes its view into the address, so a reload or a bookmark is a
share link and opened without the opening. A start-up share whose camera
landed and that follows or selects nothing now plays it as well, ending
where the link points; the share restore says when the share is of a thing.

The flight turns to the target's heading and pitch over its last part, so a
view at an angle is reached without a jump. A camera held in a target's
frame plays no opening.
2026-11-23 16:08:30 +04:00
German Khokhlov 9088c01d1a The opening's logo takes 900 ms to move to the centre 2026-11-23 15:59:13 +04:00
German Khokhlov 6785a12581 The words under the opening's logo fade in 150 ms, before it reaches the centre 2026-11-23 15:57:04 +04:00
German Khokhlov 72f3d0f4a7 The opening's app shows through the empty circle inside the eye's ring
The cover around the eye is now cut by the circle inside its ring, not by
its whole outline: the ring and the space around it stay shut, and the app
appears in the circle around the planet as the eye grows.
2026-11-23 15:56:19 +04:00
German Khokhlov e39fc96079 The opening's eye opens onto the app, and the globe matches its blue disc
The screen stays shut outside the eye once the logo is centred: a cover the
loading screen's colour, with the eye's outline cut out of it, grows with
the eye until it reaches past the screen's corners, so the app shows through
the eye as it flies at the viewer.

The blue disc in the pupil is the drawn planet: it stays with the continents
and grid instead of flying out with the eye, and the real globe starts the
size of that disc rather than of the smaller ring of continents inside it.
2026-11-23 15:42:17 +04:00
German Khokhlov b880cf42c0 Changelog: the opening turns the logo into the globe 2026-11-23 15:27:25 +04:00
German Khokhlov f5b2867752 The app opens with the logo turning into the globe over your country
When the world has loaded, the loading screen's words fade and the logo
glides to the centre. The eye's arcs fly at the viewer, the drawn planet in
the pupil gives way to the real globe drawn the same size behind it, and the
globe spins west to east, growing and slowing until it stops with the whole
planet in view over the visitor's country.

The country comes from the browser's time zone (or, for UTC, a language's
region), so nothing leaves the browser. scripts/build-home-countries.mjs
writes the zone and country table from tzdata's zone.tab and the Natural
Earth countries pack. The title's logo goes back to the same view.

A share link, a Stories link, reduced motion and ?intro=0 open as before. A
click, a key or the wheel skips to the end; any other camera move stops it.
The globe-in-view recovery waits while it plays, since the far start shows
the globe as a speck.
2026-11-23 15:26:41 +04:00
25 changed files with 2261 additions and 29 deletions

No files matched your search

+1
View File
@@ -428,6 +428,7 @@ The [Bhote Koshi event pack](public/events/bhote-koshi-2026/README.md), under `p
| **DataSF Analysis Neighborhoods** (41 SF neighborhood polygons) | `neighborhoods/` | **PDDL 1.0** (public domain) | ✅ (no restrictions) | "City & County of San Francisco — DataSF" (courtesy — not legally required) |
| **Natural Earth countries, states and provinces** (260 admin-0/map units + 4,587 admin-1 polygons) | `natural_earth/` | **Public domain** | ✅ (no restrictions) | "Made with Natural Earth" (courtesy credit — not legally required) |
| **Natural Earth disputed areas** (11 of the source's 99 features, hand-picked; [list](src/data/local_data/natural_earth/README.md#disputed-areas-disputed_areasjson)) | `natural_earth/` | **Public domain** | ✅ (no restrictions) | "Made with Natural Earth" (courtesy credit — not legally required) |
| **Home countries** (the opening's start view, 518 time zones → 247 country points) | `src/data/homeCountries.js` (built by `scripts/build-home-countries.mjs` from tzdata `zone.tab`, `tzdata.zi` and the Natural Earth countries pack) | **Public domain** (tzdata and Natural Earth) | ✅ (no restrictions) | "Made with Natural Earth" (courtesy credit — not legally required) |
| **Natural Earth populated places** (7,342 points: name, position, rank) | `natural_earth/` | **Public domain** | ✅ (no restrictions) | "Made with Natural Earth" (courtesy credit — not legally required) |
| **Wikidata cities** (31,827 settlements of 15,000 people or more: name, position, population, country) | `wikidata_cities/` | **CC0 1.0** (public domain dedication) | ✅ (no restrictions) | "City, town and village names from Wikidata (CC0)" (courtesy credit — not legally required) |
| **Wikidata places** (137,662 settlements of 1,000 to 14,999 people, none in the cities pack, in 732 tiles of 5°: name, position, population, country) | `wikidata_places/` | **CC0 1.0** (public domain dedication) | ✅ (no restrictions) | "City, town and village names from Wikidata (CC0)" (courtesy credit — not legally required) |
+9
View File
@@ -0,0 +1,9 @@
- The app opens with the loading screen's logo turning into the globe: the eye
flies at you and opens onto the app as it grows, and the planet in the pupil
becomes the real globe, which grows to the whole planet, turns and stops over
your country, taken from the browser's time zone. The title's logo goes back
to that view. A link to only a view plays it too, closing in on that view
after the turn; a link that follows or selects something or opens Street Level
photos, a link that cannot be opened, a Stories link, an embedded view,
reduced motion and `?intro=0` open as before. The address keeps out of the
flight, so a reload during it reopens on the view it ends at (gekh, #1909).
+18
View File
@@ -5311,6 +5311,24 @@ down | auth-failed` (plus the unchanged `missing-key`/`unsupported`) with
> clock goes live and the camera flies to the view the app started from (the
> host's `homeView`, else its `startView`, else the whole planet), letting go
> of whatever it follows as Reset Globe does (`returnToStart()`).
> On a bare address, the standalone app starts 23,000 km above the country of
> the browser's time zone, looking straight down. It falls back to a preferred
> language's region, then to the default start view. The lookup runs in the
> browser (`src/homeCountry.js` and `src/data/homeCountries.js`).
> Once the startup restore settles and at least one second has passed, the
> loading text fades and the logo glides to the centre. The eye grows past the
> screen edges as the drawn planet in its pupil gives way to the globe. The
> globe grows to whole-planet size and turns once west to east, stopping over
> the destination. For a closer or angled view, the camera then approaches or
> turns to match it (`src/app/openingIntro.js`).
> A bare address or a link that restores only a view plays the opening.
> Links that follow or select something or open Street Level photos skip it,
> as do failed, refused or superseded restores, a newer navigation, Stories
> links, embedded views, reduced motion and `?intro=0`.
> A press, click, key, touch or wheel event lands the opening immediately.
> Another camera move stops the opening where the camera stands. During the
> flight the address keeps the destination and globe-in-view recovery waits.
> Welcome appears once the opening ends and the loading cover has faded.
> - **Context, Cockpit, and Radio interaction contract:** explicit Contacts and
> Radio actions and successful Cockpit actions can reveal Context. Contacts
> uses the dedicated right-side chooser. Space Missions has its own rail
+118
View File
@@ -0,0 +1,118 @@
#!/usr/bin/env node
// Writes src/data/homeCountries.js: each time zone's country, and where the
// opening stops over that country.
//
// node scripts/build-home-countries.mjs [zone.tab] [tzdata.zi]
//
// Zones come from tzdata's zone.tab (macOS and most Linux systems ship it and
// tzdata.zi at /usr/share/zoneinfo), with the names ICU gives them
// (Asia/Calcutta for Asia/Kolkata) and the older names tzdata.zi links to
// them (Asia/Choibalsan): a browser may give any of them. A country's point
// lies inside its largest part in the Natural Earth countries pack (the
// contiguous United States, mainland France), or is its first zone's place
// where the pack has no such country.
import { readFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import {
countryAnchor,
countryByCode,
} from '../server/providers/news/areas.js';
const root = new URL('../', import.meta.url);
const zoneTab = process.argv[2] ?? '/usr/share/zoneinfo/zone.tab';
const zoneLinks = process.argv[3] ?? '/usr/share/zoneinfo/tzdata.zi';
const out = new URL('src/data/homeCountries.js', root);
const COUNTRY = /^[A-Z]{2}$/;
const ZONE = /^[A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)*$/;
const round = (value) => Math.round(value * 10) / 10;
/** ISO 6709 `±DDMM[SS]±DDDMM[SS]` → [lat, lon]. */
function iso6709(text) {
const [, lat, lon] =
text.match(
/^([+-]\d{2}[0-5]\d(?:[0-5]\d)?)([+-]\d{3}[0-5]\d(?:[0-5]\d)?)$/,
) ?? [];
if (!lat) throw new Error(`zone.tab: bad place ${text}`);
const part = (s, degreeDigits) => {
const sign = s[0] === '-' ? -1 : 1;
const d = s.slice(1);
const deg = Number(d.slice(0, degreeDigits));
const min = Number(d.slice(degreeDigits, degreeDigits + 2));
const sec = Number(d.slice(degreeDigits + 2) || 0);
return sign * (deg + min / 60 + sec / 3600);
};
const place = [part(lat, 2), part(lon, 3)];
if (Math.abs(place[0]) > 90 || Math.abs(place[1]) > 180)
throw new Error(`zone.tab: place out of range ${text}`);
return place;
}
const zones = new Map();
const centres = new Map();
const icuName = (zone) => {
try {
return new Intl.DateTimeFormat('en', { timeZone: zone }).resolvedOptions()
.timeZone;
} catch {
return null;
}
};
for (const line of readFileSync(zoneTab, 'utf8').split('\n')) {
if (!line || line.startsWith('#')) continue;
const [country, place, zone] = line.split('\t');
if (!COUNTRY.test(country) || !zone || !ZONE.test(zone))
throw new Error(`zone.tab: bad line ${JSON.stringify(line)}`);
const coordinates = iso6709(place);
zones.set(zone, country);
const icu = icuName(zone);
if (icu && icu !== zone && !zones.has(icu)) zones.set(icu, country);
if (centres.has(country)) continue;
const entry = countryByCode(country);
const point = entry ? countryAnchor(entry) : null;
centres.set(
country,
point ? [round(point.lat), round(point.lon)] : coordinates.map(round),
);
}
// Older Area/Place names (Asia/Choibalsan, Europe/Uzhgorod), from tzdata.zi's
// `L <zone> <older name>` links, each with the country of the zone ICU reads
// it as: a link can lead to another country's zone with the same clocks
// (Africa/Timbuktu to Abidjan). Bare names (CET, Japan) are left out: some
// are clocks several countries keep.
for (const line of readFileSync(zoneLinks, 'utf8').split('\n')) {
const [kind, , name] = line.split(' ');
if (kind !== 'L') continue;
if (!name || !ZONE.test(name)) throw new Error(`tzdata.zi: bad link ${line}`);
if (!name.includes('/') || zones.has(name)) continue;
const country = zones.get(icuName(name));
if (!country) continue;
zones.set(name, country);
}
const sortedEntries = (map) =>
[...map].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
const lines = [
'// Generated by scripts/build-home-countries.mjs. Do not edit by hand.',
'// Sources: tzdata zone.tab and tzdata.zi (public domain) and the Natural',
'// Earth countries pack in src/data/local_data/natural_earth (public domain).',
'',
"/** ISO 3166 country → [lat, lon]: in its largest part, else its first zone's place. */",
'export const COUNTRY_CENTRES = {',
...sortedEntries(centres).map(
([country, [lat, lon]]) => ` ${country}: [${lat}, ${lon}],`,
),
'};',
'',
'/** Time zone (tzdata, ICU and older names) → ISO 3166 country. */',
'export const ZONE_COUNTRIES = {',
...sortedEntries(zones).map(
([zone, country]) => ` '${zone}': '${country}',`,
),
'};',
'',
];
writeFileSync(out, lines.join('\n'));
console.log(
`${fileURLToPath(out)}: ${centres.size} countries, ${zones.size} zones`,
);
+1
View File
@@ -4303,6 +4303,7 @@
"src/render/contract/index.js",
"src/sources/sourceSlot.js",
"src/app/sources.js",
"src/app/openingIntro.js",
"src/app/startupChrome.js",
"src/app/stateChannel.js",
"src/app/surfaceServices.js",
+2 -1
View File
@@ -396,7 +396,8 @@ async function runArbitrationSection(page, { shots, consoleErrors }) {
observer.observe(document, { childList: true, subtree: true });
});
try {
await page.goto(`${APP_URL}/?welcome=1`, { waitUntil: 'domcontentloaded' });
// Disable the opening so only the cockpit holds the launcher back.
await page.goto(`${APP_URL}/?welcome=1&intro=0`, { waitUntil: 'domcontentloaded' });
} finally {
await page.removeScriptToEvaluateOnNewDocument(earlyCockpitBlocker.identifier);
}
+5 -2
View File
@@ -225,9 +225,12 @@ function newFixture(overrides = {}) {
};
}
/** Load the app and dismiss the first-run dialog. */
/** Load without the opening so its flight cannot move the camera during
* the gate's own moves, then dismiss the first-run dialog. */
async function boot(page, url) {
await page.goto(url, { waitUntil: 'domcontentloaded' });
const address = new URL(url);
address.searchParams.set('intro', '0');
await page.goto(address.href, { waitUntil: 'domcontentloaded' });
await page.waitForFunction(() => Boolean(window.__godsEyeView?.dataManager), {
timeout: 150_000,
});
+410
View File
@@ -0,0 +1,410 @@
import { START_VIEW } from '../camera.js';
import { normalizeCameraLongitude } from '../director/camera.js';
import { findCamera } from '../render/rendererOf.js';
import { isEmbedded } from './embed.js';
/**
* The opening: once the world has loaded, the loading screen's logo turns
* into the globe, which grows to the whole planet's size, turns there to a
* stop over the view it ends at and only then closes in on a closer one.
* Everything is timed from one clock, in ms.
*/
export const OPENING = Object.freeze({
/** The words under the logo fade. */
textMs: 105,
/** The logo moves to the centre. */
centreMs: 630,
// The rest is timed from the end of the move.
/** The eye grows past the screen's edges. */
eyeMs: 770,
/** The drawn planet fades into the real one. */
pupilMs: Object.freeze([420, 840]),
/** The camera's flight starts. */
flightStartMs: 210,
/** The globe grows to the whole planet's size. */
zoomMs: 1120,
/** It turns there, slowing to a stop over the view it ends at: the turn
* starts halfway through the zoom and ends this long after it. */
spinMs: 1820,
/** Then the camera closes in on a closer view (a shared one), per tenfold
* change of height, within `approachMs`. */
approachPerDecadeMs: 770,
approachMs: Object.freeze([840, 2800]),
/** How far the globe turns, degrees. */
spinDeg: 360,
});
const EARTH_RADIUS_M = 6371000;
// public/logo.svg geometry, in its viewBox units.
const EYE_CENTRE = Object.freeze({ x: 568.8, y: 379 });
const EYE_WIDTH = 726.3;
/** The empty circle inside the eye's ring, the app's window. */
const WINDOW = Object.freeze({ x: 567, y: 382, r: 226 });
/** How far past the screen's corners the window opens. */
const WINDOW_COVER_MARGIN = 1.15;
/** Never start further out than this, metres. */
const MAX_FAR_HEIGHT_M = 4e8;
/** The whole planet in view. */
const PLANET_HEIGHT_M = START_VIEW.height;
/** Openings in progress on this page. */
let playing = 0;
/**
* Whether an opening is playing: the far start shows the globe as a speck,
* which the globe-in-view recovery would otherwise turn the camera back to.
*/
export function openingPlaying() {
return playing > 0;
}
const clamp01 = (x) => Math.min(1, Math.max(0, x));
const easeInCubic = (x) => x ** 3;
const easeOutCubic = (x) => 1 - (1 - x) ** 3;
const easeInOutCubic = (x) =>
x < 0.5 ? 4 * x ** 3 : 1 - (-2 * x + 2) ** 3 / 2;
const smoothstep = (x) => x * x * (3 - 2 * x);
const span = (t, [from, to]) => clamp01((t - from) / (to - from));
/** An angle, radians, the short way round. */
const shortWay = (angle) =>
angle - 2 * Math.PI * Math.round(angle / (2 * Math.PI));
/** Where each part of the opening stands `t` ms after it starts. */
export function openingStage(t) {
const move = clamp01(t / OPENING.centreMs);
const after = t - OPENING.centreMs;
const eye = clamp01(after / OPENING.eyeMs);
return {
/** The words' opacity. */
text: 1 - clamp01(t / OPENING.textMs),
/** How far the logo has moved to the centre, 0–1. */
centre: easeInOutCubic(move),
/** Whether the screen is shut except inside the eye. */
shut: move >= 1,
/** How far the eye has grown towards covering the screen, 0–1. */
eyeGrowth: easeInCubic(eye),
/** The eye's own opacity, and that of the shutter around it. */
eyeOpacity: 1 - span(eye, [0.6, 1]),
shutterOpacity: 1 - span(eye, [0.85, 1]),
pupilOpacity: 1 - span(after, OPENING.pupilMs),
};
}
/**
* The camera's flight in, from `farHeight` over the equator, looking straight
* down. The globe first grows to the whole planet's size (or `target`'s
* height when that is further out), turns `spinDeg` west to east there,
* slowing to a stop over `target`, and only then closes in on a closer
* `target`, turning to its heading, pitch and roll (radians) on the way.
* With nothing to close in on, it grows to `target`'s height.
* Returns `{ ms, pose(at) }`: its length, and its pose `at` ms into it.
*/
export function openingFlight({ target, farHeight }) {
const headingTo = shortWay(target.heading ?? 0);
const rollTo = shortWay(target.roll ?? 0);
const pitchTo = target.pitch ?? -Math.PI / 2;
const turns =
Math.abs(headingTo) > 1e-3 ||
Math.abs(rollTo) > 1e-3 ||
Math.abs(pitchTo + Math.PI / 2) > 1e-3;
const above = Math.max(PLANET_HEIGHT_M, target.height);
const decades = Math.log10(above / target.height);
const [shortest, longest] = OPENING.approachMs;
const approachMs =
decades > 0.05 || turns
? Math.min(
longest,
Math.max(shortest, decades * OPENING.approachPerDecadeMs),
)
: 0;
const planet = approachMs ? above : target.height;
const ms = OPENING.zoomMs + OPENING.spinMs + approachMs;
const logLerp = (from, to, k) =>
Math.exp(Math.log(from) + (Math.log(to) - Math.log(from)) * k);
// The turn starts halfway through the zoom, as the drawn planet fades out.
const spinFrom = OPENING.zoomMs / 2;
const spinLength = OPENING.zoomMs + OPENING.spinMs - spinFrom;
return {
ms,
pose(at) {
const t = Math.min(Math.max(at, 0), ms);
const zoom = smoothstep(clamp01(t / OPENING.zoomMs));
const spin = easeOutCubic(clamp01((t - spinFrom) / spinLength));
const approach = approachMs
? clamp01((t - OPENING.zoomMs - OPENING.spinMs) / approachMs)
: 0;
const turning = easeInOutCubic(approach);
return {
lon: normalizeCameraLongitude(
target.lon + OPENING.spinDeg * (1 - spin),
),
lat: target.lat * spin,
height:
approach > 0
? logLerp(planet, target.height, smoothstep(approach))
: logLerp(farHeight, planet, zoom),
heading: headingTo * turning,
pitch: -Math.PI / 2 + (pitchTo + Math.PI / 2) * turning,
roll: rollTo * turning,
};
},
};
}
/**
* The globe's radius on screen, pixels, from `height` metres straight above
* it, through a lens of vertical angle `fovy` on a view `viewportHeight`
* pixels tall.
*/
export function globeRadiusPx(height, { fovy, viewportHeight }) {
const angle = Math.asin(EARTH_RADIUS_M / (EARTH_RADIUS_M + height));
return (Math.tan(angle) / Math.tan(fovy / 2)) * (viewportHeight / 2);
}
/** The height at which the globe's radius on screen is `radiusPx`. */
export function heightForGlobeRadius(radiusPx, { fovy, viewportHeight }) {
const tangent = (radiusPx * Math.tan(fovy / 2)) / (viewportHeight / 2);
return EARTH_RADIUS_M / Math.sin(Math.atan(tangent)) - EARTH_RADIUS_M;
}
/**
* How much the eye must grow, about its centre at the centre of `view`, for
* its window (the empty circle inside its ring, `windowRadius` pixels) to
* reach past the view's corners.
*/
function eyeCoverScale(windowRadius, view) {
return (
(WINDOW_COVER_MARGIN * Math.hypot(view.width, view.height)) /
2 /
windowRadius
);
}
/**
* The cover around the eye's window: a shape the loading screen's colour, as
* large as any screen, with the empty circle inside the eye's ring cut out of
* it. It sits under the logo's parts and grows with the eye, so the screen is
* shut but for that circle.
*/
function eyeShutter(eye) {
const far = 1e5;
// Centred where the eye grows from, so the two grow as one.
const { x, y } = EYE_CENTRE;
const { x: cx, y: cy, r } = WINDOW;
const shutter = eye.ownerDocument.createElementNS(
'http://www.w3.org/2000/svg',
'path',
);
shutter.setAttribute(
'd',
`M${x - far},${y - far}H${x + far}V${y + far}H${x - far}Z` +
`M${cx - r},${cy}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0Z`,
);
shutter.style.fill = 'var(--bg-dark)';
shutter.setAttribute('fill-rule', 'evenodd');
shutter.dataset.openingShutter = '';
eye.parentNode.insertBefore(shutter, eye.parentNode.firstElementChild);
return shutter;
}
/**
* Whether the page opens with the opening: not where motion is reduced, not
* in an embedded view (its host drives the camera, and an inline panel's host
* may stop animation frames), not on a Stories link (Stories opens its own
* view) and not with `?intro=0`.
*/
export function openingWanted(win = globalThis.window) {
if (!win) return false;
if (win.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
return false;
if (isEmbedded(win.location)) return false;
const params = new URLSearchParams(win.location?.search ?? '');
return !(
params.get('intro') === '0' ||
params.has('story') ||
params.has('stories')
);
}
/**
* Play the opening over `loadingScreen`, ending where the camera stands (the
* start view, or the view a link opened). Returns null when it does not
* play: without the logo's own parts (an <img> logo opens as with reduced
* motion), or for a camera at or below the ellipsoid. Else `done`, which
* settles when the camera has stopped, and `cancel()`. A press, a click, a
* key, a touch or the wheel skips to the end; any other camera move stops it
* where it is. The loading screen is `hidden` once the real globe shows, or
* at once on a cancel.
* @param {{viewer: object, loadingScreen: HTMLElement, win?: Window,
* camera?: object}} options `camera` is the viewer's camera port unless given.
*/
export function playOpeningIntro({
viewer,
loadingScreen,
win = globalThis.window,
camera = null,
}) {
if (!openingWanted(win)) return null;
camera ??= findCamera(viewer);
if (!camera) return null;
const target = camera.pose();
if (
!Number.isFinite(target.height) ||
target.height <= 0 ||
!Number.isFinite(target.lon) ||
!Number.isFinite(target.lat)
)
return null;
const doc = loadingScreen.ownerDocument;
const logo = loadingScreen.querySelector('.loader-logo');
const svg = logo?.querySelector('svg');
const eye = svg?.querySelector('#outer_eye');
// The drawn planet: its blue disc, continents and grid.
const disc = svg?.querySelector('#inner_eye');
if (!eye || !disc) return null;
const pupil = [
disc,
svg.querySelector('#globe'),
svg.querySelector('#globe_cage'),
].filter(Boolean);
// Each part fades from its own opacity: the grid is translucent.
const ownOpacity = pupil.map((element) => {
const opacity = Number.parseFloat(win.getComputedStyle(element).opacity);
return Number.isFinite(opacity) ? opacity : 1;
});
const shutter = eyeShutter(eye);
loadingScreen.classList.add('opening');
playing += 1;
// Cancel the logo gaze's offset (src/logoGaze.js): the pupil starts centred.
for (const element of pupil) element.style.transform = 'none';
const pupilRect = disc.getBoundingClientRect();
const eyeRect = eye.getBoundingClientRect();
const view = (
doc.getElementById('cesiumContainer') ?? doc.documentElement
).getBoundingClientRect();
const viewportHeight = view.height || win.innerHeight;
const lens = { fovy: target.fovy, viewportHeight };
const pupilRadius = pupilRect.width / 2;
const farHeight = Math.min(
MAX_FAR_HEIGHT_M,
Math.max(target.height * 2, heightForGlobeRadius(pupilRadius, lens)),
);
const toCentre = {
x: view.left + view.width / 2 - (pupilRect.left + pupilRect.width / 2),
y: view.top + view.height / 2 - (pupilRect.top + pupilRect.height / 2),
};
const startRadius = globeRadiusPx(farHeight, lens);
// Where the far start is capped (a wide screen), the globe there is larger
// than the drawn planet: the logo grows to it on its way to the centre,
// under the cover, and matches it from then on.
const discScale = pupilRadius > 0 ? startRadius / pupilRadius : 1;
const eyeCover = eyeRect.width
? eyeCoverScale((eyeRect.width * WINDOW.r) / EYE_WIDTH, {
width: view.width || win.innerWidth,
height: viewportHeight,
})
: 1;
let driving = false;
/** The camera as the opening last left it. */
let placed = null;
const place = ({ lon, lat, height, heading, pitch, roll = 0 }) => {
driving = true;
try {
camera.setView({
destination: { lon, lat, height },
orientation: { heading, pitch, roll },
});
} finally {
driving = false;
}
placed = camera.pose();
};
// A move made on the renderer's own camera sends no command.
const movedElsewhere = () => {
const now = camera.pose();
return (
Math.abs(now.lat - placed.lat) > 1e-6 ||
Math.abs(normalizeCameraLongitude(now.lon - placed.lon)) > 1e-6 ||
Math.abs(now.height - placed.height) > 1
);
};
let resolveDone;
const done = new Promise((resolve) => {
resolveDone = resolve;
});
let frame = 0;
let finished = false;
const hide = () => loadingScreen.classList.add('hidden');
const stopCommands = camera.onCommand(() => {
if (!driving) finish();
});
const inputs = ['pointerdown', 'click', 'wheel', 'keydown', 'touchstart'];
const onInput = () => finish({ land: true });
for (const type of inputs)
win.addEventListener(type, onInput, { capture: true, passive: true });
function finish({ land = false } = {}) {
if (finished) return;
finished = true;
playing -= 1;
try {
if (frame) win.cancelAnimationFrame(frame);
stopCommands();
for (const type of inputs)
win.removeEventListener(type, onInput, { capture: true });
if (land) place(target);
} finally {
hide();
resolveDone();
}
}
const flight = openingFlight({ target, farHeight });
const start = win.performance.now();
const step = () => {
frame = 0;
if (finished) return;
try {
if (placed && movedElsewhere()) {
finish();
return;
}
const t = win.performance.now() - start;
const flown = t - OPENING.centreMs - OPENING.flightStartMs;
if (flown >= flight.ms) {
finish({ land: true });
return;
}
const stage = openingStage(t);
const pose = flight.pose(flown);
place(pose);
const scale =
(globeRadiusPx(pose.height, lens) / startRadius) *
(1 + (discScale - 1) * stage.centre);
loadingScreen.style.setProperty('--opening-text', stage.text);
// Once the logo is centred, the shutter around the eye is the cover.
loadingScreen.style.setProperty('--opening-veil', stage.shut ? 0 : 1);
logo.style.transform = `translate(${toCentre.x * stage.centre}px, ${
toCentre.y * stage.centre
}px) scale(${scale})`;
const eyeScale = `scale(${1 + (eyeCover - 1) * stage.eyeGrowth})`;
eye.style.transform = eyeScale;
eye.style.opacity = stage.eyeOpacity;
shutter.style.transform = eyeScale;
shutter.style.opacity = stage.shutterOpacity;
pupil.forEach((element, i) => {
element.style.opacity = ownOpacity[i] * stage.pupilOpacity;
});
if (stage.pupilOpacity === 0) hide();
frame = win.requestAnimationFrame(step);
} catch (error) {
finish();
throw error;
}
};
step();
return { done, cancel: () => finish() };
}
+396
View File
@@ -0,0 +1,396 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { Window } from 'happy-dom';
import {
OPENING,
globeRadiusPx,
heightForGlobeRadius,
openingFlight,
openingPlaying,
openingStage,
openingWanted,
playOpeningIntro,
} from './openingIntro.js';
const LENS = { fovy: Math.PI / 4, viewportHeight: 800 };
const TARGET = { lon: 10.4, lat: 51.1, height: 23e6, heading: 0, pitch: -1 };
const LANDED = { lon: TARGET.lon, lat: TARGET.lat, height: TARGET.height };
const PLANET_FLIGHT_MS = OPENING.zoomMs + OPENING.spinMs;
test('the words fade, then the eye opens past the screen before the globe arrives', () => {
const start = openingStage(0);
assert.equal(start.text, 1);
assert.equal(start.shut, false);
assert.equal(start.pupilOpacity, 1);
assert.equal(openingStage(OPENING.textMs).text, 0, 'the words go first');
assert.ok(openingStage(OPENING.textMs).centre < 0.5);
const centred = openingStage(OPENING.centreMs);
assert.equal(centred.text, 0);
assert.equal(centred.centre, 1);
assert.equal(centred.shut, true, 'shut but for the eye');
assert.equal(centred.eyeGrowth, 0);
const half = openingStage(OPENING.centreMs + OPENING.eyeMs / 2);
assert.ok(half.eyeGrowth > 0 && half.eyeGrowth < 0.5, 'it speeds up');
assert.equal(half.pupilOpacity, 1, 'the planet stays in the pupil');
const open = openingStage(OPENING.centreMs + OPENING.eyeMs);
assert.equal(open.eyeGrowth, 1);
assert.equal(open.eyeOpacity, 0);
assert.equal(open.shutterOpacity, 0);
const real = openingStage(OPENING.centreMs + OPENING.pupilMs[1]);
assert.equal(real.pupilOpacity, 0);
});
const FAR = 4e8;
const PLANET = { lon: 10.4, lat: 51.1, height: 23e6 };
const unwrap = (lon, near) => lon + 360 * Math.round((near - lon) / 360);
test('the globe grows to the planet first, then turns there to a stop', () => {
const flight = openingFlight({ target: PLANET, farHeight: FAR });
assert.equal(flight.ms, PLANET_FLIGHT_MS, 'nothing to close in on');
const start = flight.pose(0);
assert.ok(Math.abs(start.height - FAR) < 1);
assert.equal(start.lat, 0);
assert.ok(
Math.abs(flight.pose(OPENING.zoomMs).height - PLANET.height) < 1,
'the whole planet first',
);
// Unwrapped longitude falls all the way (the camera moves west, so the
// surface turns east), from halfway through the zoom, slowing to a stop.
const spinFrom = OPENING.zoomMs / 2;
let previous = PLANET.lon + OPENING.spinDeg;
let previousStep = Infinity;
for (let i = 0; i <= 100; i++) {
const at = spinFrom + ((flight.ms - spinFrom) * i) / 100;
const pose = flight.pose(at);
if (at >= OPENING.zoomMs)
assert.ok(Math.abs(pose.height - PLANET.height) < 1, 'turns at size');
assert.ok(pose.lon >= -180 && pose.lon < 180);
const lon = unwrap(pose.lon, previous);
const step = previous - lon;
assert.ok(step >= -1e-9, 'west to east');
if (i > 1) assert.ok(step <= previousStep + 1e-9, 'the turn slows');
previous = lon;
previousStep = step;
}
assert.ok(Math.abs(previous - PLANET.lon) < 1e-9, 'one whole turn');
const end = flight.pose(flight.ms);
assert.ok(Math.abs(end.lon - PLANET.lon) < 1e-9);
assert.ok(Math.abs(end.lat - PLANET.lat) < 1e-9);
assert.equal(end.pitch, -Math.PI / 2);
});
test('a closer view at an angle is closed in on after the turn', () => {
const angled = {
lon: 2.35,
lat: 48.86,
height: 5000,
heading: 5.5,
pitch: -0.5,
};
const flight = openingFlight({ target: angled, farHeight: FAR });
assert.ok(flight.ms > PLANET_FLIGHT_MS);
assert.ok(flight.ms <= PLANET_FLIGHT_MS + OPENING.approachMs[1]);
const turned = flight.pose(PLANET_FLIGHT_MS);
assert.ok(Math.abs(turned.height - 23e6) < 1, 'over the whole planet');
assert.ok(Math.abs(turned.lon - angled.lon) < 1e-9);
assert.ok(Math.abs(turned.lat - angled.lat) < 1e-9);
assert.ok(Math.abs(turned.heading) < 1e-12);
assert.equal(turned.pitch, -Math.PI / 2, 'straight down until then');
const end = flight.pose(flight.ms);
// 5.5 rad turns the short way round: -0.78 rad.
assert.ok(Math.abs(end.heading - (5.5 - 2 * Math.PI)) < 1e-9);
assert.ok(Math.abs(end.pitch - angled.pitch) < 1e-9);
assert.ok(Math.abs(end.height - angled.height) < 1e-6);
assert.ok(Math.abs(end.lon - angled.lon) < 1e-9);
});
test('a view further out than the planet turns at that height', () => {
const far = { lon: -97.74, lat: 0, height: 2.8e8 };
const flight = openingFlight({ target: far, farHeight: FAR });
assert.equal(flight.ms, PLANET_FLIGHT_MS);
assert.ok(Math.abs(flight.pose(OPENING.zoomMs).height - far.height) < 1);
assert.ok(Math.abs(flight.pose(flight.ms).height - far.height) < 1);
});
test('the far start draws the globe the size of the pupil', () => {
for (const radius of [12, 20, 64]) {
const height = heightForGlobeRadius(radius, LENS);
assert.ok(Math.abs(globeRadiusPx(height, LENS) - radius) < 1e-6);
}
assert.ok(globeRadiusPx(4e8, LENS) < globeRadiusPx(23e6, LENS));
});
test('reduced motion, embedded views, Stories links and ?intro=0 open without it', () => {
const win = (search, reduced = false) => ({
location: { search },
matchMedia: () => ({ matches: reduced }),
});
assert.equal(openingWanted(win('')), true);
assert.equal(openingWanted(win('', true)), false);
assert.equal(openingWanted(win('?intro=0')), false);
assert.equal(openingWanted(win('?story=abc')), false);
assert.equal(openingWanted(win('?stories')), false);
assert.equal(openingWanted(win('?intro=1')), true);
assert.equal(openingWanted(win('?embed=1')), false);
globalThis.GEV_EMBED_INLINE = true;
try {
assert.equal(openingWanted(win('')), false);
} finally {
delete globalThis.GEV_EMBED_INLINE;
}
});
// A loading screen and a camera port; the test runs the frames by hand.
function stage({
target = TARGET,
width = 1280,
height = 800,
fovy = Math.PI / 4,
disc = null,
} = {}) {
const window = new Window({ width, height });
const doc = window.document;
doc.body.innerHTML = `
<style>.cls-4 { opacity: 0.63; }</style>
<div id="cesiumContainer"></div>
<div id="loading-screen"><span class="loader-logo"><svg>
<path id="outer_eye" d="M0,10C0,0,20,0,20,10C20,20,0,20,0,10ZM5,10h1"/>
<path id="inner_eye"/>
<path id="globe"/><path id="globe_cage" class="cls-4"/>
</svg></span></div>`;
const screen = doc.getElementById('loading-screen');
doc.getElementById('cesiumContainer').getBoundingClientRect = () => ({
left: 0,
top: 0,
width,
height,
});
if (disc) {
doc.getElementById('inner_eye').getBoundingClientRect = () => ({
left: (width - disc) / 2,
top: (height - disc) / 2,
width: disc,
height: disc,
});
}
let now = 0;
let frames = [];
window.performance.now = () => now;
window.requestAnimationFrame = (fn) => frames.push(fn);
window.cancelAnimationFrame = () => {
frames = [];
};
window.matchMedia = () => ({ matches: false });
const views = [];
const commandListeners = new Set();
let current = { ...target, fovy };
const camera = {
pose: () => ({ ...current }),
rawMove(pose) {
current = { ...pose, fovy };
},
setView(spec) {
views.push(spec);
current = { ...spec.destination, ...spec.orientation, fovy };
for (const cb of commandListeners) cb({ kind: 'setView' });
},
onCommand(cb) {
commandListeners.add(cb);
return () => commandListeners.delete(cb);
},
};
return {
window,
screen,
views,
camera,
commandListeners,
doc,
current: () => current,
play: () =>
playOpeningIntro({
viewer: {},
loadingScreen: screen,
win: window,
camera,
}),
advance(ms) {
now += ms;
const run = frames;
frames = [];
for (const fn of run) fn();
},
advanceTo(ms, stepMs = 1000 / 60) {
while (now < ms) this.advance(Math.min(stepMs, ms - now));
},
otherMove: () => {
for (const cb of [...commandListeners]) cb({ kind: 'flyTo' });
},
};
}
test('the opening runs to the start view, then hides the cover', async () => {
const s = stage();
const opening = s.play();
assert.ok(opening);
assert.equal(openingPlaying(), true);
assert.ok(s.screen.classList.contains('opening'));
assert.ok(s.views[0].destination.height > TARGET.height * 2, 'far start');
const shutter = s.screen.querySelector('[data-opening-shutter]');
assert.ok(shutter, 'the cover around the eye');
assert.match(
shutter.getAttribute('d'),
/ZM341,382a226,226 0 1,0 452,0a226,226 0 1,0 -452,0Z$/,
'the empty circle inside the ring',
);
assert.equal(shutter.getAttribute('fill-rule'), 'evenodd');
s.advance(OPENING.centreMs);
assert.equal(s.screen.style.getPropertyValue('--opening-veil'), '0');
s.advance(Math.max(OPENING.eyeMs, OPENING.pupilMs[1]));
assert.ok(s.screen.classList.contains('hidden'));
s.advance(10000);
await opening.done;
const last = s.views.at(-1);
assert.deepEqual(last.destination, LANDED);
assert.equal(last.orientation.heading, TARGET.heading);
assert.equal(last.orientation.pitch, TARGET.pitch);
assert.equal(openingPlaying(), false);
assert.equal(s.commandListeners.size, 0);
});
test("the person's input skips to the start view", async () => {
const s = stage();
const opening = s.play();
s.advance(2000);
s.window.dispatchEvent(new s.window.Event('keydown'));
await opening.done;
assert.deepEqual(s.views.at(-1).destination, LANDED);
assert.ok(s.screen.classList.contains('hidden'));
assert.equal(openingPlaying(), false);
});
test('another camera move stops it where it is', async () => {
const s = stage();
const opening = s.play();
s.advance(2000);
const count = s.views.length;
s.otherMove();
await opening.done;
s.advance(1000);
assert.equal(s.views.length, count, 'no more frames');
assert.ok(s.screen.classList.contains('hidden'));
});
const HOME = { ...TARGET, pitch: -Math.PI / 2, roll: 0 };
const CLOSE = {
lon: 2.3522,
lat: 48.8566,
height: 5000,
heading: 0,
pitch: -0.61,
roll: Math.PI / 6,
};
test("a move made on the renderer's own camera stops it there", async () => {
const s = stage({ target: HOME });
const opening = s.play();
s.advance(2000);
const park = { ...HOME, lon: -121.49, lat: 38.5816, height: 900 };
s.camera.rawMove(park);
s.advance(16);
assert.equal(s.current().lat, park.lat);
s.advanceTo(15000);
await opening.done;
assert.equal(s.current().lat, park.lat);
});
test('a shared roll survives the landing and a skip', async () => {
for (const skip of [false, true]) {
const s = stage({ target: CLOSE });
const opening = s.play();
if (skip) {
s.advance(2000);
s.window.dispatchEvent(new s.window.Event('keydown'));
} else {
s.advanceTo(15000);
}
await opening.done;
assert.ok(Math.abs(s.views.at(-1).orientation.roll - CLOSE.roll) < 1e-9);
}
});
test('a view at or below the ellipsoid plays no opening', () => {
for (const height of [-100, 0]) {
const s = stage({ target: { ...CLOSE, lon: 35.5, lat: 31.5, height } });
assert.equal(s.play(), null);
assert.equal(s.views.length, 0);
assert.equal(s.screen.classList.contains('opening'), false);
}
});
test('a view just below the planet height lands without a jump', async () => {
const target = { ...HOME, lon: 10, lat: 50, height: 21e6 };
const flight = openingFlight({ target, farHeight: FAR });
const s = stage({ target });
const opening = s.play();
s.advanceTo(OPENING.centreMs + OPENING.flightStartMs + flight.ms + 50, 1);
await opening.done;
assert.equal(s.views.at(-1).destination.height, target.height);
assert.ok(Math.abs(s.views.at(-2).destination.height - target.height) < 1000);
});
test('on any screen the drawn planet matches the globe once the logo is centred', () => {
for (const [width, height] of [
[1280, 800],
[2560, 1440],
[3440, 1440],
[3840, 2160],
]) {
const fovy = 2 * Math.atan((Math.tan(Math.PI / 6) * height) / width);
const s = stage({ target: HOME, width, height, fovy, disc: 64 });
const opening = s.play();
const logo = s.screen.querySelector('.loader-logo');
for (const at of [900, 1800]) {
s.advanceTo(at);
const scale = Number(/scale\(([^)]+)\)/.exec(logo.style.transform)[1]);
const radius = globeRadiusPx(s.current().height, {
fovy,
viewportHeight: height,
});
assert.ok(
Math.abs(32 * scale - radius) < 1,
`${width}×${height} at ${at} ms`,
);
}
opening.cancel();
}
});
test("the logo's grid fades from its own opacity", () => {
const s = stage();
const cage = s.doc.getElementById('globe_cage');
const opening = s.play();
assert.equal(Number(s.window.getComputedStyle(cage).opacity), 0.63);
// Halfway through the drawn planet's fade.
const [from, to] = OPENING.pupilMs;
s.advance(OPENING.centreMs + (from + to) / 2);
assert.ok(
Math.abs(Number(s.window.getComputedStyle(cage).opacity) - 0.315) < 0.01,
);
opening.cancel();
});
test('a lone click lands the opening before its handler reads the camera', async () => {
const s = stage({ target: CLOSE });
const opening = s.play();
s.advanceTo(3000);
const button = s.doc.createElement('button');
s.doc.body.appendChild(button);
let seen;
button.addEventListener('click', () => {
seen = s.current();
});
button.click();
assert.equal(seen.height, CLOSE.height);
await opening.done;
});
+80 -6
View File
@@ -1,6 +1,10 @@
import { initFirstRunExperience } from '../firstRunExperience.js';
/** Reveal welcome controls only after restoration and the loading transition. */
/**
* Reveal welcome controls only after restoration and the loading transition.
* `playOpening` plays the opening (src/app/openingIntro.js) on a bare address
* or a share of only a view.
*/
export function startApplicationChrome({
loadingScreen,
styleManager,
@@ -8,32 +12,87 @@ export function startApplicationChrome({
signal,
initializeWelcome = initFirstRunExperience,
initializeSettings,
playOpening = null,
}) {
let disposed = false;
let firstRun;
let opening = null;
let revealTimer;
let resolveDelay;
const minimumDelay = new Promise((resolve) => {
resolveDelay = resolve;
});
const delayTimer = setTimeout(resolveDelay, 1000);
// A navigation stamped after this (a search, a posted view, a later link)
// owns the camera: the opening must not take it back.
const generationAtStart = styleManager._navigationGeneration;
const revealFirstRun = () => {
if (disposed || signal.aborted || firstRun) return;
firstRun = initializeWelcome?.({ styleManager, dataManager });
clearTimeout(revealTimer);
loadingScreen.removeEventListener('transitionend', revealFirstRun);
};
// Welcome waits for the cover's fade, or for 900 ms where none ends.
const revealAfterCover = () => {
if (disposed || signal.aborted) return;
loadingScreen.addEventListener('transitionend', revealFirstRun, {
once: true,
});
revealTimer = setTimeout(revealFirstRun, 900);
};
void Promise.all([styleManager.initialRestorePromise, minimumDelay])
.catch(() => {
/* Restoration reports its own outcome through the controls. */
})
.then(() => {
.then(([restored] = []) => {
if (disposed || signal.aborted) return;
// A bare address, or a share of only a view, opens with the opening
// unless a newer navigation took the camera or the link was refused.
// Hold the restored address through the flight so a reload or a copied
// link opens at the destination.
const shareLink = styleManager.shareLinkManager;
const generation = Number.isInteger(restored?.navigationToken)
? restored.navigationToken
: generationAtStart;
const navigatedSince =
Number.isFinite(generation) &&
styleManager._navigationGeneration !== generation;
const wanted =
!!playOpening &&
!navigatedSince &&
!shareLink?.rejectedShareCode &&
(!styleManager.hasShareState || sharesOnlyAView(restored));
if (wanted) shareLink?.holdWrites?.(true, 'opening');
try {
opening = wanted
? playOpening({ viewer: styleManager.viewer, loadingScreen })
: null;
} catch (error) {
console.error('The opening failed', error);
opening = null;
}
const release = () => shareLink?.holdWrites?.(false, 'opening');
if (opening) {
// The cover fades long before a played-out opening ends; a skip
// hides it only as the opening ends.
let coverFaded = false;
const onCoverFaded = () => {
coverFaded = true;
};
loadingScreen.addEventListener('transitionend', onCoverFaded, {
once: true,
});
void opening.done.then(() => {
release();
loadingScreen.removeEventListener('transitionend', onCoverFaded);
if (coverFaded) revealFirstRun();
else revealAfterCover();
});
return;
}
if (wanted) release();
loadingScreen.classList.add('hidden');
loadingScreen.addEventListener('transitionend', revealFirstRun, {
once: true,
});
revealTimer = setTimeout(revealFirstRun, 900);
revealAfterCover();
});
const keySetup = Promise.resolve(
signal.aborted ? null : initializeSettings?.({ signal }),
@@ -44,6 +103,7 @@ export function startApplicationChrome({
);
return async () => {
disposed = true;
opening?.cancel();
clearTimeout(delayTimer);
clearTimeout(revealTimer);
resolveDelay();
@@ -52,3 +112,17 @@ export function startApplicationChrome({
(await keySetup.catch(() => null))?.destroy();
};
}
/**
* Whether a start-up share restore left only a view: the camera landed where
* the link points and nothing is followed or selected for it.
*/
function sharesOnlyAView(restored) {
return (
restored?.status === 'settled' &&
restored.share?.camera === 'applied' &&
restored.tracking?.status === 'skipped' &&
restored.tracking.reason === 'no-shared-target' &&
!restored.thing
);
}
+4 -2
View File
@@ -22,6 +22,7 @@ import { initImageryBoxTool } from '../ui/imageryBoxTool.js';
import { createRecentImageryPanel } from '../ui/recentImagery.js';
import { createDataLibrary } from '../library/controller.js';
import { flyToLibraryExtent } from '../library/camera.js';
import { openingPlaying } from './openingIntro.js';
import { createLibraryBrowser } from '../ui/libraryBrowser.js';
import { useDataLibraryStore } from '../ui/stores/dataLibrary.js';
import { localGeoJsonServices } from './localGeojsonServices.js';
@@ -88,8 +89,9 @@ export function createApplicationTools({
installGlobeInViewRecovery(viewer, {
// The scope mask hides everything outside its keyhole.
keyholeRadius: () => (isScopeMaskEnabled() ? KEYHOLE_OUTER_RADIUS : 0),
// An authored scene frames its own shots, holds included.
paused: () => sceneDirector.running,
// An authored scene frames its own shots, holds included, and the
// opening starts with the globe as a speck.
paused: () => sceneDirector.running || openingPlaying(),
}),
);
onSceneDirector?.(sceneDirector);
+776
View File
@@ -0,0 +1,776 @@
// Generated by scripts/build-home-countries.mjs. Do not edit by hand.
// Sources: tzdata zone.tab and tzdata.zi (public domain) and the Natural
// Earth countries pack in src/data/local_data/natural_earth (public domain).
/** ISO 3166 country → [lat, lon]: in its largest part, else its first zone's place. */
export const COUNTRY_CENTRES = {
AD: [42.5, 1.6],
AE: [23.9, 54.3],
AF: [33.8, 66],
AG: [17.1, -61.8],
AI: [18.2, -63.1],
AL: [41.1, 20.1],
AM: [40.3, 44.9],
AO: [-12.3, 17.6],
AQ: [-80.6, 20.8],
AR: [-35.2, -65.1],
AS: [-14.3, -170.7],
AT: [47.6, 14.1],
AU: [-25.6, 134.4],
AW: [12.5, -70],
AX: [60.2, 19.9],
AZ: [40.3, 47.7],
BA: [44.2, 17.8],
BB: [13.2, -59.6],
BD: [23.9, 90.2],
BE: [50.6, 4.6],
BF: [12.3, -1.8],
BG: [42.8, 25.2],
BH: [26.1, 50.5],
BI: [-3.4, 29.9],
BJ: [9.6, 2.3],
BL: [17.9, -62.8],
BM: [32.3, -64.8],
BN: [4.5, 114.6],
BO: [-16.7, -64.7],
BQ: [12.2, -68.3],
BR: [-10.8, -53.1],
BS: [24.7, -78],
BT: [27.4, 90.4],
BW: [-22.2, 23.8],
BY: [53.5, 28],
BZ: [17.2, -88.7],
CA: [57.9, -102.4],
CC: [-12.2, 96.9],
CD: [-2.9, 23.6],
CF: [6.6, 20.5],
CG: [-0.8, 15.2],
CH: [46.8, 8.2],
CI: [7.6, -5.6],
CK: [-21.2, -159.8],
CL: [-35.4, -71.2],
CM: [5.7, 12.7],
CN: [36.6, 103.8],
CO: [3.9, -73.1],
CR: [10, -84.2],
CU: [21.6, -79],
CV: [15.1, -23.6],
CW: [12.2, -69],
CX: [-10.4, 105.7],
CY: [34.9, 33],
CZ: [49.7, 15.3],
DE: [51.1, 10.4],
DJ: [11.8, 42.6],
DK: [56.2, 9.4],
DM: [15.4, -61.4],
DO: [18.9, -70.5],
DZ: [28.1, 2.7],
EC: [-1.4, -78.4],
EE: [58.7, 25.8],
EG: [26.5, 29.9],
EH: [24.2, -12.2],
ER: [15.4, 38.8],
ES: [40.4, -3.6],
ET: [8.6, 39.6],
FI: [64.5, 26.3],
FJ: [-17.8, 178],
FK: [-51.7, -58.8],
FM: [6.9, 158.2],
FO: [62.1, -7],
FR: [46.6, 2.5],
GA: [-0.6, 11.8],
GB: [53.9, -2.5],
GD: [12.1, -61.7],
GE: [42.2, 43.5],
GF: [4.9, -52.3],
GG: [49.5, -2.6],
GH: [8, -1.2],
GI: [36.1, -5.3],
GL: [74.8, -41.4],
GM: [13.4, -15.4],
GN: [10.4, -10.9],
GP: [16.2, -61.5],
GQ: [1.6, 10.5],
GR: [39.5, 22.6],
GS: [-54.4, -36.7],
GT: [15.7, -90.4],
GU: [13.4, 144.8],
GW: [12.1, -14.9],
GY: [4.8, -59],
HK: [22.4, 114.2],
HN: [14.8, -86.6],
HR: [45.2, 16.4],
HT: [18.9, -72.7],
HU: [47.2, 19.4],
ID: [-0.2, 114],
IE: [53.2, -8.1],
IL: [31.4, 34.7],
IM: [54.2, -4.5],
IN: [22.9, 79.6],
IO: [-7.3, 72.4],
IQ: [33, 43.7],
IR: [32.6, 54.3],
IS: [65, -18.6],
IT: [43.5, 12.2],
JE: [49.2, -2.1],
JM: [18.2, -77.3],
JO: [31.2, 36.8],
JP: [36.7, 138],
KE: [0.6, 37.8],
KG: [41.5, 74.5],
KH: [12.7, 104.9],
KI: [1.9, -157.4],
KM: [-11.7, 43.3],
KN: [17.3, -62.8],
KP: [40.2, 127.2],
KR: [36.5, 127.9],
KW: [29.3, 47.6],
KY: [19.3, -81.3],
KZ: [48.2, 67.3],
LA: [18.5, 103.7],
LB: [33.9, 35.9],
LC: [13.9, -61],
LI: [47.1, 9.5],
LK: [7.6, 80.7],
LR: [6.5, -9.3],
LS: [-29.6, 28.2],
LT: [55.3, 23.9],
LU: [49.8, 6.1],
LV: [56.9, 24.9],
LY: [27, 18],
MA: [29.8, -8.4],
MC: [43.7, 7.4],
MD: [47.2, 28.5],
ME: [42.8, 19.2],
MF: [18.1, -63.1],
MG: [-19.4, 46.7],
MH: [7.1, 171.2],
MK: [41.6, 21.7],
ML: [17.3, -3.5],
MM: [21.2, 96.5],
MN: [46.8, 103.1],
MO: [22.1, 113.6],
MP: [15.2, 145.7],
MQ: [14.6, -61.1],
MR: [20.3, -10.3],
MS: [16.7, -62.2],
MT: [35.9, 14.4],
MU: [-20.3, 57.6],
MV: [4.2, 73.5],
MW: [-13.2, 34.3],
MX: [23.9, -102.5],
MY: [3.6, 114.7],
MZ: [-17.3, 35.5],
NA: [-22.1, 17.2],
NC: [-21.3, 165.5],
NE: [17.4, 9.4],
NF: [-29, 168],
NG: [9.6, 8.1],
NI: [12.8, -85],
NL: [52.3, 5.6],
NO: [64.2, 14],
NP: [28.2, 83.9],
NR: [-0.5, 166.9],
NU: [-19, -169.9],
NZ: [-44, 170.5],
OM: [20.6, 56.1],
PA: [8.5, -80.1],
PE: [-9.2, -74.4],
PF: [-17.7, -149.4],
PG: [-6.6, 144.3],
PH: [16, 121.4],
PK: [29.9, 69.3],
PL: [52.1, 19.4],
PM: [47, -56.3],
PN: [-24.4, -128.3],
PR: [18.2, -66.5],
PS: [31.9, 35.3],
PT: [39.7, -8],
PW: [7.5, 134.6],
PY: [-23.2, -58.4],
QA: [25.3, 51.2],
RE: [-20.9, 55.5],
RO: [45.9, 25],
RS: [44.2, 20.8],
RU: [61.7, 99.1],
RW: [-2, 29.9],
SA: [24.1, 44.5],
SB: [-9.6, 160.2],
SC: [-4.7, 55.5],
SD: [16, 29.9],
SE: [62.8, 16.7],
SG: [1.4, 103.8],
SH: [-16, -5.7],
SI: [46.1, 14.8],
SJ: [78, 16],
SK: [48.7, 19.5],
SL: [8.6, -11.8],
SM: [43.9, 12.4],
SN: [14.4, -14.5],
SO: [4.8, 45.7],
SR: [4.1, -55.9],
SS: [7.3, 30.3],
ST: [0.2, 6.6],
SV: [13.7, -88.9],
SX: [18, -63.1],
SY: [35, 38.5],
SZ: [-26.6, 31.5],
TC: [21.8, -71.7],
TD: [15.3, 18.6],
TF: [-49.3, 69.5],
TG: [8.5, 1],
TH: [15.1, 101],
TJ: [38.5, 71],
TK: [-9.4, -171.2],
TL: [-8.8, 125.9],
TM: [39.1, 59.4],
TN: [34.1, 9.5],
TO: [-21.2, -175.2],
TR: [39, 35.4],
TT: [10.4, -61.3],
TV: [-8.5, 179.2],
TW: [23.8, 121],
TZ: [-6.3, 34.8],
UA: [49.2, 31.3],
UG: [1.3, 32.4],
UM: [5.9, -162.1],
US: [39.5, -99.1],
UY: [-32.8, -56],
UZ: [41.8, 63.1],
VA: [41.9, 12.5],
VC: [13.3, -61.2],
VE: [7.1, -66.2],
VG: [18.4, -64.6],
VI: [17.7, -64.8],
VN: [16, 107.9],
VU: [-15.2, 166.9],
WF: [-13.3, -176.2],
WS: [-13.6, -172.4],
YE: [15.9, 47.5],
YT: [-12.8, 45.2],
ZA: [-29, 25.2],
ZM: [-13.5, 27.8],
ZW: [-19, 29.9],
};
/** Time zone (tzdata, ICU and older names) → ISO 3166 country. */
export const ZONE_COUNTRIES = {
'Africa/Abidjan': 'CI',
'Africa/Accra': 'GH',
'Africa/Addis_Ababa': 'ET',
'Africa/Algiers': 'DZ',
'Africa/Asmara': 'ER',
'Africa/Asmera': 'ER',
'Africa/Bamako': 'ML',
'Africa/Bangui': 'CF',
'Africa/Banjul': 'GM',
'Africa/Bissau': 'GW',
'Africa/Blantyre': 'MW',
'Africa/Brazzaville': 'CG',
'Africa/Bujumbura': 'BI',
'Africa/Cairo': 'EG',
'Africa/Casablanca': 'MA',
'Africa/Ceuta': 'ES',
'Africa/Conakry': 'GN',
'Africa/Dakar': 'SN',
'Africa/Dar_es_Salaam': 'TZ',
'Africa/Djibouti': 'DJ',
'Africa/Douala': 'CM',
'Africa/El_Aaiun': 'EH',
'Africa/Freetown': 'SL',
'Africa/Gaborone': 'BW',
'Africa/Harare': 'ZW',
'Africa/Johannesburg': 'ZA',
'Africa/Juba': 'SS',
'Africa/Kampala': 'UG',
'Africa/Khartoum': 'SD',
'Africa/Kigali': 'RW',
'Africa/Kinshasa': 'CD',
'Africa/Lagos': 'NG',
'Africa/Libreville': 'GA',
'Africa/Lome': 'TG',
'Africa/Luanda': 'AO',
'Africa/Lubumbashi': 'CD',
'Africa/Lusaka': 'ZM',
'Africa/Malabo': 'GQ',
'Africa/Maputo': 'MZ',
'Africa/Maseru': 'LS',
'Africa/Mbabane': 'SZ',
'Africa/Mogadishu': 'SO',
'Africa/Monrovia': 'LR',
'Africa/Nairobi': 'KE',
'Africa/Ndjamena': 'TD',
'Africa/Niamey': 'NE',
'Africa/Nouakchott': 'MR',
'Africa/Ouagadougou': 'BF',
'Africa/Porto-Novo': 'BJ',
'Africa/Sao_Tome': 'ST',
'Africa/Timbuktu': 'ML',
'Africa/Tripoli': 'LY',
'Africa/Tunis': 'TN',
'Africa/Windhoek': 'NA',
'America/Adak': 'US',
'America/Anchorage': 'US',
'America/Anguilla': 'AI',
'America/Antigua': 'AG',
'America/Araguaina': 'BR',
'America/Argentina/Buenos_Aires': 'AR',
'America/Argentina/Catamarca': 'AR',
'America/Argentina/ComodRivadavia': 'AR',
'America/Argentina/Cordoba': 'AR',
'America/Argentina/Jujuy': 'AR',
'America/Argentina/La_Rioja': 'AR',
'America/Argentina/Mendoza': 'AR',
'America/Argentina/Rio_Gallegos': 'AR',
'America/Argentina/Salta': 'AR',
'America/Argentina/San_Juan': 'AR',
'America/Argentina/San_Luis': 'AR',
'America/Argentina/Tucuman': 'AR',
'America/Argentina/Ushuaia': 'AR',
'America/Aruba': 'AW',
'America/Asuncion': 'PY',
'America/Atikokan': 'CA',
'America/Atka': 'US',
'America/Bahia': 'BR',
'America/Bahia_Banderas': 'MX',
'America/Barbados': 'BB',
'America/Belem': 'BR',
'America/Belize': 'BZ',
'America/Blanc-Sablon': 'CA',
'America/Boa_Vista': 'BR',
'America/Bogota': 'CO',
'America/Boise': 'US',
'America/Buenos_Aires': 'AR',
'America/Cambridge_Bay': 'CA',
'America/Campo_Grande': 'BR',
'America/Cancun': 'MX',
'America/Caracas': 'VE',
'America/Catamarca': 'AR',
'America/Cayenne': 'GF',
'America/Cayman': 'KY',
'America/Chicago': 'US',
'America/Chihuahua': 'MX',
'America/Ciudad_Juarez': 'MX',
'America/Coral_Harbour': 'CA',
'America/Cordoba': 'AR',
'America/Costa_Rica': 'CR',
'America/Coyhaique': 'CL',
'America/Creston': 'CA',
'America/Cuiaba': 'BR',
'America/Curacao': 'CW',
'America/Danmarkshavn': 'GL',
'America/Dawson': 'CA',
'America/Dawson_Creek': 'CA',
'America/Denver': 'US',
'America/Detroit': 'US',
'America/Dominica': 'DM',
'America/Edmonton': 'CA',
'America/Eirunepe': 'BR',
'America/El_Salvador': 'SV',
'America/Ensenada': 'MX',
'America/Fort_Nelson': 'CA',
'America/Fort_Wayne': 'US',
'America/Fortaleza': 'BR',
'America/Glace_Bay': 'CA',
'America/Godthab': 'GL',
'America/Goose_Bay': 'CA',
'America/Grand_Turk': 'TC',
'America/Grenada': 'GD',
'America/Guadeloupe': 'GP',
'America/Guatemala': 'GT',
'America/Guayaquil': 'EC',
'America/Guyana': 'GY',
'America/Halifax': 'CA',
'America/Havana': 'CU',
'America/Hermosillo': 'MX',
'America/Indiana/Indianapolis': 'US',
'America/Indiana/Knox': 'US',
'America/Indiana/Marengo': 'US',
'America/Indiana/Petersburg': 'US',
'America/Indiana/Tell_City': 'US',
'America/Indiana/Vevay': 'US',
'America/Indiana/Vincennes': 'US',
'America/Indiana/Winamac': 'US',
'America/Indianapolis': 'US',
'America/Inuvik': 'CA',
'America/Iqaluit': 'CA',
'America/Jamaica': 'JM',
'America/Jujuy': 'AR',
'America/Juneau': 'US',
'America/Kentucky/Louisville': 'US',
'America/Kentucky/Monticello': 'US',
'America/Knox_IN': 'US',
'America/Kralendijk': 'BQ',
'America/La_Paz': 'BO',
'America/Lima': 'PE',
'America/Los_Angeles': 'US',
'America/Louisville': 'US',
'America/Lower_Princes': 'SX',
'America/Maceio': 'BR',
'America/Managua': 'NI',
'America/Manaus': 'BR',
'America/Marigot': 'MF',
'America/Martinique': 'MQ',
'America/Matamoros': 'MX',
'America/Mazatlan': 'MX',
'America/Mendoza': 'AR',
'America/Menominee': 'US',
'America/Merida': 'MX',
'America/Metlakatla': 'US',
'America/Mexico_City': 'MX',
'America/Miquelon': 'PM',
'America/Moncton': 'CA',
'America/Monterrey': 'MX',
'America/Montevideo': 'UY',
'America/Montreal': 'CA',
'America/Montserrat': 'MS',
'America/Nassau': 'BS',
'America/New_York': 'US',
'America/Nipigon': 'CA',
'America/Nome': 'US',
'America/Noronha': 'BR',
'America/North_Dakota/Beulah': 'US',
'America/North_Dakota/Center': 'US',
'America/North_Dakota/New_Salem': 'US',
'America/Nuuk': 'GL',
'America/Ojinaga': 'MX',
'America/Panama': 'PA',
'America/Pangnirtung': 'CA',
'America/Paramaribo': 'SR',
'America/Phoenix': 'US',
'America/Port-au-Prince': 'HT',
'America/Port_of_Spain': 'TT',
'America/Porto_Acre': 'BR',
'America/Porto_Velho': 'BR',
'America/Puerto_Rico': 'PR',
'America/Punta_Arenas': 'CL',
'America/Rainy_River': 'CA',
'America/Rankin_Inlet': 'CA',
'America/Recife': 'BR',
'America/Regina': 'CA',
'America/Resolute': 'CA',
'America/Rio_Branco': 'BR',
'America/Rosario': 'AR',
'America/Santa_Isabel': 'MX',
'America/Santarem': 'BR',
'America/Santiago': 'CL',
'America/Santo_Domingo': 'DO',
'America/Sao_Paulo': 'BR',
'America/Scoresbysund': 'GL',
'America/Shiprock': 'US',
'America/Sitka': 'US',
'America/St_Barthelemy': 'BL',
'America/St_Johns': 'CA',
'America/St_Kitts': 'KN',
'America/St_Lucia': 'LC',
'America/St_Thomas': 'VI',
'America/St_Vincent': 'VC',
'America/Swift_Current': 'CA',
'America/Tegucigalpa': 'HN',
'America/Thule': 'GL',
'America/Thunder_Bay': 'CA',
'America/Tijuana': 'MX',
'America/Toronto': 'CA',
'America/Tortola': 'VG',
'America/Vancouver': 'CA',
'America/Virgin': 'VI',
'America/Whitehorse': 'CA',
'America/Winnipeg': 'CA',
'America/Yakutat': 'US',
'America/Yellowknife': 'CA',
'Antarctica/Casey': 'AQ',
'Antarctica/Davis': 'AQ',
'Antarctica/DumontDUrville': 'AQ',
'Antarctica/Macquarie': 'AU',
'Antarctica/Mawson': 'AQ',
'Antarctica/McMurdo': 'AQ',
'Antarctica/Palmer': 'AQ',
'Antarctica/Rothera': 'AQ',
'Antarctica/South_Pole': 'AQ',
'Antarctica/Syowa': 'AQ',
'Antarctica/Troll': 'AQ',
'Antarctica/Vostok': 'AQ',
'Arctic/Longyearbyen': 'SJ',
'Asia/Aden': 'YE',
'Asia/Almaty': 'KZ',
'Asia/Amman': 'JO',
'Asia/Anadyr': 'RU',
'Asia/Aqtau': 'KZ',
'Asia/Aqtobe': 'KZ',
'Asia/Ashgabat': 'TM',
'Asia/Ashkhabad': 'TM',
'Asia/Atyrau': 'KZ',
'Asia/Baghdad': 'IQ',
'Asia/Bahrain': 'BH',
'Asia/Baku': 'AZ',
'Asia/Bangkok': 'TH',
'Asia/Barnaul': 'RU',
'Asia/Beirut': 'LB',
'Asia/Bishkek': 'KG',
'Asia/Brunei': 'BN',
'Asia/Calcutta': 'IN',
'Asia/Chita': 'RU',
'Asia/Choibalsan': 'MN',
'Asia/Chongqing': 'CN',
'Asia/Chungking': 'CN',
'Asia/Colombo': 'LK',
'Asia/Dacca': 'BD',
'Asia/Damascus': 'SY',
'Asia/Dhaka': 'BD',
'Asia/Dili': 'TL',
'Asia/Dubai': 'AE',
'Asia/Dushanbe': 'TJ',
'Asia/Famagusta': 'CY',
'Asia/Gaza': 'PS',
'Asia/Harbin': 'CN',
'Asia/Hebron': 'PS',
'Asia/Ho_Chi_Minh': 'VN',
'Asia/Hong_Kong': 'HK',
'Asia/Hovd': 'MN',
'Asia/Irkutsk': 'RU',
'Asia/Istanbul': 'TR',
'Asia/Jakarta': 'ID',
'Asia/Jayapura': 'ID',
'Asia/Jerusalem': 'IL',
'Asia/Kabul': 'AF',
'Asia/Kamchatka': 'RU',
'Asia/Karachi': 'PK',
'Asia/Kashgar': 'CN',
'Asia/Kathmandu': 'NP',
'Asia/Katmandu': 'NP',
'Asia/Khandyga': 'RU',
'Asia/Kolkata': 'IN',
'Asia/Krasnoyarsk': 'RU',
'Asia/Kuala_Lumpur': 'MY',
'Asia/Kuching': 'MY',
'Asia/Kuwait': 'KW',
'Asia/Macao': 'MO',
'Asia/Macau': 'MO',
'Asia/Magadan': 'RU',
'Asia/Makassar': 'ID',
'Asia/Manila': 'PH',
'Asia/Muscat': 'OM',
'Asia/Nicosia': 'CY',
'Asia/Novokuznetsk': 'RU',
'Asia/Novosibirsk': 'RU',
'Asia/Omsk': 'RU',
'Asia/Oral': 'KZ',
'Asia/Phnom_Penh': 'KH',
'Asia/Pontianak': 'ID',
'Asia/Pyongyang': 'KP',
'Asia/Qatar': 'QA',
'Asia/Qostanay': 'KZ',
'Asia/Qyzylorda': 'KZ',
'Asia/Rangoon': 'MM',
'Asia/Riyadh': 'SA',
'Asia/Saigon': 'VN',
'Asia/Sakhalin': 'RU',
'Asia/Samarkand': 'UZ',
'Asia/Seoul': 'KR',
'Asia/Shanghai': 'CN',
'Asia/Singapore': 'SG',
'Asia/Srednekolymsk': 'RU',
'Asia/Taipei': 'TW',
'Asia/Tashkent': 'UZ',
'Asia/Tbilisi': 'GE',
'Asia/Tehran': 'IR',
'Asia/Tel_Aviv': 'IL',
'Asia/Thimbu': 'BT',
'Asia/Thimphu': 'BT',
'Asia/Tokyo': 'JP',
'Asia/Tomsk': 'RU',
'Asia/Ujung_Pandang': 'ID',
'Asia/Ulaanbaatar': 'MN',
'Asia/Ulan_Bator': 'MN',
'Asia/Urumqi': 'CN',
'Asia/Ust-Nera': 'RU',
'Asia/Vientiane': 'LA',
'Asia/Vladivostok': 'RU',
'Asia/Yakutsk': 'RU',
'Asia/Yangon': 'MM',
'Asia/Yekaterinburg': 'RU',
'Asia/Yerevan': 'AM',
'Atlantic/Azores': 'PT',
'Atlantic/Bermuda': 'BM',
'Atlantic/Canary': 'ES',
'Atlantic/Cape_Verde': 'CV',
'Atlantic/Faeroe': 'FO',
'Atlantic/Faroe': 'FO',
'Atlantic/Jan_Mayen': 'SJ',
'Atlantic/Madeira': 'PT',
'Atlantic/Reykjavik': 'IS',
'Atlantic/South_Georgia': 'GS',
'Atlantic/St_Helena': 'SH',
'Atlantic/Stanley': 'FK',
'Australia/ACT': 'AU',
'Australia/Adelaide': 'AU',
'Australia/Brisbane': 'AU',
'Australia/Broken_Hill': 'AU',
'Australia/Canberra': 'AU',
'Australia/Currie': 'AU',
'Australia/Darwin': 'AU',
'Australia/Eucla': 'AU',
'Australia/Hobart': 'AU',
'Australia/LHI': 'AU',
'Australia/Lindeman': 'AU',
'Australia/Lord_Howe': 'AU',
'Australia/Melbourne': 'AU',
'Australia/NSW': 'AU',
'Australia/North': 'AU',
'Australia/Perth': 'AU',
'Australia/Queensland': 'AU',
'Australia/South': 'AU',
'Australia/Sydney': 'AU',
'Australia/Tasmania': 'AU',
'Australia/Victoria': 'AU',
'Australia/West': 'AU',
'Australia/Yancowinna': 'AU',
'Brazil/Acre': 'BR',
'Brazil/DeNoronha': 'BR',
'Brazil/East': 'BR',
'Brazil/West': 'BR',
'Canada/Atlantic': 'CA',
'Canada/Central': 'CA',
'Canada/Eastern': 'CA',
'Canada/Mountain': 'CA',
'Canada/Newfoundland': 'CA',
'Canada/Pacific': 'CA',
'Canada/Saskatchewan': 'CA',
'Canada/Yukon': 'CA',
'Chile/Continental': 'CL',
'Chile/EasterIsland': 'CL',
'Europe/Amsterdam': 'NL',
'Europe/Andorra': 'AD',
'Europe/Astrakhan': 'RU',
'Europe/Athens': 'GR',
'Europe/Belfast': 'GB',
'Europe/Belgrade': 'RS',
'Europe/Berlin': 'DE',
'Europe/Bratislava': 'SK',
'Europe/Brussels': 'BE',
'Europe/Bucharest': 'RO',
'Europe/Budapest': 'HU',
'Europe/Busingen': 'DE',
'Europe/Chisinau': 'MD',
'Europe/Copenhagen': 'DK',
'Europe/Dublin': 'IE',
'Europe/Gibraltar': 'GI',
'Europe/Guernsey': 'GG',
'Europe/Helsinki': 'FI',
'Europe/Isle_of_Man': 'IM',
'Europe/Istanbul': 'TR',
'Europe/Jersey': 'JE',
'Europe/Kaliningrad': 'RU',
'Europe/Kiev': 'UA',
'Europe/Kirov': 'RU',
'Europe/Kyiv': 'UA',
'Europe/Lisbon': 'PT',
'Europe/Ljubljana': 'SI',
'Europe/London': 'GB',
'Europe/Luxembourg': 'LU',
'Europe/Madrid': 'ES',
'Europe/Malta': 'MT',
'Europe/Mariehamn': 'AX',
'Europe/Minsk': 'BY',
'Europe/Monaco': 'MC',
'Europe/Moscow': 'RU',
'Europe/Nicosia': 'CY',
'Europe/Oslo': 'NO',
'Europe/Paris': 'FR',
'Europe/Podgorica': 'ME',
'Europe/Prague': 'CZ',
'Europe/Riga': 'LV',
'Europe/Rome': 'IT',
'Europe/Samara': 'RU',
'Europe/San_Marino': 'SM',
'Europe/Sarajevo': 'BA',
'Europe/Saratov': 'RU',
'Europe/Simferopol': 'UA',
'Europe/Skopje': 'MK',
'Europe/Sofia': 'BG',
'Europe/Stockholm': 'SE',
'Europe/Tallinn': 'EE',
'Europe/Tirane': 'AL',
'Europe/Tiraspol': 'MD',
'Europe/Ulyanovsk': 'RU',
'Europe/Uzhgorod': 'UA',
'Europe/Vaduz': 'LI',
'Europe/Vatican': 'VA',
'Europe/Vienna': 'AT',
'Europe/Vilnius': 'LT',
'Europe/Volgograd': 'RU',
'Europe/Warsaw': 'PL',
'Europe/Zagreb': 'HR',
'Europe/Zaporozhye': 'UA',
'Europe/Zurich': 'CH',
'Indian/Antananarivo': 'MG',
'Indian/Chagos': 'IO',
'Indian/Christmas': 'CX',
'Indian/Cocos': 'CC',
'Indian/Comoro': 'KM',
'Indian/Kerguelen': 'TF',
'Indian/Mahe': 'SC',
'Indian/Maldives': 'MV',
'Indian/Mauritius': 'MU',
'Indian/Mayotte': 'YT',
'Indian/Reunion': 'RE',
'Mexico/BajaNorte': 'MX',
'Mexico/BajaSur': 'MX',
'Mexico/General': 'MX',
'Pacific/Apia': 'WS',
'Pacific/Auckland': 'NZ',
'Pacific/Bougainville': 'PG',
'Pacific/Chatham': 'NZ',
'Pacific/Chuuk': 'FM',
'Pacific/Easter': 'CL',
'Pacific/Efate': 'VU',
'Pacific/Enderbury': 'KI',
'Pacific/Fakaofo': 'TK',
'Pacific/Fiji': 'FJ',
'Pacific/Funafuti': 'TV',
'Pacific/Galapagos': 'EC',
'Pacific/Gambier': 'PF',
'Pacific/Guadalcanal': 'SB',
'Pacific/Guam': 'GU',
'Pacific/Honolulu': 'US',
'Pacific/Johnston': 'US',
'Pacific/Kanton': 'KI',
'Pacific/Kiritimati': 'KI',
'Pacific/Kosrae': 'FM',
'Pacific/Kwajalein': 'MH',
'Pacific/Majuro': 'MH',
'Pacific/Marquesas': 'PF',
'Pacific/Midway': 'UM',
'Pacific/Nauru': 'NR',
'Pacific/Niue': 'NU',
'Pacific/Norfolk': 'NF',
'Pacific/Noumea': 'NC',
'Pacific/Pago_Pago': 'AS',
'Pacific/Palau': 'PW',
'Pacific/Pitcairn': 'PN',
'Pacific/Pohnpei': 'FM',
'Pacific/Ponape': 'FM',
'Pacific/Port_Moresby': 'PG',
'Pacific/Rarotonga': 'CK',
'Pacific/Saipan': 'MP',
'Pacific/Samoa': 'AS',
'Pacific/Tahiti': 'PF',
'Pacific/Tarawa': 'KI',
'Pacific/Tongatapu': 'TO',
'Pacific/Truk': 'FM',
'Pacific/Wake': 'UM',
'Pacific/Wallis': 'WF',
'Pacific/Yap': 'FM',
'US/Alaska': 'US',
'US/Aleutian': 'US',
'US/Arizona': 'US',
'US/Central': 'US',
'US/East-Indiana': 'US',
'US/Eastern': 'US',
'US/Hawaii': 'US',
'US/Indiana-Starke': 'US',
'US/Michigan': 'US',
'US/Mountain': 'US',
'US/Pacific': 'US',
'US/Samoa': 'AS',
};
+3 -5
View File
@@ -774,11 +774,9 @@ test('markup, startup ordering and accessibility remain pinned', async () => {
);
assert.match(startup, /styleManager\.initialRestorePromise/);
assert.ok(
startup.indexOf("loadingScreen.classList.add('hidden')") <
startup.indexOf(
"loadingScreen.addEventListener('transitionend', revealFirstRun",
),
assert.match(
startup,
/loadingScreen\.classList\.add\('hidden'\);\s*revealAfterCover\(\);/,
);
assert.match(
startup,
+50
View File
@@ -0,0 +1,50 @@
import { COUNTRY_CENTRES, ZONE_COUNTRIES } from './data/homeCountries.js';
import { START_VIEW } from './camera.js';
/**
* The visitor's country, guessed from the browser's time zone and, for a zone
* that belongs to no country (UTC), the region of a preferred language
* ("en-GB"). Nothing leaves the browser. Null when neither names one.
* @param {{timeZone?: string|null, languages?: readonly string[]}} [where]
* @returns {string|null} ISO 3166 code, e.g. 'DE'
*/
export function homeCountry({
timeZone = currentTimeZone(),
languages = globalThis.navigator?.languages ?? [],
} = {}) {
const byZone = ZONE_COUNTRIES[timeZone];
if (byZone) return byZone;
for (const language of languages) {
const region = regionOf(language);
if (region && COUNTRY_CENTRES[region]) return region;
}
return null;
}
/**
* Look straight down over the visitor's country from the start height.
* Use the default start view when the country is unknown.
* @param {{timeZone?: string|null, languages?: readonly string[]}} [where]
*/
export function homeCountryView(where = {}) {
const centre = COUNTRY_CENTRES[homeCountry(where)];
if (!centre) return START_VIEW;
const [lat, lon] = centre;
return Object.freeze({ lon, lat, height: START_VIEW.height });
}
function currentTimeZone() {
try {
return new Intl.DateTimeFormat().resolvedOptions().timeZone ?? null;
} catch {
return null;
}
}
function regionOf(language) {
try {
return new Intl.Locale(language).region ?? null;
} catch {
return null;
}
}
+61
View File
@@ -0,0 +1,61 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { homeCountry, homeCountryView } from './homeCountry.js';
import { START_VIEW } from './camera.js';
import { COUNTRY_CENTRES, ZONE_COUNTRIES } from './data/homeCountries.js';
test('the time zone names the country, in its tzdata, ICU or older name', () => {
assert.equal(homeCountry({ timeZone: 'Europe/Berlin', languages: [] }), 'DE');
assert.equal(homeCountry({ timeZone: 'Asia/Kolkata', languages: [] }), 'IN');
assert.equal(homeCountry({ timeZone: 'Asia/Calcutta', languages: [] }), 'IN');
assert.equal(
homeCountry({ timeZone: 'Asia/Choibalsan', languages: [] }),
'MN',
);
assert.equal(
homeCountry({ timeZone: 'Europe/Uzhgorod', languages: [] }),
'UA',
);
assert.equal(homeCountry({ timeZone: 'Europe/Kiev', languages: [] }), 'UA');
assert.equal(
homeCountry({ timeZone: 'America/Chicago', languages: ['de-DE'] }),
'US',
'the zone outranks the language',
);
});
test("a zone of no country falls back to a language's region", () => {
assert.equal(
homeCountry({ timeZone: 'UTC', languages: ['fr', 'en-GB'] }),
'GB',
);
assert.equal(homeCountry({ timeZone: 'Etc/UTC', languages: ['ru'] }), null);
assert.equal(homeCountry({ timeZone: null, languages: [] }), null);
});
test('the start view looks down on the country from the planet height', () => {
const view = homeCountryView({ timeZone: 'Asia/Tokyo', languages: [] });
assert.deepEqual(
[view.lat, view.lon, view.height],
[...COUNTRY_CENTRES.JP, START_VIEW.height],
);
assert.equal(
homeCountryView({ timeZone: 'UTC', languages: [] }),
START_VIEW,
'unknown: the default start',
);
});
test('every zone has a country with a centre on the globe', () => {
for (const [zone, country] of Object.entries(ZONE_COUNTRIES)) {
const centre = COUNTRY_CENTRES[country];
assert.ok(centre, `${zone} → ${country}`);
const [lat, lon] = centre;
assert.ok(Math.abs(lat) <= 90 && Math.abs(lon) <= 180, country);
}
// Countries whose largest part is not where their centroid would be.
const [usLat, usLon] = COUNTRY_CENTRES.US;
assert.ok(usLat > 30 && usLat < 45 && usLon > -110 && usLon < -85);
const [frLat, frLon] = COUNTRY_CENTRES.FR;
assert.ok(frLat > 42 && frLat < 50 && frLon > -2 && frLon < 8);
});
+8 -1
View File
@@ -61,6 +61,7 @@ import {
import { isRtlLocale } from './i18n/locale.js';
import { localizeLayerName } from './ui/layerPanel.js';
import { isEmbeddedInline } from './app/embed.js';
import { openingPlaying } from './app/openingIntro.js';
import { subscribeSelectedVessel } from './hudReadouts.js';
/** Color palettes keyed by shader mode; applied as CSS custom properties. */
@@ -330,7 +331,13 @@ export class IntelHUD {
}
// First settled view: request the AI summary now rather than waiting for
// the periodic tick (saves up to ~15s of "Awaiting telemetry...").
if (!this._firstSummaryKicked && this._visible && this._latestMetrics) {
// The opening's frames are not that view: it lands with a moveEnd.
if (
!this._firstSummaryKicked &&
!openingPlaying() &&
this._visible &&
this._latestMetrics
) {
this._firstSummaryKicked = true;
void this._updateSummary(true, true);
}
+44
View File
@@ -6,6 +6,8 @@
// setup as hudPageVisibility.test.mjs).
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { Window } from 'happy-dom';
import { playOpeningIntro } from './app/openingIntro.js';
import { hudReadouts } from './testSupport/hudReadouts.mjs';
import { registerHooks } from 'node:module';
import { fakeCameraPort } from './testSupport/fakeCameraPort.mjs';
@@ -175,3 +177,45 @@ test('an unchanged context restores its accepted reply over the fallback line',
assert.equal(service.calls, 1);
assert.equal(shown(), 'Austin capitol district live');
});
test('the first summary waits for the opening to land', (t) => {
const { hud } = createHud(t, {
summarize: async () => ({ ok: true, status: 200, data: { summary: 'x' } }),
});
hud._visible = true;
let asked = 0;
hud._updateSummary = async () => {
asked += 1;
};
const win = new Window();
win.document.body.innerHTML = `
<div id="loading-screen"><span class="loader-logo"><svg>
<path id="outer_eye"/><path id="inner_eye"/>
</svg></span></div>`;
win.requestAnimationFrame = () => 1;
win.matchMedia = () => ({ matches: false });
const opening = playOpeningIntro({
win,
loadingScreen: win.document.getElementById('loading-screen'),
camera: {
pose: () => ({
lon: 10,
lat: 50,
height: 23e6,
heading: 0,
pitch: -Math.PI / 2,
roll: 0,
fovy: 1,
}),
setView() {},
onCommand: () => () => {},
},
});
t.after(() => opening.cancel());
hud._onCameraMoveEnd();
assert.equal(asked, 0);
opening.cancel();
hud._onCameraMoveEnd();
assert.equal(asked, 1);
});
+13 -4
View File
@@ -126,6 +126,8 @@ export class ShareLinkManager {
this._panelStateProvider = null;
this._styleParamStateProvider = null;
this._initialRestorePending = false;
// Who holds the hash writes (holdWrites).
this._writeHolds = new Set();
// Each incoming share (start-up or a later hash navigation) gets a token;
// only the newest one may release URL-write suppression.
this._restoreToken = 0;
@@ -726,10 +728,12 @@ export class ShareLinkManager {
/**
* Hold the address's hash writes, for an owner that covers the view and
* keeps the person's camera and layers out of the address while it does
* (Stories). Releasing writes the current view again.
* (Stories, the opening's flight). Each `owner` holds and releases its own
* hold; once none holds, the current view is written again.
* @param {boolean} held
* @param {string} [owner]
*/
holdWrites(held) {
holdWrites(held, owner = 'stories') {
if (held && !this._writesHeld && this._debounceTimer) {
// A view change still waiting for its debounce is written first, so
// the address the owner saves is the live view.
@@ -737,11 +741,16 @@ export class ShareLinkManager {
this._debounceTimer = null;
this._updateHash();
}
this._writesHeld = !!held;
if (!held) this._scheduleUpdate();
if (held) this._writeHolds.add(owner);
else this._writeHolds.delete(owner);
if (!this._writesHeld) this._scheduleUpdate();
else clearTimeout(this._debounceTimer);
}
get _writesHeld() {
return this._writeHolds.size > 0;
}
_scheduleUpdate() {
if (this._destroyed || this._initialRestorePending || this._writesHeld)
return;
+15
View File
@@ -193,6 +193,21 @@ test('holding writes first writes a view change still waiting for its debounce',
manager.destroy();
});
test('each owner releases only its own hold on writes', (t) => {
installTab(t, SHARE_A);
const timers = installManualTimers(t);
const manager = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()));
manager.completeInitialRestore(manager.parseInitialHash().restoreToken);
manager.holdWrites(true, 'opening');
manager.holdWrites(true);
manager.holdWrites(false, 'opening');
manager._scheduleUpdate();
assert.equal(timers.size, 0, 'Stories still holds them');
manager.holdWrites(false);
assert.equal(timers.size, 1, 'written again once none holds');
manager.destroy();
});
test('a hash write keeps the state another owner stored on the entry', (t) => {
installTab(t, SHARE_A);
const written = [];
+3
View File
@@ -1,8 +1,11 @@
import { createApplicationControls } from '../app/controls.js';
import { getStandaloneCatalog } from './catalog.js';
import { homeCountryView } from '../homeCountry.js';
export function createStandaloneControls(options) {
return createApplicationControls({
catalog: options?.catalog ?? getStandaloneCatalog(),
// The planet over the visitor's country; the title's logo goes back here.
startView: homeCountryView(),
...options,
});
}
+8
View File
@@ -1,8 +1,16 @@
import { startApplicationChrome } from '../app/startupChrome.js';
import { playOpeningIntro } from '../app/openingIntro.js';
import { initKeySetup } from '../keySetup.js';
import { streetLevelFromParams } from '../view/index.js';
export function startStandaloneChrome(options) {
// A Street Level link opens its photos at its view, so it plays no
// opening. Read now: the address is rewritten once the link restores.
const streetLevel = streetLevelFromParams(
new URLSearchParams(globalThis.location?.hash.slice(1) ?? ''),
);
return startApplicationChrome({
initializeSettings: initKeySetup,
playOpening: streetLevel ? null : playOpeningIntro,
...options,
});
}
+195 -6
View File
@@ -10,7 +10,12 @@ const source = readFileSync(
.replace(/^import .*;\n/gm, '')
.replace('export function', 'function');
function fixture() {
function fixture({
playOpening,
hasShareState = false,
shareLink,
navigationGeneration,
} = {}) {
const timers = new Map();
const listeners = new Map();
const events = [];
@@ -37,6 +42,15 @@ function fixture() {
};
vm.createContext(context);
vm.runInContext(source, context);
const styleManager = {
_navigationGeneration: navigationGeneration,
hasShareState,
viewer: 'viewer',
shareLinkManager: shareLink,
initialRestorePromise: new Promise((resolve) => {
restored = resolve;
}),
};
const stop = context.startApplicationChrome({
initializeSettings: context.initKeySetup,
loadingScreen: {
@@ -44,16 +58,14 @@ function fixture() {
addEventListener: (type, listener) => listeners.set(type, listener),
removeEventListener: (type) => listeners.delete(type),
},
styleManager: {
initialRestorePromise: new Promise((resolve) => {
restored = resolve;
}),
},
playOpening,
styleManager,
dataManager: {},
signal: controller.signal,
});
return {
events,
styleManager,
listeners,
stop,
restored,
@@ -124,3 +136,180 @@ test('shutdown during the cover transition cancels the listener and fallback', a
f.fire(900);
assert.deepEqual(f.events, ['hidden', 'settings:destroy']);
});
function openingStub(events) {
let land;
const calls = [];
const play = (options) => {
calls.push(options);
events.push('opening');
return {
done: new Promise((resolve) => {
land = resolve;
}),
cancel: () => events.push('opening:cancel'),
};
};
return { play, calls, land: () => land() };
}
test('a bare address plays the opening, and welcome waits for its end', async () => {
const events = [];
const opening = openingStub(events);
const f = fixture({ playOpening: opening.play });
f.events.push = (value) => events.push(value);
f.restored();
f.fire(1000);
await flush();
assert.deepEqual(events, ['opening']);
assert.equal(opening.calls[0].viewer, 'viewer');
f.fire(900);
assert.deepEqual(events, ['opening'], 'no fallback timer while it plays');
f.listeners.get('transitionend')(); // the cover has faded
opening.land();
await flush();
assert.deepEqual(events, ['opening', 'welcome']);
await f.stop();
assert.ok(events.includes('opening:cancel'));
});
test("the opening's frames stay out of the address until it ends", async () => {
const events = [];
const holds = [];
const opening = openingStub(events);
const f = fixture({
playOpening: opening.play,
shareLink: { holdWrites: (held, owner) => holds.push([held, owner]) },
});
f.restored();
f.fire(1000);
await flush();
assert.deepEqual(holds, [[true, 'opening']]);
opening.land();
await flush();
assert.deepEqual(holds, [
[true, 'opening'],
[false, 'opening'],
]);
await f.stop();
});
test('an opening that does not play releases the address at once', async () => {
const holds = [];
const f = fixture({
playOpening: () => null,
shareLink: { holdWrites: (held, owner) => holds.push([held, owner]) },
});
f.restored();
f.fire(1000);
await flush();
assert.deepEqual(holds, [
[true, 'opening'],
[false, 'opening'],
]);
assert.ok(f.events.includes('hidden'));
await f.stop();
});
const VIEW_ONLY = Object.freeze({
status: 'settled',
share: { camera: 'applied' },
tracking: { status: 'skipped', reason: 'no-shared-target' },
thing: false,
});
test('a link to only a view opens with the opening, ending at that view', async () => {
const events = [];
const opening = openingStub(events);
const f = fixture({ playOpening: opening.play, hasShareState: true });
f.restored(VIEW_ONLY);
f.fire(1000);
await flush();
assert.equal(opening.calls.length, 1);
await f.stop();
});
for (const [name, restored] of [
['a followed target', { ...VIEW_ONLY, tracking: { status: 'restored' } }],
['a shared thing', { ...VIEW_ONLY, thing: true }],
[
'a camera the person moved first',
{ ...VIEW_ONLY, share: { camera: 'superseded' } },
],
['a failed restore', { status: 'failed' }],
]) {
test(`a link to ${name} opens without the opening`, async () => {
for (const [result, plays] of [
[restored, 0],
[VIEW_ONLY, 1],
]) {
const opening = openingStub([]);
const f = fixture({ playOpening: opening.play, hasShareState: true });
f.restored(result);
f.fire(1000);
await flush();
assert.equal(opening.calls.length, plays);
if (!plays) assert.deepEqual(f.events, ['hidden']);
await f.stop();
}
});
}
test('a share restore whose navigation was superseded does not start the opening', async () => {
const opening = openingStub([]);
const f = fixture({
playOpening: opening.play,
hasShareState: true,
navigationGeneration: 5,
});
f.restored({ ...VIEW_ONLY, navigationToken: 3 });
f.fire(1000);
await flush();
assert.equal(opening.calls.length, 0);
assert.deepEqual(f.events, ['hidden']);
await f.stop();
});
test('a navigation before the opening starts keeps the camera from it', async () => {
const opening = openingStub([]);
const f = fixture({ playOpening: opening.play, navigationGeneration: 0 });
f.styleManager._navigationGeneration = 1;
f.restored();
f.fire(1000);
await flush();
assert.equal(opening.calls.length, 0);
assert.deepEqual(f.events, ['hidden']);
await f.stop();
});
for (const [name, rejectedShareCode, plays] of [
['a rejected share code opens without the opening', 'checksum', 0],
['control: a bare address still plays it', null, 1],
]) {
test(name, async () => {
const opening = openingStub([]);
const f = fixture({
playOpening: opening.play,
shareLink: { rejectedShareCode },
});
f.restored({ status: 'not-requested', share: null, layers: [] });
f.fire(1000);
await flush();
assert.equal(opening.calls.length, plays);
if (!plays) assert.deepEqual(f.events, ['hidden']);
await f.stop();
});
}
test('a skipped opening reveals welcome only once the cover has faded', async () => {
const f = fixture({
playOpening: () => ({ done: Promise.resolve(), cancel() {} }),
});
f.restored();
f.fire(1000);
await flush();
assert.ok(!f.events.includes('welcome'));
f.fire(900);
assert.ok(f.events.includes('welcome'));
await f.stop();
});
+2 -1
View File
@@ -284,6 +284,7 @@ test('a /share/<code> address opens its place view through the start-up restore'
const result = await restore(page);
assert.equal(result.status, 'settled');
assert.equal(result.share.camera, 'applied');
assert.equal(result.thing, false, 'a view, not a thing');
assert.equal(page.restores[0].style, 'noir');
assert.deepEqual(page.restores[0].panelState.specs, [
{ id: 'data-panel', collapsed: false, pinned: null },
@@ -398,7 +399,7 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
parsed.layerState.options.flights.selectedFlightsTrackingId,
'a1b2c3',
);
await restore(page);
assert.equal((await restore(page)).thing, true, 'a share of a thing');
// The opening flight goes where following the fix puts the camera.
const camera = followCameraFor(FIX, OFFSET);
const destination = Cesium.Cartographic.fromCartesian(
+10 -1
View File
@@ -324,7 +324,16 @@ export class ShareRestoration {
if (vessel) void this._restoreSharedVessel(vessel, current);
// The token tells listeners whether anyone navigated after the
// restore's flight landed (while the layers were still loading).
settle({ status: 'settled', share, layers, tracking, navigationToken });
// `thing` says the share is of a thing (a followed or selected one),
// not only a view.
settle({
status: 'settled',
share,
layers,
tracking,
navigationToken,
thing: state?.shareView?.kind === 'thing',
});
} catch (error) {
if (!current()) return;
this.shareLinkManager.completeInitialRestore(state.restoreToken);
+29
View File
@@ -431,6 +431,35 @@ html:not([lang='en']):not(:lang(zh)):not(:lang(ja))
}
}
/* The opening (src/app/openingIntro.js) sets --opening-veil and --opening-text each frame. */
#loading-screen.opening {
background: color-mix(
in srgb,
var(--bg-dark) calc(var(--opening-veil, 1) * 100%),
transparent
);
}
#loading-screen.opening .loader-logo {
animation: none;
will-change: transform;
}
#loading-screen.opening .loader-logo svg {
overflow: visible;
}
#loading-screen.opening .loader-logo svg > path {
transform-box: fill-box;
transform-origin: center;
}
#loading-screen.opening h2,
#loading-screen.opening .loader-status {
animation: none;
opacity: var(--opening-text, 1);
}
.loader-content h2 {
font-family: var(--font-mono);
font-size: 18px;