Merge main into denis/iss-live-telemetry

Conflicts: the locale catalogs and package boundaries are three-way merges
(no message changed differently on both sides); zh-Hant is regenerated
from zh-CN. bhoteKoshiEmbeddedMedia.js keeps main's card counter and the
branch's shared YouTube loader (youtubeApi.js), so the media file builds
one script element fewer. The Cockpit briefing's LIVE tab and the orbital
NADIR/RESET button are main's UiButton.
This commit is contained in:
Denis Groshev committed 2026-11-20 10:50:16 +01:00
commit edbf3a234d
244 files changed
+11747 -1273

No files matched your search

+119
View File
@@ -0,0 +1,119 @@
// The Bhote Koshi event's controls are the kit's: its reconstruction panel
// hand-writes no <button> and no Material Symbols span, its buttons are ghost
// UiButtons that keep their data-action hooks for bhote-koshi.css and the
// tests, and its cinematic button is a pressed toggle whose state the event
// layer presents as `pressed`, not as an `aria-pressed` it writes. The
// embedded media cards are an SFC rather than markup built in script; they
// hold no control (the original link stays a link), and the script builds
// only what the provider SDKs need: their script and preconnect tags, the
// overlay root, and the Facebook player node it warms and carries into a
// card.
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 PANEL = 'ui/views/panels/BhoteKoshiPanel.vue';
const CARDS = 'ui/bhoteKoshi/BhoteKoshiMediaCards.vue';
// Per file: its UiButtons, UiCloseButtons, UiSliders and UiIcons.
const SURFACES = {
// Previous and next beat, Play, Play scene, Cinematic, Full story, Open
// original, Lower gorge, a field report (one tag, one per report) and Open
// public map; Close; the split and progress sliders.
[PANEL]: [10, 1, 2, 0],
// The media cards: a frame, a leader, a footer and the original link.
[CARDS]: [0, 0, 0, 0],
};
test('the Bhote Koshi views hand-write no button; each is a kit button', () => {
for (const [file, [buttons, closes, sliders]] of Object.entries(SURFACES)) {
const markup = template(file);
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
assert.deepEqual(markup.match(/<(select|input)\b/gi) ?? [], [], file);
assert.equal(tags(markup, 'UiButton').length, buttons, file);
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
assert.equal(tags(markup, 'UiSlider').length, sliders, file);
}
});
test('the Bhote Koshi views hand-write no Material glyph', () => {
for (const [file, [, , , icons]] of Object.entries(SURFACES)) {
const markup = template(file);
assert.deepEqual(markup.match(/material-symbols/g) ?? [], [], file);
const found = tags(markup, 'UiIcon');
assert.equal(found.length, icons, file);
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
}
});
test('the cinematic button takes the kit pressed state', () => {
for (const file of Object.keys(SURFACES))
for (const [tag, attrs] of template(file).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,
);
}
const pressed = tags(template(PANEL), 'UiButton').filter((tag) =>
/\s:pressed=/.test(tag),
);
assert.equal(pressed.length, 1);
assert.match(
pressed[0],
/^<UiButton data-action="cinematic" :pressed="Boolean\(panel\.refs\.cinematicButton\.pressed\)"/,
);
// bhote-koshi.css styles the pressed button by its aria-pressed.
assert.doesNotMatch(pressed[0], /pressed-class/);
// The layer presents the state; it writes no aria-pressed of its own.
const layer = read('data/bhoteKoshiEvent.js');
assert.doesNotMatch(layer, /aria-pressed/);
assert.match(
layer,
/setElementProperty\(button, 'pressed', _cinematicActive\)/,
);
});
test('the media cards are drawn by their view, not built in script', () => {
const source = read('data/bhoteKoshiEmbeddedMedia.js');
assert.doesNotMatch(source, /innerHTML|insertAdjacentHTML|createElementNS/);
// Provider scripts and preconnects, the overlay root, and the Facebook
// embed node and its warm host. The YouTube API's script is youtubeApi.js's.
assert.deepEqual(
[...source.matchAll(/createElement\('(\w+)'\)/g)].map((m) => m[1]),
['script', 'script', 'link', 'div', 'div', 'div'],
);
assert.match(source, /renderVue\(\s*h\(BhoteKoshiMediaCards,/);
const cards = template(CARDS);
const opening = (name, attribute) =>
new RegExp(String.raw`<${name}\b${ATTRS}\s${attribute}${ATTRS}>`);
for (const part of [
opening('iframe', 'class="bhote-embedded-media-warmup"'),
opening('section', 'class="bhote-embedded-callout"'),
opening('svg', 'class="bhote-embedded-callout-leader"'),
opening('div', 'class="bhote-embedded-callout-body" data-overlay-input'),
opening('small', 'role="status"'),
opening('a', 'target="_blank" rel="noopener noreferrer"'),
])
assert.match(cards, part);
});
+150
View File
@@ -0,0 +1,150 @@
// The AI chat panel's and the voice control's buttons and Material glyphs
// are the kit's: neither their templates nor the voice card and panel
// layout buttons they render hand-write a <button> or a Material Symbols
// span. Their other glyphs (the chat bubble, the globe, attach, send and
// stop, expand and the two Back chevrons) are inline SVG drawn with their own
// strokes, which no Material symbol the page loads draws the same, so they
// stay SVG. The voice panel's Preview and Settings are tabs (`role="tab"`
// with `aria-selected`), not pressed toggles, and DISMISS is a text button,
// not a cross, so it is a UiButton rather than a UiCloseButton. The chat's
// message box, file picker and the minutes field stay native: the kit has
// no text area, file or number field. The voice modules build no controls
// in script.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, readdirSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
/** A view's template block: everything outside script, style and comments. */
function template(file) {
const source = readFileSync(
new URL(`../views/panels/${file}`, import.meta.url),
'utf8',
);
return source
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
}
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const tags = (markup, name) =>
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
const views = {
// Settings, the quick prompts, an attachment's remove, Attach layer,
// Attach a file, Expand conversation, the command suggestions, Expand
// chat, Add attachment and Send / Stop reply.
'ChatPanel.vue': {
UiButton: 10,
UiCloseButton: 1,
UiIcon: 1,
UiSelect: 1,
svgs: 5,
},
// The tier button (dock and panel), the mic, Open AI chat, Back to chat,
// Back to voice, the Preview and Settings tabs and DISMISS.
'VoiceControl.vue': {
UiButton: 9,
UiCloseButton: 1,
UiIcon: 2,
UiSelect: 3,
UiCheckbox: 2,
svgs: 3,
},
'VoiceCard.vue': { UiButton: 0, UiCloseButton: 1, UiIcon: 0, svgs: 0 },
// Dock and minimize.
'PanelLayoutButtons.vue': { UiButton: 2, UiIcon: 0, svgs: 2 },
'VoiceVisualizer.vue': { UiButton: 0, UiIcon: 0, svgs: 1 },
};
const markup = Object.fromEntries(
Object.keys(views).map((file) => [file, template(file)]),
);
test('the chat and voice views hand-write no button; each is the kit', () => {
for (const [file, counts] of Object.entries(views)) {
assert.deepEqual(markup[file].match(/<button\b/gi) ?? [], [], file);
for (const name of ['UiButton', 'UiCloseButton', 'UiSelect', 'UiCheckbox'])
assert.equal(tags(markup[file], name).length, counts[name] ?? 0, file);
}
});
test('the pressed toggles take the kit pressed state', () => {
for (const [file, view] of Object.entries(markup))
assert.doesNotMatch(view, /aria-pressed/, file);
const voice = tags(markup['VoiceControl.vue'], 'UiButton');
const tiers = voice.filter((button) => /id="gev-voice-tier"/.test(button));
assert.equal(tiers.length, 2);
for (const tier of tiers)
assert.match(tier, /\s:pressed="Boolean\(view\.tier\.pressed\)"/);
// The mic writes no aria-pressed while its owner has no state for it.
assert.match(
markup['VoiceControl.vue'],
tag(
String.raw`<UiButton\s+id="gev-voice-button"ATTRS\s:pressed="view\.button\.pressed \?\? undefined"`,
),
);
assert.match(
markup['PanelLayoutButtons.vue'],
tag(
String.raw`<UiButton\s+data-layout-dockATTRS\s:pressed="props\.docked"`,
),
);
// The panel tabs are tabs: selected, never pressed.
const tabs = voice.filter((button) => /role="tab"/.test(button));
assert.equal(tabs.length, 2);
for (const button of tabs) {
assert.match(button, /\s:aria-selected="/);
assert.doesNotMatch(button, /\s:pressed=/);
}
});
test('the views hand-write no Material glyph; each is a UiIcon the site sizes', () => {
for (const [file, { UiIcon, svgs }] of Object.entries(views)) {
assert.deepEqual(markup[file].match(/material-symbols/g) ?? [], [], file);
const icons = tags(markup[file], 'UiIcon');
assert.equal(icons.length, UiIcon, file);
// Without it the kit writes an 18px size that beats voice-cost.css and
// voice-card.css.
for (const icon of icons) assert.match(icon, /\s:size="null"/, file);
assert.equal(markup[file].match(/<svg\b/g)?.length ?? 0, svgs, file);
}
assert.match(
markup['ChatPanel.vue'],
/<UiIcon name="settings" class="gev-voice-settings-icon" :size="null" \/>/,
);
assert.equal(
markup['VoiceControl.vue'].match(
/<UiIcon name="(?:visibility|settings)" class="gev-voice-panel-tab-icon" :size="null" \/>/g,
)?.length,
2,
);
});
test('the only native fields left are the message box, file picker and minutes', () => {
const inputs = Object.values(markup).flatMap((view) => tags(view, 'input'));
assert.equal(inputs.length, 2);
assert.match(inputs[0], /id="gev-chat-file" type="file"/);
assert.match(inputs[1], /id="gev-voice-timeout-input" type="number"/);
assert.equal(tags(markup['ChatPanel.vue'], 'textarea').length, 1);
for (const view of Object.values(markup)) {
assert.deepEqual(view.match(/<select\b/gi) ?? [], []);
assert.doesNotMatch(view, /type="(?:checkbox|range)"/);
}
});
test('the voice modules build no buttons or Material glyphs in script', () => {
const root = fileURLToPath(new URL('../../voice/', import.meta.url));
const modules = readdirSync(root, { recursive: true })
.filter((file) => file.endsWith('.js') && !/test|Harness/.test(file))
.map((file) => path.join(root, file));
assert.ok(modules.length > 50);
for (const file of modules) {
const source = readFileSync(file, 'utf8');
assert.doesNotMatch(source, /createElement\(\s*['"]button/, file);
assert.doesNotMatch(source, /<button\b|material-symbols/, file);
}
});
+9 -3
View File
@@ -1,6 +1,7 @@
// Every close, dismiss and clear button in a Vue view is a UiCloseButton: no
// SFC template hand-writes a button whose only content is × or the Material
// `close` symbol. Buttons built in script are not read here.
// SFC template hand-writes a button whose only content is × (bare or in a
// span) or the Material `close` symbol. Buttons built in script are not read
// here.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, readdirSync } from 'node:fs';
@@ -30,8 +31,10 @@ function template(source) {
// An opening tag's attributes, quoted values may hold `>` (`() => x`).
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const BUTTON = String.raw`(button|UiButton)`;
const TIMES = String.raw`×|&times;|&#215;|&#xd7;`;
const CLOSE_GLYPH = [
String.raw`×|&times;|&#215;|&#xd7;`,
TIMES,
String.raw`<span\b${ATTRS}>\s*(?:${TIMES})\s*</span\s*>`,
String.raw`<span\b[^>]*\bmaterial-symbols-outlined\b[^>]*>\s*close\s*</span\s*>`,
String.raw`<UiIcon${ATTRS}\bname="close"${ATTRS}/>`,
].join('|');
@@ -54,11 +57,14 @@ test('the scan finds each hand-written close glyph', () => {
'<template><UiButton class="x" :label="l">&times;</UiButton></template>',
'<template><button type="button" class="x">\n <span class="material-symbols-outlined" aria-hidden="true">close</span>\n</button></template>',
'<template><UiButton class="x"><UiIcon name="close" :size="14" /></UiButton></template>',
'<template><button type="button" :aria-label="l"><span aria-hidden="true">×</span></button></template>',
'<template><UiButton class="x">\n <span class="glyph">&times;</span>\n</UiButton></template>',
])
assert.equal(handWrittenCloses(markup).length, 1, markup);
for (const markup of [
'<template><UiCloseButton class="x" :label="l" /></template>',
'<template><button type="button">{{ name }} ×</button></template>',
'<template><button type="button"><span>{{ name }}</span> ×</button></template>',
'<template><button type="button">On<span class="material-symbols-outlined">close</span></button></template>',
'<template><button type="button"><span class="material-symbols-outlined">close_fullscreen</span></button></template>',
])
+148
View File
@@ -0,0 +1,148 @@
// The Cockpit HUD's controls and glyphs are the kit's: no Cockpit view
// hand-writes a <button>, a Material Symbols span, a select, a checkbox or a
// range. Its buttons are ghost UiButtons that keep their ids, classes and
// labels for the Cockpit controller's listeners and the cockpit stylesheets;
// its glyphs are UiIcons with `:size="null"`, so those stylesheets still size
// them. The utility strip's −, ◀ ▶ and transport glyphs and the orbital
// zoom's − and + are text characters, not Material symbols, and stay text.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readdirSync, readFileSync } from 'node:fs';
/** A view's template block: everything outside script, style and comments. */
function template(file) {
const source = readFileSync(
new URL(`../views/${file}`, import.meta.url),
'utf8',
);
return source
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
}
const views = {
// The vision selector's Previous, Current and Next, Look ahead, and the
// view switcher's Reset and Exit; the speed and altitude rims' pointers,
// the two vision chevrons, the reticle, the heading caret and the view
// switcher's two glyphs.
'CockpitView.vue': { buttons: 6, icons: 8 },
// Display's and Radio's collapse and launcher buttons, Radio's Enable,
// Previous, Play and Next, and the desktop rail's two items and glyphs.
'panels/CockpitUtilityControls.vue': { buttons: 10, icons: 2 },
// Previous, Next, Auto, the card's collapse and the four page tabs (LIVE
// shows only with a stream); the first, second and fourth draw a glyph.
'panels/CockpitBriefing.vue': { buttons: 8, icons: 3 },
// Previous, Next, the card's collapse and Weather; three of them draw a
// glyph, and the nearest contact's arrow is the fourth.
'panels/CockpitContext.vue': { buttons: 4, icons: 4 },
// A signal row's target and its chevron.
'panels/CockpitSignalList.vue': { buttons: 1, icons: 1 },
// TLE, Nadir, Zoom out, Zoom in and Sensor.
'panels/CockpitOrbital.vue': { buttons: 5, icons: 0 },
// The range step.
'panels/CockpitRadar.vue': { buttons: 1, icons: 0 },
// The flight plan's arrow.
'panels/CockpitRoute.vue': { buttons: 0, icons: 1 },
// Readouts only.
'panels/CockpitProgress.vue': { buttons: 0, icons: 0 },
'panels/CockpitRollingValue.vue': { buttons: 0, icons: 0 },
};
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const markup = Object.fromEntries(
Object.keys(views).map((file) => [file, template(file)]),
);
test('every Cockpit view is in the list above', () => {
const dir = (sub) =>
readdirSync(new URL(`../views/${sub}`, import.meta.url))
.filter((name) => /^Cockpit.*\.vue$/.test(name))
.map((name) => sub + name);
assert.deepEqual(
[...dir(''), ...dir('panels/')].sort(),
Object.keys(views).sort(),
);
});
test('the Cockpit views hand-write no button; each is a UiButton', () => {
for (const [file, { buttons }] of Object.entries(views)) {
assert.deepEqual(markup[file].match(/<button\b/gi) ?? [], [], file);
assert.equal(
markup[file].match(/<UiButton\b/g)?.length ?? 0,
buttons,
file,
);
}
});
test('the Cockpit views hand-write no select, checkbox or range', () => {
for (const [file, view] of Object.entries(markup)) {
assert.deepEqual(view.match(/<(select|input)\b/gi) ?? [], [], file);
}
// The compact Radio volume.
assert.equal(
markup['panels/CockpitUtilityControls.vue'].match(/<UiSlider\b/g)?.length,
1,
);
});
test('the pressed toggles take the kit pressed state', () => {
for (const view of Object.values(markup))
assert.doesNotMatch(view, tag(String.raw`<\w+\bATTRS\s:?aria-pressed`));
const pressed = Object.values(markup).flatMap(
(view) =>
view.match(tag(String.raw`<UiButton\bATTRS\s:pressed=ATTRS>`, 'g')) ?? [],
);
// Radio's Enable, the briefing's Auto and the Contact card's Weather.
assert.equal(pressed.length, 3);
for (const button of pressed) assert.match(button, /:pressed="Boolean\(/);
assert.match(
markup['panels/CockpitUtilityControls.vue'],
tag(
String.raw`<UiButton\s+id="cockpit-radio-enable-btn"ATTRS\s:pressed="Boolean\(cockpit\?\.enable\.active\)" pressed-class="active"`,
),
);
assert.match(
markup['panels/CockpitBriefing.vue'],
tag(
String.raw`<UiButton\s+id="cockpit-brief-auto"ATTRS\s:pressed="Boolean\(b\.autoRotate\)"`,
),
);
assert.match(
markup['panels/CockpitContext.vue'],
tag(
String.raw`<UiButton\s+id="cockpit-weather-toggle"ATTRS\s:pressed="Boolean\(c\.weather\)"`,
),
);
});
test('the Cockpit views hand-write no Material glyph; each is a UiIcon', () => {
for (const [file, { icons }] of Object.entries(views)) {
assert.deepEqual(
markup[file].match(/material-symbols-outlined/g) ?? [],
[],
file,
);
const found =
markup[file].match(tag(String.raw`<UiIcon\bATTRS>`, 'g')) ?? [];
assert.equal(found.length, icons, file);
// Without it the kit writes an 18px size that beats the cockpit's rules.
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
}
});
test('the heading caret outranks the kit icon rule that loads after it', () => {
const css = readFileSync(
new URL('../styles/cockpit.css', import.meta.url),
'utf8',
);
// kit.css's `.ui-icon` sets display and line-height with one class and
// loads after cockpit.css, so a one-class caret rule would lose to it.
assert.match(
css,
/\n\.cockpit-compass \.cockpit-heading-caret \{\n {2}display: block;/,
);
assert.doesNotMatch(css, /\n\.cockpit-heading-caret \{/);
});
+127
View File
@@ -0,0 +1,127 @@
// The command dock's and the Context panel's buttons and Material glyphs are
// the kit's: neither the dock, the Context view nor the view context it
// shows while nothing is picked hand-writes a <button> or a Material Symbols
// span. The dock's style buttons are pressed toggles with `active`, its
// glyphs (◯ ▦ 🌙 🌡️ ✦ ◐, the search 🔎 and the collapse +) are text
// characters, not Material symbols, and stay plain text. Context's tabs and
// its Contacts mode button are `role="tab"` controls: they say they are
// chosen with `aria-selected` and keep their own `active` class, never
// `aria-pressed`.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
/** A view's template block: everything outside script, style and comments. */
function template(file) {
const source = readFileSync(
new URL(`../views/${file}`, import.meta.url),
'utf8',
);
return source
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
}
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const tags = (markup, name) =>
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
const dock = template('CommandDockView.vue');
const context = template('ContextView.vue');
const inView = template('panels/ViewContext.vue');
const views = {
// The six style buttons, the two tray toggles and their pins, the map
// source chips, Location's collapse, its landmark and city pills and the
// search toggle.
'CommandDockView.vue': { markup: dock, buttons: 15, icons: 0, closes: 0 },
// Search and Expand in the header, the two tabs, Contacts, the cockpit
// entry, SEARCH NEARBY SITES and the TR-3B chip.
'ContextView.vue': { markup: context, buttons: 8, icons: 7, closes: 0 },
// An off layer's worldwide tile, an item's row, the place and layer chips
// and Ask GEV; a layer's Turn off is a UiCloseButton. The glyphs: the
// header's eye, a worldwide tile's (on and off), a layer group's, an
// item's motion and the layer chips' add.
'panels/ViewContext.vue': { markup: inView, buttons: 5, icons: 6, closes: 1 },
};
test('the dock and Context hand-write no button; each is a UiButton', () => {
for (const [file, { markup, buttons, closes }] of Object.entries(views)) {
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
assert.deepEqual(markup.match(/<component\b/gi) ?? [], [], file);
assert.equal(tags(markup, 'UiButton').length, buttons, file);
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
}
});
test('the style buttons are pressed toggles with active', () => {
assert.doesNotMatch(dock, /v-class-toggle="\{[^"]*\bactive\b/);
const styles = tags(dock, 'UiButton').filter((b) =>
/class="style-btn"/.test(b),
);
assert.deepEqual(
styles.map((b) => b.match(/data-style="(\w+)"/)[1]),
['normal', 'retro', 'surveillance', 'thermal', 'anime', 'noir'],
);
for (const button of styles) {
const name = button.match(/data-style="(\w+)"/)[1];
assert.match(button, /\spressed-class="active"/, name);
// Normal stays the pressed one until a style is published.
assert.match(
button,
name === 'normal'
? /\s:pressed="!style \|\| style\.name === 'normal'"/
: new RegExp(String.raw`\s:pressed="style\?\.name === '${name}'"`),
name,
);
}
});
test('no tag hand-writes aria-pressed; the pressed toggles take :pressed', () => {
for (const [file, { markup }] of Object.entries(views))
assert.doesNotMatch(
markup,
tag(String.raw`<\w+\bATTRS\s:?aria-pressed`),
file,
);
const pressed = (markup) =>
tags(markup, 'UiButton').filter((b) => /\s:pressed=/.test(b)).length;
// The six styles, two pins, map sources, landmarks and cities.
assert.equal(pressed(dock), 11);
// Search, Expand and TR-3B.
assert.equal(pressed(context), 3);
assert.equal(pressed(inView), 0);
});
test("Context's tabs say they are chosen, not pressed", () => {
const tabs = tags(context, 'UiButton').filter((b) => /\srole="tab"/.test(b));
assert.equal(tabs.length, 3);
for (const button of tabs) {
assert.match(button, /\s:aria-selected=/);
assert.doesNotMatch(button, /\s:pressed=/);
assert.match(button, /\s(?::class|v-class-toggle)="\{ active: /);
}
});
test('they hand-write no Material glyph; each is a UiIcon', () => {
for (const [file, { markup, icons }] of Object.entries(views)) {
assert.deepEqual(
markup.match(/material-symbols-outlined/g) ?? [],
[],
file,
);
const found = tags(markup, 'UiIcon');
assert.equal(found.length, icons, file);
// Without it the kit writes an 18px size that beats the site rules.
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
}
// An item's motion glyph is an image with its own name, not decoration.
const [motion] = tags(inView, 'UiIcon').filter((i) =>
/view-context__row-motion/.test(i),
);
assert.match(motion, /\srole="img"/);
assert.match(motion, /\s:aria-label=/);
assert.match(motion, /\s:aria-hidden="null"/);
});
+3 -2
View File
@@ -1,7 +1,8 @@
// Every modal dialog in a Vue view is a UiDialog: no SFC template hand-writes
// `<dialog>`. Panels drawn as `role="dialog"` (key setup, the welcome
// launcher, the CCTV popup, Story Explore's filter) and the render failure's
// `alertdialog` are other controls.
// launcher, the CCTV popup, Story Explore's filter, the credits, the Omnibar
// guide's callout) and the render failure's `alertdialog` are other
// controls.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, readdirSync } from 'node:fs';
+126
View File
@@ -0,0 +1,126 @@
// UTILITIES ▸ Draw (its toggle, Clear, the colour swatches and the drawn
// shapes' rows), Import and the Street Level panel are on the kit: none of
// them hand-writes a <button>, a Material Symbols span, a select, a checkbox
// or a range. The Draw toggle is a pressed toggle with `active`. The colour
// swatches are `role="radio"` buttons: they say they are chosen with
// `aria-checked` and their own `active` class, never `aria-pressed`. A drawn
// shape's show/hide renames itself (Show …, Hide …) rather than being pressed.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
const source = (file) =>
readFileSync(new URL(`../views/panels/${file}`, import.meta.url), 'utf8');
/** A view's template block: everything outside script, style and comments. */
const template = (file) =>
source(file)
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const tags = (markup, name) =>
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
const views = {
// Draw and Clear.
'DrawControls.vue': { buttons: 2, icons: 1, closes: 0 },
// The five colours, one v-for.
'DrawSwatches.vue': { buttons: 1, icons: 0, closes: 0 },
// A row's swatch, show/hide, the application's actions and fly to; remove
// is a UiCloseButton.
'DrawMarkList.vue': { buttons: 4, icons: 3, closes: 1 },
// Import and a file's row actions.
'GeoImport.vue': { buttons: 2, icons: 2, closes: 0 },
// The status toggle, EXPAND and the nearest-imagery button; the viewer's
// close. EXPAND's ⤢ ⤡ and the errors' ⚠ are text, not Material symbols.
'StreetLevelPanel.vue': { buttons: 3, icons: 0, closes: 1 },
};
const markup = Object.fromEntries(
Object.keys(views).map((file) => [file, template(file)]),
);
test('the Draw, Import and Street Level views hand-write no button', () => {
for (const [file, { buttons, closes }] of Object.entries(views)) {
const html = markup[file];
assert.deepEqual(html.match(/<button\b/gi) ?? [], [], file);
assert.deepEqual(html.match(/<component\b/gi) ?? [], [], file);
assert.equal(tags(html, 'UiButton').length, buttons, file);
assert.equal(tags(html, 'UiCloseButton').length, closes, file);
}
});
test('they hand-write no select, checkbox or range', () => {
for (const [file, html] of Object.entries(markup)) {
assert.deepEqual(html.match(/<select\b/gi) ?? [], [], file);
assert.doesNotMatch(
html,
tag(String.raw`<input\bATTRS\stype="(?:checkbox|range)"`),
file,
);
}
// SINCE is the kit's range.
assert.equal(tags(markup['StreetLevelPanel.vue'], 'UiSlider').length, 1);
});
test('they hand-write no Material glyph; each is a UiIcon sized by the site', () => {
for (const [file, { icons }] of Object.entries(views)) {
const html = markup[file];
assert.deepEqual(html.match(/material-symbols-outlined/g) ?? [], [], file);
const found = tags(html, 'UiIcon');
assert.equal(found.length, icons, file);
// Without it the kit writes an 18px size that beats the site rules.
for (const icon of found) assert.match(icon, /\s:size="null"/, file);
}
// Draw's and Import's glyphs keep pp-icon, which sizes them.
for (const file of ['DrawControls.vue', 'GeoImport.vue']) {
const [icon] = tags(markup[file], 'UiIcon');
assert.match(icon, /\sclass="pp-icon"/, file);
}
});
test('no tag hand-writes aria-pressed; Draw is a pressed toggle with active', () => {
for (const [file, html] of Object.entries(markup))
assert.doesNotMatch(
html,
tag(String.raw`<\w+\bATTRS\s:?aria-pressed`),
file,
);
const [draw] = tags(markup['DrawControls.vue'], 'UiButton').filter((b) =>
/\sid="draw-toggle"/.test(b),
);
assert.match(draw, /\s:pressed="draw\?\.active \?\? false"/);
assert.match(draw, /\spressed-class="active"/);
const [clear] = tags(markup['DrawControls.vue'], 'UiButton').filter((b) =>
/\sid="draw-clear"/.test(b),
);
assert.doesNotMatch(clear, /\s:pressed=/);
// A shape's show/hide says what it does in its name, not by being pressed.
for (const button of tags(markup['DrawMarkList.vue'], 'UiButton'))
assert.doesNotMatch(button, /\s:pressed=/);
});
test('the colour swatches are radios chosen by aria-checked, never pressed', () => {
const [swatch] = tags(markup['DrawSwatches.vue'], 'UiButton');
assert.match(swatch, /\srole="radio"/);
assert.match(
swatch,
/\s:aria-checked="String\(color === props\.modelValue\)"/,
);
assert.match(swatch, /\s:class="\{ active: color === props\.modelValue \}"/);
assert.doesNotMatch(swatch, /\s:pressed=|\spressed-class=/);
});
test('code that focuses a converted button reaches its element', () => {
// A template ref on a component holds the component, not the button.
assert.match(
source('DrawSwatches.vue'),
/:ref="\(swatch\) => \(buttons\[index\] = swatch\?\.\$el\)"/,
);
assert.match(
source('GeoImport.vue'),
/importButton\.value\?\.\$el\.focus\(\)/,
);
});
+7 -6
View File
@@ -31,9 +31,9 @@ const heroViews = [
test('the entity card hand-writes no button; each is a UiButton', () => {
for (const markup of [card, camera, nearby, ...heroViews])
assert.deepEqual(markup.match(/<button\b/gi) ?? [], []);
// Photos, Route, 3D, Cockpit view, the cockpit entry, Fly to, Follow and
// Ask GEV.
assert.equal(card.match(/<UiButton\b/g)?.length, 8);
// Photos, Route, 3D, Cockpit view, Find it, the cockpit entry, Fly to,
// Follow and Ask GEV.
assert.equal(card.match(/<UiButton\b/g)?.length, 9);
assert.equal(card.match(/<UiCloseButton\b/g)?.length, 1);
// A camera's bigger view and More info; its popup closes with a UiCloseButton.
assert.equal(camera.match(/<UiButton\b/g)?.length, 2);
@@ -59,9 +59,10 @@ test('the entity card hand-writes no Material glyph; each is a UiIcon', () => {
for (const markup of [card, camera, nearby, ...heroViews])
assert.deepEqual(markup.match(/material-symbols-outlined/g) ?? [], []);
const counts = [
// The preview switch's three, the hero glyph, the header icon, the
// warning, the route's plane, the route note and the three actions.
[card, 11],
// The preview switch's three, the hero glyph, the header icon, Find
// it, the warning, the route's plane, the route note and the three
// actions.
[card, 12],
// Bigger view, the popup's camera and More info.
[camera, 3],
// The two weather glyphs, five headings and three row glyphs.
+142
View File
@@ -0,0 +1,142 @@
// The space missions, Contacts, Radio and provider settings controls are the
// kit's: none of their views hand-writes a <button>, a Material Symbols span,
// a select or a checkbox. Radio's Enable, the RTL-SDR card's Connect and its
// FM and ADS-B modes are pressed toggles with `active`; Radio's Play and the
// card's Locate keep their own `active` class, since their words change
// with their state rather than saying they are pressed. The RTL-SDR card's
// FM frequency stays a native number field (the kit has none), and the radio
// tuner's range stays native: its owner moves the handle back to the
// selected station on a drag's first input without changing the slot.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
/** A view's template block: everything outside script, style and comments. */
function template(file) {
const source = readFileSync(
new URL(`../views/${file}`, import.meta.url),
'utf8',
);
return source
.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/g, '')
.replace(/<!--[\s\S]*?-->/g, '');
}
// A tag's attributes, read past quoted values so a handler's `=>` does not
// end the tag early.
const ATTRS = String.raw`(?:[^>"']|"[^"]*"|'[^']*')*`;
const tag = (pattern, flags = '') =>
new RegExp(pattern.replaceAll('ATTRS', ATTRS), flags);
const tags = (markup, name) =>
markup.match(tag(String.raw`<${name}\bATTRS>`, 'g')) ?? [];
const byId = (markup, name, id) => {
const found = tags(markup, name).filter((t) =>
new RegExp(String.raw`\sid="${id}"`).test(t),
);
assert.equal(found.length, 1, id);
return found[0];
};
// Each view's UiButtons, UiCloseButtons, UiIcons, UiSelects and UiSliders.
const VIEWS = {
// FOCUS, REPLAY ASCENT, the replay's pause, PREV, NEXT and SHOW ALL; the
// header's deselect and the replay's Cancel close.
'panels/MissionDetail.vue': [6, 2, 0, 0, 1],
// A mission's row.
'panels/MissionRoster.vue': [1, 0, 0, 0, 0],
'panels/MissionReplayOverlay.vue': [0, 0, 0, 0, 0],
'panels/SpaceMissionsPanel.vue': [0, 0, 0, 0, 0],
// PREV, FOCUS, NEXT and a contact's row.
'panels/AwarenessPanel.vue': [4, 0, 0, 0, 0],
'panels/AwarenessDirection.vue': [0, 0, 0, 0, 0],
'panels/AwarenessNames.vue': [0, 0, 0, 0, 0],
// Connect, Locate, Change device, FM, ADS-B, Tune and the two seeks.
'panels/SdrCard.vue': [8, 0, 0, 1, 1],
// Enable, PREV, PLAY, NEXT and STOP.
'panels/RadioPanel.vue': [5, 0, 0, 1, 1],
'panels/RadioTuner.vue': [0, 0, 0, 0, 0],
// The POWER UP chip and its bolt, a key's REMOVE, the voice auth toggle
// and SAVE KEYS; the dialog's close.
'ProviderSettingsView.vue': [4, 1, 1, 0, 0],
};
const views = Object.entries(VIEWS).map(([file, counts]) => ({
file,
markup: template(file),
counts,
}));
test('they hand-write no button; each is a UiButton or UiCloseButton', () => {
for (const { file, markup, counts } of views) {
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
assert.deepEqual(markup.match(/<component\b/gi) ?? [], [], file);
assert.equal(tags(markup, 'UiButton').length, counts[0], file);
assert.equal(tags(markup, 'UiCloseButton').length, counts[1], file);
}
});
test('they hand-write no Material glyph; each is a UiIcon sized by its site', () => {
for (const { file, markup, counts } of views) {
assert.deepEqual(
markup.match(/material-symbols-outlined/g) ?? [],
[],
file,
);
const icons = tags(markup, 'UiIcon');
assert.equal(icons.length, counts[2], file);
// Without it the kit writes an 18px size that beats the site rules.
for (const icon of icons) assert.match(icon, /\s:size="null"/, file);
}
});
test('their selects and ranges are the kit’s, apart from the tuner', () => {
for (const { file, markup, counts } of views) {
assert.deepEqual(markup.match(/<select\b/gi) ?? [], [], file);
assert.doesNotMatch(markup, /type="checkbox"/, file);
assert.equal(tags(markup, 'UiSelect').length, counts[3], file);
assert.equal(tags(markup, 'UiSlider').length, counts[4], file);
const ranges = tags(markup, 'input').filter((i) =>
/\stype="range"/.test(i),
);
assert.equal(ranges.length, file === 'panels/RadioTuner.vue' ? 1 : 0, file);
}
});
test('no tag hand-writes aria-pressed; the pressed toggles take :pressed', () => {
const pressed = {
'panels/MissionDetail.vue': 1,
'panels/SdrCard.vue': 3,
'panels/RadioPanel.vue': 1,
};
for (const { file, markup } of views) {
assert.doesNotMatch(
markup,
tag(String.raw`<\w+\bATTRS\s(?:v-bind)?:?aria-pressed`),
file,
);
const toggles = tags(markup, 'UiButton').filter((b) =>
/\s:pressed=/.test(b),
);
assert.equal(toggles.length, pressed[file] ?? 0, file);
}
const sdr = views.find((v) => v.file === 'panels/SdrCard.vue').markup;
const radio = views.find((v) => v.file === 'panels/RadioPanel.vue').markup;
for (const [markup, id] of [
[sdr, 'sdr-connect-btn'],
[sdr, 'sdr-mode-fm-btn'],
[sdr, 'sdr-mode-adsb-btn'],
[radio, 'radio-enable-btn'],
])
assert.match(byId(markup, 'UiButton', id), /\spressed-class="active"/, id);
});
test('Play and Locate keep their own active class rather than pressed', () => {
const sdr = views.find((v) => v.file === 'panels/SdrCard.vue').markup;
const radio = views.find((v) => v.file === 'panels/RadioPanel.vue').markup;
for (const [markup, id] of [
[radio, 'radio-play-btn'],
[sdr, 'sdr-locate-btn'],
]) {
const button = byId(markup, 'UiButton', id);
assert.doesNotMatch(button, /\s:pressed=/, id);
assert.match(button, /\sv-class-toggle="\{ active: /, id);
}
});
+135
View File
@@ -0,0 +1,135 @@
// The small surfaces' buttons and Material glyphs are the kit's: the locale
// picker, the phone tab bar, the globe actions and compass, the imagery
// divider, the scene sharing dialog, the layer group index, the celestial
// ring, the title logo, Exit clean view, the HUD's cockpit entry, the News
// cards, the rail cards, the layer rows' toggles, the credits line and the
// camera calibration chips hand-write no <button> and no Material Symbols
// span. The Omnibar guide's extra rings are its template's, not built in
// script. The locale picker's globe, caret and check and a News card's
// category icon stay inline SVG: none is a Material symbol the page loads.
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')) ?? [];
// Per file: its UiButtons, UiCloseButtons and UiIcons.
const SURFACES = {
'views/panels/LocalePicker.vue': [1, 0, 0],
'views/panels/PhoneTabBar.vue': [1, 0, 1],
'views/panels/GlobeCompass.vue': [1, 0, 1],
// Clear, share, tilt and reset; the clear, tilt and reset glyphs.
'views/panels/GlobeActions.vue': [4, 0, 3],
'views/panels/ImagerySplitView.vue': [1, 0, 0],
// The body's buttons and the footer's.
'views/panels/SceneDialog.vue': [2, 0, 0],
'views/panels/LayerSectionIndex.vue': [1, 0, 0],
// The sun and moon markers.
'views/panels/CelestialRing.vue': [0, 0, 2],
'views/panels/OmnibarGuide.vue': [3, 1, 0],
// The overlay targets' buttons and the title logo.
'views/SceneChromeView.vue': [2, 0, 0],
'views/DisplayControlsView.vue': [1, 0, 0],
'views/IntelHudView.vue': [1, 0, 1],
// The card's face and the selected card's clear chip.
'news/NewsCard.vue': [2, 0, 0],
'rail/RailCard.vue': [1, 0, 0],
'layerPanel/LayerRows.vue': [1, 0, 0],
'credits/CreditsView.vue': [1, 1, 0],
'cctv/CctvCalValue.vue': [1, 0, 0],
};
test('the small surfaces hand-write no button; each is a kit button', () => {
for (const [file, [buttons, closes]] of Object.entries(SURFACES)) {
const markup = template(file);
assert.deepEqual(markup.match(/<button\b/gi) ?? [], [], file);
assert.equal(tags(markup, 'UiButton').length, buttons, file);
assert.equal(tags(markup, 'UiCloseButton').length, closes, file);
}
});
test('the small surfaces hand-write no Material glyph; each is a UiIcon', () => {
for (const [file, [, , count]] of Object.entries(SURFACES)) {
const markup = template(file);
assert.deepEqual(
markup.match(/material-symbols-outlined/g) ?? [],
[],
file,
);
const icons = tags(markup, 'UiIcon');
assert.equal(icons.length, count, file);
// Without it the kit writes an 18px size that beats the sites' own rules.
for (const icon of icons) assert.match(icon, /\s:size="null"/, file);
}
});
test('the only inline SVG glyphs are the locale picker’s and a News category’s', () => {
for (const file of Object.keys(SURFACES)) {
const expected =
file === 'views/panels/LocalePicker.vue'
? 3
: file === 'news/NewsCard.vue'
? 1
: 0;
assert.equal(template(file).match(/<svg\b/g)?.length ?? 0, expected, file);
}
});
test('buttons whose owner patches synchronously redraw their contents with it', () => {
// A UiButton's slot renders inside the button, a tick after a change the
// button's own attributes do not carry; a conditional slot is redrawn with
// its view.
// How many of each file's first buttons the owner redraws and reads.
for (const [file, count] of [
['news/NewsCard.vue', 1],
['rail/RailCard.vue', 1],
['credits/CreditsView.vue', 1],
['views/panels/OmnibarGuide.vue', 3],
]) {
const markup = template(file);
const buttons = tags(markup, 'UiButton').slice(0, count);
assert.equal(buttons.length, count, file);
let from = 0;
for (const button of buttons) {
from = markup.indexOf(button, from) + button.length;
assert.match(
markup.slice(from),
/^\s*<template v-if="redrawWithView" #default\s*>/,
file,
);
}
assert.match(read(file), /const redrawWithView = true;/, file);
}
});
test('the Omnibar guide draws its extra rings in its template', () => {
const guide = template('views/panels/OmnibarGuide.vue');
assert.match(
guide,
/<div\s+v-for="i in view\.subRings"\s+:key="i"\s+class="gev-guide-ring gev-guide-ring--sub"\s*><\/div\s*>\s*<\/div\s*>\s*<\/Teleport/,
);
const owner = read('omnibarGuide.js');
assert.deepEqual(owner.match(/createElement\(/g), ['createElement(']);
assert.doesNotMatch(owner, /\.className\s*=|\.append\(/);
assert.match(owner, /view\.subRings = rest\.length;\s*paint\(\);/);
});
test('the layer disclosure builds no control', () => {
// Its one `<button` is a comment's word for the element Chromium focuses.
const disclosure = read('panelDisclosure.js');
assert.doesNotMatch(disclosure, /createElement|innerHTML|insertAdjacentHTML/);
const code = disclosure
.replace(/\/\/.*$/gm, '')
.replace(/\/\*[\s\S]*?\*\//g, '');
assert.doesNotMatch(code, /<button/);
});
+6 -5
View File
@@ -3,11 +3,12 @@
// `<input type="checkbox">`. Their glyphs are inline SVG drawn for Stories
// (play, pause, back, filter, search, clear, expand, the GEV eye); no
// Material symbol the page loads draws any of them the same, so they stay
// SVG, and no view hand-writes a Material Symbols span. The two search
// fields keep their own markup rather than UiSearchField, whose Material
// magnifier would replace their SVG one, and their clear buttons stay ghost
// UiButtons with an SVG cross rather than UiCloseButtons, whose glyph is ×
// or the Material `close` symbol.
// SVG, and no view hand-writes a Material Symbols span. The three search
// fields (Explore's two and the Story context sheet's) keep their own markup
// rather than UiSearchField, whose Material magnifier would replace their
// SVG one, and Explore's two clear buttons stay ghost UiButtons with an SVG
// cross rather than UiCloseButtons, whose glyph is × or the Material `close`
// symbol.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
@@ -0,0 +1,182 @@
// 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);
}
});
/**
* `loadImage`, which downloads through an Image of its own that is never on
* the page: the one place a `.src` is written.
*/
const LOADER = /^export function loadImage\([\s\S]*?^}$/m;
// An assignment, plain or compound (`=`, `+=`, `||=`, `??=`, `**=`…), not
// a comparison or an arrow.
const ASSIGN = String.raw`\s*(?:[-+*/%&|^]|\*\*|<<|>>>?|&&|\|\||\?\?)?=(?![=>])`;
const assigned = (target, flags = '') =>
new RegExp(String.raw`${target}${ASSIGN}`, flags);
// A member or computed member: what a destructuring write must not target.
const MEMBER = /[\w$)\]]\s*(?:\.\s*[\w$]|\[)/;
test('the photo viewer is drawn by its view, and its layer needs no Vue', () => {
const source = read(VIEWER);
const loader = source.match(LOADER)?.[0];
assert.ok(loader, 'loadImage is found');
const rest = source.replace(LOADER, '');
// No element made, inserted, moved, removed or written: the view does
// all of that. (The panorama renderer in panorama.js sizes its canvas's
// drawing buffer, as WebGL drawing does; nothing here does.)
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/,
assigned(
String.raw`\.(?:hidden|disabled|textContent|innerText|tabIndex|title|alt)`,
),
assigned(String.raw`\.(?:width|height|ariaLabel|id|value)`),
// Properties written in bulk or by reflection (an Error's own fields
// aside).
/\bObject\.assign\(\s*(?!new Error\()/,
/\bObject\.definePropert(?:y|ies)\(/,
/\bReflect\.(?:set|defineProperty)\(/,
/from 'vue'|\.vue'/,
])
assert.doesNotMatch(source, write);
// No property written through brackets (`picture['src'] = …`,
// `el[name] ||= …`), outside array destructuring declarations.
assert.doesNotMatch(
source.replace(/\b(?:const|let|var)\s*\[/g, ''),
assigned(String.raw`[\w$)\]]\s*\[[^[\]]*\]`),
'a bracket write',
);
// No destructuring write to a property (`[el.src] = …`,
// `({ a: el.id } = …)`); declarations bind names only.
for (const pattern of [
/(?<!\b(?:const|let|var)\s*)\[((?:[^[\]=;]|\[[^[\]=;]*\])*)\]\s*=(?![=>])/g,
/(?<!\b(?:const|let|var)\s*)\{((?:[^{}=;]|\{[^{}=;]*\})*)\}\s*\)?\s*=(?![=>])/g,
])
for (const [write, targets] of source.matchAll(pattern))
assert.doesNotMatch(targets, MEMBER, write);
const SRC = assigned(String.raw`\.src`, 'g');
assert.doesNotMatch(rest, SRC, 'a .src written on the page');
// In loadImage, only on the off-page Image it creates: `image` is bound
// once, to that Image, and never rebound or shadowed.
assert.match(loader, /\bconst image = new Image\(\);/);
assert.equal(
loader.match(/\b(?:const|let|var|function|class)\s+image\b/g)?.length,
1,
'one binding of image',
);
for (const rebinding of [
assigned(String.raw`(?<!\b(?:const|let|var)\s+)(?<![\w$.])image`),
/(?<![\w$.])image\s*=>/,
/\((?:[^()]*[,{[\s(])?image\b[^()]*\)\s*=>/,
/\bfunction\b[^(]*\((?:[^)]*[,{[\s(])?image\b[^)]*\)/,
/\b(?:const|let|var)\s*[{[][^=]*\bimage\b/,
/\bcatch\s*\([^)]*\bimage\b/,
])
assert.doesNotMatch(loader, rebinding, 'image rebound or shadowed');
const writes = loader.match(SRC)?.length ?? 0;
assert.equal(
loader.match(assigned(String.raw`(?<![\w$.)\]])image\.src`, 'g'))?.length ??
0,
writes,
'a .src written on something other than the Image',
);
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,
);
});
+439
View File
@@ -0,0 +1,439 @@
// The kit's every-control claims in docs/VUE-MIGRATION.md, read from every
// SFC outside the kit: every button is a kit button, every select a
// UiSelect, every checkbox a UiCheckbox, every range a UiSlider apart from
// the two named below, and every Material Symbols glyph a UiIcon; every
// pressed toggle is a UiButton with `pressed` (no template hand-writes
// `aria-pressed` on any element, as an attribute or inside a `v-bind`
// object, apart from the exceptions below), and every close, dismiss and
// clear button a UiCloseButton. Outside the kit, no module (nor an SFC's
// script) builds a button, select, field or Material glyph in script, or
// writes one as markup in a string, apart from the globe panel's standalone
// page named below.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, readdirSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const SRC_ROOT = fileURLToPath(new URL('../../', import.meta.url));
const KIT_ROOT = fileURLToPath(new URL('./', import.meta.url));
const REPO_ROOT = path.resolve(SRC_ROOT, '..');
// The pressed toggles that still hand-write `aria-pressed`, by file: each
// pattern matches exactly one of the file's tags, and no other tag may.
const HAND_WRITTEN_PRESSED = {
// Explore's story cards are `role="button"` elements, not buttons.
'src/ui/views/stories/ExploreScreen.vue': [
/^<div class="card" role="button"/,
],
};
/** Every SFC under src, outside the kit. */
function sfcFiles(directory = SRC_ROOT) {
const files = [];
for (const entry of readdirSync(directory, { withFileTypes: true })) {
const absolute = path.join(directory, entry.name);
if (entry.isDirectory()) {
if (path.relative(KIT_ROOT, absolute) !== '')
files.push(...sfcFiles(absolute));
} else if (entry.isFile() && entry.name.endsWith('.vue'))
files.push(absolute);
}
return files.sort();
}
/** The template block: everything outside script, style and comments. */
function template(source) {
return source
.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 RAW_SELECT = /<select\b/gi;
const ANY_TAG = new RegExp(String.raw`<[A-Za-z][\w-]*\b(${ATTRS})>`, 'g');
// An attribute's name, outside the quoted values.
const names = (attrs) => attrs.replace(/"[^"]*"|'[^']*'/g, '""');
const PRESSED = /(?:^|\s)(?::|v-bind:)?aria-pressed(?=[\s=/]|$)/;
// A `v-bind` object that names aria-pressed.
const BOUND_PRESSED =
/(?:^|\s)(?:v-bind|:)=(?:"[^"]*aria-?pressed[^"]*"|'[^']*aria-?pressed[^']*')/i;
const TIMES = String.raw`×|&times;|&#215;|&#xd7;`;
const CLOSE_GLYPH = [
TIMES,
String.raw`<span\b${ATTRS}>\s*(?:${TIMES})\s*</span\s*>`,
String.raw`<span\b[^>]*\bmaterial-symbols-outlined\b[^>]*>\s*close\s*</span\s*>`,
String.raw`<UiIcon${ATTRS}\bname="close"${ATTRS}/>`,
].join('|');
const HAND_WRITTEN_CLOSE = new RegExp(
String.raw`<(button|UiButton)\b${ATTRS}>\s*(?:${CLOSE_GLYPH})\s*</\1\s*>`,
'gi',
);
const tidy = (markup) => markup.replace(/\s+/g, ' ');
// The two ranges that stay native, by file (docs/VUE-MIGRATION.md says why).
const NATIVE_RANGES = {
'src/ui/views/panels/RadioTuner.vue': 1,
'src/ui/views/panels/WorldTimeline.vue': 1,
};
const RAW_BUTTON = /<button\b/gi;
// A tag whose class, static or bound (alone or in a `v-bind` object), names
// a Material Symbols style.
const MATERIAL_CLASS =
/(?:^|\s)(?:(?::|v-bind:)?class|v-bind|:)=(?:"[^"]*material-symbols[^"]*"|'[^']*material-symbols[^']*')/i;
const INPUT_TAG = new RegExp(String.raw`<input\b(${ATTRS})>`, 'gi');
// An attribute and its value, read from the tag rather than other values.
const ATTRIBUTE = /([^\s=/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'/>]+)))?/g;
/**
* A tag's `type`: written, bound to a quoted literal (`:type="'checkbox'"`),
* or named in a `v-bind` object; null when it is bound to anything else.
*/
function inputType(attrs) {
for (const m of attrs.matchAll(ATTRIBUTE)) {
const name = m[1].toLowerCase();
const value = m[2] ?? m[3] ?? m[4] ?? '';
if (name === 'type') return value.toLowerCase();
if (name === ':type' || name === 'v-bind:type') {
const literal = /^\s*(['`])([^'`]*)\1\s*$/.exec(value);
if (literal) return literal[2].toLowerCase();
}
if (name === 'v-bind' || name === ':') {
const named = /\btype\s*:\s*(['`])([^'`]*)\1/.exec(value);
if (named) return named[2].toLowerCase();
}
}
return null;
}
/** Hand-written buttons in an SFC's template. */
const rawButtons = (source) =>
[...template(source).matchAll(RAW_BUTTON)].map((m) => m[0]);
/** Tags in an SFC's template that draw a Material glyph by hand. */
function materialGlyphs(source) {
const found = [];
for (const m of template(source).matchAll(ANY_TAG))
if (!/^<UiIcon\b/.test(m[0]) && MATERIAL_CLASS.test(m[1]))
found.push(tidy(m[0]));
return found;
}
/** Native inputs of a type in an SFC's template. */
const nativeInputs = (source, type) =>
[...template(source).matchAll(INPUT_TAG)]
.filter((m) => inputType(m[1]) === type)
.map((m) => tidy(m[0]));
/** Raw selects in an SFC's template. */
const rawSelects = (source) =>
[...template(source).matchAll(RAW_SELECT)].map((m) => m[0]);
/** Tags that hand-write aria-pressed. */
function handWrittenPressed(source) {
const found = [];
for (const m of template(source).matchAll(ANY_TAG))
if (PRESSED.test(names(m[1])) || BOUND_PRESSED.test(m[1]))
found.push(tidy(m[0]));
return found;
}
/** Hand-written close buttons in an SFC's template. */
const handWrittenCloses = (source) =>
[...template(source).matchAll(HAND_WRITTEN_CLOSE)].map((m) => tidy(m[0]));
const views = sfcFiles().map((file) => ({
file: path.relative(REPO_ROOT, file).split(path.sep).join('/'),
source: readFileSync(file, 'utf8'),
}));
test('the scans find each hand-written control', () => {
for (const markup of [
'<template><select id="x" v-model="a"><option>1</option></select></template>',
'<template><SELECT\n class="x"></SELECT></template>',
])
assert.equal(rawSelects(markup).length, 1, markup);
for (const markup of [
'<template><UiSelect id="x" v-model="a" /></template>',
'<script>const html = "<select>";</script><template><p /></template>',
'<template><!-- a <select> once sat here --><p /></template>',
])
assert.equal(rawSelects(markup).length, 0, markup);
for (const markup of [
'<template><button type="button" :aria-pressed="String(on)">A</button></template>',
'<template><UiButton\n class="x"\n :title="a > b ? 1 : 2"\n aria-pressed="true"\n>A</UiButton></template>',
'<template><button v-bind:aria-pressed="on">A</button></template>',
'<template><div class="card" role="button" tabindex="0" :aria-pressed="on" /></template>',
'<template><li role="option" :aria-pressed="on" /></template>',
'<template><a :role="\'button\'" :aria-pressed="on">A</a></template>',
'<template><UiButton v-bind="{ \'aria-pressed\': on }">A</UiButton></template>',
])
assert.equal(handWrittenPressed(markup).length, 1, markup);
for (const markup of [
'<template><UiButton :pressed="Boolean(on)" pressed-class="active">A</UiButton></template>',
'<template><button :title="\'aria-pressed\'" @click="q(\'[aria-pressed=true]\')">A</button></template>',
'<template><li role="option" :aria-selected="on" /></template>',
])
assert.equal(handWrittenPressed(markup).length, 0, markup);
for (const markup of [
'<template><button type="button" @click="close">×</button></template>',
'<template><button type="button" :aria-label="l"><span aria-hidden="true">×</span></button></template>',
'<template><UiButton class="x"><UiIcon name="close" :size="null" /></UiButton></template>',
])
assert.equal(handWrittenCloses(markup).length, 1, markup);
for (const markup of [
'<template><UiCloseButton class="x" :label="l" /></template>',
'<template><UiButton :label="l"><UiIcon :name="item.icon" :size="null" /></UiButton></template>',
])
assert.equal(handWrittenCloses(markup).length, 0, markup);
});
test('the scans find each hand-written button, glyph, checkbox and range', () => {
for (const markup of [
'<template><button type="button">A</button></template>',
'<template><BUTTON\n class="x">A</BUTTON></template>',
])
assert.equal(rawButtons(markup).length, 1, markup);
for (const markup of [
'<template><UiButton>A</UiButton></template>',
'<script>const html = "<button>";</script><template><p /></template>',
'<template><!-- a <button> once sat here --><p /></template>',
])
assert.equal(rawButtons(markup).length, 0, markup);
for (const markup of [
'<template><span class="material-symbols-outlined">search</span></template>',
'<template><i class="pp-icon material-symbols-rounded" aria-hidden="true">add</i></template>',
'<template><span :class="\'material-symbols-outlined \' + extra">add</span></template>',
'<template><span\n class="x material-symbols-sharp"\n :title="a > b ? 1 : 2"\n>add</span></template>',
])
assert.equal(materialGlyphs(markup).length, 1, markup);
for (const markup of [
'<template><UiIcon name="search" class="material-symbols-outlined" :size="null" /></template>',
'<template><span class="x">search</span></template>',
'<template><p /></template><style>.x .material-symbols-outlined { color: red; }</style>',
])
assert.equal(materialGlyphs(markup).length, 0, markup);
assert.equal(
nativeInputs(
'<template><input type="checkbox" v-model="a" /></template>',
'checkbox',
).length,
1,
);
assert.equal(
nativeInputs(
'<template><input\n class="x"\n type="range"\n :max="a > b ? 1 : 2"\n/></template>',
'range',
).length,
1,
);
assert.equal(
nativeInputs(
'<template><input type="text" :title="\'type=checkbox\'" /></template>',
'checkbox',
).length,
0,
);
assert.equal(
nativeInputs(
'<template><UiCheckbox v-model="a">A</UiCheckbox></template>',
'checkbox',
).length,
0,
);
for (const markup of [
`<template><input :type="'checkbox'" /></template>`,
`<template><input v-bind:type="'checkbox'" /></template>`,
`<template><input v-bind="{ type: 'checkbox' }" /></template>`,
'<template><input TYPE="checkbox" /></template>',
'<template><input type=checkbox/></template>',
])
assert.equal(nativeInputs(markup, 'checkbox').length, 1, markup);
assert.equal(
nativeInputs('<template><input :type="item.type" /></template>', 'checkbox')
.length,
0,
);
assert.equal(
materialGlyphs(
`<template><span v-bind="{ class: 'material-symbols-outlined' }">add</span></template>`,
).length,
1,
);
});
test('the views are read: the scan reaches the views and skips the kit', () => {
const files = views.map((view) => view.file);
assert.ok(files.includes('src/ui/views/panels/ChatPanel.vue'));
assert.ok(files.includes('src/ui/layerPanel/RowRange.vue'));
assert.ok(!files.some((file) => file.startsWith('src/ui/kit/')));
});
test('every select in the views is a UiSelect', () => {
const found = [];
for (const { file, source } of views)
for (const markup of rawSelects(source)) found.push(`${file}: ${markup}`);
assert.deepEqual(found, []);
});
test('no view hand-writes aria-pressed on a button outside the documented exceptions', () => {
const unexpected = [];
for (const { file, source } of views) {
const allowed = [...(HAND_WRITTEN_PRESSED[file] ?? [])];
for (const markup of handWrittenPressed(source)) {
const at = allowed.findIndex((pattern) => pattern.test(markup));
if (at === -1) unexpected.push(`${file}: ${markup}`);
else allowed.splice(at, 1);
}
assert.deepEqual(allowed, [], `${file}: an exception no longer matches`);
}
assert.deepEqual(unexpected, []);
});
test('no view hand-writes a close button; each is a UiCloseButton', () => {
const found = [];
for (const { file, source } of views)
for (const markup of handWrittenCloses(source))
found.push(`${file}: ${markup}`);
assert.deepEqual(found, []);
});
test('every button in the views is a kit button', () => {
const found = [];
for (const { file, source } of views)
for (const markup of rawButtons(source)) found.push(`${file}: ${markup}`);
assert.deepEqual(found, []);
});
test('every Material Symbols glyph in the views is a UiIcon', () => {
const found = [];
for (const { file, source } of views)
for (const markup of materialGlyphs(source))
found.push(`${file}: ${markup}`);
assert.deepEqual(found, []);
});
test('every checkbox in the views is a UiCheckbox', () => {
const found = [];
for (const { file, source } of views)
for (const markup of nativeInputs(source, 'checkbox'))
found.push(`${file}: ${markup}`);
assert.deepEqual(found, []);
});
test('every range in the views is a UiSlider apart from the two named', () => {
const counts = {};
for (const { file, source } of views) {
const n = nativeInputs(source, 'range').length;
if (n) counts[file] = n;
}
assert.deepEqual(counts, NATIVE_RANGES);
});
// The globe panel's standalone page: plain HTML a host serves, with no Vue
// and no kit, so its two buttons are written as markup.
const STRING_MARKUP_PAGES = new Set(['src/tools/globePanel.js']);
/**
* Every module under src outside the kit, tests and test support, and every
* SFC's script blocks, as `{ file, source }`.
*/
function scriptSources(directory = SRC_ROOT) {
const found = [];
for (const entry of readdirSync(directory, { withFileTypes: true })) {
const absolute = path.join(directory, entry.name);
const file = path.relative(REPO_ROOT, absolute).split(path.sep).join('/');
if (entry.isDirectory()) {
if (
path.relative(KIT_ROOT, absolute) !== '' &&
entry.name !== 'testSupport'
)
found.push(...scriptSources(absolute));
} else if (
!entry.isFile() ||
/\.test\.(?:js|mjs|ts)$|Fixture\.mjs$/.test(entry.name)
) {
continue;
} else if (/\.(?:js|mjs|ts)$/.test(entry.name)) {
found.push({ file, source: readFileSync(absolute, 'utf8') });
} else if (entry.name.endsWith('.vue')) {
const blocks = [
...readFileSync(absolute, 'utf8').matchAll(
/<script\b[^>]*>([\s\S]*?)<\/script\s*>/g,
),
];
found.push({ file, source: blocks.map((m) => m[1]).join('\n') });
}
}
return found;
}
const SCRIPT_CONTROL =
/\bcreateElement(?:NS)?\(\s*(?:[^,)]*,\s*)?['"`](?:button|select|input|textarea)['"`]/gi;
const SCRIPT_GLYPH =
/['"`][^'"`]*\bmaterial-symbols-(?:outlined|rounded|sharp|\$\{)/g;
const STRING_MARKUP = /<(?:button|select|input|textarea)\b/gi;
/** A source with its comments blanked, line numbers kept. */
const uncommented = (source) =>
source
.replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, ' '))
.replace(/(^|[^:'"`\\])\/\/[^\n]*/g, '$1');
/** Each match in a source, as `file:line: text`. */
function hits(file, source, pattern) {
return [...source.matchAll(pattern)].map((m) => {
const line = source.slice(0, m.index).split('\n').length;
return `${file}:${line}: ${source.split('\n')[line - 1].trim()}`;
});
}
test('no module outside the kit builds a control or Material glyph in script', () => {
const sees = (pattern, text) => [...text.matchAll(pattern)].length > 0;
assert.ok(
sees(SCRIPT_CONTROL, "const b = document.createElement('button');"),
);
assert.ok(sees(SCRIPT_CONTROL, 'doc.createElement("INPUT")'));
assert.ok(
sees(SCRIPT_CONTROL, "someDocument.createElement(\n 'button',\n);"),
);
assert.ok(!sees(SCRIPT_CONTROL, "document.createElement('div')"));
assert.ok(
sees(SCRIPT_GLYPH, "span.className = 'material-symbols-outlined';"),
);
assert.ok(sees(SCRIPT_GLYPH, 'el.className = `material-symbols-${style}`;'));
assert.ok(
!sees(SCRIPT_GLYPH, 'ctx.font = \'24px "Material Symbols Outlined"\';'),
);
assert.ok(sees(STRING_MARKUP, "host.innerHTML = '<button>x</button>';"));
assert.ok(
!sees(STRING_MARKUP, "'<button-row>'".replace('<button-row>', '<buttons>')),
);
const sources = scriptSources();
assert.ok(
sources.some(({ file }) => file === 'src/ui/views/panels/ChatPanel.vue'),
);
const found = [];
for (const { file, source } of sources) {
found.push(
...hits(file, source, SCRIPT_CONTROL),
...hits(file, source, SCRIPT_GLYPH),
);
if (!STRING_MARKUP_PAGES.has(file))
found.push(...hits(file, uncommented(source), STRING_MARKUP));
}
assert.deepEqual(found, []);
for (const file of STRING_MARKUP_PAGES) {
const page = sources.find((s) => s.file === file);
assert.ok(
page && hits(file, page.source, STRING_MARKUP).length,
`${file} no longer writes markup`,
);
}
});