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,363 @@
1
+ # Local mode integration
2
+
3
+ Local interaction mode uses HTML-style tags, in-place parameters and `{{ expressions }}`. Author rules are in the [beginner guide](local-guide-en.md) and the [syntax specification](local-interaction-syntax-en.md); complete documents are in the [example index](../examples/local/README.md). Hosts explicitly select this mode through the `Local` APIs. See [Source revisions and migration](source-versioning-en.md) for the optional revision directive, upgrade checks and `migrateLocalSource`, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist.
4
+
5
+ ## Runtime and entries
6
+
7
+ | Entry | Contents | Dependency |
8
+ | --- | --- | --- |
9
+ | `reactive-md` | `compileLocal`, `createLocalRuntime`, expression and math utilities | No React dependency |
10
+ | `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` | React 19 |
11
+ | `reactive-md/styles.css` | Component, theme and document styles | Explicitly imported by the host |
12
+
13
+ The package ships ESM only. Node.js 22.12+ can be used for development and Node-side compilation and runtime. Local browser checks use Edge; static SSR is covered by the packed check; see [Versions and compatibility](compatibility-en.md) for the full matrix. Copyable projects are in [Standalone integration examples](../examples/integration/README.md). For single-file HTML, state files and the standalone browser runtime, see [Shareable documents and static export](shareable-export-en.md).
14
+
15
+ ## React
16
+
17
+ Install React in a host that already has Reactive MD; when using TypeScript, also install the matching type packages:
18
+
19
+ ```sh
20
+ npm install react@19 react-dom@19
21
+ npm install --save-dev @types/react@19 @types/react-dom@19
22
+ ```
23
+
24
+ ```tsx
25
+ import { LocalReactiveDocument } from 'reactive-md/react';
26
+ import 'reactive-md/styles.css';
27
+
28
+ const source = `# Cost estimate
29
+
30
+ <panel title="Adjust the plan">
31
+ <slider bind="people" label="People" initial="2" min="1" max="20">
32
+ <toggle bind="annual" label="Annual billing">
33
+ </panel>
34
+
35
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
36
+
37
+ export function Article() {
38
+ return <LocalReactiveDocument source={source} />;
39
+ }
40
+ ```
41
+
42
+ | Prop | Type | Component | Notes |
43
+ | --- | --- | --- | --- |
44
+ | `source` | `string` | `LocalReactiveDocument` | Recompiles and creates a new runtime when the source changes; old instance state is not kept. See [Keeping values when source changes](#keeping-values-when-source-changes) |
45
+ | `document` | `LocalDocument` | `LocalDocumentView` | Compiled document; compiled once by the host |
46
+ | `runtime` | `LocalRuntime` | `LocalDocumentView` | Created by the host, which is responsible for disposal |
47
+ | `onDiagnostics` | `(diagnostics: Diagnostic[]) => void` | Both | Receives compile diagnostics and runtime diagnostics when control writes are rejected |
48
+ | `urlPolicy` | `(url: string, kind: 'image' \| 'link') => boolean` | Both | Decides whether to allow an image or link after protocol checks |
49
+ | `locale` | `'en' \| 'zh'` | Both | Language for built-in labels, controls and displayed diagnostics; defaults to `'en'`. Callbacks keep structured diagnostics |
50
+ | `themes` | `readonly LocalThemeDefinition[]` | Both | Host registrations; CSS loads separately; built-in `default` is always available |
51
+ | `colorScheme` | `'light' \| 'dark' \| 'auto'` | Both | Defaults to `auto`, following the nearest explicit ancestor preference or the system |
52
+
53
+ Neither component has `className`, `style` or slot props. `LocalReactiveDocument` renders `<article class="md-document local-document">`; `LocalDocumentView` uses the same document container. See below for style overrides.
54
+
55
+ Each component instance manages in-memory state independently. Changing the source recompiles and starts from initial values; disposing an instance clears subscriptions and timers. To carry values across a source change, use the retention helpers or manage the runtime yourself; see [Keeping values when source changes](#keeping-values-when-source-changes). A panel reset in the document restores its internal parameters, input drafts and component state, and displays of same-name parameters outside the panel update as well.
56
+
57
+ When a host React root shares a page with the standalone IIFE, give the host root a distinct `identifierPrefix`, for example `createRoot(container, { identifierPrefix: 'host-' })`. The bundles own separate React instances, so their default `useId` counters can overlap. Independent server-rendered roots need matching unique prefixes on the server and client too.
58
+
59
+ When compilation fails, the component renders a disabled notice and the diagnostics list, and `onDiagnostics` also receives the diagnostics. Local computation errors during runtime are displayed near the corresponding content while the rest keeps updating.
60
+
61
+ ### Headings and table-of-contents links
62
+
63
+ Documents can use Markdown table-of-contents links directly, for example `[Parameter description](#parameter-description)` targeting `## Parameter description`. The renderer generates anchors from heading text, appends `-1`, `-2` and so on to duplicate headings, and handles collisions with existing heading names. Emphasis and inline code in headings participate in naming as text; both Chinese and percent-encoded fragment links work.
64
+
65
+ Each document instance has its own anchor prefix, and matching table-of-contents links target the current instance. The same page can embed multiple copies of the same source. Links still go through protocol checks and the host `urlPolicy` first; the policy receives the raw address written by the author.
66
+
67
+ Anchors for dynamic headings are computed from source initial values, and parameter changes only update the displayed heading text. Rendered DOM IDs belong to the current mounted instance; when saving a table of contents, keep the fragment links from the source.
68
+
69
+ ## Core API
70
+
71
+ ```ts
72
+ import { compileLocal, createLocalRuntime } from 'reactive-md';
73
+
74
+ const result = compileLocal(source);
75
+ if (result.ok) {
76
+ const runtime = createLocalRuntime(result.document);
77
+ const unsubscribe = runtime.subscribe(() => {
78
+ console.log(runtime.snapshot());
79
+ });
80
+
81
+ console.log(runtime.evaluate('people * 100'));
82
+ console.log(runtime.text('People: {{ people }}'));
83
+
84
+ unsubscribe();
85
+ runtime.dispose();
86
+ } else {
87
+ console.log(result.diagnostics);
88
+ }
89
+ ```
90
+
91
+ ### `compileLocal(source: string, options?: LocalCompileOptions)`
92
+
93
+ `source` is the `.reactive.md` source. The return value is a union:
94
+
95
+ - Success: `{ ok: true; document: LocalDocument; diagnostics: Diagnostic[] }`
96
+ - Failure: `{ ok: false; diagnostics: Diagnostic[] }`
97
+
98
+ Syntax problems are returned through diagnostics; the current build accepts only `local-draft-2`. An explicit older revision directive is rejected with a `local.version.*` diagnostic; an unversioned source keeps current-revision behavior. The source limit is 1,000,000 characters. `document` is a current runtime object and should not be treated as a persistence format.
99
+
100
+ Hosts can set the syntax node budget for a single compilation:
101
+
102
+ ```ts
103
+ import { compileLocal, type LocalCompileOptions } from 'reactive-md';
104
+
105
+ const options: LocalCompileOptions = {
106
+ limits: { maxSyntaxNodes: 50_000 },
107
+ };
108
+ const result = compileLocal(source, options);
109
+ ```
110
+
111
+ `limits.maxSyntaxNodes` defaults to 10,000 and accepts integers from `1` to `Number.MAX_SAFE_INTEGER`. Omitting the options, `limits` or `maxSyntaxNodes` uses the default. `0`, negative numbers, decimals, `NaN`, infinity, strings, `null` and malformed option containers return a `local.options.invalid` diagnostic; exceeding the valid node budget returns a `local.budget` diagnostic.
112
+
113
+ The budget counts `LocalNode` instances created cumulatively during parsing, including Markdown text, paragraphs, lists, tables, interpolations, components and some intermediate nodes, so it may exceed the final syntax tree node count. The setting affects only this compilation, leaves the options object untouched, and keeps other resource limits such as arrays independent. The budget comes from the host; document content cannot raise it on its own.
114
+
115
+ To use a custom budget in React, call `compileLocal` first and pass the compiled document and runtime to `LocalDocumentView`. `LocalReactiveDocument` and the Playground compilation thread use the default budget. After raising the node budget, hosts should measure memory and preview rendering time with their actual documents.
116
+
117
+ ### Version inspection and migration
118
+
119
+ Three pure functions inspect and migrate source without creating a runtime. They are exported from `reactive-md`:
120
+
121
+ ```ts
122
+ import {
123
+ checkLocalUpgrade,
124
+ inspectLocalSourceVersion,
125
+ migrateLocalSource,
126
+ } from 'reactive-md';
127
+
128
+ const info = inspectLocalSourceVersion(source);
129
+ const check = checkLocalUpgrade(source, { fromVersion: 'local-draft-1' });
130
+ const migrated = migrateLocalSource(source, { fromVersion: 'local-draft-1' });
131
+ ```
132
+
133
+ `inspectLocalSourceVersion` reports the declared and effective revision, whether this compiler supports it, the directive range and version diagnostics. `checkLocalUpgrade` reports `ok`, `fromVersion`, `toVersion`, `needsMigration` and diagnostics. `migrateLocalSource` adds `source`, `changed` and precise `edits`.
134
+
135
+ `LocalUpgradeOptions` supplies `fromVersion` and `allowSemanticChanges`. An unversioned historical document needs `fromVersion: 'local-draft-1'`. An explicit `fromVersion` that disagrees with the declaration is rejected. Only `local-draft-1` and `local-draft-2` are accepted migration sources.
136
+
137
+ Migration changes only the metadata directive, preserves body bytes, BOM and CRLF, and is idempotent. It blocks reserved bindings, newly recognized tags, compile errors and text-control length changes before producing output. See [Source revisions and migration](source-versioning-en.md) for the exact checks and the CLI.
138
+
139
+ ### `createLocalRuntime(document: LocalDocument)`
140
+
141
+ Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](computations-formatting-en.md).
142
+
143
+ Creates an independent in-memory runtime for a compiled document. Throws if `document` is not a local mode document, if initial values exceed budgets, or if the structure is invalid. Each instance has independent state; the runtime never stores or transmits state by itself.
144
+
145
+ ### `LocalRuntime`
146
+
147
+ `validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](constraints-collections-en.md).
148
+
149
+ | Member | Parameters | Returns | Behavior |
150
+ | --- | --- | --- | --- |
151
+ | `document` | — | `LocalDocument` | The compiled result used at creation |
152
+ | `snapshot()` | — | `{ revision: number; state: Readonly<Record<string, LocalValue>> }` | Returns the same snapshot object when state is unchanged; state is frozen |
153
+ | `get(node, slot?)` | `LocalNode`, optional slot | `LocalValue` | Reads the value bound to the control; `slot` selects `start`/`end` or `x`/`y`; returns `null` for no binding or an unknown node; arrays are copies |
154
+ | `set(node, value, slot?)` | `LocalNode`, `LocalValue`, optional slot | `Diagnostic[]` | Validates all shared controls; returns an empty array and commits once on success; does not increment revision on failure |
155
+ | `setMany(node, values)` | `LocalNode`, slot values | `Diagnostic[]` | Atomically writes several slots of one multi-slot control; invalid batches leave state and revision unchanged |
156
+ | `validate()` | — | `Diagnostic[]` | Returns copies of the current advisory validation failures; does not change or reject state |
157
+ | `parameterNames()` | — | `readonly string[]` | Sorted public binding names; internal `@` bindings excluded |
158
+ | `getParameter(name)` | `string` | `LocalValue \| undefined` | Value of a public binding; `undefined` for unknown or internal names; arrays are copies |
159
+ | `getParameters()` | — | `Readonly<Record<string, LocalValue>>` | Frozen public-only snapshot; internal `@` keys are never included |
160
+ | `setParameter(name, value)` | `string`, `LocalValue` | `Diagnostic[]` | Validates every control sharing the binding; commits once; state unchanged on failure |
161
+ | `setParameters(values)` | `Readonly<Record<string, LocalValue>>` | `Diagnostic[]` | Validates every public value and multi-slot relation, then commits all or nothing; unknown or internal names return `local.runtime.parameter`; invalid values return `local.runtime.value`; unchanged values do not bump the revision |
162
+ | `evaluate(expression)` | `string` | `LocalValue` | Evaluates with current state; throws `LocalExpressionError` on failure; arrays are copies |
163
+ | `text(template)` | `string` | `string` | Renders text containing `{{ }}`; throws on failure |
164
+ | `reset(node)` | `LocalNode` | `void` | Restores parameters and component state within the node's subtree in one commit, notifying once |
165
+ | `resetToken(node)` | `LocalNode` | `number` | Incrementing token for a control's internal state, so renderers can detect resets |
166
+ | `subscribe(listener)` | `() => void` | `() => void` | Calls the listener on every commit; returns an unsubscribe function |
167
+ | `dispose()` | — | `void` | Idempotent; clears subscriptions, expression caches and reset tokens; other members throw afterwards |
168
+
169
+ `set` relies on the controls registered in the document; node metadata passed by the caller cannot loosen constraints. `disabled` and conditional hiding are for interactive display only; the host still enforces business permissions and server-side data validation.
170
+
171
+ ### Parameters by name
172
+
173
+ Name-based access is for hosts that keep their own parameter values, such as a form or a URL. Only public bindings are visible: `parameterNames()` returns sorted names, `getParameter(name)` returns `undefined` for an unknown or internal name, and `getParameters()` returns a frozen public-only record. Anonymous `@` bindings never appear, and arrays returned by `getParameter` are copies.
174
+
175
+ Writes validate every control sharing the binding, including multi-slot relations, and commit once. A failed call returns diagnostics and leaves the state unchanged; unchanged values do not increase the revision. Unknown or internal names return `local.runtime.parameter`; invalid values return `local.runtime.value`.
176
+
177
+ ```ts
178
+ const names = runtime.parameterNames(); // e.g. ['annual', 'people']
179
+ const people = runtime.getParameter('people'); // 2
180
+
181
+ runtime.setParameter('people', 7);
182
+ const diagnostics = runtime.setParameters({ people: 8, annual: true });
183
+ if (diagnostics.length) {
184
+ // Nothing was written.
185
+ }
186
+ ```
187
+
188
+ ### State export and import
189
+
190
+ `exportLocalState(runtime, generator?)` writes the public parameters to a `reactive-md-state/v1` file. The file carries the document identity in `sourceDigest`, the language revision in `syntax`, and an optional generator name and version. Anonymous `@` bindings from `snapshot().state` are excluded, so a raw snapshot should not be stored as a long-term protocol. The [shareable export guide](shareable-export-en.md#starting-values-and-state-files) documents the format used by the CLI and standalone runtime.
191
+
192
+ `importLocalState(runtime, input, options?)` accepts serialized JSON or an already parsed file. It parses the payload, checks the source digest, syntax revision and exact public parameter set, validates every value, and applies the result; a failed import returns diagnostics and leaves the runtime unchanged. `options.maxLength` limits the serialized payload in bytes and defaults to 1 MiB.
193
+
194
+ ```ts
195
+ import { exportLocalState, importLocalState } from 'reactive-md';
196
+
197
+ const file = exportLocalState(runtime, { name: 'my-host', version: '1.0.0' });
198
+ const saved = JSON.stringify(file);
199
+
200
+ const diagnostics = importLocalState(runtime, saved);
201
+ ```
202
+
203
+ The lower-level `createLocalStateFile`, `parseLocalState`, `resolveLocalState`, `applyLocalState` and `serializeLocalState` remain available. Use `resolveLocalState(document, input)` for validation that does not touch a live runtime.
204
+
205
+ ### Keeping values when source changes
206
+
207
+ `LocalReactiveDocument` still creates a new runtime from initial values when `source` changes. Hosts that manage the runtime themselves can carry compatible values over:
208
+
209
+ ```ts
210
+ import {
211
+ applyLocalStateRetention,
212
+ compileLocal,
213
+ createLocalRuntime,
214
+ planLocalStateRetention,
215
+ } from 'reactive-md';
216
+
217
+ const next = compileLocal(nextSource);
218
+ if (!next.ok) throw new Error('Fix the compile diagnostics first');
219
+
220
+ const plan = planLocalStateRetention({
221
+ previous: previousRuntime.document,
222
+ state: previousRuntime.snapshot().state,
223
+ next: next.document,
224
+ });
225
+ const runtime = createLocalRuntime(next.document);
226
+ const { retained, dropped, diagnostics } = applyLocalStateRetention(runtime, plan);
227
+ ```
228
+
229
+ `planLocalStateRetention` returns the values to reuse, the retained parameter names, and dropped entries with a name and reason. A parameter is retained only when:
230
+
231
+ - its name exists as a public binding in both documents;
232
+ - both bindings are safely retainable: the binding has controls, every control is bound to the name, and no control is a timer or checklist;
233
+ - its type and initial definition are unchanged, including the effective initial value and any explicit `initial` attribute values.
234
+
235
+ Anonymous `@` bindings, removed or renamed parameters, timers and positional checklists are dropped. Each retained value is revalidated against the new document's constraints; a rejected value falls back to the new initial value and is reported as `invalid`. Drop reasons are `internal`, `unknown`, `unretainable`, `type`, `initial` and `invalid`.
236
+
237
+ `applyLocalStateRetention` first tries one atomic write so multi-slot relations stay consistent, then falls back to writing parameters individually, so one stale value does not block the others. `diagnostics` describe values rejected by the new document.
238
+
239
+ ### Background compilation in a Worker
240
+
241
+ Worker support is host-provided: create the worker entry with your bundler and keep `compileLocal` as the fallback. A copyable browser example is in [Standalone integration examples](../examples/integration/README.md).
242
+
243
+ ```ts
244
+ // compile.worker.ts
245
+ import { startLocalCompileWorker } from 'reactive-md';
246
+
247
+ startLocalCompileWorker();
248
+ ```
249
+
250
+ `startLocalCompileWorker()` installs the handler on the current worker global. Pass a scope explicitly only when testing or wrapping another message host.
251
+
252
+ ```ts
253
+ // main.ts
254
+ import { LocalCompileScheduler } from 'reactive-md';
255
+
256
+ const scheduler = new LocalCompileScheduler({
257
+ createWorker: () => new Worker(new URL('./compile.worker.ts', import.meta.url), { type: 'module' }),
258
+ onResult: ({ source, result, mode }) => render(source, result, mode),
259
+ onPendingChange: (pending) => showSpinner(pending),
260
+ onModeChange: (mode, detail) => console.log('compile mode', mode, detail),
261
+ });
262
+
263
+ scheduler.schedule(source);
264
+ ```
265
+
266
+ `LocalCompileScheduler` coalesces edits for `LOCAL_COMPILE_DELAY_MS` (150 ms; override with `delay`), keeps one compile in flight plus only the latest queued source, and discards results that a newer edit has superseded. When no worker is available, or after a worker error, it compiles on the main thread with `fallbackCompile`, which defaults to `compileLocal`; a worker failure switches permanently to this fallback and reports it through `onModeChange`. Failures thrown by the worker or during fallback compilation use the `local.worker.compile` diagnostic code.
267
+
268
+ `onResult` receives `LocalCompileOutcome` (`source`, `result`, `duration`, `mode`), `onPendingChange` reports whether work is queued or in flight, and `dispose()` stops the timer, terminates the worker and suppresses later callbacks.
269
+
270
+ ### Other core exports
271
+
272
+ - `LOCAL_SYNTAX_VERSION`: currently the literal `'local-draft-2'`. Use it to record the syntax revision a document uses.
273
+ - `compileExpression(source: string)`: returns an object with `source`, `dependencies`, `evaluate(env)` and `inferType(env)`; throws `LocalExpressionError` on failure.
274
+ - `LocalExpressionError`: contains `code` and `offset`.
275
+ - `compileLatex(source: string)`: returns an object with `source`, `dependencies` and `evaluate(x, env, budget?)`; throws an error with `code` and `offset` on failure.
276
+ - `samplePlot(expression, env, min, max, samples = 200, sharedBudget?)`: returns `{ points: { x: number; y: number | null }[]; endpoint: number | null }`; throws when the range, sample count or budget is invalid.
277
+ - State files: `exportLocalState`, `importLocalState`, `createLocalStateFile`, `parseLocalState`, `resolveLocalState`, `applyLocalState` and `serializeLocalState`; `LOCAL_STATE_FORMAT` is `'reactive-md-state/v1'`.
278
+ - Source revisions: `inspectLocalSourceVersion`, `checkLocalUpgrade` and `migrateLocalSource`; `LocalUpgradeOptions` configures the source revision and semantic-change allowance.
279
+ - Retention: `planLocalStateRetention` and `applyLocalStateRetention`.
280
+ - Background compilation: `LocalCompileScheduler`, `LOCAL_COMPILE_DELAY_MS` and `startLocalCompileWorker`.
281
+ - Type exports: `Diagnostic`, `SourceRange`, `LocalValue`, `LocalValueKind`, `LocalNode`, `LocalBinding`, `LocalComputation`, `LocalValidation`, `LocalDocument`, `LocalCompileLimits`, `LocalCompileOptions`, `LocalCompileResult`, `LocalUpgradeOptions`, `LocalRuntime`, `LocalSnapshot`, `LocalStateFile`, `LocalStateGenerator`, `LocalStateParseResult`, `LocalStateResolution`, `LocalRetainedState`, `LocalStateRetentionReason`, `LocalStateRetentionDrop`, `LocalStateRetentionInput`, `LocalStateRetentionResult`, `LocalCompileWorker`, `LocalCompileWorkerScope`, `LocalCompileRequest`, `LocalCompileResponse`, `LocalCompileOutcome`, `LocalCompileMode`, `LocalCompileSchedulerOptions`.
282
+
283
+ `compileExpression`, `compileLatex` and `samplePlot` are lower-level utilities with the same stability level as the core API; usually only `compileLocal` and `createLocalRuntime` are needed.
284
+
285
+ ## Diagnostics
286
+
287
+ The fields and stability levels of `Diagnostic` are described in the diagnostics contract in [Versions and compatibility](compatibility-en.md). Key points: `line`, `column` and `range` are for programmatic location; `code` can be used for coarse classification in the current version, but 0.x does not promise cross-version stability; `message` is display text and should not be parsed.
288
+
289
+ `onDiagnostics` receives compile diagnostics when the compilation result changes, and runtime diagnostics when control writes are rejected. Documents with compile errors do not activate interaction; runtime local errors replace only the corresponding content.
290
+
291
+ ## State, instances and cleanup
292
+
293
+ - `LocalReactiveDocument` recompiles and creates a runtime when `source` changes, cleaning up the old instance; React StrictMode is supported.
294
+ - When managing the lifecycle yourself, render with `<LocalDocumentView document={result.document} runtime={runtime} />` and call `runtime.dispose()` on unmount.
295
+ - `subscribe()` returns an unsubscribe function. `dispose()` clears remaining subscriptions; calling other runtime methods afterwards throws.
296
+ - `snapshot()` returns the same object until state changes, which is useful for external store subscriptions. `reset(panelNode)` commits once for the panel subtree, and subscribers receive one notification; hidden controls inside the panel are also within reset scope.
297
+ - Document state lives only in memory; the runtime never writes storage, cookies or the network. Refreshing, remounting or replacing the source starts from initial values. Persistence is an explicit host action through `exportLocalState` and `importLocalState`; the [retention helpers](#keeping-values-when-source-changes) can carry compatible values into a new runtime.
298
+ - Hidden regions keep parameters, tab selection and checklist state; timers in hidden regions pause and stay paused when shown again until the reader starts them. Disposing an instance releases timers and subscriptions.
299
+
300
+ ## Image and link policy
301
+
302
+ Images are not loaded by default, including relative-path images, so documents do not automatically request host APIs or external sites. Hosts can explicitly allow image sources through `urlPolicy`; both `LocalReactiveDocument` and `LocalDocumentView` accept this prop. Links keep safe protocol checks by default.
303
+
304
+ ```tsx
305
+ import type { LocalUrlPolicy } from 'reactive-md/react';
306
+
307
+ const urlPolicy: LocalUrlPolicy = (raw, kind) => {
308
+ if (kind === 'link') return true;
309
+ try {
310
+ const url = new URL(raw);
311
+ return url.protocol === 'https:' && url.origin === 'https://images.example.com';
312
+ } catch {
313
+ return false;
314
+ }
315
+ };
316
+
317
+ <LocalReactiveDocument source={source} urlPolicy={urlPolicy} />;
318
+ ```
319
+
320
+ | Target | Without a policy | With a policy |
321
+ | --- | --- | --- |
322
+ | Images | All rejected, including relative addresses | Protocol-bearing addresses are checked first and only HTTP(S) is allowed; relative addresses are decided by the policy |
323
+ | Links | Relative addresses and `http`, `https`, `mailto`, `tel` allowed | Decided by the policy after protocol checks; external HTTP(S) links get `_blank` and `noopener noreferrer` |
324
+
325
+ The policy receives the raw URL with leading and trailing whitespace removed, and `'image' | 'link'`. If the policy throws, the address is rejected. The renderer always checks the protocol first; even if the policy allows it, `javascript:` or dangerous `data:` addresses cannot be used. Images allowed to load use `referrerPolicy="no-referrer"`; same-origin requests may still carry cookies, so image allowlists should avoid business API paths.
326
+
327
+ `urlPolicy` controls only rendered links and images; it is not server-side authorization or a sandbox. Hosts still need to handle CSP, network egress and isolation policies for untrusted authors.
328
+
329
+ ## Theme and style scoping
330
+
331
+ `reactive-md/styles.css` is a global stylesheet, not isolated through Shadow DOM or CSS Modules. Hosts should import it explicitly once; the `reactive-md/react` library build extracts styles into this file and does not inject them automatically when importing JavaScript.
332
+
333
+ - Style selectors are mainly `.md-document`, `.local-document` and `.md-*`, `.local-*` class names. The document root rendered by components is `.md-document.local-document`.
334
+ - Theme variables are declared on `.md-document` and `.reactive-md-theme`, including `--ink`, `--surface`, `--line`, `--blue`, `--teal`, `--danger`, `--radius-*` and font variables. Override them after the library styles with rules such as `.my-article .md-document { --blue: #245c98; }`; the document root carries default values, so setting variables only on an ancestor container will not override same-name values on the root.
335
+ - Documents may start with `<theme name="default">`; omission selects `default`. Register custom themes through `themes`; see the [theme protocol](theme-protocol-en.md).
336
+ - `colorScheme` forces light or dark mode. The default `auto` reads the nearest ancestor's `data-color-scheme` or legacy `data-theme`, then the system preference. Each document exposes independent `data-rmd-theme` and resolved `data-color-scheme` attributes.
337
+ - Documents default to `max-width: 720px` and are horizontally centered. To fill the host container, override the width and margins of `.md-document` within your own scope.
338
+ - Prefer public variables for theme styling. Component outer `.md-*` and `.local-*` classes and semantic state attributes are theme hooks; internal node ordering is not an extension API. See the theme protocol for compatibility requirements.
339
+ - Neither React component accepts `className` or `style`. For local overrides, scope them with the host's own wrapper element.
340
+
341
+ ## Resource limits
342
+
343
+ A single string is limited to 100,000 characters, an array to 10,000 items, and the total string length within an array to 100,000 characters. Email validation uses a length-limited linear check. The runtime rejects writes over a limit and keeps the last valid state.
344
+
345
+ A single document source is limited to 1,000,000 characters. There are at most 100 diagnostics, and a single message is at most 2,000 characters.
346
+
347
+ Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in [constraints and collections](constraints-collections-en.md). Documents over a limit receive diagnostics; expression and math rendering also have their own depth and token budgets.
348
+
349
+ These limits bound the work for a single document; they do not replace host control over request size, concurrency and execution time. See the [security policy](../SECURITY.md) for the full threat boundary.
350
+
351
+ ## Version pinning and upgrades
352
+
353
+ - During 0.x, pin the exact package version and commit the lockfile. `^0.3.0` allows only patch versions, but production integrations should still pin the version or the tarball SHA256.
354
+ - Use one package version for both the core and React entries; do not mix different versions of `reactive-md` and `reactive-md/react`.
355
+ - Record `LOCAL_SYNTAX_VERSION` in application configuration or document metadata, alongside the persisted `.reactive.md` source. Migrate according to [Versions and compatibility](compatibility-en.md) when the syntax revision changes.
356
+ - After upgrading, recompile your own documents and check `result.diagnostics`, rendered output and browser interactions. Do not depend on the text of diagnostic `message`.
357
+
358
+ ## Features not provided
359
+
360
+ Local mode does not provide automatic state persistence or network access, plugins or custom component registration, arbitrary HTML, author CSS, event handlers, external data APIs, form submission, Vue support, React 18 support or a CommonJS entry. State export and import are explicit host calls; the runtime never saves or sends state by itself. `LocalReactiveDocument` still starts from initial values when the source changes; use the retention helpers or supply your own runtime and document. Hosts should not treat these capabilities as configuration options.
361
+
362
+
363
+ See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. `0.4.0` is the preview release on the `next` channel.
@@ -1,16 +1,26 @@
1
1
  # Reactive MD 本地交互语法规范
2
2
 
3
- 语法标识:`local-draft-1`,2026-10-22。第一次接触这套语法,建议先读 [新用户入门指南](local-guide.md);本文是完整规范。宿主通过 `compileLocal` 和 `LocalReactiveDocument` 选择本地交互模式,见 [集成说明](local-integration.md)。包版本关系、0.x 兼容规则和迁移见 [版本与兼容性](compatibility.md)。完整示例见 [Demo 索引](../examples/local/README.md)。
3
+ 本次新增的跳转、正文颜色、多选、区间、坐标、练习题、分步阅读和选择联动,见[新增组块与迁移](local-components-v2-ch.md)。
4
+
5
+ 语法标识:`local-draft-2`,2026-10-23。第一次接触这套语法,建议先读 [新用户入门指南](local-guide-ch.md);本文是完整规范。宿主通过 `compileLocal` 和 `LocalReactiveDocument` 选择本地交互模式,见 [集成说明](local-integration-ch.md)。包版本关系、0.x 兼容规则和迁移见 [版本与兼容性](compatibility-ch.md),可选修订指令与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),从 `0.3.1` / `local-draft-1` 升级见[0.4.0 发布与迁移](release-0.4.0-ch.md)。完整示例见 [示例索引](../examples/local/README.md)。
4
6
 
