From 5d0285c1ddc7a4e3e6b9704d305dab01942e7d5f Mon Sep 17 00:00:00 2001 From: Yoko Date: Fri, 4 Dec 2026 19:41:35 +0800 Subject: [PATCH 1/2] fix(ai-chat-turbo-engine): adopt a flyout by where it is painted, not by when (#280) --- .../src/core/sidebar-peek.ts | 202 ++++++++++++------ tests/ai-chat-turbo-sidebar-peek.test.ts | 91 +++++++- 2 files changed, 223 insertions(+), 70 deletions(-) diff --git a/scripts/ai-chat-turbo-engine/src/core/sidebar-peek.ts b/scripts/ai-chat-turbo-engine/src/core/sidebar-peek.ts index cfbd6e2..ccfd0df 100644 --- a/scripts/ai-chat-turbo-engine/src/core/sidebar-peek.ts +++ b/scripts/ai-chat-turbo-engine/src/core/sidebar-peek.ts @@ -120,14 +120,21 @@ const POPOVER_SELECTOR = [ const POPOVER_RECHECK_MS = 400; /** - * How long after the pointer last rested on the peek a flyout it mounts still - * belongs to that peek. History row menus are mounted next to the panel, - * outside the rail's own subtree, and most sites annotate them with no role at - * all, so the hand-off from a rail row into that menu is the only reliable - * link between them. The window is bounded because a flyout the user walks - * into long afterwards belongs to the page, not to the hover that ended. + * How far outside the panel a flyout's box may sit and still belong to the + * peek. History row menus are mounted beside the panel, outside the rail's own + * subtree, and most sites annotate them with no role at all, so neither the + * rail subtree nor the popover selectors find them. Distance is what separates + * them from a dialog the page opened elsewhere: the menu hangs off a row, so it + * lands within this margin of the box the peek actually paints. */ -export const SIDEBAR_PEEK_HANDOFF_MS = 500; +export const SIDEBAR_PEEK_ADOPT_MARGIN_PX = 32; + +/** + * A floating box at least this wide, measured against the viewport, is page + * chrome rather than a flyout: an app shell, a scrim, a chat header. Left in, + * walking from the panel into the chat column would hold the peek there. + */ +export const SIDEBAR_PEEK_ADOPT_MAX_WIDTH_RATIO = 0.6; /** * Minimum gap between pointer-move probes. The hover intent delay is longer @@ -355,15 +362,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { * Hovering one is hovering the peek, however far from the rail it is painted. */ const peekLayers = new Set(); - /** When the pointer last rested on the rail or on an adopted layer. */ - let lastPeekPointerMs = Number.NEGATIVE_INFINITY; - /** - * When the pointer last walked off an adopted layer. The submenu a row menu - * opens is often portaled into a sibling wrapper a few pixels away, so the - * event that names it can arrive from the gap between the two boxes instead - * of from the menu itself. That departure is the hand-off. - */ - let lastLayerExitMs = Number.NEGATIVE_INFINITY; const hasRail = sidebarSelectors.length > 0; @@ -740,8 +738,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { rescanNeeded = false; preexistingPopovers.clear(); peekLayers.clear(); - lastPeekPointerMs = Number.NEGATIVE_INFINITY; - lastLayerExitMs = Number.NEGATIVE_INFINITY; const node = active; if (node === null) return; active = null; @@ -1800,7 +1796,7 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { if (typeof doc.elementFromPoint !== "function") return null; const hit = doc.elementFromPoint(pointerX, pointerY); if (!(hit instanceof Element)) return null; - return peekLayerAt(hit) ?? popoverFor(hit); + return peekLayerAt(hit) ?? adoptPeekLayer(hit) ?? popoverFor(hit); } /** @@ -1892,17 +1888,98 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { } /** - * Adopt the out-of-flow wrapper the pointer just walked into from the peek. - * Page content is laid out in flow, and a wrapper that holds the rail is the - * app shell rather than a menu: both are rejected, so only a floating box - * the pointer reached straight from the panel becomes part of it. The - * outermost such ancestor wins, which is what lets a submenu hang off the - * menu that opened it and still count. + * The patch of screen the peek paints, in boxes: the rail's live box, the box + * it was last drawn at, every inner shell the panel was stretched through, + * and every layer already adopted. A flyout hangs off a row inside one of + * these, so touching this region is what identifies it as the peek's. */ - function adoptPeekLayer( - target: Element, - fromLayer = false, - ): HTMLElement | null { + function panelRegionRects(rail: HTMLElement): ScreenBox[] { + const boxes: ScreenBox[] = []; + const add = (box: ScreenBox): void => { + if (box.right - box.left <= 0 || box.bottom - box.top <= 0) return; + boxes.push(box); + }; + // The rail's own box is only as wide as the site left it, so the band the + // peek paints is the rail's box grown by the peek away from its edge. + const live = rail.getBoundingClientRect(); + const reach = Math.max(live.width, activePeekWidth); + const top = live.height > 0 ? live.top : 0; + const bottom = live.height > 0 ? live.bottom : viewportHeightOf(rail); + add( + activeSide === "right" + ? { left: live.right - reach, right: live.right, top, bottom } + : { left: live.left, right: live.left + reach, top, bottom }, + ); + if (peekBand !== null) boxes.push(peekBand); + for (const shell of shellTargets) { + const box = shell.node.getBoundingClientRect(); + add({ + left: box.left, + right: box.right, + top: box.top, + bottom: box.bottom, + }); + } + for (const layer of peekLayers) { + if (!layer.isConnected) { + peekLayers.delete(layer); + continue; + } + const box = layer.getBoundingClientRect(); + add({ + left: box.left, + right: box.right, + top: box.top, + bottom: box.bottom, + }); + } + return boxes; + } + + /** Whether a flyout's box sits against the region the peek paints. */ + function rectTouchesRegion(rect: ScreenBox, region: ScreenBox[]): boolean { + return region.some( + (box) => + rect.left <= box.right + SIDEBAR_PEEK_ADOPT_MARGIN_PX && + rect.right >= box.left - SIDEBAR_PEEK_ADOPT_MARGIN_PX && + rect.top <= box.bottom + SIDEBAR_PEEK_ADOPT_MARGIN_PX && + rect.bottom >= box.top - SIDEBAR_PEEK_ADOPT_MARGIN_PX, + ); + } + + /** + * A menu the site mounts while the pointer rests on a row appears under that + * pointer and fires no move of its own, so the box the cursor is inside + * counts as the peek's even when the site parked it away from the panel. + */ + function boxHoldsCursor(box: ScreenBox): boolean { + if (!Number.isFinite(pointerX) || !Number.isFinite(pointerY)) return false; + return ( + pointerX >= box.left && + pointerX <= box.right && + pointerY >= box.top && + pointerY <= box.bottom + ); + } + + /** + * Adopt the floating box the pointer reached from the panel: a history row + * menu, or the submenu that hangs off that menu. + * + * Page content is laid out in flow and a wrapper that holds the rail is the + * app shell, so only an out-of-flow box (or one carrying a popup role) that + * is narrow enough to be a flyout and lands within reach of the panel can + * join the peek. "Within reach" is either adjacency to the box the peek + * paints, which is how a menu mounted beside the panel is found, or the box + * the pointer is inside, which is how a menu mounted under a resting cursor + * is found. The outermost such ancestor wins, which is what lets a submenu + * hang off the menu that opened it and still count. + * + * Placement decides this, never elapsed time. A row menu that a site mounts + * under a resting cursor produces no pointer event of its own, and a budget + * measured from the pointer's last move dropped exactly that menu. + */ + function adoptPeekLayer(target: Element): HTMLElement | null { const known = peekLayerAt(target); if (known !== null) return known; const doc = boundDocument; @@ -1914,18 +1991,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { // is still the best answer for "which wrapper belongs to the page shell" // even when the current selector no longer resolves it. const rail = resolvedRail ?? active; - if (!fromLayer) { - const now = performance.now(); - // A flyout reached straight off the rail belongs to the hover that - // opened it; one reached off an adopted menu belongs to that menu, no - // matter how long the pointer rested on it before asking for the - // submenu. - const handedOffFromPeek = - now - lastPeekPointerMs <= SIDEBAR_PEEK_HANDOFF_MS; - const handedOffFromLayer = - now - lastLayerExitMs <= SIDEBAR_PEEK_HANDOFF_MS; - if (!handedOffFromPeek && !handedOffFromLayer) return null; - } const candidates: HTMLElement[] = []; for ( let node: Element | null = target; @@ -1949,21 +2014,29 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { candidates.push(node); } } + if (candidates.length === 0) return null; + const region = panelRegionRects(rail); for (let index = candidates.length - 1; index >= 0; index -= 1) { const layer = candidates[index] as HTMLElement; // A menu the page already had on screen is the page's own, and a wrapper // it closed is not the one the pointer is using. if (isPreexistingPopover(layer)) continue; if (!isVisiblePopover(layer, view)) continue; - // A viewport-sized fixed wrapper is the page chrome, not a flyout. Left - // in, walking from the rail into the chat column would keep the panel - // open for as long as the pointer moved there. const rect = layer.getBoundingClientRect(); if ( view.innerWidth > 0 && - view.innerHeight > 0 && - rect.width >= view.innerWidth * 0.7 && - rect.height >= view.innerHeight * 0.6 + rect.width >= view.innerWidth * SIDEBAR_PEEK_ADOPT_MAX_WIDTH_RATIO + ) { + continue; + } + if ( + !rectTouchesRegion(rect, region) && + !boxHoldsCursor({ + left: rect.left, + right: rect.right, + top: rect.top, + bottom: rect.bottom, + }) ) { continue; } @@ -2021,7 +2094,10 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { if (current.contains(hit) || rail.contains(hit)) return true; // A row menu or a submenu the peek adopted is painted outside the rail // but is still the peek: hovering it is not leaving the panel. - if (peekLayerAt(hit) !== null) return true; + // A menu can also be mounted directly under a resting cursor, which + // fires no pointer event of its own, so the box under the pointer is + // adopted here instead of only being looked up. + if ((peekLayerAt(hit) ?? adoptPeekLayer(hit)) !== null) return true; // Gemini and Grok open through their own toggle, which sits outside the // rail. The pointer still rests on the control that opened the panel, so // the peek must not close underneath it. @@ -2066,7 +2142,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { // A flyout the pointer just walked into from the panel is part of the // peek from here on, so hide nothing and keep the deadline unarmed. if (adoptPeekLayer(target) !== null) { - lastPeekPointerMs = performance.now(); cancelHide(); return; } @@ -2075,7 +2150,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { if (pointerReturnedToPeek()) cancelHide(); return; } - lastPeekPointerMs = performance.now(); if (active === rail) { liftInert(rail); if (rescanNeeded) { @@ -2102,7 +2176,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { if (target instanceof Element) { const overRail = railFor(target); if (overRail !== null) { - lastPeekPointerMs = performance.now(); // A move that already lands on the rail is the strongest form of the // same intent. Waiting for pointerover loses the first approach when // the rail sits under a transparent overlay, when its box is zero @@ -2115,7 +2188,6 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { // A flyout a site re-renders under the resting pointer arrives here as a // move rather than a pointerover; it is still the peek. if (target instanceof Element && adoptPeekLayer(target) !== null) { - lastPeekPointerMs = performance.now(); cancelHide(); return; } @@ -2214,16 +2286,11 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { // row menu, so that departure arms the grace here. const layer = peekLayerAt(target); if (layer === null || active === null) return; - lastLayerExitMs = performance.now(); if (related instanceof Element && ownedByPeek(related)) return; // Walking from the row menu into the submenu it opens is still the // peek: adopt the box the pointer is heading into instead of arming a // hide the pointer is about to outrun. - if ( - related instanceof Element && - adoptPeekLayer(related, true) !== null - ) { - lastPeekPointerMs = performance.now(); + if (related instanceof Element && adoptPeekLayer(related) !== null) { cancelHide(); return; } @@ -2231,6 +2298,13 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { return; } if (related instanceof Element && ownedByPeek(related)) return; + // The box the pointer is heading into may be a flyout the page has not + // given a pointer event yet: adopt it so the hide that follows finds the + // pointer inside the peek. + if (related instanceof Element && adoptPeekLayer(related) !== null) { + cancelHide(); + return; + } scheduleHide(rail); } @@ -2275,7 +2349,13 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { const target = event.target; if (!(target instanceof Element)) return; // A row menu the peek adopted is pressed as part of the panel. - if (!rail.contains(target) && peekLayerAt(target) === null) return; + if ( + !rail.contains(target) && + peekLayerAt(target) === null && + adoptPeekLayer(target) === null + ) { + return; + } if (keepsPeek(target)) return; const anchor = target.closest("a[href]"); const view = rail.ownerDocument.defaultView; @@ -2344,7 +2424,9 @@ export function createSidebarPeek(options: SidebarPeekOptions): SidebarPeek { // the site portals that menu outside the rail. if ( active !== null && - (peekLayerAt(target) !== null || popoverFor(target) !== null) + (peekLayerAt(target) !== null || + adoptPeekLayer(target) !== null || + popoverFor(target) !== null) ) { cancelHide(); // The click may close the menu or keep it open for another choice; the diff --git a/tests/ai-chat-turbo-sidebar-peek.test.ts b/tests/ai-chat-turbo-sidebar-peek.test.ts index 32805c9..7db1b56 100644 --- a/tests/ai-chat-turbo-sidebar-peek.test.ts +++ b/tests/ai-chat-turbo-sidebar-peek.test.ts @@ -4,7 +4,6 @@ import { SIDEBAR_PEEK_ATTRIBUTE, SIDEBAR_PEEK_CLICK_RELEASE_MS, SIDEBAR_PEEK_HIDE_DELAY_MS, - SIDEBAR_PEEK_HANDOFF_MS, SIDEBAR_PEEK_HOLD_ATTRIBUTE, SIDEBAR_PEEK_KEYBOARD_FOCUS_MS, SIDEBAR_PEEK_NAVIGATION_COLLAPSE_MS, @@ -661,7 +660,7 @@ describe("sidebar hover peek", () => { dispatchPointer("pointerover", row, null, "mouse", 40, 100); dispatchPointer("pointerout", row, entry, "mouse", 300, 100); dispatchPointer("pointerover", entry, row, "mouse", 300, 100); - vi.advanceTimersByTime(SIDEBAR_PEEK_HANDOFF_MS + 200); + vi.advanceTimersByTime(SIDEBAR_PEEK_HIDE_DELAY_MS * 4); expect(instance.isPeeking()).toBe(true); const restoreSub = stubHit(subEntry); @@ -715,7 +714,7 @@ describe("sidebar hover peek", () => { dispatchPointer("pointerover", row, null, "mouse", 40, 100); dispatchPointer("pointerout", row, entry, "mouse", 300, 100); dispatchPointer("pointerover", entry, row, "mouse", 300, 100); - vi.advanceTimersByTime(SIDEBAR_PEEK_HANDOFF_MS + 200); + vi.advanceTimersByTime(SIDEBAR_PEEK_HIDE_DELAY_MS * 4); const restoreGap = stubHit(chat); try { @@ -772,8 +771,12 @@ describe("sidebar hover peek", () => { } }); - /** A flyout that shows up long after the hover belongs to the page. */ - it("does not adopt a flyout the pointer reached long after the hover", () => { + /** + * The row menu is mounted beside the panel, not over the pointer, so + * adjacency to the box the peek paints is what ties it to the peek. Elapsed + * time plays no part: a menu the user reads for a while is still the menu. + */ + it("keeps the peek on a row menu painted just past the panel", () => { const instance = start(); hoverButton(); vi.advanceTimersByTime(SIDEBAR_PEEK_SHOW_DELAY_MS); @@ -781,20 +784,53 @@ describe("sidebar hover peek", () => { const row = document.getElementById("history"); if (!(row instanceof HTMLElement)) throw new Error("missing history row"); stubNodeRect(row, 248, 32, 0); - dispatchPointer("pointerover", row, null, "mouse", 40, 100); - vi.advanceTimersByTime(SIDEBAR_PEEK_HANDOFF_MS + 200); + const menu = document.createElement("div"); + menu.style.position = "absolute"; + stubNodeRect(menu, 180, 120, 252); + const entry = document.createElement("button"); + entry.textContent = "Rename"; + menu.appendChild(entry); + document.body.appendChild(menu); + const restore = stubHit(entry); + + try { + dispatchPointer("pointerover", row, null, "mouse", 40, 100); + dispatchPointer("pointerout", row, entry, "mouse", 600, 400); + dispatchPointer("pointerover", entry, row, "mouse", 600, 400); + vi.advanceTimersByTime(SIDEBAR_PEEK_HIDE_DELAY_MS); + expect(instance.isPeeking()).toBe(true); + } finally { + restore(); + menu.remove(); + } + }); + + /** + * A menu the site paints away from both the panel and the pointer is page + * chrome: adopting it would hold the peek open from across the app. + */ + it("does not adopt a flyout painted away from the panel", () => { + const instance = start(); + hoverButton(); + vi.advanceTimersByTime(SIDEBAR_PEEK_SHOW_DELAY_MS); + const row = document.getElementById("history"); + if (!(row instanceof HTMLElement)) throw new Error("missing history row"); + stubNodeRect(row, 248, 32, 0); + const chat = document.getElementById("chat"); + if (!(chat instanceof HTMLElement)) throw new Error("missing chat"); const menu = document.createElement("div"); menu.style.position = "absolute"; - stubNodeRect(menu, 180, 120, 300); + stubNodeRect(menu, 180, 120, 340); const entry = document.createElement("button"); menu.appendChild(entry); document.body.appendChild(menu); const restore = stubHit(entry); try { - dispatchPointer("pointerout", row, entry, "mouse", 300, 100); - dispatchPointer("pointerover", entry, row, "mouse", 300, 100); + dispatchPointer("pointerover", row, null, "mouse", 40, 100); + dispatchPointer("pointerout", row, chat, "mouse", 600, 400); + dispatchPointer("pointerover", chat, row, "mouse", 600, 400); vi.advanceTimersByTime(SIDEBAR_PEEK_HIDE_DELAY_MS); expect(instance.isPeeking()).toBe(false); } finally { @@ -803,6 +839,41 @@ describe("sidebar hover peek", () => { } }); + /** + * Sites mount the row menu from their own handler, so the menu can appear + * under a pointer that never moves again. That arrival names no element and + * arms no timer: only the departure from the row mentions the menu, and the + * box under the cursor has to carry the peek from there. + */ + it("keeps the peek on a menu mounted under the resting pointer", () => { + const instance = start(); + hoverButton(); + vi.advanceTimersByTime(SIDEBAR_PEEK_SHOW_DELAY_MS); + + const row = document.getElementById("history"); + if (!(row instanceof HTMLElement)) throw new Error("missing history row"); + stubNodeRect(row, 248, 32, 0); + dispatchPointer("pointerover", row, null, "mouse", 40, 100); + + const menu = document.createElement("div"); + menu.style.position = "absolute"; + stubNodeRect(menu, 200, 120, 0); + const entry = document.createElement("button"); + entry.textContent = "Rename"; + menu.appendChild(entry); + document.body.appendChild(menu); + const restore = stubHit(entry); + + try { + dispatchPointer("pointerout", row, entry, "mouse", 40, 100); + vi.advanceTimersByTime(SIDEBAR_PEEK_HIDE_DELAY_MS); + expect(instance.isPeeking()).toBe(true); + } finally { + restore(); + menu.remove(); + } + }); + it("closes immediately on an outside press or the native toggle", () => { const instance = start(); hoverButton(); From a7b558cc8e5e150fb78b357fb7eb1caee1b91bec Mon Sep 17 00:00:00 2001 From: Yoko Date: Fri, 4 Dec 2026 19:42:29 +0800 Subject: [PATCH 2/2] chore(ai-chat-turbo): bump version to 0.23.19 (#280) --- docs/ai-chat-turbo-engine.md | 14 ++++++++++++-- scripts/ai-chat-turbo-engine/meta.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/ai-chat-turbo-engine.md b/docs/ai-chat-turbo-engine.md index 8367e9a..64d32ac 100644 --- a/docs/ai-chat-turbo-engine.md +++ b/docs/ai-chat-turbo-engine.md @@ -2,7 +2,7 @@ 面向长对话与重度使用的跨平台 AI 聊天增强用户脚本。在受支持的 AI 对话页面上叠加一层轻量增强,解决四类实际痛点:长会话渲染变卡、超长代码块挤占阅读空间、大段文本撑爆输入框、上下文难以迁移到新会话。 -当前版本:**0.23.17** +当前版本:**0.23.19** 许可证:**MIT** 运行方式:单文件用户脚本,无外部依赖,无网络请求,不申请任何 GM 权限。 @@ -135,7 +135,7 @@ contain-intrinsic-size: auto var(--turbo-cached-h, 120px); - **脚本只碰必要的内联值。** ChatGPT 的展开面板常驻 DOM,但滚动区带内联的隐藏声明,样式表压不过它,因此探出模块按快照临时抬起该声明、收回时原样写回;这是唯一需要改内联样式的情况,同样不复制节点。 - **内容不再被内层容器裁掉。** 有些站点把面板内容挂在按折叠宽度写死的容器上,只加宽导轨会出现「导轨变宽了、标签仍被裁」的半截状态。平台在 `sidebar.shells` 里列出这些容器(ChatGPT 的 `#app-shell-sidebar`、Gemini 的 `bard-sidenav` 等),探出时同时给 `width` / `min-width` / `max-width` 写探出宽度,收回时按内联快照逐条还原;基础规则也带 `min-width`、`max-width` 与 `box-sizing: border-box`,避免站点自己的 `max-width` 把加宽压回去。 - **中间空隙不会打断探出。** 面板内容可能画在导轨之外的兄弟层里,指针经过这些空白区域时 `elementFromPoint` 命中的是空白、透明遮罩或别的节点。探出期间改用几何包含判断:导轨自身加宽后的矩形,加上所有被拉伸的 shell 矩形,指针落在其中任一处都算仍在面板上;真正离开这条带才进入 160ms 的收回宽限。 -- **历史行菜单与挂在它下面的子菜单算作面板。** 二级菜单由站点画在导轨之外:有的挂到 body,有的挂在行旁边的定位层里,多数还不带 `role`,既不在导轨子树内,也命中不了弹层选择器,于是从行上滑进菜单就被当成离开面板,按下 160ms 宽限收回。现在探出会认领指针从面板直接走进的那层脱离文档流的壳:只接受处于 `absolute` / `fixed` / `sticky` 或自带弹层语义、且不包含导轨的外层(页面的应用外壳在文档流里,不在其列),连同它下面挂的子菜单一起算作面板。从导轨进入第一层菜单仍要求在指针最后一次停在面板上之后的 **500ms** 内(按住不动再滑过去时,移动本身会刷新这个时间);一旦进入已认领的菜单,它再弹出的子菜单只按「从哪离开」判定,不再受停顿时长限制,跨过两框之间几像素空隙时用离开菜单的时刻续上这段交接。页面自己原有的弹层不认领,被站点销毁的层也随之失效,因此不会把页面上顺手打开的菜单粘在探出上。从认领层离开同样算「离开面板」,照旧走 160ms 宽限。 +- **历史行菜单与挂在它下面的子菜单算作面板。** 二级菜单由站点画在导轨之外:有的挂到 body,有的挂在行旁边的定位层里,多数还不带 `role`,既不在导轨子树内,也命中不了弹层选择器,于是从行上滑进菜单就被当成离开面板,按下 160ms 宽限收回。现在探出把「面板画在哪」当成唯一依据:认领指针要从面板进去的那层脱离文档流的壳,只接受处于 `absolute` / `fixed` / `sticky` 或自带弹层语义、不包含导轨、且宽度小于视口 60% 的外层(页面的应用外壳在文档流里,不在其列;视口级的固定壳同样按宽度排除)。认定依据有两条,都不看时间:菜单的矩形与探出所画区域(导轨加宽后的带、被拉伸的 shell、已认领的层)相距 **32px** 以内,或者菜单的矩形正罩住指针(站点在指针停住时把菜单挂到光标下面,这种情况下它不产生任何指针事件)。已认领的菜单本身会加入这块区域,所以它弹出的子菜单、子菜单再弹出的下一层都依次相邻可认,跨过两框之间几像素空隙也不受影响。页面自己原有的弹层不认领,被站点销毁的层也随之失效,因此不会把页面上顺手打开的菜单粘在探出上。从认领层离开同样算「离开面板」,照旧走 160ms 宽限。 - **导航后立刻退场。** 点击探出面板里的历史条目会由站点自己换路由并重建导航,此时再点一次原生折叠按钮,会命中新路由下的另一个控件,并与页面自己的过渡抢时序,表现就是收回极慢。探出在点击捕获阶段就撤销,且记录「打开时按下的是哪个原生控件」,路由或文档变化后不再按下它;`popstate` / `hashchange`、导轨被替换、`location.href` 与打开时不一致,都走同一条无动画退场路径。 - **状态以站点为准。** 站点自己展开侧栏、节点被替换、或者按下原生开关时,探出属性立即撤销;在原生开关上按 Enter / 空格、Esc、在侧栏外按下指针也会立即收回。触屏与手写笔指针不触发。 - **其余平台默认关闭。** 只有 PLATFORMS 中声明了 sidebar 的平台启用,未声明的平台不注册任何监听。豆包与元宝用 transform 把侧栏整体移出容器,千问折叠后导航节点直接消失,纯 CSS 加宽不可行;Grok 与 Poe 走站点自己的开合控件。 @@ -524,6 +524,16 @@ pointerdown → mousedown → pointerup → mouseup → click ## 版本记录 +### 0.23.19 + +**修好上一版仍未修掉的问题:指针滑进历史记录的二级菜单(以及它的下一级)时,侧边栏还是会自己缩回去。** + +- **问题,交接靠时间窗。** 上一版用「指针最后一次停在面板或已认领层之后的 **500ms** 内」来认定下一层菜单。真实站点上这条窗口并不成立:站点常把行菜单挂在**不动的光标下面**,此时没有任何 `pointerover` / `pointermove` 会被派发,时间戳停在滑入行之前,窗口一到菜单就不被认领;菜单与面板之间也可能隔开十几到几十像素,超出邻近判定。 +- **改为按位置认定。** 撤销时间窗,改成两条几何依据:菜单矩形与探出所画区域(导轨加宽后的带、被拉伸的 `shell`、已认领的层)相距 **32px** 以内即算面板;或者菜单矩形正罩住指针——站点在光标下面挂出的菜单走这一条。已认领层的矩形并入该区域,因此子菜单、孙菜单逐层相邻即可接力,停多久都不会因此收回。 +- **判定顺序更严。** 仍要求候选是不包含导轨的 `absolute` / `fixed` / `sticky` 或带弹层语义的外层,并且宽度小于视口 **60%**:视口级的固定壳、页面自己原有的弹层、以及被站点销毁的层都不认领,避免把页面上的悬浮层粘在探出上。 +- **指针读表也走认领。** 收回宽限到点时读 `elementFromPoint`,命中的节点若不是已知层就先尝试认领,再判断是否仍在面板上;指针移出面板边缘之前弹出的菜单因此不会再被误判成「已离开」。 +- **测试覆盖。** 探出用例重写为几何语义:贴面板的画出的行菜单被认领、远处悬浮层不认领、菜单在指针停驻后挂到光标下面(不派发任何移动事件)仍保持探出、子菜单跨空隙接力、视口级固定壳不认领;原有的撑宽、回收、导航退场等用例全部保持通过。 + ### 0.23.18 **修好悬停探出在历史记录二级菜单上误收回、设置面板版本号恒为 0.0.0,以及元宝 `Shift + Enter` 换行后输入标点会重复一次的问题。** diff --git a/scripts/ai-chat-turbo-engine/meta.ts b/scripts/ai-chat-turbo-engine/meta.ts index d3cfab7..dd1789c 100644 --- a/scripts/ai-chat-turbo-engine/meta.ts +++ b/scripts/ai-chat-turbo-engine/meta.ts @@ -4,7 +4,7 @@ import { PLATFORM_MATCH_PATTERNS } from "./src/config"; const meta = { name: "AI Chat Turbo Engine", namespace: "https://cyojkoy.github.io/Payment/", - version: "0.23.18", + version: "0.23.19", description: "跨平台 AI 对话加速:常驻统计 + 完整消息提取 + YAML 交接 + 多平台适配 + 长代码折叠 + 自适应脱水 + 推理强度记忆 + 元宝原子工具记忆 + 新对话快捷键覆盖", author: "Yoko", updateURL: "https://cdn.jsdelivr.net/gh/CYoJkoY/Yoko-ScriptCat-Scripts@release/ai-chat-turbo-engine.user.js",