dsh-zju-lecture-note 2.2.5 → 2.2.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/lib/client.js CHANGED
@@ -1,758 +1,907 @@
1
- /**
2
- * Browser half of dsh-zju-lecture-note.
3
- *
4
- * The same page is mounted twice, from two seats the shell owns:
5
- *
6
- * - `settings.section` — 设置 → 浙大智云课堂讲义 (the deep link), id `zju-lecture`;
7
- * - `sidebar.panellist` + `main` — the left-column row 智云讲义, whose click
8
- * selects the global panel registered under the same id.
9
- *
10
- * Both render one component over one `PipelineSettings` controller, so a switch
11
- * moved in either place shows up in the other without a reload.
12
- *
13
- * The page is built around the actual pipeline — 字幕 → 讲义 → PDF — and every
14
- * optional module is a separate switch with its own dependency and cost, so a
15
- * user can see what they are turning on before they turn it on.
16
- *
17
- * - `renderPdf` auto-typeset the written note into a reading PDF
18
- * - `enableStudyNotes` fill-in study notes (+ scholia-notes Skill)
19
- * - `enableSlides` projected-slide capture
20
- * - `embedSlideImages` reference those screenshots in the note
21
- * - `enableLoginTools` video URL / Edge-cookie helpers
22
- *
23
- * The Host exposes only `Config` fields marked `.volatile()`. Writes go
24
- * through the shared `configForms` scope, so they carry the current revision
25
- * and are refused rather than clobbering a newer value. Plain JavaScript,
26
- * React from the host module table, no build step.
27
- */
28
-
29
- window.__ModuleLoader__.load({
30
- id: 'dsh-zju-lecture-note',
31
- factory(require) {
32
- const React = require('react')
33
- const h = React.createElement
34
-
35
- const NS = 'dsh-zju-lecture-note'
36
- /**
37
- * One id for both left-column seats: `sidebar.panellist` renders the row,
38
- * `main` renders the page the row opens. The sidebar dispatches
39
- * `ctx.layout.selectPanel(id)`, so the two registrations must agree.
40
- */
41
- const PANEL_ID = 'zju-lecture'
42
- const CANDIDATE_NAMESPACES = [
43
- 'include:dsh-zju-lecture-note',
44
- 'dsh-zju-lecture-note',
45
- ]
46
-
47
- const en = {
48
- sectionTitle: 'ZJU classroom lecture notes',
49
- sectionDescription:
50
- 'One pipeline: transcript → notes → PDF. Optional modules register their tools only while switched on, so off means no extra tool, Skill or login surface.',
51
- panelLabel: 'ZJU notes',
52
- panelNote:
53
- 'The same switches also live in Settings → ZJU classroom lecture notes.',
54
- eyebrow: 'ZJU · CLASSROOM',
55
- heroTitle: 'Turn a replay into notes you actually re-read',
56
- heroBody:
57
- 'Transcripts are anonymous first; on 401/403 the plugin retries once with your local login. The PDF is typeset locally.',
58
- pipelineTranscript: 'Transcript',
59
- pipelineNotes: 'Markdown notes',
60
- pipelinePdf: 'Reading PDF',
61
- toolCountLabel: 'tools',
62
- toolsNowPrefix: 'This config registers',
63
- toolsNowSuffix: 'tools',
64
- pdfOn: 'PDF on',
65
- pdfOff: 'PDF off',
66
- presetsTitle: 'Presets',
67
- presetToken: 'Token saver',
68
- presetStudy: 'Study mode',
69
- presetFull: 'Everything',
70
- presetTokenHint: 'PDF only; no optional modules',
71
- presetStudyHint: 'PDF + fill-in notes',
72
- presetFullHint: 'All modules, including slides',
73
- coreTitle: 'Core pipeline',
74
- coreBadge: 'Always on',
75
- coreBody:
76
- 'Transcript fetch, local courseware, note writing, linting and one-click login stay registered. On 401/403, transcript tools read your local login automatically; if none is usable, the agent can open a separate login window with zju_login.',
77
- coreRowTitle: 'Transcript → notes → linting',
78
- coreRowHint: 'Anonymous first; on 401/403, one retry with local login. If that fails, ask the agent to log in: a separate browser window opens, you sign in normally, and it closes by itself.',
79
- outputBody: 'Markdown is the source; the PDF is a typeset reading copy.',
80
- outputTitle: 'Reading output',
81
- outputBadge: 'Recommended',
82
- envTitle: 'Environment',
83
- envBody:
84
- 'Typst, a redistributable CJK font and the Typst packages ship with the plugin or are prepared on first use, so a fresh machine needs no manual setup.',
85
- envBadge: 'Check in-session',
86
- envAutoTitle: 'Install Typst automatically',
87
- envAutoHint:
88
- 'On first typeset, download the official Typst release for this platform (~20 MB, Apache-2.0) into a user cache after verifying its SHA256. Turn off to get install instructions instead.',
89
- envHint:
90
- 'For this machine’s actual Typst version, font and package status, ask the agent to run zju_doctor.',
91
- studyTitle: 'Active recall',
92
- studyBadge: 'Optional',
93
- slidesTitle: 'Projected slides',
94
- slidesBadge: 'Needs login',
95
- loginTitle: 'Login helpers',
96
- loginBadge: 'On demand',
97
- pdfTitle: 'Auto-typeset a PDF',
98
- pdfHint:
99
- 'After each note write, typeset the same Markdown into a print-ready PDF. Typst is prepared automatically (installed on first use if missing); if it still fails, the Markdown is saved.',
100
- studyTitle2: 'Fill-in study notes',
101
- studyBody:
102
- 'A second output for active recall: turn a finished note into a fill-in PDF.',
103
- studyHint:
104
- 'Also registers zju_build_study_notes and loads the scholia-notes Skill. Needs Typst; the normal reading PDF does not.',
105
- slidesTitle2: 'Capture projected slides',
106
- slidesBody:
107
- 'Capture projected screenshots as a visual supplement; needs a ZJU login session.',
108
- slidesHint:
109
- 'Registers zju_fetch_slides. The transcript path is unaffected.',
110
- imagesTitle: 'Reference screenshots in notes',
111
- imagesHint:
112
- 'Only applies while projected-slide capture is on. Adds download time and vision tokens.',
113
- loginTitle2: 'Video URL and credential tools',
114
- loginBody:
115
- 'Signing in is always available: type /zju-lecture-summarizer-login or ask the agent to log in to ZJU Classroom. It opens a separate browser window, never your daily Edge profile, so App-Bound Encryption does not matter; the login is saved securely on this machine (DPAPI on Windows; 0600 on macOS/Linux) (no password).',
116
- loginHint:
117
- 'The switches below only add zju_get_video_url and zju_read_browser_cookie; they never echo credentials. zju_login is a core tool and ignores this switch.',
118
- toolsNowHint:
119
- 'Saved immediately, but loaded when DeepSeek Harness restarts: the running host keeps the tools it started with, and a new session inherits them.',
120
- saveIdle: '',
121
- saveSaving: 'Saving…',
122
- saveDone: 'Saved',
123
- saveFailed: 'Not saved. Try again.',
124
- loading: 'Loading this setting…',
125
- unavailable: 'This setting is not available in the current profile.',
126
- readOnly: 'This deployment stores plugin settings read-only.',
127
- on: 'On',
128
- off: 'Off',
129
- dependency: 'Turn on projected-slide capture first.',
130
- }
131
-
132
- const zh = {
133
- sectionTitle: '浙大智云课堂讲义',
134
- sectionDescription:
135
- '一条链路:字幕 → 讲义 → PDF。可选模块只在打开时注册对应工具;关掉就没有多余工具、Skill 与登录面。',
136
- panelLabel: '智云讲义',
137
- panelNote: '同一份开关也出现在「设置 → 浙大智云课堂讲义」。',
138
- eyebrow: 'ZJU · 智云课堂',
139
- heroTitle: '把一节回放,变成会重读的讲义',
140
- heroBody:
141
- '字幕先匿名;401/403 时自动用本机登录态重试一次。PDF 在本地排版,不额外消耗模型 token。',
142
- pipelineTranscript: '字幕',
143
- pipelineNotes: 'Markdown 讲义',
144
- pipelinePdf: '阅读 PDF',
145
- toolCountLabel: '个工具',
146
- toolsNowPrefix: '当前配置注册',
147
- toolsNowSuffix: '个工具',
148
- pdfOn: 'PDF 开',
149
- pdfOff: 'PDF 关',
150
- presetsTitle: '一键配置',
151
- presetToken: '省 Token',
152
- presetStudy: '复习模式',
153
- presetFull: '全功能',
154
- presetTokenHint: '只出 PDF,不启用可选模块',
155
- presetStudyHint: 'PDF + 填空笔记',
156
- presetFullHint: '全部模块,含投影抓取',
157
- coreTitle: '核心链路',
158
- coreBadge: '始终开启',
159
- coreBody:
160
- '字幕抓取、本地课件、讲义写入、校验与一键登录常驻;401/403 时字幕工具自动读取本机登录态,仍不可用就由 Agent 调用 zju_login 打开独立登录窗口。',
161
- coreRowTitle: '字幕 → 讲义 → 校验',
162
- coreRowHint: '先匿名;401/403 时自动用本机登录态重试一次。仍失败就让 Agent 登录:会弹出一个独立窗口,你正常登录后它自动关闭并安全保存登录态。',
163
- outputBody: 'Markdown 是源文件;PDF 是同一份内容的排版阅读版。',
164
- outputTitle: '阅读输出',
165
- outputBadge: '推荐',
166
- envTitle: '环境与依赖',
167
- envBody:
168
- 'Typst、可再分发的中文字体与 Typst 包都由插件自带或首次使用时自动准备,新机器不需要手动安装。',
169
- envBadge: '会话内可查',
170
- envAutoTitle: '自动安装 Typst',
171
- envAutoHint:
172
- '首次排版时从官方 Release 下载对应平台的 Typst(约 20 MB,Apache-2.0),校验 SHA256 后装进用户缓存。关闭后只给安装命令,不联网。',
173
- envHint:
174
- '想知道这台机器的实际状态(Typst 版本 / 字体 / 包),让 Agent 运行 zju_doctor。',
175
- studyTitle: '主动回忆',
176
- studyBadge: '可选',
177
- slidesTitle: '课堂投影',
178
- slidesBadge: '需登录',
179
- loginTitle: '登录辅助',
180
- loginBadge: '按需',
181
- pdfTitle: '自动排版 PDF 讲义',
182
- pdfHint:
183
- '每次写入讲义后,把同一份 Markdown 排成可打印 PDF。Typst 由插件自动准备(缺失时首次使用自动安装);仍失败也只是跳过 PDF,Markdown 照常保存。',
184
- studyTitle2: '填空式学习笔记',
185
- studyBody: '另一种产出:把已完成的讲义变成可动手填写的复习 PDF。',
186
- studyHint:
187
- '额外注册 zju_build_study_notes 并加载 scholia-notes Skill;需要本机 Typst,普通阅读版 PDF 不需要。',
188
- slidesTitle2: '抓取 PPT 投影截图',
189
- slidesBody: '把课堂投影截图作为讲义的视觉补充;需要浙大登录态。',
190
- slidesHint: '注册 zju_fetch_slides;字幕链路不受影响。',
191
- imagesTitle: '把截图引用进讲义',
192
- imagesHint:
193
- '仅在投影抓取开启时生效;会增加下载时间与视觉 token。',
194
- loginTitle2: '视频直链与登录态工具',
195
- loginBody:
196
- '登录入口始终可用:在对话里输入 /zju-lecture-summarizer-login,或直接说「登录智云课堂」。插件会打开一个独立的浏览器窗口(不碰你日常 Edge,ABE 不影响),你正常登录后窗口自动关闭,登录态安全保存在本机,不保存账号密码。',
197
- loginHint:
198
- '下面的开关只额外注册 zju_get_video_url 与 zju_read_browser_cookie,不回显凭据;zju_login 是核心工具,不受本开关影响。',
199
- toolsNowHint: '保存后立即写回,但插件要完全重启 DeepSeek Harness 才按新配置加载:当前会话和新建会话都沿用启动时的工具集。',
200
- saveIdle: '',
201
- saveSaving: '正在保存…',
202
- saveDone: '已保存',
203
- saveFailed: '未保存,请重试。',
204
- loading: '正在加载该设置…',
205
- unavailable: '当前 profile 未提供该设置。',
206
- readOnly: '本部署的插件设置为只读。',
207
- on: '开',
208
- off: '关',
209
- dependency: '请先打开「抓取 PPT 投影截图」。',
210
- }
211
-
212
- const CSS = [
213
- '.zju-settings-page{display:flex;flex-direction:column;gap:16px;width:100%;max-width:760px;box-sizing:border-box}',
214
- '.zju-hero{position:relative;overflow:hidden;box-sizing:border-box;padding:20px 20px 18px;border:1px solid var(--dsw-alias-border-l1);border-radius:14px;background-color:var(--dsw-alias-bg-layer-1);background-image:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,var(--dsw-alias-bg-layer-1)) 0%,var(--dsw-alias-bg-layer-1) 52%,color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,var(--dsw-alias-bg-layer-1)) 100%)}',
215
- '.zju-eyebrow{font-size:11px;line-height:16px;letter-spacing:.16em;color:var(--dsw-alias-brand-primary);font-weight:600}',
216
- '.zju-hero-title{margin:6px 0 0;font-size:20px;line-height:28px;font-weight:600;color:var(--dsw-alias-label-primary)}',
217
- '.zju-hero-body{margin:6px 0 0;max-width:54em;font-size:12px;line-height:19px;color:var(--dsw-alias-label-secondary)}',
218
- '.zju-hero-top{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}',
219
- '.zju-hero-badges{display:flex;flex-wrap:wrap;gap:6px;justify-content:flex-end;flex:none}',
220
- '.zju-pill{display:inline-flex;align-items:center;height:22px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-2) 82%,transparent);font-size:11px;line-height:20px;color:var(--dsw-alias-label-secondary);white-space:nowrap}',
221
- '.zju-pill.is-on{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,transparent);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 9%,transparent)}',
222
- '.zju-pipeline{display:flex;align-items:center;gap:7px;flex-wrap:wrap;margin-top:14px}',
223
- '.zju-step{display:inline-flex;align-items:center;height:26px;padding:0 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);font-size:12px;line-height:24px;color:var(--dsw-alias-label-primary)}',
224
- '.zju-step.is-off{color:var(--dsw-alias-label-tertiary);border-style:dashed;background:transparent}',
225
- '.zju-arrow{font-size:12px;line-height:1;color:var(--dsw-alias-label-tertiary)}',
226
- '.zju-presets{display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
227
- '.zju-presets-label{font-size:12px;color:var(--dsw-alias-label-secondary);margin-right:2px}',
228
- '.zju-preset{display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;padding:7px 11px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);cursor:pointer;font:inherit;color:var(--dsw-alias-label-primary);text-align:left}',
229
- '.zju-preset:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l2));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,var(--dsw-alias-bg-layer-1))}',
230
- '.zju-preset:disabled{opacity:.5;cursor:default}',
231
- '.zju-preset:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}',
232
- '.zju-preset-name{font-size:12px;line-height:17px;font-weight:500}',
233
- '.zju-preset-hint{font-size:10px;line-height:14px;color:var(--dsw-alias-label-tertiary)}',
234
- '.zju-card{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}',
235
- '.zju-card-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:13px 16px 11px;border-bottom:.5px solid var(--dsw-alias-border-l2)}',
236
- '.zju-card-title{margin:0;font-size:13px;line-height:19px;font-weight:600;color:var(--dsw-alias-label-primary)}',
237
- '.zju-card-body{margin:2px 0 0;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}',
238
- '.zju-badge{flex:none;font-size:10px;line-height:15px;padding:0 6px;border-radius:5px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2)}',
239
- '.zju-badge.is-accent{color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}',
240
- '.zju-row{display:flex;justify-content:space-between;align-items:flex-start;gap:22px;padding:13px 16px;border-bottom:.5px solid var(--dsw-alias-border-l2)}',
241
- '.zju-row:last-child{border-bottom:none}',
242
- '.zju-row.is-child{padding-left:30px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-2) 45%,transparent)}',
243
- '.zju-copy{min-width:0}',
244
- '.zju-row-title{font-size:13px;line-height:19px;color:var(--dsw-alias-label-primary)}',
245
- '.zju-row-hint{margin-top:3px;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary)}',
246
- '.zju-switch{position:relative;flex:none;width:36px;height:20px;padding:0;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-layer-2);cursor:pointer;transition:background-color .15s ease,border-color .15s ease}',
247
- '.zju-switch[aria-checked="true"]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary)}',
248
- '.zju-switch:disabled{opacity:.42;cursor:default}',
249
- '.zju-switch:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}',
250
- '.zju-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-bg-layer-1);box-shadow:0 1px 2px rgba(0,0,0,.18);transition:left .15s ease}',
251
- '.zju-switch[aria-checked="true"] .zju-knob{left:18px}',
252
- '.zju-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;padding:0 2px;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary)}',
253
- '.zju-save[data-state="saved"]{color:var(--dsw-alias-state-success-primary)}',
254
- '.zju-save[data-state="failed"]{color:var(--dsw-alias-state-error-primary)}',
255
- '.zju-note{font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary)}',
256
- '.zju-panel{box-sizing:border-box;height:100%;overflow:auto;display:flex;justify-content:center;align-items:flex-start;padding:0 clamp(16px,3vw,32px) 40px}',
257
- '.zju-panel-inner{box-sizing:border-box;width:100%;max-width:760px;padding-top:calc(20px + var(--dsh-frame-top-clearance,0px))}',
258
- '@media (max-width:560px){.zju-hero-top{flex-direction:column}.zju-hero-badges{justify-content:flex-start}.zju-row{gap:12px}}',
259
- ].join('\n')
260
-
261
- /**
262
- * One settings controller, shared by every switch on the page.
263
- *
264
- * The Host serves configuration forms only for `Config` fields marked
265
- * `.volatile()`. The mirror row is found by its namespace or by any known
266
- * field in its schema, so this page keeps working when the bundle is
267
- * composed under an `include:` entry id.
268
- */
269
- class PipelineSettings {
270
- constructor(ctx) {
271
- this.ctx = ctx
272
- this.listeners = new Set()
273
- this.namespace = null
274
- this.form = null
275
- this.formUnsubscribe = null
276
- this.mirror = ctx.configForms.describe()
277
- this.snapshot = {
278
- status: 'loading',
279
- value: undefined,
280
- writable: false,
281
- revision: undefined,
282
- error: null,
283
- }
284
- this.mirrorUnsubscribe = this.mirror.subscribe(() => this.sync())
285
- void Promise.resolve(this.mirror.ensure()).catch(() => {})
286
- this.sync()
287
- }
288
-
289
- subscribe = (listener) => {
290
- this.listeners.add(listener)
291
- return () => this.listeners.delete(listener)
292
- }
293
-
294
- getSnapshot = () => this.snapshot
295
-
296
- emit() {
297
- for (const listener of [...this.listeners]) listener()
298
- }
299
-
300
- publish(snapshot) {
301
- this.snapshot = snapshot
302
- this.emit()
303
- }
304
-
305
- isOurs(row) {
306
- if (!row || typeof row !== 'object') return false
307
- if (CANDIDATE_NAMESPACES.includes(row.ns)) return true
308
- if (typeof row.ns === 'string' && row.ns.includes('zju-lecture')) return true
309
- const hasField = (value) => value && typeof value === 'object' && 'enableSlides' in value
310
- if (hasField(row.value) || hasField(row.base)) return true
311
- try {
312
- return JSON.stringify(row.schema || '').includes('"enableSlides"')
313
- } catch {
314
- return false
315
- }
316
- }
317
-
318
- sync() {
319
- const view = this.mirror.getSnapshot()?.view
320
- const rows = Array.isArray(view?.namespaces) ? view.namespaces : []
321
- const row = rows.find((candidate) => this.isOurs(candidate))
322
- if (!row) {
323
- this.publish({
324
- status: view === undefined ? 'loading' : 'unavailable',
325
- value: undefined,
326
- writable: false,
327
- revision: undefined,
328
- error: null,
329
- })
330
- return
331
- }
332
- if (row.ns !== this.namespace) {
333
- this.namespace = row.ns
334
- this.form = this.ctx.configForms.get(row.ns)
335
- if (this.formUnsubscribe) this.formUnsubscribe()
336
- this.formUnsubscribe = this.form.subscribe(() => this.publishForm())
337
- }
338
- this.publishForm()
339
- }
340
-
341
- publishForm() {
342
- const form = this.form?.getSnapshot()
343
- this.publish({
344
- status: form?.status || 'unavailable',
345
- value: form?.value || {},
346
- writable: form?.writable === true,
347
- revision: form?.revision,
348
- error: this.snapshot.error || null,
349
- })
350
- }
351
-
352
- async #writeOne(field, value) {
353
- if (!this.form) return false
354
- // `set` is the convenience path used by this plugin since 1.5.1;
355
- // `mutate` is the lower-level scope API (revision-fenced batch). Try
356
- // the convenience path first, fall back to one path-addressed op.
357
- if (typeof this.form.set === 'function') {
358
- return (await this.form.set(field, value)) !== false
359
- }
360
- if (typeof this.form.mutate === 'function') {
361
- const current = this.form.getSnapshot()
362
- const accepted = await this.form.mutate(
363
- [{ op: 'set', path: field, value }],
364
- current?.revision,
365
- )
366
- return accepted !== false
367
- }
368
- return false
369
- }
370
-
371
- async setField(field, value) {
372
- try {
373
- const accepted = await this.#writeOne(field, value)
374
- this.publish({ ...this.snapshot, error: accepted ? null : 'saveFailed' })
375
- return accepted
376
- } catch {
377
- this.publish({ ...this.snapshot, error: 'saveFailed' })
378
- return false
379
- }
380
- }
381
-
382
- /** Write several switches as one user action (preset button). */
383
- async setFields(entries) {
384
- // A batch is one revision-fenced write: the Host applies every field
385
- // or none. Sequential writes could race a plugin reload between them.
386
- if (this.form && typeof this.form.mutate === 'function') {
387
- try {
388
- const current = this.form.getSnapshot()
389
- const ops = entries.map(([field, value]) => ({ op: 'set', path: field, value }))
390
- const accepted = await this.form.mutate(ops, current?.revision)
391
- if (accepted !== false) {
392
- this.publish({ ...this.snapshot, error: null })
393
- return true
394
- }
395
- } catch {
396
- /* fall through to the per-field path */
397
- }
398
- }
399
- for (const [field, value] of entries) {
400
- try {
401
- const accepted = await this.#writeOne(field, value)
402
- if (!accepted) {
403
- this.publish({ ...this.snapshot, error: 'saveFailed' })
404
- return false
405
- }
406
- } catch {
407
- this.publish({ ...this.snapshot, error: 'saveFailed' })
408
- return false
409
- }
410
- }
411
- this.publish({ ...this.snapshot, error: null })
412
- return true
413
- }
414
-
415
- dispose() {
416
- this.mirrorUnsubscribe?.()
417
- this.formUnsubscribe?.()
418
- this.listeners.clear()
419
- }
420
- }
421
-
422
- function Toggle({ checked, disabled, label, onChange }) {
423
- return h('button', {
424
- type: 'button',
425
- role: 'switch',
426
- 'aria-checked': checked ? 'true' : 'false',
427
- 'aria-label': label,
428
- disabled,
429
- className: 'zju-switch',
430
- onClick: () => {
431
- if (!disabled) onChange(!checked)
432
- },
433
- }, h('span', { className: 'zju-knob', 'aria-hidden': 'true' }))
434
- }
435
-
436
- function useSettingsSnapshot(settings) {
437
- const [snapshot, setSnapshot] = React.useState(settings.getSnapshot())
438
- React.useEffect(() => {
439
- setSnapshot(settings.getSnapshot())
440
- return settings.subscribe(() => setSnapshot(settings.getSnapshot()))
441
- }, [settings])
442
- return snapshot
443
- }
444
-
445
- function useSaveState() {
446
- const [state, setState] = React.useState('idle')
447
- const run = async (action) => {
448
- setState('saving')
449
- const ok = await action()
450
- setState(ok ? 'saved' : 'failed')
451
- return ok
452
- }
453
- return [state, run]
454
- }
455
-
456
- function Row({ t, title, hint, checked, disabled, onChange }) {
457
- return h('div', { className: 'zju-row' },
458
- h('div', { className: 'zju-copy' },
459
- h('div', { className: 'zju-row-title' }, t(title)),
460
- h('div', { className: 'zju-row-hint' }, t(hint)),
461
- ),
462
- h(Toggle, { checked, disabled, label: t(title), onChange }),
463
- )
464
- }
465
-
466
- function Card({ title, body, badge, accent, children }) {
467
- return h('section', { className: 'zju-card' },
468
- h('header', { className: 'zju-card-head' },
469
- h('div', null,
470
- h('h3', { className: 'zju-card-title' }, title),
471
- body ? h('p', { className: 'zju-card-body' }, body) : null,
472
- ),
473
- badge ? h('span', { className: `zju-badge${accent ? ' is-accent' : ''}` }, badge) : null,
474
- ),
475
- children,
476
- )
477
- }
478
-
479
- function PipelineSection({ t, settings, asPage }) {
480
- const snapshot = useSettingsSnapshot(settings)
481
- const [saveState, runSave] = useSaveState()
482
- const value = snapshot.value || {}
483
- const enableSlides = value.enableSlides === true
484
- const renderPdf = value.renderPdf !== false
485
- const typstAutoInstall = value.typstAutoInstall !== false
486
- const enableStudyNotes = value.enableStudyNotes === true
487
- const enableLoginTools = value.enableLoginTools === true
488
- const embedSlideImages = enableSlides && value.embedSlideImages === true
489
- const ready = snapshot.status === 'ready'
490
- const disabled = !ready || !snapshot.writable || saveState === 'saving'
491
- const toolCount = 7
492
- + (enableStudyNotes ? 1 : 0)
493
- + (enableSlides ? 1 : 0)
494
- + (enableLoginTools ? 2 : 0)
495
- const note = !ready && snapshot.status !== 'unavailable'
496
- ? t('loading')
497
- : snapshot.status === 'unavailable'
498
- ? t('unavailable')
499
- : ready && !snapshot.writable
500
- ? t('readOnly')
501
- : null
502
- const saveLabel = saveState === 'saving'
503
- ? t('saveSaving')
504
- : saveState === 'saved'
505
- ? t('saveDone')
506
- : saveState === 'failed'
507
- ? t('saveFailed')
508
- : snapshot.error
509
- ? t('saveFailed')
510
- : ''
511
-
512
- const update = (field, next) => runSave(() => settings.setField(field, next))
513
-
514
- const applyPreset = (preset) => runSave(async () => {
515
- const sets = preset === 'token'
516
- ? [['renderPdf', true], ['enableStudyNotes', false], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
517
- : preset === 'study'
518
- ? [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
519
- : [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', true], ['enableLoginTools', true]]
520
- return settings.setFields(sets)
521
- })
522
-
523
- return h('div', { className: 'zju-settings-page', 'data-zju-settings': 'pipeline' },
524
- h('style', { 'data-plugin': '@plugin/dsh-zju-lecture-note' }, CSS),
525
- h('header', { className: 'zju-hero' },
526
- h('div', { className: 'zju-hero-top' },
527
- h('div', null,
528
- h('div', { className: 'zju-eyebrow' }, t('eyebrow')),
529
- h(asPage ? 'h1' : 'h2', { className: 'zju-hero-title' }, t('heroTitle')),
530
- h('p', { className: 'zju-hero-body' }, t('heroBody')),
531
- ),
532
- h('div', { className: 'zju-hero-badges' },
533
- h('span', { className: 'zju-pill' }, `${toolCount} ${t('toolCountLabel')}`),
534
- h('span', { className: `zju-pill${renderPdf ? ' is-on' : ''}` }, renderPdf ? t('pdfOn') : t('pdfOff')),
535
- ),
536
- ),
537
- h('div', { className: 'zju-pipeline', 'aria-hidden': 'true' },
538
- h('span', { className: 'zju-step' }, t('pipelineTranscript')),
539
- h('span', { className: 'zju-arrow' }, '→'),
540
- h('span', { className: 'zju-step' }, t('pipelineNotes')),
541
- h('span', { className: 'zju-arrow' }, '→'),
542
- h('span', { className: `zju-step${renderPdf ? '' : ' is-off'}` }, t('pipelinePdf')),
543
- ),
544
- ),
545
- note ? h('div', { className: 'zju-note', role: 'status' }, note) : null,
546
- h('div', { className: 'zju-presets' },
547
- h('span', { className: 'zju-presets-label' }, t('presetsTitle')),
548
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('token') },
549
- h('span', { className: 'zju-preset-name' }, t('presetToken')),
550
- h('span', { className: 'zju-preset-hint' }, t('presetTokenHint')),
551
- ),
552
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('study') },
553
- h('span', { className: 'zju-preset-name' }, t('presetStudy')),
554
- h('span', { className: 'zju-preset-hint' }, t('presetStudyHint')),
555
- ),
556
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('full') },
557
- h('span', { className: 'zju-preset-name' }, t('presetFull')),
558
- h('span', { className: 'zju-preset-hint' }, t('presetFullHint')),
559
- ),
560
- ),
561
- h(Card, {
562
- title: t('coreTitle'),
563
- body: t('coreBody'),
564
- badge: t('coreBadge'),
565
- },
566
- h(Row, {
567
- t,
568
- title: 'coreRowTitle',
569
- hint: 'coreRowHint',
570
- checked: true,
571
- disabled: true,
572
- onChange: () => {},
573
- }),
574
- ),
575
- h(Card, {
576
- title: t('outputTitle'),
577
- body: t('outputBody'),
578
- badge: t('outputBadge'),
579
- accent: true,
580
- },
581
- h(Row, {
582
- t,
583
- title: 'pdfTitle',
584
- hint: 'pdfHint',
585
- checked: renderPdf,
586
- disabled,
587
- onChange: (next) => update('renderPdf', next),
588
- }),
589
- ),
590
- h(Card, {
591
- title: t('envTitle'),
592
- body: t('envBody'),
593
- badge: t('envBadge'),
594
- },
595
- h(Row, {
596
- t,
597
- title: 'envAutoTitle',
598
- hint: 'envAutoHint',
599
- checked: typstAutoInstall,
600
- disabled,
601
- onChange: (next) => update('typstAutoInstall', next),
602
- }),
603
- h('div', { className: 'zju-row is-child' },
604
- h('div', { className: 'zju-copy' },
605
- h('div', { className: 'zju-row-hint' }, t('envHint')),
606
- ),
607
- ),
608
- ),
609
- h(Card, {
610
- title: t('studyTitle'),
611
- body: t('studyBody'),
612
- badge: t('studyBadge'),
613
- },
614
- h(Row, {
615
- t,
616
- title: 'studyTitle2',
617
- hint: 'studyHint',
618
- checked: enableStudyNotes,
619
- disabled,
620
- onChange: (next) => update('enableStudyNotes', next),
621
- }),
622
- ),
623
- h(Card, {
624
- title: t('slidesTitle'),
625
- body: t('slidesBody'),
626
- badge: t('slidesBadge'),
627
- },
628
- h(Row, {
629
- t,
630
- title: 'slidesTitle2',
631
- hint: 'slidesHint',
632
- checked: enableSlides,
633
- disabled,
634
- onChange: (next) => update('enableSlides', next),
635
- }),
636
- h('div', { className: 'zju-row is-child' },
637
- h('div', { className: 'zju-copy' },
638
- h('div', { className: 'zju-row-title' }, t('imagesTitle')),
639
- h('div', { className: 'zju-row-hint' }, enableSlides ? t('imagesHint') : t('dependency')),
640
- ),
641
- h(Toggle, {
642
- checked: embedSlideImages,
643
- disabled: disabled || !enableSlides,
644
- label: t('imagesTitle'),
645
- onChange: (next) => update('embedSlideImages', next),
646
- }),
647
- ),
648
- ),
649
- h(Card, {
650
- title: t('loginTitle'),
651
- body: t('loginBody'),
652
- badge: t('loginBadge'),
653
- },
654
- h(Row, {
655
- t,
656
- title: 'loginTitle2',
657
- hint: 'loginHint',
658
- checked: enableLoginTools,
659
- disabled,
660
- onChange: (next) => update('enableLoginTools', next),
661
- }),
662
- ),
663
- h('footer', { className: 'zju-foot' },
664
- h('span', { className: 'zju-note' }, `${t('toolsNowPrefix')} ${toolCount} ${t('toolsNowSuffix')} · ${t('toolsNowHint')}`),
665
- h('span', {
666
- className: 'zju-save',
667
- 'data-state': saveState,
668
- 'aria-live': 'polite',
669
- }, saveLabel),
670
- ),
671
- asPage ? h('p', { className: 'zju-note' }, t('panelNote')) : null,
672
- )
673
- }
674
-
675
- /**
676
- * The left-column row's glyph. A `sidebar.panellist` entry draws its own
677
- * icon — the slot hands it `size` and `active`, no icon field exists — and
678
- * the row's own colour must come through, hence `currentColor`.
679
- */
680
- function PanelIcon({ size = 18 }) {
681
- return h('svg', {
682
- width: size,
683
- height: size,
684
- viewBox: '0 0 20 20',
685
- fill: 'none',
686
- stroke: 'currentColor',
687
- strokeWidth: 1.5,
688
- strokeLinecap: 'round',
689
- strokeLinejoin: 'round',
690
- 'aria-hidden': 'true',
691
- focusable: 'false',
692
- },
693
- h('path', { d: 'M4.6 3.4h6.1l4.7 4.7v7.5a1 1 0 0 1-1 1H4.6a1 1 0 0 1-1-1V4.4a1 1 0 0 1 1-1Z' }),
694
- h('path', { d: 'M10.6 3.5v4.7h4.7' }),
695
- h('path', { d: 'M6.7 11.2h4.4' }),
696
- h('path', { d: 'M6.7 13.7h6.2' }),
697
- )
698
- }
699
-
700
- /**
701
- * The page behind the left-column row.
702
- *
703
- * A `main` occupant is a full-height centre column, so it owns the page
704
- * padding the shipped entry pages use: `--dsh-frame-top-clearance` keeps the
705
- * first row below the window caption on Windows and under the traffic lights
706
- * on macOS. The content itself is the settings section, unchanged.
707
- */
708
- function SettingsPanelPage(props) {
709
- return h('div', { className: 'zju-panel', 'data-zju-panel': PANEL_ID },
710
- h('div', { className: 'zju-panel-inner' },
711
- h(PipelineSection, { ...props, asPage: true }),
712
- ),
713
- )
714
- }
715
-
716
- function apply(ctx) {
717
- ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'zju-lecture: settings dictionaries')
718
- const t = ctx.locale.bind(NS)
719
- const settings = new PipelineSettings(ctx)
720
- ctx.effect(() => () => settings.dispose(), 'zju-lecture: settings form')
721
- ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({
722
- name: 'settings.section',
723
- id: PANEL_ID,
724
- order: 25,
725
- label: () => t('sectionTitle'),
726
- locale: NS,
727
- inject: () => ({ settings }),
728
- }, PipelineSection)), 'zju-lecture: settings section')
729
- // The left column: one `sidebar.panellist` row and the `main` page under
730
- // the same id. Registered from the inner callback so the row and its page
731
- // appear together or not at all, exactly as the shipped panels do.
732
- ctx.effect(() => ctx.slots.inject('main', () => ctx.slots.inject('sidebar.panellist', () => {
733
- const stopPage = ctx.slots.register({
734
- name: 'main',
735
- key: PANEL_ID,
736
- locale: NS,
737
- inject: () => ({ settings }),
738
- }, SettingsPanelPage)
739
- const stopRow = ctx.slots.register({
740
- name: 'sidebar.panellist',
741
- id: PANEL_ID,
742
- order: 30,
743
- label: () => t('panelLabel'),
744
- locale: NS,
745
- }, PanelIcon)
746
- return () => {
747
- stopRow()
748
- stopPage()
749
- }
750
- })), 'zju-lecture: sidebar entry')
751
- }
752
-
753
- return {
754
- inject: ['slots', 'locale', 'configForms'],
755
- apply,
756
- }
757
- },
758
- })
1
+ /**
2
+ * Browser half of dsh-zju-lecture-note.
3
+ *
4
+ * The same page is mounted twice, from two seats the shell owns:
5
+ *
6
+ * - `settings.section` — 设置 → 浙大智云课堂讲义 (the deep link), id `zju-lecture`;
7
+ * - `sidebar.panellist` + `main` — the left-column row 智云讲义, whose click
8
+ * selects the global panel registered under the same id.
9
+ *
10
+ * Both render one component over one `PipelineSettings` controller, so a switch
11
+ * moved in either place shows up in the other without a reload.
12
+ *
13
+ * The page is built around the actual pipeline — 字幕 → 讲义 → PDF — and every
14
+ * optional module is a separate switch with its own dependency and cost, so a
15
+ * user can see what they are turning on before they turn it on.
16
+ *
17
+ * - `renderPdf` auto-typeset the written note into a reading PDF
18
+ * - `enableStudyNotes` fill-in study notes (+ scholia-notes Skill)
19
+ * - `enableSlides` projected-slide capture
20
+ * - `embedSlideImages` reference those screenshots in the note
21
+ * - `enableLoginTools` video URL / Edge-cookie helpers
22
+ * - `typstAutoInstall` install Typst on first use
23
+ * - `typstPath` / `typstMirror` pin the executable or a download mirror
24
+ * - `python` / `timeoutMs` / `registerSkill` advanced interpreter controls
25
+ *
26
+ * Volatile values are live: the plugin re-syncs tools, Skills, the prompt and
27
+ * its Python children when one is saved, so the agent reads the new setting on
28
+ * its next turn. The page therefore does not ask the user to restart dsh for a
29
+ * switch — only a plugin install/update still needs a restart.
30
+ *
31
+ * The Host exposes only `Config` fields marked `.volatile()`. Writes go
32
+ * through the shared `configForms` scope, so they carry the current revision
33
+ * and are refused rather than clobbering a newer value. Plain JavaScript,
34
+ * React from the host module table, no build step.
35
+ */
36
+
37
+ window.__ModuleLoader__.load({
38
+ id: 'dsh-zju-lecture-note',
39
+ factory(require) {
40
+ const React = require('react')
41
+ const h = React.createElement
42
+
43
+ const NS = 'dsh-zju-lecture-note'
44
+ /**
45
+ * One id for both left-column seats: `sidebar.panellist` renders the row,
46
+ * `main` renders the page the row opens. The sidebar dispatches
47
+ * `ctx.layout.selectPanel(id)`, so the two registrations must agree.
48
+ */
49
+ const PANEL_ID = 'zju-lecture'
50
+ const CANDIDATE_NAMESPACES = [
51
+ 'include:dsh-zju-lecture-note',
52
+ 'dsh-zju-lecture-note',
53
+ ]
54
+
55
+ const en = {
56
+ sectionTitle: 'ZJU classroom lecture notes',
57
+ panelLabel: 'ZJU notes',
58
+ panelNote: 'Also available in Settings → ZJU classroom lecture notes.',
59
+ eyebrow: 'ZJU · CLASSROOM',
60
+ heroTitle: 'Turn a replay into review-ready notes',
61
+ heroBody: 'Transcripts are anonymous first; 401/403 retries once with the local login. PDF typesetting runs locally.',
62
+ pipelineTranscript: 'Transcript',
63
+ pipelineNotes: 'Markdown notes',
64
+ pipelinePdf: 'Reading PDF',
65
+ toolCountLabel: 'tools',
66
+ toolsNowPrefix: 'This config registers',
67
+ toolsNowSuffix: 'tools',
68
+ pdfOn: 'PDF on',
69
+ pdfOff: 'PDF off',
70
+ presetsTitle: 'Presets',
71
+ presetToken: 'Token saver',
72
+ presetStudy: 'Study mode',
73
+ presetFull: 'Everything',
74
+ presetTokenHint: 'PDF only',
75
+ presetStudyHint: 'PDF + fill-in notes',
76
+ presetFullHint: 'All modules',
77
+ coreTitle: 'Core pipeline',
78
+ coreBadge: 'Always on',
79
+ coreRowTitle: 'Transcript → notes → linting',
80
+ coreRowHint: 'No configuration required.',
81
+ outputTitle: 'Reading output',
82
+ outputBadge: 'Recommended',
83
+ outputBody: 'Markdown is the source; the PDF is the reading copy.',
84
+ pdfTitle: 'Auto-typeset PDF',
85
+ pdfHint: 'After each note write, typeset the same Markdown into a print-ready PDF. Failure leaves the Markdown intact.',
86
+ envTitle: 'Environment',
87
+ envBadge: 'Session check',
88
+ envBody: 'Typst, the CJK fonts and the Typst packages are prepared automatically.',
89
+ envAutoTitle: 'Install Typst automatically',
90
+ envAutoHint: 'Downloads the official release on first use (~20 MB) after SHA256 verification. Off: print install instructions instead.',
91
+ envPathTitle: 'Typst executable',
92
+ envPathHint: 'Leave empty to auto-detect; set an absolute path to pin a version.',
93
+ envPathPlaceholder: 'Empty = auto-detect',
94
+ envMirrorTitle: 'Typst download mirror',
95
+ envMirrorHint: 'Prefix for the GitHub release URL, e.g. https://ghfast.top/.',
96
+ envMirrorPlaceholder: 'https://ghfast.top/',
97
+ envHint: 'Run zju_doctor for actual versions and paths.',
98
+ studyTitle: 'Active recall',
99
+ studyBadge: 'Optional',
100
+ studyTitle2: 'Fill-in study notes',
101
+ studyHint: 'Adds zju_build_study_notes and the scholia-notes Skill.',
102
+ slidesTitle: 'Classroom projection',
103
+ slidesBadge: 'Needs login',
104
+ slidesTitle2: 'Capture projected slides',
105
+ slidesHint: 'Registers zju_fetch_slides. The transcript path is unaffected.',
106
+ imagesTitle: 'Reference screenshots in notes',
107
+ imagesHint: 'Only when capture is on; adds download time and vision tokens.',
108
+ dependency: 'Turn on capture first.',
109
+ loginTitle: 'Login helpers',
110
+ loginBadge: 'On demand',
111
+ loginBody: 'Sign-in is always available: run /zju-lecture-summarizer-login or ask the agent. A separate browser window is used; only the session is stored locally.',
112
+ loginTitle2: 'Video URL and credential tools',
113
+ loginHint: 'Adds zju_get_video_url and zju_read_browser_cookie. zju_login is unaffected.',
114
+ advancedTitle: 'Advanced',
115
+ advancedBadge: 'Rarely needed',
116
+ pythonTitle: 'Python interpreter',
117
+ pythonHint: 'Empty tries the bundled Python, then py -3, python and python3.',
118
+ pythonPlaceholder: 'Empty = auto-detect',
119
+ timeoutTitle: 'Tool timeout (ms)',
120
+ timeoutHint: 'Default 120000. PDF tools use at least 300000; downloads and login at least 600000.',
121
+ registerSkillTitle: 'Register bundled Skills',
122
+ registerSkillHint: 'Off hides the course workflow; tools stay available.',
123
+ toolsNowHint: 'Saved live; no restart required.',
124
+ saveIdle: '',
125
+ saveSaving: 'Saving…',
126
+ saveDone: 'Saved',
127
+ saveFailed: 'Not saved. Try again.',
128
+ loading: 'Loading this setting…',
129
+ unavailable: 'This setting is not available in the current profile.',
130
+ readOnly: 'This deployment stores plugin settings read-only.',
131
+ }
132
+
133
+ const zh = {
134
+ sectionTitle: '浙大智云课堂讲义',
135
+ panelLabel: '智云讲义',
136
+ panelNote: '也可在「设置 → 浙大智云课堂讲义」中打开。',
137
+ eyebrow: 'ZJU · 智云课堂',
138
+ heroTitle: '把课程回放整理成可复习的讲义',
139
+ heroBody: '字幕先匿名;401/403 时用本机登录态重试一次。PDF 在本地排版。',
140
+ pipelineTranscript: '字幕',
141
+ pipelineNotes: 'Markdown 讲义',
142
+ pipelinePdf: '阅读 PDF',
143
+ toolCountLabel: '个工具',
144
+ toolsNowPrefix: '当前配置注册',
145
+ toolsNowSuffix: '个工具',
146
+ pdfOn: 'PDF 开',
147
+ pdfOff: 'PDF 关',
148
+ presetsTitle: '一键配置',
149
+ presetToken: '省 Token',
150
+ presetStudy: '复习模式',
151
+ presetFull: '全功能',
152
+ presetTokenHint: '仅 PDF',
153
+ presetStudyHint: 'PDF + 填空笔记',
154
+ presetFullHint: '全部模块',
155
+ coreTitle: '核心链路',
156
+ coreBadge: '始终开启',
157
+ coreRowTitle: '字幕 → 讲义 → 校验',
158
+ coreRowHint: '无需配置。',
159
+ outputTitle: '阅读输出',
160
+ outputBadge: '推荐',
161
+ outputBody: 'Markdown 是源文件,PDF 是阅读版。',
162
+ pdfTitle: '自动排版 PDF',
163
+ pdfHint: '写入讲义后生成同名 PDF;失败不影响 Markdown。',
164
+ envTitle: '环境',
165
+ envBadge: '会话内可查',
166
+ envBody: 'Typst、中文字体与 Typst 包自动准备。',
167
+ envAutoTitle: '自动安装 Typst',
168
+ envAutoHint: '首次使用时下载官方版本(约 20 MB)并校验 SHA256;关闭后只提示安装命令。',
169
+ envPathTitle: 'Typst 可执行文件',
170
+ envPathHint: '留空自动查找;填写绝对路径可固定版本。',
171
+ envPathPlaceholder: '留空 = 自动查找',
172
+ envMirrorTitle: 'Typst 下载镜像',
173
+ envMirrorHint: 'GitHub Release 前缀,例如 https://ghfast.top/。',
174
+ envMirrorPlaceholder: 'https://ghfast.top/',
175
+ envHint: '运行 zju_doctor 查看实际版本与路径。',
176
+ studyTitle: '主动回忆',
177
+ studyBadge: '可选',
178
+ studyTitle2: '填空式学习笔记',
179
+ studyHint: '额外注册 zju_build_study_notes 与 scholia-notes Skill。',
180
+ slidesTitle: '课堂投影',
181
+ slidesBadge: '需登录',
182
+ slidesTitle2: '抓取投影截图',
183
+ slidesHint: '注册 zju_fetch_slides;字幕链路不受影响。',
184
+ imagesTitle: '把截图引用进讲义',
185
+ imagesHint: '仅在投影抓取开启时生效;增加下载时间与视觉 token。',
186
+ dependency: '请先开启投影抓取。',
187
+ loginTitle: '登录辅助',
188
+ loginBadge: '按需',
189
+ loginBody: '登录入口始终可用:输入 /zju-lecture-summarizer-login 或让 Agent 登录。使用独立浏览器窗口,只在本机保存登录态。',
190
+ loginTitle2: '视频直链与登录态工具',
191
+ loginHint: '仅额外注册 zju_get_video_url 与 zju_read_browser_cookie;zju_login 不受影响。',
192
+ advancedTitle: '高级',
193
+ advancedBadge: '按需调整',
194
+ pythonTitle: 'Python 解释器',
195
+ pythonHint: '留空依次尝试自带 Python、py -3、python、python3。',
196
+ pythonPlaceholder: '留空 = 自动查找',
197
+ timeoutTitle: '工具超时(毫秒)',
198
+ timeoutHint: '默认 120000;PDF 工具至少 300000,下载与登录至少 600000。',
199
+ registerSkillTitle: '注册随包 Skill',
200
+ registerSkillHint: '关闭后不加载课程工作流;工具仍可用。',
201
+ toolsNowHint: '保存后立即同步,无需重启。',
202
+ saveIdle: '',
203
+ saveSaving: '正在保存…',
204
+ saveDone: '已保存',
205
+ saveFailed: '未保存,请重试。',
206
+ loading: '正在加载该设置…',
207
+ unavailable: '当前 profile 未提供该设置。',
208
+ readOnly: '本部署的插件设置为只读。',
209
+ }
210
+
211
+ const CSS = [
212
+ '.zju-settings-page{display:flex;flex-direction:column;gap:14px;width:100%;max-width:760px;box-sizing:border-box}',
213
+ '.zju-hero{position:relative;overflow:hidden;box-sizing:border-box;padding:20px 20px 18px;border:1px solid var(--dsw-alias-border-l1);border-radius:14px;background-color:var(--dsw-alias-bg-layer-1);background-image:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,var(--dsw-alias-bg-layer-1)) 0%,var(--dsw-alias-bg-layer-1) 52%,color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,var(--dsw-alias-bg-layer-1)) 100%)}',
214
+ '.zju-eyebrow{font-size:11px;line-height:16px;letter-spacing:.16em;color:var(--dsw-alias-brand-primary);font-weight:600}',
215
+ '.zju-hero-title{margin:6px 0 0;font-size:20px;line-height:28px;font-weight:600;color:var(--dsw-alias-label-primary)}',
216
+ '.zju-hero-body{margin:6px 0 0;max-width:54em;font-size:12px;line-height:19px;color:var(--dsw-alias-label-secondary)}',
217
+ '.zju-hero-top{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}',
218
+ '.zju-hero-badges{display:flex;flex-wrap:wrap;gap:6px;justify-content:flex-end;flex:none}',
219
+ '.zju-pill{display:inline-flex;align-items:center;height:22px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:transparent;font-size:11px;line-height:20px;color:var(--dsw-alias-label-secondary);white-space:nowrap}',
220
+ '.zju-pill.is-on{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,transparent);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 8%,transparent)}',
221
+ '.zju-pipeline{display:flex;align-items:center;gap:7px;flex-wrap:wrap;margin-top:12px}',
222
+ '.zju-step{display:inline-flex;align-items:center;height:26px;padding:0 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:transparent;font-size:12px;line-height:24px;color:var(--dsw-alias-label-primary)}',
223
+ '.zju-step.is-off{color:var(--dsw-alias-label-tertiary);border-style:dashed;background:transparent}',
224
+ '.zju-arrow{font-size:12px;line-height:1;color:var(--dsw-alias-label-tertiary)}',
225
+ '.zju-presets{display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
226
+ '.zju-presets-label{font-size:12px;color:var(--dsw-alias-label-secondary);margin-right:2px}',
227
+ '.zju-preset{display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;padding:6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;cursor:pointer;font:inherit;color:var(--dsw-alias-label-primary);text-align:left}',
228
+ '.zju-preset:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l2));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,transparent)}',
229
+ '.zju-preset:disabled{opacity:.5;cursor:default}',
230
+ '.zju-preset:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}',
231
+ '.zju-preset-name{font-size:12px;line-height:17px;font-weight:500}',
232
+ '.zju-preset-hint{font-size:10px;line-height:14px;color:var(--dsw-alias-label-tertiary)}',
233
+ '.zju-groups{display:flex;flex-direction:column;border-top:1px solid color-mix(in srgb,var(--dsw-alias-label-tertiary) 26%,transparent)}',
234
+ '.zju-group{padding:16px 0 12px}',
235
+ '.zju-group + .zju-group{border-top:1px solid color-mix(in srgb,var(--dsw-alias-label-tertiary) 26%,transparent)}',
236
+ '.zju-group-head{display:flex;align-items:center;justify-content:space-between;gap:10px}',
237
+ '.zju-group-title{margin:0;font-size:13px;line-height:19px;font-weight:600;color:var(--dsw-alias-label-primary)}',
238
+ '.zju-group-body{margin:3px 0 0;font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary)}',
239
+ '.zju-group-rows{padding-left:20px;padding-top:2px}',
240
+ '.zju-badge{flex:none;font-size:10px;line-height:15px;padding:0 6px;border-radius:5px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2)}',
241
+ '.zju-row{display:flex;justify-content:space-between;align-items:flex-start;gap:22px;padding:10px 0 0}',
242
+ '.zju-row.is-child{padding-left:20px}',
243
+ '.zju-copy{min-width:0}',
244
+ '.zju-row-title{font-size:13px;line-height:19px;color:var(--dsw-alias-label-primary)}',
245
+ '.zju-row-hint{margin-top:3px;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary)}',
246
+ '.zju-field{flex:none;display:flex;align-items:center;gap:6px}',
247
+ '.zju-input{box-sizing:border-box;width:228px;height:30px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px}',
248
+ '.zju-input::placeholder{color:var(--dsw-alias-label-tertiary)}',
249
+ '.zju-input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}',
250
+ '.zju-input:disabled{opacity:.45;cursor:default}',
251
+ '@media (max-width:560px){.zju-input{width:100%}.zju-field{width:100%}}',
252
+ '.zju-switch{position:relative;flex:none;width:36px;height:20px;padding:0;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-layer-2);cursor:pointer;transition:background-color .15s ease,border-color .15s ease}',
253
+ '.zju-switch[aria-checked="true"]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary)}',
254
+ '.zju-switch:disabled{opacity:.42;cursor:default}',
255
+ '.zju-switch:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}',
256
+ '.zju-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-bg-layer-1);box-shadow:0 1px 2px rgba(0,0,0,.18);transition:left .15s ease}',
257
+ '.zju-switch[aria-checked="true"] .zju-knob{left:18px}',
258
+ '.zju-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;padding:0 2px;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary)}',
259
+ '.zju-save[data-state="saved"]{color:var(--dsw-alias-state-success-primary)}',
260
+ '.zju-save[data-state="failed"]{color:var(--dsw-alias-state-error-primary)}',
261
+ '.zju-note{font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary)}',
262
+ '.zju-panel{box-sizing:border-box;height:100%;overflow:auto;display:flex;justify-content:center;align-items:flex-start;padding:0 clamp(16px,3vw,32px) 40px}',
263
+ '.zju-panel-inner{box-sizing:border-box;width:100%;max-width:760px;padding-top:calc(20px + var(--dsh-frame-top-clearance,0px))}',
264
+ '@media (max-width:560px){.zju-hero-top{flex-direction:column}.zju-hero-badges{justify-content:flex-start}.zju-row{gap:12px}}',
265
+ ].join('\n')
266
+
267
+ /**
268
+ * One settings controller, shared by every switch on the page.
269
+ *
270
+ * The Host serves configuration forms only for `Config` fields marked
271
+ * `.volatile()`. The mirror row is found by its namespace or by any known
272
+ * field in its schema, so this page keeps working when the bundle is
273
+ * composed under an `include:` entry id.
274
+ */
275
+ class PipelineSettings {
276
+ constructor(ctx) {
277
+ this.ctx = ctx
278
+ this.listeners = new Set()
279
+ this.namespace = null
280
+ this.form = null
281
+ this.formUnsubscribe = null
282
+ this.mirror = ctx.configForms.describe()
283
+ this.snapshot = {
284
+ status: 'loading',
285
+ value: undefined,
286
+ writable: false,
287
+ revision: undefined,
288
+ error: null,
289
+ }
290
+ this.mirrorUnsubscribe = this.mirror.subscribe(() => this.sync())
291
+ void Promise.resolve(this.mirror.ensure()).catch(() => {})
292
+ this.sync()
293
+ }
294
+
295
+ subscribe = (listener) => {
296
+ this.listeners.add(listener)
297
+ return () => this.listeners.delete(listener)
298
+ }
299
+
300
+ getSnapshot = () => this.snapshot
301
+
302
+ emit() {
303
+ for (const listener of [...this.listeners]) listener()
304
+ }
305
+
306
+ publish(snapshot) {
307
+ this.snapshot = snapshot
308
+ this.emit()
309
+ }
310
+
311
+ isOurs(row) {
312
+ if (!row || typeof row !== 'object') return false
313
+ if (CANDIDATE_NAMESPACES.includes(row.ns)) return true
314
+ if (typeof row.ns === 'string' && row.ns.includes('zju-lecture')) return true
315
+ const hasField = (value) => value && typeof value === 'object' && 'enableSlides' in value
316
+ if (hasField(row.value) || hasField(row.base)) return true
317
+ try {
318
+ return JSON.stringify(row.schema || '').includes('"enableSlides"')
319
+ } catch {
320
+ return false
321
+ }
322
+ }
323
+
324
+ sync() {
325
+ const view = this.mirror.getSnapshot()?.view
326
+ const rows = Array.isArray(view?.namespaces) ? view.namespaces : []
327
+ const row = rows.find((candidate) => this.isOurs(candidate))
328
+ if (!row) {
329
+ this.publish({
330
+ status: view === undefined ? 'loading' : 'unavailable',
331
+ value: undefined,
332
+ writable: false,
333
+ revision: undefined,
334
+ error: null,
335
+ })
336
+ return
337
+ }
338
+ if (row.ns !== this.namespace) {
339
+ this.namespace = row.ns
340
+ this.form = this.ctx.configForms.get(row.ns)
341
+ if (this.formUnsubscribe) this.formUnsubscribe()
342
+ this.formUnsubscribe = this.form.subscribe(() => this.publishForm())
343
+ }
344
+ this.publishForm()
345
+ }
346
+
347
+ publishForm() {
348
+ const form = this.form?.getSnapshot()
349
+ this.publish({
350
+ status: form?.status || 'unavailable',
351
+ value: form?.value || {},
352
+ writable: form?.writable === true,
353
+ revision: form?.revision,
354
+ error: this.snapshot.error || null,
355
+ })
356
+ }
357
+
358
+ async #writeOne(field, value) {
359
+ if (!this.form) return false
360
+ // `set` is the convenience path used by this plugin since 1.5.1;
361
+ // `mutate` is the lower-level scope API (revision-fenced batch). Try
362
+ // the convenience path first, fall back to one path-addressed op.
363
+ if (typeof this.form.set === 'function') {
364
+ return (await this.form.set(field, value)) !== false
365
+ }
366
+ if (typeof this.form.mutate === 'function') {
367
+ const current = this.form.getSnapshot()
368
+ const accepted = await this.form.mutate(
369
+ [{ op: 'set', path: field, value }],
370
+ current?.revision,
371
+ )
372
+ return accepted !== false
373
+ }
374
+ return false
375
+ }
376
+
377
+ async setField(field, value) {
378
+ try {
379
+ const accepted = await this.#writeOne(field, value)
380
+ this.publish({ ...this.snapshot, error: accepted ? null : 'saveFailed' })
381
+ return accepted
382
+ } catch {
383
+ this.publish({ ...this.snapshot, error: 'saveFailed' })
384
+ return false
385
+ }
386
+ }
387
+
388
+ /** Write several switches as one user action (preset button). */
389
+ async setFields(entries) {
390
+ // A batch is one revision-fenced write: the Host applies every field
391
+ // or none. Sequential writes could race a plugin reload between them.
392
+ if (this.form && typeof this.form.mutate === 'function') {
393
+ try {
394
+ const current = this.form.getSnapshot()
395
+ const ops = entries.map(([field, value]) => ({ op: 'set', path: field, value }))
396
+ const accepted = await this.form.mutate(ops, current?.revision)
397
+ if (accepted !== false) {
398
+ this.publish({ ...this.snapshot, error: null })
399
+ return true
400
+ }
401
+ } catch {
402
+ /* fall through to the per-field path */
403
+ }
404
+ }
405
+ for (const [field, value] of entries) {
406
+ try {
407
+ const accepted = await this.#writeOne(field, value)
408
+ if (!accepted) {
409
+ this.publish({ ...this.snapshot, error: 'saveFailed' })
410
+ return false
411
+ }
412
+ } catch {
413
+ this.publish({ ...this.snapshot, error: 'saveFailed' })
414
+ return false
415
+ }
416
+ }
417
+ this.publish({ ...this.snapshot, error: null })
418
+ return true
419
+ }
420
+
421
+ dispose() {
422
+ this.mirrorUnsubscribe?.()
423
+ this.formUnsubscribe?.()
424
+ this.listeners.clear()
425
+ }
426
+ }
427
+
428
+ function Toggle({ checked, disabled, label, onChange }) {
429
+ return h('button', {
430
+ type: 'button',
431
+ role: 'switch',
432
+ 'aria-checked': checked ? 'true' : 'false',
433
+ 'aria-label': label,
434
+ disabled,
435
+ className: 'zju-switch',
436
+ onClick: () => {
437
+ if (!disabled) onChange(!checked)
438
+ },
439
+ }, h('span', { className: 'zju-knob', 'aria-hidden': 'true' }))
440
+ }
441
+
442
+ /**
443
+ * One text or number input for the advanced settings.
444
+ *
445
+ * The field keeps a local draft so typing does not write to the Host on
446
+ * every keystroke; blur or Enter commits one revision-fenced write. A
447
+ * failed write leaves the previous value in the form snapshot, so the
448
+ * effect below resets the draft on the next render.
449
+ */
450
+ function TextField({
451
+ label,
452
+ value,
453
+ placeholder,
454
+ disabled,
455
+ type = 'text',
456
+ min,
457
+ max,
458
+ step,
459
+ onCommit,
460
+ }) {
461
+ const [draft, setDraft] = React.useState(value ?? '')
462
+ React.useEffect(() => {
463
+ setDraft(value ?? '')
464
+ }, [value])
465
+ const commit = () => {
466
+ const text = String(draft).trim()
467
+ if (type === 'number') {
468
+ const number = Number(text)
469
+ if (!text || !Number.isFinite(number)) {
470
+ setDraft(value ?? '')
471
+ return
472
+ }
473
+ const clamped = Math.min(Number(max), Math.max(Number(min), Math.round(number)))
474
+ if (clamped !== Number(value)) onCommit(clamped)
475
+ else setDraft(String(value ?? ''))
476
+ return
477
+ }
478
+ if (text !== String(value ?? '')) onCommit(text)
479
+ }
480
+ return h('input', {
481
+ type,
482
+ className: 'zju-input',
483
+ value: draft,
484
+ placeholder,
485
+ disabled,
486
+ 'aria-label': label,
487
+ min,
488
+ max,
489
+ step,
490
+ onChange: (event) => setDraft(event.target.value),
491
+ onBlur: commit,
492
+ onKeyDown: (event) => {
493
+ if (event.key === 'Enter') event.currentTarget.blur()
494
+ },
495
+ })
496
+ }
497
+
498
+ function useSettingsSnapshot(settings) {
499
+ const [snapshot, setSnapshot] = React.useState(settings.getSnapshot())
500
+ React.useEffect(() => {
501
+ setSnapshot(settings.getSnapshot())
502
+ return settings.subscribe(() => setSnapshot(settings.getSnapshot()))
503
+ }, [settings])
504
+ return snapshot
505
+ }
506
+
507
+ function useSaveState() {
508
+ const [state, setState] = React.useState('idle')
509
+ const run = async (action) => {
510
+ setState('saving')
511
+ const ok = await action()
512
+ setState(ok ? 'saved' : 'failed')
513
+ return ok
514
+ }
515
+ return [state, run]
516
+ }
517
+
518
+ function Row({ t, title, hint, checked, disabled, onChange }) {
519
+ return h('div', { className: 'zju-row' },
520
+ h('div', { className: 'zju-copy' },
521
+ h('div', { className: 'zju-row-title' }, t(title)),
522
+ h('div', { className: 'zju-row-hint' }, t(hint)),
523
+ ),
524
+ h(Toggle, { checked, disabled, label: t(title), onChange }),
525
+ )
526
+ }
527
+
528
+ function InputRow({
529
+ t,
530
+ title,
531
+ hint,
532
+ value,
533
+ placeholder,
534
+ type,
535
+ min,
536
+ max,
537
+ step,
538
+ disabled,
539
+ onCommit,
540
+ }) {
541
+ return h('div', { className: 'zju-row' },
542
+ h('div', { className: 'zju-copy' },
543
+ h('div', { className: 'zju-row-title' }, t(title)),
544
+ h('div', { className: 'zju-row-hint' }, t(hint)),
545
+ ),
546
+ h('div', { className: 'zju-field' },
547
+ h(TextField, {
548
+ label: t(title),
549
+ value,
550
+ placeholder,
551
+ type,
552
+ min,
553
+ max,
554
+ step,
555
+ disabled,
556
+ onCommit,
557
+ }),
558
+ ),
559
+ )
560
+ }
561
+
562
+ function Group({ title, body, badge, children }) {
563
+ return h('section', { className: 'zju-group' },
564
+ h('header', { className: 'zju-group-head' },
565
+ h('h3', { className: 'zju-group-title' }, title),
566
+ badge ? h('span', { className: 'zju-badge' }, badge) : null,
567
+ ),
568
+ body ? h('p', { className: 'zju-group-body' }, body) : null,
569
+ h('div', { className: 'zju-group-rows' }, children),
570
+ )
571
+ }
572
+
573
+ function PipelineSection({ t, settings, asPage }) {
574
+ const snapshot = useSettingsSnapshot(settings)
575
+ const [saveState, runSave] = useSaveState()
576
+ const value = snapshot.value || {}
577
+ const enableSlides = value.enableSlides === true
578
+ const renderPdf = value.renderPdf !== false
579
+ const typstAutoInstall = value.typstAutoInstall !== false
580
+ const enableStudyNotes = value.enableStudyNotes === true
581
+ const enableLoginTools = value.enableLoginTools === true
582
+ const embedSlideImages = enableSlides && value.embedSlideImages === true
583
+ const registerSkill = value.registerSkill !== false
584
+ const python = typeof value.python === 'string' ? value.python : ''
585
+ const typstPath = typeof value.typstPath === 'string' ? value.typstPath : ''
586
+ const typstMirror = typeof value.typstMirror === 'string' ? value.typstMirror : ''
587
+ const timeoutMs = Number.isFinite(value.timeoutMs) ? value.timeoutMs : 120000
588
+ const ready = snapshot.status === 'ready'
589
+ const disabled = !ready || !snapshot.writable || saveState === 'saving'
590
+ const toolCount = 7
591
+ + (enableStudyNotes ? 1 : 0)
592
+ + (enableSlides ? 1 : 0)
593
+ + (enableLoginTools ? 2 : 0)
594
+ const note = !ready && snapshot.status !== 'unavailable'
595
+ ? t('loading')
596
+ : snapshot.status === 'unavailable'
597
+ ? t('unavailable')
598
+ : ready && !snapshot.writable
599
+ ? t('readOnly')
600
+ : null
601
+ const saveLabel = saveState === 'saving'
602
+ ? t('saveSaving')
603
+ : saveState === 'saved'
604
+ ? t('saveDone')
605
+ : saveState === 'failed'
606
+ ? t('saveFailed')
607
+ : snapshot.error
608
+ ? t('saveFailed')
609
+ : ''
610
+
611
+ const update = (field, next) => runSave(() => settings.setField(field, next))
612
+
613
+ const applyPreset = (preset) => runSave(async () => {
614
+ const sets = preset === 'token'
615
+ ? [['renderPdf', true], ['enableStudyNotes', false], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
616
+ : preset === 'study'
617
+ ? [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
618
+ : [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', true], ['embedSlideImages', true], ['enableLoginTools', true]]
619
+ return settings.setFields(sets)
620
+ })
621
+
622
+ return h('div', { className: 'zju-settings-page', 'data-zju-settings': 'pipeline' },
623
+ h('style', { 'data-plugin': '@plugin/dsh-zju-lecture-note' }, CSS),
624
+ h('header', { className: 'zju-hero' },
625
+ h('div', { className: 'zju-hero-top' },
626
+ h('div', null,
627
+ h('div', { className: 'zju-eyebrow' }, t('eyebrow')),
628
+ h(asPage ? 'h1' : 'h2', { className: 'zju-hero-title' }, t('heroTitle')),
629
+ h('p', { className: 'zju-hero-body' }, t('heroBody')),
630
+ ),
631
+ h('div', { className: 'zju-hero-badges' },
632
+ h('span', { className: 'zju-pill' }, `${toolCount} ${t('toolCountLabel')}`),
633
+ h('span', { className: `zju-pill${renderPdf ? ' is-on' : ''}` }, renderPdf ? t('pdfOn') : t('pdfOff')),
634
+ ),
635
+ ),
636
+ h('div', { className: 'zju-pipeline', 'aria-hidden': 'true' },
637
+ h('span', { className: 'zju-step' }, t('pipelineTranscript')),
638
+ h('span', { className: 'zju-arrow' }, '→'),
639
+ h('span', { className: 'zju-step' }, t('pipelineNotes')),
640
+ h('span', { className: 'zju-arrow' }, '→'),
641
+ h('span', { className: `zju-step${renderPdf ? '' : ' is-off'}` }, t('pipelinePdf')),
642
+ ),
643
+ ),
644
+ note ? h('div', { className: 'zju-note', role: 'status' }, note) : null,
645
+ h('div', { className: 'zju-presets' },
646
+ h('span', { className: 'zju-presets-label' }, t('presetsTitle')),
647
+ h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('token') },
648
+ h('span', { className: 'zju-preset-name' }, t('presetToken')),
649
+ h('span', { className: 'zju-preset-hint' }, t('presetTokenHint')),
650
+ ),
651
+ h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('study') },
652
+ h('span', { className: 'zju-preset-name' }, t('presetStudy')),
653
+ h('span', { className: 'zju-preset-hint' }, t('presetStudyHint')),
654
+ ),
655
+ h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('full') },
656
+ h('span', { className: 'zju-preset-name' }, t('presetFull')),
657
+ h('span', { className: 'zju-preset-hint' }, t('presetFullHint')),
658
+ ),
659
+ ),
660
+ h('div', { className: 'zju-groups' },
661
+ h(Group, {
662
+ title: t('coreTitle'),
663
+ badge: t('coreBadge'),
664
+ },
665
+ h(Row, {
666
+ t,
667
+ title: 'coreRowTitle',
668
+ hint: 'coreRowHint',
669
+ checked: true,
670
+ disabled: true,
671
+ onChange: () => {},
672
+ }),
673
+ ),
674
+ h(Group, {
675
+ title: t('outputTitle'),
676
+ body: t('outputBody'),
677
+ badge: t('outputBadge'),
678
+ },
679
+ h(Row, {
680
+ t,
681
+ title: 'pdfTitle',
682
+ hint: 'pdfHint',
683
+ checked: renderPdf,
684
+ disabled,
685
+ onChange: (next) => update('renderPdf', next),
686
+ }),
687
+ ),
688
+ h(Group, {
689
+ title: t('envTitle'),
690
+ body: t('envBody'),
691
+ badge: t('envBadge'),
692
+ },
693
+ h(Row, {
694
+ t,
695
+ title: 'envAutoTitle',
696
+ hint: 'envAutoHint',
697
+ checked: typstAutoInstall,
698
+ disabled,
699
+ onChange: (next) => update('typstAutoInstall', next),
700
+ }),
701
+ h(InputRow, {
702
+ t,
703
+ title: 'envPathTitle',
704
+ hint: 'envPathHint',
705
+ value: typstPath,
706
+ placeholder: t('envPathPlaceholder'),
707
+ disabled,
708
+ onCommit: (next) => update('typstPath', next),
709
+ }),
710
+ h(InputRow, {
711
+ t,
712
+ title: 'envMirrorTitle',
713
+ hint: 'envMirrorHint',
714
+ value: typstMirror,
715
+ placeholder: t('envMirrorPlaceholder'),
716
+ disabled,
717
+ onCommit: (next) => update('typstMirror', next),
718
+ }),
719
+ h('div', { className: 'zju-row is-child' },
720
+ h('div', { className: 'zju-copy' },
721
+ h('div', { className: 'zju-row-hint' }, t('envHint')),
722
+ ),
723
+ ),
724
+ ),
725
+ h(Group, {
726
+ title: t('studyTitle'),
727
+ badge: t('studyBadge'),
728
+ },
729
+ h(Row, {
730
+ t,
731
+ title: 'studyTitle2',
732
+ hint: 'studyHint',
733
+ checked: enableStudyNotes,
734
+ disabled,
735
+ onChange: (next) => update('enableStudyNotes', next),
736
+ }),
737
+ ),
738
+ h(Group, {
739
+ title: t('slidesTitle'),
740
+ badge: t('slidesBadge'),
741
+ },
742
+ h(Row, {
743
+ t,
744
+ title: 'slidesTitle2',
745
+ hint: 'slidesHint',
746
+ checked: enableSlides,
747
+ disabled,
748
+ onChange: (next) => update('enableSlides', next),
749
+ }),
750
+ h('div', { className: 'zju-row is-child' },
751
+ h('div', { className: 'zju-copy' },
752
+ h('div', { className: 'zju-row-title' }, t('imagesTitle')),
753
+ h('div', { className: 'zju-row-hint' }, enableSlides ? t('imagesHint') : t('dependency')),
754
+ ),
755
+ h(Toggle, {
756
+ checked: embedSlideImages,
757
+ disabled: disabled || !enableSlides,
758
+ label: t('imagesTitle'),
759
+ onChange: (next) => update('embedSlideImages', next),
760
+ }),
761
+ ),
762
+ ),
763
+ h(Group, {
764
+ title: t('loginTitle'),
765
+ body: t('loginBody'),
766
+ badge: t('loginBadge'),
767
+ },
768
+ h(Row, {
769
+ t,
770
+ title: 'loginTitle2',
771
+ hint: 'loginHint',
772
+ checked: enableLoginTools,
773
+ disabled,
774
+ onChange: (next) => update('enableLoginTools', next),
775
+ }),
776
+ ),
777
+ h(Group, {
778
+ title: t('advancedTitle'),
779
+ badge: t('advancedBadge'),
780
+ },
781
+ h(InputRow, {
782
+ t,
783
+ title: 'pythonTitle',
784
+ hint: 'pythonHint',
785
+ value: python,
786
+ placeholder: t('pythonPlaceholder'),
787
+ disabled,
788
+ onCommit: (next) => update('python', next),
789
+ }),
790
+ h(InputRow, {
791
+ t,
792
+ title: 'timeoutTitle',
793
+ hint: 'timeoutHint',
794
+ value: timeoutMs,
795
+ type: 'number',
796
+ min: 1000,
797
+ max: 900000,
798
+ step: 1000,
799
+ disabled,
800
+ onCommit: (next) => update('timeoutMs', next),
801
+ }),
802
+ h(Row, {
803
+ t,
804
+ title: 'registerSkillTitle',
805
+ hint: 'registerSkillHint',
806
+ checked: registerSkill,
807
+ disabled,
808
+ onChange: (next) => update('registerSkill', next),
809
+ }),
810
+ ),
811
+ ),
812
+ h('footer', { className: 'zju-foot' },
813
+ h('span', { className: 'zju-note' }, `${t('toolsNowPrefix')} ${toolCount} ${t('toolsNowSuffix')} · ${t('toolsNowHint')}`),
814
+ h('span', {
815
+ className: 'zju-save',
816
+ 'data-state': saveState,
817
+ 'aria-live': 'polite',
818
+ }, saveLabel),
819
+ ),
820
+ asPage ? h('p', { className: 'zju-note' }, t('panelNote')) : null,
821
+ )
822
+ }
823
+
824
+ /**
825
+ * The left-column row's glyph. A `sidebar.panellist` entry draws its own
826
+ * icon — the slot hands it `size` and `active`, no icon field exists — and
827
+ * the row's own colour must come through, hence `currentColor`.
828
+ */
829
+ function PanelIcon({ size = 18 }) {
830
+ return h('svg', {
831
+ width: size,
832
+ height: size,
833
+ viewBox: '0 0 20 20',
834
+ fill: 'none',
835
+ stroke: 'currentColor',
836
+ strokeWidth: 1.5,
837
+ strokeLinecap: 'round',
838
+ strokeLinejoin: 'round',
839
+ 'aria-hidden': 'true',
840
+ focusable: 'false',
841
+ },
842
+ h('path', { d: 'M4.6 3.4h6.1l4.7 4.7v7.5a1 1 0 0 1-1 1H4.6a1 1 0 0 1-1-1V4.4a1 1 0 0 1 1-1Z' }),
843
+ h('path', { d: 'M10.6 3.5v4.7h4.7' }),
844
+ h('path', { d: 'M6.7 11.2h4.4' }),
845
+ h('path', { d: 'M6.7 13.7h6.2' }),
846
+ )
847
+ }
848
+
849
+ /**
850
+ * The page behind the left-column row.
851
+ *
852
+ * A `main` occupant is a full-height centre column, so it owns the page
853
+ * padding the shipped entry pages use: `--dsh-frame-top-clearance` keeps the
854
+ * first row below the window caption on Windows and under the traffic lights
855
+ * on macOS. The content itself is the settings section, unchanged.
856
+ */
857
+ function SettingsPanelPage(props) {
858
+ return h('div', { className: 'zju-panel', 'data-zju-panel': PANEL_ID },
859
+ h('div', { className: 'zju-panel-inner' },
860
+ h(PipelineSection, { ...props, asPage: true }),
861
+ ),
862
+ )
863
+ }
864
+
865
+ function apply(ctx) {
866
+ ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'zju-lecture: settings dictionaries')
867
+ const t = ctx.locale.bind(NS)
868
+ const settings = new PipelineSettings(ctx)
869
+ ctx.effect(() => () => settings.dispose(), 'zju-lecture: settings form')
870
+ ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({
871
+ name: 'settings.section',
872
+ id: PANEL_ID,
873
+ order: 25,
874
+ label: () => t('sectionTitle'),
875
+ locale: NS,
876
+ inject: () => ({ settings }),
877
+ }, PipelineSection)), 'zju-lecture: settings section')
878
+ // The left column: one `sidebar.panellist` row and the `main` page under
879
+ // the same id. Registered from the inner callback so the row and its page
880
+ // appear together or not at all, exactly as the shipped panels do.
881
+ ctx.effect(() => ctx.slots.inject('main', () => ctx.slots.inject('sidebar.panellist', () => {
882
+ const stopPage = ctx.slots.register({
883
+ name: 'main',
884
+ key: PANEL_ID,
885
+ locale: NS,
886
+ inject: () => ({ settings }),
887
+ }, SettingsPanelPage)
888
+ const stopRow = ctx.slots.register({
889
+ name: 'sidebar.panellist',
890
+ id: PANEL_ID,
891
+ order: 30,
892
+ label: () => t('panelLabel'),
893
+ locale: NS,
894
+ }, PanelIcon)
895
+ return () => {
896
+ stopRow()
897
+ stopPage()
898
+ }
899
+ })), 'zju-lecture: sidebar entry')
900
+ }
901
+
902
+ return {
903
+ inject: ['slots', 'locale', 'configForms'],
904
+ apply,
905
+ }
906
+ },
907
+ })