mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-24 04:02:19 +00:00
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.
This commit is contained in:
1 parent
f4d936989b
commit
c4a846b8ad
20 files changed
+679
-291
No files matched your search
@@ -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) |
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
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, a Stories link,
|
||||
reduced motion and `?intro=0` open as before. The address no longer follows
|
||||
the flight, so a reload during it reopens on the view it ends at (gekh,
|
||||
#1909).
|
||||
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).
|
||||
@@ -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
|
||||
|
||||
@@ -2,33 +2,38 @@
|
||||
// Writes src/data/homeCountries.js: each time zone's country, and where the
|
||||
// opening stops over that country.
|
||||
//
|
||||
// node scripts/build-home-countries.mjs [path/to/zone.tab]
|
||||
// node scripts/build-home-countries.mjs [zone.tab] [tzdata.zi]
|
||||
//
|
||||
// Zones come from tzdata's zone.tab (macOS and most Linux systems ship it at
|
||||
// /usr/share/zoneinfo/zone.tab), with the older names ICU still reports for
|
||||
// some of them (Asia/Calcutta for Asia/Kolkata): a browser may give either.
|
||||
// A country's point is the centroid of its largest part in the Natural Earth
|
||||
// countries pack (the contiguous United States, mainland France), or the
|
||||
// zone's own place where the pack has no such country.
|
||||
// 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 { geometryOf } from '../src/data/adminBoundaries.js';
|
||||
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 pack = JSON.parse(
|
||||
readFileSync(
|
||||
new URL('src/data/local_data/natural_earth/countries.json', root),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
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+)([+-]\d+)$/);
|
||||
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);
|
||||
@@ -37,16 +42,10 @@ function iso6709(text) {
|
||||
const sec = Number(d.slice(degreeDigits + 2) || 0);
|
||||
return sign * (deg + min / 60 + sec / 3600);
|
||||
};
|
||||
return [part(lat, 2), part(lon, 3)];
|
||||
}
|
||||
|
||||
const largest = new Map();
|
||||
for (const feature of pack.features) {
|
||||
if (feature.type !== 'Country' || !/^[A-Z]{2}$/.test(feature.iso2)) continue;
|
||||
const geometry = geometryOf({ feature, decimals: pack.meta.decimals });
|
||||
const held = largest.get(feature.iso2);
|
||||
if (!held || geometry.areaKm2 > held.areaKm2)
|
||||
largest.set(feature.iso2, geometry);
|
||||
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();
|
||||
@@ -62,32 +61,50 @@ const icuName = (zone) => {
|
||||
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 label = largest.get(country)?.label;
|
||||
const entry = countryByCode(country);
|
||||
const point = entry ? countryAnchor(entry) : null;
|
||||
centres.set(
|
||||
country,
|
||||
label ? [round(label.lat), round(label.lon)] : iso6709(place).map(round),
|
||||
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 (public domain) and the Natural Earth countries',
|
||||
'// pack in src/data/local_data/natural_earth (public domain).',
|
||||
'// 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]: the centroid of its largest part. */',
|
||||
"/** 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 and ICU names) → ISO 3166 country. */',
|
||||
'/** Time zone (tzdata, ICU and older names) → ISO 3166 country. */',
|
||||
'export const ZONE_COUNTRIES = {',
|
||||
...sortedEntries(zones).map(
|
||||
([zone, country]) => ` '${zone}': '${country}',`,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
+152
-166
@@ -1,15 +1,12 @@
|
||||
import { START_VIEW } from '../camera.js';
|
||||
import { cameraOf } from '../render/rendererOf.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. The words fade and the logo glides to the centre. The
|
||||
* screen is then shut but for the empty circle inside the eye's ring, which
|
||||
* flies at the viewer and opens onto the application as it grows past the
|
||||
* screen's edges. The drawn planet in the pupil (its blue disc) gives way to
|
||||
* the real one, drawn the same size behind it, which grows to the whole
|
||||
* planet's size, turns there to a stop over the start view (the visitor's
|
||||
* country), and only then closes in on a closer view a link opened.
|
||||
* 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({
|
||||
@@ -20,15 +17,14 @@ export const OPENING = Object.freeze({
|
||||
// The rest is timed from the end of the move.
|
||||
/** The eye grows past the screen's edges. */
|
||||
eyeMs: 1100,
|
||||
/** Without the logo's own parts (an <img>): the background clears. */
|
||||
veilMs: Object.freeze([200, 700]),
|
||||
/** The drawn planet fades into the real one. */
|
||||
pupilMs: Object.freeze([600, 1200]),
|
||||
/** The camera's flight starts. */
|
||||
flightStartMs: 300,
|
||||
/** The globe grows to the whole planet's size. */
|
||||
zoomMs: 1600,
|
||||
/** It turns there, slowing to a stop over the start view. */
|
||||
/** 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: 2600,
|
||||
/** Then the camera closes in on a closer view (a shared one), per tenfold
|
||||
* change of height, within `approachMs`. */
|
||||
@@ -39,10 +35,7 @@ export const OPENING = Object.freeze({
|
||||
});
|
||||
|
||||
const EARTH_RADIUS_M = 6371000;
|
||||
// logo.svg: its viewBox width, the drawn planet's radius (the blue disc) and
|
||||
// the eye's centre, in its units.
|
||||
const LOGO_WIDTH = 775;
|
||||
const PUPIL_RADIUS = 195;
|
||||
// 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. */
|
||||
@@ -72,19 +65,18 @@ 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.
|
||||
* @param {number} t
|
||||
*/
|
||||
export function openingStage(t, timing = OPENING, flightMs = flightLength()) {
|
||||
const move = clamp01(t / timing.centreMs);
|
||||
const after = t - timing.centreMs;
|
||||
const eye = clamp01(after / timing.eyeMs);
|
||||
const flight = clamp01((after - timing.flightStartMs) / flightMs);
|
||||
/** 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 / timing.textMs),
|
||||
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. */
|
||||
@@ -94,72 +86,58 @@ export function openingStage(t, timing = OPENING, flightMs = flightLength()) {
|
||||
/** 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]),
|
||||
eyeOpen: eye >= 1,
|
||||
/** The background's opacity where the logo is an <img>. */
|
||||
veil: 1 - span(after, timing.veilMs),
|
||||
pupilOpacity: 1 - span(after, timing.pupilMs),
|
||||
/** The flight's progress, 0–1. */
|
||||
flight,
|
||||
done: flight >= 1,
|
||||
pupilOpacity: 1 - span(after, OPENING.pupilMs),
|
||||
};
|
||||
}
|
||||
|
||||
/** How long the flight takes, ms, for a closing-in of `decades` (log10). */
|
||||
function flightLength(decades = 0, turns = false, timing = OPENING) {
|
||||
const [shortest, longest] = timing.approachMs;
|
||||
const approach =
|
||||
decades > 0.05 || turns
|
||||
? Math.min(
|
||||
longest,
|
||||
Math.max(shortest, decades * timing.approachPerDecadeMs),
|
||||
)
|
||||
: 0;
|
||||
return timing.zoomMs + timing.spinMs + approach;
|
||||
}
|
||||
|
||||
/**
|
||||
* The camera's flight in, from `farHeight` over the equator, looking straight
|
||||
* down. The globe first grows to the whole planet's size (`planetHeight`, or
|
||||
* `target.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 and pitch (radians) on the way.
|
||||
* Returns its length, ms, and its pose `ms` into it.
|
||||
* 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,
|
||||
planetHeight = PLANET_HEIGHT_M,
|
||||
timing = OPENING,
|
||||
}) {
|
||||
const heading = target.heading ?? 0;
|
||||
// The short way round to the target's heading.
|
||||
const headingTo = heading - 2 * Math.PI * Math.round(heading / (2 * Math.PI));
|
||||
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(pitchTo + Math.PI / 2) > 1e-3;
|
||||
const planet = Math.max(planetHeight, target.height);
|
||||
const decades = Math.log10(planet / target.height);
|
||||
const ms = flightLength(decades, turns, timing);
|
||||
const approachMs = ms - timing.zoomMs - timing.spinMs;
|
||||
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, while the drawn planet has
|
||||
// given way to the real one.
|
||||
const spinFrom = timing.zoomMs / 2;
|
||||
const spinLength = timing.zoomMs + timing.spinMs - spinFrom;
|
||||
// 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 / timing.zoomMs));
|
||||
const zoom = smoothstep(clamp01(t / OPENING.zoomMs));
|
||||
const spin = easeOutCubic(clamp01((t - spinFrom) / spinLength));
|
||||
const approach = approachMs
|
||||
? clamp01((t - timing.zoomMs - timing.spinMs) / approachMs)
|
||||
? clamp01((t - OPENING.zoomMs - OPENING.spinMs) / approachMs)
|
||||
: 0;
|
||||
const turning = easeInOutCubic(approach);
|
||||
const lon = target.lon + timing.spinDeg * (1 - spin);
|
||||
return {
|
||||
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
|
||||
lon: normalizeCameraLongitude(
|
||||
target.lon + OPENING.spinDeg * (1 - spin),
|
||||
),
|
||||
lat: target.lat * spin,
|
||||
height:
|
||||
approach > 0
|
||||
@@ -167,6 +145,7 @@ export function openingFlight({
|
||||
: logLerp(farHeight, planet, zoom),
|
||||
heading: headingTo * turning,
|
||||
pitch: -Math.PI / 2 + (pitchTo + Math.PI / 2) * turning,
|
||||
roll: rollTo * turning,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -193,7 +172,7 @@ export function heightForGlobeRadius(radiusPx, { fovy, viewportHeight }) {
|
||||
* its window (the empty circle inside its ring, `windowRadius` pixels) to
|
||||
* reach past the view's corners.
|
||||
*/
|
||||
export function eyeCoverScale(windowRadius, view) {
|
||||
function eyeCoverScale(windowRadius, view) {
|
||||
return (
|
||||
(WINDOW_COVER_MARGIN * Math.hypot(view.width, view.height)) /
|
||||
2 /
|
||||
@@ -207,9 +186,7 @@ export function eyeCoverScale(windowRadius, view) {
|
||||
* 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, loadingScreen, win) {
|
||||
const colour =
|
||||
win.getComputedStyle?.(loadingScreen).backgroundColor || '#000';
|
||||
function eyeShutter(eye) {
|
||||
const far = 1e5;
|
||||
// Centred where the eye grows from, so the two grow as one.
|
||||
const { x, y } = EYE_CENTRE;
|
||||
@@ -223,7 +200,7 @@ function eyeShutter(eye, loadingScreen, win) {
|
||||
`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.setAttribute('fill', colour);
|
||||
shutter.style.fill = 'var(--bg-dark)';
|
||||
shutter.setAttribute('fill-rule', 'evenodd');
|
||||
shutter.dataset.openingShutter = '';
|
||||
eye.parentNode.insertBefore(shutter, eye.parentNode.firstElementChild);
|
||||
@@ -232,12 +209,15 @@ function eyeShutter(eye, loadingScreen, win) {
|
||||
|
||||
/**
|
||||
* Whether the page opens with the opening: not where motion is reduced, not
|
||||
* on a Stories link (Stories opens its own view) and not with `?intro=0`.
|
||||
* 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' ||
|
||||
@@ -249,10 +229,12 @@ export function openingWanted(win = globalThis.window) {
|
||||
/**
|
||||
* 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, as for a camera held in a target's frame; else `done`, which settles
|
||||
* when the camera has stopped, and `cancel()`. A click, a key 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.
|
||||
* 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.
|
||||
*/
|
||||
@@ -263,15 +245,12 @@ export function playOpeningIntro({
|
||||
camera = null,
|
||||
}) {
|
||||
if (!openingWanted(win)) return null;
|
||||
try {
|
||||
camera ??= cameraOf(viewer);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
camera ??= findCamera(viewer);
|
||||
if (!camera) return null;
|
||||
const target = camera.pose();
|
||||
if (
|
||||
target?.frameIsIdentity === false ||
|
||||
!Number.isFinite(target?.height) ||
|
||||
!Number.isFinite(target.height) ||
|
||||
target.height <= 0 ||
|
||||
!Number.isFinite(target.lon) ||
|
||||
!Number.isFinite(target.lat)
|
||||
)
|
||||
@@ -279,51 +258,48 @@ export function playOpeningIntro({
|
||||
const doc = loadingScreen.ownerDocument;
|
||||
const logo = loadingScreen.querySelector('.loader-logo');
|
||||
const svg = logo?.querySelector('svg');
|
||||
const part = (id) => svg?.querySelector(`#${id}`);
|
||||
const eye = part('outer_eye');
|
||||
// The drawn planet: its blue disc, continents and grid; the whole logo
|
||||
// where it is an <img>.
|
||||
const disc = part('inner_eye');
|
||||
const pupil = svg
|
||||
? [disc, part('globe'), part('globe_cage')].filter(Boolean)
|
||||
: [logo].filter(Boolean);
|
||||
const shutter = eye ? eyeShutter(eye, loadingScreen, win) : null;
|
||||
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;
|
||||
// The planet looks out of the middle of the eye again.
|
||||
// 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 ?? logo)?.getBoundingClientRect();
|
||||
const eyeRect = eye?.getBoundingClientRect();
|
||||
const pupilRect = disc.getBoundingClientRect();
|
||||
const eyeRect = eye.getBoundingClientRect();
|
||||
const view = (
|
||||
doc.getElementById('cesiumContainer') ?? doc.documentElement
|
||||
).getBoundingClientRect();
|
||||
const viewportHeight = view.height || win.innerHeight;
|
||||
const aspect = (view.width || win.innerWidth) / viewportHeight;
|
||||
// Cesium's default lens: 60° across the wider side.
|
||||
const fovy = Number.isFinite(target.fovy)
|
||||
? target.fovy
|
||||
: aspect > 1
|
||||
? 2 * Math.atan(Math.tan(Math.PI / 6) / aspect)
|
||||
: Math.PI / 3;
|
||||
const lens = { fovy, viewportHeight };
|
||||
const pupilRadius = pupilRect
|
||||
? disc
|
||||
? pupilRect.width / 2
|
||||
: (pupilRect.width * PUPIL_RADIUS) / LOGO_WIDTH
|
||||
: 32;
|
||||
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 = pupilRect
|
||||
? {
|
||||
x: view.left + view.width / 2 - (pupilRect.left + pupilRect.width / 2),
|
||||
y: view.top + view.height / 2 - (pupilRect.top + pupilRect.height / 2),
|
||||
}
|
||||
: { x: 0, y: 0 };
|
||||
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);
|
||||
const eyeCover = eyeRect?.width
|
||||
// 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,
|
||||
@@ -331,16 +307,28 @@ export function playOpeningIntro({
|
||||
: 1;
|
||||
|
||||
let driving = false;
|
||||
const place = ({ lon, lat, height, heading, pitch }) => {
|
||||
/** 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: 0 },
|
||||
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;
|
||||
@@ -350,11 +338,10 @@ export function playOpeningIntro({
|
||||
let frame = 0;
|
||||
let finished = false;
|
||||
const hide = () => loadingScreen.classList.add('hidden');
|
||||
const stopCommands = camera.onCommand?.(() => {
|
||||
const stopCommands = camera.onCommand(() => {
|
||||
if (!driving) finish();
|
||||
});
|
||||
const inputs = ['pointerdown', 'wheel', 'keydown', 'touchstart'];
|
||||
// The person's own input skips to the end; another camera move stops it.
|
||||
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 });
|
||||
@@ -363,20 +350,16 @@ export function playOpeningIntro({
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
playing -= 1;
|
||||
if (frame) win.cancelAnimationFrame(frame);
|
||||
stopCommands?.();
|
||||
for (const type of inputs)
|
||||
win.removeEventListener(type, onInput, { capture: true });
|
||||
if (land)
|
||||
place({
|
||||
lon: target.lon,
|
||||
lat: target.lat,
|
||||
height: target.height,
|
||||
heading: target.heading ?? 0,
|
||||
pitch: target.pitch ?? -Math.PI / 2,
|
||||
});
|
||||
hide();
|
||||
resolveDone();
|
||||
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 });
|
||||
@@ -384,40 +367,43 @@ export function playOpeningIntro({
|
||||
const step = () => {
|
||||
frame = 0;
|
||||
if (finished) return;
|
||||
const stage = openingStage(
|
||||
win.performance.now() - start,
|
||||
OPENING,
|
||||
flight.ms,
|
||||
);
|
||||
if (stage.done) {
|
||||
finish({ land: true });
|
||||
return;
|
||||
}
|
||||
const pose = flight.pose(stage.flight * flight.ms);
|
||||
place(pose);
|
||||
const scale = globeRadiusPx(pose.height, lens) / startRadius;
|
||||
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',
|
||||
shutter ? (stage.shut ? 0 : 1) : stage.veil,
|
||||
);
|
||||
if (logo)
|
||||
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})`;
|
||||
if (eye) {
|
||||
const eyeScale = `scale(${1 + (eyeCover - 1) * stage.eyeGrowth})`;
|
||||
eye.style.transform = eyeScale;
|
||||
eye.style.opacity = stage.eyeOpacity;
|
||||
}
|
||||
if (shutter) {
|
||||
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;
|
||||
}
|
||||
for (const element of pupil) element.style.opacity = stage.pupilOpacity;
|
||||
if (stage.pupilOpacity === 0 && (stage.eyeOpen || !shutter)) hide();
|
||||
frame = win.requestAnimationFrame(step);
|
||||
};
|
||||
step();
|
||||
return { done, cancel: () => finish() };
|
||||
|
||||
+155
-30
@@ -3,7 +3,6 @@ import assert from 'node:assert/strict';
|
||||
import { Window } from 'happy-dom';
|
||||
import {
|
||||
OPENING,
|
||||
eyeCoverScale,
|
||||
globeRadiusPx,
|
||||
heightForGlobeRadius,
|
||||
openingFlight,
|
||||
@@ -17,14 +16,12 @@ 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;
|
||||
const END_MS = OPENING.centreMs + OPENING.flightStartMs + PLANET_FLIGHT_MS + 1;
|
||||
|
||||
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(start.flight, 0);
|
||||
assert.equal(openingStage(OPENING.textMs).text, 0, 'the words go first');
|
||||
assert.ok(openingStage(OPENING.textMs).centre < 0.5);
|
||||
const centred = openingStage(OPENING.centreMs);
|
||||
@@ -37,25 +34,10 @@ test('the words fade, then the eye opens past the screen before the globe arrive
|
||||
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.eyeOpen, true);
|
||||
assert.equal(open.eyeOpacity, 0);
|
||||
assert.equal(open.shutterOpacity, 0);
|
||||
const real = openingStage(OPENING.centreMs + OPENING.pupilMs[1]);
|
||||
assert.equal(real.pupilOpacity, 0);
|
||||
assert.ok(real.flight > 0 && real.flight < 1);
|
||||
assert.equal(openingStage(END_MS).done, true);
|
||||
});
|
||||
|
||||
test("the eye's window reaches past the corners of any screen", () => {
|
||||
const radius = 40;
|
||||
for (const view of [
|
||||
{ width: 1280, height: 720 },
|
||||
{ width: 375, height: 812 },
|
||||
{ width: 3840, height: 1600 },
|
||||
]) {
|
||||
const scale = eyeCoverScale(radius, view);
|
||||
assert.ok(radius * scale > Math.hypot(view.width, view.height) / 2);
|
||||
}
|
||||
});
|
||||
|
||||
const FAR = 4e8;
|
||||
@@ -138,7 +120,7 @@ test('the far start draws the globe the size of the pupil', () => {
|
||||
assert.ok(globeRadiusPx(4e8, LENS) < globeRadiusPx(23e6, LENS));
|
||||
});
|
||||
|
||||
test('reduced motion, Stories links and ?intro=0 open without it', () => {
|
||||
test('reduced motion, embedded views, Stories links and ?intro=0 open without it', () => {
|
||||
const win = (search, reduced = false) => ({
|
||||
location: { search },
|
||||
matchMedia: () => ({ matches: reduced }),
|
||||
@@ -149,20 +131,48 @@ test('reduced motion, Stories links and ?intro=0 open without it', () => {
|
||||
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() {
|
||||
const window = new Window({ width: 1280, height: 800 });
|
||||
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"/>
|
||||
<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;
|
||||
@@ -173,10 +183,15 @@ function stage() {
|
||||
window.matchMedia = () => ({ matches: false });
|
||||
const views = [];
|
||||
const commandListeners = new Set();
|
||||
let current = { ...target, fovy };
|
||||
const camera = {
|
||||
pose: () => ({ ...TARGET, fovy: Math.PI / 4 }),
|
||||
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) {
|
||||
@@ -190,6 +205,8 @@ function stage() {
|
||||
views,
|
||||
camera,
|
||||
commandListeners,
|
||||
doc,
|
||||
current: () => current,
|
||||
play: () =>
|
||||
playOpeningIntro({
|
||||
viewer: {},
|
||||
@@ -203,6 +220,9 @@ function stage() {
|
||||
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' });
|
||||
},
|
||||
@@ -238,13 +258,6 @@ test('the opening runs to the start view, then hides the cover', async () => {
|
||||
assert.equal(s.commandListeners.size, 0);
|
||||
});
|
||||
|
||||
test('a camera held in a target frame plays no opening', () => {
|
||||
const s = stage();
|
||||
s.camera.pose = () => ({ ...TARGET, frameIsIdentity: false });
|
||||
assert.equal(s.play(), null);
|
||||
assert.ok(!s.screen.classList.contains('opening'));
|
||||
});
|
||||
|
||||
test("the person's input skips to the start view", async () => {
|
||||
const s = stage();
|
||||
const opening = s.play();
|
||||
@@ -267,3 +280,115 @@ test('another camera move stops it where it is', async () => {
|
||||
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);
|
||||
s.advance(1800);
|
||||
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;
|
||||
});
|
||||
+45
-12
@@ -2,7 +2,8 @@ import { initFirstRunExperience } from '../firstRunExperience.js';
|
||||
|
||||
/**
|
||||
* Reveal welcome controls only after restoration and the loading transition.
|
||||
* `playOpening` plays the opening on a bare address (src/app/openingIntro.js).
|
||||
* `playOpening` plays the opening (src/app/openingIntro.js) on a bare address
|
||||
* or a share of only a view.
|
||||
*/
|
||||
export function startApplicationChrome({
|
||||
loadingScreen,
|
||||
@@ -22,12 +23,23 @@ export function startApplicationChrome({
|
||||
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. */
|
||||
@@ -35,31 +47,52 @@ export function startApplicationChrome({
|
||||
.then(([restored] = []) => {
|
||||
if (disposed || signal.aborted) return;
|
||||
// A bare address, or a share of only a view, opens with the opening
|
||||
// (it ends where the camera stands); welcome waits for its end. Its
|
||||
// frames stay out of the address, held before the first one: a reload
|
||||
// or a copied link mid-flight would open on a speck of a planet.
|
||||
// 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');
|
||||
opening = wanted
|
||||
? playOpening({ viewer: styleManager.viewer, loadingScreen })
|
||||
: null;
|
||||
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();
|
||||
revealFirstRun();
|
||||
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 }),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Generated by scripts/build-home-countries.mjs. Do not edit by hand.
|
||||
// Sources: tzdata zone.tab (public domain) and the Natural Earth countries
|
||||
// pack in src/data/local_data/natural_earth (public domain).
|
||||
// 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]: the centroid of its largest part. */
|
||||
/** 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],
|
||||
@@ -104,7 +104,7 @@ export const COUNTRY_CENTRES = {
|
||||
HU: [47.2, 19.4],
|
||||
ID: [-0.2, 114],
|
||||
IE: [53.2, -8.1],
|
||||
IL: [31.4, 35],
|
||||
IL: [31.4, 34.7],
|
||||
IM: [54.2, -4.5],
|
||||
IN: [22.9, 79.6],
|
||||
IO: [-7.3, 72.4],
|
||||
@@ -242,7 +242,7 @@ export const COUNTRY_CENTRES = {
|
||||
VE: [7.1, -66.2],
|
||||
VG: [18.4, -64.6],
|
||||
VI: [17.7, -64.8],
|
||||
VN: [16.7, 106.3],
|
||||
VN: [16, 107.9],
|
||||
VU: [-15.2, 166.9],
|
||||
WF: [-13.3, -176.2],
|
||||
WS: [-13.6, -172.4],
|
||||
@@ -253,7 +253,7 @@ export const COUNTRY_CENTRES = {
|
||||
ZW: [-19, 29.9],
|
||||
};
|
||||
|
||||
/** Time zone (tzdata and ICU names) → ISO 3166 country. */
|
||||
/** Time zone (tzdata, ICU and older names) → ISO 3166 country. */
|
||||
export const ZONE_COUNTRIES = {
|
||||
'Africa/Abidjan': 'CI',
|
||||
'Africa/Accra': 'GH',
|
||||
@@ -305,6 +305,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Africa/Ouagadougou': 'BF',
|
||||
'Africa/Porto-Novo': 'BJ',
|
||||
'Africa/Sao_Tome': 'ST',
|
||||
'Africa/Timbuktu': 'ML',
|
||||
'Africa/Tripoli': 'LY',
|
||||
'Africa/Tunis': 'TN',
|
||||
'Africa/Windhoek': 'NA',
|
||||
@@ -315,6 +316,7 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -328,6 +330,7 @@ export const ZONE_COUNTRIES = {
|
||||
'America/Aruba': 'AW',
|
||||
'America/Asuncion': 'PY',
|
||||
'America/Atikokan': 'CA',
|
||||
'America/Atka': 'US',
|
||||
'America/Bahia': 'BR',
|
||||
'America/Bahia_Banderas': 'MX',
|
||||
'America/Barbados': 'BB',
|
||||
@@ -364,7 +367,9 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -394,6 +399,7 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -416,9 +422,11 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -427,23 +435,29 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -454,13 +468,16 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -469,6 +486,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Antarctica/McMurdo': 'AQ',
|
||||
'Antarctica/Palmer': 'AQ',
|
||||
'Antarctica/Rothera': 'AQ',
|
||||
'Antarctica/South_Pole': 'AQ',
|
||||
'Antarctica/Syowa': 'AQ',
|
||||
'Antarctica/Troll': 'AQ',
|
||||
'Antarctica/Vostok': 'AQ',
|
||||
@@ -480,6 +498,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Asia/Aqtau': 'KZ',
|
||||
'Asia/Aqtobe': 'KZ',
|
||||
'Asia/Ashgabat': 'TM',
|
||||
'Asia/Ashkhabad': 'TM',
|
||||
'Asia/Atyrau': 'KZ',
|
||||
'Asia/Baghdad': 'IQ',
|
||||
'Asia/Bahrain': 'BH',
|
||||
@@ -491,7 +510,11 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -499,17 +522,20 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -518,6 +544,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Asia/Kuala_Lumpur': 'MY',
|
||||
'Asia/Kuching': 'MY',
|
||||
'Asia/Kuwait': 'KW',
|
||||
'Asia/Macao': 'MO',
|
||||
'Asia/Macau': 'MO',
|
||||
'Asia/Magadan': 'RU',
|
||||
'Asia/Makassar': 'ID',
|
||||
@@ -547,10 +574,14 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -565,26 +596,54 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -615,6 +674,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Europe/Minsk': 'BY',
|
||||
'Europe/Monaco': 'MC',
|
||||
'Europe/Moscow': 'RU',
|
||||
'Europe/Nicosia': 'CY',
|
||||
'Europe/Oslo': 'NO',
|
||||
'Europe/Paris': 'FR',
|
||||
'Europe/Podgorica': 'ME',
|
||||
@@ -631,7 +691,9 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -639,6 +701,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Europe/Volgograd': 'RU',
|
||||
'Europe/Warsaw': 'PL',
|
||||
'Europe/Zagreb': 'HR',
|
||||
'Europe/Zaporozhye': 'UA',
|
||||
'Europe/Zurich': 'CH',
|
||||
'Indian/Antananarivo': 'MG',
|
||||
'Indian/Chagos': 'IO',
|
||||
@@ -651,6 +714,9 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
@@ -667,6 +733,7 @@ export const ZONE_COUNTRIES = {
|
||||
'Pacific/Guadalcanal': 'SB',
|
||||
'Pacific/Guam': 'GU',
|
||||
'Pacific/Honolulu': 'US',
|
||||
'Pacific/Johnston': 'US',
|
||||
'Pacific/Kanton': 'KI',
|
||||
'Pacific/Kiritimati': 'KI',
|
||||
'Pacific/Kosrae': 'FM',
|
||||
@@ -686,10 +753,24 @@ export const ZONE_COUNTRIES = {
|
||||
'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',
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
+6
-8
@@ -22,17 +22,15 @@ export function homeCountry({
|
||||
}
|
||||
|
||||
/**
|
||||
* The start view over the visitor's country: the planet from `base.height`,
|
||||
* looking straight down on the country's centre. `base` where the country is
|
||||
* unknown.
|
||||
* @param {{timeZone?: string|null, languages?: readonly string[],
|
||||
* base?: {lon: number, lat: number, height: number}}} [where]
|
||||
* 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({ base = START_VIEW, ...where } = {}) {
|
||||
export function homeCountryView(where = {}) {
|
||||
const centre = COUNTRY_CENTRES[homeCountry(where)];
|
||||
if (!centre) return base;
|
||||
if (!centre) return START_VIEW;
|
||||
const [lat, lon] = centre;
|
||||
return Object.freeze({ lon, lat, height: base.height });
|
||||
return Object.freeze({ lon, lat, height: START_VIEW.height });
|
||||
}
|
||||
|
||||
function currentTimeZone() {
|
||||
|
||||
@@ -4,10 +4,18 @@ 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 or ICU name', () => {
|
||||
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'] }),
|
||||
|
||||
+8
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -541,9 +541,7 @@ test('a copied link carries the Data Library selection to a clean recipient', (t
|
||||
sharer.setLibraryParamsEncoder((params) => params.set('lib', '03.0a'));
|
||||
const code = new URL(sharer.buildLink()).pathname.split('/').at(-1);
|
||||
sharer.destroy();
|
||||
const opener = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()), {
|
||||
initialShareCode: code,
|
||||
});
|
||||
const opener = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()), { initialShareCode: code });
|
||||
assert.deepEqual(opener.parseInitialHash().library, ['03', '0a']);
|
||||
assert.deepEqual(opener.initialLibraryTokens, ['03', '0a']);
|
||||
opener.destroy();
|
||||
|
||||
@@ -1,10 +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: playOpeningIntro,
|
||||
playOpening: streetLevel ? null : playOpeningIntro,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -10,7 +10,12 @@ const source = readFileSync(
|
||||
.replace(/^import .*;\n/gm, '')
|
||||
.replace('export function', 'function');
|
||||
|
||||
function fixture({ playOpening, hasShareState = false, shareLink } = {}) {
|
||||
function fixture({
|
||||
playOpening,
|
||||
hasShareState = false,
|
||||
shareLink,
|
||||
navigationGeneration,
|
||||
} = {}) {
|
||||
const timers = new Map();
|
||||
const listeners = new Map();
|
||||
const events = [];
|
||||
@@ -37,6 +42,15 @@ function fixture({ playOpening, hasShareState = false, shareLink } = {}) {
|
||||
};
|
||||
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: {
|
||||
@@ -45,19 +59,13 @@ function fixture({ playOpening, hasShareState = false, shareLink } = {}) {
|
||||
removeEventListener: (type) => listeners.delete(type),
|
||||
},
|
||||
playOpening,
|
||||
styleManager: {
|
||||
hasShareState,
|
||||
viewer: 'viewer',
|
||||
shareLinkManager: shareLink,
|
||||
initialRestorePromise: new Promise((resolve) => {
|
||||
restored = resolve;
|
||||
}),
|
||||
},
|
||||
styleManager,
|
||||
dataManager: {},
|
||||
signal: controller.signal,
|
||||
});
|
||||
return {
|
||||
events,
|
||||
styleManager,
|
||||
listeners,
|
||||
stop,
|
||||
restored,
|
||||
@@ -157,6 +165,7 @@ test('a bare address plays the opening, and welcome waits for its end', async ()
|
||||
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']);
|
||||
@@ -230,23 +239,77 @@ for (const [name, restored] of [
|
||||
['a failed restore', { status: 'failed' }],
|
||||
]) {
|
||||
test(`a link to ${name} opens without the opening`, async () => {
|
||||
const events = [];
|
||||
const opening = openingStub(events);
|
||||
const f = fixture({ playOpening: opening.play, hasShareState: true });
|
||||
f.restored(restored);
|
||||
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, 0);
|
||||
assert.deepEqual(f.events, ['hidden']);
|
||||
assert.equal(opening.calls.length, plays);
|
||||
if (!plays) assert.deepEqual(f.events, ['hidden']);
|
||||
await f.stop();
|
||||
});
|
||||
}
|
||||
|
||||
test('without an opening to play the cover hides as before', async () => {
|
||||
const f = fixture({ playOpening: () => null });
|
||||
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.deepEqual(f.events, ['hidden']);
|
||||
assert.ok(!f.events.includes('welcome'));
|
||||
f.fire(900);
|
||||
assert.ok(f.events.includes('welcome'));
|
||||
await f.stop();
|
||||
});
|
||||
@@ -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(
|
||||
|
||||
@@ -431,7 +431,7 @@ html:not([lang='en']):not(:lang(zh)):not(:lang(ja))
|
||||
}
|
||||
}
|
||||
|
||||
/* The opening (src/app/openingIntro.js) sets these each frame. */
|
||||
/* The opening (src/app/openingIntro.js) sets --opening-veil and --opening-text each frame. */
|
||||
#loading-screen.opening {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
|
||||
Reference in new issue
Block a user