gui: a form's name and its control share a line in every editor
The owner (11-12, the second time): in a provider editor, Free for me and Redaction sat 4-5px under their ticks. "这个事情发生过不止一次了,要彻底避免。" Cause: each label carried a padding-top guessed for one control, 5px for a 29px input. Any other kind of control, such as a tick, a switch, the icon box, a row of options, a list or a JSON box, sat off its name. Fix, at the shared row layout instead of per row: - Every editor grid sets its rows on their first baseline: .editor, a dialog's .ebody, Advanced's .more .inner and Connect. The per-label padding and label.by-list are gone. - Controls with no text of their own carry a text line at their middle: the icon box (line-height 30px) and the library switch (a ZWSP ::before). - Exception: a row whose control starts with a text field is set at its top, its name padded to the field's line (--field-h, 44px on the narrow web). WebKit lays a baseline row out again on every layout and reveals a focused field each time, so the page jumped back to a new group's name (group-from-model-add). app.js's settleRows marks those rows .at-top (and a JSON box's name .by-json), only in grids a mutation touched. A CSS :has(+ ...) version held WebKit ~9s on Codex's editor (9209ms vs 249ms on base, provider-pass-errors). - Connect's options wrap at <=520px instead of scrolling: WebKit grew a baseline row holding a scroller 6px each time its bar came and went (connect-snippet-shell). - The rate-windows Add button sits at its row's top. - provider-at-once compares the label's text height, not its padded box. The label is still one line; a name beside a 44px field is padded down to its line. Guard: form-align.test.cjs opens the provider editors (a key's, Codex, with Advanced open), the group editors and Connect. For every name and control row it asserts the label's first text line and the control's first line share a vertical centre within 2px. It runs in chromium and webkit, en/zh/zh-TW/ja/de, at 1100, 420, a web 390 and a panel width. LESSONS.md gets the rule. Run (mica, through mica-run): - At the pushed tree (49274f690, the same tree before this message): form-align, provider-pass-errors, provider-at-once, provider-count-free, provider-unmasked, provider-rate-windows, provider-proxy, connect-snippet-shell, group-from-model-add, icon-url, library-mcp-hub, settings-lines-wrap, settings-update-proxy, editor-roomy and i18n-keys: 499 pass, 3 fail at load 75. The 3: settings-lines-wrap chromium de 440 is red the same on origin/main2bc25a2d6, 2 of 2 (#6353). connect-snippet-shell chromium en/de 390 passed when its file ran again alone (#4128 is its sibling). - go test -run Budget ./internal/gui: ok. - Earlier, at648cd3fdb: the whole GUI suite (473 files). The new reds in it were the :has slowdown above (fixed). The 64 files it reached were then run again on mote, rebased on 343920464; the reds left are listed below. - Broken by hand: every first baseline put back to start, form-align 0/10. On the old CSS it was 0/10. Reds that are the same on origin/main (343920464,2bc25a2d6): - connect-address-kept at 1100: #6755, filed now. - provider-mask "Hide accounts": #5109. - settings-groups warm-ups: #6597. - editor-advanced-align webkit: #4615 / #6421. - library-bili webkit: the tab click is lost about 1 run in 4, 2/8 on main, near #6015. Not tried: the real app in WKWebView, WebKitGTK and WebView2, and Windows.
This commit is contained in:
+19
@@ -547,6 +547,25 @@ the panel and gateway mode.**
|
||||
and read the `pageerror` stack before calling a timeout load.
|
||||
- Seen 1× (2026-11-13).
|
||||
|
||||
**A form's name and its control are lined up by the row, never by a
|
||||
padding guessed for one kind of control.** Every editor grid (`.editor`,
|
||||
a dialog's body, Advanced's rows, Connect) sets its rows on their first
|
||||
baseline; a control with no text of its own (a switch, the icon box)
|
||||
carries a text line at its middle. A row that starts with a text field
|
||||
is set at its top instead, its name on the field's line (`--field-h`):
|
||||
WebKit lays a baseline row out again on every layout, and a focused field
|
||||
laid out again scrolls the page back to itself. `form-align.test.cjs`
|
||||
measures every label beside its control, in every editor it opens.
|
||||
- The owner, 11-12, a second time: Free for me and Redaction sat 4-5px
|
||||
under their ticks. Labels had `padding-top: 5px`, right for a 29px
|
||||
input only; the icon row was 5px off, Extra body and every tick too.
|
||||
- A baseline row never takes its baseline from a scroller: at 520px
|
||||
Connect's options wrap instead, since WebKit grew the row 6px each time
|
||||
their scrollbar came and went.
|
||||
- A new kind of control in a form row runs form-align.test.cjs, and a new
|
||||
editor is added to it.
|
||||
- Seen 1× (2026-11-12).
|
||||
|
||||
**Playwright's WebKit is not WebKitGTK.** A GUI change with motion or a new
|
||||
browser API is tried in the real Linux app too.
|
||||
- 18e82adc6 (10-11) traded the layouts in a view transition. The GUI suite
|
||||
|
||||
+38
-13
@@ -2803,9 +2803,9 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
#connectNote.brief .copy { width: 20px; height: 20px; }
|
||||
|
||||
/* the connect card: label column, then the value with a copy button */
|
||||
.connect { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px 14px; align-items: start; padding: 12px 14px 14px; }
|
||||
.connect { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px 14px; align-items: first baseline; padding: 12px 14px 14px; }
|
||||
.connect > div { min-width: 0; }
|
||||
.connect label { font-size: 12px; color: var(--fg-2); text-align: right; padding-top: 4px; }
|
||||
.connect label { font-size: 12px; color: var(--fg-2); text-align: right; }
|
||||
.connect .hint { font-size: 11px; color: var(--fg-2); margin-top: 4px; line-height: 1.4; }
|
||||
.connect .val { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 9px; border-radius: 7px; background: var(--pill); box-shadow: inset 0 0 0 1px var(--line-2); max-width: 100%; }
|
||||
.connect .val code { font-size: 12px; color: var(--fg); user-select: text; -webkit-user-select: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
@@ -2814,6 +2814,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.connect .stack { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
|
||||
@media (max-width: 520px) {
|
||||
.connect { grid-template-columns: 48px minmax(0, 1fr); column-gap: 8px; padding-left: 10px; padding-right: 10px; }
|
||||
/* its options wrap rather than scroll: WebKit gives a baseline row
|
||||
holding a scroller 6px more each time its bar comes and goes, and the
|
||||
page moved under the reader's click (connect-snippet-shell.test.cjs) */
|
||||
.connect .segs { flex-wrap: wrap; }
|
||||
}
|
||||
/* Change key (#1869) looks like the copy button beside it, but isn't one */
|
||||
.copy, .key-edit { width: 22px; height: 22px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; transition: background .12s, color .12s; }
|
||||
@@ -3643,12 +3647,32 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va
|
||||
/* the label column is as wide as its longest label, so that label starts
|
||||
at the padding and the fields end the same way on the right (the
|
||||
owner, 10-29: a 72px column left the left edge twice the right) */
|
||||
.editor { padding: 16px 18px 14px; display: grid; grid-template-columns: fit-content(132px) minmax(0, 1fr); gap: 10px 14px; align-items: start; }
|
||||
.editor { padding: 16px 18px 14px; display: grid; grid-template-columns: fit-content(132px) minmax(0, 1fr); gap: 10px 14px; align-items: first baseline; }
|
||||
/* A field's name and its control share a line: each row of an editor's
|
||||
grid sets them on their first baseline, so the name sits level with
|
||||
whatever the control is, a box, a tick, a row of options or a list's
|
||||
first line, with no padding guessed for one kind of control (the
|
||||
owner, 11-12: Free for me and Redaction sat 4px under their ticks, the
|
||||
second time). form-align.test.cjs measures every editor's rows. The
|
||||
grids under it (a dialog's body, Advanced's rows) and Connect do the same.
|
||||
A row that starts with a text field is the exception, set at its top, its name
|
||||
on the field's first line: WebKit lays a baseline row's items out again on
|
||||
every layout, and a focused field laid out again scrolls itself into
|
||||
view, so the page jumped back to a new group's name as the reader
|
||||
scrolled to Add (group-from-model-add.test.cjs). app.js's settleRows
|
||||
marks such rows .at-top: a :has(+ …) rule here held WebKit ~9s on
|
||||
Codex's editor (provider-pass-errors.test.cjs). */
|
||||
:where(:is(.editor, .modal .editor.framed > .ebody, .editor .more .inner, .connect) > .at-top) { align-self: start; }
|
||||
:where(:is(.editor, .modal .editor.framed > .ebody, .editor .more .inner, .connect) > label.at-top:not(.tick)) { padding-top: calc((var(--field-h, 29px) - 17px) / 2); }
|
||||
/* a JSON box's first line is 1px of border and 7px of padding down, 18px tall */
|
||||
:where(:is(.editor, .modal .editor.framed > .ebody, .editor .more .inner, .connect) > label.by-json:not(.tick)) { padding-top: 8.5px; }
|
||||
.editor .ehead { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding-bottom: 8px; margin-bottom: 2px; border-bottom: 1px solid var(--line-2); }
|
||||
.editor .ehead .ic { width: 20px; height: 20px; }
|
||||
.editor .icon-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.editor .icon-pick .icon-now { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; display: grid; place-items: center; }
|
||||
.editor .icon-pick .icon-now .ic { width: 20px; height: 20px; }
|
||||
/* a line of text 30px tall, the icon in its middle: its baseline is a text
|
||||
line's, so the field's name sits level with the box's middle */
|
||||
.editor .icon-pick .icon-now { width: 32px; height: 32px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; display: block; text-align: center; font-size: 12px; line-height: 30px; }
|
||||
.editor .icon-pick .icon-now .ic { width: 20px; height: 20px; vertical-align: middle; }
|
||||
.editor .icon-pick > input { flex-basis: 100%; }
|
||||
.editor .icon-pick .icon-grid { flex-basis: 100%; display: grid; grid-template-columns: repeat(auto-fill, 34px); gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; max-height: 196px; overflow-y: auto; }
|
||||
.editor .icon-pick .icon-grid button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; }
|
||||
@@ -3657,8 +3681,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va
|
||||
.editor .icon-pick .icon-grid .ic { width: 18px; height: 18px; }
|
||||
.editor .ehead b { font-weight: 600; }
|
||||
.editor .ehead .note { font-size: 12px; color: var(--muted); }
|
||||
.editor label { font-size: 12px; color: var(--fg-2); text-align: right; padding-top: 5px; }
|
||||
.editor label.by-list { padding-top: 11px; }
|
||||
.editor label { font-size: 12px; color: var(--fg-2); text-align: right; }
|
||||
.editor .hint { font-size: 11px; color: var(--fg-2); margin-top: 4px; }
|
||||
/* a provider's own proxy (#237): the address beside the options, and no
|
||||
room at all while Custom isn't picked (an empty strip under the options
|
||||
@@ -3857,7 +3880,7 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { box-shadow: 0 1px 0 va
|
||||
.editor .more summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
/* its labels are longer (Anthropic 地址, Responses-URL): their column takes
|
||||
the longest, on one line, rather than wrap a last 址 under it (#875) */
|
||||
.editor .more .inner { display: grid; grid-template-columns: minmax(var(--ed-lab, 72px), max-content) minmax(0, 1fr); gap: 10px 14px; align-items: start; padding-top: 8px; }
|
||||
.editor .more .inner { display: grid; grid-template-columns: minmax(var(--ed-lab, 72px), max-content) minmax(0, 1fr); gap: 10px 14px; align-items: first baseline; padding-top: 8px; }
|
||||
.editor .more .inner label { white-space: nowrap; }
|
||||
.editor .warnbox { grid-column: 1 / -1; font-size: 12px; line-height: 1.5; color: var(--fg); background: color-mix(in srgb, var(--amber) 12%, transparent); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent); border-radius: 8px; padding: 8px 10px; }
|
||||
.editor .warnbox.soft { background: none; color: var(--amber); border: 0; padding: 0 0 0 var(--ed-at, 86px); }
|
||||
@@ -4622,7 +4645,7 @@ body.window.mac .modal-grip { top: calc(-1 * var(--grip-h)); }
|
||||
.modal .editor.framed { display: flex; flex-direction: column; align-items: stretch; gap: 0; padding: 0; min-height: 0; overflow: hidden; }
|
||||
.modal .editor.framed > .ebody {
|
||||
flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
|
||||
display: grid; grid-template-columns: inherit; gap: 10px 14px; align-items: start; padding: 14px 18px;
|
||||
display: grid; grid-template-columns: inherit; gap: 10px 14px; align-items: first baseline; padding: 14px 18px;
|
||||
}
|
||||
.modal .editor.framed > .ehead, .modal .editor.framed > .bar { flex: none; min-height: 48px; margin: 0; padding: 0 18px; }
|
||||
.modal .editor.framed > .ehead { border-bottom: 1px solid var(--line-2); }
|
||||
@@ -4774,15 +4797,17 @@ body.panel .modal { padding: 16px 12px; }
|
||||
body.web .row.stat.acts { grid-template-columns: 20px minmax(0, 1fr) auto auto; }
|
||||
body.web .row.stat.acts .num, body.web .row.stat.acts .share { grid-column: 2 / 5; }
|
||||
body.web .row.stat .us-more, body.web .row.stat .us-unhide { grid-column: 4; grid-row: 1; margin: 0; }
|
||||
body.web .connect { grid-template-columns: minmax(0, 1fr); gap: 6px; }
|
||||
body.web .connect { grid-template-columns: minmax(0, 1fr); gap: 6px; align-items: start; }
|
||||
body.web .connect label { text-align: left; margin-top: 6px; }
|
||||
body.web .connect .segs { flex-wrap: wrap; }
|
||||
body.web .connect .val { height: auto; min-height: 44px; }
|
||||
body.web input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
|
||||
body.web textarea, body.web select { font-size: 16px; min-height: 44px; }
|
||||
body.web { --field-h: 44px; } /* the height above, for the names beside such a field */
|
||||
body.web .modal { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
|
||||
body.web .modal .editor.framed > .ebody, body.web .editor { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 12px; }
|
||||
body.web .editor label { text-align: left; padding-top: 8px; }
|
||||
body.web .modal .editor.framed > .ebody, body.web .editor { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 12px; align-items: start; }
|
||||
body.web .editor label { text-align: left; }
|
||||
body.web :is(.editor, .modal .editor.framed > .ebody) > label:where(:not(.tick)) { padding-top: 8px; }
|
||||
body.web .editor .segs { max-width: 100%; flex-wrap: wrap; }
|
||||
body.web .editor .proxy-row { flex-wrap: wrap; }
|
||||
body.web .editor .proxy-row input.proxy-url { flex-basis: 100%; }
|
||||
@@ -5497,7 +5522,7 @@ body .row.agent .ag-prefs .row.pref .who { display: block; }
|
||||
|
||||
/* a provider's rate windows (#2463): the editor's rows, a day chip each,
|
||||
a span and a rate beside them */
|
||||
.rate-windows > .rate-win:last-child + button { align-self: start; }
|
||||
.rate-windows > button { align-self: start; }
|
||||
.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; }
|
||||
|
||||
@@ -7556,7 +7556,7 @@ let fieldIDs = 0;
|
||||
// (yujezhang on X, 11-10: "界面只保留完成操作必需的信息"). lead is the
|
||||
// one short line that stays in sight there: what turning it on costs.
|
||||
function field(label, control, hint, lead) {
|
||||
const l = el("label", control.classList?.contains("accts") ? "by-list" : "", label); // on a list's first row
|
||||
const l = el("label", "", label);
|
||||
const wrap = el("div", hint ? "fld" : "");
|
||||
wrap.append(control);
|
||||
if (hint) {
|
||||
@@ -8680,6 +8680,30 @@ function skelWatch() {
|
||||
}, 250);
|
||||
}
|
||||
skelWatch();
|
||||
// A form row whose control starts with a text field is set at its top,
|
||||
// its name on the field's first line (app.css, .at-top). Marked here: a
|
||||
// :has(+ …) rule held WebKit ~9s a layout on Codex's editor.
|
||||
const ROW_GRIDS = ".editor, .modal .editor.framed > .ebody, .editor .more .inner, .connect";
|
||||
const TEXTY = "input:not([type=checkbox], [type=radio], [type=hidden], [type=range], [type=color], [type=file]), textarea";
|
||||
function textFirst(n) {
|
||||
for (let i = 0; i < 4 && n; i++, n = n.firstElementChild) if (n.matches(TEXTY)) return true;
|
||||
return false;
|
||||
}
|
||||
function settleRows(recs) {
|
||||
const grids = new Set();
|
||||
for (const r of recs) {
|
||||
const g = r.target.closest?.(ROW_GRIDS);
|
||||
if (g) grids.add(g);
|
||||
for (const n of r.addedNodes) if (n.nodeType === 1) for (const x of n.matches(ROW_GRIDS) ? [n] : n.querySelectorAll(ROW_GRIDS)) grids.add(x);
|
||||
}
|
||||
for (const g of grids) for (const c of g.children) {
|
||||
if (c.tagName !== "LABEL") { c.classList.toggle("at-top", textFirst(c)); continue; }
|
||||
const nx = c.nextElementSibling;
|
||||
c.classList.toggle("at-top", !!nx && textFirst(nx));
|
||||
c.classList.toggle("by-json", !!nx && (nx.matches(".extra-body") || !!nx.querySelector(":scope > .extra-body")));
|
||||
}
|
||||
}
|
||||
new MutationObserver(settleRows).observe(document.body, { childList: true, subtree: true });
|
||||
async function skelBird() {
|
||||
skelFlying = true;
|
||||
let release;
|
||||
|
||||
@@ -257,6 +257,9 @@ button.row.lib-hubfolded:hover { background: var(--pill); }
|
||||
|
||||
/* the switch */
|
||||
.lib-switch { flex: none; position: relative; width: 32px; height: 19px; border-radius: 10px; background: var(--line); transition: background .2s var(--ease); }
|
||||
/* an empty line of text at the switch's middle: its baseline is a text
|
||||
line's, so a form row's name sits level with it (form-align.test.cjs) */
|
||||
.lib-switch::before { content: "\200b"; font-size: 12px; line-height: 19px; }
|
||||
.lib-switch i { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .22s var(--ease); }
|
||||
.lib-switch.on { background: var(--mark); }
|
||||
.lib-switch.on i { transform: translateX(13px); background: var(--card); }
|
||||
@@ -667,6 +670,7 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
.lib-tooltxt { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
|
||||
.lib-tool .lib-switch { width: 28px; height: 16px; padding: 0; border: 0; cursor: pointer; }
|
||||
.lib-tool .lib-switch i { width: 12px; height: 12px; }
|
||||
.lib-tool .lib-switch::before { line-height: 16px; }
|
||||
.lib-tool .lib-switch.on i { transform: translateX(12px); }
|
||||
.lib-tool.off .lib-tooltxt { opacity: .5; }
|
||||
.lib-tool.off .lib-toolname { text-decoration: line-through; }
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// formRows: every label of a form grid that sits beside its control, with
|
||||
// how far the middle of its first line is from the middle of the
|
||||
// control's first line. The first line of the control is its first
|
||||
// visible field, button, switch row, tick or line of text, in order.
|
||||
async function formRows(page, root = ".editor") {
|
||||
return page.evaluate((root) => {
|
||||
const shown = (e) => { const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && getComputedStyle(e).visibility !== "hidden"; };
|
||||
const lineOf = (n) => { const r = document.createRange(); r.selectNodeContents(n); return [...r.getClientRects()].find((x) => x.width > 0 && x.height > 0); };
|
||||
const LEAF = "input:not([type=hidden]), textarea, select, button, [role=switch], label.tick, .sess-pick, .icon-now";
|
||||
const first = (box) => {
|
||||
const w = document.createTreeWalker(box, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT);
|
||||
for (let n = w.currentNode; n; n = w.nextNode()) {
|
||||
if (n.nodeType === 3) { if (n.data.trim() && n.parentElement && shown(n.parentElement)) { const r = lineOf(n); if (r) return { r, what: "text " + n.data.trim().slice(0, 24) }; } continue; }
|
||||
if (n !== box && n.matches(LEAF) && shown(n)) {
|
||||
let r = n.getBoundingClientRect();
|
||||
// a box of several lines: its first line, inside its border and padding
|
||||
if (n.matches("textarea")) {
|
||||
const s = getComputedStyle(n), lh = parseFloat(s.lineHeight) || parseFloat(s.fontSize) * 1.2;
|
||||
const top = r.top + parseFloat(s.borderTopWidth) + parseFloat(s.paddingTop);
|
||||
r = { top, height: lh };
|
||||
}
|
||||
return { r, what: n.tagName.toLowerCase() + "." + [...n.classList].join(".") };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const out = [];
|
||||
for (const ed of document.querySelectorAll(root)) {
|
||||
for (const l of ed.querySelectorAll("label")) {
|
||||
const p = l.parentElement, c = l.nextElementSibling;
|
||||
if (!p || getComputedStyle(p).display !== "grid" || !c || l.matches(".tick") || !shown(l) || !shown(c)) continue;
|
||||
const lr = l.getBoundingClientRect(), cr = c.getBoundingClientRect();
|
||||
if (lr.right > cr.left + 1) continue; // stacked (a phone's one column)
|
||||
const t = lineOf(l), f = first(c);
|
||||
if (!t || !f) continue;
|
||||
const mid = (r) => r.top + r.height / 2;
|
||||
out.push({ label: l.textContent.trim().slice(0, 30), what: f.what, off: Math.round((mid(t) - mid(f.r)) * 10) / 10 });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}, root);
|
||||
}
|
||||
module.exports = { formRows };
|
||||
@@ -0,0 +1,127 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The owner (11-12, a second time): "没有水平对齐。这个事情发生过不止一次了,
|
||||
// 要彻底避免。" Free for me's and Redaction's names sat 4-5px under their
|
||||
// ticks: every editor label had padding-top: 5px, guessed for a 29px input,
|
||||
// and a tick, a row of options, a list or the icon box each sat off by its
|
||||
// own amount. The rows now set name and control on their first baseline.
|
||||
// For every label beside its control in a provider editor (a key's, a local
|
||||
// one's with its ticks and time windows, a subscription's with accounts),
|
||||
// a group editor (new and existing, Advanced open) and Gateway's Connect,
|
||||
// the middle of the label's first line is within 2px of the middle of the
|
||||
// control's first line, in every language, both engines, wide and narrow.
|
||||
// Where a phone's layout puts the label above its control, there is no row.
|
||||
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 { formRows } = require("./form-align.cjs");
|
||||
const { fixture } = require("./fixtures/caller-keys.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const base = { icon: "generic", chat: "", responses: "", anthropic: "", catalog: "", routing: "", models: [{ id: "m1", name: "m1", on: true }, { id: "m2", name: "m2", on: true }], agents: [], fallback: [], headers: {}, key: { set: false, masked: "" }, keyList: [], proxy: "", balanceToken: { takes: false, set: false }, searches: false, unredacted: false };
|
||||
const keyed = { ...base, id: "a", name: "Acme", chat: "https://api.acme.example/v1", key: { set: true, masked: "sk-…1234" }, ready: true };
|
||||
const local = { ...base, id: "local", name: "Local Box", chat: "http://localhost:11434/v1", countFree: true, rateWindows: [{ days: [1], start: "22:00", end: "06:00", rate: "0.5" }], ready: true };
|
||||
const codex = { ...base, id: "codex", name: "Codex", icon: "codex-color", models: [{ id: "gpt-6", name: "GPT-6", on: true }],
|
||||
account: { agent: "codex", agentName: "Codex", user: "me@example.com", plan: "PLUS", logins: [{ user: "me@example.com", plan: "PLUS", active: true, on: true }, { user: "b@example.com", plan: "PLUS", on: true }] } };
|
||||
const members = ["a/m1", "a/m2"];
|
||||
const groups = { models: members.map((id) => ({ id, name: id.slice(2), providerName: "Acme", icon: "generic" })), pools: [],
|
||||
groups: [{ id: "g", name: "Glim", members, match: ["a/*"], fast: [], off: [], routing: "", ready: true, memberInfo: members.map((id) => ({ id, ready: true })) }] };
|
||||
|
||||
function serve(lang, web) {
|
||||
const providers = { providers: [keyed, local, codex], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(lang)},theme:"light",web:${web}};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [{ id: "pi", name: "Pi", path: "/test/pi", fields: [] }], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/local-hosts") return json({ local: ["localhost"] });
|
||||
if (url.pathname === "/api/groups") return json(groups);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
|
||||
return json({ mine: true, now: new Date().toISOString(), seq: 0, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], 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 r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// every <details> fold of the editor opened, so its rows are measured too
|
||||
const openFolds = (page, root) => page.evaluate((root) => {
|
||||
for (const d of document.querySelectorAll(`${root} details`)) d.open = true;
|
||||
}, root);
|
||||
const settle = (page) => page.evaluate(() => new Promise((ok) => requestAnimationFrame(() => requestAnimationFrame(ok))));
|
||||
const far = (rows) => rows.filter((r) => Math.abs(r.off) > 2);
|
||||
|
||||
const SIZES = [[false, 1000], [false, 560], [true, 1000], [true, 420]];
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
test(`${engine} ${lang}: every form label is level with its control's first line`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const errors = [];
|
||||
for (const [web, width] of SIZES) {
|
||||
const at = `${web ? "web " : ""}${width}px`;
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(6000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(`${at}: ${e.message}`));
|
||||
await page.route("**/*", serve(lang, web));
|
||||
const wide = width >= 900;
|
||||
|
||||
// the provider editors
|
||||
for (const name of ["Acme", "Local Box", "Codex"]) {
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: name }).first().click();
|
||||
await page.locator(".editor .bar").first().waitFor();
|
||||
await openFolds(page, ".editor");
|
||||
await settle(page);
|
||||
const rows = await formRows(page);
|
||||
if (wide) assert.ok(rows.length >= 8, `${at} ${name}: the editor's rows: ${JSON.stringify(rows)}`);
|
||||
assert.deepEqual(far(rows), [], `${at} ${name}: each label is level with its control`);
|
||||
// the ticks the owner pointed at are among the rows measured
|
||||
if (wide && name === "Local Box") assert.ok(rows.filter((r) => r.what.startsWith("label.tick")).length >= 2, `${at}: the tick rows are measured: ${JSON.stringify(rows)}`);
|
||||
}
|
||||
|
||||
// a group's editor, new and existing
|
||||
const w = await page.evaluate((lang) => Object.fromEntries(["New group", "Edit"].map((k) => [k, lang === "en" ? k : I18N[lang][k]])), lang);
|
||||
for (const existing of [false, true]) {
|
||||
await page.goto("http://magpie.test/?view=groups");
|
||||
if (existing) await page.locator(".rt-group", { hasText: "Glim" }).locator("button", { hasText: w.Edit }).click();
|
||||
else await page.locator("button", { hasText: w["New group"] }).first().click();
|
||||
await page.locator(".rt-gedit").waitFor();
|
||||
await openFolds(page, ".rt-gedit");
|
||||
if (existing) await page.locator(".rt-gedit .rt-pats .fbrow").first().waitFor();
|
||||
await settle(page);
|
||||
const rows = await formRows(page, ".rt-gedit");
|
||||
if (wide) assert.ok(rows.length >= 8, `${at} group: the editor's rows: ${JSON.stringify(rows)}`);
|
||||
assert.deepEqual(far(rows), [], `${at} ${existing ? "a" : "a new"} group: each label is level with its control`);
|
||||
}
|
||||
await ctx.close();
|
||||
|
||||
// Gateway's Connect card
|
||||
const cctx = await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" });
|
||||
const cpage = await cctx.newPage();
|
||||
cpage.setDefaultTimeout(6000);
|
||||
await cpage.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} });
|
||||
cpage.on("pageerror", (e) => errors.push(`${at} connect: ${e.message}`));
|
||||
await cpage.route("**/*", fixture(lang, "light", [], { lan: true }));
|
||||
await cpage.goto("http://magpie.test/?view=gateway");
|
||||
await cpage.locator("#connect .snip").waitFor();
|
||||
await settle(cpage);
|
||||
const rows = await formRows(cpage, ".connect");
|
||||
if (width >= 560) assert.ok(rows.length >= 2, `${at} connect: its rows: ${JSON.stringify(rows)}`);
|
||||
assert.deepEqual(far(rows), [], `${at} connect: each label is level with its value`);
|
||||
await cctx.close();
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -132,8 +132,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.match(next, /max-accounts/);
|
||||
const look = (e) => { const s = getComputedStyle(e); return { bg: s.backgroundColor, border: s.borderTopColor, radius: s.borderTopLeftRadius, height: s.height }; };
|
||||
assert.deepEqual(await box(page).evaluate(look), await page.locator(".editor input.concurrency").evaluate(look), "styled as Concurrency is");
|
||||
const h = await label.evaluate((e) => e.getBoundingClientRect().height);
|
||||
const one = await page.locator(".editor label").first().evaluate((e) => e.getBoundingClientRect().height);
|
||||
// the text's own height: a name beside a field is padded down to its line
|
||||
const text = (e) => { const s = getComputedStyle(e); return e.getBoundingClientRect().height - parseFloat(s.paddingTop) - parseFloat(s.paddingBottom); };
|
||||
const h = await label.evaluate(text);
|
||||
const one = await page.locator(".editor label").first().evaluate(text);
|
||||
assert(h <= one + 1, `the label takes ${h}px, one line is ${one}px`);
|
||||
const stripes = await box(page).evaluate((e) => { const s = getComputedStyle(e); return parseFloat(s.borderLeftWidth) > parseFloat(s.borderRightWidth) || (parseFloat(s.borderLeftWidth) > 0 && s.borderLeftColor !== s.borderRightColor); });
|
||||
assert.equal(stripes, false, "no border stripe");
|
||||
|
||||
Reference in New Issue
Block a user