gui: a provider's dialog grows out of its icon and name, as an add sheet tile's does

The owner, 10-21: the provider editor's opening was stiff ("太生硬"), and
the add sheet's, opening a vendor's tile, is the one to follow. Both run
through openModal's morph, but a tile is narrower than the dialog, so the
dialog starts shrunk to it (scale ~.4) and zooms out; a provider row is
wider than the dialog, so the scale stayed 1 and the dialog opened as a
full-size strip widening over the row, its text at full size from the
first frame.

A provider row is now measured as a tile: from its left edge to where
its name and host line's words end (rowOwnRect, the text nodes' extents;
a range over the block spans its whole width), the row's height. The
dialog grows out of that and folds back into it, as a tile's does.

Run on origin/main b855cfee9 + this commit, macOS, playwright 1.62.0:
- modal-morph.test.cjs: 6/6 chromium and webkit, 1240 and 420px. Its new
  checks (starts at the row's left, ends before the words do, scale < .8;
  closes into the same) are red on the old app.js: chromium 1240 and 420
  fail.
- frames held at 8/16/30/50% of the opening and closing, row beside the
  add sheet's Custom provider tile, looked at side by side.
- go test ./internal/gui/ -run Budget ok; gofmt -l clean.

Shipped at the owner's word (10-21, "赶紧上线") before the full GUI suite
finished: it was stopped at ~2,040 passing tests (about a quarter of the
files, on b855cfee9 + the dialog change), with two reds,
desktop-longest chromium zh 640px and gateway-key-groups chromium en,
both under load at ~100. On origin/main c79400556 + both commits (rebased after onto
e68a0b1db, which adds only internal/sessions):
desktop-longest, gateway-key-groups, modal-morph, lightweight,
segs-glide, segs-press-redraw and settings-general 108/108 in chromium
and webkit; go test ./internal/settings/ ok; go test ./internal/gui/
-run 'Budget|Lightweight' ok; gofmt -l clean; GOOS=linux go vet -tags
nogui and GOOS=windows go vet of internal/settings and internal/gui.
Not run: the rest of the GUI suite.
This commit is contained in:
yetone
2026-10-21 18:45:23 +08:00
parent 3c38fe5c99
commit 1b9b97f8db
2 changed files with 39 additions and 11 deletions
+20 -5
View File
@@ -8488,9 +8488,26 @@ let modalOrigin = null, modalDone = null;
function originRect(o) {
const at = o && (o.el.isConnected ? o.el : o.find ? document.querySelector(o.find) : null);
if (!at || at.closest("[hidden]")) return null;
const r = at.getBoundingClientRect();
const r = at.matches(".row.provider") ? rowOwnRect(at) : at.getBoundingClientRect();
return r.width && r.height && r.bottom > 0 && r.top < innerHeight ? r : null;
}
// rowOwnRect: a provider row as a tile in the add sheet is, its icon and
// name. The whole row is wider than the dialog, so the dialog couldn't
// shrink into it and opened as a full-size strip widening (the owner: "太
// 生硬", the add sheet's tiles "特别完美"); out of this it zooms as they do.
function rowOwnRect(row) {
const r = row.getBoundingClientRect(), who = row.querySelector(".who");
if (!who) return r;
// where its words end: a range over the block itself spans its width
let end = who.getBoundingClientRect().left;
const text = document.createRange(), walk = document.createTreeWalker(who, NodeFilter.SHOW_TEXT);
for (let n = walk.nextNode(); n; n = walk.nextNode()) {
text.selectNodeContents(n);
end = Math.max(end, text.getBoundingClientRect().right);
}
const right = Math.min(r.right, end + 12);
return new DOMRect(r.left, r.top, right - r.left, r.height);
}
// fromRect: the transform putting the dialog (at `to`) over the rect `from`
function fromRect(from, to) {
const s = Math.max(.3, Math.min(1, from.width / to.width));
@@ -8498,10 +8515,8 @@ function fromRect(from, to) {
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.
// scaled, and clipped to its shape, so it opens as that rect growing 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)";
+19 -6
View File
@@ -1,11 +1,11 @@
// 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
// not from the provider, unlike iOS), and as an add sheet's tile does (10-21:
// a full-size strip widening over the row was "太生硬"). Held at the start of
// the opening and at the end of the closing, what shows of the dialog is the
// dialog shrunk over the row's icon and name: the row's height, from its
// left to where its words end. 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.
@@ -95,6 +95,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
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)}`);
// out of the provider's icon and name, as a tile in the add sheet:
// the dialog shrunk to them, not a full-size strip widening (the
// owner, 10-21: "太生硬")
const words = await row.evaluate((row) => {
const text = document.createRange();
let end = 0;
for (const n of row.querySelectorAll(".who .name, .who .sub")) { text.selectNodeContents(n.firstChild); end = Math.max(end, text.getBoundingClientRect().right); }
return end;
});
near(start.left, r.x, "the start's left on the row's");
assert(start.right <= words + 16, `${engine} ${width}: it starts over the icon and name, not the row: ${start.right} vs ${words}`);
const scale = await page.evaluate(() => { const d = document.querySelector("#modal > .dialog"); return d.getBoundingClientRect().width / d.offsetWidth; });
assert(scale < .8, `${engine} ${width}: it starts shrunk, as a tile's: ${scale}`);
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);
@@ -124,7 +137,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
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)}`);
assert(end.left >= r.x - 1 && end.right <= words + 16, `${engine} ${width}: closed into the icon and name: ${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");