vanspod 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,7 @@ npm run dist
38
38
  npm pack --pack-destination dist
39
39
  ```
40
40
 
41
- exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.5.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
41
+ exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.7.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
42
42
 
43
43
  exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vanspod`](https://www.npmjs.com/package/vanspod) 套件。更新時不要執行完整移除,否則會清除課堂資料。
44
44
 
@@ -46,12 +46,12 @@ exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vans
46
46
 
47
47
  一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。
48
48
 
49
- 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.5` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.7` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.4.5 -m "VansPod 0.4.5"
54
- git push origin v0.4.5
53
+ git tag -a v0.4.7 -m "VansPod 0.4.7"
54
+ git push origin v0.4.7
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
@@ -9,6 +9,7 @@ const node_util_1 = require("node:util");
9
9
  const courseCatalog_1 = require("./courseCatalog");
10
10
  const modelProxy_1 = require("./modelProxy");
11
11
  const classroomKeyRejection_1 = require("./classroomKeyRejection");
12
+ const CLIENT_ROUTE_OF = { codex: "codex", claude: "claudeCode", vscode: "vsCodeChat" };
12
13
  // 新工具加在最後,不改既有 id。
13
14
  exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
14
15
  exports.ENVIRONMENT_LABEL = {
@@ -24,8 +25,9 @@ const KEY_REJECTED_NOTICE = {
24
25
  expired: "Classroom API Key 已過期,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
25
26
  invalid: "Classroom API Key 已失效,請按「清除連線」,再用老師給的新邀請碼重新兌換。",
26
27
  };
27
- const RESTORE_CATALOG_ATTEMPTS = 3;
28
- const RESTORE_CATALOG_RETRY_MS = 1_000;
28
+ const MODELS_UNLOADED_NOTICE = "無法載入課堂模型,請按「↻ 更新」再試。";
29
+ const RESTORE_FETCH_ATTEMPTS = 3;
30
+ const RESTORE_FETCH_RETRY_MS = 1_000;
29
31
  const INSTALL_UNAVAILABLE = "尚未指定專案資料夾,安裝不可用。";
30
32
  const ENVIRONMENT_ABORTED = "已中止安裝。系統安裝程式可能仍在執行,請等待結束或稍後重新安裝。";
31
33
  const PROXY_CLIENTS = ["codex", "claude", "copilot"];
@@ -89,6 +91,11 @@ class ClassroomApp {
89
91
  allowlistError;
90
92
  // Router refused this Classroom API Key; only a new redeem or Clear resets it.
91
93
  keyRejection;
94
+ // 啟動時抓不到 Session Model Allowlist 而暫時退回 Native 的 Client Route;設定檔仍保留 Classroom,
95
+ // 「更新」抓到模型後切回去。學生自己切換或換堂後就不再代為恢復。
96
+ classroomAwaitingModels = new Set();
97
+ // 恢復 Classroom Connection 時重試後仍抓不到 Session Model Allowlist;和老師沒開放任何模型不同。
98
+ allowlistUnloaded = false;
92
99
  routeRestartNoted = false;
93
100
  vsCodeOrigin;
94
101
  sending = new Map();
@@ -794,6 +801,8 @@ class ClassroomApp {
794
801
  this.modelProviders = [];
795
802
  this.allowlistError = undefined;
796
803
  this.keyRejection = undefined;
804
+ this.allowlistUnloaded = false;
805
+ this.classroomAwaitingModels.clear();
797
806
  this.forgetModelChoices();
798
807
  this.catalog = undefined;
799
808
  this.catalogError = undefined;
@@ -889,6 +898,18 @@ class ClassroomApp {
889
898
  return this.serialConnectionOperation(() => client ? this.setClientSwitch(mode, client) : this.setSwitchNow(mode));
890
899
  }
891
900
  async setClientSwitch(mode, client) {
901
+ // 學生自己選了 Native,就不再代為恢復啟動前的 Classroom;路由此時已是 Native,只差存檔。
902
+ // 選 Classroom 則照常切換,抓不到模型被拒時仍等「更新」恢復。
903
+ const route = CLIENT_ROUTE_OF[client];
904
+ if (mode === "native" && this.classroomAwaitingModels.delete(route)) {
905
+ try {
906
+ await this.saveClientRoutePreferences();
907
+ }
908
+ catch {
909
+ this.notice = "無法儲存 Native 模式,重新啟動仍可能恢復 Classroom;請重試。";
910
+ }
911
+ return;
912
+ }
892
913
  if (client === "vscode") {
893
914
  await this.setVsCodeClientRouteSwitch(mode);
894
915
  return;
@@ -1166,12 +1187,41 @@ class ClassroomApp {
1166
1187
  return this.serialConnectionOperation(() => this.reloadAllowlistNow());
1167
1188
  }
1168
1189
  async saveClientRoutePreferences() {
1190
+ const savedMode = (id) => this.classroomAwaitingModels.has(id) ? "classroom" : this.clientRoutes[id].mode;
1169
1191
  await this.deps.clientRouteSettings?.save({
1170
- codex: { mode: this.clientRoutes.codex.mode, adapter: this.clientRoutes.codex.adapter },
1171
- claudeCode: { mode: this.clientRoutes.claudeCode.mode, adapter: this.clientRoutes.claudeCode.adapter },
1172
- vsCodeChat: { mode: this.clientRoutes.vsCodeChat.mode, adapter: this.clientRoutes.vsCodeChat.adapter },
1192
+ codex: { mode: savedMode("codex"), adapter: this.clientRoutes.codex.adapter },
1193
+ claudeCode: { mode: savedMode("claudeCode"), adapter: this.clientRoutes.claudeCode.adapter },
1194
+ vsCodeChat: { mode: savedMode("vsCodeChat"), adapter: this.clientRoutes.vsCodeChat.adapter },
1173
1195
  });
1174
1196
  }
1197
+ noteClassroomAwaitingModels(route) {
1198
+ if (this.connected && this.allowlistUnloaded)
1199
+ this.classroomAwaitingModels.add(route);
1200
+ }
1201
+ /** 「更新」抓到 Session Model Allowlist 後,把啟動時暫時退回 Native 的 Client Route 切回 Classroom。 */
1202
+ // 老師沒開放任何模型、或路由已紅燈/灰燈時不切回;紅燈恢復後仍須學生自己切入 Classroom(ADR-0006)。
1203
+ async resumeClassroomAwaitingModels() {
1204
+ const waiting = [...this.classroomAwaitingModels];
1205
+ if (waiting.length === 0)
1206
+ return;
1207
+ this.classroomAwaitingModels.clear();
1208
+ for (const route of waiting) {
1209
+ const health = this.clientRoutes[route].health;
1210
+ if (this.modelIds.length === 0 || health === "red" || health === "gray")
1211
+ continue;
1212
+ if (route === "codex")
1213
+ await this.setCodexClientRouteSwitch("classroom");
1214
+ else if (route === "claudeCode")
1215
+ await this.setClaudeCodeClientRouteSwitch("classroom");
1216
+ else
1217
+ await this.setVsCodeClientRouteSwitch("classroom");
1218
+ }
1219
+ // 沒切回的路由此時才把 Native 寫進設定檔。
1220
+ try {
1221
+ await this.saveClientRoutePreferences();
1222
+ }
1223
+ catch { /* Route state stays visible; the next save retries. */ }
1224
+ }
1175
1225
  async startCodexRoute() {
1176
1226
  const runtime = this.deps.clientRouteRuntime;
1177
1227
  if (!runtime)
@@ -1208,6 +1258,7 @@ class ClassroomApp {
1208
1258
  }
1209
1259
  lifecycle = this.codexLifecycle(); // start() supplied the route's authoritative origin.
1210
1260
  if (this.clientRoutes.codex.mode === "classroom" && (!this.connected || this.modelIds.length === 0)) {
1261
+ this.noteClassroomAwaitingModels("codex");
1211
1262
  lifecycle.setMode("native");
1212
1263
  try {
1213
1264
  await this.saveClientRoutePreferences();
@@ -1293,6 +1344,8 @@ class ClassroomApp {
1293
1344
  this.settleVsCodePublish(result?.changed);
1294
1345
  }
1295
1346
  else {
1347
+ if (this.clientRoutes.vsCodeChat.mode === "classroom")
1348
+ this.noteClassroomAwaitingModels("vsCodeChat");
1296
1349
  this.clientRoutes.vsCodeChat.mode = "native";
1297
1350
  await this.deps.vsCodeRouteSettings?.initializeNative();
1298
1351
  this.clientRoutes.vsCodeChat.health = "green";
@@ -1361,6 +1414,7 @@ class ClassroomApp {
1361
1414
  return;
1362
1415
  }
1363
1416
  if (route.mode === "classroom" && (!this.connected || this.modelIds.length === 0)) {
1417
+ this.noteClassroomAwaitingModels("claudeCode");
1364
1418
  route.mode = "native";
1365
1419
  try {
1366
1420
  await this.saveClientRoutePreferences();
@@ -1439,8 +1493,14 @@ class ClassroomApp {
1439
1493
  const refreshed = await this.loadModels(apiKey);
1440
1494
  if (this.keyRejection)
1441
1495
  this.showKeyRejection(this.keyRejection);
1496
+ else if (refreshed)
1497
+ this.allowlistError = undefined;
1442
1498
  else
1443
- this.allowlistError = refreshed ? undefined : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1499
+ this.allowlistError = this.allowlistUnloaded ? MODELS_UNLOADED_NOTICE : "重新載入課堂模型失敗,已保留上次成功的模型清單。";
1500
+ if (refreshed) {
1501
+ this.allowlistUnloaded = false;
1502
+ await this.resumeClassroomAwaitingModels();
1503
+ }
1444
1504
  const current = this.mode === "classroom" ? this.modelIds.join("\0") : "";
1445
1505
  if (previous !== current) {
1446
1506
  this.modelRestart = ["codex", "claude"].filter(client => this.clientModes[client] === "classroom");
@@ -1456,10 +1516,10 @@ class ClassroomApp {
1456
1516
  }
1457
1517
  }
1458
1518
  }
1459
- async loadModels(apiKey) {
1519
+ async loadModels(apiKey, attempts = 1) {
1460
1520
  let payload;
1461
1521
  try {
1462
- payload = await this.deps.router.fetchSessionModels(apiKey);
1522
+ payload = await fetchWithRetries(attempts, () => this.deps.router.fetchSessionModels(apiKey));
1463
1523
  }
1464
1524
  catch (error) {
1465
1525
  if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError)
@@ -1640,6 +1700,8 @@ class ClassroomApp {
1640
1700
  this.notice = undefined;
1641
1701
  this.allowlistError = undefined;
1642
1702
  this.keyRejection = undefined;
1703
+ this.allowlistUnloaded = false;
1704
+ this.classroomAwaitingModels.clear();
1643
1705
  this.catalog = undefined;
1644
1706
  this.catalogError = undefined;
1645
1707
  this.remoteCatalogHeld = false;
@@ -1794,11 +1856,16 @@ class ClassroomApp {
1794
1856
  this.hiddenKeys.add(connection.apiKey);
1795
1857
  this.applyConnectionIdentity(connection);
1796
1858
  this.mode = "native";
1797
- // 版本更新後重新啟動時網路可能還沒穩;恢復 Classroom Connection 時抓不到 Course Catalog 就稍候再試,才退回本機的 classroom-installs.yaml。
1798
- await this.loadCatalog(RESTORE_CATALOG_ATTEMPTS);
1799
- await this.loadModels(connection.apiKey);
1859
+ // 版本更新後重新啟動時網路可能還沒穩;恢復 Classroom Connection 時抓不到 Course Catalog
1860
+ // 或 Session Model Allowlist 就稍候再試,才退回本機的 classroom-installs.yaml 或 Native。
1861
+ await this.loadCatalog(RESTORE_FETCH_ATTEMPTS);
1862
+ const modelsLoaded = await this.loadModels(connection.apiKey, RESTORE_FETCH_ATTEMPTS);
1800
1863
  if (this.keyRejection)
1801
1864
  this.showKeyRejection(this.keyRejection);
1865
+ else if (!modelsLoaded) {
1866
+ this.allowlistUnloaded = true;
1867
+ this.allowlistError = MODELS_UNLOADED_NOTICE;
1868
+ }
1802
1869
  if (connection.mode === "classroom" && this.modelIds.length > 0) {
1803
1870
  this.mode = "classroom";
1804
1871
  this.clientModes = connection.clientModes ?? { codex: "classroom", claude: "classroom" };
@@ -1888,23 +1955,17 @@ class ClassroomApp {
1888
1955
  return;
1889
1956
  }
1890
1957
  let body;
1891
- for (let attempt = 1;; attempt++) {
1892
- try {
1893
- body = await this.deps.catalog.fetchCourseCatalog(apiKey);
1894
- break;
1895
- }
1896
- catch (error) {
1897
- // The refused key is reported with the allowlist; the last catalog stays on screen.
1898
- if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError) {
1899
- this.keyRejection = error.reason;
1900
- return;
1901
- }
1902
- if (attempt >= attempts) {
1903
- await this.loadLocalCatalog();
1904
- return;
1905
- }
1906
- await new Promise(resolve => setTimeout(resolve, RESTORE_CATALOG_RETRY_MS));
1958
+ try {
1959
+ body = await fetchWithRetries(attempts, () => this.deps.catalog.fetchCourseCatalog(apiKey));
1960
+ }
1961
+ catch (error) {
1962
+ // The refused key is reported with the allowlist; the last catalog stays on screen.
1963
+ if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError) {
1964
+ this.keyRejection = error.reason;
1965
+ return;
1907
1966
  }
1967
+ await this.loadLocalCatalog();
1968
+ return;
1908
1969
  }
1909
1970
  const yaml = usableCatalogYaml(body?.course_catalog_yaml);
1910
1971
  if (yaml === undefined) {
@@ -1950,6 +2011,19 @@ class ClassroomApp {
1950
2011
  }
1951
2012
  }
1952
2013
  exports.ClassroomApp = ClassroomApp;
2014
+ /** 失敗時稍候再試,最多 attempts 次;Router 拒絕 Classroom API Key 時再試也沒用,立刻放棄。 */
2015
+ async function fetchWithRetries(attempts, fetch) {
2016
+ for (let attempt = 1;; attempt++) {
2017
+ try {
2018
+ return await fetch();
2019
+ }
2020
+ catch (error) {
2021
+ if (error instanceof classroomKeyRejection_1.ClassroomKeyRejectedError || attempt >= attempts)
2022
+ throw error;
2023
+ await new Promise(resolve => setTimeout(resolve, RESTORE_FETCH_RETRY_MS));
2024
+ }
2025
+ }
2026
+ }
1953
2027
  /** 安裝後驗證未通過時的提示;安裝程式要求重新開機時,請學生重開機後再檢查。 */
1954
2028
  function environmentInstallFailure(label, result, verified) {
1955
2029
  const rejected = result?.failure
@@ -2,42 +2,118 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lifecyclePage = lifecyclePage;
4
4
  const versionUpdateView_1 = require("./versionUpdateView");
5
+ const TRASH_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3"/></svg>`;
6
+ // 完整移除的確認對話框:先列出會刪除/會保留,實際路徑由管理 API 的預覽填入。
7
+ const REMOVE_DIALOG = `<div class="power-modal" hidden><div class="power-dialog" role="dialog" aria-modal="true" aria-labelledby="power-remove-title"><h3 id="power-remove-title">移除 VansPod?</h3><p class="power-warn">只在不再使用這台電腦上課時移除。更新版本不需要移除,否則會清掉課堂資料。</p><p class="power-warn" data-uninstall-interruptions hidden></p><div class="power-split"><div class="drop"><h4>會刪除</h4><ul><li>課堂憑證(API Key)</li><li>偏好與模式記憶</li><li>日誌與暫存檔</li><li>VansPod 程式本身</li></ul></div><div class="keep"><h4>會保留</h4><ul><li>學生專案與作品</li><li>Node、Git、VS Code</li><li>個人設定</li></ul></div></div><details class="power-paths"><summary>查看實際路徑</summary><pre data-uninstall-preview>讀取中…</pre></details><div class="power-confirm" data-power-modal-confirm hidden></div><div class="power-actions"><button type="button" class="quiet" data-power-modal-close>取消</button><button type="button" class="danger" data-lifecycle-confirm="uninstall">${TRASH_ICON}<span>確認移除</span></button></div></div></div><!-- /power-modal -->`;
5
8
  function lifecyclePage(html, token) {
6
- const controls = `<div style="margin-top:16px"><button type="button" data-lifecycle="stop">結束 VansPod</button> <button type="button" data-lifecycle="uninstall">移除 VansPod</button><p role="status" data-lifecycle-message></p></div>`;
9
+ const stop = `<button type="button" class="power-stop" data-lifecycle="stop">結束 VansPod</button>`;
10
+ const remove = `<button type="button" class="power-remove" data-lifecycle="uninstall">移除 VansPod…</button>`;
7
11
  const script = `<script>
8
12
  (function () {
9
13
  var token = ${JSON.stringify(token)};
14
+ var toggle = document.querySelector('[data-power-toggle]');
15
+ var message = document.querySelector('[data-lifecycle-message]');
16
+ var modal = document.querySelector('.power-modal');
10
17
  async function request(action, body) {
11
18
  var response = await fetch('/_vanspod/' + action, {method: body ? 'POST' : 'GET', headers: {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}, body: body ? JSON.stringify(body) : undefined});
12
19
  if (!response.ok) throw new Error('無法完成操作,請重新開啟 VansPod。');
13
20
  return response.json();
14
21
  }
22
+ // 訊息寫在面板裡;不是成功訊息時,電源鈕亮黃點提醒學生打開看。
23
+ function say(text, ok) {
24
+ message.textContent = text || '';
25
+ message.classList.toggle('ok', !!ok);
26
+ toggle.classList.toggle('has-message', !!text && !ok);
27
+ }
28
+ // 中斷安裝或模型回答前,在面板/對話框裡再問一次,預設停在「取消」。
29
+ // 面板或對話框被關掉時當作取消,按鈕才不會一直停在停用。
30
+ var pending = null;
31
+ function cancelPending(records) {
32
+ if (pending && records.some(function (record) { return record.target.hidden; })) pending(false);
33
+ }
34
+ var watchHidden = new MutationObserver(cancelPending);
35
+ watchHidden.observe(document.getElementById('power-panel'), {attributes: true, attributeFilter: ['hidden']});
36
+ watchHidden.observe(modal, {attributes: true, attributeFilter: ['hidden']});
37
+ function ask(box, text, label) {
38
+ return new Promise(function (resolve) {
39
+ box.textContent = '';
40
+ var question = document.createElement('p'); question.textContent = text;
41
+ var actions = document.createElement('div'); actions.className = 'power-actions';
42
+ var cancel = document.createElement('button'); cancel.type = 'button'; cancel.className = 'quiet'; cancel.textContent = '取消';
43
+ var go = document.createElement('button'); go.type = 'button'; go.className = 'danger'; go.textContent = label;
44
+ actions.append(cancel, go); box.append(question, actions); box.hidden = false; cancel.focus();
45
+ function done(value) { pending = null; box.hidden = true; box.textContent = ''; resolve(value); }
46
+ pending = done;
47
+ cancel.onclick = function () { done(false); };
48
+ go.onclick = function () { done(true); };
49
+ });
50
+ }
51
+ async function run(action, body, box, label) {
52
+ var result = await request(action, body);
53
+ if (!result.confirmation) return result;
54
+ if (!(await ask(box, result.message, label))) return null;
55
+ return request(action, Object.assign({}, body, {confirmed: true, interruptConfirmed: true}));
56
+ }
57
+ function setModal(open) {
58
+ if (modal.hidden === !open) return;
59
+ modal.hidden = !open;
60
+ if (open) modal.querySelector('[data-power-modal-close]').focus();
61
+ else document.querySelector('[data-lifecycle="uninstall"]').focus();
62
+ }
63
+ // 預覽回來前不能確認:學生要先看到會刪除什麼、會中止哪些工作。
64
+ async function openRemoval() {
65
+ var paths = modal.querySelector('[data-uninstall-preview]');
66
+ var interruptions = modal.querySelector('[data-uninstall-interruptions]');
67
+ var confirm = modal.querySelector('[data-lifecycle-confirm="uninstall"]');
68
+ paths.textContent = '讀取中…';
69
+ interruptions.hidden = true;
70
+ confirm.disabled = true;
71
+ setModal(true);
72
+ var preview = await request('uninstall-preview');
73
+ if (!preview.ok) { setModal(false); say(preview.message); return; }
74
+ paths.textContent = preview.message;
75
+ interruptions.textContent = preview.interruptions || '';
76
+ interruptions.hidden = !preview.interruptions;
77
+ confirm.disabled = false;
78
+ }
79
+ async function remove() {
80
+ var result = await run('uninstall', {confirmed: true}, modal.querySelector('[data-power-modal-confirm]'), '仍要移除');
81
+ if (!result) return;
82
+ setModal(false);
83
+ say(result.message || '操作未完成,請重試。', result.ok);
84
+ }
85
+ async function stop() {
86
+ var result = await run('stop', {confirmed: false}, document.querySelector('[data-power-confirm]'), '仍要結束');
87
+ if (!result) return;
88
+ say(result.message || (result.ok ? 'VansPod 已結束,可關閉此分頁。' : '操作未完成,請重試。'), result.ok);
89
+ if (result.ok) document.querySelector('.power-head').textContent = 'VansPod 已結束';
90
+ }
15
91
  document.addEventListener('click', async function (event) {
16
- var button = event.target.closest && event.target.closest('[data-lifecycle]');
92
+ var target = event.target;
93
+ if (!target || !target.closest) return;
94
+ if (target.closest('[data-power-modal-close]') || target === modal) { setModal(false); return; }
95
+ var button = target.closest('[data-lifecycle], [data-lifecycle-confirm]');
17
96
  if (!button) return;
18
- var message = document.querySelector('[data-lifecycle-message]');
19
97
  button.disabled = true;
20
98
  try {
21
- var action = button.dataset.lifecycle;
22
- var confirmed = false;
23
- if (action === 'uninstall') {
24
- var preview = await request('uninstall-preview');
25
- if (!preview.ok) { message.textContent = preview.message; return; }
26
- confirmed = window.confirm(preview.message + '\\n\\n確定完整移除 VansPod?');
27
- if (!confirmed) return;
28
- }
29
- var result = await request(action, {confirmed: confirmed});
30
- if (result.confirmation && window.confirm(result.message)) result = await request(action, {confirmed: true, interruptConfirmed: true});
31
- message.textContent = result.message || (result.ok ? 'VansPod 已結束,可關閉此分頁。' : '操作未完成,請重試。');
32
- } catch (error) { message.textContent = error.message; }
99
+ if (button.dataset.lifecycle === 'stop') await stop();
100
+ else if (button.dataset.lifecycle === 'uninstall') await openRemoval();
101
+ else await remove();
102
+ } catch (error) { setModal(false); say(error.message); }
33
103
  finally { button.disabled = false; }
34
104
  });
105
+ document.addEventListener('keydown', function (event) {
106
+ if (event.key === 'Escape' && !modal.hidden) setModal(false);
107
+ });
35
108
  request('status').then(function (status) {
36
- if (status.startupError) { document.querySelector('[data-lifecycle-message]').textContent = status.startupError; return; }
37
- if (status.trayError) { document.querySelector('[data-lifecycle-message]').textContent = '右下角的系統匣圖示無法顯示,VansPod 仍在背景執行。要結束時請用這裡的「結束 VansPod」。'; return; }
38
- if (status.launchVersion && status.launchVersion !== status.version) document.querySelector('[data-lifecycle-message]').textContent = '目前執行版本 ' + status.version + ',本次開啟版本 ' + status.launchVersion + '。換版請先結束 VansPod。';
109
+ if (status.startupError) { say(status.startupError); return; }
110
+ if (status.trayError) { say('右下角的系統匣圖示無法顯示,VansPod 仍在背景執行。要結束時請用側欄底部的電源鈕。'); return; }
111
+ if (status.launchVersion && status.launchVersion !== status.version) say('目前執行版本 ' + status.version + ',本次開啟版本 ' + status.launchVersion + '。換版請先結束 VansPod。');
39
112
  }).catch(function () {});
40
113
  })();
41
114
  </script>`;
42
- return html.replace(/<form method="post" action="\/stop">[\s\S]*?<\/form>/, controls).replace('</body>', `${script}${(0, versionUpdateView_1.versionUpdateScript)(token)}</body>`);
115
+ return html
116
+ .replace(/<form method="post" action="\/stop">[\s\S]*?<\/form>/, stop)
117
+ .replace("<!-- /power-panel -->", `${remove}<!-- /power-panel -->`)
118
+ .replace("</body>", `${REMOVE_DIALOG}${script}${(0, versionUpdateView_1.versionUpdateScript)(token)}</body>`);
43
119
  }
package/dist/page.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modelStatus = modelStatus;
4
4
  exports.environmentStageText = environmentStageText;
5
5
  exports.environmentStatus = environmentStatus;
6
- exports.classroomBlocks = classroomBlocks;
7
6
  exports.renderPage = renderPage;
8
7
  exports.renderInspectorPage = renderInspectorPage;
9
8
  const version_1 = require("./version");
@@ -20,6 +19,7 @@ const classroomApp_1 = require("./classroomApp");
20
19
  const promptCapture_1 = require("./promptCapture");
21
20
  const inspectorView_1 = require("./inspectorView");
22
21
  const versionUpdateView_1 = require("./versionUpdateView");
22
+ const powerMenuView_1 = require("./powerMenuView");
23
23
  const courseCatalog_1 = require("./courseCatalog");
24
24
  const PRODUCT = "VansPod";
25
25
  const VERSION = `v${version_1.VERSION}`;
@@ -312,9 +312,6 @@ function catalogTable(view) {
312
312
  const snippetBlock = snippets ? `<h3>本課片段</h3>${snippets}` : "";
313
313
  return `${head}${table}${snippetBlock}`;
314
314
  }
315
- function stopForm() {
316
- return `<form method="post" action="/stop"><button type="submit" class="stop">停止</button></form>`;
317
- }
318
315
  function tile(title, body, wide = false) {
319
316
  return `<section class="tile${wide ? " wide" : ""}"><h2>${title}</h2>${body}</section>`;
320
317
  }
@@ -608,19 +605,6 @@ function appearanceScript() {
608
605
  });
609
606
  `;
610
607
  }
611
- function classroomBlocks(view) {
612
- return {
613
- status: statusWord(view),
614
- notices: notices(view),
615
- connect: connectInner(view),
616
- folder: folderInner(view),
617
- model: modelInner(view),
618
- environment: environmentInner(view),
619
- command: commandInner(view),
620
- catalog: catalogTable(view),
621
- stop: stopForm(),
622
- };
623
- }
624
608
  const SIDE_PAGES = [
625
609
  {
626
610
  id: "settings",
@@ -639,7 +623,7 @@ const BRAND = `<div class="brand"><div class="logo-badge"><img src="/brand-logo.
639
623
  /** 兩頁共用的側欄:行動版頂列、抽屜遮罩、選單與外觀切換。 */
640
624
  function sideMenu(current) {
641
625
  const items = SIDE_PAGES.map((page) => `<a class="side-item" href="${page.href}"${page.id === current ? ' aria-current="page"' : ""}>${page.icon}<span>${page.label}</span></a>`).join("");
642
- return `<div class="mobile-top"><button type="button" class="menu-toggle" aria-label="開啟選單" aria-expanded="false" aria-controls="side-menu"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/></svg></button>${BRAND}</div><button type="button" class="drawer-scrim" aria-label="關閉選單"></button><header class="bar" id="side-menu">${BRAND}<nav aria-label="選單">${items}</nav><div class="side-foot"><button type="button" data-appearance-toggle aria-label="切換外觀"></button>${versionUpdateView_1.UPDATE_BUTTON}</div></header>`;
626
+ return `<div class="mobile-top"><button type="button" class="menu-toggle" aria-label="開啟選單" aria-expanded="false" aria-controls="side-menu"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/></svg></button>${BRAND}</div><button type="button" class="drawer-scrim" aria-label="關閉選單"></button><header class="bar" id="side-menu">${BRAND}<nav aria-label="選單">${items}</nav><div class="side-foot"><button type="button" data-appearance-toggle aria-label="切換外觀"></button>${versionUpdateView_1.UPDATE_BUTTON}${(0, powerMenuView_1.powerMenu)(VERSION)}</div></header>`;
643
627
  }
644
628
  /** 兩頁共用的頁殼版面:側欄、行動版抽屜。 */
645
629
  const SHELL_LAYOUT_STYLES = `
@@ -657,6 +641,7 @@ const SHELL_LAYOUT_STYLES = `
657
641
  .side-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
658
642
  .side-item svg { width: 18px; height: 18px; flex-shrink: 0; }
659
643
  ${versionUpdateView_1.VERSION_UPDATE_STYLES}
644
+ ${powerMenuView_1.POWER_MENU_STYLES}
660
645
  .mobile-top, .drawer-scrim, .menu-toggle { display: none; }
661
646
  main { justify-self: center; width: min(52rem, 100%); }
662
647
  @media (max-width: 760px) {
@@ -718,7 +703,6 @@ function basePage(view) {
718
703
  ${tile("環境", environmentInner(view))}
719
704
  ${tile("指令", commandInner(view), true)}
720
705
  ${tile("課程", catalogTable(view), true)}
721
- ${tile("離開", stopForm(), true)}
722
706
  </div>
723
707
  </main>
724
708
  </body>
@@ -1114,7 +1098,7 @@ function renderPage(view) {
1114
1098
  main button.connection-clear:hover:not(:disabled) { color: light-dark(#b91c1c, #f87171); }
1115
1099
  ${classroomUpdate_1.classroomUpdateStyles}
1116
1100
  </style>
1117
- <script>${drawerScript()}${installProgress_1.installProgressScript}${environmentProgress_1.environmentProgressScript}${snippetCopyScript()}${courseSectionScript()}${connectionMascot_1.connectionMascotScript}${classroomUpdate_1.classroomUpdateScript}${settingsActions_1.settingsActionsScript}${modelStatus_1.modelStatusScript}
1101
+ <script>${drawerScript()}${powerMenuView_1.powerMenuScript}${installProgress_1.installProgressScript}${environmentProgress_1.environmentProgressScript}${snippetCopyScript()}${courseSectionScript()}${connectionMascot_1.connectionMascotScript}${classroomUpdate_1.classroomUpdateScript}${settingsActions_1.settingsActionsScript}${modelStatus_1.modelStatusScript}
1118
1102
  </script>`;
1119
1103
  return html.replace("</body>", `${extra}</body>`);
1120
1104
  }
@@ -1186,7 +1170,7 @@ function renderInspectorPage(view) {
1186
1170
  ${inspectorView_1.INSPECTOR_STYLES}
1187
1171
  </style>
1188
1172
  ${headPatrol.sheet}
1189
- <script>${drawerScript()}${connectionMascot_1.connectionMascotScript}${headPatrol.script}${recorderActionsScript}${(0, inspectorView_1.inspectorScript)()}</script>
1173
+ <script>${drawerScript()}${powerMenuView_1.powerMenuScript}${connectionMascot_1.connectionMascotScript}${headPatrol.script}${recorderActionsScript}${(0, inspectorView_1.inspectorScript)()}</script>
1190
1174
  </body>
1191
1175
  </html>`;
1192
1176
  }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // 側欄底部最右邊的電源鈕(原型 F)。只放 icon,點了先開面板說明後果,不會直接結束。
3
+ // 面板裡的「結束」是 /stop 表單;有管理 API 時由 lifecyclePage 換成生命週期按鈕並加上完整移除。
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.powerMenuScript = exports.POWER_MENU_STYLES = void 0;
6
+ exports.powerMenu = powerMenu;
7
+ const POWER_ICON = `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M12 3v8"/><path d="M6.3 6.8a8 8 0 1 0 11.4 0"/></svg>`;
8
+ function powerMenu(version) {
9
+ return `<div class="power-menu"><button type="button" class="power-toggle" data-power-toggle aria-label="結束或移除 VansPod" title="結束 VansPod" aria-haspopup="dialog" aria-expanded="false" aria-controls="power-panel">${POWER_ICON}<span class="power-dot" aria-hidden="true"></span></button><div class="power-panel" id="power-panel" role="dialog" aria-label="結束 VansPod" hidden><div class="power-head"><span class="power-live" aria-hidden="true"></span><strong>VansPod ${version} 執行中</strong></div><p class="power-message" role="status" data-lifecycle-message></p><p class="power-note">下課時再結束。課堂連線會中斷,各工具設定恢復原狀;課堂資料保留,下次開啟可接續。</p><div class="power-confirm" data-power-confirm hidden></div><div class="power-actions"><button type="button" class="quiet" data-power-close>取消</button><form method="post" action="/stop"><button type="submit" class="power-stop">結束 VansPod</button></form></div><!-- /power-panel --></div></div>`;
10
+ }
11
+ exports.POWER_MENU_STYLES = `
12
+ .bar .side-foot { position: relative; }
13
+ .power-menu { margin-left: auto; padding-left: 10px; border-left: 1px solid var(--line); display: flex; }
14
+ .power-toggle { position: relative; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; min-height: 2.75rem; flex: 0 0 auto; padding: 0; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
15
+ .power-toggle svg { width: 1.2rem; height: 1.2rem; }
16
+ .power-toggle:hover, .power-toggle[aria-expanded="true"] { color: light-dark(#b91c1c, #f87171); border-color: light-dark(rgba(185, 28, 28, 0.35), rgba(248, 113, 113, 0.35)); background: light-dark(rgba(185, 28, 28, 0.05), rgba(248, 113, 113, 0.08)); }
17
+ .power-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
18
+ .power-dot { display: none; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 999px; background: #f59e0b; box-shadow: 0 0 0 2px var(--bg); }
19
+ .power-toggle.has-message .power-dot { display: block; }
20
+ .power-panel { position: absolute; left: 0; bottom: calc(100% + 10px); z-index: 50; width: min(300px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--tile); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25); color: var(--text); font-size: 13px; }
21
+ .power-panel[hidden] { display: none; }
22
+ .power-head { display: flex; align-items: center; gap: 8px; }
23
+ .power-live { width: 8px; height: 8px; border-radius: 999px; background: light-dark(#10a37f, #4ecb9d); box-shadow: 0 0 0 3px light-dark(rgba(16, 163, 127, 0.15), rgba(78, 203, 157, 0.15)); }
24
+ .power-note { color: var(--muted); line-height: 1.6; }
25
+ .power-message:empty { display: none; }
26
+ .power-message { padding: 10px 12px; border-radius: 10px; background: light-dark(#fff7ed, #3b3024); color: light-dark(#9a3412, #fed7aa); line-height: 1.6; white-space: pre-line; }
27
+ .power-message.ok { background: light-dark(rgba(16, 163, 127, 0.10), rgba(78, 203, 157, 0.13)); color: light-dark(#0a7d5c, #4ecb9d); }
28
+ .power-confirm { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 10px; border: 1px solid light-dark(rgba(185, 28, 28, 0.30), rgba(248, 113, 113, 0.30)); background: light-dark(rgba(185, 28, 28, 0.04), rgba(248, 113, 113, 0.06)); line-height: 1.6; white-space: pre-line; }
29
+ .power-confirm[hidden] { display: none; }
30
+ .power-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
31
+ .power-panel button, .power-dialog button { min-height: 34px; padding: 8px 16px; border-radius: 999px; border: 1px solid transparent; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 500; }
32
+ .power-panel button.quiet, .power-dialog button.quiet { background: transparent; color: var(--text); border-color: var(--line); }
33
+ .power-panel button.danger, .power-dialog button.danger { display: inline-flex; align-items: center; gap: 6px; background: light-dark(#b91c1c, #f87171); color: light-dark(#ffffff, #1c1c1e); }
34
+ .power-dialog button.danger svg { width: 15px; height: 15px; }
35
+ .power-panel .power-remove { width: 100%; min-height: 0; padding: 10px 0 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--muted); font-size: 12px; text-align: left; }
36
+ .power-panel .power-remove:hover { color: light-dark(#b91c1c, #f87171); }
37
+ .power-modal { position: fixed; inset: 0; z-index: 96; display: grid; place-items: center; padding: 24px; background: light-dark(rgba(20, 20, 20, 0.32), rgba(0, 0, 0, 0.52)); }
38
+ .power-modal[hidden] { display: none; }
39
+ .power-dialog { width: min(34rem, 100%); max-height: calc(100dvh - 48px); overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 18px; border-radius: 16px; border: 1px solid var(--line); background: var(--tile); color: var(--text); font-size: 13px; }
40
+ .power-dialog > h3 { margin: 0; font-size: 18px; font-weight: 600; }
41
+ .power-warn { padding: 10px 12px; border-radius: 10px; background: light-dark(#fff7ed, #3b3024); color: light-dark(#9a3412, #fed7aa); line-height: 1.6; }
42
+ .power-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
43
+ .power-split > div { padding: 10px 12px; border-radius: 10px; background: var(--input); }
44
+ .power-split h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; }
45
+ .power-split .drop h4 { color: light-dark(#b91c1c, #f87171); }
46
+ .power-split .keep h4 { color: light-dark(#0a7d5c, #4ecb9d); }
47
+ .power-split ul { margin: 0; padding-left: 18px; line-height: 1.7; }
48
+ .power-paths summary { width: fit-content; cursor: pointer; color: var(--muted); font-size: 12px; }
49
+ .power-paths pre { margin: 6px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--input); font-size: 12px; line-height: 1.6; }
50
+ @media (max-width: 40rem) { .power-split { grid-template-columns: 1fr; } }
51
+ @media (max-width: 760px) { .power-panel { width: 100%; } }`;
52
+ /** 面板開關:點電源鈕切換,取消/Esc/點面板外關閉。完整移除的對話框開著時不收面板。 */
53
+ exports.powerMenuScript = `
54
+ (function () {
55
+ var toggle = document.querySelector("[data-power-toggle]");
56
+ var panel = document.getElementById("power-panel");
57
+ if (!toggle || !panel) return;
58
+ function setOpen(open) {
59
+ panel.hidden = !open;
60
+ toggle.setAttribute("aria-expanded", open ? "true" : "false");
61
+ if (open) panel.querySelector("[data-power-close]").focus();
62
+ }
63
+ document.addEventListener("click", function (event) {
64
+ var target = event.target;
65
+ if (!target || !target.closest) return;
66
+ if (target.closest("[data-power-toggle]")) { setOpen(panel.hidden); return; }
67
+ if (target.closest("[data-power-close]")) { setOpen(false); toggle.focus(); return; }
68
+ if (!panel.hidden && !target.closest(".power-menu") && !target.closest(".power-modal")) setOpen(false);
69
+ });
70
+ document.addEventListener("keydown", function (event) {
71
+ if (event.key !== "Escape" || panel.hidden) return;
72
+ var modal = document.querySelector(".power-modal");
73
+ if (modal && !modal.hidden) return;
74
+ setOpen(false);
75
+ toggle.focus();
76
+ });
77
+ })();
78
+ `;
package/dist/start.js CHANGED
@@ -21,7 +21,6 @@ const commandRunner_1 = require("./commandRunner");
21
21
  const windowsEnvironment_1 = require("./windowsEnvironment");
22
22
  const windowsEnvironmentSystem_1 = require("./windowsEnvironmentSystem");
23
23
  const exitGuard_1 = require("./exitGuard");
24
- const pagePrototype_1 = require("./pagePrototype");
25
24
  const routeFiles_1 = require("./routeFiles");
26
25
  const responsesChat_1 = require("./responsesChat");
27
26
  const adapterSettings_1 = require("./adapterSettings");
@@ -444,18 +443,13 @@ async function main(instance) {
444
443
  }
445
444
  const parsed = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
446
445
  const pathname = parsed.pathname;
447
- const goHome = (params) => {
446
+ const goHome = () => {
448
447
  if (req.headers["x-classroom-settings"] === "1") {
449
448
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
450
449
  const html = (0, page_1.renderPage)(app.pageView());
451
450
  res.end(instance ? (0, lifecyclePage_1.lifecyclePage)(html, instance.token) : html);
452
451
  return;
453
452
  }
454
- const variant = params?.get("prototype_variant") ?? "";
455
- if (process.env.NODE_ENV !== "production" && (0, pagePrototype_1.isPrototypeVariant)(variant)) {
456
- redirect(res, `/?variant=${variant}`);
457
- return;
458
- }
459
453
  redirect(res);
460
454
  };
461
455
  try {
@@ -486,7 +480,8 @@ async function main(instance) {
486
480
  return;
487
481
  }
488
482
  if (req.method === "GET" && pathname === "/_vanspod/uninstall-preview") {
489
- reply({ ok: true, message: `${await (0, removal_1.removalPreview)()}${(0, exitGuard_1.removalInterruptions)(exitWork())}` });
483
+ const interruptions = (0, exitGuard_1.removalInterruptions)(exitWork());
484
+ reply({ ok: true, message: `${await (0, removal_1.removalPreview)()}${interruptions}`, interruptions: interruptions.trim() });
490
485
  return;
491
486
  }
492
487
  if (req.method === "POST" && (pathname === "/_vanspod/stop" || pathname === "/_vanspod/uninstall")) {
@@ -573,10 +568,7 @@ async function main(instance) {
573
568
  // 版本更新後重新啟動時,舊分頁一拿到首頁就重新整理頁面;
574
569
  // 等 Classroom Connection 恢復、Course Catalog 載入後才給頁面,免得課程安裝停在尚未載入的狀態。
575
570
  await startupSettled;
576
- const variant = parsed.searchParams.get("variant") ?? "";
577
- const html = process.env.NODE_ENV !== "production" && (0, pagePrototype_1.isPrototypeVariant)(variant)
578
- ? (0, pagePrototype_1.renderPrototypePage)(app.pageView(), variant)
579
- : (0, page_1.renderPage)(app.pageView());
571
+ const html = (0, page_1.renderPage)(app.pageView());
580
572
  res.writeHead(200, {
581
573
  "Content-Type": "text/html; charset=utf-8",
582
574
  "Cache-Control": "no-store",
@@ -596,7 +588,7 @@ async function main(instance) {
596
588
  if (req.method === "POST" && pathname === "/redeem") {
597
589
  const params = new URLSearchParams(await readBody(req));
598
590
  await app.redeem(params.get("invite_code") ?? "", params.get("nickname") ?? "");
599
- goHome(params);
591
+ goHome();
600
592
  return;
601
593
  }
602
594
  if (req.method === "POST" && pathname === "/pick-folder") {
@@ -604,7 +596,7 @@ async function main(instance) {
604
596
  const picked = await (0, folderPicker_1.pickProjectFolder)();
605
597
  if (picked)
606
598
  await app.setProjectFolder(picked);
607
- goHome(params);
599
+ goHome();
608
600
  return;
609
601
  }
610
602
  if (req.method === "POST" && pathname === "/project-folder") {
@@ -616,7 +608,7 @@ async function main(instance) {
616
608
  else {
617
609
  app.rejectProjectFolder();
618
610
  }
619
- goHome(params);
611
+ goHome();
620
612
  return;
621
613
  }
622
614
  if (req.method === "POST" && pathname === "/prepare") {
@@ -628,7 +620,7 @@ async function main(instance) {
628
620
  res.end((0, page_1.renderPage)(view));
629
621
  return;
630
622
  }
631
- goHome(params);
623
+ goHome();
632
624
  return;
633
625
  }
634
626
  if (req.method === "POST" && pathname === "/confirm") {
@@ -640,7 +632,7 @@ async function main(instance) {
640
632
  res.end(JSON.stringify({ succeeded: view.commandSucceeded, aborted: view.commandAborted === true, output: view.commandOutput ?? "", installedActionIds: view.installedActionIds ?? [] }));
641
633
  return;
642
634
  }
643
- goHome(params);
635
+ goHome();
644
636
  return;
645
637
  }
646
638
  if (req.method === "POST" && pathname === "/cancel") {
@@ -652,7 +644,7 @@ async function main(instance) {
652
644
  res.end(JSON.stringify({ canceled }));
653
645
  return;
654
646
  }
655
- goHome(params);
647
+ goHome();
656
648
  return;
657
649
  }
658
650
  if (req.method === "POST" && pathname === "/abort-install") {
@@ -663,25 +655,25 @@ async function main(instance) {
663
655
  res.end(JSON.stringify({ aborted: true }));
664
656
  return;
665
657
  }
666
- goHome(params);
658
+ goHome();
667
659
  return;
668
660
  }
669
661
  if (req.method === "POST" && pathname === "/environment-check") {
670
662
  const params = new URLSearchParams(await readBody(req));
671
663
  await app.checkEnvironment();
672
- goHome(params);
664
+ goHome();
673
665
  return;
674
666
  }
675
667
  if (req.method === "POST" && pathname === "/environment-log") {
676
668
  const params = new URLSearchParams(await readBody(req));
677
669
  await app.openEnvironmentLog();
678
- goHome(params);
670
+ goHome();
679
671
  return;
680
672
  }
681
673
  if (req.method === "POST" && pathname === "/open-vscode") {
682
674
  const params = new URLSearchParams(await readBody(req));
683
675
  await app.openVsCode().catch(() => { });
684
- goHome(params);
676
+ goHome();
685
677
  return;
686
678
  }
687
679
  if (req.method === "POST" && pathname === "/environment") {
@@ -693,13 +685,13 @@ async function main(instance) {
693
685
  // 背景安裝:請求立刻回來,頁面輪詢 /environment-status。commandRunning 在 confirmEnvironment 同步開頭就設好,
694
686
  // 轉回首頁時已顯示進行中,exit guard、版本更新與移除也照常看得到這次安裝。
695
687
  void app.confirmEnvironment().catch(() => { });
696
- goHome(params);
688
+ goHome();
697
689
  return;
698
690
  }
699
691
  if (req.method === "POST" && pathname === "/copy") {
700
692
  const params = new URLSearchParams(await readBody(req));
701
693
  await app.copyKey();
702
- goHome(params);
694
+ goHome();
703
695
  return;
704
696
  }
705
697
  if (req.method === "POST" && pathname === "/copy-snippet") {
@@ -712,7 +704,7 @@ async function main(instance) {
712
704
  if (req.method === "POST" && pathname === "/clear") {
713
705
  const params = new URLSearchParams(await readBody(req));
714
706
  await app.clearConnection();
715
- goHome(params);
707
+ goHome();
716
708
  return;
717
709
  }
718
710
  if (req.method === "POST" && pathname === "/switch") {
@@ -727,7 +719,7 @@ async function main(instance) {
727
719
  }
728
720
  await app.setSwitch(mode, client ?? undefined);
729
721
  }
730
- goHome(params);
722
+ goHome();
731
723
  return;
732
724
  }
733
725
  if (req.method === "POST" && pathname === "/adapter") {
@@ -739,14 +731,14 @@ async function main(instance) {
739
731
  return;
740
732
  }
741
733
  await app.setAdapter(client, params.get("adapter") ?? "");
742
- goHome(params);
734
+ goHome();
743
735
  return;
744
736
  }
745
737
  if (req.method === "POST" && pathname === "/reload") {
746
738
  const params = new URLSearchParams(await readBody(req));
747
739
  await app.reloadCatalog();
748
740
  await app.reloadAllowlist();
749
- goHome(params);
741
+ goHome();
750
742
  return;
751
743
  }
752
744
  if ((req.method === "POST" || req.method === "PUT") &&
@@ -803,7 +795,7 @@ async function main(instance) {
803
795
  }
804
796
  const params = new URLSearchParams(await readBody(req));
805
797
  await app.stop();
806
- goHome(params);
798
+ goHome();
807
799
  return;
808
800
  }
809
801
  if (req.method === "POST" && pathname === "/close") {
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "0.4.5";
4
+ exports.VERSION = "0.4.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanspod",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "bin": { "vanspod": "bin/vanspod.cjs" },
5
5
  "engines": { "node": ">=24" },
6
6
  "os": ["win32"],
@@ -1,528 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROTOTYPE_VARIANTS = void 0;
4
- exports.isPrototypeVariant = isPrototypeVariant;
5
- exports.renderPrototypePage = renderPrototypePage;
6
- const page_1 = require("./page");
7
- const PRODUCT = "VansPod";
8
- exports.PROTOTYPE_VARIANTS = ["A", "B", "C", "D"];
9
- const VARIANT_NAME = {
10
- A: "側欄控制台",
11
- B: "設定清單",
12
- C: "工作區",
13
- D: "原本",
14
- };
15
- const SECTIONS = [
16
- { id: "connect", label: "連線" },
17
- { id: "folder", label: "資料夾" },
18
- { id: "model", label: "模型" },
19
- { id: "environment", label: "環境" },
20
- { id: "command", label: "指令" },
21
- { id: "catalog", label: "課程" },
22
- ];
23
- function isPrototypeVariant(value) {
24
- return exports.PROTOTYPE_VARIANTS.includes(value);
25
- }
26
- function stamp(html, variant) {
27
- if (!variant)
28
- return html;
29
- return html.replaceAll(/<form\b([^>]*)>/g, `<form$1><input type="hidden" name="prototype_variant" value="${variant}">`);
30
- }
31
- function stateText(view) {
32
- return JSON.stringify({
33
- connected: view.connected,
34
- mode: view.mode,
35
- modelId: view.modelId ?? null,
36
- classLabel: view.classLabel ?? null,
37
- detail: view.detail,
38
- notice: view.notice ?? null,
39
- projectFolder: view.projectFolder ?? null,
40
- installAvailable: view.installAvailable,
41
- commandRunning: view.commandRunning,
42
- pendingCommand: view.pendingCommand ?? null,
43
- catalogError: view.catalogError ?? null,
44
- actions: view.catalog?.actions.length ?? 0,
45
- snippets: view.catalog?.snippets?.length ?? 0,
46
- tools: view.tools.map((tool) => ({
47
- id: tool.id,
48
- readiness: tool.readiness,
49
- selected: tool.selected,
50
- })),
51
- mustRestart: view.mustRestart ?? [],
52
- }, null, 2);
53
- }
54
- const CSS = `
55
- :root {
56
- color-scheme: light dark;
57
- --bg: light-dark(#ffffff, #212121);
58
- --rail: light-dark(#f9f9f9, #171717);
59
- --surface: light-dark(#ffffff, #262626);
60
- --raised: light-dark(#f4f4f4, #303030);
61
- --border: light-dark(#e6e6e6, #3d3d3d);
62
- --border-soft: light-dark(#f0f0f0, #333333);
63
- --text: light-dark(#0d0d0d, #ececec);
64
- --muted: light-dark(#6e6e6e, #a6a6a6);
65
- --faint: light-dark(#707070, #9a9a9a);
66
- --accent: light-dark(#0d0d0d, #ececec);
67
- --accent-hover: light-dark(#3d3d3d, #ffffff);
68
- --accent-ink: light-dark(#ffffff, #0d0d0d);
69
- --accent-soft: light-dark(rgba(13, 13, 13, 0.06), rgba(255, 255, 255, 0.09));
70
- --accent-ring: light-dark(rgba(0, 0, 0, 0.5), rgba(255, 255, 255, 0.38));
71
- --green: light-dark(#0a7d5c, #4ecb9d);
72
- --green-soft: light-dark(rgba(16, 163, 127, 0.10), rgba(78, 203, 157, 0.13));
73
- --red: light-dark(#b91c1c, #f87171);
74
- --red-soft: light-dark(rgba(185, 28, 28, 0.09), rgba(248, 113, 113, 0.13));
75
- --amber: light-dark(#9a4a08, #fbbf24);
76
- --glass-rail: light-dark(rgba(249, 249, 249, 0.66), rgba(23, 23, 23, 0.62));
77
- --radius: 12px;
78
- --radius-sm: 8px;
79
- --radius-pill: 999px;
80
- --font-ui: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
81
- --font-code: ui-monospace, "Cascadia Code", Consolas, monospace;
82
- }
83
- :root[data-theme="light"] { color-scheme: light; }
84
- :root[data-theme="dark"] { color-scheme: dark; }
85
- * { box-sizing: border-box; }
86
- html, body { margin: 0; min-height: 100%; }
87
- body {
88
- background: transparent;
89
- color: var(--text);
90
- font-family: var(--font-ui);
91
- font-size: 14px;
92
- line-height: 1.5;
93
- }
94
- body::before {
95
- content: "";
96
- position: fixed;
97
- inset: -20%;
98
- z-index: -1;
99
- pointer-events: none;
100
- background:
101
- radial-gradient(42% 38% at 12% 6%, light-dark(rgba(164, 196, 255, 0.42), rgba(96, 130, 200, 0.16)), transparent 70%),
102
- radial-gradient(46% 42% at 88% 18%, light-dark(rgba(168, 226, 197, 0.38), rgba(88, 160, 130, 0.13)), transparent 70%),
103
- radial-gradient(40% 36% at 70% 92%, light-dark(rgba(255, 224, 194, 0.30), rgba(180, 140, 100, 0.08)), transparent 72%),
104
- var(--bg);
105
- filter: blur(70px);
106
- }
107
- button, input { font: inherit; color: inherit; }
108
- button { cursor: pointer; }
109
- button:disabled { opacity: 0.55; cursor: default; }
110
- h1, h2, h3, p { margin: 0; }
111
- pre, code { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font-code); font-size: 12px; }
112
- .hint, .empty, .mode-line { color: var(--muted); font-size: 13px; }
113
- .error, .restart { color: var(--red); font-size: 13px; }
114
- .running { color: var(--green); font-weight: 600; font-size: 13px; }
115
- .detail, .notice, .class-label { font-size: 14px; }
116
- .proto button:not(.nav-item):not(.theme-btn) {
117
- display: inline-flex;
118
- align-items: center;
119
- justify-content: center;
120
- min-height: 34px;
121
- padding: 8px 16px;
122
- border: 1px solid transparent;
123
- border-radius: var(--radius-pill);
124
- background: var(--accent);
125
- color: var(--accent-ink);
126
- font-size: 13px;
127
- font-weight: 500;
128
- }
129
- .proto button.quiet {
130
- background: var(--bg);
131
- color: var(--text);
132
- border-color: var(--border);
133
- }
134
- .proto button.stop {
135
- background: transparent;
136
- color: var(--red);
137
- border-color: transparent;
138
- }
139
- .proto .modes {
140
- display: flex;
141
- gap: 2px;
142
- padding: 2px;
143
- border-radius: var(--radius-pill);
144
- background: var(--raised);
145
- border: 1px solid var(--border);
146
- }
147
- .proto .modes button {
148
- flex: 1;
149
- background: transparent;
150
- color: var(--muted);
151
- border-color: transparent;
152
- }
153
- .proto .modes button.on {
154
- background: var(--accent);
155
- color: var(--accent-ink);
156
- }
157
- .proto input:not([type="checkbox"]):not([type="hidden"]) {
158
- width: 100%;
159
- min-height: 34px;
160
- border: 1px solid var(--border);
161
- border-radius: var(--radius-sm);
162
- background: var(--bg);
163
- padding: 0 10px;
164
- font-size: 13px;
165
- }
166
- .proto label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
167
- .proto form.stack, .proto .tools { display: flex; flex-direction: column; gap: 10px; }
168
- .proto .tool { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
169
- .proto .tool em { margin-left: auto; font-style: normal; color: var(--muted); font-size: 12px; }
170
- .proto table { width: 100%; border-collapse: collapse; }
171
- .proto th, .proto td { text-align: left; vertical-align: top; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--border-soft); }
172
- .proto th { font-size: 12px; font-weight: 500; color: var(--muted); }
173
- .proto .choices { display: flex; gap: 8px; align-items: center; }
174
- .proto .pending, .proto pre {
175
- margin: 0;
176
- padding: 12px;
177
- background: var(--raised);
178
- border: 1px solid var(--border-soft);
179
- border-radius: var(--radius-sm);
180
- }
181
- .badge {
182
- display: inline-flex;
183
- align-items: center;
184
- min-height: 22px;
185
- padding: 0 8px;
186
- border-radius: var(--radius-pill);
187
- background: var(--green-soft);
188
- color: var(--green);
189
- font-size: 12px;
190
- font-weight: 600;
191
- }
192
- .badge.off { background: var(--raised); color: var(--muted); }
193
- .brand-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
194
- .mark {
195
- width: 26px; height: 26px; border-radius: 6px; overflow: hidden; flex: 0 0 auto;
196
- border: 1px solid var(--border); background: var(--surface);
197
- }
198
- .mark img { width: 100%; height: 100%; object-fit: contain; }
199
- .brand-name { font-size: 16px; font-weight: 600; letter-spacing: 0; }
200
- .theme-btn {
201
- width: 34px; height: 34px; padding: 0; border-radius: 999px;
202
- background: var(--surface); color: var(--text); border: 1px solid var(--border);
203
- }
204
- .notices { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 18px; max-width: 70ch; }
205
-
206
- .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
207
- .sidebar {
208
- position: sticky; top: 0; height: 100dvh;
209
- display: flex; flex-direction: column; gap: 4px;
210
- padding: 18px 14px;
211
- border-right: 1px solid var(--border);
212
- background: var(--glass-rail);
213
- backdrop-filter: saturate(1.6) blur(22px);
214
- }
215
- .sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
216
- .nav-item {
217
- display: flex; align-items: center; width: 100%;
218
- padding: 8px 10px; border: 0; border-radius: var(--radius-sm);
219
- background: none; color: var(--muted); font-size: 13px; font-weight: 500;
220
- text-align: left;
221
- }
222
- .nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
223
- .sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
224
- .main { min-width: 0; }
225
- .main-inner { max-width: 980px; margin: 0 auto; padding: 32px 36px 96px; }
226
- .page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
227
- .page-head h2 { font-size: 20px; font-weight: 600; }
228
- .panel { display: none; }
229
- .panel.on { display: block; }
230
-
231
- .sheet { max-width: 880px; margin: 0 auto; padding: 28px 28px 120px; }
232
- .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
233
- .set-list { margin-top: 12px; border-top: 1px solid var(--border); }
234
- .set-row {
235
- display: grid;
236
- grid-template-columns: 180px minmax(0, 1fr);
237
- gap: 20px;
238
- padding: 18px 0;
239
- border-bottom: 1px solid var(--border);
240
- }
241
- .set-label h2 { font-size: 14px; font-weight: 600; }
242
- .set-label p { margin-top: 4px; color: var(--muted); font-size: 12px; }
243
- .sheet-block { padding: 22px 0 8px; }
244
- .sheet-block h2 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
245
-
246
- .workspace { min-height: 100dvh; display: flex; flex-direction: column; }
247
- .topbar {
248
- display: flex; align-items: center; justify-content: space-between; gap: 12px;
249
- padding: 14px 20px; border-bottom: 1px solid var(--border);
250
- background: var(--glass-rail); backdrop-filter: saturate(1.6) blur(22px);
251
- position: sticky; top: 0;
252
- }
253
- .split { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 0; flex: 1; }
254
- .rail-actions { border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
255
- .rail-actions section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface); }
256
- .rail-actions h2 { font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 10px; }
257
- .detail { padding: 20px 24px 110px; min-width: 0; }
258
- .detail h2 { font-size: 12px; font-weight: 500; color: var(--muted); margin: 18px 0 8px; }
259
- .detail h2:first-child { margin-top: 0; }
260
- .terminal { background: var(--rail); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-height: 180px; }
261
-
262
- .proto-bar {
263
- position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
264
- z-index: 80; width: min(440px, calc(100% - 24px));
265
- display: flex; flex-direction: column; gap: 6px; align-items: center;
266
- }
267
- .proto-state {
268
- width: 100%; max-height: 88px; overflow: auto; margin: 0;
269
- padding: 8px 10px; border-radius: 10px;
270
- background: #111; color: #f4f4f4; border: 2px solid #f5c518;
271
- font-size: 10px; line-height: 1.35;
272
- }
273
- .proto-pill {
274
- display: flex; align-items: center; gap: 8px;
275
- padding: 6px 8px; border-radius: 999px;
276
- background: #111; color: #fff; border: 2px solid #f5c518;
277
- box-shadow: 0 8px 24px rgba(0,0,0,0.28);
278
- }
279
- .proto-pill button {
280
- width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 999px;
281
- background: #f5c518; color: #111; border: 0; font-weight: 700;
282
- align-self: auto;
283
- }
284
- .proto-pill span { font-size: 13px; font-weight: 600; min-width: 9rem; text-align: center; }
285
- @media (max-width: 760px) {
286
- .shell, .split, .set-row { grid-template-columns: 1fr; }
287
- .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
288
- .rail-actions { border-right: 0; border-bottom: 1px solid var(--border); }
289
- .main-inner, .sheet { padding-inline: 16px; }
290
- }
291
- @media (prefers-reduced-motion: reduce) {
292
- * { transition: none !important; }
293
- }
294
- `;
295
- function themeButton() {
296
- return `<button type="button" class="theme-btn" data-appearance-toggle aria-label="切換外觀">◐</button>`;
297
- }
298
- function brand() {
299
- return `<div class="brand-row">
300
- <div class="mark"><img src="/brand-logo.png" alt=""></div>
301
- <div class="brand-name">${PRODUCT}</div>
302
- </div>`;
303
- }
304
- function badge(status, connected) {
305
- return `<span class="badge${connected ? "" : " off"}">${status}</span>`;
306
- }
307
- function switcher(variant, state) {
308
- const index = exports.PROTOTYPE_VARIANTS.indexOf(variant);
309
- const prev = exports.PROTOTYPE_VARIANTS[(index + exports.PROTOTYPE_VARIANTS.length - 1) % exports.PROTOTYPE_VARIANTS.length];
310
- const next = exports.PROTOTYPE_VARIANTS[(index + 1) % exports.PROTOTYPE_VARIANTS.length];
311
- return `<div class="proto-bar" data-proto-bar>
312
- <pre class="proto-state">${state.replaceAll("<", "&lt;")}</pre>
313
- <div class="proto-pill">
314
- <button type="button" data-proto-go="${prev}" aria-label="上一個版本">‹</button>
315
- <span>${variant} · ${VARIANT_NAME[variant]}</span>
316
- <button type="button" data-proto-go="${next}" aria-label="下一個版本">›</button>
317
- </div>
318
- </div>`;
319
- }
320
- function variantA(blocks, view, variant) {
321
- const nav = SECTIONS.map((section, index) => `<button type="button" class="nav-item${index === 0 ? " active" : ""}" data-nav="${section.id}">${section.label}</button>`).join("");
322
- const panels = SECTIONS.map((section, index) => {
323
- const body = stamp(blocks[section.id], variant);
324
- return `<section class="panel${index === 0 ? " on" : ""}" data-panel="${section.id}">${body}</section>`;
325
- }).join("");
326
- return `<div class="shell">
327
- <aside class="sidebar">
328
- ${brand()}
329
- <nav aria-label="區段">${nav}</nav>
330
- <div class="sidebar-foot">
331
- ${badge(blocks.status, view.connected)}
332
- ${stamp(blocks.stop, variant)}
333
- ${themeButton()}
334
- </div>
335
- </aside>
336
- <main class="main">
337
- <div class="main-inner">
338
- <div class="page-head">
339
- <h2 data-page-title>連線</h2>
340
- ${badge(blocks.status, view.connected)}
341
- </div>
342
- <div class="notices">${blocks.notices}</div>
343
- ${panels}
344
- </div>
345
- </main>
346
- </div>`;
347
- }
348
- function variantB(blocks, view, variant) {
349
- const rows = [
350
- ["連線", "邀請碼、暱稱,或複製已兌換的 key。", blocks.connect],
351
- ["資料夾", "安裝課程檔案時寫入的專案路徑。", blocks.folder],
352
- ["模型", "Classroom 與 Native 的切換。", blocks.model],
353
- ["環境", "這台電腦還缺哪些工具。", blocks.environment],
354
- ];
355
- const list = rows
356
- .map(([title, hint, body]) => `<section class="set-row">
357
- <div class="set-label"><h2>${title}</h2><p>${hint}</p></div>
358
- <div class="set-control">${stamp(body, variant)}</div>
359
- </section>`)
360
- .join("");
361
- return `<div class="sheet">
362
- <header class="sheet-head">
363
- ${brand()}
364
- <div class="brand-row">${badge(blocks.status, view.connected)}${themeButton()}</div>
365
- </header>
366
- <div class="notices">${blocks.notices}</div>
367
- <div class="set-list">${list}</div>
368
- <section class="sheet-block">
369
- <h2>指令</h2>
370
- ${stamp(blocks.command, variant)}
371
- </section>
372
- <section class="sheet-block">
373
- <h2>課程</h2>
374
- ${stamp(blocks.catalog, variant)}
375
- </section>
376
- <section class="sheet-block">${stamp(blocks.stop, variant)}</section>
377
- </div>`;
378
- }
379
- function variantC(blocks, view, variant) {
380
- const rail = [
381
- ["連線", blocks.connect],
382
- ["資料夾", blocks.folder],
383
- ["模型", blocks.model],
384
- ["環境", blocks.environment],
385
- ]
386
- .map(([title, body]) => `<section><h2>${title}</h2>${stamp(body, variant)}</section>`)
387
- .join("");
388
- return `<div class="workspace">
389
- <header class="topbar">
390
- ${brand()}
391
- <div class="brand-row">${badge(blocks.status, view.connected)}${themeButton()}${stamp(blocks.stop, variant)}</div>
392
- </header>
393
- <div class="notices" style="padding: 12px 20px 0;">${blocks.notices}</div>
394
- <div class="split">
395
- <div class="rail-actions">${rail}</div>
396
- <div class="detail">
397
- <h2>指令</h2>
398
- <div class="terminal">${stamp(blocks.command, variant)}</div>
399
- <h2>課程</h2>
400
- ${stamp(blocks.catalog, variant)}
401
- </div>
402
- </div>
403
- </div>`;
404
- }
405
- function clientScript(variant) {
406
- return `
407
- var appearanceKey = "classroom-appearance";
408
- function systemDark() {
409
- return window.matchMedia("(prefers-color-scheme: dark)").matches;
410
- }
411
- function paintTheme() {
412
- var stored = null;
413
- try { stored = localStorage.getItem(appearanceKey); } catch (error) {}
414
- var appearance = stored === "light" || stored === "dark" ? stored : (systemDark() ? "dark" : "light");
415
- document.documentElement.dataset.theme = appearance;
416
- var button = document.querySelector("[data-appearance-toggle]");
417
- if (button) button.setAttribute("aria-label", appearance === "dark" ? "切換到淺色" : "切換到深色");
418
- }
419
- paintTheme();
420
- document.addEventListener("click", function (event) {
421
- var target = event.target;
422
- if (!target || !target.closest) return;
423
- if (target.closest("[data-appearance-toggle]")) {
424
- var current = document.documentElement.dataset.theme === "dark" ? "dark" : "light";
425
- var next = current === "dark" ? "light" : "dark";
426
- try { localStorage.setItem(appearanceKey, next); } catch (error) {}
427
- paintTheme();
428
- }
429
- var jump = target.closest("[data-proto-go]");
430
- if (jump) {
431
- var url = new URL(location.href);
432
- url.searchParams.set("variant", jump.getAttribute("data-proto-go"));
433
- location.assign(url.pathname + url.search + url.hash);
434
- }
435
- var nav = target.closest("[data-nav]");
436
- if (nav) {
437
- var id = nav.getAttribute("data-nav");
438
- document.querySelectorAll("[data-nav]").forEach(function (item) {
439
- item.classList.toggle("active", item.getAttribute("data-nav") === id);
440
- });
441
- document.querySelectorAll("[data-panel]").forEach(function (panel) {
442
- panel.classList.toggle("on", panel.getAttribute("data-panel") === id);
443
- });
444
- var title = document.querySelector("[data-page-title]");
445
- if (title) title.textContent = nav.textContent;
446
- history.replaceState(null, "", "#" + id);
447
- }
448
- });
449
- var first = (location.hash || "#connect").slice(1);
450
- var start = document.querySelector('[data-nav="' + first + '"]');
451
- if (start) start.click();
452
- window.addEventListener("keydown", function (event) {
453
- var tag = event.target && event.target.tagName;
454
- if (tag === "INPUT" || tag === "TEXTAREA" || (event.target && event.target.isContentEditable)) return;
455
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
456
- var order = ${JSON.stringify(exports.PROTOTYPE_VARIANTS)};
457
- var current = ${JSON.stringify(variant)};
458
- var index = order.indexOf(current);
459
- var step = event.key === "ArrowRight" ? 1 : -1;
460
- var next = order[(index + step + order.length) % order.length];
461
- var url = new URL(location.href);
462
- url.searchParams.set("variant", next);
463
- location.assign(url.pathname + url.search);
464
- });
465
- window.addEventListener("pagehide", function () {
466
- navigator.sendBeacon("/close");
467
- });
468
- `;
469
- }
470
- function variantD(view) {
471
- const html = stamp((0, page_1.renderPage)(view), "D");
472
- const bar = `<style>
473
- .proto-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 80; width: min(440px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 6px; align-items: center; }
474
- .proto-state { width: 100%; max-height: 88px; overflow: auto; margin: 0; padding: 8px 10px; border-radius: 10px; background: #111; color: #f4f4f4; border: 2px solid #f5c518; font-size: 10px; line-height: 1.35; }
475
- .proto-pill { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 999px; background: #111; color: #fff; border: 2px solid #f5c518; box-shadow: 0 8px 24px rgba(0,0,0,0.28); }
476
- .proto-pill button { width: 32px; height: 32px; min-height: 32px; padding: 0; border: 0; border-radius: 999px; background: #f5c518; color: #111; font-weight: 700; }
477
- .proto-pill span { font-size: 13px; font-weight: 600; min-width: 9rem; text-align: center; }
478
- </style>
479
- ${switcher("D", stateText(view))}
480
- <script>
481
- document.addEventListener("click", function (event) {
482
- var target = event.target;
483
- if (!target || !target.closest) return;
484
- var jump = target.closest("[data-proto-go]");
485
- if (!jump) return;
486
- var url = new URL(location.href);
487
- url.searchParams.set("variant", jump.getAttribute("data-proto-go"));
488
- location.assign(url.pathname + url.search);
489
- });
490
- window.addEventListener("keydown", function (event) {
491
- var tag = event.target && event.target.tagName;
492
- if (tag === "INPUT" || tag === "TEXTAREA" || (event.target && event.target.isContentEditable)) return;
493
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
494
- var order = ${JSON.stringify(exports.PROTOTYPE_VARIANTS)};
495
- var index = order.indexOf("D");
496
- var step = event.key === "ArrowRight" ? 1 : -1;
497
- var next = order[(index + step + order.length) % order.length];
498
- var url = new URL(location.href);
499
- url.searchParams.set("variant", next);
500
- location.assign(url.pathname + url.search);
501
- });
502
- </script>`;
503
- return html.replace("</body>", `${bar}</body>`);
504
- }
505
- function renderPrototypePage(view, variant) {
506
- if (variant === "D")
507
- return variantD(view);
508
- const blocks = (0, page_1.classroomBlocks)(view);
509
- const body = variant === "A"
510
- ? variantA(blocks, view, variant)
511
- : variant === "B"
512
- ? variantB(blocks, view, variant)
513
- : variantC(blocks, view, variant);
514
- return `<!DOCTYPE html>
515
- <html lang="zh-Hant">
516
- <head>
517
- <meta charset="utf-8">
518
- <meta name="viewport" content="width=device-width, initial-scale=1">
519
- <title>${PRODUCT}</title>
520
- <style>${CSS}</style>
521
- </head>
522
- <body>
523
- <div class="proto">${body}</div>
524
- ${switcher(variant, stateText(view))}
525
- <script>${clientScript(variant)}</script>
526
- </body>
527
- </html>`;
528
- }