diff --git a/webui/browser/appearance.spec.ts b/webui/browser/appearance.spec.ts index 24b5c2178..63925866e 100644 --- a/webui/browser/appearance.spec.ts +++ b/webui/browser/appearance.spec.ts @@ -52,7 +52,7 @@ test("custom reading size previews, persists and survives preset changes", async await page.reload(); await expect(input).toHaveValue("24"); await page.getByRole("radio", { name: "Small reading text", exact: true }).click(); - await expect(paragraph).toHaveCSS("font-size", "16px"); + await expect(paragraph).toHaveCSS("font-size", "15px"); await page.getByRole("spinbutton", { name: "Custom text size", exact: true }).click(); await expect(input).toHaveValue("24"); await expect(paragraph).toHaveCSS("font-size", "24px"); diff --git a/webui/browser/chat-failure.spec.ts b/webui/browser/chat-failure.spec.ts index 770dfd8e3..0f2efd925 100644 --- a/webui/browser/chat-failure.spec.ts +++ b/webui/browser/chat-failure.spec.ts @@ -61,9 +61,7 @@ for (const width of [1440, 390]) { const bubble = page.locator("[data-user-text-bubble]"); const text = bubble.locator("p"); const trigger = page.locator("[data-message-block-menu-trigger]"); - const fontSize = width === 390 - ? { small: 15, standard: 16, large: 18 }[size] - : { small: 16, standard: 18, large: 20 }[size]; + const fontSize = { small: 15, standard: 16, large: 18 }[size]; await expect(text).toHaveCSS("font-size", `${fontSize}px`); await bubble.hover(); await expect(trigger).toBeVisible(); diff --git a/webui/browser/composer-action.spec.ts b/webui/browser/composer-action.spec.ts index 3d9d0b4e4..d6fbec54d 100644 --- a/webui/browser/composer-action.spec.ts +++ b/webui/browser/composer-action.spec.ts @@ -147,3 +147,56 @@ test("idle voice and ready send remain distinct from the composer in both themes } await test.info().attach("action-contrast", { body: JSON.stringify(measurements, null, 2), contentType: "application/json" }); }); + + +test("a long mobile placeholder remains available without shifting the composer", async ({ browser, baseURL }) => { + const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" }); + try { + const page = await context.newPage(); + await page.addInitScript(() => localStorage.setItem("nanobot.locale", "fr")); + await page.goto("/browser/fixture.html?case=composer-action&composerVariant=thread"); + await page.evaluate(() => document.fonts.ready); + const input = page.locator(".thread-composer-input textarea"); + const action = page.locator(".composer-primary-action"); + await expect(input).toHaveAttribute("placeholder", /compétences/); + const placeholder = (await input.getAttribute("placeholder"))!; + await expect(input).toHaveAttribute("aria-description", placeholder); + await expect(page.getByRole("tooltip")).toHaveCount(0); + const before = (await action.boundingBox())!; + const initialHeight = await input.evaluate(node => node.clientHeight); + + await input.tap(); + const hint = page.getByRole("tooltip"); + await expect(hint).toHaveText(placeholder); + const hintSurface = page.locator('[data-radix-popper-content-wrapper] [data-side]').first(); + const composer = page.locator(".thread-composer-form"); + await expect.poll(async () => { + const [hintBox, composerBox] = await Promise.all([hintSurface.boundingBox(), composer.boundingBox()]); + return !!hintBox && !!composerBox && (hintBox.y + hintBox.height <= composerBox.y || hintBox.y >= composerBox.y + composerBox.height); + }).toBe(true); + expect(await action.boundingBox()).toEqual(before); + + await input.fill("Bonjour"); + await expect(hint).toHaveCount(0); + expect(await action.boundingBox()).toEqual(before); + await input.fill("Première ligne\nDeuxième ligne\nTroisième ligne"); + await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(initialHeight); + await input.fill(""); + await expect(hint).toHaveText(placeholder); + await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(initialHeight); + expect(await action.boundingBox()).toEqual(before); + await input.press("Escape"); + await expect(hint).toHaveCount(0); + + await page.locator(".thread-composer-footer button").first().focus(); + await page.keyboard.press("Shift+Tab"); + await expect(input).toBeFocused(); + await expect(hint).toHaveText(placeholder); + const box = (await input.boundingBox())!; + await page.mouse.move(box.x + 5, box.y + 5); + await page.mouse.move(1, 800); + await expect(hint).toHaveCount(0); + } finally { + await context.close(); + } +}); diff --git a/webui/browser/composer-layout.spec.ts b/webui/browser/composer-layout.spec.ts index 9eef51384..cef317419 100644 --- a/webui/browser/composer-layout.spec.ts +++ b/webui/browser/composer-layout.spec.ts @@ -117,9 +117,9 @@ test("multiline drafts resize after reading typography changes", async ({ page } await input.fill("First line\nSecond line\nThird line"); const standardHeight = await input.evaluate(node => node.clientHeight); const sizes = [ - ["large", "Large reading text", 20], + ["large", "Large reading text", 18], ["small", "Small reading text", 16], - ["standard", "Standard reading text", 18], + ["standard", "Standard reading text", 16], ] as const; for (const [size, label, fontSize] of sizes) { await page.getByRole("radio", { name: label, exact: true }).click(); @@ -128,7 +128,6 @@ test("multiline drafts resize after reading typography changes", async ({ page } expect(await input.evaluate(node => node.scrollHeight <= node.clientHeight + 1)).toBe(true); const height = await input.evaluate(node => node.clientHeight); if (size === "large") expect(height).toBeGreaterThan(standardHeight); - else if (size === "small") expect(height).toBeLessThan(standardHeight); else expect(height).toBe(standardHeight); } }); diff --git a/webui/browser/display-math-fixture.tsx b/webui/browser/display-math-fixture.tsx index db09675fb..5ea2d0d87 100644 --- a/webui/browser/display-math-fixture.tsx +++ b/webui/browser/display-math-fixture.tsx @@ -5,7 +5,7 @@ import { MarkdownText } from "@/components/MarkdownText"; export function DisplayMathFixture() { const [step, setStep] = useState(0); const [streaming, setStreaming] = useState(true); - const terms = step === 0 ? "x + y" : Array.from({ length: 24 }, (_, index) => `x_{${index}}`).join(" + "); + const terms = step === 0 ? "x + y" : Array.from({ length: 36 }, (_, index) => `x_{${index}}`).join(" + "); const tag = step < 2 ? "1" : "1000000"; return
diff --git a/webui/browser/subagent-dock-fixture.tsx b/webui/browser/subagent-dock-fixture.tsx index 941c12f69..4a0dbaa85 100644 --- a/webui/browser/subagent-dock-fixture.tsx +++ b/webui/browser/subagent-dock-fixture.tsx @@ -14,6 +14,7 @@ const createdAt = Date.now() / 1000; let streamLength = 0; let inputNumber = 0; const saveTasks = new URLSearchParams(location.search).has("saved"); +const historyParagraphs = new URLSearchParams(location.search).has("long-history") ? 20 : 12; const taskStorageKey = "fixture.subagent-dock.tasks"; const taskLabels = new URLSearchParams(location.search).has("long-labels") ? ["核对多轮任务完成后的归档位置、长标题换行与独立详情入口", "Review_the_responsive_subtask_panel_and_keyboard_focus_without_interrupting_running_work", "整理交互建议"] @@ -28,7 +29,7 @@ const tasks: SubagentTaskSnapshot[] = taskLabels.map((label, index) => ({ const history: ThreadProjectionEvent[] = [ { event: "user_message", chat_id: chatId, projection_id: "preview-prompt", turn_id: turnId, text: "请让三个子任务分别检查实现、测试和交互。主对话继续讨论,不要等它们全部结束。", starts_turn: true }, { event: "message", chat_id: chatId, projection_id: "preview-answer", turn_id: turnId, - text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(12) }, + text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(historyParagraphs) }, ]; function updateTask(index: number, patch: Partial) { diff --git a/webui/browser/subagent-dock.spec.ts b/webui/browser/subagent-dock.spec.ts index 74b9a74c2..320c6d60a 100644 --- a/webui/browser/subagent-dock.spec.ts +++ b/webui/browser/subagent-dock.spec.ts @@ -349,13 +349,12 @@ test("does not retire a completed list or detail while it is being read", async for (const width of [1440, 390]) { test(`keeps the reading position when results are archived and the live entry retires at ${width}px`, async ({ page }) => { await page.setViewportSize({ width, height: 900 }); - await page.goto("/browser/fixture.html?case=subagent-dock"); + await page.goto("/browser/fixture.html?case=subagent-dock&long-history"); const body = page.getByTestId("thread-message-region"); const paragraphs = body.getByText("主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。", { exact: true }); - await expect(paragraphs).toHaveCount(12); + await expect(paragraphs).toHaveCount(20); await settledMotion(body); - const anchor = paragraphs.nth(6); - await anchor.scrollIntoViewIfNeeded(); + const anchor = paragraphs.nth(13); await body.hover(); await page.mouse.wheel(0, -160); await expect.poll(() => body.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeGreaterThan(100); diff --git a/webui/browser/typography.spec.ts b/webui/browser/typography.spec.ts index 900c777f0..b60f2834b 100644 --- a/webui/browser/typography.spec.ts +++ b/webui/browser/typography.spec.ts @@ -38,11 +38,12 @@ for (const narrow of [false, true]) { await expect(tables).toHaveCount(2); await expect(formulaTable.locator(".katex")).toHaveCount(7); await page.evaluate(() => document.fonts.ready); + expect(await page.evaluate(() => Array.from(document.fonts).some((font) => font.family === "Open Sans" && font.status === "loaded"))).toBe(true); const observations = []; for (const [size, label, bodySize] of [ - ["small", "阅读字号:小", narrow ? 15 : 16], - ["standard", "阅读字号:标准", narrow ? 16 : 18], - ["large", "阅读字号:大", narrow ? 18 : 20], + ["small", "阅读字号:小", 15], + ["standard", "阅读字号:标准", 16], + ["large", "阅读字号:大", 18], ] as const) { await group.getByRole("radio", { name: label, exact: true }).click(); await expect(page.locator("html")).toHaveAttribute("data-reading-text-size", size); @@ -50,13 +51,14 @@ for (const narrow of [false, true]) { await expect(paragraph).toHaveCSS("font-size", `${bodySize}px`); const body = await metrics(paragraph); expect(body.size).toBe(bodySize); - expect(body.line).toBeCloseTo(bodySize * 1.8); + expect(body.line).toBeCloseTo(bodySize * 1.6); expect(body.weight).toBe("400"); + expect(body.family).toContain("Open Sans"); expect((await metrics(page.locator("[data-user-text-bubble] p"))).size).toBe(bodySize); for (const selector of ["blockquote", "ol > li", ".task-list-item"]) { expect((await metrics(page.locator(`.markdown-content ${selector}`).first())).size).toBe(bodySize); } - for (const [selector, ratio] of [["h1", 1.5], ["h2", 1.25], ["h3", 1.125], ["h4", 1]] as const) { + for (const [selector, ratio] of [["h1", 2], ["h2", 1.5], ["h3", 1.25], ["h4", 1.125]] as const) { const heading = await metrics(page.locator(`.markdown-content ${selector}`)); expect(heading.size).toBeCloseTo(bodySize * ratio); expect(heading.weight).toBe("600"); @@ -128,7 +130,7 @@ test("keyboard, tooltip, persistence and unchanged preferences", async ({ page } const large = page.getByRole("radio", { name: "Large reading text", exact: true }); await expect(large).toBeFocused(); await expect(large).toBeChecked(); - await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${20 * 1.625}px`); + await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${18 * 1.6}px`); await page.reload(); await expect(page.getByRole("radio", { name: "Large reading text", exact: true })).toBeChecked(); expect(await page.evaluate(() => JSON.parse(localStorage.getItem("nanobot-webui.settings-preferences")!))).toMatchObject({ diff --git a/webui/public/licenses/open-sans.txt b/webui/public/licenses/open-sans.txt new file mode 100644 index 000000000..d762c3c46 --- /dev/null +++ b/webui/public/licenses/open-sans.txt @@ -0,0 +1,92 @@ +Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font +creation efforts of academic and linguistic communities, and to +provide a free and open framework in which fonts may be shared and +improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply to +any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software +components as distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, +deleting, or substituting -- in part or in whole -- any of the +components of the Original Version, by changing formats or by porting +the Font Software to a new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, +modify, redistribute, and sell modified and unmodified copies of the +Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in +Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the +corresponding Copyright Holder. This restriction only applies to the +primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created using +the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/webui/src/assets/fonts/open-sans-variable-italic.woff2 b/webui/src/assets/fonts/open-sans-variable-italic.woff2 new file mode 100644 index 000000000..ee46c3426 Binary files /dev/null and b/webui/src/assets/fonts/open-sans-variable-italic.woff2 differ diff --git a/webui/src/assets/fonts/open-sans-variable.woff2 b/webui/src/assets/fonts/open-sans-variable.woff2 new file mode 100644 index 000000000..fc5beceeb Binary files /dev/null and b/webui/src/assets/fonts/open-sans-variable.woff2 differ diff --git a/webui/src/components/DisplayMath.css b/webui/src/components/DisplayMath.css index 0380a8bb6..421be1068 100644 --- a/webui/src/components/DisplayMath.css +++ b/webui/src/components/DisplayMath.css @@ -29,10 +29,6 @@ padding-inline: calc(var(--math-tag-width) + 1em); } -.markdown-content:has(.math-fit) { - --cjk-line-height: 1.65; -} - .markdown-content li .math-fit { margin-block: 0.3em 0.35em; } diff --git a/webui/src/components/MarkdownTextRenderer.tsx b/webui/src/components/MarkdownTextRenderer.tsx index 7d86871e3..fab55ea69 100644 --- a/webui/src/components/MarkdownTextRenderer.tsx +++ b/webui/src/components/MarkdownTextRenderer.tsx @@ -831,9 +831,6 @@ export default function MarkdownTextRenderer({ components={components} className={cn( "markdown-content prose max-w-none dark:prose-invert", - "prose-headings:mt-4 prose-headings:mb-2 prose-headings:tracking-tight", - "prose-p:my-2", - "prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5", "prose-blockquote:my-3 prose-blockquote:border-l-2 prose-blockquote:font-normal", "prose-blockquote:not-italic prose-blockquote:text-foreground/80", "prose-a:text-content-link prose-a:underline-offset-2 hover:prose-a:text-content-link-hover", diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx index f9fda503c..aa8c8e994 100644 --- a/webui/src/components/thread/ThreadComposer.tsx +++ b/webui/src/components/thread/ThreadComposer.tsx @@ -1119,6 +1119,9 @@ export function ThreadComposer({ const [initialDraft] = useState(() => draftKey ? draftStore?.get(draftKey, persistDraft) : undefined); const [value, setValue] = useState(initialDraft?.text ?? ""); const [composerFocused, setComposerFocused] = useState(false); + const [placeholderHintRequested, setPlaceholderHintRequested] = useState(false); + const [placeholderHintOpen, setPlaceholderHintOpen] = useState(false); + const [placeholderHintBottomGap, setPlaceholderHintBottomGap] = useState(0); const blurFrame = useRef(null); const [boundSessionMentions, setBoundSessionMentions] = useState( initialDraft?.sessionMentions ?? [], @@ -1164,8 +1167,21 @@ export function ThreadComposer({ const textareaRef = useRef(null); const mentionOverlayRef = useRef(null); const formRef = useRef(null); + const tabFocusRequested = useRef(false); const [compactControls, setCompactControls] = useState(false); + useEffect(() => { + // Automatic session focus should not open the hint; keyboard navigation should. + const onKeyDown = (event: KeyboardEvent) => { tabFocusRequested.current = event.key === "Tab"; }; + const onPointerDown = () => { tabFocusRequested.current = false; }; + document.addEventListener("keydown", onKeyDown, true); + document.addEventListener("pointerdown", onPointerDown, true); + return () => { + document.removeEventListener("keydown", onKeyDown, true); + document.removeEventListener("pointerdown", onPointerDown, true); + }; + }, []); + useLayoutEffect(() => { const form = formRef.current; if (!form) return; @@ -1853,6 +1869,26 @@ export function ThreadComposer({ if (input) autosizeTextarea(input); }, [readingTextSize, customReadingTextSize]); + useLayoutEffect(() => { + const input = textareaRef.current; + if (!input || document.activeElement !== input || !placeholderHintRequested || input.value || !input.placeholder) { + setPlaceholderHintOpen(false); + return; + } + const form = formRef.current!; + const measure = () => { + setPlaceholderHintOpen(input.scrollWidth > input.clientWidth); + setPlaceholderHintBottomGap(form.getBoundingClientRect().bottom - input.getBoundingClientRect().bottom); + }; + measure(); + const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure); + observer?.observe(input); + observer?.observe(form); + let active = true; + void document.fonts?.ready.then(() => { if (active) measure(); }); + return () => { active = false; observer?.disconnect(); }; + }, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]); + // Runs before paint so switching sessions never flashes stale draft text. useLayoutEffect(() => { if (previousPendingQueueKeyRef.current === pendingQueueKey) return; @@ -2739,38 +2775,65 @@ export function ThreadComposer({ : null} /> ) : null} -