Multiplayer agent harness for work.
fix(web-ui): anchor touch layouts to the visual viewport (#1509)
Joshua Francef3d11986aaab
diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.cssindex c76c7f6f3..633205842 100644--- a/plugins/web-ui/src/shell.css+++ b/plugins/web-ui/src/shell.css@@ -10559,12 +10559,6 @@ h3.ambient-field-label {-webkit-tap-highlight-color: transparent;touch-action: manipulation;}- .layout {- height: 100dvh;- height: var(--vvh, 100dvh);-- transform: translateY(var(--vv-top, 0px));- }.sidebar,.layout.sidebar-closed .sidebar {@@ -11274,6 +11268,27 @@ h3.ambient-field-label {margin-top: calc(38px + env(safe-area-inset-top));}+@media (max-width: 860px), (hover: none) and (pointer: coarse) {+ .layout {+ position: fixed;+ inset: 0 0 auto;+ height: var(--vvh, 100dvh);+ transform: translateY(var(--vv-top, 0px));+ }+ .layout.bannered,+ .layout.impersonating {+ height: calc(var(--vvh, 100dvh) - 38px - env(safe-area-inset-top));+ }+ .top-banner,+ .impersonation-banner {+ transform: translateY(var(--vv-top, 0px));+ }+ .composer-input,+ .live-work-line {+ font-size: max(16px, var(--composer-font-size, 16px));+ }+}+.signin-panel,.signin form {display: flex;diff --git a/plugins/web-ui/src/viewport.ts b/plugins/web-ui/src/viewport.tsindex 3f25f0f9c..2c6c30481 100644--- a/plugins/web-ui/src/viewport.ts+++ b/plugins/web-ui/src/viewport.ts@@ -23,30 +23,13 @@ export function onPhoneChange(fn: (phone: boolean) => void): () => void {export function trackVisualViewport(): void {const vv = window.visualViewport;if (!vv) return;- let wasOpen = false;const apply = () => {- const h = Math.round(vv.height);- document.documentElement.style.setProperty("--vvh", `${h}px`);-- const open = window.innerHeight - h > 120;- document.documentElement.classList.toggle("kbd-open", open);- if (open) {- if (window.scrollY !== 0) window.scrollTo(0, 0);- document.documentElement.style.setProperty("--vv-top", `${Math.round(vv.offsetTop)}px`);- } else {- document.documentElement.style.setProperty("--vv-top", "0px");- }- if (open === wasOpen) return;- wasOpen = open;- if (!open) return;-- for (const el of document.querySelectorAll<HTMLElement>(".chat-scroll")) {- const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 160;- if (nearBottom) el.scrollTop = el.scrollHeight;- }+ if (vv.scale !== 1) return;+ document.documentElement.style.setProperty("--vvh", `${Math.round(vv.height)}px`);+ document.documentElement.style.setProperty("--vv-top", `${Math.round(vv.offsetTop)}px`);};vv.addEventListener("resize", apply);vv.addEventListener("scroll", apply);- window.addEventListener("scroll", apply, { passive: true });+ window.addEventListener("resize", apply);apply();}diff --git a/plugins/web-ui/test/pinned-composer-polish.test.ts b/plugins/web-ui/test/pinned-composer-polish.test.tsindex 2d343334c..627aaf958 100644--- a/plugins/web-ui/test/pinned-composer-polish.test.ts+++ b/plugins/web-ui/test/pinned-composer-polish.test.ts@@ -37,8 +37,14 @@ test("thinking shares input sizing while background activity stays compact", ()const blocks = css.matchAll(new RegExp(`${selector.replaceAll(".", "\\.")} \\{([^}]+)\\}`, "g"));const declarations = [...blocks].flatMap((match) => [...match[1].matchAll(/font-size: ([^;]+);/g)]);assert.ok(declarations.length > 0, selector);- for (const declaration of declarations) assert.match(declaration[1], /^var\(--composer-font-size[,)]/);+ for (const declaration of declarations) {+ assert.match(declaration[1], /^(?:max\(16px, )?var\(--composer-font-size[,)]/);+ }}+ assert.match(+ css,+ /@media \(max-width: 860px\), \(hover: none\) and \(pointer: coarse\) \{[^@]*\.composer-input,\s*\.live-work-line \{\s*font-size: max\(16px, var\(--composer-font-size, 16px\)\);/,+ );});test("queued cards tuck beneath the next card just as the queue tucks beneath the composer", () => {diff --git a/plugins/web-ui/test/viewport.test.ts b/plugins/web-ui/test/viewport.test.tsindex 21523cc01..0a7347861 100644--- a/plugins/web-ui/test/viewport.test.ts+++ b/plugins/web-ui/test/viewport.test.ts@@ -1,10 +1,12 @@import assert from "node:assert/strict";+import { readFileSync } from "node:fs";import test from "node:test";import { JSDOM } from "jsdom";class FakeVisualViewport extends EventTarget {height = 659;offsetTop = 0;+ scale = 1;}const dom = new JSDOM('<div class="chat-scroll"></div>', { url: "https://example.test/" });@@ -12,18 +14,13 @@ const vv = new FakeVisualViewport();let scrollCalls = 0;Object.defineProperties(dom.window, {innerHeight: { value: 659, configurable: true },- scrollY: { get: () => (vv.offsetTop ? 309 : 0), configurable: true },+ scrollY: { value: 309, configurable: true },visualViewport: { value: vv, configurable: true },matchMedia: {value: () => ({ matches: true, addEventListener() {}, removeEventListener() {} }),configurable: true,},- scrollTo: {- value: () => {- scrollCalls++;- },- configurable: true,- },+ scrollTo: { value: () => scrollCalls++, configurable: true },});Object.assign(globalThis, { document: dom.window.document, window: dom.window });@@ -36,26 +33,78 @@ Object.defineProperties(transcript, {const { trackVisualViewport } = await import("../src/viewport.ts");trackVisualViewport();+const style = dom.window.document.documentElement.style;++function viewport(height: number, offsetTop = 0, scale = 1, event = "resize") {+ Object.assign(vv, { height, offsetTop, scale });+ vv.dispatchEvent(new Event(event));+}++test("keyboard resize and pan follow the visual viewport without fighting document scroll", () => {+ viewport(350, 309);+ assert.equal(style.getPropertyValue("--vvh"), "350px");+ assert.equal(style.getPropertyValue("--vv-top"), "309px");+ assert.equal(scrollCalls, 0);+ assert.equal(transcript.scrollTop, 300);++ viewport(350, 221, 1, "scroll");+ assert.equal(style.getPropertyValue("--vv-top"), "221px");+ assert.equal(scrollCalls, 0);++ viewport(659);+ assert.equal(style.getPropertyValue("--vvh"), "659px");+ assert.equal(style.getPropertyValue("--vv-top"), "0px");+});++test("small viewport changes track their origin without a keyboard-height threshold", () => {+ viewport(600, 40);+ assert.equal(style.getPropertyValue("--vvh"), "600px");+ assert.equal(style.getPropertyValue("--vv-top"), "40px");+});++test("pinch zoom does not resize or reposition the app shell", () => {+ viewport(659);+ viewport(329.5, 100, 2);+ viewport(329.5, 160, 2, "scroll");+ assert.equal(style.getPropertyValue("--vvh"), "659px");+ assert.equal(style.getPropertyValue("--vv-top"), "0px");+ viewport(350, 80);+ assert.equal(style.getPropertyValue("--vvh"), "350px");+ assert.equal(style.getPropertyValue("--vv-top"), "80px");+});++test("window resize refreshes geometry after orientation changes", () => {+ Object.assign(vv, { height: 280, offsetTop: 10, scale: 1 });+ dom.window.dispatchEvent(new dom.window.Event("resize"));+ assert.equal(style.getPropertyValue("--vvh"), "280px");+ assert.equal(style.getPropertyValue("--vv-top"), "10px");+});++test("browsers without VisualViewport use the CSS fallback", () => {+ Object.defineProperty(dom.window, "visualViewport", { value: undefined, configurable: true });+ assert.doesNotThrow(trackVisualViewport);+ Object.defineProperty(dom.window, "visualViewport", { value: vv, configurable: true });+});++test("the phone shell is anchored to the layout viewport rather than document flow", () => {+ const css = readFileSync(new URL("../src/shell.css", import.meta.url), "utf8");+ const layout = [...css.matchAll(/\.layout \{([^}]+)\}/g)].find((match) => match[1]!.includes("--vvh"))![1]!;+ assert.match(css, /@media \(max-width: 860px\), \(hover: none\) and \(pointer: coarse\)/);+ assert.match(layout, /position: fixed;/);+ assert.match(layout, /inset: 0 0 auto;/);+ assert.match(layout, /height: var\(--vvh, 100dvh\);/);+ assert.match(layout, /transform: translateY\(var\(--vv-top, 0px\)\);/);+});-test("an iOS keyboard offset anchors the app to the visual viewport on every viewport event", () => {- vv.height = 350;- vv.offsetTop = 309;- vv.dispatchEvent(new Event("resize"));-- assert.equal(dom.window.document.documentElement.style.getPropertyValue("--vvh"), "350px");- assert.equal(dom.window.document.documentElement.style.getPropertyValue("--vv-top"), "309px");- assert.equal(dom.window.document.documentElement.classList.contains("kbd-open"), true);- assert.equal(scrollCalls, 1);- assert.equal(transcript.scrollTop, 900);-- vv.offsetTop = 221;- vv.dispatchEvent(new Event("scroll"));- assert.equal(dom.window.document.documentElement.style.getPropertyValue("--vv-top"), "221px");- assert.equal(scrollCalls, 2);-- vv.height = 659;- vv.offsetTop = 0;- vv.dispatchEvent(new Event("resize"));- assert.equal(dom.window.document.documentElement.style.getPropertyValue("--vv-top"), "0px");- assert.equal(dom.window.document.documentElement.classList.contains("kbd-open"), false);+test("keyboard sizing includes bannered shells and touch inputs avoid focus zoom", () => {+ const css = readFileSync(new URL("../src/shell.css", import.meta.url), "utf8");+ assert.match(+ css,+ /\.layout\.bannered,\s*\.layout\.impersonating \{\s*height: calc\(var\(--vvh, 100dvh\) - 38px - env\(safe-area-inset-top\)\);/,+ );+ assert.match(css, /\.top-banner,\s*\.impersonation-banner \{\s*transform: translateY\(var\(--vv-top, 0px\)\);/);+ assert.match(+ css,+ /\.composer-input,\s*\.live-work-line \{\s*font-size: max\(16px, var\(--composer-font-size, 16px\)\);/,+ );});