reactive-md 0.3.0 → 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 (175) hide show
  1. package/CHANGELOG-ch.md +96 -0
  2. package/CHANGELOG.md +96 -40
  3. package/CONTRIBUTING-ch.md +62 -0
  4. package/CONTRIBUTING.md +64 -61
  5. package/README-ch.md +122 -0
  6. package/README-en.md +146 -0
  7. package/README.md +146 -88
  8. package/SECURITY-ch.md +80 -0
  9. package/SECURITY.md +80 -68
  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 +3603 -1690
  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/compiler.d.ts +3 -3
  34. package/dist-library/types/local/computations.d.ts +53 -0
  35. package/dist-library/types/local/data-functions.d.ts +22 -0
  36. package/dist-library/types/local/data-table.d.ts +65 -0
  37. package/dist-library/types/local/dates.d.ts +2 -0
  38. package/dist-library/types/local/dependencies.d.ts +31 -0
  39. package/dist-library/types/local/diagnostics.d.ts +1450 -0
  40. package/dist-library/types/local/expression.d.ts +13 -3
  41. package/dist-library/types/local/formatting.d.ts +41 -0
  42. package/dist-library/types/local/heading-anchors.d.ts +17 -0
  43. package/dist-library/types/local/i18n.d.ts +18 -0
  44. package/dist-library/types/local/index.d.ts +18 -1
  45. package/dist-library/types/local/limits.d.ts +33 -1
  46. package/dist-library/types/local/locale.d.ts +1 -0
  47. package/dist-library/types/local/math.d.ts +6 -1
  48. package/dist-library/types/local/parser.d.ts +10 -4
  49. package/dist-library/types/local/render-types.d.ts +5 -1
  50. package/dist-library/types/local/retention.d.ts +23 -0
  51. package/dist-library/types/local/schema.d.ts +25 -3
  52. package/dist-library/types/local/source-migration.d.ts +35 -0
  53. package/dist-library/types/local/state.d.ts +80 -0
  54. package/dist-library/types/local/text-length.d.ts +13 -0
  55. package/dist-library/types/local/theme.d.ts +30 -0
  56. package/dist-library/types/local/types.d.ts +120 -4
  57. package/dist-library/types/local/validation.d.ts +32 -0
  58. package/dist-library/types/local/version.d.ts +1 -1
  59. package/dist-library/types/local/worker.d.ts +82 -0
  60. package/dist-library/types/react/index.d.ts +4 -1
  61. package/dist-library/types/shareable.d.ts +64 -0
  62. package/dist-standalone/reactive-md-standalone.css +2 -0
  63. package/dist-standalone/reactive-md-standalone.js +57 -0
  64. package/docs/author-tools-ch.md +56 -0
  65. package/docs/author-tools-en.md +56 -0
  66. package/docs/compatibility-ch.md +103 -0
  67. package/docs/compatibility-en.md +103 -0
  68. package/docs/component-development-ch.md +210 -0
  69. package/docs/component-development-en.md +210 -0
  70. package/docs/component-protocol-ch.md +710 -0
  71. package/docs/component-protocol-en.md +710 -0
  72. package/docs/computations-formatting-ch.md +87 -0
  73. package/docs/computations-formatting-en.md +87 -0
  74. package/docs/constraints-collections-ch.md +84 -0
  75. package/docs/constraints-collections-en.md +84 -0
  76. package/docs/diagnostics-counting-ch.md +84 -0
  77. package/docs/diagnostics-counting-en.md +84 -0
  78. package/docs/local-components-v2-ch.md +138 -0
  79. package/docs/local-components-v2-en.md +104 -0
  80. package/docs/{local-guide.md → local-guide-ch.md} +961 -936
  81. package/docs/local-guide-en.md +961 -0
  82. package/docs/local-integration-ch.md +363 -0
  83. package/docs/local-integration-en.md +363 -0
  84. package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +485 -437
  85. package/docs/local-interaction-syntax-en.md +483 -0
  86. package/docs/performance-ch.md +76 -0
  87. package/docs/performance-en.md +76 -0
  88. package/docs/release-0.4.0-ch.md +89 -0
  89. package/docs/release-0.4.0-en.md +89 -0
  90. package/docs/releasing-ch.md +101 -0
  91. package/docs/releasing-en.md +101 -0
  92. package/docs/shareable-export-ch.md +205 -0
  93. package/docs/shareable-export-en.md +207 -0
  94. package/docs/source-versioning-ch.md +159 -0
  95. package/docs/source-versioning-en.md +159 -0
  96. package/docs/theme-protocol-ch.md +107 -0
  97. package/docs/theme-protocol-en.md +107 -0
  98. package/examples/conformance/README.md +53 -11
  99. package/examples/conformance/component-protocol-1.json +482 -0
  100. package/examples/conformance/component-protocol-1.schema.json +76 -0
  101. package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
  102. package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
  103. package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
  104. package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
  105. package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
  106. package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
  107. package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
  108. package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
  109. package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
  110. package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
  111. package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
  112. package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
  113. package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
  114. package/examples/conformance/history/v0.3.1/provenance.json +72 -0
  115. package/examples/conformance/local-draft-1.json +50 -49
  116. package/examples/conformance/local-draft-2.json +212 -0
  117. package/examples/integration/README.md +45 -29
  118. package/examples/integration/core/index.mjs +32 -19
  119. package/examples/integration/react/index.html +1 -1
  120. package/examples/integration/react/main.jsx +5 -5
  121. package/examples/integration/worker/index.html +19 -0
  122. package/examples/integration/worker/main.js +61 -0
  123. package/examples/integration/worker/package.json +13 -0
  124. package/examples/integration/worker/worker.js +3 -0
  125. package/examples/local/README.md +72 -66
  126. package/examples/local/catalog.reactive.md +14 -14
  127. package/examples/local/charts.reactive.md +73 -73
  128. package/examples/local/checklist.reactive.md +19 -19
  129. package/examples/local/comparison.reactive.md +23 -23
  130. package/examples/local/components.reactive.md +20 -20
  131. package/examples/local/counter.reactive.md +4 -4
  132. package/examples/local/diagnostics.reactive.md +25 -25
  133. package/examples/local/diagram.reactive.md +20 -20
  134. package/examples/local/gallery.reactive.md +31 -31
  135. package/examples/local/parameters.reactive.md +19 -19
  136. package/examples/local/planning.reactive.md +15 -15
  137. package/examples/local/pricing.reactive.md +10 -10
  138. package/examples/local/recipes/invoice-zh.reactive.md +36 -0
  139. package/examples/local/recipes/invoice.reactive.md +36 -0
  140. package/examples/local/recipes/workshop-zh.reactive.md +33 -0
  141. package/examples/local/recipes/workshop.reactive.md +33 -0
  142. package/examples/local/showcase/README.md +25 -0
  143. package/examples/local/showcase/explore.reactive.md +102 -0
  144. package/examples/local/showcase/flow.reactive.md +86 -0
  145. package/examples/local/showcase/forms.reactive.md +126 -0
  146. package/examples/local/showcase/functions.reactive.md +119 -0
  147. package/examples/local/showcase/layout.reactive.md +100 -0
  148. package/examples/local/showcase/statistics.reactive.md +108 -0
  149. package/examples/local/showcase/tasks.reactive.md +89 -0
  150. package/examples/local/showcase/zh/explore.reactive.md +102 -0
  151. package/examples/local/showcase/zh/flow.reactive.md +86 -0
  152. package/examples/local/showcase/zh/forms.reactive.md +126 -0
  153. package/examples/local/showcase/zh/functions.reactive.md +119 -0
  154. package/examples/local/showcase/zh/layout.reactive.md +100 -0
  155. package/examples/local/showcase/zh/statistics.reactive.md +108 -0
  156. package/examples/local/showcase/zh/tasks.reactive.md +89 -0
  157. package/examples/local/zh/catalog.reactive.md +20 -0
  158. package/examples/local/zh/charts.reactive.md +73 -0
  159. package/examples/local/zh/checklist.reactive.md +32 -0
  160. package/examples/local/zh/comparison.reactive.md +47 -0
  161. package/examples/local/zh/components.reactive.md +44 -0
  162. package/examples/local/zh/counter.reactive.md +7 -0
  163. package/examples/local/zh/diagnostics.reactive.md +54 -0
  164. package/examples/local/zh/diagram.reactive.md +44 -0
  165. package/examples/local/zh/gallery.reactive.md +61 -0
  166. package/examples/local/zh/parameters.reactive.md +36 -0
  167. package/examples/local/zh/planning.reactive.md +24 -0
  168. package/examples/local/zh/pricing.reactive.md +20 -0
  169. package/package.json +90 -75
  170. package/README.en.md +0 -75
  171. package/dist-library/runtime-D4phFXOr.js +0 -10937
  172. package/docs/compatibility.md +0 -67
  173. package/docs/local-integration.md +0 -193
  174. package/docs/performance.md +0 -30
  175. package/docs/releasing.md +0 -92
