Merge remote-tracking branch 'origin/master' into worktree/composer-scrollbar-gutter

This commit is contained in:
creatixchu
2026-08-04 16:42:45 +08:00
20 changed files with 582 additions and 41 deletions

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/ui-sidebar/README.md
README.md: 19c2d1033de4475816249aa8429f4a589eeb6481
README.zh.md: b8c154586570cf1b9fd4bf776bc09b36ab5ee7d2
README.md: 5bb697b3d2f9b5eaea9c382765d2510fa24806ce
README.zh.md: 302f66c540774b1f209fc797201e41c56b849310

View File

@@ -8,6 +8,8 @@ New Session starts the runtime's page-local frontend Session Intent; a real Work
`SidebarRootComponentProps` composes the layout owner share, the global `useSessions` and `useWorkspaces` hooks, the declared `sidebar.workspace` and `sidebar.settings` child slots, and injected `startSession`, `open`, and sidebar-toggle callbacks. There is no plugin store: `deriveGroups` consumes object-layer snapshots and component-local expansion/search state.
Scrollbars in the column are a pointer affordance: the shell rebinds ui-theme's [scrollbar indirection](../ui-theme/README.md) to `transparent` whenever the pointer is outside it, and keeps the thumb drawn for 2s after the pointer leaves, so a list nobody is pointing at carries no bar. The reservation that keeps rows from moving belongs to the scrolling region ([ui-workspace](../ui-workspace/README.md)), so revealing a thumb never reflows.
The foot is the `sidebar.settings` seat: the sidebar renders only the bottom-pinned layout slot and shares its column state (`wide`); ui-settings registers the trigger row and settings panel there.
The `/client` export surface is the plugin body (`apply`/`inject`) plus the contract types only — SidebarRoot, the row components, and the tree derivation are internal (the slot registration closes over them; tests import src paths directly).

View File

@@ -8,6 +8,8 @@ New Session 会启动运行时的页面局部前端 Session Intent真实 Work
`SidebarRootComponentProps` 组合布局 owner share、全局 `useSessions``useWorkspaces` 钩子、已声明的 `sidebar.workspace``sidebar.settings` 子 slot以及注入的 `startSession``open` 和侧边栏切换回调。这里没有插件 store`deriveGroups` 消费对象层快照与组件局部的展开/搜索状态。
栏内的滚动条是一种指针可供性:只要指针不在栏内,外壳就把 ui-theme 的[滚动条间接层](../ui-theme/README.md)重新绑定为 `transparent`;指针离开后滑块再保留 2 秒,因此没人指向的列表不会带着滚动条。避免行位移的空间预留属于滚动区域本身([ui-workspace](../ui-workspace/README.md)),所以显示滑块不会引起重排。
页脚承载 `sidebar.settings`:侧边栏只渲染固定在底部的布局 slot并共享其栏状态`wide`ui-settings 在此注册触发行和设置面板。
`/client` 导出表层只包含插件主体(`apply``inject`及契约类型SidebarRoot、行组件和树派生均属于内部实现slot 注册通过闭包引用它们;测试直接导入 src 路径)。

View File

