@linxin666/dsh-client-ui-skin-center 0.4.12 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +8 -2
- package/README.zh.md +8 -2
- package/contracts/semantic-attrs-v1.md +12 -2
- package/lib/client.js +1 -1
- package/lib/css-safety-worker.js +100 -0
- package/lib/css-safety.js +825 -0
- package/lib/index.js +507 -781
- package/package.json +2 -1
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: d8abf9358dcbefa36d2eba30bdf4c7583795d178
|
|
6
|
+
README.zh.md: beab21fa090b8da4a8dde844e098b201d00543c4
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ English | [中文](README.zh.md)
|
|
|
21
21
|
- Custom theme: the final card is a user-level theme derived from the official stock look, separate from both the official-default card and catalog skins. Light and dark profiles independently edit accent, background, foreground and contrast (0–100), with live try-on, apply, current-mode reset and reload persistence. Its generated CSS is limited to an audited official-token allowlist; it cannot accept selectors, arbitrary CSS or asset URLs. Catalog skin definitions are never modified, and an active catalog skin automatically suppresses the custom-theme layer.
|
|
22
22
|
- Try-on / Apply: both go through the same atomic switch engine (`src/client/runtime/skin-controller.ts`). One switch is one new activation identity: fetch the scoped stylesheet, install it plus the background media and optional hooks, flip `html[data-dsh-skin="<id>"]`, then dispose the previous activation (append-only effect ledger, idempotent teardown). The latest request always wins; a failed or superseded switch leaves the previous skin fully intact. Try-on is the same switch without persistence — "Exit try-on" restores the committed skin. Apply persists the selection (`POST /api/skin-center/v2/active`). No page reload, no `cordis.patch.yml` rewrite, no boot-graph regeneration.
|
|
23
23
|
- First paint: the host half registers one index.html transform (`webServer.tapIndex`, single adapter module `src/tap-index-adapter.ts`) that stamps `html[data-dsh-skin]` and inserts the stylesheet links into every served document, so a reload boots straight into the active skin with no flash of the stock look. The tap fails closed to the stock look on any problem.
|
|
24
|
-
- Skin format (v2): `skin.json` (validated fail-closed, v1 fields `package`/`wiring`/`bodyAttr` ignored with migration warnings), `skin.css` (L1 token remaps + L2 semantic selectors), optional `patches.css` (L3 free selectors, high sensitivity), optional `hooks.mjs` (trusted escape hatch, high sensitivity), `assets/`, `preview/`. All CSS passes the safety pipeline
|
|
24
|
+
- Skin format (v2): `skin.json` (validated fail-closed, v1 fields `package`/`wiring`/`bodyAttr` ignored with migration warnings), `skin.css` (L1 token remaps + L2 semantic selectors), optional `patches.css` (L3 free selectors, high sensitivity), optional `hooks.mjs` (trusted escape hatch, high sensitivity), `assets/`, `preview/`. All CSS passes the safety pipeline: every selector is force-scoped under `html[data-dsh-skin]`, `@import` / remote or protocol-relative URLs / escaping paths are hard errors. The host half never loads the CSS parser itself — every transform runs in a short-lived worker process (`src/core/css-safety/host-transform.ts` + `worker-entry.ts`) that is forked per request and has exited before the stylesheet response completes, so the host process never maps the parser's native addon. See `contracts/README.md`.
|
|
25
25
|
- Coverage contract: L1 remaps the official `--dsw-*` design tokens; L2 styles the semantic attributes (`data-dsh-surface` / `data-dsh-part` / `data-dsh-plugin`, enumeration in `contracts/semantic-attrs-v1.md`) which a compat adapter (`src/client/runtime/semantic-adapter.ts`) stamps onto the official shell DOM from stable anchors (`data-slot` outlets, `data-chat-flow-kind`, etc.); L3 patches carry any selector at the skin author's own risk. Plugins that output the semantic attributes themselves get the full L2 coverage; plugins that do not only get L1. A shared shell-rendering adapter applies only while a catalog skin or a custom theme is active: it removes the workspace-list end fade, gives the composer placeholder an opaque theme-secondary text color, and reserves bottom clearance on conversation scrollports so messages remain readable above the sticky composer (#978), so individual skins do not need duplicate patches.
|
|
26
26
|
- Background priority: while a wallpaper renders, the skin and its background media stand down entirely (see "Wallpaper Engine"), so the wallpaper always has the backdrop to itself; otherwise the skin's manifest background media is the backdrop.
|
|
27
27
|
- Background controls: a background-occlusion slider (0–100%) veils the backdrop behind the panels for skins that paint one, two per-state Gaussian-blur sliders (0–20 px) control the backdrop for empty and populated conversations, an input-card blur slider (0–20 px) controls only the frosted area behind the composer, and a bubble-opacity slider (0–100%) drives translucent message bubbles for skins that expose bubble alpha. The active background blur uses a fixed `backdrop-filter` element behind the shell; 0 disables it entirely (no element, no GPU cost). The input-card frost rides its own body-level fixed follower (the `data-dsh-composer-frost` element) sized to the composer card, never the card itself: a `backdrop-filter` on the card would make it the containing block for the shell's fixed tooltips inside it and jolt the conversation on every hover.
|
|
@@ -143,6 +143,10 @@ The skin center reads the plugin's markers and never writes them, and the plugin
|
|
|
143
143
|
|
|
144
144
|
- All `/api/skin-center/*` routes are same-origin only: writes reject cross-site requests (Sec-Fetch-Site / Origin fence), and asset reads are contained inside each skin directory (path escapes fail closed).
|
|
145
145
|
- Skin CSS is sanitized (whitelist) before serving; `patches.css` (L3) is arbitrary CSS by design and disclosed as such — it runs with full page styling power and is not a security boundary.
|
|
146
|
+
- The CSS safety pipeline runs in a short-lived worker process, one worker per request, and the worker has exited before the stylesheet response is written. The host process therefore never loads the CSS parser and never maps its native addon, which is what lets a package manager replace the parser package while the host runs (issue #98).
|
|
147
|
+
- The pipeline belongs to one plugin mount: the mount creates it, injects it into the routes and disposes it with the mount. A remount therefore gets its own pipeline, and tearing down the old mount never disables the new one.
|
|
148
|
+
- The pipeline holds at most eight requests in total, the running one and the waiting ones alike. A request beyond that cap is refused at once with `503 css-transform-overloaded`; a whitelist violation is still `422`, every other transform failure is still `500`.
|
|
149
|
+
- No request can hang: every request carries a ten-second budget that also covers a worker that answered but refuses to exit, and a worker that cannot be started fails the request immediately instead of waiting for the budget.
|
|
146
150
|
- The custom-theme editor emits only fixed declarations from `CUSTOM_THEME_ALLOWED_TOKENS`, each verified against the official token registry. User input is normalized color/contrast data and never becomes a selector, URL or free-form CSS payload.
|
|
147
151
|
- `hooks.mjs` is trusted code that shares this repository's review and release; it is served same-origin only and its import/apply errors can never take the static skin down. Hooks run for built-in skins and for user-directory skins whose executable identity is byte-verified as reviewed official-market content: current Workshop installs use `dsh-market.provenance.json`, while legacy pre-provenance installs must match the generated `src/reviewed-hooks.generated.ts` identity for id, declared entry, complete `skin.json`, and hooks bytes (verified by `src/provenance.ts`, issue #1073). The fallback is read-only and offline; any modified, renamed, hand-dropped, or tampered directory keeps the hooks facet refused while the declarative parts still load.
|
|
148
152
|
|
|
@@ -151,6 +155,8 @@ The skin center reads the plugin's markers and never writes them, and the plugin
|
|
|
151
155
|
- Inline styles written by plugins at runtime can only be overridden by L3 `!important` patches.
|
|
152
156
|
- Plugins that do not output semantic attributes (and have no stable DOM anchors) receive L1 token coverage only.
|
|
153
157
|
- Wallpaper pause-on-hidden, wallpaper blur, dimming and sound live in `dsh-plugin-wallpaper-engine`'s own settings; the skin center has no wallpaper controls and its card only reports the plugin's state.
|
|
158
|
+
- While one stylesheet transform is running, the worker process holds the CSS parser's native addon, and a package install in that exact window still sees a mapped addon on Windows. The window lasts one transform; the host process itself never holds it.
|
|
159
|
+
- A burst of more than eight stylesheet requests is refused with `503` for the requests beyond the cap; the client has to retry them.
|
|
154
160
|
|
|
155
161
|
## Telemetry
|
|
156
162
|
|
|
@@ -162,7 +168,7 @@ The browser half sends one anonymous install heartbeat per UTC day to dsh-market
|
|
|
162
168
|
skins/skin-center/
|
|
163
169
|
contracts/ # the skin-facing contract surface (schema, hooks API, semantic attrs)
|
|
164
170
|
src/core/manifest-v2/ # manifest v2 types + fail-closed validator
|
|
165
|
-
src/core/css-safety/ # lightningcss scoping + whitelist pipeline
|
|
171
|
+
src/core/css-safety/ # worker-scoped lightningcss scoping + whitelist pipeline
|
|
166
172
|
src/index.ts # host entry: routes, tapIndex adapter, legacy bridge
|
|
167
173
|
src/skin-repo.ts # dual-source skin catalog (built-in + $DSH_HOME/skins)
|
|
168
174
|
src/provenance.ts # official-market install provenance verification (hooks trust)
|
package/README.zh.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- 自定义主题:列表末尾提供一张基于官方默认外观派生的用户级主题卡,与「官方默认」及目录册皮肤相互独立。浅色、深色分别编辑强调色、背景色、前景色和对比度(0–100),支持即时试穿、应用、恢复当前模式默认值和刷新持久化。生成的 CSS 只能覆盖经审计的官方 token 白名单,不接收选择器、任意 CSS 或资源 URL;不会修改任何第三方皮肤定义,目录册皮肤激活时自定义主题层自动停用。
|
|
22
22
|
- 试穿 / 应用:两者走同一个原子切换引擎(`src/client/runtime/skin-controller.ts`)。一次切换 = 一个新的 activation identity:取回已限定作用域的样式表,安装样式、背景媒体与可选 hooks,翻转 `html[data-dsh-skin="<id>"]`,然后销毁上一个 activation(append-only 效果账本,幂等清理)。最新请求永远胜出;失败或被淘汰的切换完整保留旧皮肤。试穿是同一个切换但不落盘——「退出试穿」恢复已提交的皮肤。应用会持久化选择(`POST /api/skin-center/v2/active`)。不刷新页面、不改写 `cordis.patch.yml`、不重建启动图。
|
|
23
23
|
- 首屏:host 半区注册一个 index.html 转换(`webServer.tapIndex`,单一适配模块 `src/tap-index-adapter.ts`),向每份送达的文档盖 `html[data-dsh-skin]` 属性并插入样式表链接,刷新后直接以当前皮肤启动,无官方原貌闪屏。tap 出任何问题都 fail-closed 回官方原貌。
|
|
24
|
-
- 皮肤格式(v2):`skin.json`(fail-closed 校验,v1 字段 `package`/`wiring`/`bodyAttr` 忽略并给迁移警告)、`skin.css`(L1 token 重映射 + L2 语义选择器)、可选 `patches.css`(L3 自由选择器,高敏感)、可选 `hooks.mjs`(受信逃逸舱,高敏感)、`assets/`、`preview/`。所有 CSS
|
|
24
|
+
- 皮肤格式(v2):`skin.json`(fail-closed 校验,v1 字段 `package`/`wiring`/`bodyAttr` 忽略并给迁移警告)、`skin.css`(L1 token 重映射 + L2 语义选择器)、可选 `patches.css`(L3 自由选择器,高敏感)、可选 `hooks.mjs`(受信逃逸舱,高敏感)、`assets/`、`preview/`。所有 CSS 经过安全管线:每个选择器强制限定在 `html[data-dsh-skin]` 下,`@import` / 远程或协议相对 URL / 越界路径直接报错。宿主半区自身从不加载 CSS 解析器——每次转换都在一个短生命周期 worker 进程(`src/core/css-safety/host-transform.ts` + `worker-entry.ts`)中执行:每个请求单独 fork 一个 worker,并在样式表响应写回之前确认 worker 已退出,因此宿主进程从不映射解析器的原生 addon。见 `contracts/README.md`。
|
|
25
25
|
- 覆盖契约:L1 重映射官方 `--dsw-*` 设计 token;L2 样式语义属性(`data-dsh-surface` / `data-dsh-part` / `data-dsh-plugin`,枚举见 `contracts/semantic-attrs-v1.md`),由兼容适配器(`src/client/runtime/semantic-adapter.ts`)从稳定锚点(`data-slot` 出口、`data-chat-flow-kind` 等)为官方壳层 DOM 打标;L3 补丁任意选择器,脆弱性由皮肤作者自负。主动输出语义属性的插件获得完整 L2 覆盖;不输出的只享受 L1。目录皮肤或自定义主题激活期间还会启用公共壳层渲染适配器:它清除工作区列表末端 fade,将 composer 占位符固定为不透明的主题次级文本色,并为会话滚动口保留底部安全间距以保证吸底正文不被输入区覆盖(#978),各皮肤无需重复补丁。
|
|
26
26
|
- 背景优先级:壁纸渲染期间皮肤及其背景媒体整体停画(见「Wallpaper Engine」),背景完全归壁纸;否则皮肤清单背景媒体即背景。
|
|
27
27
|
- 背景控制:背景遮蔽滑杆(0–100%)为画背景的皮肤在面板后加纱,两个按状态的高斯模糊滑杆(0–20 px)分别控制空对话与有内容时的背景,输入卡模糊滑杆(0–20 px)只控制输入卡背后的磨砂区域,气泡不透明度滑杆(0–100%)控制支持气泡 alpha 的皮肤消息气泡。整张壁纸模糊仍是独立的壁纸设置。背景模糊通过外壳之后的固定 `backdrop-filter` 元素施加;0 完全关闭(无元素、无 GPU 开销)。输入卡磨砂由独立的 body 级固定跟随层(`data-dsh-composer-frost` 元素)承担并按输入卡尺寸跟随,**不**挂在卡片本体上:卡片一旦带 `backdrop-filter` 就会成为其中 shell fixed tooltip 的包含块,悬停时整页会话会被顶动。
|
|
@@ -135,6 +135,10 @@ Wallpaper Engine 卡片并排,带 `插件皮肤` 标记;皮肤中心开启
|
|
|
135
135
|
|
|
136
136
|
- 所有 `/api/skin-center/*` 路由仅接受同源请求:写操作拒绝跨站请求(Sec-Fetch-Site / Origin 围栏),资产读取限定在各皮肤目录之内(路径逃逸 fail-closed)。
|
|
137
137
|
- 皮肤 CSS 在服务前经白名单净化;`patches.css`(L3)按设计就是任意 CSS 并如实公示——它拥有完整页面样式能力,不构成安全边界。
|
|
138
|
+
- CSS 安全管线运行在短生命周期 worker 进程中,每个请求一个 worker,并在样式表响应写回之前确认 worker 已退出。因此宿主进程既不加载 CSS 解析器,也不映射其原生 addon——这正是宿主运行期间包管理器仍能替换解析器包的原因(issue #98)。
|
|
139
|
+
- 管线归属于单个插件挂载:挂载时创建、注入路由,并随挂载一起释放。因此重新挂载会得到自己的管线,旧挂载的清理不会让新挂载失效。
|
|
140
|
+
- 管线同时最多持有 8 个请求,包含正在执行的那个与等待中的那些。超出上限的请求立即被拒绝,返回 `503 css-transform-overloaded`;白名单违规仍为 `422`,其他转换失败仍为 `500`。
|
|
141
|
+
- 不会有请求悬挂:每个请求有 10 秒预算,该预算也覆盖「已应答但拒绝退出」的 worker;无法启动的 worker 会立即让请求失败,而不是等到预算耗尽。
|
|
138
142
|
- 自定义主题编辑器只会从 `CUSTOM_THEME_ALLOWED_TOKENS` 生成固定声明,且每个 token 都对照官方 token 注册表校验。用户输入只作为规范化后的颜色/对比度数据,不会成为选择器、URL 或自由 CSS 载荷。
|
|
139
143
|
- `hooks.mjs` 是与本仓库同审同发的受信代码,仅同源 serve,其 import/apply 错误永远不会拖垮静态皮肤。hooks 对内置皮肤及可按字节验证为官方市场已审查内容的用户目录皮肤放行:当前 Workshop 安装使用 `dsh-market.provenance.json`,而早于 provenance 的历史安装必须同时匹配生成的 `src/reviewed-hooks.generated.ts` 身份中的 id、声明入口、完整 `skin.json` 与 hooks 字节(由 `src/provenance.ts` 校验,issue #1073)。回退只读且离线;任何被修改、改名、手工投放或篡改的目录都会继续拒绝 hooks facet,声明式部分仍正常加载。
|
|
140
144
|
|
|
@@ -143,6 +147,8 @@ Wallpaper Engine 卡片并排,带 `插件皮肤` 标记;皮肤中心开启
|
|
|
143
147
|
- 插件运行时写入的内联样式只能经 L3 `!important` 补丁覆盖。
|
|
144
148
|
- 不输出语义属性(且无稳定 DOM 锚点)的插件只享受 L1 token 覆盖。
|
|
145
149
|
- 壁纸的「隐藏时暂停」、模糊、压暗与声音都在 `dsh-plugin-wallpaper-engine` 自己的设置里;皮肤中心没有任何壁纸控件,卡片只报告该插件的状态。
|
|
150
|
+
- 一次样式表转换进行期间,worker 进程持有 CSS 解析器的原生 addon;正落在该窗口内的包安装在 Windows 上仍会看到已映射的 addon。该窗口只有一次转换的时长;宿主进程自身从不持有它。
|
|
151
|
+
- 超过 8 个样式表请求的突发流量中,超出上限的请求会被拒绝并返回 `503`,需要客户端重试。
|
|
146
152
|
|
|
147
153
|
## 数据遥测
|
|
148
154
|
|
|
@@ -154,7 +160,7 @@ Wallpaper Engine 卡片并排,带 `插件皮肤` 标记;皮肤中心开启
|
|
|
154
160
|
skins/skin-center/
|
|
155
161
|
contracts/ # 面向皮肤的契约面(schema、hooks API、语义属性)
|
|
156
162
|
src/core/manifest-v2/ # manifest v2 类型 + fail-closed 校验器
|
|
157
|
-
src/core/css-safety/ # lightningcss 作用域限定 + 白名单管线
|
|
163
|
+
src/core/css-safety/ # worker 内运行的 lightningcss 作用域限定 + 白名单管线
|
|
158
164
|
src/index.ts # host 入口:路由、tapIndex 适配器、旧版迁移桥
|
|
159
165
|
src/skin-repo.ts # 双来源皮肤目录册(内置 + $DSH_HOME/skins)
|
|
160
166
|
src/provenance.ts # 官方市场安装 provenance 校验(hooks 信任)
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
皮肤中心不写委托插件的任何属性,委托插件不写 `data-dsh-skin`,双方都无法把
|
|
72
72
|
对方卡死。委托皮肤的选择会照常持久化、开机采纳与试穿还原;让路暂停的是
|
|
73
73
|
视觉,不是插件的设置页与偏好。
|
|
74
|
-
## part 组(
|
|
74
|
+
## part 组(103 行,含各 owner 行)
|
|
75
75
|
|
|
76
76
|
shell 区域(owner: shell):
|
|
77
77
|
|
|
@@ -175,6 +175,15 @@ family / 插件区域:
|
|
|
175
175
|
| `empty` | browser-view | 尚未收到画面时的空态占位;panel 内 `[data-dsh-part="empty"]` |
|
|
176
176
|
| `error` | browser-view | 宿主上报错误时的错误态占位;panel 内 `[data-dsh-part="error"]` |
|
|
177
177
|
| `tab-title` | browser-view | 右栏 chip 内本插件自有部分(图标 + 标题),chip 行盒归 shell;`[data-dsh-plugin="browser-view"] [data-dsh-part="tab-title"]` |
|
|
178
|
+
| `update-toolbar` | dsh-plugin-manager | 官方「插件」页「已安装插件」组标题行内的检查更新工具条(页面不声明该席位,容器插进 `[data-plugin-group="bundles"]` 的首个子元素并随页面重绘复位);`[data-dsh-plugin-manager-toolbar]` |
|
|
179
|
+
| `builtin-group` | dsh-plugin-manager | 官方「插件」页列表底部追加的内置插件分组根(页面不声明该席位,作为已安装面板的后续兄弟挂载);`data-builtin-state` 为 `loading` / `unavailable` / `failed` / `ready`,`data-builtin-bundles` 为 `confirmed` / `unconfirmed` |
|
|
180
|
+
| `builtin-row` | dsh-plugin-manager | 内置插件分组内的一行:标题、模块名、锁定原因与启停开关;`data-entry-id` 为 loader 行 id,`data-write` 为 `writable` / `management-required` / `unaddressable` / `unknown` |
|
|
181
|
+
| `builtin-notice` | dsh-plugin-manager | 内置插件分组标题下的操作反馈行;失败为 `role="alert"`,其余为 `role="status"` |
|
|
182
|
+
| `preset-group` | dsh-plugin-manager | 内置插件分组下方的只读 Agent 预设区块根(预设行由组合决定,不提供开关) |
|
|
183
|
+
| `preset` | dsh-plugin-manager | 一个 Agent 预设卡;`data-preset-id` 为预设 id,`data-default` 为 `yes` / `no` |
|
|
184
|
+
| `preset-row` | dsh-plugin-manager | 预设组合中的一行(模块名 + 状态);`data-preset-state` 为 `on` / `off` / `conditional`,条件行同时给出表达式 |
|
|
185
|
+
| `builtin-scope` | dsh-plugin-manager | 内置插件分组标题右侧的展开/收起控件,切换「只列无所属组合包的行」与「追加全部 Loader 行」两态;`aria-expanded` 表示当前是否展开,`aria-controls` 指向它切换的列表元素,`[data-dsh-part="builtin-scope"]` |
|
|
186
|
+
| `builtin-owner` | dsh-plugin-manager | 展开态中已归属行内的次要文本,写明这一行同时属于哪个已安装组合包(文案形如「来自 <包名>」);行内 `[data-dsh-part="builtin-owner"]` |
|
|
178
187
|
|
|
179
188
|
### 面板行身份锚点 `data-dsh-panel-entry`(owner: 各注册面板的插件)
|
|
180
189
|
|
|
@@ -191,7 +200,7 @@ shell 的 `[class*="panelGlyph"]` 内)。shell 目前不把 entry id 透传到
|
|
|
191
200
|
不进 `data-dsh-plugin`:plugin 属性标记插件面板根,皮肤里已有
|
|
192
201
|
`[data-dsh-plugin="ssh"] [class*="panel"]` 一类把根当作面板子树起点的规则,把字形也算进去会误伤。
|
|
193
202
|
|
|
194
|
-
## plugin 组(
|
|
203
|
+
## plugin 组(17 个)
|
|
195
204
|
|
|
196
205
|
| data-dsh-plugin | owner | 锚定方式 |
|
|
197
206
|
| --- | --- | --- |
|
|
@@ -211,6 +220,7 @@ shell 的 `[class*="panelGlyph"]` 内)。shell 目前不把 entry id 透传到
|
|
|
211
220
|
| `preset-center` | dsh-preset-center | 创意工坊卡片的「预设」标签页面板(`dsh-workshop.panel` keyed 槽 key `preset`);`[data-dsh-plugin="preset-center"]` |
|
|
212
221
|
| `liangshen` | dsh-liangshen | 首页输入框内的梁神模式拨杆;`[data-dsh-plugin="liangshen"][data-dsh-part="lever"]`,slot entry id `liangshen-lever` |
|
|
213
222
|
| `browser-view` | dsh-browser-view | 右栏标签页类型 id `@linxin666/dsh-client-ui-browser-view`(`sidebar.right.pane.tab` 与 `.title` 的 key);`[data-dsh-plugin="browser-view"]`(面板根 + 会话头触发器);chip 内自有部分 `[data-dsh-part="tab-title"]` |
|
|
223
|
+
| `plugin-manager` | dsh-plugin-manager | 官方「插件」页上本插件的两处注入:检查更新工具条根与内置插件分组根;`[data-dsh-plugin="plugin-manager"]` |
|
|
214
224
|
|
|
215
225
|
## 已知脆弱点(上游主题缝 PR 诉求)
|
|
216
226
|
|
package/lib/client.js
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
/**
|
|
4
|
+
* Whether an error is a whitelist violation.
|
|
5
|
+
*
|
|
6
|
+
* The check is deliberately strict: the stable kind marker AND a violations
|
|
7
|
+
* list. An error that merely carries a `violations` array (a lookalike from
|
|
8
|
+
* another library, or a differently named failure) is NOT a whitelist
|
|
9
|
+
* violation and must not be answered with 422.
|
|
10
|
+
* @param error - the thrown value.
|
|
11
|
+
* @returns true when the error is a whitelist violation.
|
|
12
|
+
*/
|
|
13
|
+
function isSkinCssSafetyViolation(error) {
|
|
14
|
+
if (typeof error !== "object" || error === null) return false;
|
|
15
|
+
const candidate = error;
|
|
16
|
+
if (candidate.kind !== "SkinCssSafetyError") return false;
|
|
17
|
+
return Array.isArray(candidate.violations);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/core/css-safety/worker-entry.ts
|
|
21
|
+
/**
|
|
22
|
+
* CSS safety worker process (issue #98).
|
|
23
|
+
*
|
|
24
|
+
* This file is the entry point of the short-lived worker that serves ONE
|
|
25
|
+
* stylesheet transform. It is the only place where lightningcss is loaded:
|
|
26
|
+
* the host half forks this bundle, sends one request over IPC, and waits for
|
|
27
|
+
* the process to exit. The native addon therefore lives in this process and
|
|
28
|
+
* never in the DSH host process.
|
|
29
|
+
*
|
|
30
|
+
* The worker loads the transform bundle from its own module URL (never from
|
|
31
|
+
* the process working directory) and answers with the transformed CSS, a
|
|
32
|
+
* whitelist violation, or a failure.
|
|
33
|
+
* @module @linxin666/dsh-client-ui-skin-center/css-safety/worker-entry
|
|
34
|
+
*/
|
|
35
|
+
/** Bundle file name that carries the transform (beside this worker bundle). */
|
|
36
|
+
const CSS_SAFETY_FILE = "css-safety.js";
|
|
37
|
+
/**
|
|
38
|
+
* Load the css-safety bundle.
|
|
39
|
+
*
|
|
40
|
+
* The bundle is resolved from this module's URL: the built package keeps it
|
|
41
|
+
* beside the worker bundle, the source tree keeps it under lib/.
|
|
42
|
+
* @returns the transform function.
|
|
43
|
+
*/
|
|
44
|
+
async function loadCssSafety() {
|
|
45
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
46
|
+
const candidates = [join(here, CSS_SAFETY_FILE), join(here, "..", "..", "..", "lib", CSS_SAFETY_FILE)];
|
|
47
|
+
let lastError = null;
|
|
48
|
+
for (const candidate of candidates) try {
|
|
49
|
+
const mod = await import(pathToFileURL(candidate).href);
|
|
50
|
+
if (typeof mod.transformSkinCss === "function") return mod;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
lastError = error;
|
|
53
|
+
}
|
|
54
|
+
throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error(`${CSS_SAFETY_FILE} not found beside the CSS safety worker`);
|
|
55
|
+
}
|
|
56
|
+
let cssSafetyPromise = null;
|
|
57
|
+
/** Load the css-safety bundle once per worker process. */
|
|
58
|
+
function loadCssSafetyOnce() {
|
|
59
|
+
cssSafetyPromise ??= loadCssSafety();
|
|
60
|
+
return cssSafetyPromise;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Serve one request.
|
|
64
|
+
* @param message - the host request (one stylesheet plus its options).
|
|
65
|
+
*/
|
|
66
|
+
async function serve(message) {
|
|
67
|
+
let response;
|
|
68
|
+
try {
|
|
69
|
+
const { transformSkinCss } = await loadCssSafetyOnce();
|
|
70
|
+
const result = transformSkinCss(message.css, message.options);
|
|
71
|
+
response = {
|
|
72
|
+
type: "result",
|
|
73
|
+
code: result.code,
|
|
74
|
+
warnings: result.warnings
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (isSkinCssSafetyViolation(error)) response = {
|
|
78
|
+
type: "violation",
|
|
79
|
+
message: error.message,
|
|
80
|
+
violations: error.violations
|
|
81
|
+
};
|
|
82
|
+
else response = {
|
|
83
|
+
type: "failure",
|
|
84
|
+
message: error instanceof Error ? error.message : String(error)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
process.send?.(response, () => {
|
|
88
|
+
process.exit(0);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
process.on("message", (message) => {
|
|
92
|
+
if (!message || message.type !== "transform") return;
|
|
93
|
+
serve(message);
|
|
94
|
+
});
|
|
95
|
+
process.on("disconnect", () => {
|
|
96
|
+
process.exit(0);
|
|
97
|
+
});
|
|
98
|
+
process.send?.({ type: "ready" });
|
|
99
|
+
//#endregion
|
|
100
|
+
export {};
|