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.
This commit is contained in:
Manjunath committed 2026-11-16 20:12:10 +05:30
1 parent da81cf743b
commit 5418438339
77 files changed
+14975 -260

No files matched your search

+30 -7
View File
@@ -25,6 +25,8 @@ export class SceneControls {
this.panel = {
running: false,
hasShots: false,
// Whether the selected scene is published to the Stories page.
inStories: false,
disabled: sceneButtonsDisabled(false, false),
status: '',
progress: 0,
@@ -45,10 +47,12 @@ export class SceneControls {
this.run('renameShot', sceneId, shotId, title),
load: (sceneId, shotId) => this.run('load', sceneId, shotId),
remove: (sceneId, shotId) => this.deleteShot(sceneId, shotId),
selectScene: (sceneId) => this.run('selectScene', sceneId),
create: () => this.createScene(),
deleteScene: () => this.deleteSelectedScene(),
capture: () => this.run('capture'),
stories: () => this.run('stories'),
thumb: () => this.run('thumb'),
tag: (tag) => this.run('tag', tag),
capture: () => this.captureShot(),
update: () => this.run('update'),
next: () => this.run('next'),
export: () => this.run('export'),
@@ -59,7 +63,7 @@ export class SceneControls {
this.run(this.actions.reviewImport ? 'reviewImport' : 'import', file),
});
this.presentPanel({});
// Scene and shot titles are shown translated; the select and the list
// Scene and shot titles are shown translated; the scene name and the list
// show them again.
this.offLocale = onLocaleChange(() => {
this.presentPanel({ playLabel: t('PLAY', { context: 'scene' }) });
@@ -92,6 +96,7 @@ export class SceneControls {
'scene-created',
'scene-deleted',
'project-imported',
'story-details-changed',
].includes(type)
)
this.renderSceneSelect();
@@ -123,6 +128,8 @@ export class SceneControls {
'shot-captured',
'shot-deleted',
'project-imported',
'stories-changed',
'story-details-changed',
].includes(type)
)
this.setButtons(state.running);
@@ -165,18 +172,32 @@ export class SceneControls {
}
}
/** Publish the project to the SceneOptions and SceneShotList views. */
/** Publish the project to the scene name and the SceneShotList view. */
renderSceneSelect() {
if (!this.destroyed) this.store.publishOptions(this.read());
if (!this.destroyed) this.store.publish(this.read());
}
/** NEW SCENE: ask for a name and create the scene. @returns {boolean} */
createScene() {
if (this.destroyed) return;
if (this.destroyed) return false;
const name = window.prompt(
t('New scene name'),
t('Scene {n}', { n: this.read().scenes.length + 1 }),
);
if (name) this.run('create', name);
if (!name) return false;
this.run('create', name);
return true;
}
/** CAPTURE SHOT; with no scene it starts one first, as NEW SCENE does. */
captureShot() {
if (this.destroyed) return;
const state = this.read();
const hasScene = state.scenes.some(
(scene) => scene.id === state.selectedSceneId,
);
if (!hasScene && !this.createScene()) return;
this.run('capture');
}
deleteSelectedScene() {
@@ -221,8 +242,10 @@ export class SceneControls {
this.presentPanel({
running: !!running,
hasShots: shots.length > 0,
inStories: scene?.stories === true,
disabled: sceneButtonsDisabled(running, state.hasRun, {
hasScene: !!scene,
sceneShots: shots.length,
// PLAY and NEXT run on into the following scenes.
playableShots: (state.scenes ?? []).reduce(
(total, item) => total + (item.shots?.length ?? 0),
+286 -23
View File
@@ -37,7 +37,7 @@ function fixture() {
const byId = (id) => document.getElementById(id);
const elements = {
panel: byId('scene-panel'),
select: byId('scene-select'),
name: byId('scene-name'),
new: byId('scene-new-btn'),
delete: byId('scene-delete-btn'),
capture: byId('scene-capture-btn'),
@@ -49,6 +49,8 @@ function fixture() {
import: byId('scene-import-btn'),
file: byId('scene-import-file'),
download: byId('scene-download-btn'),
stories: byId('scene-stories-btn'),
thumb: byId('scene-thumb-btn'),
status: byId('scene-status'),
progress: byId('scene-progress-fill'),
runtime: byId('scene-runtime'),
@@ -78,11 +80,13 @@ function fixture() {
const calls = [];
const actions = Object.fromEntries(
[
'selectScene',
'selectShot',
'renameShot',
'create',
'deleteScene',
'stories',
'thumb',
'tag',
'capture',
'update',
'start',
@@ -110,6 +114,8 @@ function fixture() {
document,
/** The first shot row's label, once the view has rendered. */
label: () => elements.shots.children[0]?.children[0].children[0],
/** The Stories tag chips, in STORY_TAGS order. */
chips: () => [...document.querySelectorAll('.scene-tag-chip')],
restore() {
owner.destroy();
view.unmount();
@@ -122,8 +128,8 @@ test('Scene controls render the supplied selection and running/download states',
const f = fixture();
try {
await nextTick();
assert.equal(f.elements.select.children[0].textContent, '<Scene A>');
assert.equal(f.elements.select.value, 'scene-a');
assert.equal(f.elements.name.textContent, '<Scene A>');
assert.equal(document.getElementById('scene-select'), null);
assert.equal(f.label().textContent, '<Shot A>');
assert.equal(
f.elements.shots.children[0].children[1].textContent,
@@ -184,13 +190,23 @@ test('Authoring disables idle actions that would do nothing', async () => {
assert.equal(f.elements.capture.disabled, false);
assert.equal(f.elements.panel.classList.contains('has-shots'), false);
f.state.scenes = [];
// With no scene selected, PLAY and NEXT have nothing to run even when
// another scene has shots; CAPTURE SHOT starts a scene.
f.state.scenes.push({ id: 'scene-b', title: 'B', shots: [{ id: 'b1' }] });
f.state.selectedSceneId = null;
f.state.selectedShotId = null;
f.owner.setButtons(false);
await nextTick();
assert.equal(f.elements.delete.disabled, true);
assert.equal(f.elements.capture.disabled, true);
assert.equal(f.elements.capture.disabled, false);
assert.equal(f.elements.new.disabled, false);
assert.equal(f.elements.start.disabled, true);
assert.equal(f.elements.next.disabled, true);
assert.equal(f.elements.update.disabled, true);
assert.equal(f.elements.stories.disabled, true);
assert.equal(f.elements.thumb.disabled, true);
assert.ok(f.chips().every((chip) => chip.disabled));
assert.equal(f.elements.export.disabled, false);
} finally {
f.restore();
}
@@ -394,6 +410,7 @@ test('the real director preserves a selected shot label for the following double
},
});
director = new SceneDirector({ camera: { cancelFlight() {} } }, {}, {});
director.selectShot('scene-a');
await nextTick();
const label = f.label();
label.click();
@@ -415,6 +432,67 @@ test('the real director preserves a selected shot label for the following double
}
});
test('the real director names the scene it selects and saves it to Stories', async () => {
const f = fixture();
const previousStorage = globalThis.localStorage;
let saved = null;
let director;
try {
f.owner.destroy();
f.state.scenes.push({ id: 'scene-b', title: 'Scene B', shots: [] });
Object.defineProperty(globalThis, 'localStorage', {
configurable: true,
writable: true,
value: {
getItem: () => JSON.stringify({ version: 3, scenes: f.state.scenes }),
setItem: (_key, value) => {
saved = JSON.parse(value);
},
},
});
director = new SceneDirector({ camera: { cancelFlight() {} } }, {}, {});
await nextTick();
// Nothing is selected on load.
assert.equal(f.elements.name.textContent, 'No scene yet');
assert.equal(
f.elements.shots.querySelectorAll('.scene-shot-row').length,
0,
);
director.selectShot('scene-a');
await nextTick();
assert.equal(f.elements.name.textContent, '<Scene A>');
assert.equal(f.elements.stories.textContent, 'SAVE TO STORIES');
f.elements.stories.click();
await nextTick();
assert.equal(saved.scenes[0].stories, true);
assert.equal(f.elements.status.textContent, 'Saved to Stories');
assert.equal(f.elements.stories.textContent, 'REMOVE FROM STORIES');
// Stories' "Open in GEV" selects programmatically; the name follows.
assert.equal(director.selectShot('scene-b'), true);
await nextTick();
assert.equal(f.elements.name.textContent, 'Scene B');
assert.equal(f.elements.stories.textContent, 'SAVE TO STORIES');
assert.equal(f.elements.stories.disabled, true);
director.selectShot('scene-a');
await nextTick();
f.elements.stories.click();
await nextTick();
assert.equal(Object.hasOwn(saved.scenes[0], 'stories'), false);
assert.equal(f.elements.status.textContent, 'Removed from Stories');
assert.equal(f.elements.stories.textContent, 'SAVE TO STORIES');
} finally {
await director?.destroy();
Object.defineProperty(globalThis, 'localStorage', {
configurable: true,
writable: true,
value: previousStorage,
});
f.restore();
}
});
test('inline shot names save on Enter, cancel on Escape, and reject blank names', async () => {
const f = fixture();
const key = (name) => new KeyboardEvent('keydown', { key: name });
@@ -477,40 +555,63 @@ test('a rename keeps typed text across republishing and ends with its scene', as
}
});
test('the scene select follows option renders, as before', async () => {
test('the read-only scene name follows the selected scene', async () => {
const f = fixture();
try {
await nextTick();
f.state.scenes.push({ id: 'scene-b', title: 'B', shots: [] });
f.state.selectedSceneId = 'scene-b';
f.owner.renderSceneSelect();
await nextTick();
f.state.selectedSceneId = 'scene-b';
assert.equal(f.elements.name.textContent, 'B');
assert.equal(f.elements.name.classList.contains('scene-name-empty'), false);
f.state.scenes = [];
f.state.selectedSceneId = null;
f.owner.renderShotList();
await nextTick();
assert.equal(f.elements.select.value, 'scene-a');
f.owner.renderSceneSelect();
await nextTick();
assert.equal(f.elements.select.value, 'scene-b');
assert.equal(f.elements.name.textContent, 'No scene yet');
assert.equal(f.elements.name.classList.contains('scene-name-empty'), true);
} finally {
f.restore();
}
});
test('an option render restores the published scene after a local pick', async () => {
test('SAVE TO STORIES follows the scene flag and needs a shot', async () => {
const f = fixture();
try {
f.state.scenes.push({ id: 'scene-b', title: 'B', shots: [] });
f.owner.renderSceneSelect();
f.owner.destroy();
const channel = createStateChannel(() => f.state);
const owner = new SceneControls({
read: () => f.state,
actions: f.actions,
subscribe: (listener) => channel.subscribe(listener),
});
await nextTick();
assert.equal(f.elements.select.value, 'scene-a');
// The person picks B; the owner re-renders the shot list only.
f.elements.select.value = 'scene-b';
f.owner.renderShotList();
assert.equal(f.elements.stories.textContent, 'SAVE TO STORIES');
assert.equal(f.elements.stories.disabled, false);
f.elements.stories.click();
assert.deepEqual(f.calls, [['stories']]);
f.state.scenes[0].stories = true;
channel.publish({ type: 'stories-changed' });
await nextTick();
// Something reloads A and renders the options with the same choice.
f.owner.renderSceneSelect();
assert.equal(f.elements.stories.textContent, 'REMOVE FROM STORIES');
assert.equal(useSceneStore(applicationPinia()).panel.inStories, true);
delete f.state.scenes[0].stories;
f.state.scenes[0].shots = [];
channel.publish({ type: 'shot-deleted' });
await nextTick();
assert.equal(f.elements.select.value, 'scene-a');
assert.equal(f.elements.stories.textContent, 'SAVE TO STORIES');
assert.equal(f.elements.stories.disabled, true);
f.state.scenes[0].shots = [{ id: 'shot-a' }];
f.state.running = true;
channel.publish({ type: 'buttons-changed' });
await nextTick();
assert.equal(f.elements.stories.disabled, true, 'off while playing');
owner.destroy();
channel.destroy();
} finally {
f.restore();
}
@@ -601,7 +702,8 @@ test('Authoring refreshes idle buttons from published changes', async () => {
channel.publish({ type: 'scene-deleted' });
await nextTick();
assert.equal(disabled('delete'), true);
assert.equal(disabled('capture'), true);
assert.equal(disabled('capture'), false);
assert.equal(disabled('thumb'), true);
assert.equal(disabled('new'), false);
f.state.scenes = [{ id: 'scene-b', title: 'B', shots: [{ id: 's' }] }];
@@ -666,3 +768,164 @@ test('IMPORT clears its chooser only once the import settles, and is inert witho
f.restore();
}
});
test('CAPTURE SHOT with no scene asks for a name, creates the scene, then captures', async () => {
const f = fixture();
try {
f.state.selectedSceneId = null;
f.state.selectedShotId = null;
f.owner.renderSceneSelect();
f.owner.setButtons(false);
await nextTick();
assert.equal(f.elements.name.textContent, 'No scene yet');
let asked = 0;
window.prompt = () => (asked++ ? null : 'Harbour');
f.elements.capture.click();
assert.deepEqual(f.calls, [['create', 'Harbour'], ['capture']]);
// Cancelling the name captures nothing.
f.elements.capture.click();
assert.equal(asked, 2);
assert.equal(f.calls.length, 2);
// With a scene, CAPTURE SHOT captures straight away.
f.state.selectedSceneId = 'scene-a';
f.elements.capture.click();
assert.deepEqual(f.calls.at(-1), ['capture']);
assert.equal(asked, 2);
} finally {
f.restore();
}
});
test('Stories tag chips and THUMBNAIL follow the current scene', async () => {
const f = fixture();
try {
await nextTick();
const chips = f.chips();
assert.deepEqual(
chips.map((chip) => chip.textContent),
[
'Floods',
'Wildfires',
'Storms',
'Earthquakes',
'Flights',
'Maritime',
'Space',
'Conflict',
'Infrastructure',
'Climate',
],
);
assert.ok(
chips.every((chip) => chip.getAttribute('aria-pressed') === 'false'),
);
assert.ok(chips.every((chip) => !chip.disabled));
assert.equal(f.elements.thumb.disabled, false);
assert.equal(document.getElementById('scene-thumb-preview'), null);
chips[2].click();
f.elements.thumb.click();
assert.deepEqual(f.calls, [['tag', 'Storms'], ['thumb']]);
// The owner publishes fresh scene copies, as the director's read() does.
f.state.scenes[0] = {
...f.state.scenes[0],
storyTags: ['Storms'],
storyThumb: 'data:image/jpeg;base64,AAAA',
};
f.owner.renderSceneSelect();
await nextTick();
assert.equal(f.chips()[2].getAttribute('aria-pressed'), 'true');
assert.equal(f.chips()[2].classList.contains('active'), true);
const preview = document.getElementById('scene-thumb-preview');
assert.equal(preview.getAttribute('src'), 'data:image/jpeg;base64,AAAA');
// At five tags, only the chips already on stay available.
f.state.scenes[0] = {
...f.state.scenes[0],
storyTags: ['Floods', 'Wildfires', 'Storms', 'Earthquakes', 'Flights'],
};
f.owner.renderSceneSelect();
await nextTick();
assert.deepEqual(
f.chips().map((chip) => chip.disabled),
[false, false, false, false, false, true, true, true, true, true],
);
// A run turns them off with the other authoring actions.
f.owner.setButtons(true);
await nextTick();
assert.equal(f.elements.thumb.disabled, true);
assert.ok(f.chips().every((chip) => chip.disabled));
} finally {
f.restore();
}
});
test('the real director captures into a new scene from an empty panel', async () => {
const f = fixture();
const previousStorage = globalThis.localStorage;
let saved = null;
let director;
try {
f.owner.destroy();
Object.defineProperty(globalThis, 'localStorage', {
configurable: true,
writable: true,
value: {
getItem: () => JSON.stringify({ version: 3, scenes: f.state.scenes }),
setItem: (_key, value) => {
saved = JSON.parse(value);
},
},
});
director = new SceneDirector(
{ camera: { cancelFlight() {} } },
{
getCameraState: () => ({
lat: 1,
lon: 2,
alt: 3000,
heading: 0,
pitch: -40,
roll: 0,
}),
getVisualState: () => ({ style: 'normal' }),
},
{ getAll: () => [], getLayerParams: () => null },
);
await nextTick();
assert.equal(f.elements.name.textContent, 'No scene yet');
window.prompt = () => 'Harbour';
f.elements.capture.click();
await nextTick();
assert.equal(f.elements.name.textContent, 'Harbour');
assert.equal(saved.scenes.at(-1).title, 'Harbour');
assert.equal(saved.scenes.at(-1).shots.length, 1);
assert.equal(
f.elements.shots.querySelectorAll('.scene-shot-row').length,
1,
);
assert.equal(f.elements.thumb.disabled, false);
f.chips()[0].click();
await nextTick();
assert.deepEqual(saved.scenes.at(-1).storyTags, ['Floods']);
assert.equal(f.chips()[0].getAttribute('aria-pressed'), 'true');
// Deleting it goes back to no scene.
window.confirm = () => true;
f.elements.delete.click();
await nextTick();
assert.equal(f.elements.name.textContent, 'No scene yet');
assert.equal(f.elements.delete.disabled, true);
} finally {
await director?.destroy();
Object.defineProperty(globalThis, 'localStorage', {
configurable: true,
writable: true,
value: previousStorage,
});
f.restore();
}
});
+23 -9
View File
@@ -50,38 +50,52 @@ export function describeShot(shot) {
/**
* While a scene plays, the authoring and file actions here are off and STOP
* is on. Otherwise a button is off when it would do nothing: DELETE and
* CAPTURE SHOT without a scene, UPDATE SHOT without a selected shot, PLAY and
* NEXT when no scene in the project has a shot (both continue into the
* following scenes).
* is on. Otherwise a button is off when it would do nothing: DELETE, SAVE TO
* STORIES, THUMBNAIL and the tag chips without a scene, UPDATE SHOT
* without a selected shot, SAVE TO STORIES when the scene has no shot, PLAY
* and NEXT without a scene or when no scene in the project has a shot (both
* continue into the following scenes). CAPTURE SHOT without a scene starts
* one. EDIT DETAILS (which needs a shot) and SHARE SCENE keep their own
* checks during playback.
*/
export function sceneButtonsDisabled(
running,
hasRun,
{ hasScene = true, playableShots = 1, hasSelectedShot = true } = {},
{
hasScene = true,
sceneShots = 1,
playableShots = 1,
hasSelectedShot = true,
} = {},
) {
const idleOff = {
delete: !hasScene,
capture: !hasScene,
stories: !hasScene || sceneShots === 0,
thumb: !hasScene,
tags: !hasScene,
update: !hasSelectedShot,
start: playableShots === 0,
next: playableShots === 0,
start: !hasScene || playableShots === 0,
next: !hasScene || playableShots === 0,
};
const disabled = {};
for (const name of [
'start',
'next',
'select',
'new',
'delete',
'capture',
'update',
'thumb',
'tags',
'stories',
'export',
'import',
])
disabled[name] = running || !!idleOff[name];
disabled.stop = !running;
disabled.download = !hasRun;
disabled.details = !hasScene || !hasSelectedShot;
disabled.share = !hasScene;
return disabled;
}
+13 -22
View File
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { markRaw, shallowRef } from 'vue';
import { computed, markRaw, shallowRef } from 'vue';
/**
* @typedef {object} SceneRowHandlers
@@ -7,10 +7,10 @@ import { markRaw, shallowRef } from 'vue';
* @property {(sceneId: string, shotId: string, title: string) => void} rename
* @property {(sceneId: string, shotId: string) => void} load
* @property {(sceneId: string, shotId: string) => void} remove
* @property {(sceneId: string) => void} selectScene The select's choice.
* @property {(file: File) => Promise<void>|void} importFile A chosen file.
* @property {() => void} create, deleteScene, capture, update, start, stop,
* next, export, download The panel's buttons.
* @property {() => void} create, deleteScene, stories, thumb, capture, update,
* start, stop, next, export, download The panel's buttons.
* @property {(tag: string) => void} tag A Stories tag chip.
*/
/**
@@ -23,15 +23,15 @@ export const useSceneStore = defineStore('gev-scenes', () => {
const scenes = shallowRef(markRaw([]));
const selectedSceneId = shallowRef(null);
const selectedShotId = shallowRef(null);
// The select's choice, updated only when its options are rendered.
const listedSceneId = shallowRef(null);
// Counts option renders: each one re-applies the select's choice, which
// the person may have changed since.
const listedRevision = shallowRef(0);
/** The scene being edited, whose name the panel shows, or null. */
const currentScene = computed(
() =>
scenes.value.find((scene) => scene.id === selectedSceneId.value) ?? null,
);
/**
* The panel's buttons, status line, progress and runtime chip:
* `{running, hasShots, disabled: {[button]: boolean}, status, progress,
* runtime, playLabel}`, or null until an owner presents them.
* `{running, hasShots, inStories, disabled: {[button]: boolean}, status,
* progress, runtime, playLabel}`, or null until an owner presents them.
*/
const panel = shallowRef(null);
@@ -63,13 +63,6 @@ export const useSceneStore = defineStore('gev-scenes', () => {
selectedShotId.value = state.selectedShotId ?? null;
}
/** Publish the project and the select's choice. */
function publishOptions(state) {
publish(state);
listedSceneId.value = state.selectedSceneId ?? null;
listedRevision.value++;
}
/** @param {string|null} id */
function selectShot(id) {
selectedShotId.value = id ?? null;
@@ -83,7 +76,7 @@ export const useSceneStore = defineStore('gev-scenes', () => {
if (token !== owner) return;
owner = null;
attached.value = false;
publishOptions({});
publish({});
}
/** @returns {boolean} Whether `token` is the owner presenting now. */
@@ -104,14 +97,12 @@ export const useSceneStore = defineStore('gev-scenes', () => {
scenes,
selectedSceneId,
selectedShotId,
listedSceneId,
listedRevision,
currentScene,
attached,
panel,
publishPanel,
attach,
publish,
publishOptions,
selectShot,
detach,
owns,
+83
View File
@@ -0,0 +1,83 @@
import { defineStore } from 'pinia';
import { markRaw } from 'vue';
/**
* What the Stories view shows. The controller (src/stories/controller.js)
* owns the globe, the players and the URL; it connects here and the view's
* controls reach it through `controller`.
*/
export const useStoriesStore = defineStore('stories', {
state: () => ({
/** 'closed' | 'explore' | 'story' */
mode: 'closed',
storyId: null,
/** Explore */
query: '',
chips: [],
sort: 'new',
filters: { region: [], length: [] },
picked: null,
pins: [],
feedSnap: 'split',
/** Story */
/** Story card images by story id (none yet: cards show a placeholder). */
thumbs: {},
playback: {
wallMs: 0,
worldMs: null,
durationMs: 0,
playing: false,
exploring: false,
chapterIndex: 0,
},
/** The big Play button over a story that opened paused. */
bigPlay: false,
camera: { lat: 0, lon: 0, altKm: 0 },
muted: true,
expanded: false,
/** Context panel shown over the map while expanded (desktop). */
ctxOpen: false,
/** Phone context sheet: 'peek' | 'half' | 'full' */
sheet: 'peek',
/** Width the person dragged the context panel to; 0 is the default. */
contextWidth: 0,
/** Hints and toasts */
hint: '',
toast: '',
hostedToast: null,
popSeen: false,
hintSeen: false,
sheetHintSeen: false,
controller: null,
/** False where Stories is not offered (GEV embedded inline in a host page). */
available: true,
/** Every story Explore lists, as the controller publishes them. */
stories: [],
}),
getters: {
byId: (state) => (id) => state.stories.find((s) => s.id === id) ?? null,
},
actions: {
connect(controller, stories = []) {
this.controller = markRaw(controller);
this.stories = markRaw(stories);
},
flashHint(text, ms = 1600) {
this.hint = text;
clearTimeout(hintTimer);
hintTimer = setTimeout(() => {
if (this.hint === text) this.hint = '';
}, ms);
},
flashToast(text, ms = 2200) {
this.toast = text;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
if (this.toast === text) this.toast = '';
}, ms);
},
},
});
let hintTimer = 0;
let toastTimer = 0;
+136
View File
@@ -0,0 +1,136 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import { creditPlacement, entryPlacement } from '../stories/format.js';
const css = readFileSync(
new URL('./styles/stories.css', import.meta.url),
'utf8',
).replace(/\/\*[\s\S]*?\*\//g, '');
const view = readFileSync(
new URL('./views/StoriesView.vue', import.meta.url),
'utf8',
);
/** Every declaration block in stories.css whose selector names the credit line. */
function creditBlocks() {
const blocks = [];
const re = /([^{}]+)\{([^{}]*)\}/g;
for (let m; (m = re.exec(css));) {
if (m[1].includes('#cesium-credits'))
blocks.push({ selector: m[1].trim(), body: m[2] });
}
return blocks;
}
test('Stories never hides GEV’s required credit line', () => {
const blocks = creditBlocks();
assert.ok(blocks.length > 0, 'Stories places the credit line');
for (const { selector, body } of blocks) {
assert.doesNotMatch(
body,
/\b(display\s*:\s*none|visibility\s*:\s*hidden|opacity\s*:\s*0(?![.\d]))/,
selector,
);
}
// The rule that hides GEV's chrome while Stories is open exempts the credit.
assert.match(
css,
/body\.stories-mode\s*>\s*:not\([^)]*\[id='cesium-credits'\]/,
);
});
test('a playing scene’s recording mode cannot move the credit under the timeline', () => {
const placement = creditBlocks().find(
({ selector, body }) =>
/^body\.stories-mode:not\(#gs-a\):not\(#gs-b\)\s+#cesium-credits$/.test(
selector,
) && /bottom\s*:/.test(body),
);
assert.ok(placement, 'Stories pins the credit line');
// Two ids outrank body.recording-mode #cesium-credits and the phone shell's
// !important rule (one id each), so the measured place holds while playing.
assert.match(
placement.body,
/bottom:\s*var\(--gs-credit-bottom,\s*\d+px\)\s*!important/,
);
assert.match(
placement.body,
/left:\s*var\(--gs-credit-left,\s*\d+px\)\s*!important/,
);
});
test('the measured place keeps the credit inside the map and on screen', () => {
const rect = (left, top, right, bottom) => ({
left,
top,
right,
bottom,
width: right - left,
height: bottom - top,
});
// Story, desktop: the map ends 80 px above the window's bottom (timeline).
assert.deepEqual(
creditPlacement({ map: rect(0, 60, 1200, 720), width: 1200, height: 800 }),
{ bottom: 86, left: 24 },
);
// Explore, desktop: the feed covers the map's left, so the credit clears it.
assert.deepEqual(
creditPlacement({
map: rect(0, 0, 1200, 800),
feed: rect(0, 60, 420, 800),
width: 1200,
height: 800,
}),
{ bottom: 6, left: 434 },
);
// Explore, phone: the feed is a sheet below the map, not beside it.
assert.deepEqual(
creditPlacement({
map: rect(0, 0, 390, 360),
feed: rect(0, 360, 390, 844),
width: 390,
height: 844,
}),
{ bottom: 490, left: 10 },
);
// A map taller than the window never pushes the credit off screen.
assert.equal(
creditPlacement({ map: rect(0, 0, 800, 900), width: 800, height: 700 })
.bottom,
6,
);
// No map (Stories closing): GEV's own placement applies.
assert.equal(creditPlacement({ map: null, width: 800, height: 700 }), null);
// Closing Stories hands the credit back to GEV.
assert.match(view, /root\.removeProperty\('--gs-credit-bottom'\)/);
assert.match(view, /root\.removeProperty\('--gs-credit-left'\)/);
});
test('the Stories button sits left of whatever is in the top-right corner', () => {
const box = (left, top, width, height) => ({
left,
top,
width,
height,
right: left + width,
bottom: top + height,
});
// GEV: the ACTIVE STYLE readout.
assert.deepEqual(entryPlacement([box(1700, 24, 220, 60), undefined], 1960), {
top: 24,
right: 270,
});
// GEV Hosted: the account avatar beside the readout; the leftmost wins.
assert.deepEqual(
entryPlacement([box(1650, 24, 220, 60), box(1898, 22, 38, 38)], 1960),
{ top: 24, right: 320 },
);
// Hosted with the readout hidden: the avatar alone.
assert.deepEqual(
entryPlacement([box(0, 0, 0, 0), box(1898, 22, 38, 38)], 1960),
{ top: 22, right: 72 },
);
// Nothing there yet.
assert.deepEqual(entryPlacement([null, null], 1960), { top: 14, right: 14 });
});
+2 -2
View File
@@ -92,8 +92,8 @@ test('SCENES actions stay on one line in English', () => {
.length,
0,
);
const [select] = unguardedRules(css('scenes.css'), '#scene-select');
assert.equal(declaration(select, 'white-space'), undefined);
const [name] = unguardedRules(css('scenes.css'), '#scene-name');
assert.equal(declaration(name, 'white-space'), undefined);
});
test('Display and parameter rows keep their English layout', () => {
+65 -10
View File
@@ -162,21 +162,19 @@
flex-wrap: wrap;
}
/* The scene's name takes its own row; NEW SCENE / DELETE share the next. */
#scene-select {
/* The scene being edited, read-only, takes its own row; NEW SCENE / DELETE
share the next. A long name wraps. */
#scene-name {
flex: 1 1 100%;
min-width: 0;
min-height: 32px;
margin: 0;
font-size: 12px;
line-height: 1.4;
overflow-wrap: anywhere;
}
html:not([lang='en']) #scene-select {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-family: var(--font-mono);
font-size: 10px;
letter-spacing: 0.04em;
#scene-name.scene-name-empty {
color: var(--scene-quiet);
}
/* A translated action longer than its button wraps inside the button instead
@@ -244,6 +242,63 @@ html:not([lang='en']) #scene-panel .scene-controls .scene-btn {
background: color-mix(in srgb, var(--accent) 16%, transparent);
}
/* Stories tags: small toggle chips that wrap; a pressed chip takes the
accent. */
#scene-panel .scene-tag-chips {
gap: 4px;
}
#scene-panel .scene-tag-chip {
flex: 0 0 auto;
padding: 3px 8px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 999px;
background: transparent;
color: var(--scene-quiet);
font-size: 10px;
line-height: 1.3;
cursor: pointer;
}
#scene-panel .scene-tag-chip.active {
color: var(--accent);
border-color: color-mix(in srgb, var(--accent) 55%, transparent);
background: color-mix(in srgb, var(--accent) 12%, transparent);
}
#scene-panel .scene-tag-chip:disabled {
opacity: 0.4;
cursor: default;
}
/* The Stories card thumbnail, CAPTURE THUMBNAIL and SAVE TO STORIES share a
row; the preview keeps the card's 16:9. */
#scene-panel .scene-story-controls {
align-items: center;
}
/* Two buttons beside the preview: a label that does not fit (REMOVE FROM
STORIES) wraps inside its button, in English too. */
#scene-panel .scene-story-controls .scene-btn {
align-self: stretch;
padding: 8px 6px;
white-space: normal;
overflow-wrap: break-word;
}
.scene-thumb-preview {
flex: 0 0 64px;
width: 64px;
height: 36px;
border-radius: 3px;
object-fit: cover;
}
.scene-thumb-empty {
border: 1px dashed rgba(255, 255, 255, 0.18);
box-sizing: border-box;
}
.scene-shot-hint {
margin: 0 0 8px;
font-size: 11px;
+243
View File
@@ -0,0 +1,243 @@
/* Stories, closed: the Stories button, its first-visit popup and the
back-to-story toast, which every GEV page shows. The rest of Stories'
styles (stories.css) load with Stories itself. */
/* Ported from the GEV Stories prototype (gev-stories-real-globe.html), scoped to #gev-stories. */
#gev-stories {
--bg-dark: #0a0a0f;
--glass-bg: rgba(12, 12, 20, 0.72);
--glass-strong: rgba(14, 14, 24, 0.9);
--glass-border: rgba(255, 255, 255, 0.08);
--glass-border-hover: rgba(255, 255, 255, 0.15);
--accent: #00d4ff;
--accent-dim: rgba(0, 212, 255, 0.15);
--accent-glow: rgba(0, 212, 255, 0.4);
--text-primary: #e8eaed;
--text-secondary: rgba(232, 234, 237, 0.64);
--text-dim: rgba(232, 234, 237, 0.42);
--menu-bg: #12121c;
--warn: #ffb45a;
--live: #ff4d4d;
--cable: #a9b8ff;
--font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
--panel-radius: 16px;
--btn-radius: 10px;
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
--transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
--review-h: 46px;
color-scheme: dark;
}
#gev-stories {
background: #050508;
color: var(--text-primary);
font-family: var(--font-sans);
font-size: 14px;
line-height: 1.45;
overflow: hidden;
}
#gev-stories .glass {
background: var(--glass-bg);
border: 1px solid var(--glass-border);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
#gev-stories .tbtn {
height: 38px;
padding: 0 14px;
border-radius: var(--btn-radius);
display: inline-flex;
align-items: center;
gap: 8px;
border: 1px solid var(--glass-border);
background: var(--glass-bg);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
font: 500 12px var(--font-mono);
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--text-primary);
white-space: nowrap;
transition:
border-color var(--transition-fast),
background var(--transition-fast);
}
#gev-stories .tbtn:hover {
border-color: var(--glass-border-hover);
}
#gev-stories .tbtn svg {
width: 16px;
height: 16px;
flex: none;
}
#gev-stories .tbtn.accent {
border-color: rgba(0, 212, 255, 0.55);
color: var(--accent);
background: rgba(0, 212, 255, 0.08);
box-shadow: 0 0 18px -6px var(--accent-glow);
}
#gev-stories .tbtn.accent:hover {
background: rgba(0, 212, 255, 0.14);
}
#gev-stories .tbtn.solid {
background: var(--accent);
color: #001820;
border-color: transparent;
font-weight: 600;
}
#gev-stories .h-pop {
position: absolute;
z-index: 9;
top: 84px;
right: 74px;
width: 300px;
padding: 16px;
border-radius: var(--panel-radius);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
animation: gsx-popIn 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}
#gev-stories .h-pop::before {
content: '';
position: absolute;
top: -7px;
right: 60px;
width: 12px;
height: 12px;
background: var(--glass-strong);
border-left: 1px solid var(--glass-border);
border-top: 1px solid var(--glass-border);
transform: rotate(45deg);
}
#gev-stories .h-pop {
background: var(--glass-strong);
}
#gev-stories .h-pop .k {
font: 600 11px var(--font-mono);
letter-spacing: 0.16em;
color: var(--accent);
}
#gev-stories .h-pop h2 {
font-size: 17px;
margin: 4px 0 6px;
}
#gev-stories .h-pop p {
color: var(--text-secondary);
font-size: 13px;
}
#gev-stories .h-pop .row {
display: flex;
gap: 8px;
margin-top: 12px;
}
#gev-stories .h-toast {
position: absolute;
z-index: 9;
left: 50%;
bottom: 96px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 12px;
padding: 10px 10px 10px 16px;
border-radius: 14px;
background: rgba(12, 12, 20, 0.92);
border: 1px solid rgba(0, 212, 255, 0.35);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
animation: gsx-popIn 0.25s ease;
max-width: calc(100% - 28px);
}
#gev-stories .h-toast[hidden] {
display: none;
}
#gev-stories .h-toast b {
font: 600 11px var(--font-mono);
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--accent);
white-space: nowrap;
}
#gev-stories .h-toast span {
font-size: 13px;
color: var(--text-secondary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
min-width: 0;
}
#gev-stories .h-toast .tbtn {
height: 32px;
flex: none;
}
/* The root only hosts fixed layers; it takes no room of its own. */
#gev-stories {
position: static;
height: 0 !important;
overflow: visible !important;
background: none !important;
}
/* GEV: the Stories entry sits in GEV's top-right row. */
#gev-stories .gs-entry {
position: fixed;
z-index: 1200;
height: 36px;
font: 600 11px var(--font-mono);
letter-spacing: 0.1em;
text-transform: uppercase;
}
#gev-stories .gs-entry svg {
width: 17px;
height: 17px;
}
body:has(#loading-screen:not(.hidden)) #gev-stories .gs-entry,
body:has(#loading-screen:not(.hidden)) #gev-stories .gs-pop,
body.recording-mode #gev-stories .gs-entry,
body.recording-mode #gev-stories .gs-pop,
body.ui-clean-view #gev-stories .gs-entry,
body.ui-clean-view #gev-stories .gs-pop {
display: none;
}
#gev-stories .gs-pop {
position: fixed;
z-index: 1201;
left: auto;
}
#gev-stories .gs-hosted-toast {
position: fixed;
z-index: 1201;
bottom: 110px;
}
@media (max-width: 700px) {
#gev-stories .gs-pop {
left: 12px;
right: 12px !important;
width: auto;
}
}
/* Shared with the screens' panels (stories.css). */
@keyframes gsx-popIn {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: none;
}
}
/* Over a live globe a backdrop blur is redrawn every frame (costly on
software WebGL): the closed-state pieces use a near-opaque fill instead. */
#gev-stories .gs-entry,
#gev-stories .gs-pop,
#gev-stories .gs-hosted-toast {
-webkit-backdrop-filter: none;
backdrop-filter: none;
}
#gev-stories .gs-entry {
background: rgba(6, 24, 34, 0.92);
}
#gev-stories .gs-pop,
#gev-stories .gs-hosted-toast {
background: rgba(12, 12, 20, 0.95);
}
File diff suppressed because it is too large. Load diff
+2
View File
@@ -33,6 +33,8 @@ export function createSurfaceKeyboard({
return;
}
if (event.key !== 'Tab') return;
// Stories covers GEV while it is open: Tab stays in Stories.
if (documentRef.body?.classList?.contains?.('stories-mode')) return;
const order = [
...root.querySelectorAll(
'button, input, [href], [tabindex]:not([tabindex="-1"])',
+20 -6
View File
@@ -5,15 +5,14 @@ import UiButton from '../kit/UiButton.vue';
import RailPanel from '../rail/RailPanel.vue';
import { useSceneSharingStore } from '../stores/sceneSharing.js';
import { useSceneStore } from '../stores/scenes.js';
import { STORY_TAG_LIMIT, STORY_TAGS } from '../../scenes/storyTags.js';
import { vClassToggle } from '../rail/classToggle.js';
import SceneDialog from './panels/SceneDialog.vue';
import SceneOptions from './SceneOptions.vue';
import SceneShotList from './SceneShotList.vue';
import CctvPanel from './panels/CctvPanel.vue';
import StreetLevelPanel from './panels/StreetLevelPanel.vue';
import DrawControls from './panels/DrawControls.vue';
import GeoImport from './panels/GeoImport.vue';
import UiSelect from '../kit/UiSelect.js';
import LayerSectionIndex from './panels/LayerSectionIndex.vue';
import LayerFinder from './panels/LayerFinder.vue';
import DataLibraryBrowse from './panels/DataLibraryBrowse.vue';
@@ -24,8 +23,14 @@ const { toolbar, dialog } = storeToRefs(useSceneSharingStore());
// SceneControls presents the Scene panel's buttons, status and progress and
// answers the buttons through the store.
const scenes = useSceneStore();
const { panel: scene } = storeToRefs(scenes);
const { panel: scene, currentScene } = storeToRefs(scenes);
const off = (name) => scene.value?.disabled[name] ?? false;
// The current scene's Stories tags; a chip not yet on is off at the limit.
const tagOn = (tag) => currentScene.value?.storyTags?.includes(tag) ?? false;
const tagOff = (tag) =>
off('tags') ||
(!tagOn(tag) &&
(currentScene.value?.storyTags?.length ?? 0) >= STORY_TAG_LIMIT);
// The hidden file input is the IMPORT button's chooser, open only while an
// owner presents the panel. It is cleared once the import settles, so the same
// file can be chosen again, unless the owner went away meanwhile.
@@ -69,7 +74,7 @@ async function importChosen(event) {
<RailPanel id="scene-panel" start-collapsed v-class-toggle="{ running: scene?.running, 'has-shots': scene?.hasShots }" :title="t('AUTHORING')" :hint="t('Create and edit scenes')" scroll>
<p class="scene-step-heading">{{ t('SCENE') }}</p>
<div class="scene-controls">
<UiSelect class="gev-field" id="scene-select" :aria-label="t('Scene')" :disabled="off('select')" @update:model-value="scenes.act('selectScene', $event)"><SceneOptions /></UiSelect>
<p id="scene-name" :class="{ 'scene-name-empty': !currentScene }">{{ currentScene?.title ?? t('No scene yet') }}</p>
<UiButton id="scene-new-btn" type="button" :disabled="off('new')" @click="scenes.act('create')" class="gev-action-button scene-btn" :title="t('Start a new, empty scene')">{{ t('NEW SCENE') }}</UiButton>
<UiButton tone="alert" id="scene-delete-btn" type="button" :disabled="off('delete')" @click="scenes.act('deleteScene')" class="gev-action-button gev-action-button--danger scene-btn scene-btn-danger" :title="t('Delete this scene and all of its shots')">{{ t('DELETE') }}</UiButton>
</div>
@@ -87,6 +92,15 @@ async function importChosen(event) {
<UiButton id="scene-next-btn" type="button" :disabled="off('next')" @click="scenes.act('next')" class="gev-action-button scene-btn" :title="t('Play the shot after the selected one, moving on to the next scene when needed')">{{ t('NEXT') }}</UiButton>
</div>
<p class="scene-step-heading">{{ t('SAVE & SHARE') }}</p>
<div class="scene-controls scene-tag-chips" role="group" :aria-label="t('Stories tags')">
<UiButton v-for="tag in STORY_TAGS" :key="tag" type="button" class="scene-tag-chip" :pressed="tagOn(tag)" pressed-class="active" :disabled="tagOff(tag)" @click="scenes.act('tag', tag)">{{ t(tag) }}</UiButton>
</div>
<div class="scene-controls scene-story-controls">
<img v-if="currentScene?.storyThumb" id="scene-thumb-preview" class="scene-thumb-preview" :src="currentScene.storyThumb" :alt="t('Story thumbnail')" width="64" height="36" />
<span v-else class="scene-thumb-preview scene-thumb-empty" aria-hidden="true"></span>
<UiButton id="scene-thumb-btn" type="button" :disabled="off('thumb')" @click="scenes.act('thumb')" class="gev-action-button scene-btn" :title="t('Use the current view as the Stories card image')">{{ t('THUMBNAIL') }}</UiButton>
<UiButton id="scene-stories-btn" type="button" :disabled="off('stories')" @click="scenes.act('stories')" class="gev-action-button scene-btn" :title="scene?.inStories ? t('Take this scene off the Stories page') : t('Show this scene on the Stories page')">{{ scene?.inStories ? t('REMOVE FROM STORIES') : t('SAVE TO STORIES') }}</UiButton>
</div>
<div class="scene-controls scene-file-controls">
<UiButton id="scene-export-btn" type="button" :disabled="off('export')" @click="scenes.act('export')" class="gev-action-button scene-btn" :title="t('Download every scene as a JSON file you can import later')">{{ t('EXPORT') }}</UiButton>
<UiButton id="scene-import-btn" type="button" :disabled="off('import')" @click="chooseImport($refs.sceneFile)" class="gev-action-button scene-btn" :title="t('Load scenes from an exported JSON file')">{{ t('IMPORT') }}</UiButton>
@@ -94,8 +108,8 @@ async function importChosen(event) {
<input ref="sceneFile" type="file" id="scene-import-file" accept="application/json,.json" hidden @change="importChosen" />
</div>
<div v-if="toolbar" data-director-authoring class="scene-controls">
<UiButton type="button" class="gev-action-button scene-btn" :title="t('Edit anchors, data packs and shot details')" @click="toolbar.edit()">{{ t('EDIT DETAILS') }}</UiButton>
<UiButton type="button" class="gev-action-button scene-btn" :title="t('Download this scene as JSON or an asset bundle')" @click="toolbar.share()">{{ t('SHARE SCENE') }}</UiButton>
<UiButton type="button" class="gev-action-button scene-btn" :disabled="off('details')" :title="t('Edit anchors, data packs and shot details')" @click="toolbar.edit()">{{ t('EDIT DETAILS') }}</UiButton>
<UiButton type="button" class="gev-action-button scene-btn" :disabled="off('share')" :title="t('Download this scene as JSON or an asset bundle')" @click="toolbar.share()">{{ t('SHARE SCENE') }}</UiButton>
</div>
<div class="scene-progress">
<div id="scene-progress-fill" :style="scene ? { width: `${scene.progress}%` } : undefined">{{ scene?.progress ?? 0 }}%</div>
-31
View File
@@ -1,31 +0,0 @@
<script setup>
import { storeToRefs } from 'pinia';
import { getCurrentInstance, watch } from 'vue';
import { useSceneStore } from '../stores/scenes.js';
// The Scene select's options; selecting one stays with SceneControls.
const { scenes, listedSceneId, listedRevision } = storeToRefs(useSceneStore());
// Every option render shows the published scene, as the select did before:
// `selected` alone is written only when it changes, so it would leave a
// person's later pick standing.
const instance = getCurrentInstance();
watch(
listedRevision,
() => {
const select = instance.proxy.$el?.parentNode;
if (select && listedSceneId.value) select.value = listedSceneId.value;
},
{ flush: 'post' },
);
</script>
<template>
<option
v-for="scene in scenes"
:key="scene.id"
:value="scene.id"
:selected="scene.id === listedSceneId"
>{{ scene.title }}</option
>
</template>
+337
View File
@@ -0,0 +1,337 @@
<script setup>
import {
computed,
defineAsyncComponent,
nextTick,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue';
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 { guardStoriesKeyboard } from '../../stories/keyboard.js';
// The screens, their styles and the story data load with Stories (see
// src/stories/boot.js); only the button, popup and toast load with GEV.
const ExploreScreen = defineAsyncComponent(
() => import('./stories/ExploreScreen.vue'),
);
const StoryScreen = defineAsyncComponent(
() => import('./stories/StoryScreen.vue'),
);
/**
* GEV Stories, as the Stories prototype lays it out: a Stories button in
* GEV's top-right row, Explore (the globe beside the story feed) and the
* Story page. Both show GEV's own Cesium globe through their map areas.
*/
const store = useStoriesStore();
const { mode, storyId, toast, hostedToast } = storeToRefs(store);
const story = computed(() => (storyId.value ? store.byId(storyId.value) : null));
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; GEV Hosted adds the account
// avatar, which can come after Stories mounts (sign-in).
const CORNER = ['style-indicator', 'account-control'];
const entry = ref({ top: 14, right: 14 });
function placeEntry() {
entry.value = entryPlacement(
CORNER.map((id) => document.getElementById(id)?.getBoundingClientRect()),
innerWidth,
);
}
let entryTries = 0;
let entryTimer = 0;
let cornerObserver = null;
const observed = new Set();
// GEV Hosted moves the corner by body class (signed in, guest) without
// resizing it, which a ResizeObserver does not see.
let bodyObserver = null;
function watchCorner() {
placeEntry();
if (!bodyObserver && globalThis.MutationObserver) {
bodyObserver = new MutationObserver(placeEntry);
bodyObserver.observe(document.body, {
attributes: true,
attributeFilter: ['class'],
});
}
if (globalThis.ResizeObserver) cornerObserver ??= new ResizeObserver(placeEntry);
for (const id of CORNER) {
const el = document.getElementById(id);
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 && ++entryTries < 20)
entryTimer = setTimeout(watchCorner, 1000);
}
// ── GEV's required credit line: bottom left of the map, at every size ──
// A playing GEV scene turns on GEV's recording mode, whose rule drops the
// credit to the window's bottom edge, under the Stories timeline. Measure
// the map instead and pin the credit just inside it, playing or not.
let creditSlot = null;
let creditObserver = null;
let creditFrame = 0;
let creditTries = 0;
function placeCredit() {
const root = document.documentElement.style;
const at = creditPlacement({
map: creditSlot?.getBoundingClientRect(),
feed: document.querySelector('#gev-stories .ex-feed')?.getBoundingClientRect(),
width: innerWidth,
height: innerHeight,
});
if (!at) {
root.removeProperty('--gs-credit-bottom');
root.removeProperty('--gs-credit-left');
return;
}
root.setProperty('--gs-credit-bottom', `${at.bottom}px`);
root.setProperty('--gs-credit-left', `${at.left}px`);
}
function watchCredit() {
cancelAnimationFrame(creditFrame);
creditObserver?.disconnect();
creditSlot = null;
if (mode.value === 'closed') {
creditTries = 0;
placeCredit();
return;
}
creditSlot = document.querySelector('#gev-stories .map-slot');
if (!creditSlot) {
if (++creditTries < 120) creditFrame = requestAnimationFrame(watchCredit);
return;
}
creditTries = 0;
placeCredit();
if (globalThis.ResizeObserver) {
creditObserver = new ResizeObserver(placeCredit);
creditObserver.observe(creditSlot);
const feed = document.querySelector('#gev-stories .ex-feed');
if (feed) creditObserver.observe(feed);
}
}
// ── One onboarding popup in GEV ──
const POP_KEY = 'gevStoriesPopSeen';
const popOpen = ref(false);
function readPopSeen() {
try {
return localStorage.getItem(POP_KEY) === '1';
} catch {
return store.popSeen;
}
}
function markPopSeen() {
store.popSeen = true;
popOpen.value = false;
try {
localStorage.setItem(POP_KEY, '1');
} catch {
/* storage off: the popup comes back next visit */
}
}
function openExplore() {
markPopSeen();
store.controller.open();
}
// ── Opened in GEV: a toast that leads back to the story ──
let hostedTimer = 0;
watch(hostedToast, (v) => {
clearTimeout(hostedTimer);
if (v) hostedTimer = setTimeout(() => (hostedToast.value = null), 6000);
});
function backToStory() {
const v = hostedToast.value;
hostedToast.value = null;
if (v) store.controller.openStory(v.id, { atMs: v.atMs });
}
const hostedWhen = computed(() => hostedToast.value?.when ?? '');
// ── Card-to-map morph: Play grows the card into the story; Back folds it home ──
const appEl = ref(null);
const rootEl = ref(null);
let unguardKeys = null;
function ghost(id, rect) {
const g = document.createElement('div');
g.className = 'morph';
// Without a picture the ghost keeps the cards' placeholder look (CSS).
const thumb = store.thumbs?.[id] || '';
if (thumb) g.style.background = `#04070a url("${thumb}") center / cover no-repeat`;
Object.assign(g.style, rect);
appEl.value?.appendChild(g);
return g;
}
const rectOf = (el) => {
const r = el.getBoundingClientRect();
return { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` };
};
async function playFromExplore({ id, from }) {
if (reduceMotion() || !from?.offsetWidth) {
store.controller.openStory(id, { autoplay: true });
return;
}
const a = rectOf(from);
const g = ghost(id, a);
store.controller.openStory(id, { autoplay: true });
await nextTick();
const map = document.getElementById('stMap');
if (!map) {
g.remove();
return;
}
const b = rectOf(map);
g.animate(
[
{ ...a, borderRadius: '9px', opacity: 1 },
{ ...b, borderRadius: '0px', opacity: 1, offset: 0.8 },
{ ...b, borderRadius: '0px', opacity: 0 },
],
{ duration: 640, easing: 'cubic-bezier(.2,.9,.2,1)' },
).onfinish = () => g.remove();
}
async function backFromStory() {
const id = storyId.value;
const map = document.getElementById('stMap');
if (reduceMotion() || !map?.offsetWidth) {
store.controller.backToExplore();
return;
}
const a = rectOf(map);
const g = ghost(id, a);
store.picked = id;
store.controller.backToExplore();
await nextTick();
await new Promise((r) => requestAnimationFrame(r));
const card = document.querySelector(`#gev-stories .card[data-id="${CSS.escape(id)}"]`);
card?.scrollIntoView({ block: 'nearest' });
const dst = card?.querySelector('.thumb');
if (!dst?.offsetWidth) {
g.remove();
return;
}
g.animate(
[
{ ...a, borderRadius: '0px', opacity: 1 },
{ ...rectOf(dst), borderRadius: '9px', opacity: 1 },
],
{ duration: 560, easing: 'cubic-bezier(.2,.9,.2,1)' },
).onfinish = () => {
g.remove();
card.classList.remove('flash');
void card.offsetWidth;
card.classList.add('flash');
};
}
// ── Escape closes the topmost open layer, then steps back ──
function onKey(e) {
if (e.key !== 'Escape' || mode.value === 'closed' || e.defaultPrevented) return;
const target = e.target;
if (target?.type === 'search' && target.value) return;
const q = (sel) => document.querySelector(`#gev-stories ${sel}`);
e.preventDefault();
if (q('#exFilter')) q('#exFilterBtn')?.click();
else if (store.ctxOpen) store.ctxOpen = false;
else if (store.expanded) {
store.expanded = false;
store.controller.reframe();
} else if (mode.value === 'story') backFromStory();
else store.controller.close();
}
onMounted(() => {
watchCorner();
addEventListener('resize', placeEntry);
addEventListener('resize', placeCredit);
addEventListener('keydown', onKey, true);
unguardKeys = guardStoriesKeyboard({
root: rootEl.value,
// Until Close has put the view back, too (stories-mode stays till then).
isOpen: () =>
mode.value !== 'closed' ||
document.body.classList.contains('stories-mode'),
});
popOpen.value = !readPopSeen();
watchCredit();
});
onBeforeUnmount(() => {
clearTimeout(entryTimer);
clearTimeout(hostedTimer);
cancelAnimationFrame(creditFrame);
cornerObserver?.disconnect();
bodyObserver?.disconnect();
creditObserver?.disconnect();
creditSlot = null;
placeCredit();
removeEventListener('resize', placeEntry);
removeEventListener('resize', placeCredit);
removeEventListener('keydown', onKey, true);
unguardKeys?.();
});
watch(mode, (m) => {
if (m === 'closed') requestAnimationFrame(placeEntry);
else popOpen.value = false;
});
// Each screen (and each story, keyed) mounts its own map slot.
watch([mode, storyId], () => nextTick(watchCredit));
</script>
<template>
<div id="gev-stories" ref="rootEl">
<svg width="0" height="0" style="position: absolute" aria-hidden="true" v-html="GEV_LOGO_SYMBOL"></svg>
<!-- GEV: the Stories entry, its first-visit popup and the Opened-in-GEV toast -->
<template v-if="mode === 'closed' && store.available">
<button
id="hStories"
class="tbtn accent gs-entry"
type="button"
:style="{ top: `${entry.top}px`, right: `${entry.right}px` }"
@click="openExplore"
>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="3" /><path d="M10 9.5v5l4.5-2.5z" fill="currentColor" /></svg>
<span>{{ t('Stories') }}</span>
</button>
<div
v-if="popOpen"
id="hPop"
class="h-pop gs-pop"
role="region"
aria-labelledby="hPopT"
:style="{ top: `${entry.top + 52}px`, right: `${Math.max(12, entry.right - 40)}px` }"
>
<span class="k">{{ t('NEW') }}</span>
<h2 id="hPopT">{{ t('GEV Stories') }}</h2>
<p>{{ t('Curated, interactive views of what is happening on Earth. Play one, take over the map whenever you like, then pick the story back up.') }}</p>
<div class="row">
<button class="tbtn solid" type="button" @click="openExplore">{{ t('Browse stories') }}</button>
<button class="tbtn" type="button" @click="markPopSeen">{{ t('Not now') }}</button>
</div>
</div>
<div v-if="hostedToast" id="hToast" class="h-toast glass gs-hosted-toast" role="status">
<b>{{ t('Opened in GEV') }}</b>
<span>{{ hostedToast.title }} · {{ hostedWhen }}</span>
<button class="tbtn" type="button" @click="backToStory">{{ t('Back to story') }}</button>
</div>
</template>
<div v-if="mode !== 'closed'" ref="appEl" class="app">
<ExploreScreen v-if="mode === 'explore'" @play="playFromExplore" />
<StoryScreen v-if="mode === 'story' && story" :key="story.id" :story="story" @back="backFromStory" />
<div v-if="toast" id="uxToast" class="ux-toast" role="status" aria-live="polite">{{ toast }}</div>
</div>
</div>
</template>
+2
View File
@@ -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();
+1 -1
View File
@@ -11,6 +11,6 @@ const optional = (value) => value ?? undefined;
<template>
<Teleport to="body">
<div v-for="split in splits" :key="split.key" :id="optional(split.view.id)" :hidden="split.view.hidden"><span class="before" :title="optional(split.view.beforeTitle)">{{ split.view.beforeLabel }}</span><button type="button" :class="optional(split.view.handleClass)" role="slider" :aria-label="optional(split.view.ariaLabel)" aria-valuemin="0" aria-valuemax="100" aria-orientation="horizontal" :aria-valuenow="split.view.valueNow" :aria-valuetext="split.view.valueText" @pointerdown="split.controls.pointerdown($event)" @pointermove="split.controls.pointermove($event)" @pointerup="split.controls.pointerup($event)" @pointercancel="split.controls.pointerup($event)" @keydown="split.controls.keydown($event)">↔</button><span class="after" :title="optional(split.view.afterTitle)">{{ split.view.afterLabel }}</span></div>
<div v-for="split in splits" :key="split.key" :id="optional(split.view.id)" data-globe-overlay :hidden="split.view.hidden"><span class="before" :title="optional(split.view.beforeTitle)">{{ split.view.beforeLabel }}</span><button type="button" :class="optional(split.view.handleClass)" role="slider" :aria-label="optional(split.view.ariaLabel)" aria-valuemin="0" aria-valuemax="100" aria-orientation="horizontal" :aria-valuenow="split.view.valueNow" :aria-valuetext="split.view.valueText" @pointerdown="split.controls.pointerdown($event)" @pointermove="split.controls.pointermove($event)" @pointerup="split.controls.pointerup($event)" @pointercancel="split.controls.pointerup($event)" @keydown="split.controls.keydown($event)">↔</button><span class="after" :title="optional(split.view.afterTitle)">{{ split.view.afterLabel }}</span></div>
</Teleport>
</template>
+782
View File
@@ -0,0 +1,782 @@
<script setup>
import {
computed,
nextTick,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue';
import { storeToRefs } from 'pinia';
import { t, tn } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
import {
FILTERS,
clamp,
fmtDur,
layersFor,
metaFor,
topicsOf,
storyText,
windowText,
} from '../../../stories/storyMeta.js';
import StoriesHeader from './StoriesHeader.vue';
/**
* Explore (prototype `.scr-explore`): the feed beside GEV's Cesium globe,
* which shows through the map area and takes input where nothing of
* Stories sits on it.
*/
const emit = defineEmits(['play']);
const store = useStoriesStore();
const { query, chips, sort, filters, picked, pins, feedSnap } =
storeToRefs(store);
const all = computed(() => store.stories);
// A story's card picture, when there is one; otherwise the card shows its
// placeholder (CSS), never a broken image.
const thumbFor = (s) => (s && store.thumbs?.[s.id]) || '';
const titleOf = (s) => storyText(s.title);
const layerNames = (s) => layersFor(s).map((l) => storyText(l[2]));
// What a story is found by in the feed's search, in the page's language.
function searchText(s) {
const m = metaFor(s);
return [
titleOf(s),
s.creator,
windowText(s),
m.region,
m.place,
...m.topics,
...layerNames(s),
]
.join(' ')
.toLowerCase();
}
const shown = computed(() => {
const words = query.value.toLowerCase().split(/\s+/).filter(Boolean);
const f = filters.value;
const list = all.value.filter((s) => {
const m = metaFor(s);
const txt = searchText(s);
if (words.some((w) => !txt.includes(w))) return false;
if (
chips.value.length &&
!chips.value.some((c) => (c === 'Live' ? s.live : m.topics.includes(c)))
)
return false;
if (f.region?.length && !f.region.includes(m.region)) return false;
if (
f.length?.length &&
!f.length.includes(s.durationMs < 60000 ? 'short' : 'long')
)
return false;
return true;
});
const end = (s) => s.tMaxMs ?? 0;
const by = {
new: (a, b) => end(b) - end(a),
long: (a, b) => b.durationMs - a.durationMs,
az: (a, b) => titleOf(a).localeCompare(titleOf(b)),
}[sort.value];
return [...list].sort(by);
});
const shownIds = computed(() => new Set(shown.value.map((s) => s.id)));
const count = computed(() =>
shown.value.length === all.value.length
? `${all.value.length}`
: `${shown.value.length}/${all.value.length}`,
);
// ── Chips and filters ──
// Every story is a GEV scene: a "made with" filter would not narrow anything.
// The topic chips and region choices are the ones the stories carry, so
// none of them narrows the feed to nothing.
const topics = computed(() => topicsOf(all.value));
const filterGroups = computed(() =>
FILTERS.map(([key, label, opts]) => {
if (key !== 'region') return [key, label, opts];
const regions = new Set(all.value.map((s) => metaFor(s).region));
return [key, label, opts.filter(([value]) => regions.has(value))];
}).filter(([, , opts]) => opts.length > 1),
);
function toggleChip(c) {
if (!c) chips.value = [];
else if (chips.value.includes(c))
chips.value = chips.value.filter((x) => x !== c);
else chips.value = [...chips.value, c];
}
const filterOpen = ref(false);
const filterCount = computed(() =>
filterGroups.value.reduce(
(n, [key]) => n + (filters.value[key]?.length ?? 0),
0,
),
);
function toggleFilter(key, value, on) {
const list = filters.value[key] ?? [];
filters.value = {
...filters.value,
[key]: on ? [...list, value] : list.filter((v) => v !== value),
};
}
function clearFilters() {
filters.value = { region: [], length: [] };
}
function resetAll() {
clearFilters();
chips.value = [];
query.value = '';
filterOpen.value = false;
}
const filterEl = ref(null);
const filterBtn = ref(null);
function onDocDown(e) {
if (
filterOpen.value &&
!filterEl.value?.contains(e.target) &&
!filterBtn.value?.contains(e.target)
)
filterOpen.value = false;
}
// ── Search ──
const searchEl = ref(null);
function onSearchKey(e) {
if (e.key === 'Escape') {
query.value = '';
e.target.blur();
e.preventDefault();
} else if (e.key === 'Enter') {
const first = shown.value[0];
if (first) pick(first.id);
}
}
function onSlash(e) {
if (
e.key === '/' &&
!/INPUT|TEXTAREA|SELECT/.test(document.activeElement?.tagName ?? '')
) {
e.preventDefault();
searchEl.value?.focus();
}
}
function headerSearch() {
if (feedSnap.value === 'map') setFeed('split');
searchEl.value?.focus();
}
// ── Picking and playing ──
const feedEl = ref(null);
function pick(id) {
if (picked.value === id) return;
if (innerWidth <= 700 && feedSnap.value === 'list') setFeed('split');
store.controller.pick(id);
nextTick(() =>
feedEl.value
?.querySelector(`.card[data-id="${CSS.escape(id)}"]`)
?.scrollIntoView({ block: 'nearest', behavior: 'smooth' }),
);
}
function play(id, from) {
emit('play', { id, from });
}
function onCardKey(e, s) {
if ((e.key === 'Enter' || e.key === ' ') && e.target === e.currentTarget) {
e.preventDefault();
if (picked.value === s.id)
play(s.id, e.currentTarget.querySelector('.thumb'));
else pick(s.id);
}
}
// The pin last clicked: a pin plays on its own second click, so a story
// picked from the feed first shows its play button on the pin.
let armedPin = null;
watch(picked, (id) => {
if (id !== armedPin) armedPin = null;
});
function onPin(e, id) {
if (picked.value === id && armedPin === id)
play(id, e.currentTarget.querySelector('.pin-thumb'));
else {
armedPin = id;
if (picked.value !== id) pick(id);
}
}
const pickedStory = computed(() =>
picked.value ? store.byId(picked.value) : null,
);
// ── Pins: projected in window pixels, placed inside the map area ──
const pinsEl = ref(null);
const origin = ref({ x: 0, y: 0 });
function measure() {
const r = pinsEl.value?.getBoundingClientRect();
if (r) origin.value = { x: r.left, y: r.top };
}
watch(pins, measure);
const placedPins = computed(() =>
pins.value.map((p) => ({
...p,
story: store.byId(p.id),
style: {
transform: `translate(${p.x - origin.value.x}px, ${p.y - origin.value.y}px) translate(-50%, -100%)`,
},
})),
);
// ── Phone: drag the list header to trade globe space for list space ──
const FEED = { map: 0.3, split: 0.56, list: 0.86 };
const FEED_ORDER = ['map', 'split', 'list'];
const bodyEl = ref(null);
const dragging = ref(false);
const feedH = ref(null);
function setFeed(snap) {
feedSnap.value = snap;
feedH.value = null;
setTimeout(() => store.controller.reframe(), 320);
}
let fd = null;
function onHeadDown(e) {
if (innerWidth > 700 || e.target.closest('.fh-tools')) return;
try {
e.currentTarget.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
const body = bodyEl.value;
fd = {
y: e.clientY,
frac: body.querySelector('.ex-feed').offsetHeight / body.clientHeight,
H: body.clientHeight,
lastY: e.clientY,
lastT: performance.now(),
v: 0,
moved: false,
};
}
function onHeadMove(e) {
if (!fd) return;
const dy = e.clientY - fd.y;
if (!fd.moved && Math.abs(dy) > 4) {
fd.moved = true;
dragging.value = true;
}
if (!fd.moved) return;
feedH.value = clamp(fd.frac - dy / fd.H, 0.18, 0.9);
const now = performance.now();
fd.v = (e.clientY - fd.lastY) / Math.max(1, now - fd.lastT);
fd.lastY = e.clientY;
fd.lastT = now;
}
function onHeadUp() {
if (!fd) return;
if (fd.moved) {
const f = feedH.value ?? FEED[feedSnap.value];
let snap;
if (fd.v < -0.5) snap = f < FEED.split ? 'split' : 'list';
else if (fd.v > 0.5) snap = f > FEED.split ? 'split' : 'map';
else
snap = FEED_ORDER.reduce((a, b) =>
Math.abs(FEED[b] - f) < Math.abs(FEED[a] - f) ? b : a,
);
dragging.value = false;
setFeed(snap);
} else setFeed(FEED_ORDER[(FEED_ORDER.indexOf(feedSnap.value) + 1) % 3]);
fd = null;
}
function onGripKey(e) {
const i = FEED_ORDER.indexOf(feedSnap.value);
if (e.key === 'ArrowUp') {
e.preventDefault();
setFeed(FEED_ORDER[Math.min(2, i + 1)]);
} else if (e.key === 'ArrowDown') {
e.preventDefault();
setFeed(FEED_ORDER[Math.max(0, i - 1)]);
} else if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setFeed(FEED_ORDER[(i + 1) % 3]);
}
}
// Desktop and tablet: drag the feed's right edge to widen it, up to 50 px
// past its default; double-click puts it back.
const FEED_W = 340;
const FEED_W_MAX = FEED_W + 50;
const FEED_W_MIN = 280;
const feedW = ref(FEED_W);
try {
const saved = +localStorage.getItem('gevFeedW');
if (saved) feedW.value = clamp(saved, FEED_W_MIN, FEED_W_MAX);
} catch {
/* storage off: the default width */
}
// The feed sits over the map on desktop: a new width moves the free part of
// the map, which a resize of the map itself would not report.
watch(feedW, () => nextTick(() => store.controller.reframe()));
const resizing = ref(false);
let rw = null;
function setFeedW(px) {
feedW.value = Math.round(clamp(px, FEED_W_MIN, FEED_W_MAX));
try {
localStorage.setItem('gevFeedW', feedW.value);
} catch {
/* storage off: the width lasts this visit */
}
}
function onResizeDown(e) {
try {
e.currentTarget.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
rw = { x: e.clientX, w: feedW.value };
resizing.value = true;
e.preventDefault();
}
function onResizeMove(e) {
if (rw) setFeedW(rw.w + (e.clientX - rw.x));
}
function onResizeUp() {
rw = null;
resizing.value = false;
}
function onResizeKey(e) {
const d = { ArrowRight: 10, ArrowLeft: -10 }[e.key];
if (!d) return;
e.preventDefault();
setFeedW(feedW.value + d);
}
function onResizeReset() {
feedW.value = FEED_W;
try {
localStorage.removeItem('gevFeedW');
} catch {
/* storage off */
}
}
const bodyStyle = computed(() => ({
'--feed-h': `${(feedH.value ?? FEED[feedSnap.value]) * 100}%`,
...(innerWidth > 700
? {
'--feedw': `${feedW.value}px`,
gridTemplateColumns: `${feedW.value}px minmax(0, 1fr)`,
}
: {}),
}));
onMounted(() => {
document.addEventListener('pointerdown', onDocDown);
// On the window: the Stories keyboard guard stops keys before the document.
addEventListener('keydown', onSlash, true);
addEventListener('resize', measure);
measure();
});
onBeforeUnmount(() => {
document.removeEventListener('pointerdown', onDocDown);
removeEventListener('keydown', onSlash, true);
removeEventListener('resize', measure);
});
defineExpose({
cardThumb: (id) =>
feedEl.value?.querySelector(`.card[data-id="${CSS.escape(id)}"]`),
});
</script>
<template>
<section
id="scrExplore"
class="scr scr-explore"
:aria-label="t('GEV Stories explore')"
>
<StoriesHeader
screen="explore"
@back="store.controller.close()"
@home="store.controller.close()"
@search="headerSearch"
/>
<div
id="exBody"
ref="bodyEl"
class="ex-body"
:class="{ 'feed-dragging': dragging }"
data-side="left"
:style="bodyStyle"
>
<div
class="ex-feed-resize"
:class="{ on: resizing }"
role="separator"
aria-orientation="vertical"
:aria-label="t('Resize story list')"
:aria-valuenow="feedW"
:aria-valuemin="FEED_W_MIN"
:aria-valuemax="FEED_W_MAX"
tabindex="0"
:style="{ left: `${feedW - 5}px` }"
@pointerdown="onResizeDown"
@pointermove="onResizeMove"
@pointerup="onResizeUp"
@pointercancel="onResizeUp"
@dblclick="onResizeReset"
@keydown="onResizeKey"
></div>
<aside class="ex-feed" :aria-label="t('Stories')">
<div class="ex-feed-top">
<div
id="feedHead"
class="ex-feed-head"
@pointerdown="onHeadDown"
@pointermove="onHeadMove"
@pointerup="onHeadUp"
@pointercancel="onHeadUp"
>
<button
id="feedGrip"
class="feed-grip"
type="button"
:aria-label="t('Story list size. Drag, or press to change')"
@keydown="onGripKey"
></button>
<h1>{{ t('GEV Stories') }}</h1>
<span
id="exCount"
:aria-label="
tn(
all.length,
'{n} of {count} story',
'{n} of {count} stories',
{
n: shown.length,
},
)
"
>{{ count }}</span
>
<div class="fh-tools">
<label class="sr" for="exSort">{{ t('Sort stories') }}</label>
<select id="exSort" v-model="sort" class="fh-sort">
<option value="new">{{ t('Newest') }}</option>
<option value="long">{{ t('Longest') }}</option>
<option value="az">{{ t('A–Z') }}</option>
</select>
<button
id="exFilterBtn"
ref="filterBtn"
type="button"
class="fh-filter"
:class="{ on: filterCount }"
:aria-expanded="filterOpen"
aria-controls="exFilter"
:aria-label="
filterCount
? tn(filterCount, '{count} filter on', '{count} filters on')
: t('Filters')
"
@click.stop="filterOpen = !filterOpen"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.9"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M4 6h16M7 12h10M10 18h4" />
</svg>
<b v-if="filterCount" id="exFilterN">{{ filterCount }}</b>
</button>
</div>
</div>
<div id="exTools" class="ex-tools" @pointerdown.stop @wheel.stop>
<div class="fh-search m-only-search" role="search">
<label class="sr" for="exQm">{{ t('Search stories') }}</label>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
aria-hidden="true"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
<input
id="exQm"
ref="searchEl"
v-model="query"
class="ex-q"
type="search"
:placeholder="t('Search stories, places, creators')"
autocomplete="off"
@keydown="onSearchKey"
/>
<button
v-if="query"
type="button"
class="ex-qx"
:aria-label="t('Clear search')"
@click="
query = '';
searchEl?.focus();
"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
aria-hidden="true"
>
<path d="M6 6l12 12M18 6 6 18" />
</svg>
</button>
<kbd class="hide-m">/</kbd>
</div>
<div class="fh-row">
<div
id="exChips"
class="fh-chips"
role="group"
:aria-label="t('Topics')"
>
<button
type="button"
class="chip"
:aria-pressed="!chips.length"
@click="toggleChip('')"
>{{ t('All') }}</button
>
<button
v-for="c in topics"
:key="c"
type="button"
class="chip"
:class="{ live: c === 'Live' }"
:aria-pressed="chips.includes(c)"
@click="toggleChip(c)"
><i v-if="c === 'Live'"></i>{{ t(c) }}</button
>
</div>
</div>
<div
v-if="filterOpen"
id="exFilter"
ref="filterEl"
class="ex-filter"
role="dialog"
:aria-label="t('Filter stories')"
>
<fieldset v-for="[key, label, opts] in filterGroups" :key="key">
<legend>{{ t(label) }}</legend>
<label v-for="[value, text] in opts" :key="value" class="fopt">
<input
type="checkbox"
:checked="filters[key]?.includes(value)"
@change="toggleFilter(key, value, $event.target.checked)"
/>
<span>{{ t(text) }}</span>
</label>
</fieldset>
<div class="fact">
<button type="button" class="tbtn" @click="clearFilters">{{
t('Clear')
}}</button>
<button
type="button"
class="tbtn solid"
@click="
filterOpen = false;
filterBtn?.focus();
"
>
{{
tn(
shown.length,
'Show {count} story',
'Show {count} stories',
)
}}
</button>
</div>
</div>
</div>
</div>
<ul id="feed" ref="feedEl" class="feed">
<li v-if="!shown.length" class="feed-empty">
<b>{{ t('No stories match') }}</b>
<span>{{ t('Try another word or clear the filters.') }}</span>
<button type="button" class="tbtn" @click="resetAll">{{
t('Clear all')
}}</button>
</li>
<li v-for="s in shown" :key="s.id">
<div
class="card"
role="button"
tabindex="0"
:data-id="s.id"
:aria-pressed="picked === s.id"
@click="pick(s.id)"
@keydown="onCardKey($event, s)"
>
<span class="thumb">
<img
v-if="thumbFor(s)"
:src="thumbFor(s)"
alt=""
loading="lazy"
/>
<span v-if="s.live" class="chip"
><span class="dot"></span>{{ t('LIVE') }}</span
>
<span v-else class="chip">{{
s.draft ? t('DRAFT') : t('STORY')
}}</span>
<span class="dur">{{ fmtDur(s.durationMs) }}</span>
<button
class="thumb-play"
type="button"
:aria-label="t('Play {title}', { title: titleOf(s) })"
@click.stop="play(s.id, $event.currentTarget.parentElement)"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M9 6.5v11l9-5.5z" fill="currentColor" />
</svg>
</button>
</span>
<span class="c-title">{{ titleOf(s) }}</span>
<span class="c-meta">{{ s.creator }} · {{ windowText(s) }}</span>
<span class="c-layers"
><span v-for="l in layerNames(s)" :key="l">{{ l }}</span></span
>
<span class="c-play">
<button
class="tbtn solid"
type="button"
@click.stop="
play(
s.id,
$event.currentTarget
.closest('.card')
.querySelector('.thumb'),
)
"
>
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M7 4.5v15l12.5-7.5z" /></svg
>{{ t('Play story') }}
</button>
</span>
</div>
</li>
</ul>
</aside>
<div class="ex-map">
<div class="map-slot"></div>
<div id="pins" ref="pinsEl" class="pins">
<button
v-for="p in placedPins"
:key="p.id"
class="pin"
:class="{ out: !shownIds.has(p.id), hidden: !p.visible }"
type="button"
:data-id="p.id"
:aria-pressed="picked === p.id"
:aria-label="t('Preview {title}', { title: titleOf(p.story) })"
:style="p.style"
@click="onPin($event, p.id)"
>
<span
class="pin-thumb"
:data-preview="t('Click to preview')"
:data-play="t('Click to play')"
:data-tap="t('Tap to play')"
:data-play-short="t('Play')"
><img v-if="thumbFor(p.story)" :src="thumbFor(p.story)" alt=""
/></span>
<span class="pin-lbl">{{ titleOf(p.story).split(':')[0] }}</span>
<span class="pin-dot"></span>
</button>
</div>
<div class="ex-msearch glass" role="search">
<label class="sr" for="exQ">{{ t('Search stories') }}</label>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
aria-hidden="true"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
<input
id="exQ"
v-model="query"
class="ex-q"
type="search"
:placeholder="t('Search stories, places, creators')"
autocomplete="off"
@keydown="onSearchKey"
/>
<button
v-if="query"
type="button"
class="ex-qx"
:aria-label="t('Clear search')"
@click="query = ''"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
aria-hidden="true"
>
<path d="M6 6l12 12M18 6 6 18" />
</svg>
</button>
<kbd>/</kbd>
</div>
<div
v-if="pickedStory"
id="exPreview"
class="ex-preview glass"
aria-live="polite"
>
<span class="k"><i></i>{{ t('PREVIEW') }}</span>
<h2>{{ titleOf(pickedStory) }}</h2>
<span class="c-meta"
>{{ pickedStory.creator }} · {{ windowText(pickedStory) }}</span
>
<span class="c-layers"
><span v-for="l in layerNames(pickedStory)" :key="l">{{
l
}}</span></span
>
<button
class="tbtn solid"
type="button"
@click="play(pickedStory.id, null)"
>
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M7 4.5v15l12.5-7.5z" /></svg
>{{ t('Play story') }}
</button>
</div>
<div v-else class="ex-hint glass">{{
t('Pick a story or a pin to preview it here')
}}</div>
</div>
</div>
</section>
</template>
+181
View File
@@ -0,0 +1,181 @@
<script setup>
import {
computed,
nextTick,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue';
import { t } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
/**
* The Stories top bar (prototype `.h-top.s-head`): back, GEV logo and
* wordmark, breadcrumb, the phone title (scrolls when it is too long) and
* the right-hand buttons.
*/
const props = defineProps({
screen: { type: String, required: true },
title: { type: String, default: '' },
});
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);
async function share() {
const what = props.screen === 'story' ? t('Story') : t('Stories');
try {
await navigator.clipboard.writeText(store.controller.shareLink());
store.flashToast(t('{what} link copied', { what }));
} catch {
store.flashToast(t('Copy this link: {url}', { url: location.href }), 4000);
}
}
// Long titles scroll gently so the whole name can be read.
const mtitle = ref(null);
let observer = null;
function fitTitle() {
const el = mtitle.value;
const sp = el?.firstElementChild;
if (!sp) return;
const over = sp.scrollWidth - el.clientWidth;
el.classList.toggle('marquee', over > 4);
el.style.setProperty('--mq', `${-(over + 22)}px`);
el.style.setProperty('--mq-dur', `${Math.max(5, (over + 22) / 22)}s`);
}
onMounted(() => {
if (globalThis.ResizeObserver && mtitle.value) {
observer = new ResizeObserver(fitTitle);
observer.observe(mtitle.value);
}
fitTitle();
});
watch(
() => props.title,
() => nextTick(fitTitle),
);
onBeforeUnmount(() => observer?.disconnect());
</script>
<template>
<header class="h-top s-head">
<button
class="s-back glass"
type="button"
:aria-label="
screen === 'story' ? t('Back to stories') : t('Back to the globe')
"
@click="emit('back')"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M15 6l-6 6 6 6" />
</svg>
</button>
<div class="h-brand">
<div class="h-brand-row">
<button
class="s-home"
type="button"
:aria-label="t('Back to the globe')"
@click="emit('home')"
>
<svg class="eye" viewBox="0 0 775 520" aria-hidden="true">
<use href="#gevLogo" />
</svg>
</button>
<span class="h-word" translate="no">GOD'S EYE <b>VIEW</b></span>
</div>
<nav class="h-tag s-trail" :aria-label="t('Breadcrumb')">
<template v-if="screen === 'explore'">
<button type="button" @click="emit('home')">{{ t('Globe') }}</button>
<span aria-hidden="true">/</span>
<b>{{ t('Stories') }}</b>
</template>
<template v-else>
<button type="button" @click="emit('crumb')">{{
t('Stories')
}}</button>
<span aria-hidden="true">/</span>
<b>{{ title }}</b>
</template>
</nav>
</div>
<span ref="mtitle" class="s-mtitle glass"
><span>{{ screen === 'explore' ? t('Stories') : title }}</span></span
>
<div class="h-right">
<button
v-if="screen === 'explore'"
class="s-msearch ibtn"
type="button"
:aria-label="t('Search')"
@click="emit('search')"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
</button>
<button
v-if="!(screen === 'story' && localOnly)"
class="tbtn hide-m"
type="button"
:aria-label="t('Share')"
@click="share"
>
<span class="share-icon" aria-hidden="true">&#x1F517;</span>
<span>{{ t('Share') }}</span>
</button>
<button
v-if="screen === 'explore'"
class="tbtn accent hide-m"
type="button"
@click="emit('home')"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M19 12H5M11 6l-6 6 6 6" />
</svg>
<span>{{ t('Back to GEV') }}</span>
</button>
<button
v-else
class="tbtn accent hide-m gs-back-stories"
type="button"
@click="emit('crumb')"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M19 12H5M11 6l-6 6 6 6" />
</svg>
<span>{{ t('GEV Stories') }}</span>
</button>
</div>
</header>
</template>
+414
View File
@@ -0,0 +1,414 @@
<script setup>
import { computed, ref } from 'vue';
import { storeToRefs } from 'pinia';
import { t, tn } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
import { chapterAt } from '../../../stories/format.js';
import {
anchorStamp,
chapterStamp,
chapterTitle,
clamp,
nowFacts,
storyText,
windowText,
} from '../../../stories/storyMeta.js';
/**
* The context panel (prototype `.st-ctx`): docked on the right on desktop,
* a sheet that peeks above the timeline on a phone. It shows what a GEV
* scene carries: right-now facts, chapters, key moments, sources and
* background, with a search over its chapters, key moments and sources.
*/
const props = defineProps({
story: { type: Object, required: true },
nudge: Boolean,
});
const emit = defineEmits(['chapter', 'anchor', 'open', 'hide']);
const store = useStoriesStore();
const { playback, sheet } = storeToRefs(store);
const k = computed(() => chapterAt(props.story, playback.value.wallMs));
const chTitle = (c) => chapterTitle(props.story, c);
const events = computed(() => props.story.events ?? []);
// The background in the page's language: one text, or parts (a shipped
// scene's layers) translated one by one.
const background = computed(() =>
[]
.concat(props.story.background || [])
.map((part) => storyText(part))
.join(' '),
);
const stamp = (ms, world) => anchorStamp(props.story, ms, world);
const facts = computed(() =>
nowFacts(props.story, playback.value.worldMs, playback.value.wallMs),
);
const peekFacts = computed(() => facts.value.slice(0, 3));
const sheetSum = computed(
() =>
`${k.value + 1}/${props.story.chapters.length} · ${chTitle(props.story.chapters[k.value])} · ${tn(props.story.sources.length, '{count} source', '{count} sources')}`,
);
const titleOf = (s) => storyText(s.title);
const related = computed(() =>
store.stories.filter((x) => x.id !== props.story.id).slice(0, 3),
);
// A related story's card picture, when there is one (CSS draws a placeholder).
const thumbOf = (s) => store.thumbs?.[s.id] || '';
// ── Search this story: its chapters, key moments and sources ──
const GLYPH = { ch: '#', ev: '•', src: '↗' };
const query = ref('');
const active = ref(-1);
const results = computed(() => {
const q = query.value.trim().toLowerCase();
if (!q) return null;
const hit = (x) => `${x.title} ${x.sub}`.toLowerCase().includes(q);
const chs = props.story.chapters
.map((c, i) => ({
type: 'ch',
k: i,
title: chTitle(c),
sub: `${t('Chapter {n}', { n: i + 1 })} · ${chapterStamp(props.story, c)}`,
}))
.filter(hit);
const evs = events.value
.map((ev, i) => ({
type: 'ev',
k: i,
ev,
title: storyText(ev.label),
sub: `${t('Key moments')} · ${stamp(ev.wallMs, ev.tMs)}`,
}))
.filter(hit);
const srcs = props.story.sources
.map((x) => ({
type: 'src',
href: x[2],
title: storyText(x[0]),
sub: storyText(x[1]),
}))
.filter(hit);
return [...chs, ...evs, ...srcs].slice(0, 9);
});
function onQuery() {
active.value = results.value?.length ? 0 : -1;
}
function choose(x) {
if (!x) return;
query.value = '';
if (x.type === 'ch') emit('chapter', x.k);
else if (x.type === 'ev') emit('anchor', x.ev);
else if (x.type === 'src' && x.href && x.href !== '#')
window.open(x.href, '_blank', 'noopener');
}
function onSearchKey(e) {
const list = results.value ?? [];
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
e.preventDefault();
if (!list.length) return;
active.value =
(active.value + (e.key === 'ArrowDown' ? 1 : -1) + list.length) %
list.length;
} else if (e.key === 'Enter') {
e.preventDefault();
choose(list[active.value]);
} else if (e.key === 'Escape') query.value = '';
}
// ── Phone sheet: follows the finger, snaps to peek / half / full ──
const SNAPS = ['peek', 'half', 'full'];
const el = ref(null);
const dragH = ref(null);
const dragging = ref(false);
let sd = null;
function heights() {
const H = el.value?.closest('.st-body')?.clientHeight || innerHeight;
return { peek: 100, half: H * 0.54, full: H * 0.88, H };
}
function setSheet(s) {
sheet.value = s;
dragH.value = null;
setTimeout(() => store.controller.reframe(), 320);
}
function onHandleDown(e) {
if (innerWidth > 700) return;
try {
e.currentTarget.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
sd = {
y: e.clientY,
h: el.value.offsetHeight,
lastY: e.clientY,
lastT: performance.now(),
v: 0,
moved: false,
};
}
function onHandleMove(e) {
if (!sd) return;
const dy = e.clientY - sd.y;
if (!sd.moved && Math.abs(dy) > 4) {
sd.moved = true;
dragging.value = true;
}
if (!sd.moved) return;
dragH.value = clamp(sd.h - dy, 100, heights().H * 0.92);
const now = performance.now();
sd.v = (e.clientY - sd.lastY) / Math.max(1, now - sd.lastT);
sd.lastY = e.clientY;
sd.lastT = now;
}
let justDragged = false;
function onHandleUp() {
if (!sd) return;
if (sd.moved) {
const hs = heights();
const h = dragH.value ?? hs[sheet.value];
let target;
if (sd.v < -0.5) target = h < hs.half ? 'half' : 'full';
else if (sd.v > 0.5) target = h > hs.half ? 'half' : 'peek';
else
target = SNAPS.reduce((a, b) =>
Math.abs(hs[b] - h) < Math.abs(hs[a] - h) ? b : a,
);
dragging.value = false;
justDragged = true;
setSheet(target);
}
sd = null;
}
function onHandleClick() {
if (justDragged) {
justDragged = false;
return;
}
setSheet(SNAPS[(SNAPS.indexOf(sheet.value) + 1) % 3]);
}
function onHandleKey(e) {
const i = SNAPS.indexOf(sheet.value);
if (e.key === 'ArrowUp') {
e.preventDefault();
setSheet(SNAPS[Math.min(2, i + 1)]);
} else if (e.key === 'ArrowDown') {
e.preventDefault();
setSheet(SNAPS[Math.max(0, i - 1)]);
}
}
defineExpose({ dragging });
</script>
<template>
<aside
id="stCtx"
ref="el"
class="st-ctx"
:class="{ nudge }"
:aria-label="t('Context')"
:style="dragH != null ? { height: `${dragH}px` } : null"
>
<button
id="sheetHandle"
class="sheet-handle"
type="button"
:aria-expanded="sheet !== 'peek'"
:aria-label="
sheet === 'peek'
? t('Context. Swipe up or press to open')
: t('Context. Swipe down or press to close')
"
@pointerdown="onHandleDown"
@pointermove="onHandleMove"
@pointerup="onHandleUp"
@pointercancel="onHandleUp"
@click="onHandleClick"
@keydown="onHandleKey"
>
<span class="pk-top">
<span class="lbl">{{ t('Context') }}</span>
<span id="sheetSum" class="sum">{{ sheetSum }}</span>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 15l6-6 6 6" />
</svg>
</span>
<span id="peekFacts" class="pk-facts" aria-hidden="true">
<span v-for="f in peekFacts" :key="f[1]"
><b :class="{ warn: f[2] }">{{ f[0] }}</b
>{{ t(f[1]) }}</span
>
</span>
</button>
<div class="cx-search-wrap">
<div class="cx-search">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
aria-hidden="true"
>
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
<input
id="cxQ"
v-model="query"
type="search"
:placeholder="t('Search this story')"
autocomplete="off"
spellcheck="false"
:aria-label="t('Search this story')"
role="combobox"
:aria-expanded="!!results"
aria-controls="cxResults"
@input="onQuery"
@keydown="onSearchKey"
/>
<button
class="cx-ic"
type="button"
disabled
:aria-label="t('Voice search (not in this build)')"
:title="t('Voice search (not in this build)')"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.9"
stroke-linecap="round"
>
<rect x="9" y="3" width="6" height="11" rx="3" />
<path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21" />
</svg>
</button>
</div>
<ul
v-if="results"
id="cxResults"
class="cx-results"
role="listbox"
:aria-label="t('Search results')"
>
<li v-for="(x, i) in results" :key="`${x.type}:${x.k ?? x.title}`">
<button
type="button"
role="option"
:aria-selected="i === active"
@click="choose(x)"
>
<span class="ic" aria-hidden="true">{{ GLYPH[x.type] }}</span>
<span
><b>{{ x.title }}</b
><span class="sub">{{ x.sub }}</span></span
>
</button>
</li>
<li v-if="!results.length" class="empty">{{
t('Nothing in this story matches.')
}}</li>
</ul>
</div>
<div id="cxScroll" class="cx-scroll">
<div class="cx-sec cx-chapters">
<div class="cx-h">{{ t('Chapters') }}</div>
<ul class="cx-list">
<li v-for="(c, i) in story.chapters" :key="c.id">
<a href="#" @click.prevent="emit('chapter', i)"
>{{ i + 1 }}. {{ chTitle(c) }}</a
>
<span
>{{ chapterStamp(story, c)
}}{{ i === k ? ` · ${t('now')}` : '' }}</span
>
</li>
</ul>
</div>
<div class="cx-sec">
<div class="cx-h">
{{ t('About') }}
<button
class="tbtn cx-close"
type="button"
style="height: 28px; padding: 0 8px"
@click="emit('hide')"
>{{ t('Close') }}</button
>
</div>
<p class="cx-p">
<b>{{ titleOf(story) }}</b
><br />{{ t('by {creator}', { creator: story.creator }) }} ·
{{ windowText(story) }}
</p>
<p v-if="story.description" class="cx-p">{{
storyText(story.description)
}}</p>
</div>
<div v-if="events.length" class="cx-sec">
<div class="cx-h">{{ t('Key moments') }}</div>
<ul class="cx-anchors">
<li v-for="(ev, i) in events" :key="i">
<button
type="button"
:class="{ past: playback.wallMs >= ev.wallMs }"
@click="emit('anchor', ev)"
>
<span class="tchip">{{ stamp(ev.wallMs, ev.tMs) }}</span>
<span class="al"
><i :style="{ background: ev.color }"></i
>{{ storyText(ev.label) }}</span
>
</button>
</li>
</ul>
</div>
<div v-if="story.sources.length" class="cx-sec">
<div class="cx-h">{{ t('Sources') }}</div>
<ul class="cx-list">
<li v-for="src in story.sources" :key="src[0]">
<a :href="src[2] || '#'" target="_blank" rel="noopener"
>{{ storyText(src[0]) }} ↗</a
>
<span>{{ storyText(src[1]) }}</span>
</li>
</ul>
</div>
<div v-if="background" class="cx-sec">
<div class="cx-h">{{ t('Background') }}</div>
<p class="cx-p">{{ background }}</p>
</div>
<div class="cx-sec">
<div class="cx-h">{{ t('Related stories') }}</div>
<div class="cx-related">
<button
v-for="x in related"
:key="x.id"
type="button"
@click="emit('open', x.id)"
>
<span class="thumb"
><img v-if="thumbOf(x)" :src="thumbOf(x)" alt="" loading="lazy"
/></span>
<span
><b>{{ titleOf(x) }}</b
><span class="c-meta">{{ windowText(x) }}</span></span
>
</button>
</div>
</div>
</div>
</aside>
</template>
+53
View File
@@ -0,0 +1,53 @@
<script setup>
import { computed } from 'vue';
import { t } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
/**
* The right rail over the story map (prototype `.ov-rail`): Open in GEV (it
* opens the scene in GEV's Scenes panel) and Share.
*/
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);
async function share() {
const url = store.controller.shareLink();
try {
await navigator.clipboard.writeText(url);
store.flashHint(t('Story link copied'), 1800);
} catch {
store.flashHint(url, 2600);
}
}
</script>
<template>
<div id="ovRail" class="ov ov-rail">
<!-- The scene opens in GEV's Scenes panel. -->
<button
id="railGev"
class="rail-btn rail-gev"
type="button"
:aria-label="t('Open this moment in GEV')"
@click="store.controller.openInGev()"
>
<span class="ic"
><svg class="eye" viewBox="0 0 775 520" aria-hidden="true">
<use href="#gevLogo" /></svg></span
>{{ t('Open') }}
</button>
<button
v-if="!localOnly"
id="railShare"
class="rail-btn"
type="button"
:aria-label="t('Share this story')"
@click="share"
>
<span class="ic"
><span class="share-icon" aria-hidden="true">&#x1F517;</span></span
>{{ t('Share') }}
</button>
</div>
</template>
+631
View File
@@ -0,0 +1,631 @@
<script setup>
import {
computed,
nextTick,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue';
import { storeToRefs } from 'pinia';
import { formatNumber, t } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
import { chapterAt } from '../../../stories/format.js';
import {
chapterTitle,
clamp,
clockText,
layersFor,
nowFacts,
storyText,
} from '../../../stories/storyMeta.js';
import StoriesHeader from './StoriesHeader.vue';
import StoryTimeline from './StoryTimeline.vue';
import StoryContext from './StoryContext.vue';
import StoryRail from './StoryRail.vue';
/**
* One story (prototype `.scr-story`): a GEV scene playing on GEV's Cesium
* globe, which shows through the map area.
*/
const props = defineProps({ story: { type: Object, required: true } });
const emit = defineEmits(['back']);
const store = useStoriesStore();
const {
playback,
expanded,
ctxOpen,
sheet,
contextWidth,
camera,
hint,
bigPlay,
} = storeToRefs(store);
const titleOf = (s) => storyText(s.title);
const title = computed(() => titleOf(props.story));
const k = computed(() => chapterAt(props.story, playback.value.wallMs));
const chapter = computed(() => props.story.chapters[k.value]);
const chTitle = (c) => chapterTitle(props.story, c);
const clock = computed(() =>
clockText(
props.story,
playback.value.wallMs,
playback.value.worldMs,
k.value,
),
);
const layers = computed(() => layersFor(props.story));
const facts = computed(() =>
nowFacts(props.story, playback.value.worldMs, playback.value.wallMs),
);
const posText = computed(() => {
const { lat, lon, altKm } = camera.value;
return {
pos: `${Math.abs(lat).toFixed(2)}°${lat >= 0 ? 'N' : 'S'} ${Math.abs(lon).toFixed(2)}°${lon >= 0 ? 'E' : 'W'}`,
// ALT and KM are HUD codes, as in GEV's own readout; the number follows
// the page's language.
alt: ` · ALT ${formatNumber(altKm)} KM`,
};
});
const legendStyle = (l) =>
l[0] === 'dash'
? { borderTop: `2px dashed ${l[1]}` }
: l[0] === 'line'
? { borderTopColor: l[1] }
: { background: l[1] };
const legendClass = (l) => (l[0] === 'dot' ? 'dot' : l[0] === 'sq' ? 'sq' : '');
// ── Navigation within the story ──
const timelineRef = ref(null);
function goChapter(i) {
store.controller.seek(props.story.chapters[i].wallMs + 1);
if (playback.value.exploring) store.controller.resume();
}
function goAnchor(ev) {
store.controller.focusEvent(ev);
if (innerWidth <= 700) sheet.value = 'half';
}
function bigPlayClick() {
bigPlay.value = false;
if (playback.value.exploring) store.controller.resume();
else store.controller.play();
}
// ── Story card: Chapter · On the map · Right now ──
const page = ref(0);
const cardMin = ref(false);
const cardDragging = ref(false);
const trackEl = ref(null);
const cardEl = ref(null);
const pgEls = ref([]);
const trackHeight = ref(null);
const dragOffset = ref(null);
function sizeCard() {
const pg = pgEls.value[page.value];
if (pg) trackHeight.value = pg.offsetHeight;
}
function setPage(p) {
page.value = clamp(p, 0, 2);
dragOffset.value = null;
requestAnimationFrame(sizeCard);
}
const trackStyle = computed(() => ({
transform:
dragOffset.value != null
? `translateX(${dragOffset.value}px)`
: `translateX(${-page.value * 100}%)`,
height: trackHeight.value ? `${trackHeight.value}px` : null,
}));
let pd = null;
function onCardDown(e) {
if (e.target.closest('#pgDots, .pg-min, .pg-mini') || cardMin.value) return;
e.stopPropagation();
pd = {
x: e.clientX,
y: e.clientY,
w: cardEl.value.offsetWidth,
t: performance.now(),
moved: false,
};
try {
cardEl.value.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
}
function onCardMove(e) {
if (!pd) return;
const dx = e.clientX - pd.x;
if (
!pd.moved &&
Math.abs(dx) > 6 &&
Math.abs(dx) > Math.abs(e.clientY - pd.y)
) {
pd.moved = true;
cardDragging.value = true;
}
if (!pd.moved) return;
// Rubber band at the ends.
const ends = (page.value === 0 && dx > 0) || (page.value === 2 && dx < 0);
dragOffset.value = -page.value * pd.w + (ends ? dx * 0.3 : dx);
}
function onCardUp(e) {
if (!pd) return;
if (pd.moved) {
const dx = e.clientX - pd.x;
const fast = Math.abs(dx) / Math.max(1, performance.now() - pd.t) > 0.4;
cardDragging.value = false;
setPage(
page.value + (Math.abs(dx) > pd.w * 0.25 || fast ? (dx < 0 ? 1 : -1) : 0),
);
}
pd = null;
}
function onCardKey(e) {
if (e.key === 'ArrowRight') setPage(page.value + 1);
else if (e.key === 'ArrowLeft') setPage(page.value - 1);
}
const minBtn = ref(null);
const miniBtn = ref(null);
function setCardMin(on) {
cardMin.value = on;
if (!on) requestAnimationFrame(sizeCard);
}
// The card shows for a few seconds at each chapter (new info), then folds
// to its pill so the map has room (prototype, on every screen size here).
let cardTimer = 0;
function cardPeek() {
clearTimeout(cardTimer);
setCardMin(false);
cardTimer = setTimeout(() => {
if (!cardHover) setCardMin(true);
}, 5000);
}
// The card stays open while the pointer is on it, then folds a moment later.
let cardHover = false;
function onCardEnter() {
cardHover = true;
clearTimeout(cardTimer);
}
function onCardLeave() {
cardHover = false;
if (!cardMin.value) cardTimer = setTimeout(() => setCardMin(true), 2500);
}
watch(k, () => cardPeek());
let cardObserver = null;
// ── Phone: controls fade in expanded full screen while playing ──
const controlsHidden = ref(false);
let pokeTimer = 0;
function pokeControls() {
controlsHidden.value = false;
clearTimeout(pokeTimer);
if (
expanded.value &&
playback.value.playing &&
!playback.value.exploring &&
innerWidth <= 700
)
pokeTimer = setTimeout(() => (controlsHidden.value = true), 3000);
}
watch([expanded, () => playback.value.playing], pokeControls);
function onSectionMove(e) {
if (e.pointerType !== 'mouse' || controlsHidden.value) pokeControls();
}
// ── Phone: the first play shows that the context can be pulled up ──
const sheetHint = ref(false);
const nudge = ref(false);
let hintTimers = [];
watch(
() => playback.value.playing,
(on) => {
if (!on || store.sheetHintSeen) return;
hintTimers.push(
setTimeout(() => {
if (store.sheetHintSeen || innerWidth > 700 || sheet.value !== 'peek')
return;
store.sheetHintSeen = true;
sheetHint.value = true;
nudge.value = true;
hintTimers.push(setTimeout(() => (nudge.value = false), 2400));
hintTimers.push(setTimeout(() => (sheetHint.value = false), 5200));
}, 1500),
);
},
);
watch(sheet, () => (sheetHint.value = false));
// ── Desktop: drag the context panel's left edge to resize ──
const resizing = ref(false);
const limits = () => [260, Math.max(280, Math.min(640, innerWidth - 420))];
function setCtxW(px) {
const [a, b] = limits();
contextWidth.value = Math.round(clamp(px, a, b));
try {
localStorage.setItem('gevCtxW', contextWidth.value);
} catch {
/* storage off: the width lasts this visit */
}
}
let rd = null;
function onResizeDown(e) {
try {
e.currentTarget.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
rd = {
x: e.clientX,
w: document.getElementById('stCtx')?.offsetWidth ?? 340,
};
resizing.value = true;
e.preventDefault();
}
function onResizeMove(e) {
if (rd) setCtxW(rd.w + (rd.x - e.clientX));
}
function onResizeUp() {
if (!rd) return;
rd = null;
resizing.value = false;
store.controller.reframe();
}
function onResizeReset() {
contextWidth.value = 0;
try {
localStorage.removeItem('gevCtxW');
} catch {
/* storage off */
}
store.controller.reframe();
}
function onResizeKey(e) {
const d = { ArrowLeft: 24, ArrowRight: -24 }[e.key];
if (!d) return;
e.preventDefault();
setCtxW((document.getElementById('stCtx')?.offsetWidth ?? 340) + d);
store.controller.reframe();
}
const sectionStyle = computed(() =>
contextWidth.value && !expanded.value
? { '--ctxw': `${contextWidth.value}px` }
: null,
);
onMounted(() => {
try {
const v = +localStorage.getItem('gevCtxW');
if (v) contextWidth.value = v;
} catch {
/* storage off */
}
if (globalThis.ResizeObserver && cardEl.value) {
cardObserver = new ResizeObserver(sizeCard);
cardObserver.observe(cardEl.value);
}
nextTick(sizeCard);
cardPeek();
});
onBeforeUnmount(() => {
clearTimeout(cardTimer);
clearTimeout(pokeTimer);
hintTimers.forEach(clearTimeout);
cardObserver?.disconnect();
});
watch(
() => props.story.id,
() => {
page.value = 0;
cardMin.value = false;
nextTick(sizeCard);
},
);
watch([k, page], () => nextTick(sizeCard));
</script>
<template>
<section
id="scrStory"
class="scr scr-story"
:class="{
exploring: playback.exploring,
expanded,
'ctx-open': ctxOpen,
'ctx-sized': !!contextWidth,
'controls-hidden': controlsHidden,
'sheet-hinting': sheetHint,
'ctx-resizing': resizing,
}"
:aria-label="t('GEV Story')"
:data-sheet="sheet"
data-chapters="timeline"
:style="sectionStyle"
@pointerdown="pokeControls"
@pointermove="onSectionMove"
@keydown="pokeControls"
>
<StoriesHeader
screen="story"
:title="title"
@back="emit('back')"
@crumb="emit('back')"
@home="store.controller.close()"
/>
<div class="st-body">
<aside class="st-chapters" :aria-label="t('Chapters')">
<div class="ch-credit">
<span class="label"
><span class="chip">{{
story.live ? t('LIVE') : story.draft ? t('DRAFT') : t('STORY')
}}</span></span
>
<div class="t">{{ title }}</div>
<div class="c-meta">{{
t('by {creator}', { creator: story.creator })
}}</div>
</div>
<ol class="ch-list">
<li v-for="(c, i) in story.chapters" :key="c.id">
<button
class="ch-item"
:class="{ done: i < k }"
type="button"
:aria-current="i === k ? 'step' : undefined"
@click="goChapter(i)"
>
<span class="n">{{ i + 1 }}</span
><span
><b>{{ chTitle(c) }}</b></span
>
</button>
</li>
</ol>
</aside>
<div class="st-main">
<div id="stMap" class="st-map">
<div class="map-slot"></div>
<div
id="ovChapter"
ref="cardEl"
class="ov ov-chapter glass"
:class="{ min: cardMin, dragging: cardDragging }"
role="region"
aria-roledescription="carousel"
:aria-label="t('Story card')"
tabindex="0"
@pointerdown="onCardDown"
@pointermove="onCardMove"
@pointerup="onCardUp"
@pointercancel="onCardUp"
@keydown="onCardKey"
@focusin="!cardMin && cardPeek()"
@mouseenter="onCardEnter"
@mouseleave="onCardLeave"
>
<div
id="pgTrack"
ref="trackEl"
class="pg-track"
:style="trackStyle"
>
<section
:ref="(el) => (pgEls[0] = el)"
class="pg"
aria-roledescription="slide"
:aria-label="t('Chapter')"
:aria-hidden="page !== 0"
aria-live="polite"
>
<div class="k">{{
t('CHAPTER {n} / {total}', {
n: k + 1,
total: story.chapters.length,
})
}}</div>
<div class="t">{{ chTitle(chapter) }}</div>
<div v-if="chapter.caption" class="c">{{
storyText(chapter.caption)
}}</div>
</section>
<section
:ref="(el) => (pgEls[1] = el)"
class="pg"
aria-roledescription="slide"
:aria-label="t('On the map')"
:aria-hidden="page !== 1"
>
<div class="k">{{ t('ON THE MAP') }}</div>
<div class="pg-legend">
<span v-for="l in layers" :key="l[2]"
><i :class="legendClass(l)" :style="legendStyle(l)"></i
>{{ storyText(l[2]) }}</span
>
</div>
</section>
<section
:ref="(el) => (pgEls[2] = el)"
class="pg"
aria-roledescription="slide"
:aria-label="t('Right now')"
:aria-hidden="page !== 2"
>
<div class="k">{{ t('RIGHT NOW') }} · {{ clock.big }}</div>
<div class="pg-facts">
<div v-for="f in facts" :key="f[1]"
><b :class="{ warn: f[2] }">{{ f[0] }}</b
><span>{{ t(f[1]) }}</span></div
>
</div>
</section>
</div>
<button
id="pgMin"
ref="minBtn"
class="pg-min"
type="button"
:aria-label="t('Minimise card')"
:aria-expanded="!cardMin"
@click.stop="
setCardMin(true);
nextTick(() => miniBtn?.focus());
"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 15l6-6 6 6" />
</svg>
</button>
<button
id="pgMini"
ref="miniBtn"
class="pg-mini"
type="button"
:aria-label="t('Expand card')"
@click.stop="
setCardMin(false);
cardPeek();
nextTick(() => minBtn?.focus());
"
>
<b>{{ k + 1 }}/{{ story.chapters.length }}</b
><span>{{ chTitle(chapter) }}</span>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M6 9l6 6 6-6" />
</svg>
</button>
<div
id="pgDots"
class="pg-dots"
role="group"
:aria-label="t('Card pages')"
>
<button
v-for="(lbl, i) in [
t('Chapter'),
t('On the map'),
t('Right now'),
]"
:key="i"
type="button"
:aria-label="lbl"
:aria-current="String(i === page)"
@click="setPage(i)"
></button>
</div>
</div>
<div id="ovClock" class="ov ov-clock">
<b>{{ clock.big }}</b
><span>{{ t(clock.small) }}</span>
<span class="pos"
>{{ posText.pos }}<i>{{ posText.alt }}</i></span
>
</div>
<div id="ovLegend" class="ov ov-legend">
<span v-for="l in layers" :key="l[2]" class="glass"
><i :class="legendClass(l)" :style="legendStyle(l)"></i
>{{ storyText(l[2]) }}</span
>
</div>
<div
v-if="bigPlay && !playback.playing"
id="ovPlay"
class="ov ov-play"
>
<button
id="btnBigPlay"
type="button"
:aria-label="t('Play story')"
@click="bigPlayClick"
>
<svg viewBox="0 0 24 24" fill="currentColor">
<path
d="M8 5.7v12.6c0 .9 1 1.4 1.7.9l9.7-6.3a1.1 1.1 0 0 0 0-1.8L9.7 4.8C9 4.3 8 4.8 8 5.7Z"
/>
</svg>
</button>
</div>
<button
id="btnCtx"
class="ov ov-ctxbtn tbtn"
type="button"
:aria-pressed="ctxOpen"
@click="ctxOpen = !ctxOpen"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
>
<rect x="4" y="4" width="16" height="16" rx="3" />
<path d="M14 4v16" />
</svg>
<span>{{ t('Context') }}</span>
</button>
<div v-if="hint" id="ovHint" class="ov ov-hint glass">{{ hint }}</div>
<StoryRail />
</div>
<StoryTimeline ref="timelineRef" :story="story" @anchor="goAnchor" />
</div>
<div
id="ctxResize"
class="ctx-resize"
role="separator"
aria-orientation="vertical"
:aria-label="t('Resize context panel')"
:aria-valuenow="contextWidth || undefined"
tabindex="0"
@pointerdown="onResizeDown"
@pointermove="onResizeMove"
@pointerup="onResizeUp"
@pointercancel="onResizeUp"
@dblclick="onResizeReset"
@keydown="onResizeKey"
></div>
<StoryContext
:story="story"
:nudge="nudge"
@chapter="goChapter"
@anchor="goAnchor"
@open="(id) => store.controller.openStory(id, { autoplay: true })"
@hide="ctxOpen = false"
/>
<div
v-if="sheetHint"
id="sheetHint"
class="sheet-hint"
aria-hidden="true"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.4"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 19V5M6 11l6-6 6 6" />
</svg>
{{ t('Swipe up for context') }}
</div>
</div>
</section>
</template>
+560
View File
@@ -0,0 +1,560 @@
<script setup>
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { t } from '../../../i18n/index.js';
import { useStoriesStore } from '../../stores/stories.js';
import { chapterAt } from '../../../stories/format.js';
import {
chapterTitle,
clamp,
clockText,
fmtDur,
storyText,
} from '../../../stories/storyMeta.js';
/**
* The story timeline (prototype `.timeline`): chapter segments with
* magnetic ticks, key-moment pips, a scrub bubble, sound and expand.
* Positions are wall milliseconds on the GEV scene's own clock.
*/
const props = defineProps({ story: { type: Object, required: true } });
const emit = defineEmits(['anchor']);
const store = useStoriesStore();
const { playback, muted, expanded } = storeToRefs(store);
const dur = computed(
() => playback.value.durationMs || props.story.durationMs || 1,
);
const tNow = computed(() => playback.value.wallMs);
const pct = computed(() => clamp((tNow.value / dur.value) * 100, 0, 100));
const k = computed(() => chapterAt(props.story, tNow.value));
const chapters = computed(() => props.story.chapters);
const chTitle = (c) => chapterTitle(props.story, c);
const events = computed(() => props.story.events ?? []);
const seek = (ms) => store.controller.seek(clamp(ms, 0, dur.value - 10));
// ── Play button: pause while playing, resume while exploring, otherwise play ──
const ICON = {
pause:
'<rect x="6.5" y="5" width="4" height="14" rx="1.4"/><rect x="13.5" y="5" width="4" height="14" rx="1.4"/>',
play: '<path d="M8 5.7v12.6c0 .9 1 1.4 1.7.9l9.7-6.3a1.1 1.1 0 0 0 0-1.8L9.7 4.8C9 4.3 8 4.8 8 5.7Z"/>',
resume:
'<path d="M4.5 12a7.5 7.5 0 1 0 2.2-5.3" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/><path d="M3.5 3.8v4.6h4.6" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>',
};
const playMode = computed(() =>
playback.value.exploring && !playback.value.playing
? 'resume'
: playback.value.playing
? 'pause'
: 'play',
);
function togglePlay() {
if (playMode.value === 'resume') store.controller.resume();
else if (playback.value.playing) store.controller.pause();
else store.controller.play();
}
// ── Segments ──
const segs = computed(() =>
chapters.value.map((c, i) => {
const a = (c.wallMs / dur.value) * 100;
const next =
i + 1 < chapters.value.length ? chapters.value[i + 1].wallMs : dur.value;
const b = (next / dur.value) * 100;
const fill =
clamp((tNow.value - c.wallMs) / (next - c.wallMs || 1), 0, 1) * 100;
return {
i,
style: {
left: `calc(${a}% + ${i ? 2 : 0}px)`,
width: `calc(${b - a}% - ${i ? 2 : 0}px - ${i + 1 < chapters.value.length ? 2 : 0}px)`,
},
fill: `${fill}%`,
};
}),
);
// ── Readout ──
const clock = computed(() =>
clockText(props.story, tNow.value, playback.value.worldMs, k.value),
);
const stampAt = (ms) => fmtDur(ms);
const headTime = computed(() => `${fmtDur(tNow.value)} / ${fmtDur(dur.value)}`);
const atEdge = computed(
() => props.story.live && tNow.value >= dur.value - 600,
);
// ── Scrubbing: magnetic chapter ticks, momentum, haptic ticks ──
const track = ref(null);
const scrubbing = ref(false);
const snap = ref(-1);
const hovered = ref(-1);
const ghost = ref(0);
const bubbleAt = ref(null);
let sc = null;
let coastRaf = 0;
let pipSnap = -1;
const reduceMotion = () =>
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
const haptic = () => {
try {
navigator.vibrate?.(3);
} catch {
/* no haptics here */
}
};
function trackAt(clientX) {
const r = track.value.getBoundingClientRect();
let u = clamp((clientX - r.left) / r.width, 0, 1);
let snapped = -1;
chapters.value.forEach((c, i) => {
if (i && Math.abs(u - c.wallMs / dur.value) * r.width < 9) {
u = c.wallMs / dur.value;
snapped = i;
}
});
return { t: u * dur.value, snapped };
}
function scrubTo(target) {
const w = track.value.getBoundingClientRect().width || 1;
let tt = clamp(target, 0, dur.value - 10);
let snapped = -1;
chapters.value.forEach((c, i) => {
if (i && (Math.abs(tt - c.wallMs) / dur.value) * w < 6) {
tt = c.wallMs;
snapped = i;
}
});
let pip = -1;
if (snapped < 0)
events.value.forEach((ev, i) => {
if ((Math.abs(tt - ev.wallMs) / dur.value) * w < 5) {
tt = ev.wallMs;
pip = i;
}
});
if (pip >= 0 && pip !== pipSnap) haptic();
pipSnap = pip;
if (pip >= 0) snapped = -2 - pip;
const ch = chapterAt(props.story, tt);
if (sc && ch !== sc.ch) {
haptic();
sc.ch = ch;
}
seek(tt);
snap.value = snapped;
bubbleAt.value = tt;
return snapped >= 0 || snapped <= -2 ? Math.max(0, snapped) : -1;
}
function onDown(e) {
if (e.target.closest('.tl-pip')) return;
try {
track.value.setPointerCapture(e.pointerId);
} catch {
/* nothing to capture */
}
cancelAnimationFrame(coastRaf);
scrubbing.value = true;
const r = trackAt(e.clientX);
sc = {
lastX: e.clientX,
lastT: performance.now(),
v: 0,
ch: chapterAt(props.story, r.t),
at: r.t,
};
seek(r.t);
snap.value = r.snapped;
bubbleAt.value = r.t;
}
function onMove(e) {
if (!scrubbing.value) {
if (e.target.closest('.tl-pip')) return;
const r = trackAt(e.clientX);
ghost.value = (r.t / dur.value) * 100;
hovered.value = chapterAt(props.story, r.t);
snap.value = r.snapped;
if (r.snapped < 0) {
const w = track.value.clientWidth || 1;
const i = events.value.findIndex(
(ev) => (Math.abs(ev.wallMs - r.t) / dur.value) * w < 5,
);
if (i >= 0) snap.value = -2 - i;
}
bubbleAt.value = r.t;
return;
}
// Slow drags are fine, fast drags coarse.
const now = performance.now();
const dx = e.clientX - sc.lastX;
const dtm = Math.max(1, now - sc.lastT);
const w = track.value.getBoundingClientRect().width || 1;
const gain = clamp(0.25 + (Math.abs(dx) / dtm) * 1.1, 0.25, 2.5);
const before = sc.at;
sc.at = clamp(sc.at + (dx / w) * dur.value * gain, 0, dur.value - 10);
scrubTo(sc.at);
sc.v = (sc.at - before) / dtm;
sc.lastX = e.clientX;
sc.lastT = now;
}
function onUp() {
scrubbing.value = false;
snap.value = -1;
pipSnap = -1;
if (
!sc ||
reduceMotion() ||
Math.abs(sc.v) < 2 ||
performance.now() - sc.lastT > 120
) {
sc = null;
return;
}
// A release coasts with momentum, stopping on a chapter tick.
let v = sc.v * 16;
let at = sc.at;
const coast = () => {
at += v;
const hit = scrubTo(at);
v *= 0.92;
if (hit >= 0 || Math.abs(v) < 20 || at <= 0 || at >= dur.value - 20) {
snap.value = -1;
sc = null;
return;
}
coastRaf = requestAnimationFrame(coast);
};
coastRaf = requestAnimationFrame(coast);
}
function onLeave() {
if (scrubbing.value) return;
ghost.value = 0;
hovered.value = -1;
snap.value = -1;
bubbleAt.value = null;
}
// The bubble follows the knob while playing and the pointer while hovering.
const bubbleT = computed(() => bubbleAt.value ?? tNow.value);
const bubbleK = computed(() => chapterAt(props.story, bubbleT.value));
const bubbleClock = computed(() =>
clockText(
props.story,
bubbleT.value,
bubbleAt.value == null ? playback.value.worldMs : null,
bubbleK.value,
),
);
const bubbleEm = computed(() => {
if (snap.value >= 0) return { text: t('Chapter start'), color: null };
if (snap.value <= -2) {
const ev = events.value[-2 - snap.value];
return ev ? { text: storyText(ev.label), color: ev.color } : null;
}
return null;
});
const bubbleEl = ref(null);
const bubbleStyle = computed(() => {
const w = track.value?.clientWidth || 1;
const half = (bubbleEl.value?.offsetWidth || 120) / 2;
const x = (bubbleT.value / dur.value) * w;
const bx = clamp(x, half, Math.max(half, w - half));
return {
left: `${bx}px`,
'--caret': `${clamp(x - bx + half, 8, half * 2 - 8)}px`,
};
});
// The bubble's picture: the story's card picture, when it has one.
const prevSrc = computed(() => store.thumbs?.[props.story.id] || '');
const prevCanvas = ref(null);
function drawPreview() {
const cv = prevCanvas.value;
const src = prevSrc.value;
if (!cv || !src) return;
const img = new Image();
img.onload = () =>
cv.getContext('2d')?.drawImage(img, 0, 0, cv.width, cv.height);
img.src = src;
}
watch(prevSrc, drawPreview, { flush: 'post' });
onMounted(drawPreview);
// ── Key moments ──
const tip = ref(null);
function tipFor(i) {
const ev = events.value[i];
if (!ev) return;
const w = track.value?.clientWidth || 1;
tip.value = {
ev,
left: clamp((ev.wallMs / dur.value) * w, 90, Math.max(90, w - 90)),
};
}
function pipClick(i) {
haptic();
emit('anchor', events.value[i]);
setTimeout(() => (tip.value = null), 900);
}
// ── Keyboard on the track ──
function goChapter(i) {
seek(chapters.value[i].wallMs + 1);
if (playback.value.exploring) store.controller.resume();
}
// Previous goes to the start of this chapter first, like a video player.
function stepChapter(d) {
const kk = k.value;
const list = chapters.value;
if (d > 0 && kk === list.length - 1) {
seek(dur.value);
return;
}
const to =
d > 0
? Math.min(list.length - 1, kk + 1)
: tNow.value - list[kk].wallMs > 1500
? kk
: Math.max(0, kk - 1);
goChapter(to);
}
function onKey(e) {
if (e.target !== track.value) return;
// A key the timeline handles is the timeline's alone.
const handled = () => {
e.preventDefault();
e.stopPropagation();
};
let tt = tNow.value;
if (e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
stepChapter(e.key === 'ArrowRight' ? 1 : -1);
handled();
return;
}
if (e.key === 'PageUp') tt += dur.value / 10;
else if (e.key === 'PageDown') tt -= dur.value / 10;
else if (/^[0-9]$/.test(e.key)) tt = dur.value * (+e.key / 10);
else if (e.key === 'ArrowRight' || e.key === 'ArrowUp') tt += 2000;
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') tt -= 2000;
else if (e.key === 'Home') tt = 0;
else if (e.key === 'End') tt = dur.value;
else if (e.key === ']') {
goChapter(Math.min(chapters.value.length - 1, k.value + 1));
handled();
return;
} else if (e.key === '[') {
goChapter(Math.max(0, k.value - 1));
handled();
return;
} else if (e.key === ' ' || e.key === 'Enter') {
togglePlay();
handled();
return;
} else return;
handled();
seek(tt);
}
// ── Sound, expand ──
const VOL = {
off: '<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z" fill="currentColor" stroke="none"/><path d="M16 9.5l5 5M21 9.5l-5 5"/>',
on: '<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z" fill="currentColor" stroke="none"/><path d="M15.5 9a4.5 4.5 0 0 1 0 6M18 6.5a8 8 0 0 1 0 11"/>',
};
function toggleExpand() {
store.expanded = !store.expanded;
store.ctxOpen = false;
setTimeout(() => store.controller.reframe(), 320);
}
function jumpLive() {
seek(dur.value);
if (playback.value.exploring) store.controller.resume();
}
onBeforeUnmount(() => cancelAnimationFrame(coastRaf));
defineExpose({ goChapter });
</script>
<template>
<div id="timeline" class="timeline" :data-kind="story.live ? 'live' : ''">
<button
id="tlPlay"
class="tl-play"
:class="{ resume: playMode === 'resume' }"
type="button"
:aria-label="
playMode === 'resume'
? t('Resume story')
: playMode === 'pause'
? t('Pause')
: t('Play')
"
@click="togglePlay"
>
<svg
id="tlIcon"
viewBox="0 0 24 24"
fill="currentColor"
v-html="ICON[playMode]"
></svg>
</button>
<div
id="tlTrack"
ref="track"
class="tl-track"
:class="{ dragging: scrubbing, 'on-pip': !!tip }"
role="slider"
tabindex="0"
:aria-label="t('Story time')"
aria-valuemin="0"
aria-valuemax="100"
:aria-valuenow="Math.round(pct)"
:aria-valuetext="`${clock.big}, ${t('chapter')} ${k + 1}: ${chTitle(chapters[k])}`"
@pointerdown="onDown"
@pointermove="onMove"
@pointerup="onUp"
@pointercancel="onUp"
@pointerleave="onLeave"
@keydown="onKey"
>
<div class="tl-rail">
<div id="tlFill" class="tl-fill" :style="{ width: `${pct}%` }"></div>
</div>
<div id="tlTicks">
<span
v-for="s in segs"
:key="s.i"
class="tl-seg"
:class="{ now: s.i === k, hov: s.i === hovered, snap: s.i === snap }"
:data-k="s.i"
:style="s.style"
><i :style="{ width: s.fill }"></i
></span>
</div>
<div
id="tlGhost"
class="tl-ghost"
:style="{ width: `${ghost}%` }"
aria-hidden="true"
></div>
<div id="tlHead" class="tl-head" aria-hidden="true">
<span id="tlHeadCh"
><b>{{ k + 1 }}</b
>/{{ chapters.length }} · {{ chTitle(chapters[k]) }}</span
>
<span id="tlHeadTime">{{ headTime }}</span>
</div>
<div id="tlPips" role="group" :aria-label="t('Key moments')">
<button
v-for="(ev, i) in events"
:key="i"
type="button"
class="tl-pip"
:class="{ snap: snap === -2 - i }"
:data-e="i"
:aria-label="t('Key moment: {label}', { label: storyText(ev.label) })"
:style="{ left: `${(ev.wallMs / dur) * 100}%`, color: ev.color }"
@pointerdown.stop
@pointerover="tipFor(i)"
@pointerout="tip = null"
@focus="tipFor(i)"
@blur="tip = null"
@click.stop="pipClick(i)"
@keydown.space.stop
@keydown.enter.stop
>
<i :style="{ background: ev.color }"></i>
</button>
</div>
<div
v-if="tip"
id="tlTip"
class="tl-tip"
role="tooltip"
:style="{ left: `${tip.left}px` }"
>
<i :style="{ background: tip.ev.color }"></i
><b>{{ storyText(tip.ev.label) }}</b
><span>{{ stampAt(tip.ev.wallMs) }}</span>
</div>
<div class="tl-knob" :style="{ left: `${pct}%` }"></div>
<div
id="tlBubble"
ref="bubbleEl"
class="tl-bubble"
:data-snap="snap >= 0 ? 'ch' : snap <= -2 ? 'pip' : ''"
:style="bubbleStyle"
>
<canvas
v-if="prevSrc"
id="tlPrev"
ref="prevCanvas"
width="320"
height="180"
aria-hidden="true"
></canvas>
<div id="tlBubbleTxt">
<b>{{ bubbleK + 1 }} · {{ chTitle(chapters[bubbleK]) }}</b>
<span class="tt">{{ bubbleClock.big }}</span>
<em
v-if="bubbleEm"
:style="bubbleEm.color ? { color: bubbleEm.color } : null"
>{{ bubbleEm.text }}</em
>
</div>
</div>
</div>
<span id="tlTime" class="tl-time" aria-hidden="true">
<b v-if="story.live">{{ clock.big }}</b>
<span v-else class="tt-c">{{ headTime }}</span>
</span>
<button
v-if="story.live"
id="tlLive"
class="tl-live"
:class="{ edge: atEdge }"
type="button"
:aria-label="t('Jump to live')"
@click="jumpLive"
>
<i></i>{{ t('LIVE') }}
</button>
<button
id="tlVol"
class="tl-vol"
type="button"
:aria-label="muted ? t('Unmute') : t('Mute')"
:aria-pressed="!muted"
@click="muted = !muted"
>
<svg
id="tlVolIcon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.9"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
v-html="muted ? VOL.off : VOL.on"
></svg>
</button>
<button
id="stExpand"
class="tl-vol"
type="button"
:aria-label="expanded ? t('Exit expanded map') : t('Expand map')"
:aria-pressed="expanded"
@click="toggleExpand"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.9"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5" />
</svg>
</button>
</div>
</template>
+2
View File
@@ -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();