dsh-chaoxing-assistant 0.0.0-stage → 2.3.4

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.
Files changed (49) hide show
  1. package/.gitignore +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +198 -2
  4. package/client.js +1400 -0
  5. package/cordis.patch.yml +40 -0
  6. package/desktop/ocr.py +21 -0
  7. package/desktop/ocrapi.py +100 -0
  8. package/desktop/uia.ps1 +169 -0
  9. package/desktop/uia2.ps1 +25 -0
  10. package/desktop/uia2core.ps1 +484 -0
  11. package/desktop/uia2srv.ps1 +80 -0
  12. package/docs/DESKTOP.md +61 -0
  13. package/docs/DETAIL.md +226 -0
  14. package/icon.svg +19 -0
  15. package/index.js +300 -0
  16. package/lib/actions.mjs +204 -0
  17. package/lib/autopilot.mjs +1335 -0
  18. package/lib/browser.mjs +344 -0
  19. package/lib/cdp.mjs +616 -0
  20. package/lib/chaoxing.mjs +505 -0
  21. package/lib/cleanup.mjs +503 -0
  22. package/lib/commands.mjs +593 -0
  23. package/lib/cu.mjs +433 -0
  24. package/lib/deskengine.mjs +2427 -0
  25. package/lib/deskflow.mjs +1769 -0
  26. package/lib/desktop.mjs +185 -0
  27. package/lib/deskv2.mjs +844 -0
  28. package/lib/edge.mjs +213 -0
  29. package/lib/engine.mjs +1551 -0
  30. package/lib/extract.mjs +1156 -0
  31. package/lib/guard.mjs +122 -0
  32. package/lib/judge.mjs +64 -0
  33. package/lib/llm.mjs +557 -0
  34. package/lib/paths.mjs +252 -0
  35. package/lib/python.mjs +220 -0
  36. package/lib/quiz.mjs +423 -0
  37. package/lib/quizstate.mjs +33 -0
  38. package/lib/screen.mjs +109 -0
  39. package/lib/solver.mjs +921 -0
  40. package/lib/tools.mjs +876 -0
  41. package/lib/uibridge.mjs +1310 -0
  42. package/lib/util.mjs +171 -0
  43. package/lib/work.mjs +311 -0
  44. package/lib/ws.mjs +720 -0
  45. package/locale/en.json +7 -0
  46. package/locale/zh.json +7 -0
  47. package/package.json +67 -4
  48. package/python/captcha.py +400 -0
  49. package/python/fontmap.py +559 -0
