reactive-md 0.3.0 → 0.3.1
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/CHANGELOG.md +53 -40
- package/CONTRIBUTING.md +4 -0
- package/README.en.md +3 -2
- package/README.md +3 -2
- package/SECURITY.md +71 -68
- package/dist-library/reactive-md-react.js +1099 -964
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1 -1
- package/dist-library/{runtime-D4phFXOr.js → runtime-CPzMEMcW.js} +2232 -2058
- package/dist-library/types/local/compiler.d.ts +3 -3
- package/dist-library/types/local/heading-anchors.d.ts +6 -0
- package/dist-library/types/local/index.d.ts +1 -1
- package/dist-library/types/local/limits.d.ts +1 -0
- package/dist-library/types/local/parser.d.ts +2 -2
- package/dist-library/types/local/types.d.ts +8 -0
- package/docs/compatibility.md +68 -67
- package/docs/component-development.md +206 -0
- package/docs/component-protocol.md +685 -0
- package/docs/local-guide.md +941 -936
- package/docs/local-integration.md +218 -193
- package/docs/local-interaction-syntax.md +439 -437
- package/docs/performance.md +67 -30
- package/docs/releasing.md +5 -5
- package/examples/conformance/README.md +51 -11
- package/examples/conformance/component-protocol-1.json +194 -0
- package/examples/conformance/component-protocol-1.schema.json +76 -0
- package/examples/conformance/local-draft-1.json +50 -49
- package/examples/integration/README.md +2 -2
- package/examples/local/README.md +66 -66
- package/examples/local/charts.reactive.md +73 -73
- package/package.json +77 -75
package/docs/performance.md
CHANGED
|
@@ -1,30 +1,67 @@
|
|
|
1
|
-
# 性能测量
|
|
2
|
-
|
|
3
|
-
在源码仓库根目录构建语言包,然后运行:
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
npm run build
|
|
7
|
-
npm run benchmark
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
脚本对每个场景预热 3 次、测量 20 次,报告中位数和 P95,原始结果写入 `artifacts/benchmark.json`。可用 `npm run benchmark -- --iterations 50 --output artifacts/benchmark-50.json` 改变次数和输出位置。报告包含包版本、Node 版本、操作系统和 CPU 信息。
|
|
11
|
-
|
|
12
|
-
## 本地基线
|
|
13
|
-
|
|
14
|
-
2026-10-22,Reactive MD 0.3.0,Node 22.17.0,Windows x64,Intel Core Ultra 5 125H。测量时机器上也有其他开发进程运行。
|
|
15
|
-
|
|
16
|
-
| 场景 | 中位数 | P95 |
|
|
17
|
-
| --- | ---: | ---: |
|
|
18
|
-
| 编译费用示例,378 字符 | 2.51 ms | 5.83 ms |
|
|
19
|
-
| 编译 250 行响应式表格,7,161 字符 | 17.04 ms | 28.05 ms |
|
|
20
|
-
| 编译 100 节文章,15,550 字符 | 45.34 ms | 59.81 ms |
|
|
21
|
-
| 连续 100 次状态写入与表达式求值 | 0.20 ms | 0.34 ms |
|
|
22
|
-
| 三条曲线,每条 200 个采样点 | 0.55 ms | 1.61 ms |
|
|
23
|
-
|
|
24
|
-
计时包含正确性断言,运行时场景的一次测量包含 100 次更新。绘图场景包含正常函数与非网格渐近线的断点检查。
|
|
25
|
-
|
|
26
|
-
这些数据测量 Node 中的编译、求值和采样,不包含浏览器排版、绘制或输入到画面的延迟。数值用于同条件下比较版本,不设置跨机器通过阈值,也不代表源码上限内的所有文档都有相同耗时。CI 保存 Node 24 的测量报告;[首轮 CI](https://github.com/yao1145/ReactiveMD/actions/runs/39782886373) 已通过并生成报告。
|
|
27
|
-
|
|
28
|
-
## 宿主中的大文档
|
|
29
|
-
|
|
30
|
-
文档源码上限为 1,000,000 个 UTF-16 代码单元,绘图和表达式还有独立计算预算,详见[安全策略](../SECURITY.md)。资源上限控制工作量,编译 API 仍是同步调用。编辑器可以合并连续输入触发的编译;处理来源不可信或较大的文档时,可以在宿主 Worker 或独立进程中编译,并由宿主控制并发和超时。
|
|
1
|
+
# 性能测量
|
|
2
|
+
|
|
3
|
+
在源码仓库根目录构建语言包,然后运行:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm run build
|
|
7
|
+
npm run benchmark
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
脚本对每个场景预热 3 次、测量 20 次,报告中位数和 P95,原始结果写入 `artifacts/benchmark.json`。可用 `npm run benchmark -- --iterations 50 --output artifacts/benchmark-50.json` 改变次数和输出位置。报告包含包版本、Node 版本、操作系统和 CPU 信息。
|
|
11
|
+
|
|
12
|
+
## 本地基线
|
|
13
|
+
|
|
14
|
+
2026-10-22,Reactive MD 0.3.0,Node 22.17.0,Windows x64,Intel Core Ultra 5 125H。测量时机器上也有其他开发进程运行。
|
|
15
|
+
|
|
16
|
+
| 场景 | 中位数 | P95 |
|
|
17
|
+
| --- | ---: | ---: |
|
|
18
|
+
| 编译费用示例,378 字符 | 2.51 ms | 5.83 ms |
|
|
19
|
+
| 编译 250 行响应式表格,7,161 字符 | 17.04 ms | 28.05 ms |
|
|
20
|
+
| 编译 100 节文章,15,550 字符 | 45.34 ms | 59.81 ms |
|
|
21
|
+
| 连续 100 次状态写入与表达式求值 | 0.20 ms | 0.34 ms |
|
|
22
|
+
| 三条曲线,每条 200 个采样点 | 0.55 ms | 1.61 ms |
|
|
23
|
+
|
|
24
|
+
计时包含正确性断言,运行时场景的一次测量包含 100 次更新。绘图场景包含正常函数与非网格渐近线的断点检查。
|
|
25
|
+
|
|
26
|
+
这些数据测量 Node 中的编译、求值和采样,不包含浏览器排版、绘制或输入到画面的延迟。数值用于同条件下比较版本,不设置跨机器通过阈值,也不代表源码上限内的所有文档都有相同耗时。CI 保存 Node 24 的测量报告;[首轮 CI](https://github.com/yao1145/ReactiveMD/actions/runs/39782886373) 已通过并生成报告。
|
|
27
|
+
|
|
28
|
+
## 宿主中的大文档
|
|
29
|
+
|
|
30
|
+
文档源码上限为 1,000,000 个 UTF-16 代码单元,绘图和表达式还有独立计算预算,详见[安全策略](../SECURITY.md)。资源上限控制工作量,编译 API 仍是同步调用。编辑器可以合并连续输入触发的编译;处理来源不可信或较大的文档时,可以在宿主 Worker 或独立进程中编译,并由宿主控制并发和超时。
|
|
31
|
+
|
|
32
|
+
语法节点预算默认 10,000,宿主可用 `compileLocal(source, { limits: { maxSyntaxNodes: 50_000 } })` 按次调整,见[核心 API](local-integration.md#核心-api)。提高预算后应同时测量编译、内存和最终预览渲染成本。
|
|
33
|
+
|
|
34
|
+
## Playground 实时编辑
|
|
35
|
+
|
|
36
|
+
Playground 在独立的模块 Worker 中调用公开的 `compileLocal`,将连续 150 ms 内的编辑合并。调度器最多保留一个正在编译的任务和一份最新待编译源码;过期结果不会替换当前预览或诊断。输入框和导出始终使用最新源码,等待编译时显示“编译中”并保留上一次预览。预览组件复用相同文档,避免每次按键重建整个预览。
|
|
37
|
+
|
|
38
|
+
源码保存延后执行,切换示例或离开页面时保存待写入的内容。Worker 无法使用或运行失败时,页面提示降级,并合并编辑后在主线程编译;该模式仍有大文档阻塞的成本。正常 Worker 模式中,接收编译结果后的 React 渲染、排版与绘制仍在主线程执行。
|
|
39
|
+
|
|
40
|
+
语言包的同步编译 API 和 `LocalReactiveDocument` 保持原有行为。其他宿主可以参考 `demo/src/local-compile-worker.ts` 与调度器,将编译放到自己管理的 Worker。
|
|
41
|
+
|
|
42
|
+
### 复测
|
|
43
|
+
|
|
44
|
+
在仓库根目录构建语言包后执行:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
node scripts/benchmark-large-documents.mjs
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
脚本预热 3 次、测量 20 次,检查 10、100、300、600 节文章编译结果并保存中位数和 P95。启动 Playground 后,可以从仓库根目录执行以下浏览器检查;默认服务器为 `http://127.0.0.1:5184`,可用 `DEMO_URL` 覆盖。
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
node demo/scripts/verify-editing.mjs
|
|
54
|
+
node demo/scripts/benchmark-editing.mjs
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
编辑基准在 300 节、约 47,000 字符的文章末尾连续键入 10 个字符,按键间隔为 20 ms,记录输入事件到下一次 `requestAnimationFrame` 回调的延迟和主线程长任务。该指标用于观察输入响应,不等同于画面完成绘制的时间;长任务统计包含最终预览渲染。`EDITING_SECTIONS` 可调整节数,`EDITING_REPORT` 可指定报告路径。所有报告写入忽略目录 `artifacts/`。
|
|
58
|
+
|
|
59
|
+
2026-10-22,在上述 Windows 机器上用本机 Edge 对同一份 46,969 字符文章进行一次前后对比。两边均使用 Vite 开发服务、1440 × 1000 视口,原版为 `94fd72e`,优化版包含本节描述的 Worker 调度与预览复用。
|
|
60
|
+
|
|
61
|
+
| 指标 | 原版 | 优化版 |
|
|
62
|
+
| --- | ---: | ---: |
|
|
63
|
+
| 输入到下一帧回调的中位延迟 | 147.3 ms | 9.5 ms |
|
|
64
|
+
| 输入到下一帧回调的最大延迟 | 157.9 ms | 36.9 ms |
|
|
65
|
+
| 连续键入 10 个字符的总耗时 | 2,302 ms | 538 ms |
|
|
66
|
+
|
|
67
|
+
原始报告分别为 `artifacts/benchmark-editing-before.json` 和 `artifacts/benchmark-editing-after.json`。这是一次本机观测,机器负载会影响数值。优化主要减少按键触发的主线程工作,同步 `compileLocal` 本身的算法和单次编译速度保持原样。
|
package/docs/releasing.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 发布清单
|
|
2
2
|
|
|
3
|
-
本文件是维护者的手动发布流程。Reactive MD 当前为 `0.3.
|
|
3
|
+
本文件是维护者的手动发布流程。Reactive MD 当前为 `0.3.1` 公开预览版。版本规则见[版本与兼容性](compatibility.md)。
|
|
4
4
|
|
|
5
5
|
## 发布前确认
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
4. 核对 `package.json` 的 `repository`、`homepage`、`bugs`、`license`、`engines` 等发布元数据;当前已设置,发布前确认 URL 和最低 Node 版本仍然正确,并确认 `private` 保持移除状态。
|
|
15
15
|
5. 确认 `files` 覆盖发布所需内容。当前包含 `dist-library`、中英文 README、`CONTRIBUTING.md`、`CHANGELOG.md`、`SECURITY.md`、`THIRD_PARTY_NOTICES.md`、`docs` 和 `examples`;新增文档或 notice 时同步加入 `files`。
|
|
16
16
|
|
|
17
|
-
包名和版本决定 tarball 名称。当前 `0.3.
|
|
17
|
+
包名和版本决定 tarball 名称。当前 `0.3.1` 的预期文件名是 `reactive-md-0.3.1.tgz`;改名或改版本后以 `npm pack` 的实际输出为准。
|
|
18
18
|
|
|
19
19
|
### 第三方 notice
|
|
20
20
|
|
|
@@ -42,7 +42,7 @@ npm pack
|
|
|
42
42
|
mkdir /tmp/reactive-md-consumer
|
|
43
43
|
cd /tmp/reactive-md-consumer
|
|
44
44
|
npm init -y
|
|
45
|
-
npm install /path/to/reactive-md-0.3.
|
|
45
|
+
npm install /path/to/reactive-md-0.3.1.tgz
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
核心入口可在 Node 中直接检查:
|
|
@@ -84,8 +84,8 @@ import 'reactive-md/styles.css';
|
|
|
84
84
|
4. 运行 `npm pack --dry-run` 检查文件列表、大小和许可文件;再实际 `npm pack` 并在空目录安装验证。
|
|
85
85
|
5. 检查 tarball 的 SHA256,记录到发布说明或内部发布记录。
|
|
86
86
|
6. 合并发布提交,等待 `main` 上的 CI 全部通过。
|
|
87
|
-
7. 手动创建并推送 tag,例如 `v0.3.
|
|
88
|
-
8. 在维护者本机完成 npm 登录和双因素认证后手动发布 tarball:`npm publish reactive-md-0.3.
|
|
87
|
+
7. 手动创建并推送 tag,例如 `v0.3.1`。不要在自动发布工作流中保存 npm token。
|
|
88
|
+
8. 在维护者本机完成 npm 登录和双因素认证后手动发布 tarball:`npm publish reactive-md-0.3.1.tgz --access public`。使用 scope 包名时改为对应的 `@scope/name`。
|
|
89
89
|
9. 在 npm 和 GitHub Releases 上核对包内容、版本、README、许可与发布说明;从公开 registry 重新安装一次。
|
|
90
90
|
10. 从 registry 验证 README 中的安装命令可用,核对 registry 的完整性摘要与发布 tarball 一致。
|
|
91
91
|
|
|
@@ -1,11 +1,51 @@
|
|
|
1
|
-
# 语言验收数据
|
|
2
|
-
|
|
3
|
-
[local-draft-1.json](local-draft-1.json) 是可复制的最小语义验收集,包含源码、编译结果、初始参数、状态写入和预期文本。数据随 npm 包分发,其他工具或实现可以读取同一份 JSON。
|
|
4
|
-
|
|
5
|
-
- `syntaxVersion` 对应核心导出的 `LOCAL_SYNTAX_VERSION`。
|
|
6
|
-
- `ok`
|
|
7
|
-
- `initial` 检查公开参数的初值;`bindingNames` 在出现时检查完整绑定名集合。
|
|
8
|
-
- `actions` 按 `bind` 查找控件并提交 `value`;有 `codes` 时预期写入被拒绝,否则预期成功。
|
|
9
|
-
- `text` 用更新后的状态求值,结果应等于 `expectedText`。
|
|
10
|
-
|
|
11
|
-
运行器见仓库中的 `tests/conformance.test.ts`,执行 `npm test` 即可检查。本集覆盖共享参数、隐藏初始化、写入约束、代码隔离和诊断;完整语法验收还包含其他语言测试及浏览器检查,规则见[语法规范](../../docs/local-interaction-syntax.md)。诊断码的跨版本约定见[兼容说明](../../docs/compatibility.md)。
|
|
1
|
+
# 语言验收数据
|
|
2
|
+
|
|
3
|
+
[local-draft-1.json](local-draft-1.json) 是可复制的最小语义验收集,包含源码、编译结果、初始参数、状态写入和预期文本。数据随 npm 包分发,其他工具或实现可以读取同一份 JSON。
|
|
4
|
+
|
|
5
|
+
- `syntaxVersion` 对应核心导出的 `LOCAL_SYNTAX_VERSION`。
|
|
6
|
+
- `ok` 是预期编译结果;`codes` 是去重后的预期诊断码集合,省略时应无诊断。编译成功时也可能包含降级警告。
|
|
7
|
+
- `initial` 检查公开参数的初值;`bindingNames` 在出现时检查完整绑定名集合。
|
|
8
|
+
- `actions` 按 `bind` 查找控件并提交 `value`;有 `codes` 时预期写入被拒绝,否则预期成功。
|
|
9
|
+
- `text` 用更新后的状态求值,结果应等于 `expectedText`。
|
|
10
|
+
|
|
11
|
+
运行器见仓库中的 `tests/conformance.test.ts`,执行 `npm test` 即可检查。本集覆盖共享参数、隐藏初始化、写入约束、代码隔离和诊断;完整语法验收还包含其他语言测试及浏览器检查,规则见[语法规范](../../docs/local-interaction-syntax.md)。诊断码的跨版本约定见[兼容说明](../../docs/compatibility.md)。
|
|
12
|
+
|
|
13
|
+
## 组块协议验收
|
|
14
|
+
|
|
15
|
+
[component-protocol-1.json](component-protocol-1.json) 为[组块协议](../../docs/component-protocol.md)提供代表性用例,覆盖 `slider`、`tabs`、`plot` 以及未知组块的惰性降级。[JSON Schema](component-protocol-1.schema.json) 定义验收文件格式,可供其他实现的工具读取。这个 JSON 是测试输入和预期结果,组件提案的声明模板见[开发指南](../../docs/component-development.md)。
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm run test:components
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
该命令运行组块协议用例和原有语言验收数据。新增组块应补充自己的用例、单元测试和受影响的渲染器检查;通过本集合只证明这些具体用例通过。
|
|
22
|
+
|
|
23
|
+
### 文件与用例字段
|
|
24
|
+
|
|
25
|
+
文件根对象包含 `protocolVersion`、`syntaxVersion` 和非空的 `cases`。当前分别为 `component-protocol-1` 和 `local-draft-1`。包版本另由 `package.json` 标识,不由这两个字段推断。
|
|
26
|
+
|
|
27
|
+
| 字段 | 规则 |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `id` | 必填,在文件内唯一;描述一个可观察的行为 |
|
|
30
|
+
| `component` | 必填,标明主要验收的组块;源码可同时使用其他组块 |
|
|
31
|
+
| `source` | 必填,原始文档源码 |
|
|
32
|
+
| `ok` | 必填,预期编译是否成功 |
|
|
33
|
+
| `codes` | 必填,编译诊断码的去重集合;无诊断时为 `[]`,忽略顺序、精确比较集合 |
|
|
34
|
+
| `initial` | 可选,编译成功后的初始状态期望,按给定键部分匹配 |
|
|
35
|
+
| `bindingNames` | 可选,完整公开绑定名集合;不包含匿名组块的内部状态键 |
|
|
36
|
+
| `actions` | 可选,依次写入命名绑定;每项必填 `bind`、`value`、`codes`,可选 `expectedState` |
|
|
37
|
+
| `reset` | 可选,写入完成后重置指定节点;必填 `component` 和 `expectedState`,`index` 默认为同名组件源码顺序中的第 0 个 |
|
|
38
|
+
| `text`、`expectedText` | 可选,必须成对;在写入和重置后求值并精确比较结果 |
|
|
39
|
+
| `htmlIncludes`、`htmlExcludes` | 可选,在最终状态做 React 静态渲染,逐项检查包含或不包含的片段 |
|
|
40
|
+
|
|
41
|
+
`initial`、`expectedState` 的值使用语言现有的 `LocalValue`:字符串、有限数字、布尔值、`null` 或字符串数组。`actions[].codes` 是该次写入返回的诊断码集合,无诊断仍须写 `[]`;被拒绝的写入应保留上一次合法状态。运行器通过 `bind` 查找已编译的控件,调用 `runtime.set`,不模拟浏览器输入事件。
|
|
42
|
+
|
|
43
|
+
执行顺序固定为:校验数据格式及唯一 ID,编译并比较诊断,检查初始状态及公开绑定名,依序写入,再重置,最后检查文本和可选渲染结果。创建的运行时均在结束时销毁。`ok: false` 的用例只允许编译期字段,不能附加状态、动作或渲染期望;未知字段、缺失字段和不合法值应当让验收失败。
|
|
44
|
+
|
|
45
|
+
`reset` 调用当前实例的 `runtime.reset(node)`,节点按组块名和索引查找;验收文件不保存 `node.id`。这项检查验证运行时重置语义,点击重置按钮仍需渲染器或浏览器检查。
|
|
46
|
+
|
|
47
|
+
### 可移植范围
|
|
48
|
+
|
|
49
|
+
编译结果、诊断集合、状态变化和表达式文本是可移植的语义期望。HTML 片段只检查本仓库的 React 参考渲染器;其他渲染器应验证同等用户行为,无需生成相同 DOM 或 CSS 类名。
|
|
50
|
+
|
|
51
|
+
这些用例不会证明真实键盘操作、焦点移动、中文输入法、375px 布局、计时器暂停或销毁后的计时清理。涉及这些行为的贡献仍需提交相应浏览器证据,检查方法见[开发指南](../../docs/component-development.md)。诊断码的跨版本稳定性继续遵守[兼容说明](../../docs/compatibility.md)。
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocolVersion": "component-protocol-1",
|
|
3
|
+
"syntaxVersion": "local-draft-1",
|
|
4
|
+
"cases": [
|
|
5
|
+
{
|
|
6
|
+
"id": "slider-explicit-initial",
|
|
7
|
+
"component": "slider",
|
|
8
|
+
"source": "<slider bind=\"seats\" label=\"人数\" initial=\"2\" min=\"1\" max=\"20\">\n\n当前 {{ seats }} 人。",
|
|
9
|
+
"ok": true,
|
|
10
|
+
"codes": [],
|
|
11
|
+
"initial": { "seats": 2 },
|
|
12
|
+
"bindingNames": ["seats"],
|
|
13
|
+
"text": "当前 {{ seats }} 人。",
|
|
14
|
+
"expectedText": "当前 2 人。",
|
|
15
|
+
"htmlIncludes": ["人数"]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "slider-default-min",
|
|
19
|
+
"component": "slider",
|
|
20
|
+
"source": "<slider bind=\"level\" label=\"档位\" min=\"5\" max=\"15\">",
|
|
21
|
+
"ok": true,
|
|
22
|
+
"codes": [],
|
|
23
|
+
"initial": { "level": 5 },
|
|
24
|
+
"bindingNames": ["level"],
|
|
25
|
+
"text": "档位:{{ level }}。",
|
|
26
|
+
"expectedText": "档位:5。"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "slider-shared-update",
|
|
30
|
+
"component": "slider",
|
|
31
|
+
"source": "<slider bind=\"n\" label=\"甲\" initial=\"1\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"乙\" min=\"0\" max=\"10\">\n\n共享值 {{ n }}。",
|
|
32
|
+
"ok": true,
|
|
33
|
+
"codes": [],
|
|
34
|
+
"initial": { "n": 1 },
|
|
35
|
+
"bindingNames": ["n"],
|
|
36
|
+
"actions": [
|
|
37
|
+
{ "bind": "n", "value": 7, "codes": [], "expectedState": { "n": 7 } }
|
|
38
|
+
],
|
|
39
|
+
"text": "共享值 {{ n }}。",
|
|
40
|
+
"expectedText": "共享值 7。"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "slider-rejects-invalid-writes",
|
|
44
|
+
"component": "slider",
|
|
45
|
+
"source": "<slider bind=\"amount\" label=\"数量\" initial=\"4\" min=\"0\" max=\"10\">",
|
|
46
|
+
"ok": true,
|
|
47
|
+
"codes": [],
|
|
48
|
+
"initial": { "amount": 4 },
|
|
49
|
+
"bindingNames": ["amount"],
|
|
50
|
+
"actions": [
|
|
51
|
+
{ "bind": "amount", "value": 11, "codes": ["local.runtime.value"], "expectedState": { "amount": 4 } },
|
|
52
|
+
{ "bind": "amount", "value": 6, "codes": [], "expectedState": { "amount": 6 } },
|
|
53
|
+
{ "bind": "amount", "value": 1.5, "codes": ["local.runtime.value"], "expectedState": { "amount": 6 } }
|
|
54
|
+
],
|
|
55
|
+
"text": "{{ amount }}",
|
|
56
|
+
"expectedText": "6"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "slider-shared-constraint-mismatch",
|
|
60
|
+
"component": "slider",
|
|
61
|
+
"source": "<slider bind=\"n\" label=\"甲\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"乙\" min=\"0\" max=\"20\">",
|
|
62
|
+
"ok": false,
|
|
63
|
+
"codes": ["local.binding.constraint"]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "slider-anonymous-controls",
|
|
67
|
+
"component": "slider",
|
|
68
|
+
"source": "<slider label=\"匿名甲\" initial=\"3\" min=\"0\" max=\"10\">\n<slider label=\"匿名乙\" initial=\"7\" min=\"0\" max=\"10\">",
|
|
69
|
+
"ok": true,
|
|
70
|
+
"codes": [],
|
|
71
|
+
"bindingNames": [],
|
|
72
|
+
"htmlIncludes": ["匿名甲", "匿名乙"]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "slider-initial-out-of-range",
|
|
76
|
+
"component": "slider",
|
|
77
|
+
"source": "<slider bind=\"ratio\" label=\"比例\" initial=\"12\" min=\"0\" max=\"10\">",
|
|
78
|
+
"ok": false,
|
|
79
|
+
"codes": ["local.initial.range"]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "tabs-default-first",
|
|
83
|
+
"component": "tabs",
|
|
84
|
+
"source": "<tabs bind=\"view\" label=\"视图\">\n<tab label=\"概览\">概览内容</tab>\n<tab label=\"细节\" value=\"detail\">细节内容</tab>\n</tabs>",
|
|
85
|
+
"ok": true,
|
|
86
|
+
"codes": [],
|
|
87
|
+
"initial": { "view": "tab-1" },
|
|
88
|
+
"bindingNames": ["view"],
|
|
89
|
+
"actions": [
|
|
90
|
+
{ "bind": "view", "value": "detail", "codes": [], "expectedState": { "view": "detail" } },
|
|
91
|
+
{ "bind": "view", "value": "absent", "codes": ["local.runtime.value"], "expectedState": { "view": "detail" } }
|
|
92
|
+
],
|
|
93
|
+
"text": "当前页 {{ view }}。",
|
|
94
|
+
"expectedText": "当前页 detail。"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "tabs-explicit-initial-and-reset",
|
|
98
|
+
"component": "tabs",
|
|
99
|
+
"source": "<tabs bind=\"view\" label=\"视图\" initial=\"detail\">\n<tab label=\"概览\" value=\"summary\">摘要页</tab>\n<tab label=\"细节\" value=\"detail\">细节页</tab>\n</tabs>",
|
|
100
|
+
"ok": true,
|
|
101
|
+
"codes": [],
|
|
102
|
+
"initial": { "view": "detail" },
|
|
103
|
+
"bindingNames": ["view"],
|
|
104
|
+
"actions": [
|
|
105
|
+
{ "bind": "view", "value": "summary", "codes": [], "expectedState": { "view": "summary" } }
|
|
106
|
+
],
|
|
107
|
+
"reset": { "component": "tabs", "index": 0, "expectedState": { "view": "detail" } },
|
|
108
|
+
"text": "{{ view }}",
|
|
109
|
+
"expectedText": "detail"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "tabs-exclusive-binding",
|
|
113
|
+
"component": "tabs",
|
|
114
|
+
"source": "<tabs bind=\"view\" label=\"甲\">\n<tab label=\"A\">甲页</tab>\n</tabs>\n<tabs bind=\"view\" label=\"乙\">\n<tab label=\"B\">乙页</tab>\n</tabs>",
|
|
115
|
+
"ok": false,
|
|
116
|
+
"codes": ["local.binding.exclusive"]
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"id": "tabs-hidden-controls-and-panel-reset",
|
|
120
|
+
"component": "tabs",
|
|
121
|
+
"source": "<panel title=\"设置\">\n<tabs bind=\"view\" label=\"分页\" initial=\"basic\">\n<tab label=\"基本\" value=\"basic\">\n<slider bind=\"a\" label=\"A\" initial=\"2\" min=\"0\" max=\"10\">\n</tab>\n<tab label=\"高级\" value=\"advanced\">\n<slider bind=\"b\" label=\"B\" initial=\"7\" min=\"0\" max=\"10\">\n</tab>\n</tabs>\n</panel>",
|
|
122
|
+
"ok": true,
|
|
123
|
+
"codes": [],
|
|
124
|
+
"initial": { "view": "basic", "a": 2, "b": 7 },
|
|
125
|
+
"bindingNames": ["a", "b", "view"],
|
|
126
|
+
"actions": [
|
|
127
|
+
{ "bind": "view", "value": "advanced", "codes": [], "expectedState": { "view": "advanced", "a": 2, "b": 7 } },
|
|
128
|
+
{ "bind": "a", "value": 5, "codes": [], "expectedState": { "view": "advanced", "a": 5, "b": 7 } },
|
|
129
|
+
{ "bind": "b", "value": 9, "codes": [], "expectedState": { "view": "advanced", "a": 5, "b": 9 } }
|
|
130
|
+
],
|
|
131
|
+
"reset": { "component": "panel", "expectedState": { "view": "basic", "a": 2, "b": 7 } },
|
|
132
|
+
"text": "{{ view }}:{{ a }} / {{ b }}",
|
|
133
|
+
"expectedText": "basic:2 / 7"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "plot-valid-latex",
|
|
137
|
+
"component": "plot",
|
|
138
|
+
"source": "<slider bind=\"a\" label=\"振幅\" initial=\"1\" min=\"0\" max=\"3\" step=\"0.5\">\n\n<plot label=\"正弦波\" min=\"-2\" max=\"2\">\n$$ y = a\\sin x $$\n</plot>",
|
|
139
|
+
"ok": true,
|
|
140
|
+
"codes": [],
|
|
141
|
+
"initial": { "a": 1 },
|
|
142
|
+
"bindingNames": ["a"],
|
|
143
|
+
"htmlIncludes": ["区间 -2 到 2,200 个采样点"]
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"id": "plot-dynamic-range",
|
|
147
|
+
"component": "plot",
|
|
148
|
+
"source": "<slider bind=\"low\" label=\"下限\" initial=\"-2\" min=\"-10\" max=\"0\">\n<slider bind=\"high\" label=\"上限\" initial=\"3\" min=\"0\" max=\"10\">\n\n<plot label=\"范围曲线\" min=\"{{ low }}\" max=\"{{ high }}\">\n$$ y = x $$\n</plot>",
|
|
149
|
+
"ok": true,
|
|
150
|
+
"codes": [],
|
|
151
|
+
"initial": { "low": -2, "high": 3 },
|
|
152
|
+
"bindingNames": ["low", "high"],
|
|
153
|
+
"actions": [
|
|
154
|
+
{ "bind": "high", "value": 5, "codes": [], "expectedState": { "high": 5 } }
|
|
155
|
+
],
|
|
156
|
+
"text": "{{ high - low }}",
|
|
157
|
+
"expectedText": "7",
|
|
158
|
+
"htmlIncludes": ["区间 -2 到 5,200 个采样点"]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"id": "plot-non-number-binding",
|
|
162
|
+
"component": "plot",
|
|
163
|
+
"source": "<toggle bind=\"a\" label=\"开关\">\n\n<plot label=\"类型错误\">\n$$ y = a\\sin x $$\n</plot>",
|
|
164
|
+
"ok": false,
|
|
165
|
+
"codes": ["local.math.binding"]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "plot-invalid-range",
|
|
169
|
+
"component": "plot",
|
|
170
|
+
"source": "<plot label=\"无效范围\" min=\"5\" max=\"5\">\n$$ y = x $$\n</plot>",
|
|
171
|
+
"ok": false,
|
|
172
|
+
"codes": ["local.constraint"]
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"id": "plot-point-budget",
|
|
176
|
+
"component": "plot",
|
|
177
|
+
"source": "<plot label=\"第一组\" min=\"-1\" max=\"1\" samples=\"2000\">\n$$ y = x $$\n$$ y = x^2 $$\n$$ y = \\sin x $$\n$$ y = \\cos x $$\n$$ y = x/2 $$\n$$ y = 2x $$\n</plot>\n\n<plot label=\"第二组\" min=\"-1\" max=\"1\" samples=\"2000\">\n$$ y = x + 1 $$\n$$ y = x - 1 $$\n$$ y = 3x $$\n$$ y = \\frac{x}{3} $$\n$$ y = -x $$\n</plot>",
|
|
178
|
+
"ok": false,
|
|
179
|
+
"codes": ["local.budget.plot.points"]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"id": "unknown-tag-inert-fallback",
|
|
183
|
+
"component": "slider",
|
|
184
|
+
"source": "<slidr label=\"拼写错误\">\n<slider bind=\"ghost\" label=\"不应激活\" initial=\"4\" min=\"0\" max=\"10\">\n{{ ghost }} 不应执行。\n</slidr>\n\n外部仍可计算:{{ 1 + 2 }}。",
|
|
185
|
+
"ok": true,
|
|
186
|
+
"codes": ["local.component.unknown"],
|
|
187
|
+
"bindingNames": [],
|
|
188
|
+
"text": "外部仍可计算:{{ 1 + 2 }}。",
|
|
189
|
+
"expectedText": "外部仍可计算:3。",
|
|
190
|
+
"htmlIncludes": ["未支持的语法,已按源码原样显示"],
|
|
191
|
+
"htmlExcludes": ["<input"]
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "ReactiveMD component-protocol-1 reference cases",
|
|
4
|
+
"description": "Portable semantic cases and optional React reference-renderer assertions. This is a test-data format, not a loadable component or serialized AST format.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["protocolVersion", "syntaxVersion", "cases"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"protocolVersion": { "const": "component-protocol-1" },
|
|
10
|
+
"syntaxVersion": { "const": "local-draft-1" },
|
|
11
|
+
"cases": {
|
|
12
|
+
"type": "array", "minItems": 1,
|
|
13
|
+
"items": { "$ref": "#/$defs/case" },
|
|
14
|
+
"$comment": "Case ids must also be unique across the suite; checked by the reference runner."
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"$defs": {
|
|
18
|
+
"name": { "type": "string", "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$" },
|
|
19
|
+
"strings": { "type": "array", "items": { "type": "string", "minLength": 1 } },
|
|
20
|
+
"codes": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
|
|
21
|
+
"value": {
|
|
22
|
+
"oneOf": [
|
|
23
|
+
{ "type": "string" }, { "type": "number" }, { "type": "boolean" }, { "type": "null" },
|
|
24
|
+
{ "type": "array", "items": { "type": "string" } }
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"state": { "type": "object", "additionalProperties": { "$ref": "#/$defs/value" } },
|
|
28
|
+
"action": {
|
|
29
|
+
"type": "object", "additionalProperties": false,
|
|
30
|
+
"required": ["bind", "value", "codes"],
|
|
31
|
+
"properties": {
|
|
32
|
+
"bind": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
|
|
33
|
+
"value": { "$ref": "#/$defs/value" },
|
|
34
|
+
"codes": { "$ref": "#/$defs/codes" },
|
|
35
|
+
"expectedState": { "$ref": "#/$defs/state" }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"reset": {
|
|
39
|
+
"type": "object", "additionalProperties": false,
|
|
40
|
+
"required": ["component", "expectedState"],
|
|
41
|
+
"properties": {
|
|
42
|
+
"component": { "$ref": "#/$defs/name" },
|
|
43
|
+
"index": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
|
|
44
|
+
"expectedState": { "$ref": "#/$defs/state" }
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"case": {
|
|
48
|
+
"type": "object", "additionalProperties": false,
|
|
49
|
+
"required": ["id", "component", "source", "ok", "codes"],
|
|
50
|
+
"properties": {
|
|
51
|
+
"id": { "type": "string", "minLength": 1 },
|
|
52
|
+
"component": { "$ref": "#/$defs/name" },
|
|
53
|
+
"source": { "type": "string" },
|
|
54
|
+
"ok": { "type": "boolean" },
|
|
55
|
+
"codes": { "$ref": "#/$defs/codes" },
|
|
56
|
+
"initial": { "$ref": "#/$defs/state" },
|
|
57
|
+
"bindingNames": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
|
|
58
|
+
"actions": { "type": "array", "items": { "$ref": "#/$defs/action" } },
|
|
59
|
+
"reset": { "$ref": "#/$defs/reset" },
|
|
60
|
+
"text": { "type": "string" }, "expectedText": { "type": "string" },
|
|
61
|
+
"htmlIncludes": { "$ref": "#/$defs/strings" },
|
|
62
|
+
"htmlExcludes": { "$ref": "#/$defs/strings" }
|
|
63
|
+
},
|
|
64
|
+
"dependentRequired": { "text": ["expectedText"], "expectedText": ["text"] },
|
|
65
|
+
"allOf": [{
|
|
66
|
+
"if": { "properties": { "ok": { "const": false } }, "required": ["ok"] },
|
|
67
|
+
"then": { "not": { "anyOf": [
|
|
68
|
+
{ "required": ["initial"] }, { "required": ["bindingNames"] },
|
|
69
|
+
{ "required": ["actions"] }, { "required": ["reset"] },
|
|
70
|
+
{ "required": ["text"] }, { "required": ["expectedText"] },
|
|
71
|
+
{ "required": ["htmlIncludes"] }, { "required": ["htmlExcludes"] }
|
|
72
|
+
] } }
|
|
73
|
+
}]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"syntaxVersion": "local-draft-1",
|
|
3
|
-
"cases": [
|
|
4
|
-
{
|
|
5
|
-
"name": "shared numeric binding has one initial value and updates prose",
|
|
6
|
-
"source": "<number bind=\"n\" label=\"Count\" initial=\"2\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"Shared count\" min=\"0\" max=\"10\">\n\nTotal: {{ n * 2 }}",
|
|
7
|
-
"ok": true,
|
|
8
|
-
"initial": { "n": 2 },
|
|
9
|
-
"actions": [{ "bind": "n", "value": 5 }],
|
|
10
|
-
"text": "Total: {{ n * 2 }}",
|
|
11
|
-
"expectedText": "Total: 10"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"name": "hidden controls initialize their bindings",
|
|
15
|
-
"source": "<toggle bind=\"show\" label=\"Show\">\n<if when=\"{{ show }}\">\n<number bind=\"n\" label=\"Hidden count\" initial=\"4\">\n</if>\n\n{{ n * 2 }}",
|
|
16
|
-
"ok": true,
|
|
17
|
-
"initial": { "show": false, "n": 4 },
|
|
18
|
-
"text": "{{ n * 2 }}",
|
|
19
|
-
"expectedText": "8"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"name": "invalid state writes keep the last valid value",
|
|
23
|
-
"source": "<number bind=\"n\" label=\"Count\" initial=\"4\" min=\"0\" max=\"10\">",
|
|
24
|
-
"ok": true,
|
|
25
|
-
"initial": { "n": 4 },
|
|
26
|
-
"actions": [{ "bind": "n", "value": 11, "codes": ["local.runtime.value"] }],
|
|
27
|
-
"text": "{{ n }}",
|
|
28
|
-
"expectedText": "4"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"name": "code fences keep controls and interpolation literal",
|
|
32
|
-
"source": "```markdown\n<counter bind=\"n\" label=\"Literal\">\n{{ missing }}\n```",
|
|
33
|
-
"ok": true,
|
|
34
|
-
"bindingNames": []
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"name": "unknown components
|
|
38
|
-
"source": "<slidr label=\"Typo\">\n</slidr>",
|
|
39
|
-
"ok":
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
{
|
|
2
|
+
"syntaxVersion": "local-draft-1",
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"name": "shared numeric binding has one initial value and updates prose",
|
|
6
|
+
"source": "<number bind=\"n\" label=\"Count\" initial=\"2\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"Shared count\" min=\"0\" max=\"10\">\n\nTotal: {{ n * 2 }}",
|
|
7
|
+
"ok": true,
|
|
8
|
+
"initial": { "n": 2 },
|
|
9
|
+
"actions": [{ "bind": "n", "value": 5 }],
|
|
10
|
+
"text": "Total: {{ n * 2 }}",
|
|
11
|
+
"expectedText": "Total: 10"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "hidden controls initialize their bindings",
|
|
15
|
+
"source": "<toggle bind=\"show\" label=\"Show\">\n<if when=\"{{ show }}\">\n<number bind=\"n\" label=\"Hidden count\" initial=\"4\">\n</if>\n\n{{ n * 2 }}",
|
|
16
|
+
"ok": true,
|
|
17
|
+
"initial": { "show": false, "n": 4 },
|
|
18
|
+
"text": "{{ n * 2 }}",
|
|
19
|
+
"expectedText": "8"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "invalid state writes keep the last valid value",
|
|
23
|
+
"source": "<number bind=\"n\" label=\"Count\" initial=\"4\" min=\"0\" max=\"10\">",
|
|
24
|
+
"ok": true,
|
|
25
|
+
"initial": { "n": 4 },
|
|
26
|
+
"actions": [{ "bind": "n", "value": 11, "codes": ["local.runtime.value"] }],
|
|
27
|
+
"text": "{{ n }}",
|
|
28
|
+
"expectedText": "4"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "code fences keep controls and interpolation literal",
|
|
32
|
+
"source": "```markdown\n<counter bind=\"n\" label=\"Literal\">\n{{ missing }}\n```",
|
|
33
|
+
"ok": true,
|
|
34
|
+
"bindingNames": []
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "unknown components preserve source with a warning",
|
|
38
|
+
"source": "<slidr label=\"Typo\">\n</slidr>",
|
|
39
|
+
"ok": true,
|
|
40
|
+
"bindingNames": [],
|
|
41
|
+
"codes": ["local.component.unknown"]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "unbound expression names produce a compiler diagnostic",
|
|
45
|
+
"source": "Total: {{ missing * 2 }}",
|
|
46
|
+
"ok": false,
|
|
47
|
+
"codes": ["local.binding.unknown"]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
cd core
|
|
11
|
-
npm install reactive-md@0.3.
|
|
11
|
+
npm install reactive-md@0.3.1 --ignore-scripts --no-audit --no-fund
|
|
12
12
|
npm start
|
|
13
13
|
```
|
|
14
14
|
|
|
@@ -20,7 +20,7 @@ npm start
|
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
22
|
cd react
|
|
23
|
-
npm install reactive-md@0.3.
|
|
23
|
+
npm install reactive-md@0.3.1
|
|
24
24
|
npm run dev
|
|
25
25
|
```
|
|
26
26
|
|