Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: a dialog grows out of the row that opened it and folds back into it

yetoned9d1680ab674
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 01b0d43f9..00af998e6 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -8460,6 +8460,26 @@ function fromRect(from, to) {
const dx = from.left + from.width / 2 - (to.left + to.width / 2), dy = from.top + from.height / 2 - (to.top + to.height / 2);
return `translate(${dx}px, ${dy}px) scale(${s})`;
}
+// morphFrom: the dialog drawn as the rect it grows out of — moved over it,
+// scaled, and clipped to its shape. A provider row is wider than the
+// dialog, so scale alone left it a full-size dialog sliding in from the
+// row's middle (the owner: "从右上角弹出"); clipped, it opens as a strip
+// the row's height that grows into the dialog, and closes back into it.
+// At rest the clip stands clear of the dialog so its shadow shows all the
+// way (inset can go negative in both engines).
+const MORPH_REST = "inset(-100px round 14px)";
+function morphFrom(from, to) {
+ const s = Math.max(.3, Math.min(1, from.width / to.width));
+ const w = Math.min(to.width, from.width / s), h = Math.min(to.height, from.height / s);
+ const r = Math.min(10, from.height / 2) / s;
+ return { transform: fromRect(from, to), clipPath: `inset(${(to.height - h) / 2}px ${(to.width - w) / 2}px round ${r}px)` };
+}
+// VEIL_OFF: the backdrop gone. It is the modal's own background and blur, so
+// fading the modal's opacity faded the dialog in it too, and a dialog
+// folding back into its row was all but gone halfway there; the backdrop
+// fades by itself instead.
+const VEIL_OFF = { backgroundColor: "rgba(0, 0, 0, 0)", backdropFilter: "blur(0px) saturate(1)", webkitBackdropFilter: "blur(0px) saturate(1)" };
+const unveil = (m) => { for (const p of ["opacity", "background-color", "backdrop-filter", "-webkit-backdrop-filter"]) m.style.removeProperty(p); };
let modalReturnFocus = null, modalFormBase = "";
function formValues(box) {
return JSON.stringify([
@@ -8634,15 +8654,28 @@ function openModal(content) {
holdModal();
if (!fresh) return;
for (const a of [...m.getAnimations(), ...d.getAnimations()]) a.cancel();
- d.style.opacity = d.style.transform = m.style.opacity = "";
+ d.style.opacity = d.style.transform = d.style.clipPath = "";
+ unveil(m);
modalDone = null;
modalOrigin = pressed && performance.now() - pressed.time < 1000 ? pressed : null;
pressed = null;
- m.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 280, easing: "ease-out" });
+ m.animate([{ ...VEIL_OFF, offset: 0 }], { duration: 280, easing: "ease-out" });
if (calm()) { d.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 160 }); return; }
const to = d.getBoundingClientRect(), from = originRect(modalOrigin);
- d.animate([{ transform: from ? fromRect(from, to) : "translateY(24px) scale(.94)" }, { transform: "none" }], { duration: 570, easing: SPRING });
- d.animate([{ opacity: 0 }, { opacity: 1 }], { duration: from ? 200 : 240, easing: "ease-out" });
+ const grow = d.animate(from ? [morphFrom(from, to), { transform: "none", clipPath: MORPH_REST }] : [{ transform: "translateY(24px) scale(.94)" }, { transform: "none" }], { duration: 570, easing: SPRING });
+ d.animate([{ opacity: 0 }, { opacity: 1 }], { duration: from ? 140 : 240, easing: "ease-out" });
+ if (!from) return;
+ // an editor can settle its size after it was measured (a provider's grew
+ // 30px shorter as it filled in), which left the strip off the row; while
+ // it grows, the start follows the size it has now
+ const x0 = d.offsetLeft, y0 = d.offsetTop;
+ const follow = new ResizeObserver(() => {
+ const now = { left: to.left + d.offsetLeft - x0, top: to.top + d.offsetTop - y0, width: d.offsetWidth, height: d.offsetHeight };
+ grow.effect.setKeyframes([morphFrom(from, now), { transform: "none", clipPath: MORPH_REST }]);
+ });
+ follow.observe(d);
+ const stop = () => follow.disconnect();
+ grow.finished.then(stop, stop);
}
// frame holds an editor's head and its buttons still while the fields
// between them scroll.
@@ -8666,14 +8699,17 @@ function closeModal() {
d.style.transform = "none";
const to = d.getBoundingClientRect(), from = calm() ? null : originRect(modalOrigin);
d.style.transform = was;
+ const clip = d.style.clipPath || MORPH_REST;
const shape = { duration: from ? 380 : 260, easing: IOS_EASE, fill: "forwards" };
const moves = [
- m.animate([{ opacity: 0 }], { ...shape, easing: "ease-out" }),
+ m.animate([VEIL_OFF], { ...shape, easing: "ease-out" }),
calm() ? d.animate([{ opacity: 0 }], { duration: 140, fill: "forwards" })
- : d.animate([{ transform: from ? fromRect(from, to) : "translateY(14px) scale(.95)" }], shape),
+ : d.animate(from ? [{ transform: was || "none", clipPath: clip }, morphFrom(from, to)] : [{ transform: "translateY(14px) scale(.95)" }], shape),
];
- // it fades as it lands, the last part of the way
- if (!calm()) moves.push(d.animate([{ offset: from ? .45 : .2, opacity: getComputedStyle(d).opacity }, { opacity: 0 }], shape));
+ // it fades as it lands, the last part of the time: on the shape's own
+ // easing an offset is of the way, and IOS_EASE has gone ~90% of it by half
+ // the time, so a dialog folding back was all but gone halfway there
+ if (!calm()) moves.push(d.animate([{ offset: from ? .6 : .2, opacity: getComputedStyle(d).opacity, easing: "ease-in" }, { opacity: 0 }], { ...shape, easing: "linear" }));
const done = modalDone = Promise.all(moves.map((a) => a.finished)).then(() => {
if (modalDone !== done) return;
modalDone = null;
@@ -8687,7 +8723,8 @@ function closeModal() {
else if (!$("#view-" + view).hidden) $("#view-" + view).focus({ preventScroll: true });
modalReturnFocus = null;
for (const a of [...m.getAnimations(), ...d.getAnimations()]) a.cancel();
- d.style.opacity = d.style.transform = m.style.opacity = "";
+ d.style.opacity = d.style.transform = d.style.clipPath = "";
+ unveil(m);
// an editor opened from the add sheet gives the focus back to its option
const sheet = $("#addSheet");
if (adding && !sheet.hidden && !$("#view-providers").hidden) {
diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go
index b7c392dab..d6f09f3c6 100644
--- a/internal/gui/core_budget_test.go
+++ b/internal/gui/core_budget_test.go
@@ -15,7 +15,7 @@ import (
// so a page can't quietly grow back into the core; a change that needs more
// raises them and says why in its commit.
const (
- appScriptBudget = 1_292_000 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%
+ appScriptBudget = 1_292_000 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20)
coreScriptBudget = 1_469_000 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it
)
diff --git a/internal/gui/tests/modal-morph.test.cjs b/internal/gui/tests/modal-morph.test.cjs
new file mode 100644
index 000000000..3288df35b
--- /dev/null
+++ b/internal/gui/tests/modal-morph.test.cjs
@@ -0,0 +1,155 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// A provider's editor grows out of the row that was clicked and folds back
+// into it (the owner, 10-20: it came from the top right or a lower corner,
+// not from the provider, unlike iOS). A row is wider than the dialog, so a
+// scale alone left a full-size dialog sliding in from the row's middle; the
+// dialog is clipped to the row's shape too. Held at the start of the
+// opening and at the end of the closing, what shows of the dialog is a
+// strip over the row: the row's height, centred on it, inside it. At rest
+// nothing is clipped, the shadow included. Halfway back it still shows,
+// only the backdrop fading. Reduced motion only fades. Wide and narrow,
+// Chromium and WebKit; no backend, the API is faked here.
+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 provider = (id, name) => ({
+ id, name, icon: "generic", chat: `https://api.${id}.example/v1`, url: `https://api.${id}.example/v1`, host: `api.${id}.example`, responses: "", anthropic: "", catalog: "",
+ models: [{ id: "m1", name: "", on: true }, { id: "m2", name: "", on: true }],
+ agents: [], fallback: [], headers: {}, keyList: [], proxy: "", key: { set: true, masked: "sk-…1234" }, ready: true,
+});
+
+function serve() {
+ const settings = { theme: "light", lang: "en", tray: "panel", currency: "usd" };
+ const providers = { providers: ["alpha", "beta", "gamma", "delta", "epsilon", "zeta"].map((id) => provider(id, id[0].toUpperCase() + id.slice(1))), presets: [], excluded: [], gateway: { running: true, window: true } };
+ return async (route) => {
+ const url = new URL(route.request().url());
+ const json = (data) => route.fulfill({ json: data });
+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:true};` });
+ 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 });
+ if (url.pathname === "/api/settings") return json(settings);
+ if (url.pathname === "/api/providers") return json(providers);
+ if (url.pathname === "/api/usage/quotas") return json([]);
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname.startsWith("/api/")) return json({});
+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
+ try {
+ await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
+ } catch {
+ await route.fulfill({ status: 404, body: "" });
+ }
+ };
+}
+
+// what shows of the dialog, on screen: its transformed box less its clip,
+// with every animation on it and the backdrop held at time `at` (a fraction
+// of each one)
+const shown = (page, at) => page.evaluate((at) => {
+ const d = document.querySelector("#modal > .dialog");
+ for (const a of [...d.parentElement.getAnimations(), ...d.getAnimations()]) { a.pause(); a.currentTime = at * a.effect.getTiming().duration; }
+ const box = d.getBoundingClientRect(), s = box.width / d.offsetWidth;
+ const clip = getComputedStyle(d).clipPath;
+ const m = clip.match(/^inset\(([-\d.]+)px(?: ([-\d.]+)px)?(?: ([-\d.]+)px)?(?: ([-\d.]+)px)?/);
+ if (!m) return { clip, top: box.top, bottom: box.bottom, left: box.left, right: box.right };
+ const [t, r = t, b = t, l = r] = m.slice(1).map((v) => v === undefined ? undefined : +v);
+ return { clip, top: box.top + Math.max(0, t) * s, bottom: box.bottom - Math.max(0, b) * s, left: box.left + Math.max(0, l) * s, right: box.right - Math.max(0, r) * s };
+}, at);
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const width of [1240, 420]) {
+ test(`${engine} ${width}: a provider's editor grows out of its row and folds back into it`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const page = await browser.newPage({ viewport: { width, height: 760 }, reducedMotion: "no-preference" });
+ page.setDefaultTimeout(5000);
+ const errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve());
+ // the modal's animations are held from the moment they start, so a
+ // slow machine can't let one finish before it is measured
+ await page.addInitScript(() => {
+ const animate = Element.prototype.animate;
+ Element.prototype.animate = function () {
+ const a = animate.apply(this, arguments);
+ if (window.__hold && this.matches("#modal, #modal > .dialog")) a.pause();
+ return a;
+ };
+ });
+ await page.goto("http://magpie.test/?view=providers");
+ const row = page.locator('.row.provider[data-id="delta"]');
+ await row.waitFor();
+ await page.evaluate(() => { window.__hold = true; });
+ const r = await row.boundingBox();
+
+ // held at the start: a strip of the dialog over the row
+ await row.locator(".name, .who").first().click();
+ await page.locator("#modal:not([hidden]) > .dialog").waitFor();
+ const start = await shown(page, 0);
+ assert.match(start.clip, /^inset\(/, `${engine} ${width}: the opening clips the dialog: ${start.clip}`);
+ const near = (a, b, what) => assert(Math.abs(a - b) <= 3, `${engine} ${width}: ${what}: ${a} vs ${b}`);
+ near(start.top, r.y, "the strip's top on the row's");
+ near(start.bottom, r.y + r.height, "the strip's bottom on the row's");
+ assert(start.left >= r.x - 1 && start.right <= r.x + r.width + 1, `${engine} ${width}: the strip stays inside the row: ${JSON.stringify(start)} ${JSON.stringify(r)}`);
+ if (process.env.MORPH_SHOT) await page.screenshot({ path: `${process.env.MORPH_SHOT}-${engine}-${width}-open0.png` });
+ for (const at of [.15, .35]) {
+ await shown(page, at);
+ if (process.env.MORPH_SHOT) await page.screenshot({ path: `${process.env.MORPH_SHOT}-${engine}-${width}-open${at}.png` });
+ }
+
+ // at rest: nothing clipped, its shadow whole
+ await page.evaluate(() => { for (const a of document.querySelector("#modal").getAnimations({ subtree: true })) a.finish(); });
+ const rest = await page.locator("#modal > .dialog").evaluate((d) => [getComputedStyle(d).clipPath, getComputedStyle(d).transform]);
+ assert.deepEqual(rest, ["none", "none"], `${engine} ${width}: at rest`);
+ if (process.env.MORPH_SHOT) await page.screenshot({ path: `${process.env.MORPH_SHOT}-${engine}-${width}-rest.png` });
+
+ // closed: held at its end, back in the row's strip
+ await page.keyboard.press("Escape");
+ await page.locator("#modal.out").waitFor({ state: "attached" });
+ for (const at of [.5]) {
+ await shown(page, at);
+ if (process.env.MORPH_SHOT) await page.screenshot({ path: `${process.env.MORPH_SHOT}-${engine}-${width}-close${at}.png` });
+ }
+ // halfway back it is still there to see: the backdrop fades by
+ // itself, not the modal holding the dialog
+ const seen = await page.evaluate(() => {
+ const m = document.querySelector("#modal");
+ return +getComputedStyle(m).opacity * +getComputedStyle(m.firstElementChild).opacity;
+ });
+ assert(seen > .8, `${engine} ${width}: halfway back the dialog shows: ${seen}`);
+ const end = await shown(page, 1);
+ near(end.top, r.y, "closed: the strip's top on the row's");
+ near(end.bottom, r.y + r.height, "closed: the strip's bottom on the row's");
+ assert(end.left >= r.x - 1 && end.right <= r.x + r.width + 1, `${engine} ${width}: closed inside the row: ${JSON.stringify(end)}`);
+ await page.evaluate(() => { window.__hold = false; for (const a of [...document.querySelector("#modal").getAnimations({ subtree: true })]) a.play(); });
+ await page.locator("#modal").waitFor({ state: "hidden" });
+ assert.equal(await page.locator("#modal > .dialog").evaluate((d) => d.style.clipPath), "", "no clip left behind");
+
+ // opened again: it grows from the row again
+ await page.evaluate(() => { window.__hold = true; });
+ await row.locator(".name, .who").first().click();
+ await page.locator("#modal:not([hidden]) > .dialog").waitFor();
+ const again = await shown(page, 0);
+ near(again.top, r.y, "again: the strip's top on the row's");
+ assert.deepEqual(errors, []);
+ });
+ }
+
+ test(`${engine}: reduced motion only fades`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const page = await browser.newPage({ viewport: { width: 1240, height: 760 }, reducedMotion: "reduce" });
+ page.setDefaultTimeout(5000);
+ await page.route("**/*", serve());
+ await page.goto("http://magpie.test/?view=providers");
+ const row = page.locator('.row.provider[data-id="delta"]');
+ await row.locator(".name, .who").first().click();
+ await page.locator("#modal:not([hidden]) > .dialog").waitFor();
+ const moving = await page.locator("#modal > .dialog").evaluate((d) => d.getAnimations().flatMap((a) => a.effect.getKeyframes().flatMap((k) => Object.keys(k))).filter((k) => k === "transform" || k === "clipPath"));
+ assert.deepEqual(moving, [], "nothing moves or clips under reduced motion");
+ });
+}