From 881354e2839df0b0f69b12f08e1c407c26a68063 Mon Sep 17 00:00:00 2001 From: OddTurtleHead <355182507+OddTurtleHead@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:21:15 +0800 Subject: [PATCH] feat(skin): dock recovery as host-owned toolbar buttons Add chrome.json slot mode "toolbar" with grouped and per-action recovery buttons, page-specific anchor candidates and sanitized toolbar style tokens. Keep the floating capsule as the bad-anchor fallback, hide the duplicate plugin launcher, and preserve legacy capsule slots. Document the full contract, add a minimal toolbar example package, and cover the new behavior in unit and browser tests. --- .../skills/webspeak-skin-development/SKILL.md | 1 + docs/README.en.md | 2 +- docs/README.zh-CN.md | 2 +- docs/SKIN_DEVELOPMENT.md | 116 ++++- docs/examples/HOST-CHROME-TOOLBAR.md | 51 +++ docs/examples/host-chrome-demo.wskin | Bin 3188 -> 3188 bytes docs/examples/host-chrome-themed.wskin | Bin 3095 -> 3095 bytes docs/examples/host-chrome-toolbar.wskin | Bin 0 -> 1774 bytes docs/examples/host-chrome-toolbar/chrome.json | 10 + .../host-chrome-toolbar/manifest.json | 13 + docs/examples/host-chrome-toolbar/skin.css | 96 ++++ package.json | 2 +- src/shared/skin-chrome.ts | 81 +++- src/shared/skin-css.test.ts | 76 +++- src/shared/skin-visual-parts.ts | 11 +- web/public/host-chrome-demo.wskin | Bin 3188 -> 3188 bytes web/public/host-chrome-themed.wskin | Bin 3095 -> 3095 bytes web/public/host-chrome-toolbar.wskin | Bin 0 -> 1774 bytes web/scripts/build-host-chrome-demo-skin.mjs | 29 +- web/src/components/HostChrome.vue | 414 +++++++++++++++--- web/src/components/PluginPanel.vue | 7 +- .../services/host-chrome-visibility.test.ts | 37 ++ web/src/services/host-chrome.ts | 17 + web/src/services/host-control-tokens.test.ts | 150 +++++++ web/src/services/host-control-tokens.ts | 220 ++++++++++ web/src/services/host-owned-layer.ts | 10 +- .../host-recovery-presentation.test.ts | 89 ++++ .../services/host-recovery-presentation.ts | 87 ++++ web/src/services/host-slot-placement.test.ts | 38 ++ web/src/services/host-slot-placement.ts | 81 +++- .../fixtures/host-recovery-legacy-slot.html | 85 ++++ web/test/fixtures/host-recovery-toolbar.html | 252 +++++++++++ web/test/host-chrome-recovery.test.mjs | 152 ++++++- 33 files changed, 2016 insertions(+), 113 deletions(-) create mode 100644 docs/examples/HOST-CHROME-TOOLBAR.md create mode 100644 docs/examples/host-chrome-toolbar.wskin create mode 100644 docs/examples/host-chrome-toolbar/chrome.json create mode 100644 docs/examples/host-chrome-toolbar/manifest.json create mode 100644 docs/examples/host-chrome-toolbar/skin.css create mode 100644 web/public/host-chrome-toolbar.wskin create mode 100644 web/src/services/host-recovery-presentation.test.ts create mode 100644 web/src/services/host-recovery-presentation.ts create mode 100644 web/test/fixtures/host-recovery-legacy-slot.html create mode 100644 web/test/fixtures/host-recovery-toolbar.html diff --git a/.agents/skills/webspeak-skin-development/SKILL.md b/.agents/skills/webspeak-skin-development/SKILL.md index 4378da0..d498c4b 100644 --- a/.agents/skills/webspeak-skin-development/SKILL.md +++ b/.agents/skills/webspeak-skin-development/SKILL.md @@ -25,6 +25,7 @@ When a WebSpeak checkout is unavailable, read the [published skin guide](https:/ - Use component schema v3 and set `minAppVersion` to at least `0.3.2` when using `voice.plugin-launcher`. Place it once in the voice surface, inside a visible slot. Set `options.pluginPresentation` to `drawer-side` for a sidebar, `drawer-below` for a header button, or `dialog` for the default library. The built-in Day, Night and ILLUSIA skins use the header drawer. The KAAK and Discord examples use the sidebar drawer. - Style `voice.plugin-launcher`, `voice.plugin-drawer` and `voice.plugin-drawer.app` through the published parts. WebSpeak owns app availability, pinning, authorization and the app window. Layouts without a usable mount can fall back to the host library. In a connected, authorized voice session verify that the launcher mounts in the intended slot, that the drawer stays within desktop and narrow viewports, and that both pinned and unpinned apps open. For KAAK, verify the rail itself and check the package version served by the instance if the launcher still floats. - For a compact rail, `home.social-links` accepts `options.communityLinks: false` to keep the admin entry and hide community links. The admin console uses host styling. Use `chrome.json#visibleParts` only for documented host decorations. Confirm that the host-owned recovery action remains usable after applying the skin. +- To fold recovery into a skin top bar, declare `chrome.json#slots` with `"mode": "toolbar"` (one grouped entry) or the independent `host.recovery.built-in` / `host.recovery.library` keys. Supply page-specific anchor candidates and `--skin-recovery-toolbar-*` / `--skin-host-toolbar-*` tokens; never target the host toolbar DOM. The host keeps the button labels, click handlers, minimum hit target and floating-capsule fallback, and hides the ordinary plugin launcher so the library has one entry. See [Host chrome toolbar example](../../../docs/examples/HOST-CHROME-TOOLBAR.md). - Test changes to the public home and voice surfaces with the same released archive. Check cold load for a theme flash, long translations for clipping, and live/shared media for artwork layering. Use a real voice session for interaction claims. ## Automatic distribution PR diff --git a/docs/README.en.md b/docs/README.en.md index 2bfb5be..f20b4bb 100644 --- a/docs/README.en.md +++ b/docs/README.en.md @@ -308,7 +308,7 @@ Disable and save the relay configuration to remove the relay option from the wel Skins own appearance, layout and their attached widgets. Administrators install, enable and choose the default skin. Authors use the public contract without changing WebSpeak source code. -[Development guide](./SKIN_DEVELOPMENT.md) · [Agent Skill](../.agents/skills/webspeak-skin-development/SKILL.md) · [Skin catalog](https://github.com/Huddle-Up-Forge/webspeak-skins) · [Discord Voice example](https://github.com/Huddle-Up-Forge/webspeak-skin-discord-voice) +[Development guide](./SKIN_DEVELOPMENT.md) · [Agent Skill](../.agents/skills/webspeak-skin-development/SKILL.md) · [Skin catalog](https://github.com/Huddle-Up-Forge/webspeak-skins) · [Discord Voice example](https://github.com/Huddle-Up-Forge/webspeak-skin-discord-voice) · [Host chrome toolbar example](./examples/HOST-CHROME-TOOLBAR.md) ### Functional plugins `.wplugin` diff --git a/docs/README.zh-CN.md b/docs/README.zh-CN.md index edfa0cb..c481f16 100644 --- a/docs/README.zh-CN.md +++ b/docs/README.zh-CN.md @@ -329,7 +329,7 @@ relay.example.com { 皮肤包负责外观、布局及其附属小组件。管理员可安装、启用和设置默认皮肤;开发时遵循公开接口,无需修改 WebSpeak 源码。 -[开发指南](./SKIN_DEVELOPMENT.md) · [Agent Skill](../.agents/skills/webspeak-skin-development/SKILL.md) · [皮肤索引仓库](https://github.com/Huddle-Up-Forge/webspeak-skins) · [Discord Voice 示例](https://github.com/Huddle-Up-Forge/webspeak-skin-discord-voice) +[开发指南](./SKIN_DEVELOPMENT.md) · [Agent Skill](../.agents/skills/webspeak-skin-development/SKILL.md) · [皮肤索引仓库](https://github.com/Huddle-Up-Forge/webspeak-skins) · [Discord Voice 示例](https://github.com/Huddle-Up-Forge/webspeak-skin-discord-voice) · [宿主顶栏 toolbar 示例](./examples/HOST-CHROME-TOOLBAR.md) ### 功能插件 `.wplugin` diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index 219b624..cb7f6de 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -26,6 +26,8 @@ v3 保留安全的标准元素和属性白名单;组件可通过完整页面 s 可直接查看 [ILLUSIA 风示例源码](examples/illusia-voice/) 与 [示例说明](examples/ILLUSIA-VOICE.md)。它使用本地美术素材和 CSS 完整定制首页、语音房间、成员区、聊天空状态及播放器,同时沿用 WebSpeak 提供的基础翻译;也是管理控制台内置且不可移除的示例皮肤。 +宿主外壳与恢复入口的 toolbar 停靠见 [Host Chrome Toolbar 示例](examples/HOST-CHROME-TOOLBAR.md):它用最小包演示 `mode: "toolbar"`、按页候选锚点、工具栏令牌、应用库去重和坏锚点回退,不包含任何真实服务器或成员数据。 + ## 使用与发布 管理员在 `/admin/skins` 查看三款随 WebSpeak 提供的内置皮肤,并可导入、替换、启用/停用或删除实例自定义皮肤;还可指定访客首次访问时使用的默认皮肤。默认日间、默认夜间和 ILLUSIA 风为受保护内置项,不可替换、停用或移除。访客手动选择的皮肤保存在该浏览器,后续实例默认值变更不会覆盖该明确选择;仅自动套用过旧默认值的浏览器会采用最新实例默认值。皮肤包会缓存在浏览器本地;页面启动时会查询实例目录,目录可用且版本更新时拉取新包。若网络不可用,已缓存的版本仍可使用。 @@ -406,7 +408,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 | 聊天与菜单 | `voice.chat`、`voice.chat.tabs`、`voice.chat.tab`、`voice.chat.heading`、`voice.chat.messages`、`voice.chat.event`、`voice.chat.message`、`voice.chat.message-avatar`、`voice.chat.message-body`、`voice.chat.message-bubble`、`voice.chat.empty`、`voice.chat.composer`、`voice.chat.status`、`voice.context-menu-backdrop`、`voice.context-menu`、`voice.context-menu.header`、`voice.context-menu.move-submenu` | | 屏幕共享 | `voice.screen-share-settings`、`voice.screen-share-settings.heading`、`voice.screen-share-settings.fields`、`voice.screen-share-settings.note`、`voice.screen-share-settings.actions`、`voice.screen-player`、`voice.screen-player.stage`、`voice.screen-player.video`、`voice.screen-player.placeholder`、`voice.screen-player.exit`、`voice.screen-player.viewers`、`voice.screen-player.viewer-avatar`、`voice.screen-player.live`、`voice.screen-player.source`、`voice.screen-player.controls`、`voice.screen-player.volume`、`voice.screen-player.fullscreen` | | `/demo` 演示页 | `demo.header`、`demo.brand`、`demo.header-tools`、`demo.badge`、`demo.skin-switcher`、`demo.language-switcher`、`demo.home-link`、`demo.reconnect`、`demo.reconnect.restore`、`demo.layout`、`demo.channels`、`demo.channels.heading`、`demo.channel`、`demo.channel.select`、`demo.channel.members`、`demo.main`、`demo.hero`、`demo.live`、`demo.hero.title`、`demo.hero.description`、`demo.hero.online`、`demo.wave`、`demo.voice-heading`、`demo.voice-grid`、`demo.voice-card`、`demo.avatar`、`demo.member-name`、`demo.member-status`、`demo.chat.heading`、`demo.chat.tabs`、`demo.chat.tab`、`demo.chat.messages`、`demo.chat.message`、`demo.chat.empty`、`demo.chat.composer`、`demo.chat.input`、`demo.chat.send`、`demo.actions`、`demo.actions.heading`、`demo.action.speaking`、`demo.action.poke`、`demo.action.reconnect`、`demo.note`、`demo.user`、`demo.poke-notification`、`demo.poke.dismiss` | -| 宿主外壳(皮肤根之外 / 宿主固定绘制) | 可主题化:`host.plugins.launcher`、`host.plugins.overlay`、`host.watermark`、`host.hint`、`host.voice-status-decoration`;`host.recovery`(可经 `chrome.json#slots` 停靠,并可用 `--skin-recovery-*` / `--skin-host-*` 令牌换肤)/ `host.permission` 与 `app.skin-load-recovery`(无 CSS 钩子;分别用 `--skin-permission-*` / `--skin-load-recovery-*` 令牌换肤,见下文);`skin.library` 是皮肤菜单里的应用库入口 | +| 宿主外壳(皮肤根之外 / 宿主固定绘制) | 可主题化:`host.plugins.launcher`、`host.plugins.overlay`、`host.watermark`、`host.hint`、`host.voice-status-decoration`;`host.recovery`(可经 `chrome.json#slots` 以胶囊或 `mode: "toolbar"` 的宿主按钮停靠,并可用 `--skin-recovery-*` / `--skin-host-*` 以及 `--skin-recovery-toolbar-*` / `--skin-host-toolbar-*` 令牌换肤)/ `host.permission` 与 `app.skin-load-recovery`(无 CSS 钩子;分别用 `--skin-permission-*` / `--skin-load-recovery-*` 令牌换肤,见下文);`skin.library` 是皮肤菜单里的应用库入口 | | 首页页脚拆分 | `home.footer`(容器,不可隐藏)、`home.footer.decoration`(装饰文案,可隐藏)、`home.footer.clear`(必要链接,受保护) | `voice.member.avatar` 是语音活动区头像;`voice.member.mic-status` 在成员麦克风静音时显示,状态值为 `muted`;`voice.member.action-trigger` 是打开宿主成员操作菜单的按钮,由成员卡片小组件的 `options.memberActions` 控制;`voice.member-row.avatar` 是右侧成员树头像。语音成员列表的动态项提供 `.ws-voice-member-enter-active`、`.ws-voice-member-leave-active`、`.ws-voice-member-enter-from`、`.ws-voice-member-leave-to` 和 `.ws-voice-member-move` 动效钩子,可分别设置加入、离开和排序变化的过渡。状态属性还会使用 `current`、`drag-over`、`dragging`、`self`、`events-empty` 和 `messages-empty`。当前根节点以及屏幕共享播放器、弹窗、菜单都属于同一皮肤作用域。 @@ -453,15 +455,15 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 ### 恢复入口与授权对话框:结构上不可被皮肤触及 -`host.recovery`(恢复入口)与 `host.permission`(授权对话框)是可信宿主控件。它们**不是**可供皮肤选择或直接改写的 CSS 钩子;当前客户端把两者渲染在 `Teleport` 到 `body` 的宿主层里,该层满足下面三条,编译后的皮肤 CSS 无法命中、遮挡或禁用它们。皮肤可以通过下文「受保护控件的主题化」中的受控令牌让它们融入外观,`host.recovery` 还可以通过 `chrome.json#slots` 停靠到皮肤布局: +`host.recovery`(恢复入口)与 `host.permission`(授权对话框)是可信宿主控件。它们**不是**可供皮肤选择或直接改写的 CSS 钩子;当前客户端把两者渲染在 `Teleport` 到 `body` 的宿主层里,该层满足下面三条,编译后的皮肤 CSS 无法命中、遮挡或禁用它们。皮肤可以通过下文「受保护控件的主题化」中的受控令牌让它们融入外观,`host.recovery` 还可以通过 `chrome.json#slots` 停靠到皮肤布局,或声明 `mode: "toolbar"` 后以无胶囊壳的宿主按钮并入皮肤顶栏(见下文「工具栏模式」): 1. **闭合 Shadow DOM**:内容位于 `attachShadow({ mode: "closed" })` 的根内。作者 CSS(无论影子根开或闭)不能跨越 shadow 边界;宿主层元素本身也不带任何 `data-ws-part`,因此连文档级宿主作用域(`:root[data-ws-host-skin="…"] [data-ws-part="host.…"]`)也匹配不到。 2. **顶层(top layer)**:恢复入口是 `popover="manual"`,授权对话框是 `` + `showModal()`。顶层绘制高于所有普通层叠上下文,包括皮肤把某个公开部件写成 `position: fixed; inset: 0; z-index: 2147483647` 的全屏层。 3. **不依赖可主题化浮层**:恢复面板的「使用内置皮肤」直接重置到内置 Day/Night 皮肤,不经过 `host.plugins.overlay`;即使皮肤把该浮层写成 `display: none !important` 或 `pointer-events: none`,重置仍然生效。「应用库」按钮只是一条便利路径,会走常规应用库浮层,因此不是兜底路径。 -**显示规则**:只要当前是第三方(非内置/非官方)皮肤,恢复入口就作为小型常驻胶囊显示在左下角(皮肤可通过下文的 `chrome.json#slots` 申请停靠到自己的锚点);它不是水印或装饰条,官方 Day、Night、ILLUSIA 与 KAAK 皮肤不会自动出现它。对内置/官方皮肤,它只在 `host.plugins.launcher` 被实例配置或 `chrome.json` 声明隐藏、或宿主在已连接状态下检测到启动器被 CSS 隐藏/移出视口/不可点击时作为兜底出现。 +**显示规则**:只要当前是第三方(非内置/非官方)皮肤,恢复入口就作为小型常驻胶囊显示在左下角(皮肤可通过下文的 `chrome.json#slots` 申请停靠到自己的锚点,或用 `mode: "toolbar"` 改成宿主顶栏按钮);它不是水印或装饰条,官方 Day、Night、ILLUSIA 与 KAAK 皮肤不会自动出现它。对内置/官方皮肤,它只在 `host.plugins.launcher` 被实例配置或 `chrome.json` 声明隐藏、或宿主在已连接状态下检测到启动器被 CSS 隐藏/移出视口/不可点击时作为兜底出现。 -**键盘快捷键**:第三方皮肤被允许时,`Ctrl+Alt+Shift+R`(macOS 为 `⌘+⌥+⇧+R`)随时把同一宿主层恢复入口召唤到顶层并聚焦第一个按钮;它不与 WebSpeak 现有快捷键或浏览器常用快捷键冲突。监听器运行在捕获阶段,皮肤或插件脚本提前调用 `preventDefault()` 不会吞掉该组合键。 +**键盘快捷键**:第三方皮肤被允许时,`Ctrl+Alt+Shift+R`(macOS 为 `⌘+⌥+⇧+R`)随时把同一宿主层恢复入口召唤到顶层并聚焦第一个按钮;无论胶囊是停靠、浮动还是被 `mode: "toolbar"` 替换,快捷键都会临时隐藏工具栏并显示完整胶囊。它不与 WebSpeak 现有快捷键或浏览器常用快捷键冲突。监听器运行在捕获阶段,皮肤或插件脚本提前调用 `preventDefault()` 不会吞掉该组合键。 `host.recovery` 与 `host.permission` 这两个名称仅保留为文档/布局元数据中的概念标识,**不对应可被皮肤命中的 DOM 钩子**。当前客户端没有渲染 `host.permission` 元素;授权界面由宿主自己的 `InstanceAuthorization` 对话框绘制,它和恢复胶囊一样位于闭合 Shadow DOM 的顶层。皮肤加载失败的横幅保留 `app.skin-load-recovery` 部件标识(「切换到内置皮肤」),它同样运行在闭合 Shadow DOM 宿主层中。三者都只能通过受保护控件令牌间接换肤,编译后的皮肤 CSS 无法命中或改写它们。`skin.library` 是皮肤菜单里的应用库快捷入口,可作辅助路径,但**不是**兜底。 @@ -469,7 +471,7 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 #### 将恢复入口停靠到皮肤布局(`chrome.json#slots`) -第三方皮肤可以在 `chrome.json` 中用 `slots` 声明一个自己已经拥有的布局锚点,让恢复胶囊停靠在皮肤界面里,而不是固定盖在左下角。胶囊仍然是宿主控件:皮肤只提供锚点部件名和视觉令牌,无法取得它的 DOM、点击处理或 CSS 选择器;未知的 `data-ws-*` 属性仍由生成界面拒绝。内置/官方皮肤没有 `chrome.json`,行为完全不变。 +第三方皮肤可以在 `chrome.json` 中用 `slots` 声明一个自己已经拥有的布局锚点,让恢复入口停靠在皮肤界面里,而不是固定盖在左下角。默认仍是带胶囊壳的恢复胶囊;显式写 `mode: "toolbar"` 时改为无胶囊壳的宿主按钮,可直接并入皮肤顶栏。两种形态都是宿主控件:皮肤只提供锚点部件名和视觉令牌,无法取得它们的 DOM、点击处理或 CSS 选择器;未知的 `data-ws-*` 属性仍由生成界面拒绝。内置/官方皮肤没有 `chrome.json`,行为完全不变。 ```json "slots": { @@ -479,10 +481,11 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 | 字段 | 规则 | | --- | --- | -| 键名 | 目前只接受 `host.recovery`(`src/shared/skin-visual-parts.ts` 的 `HOST_SLOTTABLE_PART_IDS`;后续可加入其他受保护控件)。未知键或未开放控件会被拒绝,错误码为 `SKIN_CHROME_SLOT_INVALID`。 | -| `anchor` | 必填,必须是 `.ws-skin-root` 内已存在的 `data-ws-part` 名称。不能是 `host.*`,也不能是任何可信宿主部件(如 `app`、`voice.connection-status`、`auth.password.*`)。宿主只取第一个可见匹配;锚点不存在、`display:none`、`visibility:hidden`、完全透明、被裁剪、尺寸过小或大部分移出视口时都会回退。 | -| `align` | 可选,`start`、`center` 或 `end`,默认 `end`;胶囊在锚点矩形内按此水平对齐,并垂直居中。 | -| `compact` | 可选布尔值;为 `true` 时停靠后的胶囊折叠为 ◈ 标记,悬停或聚焦后展开。 | +| 键名 | `host.recovery` 表示整组恢复入口(胶囊或 toolbar 组合);`host.recovery.built-in` 与 `host.recovery.library` 表示两个独立按钮,只接受 toolbar 形态。同一份 `chrome.json` 只能二选一:声明了 `host.recovery` 就不能再声明独立按钮键,反之亦然。未知键或未开放控件会被拒绝,错误码为 `SKIN_CHROME_SLOT_INVALID`。 | +| `anchor` | 必填,必须是 `.ws-skin-root` 内已存在的 `data-ws-part` 名称,或 1–8 个候选名称组成的数组(按页面/组件变体排列,重复项自动去重);宿主按顺序取第一个可见匹配,因此同一份声明可同时覆盖首页和语音页。每个候选名最长 240 字符,不能是 `host.*`,也不能是任何可信宿主部件(如 `app`、`voice.connection-status`、`auth.password.*`)。锚点不存在、`display:none`、`visibility:hidden`、完全透明、被裁剪、尺寸过小或大部分移出视口时都会回退。 | +| `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` 或其他字段推断。 | `anchor` 写的是宿主渲染后的完整部件名,而不是组件 id: @@ -490,11 +493,11 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 - v3 组件中带 `part` 的节点:`skin...part-`;按钮、链接、输入、`role="button"` 或绑定了用户事件的可交互节点会渲染为 `skin...control-part-`。推荐在 surface 里放一个专门的非交互空节点并设置稳定的 `part`(例如 `skin.voice.harbor-dock.part-anchor`),避免名称随交互语义变化。 - v4 运行时插件生成的节点:`skin..runtime_plugin___.part-`(同样有 `control-` 变体)。插件 UI 与 `data-ws-skin-mount` 挂载点都位于 `.ws-skin-root` 内,因此也能作为锚点。 -**这不是编译期限制。** `skin.css` 校验器不会因为是否声明 `slots` 而改变,也不会生成额外的隐藏或定位规则;停靠完全由宿主运行时完成。胶囊位于顶层,会挡住它下面的一切,因此宿主还会检查胶囊的占位(按观察到的最大尺寸计算,紧凑模式展开后的宽度也算在内)是否压到了可见的受保护控件(`PROTECTED_PART_IDS`,例如 `voice.audio-dock.microphone`、`voice.audio-dock.output`、`home.footer.clear`、`voice.connection-status.reconnect`);锚点的祖先容器(如包住专用锚点的 `voice.audio-dock`)不算,锚点自身只有在它是或包含可交互控件时才算。压到时同样回退。示例 `host-chrome-demo` 因此把胶囊靠 `start` 对齐在音频栏左侧的说明文字上,避开右侧的麦克风/输出按钮。锚点一旦不可用,胶囊立即回到默认左下角(仍在闭合 Shadow DOM 和顶层,皮肤无法遮挡或隐藏)。为避免闪烁,回退后需要连续 2 次检查都通过才会重新停靠;停靠期间约每 400 ms 复查一次,浮动态保持原来的 1 s 节奏。窗口缩放、滚动和锚点/胶囊尺寸变化都会触发复查。 +**这不是编译期限制。** `skin.css` 校验器不会因为是否声明 `slots` 而改变,也不会生成额外的隐藏或定位规则;停靠完全由宿主运行时完成。胶囊或 toolbar 按钮位于顶层,会挡住它下面的一切,因此宿主还会检查控件的占位(按观察到的最大尺寸计算,紧凑模式展开后的宽度也算在内)是否压到了可见的受保护控件(`PROTECTED_PART_IDS`,例如 `voice.audio-dock.microphone`、`voice.audio-dock.output`、`home.footer.clear`、`voice.connection-status.reconnect`);锚点的祖先容器(如包住专用锚点的 `voice.audio-dock`)不算,锚点自身只有在它是或包含可交互控件时才算。压到时同样回退。示例 `host-chrome-demo` 因此把胶囊靠 `start` 对齐在音频栏左侧的说明文字上,避开右侧的麦克风/输出按钮。锚点一旦不可用,胶囊立即回到默认左下角(仍在闭合 Shadow DOM 和顶层,皮肤无法遮挡或隐藏)。为避免闪烁,回退后需要连续 2 次检查都通过才会重新停靠;停靠期间约每 400 ms 复查一次,浮动态保持原来的 1 s 节奏。窗口缩放、滚动和锚点/胶囊尺寸变化都会触发复查。 **浮动位置的运行时避让。** 没有停靠(未声明 `slots`,或锚点回退)时,恢复胶囊默认在左下角;宿主约每 400 ms(以及每次点击后约 150 ms)检查一次它是否盖住了皮肤里可见、处于最上层的可交互控件(按钮、链接、输入框、`[tabindex]` 自定义按钮、iframe 等;禁用的“发送”按钮也算,透明度为 0 的不算;受保护部件权重最高,其次是打开的对话框/底部弹层里的控件;只因位于皮肤根 `app` 之内的普通按钮不算受保护)。盖住时,胶囊会换到左下、右下、左上、右上、左中、右中、底部居中、顶部居中里遮挡最少的位置,但不会换到鼠标最后所在的位置或当前聚焦的控件上;只有收起能至少让出一个控件时,才收成只显示 ◈ 的紧凑形态(悬停、聚焦或点按展开)。鼠标悬停(触屏上不算残留的悬停)或焦点在胶囊内时不会移动。为避免闪动:遮挡要持续约 250 ms 才移动,两次移动至少相隔 1 s,10 s 内移动超过 6 次就停在默认角落 10 s(期间若默认角落盖住了控件,最多再挪开一次,之后保持不动);判断某个控件是否被盖住时会“看穿”短暂出现的提示条(`app.toast`)和另一个宿主浮动控件,提示条暂时挡住的控件仍按存在计算,不会因此把那个角落误判为空闲;同一页面内,当前位置不遮挡时不会为了回到默认角落而移动(默认角落“看起来空”可能只是被模态对话框的遮罩或提示条暂时挡住);进入或离开语音页、切换皮肤时,宿主会在约 1.5 s 内跳过确认等待和最短间隔、连续复查几次,并在默认角落和当前位置都空闲(鼠标也不在那里)时回到默认角落,免得为上一屏选的位置盖住下一屏新出现的控件。位置计算和 CSS 一样计入 `env(safe-area-inset-*)`(刘海屏、底部手势条)。宿主自带的应用库悬浮按钮(皮肤没有提供 `voice.plugin-launcher` 挂载点时出现在右下角)使用同一套避让,两者也互相避开。这同样只是运行时行为,不新增任何 `skin.css` 编译期限制;皮肤作者无需为它做任何事,但如果希望胶囊固定在设计好的位置,仍建议用 `slots` 停靠。 -**样式令牌**:皮肤可在皮肤根(`:root`)、锚点或锚点的祖先上设置下列普通 `--skin-*` 变量;宿主从锚点(存在时)或活动皮肤根的计算样式读取、校验,再写入闭合 Shadow DOM 内部的宿主变量。没有声明 `slots` 的皮肤也能用这些令牌给浮动态胶囊换肤;锚点仍在 DOM 中时,停靠态和浮动态都会继续使用这些令牌;锚点被移除或隐藏时,宿主读取皮肤根上可继承的值,否则使用默认值。每个 `--skin-recovery-*` 都有全局回退 `--skin-host-<同名>`,`--skin-recovery-*` 优先;只有颜色对比度不达标时整组颜色才回退到宿主默认值。声明了插槽但没写颜色令牌时,胶囊使用不透明的宿主默认色(白底),而不是无插槽时的半透明底。 +**样式令牌**:皮肤可在皮肤根(`:root`)、锚点或锚点的祖先上设置下列普通 `--skin-*` 变量;宿主从锚点(存在时)或活动皮肤根的计算样式读取、校验,再写入闭合 Shadow DOM 内部的宿主变量。没有声明 `slots` 的皮肤也能用这些令牌给浮动态胶囊换肤;锚点仍在 DOM 中时,停靠态和浮动态都会继续使用这些令牌;锚点被移除或隐藏时,宿主读取皮肤根上可继承的值,否则使用默认值。每个 `--skin-recovery-*` 都有全局回退 `--skin-host-<同名>`,`--skin-recovery-*` 优先;只有颜色对比度不达标时整组颜色才回退到宿主默认值。声明了插槽但没写颜色令牌时,胶囊使用不透明的宿主默认色(白底),而不是无插槽时的半透明底。这些胶囊令牌也是 toolbar 颜色的最终回退;toolbar 的圆角、内边距、高度和阴影使用下一节自己的默认值,不会继承胶囊的 999px 圆角或浮动阴影。 | 令牌 | 规则 | | --- | --- | @@ -512,6 +515,74 @@ Wasm 每轮最多读取一次输入并提交一个 UI 输出;首版宿主动 **键盘快捷键**:`Ctrl+Alt+Shift+R`(macOS 为 `⌘+⌥+⇧+R`)在停靠、浮动态和紧凑模式下行为一致:显示完整胶囊并聚焦第一个按钮,焦点离开胶囊后紧凑模式重新生效;它仍在捕获阶段处理,皮肤或插件的 `preventDefault()` 无法吞掉。 +#### 工具栏模式:把恢复按钮并进皮肤顶栏(`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` 只能选一种: + +**组合式**(两个动作共用一个锚点,并排成一组,顺序为先「使用内置皮肤」、后「应用库」): + +```json +"slots": { + "host.recovery": { + "mode": "toolbar", + "anchor": ["home.header", "voice.header"], + "align": "end" + } +} +``` + +**独立式**(每个动作有自己的锚点,可放在顶栏两侧或不同部件上): + +```json +"slots": { + "host.recovery.built-in": { + "anchor": ["home.header-tools", "voice.header-actions"], + "align": "end" + }, + "host.recovery.library": { + "anchor": ["home.header-tools", "voice.header-actions"], + "align": "start" + } +} +``` + +上面只是示意:两个独立按钮若使用同一锚点,应选不同的 `align` 或不同锚点,否则会互相覆盖。 + +规则: + +- `mode` 省略时,`host.recovery` 仍是 `capsule`,旧皮肤行为不变;独立按钮键省略时是 `toolbar`,显式写 `capsule` 会被拒绝。模式必须显式声明,宿主不会从 `compact` 或其他字段推断。 +- `compact` 只适用于胶囊;toolbar 配 `compact` 会被拒绝。toolbar 永远显示完整文字按钮,不会折叠成 ◈。 +- 组合式下「应用库」按钮只在应用库可用(已连接且插件会话就绪)时渲染;「使用内置皮肤」始终渲染。 +- 独立式下每个动作独立停靠:一个锚点失效只把该动作放回浮动胶囊,另一个仍留在工具栏;两个都失效时显示完整浮动胶囊。toolbar 模式下的胶囊永不折叠,因为它是兜底入口而不是设计目标。 +- 回退、抗抖动和复查节奏与胶囊相同:锚点失效立即回退;恢复后需连续 2 次检查通过才重新停靠;停靠时约 400 ms 复查,浮动时约 1 s。 +- 锚点候选数组按顺序取第一个可见项;页面切换、皮肤重载或锚点显隐后会重新解析,不要求重新绑定。 +- 快捷键 `Ctrl+Alt+Shift+R` / `⌘+⌥+⇧+R` 会隐藏工具栏并召唤完整胶囊;关闭(Escape 或焦点离开)后,锚点仍有效的 toolbar 自动恢复。快捷键仍在捕获阶段处理。 +- 按钮的最小命中高度、可见文字、焦点环和指针/键盘操作都由宿主保证;皮肤不能把 toolbar 变成图标按钮、空白按钮或零尺寸按钮。 + +**应用库去重**:只要皮肤声明了 toolbar 形式的恢复入口(组合式的 `host.recovery`,或独立式的 `host.recovery.library`),并且应用库可用,宿主就把工具栏里的「应用库」按钮当作该页唯一的应用库入口,并隐藏普通的 `host.plugins.launcher`。即使锚点失效、入口退回浮动胶囊,启动器仍保持隐藏(胶囊继续提供应用库按钮),避免同一页出现两个入口;应用库不可用时启动器照常显示,工具栏也不渲染该按钮。这个去重只影响 toolbar 声明,不改变普通胶囊皮肤或内置皮肤。 + +**工具栏令牌**:皮肤在皮肤根、锚点或锚点祖先上声明下列普通变量;宿主从每个按钮当前锚点的计算样式读取、校验,再写入闭合 Shadow DOM。每个 `--skin-recovery-toolbar-*` 都有全局回退 `--skin-host-toolbar-*`,前者优先。组合式和独立式按钮共用同一组变量名;由于值按锚点继承,不同页面或不同锚点可以给同一变量不同的值。 + +| 令牌 | 默认与规则 | +| --- | --- | +| `--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-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-shadow` | `none` 或单个简单 `box-shadow`(2–4 个 px 偏移/尺寸加一个颜色,最长 160 字符),默认 `none`。`url()`、`var()`、多个阴影和额外声明一律忽略为 `none`,胶囊阴影不会带入。 | + +无效、透明或不可读的颜色、越界的字号/高度/内边距、皮肤字体和非法阴影都只会回退到可见的宿主默认值,不会隐藏按钮。toolbar 文字由宿主按当前界面语言本地化,长文本换行而不是裁掉;`prefers-reduced-motion` 下同样没有过渡。 + +**旧 slots 兼容**:旧包里的 `{ "anchor": ..., "align": ..., "compact": ... }` 没有 `mode`,仍按胶囊停靠,行为不变;`chrome.json` 的其它字段(`visibleParts`、`hiddenParts`、`icons`)不受影响。只有显式写 `mode: "toolbar"` 才会切换形态。 + +**不影响其它宿主控件**:工具栏令牌只作用于恢复按钮。授权对话框(`--skin-permission-*`)和皮肤加载失败横幅(`--skin-load-recovery-*`)继续使用各自令牌与默认外观;本节的变量不会改变它们。 + #### 受保护控件的主题化 28 个受保护部件里,`host.recovery`、`app.skin-load-recovery` 和授权对话框由宿主在闭合 Shadow DOM 中绘制,`host.permission` 目前没有渲染点;其余 25 个都渲染在 `.ws-skin-root` 内(服务器/频道密码弹窗也在根内,不是 `Teleport`)。开放皮肤(schemaVersion 3/4)可以直接用 `skin.css` 给它们换肤;宿主只保留「不能隐藏 / 不能移出视口 / 不能禁用 / 使用内置皮肤的路径不能被切断」四条底线。 @@ -628,7 +699,28 @@ 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`,值只能包含 `anchor`、`align`、`compact`。详见上文「将恢复入口停靠到皮肤布局」。未知键、指向 `host.*` 或可信宿主部件的锚点会被拒绝。 | +| `slots` | 可选,最多 8 项;键名只能是 `host.recovery`(整组)或 `host.recovery.built-in` / `host.recovery.library`(独立 toolbar 按钮),两种写法互斥。值只能包含 `anchor`、`align`、`compact`、`mode`;`anchor` 可以是单个部件名或最多 8 个候选名的数组。详见上文「将恢复入口停靠到皮肤布局」与「工具栏模式」。未知键、指向 `host.*` 或可信宿主部件的锚点、`toolbar` 配 `compact` 都会被拒绝。 | + +工具栏形态只需在 `host.recovery` 上写 `"mode": "toolbar"`(两个按钮共用一个锚点): + +```json +"slots": { + "host.recovery": { + "mode": "toolbar", + "anchor": ["home.header", "voice.header"], + "align": "end" + } +} +``` + +也可以改用独立按钮键,让两个动作各自停靠: + +```json +"slots": { + "host.recovery.built-in": { "anchor": ["home.header-tools", "voice.header-actions"], "align": "end" }, + "host.recovery.library": { "anchor": ["home.header-tools", "voice.header-actions"], "align": "start" } +} +``` 图标文件约定:仅 PNG / JPG / WebP / AVIF / GIF(**不接受 SVG**),路径必须位于 `assets/icons/` 下且只有一层文件名(不允许 `..`、绝对路径、`\`、`%`、空格或外部 URL)。导入端与服务端登记时都会校验路径、文件是否存在、MIME 是否为位图、单张不超过 64 KiB、总量不超过 512 KiB。宿主把位图编译进皮肤 CSS 的 `background-image`,并隐藏槽内的矢量图形;`url()` 仍走包内资源解析,无法引用外部地址。 diff --git a/docs/examples/HOST-CHROME-TOOLBAR.md b/docs/examples/HOST-CHROME-TOOLBAR.md new file mode 100644 index 0000000..c1511ea --- /dev/null +++ b/docs/examples/HOST-CHROME-TOOLBAR.md @@ -0,0 +1,51 @@ +# 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. + +- Source: [host-chrome-toolbar](./host-chrome-toolbar/) +- Importable package: [host-chrome-toolbar.wskin](./host-chrome-toolbar.wskin) +- 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) + +## Package layout + +```text +host-chrome-toolbar/ + manifest.json # schema v3, 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` 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 + +```json +{ + "schemaVersion": 1, + "slots": { + "host.recovery": { + "mode": "toolbar", + "anchor": ["home.header", "voice.header"], + "align": "end" + } + } +} +``` + +- `mode: "toolbar"` asks the host to render two plain host buttons (use built-in skin, application library) without the capsule shell. +- 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. +- Old slots without `mode` keep the capsule presentation; this example opts in explicitly. + +## 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. + +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-demo.wskin b/docs/examples/host-chrome-demo.wskin index 45f89392899d425ea79e3919d4dc1befee6608aa..881dd48f5b1103ccb05a412da64ad65c7c1a920d 100644 GIT binary patch delta 124 zcmew&@kN3=z?+#xgn@y9gF#^e$S-@WC?M*0m+B#!jp5j^?|HL4&lk`!L0jW88se1 E0H@_3Y5)KL delta 124 zcmew&@kN3=z?+#xgn@y9gF$s8w;3a&>SiZKJrGsMbee@xb+Rq{Vj%gDeLj$Ee$S-@WC?M*0m+B#!jp5j^?|HL4&lk`!L0jW88se1 E0J@eSx&QzG diff --git a/docs/examples/host-chrome-themed.wskin b/docs/examples/host-chrome-themed.wskin index 927d40dbc81b6eda13e9357984fc9ca4d3786f4a..e8c85241f32f288d29549d18de392839f82cf98e 100644 GIT binary patch delta 111 zcmbO(Fb(v8akNY-SR;KdyJ}^MVL;r067oX76Zu^_W3|kg<~F& uJj?+SN#_KS++0>b(v8akNY-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 literal 0 HcmV?d00001 diff --git a/docs/examples/host-chrome-toolbar/chrome.json b/docs/examples/host-chrome-toolbar/chrome.json new file mode 100644 index 0000000..0729373 --- /dev/null +++ b/docs/examples/host-chrome-toolbar/chrome.json @@ -0,0 +1,10 @@ +{ + "schemaVersion": 1, + "slots": { + "host.recovery": { + "mode": "toolbar", + "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 new file mode 100644 index 0000000..09d8263 --- /dev/null +++ b/docs/examples/host-chrome-toolbar/manifest.json @@ -0,0 +1,13 @@ +{ + "schemaVersion": 3, + "packageType": "open-skin", + "id": "community.host-chrome-toolbar", + "name": "Host Chrome Toolbar", + "version": "1.0.0", + "author": "WebSpeak Community", + "license": "AGPL-3.0-only", + "description": "Minimal open skin that docks the trusted recovery actions as host-owned toolbar buttons.", + "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 new file mode 100644 index 0000000..fc54997 --- /dev/null +++ b/docs/examples/host-chrome-toolbar/skin.css @@ -0,0 +1,96 @@ +/* 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]. */ + +:root { + --skin-demo-surface: #13263d; + --skin-demo-foreground: #eef7ff; + --skin-demo-border: #3a628c; + --skin-demo-accent: #47dcc4; + + /* 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; + --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-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; +} + +[data-ws-page] { + color-scheme: dark; + color: #e8f0f8; + background: #09131f; + 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; +} + +/* Voice page can carry a slightly darker value on its own anchor; the host + reads tokens from the anchor that actually docked the button. */ +[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; + } +} + +[data-ws-part="home.join-card"], +[data-ws-part="home.content"] { + color: #e8f0f8; +} + +[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; +} + +[data-ws-part="voice.audio-dock"] { + background: #0f1f33; + border-top: 1px solid #2a4a6a; +} + +[data-ws-part="home.footer"] { + color: #9db5c8; +} + +[data-ws-part="home.footer.clear"] { + color: var(--skin-demo-accent); +} diff --git a/package.json b/package.json index 144cf20..eabb305 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "scripts": { "dev": "tsx src/index.ts", "build": "tsc", - "test": "node --import tsx --test src/admin/security-boundaries.test.ts src/admin/update-routes.test.ts src/updater/version.test.ts src/updater/deployment.test.ts src/updater/archive.test.ts src/updater/code-swap.test.ts src/updater/update-state.test.ts src/updater/update-service.test.ts src/updater/restart-runner.test.ts src/updater/swap-recovery.test.ts src/domain/teamspeak-target.test.ts web/src/voice/member-volume-preferences.test.ts web/src/services/voice-channel-tree.test.ts src/admin/skin-registry.test.ts web/test/skin-store.test.ts src/admin/ts-admin-service.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts scripts/acceleration-poc/target-guard-parity.test.mjs src/server/acceleration-relay.test.ts src/server/visitor-count.test.ts src/server/voice-gateway-auth.test.ts src/server/voice-gateway.test.ts src/server/relay-delegation.integration.test.ts src/persistence/database.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/teamspeak-adapter.test.ts src/server/teamspeak-sdk.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/channel-capacity.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-css.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugin-context.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-workspace.test.mjs web/test/skin-workspace.test.ts web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-content.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-plugin-authoring.test.ts web/src/services/skin-editor-mode.test.ts web/src/services/skin-plugin-approval.test.ts web/src/services/host-editor-top-layer.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/audio-device-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/test/skin-plugin-editor.test.mjs web/src/services/identity-import.test.ts web/src/services/identity-provider.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-runtime-plugin-wasm.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts src/plugins/plugins.test.ts web/test/plugins.integration.test.ts web/src/services/plugin-app-client.test.ts web/src/services/instance-authorization.test.ts web/src/services/host-chrome-visibility.test.ts web/src/services/host-control-tokens.test.ts web/src/services/host-recovery-helpers.test.ts web/src/services/host-slot-placement.test.ts web/src/services/host-floating-placement.test.ts web/test/host-chrome-recovery.test.mjs", + "test": "node --import tsx --test src/admin/security-boundaries.test.ts src/admin/update-routes.test.ts src/updater/version.test.ts src/updater/deployment.test.ts src/updater/archive.test.ts src/updater/code-swap.test.ts src/updater/update-state.test.ts src/updater/update-service.test.ts src/updater/restart-runner.test.ts src/updater/swap-recovery.test.ts src/domain/teamspeak-target.test.ts web/src/voice/member-volume-preferences.test.ts web/src/services/voice-channel-tree.test.ts src/admin/skin-registry.test.ts web/test/skin-store.test.ts src/admin/ts-admin-service.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts scripts/acceleration-poc/target-guard-parity.test.mjs src/server/acceleration-relay.test.ts src/server/visitor-count.test.ts src/server/voice-gateway-auth.test.ts src/server/voice-gateway.test.ts src/server/relay-delegation.integration.test.ts src/persistence/database.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/teamspeak-adapter.test.ts src/server/teamspeak-sdk.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/channel-capacity.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-css.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugin-context.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-workspace.test.mjs web/test/skin-workspace.test.ts web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-content.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-plugin-authoring.test.ts web/src/services/skin-editor-mode.test.ts web/src/services/skin-plugin-approval.test.ts web/src/services/host-editor-top-layer.test.ts web/src/services/host-recovery-presentation.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/audio-device-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/test/skin-plugin-editor.test.mjs web/src/services/identity-import.test.ts web/src/services/identity-provider.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-runtime-plugin-wasm.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts src/plugins/plugins.test.ts web/test/plugins.integration.test.ts web/src/services/plugin-app-client.test.ts web/src/services/instance-authorization.test.ts web/src/services/host-chrome-visibility.test.ts web/src/services/host-control-tokens.test.ts web/src/services/host-recovery-helpers.test.ts web/src/services/host-slot-placement.test.ts web/src/services/host-floating-placement.test.ts web/test/host-chrome-recovery.test.mjs", "verify": "npm test && npm run build && npm run web:build", "skin:harbor:build": "node web/scripts/build-harbor-voice-skin.mjs", "skin:open-voice:build": "node web/scripts/build-open-voice-surface-skin.mjs", diff --git a/src/shared/skin-chrome.ts b/src/shared/skin-chrome.ts index 9e55233..2d2c105 100644 --- a/src/shared/skin-chrome.ts +++ b/src/shared/skin-chrome.ts @@ -18,7 +18,8 @@ import { * - `icons`: bitmap overrides for stable icon slots, keyed by part name. * - `slots`: declarative anchors for trusted host controls. A skin never * receives the control; it only names a part it already renders so the - * host can position its own top-layer capsule there and fall back to the + * host can position its own top-layer capsule (or, with an explicit + * `mode: "toolbar"`, chrome-less host buttons) there and fall back to the * default corner when the anchor stops being usable. * * Both the browser importer and the server-side registry parse the exact same @@ -29,6 +30,7 @@ export const SKIN_CHROME_MAX_BYTES = 32 * 1024; export const SKIN_CHROME_MAX_HIDDEN_PARTS = 32; export const SKIN_CHROME_MAX_ICONS = 16; export const SKIN_CHROME_MAX_SLOTS = 8; +export const SKIN_CHROME_MAX_SLOT_ANCHORS = 8; export const SKIN_ICON_MAX_BYTES = 64 * 1024; export const SKIN_ICONS_MAX_TOTAL_BYTES = 512 * 1024; export const SKIN_ICON_DIRECTORY = "assets/icons/"; @@ -72,13 +74,34 @@ export interface SkinChromeDocument { export type SkinChromeSlotAlign = "start" | "center" | "end"; +/** + * How a slotted recovery control is presented: + * - `capsule` (default): the existing rounded host capsule with its own shell. + * - `toolbar`: independent, chrome-less host buttons that can match a skin's + * top bar. The host still creates the buttons, their labels, focus and + * click handlers; the skin only names anchors and style tokens. + * + * The mode is explicit and never inferred from `compact`: an old slot without + * `mode` keeps docking the capsule exactly as before. + */ +export type SkinChromeSlotMode = "capsule" | "toolbar"; + +/** One anchor name, or ordered candidates (for example one per page). */ +export type SkinChromeSlotAnchor = string | string[]; + export interface SkinChromeSlot { - /** Existing `data-ws-part` inside `.ws-skin-root` used as the anchor box. */ - anchor: string; + /** + * Existing `data-ws-part` inside `.ws-skin-root` used as the anchor box. + * A list lists page/component candidates: the host takes the first visible + * one, so one slot can cover both the home and the voice page. + */ + anchor: SkinChromeSlotAnchor; /** Horizontal alignment inside the anchor; the control is vertically centred. */ align: SkinChromeSlotAlign; - /** Collapse to the mark only until hovered or focused. */ + /** Collapse to the mark only until hovered or focused (capsule mode only). */ compact: boolean; + /** Explicit presentation; see `SkinChromeSlotMode`. */ + mode: SkinChromeSlotMode; } export interface SkinChromeAssetInfo { @@ -147,6 +170,28 @@ function normalizeSlotAnchor(raw: unknown): string { return raw; } +/** + * A slot may name one anchor or an ordered candidate list (one per page or + * per component variant). Candidates are validated exactly like a single + * anchor; duplicates are removed so a page cannot be tried twice per check. + */ +function normalizeSlotAnchors(raw: unknown): SkinChromeSlotAnchor { + if (!Array.isArray(raw)) return normalizeSlotAnchor(raw); + if (!raw.length || raw.length > SKIN_CHROME_MAX_SLOT_ANCHORS) { + return reject(`A slot anchor list must contain between 1 and ${SKIN_CHROME_MAX_SLOT_ANCHORS} part names.`, "SKIN_CHROME_SLOT_INVALID"); + } + const anchors: string[] = []; + for (const entry of raw) { + const anchor = normalizeSlotAnchor(entry); + if (!anchors.includes(anchor)) anchors.push(anchor); + } + return anchors; +} + +function isSlotMode(value: unknown): value is SkinChromeSlotMode { + return value === "capsule" || value === "toolbar"; +} + function isSlotAlign(value: unknown): value is SkinChromeSlotAlign { return value === "start" || value === "center" || value === "end"; } @@ -226,20 +271,42 @@ 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") { + if (key !== "anchor" && key !== "align" && key !== "compact" && key !== "mode") { return reject(`Slot ${part} contains an unsupported field: ${key}.`, "SKIN_CHROME_SLOT_INVALID"); } } - const anchor = normalizeSlotAnchor(value.anchor); + const anchor = normalizeSlotAnchors(value.anchor); const align = value.align === undefined ? "end" : value.align; if (!isSlotAlign(align)) { return reject(`Slot ${part} has an invalid align value: ${String(align)}.`, "SKIN_CHROME_SLOT_INVALID"); } + // The group slot keeps the historical capsule default. The two + // single-action slots only exist for toolbar presentation; a one-button + // capsule would be a new, ambiguous surface with no product need. + const mode = value.mode === undefined + ? (part === "host.recovery" ? "capsule" : "toolbar") + : value.mode; + if (!isSlotMode(mode)) { + return reject(`Slot ${part} has an invalid mode value: ${String(mode)}.`, "SKIN_CHROME_SLOT_INVALID"); + } + if (part !== "host.recovery" && mode !== "toolbar") { + return reject(`Slot ${part} only supports toolbar mode.`, "SKIN_CHROME_SLOT_INVALID"); + } const compact = value.compact === undefined ? false : value.compact; if (typeof compact !== "boolean") { return reject(`Slot ${part} compact must be a boolean.`, "SKIN_CHROME_SLOT_INVALID"); } - slots[part] = { anchor, align, compact }; + 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 perAction = slots["host.recovery.built-in"] !== undefined || slots["host.recovery.library"] !== undefined; + if (slots["host.recovery"] && perAction) { + return reject( + "Declare either host.recovery or its per-action slots (host.recovery.built-in / host.recovery.library), not both.", + "SKIN_CHROME_SLOT_INVALID", + ); } } diff --git a/src/shared/skin-css.test.ts b/src/shared/skin-css.test.ts index 693438b..08deac4 100644 --- a/src/shared/skin-css.test.ts +++ b/src/shared/skin-css.test.ts @@ -197,7 +197,11 @@ test("chrome.json declares hidden parts and icon bitmaps, with path and size val }); test("chrome.json slots accept skin-owned anchors and reject trusted host UI", () => { - assert.deepEqual([...HOST_SLOTTABLE_PART_IDS], ["host.recovery"]); + assert.deepEqual([...HOST_SLOTTABLE_PART_IDS], [ + "host.recovery", + "host.recovery.built-in", + "host.recovery.library", + ]); const explicit = parseSkinChromeDocument(JSON.stringify({ schemaVersion: 1, @@ -209,10 +213,11 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( anchor: "voice.audio-dock", align: "start", compact: true, + mode: "capsule", }); - // Defaults: align "end", compact off. Component and runtime-plugin parts are - // ordinary anchors; only host/trusted parts are off limits. + // Old slots without `mode` keep the docked capsule: the presentation is + // explicit, never inferred from compact or any other field. const defaults = parseSkinChromeDocument(JSON.stringify({ schemaVersion: 1, slots: { @@ -223,6 +228,7 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( anchor: "skin.voice.harbor-dock.part-anchor", align: "end", compact: false, + mode: "capsule", }); assert.doesNotThrow(() => parseSkinChromeDocument(JSON.stringify({ schemaVersion: 1, @@ -246,6 +252,70 @@ test("chrome.json slots accept skin-owned anchors and reject trusted host UI", ( [{ schemaVersion: 1, slots: { "host.recovery": { anchor: "../escape" } } }, /not a valid part name/], [{ 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", 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/], + ]; + for (const [value, message] of invalidDocuments) { + assert.throws(() => parseSkinChromeDocument(JSON.stringify(value)), message, JSON.stringify(value)); + } +}); + +test("chrome.json toolbar slots support page candidates and separate action buttons", () => { + const toolbar = parseSkinChromeDocument(JSON.stringify({ + schemaVersion: 1, + slots: { + "host.recovery": { + mode: "toolbar", + anchor: [ + "skin.home.topbar.part-host-actions", + "skin.voice.topbar.part-host-actions", + "skin.home.topbar.part-host-actions", + ], + align: "end", + }, + }, + })); + assert.deepEqual(toolbar.slots?.["host.recovery"], { + anchor: [ + "skin.home.topbar.part-host-actions", + "skin.voice.topbar.part-host-actions", + ], + align: "end", + compact: false, + mode: "toolbar", + }); + + const perAction = parseSkinChromeDocument(JSON.stringify({ + schemaVersion: 1, + slots: { + "host.recovery.built-in": { + mode: "toolbar", + anchor: "skin.voice.topbar.part-built-in", + align: "start", + }, + "host.recovery.library": { + mode: "toolbar", + anchor: "skin.voice.topbar.part-library", + }, + }, + })); + assert.deepEqual(perAction.slots?.["host.recovery.built-in"], { + anchor: "skin.voice.topbar.part-built-in", + align: "start", + compact: false, + mode: "toolbar", + }); + // 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"); + + const invalidDocuments: Array<[unknown, RegExp]> = [ + [{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: [] } } }, /between 1 and 8/], + [{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: Array.from({ length: 9 }, (_, index) => `part-${index}`) } } }, /between 1 and 8/], + [{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: ["voice.audio-dock", "host.plugins.launcher"] } } }, /trusted host UI/], + [{ schemaVersion: 1, slots: { "host.recovery": { mode: "toolbar", anchor: "voice.audio-dock" }, "host.recovery.built-in": { mode: "toolbar", anchor: "voice.audio-dock" } } }, /either host.recovery or its per-action slots/], ]; for (const [value, message] of invalidDocuments) { assert.throws(() => parseSkinChromeDocument(JSON.stringify(value)), message, JSON.stringify(value)); diff --git a/src/shared/skin-visual-parts.ts b/src/shared/skin-visual-parts.ts index 853546d..8f7da34 100644 --- a/src/shared/skin-visual-parts.ts +++ b/src/shared/skin-visual-parts.ts @@ -47,11 +47,18 @@ export const HOST_TRUSTED_PART_IDS: ReadonlySet = new Set([ * Trusted host controls that an open skin may fold into its own layout through * `chrome.json#slots`. The key names the protected part, not a CSS hook: the * skin only declares an anchor rectangle, the host still owns, paints and - * hit-tests the control. Extend this set (for example with `host.permission`) - * when another protected control learns the same runtime placement. + * hit-tests the control. + * + * `host.recovery` is the historical capsule group. The two action keys only + * exist for `mode: "toolbar"` and let a skin dock the "use built-in skin" and + * "application library" host buttons separately; they are still host-owned + * buttons, never DOM hooks. Extend this set when another protected control + * learns the same runtime placement. */ export const HOST_SLOTTABLE_PART_IDS: ReadonlySet = new Set([ "host.recovery", + "host.recovery.built-in", + "host.recovery.library", ]); /** All host-owned parts (used by the part registry and documentation). */ diff --git a/web/public/host-chrome-demo.wskin b/web/public/host-chrome-demo.wskin index 45f89392899d425ea79e3919d4dc1befee6608aa..881dd48f5b1103ccb05a412da64ad65c7c1a920d 100644 GIT binary patch delta 124 zcmew&@kN3=z?+#xgn@y9gF#^e$S-@WC?M*0m+B#!jp5j^?|HL4&lk`!L0jW88se1 E0H@_3Y5)KL delta 124 zcmew&@kN3=z?+#xgn@y9gF$s8w;3a&>SiZKJrGsMbee@xb+Rq{Vj%gDeLj$Ee$S-@WC?M*0m+B#!jp5j^?|HL4&lk`!L0jW88se1 E0J@eSx&QzG diff --git a/web/public/host-chrome-themed.wskin b/web/public/host-chrome-themed.wskin index 927d40dbc81b6eda13e9357984fc9ca4d3786f4a..e8c85241f32f288d29549d18de392839f82cf98e 100644 GIT binary patch delta 111 zcmbO(Fb(v8akNY-SR;KdyJ}^MVL;r067oX76Zu^_W3|kg<~F& uJj?+SN#_KS++0>b(v8akNY-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 literal 0 HcmV?d00001 diff --git a/web/scripts/build-host-chrome-demo-skin.mjs b/web/scripts/build-host-chrome-demo-skin.mjs index f9c1135..e3917ed 100644 --- a/web/scripts/build-host-chrome-demo-skin.mjs +++ b/web/scripts/build-host-chrome-demo-skin.mjs @@ -3,8 +3,11 @@ import { deflateSync } from "node:zlib"; import { zipSync, strToU8 } from "fflate"; const source = new URL("../../docs/examples/host-chrome-demo/", import.meta.url); +const toolbarSource = new URL("../../docs/examples/host-chrome-toolbar/", import.meta.url); const examples = new URL("../../docs/examples/", import.meta.url); const publicDir = new URL("../public/", import.meta.url); +// Keep rebuilt archives byte-stable when their inputs do not change. +const archiveMtime = new Date(2026, 10, 15, 16, 33, 0); const crcTable = (() => { const table = new Uint32Array(256); @@ -66,12 +69,20 @@ const icons = { "assets/icons/status.png": iconPng([150, 60, 90], [84, 28, 52]), }; -const [manifestText, cssText, chromeText] = await Promise.all([ +const [manifestText, cssText, chromeText, toolbarManifestText, toolbarCssText, toolbarChromeText] = await Promise.all([ readFile(new URL("manifest.json", source), "utf8"), readFile(new URL("skin.css", source)), readFile(new URL("chrome.json", source), "utf8"), + readFile(new URL("manifest.json", toolbarSource), "utf8"), + readFile(new URL("skin.css", toolbarSource)), + readFile(new URL("chrome.json", toolbarSource), "utf8"), ]); +const toolbarManifest = JSON.parse(toolbarManifestText); +if (toolbarManifest.author !== "WebSpeak Community") { + throw new Error("host-chrome-toolbar manifest author must be WebSpeak Community"); +} + const chrome = JSON.parse(chromeText); const sharedFiles = { "skin.css": new Uint8Array(cssText), @@ -85,20 +96,30 @@ const themed = zipSync({ "manifest.json": strToU8(themedManifest), "chrome.json": strToU8(themedChrome), ...sharedFiles, -}, { level: 9 }); +}, { level: 9, mtime: archiveMtime }); // Variant B: the same package plus declarative hiding of non-critical chrome. const hidden = zipSync({ "manifest.json": strToU8(manifestText), "chrome.json": strToU8(chromeText), ...sharedFiles, -}, { level: 9 }); +}, { level: 9, mtime: archiveMtime }); + +// Minimal toolbar-mode sample: host-owned recovery buttons docked into the +// header, with page-wide anchor candidates and toolbar tokens. +const toolbar = zipSync({ + "manifest.json": strToU8(toolbarManifestText), + "chrome.json": strToU8(toolbarChromeText), + "skin.css": new Uint8Array(toolbarCssText), +}, { level: 9, mtime: archiveMtime }); await Promise.all([ writeFile(new URL("host-chrome-themed.wskin", examples), themed), writeFile(new URL("host-chrome-demo.wskin", examples), hidden), + writeFile(new URL("host-chrome-toolbar.wskin", examples), toolbar), writeFile(new URL("host-chrome-themed.wskin", publicDir), themed), writeFile(new URL("host-chrome-demo.wskin", publicDir), hidden), + writeFile(new URL("host-chrome-toolbar.wskin", publicDir), toolbar), ]); -console.log(`Built host chrome demo skins (${themed.byteLength} / ${hidden.byteLength} bytes) into docs/examples and web/public.`); +console.log(`Built host chrome demo skins (${themed.byteLength} / ${hidden.byteLength} / ${toolbar.byteLength} bytes) into docs/examples and web/public.`); diff --git a/web/src/components/HostChrome.vue b/web/src/components/HostChrome.vue index c44d765..93f2806 100644 --- a/web/src/components/HostChrome.vue +++ b/web/src/components/HostChrome.vue @@ -28,8 +28,77 @@ + `data-ws-part`: there is intentionally no skin hook for this control. + + With an explicit `chrome.json` `mode: "toolbar"` the host paints plain + host buttons instead of the capsule shell. The buttons are still owned, + labelled, focusable and clickable by the host; the skin only supplies + an anchor and style tokens. --> + +
+ + +
+ + +
+ +
+ +
+ +
+
+
+ + +
+
pending
+ + + diff --git a/web/test/host-chrome-recovery.test.mjs b/web/test/host-chrome-recovery.test.mjs index 09318b8..614543f 100644 --- a/web/test/host-chrome-recovery.test.mjs +++ b/web/test/host-chrome-recovery.test.mjs @@ -55,7 +55,7 @@ const scenarios = [ ]; test("host chrome renders recovery and authorization in a closed-shadow top layer", async () => { - const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice, slotPlacement] = await Promise.all([ + const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice, slotPlacement, pluginPanel, presentation, controlTokens] = await Promise.all([ read("../src/components/HostChrome.vue"), read("../src/components/InstanceAuthorization.vue"), read("../src/services/host-owned-layer.ts"), @@ -63,6 +63,9 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye read("../src/composables/usePublicSkin.ts"), read("../src/components/SkinLoadRecoveryNotice.vue"), read("../src/services/host-slot-placement.ts"), + read("../src/components/PluginPanel.vue"), + read("../src/services/host-recovery-presentation.ts"), + read("../src/services/host-control-tokens.ts"), ]); // Recovery: closed shadow root + manual popover + no skin hook. @@ -86,6 +89,28 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye assert.match(hostChrome, /activeHostSlot\("host\.recovery"\)/); assert.match(hostChrome, /bindHostSlot\(/); assert.match(hostChrome, /onModeChange/); + // Explicit toolbar presentation: plain host buttons, no capsule shell, real + // host click handlers and i18n labels. The mode is a separate schema field, + // not inferred from compact. + assert.match(hostChrome, /activeHostSlot\("host\.recovery\.built-in"\)/); + assert.match(hostChrome, /activeHostSlot\("host\.recovery\.library"\)/); + assert.match(hostChrome, /presentation: "toolbar"/); + assert.match(hostChrome, /resolveHostRecoveryPresentation/); + assert.match(hostChrome, /class="ws-host-toolbar-action"/); + 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\(/); + assert.match(presentation, /suppressLauncher/); + assert.match(hostChrome, /setInlineLibraryEntryVisible/); + assert.match(pluginPanel, /isInlineLibraryEntryVisible/); + assert.match(pluginPanel, /!inlineLibraryEntry/); + // Toolbar tokens are sanitized by the same shared reader with their own + // geometry defaults; no capsule shadow/radius/pale fixed background. + assert.match(controlTokens, /HOST_TOOLBAR_TOKEN_NAMES/); + assert.match(controlTokens, /resolveHostControlToolbarTokens/); + assert.match(slotPlacement, /applyHostControlToolbarTokens/); + assert.match(slotPlacement, /resolveHostControlToolbarTokens/); + assert.match(slotPlacement, /presentation === "toolbar"/); assert.match(slotPlacement, /querySelectorAll\("\.ws-skin-root"\)/); assert.match(slotPlacement, /isHostPartReachable\(/); assert.match(slotPlacement, /evaluateSlottedControl/); @@ -491,3 +516,128 @@ test("host control tokens follow late skin CSS, resolve modern colours and refus assert.notEqual(resized.inlineBackground, resized.beforeResize, "a viewport change did not refresh @media tokens"); assert.equal(byName["after-dispose"].inlineBackground, late.inlineBackground, "a disposed binding kept observing the document"); }); + +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, + 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 run = async (windowSize) => { + const dom = await dumpDom( + `http://127.0.0.1:${port}/test/fixtures/host-recovery-toolbar.html`, + ["--virtual-time-budget=30000", `--window-size=${windowSize}`], + ); + const match = dom.match(/
]*>([\s\S]*?)<\/pre>/);
+    assert.ok(match, "the toolbar fixture did not emit a result block");
+    return JSON.parse(match[1].replace(/"/g, '"').replace(/&/g, "&"));
+  };
+
+  const payload = await run("1280,800");
+  assert.equal(payload.error, undefined, payload.error);
+
+  const initial = payload.initial;
+  assert.equal(initial.toolbarOpen, true, "the toolbar did not dock into the declared anchor");
+  assert.equal(initial.insideAnchor, true, "the toolbar is not placed inside the page anchor");
+  assert.equal(initial.insideViewport, true);
+  assert.equal(initial.actionCount, 2, "the group slot must render both independent host buttons");
+  assert.deepEqual(initial.labels, ["Integrierten Skin verwenden", "Anwendungsbibliothek"]);
+  assert.equal(initial.capsuleOpen, false, "the capsule shell must not be shown next to a docked toolbar");
+  assert.equal(initial.background, "rgb(16, 32, 48)", "toolbar background token was not applied");
+  assert.equal(initial.foreground, "rgb(255, 255, 255)", "toolbar foreground token was not applied");
+  assert.equal(initial.border, "rgb(71, 220, 196)", "toolbar border token was not applied");
+  assert.equal(initial.radius, "8px", "toolbar radius token was not applied");
+  assert.equal(initial.fontSize, "14px", "toolbar font-size token was not applied");
+  assert.equal(initial.minHeight, "36px", "toolbar height token was not applied");
+  assert.equal(initial.shadow, "none", "the capsule shadow must not leak into toolbar mode");
+  assert.equal(initial.clickable, true);
+  assert.equal(initial.launcherSuppressed, true, "the host library button must replace the ordinary launcher");
+  assert.equal(payload.builtInClicked, true, "clicking the toolbar button must run the host reset action");
+  assert.equal(payload.libraryClicked, true, "clicking the toolbar library button must reach the host handler");
+
+  for (const lang of ["de", "ru", "ja"]) {
+    const entries = payload.languages[lang];
+    assert.equal(entries.length, 2, `${lang}: both host buttons must stay rendered`);
+    for (const entry of entries) {
+      assert.ok(entry.text && entry.text.length > 0, `${lang}: button lost its visible label`);
+      assert.equal(entry.visible, true, `${lang}: button is not visible`);
+      assert.equal(entry.inViewport, true, `${lang}: button escaped the viewport`);
+      assert.ok(entry.height >= 28, `${lang}: button fell below the host hit target (${entry.height})`);
+    }
+  }
+
+  assert.equal(payload.afterSwitch.toolbarOpen, true, "the toolbar did not survive the home -> voice page switch");
+  assert.equal(payload.afterSwitch.insideVoiceAnchor, true, "the toolbar stayed on the previous page anchor");
+  assert.equal(payload.afterSwitch.resolvedVoice, "voice-anchor", "the candidate list did not resolve the voice anchor");
+
+  assert.equal(payload.fallback.toolbarOpen, false, "the toolbar stayed visible with a broken anchor");
+  assert.equal(payload.fallback.capsuleVisible, true, "no visible floating recovery entry after the anchor failed");
+  assert.deepEqual(payload.fallback.capsuleActions, ["built-in", "library"]);
+  assert.equal(payload.fallback.launcherSuppressed, true, "the fallback capsule must keep exactly one library entry");
+
+  assert.equal(payload.redocked.toolbarOpen, true, "the toolbar did not re-dock after the anchor returned");
+  assert.equal(payload.redocked.insideVoiceAnchor, true);
+  assert.equal(payload.redocked.capsuleOpen, false);
+
+  assert.equal(payload.shortcut.capsuleOpen, true, "the shortcut did not summon the recovery capsule");
+  assert.equal(payload.shortcut.toolbarOpen, false, "the docked toolbar must yield to the summoned capsule");
+  assert.equal(payload.shortcut.focusedAction, "built-in", "the shortcut did not focus the first host button");
+  assert.deepEqual(payload.shortcut.capsuleActions, ["built-in", "library"]);
+  assert.equal(payload.afterEscape.capsuleOpen, false);
+  assert.equal(payload.afterEscape.toolbarOpen, true, "closing the shortcut did not restore the docked toolbar");
+
+  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.foreground, "rgb(49, 82, 79)");
+  assert.equal(payload.invalidTokens.shadow, "none", "the invalid shadow token must not be applied");
+
+  // Narrow viewport: long labels wrap inside the viewport and stay tappable.
+  const narrow = await run("320,640");
+  assert.equal(narrow.error, undefined, narrow.error);
+  assert.equal(narrow.initial.toolbarOpen, true, JSON.stringify(narrow.initial));
+  assert.equal(narrow.initial.insideViewport, true, JSON.stringify(narrow.initial.rect));
+  assert.equal(narrow.initial.actionCount, 2);
+  for (const entry of narrow.languages.de) {
+    assert.equal(entry.visible, true);
+    assert.equal(entry.inViewport, true, JSON.stringify(entry.rect));
+    assert.ok(entry.height >= 28, JSON.stringify(entry));
+  }
+});
+
+test("legacy slots without a mode still dock the capsule", { 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-legacy-slot.html`,
+    ["--virtual-time-budget=10000", "--window-size=1280,800"],
+  );
+  const match = dom.match(/
]*>([\s\S]*?)<\/pre>/);
+  assert.ok(match, "the legacy slot fixture did not emit a result block");
+  const payload = JSON.parse(match[1].replace(/"/g, '"').replace(/&/g, "&"));
+  assert.equal(payload.error, undefined, payload.error);
+  assert.equal(payload.capsuleOpen, true, "an old slot without mode must keep the capsule presentation");
+  assert.equal(payload.toolbarRendered, false, "an old slot must not grow a toolbar");
+  assert.equal(payload.insideAnchor, true, "the capsule did not dock into the legacy anchor");
+  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.equal(payload.clicked, true);
+});