oficina / base Public

Keep both themes whole without light-dark(); darker focus ring, tints

light-dark() is missing before Safari 17.5, and there every token that
used it was invalid, so pages lost their colours. :root now holds each
token's dark value plainly; :root[data-theme="light"] holds the light
values plainly, so choosing Light works in any browser; the light-dark()
pairs, color-scheme: light dark and following the device live inside
@supports (color: light-dark(white, black)). A look test keeps the
three in step, and a browser test drops what an old browser would and
finds every element drawn as a current browser draws dark (System on a
light device), Light and Dark.

The focus ring has its own token, a deeper teal in the light (#0A6E66,
4:1 or more on the sky and glass where #0FA89C was 2-2.8:1); dark keeps
#6EE7DC. The light tile tints are deeper so their white icons reach 3:1
(3.4-4.2:1, from 2.0-2.9:1). The light-mode test now measures the focus
ring and every tint's icon too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 089edac0f2330da5d5c1202420608923e8cf3006 parent 9a8ea76
3 files changed, +471 −127
  • internal/browsertest/light_test.go +188 −22
  • internal/look/static/app.css +197 −86
  • internal/look/theme_test.go +86 −19
diff --git a/internal/browsertest/light_test.go b/internal/browsertest/light_test.go
index 894ac05..b333734 100644
--- a/internal/browsertest/light_test.go
+++ b/internal/browsertest/light_test.go
@@ -23,6 +23,7 @@ import (
"amadan.net/rastrillo/rastrillo/harness"
"amadan.net/carlos/base/internal/config"
+ "amadan.net/carlos/base/internal/store"
)
// prefersScheme emulates the device's light or dark setting.
@@ -74,30 +75,49 @@ func luminance(r, g, b float64) float64 {
// that element needs (3 for large text).
func textContrast(t *testing.T, rig *harness.Rig, sel string) (worst, need float64, where string) {
t.Helper()
- drive(t, rig, chromedp.Evaluate[chromedp.Void](`(() => { const s = document.createElement("style"); s.id = "contrast-pause";
- s.textContent = "*, *::before, *::after { animation-play-state: paused !important; transition: none !important; caret-color: transparent !important; }";
- document.head.append(s); })()`), chromedp.Sleep(100*time.Millisecond))
+ return contrastOf(t, rig, sel, "color", 0)
+}
+
+// pauseJS stops the page's animations and transitions (a constructed
+// stylesheet, which the page's CSP allows), so two screenshots differ only
+// in what a check changes.
+const pauseJS = `(() => { const s = new CSSStyleSheet();
+ s.replaceSync("*, *::before, *::after { animation-play-state: paused !important; transition: none !important; caret-color: transparent !important; }");
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, s]; window.__pause = s; })()`
+
+const unpauseJS = `document.adoptedStyleSheets = document.adoptedStyleSheets.filter(s => s !== window.__pause)`
+
+// contrastOf is textContrast for any colour an element draws: prop is the
+// CSS property (color, stroke, outline-color) it hides to find the pixels
+// that colour paints. need 0 means text: 4.5, or 3 when large; anything
+// else (an icon, a focus ring) needs what it is given.
+func contrastOf(t *testing.T, rig *harness.Rig, sel, prop string, minimum float64) (worst, need float64, where string) {
+ t.Helper()
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](pauseJS), chromedp.Sleep(100*time.Millisecond))
with := harness.Read(rig, chromedp.CaptureScreenshot())
var boxes []textBox
- if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, `((sel) => {
+ if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, `((sel, prop) => {
const out = [];
for (const e of document.querySelectorAll(sel)) {
- const r = e.getBoundingClientRect();
- if (!e.checkVisibility() || !e.textContent.trim() || r.bottom <= 0 || r.top >= innerHeight || r.width === 0) continue;
+ let r = e.getBoundingClientRect();
+ if (!e.checkVisibility() || (prop === "color" && !e.textContent.trim()) || r.bottom <= 0 || r.top >= innerHeight || r.width === 0) continue;
const s = getComputedStyle(e);
- out.push({Label: e.textContent.trim().slice(0, 30), X: r.left, Y: r.top, W: r.width, H: r.height,
- Size: parseFloat(s.fontSize) * (parseInt(s.fontWeight) >= 700 ? 1.33 : 1), Color: s.color});
+ if (prop === "outline-color") { // the ring lies outside the box
+ const o = parseFloat(s.outlineOffset) + parseFloat(s.outlineWidth) + 2;
+ r = {left: r.left - o, top: r.top - o, width: r.width + 2 * o, height: r.height + 2 * o};
+ }
+ out.push({Label: (e.textContent.trim() || e.closest("a,button")?.textContent.trim() || sel).slice(0, 30), X: r.left, Y: r.top, W: r.width, H: r.height,
+ Size: parseFloat(s.fontSize) * (parseInt(s.fontWeight) >= 700 ? 1.33 : 1), Color: s.getPropertyValue(prop)});
e.dataset.contrast = "1";
- e.style.setProperty("color", "transparent", "important");
+ e.style.setProperty(prop, "transparent", "important");
}
return JSON.stringify(out);
- })(`+strconv.Quote(sel)+`)`)), &boxes); err != nil {
+ })(`+strconv.Quote(sel)+`, `+strconv.Quote(prop)+`)`)), &boxes); err != nil {
t.Fatal(err)
}
without := harness.Read(rig, chromedp.CaptureScreenshot())
dpr := harness.Evaluate[float64](rig, `window.devicePixelRatio`)
- drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.querySelectorAll("[data-contrast]").forEach(e => { e.style.removeProperty("color"); delete e.dataset.contrast; }),
- document.getElementById("contrast-pause").remove()`))
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.querySelectorAll("[data-contrast]").forEach(e => { e.style.removeProperty(`+strconv.Quote(prop)+`); delete e.dataset.contrast; }), `+unpauseJS))
if len(boxes) == 0 {
t.Fatalf("nothing on screen matches %s", sel)
}
@@ -110,6 +130,7 @@ func textContrast(t *testing.T, rig *harness.Rig, sel string) (worst, need float
t.Fatal(err)
}
worst, need = math.Inf(1), 4.5
+ measured := 0
for _, box := range boxes {
m := rgbRE.FindStringSubmatch(box.Color)
if m == nil {
@@ -120,8 +141,8 @@ func textContrast(t *testing.T, rig *harness.Rig, sel string) (worst, need float
bl, _ := strconv.ParseFloat(m[3], 64)
fg := luminance(r, g, bl)
lo, glyphs := math.Inf(1), 0
- for y := int(box.Y * dpr); y < int((box.Y+box.H)*dpr); y++ {
- for x := int(box.X * dpr); x < int((box.X+box.W)*dpr); x++ {
+ for y := max(0, int(box.Y*dpr)); y < int((box.Y+box.H)*dpr); y++ {
+ for x := max(0, int(box.X*dpr)); x < int((box.X+box.W)*dpr); x++ {
ar, ag, ab, _ := a.At(x, y).RGBA()
br, bg, bb, _ := b.At(x, y).RGBA()
if diff(ar, br)+diff(ag, bg)+diff(ab, bb) < 48 {
@@ -133,16 +154,23 @@ func textContrast(t *testing.T, rig *harness.Rig, sel string) (worst, need float
}
}
if glyphs == 0 {
- t.Fatalf("%s %q: no glyphs found", sel, box.Label)
+ continue // below the fold, or drawn the same either way
}
- n := 4.5
- if box.Size >= 24 {
- n = 3
+ measured++
+ n := minimum
+ if n == 0 {
+ n = 4.5
+ if box.Size >= 24 {
+ n = 3
+ }
}
if lo/n < worst/need {
worst, need, where = lo, n, box.Label
}
}
+ if measured == 0 {
+ t.Fatalf("%s: nothing drawn in %s", sel, prop)
+ }
return worst, need, where
}
@@ -173,6 +201,37 @@ func checkContrast(t *testing.T, rig *harness.Rig, when string, sels ...string)
}
}
+// focusRing tabs until focus is on the first element matching sel and holds
+// its focus ring to 3:1 against what lies behind it.
+func focusRing(t *testing.T, rig *harness.Rig, when, sel string) {
+ t.Helper()
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.activeElement.blur()`))
+ for range 40 {
+ drive(t, rig, chromedp.KeyEvent("\t"))
+ if harness.Evaluate[bool](rig, `document.activeElement.matches(`+strconv.Quote(sel)+`)`) {
+ break
+ }
+ }
+ if !harness.Evaluate[bool](rig, `document.activeElement.matches(`+strconv.Quote(sel)+`) && document.activeElement.matches(":focus-visible")`) {
+ t.Fatalf("%s: the keyboard never reached %s", when, sel)
+ }
+ worst, need, where := contrastOf(t, rig, ":focus-visible", "outline-color", 3)
+ t.Logf("%s: focus ring on %s %.2f (%q)", when, sel, worst, where)
+ if worst < need {
+ t.Errorf("%s: the focus ring on %s %q has contrast %.2f, needs %.1f", when, sel, where, worst, need)
+ }
+}
+
+// iconContrast holds the tiles' line icons to 3:1 against their tint.
+func iconContrast(t *testing.T, rig *harness.Rig, when, sel string) {
+ t.Helper()
+ worst, need, where := contrastOf(t, rig, sel, "stroke", 3)
+ t.Logf("%s: icons %s worst %.2f (%q)", when, sel, worst, where)
+ if worst < need {
+ t.Errorf("%s: the icon in %q has contrast %.2f, needs %.1f", when, where, worst, need)
+ }
+}
+
// textColour is el's computed colour.
func textColour(rig *harness.Rig, sel string) string {
return harness.Evaluate[string](rig, `getComputedStyle(document.querySelector(`+strconv.Quote(sel)+`)).color`)
@@ -187,7 +246,16 @@ const (
// one in Settings; light mode's text passes AA over the moving fog.
func TestLightMode(t *testing.T) {
apps := teamApps(t)
- rig, _, _ := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
+ rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
+ // Welcome and Scratchpad installed, so every tile tint is on Home.
+ for _, app := range []string{"welcome", "scratchpad"} {
+ if _, err := store.ClaimInstall(context.Background(), b.db, app, "acme-"+app+".test"); err != nil {
+ t.Fatal(err)
+ }
+ if err := store.SetInstallState(context.Background(), b.db, app, "installed", ""); err != nil {
+ t.Fatal(err)
+ }
+ }
home := func() {
t.Helper()
drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
@@ -210,6 +278,12 @@ func TestLightMode(t *testing.T) {
// rail's labels.
checkContrast(t, rig, "Home, light", ".hello", ".lede", ".team", ".steps li", "a.ask", "nav.rail a.rail-app span", ".dock a.app")
lightShot(t, rig, "home-desktop")
+ for _, tint := range []string{"teal", "violet", "mist", "amber", "rose"} {
+ iconContrast(t, rig, "Home, light", ".dock .tile.t-"+tint+" svg")
+ }
+ for _, sel := range []string{"a.ask", "a.me", "nav.rail a.rail-app", ".dock a.app"} {
+ focusRing(t, rig, "Home, light", sel)
+ }
// The panel mid-conversation: both bubbles, the header and status.
drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)),
@@ -233,6 +307,9 @@ func TestLightMode(t *testing.T) {
drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/settings"), chromedp.WaitVisible(chromedp.CSS(`form.segmented`)))
checkContrast(t, rig, "Settings, light", ".sheet h2", ".people .who", ".people .who small", ".soon", "form.segmented button")
lightShot(t, rig, "settings")
+ for _, sel := range []string{"a.wordmark", "form.segmented button", ".people .btn.ghost"} {
+ focusRing(t, rig, "Settings, light", sel)
+ }
// A phone.
drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)))
@@ -255,9 +332,13 @@ func TestLightMode(t *testing.T) {
for _, c := range []struct{ choice, device, want string }{
{"light", "dark", lightInk}, {"dark", "light", darkInk}, {"system", "light", lightInk}, {"system", "dark", darkInk},
} {
- drive(t, rig, prefersScheme(c.device), chromedp.Navigate(rig.Origin+"/settings"), chromedp.WaitVisible(chromedp.CSS(`form.segmented`)),
- chromedp.Click(chromedp.CSS(fmt.Sprintf(`form.segmented button[value=%q]`, c.choice))),
- chromedp.WaitVisible(chromedp.CSS(fmt.Sprintf(`form.segmented button[value=%q][aria-pressed="true"]`, c.choice))))
+ pressed := fmt.Sprintf(`form.segmented button[value=%q][aria-pressed="true"]`, c.choice)
+ drive(t, rig, prefersScheme(c.device), chromedp.Navigate(rig.Origin+"/settings"), chromedp.WaitVisible(chromedp.CSS(`form.segmented`)))
+ // Already chosen (System twice running), there is nothing to submit.
+ if !harness.Evaluate[bool](rig, `!!document.querySelector(`+strconv.Quote(pressed)+`)`) {
+ drive(t, rig, chromedp.Click(chromedp.CSS(fmt.Sprintf(`form.segmented button[value=%q]`, c.choice))),
+ chromedp.WaitVisible(chromedp.CSS(pressed)))
+ }
home()
if got := textColour(rig, ".hello"); got != c.want {
t.Errorf("scripts off %v: %s on a %s device draws Home's text %s, want %s", off, c.choice, c.device, got, c.want)
@@ -269,3 +350,88 @@ func TestLightMode(t *testing.T) {
t.Logf("light screenshots in %s", filepath.Clean(dir))
}
}
+
+// snapshotJS records every colour each element (and the wordmark's mark)
+// is drawn in, with transitions off so none is caught midway.
+const snapshotJS = `(() => {
+ const props = ["color", "background-color", "background-image", "border-top-color", "box-shadow", "outline-color", "stroke", "color-scheme"];
+ const out = [];
+ for (const e of [document.documentElement, ...document.querySelectorAll("body, body *")]) {
+ const s = getComputedStyle(e);
+ out.push(e.tagName + "." + e.className + " " + props.map(p => s.getPropertyValue(p)).join(" | "));
+ }
+ const w = document.querySelector(".wordmark");
+ if (w) out.push("wordmark::before " + getComputedStyle(w, "::before").backgroundImage);
+ return JSON.stringify(out);
+})()`
+
+// oldBrowserJS swaps the stylesheet for what a browser without
+// light-dark() makes of it (Safari before 17.5): the @supports block is
+// dropped, and so is any token whose value uses light-dark().
+const oldBrowserJS = `(async () => {
+ const link = document.querySelector('link[rel="stylesheet"]');
+ let css = await (await fetch(link.href)).text();
+ const head = "@supports (color: light-dark(white, black)) {";
+ for (let i; (i = css.indexOf(head)) >= 0;) {
+ let d = 0, j = i + head.length - 1;
+ for (; j < css.length; j++) { if (css[j] === "{") d++; else if (css[j] === "}" && --d === 0) break; }
+ css = css.slice(0, i) + css.slice(j + 1);
+ }
+ css = css.replace(/--[\w-]+:\s*light-dark\([^;]*;/g, "");
+ const s = new CSSStyleSheet();
+ s.replaceSync(css);
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, s];
+ link.disabled = true;
+ return true;
+})()`
+
+// A browser without light-dark() draws Base in its dark theme, every colour
+// intact, even on a light device; a member who chose Light gets it there
+// too. Each is held to what a current browser draws for that theme.
+func TestThemesWithoutLightDark(t *testing.T) {
+ apps := teamApps(t)
+ rig, _, _ := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
+ drive(t, rig, prefersScheme("light"))
+ for _, page := range []struct{ path, wait string }{{"/", ".hello"}, {"/settings", "form.segmented"}} {
+ snap := func(theme string, old bool) []string {
+ t.Helper()
+ drive(t, rig, chromedp.Navigate(rig.Origin+page.path), chromedp.WaitVisible(chromedp.CSS(page.wait)),
+ chromedp.Evaluate[chromedp.Void](pauseJS))
+ if theme != "" {
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.documentElement.dataset.theme = `+strconv.Quote(theme)))
+ }
+ if old {
+ drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := chromedp.Evaluate[bool](oldBrowserJS, chromedp.EvalAwaitPromise)(ctx, target)
+ return err
+ }))
+ }
+ var out []string
+ if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, snapshotJS)), &out); err != nil {
+ t.Fatal(err)
+ }
+ return out
+ }
+ for _, c := range []struct{ name, want, old string }{
+ {"System on a light device", "dark", ""},
+ {"Light chosen", "light", "light"},
+ {"Dark chosen", "dark", "dark"},
+ } {
+ want, got := snap(c.want, false), snap(c.old, true)
+ if len(want) != len(got) {
+ t.Fatalf("%s %s: %d elements, want %d", page.path, c.name, len(got), len(want))
+ }
+ bad := 0
+ for i := range want {
+ if want[i] != got[i] {
+ if bad++; bad <= 5 {
+ t.Errorf("%s, %s, without light-dark():\n got %s\n want %s", page.path, c.name, got[i], want[i])
+ }
+ }
+ }
+ if bad > 5 {
+ t.Errorf("%s, %s: %d elements differ in all", page.path, c.name, bad)
+ }
+ }
+ }
+}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index 631d781..e37139c 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -7,113 +7,224 @@
@font-face { font-family: "DM Sans"; src: url(fonts/dm-sans/4.004/DMSans-VF.woff2) format("woff2");
font-weight: 400 700; font-style: normal; font-display: swap;
size-adjust: 98%; ascent-override: 98.3%; descent-override: 25.3%; line-gap-override: 0%; }
-/* Colours. One set of tokens drives both themes: each is light-dark(light,
- dark), resolved by color-scheme, which follows the device's setting
- unless the member's Appearance holds one (data-theme on <html>, drawn by
- the server, so there is no flash and no script). Every colour in this
- file is a token here; internal/look's TestStylesheetThemes holds it so. */
+/* Colours. One set of tokens drives both themes, in three places that
+ internal/look's TestStylesheetThemes keeps in step:
+ - :root holds every token's dark value, plainly. A browser without
+ light-dark() (Safari before 17.5) gets the dark theme whole.
+ - :root[data-theme="light"] holds the light values plainly, so a member
+ who chose Light (data-theme on <html>, drawn by the server: no flash,
+ no script) gets it in any browser.
+ - Where light-dark() works, @supports pairs each token with its light
+ value and lets color-scheme follow the device until the member's
+ Appearance holds one.
+ Every colour in this file is a token here. */
:root {
- color-scheme: light dark;
+ color-scheme: dark;
--lagoon: #2FC6C0; /* teal light */
--orchid: #8B5CF6; /* violet light */
--ember: #FFB066; /* warm light */
--rose: #F472B6; /* rose light */
--mist: #C9D3E3; /* pale fog */
- --frost: light-dark(#1E2440, #EEF2F8); /* text */
- --haze: light-dark(#4A5275, #DDE3F0); /* secondary text */
- --signal: light-dark(#0FA89C, #6EE7DC); /* accent: focus, finished steps, progress */
- --on-signal: light-dark(#FFFFFF, #1E2738);
+ --frost: #EEF2F8; /* text */
+ --haze: #DDE3F0; /* secondary text */
+ --signal: #6EE7DC; /* accent: focus, finished steps, progress */
+ --focus: #6EE7DC; /* the focus ring: a deeper teal in the light, 3:1 on the sky and glass */
+ --on-signal: #1E2738;
--ink: #1E2738; /* text on the bright fills (the avatar, a member's face, installing) */
--font: "Timeless Sans", "DM Sans", system-ui, sans-serif;
/* The atmosphere: the sky, the beams of light and the banks of fog. */
- --sky: light-dark(#DDE1F3, #1A1F45);
- --sky-1: light-dark(#F4F5FC, #2C3470);
- --sky-2: light-dark(#E8EAF7, #1A1F45);
- --sky-3: light-dark(#DDE1F3, #16193A);
+ --sky: #1A1F45;
+ --sky-1: #2C3470;
+ --sky-2: #1A1F45;
+ --sky-3: #16193A;
--sky-stop: 62%;
- --beam-1: light-dark(rgba(255,214,170,.55), rgba(255,214,170,.42));
- --beam-2: light-dark(rgba(255,190,140,.18), rgba(255,176,102,.12));
- --beam-3: light-dark(rgba(255,190,140,0), rgba(255,176,102,0));
+ --beam-1: rgba(255,214,170,.42);
+ --beam-2: rgba(255,176,102,.12);
+ --beam-3: rgba(255,176,102,0);
--shine-1: rgba(238,242,248,.26);
--shine-2: rgba(238,242,248,0);
- --fog-4: light-dark(#FFFFFF, #C9D3E3); /* the mist bank: white in the light */
+ --fog-4: #C9D3E3; /* the mist bank: white in the light */
--fog-1-a: .5; --fog-2-a: .55; --fog-3-a: .32; --fog-4-a: .14;
/* Glass: dark-tinted in the dark, white frost in the light. */
- --glass-1: light-dark(rgba(255,255,255,.62), rgba(238,242,248,.07));
- --glass-2: light-dark(rgba(255,255,255,.42), rgba(238,242,248,.03));
- --glass-base: light-dark(rgba(255,255,255,0), rgba(14,17,42,.40));
- --glass-edge: light-dark(rgba(255,255,255,.75), rgba(238,242,248,.18));
- --glass-shine: light-dark(rgba(255,255,255,.95), rgba(255,255,255,.22));
- --glass-shadow: light-dark(rgba(40,46,90,.35), rgba(8,12,22,.6));
+ --glass-1: rgba(238,242,248,.07);
+ --glass-2: rgba(238,242,248,.03);
+ --glass-base: rgba(14,17,42,.40);
+ --glass-edge: rgba(238,242,248,.18);
+ --glass-shine: rgba(255,255,255,.22);
+ --glass-shadow: rgba(8,12,22,.6);
--glass-lift: -20px;
- --mark-1: light-dark(#2A3156, #FFFFFF);
- --mark-2: light-dark(#6B73A8, rgba(238,242,248,.35));
- --mark-edge: light-dark(rgba(255,255,255,0), rgba(255,255,255,.5));
+ --mark-1: #FFFFFF;
+ --mark-2: rgba(238,242,248,.35);
+ --mark-edge: rgba(255,255,255,.5);
/* Controls. */
- --btn: light-dark(#1E2440, #EEF2F8);
- --btn-ink: light-dark(#FFFFFF, #1E2738);
- --ghost: light-dark(rgba(30,36,64,.06), rgba(238,242,248,.1));
- --ghost-edge: light-dark(rgba(30,36,64,.18), rgba(238,242,248,.22));
- --danger: light-dark(#F6D3D6, #F3C6C9);
+ --btn: #EEF2F8;
+ --btn-ink: #1E2738;
+ --ghost: rgba(238,242,248,.1);
+ --ghost-edge: rgba(238,242,248,.22);
+ --danger: #F3C6C9;
--danger-ink: #5B1820;
- --field: light-dark(rgba(255,255,255,.75), rgba(10,16,28,.28));
- --field-edge: light-dark(rgba(30,36,64,.16), rgba(238,242,248,.22));
- --placeholder: light-dark(#5A6285, #DDE3F0);
- --well: light-dark(rgba(255,255,255,.6), rgba(10,16,28,.25));
- --well-edge: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.14));
- --well-ring: light-dark(rgba(30,36,64,.14), rgba(238,242,248,.18));
- --well-hover: light-dark(rgba(255,255,255,.85), rgba(10,16,28,.4));
- --accent-edge: light-dark(rgba(15,168,156,.5), rgba(110,231,220,.45));
- --ring: light-dark(rgba(30,36,64,.35), rgba(238,242,248,.5));
- --ring-soft: light-dark(rgba(30,36,64,.35), rgba(238,242,248,.4));
- --hover: light-dark(rgba(30,36,64,.07), rgba(238,242,248,.1));
- --chip: light-dark(rgba(30,36,64,.05), rgba(238,242,248,.08));
- --chip-edge: light-dark(rgba(30,36,64,.18), rgba(238,242,248,.2));
- --chip-hover: light-dark(rgba(30,36,64,.1), rgba(238,242,248,.16));
- --track: light-dark(rgba(30,36,64,.08), rgba(238,242,248,.12));
- --track-edge: light-dark(rgba(30,36,64,.3), rgba(238,242,248,.35));
- --rule: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.12));
- --rule-strong: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.14));
- --alarm: light-dark(rgba(243,198,201,.35), rgba(243,198,201,.12));
- --alarm-edge: light-dark(rgba(200,90,100,.35), rgba(243,198,201,.35));
+ --field: rgba(10,16,28,.28);
+ --field-edge: rgba(238,242,248,.22);
+ --placeholder: #DDE3F0;
+ --well: rgba(10,16,28,.25);
+ --well-edge: rgba(238,242,248,.14);
+ --well-ring: rgba(238,242,248,.18);
+ --well-hover: rgba(10,16,28,.4);
+ --accent-edge: rgba(110,231,220,.45);
+ --ring: rgba(238,242,248,.5);
+ --ring-soft: rgba(238,242,248,.4);
+ --hover: rgba(238,242,248,.1);
+ --chip: rgba(238,242,248,.08);
+ --chip-edge: rgba(238,242,248,.2);
+ --chip-hover: rgba(238,242,248,.16);
+ --track: rgba(238,242,248,.12);
+ --track-edge: rgba(238,242,248,.35);
+ --rule: rgba(238,242,248,.12);
+ --rule-strong: rgba(238,242,248,.14);
+ --alarm: rgba(243,198,201,.12);
+ --alarm-edge: rgba(243,198,201,.35);
/* Tiles: a little deeper in the light, so their white icons read. */
- --tile-ink: light-dark(#FFFFFF, #EEF2F8);
- --amber-1: light-dark(rgba(240,150,70,.9), rgba(255,176,102,.78));
- --amber-2: light-dark(rgba(244,114,182,.45), rgba(244,114,182,.22));
- --teal-1: light-dark(rgba(20,168,160,.85), rgba(47,198,192,.55));
- --teal-2: light-dark(rgba(47,198,192,.45), rgba(47,198,192,.12));
- --violet-1: light-dark(rgba(124,77,232,.85), rgba(139,92,246,.6));
- --violet-2: light-dark(rgba(139,92,246,.45), rgba(139,92,246,.14));
- --mist-1: light-dark(rgba(120,132,170,.75), rgba(201,211,227,.4));
- --mist-2: light-dark(rgba(120,132,170,.35), rgba(201,211,227,.08));
- --rose-1: light-dark(rgba(226,82,150,.85), rgba(244,114,182,.55));
- --rose-2: light-dark(rgba(244,114,182,.45), rgba(244,114,182,.12));
+ --tile-ink: #EEF2F8;
+ --amber-1: rgba(255,176,102,.78);
+ --amber-2: rgba(244,114,182,.22);
+ --teal-1: rgba(47,198,192,.55);
+ --teal-2: rgba(47,198,192,.12);
+ --violet-1: rgba(139,92,246,.6);
+ --violet-2: rgba(139,92,246,.14);
+ --mist-1: rgba(201,211,227,.4);
+ --mist-2: rgba(201,211,227,.08);
+ --rose-1: rgba(244,114,182,.55);
+ --rose-2: rgba(244,114,182,.12);
/* Menus (⋯ and More): near-solid, as they open over other glass. */
- --menu-1: light-dark(rgba(255,255,255,0), rgba(238,242,248,.08));
- --menu-2: light-dark(rgba(255,255,255,0), rgba(238,242,248,.04));
- --menu-base: light-dark(#FBFBFE, rgb(24,28,62));
- --menu-shine: light-dark(rgba(255,255,255,.95), rgba(255,255,255,.18));
- --menu-shadow: light-dark(rgba(40,46,90,.3), rgba(8,12,22,.8));
+ --menu-1: rgba(238,242,248,.08);
+ --menu-2: rgba(238,242,248,.04);
+ --menu-base: rgb(24,28,62);
+ --menu-shine: rgba(255,255,255,.18);
+ --menu-shadow: rgba(8,12,22,.8);
/* The Ask panel and its conversation. */
- --sheet-1: light-dark(rgba(255,255,255,.82), rgba(238,242,248,.07));
- --sheet-2: light-dark(rgba(255,255,255,.72), rgba(238,242,248,.03));
- --sheet-base: light-dark(rgba(244,245,252,.6), rgba(14,17,42,.62));
- --scrim: light-dark(rgba(30,36,64,.18), rgba(10,12,30,.38));
- --mine: light-dark(rgba(15,168,156,.14), rgba(47,198,192,.24));
- --mine-edge: light-dark(rgba(15,168,156,.38), rgba(110,231,220,.35));
- --theirs: light-dark(rgba(255,255,255,.88), rgba(238,242,248,.08));
- --theirs-edge: light-dark(rgba(30,36,64,.1), rgba(238,242,248,.16));
- --card: light-dark(rgba(139,92,246,.1), rgba(139,92,246,.16));
- --card-edge: light-dark(rgba(124,77,232,.35), rgba(139,92,246,.45));
+ --sheet-1: rgba(238,242,248,.07);
+ --sheet-2: rgba(238,242,248,.03);
+ --sheet-base: rgba(14,17,42,.62);
+ --scrim: rgba(10,12,30,.38);
+ --mine: rgba(47,198,192,.24);
+ --mine-edge: rgba(110,231,220,.35);
+ --theirs: rgba(238,242,248,.08);
+ --theirs-edge: rgba(238,242,248,.16);
+ --card: rgba(139,92,246,.16);
+ --card-edge: rgba(139,92,246,.45);
+}
+:root[data-theme="light"] {
+ color-scheme: light; --sky-stop: 55%; --glass-lift: -22px;
+ --fog-1-a: .28; --fog-2-a: .26; --fog-3-a: .2; --fog-4-a: .55;
+ --frost: #1E2440; --haze: #4A5275; --signal: #0FA89C;
+ --focus: #0A6E66; --on-signal: #FFFFFF; --sky: #DDE1F3;
+ --sky-1: #F4F5FC; --sky-2: #E8EAF7; --sky-3: #DDE1F3;
+ --beam-1: rgba(255,214,170,.55); --beam-2: rgba(255,190,140,.18); --beam-3: rgba(255,190,140,0);
+ --fog-4: #FFFFFF; --glass-1: rgba(255,255,255,.62); --glass-2: rgba(255,255,255,.42);
+ --glass-base: rgba(255,255,255,0); --glass-edge: rgba(255,255,255,.75); --glass-shine: rgba(255,255,255,.95);
+ --glass-shadow: rgba(40,46,90,.35); --mark-1: #2A3156; --mark-2: #6B73A8;
+ --mark-edge: rgba(255,255,255,0); --btn: #1E2440; --btn-ink: #FFFFFF;
+ --ghost: rgba(30,36,64,.06); --ghost-edge: rgba(30,36,64,.18); --danger: #F6D3D6;
+ --field: rgba(255,255,255,.75); --field-edge: rgba(30,36,64,.16); --placeholder: #5A6285;
+ --well: rgba(255,255,255,.6); --well-edge: rgba(30,36,64,.12); --well-ring: rgba(30,36,64,.14);
+ --well-hover: rgba(255,255,255,.85); --accent-edge: rgba(15,168,156,.5); --ring: rgba(30,36,64,.35);
+ --ring-soft: rgba(30,36,64,.35); --hover: rgba(30,36,64,.07); --chip: rgba(30,36,64,.05);
+ --chip-edge: rgba(30,36,64,.18); --chip-hover: rgba(30,36,64,.1); --track: rgba(30,36,64,.08);
+ --track-edge: rgba(30,36,64,.3); --rule: rgba(30,36,64,.12); --rule-strong: rgba(30,36,64,.12);
+ --alarm: rgba(243,198,201,.35); --alarm-edge: rgba(200,90,100,.35); --tile-ink: #FFFFFF;
+ --amber-1: rgba(192,96,24,.95); --amber-2: rgba(200,70,130,.8); --teal-1: rgba(12,136,129,.95);
+ --teal-2: rgba(16,150,143,.85); --violet-1: rgba(110,62,220,.9); --violet-2: rgba(124,77,232,.72);
+ --mist-1: rgba(84,96,138,.88); --mist-2: rgba(100,112,152,.7); --rose-1: rgba(205,58,128,.92);
+ --rose-2: rgba(222,82,150,.72); --menu-1: rgba(255,255,255,0); --menu-2: rgba(255,255,255,0);
+ --menu-base: #FBFBFE; --menu-shine: rgba(255,255,255,.95); --menu-shadow: rgba(40,46,90,.3);
+ --sheet-1: rgba(255,255,255,.82); --sheet-2: rgba(255,255,255,.72); --sheet-base: rgba(244,245,252,.6);
+ --scrim: rgba(30,36,64,.18); --mine: rgba(15,168,156,.14); --mine-edge: rgba(15,168,156,.38);
+ --theirs: rgba(255,255,255,.88); --theirs-edge: rgba(30,36,64,.1); --card: rgba(139,92,246,.1);
+ --card-edge: rgba(124,77,232,.35);
}
-/* The member's Appearance holds a theme; without one the device decides. The
- few values that are not colours follow the same choice here. */
-:root[data-theme="light"] { color-scheme: light; --sky-stop: 55%; --glass-lift: -22px;
- --fog-1-a: .28; --fog-2-a: .26; --fog-3-a: .2; --fog-4-a: .55; }
:root[data-theme="dark"] { color-scheme: dark; }
-@media (prefers-color-scheme: light) {
- :root:not([data-theme="dark"]) { --sky-stop: 55%; --glass-lift: -22px;
- --fog-1-a: .28; --fog-2-a: .26; --fog-3-a: .2; --fog-4-a: .55; }
+@supports (color: light-dark(white, black)) {
+ :root {
+ color-scheme: light dark;
+ --frost: light-dark(#1E2440, #EEF2F8);
+ --haze: light-dark(#4A5275, #DDE3F0);
+ --signal: light-dark(#0FA89C, #6EE7DC);
+ --focus: light-dark(#0A6E66, #6EE7DC);
+ --on-signal: light-dark(#FFFFFF, #1E2738);
+ --sky: light-dark(#DDE1F3, #1A1F45);
+ --sky-1: light-dark(#F4F5FC, #2C3470);
+ --sky-2: light-dark(#E8EAF7, #1A1F45);
+ --sky-3: light-dark(#DDE1F3, #16193A);
+ --beam-1: light-dark(rgba(255,214,170,.55), rgba(255,214,170,.42));
+ --beam-2: light-dark(rgba(255,190,140,.18), rgba(255,176,102,.12));
+ --beam-3: light-dark(rgba(255,190,140,0), rgba(255,176,102,0));
+ --fog-4: light-dark(#FFFFFF, #C9D3E3);
+ --glass-1: light-dark(rgba(255,255,255,.62), rgba(238,242,248,.07));
+ --glass-2: light-dark(rgba(255,255,255,.42), rgba(238,242,248,.03));
+ --glass-base: light-dark(rgba(255,255,255,0), rgba(14,17,42,.40));
+ --glass-edge: light-dark(rgba(255,255,255,.75), rgba(238,242,248,.18));
+ --glass-shine: light-dark(rgba(255,255,255,.95), rgba(255,255,255,.22));
+ --glass-shadow: light-dark(rgba(40,46,90,.35), rgba(8,12,22,.6));
+ --mark-1: light-dark(#2A3156, #FFFFFF);
+ --mark-2: light-dark(#6B73A8, rgba(238,242,248,.35));
+ --mark-edge: light-dark(rgba(255,255,255,0), rgba(255,255,255,.5));
+ --btn: light-dark(#1E2440, #EEF2F8);
+ --btn-ink: light-dark(#FFFFFF, #1E2738);
+ --ghost: light-dark(rgba(30,36,64,.06), rgba(238,242,248,.1));
+ --ghost-edge: light-dark(rgba(30,36,64,.18), rgba(238,242,248,.22));
+ --danger: light-dark(#F6D3D6, #F3C6C9);
+ --field: light-dark(rgba(255,255,255,.75), rgba(10,16,28,.28));
+ --field-edge: light-dark(rgba(30,36,64,.16), rgba(238,242,248,.22));
+ --placeholder: light-dark(#5A6285, #DDE3F0);
+ --well: light-dark(rgba(255,255,255,.6), rgba(10,16,28,.25));
+ --well-edge: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.14));
+ --well-ring: light-dark(rgba(30,36,64,.14), rgba(238,242,248,.18));
+ --well-hover: light-dark(rgba(255,255,255,.85), rgba(10,16,28,.4));
+ --accent-edge: light-dark(rgba(15,168,156,.5), rgba(110,231,220,.45));
+ --ring: light-dark(rgba(30,36,64,.35), rgba(238,242,248,.5));
+ --ring-soft: light-dark(rgba(30,36,64,.35), rgba(238,242,248,.4));
+ --hover: light-dark(rgba(30,36,64,.07), rgba(238,242,248,.1));
+ --chip: light-dark(rgba(30,36,64,.05), rgba(238,242,248,.08));
+ --chip-edge: light-dark(rgba(30,36,64,.18), rgba(238,242,248,.2));
+ --chip-hover: light-dark(rgba(30,36,64,.1), rgba(238,242,248,.16));
+ --track: light-dark(rgba(30,36,64,.08), rgba(238,242,248,.12));
+ --track-edge: light-dark(rgba(30,36,64,.3), rgba(238,242,248,.35));
+ --rule: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.12));
+ --rule-strong: light-dark(rgba(30,36,64,.12), rgba(238,242,248,.14));
+ --alarm: light-dark(rgba(243,198,201,.35), rgba(243,198,201,.12));
+ --alarm-edge: light-dark(rgba(200,90,100,.35), rgba(243,198,201,.35));
+ --tile-ink: light-dark(#FFFFFF, #EEF2F8);
+ --amber-1: light-dark(rgba(192,96,24,.95), rgba(255,176,102,.78));
+ --amber-2: light-dark(rgba(200,70,130,.8), rgba(244,114,182,.22));
+ --teal-1: light-dark(rgba(12,136,129,.95), rgba(47,198,192,.55));
+ --teal-2: light-dark(rgba(16,150,143,.85), rgba(47,198,192,.12));
+ --violet-1: light-dark(rgba(110,62,220,.9), rgba(139,92,246,.6));
+ --violet-2: light-dark(rgba(124,77,232,.72), rgba(139,92,246,.14));
+ --mist-1: light-dark(rgba(84,96,138,.88), rgba(201,211,227,.4));
+ --mist-2: light-dark(rgba(100,112,152,.7), rgba(201,211,227,.08));
+ --rose-1: light-dark(rgba(205,58,128,.92), rgba(244,114,182,.55));
+ --rose-2: light-dark(rgba(222,82,150,.72), rgba(244,114,182,.12));
+ --menu-1: light-dark(rgba(255,255,255,0), rgba(238,242,248,.08));
+ --menu-2: light-dark(rgba(255,255,255,0), rgba(238,242,248,.04));
+ --menu-base: light-dark(#FBFBFE, rgb(24,28,62));
+ --menu-shine: light-dark(rgba(255,255,255,.95), rgba(255,255,255,.18));
+ --menu-shadow: light-dark(rgba(40,46,90,.3), rgba(8,12,22,.8));
+ --sheet-1: light-dark(rgba(255,255,255,.82), rgba(238,242,248,.07));
+ --sheet-2: light-dark(rgba(255,255,255,.72), rgba(238,242,248,.03));
+ --sheet-base: light-dark(rgba(244,245,252,.6), rgba(14,17,42,.62));
+ --scrim: light-dark(rgba(30,36,64,.18), rgba(10,12,30,.38));
+ --mine: light-dark(rgba(15,168,156,.14), rgba(47,198,192,.24));
+ --mine-edge: light-dark(rgba(15,168,156,.38), rgba(110,231,220,.35));
+ --theirs: light-dark(rgba(255,255,255,.88), rgba(238,242,248,.08));
+ --theirs-edge: light-dark(rgba(30,36,64,.1), rgba(238,242,248,.16));
+ --card: light-dark(rgba(139,92,246,.1), rgba(139,92,246,.16));
+ --card-edge: light-dark(rgba(124,77,232,.35), rgba(139,92,246,.45));
+ }
+ /* The few values that are not colours follow the device too. */
+ @media (prefers-color-scheme: light) {
+ :root:not([data-theme="dark"]) { --sky-stop: 55%; --glass-lift: -22px;
+ --fog-1-a: .28; --fog-2-a: .26; --fog-3-a: .2; --fog-4-a: .55; }
+ }
}
* { box-sizing: border-box; }
html { background: var(--sky); }
@@ -123,7 +234,7 @@ main { min-height: 100vh; }
button, input { font-variation-settings: inherit; }
h1, h2, .wordmark { font-variation-settings: "STYL" 0; }
button, input { font: inherit; }
-:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }
+:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
/* The atmosphere sits behind the whole page: deep slate, banks of fog, one soft light from above. */
/* Two beams of warm light that sway and breathe, and four banks of coloured fog,
diff --git a/internal/look/theme_test.go b/internal/look/theme_test.go
index 5f02804..aa887f8 100644
--- a/internal/look/theme_test.go
+++ b/internal/look/theme_test.go
@@ -50,34 +50,101 @@ func TestPageTheme(t *testing.T) {
}
}
-// One set of tokens drives both themes: every colour in app.css is a
-// token in its :root block, each a light-dark() pair, chosen by
-// color-scheme, which follows the device unless data-theme holds one.
+// block returns the body of the first rule that starts with head, braces
+// balanced, and where it starts and ends in css.
+func block(t *testing.T, css, head string) (body string, from, to int) {
+ t.Helper()
+ from = strings.Index(css, head)
+ if from < 0 {
+ t.Fatalf("app.css has no %q", head)
+ }
+ depth := 0
+ for i := from + len(head) - 1; i < len(css); i++ {
+ switch css[i] {
+ case '{':
+ depth++
+ case '}':
+ depth--
+ if depth == 0 {
+ return css[from+len(head) : i], from, i + 1
+ }
+ }
+ }
+ t.Fatalf("%q never closes", head)
+ return "", 0, 0
+}
+
+var declRE = regexp.MustCompile(`(--[\w-]+|color-scheme):\s*([^;]+);`)
+
+func decls(body string) map[string]string {
+ out := map[string]string{}
+ for _, m := range declRE.FindAllStringSubmatch(body, -1) {
+ out[m[1]] = strings.TrimSpace(m[2])
+ }
+ return out
+}
+
+var pairRE = regexp.MustCompile(`^light-dark\((.+?), ((?:rgba?\([^)]*\)|#\w+))\)$`)
+
+// One set of tokens drives both themes. :root holds every token as a plain
+// dark value, so a browser without light-dark() (Safari before 17.5) gets
+// the dark theme whole. Where light-dark() works, @supports pairs each one
+// with its light value and follows the device. data-theme="light" holds
+// the light values plainly, so choosing Light works everywhere. Each pair's
+// halves are the plain values, and every colour in app.css is a token.
func TestStylesheetThemes(t *testing.T) {
css := stylesheet(t)
- root := regexp.MustCompile(`(?s)\n:root \{(.*?)\n\}`).FindStringSubmatch(css)
- if root == nil {
- t.Fatal("no :root block")
+ rootBody, rootFrom, rootTo := block(t, css, "\n:root {")
+ lightBody, lightFrom, lightTo := block(t, css, `:root[data-theme="light"] {`)
+ supBody, supFrom, supTo := block(t, css, "@supports (color: light-dark(white, black)) {")
+ pairBody, _, _ := block(t, supBody, ":root {")
+ root, light, pairs := decls(rootBody), decls(lightBody), decls(pairBody)
+
+ if root["color-scheme"] != "dark" || light["color-scheme"] != "light" || pairs["color-scheme"] != "light dark" {
+ t.Errorf("color-scheme: :root %q, Light %q, @supports %q; want dark, light, light dark",
+ root["color-scheme"], light["color-scheme"], pairs["color-scheme"])
+ }
+ if !strings.Contains(css, `:root[data-theme="dark"] { color-scheme: dark; }`) {
+ t.Error(`no :root[data-theme="dark"] { color-scheme: dark; }`)
}
- for _, want := range []string{"color-scheme: light dark;"} {
- if !strings.Contains(root[1], want) {
- t.Errorf(":root lacks %q", want)
+ if !strings.Contains(supBody, "@media (prefers-color-scheme: light) {") {
+ t.Error("the device's light setting is not followed inside @supports")
+ }
+ if len(pairs) < 50 {
+ t.Fatalf("only %d paired tokens", len(pairs))
+ }
+ for name, v := range pairs {
+ if name == "color-scheme" {
+ continue
+ }
+ m := pairRE.FindStringSubmatch(v)
+ if m == nil {
+ t.Errorf("%s: %q is not light-dark(light, dark)", name, v)
+ continue
+ }
+ if root[name] != m[2] {
+ t.Errorf("%s: :root's plain value %q, want the pair's dark half %q", name, root[name], m[2])
+ }
+ if light[name] != m[1] {
+ t.Errorf("%s: Light's plain value %q, want the pair's light half %q", name, light[name], m[1])
}
}
- for _, want := range []string{
- `:root[data-theme="light"] { color-scheme: light;`,
- `:root[data-theme="dark"] { color-scheme: dark;`,
- `@media (prefers-color-scheme: light) {`,
- } {
- if !strings.Contains(css, want) {
- t.Errorf("app.css lacks %q", want)
+ for name, v := range root {
+ if strings.Contains(v, "light-dark(") {
+ t.Errorf(":root's %s uses light-dark(): %s", name, v)
}
}
+ comments := regexp.MustCompile(`(?s)/\*.*?\*/`)
+ if strings.Count(comments.ReplaceAllString(css, ""), "light-dark(") != strings.Count(comments.ReplaceAllString(supBody, ""), "light-dark(")+1 {
+ t.Error("light-dark() used outside the @supports block")
+ }
+
+ // No colour outside the token blocks.
+ rest := css[:rootFrom] + css[rootTo:lightFrom] + css[lightTo:supFrom] + css[supTo:]
colour := regexp.MustCompile(`#[0-9A-Fa-f]{3,8}\b|rgba?\(`)
- rest := strings.Replace(css, root[0], "", 1)
for i, line := range strings.Split(rest, "\n") {
- if colour.MatchString(line) && !strings.Contains(line, "/* not a colour */") {
- t.Errorf("app.css has a colour outside the :root tokens (line %d of the rest): %s", i+1, strings.TrimSpace(line))
+ if colour.MatchString(line) {
+ t.Errorf("app.css has a colour outside the tokens (line %d of the rest): %s", i+1, strings.TrimSpace(line))
}
}
}