dsh-quick-phrases 0.9.2 → 0.10.1
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.md +38 -4
- package/client.js +298 -21
- package/docs/ARCHITECTURE.md +44 -7
- package/docs/DETAIL.de.md +56 -7
- package/docs/DETAIL.en.md +56 -7
- package/docs/DETAIL.es.md +56 -7
- package/docs/DETAIL.fr.md +56 -7
- package/docs/DETAIL.md +56 -7
- package/docs/DETAIL.pt.md +56 -7
- package/docs/DETAIL.ru.md +56 -7
- package/docs/images/README.md +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
语言:[简体中文](docs/DETAIL.md) · [English](docs/DETAIL.en.md) · [Español](docs/DETAIL.es.md) · [Français](docs/DETAIL.fr.md) · [Deutsch](docs/DETAIL.de.md) · [Русский](docs/DETAIL.ru.md) · [Português](docs/DETAIL.pt.md)
|
|
9
9
|
|
|
10
|
-
给 DeepSeek Harness(DSH)的输入框加一排快捷短语按钮:`继续`、`提交`、`推送`、`发版`
|
|
10
|
+
给 DeepSeek Harness(DSH)的输入框加一排快捷短语按钮:`继续`、`提交`、`推送`、`发版` 这类天天要打的字,点一下就送进输入框或直接发出。
|
|
11
|
+
|
|
12
|
+
按钮上显示的**名称**和真正发出的**内容**分开编辑,所以按钮可以很短,话可以很长。
|
|
11
13
|
|
|
12
14
|
> Composer decoration for DeepSeek Harness: a row of quick-phrase chips whose captions and sent text are edited separately, plus a management page in Settings.
|
|
13
15
|
|
|
@@ -15,6 +17,21 @@
|
|
|
15
17
|
|
|
16
18
|
> 文档里的截图都是**界面示意图**:由 `test/preview.mjs` 把真实组件套上宿主主题 token 渲染出来,不是真机截屏。实际观感以运行中的界面为准。
|
|
17
19
|
|
|
20
|
+
**目录**
|
|
21
|
+
|
|
22
|
+
- [功能](#功能)
|
|
23
|
+
- [安装](#安装)
|
|
24
|
+
- [使用](#使用)
|
|
25
|
+
- [放在哪里](#放在哪里)
|
|
26
|
+
- [管理页](#管理页)
|
|
27
|
+
- [收起与隐藏](#收起与隐藏)
|
|
28
|
+
- [窄屏自动舍弃](#窄屏自动舍弃)
|
|
29
|
+
- [数据与隐私](#数据与隐私)
|
|
30
|
+
- [开发](#开发)
|
|
31
|
+
- [文档](#文档)
|
|
32
|
+
- [许可证](#许可证)
|
|
33
|
+
- [支持本项目](#支持本项目)
|
|
34
|
+
|
|
18
35
|
## 功能
|
|
19
36
|
|
|
20
37
|
- **一排短语按钮**:显示名称与发送内容分离,默认四条:继续 / 提交 / 推送 / 发版。
|
|
@@ -23,12 +40,15 @@
|
|
|
23
40
|
- **整排三态可选**:设置里的「短语行显示」一档搞定——**显示整排**常驻;**收成胶囊**只留一个小胶囊,点开可临时展开;**彻底隐藏**则把整排从界面完全移除(连胶囊都不留),只能回到 **设置 → 快捷短语** 恢复。
|
|
24
41
|
- **管理入口可换**:行尾的「管理」可以保持文字按钮、换成齿轮图标,或直接隐藏;隐藏后管理页仍从 **设置 → 快捷短语** 进入。
|
|
25
42
|
- **单条短语可隐藏**:管理页每张卡片有一个眼睛开关,隐藏后这条按钮从短语行消失,卡片仍留在管理页并标注「已隐藏」。
|
|
43
|
+
- **窄屏自动舍弃**:短语行按**实际可用宽度**自动降级——先丢行尾「收起」,再丢「管理」,再从末尾往前逐个丢短语;极窄时只保留第一条可用短语,不会丢光,也不新增设置项。
|
|
26
44
|
- **管理页**:拖动手柄排序、直接在卡片上改名、实时按钮预览与字数、两步确认删除、一键恢复默认。
|
|
27
45
|
- **零依赖**:纯前端一个 `client.js`,不联网、不读写文件、不引入 npm 包,数据只存在本机 `localStorage`。
|
|
28
46
|
|
|
29
47
|
## 安装
|
|
30
48
|
|
|
31
|
-
前置:DSH 桌面端或 Web 端,支持版本 `^0.2.2-rc.3`(0.2.2-rc.3 起,不含 0.3.0 及以上)——与包内 `engines.dsh` 及市场索引 `versions[].engines.dsh`
|
|
49
|
+
- 前置:DSH 桌面端或 Web 端,支持版本 `^0.2.2-rc.3`(0.2.2-rc.3 起,不含 0.3.0 及以上)——与包内 `engines.dsh` 及市场索引 `versions[].engines.dsh` 一致。
|
|
50
|
+
- 插件分类为**界面增强(UI Enhancements)**,与市场索引 `metadata.categories.ui` / `metadata.category: ui` 一致。
|
|
51
|
+
- 插件没有运行时依赖,也没有构建步骤。
|
|
32
52
|
|
|
33
53
|
**方式 A(npm,推荐)**
|
|
34
54
|
|
|
@@ -42,7 +62,7 @@ dsh plugin --profile <你的 profile> add dsh-quick-phrases
|
|
|
42
62
|
|
|
43
63
|
在 DSH 里打开 **Plugins → Discover → Index sources**,添加本仓库的索引地址:
|
|
44
64
|
|
|
45
|
-
```
|
|
65
|
+
```text
|
|
46
66
|
https://raw.githubusercontent.com/pengtang1024/dsh-quick-phrases/main/index.json
|
|
47
67
|
```
|
|
48
68
|
|
|
@@ -70,6 +90,8 @@ Plugins → Add plugin → 选择本仓库目录;或让 DSH 里的 agent 执
|
|
|
70
90
|
|
|
71
91
|
设置 → **快捷短语**:上面五项决定位置、点按行为、短语行的显示形态、管理入口样式、以及输入框有内容时怎么收起,选中即生效、无需重启;下面一条短语一张卡片。
|
|
72
92
|
|
|
93
|
+
> **小屏设计优化**:设置 / 管理页在窄屏(≤560px)有一套纯排版优化——选项标签与下拉同行、说明文字完整保留、触控目标放大(按钮 36px、textarea 52px)、区块头按钮平分一行、页边距收紧、长文本任意处换行;**不删任何元素、不改功能**。这与短语行的「按宽度舍弃」(见下文「窄屏自动舍弃」)是两套完全不同的逻辑:那里按实际宽度逐个舍弃控件,这里一个元素都不删。
|
|
94
|
+
|
|
73
95
|
| 配置项 | 可选值 | 默认值 |
|
|
74
96
|
| --- | --- | --- |
|
|
75
97
|
| 显示位置 | 输入框下方 / 输入框上方 / 工具行右侧 | 输入框下方 |
|
|
@@ -112,6 +134,18 @@ Plugins → Add plugin → 选择本仓库目录;或让 DSH 里的 agent 执
|
|
|
112
134
|
|
|
113
135
|
行尾「收起 ▾」等价于选「收成胶囊」;下拉选「显示整排」时会顺带清掉折叠状态,直接回到整排。「短语行显示」没有单独的状态键,读写的就是下面表里的 `hidden` 与 `collapsed` 两个键。
|
|
114
136
|
|
|
137
|
+
### 窄屏自动舍弃
|
|
138
|
+
|
|
139
|
+
宽度不够时,短语行会按可用宽度**自动依次舍弃**控件,不用改任何设置,也不是固定像素断点(用 `ResizeObserver` 量容器实际宽度 + 缓存每个胶囊的实测宽度来计算,长短名称都能正确降级):
|
|
140
|
+
|
|
141
|
+
1. 先丢行尾的 **收起**(最不重要);
|
|
142
|
+
2. 再丢 **管理**入口;
|
|
143
|
+
3. 再从末尾往前逐个丢**短语胶囊**,顺序与上面的列表顺序一致,靠前的短语优先留下。
|
|
144
|
+
|
|
145
|
+
极窄时**只保留第一条可用短语**,绝不把短语丢光;若一条短语都没有,收起与管理两个入口仍然可达。
|
|
146
|
+
|
|
147
|
+
「收起」在窄屏被自动舍弃后不用慌:输入框出现草稿时仍会按「自动收起」把整排折成胶囊;也可以在设置里把「短语行显示」选成「收成胶囊」折叠整排。窗口变宽后控件按同样的规则自动回来。管理入口若在窄屏被舍弃,仍可从 **设置 → 快捷短语** 进入管理页。三态 full/pill/hidden、自动收起、单条隐藏等既有行为都不变。
|
|
148
|
+
|
|
115
149
|
单条短语则在管理页用眼睛开关隐藏;短语行的从左到右顺序与卡片顺序保持一致。
|
|
116
150
|
|
|
117
151
|
## 数据与隐私
|
|
@@ -145,7 +179,7 @@ node test/preview.mjs --shot # 再用无头 Chromium 截图
|
|
|
145
179
|
|
|
146
180
|
目录结构:
|
|
147
181
|
|
|
148
|
-
```
|
|
182
|
+
```text
|
|
149
183
|
client.js 客户端插件全部逻辑(ModuleLoader 工厂 + 三个插槽组件)
|
|
150
184
|
index.js Host 侧空壳(export function apply() {})
|
|
151
185
|
cordis.patch.yml bundle 插入行
|
package/client.js
CHANGED
|
@@ -1000,6 +1000,114 @@ window.__ModuleLoader__.load({
|
|
|
1000
1000
|
setCollapsed(false)
|
|
1001
1001
|
}
|
|
1002
1002
|
|
|
1003
|
+
/* ------------------------------------------------------------------ *
|
|
1004
|
+
* Width fitting: shed the least important chips first. Driven by the
|
|
1005
|
+
* row's real content width (ResizeObserver), never by a fixed px
|
|
1006
|
+
* breakpoint, so short and long captions both degrade correctly.
|
|
1007
|
+
* ------------------------------------------------------------------ */
|
|
1008
|
+
|
|
1009
|
+
var CHIP_GAP = 6
|
|
1010
|
+
|
|
1011
|
+
function finitePx(value) {
|
|
1012
|
+
return typeof value === 'number' && isFinite(value) ? value : null
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
function widthOf(value) {
|
|
1016
|
+
var px = finitePx(value)
|
|
1017
|
+
return px === null || px < 0 ? 0 : px
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Pure, DOM-free fitter. Return the chips that survive at `available` px.
|
|
1022
|
+
* Priority: collapse (least important) -> manage -> phrase chips from the
|
|
1023
|
+
* end. The first usable phrase chip is never dropped; with no phrase at
|
|
1024
|
+
* all both trailing controls stay reachable.
|
|
1025
|
+
*
|
|
1026
|
+
* options: { phraseWidths, collapseWidth, manageWidth, manage, gap }
|
|
1027
|
+
* returns: { phraseCount, collapse, manage }
|
|
1028
|
+
*/
|
|
1029
|
+
function fitRowToWidth(available, options) {
|
|
1030
|
+
var opts = options && typeof options === 'object' ? options : {}
|
|
1031
|
+
var widths = Array.isArray(opts.phraseWidths) ? opts.phraseWidths : []
|
|
1032
|
+
var gap = widthOf(opts.gap)
|
|
1033
|
+
if (gap === 0) gap = CHIP_GAP
|
|
1034
|
+
var collapseWidth = widthOf(opts.collapseWidth)
|
|
1035
|
+
var manageWidth = widthOf(opts.manageWidth)
|
|
1036
|
+
var manage = opts.manage !== false
|
|
1037
|
+
var plan = { phraseCount: widths.length, collapse: true, manage: manage }
|
|
1038
|
+
var px = finitePx(available)
|
|
1039
|
+
|
|
1040
|
+
if (px === null || px <= 0 || widths.length === 0) return plan
|
|
1041
|
+
|
|
1042
|
+
function used(candidate) {
|
|
1043
|
+
var total = 0
|
|
1044
|
+
var count = 0
|
|
1045
|
+
for (var i = 0; i < candidate.phraseCount; i += 1) {
|
|
1046
|
+
total += widthOf(widths[i])
|
|
1047
|
+
count += 1
|
|
1048
|
+
}
|
|
1049
|
+
if (candidate.collapse) { total += collapseWidth; count += 1 }
|
|
1050
|
+
if (candidate.manage) { total += manageWidth; count += 1 }
|
|
1051
|
+
if (count > 1) total += gap * (count - 1)
|
|
1052
|
+
return total
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
while (used(plan) > px) {
|
|
1056
|
+
if (plan.collapse) plan.collapse = false
|
|
1057
|
+
else if (plan.manage) plan.manage = false
|
|
1058
|
+
else if (plan.phraseCount > 1) plan.phraseCount -= 1
|
|
1059
|
+
else break
|
|
1060
|
+
}
|
|
1061
|
+
return plan
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Test seam: the smoke-test sandbox has no DOM / ResizeObserver, so it can
|
|
1066
|
+
* pin the available width and the per-chip measured widths here. It is
|
|
1067
|
+
* inert until a test explicitly opts in (any setter flips `enabled`), so a
|
|
1068
|
+
* production render never consults a stale global left by another session.
|
|
1069
|
+
* `reset()` turns it off again and restores real DOM measurement.
|
|
1070
|
+
*/
|
|
1071
|
+
var widthFitProbe = {
|
|
1072
|
+
enabled: false,
|
|
1073
|
+
available: null,
|
|
1074
|
+
phrases: null,
|
|
1075
|
+
collapseWidth: null,
|
|
1076
|
+
manageWidth: null,
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
function probeIsActive() {
|
|
1080
|
+
return widthFitProbe.enabled === true
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
window.__DQP_WIDTH_FIT__ = {
|
|
1084
|
+
fit: fitRowToWidth,
|
|
1085
|
+
// Explicit opt-in helpers; the setters below also opt in so existing
|
|
1086
|
+
// probe-driven tests keep working without a separate enable() call.
|
|
1087
|
+
enable: function () { widthFitProbe.enabled = true },
|
|
1088
|
+
disable: function () { widthFitProbe.enabled = false },
|
|
1089
|
+
setAvailableWidth: function (value) {
|
|
1090
|
+
widthFitProbe.enabled = true
|
|
1091
|
+
widthFitProbe.available = finitePx(value)
|
|
1092
|
+
},
|
|
1093
|
+
setChipWidths: function (widths) {
|
|
1094
|
+
widthFitProbe.enabled = true
|
|
1095
|
+
widthFitProbe.phrases = Array.isArray(widths) ? widths.slice() : null
|
|
1096
|
+
},
|
|
1097
|
+
setTrailingWidths: function (collapse, manage) {
|
|
1098
|
+
widthFitProbe.enabled = true
|
|
1099
|
+
widthFitProbe.collapseWidth = finitePx(collapse)
|
|
1100
|
+
widthFitProbe.manageWidth = finitePx(manage)
|
|
1101
|
+
},
|
|
1102
|
+
reset: function () {
|
|
1103
|
+
widthFitProbe.enabled = false
|
|
1104
|
+
widthFitProbe.available = null
|
|
1105
|
+
widthFitProbe.phrases = null
|
|
1106
|
+
widthFitProbe.collapseWidth = null
|
|
1107
|
+
widthFitProbe.manageWidth = null
|
|
1108
|
+
},
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1003
1111
|
/* ------------------------------------------------------------------ *
|
|
1004
1112
|
* Styles: local to each component, removed on unmount.
|
|
1005
1113
|
* ------------------------------------------------------------------ */
|
|
@@ -1204,23 +1312,48 @@ window.__ModuleLoader__.load({
|
|
|
1204
1312
|
'transition:border-color .14s ease,box-shadow .14s ease}' +
|
|
1205
1313
|
'.dqp-input::placeholder{color:var(--dsw-alias-label-caption,#7d7d7d)}' +
|
|
1206
1314
|
'.dqp-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary,#4c6fff);box-shadow:0 0 0 2px rgba(0,0,0,.12)}' +
|
|
1207
|
-
/* Narrow viewports
|
|
1208
|
-
|
|
1315
|
+
/* Narrow viewports. Nothing is shed: every picker keeps its label, its
|
|
1316
|
+
full explanation and its control. The picker sits beside the label in
|
|
1317
|
+
one row (long labels simply wrap), with the complete explanation kept
|
|
1318
|
+
below it — five options cost five compact blocks, not ten.
|
|
1319
|
+
Phrase cards give the name field its own line, lift every control to a
|
|
1320
|
+
36px touch target, and wrap the preview instead of ellipsing it. */
|
|
1209
1321
|
'@media (max-width:560px){' +
|
|
1210
|
-
'.dqp-page{padding:
|
|
1211
|
-
'.dqp-inner{gap:
|
|
1212
|
-
'.dqp-head{padding-left:10px}' +
|
|
1322
|
+
'.dqp-page{padding:12px 12px 18px}' +
|
|
1323
|
+
'.dqp-inner{gap:12px}' +
|
|
1324
|
+
'.dqp-head{flex-wrap:wrap;gap:8px;padding-left:10px}' +
|
|
1213
1325
|
'.dqp-title{font-size:17px;line-height:24px}' +
|
|
1214
|
-
'.dqp-
|
|
1215
|
-
'.dqp-
|
|
1216
|
-
'.dqp-
|
|
1217
|
-
'
|
|
1218
|
-
'.dqp-
|
|
1219
|
-
'
|
|
1220
|
-
'.dqp-label-
|
|
1221
|
-
'.dqp-
|
|
1222
|
-
'.dqp-
|
|
1223
|
-
'.dqp-
|
|
1326
|
+
'.dqp-desc{overflow-wrap:anywhere}' +
|
|
1327
|
+
'.dqp-options{border-radius:8px}' +
|
|
1328
|
+
'.dqp-option{display:flex;flex-direction:row;align-items:flex-start;gap:8px;' +
|
|
1329
|
+
'padding:7px 12px;min-height:0}' +
|
|
1330
|
+
'.dqp-option-text{flex:1 1 auto;min-width:0;display:flex;flex-direction:row;' +
|
|
1331
|
+
'align-items:center;flex-wrap:wrap;gap:2px 8px}' +
|
|
1332
|
+
'.dqp-option-label,.dqp-option-label-row{min-width:0;overflow-wrap:anywhere}' +
|
|
1333
|
+
'.dqp-option-hint{flex:1 1 100%;width:100%;min-width:0;line-height:15px;overflow-wrap:anywhere}' +
|
|
1334
|
+
'.dqp-select-wrap{flex:0 0 44%;width:44%;min-width:0}' +
|
|
1335
|
+
'.dqp-select{width:100%;min-width:0;height:36px;font-size:13px}' +
|
|
1336
|
+
'.dqp-btn{height:auto;min-height:36px;padding:6px 12px;line-height:16px}' +
|
|
1337
|
+
'.dqp-section-head{gap:6px 8px}' +
|
|
1338
|
+
'.dqp-section-title{flex:1 1 100%;min-width:0}' +
|
|
1339
|
+
'.dqp-section-head .dqp-btn{flex:1 1 auto;min-width:0}' +
|
|
1340
|
+
'.dqp-list{gap:8px}' +
|
|
1341
|
+
'.dqp-row{gap:6px;padding:8px 10px 8px 2px;flex-wrap:nowrap;align-items:flex-start}' +
|
|
1342
|
+
'.dqp-grip{flex:0 0 28px;width:28px;height:36px}' +
|
|
1343
|
+
'.dqp-row-head{flex-wrap:wrap;gap:6px}' +
|
|
1344
|
+
'.dqp-label-input{flex:1 1 100%;min-width:0;height:34px;font-size:14px}' +
|
|
1345
|
+
'.dqp-row-actions{margin-left:auto;gap:4px;flex-wrap:wrap;justify-content:flex-end}' +
|
|
1346
|
+
'.dqp-icon{width:36px;height:36px}' +
|
|
1347
|
+
'.dqp-icon-confirm{width:auto;min-width:36px;padding:0 10px}' +
|
|
1348
|
+
'.dqp-textarea{min-height:52px;padding:7px 10px;font-size:13px;line-height:19px}' +
|
|
1349
|
+
'.dqp-row-meta{align-items:flex-start;gap:6px;line-height:16px}' +
|
|
1350
|
+
'.dqp-preview{display:block;flex:1 1 auto;min-width:0;max-width:none;height:auto;' +
|
|
1351
|
+
'min-height:22px;padding:2px 8px;overflow:visible;text-overflow:clip;' +
|
|
1352
|
+
'white-space:normal;overflow-wrap:anywhere}' +
|
|
1353
|
+
'.dqp-meta-grow{flex:1 1 4px;min-width:4px}' +
|
|
1354
|
+
'.dqp-row-meta>span:last-child{flex:0 0 auto;white-space:nowrap}' +
|
|
1355
|
+
'.dqp-foot,.dqp-star{line-height:17px;overflow-wrap:anywhere}' +
|
|
1356
|
+
'.dqp-star-link{min-height:36px;padding:6px 10px}' +
|
|
1224
1357
|
'}'
|
|
1225
1358
|
|
|
1226
1359
|
/* ------------------------------------------------------------------ *
|
|
@@ -1310,6 +1443,12 @@ window.__ModuleLoader__.load({
|
|
|
1310
1443
|
var showHint = React.useState(false)
|
|
1311
1444
|
var setShowHint = showHint[1]
|
|
1312
1445
|
var hintTimer = React.useRef(null)
|
|
1446
|
+
// Width fitting state. These hooks are unconditional so the hook count
|
|
1447
|
+
// never changes with the placement, folded state, or fitted chip count.
|
|
1448
|
+
var widthTickState = React.useState(0)
|
|
1449
|
+
var bumpWidth = widthTickState[1]
|
|
1450
|
+
var rowRef = React.useRef(null)
|
|
1451
|
+
var metricsRef = React.useRef({ available: null, phrases: {} })
|
|
1313
1452
|
var hasDraft = draft.trim() !== '' || attachments > 0
|
|
1314
1453
|
var folded = collapsed || (autoHide === 'fold' && hasDraft && !peeked)
|
|
1315
1454
|
var usable = phrases.filter(function (phrase) {
|
|
@@ -1328,6 +1467,106 @@ window.__ModuleLoader__.load({
|
|
|
1328
1467
|
}
|
|
1329
1468
|
}, [])
|
|
1330
1469
|
|
|
1470
|
+
// Re-measure on every render so changes in caption/phrase list update
|
|
1471
|
+
// the fit. ResizeObserver adds a nudge when the container changes without
|
|
1472
|
+
// a React update. A first paint often reports clientWidth === 0 before
|
|
1473
|
+
// layout settles, so also schedule bounded deferred re-measures: a
|
|
1474
|
+
// static session must still descend from the full row even when no
|
|
1475
|
+
// ResizeObserver exists and no further React render happens.
|
|
1476
|
+
React.useEffect(function () {
|
|
1477
|
+
function measure() {
|
|
1478
|
+
var node = rowRef.current
|
|
1479
|
+
if (node === null || node === undefined) return
|
|
1480
|
+
var available = finitePx(node.clientWidth)
|
|
1481
|
+
if (available === null) return
|
|
1482
|
+
// Shed chips must keep their cached widths; otherwise dropping one
|
|
1483
|
+
// would free an estimated 0px next render and make the row oscillate.
|
|
1484
|
+
// Cache is keyed by phrase.id, never by DOM index: a shed chip leaves
|
|
1485
|
+
// a hole in node.children, and the folded pill / trailing controls
|
|
1486
|
+
// must never be mistaken for a phrase.
|
|
1487
|
+
var phrases = {}
|
|
1488
|
+
for (var key in metricsRef.current.phrases) {
|
|
1489
|
+
if (Object.prototype.hasOwnProperty.call(metricsRef.current.phrases, key)) {
|
|
1490
|
+
phrases[key] = metricsRef.current.phrases[key]
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
var collapseWidth = metricsRef.current.collapseWidth
|
|
1494
|
+
var manageWidth = metricsRef.current.manageWidth
|
|
1495
|
+
for (var i = 0; i < node.children.length; i += 1) {
|
|
1496
|
+
var child = node.children[i]
|
|
1497
|
+
if (child === null || child === undefined || typeof child.className !== 'string') continue
|
|
1498
|
+
var value = finitePx(child.getBoundingClientRect ? child.getBoundingClientRect().width : child.offsetWidth)
|
|
1499
|
+
if (value === null) continue
|
|
1500
|
+
var cls = child.className
|
|
1501
|
+
if (cls.indexOf('dqp-chip-collapse') >= 0) { collapseWidth = value; continue }
|
|
1502
|
+
if (cls.indexOf('dqp-chip-manage') >= 0) { manageWidth = value; continue }
|
|
1503
|
+
if (cls.indexOf('dqp-pill') >= 0 || cls.indexOf('dqp-chip') < 0) continue
|
|
1504
|
+
var phraseId = typeof child.getAttribute === 'function'
|
|
1505
|
+
? child.getAttribute('data-dqp-phrase-id')
|
|
1506
|
+
: null
|
|
1507
|
+
if (phraseId === null || phraseId === undefined || phraseId === '') continue
|
|
1508
|
+
phrases[phraseId] = value
|
|
1509
|
+
}
|
|
1510
|
+
var prev = metricsRef.current
|
|
1511
|
+
var changed = prev.available !== available || prev.collapseWidth !== collapseWidth ||
|
|
1512
|
+
prev.manageWidth !== manageWidth
|
|
1513
|
+
if (!changed) {
|
|
1514
|
+
for (var nextKey in phrases) {
|
|
1515
|
+
if (Object.prototype.hasOwnProperty.call(phrases, nextKey) && prev.phrases[nextKey] !== phrases[nextKey]) {
|
|
1516
|
+
changed = true
|
|
1517
|
+
break
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
if (changed) {
|
|
1522
|
+
metricsRef.current = { available: available, phrases: phrases, collapseWidth: collapseWidth, manageWidth: manageWidth }
|
|
1523
|
+
bumpWidth(function (value) { return value + 1 })
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
measure()
|
|
1527
|
+
var node = rowRef.current
|
|
1528
|
+
if (node === null || node === undefined) return undefined
|
|
1529
|
+
|
|
1530
|
+
var disposed = false
|
|
1531
|
+
var deferredId = null
|
|
1532
|
+
var hasRaf = typeof window.requestAnimationFrame === 'function'
|
|
1533
|
+
function later() {
|
|
1534
|
+
if (disposed) return
|
|
1535
|
+
deferredId = null
|
|
1536
|
+
measure()
|
|
1537
|
+
scheduleDeferred()
|
|
1538
|
+
}
|
|
1539
|
+
function scheduleDeferred() {
|
|
1540
|
+
if (disposed || deferredId !== null) return
|
|
1541
|
+
// Only retry while the width is still unusable; a real width means
|
|
1542
|
+
// the synchronous measure already did its job. Bound the chain so a
|
|
1543
|
+
// permanently hidden/zero-width row cannot spin rAF forever.
|
|
1544
|
+
var width = finitePx(node.clientWidth)
|
|
1545
|
+
if (width !== null && width > 0) return
|
|
1546
|
+
if (deferredCount >= 3) return
|
|
1547
|
+
deferredCount += 1
|
|
1548
|
+
deferredId = hasRaf
|
|
1549
|
+
? window.requestAnimationFrame(later)
|
|
1550
|
+
: window.setTimeout(later, 0)
|
|
1551
|
+
}
|
|
1552
|
+
var deferredCount = 0
|
|
1553
|
+
scheduleDeferred()
|
|
1554
|
+
|
|
1555
|
+
var observer = null
|
|
1556
|
+
if (typeof window.ResizeObserver === 'function') {
|
|
1557
|
+
observer = new window.ResizeObserver(measure)
|
|
1558
|
+
observer.observe(node)
|
|
1559
|
+
}
|
|
1560
|
+
return function () {
|
|
1561
|
+
disposed = true
|
|
1562
|
+
if (deferredId !== null) {
|
|
1563
|
+
if (hasRaf && typeof window.cancelAnimationFrame === 'function') window.cancelAnimationFrame(deferredId)
|
|
1564
|
+
else window.clearTimeout(deferredId)
|
|
1565
|
+
}
|
|
1566
|
+
if (observer !== null) observer.disconnect()
|
|
1567
|
+
}
|
|
1568
|
+
})
|
|
1569
|
+
|
|
1331
1570
|
if (current !== spec.value) return null
|
|
1332
1571
|
|
|
1333
1572
|
// A completely hidden row leaves nothing on screen — no chips, no pill,
|
|
@@ -1389,6 +1628,43 @@ window.__ModuleLoader__.load({
|
|
|
1389
1628
|
if (spec.compact) rowClass += ' dqp-dock-tool'
|
|
1390
1629
|
if (spec.inset) rowClass += ' dqp-dock-inset'
|
|
1391
1630
|
|
|
1631
|
+
// Available width comes from the real DOM measurement. The test probe is
|
|
1632
|
+
// only consulted when a test has explicitly enabled it, so a stale
|
|
1633
|
+
// global cannot change a production render in another session. Without
|
|
1634
|
+
// either measurement we render the full row — safe degradation.
|
|
1635
|
+
var probeActive = probeIsActive()
|
|
1636
|
+
var available = probeActive && widthFitProbe.available !== null
|
|
1637
|
+
? widthFitProbe.available
|
|
1638
|
+
: finitePx(metricsRef.current.available)
|
|
1639
|
+
// Probe widths are an array indexed by usable position (test contract);
|
|
1640
|
+
// the DOM cache is keyed by phrase.id so shedding cannot shift indices.
|
|
1641
|
+
var measured = probeActive ? widthFitProbe.phrases : null
|
|
1642
|
+
var phraseWidths = usable.map(function (phrase, index) {
|
|
1643
|
+
if (measured !== null && finitePx(measured[index]) !== null) return widthOf(measured[index])
|
|
1644
|
+
var fromDom = finitePx(metricsRef.current.phrases[phrase.id])
|
|
1645
|
+
if (fromDom !== null) return widthOf(fromDom)
|
|
1646
|
+
var caption = phraseCaption(phrase)
|
|
1647
|
+
var units = 0
|
|
1648
|
+
for (var ci = 0; ci < caption.length; ci += 1) {
|
|
1649
|
+
units += caption.charCodeAt(ci) > 255 ? 12 : 7
|
|
1650
|
+
}
|
|
1651
|
+
return Math.min(spec.compact ? 130 : 200, units + (spec.compact ? 22 : 26))
|
|
1652
|
+
})
|
|
1653
|
+
var collapseWidth = probeActive && widthFitProbe.collapseWidth !== null
|
|
1654
|
+
? widthFitProbe.collapseWidth
|
|
1655
|
+
: widthOf(metricsRef.current.collapseWidth) || 24
|
|
1656
|
+
var manageWidth = probeActive && widthFitProbe.manageWidth !== null
|
|
1657
|
+
? widthFitProbe.manageWidth
|
|
1658
|
+
: widthOf(metricsRef.current.manageWidth) || 24
|
|
1659
|
+
var plan = fitRowToWidth(available, {
|
|
1660
|
+
phraseWidths: phraseWidths,
|
|
1661
|
+
collapseWidth: collapseWidth,
|
|
1662
|
+
manageWidth: manageWidth,
|
|
1663
|
+
manage: manageEntry !== 'hidden',
|
|
1664
|
+
gap: CHIP_GAP,
|
|
1665
|
+
})
|
|
1666
|
+
var visiblePhrases = usable.slice(0, plan.phraseCount)
|
|
1667
|
+
|
|
1392
1668
|
var children = [h('style', { key: 'style' }, DOCK_CSS)]
|
|
1393
1669
|
if (folded) {
|
|
1394
1670
|
// One pill keeps the caret-insertion path reachable: opening it is a
|
|
@@ -1408,18 +1684,19 @@ window.__ModuleLoader__.load({
|
|
|
1408
1684
|
}, dockIcon('expand')),
|
|
1409
1685
|
))
|
|
1410
1686
|
} else {
|
|
1411
|
-
children.push(h('div', { key: 'row', className: rowClass },
|
|
1412
|
-
|
|
1687
|
+
children.push(h('div', { key: 'row', ref: rowRef, className: rowClass },
|
|
1688
|
+
visiblePhrases.map(function (phrase, index) {
|
|
1413
1689
|
return h('button', {
|
|
1414
1690
|
key: phrase.id + ':' + index,
|
|
1415
1691
|
type: 'button',
|
|
1416
1692
|
className: 'dqp-chip',
|
|
1693
|
+
'data-dqp-phrase-id': phrase.id,
|
|
1417
1694
|
title: phrase.text,
|
|
1418
1695
|
'aria-label': phraseCaption(phrase) + ' — ' + t('dock.tooltip'),
|
|
1419
1696
|
onClick: function () { activate(phrase) },
|
|
1420
1697
|
}, phraseCaption(phrase))
|
|
1421
1698
|
}),
|
|
1422
|
-
h('button', {
|
|
1699
|
+
plan.collapse ? h('button', {
|
|
1423
1700
|
key: 'collapse',
|
|
1424
1701
|
type: 'button',
|
|
1425
1702
|
className: 'dqp-chip dqp-chip-icon dqp-chip-collapse',
|
|
@@ -1430,15 +1707,15 @@ window.__ModuleLoader__.load({
|
|
|
1430
1707
|
setPeeked(false)
|
|
1431
1708
|
setCollapsed(true)
|
|
1432
1709
|
},
|
|
1433
|
-
}, dockIcon('collapse')),
|
|
1434
|
-
manageEntry
|
|
1710
|
+
}, dockIcon('collapse')) : null,
|
|
1711
|
+
plan.manage && manageEntry !== 'hidden' ? h('button', {
|
|
1435
1712
|
key: 'manage',
|
|
1436
1713
|
type: 'button',
|
|
1437
1714
|
className: 'dqp-chip dqp-chip-manage dqp-chip-icon' + (manageEntry === 'text' ? ' dqp-chip-manage-icon' : ''),
|
|
1438
1715
|
title: t('dock.manage'),
|
|
1439
1716
|
'aria-label': t('dock.manage'),
|
|
1440
1717
|
onClick: handleManage,
|
|
1441
|
-
}, dockIcon('manage')),
|
|
1718
|
+
}, dockIcon('manage')) : null,
|
|
1442
1719
|
))
|
|
1443
1720
|
}
|
|
1444
1721
|
if (showHint[0]) {
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
这份文档写给要继续改 `client.js` 的人:它怎么挂进 DSH、数据放在哪、以及哪些约束不能碰。
|
|
4
4
|
|
|
5
|
+
## 目录
|
|
6
|
+
|
|
7
|
+
- [插件形态](#插件形态)
|
|
8
|
+
- [客户端入口](#客户端入口)
|
|
9
|
+
- [插槽](#插槽)
|
|
10
|
+
- [数据层](#数据层)
|
|
11
|
+
- [宽度降级(按实际宽度逐级舍弃)](#宽度降级按实际宽度逐级舍弃)
|
|
12
|
+
- [样式](#样式)
|
|
13
|
+
- [测试](#测试)
|
|
14
|
+
- [兼容性注意](#兼容性注意)
|
|
15
|
+
|
|
5
16
|
## 插件形态
|
|
6
17
|
|
|
7
18
|
DSH 的插件是「bundle」:一个 npm 包 + 一行 Cordis patch。本仓库的 Host 侧是空壳,所有能力都在客户端:
|
|
@@ -15,7 +26,9 @@ DSH 的插件是「bundle」:一个 npm 包 + 一行 Cordis patch。本仓库
|
|
|
15
26
|
| `icon.svg` | 插件列表图标 |
|
|
16
27
|
| `index.json` | 插件市场索引(format 1),让 Discover 能搜到并安装本插件 |
|
|
17
28
|
|
|
18
|
-
`package.json` 里声明 `dsh.client.platform = "web"`、`immediately: true`、`inject: ["@deepseek-ai/dsh-client-ui-conversation"]`;`dsh.bundle.patch` 指向 patch 文件。`engines.dsh` 声明兼容的 DSH 版本,市场索引与 `plugin_manager`
|
|
29
|
+
`package.json` 里声明 `dsh.client.platform = "web"`、`immediately: true`、`inject: ["@deepseek-ai/dsh-client-ui-conversation"]`;`dsh.bundle.patch` 指向 patch 文件。`engines.dsh` 声明兼容的 DSH 版本,市场索引与 `plugin_manager` 用它判断可装性。
|
|
30
|
+
|
|
31
|
+
> 没有构建步骤,改完 `client.js` 让渲染进程重载即可。
|
|
19
32
|
|
|
20
33
|
## 客户端入口
|
|
21
34
|
|
|
@@ -34,7 +47,7 @@ return {
|
|
|
34
47
|
|
|
35
48
|
- `require('react')` 取的是 DSH 浏览器端的 React,不需要打包。
|
|
36
49
|
- 所有注册都放进 `apply`,用 `ctx.slots.inject` 等待插槽出现;插槽消失时框架会自动调用注册返回的清理函数。
|
|
37
|
-
|
|
50
|
+
> 组件不能往 `document.body` 追加东西,也不能读别的插件的 DOM。
|
|
38
51
|
|
|
39
52
|
## 插槽
|
|
40
53
|
|
|
@@ -72,18 +85,30 @@ return {
|
|
|
72
85
|
|
|
73
86
|
短语条目里除了 `id` / `label` / `text` 还有一个 `hidden` 布尔值(`normalize()` 缺成 `false`)。短语行渲染前会滤掉 `hidden === true` 的条目,管理页则照常渲染并用 `dqp-row-muted` 变暗、加「已隐藏」徽标。
|
|
74
87
|
|
|
75
|
-
可见性判断也在 `DockChips` 里,顺序固定:先把 hook
|
|
88
|
+
可见性判断也在 `DockChips` 里,顺序固定:先把 hook 全部跑完(数量不随状态变化),再依次判断位置、彻底隐藏、折叠、宽度降级:
|
|
76
89
|
|
|
77
|
-
```
|
|
90
|
+
```js
|
|
78
91
|
if (current !== spec.value) return null // 只有选中位置的那一行渲染
|
|
79
92
|
if (hidden) return null // 彻底隐藏:什么都不渲染,连胶囊都不留
|
|
80
93
|
hasDraft = draft.trim() !== '' || attachments > 0
|
|
81
94
|
folded = collapsed || (autoHide === 'fold' && hasDraft && !peeked)
|
|
95
|
+
plan = fitRowToWidth(available, {...}) // 只在未折叠时按可用宽度决定渲染哪些控件
|
|
82
96
|
```
|
|
83
97
|
|
|
84
98
|
`hidden` 优先于折叠:即使之前用「收起」写过 `collapsed='1'`,隐藏后也不会冒出胶囊。设置页下拉选「显示整排」时同时 `setHidden(false)` 与 `setCollapsed(false)`,直接回到整排;选「收成胶囊」写 `hidden='0'`、`collapsed='1'`;选「彻底隐藏」只写 `hidden='1'`。
|
|
85
99
|
|
|
86
|
-
|
|
100
|
+
### 宽度降级(按实际宽度逐级舍弃)
|
|
101
|
+
|
|
102
|
+
短语行不再靠固定 px 断点,而是测「实际可用宽度」后动态舍弃控件:
|
|
103
|
+
|
|
104
|
+
- `measure()` 读 `node.clientWidth` 并缓存每个胶囊的实测宽度(`metricsRef`),每次渲染同步测一遍;`ResizeObserver` 存在时再观察整行节点,容器无 React 更新地变化时补一次测量。没有 DOM 或拿不到宽度就渲染整排(安全降级)。
|
|
105
|
+
- **首帧兜底**:首帧常报 `clientWidth === 0`(真机 WebView 尤其常见),单靠 `ResizeObserver` 不保证补测。首次挂载时若宽度仍为 0,用 `requestAnimationFrame`(缺失时降级 `setTimeout(0)`)排有界延迟补测——只在宽度仍不可用时重试,最多 3 次;即使 `ResizeObserver` 不存在也会完成二次测量。只有测量值(available / 尾部宽度 / 短语宽度)真变化才更新 `metricsRef` 并 `bumpWidth` 触发重渲染,避免假变化抖动;组件卸载时置 `disposed` 并清掉待执行的 rAF / timeout 与 observer,防止跨会话残留。
|
|
106
|
+
- **按 `phrase.id` 缓存**:短语 chip 带 `data-dqp-phrase-id`,`metricsRef.current.phrases` 的键就是 `phrase.id`,读取时用 `metricsRef.current.phrases[phrase.id]`;被舍弃的短语保留其缓存宽度,否则丢一个后下一帧估算成 0px 会让行来回抖动。测量遍历子节点时按类名分流:`.dqp-chip-collapse` / `.dqp-chip-manage` 的宽度单独记到 `collapseWidth` / `manageWidth`,`.dqp-pill` 与非 `.dqp-chip` 子节点直接跳过,没有有效 `data-dqp-phrase-id` 的不写入短语缓存——避免按下标缓存时被折叠 pill 与空洞污染,导致同一宽度下舍弃结果漂移。
|
|
107
|
+
- 无 DOM 的纯函数 `fitRowToWidth(available, options)` 计算存活方案 `{ phraseCount, collapse, manage }`:先算当前总占用(各胶囊宽 + 间距),超宽时按固定优先级舍弃——**收起按钮(`.dqp-chip-collapse`)→ 管理按钮(`.dqp-chip-manage`)→ 短语从末尾往前逐个(`phraseCount--`)**;**第一条可用短语永不丢弃**,一条短语都没有时收起与管理仍可达。管理入口设为 `hidden` 时 `manage` 从一开始就是 `false`。
|
|
108
|
+
- 宽度来源:生产渲染只读真实 DOM 测量(`metricsRef.current.available` / 按 id 的短语缓存);测试探针仅在显式启用后才参与(见下文「测试」)。短语宽度依次取探针(启用时,按可用位置下标,属测试契约)→ DOM 缓存(按 `phrase.id`)→ 按标题字数估算(工具行封顶 130px,普通行 200px)。窗口变宽后同一套规则会把控件自动加回来。
|
|
109
|
+
- 窄屏自动舍弃是纯渲染层行为,不写任何 `localStorage` 键、不新增设置项;三态 full/pill/hidden、自动收起 / peek、单条隐藏、管理入口三态等既有行为不变。「收起」在窄屏不可见时,仍可通过草稿自动收起或设置页「短语行显示 = 收成胶囊」折叠整排,管理入口不可见时仍可从设置页进入。
|
|
110
|
+
|
|
111
|
+
管理入口在同一个 `DockChips` 里按 `manage.v1` 渲染:`text` 是原来的「管理」文字 chip,`icon` 是同样点击行为的齿轮 `svg`(`aria-label` 仍取 `dock.manage`),`hidden` 连按钮都不渲染。三种模式都不影响短语 chips、「收起」chip 和管理页本身;`hidden` 模式下宽度拟合的 `plan.manage` 恒为 `false`,不再为已隐藏的入口预留宽度。
|
|
87
112
|
|
|
88
113
|
`peeked` 是组件内部的临时状态:点胶囊时置 `true` 并同时展开(`setCollapsed(false)`),这样"临时看一眼"不会写进 `localStorage`,草稿清空后 `useEffect` 会把它清掉。手动收起(`setCollapsed(true)`)是持久状态,跨会话保留。
|
|
89
114
|
|
|
@@ -104,7 +129,15 @@ folded = collapsed || (autoHide === 'fold' && hasDraft && !peeked)
|
|
|
104
129
|
- 主按钮:`--dsw-alias-button-primary-fill` + `--dsw-alias-label-primary-foreground`(与宿主 `Button` 的 primary 变体一致,深浅主题都对得上)
|
|
105
130
|
- 焦点:`--dsw-focus-ring-width` / `--dsw-focus-ring-color`
|
|
106
131
|
|
|
107
|
-
不要写死颜色,也不要用 `prefers-color-scheme` 判断主题——DSH 用 `data-ds-dark-theme` 切换,硬编码会两边都对不上。
|
|
132
|
+
> 不要写死颜色,也不要用 `prefers-color-scheme` 判断主题——DSH 用 `data-ds-dark-theme` 切换,硬编码会两边都对不上。
|
|
133
|
+
|
|
134
|
+
短语行的宽度拟合相关样式:`DOCK_CSS` 里 `.dqp-dock` 用 `display:flex; flex-wrap:wrap; gap:6px; min-width:0`,`.dqp-chip` 是 `flex:0 0 auto` 并带 `max-width`(普通行 200px / 工具行 130px)——胶囊不收缩、超出就换行,实测宽度才稳定可缓存;`CHIP_GAP = 6` 与 CSS 的 `gap:6px` 保持一致,拟合计算才和实际占用对得上。工具行 `.dqp-dock-tool` 另有 `flex-wrap:nowrap; overflow-x:auto`,窄屏在滚动之上仍先按上述顺序舍弃控件。
|
|
135
|
+
|
|
136
|
+
设置 / 管理页(`MANAGER_CSS`)另有一套小屏排版优化, `@media (max-width:560px)` 段:选项标签与下拉同行(长标签自然换行)、每项说明完整保留在控件下方、所有按钮与图标触控目标 ≥36px、textarea 最小高度 52px、预览改为 `white-space:normal` 可换行不再省略号截断、区块标题与两个按钮平分一行、`.dqp-page` 页边距收紧到 `12px`,所有长文本加 `overflow-wrap:anywhere` 防溢出。
|
|
137
|
+
|
|
138
|
+
> **这套规则纯 CSS、只改排版,不删任何 DOM 元素、不改任何状态或功能。**
|
|
139
|
+
|
|
140
|
+
它与上面的短语行宽度降级是两套独立逻辑:`fitRowToWidth` 按实际宽度逐级舍弃控件(渲染层行为),而管理页小屏优化从不舍弃元素——二者不可混为一谈。
|
|
108
141
|
|
|
109
142
|
「输入框上方」的位置需要复制宿主 dock 的几何,否则会贴在会话栏左缘:
|
|
110
143
|
|
|
@@ -120,7 +153,11 @@ margin: 0 auto;
|
|
|
120
153
|
|
|
121
154
|
与收起/隐藏相关的断言:点「收起」写入 `collapsed.v1='1'` 且只剩 `.dqp-pill`;点胶囊回到 `'0'` 并恢复六个 chip;草稿出现时默认折成胶囊、展开后点第二条仍插到光标处;`autohide` 切到 `keep` 后草稿不再折叠;`#dqp-rowmode` 默认 `full`、选 `pill` 写 `collapsed='1'` 且 dock 只剩一个 `.dqp-pill`、选 `hidden` 写 `hidden='1'` 且整排组件返回 `null`(连胶囊都没有)、hidden 时改选 `pill` 会清掉 `hidden` 并折回胶囊、再选 `full` 把两个键都写成 `'0'` 并恢复六个 chip;管理页在 hidden 时显示「整排已隐藏」徽标与恢复提示。`#dqp-manage` 默认 `text`(显示「管理」chip)、`icon` 渲染含 `svg` 且无文字、`aria-label` 仍是「管理」、`hidden` 时行尾没有管理 chip 但短语 chips 照常渲染,且三态分别持久化到 `manage.v1`。隐藏一条后短语行少一个 chip、管理页仍是四张卡片且第一张带 `dqp-row-muted`;字典还有一条 zh/en 键集合完全对称的断言。
|
|
122
155
|
|
|
123
|
-
`
|
|
156
|
+
与宽度降级相关的断言走测试探针 `window.__DQP_WIDTH_FIT__`(`fit` 纯函数 + `setAvailableWidth` / `setChipWidths` / `setTrailingWidths` 注入宽度 + `reset` 复位;沙箱没有 DOM / ResizeObserver,由探针代替真实测量):纯函数 `fit` 依次覆盖**四级**——够宽全部保留 → 稍窄先丢 `collapse` → 更窄丢 `manage` → 再窄短语从末尾往前逐个减少 → 极窄只剩 1 个短语且两个尾部控件都没了;另测 `manage:false` 入参恒不渲染管理、无短语时收起与管理仍可达。DOM 渲染段用探针固定每个胶囊宽度,按几个宽度档位(渲染名前缀 `wf-`)断言存活 chip 的数量与顺序,末尾 `reset()` 恢复真实测量。
|
|
157
|
+
|
|
158
|
+
探针状态收在 `factory` 闭包内、默认 `enabled = false`:生产渲染不看它,避免别的会话在全局 `window` 上留下的旧值污染本次渲染。三个 setter(`setAvailableWidth` / `setChipWidths` / `setTrailingWidths`)调用时自动置 `enabled = true`,测试无需额外调用;另有 `enable()` / `disable()` 显式开关,`reset()` 会同时置 `false` 并清空全部注入值。探针的短语宽度数组仍按可用位置下标(测试契约),与生产缓存按 `phrase.id` 索引互不干扰。
|
|
159
|
+
|
|
160
|
+
`test/preview.mjs` 把组件渲染成静态 HTML,拼上宿主主题 CSS,可用无头 Chromium 截图,用来肉眼核对深浅两套主题;它还会渲染「整排完全隐藏」的管理页状态和三态短语行 / 三态管理入口的状态页(`/tmp/dqp-modes-*.html`),并断言隐藏时短语行序列化出来是空字符串;另有一组「窄屏宽度降级」预览(宽 / 中 / 窄 / 极窄四档),便于肉眼核对舍弃顺序。`docs/images/` 下的图就是它产出的**界面示意图**(图内带「界面示意图」标题),不是真机截屏。
|
|
124
161
|
|
|
125
162
|
## 兼容性注意
|
|
126
163
|
|