reactive-md 0.6.0 → 0.6.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 (105) hide show
  1. package/CHANGELOG-ch.md +203 -194
  2. package/CHANGELOG.md +203 -194
  3. package/CONTRIBUTING-ch.md +67 -67
  4. package/CONTRIBUTING.md +69 -69
  5. package/README-ch.md +157 -157
  6. package/README-en.md +184 -184
  7. package/README.md +184 -184
  8. package/SECURITY-ch.md +81 -81
  9. package/SECURITY.md +81 -81
  10. package/THIRD_PARTY_NOTICES.md +313 -209
  11. package/bin/reactive-md.mjs +39 -39
  12. package/cli/args.mjs +181 -181
  13. package/cli/assets.mjs +390 -390
  14. package/cli/build.mjs +268 -268
  15. package/cli/document.mjs +130 -130
  16. package/cli/errors.mjs +61 -61
  17. package/cli/fs-utils.mjs +133 -133
  18. package/cli/glob.mjs +203 -203
  19. package/cli/help.mjs +138 -138
  20. package/cli/lint.mjs +177 -177
  21. package/cli/main.mjs +55 -55
  22. package/cli/migrate.mjs +368 -368
  23. package/cli/package.mjs +210 -210
  24. package/dist-library/{authoring-DSC0VsNK.js → authoring-BEVyth5X.js} +1 -1
  25. package/dist-library/compiler-Cm3ppMxG.js +46044 -0
  26. package/dist-library/{react-Dk94rcOp.js → react-Bh7_oxZp.js} +20110 -20113
  27. package/dist-library/reactive-md-authoring.js +2 -2
  28. package/dist-library/reactive-md-print.css +284 -284
  29. package/dist-library/reactive-md-react-unstyled.js +1 -1
  30. package/dist-library/reactive-md-react.js +1 -1
  31. package/dist-library/reactive-md.css +1 -1
  32. package/dist-library/reactive-md.js +3 -3
  33. package/dist-library/{runtime-D8KbnCd0.js → runtime-DlFYQ4s_.js} +1 -1
  34. package/dist-library/types/local/math-display.d.ts +22 -23
  35. package/dist-library/types/local/math-view.d.ts +6 -7
  36. package/dist-standalone/reactive-md-standalone.css +1 -1
  37. package/dist-standalone/reactive-md-standalone.js +318 -62
  38. package/docs/compatibility/compatibility-ch.md +121 -119
  39. package/docs/compatibility/compatibility-en.md +121 -119
  40. package/docs/compatibility/source-versioning-ch.md +159 -159
  41. package/docs/compatibility/source-versioning-en.md +159 -159
  42. package/docs/development/component-development-ch.md +210 -210
  43. package/docs/development/component-development-en.md +210 -210
  44. package/docs/development/component-protocol-ch.md +747 -747
  45. package/docs/development/component-protocol-en.md +747 -747
  46. package/docs/development/performance-ch.md +76 -76
  47. package/docs/development/performance-en.md +76 -76
  48. package/docs/development/releasing-ch.md +108 -108
  49. package/docs/development/releasing-en.md +108 -108
  50. package/docs/integration/author-tools-ch.md +62 -62
  51. package/docs/integration/author-tools-en.md +62 -62
  52. package/docs/integration/shareable-export-ch.md +209 -209
  53. package/docs/integration/shareable-export-en.md +211 -211
  54. package/docs/reference/computations-formatting-ch.md +87 -87
  55. package/docs/reference/computations-formatting-en.md +87 -87
  56. package/docs/reference/constraints-collections-ch.md +84 -84
  57. package/docs/reference/constraints-collections-en.md +84 -84
  58. package/docs/reference/diagnostics-counting-ch.md +104 -104
  59. package/docs/reference/diagnostics-counting-en.md +104 -104
  60. package/docs/reference/local-components-v2-ch.md +138 -138
  61. package/docs/reference/local-components-v2-en.md +104 -104
  62. package/docs/reference/local-interaction-syntax-ch.md +515 -511
  63. package/docs/reference/local-interaction-syntax-en.md +511 -507
  64. package/docs/reference/theme-protocol-ch.md +107 -107
  65. package/docs/reference/theme-protocol-en.md +107 -107
  66. package/docs/releases/release-0.4.0-ch.md +89 -89
  67. package/docs/releases/release-0.4.0-en.md +89 -89
  68. package/docs/releases/release-0.4.1-ch.md +23 -23
  69. package/docs/releases/release-0.4.1-en.md +23 -23
  70. package/docs/releases/release-0.6.1-ch.md +27 -0
  71. package/docs/releases/release-0.6.1-en.md +27 -0
  72. package/examples/conformance/README.md +53 -53
  73. package/examples/conformance/component-protocol-1.json +482 -482
  74. package/examples/conformance/component-protocol-1.schema.json +76 -76
  75. package/examples/conformance/local-draft-1.json +50 -50
  76. package/examples/conformance/local-draft-2.json +212 -212
  77. package/examples/integration/README.md +47 -47
  78. package/examples/integration/core/index.mjs +32 -32
  79. package/examples/integration/worker/index.html +19 -19
  80. package/examples/integration/worker/main.js +61 -61
  81. package/examples/integration/worker/package.json +13 -13
  82. package/examples/integration/worker/worker.js +3 -3
  83. package/examples/local/README.md +74 -74
  84. package/examples/local/charts.reactive.md +73 -73
  85. package/examples/local/recipes/invoice-zh.reactive.md +36 -36
  86. package/examples/local/recipes/invoice.reactive.md +36 -36
  87. package/examples/local/recipes/workshop-zh.reactive.md +33 -33
  88. package/examples/local/recipes/workshop.reactive.md +33 -33
  89. package/examples/local/showcase/README.md +25 -25
  90. package/examples/local/showcase/explore.reactive.md +102 -102
  91. package/examples/local/showcase/flow.reactive.md +86 -86
  92. package/examples/local/showcase/forms.reactive.md +126 -126
  93. package/examples/local/showcase/functions.reactive.md +119 -119
  94. package/examples/local/showcase/layout.reactive.md +100 -100
  95. package/examples/local/showcase/statistics.reactive.md +108 -108
  96. package/examples/local/showcase/tasks.reactive.md +89 -89
  97. package/examples/local/showcase/zh/explore.reactive.md +102 -102
  98. package/examples/local/showcase/zh/flow.reactive.md +86 -86
  99. package/examples/local/showcase/zh/forms.reactive.md +126 -126
  100. package/examples/local/showcase/zh/functions.reactive.md +119 -119
  101. package/examples/local/showcase/zh/layout.reactive.md +100 -100
  102. package/examples/local/showcase/zh/statistics.reactive.md +108 -108
  103. package/examples/local/showcase/zh/tasks.reactive.md +89 -89
  104. package/package.json +152 -152
  105. package/dist-library/compiler-CRD88BMt.js +0 -24964
