dsh-zju-lecture-note 2.2.6 → 2.2.8

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