feat(web-svc-design): harden palette contrast, add frame tokens

The palette derives the link color and the four status colors against
all five surfaces (the three surface levels plus their hover and active
states) instead of the two content surfaces, and a status color also
reaches AA on its own subtle tint. The subtle and border tints of the
status colors move from a CSS color-mix into the palette, so both modes
carry them as plain values.

New tokens --design-frame, --design-on-frame, --design-frame-hover and
--design-frame-active give large brand surfaces such as a sidebar a deep
tone with AAA text in light and dark mode. The default focus outline
reads --design-focus and falls back to --design-link, so a frame can
keep its focus indicator visible.

The design lookup exposes the generated icon under urls.favicon_ico,
because a role may declare a slot named favicon. Slot names must be
kebab-case; a violation fails the lookup. resolve_branding returns a
bootstrap flag whose default false lives in web-svc-design.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-10-05 21:27:48 +02:00
1 parent 7c71a3ca00
commit eae1fb786a
8 files changed
+148 -24

No files matched your search

@@ -2,7 +2,7 @@ import tempfile
import unittest
from pathlib import Path
from utils.design.branding import is_disabled, resolve_branding
from utils.design.branding import asset_urls, is_disabled, resolve_branding
GLOBAL_SLOTS = {"icon": {"width": 512, "height": 512}}
@@ -31,6 +31,7 @@ class TestResolveBranding(unittest.TestCase):
design = {
"logo": "assets/logo.png",
"title": True,
"bootstrap": False,
"slots": GLOBAL_SLOTS,
**global_extra,
}
@@ -52,6 +53,25 @@ class TestResolveBranding(unittest.TestCase):
)
self.assertEqual(result["title"], "Platform")
def test_bootstrap_mapping_is_off_unless_a_role_or_the_platform_opts_in(
self,
) -> None:
self.assertFalse(
resolve_branding(self._apps({}, {}), "web-app-a", self.root)["bootstrap"]
)
self.assertTrue(
resolve_branding(
self._apps({}, {"bootstrap": True}), "web-app-a", self.root
)["bootstrap"]
)
self.assertFalse(
resolve_branding(
self._apps({"bootstrap": True}, {"bootstrap": False}),
"web-app-a",
self.root,
)["bootstrap"]
)
def test_role_override_wins_over_global(self) -> None:
apps = self._apps({"title": "Platform"}, {"title": "Own", "logo": "custom.png"})
result = resolve_branding(apps, "web-app-a", self.root)
@@ -112,6 +132,27 @@ class TestResolveBranding(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "positive"):
resolve_branding(apps, "web-app-a", self.root)
def test_slot_name_outside_kebab_case_fails_loudly(self) -> None:
for name in ("favicon_ico", "Logo", "wide.banner", ""):
with self.subTest(name=name):
apps = self._apps({}, {"slots": {name: {"width": 10, "height": 10}}})
with self.assertRaisesRegex(ValueError, "kebab-case"):
resolve_branding(apps, "web-app-a", self.root)
class TestAssetUrls(unittest.TestCase):
def test_a_slot_named_favicon_keeps_the_icon_url(self) -> None:
urls = asset_urls("https://cdn.test/design", {"favicon": {}, "logo": {}})
self.assertEqual(urls["favicon_ico"], "https://cdn.test/design/favicon.ico")
self.assertEqual(
urls["favicon"],
{
"png": "https://cdn.test/design/favicon.png",
"svg": "https://cdn.test/design/favicon.svg",
},
)
self.assertEqual(set(urls), {"favicon_ico", "favicon", "logo"})
class TestIsDisabled(unittest.TestCase):
def test_disabled_spellings(self) -> None:
+44 -2
View File
@@ -50,7 +50,9 @@ class TestPaletteContrast(unittest.TestCase):
self._assert_min(
t["--design-text-muted"], surfaces, CONTRAST_TEXT, "muted"
)
self._assert_min(t["--design-link"], content, CONTRAST_TEXT, "link")
self._assert_min(
t["--design-link"], surfaces, CONTRAST_TEXT, "link"
)
self._assert_min(
t["--design-primary"], content, CONTRAST_UI, "primary"
)
@@ -65,7 +67,12 @@ class TestPaletteContrast(unittest.TestCase):
)
for status in STATUS_HUES:
color = t[f"--design-{status}"]
self._assert_min(color, content, CONTRAST_TEXT, status)
self._assert_min(
color,
[*surfaces, t[f"--design-{status}-subtle"]],
CONTRAST_TEXT,
status,
)
self._assert_min(
t[f"--design-on-{status}"],
[color],
@@ -89,6 +96,10 @@ class TestPaletteContrast(unittest.TestCase):
self._assert_min(
t["--design-text-muted"], states, CONTRAST_TEXT, "muted"
)
for name in ("link", *STATUS_HUES):
self._assert_min(
t[f"--design-{name}"], states, CONTRAST_TEXT, name
)
for fill in ("primary", *STATUS_HUES):
self._assert_min(
t[f"--design-on-{fill}"],
@@ -97,6 +108,37 @@ class TestPaletteContrast(unittest.TestCase):
f"on-{fill}",
)
def test_frame_is_a_deep_brand_surface_in_both_modes(self) -> None:
for base in self.BASES:
palette = build_palette(base)
for mode in self.MODES:
with self.subTest(base=base, mode=mode):
t = palette[mode]
frame = t["--design-frame"]
self._assert_min(
t["--design-on-frame"],
[
frame,
t["--design-frame-hover"],
t["--design-frame-active"],
],
CONTRAST_BODY_TEXT,
"on-frame",
)
self.assertLess(
relative_luminance(frame),
relative_luminance(palette["light"]["--design-surface-3"]),
"the frame must stay darker than every light surface",
)
self.assertGreaterEqual(
contrast(frame, t["--design-surface-1"]),
1.2,
"the frame must stand out against the page",
)
def test_light_frame_keeps_a_deep_base_unchanged(self) -> None:
self.assertEqual(build_palette("#001f3f")["light"]["--design-frame"], "#001f3f")
def test_light_primary_keeps_a_compliant_base_unchanged(self) -> None:
self.assertEqual(
build_palette("#001f3f")["light"]["--design-primary"], "#001f3f"