reactive-md 0.8.0 → 0.9.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 (441) hide show
  1. package/CHANGELOG-ch.md +54 -4
  2. package/CHANGELOG.md +55 -4
  3. package/CONTRIBUTING-ch.md +13 -2
  4. package/CONTRIBUTING.md +13 -2
  5. package/README-ch.md +132 -23
  6. package/README-en.md +130 -21
  7. package/README.md +128 -21
  8. package/SECURITY-ch.md +3 -3
  9. package/SECURITY.md +3 -3
  10. package/THIRD_PARTY_NOTICES.md +111 -1
  11. package/cli/args.mjs +51 -1
  12. package/cli/assets.mjs +6 -1
  13. package/cli/build.mjs +125 -9
  14. package/cli/fs-utils.mjs +3 -3
  15. package/cli/help.mjs +12 -5
  16. package/cli/init.mjs +1 -1
  17. package/cli/package.mjs +1 -0
  18. package/dist-library/LocalDocumentView-sthUP0ct.js +109 -0
  19. package/dist-library/LocalDocumentViewCore-GiWV3bey.js +9829 -0
  20. package/dist-library/LocalReactiveDocumentCore-ZjQSGyHE.js +275 -0
  21. package/dist-library/{authoring-BsfSwQRm.js → authoring-Dsune4Hy.js} +240 -218
  22. package/dist-library/compile-wUv8KEge.js +1249 -0
  23. package/dist-library/{compiler-core-kPiH-gOV.js → compiler-core-As_m-MNm.js} +5372 -5559
  24. package/dist-library/compiler-eOfcinZs.js +62 -0
  25. package/dist-library/component-state-BoLCGee4.js +801 -0
  26. package/dist-library/{component-state-D_cw_EHe.js → component-state-C52ZFJGl.js} +2 -2
  27. package/dist-library/{registry-B9Jc3FVe.js → config-BadfhjdP.js} +374 -457
  28. package/dist-library/{config-validation-DXTynAw7.js → config-validation-F47AcE6o.js} +549 -751
  29. package/dist-library/controls-CcT6n7k_.js +6740 -0
  30. package/dist-library/coordinate-CWS9p5q_.js +293 -0
  31. package/dist-library/data-table-Bgccxd7h.js +296 -0
  32. package/dist-library/{default-components-Z_YMio5P.js → default-components-BwQf0oP-.js} +344 -334
  33. package/dist-library/{math-display-BJz4gbFc.js → display-B-VhqVND.js} +1299 -1299
  34. package/dist-library/export-BqVmTXm8.js +369 -0
  35. package/dist-library/gallery-CY6mTx8i.js +360 -0
  36. package/dist-library/html-CNT4KD-2.js +757 -0
  37. package/dist-library/{math-sample-BGEW49zY.js → incremental-Dv0FSp_U.js} +476 -394
  38. package/dist-library/latex-1w7aQgD5.js +928 -0
  39. package/dist-library/layout-C0YlEPGr.js +562 -0
  40. package/dist-library/mount-preset-KxvtKgJb.js +13 -0
  41. package/dist-library/options-1aDLK7JY.js +121 -0
  42. package/dist-library/{react-ByOHunUW.js → package-core-WFK1RhAZ.js} +49 -55
  43. package/dist-library/{parser-standard-DlCk7sLo.js → parser-standard-Yuf3A_VI.js} +6605 -7097
  44. package/dist-library/plugin-packs-B1XPWcFs.js +18 -0
  45. package/dist-library/{identity-MYJXKSkB.js → preset-core-CKc5YXSM.js} +31 -31
  46. package/dist-library/{props-DGlBk0e5.js → props-sJ8vk0cr.js} +1 -1
  47. package/dist-library/react-BbyAgeXc.js +6070 -0
  48. package/dist-library/react-D5iGiUdL.js +7 -0
  49. package/dist-library/reactive-md-authoring.js +222 -223
  50. package/dist-library/reactive-md-build.js +126 -72
  51. package/dist-library/reactive-md-compiler-standard.js +12 -10
  52. package/dist-library/reactive-md-compiler.js +3 -3
  53. package/dist-library/reactive-md-default-packs.js +2 -2
  54. package/dist-library/reactive-md-default-preset.js +4 -4
  55. package/dist-library/reactive-md-export-assets.js +57 -0
  56. package/dist-library/reactive-md-export.js +5 -111
  57. package/dist-library/reactive-md-minimal-preset.js +24 -0
  58. package/dist-library/reactive-md-minimal-react-preset.js +26 -0
  59. package/dist-library/reactive-md-minimal-styles.js +80 -0
  60. package/dist-library/reactive-md-minimal.css +2 -0
  61. package/dist-library/reactive-md-pdf.js +7582 -0
  62. package/dist-library/reactive-md-plugin-chart.js +13 -0
  63. package/dist-library/reactive-md-plugin-data.js +17 -0
  64. package/dist-library/reactive-md-plugin-diagram.js +18 -0
  65. package/dist-library/reactive-md-plugin-forms.js +18 -0
  66. package/dist-library/reactive-md-plugin-gallery.js +12 -0
  67. package/dist-library/reactive-md-plugin-navigation.js +15 -0
  68. package/dist-library/reactive-md-plugin-network.js +222 -0
  69. package/dist-library/reactive-md-plugin-plot.js +24 -0
  70. package/dist-library/reactive-md-print.css +5 -0
  71. package/dist-library/reactive-md-react-minimal.js +28 -0
  72. package/dist-library/reactive-md-react-server.js +34 -32
  73. package/dist-library/reactive-md-react-unstyled.js +14 -9
  74. package/dist-library/reactive-md-react.js +14 -9
  75. package/dist-library/reactive-md-runtime-browser.js +847 -15
  76. package/dist-library/reactive-md-runtime.js +3 -3
  77. package/dist-library/reactive-md-sdk.js +8 -6
  78. package/dist-library/reactive-md-standalone-configured.js +16 -0
  79. package/dist-library/reactive-md-standalone-host.js +9 -438
  80. package/dist-library/reactive-md-testing-browser.js +5 -4
  81. package/dist-library/reactive-md-testing-react.js +46 -44
  82. package/dist-library/reactive-md-testing.js +45 -44
  83. package/dist-library/reactive-md-vite.js +135 -37
  84. package/dist-library/reactive-md.css +1 -1
  85. package/dist-library/reactive-md.js +590 -498
  86. package/dist-library/registry-B9NGct4d.js +20 -0
  87. package/dist-library/registry-core-Bbad9Bm2.js +479 -0
  88. package/dist-library/{resources-BGt8mpDA.js → resources-D2GDQS0p.js} +45 -45
  89. package/dist-library/{runtime-Dkq7ldyg.js → runtime-B2fxeveq.js} +1 -1
  90. package/dist-library/runtime-kcA7bG7G.js +1282 -0
  91. package/dist-library/sample-bP4zHB3L.js +289 -0
  92. package/dist-library/{schema-ZFufO8V0.js → schema-BufhKUSM.js} +12 -11
  93. package/dist-library/sdk-core-BoJT1SIt.js +1166 -0
  94. package/dist-library/session-core-nmJHuR9c.js +452 -0
  95. package/dist-library/{shareable-DDVL4Fi9.js → shareable-DpbE-59H.js} +250 -283
  96. package/dist-library/tooltip-layer-HDLrSWs0.js +28 -0
  97. package/dist-library/types/authoring/catalog.d.ts +2 -3
  98. package/dist-library/types/authoring/editor-i18n.d.ts +1 -1
  99. package/dist-library/types/authoring/index.d.ts +1 -1
  100. package/dist-library/types/authoring/insert.d.ts +1 -1
  101. package/dist-library/types/authoring/templates.d.ts +2 -2
  102. package/dist-library/types/build/diagnostics.d.ts +1 -1
  103. package/dist-library/types/build/host.d.ts +1 -1
  104. package/dist-library/types/build/index.d.ts +1 -1
  105. package/dist-library/types/build/notices.d.ts +1 -1
  106. package/dist-library/types/build/resources.d.ts +1 -1
  107. package/dist-library/types/build/vite.d.ts +1 -1
  108. package/dist-library/types/compiler/index.d.ts +2 -2
  109. package/dist-library/types/compiler/result.d.ts +1 -1
  110. package/dist-library/types/compiler/standard.d.ts +2 -2
  111. package/dist-library/types/compiler/types.d.ts +1 -1
  112. package/dist-library/types/components/{controls.d.ts → controls/controls.d.ts} +2 -3
  113. package/dist-library/types/components/{numeric-sliders.d.ts → controls/numeric-sliders.d.ts} +1 -1
  114. package/dist-library/types/components/{gallery.d.ts → gallery/gallery.d.ts} +1 -1
  115. package/dist-library/types/components/{layout.d.ts → layout/layout.d.ts} +1 -1
  116. package/dist-library/types/components/minimal-preset.d.ts +2 -0
  117. package/dist-library/types/components/mount-preset.d.ts +4 -0
  118. package/dist-library/types/components/network/submit-button.d.ts +10 -0
  119. package/dist-library/types/components/plot/coordinate.d.ts +2 -0
  120. package/dist-library/types/components/plugins/chart.d.ts +2 -0
  121. package/dist-library/types/components/plugins/data.d.ts +2 -0
  122. package/dist-library/types/components/plugins/diagram.d.ts +2 -0
  123. package/dist-library/types/components/plugins/forms.d.ts +2 -0
  124. package/dist-library/types/components/plugins/gallery.d.ts +2 -0
  125. package/dist-library/types/components/plugins/navigation.d.ts +2 -0
  126. package/dist-library/types/components/plugins/network.d.ts +2 -0
  127. package/dist-library/types/components/plugins/plot.d.ts +2 -0
  128. package/dist-library/types/components/shared/visual-frame.d.ts +12 -0
  129. package/dist-library/types/components/{visuals.d.ts → shared/visuals.d.ts} +1 -7
  130. package/dist-library/types/components/{data-table.d.ts → table/data-table.d.ts} +2 -2
  131. package/dist-library/types/export/component-state.d.ts +1 -1
  132. package/dist-library/types/export/index.d.ts +2 -1
  133. package/dist-library/types/export/print-document.d.ts +18 -0
  134. package/dist-library/types/export/render-markup.d.ts +23 -0
  135. package/dist-library/types/export/requirements.d.ts +1 -1
  136. package/dist-library/types/export/resources.d.ts +1 -1
  137. package/dist-library/types/export/restoration.d.ts +1 -1
  138. package/dist-library/types/export-assets/index.d.ts +25 -0
  139. package/dist-library/types/local/compilation/compiler-attributes.d.ts +8 -0
  140. package/dist-library/types/local/compilation/compiler-bindings.d.ts +19 -0
  141. package/dist-library/types/local/compilation/compiler-capabilities.d.ts +3 -0
  142. package/dist-library/types/local/compilation/compiler-core.d.ts +11 -3
  143. package/dist-library/types/local/compilation/compiler-declarations.d.ts +32 -0
  144. package/dist-library/types/local/compilation/compiler-expressions.d.ts +32 -0
  145. package/dist-library/types/local/compilation/compiler-services.d.ts +62 -16
  146. package/dist-library/types/local/compilation/compiler-structure.d.ts +38 -3
  147. package/dist-library/types/local/compilation/compiler-tables.d.ts +30 -0
  148. package/dist-library/types/local/compilation/compiler-validation.d.ts +15 -0
  149. package/dist-library/types/local/compilation/compiler-values.d.ts +39 -1
  150. package/dist-library/types/local/compilation/compiler.d.ts +7 -14
  151. package/dist-library/types/local/compilation/dependencies.d.ts +1 -1
  152. package/dist-library/types/local/compilation/session/incremental.d.ts +75 -0
  153. package/dist-library/types/local/{session → compilation/session}/row-reuse.d.ts +1 -1
  154. package/dist-library/types/local/{session/compiler-cache.d.ts → compilation/session/semantic-cache.d.ts} +5 -19
  155. package/dist-library/types/local/compilation/streaming.d.ts +27 -0
  156. package/dist-library/types/local/configuration/capability-policy.d.ts +3 -0
  157. package/dist-library/types/local/{compilation → configuration}/component-kernel.d.ts +3 -79
  158. package/dist-library/types/local/configuration/diagnostic-messages.d.ts +1104 -1056
  159. package/dist-library/types/local/configuration/diagnostic-runtime-messages.d.ts +731 -0
  160. package/dist-library/types/local/configuration/diagnostics.d.ts +1 -1
  161. package/dist-library/types/local/configuration/kernel-value-rules.d.ts +66 -0
  162. package/dist-library/types/local/configuration/official-leaf-syntax.d.ts +24 -0
  163. package/dist-library/types/local/configuration/options-core.d.ts +5 -4
  164. package/dist-library/types/local/configuration/options.d.ts +2 -1
  165. package/dist-library/types/local/configuration/portable-options.d.ts +1 -1
  166. package/dist-library/types/local/configuration/schema-core.d.ts +1 -1
  167. package/dist-library/types/local/configuration/schema.d.ts +1 -1
  168. package/dist-library/types/local/css/author-css.d.ts +66 -0
  169. package/dist-library/types/local/evaluation/computations.d.ts +2 -2
  170. package/dist-library/types/local/evaluation/expression/compile.d.ts +30 -0
  171. package/dist-library/types/local/evaluation/expression/evaluation.d.ts +3 -0
  172. package/dist-library/types/local/evaluation/expression/inference.d.ts +4 -0
  173. package/dist-library/types/local/evaluation/expression/syntax.d.ts +72 -0
  174. package/dist-library/types/local/evaluation/expression/values.d.ts +56 -0
  175. package/dist-library/types/local/evaluation/{math-display.d.ts → math/display.d.ts} +2 -2
  176. package/dist-library/types/local/evaluation/math/evaluation.d.ts +10 -0
  177. package/dist-library/types/local/evaluation/{math.d.ts → math/latex.d.ts} +58 -17
  178. package/dist-library/types/local/evaluation/{math-sample.d.ts → math/sample.d.ts} +4 -2
  179. package/dist-library/types/local/evaluation/math/syntax.d.ts +72 -0
  180. package/dist-library/types/local/evaluation/validation.d.ts +1 -1
  181. package/dist-library/types/local/html/extended-fragment.d.ts +41 -0
  182. package/dist-library/types/local/html/html-details.d.ts +1 -1
  183. package/dist-library/types/local/html/html-entities.d.ts +11 -2
  184. package/dist-library/types/local/html/html-recovery.d.ts +1 -1
  185. package/dist-library/types/local/html/html-table.d.ts +1 -1
  186. package/dist-library/types/local/html/html.d.ts +40 -4
  187. package/dist-library/types/local/index.d.ts +14 -13
  188. package/dist-library/types/local/parsing/author-markdown.d.ts +11 -0
  189. package/dist-library/types/local/{markdown → parsing}/fast-markdown.d.ts +1 -1
  190. package/dist-library/types/local/{markdown → parsing}/footnotes.d.ts +1 -1
  191. package/dist-library/types/local/{markdown → parsing}/heading-anchors.d.ts +1 -1
  192. package/dist-library/types/local/parsing/html-attributes.d.ts +14 -0
  193. package/dist-library/types/local/parsing/parse-budget.d.ts +1 -1
  194. package/dist-library/types/local/{session → parsing}/parse-session.d.ts +5 -5
  195. package/dist-library/types/local/parsing/parser-capabilities.d.ts +7 -2
  196. package/dist-library/types/local/parsing/parser-convert.d.ts +26 -0
  197. package/dist-library/types/local/parsing/parser-core.d.ts +10 -4
  198. package/dist-library/types/local/parsing/parser-internals.d.ts +54 -0
  199. package/dist-library/types/local/parsing/parser-region.d.ts +46 -0
  200. package/dist-library/types/local/parsing/parser-standard.d.ts +3 -0
  201. package/dist-library/types/local/parsing/parser-tags.d.ts +108 -0
  202. package/dist-library/types/local/parsing/parser.d.ts +3 -3
  203. package/dist-library/types/local/{markdown → parsing}/plain-paragraphs.d.ts +1 -1
  204. package/dist-library/types/local/parsing/rmd-recovery.d.ts +1 -1
  205. package/dist-library/types/local/parsing/theme-declaration.d.ts +22 -0
  206. package/dist-library/types/local/rendering/document/ExtendedHtmlFragment.d.ts +14 -0
  207. package/dist-library/types/local/rendering/document/LocalDocumentView.d.ts +5 -0
  208. package/dist-library/types/local/rendering/{LocalDocumentView.d.ts → document/LocalDocumentViewCore.d.ts} +48 -9
  209. package/dist-library/types/local/rendering/document/LocalReactiveDocumentCore.d.ts +6 -0
  210. package/dist-library/types/local/rendering/document/render-nodes.d.ts +24 -0
  211. package/dist-library/types/local/rendering/document/use-author-script.d.ts +3 -0
  212. package/dist-library/types/local/rendering/document/use-color-scheme.d.ts +10 -0
  213. package/dist-library/types/local/rendering/document/validation-state.d.ts +31 -0
  214. package/dist-library/types/local/rendering/document/view-render-context.d.ts +146 -0
  215. package/dist-library/types/local/rendering/{view-revision.d.ts → document/view-revision.d.ts} +31 -4
  216. package/dist-library/types/local/rendering/render-types.d.ts +1 -1
  217. package/dist-library/types/local/{widgets/table-surface.d.ts → rendering/table/data-table.d.ts} +3 -0
  218. package/dist-library/types/local/rendering/table/table-numeric-columns.d.ts +7 -0
  219. package/dist-library/types/local/runtime/author-script-protocol.d.ts +59 -0
  220. package/dist-library/types/local/runtime/retention.d.ts +1 -1
  221. package/dist-library/types/local/runtime/runtime-document.d.ts +71 -0
  222. package/dist-library/types/local/runtime/runtime-migration.d.ts +19 -0
  223. package/dist-library/types/local/runtime/runtime-values.d.ts +39 -0
  224. package/dist-library/types/local/runtime/runtime.d.ts +4 -2
  225. package/dist-library/types/local/runtime/state.d.ts +1 -1
  226. package/dist-library/types/local/source/authoring-syntax.d.ts +48 -0
  227. package/dist-library/types/local/source/authoring.d.ts +1 -1
  228. package/dist-library/types/local/source/source-context.d.ts +23 -0
  229. package/dist-library/types/local/source/source-migration.d.ts +2 -2
  230. package/dist-library/types/local/transport/compile-patch.d.ts +1 -1
  231. package/dist-library/types/local/transport/flat-compiled-data.d.ts +1 -1
  232. package/dist-library/types/local/transport/shared-data.d.ts +1 -1
  233. package/dist-library/types/local/transport/worker-handler.d.ts +30 -0
  234. package/dist-library/types/local/transport/worker-job.d.ts +28 -0
  235. package/dist-library/types/local/transport/worker.d.ts +32 -46
  236. package/dist-library/types/local/{contracts/types.d.ts → types.d.ts} +78 -21
  237. package/dist-library/types/pdf.d.ts +22 -0
  238. package/dist-library/types/presets/identity.d.ts +1 -0
  239. package/dist-library/types/presets/minimal.d.ts +2 -0
  240. package/dist-library/types/presets/plugin-packs.d.ts +1 -0
  241. package/dist-library/types/react/component-api.d.ts +20 -4
  242. package/dist-library/types/react/component-primitives.d.ts +10 -10
  243. package/dist-library/types/react/component-utils.d.ts +9 -1
  244. package/dist-library/types/react/index.d.ts +6 -5
  245. package/dist-library/types/{local/theme/i18n.d.ts → react/localization.d.ts} +2 -2
  246. package/dist-library/types/react/minimal.d.ts +13 -0
  247. package/dist-library/types/react/package-core.d.ts +67 -0
  248. package/dist-library/types/react/package.d.ts +3 -67
  249. package/dist-library/types/react/runtime/common.d.ts +1 -1
  250. package/dist-library/types/react/sdk-core.d.ts +115 -0
  251. package/dist-library/types/react/sdk.d.ts +4 -110
  252. package/dist-library/types/react/server.d.ts +2 -2
  253. package/dist-library/types/react/use-draft-field.d.ts +5 -1
  254. package/dist-library/types/runtime-services/browser/duplex.d.ts +163 -0
  255. package/dist-library/types/runtime-services/browser/http-sse.d.ts +117 -0
  256. package/dist-library/types/runtime-services/browser/index.d.ts +2 -1
  257. package/dist-library/types/runtime-services/component-state.d.ts +1 -1
  258. package/dist-library/types/runtime-services/index.d.ts +2 -0
  259. package/dist-library/types/runtime-services/network.d.ts +86 -0
  260. package/dist-library/types/runtime-services/runtime.d.ts +1 -1
  261. package/dist-library/types/sdk/config.d.ts +1 -1
  262. package/dist-library/types/sdk/index.d.ts +1 -0
  263. package/dist-library/types/sdk/props.d.ts +1 -1
  264. package/dist-library/types/sdk/registry-core.d.ts +1 -1
  265. package/dist-library/types/sdk/theme.d.ts +5 -4
  266. package/dist-library/types/sdk/types.d.ts +2 -2
  267. package/dist-library/types/shareable.d.ts +6 -5
  268. package/dist-library/types/standalone/diagnostics.d.ts +1 -1
  269. package/dist-library/types/standalone/host.d.ts +5 -0
  270. package/dist-library/types/standalone/payload.d.ts +1 -1
  271. package/dist-library/types/standalone/prepare.d.ts +2 -2
  272. package/dist-library/types/standalone/session-core.d.ts +68 -0
  273. package/dist-library/types/standalone/session.d.ts +6 -68
  274. package/dist-library/types/themes/contract.d.ts +7 -0
  275. package/dist-library/types/{local/theme/theme.d.ts → themes/document-theme.d.ts} +4 -3
  276. package/dist-library/types/vite/client.d.ts +19 -0
  277. package/dist-library/types/vite/index.d.ts +18 -3
  278. package/dist-library/types/vite/registration.d.ts +2 -2
  279. package/dist-library/{types-BFCrMrg0.js → types-BeNtPqdY.js} +1 -1
  280. package/dist-library/validation-BEBA_HvS.js +1121 -0
  281. package/dist-library/visual-frame-CyV1FXzs.js +48 -0
  282. package/dist-library/visuals-B5KSafVk.js +3 -0
  283. package/dist-library/visuals-BZbZYA7w.js +72572 -0
  284. package/dist-standalone/reactive-md-standalone.css +1 -1
  285. package/dist-standalone/reactive-md-standalone.js +146 -137
  286. package/docs/README-ch.md +16 -11
  287. package/docs/README.md +16 -11
  288. package/docs/compatibility/compatibility-ch.md +8 -8
  289. package/docs/compatibility/compatibility-en.md +8 -8
  290. package/docs/compatibility/source-versioning-ch.md +1 -1
  291. package/docs/compatibility/source-versioning-en.md +1 -1
  292. package/docs/development/component-development-ch.md +2 -2
  293. package/docs/development/component-development-en.md +2 -2
  294. package/docs/development/component-development-reference-ch.md +4 -4
  295. package/docs/development/component-development-reference-en.md +4 -4
  296. package/docs/development/component-protocol-ch.md +14 -14
  297. package/docs/development/component-protocol-en.md +14 -14
  298. package/docs/development/extension-tutorial-ch.md +308 -0
  299. package/docs/development/extension-tutorial-en.md +308 -0
  300. package/docs/development/local-module-layout-ch.md +10 -50
  301. package/docs/development/local-module-layout-en.md +9 -49
  302. package/docs/development/performance-overview-ch.md +174 -154
  303. package/docs/development/performance-overview-en.md +174 -154
  304. package/docs/guides/local-guide-ch.md +2 -2
  305. package/docs/guides/local-guide-en.md +2 -2
  306. package/docs/integration/author-tools-ch.md +2 -2
  307. package/docs/integration/author-tools-en.md +2 -2
  308. package/docs/integration/compiler-ch.md +4 -2
  309. package/docs/integration/compiler-en.md +4 -2
  310. package/docs/integration/directory-discovery-ch.md +5 -1
  311. package/docs/integration/directory-discovery-en.md +5 -1
  312. package/docs/integration/editor-ch.md +35 -5
  313. package/docs/integration/editor-en.md +42 -4
  314. package/docs/integration/extension-sdk-ch.md +6 -4
  315. package/docs/integration/extension-sdk-en.md +6 -4
  316. package/docs/integration/local-integration-ch.md +201 -19
  317. package/docs/integration/local-integration-en.md +194 -18
  318. package/docs/integration/network-host-ch.md +75 -0
  319. package/docs/integration/network-host-en.md +75 -0
  320. package/docs/integration/shareable-export-ch.md +58 -16
  321. package/docs/integration/shareable-export-en.md +57 -15
  322. package/docs/reference/html-compatibility-ch.md +20 -67
  323. package/docs/reference/html-compatibility-en.md +19 -64
  324. package/docs/reference/local-interaction-syntax-ch.md +199 -26
  325. package/docs/reference/local-interaction-syntax-en.md +194 -27
  326. package/docs/reference/public-api-ch.md +416 -0
  327. package/docs/reference/public-api-en.md +416 -0
  328. package/docs/reference/theme-protocol-ch.md +27 -8
  329. package/docs/reference/theme-protocol-en.md +46 -8
  330. package/docs/releases/release-0.4.0-ch.md +2 -2
  331. package/docs/releases/release-0.4.0-en.md +2 -2
  332. package/docs/releases/release-0.8.0-ch.md +19 -3
  333. package/docs/releases/release-0.8.0-en.md +19 -3
  334. package/docs/releases/release-0.9.0-ch.md +44 -0
  335. package/docs/releases/release-0.9.0-en.md +44 -0
  336. package/docs/releases/release-0.9.1-ch.md +29 -0
  337. package/docs/releases/release-0.9.1-en.md +29 -0
  338. package/examples/component-package/README-ch.md +1 -1
  339. package/examples/component-package/README.md +1 -1
  340. package/examples/conformance/README-ch.md +3 -3
  341. package/examples/conformance/README.md +3 -3
  342. package/examples/game-2048-package/README-ch.md +3 -9
  343. package/examples/game-2048-package/README.md +8 -12
  344. package/examples/integration/README-ch.md +21 -2
  345. package/examples/integration/README.md +21 -2
  346. package/examples/integration/extension-sdk/README-ch.md +1 -1
  347. package/examples/integration/extension-sdk/README.md +1 -1
  348. package/examples/integration/streaming/index.html +48 -0
  349. package/examples/integration/streaming/main.js +175 -0
  350. package/examples/integration/streaming/package.json +13 -0
  351. package/examples/integration/streaming/worker.js +3 -0
  352. package/examples/local/README-ch.md +3 -3
  353. package/examples/local/README.md +2 -2
  354. package/examples/local/minimal-budget.reactive.md +48 -0
  355. package/examples/minimal-extension/README-ch.md +78 -0
  356. package/examples/minimal-extension/README.md +78 -0
  357. package/examples/minimal-extension/index.html +15 -0
  358. package/examples/minimal-extension/package.json +26 -0
  359. package/examples/minimal-extension/sample/document.reactive.md +10 -0
  360. package/examples/minimal-extension/scripts/build.mjs +32 -0
  361. package/examples/minimal-extension/scripts/export.mjs +72 -0
  362. package/examples/minimal-extension/scripts/test-node.mjs +75 -0
  363. package/examples/minimal-extension/src/extension.tsx +90 -0
  364. package/examples/minimal-extension/src/preview.tsx +12 -0
  365. package/examples/minimal-extension/src/source.ts +4 -0
  366. package/examples/minimal-extension/tsconfig.json +14 -0
  367. package/examples/network-survey/README.md +200 -0
  368. package/examples/network-survey/index.html +49 -0
  369. package/examples/network-survey/package.json +26 -0
  370. package/examples/network-survey/sample/document.reactive.md +51 -0
  371. package/examples/network-survey/src/components.tsx +325 -0
  372. package/examples/network-survey/src/host.ts +316 -0
  373. package/examples/network-survey/src/main.tsx +91 -0
  374. package/examples/network-survey/src/source.ts +1 -0
  375. package/examples/network-survey/tsconfig.json +26 -0
  376. package/examples/network-survey/vite.config.ts +227 -0
  377. package/examples/sci-fi-theme/README-ch.md +4 -2
  378. package/examples/sci-fi-theme/README.md +4 -2
  379. package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -0
  380. package/examples/sci-fi-theme/demo/demo.css +129 -23
  381. package/examples/sci-fi-theme/demo/document.reactive.md +27 -6
  382. package/examples/sci-fi-theme/demo/main.tsx +45 -10
  383. package/examples/sci-fi-theme/docs/design-system-ch.md +6 -6
  384. package/examples/sci-fi-theme/package.json +2 -1
  385. package/examples/sci-fi-theme/src/components.css +1064 -154
  386. package/examples/sci-fi-theme/src/notch.css +142 -0
  387. package/examples/sci-fi-theme/src/sci-fi.css +3 -1
  388. package/examples/sci-fi-theme/src/theme.ts +2 -0
  389. package/examples/sci-fi-theme/src/tokens.css +512 -408
  390. package/examples/tetris-package/README-ch.md +4 -4
  391. package/examples/tetris-package/README.md +4 -4
  392. package/package.json +70 -3
  393. package/dist-library/LocalDocumentView-6trX7xJc.js +0 -97920
  394. package/dist-library/compiler--ea2CKQF.js +0 -61
  395. package/dist-library/component-state-Cq2K5gkS.js +0 -490
  396. package/dist-library/options-CX5m5n-J.js +0 -115
  397. package/dist-library/runtime-C-sbfpOX.js +0 -1157
  398. package/dist-library/types/local/contracts/locale.d.ts +0 -1
  399. package/dist-library/types/local/contracts/version.d.ts +0 -2
  400. package/dist-library/types/local/evaluation/dates.d.ts +0 -2
  401. package/dist-library/types/local/evaluation/expression.d.ts +0 -47
  402. package/dist-library/types/local/markdown/markdown-structure.d.ts +0 -3
  403. package/dist-library/types/local/rendering/legacy-component-adapter.d.ts +0 -36
  404. package/dist-library/types/local/session/incremental.d.ts +0 -48
  405. package/dist-library/types/local/source/node-walk.d.ts +0 -3
  406. package/dist-library/types/local/source/text-length.d.ts +0 -13
  407. package/dist-library/types/local/theme/theme-name.d.ts +0 -3
  408. package/dist-library/types/local/widgets/visuals.d.ts +0 -25
  409. package/dist-library/types/react/default-theme.d.ts +0 -6
  410. package/dist-library/validation-W-bmny-x.js +0 -2253
  411. package/docs/development/releasing-ch.md +0 -12
  412. package/docs/development/releasing-en.md +0 -12
  413. package/docs/integration/codemirror-ch.md +0 -52
  414. package/docs/integration/codemirror-en.md +0 -29
  415. package/docs/integration/repository-split-ch.md +0 -40
  416. package/docs/integration/repository-split-en.md +0 -23
  417. package/docs/reference/computations-formatting-ch.md +0 -89
  418. package/docs/reference/computations-formatting-en.md +0 -89
  419. package/docs/reference/constraints-collections-ch.md +0 -104
  420. package/docs/reference/constraints-collections-en.md +0 -104
  421. package/docs/reference/local-components-v2-ch.md +0 -140
  422. package/docs/reference/local-components-v2-en.md +0 -106
  423. package/docs/reference/tolerance-ch.md +0 -64
  424. package/docs/reference/tolerance-en.md +0 -57
  425. /package/dist-library/types/components/{chart-motion.d.ts → chart/chart-motion.d.ts} +0 -0
  426. /package/dist-library/types/components/{default-chart-types.d.ts → chart/default-chart-types.d.ts} +0 -0
  427. /package/dist-library/types/components/{default-chart.d.ts → chart/default-chart.d.ts} +0 -0
  428. /package/dist-library/types/components/{diagram-inspector.d.ts → diagram/diagram-inspector.d.ts} +0 -0
  429. /package/dist-library/types/{local/widgets/diagram-layout.d.ts → components/diagram/layout.d.ts} +0 -0
  430. /package/dist-library/types/components/{mafs-plot-grid.d.ts → plot/mafs-plot-grid.d.ts} +0 -0
  431. /package/dist-library/types/components/{mafs-visuals.d.ts → plot/mafs-visuals.d.ts} +0 -0
  432. /package/dist-library/types/components/{use-hydrated.d.ts → shared/use-hydrated.d.ts} +0 -0
  433. /package/dist-library/types/local/{theme/colors.d.ts → configuration/color-values.d.ts} +0 -0
  434. /package/dist-library/types/local/evaluation/{collection-functions.d.ts → expression/collection-functions.d.ts} +0 -0
  435. /package/dist-library/types/local/evaluation/{data-functions.d.ts → expression/data-functions.d.ts} +0 -0
  436. /package/dist-library/types/local/evaluation/{formatting.d.ts → expression/formatting.d.ts} +0 -0
  437. /package/dist-library/types/local/{markdown → parsing}/markdown-blocks.d.ts +0 -0
  438. /package/dist-library/types/local/{widgets → rendering/code}/code-block.d.ts +0 -0
  439. /package/dist-library/types/local/{widgets → rendering/code}/code-languages.d.ts +0 -0
  440. /package/dist-library/types/local/{widgets → rendering/image}/image-view.d.ts +0 -0
  441. /package/dist-library/types/local/{widgets → rendering}/math-view.d.ts +0 -0