package/client.js ADDED
@@ -0,0 +1,1400 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-chaoxing-assistant',
3
+ factory(require) {
4
+ const React = require('react');
5
+ if (!React || typeof React.createElement !== 'function') return {};
6
+
7
+ const h = React.createElement;
8
+ const useState = React.useState;
9
+ const useEffect = React.useEffect;
10
+ const useRef = React.useRef;
11
+ const useMemo = React.useMemo;
12
+ const DEF_ID = 'dsh-chaoxing-assistant';
13
+ const VERSION = '2.3.4';
14
+ const UI_PORT = 9483;
15
+ // 两条传输:优先 DSH 同源路由(dsh-app://app 下无 CORS/无额外端口),失败再退到本机独立端口。
16
+ // v2.2.1 只写死了 http://127.0.0.1:9483,桌面端 Origin 是 dsh-app://app,被桥 403 掉 → 永远「未连接」。
17
+ const ROUTE_BASE = '/chaoxing';
18
+ const LEGACY_BASE = 'http://127.0.0.1:' + UI_PORT;
19
+ const BASES = [ROUTE_BASE, LEGACY_BASE];
20
+ let activeBase = null;
21
+ const POLL_MS = 2500;
22
+ const HIDDEN_POLL_MS = 8000;
23
+ const MAX_BACKOFF_MS = 20000;
24
+ const MAX_LINES = 240;
25
+ const STYLE_ID = 'chaoxing-tech-style';
26
+ const COURSE_KEY = 'chaoxing.course';
27
+ const MODE_KEY = 'chaoxing.mode';
28
+
29
+ /* ---------------- 面板服务 API ---------------- */
30
+
31
+ function timed(ms) {
32
+ const ctl = new AbortController();
33
+ const t = setTimeout(() => { try { ctl.abort(); } catch (e) { /* ignore */ } }, ms);
34
+ return { signal: ctl.signal, done: () => clearTimeout(t) };
35
+ }
36
+
37
+ function nowMs() {
38
+ try {
39
+ if (typeof performance !== 'undefined' && performance && typeof performance.now === 'function') return performance.now();
40
+ } catch (e) { /* ignore */ }
41
+ return Date.now();
42
+ }
43
+
44
+ function baseLabel() {
45
+ if (!activeBase) return '未连接';
46
+ return activeBase === ROUTE_BASE ? '同源 /chaoxing' : '127.0.0.1:' + UI_PORT;
47
+ }
48
+
49
+ /** 先试同源路由,再退到本机 9483;成功的那条被记住,失败后下次重排 */
50
+ function baseOrder() {
51
+ return activeBase ? [activeBase].concat(BASES.filter((b) => b !== activeBase)) : BASES.slice();
52
+ }
53
+
54
+ function dropBase() { activeBase = null; }
55
+
56
+ async function apiFetch(path, init, ms) {
57
+ const order = baseOrder();
58
+ let lastError = null;
59
+ for (let i = 0; i < order.length; i += 1) {
60
+ const b = order[i];
61
+ const w = timed(ms);
62
+ try {
63
+ const r = await fetch(b + path, Object.assign({ cache: 'no-store' }, init || {}, { signal: w.signal }));
64
+ // 404/405 = 这条通道没有该路由(例如旧宿主还没有 /chaoxing),换下一条
65
+ if (r && (r.status === 404 || r.status === 405)) {
66
+ lastError = new Error('HTTP ' + r.status);
67
+ continue;
68
+ }
69
+ activeBase = b;
70
+ return r;
71
+ } catch (e) {
72
+ lastError = e;
73
+ } finally { w.done(); }
74
+ }
75
+ activeBase = null;
76
+ throw lastError || new Error('面板服务不可达');
77
+ }
78
+
79
+ async function getProgress(mode) {
80
+ const r = await apiFetch('/progress?_=' + Date.now() + (mode ? '&mode=' + encodeURIComponent(mode) : ''), null, 6000);
81
+ if (!r.ok) throw new Error('HTTP ' + r.status);
82
+ return await r.text();
83
+ }
84
+
85
+ async function getState() {
86
+ try {
87
+ const r = await apiFetch('/state?_=' + Date.now(), null, 6000);
88
+ if (!r.ok) return null;
89
+ const j = await r.json();
90
+ return j && typeof j === 'object' ? j : null;
91
+ } catch (e) {
92
+ return null;
93
+ }
94
+ }
95
+
96
+ /** 一次取齐「进度文本 + 状态」:每 tick 只发 1 个请求 */
97
+ async function getSnapshot(mode) {
98
+ const r = await apiFetch('/snapshot?mode=' + encodeURIComponent(mode || ''), null, 6000);
99
+ if (!r.ok) throw new Error('HTTP ' + r.status);
100
+ const j = await r.json();
101
+ if (!j || typeof j !== 'object') throw new Error('面板服务返回了无法解析的数据');
102
+ return {
103
+ text: typeof j.text === 'string' ? j.text : '',
104
+ state: j.state && typeof j.state === 'object' ? j.state : null,
105
+ };
106
+ }
107
+
108
+ async function postAction(action, body) {
109
+ const r = await apiFetch('/action', {
110
+ method: 'POST',
111
+ headers: { 'Content-Type': 'application/json' },
112
+ body: JSON.stringify(Object.assign({ action: action }, body || {})),
113
+ }, 90000);
114
+ const txt = await r.text();
115
+ let j = null;
116
+ try { j = JSON.parse(txt); } catch (e) { /* 非 JSON 响应 */ }
117
+ if (!j || typeof j !== 'object') return { ok: r.ok, text: txt || ('面板服务返回 HTTP ' + r.status) };
118
+ return j;
119
+ }
120
+
121
+ /* ---------------- 文案与格式化 ---------------- */
122
+
123
+ const PHASES = {
124
+ idle: '空闲',
125
+ 'starting-browser': '启动浏览器',
126
+ 'waiting-login': '等待登录',
127
+ discovering: '扫描课程',
128
+ working: '自动刷课',
129
+ done: '已完成',
130
+ error: '出错',
131
+ stopped: '已停止',
132
+ };
133
+
134
+ const DESK_PHASES = {
135
+ launching: '启动客户端',
136
+ navigating: '打开页面',
137
+ scanning: '扫描课程',
138
+ works: '做作业',
139
+ running: '运行中',
140
+ starting: '启动中',
141
+ };
142
+
143
+ const MODES = [
144
+ { key: 'web', name: '网页版', desc: '插件自带的 Edge' },
145
+ { key: 'desktop', name: '桌面版', desc: '本机学习通客户端' },
146
+ ];
147
+
148
+ const CTA = [
149
+ { key: 'start', label: '开始', cls: 'start' },
150
+ { key: 'stop', label: '停止', cls: 'stop' },
151
+ ];
152
+
153
+ // 主操作:直接动任务队列
154
+ const CORE = [
155
+ { key: 'scan', label: '扫描', needsCourse: true },
156
+ { key: 'run', label: '刷课', needsCourse: true },
157
+ { key: 'works', label: '作业', needsCourse: true },
158
+ ];
159
+
160
+ // 辅助操作:准备与查看
161
+ const AUX = [
162
+ { key: 'login', label: '登录' },
163
+ { key: 'check', label: '检查' },
164
+ { key: 'refresh', label: '刷新' },
165
+ ];
166
+
167
+ const ALL_ACTIONS = CTA.concat(CORE).concat(AUX);
168
+ const NEEDS_COURSE = ['scan', 'run', 'works'];
169
+ const ACTION_LABELS = {};
170
+ ALL_ACTIONS.forEach((a) => { ACTION_LABELS[a.key] = a.label; });
171
+ ACTION_LABELS.focus = '确定';
172
+
173
+ function labelOf(key) {
174
+ return ACTION_LABELS[key] || key;
175
+ }
176
+
177
+ function fmtClock(sec) {
178
+ const s = Math.max(0, Math.floor(sec || 0));
179
+ const hh = Math.floor(s / 3600);
180
+ const mm = Math.floor((s % 3600) / 60);
181
+ const ss = s % 60;
182
+ const pad = (n) => (n < 10 ? '0' + n : '' + n);
183
+ return (hh ? hh + ':' : '') + pad(mm) + ':' + pad(ss);
184
+ }
185
+
186
+ function fmtTime(ts) {
187
+ try {
188
+ const d = new Date(ts);
189
+ const pad = (n) => (n < 10 ? '0' + n : '' + n);
190
+ return pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
191
+ } catch (e) { return ''; }
192
+ }
193
+
194
+ /** 进度文本里的运行时长的解析:网页版「已运行 00:12:34」/ 桌面版「▸ 桌面版 scanning · 12:34」 */
195
+ function parseElapsed(text) {
196
+ const line = String(text || '').split('\n').map((x) => x.trim()).filter(Boolean)[0] || '';
197
+ if (!line) return null;
198
+ let m = /已运行\s*(\d{1,3}(?::\d{1,2}){1,2})/.exec(line);
199
+ if (!m) m = /^▸\s*桌面版[^·]*·\s*(\d{1,3}(?::\d{1,2}){1,2})/.exec(line);
200
+ if (!m) return null;
201
+ const parts = m[1].split(':').map((x) => parseInt(x, 10));
202
+ if (parts.some((n) => !isFinite(n))) return null;
203
+ let s = 0;
204
+ for (let i = 0; i < parts.length; i += 1) s = s * 60 + parts[i];
205
+ return s;
206
+ }
207
+
208
+ /** 旧桥没有 /state.desktop 时,从进度文本首行兜底推断桌面版阶段 */
209
+ function deskHeadFromText(text) {
210
+ const line = String(text || '').split('\n').map((x) => x.trim()).filter(Boolean)[0] || '';
211
+ const m = /^▸\s*桌面版\s*([^·]*)/.exec(line);
212
+ return m ? String(m[1] || '').trim() : '';
213
+ }
214
+
215
+ function loadCourse() {
216
+ try { return localStorage.getItem(COURSE_KEY) || ''; } catch (e) { return ''; }
217
+ }
218
+
219
+ function saveCourse(v) {
220
+ try { localStorage.setItem(COURSE_KEY, v); } catch (e) { /* ignore */ }
221
+ }
222
+
223
+ function loadMode() {
224
+ try {
225
+ const m = localStorage.getItem(MODE_KEY);
226
+ // 默认「网页版」:老版本什么都没存时会返回 null,导致所有按钮 disabled,
227
+ // 用户看到的就是「点了没反应」。
228
+ return m === 'desktop' ? 'desktop' : 'web';
229
+ } catch (e) { return 'web'; }
230
+ }
231
+
232
+ function saveMode(v) {
233
+ try { if (v) localStorage.setItem(MODE_KEY, v); } catch (e) { /* ignore */ }
234
+ }
235
+
236
+ function lineClass(line) {
237
+ if (/^▸/.test(line)) return 'cx-line cx-line-head';
238
+ if (/已完成|已登录|已继续|已锁定|本轮完成|成功/.test(line)) return 'cx-line cx-line-ok';
239
+ if (/失败|出错|错误|异常|超时|未登录|找不到|未连接|不可用|拒绝/.test(line)) return 'cx-line cx-line-warn';
240
+ if (/^\s{2,}[·-]/.test(line)) return 'cx-line cx-line-dim';
241
+ return 'cx-line';
242
+ }
243
+
244
+ /** 只比较业务字段:/state 的 at 每次都变,不能因此触发整块重渲染 */
245
+ function sameState(a, b) {
246
+ if (a === b) return true;
247
+ if (!a || !b) return false;
248
+ try {
249
+ const ca = Object.assign({}, a);
250
+ const cb = Object.assign({}, b);
251
+ delete ca.at;
252
+ delete cb.at;
253
+ return JSON.stringify(ca) === JSON.stringify(cb);
254
+ } catch (e) {
255
+ return false;
256
+ }
257
+ }
258
+
259
+ /* ---------------- 样式 ---------------- */
260
+
261
+ const CSS = `.cx-root{
262
+ /* ---- 色彩:冷调玻璃,一层冷光、一层薄荷色状态 ---- */
263
+ --bg:#06070a;
264
+ --text:#eef1f7;
265
+ --text-2:#a7aebd;
266
+ --text-3:#767e8d;
267
+ --accent:#a9c1ff;
268
+ --accent-2:#829fff;
269
+ --accent-soft:rgba(169,193,255,.12);
270
+ --accent-line:rgba(169,193,255,.34);
271
+ --ok:#9fe0c0;
272
+ --warn:#e8cd9c;
273
+ --err:#eeb2b8;
274
+ --mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Microsoft YaHei UI",monospace;
275
+ /* ---- 玻璃材质:高光边 / 接触阴影 / 环境光 ---- */
276
+ --rim-hi:rgba(255,255,255,.46);
277
+ --rim-mid:rgba(255,255,255,.10);
278
+ --rim-lo:rgba(169,193,255,.20);
279
+ --contact:0 1px 0 rgba(0,0,0,.55);
280
+ --drop:0 26px 46px -34px rgba(0,0,0,1),0 10px 20px -16px rgba(0,0,0,.92);
281
+
282
+ position:relative;box-sizing:border-box;height:100%;width:100%;
283
+ display:flex;flex-direction:column;gap:10px;
284
+ padding:13px 13px 11px;border-radius:15px;
285
+ border:1px solid rgba(255,255,255,.07);
286
+ overflow-y:auto;overflow-x:hidden;
287
+ background:
288
+ radial-gradient(118% 62% at 50% -18%,rgba(169,193,255,.22),rgba(169,193,255,0) 62%),
289
+ radial-gradient(74% 46% at 106% -2%,rgba(146,124,255,.14),rgba(146,124,255,0) 62%),
290
+ radial-gradient(96% 48% at 50% 114%,rgba(96,128,220,.10),rgba(96,128,220,0) 68%),
291
+ radial-gradient(80% 52% at -8% 96%,rgba(122,220,192,.055),rgba(122,220,192,0) 64%),
292
+ linear-gradient(180deg,#0b0d13 0%,#090a0e 42%,#060709 100%);
293
+ color:var(--text);font-size:12.5px;line-height:1.6;color-scheme:dark;
294
+ font-family:ui-sans-serif,"Microsoft YaHei UI","PingFang SC","HarmonyOS Sans SC",system-ui,sans-serif;
295
+ -webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility;
296
+ container:cxroot/inline-size;
297
+ animation:cx-enter .42s cubic-bezier(.2,.7,.2,1) both;
298
+ }
299
+ /* 顶部一道冷光:面板与宿主窗口的“分界光” */
300
+ .cx-root::before{content:"";position:absolute;top:0;left:16px;right:16px;height:1px;pointer-events:none;
301
+ background:linear-gradient(90deg,transparent,rgba(190,209,255,.55),rgba(255,255,255,.10),transparent)}
302
+ .cx-root::-webkit-scrollbar{width:8px}
303
+ .cx-root::-webkit-scrollbar-thumb{background:rgba(255,255,255,.10);border-radius:999px}
304
+ .cx-root::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.18)}
305
+ .cx-root::-webkit-scrollbar-track{background:transparent}
306
+ .cx-root *,.cx-root *::before,.cx-root *::after{box-sizing:border-box}
307
+
308
+ /* =========================================================
309
+ L1 · 玻璃面板(抬起的表面)
310
+ ========================================================= */
311
+ .cx-head,.cx-controls,.cx-metrics,.cx-notice,.cx-console{
312
+ position:relative;
313
+ border:1px solid rgba(255,255,255,.085);
314
+ background:
315
+ linear-gradient(180deg,rgba(255,255,255,.062),rgba(255,255,255,.026) 46%,rgba(255,255,255,.012));
316
+ box-shadow:
317
+ inset 0 1px 0 rgba(255,255,255,.17),
318
+ inset 0 -1px 0 rgba(255,255,255,.028),
319
+ var(--contact),var(--drop);
320
+ }
321
+
322
+ /* ---- 高光边:只在支持 mask 合成的环境启用,避免降级成实心块 ---- */
323
+ @supports (mask-composite:exclude) or (-webkit-mask-composite:xor){
324
+ .cx-head::after,.cx-controls::before,.cx-metrics::before{
325
+ content:"";position:absolute;inset:0;border-radius:inherit;padding:1px;pointer-events:none;
326
+ background:linear-gradient(152deg,var(--rim-hi),var(--rim-mid) 27%,rgba(255,255,255,.02) 62%,var(--rim-lo));
327
+ -webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
328
+ -webkit-mask-composite:xor;mask-composite:exclude;
329
+ }
330
+ }
331
+
332
+ /* =========================================================
333
+ L0 · 头部
334
+ ========================================================= */
335
+ .cx-head{display:flex;align-items:center;gap:11px;min-width:0;flex:none;padding:12px;
336
+ border-radius:16px;overflow:hidden;
337
+ background:
338
+ radial-gradient(120% 130% at 88% -30%,rgba(150,180,255,.22),rgba(150,180,255,0) 60%),
339
+ linear-gradient(160deg,rgba(255,255,255,.085),rgba(255,255,255,.030) 52%,rgba(255,255,255,.014));
340
+ box-shadow:
341
+ inset 0 1px 0 rgba(255,255,255,.22),
342
+ inset 0 -1px 0 rgba(255,255,255,.03),
343
+ var(--contact),0 26px 44px -34px rgba(0,0,0,1),0 8px 18px -16px rgba(120,150,255,.35);
344
+ }
345
+ .cx-head::before{content:"";position:absolute;left:-30px;bottom:-84px;width:210px;height:160px;border-radius:50%;
346
+ background:radial-gradient(closest-side,rgba(169,193,255,.20),transparent);pointer-events:none}
347
+ .cx-head>*{position:relative;z-index:1}
348
+ .cx-logo{flex:none;width:36px;height:36px;border-radius:12px;display:grid;place-items:center;
349
+ border:1px solid rgba(255,255,255,.72);color:#0a0c11;
350
+ background:
351
+ radial-gradient(120% 120% at 30% -20%,#ffffff,rgba(255,255,255,0) 62%),
352
+ linear-gradient(155deg,#fdfefe 0%,#eef2f8 40%,#d3dce9 72%,#bcc7d8 100%);
353
+ font-family:"Songti SC","STSong","SimSun",serif;font-size:18px;font-weight:700;line-height:1;
354
+ letter-spacing:-.04em;text-indent:-.02em;
355
+ box-shadow:
356
+ inset 0 1px 0 #fff,
357
+ inset 0 -1px 1px rgba(0,0,0,.20),
358
+ inset 0 8px 14px -10px rgba(255,255,255,.95),
359
+ 0 2px 4px rgba(0,0,0,.35),
360
+ 0 10px 20px -10px rgba(150,180,255,.55);
361
+ }
362
+ .cx-brand{min-width:0;display:flex;flex-direction:column;gap:2px}
363
+ .cx-title{font-size:15px;font-weight:650;letter-spacing:.014em;color:#f8f9fc;
364
+ white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
365
+ text-shadow:0 1px 1px rgba(0,0,0,.35)}
366
+ .cx-sub{font-size:8.5px;font-weight:500;letter-spacing:.16em;color:var(--text-3);
367
+ text-transform:uppercase;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
368
+ .cx-pill{margin-left:auto;flex:none;display:inline-flex;align-items:center;gap:6px;max-width:48%;
369
+ padding:4px 9px;border-radius:999px;color:var(--text-2);
370
+ border:1px solid rgba(255,255,255,.10);
371
+ background:linear-gradient(180deg,rgba(255,255,255,.085),rgba(255,255,255,.03));
372
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.16),0 1px 2px rgba(0,0,0,.35);
373
+ font-size:10.5px;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
374
+ .cx-pill .cx-dot{width:5px;height:5px;border-radius:50%;background:currentColor;flex:none;opacity:.9}
375
+ .cx-pill.on{color:#bff0d8;border-color:rgba(159,224,192,.26);
376
+ background:linear-gradient(180deg,rgba(159,224,192,.16),rgba(159,224,192,.06));
377
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.14),0 0 16px -6px rgba(159,224,192,.45)}
378
+ .cx-pill.on .cx-dot{box-shadow:0 0 8px rgba(159,224,192,.75);animation:cx-breathe 2.6s ease-in-out infinite}
379
+ .cx-pill.idle{color:var(--text-2)}
380
+ .cx-pill.off{color:#f2bcc2;border-color:rgba(238,178,184,.28);
381
+ background:linear-gradient(180deg,rgba(238,178,184,.14),rgba(238,178,184,.05))}
382
+
383
+ /* =========================================================
384
+ L1 · 分区标题(层级:小标题 + 发丝延长线)
385
+ ========================================================= */
386
+ .cx-section,.cx-course{display:flex;flex-direction:column;gap:6px;flex:none}
387
+ .cx-cap{display:flex;align-items:center;gap:8px;min-width:0;padding:0 2px;
388
+ font-size:9.5px;font-weight:600;letter-spacing:.15em;line-height:1.4;
389
+ color:var(--text-3);text-transform:uppercase}
390
+ .cx-cap>span:first-child{flex:none;display:inline-flex;align-items:center;gap:6px}
391
+ .cx-cap>span:first-child::before{content:"";width:2px;height:9px;border-radius:2px;flex:none;
392
+ background:linear-gradient(180deg,var(--accent),rgba(169,193,255,.05))}
393
+ .cx-cap::after{content:"";height:1px;flex:1;min-width:12px;
394
+ background:linear-gradient(90deg,rgba(255,255,255,.13),rgba(255,255,255,0))}
395
+ .cx-cap-hint{flex:none;font-size:9px;font-weight:400;letter-spacing:.04em;text-transform:none;
396
+ color:var(--text-3);opacity:.78;white-space:nowrap}
397
+
398
+ /* =========================================================
399
+ L2 · 分段开关:凹陷玻璃槽 + 抬起玻璃片
400
+ ========================================================= */
401
+ .cx-modes{display:flex;gap:3px;padding:4px;height:38px;flex:none;border-radius:12px;
402
+ border:1px solid rgba(255,255,255,.07);
403
+ background:linear-gradient(180deg,rgba(0,0,0,.34),rgba(255,255,255,.018));
404
+ box-shadow:
405
+ inset 0 2px 7px rgba(0,0,0,.55),
406
+ inset 0 -1px 0 rgba(255,255,255,.055),
407
+ 0 1px 0 rgba(255,255,255,.03)}
408
+ .cx-mode{position:relative;flex:1;display:flex;align-items:center;justify-content:center;gap:6px;
409
+ padding:0 8px;border:1px solid transparent;border-radius:9px;background:transparent;
410
+ color:var(--text-3);font-family:inherit;font-size:11.5px;letter-spacing:.02em;cursor:pointer;
411
+ transition:color .2s ease,background .2s ease,border-color .2s ease,box-shadow .2s ease,transform .2s ease}
412
+ .cx-mode:hover:not(:disabled){color:var(--text-2);background:rgba(255,255,255,.035)}
413
+ .cx-mode.active{color:#f7f9fc;font-weight:600;border-color:rgba(255,255,255,.15);
414
+ background:linear-gradient(180deg,rgba(255,255,255,.17),rgba(255,255,255,.075) 52%,rgba(255,255,255,.05));
415
+ box-shadow:
416
+ inset 0 1px 0 rgba(255,255,255,.42),
417
+ inset 0 -1px 0 rgba(255,255,255,.06),
418
+ 0 1px 1px rgba(0,0,0,.45),
419
+ 0 8px 18px -12px rgba(150,180,255,.55)}
420
+ .cx-mode.active::after{content:"";position:absolute;left:50%;bottom:3px;width:16px;height:2px;border-radius:2px;
421
+ transform:translateX(-50%);background:linear-gradient(90deg,var(--accent-2),var(--accent));
422
+ box-shadow:0 0 10px rgba(169,193,255,.65)}
423
+ .cx-mode:disabled{opacity:.4;cursor:not-allowed}
424
+
425
+ /* =========================================================
426
+ L2 · 课程输入:内凹玻璃槽
427
+ ========================================================= */
428
+ .cx-row{display:flex;gap:7px;align-items:center}
429
+ .cx-inputwrap{flex:1;min-width:0;display:flex;align-items:center;gap:5px;height:36px;padding:0 11px;
430
+ border-radius:10px;border:1px solid rgba(255,255,255,.075);
431
+ background:linear-gradient(180deg,rgba(0,0,0,.36),rgba(255,255,255,.02));
432
+ box-shadow:inset 0 2px 6px rgba(0,0,0,.42),inset 0 -1px 0 rgba(255,255,255,.05);
433
+ transition:border-color .2s ease,box-shadow .2s ease,background .2s ease}
434
+ .cx-inputwrap:focus-within{border-color:rgba(169,193,255,.42);
435
+ background:linear-gradient(180deg,rgba(20,26,44,.5),rgba(169,193,255,.05));
436
+ box-shadow:inset 0 2px 6px rgba(0,0,0,.35),0 0 0 3px rgba(169,193,255,.09),0 0 18px -8px rgba(169,193,255,.55)}
437
+ .cx-input{flex:1;min-width:0;padding:0;border:0;background:transparent;color:var(--text);outline:none;
438
+ font-family:inherit;font-size:12.5px;letter-spacing:.01em}
439
+ .cx-input::placeholder{color:#6d7483}
440
+ .cx-clear{flex:none;width:20px;height:20px;padding:0;border:0;border-radius:6px;background:transparent;
441
+ color:var(--text-3);font-family:inherit;font-size:13px;line-height:1;cursor:pointer;
442
+ display:grid;place-items:center;transition:color .15s ease,background .15s ease}
443
+ .cx-clear:hover{color:var(--text);background:rgba(255,255,255,.09)}
444
+ .cx-ok{flex:none;height:36px;min-width:66px;padding:0 14px;border-radius:10px;
445
+ color:var(--text);font-family:inherit;font-size:12px;font-weight:550;cursor:pointer;
446
+ position:relative;
447
+ border:1px solid rgba(255,255,255,.13);
448
+ background:
449
+ radial-gradient(120% 100% at 50% -40%,rgba(255,255,255,.26),rgba(255,255,255,0) 58%),
450
+ linear-gradient(180deg,rgba(255,255,255,.12),rgba(255,255,255,.05) 55%,rgba(255,255,255,.03));
451
+ box-shadow:
452
+ inset 0 1px 0 rgba(255,255,255,.38),
453
+ inset 0 -1px 0 rgba(255,255,255,.05),
454
+ 0 1px 1px rgba(0,0,0,.5),
455
+ 0 10px 20px -16px rgba(0,0,0,.95);
456
+ transition:background .2s ease,border-color .2s ease,box-shadow .2s ease,transform .2s ease,opacity .2s ease}
457
+ .cx-ok:not(:disabled):hover{border-color:rgba(255,255,255,.22);transform:translateY(-1px);
458
+ background:
459
+ radial-gradient(120% 100% at 50% -40%,rgba(255,255,255,.34),rgba(255,255,255,0) 58%),
460
+ linear-gradient(180deg,rgba(255,255,255,.17),rgba(255,255,255,.075) 55%,rgba(255,255,255,.04));
461
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.5),0 2px 3px rgba(0,0,0,.4),0 14px 24px -16px rgba(150,180,255,.5)}
462
+ .cx-ok:not(:disabled):active{transform:translateY(0) scale(.995)}
463
+ .cx-ok:disabled{opacity:.38;cursor:not-allowed}
464
+
465
+ /* =========================================================
466
+ L2 · 主控台:玻璃甲板 + 液态玻璃按钮
467
+ ========================================================= */
468
+ .cx-controls{display:flex;flex-direction:column;gap:8px;flex:none;padding:10px;border-radius:14px;
469
+ background:
470
+ radial-gradient(90% 60% at 50% -20%,rgba(169,193,255,.10),rgba(169,193,255,0) 60%),
471
+ linear-gradient(180deg,rgba(255,255,255,.05),rgba(255,255,255,.018) 55%,rgba(255,255,255,.01));
472
+ box-shadow:
473
+ inset 0 1px 0 rgba(255,255,255,.14),
474
+ inset 0 -1px 0 rgba(255,255,255,.025),
475
+ var(--contact),0 24px 40px -32px #000}
476
+ .cx-cta{display:grid;grid-template-columns:minmax(0,1fr) 88px;gap:8px}
477
+
478
+ /* 液态玻璃按钮母版:高光穹顶 + 边缘折射 + 底部焦散 */
479
+ .cx-btn{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:6px;
480
+ height:37px;padding:0 10px;border-radius:11px;cursor:pointer;white-space:nowrap;
481
+ overflow:hidden;
482
+ border:1px solid rgba(255,255,255,.13);color:var(--text-2);
483
+ font-family:inherit;font-size:12.5px;letter-spacing:.02em;
484
+ background:
485
+ radial-gradient(125% 105% at 50% -45%,rgba(255,255,255,.30),rgba(255,255,255,0) 60%),
486
+ linear-gradient(180deg,rgba(255,255,255,.115),rgba(255,255,255,.05) 52%,rgba(255,255,255,.028));
487
+ box-shadow:
488
+ inset 0 1px 0 rgba(255,255,255,.36),
489
+ inset 0 -1px 0 rgba(255,255,255,.05),
490
+ inset 0 -12px 18px -16px rgba(255,255,255,.42),
491
+ 0 1px 1px rgba(0,0,0,.5),
492
+ 0 8px 18px -14px rgba(0,0,0,.95);
493
+ transition:background .2s ease,border-color .2s ease,color .2s ease,box-shadow .2s ease,transform .2s ease,opacity .2s ease}
494
+ /* 扫光:只在 hover 时掠过,模拟玻璃表面的镜面反射 */
495
+ .cx-btn::before,.cx-ok::before,.cx-tool::before{content:"";position:absolute;inset:-1px;border-radius:inherit;
496
+ pointer-events:none;opacity:0;z-index:0;
497
+ background:linear-gradient(105deg,rgba(255,255,255,0) 36%,rgba(255,255,255,.42) 48%,rgba(255,255,255,.08) 56%,rgba(255,255,255,0) 64%)}
498
+ .cx-btn:hover:not(:disabled)::before,.cx-ok:hover:not(:disabled)::before,.cx-tool:hover::before{
499
+ animation:cx-sheen .82s cubic-bezier(.32,.72,.32,1)}
500
+ /* 边缘折射:1px 渐变亮边 */
501
+ @supports (mask-composite:exclude) or (-webkit-mask-composite:xor){
502
+ .cx-btn::after,.cx-ok::after,.cx-mode.active::before{
503
+ content:"";position:absolute;inset:0;border-radius:inherit;padding:1px;pointer-events:none;
504
+ background:linear-gradient(178deg,rgba(255,255,255,.62),rgba(255,255,255,.13) 26%,rgba(255,255,255,.03) 64%,rgba(255,255,255,.24));
505
+ -webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
506
+ -webkit-mask-composite:xor;mask-composite:exclude;
507
+ }
508
+ .cx-btn.start::after{background:linear-gradient(178deg,#fff,rgba(255,255,255,.74) 24%,rgba(186,208,255,.46) 62%,rgba(128,164,255,.88))}
509
+ .cx-btn.stop::after{background:linear-gradient(178deg,rgba(255,220,222,.55),rgba(255,220,222,.14) 30%,rgba(255,220,222,.05) 66%,rgba(238,178,184,.32))}
510
+ .cx-tools .cx-btn::after{background:linear-gradient(178deg,rgba(255,255,255,.30),rgba(255,255,255,.08) 30%,rgba(255,255,255,.02) 66%,rgba(255,255,255,.12))}
511
+ }
512
+ .cx-btn:disabled{opacity:.35;cursor:not-allowed}
513
+ .cx-btn[aria-busy="true"]{color:var(--text)}
514
+ .cx-btn-label{position:relative;z-index:1;white-space:nowrap}
515
+
516
+ /* 主按钮:液态玻璃 —— 透光(backdrop-blur 吸走背后底色)+ 镜面弧光 + 冷色折射边 + 底部焦散 */
517
+ .cx-btn.start{color:#0b1220;font-weight:700;letter-spacing:.045em;
518
+ border-color:rgba(255,255,255,.62);
519
+ background:
520
+ radial-gradient(78% 28% at 50% 0%,#fff 0%,rgba(255,255,255,.74) 44%,rgba(255,255,255,0) 100%),
521
+ linear-gradient(180deg,rgba(255,255,255,.97) 0%,rgba(250,252,255,.92) 32%,rgba(234,241,253,.86) 64%,rgba(212,225,248,.82) 100%),
522
+ linear-gradient(180deg,rgba(255,255,255,.18),rgba(150,180,255,.10));
523
+ -webkit-backdrop-filter:blur(12px) saturate(160%);
524
+ backdrop-filter:blur(12px) saturate(160%);
525
+ box-shadow:
526
+ inset 0 1.5px 0 rgba(255,255,255,1),
527
+ inset 0 -1px 0 rgba(255,255,255,.92),
528
+ inset 0 -5px 9px -7px rgba(52,96,190,.55),
529
+ inset 0 -1px 2px rgba(140,170,225,.32),
530
+ 0 1px 1px rgba(0,0,0,.52),
531
+ 0 2px 2px rgba(0,0,0,.26),
532
+ 0 10px 22px -12px rgba(151,183,255,.62),
533
+ 0 22px 34px -26px rgba(125,163,255,.92);
534
+ text-shadow:0 1px 0 rgba(255,255,255,.85)}
535
+ /* 液态:一道高光在玻璃里缓慢游动(hover 时改为扫光) */
536
+ .cx-btn.start::before{
537
+ background:radial-gradient(38% 130% at 20% 0%,rgba(255,255,255,.9),rgba(255,255,255,.22) 46%,rgba(255,255,255,0) 72%);
538
+ opacity:.9;mix-blend-mode:screen;
539
+ animation:cx-liquid 7.5s ease-in-out infinite}
540
+ .cx-btn.start:hover:not(:disabled)::before{background:
541
+ linear-gradient(105deg,rgba(255,255,255,0) 36%,rgba(255,255,255,.42) 48%,rgba(255,255,255,.08) 56%,rgba(255,255,255,0) 64%)}
542
+ .cx-btn.start:not(:disabled):hover{transform:translateY(-1px);
543
+ border-color:rgba(255,255,255,.82);
544
+ background:
545
+ radial-gradient(78% 28% at 50% 0%,#fff 0%,rgba(255,255,255,.82) 44%,rgba(255,255,255,0) 100%),
546
+ linear-gradient(180deg,#fff 0%,rgba(252,253,255,.96) 32%,rgba(239,245,255,.92) 64%,rgba(219,231,252,.88) 100%),
547
+ linear-gradient(180deg,rgba(255,255,255,.24),rgba(150,180,255,.14));
548
+ box-shadow:
549
+ inset 0 1.5px 0 #fff,
550
+ inset 0 -1px 0 rgba(255,255,255,.95),
551
+ inset 0 -5px 9px -7px rgba(52,96,190,.45),
552
+ inset 0 -1px 2px rgba(140,170,225,.28),
553
+ 0 2px 2px rgba(0,0,0,.42),
554
+ 0 14px 26px -12px rgba(151,183,255,.8),
555
+ 0 30px 42px -28px rgba(125,163,255,1)}
556
+ /* 按下:玻璃被压进底座,高光收窄、焦散加深 */
557
+ .cx-btn.start:active:not(:disabled){transform:translateY(0) scale(.995);
558
+ background:
559
+ radial-gradient(52% 34% at 50% 8%,rgba(255,255,255,.92),rgba(255,255,255,.34) 64%,rgba(255,255,255,0) 100%),
560
+ linear-gradient(180deg,rgba(238,244,255,.62),rgba(198,214,246,.46));
561
+ box-shadow:
562
+ inset 0 2px 4px rgba(48,86,170,.42),
563
+ inset 0 1px 0 rgba(255,255,255,.7),
564
+ inset 0 -1px 0 rgba(255,255,255,.5),
565
+ 0 6px 14px -10px rgba(152,184,255,.55)}
566
+ /* 危险操作:玫瑰色玻璃 */
567
+ .cx-btn.stop{color:#f0bcc1;font-weight:550;border-color:rgba(238,178,184,.24);
568
+ background:
569
+ radial-gradient(125% 105% at 50% -45%,rgba(255,200,205,.20),rgba(255,200,205,0) 60%),
570
+ linear-gradient(180deg,rgba(238,178,184,.10),rgba(238,178,184,.04) 55%,rgba(238,178,184,.025))}
571
+ .cx-btn.stop:not(:disabled):hover{color:#f7c9cd;border-color:rgba(238,178,184,.42);
572
+ background:
573
+ radial-gradient(125% 105% at 50% -45%,rgba(255,206,212,.28),rgba(255,206,212,0) 60%),
574
+ linear-gradient(180deg,rgba(238,178,184,.16),rgba(238,178,184,.07) 55%,rgba(238,178,184,.04));
575
+ box-shadow:
576
+ inset 0 1px 0 rgba(255,255,255,.22),
577
+ inset 0 -1px 0 rgba(255,220,222,.08),
578
+ 0 1px 1px rgba(0,0,0,.5),
579
+ 0 10px 22px -14px rgba(238,140,150,.45)}
580
+ .cx-btn:active:not(:disabled){transform:translateY(0)}
581
+ .cx-spin{width:10px;height:10px;flex:none;border-radius:50%;border:1.5px solid rgba(255,255,255,.24);
582
+ border-top-color:currentColor;animation:cx-spin .8s linear infinite;position:relative;z-index:1}
583
+ .cx-btn.start .cx-spin{border-color:rgba(10,13,20,.22);border-top-color:#0c111c}
584
+
585
+ /* 工具格:一颗颗独立的玻璃珠 */
586
+ .cx-tools{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px;flex:none}
587
+ .cx-tools .cx-btn{height:34px;font-size:11.5px;letter-spacing:.03em;border-radius:10px;
588
+ border-color:rgba(255,255,255,.085);color:var(--text-3);
589
+ background:
590
+ radial-gradient(64% 42% at 50% 2%,rgba(255,255,255,.20),rgba(255,255,255,0) 100%),
591
+ radial-gradient(124% 108% at 50% -42%,rgba(255,255,255,.17),rgba(255,255,255,0) 62%),
592
+ linear-gradient(180deg,rgba(255,255,255,.062),rgba(255,255,255,.020));
593
+ box-shadow:
594
+ inset 0 1px 0 rgba(255,255,255,.14),
595
+ inset 0 -1px 0 rgba(255,255,255,.035),
596
+ inset 0 -9px 14px -14px rgba(255,255,255,.28),
597
+ 0 1px 1px rgba(0,0,0,.42),0 8px 14px -14px #000;
598
+ transition:background .18s ease,border-color .18s ease,color .18s ease,box-shadow .18s ease,transform .18s ease,opacity .18s ease}
599
+ /* 主功能(扫描/刷课/作业)比辅助功能高一档:带冷色玻璃 */
600
+ .cx-tools .cx-btn:nth-child(-n+3){color:var(--text-2);font-weight:500;
601
+ border-color:rgba(190,209,255,.16);
602
+ background:
603
+ radial-gradient(64% 42% at 50% 2%,rgba(255,255,255,.30),rgba(255,255,255,0) 100%),
604
+ radial-gradient(124% 108% at 50% -42%,rgba(255,255,255,.26),rgba(255,255,255,0) 62%),
605
+ linear-gradient(180deg,rgba(190,209,255,.12),rgba(169,193,255,.035));
606
+ box-shadow:
607
+ inset 0 1px 0 rgba(255,255,255,.24),
608
+ inset 0 -1px 0 rgba(190,209,255,.10),
609
+ inset 0 -9px 14px -14px rgba(190,209,255,.45),
610
+ 0 1px 1px rgba(0,0,0,.44),0 10px 16px -14px #000}
611
+ .cx-tools .cx-btn:not(:disabled):hover{color:var(--text);border-color:rgba(255,255,255,.22);
612
+ transform:translateY(-1px);
613
+ background:
614
+ radial-gradient(64% 42% at 50% 2%,rgba(255,255,255,.42),rgba(255,255,255,0) 100%),
615
+ radial-gradient(124% 108% at 50% -42%,rgba(255,255,255,.34),rgba(255,255,255,0) 62%),
616
+ linear-gradient(180deg,rgba(255,255,255,.15),rgba(255,255,255,.055));
617
+ box-shadow:
618
+ inset 0 1px 0 rgba(255,255,255,.34),
619
+ inset 0 -1px 0 rgba(255,255,255,.06),
620
+ 0 2px 3px rgba(0,0,0,.4),0 14px 22px -16px rgba(150,180,255,.6)}
621
+ .cx-tools .cx-btn:active:not(:disabled){transform:translateY(0)}
622
+
623
+ /* =========================================================
624
+ L1 · 状态卡
625
+ ========================================================= */
626
+ .cx-metrics{display:flex;flex-direction:column;gap:9px;flex:none;padding:11px 12px;border-radius:14px;
627
+ background:
628
+ radial-gradient(100% 70% at 6% -30%,rgba(159,224,192,.10),rgba(159,224,192,0) 62%),
629
+ linear-gradient(180deg,rgba(255,255,255,.055),rgba(255,255,255,.02) 55%,rgba(255,255,255,.012))}
630
+ .cx-phase{display:flex;align-items:center;gap:8px;min-width:0;font-size:12.5px;color:var(--text)}
631
+ .cx-phase b{font-weight:600;letter-spacing:.01em;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
632
+ text-shadow:0 1px 1px rgba(0,0,0,.35)}
633
+ .cx-phase .cx-dot{width:6px;height:6px;border-radius:50%;background:var(--text-3);flex:none;opacity:.8}
634
+ .cx-phase.run .cx-dot{background:var(--ok);opacity:1;
635
+ box-shadow:0 0 0 3px rgba(159,224,192,.10),0 0 12px rgba(159,224,192,.55)}
636
+ .cx-clock{margin-left:auto;flex:none;font-size:10.5px;color:var(--text-3);
637
+ font-variant-numeric:tabular-nums;letter-spacing:.04em;padding-left:8px}
638
+ .cx-chips{display:flex;flex-wrap:wrap;align-items:center;gap:5px;min-width:0}
639
+ .cx-chip{padding:3px 8px;border-radius:999px;color:var(--text-2);
640
+ border:1px solid rgba(255,255,255,.085);
641
+ background:linear-gradient(180deg,rgba(255,255,255,.07),rgba(255,255,255,.025));
642
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.10),0 1px 2px rgba(0,0,0,.32);
643
+ font-size:10.5px;line-height:1.35;font-variant-numeric:tabular-nums;white-space:nowrap}
644
+ .cx-chip.mint{color:#c6f0dc;border-color:rgba(159,224,192,.22);
645
+ background:linear-gradient(180deg,rgba(159,224,192,.16),rgba(159,224,192,.055));
646
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.12),0 0 14px -8px rgba(159,224,192,.7)}
647
+ .cx-chip.amber{color:#f2dfb8;border-color:rgba(232,205,156,.22);
648
+ background:linear-gradient(180deg,rgba(232,205,156,.16),rgba(232,205,156,.055));
649
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.10),0 0 14px -8px rgba(232,205,156,.65)}
650
+ .cx-chip.muted{color:var(--text-3);background:transparent;border-color:rgba(255,255,255,.055);box-shadow:none}
651
+ .cx-bar{position:relative;height:3px;flex:none;margin-top:1px;border-radius:999px;overflow:hidden;
652
+ background:rgba(0,0,0,.45);box-shadow:inset 0 1px 2px rgba(0,0,0,.6)}
653
+ .cx-bar>i{display:block;height:100%;width:38%;border-radius:999px;
654
+ background:linear-gradient(90deg,rgba(169,193,255,0),var(--accent),rgba(255,255,255,.9),var(--accent),rgba(169,193,255,0));
655
+ box-shadow:0 0 12px rgba(169,193,255,.75);animation:cx-sweep 2.2s ease-in-out infinite}
656
+
657
+ /* =========================================================
658
+ L1 · 提示条
659
+ ========================================================= */
660
+ .cx-notice{display:flex;align-items:flex-start;gap:8px;flex:none;padding:9px 11px;border-radius:11px;
661
+ color:var(--text-2);font-size:11.5px;line-height:1.6;
662
+ border-color:rgba(255,255,255,.09);
663
+ background:linear-gradient(180deg,rgba(255,255,255,.06),rgba(255,255,255,.022))}
664
+ .cx-notice.ok{color:#d2f2e2;border-color:rgba(159,224,192,.26);
665
+ background:linear-gradient(100deg,rgba(159,224,192,.16),rgba(159,224,192,.05) 46%,rgba(255,255,255,.018));
666
+ box-shadow:inset 2px 0 0 rgba(159,224,192,.65),inset 0 1px 0 rgba(255,255,255,.10),0 12px 22px -20px #000}
667
+ .cx-notice.err{color:#f6d3d7;border-color:rgba(238,178,184,.26);
668
+ background:linear-gradient(100deg,rgba(238,178,184,.16),rgba(238,178,184,.05) 46%,rgba(255,255,255,.018));
669
+ box-shadow:inset 2px 0 0 rgba(238,178,184,.65),inset 0 1px 0 rgba(255,255,255,.10),0 12px 22px -20px #000}
670
+ .cx-notice .cx-n-text{flex:1;min-width:0;word-break:break-word;white-space:pre-wrap}
671
+ .cx-notice .cx-n-x{flex:none;padding:0 2px;border:0;background:transparent;color:inherit;
672
+ font-family:inherit;font-size:14px;line-height:1;opacity:.55;cursor:pointer;transition:opacity .15s ease}
673
+ .cx-notice .cx-n-x:hover{opacity:1}
674
+
675
+ /* =========================================================
676
+ L-1 · 终端:下沉的玻璃井
677
+ ========================================================= */
678
+ .cx-console{flex:1 1 auto;min-height:150px;display:flex;flex-direction:column;position:relative;
679
+ border-radius:14px;overflow:hidden;background:#05060a;
680
+ border-color:rgba(255,255,255,.065);
681
+ box-shadow:
682
+ inset 0 2px 8px rgba(0,0,0,.6),
683
+ inset 0 -1px 0 rgba(255,255,255,.035),
684
+ 0 1px 0 rgba(255,255,255,.05),
685
+ 0 24px 40px -34px #000}
686
+ .cx-console-head{display:flex;align-items:center;gap:7px;height:33px;padding:0 7px 0 12px;flex:none;
687
+ border-bottom:1px solid rgba(255,255,255,.06);
688
+ background:linear-gradient(180deg,rgba(255,255,255,.055),rgba(255,255,255,.012));
689
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.10);
690
+ color:var(--text-3);font-size:9.5px;letter-spacing:.14em;text-transform:uppercase}
691
+ .cx-console-title{display:inline-flex;align-items:center;gap:7px;min-width:0;white-space:nowrap}
692
+ .cx-live-dot{width:5px;height:5px;border-radius:50%;background:var(--text-3);opacity:.45;flex:none}
693
+ .cx-console-title.on .cx-live-dot{opacity:1;background:var(--ok);
694
+ box-shadow:0 0 0 3px rgba(159,224,192,.08),0 0 10px rgba(159,224,192,.6);
695
+ animation:cx-breathe 2.4s ease-in-out infinite}
696
+ .cx-sync{margin-left:auto;min-width:0;color:var(--text-3);font-size:9.5px;letter-spacing:.02em;
697
+ text-transform:none;font-variant-numeric:tabular-nums;
698
+ white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
699
+ .cx-tool{position:relative;flex:none;width:25px;height:25px;display:grid;place-items:center;padding:0;
700
+ border:1px solid rgba(255,255,255,.06);border-radius:8px;color:var(--text-3);
701
+ background:linear-gradient(180deg,rgba(255,255,255,.05),rgba(255,255,255,.015));
702
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.08);
703
+ font-family:inherit;font-size:12px;line-height:1;cursor:pointer;overflow:hidden;
704
+ transition:color .15s ease,background .15s ease,border-color .15s ease,box-shadow .15s ease}
705
+ .cx-tool:hover{color:var(--text);border-color:rgba(255,255,255,.18);
706
+ background:linear-gradient(180deg,rgba(255,255,255,.11),rgba(255,255,255,.04));
707
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.18),0 6px 12px -10px #000}
708
+ .cx-out{flex:1;min-height:0;overflow:auto;padding:10px 12px 12px;
709
+ background:radial-gradient(120% 80% at 0 0,rgba(169,193,255,.028),transparent 58%);
710
+ color:#b8c0cf;font-family:var(--mono);font-size:11.2px;line-height:1.75;
711
+ white-space:pre-wrap;word-break:break-word}
712
+ .cx-out::-webkit-scrollbar{width:6px;height:6px}
713
+ .cx-out::-webkit-scrollbar-thumb{background:rgba(255,255,255,.10);border-radius:999px}
714
+ .cx-out::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.2)}
715
+ .cx-out::-webkit-scrollbar-track{background:transparent}
716
+ .cx-line{color:#b8c0cf}
717
+ .cx-line-head{color:#f1f4fa;font-weight:500}
718
+ .cx-line-ok{color:#aee3c8}
719
+ .cx-line-warn{color:#eed6a8}
720
+ .cx-line-dim{color:#7c8492}
721
+ .cx-empty{height:100%;min-height:96px;display:flex;flex-direction:column;align-items:center;
722
+ justify-content:center;gap:7px;padding:16px;text-align:center;color:var(--text-3);font-size:11.5px}
723
+ .cx-empty .cx-e-glyph{width:36px;height:36px;display:grid;place-items:center;border-radius:50%;
724
+ border:1px solid rgba(255,255,255,.13);color:var(--text-2);font-size:14px;line-height:1;
725
+ background:
726
+ radial-gradient(120% 120% at 30% 0,rgba(169,193,255,.20),rgba(255,255,255,.02) 62%),
727
+ linear-gradient(180deg,rgba(255,255,255,.07),rgba(255,255,255,.02));
728
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.16),0 8px 16px -12px rgba(169,193,255,.5)}
729
+ .cx-empty .cx-e-tip{max-width:26em;font-size:10.5px;line-height:1.65;opacity:.9}
730
+ .cx-empty>div:nth-child(2){color:var(--text-2);font-size:12px;letter-spacing:.01em}
731
+ .cx-console:has(.cx-jump) .cx-out{padding-bottom:40px}
732
+ .cx-jump{position:absolute;right:10px;bottom:10px;height:25px;padding:0 11px;border-radius:999px;
733
+ border:1px solid rgba(255,255,255,.16);color:var(--text);
734
+ background:linear-gradient(180deg,rgba(255,255,255,.14),rgba(255,255,255,.05));
735
+ -webkit-backdrop-filter:blur(10px) saturate(150%);backdrop-filter:blur(10px) saturate(150%);
736
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.24),0 10px 22px rgba(0,0,0,.55);
737
+ font-family:inherit;font-size:10.5px;cursor:pointer}
738
+ .cx-jump:hover{background:linear-gradient(180deg,rgba(255,255,255,.20),rgba(255,255,255,.08))}
739
+
740
+ /* =========================================================
741
+ L0 · 页脚
742
+ ========================================================= */
743
+ .cx-foot{flex:none;display:flex;align-items:center;gap:5px;padding:8px 2px 0;
744
+ border-top:1px solid rgba(255,255,255,.055);color:var(--text-3);
745
+ font-size:9.5px;letter-spacing:.03em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
746
+ .cx-foot b{color:var(--text-2);font-weight:550;font-variant-numeric:tabular-nums;
747
+ font-family:var(--mono);font-size:9.5px}
748
+
749
+ .cx-root button:focus-visible,.cx-root input:focus-visible{
750
+ outline:2px solid rgba(169,193,255,.65);outline-offset:2px}
751
+
752
+ @keyframes cx-enter{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
753
+ @keyframes cx-liquid{0%,100%{transform:translateX(-14%) scaleX(1);opacity:.55}
754
+ 50%{transform:translateX(14%) scaleX(1.12);opacity:.95}}
755
+ @keyframes cx-breathe{0%,100%{opacity:.35}50%{opacity:1}}
756
+ @keyframes cx-spin{to{transform:rotate(360deg)}}
757
+ @keyframes cx-sweep{0%{transform:translateX(-110%)}100%{transform:translateX(320%)}}
758
+ @keyframes cx-sheen{0%{opacity:0;transform:translateX(-120%) skewX(-10deg)}
759
+ 16%{opacity:1}
760
+ 72%{opacity:.55}
761
+ 100%{opacity:0;transform:translateX(120%) skewX(-10deg)}}
762
+
763
+ @container cxroot (max-width:340px){
764
+ .cx-root{gap:9px;padding:12px 11px 10px}
765
+ .cx-head{padding:10px;gap:9px;border-radius:14px}
766
+ .cx-logo{width:33px;height:33px;border-radius:11px;font-size:17px}
767
+ .cx-sub{display:none}
768
+ .cx-section .cx-cap-hint{display:none}
769
+ .cx-cta{grid-template-columns:minmax(0,1fr) 78px;gap:7px}
770
+ .cx-ok{min-width:58px;padding:0 11px}
771
+ .cx-tools{gap:6px}
772
+ .cx-tools .cx-btn{font-size:11px;height:32px}
773
+ .cx-foot{font-size:9px}
774
+ }
775
+ @container cxroot (max-width:300px){
776
+ .cx-root{gap:8px;padding:11px 10px 9px;border-radius:13px}
777
+ .cx-title{font-size:14px}
778
+ .cx-pill{max-width:44%;padding:3px 7px;font-size:9.5px}
779
+ .cx-mode{font-size:11px;padding:0 6px}
780
+ .cx-btn{font-size:12px;height:36px;border-radius:10px}
781
+ .cx-tools .cx-btn{height:31px;font-size:10.5px}
782
+ .cx-chip{font-size:10px;padding:2px 6px}
783
+ .cx-metrics{padding:10px}
784
+ }
785
+ @media (prefers-reduced-motion:reduce){
786
+ .cx-root{animation:none}
787
+ .cx-root *,.cx-root *::before,.cx-root *::after{animation:none!important;transition:none!important}
788
+ }
789
+ `;
790
+
791
+ /* ---------------- 组件 ---------------- */
792
+
793
+ class PanelBoundary extends React.Component {
794
+ constructor(props) {
795
+ super(props);
796
+ this.state = { error: null };
797
+ }
798
+ static getDerivedStateFromError(error) {
799
+ return { error: error };
800
+ }
801
+ render() {
802
+ if (this.state.error) {
803
+ return h('div', { className: 'cx-root' },
804
+ h('div', { className: 'cx-empty' },
805
+ h('div', { className: 'cx-e-glyph' }, '⚠'),
806
+ h('div', null, '面板渲染出错'),
807
+ h('div', { className: 'cx-e-tip' }, String((this.state.error && this.state.error.message) || this.state.error || ''))
808
+ )
809
+ );
810
+ }
811
+ return this.props.children;
812
+ }
813
+ }
814
+
815
+ function Notice(props) {
816
+ const n = props.notice;
817
+ if (!n) return null;
818
+ return h('div', { className: 'cx-notice' + (n.kind === 'ok' ? ' ok' : n.kind === 'err' ? ' err' : ''), role: 'status' },
819
+ h('span', { className: 'cx-n-text' }, n.text),
820
+ h('button', { type: 'button', className: 'cx-n-x', title: '关闭提示', 'aria-label': '关闭提示', onClick: props.onClose }, '×')
821
+ );
822
+ }
823
+
824
+ /** 行动按钮:只有被点的那颗转圈,其余仅变灰;「停止」始终保持可点 */
825
+ function ActionButton(props) {
826
+ const item = props.item;
827
+ const busy = props.pending === item.key;
828
+ const blocked = !!props.pending && !busy && item.key !== 'stop';
829
+ return h('button', {
830
+ type: 'button',
831
+ className: 'cx-btn' + (item.cls ? ' ' + item.cls : ''),
832
+ disabled: blocked || !!props.disabled,
833
+ 'aria-busy': busy ? 'true' : 'false',
834
+ title: item.title || item.label,
835
+ onClick: () => props.onAct(item.key),
836
+ },
837
+ busy ? h('span', { className: 'cx-spin', 'aria-hidden': 'true' }) : null,
838
+ h('span', { className: 'cx-btn-label' }, item.label)
839
+ );
840
+ }
841
+
842
+ /** 独立计时的运行时长:只让这一小块每秒重渲染 */
843
+ function Elapsed(props) {
844
+ const [, tick] = useState(0);
845
+ const active = !!props.active;
846
+ useEffect(() => {
847
+ if (!active) return undefined;
848
+ const id = setInterval(() => tick((v) => v + 1), 1000);
849
+ return () => clearInterval(id);
850
+ }, [active]);
851
+ const base = Number(props.base || 0);
852
+ if (!base && !active) return null;
853
+ const sec = base + (active ? Math.max(0, (Date.now() - Number(props.at || Date.now())) / 1000) : 0);
854
+ return h('span', { className: 'cx-clock', title: '已运行时长' }, fmtClock(sec));
855
+ }
856
+
857
+ function Panel(props) {
858
+ const app = (props && props.ctx) || {};
859
+ const [text, setText] = useState('');
860
+ const [state, setState] = useState(null);
861
+ const [live, setLive] = useState(null); // null=连接中 true=已连接 false=断开
862
+ const [pending, setPending] = useState(''); // 正在执行的动作 key
863
+ const [course, setCourse] = useState(loadCourse);
864
+ const [mode, setMode] = useState(loadMode);
865
+ const [notice, setNotice] = useState(null);
866
+ const [at, setAt] = useState(0);
867
+ const [latency, setLatency] = useState(0);
868
+ const [clock, setClock] = useState(null); // { sec, at }:从进度文本解析的运行时长
869
+ const [bottom, setBottom] = useState(true);
870
+
871
+ const modeRef = useRef(null);
872
+ const pendingRef = useRef('');
873
+ const epochRef = useRef(0);
874
+ const refreshRef = useRef(null);
875
+ const outRef = useRef(null);
876
+ const stickRef = useRef(true);
877
+
878
+ modeRef.current = mode;
879
+ const connected = live !== false;
880
+ const phase = (state && state.phase) || 'idle';
881
+ const stats = (state && state.stats) || {};
882
+ const desk = (state && state.desktop) || null;
883
+ const running = !!(state && state.running) && connected;
884
+ const deskActive = !!(desk && (desk.state === 'running' || desk.state === 'starting'));
885
+ const active = mode === 'desktop' ? deskActive : running;
886
+
887
+ let headLabel;
888
+ let chipSource;
889
+ if (mode === 'desktop') {
890
+ if (desk) {
891
+ headLabel = DESK_PHASES[desk.phase] || DESK_PHASES[desk.state] || desk.phase || '运行中';
892
+ chipSource = 'desk';
893
+ } else {
894
+ const raw = deskHeadFromText(text);
895
+ headLabel = DESK_PHASES[raw] || raw || '空闲';
896
+ chipSource = 'text';
897
+ }
898
+ } else {
899
+ headLabel = PHASES[phase] || phase || '空闲';
900
+ chipSource = 'web';
901
+ }
902
+
903
+ const chips = [];
904
+ if (!connected && state) chips.push({ text: '离线 · 数据已过期', cls: 'amber' });
905
+ if (chipSource === 'desk') {
906
+ const p = desk.progress || {};
907
+ if (desk.item) chips.push({ text: '节点 ' + desk.item, cls: 'mint' });
908
+ if (p.videos || p.docs || p.quizzes) {
909
+ chips.push({ text: '视频 ' + (p.videos || 0) + ' · 文档 ' + (p.docs || 0) + ' · 测验 ' + (p.quizzes || 0), cls: '' });
910
+ }
911
+ if (p.itemsPending) chips.push({ text: '待完成 ' + p.itemsPending, cls: 'amber' });
912
+ if (p.worksFound || p.worksDone) chips.push({ text: '作业 ' + (p.worksDone || 0) + '/' + ((p.worksFound || 0) + (p.worksDone || 0)), cls: '' });
913
+ } else if (chipSource === 'text') {
914
+ // 旧桥兜底:从展示文本里刮(后端升级到 /state.desktop 后不再走这里)
915
+ const node = /节点\s*([^\s·]+)/.exec(text || '');
916
+ const media = /视频\s*(\d+)\s*·\s*文档\s*(\d+)\s*·\s*测验\s*(\d+)/.exec(text || '');
917
+ const pendingCnt = /未完成任务点\s*(\d+)/.exec(text || '');
918
+ const works = /作业\s*未交\s*(\d+)/.exec(text || '');
919
+ if (node) chips.push({ text: '节点 ' + node[1], cls: 'mint' });
920
+ if (media) chips.push({ text: '视频 ' + media[1] + ' · 文档 ' + media[2] + ' · 测验 ' + media[3], cls: '' });
921
+ if (pendingCnt) chips.push({ text: '待完成 ' + pendingCnt[1], cls: 'amber' });
922
+ if (works) chips.push({ text: '作业未交 ' + works[1], cls: '' });
923
+ } else {
924
+ if (stats.courses) chips.push({ text: '课程 ' + (stats.coursesDone || 0) + '/' + stats.courses, cls: '' });
925
+ if (stats.nodesDone) chips.push({ text: '节点 ' + stats.nodesDone, cls: 'mint' });
926
+ if (stats.nodesFailed) chips.push({ text: '失败 ' + stats.nodesFailed, cls: 'amber' });
927
+ if (stats.gained) chips.push({ text: '得分 +' + stats.gained, cls: 'mint' });
928
+ if (stats.quizzesSolved) chips.push({ text: '测验 ' + stats.quizzesSolved, cls: '' });
929
+ if (stats.worksSolved) chips.push({ text: '作业 ' + stats.worksSolved, cls: '' });
930
+ }
931
+ if (state && state.jobs && state.jobs.length) chips.push({ text: '任务 ' + state.jobs.length, cls: 'muted' });
932
+
933
+ useEffect(() => {
934
+ try { saveCourse(course); } catch (e) { /* ignore */ }
935
+ }, [course]);
936
+
937
+ useEffect(() => {
938
+ try { saveMode(mode); } catch (e) { /* ignore */ }
939
+ }, [mode]);
940
+
941
+ // 轮询:1 个 /snapshot 请求;失败退避(2.5s→5s→10s→20s),成功立即恢复
942
+ useEffect(() => {
943
+ let alive = true;
944
+ let timer = null;
945
+ let fails = 0;
946
+ let hidden = false;
947
+ const clear = () => { if (timer) { clearTimeout(timer); timer = null; } };
948
+ const schedule = (ms) => {
949
+ clear();
950
+ if (!alive) return;
951
+ timer = setTimeout(tick, Math.max(0, ms));
952
+ };
953
+ const tick = async () => {
954
+ if (!alive) return;
955
+ // 不可见时也继续轮询(只是放慢):旧版直接跳过,窗口最小化/被挡时面板一直停在「未连接」
956
+ const docHidden = typeof document !== 'undefined' && !!document.hidden;
957
+ hidden = docHidden;
958
+ const m = modeRef.current || '';
959
+ const epoch = epochRef.current;
960
+ const t0 = nowMs();
961
+ try {
962
+ const snap = await getSnapshot(m);
963
+ if (!alive) return;
964
+ // 切模式或手动刷新后,旧请求的响应直接丢掉,避免覆盖新状态
965
+ if (epoch !== epochRef.current || m !== (modeRef.current || '')) { schedule(0); return; }
966
+ fails = 0;
967
+ setLatency(Math.round(nowMs() - t0));
968
+ setLive(true);
969
+ setState((prev) => (sameState(prev, snap.state) ? prev : snap.state));
970
+ setText((prev) => (prev === snap.text ? prev : snap.text));
971
+ setAt(Date.now());
972
+ const el = parseElapsed(snap.text);
973
+ if (el != null) setClock({ sec: el, at: Date.now() });
974
+ schedule(docHidden ? HIDDEN_POLL_MS : POLL_MS);
975
+ } catch (e) {
976
+ if (!alive) return;
977
+ fails += 1;
978
+ dropBase();
979
+ setLive(false);
980
+ const why = String((e && e.message) || e || '').slice(0, 120);
981
+ setText((prev) => prev || ('› 面板服务未连接' + (why ? '(' + why + ')' : '') +
982
+ '\n · 同源路由 /chaoxing 与端口 ' + UI_PORT + ' 都不可达' +
983
+ '\n · 自动重连中,也可点右上角 ⟲ 立即重试'));
984
+ schedule(Math.min(POLL_MS * Math.pow(2, Math.min(fails - 1, 3)), MAX_BACKOFF_MS));
985
+ }
986
+ };
987
+ refreshRef.current = () => { fails = 0; dropBase(); schedule(0); };
988
+ tick();
989
+ const onVis = () => {
990
+ if (typeof document !== 'undefined' && !document.hidden) {
991
+ if (hidden) { hidden = false; fails = 0; schedule(0); }
992
+ }
993
+ };
994
+ if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVis);
995
+ return () => {
996
+ alive = false;
997
+ clear();
998
+ refreshRef.current = null;
999
+ if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVis);
1000
+ };
1001
+ }, []);
1002
+
1003
+ useEffect(() => {
1004
+ if (!notice) return undefined;
1005
+ const id = setTimeout(() => setNotice(null), notice.kind === 'err' ? 9000 : 5000);
1006
+ return () => clearTimeout(id);
1007
+ }, [notice]);
1008
+
1009
+ useEffect(() => {
1010
+ const el = outRef.current;
1011
+ if (!el || !stickRef.current) return;
1012
+ el.scrollTop = el.scrollHeight;
1013
+ }, [text]);
1014
+
1015
+ const act = async (key, forceMode) => {
1016
+ const cur = pendingRef.current;
1017
+ if (cur && key !== 'stop' && cur !== key) {
1018
+ setNotice({ kind: 'err', text: '正在执行「' + labelOf(cur) + '」,等它结束或点「停止」' });
1019
+ return null;
1020
+ }
1021
+ if (cur === key) return null;
1022
+ const curMode = forceMode || modeRef.current;
1023
+ const c = String(course || '').trim();
1024
+ if (key === 'focus' && !c) {
1025
+ setNotice({ kind: 'err', text: '先在课程框里输入课程名,再点「确定」' });
1026
+ return null;
1027
+ }
1028
+ const body = { mode: curMode || undefined };
1029
+ if (c) {
1030
+ body.course = c;
1031
+ if (NEEDS_COURSE.indexOf(key) >= 0) body.courses = [c];
1032
+ }
1033
+ pendingRef.current = key;
1034
+ setPending(key);
1035
+ try {
1036
+ const j = await postAction(key, body);
1037
+ const ok = !!(j && j.ok !== false);
1038
+ if (ok) {
1039
+ let msg = j && j.text ? String(j.text) : '已执行「' + labelOf(key) + '」';
1040
+ if (key === 'refresh') msg = '进度已刷新';
1041
+ setNotice({ kind: 'ok', text: msg });
1042
+ if (key === 'refresh' && j && typeof j.text === 'string') {
1043
+ // /action refresh 本身就返回了最新进度文本,直接落盘,不再多打一次 /snapshot
1044
+ const t = j.text;
1045
+ setText(t);
1046
+ setAt(Date.now());
1047
+ const el = parseElapsed(t);
1048
+ setClock(el != null ? { sec: el, at: Date.now() } : null);
1049
+ setLive(true);
1050
+ } else if (refreshRef.current) {
1051
+ refreshRef.current();
1052
+ }
1053
+ } else {
1054
+ setNotice({ kind: 'err', text: (j && j.text) ? String(j.text) : '操作失败' });
1055
+ }
1056
+ return j;
1057
+ } catch (e) {
1058
+ const m = e && (e.name === 'AbortError' ? '请求超时(90 秒)' : (e.message || String(e)));
1059
+ setNotice({ kind: 'err', text: '操作失败:' + m });
1060
+ return null;
1061
+ } finally {
1062
+ pendingRef.current = '';
1063
+ setPending('');
1064
+ }
1065
+ };
1066
+
1067
+ const chooseMode = (key) => {
1068
+ if (mode === key) {
1069
+ if (refreshRef.current) refreshRef.current();
1070
+ return;
1071
+ }
1072
+ epochRef.current += 1;
1073
+ modeRef.current = key;
1074
+ setMode(key);
1075
+ setClock(null);
1076
+ act(key, key);
1077
+ };
1078
+
1079
+ const onOutScroll = () => {
1080
+ const el = outRef.current;
1081
+ if (!el) return;
1082
+ const near = el.scrollHeight - el.scrollTop - el.clientHeight < 28;
1083
+ stickRef.current = near;
1084
+ setBottom((prev) => (prev === near ? prev : near));
1085
+ };
1086
+
1087
+ const jumpToBottom = () => {
1088
+ const el = outRef.current;
1089
+ if (!el) return;
1090
+ el.scrollTop = el.scrollHeight;
1091
+ stickRef.current = true;
1092
+ setBottom(true);
1093
+ };
1094
+
1095
+ const copyText = async () => {
1096
+ try {
1097
+ if (navigator.clipboard && navigator.clipboard.writeText) {
1098
+ await navigator.clipboard.writeText(text || '');
1099
+ } else {
1100
+ const ta = document.createElement('textarea');
1101
+ ta.value = text || '';
1102
+ ta.style.position = 'fixed';
1103
+ ta.style.opacity = '0';
1104
+ document.body.appendChild(ta);
1105
+ ta.select();
1106
+ document.execCommand('copy');
1107
+ document.body.removeChild(ta);
1108
+ }
1109
+ setNotice({ kind: 'ok', text: '已复制当前进度文本' });
1110
+ } catch (e) {
1111
+ setNotice({ kind: 'err', text: '复制失败:' + (e && e.message ? e.message : e) });
1112
+ }
1113
+ };
1114
+
1115
+ const lines = useMemo(() => {
1116
+ const raw = String(text || '');
1117
+ if (!raw.trim()) return [];
1118
+ const all = raw.split('\n');
1119
+ const tail = all.length > MAX_LINES ? all.slice(all.length - MAX_LINES) : all;
1120
+ return tail.map((l, i) => ({ k: i, cls: lineClass(l), t: l === '' ? ' ' : l }));
1121
+ }, [text]);
1122
+
1123
+ const pillCls = live === false ? ' off' : active ? ' on' : live === true ? ' idle' : '';
1124
+ const pillText = live === false ? '未连接' : live === null ? '连接中' : active ? '运行中 · ' + headLabel : '空闲';
1125
+
1126
+ const baseSec = mode === 'desktop' ? (desk ? desk.elapsedSec : 0) : (clock ? clock.sec : 0);
1127
+ const baseAt = mode === 'desktop' ? at : (clock ? clock.at : at);
1128
+
1129
+ const syncLabel = live === false
1130
+ ? '未连接 · 重连中'
1131
+ : at
1132
+ ? '同步 ' + fmtTime(at) + (latency ? ' · ' + latency + 'ms' : '')
1133
+ : '等待数据';
1134
+
1135
+ const emptyTitle = live === null
1136
+ ? '正在连接面板服务…'
1137
+ : live === false
1138
+ ? '面板服务未连接'
1139
+ : !mode
1140
+ ? '先选运行环境'
1141
+ : '还没有进度输出';
1142
+ const emptyTip = live === false
1143
+ ? '确认 DSH 正在运行(端口 ' + UI_PORT + '),会自动重连'
1144
+ : !mode
1145
+ ? '网页版用自带 Edge,桌面版用本机学习通客户端'
1146
+ : '开始任务后这里会滚动显示实时进度';
1147
+
1148
+ return h('div', { className: 'cx-root' },
1149
+ h('div', { className: 'cx-head' },
1150
+ h('div', { className: 'cx-logo', 'aria-hidden': 'true' }, '学'),
1151
+ h('div', { className: 'cx-brand' },
1152
+ h('div', { className: 'cx-title' }, '学习通助手'),
1153
+ h('div', { className: 'cx-sub' }, 'Chaoxing Autopilot')
1154
+ ),
1155
+ h('span', {
1156
+ className: 'cx-pill' + pillCls,
1157
+ 'aria-live': 'polite',
1158
+ title: '阶段:' + headLabel,
1159
+ },
1160
+ h('i', { className: 'cx-dot', 'aria-hidden': 'true' }),
1161
+ pillText
1162
+ )
1163
+ ),
1164
+
1165
+ h('div', { className: 'cx-section' },
1166
+ h('div', { className: 'cx-cap' },
1167
+ h('span', null, '运行环境'),
1168
+ h('span', { className: 'cx-cap-hint' }, 'WEB / DESKTOP')
1169
+ ),
1170
+ h('div', { className: 'cx-modes', role: 'group', 'aria-label': '运行环境' },
1171
+ MODES.map((m) => h('button', {
1172
+ key: m.key,
1173
+ type: 'button',
1174
+ title: m.name + ':' + m.desc,
1175
+ className: 'cx-mode' + (mode === m.key ? ' active' : ''),
1176
+ 'aria-pressed': mode === m.key,
1177
+ onClick: () => chooseMode(m.key),
1178
+ }, h('span', null, m.name)))
1179
+ )
1180
+ ),
1181
+
1182
+ mode ? h('div', { className: 'cx-course' },
1183
+ h('div', { className: 'cx-cap' },
1184
+ h('span', null, '目标课程'),
1185
+ h('span', { className: 'cx-cap-hint' }, '留空 = 全部课程')
1186
+ ),
1187
+ h('div', { className: 'cx-row' },
1188
+ h('div', { className: 'cx-inputwrap' },
1189
+ h('input', {
1190
+ className: 'cx-input',
1191
+ value: course,
1192
+ placeholder: '输课程名,如:电工电子技术',
1193
+ 'aria-label': '目标课程',
1194
+ onChange: (e) => setCourse(e.target.value),
1195
+ onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); try { e.target.blur(); } catch (err) { /* ignore */ } } },
1196
+ }),
1197
+ course ? h('button', {
1198
+ type: 'button',
1199
+ className: 'cx-clear',
1200
+ title: '清空课程名',
1201
+ 'aria-label': '清空课程名',
1202
+ onClick: () => setCourse(''),
1203
+ }, '×') : null
1204
+ ),
1205
+ h('button', {
1206
+ type: 'button',
1207
+ className: 'cx-ok',
1208
+ disabled: !String(course || '').trim() || pending === 'focus',
1209
+ title: '用这门课重新开始自动任务(会中断当前队列,只跑这一门)',
1210
+ onClick: () => act('focus'),
1211
+ }, pending === 'focus' ? h('span', { className: 'cx-spin', 'aria-hidden': 'true' }) : '确定')
1212
+ )
1213
+ ) : null,
1214
+
1215
+ h('div', { className: 'cx-controls' },
1216
+ h('div', { className: 'cx-cta' },
1217
+ CTA.map((b) => h(ActionButton, {
1218
+ key: b.key,
1219
+ item: Object.assign({}, b, { title: b.key === 'start' ? '开始/继续自动任务' : '停止所有任务(不会自动恢复)' }),
1220
+ pending,
1221
+ disabled: !mode && b.key === 'start',
1222
+ onAct: act,
1223
+ }))
1224
+ ),
1225
+ h('div', { className: 'cx-tools', role: 'group', 'aria-label': '任务操作' },
1226
+ CORE.concat(AUX).map((b) => h(ActionButton, {
1227
+ key: b.key,
1228
+ item: Object.assign({}, b, {
1229
+ title: b.needsCourse && String(course || '').trim()
1230
+ ? b.label + ':只处理《' + String(course).trim() + '》'
1231
+ : b.label,
1232
+ }),
1233
+ pending,
1234
+ disabled: !mode,
1235
+ onAct: act,
1236
+ }))
1237
+ )
1238
+ ),
1239
+
1240
+ (state || mode === 'desktop') ? h('div', { className: 'cx-metrics' },
1241
+ h('div', { className: 'cx-phase' + (active ? ' run' : '') },
1242
+ h('i', { className: 'cx-dot', 'aria-hidden': 'true' }),
1243
+ h('b', null, headLabel),
1244
+ h(Elapsed, { base: baseSec, at: baseAt, active })
1245
+ ),
1246
+ chips.length ? h('div', { className: 'cx-chips' },
1247
+ chips.map((c, i) => h('span', { key: i, className: 'cx-chip ' + c.cls }, c.text))
1248
+ ) : null,
1249
+ active ? h('div', { className: 'cx-bar', 'aria-hidden': 'true' }, h('i')) : null
1250
+ ) : null,
1251
+
1252
+ h(Notice, { notice: notice, onClose: () => setNotice(null) }),
1253
+
1254
+ h('div', { className: 'cx-console' },
1255
+ h('div', { className: 'cx-console-head' },
1256
+ h('span', { className: 'cx-console-title' + (active ? ' on' : '') },
1257
+ h('i', { className: 'cx-live-dot', 'aria-hidden': 'true' }),
1258
+ '实时输出'
1259
+ ),
1260
+ h('span', { className: 'cx-sync' }, syncLabel),
1261
+ h('button', { type: 'button', className: 'cx-tool', title: '立即重新连接', 'aria-label': '立即重新连接', onClick: () => { if (refreshRef.current) refreshRef.current(); } }, '⟲'),
1262
+ h('button', { type: 'button', className: 'cx-tool', title: '复制进度文本', 'aria-label': '复制进度文本', onClick: copyText }, '⧉')
1263
+ ),
1264
+ h('div', {
1265
+ className: 'cx-out',
1266
+ ref: outRef,
1267
+ onScroll: onOutScroll,
1268
+ role: 'log',
1269
+ 'aria-live': 'off',
1270
+ 'aria-label': '实时进度输出',
1271
+ },
1272
+ lines.length
1273
+ ? lines.map((l) => h('div', { key: l.k, className: l.cls }, l.t))
1274
+ : h('div', { className: 'cx-empty' },
1275
+ h('div', { className: 'cx-e-glyph', 'aria-hidden': 'true' }, '◌'),
1276
+ h('div', null, emptyTitle),
1277
+ h('div', { className: 'cx-e-tip' }, emptyTip)
1278
+ )
1279
+ ),
1280
+ !bottom && lines.length ? h('button', { type: 'button', className: 'cx-jump', onClick: jumpToBottom }, '↓ 最新') : null
1281
+ ),
1282
+
1283
+ h('div', { className: 'cx-foot' },
1284
+ h('span', null, '面板通道 '),
1285
+ h('b', null, baseLabel()),
1286
+ h('span', null, ' · 备用 127.0.0.1:' + UI_PORT),
1287
+ h('span', null, ' · ' + (POLL_MS / 1000) + 's 自动刷新'),
1288
+ h('span', null, ' · v' + VERSION)
1289
+ )
1290
+ );
1291
+ }
1292
+
1293
+ /* ---------------- 注册 ---------------- */
1294
+
1295
+ function apply(ctx) {
1296
+ const app = ctx || {};
1297
+ const offs = [];
1298
+
1299
+ // 无 DOM 环境(测试/SSR/宿主只拿 factory 不挂载)时跳过样式注入,避免 apply 直接抛错
1300
+ if (typeof document !== 'undefined' && document && typeof document.createElement === 'function') {
1301
+ const old = document.getElementById(STYLE_ID);
1302
+ if (old) old.remove();
1303
+ const style = document.createElement('style');
1304
+ style.id = STYLE_ID;
1305
+ style.textContent = CSS;
1306
+ (document.head || document.body || document.documentElement).appendChild(style);
1307
+ offs.push(() => { try { style.remove(); } catch (e) { /* ignore */ } });
1308
+ }
1309
+
1310
+ if (app.slots && typeof app.slots.register === 'function') {
1311
+ // 槽位可能由宿主插件稍后才声明:用 slots.inject 等它出现再注册,
1312
+ // 直接 register 会在槽位尚未声明时抛错而被静默吞掉(旧版即因此不显示)。
1313
+ const put = (name, spec, Comp) => {
1314
+ const full = Object.assign({ name: name }, spec);
1315
+ let off;
1316
+ if (typeof app.slots.inject === 'function') {
1317
+ off = app.slots.inject(name, () => app.slots.register(full, Comp));
1318
+ } else {
1319
+ off = app.slots.register(full, Comp);
1320
+ }
1321
+ if (typeof off === 'function') offs.push(off);
1322
+ };
1323
+
1324
+ try {
1325
+ put('sidebar.right.pane.tab', { key: DEF_ID }, (props) =>
1326
+ h(PanelBoundary, null, h(Panel, Object.assign({}, props, { ctx: app })))
1327
+ );
1328
+ } catch (e) {
1329
+ try { console.warn('[chaoxing] register pane failed', e && e.message); } catch (e2) { /* ignore */ }
1330
+ }
1331
+ // 右侧边栏:注册一个「学习通」标签类型 + 引导页入口(左侧栏设置按钮保持原样,不再占用 footer 槽位)。
1332
+ // sidebarRightTabs 由 sidebar-right 插件运行时 reflect.provide,不能写进 inject(会让整个插件永远不 apply);
1333
+ // 等到右侧边栏的 pane.tab 槽位出现(说明该插件已就绪)再注册,失败只告警。
1334
+ let tabTypeReg = false;
1335
+ const registerRightTab = () => {
1336
+ if (tabTypeReg) return;
1337
+ let tabs = null;
1338
+ try { tabs = app.get && app.get('sidebarRightTabs'); } catch (e) { tabs = null; }
1339
+ if (!tabs || typeof tabs.register !== 'function') return;
1340
+ let off = null;
1341
+ try {
1342
+ off = tabs.register({
1343
+ id: DEF_ID,
1344
+ kind: DEF_ID,
1345
+ priority: 'plugin',
1346
+ title: () => '学习通',
1347
+ keepMounted: true,
1348
+ guide: [
1349
+ {
1350
+ id: DEF_ID,
1351
+ order: 40,
1352
+ title: () => '学习通',
1353
+ description: () => '刷课 · 作业 · 进度面板',
1354
+ },
1355
+ ],
1356
+ });
1357
+ } catch (e) {
1358
+ // 热重载后旧实例可能还占着同 id:当成已注册,避免轮询里反复抛错。
1359
+ if (e && /already registered/i.test(String(e.message || e))) { tabTypeReg = true; return; }
1360
+ throw e;
1361
+ }
1362
+ tabTypeReg = true;
1363
+ if (typeof off === 'function') offs.push(off);
1364
+ };
1365
+ // 右侧边栏服务是运行时 provide 的:等 pane.tab 槽位出现后再试,失败则短轮询直到就绪(最多 ~16s)。
1366
+ const tryRegisterRightTab = () => {
1367
+ try { registerRightTab(); } catch (e) {
1368
+ try { console.warn('[chaoxing] register right tab type failed', e && e.message); } catch (e2) { /* ignore */ }
1369
+ }
1370
+ };
1371
+ try {
1372
+ if (typeof app.slots.inject === 'function') {
1373
+ const offWait = app.slots.inject('sidebar.right.pane.tab', tryRegisterRightTab);
1374
+ if (typeof offWait === 'function') offs.push(offWait);
1375
+ }
1376
+ } catch (e) {
1377
+ try { console.warn('[chaoxing] right tab type inject failed', e && e.message); } catch (e2) { /* ignore */ }
1378
+ }
1379
+ let tabTries = 0;
1380
+ const tabTimer = setInterval(() => {
1381
+ tabTries += 1;
1382
+ if (tabTypeReg || tabTries > 40) { clearInterval(tabTimer); return; }
1383
+ tryRegisterRightTab();
1384
+ }, 400);
1385
+ if (typeof tabTimer.unref === 'function') tabTimer.unref();
1386
+ offs.push(() => clearInterval(tabTimer));
1387
+ }
1388
+
1389
+ const dispose = () => {
1390
+ while (offs.length) {
1391
+ const fn = offs.pop();
1392
+ try { if (typeof fn === 'function') fn(); } catch (e) { /* ignore */ }
1393
+ }
1394
+ };
1395
+ return dispose;
1396
+ }
1397
+
1398
+ return { inject: ['slots'], apply };
1399
+ },
1400
+ });