Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Fix active navigation contrast in light theme

Nguyen Xuan An1f8a7785678b
diff --git a/scripts/smoke-navigation.mjs b/scripts/smoke-navigation.mjs
new file mode 100644
index 00000000..33b6e077
--- /dev/null
+++ b/scripts/smoke-navigation.mjs
@@ -0,0 +1,53 @@
+import assert from 'node:assert/strict';
+import { chromium } from 'playwright';
+
+const origin = process.argv[2] ?? 'http://127.0.0.1:5173';
+const browser = await chromium.launch({
+ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe',
+ headless: true,
+});
+let checks = 0;
+
+try {
+ const page = await browser.newPage({ reducedMotion: 'reduce' });
+ for (const colorScheme of ['light', 'dark']) {
+ await page.emulateMedia({ colorScheme });
+ for (const route of ['/', '/docs.html', '/getting-started.html']) {
+ await page.goto(origin + route);
+ for (const width of [320, 390, 580, 1440]) {
+ await page.setViewportSize({ width, height: 1000 });
+ const contrast = await page.locator('nav a[aria-current]').evaluate(link => {
+ const channels = color => color.match(/[\d.]+/g).map(Number);
+ const backgrounds = [];
+ for (let element = link; element; element = element.parentElement) {
+ backgrounds.unshift(channels(getComputedStyle(element).backgroundColor));
+ }
+ let background = [255, 255, 255];
+ for (const layer of backgrounds) {
+ const opacity = layer[3] ?? 1;
+ background = background.map((channel, index) => layer[index] * opacity + channel * (1 - opacity));
+ }
+ const luminance = color => color.slice(0, 3).map(channel => {
+ const value = channel / 255;
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
+ }).reduce((total, channel, index) => total + channel * [0.2126, 0.7152, 0.0722][index], 0);
+ const backgroundLight = luminance(background);
+ const ratio = element => {
+ const foregroundLight = luminance(channels(getComputedStyle(element).color));
+ return (Math.max(foregroundLight, backgroundLight) + 0.05) / (Math.min(foregroundLight, backgroundLight) + 0.05);
+ };
+ const icon = link.querySelector('svg');
+ return { text: ratio(link), icon: icon ? ratio(icon) : null };
+ });
+ assert.ok(contrast.text >= 4.5, `${route} ${colorScheme} ${width}: active text contrast ${contrast.text.toFixed(2)} < 4.5`);
+ if (contrast.icon !== null) {
+ assert.ok(contrast.icon >= 3, `${route} ${colorScheme} ${width}: active icon contrast < 3`);
+ }
+ checks += 1;
+ }
+ }
+ }
+ console.log(`Navigation contrast passed: ${checks} page/theme/viewport combinations.`);
+} finally {
+ await browser.close();
+}
diff --git a/scripts/smoke-site.mjs b/scripts/smoke-site.mjs
index 14382eff..ba836617 100644
--- a/scripts/smoke-site.mjs
+++ b/scripts/smoke-site.mjs
@@ -3,6 +3,7 @@ import { mkdir, writeFile } from 'node:fs/promises';
import { chromium } from 'playwright';
const origin = process.argv[2] ?? 'http://127.0.0.1:5173';
+await import('./smoke-navigation.mjs');
await mkdir('artifacts', { recursive: true });
const browser = await chromium.launch({ executablePath:'C:/Program Files/Google/Chrome/Application/chrome.exe', headless:true, args:['--enable-webgl','--ignore-gpu-blocklist'] });
const errors = [];
diff --git a/src/brand.css b/src/brand.css
index 73e2109a..bee15929 100644
--- a/src/brand.css
+++ b/src/brand.css
@@ -11,7 +11,7 @@ button[aria-pressed=true] { background:#ffffff20; color:#fff; }
body .primary { background:#ececec; color:#171717; }
body .primary:hover { background:#fff; }
body input[type=range] { accent-color:#d7d7d7; }
-.studio-nav a[aria-current], nav a[aria-current] { color:#ececec; }
+.studio-nav a[aria-current], nav a[aria-current] { color:var(--text); }
.toolbar, .world-header { z-index:3; }
body .controls, body .landscape-controls { background:#171717e8; border:1px solid #ffffff1c; border-radius:var(--panel-radius); backdrop-filter:blur(16px); }
.demo-links { display:flex; gap:12px; font-size:12px; }