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
@@ -0,0 +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](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](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.4.0` is the preview release on the `next` channel. This page documents its migration tools.
@@ -0,0 +1,107 @@
1
+ # Reactive MD 主题协议
2
+
3
+ 协议修订:`reactive-md-theme-1`。本功能随 `0.4.0` 发布,该版本是 `next` 渠道的预览版;现有外观作为内置 `default` 保留。
4
+
5
+ ## 文档选择主题
6
+
7
+ 在正文之前写一行声明:
8
+
9
+ ```markdown
10
+ <theme name="default">
11
+
12
+ # 文档标题
13
+ ```
14
+
15
+ 也接受 `<theme name="default" />`。省略声明时使用 `default`。声明前允许空白、BOM 和注释;声明只允许出现一次,不能嵌入组件。`name` 是静态字符串,使用小写 kebab-case,首字符为字母,最多 64 个字符。声明不接受表达式或其他属性。
16
+
17
+ 声明是文档元数据,不属于组块,不生成可见组件。编译结果的 `document.theme` 保存选择,`document.themeRange` 保存声明在原文中的位置;正文节点继续使用原始源码位置。代码围栏、行内代码、注释和转义中的示例保持字面含义。
18
+
19
+ 无效声明产生 `local.theme.*` 警告并使用 `default`。重复声明不改变第一次的选择;正文之后或组件内的声明不影响主题。正常正文和控件继续工作。
20
+
21
+ ## 宿主登记主题
22
+
23
+ 主题由开发者提供 CSS 和登记信息。宿主先导入公共样式,再导入主题 CSS,并通过 `themes` 提供允许选择的主题:
24
+
25
+ ```tsx
26
+ import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
+ import { LocalReactiveDocument } from 'reactive-md/react';
28
+ import 'reactive-md/styles.css';
29
+ import './paper-theme.css';
30
+
31
+ const paperTheme = {
32
+ name: 'paper',
33
+ protocol: LOCAL_THEME_PROTOCOL,
34
+ colorSchemes: ['light', 'dark'],
35
+ } as const satisfies LocalThemeDefinition;
36
+
37
+ export function Article({ source }: { source: string }) {
38
+ return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
+ }
40
+ ```
41
+
42
+ 此示例说明登记方式;仓库仅内置 `default`,不提供 `paper` 的设计或 CSS。
43
+
44
+ | 字段 | 要求 |
45
+ | --- | --- |
46
+ | `name` | 符合文档名称规则;`default` 保留;同一宿主列表中唯一 |
47
+ | `protocol` | 必须为 `reactive-md-theme-1`,可使用 `LOCAL_THEME_PROTOCOL` |
48
+ | `colorSchemes` | 必须同时包含 `light` 和 `dark` |
49
+
50
+ 宿主负责加载 CSS;登记信息不触发下载或注入样式。文档按名称选择宿主允许的主题,不接受 CSS、样式地址或脚本。主题 CSS 属于宿主信任的代码,宿主负责审查其作用域和资源引用。
51
+
52
+ 未知主题、所选名称重复、所选登记信息无效、协议不兼容或缺少深浅模式时,渲染器警告并回退到 `default`。纯核心宿主可调用 `resolveLocalTheme(name, themes, range?, source?)`,得到 `{ name, diagnostics }`。编译器只处理声明,不查询宿主的主题列表。
53
+
54
+ ## 深浅模式与实例作用域
55
+
56
+ 两个 React 组件均接受 `themes` 和 `colorScheme`。主题名称决定风格,`colorScheme` 决定该风格的深浅版本:
57
+
58
+ | 值 | 行为 |
59
+ | --- | --- |
60
+ | `light` | 当前文档使用浅色,包括处于深色宿主中时 |
61
+ | `dark` | 当前文档使用深色 |
62
+ | `auto`(默认) | 读取最近祖先的显式模式,否则跟随系统偏好;服务端输出以浅色开始 |
63
+
64
+ 祖先的显式模式支持 `data-color-scheme="light|dark"` 和已有的 `data-theme="light|dark"`。浏览器中祖先属性或系统偏好变化会更新文档。显式 `colorScheme` 优先。
65
+
66
+ 渲染器在当前文档根节点输出:
67
+
68
+ ```html
69
+ <article class="md-document local-document"
70
+ data-rmd-theme="paper"
71
+ data-color-scheme="dark">
72
+ ```
73
+
74
+ 每个实例独立选择主题与模式。主题 CSS 的每条规则必须限制在该主题根节点及其后代,例如 `[data-rmd-theme="paper"][data-color-scheme="dark"]`。不得使用会影响宿主的全局 `body`、`:root` 或无作用域的元素规则。
75
+
76
+ 改变 `themes` 或 `colorScheme` 不创建新运行时。`LocalReactiveDocument` 更换 `source` 时仍遵从既有规则,重新编译并创建运行时;宿主需要保留参数时可自行管理 `LocalDocumentView` 的文档和运行时。
77
+
78
+ ## 共享样式变量
79
+
80
+ 公共组件 CSS 提供结构、交互与默认样式。自定义主题继承完整的默认变量,按需覆盖;浅色和深色规则必须分别设计与验收。
81
+
82
+ | 用途 | 公共变量 |
83
+ | --- | --- |
84
+ | 背景 | `--paper`、`--surface`、`--document-bg`(默认跟随 `--surface`)、`--surface-subtle`、`--surface-hover`、`--surface-active` |
85
+ | 文字与边框 | `--ink`、`--ink-soft`、`--ink-muted`、`--line`、`--line-strong` |
86
+ | 强调色 | `--accent`、`--accent-hover`、`--accent-soft`、`--accent-line` |
87
+ | 状态 | `--info`、`--info-soft`、`--success`、`--success-soft`、`--success-line`、`--warning`、`--warning-soft`、`--warning-line`、`--danger`、`--danger-soft`、`--danger-line`、`--neutral-soft` |
88
+ | 焦点 | `--focus`、`--focus-outline`、`--focus-ring` |
89
+ | 数据与代码 | `--chart-1` 至 `--chart-8`、`--chart-grid`、`--chart-axis`、`--code-bg`、`--code-bg-deep`、`--code-ink` |
90
+ | 字体 | `--font-sans`、`--font-mono`、`--text-xs` 至 `--text-xl`、`--text-2xl`、`--text-block-title`、`--text-block-subtitle` |
91
+ | 行高与字重 | `--leading-tight`、`--leading-snug`、`--leading-normal`、`--leading-relaxed`、`--weight-regular`、`--weight-medium`、`--weight-semibold`、`--weight-bold` |
92
+ | 间距 | `--space-1` 至 `--space-7`、`--field-gap` |
93
+ | 圆角 | `--radius-control`、`--radius-card`、`--radius-panel`、`--radius-pill` |
94
+ | 控件 | `--control-height-sm`、`--control-height`、`--control-height-lg`、`--control-padding-x`、`--control-padding-y`、`--disabled-opacity` |
95
+ | 动效与阴影 | `--motion-fast`、`--motion-base`、`--motion-slow`、`--ease-standard`、`--shadow-sm`、`--shadow-md` |
96
+
97
+ 已有 `--blue`、`--blue-deep`、`--blue-soft`、`--blue-line` 保留兼容;新主题优先使用强调色变量。组件的局部 `color` 属性覆盖对应局部颜色,其余样式继续使用主题。数据序列、状态提示等保留各自的语义颜色。
98
+
99
+ ## 组件 CSS 与验收
100
+
101
+ 主题可在共享变量之外覆盖现有 `.md-*`、`.local-*` 组件类。文档根类、组件外层类和语义状态属性是主题的样式接口;内部节点的排列不是扩展 API。主题规则遵守文档作用域,并在公共样式之后加载。使用足够明确的根节点与组件选择器覆盖基础规则,避免依赖 `!important`。
102
+
103
+ 主题覆盖范围包括 Markdown 正文、表格、公式、输入控件、容器、反馈、图表与图解。新增组件必须读取共享变量并在 `default` 下可用;自定义主题未添加专门规则时继承公共样式。
104
+
105
+ 符合本协议的主题必须在两种模式下检查全部组件,以及 hover、focus、active、disabled、错误与选中状态。保持键盘焦点可见、文字和控件可读、375px 布局可用,并遵守减少动态效果的系统偏好。改变字号或字体后应检查 SVG 图解的标签、节点和边界。
106
+
107
+ 登记校验确认协议与模式声明;CSS 的实际覆盖、对比度和布局通过浏览器验收。验收应包含同页多主题隔离、显式浅色置于深色宿主、系统切换、状态保留和卸载清理。
@@ -0,0 +1,107 @@
1
+ # Reactive MD theme protocol
2
+
3
+ Protocol revision: `reactive-md-theme-1`. This feature ships in `0.4.0`, the preview release on the `next` channel. The built-in `default` preserves the existing appearance.
4
+
5
+ ## Selecting a theme
6
+
7
+ Place a declaration before the document body:
8
+
9
+ ```markdown
10
+ <theme name="default">
11
+
12
+ # Document title
13
+ ```
14
+
15
+ `<theme name="default" />` is also accepted. Omission selects `default`. Whitespace, a BOM and comments may precede the declaration. Declare it once, outside components. The static `name` uses lowercase kebab-case, starts with a letter and has at most 64 characters. Expressions and additional attributes are invalid.
16
+
17
+ The declaration is document metadata, does not count as a component and produces no visible element. Compilation stores `document.theme` and the original declaration's `document.themeRange`. Body nodes retain their original source positions. Fenced code, inline code, comments and escaped examples remain literal.
18
+
19
+ Invalid declarations produce `local.theme.*` warnings and select `default`. Repeated declarations do not change the first selection. Late or nested declarations do not select a theme. Healthy body content and controls remain usable.
20
+
21
+ ## Host registration
22
+
23
+ A developer supplies CSS and registration metadata. Import the shared styles before the theme stylesheet, then pass the allowed themes to the renderer:
24
+
25
+ ```tsx
26
+ import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
+ import { LocalReactiveDocument } from 'reactive-md/react';
28
+ import 'reactive-md/styles.css';
29
+ import './paper-theme.css';
30
+
31
+ const paperTheme = {
32
+ name: 'paper',
33
+ protocol: LOCAL_THEME_PROTOCOL,
34
+ colorSchemes: ['light', 'dark'],
35
+ } as const satisfies LocalThemeDefinition;
36
+
37
+ export function Article({ source }: { source: string }) {
38
+ return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
+ }
40
+ ```
41
+
42
+ This demonstrates registration. The repository includes only `default`; it does not include a `paper` design or stylesheet.
43
+
44
+ | Field | Requirement |
45
+ | --- | --- |
46
+ | `name` | Follows the document identifier rules; unique in the host list; `default` is reserved |
47
+ | `protocol` | Must be `reactive-md-theme-1`; use `LOCAL_THEME_PROTOCOL` |
48
+ | `colorSchemes` | Must include both `light` and `dark` |
49
+
50
+ The host loads the CSS. Registration does not fetch or inject styles. Documents select a registered name and cannot provide CSS, stylesheet URLs or scripts. Theme CSS is trusted host code; the host reviews its scope and resource references.
51
+
52
+ An unknown name, duplicate selected name, invalid selected registration, unsupported protocol or missing mode produces a renderer warning and falls back to `default`. Core-only hosts can call `resolveLocalTheme(name, themes, range?, source?)` to obtain `{ name, diagnostics }`. Compilation parses declarations independently of host registrations.
53
+
54
+ ## Color schemes and instance scope
55
+
56
+ Both React components accept `themes` and `colorScheme`. The theme selects the visual design; the color scheme selects its light or dark version:
57
+
58
+ | Value | Behavior |
59
+ | --- | --- |
60
+ | `light` | Forces light mode for this document, including inside a dark host |
61
+ | `dark` | Forces dark mode for this document |
62
+ | `auto` (default) | Uses the nearest ancestor's explicit preference, then the system preference; server output starts in light mode |
63
+
64
+ Ancestor preferences support `data-color-scheme="light|dark"` and the existing `data-theme="light|dark"`. Ancestor attribute changes and system preference changes update the document in the browser. An explicit local `colorScheme` takes precedence.
65
+
66
+ The renderer exposes the resolved selection on its document root:
67
+
68
+ ```html
69
+ <article class="md-document local-document"
70
+ data-rmd-theme="paper"
71
+ data-color-scheme="dark">
72
+ ```
73
+
74
+ Each instance chooses independently. Every theme rule must be scoped to its named root or descendants, for example `[data-rmd-theme="paper"][data-color-scheme="dark"]`. Global `body`, `:root` and unscoped element rules must not affect the host.
75
+
76
+ Changing `themes` or `colorScheme` does not create a runtime. Changing `LocalReactiveDocument.source` retains its existing behavior: recompilation and a new runtime. Hosts that retain parameters across source changes can manage `LocalDocumentView` and its runtime themselves.
77
+
78
+ ## Shared style variables
79
+
80
+ Shared component CSS supplies structure, interaction and defaults. Custom themes inherit a complete default variable set and override the values they need. Both light and dark variants must be designed and checked.
81
+
82
+ | Purpose | Public variables |
83
+ | --- | --- |
84
+ | Surfaces | `--paper`, `--surface`, `--document-bg` (defaults to `--surface`), `--surface-subtle`, `--surface-hover`, `--surface-active` |
85
+ | Text and borders | `--ink`, `--ink-soft`, `--ink-muted`, `--line`, `--line-strong` |
86
+ | Accent | `--accent`, `--accent-hover`, `--accent-soft`, `--accent-line` |
87
+ | Status | `--info`, `--info-soft`, `--success`, `--success-soft`, `--success-line`, `--warning`, `--warning-soft`, `--warning-line`, `--danger`, `--danger-soft`, `--danger-line`, `--neutral-soft` |
88
+ | Focus | `--focus`, `--focus-outline`, `--focus-ring` |
89
+ | Data and code | `--chart-1` through `--chart-8`, `--chart-grid`, `--chart-axis`, `--code-bg`, `--code-bg-deep`, `--code-ink` |
90
+ | Fonts | `--font-sans`, `--font-mono`, `--text-xs` through `--text-xl`, `--text-2xl`, `--text-block-title`, `--text-block-subtitle` |
91
+ | Line height and weight | `--leading-tight`, `--leading-snug`, `--leading-normal`, `--leading-relaxed`, `--weight-regular`, `--weight-medium`, `--weight-semibold`, `--weight-bold` |
92
+ | Spacing | `--space-1` through `--space-7`, `--field-gap` |
93
+ | Radius | `--radius-control`, `--radius-card`, `--radius-panel`, `--radius-pill` |
94
+ | Controls | `--control-height-sm`, `--control-height`, `--control-height-lg`, `--control-padding-x`, `--control-padding-y`, `--disabled-opacity` |
95
+ | Motion and elevation | `--motion-fast`, `--motion-base`, `--motion-slow`, `--ease-standard`, `--shadow-sm`, `--shadow-md` |
96
+
97
+ Existing `--blue`, `--blue-deep`, `--blue-soft` and `--blue-line` remain compatible. New themes should use the accent variables. Explicit component `color` attributes override their corresponding local color; other properties continue to use the theme. Series and status colors retain their semantic roles.
98
+
99
+ ## Component CSS and acceptance
100
+
101
+ Themes can supplement variable overrides with existing `.md-*` and `.local-*` component classes. Root classes, component outer classes and semantic state attributes are styling interfaces; internal node ordering is not an extension API. Load scoped theme rules after the shared stylesheet, using sufficiently specific root and component selectors instead of relying on `!important`.
102
+
103
+ Coverage includes Markdown, tables, formulas, controls, containers, feedback, charts and diagrams. New components must consume shared variables and work with `default`. Themes without dedicated rules for a new component inherit its shared styles.
104
+
105
+ A conforming theme must check every component in both modes, including hover, focus, active, disabled, error and selection states. Preserve visible keyboard focus, readable text and controls, a usable 375px layout and reduced-motion preferences. Font changes require checking SVG diagram labels, nodes and bounds.
106
+
107
+ Registration validates protocol and declared modes. Browser acceptance verifies CSS coverage, contrast and layout. Include multiple isolated themes, forced light inside a dark host, system preference changes, retained interaction state and unmount cleanup.
@@ -1,51 +1,53 @@
1
- # 语言验收数据
1
+ # Language conformance data
2
2
 
3
- [local-draft-1.json](local-draft-1.json) 是可复制的最小语义验收集,包含源码、编译结果、初始参数、状态写入和预期文本。数据随 npm 包分发,其他工具或实现可以读取同一份 JSON。
3
+ [local-draft-2.json](local-draft-2.json) is a copyable minimal semantic conformance suite containing source documents, compilation results, initial parameters, state writes and expected text. The data is distributed with the npm package so other tools or implementations can read the same JSON.
4
4
 
5
- - `syntaxVersion` 对应核心导出的 `LOCAL_SYNTAX_VERSION`。
6
- - `ok` 是预期编译结果;`codes` 是去重后的预期诊断码集合,省略时应无诊断。编译成功时也可能包含降级警告。
7
- - `initial` 检查公开参数的初值;`bindingNames` 在出现时检查完整绑定名集合。
8
- - `actions` 按 `bind` 查找控件并提交 `value`;有 `codes` 时预期写入被拒绝,否则预期成功。
9
- - `text` 用更新后的状态求值,结果应等于 `expectedText`。
5
+ - `syntaxVersion` matches the core export `LOCAL_SYNTAX_VERSION`.
6
+ - `ok` is the expected compilation result; `codes` is the deduplicated set of expected diagnostic codes, and when omitted no diagnostics are expected. A successful compile can still contain degradation warnings.
7
+ - `initial` checks the initial values of public parameters; `bindingNames`, when present, checks the complete set of binding names.
8
+ - `actions` finds controls by `bind` and submits `value`; when `codes` is present the write is expected to be rejected, otherwise it is expected to succeed.
9
+ - `text` is evaluated with the updated state and the result should equal `expectedText`.
10
10
 
11
- 运行器见仓库中的 `tests/conformance.test.ts`,执行 `npm test` 即可检查。本集覆盖共享参数、隐藏初始化、写入约束、代码隔离和诊断;完整语法验收还包含其他语言测试及浏览器检查,规则见[语法规范](../../docs/local-interaction-syntax.md)。诊断码的跨版本约定见[兼容说明](../../docs/compatibility.md)。
11
+ The runner lives at `tests/conformance.test.ts` in the repository; run `npm test` to check it. This suite covers shared parameters, hidden initialization, write constraints, code isolation, diagnostics, multi-slot controls, multiple selection, generated-table selection and a computed-value aggregate recalculation. It does not cover validation hints, generated table rendering, HTML export, author tooling or browser behavior; those have dedicated tests and the release gate. Full syntax conformance also includes other language tests and browser checks, with rules in the [syntax specification](../../docs/local-interaction-syntax-en.md). See the [compatibility notes](../../docs/compatibility-en.md) for cross-version guarantees on diagnostic codes.
12
12
 
13
- ## 组块协议验收
13
+ The conformance sources are unversioned and use the current `local-draft-2` revision. The optional prologue version declaration is compile metadata and does not change these semantic cases. Version rejection and migration behavior have dedicated tests and historical fixtures. See [Source revisions and migration](../../docs/source-versioning-en.md).
14
14
 
15
- [component-protocol-1.json](component-protocol-1.json) 为[组块协议](../../docs/component-protocol.md)提供代表性用例,覆盖 `slider`、`tabs`、`plot` 以及未知组块的惰性降级。[JSON Schema](component-protocol-1.schema.json) 定义验收文件格式,可供其他实现的工具读取。这个 JSON 是测试输入和预期结果,组件提案的声明模板见[开发指南](../../docs/component-development.md)。
15
+ ## Component protocol conformance
16
+
17
+ [component-protocol-1.json](component-protocol-1.json) provides representative cases for the [component protocol](../../docs/component-protocol-en.md), covering `slider`, `tabs`, `plot` and lazy degradation of unknown components. The [JSON Schema](component-protocol-1.schema.json) defines the conformance file format so tools from other implementations can read it. This JSON is test input and expected results; see the [development guide](../../docs/component-development-en.md) for the declaration template of a component proposal.
16
18
 
17
19
  ```sh
18
20
  npm run test:components
19
21
  ```
20
22
 
21
- 该命令运行组块协议用例和原有语言验收数据。新增组块应补充自己的用例、单元测试和受影响的渲染器检查;通过本集合只证明这些具体用例通过。
23
+ That command runs the component protocol cases and the existing language conformance data. A new component should add its own cases, unit tests and affected renderer checks; passing this suite only proves these specific cases pass.
22
24
 
23
- ### 文件与用例字段
25
+ ### File and case fields
24
26
 
25
- 文件根对象包含 `protocolVersion`、`syntaxVersion` 和非空的 `cases`。当前分别为 `component-protocol-1` 和 `local-draft-1`。包版本另由 `package.json` 标识,不由这两个字段推断。
27
+ The file root object contains `protocolVersion`, `syntaxVersion` and a non-empty `cases` array. Currently these are `component-protocol-1` and `local-draft-2`. The package version is identified separately by `package.json` and is not inferred from these two fields.
26
28
 
27
- | 字段 | 规则 |
29
+ | Field | Rule |
28
30
  | --- | --- |
29
- | `id` | 必填,在文件内唯一;描述一个可观察的行为 |
30
- | `component` | 必填,标明主要验收的组块;源码可同时使用其他组块 |
31
- | `source` | 必填,原始文档源码 |
32
- | `ok` | 必填,预期编译是否成功 |
33
- | `codes` | 必填,编译诊断码的去重集合;无诊断时为 `[]`,忽略顺序、精确比较集合 |
34
- | `initial` | 可选,编译成功后的初始状态期望,按给定键部分匹配 |
35
- | `bindingNames` | 可选,完整公开绑定名集合;不包含匿名组块的内部状态键 |
36
- | `actions` | 可选,依次写入命名绑定;每项必填 `bind`、`value`、`codes`,可选 `expectedState` |
37
- | `reset` | 可选,写入完成后重置指定节点;必填 `component` 和 `expectedState`,`index` 默认为同名组件源码顺序中的第 0 个 |
38
- | `text`、`expectedText` | 可选,必须成对;在写入和重置后求值并精确比较结果 |
39
- | `htmlIncludes`、`htmlExcludes` | 可选,在最终状态做 React 静态渲染,逐项检查包含或不包含的片段 |
31
+ | `id` | Required, unique within the file; describes one observable behavior |
32
+ | `component` | Required, names the component primarily under test; the source may use other components too |
33
+ | `source` | Required, the original document source |
34
+ | `ok` | Required, whether compilation is expected to succeed |
35
+ | `codes` | Required, the deduplicated set of compilation diagnostic codes; `[]` when there are none, order ignored, the set compared exactly |
36
+ | `initial` | Optional, initial state expectations after successful compilation, partially matched by the given keys |
37
+ | `bindingNames` | Optional, the complete set of public binding names; excludes internal state keys of anonymous components |
38
+ | `actions` | Optional, writes to named bindings in order; each entry requires `bind`, `value`, `codes` and may include `expectedState` |
39
+ | `reset` | Optional, resets the named node after the writes; requires `component` and `expectedState`, `index` defaults to the 0th in source order among components with that name |
40
+ | `text`, `expectedText` | Optional, must be paired; evaluated after writes and reset with the result compared exactly |
41
+ | `htmlIncludes`, `htmlExcludes` | Optional, performs React static rendering in the final state and checks each listed fragment is present or absent |
40
42
 
41
- `initial`、`expectedState` 的值使用语言现有的 `LocalValue`:字符串、有限数字、布尔值、`null` 或字符串数组。`actions[].codes` 是该次写入返回的诊断码集合,无诊断仍须写 `[]`;被拒绝的写入应保留上一次合法状态。运行器通过 `bind` 查找已编译的控件,调用 `runtime.set`,不模拟浏览器输入事件。
43
+ `initial` and `expectedState` values use the language's existing `LocalValue`: a string, finite number, boolean, `null` or string array. Public writable controls do not produce numeric arrays; numeric arrays are available to expressions and computed values. `actions[].codes` is the set of diagnostic codes returned by that write; still write `[]` when there are none. A rejected write should keep the last valid state. The runner finds compiled controls by `bind` and calls `runtime.set`; it does not simulate browser input events.
42
44
 
43
- 执行顺序固定为:校验数据格式及唯一 ID,编译并比较诊断,检查初始状态及公开绑定名,依序写入,再重置,最后检查文本和可选渲染结果。创建的运行时均在结束时销毁。`ok: false` 的用例只允许编译期字段,不能附加状态、动作或渲染期望;未知字段、缺失字段和不合法值应当让验收失败。
45
+ Execution order is fixed: validate the data format and unique IDs, compile and compare diagnostics, check the initial state and public binding names, perform writes in order, then reset, and finally check text and optional rendering results. Every created runtime is disposed at the end. Cases with `ok: false` may only use compile-time fields and cannot add state, action or rendering expectations; unknown fields, missing fields and invalid values should fail conformance.
44
46
 
45
- `reset` 调用当前实例的 `runtime.reset(node)`,节点按组块名和索引查找;验收文件不保存 `node.id`。这项检查验证运行时重置语义,点击重置按钮仍需渲染器或浏览器检查。
47
+ `reset` calls `runtime.reset(node)` on the current instance; nodes are found by component name and index, and the conformance file does not store `node.id`. This check verifies runtime reset semantics; clicking a reset button still needs a renderer or browser check.
46
48
 
47
- ### 可移植范围
49
+ ### Portable scope
48
50
 
49
- 编译结果、诊断集合、状态变化和表达式文本是可移植的语义期望。HTML 片段只检查本仓库的 React 参考渲染器;其他渲染器应验证同等用户行为,无需生成相同 DOM 或 CSS 类名。
51
+ Compilation results, diagnostic sets, state changes and expression text are portable semantic expectations. HTML fragments only check this repository's React reference renderer; other renderers should verify equivalent user behavior and need not generate the same DOM or CSS class names.
50
52
 
51
- 这些用例不会证明真实键盘操作、焦点移动、中文输入法、375px 布局、计时器暂停或销毁后的计时清理。涉及这些行为的贡献仍需提交相应浏览器证据,检查方法见[开发指南](../../docs/component-development.md)。诊断码的跨版本稳定性继续遵守[兼容说明](../../docs/compatibility.md)。
53
+ These cases do not prove real keyboard operation, focus movement, Chinese input methods, 375px layout, timer pause, or timer cleanup after disposal. Contributions involving those behaviors still need corresponding browser evidence; see the [development guide](../../docs/component-development-en.md) for verification methods. Cross-version stability of diagnostic codes continues to follow the [compatibility notes](../../docs/compatibility-en.md).