dsh-codex-model-effort-ui 1.1.6 → 1.1.7
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 +20 -7
- package/client.effort.js +2 -2
- package/client.js +99 -81
- package/client.styles.js +42 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
- [推理强度面板](#推理强度面板)
|
|
17
17
|
- [模型面板](#模型面板)
|
|
18
18
|
- [使用](#使用)
|
|
19
|
+
- [实现要点](#实现要点)
|
|
19
20
|
- [兼容性与已知限制](#兼容性与已知限制)
|
|
20
21
|
- [开发](#开发)
|
|
21
22
|
- [文件结构](#文件结构)
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
|
|
25
26
|
## 这是什么
|
|
26
27
|
|
|
27
|
-
DSH 输入框上原本只有一枚很小的模型按钮。本插件用 `priority: -1`
|
|
28
|
+
DSH 输入框上原本只有一枚很小的模型按钮。本插件用 `priority: -1` **接管** `conversation.input.model` 座位,点开是一个 Codex 风格的弹层,里面是两块面板:
|
|
28
29
|
|
|
29
30
|
| 面板 | 内容 |
|
|
30
31
|
|---|---|
|
|
@@ -42,8 +43,8 @@ dsh plugin --profile web add dsh-codex-model-effort-ui # NPM 源
|
|
|
42
43
|
dsh plugin --profile web add github:zxclf/dsh-codex-model-effort-ui # GitHub 源
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
>
|
|
46
|
-
>
|
|
46
|
+
> [!NOTE]
|
|
47
|
+
> **DSH Desktop 需在应用内手动安装**,且安装后需**重启 DSH Desktop** 才生效(客户端 bundle 在启动时注入)。
|
|
47
48
|
> 安装后,输入框右侧的模型按钮会变成 Codex 风格的收起态按钮(见 [使用](#使用))。
|
|
48
49
|
|
|
49
50
|
---
|
|
@@ -99,11 +100,24 @@ dsh plugin --profile web add github:zxclf/dsh-codex-model-effort-ui # GitHub 源
|
|
|
99
100
|
|
|
100
101
|
---
|
|
101
102
|
|
|
103
|
+
## 实现要点
|
|
104
|
+
|
|
105
|
+
几个值得知道的实现决策(便于二次开发 / 排查):
|
|
106
|
+
|
|
107
|
+
- **浮层 portal 到 `document.body`**:宿主给输入区座位 `.composerSeat` 写了 `will-change: transform`,按规范这会让 seat 成为每个 `position: fixed` 后代的包含块,导致弹层整体平移并被 `z-index: 9` 层叠上下文压住。弹层与 tooltip 一并 portal 到 body 后,`fixed` 重新相对视口解析,`z-index` 在根上下文生效。DSH 自家浮层(StatsPills / TurnUsagePanel 等)采用同一做法。
|
|
108
|
+
- **强度领域纯函数独立成块**:阶梯归类、调色板、混色、滑轨指针映射、星尘/绽放生成都在 `client.effort.js`,不依赖 React/DOM,可用 Node 直接单测。
|
|
109
|
+
- **调色板过三道 WCAG 底线**并由测试守护:填充色 vs 未填充滑轨 `≥ 2.5`、圆钮 vs 填充色 `≥ 2.2`、标题墨色 vs 卡片 `≥ 4.5`(深浅两主题分别验证)。
|
|
110
|
+
- **星尘 / 绽放确定性生成**:相位用低差异序列、其余用哈希,不用 `Math.random`,重新渲染不会重新洗牌。
|
|
111
|
+
- **fail-open 约定**:localStorage、懒加载分块、`remote.agentTeams` 注入等全部有保护,失败只损失对应增强功能,绝不影响输入框。
|
|
112
|
+
- **焦点陷阱**:弹层 `role="dialog"`,打开期间拦下 `Tab` 在首/末可聚焦元素处循环,焦点始终圈在弹层内。
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
102
116
|
## 兼容性与已知限制
|
|
103
117
|
|
|
104
118
|
| 项 | 说明 |
|
|
105
119
|
|---|---|
|
|
106
|
-
| DSH | 已在 **DSH Desktop 0.2.1-rc.2(Windows)** 实机验证;`0.2.0-rc.2`
|
|
120
|
+
| DSH | 已在 **DSH Desktop 0.2.1-rc.2(Windows)** 实机验证;`0.2.0-rc.2` 仍可用(依赖 `conversation.input.model` slot 契约,官方若改动该形状则本插件静默退回、不破坏官方界面) |
|
|
107
121
|
| 主题 | 跟随 DSH 主题令牌(`--dsw-*`),令牌缺失时回退到中性灰 + `#4d93f8` 蓝 |
|
|
108
122
|
|
|
109
123
|
### 已知限制
|
|
@@ -124,12 +138,11 @@ pnpm install # 安装开发依赖
|
|
|
124
138
|
pnpm check # 运行 lint + 测试
|
|
125
139
|
```
|
|
126
140
|
|
|
127
|
-
|
|
128
141
|
| 命令 | 作用 |
|
|
129
142
|
|---|---|
|
|
130
143
|
| `pnpm install` | 首次安装 ESLint 等开发依赖 |
|
|
131
144
|
| `pnpm lint` | ESLint(含 react-hooks 规则) |
|
|
132
|
-
| `pnpm test` | node:test,纯函数与 i18n
|
|
145
|
+
| `pnpm test` | node:test,纯函数与 i18n 回归(11 个用例) |
|
|
133
146
|
| `pnpm check` | lint + test |
|
|
134
147
|
|
|
135
148
|
`pnpm-workspace.yaml` 关闭了 peer 自动安装:`@deepseek-ai/dsh` 是宿主提供的运行时依赖。
|
|
@@ -145,7 +158,7 @@ pnpm check # 运行 lint + 测试
|
|
|
145
158
|
| `client.styles.js` | CSS 字符串与布局度量 `METRICS` |
|
|
146
159
|
| `index.js` | 插件入口(`apply` 空实现) |
|
|
147
160
|
|
|
148
|
-
测试位于 `test/`:`effort.test.mjs` 覆盖强度领域函数与调色板对比度底线,`locale.test.mjs`
|
|
161
|
+
测试位于 `test/`:`effort.test.mjs` 覆盖强度领域函数与调色板对比度底线,`locale.test.mjs` 覆盖词典键集、占位符一致性和硬编码文案检查,`loader.mjs` 提供最小 `window.__ModuleLoader__` 沙箱。
|
|
149
162
|
|
|
150
163
|
---
|
|
151
164
|
|
package/client.effort.js
CHANGED
|
@@ -147,7 +147,7 @@ window.__ModuleLoader__.load({
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function rank(id) {
|
|
150
|
-
const i = EFFORT_ORDER.indexOf(String(id).toLowerCase());
|
|
150
|
+
const i = EFFORT_ORDER.indexOf(String(id).toLowerCase().trim());
|
|
151
151
|
return i === -1 ? 50 : i;
|
|
152
152
|
}
|
|
153
153
|
/** 按 Codex 阶梯顺序排序模型声明的强度项。 */
|
|
@@ -157,7 +157,7 @@ window.__ModuleLoader__.load({
|
|
|
157
157
|
/** 强度的本地化标签;无法匹配时回退到模型自身的名称。 */
|
|
158
158
|
function effortLabel(effort, t) {
|
|
159
159
|
if (!effort) return '';
|
|
160
|
-
const key = EFFORT_KEY[String(effort.id).toLowerCase()];
|
|
160
|
+
const key = EFFORT_KEY[String(effort.id).toLowerCase().trim()];
|
|
161
161
|
if (key) {
|
|
162
162
|
const translated = t(key);
|
|
163
163
|
// 键缺失时 locale 查找会把键名原样返回
|
package/client.js
CHANGED
|
@@ -12,6 +12,7 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
id: 'dsh-codex-model-effort-ui',
|
|
13
13
|
factory(require) {
|
|
14
14
|
const React = require('react');
|
|
15
|
+
const { createPortal } = require('react-dom');
|
|
15
16
|
const h = React.createElement;
|
|
16
17
|
const { useState, useEffect, useLayoutEffect, useRef, useSyncExternalStore, useMemo, lazy, Suspense } = React;
|
|
17
18
|
|
|
@@ -169,38 +170,24 @@ window.__ModuleLoader__.load({
|
|
|
169
170
|
* 可复用的定位 / 状态 Hook
|
|
170
171
|
* ================================================================== */
|
|
171
172
|
|
|
172
|
-
/*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
function
|
|
176
|
-
if (probe) {
|
|
177
|
-
const box = probe.getBoundingClientRect();
|
|
178
|
-
return { left: box.left, top: box.top, bottom: box.bottom };
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
left: 0,
|
|
182
|
-
top: 0,
|
|
183
|
-
bottom: typeof window === 'undefined' ? 0 : window.innerHeight
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function positionAbove(anchor, tip, box, fallbackW, fallbackH) {
|
|
173
|
+
/* 弹层与 tooltip 都通过 createPortal 渲染到 document.body(见 render 处
|
|
174
|
+
* 的说明),因此它们的 position:fixed 恒相对视口解析——不必再测量包含块,
|
|
175
|
+
* 直接写视口坐标即可。 */
|
|
176
|
+
function positionAbove(anchor, tip, fallbackW, fallbackH) {
|
|
188
177
|
if (!anchor || !tip) return;
|
|
189
178
|
const r = anchor.getBoundingClientRect();
|
|
190
179
|
const tw = tip.offsetWidth || fallbackW;
|
|
191
180
|
const th = tip.offsetHeight || fallbackH;
|
|
192
181
|
const left = Math.max(8, Math.min(r.left + r.width / 2 - tw / 2, window.innerWidth - tw - 8));
|
|
193
182
|
const top = Math.max(8, r.top - th - 7);
|
|
194
|
-
tip.style.left = `${left
|
|
195
|
-
tip.style.top = `${top
|
|
183
|
+
tip.style.left = `${left}px`;
|
|
184
|
+
tip.style.top = `${top}px`;
|
|
196
185
|
}
|
|
197
186
|
|
|
198
|
-
function useAnchoredTip(shown, anchorRef, tipRef,
|
|
187
|
+
function useAnchoredTip(shown, anchorRef, tipRef, fallbackW, fallbackH) {
|
|
199
188
|
useLayoutEffect(() => {
|
|
200
189
|
if (!shown) return;
|
|
201
|
-
const place = () => positionAbove(
|
|
202
|
-
anchorRef.current, tipRef.current, containingBoxOf(probeRef.current), fallbackW, fallbackH
|
|
203
|
-
);
|
|
190
|
+
const place = () => positionAbove(anchorRef.current, tipRef.current, fallbackW, fallbackH);
|
|
204
191
|
place();
|
|
205
192
|
window.addEventListener('resize', place);
|
|
206
193
|
document.addEventListener('scroll', place, true);
|
|
@@ -208,43 +195,48 @@ window.__ModuleLoader__.load({
|
|
|
208
195
|
window.removeEventListener('resize', place);
|
|
209
196
|
document.removeEventListener('scroll', place, true);
|
|
210
197
|
};
|
|
211
|
-
}, [shown, anchorRef, tipRef,
|
|
198
|
+
}, [shown, anchorRef, tipRef, fallbackW, fallbackH]);
|
|
212
199
|
}
|
|
213
200
|
|
|
214
201
|
/* 弹出面板的定位、高度余量与外部关闭 / Escape。
|
|
215
202
|
* 回调经 ref 读取,监听器只随 open 重绑一次,避免闭包过期。 */
|
|
216
|
-
function usePopoverLayout({ open, rootRef, popupRef,
|
|
203
|
+
function usePopoverLayout({ open, rootRef, popupRef, triggerRef, onOutside, onEscape }) {
|
|
217
204
|
const [room, setRoom] = useState(0);
|
|
218
205
|
const handlersRef = useRef({ onOutside, onEscape });
|
|
219
206
|
useLayoutEffect(() => { handlersRef.current = { onOutside, onEscape }; });
|
|
220
207
|
|
|
221
|
-
/*
|
|
208
|
+
/* 把触发按钮对齐到弹层:直接写视口 top/left,并回写高度余量。
|
|
222
209
|
* 只读 ref 与 window,因此是引用稳定的——既能被下面的 layout effect
|
|
223
210
|
* 绑定到事件上,也能被 `primeRoom` 在打开前直接调用,把首帧的
|
|
224
|
-
* left
|
|
211
|
+
* top/left 一并预置(否则首帧会用 CSS 里的回退坐标画一帧再跳正)。 */
|
|
225
212
|
const align = React.useCallback(() => {
|
|
226
213
|
const trigger = triggerRef.current?.getBoundingClientRect();
|
|
227
214
|
const popup = popupRef.current;
|
|
228
|
-
if (!trigger || !popup || !
|
|
215
|
+
if (!trigger || !popup || !popup.isConnected) return;
|
|
229
216
|
const width = Math.min(272, window.innerWidth - 24);
|
|
230
217
|
const left = Math.max(12, Math.min((trigger.left + trigger.right - width) / 2, window.innerWidth - width - 12));
|
|
231
|
-
/*
|
|
232
|
-
*
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
rootRef.current.style.setProperty(`--${P}-bottom`, `${Math.max(12, box.bottom - trigger.top + 8)}px`);
|
|
218
|
+
/* 弹出面板 portal 到 body,position:fixed 恒相对视口,所以直接用
|
|
219
|
+
* 视口坐标:面板底边停在触发按钮上方 8px。 */
|
|
220
|
+
popup.style.setProperty(`--${P}-left`, `${left}px`);
|
|
221
|
+
popup.style.setProperty(`--${P}-top`, `${Math.max(12, trigger.top - popup.offsetHeight - 8)}px`);
|
|
236
222
|
/* 触发按钮上方的空间:驱动高度钳制,同时写回 state,让 render
|
|
237
223
|
* 不必自己读布局。 */
|
|
238
224
|
const roomAbove = Math.max(120, trigger.top - 20);
|
|
239
|
-
|
|
225
|
+
popup.style.setProperty(`--${P}-room`, `${roomAbove}px`);
|
|
240
226
|
setRoom(prev => (prev === roomAbove ? prev : roomAbove));
|
|
241
|
-
}, [
|
|
227
|
+
}, [popupRef, triggerRef]);
|
|
242
228
|
|
|
243
229
|
useLayoutEffect(() => {
|
|
244
230
|
if (!open) return;
|
|
245
231
|
let frame = 0;
|
|
246
232
|
function outside(event) {
|
|
247
|
-
|
|
233
|
+
/* 弹出面板 portal 到 body,已不在 `.cmes-root` 之内:外部点击判定
|
|
234
|
+
* 必须把面板与触发按钮一并视为「内部」,否则点面板自身会把它关掉。 */
|
|
235
|
+
const target = event.target;
|
|
236
|
+
if (rootRef.current?.contains(target)) return;
|
|
237
|
+
if (popupRef.current?.contains(target)) return;
|
|
238
|
+
if (target instanceof Node && triggerRef.current?.contains(target)) return;
|
|
239
|
+
handlersRef.current.onOutside(event);
|
|
248
240
|
}
|
|
249
241
|
function escape(event) {
|
|
250
242
|
if (event.key !== 'Escape') return;
|
|
@@ -261,13 +253,13 @@ window.__ModuleLoader__.load({
|
|
|
261
253
|
window.addEventListener('resize', resized);
|
|
262
254
|
document.addEventListener('scroll', align, true);
|
|
263
255
|
/* 输入区是多行的:换行 / 贴图 / 切会话会让触发按钮在**既不产生 window
|
|
264
|
-
* resize、也未必冒泡出 scroll 事件**的情况下移动,而弹层的
|
|
256
|
+
* resize、也未必冒泡出 scroll 事件**的情况下移动,而弹层的 top 是
|
|
265
257
|
* 打开那一刻按 trigger.top 算死的——按钮一动弹层不跟,于是相对按钮
|
|
266
258
|
* 上浮或下沉。用一个观察器盯住触发按钮的定位祖先(`offsetParent`,
|
|
267
|
-
* 正是那条 overflow:auto/hidden
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
259
|
+
* 正是那条 overflow:auto/hidden 的输入区链)与触发按钮本身:它们的
|
|
260
|
+
* 盒子尺寸一变(输入区长高、滚动条出现/消失、外框平移)就重跑
|
|
261
|
+
* `align`,把弹层重新锚定到当前按钮位置。观察器回调在绘制前触发,
|
|
262
|
+
* 因此漂移不会先画出来再纠正。
|
|
271
263
|
*
|
|
272
264
|
* 已知残留缺口:ResizeObserver 只对「盒子尺寸变化」敏感。若按钮因
|
|
273
265
|
* 某祖先的 CSS transform / 主动画被整体平移,而所有被观察盒子尺寸
|
|
@@ -279,7 +271,12 @@ window.__ModuleLoader__.load({
|
|
|
279
271
|
observer = new ResizeObserver(() => align());
|
|
280
272
|
const anchor = triggerRef.current?.offsetParent;
|
|
281
273
|
if (anchor) observer.observe(anchor);
|
|
282
|
-
if (
|
|
274
|
+
if (triggerRef.current) observer.observe(triggerRef.current);
|
|
275
|
+
/* 弹层自身也要观察:面板高度带 `.2s` 过渡,切换 pane(强度 <-> 模型列表)
|
|
276
|
+
* 时高度会动画变化,而 top 是按当时的 offsetHeight 算死的。只盯触发按钮
|
|
277
|
+
* 的话,高度一长弹层底边就往下压过触发按钮(实测 gap 变 -32px)。观察
|
|
278
|
+
* 弹层后,动画每一帧高度一变就重算 top,底边始终钉在按钮上方 8px。 */
|
|
279
|
+
if (popupRef.current) observer.observe(popupRef.current);
|
|
283
280
|
}
|
|
284
281
|
align();
|
|
285
282
|
return () => {
|
|
@@ -290,10 +287,10 @@ window.__ModuleLoader__.load({
|
|
|
290
287
|
if (observer) observer.disconnect();
|
|
291
288
|
cancelAnimationFrame(frame);
|
|
292
289
|
};
|
|
293
|
-
}, [open, align, rootRef, popupRef,
|
|
290
|
+
}, [open, align, rootRef, popupRef, triggerRef]);
|
|
294
291
|
|
|
295
292
|
/* 打开前先量一次:首帧就有正确的高度 **和位置**,不会先回退到 CSS 里的
|
|
296
|
-
* 回退坐标(left:12 /
|
|
293
|
+
* 回退坐标(left:12 / top:auto)再跳变。 */
|
|
297
294
|
function primeRoom() {
|
|
298
295
|
align();
|
|
299
296
|
}
|
|
@@ -521,7 +518,12 @@ window.__ModuleLoader__.load({
|
|
|
521
518
|
};
|
|
522
519
|
}, []);
|
|
523
520
|
|
|
524
|
-
|
|
521
|
+
/* liveRef 在拖拽期间持有 paintLive 写入的**连续**比例(非档位吸附值)。
|
|
522
|
+
* React 渲染滑轨 style 时若正在拖拽就读它,使两条 --pos 写入路径
|
|
523
|
+
* (paintLive 的 DOM 直写 与 React 的 style prop)写出同一个连续值——
|
|
524
|
+
* 否则越过档位阈值的那一帧 React 会把 --pos 改写回吸附位,圆钮偏离
|
|
525
|
+
* 指针半个档距再弹回(与「拖动期间无吸附跟随」的设计相矛盾)。 */
|
|
526
|
+
return { dragging, hovered, setHovered, pointerDown, pointerMove, finish, cancelDrag, keyDown, liveRef };
|
|
525
527
|
}
|
|
526
528
|
|
|
527
529
|
function SelectorImpl({ directory, load, select, available, locked, t, sessionId, setTeamMode, teamMode, css, M, U }) {
|
|
@@ -548,7 +550,6 @@ window.__ModuleLoader__.load({
|
|
|
548
550
|
const [subProvider, setSubProvider] = useState(null);
|
|
549
551
|
const rootRef = useRef(null);
|
|
550
552
|
const popupRef = useRef(null);
|
|
551
|
-
const probeRef = useRef(null);
|
|
552
553
|
const railRef = useRef(null);
|
|
553
554
|
const triggerRef = useRef(null);
|
|
554
555
|
const searchRef = useRef(null);
|
|
@@ -586,7 +587,7 @@ window.__ModuleLoader__.load({
|
|
|
586
587
|
const team = useTeamToggle({ teamMode, setTeamMode, available, t, onError: setError, mountedRef });
|
|
587
588
|
/* 弹出面板定位 / 高度余量 / 外部关闭 / Escape。 */
|
|
588
589
|
const { room, primeRoom } = usePopoverLayout({
|
|
589
|
-
open, rootRef, popupRef,
|
|
590
|
+
open, rootRef, popupRef, triggerRef,
|
|
590
591
|
onOutside: handleOutside, onEscape: handleEscape
|
|
591
592
|
});
|
|
592
593
|
/* 提交串行化:结束后清掉预览值。 */
|
|
@@ -601,9 +602,9 @@ window.__ModuleLoader__.load({
|
|
|
601
602
|
onMove: showEffort, onPick: chooseEffort,
|
|
602
603
|
onCancel: cancelPreview, U
|
|
603
604
|
});
|
|
604
|
-
useAnchoredTip(tipShown, fastBtnRef, tipRef,
|
|
605
|
-
useAnchoredTip(teamTipShown, teamInfoBtnRef, teamTipRef,
|
|
606
|
-
useAnchoredTip(resetTipShown, resetRef, resetTipRef,
|
|
605
|
+
useAnchoredTip(tipShown, fastBtnRef, tipRef, 120, 44);
|
|
606
|
+
useAnchoredTip(teamTipShown, teamInfoBtnRef, teamTipRef, 220, 60);
|
|
607
|
+
useAnchoredTip(resetTipShown, resetRef, resetTipRef, 140, 48);
|
|
607
608
|
|
|
608
609
|
const sparkles = useMemo(() => U.buildSparkles(22), [U]);
|
|
609
610
|
const bloomMotes = useMemo(() => U.buildBloom(U.BLOOM_COUNT), [U]);
|
|
@@ -1019,8 +1020,11 @@ window.__ModuleLoader__.load({
|
|
|
1019
1020
|
/* 绽放粒子是当前档位颜色向白色提亮——对 Ultra 而言正好落在
|
|
1020
1021
|
* 测量得到的 #ceb0fa 左右紫色,无需第二张硬编码表 */
|
|
1021
1022
|
[`--${P}-mote`]: U.mixHex(U.fillFor(displayed, dark), '#ffffff', dark ? 0.30 : 0.42),
|
|
1022
|
-
/*
|
|
1023
|
-
|
|
1023
|
+
/* 一个无量纲比例同时驱动圆钮和填充。拖拽期间改读 liveRef 里的
|
|
1024
|
+
* 连续比例,与 paintLive 的 DOM 直写保持同一个值——若这里仍用
|
|
1025
|
+
* 吸附比例 fraction,越过档位阈值的那一帧 React 会把它写回
|
|
1026
|
+
* 吸附位,圆钮偏离指针半个档距再弹回。 */
|
|
1027
|
+
[`--${P}-pos`]: rail.dragging ? (rail.liveRef.current ?? fraction) : fraction
|
|
1024
1028
|
},
|
|
1025
1029
|
role: 'slider', tabIndex: 0,
|
|
1026
1030
|
'aria-label': t('effort'),
|
|
@@ -1099,36 +1103,18 @@ window.__ModuleLoader__.load({
|
|
|
1099
1103
|
}))
|
|
1100
1104
|
: null);
|
|
1101
1105
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
else {
|
|
1115
|
-
/* 打开前先量一次可用高度,首帧就是正确值,不会高度弹跳。 */
|
|
1116
|
-
primeRoom();
|
|
1117
|
-
setPane(model ? 'effort' : 'models');
|
|
1118
|
-
setOpen(true);
|
|
1119
|
-
load();
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
},
|
|
1123
|
-
fast ? h('svg', { className: `${P}-bolt`, viewBox: '0 0 24 24', 'aria-hidden': true }, h('path', { d: ICON.bolt })) : null,
|
|
1124
|
-
h('span', { className: `${P}-compact` }, icon('model')),
|
|
1125
|
-
h('span', { className: `${P}-caption` },
|
|
1126
|
-
modelName),
|
|
1127
|
-
triggerLabel
|
|
1128
|
-
? h('span', { className: `${P}-triggerEffort` }, triggerLabel)
|
|
1129
|
-
: null,
|
|
1130
|
-
icon('down', `${P}-chev`)),
|
|
1131
|
-
|
|
1106
|
+
/* 浮层(弹出面板 + tooltip)portal 到 document.body。
|
|
1107
|
+
* 原因:宿主 DSH 给输入区座位 `.composerSeat` 无条件写了
|
|
1108
|
+
* `will-change: transform`(ConversationRoot.module.css),按规范这使
|
|
1109
|
+
* seat 成为它每个 `position:fixed` 后代的包含块。本插件的弹层 / tooltip
|
|
1110
|
+
* 过去作为 `.cmes-root` 的子节点留在 seat 里,于是 fixed 坐标被按 seat
|
|
1111
|
+
* 盒子而非视口解读——弹层相对触发按钮整体平移(探针 rect 变成座位原点,
|
|
1112
|
+
* Firefox 上实测中心 Δ≈277、间隙≈276),又被 seat 的 `z-index:9` 层叠
|
|
1113
|
+
* 上下文压在 DSH 元素之下而无法操作。portal 到 body 后浮层脱离 seat 的
|
|
1114
|
+
* 包含块与层叠上下文:fixed 重新相对视口解析,z-index 也在根上下文生效,
|
|
1115
|
+
* 同时不干扰 DSH 想从 `will-change` 得到的合成层。DSH 自家浮层
|
|
1116
|
+
* (StatsPills / TurnUsagePanel / ApprovalWarning 等)采用同一做法。 */
|
|
1117
|
+
const overlay = h(React.Fragment, null,
|
|
1132
1118
|
h('section', {
|
|
1133
1119
|
className: classes, ref: popupRef, role: 'dialog',
|
|
1134
1120
|
'aria-label': pane === 'models' ? t('model') : t('effort'),
|
|
@@ -1166,6 +1152,38 @@ window.__ModuleLoader__.load({
|
|
|
1166
1152
|
},
|
|
1167
1153
|
h('span', { className: `${P}-tipTitle` }, t('team')),
|
|
1168
1154
|
h('span', null, t('teamDesc'))));
|
|
1155
|
+
|
|
1156
|
+
return h('div', { className: `${P}-root`, ref: rootRef },
|
|
1157
|
+
h('style', null, css),
|
|
1158
|
+
h('button', {
|
|
1159
|
+
className: `${P}-trigger${U.isPeakId(savedEffort) ? ' peak' : ''}${fast ? ' fast' : ''}`,
|
|
1160
|
+
ref: triggerRef, disabled,
|
|
1161
|
+
'aria-label': `${modelName} ${triggerLabel}`.trim(),
|
|
1162
|
+
'aria-expanded': open, 'aria-haspopup': 'dialog', 'aria-busy': busy,
|
|
1163
|
+
style: { [`--${P}-ink`]: U.inkFor(savedEffort, dark) },
|
|
1164
|
+
onClick: () => {
|
|
1165
|
+
if (open) close();
|
|
1166
|
+
else {
|
|
1167
|
+
/* 打开前先量一次可用高度,首帧就是正确值,不会高度弹跳。 */
|
|
1168
|
+
primeRoom();
|
|
1169
|
+
setPane(model ? 'effort' : 'models');
|
|
1170
|
+
setOpen(true);
|
|
1171
|
+
load();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
},
|
|
1175
|
+
fast ? h('svg', { className: `${P}-bolt`, viewBox: '0 0 24 24', 'aria-hidden': true }, h('path', { d: ICON.bolt })) : null,
|
|
1176
|
+
h('span', { className: `${P}-compact` }, icon('model')),
|
|
1177
|
+
h('span', { className: `${P}-caption` },
|
|
1178
|
+
modelName),
|
|
1179
|
+
triggerLabel
|
|
1180
|
+
? h('span', { className: `${P}-triggerEffort` }, triggerLabel)
|
|
1181
|
+
: null,
|
|
1182
|
+
icon('down', `${P}-chev`)),
|
|
1183
|
+
|
|
1184
|
+
/* 浮层 portal 到 body:脱离 composerSeat 的 will-change 包含块与
|
|
1185
|
+
* z-index:9 层叠上下文(完整说明见上方 overlay 定义处)。 */
|
|
1186
|
+
createPortal(overlay, document.body));
|
|
1169
1187
|
}
|
|
1170
1188
|
|
|
1171
1189
|
/* 懒加载样式表分块(client.styles.js)。React.lazy + Suspense 让座位
|
package/client.styles.js
CHANGED
|
@@ -29,9 +29,14 @@ window.__ModuleLoader__.load({
|
|
|
29
29
|
function css(P, M = METRICS) {
|
|
30
30
|
return `
|
|
31
31
|
.${P}-root{position:relative;display:inline-flex;min-width:0;font-family:var(--dsw-font-family);font-size:14px;letter-spacing:0}
|
|
32
|
-
/*
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
/* 浮层(弹层 + tooltip)已 portal 到 document.body,脱离 .cmes-root,因此
|
|
33
|
+
那条 .cmes-root * 的 box-sizing / corner-shape 和 .cmes-root button 的
|
|
34
|
+
按钮重置都不再作用于它们——不补回,面板里每个 button 都会退回浏览器默认
|
|
35
|
+
样式(灰色底 + 2px outset 黑框 + 13.33px 系统字号),即「元素外有黑框」。
|
|
36
|
+
这里只放低特异性的重置,各按钮自己的 border:0 / background / font-size
|
|
37
|
+
规则会照常覆盖。 */
|
|
38
|
+
.${P}-popover,.${P}-popover *,.${P}-tip,.${P}-tip *{box-sizing:border-box;corner-shape:round;font-family:var(--dsw-font-family)}
|
|
39
|
+
.${P}-popover button{font:inherit;cursor:pointer;border:0;color:inherit}
|
|
35
40
|
.${P}-root *{box-sizing:border-box;corner-shape:round}
|
|
36
41
|
.${P}-root button{font:inherit;cursor:pointer;border:0;background:transparent;color:inherit}
|
|
37
42
|
|
|
@@ -52,20 +57,22 @@ window.__ModuleLoader__.load({
|
|
|
52
57
|
.${P}-chev{width:12px;height:12px;flex:none;color:var(--dsw-alias-label-caption);transition:transform .12s ease}
|
|
53
58
|
.${P}-trigger[aria-expanded=true] .${P}-chev{transform:rotate(180deg)}
|
|
54
59
|
/* ---------- Fast 提示框 ----------
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
历史上的两个坑,都由「固定定位后代被祖先变成包含块」引起:
|
|
61
|
+
1) 这一层过去是 ⚡ 按钮的子节点——也就是在弹出面板内部。弹出面板绘制出厂
|
|
62
|
+
的菜单材质 backdrop-filter: var(--dsw-menu-backdrop-filter)
|
|
63
|
+
= blur(40px) saturate(150%),而非 none 的 backdrop-filter 会让该元素
|
|
64
|
+
成为每个固定/绝对定位后代的包含块。于是算出的视口坐标被重新按弹出面板
|
|
65
|
+
的盒子解读(实测:期望 top 479,实际落在 1023 = 弹出面板 top 544 + 479),
|
|
66
|
+
随后 overflow:hidden 把这一层裁掉——悬停把 opacity/visibility 都翻过来了,
|
|
67
|
+
却什么都没画出来。
|
|
68
|
+
2) 后来把 tooltip 提为弹出面板的兄弟节点,但它仍留在 .cmes-root 里,而宿主
|
|
69
|
+
DSH 给输入区座位 .composerSeat 无条件写了 will-change: transform,这使
|
|
70
|
+
seat 成为每个固定定位后代的包含块,坐标整体平移(Firefox 上弹层中心
|
|
71
|
+
Δ≈277、间隙≈276)。
|
|
72
|
+
现在的修复:tooltip 与弹出面板一起 portal 到 document.body,彻底脱离上述任何
|
|
73
|
+
祖先的包含块,position:fixed 恒相对视口解析;tooltip 也不再是按钮的后代,可见
|
|
74
|
+
性改由 pointer enter/leave + focus/blur 驱动的 .show 类控制。 */
|
|
75
|
+
.${P}-tip{position:fixed;z-index:1400;padding:7px 12px;white-space:nowrap;font-family:var(--dsw-font-family);background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));background:color-mix(in srgb,var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2)) 72%,transparent);backdrop-filter:blur(20px) saturate(180%);-webkit-backdrop-filter:blur(20px) saturate(180%);box-shadow:var(--dsw-elevation-panel);border-radius:10px;font-size:12px;line-height:17px;text-align:center;color:var(--dsw-alias-label-primary);opacity:0;visibility:hidden;pointer-events:none;transform:translateY(2px);transition:opacity .12s ease,transform .12s ease,visibility 0s .12s}
|
|
69
76
|
.${P}-tip.show{opacity:1;visibility:visible;transform:translateY(0);transition:opacity .12s ease,transform .12s ease,visibility 0s}
|
|
70
77
|
/* 参考实现中的 tooltip 是两行卡片:较重的标题压在柔和副标题上。
|
|
71
78
|
“仅视觉效果”的披露只留给辅助技术,因此卡片保持参考实现的两行形态。 */
|
|
@@ -79,8 +86,11 @@ window.__ModuleLoader__.load({
|
|
|
79
86
|
.${P}-resetTip{max-width:min(240px,calc(100vw - 32px));white-space:normal;text-align:left}
|
|
80
87
|
|
|
81
88
|
/* ---------- 弹出面板 ---------- */
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
/* 弹出面板 portal 到 body,position:fixed 恒相对视口;定位由 align() 写入的
|
|
90
|
+
--top / --left 视口坐标驱动(面板底边停在触发按钮上方 8px),CSS 值只是
|
|
91
|
+
首帧前的回退。 */
|
|
92
|
+
.${P}-popover{position:fixed;top:var(--${P}-top,auto);left:var(--${P}-left,12px);width:272px;max-width:calc(100vw - 24px);height:var(--${P}-height,${M.effortPaneH}px);max-height:var(--${P}-room,calc(100vh - 52px));padding:0;font-family:var(--dsw-font-family);font-size:14px;letter-spacing:0;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));border-radius:14px;box-shadow:var(--dsw-elevation-panel);backdrop-filter:var(--dsw-menu-backdrop-filter);z-index:1100;overflow:hidden;transform-origin:top left;transition:opacity .18s ease,transform .18s ease,height .2s cubic-bezier(.2,.8,.2,1),visibility 0s}
|
|
93
|
+
.${P}-popover.closed{opacity:0;pointer-events:none;visibility:hidden;transform:translateY(-5px) scale(.98);transition-delay:0s,0s,0s,.18s}
|
|
84
94
|
.${P}-popover.peak{--dsw-elevation-stroke-color:rgba(145,78,246,.28)}
|
|
85
95
|
|
|
86
96
|
/* ---------- 面板分层 ---------- */
|
|
@@ -89,14 +99,14 @@ window.__ModuleLoader__.load({
|
|
|
89
99
|
|
|
90
100
|
/* ---------- 强度面板 ---------- */
|
|
91
101
|
.${P}-main{height:var(--${P}-main-h,${M.effortPaneH}px)}
|
|
92
|
-
.${P}-tool{position:absolute;top:7px;width:28px;height:28px;display:flex;align-items:center;justify-content:center;padding:0;border-radius:8px;color:var(--dsw-alias-label-caption)}
|
|
102
|
+
.${P}-tool{position:absolute;top:7px;width:28px;height:28px;display:flex;align-items:center;justify-content:center;padding:0;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-caption)}
|
|
93
103
|
.${P}-tool:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
94
104
|
.${P}-fast{left:7px}
|
|
95
105
|
.${P}-reset{right:7px}
|
|
96
106
|
.${P}-tool svg{width:16px;height:16px}
|
|
97
107
|
.${P}-fast.active{color:var(--${P}-accent,#3988f6)}
|
|
98
108
|
.${P}-popover.peak .${P}-fast.active{color:var(--${P}-accentPeak,#9b48eb)}
|
|
99
|
-
.${P}-modelLink{position:absolute;left:43px;right:43px;top:8px;height:42px;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:2px 4px;border-radius:5px;transition:opacity .2s ease}
|
|
109
|
+
.${P}-modelLink{position:absolute;left:43px;right:43px;top:8px;height:42px;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:2px 4px;border:0;border-radius:5px;background:transparent;transition:opacity .2s ease}
|
|
100
110
|
.${P}-modelLink:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
101
111
|
.${P}-heading{display:flex;gap:3px;justify-content:center;align-items:center;max-width:100%;height:20px;color:var(--${P}-ink,#3989e9);font-size:14px;line-height:20px;white-space:nowrap;transition:color .2s ease}
|
|
102
112
|
.${P}-heading svg{width:10px;height:10px;color:var(--dsw-alias-label-caption)}
|
|
@@ -184,14 +194,18 @@ window.__ModuleLoader__.load({
|
|
|
184
194
|
--dsw-radius-md,以及交互式悬停底色。 */
|
|
185
195
|
.${P}-team{position:absolute;left:8px;right:8px;top:96px;display:flex;align-items:center;justify-content:space-between;gap:16px;min-height:${M.teamRowH}px;padding:0 8px;border-radius:var(--dsw-radius-md);color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
|
|
186
196
|
.${P}-teamLabel{display:inline-flex;align-items:center;gap:4px;min-width:0}
|
|
187
|
-
.${P}-teamInfo{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;flex:none;padding:0;color:var(--dsw-alias-label-caption);cursor:help}
|
|
197
|
+
.${P}-teamInfo{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;flex:none;padding:0;border:0;border-radius:0;background:transparent;color:var(--dsw-alias-label-caption);cursor:help}
|
|
188
198
|
.${P}-teamInfo svg{width:11px;height:11px}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.${P}-
|
|
194
|
-
.${P}-
|
|
199
|
+
/* 开关随弹出面板 portal 到 body,不再位于 .cmes-root 之内,因此规则不能用
|
|
200
|
+
.cmes-root 后代选择器(否则整块失效,按钮退回浏览器默认样式:灰色底 +
|
|
201
|
+
2px outset 黑框 + 直角)。改用单类选择器;并补回过去由 .cmes-root button
|
|
202
|
+
提供的 font / cursor / border 重置。 */
|
|
203
|
+
.${P}-teamSwitch{position:relative;flex:none;width:32px;height:18px;padding:0;border:0;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover-solid,#cfd1d6);color:inherit;font:inherit;cursor:pointer;box-sizing:border-box;transition:background .16s ease}
|
|
204
|
+
.${P}-teamSwitch[aria-checked=true]{background:var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
205
|
+
.${P}-teamSwitch:disabled{opacity:.45;cursor:default}
|
|
206
|
+
.${P}-teamSwitch:focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
207
|
+
.${P}-teamSwitch::after{content:"";position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.22);transition:transform .16s ease}
|
|
208
|
+
.${P}-teamSwitch[aria-checked=true]::after{transform:translateX(14px)}
|
|
195
209
|
@media (hover:hover){.${P}-team:hover{background:var(--dsw-alias-interactive-bg-hover)}}
|
|
196
210
|
@media (prefers-reduced-motion:reduce){
|
|
197
211
|
.${P}-sp{animation-duration:calc(var(--dur,3s) * 2.6)}
|