5
7
  ## 1. 定位与范围
6
8
 
9
+ `0.4.0` 新增不可见的 `computed`/`const` 声明与数字、字符串、日期函数。声明语法、依赖与错误规则、函数签名及固定默认值见[复用计算与格式化数值](computations-formatting-ch.md)。
10
+
11
+ 跨字段校验、条件样式、数组与有限表格行生成见[条件、校验与本地集合](constraints-collections-ch.md)。
12
+
13
+ 字符长度、源码定位与资源预算的单位见[诊断与计数规则](diagnostics-counting-ch.md)。字符串 `len()` 和文本控件长度约束按 Unicode 码点计数。
14
+
7
15
  Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件,读者调整参数后,相关文字、公式、图表和图解立即更新。
8
16
 
9
17
  基础语言只需要掌握两条连接规则:`bind` 为输入命名,`{{ 表达式 }}` 在其他位置读取它。组件负责自己的选择、展开、搜索、排序、计时和重置。
10
18
 
11
- 本草案不包含外部服务调用、提交表单、异步资源、命名动作、事件处理器、可编程集合增删、循环模板或任意脚本。旧版 `state/data/computed/actions` 配置块不属于新语法。数组仅由清单组件产生,表格数据直接写在正文中。
19
+ 本草案不包含外部服务调用、提交表单、异步资源、命名动作、事件处理器、可编程集合增删、通用循环模板或任意脚本。旧版 `state/data/computed/actions` 配置块不属于新语法。表达式可以产生字符串或数字数组,清单与多选组件继续产生字符串数组。表格可直接写为 Markdown,也可通过带预算的 `data-table` 从本地值生成行。
20
+
21
+ 文档默认只保存当前实例的内存状态。重新打开从初值开始;持久化不属于作者语法。无需声明语言版本、导入组件或编写 YAML。文档可以在前导区、主题和正文之前用一行 `<!-- reactive-md: local-draft-2 -->` 可选地声明修订;无指令文档使用当前修订。见[源码修订与迁移](source-versioning-ch.md)。宿主应明确选择草案解析模式,不能把旧语法与新语法混合猜测解析。
12
22
 
