reactive-md 0.3.1 → 0.4.0

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 (172) hide show
  1. package/CHANGELOG-ch.md +96 -0
  2. package/CHANGELOG.md +82 -39
  3. package/CONTRIBUTING-ch.md +62 -0
  4. package/CONTRIBUTING.md +64 -65
  5. package/README-ch.md +122 -0
  6. package/README-en.md +146 -0
  7. package/README.md +146 -89
  8. package/SECURITY-ch.md +80 -0
  9. package/SECURITY.md +58 -49
  10. package/THIRD_PARTY_NOTICES.md +85 -1
  11. package/bin/reactive-md.mjs +40 -0
  12. package/cli/args.mjs +181 -0
  13. package/cli/assets.mjs +390 -0
  14. package/cli/build.mjs +268 -0
  15. package/cli/document.mjs +130 -0
  16. package/cli/errors.mjs +61 -0
  17. package/cli/fs-utils.mjs +133 -0
  18. package/cli/glob.mjs +203 -0
  19. package/cli/help.mjs +138 -0
  20. package/cli/lint.mjs +177 -0
  21. package/cli/main.mjs +55 -0
  22. package/cli/migrate.mjs +368 -0
  23. package/cli/package.mjs +209 -0
  24. package/dist-library/reactive-md-react.js +3425 -1647
  25. package/dist-library/reactive-md.css +1 -1
  26. package/dist-library/reactive-md.js +1798 -4
  27. package/dist-library/runtime-DtjdPXxJ.js +15410 -0
  28. package/dist-library/types/index.d.ts +1 -0
  29. package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
  30. package/dist-library/types/local/authoring.d.ts +63 -0
  31. package/dist-library/types/local/collection-functions.d.ts +4 -0
  32. package/dist-library/types/local/colors.d.ts +2 -0
  33. package/dist-library/types/local/computations.d.ts +53 -0
  34. package/dist-library/types/local/data-functions.d.ts +22 -0
  35. package/dist-library/types/local/data-table.d.ts +65 -0
  36. package/dist-library/types/local/dates.d.ts +2 -0
  37. package/dist-library/types/local/dependencies.d.ts +31 -0
  38. package/dist-library/types/local/diagnostics.d.ts +1450 -0
  39. package/dist-library/types/local/expression.d.ts +13 -3
  40. package/dist-library/types/local/formatting.d.ts +41 -0
  41. package/dist-library/types/local/heading-anchors.d.ts +13 -2
  42. package/dist-library/types/local/i18n.d.ts +18 -0
  43. package/dist-library/types/local/index.d.ts +18 -1
  44. package/dist-library/types/local/limits.d.ts +32 -1
  45. package/dist-library/types/local/locale.d.ts +1 -0
  46. package/dist-library/types/local/math.d.ts +6 -1
  47. package/dist-library/types/local/parser.d.ts +10 -4
  48. package/dist-library/types/local/render-types.d.ts +5 -1
  49. package/dist-library/types/local/retention.d.ts +23 -0
  50. package/dist-library/types/local/schema.d.ts +25 -3
  51. package/dist-library/types/local/source-migration.d.ts +35 -0
  52. package/dist-library/types/local/state.d.ts +80 -0
  53. package/dist-library/types/local/text-length.d.ts +13 -0
  54. package/dist-library/types/local/theme.d.ts +30 -0
  55. package/dist-library/types/local/types.d.ts +112 -4
  56. package/dist-library/types/local/validation.d.ts +32 -0
  57. package/dist-library/types/local/version.d.ts +1 -1
  58. package/dist-library/types/local/worker.d.ts +82 -0
  59. package/dist-library/types/react/index.d.ts +4 -1
  60. package/dist-library/types/shareable.d.ts +64 -0
  61. package/dist-standalone/reactive-md-standalone.css +2 -0
  62. package/dist-standalone/reactive-md-standalone.js +57 -0
  63. package/docs/author-tools-ch.md +56 -0
  64. package/docs/author-tools-en.md +56 -0
  65. package/docs/compatibility-ch.md +103 -0
  66. package/docs/compatibility-en.md +103 -0
  67. package/docs/{component-development.md → component-development-ch.md} +210 -206
  68. package/docs/component-development-en.md +210 -0
  69. package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
  70. package/docs/component-protocol-en.md +710 -0
  71. package/docs/computations-formatting-ch.md +87 -0
  72. package/docs/computations-formatting-en.md +87 -0
  73. package/docs/constraints-collections-ch.md +84 -0
  74. package/docs/constraints-collections-en.md +84 -0
  75. package/docs/diagnostics-counting-ch.md +84 -0
  76. package/docs/diagnostics-counting-en.md +84 -0
  77. package/docs/local-components-v2-ch.md +138 -0
  78. package/docs/local-components-v2-en.md +104 -0
  79. package/docs/{local-guide.md → local-guide-ch.md} +28 -8
  80. package/docs/local-guide-en.md +961 -0
  81. package/docs/local-integration-ch.md +363 -0
  82. package/docs/local-integration-en.md +363 -0
  83. package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
  84. package/docs/local-interaction-syntax-en.md +483 -0
  85. package/docs/{performance.md → performance-ch.md} +12 -3
  86. package/docs/performance-en.md +76 -0
  87. package/docs/release-0.4.0-ch.md +89 -0
  88. package/docs/release-0.4.0-en.md +89 -0
  89. package/docs/releasing-ch.md +101 -0
  90. package/docs/releasing-en.md +101 -0
  91. package/docs/shareable-export-ch.md +205 -0
  92. package/docs/shareable-export-en.md +207 -0
  93. package/docs/source-versioning-ch.md +159 -0
  94. package/docs/source-versioning-en.md +159 -0
  95. package/docs/theme-protocol-ch.md +107 -0
  96. package/docs/theme-protocol-en.md +107 -0
  97. package/examples/conformance/README.md +33 -31
  98. package/examples/conformance/component-protocol-1.json +482 -194
  99. package/examples/conformance/component-protocol-1.schema.json +76 -76
  100. package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
  101. package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
  102. package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
  103. package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
  104. package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
  105. package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
  106. package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
  107. package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
  108. package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
  109. package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
  110. package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
  111. package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
  112. package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
  113. package/examples/conformance/history/v0.3.1/provenance.json +72 -0
  114. package/examples/conformance/local-draft-2.json +212 -0
  115. package/examples/integration/README.md +45 -29
  116. package/examples/integration/core/index.mjs +32 -19
  117. package/examples/integration/react/index.html +1 -1
  118. package/examples/integration/react/main.jsx +5 -5
  119. package/examples/integration/worker/index.html +19 -0
  120. package/examples/integration/worker/main.js +61 -0
  121. package/examples/integration/worker/package.json +13 -0
  122. package/examples/integration/worker/worker.js +3 -0
  123. package/examples/local/README.md +64 -58
  124. package/examples/local/catalog.reactive.md +14 -14
  125. package/examples/local/charts.reactive.md +34 -34
  126. package/examples/local/checklist.reactive.md +19 -19
  127. package/examples/local/comparison.reactive.md +23 -23
  128. package/examples/local/components.reactive.md +20 -20
  129. package/examples/local/counter.reactive.md +4 -4
  130. package/examples/local/diagnostics.reactive.md +25 -25
  131. package/examples/local/diagram.reactive.md +20 -20
  132. package/examples/local/gallery.reactive.md +31 -31
  133. package/examples/local/parameters.reactive.md +19 -19
  134. package/examples/local/planning.reactive.md +15 -15
  135. package/examples/local/pricing.reactive.md +10 -10
  136. package/examples/local/recipes/invoice-zh.reactive.md +36 -0
  137. package/examples/local/recipes/invoice.reactive.md +36 -0
  138. package/examples/local/recipes/workshop-zh.reactive.md +33 -0
  139. package/examples/local/recipes/workshop.reactive.md +33 -0
  140. package/examples/local/showcase/README.md +25 -0
  141. package/examples/local/showcase/explore.reactive.md +102 -0
  142. package/examples/local/showcase/flow.reactive.md +86 -0
  143. package/examples/local/showcase/forms.reactive.md +126 -0
  144. package/examples/local/showcase/functions.reactive.md +119 -0
  145. package/examples/local/showcase/layout.reactive.md +100 -0
  146. package/examples/local/showcase/statistics.reactive.md +108 -0
  147. package/examples/local/showcase/tasks.reactive.md +89 -0
  148. package/examples/local/showcase/zh/explore.reactive.md +102 -0
  149. package/examples/local/showcase/zh/flow.reactive.md +86 -0
  150. package/examples/local/showcase/zh/forms.reactive.md +126 -0
  151. package/examples/local/showcase/zh/functions.reactive.md +119 -0
  152. package/examples/local/showcase/zh/layout.reactive.md +100 -0
  153. package/examples/local/showcase/zh/statistics.reactive.md +108 -0
  154. package/examples/local/showcase/zh/tasks.reactive.md +89 -0
  155. package/examples/local/zh/catalog.reactive.md +20 -0
  156. package/examples/local/zh/charts.reactive.md +73 -0
  157. package/examples/local/zh/checklist.reactive.md +32 -0
  158. package/examples/local/zh/comparison.reactive.md +47 -0
  159. package/examples/local/zh/components.reactive.md +44 -0
  160. package/examples/local/zh/counter.reactive.md +7 -0
  161. package/examples/local/zh/diagnostics.reactive.md +54 -0
  162. package/examples/local/zh/diagram.reactive.md +44 -0
  163. package/examples/local/zh/gallery.reactive.md +61 -0
  164. package/examples/local/zh/parameters.reactive.md +36 -0
  165. package/examples/local/zh/planning.reactive.md +24 -0
  166. package/examples/local/zh/pricing.reactive.md +20 -0
  167. package/package.json +16 -3
  168. package/README.en.md +0 -76
  169. package/dist-library/runtime-CPzMEMcW.js +0 -11111
  170. package/docs/compatibility.md +0 -68
  171. package/docs/local-integration.md +0 -218
  172. package/docs/releasing.md +0 -92
