Stories: phone entry, centred framing, review follow-ups

- On GEV's phone layout, where neither the style readout nor the account
  avatar shows, the Stories button goes icon-only under the corner-actions
  column instead of covering the top row of icon buttons.
- Explore frames its start view and a picked story in the middle of the
  map it leaves visible (beside the feed, above the phone sheet), with one
  short correction if that area moved during the flight.
- The share icon stays visible in icon-only header buttons.
- A world clock nothing moved while Stories was open (no jump, same mode
  and rate) is left alone on Close.
- Card images use the globe's own Esri tile URL; the credit list keeps the
  application's full-screen placement on phones.
- Tests cover the live and playing clock restores, the clock coming back
  after the share state, the tile-settling hold being released (settled,
  10 s, Close), the visible-map aim, and the near-end Play fix in the
  director's real order. One changelog fragment covers the PR.
This commit is contained in:
Manjunath committed 2026-11-16 21:08:23 +05:30
1 parent 8a0953c35d
commit 472cc35c47
13 files changed
+351 -38

No files matched your search

+2 -1
View File
@@ -15,7 +15,8 @@
import { findFrame, findGlobe, rendererOf } from '../render/rendererOf.js';
import { KEYLESS_TERRAIN_URL } from './keylessTerrain.js';
const ESRI_TILES =
/** Esri World Imagery's tiles; Stories' card images draw from the same. */
export const ESRI_TILES =
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
const ESRI_CREDIT =
'Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community';
+83 -11
View File
@@ -1,4 +1,4 @@
import { markRaw, toRaw } from 'vue';
import { markRaw, nextTick, toRaw } from 'vue';
import { t } from '../i18n/index.js';
import {
governorRequestRender,
@@ -275,6 +275,7 @@ export function createStoriesController({
playing: world.playing,
rate: world.rate,
stepping: world.stepping,
jumps: world.jumps,
},
openedAt: Date.now(),
// Story history entries have no hash. Capture the live globe state.
@@ -306,13 +307,25 @@ export function createStoriesController({
/**
* The world clock as the person left it: live stays live, and a playing
* clock carries on as if Stories had never paused it. A clock still where
* it should be is left alone, so its layers see no jump.
* clock carries on as if Stories had never paused it. A clock nothing
* moved while Stories was open (no jump, same mode and rate) is left
* alone, so its layers see no jump.
*/
function restoreClock(saved) {
const was = saved?.clock;
if (!was) return;
const now = clock.getState();
// Nothing moved it while Stories was open (no jump, same mode and
// rate): a clock playing at its own pace, held by buffering or stepped
// by a driver, is left as it is.
if (
Number.isFinite(was.jumps) &&
now.jumps === was.jumps &&
now.live === was.live &&
now.playing === was.playing &&
now.rate === was.rate
)
return;
if (was.live) {
if (!now.live) clock.goLive();
return;
@@ -502,18 +515,68 @@ export function createStoriesController({
holdContinuousRender('stories-tiles');
tilesTimer = setTimeout(stopSettling, 10000);
}
function flyTo({ lat, lon, alt }, duration = 1.6) {
/**
* Where the map shows between Explore's own panels (the feed beside it on
* a wide screen, its sheet below it on a phone): how far, in pixels, that
* area's centre is from the canvas's, and the canvas height.
*/
function visibleOffset() {
const map = document
.querySelector('#gev-stories .ex-map')
?.getBoundingClientRect();
const view = canvas?.getBoundingClientRect?.();
if (!map?.width || !map?.height || !view?.height) return null;
return {
right: map.left + map.width / 2 - (view.left + view.width / 2),
up: view.top + view.height / 2 - (map.top + map.height / 2),
height: view.height,
};
}
/**
* The point to aim at so that (lat, lon) lands in the middle of the visible
* map rather than of the whole canvas, for a camera `distance` metres away
* looking down at `pitch` (radians) with heading north.
*/
function aimFor(lat, lon, distance, pitch, off = visibleOffset()) {
if (!off || (!off.right && !off.up)) return { lat, lon };
const fovy = camera()?.pose()?.fovy || Math.PI / 3;
const perPx = (2 * distance * Math.tan(fovy / 2)) / off.height;
const metresNorth = (off.up * perPx) / Math.max(0.2, Math.sin(-pitch));
const metresEast = off.right * perPx;
const cosLat = Math.max(0.05, Math.cos((lat * Math.PI) / 180));
return {
lat: Math.max(-89, Math.min(89, lat - metresNorth / 111320)),
lon: lon - metresEast / (111320 * cosLat),
};
}
// The visible map can still be settling while a flight runs (the phone
// sheet takes its height just after Explore opens): a flight that lands
// with the map moved by more than a few pixels makes one short correction.
const moved = (a, b) =>
!a !== !b ||
(a && (Math.abs(a.up - b.up) > 8 || Math.abs(a.right - b.right) > 8));
function flyTo(place, duration = 1.6, corrected = false) {
const { lat: lat0, lon: lon0, alt } = place;
// The whole globe straight down; a story's place at an angle, framed in
// the middle of the view rather than under the camera.
// the middle of the visible map rather than under the camera.
const port = camera();
if (!port) return;
if (alt > 2e6) {
const top = alt > 2e6;
const pitch = top ? -Math.PI / 2 : (-60 * Math.PI) / 180;
const off = visibleOffset();
const { lat, lon } = aimFor(lat0, lon0, alt, pitch, off);
const onComplete = () => {
if (!corrected && store.mode === 'explore' && moved(off, visibleOffset()))
return flyTo(place, 0.5, true);
settleTiles();
};
if (top) {
port.flyTo(
{ lon, lat, height: alt },
{
orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 },
orientation: { heading: 0, pitch, roll: 0 },
durationS: duration,
onComplete: settleTiles,
onComplete,
},
);
return;
@@ -521,9 +584,9 @@ export function createStoriesController({
port.flyToBounds(
{ center: fromDegrees(lon, lat), radius: 0 },
{
offset: { heading: 0, pitch: (-60 * Math.PI) / 180, range: alt },
offset: { heading: 0, pitch, range: alt },
durationS: duration,
onComplete: settleTiles,
onComplete,
},
);
}
@@ -743,7 +806,16 @@ export function createStoriesController({
// is back.
drawThumbs();
};
if (!saved?.ranScene) return frame();
// The aim centres the story in Explore's visible map, which is measured
// once Explore has rendered.
const root = document.getElementById('gev-stories');
const whenLaidOut = (run) =>
root && !root.querySelector('.ex-map')
? nextTick(() => {
if (entry === exploreEntry && store.mode === 'explore') run();
})
: run();
if (!saved?.ranScene) return whenLaidOut(frame);
// Back from a scene: once it has torn down, the person's own layers,
// style and clock come back before Explore frames the globe, as on
// Close. The address keeps naming only Stories' place.
+134 -1
View File
@@ -7,6 +7,8 @@ import assert from 'node:assert/strict';
import { createPinia, setActivePinia } from 'pinia';
import { createStateChannel } from '../app/stateChannel.js';
import { bindRenderer } from '../render/rendererOf.js';
import { getRenderGovernorDiagnostics } from '../renderGovernor.js';
const holds = () => getRenderGovernorDiagnostics().holds;
registerHooks({
load(url, context, next) {
@@ -110,16 +112,19 @@ function fakeClock(state = {}) {
playing: false,
rate: 1,
stepping: false,
jumps: 0,
...state,
},
getState: () => ({ ...clock.state }),
goLive() {
calls.push(['goLive']);
Object.assign(clock.state, { live: true, playing: false });
clock.state.jumps += 1;
},
seek(ms) {
calls.push(['seek', ms]);
Object.assign(clock.state, { live: false, timeMs: ms });
clock.state.jumps += 1;
},
pause() {
calls.push(['pause']);
@@ -1107,13 +1112,20 @@ test('Explore frames country level straight down, a picked story at −60°, and
globe.settled = true;
frame.draw();
assert.equal(frame.listeners.size, 1, 'settled: only the pins listen');
assert.ok(!holds().includes('stories-tiles'), 'settled: the hold is let go');
// ...and for 10 s at most.
globe.settled = false;
picked.onComplete();
assert.equal(frame.listeners.size, 2);
assert.ok(holds().includes('stories-tiles'), 'frames held while settling');
t.mock.timers.tick(10000);
assert.equal(frame.listeners.size, 1, 'given up after 10 s');
assert.ok(!holds().includes('stories-tiles'), 'given up: the hold is let go');
// Close lets go of a hold still waiting.
picked.onComplete();
assert.ok(holds().includes('stories-tiles'));
controller.destroy();
assert.ok(!holds().includes('stories-tiles'), 'closed: the hold is let go');
});
test('Close puts back the world clock the person had, and the camera readout follows a story', async () => {
@@ -1128,7 +1140,7 @@ test('Close puts back the world clock the person had, and the camera readout fol
frame.draw();
assert.deepEqual(store.camera, { lat: 28.65, lon: 11.46, altKm: 2000 });
// A scene moved the world clock.
clock.state = { ...clock.state, live: true };
clock.state = { ...clock.state, live: true, jumps: clock.state.jumps + 1 };
await controller.close();
assert.equal(camera.views.length, 1);
assert.deepEqual(clock.calls, [['pause'], ['seek', Date.UTC(2025, 5, 1)]]);
@@ -1139,3 +1151,124 @@ test('Close puts back the world clock the person had, and the camera readout fol
assert.deepEqual(clock.calls, []);
controller.destroy();
});
test('Close puts a live clock back live, and a playing clock plays on from where it would be', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout', 'Date'], now: 1_000_000 });
// Live: a scene seeked the clock; Close goes live again.
const live = fakeClock({ live: true });
const a = setup({ clock: live });
a.controller.open();
live.seek(Date.UTC(2020, 0, 1));
live.calls.length = 0;
const closingA = a.controller.close({ fromHistory: true });
t.mock.timers.tick(100);
await closingA;
assert.deepEqual(live.calls, [['goLive']]);
a.controller.destroy();
// Playing at 2×: paused by a scene; Close seeks to where it would be
// after the time Stories was open, and plays on at its rate.
const playing = fakeClock({
live: false,
playing: true,
rate: 2,
timeMs: Date.UTC(2025, 0, 1),
});
const b = setup({ clock: playing });
b.controller.open();
playing.pause();
playing.seek(Date.UTC(2019, 0, 1));
playing.calls.length = 0;
t.mock.timers.tick(5000);
const closingB = b.controller.close({ fromHistory: true });
t.mock.timers.tick(100);
await closingB;
const seek = playing.calls.find(([name]) => name === 'seek');
assert.ok(
Math.abs(seek[1] - (Date.UTC(2025, 0, 1) + 5100 * 2)) <= 200,
'extrapolated by the time away at its rate',
);
assert.deepEqual(playing.calls.at(-1), [
'play',
{ rate: 2, continuous: true },
]);
b.controller.destroy();
});
test('a playing clock nothing moved is left alone on Close, even if it fell behind', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout', 'Date'], now: 1_000_000 });
const clock = fakeClock({
live: false,
playing: true,
rate: 1,
timeMs: Date.UTC(2025, 0, 1),
});
const { controller } = setup({ clock });
controller.open();
// Held by buffering: no jump, same mode and rate, but behind the wall.
t.mock.timers.tick(30000);
const closing = controller.close({ fromHistory: true });
t.mock.timers.tick(100);
await closing;
assert.deepEqual(clock.calls, []);
controller.destroy();
});
test('the clock comes back after the share state on Close, so a shared paused time does not stop a playing clock', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout', 'Date'], now: 1_000_000 });
const clock = fakeClock({
live: false,
playing: true,
rate: 1,
timeMs: Date.UTC(2025, 0, 1),
});
const { controller, director } = setup({ clock });
// The share state arrives with its world time paused.
director.styleManager.shareLinkManager.restore = () => {
clock.pause();
clock.seek(Date.UTC(2025, 0, 1));
return true;
};
controller.open();
controller.openStory('gev:bhote-koshi-nepal-scene');
clock.pause();
const closing = controller.close({ fromHistory: true });
t.mock.timers.tick(100);
await closing;
assert.equal(clock.state.playing, true, 'playing again after the share');
controller.destroy();
});
test('Explore aims a story at the middle of the visible map, not of the canvas', () => {
const { controller, store, camera, canvas } = setup();
canvas.getBoundingClientRect = () => ({
left: 0,
top: 0,
width: 400,
height: 800,
});
// Explore's map is the top half of an 800 px canvas (a phone's sheet
// below it).
const root = document.createElement('div');
root.id = 'gev-stories';
const map = document.createElement('div');
map.className = 'ex-map';
root.append(map);
document.body.append(root);
map.getBoundingClientRect = () => ({
left: 0,
top: 0,
width: 400,
height: 400,
});
controller.open();
const story = store.stories[0];
controller.pick(null);
const flight = camera.flights.at(-1);
const { lat } = story.area ?? story.cover;
assert.ok(
flight.destination.lat < lat,
'aims south, so the story shows above the sheet',
);
root.remove();
controller.destroy();
});
+18 -5
View File
@@ -34,13 +34,26 @@ export function creditPlacement({ map, feed, width, height }) {
* Where the Stories button sits: just left of the leftmost visible control
* in GEV's top-right corner — the ACTIVE STYLE readout in GEV, the account
* avatar (with or beside the readout) in GEV Hosted — top-aligned with it.
* Where none of those shows (GEV's phone layout, whose top row of icon
* buttons spans the corner), it goes icon-only just under the right-hand
* column of corner actions, aligned with its right edge.
* @param {Array<DOMRect|null|undefined>} corner The corner controls' boxes.
* @param {number} width The window's width.
* @returns {{top: number, right: number}} Pixels from the top and right.
* @param {DOMRect|null} [column] The corner-actions column's box.
* @returns {{top: number, right: number, compact?: boolean}} Pixels from
* the top and right; `compact` for the icon-only button.
*/
export function entryPlacement(corner, width) {
export function entryPlacement(corner, width, column = null) {
const shown = corner.filter((r) => r && r.width > 0 && r.height > 0);
if (!shown.length) return { top: 14, right: 14 };
const left = shown.reduce((a, b) => (b.left < a.left ? b : a));
return { top: left.top, right: width - left.left + 10 };
if (shown.length) {
const left = shown.reduce((a, b) => (b.left < a.left ? b : a));
return { top: left.top, right: width - left.left + 10 };
}
if (column && column.width > 0 && column.height > 0)
return {
top: Math.round(column.bottom + 8),
right: Math.round(width - column.right),
compact: true,
};
return { top: 14, right: 14 };
}
+50 -2
View File
@@ -18,7 +18,12 @@ function deferredDirector({ running = false } = {}) {
running,
calls,
listShots: () => [{ id: 'a' }, { id: 'b' }],
subscribeSceneClock: () => () => {},
// The scene clock's listener, so a test can publish as the director
// does after a seek or at a run's end.
subscribeSceneClock: (fn) => {
director.publish = (snap) => fn({ sceneId: 'scene-1', ...snap });
return () => {};
},
stopScene: () => calls.push('stop'),
whenIdle() {
return new Promise((resolve) => {
@@ -114,7 +119,11 @@ test('Play from a paused link in the final quarter-second stays in the final sho
player.seek(59800); // 200 ms before the end of a two-shot scene
const playing = player.play();
await turns();
assert.equal(player.state.wallMs, 59800, 'the link is not treated as complete');
assert.equal(
player.state.wallMs,
59800,
'the link is not treated as complete',
);
assert.equal(director.startAfterShotId, 'a', 'resume in the final shot');
director.finishRun();
await playing;
@@ -141,3 +150,42 @@ test('Destroy cancels a waiting Play', async () => {
await playing;
assert.equal(director.calls.includes('start'), false);
});
test('in the director’s order, a paused link near the end resumes in its final shot', async () => {
const director = deferredDirector();
const player = createGevPlayer(director, story);
player.seek(59800);
// The director reports a seek as seeking, even once it has settled.
director.publish({
sceneDurationSec: 60,
sceneElapsedSec: 59.8,
shotIndex: 1,
running: false,
seeking: true,
});
assert.equal(player.state.wallMs, 59800, 'not rounded to the end');
const playing = player.play();
await turns();
assert.equal(director.startAfterShotId, 'a', 'resume in the final shot');
director.finishRun();
await playing;
});
test('a run that ends on its own is rounded to the end, and Play then starts over', async () => {
const director = deferredDirector();
const player = createGevPlayer(director, story);
// The director reports a run's natural end as stopped, not seeking.
director.publish({
sceneDurationSec: 60,
sceneElapsedSec: 59.9,
shotIndex: 1,
running: false,
});
assert.equal(player.state.wallMs, 60000, 'rounded to the end');
const playing = player.play();
await turns();
assert.equal(player.state.wallMs, 0);
assert.equal(director.startAfterShotId, null, 'from the first shot');
director.finishRun();
await playing;
});
+4 -3
View File
@@ -4,14 +4,15 @@
* the same tiles, from the same host, that GEV's Esri map draws (and credits
* on screen); no other host is asked.
*/
import { ESRI_TILES } from '../maps/globeEngine.js';
const WIDTH = 320;
const HEIGHT = 180;
const TILE_SIZE = 256;
const TILE_TRIES = 3;
/** Esri World Imagery's tiles: Web Mercator, as GEV's Esri map draws them. */
export const ESRI_TILE_URL =
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
/** Esri World Imagery's tiles: Web Mercator, the ones GEV's Esri map draws. */
export const ESRI_TILE_URL = ESRI_TILES;
const ESRI_MAX_LEVEL = 19;
/** A zoom level that frames `range` metres of view, within the imagery's. */
+11
View File
@@ -146,4 +146,15 @@ test('the Stories button sits left of whatever is in the top-right corner', () =
);
// Nothing there yet.
assert.deepEqual(entryPlacement([null, null], 1960), { top: 14, right: 14 });
// GEV's phone layout: no readout or avatar; icon-only under the corner
// actions column, aligned with its right edge.
assert.deepEqual(
entryPlacement([box(0, 0, 0, 0), null], 639, box(594, 60, 33, 70)),
{ top: 138, right: 12, compact: true },
);
// A visible readout still wins over the column.
assert.deepEqual(
entryPlacement([box(400, 24, 200, 40), null], 639, box(594, 60, 33, 70)),
{ top: 24, right: 249 },
);
});
+10
View File
@@ -241,3 +241,13 @@ body.ui-clean-view #gev-stories .gs-pop {
#gev-stories .gs-hosted-toast {
background: rgba(12, 12, 20, 0.95);
}
/* GEV's phone layout: icon-only, the size of the icon buttons beside it. */
#gev-stories .gs-entry.gs-entry-compact {
width: 36px;
padding: 0;
justify-content: center;
}
#gev-stories .gs-entry.gs-entry-compact span {
display: none;
}
+14 -6
View File
@@ -379,7 +379,7 @@
padding: 0;
justify-content: center;
}
#gev-stories .scr-story .s-head .h-right .tbtn span {
#gev-stories .scr-story .s-head .h-right .tbtn span:not(.share-icon) {
display: none;
}
}
@@ -3562,7 +3562,12 @@
border-radius: 50%;
border-color: var(--glass-border-hover);
}
#gev-stories #scrExplore .s-head .h-right .tbtn.hide-m:not(.accent) span {
#gev-stories
#scrExplore
.s-head
.h-right
.tbtn.hide-m:not(.accent)
span:not(.share-icon) {
display: none;
}
#gev-stories #scrExplore .s-head .h-right .tbtn.hide-m:not(.accent) svg {
@@ -3805,10 +3810,13 @@ body.stories-mode:not(#gs-a):not(#gs-b) #gev-credits {
bottom: var(--gs-credit-bottom, 36px) !important;
left: var(--gs-credit-left, 36px) !important;
}
/* The application's credit list opens just above its line, wherever that is. */
body.stories-mode:not(#gs-a):not(#gs-b) .gev-credits-panel {
bottom: calc(var(--gs-credit-bottom, 36px) + 24px);
left: var(--gs-credit-left, 36px);
/* The application's credit list opens just above its line, wherever that is;
on a phone it keeps the application's full-screen list. */
@media (min-width: 576px) {
body.stories-mode:not(#gs-a):not(#gs-b) .gev-credits-panel {
bottom: calc(var(--gs-credit-bottom, 36px) + 24px);
left: var(--gs-credit-left, 36px);
}
}
/* On a phone the line wraps and shrinks to stay on screen, as the phone
shell does outside recording mode. */
+7 -2
View File
@@ -39,11 +39,14 @@ const reduceMotion = () =>
// GEV has its ACTIVE STYLE readout there; GEV Hosted adds the account
// avatar, which can come after Stories mounts (sign-in).
const CORNER = ['style-indicator', 'account-control'];
// GEV's phone layout shows neither; the button then sits under this column.
const COLUMN = 'corner-actions';
const entry = ref({ top: 14, right: 14 });
function placeEntry() {
entry.value = entryPlacement(
CORNER.map((id) => document.getElementById(id)?.getBoundingClientRect()),
innerWidth,
document.getElementById(COLUMN)?.getBoundingClientRect() ?? null,
);
}
let entryTries = 0;
@@ -63,7 +66,7 @@ function watchCorner() {
});
}
if (globalThis.ResizeObserver) cornerObserver ??= new ResizeObserver(placeEntry);
for (const id of CORNER) {
for (const id of [...CORNER, COLUMN]) {
const el = document.getElementById(id);
if (el && cornerObserver && !observed.has(el)) {
cornerObserver.observe(el);
@@ -71,7 +74,7 @@ function watchCorner() {
}
}
// Keep looking for a while for a control that mounts late.
if (observed.size < CORNER.length && ++entryTries < 20)
if (observed.size < CORNER.length + 1 && ++entryTries < 20)
entryTimer = setTimeout(watchCorner, 1000);
}
@@ -298,7 +301,9 @@ watch([mode, storyId], () => nextTick(watchCredit));
<button
id="hStories"
class="tbtn accent gs-entry"
:class="{ 'gs-entry-compact': entry.compact }"
type="button"
:aria-label="entry.compact ? t('Stories') : undefined"
:style="{ top: `${entry.top}px`, right: `${entry.right}px` }"
@click="openExplore"
>