dsh-digital-logic-lectern 0.0.0-stage → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +119 -0
  3. package/README.md +118 -2
  4. package/_selftest.mjs +141 -0
  5. package/cordis.patch.yml +3 -0
  6. package/lib/client.js +274 -0
  7. package/lib/index.js +150 -0
  8. package/locale/en.json +6 -0
  9. package/locale/zh-CN.json +6 -0
  10. package/package.json +78 -5
  11. package/skills/digital-logic-lectern/SKILL.md +115 -0
  12. package/skills/digital-logic-lectern/examples/counter4.v +15 -0
  13. package/skills/digital-logic-lectern/examples/counter4_tb.v +25 -0
  14. package/skills/digital-logic-lectern/references/appendix_verilog.md +32 -0
  15. package/skills/digital-logic-lectern/references/glossary.md +231 -0
  16. package/skills/digital-logic-lectern/references/m1_number_code.md +29 -0
  17. package/skills/digital-logic-lectern/references/m2_boolean_algebra.md +29 -0
  18. package/skills/digital-logic-lectern/references/m3_combinational.md +29 -0
  19. package/skills/digital-logic-lectern/references/m4_sequential.md +29 -0
  20. package/skills/digital-logic-lectern/references/m5_memory.md +29 -0
  21. package/skills/digital-logic-lectern/references/m6_pld_fpga.md +29 -0
  22. package/skills/digital-logic-lectern/references/m7_controller.md +29 -0
  23. package/skills/digital-logic-lectern/references/m8_verilog.md +44 -0
  24. package/skills/digital-logic-lectern/references/textbook/ch1.md +164 -0
  25. package/skills/digital-logic-lectern/references/textbook/ch2.md +171 -0
  26. package/skills/digital-logic-lectern/references/textbook/ch3.md +130 -0
  27. package/skills/digital-logic-lectern/references/textbook/ch4.md +91 -0
  28. package/skills/digital-logic-lectern/references/textbook/ch5.md +121 -0
  29. package/skills/digital-logic-lectern/references/textbook/ch6.md +138 -0
  30. package/skills/digital-logic-lectern/references/textbook/ch7.md +73 -0
  31. package/skills/digital-logic-lectern/references/textbook_map.md +33 -0
  32. package/skills/digital-logic-lectern/scripts/dlbook.js +243 -0
  33. package/skills/digital-logic-lectern/scripts/dlquiz.js +1069 -0
  34. package/skills/digital-logic-lectern/scripts/dltool.js +658 -0
  35. package/skills/digital-logic-lectern/scripts/dlverify.js +125 -0
  36. package/skills/digital-logic-lectern/ui/book.js +1472 -0
  37. package/skills/digital-logic-lectern/ui/bupt-logo.png +0 -0
  38. package/skills/digital-logic-lectern/ui/index.html +1324 -0
  39. package/skills/digital-logic-lectern/ui/questions.js +1448 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-digital-logic-lectern contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,119 @@
