reactive-md 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG-ch.md +113 -0
  2. package/CHANGELOG.md +113 -53
  3. package/CONTRIBUTING-ch.md +62 -0
  4. package/CONTRIBUTING.md +64 -65
  5. package/LICENSE +21 -21
  6. package/README-ch.md +123 -0
  7. package/README-en.md +147 -0
  8. package/README.md +96 -38
  9. package/SECURITY-ch.md +80 -0
  10. package/SECURITY.md +58 -49
  11. package/THIRD_PARTY_NOTICES.md +85 -1
  12. package/bin/reactive-md.mjs +40 -0
  13. package/cli/args.mjs +181 -0
  14. package/cli/assets.mjs +390 -0
  15. package/cli/build.mjs +268 -0
  16. package/cli/document.mjs +130 -0
  17. package/cli/errors.mjs +61 -0
  18. package/cli/fs-utils.mjs +133 -0
  19. package/cli/glob.mjs +203 -0
  20. package/cli/help.mjs +138 -0
  21. package/cli/lint.mjs +177 -0
  22. package/cli/main.mjs +55 -0
  23. package/cli/migrate.mjs +368 -0
  24. package/cli/package.mjs +209 -0
  25. package/dist-library/reactive-md-react.js +3525 -1651
  26. package/dist-library/reactive-md.css +1 -1
  27. package/dist-library/reactive-md.js +1798 -4
  28. package/dist-library/runtime-D3QTVYaz.js +15410 -0
  29. package/dist-library/types/index.d.ts +1 -0
  30. package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
  31. package/dist-library/types/local/authoring.d.ts +63 -0
  32. package/dist-library/types/local/collection-functions.d.ts +4 -0
  33. package/dist-library/types/local/colors.d.ts +2 -0
  34. package/dist-library/types/local/computations.d.ts +53 -0
  35. package/dist-library/types/local/data-functions.d.ts +22 -0
  36. package/dist-library/types/local/data-table.d.ts +65 -0
  37. package/dist-library/types/local/dates.d.ts +2 -0
  38. package/dist-library/types/local/dependencies.d.ts +31 -0
  39. package/dist-library/types/local/diagnostics.d.ts +1450 -0
  40. package/dist-library/types/local/expression.d.ts +13 -3
  41. package/dist-library/types/local/formatting.d.ts +41 -0
  42. package/dist-library/types/local/heading-anchors.d.ts +13 -2
  43. package/dist-library/types/local/i18n.d.ts +18 -0
  44. package/dist-library/types/local/index.d.ts +18 -1
  45. package/dist-library/types/local/limits.d.ts +32 -1
  46. package/dist-library/types/local/locale.d.ts +1 -0
  47. package/dist-library/types/local/math.d.ts +6 -1
  48. package/dist-library/types/local/parser.d.ts +10 -4
  49. package/dist-library/types/local/render-types.d.ts +5 -1
  50. package/dist-library/types/local/retention.d.ts +23 -0
  51. package/dist-library/types/local/schema.d.ts +25 -3
  52. package/dist-library/types/local/source-migration.d.ts +35 -0
  53. package/dist-library/types/local/state.d.ts +80 -0
  54. package/dist-library/types/local/text-length.d.ts +13 -0
  55. package/dist-library/types/local/theme.d.ts +30 -0
  56. package/dist-library/types/local/types.d.ts +112 -4
  57. package/dist-library/types/local/validation.d.ts +32 -0
  58. package/dist-library/types/local/version.d.ts +1 -1
  59. package/dist-library/types/local/worker.d.ts +82 -0
  60. package/dist-library/types/react/index.d.ts +4 -1
  61. package/dist-library/types/shareable.d.ts +64 -0
  62. package/dist-standalone/reactive-md-standalone.css +2 -0
  63. package/dist-standalone/reactive-md-standalone.js +57 -0
  64. package/docs/author-tools-ch.md +56 -0
  65. package/docs/author-tools-en.md +56 -0
  66. package/docs/compatibility-ch.md +103 -0
  67. package/docs/compatibility-en.md +103 -0
  68. package/docs/{component-development.md → component-development-ch.md} +210 -206
  69. package/docs/component-development-en.md +210 -0
  70. package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
  71. package/docs/component-protocol-en.md +710 -0
  72. package/docs/computations-formatting-ch.md +87 -0
  73. package/docs/computations-formatting-en.md +87 -0
  74. package/docs/constraints-collections-ch.md +84 -0
  75. package/docs/constraints-collections-en.md +84 -0
  76. package/docs/diagnostics-counting-ch.md +84 -0
  77. package/docs/diagnostics-counting-en.md +84 -0
  78. package/docs/local-components-v2-ch.md +138 -0
  79. package/docs/local-components-v2-en.md +104 -0
  80. package/docs/{local-guide.md → local-guide-ch.md} +28 -8
  81. package/docs/local-guide-en.md +961 -0
  82. package/docs/local-integration-ch.md +363 -0
  83. package/docs/local-integration-en.md +363 -0
  84. package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
  85. package/docs/local-interaction-syntax-en.md +483 -0
  86. package/docs/{performance.md → performance-ch.md} +12 -3
  87. package/docs/performance-en.md +76 -0
  88. package/docs/release-0.4.0-ch.md +89 -0
  89. package/docs/release-0.4.0-en.md +89 -0
  90. package/docs/release-0.4.1-ch.md +23 -0
  91. package/docs/release-0.4.1-en.md +23 -0
  92. package/docs/releasing-ch.md +101 -0
  93. package/docs/releasing-en.md +101 -0
  94. package/docs/shareable-export-ch.md +205 -0
  95. package/docs/shareable-export-en.md +207 -0
  96. package/docs/source-versioning-ch.md +159 -0
  97. package/docs/source-versioning-en.md +159 -0
  98. package/docs/theme-protocol-ch.md +107 -0
  99. package/docs/theme-protocol-en.md +107 -0
  100. package/examples/conformance/README.md +33 -31
  101. package/examples/conformance/component-protocol-1.json +482 -194
  102. package/examples/conformance/component-protocol-1.schema.json +76 -76
  103. package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
  104. package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
  105. package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
  106. package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
  107. package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
  108. package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
  109. package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
  110. package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
  111. package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
  112. package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
  113. package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
  114. package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
  115. package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
  116. package/examples/conformance/history/v0.3.1/provenance.json +72 -0
  117. package/examples/conformance/local-draft-2.json +212 -0
  118. package/examples/integration/README.md +45 -29
  119. package/examples/integration/core/index.mjs +32 -19
  120. package/examples/integration/core/package.json +7 -7
  121. package/examples/integration/react/index.html +12 -12
  122. package/examples/integration/react/main.jsx +21 -21
  123. package/examples/integration/react/package.json +9 -9
  124. package/examples/integration/worker/index.html +19 -0
  125. package/examples/integration/worker/main.js +61 -0
  126. package/examples/integration/worker/package.json +13 -0
  127. package/examples/integration/worker/worker.js +3 -0
  128. package/examples/local/README.md +64 -58
  129. package/examples/local/catalog.reactive.md +20 -20
  130. package/examples/local/charts.reactive.md +34 -34
  131. package/examples/local/checklist.reactive.md +32 -32
  132. package/examples/local/comparison.reactive.md +47 -47
  133. package/examples/local/components.reactive.md +44 -44
  134. package/examples/local/counter.reactive.md +7 -7
  135. package/examples/local/diagnostics.reactive.md +54 -54
  136. package/examples/local/diagram.reactive.md +44 -44
  137. package/examples/local/gallery.reactive.md +61 -61
  138. package/examples/local/parameters.reactive.md +36 -36
  139. package/examples/local/planning.reactive.md +24 -24
  140. package/examples/local/pricing.reactive.md +20 -20
  141. package/examples/local/recipes/invoice-zh.reactive.md +36 -0
  142. package/examples/local/recipes/invoice.reactive.md +36 -0
  143. package/examples/local/recipes/workshop-zh.reactive.md +33 -0
  144. package/examples/local/recipes/workshop.reactive.md +33 -0
  145. package/examples/local/showcase/README.md +25 -0
  146. package/examples/local/showcase/explore.reactive.md +102 -0
  147. package/examples/local/showcase/flow.reactive.md +86 -0
  148. package/examples/local/showcase/forms.reactive.md +126 -0
  149. package/examples/local/showcase/functions.reactive.md +119 -0
  150. package/examples/local/showcase/layout.reactive.md +100 -0
  151. package/examples/local/showcase/statistics.reactive.md +108 -0
  152. package/examples/local/showcase/tasks.reactive.md +89 -0
  153. package/examples/local/showcase/zh/explore.reactive.md +102 -0
  154. package/examples/local/showcase/zh/flow.reactive.md +86 -0
  155. package/examples/local/showcase/zh/forms.reactive.md +126 -0
  156. package/examples/local/showcase/zh/functions.reactive.md +119 -0
  157. package/examples/local/showcase/zh/layout.reactive.md +100 -0
  158. package/examples/local/showcase/zh/statistics.reactive.md +108 -0
  159. package/examples/local/showcase/zh/tasks.reactive.md +89 -0
  160. package/examples/local/zh/catalog.reactive.md +20 -0
  161. package/examples/local/zh/charts.reactive.md +73 -0
  162. package/examples/local/zh/checklist.reactive.md +32 -0
  163. package/examples/local/zh/comparison.reactive.md +47 -0
  164. package/examples/local/zh/components.reactive.md +44 -0
  165. package/examples/local/zh/counter.reactive.md +7 -0
  166. package/examples/local/zh/diagnostics.reactive.md +54 -0
  167. package/examples/local/zh/diagram.reactive.md +44 -0
  168. package/examples/local/zh/gallery.reactive.md +61 -0
  169. package/examples/local/zh/parameters.reactive.md +36 -0
  170. package/examples/local/zh/planning.reactive.md +24 -0
  171. package/examples/local/zh/pricing.reactive.md +20 -0
  172. package/package.json +91 -77
  173. package/README.en.md +0 -76
  174. package/dist-library/runtime-CPzMEMcW.js +0 -11111
  175. package/docs/compatibility.md +0 -68
  176. package/docs/local-integration.md +0 -218
  177. package/docs/releasing.md +0 -92