13
- 文档默认只保存当前实例的内存状态。重新打开从初值开始;持久化不属于作者语法。无需声明语言版本、导入组件或编写 YAML。宿主应明确选择草案解析模式,不能把旧语法与新语法混合猜测解析。
23
+ 文档可在正文前用 `<theme name="default">` 选择整份文档的主题,省略时为 `default`。这是静态元数据声明,不是组件;自定义主题须由宿主登记并同时支持深浅模式,见[主题协议](theme-protocol-ch.md)。
14
24
 
15
25
  ## 2. 第一份文档
16
26
 
@@ -37,7 +47,7 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
37
47
 
38
48
  块组件的开始与结束标签各占一行。开始标签的属性可以跨多行书写。标签内部的 `>` 只有在引号之外才结束标签。缩进只用于可读性:容器内容按共同缩进量去缩进,再按 Markdown 解析;代码围栏内部的缩进保持原样。
39
49
 
40
- 行内组件 `badge`、`tooltip` 可以嵌入句子。其他组件为块组件;`option`、`tab`、`disclosure`、`node`、`edge` 是限定父容器内的子组件。
50
+ 行内组件 `badge`、`tooltip`、`jump`、`text` 可以嵌入句子。其他组件为块组件;`option`、`tab`、`disclosure`、`node`、`edge` 是限定父容器内的子组件。
41
51
 