1
+ # 数字逻辑辅助学习插件
2
+
3
+ npm package: `dsh-digital-logic-lectern`
4
+
5
+ Author: Liu Baiming(刘柏铭)|[中文](README.md)
6
+
7
+ A study and practice plugin for the Digital Logic course, built for DeepSeek Harness. It follows the table of contents of *Digital Logic* (7th edition), edited by Bai Zhongying and Zhu Zhengdong, Science Press, 2020. The notes are written against that outline; they are not a copy of the textbook.
8
+
9
+ The plugin ships one skill and one web page. The skill explains concepts, walks through derivations, checks numeric results with a command-line tool, and draws practice questions from the course bank. The page holds the notes, chapter quizzes, human-vs-AI matches, and a wrong-answer list. The page can open inside the DSH app.
10
+
11
+ ## Install
12
+
13
+ From npm:
14
+
15
+ ```bash
16
+ npm install dsh-digital-logic-lectern
17
+ ```
18
+
19
+ Or enter the package name `dsh-digital-logic-lectern` in the Harness add-plugin dialog. A Git URL also works:
20
+
21
+ ```
22
+ https://github.com/MoroboshiAo/dsh-digital-logic-lectern.git
23
+ ```
24
+
25
+ The Git route clones the repository before installing, so git and network access are required. The repository is public. The three routes are equivalent: npm name, Git URL, local directory or tgz.
26
+
27
+ ```bash
28
+ dsh plugin --profile <profile> add file:/absolute/path/dsh-digital-logic-lectern-0.6.4.tgz
29
+ ```
30
+
31
+ Copying `skills/digital-logic-lectern` into `~/.dsh/skills/` works too. Pick one route; installing twice makes the two copies of the same skill shadow each other. Restart the client afterwards.
32
+
33
+ ## Open the page
34
+
35
+ Three entry points inside the app:
36
+
37
+ - The 「数字逻辑」 icon at the bottom of the sidebar opens the page full screen.
38
+ - Send `/logic-lectern` from the input box.
39
+ - Find the plugin row on the Plugins page and press 「在应用内打开」.
40
+
41
+ The plugin row also has a default difficulty (easy / normal / hard) and a sidebar-entry switch, both stored locally. If the sidebar icon is off, the command and the plugin row still open the page. The default difficulty only preselects a level when a quiz starts.
42
+
43
+ The client panel requires DSH 0.2.1-rc.2 or newer. Older hosts register the skill only; the page still works when opened directly in a browser.
44
+
45
+ To open it in a browser, generate the page data first:
46
+
47
+ ```bash
48
+ cd skills/digital-logic-lectern
49
+ node scripts/dlbook.js --build # notes -> page data
50
+ node scripts/dlquiz.js --build # generate 80 questions and verify answers
51
+ start ui/index.html
52
+ ```
53
+
54
+ The repository already contains generated `ui/book.js` and `ui/questions.js`. Re-run both commands after editing `references/`. `dlquiz --build` checks every calculation question with `dltool` and refuses to write if an answer disagrees. Use `--seed <number>` for another batch or `--count <number>` for a different size.
55
+
56
+ ## The page
57
+
58
+ The square button at the top right cycles follow-system, light, and dark; the choice is stored locally.
59
+
60
+ **Study.** Chapters 1 to 7, plus a Verilog appendix and a glossary. The contents tree goes down to subsection level, the search box covers headings and body text, and every glossary row links to its subsection. The footer carries the textbook title, editors, publisher, edition, and the plugin version.
61
+
62
+ **Quiz.** Pick a chapter, a mode, and a question count. Human-vs-AI mode adds a difficulty level:
63
+
64
+ | Level | Base accuracy | Answer delay | Points per correct answer |
65
+ | --- | --- | --- | --- |
66
+ | Easy | 58% | 3.3–5.5 s | 60 |
67
+ | Normal | 80% | 2.5–4.2 s | 100 |
68
+ | Hard | 93% | 1.7–2.8 s | 150 |
69
+
70
+ Harder questions lower the AI's accuracy and shorten its delay a little further. Answer with the mouse or keys 1 to 4; Enter moves on.
71
+
72
+ **Review.** Wrong answers are collected automatically and can be redone. Data stays in the browser's local storage.
73
+
74
+ ## Command-line tools
75
+
76
+ | Command | Purpose |
77
+ | --- | --- |
78
+ | `node scripts/dltool.js` | Base conversion, sign-magnitude / ones' / two's complement, offset binary, Gray code, BCD, truth tables, Karnaugh maps, Hamming codes |
79
+ | `node scripts/dlquiz.js` | Generate questions and verify calculation answers with `dltool` |
80
+ | `node scripts/dlbook.js` | Turn `references/` into page data |
81
+ | `node scripts/dlverify.js` | Run simulations through iverilog |
82
+
83
+ Bit patterns and numeric results come from these outputs, not from mental arithmetic.
84
+
85
+ ## Layout
86
+
87
+ ```
88
+ skills/digital-logic-lectern/
89
+ ├── SKILL.md skill: study-card structure, tool rules, module index, limits
90
+ ├── references/ eight module cards, seven chapters, glossary, textbook map
91
+ │ ├── textbook/ ch1 to ch7, following textbook sections and subsections
92
+ │ └── appendix_verilog.md Verilog appendix, not in the textbook
93
+ ├── scripts/
94
+ │ ├── dltool.js bases, codes, truth tables, Karnaugh maps, Hamming codes
95
+ │ ├── dlquiz.js generate questions and verify them
96
+ │ ├── dlbook.js build page data from references
97
+ │ └── dlverify.js run iverilog simulations
98
+ ├── ui/ three-tab page: index.html, book.js, questions.js, bupt-logo.png
99
+ └── examples/ counter example source
100
+ lib/index.js plugin entry: register the skill, serve ui/ over static routes
101
+ lib/client.js client entry: sidebar icon, main panel, plugin-row options, slash command
102
+ locale/ Chinese and English title and summary for the plugin list
103
+ cordis.patch.yml patch file required by the plugin manifest
104
+ ```
105
+
106
+ ## Question bank
107
+
108
+ 80 questions across the eight modules. Calculation questions are generated by `dlquiz.js` and every answer is checked against `dltool`; concept questions are written from the topics covered by the textbook exercises and the companion answer set, and have not been reviewed question by question by an instructor. Exercise answers in this course rely heavily on figures and formulas, so the repository keeps the numeric and text questions that can be verified in a terminal rather than reproducing the original figures.
109
+
110
+ ## Limits
111
+
112
+ - The notes follow the outline of *Digital Logic* (7th edition, Bai Zhongying and Zhu Zhengdong, Science Press, 2020). They are not the publisher's text. Section numbers were checked against the slide deck that ships with that edition; the mapping is in `references/textbook_map.md`. Section 5.5 of the textbook covers VHDL, while this course uses Verilog; the notes point out the difference.
113
+ - The in-app page is an iframe over the same static page, so the review list and options live in the host page's local storage. Clearing site data or switching browsers loses them.
114
+ - Simulation requires iverilog. Without it `dlverify.js` fails loudly and prints install instructions; simulation results then have to be marked unverified.
115
+ - Coverage is limited to the eight course modules. Analog circuits and lab-bench procedures are out of scope.
116
+
117
+ ## License
118
+
119
+ MIT, by Liu Baiming(刘柏铭). The textbook *Digital Logic* (7th edition, Bai Zhongying and Zhu Zhengdong, Science Press, 2020) remains under its publisher's copyright; this repository only maps terminology and chapter structure. The BUPT emblem in the page header belongs to the university and is used as a course mark only.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # 数字逻辑辅助学习插件
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ npm 包名:`dsh-digital-logic-lectern`
4
+
5
+ 作者:刘柏铭(Liu Baiming)|[English](README.en.md)
6
+
7
+ 面向《数字逻辑》(第七版,白中英、朱正东主编,科学出版社,2020 年)的学习与练习插件,用于 DeepSeek Harness。插件提供一套课程知识库、一份 80 题的题库和一个网页界面;知识库按该教材目录自编,不是教材原文。
8
+
9
+ 插件包含一个技能和一个网页。技能负责解释概念、分步推导、核对计算结果、按教材范围出练习;网页负责看讲义、做章节自测、人机对战、收错题。网页可以在 DSH 应用内直接打开。
10
+
11
+ ## 安装
12
+
13
+ 从 npm 安装:
14
+
15
+ ```bash
16
+ npm install dsh-digital-logic-lectern
17
+ ```
18
+
19
+ 或在 DSH 的添加插件对话框中填包名 `dsh-digital-logic-lectern`。也可以填 Git 地址:
20
+
21
+ ```
22
+ https://github.com/MoroboshiAo/dsh-digital-logic-lectern.git
23
+ ```
24
+
25
+ Git 方式会克隆仓库再安装,需要本机有 git 与网络。仓库已公开,不需要凭据。三种写法等价:npm 包名、Git 地址、本地目录或 tgz。
26
+
27
+ ```bash
28
+ dsh plugin --profile <profile> add file:/absolute/path/dsh-digital-logic-lectern-0.6.4.tgz
29
+ ```
30
+
31
+ 也可以把 `skills/digital-logic-lectern` 复制到 `~/.dsh/skills/`。几种方式只选一种,重复安装会让同名技能互相遮蔽。安装后重启客户端。
32
+
33
+ ## 打开页面
34
+
35
+ 应用内三个入口:
36
+
37
+ - 侧栏底部的「数字逻辑」图标,整页打开。
38
+ - 输入框发 `/logic-lectern`。
39
+ - 插件页的插件行,按「在应用内打开」。
40
+
41
+ 插件行还有两个选项:默认难度(简单 / 普通 / 困难)与侧栏入口开关,保存在本地。关掉侧栏图标后,命令和插件行仍可打开页面。默认难度只决定开始自测时预选哪一档,进入后仍可改。
42
+
43
+ 客户端面板需要 DSH 0.2.1-rc.2 或更新版本;旧版本只注册技能,网页在浏览器里打开同样可用。
44
+
45
+ 浏览器打开前先生成页面数据:
46
+
47
+ ```bash
48
+ cd skills/digital-logic-lectern
49
+ node scripts/dlbook.js --build # 讲义 → 页面数据
50
+ node scripts/dlquiz.js --build # 生成 80 题并复核计算题
51
+ start ui/index.html
52
+ ```
53
+
54
+ 仓库里已带生成好的 `ui/book.js` 与 `ui/questions.js`。改过 `references/` 后重跑这两条命令。`dlquiz --build` 会用 `dltool` 逐题复核计算题,答案不一致就拒绝写入;`--seed <数字>` 可换一批题,`--count <数字>` 可改题量。
55
+
56
+ ## 页面
57
+
58
+ 右上角方形按钮循环切换跟随系统、浅色、深色,选择保存在本地。
59
+
60
+ **学习。** 第一章到第七章,加 Verilog 附录与术语表。左侧目录可展开到小节(例如 1.1 → 1.1.1),搜索框同时搜标题与正文,术语表每一行都能跳到对应小节。页脚注明教材全名、主编、出版社、版次与版本号。
61
+
62
+ **自测。** 选章节、模式与题数后开始。人机对战有三档难度:
63
+
64
+ | 难度 | 基础正确率 | 答题延迟 | 每题得分 |
65
+ | --- | --- | --- | --- |
66
+ | 简单 | 58% | 3.3–5.5 秒 | 60 |
67
+ | 普通 | 80% | 2.5–4.2 秒 | 100 |
68
+ | 困难 | 93% | 1.7–2.8 秒 | 150 |
69
+
70
+ 题目越难,AI 正确率越低、延迟越短。鼠标点选或按 1–4 作答,回车进入下一题。
71
+
72
+ **错题本。** 答错自动收录,可重做、单条移除、整体清空。数据存在浏览器本地。
73
+
74
+ ## 命令行工具
75
+
76
+ | 命令 | 用途 |
77
+ | --- | --- |
78
+ | `node scripts/dltool.js` | 进制转换、原码/反码/补码、移码、格雷码、BCD、真值表、卡诺图、海明码 |
79
+ | `node scripts/dlquiz.js` | 生成题库并用 `dltool` 复核计算题 |
80
+ | `node scripts/dlbook.js` | 把 `references/` 转成页面数据 |
81
+ | `node scripts/dlverify.js` | 通过 iverilog 跑 Verilog 仿真 |
82
+
83
+ 回答里的位模式与计算结果都取自这些命令的输出,不靠口算。
84
+
85
+ ## 目录
86
+
87
+ ```
88
+ skills/digital-logic-lectern/
89
+ ├── SKILL.md 技能定义:学习卡结构、工具规则、模块索引、红线
90
+ ├── references/ 八个模块卡、七章讲义、术语表、教材对照表
91
+ │ ├── textbook/ ch1 到 ch7,按教材章节与小节编排
92
+ │ └── appendix_verilog.md Verilog 附录,教材外补充
93
+ ├── scripts/
94
+ │ ├── dltool.js 进制、编码、真值表、卡诺图、海明码
95
+ │ ├── dlquiz.js 生成题库并复核
96
+ │ ├── dlbook.js 由 references 生成页面数据
97
+ │ └── dlverify.js 调用 iverilog 跑仿真
98
+ ├── ui/ 三栏页面:index.html、book.js、questions.js、bupt-logo.png
99
+ └── examples/ 计数器示例源码
100
+ lib/index.js 插件入口:注册技能,提供网页静态路由
101
+ lib/client.js 客户端入口:侧栏图标、主面板、插件行选项、斜杠命令
102
+ locale/ 插件列表中的中英文名称与简介
103
+ cordis.patch.yml 插件清单要求的补丁文件
104
+ ```
105
+
106
+ ## 题库
107
+
108
+ 80 题,覆盖八个模块。计算题由 `dlquiz.js` 随机生成,答案经 `dltool` 复核;概念题按教材习题范围与配套答案整理的考点手写,未逐题送教师审阅。数字逻辑的习题答案涉及大量图形与公式,本仓库不复刻原题图片,只保留可在终端复核的数值题与文字题。
109
+
110
+ ## 限制
111
+
112
+ - 讲义按《数字逻辑》(第七版)目录自编,不是出版社原文。章节号已按该版配套课件核对,对照表在 `references/textbook_map.md`。教材 5.5 节用 VHDL,本课程用 Verilog,讲义会指出差异。
113
+ - 网页是宿主面板里的 iframe,错题与选项存在宿主页面的 localStorage;清除站点数据或换浏览器会丢失。
114
+ - Verilog 仿真需要本机安装 iverilog。没装时 `dlverify.js` 会直接报错并给出安装指引,不会伪造结果;此时任何仿真结论只能标「未验证」。
115
+ - 范围限于八个课程模块,模拟电路与实验台操作不在内。
116
+
117
+ ## 许可
118
+
119
+ MIT,作者刘柏铭(Liu Baiming)。《数字逻辑》(第七版,白中英、朱正东主编,科学出版社,2020 年)版权归出版社所有,本仓库只做术语与章节结构的对照。页面左上角北京邮电大学校徽归学校所有,仅作课程标识。
package/_selftest.mjs ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * 用 mock 的 ctx 验证服务端与客户端入口:
3
+ * - 能发现 SKILL.md、能注册、resourceBase 正确、正文已剥离 frontmatter;
4
+ * - webServer 上挂了四个静态路由;
5
+ * - 客户端注册侧栏图标、主页面板、插件行选项与斜杠命令。
6
+ * 运行:node _selftest.mjs
7
+ */
8
+
9
+ import assert from "node:assert/strict";
10
+ import { readFileSync, existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { apply, inject, name } from "./lib/index.js";
13
+
14
+ const registered = [];
15
+ const routes = [];
16
+ let effectRan = false;
17
+
18
+ const ctx = {
19
+ skills: {
20
+ register(skill) {
21
+ registered.push(skill);
22
+ return () => {};
23
+ },
24
+ },
25
+ effect(factory) {
26
+ effectRan = true;
27
+ factory();
28
+ },
29
+ inject(names, callback) {
30
+ assert.deepEqual(names, ["webServer"], "只应注入 webServer");
31
+ callback({
32
+ get(key) {
33
+ assert.equal(key, "webServer");
34
+ return {
35
+ register(route) {
36
+ routes.push(route);
37
+ return () => {};
38
+ },
39
+ };
40
+ },
41
+ effect(factory) {
42
+ factory();
43
+ },
44
+ });
45
+ },
46
+ };
47
+
48
+ assert.equal(name, "dsh-digital-logic-lectern");
49
+ assert.deepEqual(inject, ["skills"]);
50
+
51
+ apply(ctx);
52
+
53
+ assert.ok(effectRan, "ctx.effect 应该被调用,用于绑定生命周期");
54
+ assert.equal(registered.length, 1, `应注册 1 个技能,实际 ${registered.length}`);
55
+
56
+ const skill = registered[0];
57
+ assert.equal(skill.name, "digital-logic-lectern");
58
+ assert.ok(skill.description.length > 20, "description 不能为空或过短");
59
+ assert.ok(skill.whenToUse.length > 10, "whenToUse 应存在");
60
+ assert.equal(skill.source, "dsh-digital-logic-lectern");
61
+ assert.ok(!skill.content.startsWith("---"), "正文不应包含 frontmatter");
62
+ assert.ok(skill.content.includes("学习卡"), "正文应是 SKILL.md 的主体");
63
+ assert.equal(skill.resourceBase.kind, "directory");
64
+ assert.ok(existsSync(join(skill.resourceBase.path, "scripts", "dltool.js")), "resourceBase 下应有 scripts/dltool.js");
65
+ assert.ok(existsSync(join(skill.resourceBase.path, "references", "m1_number_code.md")), "references 应完整");
66
+ assert.equal(skill.metadata.author, "刘柏铭(Liu Baiming)");
67
+
68
+ assert.equal(routes.length, 4, `应挂 4 个静态路由,实际 ${routes.length}`);
69
+ assert.deepEqual(
70
+ routes.map((route) => route.path).sort(),
71
+ [
72
+ "/dsh-digital-logic-lectern/book.js",
73
+ "/dsh-digital-logic-lectern/bupt-logo.png",
74
+ "/dsh-digital-logic-lectern/index.html",
75
+ "/dsh-digital-logic-lectern/questions.js",
76
+ ]
77
+ );
78
+
79
+ /* ---------- 客户端 ---------- */
80
+
81
+ let definition = null;
82
+ const clientCode = readFileSync(new URL("./lib/client.js", import.meta.url), "utf8");
83
+ new Function("window", clientCode)({
84
+ __ModuleLoader__: {
85
+ load(value) {
86
+ definition = value;
87
+ },
88
+ },
89
+ });
90
+ assert.ok(definition !== null, "客户端应通过 __ModuleLoader__ 注册");
91
+ assert.equal(definition.id, "dsh-digital-logic-lectern");
92
+
93
+ const clientModule = definition.factory((id) => {
94
+ if (id === "react") return { useState: (value) => [value, () => {}] };
95
+ return { jsx: () => null, jsxs: () => null };
96
+ });
97
+
98
+ const slots = [];
99
+ let commands = 0;
100
+ clientModule.apply({
101
+ slots: {
102
+ inject(slotName, callback) {
103
+ callback();
104
+ },
105
+ register(config) {
106
+ slots.push(config.name);
107
+ return () => {};
108
+ },
109
+ },
110
+ inject(names, callback) {
111
+ assert.deepEqual(names, ["commandUi"]);
112
+ callback({
113
+ effect(factory) {
114
+ factory();
115
+ },
116
+ get() {
117
+ return {
118
+ register() {
119
+ commands += 1;
120
+ return () => {};
121
+ },
122
+ };
123
+ },
124
+ });
125
+ },
126
+ get() {
127
+ return { selectPanel() {} };
128
+ },
129
+ });
130
+
131
+ assert.deepEqual(clientModule.inject, ["slots", "commandUi"]);
132
+ assert.deepEqual(
133
+ slots.sort(),
134
+ ["main", "plugins.bundle.config", "plugins.row.config", "sidebar.panellist"],
135
+ "客户端应占满四个 slot"
136
+ );
137
+ assert.equal(commands, 1, "应有 1 个斜杠命令");
138
+
139
+ console.log(`自检通过:注册 ${registered.length} 个技能(${registered.map((item) => item.name).join(", ")})`);
140
+ console.log(`resourceBase:${skill.resourceBase.path}`);
141
+ console.log(`静态路由:${routes.length} 个;客户端 slot:${slots.join(", ")};命令:${commands} 个`);
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: digital-logic-lectern
3
+ name: dsh-digital-logic-lectern
package/lib/client.js ADDED
@@ -0,0 +1,274 @@
1
+ /**
2
+ * dsh-digital-logic-lectern —— 客户端入口(浏览器侧)
3
+ *
4
+ * 把数字逻辑辅助学习插件接进 DSH 界面:
5
+ * - 侧栏图标 + 主页面板:点开后整页嵌入 ui/index.html(由 lib/index.js 挂在
6
+ * /dsh-digital-logic-lectern/ 下),页面原样运行,错题本等本地数据照旧。
7
+ * - 斜杠命令 /logic-lectern:从输入框直接唤出面板。
8
+ * - 插件行配置:在「插件」页里给默认难度与侧栏入口两个选项。
9
+ *
10
+ * 这个文件不参与构建,直接手写;宿主用 __ModuleLoader__ 加载。
11
+ */
12
+
13
+ window.__ModuleLoader__.load({
14
+ id: "dsh-digital-logic-lectern",
15
+ factory: (require) => {
16
+ var module = { exports: {} };
17
+ var exports = module.exports;
18
+
19
+ const react = require("react");
20
+ const jsx = require("react/jsx-runtime");
21
+
22
+ const PANEL_ID = "dsh-digital-logic-lectern";
23
+ const PAGE_PATH = "dsh-digital-logic-lectern/index.html";
24
+ const OPTIONS_KEY = "dll-options";
25
+ const LEVELS = [
26
+ { id: 1, label: "简单" },
27
+ { id: 2, label: "普通" },
28
+ { id: 3, label: "困难" },
29
+ ];
30
+ const DEFAULT_OPTIONS = { level: 2, sidebar: true };
31
+
32
+ const CSS = [
33
+ ".dll-card{font-family:-apple-system,\"PingFang SC\",\"Microsoft YaHei\",\"Segoe UI\",system-ui,sans-serif;display:flex;flex-direction:column;gap:12px;padding:14px 16px;border:1px solid rgba(0,0,0,.08);border-radius:12px;background:rgba(255,255,255,.6)}",
34
+ ".dll-head{display:flex;align-items:center;gap:10px}",
35
+ ".dll-mark{width:28px;height:28px;flex:0 0 auto;display:grid;place-items:center;border-radius:8px;background:#e9f9dc;color:#46a302}",
36
+ ".dll-mark svg{width:17px;height:17px}",
37
+ ".dll-title{flex:1;font-size:14px;font-weight:600;color:inherit}",
38
+ ".dll-open{border:1px solid rgba(0,0,0,.12);border-radius:9px;background:transparent;color:inherit;font:inherit;font-size:13px;padding:6px 12px;cursor:pointer}",
39
+ ".dll-open:hover{background:rgba(0,0,0,.04)}",
40
+ ".dll-row{display:flex;align-items:center;gap:12px;font-size:13px}",
41
+ ".dll-label{min-width:64px;opacity:.6}",
42
+ ".dll-chips{display:flex;gap:6px;flex-wrap:wrap}",
43
+ ".dll-chip{border:1px solid rgba(0,0,0,.12);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:12.5px;padding:5px 11px;cursor:pointer}",
44
+ ".dll-chip.on{border-color:#1cb0f6;background:rgba(28,176,246,.12);color:#0b7fb3;font-weight:600}",
45
+ ".dll-switch{position:relative;width:38px;height:22px;flex:0 0 auto;border:none;border-radius:999px;background:rgba(0,0,0,.18);cursor:pointer;padding:0}",
46
+ ".dll-switch i{position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:#fff;transition:transform .15s ease}",
47
+ ".dll-switch.on{background:#58cc02}",
48
+ ".dll-switch.on i{transform:translateX(16px)}",
49
+ ".dll-page{height:100%;min-height:0;display:flex}",
50
+ ".dll-frame{flex:1;width:100%;height:100%;border:0;background:#f7f8fa}",
51
+ "@media (prefers-color-scheme:dark){.dll-card{border-color:rgba(255,255,255,.12);background:rgba(30,30,32,.6)}.dll-open:hover{background:rgba(255,255,255,.08)}.dll-chip.on{color:#5cc8ff}}",
52
+ ].join("");
53
+
54
+ const ICON_GATE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8.5h4M3 15.5h4M18 12h3"/><path d="M7 5.5h4.5a6.5 6.5 0 0 1 0 13H7z"/></svg>';
55
+
56
+ /** 页面的绝对地址;按宿主页面的 base 解析,反代前缀也能带上。 */
57
+ function pageUrl() {
58
+ try {
59
+ return new URL(PAGE_PATH, document.baseURI).toString();
60
+ } catch {
61
+ return "/" + PAGE_PATH;
62
+ }
63
+ }
64
+
65
+ function readOptions() {
66
+ try {
67
+ const raw = localStorage.getItem(OPTIONS_KEY);
68
+ const parsed = raw === null ? null : JSON.parse(raw);
69
+ if (parsed === null || typeof parsed !== "object") return { ...DEFAULT_OPTIONS };
70
+ const level = LEVELS.some((item) => item.id === parsed.level) ? parsed.level : DEFAULT_OPTIONS.level;
71
+ return { level, sidebar: parsed.sidebar !== false };
72
+ } catch {
73
+ return { ...DEFAULT_OPTIONS };
74
+ }
75
+ }
76
+
77
+ let currentOptions = readOptions();
78
+ /** 由 apply 填上,供按钮和命令共用。 */
79
+ let host = { openPanel: () => false };
80
+
81
+ function writeOptions(next) {
82
+ currentOptions = next;
83
+ try {
84
+ localStorage.setItem(OPTIONS_KEY, JSON.stringify(next));
85
+ } catch {
86
+ // 隐私模式下写不进去,本次会话仍然生效。
87
+ }
88
+ }
89
+
90
+ function installCss() {
91
+ if (typeof document === "undefined") return;
92
+ const tagId = "dsh-digital-logic-lectern/client.css";
93
+ if (document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") !== null) return;
94
+ const tag = document.createElement("style");
95
+ tag.dataset.plugin = "dsh-digital-logic-lectern";
96
+ tag.dataset.pluginCss = tagId;
97
+ tag.textContent = CSS;
98
+ document.head.appendChild(tag);
99
+ }
100
+
101
+ function openInBrowser() {
102
+ try {
103
+ window.open(pageUrl(), "_blank", "noopener");
104
+ } catch {
105
+ // 弹窗被拦时什么也不做,面板按钮本身已经够用。
106
+ }
107
+ }
108
+
109
+ function LecternPage() {
110
+ return jsx.jsx("div", {
111
+ className: "dll-page",
112
+ children: jsx.jsx("iframe", {
113
+ className: "dll-frame",
114
+ src: pageUrl(),
115
+ title: "数字逻辑辅助学习插件",
116
+ }),
117
+ });
118
+ }
119
+
120
+ function SidebarIcon() {
121
+ return jsx.jsx("svg", {
122
+ width: 18,
123
+ height: 18,
124
+ viewBox: "0 0 24 24",
125
+ fill: "none",
126
+ "aria-hidden": "true",
127
+ children: [
128
+ jsx.jsx("path", { d: "M3 8.5h4M3 15.5h4M18 12h3", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" }, "wires"),
129
+ jsx.jsx("path", { d: "M7 5.5h4.5a6.5 6.5 0 0 1 0 13H7z", stroke: "currentColor", strokeWidth: "1.8", strokeLinejoin: "round" }, "gate"),
130
+ ],
131
+ });
132
+ }
133
+
134
+ function LecternCard() {
135
+ const [options, setOptions] = react.useState(currentOptions);
136
+ const update = (patch) => {
137
+ const next = { ...currentOptions, ...patch };
138
+ writeOptions(next);
139
+ setOptions(next);
140
+ if ("sidebar" in patch) host.syncSidebar();
141
+ };
142
+ const open = () => {
143
+ if (!host.openPanel()) openInBrowser();
144
+ };
145
+ return jsx.jsxs("div", {
146
+ className: "dll-card",
147
+ children: [
148
+ jsx.jsxs("div", {
149
+ className: "dll-head",
150
+ children: [
151
+ jsx.jsx("span", { className: "dll-mark", dangerouslySetInnerHTML: { __html: ICON_GATE } }),
152
+ jsx.jsx("span", { className: "dll-title", children: "数字逻辑辅助学习插件" }),
153
+ jsx.jsx("button", { type: "button", className: "dll-open", onClick: open, children: "在应用内打开" }),
154
+ ],
155
+ }),
156
+ jsx.jsxs("div", {
157
+ className: "dll-row",
158
+ children: [
159
+ jsx.jsx("span", { className: "dll-label", children: "默认难度" }),
160
+ jsx.jsx("div", {
161
+ className: "dll-chips",
162
+ children: LEVELS.map((level) =>
163
+ jsx.jsx("button", {
164
+ type: "button",
165
+ className: "dll-chip" + (options.level === level.id ? " on" : ""),
166
+ "aria-pressed": options.level === level.id,
167
+ onClick: () => update({ level: level.id }),
168
+ children: level.label,
169
+ }, level.id)
170
+ ),
171
+ }),
172
+ ],
173
+ }),
174
+ jsx.jsxs("div", {
175
+ className: "dll-row",
176
+ children: [
177
+ jsx.jsx("span", { className: "dll-label", children: "侧栏入口" }),
178
+ jsx.jsx("button", {
179
+ type: "button",
180
+ role: "switch",
181
+ "aria-checked": options.sidebar,
182
+ className: "dll-switch" + (options.sidebar ? " on" : ""),
183
+ onClick: () => update({ sidebar: !options.sidebar }),
184
+ children: jsx.jsx("i", {}),
185
+ }),
186
+ ],
187
+ }),
188
+ ],
189
+ });
190
+ }
191
+
192
+ const inject = ["slots", "commandUi"];
193
+
194
+ function apply(ctx) {
195
+ installCss();
196
+
197
+ host.openPanel = () => {
198
+ try {
199
+ const layout = ctx.get("layout");
200
+ if (layout && typeof layout.selectPanel === "function") {
201
+ layout.selectPanel(PANEL_ID);
202
+ return true;
203
+ }
204
+ } catch {
205
+ // 旧宿主没有 layout 服务。
206
+ }
207
+ return false;
208
+ };
209
+
210
+ // 侧栏图标按选项挂载;关掉之后仍可从 /logic-lectern 或插件行打开。
211
+ let seatReady = false;
212
+ let entryDispose = null;
213
+ const syncSidebar = () => {
214
+ if (!seatReady) return;
215
+ if (currentOptions.sidebar && entryDispose === null) {
216
+ entryDispose = ctx.slots.register(
217
+ { name: "sidebar.panellist", id: PANEL_ID, order: 35, label: () => "数字逻辑" },
218
+ SidebarIcon
219
+ );
220
+ } else if (!currentOptions.sidebar && entryDispose !== null) {
221
+ entryDispose();
222
+ entryDispose = null;
223
+ }
224
+ };
225
+ host.syncSidebar = syncSidebar;
226
+
227
+ ctx.slots.inject("sidebar.panellist", () => {
228
+ seatReady = true;
229
+ syncSidebar();
230
+ return () => {
231
+ seatReady = false;
232
+ if (entryDispose !== null) {
233
+ entryDispose();
234
+ entryDispose = null;
235
+ }
236
+ };
237
+ });
238
+
239
+ ctx.slots.inject("main", () =>
240
+ ctx.slots.register({ name: "main", key: PANEL_ID }, LecternPage)
241
+ );
242
+
243
+ ctx.slots.inject("plugins.row.config", () =>
244
+ ctx.slots.register(
245
+ { name: "plugins.row.config", key: "dsh-digital-logic-lectern#digital-logic-lectern" },
246
+ LecternCard
247
+ )
248
+ );
249
+
250
+ ctx.slots.inject("plugins.bundle.config", () =>
251
+ ctx.slots.register(
252
+ { name: "plugins.bundle.config", key: "dsh-digital-logic-lectern" },
253
+ LecternCard
254
+ )
255
+ );
256
+
257
+ ctx.inject(["commandUi"], (sctx) => {
258
+ sctx.effect(() => {
259
+ const dispose = sctx.get("commandUi").register({
260
+ name: "logic-lectern",
261
+ description: () => "打开数字逻辑辅助学习插件",
262
+ available: () => true,
263
+ ui: { kind: "action", run: () => { host.openPanel(); } },
264
+ });
265
+ return () => dispose();
266
+ }, "dsh-digital-logic-lectern: slash command");
267
+ });
268
+ }
269
+
270
+ exports.apply = apply;
271
+ exports.inject = inject;
272
+ return module.exports;
273
+ },
274
+ });