reactive-md 0.3.1 → 0.4.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.
Files changed (177) hide show
  1. package/CHANGELOG-ch.md +113 -0
  2. package/CHANGELOG.md +113 -53
  3. package/CONTRIBUTING-ch.md +62 -0
  4. package/CONTRIBUTING.md +64 -65
  5. package/LICENSE +21 -21
  6. package/README-ch.md +123 -0
  7. package/README-en.md +147 -0
  8. package/README.md +96 -38
  9. package/SECURITY-ch.md +80 -0
  10. package/SECURITY.md +58 -49
  11. package/THIRD_PARTY_NOTICES.md +85 -1
  12. package/bin/reactive-md.mjs +40 -0
  13. package/cli/args.mjs +181 -0
  14. package/cli/assets.mjs +390 -0
  15. package/cli/build.mjs +268 -0
  16. package/cli/document.mjs +130 -0
  17. package/cli/errors.mjs +61 -0
  18. package/cli/fs-utils.mjs +133 -0
  19. package/cli/glob.mjs +203 -0
  20. package/cli/help.mjs +138 -0
  21. package/cli/lint.mjs +177 -0
  22. package/cli/main.mjs +55 -0
  23. package/cli/migrate.mjs +368 -0
  24. package/cli/package.mjs +209 -0
  25. package/dist-library/reactive-md-react.js +3525 -1651
  26. package/dist-library/reactive-md.css +1 -1
  27. package/dist-library/reactive-md.js +1798 -4
  28. package/dist-library/runtime-D3QTVYaz.js +15410 -0
  29. package/dist-library/types/index.d.ts +1 -0
  30. package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
  31. package/dist-library/types/local/authoring.d.ts +63 -0
  32. package/dist-library/types/local/collection-functions.d.ts +4 -0
  33. package/dist-library/types/local/colors.d.ts +2 -0
  34. package/dist-library/types/local/computations.d.ts +53 -0
  35. package/dist-library/types/local/data-functions.d.ts +22 -0
  36. package/dist-library/types/local/data-table.d.ts +65 -0
  37. package/dist-library/types/local/dates.d.ts +2 -0
  38. package/dist-library/types/local/dependencies.d.ts +31 -0
  39. package/dist-library/types/local/diagnostics.d.ts +1450 -0
  40. package/dist-library/types/local/expression.d.ts +13 -3
  41. package/dist-library/types/local/formatting.d.ts +41 -0
  42. package/dist-library/types/local/heading-anchors.d.ts +13 -2
  43. package/dist-library/types/local/i18n.d.ts +18 -0
  44. package/dist-library/types/local/index.d.ts +18 -1
  45. package/dist-library/types/local/limits.d.ts +32 -1
  46. package/dist-library/types/local/locale.d.ts +1 -0
  47. package/dist-library/types/local/math.d.ts +6 -1
  48. package/dist-library/types/local/parser.d.ts +10 -4
  49. package/dist-library/types/local/render-types.d.ts +5 -1
  50. package/dist-library/types/local/retention.d.ts +23 -0
  51. package/dist-library/types/local/schema.d.ts +25 -3
  52. package/dist-library/types/local/source-migration.d.ts +35 -0
  53. package/dist-library/types/local/state.d.ts +80 -0
  54. package/dist-library/types/local/text-length.d.ts +13 -0
  55. package/dist-library/types/local/theme.d.ts +30 -0
  56. package/dist-library/types/local/types.d.ts +112 -4
  57. package/dist-library/types/local/validation.d.ts +32 -0
  58. package/dist-library/types/local/version.d.ts +1 -1
  59. package/dist-library/types/local/worker.d.ts +82 -0
  60. package/dist-library/types/react/index.d.ts +4 -1
  61. package/dist-library/types/shareable.d.ts +64 -0
  62. package/dist-standalone/reactive-md-standalone.css +2 -0
  63. package/dist-standalone/reactive-md-standalone.js +57 -0
  64. package/docs/author-tools-ch.md +56 -0
  65. package/docs/author-tools-en.md +56 -0
  66. package/docs/compatibility-ch.md +103 -0
  67. package/docs/compatibility-en.md +103 -0
  68. package/docs/{component-development.md → component-development-ch.md} +210 -206
  69. package/docs/component-development-en.md +210 -0
  70. package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
  71. package/docs/component-protocol-en.md +710 -0
  72. package/docs/computations-formatting-ch.md +87 -0
  73. package/docs/computations-formatting-en.md +87 -0
  74. package/docs/constraints-collections-ch.md +84 -0
  75. package/docs/constraints-collections-en.md +84 -0
  76. package/docs/diagnostics-counting-ch.md +84 -0
  77. package/docs/diagnostics-counting-en.md +84 -0
  78. package/docs/local-components-v2-ch.md +138 -0
  79. package/docs/local-components-v2-en.md +104 -0
  80. package/docs/{local-guide.md → local-guide-ch.md} +28 -8
  81. package/docs/local-guide-en.md +961 -0
  82. package/docs/local-integration-ch.md +363 -0
  83. package/docs/local-integration-en.md +363 -0
  84. package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
  85. package/docs/local-interaction-syntax-en.md +483 -0
  86. package/docs/{performance.md → performance-ch.md} +12 -3
  87. package/docs/performance-en.md +76 -0
  88. package/docs/release-0.4.0-ch.md +89 -0
  89. package/docs/release-0.4.0-en.md +89 -0
  90. package/docs/release-0.4.1-ch.md +23 -0
  91. package/docs/release-0.4.1-en.md +23 -0
  92. package/docs/releasing-ch.md +101 -0
  93. package/docs/releasing-en.md +101 -0
  94. package/docs/shareable-export-ch.md +205 -0
  95. package/docs/shareable-export-en.md +207 -0
  96. package/docs/source-versioning-ch.md +159 -0
  97. package/docs/source-versioning-en.md +159 -0
  98. package/docs/theme-protocol-ch.md +107 -0
  99. package/docs/theme-protocol-en.md +107 -0
  100. package/examples/conformance/README.md +33 -31
  101. package/examples/conformance/component-protocol-1.json +482 -194
  102. package/examples/conformance/component-protocol-1.schema.json +76 -76
  103. package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
  104. package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
  105. package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
  106. package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
  107. package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
  108. package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
  109. package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
  110. package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
  111. package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
  112. package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
  113. package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
  114. package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
  115. package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
  116. package/examples/conformance/history/v0.3.1/provenance.json +72 -0
  117. package/examples/conformance/local-draft-2.json +212 -0
  118. package/examples/integration/README.md +45 -29
  119. package/examples/integration/core/index.mjs +32 -19
  120. package/examples/integration/core/package.json +7 -7
  121. package/examples/integration/react/index.html +12 -12
  122. package/examples/integration/react/main.jsx +21 -21
  123. package/examples/integration/react/package.json +9 -9
  124. package/examples/integration/worker/index.html +19 -0
  125. package/examples/integration/worker/main.js +61 -0
  126. package/examples/integration/worker/package.json +13 -0
  127. package/examples/integration/worker/worker.js +3 -0
  128. package/examples/local/README.md +64 -58
  129. package/examples/local/catalog.reactive.md +20 -20
  130. package/examples/local/charts.reactive.md +34 -34
  131. package/examples/local/checklist.reactive.md +32 -32
  132. package/examples/local/comparison.reactive.md +47 -47
  133. package/examples/local/components.reactive.md +44 -44
  134. package/examples/local/counter.reactive.md +7 -7
  135. package/examples/local/diagnostics.reactive.md +54 -54
  136. package/examples/local/diagram.reactive.md +44 -44
  137. package/examples/local/gallery.reactive.md +61 -61
  138. package/examples/local/parameters.reactive.md +36 -36
  139. package/examples/local/planning.reactive.md +24 -24
  140. package/examples/local/pricing.reactive.md +20 -20
  141. package/examples/local/recipes/invoice-zh.reactive.md +36 -0
  142. package/examples/local/recipes/invoice.reactive.md +36 -0
  143. package/examples/local/recipes/workshop-zh.reactive.md +33 -0
  144. package/examples/local/recipes/workshop.reactive.md +33 -0
  145. package/examples/local/showcase/README.md +25 -0
  146. package/examples/local/showcase/explore.reactive.md +102 -0
  147. package/examples/local/showcase/flow.reactive.md +86 -0
  148. package/examples/local/showcase/forms.reactive.md +126 -0
  149. package/examples/local/showcase/functions.reactive.md +119 -0
  150. package/examples/local/showcase/layout.reactive.md +100 -0
  151. package/examples/local/showcase/statistics.reactive.md +108 -0
  152. package/examples/local/showcase/tasks.reactive.md +89 -0
  153. package/examples/local/showcase/zh/explore.reactive.md +102 -0
  154. package/examples/local/showcase/zh/flow.reactive.md +86 -0
  155. package/examples/local/showcase/zh/forms.reactive.md +126 -0
  156. package/examples/local/showcase/zh/functions.reactive.md +119 -0
  157. package/examples/local/showcase/zh/layout.reactive.md +100 -0
  158. package/examples/local/showcase/zh/statistics.reactive.md +108 -0
  159. package/examples/local/showcase/zh/tasks.reactive.md +89 -0
  160. package/examples/local/zh/catalog.reactive.md +20 -0
  161. package/examples/local/zh/charts.reactive.md +73 -0
  162. package/examples/local/zh/checklist.reactive.md +32 -0
  163. package/examples/local/zh/comparison.reactive.md +47 -0
  164. package/examples/local/zh/components.reactive.md +44 -0
  165. package/examples/local/zh/counter.reactive.md +7 -0
  166. package/examples/local/zh/diagnostics.reactive.md +54 -0
  167. package/examples/local/zh/diagram.reactive.md +44 -0
  168. package/examples/local/zh/gallery.reactive.md +61 -0
  169. package/examples/local/zh/parameters.reactive.md +36 -0
  170. package/examples/local/zh/planning.reactive.md +24 -0
  171. package/examples/local/zh/pricing.reactive.md +20 -0
  172. package/package.json +91 -77
  173. package/README.en.md +0 -76
  174. package/dist-library/runtime-CPzMEMcW.js +0 -11111
  175. package/docs/compatibility.md +0 -68
  176. package/docs/local-integration.md +0 -218
  177. package/docs/releasing.md +0 -92
