diff --git a/internal/gui/appearance.go b/internal/gui/appearance.go index e8e915b9d..cd4cc457b 100644 --- a/internal/gui/appearance.go +++ b/internal/gui/appearance.go @@ -134,6 +134,9 @@ var ( // the header switch's thumb (--seg-thumb over --seg-track) lightPick = rgb{0xe9, 0xe9, 0xee} darkPick = rgb{0x4c, 0x4c, 0x52} + // the dark theme's chosen thumb before it is tinted (--mark-fill): the + // header switch's thumb as it reads over the page + darkFill = rgb{0x3a, 0x3a, 0x3f} // how much of the theme's background lies over the picture wallVeil = "color-mix(in srgb,var(--bg) 84%,transparent)" ) @@ -147,21 +150,34 @@ func accentOn(c rgb, dark bool) rgb { return inkOn(c, black, lightBg) } -// inkOn is c moved toward toward just enough to read as text on against. -func inkOn(c, toward, against rgb) rgb { +// inkOn is c moved toward toward just enough to read as text on each of +// against. +func inkOn(c, toward rgb, against ...rgb) rgb { + reads := func(o rgb) bool { + for _, bg := range against { + if contrast(o, bg) < accentInk { + return false + } + } + return true + } out := c - for p := 0.0; p <= 1 && contrast(out, against) < accentInk; p += 0.02 { + for p := 0.0; p <= 1 && !reads(out); p += 0.02 { out = c.mix(toward, p) } return out } // accentVars are the theme's --accent, its soft fill, the text on it, the -// selection, and --mark, from c. --mark is the ink of what is chosen (the -// open page's sidebar icon, a switch's or tab's chosen option), magpie's -// own text colour without an accent of the user's, as a Mac's Graphite: -// without it a colour picked showed nowhere on Settings, nor on most pages -// (CHENGJIAHEGOXIS on X, 「选中任意强调色没反应」). +// selection, --mark and --mark-fill, from c. --mark is the ink of what is +// chosen (the open page's sidebar icon, a switch's or tab's chosen +// option), magpie's own text colour without an accent of the user's, as a +// Mac's Graphite: without it a colour picked showed nowhere on Settings, +// nor on most pages (CHENGJIAHEGOXIS on X, 「选中任意强调色没反应」). +// --mark-fill is the ground under it, a segmented control's thumb or a +// chosen tab's, tinted with the colour: a grey thumb under a coloured word +// still read as grey in the dark theme (「主题深色依然还是灰色」). It is +// unset without an accent, so each keeps its own grey there. func accentVars(c rgb, dark bool) string { a := accentOn(c, dark) fg := white @@ -169,12 +185,14 @@ func accentVars(c rgb, dark bool) string { fg = rgb{0x14, 0x14, 0x1a} } soft, sel := white.mix(a, 0.09), white.mix(a, 0.11) - mark := inkOn(c, black, lightPick) + fill := white.mix(a, 0.12) + mark := inkOn(c, black, lightPick, fill) if dark { soft, sel = darkBg.mix(a, 0.14), darkBg.mix(a, 0.2) - mark = inkOn(c, white, darkPick) + fill = darkFill.mix(a, 0.26) + mark = inkOn(c, white, darkPick, fill) } - return fmt.Sprintf("--accent:%s;--accent-soft:%s;--accent-fg:%s;--sel:%s;--mark:%s", a.hex(), soft.hex(), fg.hex(), sel.hex(), mark.hex()) + return fmt.Sprintf("--accent:%s;--accent-soft:%s;--accent-fg:%s;--sel:%s;--mark:%s;--mark-fill:%s", a.hex(), soft.hex(), fg.hex(), sel.hex(), mark.hex(), fill.hex()) } // appearanceRoutes serve the look's stylesheet and the wallpaper, and take diff --git a/internal/gui/appearance_test.go b/internal/gui/appearance_test.go index 193a1f97c..3ee46590e 100644 --- a/internal/gui/appearance_test.go +++ b/internal/gui/appearance_test.go @@ -84,7 +84,7 @@ func TestAccentSetting(t *testing.T) { // Whatever colour is picked, the accent drawn reads as text on the // theme's background and cards, and the text on it reads too. func TestAccentReadable(t *testing.T) { - re := regexp.MustCompile(`--accent:(#[0-9a-f]{6});--accent-soft:(#[0-9a-f]{6});--accent-fg:(#[0-9a-f]{6});--sel:#[0-9a-f]{6};--mark:(#[0-9a-f]{6})$`) + re := regexp.MustCompile(`--accent:(#[0-9a-f]{6});--accent-soft:(#[0-9a-f]{6});--accent-fg:(#[0-9a-f]{6});--sel:#[0-9a-f]{6};--mark:(#[0-9a-f]{6});--mark-fill:(#[0-9a-f]{6})$`) for _, pick := range []string{"#ffffff", "#000000", "#ffff00", "#00ff00", "#0d9488", "#2563eb", "#ea580c", "#52525b", "#808080", "#1a1a1e", "#f4f4f6"} { c, _ := parseHex(pick) for _, dark := range []bool{false, true} { @@ -110,9 +110,11 @@ func TestAccentReadable(t *testing.T) { // a colour picked showed nowhere on Settings), and reads as text // on every surface a chosen option sits on mark, _ := parseHex(m[4]) - on := []rgb{lightBg, white, lightPick} + // and on the tinted thumb under it (「主题深色依然还是灰色」) + fill, _ := parseHex(m[5]) + on := []rgb{lightBg, white, lightPick, fill} if dark { - on = []rgb{darkBg, darkCard, darkPick} + on = []rgb{darkBg, darkCard, darkPick, fill} } for _, bg := range on { if r := contrast(mark, bg); r < 4.4 { @@ -121,6 +123,16 @@ func TestAccentReadable(t *testing.T) { } } } + // the chosen thumb is tinted with the colour in both themes, not left + // grey (CHENGJIAHEGOXIS on X, 「主题深色依然还是灰色」) + for _, dark := range []bool{false, true} { + c, _ := parseHex("#7c3aed") + m := re.FindStringSubmatch(accentVars(c, dark)) + f, _ := parseHex(m[5]) + if f[2]-f[1] < 12 { + t.Errorf("dark=%v: the chosen thumb %s is still grey", dark, m[5]) + } + } // a colour that reads already is drawn as picked c, _ := parseHex("#2563eb") if got := accentVars(c, false); !strings.HasPrefix(got, "--accent:#2563eb;") || !strings.Contains(got, ";--mark:#") { diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 3b1d9f3ae..e9db1f9f4 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -27,6 +27,8 @@ tab's chosen option. The text's own, graphite as a Mac's sidebar is, until an accent of the user's own takes it (appearance.go accentVars) */ --mark: var(--fg); + /* the surface under it, a thumb or a chosen tab's ground, is left unset: + each keeps its own grey (var(--mark-fill, …)) until an accent tints it */ --green: #189a58; --green-soft: #e4f6ec; --red: #d64545; @@ -281,7 +283,7 @@ body:not(.window.linux) #winclose { display: none; } display: inline-flex; padding: 2px; border-radius: 8px; /* no grey track behind the tabs: only the open one's thumb */ } -.seg > .thumb { border-radius: 6px; background: var(--seg-thumb); box-shadow: var(--seg-edge); } +.seg > .thumb { border-radius: 6px; background: var(--mark-fill, var(--seg-thumb)); box-shadow: var(--seg-edge); } body.panel .seg { display: none; } .seg button { position: relative; z-index: 1; white-space: nowrap; height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--ctl-fg); transition: color .18s var(--ease), transform .14s var(--ease); } .seg button.on { color: var(--mark); } @@ -3229,7 +3231,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } #gatewayKeys .klf-which { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; } #gatewayKeys .klf-tab { height: 24px; padding: 0 10px; border-radius: 6px; font-size: 12px; color: var(--ctl-fg); white-space: nowrap; } #gatewayKeys .klf-tab:hover:not(.on) { color: var(--fg-2); } -#gatewayKeys .klf-tab.on { color: var(--mark); background: var(--seg-thumb); box-shadow: var(--seg-edge); } +#gatewayKeys .klf-tab.on { color: var(--mark); background: var(--mark-fill, var(--seg-thumb)); box-shadow: var(--seg-edge); } @media (max-width: 520px) { #gatewayKeys .klf, #gatewayKeys .klf.with-days { grid-template-columns: 1fr; } #gatewayKeys .klf-used { flex-wrap: wrap; } } /* the models a key may use (#882): a long model's id is cut, and the badge gives way first on a narrow window */ @@ -3720,7 +3722,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va .opt:hover:not(.on) { color: var(--fg-2); } .thumb { position: absolute; top: 2px; bottom: 2px; left: 0; width: 0; border-radius: 6px; - background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06); + background: var(--mark-fill, var(--card)); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06); transition: opacity .15s; /* the glide is slide()'s, which only it starts */ pointer-events: none; } @@ -4011,7 +4013,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va .warm-tabs { display: flex; align-items: center; gap: 2px; margin-left: -7px; } .warm-tabs button { height: 22px; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); transition: color .12s, background-color .12s; } .warm-tabs button:hover:not(.on) { color: var(--fg-2); } -.warm-tabs button.on { color: var(--mark); background: var(--pill); } +.warm-tabs button.on { color: var(--mark); background: var(--mark-fill, var(--pill)); } .warm-tabs button[hidden] { display: none; } /* the page's parts (#471): a tab each at the top in the same look, a line more when they don't fit across (a narrow window, a larger text size), @@ -4761,7 +4763,7 @@ body.panel .modal { padding: 16px 12px; } .editor.importapps .apptabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: var(--pill); overflow-x: auto; scrollbar-width: none; } .editor.importapps .apptab { flex: 1 1 0; min-width: max-content; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; } .editor.importapps .apptab:hover { color: var(--fg); } -.editor.importapps .apptab.on { background: var(--card); color: var(--mark); box-shadow: 0 1px 2px rgba(0,0,0,.18); } +.editor.importapps .apptab.on { background: var(--mark-fill, var(--card)); color: var(--mark); box-shadow: 0 1px 2px rgba(0,0,0,.18); } .editor.importapps .apptab.missing .applogo { filter: grayscale(1); opacity: .5; } .editor.importapps .apptab .count { min-width: 16px; padding: 0 5px; border-radius: 8px; font-size: 10.5px; line-height: 16px; text-align: center; color: var(--fg-2); background: var(--line); } .editor.importapps .apptab.missing .count { background: none; color: var(--faint); } @@ -4979,7 +4981,7 @@ body.window .row.agent .who.with-models { flex-wrap: wrap; row-gap: 0; } .am-search:focus-within { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); } .am-seg { display: inline-flex; flex: none; padding: 2px; border-radius: 8px; background: var(--seg-track); } .am-seg button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: none; color: var(--ctl-fg); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s, color .15s; } -.am-seg button.on { background: var(--seg-thumb); color: var(--mark); box-shadow: var(--seg-edge); } +.am-seg button.on { background: var(--mark-fill, var(--seg-thumb)); color: var(--mark); box-shadow: var(--seg-edge); } .am-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; } /* the providers down the left (蓝猫 on Discord), the models of the one picked beside them, each scrolling on its own */ @@ -5422,7 +5424,7 @@ body .row.agent .ag-prefs .row.pref .who { display: block; } .rate-win { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; } .rate-win .day-chips { display: flex; gap: 2px; } .rate-win .day-chip { min-width: 24px; height: 24px; padding: 0 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--muted); font: inherit; font-size: 11px; } -.rate-win .day-chip.on { color: var(--mark); background: var(--seg-thumb); box-shadow: var(--seg-edge); } +.rate-win .day-chip.on { color: var(--mark); background: var(--mark-fill, var(--seg-thumb)); box-shadow: var(--seg-edge); } .rate-win input { width: 64px; height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--fg); font: inherit; font-size: 12px; } .rate-win .rate-rate { width: 56px; } .rate-win .rate-dash { color: var(--muted); } diff --git a/internal/gui/assets/context.css b/internal/gui/assets/context.css index 4846608ea..1e1b186b1 100644 --- a/internal/gui/assets/context.css +++ b/internal/gui/assets/context.css @@ -425,7 +425,7 @@ i.dot.free { background: var(--k-free); box-shadow: inset 0 0 0 1px color-mix(in .ctx-look-b { display: inline-grid; place-items: center; width: 24px; height: 20px; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--faint); cursor: pointer; transition: background-color .2s ease, color .2s ease, box-shadow .2s ease; } .ctx-look-b svg { fill: currentColor; } .ctx-look-b:hover { color: var(--fg-2); } -.ctx-look-b.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px color-mix(in srgb, var(--fg) 10%, transparent); } +.ctx-look-b.on { background: var(--mark-fill, var(--card)); color: var(--mark); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px color-mix(in srgb, var(--fg) 10%, transparent); } /* an image the request carried, in its text */ .ctx-pic { display: block; width: fit-content; max-width: 100%; margin: 4px 0 2px; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--fg) 4%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--fg) 9%, transparent); cursor: zoom-in; transform-origin: top left; opacity: 0; transition: opacity .25s ease; } diff --git a/internal/gui/assets/plugins/sessions/sessions.css b/internal/gui/assets/plugins/sessions/sessions.css index dd3e680fe..cdb5bcd7b 100644 --- a/internal/gui/assets/plugins/sessions/sessions.css +++ b/internal/gui/assets/plugins/sessions/sessions.css @@ -5,7 +5,7 @@ .segs.sm-agents { background: var(--seg-track); } .sm-agents .opt:not(.on, :hover) { color: var(--ctl-fg); } .sm-agents .opt { display: inline-flex; align-items: center; gap: 5px; } -.sm-agents .opt.on { background: var(--seg-thumb); box-shadow: var(--seg-edge); } +.sm-agents .opt.on { background: var(--mark-fill, var(--seg-thumb)); box-shadow: var(--seg-edge); } .sm-agents .opt.on em { color: var(--muted); } .sm-agents .opt .ic { width: 13px; height: 13px; } .sm-agent-pick { min-width: 0; max-width: 220px; gap: 6px; color: var(--fg); } diff --git a/internal/gui/tests/appearance-look.test.cjs b/internal/gui/tests/appearance-look.test.cjs index 81ae7848e..fc7ea351e 100644 --- a/internal/gui/tests/appearance-look.test.cjs +++ b/internal/gui/tests/appearance-look.test.cjs @@ -22,11 +22,13 @@ const assets = path.resolve(__dirname, "../assets"); // a 1×1 PNG const PNG = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", "base64"); // as appearance.go's lookCSS draws it: the light theme's, then the dark -// one's, --mark the ink of what is chosen +// one's, --mark the ink of what is chosen and --mark-fill the thumb under it const DARK = { "#0d9488": "#5cc9bd", "#db2777": "#f08cbd", "#7c3aed": "#c4a6f8" }; -const accentCSS = (a) => (a ? `html:not(.omarchy):root{--accent:${a};--accent-soft:#e6f4f2;--accent-fg:#ffffff;--sel:#e1f1ef;--mark:${a}} -@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme="light"]){--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a}}} -html:not(.omarchy):root[data-theme="dark"]{--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a}}` : ""); +const FILL = { "#0d9488": ["#e2efee", "#325354"], "#db2777": ["#f9e5ee", "#664155"], "#7c3aed": ["#efe7fd", "#55486e"] }; +const fill = (a, dark) => (FILL[a] || ["#eeeeee", "#444444"])[dark ? 1 : 0]; +const accentCSS = (a) => (a ? `html:not(.omarchy):root{--accent:${a};--accent-soft:#e6f4f2;--accent-fg:#ffffff;--sel:#e1f1ef;--mark:${a};--mark-fill:${fill(a)}} +@media (prefers-color-scheme: dark){html:not(.omarchy):root:not([data-theme="light"]){--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a};--mark-fill:${fill(a, 1)}}} +html:not(.omarchy):root[data-theme="dark"]{--accent:${DARK[a] || a};--accent-soft:#1a2c2e;--accent-fg:#14141a;--sel:#1a3435;--mark:${DARK[a] || a};--mark-fill:${fill(a, 1)}}` : ""); function serve(st, log) { const settings = () => ({ lang: "en", theme: "light", searchVendors: [], searchAPIs: [], ...st }); @@ -156,6 +158,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const sel = ["#themeSegs .opt.on", "#birdSegs .opt.on", "body.side-nav #prefs.on svg"]; const before = await settled(page, sel); same(before, before.fg, "magpie's own look: what is chosen is in the text's ink"); + // 「主题深色依然还是灰色」: the chosen option's thumb is tinted too, + // and is its own grey, exactly as before, with no accent + const thumbs = ["#themeSegs .segs > .thumb", "#birdSegs .segs > .thumb", "#reduceMotionSegs .segs > .thumb"]; + const grounds = () => page.evaluate((sel) => sel.map((s) => { const e = document.querySelector(s); return e ? getComputedStyle(e).backgroundColor : "missing " + s; }), thumbs); + const card = await page.evaluate(() => { const p = document.createElement("i"); p.style.background = "var(--card)"; document.body.append(p); const c = getComputedStyle(p).backgroundColor; p.remove(); return c; }); + assert.deepEqual(await grounds(), thumbs.map(() => card), "magpie's own look: the thumb is the card's grey"); + const rgbOf = (h) => `rgb(${parseInt(h.slice(1, 3), 16)}, ${parseInt(h.slice(3, 5), 16)}, ${parseInt(h.slice(5, 7), 16)})`; for (const [v, light] of [["#0d9488", "#0d9488"], ["#db2777", "#db2777"]]) { await page.locator(`#accentPick .swatch[data-accent="${v}"]`).click(); const want = theme === "dark" ? DARK[v] : light; @@ -163,11 +172,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const r = await settled(page, sel); assert.notEqual(r.mark, r.fg); same(r, r.mark, `${v}: what is chosen is in the colour picked`); + assert.deepEqual(await grounds(), thumbs.map(() => rgbOf(fill(v, theme === "dark"))), `${v}: the chosen thumb is tinted`); } await page.locator('#accentPick .swatch[data-accent=""]').click(); await page.waitForFunction(() => !document.getElementById("lookCSS")?.textContent); const back = await settled(page, sel); same(back, back.fg, "back to magpie's own"); + assert.deepEqual(await grounds(), thumbs.map(() => card), "back to magpie's own thumb"); assert.deepEqual(errors, []); });