Merge branch 'main' into samehkhamis/start-layers

This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-19 15:12:01 -08:00
commit 54b6ba827e
62 files changed
+5709 -372

No files matched your search

+15
View File
@@ -65,6 +65,7 @@ import { useContextStore } from './stores/context.js';
import { useSpaceMissionsStore } from './stores/spaceMissions.js';
import { SpaceMissionsControls } from './spaceMissionsControls.js';
import { useMissionReplayStore } from './stores/missionReplay.js';
import { useStreetLevelPhotoStore } from './stores/streetLevelPhoto.js';
import { useCelestialRingStore } from './stores/celestialRing.js';
import { icrfToFixedAxes } from '../sky/icrf.js';
import { useWorldOverlayActionsStore } from './stores/worldOverlayActions.js';
@@ -1204,7 +1205,18 @@ export class StyleManager extends ShellFacade {
const { streetLevelLayer } = this.services;
this._streetLevelControls?.destroy();
this._streetLevelControls = null;
// The photo viewer (KartaView, Panoramax), which the layer panels draw
// into the viewer host. A viewer left by an earlier shell must
// not outlive its layer.
const streetLevelPhotoStore = useStreetLevelPhotoStore(applicationPinia());
this._streetLevelPhotoUnsubscribe?.();
this._streetLevelPhotoUnsubscribe = null;
streetLevelPhotoStore.publish(null);
if (!this._streetLevelPanel || !streetLevelLayer) return;
this._streetLevelPhotoUnsubscribe =
streetLevelLayer.subscribePhotoViewer?.((view) =>
streetLevelPhotoStore.publish(view),
) ?? null;
// Photo framing yields to newer navigation and releases tracking like
// any deferred flight.
streetLevelLayer.attachNavigation?.({
@@ -1973,7 +1985,10 @@ export class StyleManager extends ShellFacade {
this._spaceMissionsControls = null;
this._missionReplayUnsubscribe?.();
this._missionReplayUnsubscribe = null;
this._streetLevelPhotoUnsubscribe?.();
this._streetLevelPhotoUnsubscribe = null;
useMissionReplayStore(applicationPinia()).publish(null);
useStreetLevelPhotoStore(applicationPinia()).publish(null);
const contextStore = useContextStore(applicationPinia());
contextStore.connectAwareness(null);
contextStore.publishAwareness(null);
@@ -0,0 +1,116 @@
// The Street Level photo viewer (KartaView, Panoramax) is a view with kit
// controls: StreetLevelPhotoViewer draws what the photo viewer presents and
// hand-writes no <button> and no Material Symbols span; its ‹ › are ghost
// UiButtons, not pressed toggles, whose glyphs are text characters. The
// photo viewer builds no element of its own, and the street-level layer it
// belongs to needs no Vue: the application shell publishes its
// presentation to the store the view renders.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
const read = (file) =>
readFileSync(new URL(`../../${file}`, import.meta.url), 'utf8');
/** The template block: everything outside script, style and comments. */
const template = (file) =>
read(file)
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
// An opening tag's attributes, quoted values may hold `>` (`() => x`).
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tags = (markup, name) =>
markup.match(new RegExp(String.raw`<${name}\b${ATTRS}>`, 'g')) ?? [];
// An attribute's name, outside the quoted values.
const names = (attrs) => attrs.replace(/"[^"]*"|'[^']*'/g, '""');
const VIEW = 'ui/views/panels/StreetLevelPhotoViewer.vue';
const VIEWER = 'layers/streetLevel/photoViewer.js';
test('the photo viewer hand-writes no button; ‹ and › are kit buttons', () => {
const markup = template(VIEW);
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], VIEW);
assert.deepEqual(markup.match(/<(select|input)\b/gi) ?? [], [], VIEW);
const buttons = tags(markup, 'UiButton');
assert.equal(buttons.length, 2);
assert.equal(tags(markup, 'UiCloseButton').length, 0);
// Ghost buttons with the classes street-level.css styles.
for (const [button, side] of [
[buttons[0], 'prev'],
[buttons[1], 'next'],
]) {
assert.doesNotMatch(button, /\svariant=/);
assert.match(
button,
new RegExp(`\\sclass="sl-photo-step sl-photo-step-${side}"`),
);
}
});
test('the photo viewer hand-writes no Material glyph', () => {
const markup = template(VIEW);
assert.deepEqual(markup.match(/material-symbols/g) ?? [], [], VIEW);
assert.equal(tags(markup, 'UiIcon').length, 0);
// ‹ and › are text characters.
assert.match(markup, />‹<\/UiButton\s*>/);
assert.match(markup, />›<\/UiButton\s*>/);
});
test('the step buttons are not pressed toggles', () => {
const markup = template(VIEW);
for (const [tag, attrs] of markup.matchAll(
new RegExp(String.raw`<[A-Za-z][\w-]*\b(${ATTRS})>`, 'g'),
)) {
assert.doesNotMatch(
names(attrs),
/(?:^|\s)(?::|v-bind:)?aria-pressed(?=[\s=/]|$)/,
tag,
);
assert.doesNotMatch(
attrs,
/(?:^|\s)(?:v-bind|:)=(?:"[^"]*aria-?pressed[^"]*"|'[^']*aria-?pressed[^']*')/i,
tag,
);
assert.doesNotMatch(names(attrs), /(?:^|\s)(?::|v-bind:)?pressed\b/, tag);
}
});
test('the photo viewer is drawn by its view, and its layer needs no Vue', () => {
const source = read(VIEWER);
// No element made, inserted, moved, removed or written: the view does
// all of that. (An Image the loader downloads with is not on the page.)
for (const write of [
/createElement/,
/\b(?:inner|outer)HTML\b/,
/insertAdjacent(?:HTML|Element|Text)/,
/\.(?:append|prepend|appendChild|insertBefore|replaceWith|replaceChildren|before|after)\(/,
/\.remove\(\)/,
/\.(?:set|remove|toggle)Attribute(?:NS)?\(/,
/\.(?:classList|className|dataset|style)\b/,
/\.(?:hidden|disabled|textContent|innerText|tabIndex|title|alt)\s*=[^=]/,
/from 'vue'|\.vue'/,
])
assert.doesNotMatch(source, write);
const markup = template(VIEW);
const opening = (name, attribute) =>
new RegExp(String.raw`<${name}\b${ATTRS}\s${attribute}${ATTRS}>`);
for (const part of [
opening('div', 'class="sl-photo-viewer"'),
opening('img', 'class="sl-photo-flat"'),
opening('canvas', ':key="photo.canvasKey"'),
opening('canvas', 'class="sl-photo-pano"'),
])
assert.match(markup, part);
const groups = JSON.parse(
readFileSync(
new URL('../../../scripts/package-boundaries.json', import.meta.url),
'utf8',
),
);
const layer = groups['street-level-layer'];
assert.ok(layer.modules.includes(`src/${VIEWER}`));
assert.equal(layer.external.includes('vue'), false);
assert.equal(
layer.modules.some((module) => module.endsWith('.vue')),
false,
);
});
+26
View File
@@ -0,0 +1,26 @@
import { defineStore } from 'pinia';
import { markRaw, shallowRef } from 'vue';
/**
* The Street Level photo viewer (KartaView, Panoramax) as its view renders
* it. The street-level layer presents it through `subscribePhotoViewer()`
* and the application shell publishes each presentation here.
*/
export const useStreetLevelPhotoStore = defineStore(
'gev-street-level-photo',
() => {
/**
* `{host, providerId, label, alt, kind, src, fit, canvasKey, dragging,
* prevLabel, prevDisabled, nextLabel, nextDisabled, actions}`, or null
* while no photo viewer is mounted.
*/
const photo = shallowRef(null);
/** @param {?object} next A fresh presentation; every publish re-renders. */
function publish(next) {
photo.value = next && markRaw(next);
}
return { photo, publish };
},
);
+2
View File
@@ -12,6 +12,7 @@ import SceneOptions from './SceneOptions.vue';
import SceneShotList from './SceneShotList.vue';
import CctvPanel from './panels/CctvPanel.vue';
import StreetLevelPanel from './panels/StreetLevelPanel.vue';
import StreetLevelPhotoViewer from './panels/StreetLevelPhotoViewer.vue';
import DrawControls from './panels/DrawControls.vue';
import GeoImport from './panels/GeoImport.vue';
import UiSelect from '../kit/UiSelect.js';
@@ -71,6 +72,7 @@ async function importChosen(event) {
<!-- Street Level Panel (moved into #right-context-rail at runtime) -->
<StreetLevelPanel />
<StreetLevelPhotoViewer />
<!-- Scene Director Panel -->
<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>
@@ -0,0 +1,304 @@
// The Street Level photo viewer (KartaView, Panoramax) on a page: the photo
// viewer presents it, the store carries it, and StreetLevelPhotoViewer draws
// it into the viewer host, forwards its events and hands its elements back.
import '../../../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createApp, nextTick } from 'vue';
import { createPinia } from 'pinia';
import { createPhotoViewer } from '../../../layers/streetLevel/photoViewer.js';
import { subscribePhotoViewers } from '../../../layers/streetLevel/photoViewers.js';
import { useStreetLevelPhotoStore } from '../../stores/streetLevelPhoto.js';
import StreetLevelPhotoViewer from './StreetLevelPhotoViewer.vue';
const PHOTOS = {
f: { id: 'f', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: false },
g: { id: 'g', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: false },
p: { id: 'p', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: true },
};
const SOURCES = {
hasPano: (photo) => photo.isPano,
panoFirst: (photo) => ({ url: `${photo.id}-pano`, width: 2048 }),
panoSharp: () => null,
flatFirst: (photo) => [`https://photos.test/${photo.id}.jpg`],
flatSharp: () => null,
describe: () => ({ externalUrl: 'https://example.org' }),
};
/**
* The view in an app, a viewer per provider published to its store as the
* street-level layer does, and a panel host.
*/
function mount(t, options = {}, providerIds = ['panoramax']) {
document.body.replaceChildren();
const wrap = document.body.appendChild(document.createElement('div'));
wrap.className = 'sl-viewer-wrap';
const host = wrap.appendChild(document.createElement('div'));
host.id = 'sl-viewer';
const pinia = createPinia();
const app = createApp(StreetLevelPhotoViewer).use(pinia);
app.mount(document.body.appendChild(document.createElement('div')));
const store = useStreetLevelPhotoStore(pinia);
const renderers = [];
const stepped = [];
const create = (providerId) =>
createPhotoViewer({
providerId,
name: providerId === 'panoramax' ? 'Panoramax' : 'KartaView',
sources: SOURCES,
getPhoto: async (id) => PHOTOS[id],
// f, then g: the whole sequence.
step: async (photo, delta) =>
({ f: { 1: 'g' }, g: { '-1': 'f' } })[photo.id]?.[delta] ?? null,
onStep: (id) => stepped.push(id),
load: async (url) => ({ src: url }),
createRenderer: (canvas) => {
const view = { yaw: 0, pitch: 0, fov: 80 };
const renderer = {
canvas,
setImage() {},
setView: (next) => Object.assign(view, next),
getView: () => ({ ...view }),
resize() {},
clear() {},
destroy() {},
};
renderers.push(renderer);
return renderer;
},
...options,
});
const viewers = providerIds.map(create);
const unsubscribe = subscribePhotoViewers(viewers, (view) =>
store.publish(view),
);
t.after(() => {
for (const viewer of viewers) viewer.unmount();
unsubscribe();
app.unmount();
});
return { viewer: viewers[0], viewers, host, wrap, renderers, stepped };
}
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
test('the viewer draws in its host with the markup its stylesheet reads', async (t) => {
const { viewer, host } = mount(t);
await viewer.mount(host);
const root = host.querySelector(':scope > .sl-photo-viewer');
assert.ok(root, 'drawn in the host');
assert.equal(root.dataset.provider, 'panoramax');
assert.equal(root.getAttribute('tabindex'), '0');
assert.equal(root.getAttribute('role'), 'group');
assert.match(root.getAttribute('aria-label'), /^Panoramax photo\. ← and →/);
assert.equal(root.hasAttribute('data-kind'), false, 'nothing shown yet');
const [picture, canvas, prev, next] = root.children;
assert.equal(picture.tagName, 'IMG');
assert.equal(picture.className, 'sl-photo-flat');
assert.equal(picture.getAttribute('alt'), 'Panoramax street-level photo');
assert.equal(picture.getAttribute('draggable'), 'false');
assert.equal(picture.hidden, true);
assert.equal(picture.hasAttribute('src'), false);
assert.equal(picture.style.objectFit, 'contain');
assert.equal(canvas.tagName, 'CANVAS');
assert.equal(canvas.className, 'sl-photo-pano');
assert.equal(canvas.hidden, true);
for (const [button, side, glyph, label] of [
[prev, 'prev', '‹', 'Previous photo in this sequence (←)'],
[next, 'next', '›', 'Next photo in this sequence (→)'],
]) {
assert.equal(button.tagName, 'BUTTON');
assert.equal(button.type, 'button');
assert.ok(button.classList.contains('sl-photo-step'));
assert.ok(button.classList.contains(`sl-photo-step-${side}`));
assert.equal(button.textContent.trim(), glyph);
assert.equal(button.getAttribute('aria-label'), label);
assert.equal(button.getAttribute('title'), label);
assert.equal(button.disabled, true);
assert.equal(button.hasAttribute('aria-pressed'), false);
}
viewer.setRenderMode('fill');
await nextTick();
assert.equal(picture.style.objectFit, 'cover');
viewer.unmount();
await nextTick();
assert.equal(host.children.length, 0, 'unmounted: gone from the host');
});
test('a flat photo shows, ‹ › and ← → step along its sequence, and close hides it', async (t) => {
const { viewer, host, stepped } = mount(t);
await viewer.mount(host);
await viewer.open('f');
await nextTick();
const root = host.querySelector('.sl-photo-viewer');
const [picture, canvas, prev, next] = root.children;
assert.equal(root.dataset.kind, 'flat');
assert.equal(picture.hidden, false);
assert.equal(canvas.hidden, true);
assert.equal(picture.getAttribute('src'), 'https://photos.test/f.jpg');
// ‹ is disabled once its end is known; › stays.
await tick();
await nextTick();
assert.equal(prev.disabled, true);
assert.equal(next.disabled, false);
let bubbled = 0;
host.addEventListener('click', () => bubbled++);
next.click();
await tick();
assert.deepEqual(stepped, ['g']);
assert.equal(bubbled, 0, 'the click stays in the viewer');
await viewer.open('g');
root.dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }),
);
await tick();
assert.deepEqual(stepped, ['g', 'f']);
viewer.close();
await nextTick();
assert.equal(root.dataset.kind, '');
assert.equal(picture.hidden, true);
assert.equal(picture.hasAttribute('src'), false);
});
test('a step button that disables under the keyboard hands focus to the viewer', async (t) => {
// The sequence's end is known only once the user is on ›.
let answer;
const asked = new Promise((resolve) => (answer = resolve));
const { viewer, host } = mount(t, {
step: async (photo, delta) => (delta > 0 ? asked : null),
});
await viewer.mount(host);
await viewer.open('g');
await nextTick();
const root = host.querySelector('.sl-photo-viewer');
const next = root.children[3];
assert.equal(next.disabled, false);
next.focus();
assert.ok(document.activeElement === next, 'on ›');
answer(null);
await tick();
await nextTick();
assert.equal(next.disabled, true, 'g is the last photo');
assert.ok(document.activeElement === root, 'focus moved to the viewer');
});
test('a panorama draws on the view’s canvas; drag, wheel and a lost context reach the viewer', async (t) => {
const { viewer, host, renderers } = mount(t);
await viewer.mount(host);
await viewer.open('p');
await nextTick();
const root = host.querySelector('.sl-photo-viewer');
const canvas = root.children[1];
assert.ok(renderers[0].canvas === canvas, 'the canvas the view drew');
assert.equal(root.dataset.kind, 'pano');
assert.equal(canvas.hidden, false);
assert.equal(root.children[0].hidden, true);
canvas.dispatchEvent(
new PointerEvent('pointerdown', {
pointerId: 1,
pointerType: 'mouse',
button: 0,
clientX: 0,
clientY: 0,
}),
);
await nextTick();
assert.ok(canvas.classList.contains('sl-photo-dragging'));
canvas.dispatchEvent(new PointerEvent('pointerup', { pointerId: 1 }));
await nextTick();
assert.equal(canvas.classList.contains('sl-photo-dragging'), false);
const wheel = new WheelEvent('wheel', { deltaY: 100, cancelable: true });
canvas.dispatchEvent(wheel);
assert.equal(wheel.defaultPrevented, true, 'the page does not scroll');
assert.ok(renderers[0].getView().fov > 80, 'zoomed out');
// A lost context: a fresh canvas in its place, which the next renderer takes.
canvas.dispatchEvent(new Event('webglcontextlost', { cancelable: true }));
await nextTick();
const fresh = root.children[1];
assert.ok(fresh !== canvas, 'a new canvas');
assert.equal(fresh.className, 'sl-photo-pano');
assert.equal(canvas.isConnected, false, 'the lost one is gone');
await viewer.open('p');
assert.ok(renderers[1].canvas === fresh, 'the next renderer takes it');
});
test('docked, Esc in the viewer’s box is offered to the provider first', async (t) => {
let asked = 0;
const { viewer, host } = mount(t, { onEscape: () => ++asked > 0 });
await viewer.mount(host);
const root = host.querySelector('.sl-photo-viewer');
const escape = new KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true,
});
let reachedPage = false;
document.body.addEventListener('keydown', () => (reachedPage = true));
root.dispatchEvent(escape);
assert.equal(asked, 1);
assert.equal(escape.defaultPrevented, true);
assert.equal(reachedPage, false, 'the panel does not collapse');
});
test('without a view, the viewer cannot mount', async () => {
const viewer = createPhotoViewer({
providerId: 'test',
name: 'Test',
sources: SOURCES,
getPhoto: async (id) => PHOTOS[id],
step: async () => null,
onStep() {},
});
await assert.rejects(
viewer.mount(document.createElement('div')),
/no view to draw it/,
);
});
test('a viewer mounted in the tick another unmounts gets elements of its own', async (t) => {
const { viewers, host, renderers } = mount(t, {}, ['kartaview', 'panoramax']);
const [kartaView, panoramax] = viewers;
await kartaView.mount(host);
await kartaView.open('p');
const root = host.querySelector('.sl-photo-viewer');
const canvas = root.children[1];
assert.ok(renderers[0].canvas === canvas);
// The core switches source: one unmounts and the other mounts at once.
kartaView.unmount();
const mounting = panoramax.mount(host);
await mounting;
await panoramax.open('p');
const fresh = host.querySelector('.sl-photo-viewer');
assert.equal(host.children.length, 1);
assert.ok(fresh !== root, 'a root of its own');
assert.equal(fresh.dataset.provider, 'panoramax');
assert.ok(fresh.children[1] !== canvas, 'not the destroyed renderer’s canvas');
assert.ok(renderers[1].canvas === fresh.children[1]);
assert.equal(fresh.dataset.kind, 'pano', 'not the front view');
});
test('a mount overtaken before it is drawn closes, and never shows later', async (t) => {
const { viewers, host } = mount(t, {}, ['kartaview', 'panoramax']);
const [kartaView, panoramax] = viewers;
// KartaView starts mounting; Panoramax mounts before the view draws it.
const overtaken = kartaView.mount(host);
const current = panoramax.mount(host);
// It settles, rather than wait for a draw that never comes.
const outcome = await Promise.race([
overtaken.then(
() => 'mounted',
(error) => error.message,
),
new Promise((resolve) => setTimeout(() => resolve('still pending'), 100)),
]);
assert.match(outcome, /viewer was closed/);
await current;
await nextTick();
assert.equal(host.children.length, 1);
assert.equal(host.children[0].dataset.provider, 'panoramax');
await assert.rejects(kartaView.open('f'), /not mounted/);
// Once Panoramax goes, nothing is left in the host.
panoramax.unmount();
await nextTick();
assert.equal(host.children.length, 0);
});
@@ -0,0 +1,80 @@
<script setup>
import { storeToRefs } from 'pinia';
import UiButton from '../../kit/UiButton.vue';
import { useStreetLevelPhotoStore } from '../../stores/streetLevelPhoto.js';
// The Street Level photo viewer of the providers whose photos are plain
// files (KartaView, Panoramax), in the viewer host the layer mounts it in.
// The viewer (src/layers/streetLevel/photoViewer.js) keeps every decision:
// which photo shows and how, its loading, the panorama it draws, the keys,
// drag and zoom. This view draws what it presents, forwards the events and
// hands each element back: the canvas it draws on, the frame and picture
// it measures, the root and buttons it keeps focus with. Each mount and each
// canvas has its own key, so a viewer never gets another one's elements.
const { photo } = storeToRefs(useStreetLevelPhotoStore());
/** Hand `name`'s element back to the viewer that presented it. */
const keep = (name) => (element) => {
if (element) photo.value?.actions.attach(name, element.$el ?? element);
};
// One function per element: a new one on each render would hand it back
// again each time.
const refs = {
root: keep('root'),
picture: keep('picture'),
canvas: keep('canvas'),
prev: keep('prev'),
next: keep('next'),
};
</script>
<template>
<Teleport v-if="photo" :to="photo.host"
><div
:key="photo.mountKey"
:ref="refs.root"
class="sl-photo-viewer"
:data-provider="photo.providerId"
tabindex="0"
role="group"
:aria-label="photo.label"
:data-kind="photo.kind"
@keydown="photo.actions.keydown"
><img
:ref="refs.picture"
class="sl-photo-flat"
:alt="photo.alt"
draggable="false"
:hidden="photo.kind !== 'flat'"
:src="photo.src ?? undefined"
:style="{ objectFit: photo.fit }" /><canvas
:key="photo.canvasKey"
:ref="refs.canvas"
class="sl-photo-pano"
:class="{ 'sl-photo-dragging': photo.dragging }"
:hidden="photo.kind !== 'pano'"
@pointerdown="photo.actions.pointerdown"
@pointermove="photo.actions.pointermove"
@pointerup="photo.actions.pointerup"
@pointercancel="photo.actions.pointerup"
@wheel="photo.actions.wheel"
@webglcontextlost="photo.actions.contextLost"
></canvas
><UiButton
:ref="refs.prev"
class="sl-photo-step sl-photo-step-prev"
:label="photo.prevLabel"
:disabled="photo.prevDisabled"
@click="photo.actions.step(-1, $event)"
>‹</UiButton
><UiButton
:ref="refs.next"
class="sl-photo-step sl-photo-step-next"
:label="photo.nextLabel"
:disabled="photo.nextDisabled"
@click="photo.actions.step(1, $event)"
>›</UiButton
></div
></Teleport
>
</template>