From df826f575e99ac5cd514555a97b7d8936ffcd989 Mon Sep 17 00:00:00 2001 From: OddTurtleHead <355182507+OddTurtleHead@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:16:24 +0800 Subject: [PATCH] feat(skin): match Classic toolbar icon buttons for host recovery Add slot appearance "icon" and "icon-and-label", allow an explicit 22px toolbar height, preserve transparent backgrounds, and introduce hover, surface, gap, and icon-size tokens so host-owned recovery and library buttons can match the Classic microphone control. Shortcut and failed- anchor fallbacks stay full label capsules. Update the example skin, docs, and tests, including a Classic toolbar fixture. --- docs/SKIN_DEVELOPMENT.md | 53 +++++- docs/examples/HOST-CHROME-TOOLBAR.md | 71 ++++++- docs/examples/host-chrome-toolbar.wskin | Bin 1774 -> 1538 bytes docs/examples/host-chrome-toolbar/chrome.json | 1 + .../host-chrome-toolbar/manifest.json | 4 +- docs/examples/host-chrome-toolbar/skin.css | 114 +++++------ src/shared/skin-chrome.ts | 20 +- src/shared/skin-css.test.ts | 12 +- web/public/host-chrome-toolbar.wskin | Bin 1774 -> 1538 bytes web/src/components/HostChrome.vue | 75 +++++++- .../services/host-chrome-visibility.test.ts | 1 + web/src/services/host-control-tokens.test.ts | 139 ++++++++++++-- web/src/services/host-control-tokens.ts | 177 +++++++++++++++--- web/src/services/host-slot-placement.ts | 58 ++++-- .../fixtures/host-recovery-legacy-slot.html | 5 + .../host-recovery-toolbar-classic.html | 150 +++++++++++++++ web/test/fixtures/host-recovery-toolbar.html | 2 +- web/test/host-chrome-recovery.test.mjs | 83 +++++++- 18 files changed, 805 insertions(+), 160 deletions(-) create mode 100644 web/test/fixtures/host-recovery-toolbar-classic.html diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index c423457..60299ce 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -486,6 +486,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 | `align` | 可选,`start`、`center` 或 `end`,默认 `end`;控件在锚点矩形内按此水平对齐,并垂直居中。 | | `compact` | 可选布尔值;为 `true` 时停靠后的胶囊折叠为 ◈ 标记,悬停或聚焦后展开。仅胶囊模式可用;`mode: "toolbar"` 与 `compact: true` 同时出现会被拒绝。 | | `mode` | 可选,`"capsule"` 或 `"toolbar"`。`host.recovery` 省略时保持历史默认 `"capsule"`(旧皮肤无需改动);`host.recovery.built-in` / `host.recovery.library` 省略时为 `"toolbar"`,且显式写 `"capsule"` 会被拒绝。模式必须显式声明,宿主不会从 `compact` 或其他字段推断。 | +| `appearance` | 可选,`"label"`(默认)、`"icon"` 或 `"icon-and-label"`,只接受 toolbar 模式。`label` 保持旧文字按钮;`icon` 使用宿主 16px 图标、24px 宽按钮和零内边距;`icon-and-label` 同时显示图标和本地化文字。三种形态都保留 `aria-label` / `title`。胶囊只接受 `label`;未知值或胶囊中的图标形态会以 `SKIN_CHROME_SLOT_INVALID` 拒绝。 | `anchor` 写的是宿主渲染后的完整部件名,而不是组件 id: @@ -517,7 +518,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 #### 工具栏模式:把恢复按钮并进皮肤顶栏(`mode: "toolbar"`) -默认的恢复入口是带胶囊壳的浮动/停靠胶囊。若皮肤顶栏已有自己的按钮风格,可以在 `chrome.json` 中显式声明 `mode: "toolbar"`,让宿主在锚点位置绘制**无胶囊壳的真实宿主按钮**。按钮仍由宿主创建、标注、聚焦和点击,位于闭合 Shadow DOM 的顶层;皮肤只提供锚点和 `--skin-recovery-toolbar-*` 令牌,不能替换文字、图标、顺序、点击处理或取得 DOM。`.ws-host-toolbar`、`data-ws-host-recovery-toolbar` 与 `data-ws-recovery-action` 都不是公开钩子,皮肤选择器引用它们会被拒绝。 +默认的恢复入口是带胶囊壳的浮动/停靠胶囊。若皮肤顶栏已有自己的按钮风格,可以在 `chrome.json` 中显式声明 `mode: "toolbar"`,让宿主在锚点位置绘制**无胶囊壳的真实宿主按钮**。按钮仍由宿主创建、标注、聚焦和点击,位于闭合 Shadow DOM 的顶层;皮肤只提供锚点、`appearance` 形态声明和 `--skin-recovery-toolbar-*` 令牌,不能替换宿主图标、文案、顺序、点击处理或取得 DOM。`.ws-host-toolbar`、`data-ws-host-recovery-toolbar` 与 `data-ws-recovery-action` 都不是公开钩子,皮肤选择器引用它们会被拒绝。 两种声明方式互斥,同一份 `chrome.json` 只能选一种: @@ -527,6 +528,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 "slots": { "host.recovery": { "mode": "toolbar", + "appearance": "icon", "anchor": ["home.header", "voice.header"], "align": "end" } @@ -538,10 +540,14 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 ```json "slots": { "host.recovery.built-in": { + "mode": "toolbar", + "appearance": "icon-and-label", "anchor": ["home.header-tools", "voice.header-actions"], "align": "end" }, "host.recovery.library": { + "mode": "toolbar", + "appearance": "icon", "anchor": ["home.header-tools", "voice.header-actions"], "align": "start" } @@ -553,13 +559,14 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 规则: - `mode` 省略时,`host.recovery` 仍是 `capsule`,旧皮肤行为不变;独立按钮键省略时是 `toolbar`,显式写 `capsule` 会被拒绝。模式必须显式声明,宿主不会从 `compact` 或其他字段推断。 -- `compact` 只适用于胶囊;toolbar 配 `compact` 会被拒绝。toolbar 永远显示完整文字按钮,不会折叠成 ◈。 +- `compact` 只适用于胶囊;toolbar 配 `compact` 会被拒绝。toolbar 不会折叠成 ◈;`appearance` 省略时仍显示完整文字按钮。 +- `appearance: "icon"` 只改变 toolbar 的可见内容,不移除按钮的可访问名称。宿主图标为内联 SVG,`aria-hidden="true"`;按钮保留当前语言的 `aria-label`,`title` 仍说明动作/快捷键。`icon-and-label` 同时显示图标和文字。快捷键与失败回退始终使用完整文字胶囊,不受 toolbar 外观影响。 - 组合式下「应用库」按钮只在应用库可用(已连接且插件会话就绪)时渲染;「使用内置皮肤」始终渲染。 - 独立式下每个动作独立停靠:一个锚点失效只把该动作放回浮动胶囊,另一个仍留在工具栏;两个都失效时显示完整浮动胶囊。toolbar 模式下的胶囊永不折叠,因为它是兜底入口而不是设计目标。 - 回退、抗抖动和复查节奏与胶囊相同:锚点失效立即回退;恢复后需连续 2 次检查通过才重新停靠;停靠时约 400 ms 复查,浮动时约 1 s。 - 锚点候选数组按顺序取第一个可见项;页面切换、皮肤重载或锚点显隐后会重新解析,不要求重新绑定。 - 快捷键 `Ctrl+Alt+Shift+R` / `⌘+⌥+⇧+R` 会隐藏工具栏并召唤完整胶囊;关闭(Escape 或焦点离开)后,锚点仍有效的 toolbar 自动恢复。快捷键仍在捕获阶段处理。 -- 按钮的最小命中高度、可见文字、焦点环和指针/键盘操作都由宿主保证;皮肤不能把 toolbar 变成图标按钮、空白按钮或零尺寸按钮。 +- 按钮的最小命中高度、可见图标/文字、焦点环和指针/键盘操作都由宿主保证;皮肤不能通过选择器隐藏 toolbar、移除可访问名称或把按钮变成零尺寸。`appearance` 只能选择宿主提供的三种形态。 **应用库去重**:只要皮肤声明了 toolbar 形式的恢复入口(组合式的 `host.recovery`,或独立式的 `host.recovery.library`),并且应用库可用,宿主就把工具栏里的「应用库」按钮当作该页唯一的应用库入口,并隐藏普通的 `host.plugins.launcher`。即使锚点失效、入口退回浮动胶囊,启动器仍保持隐藏(胶囊继续提供应用库按钮),避免同一页出现两个入口;应用库不可用时启动器照常显示,工具栏也不渲染该按钮。这个去重只影响 toolbar 声明,不改变普通胶囊皮肤或内置皮肤。 @@ -567,17 +574,43 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 | 令牌 | 默认与规则 | | --- | --- | -| `--skin-recovery-toolbar-background` | 按钮背景。省略时沿用已解析的胶囊底色(`--skin-recovery-background` / `--skin-host-background` / 宿主白色)。alpha 视为 1,宿主强制不透明。 | -| `--skin-recovery-toolbar-foreground` | 文字色。与背景的对比度必须 ≥ 4.5;整组颜色不可读时,背景和文字一起回退到已解析的胶囊配色,而不是只改一项。 | -| `--skin-recovery-toolbar-border` | 边框色。与背景的对比度必须 ≥ 3,否则使用已解析的胶囊边框。 | +| `--skin-recovery-toolbar-background` | 按钮背景。省略时沿用已解析的胶囊底色(`--skin-recovery-background` / `--skin-host-background` / 宿主白色)。完全透明(`transparent` 或 alpha 0)会保留;非零 alpha 仍按旧规则转为不透明 RGB。 | +| `--skin-recovery-toolbar-foreground` | 图标/文字色。与不透明按钮背景的对比度必须 ≥ 4.5;背景透明时改与 `surface` 令牌或宿主采样的锚点/祖先不透明底色比较。整组颜色不可读时,背景和文字一起回退到已解析的胶囊配色。 | +| `--skin-recovery-toolbar-border` | 边框色。完全不透明时与有效背景的对比度必须 ≥ 3,否则使用已解析的胶囊边框;完全透明边框有效。 | +| `--skin-recovery-toolbar-hover-background` | 悬停背景,默认使用正常背景;宿主独立检查悬停后的文字对比度,不合格时回退到正常背景。 | +| `--skin-recovery-toolbar-hover-border` | 悬停边框,默认使用正常边框;校验颜色语法,允许 Classic 的 subtle `#b8cfe8` 边缘,不强制 3:1。 | +| `--skin-recovery-toolbar-surface` | 可选的完全不透明底色,仅用于透明按钮/悬停背景的文字对比度检查,不绘制按钮本身。优先级为 per-part、global、锚点/祖先计算背景采样、宿主白色。渐变或图片顶栏应显式提供该令牌。 | | `--skin-recovery-toolbar-radius` | 圆角,px 长度,限制 0–24,默认 6;胶囊的 999px 不会带入 toolbar。 | | `--skin-recovery-toolbar-font` | 字体族列表,规则与胶囊相同:只接受已安装字体或通用族名,皮肤 `@font-face`(包括 `ws-` 前缀)整项忽略。 | | `--skin-recovery-toolbar-font-size` | 字号,px,默认沿用当前尺寸档位的宿主字号(≥ 11/12/13 px),限制 11–20 px;不能低于宿主下限。 | -| `--skin-recovery-toolbar-padding` | 一个或两个 px 值(`上下 左右`,或一个值表示四边相同),默认 `6px 12px`,每个方向限制 0–48 px。 | -| `--skin-recovery-toolbar-height` | 最小高度,px,默认当前尺寸档位的最小命中高度(28/32/36 px),限制不低于该值且不超过 72 px。 | +| `--skin-recovery-toolbar-padding` | 一个或两个长度值(`上下 左右`,或一个值表示四边相同),默认 `6px 12px`,每个方向限制 0–48 px;接受 px 和无单位 `0`。`appearance: "icon"` 时宿主强制零内边距。 | +| `--skin-recovery-toolbar-height` | 最小高度,px。省略时保持当前尺寸档位的 28/32/36 px;显式值限制 22–72 px,因此 Classic 22px 仅在 toolbar 生效。胶囊仍保持 28/32/36 px。 | | `--skin-recovery-toolbar-shadow` | `none` 或单个简单 `box-shadow`(2–4 个 px 偏移/尺寸加一个颜色,最长 160 字符),默认 `none`。`url()`、`var()`、多个阴影和额外声明一律忽略为 `none`,胶囊阴影不会带入。 | +| `--skin-recovery-toolbar-gap` | 组合式两个宿主按钮之间的间距,px,默认 4,限制 0–16;Classic 可设 `1px`。独立式各自只有一个按钮。 | +| `--skin-recovery-toolbar-icon-size` | 宿主图标边长,px,默认 16,限制 12–24。`appearance: "icon"` 时按钮宽度为 `max(24px, icon-size + 8px)`,16px 图标对应 Classic 24px 按钮。 | -无效、透明或不可读的颜色、越界的字号/高度/内边距、皮肤字体和非法阴影都只会回退到可见的宿主默认值,不会隐藏按钮。toolbar 文字由宿主按当前界面语言本地化,长文本换行而不是裁掉;`prefers-reduced-motion` 下同样没有过渡。 +无效、不可读的颜色,越界的字号/高度/内边距/间距/图标尺寸,皮肤字体和非法阴影都只会回退到可见的宿主默认值,不会隐藏按钮。toolbar 文案由宿主按当前界面语言本地化,长文本换行而不是裁掉;`prefers-reduced-motion` 下同样没有过渡。 + +**Classic 麦克风按钮对齐示例**(22px 高、透明底、1px 边框、2px 圆角、11px 字号、16px 图标、1px 组间距): + +```css +:root { + --skin-host-toolbar-background: transparent; + --skin-host-toolbar-foreground: #1a1a1a; + --skin-host-toolbar-border: transparent; + --skin-host-toolbar-hover-background: #eaf2fd; + --skin-host-toolbar-hover-border: #b8cfe8; + --skin-host-toolbar-radius: 2px; + --skin-host-toolbar-font-size: 11px; + --skin-host-toolbar-padding: 0 4px; + --skin-host-toolbar-height: 22px; + --skin-host-toolbar-gap: 1px; + --skin-host-toolbar-icon-size: 16px; + --skin-host-toolbar-surface: #ffffff; +} +``` + +配合 `"appearance": "icon"` 使用。`surface` 只参与可读性计算;顶栏实际不是白色时应改成真实不透明底色。图标按钮的零内边距由宿主强制执行,`padding` 令牌仍用于 `label` / `icon-and-label`。 **旧 slots 兼容**:旧包里的 `{ "anchor": ..., "align": ..., "compact": ... }` 没有 `mode`,仍按胶囊停靠,行为不变;`chrome.json` 的其它字段(`visibleParts`、`hiddenParts`、`icons`)不受影响。只有显式写 `mode: "toolbar"` 才会切换形态。 @@ -699,7 +732,7 @@ v3/v4 清单可增加可选字段 `"chrome": "chrome.json"`,文件位于包根 | `visibleParts` | 可选,最多 32 项,只能是本文档「可隐藏的装饰部件」白名单中的宿主装饰名。`host.watermark`、`host.hint`、`host.voice-status-decoration` 默认隐藏;皮肤需在这里明确列出才会渲染。省略该字段时装饰保持隐藏,即使包内已有 `hiddenParts` 或 `icons`(宿主不再根据生成的 CSS 猜测旧包意图)。内置皮肤没有 `chrome.json`,因此始终不显示这些装饰。实例级 `hiddenParts` 与皮肤 `hiddenParts` 仍然优先。 | | `hiddenParts` | 最多 32 项,只能是本文档「可隐藏的装饰部件」白名单中的名字;编译成 `display:none` 并写入皮肤 CSS。可信控件、恢复入口与必要音频路径(如 `voice.audio-dock`、`voice.connection-status`、`home.footer.clear`)永不允许出现,皮肤 CSS 直接隐藏它们也会被拒绝。 | | `icons` | 最多 16 项;键必须是上表的图标槽名;值必须是包内 `assets/icons/<文件名>` 的位图相对路径。 | -| `slots` | 可选,最多 8 项;键名只能是 `host.recovery`(整组)或 `host.recovery.built-in` / `host.recovery.library`(独立 toolbar 按钮),两种写法互斥。值只能包含 `anchor`、`align`、`compact`、`mode`;`anchor` 可以是单个部件名或最多 8 个候选名的数组。详见上文「将恢复入口停靠到皮肤布局」与「工具栏模式」。未知键、指向 `host.*` 或可信宿主部件的锚点、`toolbar` 配 `compact` 都会被拒绝。 | +| `slots` | 可选,最多 8 项;键名只能是 `host.recovery`(整组)或 `host.recovery.built-in` / `host.recovery.library`(独立 toolbar 按钮),两种写法互斥。值只能包含 `anchor`、`align`、`compact`、`mode`、`appearance`;`anchor` 可以是单个部件名或最多 8 个候选名的数组。详见上文「将恢复入口停靠到皮肤布局」与「工具栏模式」。未知键、指向 `host.*` 或可信宿主部件的锚点、`toolbar` 配 `compact`、非法 `appearance` 或胶囊中的图标形态都会被拒绝。 | 工具栏形态只需在 `host.recovery` 上写 `"mode": "toolbar"`(两个按钮共用一个锚点): diff --git a/docs/examples/HOST-CHROME-TOOLBAR.md b/docs/examples/HOST-CHROME-TOOLBAR.md index c1511ea..5e080c4 100644 --- a/docs/examples/HOST-CHROME-TOOLBAR.md +++ b/docs/examples/HOST-CHROME-TOOLBAR.md @@ -1,9 +1,10 @@ # Host chrome toolbar example -A minimal schema v3 open skin that docks the trusted recovery entry into the page header as host-owned buttons instead of the floating capsule shell. It is the smallest reference for `chrome.json` `mode: "toolbar"`, page-specific anchor candidates, toolbar style tokens, application-library de-duplication and the floating-capsule fallback. +A minimal schema v3 open skin that docks the trusted recovery entry into the page header as Classic-aligned, host-owned icon buttons instead of the floating capsule shell. It is the smallest reference for `chrome.json` `mode: "toolbar"`, `appearance`, page-specific anchor candidates, transparent toolbar tokens, application-library de-duplication and the floating-capsule fallback. - Source: [host-chrome-toolbar](./host-chrome-toolbar/) - Importable package: [host-chrome-toolbar.wskin](./host-chrome-toolbar.wskin) +- Author: WebSpeak Community - Shared component and permission rules: [skin development guide](../SKIN_DEVELOPMENT.md) - Host chrome and toolbar contract: [skin development guide](../SKIN_DEVELOPMENT.md) (see the `chrome.json#slots` and toolbar-mode sections) @@ -11,14 +12,14 @@ A minimal schema v3 open skin that docks the trusted recovery entry into the pag ```text host-chrome-toolbar/ - manifest.json # schema v3, author WebSpeak Community + manifest.json # schema v3, version 1.1.0, author WebSpeak Community chrome.json # one grouped toolbar slot with a home/voice anchor list - skin.css # page theme, toolbar tokens and header space reservation + skin.css # light page theme, Classic toolbar tokens and header space ``` `skin.css` uses only public `data-ws-part` hooks and sets `--skin-host-toolbar-*` / `--skin-recovery-toolbar-*` variables. It never targets the host toolbar DOM, the recovery capsule, the authorization dialog or the load-failure banner. -## What the declaration does +## Grouped declaration ```json { @@ -26,6 +27,7 @@ host-chrome-toolbar/ "slots": { "host.recovery": { "mode": "toolbar", + "appearance": "icon", "anchor": ["home.header", "voice.header"], "align": "end" } @@ -33,19 +35,70 @@ host-chrome-toolbar/ } ``` -- `mode: "toolbar"` asks the host to render two plain host buttons (use built-in skin, application library) without the capsule shell. +- `mode: "toolbar"` asks the host to render two real host buttons without the capsule shell. +- `appearance: "icon"` selects the host-owned 16px built-in-skin and application-library SVGs. Each button is 24px wide, has zero padding and keeps its localized `aria-label` and `title`. - The anchor list covers both pages; the host picks the first visible one and re-resolves it after a page switch. A missing or hidden anchor returns the complete, visible floating capsule. - While the library is available, the host hides the ordinary application-library launcher so the page keeps exactly one library entry. The fallback capsule keeps that entry when the anchor fails. -- The host owns the labels, click handlers, focus behaviour, minimum hit target and shortcut handling. The skin only supplies anchor and token values. +- The host owns the icons, labels, click handlers, focus behaviour, shortcut handling and fallback. The skin only supplies the anchor, appearance and token values. - Old slots without `mode` keep the capsule presentation; this example opts in explicitly. +## Classic tokens + +```css +:root { + --skin-host-toolbar-background: transparent; + --skin-host-toolbar-foreground: #1a1a1a; + --skin-host-toolbar-border: transparent; + --skin-host-toolbar-hover-background: #eaf2fd; + --skin-host-toolbar-hover-border: #b8cfe8; + --skin-host-toolbar-surface: #f4f7fb; + --skin-host-toolbar-radius: 2px; + --skin-host-toolbar-font-size: 11px; + --skin-host-toolbar-padding: 0 4px; + --skin-host-toolbar-height: 22px; + --skin-host-toolbar-gap: 1px; + --skin-host-toolbar-icon-size: 16px; +} +``` + +This produces 22px-high buttons, a transparent normal surface, a 1px transparent border, 2px corners, 11px type, 16px icons and a 1px gap. Hover uses `#eaf2fd` with a `#b8cfe8` edge. `surface` is not painted; it tells the host which opaque colour to use for contrast checks. Set it to the real header colour when adapting the example. + +The package also declares an opaque `--skin-recovery-*` capsule palette. Capsule mode keeps its historical 28/32/36px size floors, full text labels and fixed `#fff7ed` built-in action; toolbar tokens never shrink or restyle that escape hatch. + +## Independent declaration + +Use the per-action keys when the two actions need different anchors or appearances. Do not declare them together with `host.recovery`. + +```json +{ + "schemaVersion": 1, + "slots": { + "host.recovery.built-in": { + "mode": "toolbar", + "appearance": "icon-and-label", + "anchor": ["home.header-tools", "voice.header-actions"], + "align": "end" + }, + "host.recovery.library": { + "mode": "toolbar", + "appearance": "icon", + "anchor": ["home.header-tools", "voice.header-actions"], + "align": "start" + } + } +} +``` + +`appearance` defaults to `"label"` for backward compatibility. The accepted toolbar values are `"label"`, `"icon"` and `"icon-and-label"`; unknown values and icon appearances in capsule mode are rejected with `SKIN_CHROME_SLOT_INVALID`. + ## Trying it 1. Build or import [host-chrome-toolbar.wskin](./host-chrome-toolbar.wskin) in a local WebSpeak instance. 2. Allow the third-party skin when the host asks. 3. Connect to **Demo Server**, join **Demo Lobby**, and check the header as **Demo User**. -4. Confirm the two host buttons appear at the end of the home and voice headers, use the dark toolbar palette, and open the built-in-skin and application-library actions. -5. Remove or hide the anchor in the page inspector; the complete floating capsule should appear at a corner. Restore the anchor; the toolbar should re-dock after the anti-flap check. -6. Press `Ctrl+Alt+Shift+R` (`⌘+⌥+⇧+R` on macOS); the toolbar hides, the complete capsule appears and focuses its first button. Press Escape to return to the toolbar. +4. Confirm the two 24px host icons appear at the end of the home and voice headers, remain transparent at rest, use the Classic hover colours, and open the built-in-skin and application-library actions. +5. Remove or hide the anchor in the page inspector; the complete floating capsule should appear at a free corner. Restore the anchor; the toolbar should re-dock after the anti-flap check. +6. Press `Ctrl+Alt+Shift+R` (`⌘+⌥+⇧+R` on macOS); the toolbar hides, the complete full-text capsule appears and focuses its first button. Press Escape to return to the toolbar. +7. Check a narrow viewport and all five interface languages. Icon-only names must remain available to assistive technology, and the fallback capsule must keep readable localized labels. The example contains no server addresses, member names, chat contents or other real instance data. Public descriptions use only the Demo Server / Demo Lobby / Demo User placeholders. diff --git a/docs/examples/host-chrome-toolbar.wskin b/docs/examples/host-chrome-toolbar.wskin index 64094c1f4bd16c758ea680bbda264762e4f5d098..2713053979485be236e340bf3f4a7cd1dbecb217 100644 GIT binary patch literal 1538 zcmWIWW@Zs#U|`^2P-w}IovM_e_6NwD#>l|H3#4-s^D@&?i%ayfiu3b)0}lEfHsIO& zUVF`)%qpFi{N|Gvc_@s*kFdzYu@ zjXRFj!53cqdEr+vLs@Ue#Ev^JJaS%5`^8kn`S8q?bnA|1$M`*&%py~)c5M;5*;@5~ zgTR8-EEX}scK>S5o_qJE%=NA%|0J#-ZO5l~tKO%C6MU{1m$OQK33&riVN+t)Z-rv#b*JFD{=Tqddmbhu`=?eO59Ok6% zbm{OmHdyf5@a9zk%jG*GL`z?XhF7dzQWmQId);aGQqhj@hX1bTZQHhWd)nu{KN$m1 zf{E?chv)Uc;5iJ$+(4Y1QIwyX3JxUKK0_{GAh~{@b0|Zvahr2_LAFk0MRe$s0ne2owIkD`!U93L;)>`sIc0Z#yzi`>?+Lx!% z+{v=+Se!3214BF~D1sRninBBG^pcBk!h{m$b?z zf$zxT_QyfLxleEodZiyZSFuRy^^nYB() zhlIr6-GB08Z|H_CrwV5lI(kO6Dm*#o`Ao3o@QtLLg+-Tc9+i5@$`Lp*OYft*>%`s5 zE}n9HnyrCcmbbXjr)C?x%y^dHCpp2APcm82KP7!mum1P# z@f!QYW8N|cKPaD_`QY>Jha7uMW>yqkdt*Jj;&*U^kJ{hxDJ!<>J~Ng$>{%b?7Wl5I zl>dh1w4%^@o4h>k7hCMlrmv_pZFX|GbILlZ`C!bWMMpGJ^tok1RJ)E`3a{MKr5d%d z*X?*|-^x!motxgC+GslU-5=k-+gmdyZ;Nl*el@Ca&y|;%R(tiIo_lxCH`BCG?B`BN zo_(E)iJLwdEwh|^|5gCIm%s8>1|GfKy4wA1ZSsqvE6f=8J&N9Bz3Ell`$Ml6PFb+H zCqPPeUVqu*={Z+(cO1Lry6t9LoAyE0Qy@9aWr*^@#? zl%{=mNqy|2-L|r0*S~WO$M|hm#Q4bHXt=VCwaeISf_c0`pziU0-vyyDGPe zLpM?JH^+UfVL?^H?9-=I&dzwk_<} z*-ys2%5*1x5dbxto mrw%NTkxChKjp!L2q47LWBP`noc(byBWSD_)6_9pf1@Qnxn4um3 literal 1774 zcmWIWW@Zs#U|`^2P-w}IeKP6By{|ytBt`}XULc*Dn3tKBT3n)+Rh*ya8?e#ur~%KN z`{5BYGece+`}T!R!oleg=QES785zRv8@X2r{P&wARx!J@{M*lWuNfBH=zDRNTdhpw zif&0bYwt0?XT0aLkMwAENl49$37A^y%&1$rpGAGOT<6k_$x8jb0%!Mn&Nh&U|Nee6 zgI_4abMJ%4=da&&ZEc?U6&<4>tq0oQ&I_JpSsuUH*U-AV@%7uscP~3%ez|R-!TUE2 zIg`6L#n+V_tTcA^WK?B6k-@^YN%*;--SWLYyBaR~>U$$O{pZ|`T}=m0U1|JN=(KrH%W6BP zkiA=CD!Sh=t=_&x`RC;O;fl-O-%(%J7-sQ>&-e@@s@u-{UC{GkVPN>r1&U1uhT`nZ zJiX-N;;CV`^KQEd)Lswgc_MCYAlem@67ANwPsAhe%Tmu^k=90@^68JCcVcX*ys1pNTv_xz)mKu>gzF z%=GY}j+?sXSI*ilx;CFbnf<`eJ`S6fZq7dg%2JZ?=YkZ(IM0 zK(AO`@q*C%hfB=fL}={QSuyJit9(~;ZtKd~zb5cnx9vOBviJ6Bor+UtCmQyiKKae2&&{3tytb}SCP%oKhtv|6 z-H%cp>V_B0J^s^lzvT-1eKVI`4v0{2?8}a|`|>&C&uX!27L%)g2;bMPby<6O(VG8> zKAKmSgdY2N_vyycGXUcY1SO-nL1#_wPrF^?0X@$w>hnxKgT!NtKgRLuQ{8&?;kqUamm(yxBrK~JHmpL=d54Z zzINKahy%Vd*T0K1?wWqGGU+{|e22OtwFjX!q6r={UUfVI&it6^TGSwj?%5YSJaZW)o^nidAduyld+@tSHLa)y6{WAXYO@A+_=S1 zIB-&dtXtlNdGqV|Czjau?PCh?W@Hj!z+GPeiyb6@QhT6lMK4Mb`V@eb4^qL3t`WVQ aLulLs)Ceo}0=!w-Kr+lgxC%(?fq4L>Rtp9I diff --git a/docs/examples/host-chrome-toolbar/chrome.json b/docs/examples/host-chrome-toolbar/chrome.json index 0729373..aa5c557 100644 --- a/docs/examples/host-chrome-toolbar/chrome.json +++ b/docs/examples/host-chrome-toolbar/chrome.json @@ -3,6 +3,7 @@ "slots": { "host.recovery": { "mode": "toolbar", + "appearance": "icon", "anchor": ["home.header", "voice.header"], "align": "end" } diff --git a/docs/examples/host-chrome-toolbar/manifest.json b/docs/examples/host-chrome-toolbar/manifest.json index 09d8263..53a37cf 100644 --- a/docs/examples/host-chrome-toolbar/manifest.json +++ b/docs/examples/host-chrome-toolbar/manifest.json @@ -3,10 +3,10 @@ "packageType": "open-skin", "id": "community.host-chrome-toolbar", "name": "Host Chrome Toolbar", - "version": "1.0.0", + "version": "1.1.0", "author": "WebSpeak Community", "license": "AGPL-3.0-only", - "description": "Minimal open skin that docks the trusted recovery actions as host-owned toolbar buttons.", + "description": "Minimal open skin that docks Classic-aligned host-owned recovery icons into the page header.", "entry": "skin.css", "chrome": "chrome.json", "minAppVersion": "0.3.2" diff --git a/docs/examples/host-chrome-toolbar/skin.css b/docs/examples/host-chrome-toolbar/skin.css index fc54997..23b8b7f 100644 --- a/docs/examples/host-chrome-toolbar/skin.css +++ b/docs/examples/host-chrome-toolbar/skin.css @@ -1,96 +1,76 @@ /* Host chrome toolbar demo — v3 open skin (schemaVersion 3). - The only host integration is chrome.json: the trusted recovery entry is - declared as `mode: "toolbar"` and docked into the page header. The skin - supplies anchors and tokens; the host still owns the buttons and handlers. - - Selectors stay inside :root, [data-ws-page] and [data-ws-part]. */ + The host owns the recovery structure, icons, labels, focus and actions. + This package only declares an anchor, appearance and validated tokens. */ :root { - --skin-demo-surface: #13263d; - --skin-demo-foreground: #eef7ff; - --skin-demo-border: #3a628c; - --skin-demo-accent: #47dcc4; + color-scheme: light; + --skin-demo-surface: #f4f7fb; + --skin-demo-foreground: #1a1a1a; + --skin-demo-border: #d5dee8; + --skin-demo-accent: #1d4ed8; - /* Host-owned recovery buttons (toolbar mode). Every value is validated by - the host; invalid or unreadable values fall back to a visible button. */ - --skin-host-toolbar-background: #13263d; - --skin-host-toolbar-foreground: #eef7ff; - --skin-host-toolbar-border: #3a628c; - --skin-host-toolbar-radius: 8px; + /* Classic microphone-button geometry and colours. `surface` is the opaque + colour used to check text contrast behind the transparent toolbar. */ + --skin-host-toolbar-background: transparent; + --skin-host-toolbar-foreground: #1a1a1a; + --skin-host-toolbar-border: transparent; + --skin-host-toolbar-hover-background: #eaf2fd; + --skin-host-toolbar-hover-border: #b8cfe8; + --skin-host-toolbar-surface: #f4f7fb; + --skin-host-toolbar-radius: 2px; --skin-host-toolbar-font: Tahoma, "Segoe UI", sans-serif; - --skin-host-toolbar-font-size: 12px; - --skin-host-toolbar-padding: 7px 14px; - --skin-host-toolbar-height: 34px; + --skin-host-toolbar-font-size: 11px; + --skin-host-toolbar-padding: 0 4px; + --skin-host-toolbar-height: 22px; + --skin-host-toolbar-gap: 1px; + --skin-host-toolbar-icon-size: 16px; --skin-host-toolbar-shadow: none; - /* The floating capsule is the fallback when an anchor disappears. Keep the - same palette so a failed toolbar does not turn into a white popup. */ - --skin-recovery-background: #13263d; - --skin-recovery-foreground: #eef7ff; - --skin-recovery-border: #3a628c; - --skin-recovery-accent: #47dcc4; + /* The fallback and shortcut capsule remains opaque and full-text. */ + --skin-recovery-background: #ffffff; + --skin-recovery-foreground: #1a1a1a; + --skin-recovery-border: #9db6b2; + --skin-recovery-accent: #1d4ed8; + --skin-recovery-radius: 8px; } [data-ws-page] { - color-scheme: dark; - color: #e8f0f8; - background: #09131f; + color: #1a1a1a; + background: #ffffff; font-family: Tahoma, "Segoe UI", "Microsoft YaHei", sans-serif; } [data-ws-part="home.header"], [data-ws-part="voice.header"] { - background: linear-gradient(180deg, #12253c, #0d1a2b); - border-bottom: 1px solid #2a4a6a; - color: #e8f0f8; + background: #f4f7fb; + border-bottom: 1px solid var(--skin-demo-border); + color: var(--skin-demo-foreground); } -/* Voice page can carry a slightly darker value on its own anchor; the host - reads tokens from the anchor that actually docked the button. */ +/* Keep the two 24px icon buttons clear of ordinary header actions. */ +[data-ws-part="home.header"], [data-ws-part="voice.header"] { - --skin-recovery-toolbar-background: #0e2236; - --skin-recovery-toolbar-foreground: #f4fbff; - --skin-recovery-toolbar-border: #4f7fb0; -} - -/* Reserve the right edge of the top bar for the host-owned toolbar. Without - this the docked buttons would sit on top of the header actions. */ -@media (min-width: 900px) { - [data-ws-part="home.header"], - [data-ws-part="voice.header"] { - padding-right: 320px; - } + padding-right: 72px; } [data-ws-part="home.join-card"], -[data-ws-part="home.content"] { - color: #e8f0f8; +[data-ws-part="home.content"], +[data-ws-part="voice.workspace"], +[data-ws-part="voice.content"] { + color: var(--skin-demo-foreground); } [data-ws-part="home.join-card"] { - background: #0f1f33; - border: 1px solid #2a4a6a; - border-radius: 16px; - box-shadow: 0 24px 60px #0008; -} - -[data-ws-part="voice.workspace"] { - background: #09131f; -} - -[data-ws-part="voice.content"] { - color: #e8f0f8; + background: #ffffff; + border: 1px solid var(--skin-demo-border); + border-radius: 12px; + box-shadow: 0 16px 40px #10203012; } [data-ws-part="voice.audio-dock"] { - background: #0f1f33; - border-top: 1px solid #2a4a6a; + background: #f4f7fb; + border-top: 1px solid var(--skin-demo-border); } -[data-ws-part="home.footer"] { - color: #9db5c8; -} - -[data-ws-part="home.footer.clear"] { - color: var(--skin-demo-accent); -} +[data-ws-part="home.footer"] { color: #52606d; } +[data-ws-part="home.footer.clear"] { color: var(--skin-demo-accent); } diff --git a/src/shared/skin-chrome.ts b/src/shared/skin-chrome.ts index 2d2c105..9d4af0e 100644 --- a/src/shared/skin-chrome.ts +++ b/src/shared/skin-chrome.ts @@ -86,6 +86,9 @@ export type SkinChromeSlotAlign = "start" | "center" | "end"; */ export type SkinChromeSlotMode = "capsule" | "toolbar"; +/** Toolbar buttons may show host-owned icons without losing their accessible names. */ +export type SkinChromeSlotAppearance = "label" | "icon" | "icon-and-label"; + /** One anchor name, or ordered candidates (for example one per page). */ export type SkinChromeSlotAnchor = string | string[]; @@ -102,6 +105,8 @@ export interface SkinChromeSlot { compact: boolean; /** Explicit presentation; see `SkinChromeSlotMode`. */ mode: SkinChromeSlotMode; + /** Toolbar-only label/icon shape; the host always supplies the icon and name. */ + appearance: SkinChromeSlotAppearance; } export interface SkinChromeAssetInfo { @@ -196,6 +201,10 @@ function isSlotAlign(value: unknown): value is SkinChromeSlotAlign { return value === "start" || value === "center" || value === "end"; } +function isSlotAppearance(value: unknown): value is SkinChromeSlotAppearance { + return value === "label" || value === "icon" || value === "icon-and-label"; +} + export function parseSkinChromeDocument(source: string): SkinChromeDocument { const bytes = new TextEncoder().encode(source).byteLength; if (!bytes || bytes > SKIN_CHROME_MAX_BYTES) { @@ -271,7 +280,7 @@ export function parseSkinChromeDocument(source: string): SkinChromeDocument { return reject(`Slot ${part} must be an object.`, "SKIN_CHROME_SLOT_INVALID"); } for (const key of Object.keys(value)) { - if (key !== "anchor" && key !== "align" && key !== "compact" && key !== "mode") { + if (key !== "anchor" && key !== "align" && key !== "compact" && key !== "mode" && key !== "appearance") { return reject(`Slot ${part} contains an unsupported field: ${key}.`, "SKIN_CHROME_SLOT_INVALID"); } } @@ -299,7 +308,14 @@ export function parseSkinChromeDocument(source: string): SkinChromeDocument { if (mode === "toolbar" && compact) { return reject(`Slot ${part} compact is only valid in capsule mode.`, "SKIN_CHROME_SLOT_INVALID"); } - slots[part] = { anchor, align, compact, mode }; + const appearance = value.appearance === undefined ? "label" : value.appearance; + if (!isSlotAppearance(appearance)) { + return reject(`Slot ${part} has an invalid appearance value: ${String(appearance)}.`, "SKIN_CHROME_SLOT_INVALID"); + } + if (mode !== "toolbar" && appearance !== "label") { + return reject(`Slot ${part} appearance is only available in toolbar mode.`, "SKIN_CHROME_SLOT_INVALID"); + } + slots[part] = { anchor, align, compact, mode, appearance }; } const perAction = slots["host.recovery.built-in"] !== undefined || slots["host.recovery.library"] !== undefined; if (slots["host.recovery"] && perAction) { diff --git a/src/shared/skin-css.test.ts b/src/shared/skin-css.test.ts index 97e4d51..a859869 100644 --- a/src/shared/skin-css.test.ts +++ b/src/shared/skin-css.test.ts @@ -209,7 +209,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( const explicit = parseSkinChromeDocument(JSON.stringify({ schemaVersion: 1, slots: { - "host.recovery": { anchor: "voice.audio-dock", align: "start", compact: true }, + "host.recovery": { anchor: "voice.audio-dock", align: "start", compact: true, appearance: "label" }, }, })); assert.deepEqual(explicit.slots?.["host.recovery"], { @@ -217,6 +217,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( align: "start", compact: true, mode: "capsule", + appearance: "label", }); // Old slots without `mode` keep the docked capsule: the presentation is @@ -232,6 +233,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( align: "end", compact: false, mode: "capsule", + appearance: "label", }); assert.doesNotThrow(() => parseSkinChromeDocument(JSON.stringify({ schemaVersion: 1, @@ -256,6 +258,9 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "Voice Audio Dock" } } }, /not a valid part name/], [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "" } } }, /at most 240 characters/], [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "float" } } }, /invalid mode/], + [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "toolbar", appearance: "text" } } }, /invalid appearance/], + [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", appearance: "icon" } } }, /appearance is only available in toolbar mode/], + [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "capsule", appearance: "icon-and-label" } } }, /appearance is only available in toolbar mode/], [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "voice.audio-dock", mode: "toolbar", compact: true } } }, /compact is only valid in capsule mode/], [{ schemaVersion: 1, slots: { "host.recovery.built-in": { anchor: "voice.audio-dock", mode: "capsule" } } }, /only supports toolbar mode/], [{ schemaVersion: 1, slots: { "host.recovery.built-in": { anchor: "voice.audio-dock", compact: true } } }, /compact is only valid in capsule mode/], @@ -277,6 +282,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt "skin.home.topbar.part-host-actions", ], align: "end", + appearance: "icon", }, }, })); @@ -288,6 +294,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt align: "end", compact: false, mode: "toolbar", + appearance: "icon", }); const perAction = parseSkinChromeDocument(JSON.stringify({ @@ -297,6 +304,7 @@ test("chrome.json toolbar slots support page candidates and separate action butt mode: "toolbar", anchor: "skin.voice.topbar.part-built-in", align: "start", + appearance: "icon-and-label", }, "host.recovery.library": { mode: "toolbar", @@ -309,10 +317,12 @@ test("chrome.json toolbar slots support page candidates and separate action butt align: "start", compact: false, mode: "toolbar", + appearance: "icon-and-label", }); // Single-action slots are toolbar-only and default to toolbar mode. assert.equal(perAction.slots?.["host.recovery.library"]?.mode, "toolbar"); assert.equal(perAction.slots?.["host.recovery.library"]?.align, "end"); + assert.equal(perAction.slots?.["host.recovery.library"]?.appearance, "label"); const invalidDocuments: Array<[unknown, RegExp]> = [ [{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: [] } } }, /between 1 and 8/], diff --git a/web/public/host-chrome-toolbar.wskin b/web/public/host-chrome-toolbar.wskin index 64094c1f4bd16c758ea680bbda264762e4f5d098..2713053979485be236e340bf3f4a7cd1dbecb217 100644 GIT binary patch literal 1538 zcmWIWW@Zs#U|`^2P-w}IovM_e_6NwD#>l|H3#4-s^D@&?i%ayfiu3b)0}lEfHsIO& zUVF`)%qpFi{N|Gvc_@s*kFdzYu@ zjXRFj!53cqdEr+vLs@Ue#Ev^JJaS%5`^8kn`S8q?bnA|1$M`*&%py~)c5M;5*;@5~ zgTR8-EEX}scK>S5o_qJE%=NA%|0J#-ZO5l~tKO%C6MU{1m$OQK33&riVN+t)Z-rv#b*JFD{=Tqddmbhu`=?eO59Ok6% zbm{OmHdyf5@a9zk%jG*GL`z?XhF7dzQWmQId);aGQqhj@hX1bTZQHhWd)nu{KN$m1 zf{E?chv)Uc;5iJ$+(4Y1QIwyX3JxUKK0_{GAh~{@b0|Zvahr2_LAFk0MRe$s0ne2owIkD`!U93L;)>`sIc0Z#yzi`>?+Lx!% z+{v=+Se!3214BF~D1sRninBBG^pcBk!h{m$b?z zf$zxT_QyfLxleEodZiyZSFuRy^^nYB() zhlIr6-GB08Z|H_CrwV5lI(kO6Dm*#o`Ao3o@QtLLg+-Tc9+i5@$`Lp*OYft*>%`s5 zE}n9HnyrCcmbbXjr)C?x%y^dHCpp2APcm82KP7!mum1P# z@f!QYW8N|cKPaD_`QY>Jha7uMW>yqkdt*Jj;&*U^kJ{hxDJ!<>J~Ng$>{%b?7Wl5I zl>dh1w4%^@o4h>k7hCMlrmv_pZFX|GbILlZ`C!bWMMpGJ^tok1RJ)E`3a{MKr5d%d z*X?*|-^x!motxgC+GslU-5=k-+gmdyZ;Nl*el@Ca&y|;%R(tiIo_lxCH`BCG?B`BN zo_(E)iJLwdEwh|^|5gCIm%s8>1|GfKy4wA1ZSsqvE6f=8J&N9Bz3Ell`$Ml6PFb+H zCqPPeUVqu*={Z+(cO1Lry6t9LoAyE0Qy@9aWr*^@#? zl%{=mNqy|2-L|r0*S~WO$M|hm#Q4bHXt=VCwaeISf_c0`pziU0-vyyDGPe zLpM?JH^+UfVL?^H?9-=I&dzwk_<} z*-ys2%5*1x5dbxto mrw%NTkxChKjp!L2q47LWBP`noc(byBWSD_)6_9pf1@Qnxn4um3 literal 1774 zcmWIWW@Zs#U|`^2P-w}IeKP6By{|ytBt`}XULc*Dn3tKBT3n)+Rh*ya8?e#ur~%KN z`{5BYGece+`}T!R!oleg=QES785zRv8@X2r{P&wARx!J@{M*lWuNfBH=zDRNTdhpw zif&0bYwt0?XT0aLkMwAENl49$37A^y%&1$rpGAGOT<6k_$x8jb0%!Mn&Nh&U|Nee6 zgI_4abMJ%4=da&&ZEc?U6&<4>tq0oQ&I_JpSsuUH*U-AV@%7uscP~3%ez|R-!TUE2 zIg`6L#n+V_tTcA^WK?B6k-@^YN%*;--SWLYyBaR~>U$$O{pZ|`T}=m0U1|JN=(KrH%W6BP zkiA=CD!Sh=t=_&x`RC;O;fl-O-%(%J7-sQ>&-e@@s@u-{UC{GkVPN>r1&U1uhT`nZ zJiX-N;;CV`^KQEd)Lswgc_MCYAlem@67ANwPsAhe%Tmu^k=90@^68JCcVcX*ys1pNTv_xz)mKu>gzF z%=GY}j+?sXSI*ilx;CFbnf<`eJ`S6fZq7dg%2JZ?=YkZ(IM0 zK(AO`@q*C%hfB=fL}={QSuyJit9(~;ZtKd~zb5cnx9vOBviJ6Bor+UtCmQyiKKae2&&{3tytb}SCP%oKhtv|6 z-H%cp>V_B0J^s^lzvT-1eKVI`4v0{2?8}a|`|>&C&uX!27L%)g2;bMPby<6O(VG8> zKAKmSgdY2N_vyycGXUcY1SO-nL1#_wPrF^?0X@$w>hnxKgT!NtKgRLuQ{8&?;kqUamm(yxBrK~JHmpL=d54Z zzINKahy%Vd*T0K1?wWqGGU+{|e22OtwFjX!q6r={UUfVI&it6^TGSwj?%5YSJaZW)o^nidAduyld+@tSHLa)y6{WAXYO@A+_=S1 zIB-&dtXtlNdGqV|Czjau?PCh?W@Hj!z+GPeiyb6@QhT6lMK4Mb`V@eb4^qL3t`WVQ aLulLs)Ceo}0=!w-Kr+lgxC%(?fq4L>Rtp9I diff --git a/web/src/components/HostChrome.vue b/web/src/components/HostChrome.vue index 8bd7d35..7fab748 100644 --- a/web/src/components/HostChrome.vue +++ b/web/src/components/HostChrome.vue @@ -48,18 +48,42 @@ + > + + {{ copy.useBuiltIn }} + + > + + {{ copy.library }} + @@ -75,10 +99,22 @@ + > + + {{ copy.useBuiltIn }} +
{{ copy.library }} + > + + {{ copy.library }} +
{ align: "end", compact: false, mode: "capsule", + appearance: "label", }); // A part that is not slottable cannot be selected through chrome.json. assert.equal(activeHostSlot("host.permission"), undefined); diff --git a/web/src/services/host-control-tokens.test.ts b/web/src/services/host-control-tokens.test.ts index b0c08c2..3636ba0 100644 --- a/web/src/services/host-control-tokens.test.ts +++ b/web/src/services/host-control-tokens.test.ts @@ -13,14 +13,21 @@ import { PERMISSION_CONTROL_DEFAULTS, RECOVERY_CONTROL_DEFAULTS, SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS, + TOOLBAR_DEFAULT_GAP, + TOOLBAR_DEFAULT_ICON_SIZE, TOOLBAR_DEFAULT_PADDING_X, TOOLBAR_DEFAULT_PADDING_Y, TOOLBAR_DEFAULT_RADIUS, TOOLBAR_MAX_FONT_SIZE, + TOOLBAR_MAX_GAP, TOOLBAR_MAX_HEIGHT, + TOOLBAR_MAX_ICON_SIZE, TOOLBAR_MAX_PADDING, + TOOLBAR_MIN_HEIGHT, + TOOLBAR_MIN_ICON_SIZE, applyHostControlTokens, applyHostControlToolbarTokens, + compositeRgb, contrastRatio, fontFamilyNames, formatRgb, @@ -30,6 +37,7 @@ import { hostControlTokenProperty, hostToolbarTokenProperty, parseCssColor, + parseCssColorWithAlpha, relativeLuminance, resolveHostControlTokens, resolveHostControlToolbarTokens, @@ -265,6 +273,13 @@ test("CSS colours parse to RGB and ignore alpha for contrast", () => { } }); +test("alpha colours parse and composite over opaque toolbar surfaces", () => { + assert.deepEqual(parseCssColorWithAlpha("transparent"), { r: 0, g: 0, b: 0, a: 0 }); + assert.deepEqual(parseCssColorWithAlpha("#10203080"), { r: 16, g: 32, b: 48, a: 128 / 255 }); + assert.deepEqual(parseCssColorWithAlpha("rgb(255 0 0 / 50%)"), { r: 255, g: 0, b: 0, a: 0.5 }); + assert.deepEqual(compositeRgb({ r: 0, g: 0, b: 0, a: 0.5 }, { r: 255, g: 255, b: 255 }), { r: 128, g: 128, b: 128 }); +}); + test("WCAG contrast follows the relative-luminance formula", () => { assert.equal(relativeLuminance({ r: 0, g: 0, b: 0 }), 0); assert.equal(relativeLuminance({ r: 255, g: 255, b: 255 }), 1); @@ -293,12 +308,14 @@ test("host controls ignore fonts registered by a skin @font-face", () => { assert.equal(resolve("Tahoma, ws-community-evil-blank"), SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS.font); }); -const resolveToolbar = (tokens: TokenMap = {}, global: TokenMap = {}) => +const resolveToolbar = (tokens: TokenMap = {}, global: TokenMap = {}, sampledSurface?: { r: number; g: number; b: number }) => resolveHostControlToolbarTokens( - style({ ...prefixed("host", {}), ...tokens, ...global }), + style({ ...tokens, ...global }), "host.recovery", raw => raw, RECOVERY_CONTROL_DEFAULTS, + undefined, + sampledSurface, ); test("toolbar tokens are independent of the capsule shell and keep host floors", () => { @@ -341,16 +358,98 @@ test("toolbar tokens are independent of the capsule shell and keep host floors", assert.equal(global.foreground, "rgb(255, 255, 255)"); }); -test("unreadable or invalid toolbar tokens fall back to a visible, readable button", () => { - // Transparent backgrounds are treated as opaque RGB by parseCssColor; the - // result is unreadable against the text and the whole pair reverts. - const transparent = resolveToolbar({ - "--skin-recovery-toolbar-background": "rgba(0, 0, 0, 0)", - "--skin-recovery-toolbar-foreground": "#111111", +test("toolbar colours preserve transparency and check text against an opaque surface", () => { + const classic = resolveToolbar({ + "--skin-recovery-toolbar-background": "transparent", + "--skin-recovery-toolbar-foreground": "#1a1a1a", + "--skin-recovery-toolbar-border": "transparent", + "--skin-recovery-toolbar-hover-background": "#eaf2fd", + "--skin-recovery-toolbar-hover-border": "#b8cfe8", + }, {}, { r: 255, g: 255, b: 255 }); + assert.equal(classic.background, "transparent"); + assert.equal(classic.border, "transparent"); + assert.equal(classic.foreground, "rgb(26, 26, 26)"); + assert.equal(classic.hoverBackground, "rgb(234, 242, 253)"); + assert.equal(classic.hoverBorder, "rgb(184, 207, 232)"); + + const explicitDarkSurface = resolveToolbar({ + "--skin-recovery-toolbar-background": "#00000000", + "--skin-recovery-toolbar-foreground": "#ffffff", + "--skin-recovery-toolbar-surface": "#102030", + }, {}, { r: 255, g: 255, b: 255 }); + assert.equal(explicitDarkSurface.background, "transparent"); + assert.equal(explicitDarkSurface.foreground, "rgb(255, 255, 255)"); + + const sampledDarkSurface = resolveToolbar({ + "--skin-recovery-toolbar-background": "transparent", + "--skin-recovery-toolbar-foreground": "#ffffff", + }, {}, { r: 16, g: 32, b: 48 }); + assert.equal(sampledDarkSurface.background, "transparent"); + assert.equal(sampledDarkSurface.foreground, "rgb(255, 255, 255)"); + + const globalSurface = resolveToolbar({ + "--skin-recovery-toolbar-background": "transparent", + "--skin-recovery-toolbar-foreground": "#ffffff", + }, { "--skin-host-toolbar-surface": "#102030" }, { r: 255, g: 255, b: 255 }); + assert.equal(globalSurface.foreground, "rgb(255, 255, 255)"); +}); + +test("toolbar hover colours and Classic geometry are sanitized independently", () => { + const classic = resolveToolbar({ + "--skin-recovery-toolbar-height": "22px", + "--skin-recovery-toolbar-padding": "0 4px", + "--skin-recovery-toolbar-radius": "2px", + "--skin-recovery-toolbar-font-size": "11px", + "--skin-recovery-toolbar-gap": "1px", + "--skin-recovery-toolbar-icon-size": "16px", }); - assert.equal(transparent.background, "rgb(255, 255, 255)"); - assert.equal(transparent.foreground, "rgb(49, 82, 79)"); - assert.ok(contrastRatio(parseCssColor(transparent.foreground)!, parseCssColor(transparent.background)!) >= HOST_CONTROL_MIN_FOREGROUND_CONTRAST); + assert.equal(classic.minHeight, 22); + assert.equal(classic.paddingX, 4); + assert.equal(classic.paddingY, 0); + assert.equal(classic.radius, 2); + assert.equal(classic.fontSize, 11); + assert.equal(classic.gap, 1); + assert.equal(classic.iconSize, 16); + + const unreadableHover = resolveToolbar({ + "--skin-recovery-toolbar-background": "#ffffff", + "--skin-recovery-toolbar-foreground": "#757575", + "--skin-recovery-toolbar-hover-background": "#eeeeee", + "--skin-recovery-toolbar-hover-border": "not-a-colour", + }); + assert.equal(unreadableHover.hoverBackground, "rgb(255, 255, 255)"); + assert.equal(unreadableHover.hoverBorder, "rgb(157, 182, 178)"); + + const clamped = resolveToolbar({ + "--skin-recovery-toolbar-gap": "100px", + "--skin-recovery-toolbar-icon-size": "2px", + }); + assert.equal(clamped.gap, TOOLBAR_MAX_GAP); + assert.equal(clamped.iconSize, TOOLBAR_MIN_ICON_SIZE); + const oversized = resolveToolbar({ "--skin-recovery-toolbar-icon-size": "100px" }); + assert.equal(oversized.iconSize, TOOLBAR_MAX_ICON_SIZE); + assert.equal(resolveToolbar().gap, TOOLBAR_DEFAULT_GAP); + assert.equal(resolveToolbar().iconSize, TOOLBAR_DEFAULT_ICON_SIZE); +}); + +test("capsule tokens keep their opaque palette and 28px hit target", () => { + const capsule = resolveHostControlTokens(style({ + "--skin-recovery-background": "transparent", + "--skin-recovery-foreground": "#1a1a1a", + "--skin-recovery-toolbar-height": "22px", + }), "host.recovery", raw => raw, RECOVERY_CONTROL_DEFAULTS); + assert.equal(capsule.background, "rgb(255, 255, 255)"); + assert.equal(capsule.hitTarget, 28); +}); + +test("unreadable or invalid toolbar tokens fall back to a visible, readable button", () => { + const transparentUnreadable = resolveToolbar({ + "--skin-recovery-toolbar-background": "rgba(0, 0, 0, 0)", + "--skin-recovery-toolbar-foreground": "#ffffff", + }, {}, { r: 255, g: 255, b: 255 }); + assert.equal(transparentUnreadable.background, "rgb(255, 255, 255)"); + assert.equal(transparentUnreadable.foreground, "rgb(49, 82, 79)"); + assert.ok(contrastRatio(parseCssColor(transparentUnreadable.foreground)!, parseCssColor(transparentUnreadable.background)!) >= HOST_CONTROL_MIN_FOREGROUND_CONTRAST); const lowContrast = resolveToolbar({ "--skin-recovery-toolbar-background": "#777777", @@ -377,7 +476,7 @@ test("unreadable or invalid toolbar tokens fall back to a visible, readable butt // A syntactically valid but oversized padding is clamped, not applied raw. assert.equal(invalid.paddingX, TOOLBAR_MAX_PADDING); assert.equal(invalid.paddingY, TOOLBAR_MAX_PADDING); - assert.equal(invalid.minHeight, HOST_CONTROL_MIN_HIT_TARGET); + assert.equal(invalid.minHeight, TOOLBAR_MIN_HEIGHT); assert.equal(invalid.shadow, "none"); const oversized = resolveToolbar({ @@ -418,16 +517,24 @@ test("applying and clearing toolbar tokens writes only toolbar variables", () => }, } as unknown as HTMLElement; applyHostControlToolbarTokens(control, resolveToolbar({ - "--skin-recovery-toolbar-background": "#102030", - "--skin-recovery-toolbar-foreground": "#ffffff", + "--skin-recovery-toolbar-background": "#ffffff", + "--skin-recovery-toolbar-foreground": "#1a1a1a", "--skin-recovery-toolbar-padding": "6px 14px", "--skin-recovery-toolbar-height": "36px", + "--skin-recovery-toolbar-hover-background": "#eaf2fd", + "--skin-recovery-toolbar-hover-border": "#b8cfe8", + "--skin-recovery-toolbar-gap": "1px", + "--skin-recovery-toolbar-icon-size": "16px", })); - assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.background), "rgb(16, 32, 48)"); - assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.foreground), "rgb(255, 255, 255)"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.background), "rgb(255, 255, 255)"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.foreground), "rgb(26, 26, 26)"); assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.paddingX), "14px"); assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.paddingY), "6px"); assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.minHeight), "36px"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.hoverBackground), "rgb(234, 242, 253)"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.hoverBorder), "rgb(184, 207, 232)"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.gap), "1px"); + assert.equal(values.get(HOST_TOOLBAR_APPLIED_VARIABLES.iconSize), "16px"); applyHostControlToolbarTokens(control, null); assert.equal(values.size, 0); }); diff --git a/web/src/services/host-control-tokens.ts b/web/src/services/host-control-tokens.ts index 6e27531..b25db2b 100644 --- a/web/src/services/host-control-tokens.ts +++ b/web/src/services/host-control-tokens.ts @@ -58,6 +58,7 @@ export type HostControlTokenName = (typeof HOST_CONTROL_TOKEN_NAMES)[number]; */ export const HOST_TOOLBAR_TOKEN_NAMES = [ "background", "foreground", "border", "radius", "font", "font-size", "padding", "height", "shadow", + "hover-background", "hover-border", "surface", "gap", "icon-size", ] as const; export type HostToolbarTokenName = (typeof HOST_TOOLBAR_TOKEN_NAMES)[number]; @@ -72,6 +73,11 @@ export const HOST_TOOLBAR_GLOBAL_TOKEN_PROPERTIES: Readonly>, + globalTokens: Partial>, + probeColor: ColorProbe, + sampledSurface: RgbColor | null | undefined, + defaults: HostControlDefaults, +): RgbColor { + for (const raw of [partTokens.surface, globalTokens.surface]) { + const color = parseToolbarColor(raw, probeColor); + if (color?.a === 1) return { r: color.r, g: color.g, b: color.b }; + } + return sampledSurface ?? defaults.background; +} + +function resolveToolbarBorder( + raw: string | undefined, + background: RgbColor, + fallback: string, + probeColor: ColorProbe, +): string { + const color = parseToolbarColor(raw, probeColor); + if (!color) return fallback; + if (color.a === 0) return "transparent"; + return contrastRatio(color, background) >= HOST_CONTROL_MIN_BORDER_CONTRAST ? formatRgb(color) : fallback; +} + +function resolveToolbarHoverBorder(raw: string | undefined, fallback: string, probeColor: ColorProbe): string { + const color = parseToolbarColor(raw, probeColor); + if (!color) return fallback; + // Classic's subtle #b8cfe8 hover edge is intentionally below the 3:1 + // non-text contrast floor; validate syntax without rejecting that design. + return formatToolbarColor(color); +} + /** * Resolve the toolbar button palette and geometry. * - * The base control palette is resolved first (background/foreground/accent/ - * border/font/size, with every existing readability floor). Toolbar tokens - * then override colours and radius; an unreadable toolbar colour pair falls - * back to the readable base pair, so an invalid or transparent value can never - * make the button invisible. `font-size`, `padding` and `height` may raise the - * button but never go below `HOST_CONTROL_MIN_FONT_SIZE` / the current hit - * target; `shadow` accepts one simple box-shadow value and otherwise becomes - * `none` (no fixed capsule shadow). + * Transparent backgrounds and borders are valid. Text is checked against an + * explicit opaque `surface` token, or the caller's sampled anchor/ancestor + * surface, never against transparent black. Opaque colours keep the existing + * capsule contrast floors. Hover colours fall back independently to the normal + * button colours, and only an explicit toolbar height may reach the 22px + * Classic toolbar floor; the size-tier default remains 28/32/36px. */ export function resolveHostControlToolbarTokens( style: Pick | null, @@ -613,6 +713,7 @@ export function resolveHostControlToolbarTokens( probeColor: ColorProbe, defaults: HostControlDefaults, isWebFont: WebFontCheck = NO_WEB_FONTS, + sampledSurface?: RgbColor | null, ): HostControlToolbarTokens { const base = resolveHostControlTokens(style, part, probeColor, defaults, isWebFont); const globalTokens = readToolbarTokenSet(style, (token) => HOST_TOOLBAR_GLOBAL_TOKEN_PROPERTIES[token]); @@ -622,21 +723,30 @@ export function resolveHostControlToolbarTokens( const baseBackground = parseCssColor(base.background) ?? defaults.background; const baseForeground = parseCssColor(base.foreground) ?? defaults.foreground; const baseBorder = parseCssColor(base.border) ?? defaults.border; - let background = parseCssColor(probeColor(merged.background)) ?? baseBackground; - let foreground = parseCssColor(probeColor(merged.foreground)) ?? baseForeground; - // A toolbar colour pair must keep the same text contrast floor as the - // capsule; on any failure the already-readable base palette wins as a pair. - if (contrastRatio(foreground, background) < HOST_CONTROL_MIN_FOREGROUND_CONTRAST) { - background = baseBackground; - foreground = baseForeground; + const surface = resolveToolbarSurface(partTokens, globalTokens, probeColor, sampledSurface, defaults); + let background = parseToolbarColor(merged.background, probeColor) ?? { ...baseBackground, a: 1 }; + let foreground = parseToolbarColor(merged.foreground, probeColor) ?? { ...baseForeground, a: 1 }; + let effectiveBackground = background.a === 0 ? surface : background; + if (contrastRatio(foreground, effectiveBackground) < HOST_CONTROL_MIN_FOREGROUND_CONTRAST) { + background = { ...baseBackground, a: 1 }; + foreground = { ...baseForeground, a: 1 }; + effectiveBackground = baseBackground; } - const border = resolveBorder(merged.border, background, probeColor) ?? baseBorder; + const border = resolveToolbarBorder(merged.border, effectiveBackground, base.border, probeColor); + + let hoverBackground = parseToolbarColor(merged["hover-background"], probeColor) ?? background; + let effectiveHoverBackground = hoverBackground.a === 0 ? surface : hoverBackground; + if (contrastRatio(foreground, effectiveHoverBackground) < HOST_CONTROL_MIN_FOREGROUND_CONTRAST) { + hoverBackground = background; + effectiveHoverBackground = effectiveBackground; + } + const hoverBorder = resolveToolbarHoverBorder(merged["hover-border"], border, probeColor); const padding = sanitizeToolbarPadding(merged.padding); return { - background: formatRgb(background), + background: formatToolbarColor(background), foreground: formatRgb(foreground), - border: formatRgb(border), + border, radius: sanitizeRadius(merged.radius, TOOLBAR_DEFAULT_RADIUS, TOOLBAR_MAX_RADIUS), font: sanitizeFont(merged.font, base.font, isWebFont), fontSize: sanitizeToolbarFontSize(merged["font-size"], base.fontSize), @@ -644,6 +754,15 @@ export function resolveHostControlToolbarTokens( paddingY: padding?.y ?? TOOLBAR_DEFAULT_PADDING_Y, minHeight: sanitizeToolbarHeight(merged.height, base.hitTarget), shadow: sanitizeToolbarShadow(merged.shadow) ?? "none", + hoverBackground: formatToolbarColor(hoverBackground), + hoverBorder, + gap: sanitizeToolbarLength(merged.gap, TOOLBAR_DEFAULT_GAP, 0, TOOLBAR_MAX_GAP), + iconSize: sanitizeToolbarLength( + merged["icon-size"], + TOOLBAR_DEFAULT_ICON_SIZE, + TOOLBAR_MIN_ICON_SIZE, + TOOLBAR_MAX_ICON_SIZE, + ), focus: base.accent, }; } @@ -667,6 +786,10 @@ export function applyHostControlToolbarTokens( style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.minHeight, `${tokens.minHeight}px`); style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.shadow, tokens.shadow); style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.focus, tokens.focus); + style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.hoverBackground, tokens.hoverBackground); + style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.hoverBorder, tokens.hoverBorder); + style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.gap, `${tokens.gap}px`); + style.setProperty(HOST_TOOLBAR_APPLIED_VARIABLES.iconSize, `${tokens.iconSize}px`); } export interface HostControlThemeBindingOptions { @@ -804,8 +927,8 @@ export function createHostControlProbe(shadow: ShadowRoot): HostControlProbe { canvas.fillStyle = "#000"; canvas.fillStyle = computed; canvas.fillRect(0, 0, 1, 1); - const [r, g, b] = canvas.getImageData(0, 0, 1, 1).data; - return formatRgb({ r, g, b }); + const [r, g, b, a] = canvas.getImageData(0, 0, 1, 1).data; + return a === 255 ? formatRgb({ r, g, b }) : `rgba(${r}, ${g}, ${b}, ${a / 255})`; }; return { diff --git a/web/src/services/host-slot-placement.ts b/web/src/services/host-slot-placement.ts index 5e98492..9bec6c2 100644 --- a/web/src/services/host-slot-placement.ts +++ b/web/src/services/host-slot-placement.ts @@ -21,12 +21,16 @@ import { RECOVERY_CONTROL_DEFAULTS, applyHostControlTokens, applyHostControlToolbarTokens, + compositeRgb, createHostControlProbe, findSkinRoot, + parseCssColorWithAlpha, resolveHostControlTokens, resolveHostControlToolbarTokens, type HostControlTokens, type HostControlProbe, + type RgbColor, + type RgbaColor, } from "./host-control-tokens.js"; export interface SlotViewport { @@ -226,6 +230,22 @@ function rectOf(rect: DOMRect | HostPartRect): HostPartRect { }; } +/** Composite the anchor and top-bar ancestor backgrounds over the page canvas. */ +export function sampleOpaqueSurface(element: Element | null, doc: Document = document): RgbColor { + const view = doc.defaultView; + const layers: RgbaColor[] = []; + for (let current: Element | null = element; current && view; current = current.parentElement) { + const color = parseCssColorWithAlpha(view.getComputedStyle(current).backgroundColor); + if (color && color.a > 0) layers.push(color); + if (color?.a === 1) break; + } + let surface: RgbColor = { r: 255, g: 255, b: 255 }; + for (let index = layers.length - 1; index >= 0; index -= 1) { + surface = compositeRgb(layers[index], surface); + } + return surface; +} + /** Overlap of two rects in CSS pixels on both axes (more than 1px each). */ export function rectsOverlap(first: HostPartRect, second: HostPartRect): boolean { const width = Math.min(first.right, second.right) - Math.max(first.left, second.left); @@ -327,9 +347,10 @@ export interface HostSlotBindingOptions { skinId?: string; align?: SkinChromeSlotAlign; /** - * `toolbar` also applies `--skin-recovery-toolbar-*` tokens (background, - * foreground, border, radius, font, font size, padding, min height, shadow). - * The capsule mode keeps the historical control tokens only. + * `toolbar` also applies `--skin-recovery-toolbar-*` / `--skin-host-toolbar-*` + * tokens for background, foreground, border, hover, radius, font, font size, + * padding, height, shadow, surface, gap and icon size. The capsule mode keeps + * the historical control tokens only. */ presentation?: "capsule" | "toolbar"; /** @@ -451,22 +472,23 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding { const tokenStyle = tokenSource ? win.getComputedStyle(tokenSource) : null; const tokens = readTokens(tokenStyle); applyHostControlTokens(control, tokenStyle ? tokens : null); + let toolbarMinHeight: number | undefined; if (options.presentation === "toolbar") { // Toolbar buttons get a second, independent token set so they can match - // a neighbouring top-bar button instead of the capsule palette. The - // resolver keeps the same contrast/font floors and falls back as a group. - applyHostControlToolbarTokens( - control, - tokenStyle - ? resolveHostControlToolbarTokens( - tokenStyle, - "host.recovery", - probe.probeColor, - RECOVERY_CONTROL_DEFAULTS, - probe.isWebFont, - ) - : null, - ); + // a neighbouring top-bar button instead of the capsule palette. A + // transparent button is checked against the surface behind its anchor. + const toolbarTokens = tokenStyle + ? resolveHostControlToolbarTokens( + tokenStyle, + "host.recovery", + probe.probeColor, + RECOVERY_CONTROL_DEFAULTS, + probe.isWebFont, + sampleOpaqueSurface(tokenSource, doc), + ) + : null; + toolbarMinHeight = toolbarTokens?.minHeight; + applyHostControlToolbarTokens(control, toolbarTokens); } const controlBox = control.getBoundingClientRect(); @@ -522,7 +544,7 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding { anchor: anchorSnapshot, controlRect: intendedRect, viewport, - minHitTarget: tokens.hitTarget, + minHitTarget: toolbarMinHeight ?? tokens.hitTarget, coversProtected, otherControls: options.otherControls?.(), hitTestOk: placement diff --git a/web/test/fixtures/host-recovery-legacy-slot.html b/web/test/fixtures/host-recovery-legacy-slot.html index af4c5e1..b60dae5 100644 --- a/web/test/fixtures/host-recovery-legacy-slot.html +++ b/web/test/fixtures/host-recovery-legacy-slot.html @@ -61,6 +61,7 @@ try { const anchorRect = document.getElementById("anchor").getBoundingClientRect(); const capsuleRect = capsule.getBoundingClientRect(); const button = capsule.querySelector('[data-ws-recovery-action="built-in"]'); + const buttonStyle = getComputedStyle(button); const style = getComputedStyle(capsule); const isOpen = Boolean(capsule.matches(":popover-open")) || style.display !== "none"; const before = hostBuiltInSkinRequests.value; @@ -75,6 +76,10 @@ try { .map((entry) => entry.getAttribute("data-ws-recovery-action")), background: style.backgroundColor, foreground: style.color, + capsuleHeight: capsule.getBoundingClientRect().height, + builtInHeight: button.getBoundingClientRect().height, + builtInBackground: buttonStyle.backgroundColor, + builtInForeground: buttonStyle.color, clicked: hostBuiltInSkinRequests.value === before + 1, }); } catch (error) { diff --git a/web/test/fixtures/host-recovery-toolbar-classic.html b/web/test/fixtures/host-recovery-toolbar-classic.html new file mode 100644 index 0000000..c655681 --- /dev/null +++ b/web/test/fixtures/host-recovery-toolbar-classic.html @@ -0,0 +1,150 @@ + + + + + +Classic recovery toolbar fixture + + + + +
+
+ +
+
+
+
pending
+ + + diff --git a/web/test/fixtures/host-recovery-toolbar.html b/web/test/fixtures/host-recovery-toolbar.html index 650493c..3456c62 100644 --- a/web/test/fixtures/host-recovery-toolbar.html +++ b/web/test/fixtures/host-recovery-toolbar.html @@ -246,7 +246,7 @@ try { // Invalid / unreadable toolbar tokens must not make the button invisible. const voiceAnchor = document.getElementById("voice-anchor"); voiceAnchor.style.setProperty("--skin-recovery-toolbar-background", "rgba(0,0,0,0)"); - voiceAnchor.style.setProperty("--skin-recovery-toolbar-foreground", "#111111"); + voiceAnchor.style.setProperty("--skin-recovery-toolbar-foreground", "#ffffff"); voiceAnchor.style.setProperty("--skin-recovery-toolbar-shadow", "url(https://example.invalid/pixel)"); await sleep(700); const fallbackStyle = getComputedStyle(buttons()[0]); diff --git a/web/test/host-chrome-recovery.test.mjs b/web/test/host-chrome-recovery.test.mjs index 521522e..d65b1a8 100644 --- a/web/test/host-chrome-recovery.test.mjs +++ b/web/test/host-chrome-recovery.test.mjs @@ -98,6 +98,14 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye assert.match(hostChrome, /presentation: "toolbar"/); assert.match(hostChrome, /resolveHostRecoveryPresentation/); assert.match(hostChrome, /class="ws-host-toolbar-action"/); + assert.match(hostChrome, /:aria-label="copy\.useBuiltIn"/); + assert.match(hostChrome, /:aria-label="copy\.library"/); + assert.match(hostChrome, /class="ws-host-toolbar-icon" aria-hidden="true"/); + assert.match(hostChrome, /focusable="false"/); + assert.match(hostChrome, /--ws-toolbar-hover-background/); + assert.match(hostChrome, /--ws-toolbar-hover-border/); + assert.match(hostChrome, /--ws-toolbar-gap/); + assert.match(hostChrome, /--ws-toolbar-icon-size/); assert.match(hostChrome, /data-ws-recovery-action="built-in"[\s\S]*?@click="useBuiltInSkin"/); assert.match(hostChrome, /data-ws-recovery-action="library"[\s\S]*?@click="openLibrary"/); assert.match(hostChrome, /resolveHostRecoveryPresentation\(/); @@ -528,6 +536,75 @@ test("host control tokens follow late skin CSS, resolve modern colours and refus assert.equal(byName["after-dispose"].inlineBackground, late.inlineBackground, "a disposed binding kept observing the document"); }); +test("Classic toolbar icons keep 22px geometry, transparency, names and full-label shortcut recovery", { skip: !CHROME && "google-chrome is not installed" }, async (t) => { + const server = await createServer({ + root: webRoot, + configFile: path.join(webRoot, "vite.config.ts"), + logLevel: "silent", + server: { host: "127.0.0.1", port: 0, strictPort: false, hmr: false, ws: false }, + }); + t.after(() => server.close()); + await server.listen(); + const address = server.httpServer?.address(); + const port = address && typeof address === "object" ? address.port : 0; + assert.ok(port, "Vite did not expose a listening port"); + + const dom = await dumpDom( + `http://127.0.0.1:${port}/test/fixtures/host-recovery-toolbar-classic.html`, + ["--virtual-time-budget=10000", "--window-size=1280,800"], + ); + const match = dom.match(/
]*>([\s\S]*?)<\/pre>/);
+  assert.ok(match, "the Classic toolbar fixture did not emit a result block");
+  const payload = JSON.parse(match[1].replace(/"/g, '"').replace(/&/g, "&"));
+  assert.equal(payload.error, undefined, payload.error);
+
+  const initial = payload.initial;
+  assert.equal(initial.toolbarOpen, true);
+  assert.equal(initial.capsuleOpen, false);
+  assert.equal(initial.actionCount, 2);
+  assert.equal(initial.height, 22);
+  assert.equal(initial.width, 24);
+  assert.equal(initial.minHeight, "22px");
+  assert.equal(initial.paddingTop, "0px");
+  assert.equal(initial.paddingRight, "0px");
+  assert.equal(initial.paddingBottom, "0px");
+  assert.equal(initial.paddingLeft, "0px");
+  assert.equal(initial.borderTopWidth, "1px");
+  assert.equal(initial.radius, "2px");
+  assert.equal(initial.fontSize, "11px");
+  assert.equal(initial.background, "rgba(0, 0, 0, 0)");
+  assert.equal(initial.foreground, "rgb(26, 26, 26)");
+  assert.equal(initial.gap, "1px");
+  assert.equal(initial.hoverBackground, "rgb(234, 242, 253)");
+  assert.equal(initial.hoverBorder, "rgb(184, 207, 232)");
+  assert.equal(initial.iconWidth, 16);
+  assert.equal(initial.iconHeight, 16);
+  assert.equal(initial.iconDisplay, "block");
+  assert.equal(initial.iconAriaHidden, "true");
+  assert.equal(initial.svgFocusable, "false");
+  assert.deepEqual(initial.visibleText, ["", ""]);
+  assert.deepEqual(initial.accessibleNames, ["Use built-in skin", "Application library"]);
+  assert.equal(initial.titles[0], "Restore the built-in skin (Ctrl+Alt+Shift+R, or ⌘+⌥+⇧+R on macOS)");
+  assert.equal(initial.titles[1], "Application library");
+  assert.equal(initial.groupName, "Restore built-in skin");
+  assert.equal(initial.hitIsLayerHost, true);
+  assert.equal(initial.builtInClicked, true);
+  assert.equal(initial.libraryClicked, true);
+
+  assert.equal(payload.shortcut.capsuleOpen, true);
+  assert.equal(payload.shortcut.toolbarOpen, false);
+  assert.deepEqual(payload.shortcut.labels, ["Use built-in skin", "Application library"]);
+  assert.ok(payload.shortcut.height >= 28);
+  assert.equal(payload.shortcut.builtInBackground, "rgb(255, 247, 237)");
+  assert.equal(payload.shortcut.builtInForeground, "rgb(124, 45, 18)");
+  assert.equal(payload.shortcut.focusedAction, "built-in");
+  assert.equal(payload.afterEscape.capsuleOpen, false);
+  assert.equal(payload.afterEscape.toolbarOpen, true);
+  assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)");
+  assert.equal(payload.invalidTokens.foreground, "rgb(49, 82, 79)");
+  assert.equal(payload.invalidTokens.visible, true);
+});
+
 test("toolbar-mode recovery docks plain host buttons, de-duplicates the library and falls back", { skip: !CHROME && "google-chrome is not installed" }, async (t) => {
   const server = await createServer({
     root: webRoot,
@@ -615,7 +692,7 @@ test("toolbar-mode recovery docks plain host buttons, de-duplicates the library
 
   assert.equal(payload.invalidTokens.visible, true, "invalid toolbar tokens hid the button");
   assert.equal(payload.invalidTokens.inViewport, true);
-  assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)", "transparent background must fall back to a visible surface");
+  assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)", "unreadable transparent foreground must fall back to a visible surface");
   assert.equal(payload.invalidTokens.foreground, "rgb(49, 82, 79)");
   assert.equal(payload.invalidTokens.shadow, "none", "the invalid shadow token must not be applied");
 
@@ -832,5 +909,9 @@ test("legacy slots without a mode still dock the capsule", { skip: !CHROME && "g
   assert.deepEqual(payload.actions, ["built-in", "library"]);
   assert.equal(payload.background, "rgb(16, 32, 48)", "the capsule still reads --skin-recovery-* tokens");
   assert.equal(payload.foreground, "rgb(255, 255, 255)");
+  assert.ok(payload.capsuleHeight >= 28, "the legacy capsule lost its original size floor");
+  assert.ok(payload.builtInHeight >= 28, "the legacy capsule action lost its original size floor");
+  assert.equal(payload.builtInBackground, "rgb(255, 247, 237)", "the capsule built-in action must keep its fixed light background");
+  assert.equal(payload.builtInForeground, "rgb(124, 45, 18)");
   assert.equal(payload.clicked, true);
 });