@@ -1,159 +1,159 @@
1
- # 源码修订与迁移
2
-
3
- 本文说明 `0.4.0` 中的显式源码修订、编译器的处理方式,以及纯核心 API 与 CLI 迁移工具。语法规则见[语法规范](../reference/local-interaction-syntax-ch.md),包版本与 API 兼容规则见[版本与兼容性](compatibility-ch.md),组块升级清单见[0.4.0 发布与迁移](../releases/release-0.4.0-ch.md)。
4
-
5
- ## 声明修订
6
-
7
- 源码用一行 HTML 注释声明修订:
8
-
9
- ```markdown
10
- <!-- reactive-md: local-draft-2 -->
11
- ```
12
-
13
- 该指令属于文档前导区,位于 `<theme>` 声明和正文之前。BOM、空行和普通 Markdown 注释可以出现在它前面。只允许一条指令。
14
-
15
- 行内代码、代码围栏、数学区域和按原文显示的未知标签示例都不是指令。在文档里展示这一行,不会为周围文档声明版本。
16
-
17
- 编译行为:
18
-
19
- | 源码 | 结果 |
20
- | --- | --- |
21
- | 没有指令 | 按当前修订 `local-draft-2` 解析,与之前一致;不新增警告 |
22
- | `local-draft-2` | 正常解析 |
23
- | `local-draft-1` 或其他显式旧修订 | 以 `local.version.*` 诊断拒绝 |
24
- | 未知、格式错误、重复或位置错误的指令 | 以 `local.version.*` 诊断拒绝 |
25
-
26
- 版本声明被拒绝时不创建运行时。声明旧修订不会选择旧解析器,也不会让文档在现行规则下可读;必须先迁移源码。
27
-
28
- 在这一声明出现之前构建的读者(包括 `0.3.1`)会把这条注释当作普通 HTML 注释。它们不校验声明,不拒绝旧修订,也不执行这项检查。声明保护的是在本版本及后续版本中打开的文档;依赖这项检查前,先迁移旧文档。
29
-
30
- ## 查看声明的修订
31
-
32
- `inspectLocalSourceVersion` 从 `reactive-md` 导出,不编译,也不创建运行时:
33
-
34
- ```ts
35
- import { inspectLocalSourceVersion } from 'reactive-md';
36
-
37
- const info = inspectLocalSourceVersion(source);
38
- // {
39
- // declaredVersion: string | null,
40
- // effectiveVersion: string,
41
- // supported: boolean,
42
- // range: SourceRange | null,
43
- // diagnostics: Diagnostic[]
44
- // }
45
- ```
46
-
47
- - `declaredVersion` 是指令声明的修订;无指令时为 `null`。
48
- - `effectiveVersion` 是用于解释判定的修订:有声明时取声明值,否则取当前修订。`supported` 为 `false` 时不进行解释。
49
- - `supported` 表示当前编译器是否接受该修订。
50
- - `range` 指向原始源码中的指令;没有指令时为 `null`。
51
- - `diagnostics` 使用 `local.version.*` 前缀报告格式错误、重复、位置错误、旧修订或未知声明。
52
-
53
- 无指令源码返回 `declaredVersion: null`、`effectiveVersion: 'local-draft-2'`、`supported: true`,不产生版本诊断。
54
-
55
- ## 检查升级
56
-
57
- ```ts
58
- import { checkLocalUpgrade } from 'reactive-md';
59
-
60
- const check = checkLocalUpgrade(source);
61
- // {
62
- // ok: boolean,
63
- // fromVersion: string,
64
- // toVersion: 'local-draft-2',
65
- // needsMigration: boolean,
66
- // diagnostics: Diagnostic[]
67
- // }
68
- ```
69
-
70
- `fromVersion` 默认取声明的修订;源码没有声明时取当前修订。可以用 `LocalUpgradeOptions` 覆盖:
71
-
72
- ```ts
73
- type LocalUpgradeOptions = {
74
- fromVersion?: string;
75
- allowSemanticChanges?: boolean;
76
- };
77
-
78
- const check = checkLocalUpgrade(oldSource, { fromVersion: 'local-draft-1' });
79
- ```
80
-
81
- 无版本声明的历史文档需要传入 `fromVersion: 'local-draft-1'`,才会执行 draft-1 检查。显式 `fromVersion` 与声明不一致时,检查被拒绝。迁移源只接受 `local-draft-1` 和当前的 `local-draft-2`;旧版 YAML 修订和未知名称会被拒绝。
82
-
83
- `needsMigration` 表示源码需要写入或替换声明:无声明源码需要补上当前指令,当前源码已经完整,draft-1 源码需要替换指令。版本变化本身可以识别、但存在阻止安全迁移的条件时,`ok` 为 `false`。
84
-
85
- ## 迁移源码
86
-
87
- ```ts
88
- import { migrateLocalSource } from 'reactive-md';
89
-
90
- const result = migrateLocalSource(oldSource, { fromVersion: 'local-draft-1' });
91
- // {
92
- // ok: boolean,
93
- // fromVersion: string,
94
- // toVersion: 'local-draft-2',
95
- // needsMigration: boolean,
96
- // diagnostics: Diagnostic[],
97
- // source: string,
98
- // changed: boolean,
99
- // edits: { range: SourceRange; text: string }[]
100
- // }
101
- ```
102
-
103
- 迁移只写入或替换元数据注释,保留正文。正文原始字节、UTF-8 BOM 和 CRLF 换行保持不变;操作幂等,已迁移到当前版本的源码返回 `changed: false` 和相同文本。`edits` 定位每处替换。迁移被阻止时不产生迁移结果,调用方传入的内容保持不变。
104
-
105
- 把 `local-draft-1` 源码迁移到 `local-draft-2` 之前,迁移会阻止:
106
-
107
- - 使用 17 个新增保留表达式名的绑定:`sum`、`average`、`minOf`、`maxOf`、`formatNumber`、`formatPercent`、`formatScientific`、`formatCurrency`、`trim`、`lower`、`upper`、`startsWith`、`endsWith`、`replace`、`slice`、`dateCompare`、`dateDiff`;
108
- - 代码之外出现的 15 个新增可识别标签名:`jump`、`anchor`、`text`、`section`、`multi-select`、`range-slider`、`coordinate`、`quiz`、`steps`、`step`、`computed`、`const`、`validation`、`data-table`、`column`;
109
- - 表达式中的数组语法或新增内置函数调用;字符串字面量中的文本不触发此检查;
110
- - 源码当前的编译错误。
111
-
112
- 诊断给出准确位置。迁移不重命名标识符、不改写表达式,也不激活原先按原文显示的标签;这些属于作者对源码的修改。
113
-
114
- 文本控件需要一次明确的兼容决定。`input` 或 `textarea` 带大于零的 `min-length`,或带 `max-length` 时,astral Unicode 的读者语义会改变:draft-2 按 Unicode 码点计数,draft-1 按 UTF-16 代码单元计数。除非允许语义变化,迁移会阻止这些控件:
115
-
116
- ```ts
117
- migrateLocalSource(oldSource, {
118
- fromVersion: 'local-draft-1',
119
- allowSemanticChanges: true,
120
- });
121
- ```
122
-
123
- 开启后迁移继续,并为每个受影响的控件返回警告。新的码点上限就是预期读者行为时使用该选项。
124
-
125
- 清单完成样式是有记录的兼容例外。这项视觉变化本身不阻止迁移,也不按核心运行时语义失败处理。
126
-
127
- 迁移会改变源码摘要。现有 `reactive-md-state/v1` 文件随后无法通过摘要校验,迁移后应重新导出状态文件。迁移不会改写状态文件。
128
-
129
- ## CLI
130
-
131
- ```sh
132
- reactive-md migrate doc.reactive.md
133
- reactive-md migrate - --from local-draft-1 -o doc.reactive.md
134
- reactive-md migrate doc.reactive.md --check
135
- reactive-md migrate doc.reactive.md --check --json
136
- reactive-md migrate old.reactive.md --from local-draft-1 --accept-semantic-changes -o new.reactive.md
137
- ```
138
-
139
- | 选项 | 含义 |
140
- | --- | --- |
141
- | `[file\|-]` | 输入文件;`-` 表示标准输入 |
142
- | `--from local-draft-1\|local-draft-2` | 源修订;默认取声明或当前修订 |
143
- | `--check` | 只报告是否需要迁移,从不写入 |
144
- | `--json` | 标准输出结构化报告,且是唯一的 stdout 内容 |
145
- | `-o, --output <file>` | 新建文件;拒绝任何已存在的路径,包括输入文件本身 |
146
- | `--accept-semantic-changes` | 允许文本控件长度语义变化,并报告警告 |
147
- | `--locale en\|zh` | 诊断和摘要的显示语言 |
148
-
149
- 默认把迁移后的源码写到标准输出。输入文件不会被覆盖;`-o` 使用独占创建,目标已存在即报错。没有 `-o` 时,请重定向 stdout 保存结果。
150
-
151
- `--check` 从不写入。它输出诊断和摘要;带 `--json` 时输出 JSON 报告。需要迁移或被阻止时退出 `1`,源码已是当前版本时退出 `0`。普通迁移被阻止时退出 `1`,成功时退出 `0`。用法和 I/O 错误退出 `2`。不要把源码文本混入 JSON 报告。
152
-
153
- 命令一次迁移一份源码。本版本不提供 `--write`、不就地覆盖,也不提供破坏性批量操作。
154
-
155
- ## 范围
156
-
157
- 迁移处理声明的元数据变化,并检查正文能否跨越修订边界。它不是旧版读取器:不解释 YAML `state`/`data`/`computed`/`actions` 配置块、directive 或其他 draft 之前的语法,也不改写正文。在 `local-draft-2` 下已经无法编译的源码会保持阻止状态,直到作者修复报告的位置。
158
-
159
- `0.6.0` 同时提供于 `latest` 与 `next` 渠道。本页说明从 `0.4.0` 起提供的迁移工具。
1
+ # 源码修订与迁移
2
+
3
+ 本文说明 `0.4.0` 中的显式源码修订、编译器的处理方式,以及纯核心 API 与 CLI 迁移工具。语法规则见[语法规范](../reference/local-interaction-syntax-ch.md),包版本与 API 兼容规则见[版本与兼容性](compatibility-ch.md),组块升级清单见[0.4.0 发布与迁移](../releases/release-0.4.0-ch.md)。
4
+
5
+ ## 声明修订
6
+
7
+ 源码用一行 HTML 注释声明修订:
8
+
9
+ ```markdown
10
+ <!-- reactive-md: local-draft-2 -->
11
+ ```
12
+
13
+ 该指令属于文档前导区,位于 `<theme>` 声明和正文之前。BOM、空行和普通 Markdown 注释可以出现在它前面。只允许一条指令。
14
+
15
+ 行内代码、代码围栏、数学区域和按原文显示的未知标签示例都不是指令。在文档里展示这一行,不会为周围文档声明版本。
16
+
17
+ 编译行为:
18
+
19
+ | 源码 | 结果 |
20
+ | --- | --- |
21
+ | 没有指令 | 按当前修订 `local-draft-2` 解析,与之前一致;不新增警告 |
22
+ | `local-draft-2` | 正常解析 |
23
+ | `local-draft-1` 或其他显式旧修订 | 以 `local.version.*` 诊断拒绝 |
24
+ | 未知、格式错误、重复或位置错误的指令 | 以 `local.version.*` 诊断拒绝 |
25
+
26
+ 版本声明被拒绝时不创建运行时。声明旧修订不会选择旧解析器,也不会让文档在现行规则下可读;必须先迁移源码。
27
+
28
+ 在这一声明出现之前构建的读者(包括 `0.3.1`)会把这条注释当作普通 HTML 注释。它们不校验声明,不拒绝旧修订,也不执行这项检查。声明保护的是在本版本及后续版本中打开的文档;依赖这项检查前,先迁移旧文档。
29
+
30
+ ## 查看声明的修订
31
+
32
+ `inspectLocalSourceVersion` 从 `reactive-md` 导出,不编译,也不创建运行时:
33
+
34
+ ```ts
35
+ import { inspectLocalSourceVersion } from 'reactive-md';
36
+
37
+ const info = inspectLocalSourceVersion(source);
38
+ // {
39
+ // declaredVersion: string | null,
40
+ // effectiveVersion: string,
41
+ // supported: boolean,
42
+ // range: SourceRange | null,
43
+ // diagnostics: Diagnostic[]
44
+ // }
45
+ ```
46
+
47
+ - `declaredVersion` 是指令声明的修订;无指令时为 `null`。
48
+ - `effectiveVersion` 是用于解释判定的修订:有声明时取声明值,否则取当前修订。`supported` 为 `false` 时不进行解释。
49
+ - `supported` 表示当前编译器是否接受该修订。
50
+ - `range` 指向原始源码中的指令;没有指令时为 `null`。
51
+ - `diagnostics` 使用 `local.version.*` 前缀报告格式错误、重复、位置错误、旧修订或未知声明。
52
+
53
+ 无指令源码返回 `declaredVersion: null`、`effectiveVersion: 'local-draft-2'`、`supported: true`,不产生版本诊断。
54
+
55
+ ## 检查升级
56
+
57
+ ```ts
58
+ import { checkLocalUpgrade } from 'reactive-md';
59
+
60
+ const check = checkLocalUpgrade(source);
61
+ // {
62
+ // ok: boolean,
63
+ // fromVersion: string,
64
+ // toVersion: 'local-draft-2',
65
+ // needsMigration: boolean,
66
+ // diagnostics: Diagnostic[]
67
+ // }
68
+ ```
69
+
70
+ `fromVersion` 默认取声明的修订;源码没有声明时取当前修订。可以用 `LocalUpgradeOptions` 覆盖:
71
+
72
+ ```ts
73
+ type LocalUpgradeOptions = {
74
+ fromVersion?: string;
75
+ allowSemanticChanges?: boolean;
76
+ };
77
+
78
+ const check = checkLocalUpgrade(oldSource, { fromVersion: 'local-draft-1' });
79
+ ```
80
+
81
+ 无版本声明的历史文档需要传入 `fromVersion: 'local-draft-1'`,才会执行 draft-1 检查。显式 `fromVersion` 与声明不一致时,检查被拒绝。迁移源只接受 `local-draft-1` 和当前的 `local-draft-2`;旧版 YAML 修订和未知名称会被拒绝。
82
+
83
+ `needsMigration` 表示源码需要写入或替换声明:无声明源码需要补上当前指令,当前源码已经完整,draft-1 源码需要替换指令。版本变化本身可以识别、但存在阻止安全迁移的条件时,`ok` 为 `false`。
84
+
85
+ ## 迁移源码
86
+
87
+ ```ts
88
+ import { migrateLocalSource } from 'reactive-md';
89
+
90
+ const result = migrateLocalSource(oldSource, { fromVersion: 'local-draft-1' });
91
+ // {
92
+ // ok: boolean,
93
+ // fromVersion: string,
94
+ // toVersion: 'local-draft-2',
95
+ // needsMigration: boolean,
96
+ // diagnostics: Diagnostic[],
97
+ // source: string,
98
+ // changed: boolean,
99
+ // edits: { range: SourceRange; text: string }[]
100
+ // }
101
+ ```
102
+
103
+ 迁移只写入或替换元数据注释,保留正文。正文原始字节、UTF-8 BOM 和 CRLF 换行保持不变;操作幂等,已迁移到当前版本的源码返回 `changed: false` 和相同文本。`edits` 定位每处替换。迁移被阻止时不产生迁移结果,调用方传入的内容保持不变。
104
+
105
+ 把 `local-draft-1` 源码迁移到 `local-draft-2` 之前,迁移会阻止:
106
+
107
+ - 使用 17 个新增保留表达式名的绑定:`sum`、`average`、`minOf`、`maxOf`、`formatNumber`、`formatPercent`、`formatScientific`、`formatCurrency`、`trim`、`lower`、`upper`、`startsWith`、`endsWith`、`replace`、`slice`、`dateCompare`、`dateDiff`;
108
+ - 代码之外出现的 15 个新增可识别标签名:`jump`、`anchor`、`text`、`section`、`multi-select`、`range-slider`、`coordinate`、`quiz`、`steps`、`step`、`computed`、`const`、`validation`、`data-table`、`column`;
109
+ - 表达式中的数组语法或新增内置函数调用;字符串字面量中的文本不触发此检查;
110
+ - 源码当前的编译错误。
111
+
112
+ 诊断给出准确位置。迁移不重命名标识符、不改写表达式,也不激活原先按原文显示的标签;这些属于作者对源码的修改。
113
+
114
+ 文本控件需要一次明确的兼容决定。`input` 或 `textarea` 带大于零的 `min-length`,或带 `max-length` 时,astral Unicode 的读者语义会改变:draft-2 按 Unicode 码点计数,draft-1 按 UTF-16 代码单元计数。除非允许语义变化,迁移会阻止这些控件:
115
+
116
+ ```ts
117
+ migrateLocalSource(oldSource, {
118
+ fromVersion: 'local-draft-1',
119
+ allowSemanticChanges: true,
120
+ });
121
+ ```
122
+
123
+ 开启后迁移继续,并为每个受影响的控件返回警告。新的码点上限就是预期读者行为时使用该选项。
124
+
125
+ 清单完成样式是有记录的兼容例外。这项视觉变化本身不阻止迁移,也不按核心运行时语义失败处理。
126
+
127
+ 迁移会改变源码摘要。现有 `reactive-md-state/v1` 文件随后无法通过摘要校验,迁移后应重新导出状态文件。迁移不会改写状态文件。
128
+
129
+ ## CLI
130
+
131
+ ```sh
132
+ reactive-md migrate doc.reactive.md
133
+ reactive-md migrate - --from local-draft-1 -o doc.reactive.md
134
+ reactive-md migrate doc.reactive.md --check
135
+ reactive-md migrate doc.reactive.md --check --json
136
+ reactive-md migrate old.reactive.md --from local-draft-1 --accept-semantic-changes -o new.reactive.md
137
+ ```
138
+
139
+ | 选项 | 含义 |
140
+ | --- | --- |
141
+ | `[file\|-]` | 输入文件;`-` 表示标准输入 |
142
+ | `--from local-draft-1\|local-draft-2` | 源修订;默认取声明或当前修订 |
143
+ | `--check` | 只报告是否需要迁移,从不写入 |
144
+ | `--json` | 标准输出结构化报告,且是唯一的 stdout 内容 |
145
+ | `-o, --output <file>` | 新建文件;拒绝任何已存在的路径,包括输入文件本身 |
146
+ | `--accept-semantic-changes` | 允许文本控件长度语义变化,并报告警告 |
147
+ | `--locale en\|zh` | 诊断和摘要的显示语言 |
148
+
149
+ 默认把迁移后的源码写到标准输出。输入文件不会被覆盖;`-o` 使用独占创建,目标已存在即报错。没有 `-o` 时,请重定向 stdout 保存结果。
150
+
151
+ `--check` 从不写入。它输出诊断和摘要;带 `--json` 时输出 JSON 报告。需要迁移或被阻止时退出 `1`,源码已是当前版本时退出 `0`。普通迁移被阻止时退出 `1`,成功时退出 `0`。用法和 I/O 错误退出 `2`。不要把源码文本混入 JSON 报告。
152
+
153
+ 命令一次迁移一份源码。本版本不提供 `--write`、不就地覆盖,也不提供破坏性批量操作。
154
+
155
+ ## 范围
156
+
157
+ 迁移处理声明的元数据变化,并检查正文能否跨越修订边界。它不是旧版读取器:不解释 YAML `state`/`data`/`computed`/`actions` 配置块、directive 或其他 draft 之前的语法,也不改写正文。在 `local-draft-2` 下已经无法编译的源码会保持阻止状态,直到作者修复报告的位置。
158
+
159
+ `0.6.0` 同时提供于 `latest` 与 `next` 渠道。本页说明从 `0.4.0` 起提供的迁移工具。
@@ -1,159 +1,159 @@
1
- # Source revisions and migration
2
-
3
- This page covers explicit source revisions, how the compiler treats them, and the pure core and CLI migration tools in `0.4.0`. Syntax rules are in the [syntax specification](../reference/local-interaction-syntax-en.md); package and API compatibility rules are in [Versions and compatibility](compatibility-en.md); the component upgrade checklist is in [0.4.0 release and migration](../releases/release-0.4.0-en.md).
4
-
5
- ## Declaring a revision
6
-
7
- A source declares its revision with one HTML comment on its own line:
8
-
9
- ```markdown
10
- <!-- reactive-md: local-draft-2 -->
11
- ```
12
-
13
- The directive belongs to the document prologue, before the `<theme>` declaration and before any body content. A BOM, blank lines and ordinary Markdown comments may precede it. Exactly one directive is allowed.
14
-
15
- Code spans and fences, math regions and inert fallback examples are not directives. Showing the line in documentation does not version the surrounding document.
16
-
17
- Compilation behavior:
18
-
19
- | Source | Result |
20
- | --- | --- |
21
- | No directive | Parsed as the current revision `local-draft-2`, as before; no new warning |
22
- | `local-draft-2` | Parsed normally |
23
- | `local-draft-1` or another explicit older revision | Rejected with a `local.version.*` diagnostic |
24
- | Unknown, malformed, duplicate or misplaced directive | Rejected with a `local.version.*` diagnostic |
25
-
26
- A rejected version declaration constructs no runtime. Declaring an old revision does not select an old parser, and it does not make the document readable under current rules. Migrate the source first.
27
-
28
- Readers built before this declaration existed, including `0.3.1`, treat the comment as an inert HTML comment. They do not validate it, do not reject old revisions and do not enforce this guard. A declaration protects documents opened in this build and later builds; migrate old documents before relying on the check.
29
-
30
- ## Inspect the declared revision
31
-
32
- `inspectLocalSourceVersion` is exported from `reactive-md` and does not compile or create a runtime:
33
-
34
- ```ts
35
- import { inspectLocalSourceVersion } from 'reactive-md';
36
-
37
- const info = inspectLocalSourceVersion(source);
38
- // {
39
- // declaredVersion: string | null,
40
- // effectiveVersion: string,
41
- // supported: boolean,
42
- // range: SourceRange | null,
43
- // diagnostics: Diagnostic[]
44
- // }
45
- ```
46
-
47
- - `declaredVersion` is the revision named by the directive, or `null` when the source is unversioned.
48
- - `effectiveVersion` is the revision used for interpretation decisions: the declared revision when present, otherwise the current revision. When `supported` is `false`, no interpretation takes place.
49
- - `supported` is `true` when this compiler accepts that revision.
50
- - `range` locates the directive in the original source, or is `null` when there is none.
51
- - `diagnostics` reports malformed, duplicate, misplaced, old or unknown declarations using the `local.version.*` prefix.
52
-
53
- An unversioned source reports `declaredVersion: null`, `effectiveVersion: 'local-draft-2'`, `supported: true` and no version diagnostic.
54
-
55
- ## Check an upgrade
56
-
57
- ```ts
58
- import { checkLocalUpgrade } from 'reactive-md';
59
-
60
- const check = checkLocalUpgrade(source);
61
- // {
62
- // ok: boolean,
63
- // fromVersion: string,
64
- // toVersion: 'local-draft-2',
65
- // needsMigration: boolean,
66
- // diagnostics: Diagnostic[]
67
- // }
68
- ```
69
-
70
- `fromVersion` defaults to the declared revision, or to the current revision when the source is unversioned. Pass `LocalUpgradeOptions` to override it:
71
-
72
- ```ts
73
- type LocalUpgradeOptions = {
74
- fromVersion?: string;
75
- allowSemanticChanges?: boolean;
76
- };
77
-
78
- const check = checkLocalUpgrade(oldSource, { fromVersion: 'local-draft-1' });
79
- ```
80
-
81
- An unversioned historical document requires `fromVersion: 'local-draft-1'` to receive the draft-1 checks. When an explicit `fromVersion` disagrees with the declaration, the check is rejected. Only `local-draft-1` and the current `local-draft-2` are accepted as migration sources; legacy YAML revisions and unknown names are rejected.
82
-
83
- `needsMigration` is `true` when the source needs a new or different directive. An unversioned source needs the current directive stamped; a current source is already complete; a draft-1 source needs its directive replaced. `ok` is `false` when a blocker prevents a safe migration even though the version change itself is recognized.
84
-
85
- ## Migrate source
86
-
87
- ```ts
88
- import { migrateLocalSource } from 'reactive-md';
89
-
90
- const result = migrateLocalSource(oldSource, { fromVersion: 'local-draft-1' });
91
- // {
92
- // ok: boolean,
93
- // fromVersion: string,
94
- // toVersion: 'local-draft-2',
95
- // needsMigration: boolean,
96
- // diagnostics: Diagnostic[],
97
- // source: string,
98
- // changed: boolean,
99
- // edits: { range: SourceRange; text: string }[]
100
- // }
101
- ```
102
-
103
- Migration stamps or replaces the metadata comment and preserves the body. It keeps original body bytes, a UTF-8 BOM and CRLF line endings, and is idempotent: migrating an already current source returns `changed: false` and the same text. `edits` locates each replacement. A blocked migration produces no migrated output, and the caller's input remains unchanged.
104
-
105
- Before moving `local-draft-1` source to `local-draft-2`, migration blocks:
106
-
107
- - bindings that use one of the 17 newly reserved expression names: `sum`, `average`, `minOf`, `maxOf`, `formatNumber`, `formatPercent`, `formatScientific`, `formatCurrency`, `trim`, `lower`, `upper`, `startsWith`, `endsWith`, `replace`, `slice`, `dateCompare`, `dateDiff`;
108
- - the 15 newly recognized tag names outside code: `jump`, `anchor`, `text`, `section`, `multi-select`, `range-slider`, `coordinate`, `quiz`, `steps`, `step`, `computed`, `const`, `validation`, `data-table`, `column`;
109
- - array syntax or calls to newly introduced built-ins in expressions; text inside string literals does not trigger this check;
110
- - current compile errors in the source.
111
-
112
- Diagnostics report precise source positions. Migration does not rename identifiers, rewrite expressions or activate formerly inert tags. Those are source changes for the author.
113
-
114
- Text controls need one explicit compatibility decision. An `input` or `textarea` with `min-length` greater than zero, or with a `max-length`, changes reader semantics for astral Unicode: draft-2 counts Unicode code points while draft-1 counted UTF-16 code units. Migration blocks these controls unless semantic changes are allowed:
115
-
116
- ```ts
117
- migrateLocalSource(oldSource, {
118
- fromVersion: 'local-draft-1',
119
- allowSemanticChanges: true,
120
- });
121
- ```
122
-
123
- With that option, migration proceeds and returns a warning for each affected control. Use it when the new code-point limits are the intended reader behavior.
124
-
125
- Completed checklist styling is a documented compatibility exception. The visual change alone does not block migration and is not treated as a core runtime-semantic failure.
126
-
127
- Migration changes the source digest. Existing `reactive-md-state/v1` files then fail digest validation, so export a fresh state file after migrating. Migration never rewrites state files.
128
-
129
- ## CLI
130
-
131
- ```sh
132
- reactive-md migrate doc.reactive.md
133
- reactive-md migrate - --from local-draft-1 -o doc.reactive.md
134
- reactive-md migrate doc.reactive.md --check
135
- reactive-md migrate doc.reactive.md --check --json
136
- reactive-md migrate old.reactive.md --from local-draft-1 --accept-semantic-changes -o new.reactive.md
137
- ```
138
-
139
- | Option | Meaning |
140
- | --- | --- |
141
- | `[file\|-]` | Input file, or `-` for standard input |
142
- | `--from local-draft-1\|local-draft-2` | Source revision; defaults to the declaration or the current revision |
143
- | `--check` | Report whether migration is needed; never writes |
144
- | `--json` | Structured report on standard output; the only stdout content |
145
- | `-o, --output <file>` | Create a new file; refuses any existing path, including the input |
146
- | `--accept-semantic-changes` | Allow the text-control length change and report warnings |
147
- | `--locale en\|zh` | Language for displayed diagnostics and summaries |
148
-
149
- By default, migrated source goes to standard output. The input file is never overwritten; `-o` uses exclusive creation, so an existing file is an error. Without `-o`, redirect stdout to keep the result.
150
-
151
- `--check` never writes. It prints diagnostics and a summary, or a JSON report with `--json`. It exits `1` when changes are needed or migration is blocked, and `0` when the source is already current. A normal migration exits `1` when blocked and `0` on success. Usage and I/O errors exit `2`. Do not mix source text with the JSON report.
152
-
153
- The command migrates one source at a time. This build has no `--write` mode, no in-place overwrite and no destructive batch operation.
154
-
155
- ## Scope
156
-
157
- Migration handles the declared metadata change and checks whether the body can cross the revision boundary. It is not a legacy reader: it does not interpret YAML `state`/`data`/`computed`/`actions` blocks, directives or other pre-draft syntax, and it does not rewrite the body. Source that already fails to compile under `local-draft-2` stays blocked until the author fixes the reported positions.
158
-
159
- `0.6.0` is available on both the `latest` and `next` channels. This page documents the migration tools introduced in `0.4.0`.
1
+ # Source revisions and migration
2
+
3
+ This page covers explicit source revisions, how the compiler treats them, and the pure core and CLI migration tools in `0.4.0`. Syntax rules are in the [syntax specification](../reference/local-interaction-syntax-en.md); package and API compatibility rules are in [Versions and compatibility](compatibility-en.md); the component upgrade checklist is in [0.4.0 release and migration](../releases/release-0.4.0-en.md).
4
+
5
+ ## Declaring a revision
6
+
7
+ A source declares its revision with one HTML comment on its own line:
8
+
9
+ ```markdown
10
+ <!-- reactive-md: local-draft-2 -->
11
+ ```
12
+
13
+ The directive belongs to the document prologue, before the `<theme>` declaration and before any body content. A BOM, blank lines and ordinary Markdown comments may precede it. Exactly one directive is allowed.
14
+
15
+ Code spans and fences, math regions and inert fallback examples are not directives. Showing the line in documentation does not version the surrounding document.
16
+
17
+ Compilation behavior:
18
+
19
+ | Source | Result |
20
+ | --- | --- |
21
+ | No directive | Parsed as the current revision `local-draft-2`, as before; no new warning |
22
+ | `local-draft-2` | Parsed normally |
23
+ | `local-draft-1` or another explicit older revision | Rejected with a `local.version.*` diagnostic |
24
+ | Unknown, malformed, duplicate or misplaced directive | Rejected with a `local.version.*` diagnostic |
25
+
26
+ A rejected version declaration constructs no runtime. Declaring an old revision does not select an old parser, and it does not make the document readable under current rules. Migrate the source first.
27
+
28
+ Readers built before this declaration existed, including `0.3.1`, treat the comment as an inert HTML comment. They do not validate it, do not reject old revisions and do not enforce this guard. A declaration protects documents opened in this build and later builds; migrate old documents before relying on the check.
29
+
30
+ ## Inspect the declared revision
31
+
32
+ `inspectLocalSourceVersion` is exported from `reactive-md` and does not compile or create a runtime:
33
+
34
+ ```ts
35
+ import { inspectLocalSourceVersion } from 'reactive-md';
36
+
37
+ const info = inspectLocalSourceVersion(source);
38
+ // {
39
+ // declaredVersion: string | null,
40
+ // effectiveVersion: string,
41
+ // supported: boolean,
42
+ // range: SourceRange | null,
43
+ // diagnostics: Diagnostic[]
44
+ // }
45
+ ```
46
+
47
+ - `declaredVersion` is the revision named by the directive, or `null` when the source is unversioned.
48
+ - `effectiveVersion` is the revision used for interpretation decisions: the declared revision when present, otherwise the current revision. When `supported` is `false`, no interpretation takes place.
49
+ - `supported` is `true` when this compiler accepts that revision.
50
+ - `range` locates the directive in the original source, or is `null` when there is none.
51
+ - `diagnostics` reports malformed, duplicate, misplaced, old or unknown declarations using the `local.version.*` prefix.
52
+
53
+ An unversioned source reports `declaredVersion: null`, `effectiveVersion: 'local-draft-2'`, `supported: true` and no version diagnostic.
54
+
55
+ ## Check an upgrade
56
+
57
+ ```ts
58
+ import { checkLocalUpgrade } from 'reactive-md';
59
+
60
+ const check = checkLocalUpgrade(source);
61
+ // {
62
+ // ok: boolean,
63
+ // fromVersion: string,
64
+ // toVersion: 'local-draft-2',
65
+ // needsMigration: boolean,
66
+ // diagnostics: Diagnostic[]
67
+ // }
68
+ ```
69
+
70
+ `fromVersion` defaults to the declared revision, or to the current revision when the source is unversioned. Pass `LocalUpgradeOptions` to override it:
71
+
72
+ ```ts
73
+ type LocalUpgradeOptions = {
74
+ fromVersion?: string;
75
+ allowSemanticChanges?: boolean;
76
+ };
77
+
78
+ const check = checkLocalUpgrade(oldSource, { fromVersion: 'local-draft-1' });
79
+ ```
80
+
81
+ An unversioned historical document requires `fromVersion: 'local-draft-1'` to receive the draft-1 checks. When an explicit `fromVersion` disagrees with the declaration, the check is rejected. Only `local-draft-1` and the current `local-draft-2` are accepted as migration sources; legacy YAML revisions and unknown names are rejected.
82
+
83
+ `needsMigration` is `true` when the source needs a new or different directive. An unversioned source needs the current directive stamped; a current source is already complete; a draft-1 source needs its directive replaced. `ok` is `false` when a blocker prevents a safe migration even though the version change itself is recognized.
84
+
85
+ ## Migrate source
86
+
87
+ ```ts
88
+ import { migrateLocalSource } from 'reactive-md';
89
+
90
+ const result = migrateLocalSource(oldSource, { fromVersion: 'local-draft-1' });
91
+ // {
92
+ // ok: boolean,
93
+ // fromVersion: string,
94
+ // toVersion: 'local-draft-2',
95
+ // needsMigration: boolean,
96
+ // diagnostics: Diagnostic[],
97
+ // source: string,
98
+ // changed: boolean,
99
+ // edits: { range: SourceRange; text: string }[]
100
+ // }
101
+ ```
102
+
103
+ Migration stamps or replaces the metadata comment and preserves the body. It keeps original body bytes, a UTF-8 BOM and CRLF line endings, and is idempotent: migrating an already current source returns `changed: false` and the same text. `edits` locates each replacement. A blocked migration produces no migrated output, and the caller's input remains unchanged.
104
+
105
+ Before moving `local-draft-1` source to `local-draft-2`, migration blocks:
106
+
107
+ - bindings that use one of the 17 newly reserved expression names: `sum`, `average`, `minOf`, `maxOf`, `formatNumber`, `formatPercent`, `formatScientific`, `formatCurrency`, `trim`, `lower`, `upper`, `startsWith`, `endsWith`, `replace`, `slice`, `dateCompare`, `dateDiff`;
108
+ - the 15 newly recognized tag names outside code: `jump`, `anchor`, `text`, `section`, `multi-select`, `range-slider`, `coordinate`, `quiz`, `steps`, `step`, `computed`, `const`, `validation`, `data-table`, `column`;
109
+ - array syntax or calls to newly introduced built-ins in expressions; text inside string literals does not trigger this check;
110
+ - current compile errors in the source.
111
+
112
+ Diagnostics report precise source positions. Migration does not rename identifiers, rewrite expressions or activate formerly inert tags. Those are source changes for the author.
113
+
114
+ Text controls need one explicit compatibility decision. An `input` or `textarea` with `min-length` greater than zero, or with a `max-length`, changes reader semantics for astral Unicode: draft-2 counts Unicode code points while draft-1 counted UTF-16 code units. Migration blocks these controls unless semantic changes are allowed:
115
+
116
+ ```ts
117
+ migrateLocalSource(oldSource, {
118
+ fromVersion: 'local-draft-1',
119
+ allowSemanticChanges: true,
120
+ });
121
+ ```
122
+
123
+ With that option, migration proceeds and returns a warning for each affected control. Use it when the new code-point limits are the intended reader behavior.
124
+
125
+ Completed checklist styling is a documented compatibility exception. The visual change alone does not block migration and is not treated as a core runtime-semantic failure.
126
+
127
+ Migration changes the source digest. Existing `reactive-md-state/v1` files then fail digest validation, so export a fresh state file after migrating. Migration never rewrites state files.
128
+
129
+ ## CLI
130
+
131
+ ```sh
132
+ reactive-md migrate doc.reactive.md
133
+ reactive-md migrate - --from local-draft-1 -o doc.reactive.md
134
+ reactive-md migrate doc.reactive.md --check
135
+ reactive-md migrate doc.reactive.md --check --json
136
+ reactive-md migrate old.reactive.md --from local-draft-1 --accept-semantic-changes -o new.reactive.md
137
+ ```
138
+
139
+ | Option | Meaning |
140
+ | --- | --- |
141
+ | `[file\|-]` | Input file, or `-` for standard input |
142
+ | `--from local-draft-1\|local-draft-2` | Source revision; defaults to the declaration or the current revision |
143
+ | `--check` | Report whether migration is needed; never writes |
144
+ | `--json` | Structured report on standard output; the only stdout content |
145
+ | `-o, --output <file>` | Create a new file; refuses any existing path, including the input |
146
+ | `--accept-semantic-changes` | Allow the text-control length change and report warnings |
147
+ | `--locale en\|zh` | Language for displayed diagnostics and summaries |
148
+
149
+ By default, migrated source goes to standard output. The input file is never overwritten; `-o` uses exclusive creation, so an existing file is an error. Without `-o`, redirect stdout to keep the result.
150
+
151
+ `--check` never writes. It prints diagnostics and a summary, or a JSON report with `--json`. It exits `1` when changes are needed or migration is blocked, and `0` when the source is already current. A normal migration exits `1` when blocked and `0` on success. Usage and I/O errors exit `2`. Do not mix source text with the JSON report.
152
+
153
+ The command migrates one source at a time. This build has no `--write` mode, no in-place overwrite and no destructive batch operation.
154
+
155
+ ## Scope
156
+
157
+ Migration handles the declared metadata change and checks whether the body can cross the revision boundary. It is not a legacy reader: it does not interpret YAML `state`/`data`/`computed`/`actions` blocks, directives or other pre-draft syntax, and it does not rewrite the body. Source that already fails to compile under `local-draft-2` stays blocked until the author fixes the reported positions.
158
+
159
+ `0.6.0` is available on both the `latest` and `next` channels. This page documents the migration tools introduced in `0.4.0`.