42
52
  ### 3.2 两种标签形态
43
53
 
@@ -46,7 +56,7 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
46
56
  | 无正文组件 | `<slider bind="a" label="振幅">` | 不写结束标签;也接受末尾的 `/>` |
47
57
  | 有正文容器 | `<card title="说明">` 和 `</card>` | 必须显式闭合,允许嵌套 |
48
58
 
49
- 无正文组件固定为 `input`、`textarea`、`number`、`slider`、`toggle`、`checkbox`、`date`、`counter`、`timer`、`progress`、`edge`。其余本草案列出的组件均使用成对标签。`textarea` 的文本通过 `initial` 设置,因此属于无正文组件。
59
+ 无正文组件固定为 `input`、`textarea`、`number`、`slider`、`range-slider`、`coordinate`、`toggle`、`checkbox`、`date`、`counter`、`timer`、`progress`、`anchor`、`edge`。声明标签 `computed`、`const`、`validation` 以及结构子项 `column` 同样没有正文。其余本草案列出的组件均使用成对标签。`textarea` 的文本通过 `initial` 设置,因此属于无正文组件。
50
60
 
51
61
  例如:
52
62
 
@@ -80,13 +90,13 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
80
90
 
81
91
  属性中的 `&quot;`、`&apos;`、`&amp;`、`&lt;`、`&gt;` 解码为相应文字;反斜杠不用于转义属性引号。数值和布尔属性的动态值必须是一个完整插值,结果保持原类型;文本属性可包含多段插值。