@@ -0,0 +1,75 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import {
5
+ createLocalComplianceReport,
6
+ runLocalBehaviorCompliance,
7
+ runLocalManifestCompliance,
8
+ } from 'reactive-md/testing';
9
+ import { runLocalReactCompliance } from 'reactive-md/testing/react';
10
+
11
+ /**
12
+ * Node and SSR evidence. The browser suite is not part of this template, so
13
+ * the report deliberately omits the offline capability and writes
14
+ * `complete: false`. Run a browser suite before claiming offline behavior.
15
+ */
16
+ const root = path.resolve(fileURLToPath(new URL('..', import.meta.url)));
17
+ const entry = await import(pathToFileURL(path.join(root, 'dist', 'node', 'entry.mjs')).href);
18
+
19
+ const behaviorSpec = {
20
+ protocol: 'reactive-md-behavior-spec/v1',
21
+ component: 'rating-card',
22
+ source: '<rating-card bind="score" label="Score" max="5" initial="3">',
23
+ writes: [
24
+ { id: 'increment', value: 4, accepted: true, expect: { score: 4 } },
25
+ { id: 'at-max', value: 5, accepted: true, expect: { score: 5 } },
26
+ { id: 'over-max', value: 6, accepted: false },
27
+ { id: 'wrong-type', value: 'four', accepted: false },
28
+ ],
29
+ };
30
+
31
+ const reactSpec = {
32
+ protocol: 'reactive-md-react-spec/v1',
33
+ source: entry.source,
34
+ staticMarkupIncludes: ['data-rating-card-static'],
35
+ ssrMarkupIncludes: ['data-rating-card-static'],
36
+ };
37
+
38
+ const manifest = runLocalManifestCompliance(entry.ratingCard);
39
+ const behavior = runLocalBehaviorCompliance(behaviorSpec, entry.config);
40
+ const react = runLocalReactCompliance({
41
+ config: entry.config,
42
+ reactConfig: entry.reactConfig,
43
+ component: 'rating-card',
44
+ spec: reactSpec,
45
+ locale: 'en',
46
+ });
47
+
48
+ const report = createLocalComplianceReport({
49
+ config: entry.config,
50
+ component: 'rating-card',
51
+ suites: [manifest, behavior, react],
52
+ capabilities: ['interactive', 'static', 'ssr'],
53
+ });
54
+
55
+ await mkdir(path.join(root, 'dist'), { recursive: true });
56
+ await writeFile(path.join(root, 'dist', 'compliance.json'), JSON.stringify({
57
+ complete: false,
58
+ offline: 'not executed: the browser suite is not part of this template',
59
+ report,
60
+ }, null, 2));
61
+
62
+ console.log(`rating-card: passed=${report.summary.passed} failed=${report.summary.failed} skipped=${report.summary.skipped} unsupported=${report.summary.unsupported}`);
63
+ for (const evidence of report.capabilities) {
64
+ console.log(` ${evidence.capability}: ${evidence.status}`);
65
+ }
66
+ for (const diagnostic of report.diagnostics) {
67
+ console.log(` [${diagnostic.code}] ${diagnostic.message}`);
68
+ }
69
+
70
+ if (!report.ok) {
71
+ console.error('Node/SSR compliance failed.');
72
+ process.exit(1);
73
+ }
74
+ console.log('Node and SSR checks passed. Offline and browser evidence is not part of this run;');
75
+ console.log('see dist/interactive.html from `npm run export` and the component-package template for a browser suite.');
@@ -0,0 +1,90 @@
1
+ import { createLocalConfig, defineLocalComponent } from 'reactive-md/sdk';
2
+ import { createReactConfig, defineReactComponent, type LocalComponentContext } from 'reactive-md/react';
3
+
4
+ /**
5
+ * One leaf component. The manifest below is plain JSON data; the two render
6
+ * functions are React code. `config` and `reactConfig` are the pair every host
7
+ * needs, and both are built from the same manifest.
8
+ */
9
+ export const ratingCard = defineLocalComponent({
10
+ id: 'example/rating-card',
11
+ name: 'rating-card',
12
+ version: '1.0.0',
13
+ protocol: 'reactive-md-component/v1',
14
+ form: 'leaf',
15
+ props: {
16
+ label: { kind: 'string', required: true },
17
+ max: { kind: 'number', dynamic: true, default: 5, integer: true, min: 1, max: 10 },
18
+ },
19
+ bindings: {
20
+ value: {
21
+ kind: 'number',
22
+ family: 'number',
23
+ bind: 'bind',
24
+ initial: 'initial',
25
+ initialRule: 'nearest-zero',
26
+ constraints: {
27
+ min: { literal: 0 },
28
+ max: { prop: 'max' },
29
+ step: { literal: 1 },
30
+ },
31
+ },
32
+ },
33
+ structure: { rule: 'none' },
34
+ capabilities: { interactive: true, static: true, ssr: true, offline: true },
35
+ authoring: {
36
+ title: { en: 'Rating card', zh: '评分卡' },
37
+ description: {
38
+ en: 'A leaf card that increments one shared number.',
39
+ zh: '递增一个共享数值的叶子卡片。',
40
+ },
41
+ category: 'input',
42
+ insertText: '<rating-card bind="score" label="Score" max="5" initial="3">',
43
+ },
44
+ });
45
+
46
+ function currentValue(context: LocalComponentContext): number {
47
+ const value = context.bindings.value.get();
48
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
49
+ }
50
+
51
+ export function RatingCard(context: LocalComponentContext) {
52
+ const value = currentValue(context);
53
+ const maximum = typeof context.props.max === 'number' ? context.props.max : 5;
54
+ const label = String(context.props.label ?? 'Rating');
55
+ const unavailable = context.disabled || !context.visible;
56
+ const locked = unavailable || value >= maximum;
57
+ return (
58
+ <div className="rating-card" data-rating-card data-value={String(value)} role="group" aria-label={label}>
59
+ <output data-rating-card-value>{String(value)}</output>
60
+ <span aria-hidden="true">{'\u2605'.repeat(value)}{'\u2606'.repeat(Math.max(0, maximum - value))}</span>
61
+ <button type="button" data-rating-card-up disabled={locked} onClick={() => context.bindings.value.set(value + 1)}>
62
+ Add one
63
+ </button>
64
+ <button type="button" data-rating-card-reset disabled={unavailable} onClick={() => context.runtime.reset(context.content)}>
65
+ Reset
66
+ </button>
67
+ </div>
68
+ );
69
+ }
70
+
71
+ export function RatingCardStatic(context: LocalComponentContext) {
72
+ return (
73
+ <span className="rating-card" data-rating-card-static>
74
+ {String(context.props.label ?? 'Rating')}: {String(currentValue(context))}
75
+ </span>
76
+ );
77
+ }
78
+
79
+ const ratingCardImplementation = defineReactComponent(ratingCard, {
80
+ render: RatingCard,
81
+ renderStatic: RatingCardStatic,
82
+ });
83
+
84
+ /** Passed to compilers, editors and workers. The default preset stays enabled. */
85
+ export const config = createLocalConfig({ components: [ratingCard] });
86
+
87
+ /** Passed to preview, SSR and export rendering. */
88
+ export const reactConfig = createReactConfig(config, { components: [ratingCardImplementation] });
89
+
90
+ export { source } from './source';
@@ -0,0 +1,12 @@
1
+ import { createRoot } from 'react-dom/client';
2
+ import { LocalReactiveDocument } from 'reactive-md/react';
3
+ import 'reactive-md/styles.css';
4
+ import { reactConfig } from './extension';
5
+ import { source } from './source';
6
+
7
+ const host = document.getElementById('app');
8
+ if (!host) throw new Error('The preview page is missing #app.');
9
+
10
+ createRoot(host).render(
11
+ <LocalReactiveDocument source={source} reactConfig={reactConfig} locale="en" />,
12
+ );
@@ -0,0 +1,4 @@
1
+ import text from '../sample/document.reactive.md?raw';
2
+
3
+ /** The sample document shipped with the template. */
4
+ export const source = text;
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "noEmit": true,
11
+ "types": ["vite/client"]
12
+ },
13
+ "include": ["src"]
14
+ }
@@ -0,0 +1,200 @@
1
+ # 命名网络通道问卷示例
2
+
3
+ 读者可以提交回答,并在 Markdown 正文和两个自定义组件中看到实时计票。
4
+ 页面不依赖任何外部服务;默认使用内存适配器,也可以切到本地 HTTP + SSE 端点。
5
+
6
+ 所有导入都走公开包入口(`reactive-md/sdk`、`reactive-md/react/minimal`、
7
+ `reactive-md/plugins/network`、`reactive-md/runtime`、
8
+ `reactive-md/runtime/browser`),渲染与构建复用仓库的 `dist-library` 与 Vite。
9
+
10
+ ## 运行
11
+
12
+ 依赖复用仓库根目录已安装的 Vite、React 和 `dist-library`,不需要单独安装。
13
+ 在仓库根目录执行:
14
+
15
+ ```sh
16
+ npx vite --config examples/network-survey/vite.config.ts
17
+ ```
18
+
19
+ 打开 `http://localhost:4318`。默认是内存适配器:提交经过 220 ms 模拟往返,
20
+ 计票组件立刻收到新值。需要真实 HTTP 请求时改用:
21
+
22
+ ```sh
23
+ npx vite --config examples/network-survey/vite.config.ts --mode http
24
+ ```
25
+
26
+ `vite.config.ts` 优先把 `reactive-md/*` 指向 `dist-library`。如果这次构建还没有
27
+ 生成 `reactive-md-plugin-network.js`(例如尚未运行 `npm run build:lib`),它会整体
28
+ 回退到仓库的 `src/`,页面照样能启动;重新构建后自动使用打包产物。
29
+
30
+ `--mode http` 启动时,同一端口提供两个受控端点:
31
+
32
+ | 方法 | 路径 | 作用 |
33
+ | --- | --- | --- |
34
+ | `POST` | `/api/survey/answers` | 接收 `{"choice":"yes","comment":""}`,成功返回 `{ok:true,counts}`;字段不符返回 422。 |
35
+ | `GET` | `/api/survey/results/events` | `text/event-stream`:连接时发一次当前计数,每次提交广播 `data: {"yes":n,"no":n}`,每 5 秒重发快照,每 15 秒一个心跳。 |
36
+
37
+ 在 `http` 模式页面加 `?transport=memory` 可退回内存适配器;默认模式下加
38
+ `?transport=http` 会尝试连接端点(没有 `--mode http` 时请求失败,正好可以看
39
+ 按钮的拒绝提示)。
40
+
41
+ 页面底部的「宿主连接记录」实时显示提交次数、已确认/拒绝次数、通道打开与
42
+ 释放次数、当前连接数。
43
+
44
+ 把示例复制到仓库外单独使用时,在 `examples/network-survey` 内执行
45
+ `npm install && npm run dev`;此时需要仓库已发布或本地链接的 `reactive-md`。
46
+ 本仓库内推荐上面的根目录命令。
47
+
48
+ ## 浏览器验收
49
+
50
+ 在引擎仓库根目录运行以下命令。脚本使用 Playwright Chromium、本机回环服务和两个本机 WebRTC peer。
51
+
52
+ ```powershell
53
+ node scripts/verify-network-browser.mjs
54
+ ```
55
+
56
+ 如果机器已安装 Microsoft Edge,可以用 `$env:PLAYWRIGHT_CHANNEL = 'msedge'` 指定浏览器。也可以用 `npx playwright install chromium` 安装 Playwright 的 Chromium。
57
+
58
+ | 验收项 | 通过条件 |
59
+ | --- | --- |
60
+ | HTTP 提交 | 键入有效值期间没有 POST。把已保存的合法输入改成不合法草稿后,提交提示字段错误,保留草稿。聚焦按钮按 Enter 发出一次请求,HTTP 503 后双击重试也只发一次,并沿用原幂等键。请求只含所选字段。 |
61
+ | 问卷写入去重 | 示例后端记下第一票后,测试丢弃响应。浏览器用相同幂等键重试并收到首次结果,票数只增加一次。同键换载荷返回 409,另一位参与者可以独立使用同一个键。 |
62
+ | React 与 SSE | 两个组件收到同一条流的数据。编辑普通正文和移除第一个组件时连接保持,最后一个组件卸载后连接关闭。切换文档时替换连接,撤销授权后释放旧流。 |
63
+ | 外部变量与回执 | SSE 更新 Markdown 正文、计算值和条件块,保留输入草稿。撤销授权后恢复宿主初值。自定义组件只收到宿主选出的报名编号。 |
64
+ | WebSocket | 浏览器连接本地受控端点,收到推送,并按 `requestId` 将乱序回复分给两个提交。带 emoji 的超限确认被丢弃,合法拒绝仍能结算对应提交。 |
65
+ | WebRTC | 两个真实的 `RTCPeerConnection` 建立 DataChannel,完成推送与提交。最后一个订阅退出时,待确认的提交继续占用连接。确认到达后调用一次宿主的释放函数。 |
66
+
67
+ 手动复核时,按前面的步骤启动示例的 HTTP/SSE 模式。打开开发者工具的 Network 面板,筛选 `/api/survey/`。选项和备注编辑期间没有 POST,聚焦「提交回答」后按 Enter,新 POST 的 Payload 只有 `choice` 和 `comment`。再用下面的开关核对 EventStream 和页面连接记录。自动验收夹具提供文本约束及可控回复,用于复核无效草稿、双击和未确认重试。
68
+
69
+ ## 观察生命周期
70
+
71
+ 1. 打开问卷。正文和两个计票组件共享一个 `results` 通道,“通道打开”为 1,“当前连接”为 1。
72
+ 2. 取消「显示实时计票」。组件隐藏并退订,计票明细继续接收消息,连接计数保持为 1。
73
+ 3. 取消「显示计票明细」。正文仍能更新,“当前连接”保持为 1。再取消「启用实时更新与提交」,“通道释放”加 1,“当前连接”归 0,正文隐藏实时票数。
74
+ 4. 重新启用后点击「提交回答」。按钮读取 `choice` 与 `comment` 的快照,成功后正文和可见组件更新计数。备注在统计刷新时保留。
75
+
76
+ ## 代码位置
77
+
78
+ | 路径 | 作用 |
79
+ | --- | --- |
80
+ | `sample/document.reactive.md` | 外部变量、动态计票正文、提交按钮和两个按可见性订阅的组件。 |
81
+ | `src/components.tsx` | `defineLocalComponent` 清单、`defineReactComponent` 实现、订阅 effect、`createReactHost` 装配。 |
82
+ | `src/host.ts` | 宿主通道注册表、计票消息到外部变量的映射、参与者标识和连接统计。 |
83
+ | `src/main.tsx` | 页面外壳,通过 `externalValues` 控制统计组件可见性,展示连接记录。 |
84
+ | `vite.config.ts` | 公开入口别名、`--mode http` 的受控端点。 |
85
+
86
+ 两个订阅组件都读 `context.visible`,并在 effect 里返回订阅的取消函数:
87
+
88
+ ```tsx
89
+ useEffect(() => {
90
+ if (!visible || network === undefined) return
91
+ return network.subscribe(channel, (event) => {
92
+ if (event.type === 'data' && isCounts(event.value)) setCounts(event.value)
93
+ if (event.type === 'error') setProblem(event.error.message)
94
+ })
95
+ }, [network, channel, visible])
96
+ ```
97
+
98
+ `network` 来自 `context.services.network`,在该文档会话内保持同一引用,所以普通
99
+ 重渲染不会退订。组件看不到地址、请求头或凭据。隐藏或卸载组件时 effect 清理,
100
+ 运行时在最后一个监听者离开后关闭连接并取消重连计时器。
101
+
102
+ ## HTTP 接线
103
+
104
+ `src/host.ts` 的 HTTP 分支就是下面这段;`--mode http` 只负责提供端点:
105
+
106
+ ```ts
107
+ import { httpSubmit, sseStream } from 'reactive-md/runtime/browser'
108
+
109
+ const participant = crypto.randomUUID().replaceAll('-', '')
110
+
111
+ const network = {
112
+ channels: {
113
+ answers: {
114
+ submit: httpSubmit({
115
+ endpoint: '/api/survey/answers',
116
+ validate: payload => payload.choice === 'yes' || payload.choice === 'no',
117
+ headers: { 'X-Survey-Participant': participant },
118
+ // 可选:用服务端错误信息替换纯状态码摘要。
119
+ interpret: response => response.status >= 400 && response.status < 500 ? {
120
+ ok: false,
121
+ error: { code: 'rejected', message: `HTTP ${response.status}` },
122
+ } : undefined,
123
+ }),
124
+ },
125
+ results: {
126
+ subscribe: sseStream({
127
+ endpoint: '/api/survey/results/events',
128
+ validate: isCounts,
129
+ }),
130
+ mapExternalValues: mapCounts,
131
+ },
132
+ },
133
+ }
134
+ ```
135
+
136
+ `mapCounts` 将宿主校验过的 `{ yes, no }` 映射为 `votesYes`、`votesNo` 和 `votesReady`。文档直接用这三个只读变量计算总票数、控制正文何时出现并显示结果。
137
+
138
+ `httpSubmit` 默认 POST JSON,并按 `2xx` 确认、`4xx` 明确拒绝、其余为未确认;
139
+ `interpret` 返回 `undefined` 时沿用这套规则。`timeoutMs` 默认 15 秒,覆盖等待响应和读取响应体。
140
+ 配置 `interpret` 时,适配器按 `maxResponseBytes` 流式限制响应体,默认 64 KiB。
141
+ 超时、超限或读不到完整确认时返回 `unconfirmed`,按钮可用原幂等键重试。
142
+
143
+ 需要在自定义组件里展示回执时,宿主可以在 `interpret` 中校验服务端返回的业务字段,只选取组件需要的数据。例如,报名端点可以返回 `{ ok: true, data: { registrationId } }`。组件调用 `network.submit()`,在 `result.ok` 为真时读取可选的 `result.data`。
144
+
145
+ 示例后端按 `X-Survey-Participant`、提交操作和 `Idempotency-Key` 保存首次计票结果。
146
+ 同键同载荷返回首次快照,同键不同载荷返回 409。记录保存在当前开发服务进程中,最多 1024 条。
147
+ 生产接入应使用服务端认证会话确定用户身份,并将幂等记录与业务写入放在同一事务中。
148
+
149
+ `sseStream` 的重连由
150
+ 客户端的 `EventSource` 负责;最后一个监听者离开时适配器移除监听并关闭它。
151
+ `validate` 在发送前与分发前由运行时调用。
152
+
153
+ ## WebSocket / WebRTC 的确认映射
154
+
155
+ 两个双向适配器使用同一套 JSON 消息(`src/runtime-services/browser/duplex.ts`):
156
+
157
+ | 方向 | 消息 | 关联方式 |
158
+ | --- | --- | --- |
159
+ | 客户端提交 | `{"type":"submit","requestId":"1","payload":{...},"idempotencyKey":"..."}` | `requestId` 由运行时生成。 |
160
+ | 服务端确认 | `{"type":"ack","requestId":"1"}` | 匹配同一 `requestId`,提交返回 `{ok:true}`。 |
161
+ | 服务端拒绝 | `{"type":"reject","requestId":"1","message":"..."}` | 返回 `rejected`,`message` 为可展示摘要。 |
162
+ | 服务端推送 | `{"type":"data","value":...}` | 不含请求标识,交给入站校验后广播给监听者。 |
163
+
164
+ 替换工厂即可复用同一套组件与通道名:
165
+
166
+ ```ts
167
+ import { webSocketChannel, webRtcChannel } from 'reactive-md/runtime/browser'
168
+
169
+ const resultsOverWebSocket = webSocketChannel({
170
+ endpoint: 'wss://survey.example/events',
171
+ validateSubmit: payload => payload.choice === 'yes' || payload.choice === 'no',
172
+ validateSubscribe: value => Number.isInteger(value?.yes),
173
+ // reconnect 默认关闭;需要时传 { delayMs, maxDelayMs, attempts }。
174
+ })
175
+
176
+ const answersOverDataChannel = webRtcChannel({
177
+ endpoint: 'peer:survey-host',
178
+ validateSubmit: validateAnswer,
179
+ // 宿主负责信令、认证和对端选择;适配器只使用交回的通道。
180
+ connect: async (endpoint, signal) => hostPeer(endpoint, signal),
181
+ })
182
+ ```
183
+
184
+ - 一条连接承载该会话的提交与订阅。最后一个订阅者离开后,仍有待确认提交时
185
+ 连接保持;确认或超时后释放。
186
+ - 超时(默认 15 秒)、断线或重连后都不自动重放提交;调用方拿到
187
+ `unconfirmed` 后可手动重试,并复用同一 `idempotencyKey`。
188
+ - `data` 与 `ack`/`reject` 共用一个消息通道,`data` 不带 `requestId`。
189
+ - WebRTC 的 `release` 由宿主提供;适配器只移除自己的监听并调用它,不会关闭
190
+ 借出的数据通道或 PeerConnection。
191
+
192
+ ## 类型检查
193
+
194
+ 在仓库根目录执行:
195
+
196
+ ```sh
197
+ npx tsc -p examples/network-survey/tsconfig.json --noEmit
198
+ ```
199
+
200
+ `tsconfig.json` 用 `paths` 指向仓库源码,因此不依赖已发布的类型包。
@@ -0,0 +1,49 @@
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">
6
+ <title>Reactive MD 命名通道问卷示例</title>
7
+ <style>
8
+ :root { color-scheme: light dark; }
9
+ body {
10
+ margin: 0 auto;
11
+ padding: 2rem 1rem 4rem;
12
+ max-width: 52rem;
13
+ font-family: system-ui, sans-serif;
14
+ background: #f6f5f3;
15
+ color: #111;
16
+ }
17
+ @media (prefers-color-scheme: dark) {
18
+ body { background: #151618; color: #f2f1ef; }
19
+ }
20
+ .survey-page-title { margin: 0 0 1.5rem; font-size: 1.125rem; letter-spacing: 0.01em; }
21
+ .survey-host-ledger {
22
+ margin-top: 2rem;
23
+ padding: 1rem 1.25rem;
24
+ border: 1px solid #d6d4d2;
25
+ border-radius: 12px;
26
+ background: #fff;
27
+ }
28
+ @media (prefers-color-scheme: dark) {
29
+ .survey-host-ledger { background: #1c1d20; border-color: #34363a; }
30
+ }
31
+ .survey-host-ledger h2 { margin: 0 0 0.75rem; font-size: 1rem; }
32
+ .survey-host-ledger dl {
33
+ display: grid;
34
+ grid-template-columns: max-content 1fr;
35
+ gap: 0.35rem 1rem;
36
+ margin: 0;
37
+ }
38
+ .survey-host-ledger div { display: contents; }
39
+ .survey-host-ledger dt { color: #6f6c68; }
40
+ .survey-host-ledger dd { margin: 0; font-variant-numeric: tabular-nums; }
41
+ .survey-host-ledger p { margin: 0.9rem 0 0; color: #55524e; font-size: 0.875rem; line-height: 1.5; }
42
+ .survey-host-ledger code { font-size: 0.8125rem; }
43
+ </style>
44
+ </head>
45
+ <body>
46
+ <div id="app"></div>
47
+ <script type="module" src="/src/main.tsx"></script>
48
+ </body>
49
+ </html>
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "reactive-md-network-survey",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "Runnable Reactive MD survey: one submit-button posting answers and two custom components subscribing to shared results.",
7
+ "license": "MIT",
8
+ "scripts": {
9
+ "dev": "vite --config vite.config.ts",
10
+ "dev:http": "vite --config vite.config.ts --mode http",
11
+ "build": "vite build --config vite.config.ts",
12
+ "typecheck": "tsc --noEmit"
13
+ },
14
+ "dependencies": {
15
+ "reactive-md": "^0.8.0",
16
+ "react": "^19.0.0",
17
+ "react-dom": "^19.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/react": "^19.0.0",
21
+ "@types/react-dom": "^19.0.0",
22
+ "@vitejs/plugin-react": "^6.1.2",
23
+ "typescript": "^7.0.0",
24
+ "vite": "^8.0.0"
25
+ }
26
+ }
@@ -0,0 +1,51 @@
1
+ # 命名通道问卷
2
+
3
+ <external name="showTally" type="boolean">
4
+ <external name="showFeed" type="boolean">
5
+ <external name="votesReady" type="boolean">
6
+ <external name="votesYes" type="number">
7
+ <external name="votesNo" type="number">
8
+ <computed name="votesTotal" value="{{ votesYes + votesNo }}">
9
+
10
+ 这份文档只引用通道名,不包含地址、请求头或令牌。宿主在 `src/host.ts` 里决定
11
+ `answers` 如何提交、`results` 来自哪里;文档换一个宿主就换一套接线。
12
+
13
+ ## 你的回答
14
+
15
+ <panel title="问卷">
16
+
17
+ <select bind="choice" label="你会参加吗?" initial="yes">
18
+ <option value="yes">会来</option>
19
+ <option value="no">不来</option>
20
+ </select>
21
+
22
+ <textarea bind="comment" label="补充说明" rows="2" placeholder="可以留空">
23
+
24
+ <submit-button channel="answers" fields="choice comment" label="提交回答">
25
+
26
+ </panel>
27
+
28
+ 按钮一次读取 `choice` 和 `comment`。页面里再加输入框不会改变提交内容;提交
29
+ 失败时输入保留,可以修改后重试。
30
+
31
+ ## 实时统计
32
+
33
+ <if when="{{ votesReady }}">
34
+
35
+ 已有 **{{ votesTotal }}** 人投票,其中 {{ votesYes }} 人会参加。
36
+
37
+ </if>
38
+
39
+ 正文的只读值与两个计票组件共享 `results` 连接。隐藏计票面板后,正文仍会收到统计更新。
40
+
41
+ <if when="{{ showTally }}">
42
+
43
+ <vote-tally channel="results" label="实时计票">
44
+
45
+ </if>
46
+
47
+ <if when="{{ showFeed }}">
48
+
49
+ <vote-feed channel="results" label="计票明细">
50
+
51
+ </if>