package/README-ch.md ADDED
@@ -0,0 +1,123 @@
1
+ # Reactive MD
2
+
3
+ [English](README.md)
4
+
5
+ 用 Markdown 写本地交互文档。放入输入控件,用 `bind` 命名参数,用 `{{ 表达式 }}` 连接文字、公式、图表和图解。文档作者无需编写 JavaScript 或 CSS。
6
+
7
+ 本地模式采用 HTML 风格标签,参数和表格数据直接写在正文中,LaTeX 公式可用于函数绘图。TypeScript 核心和 React 渲染器可独立集成。`0.4.1` 是当前的 0.x 预览版,同时提供于 `latest` 和 `next` 渠道,语法修订为 `local-draft-2`。
8
+
9
+ ## 从这里开始
10
+
11
+ - [新用户入门指南](docs/local-guide-ch.md):从 Markdown 过渡到交互文档,含完整练习与错误速查。
12
+ - [本地交互语法规范](docs/local-interaction-syntax-ch.md) · [功能演示与示例](examples/local/README.md):48 个标签名、标签、就地参数与 LaTeX 绘图。
13
+ - [本地模式集成](docs/local-integration-ch.md):`compileLocal`、状态运行时、React 嵌入、URL 策略与样式作用域。
14
+ - [可分享文档与静态导出](docs/shareable-export-ch.md):单文件交互 HTML、静态输出、版本化状态文件、图片资源、CLI 与独立浏览器 API。
15
+ - [主题协议](docs/theme-protocol-ch.md):文档主题选择、自定义 CSS 与深浅模式。
16
+ - [作者工具](docs/author-tools-ch.md):源码高亮、补全、绑定定位、重命名、格式化与命令行检查。
17
+ - [独立接入示例](examples/integration/README.md):可复制到仓库外运行的 Node 核心和 React 页面。
18
+ - [版本与兼容性](docs/compatibility-ch.md):0.x 规则、迁移、诊断契约和平台范围。
19
+ - [组块协议](docs/component-protocol-ch.md) · [组块开发指南](docs/component-development-ch.md):新增组件的声明、行为契约和兼容性验收。
20
+ - [0.4.1 发布说明](docs/release-0.4.1-ch.md):界面与交互修复,兼容 0.4.0。
21
+ - [0.4.0 发布与迁移](docs/release-0.4.0-ch.md):本 minor 系列包含的能力,以及从 `0.3.1` / `local-draft-1` 升级的方法。
22
+
23
+ ## 写一份文档
24
+
25
+ ```markdown
26
+ <panel title="费用估算">
27
+ <slider bind="people" label="人数" initial="2" min="1" max="20">
28
+ <toggle bind="annual" label="年度付款">
29
+ </panel>
30
+
31
+ 每月费用:**{{ people * (annual ? 80 : 100) }} 元**。
32
+ ```
33
+
34
+ 输入立即更新结果,面板自带“恢复默认”。独立使用的计数器只需一行 `<counter label="人数">`。
35
+
36
+ `0.4.0` 新增 `local-draft-2`、命名计算、校验、集合、主题和离线 HTML 导出;旧版 `0.3.1` 使用 `local-draft-1`。见[0.4.0 发布与迁移](docs/release-0.4.0-ch.md)。
37
+
38
+ ## 安装
39
+
40
+ 需要 Node.js 22.12 或更新版本,包提供 ESM 入口:
41
+
42
+ ```sh
43
+ npm install reactive-md
44
+ ```
45
+
46
+ `latest` 和 `next` 当前均指向 `0.4.1`;需要固定版本时使用 `npm install reactive-md@0.4.1`。从 `0.3.1` / `local-draft-1` 升级前请阅读迁移说明。
47
+
48
+ `reactive-md` 入口提供本地编译器、表达式和运行时,`reactive-md/react` 提供 React 渲染器。组件样式通过 `reactive-md/styles.css` 引入。
49
+
50
+ React 入口需要 React 19:
51
+
52
+ ```sh
53
+ npm install react@19 react-dom@19
54
+ ```
55
+
56
+ ```tsx
57
+ import { LocalReactiveDocument } from 'reactive-md/react';
58
+ import 'reactive-md/styles.css';
59
+
60
+ export function Article({ source }: { source: string }) {
61
+ return <LocalReactiveDocument source={source} />;
62
+ }
63
+ ```
64
+
65
+ `reactive-md` 核心入口不依赖 React。完整的编译与运行时 API、宿主 URL 策略、生命周期和样式覆盖见[本地模式集成](docs/local-integration-ch.md)。
66
+
67
+ 0.x 次版本可能包含破坏性变更。升级前阅读[变更记录](CHANGELOG-ch.md)与[兼容规则](docs/compatibility-ch.md),并保存原始 `.reactive.md` 源码。
68
+
69
+ ## 分享文档
70
+
71
+ 构建读者可以离线打开的单个 HTML 文件,或不含脚本的静态快照:
72
+
73
+ ```sh
74
+ npm run build
75
+ npx reactive-md build examples/local/counter.reactive.md -o counter.html
76
+ npx reactive-md build examples/local/counter.reactive.md -o counter-static.html --mode static
77
+ ```
78
+
79
+ 交互文件内嵌原始源码、React 19、运行时、样式以及经过校验的本地图片。它先渲染静态首屏,因此禁用 JavaScript 时仍可阅读。使用 `--state-file doc.state.json` 导出已保存的 `reactive-md-state/v1` 基线;省略时使用作者初值,并把它作为读者的重置基线。Demo 导出对话框可以把当前预览参数保存成此类状态文件。
80
+
81
+ 图片上限、CSP/安全、打印、退出码、`ReactiveMD.mount`/`mountAll` 与 `<reactive-md-doc>` 见[可分享文档与静态导出](docs/shareable-export-ch.md)。单文件导出的静态首屏水合由 Playwright Chromium 和本地 Edge 检查覆盖;Firefox、Safari/WebKit 与通用 SSR 水合仍未验证。
82
+
83
+ ## 体验 Demo
84
+
85
+ ```sh
86
+ npm ci
87
+ npm run dev
88
+ ```
89
+
90
+ 该命令先构建语言包,再启动独立的 `demo/` 应用,地址为 `http://127.0.0.1:5173`。`/embed.html` 展示嵌入方式。页面顶部的语言按钮可以在中文和英文之间切换,选择会保存在浏览器中。Demo 的页面、编辑器、演示服务、资产和浏览器检查均在 `demo/`,通过语言包的公开入口集成。
91
+
92
+ ## 仓库结构
93
+
94
+ ```text
95
+ src/ 本地语法编译、表达式、运行时和 React 渲染器
96
+ examples/ 可复制的本地交互示例,与 demo 应用无关
97
+ docs/ 本地语法规范、集成与发布文档
98
+ tests/ 语言与渲染器测试
99
+ demo/ 独立的 Playground 应用
100
+ ```
101
+
102
+ ## 文档
103
+
104
+ - [新用户入门指南](docs/local-guide-ch.md)与[本地交互语法规范](docs/local-interaction-syntax-ch.md)。
105
+ - [本地模式集成](docs/local-integration-ch.md):核心与 React API、URL 策略、生命周期、样式和版本固定。
106
+ - [可分享文档与静态导出](docs/shareable-export-ch.md):CLI build/lint、状态文件、本地图片内联、打印与独立浏览器运行时。
107
+ - [功能演示与示例](examples/local/README.md)与[独立接入示例](examples/integration/README.md)。
108
+ - [版本与兼容性](docs/compatibility-ch.md)与[0.4.0 发布与迁移](docs/release-0.4.0-ch.md)。
109
+ - [组块协议](docs/component-protocol-ch.md)与[组块开发指南](docs/component-development-ch.md)。
110
+ - [性能说明](docs/performance-ch.md)与[发布清单](docs/releasing-ch.md)。
111
+
112
+ 更多开发与测试命令见[贡献指南](CONTRIBUTING-ch.md)。
113
+
114
+ ## 贡献与安全
115
+
116
+ - [贡献指南](CONTRIBUTING-ch.md):环境、检查命令和改动要求。
117
+ - [安全策略](SECURITY-ch.md):威胁边界、资源上限、宿主责任和漏洞报告渠道。
118
+ - [变更记录](CHANGELOG-ch.md)。
119
+ - [发布清单](docs/releasing-ch.md):验证门禁、notice、tarball 和人工发布流程。
120
+
121
+ ## 许可证
122
+
123
+ [MIT](LICENSE)
package/README-en.md ADDED
@@ -0,0 +1,147 @@
1
+ # Reactive MD
2
+
3
+ [中文](README-ch.md)
4
+
5
+ Write local interactive documents in Markdown. Add input controls, name parameters with `bind`, and connect prose, formulas, charts and diagrams with `{{ expressions }}`. Document authors do not write JavaScript or CSS.
6
+
7
+ Local mode uses HTML-style tags, with parameters and table data written directly in the prose; LaTeX formulas can drive function plots. The TypeScript core and the React renderer can be integrated independently. `0.4.1` is the current 0.x preview on both `latest` and `next`, with syntax revision `local-draft-2`. See [README-ch.md](README-ch.md) for the Chinese overview.
8
+
9
+ ## Start here
10
+
11
+ - [Beginner guide](docs/local-guide-en.md): move from Markdown to interactive documents, with a complete exercise and an error quick reference.
12
+ - [Local interaction syntax specification](docs/local-interaction-syntax-en.md) · [Feature tours and examples](examples/local/README.md): 48 tag names, tags, in-place parameters and LaTeX plots.
13
+ - [Local mode integration](docs/local-integration-en.md): `compileLocal`, the state runtime, React embedding, URL policy and style scoping.
14
+ - [Shareable documents and static export](docs/shareable-export-en.md): single-file interactive HTML, static output, versioned state files, assets, the CLI and the standalone browser API.
15
+ - [Theme protocol](docs/theme-protocol-en.md): document theme selection, custom CSS and light/dark modes.
16
+ - [Author tools](docs/author-tools-en.md): source highlighting, completion, binding navigation, rename, formatting and command-line lint.
17
+ - [Standalone integration examples](examples/integration/README.md): Node core and React pages you can copy and run outside the repository.
18
+ - [Versions and compatibility](docs/compatibility-en.md): 0.x rules, migration, the diagnostics contract and supported platforms.
19
+ - [Component protocol](docs/component-protocol-en.md) · [Component development guide](docs/component-development-en.md): declarations, behavior contracts and compatibility acceptance for new components.
20
+ - [0.4.1 release notes](docs/release-0.4.1-en.md): visual and interaction fixes, compatible with 0.4.0.
21
+ - [0.4.0 release and migration](docs/release-0.4.0-en.md): what the minor series adds and how to upgrade from `0.3.1` / `local-draft-1`.
22
+
23
+ ## Write a document
24
+
25
+ ```markdown
26
+ <panel title="Cost estimate">
27
+ <slider bind="people" label="People" initial="2" min="1" max="20">
28
+ <toggle bind="annual" label="Annual billing">
29
+ </panel>
30
+
31
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.
32
+ ```
33
+
34
+ Inputs update the result immediately, and the panel includes a restore-defaults action. A standalone counter is a single line: `<counter label="People">`.
35
+
36
+ `0.4.0` adds `local-draft-2`, named calculations, validation, collections, themes and offline HTML export. The earlier `0.3.1` release uses `local-draft-1`. See [0.4.0 release and migration](docs/release-0.4.0-en.md).
37
+
38
+ ## Install
39
+
40
+ Reactive MD requires Node.js 22.12 or newer and ships only ESM entries:
41
+
42
+ ```sh
43
+ npm install reactive-md
44
+ ```
45
+
46
+ Both `latest` and `next` resolve to `0.4.1`; pin it with `npm install reactive-md@0.4.1`. Read the migration guide before upgrading from `0.3.1` / `local-draft-1`.
47
+
48
+ The `reactive-md` entry provides the local compiler, expressions and runtime; `reactive-md/react` provides the React renderer. Import component styles from `reactive-md/styles.css`.
49
+
50
+ The core `reactive-md` entry does not depend on React:
51
+
52
+ ```js
53
+ import { compileLocal, createLocalRuntime } from 'reactive-md';
54
+
55
+ const result = compileLocal('<number bind="n" label="Count" initial="2">');
56
+ if (result.ok) {
57
+ const runtime = createLocalRuntime(result.document);
58
+ try { console.log(runtime.text('Total: {{ n * 100 }}')); }
59
+ finally { runtime.dispose(); }
60
+ }
61
+ ```
62
+
63
+ See [Local mode integration](docs/local-integration-en.md) for the full compile and runtime APIs, host URL policy, lifecycle and style overrides.
64
+
65
+ 0.x minor releases may contain breaking changes. Before upgrading, read the [changelog](CHANGELOG.md) and [compatibility rules](docs/compatibility-en.md), and keep the original `.reactive.md` sources.
66
+
67
+ ## Use with React
68
+
69
+ The React entry requires React 19:
70
+
71
+ ```sh
72
+ npm install react@19 react-dom@19
73
+ ```
74
+
75
+ ```tsx
76
+ import { LocalReactiveDocument } from 'reactive-md/react';
77
+ import 'reactive-md/styles.css';
78
+
79
+ export function Article({ source }: { source: string }) {
80
+ return <LocalReactiveDocument source={source} />;
81
+ }
82
+ ```
83
+
84
+ `LocalReactiveDocument` compiles and manages the runtime for you. To control compilation, lifecycle or URL policy yourself, use `LocalDocumentView` as described in [Local mode integration](docs/local-integration-en.md).
85
+
86
+ ## Share documents
87
+
88
+ Build a self-contained HTML file that readers can open offline, or a script-free static snapshot:
89
+
90
+ ```sh
91
+ npm run build
92
+ npx reactive-md build examples/local/counter.reactive.md -o counter.html
93
+ npx reactive-md build examples/local/counter.reactive.md -o counter-static.html --mode static
94
+ ```
95
+
96
+ The interactive file embeds the original source, React 19, the runtime, styles and any verified local images. It hydrates a static first screen, so it remains readable with JavaScript disabled. Use `--state-file doc.state.json` to export a saved `reactive-md-state/v1` baseline; without it, the author initial values are used and become the reader's reset baseline. The demo export dialog can save the current preview parameters as such a file.
97
+
98
+ See [Shareable documents and static export](docs/shareable-export-en.md) for image limits, CSP/security, printing, exit codes, `ReactiveMD.mount`/`mountAll` and `<reactive-md-doc>`.
99
+
100
+ ## Try the demo
101
+
102
+ ```sh
103
+ npm ci
104
+ npm run dev
105
+ ```
106
+
107
+ The command builds the language package first, then starts the standalone `demo/` app at `http://127.0.0.1:5173`. `/embed.html` demonstrates the embedding approach. The masthead language toggle switches the demo between English and Chinese, and the choice is saved in the browser. The demo pages, editor, demo server, assets and browser checks all live in `demo/` and integrate through the package's public entries.
108
+
109
+ ## Repository layout
110
+
111
+ ```text
112
+ src/ Local syntax compilation, expressions, runtime and React renderer
113
+ examples/ Copyable local interactive examples, independent of the demo app
114
+ docs/ Local syntax specification, integration and release documentation
115
+ tests/ Language and renderer tests
116
+ demo/ Standalone Playground app
117
+ ```
118
+
119
+ ## Documentation
120
+
121
+ - [Beginner guide](docs/local-guide-en.md) and [local interaction syntax specification](docs/local-interaction-syntax-en.md).
122
+ - [Local mode integration](docs/local-integration-en.md): core and React API, URL policy, lifecycle, styling and version pinning.
123
+ - [Shareable documents and static export](docs/shareable-export-en.md): CLI build/lint, state files, local image inlining, printing and the standalone browser runtime.
124
+ - [Feature tours and examples](examples/local/README.md) and [standalone integrations](examples/integration/README.md).
125
+ - [Versions and compatibility](docs/compatibility-en.md): 0.x rules, migration, diagnostics and supported platforms.
126
+ - [0.4.0 release and migration](docs/release-0.4.0-en.md): the upgrade checklist for this release.
127
+ - [Component protocol](docs/component-protocol-en.md) and [component development guide](docs/component-development-en.md): contribution contracts, a proposal template and acceptance cases.
128
+ - [Performance measurements](docs/performance-en.md) and [release checklist](docs/releasing-en.md).
129
+
130
+ See the [contributing guide](CONTRIBUTING.md) for development and test commands.
131
+
132
+ ## Support and status
133
+
134
+ - CI targets Node 22.12 and Node 24 with Playwright Chromium; local browser checks use Microsoft Edge. The packed check covers static SSR, and `npm run test:shareable` covers the single-file export's static-first hydration. General SSR hydration outside that path, Firefox and WebKit remain unverified.
135
+ - 0.x minor releases may contain breaking changes. Persist the original `.reactive.md` source, not the runtime AST or in-memory state.
136
+ - `0.4.1` is available on both `latest` and `next`. Security fixes may ship in minor releases.
137
+
138
+ ## Contributing and security
139
+
140
+ - [Contributing guide](CONTRIBUTING.md): environment, check commands and change requirements.
141
+ - [Security policy](SECURITY.md): threat boundary, resource limits, host responsibilities and vulnerability reporting.
142
+ - [Changelog](CHANGELOG.md).
143
+ - [Release checklist](docs/releasing-en.md): the verification gate, notices, tarball and the manual release flow for maintainers.
144
+
145
+ ## License
146
+
147
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -1,45 +1,72 @@
1
1
  # Reactive MD
