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,207 @@
1
+ # Shareable documents and static export
2
+
3
+ This guide covers the single-file HTML exporter introduced with `local-draft-2`. It complements [Local mode integration](local-integration-en.md), the [syntax reference](local-interaction-syntax-en.md), [Source revisions and migration](source-versioning-en.md) and the [0.4.0 release notes](release-0.4.0-en.md).
4
+
5
+ ## Output modes
6
+
7
+ **Interactive HTML** is one self-contained `.html` file. It embeds the original source, the standalone browser runtime, React 19, the current stylesheet and print styles. Readers can open it through `file://` without Node.js, React, the reactive-md package or network access.
8
+
9
+ The first rendered pass is static. After the embedded runtime hydrates it, controls become interactive. With JavaScript disabled the same static values, tables, formulas and charts remain readable. Refreshing restores the exported baseline; the reader's changes are not persisted.
10
+
11
+ **Static HTML** (`--mode static`) contains read-only values and no executable script cargo. It is intended for archives, static sites and email attachments. Interactive action buttons, form widgets and the reset action are removed.
12
+
13
+ Both modes use the same renderer as the React integration, so conditional content, interpolation, tables, formulas, charts and layout follow the runtime state.
14
+
15
+ ## CLI
16
+
17
+ The package exposes the `reactive-md` command. HTML builds require React 19 and React DOM in the project that installs the package; `lint` and `migrate` do not.
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
+ Build options:
29
+
30
+ | Option | Meaning |
31
+ | --- | --- |
32
+ | `-o, --output <file>` | Required output path. Its parent directory must already exist. |
33
+ | `--mode interactive\|static` | Output mode. Default: `interactive`. |
34
+ | `--state-file <json>` | Use a validated `reactive-md-state/v1` file as the starting and reset baseline. |
35
+ | `--assets inline\|omit` | Inline verified local raster images (default) or leave the renderer's alt fallback. |
36
+ | `--asset-root <dir>` | Additional local directory that relative image paths may resolve inside. |
37
+ | `--locale en\|zh` | Renderer labels and validation messages. Default: `en`. |
38
+ | `--color-scheme auto\|light\|dark` | Document color mode. Default: `auto`. |
39
+ | `--title <text>` | Override the HTML title. The first heading or the input filename is used otherwise. |
40
+ | `--strict` | Fail on compiler warnings; with `--assets omit`, fail when images are omitted. |
41
+
42
+ Exit codes are separate so build automation can distinguish failures:
43
+
44
+ | Code | Meaning |
45
+ | --- | --- |
46
+ | `0` | Success |
47
+ | `2` | Usage or argument error |
48
+ | `3` | Document compile, render, React, or packaged-artifact failure |
49
+ | `4` | Input/output file failure |
50
+ | `5` | Asset or security-policy failure |
51
+
52
+ The CLI does not use a current preview implicitly. `--state-file` is the only way to select a non-initial baseline. `format` is not part of this release.
53
+
54
+ ## Migrating source
55
+
56
+ `reactive-md migrate` moves one source revision declaration to `local-draft-2`:
57
+
58
+ ```sh
59
+ reactive-md migrate old.reactive.md --from local-draft-1 -o new.reactive.md
60
+ reactive-md migrate old.reactive.md --check --json
61
+ ```
62
+
63
+ By default it prints the migrated source to standard output. `-o` creates a new file with exclusive creation and refuses any existing path, including the input. `--check` never writes. `--json` prints a structured report and nothing else. `--accept-semantic-changes` allows the text-control length change and reports warnings; `--locale en|zh` selects the display language.
64
+
65
+ A migration exits `1` when blocked and `0` on success. `--check` exits `1` when changes are needed or blocked, and `0` when the source is current. Usage and I/O errors exit `2`. The command does not overwrite in place and has no batch or `--write` mode. See [Source revisions and migration](source-versioning-en.md) for the checks, preserved bytes and state-digest consequences.
66
+
67
+ ## Starting values and state files
68
+
69
+ By default, the exported baseline is the document's author initial values. This keeps builds repeatable and avoids leaking trial inputs.
70
+
71
+ A state file has this versioned shape:
72
+
73
+ ```json
74
+ {
75
+ "format": "reactive-md-state/v1",
76
+ "syntax": "local-draft-2",
77
+ "sourceDigest": "fnv1a32:0123abcd",
78
+ "parameters": {
79
+ "people": 7,
80
+ "plan": "pro"
81
+ },
82
+ "generator": { "name": "example-host", "version": "1.0.0" }
83
+ }
84
+ ```
85
+
86
+ Only public, serializable binding values are stored. The file identifies the document through `sourceDigest` and the language revision through `syntax`. Internal bindings (names beginning with `@`), revisions, node IDs, AST data, timers, open panels and focus are never persisted; internal snapshot keys and IDs are implementation details, not a storage format.
87
+
88
+ Resolution verifies the source digest, syntax revision, exact public parameter set and every value against the document's constraints. Unknown, missing or invalid parameters reject the file with a named diagnostic; a mismatched file is never partially applied. Slot controls such as `<range-slider>` are validated atomically.
89
+
90
+ The selected state becomes the document's reset baseline. Opening, refreshing and the panel reset action therefore return to the exported values, not to a different hidden default.
91
+
92
+ Hosts can create and apply the same file without the CLI:
93
+
94
+ ```ts
95
+ import { exportLocalState, importLocalState } from 'reactive-md';
96
+
97
+ const file = exportLocalState(runtime, { name: 'example-host', version: '1.0.0' });
98
+ const saved = JSON.stringify(file);
99
+
100
+ const diagnostics = importLocalState(runtime, saved);
101
+ ```
102
+
103
+ `exportLocalState` reads public parameters only. `importLocalState` validates the source digest, syntax, parameter set and constraints, then applies the values; a failed import leaves the runtime unchanged. Both are explicit host calls: the runtime still does not save or send state by itself. Use `resolveLocalState(document, input)` to validate without touching a live runtime.
104
+
105
+ The demo's export dialog can download the current preview parameters as a state file for a later CLI build. The lower-level `createLocalStateFile`, `parseLocalState`, `applyLocalState` and `serializeLocalState` remain available from `reactive-md`.
106
+
107
+ ## Images
108
+
109
+ Offline export defaults to `--assets inline`:
110
+
111
+ - Only relative paths that resolve inside the document directory, or an explicit `--asset-root`, are read.
112
+ - Absolute paths, URL schemes, protocol-relative URLs, backslashes, path traversal and symlink escapes are rejected.
113
+ - Remote images are never fetched.
114
+ - PNG, JPEG, GIF and WebP are detected by file contents; SVG, forged MIME types and unknown formats are rejected.
115
+ - Files are limited to 8 MiB each, 24 MiB total and 64 distinct payloads. Identical content is deduplicated.
116
+ - Alt text is preserved. A failure stops the build by default. `--assets omit` is the explicit opt-out and leaves the alt fallback.
117
+
118
+ The renderer's global security boundary is unchanged: images are still rejected by default unless a host URL policy explicitly allows them. The exporter supplies a host policy and image resolver after it has verified each local file.
119
+
120
+ ## Single-file security and printing
121
+
122
+ The HTML shell includes:
123
+
124
+ - a CSP that disallows connections, frames, objects, base URL changes and form submission while allowing the inline stylesheet/runtime and `data:` images;
125
+ - HTML- and script-context escaping for JSON, source, titles and license notices;
126
+ - the MIT and third-party notices in a non-executed `<template>`;
127
+ - no CDN or remote stylesheet, font or runtime.
128
+
129
+ Clicking an ordinary external link can still navigate, but opening the document itself performs no remote request. The exporter is not a sandbox for fully untrusted authors; use a sandboxed iframe when that threat model applies.
130
+
131
+ Printing does not require a temporary state switch. The current runtime values are rendered in print-only nodes, so `Ctrl+P` prints the state the reader currently sees. Print CSS forces a light paper theme, hides toolbars and controls, uses printer-owned page margins, keeps headings with following content, repeats table headers, wraps long code and URLs, and constrains charts to page width. Static HTML already contains only read-only values.
132
+
133
+ ## Standalone runtime API
134
+
135
+ The build emits `dist-standalone/reactive-md-standalone.js` (IIFE, global `ReactiveMD`) and `reactive-md-standalone.css`. Load the stylesheet and script as classic browser assets:
136
+
137
+ ```html
138
+ <link rel="stylesheet" href="reactive-md-standalone.css">
139
+ <script src="reactive-md-standalone.js"></script>
140
+ ```
141
+
142
+ Programmatic mounting:
143
+
144
+ ```js
145
+ const handle = ReactiveMD.mount(document.getElementById('doc'), {
146
+ source: '# Hello\n\n<slider bind="n" label="Count" initial="2">\n\nValue: {{ n }}',
147
+ locale: 'en',
148
+ colorScheme: 'auto',
149
+ });
150
+ handle.getState(); // reactive-md-state/v1 snapshot
151
+ handle.unmount();
152
+ ```
153
+
154
+ `ReactiveMD.mountAll(root)` scans only once for safe auto-mount payloads:
155
+
156
+ ```html
157
+ <div id="doc"></div>
158
+ <script type="application/reactive-md+json" data-reactive-md-auto>
159
+ {"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}
160
+ </script>
161
+ ```
162
+
163
+ Targets are resolved by `id`, never by an interpolated selector. Payload source is data, not executable markup. Raw `<script type="text/reactive-md">` text is deliberately not interpreted.
164
+
165
+ ### `<reactive-md-doc>`
166
+
167
+ The IIFE registers a light-DOM custom element. Simple options are attributes; complex options are DOM properties.
168
+
169
+ ```html
170
+ <reactive-md-doc src="./doc.reactive.md" locale="en" color-scheme="auto"></reactive-md-doc>
171
+ ```
172
+
173
+ - Attributes: `src`, `source`, `locale`, `color-scheme`, `theme`.
174
+ - Properties: `source`, `state`, `urlPolicy`, `imageResolver`, `themes`.
175
+ - Events: `reactive-md-diagnostics` and `reactive-md-state-change`.
176
+ - `src` uses `fetch` with cancellation; an explicit source avoids network access.
177
+ - Disconnecting aborts fetches, removes subscriptions and the React root, and disposes the runtime. Two elements with the same source have independent state.
178
+
179
+ The element uses Light DOM so the existing document CSS, heading anchors and print styles apply. Shadow DOM is intentionally out of scope for this release.
180
+
181
+ ## Security boundaries
182
+
183
+ - Core and React entry points keep React external. Only the standalone IIFE bundles React.
184
+ - The core entry remains React-free.
185
+ - State export and import use only public binding names and validated values.
186
+ - Exported HTML does not persist a reader's changes.
187
+ - The demo preview still blocks images unless a host policy is supplied; the demo export dialog disables HTML export when a document contains images because it has no asset root. Use the CLI for image-bearing documents.
188
+ - The export format version is `reactive-md-html/v1`; inspect it in the generated meta tags.
189
+
190
+ ## Bundle baseline
191
+
192
+ `npm run test:shareable` records the standalone artifact size and fails above these regression alarms:
193
+
194
+ | Artifact | Current baseline | Alarm |
195
+ | --- | --- | --- |
196
+ | `reactive-md-standalone.js` | ≈625.5 kB (≈186 kB gzip) | 800 KiB / 240 KiB gzip |
197
+ | `reactive-md-standalone.css` | ≈59.7 kB (≈10.1 kB gzip) | 80 KiB / 20 KiB gzip |
198
+
199
+ Sizes vary slightly with the minifier and React patch release. The alarm is intentionally well above normal noise while catching a React or renderer duplication regression. The full generated HTML also contains the source, notices and inline images, so it is larger than this baseline.
200
+
201
+ ## Current scope
202
+
203
+ Included: CLI `build`/`lint`/`migrate`, interactive and static HTML, state files, local raster inlining, print output, standalone mount APIs, auto-mount, and the Web Component.
204
+
205
+ Not included in this release: `format`, UMD, remote image fetching, SVG inlining, framework plugins (Vite, Astro, Docusaurus, Next.js), Shadow DOM, and general SSR hydration guarantees outside the single-file export path.
206
+
207
+ Single-file static-first hydration is covered by the Playwright Chromium checks and local Edge checks. Firefox, Safari/WebKit and general server-side hydration remain unverified and are not claimed as supported.
@@ -0,0 +1,159 @@
1
+ # 源码修订与迁移
2
+
3
+ 本文说明 `0.4.0` 中的显式源码修订、编译器的处理方式,以及纯核心 API 与 CLI 迁移工具。语法规则见[语法规范](local-interaction-syntax-ch.md),包版本与 API 兼容规则见[版本与兼容性](compatibility-ch.md),组块升级清单见[0.4.0 发布与迁移](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.4.0` 是 `next` 渠道的预览版。本页说明其中的迁移工具。
@@ -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 的实际覆盖、对比度和布局通过浏览器验收。验收应包含同页多主题隔离、显式浅色置于深色宿主、系统切换、状态保留和卸载清理。