@@ -0,0 +1,212 @@
1
+ {
2
+ "syntaxVersion": "local-draft-2",
3
+ "cases": [
4
+ {
5
+ "name": "shared numeric binding has one initial value and updates prose",
6
+ "source": "<number bind=\"n\" label=\"Count\" initial=\"2\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"Shared count\" min=\"0\" max=\"10\">\n\nTotal: {{ n * 2 }}",
7
+ "ok": true,
8
+ "initial": {
9
+ "n": 2
10
+ },
11
+ "actions": [
12
+ {
13
+ "bind": "n",
14
+ "value": 5
15
+ }
16
+ ],
17
+ "text": "Total: {{ n * 2 }}",
18
+ "expectedText": "Total: 10"
19
+ },
20
+ {
21
+ "name": "hidden controls initialize their bindings",
22
+ "source": "<toggle bind=\"show\" label=\"Show\">\n<if when=\"{{ show }}\">\n<number bind=\"n\" label=\"Hidden count\" initial=\"4\">\n</if>\n\n{{ n * 2 }}",
23
+ "ok": true,
24
+ "initial": {
25
+ "show": false,
26
+ "n": 4
27
+ },
28
+ "text": "{{ n * 2 }}",
29
+ "expectedText": "8"
30
+ },
31
+ {
32
+ "name": "invalid state writes keep the last valid value",
33
+ "source": "<number bind=\"n\" label=\"Count\" initial=\"4\" min=\"0\" max=\"10\">",
34
+ "ok": true,
35
+ "initial": {
36
+ "n": 4
37
+ },
38
+ "actions": [
39
+ {
40
+ "bind": "n",
41
+ "value": 11,
42
+ "codes": [
43
+ "local.runtime.value"
44
+ ]
45
+ }
46
+ ],
47
+ "text": "{{ n }}",
48
+ "expectedText": "4"
49
+ },
50
+ {
51
+ "name": "code fences keep controls and interpolation literal",
52
+ "source": "```markdown\n<counter bind=\"n\" label=\"Literal\">\n{{ missing }}\n```",
53
+ "ok": true,
54
+ "bindingNames": []
55
+ },
56
+ {
57
+ "name": "unknown components preserve source with a warning",
58
+ "source": "<slidr label=\"Typo\">\n</slidr>",
59
+ "ok": true,
60
+ "bindingNames": [],
61
+ "codes": [
62
+ "local.component.unknown"
63
+ ]
64
+ },
65
+ {
66
+ "name": "unbound expression names produce a compiler diagnostic",
67
+ "source": "Total: {{ missing * 2 }}",
68
+ "ok": false,
69
+ "codes": [
70
+ "local.binding.unknown"
71
+ ]
72
+ },
73
+ {
74
+ "name": "multi-select-values",
75
+ "source": "<multi-select bind=\"subjects\" label=\"Subjects\" max-selected=\"2\">\n<option value=\"math\">Math</option>\n<option value=\"physics\">Physics</option>\n</multi-select>",
76
+ "ok": true,
77
+ "codes": [],
78
+ "initial": {
79
+ "subjects": []
80
+ },
81
+ "bindingNames": [
82
+ "subjects"
83
+ ],
84
+ "actions": [
85
+ {
86
+ "bind": "subjects",
87
+ "value": [
88
+ "physics",
89
+ "math"
90
+ ],
91
+ "codes": []
92
+ }
93
+ ],
94
+ "text": "{{ len(subjects) }}",
95
+ "expectedText": "2"
96
+ },
97
+ {
98
+ "name": "range-slots",
99
+ "source": "<range-slider label=\"Interval\" bind-start=\"low\" bind-end=\"high\" initial-start=\"20\" initial-end=\"80\">",
100
+ "ok": true,
101
+ "codes": [],
102
+ "initial": {
103
+ "low": 20,
104
+ "high": 80
105
+ },
106
+ "bindingNames": [
107
+ "low",
108
+ "high"
109
+ ],
110
+ "text": "{{ high - low }}",
111
+ "expectedText": "60"
112
+ },
113
+ {
114
+ "name": "coordinate-slots",
115
+ "source": "<coordinate label=\"Point\" bind-x=\"px\" bind-y=\"py\" initial-x=\"1\" initial-y=\"2\">",
116
+ "ok": true,
117
+ "codes": [],
118
+ "initial": {
119
+ "px": 1,
120
+ "py": 2
121
+ },
122
+ "bindingNames": [
123
+ "px",
124
+ "py"
125
+ ],
126
+ "text": "{{ px + py }}",
127
+ "expectedText": "3"
128
+ },
129
+ {
130
+ "name": "steps-initialization",
131
+ "source": "<steps label=\"Path\" bind=\"lesson\">\n<step label=\"Read\">\nRead first.\n</step>\n<step label=\"Try\">\nTry next.\n</step>\n</steps>",
132
+ "ok": true,
133
+ "codes": [],
134
+ "initial": {
135
+ "lesson": "step-1"
136
+ },
137
+ "bindingNames": [
138
+ "lesson"
139
+ ],
140
+ "actions": [
141
+ {
142
+ "bind": "lesson",
143
+ "value": "step-2",
144
+ "codes": []
145
+ }
146
+ ],
147
+ "text": "{{ lesson }}",
148
+ "expectedText": "step-2"
149
+ },
150
+ {
151
+ "name": "jump-colored-prose",
152
+ "source": "<jump to=\"result\">Results</jump>\n\n<section color=\"#123\">\n\n<text color=\"red\">Important</text>\n\n</section>\n\n<anchor id=\"result\">\n\nDone.",
153
+ "ok": true,
154
+ "codes": []
155
+ },
156
+ {
157
+ "name": "quiz-choice",
158
+ "source": "<quiz label=\"Two plus three\" answer=\"b\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>",
159
+ "ok": true,
160
+ "codes": []
161
+ },
162
+ {
163
+ "name": "selection-key",
164
+ "source": "<table bind=\"project\" key=\"Project\" initial=\"Visual\">\n| Project | Cost |\n| --- | ---: |\n| Content | 120 |\n| Visual | 230 |\n</table>",
165
+ "ok": true,
166
+ "codes": [],
167
+ "initial": {
168
+ "project": "Visual"
169
+ },
170
+ "bindingNames": [
171
+ "project"
172
+ ],
173
+ "actions": [
174
+ {
175
+ "bind": "project",
176
+ "value": "Content",
177
+ "codes": []
178
+ }
179
+ ],
180
+ "text": "{{ project }}",
181
+ "expectedText": "Content"
182
+ },
183
+ {
184
+ "name": "computed-values-recalculate-from-controls-and-arrays",
185
+ "source": "<computed name=\"costs\" value=\"{{ [seats * 80, materials ? seats * 20 : 0] }}\">\n<computed name=\"total\" value=\"{{ sum(costs) }}\">\n\n<number bind=\"seats\" label=\"Seats\" initial=\"4\" min=\"1\" max=\"20\">\n<toggle bind=\"materials\" label=\"Materials\">\n\nTotal: {{ total }}.",
186
+ "ok": true,
187
+ "codes": [],
188
+ "initial": {
189
+ "seats": 4,
190
+ "materials": false
191
+ },
192
+ "bindingNames": [
193
+ "materials",
194
+ "seats"
195
+ ],
196
+ "actions": [
197
+ {
198
+ "bind": "materials",
199
+ "value": true,
200
+ "codes": []
201
+ },
202
+ {
203
+ "bind": "seats",
204
+ "value": 6,
205
+ "codes": []
206
+ }
207
+ ],
208
+ "text": "Total: {{ total }}.",
209
+ "expectedText": "Total: 600."
210
+ }
211
+ ]
212
+ }
@@ -1,29 +1,45 @@
1
- # 独立集成示例
2
-
3
- 这些目录使用包的公开入口,可以复制到仓库外运行。以下命令从当前目录开始。
4
-
5
- ## Node 核心
6
-
7
- 需要 Node.js 22.12 或更新版本。核心示例无需 React,也不发起网络请求。
8
-
9
- ```sh
10
- cd core
11
- npm install reactive-md@0.3.0 --ignore-scripts --no-audit --no-fund
12
- npm start
13
- ```
14
-
15
- 预期先输出 `人数:2,费用:200`,再输出 `人数:5,费用:500`。源码在 [core/index.mjs](core/index.mjs)。
16
-
17
- ## React 页面
18
-
19
- 需要 Node.js 22.12 或更新版本。第一次安装会获取 React 19 和 Vite。
20
-
21
- ```sh
22
- cd react
23
- npm install reactive-md@0.3.0
24
- npm run dev
25
- ```
26
-
27
- 打开终端给出的本地地址,调整人数并观察费用变化。示例入口是 [react/main.jsx](react/main.jsx),库样式通过 `reactive-md/styles.css` 引入。
28
-
29
- 在源代码仓库根目录执行 `npm run test:packed`,可自动验证压缩包的独立离线安装、严格类型检查和 React 静态服务端渲染。API 与宿主策略见[集成说明](../../docs/local-integration.md)。
1
+ # Standalone integration examples
2
+
3
+ These directories use the package's public entry points and can be copied outside the repository. The commands below start from the current directory.
4
+
5
+ These examples target `0.4.0`, the preview release on the `next` channel. First run `npm pack` in the repository, then copy the desired example directory outside the repository. In each command below, replace `/path/to/reactive-md-0.4.0.tgz` with the tarball's absolute path. The install uses the built package; React and Vite are installed from the example's own dependencies where needed.
6
+
7
+ ## Node core
8
+
9
+ Requires Node.js 22.12 or newer. The core example needs no React and makes no network requests.
10
+
11
+ ```sh
12
+ cd core
13
+ npm install /path/to/reactive-md-0.4.0.tgz --ignore-scripts --no-audit --no-fund
14
+ npm start
15
+ ```
16
+
17
+ It should print `People: 2, cost: 200` first, then `People: 5, cost: 500`. The source is in [core/index.mjs](core/index.mjs).
18
+
19
+ The core and worker examples use host APIs added in the `0.4.0` preview.
20
+
21
+ ## React page
22
+
23
+ Requires Node.js 22.12 or newer. The first install fetches React 19 and Vite.
24
+
25
+ ```sh
26
+ cd react
27
+ npm install /path/to/reactive-md-0.4.0.tgz
28
+ npm run dev
29
+ ```
30
+
31
+ Open the local URL printed by the terminal, adjust the headcount and watch the cost change. The example entry is [react/main.jsx](react/main.jsx), and the library styles are imported through `reactive-md/styles.css`.
32
+
33
+ ## Worker compilation
34
+
35
+ [worker](worker) is a copyable browser page that keeps compilation off the main thread. It debounces edits, compiles in a module Worker, and falls back to the main thread when a Worker cannot start or crashes.
36
+
37
+ ```sh
38
+ cd worker
39
+ npm install /path/to/reactive-md-0.4.0.tgz
40
+ npm run dev
41
+ ```
42
+
43
+ The UI and scheduler wiring live in [worker/main.js](worker/main.js); the Worker entry is [worker/worker.js](worker/worker.js).
44
+
45
+ From the source repository root, `npm run verify:release` runs the complete gate, including standalone offline installation from the packed tarball, strict type checking, combined-feature checks, React rendering and HTML export. Use `npm run test:packed` for the focused package check after building. See the [integration guide](../../docs/local-integration-en.md) for the API and host policies.
@@ -1,19 +1,32 @@
1
- import { compileLocal, createLocalRuntime, LOCAL_SYNTAX_VERSION } from 'reactive-md';
2
-
3
- const source = `<number bind="people" label="人数" initial="2" min="1" max="20">
4
-
5
- 人数:{{ people }},费用:{{ people * 100 }}`;
6
- const result = compileLocal(source);
7
- if (!result.ok) throw new Error(JSON.stringify(result.diagnostics));
8
-
9
- console.log(`Syntax: ${LOCAL_SYNTAX_VERSION}`);
10
- const runtime = createLocalRuntime(result.document);
11
- try {
12
- const print = () => console.log(runtime.text('人数:{{ people }},费用:{{ people * 100 }}'));
13
- print();
14
- const people = result.document.nodes.find(node => node.name === 'number');
15
- if (!people) throw new Error('The example input was not compiled.');
16
- const diagnostics = runtime.set(people, 5);
17
- if (diagnostics.length) throw new Error(JSON.stringify(diagnostics));
18
- print();
19
- } finally { runtime.dispose(); }
1
+ import {
2
+ compileLocal,
3
+ createLocalRuntime,
4
+ exportLocalState,
5
+ importLocalState,
6
+ LOCAL_SYNTAX_VERSION,
7
+ } from 'reactive-md';
8
+
9
+ const source = `<number bind="people" label="People" initial="2" min="1" max="20">
10
+
11
+ People: {{ people }}, cost: {{ people * 100 }}`;
12
+ const result = compileLocal(source);
13
+ if (!result.ok) throw new Error(JSON.stringify(result.diagnostics));
14
+
15
+ console.log(`Syntax: ${LOCAL_SYNTAX_VERSION}`);
16
+ const runtime = createLocalRuntime(result.document);
17
+ try {
18
+ const print = () => console.log(runtime.text('People: {{ people }}, cost: {{ people * 100 }}'));
19
+ print();
20
+ console.log(`People parameter: ${runtime.getParameter('people')}`);
21
+
22
+ const diagnostics = runtime.setParameters({ people: 5 });
23
+ if (diagnostics.length) throw new Error(JSON.stringify(diagnostics));
24
+ print();
25
+
26
+ const file = exportLocalState(runtime, { name: 'reactive-md-core-example', version: '1' });
27
+ runtime.setParameter('people', 1);
28
+ const imported = importLocalState(runtime, JSON.stringify(file));
29
+ if (imported.length) throw new Error(JSON.stringify(imported));
30
+ print();
31
+ console.log(`State: ${file.format}, document ${file.sourceDigest}`);
32
+ } finally { runtime.dispose(); }
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html lang="zh-CN">
2
+ <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -3,14 +3,14 @@ import { createRoot } from 'react-dom/client';
3
3
  import { LocalReactiveDocument } from 'reactive-md/react';
