diff --git a/CHANGELOG.md b/CHANGELOG.md index a36059b..dce6c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Added semantic link, code, disabled, font-size, and breakpoint tokens. - Expanded the example page and validation checks for the public API. - Added a generated public API manifest, breaking-change detection, release metadata validation, and isolated tarball consumer tests. +- Added forced-colors support with system-color mappings, non-color state cues, catalog guidance, and component-level Playwright regressions. ## 0.4.0 diff --git a/README.md b/README.md index 78033c1..14c0861 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Frost ist eine kleine CSS-Basis für persönliche Websites und Web-Apps. Sie bri Der interaktive [Komponentenkatalog](examples/index.html) zeigt die öffentliche Komponenten-API mit echten Live-Beispielen, kopierbarem HTML und konkreten Accessibility-Hinweisen. Suche und Theme-Wechsel funktionieren direkt im Browser; Dropdowns, Tabs, Accordions und Modals demonstrieren das erwartete Tastatur- und Fokusverhalten. -Die visuellen Regressionstests erzeugen für jede Komponentengruppe eigene Referenzbilder in heller und dunkler Darstellung sowie für Desktop- und Mobile-Viewports. Dadurch lässt sich eine Änderung einer konkreten Gruppe zuordnen, ohne eine vollständige Galerieseite vergleichen zu müssen. +Die visuellen Regressionstests erzeugen für jede Komponentengruppe eigene Referenzbilder in heller, dunkler und erzwungener Systemfarb-Darstellung sowie für Desktop- und Mobile-Viewports. Dadurch lässt sich eine Änderung einer konkreten Gruppe zuordnen, ohne eine vollständige Galerieseite vergleichen zu müssen. ## Einbinden @@ -160,6 +160,12 @@ oder: Frost braucht kein JavaScript. Ein Theme-Schalter kann später mit Iceberg oder ganz normalem Vanilla-JavaScript ergänzt werden. +Bei `forced-colors: active` hat das Betriebssystem Vorrang vor hellen, dunklen und benutzerdefinierten Themes. Frost bildet Flächen und Text auf `Canvas`/`CanvasText`, Controls auf `ButtonFace`/`ButtonText`, Links auf `LinkText`, Auswahl und Fokus auf `Highlight`/`HighlightText` sowie deaktivierte Inhalte auf `GrayText` ab. Fehler, Warnungen, Erfolg, Auswahl und aktive Zustände unterscheiden sich zusätzlich über Rahmenstil, Rahmenbreite oder Unterstreichung und sind damit nicht ausschließlich farbabhängig. + +Bei `prefers-contrast: more` ohne Forced Colors verstärkt Frost Control- und Flächenrahmen, Fokus, Auswahl und Validierungszustände und hebt gedämpften Text auf die normale Textfarbe an. Benutzerdefinierte Theme-Farben bleiben in diesem Modus erhalten. + +Eigene Erweiterungen sollten die automatische Anpassung bevorzugen. `forced-color-adjust: none` ist nur sinnvoll, wenn die Komponente anschließend vollständig mit Systemfarben definiert wird. Der [Komponentenkatalog](examples/index.html) zeigt die Palette und die erwarteten Zustände live. + Wenn ein Projekt weitere Themes braucht, sollten die semantischen Rollen von Frost überschrieben werden – nicht die Component-Selektoren: ```css @@ -281,7 +287,7 @@ npx playwright install chromium npm run test:browser ``` -Die Suite prüft Desktop- und Mobile-Ansichten, helle und dunkle Themes, Tastaturinteraktionen und WCAG-A/AA-Regeln. Absichtliche visuelle Änderungen aktualisieren die gespeicherten Referenzbilder mit: +Die Suite prüft Desktop- und Mobile-Ansichten, helle und dunkle Themes, Forced Colors, Tastaturinteraktionen und WCAG-A/AA-Regeln. Die Forced-Colors-Fälle kontrollieren zusätzlich Systemfarb-Mappings sowie sichtbare Fokus-, Fehler-, Auswahl- und Disabled-Zustände. Absichtliche visuelle Änderungen aktualisieren die gespeicherten Referenzbilder mit: ```bash npm run test:browser:update diff --git a/component-layer.css b/component-layer.css index 51b3213..9f04393 100644 --- a/component-layer.css +++ b/component-layer.css @@ -1,4 +1,4 @@ -@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.controls, frost.components; +@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.controls, frost.components, frost.forced-colors; @import url("./core.css"); @import url("./layout.css") layer(frost.layout); diff --git a/core.css b/core.css index fff58b8..7782060 100644 --- a/core.css +++ b/core.css @@ -1,5 +1,6 @@ -@layer frost.tokens, frost.base, frost.accessibility; +@layer frost.tokens, frost.base, frost.accessibility, frost.forced-colors; @import url("./tokens.css") layer(frost.tokens); @import url("./base.css") layer(frost.base); @import url("./accessibility.css") layer(frost.accessibility); +@import url("./forced-colors.css"); diff --git a/examples/catalog.css b/examples/catalog.css index 7ecc310..24f7412 100644 --- a/examples/catalog.css +++ b/examples/catalog.css @@ -126,6 +126,41 @@ .catalog-hero__meta { align-items: center; } + .catalog-contrast-guide { + display: grid; + grid-template-columns: minmax(0, 1.2fr) minmax(14rem, 0.8fr); + gap: var(--frost-space-5) var(--frost-space-8); + margin-block: var(--frost-space-8) 0; + border-color: color-mix(in srgb, var(--frost-color-accent) 42%, var(--frost-color-border)); + } + + .catalog-contrast-guide h2 { margin: 0 0 var(--frost-space-3); font-size: var(--frost-font-size-xl); } + .catalog-contrast-guide p:not(.catalog-eyebrow) { margin: 0; color: var(--frost-color-text-muted); } + .catalog-contrast-guide ul { grid-column: 1 / -1; display: grid; gap: var(--frost-space-2); margin: 0; padding-inline-start: var(--frost-space-5); color: var(--frost-color-text-muted); } + + .catalog-system-colors { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: var(--frost-space-2); + align-self: start; + } + + .catalog-system-color { + display: grid; + min-height: 3.5rem; + place-items: center; + padding: var(--frost-space-2); + border: 1px solid var(--frost-color-border-strong); + border-radius: var(--frost-radius-sm); + font-size: 0.75rem; + font-weight: 750; + } + + .catalog-system-color--canvas { background: var(--frost-color-surface); color: var(--frost-color-text); } + .catalog-system-color--text { background: var(--frost-color-text); color: var(--frost-color-bg); } + .catalog-system-color--button { background: var(--frost-color-surface-soft); color: var(--frost-color-text); } + .catalog-system-color--highlight { background: var(--frost-color-accent); color: var(--frost-color-on-accent); } + .catalog-empty { padding: var(--frost-space-8); border: 1px dashed var(--frost-color-border-strong); @@ -286,6 +321,7 @@ @media (max-width: 48rem) { .catalog-hero, + .catalog-contrast-guide, .catalog-component__header, .catalog-details { grid-template-columns: 1fr; } .catalog-hero__actions { justify-self: start; } @@ -293,4 +329,44 @@ .catalog-demo-grid { grid-template-columns: 1fr; } .catalog-component__header { padding: var(--frost-space-5); } } + + @media (forced-colors: active) { + .catalog-sidebar, + .catalog-hero, + .catalog-contrast-guide, + .catalog-component, + .catalog-component__header, + .catalog-code, + .catalog-code__toolbar, + .catalog-a11y { + border-color: CanvasText; + background: Canvas; + color: CanvasText; + box-shadow: none; + } + + .catalog-hero { background-image: none; } + .catalog-brand__mark { border: 1px solid Highlight; background: Highlight; color: HighlightText; forced-color-adjust: none; } + .catalog-eyebrow, + .catalog-hero__copy, + .catalog-sidebar__intro, + .catalog-nav__label, + .catalog-component__header p, + .catalog-live__label, + .catalog-a11y ul, + .catalog-contrast-guide p:not(.catalog-eyebrow), + .catalog-contrast-guide ul { color: CanvasText; } + .catalog-nav__link { color: LinkText; } + .catalog-nav__link:hover, + .catalog-nav__link:focus-visible { background: Highlight; color: HighlightText; forced-color-adjust: none; } + .catalog-live { background: Canvas; } + .catalog-copy { border-color: ButtonText; background: ButtonFace; color: ButtonText; forced-color-adjust: none; } + .catalog-copy:hover { background: Highlight; color: HighlightText; } + .catalog-code pre { background: Canvas; color: CanvasText; forced-color-adjust: none; } + .catalog-system-color { border-color: CanvasText; forced-color-adjust: none; } + .catalog-system-color--canvas { background: Canvas; color: CanvasText; } + .catalog-system-color--text { background: CanvasText; color: Canvas; } + .catalog-system-color--button { background: ButtonFace; color: ButtonText; } + .catalog-system-color--highlight { background: Highlight; color: HighlightText; } + } } diff --git a/examples/index.html b/examples/index.html index f10f9a1..b7cc2d9 100644 --- a/examples/index.html +++ b/examples/index.html @@ -103,6 +103,11 @@
HTML
+ diff --git a/frost.css b/frost.css index 243bf66..1e8ac98 100644 --- a/frost.css +++ b/frost.css @@ -1,4 +1,4 @@ -@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.controls, frost.components, frost.utilities; +@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.controls, frost.components, frost.utilities, frost.forced-colors; @import url("./core.css"); @import url("./layout.css") layer(frost.layout); diff --git a/package.json b/package.json index c9fcbba..71eeb4d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "./tokens.css": "./tokens.css", "./base.css": "./base.css", "./accessibility.css": "./accessibility.css", + "./forced-colors.css": "./forced-colors.css", "./layout.css": "./layout.css", "./controls.css": "./controls.css", "./components.css": "./components.css", @@ -23,6 +24,7 @@ "./components": "./components.css", "./utilities": "./utilities.css", "./tokens": "./tokens.css", + "./forced-colors": "./forced-colors.css", "./public-api.json": "./public-api.json", "./package.json": "./package.json" }, diff --git a/public-api.json b/public-api.json index f3af4ff..a9cf40d 100644 --- a/public-api.json +++ b/public-api.json @@ -569,7 +569,8 @@ "frost.layout", "frost.controls", "frost.components", - "frost.utilities" + "frost.utilities", + "frost.forced-colors" ], "exports": { ".": "./frost.css", @@ -583,6 +584,8 @@ "./controls.css": "./controls.css", "./core": "./core.css", "./core.css": "./core.css", + "./forced-colors": "./forced-colors.css", + "./forced-colors.css": "./forced-colors.css", "./frost.css": "./frost.css", "./layout.css": "./layout.css", "./package.json": "./package.json", diff --git a/scripts/build.mjs b/scripts/build.mjs index ce33fd7..5a1e22d 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -5,9 +5,9 @@ import { fileURLToPath } from "node:url"; const root = fileURLToPath(new URL("..", import.meta.url)); const output = resolve(root, "dist"); const layers = { - "frost.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css"], - "utility-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "utilities.css"], - "component-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css"], + "frost.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css", "forced-colors.css"], + "utility-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "utilities.css", "forced-colors.css"], + "component-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "forced-colors.css"], }; const minify = (source) => source diff --git a/scripts/check.mjs b/scripts/check.mjs index f53fc91..01ff50e 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -11,6 +11,7 @@ const cssFiles = [ "tokens.css", "base.css", "accessibility.css", + "forced-colors.css", "layout.css", "controls.css", "components.css", @@ -35,7 +36,7 @@ for (const match of entry.matchAll(/@import\s+url\("([^"]+)"\)/g)) { } const layerSources = { - "core.css": ["tokens.css", "base.css", "accessibility.css"], + "core.css": ["tokens.css", "base.css", "accessibility.css", "forced-colors.css"], "utility-layer.css": ["core.css", "layout.css", "utilities.css"], "component-layer.css": ["core.css", "layout.css", "controls.css", "components.css"], }; @@ -67,6 +68,9 @@ for (const exportPath of ["./utilities", "./components", "./tokens"]) { for (const exportPath of ["./core", "./utility-layer", "./component-layer"]) { if (!packageJson.exports[exportPath]) errors.push(`package.json: missing layer export ${exportPath}`); } +for (const exportPath of ["./forced-colors", "./forced-colors.css"]) { + if (!packageJson.exports[exportPath]) errors.push(`package.json: missing forced-colors export ${exportPath}`); +} if (errors.length) { console.error(errors.join("\n")); diff --git a/scripts/public-api.mjs b/scripts/public-api.mjs index cb5cb74..6bdfee5 100644 --- a/scripts/public-api.mjs +++ b/scripts/public-api.mjs @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url"; const root = fileURLToPath(new URL("..", import.meta.url)); const manifestPath = resolve(root, "public-api.json"); -const cssFiles = ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css"]; +const cssFiles = ["tokens.css", "base.css", "accessibility.css", "forced-colors.css", "layout.css", "controls.css", "components.css", "utilities.css"]; const sortLexically = (values) => [...values].sort((left, right) => left < right ? -1 : left > right ? 1 : 0); const packageJson = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")); diff --git a/scripts/size.mjs b/scripts/size.mjs index 2181631..c07d983 100644 --- a/scripts/size.mjs +++ b/scripts/size.mjs @@ -4,7 +4,7 @@ import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; const root = fileURLToPath(new URL("..", import.meta.url)); -const files = ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css"]; +const files = ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css", "forced-colors.css"]; const source = (await Promise.all(files.map((file) => readFile(resolve(root, file), "utf8")))).join("\n"); const rawBytes = Buffer.byteLength(source); const gzipBytes = gzipSync(source).byteLength; diff --git a/tests/browser/example.spec.mjs b/tests/browser/example.spec.mjs index be6b62c..8b3d7c3 100644 --- a/tests/browser/example.spec.mjs +++ b/tests/browser/example.spec.mjs @@ -20,6 +20,7 @@ test.beforeEach(async ({ page }) => { }); const visualCases = [ + { id: "contrast-guide", name: "forced-colors guidance", target: ".catalog-contrast-guide" }, { id: "buttons", name: "buttons" }, { id: "forms", name: "form controls" }, { id: "surfaces", name: "surfaces and badges" }, @@ -47,6 +48,14 @@ for (const visualCase of visualCases) { await expect(target).toHaveScreenshot(`component-${visualCase.id}-${theme}.png`); } }); + + test(`${visualCase.name} matches its forced-colors baseline`, async ({ page }) => { + await page.emulateMedia({ colorScheme: "light", forcedColors: "active" }); + await page.addStyleTag({ content: ".frost-skip-link { display: none !important; }" }); + await visualCase.prepare?.(page); + const target = page.locator(visualCase.target ?? `#${visualCase.id}`); + await expect(target).toHaveScreenshot(`component-${visualCase.id}-forced-colors.png`); + }); } for (const theme of ["light", "dark"]) { @@ -139,3 +148,75 @@ test("modal restores focus to its trigger after closing", async ({ page }) => { await expect(trigger).toBeFocused(); }); +test("forced colors preserves system mappings and non-color state cues", async ({ page }) => { + await page.emulateMedia({ colorScheme: "light", forcedColors: "active" }); + + const primary = page.locator("#buttons .frost-button--primary").first(); + const disabled = page.locator("#buttons .frost-button:disabled"); + const invalid = page.locator("#forms [aria-invalid='true']"); + const selectedTab = page.locator("#disclosure [role='tab'][aria-selected='true']"); + + await primary.focus(); + await expect(primary).toBeFocused(); + + const states = await page.evaluate(() => { + const style = (selector) => getComputedStyle(document.querySelector(selector)); + const primaryStyle = style("#buttons .frost-button--primary"); + const disabledStyle = style("#buttons .frost-button:disabled"); + const invalidStyle = style("#forms [aria-invalid='true']"); + const selectedStyle = style("#disclosure [role='tab'][aria-selected='true']"); + const interactiveCardStyle = style("#surfaces .frost-card--interactive"); + return { + primary: { + forcedColorAdjust: primaryStyle.forcedColorAdjust, + outlineStyle: primaryStyle.outlineStyle, + outlineWidth: Number.parseFloat(primaryStyle.outlineWidth), + }, + disabled: { opacity: disabledStyle.opacity }, + invalid: { borderStyle: invalidStyle.borderStyle, borderWidth: Number.parseFloat(invalidStyle.borderWidth) }, + selected: { borderStyle: selectedStyle.borderBottomStyle, borderWidth: Number.parseFloat(selectedStyle.borderBottomWidth) }, + card: { boxShadow: interactiveCardStyle.boxShadow }, + }; + }); + + expect(states.primary.forcedColorAdjust).toBe("none"); + expect(states.primary.outlineStyle).toBe("solid"); + expect(states.primary.outlineWidth).toBeGreaterThanOrEqual(3); + expect(states.disabled.opacity).toBe("1"); + expect(states.invalid.borderStyle).toBe("dashed"); + expect(states.invalid.borderWidth).toBeGreaterThanOrEqual(2); + expect(states.selected.borderStyle).toBe("solid"); + expect(states.selected.borderWidth).toBeGreaterThanOrEqual(3); + expect(states.card.boxShadow).toBe("none"); + + await expect(disabled).toBeDisabled(); + await expect(invalid).toHaveAttribute("aria-invalid", "true"); + await expect(selectedTab).toHaveAttribute("aria-selected", "true"); +}); + +test("increased contrast strengthens component boundaries and states", async ({ page }) => { + await page.emulateMedia({ colorScheme: "light", contrast: "more", forcedColors: "none" }); + + const states = await page.evaluate(() => { + const style = (selector) => getComputedStyle(document.querySelector(selector)); + const buttonStyle = style("#buttons .frost-button--primary"); + const disabledStyle = style("#buttons .frost-button:disabled"); + const invalidStyle = style("#forms [aria-invalid='true']"); + const cardStyle = style("#surfaces .frost-card"); + const selectedStyle = style("#disclosure [role='tab'][aria-selected='true']"); + return { + buttonBorderWidth: Number.parseFloat(buttonStyle.borderWidth), + disabled: { borderStyle: disabledStyle.borderStyle, opacity: disabledStyle.opacity }, + invalidBorderStyle: invalidStyle.borderStyle, + cardBorderWidth: Number.parseFloat(cardStyle.borderWidth), + selectedBorderWidth: Number.parseFloat(selectedStyle.borderBottomWidth), + }; + }); + + expect(states.buttonBorderWidth).toBeGreaterThanOrEqual(2); + expect(states.disabled).toEqual({ borderStyle: "dotted", opacity: "1" }); + expect(states.invalidBorderStyle).toBe("dashed"); + expect(states.cardBorderWidth).toBeGreaterThanOrEqual(2); + expect(states.selectedBorderWidth).toBeGreaterThanOrEqual(3); +}); + diff --git a/utility-layer.css b/utility-layer.css index e203885..ae35ba9 100644 --- a/utility-layer.css +++ b/utility-layer.css @@ -1,4 +1,4 @@ -@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.utilities; +@layer frost.tokens, frost.base, frost.accessibility, frost.layout, frost.utilities, frost.forced-colors; @import url("./core.css"); @import url("./layout.css") layer(frost.layout);