diff --git a/src/agent/dsh-native-client.ts b/src/agent/dsh-native-client.ts index 69bc636179..b2f461b20c 100644 --- a/src/agent/dsh-native-client.ts +++ b/src/agent/dsh-native-client.ts @@ -81,7 +81,7 @@ const PAGE_KEYS: Record = { config: "tab_config", logs: "tab_logs", }; -const EMBED_HEIGHT_PX = 640; +const EMBED_HEIGHT_CSS = "min(640px, 78vh)"; const zh: Dict = { "nav": "bili设置", @@ -214,7 +214,7 @@ export function apply(ctx: ClientContext): void { style: { display: "block", width: "100%", - height: EMBED_HEIGHT_PX, + height: EMBED_HEIGHT_CSS, border: "1px solid rgba(127,127,127,0.4)", borderRadius: 8, background: "transparent", @@ -223,14 +223,15 @@ export function apply(ctx: ClientContext): void { ), createElement( "div", - { style: { display: "flex", alignItems: "center", gap: 10 } }, - createElement("p", { style: { margin: 0, opacity: 0.7, fontSize: 13, lineHeight: 1.6, flex: 1 } }, t("hint")), + { style: { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" } }, + createElement("p", { style: { margin: 0, opacity: 0.7, fontSize: 13, lineHeight: 1.6, flex: "1 1 240px" } }, t("hint")), origin === undefined ? null : createElement( "button", { type: "button", + title: `${origin}/__bili/`, onClick: () => openExternal(`${origin}/__bili/`), style: { cursor: "pointer", @@ -242,10 +243,9 @@ export function apply(ctx: ClientContext): void { fontSize: 14, lineHeight: "22px", padding: "7px 16px", - whiteSpace: "nowrap", }, }, - `${t("open")}(${origin})`, + t("open"), ), ), ); diff --git a/src/web/styles.ts b/src/web/styles.ts index 39625242de..d898895391 100644 --- a/src/web/styles.ts +++ b/src/web/styles.ts @@ -364,4 +364,12 @@ pre.tool-args, pre.tool-out { margin: 6px 0 0; padding: 8px; background: var(--b } .embed main { max-width: none; padding: 4px 0 12px; } .embed .banner { margin: 8px 0 0; } + +/* #2448: the iframe viewport IS the host panel width (dsh settings, ~400–760px), + so reuse the ≤720px compact column set unconditionally in embed mode and drop + the standalone-page min-widths — otherwise the tables force a horizontal + scroll inside the frame (≤720px) or squish (720–940px). */ +.embed .twide table.data, .embed .tproc table.data { min-width: 0; } +.embed table.data th:nth-child(n + 6), .embed table.data td:nth-child(n + 6) { display: none; } +.embed table.data th, .embed table.data td { padding-left: 5px; padding-right: 5px; } `; diff --git a/tests/dsh-settings-ui.test.ts b/tests/dsh-settings-ui.test.ts index b6c4169f29..d69aaeeb84 100644 --- a/tests/dsh-settings-ui.test.ts +++ b/tests/dsh-settings-ui.test.ts @@ -448,6 +448,23 @@ test("#1590/#2125: client bundle registers the settings.section entry bili AND t (buttons[4].props!.onClick as () => void)(); assert.deepEqual(opened, ["http://127.0.0.1:8787/__bili/"]); + // #2448: the frame height tracks the host viewport (capped at 640px), and + // the backup label drops the inline origin URL in favor of a hover tooltip + // so narrow panels don't get a full-URL label squeezing the row. + assert.equal((frameAfterTab.props?.style as Record).height, "min(640px, 78vh)", "iframe height follows the host viewport"); + const backup = buttons[4]; + assert.equal(backup.props?.title, "http://127.0.0.1:8787/__bili/", "tooltip carries the exact URL the button opens"); + const backupLabel: string[] = []; + collectText(backup, backupLabel); + assert.equal(backupLabel.join(""), "打开 Web UI", "label is the bare translation without the origin"); + // The bottom row is a third root-level child after the h3 and the + // tab/frame column (see the panel layout in dsh-native-client.ts). + const bottomRow = treeAfterTab.children[2] as ElementNode; + assert.equal((bottomRow.props?.style as Record).flexWrap, "wrap", "the hint/button row wraps on narrow panels"); + const hint = findTag(treeAfterTab, "p"); + assert.ok(hint !== undefined, "the bottom row still carries its hint paragraph"); + assert.equal((hint.props!.style as Record).flex, "1 1 240px", "the hint reserves width before the row wraps"); + // #2125: the bundle panel reuses the probe/frame/hint but drops the title // — the plugin detail page draws it. calls.length = 0; @@ -458,11 +475,10 @@ test("#1590/#2125: client bundle registers the settings.section entry bili AND t const bframe = findTag(btree, "iframe"); assert.ok(bframe !== undefined, "origin present renders the embedded iframe in the bundle panel"); assert.equal(bframe.props?.src, "http://127.0.0.1:8787/__bili/?embed=1&lang=zh#/overview"); - const btexts: string[] = []; - collectText(btree, btexts); - assert.ok(btexts.some((x) => x.includes("http://127.0.0.1:8787")), `bundle backup button label carries the origin: ${JSON.stringify(btexts)}`); const bButtons = collectButtons(btree); assert.equal(bButtons.length, 5, "the bundle panel offers the same tabs plus backup button"); + // #2448: the origin moved from the label into the tooltip attribute. + assert.equal(bButtons[bButtons.length - 1].props?.title, "http://127.0.0.1:8787/__bili/", "bundle backup tooltip carries the origin (label no longer does)"); opened.length = 0; (bButtons[bButtons.length - 1].props!.onClick as () => void)(); assert.deepEqual(opened, ["http://127.0.0.1:8787/__bili/"]); @@ -640,15 +656,14 @@ test("#1809/#2125/#2187: client polls /bili/origin while unresolved — upgrades }); m.resetHooks(); const first = m.component() as ElementNode; - const firstTexts: string[] = []; - collectText(first, firstTexts); - assert.ok(firstTexts.some((x) => x.includes("http://127.0.0.1:8787")), "the snapshot paints immediately (first-paint hint)"); + const firstBackup = collectButtons(first); + assert.equal(firstBackup[firstBackup.length - 1].props?.title, "http://127.0.0.1:8787/__bili/", "the snapshot paints immediately (first-paint backup target)"); await tick(); const second = m.component() as ElementNode; - const texts: string[] = []; - collectText(second, texts); - assert.ok(texts.some((x) => x.includes("http://127.0.0.1:18798")), `stale snapshot upgraded to the live origin: ${JSON.stringify(texts)}`); - assert.ok(!texts.some((x) => x.includes(":8787")), "the stale origin is gone from the label"); + // #2448: origin tracking now asserts on the tooltip attribute — the label no longer renders it. + const titles = collectButtons(second).map((b) => String(b.props?.title ?? "")); + assert.ok(titles.includes("http://127.0.0.1:18798/__bili/"), "stale snapshot upgraded to the live origin"); + assert.ok(!titles.some((x) => x.includes(":8787")), "the stale origin is gone from the backup target"); const sframe = findTag(second, "iframe"); assert.ok(sframe !== undefined, "the upgraded entry keeps its frame"); assert.equal(sframe.props?.src, "http://127.0.0.1:18798/__bili/?embed=1&lang=zh#/overview", "the embedded frame follows the corrected live origin"); @@ -696,10 +711,10 @@ test("#1809/#2125/#2187: client polls /bili/origin while unresolved — upgrades } await tick(); const tree = m.component() as ElementNode; - const texts: string[] = []; - collectText(tree, texts); - assert.ok(texts.some((x) => x.includes("http://127.0.0.1:18800")), `mid-session re-bind follows the live origin: ${JSON.stringify(texts)}`); - assert.ok(!texts.some((x) => x.includes(":18798")), "the pre-re-bind origin is gone from the label"); + // #2448: re-bind tracking now asserts on the tooltip attribute. + const titles = collectButtons(tree).map((b) => String(b.props?.title ?? "")); + assert.ok(titles.includes("http://127.0.0.1:18800/__bili/"), "mid-session re-bind follows the live origin"); + assert.ok(!titles.some((x) => x.includes(":18798")), "the pre-re-bind origin is gone from the backup target"); const rframe = findTag(tree, "iframe"); assert.ok(rframe !== undefined, "the re-bound entry keeps its frame"); assert.equal(rframe.props?.src, "http://127.0.0.1:18800/__bili/?embed=1&lang=zh#/overview", "the embedded frame follows the mid-session re-bind"); diff --git a/tests/web-i18n.test.ts b/tests/web-i18n.test.ts index 7773f2b1c0..fa860e4454 100644 --- a/tests/web-i18n.test.ts +++ b/tests/web-i18n.test.ts @@ -7,6 +7,7 @@ import { fileURLToPath } from "node:url"; import { LOCALES, MESSAGES, translate } from "../src/web/i18n.ts"; import { renderPage } from "../src/web/page.ts"; import { WEB_CLIENT } from "../src/web/client.ts"; +import { WEB_STYLES } from "../src/web/styles.ts"; const here = dirname(fileURLToPath(import.meta.url)); const han = /\p{Script=Han}/u; @@ -162,6 +163,13 @@ test("#2321: embed mode marks the body for chrome-less framing", () => { assert.ok(embedded.includes(''), "embed flag marks the body"); }); +test("#2448: embed mode reuses the compact column set and drops standalone-page min-widths", () => { + assert.ok(WEB_STYLES.includes(".embed .twide table.data, .embed .tproc table.data { min-width: 0; }"), "embed tables lose the standalone-page min-width"); + assert.ok(WEB_STYLES.includes(".embed table.data th:nth-child(n + 6), .embed table.data td:nth-child(n + 6) { display: none; }"), "embed tables reuse the ≤720px compact column set"); + assert.ok(WEB_STYLES.includes(".embed table.data th, .embed table.data td { padding-left: 5px; padding-right: 5px; }"), "embed cells tighten horizontal padding"); + assert.match(WEB_STYLES, /@media \(max-width: 720px\) [\s\S]*?table\.data th:nth-child\(n \+ 6\)/, "the mobile media query still owns the standalone-page compact rule"); +}); + test("#1024: embedded client parses and persists the language choice", () => { assert.doesNotThrow(() => new Function(WEB_CLIENT)); assert.match(WEB_CLIENT, /bili-language/);