gui: the add sheet's Partners heading lights once an opening

The owner asked for an elegant light on the Partners heading each time
Add provider takes the view to the sheet, and picked the traced outline
of three drafts. A 1px hairline (a conic gradient on an animated
@property angle, masked to the border) runs once round the heading's
words over 1.8s and fades, over a faint wash of the accent; it follows
--accent, so it reads in both themes, and keeps to the heading's own
padding box, inside the sheet.

It plays when the heading is fully in view (an IntersectionObserver on
the providers view), once per opening of the sheet: a search or a reload
drawing the sheet again doesn't play it, closing and opening it does
(partnersShone, reset where partnersCounted is). With the system's
reduced motion or Settings' Reduce motion (#3813, calm() and holdStill)
it isn't drawn. The outline's elements are <i>, so the heading's hint
stays its only span, which the add-sheet and partners tests read.

The core's scripts are 1,528,076 bytes, their budget raised to it with
no room added; app.js stays under its own.

Run at this head, on mote: TestCoreScriptBudget ok; the 59 GUI files
that open the add sheet (grep addProvider|#addSheet) and
reduce-motion and settings-general, chromium and webkit: 826 of 826 ok
(at --test-concurrency=2; at 4, on mote at load ~230 from other runs,
8 chromium sign-in cases timed out at 5s and passed 28 of 28 alone).
add-partners-shine.test.cjs: en zh ja de at 900 and 440px, lit once on
open, not again after a search, again after close and reopen, the
outline round the words and inside the sheet, none under either reduced
motion.
Broken by hand: without the partnersShone check every redraw lights it
again, and the test is red in all 8 language/width cases.
Not run: the whole GUI suite (the change adds no API call and its
classes are scoped to the add sheet's heading); not seen on Windows'
WebView2 or WebKitGTK, where @property and mask-composite are supported
but the motion wasn't watched.
This commit is contained in:
yetone
2026-10-28 17:52:16 +08:00
parent 51247a55b2
commit 33af28ed6b
4 changed files with 158 additions and 2 deletions
+12
View File
@@ -2873,6 +2873,18 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.sheet .kind { display: flex; align-items: baseline; gap: 8px; padding: 22px 8px 6px; font-size: 12px; }
.sheet .kind b { font-size: 13px; font-weight: 600; color: var(--fg); }
.sheet .kind span { color: var(--faint); }
/* Partners' light (shinePartners): a hairline runs once round the heading
and fades, over a breath of the accent; nothing with reduced motion */
@property --shine-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.sheet .kind.shine { position: relative; width: fit-content; }
.sheet .kind.shine i { position: absolute; inset: 17px 0 1px; border-radius: 8px; opacity: 0; pointer-events: none; }
.sheet .kind.shine .glow { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.sheet .kind.shine .ring { padding: 1px; background: conic-gradient(from var(--shine-a), transparent 0deg 250deg, color-mix(in srgb, var(--accent) 35%, transparent) 300deg, var(--accent) 345deg, transparent 360deg); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
.sheet .kind.lit .ring { animation: shine-trace 1.8s cubic-bezier(.5, 0, .3, 1); }
.sheet .kind.lit .glow { animation: shine-glow 1.8s ease-out; }
@keyframes shine-trace { 0% { --shine-a: 0deg; opacity: 0; } 15%, 70% { opacity: 1; } 100% { --shine-a: 360deg; opacity: 0; } }
@keyframes shine-glow { 35% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet .kind.shine i { display: none; } }
/* a removed account: its name, then Add it back and Sign out… side by
side, across the row (#694) */
.sheet .tile.removed { grid-column: 1 / -1; }
+23 -1
View File
@@ -78,6 +78,8 @@ let adding = false; // the preset sheet is open
// the partners counted as shown since the sheet opened: once an opening,
// however often it is drawn (countPartner)
let partnersCounted = null;
// the Partners heading's light has run since the sheet opened (shinePartners)
let partnersShone = false;
let importing = null; // a magpie://import link waiting for a yes: { provider, error, replaces }
let importingApps = null; // the Import from other apps dialog: { sources, picks }
let providerDiscovery = []; // only opaque fingerprints and app names, never credentials
@@ -7029,6 +7031,25 @@ function pickForAgent(a, p, btn, ev) {
openPicker(agent, field, btn, ev, (o) => pre.test(o.value));
}
// shinePartners: a hairline of light runs once round the Partners heading
// when the sheet opens, as the reader reaches it (the owner picked it, of
// three). Once an opening: a search or a reload drawing it again doesn't.
function shinePartners(k) {
if (partnersShone || calm()) return;
k.classList.add("shine");
k.append(el("i", "glow"), el("i", "ring"));
const seen = new IntersectionObserver(([en]) => {
// a redraw's new heading takes over from this one
if (!k.isConnected) return seen.disconnect();
if (!en.isIntersecting || !adding) return;
seen.disconnect();
if (partnersShone) return;
partnersShone = true;
k.classList.add("lit");
}, { root: $("#view-providers"), threshold: 1 });
seen.observe(k);
}
// The add sheet: presets first (a key is all they need), custom last.
let presetQuery = "", addReturnPick = null;
function renderAdd() {
@@ -7049,7 +7070,7 @@ function renderAdd() {
setRoom(view, 0);
}
sheet.hidden = !adding;
if (!adding) partnersCounted = null;
if (!adding) { partnersCounted = null; partnersShone = false; }
// Duplicate and Add another open a new provider's editor with no sheet
if (!adding) return editing && typeof editing === "object" ? renderEditor(null, editing.preset) : null;
const head = el("div", "row-head");
@@ -7108,6 +7129,7 @@ function renderAdd() {
if (partners.length) {
any = true;
const grid = section("Partners", "magpie's sponsors");
shinePartners(grid.previousElementSibling);
// a new one's tile keeps a dot until opened (partnerTile)
newPartnerTiles ??= new Set();
for (const p of partners) if (p.new && !p.added) newPartnerTiles.add(p.id);
File diff suppressed because one or more lines are too long
@@ -0,0 +1,122 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The Partners heading's light (yetone: 每次点击"添加供应商"……要有一个优雅、
// 精致、让人舒服的流光动画; the owner picked the traced outline): once the
// sheet opens and the heading is in view, a hairline runs round it and
// fades. Once an opening: a search drawing the sheet again doesn't play it,
// closing and opening it again does. The outline wraps the heading's words
// and stays in the sheet, and with reduced motion, the system's or
// Settings' (#3813), there is none.
// English, Chinese, Japanese and German, at 900px and 440px; no backend.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const partners = [
{ id: "acme", name: "Acme AI", icon: "generic", kind: "partner", sponsored: true, chat: "https://api.acme.example.com/v1" },
{ id: "beta", name: "Beta Relay", icon: "generic", kind: "partner", sponsored: true, chat: "https://api.beta.example.com/v1" },
];
const presets = [{ id: "openai", name: "OpenAI", icon: "openai", kind: "vendor", chat: "https://api.openai.example.com/v1" }];
// one provider already, so the page is the list with its Add provider
const providers = [{ id: "openai", name: "OpenAI", icon: "openai", preset: "openai", models: [], agents: [], key: { set: true, masked: "sk-…ab12" } }];
function server(lang, prefs = {}) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/api/partner") return route.fulfill({ status: 204, body: "" });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", web: false, ...prefs })};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", ...prefs } });
if (url.pathname === "/api/providers") return json({ providers, presets: [...partners, ...presets], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const L = { en: "Partners", zh: "合作伙伴", ja: "パートナー", de: "Partner" };
// the heading as drawn now: whether it lit, what plays on it, and where its
// outline sits against its words and the sheet
const look = (page) => page.locator("#addSheet .kind").first().evaluate((k) => {
const r = (e) => e.getBoundingClientRect();
const ring = k.querySelector("i.ring"), sheet = r(k.closest("#addSheet")), o = ring && r(ring);
const words = [r(k.querySelector("b")), r(k.querySelector("span"))];
return {
shine: k.classList.contains("shine"), lit: k.classList.contains("lit"),
plays: k.getAnimations({ subtree: true }).map((a) => a.animationName).sort(),
wraps: !!o && words.every((w) => w.left >= o.left && w.right <= o.right && w.top >= o.top && w.bottom <= o.bottom),
inSheet: !!o && o.left >= sheet.left && o.right <= sheet.right,
spans: k.querySelectorAll("span").length,
};
});
async function open(page) {
await page.locator("#addProvider").click();
await page.locator("#addSheet .tile").first().waitFor();
await page.locator("#addSheet .kind.lit").first().waitFor();
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Partners heading lights once an opening", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(L)) for (const width of [900, 440]) {
await t.test(lang + " " + width, async () => {
const page = await (await browser.newContext({ viewport: { width, height: 800 } })).newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=providers");
await open(page);
assert.equal(await page.locator("#addSheet .kind b").first().textContent(), L[lang]);
let h = await look(page);
assert(h.shine && h.lit);
assert.deepEqual(h.plays, ["shine-glow", "shine-trace"]);
assert(h.wraps, "the outline wraps the heading's words");
assert(h.inSheet, "the outline stays in the sheet");
assert.equal(h.spans, 1, "the hint stays the heading's only span");
// a search draws the sheet again; the light doesn't play again
const find = page.locator("#addSheet input").first();
await find.fill("a");
await find.fill("");
await page.locator("#addSheet .kind").first().waitFor();
h = await look(page);
assert(!h.shine && !h.lit);
assert.deepEqual(h.plays, []);
// closed and opened again, it does
await page.keyboard.press("Escape");
if (await page.locator("#addSheet").isVisible()) await page.keyboard.press("Escape");
await page.locator("#addSheet").waitFor({ state: "hidden" });
await open(page);
h = await look(page);
assert(h.lit);
assert.deepEqual(h.plays, ["shine-glow", "shine-trace"]);
assert.deepEqual(errors, []);
await page.context().close();
});
}
for (const [name, ctx, prefs] of [["the system's reduced motion", { reducedMotion: "reduce" }, {}], ["Settings' Reduce motion", {}, { reduceMotion: true }]]) await t.test(name, async () => {
const page = await (await browser.newContext({ viewport: { width: 900, height: 800 }, ...ctx })).newPage();
await page.route("**/*", server("en", prefs));
await page.goto("http://magpie.test/?view=providers");
await page.locator("#addProvider").click();
await page.locator("#addSheet .tile").first().waitFor();
const h = await look(page);
assert(!h.shine && !h.lit);
assert.equal(await page.locator("#addSheet .kind i").count(), 0);
assert.deepEqual(h.plays, []);
await page.context().close();
});
});
}