82
92
 
83
- `bind`、`initial`、`id`、`value`(选项标识)、`from`、`to`、`kind`、字段映射以及布局枚举是静态属性。输入的 `min/max/step` 也是静态约束;绘图的 `min/max` 可以动态,以支持调整观察区间。
93
+ `bind`、`initial`、`name`、`id`、`value`(选项标识)、`to`、`from`、`answer`、`kind`、字段映射以及布局枚举是静态属性。输入的 `min/max/step` 也是静态约束;绘图的 `min/max` 可以动态,以支持调整观察区间。`textarea` 的 `rows` 是静态行数,`data-table.rows` 则是必填表达式,两者不要混淆。
84
94
 
85
95
  未知组件、未知属性、错误位置或错误属性类型都给出源码诊断。注册的标签不直接作为任意 HTML 执行;作者不能使用 `script`、`style`、`onclick` 或其他脚本入口。
86
96
 
87
97
  ### 3.4 代码、公式与转义
88
98
 
89
- 行内代码和代码围栏内的标签、插值、公式标记全部按原文显示。Markdown 注释 `<!-- ... -->` 不产生组件或变量。
99
+ 行内代码和代码围栏内的标签、插值、公式标记全部按原文显示。前导区中的源码修订指令是会被识别的版本注释;其他 Markdown 注释 `<!-- ... -->` 不产生组件或变量。
90
100
 
