dsh-codex-model-effort-ui 1.1.5 → 1.1.6

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/client.js CHANGED
@@ -28,10 +28,10 @@ window.__ModuleLoader__.load({
28
28
  usage: '用量更多', visual: '(仅视觉效果)', reset: '重置为默认',
29
29
  warning: '更快消耗使用额度', model: '切换模型', back: '返回',
30
30
  loading: '正在加载模型', empty: '没有可用模型',
31
- unsupported: '此模型未提供推理强度', retry: '重试',
31
+ unsupported: '此模型未提供推理强度',
32
32
  busy: '正在切换', failed: '切换失败',
33
33
  unavailable: '此会话不能切换模型',
34
- search: '搜索模型', noMatch: '没有匹配的模型', clear: '清除搜索',
34
+ search: '搜索模型', noMatch: '没有匹配的模型',
35
35
  team: '多团队协作',
36
36
  teamDesc: '开启后由多个子代理协同完成当前会话的工作,可在任务面板查看进度',
37
37
  teamFailed: '协作开关切换失败',
@@ -48,10 +48,10 @@ window.__ModuleLoader__.load({
48
48
  usage: 'Uses more quota', visual: '(Visual only)', reset: 'Reset to default',
49
49
  warning: 'Consumes usage quota faster', model: 'Switch model', back: 'Back',
50
50
  loading: 'Loading models', empty: 'No available models',
51
- unsupported: 'This model provides no reasoning effort levels', retry: 'Retry',
51
+ unsupported: 'This model provides no reasoning effort levels',
52
52
  busy: 'Switching', failed: 'Selection failed',
53
53
  unavailable: 'Model selection unavailable',
54
- search: 'Search models', noMatch: 'No matching models', clear: 'Clear search',
54
+ search: 'Search models', noMatch: 'No matching models',
55
55
  team: 'Agent Teams',
56
56
  teamDesc: 'Let subagents work on this session together; progress appears in the task panel',
57
57
  teamFailed: 'Could not switch Agent Teams',
@@ -96,7 +96,6 @@ window.__ModuleLoader__.load({
96
96
  check: 'm20 6-11 11-5-5',
97
97
  reset: 'M3 11a9 9 0 1 1 2.6 7M3 4v7h7',
98
98
  info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 11v5M12 7.4v.01',
99
- close: 'M6 6l12 12M18 6L6 18',
100
99
  search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14ZM20 20l-4-4',
101
100
  model: 'M12 3 3 8l9 5 9-5-9-5ZM3 12l9 5 9-5M3 16l9 5 9-5',
102
101
  bolt: 'M14.4 2Q16 .2 15.8 2.5L15.1 8.5H20.5Q22 8.5 21 9.8L10.7 21.7Q9 23.4 9.2 21.2L10 14.2H4.2Q2.6 14.2 3.6 12.9L14.4 2Z'
@@ -109,6 +108,27 @@ window.__ModuleLoader__.load({
109
108
  }, h('path', { d: ICON[name] || ICON.chevron }));
110
109
  }
111
110
 
111
+ /* 焦点陷阱:弹层是 role="dialog",Tab 不该走出它落到背景页上。
112
+ * 在弹层打开期间拦下 Tab,在「首个 / 末个」可聚焦元素处掉头循环,
113
+ * 把焦点始终圈在弹层内。只处理 Tab,其余按键(方向键 / Enter /
114
+ * Escape)原样放行,不与滑轨、搜索框、模型列表的键盘逻辑抢事件。
115
+ * 宿主若注入了自己的陷阱,这里只是冗余兜底;未注入时补齐缺口。 */
116
+ const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
117
+ function trapFocus(section, event) {
118
+ if (event.key !== 'Tab') return;
119
+ const nodes = Array.from(section.querySelectorAll(FOCUSABLE))
120
+ .filter(el => !el.closest(`.${P}-pane.hidden`) && (el.offsetWidth > 0 || el.offsetHeight > 0));
121
+ if (!nodes.length) return;
122
+ const first = nodes[0];
123
+ const last = nodes[nodes.length - 1];
124
+ const active = section.ownerDocument.activeElement;
125
+ if (event.shiftKey) {
126
+ if (active === first || !section.contains(active)) { event.preventDefault(); last.focus({ preventScroll: true }); }
127
+ } else if (active === last || !section.contains(active)) {
128
+ event.preventDefault(); first.focus({ preventScroll: true });
129
+ }
130
+ }
131
+
112
132
  /* ------------------------------------------------------------------ *
113
133
  * Fast 开关 —— 按会话持久化
114
134
  * 本插件是 fail-open 的,因此每次存储访问都有保护:失败只损失重启后
@@ -198,6 +218,28 @@ window.__ModuleLoader__.load({
198
218
  const handlersRef = useRef({ onOutside, onEscape });
199
219
  useLayoutEffect(() => { handlersRef.current = { onOutside, onEscape }; });
200
220
 
221
+ /* 把触发按钮对齐到弹层:按包含块换算 left/bottom,并回写高度余量。
222
+ * 只读 ref 与 window,因此是引用稳定的——既能被下面的 layout effect
223
+ * 绑定到事件上,也能被 `primeRoom` 在打开前直接调用,把首帧的
224
+ * left/bottom 一并预置(否则首帧会用 CSS 里的回退坐标画一帧再跳正)。 */
225
+ const align = React.useCallback(() => {
226
+ const trigger = triggerRef.current?.getBoundingClientRect();
227
+ const popup = popupRef.current;
228
+ if (!trigger || !popup || !rootRef.current) return;
229
+ const width = Math.min(272, window.innerWidth - 24);
230
+ const left = Math.max(12, Math.min((trigger.left + trigger.right - width) / 2, window.innerWidth - width - 12));
231
+ /* 弹出面板是 `position: fixed`,因此浏览器按包含块而非窗口解读
232
+ * 这些数值:用测量到的包含块重新换算,视口时原点就是 0,0。 */
233
+ const box = containingBoxOf(probeRef.current);
234
+ rootRef.current.style.setProperty(`--${P}-left`, `${left - box.left}px`);
235
+ rootRef.current.style.setProperty(`--${P}-bottom`, `${Math.max(12, box.bottom - trigger.top + 8)}px`);
236
+ /* 触发按钮上方的空间:驱动高度钳制,同时写回 state,让 render
237
+ * 不必自己读布局。 */
238
+ const roomAbove = Math.max(120, trigger.top - 20);
239
+ rootRef.current.style.setProperty(`--${P}-room`, `${roomAbove}px`);
240
+ setRoom(prev => (prev === roomAbove ? prev : roomAbove));
241
+ }, [rootRef, popupRef, probeRef, triggerRef]);
242
+
201
243
  useLayoutEffect(() => {
202
244
  if (!open) return;
203
245
  let frame = 0;
@@ -208,23 +250,6 @@ window.__ModuleLoader__.load({
208
250
  if (event.key !== 'Escape') return;
209
251
  handlersRef.current.onEscape(event);
210
252
  }
211
- function align() {
212
- const trigger = triggerRef.current?.getBoundingClientRect();
213
- const popup = popupRef.current;
214
- if (!trigger || !popup || !rootRef.current) return;
215
- const width = Math.min(272, window.innerWidth - 24);
216
- const left = Math.max(12, Math.min((trigger.left + trigger.right - width) / 2, window.innerWidth - width - 12));
217
- /* 弹出面板是 `position: fixed`,因此浏览器按包含块而非窗口解读
218
- * 这些数值:用测量到的包含块重新换算,视口时原点就是 0,0。 */
219
- const box = containingBoxOf(probeRef.current);
220
- rootRef.current.style.setProperty(`--${P}-left`, `${left - box.left}px`);
221
- rootRef.current.style.setProperty(`--${P}-bottom`, `${Math.max(12, box.bottom - trigger.top + 8)}px`);
222
- /* 触发按钮上方的空间:驱动高度钳制,同时写回 state,让 render
223
- * 不必自己读布局。 */
224
- const roomAbove = Math.max(120, trigger.top - 20);
225
- rootRef.current.style.setProperty(`--${P}-room`, `${roomAbove}px`);
226
- setRoom(prev => (prev === roomAbove ? prev : roomAbove));
227
- }
228
253
  function resized() {
229
254
  cancelAnimationFrame(frame);
230
255
  const until = performance.now() + 500;
@@ -235,20 +260,42 @@ window.__ModuleLoader__.load({
235
260
  document.addEventListener('keydown', escape, true);
236
261
  window.addEventListener('resize', resized);
237
262
  document.addEventListener('scroll', align, true);
263
+ /* 输入区是多行的:换行 / 贴图 / 切会话会让触发按钮在**既不产生 window
264
+ * resize、也未必冒泡出 scroll 事件**的情况下移动,而弹层的 bottom 是
265
+ * 打开那一刻按 trigger.top 算死的——按钮一动弹层不跟,于是相对按钮
266
+ * 上浮或下沉。用一个观察器盯住触发按钮的定位祖先(`offsetParent`,
267
+ * 正是那条 overflow:auto/hidden 的输入区链)与根节点:它们的盒子
268
+ * 尺寸一变(输入区长高、滚动条出现/消失、外框平移)就重跑 `align`,
269
+ * 把弹层重新锚定到当前按钮位置。观察器回调在绘制前触发,因此漂移
270
+ * 不会先画出来再纠正。
271
+ *
272
+ * 已知残留缺口:ResizeObserver 只对「盒子尺寸变化」敏感。若按钮因
273
+ * 某祖先的 CSS transform / 主动画被整体平移,而所有被观察盒子尺寸
274
+ * 都没变,观察器不会响——这类纯位移只能靠 IntersectionObserver 或
275
+ * rAF 轮询兜底,但对一个 fail-open 插件而言过重,故刻意不引入。
276
+ * scroll(capture)与 window resize 监听仍覆盖绝大多数实际场景。 */
277
+ let observer = null;
278
+ if (typeof ResizeObserver === 'function') {
279
+ observer = new ResizeObserver(() => align());
280
+ const anchor = triggerRef.current?.offsetParent;
281
+ if (anchor) observer.observe(anchor);
282
+ if (rootRef.current) observer.observe(rootRef.current);
283
+ }
238
284
  align();
239
285
  return () => {
240
286
  document.removeEventListener('pointerdown', outside);
241
287
  document.removeEventListener('keydown', escape, true);
242
288
  window.removeEventListener('resize', resized);
243
289
  document.removeEventListener('scroll', align, true);
290
+ if (observer) observer.disconnect();
244
291
  cancelAnimationFrame(frame);
245
292
  };
246
- }, [open, rootRef, popupRef, probeRef, triggerRef]);
293
+ }, [open, align, rootRef, popupRef, probeRef, triggerRef]);
247
294
 
248
- /* 打开前先量一次,首帧就有正确高度,不会先回退到视口再跳变。 */
295
+ /* 打开前先量一次:首帧就有正确的高度 **和位置**,不会先回退到 CSS 里的
296
+ * 回退坐标(left:12 / bottom:40)再跳变。 */
249
297
  function primeRoom() {
250
- const rect = triggerRef.current?.getBoundingClientRect();
251
- if (rect) setRoom(Math.max(120, rect.top - 20));
298
+ align();
252
299
  }
253
300
  return { room, primeRoom };
254
301
  }
@@ -484,7 +531,6 @@ window.__ModuleLoader__.load({
484
531
  );
485
532
 
486
533
  const [open, setOpen] = useState(false);
487
- const [present, setPresent] = useState(false);
488
534
  const [pane, setPane] = useState('effort');
489
535
  const [preview, setPreview] = useState(null);
490
536
  const [message, setMessage] = useState(false);
@@ -562,21 +608,17 @@ window.__ModuleLoader__.load({
562
608
  const sparkles = useMemo(() => U.buildSparkles(22), [U]);
563
609
  const bloomMotes = useMemo(() => U.buildBloom(U.BLOOM_COUNT), [U]);
564
610
 
565
- /* `latest` 供 Escape 处理器读取“最近一次提交”的面板状态。只在 layout
566
- * effect 里同步:render 期间写 ref 会破坏渲染的纯粹性。 */
611
+ /* `latest` 供 Escape 处理器读取「最近一次提交」的面板状态。只在 layout
612
+ * effect 里同步:render 期间写 ref 会破坏渲染的纯粹性。刻意不放
613
+ * open——Escape 监听器只在弹层打开期间绑定,这里只保留 Escape 退层
614
+ * 真正需要的 pane/view 等即时状态,避免读到关闭动画窗口内的过期值。 */
567
615
  useLayoutEffect(() => {
568
- latest.current = { open: present, fast, peak, pane, efforts, index, savedEffort, view };
616
+ latest.current = { fast, peak, pane, efforts, index, savedEffort, view };
569
617
  });
570
618
 
571
619
  /* ---------- 副作用 ---------- */
572
620
  useEffect(() => { if (available) load(); }, [available, load]);
573
621
 
574
- useLayoutEffect(() => {
575
- if (open) { setPresent(true); return; }
576
- const timer = setTimeout(() => setPresent(false), 180);
577
- return () => clearTimeout(timer);
578
- }, [open]);
579
-
580
622
  useEffect(() => {
581
623
  mountedRef.current = true;
582
624
  return () => {
@@ -603,9 +645,16 @@ window.__ModuleLoader__.load({
603
645
  if (arrived) setBloom(n => n + 1);
604
646
  }, [index, open, efforts.length]);
605
647
 
648
+ /* 统一清掉峰值提示的定时器:既 cancel 掉还没触发的,也把数组清空,
649
+ * 避免失效 id 无谓地累积(clearTimeout 对旧 id 是 no-op,但不整洁)。 */
650
+ function clearTimers() {
651
+ timersRef.current.forEach(clearTimeout);
652
+ timersRef.current = [];
653
+ }
654
+
606
655
  /* 进入峰值时的特效:先显示警告,随后落定 */
607
656
  function enterPeak() {
608
- timersRef.current.forEach(clearTimeout);
657
+ clearTimers();
609
658
  setMessage(true);
610
659
  timersRef.current = [setTimeout(() => { if (mountedRef.current) setMessage(false); }, 1800)];
611
660
  }
@@ -797,6 +846,13 @@ window.__ModuleLoader__.load({
797
846
  : (typeof window === 'undefined' ? Infinity : Math.max(120, window.innerHeight - 52));
798
847
  const cappedHeight = Math.min(menuHeight, roomAbove);
799
848
 
849
+ /* 错误提示行:原先用 bottom 锚定,会在「无推理档位」时压住
850
+ * .cmes-noeffort 文案(那块和滑轨同样占据 top:65 起、line-height 26
851
+ * 的带状区域,而 status 落在 bottom:6 正好与其重叠)。改为 top 锚定,
852
+ * 落在顶部 ⚡/重置 按钮之间的空档(y 8..50 的 modelLink 那一行),
853
+ * 那里无论有无档位、有无 team 行都恒为空,不会再与任何内容打架。 */
854
+ const statusTop = 8;
855
+
800
856
  const classes = [
801
857
  `${P}-popover`,
802
858
  !open ? 'closed' : '',
@@ -926,7 +982,7 @@ window.__ModuleLoader__.load({
926
982
  'aria-label': t('model'), title: modelName
927
983
  },
928
984
  h('span', { className: `${P}-heading` }, currentLabel || t('choose'), icon('chevron', `${P}-iconSmall`)),
929
- h('span', { className: `${P}-modelName` }, modelName)),
985
+ h('span', { className: `${P}-modelLinkName` }, modelName)),
930
986
 
931
987
  h('div', { className: `${P}-warning` }, h('span', null, t('warning'))),
932
988
 
@@ -1019,12 +1075,18 @@ window.__ModuleLoader__.load({
1019
1075
  type: 'button',
1020
1076
  className: `${P}-teamInfo`,
1021
1077
  ref: teamInfoBtnRef,
1022
- 'aria-label': t('teamDesc'),
1078
+ /* 可访问名只用简短的「Agent Teams」;整句说明交给
1079
+ * aria-describedby 指向的提示卡,避免把长句塞进 label。 */
1080
+ 'aria-label': t('team'),
1023
1081
  'aria-describedby': `${P}-team-tip`,
1024
1082
  onPointerEnter: () => setTeamTipOn(true),
1025
1083
  onPointerLeave: () => setTeamTipOn(false),
1026
1084
  onFocus: () => setTeamTipOn(true),
1027
1085
  onBlur: () => setTeamTipOn(false),
1086
+ /* 提示卡的显隐完全交给 hover / focus:这里若再切一刀,
1087
+ * 点击会把 hover 刚点亮的提示卡反过来关掉(指针还悬在上面,
1088
+ * 不会重新触发 enter),表现为提示卡在光标下凭空消失。
1089
+ * 点击只拦住冒泡,避免把整个弹层关掉。 */
1028
1090
  onClick: event => { event.preventDefault(); event.stopPropagation(); }
1029
1091
  }, icon('info', `${P}-teamInfoIcon`))),
1030
1092
  h('button', {
@@ -1070,7 +1132,8 @@ window.__ModuleLoader__.load({
1070
1132
  h('section', {
1071
1133
  className: classes, ref: popupRef, role: 'dialog',
1072
1134
  'aria-label': pane === 'models' ? t('model') : t('effort'),
1073
- 'aria-hidden': !open, inert: !open ? '' : undefined,
1135
+ 'aria-hidden': open ? undefined : 'true', inert: !open ? '' : undefined,
1136
+ onKeyDown: open ? event => trapFocus(popupRef.current, event) : undefined,
1074
1137
  style: {
1075
1138
  [`--${P}-height`]: `${pane === 'models' ? cappedHeight : (team.supported ? M.teamPaneH : M.effortPaneH)}px`,
1076
1139
  [`--${P}-ink`]: U.inkFor(displayed, dark)
@@ -1079,7 +1142,7 @@ window.__ModuleLoader__.load({
1079
1142
  modelsView,
1080
1143
  effortView,
1081
1144
  busy ? h('div', { className: `${P}-sr`, role: 'status' }, t('busy')) : null,
1082
- status ? h('div', { className: `${P}-status`, role: 'alert', style: { position: 'absolute', left: 12, right: 12, bottom: team.supported ? 44 : 6, color: 'var(--dsw-alias-state-error-primary)' } },
1145
+ status ? h('div', { className: `${P}-status`, role: 'alert', style: { position: 'absolute', left: 12, right: 12, top: statusTop, color: 'var(--dsw-alias-state-error-primary)' } },
1083
1146
  h('span', null, status)) : null),
1084
1147
  h('span', {
1085
1148
  role: 'tooltip', id: `${P}-reset-tip`,
package/client.styles.js CHANGED
@@ -100,7 +100,10 @@ window.__ModuleLoader__.load({
100
100
  .${P}-modelLink:hover{background:var(--dsw-alias-interactive-bg-hover)}
101
101
  .${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
102
  .${P}-heading svg{width:10px;height:10px;color:var(--dsw-alias-label-caption)}
103
- .${P}-modelName{display:block;max-width:100%;height:18px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
103
+ /* 强度面板中间那行的模型名:独立类名,避免与下方模型列表行的
104
+ * .${P}-modelName(display:flex 徽标布局)同名互相覆盖——两者同名时后者
105
+ * 靠后生效,会让这里的 height/font-size/ellipsis 全部失效。 */
106
+ .${P}-modelLinkName{display:block;max-width:100%;height:18px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
104
107
  .${P}-warning{position:absolute;left:29px;right:29px;top:20px;text-align:center;line-height:18px;font-size:13px;opacity:0;pointer-events:none;transition:opacity .2s ease}
105
108
  .${P}-warning span{display:inline-block;background:linear-gradient(90deg,var(--${P}-warnHi,#a965dd) 0%,var(--${P}-warnHi,#a965dd) 42%,var(--${P}-warnLo,#653780) 50%,var(--${P}-warnHi,#a965dd) 58%,var(--${P}-warnHi,#a965dd) 100%);background-size:300% 100%;background-position:0 0;background-clip:text;-webkit-background-clip:text;color:transparent;-webkit-text-fill-color:transparent}
106
109
  .${P}-popover.message .${P}-modelLink,.${P}-popover.message .${P}-tool{opacity:0;pointer-events:none}
@@ -254,6 +257,9 @@ window.__ModuleLoader__.load({
254
257
  .${P}-model.sel .${P}-ck{opacity:1}
255
258
  .${P}-empty{color:var(--dsw-alias-label-tertiary,#9aa0ab);font-size:13px;padding:14px 10px;text-align:center}
256
259
  .${P}-failure{border-radius:8px;background:var(--dsw-alias-interactive-bg-hover-danger,rgba(229,72,77,.12));color:var(--dsw-alias-state-error-primary,#e5484d);font-size:12px;line-height:1.6;padding:4px 8px;margin:0 2px 3px;word-break:break-word}
260
+ /* 错误提示行只做展示:它覆盖在 modelLink(强度面板)/ 返回+搜索(模型页)
261
+ * 之上,若不关掉命中测试,会在出错时吞掉这些控件的点击。 */
262
+ .${P}-status{position:absolute;pointer-events:none}
257
263
  .${P}-sr{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
258
264
 
259
265
  /* ---------- 深色主题 ----------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-codex-model-effort-ui",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "把 Codex 桌面版的模型选择列表与推理强度滑块 1:1 复刻进 DeepSeek Harness:同一个弹层里切换模型与推理强度。",
5
5
  "author": "zxclf",
6
6
  "license": "MIT",