2
2
 
3
- [English](README.en.md)
3
+ [English](README-en.md) · [中文](README-ch.md)
4
4
 
5
- 用 Markdown 写本地交互文档。放入输入控件,用 `bind` 命名参数,用 `{{ 表达式 }}` 连接文字、公式、图表和图解。文档作者无需编写 JavaScript 或 CSS。
5
+ Write local interactive documents in Markdown. Add input controls, name parameters with `bind`, and connect prose, formulas, charts and diagrams with `{{ expressions }}`. Document authors do not write JavaScript or CSS.
6
6
 
7
- 本地模式采用 HTML 风格标签,参数和表格数据直接写在正文中,LaTeX 公式可用于函数绘图。TypeScript 核心和 React 渲染器可独立集成。当前为 `0.3.1` 预览版,语法修订 `local-draft-1`。
7
+ Local mode uses HTML-style tags, with parameters and table data written directly in the prose; LaTeX formulas can drive function plots. The TypeScript core and the React renderer can be integrated independently. `0.4.1` is the current 0.x preview on both `latest` and `next`, with syntax revision `local-draft-2`. See [README-ch.md](README-ch.md) for the Chinese overview.
8
8
 
9
- ## 从这里开始
9
+ ## Start here
10
10
 
11
- - [新用户入门指南](docs/local-guide.md):从 Markdown 过渡到交互文档,含完整练习与错误速查。
12
- - [本地交互语法规范](docs/local-interaction-syntax.md) · [12 份 Demo](examples/local/README.md):33 个组件名、标签、就地参数与 LaTeX 绘图。
13
- - [本地模式集成](docs/local-integration.md):`compileLocal`、状态运行时、React 嵌入、URL 策略与样式作用域。
14
- - [独立接入示例](examples/integration/README.md):可复制到仓库外运行的 Node 核心和 React 页面。
15
- - [版本与兼容性](docs/compatibility.md):0.x 规则、迁移、诊断契约和平台范围。
16
- - [组块协议](docs/component-protocol.md) · [组块开发指南](docs/component-development.md):新增组件的声明、行为契约和兼容性验收。
17
- - [Demo 说明](https://github.com/yao1145/ReactiveMD/blob/main/demo/README.md)。
11
+ - [Beginner guide](docs/local-guide-en.md): move from Markdown to interactive documents, with a complete exercise and an error quick reference.
12
+ - [Local interaction syntax specification](docs/local-interaction-syntax-en.md) · [Feature tours and examples](examples/local/README.md): 48 tag names, tags, in-place parameters and LaTeX plots.
13
+ - [Local mode integration](docs/local-integration-en.md): `compileLocal`, the state runtime, React embedding, URL policy and style scoping.
14
+ - [Shareable documents and static export](docs/shareable-export-en.md): single-file interactive HTML, static output, versioned state files, assets, the CLI and the standalone browser API.
15
+ - [Theme protocol](docs/theme-protocol-en.md): document theme selection, custom CSS and light/dark modes.
16
+ - [Author tools](docs/author-tools-en.md): source highlighting, completion, binding navigation, rename, formatting and command-line lint.
17
+ - [Standalone integration examples](examples/integration/README.md): Node core and React pages you can copy and run outside the repository.
18
+ - [Versions and compatibility](docs/compatibility-en.md): 0.x rules, migration, the diagnostics contract and supported platforms.
19
+ - [Component protocol](docs/component-protocol-en.md) · [Component development guide](docs/component-development-en.md): declarations, behavior contracts and compatibility acceptance for new components.
20
+ - [0.4.1 release notes](docs/release-0.4.1-en.md): visual and interaction fixes, compatible with 0.4.0.
21
+ - [0.4.0 release and migration](docs/release-0.4.0-en.md): what the minor series adds and how to upgrade from `0.3.1` / `local-draft-1`.
18
22
 
19
- ## 写一份文档
23
+ ## Write a document
20
24
 
21
25
  ```markdown
22
- <panel title="费用估算">
23
- <slider bind="people" label="人数" initial="2" min="1" max="20">
24
- <toggle bind="annual" label="年度付款">
26
+ <panel title="Cost estimate">
27
+ <slider bind="people" label="People" initial="2" min="1" max="20">
28
+ <toggle bind="annual" label="Annual billing">
25
29
  </panel>
26
30
 
27
- 每月费用:**{{ people * (annual ? 80 : 100) }} 元**。
31
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.
28
32
  ```
29
33
 
30
- 输入立即更新结果,面板自带“恢复默认”。独立使用的计数器只需一行 `<counter label="人数">`。
34
+ Inputs update the result immediately, and the panel includes a restore-defaults action. A standalone counter is a single line: `<counter label="People">`.
31
35
 
32
- ## 安装
36
+ `0.4.0` adds `local-draft-2`, named calculations, validation, collections, themes and offline HTML export. The earlier `0.3.1` release uses `local-draft-1`. See [0.4.0 release and migration](docs/release-0.4.0-en.md).
33
37
 
34
- 需要 Node.js 22.12 或更新版本,包提供 ESM 入口:
38
+ ## Install
39
+
40
+ Reactive MD requires Node.js 22.12 or newer and ships only ESM entries:
35
41
 
36
42
  ```sh
37
- npm install reactive-md@0.3.1
43
+ npm install reactive-md
38
44
  ```
39
45
 
40
- `reactive-md` 入口提供本地编译器、表达式和运行时,`reactive-md/react` 提供 React 渲染器。组件样式通过 `reactive-md/styles.css` 引入。
46
+ Both `latest` and `next` resolve to `0.4.1`; pin it with `npm install reactive-md@0.4.1`. Read the migration guide before upgrading from `0.3.1` / `local-draft-1`.
47
+
48
+ The `reactive-md` entry provides the local compiler, expressions and runtime; `reactive-md/react` provides the React renderer. Import component styles from `reactive-md/styles.css`.
49
+
50
+ The core `reactive-md` entry does not depend on React:
41
51
 
42
- React 入口需要 React 19:
52
+ ```js
53
+ import { compileLocal, createLocalRuntime } from 'reactive-md';
54
+
55
+ const result = compileLocal('<number bind="n" label="Count" initial="2">');
56
+ if (result.ok) {
57
+ const runtime = createLocalRuntime(result.document);
58
+ try { console.log(runtime.text('Total: {{ n * 100 }}')); }
59
+ finally { runtime.dispose(); }
60
+ }
61
+ ```
62
+
63
+ See [Local mode integration](docs/local-integration-en.md) for the full compile and runtime APIs, host URL policy, lifecycle and style overrides.
64
+
65
+ 0.x minor releases may contain breaking changes. Before upgrading, read the [changelog](CHANGELOG.md) and [compatibility rules](docs/compatibility-en.md), and keep the original `.reactive.md` sources.
66
+
67
+ ## Use with React
68
+
69
+ The React entry requires React 19:
43
70
 
44
71
  ```sh
45
72
  npm install react@19 react-dom@19
@@ -54,36 +81,67 @@ export function Article({ source }: { source: string }) {
54
81
  }
55
82
  ```
56
83
 
57
- `reactive-md` 核心入口不依赖 React。完整的编译与运行时 API、宿主 URL 策略、生命周期和样式覆盖见[本地模式集成](docs/local-integration.md)。
84
+ `LocalReactiveDocument` compiles and manages the runtime for you. To control compilation, lifecycle or URL policy yourself, use `LocalDocumentView` as described in [Local mode integration](docs/local-integration-en.md).
58
85
 
59
- 0.x 次版本可能包含破坏性变更。升级前阅读[变更记录](CHANGELOG.md)与[兼容规则](docs/compatibility.md),并保存原始 `.reactive.md` 源码。
86
+ ## Share documents
60
87
 
61
- ## 体验 Demo
88
+ Build a self-contained HTML file that readers can open offline, or a script-free static snapshot:
89
+
90
+ ```sh
91
+ npm run build
92
+ npx reactive-md build examples/local/counter.reactive.md -o counter.html
93
+ npx reactive-md build examples/local/counter.reactive.md -o counter-static.html --mode static
94
+ ```
95
+
96
+ The interactive file embeds the original source, React 19, the runtime, styles and any verified local images. It hydrates a static first screen, so it remains readable with JavaScript disabled. Use `--state-file doc.state.json` to export a saved `reactive-md-state/v1` baseline; without it, the author initial values are used and become the reader's reset baseline. The demo export dialog can save the current preview parameters as such a file.
97
+
98
+ See [Shareable documents and static export](docs/shareable-export-en.md) for image limits, CSP/security, printing, exit codes, `ReactiveMD.mount`/`mountAll` and `<reactive-md-doc>`.
99
+
100
+ ## Try the demo
62
101
 
63
102
  ```sh
64
103
  npm ci
65
104
  npm run dev
66
105
  ```
67
106
 
68
- 该命令先构建语言包,再启动独立的 `demo/` 应用,地址为 `http://127.0.0.1:5173`。`/embed.html` 展示嵌入方式。Demo 的页面、编辑器、演示服务、资产和浏览器检查均在 `demo/`,通过语言包的公开入口集成。
107
+ The command builds the language package first, then starts the standalone `demo/` app at `http://127.0.0.1:5173`. `/embed.html` demonstrates the embedding approach. The masthead language toggle switches the demo between English and Chinese, and the choice is saved in the browser. The demo pages, editor, demo server, assets and browser checks all live in `demo/` and integrate through the package's public entries.
108
+
109
+ ## Repository layout
69
110
 
70
111
  ```text
71
- src/ 本地语法编译、表达式、运行时和 React 渲染器
72
- examples/ 可复制的本地交互示例,与 demo 应用无关
73
- docs/ 本地语法规范、集成与发布文档
74
- tests/ 语言与渲染器测试
75
- demo/ 独立的 Playground 应用
112
+ src/ Local syntax compilation, expressions, runtime and React renderer
113
+ examples/ Copyable local interactive examples, independent of the demo app
114
+ docs/ Local syntax specification, integration and release documentation
115
+ tests/ Language and renderer tests
116
+ demo/ Standalone Playground app
76
117
  ```
77
118
 
78
- 更多开发与测试命令见[贡献指南](CONTRIBUTING.md)。
119
+ ## Documentation
120
+
121
+ - [Beginner guide](docs/local-guide-en.md) and [local interaction syntax specification](docs/local-interaction-syntax-en.md).
122
+ - [Local mode integration](docs/local-integration-en.md): core and React API, URL policy, lifecycle, styling and version pinning.
123
+ - [Shareable documents and static export](docs/shareable-export-en.md): CLI build/lint, state files, local image inlining, printing and the standalone browser runtime.
124
+ - [Feature tours and examples](examples/local/README.md) and [standalone integrations](examples/integration/README.md).
125
+ - [Versions and compatibility](docs/compatibility-en.md): 0.x rules, migration, diagnostics and supported platforms.
126
+ - [0.4.0 release and migration](docs/release-0.4.0-en.md): the upgrade checklist for this release.
127
+ - [Component protocol](docs/component-protocol-en.md) and [component development guide](docs/component-development-en.md): contribution contracts, a proposal template and acceptance cases.
128
+ - [Performance measurements](docs/performance-en.md) and [release checklist](docs/releasing-en.md).
129
+
130
+ See the [contributing guide](CONTRIBUTING.md) for development and test commands.
131
+
132
+ ## Support and status
133
+
134
+ - CI targets Node 22.12 and Node 24 with Playwright Chromium; local browser checks use Microsoft Edge. The packed check covers static SSR, and `npm run test:shareable` covers the single-file export's static-first hydration. General SSR hydration outside that path, Firefox and WebKit remain unverified.
135
+ - 0.x minor releases may contain breaking changes. Persist the original `.reactive.md` source, not the runtime AST or in-memory state.
136
+ - `0.4.1` is available on both `latest` and `next`. Security fixes may ship in minor releases.
79
137
 
80
- ## 贡献与安全
138
+ ## Contributing and security
81
139
 
82
- - [贡献指南](CONTRIBUTING.md):环境、检查命令和改动要求。
83
- - [安全策略](SECURITY.md):威胁边界、资源上限、宿主责任和漏洞报告渠道。
84
- - [变更记录](CHANGELOG.md)。
85
- - [发布清单](docs/releasing.md):维护者的包名、notice、tarball 和人工发布流程。
140
+ - [Contributing guide](CONTRIBUTING.md): environment, check commands and change requirements.
141
+ - [Security policy](SECURITY.md): threat boundary, resource limits, host responsibilities and vulnerability reporting.
142
+ - [Changelog](CHANGELOG.md).
143
+ - [Release checklist](docs/releasing-en.md): the verification gate, notices, tarball and the manual release flow for maintainers.
86
144
 
87
- ## 许可证
145
+ ## License
88
146
 
89
147
  [MIT](LICENSE)
package/SECURITY-ch.md ADDED
@@ -0,0 +1,80 @@
1
+ # 安全策略
2
+
3
+ Reactive MD 渲染作者编写的本地交互文档。文档是不可信输入时,渲染器、表达式和数学求值都按下面的边界处理。宿主仍然负责授权、网络策略和服务端数据。
4
+
5
+ ## 支持范围
6
+
7
+ 当前维护最新的 0.x 预览版本。安全修复可能随次版本发布,并在[变更记录](CHANGELOG-ch.md)中说明影响和迁移步骤。
8
+
9
+ ## 威胁边界
10
+
11
+ 以下保证有编译器、运行时和渲染器测试覆盖;未列出的能力不做承诺。
12
+
13
+ ### 文档内容
14
+
15
+ - 作者不能执行脚本。`<script>`、原始 HTML、`on-*` 事件属性和作者 CSS 不属于 `local-draft-2`,会作为语法诊断或文本处理,不会作为 HTML 执行。
16
+ - React 渲染器不调用 `dangerouslySetInnerHTML`,也不把文档内容写入 `innerHTML`。
17
+ - 表达式使用自己的解析器和 AST 求值器,不使用 `eval`、`new Function`,不支持赋值、方法调用、属性访问、原型路径或导入。表达式只能读取文档声明的参数和内置函数。
18
+ - LaTeX 通过受预算限制的解析器计算,并由原生 MathML 渲染;渲染器不执行宏、文件、网络或 HTML 入口。未知命令显示为文本。
19
+ - 表达式、模板、表格和图表不会发起网络请求;图表数据必须写在文档里。
20
+
21
+ ### URL 与网络
22
+
23
+ - 图片默认全部拒绝,包括相对路径和协议相对地址,因此加载文档本身不会触发图片请求。
24
+ - 只有宿主传入 `urlPolicy` 且策略返回 `true` 时,图片才会加载。带协议的图片地址仍先检查协议,只允许 `http:` 和 `https:`;相对地址则由策略决定。`javascript:`、危险的 `data:` 等地址即使策略放行也会被拒绝。
25
+ - 链接默认允许相对地址和 `http:`、`https:`、`mailto:`、`tel:`;外部 HTTP 链接以新标签打开并带 `noopener noreferrer`。危险协议始终拒绝。
26
+ - 策略抛出异常时拒绝该地址。获准加载的图片使用 `referrerPolicy="no-referrer"`;同源图片仍可能携带 Cookie,图片白名单应避开业务 API。
27
+ - 受信任的 `imageResolver` 只在图片地址通过协议检查和 `urlPolicy` 后运行,把允许的地址映射为宿主控制的输出;导出文件只使用经过验证的 `data:image/png|jpeg|gif|webp;base64` 值,链接不会进入该回调。
28
+ - `urlPolicy` 是 URL 允许列表,不是服务端授权。宿主仍需配置 CSP、网络出口、图片代理或沙箱 iframe(当作者完全不可信时)。
29
+
30
+ ### 资源上限
31
+
32
+ `src/local/limits.ts` 定义共享上限,编译、运行时和可视化共同使用:
33
+
34
+ | 限制 | 值 |
35
+ | --- | --- |
36
+ | 单份文档源码 | 1,000,000 字符 |
37
+ | 解析期间累计创建的语法节点 | 默认 10,000,由宿主按次配置 |
38
+ | 单个字符串值或模板 | 100,000 字符 |
39
+ | 单个数组 | 10,000 项 |
40
+ | 数组内字符串总长度 | 100,000 字符 |
41
+ | 邮箱地址 | 254 字符,线性校验 |
42
+ | 诊断数量 | 100 条 |
43
+ | 单条诊断文本 | 2,000 字符 |
44
+ | 每个绘图组件的曲线数 | 16 |
45
+ | 整篇文档请求的曲线采样点 | 20,000 |
46
+ | 绘图共享计算步数 | 2,000,000 |
47
+
48
+ 超限写入会被拒绝,运行时保持上一次合法状态;编译期超限返回诊断。绘图和数学计算还有各自的深度、记号和节点预算。预算用于限制单个文档的工作量,不替代宿主对请求大小、并发和超时的控制。
49
+
50
+ 宿主通过 `compileLocal(source, { limits: { maxSyntaxNodes } })` 为单次编译调整语法节点预算,取值必须是正的安全整数。文档内容不能修改该设置。省略时保留 10,000 的默认预算;提高节点预算不会改变源码长度、数组、表达式或绘图的其他上限。计数覆盖解析中创建的全部 `LocalNode`,包含部分最终未保留的中间节点。
51
+
52
+ ### 状态与隔离
53
+
54
+ - 参数状态只存在于当前文档实例的内存中。每个 `LocalReactiveDocument` 或 `LocalDocumentView` 实例独立;销毁时会清理订阅、表达式缓存和计时器。
55
+ - `createLocalRuntime` 会校验初值和共享控件的约束;`set` 以文档中登记的控件为准,忽略调用方伪造的节点元数据,并且只有在所有共享控件都接受时才原子提交。
56
+ - `snapshot()` 返回稳定的冻结快照,其中的数组也被冻结;`get()` 和 `evaluate()` 返回数组副本。状态更新通过 `set()` 校验后提交。
57
+ - `disabled` 和 `if` 只是界面展示状态,不是权限控制。业务权限和值校验必须由宿主在提交到服务端时执行。
58
+
59
+ ### 可分享 HTML 导出
60
+
61
+ - `reactive-md-state/v1` 只保存公开绑定名和可序列化值,不保存 `@` 内部绑定、revision、节点 ID、AST、UI 状态或计时器。导入前会校验源码摘要、语法、参数集合和每个值;未知或冲突键会拒绝整个文件。
62
+ - 交互式 HTML 内嵌固定版本的独立运行时,CSP 禁止网络连接、frame、object、base 注入和表单提交,只允许内联样式/运行时与 `data:` 图片。JSON、源码、标题和 notices 会按 HTML/脚本上下文转义。
63
+ - CLI 只内联位于文档目录或显式资源根内的相对位图。它拒绝远程图片、URL scheme、绝对路径、路径穿越、符号链接逃逸、SVG、伪造格式和超限资源。Demo 导出对话框在包含图片时会禁用 HTML 导出。
64
+ - 静态 HTML 不包含运行时脚本或自动挂载载荷。静态首屏水合目前只在单文件 Chromium/Edge 路径验证,不构成通用水合或沙箱保证。作者完全不可信时应使用 sandboxed iframe。
65
+ - 导出当前参数是宿主/读者的显式动作。生成的状态文件和 HTML 可能包含敏感信息;除非确实要分享当前值,否则应选择作者初值。
66
+
67
+ ## 宿主责任
68
+
69
+ - 决定谁可以编写、提交和分享文档;限制不可信作者的请求大小、并发和执行时间。编译 1,000,000 字符的文档仍是真实的 CPU 工作。
70
+ - 为图片和链接配置 `urlPolicy`;维持 CSP、网络出口控制和图片白名单。
71
+ - 在服务端重新校验表单值、权限和业务约束,不信任文档中的 `disabled`、条件显示或客户端状态。
72
+ - 需要持久化时,安全地保存原始 `.reactive.md` 源码;运行时状态和 `LocalDocument` 不应当作持久化格式。
73
+ - 在服务端静态渲染不可信文档之前,评估渲染进程的资源上限;通用 SSR 水合仍未验证,只有单文件静态首屏路径在 Chromium/Edge 有覆盖。水合不应作为安全边界。
74
+ - 第三方依赖漏洞应同时报告给上游项目;本包只负责自身集成代码。
75
+
76
+ ## 报告漏洞
77
+
78
+ 仓库已启用 GitHub 私密漏洞报告。请通过 [Report a vulnerability](https://github.com/yao1145/ReactiveMD/security/advisories/new) 提交受影响版本、最小复现、预期影响和修复建议。
79
+
80
+ 使用私密渠道报告漏洞细节;公开 issue 和 PR 中请移除利用代码、凭据、用户数据及受影响部署的信息。