4
4
  import 'reactive-md/styles.css';
5
5
 
6
- const source = `# 费用估算
6
+ const source = `# Cost estimate
7
7
 
8
- <panel title="调整方案">
9
- <slider bind="people" label="人数" initial="2" min="1" max="20">
10
- <toggle bind="annual" label="年度付款">
8
+ <panel title="Adjust the plan">
9
+ <slider bind="people" label="People" initial="2" min="1" max="20">
10
+ <toggle bind="annual" label="Annual billing">
11
11
  </panel>
12
12
 
13
- 每月费用:**{{ people * (annual ? 80 : 100) }} 元**。`;
13
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
14
14
 
15
15
  createRoot(document.getElementById('root')).render(
16
16
  <React.StrictMode>
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Reactive MD worker compilation</title>
7
+ </head>
8
+ <body>
9
+ <main>
10
+ <h1>Worker compilation</h1>
11
+ <p>Edit the source; compilation is debounced and runs in a module Worker, falling back to the main thread if needed.</p>
12
+ <textarea id="source" rows="12" cols="80" spellcheck="false"></textarea>
13
+ <p id="status">Starting...</p>
14
+ <pre id="diagnostics"></pre>
15
+ <pre id="preview"></pre>
16
+ </main>
17
+ <script type="module" src="/main.js"></script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,61 @@
1
+ import { LocalCompileScheduler } from 'reactive-md';
2
+
3
+ const editor = document.getElementById('source');
4
+ const status = document.getElementById('status');
5
+ const diagnostics = document.getElementById('diagnostics');
6
+ const preview = document.getElementById('preview');
7
+
8
+ const initialSource = `# Compile in a Worker
9
+
10
+ Edits are compiled off the main thread after a short debounce. Keep typing and the status below updates.
11
+
12
+ <slider bind="people" label="People" min="1" max="20">`;
13
+
14
+ editor.value = initialSource;
15
+
16
+ function createWorker() {
17
+ return new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
18
+ }
19
+
20
+ function formatDiagnostics(list) {
21
+ return list.length
22
+ ? list.map((diagnostic) => `${diagnostic.line}:${diagnostic.column} ${diagnostic.code}: ${diagnostic.message}`).join('\n')
23
+ : 'No diagnostics.';
24
+ }
25
+
26
+ function showResult(outcome) {
27
+ const { result, duration, mode } = outcome;
28
+ status.textContent = `Compiled in ${duration} ms (${mode})`;
29
+ diagnostics.textContent = formatDiagnostics(result.diagnostics);
30
+ if (!result.ok) {
31
+ preview.textContent = 'No document';
32
+ return;
33
+ }
34
+ const heading = result.document.nodes.find((node) => node.type === 'heading');
35
+ const title = heading
36
+ ? (heading.children ?? []).map((child) => child.value ?? '').join('') || 'Untitled'
37
+ : 'Untitled';
38
+ const bindings = Object.keys(result.document.bindings);
39
+ preview.textContent = [
40
+ `Title: ${title}`,
41
+ `Nodes: ${result.document.nodes.length}`,
42
+ `Bindings: ${bindings.length ? bindings.join(', ') : 'none'}`,
43
+ ].join('\n');
44
+ }
45
+
46
+ const scheduler = new LocalCompileScheduler({
47
+ createWorker,
48
+ onResult: showResult,
49
+ onPendingChange: (pending) => {
50
+ if (pending) status.textContent = 'Compiling...';
51
+ },
52
+ onModeChange: (mode, detail) => {
53
+ status.textContent = mode === 'worker'
54
+ ? 'Compiling in a Worker...'
55
+ : `Compiling on the main thread${detail ? ` (${detail})` : ''}`;
56
+ },
57
+ });
58
+
59
+ editor.addEventListener('input', () => scheduler.schedule(editor.value));
60
+ window.addEventListener('beforeunload', () => scheduler.dispose());
61
+ scheduler.schedule(editor.value);
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "reactive-md-worker-example",
3
+ "private": true,
4
+ "type": "module",
5
+ "engines": { "node": ">=22.12.0" },
6
+ "scripts": {
7
+ "dev": "vite --host 127.0.0.1",
8
+ "build": "vite build",
9
+ "preview": "vite preview --host 127.0.0.1"
10
+ },
11
+ "dependencies": { "reactive-md": "^0.4.0" },
12
+ "devDependencies": { "vite": "^8.3.5" }
13
+ }
@@ -0,0 +1,3 @@
1
+ import { startLocalCompileWorker } from 'reactive-md';
2
+
3
+ startLocalCompileWorker();
@@ -1,66 +1,72 @@
1
- # 本地交互语法 Demo
2
-
3
- 这些文件是 `local-draft-1` 的完整作者示例,对应 [本地交互语法规范](../../docs/local-interaction-syntax.md)。第一次接触语法时,先读 [新用户入门指南](../../docs/local-guide.md)。Playground 直接加载本目录;宿主通过 [本地模式 API](../../docs/local-integration.md) 编译和渲染。
4
-
5
- 本目录有 11 份正常示例、1 份故意含错的诊断示例。每份文件独立使用,不共享参数。正常示例均没有 YAML 配置、命名动作、事件处理或外部调用。
6
-
7
- ## 从短示例开始
8
-
9
- 建议先看 [计数器](counter.reactive.md)、[方案计算器](pricing.reactive.md) 和 [交互图解](diagram.reactive.md),再看较长的图表与参数面板。日常写作只需用到其中少数组件。
10
-
11
- ## 完整目录
12
-
13
- | 文件 | 内容 |
14
- | --- | --- |
15
- | [counter.reactive.md](counter.reactive.md) | 一行计数器,自带加、减和重置 |
16
- | [pricing.reactive.md](pricing.reactive.md) | 方案计算器,面板内参数联动 |
17
- | [comparison.reactive.md](comparison.reactive.md) | 并排比较,开关就地声明,标签页内部管理选择 |
18
- | [parameters.reactive.md](parameters.reactive.md) | 实时参数面板,含输入、日期和选择器 |
19
- | [checklist.reactive.md](checklist.reactive.md) | 固定可勾选清单与增强表格 |
20
- | [charts.reactive.md](charts.reactive.md) | 表格生成图表,复利公式使用 LaTeX |
21
- | [diagram.reactive.md](diagram.reactive.md) | 自动布局的交互图解与曲线 |
22
- | [catalog.reactive.md](catalog.reactive.md) | 本地目录搜索、排序和分页 |
23
- | [planning.reactive.md](planning.reactive.md) | 时间轴、计时器与分账计算 |
24
- | [components.reactive.md](components.reactive.md) | 内容卡片、折叠、标签页与提示组件 |
25
- | [gallery.reactive.md](gallery.reactive.md) | 常用输入、独立组件和原样代码 |
26
- | [diagnostics.reactive.md](diagnostics.reactive.md) | 故意含错的诊断示例 |
27
-
28
- Playground 的示例索引位于仓库中的 [demo/src/examples.ts](https://github.com/yao1145/ReactiveMD/blob/main/demo/src/examples.ts)。
29
-
30
- ## 正常示例的预期行为
31
-
32
- 下表列出每份文档的初值与交互验收点。数值按正文公式计算。
33
-
34
- | 示例 | 初始显示 | 交互检查 |
35
- | --- | --- | --- |
36
- | comparison | 基础 100 元,专业 200 元 | 开启年度付款变为 80/160;切换标签页不用声明变量;恢复默认回到月付 |
37
- | parameters | 日期 2026-10-22,个人使用,称呼未填 | 输入称呼更新卡片;选择团队更新说明;勾选开关显示准备清单;面板重置恢复字段和开关 |
38
- | checklist | 1/3 项,进度约 33.33% | 全选后显示完成提示;重置恢复仅第一项勾选;表格按价格排序、搜索和分页 |
39
- | charts | 4 组预算比较;储蓄参数 10000、500、5%、20 年;方案柱高 40/70 | 利率调为 0 时曲线终点为 130000;默认复利终点约 232643.24;人数调为 5 时柱高 100/175 |
40
- | diagram | 选中输入节点,a=1、f=1 | 点击计算节点更新详情和正文;a=0 时曲线变平并出现提示;两条固定曲线同时显示 |
41
- | catalog | 8 行目录,每页 4 行 | 搜索“视觉”得到 chart/plot/diagram;无匹配显示空态;恢复默认清空查询、排序和页码 |
42
- | planning | 45 分钟时间轴,倒计时暂停在 60 秒,每人 88 元 | timer 开始/暂停/重置;额外费用改为 0 时每人 80 元;开始 15 的参考任务与主体时间重叠 |
43
- | components | 简洁说明,首个折叠项展开 | 选择详细后切换正文;提示可用键盘聚焦;其他折叠项独立展开 |
44
- | pricing | 2 人,每人 100 元,合计 200 元 | 年付后 160 元;年付 5 人为 400 元且显示团队提示;重置回到 200 元 |
45
- | counter | 0 | 连续加三次显示 3;减三次回到 0 后禁用减号;重置回到 0 |
46
- | gallery | 小林、数量 3、专业版、月付,费用 240 元 | 年付后 192 元;加急区隐藏再出现保留勾选;独立计数器和计时器无需 bind;代码中的 example 不生成变量 |
47
-
48
- parameters 中条件清单位于面板外:它的已有勾选在隐藏后保留,不属于该面板的重置范围。gallery 的独立计数器与计时器也位于输入面板外,输入面板重置不影响它们。
49
-
50
- ## 诊断示例的预期结果
51
-
52
- [diagnostics.reactive.md](diagnostics.reactive.md) 故意包含以下 9 类错误。编辑器应收集可恢复的独立诊断,文件整体不能激活交互。
53
-
54
- 1. `seat` 未声明,可提示已有参数 `seats`。
55
- 2. `seats` 的显式 initial 重复,指出两处来源。
56
- 3. `ratio` 初值 12 超过最大值 10。
57
- 4. if.when 的 `seats` 为数字,要求布尔值。
58
- 5. `slidr` 是未知组件,可提示 slider。
59
- 6. `on-click` 不属于 counter,也不属于本地交互事件语法。
60
- 7. edge 的目标 `missing` 不存在。
61
- 8. 积分可以显示,但不属于首版绘图的可计算结构。
62
- 9. 图表费用列的 `20 元` 是文本,需要纯数值。
63
-
64
- ## 检查入口
65
-
66
- `npm test` 检查解析、绑定、表达式、LaTeX、运行时和示例;`npm run test:demo` 检查 Playground 索引;启动应用后用 `npm run test:browser` 检查实际交互。`npm run test:docs` 检查文档链接。实际运行结果见[仓库实现说明](https://github.com/yao1145/ReactiveMD/blob/main/demo/IMPLEMENTATION.md)。
1
+ # Local interaction syntax demo
2
+
3
+ These are standalone authoring examples for `local-draft-2`, described in the [local interaction syntax specification](../../docs/local-interaction-syntax-en.md). The Playground starts with a [quick calculator](pricing.reactive.md), followed by six focused [feature tours](showcase/README.md). Components are distributed across these six scenarios; diagnostics has an auxiliary menu. Hosts can compile and render every document through the [local mode API](../../docs/local-integration-en.md).
4
+
5
+ The original eleven working examples and one intentionally broken diagnostics document remain in this directory, with Chinese versions in [zh/](zh/). The six feature tours live in [showcase/](showcase/README.md), with Chinese sources in [showcase/zh/](showcase/zh/). Each file runs independently. Controls, expressions and visualizations use local state.
6
+
7
+ ## Start with the short examples
8
+
9
+ The [workshop recipe](recipes/workshop.reactive.md) ([中文](recipes/workshop-zh.reactive.md)) combines cross-field validation, conditional tones, numeric aggregates and generated table rows. See the [constraints and collections reference](../../docs/constraints-collections-en.md) for rules and budgets.
10
+
11
+ The [invoice recipe](recipes/invoice.reactive.md) ([中文](recipes/invoice-zh.reactive.md)) demonstrates shared calculations, constants, formatting and UTC date differences. The [calculation reference](../../docs/computations-formatting-en.md) explains its rules.
12
+
13
+ Start with the [plan calculator](pricing.reactive.md), then choose a [feature tour](showcase/README.md). For the smallest possible state example, read the original [counter](counter.reactive.md). If you are new to the syntax, read the [new user guide](../../docs/local-guide-en.md).
14
+
15
+ ## Original standalone catalog
16
+
17
+ | File | Contents |
18
+ | --- | --- |
19
+ | [counter.reactive.md](counter.reactive.md) | One-line counter with built-in plus, minus and reset |
20
+ | [pricing.reactive.md](pricing.reactive.md) | Plan calculator with parameters linked inside a panel |
21
+ | [comparison.reactive.md](comparison.reactive.md) | Side-by-side comparison, a switch declared in place, tabs that manage their own selection |
22
+ | [parameters.reactive.md](parameters.reactive.md) | Live parameter panel with text, date and choice inputs |
23
+ | [checklist.reactive.md](checklist.reactive.md) | Fixed checkable list and an enhanced table |
24
+ | [charts.reactive.md](charts.reactive.md) | Charts built from tables, with a compound-interest formula in LaTeX |
25
+ | [diagram.reactive.md](diagram.reactive.md) | Auto-laid-out interactive diagram and curves |
26
+ | [catalog.reactive.md](catalog.reactive.md) | Local catalog search, sorting and paging |
27
+ | [planning.reactive.md](planning.reactive.md) | Timeline, timer and bill-splitting calculation |
28
+ | [components.reactive.md](components.reactive.md) | Content cards, disclosures, tabs and hint components |
29
+ | [gallery.reactive.md](gallery.reactive.md) | Common inputs, standalone components and code shown as-is |
30
+ | [diagnostics.reactive.md](diagnostics.reactive.md) | Intentionally broken diagnostics example |
31
+
32
+ The Playground example index is maintained in the repository's demo application.
33
+
34
+ ## Expected behavior of the working examples
35
+
36
+ The table below lists the initial values and interaction checkpoints for each document. Numbers follow the formulas in the prose.
37
+
38
+ | Example | Initial display | Interaction checks |
39
+ | --- | --- | --- |
40
+ | comparison | Basic 100 USD, Pro 200 USD | Annual billing changes them to 80/160; switching tabs needs no declared variable; reset returns to monthly billing |
41
+ | parameters | Date 2026-10-22, personal use, name empty | Entering a name updates the card; selecting team use updates the description; checking the switch shows the preparation checklist; panel reset restores fields and switches |
42
+ | checklist | 1/3 items, progress about 33.33% | Selecting all shows the completion notice; reset restores only the first item; the table sorts by price, searches and pages |
43
+ | charts | 4 budget comparisons; savings parameters 10000, 500, 5%, 20 years; plan bars 40/70 | With the rate at 0 the end-of-curve readout is 130000; the default compound readout is about 232643.24; with 5 people the bars are 100/175 |
44
+ | diagram | Input node selected, a=1, f=1 | Clicking the compute node updates the details and prose; at a=0 the curve flattens and a notice appears; both fixed curves are shown together |
45
+ | catalog | 8 catalog rows, 4 rows per page | Searching for "visual" returns chart/plot/diagram; no match shows the empty state; reset clears the query, sorting and page |
46
+ | planning | 45-minute timeline, countdown paused at 60 seconds, 88 USD per person | timer start/pause/reset; with the extra charge at 0 each person pays 80 USD; the reference task starting at 15 overlaps the main section |
47
+ | components | Concise explanation, first disclosure open | Selecting detailed switches the prose; the tooltip is keyboard-focusable; other disclosures open independently |
48
+ | pricing | 2 people, 100 USD each, 200 USD total | Annual billing gives 160 USD; annual billing for 5 people is 400 USD and shows the team notice; reset returns to 200 USD |
49
+ | counter | 0 | Three increments show 3; three decrements return to 0 and disable minus; reset returns to 0 |
50
+ | gallery | Alex, quantity 3, Pro, monthly billing, cost 240 USD | Annual billing gives 192 USD; hiding and showing the express section keeps its checks; the standalone counter and timer need no bind; `example` in the code block creates no variable |
51
+
52
+ In parameters, the conditional checklist sits outside the panel: its existing checks survive hiding and are outside that panel's reset scope. The standalone counter and timer in gallery also sit outside the input panel, so resetting the input panel does not affect them.
53
+
54
+ ## Expected results of the diagnostics example
55
+
56
+ [diagnostics.reactive.md](diagnostics.reactive.md) intentionally contains the following 9 error classes. The editor should collect recoverable, independent diagnostics, and the document as a whole must not activate interactions.
57
+
58
+ 1. `seat` is not declared; the message can suggest the existing parameter `seats`.
59
+ 2. `seats` has a duplicate explicit initial; both sources are reported.
60
+ 3. `ratio` has initial value 12, above the maximum 10.
61
+ 4. if.when receives `seats`, a number, where a boolean is required.
62
+ 5. `slidr` is an unknown component; the message can suggest `slider`.
63
+ 6. `on-click` is not part of counter or the local interaction event syntax.
64
+ 7. The edge target `missing` does not exist.
65
+ 8. The integral can be displayed but is not a computable structure in the first plot version.
66
+ 9. The chart's cost column contains `20 USD`, text where a plain number is required.
67
+
68
+ ## Check entry points
69
+
70
+ `npm test` checks parsing, bindings, expressions, LaTeX, the runtime and examples; `npm run test:demo` checks the Playground index; `npm run verify:release` runs the complete Node-side and browser gate, including real-tarball consumption and HTML export. See the [contributing guide](../../CONTRIBUTING.md) for individual commands.
71
+
72
+ The [six scenarios](showcase/README.md) include all 48 tag names: intervals, coordinates and numeric questions in Functions; input choices in Forms; linked selection in Data; jumps and prose colors in Layout; guided steps and choice questions in Flow; todos and timing in Checklists. The standalone gallery and interaction-tour sources remain available as authoring examples.