mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
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]>
107 lines
3.9 KiB
JavaScript
107 lines
3.9 KiB
JavaScript
// 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);
|
||
assert.doesNotMatch(
|
||
source,
|
||
/createElement|innerHTML|insertAdjacentHTML|\.append\(|\.classList|\.dataset|from 'vue'|\.vue'/,
|
||
);
|
||
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,
|
||
);
|
||
});
|