91
101
  正文用 `\{{` 显示字面量 `{{`,用 `\<slider>` 或行内代码显示标签示例。反斜杠的这类转义只属于 Markdown 上下文,不应用到 LaTeX 源码。
92
102
 
@@ -107,12 +117,17 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
107
117
  | counter | 数字 | 在范围内最接近 0 的合法步长值 |
108
118
  | toggle、checkbox | 布尔值 | false |
109
119
  | select、choices、radio-group | 选项字符串 | 第一项的 value |
120
+ | multi-select | 已选选项 value 的字符串数组 | 空数组 |
121
+ | range-slider | 两个数字,`start` / `end` 槽位 | start=min;end=不超过 max 的最大合法步长值 |
122
+ | coordinate | 两个数字,`x` / `y` 槽位 | 各轴最接近 0 的合法步长值 |
123
+ | 带 `key` 的 table、chart | 稳定的行标识字符串 | 空字符串(未选) |
110
124
  | tabs | 页面字符串 | 第一项的 value |
125
+ | steps | 步骤字符串 | 第一步的 value |
111
126
  | diagram | 节点 ID 字符串 | 第一节点的 id |
112
127
  | checklist | 已选条目 ID 的字符串数组 | 由任务列表的勾选标记决定 |
113
128
  | timer | 剩余秒数 | duration,默认 60 |
114
129
 
115
- 标量组件用 `initial` 覆盖默认值。`timer` 使用 `duration`,`checklist` 使用正文的勾选标记,两者不接受 `initial`。日期使用真实有效的 `YYYY-MM-DD`;空字符串表示尚未选择。
130
+ 标量组件用 `initial` 覆盖默认值。`range-slider` 和 `coordinate` 分别用 `initial-start`/`initial-end` 与 `initial-x`/`initial-y` 设置槽位;`multi-select` 的 `initial` 是逗号分隔的静态选项 value 列表。`timer` 使用 `duration`,`checklist` 使用正文的勾选标记,两者不接受 `initial`。`table` 或 `chart` 的选择状态只有在同时提供 `key` 时才接受 `initial`。日期使用真实有效的 `YYYY-MM-DD`;空字符串表示尚未选择。
116
131
 
117
132
  `bind` 可省略。未命名组件拥有独立内部状态,不从标签推导变量名。控件的 `label` 必填,可使用动态文本;这同时是控件的可访问名称。
118
133
 
@@ -122,7 +137,7 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
122
137
 
123
138
  同类数值、文本或布尔输入可以绑定同一变量,值保持同步;类型必须相同,数值范围和步长必须一致。`select/choices/radio-group` 共享变量时,value 集合与顺序也必须相同。标签文字可不同。
124
139
 
125
- 同一变量最多出现一次显式 `initial`。没有显式初值时,采用源码中首个控件的默认值,并校验所有关联约束。后续控件省略 `initial` 表示共享已有初值。`timer/checklist/tabs/diagram` 的公开状态各由一个组件拥有,不接受第二个同名拥有者或其他控件写入。
140
+ 同一变量最多出现一次显式 `initial`。没有显式初值时,采用源码中首个控件的默认值,并校验所有关联约束。后续控件省略 `initial` 表示共享已有初值。`timer/checklist/tabs/diagram/multi-select/steps` 的公开状态各由一个组件拥有,不接受第二个同名拥有者或其他控件写入。`range-slider` 和 `coordinate` 的每个数值槽位也独占绑定。`table` 与 `chart` 只有在有序 `key` 集合完全一致时才能共享选择绑定。
126
141
 
127
142
  引用未声明变量直接报错,不自动创建空值。组件的初值是文档初始化数据,重新显示隐藏控件不会再次初始化。
128
143
 
@@ -158,6 +173,10 @@ Reactive MD 用于本地交互文档:作者写 Markdown、放置输入控件
158
173
  | 条件 | `条件 ? 真值 : 假值` |
