From 541843833921a98e9862c12a79fc1688370740cb Mon Sep 17 00:00:00 2001 From: Manjunath <301209272+manjunath22466@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:08:55 +0530 Subject: [PATCH 01/34] Stories: GEV scenes as stories on the live globe A Stories button (top right) opens Explore: a feed of GEV scenes over GEV's own Cesium globe, with a pin per story. Explore opens at country level over the first story and, while idle, flies on from story to story for a minute. A picked story is framed in the middle of the view; a pin plays its story on a second click. The Story page plays the scene through SceneDirector with a timeline, chapters, key moments, sources and background, then Close (or Back) puts the person's camera, clock, layers, style and AUTHORING selection back. Open in GEV hands the scene to the Scenes panel at its current shot. Stories lists the scenes GEV ships with a camera path (while they are in the project), the scenes saved with SAVE TO STORIES in AUTHORING, and the person's other scenes as drafts. The person's own stories live in the project on this device, so they have no Share; a link to a story that is not here opens Explore and says so. Each shipped story's context comes from what GEV knows: what it shows, the place each shot goes, and each layer's data sources as DATA_SOURCES.md lists them; the Nepal story carries the event pack's facts and CC BY-NC sources. Card images are a captured THUMBNAIL or drawn from the keyless Esri World Imagery. AUTHORING has no scene picker: it starts with no scene, NEW SCENE (or CAPTURE SHOT) makes one, and Stories' Open in GEV selects one. Before SAVE TO STORIES it offers topic tags and THUMBNAIL. A scene's stories flag, storyThumb and storyTags are saved with the project and kept through export and import. Only the closed state loads with the page; the screens, styles, story data and controller load on first open. Stories keeps its place in the query (one history entry per screen) and holds the share link's hash writes while open. Keyboard input and voice tools stay with Stories while it is open. Explore's pins move on every drawn frame without asking for frames; the idle tour and tile settling are bounded. All strings are translated in the 13 locales. --- docs/CURRENT-STATE.md | 162 +- docs/VUE-MIGRATION.md | 2 +- index.html | 1 + scripts/format-scope.json | 27 + scripts/package-boundaries.json | 51 +- scripts/qa-form-fields.mjs | 86 +- scripts/qa-scene-controls.mjs | 9 +- src/app/tools.js | 17 + src/creditAttribution.test.mjs | 3 + src/data/bhoteKoshiEmbeddedMedia.js | 4 + src/director/document.js | 31 +- src/director/documentFields.js | 5 +- src/i18n/locales/ar.json | 189 +- src/i18n/locales/de.json | 177 +- src/i18n/locales/es.json | 180 +- src/i18n/locales/fr.json | 180 +- src/i18n/locales/he.json | 180 +- src/i18n/locales/it.json | 180 +- src/i18n/locales/ja.json | 174 +- src/i18n/locales/pt.json | 180 +- src/i18n/locales/ru.json | 183 +- src/i18n/locales/sv.json | 177 +- src/i18n/locales/uk.json | 183 +- src/i18n/locales/zh-CN.json | 174 +- src/i18n/locales/zh-Hant.json | 174 +- src/i18n/same-as-english.json | 30 +- src/navigationPolicy.js | 2 + src/scenes/director.js | 322 +- src/scenes/director.test.mjs | 569 ++- src/scenes/project.js | 11 + src/scenes/storyTags.js | 37 + src/scenes/storyThumb.js | 139 + src/scenes/storyThumb.test.mjs | 173 + src/sharelink.js | 46 +- src/sharelink.navigation.test.mjs | 47 + src/stories/boot.js | 119 + src/stories/boot.test.mjs | 142 + src/stories/catalog.js | 340 ++ src/stories/controller.js | 953 +++++ src/stories/controller.test.mjs | 787 ++++ src/stories/format.js | 46 + src/stories/gevLogo.js | 3 + src/stories/gevPlayer.js | 143 + src/stories/gevPlayer.test.mjs | 95 + src/stories/keyboard.js | 38 + src/stories/keyboard.test.mjs | 76 + src/stories/storyMeta.js | 150 + src/stories/thumbs.js | 102 + src/stories/thumbs.test.mjs | 68 + src/tooling/applicationHtml.test.mjs | 2 +- src/ui/sceneControls.js | 37 +- src/ui/sceneControls.test.mjs | 309 +- src/ui/scenePresentation.js | 32 +- src/ui/stores/scenes.js | 35 +- src/ui/stores/stories.js | 83 + src/ui/storiesCredit.test.mjs | 136 + src/ui/styles/english-css-parity.test.mjs | 4 +- src/ui/styles/scenes.css | 75 +- src/ui/styles/stories-entry.css | 243 ++ src/ui/styles/stories.css | 4031 +++++++++++++++++++++ src/ui/surfaceKeyboard.js | 2 + src/ui/views/LayerPanelsView.vue | 26 +- src/ui/views/SceneOptions.vue | 31 - src/ui/views/StoriesView.vue | 337 ++ src/ui/views/index.js | 2 + src/ui/views/panels/ImagerySplitView.vue | 2 +- src/ui/views/stories/ExploreScreen.vue | 782 ++++ src/ui/views/stories/StoriesHeader.vue | 181 + src/ui/views/stories/StoryContext.vue | 414 +++ src/ui/views/stories/StoryRail.vue | 53 + src/ui/views/stories/StoryScreen.vue | 631 ++++ src/ui/views/stories/StoryTimeline.vue | 560 +++ src/ui/wildlifeSightingCard.js | 2 + src/voice/gevActions.js | 11 + src/voice/gevActions.test.mjs | 42 + src/voice/realtimeInput.js | 4 +- style.css | 1 + 77 files changed, 14975 insertions(+), 260 deletions(-) create mode 100644 src/scenes/storyTags.js create mode 100644 src/scenes/storyThumb.js create mode 100644 src/scenes/storyThumb.test.mjs create mode 100644 src/stories/boot.js create mode 100644 src/stories/boot.test.mjs create mode 100644 src/stories/catalog.js create mode 100644 src/stories/controller.js create mode 100644 src/stories/controller.test.mjs create mode 100644 src/stories/format.js create mode 100644 src/stories/gevLogo.js create mode 100644 src/stories/gevPlayer.js create mode 100644 src/stories/gevPlayer.test.mjs create mode 100644 src/stories/keyboard.js create mode 100644 src/stories/keyboard.test.mjs create mode 100644 src/stories/storyMeta.js create mode 100644 src/stories/thumbs.js create mode 100644 src/stories/thumbs.test.mjs create mode 100644 src/ui/stores/stories.js create mode 100644 src/ui/storiesCredit.test.mjs create mode 100644 src/ui/styles/stories-entry.css create mode 100644 src/ui/styles/stories.css delete mode 100644 src/ui/views/SceneOptions.vue create mode 100644 src/ui/views/StoriesView.vue create mode 100644 src/ui/views/stories/ExploreScreen.vue create mode 100644 src/ui/views/stories/StoriesHeader.vue create mode 100644 src/ui/views/stories/StoryContext.vue create mode 100644 src/ui/views/stories/StoryRail.vue create mode 100644 src/ui/views/stories/StoryScreen.vue create mode 100644 src/ui/views/stories/StoryTimeline.vue diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 811e2a1fd..87d00f49a 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -658,6 +658,106 @@ owner (open state, filters, the rows they show, Remove all) and the text helpers the view renders, so every label follows the locale. Only the modal open/close and focus moves are imperative. +## Stories — November 13, 2026 + +A Stories button (top right, `#hStories`) opens Explore: a feed of stories +over GEV's own Cesium globe with their pins, then a Story screen with a +timeline, chapters and context. Every GEV page loads only what the +closed state needs: the boot shell (`src/stories/boot.js`), the store, +`StoriesView.vue` with the Stories button, first-visit popup and +back-to-story toast, and their styles (`stories-entry.css`). The screens +(`ExploreScreen.vue`, `StoryScreen.vue` and their parts), their styles +(`stories.css`), the story data (`storyMeta.js`, `catalog.js`) and the +controller are separate chunks fetched together on first open, on a +`?stories=` / `?story=` link, or on Back or Forward into Stories; a failed +fetch is reported and the next attempt tries again. Stories keeps its place +in the query, not the share-state hash, with one history entry per screen; +Close steps back over those entries, so Back afterwards does not reopen it, +and share links carry only the Stories place (`stories` / `story`), not the +sender's camera, layers or other settings. GEV's share link keeps +`history.state` when it rewrites the hash, so Stories' entries survive. + +Every story is a GEV scene, played on the person's own Cesium globe through +`SceneDirector`, with its labels, embedded media, A/B imagery split (marked +`data-globe-overlay`) and data-pack cards kept while the rest of GEV is +hidden. Explore lists the scenes the person saved to Stories from AUTHORING +first (`SceneDirector.storyScenes()`, refreshed on every `stories-changed`), +then the person's other scenes with a shot as drafts +(`SceneDirector.draftScenes()`, marked DRAFT), then the +scenes GEV ships with a camera path while they are in the project +(`SceneDirector.hasScene`). A saved scene brings the card image and topics +picked for it in AUTHORING; the topic chips use AUTHORING's tag names and +order. Explore opens at country level +(2,500 km) over the first story and, while idle, flies on to the next story +every few seconds, for a minute after the last touch (never with a story +picked or with reduced motion). A picked story's place is framed in the +middle of the view at an angle. After each landing the globe keeps drawing +only until its tiles have loaded (at most 10 s). Each story's pin, in the +world overlay's label style (`src/overlays/worldOverlayTokens.js`), is placed +from Cesium's own projection on every drawn frame, written straight to the +pin's transform, and hidden behind the globe; the pins ask for no frames of +their own. Card images are drawn from the keyless Esri World Imagery tiles +around the story's place (`src/stories/thumbs.js`) unless the scene has its +own; with any other base imagery the card shows its placeholder, and a card +drawn from Esri earlier is dropped. A shot +tied to an anchor rather than a place pins the whole-globe view. + +A shipped story's context comes from what GEV knows about it +(`src/stories/catalog.js`): what it shows, the place each shot goes, and, +for each layer it turns on, what the layer shows and the data sources +DATA_SOURCES.md lists for it. The Nepal story carries the event pack's own +facts and sources (Vantor imagery and the GeoPera reconstruction, CC BY-NC +4.0), and its key moments are the chapters that show them. Topic chips and +region choices are the ones the listed stories carry. Closing Stories after +a story played puts AUTHORING's own selection back (usually none); +Open in GEV leaves the story's scene selected there. + +Opening Stories claims the camera through the shared navigation policy, so +orbit, a tracked contact or a flight end, and Cockpit refuses with the +policy's own toast ("Exit cockpit to open Stories"). Those owners are not +started again on Close: the camera and clock come back, a follow or orbit +does not. While Stories is open it owns the keyboard (`src/stories/keyboard.js`): +a key pressed in Stories stops at its root, and a key pressed anywhere else +stops at the window, so none of GEV's document-level shortcuts act behind it, +except on a playing GEV scene's own on-globe controls (`data-globe-overlay`); +the capture-phase listeners (hold Space to talk, a surface's Tab trap, the +wildlife card's Escape) check `body.stories-mode` themselves. Voice tool calls +are refused while `stories-mode` is set ("Close Stories first"). + +The address bar names only the story while Stories is open: the share link +holds its hash writes (`ShareLinkManager.holdWrites`, which first writes a +change still waiting for its debounce, so the view Stories saves is current). +Close works in this order. Stories' screens go and GEV is back on screen, but +`stories-mode` (keyboard guard, voice refusal) stays. The director is waited +on until idle (`SceneDirector.whenIdle`: no run and no pending LOAD, seek or +interaction; at most 15 s). The camera and clock are put back, unless a +camera owner took over during the wait (a drag on the globe, a layer's +focus). History steps back over Stories' entries; once that lands (or after +2 s if it never does), the saved share state is re-applied directly +(`ShareLinkManager.restore`, since the share link skips a hash it already +knows) and the share link writes the live view again. Back out of Stories +re-applies it the same way, and Back to Explore from a story re-applies it +once the scene has torn down, with the address still naming only Stories. +"Open in GEV" (GEV scene stories only) closes the +same way but keeps the place and look: nothing is put back, the scene and its +current shot are selected (`SceneDirector.selectShot`) and the Scenes panel +opens for authoring; Back then goes to the page before Stories. A Close or +open made while a traversal is landing runs once it has landed; a second Back +to Explore is ignored. Reopening Stories while a closed GEV scene is still +tearing down keeps the view from before Stories as the one Close restores. +Inside an inline embed Stories is not offered: the URL and history are the +host's. + +The Stories button sits left of whatever holds GEV's top-right corner: the +ACTIVE STYLE readout, or GEV Hosted's account avatar. The first-visit popup +is a labelled region that does not take focus. The story page's rail offers +Open in GEV and Share only. A scene of the person's own (saved or draft) +shows as theirs ("You") and has no Share: the project lives on this device, +so a link to it would open nothing elsewhere; a link to a story that is not +here opens Explore and says so. GEV's own credit line stays on screen throughout, inside the +Stories map while a scene plays (`creditPlacement` in +`src/stories/format.js`). + ## Utilities panel — October 29, 2026 UTILITIES is its own left-side panel, between Data Layers and Scenes, with @@ -1271,7 +1371,7 @@ Native `
- {{ t('EDIT DETAILS') }} - {{ t('SHARE SCENE') }} + {{ t('EDIT DETAILS') }} + {{ t('SHARE SCENE') }}
{{ scene?.progress ?? 0 }}%
diff --git a/src/ui/views/SceneOptions.vue b/src/ui/views/SceneOptions.vue deleted file mode 100644 index 4cc6bbe77..000000000 --- a/src/ui/views/SceneOptions.vue +++ /dev/null @@ -1,31 +0,0 @@ - - - diff --git a/src/ui/views/StoriesView.vue b/src/ui/views/StoriesView.vue new file mode 100644 index 000000000..4e3944e64 --- /dev/null +++ b/src/ui/views/StoriesView.vue @@ -0,0 +1,337 @@ + + + diff --git a/src/ui/views/index.js b/src/ui/views/index.js index a85224912..522a8d0c9 100644 --- a/src/ui/views/index.js +++ b/src/ui/views/index.js @@ -10,6 +10,7 @@ import CockpitView from './CockpitView.vue'; import SceneChromeView from './SceneChromeView.vue'; import ProviderSettingsView from './ProviderSettingsView.vue'; import IntelHudView from './IntelHudView.vue'; +import StoriesView from './StoriesView.vue'; /** * Application views by name. A page places each one with a host element, @@ -26,6 +27,7 @@ export const APPLICATION_VIEWS = Object.freeze({ context: ContextView, welcome: WelcomeView, 'intel-hud': IntelHudView, + stories: StoriesView, }); const mounted = new WeakMap(); diff --git a/src/ui/views/panels/ImagerySplitView.vue b/src/ui/views/panels/ImagerySplitView.vue index b25c7cf46..1c2a34e05 100644 --- a/src/ui/views/panels/ImagerySplitView.vue +++ b/src/ui/views/panels/ImagerySplitView.vue @@ -11,6 +11,6 @@ const optional = (value) => value ?? undefined; diff --git a/src/ui/views/stories/ExploreScreen.vue b/src/ui/views/stories/ExploreScreen.vue new file mode 100644 index 000000000..04babc054 --- /dev/null +++ b/src/ui/views/stories/ExploreScreen.vue @@ -0,0 +1,782 @@ + + + diff --git a/src/ui/views/stories/StoriesHeader.vue b/src/ui/views/stories/StoriesHeader.vue new file mode 100644 index 000000000..e53d35b3b --- /dev/null +++ b/src/ui/views/stories/StoriesHeader.vue @@ -0,0 +1,181 @@ + + + diff --git a/src/ui/views/stories/StoryContext.vue b/src/ui/views/stories/StoryContext.vue new file mode 100644 index 000000000..2556c6405 --- /dev/null +++ b/src/ui/views/stories/StoryContext.vue @@ -0,0 +1,414 @@ + + + diff --git a/src/ui/views/stories/StoryRail.vue b/src/ui/views/stories/StoryRail.vue new file mode 100644 index 000000000..5687a61c9 --- /dev/null +++ b/src/ui/views/stories/StoryRail.vue @@ -0,0 +1,53 @@ + + + diff --git a/src/ui/views/stories/StoryScreen.vue b/src/ui/views/stories/StoryScreen.vue new file mode 100644 index 000000000..8eeff9c15 --- /dev/null +++ b/src/ui/views/stories/StoryScreen.vue @@ -0,0 +1,631 @@ + + + diff --git a/src/ui/views/stories/StoryTimeline.vue b/src/ui/views/stories/StoryTimeline.vue new file mode 100644 index 000000000..de0bd9972 --- /dev/null +++ b/src/ui/views/stories/StoryTimeline.vue @@ -0,0 +1,560 @@ + + + diff --git a/src/ui/wildlifeSightingCard.js b/src/ui/wildlifeSightingCard.js index ce6a24588..7a01b110d 100644 --- a/src/ui/wildlifeSightingCard.js +++ b/src/ui/wildlifeSightingCard.js @@ -203,6 +203,8 @@ export function createWildlifeSightingCard({ const keydown = (event) => { if (!selected.value || event.key !== 'Escape') return; + // Stories owns Escape while it is open (the card is behind it). + if (documentRef.body?.classList?.contains?.('stories-mode')) return; event.preventDefault(); event.stopImmediatePropagation(); layer.clearSightingSelection(); diff --git a/src/voice/gevActions.js b/src/voice/gevActions.js index 3343cd243..45279baa9 100644 --- a/src/voice/gevActions.js +++ b/src/voice/gevActions.js @@ -444,6 +444,17 @@ export function createGevActionRunner({ runOptions = {}, ) { const args = rawArgs && typeof rawArgs === 'object' ? rawArgs : {}; + // Stories covers GEV and owns its camera and scenes: an open-mic session + // must not fly, load or change what is behind it. + if (globalThis.document?.body?.classList?.contains?.('stories-mode')) + return { + ok: false, + action: name, + applied: false, + refused: 'stories-open', + error: 'Stories is open. Close Stories first.', + say: 'Stories is open. Close Stories first to control the globe.', + }; const current = () => !runOptions.signal?.aborted && (typeof runOptions.isCurrent !== 'function' || runOptions.isCurrent()); diff --git a/src/voice/gevActions.test.mjs b/src/voice/gevActions.test.mjs index 123bbd8e4..0a26b4b36 100644 --- a/src/voice/gevActions.test.mjs +++ b/src/voice/gevActions.test.mjs @@ -258,6 +258,48 @@ test('zoom to globe adopts the shared visible reset route and returns its result assert.equal(calls, 1); }); +test('voice changes nothing behind Stories while it is open', async () => { + globalThis.window = globalThis.window || { + clearTimeout, + setTimeout, + requestIdleCallback: null, + }; + const viewer = { + clock: { onTick: { addEventListener: () => () => {} } }, + scene: { canvas: { addEventListener() {}, removeEventListener() {} } }, + camera: { moveEnd: { addEventListener() {} } }, + }; + let calls = 0; + const styleManager = { + async resetToGlobeView() { + calls += 1; + return { ok: true }; + }, + }; + const runner = createGevActionRunner({ + viewer, + styleManager, + dataManager: { layers: new Map(), getAll: () => [] }, + }); + const classes = new Set(['stories-mode']); + const priorDocument = globalThis.document; + globalThis.document = { + ...(priorDocument ?? {}), + body: { classList: { contains: (c) => classes.has(c) } }, + }; + try { + const refused = await runner('zoom_to_globe'); + assert.equal(refused.ok, false); + assert.equal(refused.refused, 'stories-open'); + assert.equal(calls, 0); + classes.clear(); + await runner('zoom_to_globe'); + assert.equal(calls, 1, 'works again once Stories has closed'); + } finally { + globalThis.document = priorDocument; + } +}); + test('dependent voice navigation waits for the destination viewport to arrive', async () => { globalThis.window = globalThis.window || { clearTimeout, diff --git a/src/voice/realtimeInput.js b/src/voice/realtimeInput.js index 0a43fa6ec..e759e14d8 100644 --- a/src/voice/realtimeInput.js +++ b/src/voice/realtimeInput.js @@ -55,9 +55,11 @@ export class RealtimeInput { bindPushToTalkShortcut() { if (this.shortcutKeyDownHandler) return; this.shortcutKeyDownHandler = (event) => { - // Space types in chat; it never talks while chat is open. + // Space types in chat; it never talks while chat is open, nor while + // Stories owns the keyboard (body.stories-mode). if ( this.ui.state?.chat?.open === true || + globalThis.document?.body?.classList?.contains?.('stories-mode') || !shouldHandlePushToTalkKeyDown(event) ) return; diff --git a/style.css b/style.css index 7e218d7f8..6d3591643 100644 --- a/style.css +++ b/style.css @@ -55,4 +55,5 @@ @import './src/ui/styles/cockpit-panels.css'; @import './src/ui/styles/ai-chat.css'; @import './src/ui/styles/scope-off-shadows.css'; +@import './src/ui/styles/stories-entry.css'; @import './src/ui/styles/cyber.css'; From 9e9ce1db22c46de52d14b7ffb48a25dab04ad1b5 Mon Sep 17 00:00:00 2001 From: Manjunath <301209272+manjunath22466@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:23:07 +0530 Subject: [PATCH 02/34] Fix Stories navigation, sharing, and voice entry --- docs/CURRENT-STATE.md | 20 +- scripts/qa-director-sharing.mjs | 29 ++- scripts/qa-scene-controls.mjs | 16 +- server/providers/openai/instructions.js | 2 +- server/providers/openai/toolDescriptions.js | 5 + src/app/tools.js | 23 +- src/firstRunExperience.test.mjs | 1 + src/i18n/locales/ar.json | 1 + src/i18n/locales/de.json | 1 + src/i18n/locales/es.json | 1 + src/i18n/locales/fr.json | 1 + src/i18n/locales/he.json | 1 + src/i18n/locales/it.json | 1 + src/i18n/locales/ja.json | 1 + src/i18n/locales/pt.json | 1 + src/i18n/locales/ru.json | 1 + src/i18n/locales/sv.json | 1 + src/i18n/locales/uk.json | 1 + src/i18n/locales/zh-CN.json | 1 + src/i18n/locales/zh-Hant.json | 1 + src/radioMarkup.test.mjs | 9 +- src/sharelink.js | 5 + src/sharelink.navigation.test.mjs | 6 + src/stories/boot.js | 3 + src/stories/boot.test.mjs | 22 +- src/stories/controller.js | 185 +++++++++++--- src/stories/controller.test.mjs | 267 +++++++++++++++++--- src/stories/gevPlayer.js | 15 +- src/stories/gevPlayer.test.mjs | 39 ++- src/ui/views/stories/StoriesHeader.vue | 12 +- src/voice/actionSchemas.js | 8 + src/voice/actionSchemas.test.mjs | 4 +- src/voice/geminiSession.js | 9 +- src/voice/gevActions.js | 53 +++- src/voice/gevActions.test.mjs | 52 ++++ src/voice/gevRealtime.test.mjs | 28 ++ src/voice/realtimeConnection.js | 4 +- src/voice/realtimeInput.js | 7 +- src/voice/realtimeInputPolicy.js | 7 + src/voice/session.js | 14 +- src/voice/session.test.mjs | 18 +- src/voice/sessionCommands.js | 4 +- src/voice/speech.js | 1 + 43 files changed, 744 insertions(+), 137 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 87d00f49a..ce30c9217 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -721,14 +721,18 @@ a key pressed in Stories stops at its root, and a key pressed anywhere else stops at the window, so none of GEV's document-level shortcuts act behind it, except on a playing GEV scene's own on-globe controls (`data-globe-overlay`); the capture-phase listeners (hold Space to talk, a surface's Tab trap, the -wildlife card's Escape) check `body.stories-mode` themselves. Voice tool calls +wildlife card's Escape) check `body.stories-mode` themselves. "Open Stories" +works from voice or typed AI chat. Entering Stories ends active or pending +microphone capture and blocks microphone starts while Stories owns the +globe. Stories shows a notice when it turns off an active or connecting +voice session. A typed reply can finish after opening Stories. Globe tool calls are refused while `stories-mode` is set ("Close Stories first"). -The address bar names only the story while Stories is open: the share link -holds its hash writes (`ShareLinkManager.holdWrites`, which first writes a -change still waiting for its debounce, so the view Stories saves is current). -Close works in this order. Stories' screens go and GEV is back on screen, but -`stories-mode` (keyboard guard, voice refusal) stays. The director is waited +The address bar names only the story while Stories is open. Stories holds +hash writes (`ShareLinkManager.holdWrites`) and saves a snapshot of the live +globe, including when it opens from a story link without a hash. +Close dismisses the Stories screens and keeps the keyboard and microphone +guards until the previous view is back. The director is waited on until idle (`SceneDirector.whenIdle`: no run and no pending LOAD, seek or interaction; at most 15 s). The camera and clock are put back, unless a camera owner took over during the wait (a drag on the globe, a layer's @@ -751,7 +755,9 @@ host's. The Stories button sits left of whatever holds GEV's top-right corner: the ACTIVE STYLE readout, or GEV Hosted's account avatar. The first-visit popup is a labelled region that does not take focus. The story page's rail offers -Open in GEV and Share only. A scene of the person's own (saved or draft) +Open in GEV and Share only. Share on Explore reopens the list with the same +shipped story selected. A story link opens paused at the shared +point on its timeline. A scene of the person's own (saved or draft) shows as theirs ("You") and has no Share: the project lives on this device, so a link to it would open nothing elsewhere; a link to a story that is not here opens Explore and says so. GEV's own credit line stays on screen throughout, inside the diff --git a/scripts/qa-director-sharing.mjs b/scripts/qa-director-sharing.mjs index 4a4a93d48..ef31e2e68 100644 --- a/scripts/qa-director-sharing.mjs +++ b/scripts/qa-director-sharing.mjs @@ -116,7 +116,7 @@ try { document.getElementById('loading-screen')?.classList.contains('hidden'), { timeout: 60000 }, ); - await page.click('[data-collapse-target="scene-panel"]'); + await page.click('[data-rail-item="scene-panel"]'); const before = await page.evaluate(() => JSON.stringify(window.__godsEyeView.sceneDirector._project), ); @@ -304,18 +304,17 @@ try { window.__godsEyeView.sceneDirector.getInteractionState().count === 1, )), ); - await page.waitForFunction( - () => window.__godsEyeView.tileset?.tilesLoaded === true, - { timeout: 60000 }, - ); + const activeMapReady = () => { + const { viewer, mapStackController } = window.__godsEyeView; + const tileset = mapStackController.getImageryHostTileset(); + if (tileset) return tileset.tilesLoaded; + return viewer.scene.globe.show && viewer.scene.globe.tilesLoaded; + }; + await page.waitForFunction(activeMapReady, { timeout: 60000 }); await page.screenshot({ path: path.join(output, 'rendered.png') }); fs.writeFileSync( path.join(output, 'report.json'), - JSON.stringify( - await page.evaluate(() => ({ - tilesSettled: window.__godsEyeView.tileset?.tilesLoaded === true, - })), - ), + JSON.stringify({ tilesSettled: await page.evaluate(activeMapReady) }), ); await page.evaluate(() => window.__godsEyeView.sceneDirector.stopScene()); check( @@ -368,6 +367,16 @@ try { ); await page.screenshot({ path: path.join(output, 'narrow.png') }); await page.keyboard.press('Escape'); + await page.setViewport({ width: 1440, height: 900 }); + await page.waitForSelector('[data-rail-item="scene-panel"]', { + visible: true, + }); + if ( + await page.$eval('#scene-panel', (panel) => + panel.classList.contains('collapsed'), + ) + ) + await page.click('[data-rail-item="scene-panel"]'); const pending = await page.evaluate(async () => { const d = window.__godsEyeView.sceneDirector; let finish; diff --git a/scripts/qa-scene-controls.mjs b/scripts/qa-scene-controls.mjs index 5171da684..fc9bf1606 100644 --- a/scripts/qa-scene-controls.mjs +++ b/scripts/qa-scene-controls.mjs @@ -45,7 +45,7 @@ try { window.__qaSceneState.push(notification), ); }); - await page.click('[data-collapse-target="scene-panel"]'); + await page.click('[data-rail-item="scene-panel"]'); await page.click('#scene-new-btn'); await page.waitForFunction( () => document.querySelector('#scene-name')?.textContent === 'QA Scene', @@ -276,7 +276,7 @@ try { panel.classList.contains('collapsed'), ) ) - await page.click('[data-collapse-target="scene-panel"]'); + await page.click('[data-rail-item="scene-panel"]'); await page.waitForSelector('#scene-download-btn', { visible: true }); await page.click('#scene-download-btn'); const metadata = await page.evaluate(async () => @@ -389,15 +389,15 @@ try { () => !window.__godsEyeView.sceneDirector._project.scenes.some( (item) => item.title === 'QA Scene', - ), + ) && document.querySelector('#scene-name.scene-name-empty'), ); check( - 'Deleting the final scene restores the built-in recipes', + 'Deleting the final scene restores the built-in recipes and clears Authoring', await page.evaluate( () => window.__godsEyeView.sceneDirector._project.scenes.length > 0 && - document.querySelector('#scene-name')?.textContent === - window.__godsEyeView.sceneDirector._getSelectedScene()?.title, + window.__godsEyeView.sceneDirector._getSelectedScene() === null && + document.querySelector('#scene-name.scene-name-empty') !== null, ), ); check( @@ -425,6 +425,10 @@ try { ); }), ); + promptValue = 'Disposal scene'; + await page.click('#scene-new-btn'); + await page.click('#scene-capture-btn'); + await page.waitForSelector('.scene-shot-label', { visible: true }); const teardown = await page.evaluate(async () => { const director = window.__godsEyeView.sceneDirector; const controls = director._controls; diff --git a/server/providers/openai/instructions.js b/server/providers/openai/instructions.js index f9ac49244..f9125df60 100644 --- a/server/providers/openai/instructions.js +++ b/server/providers/openai/instructions.js @@ -26,7 +26,7 @@ function realtimeDirectives( 'analyst_query ANSWERS questions; it never moves the camera or starts tracking. For requests to FOLLOW or TRACK a specific aircraft/ship, call track_entity (get_entity_context first when the target is ambiguous), never analyst_query as the final or only action. For "follow/track the nearest aircraft", first call analyst_query with the aircraft layer(s), sortBy=distance, and limit=1, then call track_entity with the returned aircraft identity in the same turn. The lookup alone does not fulfill a follow/track command.', 'For a request to enable an aircraft layer and SELECT or FIND the nearest/closest aircraft near a named place — for example, "Turn on flights and select the closest aircraft to Austin" — call select_nearest_aircraft once. It atomically turns on the requested aircraft layer first, waits for location arrival, refreshes that layer for the destination viewport, filters out landed/on-ground records, and selects the nearest airborne result. A healthy fallback feed is valid data, never an enable failure. Do not also call fly_to_location, set_layer_visibility, analyst_query, track_entity, set_context_mode, or control_cockpit for the same request.', 'For ANALYTICAL questions about loaded layer data — how many / which / fastest / highest / biggest / nearest / next flights, ships, fires, earthquakes, satellites, launches, storms, transit, bikes, bases, datacenters or dams ("how many flights over Texas", "anything above 40,000 feet") — call analyst_query, not get_entity_context. Always set scope by WHERE: "around here" or "near this" while pointing is kind pointer, never view. Filter on the attribute the user names ("MODIS" → sensor eq MODIS). Say the count with its scope in a few words ("37 loaded flights over Texas") plus one or two examples by name. If the needed layer is off, say so and offer to turn it on. "Which of THOSE…" about the last answer → followUp=true with only the new filter/sort.', - 'WORLD QUERIES — the query tools (get_weather, get_wind, search_places, places_nearby, plan_route, get_cyclones, get_fire_perimeters, get_bike_share, get_transit_vehicles, get_traffic_flow, situation_brief, military_awareness and the other get_* and find_* tools you have) look up data anywhere in the world without changing the map and without any layer being on. Use them when the user asks about a place they are not looking at or data whose layer is off ("what is the weather in Tokyo", "how do I drive from Austin to Dallas", "any wildfires in California"). For aircraft, ships, earthquakes, active fires, datacenters, dams and satellites overhead, use analyst_query over the layers instead, turning the layer on first when the user wants it. Use analyst_query and get_entity_context for what the app has loaded or what is on screen. Answer from the result summary and data, mention its source when it has one, and never claim the map changed. If the user also wants to SEE it, use the matching app action (fly_to_location, set_layer_visibility) as well.', + 'WORLD QUERIES: query tools (get_weather, get_wind, search_places, places_nearby, plan_route, get_cyclones, get_fire_perimeters, get_bike_share, get_transit_vehicles, get_traffic_flow, situation_brief, military_awareness and other get_* and find_* tools) look up any place without changing the map or enabling layers. Use them for places out of view or data whose layer is off. For aircraft, ships, earthquakes, active fires, datacenters, dams and satellites overhead, use analyst_query over layers instead; enable the layer first if asked. Use analyst_query and get_entity_context for loaded data or what is on screen. Answer from the result; name its source if supplied and never claim the map changed. If asked to show it, also use the matching app action (fly_to_location, set_layer_visibility).', 'WHERE, for every tool that takes a place or scope, in this order: (1) a place the user names, or an areaId you already have; (2) explicit pointing — "this/that one/here/around here" while pointer_context shows pointing or a target → "pointer"; (3) the Contacts subject while Contacts is active, or the selection when the user refers to it; (4) the current view. A selected datacenter, dam, fire or cable never silently becomes the centre.', 'AREAS: resolve_area turns a named boundary (country, state, province, county, city, district, natural region) into an areaId; to outline it pass draw=true; annotate_map is for marks, not boundaries. Count inside it → analyst_query kind=area with the areaId (or kind=region); "the area I drew" → kind=drawn; "the area you outlined" → kind=annotation. Imagery of a place → resolve_area, then find_imagery. Ambiguous name: call resolve_area; on needsClarification ask which, never guess.' + (overpass diff --git a/server/providers/openai/toolDescriptions.js b/server/providers/openai/toolDescriptions.js index d3116f06a..490de5c0b 100644 --- a/server/providers/openai/toolDescriptions.js +++ b/server/providers/openai/toolDescriptions.js @@ -309,6 +309,11 @@ export const ACTION_DESCRIPTIONS = { }, }, }, + open_stories: { + description: + 'Open the Stories Explore list on request ("open Stories", "show the story list"). Turns off voice.', + $position: 1, + }, control_scene: { description: 'Cinematic scene playback: list scenes, play one scene by name, stop, advance, or read status. Play starts a single named scene and returns immediately.', diff --git a/src/app/tools.js b/src/app/tools.js index 71f0970b1..e35d861cf 100644 --- a/src/app/tools.js +++ b/src/app/tools.js @@ -21,6 +21,7 @@ import { createLibraryBrowser } from '../ui/libraryBrowser.js'; import { useDataLibraryStore } from '../ui/stores/dataLibrary.js'; import { localGeoJsonServices } from './localGeojsonServices.js'; import { initGevVoiceCommands } from '../voice/gevRealtime.js'; +import { isStoriesOpen } from '../voice/realtimeInputPolicy.js'; import { installViews, isEmbeddedInline } from './embed.js'; import { installScopeMask, @@ -81,12 +82,23 @@ export function createApplicationTools({ onSceneDirector?.(sceneDirector); // Stories: GEV scenes on this globe, from a Stories button. Its screens, // styles, story data and controller load on first use. + const storiesStore = useStoriesStore(applicationPinia()); + let voiceCommands; const stories = bootStories({ // Inline in a host page, the URL and history are the host's. available: !isEmbeddedInline(), viewer, director: sceneDirector, - store: useStoriesStore(applicationPinia()), + store: storiesStore, + onEnter: () => { + const session = voiceCommands?.session; + // A typed command can finish its reply without keeping a microphone on. + if (!session || session.adapter.getStartOptions?.().textOnly) return; + const wasActive = session.isActive(); + session.stop(); + if (wasActive) + storiesStore.flashToast(t('Voice is disabled in Stories.'), 4000); + }, onLoadFailed: () => styleManager._showToast?.( t('Stories could not load. Check the connection and try again.'), @@ -299,8 +311,15 @@ export function createApplicationTools({ defer(() => { if (window.__godsEyeView === debug) delete window.__godsEyeView; }); - const voiceCommands = initGevVoiceCommands({ + voiceCommands = initGevVoiceCommands({ ...voice, + canStartVoice: () => !isStoriesOpen(), + openStories: storiesStore.available + ? ({ isCurrent }) => + storiesStore.mode === 'closed' + ? stories.open({ isCurrent }) + : 'already-open' + : null, floorServices: operations.surface.groundFloor, annotationResolver: operations.annotationResolver, searchNavigation: operations.searchAndFlyTo, diff --git a/src/firstRunExperience.test.mjs b/src/firstRunExperience.test.mjs index e81e4651e..9365ae74f 100644 --- a/src/firstRunExperience.test.mjs +++ b/src/firstRunExperience.test.mjs @@ -991,6 +991,7 @@ test('the voice TOOL SCHEMA matches the pinned contract — the mission mapping 'find_imagery', 'osm_query', 'show_street_level', + 'open_stories', ].includes(tool.name), ); const hudLayout = legacyTools.find((tool) => tool.name === 'set_hud') diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index 7aae7547d..c31e12f58 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -205,6 +205,7 @@ "Hold Space to talk": "اضغط مطولًا على Space للتحدث", "Release Space to send": "حرّر Space للإرسال", "Ask or command": "اسأل أو أصدر أمرًا", + "Voice is disabled in Stories.": "التحكم الصوتي معطّل في القصص.", "Voice off": "الصوت متوقف", "Running command": "جارٍ تنفيذ الأمر", "Radio did not start": "لم يبدأ الراديو", diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 2fdd5d27c..3f5ef6fe0 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -784,6 +784,7 @@ "Requesting microphone": "Mikrofonzugriff wird angefordert", "Ask or command": "Fragen oder Befehl geben", "Running command": "Befehl läuft", + "Voice is disabled in Stories.": "Die Sprachsteuerung ist in Stories deaktiviert.", "Voice off": "Sprache aus", "WebRTC microphone support unavailable": "WebRTC-Mikrofonunterstützung nicht verfügbar", "VOICE UNAVAILABLE": "SPRACHE N. V.", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index b2867f41a..c837a8d9d 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -968,6 +968,7 @@ "Hold Space to talk": "Mantén Space y habla", "Release Space to send": "Suelta Space para enviar", "Ask or command": "Pregunta o ordena", + "Voice is disabled in Stories.": "El control por voz está desactivado en Historias.", "Voice off": "Voz desactivada", "Running command": "Ejecutando comando", "Radio did not start": "La radio no se inició", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 7c31a92a6..ca2dfae59 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -2526,6 +2526,7 @@ "Gemini voice is not connected": "La voix Gemini n'est pas connectée", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "La saisie interrompue de Gemini a dépassé sa limite de tampon ou d'attente. Relancez la voix.", "Gemini Live connection is expiring. Start voice again for a new conversation.": "La connexion à Gemini Live expire. Relancez la voix pour une nouvelle conversation.", + "Voice is disabled in Stories.": "La commande vocale est désactivée dans les Stories.", "Voice off": "Voix désactivée", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Les sessions vocales Gemini sont limitées dans le temps. Quand une session expire, relancez la voix pour une nouvelle conversation.", "Stopped by voice": "Arrêté par la voix", diff --git a/src/i18n/locales/he.json b/src/i18n/locales/he.json index 7c9a37fbe..838200552 100644 --- a/src/i18n/locales/he.json +++ b/src/i18n/locales/he.json @@ -2862,6 +2862,7 @@ "Gemini voice is not connected": "הקול של Gemini אינו מחובר", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "הקלט שהופסק של Gemini חרג מהחוצץ או ממגבלת ההמתנה. הפעל את הקול שוב.", "Gemini Live connection is expiring. Start voice again for a new conversation.": "חיבור Gemini Live עומד לפוג. הפעל את הקול שוב לשיחה חדשה.", + "Voice is disabled in Stories.": "השליטה הקולית מושבתת בסיפורים.", "Voice off": "הקול כבוי", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "הפעלות הקול של Gemini מוגבלות בזמן. כשההפעלה פגה, הפעל את הקול שוב לשיחה חדשה.", "Stopped by voice": "נעצר בקול", diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index 243b2b049..b0e3df729 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -2526,6 +2526,7 @@ "Gemini voice is not connected": "La voce Gemini non è connessa", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "L'input interrotto di Gemini ha superato il limite di buffer o di attesa. Riavvia la voce.", "Gemini Live connection is expiring. Start voice again for a new conversation.": "La connessione a Gemini Live sta scadendo. Riavvia la voce per una nuova conversazione.", + "Voice is disabled in Stories.": "Il controllo vocale è disattivato nelle Storie.", "Voice off": "Voce disattivata", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Le sessioni vocali Gemini hanno un limite di tempo. Quando una sessione scade, riavvia la voce per una nuova conversazione.", "Stopped by voice": "Fermato dalla voce", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index f95f3255d..c89fc74f6 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -2426,6 +2426,7 @@ "Gemini voice is not connected": "Gemini音声が接続されていません", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "Geminiの中断された入力がバッファーまたは待機の上限を超えました。音声をもう一度開始してください。", "Gemini Live connection is expiring. Start voice again for a new conversation.": "Gemini Liveの接続がまもなく期限切れです。新しい会話を始めるには、音声をもう一度開始してください。", + "Voice is disabled in Stories.": "ストーリーでは音声操作が無効になります。", "Voice off": "音声 オフ", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Gemini音声のセッションには時間制限があります。セッションが期限切れになったら、音声をもう一度開始して新しい会話を始めてください。", "Stopped by voice": "音声で停止しました", diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index 2f336b3ab..93fa6f71e 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -2526,6 +2526,7 @@ "Gemini voice is not connected": "A voz do Gemini não está conectada", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "A entrada interrompida do Gemini excedeu o limite de buffer ou de espera. Inicie a voz de novo.", "Gemini Live connection is expiring. Start voice again for a new conversation.": "A conexão com o Gemini Live vai expirar. Inicie a voz de novo para uma nova conversa.", + "Voice is disabled in Stories.": "O controle por voz está desativado nas Histórias.", "Voice off": "Voz desligada", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "As sessões de voz do Gemini têm limite de tempo. Quando uma sessão expirar, inicie a voz de novo para uma nova conversa.", "Stopped by voice": "Parado por voz", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 60e7731a3..d87a19226 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -1024,6 +1024,7 @@ "Ask or command": "Спросите или дайте команду", "WebRTC microphone support unavailable": "Поддержка микрофона WebRTC недоступна", "Requesting microphone": "Запрос доступа к микрофону", + "Voice is disabled in Stories.": "Голосовое управление в историях отключено.", "Voice off": "Голос выключен", "VOICE UNAVAILABLE": "ГОЛОС НЕДОСТУПЕН", "VOICE ACTIVE": "ГОЛОС АКТИВЕН", diff --git a/src/i18n/locales/sv.json b/src/i18n/locales/sv.json index f8319e585..e1976a8a5 100644 --- a/src/i18n/locales/sv.json +++ b/src/i18n/locales/sv.json @@ -740,6 +740,7 @@ "Requesting microphone": "Begär åtkomst till mikrofonen", "Ask or command": "Fråga eller ge ett kommando", "Running command": "Kör kommando", + "Voice is disabled in Stories.": "Röststyrning är avstängd i Stories.", "Voice off": "Röst av", "WebRTC microphone support unavailable": "Mikrofonstöd för WebRTC saknas", "VOICE UNAVAILABLE": "RÖST OTILLGÄNGLIG", diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index 70bba2d73..14d32aec3 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -2575,6 +2575,7 @@ "Gemini voice is not connected": "Голосовий режим Gemini не підключено", "Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "Перерване введення Gemini перевищило ліміт буфера або очікування. Запустіть голосовий режим знову.", "Gemini Live connection is expiring. Start voice again for a new conversation.": "Термін дії зʼєднання з Gemini Live спливає. Запустіть голосовий режим знову для нової розмови.", + "Voice is disabled in Stories.": "Голосове керування в історіях вимкнено.", "Voice off": "Голос вимкнено", "Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Тривалість голосових сеансів Gemini обмежена. Коли сеанс завершиться, запустіть голосовий режим знову для нової розмови.", "Stopped by voice": "Зупинено голосовою командою", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 5afbbab41..08926db8b 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -2332,6 +2332,7 @@ "Release Space to send": "松开空格键发送", "Hold Space to talk": "按住空格键说话", "Ask or command": "提问或下达指令", + "Voice is disabled in Stories.": "故事模式下语音控制已禁用。", "Voice off": "语音已关闭", "VOICE UNAVAILABLE": "语音不可用", "VOICE ACTIVE": "语音已启用", diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index 21a4463e5..eea3781dc 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -2322,6 +2322,7 @@ "Release Space to send": "鬆開空格鍵發送", "Hold Space to talk": "按住空格鍵說話", "Ask or command": "提問或下達指令", + "Voice is disabled in Stories.": "故事模式下語音控制已停用。", "Voice off": "語音已關閉", "VOICE UNAVAILABLE": "語音不可用", "VOICE ACTIVE": "語音已啟用", diff --git a/src/radioMarkup.test.mjs b/src/radioMarkup.test.mjs index 6dec02b14..8cfa09ba6 100644 --- a/src/radioMarkup.test.mjs +++ b/src/radioMarkup.test.mjs @@ -25,15 +25,16 @@ const css = readStylesheet(new URL('../style.css', import.meta.url)); function realtimeTools() { return GEV_REALTIME_TOOLS; } -test('Realtime schema exposes the authoritative 35-tool inventory', () => { +test('Realtime schema exposes the authoritative 36-tool inventory', () => { const tools = realtimeTools(); - assert.equal(tools.length, 35); + assert.equal(tools.length, 36); const names = tools.map((tool) => tool.name); - assert.equal(new Set(names).size, 35, 'tool names are unique'); + assert.equal(new Set(names).size, 36, 'tool names are unique'); assert.ok(names.includes('resolve_area')); assert.ok(names.includes('find_imagery')); assert.ok(names.includes('osm_query')); assert.ok(names.includes('show_street_level')); + assert.ok(names.includes('open_stories')); assert.ok(names.includes('set_context_mode')); assert.ok(names.includes('control_cockpit')); assert.ok(names.includes('set_voice_inactivity_timeout')); @@ -209,6 +210,8 @@ test('no unchanged Realtime tool definition drifts silently', () => { 'osm_query', // Street-level photos: a new composite tool, not an edit to a shipped one. 'show_street_level', + // Stories Explore: a new entry action. + 'open_stories', ]); const unchanged = realtimeTools() .filter((tool) => !TOUCHED.has(tool.name)) diff --git a/src/sharelink.js b/src/sharelink.js index b427b5a8b..91461923d 100644 --- a/src/sharelink.js +++ b/src/sharelink.js @@ -756,6 +756,11 @@ export class ShareLinkManager { history.replaceState(history.state, '', url.href); } + /** Capture the live share hash without changing the current history entry. */ + snapshotHash() { + return this._buildHashParams()?.toString() ?? null; + } + /** Build a deterministic snapshot without mutating history. */ _buildHashParams() { if (this._destroyed) return null; diff --git a/src/sharelink.navigation.test.mjs b/src/sharelink.navigation.test.mjs index 087812ef0..0d18b5b7c 100644 --- a/src/sharelink.navigation.test.mjs +++ b/src/sharelink.navigation.test.mjs @@ -167,6 +167,12 @@ test('holding writes first writes a view change still waiting for its debounce', manager.holdWrites(true); assert.equal(window.location.hash, '#v=2&lat=5', 'written before the hold'); manager._buildHashParams = () => new URLSearchParams('v=2&lat=9'); + assert.equal(manager.snapshotHash(), 'v=2&lat=9'); + assert.equal( + window.location.hash, + '#v=2&lat=5', + 'snapshot leaves the URL alone', + ); manager._scheduleUpdate(); assert.equal(timers.size, 0, 'nothing scheduled while held'); manager.destroy(); diff --git a/src/stories/boot.js b/src/stories/boot.js index 7ea77efa8..1b0162b47 100644 --- a/src/stories/boot.js +++ b/src/stories/boot.js @@ -14,6 +14,7 @@ const wantsStories = () => { * @param {{viewer: import('cesium').Viewer, * director: import('../scenes/director.js').SceneDirector, * store: ReturnType, + * onEnter?: () => void, * onLoadFailed?: () => void, * loadModules?: () => Promise<[object, object]>}} options `onLoadFailed` * tells the person a click did nothing because Stories could not load; @@ -26,6 +27,7 @@ export function bootStories({ viewer, director, store, + onEnter, onLoadFailed, available = true, loadModules = () => @@ -67,6 +69,7 @@ export function bootStories({ viewer, director, store, + onEnter, }); store.connect(real, listStories()); return real; diff --git a/src/stories/boot.test.mjs b/src/stories/boot.test.mjs index 1d540d72a..bb353bbb3 100644 --- a/src/stories/boot.test.mjs +++ b/src/stories/boot.test.mjs @@ -70,7 +70,14 @@ test('the shell loads the controller on first open, then steps aside', async () setActivePinia(createPinia()); history.replaceState(null, '', '/'); const store = useStoriesStore(); - const shell = bootStories({ viewer, director, store }); + const entries = []; + const shell = bootStories({ + viewer, + director, + store, + onEnter: () => + entries.push(document.body.classList.contains('stories-mode')), + }); assert.equal(store.controller, shell); assert.equal(store.stories.length, 0, 'no catalog until Stories is used'); const engineLoaded = () => @@ -78,7 +85,14 @@ test('the shell loads the controller on first open, then steps aside', async () /stories\/(controller|catalog|protoEngine)\.js$/.test(u), ); assert.equal(engineLoaded(), false, 'GEV starts without the Stories chunk'); - await shell.open(); + let current = true; + const staleOpen = shell.open({ isCurrent: () => current }); + current = false; + assert.equal(await staleOpen, false); + assert.equal(store.mode, 'closed'); + assert.deepEqual(entries, []); + assert.equal(await shell.open(), true); + assert.deepEqual(entries, [true]); assert.equal(engineLoaded(), true); assert.notEqual(store.controller, shell); assert.ok(store.stories.length > 0); @@ -115,10 +129,10 @@ test('a failed load is reported and the next open tries again', async () => { ? Promise.reject(new Error('offline')) : Promise.all([import('./controller.js'), import('./catalog.js')]), }); - await shell.open(); + assert.equal(await shell.open(), undefined); assert.equal(failures, 1); assert.equal(store.mode, 'closed'); - await shell.open(); + assert.equal(await shell.open(), true); assert.equal(attempts, 2, 'the failure was not kept'); assert.equal(store.mode, 'explore'); shell.destroy(); diff --git a/src/stories/controller.js b/src/stories/controller.js index f72acc0c8..327b8ee25 100644 --- a/src/stories/controller.js +++ b/src/stories/controller.js @@ -19,6 +19,20 @@ import { registerNavigationAuthorityListener } from '../navigationPolicy.js'; const PARAM_STORIES = 'stories'; const PARAM_STORY = 'story'; +const PARAM_STORY_TIME = 'storyTime'; +const PARAM_SELECTED_STORY = 'selectedStory'; + +function exploreSelection(params) { + const id = params.get(PARAM_SELECTED_STORY); + const story = id ? storyById(id) : null; + return story && !story.mine ? story.id : null; +} + +function storyTime(params) { + const value = params.get(PARAM_STORY_TIME); + const ms = Number(value); + return value && /^\d+$/.test(value) && Number.isSafeInteger(ms) ? ms : 0; +} /** * Stories: Explore (the story list over the person's own Cesium globe, with @@ -34,19 +48,28 @@ const PARAM_STORY = 'story'; * * @param {{viewer: Cesium.Viewer, * director: import('../scenes/director.js').SceneDirector, - * store: ReturnType}} options + * store: ReturnType, + * onEnter?: () => void}} options */ -export function createStoriesController({ viewer, director, store }) { +export function createStoriesController({ viewer, director, store, onEnter }) { let player = null; let saved = null; // The view a Close is about to restore, once a stopping scene has settled. let pendingView = null; + // Reopening reuses the saved view, but supersedes the old close request. + let closeGeneration = 0; let removeReadout = null; let destroyed = false; // Close steps back over Stories' own entries; the landing popstate is ours. let closingHistory = false; // A Back to Explore traversal is on its way. let steppingBack = false; + let backTimer = 0; + let readyTimer = 0; + function cancelInitialLink() { + clearTimeout(readyTimer); + readyTimer = 0; + } // A call made while a traversal is landing runs from the entry it lands on, // so two traversals never stack (Close after Back to Explore would step // one entry too far). @@ -78,7 +101,7 @@ export function createStoriesController({ viewer, director, store }) { // A draft's THUMBNAIL or tags. 'story-details-changed', ]); - const unsubscribeScenes = director.subscribe?.((change) => { + const unsubscribeScenes = director.subscribe?.(({ change }) => { if (!LIST_CHANGES.has(change?.type) || destroyed) return; store.stories = markRaw(listStories()); if (removePins) { @@ -96,6 +119,8 @@ export function createStoriesController({ viewer, director, store }) { const url = new URL(location.href); url.searchParams.delete(PARAM_STORIES); url.searchParams.delete(PARAM_STORY); + url.searchParams.delete(PARAM_STORY_TIME); + url.searchParams.delete(PARAM_SELECTED_STORY); for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v); if (Object.keys(params).length) url.hash = ''; return url.toString(); @@ -168,6 +193,7 @@ export function createStoriesController({ viewer, director, store }) { } const onPopState = () => { if (destroyed) return; + cancelInitialLink(); const queued = afterTraversal; afterTraversal = null; try { @@ -177,6 +203,8 @@ export function createStoriesController({ viewer, director, store }) { } }; function handlePopState() { + clearTimeout(backTimer); + backTimer = 0; steppingBack = false; if (closingHistory) { closingHistory = false; @@ -189,12 +217,24 @@ export function createStoriesController({ viewer, director, store }) { } const params = new URLSearchParams(location.search); const id = params.get(PARAM_STORY); - if (id && storyById(id)) controller.openStory(id, { fromHistory: true }); + if (id && storyById(id)) + controller.openStory(id, { + fromHistory: true, + atMs: storyTime(params), + }); else if (params.has(PARAM_STORIES)) store.mode === 'closed' ? controller.open({ fromHistory: true }) : controller.backToExplore({ fromHistory: true }); else if (store.mode !== 'closed') controller.close({ fromHistory: true }); + else if (pendingView) { + // Another browser navigation landed while the scene was stopping. + // The destination owns the globe now, so discard the earlier restore. + pendingView = null; + closeGeneration += 1; + document.body.classList.remove('stories-mode'); + shareLink()?.holdWrites?.(false); + } } addEventListener('popstate', onPopState); @@ -209,9 +249,8 @@ export function createStoriesController({ viewer, director, store }) { time: viewer.clock.currentTime.clone(), animate: viewer.clock.shouldAnimate, openedAt: Date.now(), - // The share state (layers, style, camera) as it was, for after a GEV - // scene has changed it. - hash: location.hash, + // Story history entries have no hash. Capture the live globe state. + hash: shareLink()?.snapshotHash?.() ?? location.hash, ranScene: false, // Whether a scene played during this visit, which selects it in // AUTHORING (ranScene clears once Back to Explore has undone the look). @@ -585,7 +624,9 @@ export function createStoriesController({ viewer, director, store }) { saved = pendingView; pendingView = null; } else saveView(); + closeGeneration += 1; document.body.classList.add('stories-mode'); + onEnter?.(); return true; } @@ -678,34 +719,41 @@ export function createStoriesController({ viewer, director, store }) { } const controller = { - open({ fromHistory = false } = {}) { + open({ fromHistory = false, isCurrent } = {}) { + if (destroyed || (isCurrent && !isCurrent())) return false; + cancelInitialLink(); if (!fromHistory && traversing()) { - afterTraversal = () => controller.open(); - return; + if (!isCurrent) afterTraversal = () => controller.open(); + return false; } - if (store.mode !== 'closed') return; - if (!enterStories()) return; - store.picked = null; + if (store.mode !== 'closed' || !enterStories()) return false; + store.picked = fromHistory + ? exploreSelection(new URLSearchParams(location.search)) + : null; showExplore(); if (!fromHistory) navigate({ [PARAM_STORIES]: 'explore' }, true); + return true; }, close({ fromHistory = false, keepCamera = false } = {}) { + if (destroyed) return; + cancelInitialLink(); if (store.mode === 'closed') return; if (!fromHistory && traversing()) { afterTraversal = () => controller.close({ keepCamera }); return; } + const generation = ++closeGeneration; dropPlayer(); stopPins(); viewer.camera.cancelFlight(); - // GEV comes back on screen now; `stories-mode` (keyboard guard, voice - // refusal) stays until the view is back, so nothing acts on GEV under - // a scene that is still tearing down. + // Close the Stories screens now and keep their input guard until the + // scene and share view have finished restoring. document.body.classList.remove('stories-scene'); store.mode = 'closed'; store.storyId = null; store.picked = null; store.expanded = false; + store.toast = ''; const was = saved; saved = null; pendingView = was; @@ -727,9 +775,14 @@ export function createStoriesController({ viewer, director, store }) { canvas.removeEventListener('pointerdown', onDrag); stopWatching(); // Reopened meanwhile (the reopen took `was` over), or torn down. - if (pendingView !== was || destroyed || viewer.isDestroyed?.()) return; + if ( + generation !== closeGeneration || + pendingView !== was || + destroyed || + viewer.isDestroyed?.() + ) + return; pendingView = null; - document.body.classList.remove('stories-mode'); if (!navigated) restoreView(was, { keepCamera }); // AUTHORING shows what it showed before, unless the person opened // the story there. @@ -740,6 +793,7 @@ export function createStoriesController({ viewer, director, store }) { // over the earlier entry instead. if (!keepCamera && !navigated) restoreShareState(was); shareLink()?.holdWrites?.(false); + document.body.classList.remove('stories-mode'); }; if (fromHistory) afterLanding(); else leaveHistory(afterLanding); @@ -759,6 +813,8 @@ export function createStoriesController({ viewer, director, store }) { * @param {{autoplay?: boolean, fromHistory?: boolean, atMs?: number}} [opts] */ openStory(id, { autoplay = false, fromHistory = false, atMs = 0 } = {}) { + if (destroyed) return; + cancelInitialLink(); const story = storyById(id); if (!story) return; if (!fromHistory && traversing()) { @@ -777,6 +833,9 @@ export function createStoriesController({ viewer, director, store }) { store.sheet = 'peek'; store.bigPlay = !autoplay; syncSceneShots(story); + atMs = Number.isFinite(atMs) + ? Math.max(0, Math.min(story.durationMs, Math.round(atMs))) + : 0; store.playback = { wallMs: atMs, worldMs: null, @@ -796,15 +855,26 @@ export function createStoriesController({ viewer, director, store }) { // Opened paused, a scene frames its first shot (or the moment asked). if (atMs || !autoplay) player.seek(atMs); if (autoplay) player.play(); - if (!fromHistory) navigate({ [PARAM_STORY]: story.id }, true); + if (!fromHistory) + navigate( + atMs + ? { [PARAM_STORY]: story.id, [PARAM_STORY_TIME]: atMs } + : { [PARAM_STORY]: story.id }, + true, + ); if (!store.hintSeen) { store.hintSeen = true; store.flashHint(t('Drag the map to explore · Resume any time'), 4200); } }, backToExplore({ fromHistory = false } = {}) { - // A second press while the first is landing does nothing more. - if (!fromHistory && traversing()) return; + if (destroyed) return; + cancelInitialLink(); + // A second Back keeps the traversal, but cancels a story queued since. + if (!fromHistory && traversing()) { + if (steppingBack) afterTraversal = null; + return; + } dropPlayer(); store.expanded = false; if (!fromHistory) { @@ -816,7 +886,9 @@ export function createStoriesController({ viewer, director, store }) { if (params.has(PARAM_STORY) && to != null && depth() > to) { steppingBack = true; // A step that never lands gives up, as Close's does. - setTimeout(() => { + clearTimeout(backTimer); + backTimer = setTimeout(() => { + backTimer = 0; if (!steppingBack) return; steppingBack = false; const queued = afterTraversal; @@ -827,6 +899,10 @@ export function createStoriesController({ viewer, director, store }) { return; } navigate({ [PARAM_STORIES]: 'explore' }, true); + } else { + const params = new URLSearchParams(location.search); + if (params.has(PARAM_SELECTED_STORY)) + store.picked = exploreSelection(params); } showExplore(); }, @@ -855,7 +931,10 @@ export function createStoriesController({ viewer, director, store }) { player.pause(); // After Close has settled: the scene's teardown restores GEV's look // and panels, which would fold the Scenes panel again. - await controller.close({ keepCamera: true }); + const closing = controller.close({ keepCamera: true }); + const generation = closeGeneration; + await closing; + if (destroyed || generation !== closeGeneration) return; director.selectShot?.(s.sceneId, shotId); director.styleManager?.setPanelCollapsed?.('scene-panel', false, { explicit: true, @@ -871,15 +950,35 @@ export function createStoriesController({ viewer, director, store }) { shareLink() { const here = new URL(location.href); const url = new URL(here.pathname, here.origin); - for (const key of [PARAM_STORIES, PARAM_STORY]) - if (here.searchParams.has(key)) - url.searchParams.set(key, here.searchParams.get(key)); + const id = store.mode === 'story' ? store.storyId : store.picked; + const story = id ? storyById(id) : null; + if (store.mode === 'story' && story && !story.mine) { + url.searchParams.set(PARAM_STORY, story.id); + const ms = Math.round(store.playback.wallMs); + if (Number.isSafeInteger(ms) && ms > 0) + url.searchParams.set(PARAM_STORY_TIME, String(ms)); + } else { + url.searchParams.set(PARAM_STORIES, 'explore'); + if (story && !story.mine) + url.searchParams.set(PARAM_SELECTED_STORY, story.id); + } return url.toString(); }, destroy() { if (destroyed) return; - controller.close(); destroyed = true; + cancelInitialLink(); + clearTimeout(backTimer); + clearTimeout(landingTimer); + steppingBack = closingHistory = false; + afterTraversal = landed = null; + dropPlayer(); + stopPins(); + viewer.camera.cancelFlight(); + store.mode = 'closed'; + store.storyId = null; + store.picked = null; + store.expanded = false; // Torn down mid-close: what the close would undo once settled is // undone now (keyboard and voice guard, held share writes). document.body.classList.remove('stories-mode', 'stories-scene'); @@ -893,7 +992,6 @@ export function createStoriesController({ viewer, director, store }) { canvas.removeEventListener('pointerup', onExploreInput); canvas.removeEventListener('pointercancel', onExploreInput); canvas.removeEventListener('wheel', onExploreInput); - stopTour(); canvas.removeEventListener('pointerup', onUp); }, }; @@ -901,17 +999,21 @@ export function createStoriesController({ viewer, director, store }) { // A shared link opens where it points once GEV has finished loading. const params = new URLSearchParams(location.search); if (params.has(PARAM_STORY) || params.has(PARAM_STORIES)) { - const id = params.get(PARAM_STORY); const started = Date.now(); const whenReady = () => { + readyTimer = 0; if (destroyed) return; + const params = new URLSearchParams(location.search); + if (!params.has(PARAM_STORY) && !params.has(PARAM_STORIES)) return; + const id = params.get(PARAM_STORY); + const atMs = storyTime(params); const loading = document.getElementById('loading-screen'); if ( loading && !loading.classList.contains('hidden') && Date.now() - started < 30000 ) { - setTimeout(whenReady, 300); + readyTimer = setTimeout(whenReady, 300); return; } // A reload, or Back/Forward into a Stories entry: its history is @@ -920,11 +1022,19 @@ export function createStoriesController({ viewer, director, store }) { // GEV's boot wrote its share hash onto the entry: Stories' entries // carry none. const own = Object.fromEntries( - [...params].filter(([k]) => k === PARAM_STORIES || k === PARAM_STORY), + [...params].filter( + ([key]) => + key === PARAM_STORIES || + key === PARAM_STORY || + (key === PARAM_STORY_TIME && id && atMs) || + (key === PARAM_SELECTED_STORY && + !id && + params.has(PARAM_STORIES)), + ), ); history.replaceState(history.state, '', urlFor(own)); if (id && storyById(id)) - controller.openStory(id, { fromHistory: true }); + controller.openStory(id, { fromHistory: true, atMs }); else { controller.open({ fromHistory: true }); if (id) store.flashToast(t('That story is not available here')); @@ -933,19 +1043,24 @@ export function createStoriesController({ viewer, director, store }) { } // A new link: Explore sits under a story it opens, so Back lands there. const landing = { stories: 'explore', depth: 0, explore: 0 }; + const selected = + !id && params.has(PARAM_STORIES) ? exploreSelection(params) : null; history.replaceState( { ...(history.state ?? {}), gevStories: landing }, '', - urlFor({ [PARAM_STORIES]: 'explore' }), + urlFor({ + [PARAM_STORIES]: 'explore', + ...(selected ? { [PARAM_SELECTED_STORY]: selected } : {}), + }), ); - if (id && storyById(id)) controller.openStory(id); + if (id && storyById(id)) controller.openStory(id, { atMs }); else { controller.open({ fromHistory: true }); // A story saved on someone else's device, or no longer here. if (id) store.flashToast(t('That story is not available here')); } }; - setTimeout(whenReady, 300); + readyTimer = setTimeout(whenReady, 300); } if (import.meta.env?.DEV) globalThis.__gevStories = { viewer, controller }; diff --git a/src/stories/controller.test.mjs b/src/stories/controller.test.mjs index ee5594acc..c8569df6e 100644 --- a/src/stories/controller.test.mjs +++ b/src/stories/controller.test.mjs @@ -6,6 +6,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import * as Cesium from 'cesium'; import { createPinia, setActivePinia } from 'pinia'; +import { createStateChannel } from '../app/stateChannel.js'; registerHooks({ load(url, context, next) { @@ -123,21 +124,31 @@ function setup(options = {}) { const store = useStoriesStore(); const viewer = fakeViewer(); const director = fakeDirector(options); - const controller = createStoriesController({ viewer, director, store }); + const controller = createStoriesController({ + viewer, + director, + store, + onEnter: options.onEnter, + }); store.connect(controller, listStories()); return { store, viewer, director, controller }; } test('Close steps back over every entry Stories pushed', async () => { - const { controller } = setup(); + const entered = []; + const { controller } = setup({ + onEnter: () => + entered.push(document.body.classList.contains('stories-mode')), + }); const steps = []; const go = history.go; history.go = (n) => steps.push(n); try { - controller.open(); + assert.equal(controller.open(), true); assert.equal(history.state.gevStories.depth, 1); controller.openStory('gev:flights-radar'); assert.equal(history.state.gevStories.depth, 2); + assert.deepEqual(entered, [true]); await controller.close(); // Back after Close would otherwise land on ?story=… and reopen it. assert.deepEqual(steps, [-2]); @@ -158,8 +169,13 @@ test('Close from a Stories link clears Stories from the URL in place', async () }); test('Cockpit keeps the camera: Stories does not open', () => { - const { controller, store, director } = setup({ refuse: true }); - controller.open(); + const { controller, store, director } = setup({ + refuse: true, + onEnter: () => assert.fail('refused entry should not stop voice'), + }); + assert.equal(controller.open({ isCurrent: () => false }), false); + assert.deepEqual(director.claims, []); + assert.equal(controller.open(), false); assert.equal(store.mode, 'closed'); assert.equal(director.stops, 0); // The navigation policy shows the refusal; it needs a sentence for the noun. @@ -169,17 +185,21 @@ test('Cockpit keeps the camera: Stories does not open', () => { }); test('reopening while a scene tears down keeps the view from before Stories', async () => { - const { controller, viewer, director } = setup(); + const { controller, viewer, director, store } = setup(); const before = viewer.camera.positionWC; controller.open(); controller.openStory('gev:bhote-koshi-nepal-scene'); director.running = true; - const closing = controller.close(); + const toast = store.hostedToast; + const closing = controller.openInGev(); // The scene has moved the camera; the person opens Stories again at once. viewer.camera.positionWC = new Cesium.Cartesian3(9, 9, 9); controller.open(); director.running = false; await closing; + assert.deepEqual(director.selected, []); + assert.deepEqual(director.styleManager.panels, []); + assert.equal(store.hostedToast, toast); assert.equal( viewer.camera.views.length, 0, @@ -204,14 +224,36 @@ test('after a GEV scene, the person’s view comes back once the scene has torn controller.destroy(); }); -test('a share link carries the story, not the sender’s camera and layers', () => { - const { controller } = setup(); +test('Share links to the selection and captures the playing story’s timeline', () => { + const { controller, store } = setup(); controller.open(); + assert.equal(new URL(controller.shareLink()).search, '?stories=explore'); + controller.pick('gev:orbital-watch'); + assert.equal( + new URL(controller.shareLink()).search, + '?stories=explore&selectedStory=gev%3Aorbital-watch', + ); controller.openStory('gev:flights-radar'); + store.playback = { ...store.playback, playing: true, wallMs: 1250.6 }; const link = new URL(controller.shareLink()); - assert.equal(link.searchParams.get('story'), 'gev:flights-radar'); + assert.deepEqual( + [...link.searchParams], + [ + ['story', 'gev:flights-radar'], + ['storyTime', '1251'], + ], + ); assert.equal(link.hash, ''); - assert.equal(link.searchParams.has('x'), false, 'no other query parameters'); + store.playback.wallMs = 1850; + assert.equal( + new URL(controller.shareLink()).searchParams.get('storyTime'), + '1850', + ); + controller.backToExplore({ fromHistory: true }); + assert.equal( + new URL(controller.shareLink()).search, + '?stories=explore&selectedStory=gev%3Aflights-radar', + ); controller.destroy(); }); @@ -227,7 +269,7 @@ function recordGo(t) { } test('Back to Explore after a related story steps past both stories', (t) => { - const { controller } = setup(); + const { controller, store } = setup(); const steps = recordGo(t); controller.open(); controller.openStory('gev:flights-radar'); @@ -235,9 +277,19 @@ test('Back to Explore after a related story steps past both stories', (t) => { assert.equal(history.state.gevStories.depth, 3); assert.equal(history.state.gevStories.explore, 1); controller.backToExplore(); - // A second click before the traversal lands does nothing more. + controller.openStory('gev:flights-radar'); // queued behind Back + // The latest Back cancels that queued story without another traversal. controller.backToExplore(); assert.deepEqual(steps, [-2]); + history.replaceState( + { gevStories: { stories: 'explore', depth: 1, explore: 1 } }, + '', + '/?stories=explore', + ); + dispatchEvent(new PopStateEvent('popstate')); + assert.equal(store.mode, 'explore'); + assert.equal(store.storyId, null); + assert.equal(history.state.gevStories.depth, 1, 'no queued story pushed'); controller.destroy(); }); @@ -246,13 +298,13 @@ test('a second Close after a quick reopen still waits for the scene to tear down controller.open(); controller.openStory('gev:bhote-koshi-nepal-scene'); director.running = true; - controller.close(); + const first = controller.close({ keepCamera: true }); controller.open(); // reopened while the scene is still stopping const closing = controller.close(); // Explore: no GEV story on screen assert.ok(closing, 'this Close waits too'); assert.equal(viewer.camera.views.length, 0, 'nothing restored yet'); setTimeout(() => (director.running = false), 120); - await closing; + await Promise.all([first, closing]); assert.equal(viewer.camera.views.length, 1); controller.destroy(); }); @@ -262,7 +314,7 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back' history.replaceState( { gevStories: { story: 'gev:flights-radar', depth: 2, explore: 1 } }, '', - '/?story=gev%3Aflights-radar', + '/?story=gev%3Aflights-radar&storyTime=1250', ); const steps = recordGo(t); const store = useStoriesStore(); @@ -274,6 +326,8 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back' store.connect(controller, listStories()); await new Promise((resolve) => setTimeout(resolve, 400)); assert.equal(store.storyId, 'gev:flights-radar'); + assert.equal(store.playback.wallMs, 1250); + assert.equal(store.playback.playing, false); assert.equal(history.state.gevStories.depth, 2, 'no extra entry pushed'); await controller.close(); assert.deepEqual(steps, [-2]); @@ -282,7 +336,7 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back' test('a new story link puts Explore under the story', async (t) => { setActivePinia(createPinia()); - history.replaceState(null, '', '/?story=gev%3Aflights-radar'); + history.replaceState(null, '', '/?story=gev%3Aflights-radar&storyTime=1250'); const steps = recordGo(t); const store = useStoriesStore(); const controller = createStoriesController({ @@ -293,8 +347,11 @@ test('a new story link puts Explore under the story', async (t) => { store.connect(controller, listStories()); await new Promise((resolve) => setTimeout(resolve, 400)); assert.equal(store.storyId, 'gev:flights-radar'); + assert.equal(store.playback.wallMs, 1250); + assert.equal(store.playback.playing, false); assert.deepEqual(history.state.gevStories, { story: 'gev:flights-radar', + storyTime: 1250, depth: 1, explore: 0, }); @@ -377,6 +434,29 @@ function land(hash = '#v=2&lat=1') { dispatchEvent(new PopStateEvent('popstate')); } +test('a second browser Back during scene teardown supersedes the Stories restore', async () => { + const { controller, director, store, viewer } = setup(); + const share = director.styleManager.shareLinkManager; + const holds = []; + share.holdWrites = (held) => holds.push(held); + director.selection = () => ({ sceneId: 'previous', shotId: 'shot-1' }); + controller.open(); + controller.openStory('gev:bhote-koshi-nepal-scene'); + director.running = true; + land(); + assert.equal(store.mode, 'closed'); + land('#v=2&lat=2'); + director.running = false; + await tick(0); + assert.equal(location.hash, '#v=2&lat=2'); + assert.equal(viewer.camera.views.length, 0); + assert.deepEqual(share.restored, []); + assert.deepEqual(director.selected, []); + assert.deepEqual(holds, [true, false]); + assert.equal(document.body.classList.contains('stories-mode'), false); + controller.destroy(); +}); + test('Close after a GEV scene puts the share state back once the step back lands', async (t) => { const { controller, director } = setup(); const steps = recordGo(t); @@ -386,8 +466,10 @@ test('Close after a GEV scene puts the share state back once the step back lands await controller.close(); assert.deepEqual(steps, [-2]); assert.deepEqual(restored, [], 'not before the landing'); + assert.equal(document.body.classList.contains('stories-mode'), true); land(); assert.deepEqual(restored, ['v=2&lat=1']); + assert.equal(document.body.classList.contains('stories-mode'), false); controller.destroy(); }); @@ -435,7 +517,7 @@ test('a reloaded Stories entry drops the share hash GEV wrote on boot', async () history.replaceState( { gevStories: { stories: 'explore', depth: 1, explore: 1 } }, '', - '/?stories=explore#v=2&lat=7', + '/?stories=explore&selectedStory=gev%3Aorbital-watch#v=2&lat=7', ); const store = useStoriesStore(); const controller = createStoriesController({ @@ -447,7 +529,19 @@ test('a reloaded Stories entry drops the share hash GEV wrote on boot', async () await new Promise((resolve) => setTimeout(resolve, 400)); assert.equal(store.mode, 'explore'); assert.equal(location.hash, ''); - assert.equal(new URL(location.href).searchParams.get('stories'), 'explore'); + assert.equal(store.picked, 'gev:orbital-watch'); + assert.equal( + location.search, + '?stories=explore&selectedStory=gev%3Aorbital-watch', + ); + const exploreState = history.state; + const exploreUrl = location.href; + controller.openStory('gev:flights-radar'); + assert.equal(location.search, '?story=gev%3Aflights-radar'); + history.replaceState(exploreState, '', exploreUrl); + dispatchEvent(new PopStateEvent('popstate')); + assert.equal(store.mode, 'explore'); + assert.equal(store.picked, 'gev:orbital-watch'); controller.destroy(); }); @@ -478,13 +572,13 @@ test('a scene saved to Stories from AUTHORING joins the list at once', () => { shotCount: 2, }, ]; - listener({ type: 'stories-changed' }); + listener({ change: { type: 'stories-changed' } }); const story = store.byId('gev:my-scene'); assert.equal(story?.title, 'Harbour at dawn'); assert.equal(story.mine, true); assert.equal(store.stories[0].id, 'gev:my-scene', 'the person’s own first'); mine = []; - listener({ type: 'stories-changed' }); + listener({ change: { type: 'stories-changed' } }); assert.equal(store.byId('gev:my-scene'), null, 'removed from Stories'); controller.destroy(); assert.equal(listener, null, 'unsubscribed'); @@ -492,10 +586,13 @@ test('a scene saved to Stories from AUTHORING joins the list at once', () => { test('Back to Explore after a scene puts the look back once the scene has torn down, then frames Explore', async () => { const { controller, viewer, director } = setup(); + history.replaceState(null, '', '/'); const flights = []; viewer.camera.flyTo = (f) => flights.push(f); viewer.camera.flyToBoundingSphere = (f) => flights.push(f); const share = director.styleManager.shareLinkManager; + const original = 'v=2&lat=1&style=normal'; + share.snapshotHash = () => original; // GEV's restore writes the hash it applies; Explore's address drops it. share.restore = function (hash) { this.restored.push(hash); @@ -506,13 +603,18 @@ test('Back to Explore after a scene puts the look back once the scene has torn d controller.openStory('gev:bhote-koshi-nepal-scene'); director.running = true; flights.length = 0; - controller.backToExplore({ fromHistory: true }); + history.replaceState( + { gevStories: { stories: 'explore', depth: 1, explore: 1 } }, + '', + '/?stories=explore', + ); + dispatchEvent(new PopStateEvent('popstate')); await tick(30); assert.deepEqual(share.restored, [], 'not under the stopping scene'); assert.equal(flights.length, 0, 'Explore waits for the scene'); director.running = false; await tick(40); - assert.deepEqual(share.restored, ['v=2&lat=1']); + assert.deepEqual(share.restored, [original]); assert.equal(location.hash, '', 'the address names only Stories'); assert.equal(flights.length, 1, 'then Explore frames the globe'); // A later Back to Explore with no scene in between restores nothing more. @@ -579,9 +681,16 @@ test('Explore tours from story to story once idle, stops on a pick or a touch, a test('a new Explore link keeps the address free of the share hash GEV writes as Stories opens', async () => { setActivePinia(createPinia()); - history.replaceState(null, '', '/?stories=explore'); + history.replaceState( + null, + '', + '/?stories=explore&selectedStory=gev%3Aorbital-watch', + ); const store = useStoriesStore(); const director = fakeDirector(); + const playbackCalls = []; + director.startScene = () => playbackCalls.push('start'); + director.seekScene = () => playbackCalls.push('seek'); // Holding writes first writes the view change still waiting. director.styleManager.shareLinkManager.holdWrites = (held) => { if (held) history.replaceState(history.state, '', `${location.search}#v=2`); @@ -595,7 +704,13 @@ test('a new Explore link keeps the address free of the share hash GEV writes as await tick(400); assert.equal(store.mode, 'explore'); assert.equal(location.hash, ''); - assert.equal(location.search, '?stories=explore'); + assert.equal( + location.search, + '?stories=explore&selectedStory=gev%3Aorbital-watch', + ); + assert.equal(store.picked, 'gev:orbital-watch'); + assert.equal(store.storyId, null); + assert.deepEqual(playbackCalls, []); controller.destroy(); }); @@ -690,13 +805,12 @@ test('Close after Back to Explore still puts AUTHORING’s selection back', asyn controller.destroy(); }); -test('the person’s unsaved scenes list as drafts, which cannot be shared', () => { +test('unsaved scenes appear as local drafts and disappear when deleted', () => { setActivePinia(createPinia()); history.replaceState(null, '', '/'); const store = useStoriesStore(); const director = fakeDirector(); - director.subscribe = () => () => {}; - director.draftScenes = () => [ + const drafts = [ { id: 'sketch', title: 'Sketch', @@ -706,6 +820,9 @@ test('the person’s unsaved scenes list as drafts, which cannot be shared', () tags: [], }, ]; + const channel = createStateChannel(() => ({ scenes: drafts })); + director.subscribe = channel.subscribe; + director.draftScenes = () => drafts; const controller = createStoriesController({ viewer: fakeViewer(), director, @@ -715,6 +832,10 @@ test('the person’s unsaved scenes list as drafts, which cannot be shared', () const draft = store.byId('gev:sketch'); assert.equal(draft?.draft, true); assert.equal(draft.mine, true, 'local only: no Share'); + drafts.length = 0; + channel.publish({ type: 'scene-deleted' }); + controller.open(); + assert.equal(store.byId('gev:sketch'), null); controller.destroy(); }); @@ -755,20 +876,31 @@ test('the tour waits again after a wheel turn or a cancelled press, and a list c assert.equal(flights.length, before + 1, `${type}: then tours`); } canvas.dispatchEvent(new Event('pointerdown')); - listener({ type: 'stories-changed' }); + listener({ change: { type: 'stories-changed' } }); const held = flights.length; t.mock.timers.tick(30000); assert.equal(flights.length, held, 'nothing flies under the drag'); again.destroy(); }); -test('teardown mid-close lets the share link write again', () => { - const { controller, director } = setup(); +test('teardown mid-close releases share writes and cancels a queued reopen', async (t) => { + t.mock.timers.enable({ apis: ['setTimeout'] }); + const { controller, director, store, viewer } = setup(); + recordGo(t); const held = []; director.styleManager.shareLinkManager.holdWrites = (on) => held.push(on); + let flights = 0; + viewer.camera.flyTo = () => flights++; controller.open(); + await controller.close(); + controller.open(); // queued until the Close traversal lands controller.destroy(); + const before = flights; assert.equal(held.at(-1), false); + t.mock.timers.tick(3000); + assert.equal(store.mode, 'closed'); + assert.equal(held.at(-1), false, 'no late reopen holds writes again'); + assert.equal(flights, before, 'no late flight after teardown'); }); test('place names name only a shipped scene’s untitled shots', () => { @@ -785,3 +917,76 @@ test('place names name only a shipped scene’s untitled shots', () => { ); controller.destroy(); }); + +test('new navigation cancels a delayed initial story link', async (t) => { + t.mock.timers.enable({ apis: ['setTimeout'] }); + for (const action of ['back', 'open', 'close']) { + setActivePinia(createPinia()); + history.replaceState(null, '', '/?story=gev%3Aflights-radar'); + const store = useStoriesStore(); + const controller = createStoriesController({ + viewer: fakeViewer(), + director: fakeDirector(), + store, + }); + store.connect(controller, listStories()); + try { + if (action === 'back') land(); + else if (action === 'open') controller.open(); + else controller.close(); + const url = location.href; + t.mock.timers.tick(400); + assert.equal( + store.mode, + action === 'open' ? 'explore' : 'closed', + action, + ); + assert.equal(store.storyId, null, action); + assert.equal( + location.href, + url, + 'the old link does not rewrite navigation', + ); + } finally { + controller.destroy(); + } + } +}); + +test('an earlier Back timeout cannot release a later traversal', async (t) => { + t.mock.timers.enable({ apis: ['setTimeout'] }); + const { controller, store } = setup(); + const steps = recordGo(t); + const landExplore = () => { + history.replaceState( + { gevStories: { stories: 'explore', depth: 1, explore: 1 } }, + '', + '/?stories=explore', + ); + dispatchEvent(new PopStateEvent('popstate')); + }; + try { + controller.open(); + controller.openStory('gev:flights-radar'); + controller.backToExplore(); + landExplore(); + t.mock.timers.tick(1500); + controller.openStory('gev:orbital-watch'); + controller.backToExplore(); + controller.close(); + t.mock.timers.tick(600); + assert.equal(store.mode, 'story', 'Close still waits for the second Back'); + assert.deepEqual(steps, [-1, -1]); + landExplore(); + // Drain the director's already-idle promise without advancing timers. + for (let i = 0; i < 12; i++) await Promise.resolve(); + assert.equal(store.mode, 'closed'); + assert.deepEqual( + steps, + [-1, -1, -1], + 'queued Close runs once after landing', + ); + } finally { + controller.destroy(); + } +}); diff --git a/src/stories/gevPlayer.js b/src/stories/gevPlayer.js index 5a43a624a..35210ea65 100644 --- a/src/stories/gevPlayer.js +++ b/src/stories/gevPlayer.js @@ -44,7 +44,7 @@ export function createGevPlayer(director, story, hooks = {}) { let shotIndex = 0; let destroyed = false; // Each Play, Pause, Seek and Destroy takes a new number; a Play that waited - // for a teardown or a start goes ahead only if nothing came after it. + // for a teardown or a run to finish acts only if nothing came after it. let request = 0; const state = () => ({ @@ -65,7 +65,8 @@ export function createGevPlayer(director, story, hooks = {}) { wallMs = (snap.sceneElapsedSec ?? 0) * 1000; shotIndex = snap.shotIndex ?? shotIndex; playing = !!snap.running && !snap.seeking; - if (!playing && wallMs >= durationMs - 250) wallMs = durationMs; + if (!playing && !snap.seeking && wallMs >= durationMs - 250) + wallMs = durationMs; tick(); }); @@ -100,13 +101,9 @@ export function createGevPlayer(director, story, hooks = {}) { afterShotId, preview: true, }); - if (destroyed) return; - if (mine !== request) { - // Paused or scrubbed while the run was starting: that wins. - if (result?.started) - director.seekScene(sceneId, durationMs ? wallMs / durationMs : 0); - return; - } + // startScene resolves after the run finishes, not when it starts. + // A newer pause, seek or play already owns the director by then. + if (destroyed || mine !== request) return; if (!result?.started) { playing = false; tick(); diff --git a/src/stories/gevPlayer.test.mjs b/src/stories/gevPlayer.test.mjs index eeef43108..e94093d19 100644 --- a/src/stories/gevPlayer.test.mjs +++ b/src/stories/gevPlayer.test.mjs @@ -1,5 +1,5 @@ // A GEV scene's Play waits for the last run to tear down and for the new run -// to start; a Pause, Seek or Destroy meanwhile must win. +// to finish; a Pause, Seek or Destroy meanwhile must win. import test from 'node:test'; import assert from 'node:assert/strict'; import { createGevPlayer } from './gevPlayer.js'; @@ -10,7 +10,7 @@ const story = { chapters: [{ wallMs: 0 }, { wallMs: 30000 }], }; -/** A director whose start resolves when the test says so. */ +/** A director whose run starts immediately and ends when the test says so. */ function deferredDirector({ running = false } = {}) { const calls = []; let release = null; @@ -30,14 +30,15 @@ function deferredDirector({ running = false } = {}) { seekScene: (id, f) => calls.push(`seek ${f}`), startScene: () => { calls.push('start'); + director.running = true; return new Promise((resolve) => { release = () => { - director.running = true; + director.running = false; resolve({ started: true }); }; }); }, - finishStart: () => release?.(), + finishRun: () => release?.(), }; return director; } @@ -70,17 +71,39 @@ test('a Seek during the last run’s teardown cancels the waiting Play', async ( assert.equal(player.state.wallMs, 30000); }); -test('a Pause while the run is starting is applied once it has started', async () => { +test('a stopped run’s completion does not repeat a newer seek', async () => { const director = deferredDirector(); const player = createGevPlayer(director, story); const playing = player.play(); await turns(); assert.deepEqual(director.calls, ['start']); + assert.equal(director.running, true); player.pause(); - director.finishStart(); + player.seek(30000); + director.finishRun(); await playing; - // Pause seeks once when pressed, and again after the late start. - assert.equal(director.calls.filter((c) => c.startsWith('seek')).length, 2); + assert.deepEqual(director.calls, ['start', 'seek 0', 'seek 0.5']); + assert.equal(player.state.playing, false); + assert.equal(player.state.wallMs, 30000); +}); + +test('a paused seek keeps its exact position near the end of a story', () => { + const director = deferredDirector(); + let publishClock; + director.subscribeSceneClock = (listener) => { + publishClock = listener; + return () => {}; + }; + const player = createGevPlayer(director, story); + player.seek(59800); + publishClock({ + sceneId: story.sceneId, + sceneElapsedSec: 59.8, + sceneDurationSec: 60, + running: false, + seeking: true, + }); + assert.equal(player.state.wallMs, 59800); assert.equal(player.state.playing, false); }); diff --git a/src/ui/views/stories/StoriesHeader.vue b/src/ui/views/stories/StoriesHeader.vue index e53d35b3b..72502064a 100644 --- a/src/ui/views/stories/StoriesHeader.vue +++ b/src/ui/views/stories/StoriesHeader.vue @@ -22,15 +22,19 @@ const props = defineProps({ const emit = defineEmits(['back', 'home', 'crumb', 'search']); const store = useStoriesStore(); // A scene saved on this device only: a link to it opens nothing elsewhere. -const localOnly = computed(() => !!store.byId(store.storyId)?.mine); +const localOnly = computed( + () => + !!store.byId(props.screen === 'story' ? store.storyId : store.picked)?.mine, +); async function share() { const what = props.screen === 'story' ? t('Story') : t('Stories'); + const url = store.controller.shareLink(); try { - await navigator.clipboard.writeText(store.controller.shareLink()); + await navigator.clipboard.writeText(url); store.flashToast(t('{what} link copied', { what })); } catch { - store.flashToast(t('Copy this link: {url}', { url: location.href }), 4000); + store.flashToast(t('Copy this link: {url}', { url }), 4000); } } // Long titles scroll gently so the whole name can be read. @@ -131,7 +135,7 @@ onBeforeUnmount(() => observer?.disconnect()); - {{ t(c) }}
@@ -623,10 +619,7 @@ defineExpose({ alt="" loading="lazy" /> - {{ t('LIVE') }} - {{ + {{ s.draft ? t('DRAFT') : t('STORY') }} {{ fmtDur(s.durationMs) }} diff --git a/src/ui/views/stories/StoryScreen.vue b/src/ui/views/stories/StoryScreen.vue index 058190f97..ad32f837f 100644 --- a/src/ui/views/stories/StoryScreen.vue +++ b/src/ui/views/stories/StoryScreen.vue @@ -342,7 +342,7 @@ watch([k, page], () => nextTick(sizeCard));
{{ - story.live ? t('LIVE') : story.draft ? t('DRAFT') : t('STORY') + story.draft ? t('DRAFT') : t('STORY') }}
{{ title }}
From 78b8d8dc786cdc5237ac3ed1a36d1f7e9583c46b Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:13:06 -0800 Subject: [PATCH 29/34] Stories: read whether the story was playing before the press stops it The director's own pointerdown listener, added first, stops a run whose camera it drives before Stories heard the press, so the tap still played the story again. Stories now reads the press in the capture phase, and its tap listeners are removed on teardown. --- src/stories/controller.js | 8 +++++--- src/stories/controller.test.mjs | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/stories/controller.js b/src/stories/controller.js index 247384365..97106fda8 100644 --- a/src/stories/controller.js +++ b/src/stories/controller.js @@ -745,7 +745,8 @@ export function createStoriesController({ let downAt = null; // Whether the story was playing when the tap began: a camera move the // scene drives frame by frame stops on the press itself, before the tap - // ends, and that tap still means pause. + // ends, and that tap still means pause. The press is read in the capture + // phase, before the director's own listener can stop the run. let playingAtDown = false; const onDown = (e) => { downAt = [e.clientX, e.clientY]; @@ -768,7 +769,7 @@ export function createStoriesController({ store.bigPlay = true; } else player.play(); }; - canvas.addEventListener('pointerdown', onDown); + canvas.addEventListener('pointerdown', onDown, true); canvas.addEventListener('pointerup', onUp); /** @returns {boolean} False when the camera is not free (Cockpit). */ @@ -1237,7 +1238,8 @@ export function createStoriesController({ useInstalledScenes(null); removeEventListener('popstate', onPopState); removeEventListener('popstate', onLandingCapture, true); - canvas.removeEventListener('pointerdown', onDown); + canvas.removeEventListener('pointerdown', onDown, true); + canvas.removeEventListener('pointerup', onUp); canvas.removeEventListener('pointerdown', onExploreInput); canvas.removeEventListener('pointerup', onExploreInput); canvas.removeEventListener('pointercancel', onExploreInput); diff --git a/src/stories/controller.test.mjs b/src/stories/controller.test.mjs index 0c613420d..6ee2039a4 100644 --- a/src/stories/controller.test.mjs +++ b/src/stories/controller.test.mjs @@ -783,7 +783,24 @@ test('a story opened while the scene tears down is not undone by the late restor }); test('a tap pauses a story whose camera move stopped on the press', async () => { - const { controller, store, director, canvas } = setup(); + setActivePinia(createPinia()); + history.replaceState(null, '', '/?x=1#v=2&lat=1'); + const store = useStoriesStore(); + const scene = fakeScene(); + const { canvas } = scene; + // As in the app, the director listens for the press before Stories does, + // and stopping its run publishes a stopped clock at once. + canvas.addEventListener('pointerdown', () => { + store.playback = { ...store.playback, playing: false }; + }); + const director = fakeDirector(); + const controller = createStoriesController({ + viewer: scene.viewer, + director, + store, + clock: fakeClock(), + }); + store.connect(controller, listStories()); controller.openStory('gev:flights-radar'); await tick(20); let starts = 0; @@ -793,9 +810,7 @@ test('a tap pauses a story whose camera move stopped on the press', async () => }; store.playback = { ...store.playback, playing: true }; canvas.dispatchEvent(new Event('pointerdown')); - // A camera move the scene drives frame by frame stops on the press, so the - // story already reads as stopped when the tap ends. - store.playback = { ...store.playback, playing: false }; + assert.equal(store.playback.playing, false, 'the press stopped the run'); canvas.dispatchEvent(new Event('pointerup')); await tick(20); assert.equal(starts, 0, 'the tap does not play it again'); From 9e6207d7f277577a5fe1488bea525d801938b6d5 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:14:27 -0800 Subject: [PATCH 30/34] Stories: the button sits left of elements marked data-stories-corner The corner controls are the ACTIVE STYLE readout and any element marked with data-stories-corner, looked for again for 20 s after Stories mounts, in place of an element id this app never has. --- docs/CURRENT-STATE.md | 5 +++-- src/stories/format.js | 18 ++++++++++++++++-- src/ui/storiesCredit.test.mjs | 24 ++++++++++++++++++++++-- src/ui/views/StoriesView.vue | 22 ++++++++++++++-------- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 7a6a56a88..72bbd4914 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -780,8 +780,9 @@ Inside an inline embed Stories is not offered: the URL and history are the host's. The Stories button sits left of whatever holds GEV's top-right corner: the -ACTIVE STYLE readout, or an element placed in that corner (`#account-control`, -with or beside the readout). On GEV's phone layout, +ACTIVE STYLE readout (`#style-indicator`), or an element marked with +`data-stories-corner` (with or beside the readout; one added after Stories +mounts is found within 20 s). On GEV's phone layout, where neither shows, it is icon-only under the corner-actions column (`#corner-actions`), aligned with its right edge. The first-visit popup is a labelled region that does not take focus. The story page's rail offers diff --git a/src/stories/format.js b/src/stories/format.js index 20a99bed3..f960c5882 100644 --- a/src/stories/format.js +++ b/src/stories/format.js @@ -30,10 +30,24 @@ export function creditPlacement({ map, feed, width, height }) { }; } +/** + * The controls in GEV's top-right corner: the ACTIVE STYLE readout + * (`#style-indicator`) and any element marked with `data-stories-corner`. + * @param {Document|Element} root Where to look. + * @returns {Element[]} + */ +export function cornerControls(root) { + return [ + root.querySelector('#style-indicator'), + ...root.querySelectorAll('[data-stories-corner]'), + ].filter(Boolean); +} + /** * Where the Stories button sits: just left of the leftmost visible control - * in GEV's top-right corner — the ACTIVE STYLE readout, or an element placed - * in that corner (with or beside the readout) — top-aligned with it. + * in GEV's top-right corner — the ACTIVE STYLE readout, or an element marked + * with `data-stories-corner` (with or beside the readout) — 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. diff --git a/src/ui/storiesCredit.test.mjs b/src/ui/storiesCredit.test.mjs index c77accb01..803ee62cd 100644 --- a/src/ui/storiesCredit.test.mjs +++ b/src/ui/storiesCredit.test.mjs @@ -1,7 +1,12 @@ +import '../testSupport/registerDom.mjs'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import test from 'node:test'; -import { creditPlacement, entryPlacement } from '../stories/format.js'; +import { + cornerControls, + creditPlacement, + entryPlacement, +} from '../stories/format.js'; const css = readFileSync( new URL('./styles/stories.css', import.meta.url), @@ -120,6 +125,20 @@ test('the measured place keeps the credit inside the map and on screen', () => { assert.match(view, /root\.removeProperty\('--gs-credit-left'\)/); }); +test('the corner controls are the readout and elements marked data-stories-corner', () => { + const root = document.createElement('div'); + assert.deepEqual(cornerControls(root), [], 'nothing there yet'); + const readout = root.appendChild(document.createElement('div')); + readout.id = 'style-indicator'; + const other = root.appendChild(document.createElement('div')); + assert.deepEqual(cornerControls(root), [readout], 'an unmarked element is not'); + // A marked element added later counts on the next look. + const marked = root.appendChild(document.createElement('button')); + marked.setAttribute('data-stories-corner', ''); + assert.deepEqual(cornerControls(root), [readout, marked]); + assert.ok(other); +}); + test('the Stories button sits left of whatever is in the top-right corner', () => { const box = (left, top, width, height) => ({ left, @@ -134,7 +153,8 @@ test('the Stories button sits left of whatever is in the top-right corner', () = top: 24, right: 270, }); - // An element placed beside the readout; the leftmost wins. + // An element marked with data-stories-corner beside the readout; the + // leftmost wins. assert.deepEqual( entryPlacement([box(1650, 24, 220, 60), box(1898, 22, 38, 38)], 1960), { top: 24, right: 320 }, diff --git a/src/ui/views/StoriesView.vue b/src/ui/views/StoriesView.vue index e3740402e..1c3ce552e 100644 --- a/src/ui/views/StoriesView.vue +++ b/src/ui/views/StoriesView.vue @@ -12,7 +12,11 @@ import { storeToRefs } from 'pinia'; import { t } from '../../i18n/index.js'; import { useStoriesStore } from '../stores/stories.js'; import { GEV_LOGO_SYMBOL } from '../../stories/gevLogo.js'; -import { creditPlacement, entryPlacement } from '../../stories/format.js'; +import { + cornerControls, + creditPlacement, + entryPlacement, +} from '../../stories/format.js'; import { guardStoriesKeyboard } from '../../stories/keyboard.js'; // The screens, their styles and the story data load with Stories (see @@ -36,15 +40,15 @@ const reduceMotion = () => globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches; // ── Entry: in GEV's top-right row, left of what sits in the corner ── -// GEV has its ACTIVE STYLE readout there; an element placed in that corner -// (#account-control, with or beside the readout) can come after Stories mounts. -const CORNER = ['style-indicator', 'account-control']; +// GEV has its ACTIVE STYLE readout there; an element marked with +// data-stories-corner (with or beside the readout) can come after Stories +// mounts (cornerControls). // 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()), + cornerControls(document).map((el) => el.getBoundingClientRect()), innerWidth, document.getElementById(COLUMN)?.getBoundingClientRect() ?? null, ); @@ -66,15 +70,17 @@ function watchCorner() { }); } if (globalThis.ResizeObserver) cornerObserver ??= new ResizeObserver(placeEntry); - for (const id of [...CORNER, COLUMN]) { - const el = document.getElementById(id); + for (const el of [ + ...cornerControls(document), + document.getElementById(COLUMN), + ]) { if (el && cornerObserver && !observed.has(el)) { cornerObserver.observe(el); observed.add(el); } } // Keep looking for a while for a control that mounts late. - if (observed.size < CORNER.length + 1 && ++entryTries < 20) + if (++entryTries < 20) entryTimer = setTimeout(watchCorner, 1000); } From c3b8013038960e599a67080e4c6eea061693d09d Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:15:15 -0800 Subject: [PATCH 31/34] Stories: format the corner-controls test --- src/ui/storiesCredit.test.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/storiesCredit.test.mjs b/src/ui/storiesCredit.test.mjs index 803ee62cd..775d5a811 100644 --- a/src/ui/storiesCredit.test.mjs +++ b/src/ui/storiesCredit.test.mjs @@ -131,7 +131,11 @@ test('the corner controls are the readout and elements marked data-stories-corne const readout = root.appendChild(document.createElement('div')); readout.id = 'style-indicator'; const other = root.appendChild(document.createElement('div')); - assert.deepEqual(cornerControls(root), [readout], 'an unmarked element is not'); + assert.deepEqual( + cornerControls(root), + [readout], + 'an unmarked element is not', + ); // A marked element added later counts on the next look. const marked = root.appendChild(document.createElement('button')); marked.setAttribute('data-stories-corner', ''); From 5cce9d07057e5d2746e6da5981e964d3b4c389ab Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:18:21 -0800 Subject: [PATCH 32/34] Nepal evidence: a seek in the hold places a camera-led shot's sequence For a shot whose path runs during the camera move, a seek in the hold showed its evidence sequence at the start and a resumed run jumped to its end. The sequence now stands where its own clock has it (after the clip and its exit), and a resumed run carries on from there. --- src/data/bhoteKoshiEvent.js | 84 +++++++++++++++++++------------ src/data/bhoteKoshiEvent.test.mjs | 64 ++++++++++++++++++++++- 2 files changed, 115 insertions(+), 33 deletions(-) diff --git a/src/data/bhoteKoshiEvent.js b/src/data/bhoteKoshiEvent.js index bbd6abe1d..86d17e710 100644 --- a/src/data/bhoteKoshiEvent.js +++ b/src/data/bhoteKoshiEvent.js @@ -1858,6 +1858,43 @@ export function createBhoteKoshiEventLayer({ return true; } + // The settled-camera reveal waits out the shot's clip and its exit + // (unless the path runs during the clip), then runs for its duration. + const mediaDurationSec = + _sceneControls.evidenceMediaAutoplay === true + ? Math.max( + SCENE_MEDIA_MIN_PLAYBACK_SECONDS, + Number(_sceneControls.mediaPlaybackHoldSec) || 0, + ) + : 0; + const exitDurationSec = + _sceneControls.evidenceMediaAutoplay === true + ? Math.max( + SCENE_MEDIA_EXIT_SECONDS, + Number(_sceneControls.mediaExitDurationSec) || 0, + ) + : 0; + const settledDurationSec = Math.max( + 0.25, + Number( + sceneUsesSourcePath() + ? _sceneControls.evidencePathDurationSec + : sceneEvidenceSequenceAnimates() + ? _sceneControls.evidenceSequenceDurationSec + : _sceneControls.evidenceRevealDurationSec, + ) || 0.9, + ); + const settledStartSec = Math.max( + 0, + Number(_sceneControls.evidencePathStartDelaySec) || 0, + _sceneControls.evidencePathDuringMedia === true + ? 0 + : mediaDurationSec + exitDurationSec, + ); + const settledLinear = clampUnit( + (holdElapsedSec - settledStartSec) / settledDurationSec, + ); + if (scenePathMovesDuringCamera()) { const authoredDurationSec = Number( _sceneControls.evidencePathTravelDurationSec, @@ -1883,41 +1920,24 @@ export function createBhoteKoshiEventLayer({ Number(_sceneControls.evidenceRevealDurationSec) || 0.9, ), ); + // In the hold, an animated evidence sequence runs on its own clock + // after the camera's path; it stands where that clock has it. + const sequenceWindow = + cameraProgress >= 1 && sceneEvidenceSequenceAnimates() + ? evidenceSequenceWindow(_sceneBeatId, _evidenceTimeline) + : null; + if (sequenceWindow) { + _sceneSeekRevealLinear = settledLinear; + _sceneRevealProgress = smoothstep(0, 1, settledLinear); + _progress = + sequenceWindow.startProgress + + (sequenceWindow.targetProgress - sequenceWindow.startProgress) * + _sceneRevealProgress; + } return true; } - const mediaDurationSec = - _sceneControls.evidenceMediaAutoplay === true - ? Math.max( - SCENE_MEDIA_MIN_PLAYBACK_SECONDS, - Number(_sceneControls.mediaPlaybackHoldSec) || 0, - ) - : 0; - const exitDurationSec = - _sceneControls.evidenceMediaAutoplay === true - ? Math.max( - SCENE_MEDIA_EXIT_SECONDS, - Number(_sceneControls.mediaExitDurationSec) || 0, - ) - : 0; - const pathDurationSec = Math.max( - 0.25, - Number( - sceneUsesSourcePath() - ? _sceneControls.evidencePathDurationSec - : sceneEvidenceSequenceAnimates() - ? _sceneControls.evidenceSequenceDurationSec - : _sceneControls.evidenceRevealDurationSec, - ) || 0.9, - ); - const pathStartSec = Math.max( - 0, - Number(_sceneControls.evidencePathStartDelaySec) || 0, - _sceneControls.evidencePathDuringMedia === true - ? 0 - : mediaDurationSec + exitDurationSec, - ); - const linear = clampUnit((holdElapsedSec - pathStartSec) / pathDurationSec); + const linear = settledLinear; _sceneSeekRevealLinear = linear; _sceneRevealProgress = smoothstep(0, 1, linear); _scenePathRevealProgress = diff --git a/src/data/bhoteKoshiEvent.test.mjs b/src/data/bhoteKoshiEvent.test.mjs index a33984d0f..87159fd18 100644 --- a/src/data/bhoteKoshiEvent.test.mjs +++ b/src/data/bhoteKoshiEvent.test.mjs @@ -34,7 +34,7 @@ import { usesProviderEmbeddedEvidence, visibleSegmentCount, } from './bhoteKoshiEvent.js'; -import { SCENE_RECIPES } from '../scenes/recipes.js'; +import { SCENE_RECIPES, getSceneAppendRecipeById } from '../scenes/recipes.js'; import { LayerLifecycle } from './lifecycle.js'; import { createBhoteKoshiEmbeddedMedia } from './bhoteKoshiEmbeddedMedia.js'; import { SceneDirector } from '../scenes/director.js'; @@ -467,6 +467,68 @@ test('scene media plays again when a run goes on from a seek inside its hold, un } finally { await layer.destroy(); Object.assign(globalThis, previous); } }); +test('a run going on from a seek in Timure’s hold resumes its evidence sequence from that point', async () => { + const keys = ['document', 'window', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame']; + const previous = Object.fromEntries(keys.map((key) => [key, globalThis[key]])); + installEventDom(); + let now = 1000; + let nextFrame = 0; + const frames = new Map(); + globalThis.window = { setTimeout: () => 1, clearTimeout() {} }; + globalThis.performance = { now: () => now }; + globalThis.requestAnimationFrame = (callback) => { frames.set(++nextFrame, callback); return nextFrame; }; + globalThis.cancelAnimationFrame = (id) => frames.delete(id); + const frame = (ms) => { + now += ms; + const callback = frames.get(nextFrame); + frames.delete(nextFrame); + callback?.(now); + }; + const event = JSON.parse(await readFile(eventUrl, 'utf8')); + const layer = createBhoteKoshiEventLayer({ + eventLoader: async () => event, + imagerySpecFactory: async (url) => ({ url }), + terrainSampler: async () => null, + mediaLoader: async () => { throw Object.assign(new Error('fixture'), { name: 'AbortError' }); }, + overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} }, + renderHost: { request() {}, hold() {}, release() {} }, + embeddedMediaFactory: () => ({ warm: () => true, show: () => true, play() {}, pause() {}, + getPlaybackState: () => ({ phase: 'completed' }), hide() {}, destroy() {} }), + }); + const recipe = getSceneAppendRecipeById('bhote-koshi-nepal-evidence-pack'); + const controls = { ...recipe.runtimeControlsByBeat['timure-cluster'], cameraSettled: true }; + assert.equal(controls.evidenceSequence, true); + assert.equal(controls.evidencePathDuringCamera, true); + const params = (sceneControls) => ({ presentation: 'scene-beat', sceneSurface: 'evidence-beat', + beatId: 'timure-cluster', sceneControls }); + // The sequence waits out the 6 s clip and its 0.65 s exit, then runs 12 s: + // 8 s into the hold it is 1.35 s along. + const seek = { ...controls, + timelineSeek: { cameraProgress: 1, holdElapsedSec: 8, holdDurationSec: 12, flightDurationSec: 2 } }; + const at = (holdElapsedSec) => { + layer.setParams(params({ ...seek, timelineSeek: { ...seek.timelineSeek, holdElapsedSec } }), + { origin: 'scene' }); + return layer.getPlaybackState().progress; + }; + try { + const viewer = eventViewer(); + await layer.init(viewer); + layer.setParams(params(seek), { origin: 'scene' }); + await layer.enable(viewer, { origin: 'scene' }); + // Where the sequence starts and ends, and where the seek puts it. + const start = at(0); + const end = at(30); + const atSeek = at(8); + assert.ok(start < atSeek && atSeek < end, `the seek shows the sequence partway (${start} < ${atSeek} < ${end})`); + // The run goes on: the sequence carries on from that point, not 0 or its end. + layer.setParams(params(controls), { origin: 'scene' }); + assert.ok(Math.abs(layer.getPlaybackState().progress - atSeek) < 1e-9, 'it starts where the seek stood'); + frame(1000); + const later = layer.getPlaybackState().progress; + assert.ok(atSeek < later && later < end, `and moves on from there (${atSeek} < ${later} < ${end})`); + } finally { await layer.destroy(); Object.assign(globalThis, previous); } +}); + test('Pinokio source-card fallback selects authored Director dwell, not an impossible player hold', async () => { const previous = { document: globalThis.document, window: globalThis.window }; installEventDom(); From 186f8b76d996635775e0aa63c1fda054a3f6fed7 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:20:55 -0800 Subject: [PATCH 33/34] Scenes: a clip restarted without a media gate plays its hold out A resumed hold waited only its rest unless the layer gave a media gate, and only trimmed clips have one, so an untrimmed clip started again (as on Gyirong) was cut short. The layer now says when a run going on from a seek started its clip again, and the hold then plays out as from its start: through the media gate when there is one, else for the whole hold. --- docs/DIRECTOR.md | 7 ++-- src/data/bhoteKoshiEvent.js | 24 +++++++++++++ src/data/bhoteKoshiEvent.test.mjs | 60 +++++++++++++++++++++++++++++++ src/scenes/director.js | 19 +++++++--- src/scenes/director.test.mjs | 4 ++- 5 files changed, 106 insertions(+), 8 deletions(-) diff --git a/docs/DIRECTOR.md b/docs/DIRECTOR.md index fd2c6eeda..3a81ef96d 100644 --- a/docs/DIRECTOR.md +++ b/docs/DIRECTOR.md @@ -41,8 +41,11 @@ goes on from there along the rest of the path a seek samples, over the rest of t flight; inside its hold, the layers take that moment's state as a seek gives them and then play on from it: a reveal goes on from where the seek put it, and a clip the moment falls in starts again from its beginning (a clip cannot be -joined partway), while one the moment is past stays finished. A clip started again is waited -for as in any hold; otherwise only the rest of the hold is waited out. The scene clock carries on from the same point. `SceneDirector` still owns editor state, saved-project import/export, +joined partway), while one the moment is past stays finished. A clip started +again plays the hold out as from its start: until its media gate opens (a +trimmed clip, with its fade), or for the shot's whole hold (a clip without +one). Otherwise only the rest of the hold is waited out. The scene clock +carries on from the same point. `SceneDirector` still owns editor state, saved-project import/export, camera ownership and asynchronous load/seek arbitration. Pure seek calculations live in `src/director/timeline.js`; `src/director/clock.js` owns the run/load/shot tickers, hold deadlines, snapshots and clock subscriptions. Stop settles pending diff --git a/src/data/bhoteKoshiEvent.js b/src/data/bhoteKoshiEvent.js index 86d17e710..b47dca8e2 100644 --- a/src/data/bhoteKoshiEvent.js +++ b/src/data/bhoteKoshiEvent.js @@ -1090,6 +1090,8 @@ export function createBhoteKoshiEventLayer({ let _sceneRevealProgress = 1; // How far a timeline seek's settled-camera reveal had come (0..1, linear). let _sceneSeekRevealLinear = 1; + // The beat whose clip a run going on from a seek in its hold started again. + let _sceneMediaRestartBeatId = null; let _cinematicKeyframes = []; let _cinematicActive = false; let _cinematicReplayArmed = false; @@ -1552,6 +1554,19 @@ export function createBhoteKoshiEventLayer({ ); } + /** + * Whether a run going on from a seek in this beat's hold started its clip + * again, so the hold has to play out as from its start. + */ + function sceneShotRestartsMedia(beatId) { + return ( + _enabled && + _sceneBeatId === beatId && + _sceneMediaRestartBeatId === beatId && + sceneEvidenceMediaAutoplays() + ); + } + function getSceneShotMediaHold(beatId) { if ( !_enabled || @@ -3896,6 +3911,14 @@ export function createBhoteKoshiEventLayer({ nowDeferred; if (resumesSeek && sceneSeekPassedMedia(previousSeek)) _sceneMediaPlaybackCompletedBeatId = _sceneBeatId; + if ( + resumesSeek && + sceneEvidenceMediaAutoplays() && + !sceneSeekPassedMedia(previousSeek) + ) + _sceneMediaRestartBeatId = _sceneBeatId; + else if (beatChanged || sceneTimelineSeek()) + _sceneMediaRestartBeatId = null; if (!nowDeferred) { stopSceneEvidenceReveal(); _sceneRevealProgress = 1; @@ -4010,6 +4033,7 @@ export function createBhoteKoshiEventLayer({ setParams, getParams, getSceneShotMediaHold, + sceneShotRestartsMedia, setSceneMediaPlayback, getStats() { return { diff --git a/src/data/bhoteKoshiEvent.test.mjs b/src/data/bhoteKoshiEvent.test.mjs index 87159fd18..5eb4b7863 100644 --- a/src/data/bhoteKoshiEvent.test.mjs +++ b/src/data/bhoteKoshiEvent.test.mjs @@ -529,6 +529,66 @@ test('a run going on from a seek in Timure’s hold resumes its evidence sequenc } finally { await layer.destroy(); Object.assign(globalThis, previous); } }); +test('a run going on from a seek in Gyirong’s hold plays its restarted clip out before the next shot', async () => { + const previous = { document: globalThis.document, window: globalThis.window, + requestAnimationFrame: globalThis.requestAnimationFrame, cancelAnimationFrame: globalThis.cancelAnimationFrame }; + installEventDom(); + globalThis.window = { setTimeout: () => 1, clearTimeout() {} }; + globalThis.requestAnimationFrame = () => 1; + globalThis.cancelAnimationFrame = () => {}; + const event = JSON.parse(await readFile(eventUrl, 'utf8')); + let plays = 0; + const layer = createBhoteKoshiEventLayer({ + eventLoader: async () => event, + imagerySpecFactory: async (url) => ({ url }), + terrainSampler: async (_viewer, observations) => observations.map(() => ({ height: 800 })), + mediaLoader: async () => { throw Object.assign(new Error('No bundled clip'), { name: 'AbortError' }); }, + overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} }, + renderHost: { request() {}, hold() {}, release() {} }, + embeddedMediaFactory: () => ({ warm: () => true, show: () => true, play() { plays++; }, pause() {}, + getPlaybackState: () => ({ phase: 'playing' }), hide() {}, destroy() {} }), + }); + const recipe = getSceneAppendRecipeById('bhote-koshi-nepal-evidence-pack'); + const controls = { ...recipe.runtimeControlsByBeat['gyirong-border-gate'], cameraSettled: true }; + const params = (sceneControls) => ({ presentation: 'scene-beat', sceneSurface: 'evidence-beat', + beatId: 'gyirong-border-gate', sceneContext: { sceneId: 'scene', shotId: 'shot', holdSec: 9.15 }, sceneControls }); + const token = { cancelled: false, signal: new AbortController().signal }; + const hold = async (resume) => { + const waits = []; + await SceneDirector.prototype._holdShot.call({ + _layerStatesForShot: () => ({ [layer.id]: { enabled: true, params: params(controls) } }), + dataManager: { layers: new Map([[layer.id, { module: layer }]]) }, + _effectiveShotHoldSec: () => 9.15, + _sleep: async (ms) => waits.push(ms), + stopScene: () => assert.fail('no timeout'), + }, { id: 'scene' }, { id: 'shot' }, token, resume); + return waits; + }; + try { + const viewer = eventViewer(); + await layer.init(viewer); + layer.setSceneMediaPlayback({ sceneId: 'scene', shotId: 'shot', token }); + // 5 s into the 9.15 s hold, inside the 6 s clip, which has no media gate. + const resume = { holdElapsedSec: 5, holdDurationSec: 9.15 }; + layer.setParams(params({ ...controls, timelineSeek: { cameraProgress: 1, ...resume, flightDurationSec: 2 } }), + { origin: 'scene' }); + await layer.enable(viewer, { origin: 'scene' }); + assert.equal(layer.getSceneShotMediaHold('gyirong-border-gate'), null, 'the clip is not trimmed'); + layer.setParams(params(controls), { origin: 'scene' }); + assert.ok(plays > 0, 'the clip starts again'); + assert.equal(layer.sceneShotRestartsMedia('gyirong-border-gate'), true); + assert.deepEqual(await hold(resume), [9150], 'the hold plays out as from its start, not 4.15 s'); + // A seek after the clip: only the rest of the hold. + const late = { holdElapsedSec: 8, holdDurationSec: 9.15 }; + layer.setParams(params({ ...controls, timelineSeek: { cameraProgress: 1, ...late, flightDurationSec: 2 } }), + { origin: 'scene' }); + layer.setParams(params(controls), { origin: 'scene' }); + assert.equal(layer.sceneShotRestartsMedia('gyirong-border-gate'), false); + const [rest] = await hold(late); + assert.ok(Math.abs(rest - 1150) < 1e-6, String(rest)); + } finally { await layer.destroy(); Object.assign(globalThis, previous); } +}); + test('Pinokio source-card fallback selects authored Director dwell, not an impossible player hold', async () => { const previous = { document: globalThis.document, window: globalThis.window }; installEventDom(); diff --git a/src/scenes/director.js b/src/scenes/director.js index edc141e01..35387ecba 100644 --- a/src/scenes/director.js +++ b/src/scenes/director.js @@ -2957,11 +2957,20 @@ export class SceneDirector { ] : []; }); - // Resumed inside the hold, its layers play on from that moment: a clip - // they started again is waited for as in any hold; otherwise only the - // rest of the hold is left to wait. - const resumed = resume?.holdElapsedSec > 0; - if (resumed && !readers.some(({ read }) => read()?.pending === true)) { + // Resumed inside the hold, its layers play on from that moment. A clip + // they started again plays the hold out as from its start (its media + // gate, or the shot's whole hold for a clip without one); otherwise only + // the rest of the hold is left to wait. + const restartedClip = + resume?.holdElapsedSec > 0 && + Object.entries(this._layerStatesForShot(scene, shot)).some( + ([id, state]) => + state.enabled && + this.dataManager?.layers + ?.get(id) + ?.module?.sceneShotRestartsMedia?.(state.params?.beatId) === true, + ); + if (resume?.holdElapsedSec > 0 && !restartedClip) { await this._sleep( Math.max(0, resume.holdDurationSec - resume.holdElapsedSec) * 1000, token, diff --git a/src/scenes/director.test.mjs b/src/scenes/director.test.mjs index f742db981..dd36ec389 100644 --- a/src/scenes/director.test.mjs +++ b/src/scenes/director.test.mjs @@ -2140,6 +2140,7 @@ test('a hold resumed partway waits for a clip that starts again, else only its r let reads = 0; const module = { getSceneShotMediaHold: () => ({ pending: reads++ < pendingReads, maxWaitMs: 20000 }), + sceneShotRestartsMedia: () => pendingReads > 0, }; const waits = []; await SceneDirector.prototype._holdShot.call( @@ -2158,7 +2159,8 @@ test('a hold resumed partway waits for a clip that starts again, else only its r return waits; }; // The clip plays again: the hold polls until it is done, as any hold does. - assert.deepEqual(await hold(4), [70, 70]); + const polls = await hold(4); + assert.ok(polls.length && polls.every((ms) => ms === 70), String(polls)); // The moment was past the clip: only the rest of the hold. assert.deepEqual(await hold(0), [2000]); }); From 2788a9f667428f7c570d539823dba86ecb369925 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:20:55 -0800 Subject: [PATCH 34/34] Docs: the timeline waits at a shot's end while a restarted clip plays --- docs/CURRENT-STATE.md | 3 ++- docs/DIRECTOR.md | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 72bbd4914..94b376caa 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -731,7 +731,8 @@ it seeks the globe once. Play after a pause, a seek or a paused link goes on from that exact moment (`SceneDirector.startScene` with `fromProgress`), even inside a shot or its final quarter-second: the camera, the hold, the scene clock and the layers' reveals carry on from there (a clip that moment falls in -starts again from its beginning, and the hold waits for it). A scene that has actually ended replays from the +starts again from its beginning, and the hold waits for it, with the +timeline held at the shot's end meanwhile). A scene that has actually ended replays from the beginning. Opening Stories claims the camera through the shared navigation policy, so diff --git a/docs/DIRECTOR.md b/docs/DIRECTOR.md index 3a81ef96d..5dc342726 100644 --- a/docs/DIRECTOR.md +++ b/docs/DIRECTOR.md @@ -45,7 +45,9 @@ joined partway), while one the moment is past stays finished. A clip started again plays the hold out as from its start: until its media gate opens (a trimmed clip, with its fade), or for the shot's whole hold (a clip without one). Otherwise only the rest of the hold is waited out. The scene clock -carries on from the same point. `SceneDirector` still owns editor state, saved-project import/export, +carries on from the same point; while a restarted clip plays past where the +shot would have ended, the timeline waits at the shot's end until the clip +and the rest of the hold finish. `SceneDirector` still owns editor state, saved-project import/export, camera ownership and asynchronous load/seek arbitration. Pure seek calculations live in `src/director/timeline.js`; `src/director/clock.js` owns the run/load/shot tickers, hold deadlines, snapshots and clock subscriptions. Stop settles pending