@@ -0,0 +1,89 @@
1
+ # 0.4.0 预览与迁移
2
+
3
+ 状态:发布在 `next` 分发渠道的预览版。包版本 `0.4.0`,语法修订 `local-draft-2`,组块协议 `component-protocol-1`,主题协议 `reactive-md-theme-1`。这些是彼此独立的版本轴;`local-draft-2`、`component-protocol-1` 和 `reactive-md-theme-1` 都不是包版本。
4
+
5
+ 使用 `npm install reactive-md@next` 安装预览版,或用 `npm install reactive-md@0.4.0` 固定版本。`0.3.1` 仍为 `latest` 版本。
6
+
7
+ 本文汇总 0.4.0 包含的能力、对现有文档和宿主的变化,以及从 `0.3.1` / `local-draft-1` 升级的步骤。具体规则仍以链接的参考页为准;本页是升级清单。显式修订声明和迁移工具见[源码修订与迁移](source-versioning-ch.md)。
8
+
9
+ ## 适合哪些项目
10
+
11
+ - 需要命名计算、格式化、校验、集合、新输入类型、主题或离线 HTML 导出的作者。
12
+ - 可以把宿主更新到 `local-draft-2`,并愿意补充 `LocalValueKind` 穷举、运行时适配器和状态处理的宿主。
13
+ - 固定使用 `0.3.1`、只需要 `local-draft-1` 的项目可以继续留在旧版本;它仍为 `latest`。当前构建只接受一个语法修订,不提供独立的 `local-draft-1` 模式;使用受支持旧写法的无指令源码按 `local-draft-2` 规则读取,显式 `local-draft-1` 声明必须先迁移。
14
+
15
+ ## 0.4.0 包含的能力
16
+
17
+ | 范围 | 内容 |
18
+ | --- | --- |
19
+ | 语法 | 十个 `local-draft-2` 组块:`jump`、`anchor`、`text`、`section`、`multi-select`、`range-slider`、`coordinate`、`quiz`、`steps`、`step` |
20
+ | 源码修订 | 可选的 `local-draft-2` 指令、版本查看与升级检查、单份源码的元数据迁移 |
21
+ | 计算 | 顶层 `<const>` 与 `<computed>` 声明,支持依赖排序、类型推断、循环检测和运行时独立缓存 |
22
+ | 表达式 | 字符串与数字数组字面量、索引、`sum`/`average`/`minOf`/`maxOf`、数字/百分比/科学计数法/货币格式化、文本函数及 UTC 日期比较与日期差 |
23
+ | 校验与数据 | 提示型 `<validation>` 规则、`runtime.validate()`、`alert`/`badge` 动态 `tone`、带稳定行键的 `<data-table>`/`<column>` |
24
+ | 外观 | `<theme name="…">`、宿主主题登记、文档深浅模式、组块主色和清单完成样式 |
25
+ | 诊断 | 中英文共享诊断目录,渲染器、Playground 与 CLI 按语言显示,机器字段保持稳定 |
26
+ | 宿主状态 | 按名称读写公开参数、`exportLocalState`/`importLocalState`、参数保留工具和可选的 Worker 编译 |
27
+ | 导出 | `reactive-md build`/`lint`、交互与静态单文件 HTML、版本化状态文件、经校验的本地位图内联、standalone `ReactiveMD.mount`/`mountAll` 和 `<reactive-md-doc>` |
28
+ | 作者工具 | 高亮、补全、绑定定位、重命名、格式化及 `lint --locale en|zh` |
29
+ | 渲染 | 依赖感知的渲染,避免重算未受影响的文档子树 |
30
+
31
+ 可运行示例见[示例索引](../examples/local/README.md),包括六个双语功能场景、账单示例和工作坊示例。全部可接受的标签名见[语法规范](local-interaction-syntax-ch.md#12-组件速查与语法裁剪)。
32
+
33
+ ## 从 0.3.1 / local-draft-1 升级
34
+
35
+ 无指令源码中,`local-draft-1` 已支持的写法继续有效;下面这些变化仍需要检查源码和宿主。
36
+
37
+ ### 新增保留标识符
38
+
39
+ 新增表达式函数名不能再用作控件绑定名。升级前请重命名以下同名旧绑定并同步修改引用:
40
+
41
+ `sum`、`average`、`minOf`、`maxOf`、`formatNumber`、`formatPercent`、`formatScientific`、`formatCurrency`、`trim`、`lower`、`upper`、`startsWith`、`endsWith`、`replace`、`slice`、`dateCompare`、`dateDiff`。
42
+
43
+ 它们与原有保留名共同生效:数学与集合函数(`abs`、`sqrt`、`floor`、`ceil`、`round`、`min`、`max`、`pow`、`sin`、`cos`、`tan`、`asin`、`acos`、`atan`、`exp`、`log`、`len`、`contains`、`clamp`)、常量 `pi` 与 `e`、绘图名 `x` 与 `y`、字面量 `true`、`false`、`null`,以及 `__proto__`、`prototype`、`constructor`。详见[复用计算与格式化数值](computations-formatting-ch.md#兼容性)。
44
+
45
+ ### 新增可识别标签名
46
+
47
+ 当前构建会把以下名称解释为标签:`jump`、`anchor`、`text`、`section`、`multi-select`、`range-slider`、`coordinate`、`quiz`、`steps`、`step`、`computed`、`const`、`validation`、`data-table`、`column`。
48
+
49
+ 如果旧文档把这些名称当作普通正文,或作为“未知标签按原文显示”的示例,现在会被解析为组块或声明。请把这类示例放进行内代码、代码围栏,或转义标签,并核对新增保留名与下列行为变化。
50
+
51
+ 开头的 `<theme name="…">` 是文档元数据,不是组块;它同样只允许在正文前声明一次。
52
+
53
+ ### 修订声明与迁移
54
+
55
+ 源码可以在前导区声明 `<!-- reactive-md: local-draft-2 -->`。无指令源码保持当前修订的行为。显式 `local-draft-1` 或未知修订会以 `local.version.*` 诊断拒绝,不创建运行时;声明旧修订不会选择旧解析器。
56
+
57
+ `reactive-md migrate` 或纯核心 `migrateLocalSource` 把单份源码迁移到 `local-draft-2`。迁移只替换或补上元数据注释,保留正文原始字节、BOM 和 CRLF。写出结果前会阻止新增保留绑定、新增可识别标签、当前编译错误和文本控件长度语义变化;不重命名标识符,也不激活原先按原文显示的标签。清单完成样式属于兼容例外,不阻止迁移。迁移会改变源码摘要,之后应重新导出状态文件。在这一声明之前构建的读者(包括 `0.3.1`)会把它当作普通注释,不执行检查,因此应先迁移旧文档。
58
+
59
+ ### 行为变化
60
+
61
+ - 清单中已勾选的条目现在加删除线并变淡,包括初始 `[x]` 条目。
62
+ - `alert` 与 `badge` 可以在现有枚举内使用动态 `tone` 表达式。
63
+ - 提供 `key`(稳定标识列)时,`table` 和 `chart` 可通过 `bind` 公开选择状态;没有 `key` 的旧表格仍只在渲染器内部保存选择。
64
+ - 文本控件的 `min-length` 与 `max-length` 按 Unicode 码点计数,与字符串 `len()` 一致。原先因 emoji 占两个 UTF-16 代码单元而失败的值现在可能通过;源码位置和资源预算仍按 UTF-16 计算。
65
+ - `document.bindings` 与 `document.initialState` 仍只描述可写控件;`runtime.snapshot().state` 还会包含成功求值的命名计算结果,宿主不能假设快照里只有控件。
66
+ - `LocalValueKind` 增加 `number-array`,`LocalValue` 增加 `number[]`;可写的清单与多选控件仍产生字符串数组。
67
+ - 自定义运行时适配器需要补充 `validate()`;多槽控件使用 `get(node, slot?)`、`set(node, value, slot?)` 和 `setMany(node, values)`。
68
+ - 状态文件携带 `syntax: "local-draft-2"` 和源码摘要。语法修订、摘要或公开参数集合不一致时会拒绝整个文件。
69
+ - 显示用诊断通过共享目录本地化;回调仍收到结构化诊断。`message` 是显示文本,不是 API。
70
+
71
+ ## 升级清单
72
+
73
+ 1. 从 `next` 安装 `0.4.0` 或固定 `0.4.0`,保存原始 `.reactive.md` 源码,并记录 `LOCAL_SYNTAX_VERSION`。
74
+ 2. 对每份源码运行 `reactive-md migrate <file> --check` 或 `migrateLocalSource`。无版本声明的历史文档要加 `--from local-draft-1`;写出结果前处理全部阻止项。
75
+ 3. 在代码区域之外搜索 15 个新增可识别标签名,按需要转义或放进代码。
76
+ 4. 搜索 `bind`、`bind-start`、`bind-end`、`bind-x`、`bind-y` 的值,确认没有 17 个新增保留标识符;如有则重命名绑定和引用。核心入口的 `renameLocalBinding` 和编辑器重命名会同时更新声明、表达式引用与绘图参数。
77
+ 5. 重新编译全部文档,处理新增的位置或结构诊断,尤其是顶层 `computed`/`const`、`validation`、`data-table`/`column`、`steps`/`step` 和 `quiz`。
78
+ 6. 更新宿主对 `number-array`、`validate()`、槽位 API 和包含计算值的快照的处理。
79
+ 7. 重新检查状态导入导出、参数保留和宿主内的 HTML 导出。迁移会改变源码摘要,应重新导出状态文件。
80
+ 8. 检查可见变化:清单完成样式、表格/图表选择和主题 CSS。
81
+ 9. 运行[发布验证入口](../CONTRIBUTING-ch.md),并用自己的文档和浏览器检查复验。
82
+
83
+ ## 验证范围
84
+
85
+ `0.4.0` 面向 Node.js 22.12 与 Node 24;CI 门禁使用 Playwright Chromium,本地检查使用 Microsoft Edge。`npm run verify:release` 是完整发布门禁:覆盖核心与 Demo 测试、类型、包与文档检查、仓库外真实 tarball 消费,以及计算、集合、作者工具、状态恢复、HTML 导出的浏览器检查和渲染等价检查。单项命令仍列在[贡献指南](../CONTRIBUTING-ch.md)。
86
+
87
+ 静态 SSR 由 packed 检查覆盖。单文件导出的静态首屏水合由 Playwright Chromium 和本地 Edge 检查覆盖。该路径之外的通用 SSR 水合、Firefox 与 Safari/WebKit 尚未验证,不作支持声明。
88
+
89
+ 版本规则与诊断契约见[版本与兼容性](compatibility-ch.md),修订指令与迁移工具见[源码修订与迁移](source-versioning-ch.md),HTML 与状态格式见[可分享文档与静态导出](shareable-export-ch.md),组块新增见[local-draft-2 扩展说明](local-components-v2-ch.md)。
@@ -0,0 +1,89 @@
1
+ # 0.4.0 preview and migration
2
+
3
+ Status: preview release on the `next` distribution channel. Package version `0.4.0`, syntax revision `local-draft-2`, component protocol `component-protocol-1`, theme protocol `reactive-md-theme-1`. These are separate version axes; `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1` are not package versions.
4
+
5
+ Install the preview with `npm install reactive-md@next`, or pin it with `npm install reactive-md@0.4.0`. `0.3.1` remains the `latest` release.
6
+
7
+ This page summarizes what 0.4.0 contains, what changes for existing documents and hosts, and how to move from `0.3.1` / `local-draft-1`. Detailed rules remain in the linked reference pages; this page is the upgrade checklist. Explicit revision declarations and the migration tools are specified in [Source revisions and migration](source-versioning-en.md).
8
+
9
+ ## Who should upgrade
10
+
11
+ - Authors who need named calculations, formatting, validation, collections, new input types, themes or offline HTML export.
12
+ - Hosts that can adopt `local-draft-2` and update exhaustive `LocalValueKind` checks, runtime adapters and state handling.
13
+ - Projects that pin `0.3.1` and only need `local-draft-1` can stay there; it remains the `latest` release. The build accepts one syntax revision and has no separate `local-draft-1` mode; unversioned source in supported old forms is read under `local-draft-2` rules, while an explicit `local-draft-1` declaration must be migrated first.
14
+
15
+ ## What 0.4.0 contains
16
+
17
+ | Area | Included |
18
+ | --- | --- |
19
+ | Syntax | Ten `local-draft-2` components: `jump`, `anchor`, `text`, `section`, `multi-select`, `range-slider`, `coordinate`, `quiz`, `steps`, `step` |
20
+ | Source revisions | Optional `local-draft-2` directive, version inspection and upgrade checks, and single-source metadata migration |
21
+ | Calculations | Top-level `<const>` and `<computed>` declarations with dependency ordering, inferred types, cycle detection and per-runtime caching |
22
+ | Expressions | String and numeric array literals, indexing, `sum`/`average`/`minOf`/`maxOf`, number/percent/scientific/currency formatting, text functions and UTC date comparison/differences |
23
+ | Validation and data | Advisory `<validation>` rules, `runtime.validate()`, dynamic `alert`/`badge` tones, `<data-table>`/`<column>` row generation with stable keys |
24
+ | Appearance | `<theme name="…">`, host theme registration, document color schemes, component accent colors and completed-checklist styling |
25
+ | Diagnostics | Shared English/Chinese catalogue and localization in the renderer, Playground and CLI, with stable machine fields |
26
+ | Host state | Public parameter access by name, `exportLocalState`/`importLocalState`, retention helpers and optional Worker compilation |
27
+ | Export | `reactive-md build`/`lint`, interactive and static single-file HTML, versioned state files, verified local raster inlining, standalone `ReactiveMD.mount`/`mountAll` and `<reactive-md-doc>` |
28
+ | Author tools | Highlighting, completion, binding navigation, rename, formatting and `lint --locale en|zh` |
29
+ | Rendering | Dependency-aware rendering that avoids recomputing unaffected document subtrees |
30
+
31
+ The runnable examples are in the [example index](../examples/local/README.md), including the six bilingual feature tours, the invoice recipe and the workshop recipe. Every accepted tag name is listed in the [syntax specification](local-interaction-syntax-en.md#12-component-reference-and-syntax-scope).
32
+
33
+ ## Upgrade from 0.3.1 / local-draft-1
34
+
35
+ Unversioned source in previously supported `local-draft-1` forms keeps its supported forms. The changes below still require a source and host review.
36
+
37
+ ### Newly reserved identifiers
38
+
39
+ The new expression functions are reserved binding names. Rename any existing control binding with one of these names and update its references before upgrading:
40
+
41
+ `sum`, `average`, `minOf`, `maxOf`, `formatNumber`, `formatPercent`, `formatScientific`, `formatCurrency`, `trim`, `lower`, `upper`, `startsWith`, `endsWith`, `replace`, `slice`, `dateCompare`, `dateDiff`.
42
+
43
+ These join the existing reserved names: math and collection functions (`abs`, `sqrt`, `floor`, `ceil`, `round`, `min`, `max`, `pow`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `exp`, `log`, `len`, `contains`, `clamp`), the constants `pi` and `e`, the plot names `x` and `y`, the literals `true`, `false` and `null`, and `__proto__`, `prototype` and `constructor`. See [Reusing calculations and formatting values](computations-formatting-en.md#compatibility).
44
+
45
+ ### Newly recognized tag names
46
+
47
+ The build now interprets these names as tags: `jump`, `anchor`, `text`, `section`, `multi-select`, `range-slider`, `coordinate`, `quiz`, `steps`, `step`, `computed`, `const`, `validation`, `data-table` and `column`.
48
+
49
+ Source that used one of these names as literal prose, or as an inert unknown-tag example, now parses as a component or declaration. Put literal examples inside code spans or fences, or escape the tag. Also check reserved identifiers and the behaviour changes below.
50
+
51
+ The leading `<theme name="…">` declaration is document metadata, not a component. It joins the same placement rule: one declaration before the body.
52
+
53
+ ### Version declarations and migration
54
+
55
+ A source may declare `<!-- reactive-md: local-draft-2 -->` in its prologue. Unversioned source keeps current-revision behavior. An explicit `local-draft-1` or unknown revision is rejected with a `local.version.*` diagnostic and creates no runtime; declaring an old revision does not select an old parser.
56
+
57
+ `reactive-md migrate` or the pure core `migrateLocalSource` moves one source to `local-draft-2`. Migration replaces or adds only the metadata comment and preserves body bytes, BOM and CRLF. It blocks newly reserved bindings, newly recognized tags, current compile errors and text-control length changes before writing output. It does not rename identifiers or activate formerly inert tags. Completed checklist styling is a compatibility exception and does not block migration. Because migration changes the source digest, export fresh state files afterwards. Readers built before this declaration, including `0.3.1`, treat it as an ordinary comment and do not enforce the check, so migrate old documents first.
58
+
59
+ ### Behaviour changes
60
+
61
+ - Completed checklist items are now struck through and muted, including `[x]` items in the initial state.
62
+ - `alert` and `badge` accept a dynamic `tone` expression within their existing enums.
63
+ - `table` and `chart` expose selection through `bind` when `key` names a stable identifier column. Existing tables without `key` keep renderer-local selection.
64
+ - Text-control `min-length` and `max-length` count Unicode code points, matching string `len()`. Values that previously failed because an emoji occupied two UTF-16 code units can now pass. Source positions and resource budgets still use UTF-16 units.
65
+ - `document.bindings` and `document.initialState` still describe writable controls. `runtime.snapshot().state` also contains successful named calculation results. Do not assume the snapshot contains controls only.
66
+ - `LocalValueKind` gains `number-array`; `LocalValue` gains `number[]`. Writable checklist and multi-select controls still produce string arrays.
67
+ - Custom runtime adapters need `validate()`; multi-slot controls use `get(node, slot?)`, `set(node, value, slot?)` and `setMany(node, values)`.
68
+ - State files carry `syntax: "local-draft-2"` and a source digest. A file is rejected when either the revision, digest or exact public parameter set differs.
69
+ - Displayed diagnostics are localized through the shared catalogue; callbacks still receive structured diagnostics. `message` remains display text, not an API.
70
+
71
+ ## Upgrade checklist
72
+
73
+ 1. Install `0.4.0` from `next` or pin `0.4.0`, keep the original `.reactive.md` sources and record `LOCAL_SYNTAX_VERSION`.
74
+ 2. Run `reactive-md migrate <file> --check` or `migrateLocalSource` on each source. Unversioned historical documents need `--from local-draft-1`; resolve every reported blocker before writing output.
75
+ 3. Search prose and examples for the 15 newly recognized tag names outside code regions; escape them or move them into code.
76
+ 4. Search `bind`, `bind-start`, `bind-end`, `bind-x` and `bind-y` values for the 17 newly reserved identifiers; rename the bindings and their references. The core `renameLocalBinding` helper and the editor rename action update declarations, expression references and plot parameters together.
77
+ 5. Recompile every document and fix new placement or structure diagnostics, especially top-level `computed`/`const`, `validation`, `data-table`/`column`, `steps`/`step` and `quiz`.
78
+ 6. Update hosts for `number-array`, `validate()`, slot APIs and snapshots that include calculated values.
79
+ 7. Recheck state import/export, retention and any HTML export inside the host. Migration changes the source digest; export fresh state files.
80
+ 8. Check the visible changes: checklist completion styling, table/chart selection and theme CSS.
81
+ 9. Run the [release verification gate](../CONTRIBUTING.md) and your own document and browser checks.
82
+
83
+ ## Verification scope
84
+
85
+ The `0.4.0` build targets Node.js 22.12 and Node 24; its CI gate uses Playwright Chromium and local checks use Microsoft Edge. `npm run verify:release` is the complete release gate: it covers core and demo tests, types, package and documentation checks, packed consumption outside the repository, and the browser checks for calculations, collections, authoring, state restoration, HTML export and rendering equivalence. Individual commands remain in the [contributing guide](../CONTRIBUTING.md).
86
+
87
+ Static SSR is covered by the packed check. Single-file export static-first hydration is covered by the Playwright Chromium and local Edge checks. General SSR hydration outside that path, Firefox and Safari/WebKit are unverified and are not claimed as supported.
88
+
89
+ Use [Versions and compatibility](compatibility-en.md) for the version rules and diagnostics contract, [Source revisions and migration](source-versioning-en.md) for the directive and migration tools, [Shareable documents and static export](shareable-export-en.md) for the HTML and state formats, and [local-draft-2 components and migration](local-components-v2-en.md) for the component additions.
@@ -0,0 +1,101 @@
1
+ # 发布清单
2
+
3
+ 本文件是维护者的手动发布流程。本清单覆盖发布在 `next` 渠道的 `0.4.0` 预览版;`0.3.1` 保持 `latest`,直到另行决定提升。版本规则见[版本与兼容性](compatibility-ch.md),面向使用者的升级说明见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
4
+
5
+ ## 发布前确认
6
+
7
+ ### 包身份与元数据
8
+
9
+ 非 scope 名称 `reactive-md` 已由已发布的 `0.3.0`、`0.3.1` 建立,`reactive-md/react` 和 `reactive-md/styles.css` 子路径也随这些版本生效。不要把改名当作常规发布准备:改名会破坏导入、状态工具和文档。
10
+
11
+ 1. 除非维护者明确决定改用 scope,否则保持 `reactive-md`。scope 需要对应的 npm 账号或组织权限。
12
+ 2. 如果改名,同时更新 `package.json` 的 `name`、文档中的导入语句、tarball 文件名说明、示例和两个子路径,并在变更记录中按破坏性变更说明。
13
+ 3. 核对 `package.json` 的 `repository`、`homepage`、`bugs`、`license`、`engines` 等发布元数据;当前已设置,发布前确认 URL 和最低 Node 版本仍然正确,并确认 `private` 保持移除状态。
14
+ 4. 确认 `files` 覆盖发布所需内容。当前包含 `dist-library`、`dist-standalone`、`bin`、`cli`、README(`README.md`、`README-en.md`、`README-ch.md`)、中英文贡献指南、变更记录与安全策略、`THIRD_PARTY_NOTICES.md`、`docs` 和 `examples`;新增文档或 notice 时同步加入 `files`。
15
+
16
+ 包名和版本决定 tarball 名称。当前 `0.4.0` 的预期文件名是 `reactive-md-0.4.0.tgz`;改名或改版本后以 `npm pack` 的实际输出为准。
17
+
18
+ ### 第三方 notice
19
+
20
+ 库产物打包了 `remark-gfm@4.0.1`、`remark-parse@11.0.0`、`unified@11.0.5` 及其依赖。独立 HTML 运行时还打包了 React、React DOM 和 scheduler;库的 React 入口使用宿主提供的 peer dependency。`THIRD_PARTY_NOTICES.md` 保留这些打包依赖的版权和许可声明。
21
+
22
+ 维护者在发布前:
23
+
24
+ 1. 运行 `npm run notices`,从已安装依赖重新生成 `THIRD_PARTY_NOTICES.md`。生成脚本覆盖 `remark-gfm`、`remark-parse`、`unified`、`react`、`react-dom` 的依赖树和实际许可证文本,包括 scheduler。
25
+ 2. 确认 `package.json` 的 `files` 包含 `THIRD_PARTY_NOTICES.md`,并随 tarball 分发。
26
+ 3. 检查 `npm pack --dry-run` 的输出,确认没有 `node_modules`、`demo/`、`demo/artifacts/`、测试产物或本地缓存。
27
+ 4. 核对依赖许可证与打包内容一致;新增或升级 Markdown 依赖后重新生成 notice。
28
+
29
+ ## 本地 tarball 安装
30
+
31
+ 完整的本地门禁是:
32
+
33
+ ```sh
34
+ npm ci
35
+ npm run verify:release
36
+ ```
37
+
38
+ `verify:release` 运行 Node 端与浏览器检查,构建包,在仓库外安装真实 tarball,并验证多份能力组合后的文档行为;它自行管理预览服务和浏览器生命周期。CI 通过 `verify:release:node` 和 `verify:release:browser` 分片运行同一门禁。本机需已安装浏览器。
39
+
40
+ packed 检查会在 `artifacts/release-package/` 保留经过验证的原始安装包,并在同目录的 `package-verification.json` 记录 SHA256 与 npm integrity。完整门禁通过后发布这一安装包;源码、包元数据或随包文档变化后重新验证。
41
+
42
+ 需要手工检查包内容时,直接使用 tarball。在仓库根目录:
43
+
44
+ ```sh
45
+ npm pack
46
+ ```
47
+
48
+ `npm pack` 会通过 `prepack` 先运行构建和 `npm run notices`,生成 `dist-library/` 与 `THIRD_PARTY_NOTICES.md`。`dist-library/` 是 `package.json` 的 `exports` 指向的目录。随后在一个空目录中验证安装:
49
+
50
+ ```sh
51
+ mkdir /tmp/reactive-md-consumer
52
+ cd /tmp/reactive-md-consumer
53
+ npm init -y
54
+ npm install /path/to/reactive-md-0.4.0.tgz
55
+ ```
56
+
57
+ 核心入口可在 Node 中直接检查:
58
+
59
+ ```sh
60
+ node --input-type=module -e "import { compileLocal, LOCAL_SYNTAX_VERSION } from 'reactive-md'; console.log(LOCAL_SYNTAX_VERSION, compileLocal('# ok').ok)"
61
+ ```
62
+
63
+ React 入口需要另装 React 19:
64
+
65
+ ```sh
66
+ npm install react@19 react-dom@19
67
+ ```
68
+
69
+ ```tsx
70
+ import { LocalReactiveDocument } from 'reactive-md/react';
71
+ import 'reactive-md/styles.css';
72
+ ```
73
+
74
+ 静态 SSR 渲染由 packed 检查覆盖。单文件导出的静态首屏水合由 Playwright Chromium 和本地 Edge 浏览器检查覆盖;该路径之外的通用 SSR 水合尚未验证。安装验证还应确认 tarball 中的 `dist-library/types`、`dist-standalone`、`bin`、`cli`、`README.md`、`README-en.md`、`README-ch.md`、`CHANGELOG-ch.md`、`SECURITY-ch.md`、`THIRD_PARTY_NOTICES.md`、`docs` 和 `examples` 完整,并检查 `docs` 中没有指向未打包 `demo/`、`src/`、`tests/` 或 `.tasks/` 文件的本地链接。
75
+
76
+ ## 发布说明
77
+
78
+ 发布说明面向使用者,至少包含:
79
+
80
+ - 包版本、`LOCAL_SYNTAX_VERSION`、组块协议修订与主题协议修订;这些不是同一个版本号。
81
+ - 安装方式:`npm install reactive-md@next`,或使用 `npm install reactive-md@<version>` 固定版本;并提供可下载 tarball 作为离线安装选项。
82
+ - 用户可见变化、破坏性变更和迁移步骤;直接链接[变更记录](../CHANGELOG-ch.md),本轮同时链接[0.4.0 发布说明](release-0.4.0-ch.md)。
83
+ - 已验证的平台,以及未验证的浏览器、通用 SSR 水合等范围。
84
+ - 已知限制和安全说明链接 [SECURITY-ch.md](../SECURITY-ch.md)。
85
+
86
+ 不要写尚未执行的检查结果,也不要把 CI 配置存在写成 CI 已通过。
87
+
88
+ ## 人工发布清单
89
+
90
+ 1. 确认工作区干净,变更已审查;`npm ci` 从锁文件安装成功。
91
+ 2. 在 Node 22.12 和受支持的较新 LTS(当前为 24)上运行 `npm run verify:release`。这是维护者和 CI 共用的完整门禁,不要用一组自行挑选的命令代替。
92
+ 3. 确认版本号、`CHANGELOG-ch.md` 和发布说明一致。语法变化时更新 `LOCAL_SYNTAX_VERSION`;组块或主题协议修订仅在各自契约变化时更新,这些版本轴保持独立。
93
+ 4. 检查门禁保留的安装包,包括文件列表、大小和许可文件。手动重新运行 `npm pack` 会产生新候选包,需要单独完成安装验证。
94
+ 5. 核对安装包的 SHA256 与 `artifacts/release-package/package-verification.json` 一致,并记录到发布说明或内部发布记录。
95
+ 6. 合并发布提交,等待 `main` 上的 CI 全部通过。
96
+ 7. 手动创建并推送 tag,例如 `v0.4.0`。不要在自动发布工作流中保存 npm token。
97
+ 8. 在维护者本机完成 npm 登录和双因素认证后,手动发布已经验证的预览版安装包:`npm publish artifacts/release-package/reactive-md-0.4.0.tgz --access public --tag next`。预览版使用 `next` 分发标签;是否更新稳定版的 `latest` 标签另行决定。
98
+ 9. 在 npm 和 GitHub Releases 上核对包内容、版本、README、许可与发布说明;从公开 registry 重新安装一次。
99
+ 10. 从 registry 验证 README 中的安装命令可用,核对 registry 的完整性摘要与发布 tarball 一致。
100
+
101
+ README 中的版本与安装命令应在打包前准备好,并在发布后验证。发布过程中不要提交 token、`.npmrc` 凭据或本机路径。
@@ -0,0 +1,101 @@
1
+ # Release checklist
2
+
3
+ This file is the maintainers' manual release process. This checklist covers the `0.4.0` preview release on the `next` channel; `0.3.1` remains `latest` until a separate promotion decision. See [Versions and compatibility](compatibility-en.md) for version rules and [0.4.0 release and migration](release-0.4.0-en.md) for the user-facing upgrade summary.
4
+
5
+ ## Before release
6
+
7
+ ### Package identity and metadata
8
+
9
+ The unscoped name `reactive-md` is already established by the published `0.3.0` and `0.3.1` releases, together with the `reactive-md/react` and `reactive-md/styles.css` subpaths. Do not treat a rename as routine release preparation: changing the name is a breaking change for imports, state tooling and documentation.
10
+
11
+ 1. Keep `reactive-md` unless maintainers explicitly decide on a scoped rename. A scope requires the corresponding npm account or organization permissions.
12
+ 2. If renaming, update `name` in `package.json`, import statements in the documentation, tarball filename references, examples and both subpaths, then record the change as breaking in the changelog.
13
+ 3. Check release metadata in `package.json`: `repository`, `homepage`, `bugs`, `license`, `engines` and similar fields. They are currently set; before releasing, confirm the URLs and minimum Node version are still correct and that `private` remains removed.
14
+ 4. Confirm `files` covers what needs to be published. It currently includes `dist-library`, `dist-standalone`, `bin`, `cli`, the READMEs (`README.md`, `README-en.md`, `README-ch.md`), the contributing, changelog and security guides in both languages, `THIRD_PARTY_NOTICES.md`, `docs` and `examples`; add any new documentation or notices to `files` as well.
15
+
16
+ The package name and version determine the tarball name. The expected filename for `0.4.0` is `reactive-md-0.4.0.tgz`; after renaming or changing the version, use the actual output of `npm pack`.
17
+
18
+ ### Third-party notices
19
+
20
+ The library bundles `remark-gfm@4.0.1`, `remark-parse@11.0.0`, `unified@11.0.5` and their dependencies. The standalone HTML runtime also bundles React, React DOM and scheduler; the library React entry uses host-provided peers. All these bundles retain the installed dependencies' copyright and license notices in `THIRD_PARTY_NOTICES.md`.
21
+
22
+ Before releasing, maintainers:
23
+
24
+ 1. Run `npm run notices` to regenerate `THIRD_PARTY_NOTICES.md` from installed dependencies. The generation script covers the dependency trees and actual license texts of `remark-gfm`, `remark-parse`, `unified`, `react` and `react-dom`, including scheduler.
25
+ 2. Confirm `files` in `package.json` includes `THIRD_PARTY_NOTICES.md` so it ships in the tarball.
26
+ 3. Inspect the output of `npm pack --dry-run` and confirm there is no `node_modules`, `demo/`, `demo/artifacts/`, test output or local cache.
27
+ 4. Check that dependency licenses match the packaged content; regenerate notices after adding or upgrading Markdown dependencies.
28
+
29
+ ## Local tarball installation
30
+
31
+ The complete local gate is:
32
+
33
+ ```sh
34
+ npm ci
35
+ npm run verify:release
36
+ ```
37
+
38
+ `verify:release` runs the Node-side and browser checks, builds the package, installs the real tarball outside the repository and exercises combined document behavior. It manages the preview server and browser lifecycle itself. CI splits the same gate with `verify:release:node` and `verify:release:browser`. A browser must already be installed locally.
39
+
40
+ The packed check retains the exact verified archive in `artifacts/release-package/` and records its SHA256 and npm integrity in `package-verification.json` there. Publish that archive after the complete gate passes. Re-run verification if source, package metadata or packaged documentation changes.
41
+
42
+ To inspect the package manually, use the tarball directly. In the repository root:
43
+
44
+ ```sh
45
+ npm pack
46
+ ```
47
+
48
+ `npm pack` runs the build and `npm run notices` through `prepack` first, producing `dist-library/` and `THIRD_PARTY_NOTICES.md`. `dist-library/` is the directory targeted by `exports` in `package.json`. Then verify installation in an empty directory:
49
+
50
+ ```sh
51
+ mkdir /tmp/reactive-md-consumer
52
+ cd /tmp/reactive-md-consumer
53
+ npm init -y
54
+ npm install /path/to/reactive-md-0.4.0.tgz
55
+ ```
56
+
57
+ The core entry can be checked directly in Node:
58
+
59
+ ```sh
60
+ node --input-type=module -e "import { compileLocal, LOCAL_SYNTAX_VERSION } from 'reactive-md'; console.log(LOCAL_SYNTAX_VERSION, compileLocal('# ok').ok)"
61
+ ```
62
+
63
+ The React entry requires React 19 to be installed separately:
64
+
65
+ ```sh
66
+ npm install react@19 react-dom@19
67
+ ```
68
+
69
+ ```tsx
70
+ import { LocalReactiveDocument } from 'reactive-md/react';
71
+ import 'reactive-md/styles.css';
72
+ ```
73
+
74
+ Static SSR rendering is covered by the packed check. Single-file export static-first hydration is covered by the Playwright Chromium and local Edge browser checks; general SSR hydration outside that path is unverified. Installation verification should also confirm that the tarball contains complete `dist-library/types`, `dist-standalone`, `bin`, `cli`, `README.md`, `README-en.md`, `README-ch.md`, `CHANGELOG.md`, `SECURITY.md`, `THIRD_PARTY_NOTICES.md`, `docs` and `examples`, and check that `docs` contains no local links to unpackaged `demo/`, `src/`, `tests/` or `.tasks/` files.
75
+
76
+ ## Release notes
77
+
78
+ Release notes are for users and must include at least:
79
+
80
+ - The package version, `LOCAL_SYNTAX_VERSION`, component protocol revision and theme protocol revision; these are different version numbers.
81
+ - The install command `npm install reactive-md@next`, or `npm install reactive-md@<version>` to pin the release, with a downloadable tarball as an offline installation option.
82
+ - User-visible changes, breaking changes and migration steps; link directly to the [changelog](../CHANGELOG.md) and the [0.4.0 release notes](release-0.4.0-en.md) for this cycle.
83
+ - Verified platforms, plus unverified browsers, general SSR hydration and other scope.
84
+ - Known limitations and a link to [SECURITY.md](../SECURITY.md).
85
+
86
+ Do not write results for checks that have not run, and do not present the existence of CI configuration as CI passing.
87
+
88
+ ## Manual release checklist
89
+
90
+ 1. Confirm the working tree is clean, changes have been reviewed, and `npm ci` installs successfully from the lockfile.
91
+ 2. On Node 22.12 and a supported newer LTS (currently 24), run `npm run verify:release`. This is the same complete gate local maintainers and CI use; do not replace it with a list of hand-picked commands.
92
+ 3. Confirm the version number, `CHANGELOG.md` and the release notes agree. Update `LOCAL_SYNTAX_VERSION` when syntax changes; update component or theme protocol revisions only when their own contracts change. These version axes remain independent.
93
+ 4. Inspect the verified archive retained by the gate, including its file list, size and license files. A fresh manual `npm pack` produces a new candidate that needs its own installation verification.
94
+ 5. Compare the archive's SHA256 with `artifacts/release-package/package-verification.json` and record it in the release notes or an internal release record.
95
+ 6. Merge the release commit and wait for all CI on `main` to pass.
96
+ 7. Create and push the tag manually, for example `v0.4.0`. Do not store npm tokens in an automated release workflow.
97
+ 8. After signing in to npm and completing two-factor authentication on the maintainer's machine, publish the verified preview tarball manually: `npm publish artifacts/release-package/reactive-md-0.4.0.tgz --access public --tag next`. The preview uses the `next` distribution tag; changing the stable `latest` tag is a separate release decision.
98
+ 9. Verify the package contents, version, README, license and release notes on npm and GitHub Releases; reinstall once from the public registry.
99
+ 10. Verify that the install command in the README works from the registry, and that the registry integrity digest matches the released tarball.
100
+
101
+ The version and install command in the README should be ready before packaging and verified after release. Do not commit tokens, `.npmrc` credentials or local paths during the release process.
@@ -0,0 +1,205 @@
1
+ # 可分享文档与静态导出
2
+
3
+ 本文说明 `local-draft-2` 新增的单文件 HTML 导出能力。编译与运行时接口见[本地模式集成](local-integration-ch.md),语法见[交互语法规范](local-interaction-syntax-ch.md),修订声明与迁移见[源码修订与迁移](source-versioning-ch.md),升级说明见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
4
+
5
+ ## 两种产物
6
+
7
+ **交互式 HTML** 是一个自包含的 `.html` 文件。它内嵌原始源码、独立浏览器运行时、React 19、样式表和打印样式。读者通过 `file://` 打开即可交互,不需要 Node.js、React、reactive-md 包或网络连接。
8
+
9
+ 首次渲染是静态内容;内嵌运行时水合完成后再增强为控件。禁用 JavaScript 时,正文、当前值、表格、公式和图表仍然可读。读者刷新后回到导出基线,后续修改不会自动保存。
10
+
11
+ **静态 HTML**(`--mode static`)只包含只读结果,不携带可执行运行时。它适合邮件附件、归档和静态站点。供交互使用的按钮、表单控件和重置操作会被移除。
12
+
13
+ 两种模式都复用 React 渲染器,因此条件内容、插值、表格、公式、图表和布局都按运行时状态求值。
14
+
15
+ ## CLI
16
+
17
+ 包提供 `reactive-md` 命令。构建 HTML 的项目需要安装 React 19 和 React DOM;`lint` 和 `migrate` 不需要。
18
+
19
+ ```sh
20
+ reactive-md build doc.reactive.md -o doc.html
21
+ reactive-md build doc.reactive.md -o doc.html --mode static
22
+ reactive-md build doc.reactive.md -o doc.html --state-file doc.state.json
23
+ reactive-md build doc.reactive.md -o doc.html --assets omit
24
+ reactive-md lint "docs/**/*.reactive.md"
25
+ reactive-md lint "docs/**/*.reactive.md" --json --strict
26
+ ```
27
+
28
+ | 选项 | 含义 |
29
+ | --- | --- |
30
+ | `-o, --output <file>` | 必填输出路径;父目录必须已存在。 |
31
+ | `--mode interactive\|static` | 输出模式,默认 `interactive`。 |
32
+ | `--state-file <json>` | 使用经过校验的 `reactive-md-state/v1` 文件作为打开和重置基线。 |
33
+ | `--assets inline\|omit` | 内联已验证的本地位图(默认),或保留渲染器的替代文本降级。 |
34
+ | `--asset-root <dir>` | 额外允许相对图片路径解析的本地目录。 |
35
+ | `--locale en\|zh` | 渲染标签与校验信息语言,默认 `en`。 |
36
+ | `--color-scheme auto\|light\|dark` | 文档颜色模式,默认 `auto`。 |
37
+ | `--title <text>` | 覆盖 HTML 标题;默认取首个标题或输入文件名。 |
38
+ | `--strict` | 警告也视为失败;配合 `--assets omit` 时,存在被省略图片也失败。 |
39
+
40
+ 退出码区分不同失败:
41
+
42
+ | 退出码 | 含义 |
43
+ | --- | --- |
44
+ | `0` | 成功 |
45
+ | `2` | 参数或用法错误 |
46
+ | `3` | 文档编译、渲染、React 或包内构建产物错误 |
47
+ | `4` | 输入/输出文件错误 |
48
+ | `5` | 资源或安全策略错误 |
49
+
50
+ CLI 没有“当前预览”概念,只有 `--state-file` 可以选择非初值基线。本版本暂不提供 `format`。
51
+
52
+ ## 迁移源码
53
+
54
+ `reactive-md migrate` 把单份源码的修订声明迁移到 `local-draft-2`:
55
+
56
+ ```sh
57
+ reactive-md migrate old.reactive.md --from local-draft-1 -o new.reactive.md
58
+ reactive-md migrate old.reactive.md --check --json
59
+ ```
60
+
61
+ 默认把迁移后的源码写到标准输出。`-o` 使用独占创建,拒绝任何已存在的路径,包括输入文件本身。`--check` 从不写入。`--json` 只输出结构化报告。`--accept-semantic-changes` 允许文本控件长度语义变化并报告警告;`--locale en|zh` 选择显示语言。
62
+
63
+ 迁移被阻止时退出 `1`,成功时退出 `0`。`--check` 在需要迁移或被阻止时退出 `1`,源码已是当前版本时退出 `0`。用法和 I/O 错误退出 `2`。命令不就地覆盖,也不提供批量或 `--write` 模式。检查项、保留字节和状态摘要影响见[源码修订与迁移](source-versioning-ch.md)。
64
+
65
+ ## 起始参数与状态文件
66
+
67
+ 默认导出作者定义的初始参数,保证构建可重复,避免把调试值或敏感输入带给接收者。
68
+
69
+ 状态文件采用版本化结构:
70
+
71
+ ```json
72
+ {
73
+ "format": "reactive-md-state/v1",
74
+ "syntax": "local-draft-2",
75
+ "sourceDigest": "fnv1a32:0123abcd",
76
+ "parameters": {
77
+ "people": 7,
78
+ "plan": "pro"
79
+ },
80
+ "generator": { "name": "example-host", "version": "1.0.0" }
81
+ }
82
+ ```
83
+
84
+ 只保存公开、可序列化的绑定值。文件通过 `sourceDigest` 标识文档,通过 `syntax` 记录语言修订。`@` 开头的内部绑定、revision、节点 ID、AST、计时器、展开状态和焦点都不会写入;内部快照键和 ID 属于实现细节,不是存储格式。
85
+
86
+ 恢复时按源码摘要、语法版本、参数集合和槽位约束逐项校验。未知、缺失或非法参数会报告具体名称并拒绝整个文件,不会部分应用。`range-slider` 等双槽组件按原子写入规则校验。
87
+
88
+ 选中的状态同时成为重置基线。因此打开、刷新和面板重置都会回到导出值,而不是另一个隐藏的默认值。
89
+
90
+ 宿主可以不经过 CLI 生成和应用同一格式:
91
+
92
+ ```ts
93
+ import { exportLocalState, importLocalState } from 'reactive-md';
94
+
95
+ const file = exportLocalState(runtime, { name: 'example-host', version: '1.0.0' });
96
+ const saved = JSON.stringify(file);
97
+
98
+ const diagnostics = importLocalState(runtime, saved);
99
+ ```
100
+
101
+ `exportLocalState` 只读取公开参数。`importLocalState` 校验源码摘要、语法、参数集合和槽位约束后应用;导入失败时运行时状态不变。两者都是宿主显式调用,运行时本身仍不会保存或发送状态。只做校验、不改动运行中实例时使用 `resolveLocalState(document, input)`。
102
+
103
+ Demo 导出对话框可以把当前预览参数下载为状态文件,供后续 CLI 构建使用。较低层的 `createLocalStateFile`、`parseLocalState`、`applyLocalState` 和 `serializeLocalState` 仍可从 `reactive-md` 使用。
104
+
105
+ ## 图片
106
+
107
+ 离线导出默认使用 `--assets inline`:
108
+
109
+ - 只读取文档目录内或显式 `--asset-root` 内的相对路径。
110
+ - 拒绝绝对路径、URL scheme、协议相对地址、反斜杠、路径穿越和符号链接逃逸。
111
+ - 从不自动抓取远程图片。
112
+ - 按文件内容识别 PNG、JPEG、GIF、WebP;拒绝 SVG、伪造 MIME 和未知格式。
113
+ - 单图上限 8 MiB,总量上限 24 MiB,最多 64 个不同资源;相同内容按哈希去重。
114
+ - 保留 alt;无法内联时默认构建失败。`--assets omit` 是显式降级,保留 alt 回退。
115
+
116
+ 渲染器原有的全局安全边界没有放宽:没有宿主 URL 策略时图片仍默认全部拒绝。导出器只在校验本地文件后提供 URL 策略和图片映射。
117
+
118
+ ## 单文件安全与打印
119
+
120
+ HTML 外壳包含:
121
+
122
+ - CSP:禁止连接、frame、object、base 注入和表单提交,只允许内联样式/运行时和 `data:` 图片;
123
+ - 对 JSON、源码、标题和许可证文本做 HTML 与脚本上下文转义;
124
+ - 在不会执行的 `<template>` 中保留 MIT 和第三方 notices;
125
+ - 不引用 CDN、远程样式、字体或运行时。
126
+
127
+ 普通外链在读者主动点击时仍可导航,但打开文档本身不会发起远程请求。该导出器不等同于不可信作者的沙箱;需要隔离时应使用 sandboxed iframe。
128
+
129
+ 打印不依赖临时的状态切换。交互式页面会为当前运行时值输出打印专用节点,`Ctrl+P` 打印读者当前看到的结果。打印样式强制浅色纸张、隐藏工具栏和控件、使用打印机决定纸张边距、避免标题孤立、重复表头、换行长代码和 URL,并把图表限制在页面宽度内。静态 HTML 本身只包含只读值。
130
+
131
+ ## 独立运行时 API
132
+
133
+ 构建会生成 `dist-standalone/reactive-md-standalone.js`(IIFE,全局名 `ReactiveMD`)和 `reactive-md-standalone.css`。二者按普通浏览器资源加载:
134
+
135
+ ```html
136
+ <link rel="stylesheet" href="reactive-md-standalone.css">
137
+ <script src="reactive-md-standalone.js"></script>
138
+ ```
139
+
140
+ 程序化挂载:
141
+
142
+ ```js
143
+ const handle = ReactiveMD.mount(document.getElementById('doc'), {
144
+ source: '# Hello\n\n<slider bind="n" label="Count" initial="2">\n\nValue: {{ n }}',
145
+ locale: 'en',
146
+ colorScheme: 'auto',
147
+ });
148
+ handle.getState(); // reactive-md-state/v1 快照
149
+ handle.unmount();
150
+ ```
151
+
152
+ `ReactiveMD.mountAll(root)` 只扫描一次安全的自动挂载载荷:
153
+
154
+ ```html
155
+ <div id="doc"></div>
156
+ <script type="application/reactive-md+json" data-reactive-md-auto>
157
+ {"version":1,"target":"doc","source":"# Hello","state":{"format":"reactive-md-state/v1","syntax":"local-draft-2","sourceDigest":"fnv1a32:01209266","parameters":{}},"locale":"en","colorScheme":"auto","hydrate":false}
158
+ </script>
159
+ ```
160
+
161
+ 目标只按 `id` 查找,不拼接选择器。source 只作为数据处理,不当作可执行 HTML。故意不解释 `<script type="text/reactive-md">` 的原始文本。
162
+
163
+ ### `<reactive-md-doc>`
164
+
165
+ IIFE 会注册一个 Light DOM 自定义元素。简单选项通过属性传递,复杂选项通过 DOM property 传递。
166
+
167
+ ```html
168
+ <reactive-md-doc src="./doc.reactive.md" locale="en" color-scheme="auto"></reactive-md-doc>
169
+ ```
170
+
171
+ - 属性:`src`、`source`、`locale`、`color-scheme`、`theme`。
172
+ - Property:`source`、`state`、`urlPolicy`、`imageResolver`、`themes`。
173
+ - 事件:`reactive-md-diagnostics`、`reactive-md-state-change`。
174
+ - `src` 通过可取消的 `fetch` 加载;显式 source 不会产生请求。
175
+ - 断开连接时中止请求、移除订阅、卸载 React root 并释放运行时。两个相同 source 的元素拥有独立状态。
176
+
177
+ 元素使用 Light DOM,以复用现有文档样式、标题锚点和打印样式。本版本不提供 Shadow DOM。
178
+
179
+ ## 安全边界
180
+
181
+ - 核心与 React 入口继续保持 React external;只有 standalone IIFE 打包 React。
182
+ - 核心入口仍不加载 React。
183
+ - 状态导出与导入只使用公开绑定名和经过校验的值。
184
+ - 读者修改不会持久化到导出文件。
185
+ - Demo 预览仍按默认策略阻止图片;Demo 没有资源根,因此文档包含图片时会禁用 HTML 导出。含图文档请使用 CLI。
186
+ - 导出格式版本为 `reactive-md-html/v1`,可从生成的 meta 标签检查。
187
+
188
+ ## 产物体积基线
189
+
190
+ `npm run test:shareable` 会记录 standalone 产物体积,并在超过以下回归阈值时失败:
191
+
192
+ | 产物 | 当前基线 | 报警阈值 |
193
+ | --- | --- | --- |
194
+ | `reactive-md-standalone.js` | 约 625.5 kB(gzip 约 186 kB) | 800 KiB / gzip 240 KiB |
195
+ | `reactive-md-standalone.css` | 约 59.7 kB(gzip 约 10.1 kB) | 80 KiB / gzip 20 KiB |
196
+
197
+ 数值会随压缩器和 React 补丁版本小幅变化。阈值远高于正常波动,同时能捕获 React 或渲染器被重复打包的退化。完整 HTML 还包含源码、notices 和内联图片,因此会大于这个基线。
198
+
199
+ ## 当前范围
200
+
201
+ 已实现:CLI 的 `build`/`lint`/`migrate`、交互与静态 HTML、状态文件、本地位图内联、打印输出、standalone 挂载 API、自动挂载和 Web Component。
202
+
203
+ 本版本不包含:`format`、UMD、远程图片抓取、SVG 内联、框架插件(Vite、Astro、Docusaurus、Next.js)、Shadow DOM,以及单文件导出之外的通用 SSR 水合保证。
204
+
205
+ 单文件静态首屏水合由 Playwright Chromium 和本地 Edge 检查覆盖。Firefox、Safari/WebKit 以及通用服务端水合尚未验证,不作支持声明。