159
174
  | 数学函数 | abs、sqrt、floor、ceil、round、min、max、pow、sin、cos、tan、asin、acos、atan、exp、log |
160
175
  | 常用函数 | len、contains、clamp |
176
+ | 格式化 | formatNumber、formatPercent、formatScientific、formatCurrency |
177
+ | 字符串 | trim、lower、upper、startsWith、endsWith、replace、slice |
178
+ | 日期 | dateCompare、dateDiff |
179
+ | 数组聚合 | sum、average、minOf、maxOf |
161
180
  | 常量 | pi、e |
162
181
 
163
182
  优先级依次为函数/括号、一元运算、乘除余数、加减、大小比较、相等比较、逻辑与、逻辑或、条件表达式;条件表达式右结合,其余二元运算左结合。逻辑和条件表达式短路求值。
@@ -174,7 +193,7 @@ GFM 表格中的竖线须写成 `\|`,例如逻辑或写 `\|\|`。表格解析
174
193
 
175
194
  除零、定义域错误、非有限结果和类型错误显示在对应内容附近。参数本身合法时仍保留用户的新输入,其他独立内容正常更新;出错结果显示“无法计算”,不沿用旧数值冒充新结果。
176
195
 
177
- 基础语法不引入命名 computed。简短计算就地书写;长数学关系用公式和曲线表达,避免在 YAML 与正文重复维护。
196
+ 本版本通过顶层 `computed` 与 `const` 声明增加只读命名值。简短计算仍可就地书写;需要被正文、条件、公式和图表共享的中间结果使用声明。依赖、错误和缓存规则见[复用计算与格式化数值](computations-formatting-ch.md)。
178
197
 
179
198
  ## 6. 输入与参数面板
180
199
 
@@ -186,10 +205,14 @@ GFM 表格中的竖线须写成 `\|`,例如逻辑或写 `\|\|`。表格解析
186
205
  | textarea | placeholder;rows=4;required=false;min-length=0;可选 max-length |
187
206
  | number | 可选 min/max;step=1 |
188
207
  | slider | min=0;max=100;step=1 |
208
+ | range-slider | bind-start/bind-end 与 initial-start/initial-end;min=0;max=100;step=1;可选 color |
209
+ | coordinate | bind-x/bind-y 与 initial-x/initial-y;x-min/y-min=-5;x-max/y-max=5;step=1;可选 color |
189
210
  | counter | min=0;可选 max;step=1 |
190
- | toggle、checkbox | 无 |
211
+ | toggle、checkbox | 可选 color |
191
212
  | date | 可选 min/max 日期;required=false |
192
- | select、choices、radio-group | 正文为一个或多个 option |
213
+ | select、choices、radio-group、multi-select | 正文为一个或多个 option;multi-select 增加 max-selected,值为字符串数组 |
214
+
215
+ `range-slider` 和 `coordinate` 公开彼此独立的数字槽位。省略 `bind-start`/`bind-end` 或 `bind-x`/`bind-y` 时对应槽位只保留内部状态;每个槽位最多一处显式初值。端点交叉会被拒绝,不会自动交换。`multi-select` 的 `label` 必填,支持 `max-selected`,写入按源码顺序规范化。这些组件都支持可选 `color`。完整规则见[local-draft-2 扩展说明](local-components-v2-ch.md)。
193
216
 
194
217
  选择器示例:
195
218
 
@@ -213,7 +236,7 @@ option.value 为非空、静态、唯一字符串;正文是选项的行内文
213
236
  | 容器 | 属性 | 正文与默认行为 |
214
237
  | --- | --- | --- |
215
238
  | card | 可选 title | 普通 Markdown;一块内容卡片 |
216
- | grid | columns=2(整数 1–4) | 直接子项为 card;窄屏自动单列 |
239
+ | grid | columns=2(整数 1–4,表示最大列数) | 直接子项为 card;按容器可用宽度减少列数,适用于嵌套网格和嵌入文档 |
217
240
  | tabs | 可选 label、bind、initial | 一个或多个 tab,默认选第一项 |
218
241
  | tab | label 必填,可选 value | 普通 Markdown |
219
242
  | accordion | 可选 label | 一个或多个 disclosure |
@@ -227,7 +250,21 @@ tab 未写 value 时,按源码顺序生成 `tab-1`、`tab-2` 等;同组 valu
227
250
 
228
251
  if 的 when 为假时不显示内容,内部参数仍按第 4 节初始化。未知变量或类型错误在隐藏分支中仍是编译错误。
229
252
 
