Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion test/muted-text-contrast.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`)
}
}
}
})
2 changes: 1 addition & 1 deletion web/src/AppSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', <span key="web" style={{color: webNow.tone === 'bad' ? 'var(--red)' : webNow.tone === 'wait' ? 'var(--yellow)' : undefined}}>{webNow.label}</span>])
if (webNow) rows.push(['Web page', <span key="web" style={{color: webNow.tone === 'bad' ? 'var(--red-text)' : webNow.tone === 'wait' ? 'var(--yellow-text)' : undefined}}>{webNow.label}</span>])
if (url) rows.push(['Address', <a key="addr" href={url} style={{color: 'var(--accent-text)'}}>{new URL(url).host}</a>])

return (
Expand Down
2 changes: 1 addition & 1 deletion web/src/screens/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,7 @@ export function ShareSheet({
<span className="k">Password</span>
<span
className={!pw.data && pw.error && !pw.isFetching ? "v" : "v mono"}
style={{ fontSize: 12.5, ...(!pw.data && pw.error && !pw.isFetching ? { color: "var(--red)" } : {}) }}
style={{ fontSize: 12.5, ...(!pw.data && pw.error && !pw.isFetching ? { color: "var(--red-text)" } : {}) }}
>
{sharePasswordLabel({ data: pw.data, isFetching: pw.isFetching, error: pw.error })}
</span>
Expand Down
8 changes: 4 additions & 4 deletions web/src/screens/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,16 @@ function CheckLine({check, busy}: {check: Pick<AssistantCheck, 'ok' | 'message'>
<>
<div role="status" aria-live="polite" aria-atomic="true">
{live.status ? (
<p className="footer-note" style={busy ? style : {...style, color: 'var(--green)'}}>
{busy ? <span className="spinner" /> : <Icon name="check" size={15} />}
<p className="footer-note" style={busy ? style : {...style, color: 'var(--green-text)'}}>
{busy ? <span className="spinner" /> : <Icon name="check" size={15} style={{color: 'var(--green)'}} />}
{live.status}
</p>
) : null}
</div>
<div role="alert" aria-live="assertive" aria-atomic="true">
{live.alert ? (
<p className="footer-note" style={{...style, color: 'var(--red)'}}>
<Icon name="alert" size={15} />
<p className="footer-note" style={{...style, color: 'var(--red-text)'}}>
<Icon name="alert" size={15} style={{color: 'var(--red)'}} />
{live.alert}
</p>
) : null}
Expand Down
63 changes: 45 additions & 18 deletions web/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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). */
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -10427,7 +10454,7 @@ select.field {
line-height: 1.4;
}
.bk-err {
color: var(--red);
color: var(--red-text);
}
.bk-bar {
height: 8px;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions web/src/swarm/Swarm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ export function LocalSwarm({
{alerts.length > 0 && (
<div className="glass" role="status" style={{padding: '10px 14px', marginBottom: 12, display: 'grid', gap: 6}}>
{alerts.slice(0, 4).map((al) => (
<button key={al.id} type="button" onClick={() => setSelectedId(al.agentId)} style={{display: 'flex', alignItems: 'center', gap: 8, background: 'none', border: 0, padding: 0, color: al.severity === 'critical' ? 'var(--red)' : 'var(--yellow)', font: 'inherit', fontSize: 13, textAlign: 'left', cursor: 'pointer'}}>
<Icon name="alert" size={16} />
<span>{al.message}</span>
<button key={al.id} type="button" onClick={() => setSelectedId(al.agentId)} style={{display: 'flex', alignItems: 'center', gap: 8, background: 'none', border: 0, padding: 0, color: 'inherit', font: 'inherit', fontSize: 13, textAlign: 'left', cursor: 'pointer'}}>
<Icon name="alert" size={16} style={{color: al.severity === 'critical' ? 'var(--red)' : 'var(--yellow)', flex: 'none'}} />
<span style={{color: al.severity === 'critical' ? 'var(--red-text)' : 'var(--yellow-text)'}}>{al.message}</span>
</button>
))}
</div>
Expand Down
10 changes: 9 additions & 1 deletion web/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@ const STATUS_COLOR: Record<StatusKind, string> = {
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<StatusKind, string> = {
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 (
<span className={`pill${kind === 'busy' ? ' busy' : ''}`} style={{'--c': STATUS_COLOR[kind]} as CSSProperties}>
<span className={`pill${kind === 'busy' ? ' busy' : ''}`} style={{'--c': STATUS_COLOR[kind], color: STATUS_INK[kind]} as CSSProperties}>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status ink fails on tinted fills

Medium Severity

Status ink is darkened only until it clears 4.5:1 on the page. StatusPill, failed transfer counts, and the What's New fix tag then draw that ink on a translucent mix of the brighter fill, so the rendered contrast falls back under 4.5:1 on Daylight, Linen, and Sky.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 61e1446. Configure here.

<i />
{label}
</span>
Expand Down
Loading