mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
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.
This commit is contained in:
1 parent
4131d9c319
commit
df826f575e
18 files changed
+805
-160
No files matched your search
+43
-10
@@ -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"`(两个按钮共用一个锚点):
|
||||
|
||||
|
||||
@@ -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.
|
||||
Binary file not shown.
@@ -3,6 +3,7 @@
|
||||
"slots": {
|
||||
"host.recovery": {
|
||||
"mode": "toolbar",
|
||||
"appearance": "icon",
|
||||
"anchor": ["home.header", "voice.header"],
|
||||
"align": "end"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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); }
|
||||
@@ -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) {
|
||||
|
||||
@@ -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/],
|
||||
|
||||
Binary file not shown.
@@ -48,18 +48,42 @@
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
:class="{ 'ws-host-toolbar-action-icon': groupToolbarConfig.appearance === 'icon' }"
|
||||
data-ws-recovery-action="built-in"
|
||||
:aria-label="copy.useBuiltIn"
|
||||
:title="copy.shortcut"
|
||||
@click="useBuiltInSkin"
|
||||
>{{ copy.useBuiltIn }}</button>
|
||||
>
|
||||
<span v-if="groupToolbarConfig.appearance !== 'label'" class="ws-host-toolbar-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" focusable="false">
|
||||
<path d="M8 2.2a5.8 5.8 0 1 0 0 11.6h.9a1.5 1.5 0 0 0 .7-2.83 1.2 1.2 0 0 1 .6-2.25H12A2 2 0 0 0 14 6.8C14 4.1 11.3 2.2 8 2.2Z"/>
|
||||
<circle cx="5" cy="6" r=".7" fill="currentColor" stroke="none"/>
|
||||
<circle cx="7.2" cy="4.6" r=".7" fill="currentColor" stroke="none"/>
|
||||
<circle cx="10" cy="4.9" r=".7" fill="currentColor" stroke="none"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="groupToolbarConfig.appearance !== 'icon'" class="ws-host-toolbar-label">{{ copy.useBuiltIn }}</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="pluginLibraryAvailable"
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
:class="{ 'ws-host-toolbar-action-icon': groupToolbarConfig.appearance === 'icon' }"
|
||||
data-ws-recovery-action="library"
|
||||
:aria-label="copy.library"
|
||||
:title="copy.library"
|
||||
@click="openLibrary"
|
||||
>{{ copy.library }}</button>
|
||||
>
|
||||
<span v-if="groupToolbarConfig.appearance !== 'label'" class="ws-host-toolbar-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" focusable="false">
|
||||
<rect x="2.2" y="2.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="9.2" y="2.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="2.2" y="9.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="9.2" y="9.2" width="4.6" height="4.6" rx=".8"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="groupToolbarConfig.appearance !== 'icon'" class="ws-host-toolbar-label">{{ copy.library }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Per-action toolbar entries: each action has its own anchor. -->
|
||||
@@ -75,10 +99,22 @@
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
:class="{ 'ws-host-toolbar-action-icon': builtInToolbarConfig.appearance === 'icon' }"
|
||||
data-ws-recovery-action="built-in"
|
||||
:aria-label="copy.useBuiltIn"
|
||||
:title="copy.shortcut"
|
||||
@click="useBuiltInSkin"
|
||||
>{{ copy.useBuiltIn }}</button>
|
||||
>
|
||||
<span v-if="builtInToolbarConfig.appearance !== 'label'" class="ws-host-toolbar-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" focusable="false">
|
||||
<path d="M8 2.2a5.8 5.8 0 1 0 0 11.6h.9a1.5 1.5 0 0 0 .7-2.83 1.2 1.2 0 0 1 .6-2.25H12A2 2 0 0 0 14 6.8C14 4.1 11.3 2.2 8 2.2Z"/>
|
||||
<circle cx="5" cy="6" r=".7" fill="currentColor" stroke="none"/>
|
||||
<circle cx="7.2" cy="4.6" r=".7" fill="currentColor" stroke="none"/>
|
||||
<circle cx="10" cy="4.9" r=".7" fill="currentColor" stroke="none"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="builtInToolbarConfig.appearance !== 'icon'" class="ws-host-toolbar-label">{{ copy.useBuiltIn }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -93,10 +129,22 @@
|
||||
<button
|
||||
type="button"
|
||||
class="ws-host-toolbar-action"
|
||||
:class="{ 'ws-host-toolbar-action-icon': libraryToolbarConfig.appearance === 'icon' }"
|
||||
data-ws-recovery-action="library"
|
||||
:aria-label="copy.library"
|
||||
:title="copy.library"
|
||||
@click="openLibrary"
|
||||
>{{ copy.library }}</button>
|
||||
>
|
||||
<span v-if="libraryToolbarConfig.appearance !== 'label'" class="ws-host-toolbar-icon" aria-hidden="true">
|
||||
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" focusable="false">
|
||||
<rect x="2.2" y="2.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="9.2" y="2.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="2.2" y="9.2" width="4.6" height="4.6" rx=".8"/>
|
||||
<rect x="9.2" y="9.2" width="4.6" height="4.6" rx=".8"/>
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="libraryToolbarConfig.appearance !== 'icon'" class="ws-host-toolbar-label">{{ copy.library }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -254,7 +302,7 @@ const RECOVERY_LAYER_CSS = `
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
gap: var(--ws-toolbar-gap, 4px);
|
||||
max-width: calc(100vw - 8px);
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -263,6 +311,7 @@ const RECOVERY_LAYER_CSS = `
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
box-sizing: border-box;
|
||||
min-height: var(--ws-toolbar-min-height, var(--ws-control-hit, 28px));
|
||||
max-width: min(320px, calc(100vw - 8px));
|
||||
@@ -281,11 +330,25 @@ const RECOVERY_LAYER_CSS = `
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
.ws-host-toolbar-action:hover { filter: brightness(.96); }
|
||||
.ws-host-toolbar-action:hover {
|
||||
border-color: var(--ws-toolbar-hover-border, var(--ws-toolbar-border, #9db6b2));
|
||||
background: var(--ws-toolbar-hover-background, var(--ws-toolbar-background, #fff));
|
||||
}
|
||||
.ws-host-toolbar-action:focus-visible {
|
||||
outline: 2px solid var(--ws-toolbar-focus, var(--ws-control-accent, #4c8f88));
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.ws-host-toolbar-icon {
|
||||
display: block;
|
||||
flex: 0 0 auto;
|
||||
width: var(--ws-toolbar-icon-size, 16px);
|
||||
height: var(--ws-toolbar-icon-size, 16px);
|
||||
}
|
||||
.ws-host-toolbar-icon svg { display: block; width: 100%; height: 100%; }
|
||||
.ws-host-toolbar-action-icon {
|
||||
width: max(24px, calc(var(--ws-toolbar-icon-size, 16px) + 8px));
|
||||
padding: 0;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ws-host-recovery, .ws-host-recovery button, .ws-host-toolbar-action { transition: none !important; }
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ test("slot declarations are honoured for third-party skins only", () => {
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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<Record<HostToolbarTo
|
||||
padding: "--skin-host-toolbar-padding",
|
||||
height: "--skin-host-toolbar-height",
|
||||
shadow: "--skin-host-toolbar-shadow",
|
||||
"hover-background": "--skin-host-toolbar-hover-background",
|
||||
"hover-border": "--skin-host-toolbar-hover-border",
|
||||
surface: "--skin-host-toolbar-surface",
|
||||
gap: "--skin-host-toolbar-gap",
|
||||
"icon-size": "--skin-host-toolbar-icon-size",
|
||||
};
|
||||
|
||||
/** Global token set read from the active skin root (or a slot anchor). */
|
||||
@@ -135,6 +141,10 @@ export const HOST_TOOLBAR_APPLIED_VARIABLES = {
|
||||
minHeight: "--ws-toolbar-min-height",
|
||||
shadow: "--ws-toolbar-shadow",
|
||||
focus: "--ws-toolbar-focus",
|
||||
hoverBackground: "--ws-toolbar-hover-background",
|
||||
hoverBorder: "--ws-toolbar-hover-border",
|
||||
gap: "--ws-toolbar-gap",
|
||||
iconSize: "--ws-toolbar-icon-size",
|
||||
} as const;
|
||||
|
||||
export interface HostControlRawTokens {
|
||||
@@ -189,9 +199,15 @@ export interface HostControlToolbarTokens {
|
||||
fontSize: number;
|
||||
paddingX: number;
|
||||
paddingY: number;
|
||||
/** Minimum button height; never below the current size tier hit target. */
|
||||
/** Minimum button height; defaults to the size tier and may reach 22px in toolbar mode. */
|
||||
minHeight: number;
|
||||
shadow: string;
|
||||
hoverBackground: string;
|
||||
hoverBorder: string;
|
||||
/** Space between grouped host buttons. */
|
||||
gap: number;
|
||||
/** Size of the host-owned toolbar icon. */
|
||||
iconSize: number;
|
||||
/** Focus ring colour, from the readable accent of the control palette. */
|
||||
focus: string;
|
||||
}
|
||||
@@ -202,6 +218,10 @@ export interface RgbColor {
|
||||
b: number;
|
||||
}
|
||||
|
||||
export interface RgbaColor extends RgbColor {
|
||||
a: number;
|
||||
}
|
||||
|
||||
const DEFAULT_ACCENT: RgbColor = { r: 180, g: 83, b: 9 };
|
||||
const DEFAULT_BACKGROUND: RgbColor = { r: 255, g: 255, b: 255 };
|
||||
const DEFAULT_FOREGROUND: RgbColor = { r: 49, g: 82, b: 79 };
|
||||
@@ -213,7 +233,8 @@ const ON_ACCENT_DARK: RgbColor = { r: 17, g: 24, b: 39 };
|
||||
const MAX_RADIUS = 999;
|
||||
const MAX_FONT_LENGTH = 120;
|
||||
const FONT_FAMILY_PATTERN = /^[A-Za-z0-9 ,'"-]{1,120}$/;
|
||||
/** Toolbar-mode geometry limits; a skin cannot shrink below host minimums. */
|
||||
/** Toolbar-mode geometry limits; only an explicit height may reach 22px. */
|
||||
export const TOOLBAR_MIN_HEIGHT = 22;
|
||||
export const TOOLBAR_DEFAULT_RADIUS = 6;
|
||||
export const TOOLBAR_MAX_RADIUS = 24;
|
||||
export const TOOLBAR_DEFAULT_PADDING_X = 12;
|
||||
@@ -221,9 +242,14 @@ export const TOOLBAR_DEFAULT_PADDING_Y = 6;
|
||||
export const TOOLBAR_MAX_PADDING = 48;
|
||||
export const TOOLBAR_MAX_HEIGHT = 72;
|
||||
export const TOOLBAR_MAX_FONT_SIZE = 20;
|
||||
export const TOOLBAR_DEFAULT_GAP = 4;
|
||||
export const TOOLBAR_MAX_GAP = 16;
|
||||
export const TOOLBAR_DEFAULT_ICON_SIZE = 16;
|
||||
export const TOOLBAR_MIN_ICON_SIZE = 12;
|
||||
export const TOOLBAR_MAX_ICON_SIZE = 24;
|
||||
const MAX_SHADOW_LENGTH = 160;
|
||||
const LENGTH_PX_PATTERN = /^(-?\d+(?:\.\d+)?)px$/i;
|
||||
const PADDING_PATTERN = /^(\d+(?:\.\d+)?)px(?:\s+(\d+(?:\.\d+)?)px)?$/i;
|
||||
const PADDING_PATTERN = /^(0|\d+(?:\.\d+)?px)(?:\s+(0|\d+(?:\.\d+)?px))?$/i;
|
||||
/**
|
||||
* A single box-shadow value: optional `inset`, two to four px offsets/sizes
|
||||
* and one simple colour. `url()`, `var()`, extra shadows and declarations are
|
||||
@@ -289,10 +315,11 @@ export const PERMISSION_CONTROL_DEFAULTS: HostControlDefaults = {
|
||||
},
|
||||
};
|
||||
|
||||
/** Parse `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()`. */
|
||||
export function parseCssColor(value: string | undefined | null): RgbColor | null {
|
||||
/** Parse CSS colours to sRGB channels plus alpha for toolbar transparency checks. */
|
||||
export function parseCssColorWithAlpha(value: string | undefined | null): RgbaColor | null {
|
||||
if (!value) return null;
|
||||
const text = value.trim().toLowerCase();
|
||||
if (text === "transparent") return { r: 0, g: 0, b: 0, a: 0 };
|
||||
const hex = /^#([0-9a-f]{3,8})$/.exec(text);
|
||||
if (hex) {
|
||||
const digits = hex[1];
|
||||
@@ -301,6 +328,7 @@ export function parseCssColor(value: string | undefined | null): RgbColor | null
|
||||
r: Number.parseInt(digits[0] + digits[0], 16),
|
||||
g: Number.parseInt(digits[1] + digits[1], 16),
|
||||
b: Number.parseInt(digits[2] + digits[2], 16),
|
||||
a: digits.length === 4 ? Number.parseInt(digits[3] + digits[3], 16) / 255 : 1,
|
||||
};
|
||||
}
|
||||
if (digits.length === 6 || digits.length === 8) {
|
||||
@@ -308,6 +336,7 @@ export function parseCssColor(value: string | undefined | null): RgbColor | null
|
||||
r: Number.parseInt(digits.slice(0, 2), 16),
|
||||
g: Number.parseInt(digits.slice(2, 4), 16),
|
||||
b: Number.parseInt(digits.slice(4, 6), 16),
|
||||
a: digits.length === 8 ? Number.parseInt(digits.slice(6, 8), 16) / 255 : 1,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
@@ -325,7 +354,30 @@ export function parseCssColor(value: string | undefined | null): RgbColor | null
|
||||
const channel = percent ? parsed * 2.55 : parsed;
|
||||
channels.push(Math.round(Math.min(255, Math.max(0, channel))));
|
||||
}
|
||||
return { r: channels[0], g: channels[1], b: channels[2] };
|
||||
let alpha = 1;
|
||||
if (parts.length === 4) {
|
||||
const rawAlpha = Number.parseFloat(parts[3]);
|
||||
if (!Number.isFinite(rawAlpha)) return null;
|
||||
alpha = parts[3].endsWith("%") ? rawAlpha / 100 : rawAlpha;
|
||||
alpha = Math.min(1, Math.max(0, alpha));
|
||||
}
|
||||
return { r: channels[0], g: channels[1], b: channels[2], a: alpha };
|
||||
}
|
||||
|
||||
/** Parse `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()`. */
|
||||
export function parseCssColor(value: string | undefined | null): RgbColor | null {
|
||||
const color = parseCssColorWithAlpha(value);
|
||||
return color ? { r: color.r, g: color.g, b: color.b } : null;
|
||||
}
|
||||
|
||||
/** Composite a possibly translucent colour over an opaque sRGB surface. */
|
||||
export function compositeRgb(foreground: RgbaColor, background: RgbColor): RgbColor {
|
||||
const alpha = Math.min(1, Math.max(0, foreground.a));
|
||||
return {
|
||||
r: Math.round(foreground.r * alpha + background.r * (1 - alpha)),
|
||||
g: Math.round(foreground.g * alpha + background.g * (1 - alpha)),
|
||||
b: Math.round(foreground.b * alpha + background.b * (1 - alpha)),
|
||||
};
|
||||
}
|
||||
|
||||
export function formatRgb(color: RgbColor): string {
|
||||
@@ -572,10 +624,18 @@ function sanitizeToolbarHeight(value: string | undefined, fallback: number): num
|
||||
if (!match) return fallback;
|
||||
const height = Number.parseFloat(match[1]);
|
||||
return Number.isFinite(height)
|
||||
? Math.min(TOOLBAR_MAX_HEIGHT, Math.max(fallback, height))
|
||||
? Math.min(TOOLBAR_MAX_HEIGHT, Math.max(TOOLBAR_MIN_HEIGHT, height))
|
||||
: fallback;
|
||||
}
|
||||
|
||||
function sanitizeToolbarLength(value: string | undefined, fallback: number, min: number, max: number): number {
|
||||
if (!value) return fallback;
|
||||
const match = LENGTH_PX_PATTERN.exec(value.trim());
|
||||
if (!match) return fallback;
|
||||
const length = Number.parseFloat(match[1]);
|
||||
return Number.isFinite(length) ? Math.min(max, Math.max(min, length)) : fallback;
|
||||
}
|
||||
|
||||
function sanitizeToolbarShadow(value: string | undefined): string | undefined {
|
||||
if (!value) return undefined;
|
||||
const shadow = value.trim().replace(/\s+/g, " ");
|
||||
@@ -595,17 +655,57 @@ export function hasHostToolbarTokens(
|
||||
);
|
||||
}
|
||||
|
||||
function parseToolbarColor(raw: string | undefined, probeColor: ColorProbe): RgbaColor | null {
|
||||
return parseCssColorWithAlpha(raw ? probeColor(raw) : undefined);
|
||||
}
|
||||
|
||||
function formatToolbarColor(color: RgbaColor): string {
|
||||
return color.a === 0 ? "transparent" : formatRgb(color);
|
||||
}
|
||||
|
||||
function resolveToolbarSurface(
|
||||
partTokens: Partial<Record<HostToolbarTokenName, string>>,
|
||||
globalTokens: Partial<Record<HostToolbarTokenName, string>>,
|
||||
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<CSSStyleDeclaration, "getPropertyValue"> | 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-ws-route="webclient" data-ws-page="voice" data-ws-host-skin="community.classic-toolbar-fixture">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Classic recovery toolbar fixture</title>
|
||||
<script>
|
||||
try { localStorage.setItem("webspeak:instance-authorization:v1", JSON.stringify({ schemaVersion: 1, allowed: true })); } catch {}
|
||||
</script>
|
||||
<style>
|
||||
html, body { margin: 0; width: 100%; height: 100%; font: 12px/1.5 system-ui, sans-serif; }
|
||||
.ws-skin-root { position: relative; width: 100vw; height: 100vh; background: #f4f7fb; }
|
||||
#topbar { position: absolute; left: 0; top: 0; right: 0; height: 32px; background: #f4f7fb; }
|
||||
#anchor { position: absolute; left: 40px; top: 5px; width: 320px; height: 22px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ws-skin-root" data-ws-skin="community.classic-toolbar-fixture" data-ws-page="voice" data-ws-part="app">
|
||||
<div id="topbar" data-ws-part="voice.header">
|
||||
<span id="anchor" data-ws-part="skin.voice.topbar.part-host-actions"
|
||||
style="--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;--skin-recovery-toolbar-radius:2px;--skin-recovery-toolbar-font-size:11px;--skin-recovery-toolbar-padding:0 4px;--skin-recovery-toolbar-height:22px;--skin-recovery-toolbar-gap:1px;--skin-recovery-toolbar-icon-size:16px"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="app"></div>
|
||||
<pre id="result" style="position:relative;z-index:5;background:#fff">pending</pre>
|
||||
<script type="module">
|
||||
import { createApp, h, nextTick } from "vue";
|
||||
import HostChrome from "/src/components/HostChrome.vue";
|
||||
import {
|
||||
hostBuiltInSkinRequests,
|
||||
pluginLibraryRequests,
|
||||
setHostChromeActiveSkin,
|
||||
setSkinHostChromeParts,
|
||||
} from "/src/services/host-chrome.ts";
|
||||
import { parseSkinChromeDocument } from "../../../src/shared/skin-chrome.ts";
|
||||
import { hostOwnedLayers } from "/src/services/host-owned-layer.ts";
|
||||
|
||||
const output = document.getElementById("result");
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const isOpen = (element) => Boolean(element?.matches?.(":popover-open"))
|
||||
|| (element ? getComputedStyle(element).display !== "none" : false);
|
||||
|
||||
try {
|
||||
setSkinHostChromeParts(parseSkinChromeDocument(JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
slots: {
|
||||
"host.recovery": {
|
||||
mode: "toolbar",
|
||||
appearance: "icon",
|
||||
anchor: "skin.voice.topbar.part-host-actions",
|
||||
align: "start",
|
||||
},
|
||||
},
|
||||
})));
|
||||
setHostChromeActiveSkin("community.classic-toolbar-fixture");
|
||||
createApp({
|
||||
render: () => h(HostChrome, { language: "en", connected: true, pluginLibraryAvailable: true }),
|
||||
}).mount("#app");
|
||||
|
||||
await nextTick();
|
||||
await sleep(300);
|
||||
|
||||
const layer = hostOwnedLayers().find((entry) => entry.name === "recovery");
|
||||
if (!layer) throw new Error("recovery layer was not created");
|
||||
const toolbar = layer.container.querySelector("[data-ws-host-recovery-toolbar]");
|
||||
const capsule = layer.container.querySelector("[data-ws-host-recovery]");
|
||||
const actions = [...toolbar.querySelectorAll("[data-ws-recovery-action]")];
|
||||
if (actions.length !== 2) throw new Error("expected two toolbar actions");
|
||||
const first = actions[0];
|
||||
const style = getComputedStyle(first);
|
||||
const icon = first.querySelector(".ws-host-toolbar-icon");
|
||||
const iconStyle = getComputedStyle(icon);
|
||||
const firstRect = first.getBoundingClientRect();
|
||||
const hit = document.elementFromPoint(firstRect.left + firstRect.width / 2, firstRect.top + firstRect.height / 2);
|
||||
const builtInBefore = hostBuiltInSkinRequests.value;
|
||||
const libraryBefore = pluginLibraryRequests.value;
|
||||
first.click();
|
||||
actions[1].click();
|
||||
|
||||
const initial = {
|
||||
toolbarOpen: isOpen(toolbar),
|
||||
capsuleOpen: isOpen(capsule),
|
||||
actionCount: actions.length,
|
||||
height: firstRect.height,
|
||||
width: firstRect.width,
|
||||
minHeight: style.minHeight,
|
||||
paddingTop: style.paddingTop,
|
||||
paddingRight: style.paddingRight,
|
||||
paddingBottom: style.paddingBottom,
|
||||
paddingLeft: style.paddingLeft,
|
||||
borderTopWidth: style.borderTopWidth,
|
||||
radius: style.borderTopLeftRadius,
|
||||
fontSize: style.fontSize,
|
||||
background: style.backgroundColor,
|
||||
foreground: style.color,
|
||||
gap: getComputedStyle(toolbar).columnGap,
|
||||
hoverBackground: toolbar.style.getPropertyValue("--ws-toolbar-hover-background"),
|
||||
hoverBorder: toolbar.style.getPropertyValue("--ws-toolbar-hover-border"),
|
||||
iconWidth: icon.getBoundingClientRect().width,
|
||||
iconHeight: icon.getBoundingClientRect().height,
|
||||
iconDisplay: iconStyle.display,
|
||||
iconAriaHidden: icon.getAttribute("aria-hidden"),
|
||||
svgFocusable: icon.querySelector("svg").getAttribute("focusable"),
|
||||
visibleText: actions.map((button) => button.textContent.trim()),
|
||||
accessibleNames: actions.map((button) => button.getAttribute("aria-label")),
|
||||
titles: actions.map((button) => button.getAttribute("title")),
|
||||
groupName: toolbar.getAttribute("aria-label"),
|
||||
hitIsLayerHost: hit === layer.host,
|
||||
builtInClicked: hostBuiltInSkinRequests.value === builtInBefore + 1,
|
||||
libraryClicked: pluginLibraryRequests.value === libraryBefore + 1,
|
||||
};
|
||||
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {
|
||||
key: "r", code: "KeyR", ctrlKey: true, altKey: true, shiftKey: true, bubbles: true, cancelable: true,
|
||||
}));
|
||||
await nextTick();
|
||||
await sleep(100);
|
||||
const capsuleButtons = [...capsule.querySelectorAll("[data-ws-recovery-action]")];
|
||||
const builtInCapsuleStyle = getComputedStyle(capsuleButtons[0]);
|
||||
const shortcut = {
|
||||
capsuleOpen: isOpen(capsule),
|
||||
toolbarOpen: isOpen(toolbar),
|
||||
labels: capsuleButtons.map((button) => button.textContent.trim()),
|
||||
height: capsuleButtons[0].getBoundingClientRect().height,
|
||||
builtInBackground: builtInCapsuleStyle.backgroundColor,
|
||||
builtInForeground: builtInCapsuleStyle.color,
|
||||
focusedAction: layer.shadow.activeElement?.getAttribute?.("data-ws-recovery-action") ?? null,
|
||||
};
|
||||
capsule.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
await nextTick();
|
||||
await sleep(150);
|
||||
const afterEscape = { capsuleOpen: isOpen(capsule), toolbarOpen: isOpen(toolbar) };
|
||||
|
||||
const anchor = document.getElementById("anchor");
|
||||
anchor.style.setProperty("--skin-recovery-toolbar-foreground", "#ffffff");
|
||||
await sleep(700);
|
||||
const invalidStyle = getComputedStyle(first);
|
||||
const invalidTokens = {
|
||||
background: invalidStyle.backgroundColor,
|
||||
foreground: invalidStyle.color,
|
||||
visible: invalidStyle.display !== "none" && invalidStyle.visibility !== "hidden",
|
||||
};
|
||||
|
||||
output.textContent = JSON.stringify({ initial, shortcut, afterEscape, invalidTokens });
|
||||
} catch (error) {
|
||||
output.textContent = JSON.stringify({ error: String(error?.stack ?? error) });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -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]);
|
||||
|
||||
@@ -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(/<pre id="result"[^>]*>([\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);
|
||||
});
|
||||
Reference in new issue
Block a user