mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Vue kit: Street Level's photo viewer is a view with kit buttons
The photo viewer KartaView and Panoramax share (photoViewer.js) no longer builds its root, picture, panorama canvas and ‹ › buttons in script. It presents them through subscribeView(), which the street-level layer gathers in subscribePhotoViewer(); the application shell publishes that to the gev-street-level-photo store, and StreetLevelPhotoViewer, beside the Street Level panel in the layer panels, teleports the viewer into the viewer host with the same classes, data attributes, labels and order. Its ‹ and › are ghost UiButtons. The view forwards keys, pointers, wheel, the step clicks and a lost WebGL context to the viewer and hands each element back: the canvas the panorama is drawn on (a fresh, keyed one after a lost context, which an open now waits for), and the frame, picture, root and buttons the viewer measures and keeps focus with. The viewer keeps every decision: loading, upgrades, size limits, keys, drag, pinch, zoom, Esc on the viewer's box and focus when a step button disables. The street-level layer still needs no Vue; with no view subscribed these photos cannot mount, which docs/VUE-MIGRATION.md records. The provider and viewer tests draw the viewer with a fake view in kartaViewFakes.mjs; StreetLevelPhotoViewer.test.mjs runs the real view on a page, and streetLevelPhotoControls.test.mjs pins the kit controls. The panel page's lost-graphics notice in globePanelRuntime.js stays built in script, as the document now says. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
9423a26487
commit
766364f691
20 files changed
+911
-112
No files matched your search
@@ -60,13 +60,112 @@ function fakeElement(tag) {
|
||||
return element;
|
||||
}
|
||||
|
||||
export function fakeHost() {
|
||||
const doc = { createElement: (tag) => fakeElement(tag) };
|
||||
/**
|
||||
* A host element; given a photo viewer, its view is drawn as
|
||||
* StreetLevelPhotoViewer draws it (see `drawPhotoViewer`).
|
||||
*/
|
||||
export function fakeHost(viewer = null) {
|
||||
const host = fakeElement('div');
|
||||
host.ownerDocument = doc;
|
||||
if (viewer) drawPhotoViewer(viewer);
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a photo viewer's presentations with fake elements, as
|
||||
* StreetLevelPhotoViewer does: the root in the host it names, holding the
|
||||
* picture, the panorama canvas and the ‹ › buttons, each handed back; a
|
||||
* value is written only when the presentation changes it (as Vue patches),
|
||||
* and the elements' events reach the viewer's actions. A new canvas key
|
||||
* puts a fresh canvas in the old one's place.
|
||||
* @returns {() => void} Stop drawing.
|
||||
*/
|
||||
export function drawPhotoViewer(viewer) {
|
||||
let parts = null;
|
||||
let last = null;
|
||||
const on = (element, type, name) =>
|
||||
element.addEventListener(type, (event) => last?.actions[name](event));
|
||||
const canvasFor = () => {
|
||||
const canvas = fakeElement('canvas');
|
||||
canvas.classList.add('sl-photo-pano');
|
||||
for (const type of ['pointerdown', 'pointermove', 'pointerup', 'wheel'])
|
||||
on(canvas, type, type);
|
||||
on(canvas, 'pointercancel', 'pointerup');
|
||||
on(canvas, 'webglcontextlost', 'contextLost');
|
||||
return canvas;
|
||||
};
|
||||
const build = (view) => {
|
||||
const root = fakeElement('div');
|
||||
const picture = fakeElement('img');
|
||||
const canvas = canvasFor();
|
||||
const button = (delta) => {
|
||||
const element = fakeElement('button');
|
||||
element.addEventListener('click', (event) =>
|
||||
last?.actions.step(delta, event),
|
||||
);
|
||||
return element;
|
||||
};
|
||||
const prev = button(-1);
|
||||
const next = button(1);
|
||||
on(root, 'keydown', 'keydown');
|
||||
root.append(picture, canvas, prev, next);
|
||||
view.host.append(root);
|
||||
return { root, picture, canvas, prev, next };
|
||||
};
|
||||
const changed = (view, key) => !last || last[key] !== view[key];
|
||||
return viewer.subscribeView((view) => {
|
||||
if (!view) {
|
||||
parts?.root.remove();
|
||||
parts = last = null;
|
||||
return;
|
||||
}
|
||||
const fresh = !parts || last.host !== view.host;
|
||||
if (fresh) {
|
||||
parts?.root.remove();
|
||||
parts = build(view);
|
||||
last = null;
|
||||
}
|
||||
const { root, picture, prev, next } = parts;
|
||||
if (!fresh && changed(view, 'canvasKey')) {
|
||||
const canvas = canvasFor();
|
||||
parts.canvas.replaceWith(canvas);
|
||||
parts.canvas = canvas;
|
||||
parts.canvasFresh = true;
|
||||
}
|
||||
const { canvas } = parts;
|
||||
if (changed(view, 'providerId')) root.dataset.provider = view.providerId;
|
||||
if (changed(view, 'label')) root.attributes['aria-label'] = view.label;
|
||||
if (changed(view, 'kind') && view.kind !== undefined)
|
||||
root.dataset.kind = view.kind;
|
||||
if (changed(view, 'alt')) picture.alt = view.alt;
|
||||
if (changed(view, 'src')) {
|
||||
if (view.src) picture.src = view.src;
|
||||
else picture.removeAttribute('src');
|
||||
}
|
||||
if (changed(view, 'fit')) picture.style.objectFit = view.fit;
|
||||
if (changed(view, 'kind') || parts.canvasFresh) {
|
||||
picture.hidden = view.kind !== 'flat';
|
||||
canvas.hidden = view.kind !== 'pano';
|
||||
}
|
||||
if (changed(view, 'dragging') || parts.canvasFresh) {
|
||||
if (view.dragging) canvas.classList.add('sl-photo-dragging');
|
||||
else canvas.classList.remove('sl-photo-dragging');
|
||||
}
|
||||
if (changed(view, 'prevLabel'))
|
||||
prev.attributes['aria-label'] = view.prevLabel;
|
||||
if (changed(view, 'nextLabel'))
|
||||
next.attributes['aria-label'] = view.nextLabel;
|
||||
if (changed(view, 'prevDisabled')) prev.disabled = view.prevDisabled;
|
||||
if (changed(view, 'nextDisabled')) next.disabled = view.nextDisabled;
|
||||
const handBack = fresh || parts.canvasFresh;
|
||||
parts.canvasFresh = false;
|
||||
last = view;
|
||||
if (fresh)
|
||||
for (const name of ['root', 'picture', 'canvas', 'prev', 'next'])
|
||||
view.actions.attach(name, parts[name]);
|
||||
else if (handBack) view.actions.attach('canvas', canvas);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait, a macrotask at a time, until `condition` holds; false if it never
|
||||
* does within `ticks`. A test asserting that something did not happen waits
|
||||
|
||||
Reference in new issue
Block a user