230
- 基础排版使用 Markdown;图片用 `![说明](路径)`,链接用 `[文字](地址)`,分隔线用 `---`。图片需由宿主通过 URL 策略明确允许后才加载,默认不产生图片请求,集成方式见[图片与链接策略](local-integration.md#图片与链接策略)。本草案不提供 row、stack、spacer、icon、image、link-button 等对应的作者标签,也不开放 class/style。
253
+ ### 7.1 跳转、颜色与分步阅读
254
+
255
+ | 容器或行内标签 | 属性 | 正文与默认行为 |
256
+ | --- | --- | --- |
257
+ | jump | to 必填;appearance=link/button,默认 link;可选 color | 行内 Markdown;滚动到标题锚点或显式 anchor |
258
+ | anchor | id 必填且文档内唯一 | 无正文;标记显式跳转目标 |
259
+ | text | color 必填 | 行内 Markdown 与插值;设置前景色 |
260
+ | section | color 必填 | 块级 Markdown;设置可继承的前景色,不添加边框或背景 |
261
+ | quiz | type=choice/number,默认 choice;label 与 answer 必填;可选 explanation、tolerance | 选择题含 option;数字题正文为空;不公开 bind |
262
+ | steps | 可选 label、bind、initial;字符串绑定独占 | 一个或多个 step;默认选第一步 |
263
+ | step | label 必填;可选 value | Markdown 正文;省略 value 时生成 step-1、step-2 等 |
264
+
265
+ `jump.to` 与 `anchor.id` 匹配标题锚点或显式 ID。重复 anchor、与标题锚点冲突或目标不存在都是编译错误。`quiz` 的答案随源码提供,适合自学;草稿和反馈保留在组件内部,面板重置会清除。`steps` 中未激活的步骤仍参与初始化并保留状态;隐藏计时器暂停。颜色校验和槽位细节见[local-draft-2 扩展说明](local-components-v2-ch.md)。
266
+
267
+ 基础排版使用 Markdown;图片用 `![说明](路径)`,链接用 `[文字](地址)`,分隔线用 `---`。图片需由宿主通过 URL 策略明确允许后才加载,默认不产生图片请求,集成方式见[图片与链接策略](local-integration-ch.md#图片与链接策略)。本草案不提供 row、stack、spacer、icon、image、link-button 等对应的作者标签,也不开放 class/style。
231
268
 
232
269
  ## 8. 可勾选清单
233
270
 
@@ -270,7 +307,7 @@ table、chart、timeline 的正文各为一张 Markdown 表格。表头非空且
270
307
  </table>
271
308
  ```
272
309
 
273
- table 支持可选 label、searchable=true、sortable=true、page-size=10(正整数)。默认提供搜索框、可排序表头和分页;只有一页时隐藏分页控件。
310
+ table 支持可选 label、searchable=true、sortable=true、page-size=10(正整数)。默认提供搜索框、可排序表头和分页;只有一页时隐藏分页控件。`key` 指定静态、非空、唯一的标识列后,`bind` 与 `initial` 可以把选中行公开为稳定字符串;没有 `key` 时选择只保留在渲染器内部。
274
311
 
275
312
  搜索是全列显示文本的大小写不敏感子串匹配,去掉查询首尾空白;排序使用完整列的类型,数值列按数值,其余按文本 Unicode 码点顺序,保持同值行的原始顺序。表头点击依次升序、降序、恢复源码顺序。搜索或排序变化回到第一页,响应式数据变化后把当前页限制到有效范围。无匹配项显示“没有匹配结果”。这些交互只影响表格内部。
276
313
 
@@ -295,11 +332,11 @@ chart.kind 默认为 bar,支持 bar、line、area、scatter、donut。支持
295
332
 
296
333
  line/area 的横轴按整列类型确定为数值轴或分类轴,按源码顺序连接。donut 数值必须非负,总和为零时显示“暂无占比”。系列名称自动成为图例;默认提供指针与键盘读数,无需事件逻辑。
297
334
 
298
- 数值列会随参数更新。计算错误显示在对应图表,不将错误值替换为 0。此基础版本不暴露图表选择作为公开状态。
335
+ 数值列会随参数更新。计算错误显示在对应图表,不将错误值替换为 0。提供 `key` 时,图表可以通过 `bind` 公开选择,使用与 `table` 相同的稳定行标识规则;表格与图表只有在有序 key 一致时才能共享该绑定。
299
336
 
300
337
  ### 9.4 时间轴
301
338
 
302
- timeline 支持可选 title、unit(显示文本,默认“分钟”),正文为包含 `事项`、`开始`、`时长` 三列及可选 `说明` 列的表格。这些列名是固定表头;开始和时长为非负数。按开始时间稳定排序,允许重叠区间,说明通过指针或键盘查看。表格内容可以使用插值。
339
+ timeline 支持可选 title、unit(显示文本,默认“分钟”),正文为包含 `事项`、`开始`、`时长` 三列(可选 `说明`)或 `Task`、`Start`、`Duration` 三列(可选 `Notes`)的表格。这些列名是固定表头;开始和时长为非负数。按开始时间稳定排序,允许重叠区间,说明通过指针或键盘查看。表格内容可以使用插值。
303
340
 
304
341
  ## 10. LaTeX 公式与函数绘图
305
342
 
@@ -395,13 +432,16 @@ node.id 为当前图解内唯一的 `[A-Za-z_][A-Za-z0-9_-]*`。edge 必填 from
395
432
 
396
433
  | 用途 | 草案组件 |
397
434
  | --- | --- |
398
- | 参数输入 | input、textarea、number、slider、toggle、checkbox、date、select、choices、radio-group、option |
435
+ | 参数输入 | input、textarea、number、slider、range-slider、coordinate、toggle、checkbox、date、select、choices、radio-group、multi-select、option |
399
436
  | 自带操作 | counter、timer、checklist、progress |
400
437
  | 组织内容 | panel、card、grid、tabs、tab、accordion、disclosure、if |
438
+ | 跳转与正文 | jump、anchor、text、section |
439
+ | 练习与分步 | quiz、steps、step |
401
440
  | 提示 | alert、badge、tooltip |
441
+ | 声明与生成数据 | computed、const、validation、data-table、column |
402
442
  | 可视化 | table、chart、plot、timeline、diagram、node、edge |
403
443
 
404
- 共 33 个组件名,其中 option、tab、disclosure、node、edge 为父组件的结构子项。大部分文章只需 Markdown 和两三个输入/展示组件。普通金额可以直接写 `{{ total }} 元`;货币格式、统计卡片不作为入门必需品。
444
+ 共 48 个标签名。`option`、`tab`、`disclosure`、`node`、`edge`、`step`、`column` 为父组件的结构子项。`computed`、`const`、`validation` 是文档声明,按标签解析但不渲染为控件。开头的 `<theme>` 声明是元数据,不计入这里。大部分文章只需 Markdown 和两三个输入/展示组件。普通金额可以直接写 `{{ total }} 元`;货币格式、统计卡片不作为入门必需品。
405
445
 
406
446
  本草案不接受旧版 form、submit、button、each、list、spinner、stat、value 等标签,也不接受 set/reset 动作属性或 on-* 事件属性。面板的 reset 是固定布尔选项,不是可编程动作。
407
447
 
@@ -421,6 +461,9 @@ node.id 为当前图解内唯一的 `[A-Za-z_][A-Za-z0-9_-]*`。edge 必填 from
421
461
  | 约束 | slider 初值超出 max | 合法范围和当前值 |
422
462
  | 表格 | 数值列含“20 元” | 列名、行号以及应填写数字 |
423
463
  | 图解 | edge 指向不存在的节点 | 缺失的节点 ID |
464
+ | 声明 | computed 放在容器内或名称重复 | 顶层位置、冲突名称或控件 |
465
+ | 数据表 | data-table 缺少 column,或 key 重复 | 必需的列和唯一稳定键 |
466
+ | 校验 | fields 包含只读声明 | 可写的公开绑定名 |
424
467
  | 数学 | 绘图中使用积分或缺失参数 | 对应数学片段和支持范围 |
425
468
 
426
469
  实现验收必须覆盖:
@@ -436,4 +479,7 @@ node.id 为当前图解内唯一的 `[A-Za-z_][A-Za-z0-9_-]*`。edge 必填 from
436
479
  9. 中文输入法、键盘操作、可访问名称和 375px 窄屏可用。
437
480
  10. 文档实例独立、销毁清理、无意外网络动作;复杂或超量数学输入能够被执行预算中止。
438
481
 
439
- 这些规则用于编译器、运行时和浏览器验收。示例映射及预期观察点见 [Demo 索引](../examples/local/README.md),机器可读的最小验收集见[语言验收数据](../examples/conformance/README.md),实际检查记录见[仓库实现说明](https://github.com/yao1145/ReactiveMD/blob/main/demo/IMPLEMENTATION.md)。
482
+ 这些规则用于编译器、运行时和浏览器验收。示例映射及预期观察点见[示例索引](../examples/local/README.md),机器可读的最小验收集见[语言验收数据](../examples/conformance/README.md)。实际仓库检查记录保留在仓库内,不属于发布包。
483
+
484
+
485
+ 新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.4.0` 是 `next` 渠道的预览版。