diff --git a/test/muted-text-contrast.test.mjs b/test/muted-text-contrast.test.mjs index 07ed9bd5..8d8d04a0 100644 --- a/test/muted-text-contrast.test.mjs +++ b/test/muted-text-contrast.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert/strict' import {readFileSync} from 'node:fs' import {test} from 'node:test' -import {contrastRatio, legibleMuted, mixRgb, parseRgbColor} from '../web/src/theme/contrast.ts' +import {contrastRatio, darkenForTextOn, legibleMuted, mixRgb, parseRgbColor} from '../web/src/theme/contrast.ts' const CSS = readFileSync(new URL('../web/src/styles.css', import.meta.url), 'utf8') const rgb = (hex) => parseRgbColor(hex) @@ -148,3 +148,47 @@ test('a danger button is white text on a deep red, at least 4.5:1 in every theme assert.ok(got >= 4.5, `${id} white on danger is ${got.toFixed(2)}`) } }) + +function decl(css, name) { + const m = css.match(new RegExp(`(?:^|\\n)\\t${name}: ([^;]+);`)) + return m ? m[1].trim() : null +} + +// Same 2% steps as darkenForTextOn, toward white. Used when the page is darker than the fill. +function lightenForTextOn(fill, bg) { + const src = rgb(fill) + for (let keep = 100; keep >= 0; keep -= 2) { + const cand = mixRgb(src, [255, 255, 255], keep) + if (contrastRatio(cand, bg) >= 4.5) return cand + } + return [255, 255, 255] +} + +test('status text tokens are at least 4.5:1 on the page, and stay the fill when that already passes (#498)', () => { + const rootStart = CSS.indexOf('\n:root,') + const root = CSS.slice(rootStart, CSS.indexOf('\n}', rootStart)) + for (const name of ['green', 'yellow', 'peach', 'red']) { + assert.equal(decl(root, `--${name}-text`), `var(--${name})`) + } + for (const id of ['horizon', 'mocha', 'tokyo', 'gruvbox', 'latte', 'linen', 'sky', 'omarchy']) { + const css = id === 'horizon' ? root : block(`[data-theme='${id}']`) + const bgHex = token(css, '--bg') + const bg = rgb(bgHex) + for (const name of ['green', 'yellow', 'peach', 'red']) { + const fill = token(css, `--${name}`) + assert.ok(fill, `${id} --${name}`) + const own = decl(css, `--${name}-text`) + const text = !own || own === `var(--${name})` ? fill : own + assert.match(text, /^#[0-9a-f]{6}$/, `${id} --${name}-text`) + const got = ratio(text, bgHex) + assert.ok(got >= 4.5, `${id} --${name}-text ${text} on ${bgHex} is ${got.toFixed(2)}`) + if (ratio(fill, bgHex) >= 4.5) { + assert.equal(text, fill, `${id} --${name}-text should stay the fill`) + } else { + const darkened = darkenForTextOn(fill, bg) + if (contrastRatio(rgb(darkened), bg) >= 4.5) assert.equal(text, darkened, `${id} --${name}-text`) + else assert.deepEqual(rgb(text), lightenForTextOn(fill, bg), `${id} --${name}-text`) + } + } + } +}) diff --git a/web/src/AppSheet.tsx b/web/src/AppSheet.tsx index f43b92eb..9252c5f1 100644 --- a/web/src/AppSheet.tsx +++ b/web/src/AppSheet.tsx @@ -184,7 +184,7 @@ export function AppSheet({app, update, onClose, onTerminal}: Props) { if (app.apiPort) rows.push(['Job API', `${boot.server!.host}:${app.apiPort}`]) rows.push(['Version', update ? `${app.version} → ${update.version}` : (app.version ?? '–')]) const webNow = app.state === 'running' ? webStatus(web.data) : null - if (webNow) rows.push(['Web page', {webNow.label}]) + if (webNow) rows.push(['Web page', {webNow.label}]) if (url) rows.push(['Address', {new URL(url).host}]) return ( diff --git a/web/src/screens/Files.tsx b/web/src/screens/Files.tsx index 17eb5c36..63e05f93 100644 --- a/web/src/screens/Files.tsx +++ b/web/src/screens/Files.tsx @@ -3472,7 +3472,7 @@ export function ShareSheet({ Password {sharePasswordLabel({ data: pw.data, isFetching: pw.isFetching, error: pw.error })} diff --git a/web/src/screens/Settings.tsx b/web/src/screens/Settings.tsx index bfac467e..6d298059 100644 --- a/web/src/screens/Settings.tsx +++ b/web/src/screens/Settings.tsx @@ -478,16 +478,16 @@ function CheckLine({check, busy}: {check: Pick <>
{live.status ? ( -

- {busy ? : } +

+ {busy ? : } {live.status}

) : null}
{live.alert ? ( -

- +

+ {live.alert}

) : null} diff --git a/web/src/styles.css b/web/src/styles.css index ea0da3d2..4e53e45e 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -47,6 +47,11 @@ --teal: #2dd4bf; --peach: #fb923c; --pink: #f472b6; + /* Word ink. The fills stay bright for dots, icons, charts, and buttons. */ + --green-text: var(--green); + --yellow-text: var(--yellow); + --peach-text: var(--peach); + --red-text: var(--red); --shadow: 0 18px 50px rgba(0, 0, 0, 0.45); --icon-shadow: 0 6px 16px rgba(0, 0, 0, 0.35); --text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45); @@ -117,6 +122,8 @@ --green: #b8bb26; --yellow: #fabd2f; --red: #fb4934; + /* #fb4934 is 4.29:1 here. Darkening it toward black loses contrast, so the words are one step lighter. */ + --red-text: #fb5440; --blue: #83a598; --mauve: #d3869b; --teal: #8ec07c; @@ -141,6 +148,9 @@ --green: #40a02b; --yellow: #df8e1d; --red: #d20f39; + --green-text: #327d22; + --yellow-text: #986114; + --peach-text: #bc4a08; --blue: #1e66f5; --mauve: #8839ef; --teal: #179299; @@ -168,6 +178,10 @@ --green: #3d8c3a; --yellow: #b8860b; --red: #c44536; + --green-text: #367b33; + --yellow-text: #8c6608; + --peach-text: #a55921; + --red-text: #c04435; --blue: #3d6fbf; --mauve: #8a5a9a; --teal: #2a8a84; @@ -195,6 +209,10 @@ --green: #2f8f6b; --yellow: #c4922a; --red: #d04555; + --green-text: #257053; + --yellow-text: #7d5d1b; + --peach-text: #945128; + --red-text: #af3a47; --blue: #3a6fbf; --mauve: #6d5bd0; --teal: #1f8a9a; @@ -762,11 +780,17 @@ html.desk-mode .group.screen-list { align-items: center; justify-content: center; gap: 4px; - color: var(--yellow); + color: var(--yellow-text); white-space: normal; line-height: 1.2; } +.gauge .sub.gauge-alert svg { + color: var(--yellow); +} .gauge .sub.gauge-alert.danger { + color: var(--red-text); +} +.gauge .sub.gauge-alert.danger svg { color: var(--red); } .facts { @@ -1963,7 +1987,7 @@ button.ap-open { padding-left: 4px; } .field .hint.field-error { - color: var(--red); + color: var(--red-text); } .field input[aria-invalid='true'] { border-color: var(--red); @@ -3910,7 +3934,7 @@ html.screen-locked .auth { background: color-mix(in oklab, var(--accent-text) 16%, transparent); } .transfer-count.failed { - color: var(--red); + color: var(--red-text); background: color-mix(in oklab, var(--red) 16%, transparent); } .transfer-row { @@ -4418,7 +4442,7 @@ button.nu-recent-row { text-overflow: ellipsis; } .drive-warn { - color: var(--peach) !important; + color: var(--peach-text) !important; font-size: 12.5px !important; font-weight: 560; margin-top: 1px; @@ -7547,7 +7571,7 @@ html:not(.desk-mode) .upload-panel { vertical-align: 1px; } .whats-new .tag.new { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-text, var(--accent)); } -.whats-new .tag.fix { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); } +.whats-new .tag.fix { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green-text); } .whats-new .btn.block { margin-top: 6px; } .update-error .main span, .update-error .main b { white-space: normal !important; } @@ -8100,7 +8124,7 @@ html.page-locked .auth { .mx-warn { margin: 0; font-size: 13px; - color: var(--yellow); + color: var(--yellow-text); } .mx-hr { border: 0; @@ -8226,14 +8250,14 @@ html.page-locked .auth { overflow-wrap: anywhere; } .st-running { - color: var(--green); + color: var(--green-text); } .st-error { - color: var(--red); + color: var(--red-text); } .st-suspended, .st-hibernated { - color: var(--yellow); + color: var(--yellow-text); } .mx-charts { display: grid; @@ -8347,11 +8371,11 @@ html.page-locked .auth { text-overflow: ellipsis; } .mx-tr.st-error .mx-status { - color: var(--red); + color: var(--red-text); white-space: normal; } .mx-tr.st-ok .mx-status { - color: var(--green); + color: var(--green-text); } .mx-tr-actions { display: flex; @@ -8971,7 +8995,7 @@ html.page-locked .auth { } .access-refused { margin: 4px 0 0; - color: var(--red); + color: var(--red-text); font-size: 13.5px; line-height: 1.45; } @@ -9032,7 +9056,7 @@ html.page-locked .auth { font: inherit; } .unused-err { - color: var(--red) !important; + color: var(--red-text) !important; } /* An app that's running but whose page doesn't answer (AppSheet). */ @@ -9096,9 +9120,12 @@ html.page-locked .auth { align-items: center; gap: 3px; font-size: 11.5px; - color: var(--green); + color: var(--green-text); flex: none; } +.plugin-verified svg { + color: var(--green); +} .plugin-body p { margin: 4px 0 0; font-size: 13.5px; @@ -9109,7 +9136,7 @@ html.page-locked .auth { overflow: hidden; } .plugin-body .plugin-error { - color: var(--red); + color: var(--red-text); -webkit-line-clamp: 4; } .plugin-actions { @@ -10124,7 +10151,7 @@ html.ac-paused .ac :is(.ac-body, .ac-shadow) { animation-play-state: paused !imp } .ac-say-row.problem .ac-say-open, .ac-say-row.problem .ac-say-text { - color: var(--red); + color: var(--red-text); } .ac-widget .ac-dot { position: absolute; @@ -10427,7 +10454,7 @@ select.field { line-height: 1.4; } .bk-err { - color: var(--red); + color: var(--red-text); } .bk-bar { height: 8px; @@ -12330,7 +12357,7 @@ input.temp-unit-box.fallback:checked { color: var(--muted); } .connect-timer.low { - color: var(--red); + color: var(--red-text); } .connect-pair-qr { display: flex; diff --git a/web/src/swarm/Swarm.tsx b/web/src/swarm/Swarm.tsx index 8e1175f8..fa722a2c 100644 --- a/web/src/swarm/Swarm.tsx +++ b/web/src/swarm/Swarm.tsx @@ -269,9 +269,9 @@ export function LocalSwarm({ {alerts.length > 0 && (
{alerts.slice(0, 4).map((al) => ( - ))}
diff --git a/web/src/ui.tsx b/web/src/ui.tsx index c81c8a37..34bdf631 100644 --- a/web/src/ui.tsx +++ b/web/src/ui.tsx @@ -86,11 +86,19 @@ const STATUS_COLOR: Record = { update: 'var(--yellow)', error: 'var(--red)', } +// The dot and the wash stay on the fill. The word uses the text token. +const STATUS_INK: Record = { + running: 'var(--green-text)', + stopped: 'var(--muted)', + busy: 'var(--blue)', + update: 'var(--yellow-text)', + error: 'var(--red-text)', +} export const statusColor = (kind: StatusKind) => STATUS_COLOR[kind] export function StatusPill({kind, label}: {kind: StatusKind; label: string}) { return ( - + {label}