oficina / base Public

Add light mode: follow the device, or the member's Appearance choice

Every colour in app.css is now a token in one :root block, each a
light-dark(light, dark) pair resolved by color-scheme. The few values
that are not colours (the sky's middle stop, the glass shadow's spread,
the fog's opacities) switch in a small block beside it. Dark is
unchanged (a reduced-motion screenshot of Home matches the old one
pixel for pixel); light takes the approved mockup's values and extends
them to the Ask panel, bubbles, composer, menus, rail and tiles, the
connect and /ask pages and Settings.

By default a page follows the device (color-scheme: light dark). In
Settings, Appearance offers System, Light and Dark: a plain form (303),
stored per member (members.theme). The look renderer parses each page
once per theme, so the server draws <html data-theme>, color-scheme and
theme-color for the member's choice: no flash, no script. Pages with no
member (sign-in) and the installed apps follow the device.

A browser test checks the device setting is followed and the choice
holds over it (scripts on and off), and measures light mode's text
contrast against the pixels behind each glyph at two moments of the
fog: Home, the rail, the panel's bubbles, More, Settings, /ask and a
phone all pass AA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 9a8ea76d40a2a44c2e2fd145aefaa89fbee0800a parent 2bf8b7b
21 files changed, +780 −95
  • docs/copy-pending.md +2 −0
  • internal/browsertest/ask_test.go +12 −1
  • internal/browsertest/light_test.go +271 −0
  • internal/look/look.go +38 −17
  • internal/look/static/app.css +161 −61
  • internal/look/templates/layout.html +10 −2
  • internal/look/theme_test.go +93 −0
  • internal/store/members.go +5 −2
  • internal/store/migrations/0008_theme.sql +3 −0
  • internal/store/theme.go +22 −0
  • internal/store/theme_test.go +38 −0
  • internal/web/app.go +1 −0
  • internal/web/ask.go +1 −1
  • internal/web/ask_connect.go +1 −1
  • internal/web/home.go +1 −1
  • internal/web/people.go +1 −1
  • internal/web/settings.go +40 −1
  • internal/web/signin.go +13 −5
  • internal/web/store.go +2 −2
  • internal/web/templates/settings.html +1 −0
  • internal/webtest/settings_test.go +64 −0
diff --git a/docs/copy-pending.md b/docs/copy-pending.md
index b0db8df..836c80c 100644
--- a/docs/copy-pending.md
+++ b/docs/copy-pending.md
@@ -277,5 +277,7 @@ Review 5 (pending): "Ask Base anything", the chat with Equipo's coordinator.
| internal/web/templates/home.html | The More panel's accessible name (a region) | More Oficina apps |
| internal/web/templates/home.html | The More panel's switch (on: the rail lists every app, on every device) | Keep expanded |
| internal/web/templates/home.html | Oficina rail kept expanded, its last entry (puts More back) | Collapse |
+| internal/web/templates/settings.html | Settings label for the theme choice (also the choice's accessible name) | Appearance |
+| internal/web/settings.go | Appearance, the three buttons (System follows the device's light or dark setting; the chosen one is pressed) | System / Light / Dark |
Activity lines in the status ("Adding a project…" and the like) are Equipo's own labels, shown as Equipo sends them.
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go
index d65a71d..930501c 100644
--- a/internal/browsertest/ask_test.go
+++ b/internal/browsertest/ask_test.go
@@ -16,6 +16,7 @@ import (
"amadan.net/rastrillo/rastrillo/harness"
+ "amadan.net/carlos/base/internal/config"
"amadan.net/carlos/base/internal/equipo/equipotest"
)
@@ -39,6 +40,13 @@ func TestAskFieldOffIsGlass(t *testing.T) {
// connected to it from Settings: Connect Equipo, approve the code in
// Equipo, Check again.
func askBase(t *testing.T) (*harness.Rig, *equipotest.Fake) {
+ t.Helper()
+ rig, f, _ := askBaseWith(t, nil)
+ return rig, f
+}
+
+// askBaseWith is askBase with a last say over Base's configuration.
+func askBaseWith(t *testing.T, tweak func(*config.Config)) (*harness.Rig, *equipotest.Fake, *baseApp) {
t.Helper()
f := equipotest.New(t)
f.Reply = func(string) string {
@@ -48,6 +56,9 @@ func askBase(t *testing.T) (*harness.Rig, *equipotest.Fake) {
rig := newRig(t, func(origin string) http.Handler {
cfg := baseConfig(origin)
cfg.EquipoOrigin = f.URL
+ if tweak != nil {
+ tweak(&cfg)
+ }
b = newBase(t, cfg)
return b.handler
})
@@ -70,7 +81,7 @@ func askBase(t *testing.T) (*harness.Rig, *equipotest.Fake) {
drive(t, rig, chromedp.Click(chromedp.CSS(`form[action="/ask/connect/check"] button`)),
chromedp.WaitVisible(chromedp.CSS(`form[action="/ask/disconnect"]`)))
rig.Screen(".sheet", "Settings, Equipo connected")
- return rig, f
+ return rig, f, b
}
// openPanel opens the panel from Home's Ask field.
diff --git a/internal/browsertest/light_test.go b/internal/browsertest/light_test.go
new file mode 100644
index 0000000..894ac05
--- /dev/null
+++ b/internal/browsertest/light_test.go
@@ -0,0 +1,271 @@
+//go:build browser
+
+package browsertest
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "image/png"
+ "math"
+ "os"
+ "path/filepath"
+ "regexp"
+ "strconv"
+ "testing"
+ "time"
+
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/emulation"
+ "github.com/chromedp/chromedp"
+
+ "amadan.net/rastrillo/rastrillo/harness"
+
+ "amadan.net/carlos/base/internal/config"
+)
+
+// prefersScheme emulates the device's light or dark setting.
+func prefersScheme(scheme string) chromedp.Action[chromedp.Void] {
+ return chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := cdp.Call(ctx, target, emulation.SetEmulatedMedia, emulation.SetEmulatedMediaParams{
+ Features: []*emulation.MediaFeature{{Name: "prefers-color-scheme", Value: scheme}}})
+ return err
+ })
+}
+
+// lightShot saves what is on screen to BASE_LIGHT_ARTIFACTS, when set.
+func lightShot(t *testing.T, rig *harness.Rig, name string) {
+ t.Helper()
+ dir := os.Getenv("BASE_LIGHT_ARTIFACTS")
+ if dir == "" {
+ return
+ }
+ t.Setenv("BASE_BROWSER_ARTIFACTS", dir)
+ viewportShot(t, rig, name)
+}
+
+type textBox struct {
+ Label string
+ X, Y, W, H, Size float64
+ Color string
+}
+
+var rgbRE = regexp.MustCompile(`rgba?\(([\d.]+),? ([\d.]+),? ([\d.]+)`)
+
+func luminance(r, g, b float64) float64 {
+ ch := func(v float64) float64 {
+ v /= 255
+ if v <= 0.03928 {
+ return v / 12.92
+ }
+ return math.Pow((v+0.055)/1.055, 2.4)
+ }
+ return 0.2126*ch(r) + 0.7152*ch(g) + 0.0722*ch(b)
+}
+
+// textContrast measures, for each visible element matching sel, the
+// contrast of its computed text colour against the pixels right behind its
+// glyphs, as the page is drawn at that moment (fog, glass and all). With
+// animations paused it takes one screenshot with the text and one without
+// (descendants with their own colour, such as a step's tick, stay drawn in
+// both): the pixels that differ are the glyphs, and the second shot has
+// what lies behind them. It returns the worst element's ratio and the ratio
+// 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))
+ with := harness.Read(rig, chromedp.CaptureScreenshot())
+ var boxes []textBox
+ if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, `((sel) => {
+ 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;
+ 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});
+ e.dataset.contrast = "1";
+ e.style.setProperty("color", "transparent", "important");
+ }
+ return JSON.stringify(out);
+ })(`+strconv.Quote(sel)+`)`)), &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()`))
+ if len(boxes) == 0 {
+ t.Fatalf("nothing on screen matches %s", sel)
+ }
+ a, err := png.Decode(bytes.NewReader(with))
+ if err != nil {
+ t.Fatal(err)
+ }
+ b, err := png.Decode(bytes.NewReader(without))
+ if err != nil {
+ t.Fatal(err)
+ }
+ worst, need = math.Inf(1), 4.5
+ for _, box := range boxes {
+ m := rgbRE.FindStringSubmatch(box.Color)
+ if m == nil {
+ t.Fatalf("%s: colour %q", box.Label, box.Color)
+ }
+ r, _ := strconv.ParseFloat(m[1], 64)
+ g, _ := strconv.ParseFloat(m[2], 64)
+ 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++ {
+ 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 {
+ continue // not a glyph
+ }
+ glyphs++
+ l := luminance(float64(br>>8), float64(bg>>8), float64(bb>>8))
+ lo = math.Min(lo, (math.Max(fg, l)+0.05)/(math.Min(fg, l)+0.05))
+ }
+ }
+ if glyphs == 0 {
+ t.Fatalf("%s %q: no glyphs found", sel, box.Label)
+ }
+ n := 4.5
+ if box.Size >= 24 {
+ n = 3
+ }
+ if lo/n < worst/need {
+ worst, need, where = lo, n, box.Label
+ }
+ }
+ return worst, need, where
+}
+
+// diff is how far apart two 16-bit channels are, in 8-bit steps.
+func diff(a, b uint32) int {
+ d := int(a>>8) - int(b>>8)
+ if d < 0 {
+ return -d
+ }
+ return d
+}
+
+// checkContrast holds each selector's text to AA at this moment and again
+// a few seconds on, when the fog has moved.
+func checkContrast(t *testing.T, rig *harness.Rig, when string, sels ...string) {
+ t.Helper()
+ for moment := range 2 {
+ if moment > 0 {
+ drive(t, rig, chromedp.Sleep(4*time.Second))
+ }
+ for _, sel := range sels {
+ worst, need, where := textContrast(t, rig, sel)
+ t.Logf("%s, moment %d: %s worst %.2f (%q, needs %.1f)", when, moment+1, sel, worst, where, need)
+ if worst < need {
+ t.Errorf("%s, moment %d: %s %q has contrast %.2f, needs %.1f", when, moment+1, sel, 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`)
+}
+
+const (
+ lightInk = "rgb(30, 36, 64)" // #1E2440
+ darkInk = "rgb(238, 242, 248)" // #EEF2F8
+)
+
+// Base follows the device's light or dark setting until the member picks
+// 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 })
+ home := func() {
+ t.Helper()
+ drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
+ }
+
+ // System: the device decides.
+ drive(t, rig, chromedp.EmulateViewport(1280, 800), prefersScheme("light"))
+ home()
+ if got := textColour(rig, ".hello"); got != lightInk || harness.Evaluate[bool](rig, `document.documentElement.hasAttribute("data-theme")`) {
+ t.Fatalf("System on a light device: Home's text is %s (want %s), data-theme %v", got, lightInk,
+ harness.Evaluate[bool](rig, `document.documentElement.hasAttribute("data-theme")`))
+ }
+ drive(t, rig, prefersScheme("dark"))
+ if got := textColour(rig, ".hello"); got != darkInk {
+ t.Errorf("System on a dark device: Home's text is %s, want %s", got, darkInk)
+ }
+ drive(t, rig, prefersScheme("light"))
+
+ // Light Home: the greeting, the lede, the steps, the Ask field and the
+ // 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")
+
+ // 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`)),
+ chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"),
+ chromedp.Click(chromedp.CSS(`#ask-panel form.composer button`)),
+ chromedp.Poll[chromedp.Void](`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => !m.classList.contains("draft"))`,
+ chromedp.WithPollingTimeout(10*time.Second)),
+ chromedp.Poll[chromedp.Void](`getComputedStyle(document.querySelector("#ask-panel")).transform === "none"`, chromedp.WithPollingTimeout(3*time.Second)))
+ checkContrast(t, rig, "the panel, light", "#ask-panel .msg.person", "#ask-panel .msg.coordinator", "#ask-panel .ask-head h2")
+ lightShot(t, rig, "home-panel-open")
+ drive(t, rig, chromedp.KeyEvent("\u001b"))
+
+ // More's panel.
+ drive(t, rig, chromedp.EmulateViewport(1280, 600))
+ home()
+ drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
+ checkContrast(t, rig, "More's panel, light", ".rail-panel a span", ".rail-panel .switch span")
+ lightShot(t, rig, "home-more-open")
+
+ // Settings.
+ 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")
+
+ // A phone.
+ drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)))
+ home()
+ checkContrast(t, rig, "Home on a phone, light", ".lede", ".oficina h3", ".oficina a.app", ".dock a.app")
+ lightShot(t, rig, "home-phone")
+ noOverflow(t, rig, "Home on a phone, light")
+ drive(t, rig, chromedp.EmulateViewport(1280, 800))
+
+ // /ask with scripts off: the same conversation as a page.
+ drive(t, rig, scriptsDisabled(true), chromedp.Navigate(rig.Origin+"/ask"), chromedp.WaitVisible(chromedp.CSS(".ask-page .composer")))
+ checkContrast(t, rig, "/ask with scripts off, light", ".ask-page .msg.person", ".ask-page .msg.coordinator", ".ask-page .ask-head h2", ".crumb span")
+ lightShot(t, rig, "ask-scripts-off")
+ drive(t, rig, scriptsDisabled(false))
+
+ // The member's choice holds whatever the device says, and System gives
+ // it back. Scripts off too: it is a plain form.
+ for _, off := range []bool{false, true} {
+ drive(t, rig, scriptsDisabled(off))
+ 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))))
+ 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)
+ }
+ }
+ }
+ drive(t, rig, scriptsDisabled(false), prefersScheme("dark"))
+ if dir := os.Getenv("BASE_LIGHT_ARTIFACTS"); dir != "" {
+ t.Logf("light screenshots in %s", filepath.Clean(dir))
+ }
+}
diff --git a/internal/look/look.go b/internal/look/look.go
index 03aa1c0..4502822 100644
--- a/internal/look/look.go
+++ b/internal/look/look.go
@@ -59,14 +59,20 @@ func FontHandler() http.Handler {
// Renderer renders page templates inside the shared layout.
type Renderer struct {
- pages map[string]*template.Template
+ // pages holds each page once per theme ("" follows the device), so
+ // the layout draws a member's Appearance without a script.
+ pages map[string]map[string]*template.Template
}
+// themes are the Appearances a page is drawn in: "" follows the device's
+// light or dark setting; "light" and "dark" hold that one.
+var themes = []string{"", "light", "dark"}
+
// NewRenderer parses every top-level *.html in pageFS as a page named after
// the file (without .html). A page defines the layout's "title" and "main"
// blocks. Templates in partials/*.html are not pages: every page can use
// what they define. funcs are extra template functions; "asset" is always
-// provided.
+// provided, and "theme" (the layout's: the Appearance it draws).
func NewRenderer(pageFS fs.FS, funcs template.FuncMap) (*Renderer, error) {
files, err := fs.Glob(pageFS, "*.html")
if err != nil {
@@ -80,21 +86,25 @@ func NewRenderer(pageFS fs.FS, funcs template.FuncMap) (*Renderer, error) {
for k, v := range funcs {
all[k] = v
}
- r := &Renderer{pages: make(map[string]*template.Template, len(files))}
- for _, f := range files {
- t, err := template.New("layout").Funcs(all).ParseFS(embedded, "templates/layout.html")
- if err != nil {
- return nil, err
- }
- if len(partials) > 0 {
- if t, err = t.ParseFS(pageFS, partials...); err != nil {
- return nil, fmt.Errorf("look: partials: %w", err)
+ r := &Renderer{pages: make(map[string]map[string]*template.Template, len(themes))}
+ for _, theme := range themes {
+ r.pages[theme] = make(map[string]*template.Template, len(files))
+ all["theme"] = func() string { return theme }
+ for _, f := range files {
+ t, err := template.New("layout").Funcs(all).ParseFS(embedded, "templates/layout.html")
+ if err != nil {
+ return nil, err
}
+ if len(partials) > 0 {
+ if t, err = t.ParseFS(pageFS, partials...); err != nil {
+ return nil, fmt.Errorf("look: partials: %w", err)
+ }
+ }
+ if t, err = t.ParseFS(pageFS, f); err != nil {
+ return nil, fmt.Errorf("look: page %s: %w", f, err)
+ }
+ r.pages[theme][strings.TrimSuffix(f, ".html")] = t
}
- if t, err = t.ParseFS(pageFS, f); err != nil {
- return nil, fmt.Errorf("look: page %s: %w", f, err)
- }
- r.pages[strings.TrimSuffix(f, ".html")] = t
}
return r, nil
}
@@ -106,9 +116,20 @@ func (r *Renderer) Page(w http.ResponseWriter, name string, data any) error {
}
// PageStatus is Page with another status, such as 409 for a refused save
-// shown again with what the person typed.
+// shown again with what the person typed. The page follows the device's
+// light or dark setting.
func (r *Renderer) PageStatus(w http.ResponseWriter, status int, name string, data any) error {
- t, ok := r.pages[name]
+ return r.PageTheme(w, status, name, data, "")
+}
+
+// PageTheme is PageStatus in a member's Appearance: "light" or "dark" holds
+// that theme; anything else follows the device.
+func (r *Renderer) PageTheme(w http.ResponseWriter, status int, name string, data any, theme string) error {
+ byName, ok := r.pages[theme]
+ if !ok {
+ byName = r.pages[""]
+ }
+ t, ok := byName[name]
if !ok {
return fmt.Errorf("look: no page %q", name)
}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index a8793d0..631d781 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -7,25 +7,118 @@
@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. */
:root {
- --slate: #1A1F45; /* deep atmosphere: indigo night */
- --harbour: #2C3470; /* mid atmosphere */
- --mist: #C9D3E3; /* pale fog */
+ color-scheme: light dark;
--lagoon: #2FC6C0; /* teal light */
--orchid: #8B5CF6; /* violet light */
--ember: #FFB066; /* warm light */
--rose: #F472B6; /* rose light */
- --frost: #EEF2F8; /* text and highlights */
- --haze: #DDE3F0; /* secondary text on glass */
- --signal: #6EE7DC; /* accent: finished steps, progress */
- --page: #DCE2EC;
- --ink: #1E2738;
+ --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);
+ --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-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));
+ --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-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-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));
+ /* 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);
+ --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));
+ /* 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));
+ /* 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));
+ /* 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));
+}
+/* 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; }
}
* { box-sizing: border-box; }
-html { background: var(--slate); }
+html { background: var(--sky); }
body { margin: 0; min-height: 100vh; position: relative; isolation: isolate; font: 400 16px/1.5 var(--font); font-variation-settings: "STYL" 100; color: var(--frost);
- background: linear-gradient(165deg, var(--harbour) 0%, var(--slate) 62%, #16193A 100%) fixed; }
+ background: linear-gradient(165deg, var(--sky-1) 0%, var(--sky-2) var(--sky-stop), var(--sky-3) 100%) fixed; }
main { min-height: 100vh; }
button, input { font-variation-settings: inherit; }
h1, h2, .wordmark { font-variation-settings: "STYL" 0; }
@@ -36,10 +129,10 @@ button, input { font: inherit; }
/* Two beams of warm light that sway and breathe, and four banks of coloured fog,
each on its own slow path. The fog's colours shift a little over time. */
.light { position: fixed; z-index: -1; pointer-events: none; top: -30%; left: 18%; width: 46%; height: 120%;
- background: linear-gradient(180deg, rgba(255,214,170,.42), rgba(255,176,102,.12) 45%, rgba(255,176,102,0) 78%);
+ background: linear-gradient(180deg, var(--beam-1), var(--beam-2) 45%, var(--beam-3) 78%);
filter: blur(40px); transform-origin: 50% 0; animation: sway 9s ease-in-out infinite alternate, breathe 6s ease-in-out infinite alternate; }
.light::after { content: ""; position: absolute; left: 95%; top: 0; width: 45%; height: 85%;
- background: linear-gradient(180deg, rgba(238,242,248,.26), rgba(238,242,248,0) 80%);
+ background: linear-gradient(180deg, var(--shine-1), var(--shine-2) 80%);
transform-origin: 50% 0; animation: sway 13s ease-in-out -4s infinite alternate-reverse; }
@keyframes sway { from { transform: skewX(-24deg) translateX(-18%); } to { transform: skewX(-4deg) translateX(22%); } }
@keyframes breathe { from { opacity: .45; } to { opacity: 1; } }
@@ -47,31 +140,31 @@ button, input { font: inherit; }
.fog { position: fixed; z-index: -1; inset: -20%; pointer-events: none; animation: tint 18s ease-in-out infinite alternate; }
@keyframes tint { from { filter: hue-rotate(-20deg); } to { filter: hue-rotate(28deg); } }
.fog i { position: absolute; border-radius: 50%; filter: blur(56px); will-change: transform; }
-.fog i:nth-child(1) { background: var(--lagoon); width: 62%; height: 34%; left: -4%; bottom: 10%; opacity: .5; animation: path-a 12s ease-in-out infinite alternate; }
-.fog i:nth-child(2) { background: var(--orchid); width: 58%; height: 36%; right: -6%; bottom: 20%; opacity: .55; animation: path-b 15s ease-in-out -5s infinite alternate; }
-.fog i:nth-child(3) { background: var(--rose); width: 36%; height: 22%; left: 40%; bottom: 2%; opacity: .32; animation: path-c 10s ease-in-out -3s infinite alternate; }
-.fog i:nth-child(4) { background: var(--mist); width: 70%; height: 18%; left: 10%; bottom: 30%; opacity: .14; animation: path-b 17s ease-in-out -9s infinite alternate-reverse; }
+.fog i:nth-child(1) { background: var(--lagoon); width: 62%; height: 34%; left: -4%; bottom: 10%; opacity: var(--fog-1-a); animation: path-a 12s ease-in-out infinite alternate; }
+.fog i:nth-child(2) { background: var(--orchid); width: 58%; height: 36%; right: -6%; bottom: 20%; opacity: var(--fog-2-a); animation: path-b 15s ease-in-out -5s infinite alternate; }
+.fog i:nth-child(3) { background: var(--rose); width: 36%; height: 22%; left: 40%; bottom: 2%; opacity: var(--fog-3-a); animation: path-c 10s ease-in-out -3s infinite alternate; }
+.fog i:nth-child(4) { background: var(--fog-4); width: 70%; height: 18%; left: 10%; bottom: 30%; opacity: var(--fog-4-a); animation: path-b 17s ease-in-out -9s infinite alternate-reverse; }
@keyframes path-a { 0% { transform: translate(-18%, 6%) scale(.9); } 50% { transform: translate(14%, -28%) scale(1.25); } 100% { transform: translate(36%, 4%) scale(1); } }
@keyframes path-b { 0% { transform: translate(16%, -4%) scale(1.1); } 50% { transform: translate(-20%, 22%) scale(.85); } 100% { transform: translate(-38%, -14%) scale(1.2); } }
@keyframes path-c { 0% { transform: translate(10%, 10%) scale(.8); } 50% { transform: translate(-32%, -40%) scale(1.3); } 100% { transform: translate(28%, -18%) scale(1); } }
-/* Glass is tinted dark so text keeps its contrast whatever colour the fog is behind it. */
-.glass { background: linear-gradient(rgba(238,242,248,.07), rgba(238,242,248,.03)), rgba(14,17,42,.40); border: 1px solid rgba(238,242,248,.18);
+/* Glass is tinted dark (white frost in the light) so text keeps its contrast whatever colour the fog is behind it. */
+.glass { background: linear-gradient(var(--glass-1), var(--glass-2)), var(--glass-base); border: 1px solid var(--glass-edge);
backdrop-filter: blur(22px) saturate(130%); -webkit-backdrop-filter: blur(22px) saturate(130%);
- box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 18px 40px -20px rgba(8,12,22,.6); }
+ box-shadow: inset 0 1px 0 var(--glass-shine), 0 18px 40px var(--glass-lift) var(--glass-shadow); }
.wordmark { font-weight: 600; letter-spacing: -0.02em; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.wordmark::before { content: ""; width: 14px; height: 14px; border-radius: 4px;
- background: linear-gradient(160deg, #fff, rgba(238,242,248,.35)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.5); }
+ background: linear-gradient(160deg, var(--mark-1), var(--mark-2)); box-shadow: inset 0 0 0 1px var(--mark-edge); }
/* Buttons and fields share one control height: 44px, border included. */
.btn, .input { height: 44px; line-height: 20px; }
-.btn { padding: 0 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; background: var(--frost); color: var(--ink); }
-.btn.ghost { background: rgba(238,242,248,.1); color: var(--frost); box-shadow: inset 0 0 0 1px rgba(238,242,248,.22); }
-.btn.danger { background: #F3C6C9; color: #5B1820; }
-.input { padding: 0 14px; border-radius: 10px; border: 1px solid rgba(238,242,248,.22); color: var(--frost);
- background: rgba(10,16,28,.28); }
-.input::placeholder { color: var(--haze); }
+.btn { padding: 0 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; background: var(--btn); color: var(--btn-ink); }
+.btn.ghost { background: var(--ghost); color: var(--frost); box-shadow: inset 0 0 0 1px var(--ghost-edge); }
+.btn.danger { background: var(--danger); color: var(--danger-ink); }
+.input { padding: 0 14px; border-radius: 10px; border: 1px solid var(--field-edge); color: var(--frost);
+ background: var(--field); }
+.input::placeholder { color: var(--placeholder); }
/* Sign in */
.signin { display: grid; place-items: center; padding: 32px; }
@@ -98,26 +191,26 @@ button.alt[aria-busy="true"] { cursor: progress; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 10px 8px 16px; border-radius: 14px; }
.team { font-size: 14px; color: var(--haze); }
.ask { flex: 1; max-width: 420px; margin-left: auto; padding: 8px 14px; border-radius: 10px; font-size: 14px; color: var(--haze);
- background: rgba(10,16,28,.25); box-shadow: inset 0 0 0 1px rgba(238,242,248,.14); display: flex; justify-content: space-between; }
+ background: var(--well); box-shadow: inset 0 0 0 1px var(--well-edge); display: flex; justify-content: space-between; }
.me { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: linear-gradient(140deg, var(--ember), var(--rose)); color: var(--ink); }
.hello { margin: 46px 0 0; font-size: clamp(34px, 4.4vw, 52px); font-weight: 500; letter-spacing: -0.035em; line-height: 1.05; }
.lede { margin: 12px 0 24px; color: var(--haze); font-size: 17px; }
.steps { display: flex; gap: 10px; list-style: none; padding: 0; margin: 0; flex-wrap: wrap; }
.steps li { padding: 9px 14px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; }
-.steps .mark { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(238,242,248,.5); display: grid; place-items: center; font-size: 11px; }
-.steps .done .mark { background: var(--signal); box-shadow: none; color: var(--ink); }
+.steps .mark { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--ring); display: grid; place-items: center; font-size: 11px; }
+.steps .done .mark { background: var(--signal); box-shadow: none; color: var(--on-signal); }
.steps .done { color: var(--haze); }
.dock { display: flex; gap: 18px; flex-wrap: wrap; margin-top: auto; padding-top: 44px; }
.app { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 80px; font-size: 13px; font-weight: 500; }
.tile { width: 76px; height: 76px; border-radius: 20px; display: grid; place-items: center; }
-.tile svg { width: 28px; height: 28px; stroke: var(--frost); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
-.tile.t-amber { background: linear-gradient(155deg, rgba(255,176,102,.78), rgba(244,114,182,.22)); }
-.tile.t-teal { background: linear-gradient(155deg, rgba(47,198,192,.55), rgba(47,198,192,.12)); }
-.tile.t-violet { background: linear-gradient(155deg, rgba(139,92,246,.6), rgba(139,92,246,.14)); }
-.tile.t-mist { background: linear-gradient(155deg, rgba(201,211,227,.4), rgba(201,211,227,.08)); }
-.tile.t-rose { background: linear-gradient(155deg, rgba(244,114,182,.55), rgba(244,114,182,.12)); }
+.tile svg { width: 28px; height: 28px; stroke: var(--tile-ink); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
+.tile.t-amber { background: linear-gradient(155deg, var(--amber-1), var(--amber-2)); }
+.tile.t-teal { background: linear-gradient(155deg, var(--teal-1), var(--teal-2)); }
+.tile.t-violet { background: linear-gradient(155deg, var(--violet-1), var(--violet-2)); }
+.tile.t-mist { background: linear-gradient(155deg, var(--mist-1), var(--mist-2)); }
+.tile.t-rose { background: linear-gradient(155deg, var(--rose-1), var(--rose-2)); }
/* Home's columns: the Oficina rail, when there is one, and everything else. */
.home-cols { flex: 1; display: flex; gap: 22px; }
.home-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
@@ -138,11 +231,11 @@ button.alt[aria-busy="true"] { cursor: progress; }
width: 100%; padding: 0 2px; border: 0; border-radius: 12px; background: none; cursor: pointer;
color: var(--frost); text-decoration: none; font: inherit; font-size: 12px; font-weight: 500; line-height: 1.2; transition: background .2s; }
.rail-app img { width: 36px; height: 36px; display: block; }
-.rail-app:hover, .rail-more[open] > summary { background: rgba(238,242,248,.1); }
-.rail-app:focus-visible { outline-offset: -2px; background: rgba(238,242,248,.1); }
+.rail-app:hover, .rail-more[open] > summary { background: var(--hover); }
+.rail-app:focus-visible { outline-offset: -2px; background: var(--hover); }
/* More and Collapse: a round glass glyph in place of an app's icon. */
.rail-app .glyph { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
- background: rgba(238,242,248,.08); box-shadow: inset 0 0 0 1px rgba(238,242,248,.2); }
+ background: var(--chip); box-shadow: inset 0 0 0 1px var(--chip-edge); }
.rail-app .glyph svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.rail-more .glyph svg { stroke-width: 3.2; }
.rail-more, .rail-collapse { flex: none; }
@@ -152,19 +245,19 @@ button.alt[aria-busy="true"] { cursor: progress; }
/* More's panel opens beside the rail, its foot level with More's. */
.rail-panel { position: absolute; left: calc(100% + 18px); bottom: 0; width: 224px; max-height: calc(100dvh - 120px); overflow-y: auto;
padding: 6px; border-radius: 14px;
- background: linear-gradient(rgba(238,242,248,.08), rgba(238,242,248,.04)), rgb(24,28,62);
- box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 18px 40px -12px rgba(8,12,22,.8); }
+ background: linear-gradient(var(--menu-1), var(--menu-2)), var(--menu-base);
+ box-shadow: inset 0 1px 0 var(--menu-shine), 0 18px 40px -12px var(--menu-shadow); }
.rail-panel-apps { display: flex; flex-direction: column; }
.rail-panel-app { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 8px;
color: var(--frost); text-decoration: none; font-size: 15px; font-weight: 500; }
.rail-panel-app img { width: 28px; height: 28px; display: block; }
-.rail-panel form { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid rgba(238,242,248,.12); }
+.rail-panel form { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--rule); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 0 10px;
border: 0; border-radius: 8px; background: none; color: var(--frost); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
.switch i { flex: none; position: relative; width: 36px; height: 22px; border-radius: 11px;
- background: rgba(238,242,248,.12); box-shadow: inset 0 0 0 1px rgba(238,242,248,.35); }
+ background: var(--track); box-shadow: inset 0 0 0 1px var(--track-edge); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--haze); }
-.rail-panel-app:hover, .rail-panel-app:focus-visible, .switch:hover, .switch:focus-visible { background: rgba(238,242,248,.1); }
+.rail-panel-app:hover, .rail-panel-app:focus-visible, .switch:hover, .switch:focus-visible { background: var(--hover); }
.rail-panel-app:focus-visible, .switch:focus-visible { outline-offset: -2px; }
/* How many apps fit: S entries need 76S - 4px of the rail's inner height.
When the apps outnumber S, the rail shows the first S - 1 and More, and
@@ -236,16 +329,23 @@ button.alt[aria-busy="true"] { cursor: progress; }
.invite { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.invite .input { flex: 1; min-width: 180px; }
.people { list-style: none; margin: 0; padding: 0; }
-.people li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid rgba(238,242,248,.14); }
+.people li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--rule-strong); }
.face { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }
.face.on { background: linear-gradient(140deg, var(--ember), var(--rose)); color: var(--ink); }
-.face.off { box-shadow: inset 0 0 0 1.5px rgba(238,242,248,.4); color: var(--haze); }
+.face.off { box-shadow: inset 0 0 0 1.5px var(--ring-soft); color: var(--haze); }
.people .who { flex: 1; font-weight: 500; }
.people .who small { display: block; color: var(--haze); font-size: 13px; font-weight: 400; }
.tag { font-size: 13px; color: var(--haze); }
+/* Settings' Appearance: System, Light and Dark in one pill, the chosen one
+ filled. Each is a submit button, so it works without scripts. */
+.segmented { display: flex; flex: none; gap: 2px; padding: 3px; border-radius: 13px; background: var(--well); box-shadow: inset 0 0 0 1px var(--well-edge); }
+.segmented button { height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: none; color: var(--frost);
+ font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; transition: background .2s; }
+.segmented button:hover { background: var(--hover); }
+.segmented button[aria-pressed="true"] { background: var(--btn); color: var(--btn-ink); font-weight: 600; }
.listing { display: flex; gap: 16px; align-items: center; padding: 16px 0;
- border-top: 1px solid rgba(238,242,248,.14); border-bottom: 1px solid rgba(238,242,248,.14); }
+ border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule-strong); }
.listing .tile { flex: none; width: 56px; height: 56px; border-radius: 16px; }
.listing .txt { flex: 1; }
.listing .txt b { display: block; font-weight: 600; }
@@ -255,7 +355,7 @@ button.alt[aria-busy="true"] { cursor: progress; }
background: linear-gradient(var(--signal), var(--signal)) left / 0% 100% no-repeat, var(--mist);
animation: fill 1.8s cubic-bezier(.4,0,.2,1) forwards; }
@keyframes fill { to { background-size: 100% 100%, auto; } }
-.confirm { margin-top: 12px; padding: 14px 16px; border-radius: 14px; background: rgba(243,198,201,.12); box-shadow: inset 0 0 0 1px rgba(243,198,201,.35); }
+.confirm { margin-top: 12px; padding: 14px 16px; border-radius: 14px; background: var(--alarm); box-shadow: inset 0 0 0 1px var(--alarm-edge); }
.confirm p { margin: 0 0 12px; }
.soon { margin-top: 22px; color: var(--haze); font-size: 14px; }
.soon b { color: var(--frost); font-weight: 500; }
@@ -280,12 +380,12 @@ a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.ask::placeholder { color: var(--haze); opacity: 1; }
.ask:disabled { cursor: not-allowed; color: var(--haze); opacity: 1; }
a.ask { text-decoration: none; transition: background .2s, box-shadow .2s; }
-a.ask:hover { background: rgba(10,16,28,.4); box-shadow: inset 0 0 0 1px rgba(110,231,220,.45); }
+a.ask:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); }
a.ask::after { content: "/"; color: var(--haze); opacity: .7; }
/* The Ask icon stands in for the field on a phone. */
.ask-icon { display: none; flex: none; width: 44px; height: 44px; border-radius: 50%; place-items: center; margin-left: auto; color: var(--frost);
- background: rgba(10,16,28,.25); box-shadow: inset 0 0 0 1px rgba(238,242,248,.18); transition: background .2s, box-shadow .2s; }
-.ask-icon:hover { background: rgba(10,16,28,.4); box-shadow: inset 0 0 0 1px rgba(110,231,220,.45); }
+ background: var(--well); box-shadow: inset 0 0 0 1px var(--well-ring); transition: background .2s, box-shadow .2s; }
+.ask-icon:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); }
.ask-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.ask-icon svg path + path { stroke-width: 2.4; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@@ -294,7 +394,7 @@ a.ask::after { content: "/"; color: var(--haze); opacity: .7; }
(full screen on a phone), and the same conversation on /ask. */
dialog.ask-panel { position: fixed; inset: 12px 12px 12px auto; width: min(460px, calc(100vw - 24px)); height: auto;
max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 18px; color: var(--frost);
- background: linear-gradient(rgba(238,242,248,.07), rgba(238,242,248,.03)), rgba(14,17,42,.62);
+ background: linear-gradient(var(--sheet-1), var(--sheet-2)), var(--sheet-base);
flex-direction: column; overflow: hidden;
transition: transform .35s cubic-bezier(.2,.7,0,1), opacity .35s, overlay .35s allow-discrete, display .35s allow-discrete;
transform: translateX(32px); opacity: 0; }
@@ -306,34 +406,34 @@ dialog.ask-panel { position: fixed; inset: 12px 12px 12px auto; width: min(460px
}
dialog.ask-panel[open] { display: flex; transform: none; opacity: 1; }
@starting-style { dialog.ask-panel[open] { transform: translateX(32px); opacity: 0; } }
-dialog.ask-panel::backdrop { background: rgba(10,12,30,.38); }
-.ask-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px 20px; border-bottom: 1px solid rgba(238,242,248,.12); }
+dialog.ask-panel::backdrop { background: var(--scrim); }
+.ask-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--rule); }
.ask-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 500; letter-spacing: -0.02em; font-variation-settings: "STYL" 0; }
/* The header's round glass buttons: ⋯ (a menu holding Open Equipo) and close. */
.ask-head .round { flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
- color: var(--frost); background: rgba(238,242,248,.08); box-shadow: inset 0 0 0 1px rgba(238,242,248,.2); transition: background .2s, box-shadow .2s; }
-.ask-head .round:hover, .ask-more[open] > summary { background: rgba(238,242,248,.16); box-shadow: inset 0 0 0 1px rgba(110,231,220,.45); }
+ color: var(--frost); background: var(--chip); box-shadow: inset 0 0 0 1px var(--chip-edge); transition: background .2s, box-shadow .2s; }
+.ask-head .round:hover, .ask-more[open] > summary { background: var(--chip-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); }
.ask-head .round svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; fill: none; }
.ask-more summary svg { width: 22px; height: 22px; stroke-width: 3.2; }
.ask-more { position: relative; }
.ask-more > summary { list-style: none; }
.ask-more > summary::-webkit-details-marker { display: none; }
.ask-menu { position: absolute; z-index: 2; right: 0; top: calc(100% + 6px); min-width: 180px; padding: 6px; border-radius: 12px;
- background: linear-gradient(rgba(238,242,248,.08), rgba(238,242,248,.04)), rgb(24,28,62);
- box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 18px 40px -12px rgba(8,12,22,.8); }
+ background: linear-gradient(var(--menu-1), var(--menu-2)), var(--menu-base);
+ box-shadow: inset 0 1px 0 var(--menu-shine), 0 18px 40px -12px var(--menu-shadow); }
.ask-menu a { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--frost);
text-decoration: none; font-size: 15px; font-weight: 500; white-space: nowrap; }
-.ask-menu a:hover, .ask-menu a:focus-visible { background: rgba(238,242,248,.1); }
+.ask-menu a:hover, .ask-menu a:focus-visible { background: var(--hover); }
.ask-note { padding: 22px 20px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.ask-note p { margin: 0; color: var(--haze); }
.ask-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 18px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
-.msg.person { align-self: flex-end; background: rgba(47,198,192,.24); box-shadow: inset 0 0 0 1px rgba(110,231,220,.35); border-bottom-right-radius: 4px; }
-.msg.coordinator { align-self: flex-start; background: rgba(238,242,248,.08); box-shadow: inset 0 0 0 1px rgba(238,242,248,.16); border-bottom-left-radius: 4px; }
+.msg.person { align-self: flex-end; background: var(--mine); box-shadow: inset 0 0 0 1px var(--mine-edge); border-bottom-right-radius: 4px; }
+.msg.coordinator { align-self: flex-start; background: var(--theirs); box-shadow: inset 0 0 0 1px var(--theirs-edge); border-bottom-left-radius: 4px; }
.msg.draft::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 3px; vertical-align: -2px; background: var(--signal); animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
-.msg.card { align-self: stretch; max-width: none; background: rgba(139,92,246,.16); box-shadow: inset 0 0 0 1px rgba(139,92,246,.45); }
+.msg.card { align-self: stretch; max-width: none; background: var(--card); box-shadow: inset 0 0 0 1px var(--card-edge); }
.msg.card p { margin: 0 0 10px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-empty, .ask-problem { margin: 0; padding: 0 20px 12px; color: var(--haze); font-size: 14px; }
diff --git a/internal/look/templates/layout.html b/internal/look/templates/layout.html
index 157e490..c310e9a 100644
--- a/internal/look/templates/layout.html
+++ b/internal/look/templates/layout.html
@@ -1,9 +1,17 @@
{{define "layout"}}<!DOCTYPE html>
-<html lang="en">
+<html lang="en"{{with theme}} data-theme="{{.}}"{{end}}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
-<title>{{block "title" .}}Base{{end}}</title>
+{{/* The browser's own colours (form controls, scrollbars, the address bar)
+ before the stylesheet arrives: the member's Appearance, or the device's. */}}{{if eq theme "light"}}<meta name="color-scheme" content="light">
+<meta name="theme-color" content="#F4F5FC">
+{{else if eq theme "dark"}}<meta name="color-scheme" content="dark">
+<meta name="theme-color" content="#1A1F45">
+{{else}}<meta name="color-scheme" content="light dark">
+<meta name="theme-color" content="#F4F5FC" media="(prefers-color-scheme: light)">
+<meta name="theme-color" content="#1A1F45" media="(prefers-color-scheme: dark)">
+{{end}}<title>{{block "title" .}}Base{{end}}</title>
{{block "head" .}}{{end}}
<link rel="preload" href="/static/fonts/timeless/1.094/TimelessSansVF.woff2" as="font" type="font/woff2" crossorigin>
<link rel="stylesheet" href="{{asset "static/app.css"}}">
diff --git a/internal/look/theme_test.go b/internal/look/theme_test.go
new file mode 100644
index 0000000..5f02804
--- /dev/null
+++ b/internal/look/theme_test.go
@@ -0,0 +1,93 @@
+package look_test
+
+import (
+ "net/http/httptest"
+ "regexp"
+ "strings"
+ "testing"
+
+ "amadan.net/carlos/base/internal/look"
+)
+
+func renderTheme(t *testing.T, theme string) string {
+ t.Helper()
+ r, err := look.NewRenderer(testPages, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ rec := httptest.NewRecorder()
+ if err := r.PageTheme(rec, 200, "hello", "you", theme); err != nil {
+ t.Fatal(err)
+ }
+ return rec.Body.String()
+}
+
+// A member's Appearance is drawn by the server: <html data-theme> and the
+// browser's own colours (color-scheme, theme-color) for that theme, so the
+// page never flashes the other one and needs no script. Without one (and
+// on pages with no member, Page) the page follows the device.
+func TestPageTheme(t *testing.T) {
+ for theme, want := range map[string][]string{
+ "light": {`<html lang="en" data-theme="light">`, `<meta name="color-scheme" content="light">`, `<meta name="theme-color" content="#F4F5FC">`},
+ "dark": {`<html lang="en" data-theme="dark">`, `<meta name="color-scheme" content="dark">`, `<meta name="theme-color" content="#1A1F45">`},
+ "": {`<html lang="en">`, `<meta name="color-scheme" content="light dark">`,
+ `<meta name="theme-color" content="#F4F5FC" media="(prefers-color-scheme: light)">`,
+ `<meta name="theme-color" content="#1A1F45" media="(prefers-color-scheme: dark)">`},
+ "purple": {`<html lang="en">`, `<meta name="color-scheme" content="light dark">`},
+ } {
+ body := renderTheme(t, theme)
+ for _, w := range want {
+ if !strings.Contains(body, w) {
+ t.Errorf("theme %q: no %s in:\n%s", theme, w, body)
+ }
+ }
+ if n := strings.Count(body, `name="theme-color"`); (theme == "light" || theme == "dark") && n != 1 {
+ t.Errorf("theme %q: %d theme-color tags", theme, n)
+ }
+ }
+ if body := render(t); !strings.Contains(body, `<html lang="en">`) || strings.Contains(body, "data-theme") {
+ t.Errorf("Page forces a theme:\n%s", body)
+ }
+}
+
+// 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.
+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")
+ }
+ for _, want := range []string{"color-scheme: light dark;"} {
+ if !strings.Contains(root[1], want) {
+ t.Errorf(":root lacks %q", want)
+ }
+ }
+ 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)
+ }
+ }
+ 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))
+ }
+ }
+}
+
+func stylesheet(t *testing.T) string {
+ t.Helper()
+ rec := httptest.NewRecorder()
+ look.Assets.Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/static/app.css", nil))
+ if rec.Code != 200 {
+ t.Fatalf("app.css: %d", rec.Code)
+ }
+ return rec.Body.String()
+}
diff --git a/internal/store/members.go b/internal/store/members.go
index b176c07..3541aa1 100644
--- a/internal/store/members.go
+++ b/internal/store/members.go
@@ -18,9 +18,12 @@ type Member struct {
InvitedAt time.Time
JoinedAt *time.Time
InviteSentAt *time.Time // nil until an invitation email was delivered
+ // Theme is the member's Appearance: "" follows the device; "light" or
+ // "dark" holds that one on every device.
+ Theme string
}
-const memberCols = `id, email, name, role, invited_at, joined_at, invite_sent_at`
+const memberCols = `id, email, name, role, invited_at, joined_at, invite_sent_at, theme`
// memberColsOf is memberCols qualified by a table alias, for joins.
func memberColsOf(alias string) string {
@@ -36,7 +39,7 @@ type scanner interface{ Scan(...any) error }
func scanMember(s scanner) (Member, error) {
var m Member
var joined, sent sql.NullTime
- if err := s.Scan(&m.ID, &m.Email, &m.Name, &m.Role, &m.InvitedAt, &joined, &sent); err != nil {
+ if err := s.Scan(&m.ID, &m.Email, &m.Name, &m.Role, &m.InvitedAt, &joined, &sent, &m.Theme); err != nil {
return Member{}, err
}
if joined.Valid {
diff --git a/internal/store/migrations/0008_theme.sql b/internal/store/migrations/0008_theme.sql
new file mode 100644
index 0000000..5b70f8d
--- /dev/null
+++ b/internal/store/migrations/0008_theme.sql
@@ -0,0 +1,3 @@
+-- Appearance: '' follows the device's light or dark setting; 'light' or
+-- 'dark' holds that theme. The member's, on every device.
+ALTER TABLE members ADD COLUMN theme text NOT NULL DEFAULT '';
diff --git a/internal/store/theme.go b/internal/store/theme.go
new file mode 100644
index 0000000..39ef382
--- /dev/null
+++ b/internal/store/theme.go
@@ -0,0 +1,22 @@
+package store
+
+import (
+ "context"
+ "database/sql"
+ "fmt"
+)
+
+// SetTheme keeps the member's Appearance: "" (the device's), "light" or
+// "dark". The caller checks the value.
+func SetTheme(ctx context.Context, db *sql.DB, memberID, theme string) error {
+ res, err := db.ExecContext(ctx, `UPDATE members SET theme = ? WHERE id = ?`, theme, memberID)
+ if err != nil {
+ return err
+ }
+ if n, err := res.RowsAffected(); err != nil {
+ return err
+ } else if n != 1 {
+ return fmt.Errorf("store: no member %s", memberID)
+ }
+ return nil
+}
diff --git a/internal/store/theme_test.go b/internal/store/theme_test.go
new file mode 100644
index 0000000..a0715fe
--- /dev/null
+++ b/internal/store/theme_test.go
@@ -0,0 +1,38 @@
+package store
+
+import (
+ "context"
+ "testing"
+)
+
+// A member's Appearance starts as the device's ("") and holds what they
+// choose, on every device: it is on their member row.
+func TestTheme(t *testing.T) {
+ ctx, db := context.Background(), open(t)
+ if err := Bootstrap(ctx, db, "owner@example.com"); err != nil {
+ t.Fatal(err)
+ }
+ theme := func() string {
+ t.Helper()
+ m, _, err := MemberByEmail(ctx, db, "owner@example.com")
+ if err != nil {
+ t.Fatal(err)
+ }
+ return m.Theme
+ }
+ if got := theme(); got != "" {
+ t.Fatalf("fresh member: %q, want the device's", got)
+ }
+ owner, _, _ := MemberByEmail(ctx, db, "owner@example.com")
+ for _, want := range []string{"light", "dark", ""} {
+ if err := SetTheme(ctx, db, owner.ID, want); err != nil {
+ t.Fatal(err)
+ }
+ if got := theme(); got != want {
+ t.Errorf("after choosing %q: %q", want, got)
+ }
+ }
+ if err := SetTheme(ctx, db, "no-such-member", "light"); err == nil {
+ t.Error("set for a member who isn't there")
+ }
+}
diff --git a/internal/web/app.go b/internal/web/app.go
index e135199..e361a10 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -196,6 +196,7 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger
r.Get("/store/{app}/uninstall", a.uninstallPage)
r.Post("/store/{app}/uninstall", a.storeUninstall)
r.Get("/settings", a.settings)
+ r.Post("/settings/appearance", a.settingsAppearance)
r.With(ownSignInOnly).Post(registerBeginPath, a.pk.RegisterBegin)
r.With(ownSignInOnly).Post(registerFinishPath, a.pk.RegisterFinish)
r.Method(http.MethodGet, "/authorize", authorize)
diff --git a/internal/web/ask.go b/internal/web/ask.go
index 289ea11..875d8ef 100644
--- a/internal/web/ask.go
+++ b/internal/web/ask.go
@@ -221,7 +221,7 @@ func (a *app) askPageView(w http.ResponseWriter, r *http.Request) {
v.Problem = "Equipo didn't get that. Try again."
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "ask", askPage{Name: a.cfg.Name, Ask: v})
+ a.render(w, r, "ask", askPage{Name: a.cfg.Name, Ask: v})
}
// askStateJSON is GET /ask/state: what the panel draws, and the cursor its
diff --git a/internal/web/ask_connect.go b/internal/web/ask_connect.go
index 4272334..6221915 100644
--- a/internal/web/ask_connect.go
+++ b/internal/web/ask_connect.go
@@ -256,7 +256,7 @@ func (a *app) askDisconnect(w http.ResponseWriter, r *http.Request) {
func (a *app) renderConnect(w http.ResponseWriter, r *http.Request, status int, v connectView) {
v.Name, v.Label, v.Back = a.cfg.Name, a.ask.label, askNext[v.Next]
w.Header().Set("Cache-Control", "no-store")
- if err := a.pages.PageStatus(w, status, "ask_connect", v); err != nil {
+ if err := a.pages.PageTheme(w, status, "ask_connect", v, themeOf(r)); err != nil {
a.fail(w, err)
}
}
diff --git a/internal/web/home.go b/internal/web/home.go
index f5eef60..55b8f0c 100644
--- a/internal/web/home.go
+++ b/internal/web/home.go
@@ -168,7 +168,7 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
page.Ask = &v
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "home", page)
+ a.render(w, r, "home", page)
}
// railSet is Keep expanded (expanded=1) and Collapse (expanded=0) for Home's
diff --git a/internal/web/people.go b/internal/web/people.go
index 6aaecd7..b8b7964 100644
--- a/internal/web/people.go
+++ b/internal/web/people.go
@@ -48,7 +48,7 @@ func (a *app) people(w http.ResponseWriter, r *http.Request) {
})
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "people", page)
+ a.render(w, r, "people", page)
}
// invite adds a teammate and emails them where to sign in. Only the owner may.
diff --git a/internal/web/settings.go b/internal/web/settings.go
index 4ff0a70..c88c0b5 100644
--- a/internal/web/settings.go
+++ b/internal/web/settings.go
@@ -6,6 +6,8 @@ import (
"amadan.net/oficina/home/connect"
"amadan.net/rastrillo/rastrillo/sessions"
+
+ "amadan.net/carlos/base/internal/store"
)
type settingsPage struct {
@@ -28,6 +30,20 @@ type settingsPage struct {
// Equipo is the member's Equipo connection (connect, pending, ready or
// reconnect), empty with the chat off.
Equipo string
+ // Themes are the Appearance choices, the member's pressed.
+ Themes []themeChoice
+}
+
+// themeChoice is one Appearance button in Settings.
+type themeChoice struct {
+ Value, Label string
+ On bool
+}
+
+// appearances are Settings' Appearance choices and what each stores:
+// System follows the device ("").
+var appearances = []struct{ value, label, stored string }{
+ {"system", "System", ""}, {"light", "Light", "light"}, {"dark", "Dark", "dark"},
}
func (a *app) settings(w http.ResponseWriter, r *http.Request) {
@@ -54,6 +70,9 @@ func (a *app) settings(w http.ResponseWriter, r *http.Request) {
UserID: base64.RawURLEncoding.EncodeToString([]byte(me.ID)),
ModuleURL: webauthnModulePath, RegisterBegin: registerBeginPath, RegisterEnd: registerFinishPath,
}
+ for _, c := range appearances {
+ page.Themes = append(page.Themes, themeChoice{Value: c.value, Label: c.label, On: c.stored == me.Theme})
+ }
if a.ask != nil {
_, _, state, err := a.askLink(r.Context(), me)
if err != nil {
@@ -73,5 +92,25 @@ func (a *app) settings(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Referrer-Policy", "strict-origin")
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "settings", page)
+ a.render(w, r, "settings", page)
+}
+
+// settingsAppearance keeps the member's Appearance (System, Light or Dark):
+// a plain form, so it works without scripts.
+func (a *app) settingsAppearance(w http.ResponseWriter, r *http.Request) {
+ me, _ := CurrentMember(r)
+ choice := r.PostFormValue("theme")
+ for _, c := range appearances {
+ if c.value != choice {
+ continue
+ }
+ if err := store.SetTheme(r.Context(), a.db, me.ID, c.stored); err != nil {
+ a.logger.Error("settings: appearance", "err", err)
+ http.Error(w, "unavailable", http.StatusServiceUnavailable)
+ return
+ }
+ http.Redirect(w, r, "/settings", http.StatusSeeOther)
+ return
+ }
+ http.Error(w, "bad request", http.StatusBadRequest)
}
diff --git a/internal/web/signin.go b/internal/web/signin.go
index 23ab35b..313c152 100644
--- a/internal/web/signin.go
+++ b/internal/web/signin.go
@@ -45,7 +45,7 @@ func (a *app) signinWith(w http.ResponseWriter, r *http.Request, oficina string)
}
a.auth.PrepareSigninResponse(w, state)
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "signin", signinPage{
+ a.render(w, r, "signin", signinPage{
Name: a.cfg.Name, State: state,
Refused: r.URL.Query().Get("refused") == "1",
ProblemText: problemText[state.Problem],
@@ -56,13 +56,15 @@ func (a *app) signinWith(w http.ResponseWriter, r *http.Request, oficina string)
// renderConfirm draws the page an emailed link lands on: one button that
// posts the token, so a mail scanner opening the link spends nothing.
-func (a *app) renderConfirm(w http.ResponseWriter, _ *http.Request, d auth.ConfirmPageData) {
+func (a *app) renderConfirm(w http.ResponseWriter, r *http.Request, d auth.ConfirmPageData) {
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "confirm", signinPage{Name: a.cfg.Name, Confirm: &d})
+ a.render(w, r, "confirm", signinPage{Name: a.cfg.Name, Confirm: &d})
}
-func (a *app) render(w http.ResponseWriter, name string, data any) {
- if err := a.pages.Page(w, name, data); err != nil {
+// render draws a page in the signed-in member's Appearance; with no member
+// (the sign-in pages), in the device's.
+func (a *app) render(w http.ResponseWriter, r *http.Request, name string, data any) {
+ if err := a.pages.PageTheme(w, http.StatusOK, name, data, themeOf(r)); err != nil {
a.logger.Error("render", "page", name, "err", err)
http.Error(w, "something went wrong", http.StatusInternalServerError)
}
@@ -82,3 +84,9 @@ func linkPending(r *http.Request) bool {
c, err := r.Cookie(linkNavigationCookie)
return err == nil && c.Value != ""
}
+
+// themeOf is the signed-in member's Appearance, "" (the device's) without one.
+func themeOf(r *http.Request) string {
+ me, _ := CurrentMember(r)
+ return me.Theme
+}
diff --git a/internal/web/store.go b/internal/web/store.go
index b2752e2..c706ff0 100644
--- a/internal/web/store.go
+++ b/internal/web/store.go
@@ -50,7 +50,7 @@ func (a *app) storePage(w http.ResponseWriter, r *http.Request) {
}
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "store", page)
+ a.render(w, r, "store", page)
}
// owner returns the catalogue entry named in the URL when the signed-in
@@ -90,7 +90,7 @@ func (a *app) uninstallPage(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Cache-Control", "no-store")
- a.render(w, "uninstall", struct {
+ a.render(w, r, "uninstall", struct {
Name string
App catalog.Entry
}{a.cfg.Name, e})
diff --git a/internal/web/templates/settings.html b/internal/web/templates/settings.html
index 2d96f9c..cfc36b5 100644
--- a/internal/web/templates/settings.html
+++ b/internal/web/templates/settings.html
@@ -6,6 +6,7 @@
<ul class="people">
<li><div class="who">Base name<small>{{.Name}}</small></div></li>
<li><div class="who">Signed in as<small>{{.Address}}</small></div></li>
+<li><div class="who" id="appearance">Appearance</div><form class="segmented" method="post" action="/settings/appearance" role="group" aria-labelledby="appearance">{{range .Themes}}<button type="submit" name="theme" value="{{.Value}}" aria-pressed="{{.On}}">{{.Label}}</button>{{end}}</form></li>
<li><div class="who">Passkeys<small id="passkeys">{{if .Passkeys}}{{.Passkeys}} added{{else}}None yet{{end}}</small></div>{{if .CanAddPasskey}}{{/* Hidden until the script finds the browser can make a passkey, so with scripts off there is no dead button. */}}<button class="btn ghost" type="button" hidden data-passkey-add data-module="{{.ModuleURL}}" data-begin="{{.RegisterBegin}}" data-finish="{{.RegisterEnd}}" data-rp-name="{{.Name}}" data-user-id="{{.UserID}}" data-user-name="{{.Address}}" data-done="/settings?passkey=added" data-cancelled="No passkey was added." data-failed="That didn't work. Try again." aria-describedby="passkey-msg">Add a passkey</button>{{end}}</li>
{{with .Equipo}}<li><div class="who">Equipo<small>{{if eq . "ready"}}Connected{{else if eq . "pending"}}Waiting for your approval in Equipo{{else if eq . "reconnect"}}Connection expired or removed{{else}}Not connected{{end}}</small></div>{{if eq . "ready"}}<form method="post" action="/ask/disconnect"><button class="btn ghost" type="submit">Disconnect</button></form>{{else if eq . "pending"}}<a class="btn ghost" href="/ask/connect?next=settings">Finish connecting</a>{{else}}<form method="post" action="/ask/connect"><input type="hidden" name="next" value="settings"><button class="btn ghost" type="submit">{{if eq . "reconnect"}}Reconnect Equipo{{else}}Connect Equipo{{end}}</button></form>{{end}}</li>
{{end}}{{if .Connect}}<li><div class="who">Oficina account<small>Not connected</small></div><a class="btn ghost" href="/account/home">{{.ConnectLabel}}</a></li>
diff --git a/internal/webtest/settings_test.go b/internal/webtest/settings_test.go
index a58c7df..95d467e 100644
--- a/internal/webtest/settings_test.go
+++ b/internal/webtest/settings_test.go
@@ -1,6 +1,8 @@
package webtest
import (
+ "net/url"
+ "regexp"
"strings"
"testing"
)
@@ -53,3 +55,65 @@ func TestInnerPagesLinkHome(t *testing.T) {
}
}
}
+
+var appearanceRE = regexp.MustCompile(`(?s)<form class="segmented" method="post" action="/settings/appearance" role="group" aria-labelledby="appearance">(.*?)</form>`)
+
+// pressed is the Appearance choice Settings shows as current.
+func pressed(t *testing.T, body string) string {
+ t.Helper()
+ m := appearanceRE.FindStringSubmatch(body)
+ if m == nil {
+ t.Fatalf("no Appearance choice:\n%s", body)
+ }
+ on := regexp.MustCompile(`<button type="submit" name="theme" value="(\w+)" aria-pressed="true">`).FindAllStringSubmatch(m[1], -1)
+ if len(on) != 1 || len(regexp.MustCompile(`<button type="submit" name="theme" value="(system|light|dark)" aria-pressed="(true|false)">(System|Light|Dark)</button>`).FindAllString(m[1], -1)) != 3 {
+ t.Fatalf("want System, Light and Dark with one pressed:\n%s", m[1])
+ }
+ return on[0][1]
+}
+
+// Appearance follows the device until the member picks Light or Dark in
+// Settings (a plain form): then every page Base draws for them holds it, as
+// <html data-theme>, on every device. System goes back to the device's.
+func TestSettingsAppearance(t *testing.T) {
+ a := newApp(t)
+ a.signedInOwner()
+ page := a.get("/settings").Body
+ if got := pressed(t, page); got != "system" || strings.Contains(page, "data-theme") {
+ t.Fatalf("fresh member: %s pressed, data-theme drawn %v", got, strings.Contains(page, "data-theme"))
+ }
+ for _, theme := range []string{"light", "dark", "system"} {
+ if r := a.post("/settings/appearance", url.Values{"theme": {theme}}); r.Code != 303 || r.Location() != "/settings" {
+ t.Fatalf("%s: %d %q", theme, r.Code, r.Location())
+ }
+ want := `<html lang="en" data-theme="` + theme + `">`
+ if theme == "system" {
+ want = `<html lang="en">`
+ }
+ page := a.get("/settings").Body
+ if got := pressed(t, page); got != theme {
+ t.Errorf("after %s: %s pressed", theme, got)
+ }
+ for _, path := range []string{"/settings", "/", "/people", "/store"} {
+ if body := a.get(path).Body; !strings.Contains(body, want) {
+ t.Errorf("after %s, %s lacks %s", theme, path, want)
+ }
+ }
+ }
+ other := a.newBrowser()
+ other.signedInOwner()
+ a.post("/settings/appearance", url.Values{"theme": {"dark"}})
+ if body := other.get("/").Body; !strings.Contains(body, `data-theme="dark"`) {
+ t.Error("the member's other browser doesn't hold Dark")
+ }
+ for _, bad := range []url.Values{{"theme": {"purple"}}, {}} {
+ if r := a.post("/settings/appearance", bad); r.Code != 400 {
+ t.Errorf("%v: %d, want 400", bad, r.Code)
+ }
+ }
+ // Signed out there is no member: the sign-in page follows the device.
+ a.post("/auth/signout", nil)
+ if body := a.get("/signin").Body; strings.Contains(body, "data-theme") {
+ t.Error("the sign-in page forces a theme")
+ }
+}