@@ -25,6 +25,19 @@
padding: 18px 10px 6px;
}
/* Scrollbars in the column are a pointer affordance: the shell adds this
class whenever the pointer is not inside (SidebarRoot.tsx owns the linger),
and rebinding ui-theme's indirection pair to `transparent` takes the thumb
out of every scroll region nested under it — the workspace browser's
session list today. `transparent` rather than `display: none` on the bar:
the reservation (`scrollbar-gutter: stable` on the list) stays in force, so
revealing the thumb never reflows a row. Rebinding contract and the two
rendering paths it reaches: ui-theme's README. */
.root.quietBars {
--dsh-scrollbar-thumb: transparent;
--dsh-scrollbar-thumb-hover: transparent;
}
/* Collapse phase 1: the whole frozen-width content fades out in place over
150ms; at settle the children unmount/snap to the rail layout. */
.fading > * {

View File

@@ -8,6 +8,11 @@
* button and the foot is the `sidebar.workspaces` registrant's, and the foot
* is the `sidebar.settings` registrant's; the shell hands them the wide flag
* (plus an expand request callback for the browser).
*
* The column also owns whether the scroll regions nested in it draw a
* scrollbar at all: the shell tracks the pointer and rebinds ui-theme's
* scrollbar indirection away while it is elsewhere, so a list the user is not
* pointing at carries no bar.
*/
import { useEffect, useRef, useState } from 'react'
import clsx from 'clsx'
@@ -22,6 +27,14 @@ import css from './SidebarRoot.module.css'
/** Wide-content unmount delay; matches the 150ms wide-content fade-out. */
const COLLAPSE_SETTLE_MS = 150
/**
* How long the column's scrollbars stay drawn after the pointer leaves it.
* The bar is a pointer affordance here, and hiding it on the leave event
* itself makes it blink out while the pointer is only crossing the column's
* edge — on the way to the conversation, or around a portalled menu.
*/
const SCROLLBAR_LINGER_MS = 2000
/**
* Render the sidebar column shell.
* @param props - composed slot props (runtime share + injected callbacks, contract/slots.ts).
@@ -56,10 +69,62 @@ export function SidebarRoot({
const everWide = useRef(!collapsed)
if (!collapsed) everWide.current = true
// Scrollbars in the column follow the pointer (.quietBars rebinds them
// away): drawn while it is inside, and for SCROLLBAR_LINGER_MS after it
// leaves. A pointer that returns within that window cancels the pending
// hide rather than restarting from a hidden bar.
const column = useRef<HTMLDivElement>(null)
const [pointerInside, setPointerInside] = useState(false)
const lingerTimer = useRef<number | undefined>(undefined)
const armLinger = (): void => {
if (lingerTimer.current !== undefined) return
lingerTimer.current = window.setTimeout(() => {
lingerTimer.current = undefined
setPointerInside(false)
}, SCROLLBAR_LINGER_MS)
}
const cancelLinger = (): void => {
window.clearTimeout(lingerTimer.current)
lingerTimer.current = undefined
}
// Leaving is decided by the column's BOX, not by DOM containment, and only
// while the bars are drawn. ui-settings renders its full-viewport panel as a
// fixed-position DESCENDANT of this column, so a pointer moved onto that
// panel — or onto the conversation once it closes — fires no `pointerleave`
// here, and the bars would stay drawn over a column nobody is pointing at.
// The element's own leave stays as the one signal geometry cannot give: a
// pointer that leaves the window emits no further moves.
useEffect(() => {
if (!pointerInside) return
const onMove = (event: PointerEvent): void => {
const rect = column.current?.getBoundingClientRect()
/* v8 ignore next -- the listener only exists while the column is mounted and revealed. */
if (rect === undefined) return
const inside = event.clientX >= rect.left && event.clientX < rect.right
&& event.clientY >= rect.top && event.clientY < rect.bottom
if (inside) cancelLinger()
else armLinger()
}
document.addEventListener('pointermove', onMove)
return () => {
document.removeEventListener('pointermove', onMove)
cancelLinger()
}
}, [pointerInside])
return (
<div
className={clsx(css.root, !wide && css.collapsed, !wide && everWide.current && css.railIn, collapsed && wide && css.fading)}
ref={column}
className={clsx(
css.root, !wide && css.collapsed, !wide && everWide.current && css.railIn,
collapsed && wide && css.fading, !pointerInside && css.quietBars,
)}
style={wide ? { width: collapsed ? lastWideWidth.current : width } : undefined}
onPointerEnter={() => {
cancelLinger()
setPointerInside(true)
}}
onPointerLeave={() => { armLinger() }}
>
<div className={css.logoRow}>
{/* Expanded, the wordmark doubles as a New Session shortcut; the

View File

@@ -5,7 +5,7 @@ exports[`sidebar shell snapshots > renders the collapsed rail after the crossfad
data-slot="sidebar"
>
<div
class="root collapsed railIn"
class="root collapsed railIn quietBars"
style=""
>
<div
@@ -65,7 +65,7 @@ exports[`sidebar shell snapshots > renders the expanded column (wordmark, capsul
data-slot="sidebar"
>
<div
class="root"
class="root quietBars"
style="width: 300px;"
>
<div
@@ -135,7 +135,7 @@ exports[`sidebar shell snapshots > renders the expanded column in the default lo
data-slot="sidebar"
>
<div
class="root"
class="root quietBars"
style="width: 300px;"
>
<div

View File

@@ -0,0 +1,157 @@
// @vitest-environment jsdom
/**
* Pointer-revealed scrollbars, the shell's half: which class state the column
* carries as the pointer crosses it. The stylesheet rule that state drives is
* asserted in scrollbar-quiet-styles.spec.ts (node environment — a jsdom spec
* has no file: module URL to read the sheet through).
*/
import { afterEach, describe, expect, it, vi } from 'vitest'
import { act, cleanup, fireEvent, render } from '@testing-library/react'
import type { SidebarRootComponentProps, SidebarSectionOwnerProps } from '../src/client/contract/slots.ts'
import { SidebarRoot } from '../src/client/SidebarRoot.tsx'
import { en } from '../src/client/locales.ts'
/** Pinned column box; the shell compares pointer coordinates against it. */
const COLUMN_WIDTH = 280
const COLUMN_HEIGHT = 600
const t: SidebarRootComponentProps['t'] = key => (en as Record<string, string>)[key] ?? key
/** The shell never reads the global hooks; the props share carries them regardless. */
const neverHook = (() => { throw new Error('shell must not read global hooks') }) as never
afterEach(() => {
cleanup()
vi.useRealTimers()
})
/**
* Render the shell and expose its column element.
* @returns the column element and whether it currently carries the quiet state.
*/
function mountColumn(): { column: HTMLElement; quiet: () => boolean } {
const view = render(
<SidebarRoot
collapsed={false} width={300}
useSessions={neverHook} useWorkspaces={neverHook}
startSession={vi.fn()} toggleSidebar={vi.fn()} t={t}
renderSlot={((_key: string, owner: SidebarSectionOwnerProps) =>
<div data-testid="region" data-wide={owner.wide} />) as SidebarRootComponentProps['renderSlot']}
/>,
)
const column = view.container.firstElementChild
if (!(column instanceof HTMLElement)) throw new Error('sidebar column not rendered')
// jsdom lays nothing out, and the leave decision is geometric: pin the box
// the shell reads so a coordinate can be inside or outside it.
Object.defineProperty(column, 'getBoundingClientRect', {
value: () => ({
left: 0, top: 0, right: COLUMN_WIDTH, bottom: COLUMN_HEIGHT,
x: 0, y: 0, width: COLUMN_WIDTH, height: COLUMN_HEIGHT, toJSON: () => ({}),
}),
})
// CSS-module locals are hashed in this bench, so the state is read as a
// substring of the class list rather than as an exact local name.
return { column, quiet: () => [...column.classList].some(name => name.includes('quietBars')) }
}
/**
* Cross the pointer into or out of the column. React synthesizes
* `pointerenter`/`pointerleave` from `pointerover`/`pointerout`, so the raw
* enter and leave events it does not listen to would assert nothing.
* @param column - the sidebar column element.
* @param direction - `in` to enter the column, `out` to leave it.
*/
function movePointer(column: HTMLElement, direction: 'in' | 'out'): void {
const outside = document.body
if (direction === 'in') fireEvent.pointerOver(column, { relatedTarget: outside })
else fireEvent.pointerOut(column, { relatedTarget: outside })
}
/**
* Move the pointer over the document, as a pointer crossing a fixed overlay
* that is a DOM descendant of the column does.
* @param x - client x coordinate.
* @param y - client y coordinate.
*/
function movePointerOverDocument(x: number, y: number): void {
fireEvent.pointerMove(document, { clientX: x, clientY: y })
}
describe('SidebarRoot pointer-revealed scrollbars', () => {
it('draws them only while the pointer is inside, and lingers on the way out', () => {
vi.useFakeTimers()
const { column, quiet } = mountColumn()
// At rest — the pointer has never been over the column — the bars are off.
expect(quiet()).toBe(true)
movePointer(column, 'in')
expect(quiet()).toBe(false)
movePointer(column, 'out')
// The linger: still drawn just before the window closes, gone just after.
act(() => { vi.advanceTimersByTime(1999) })
expect(quiet()).toBe(false)
act(() => { vi.advanceTimersByTime(1) })
expect(quiet()).toBe(true)
})
it('cancels a pending hide when the pointer comes back', () => {
vi.useFakeTimers()
const { column, quiet } = mountColumn()
movePointer(column, 'in')
movePointer(column, 'out')
act(() => { vi.advanceTimersByTime(1000) })
movePointer(column, 'in')
// The first leave's timer would fire here; a cancelled one leaves the bars
// drawn, which is what keeps a pointer skirting the edge from blinking them.
act(() => { vi.advanceTimersByTime(5000) })
expect(quiet()).toBe(false)
})
it('hides when the pointer moves outside the column box without leaving its subtree', () => {
// ui-settings renders its full-viewport panel as a fixed-position
// DESCENDANT of the column, so DOM containment reports the pointer as
// still inside while it is visually somewhere else entirely.
vi.useFakeTimers()
const { column, quiet } = mountColumn()
movePointer(column, 'in')
expect(quiet()).toBe(false)
movePointerOverDocument(COLUMN_WIDTH + 400, 300)
act(() => { vi.advanceTimersByTime(2000) })
expect(quiet()).toBe(true)
})
it('does not restart the window when the pointer keeps moving outside', () => {
vi.useFakeTimers()
const { column, quiet } = mountColumn()
movePointer(column, 'in')
movePointer(column, 'out')
act(() => { vi.advanceTimersByTime(1500) })
// A pending hide is left alone rather than re-armed: otherwise a pointer
// resting outside the column would keep pushing the bars' disappearance
// out, one move at a time.
movePointerOverDocument(COLUMN_WIDTH + 400, 300)
act(() => { vi.advanceTimersByTime(600) })
expect(quiet()).toBe(true)
})
it('keeps them drawn while the pointer moves inside the column box', () => {
vi.useFakeTimers()
const { column, quiet } = mountColumn()
movePointer(column, 'in')
movePointer(column, 'out')
// A move landing back inside the box cancels the pending hide, the same
// way re-entering the element does.
movePointerOverDocument(COLUMN_WIDTH - 10, 300)
act(() => { vi.advanceTimersByTime(5000) })
expect(quiet()).toBe(false)
})
it('drops the pending hide when the column unmounts', () => {
vi.useFakeTimers()
const { column } = mountColumn()
movePointer(column, 'in')
movePointer(column, 'out')
cleanup()
// A timer surviving the unmount would call setState on a dead component.
expect(() => { vi.advanceTimersByTime(5000) }).not.toThrow()
expect(vi.getTimerCount()).toBe(0)
})
})

View File

@@ -0,0 +1,33 @@
/**
* The quiet-column rule as CSS text: the state SidebarRoot toggles
* (pointer-scrollbars.spec.tsx) hides a scrollbar only through this rule, and
* ui-theme's gate checks the rebinding contract's shape without knowing which
* sheet states which half.
*/
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
const css = readFileSync(fileURLToPath(new URL('../src/client/SidebarRoot.module.css', import.meta.url)), 'utf8')
/** Declarations only: the sheet's prose names the properties it explains. */
const declarationText = css.replace(/\/\*[\s\S]*?\*\//g, ' ')
describe('SidebarRoot.module.css quiet column', () => {
it('rebinds the ui-theme indirection pair to transparent', () => {
// The pair, not the resting thumb alone: rebinding one leaves the other
// painting its base-surface colour the moment the pointer reaches the bar.
const rule = /\.root\.quietBars\s*\{([^{}]*)\}/.exec(declarationText)
expect(rule).not.toBeNull()
const declarations = (rule![1] ?? '').split(';').map(part => part.trim()).filter(Boolean).sort()
expect(declarations).toEqual([
'--dsh-scrollbar-thumb-hover: transparent',
'--dsh-scrollbar-thumb: transparent',
].sort())
})
it('leaves the gutter reservation to the scrolling region', () => {
// Hiding the thumb must not move a row: the reservation lives on the list
// (ui-workspace), so the column states colour only.
expect(declarationText).not.toMatch(/scrollbar-gutter/)
})
})

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/ui-theme/README.md
README.md: a1ff7d840dae86f5da98de1208ecda3b8b62026b
README.zh.md: 2e034f3173baabb3eea6b4ae670d5070c95480be
README.md: 88e21fe214ec806b101050949690283d811be36d
README.zh.md: 4ed45070234acb78a2e5edef52578b504ae53077

View File

@@ -6,7 +6,7 @@ Theme plugin: ThemeService over the --dsw-* token base stylesheets (static scale
`src/styles/` holds five sheets, all imported by the web shell's `base.css`: `base.css`, `design-platform.css`, `scrollbar.css`, `gradient-shadow-text.css`, and `shiki.css`. `scrollbar.css` is the sole consumer of the `--dsw-alias-scrollbar-*` tokens and must follow `design-platform.css`, which declares them.
Scrollbar rebinding contract: `scrollbar.css` binds `--dsh-scrollbar-thumb` and `--dsh-scrollbar-thumb-hover` on `body` to the l1 (base-surface) tokens, and both rendering paths read that pair. An elevated surface (menu, popover, dialog) sets `--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2)` and `--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2)` on its own container; one rebind retints whichever path the engine took.
Scrollbar rebinding contract: `scrollbar.css` binds `--dsh-scrollbar-thumb` and `--dsh-scrollbar-thumb-hover` on `body` to the l1 (base-surface) tokens, and both rendering paths read that pair. An elevated surface (menu, popover, dialog) sets `--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2)` and `--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2)` on its own container; one rebind retints whichever path the engine took. The pair's other legal target is `transparent`, which draws no thumb at all — [ui-sidebar](../ui-sidebar/README.md) rebinds its column that way while the pointer is elsewhere. A rebind to the l1 pair is not a rebind; it restates the base-surface default.
The two paths are mutually exclusive by construction. `scrollbar-width`/`scrollbar-color` sit inside `@supports not selector(::-webkit-scrollbar)` because a non-`auto` value of either makes Chromium and Safari discard every `::-webkit-scrollbar*` rule for that element, `::-webkit-scrollbar-thumb:hover` included — declaring both unconditionally leaves `--dsh-scrollbar-thumb-hover` with no rendering anywhere. Firefox therefore takes the standard properties and WebKit-based engines take the pseudo-elements, so the hover token only ever renders through the pseudo-element path. Reasoning and the measured computed values: [the scrollbar Agent Note](../../../.agents/notes/implemented/bug-fix/2026-07-28-themed-scrollbars-and-reserved-gutter.md).

View File

@@ -6,7 +6,7 @@
`src/styles/` 下有五张样式表,全部由 web 壳的 `base.css` 导入:`base.css``design-platform.css``scrollbar.css``gradient-shadow-text.css``shiki.css``scrollbar.css``--dsw-alias-scrollbar-*` token 的唯一消费方,必须排在声明这些 token 的 `design-platform.css` 之后。
滚动条重新绑定契约:`scrollbar.css``body` 上把 `--dsh-scrollbar-thumb``--dsh-scrollbar-thumb-hover` 绑定到 l1基础表面token两条渲染路径都读取这一组变量。高层级表面菜单、浮层、对话框在自己的容器上设置 `--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2)``--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2)`;一次重新绑定即可为引擎实际走的那条路径换色。
滚动条重新绑定契约:`scrollbar.css``body` 上把 `--dsh-scrollbar-thumb``--dsh-scrollbar-thumb-hover` 绑定到 l1基础表面token两条渲染路径都读取这一组变量。高层级表面菜单、浮层、对话框在自己的容器上设置 `--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2)``--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2)`;一次重新绑定即可为引擎实际走的那条路径换色。这组变量另一个合法的目标是 `transparent`,即完全不绘制滑块——[ui-sidebar](../ui-sidebar/README.md) 在指针不在栏内时就这样重新绑定自己的列。绑回 l1 那组不算重新绑定,它只是重述基础表面的默认值。
两条路径在构造上互斥。`scrollbar-width``scrollbar-color` 写在 `@supports not selector(::-webkit-scrollbar)` 之内,因为这两个属性中的任一个只要取非 `auto`Chromium 与 Safari 就会丢弃该元素上的全部 `::-webkit-scrollbar*` 规则,`::-webkit-scrollbar-thumb:hover` 也在其中——若无条件地同时声明,`--dsh-scrollbar-thumb-hover` 在任何引擎上都不会被渲染。因此 Firefox 走标准属性WebKit 系引擎走伪元素hover token 只经由伪元素这条路径渲染。推理过程与实测计算值见[滚动条 Agent Noteagent 决策记录)](../../../.agents/notes/implemented/bug-fix/2026-07-28-themed-scrollbars-and-reserved-gutter.md)。

View File

@@ -31,6 +31,13 @@ const DARK_ATTRIBUTE = '[data-ds-dark-theme]'
const TOKEN_PREFIX = '--dsw-alias-scrollbar-'
/** Prefix of the rebindable indirection scrollbar.css owns. */
const INDIRECTION_PREFIX = '--dsh-scrollbar-'
/** The one non-token rebind value: a surface that draws no thumb at all. */
const HIDDEN_THUMB = 'transparent'
/** The elevation rebind, spelled per property: value-wholeness, not token shape. */
const ELEVATED_REBIND = new Map([
['--dsh-scrollbar-thumb', '--dsw-alias-scrollbar-bg-l2'],
['--dsh-scrollbar-thumb-hover', '--dsw-alias-scrollbar-hover-l2'],
].map(([property, token]) => [property!, `var(${token!})`]))
/**
* Flatten a stylesheet into rules. Whitespace, declaration order, and trailing
@@ -179,8 +186,13 @@ interface SheetSurfaces {
elevated: Set<string>
/** True when some rule declares `overflow*: auto|scroll`. */
scrolls: boolean
/** True when some rule rebinds the indirection. */
rebinds: boolean
/**
* True when some rule rebinds the indirection to an ELEVATION. A rule that
* only hides the bar (`transparent`) does not count: it states no elevation,
* so a sheet that hides its bars and also scrolls on an elevated surface
* still owes the l2 pair for whatever draws a thumb there.
*/
rebindsElevation: boolean
}
const sheetSurfaces = new Map<string, SheetSurfaces>()
@@ -238,12 +250,16 @@ const elevatedSurfaces = elevatedRungs()
for (const file of packageStylesheets()) {
const rules = parseRules(readFileSync(file, 'utf8'))
const surfaces: SheetSurfaces = { elevated: new Set(), scrolls: false, rebinds: false }
const surfaces: SheetSurfaces = { elevated: new Set(), scrolls: false, rebindsElevation: false }
for (const rule of rules) {
let rebinds = false
let rebindsElevation = false
const ruleSurfaces: string[] = []
for (const [property, value] of rule.declarations) {
if (property.startsWith(INDIRECTION_PREFIX) && file !== fileURLToPath(new URL('scrollbar.css', STYLES))) rebinds = true
if (property.startsWith(INDIRECTION_PREFIX) && file !== fileURLToPath(new URL('scrollbar.css', STYLES))) {
rebinds = true
if (value !== HIDDEN_THUMB) rebindsElevation = true
}
if (OVERFLOW_PROPERTIES.includes(property) && /\b(?:auto|scroll)\b/.test(value)) surfaces.scrolls = true
if (SURFACE_PROPERTIES.includes(property)) ruleSurfaces.push(...varReferences(value))
for (const token of varReferences(value)) {
@@ -254,10 +270,8 @@ for (const file of packageStylesheets()) {
for (const token of ruleSurfaces) {
if (elevatedSurfaces.has(token)) surfaces.elevated.add(token)
}
if (rebinds) {
rebindRules.push({ file, rule })
surfaces.rebinds = true
}
if (rebinds) rebindRules.push({ file, rule })
if (rebindsElevation) surfaces.rebindsElevation = true
}
sheetSurfaces.set(file, surfaces)
}
@@ -452,13 +466,25 @@ describe('elevated surface rebinds', () => {
}
})
it('every rebind targets the l2 elevation pair', () => {
it('rebinds the pair to one target: the l2 elevation pair, or transparent', () => {
// The rule as a whole, not each declaration on its own. Per-declaration
// checking accepts a MIXED rule — `thumb: transparent` beside
// `thumb-hover: var(--dsw-alias-scrollbar-hover-l2)` — which repaints the
// bar the moment the pointer reaches it while passing a gate that claims
// the two targets are exclusive.
//
// The elevation half compares the whole value against the pair's canonical
// spelling rather than checking that every token it mentions ends in `-l2`.
// A shape check admits `color-mix(…, var(--dsw-alias-scrollbar-bg-l2) 85%,
// white)` and a crossed pair (the hover token bound to the resting
// property); neither is what the contract says.
for (const { file, rule } of rebindRules) {
for (const [property, value] of rule.declarations) {
if (!property.startsWith(INDIRECTION_PREFIX)) continue
for (const token of varReferences(value)) {
expect(token, `${file}: ${property}`).toMatch(/-l2$/)
}
const rebinds = rule.declarations.filter(([property]) => property.startsWith(INDIRECTION_PREFIX))
const where = `${file} ${rule.selectors.join(', ')}`
if (rebinds.every(([, value]) => value === HIDDEN_THUMB)) continue
expect(rebinds.some(([, value]) => value === HIDDEN_THUMB), `${where}: mixes ${HIDDEN_THUMB} with an elevation`).toBe(false)
for (const [property, value] of rebinds) {
expect(value, `${where}: ${property}`).toBe(ELEVATED_REBIND.get(property))
}
}
})
@@ -499,7 +525,7 @@ describe('elevated surface rebinds', () => {
// (ChatView's `.toBottom`, CodeBlock's banner). Geometry cannot make that
// call — a floating button carries a radius, a shadow, and a fixed size.
for (const [file, surfaces] of sheetSurfaces) {
if (!surfaces.scrolls || surfaces.rebinds) continue
if (!surfaces.scrolls || surfaces.rebindsElevation) continue
expect([...surfaces.elevated], `${file} scrolls on an elevated surface without rebinding`).toEqual([])
}
})