mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Merge remote-tracking branch 'origin/main' into samehkhamis/kit-sweep-chat-voice
# Conflicts: # docs/VUE-MIGRATION.md # scripts/format-scope.json
This commit is contained in:
commit
21fde3829f
48 files changed
+877
-264
No files matched your search
@@ -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 three page tabs; the
|
||||
// first, second and fourth draw a glyph.
|
||||
'panels/CockpitBriefing.vue': { buttons: 7, 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 \{/);
|
||||
});
|
||||
@@ -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"/);
|
||||
});
|
||||
@@ -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/);
|
||||
});
|
||||
Reference in new issue
Block a user