mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
Merge remote-tracking branch 'origin/main' into samehkhamis/kit-sweep-draw
# Conflicts: # docs/VUE-MIGRATION.md
This commit is contained in:
commit
25cbd124d5
51 files changed
+1126
-235
No files matched your search
@@ -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);
|
||||
}
|
||||
});
|
||||
@@ -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,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