feat(ui): high-contrast fallbacks, and a pseudo-locale that does not ship

UI-SPEC §8 says "tokens fall back to system colors" and the stylesheet set two
properties on `body`. Forced-colors does not *ignore* a palette — it overrides
the properties it knows about and leaves the rest, so every token still resolved
and still lost. Every `--color-*` is now rebound to a system keyword, which is
what makes the whole app follow rather than the handful of properties the UA
happens to force.

Two cases the UA cannot rescue on its own. **A tinted background carries meaning
here**: `bg-danger/20` is what distinguishes *Force latest* and *Remove anyway*
from Cancel, and it is erased — leaving a destructive button that looks like the
safe one. They get a border, which survives. **Selection is a background too**,
so a selected row flattens into every other row; an outline survives.
`--color-warn` and `--color-danger` both become `CanvasText` rather than
pretending to a distinction the mode does not have — the copy already says which
is which.

The pseudo-locale is I18N §5's clipping check. It appends rather than
substituting: `{{count}}` placeholders survive untouched, so nothing fails for a
reason unrelated to layout, and the string stays readable so a clipped button is
still identifiable. The closing `⟧` is the tell — if it is missing, the container
clipped.

Dev-only and not a supported locale: Settings never offers it, `resolveLocale`
never returns it, and the parity test never compares against it. Verified by
grepping a production build for it — zero occurrences.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5 committed 2026-08-09 21:46:25 +07:00
1 parent 9e26bee186
commit fbc93e32fa
3 files changed
+120 -1

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
/**
* The pseudo-locale — I18N §5, "to catch clipping".
*
* Vietnamese runs longer than English almost everywhere, and the place that shows is a button or a
* chip sized to its English label. A pseudo-locale makes that visible without waiting for a
* translator: every string grows ~40% and gains brackets, so a container that cannot hold it is
* obvious at a glance rather than on the one screen someone happened to open.
*
* **Dev-only, and not a supported locale.** It is registered under `import.meta.env.DEV` and left
* out of `SUPPORTED_LOCALES`, so Settings never offers it and no build ships it. `Ctrl+Alt+P`
* toggles it, keyed on `e.code` because AltGr layouts do not agree on `e.key`.
*/
/** Padding characters, chosen to be wide and obviously not English. */
const PAD = 'ẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍẍ'
/**
* Expand one string, bracketing it so a truncation is unmistakable.
*
* The original text is left **exactly** as it is and the padding is appended, rather than the
* letters being substituted the way some pseudo-locales do. Two reasons: `{{count}}` placeholders
* survive untouched, so nothing fails for a reason that has nothing to do with layout; and the
* string stays readable, so whoever is looking at a clipped button can still tell which one it is.
*
* The closing `⟧` is the tell. If it is missing, the container clipped.
*/
export function pseudoize(value: string): string {
const grow = Math.min(Math.ceil(value.length * 0.4), PAD.length)
return `⟦${value}${PAD.slice(0, grow)}⟧`
}
/** Recursively pseudoize a catalog. */
export function pseudoCatalog(node: unknown): unknown {
if (typeof node === 'string') return pseudoize(node)
if (typeof node !== 'object' || node === null) return node
return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, pseudoCatalog(v)]))
}
+28
View File
@@ -1,6 +1,8 @@
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import { pseudoCatalog } from './i18n.pseudo'
import enCommon from './locales/en/common.json'
import enErrors from './locales/en/errors.json'
import viCommon from './locales/vi/common.json'
@@ -47,6 +49,15 @@ export const resources = {
vi: { common: { ...viCommon, ...viErrors } },
} as const
/**
* I18N §5's pseudo-locale, in development only.
*
* Registered as a resource but deliberately **not** in `SUPPORTED_LOCALES`, so Settings never
* offers it, `resolveLocale` never returns it, and the i18n parity test never compares against it.
* `import.meta.env.DEV` keeps it out of a production bundle entirely.
*/
export const PSEUDO_LOCALE = 'en-XA'
void i18n.use(initReactI18next).init({
resources,
lng: resolveLocale(typeof navigator === 'undefined' ? undefined : navigator.language),
@@ -63,4 +74,21 @@ void i18n.use(initReactI18next).init({
},
})
if (import.meta.env.DEV) {
i18n.addResourceBundle(
PSEUDO_LOCALE,
'common',
pseudoCatalog(resources.en.common),
true,
true,
)
// `e.code`, not `e.key`: on an AltGr layout the character produced by Alt+P is not "p".
window.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.altKey && e.code === 'KeyP') {
e.preventDefault()
void i18n.changeLanguage(i18n.language === PSEUDO_LOCALE ? FALLBACK_LOCALE : PSEUDO_LOCALE)
}
})
}
export default i18n
+55 -1
View File
@@ -98,11 +98,65 @@
}
}
/* UI-SPEC §8: Windows high-contrast mode falls back to system colors. */
/* UI-SPEC §8: Windows high-contrast mode falls back to system colors.
*
* Forced-colors does not *ignore* the palette — it overrides the properties it knows about and
* leaves the rest, so a token still resolves and still loses. Rebinding every `--color-*` to a
* system keyword is what makes the whole app follow, rather than the handful of properties the
* UA happens to force.
*
* Two cases the UA cannot rescue on its own, both load-bearing:
*
* - **A tinted background carries no meaning here.** `bg-danger/20` on *Force latest* and on
* *Remove anyway* is erased, leaving them visually identical to Cancel — a destructive button
* that looks like the safe one. They get a border instead, which forced-colors keeps.
* - **Selection is a background too.** A selected row is `bg-surface-2`, which flattens into
* every other row; an outline survives.
*/
@media (forced-colors: active) {
:root {
--color-bg: Canvas;
--color-surface: Canvas;
--color-surface-2: Canvas;
--color-border: CanvasText;
--color-text: CanvasText;
--color-text-dim: GrayText;
--color-accent: LinkText;
--color-accent-dim: LinkText;
/* No system keyword means "warning" or "danger", so both take the one that means
* "this is not ordinary text" rather than pretending to a distinction the mode does not
* have. The copy already says which is which. */
--color-warn: CanvasText;
--color-danger: CanvasText;
--color-info: CanvasText;
}
body {
background-color: Canvas;
color: CanvasText;
}
/* The focus ring UI-SPEC §8 says is never removed. */
:focus-visible {
outline: 2px solid Highlight;
outline-offset: 2px;
}
/* A row's focus ring sits inside it, or the virtualizer's absolute positioning clips it. */
[role='row']:focus-visible {
outline-offset: -2px;
}
[aria-selected='true'],
[aria-current='true'] {
outline: 1px solid Highlight;
}
/* Destructive controls, which are otherwise indistinguishable once their tint is dropped. */
button[data-action='force'],
button[data-action='uninstall'],
button[data-action='rollback'] {
border: 2px solid CanvasText;
}
}
}