@@ -0,0 +1,20 @@
1
+ # 方案计算器
2
+
3
+ 调整人数和付款方式,比较每月平均费用。每人每月 100 元,年度付款享受八折。
4
+
5
+ <panel title="你的方案">
6
+ <slider bind="seats" label="人数" initial="2" min="1" max="20">
7
+ <toggle bind="annual" label="年度付款">
8
+ </panel>
9
+
10
+ 当前人数:**{{ seats }}**。
11
+
12
+ 每人每月:**{{ annual ? 80 : 100 }} 元**。
13
+
14
+ 每月合计:**{{ seats * (annual ? 80 : 100) }} 元**。
15
+
16
+ <if when="{{ seats >= 5 }}">
17
+ <alert title="团队方案">
18
+ 你选择了至少 5 人,可以继续切换付款方式比较费用。
19
+ </alert>
20
+ </if>
@@ -0,0 +1,72 @@
1
+ {
2
+ "tag": "v0.3.1",
3
+ "commit": "bdfc98bd914058df5093a1c02123ad11a9ebe207",
4
+ "syntaxVersion": "local-draft-1",
5
+ "files": [
6
+ {
7
+ "file": "local-draft-1.json",
8
+ "sourcePath": "examples/conformance/local-draft-1.json",
9
+ "sha256": "7d736ebf325f2a9c392cb44fd6edd85db2b4cff91bf8999fc8f431f9f61e55eb"
10
+ },
11
+ {
12
+ "file": "catalog.reactive.md",
13
+ "sourcePath": "examples/local/catalog.reactive.md",
14
+ "sha256": "bfb6d8d29f695cb2139676f47892613003b01278e9987b145723d8150ed70b38"
15
+ },
16
+ {
17
+ "file": "charts.reactive.md",
18
+ "sourcePath": "examples/local/charts.reactive.md",
19
+ "sha256": "16f6711e3bab7b7dfe9f4ad10364b7bafca28109d7869693a331bd2f93579254"
20
+ },
21
+ {
22
+ "file": "checklist.reactive.md",
23
+ "sourcePath": "examples/local/checklist.reactive.md",
24
+ "sha256": "8f88f50c652d58e6410eab1a50885eb356219b0efe28f67e1a1fd605c12dba2c"
25
+ },
26
+ {
27
+ "file": "comparison.reactive.md",
28
+ "sourcePath": "examples/local/comparison.reactive.md",
29
+ "sha256": "a625b2b7ef1123e5a59528de3a3fd6aed87d46e5a6e55e2a5b6691644e351deb"
30
+ },
31
+ {
32
+ "file": "components.reactive.md",
33
+ "sourcePath": "examples/local/components.reactive.md",
34
+ "sha256": "b9f2e3fdc0752f8d85afafb87513eadf22fa64c3a2e504ec6ef104c310cf64a9"
35
+ },
36
+ {
37
+ "file": "counter.reactive.md",
38
+ "sourcePath": "examples/local/counter.reactive.md",
39
+ "sha256": "659955e5a3b42b8dacca4c6da9447bf6bfcb25e651496481c4855976f36b4820"
40
+ },
41
+ {
42
+ "file": "diagnostics.reactive.md",
43
+ "sourcePath": "examples/local/diagnostics.reactive.md",
44
+ "sha256": "315a65a5df2a1968cce320b1f1c096e2994c5c36a1bfd6f7bbb5ef5bec1903c5"
45
+ },
46
+ {
47
+ "file": "diagram.reactive.md",
48
+ "sourcePath": "examples/local/diagram.reactive.md",
49
+ "sha256": "7f356517d2ce13b740c46a917dac51f74471eb6e128d367f953c129958036635"
50
+ },
51
+ {
52
+ "file": "gallery.reactive.md",
53
+ "sourcePath": "examples/local/gallery.reactive.md",
54
+ "sha256": "33d854dcff496bd85454eb5fbb52f71ac2e906ef9cdedbca5abbf74d426aef5f"
55
+ },
56
+ {
57
+ "file": "parameters.reactive.md",
58
+ "sourcePath": "examples/local/parameters.reactive.md",
59
+ "sha256": "676cd75a58cfade9e265cefce204d1fd877cfcc3071d5c0b1b368eae0b0285e1"
60
+ },
61
+ {
62
+ "file": "planning.reactive.md",
63
+ "sourcePath": "examples/local/planning.reactive.md",
64
+ "sha256": "9c101147d8f0d61adbe12f422c6e2c8e141cfb8274922055cf5ebdaada329b0a"
65
+ },
66
+ {
67
+ "file": "pricing.reactive.md",
68
+ "sourcePath": "examples/local/pricing.reactive.md",
69
+ "sha256": "79746029d23a32b1eeeeffadb36aa82807fdaa7ce7808e57f3038d5616d595eb"
70
+ }
71
+ ]
72
+ }
@@ -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.1 --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.1
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,7 +1,7 @@
1
- {
2
- "name": "reactive-md-core-example",
3
- "private": true,
4
- "type": "module",
5
- "engines": { "node": ">=22.12.0" },
6
- "scripts": { "start": "node index.mjs" }
7
- }
1
+ {
2
+ "name": "reactive-md-core-example",
3
+ "private": true,
4
+ "type": "module",
5
+ "engines": { "node": ">=22.12.0" },
6
+ "scripts": { "start": "node index.mjs" }
7
+ }
@@ -1,12 +1,12 @@
1
- <!doctype html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Reactive MD integration</title>
7
- </head>
8
- <body>
9
- <div id="root"></div>
10
- <script type="module" src="/main.jsx"></script>
11
- </body>
12
- </html>
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 integration</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/main.jsx"></script>
11
+ </body>
12
+ </html>
@@ -1,21 +1,21 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { LocalReactiveDocument } from 'reactive-md/react';
4
- import 'reactive-md/styles.css';
5
-
6
- const source = `# 费用估算
7
-
8
- <panel title="调整方案">
9
- <slider bind="people" label="人数" initial="2" min="1" max="20">
10
- <toggle bind="annual" label="年度付款">
11
- </panel>
12
-
13
- 每月费用:**{{ people * (annual ? 80 : 100) }} 元**。`;
14
-
15
- createRoot(document.getElementById('root')).render(
16
- <React.StrictMode>
17
- <main style={{ padding: 24 }}>
18
- <LocalReactiveDocument source={source} />
19
- </main>
20
- </React.StrictMode>,
21
- );
1
+ import React from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import { LocalReactiveDocument } from 'reactive-md/react';
4
+ import 'reactive-md/styles.css';
5
+
6
+ const source = `# Cost estimate
7
+
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
+ </panel>
12
+
13
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
14
+
15
+ createRoot(document.getElementById('root')).render(
16
+ <React.StrictMode>
17
+ <main style={{ padding: 24 }}>
18
+ <LocalReactiveDocument source={source} />
19
+ </main>
20
+ </React.StrictMode>,
21
+ );
@@ -1,9 +1,9 @@
1
- {
2
- "name": "reactive-md-react-example",
3
- "private": true,
4
- "type": "module",
5
- "engines": { "node": ">=22.12.0" },
6
- "scripts": { "dev": "vite --host 127.0.0.1", "build": "vite build" },
7
- "dependencies": { "react": "^19.0.0", "react-dom": "^19.0.0" },
8
- "devDependencies": { "vite": "^8.3.5" }
9
- }
1
+ {
2
+ "name": "reactive-md-react-example",
3
+ "private": true,
4
+ "type": "module",
5
+ "engines": { "node": ">=22.12.0" },
6
+ "scripts": { "dev": "vite --host 127.0.0.1", "build": "vite build" },
7
+ "dependencies": { "react": "^19.0.0", "react-dom": "^19.0.0" },
8
+ "devDependencies": { "vite": "^8.3.5" }
9
+ }
@@ -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();