reactive-md 0.5.3 → 0.6.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 (141) hide show
  1. package/CHANGELOG-ch.md +195 -165
  2. package/CHANGELOG.md +195 -165
  3. package/CONTRIBUTING-ch.md +67 -62
  4. package/CONTRIBUTING.md +69 -64
  5. package/README-ch.md +157 -155
  6. package/README-en.md +184 -181
  7. package/README.md +184 -181
  8. package/SECURITY-ch.md +81 -81
  9. package/SECURITY.md +81 -81
  10. package/THIRD_PARTY_NOTICES.md +585 -1
  11. package/bin/reactive-md.mjs +39 -39
  12. package/cli/args.mjs +181 -181
  13. package/cli/assets.mjs +390 -390
  14. package/cli/build.mjs +268 -268
  15. package/cli/document.mjs +130 -130
  16. package/cli/errors.mjs +61 -61
  17. package/cli/fs-utils.mjs +133 -133
  18. package/cli/glob.mjs +203 -203
  19. package/cli/help.mjs +138 -138
  20. package/cli/lint.mjs +177 -177
  21. package/cli/main.mjs +55 -55
  22. package/cli/migrate.mjs +368 -368
  23. package/cli/package.mjs +210 -210
  24. package/dist-library/{authoring-DJJjKYg9.js → authoring-BEVyth5X.js} +58 -58
  25. package/dist-library/compiler-Cm3ppMxG.js +46044 -0
  26. package/dist-library/react-Bh7_oxZp.js +59655 -0
  27. package/dist-library/reactive-md-authoring.js +2 -2
  28. package/dist-library/reactive-md-editor.js +13 -0
  29. package/dist-library/reactive-md-print.css +284 -284
  30. package/dist-library/reactive-md-react-unstyled.js +1 -1
  31. package/dist-library/reactive-md-react.js +1 -1
  32. package/dist-library/reactive-md.css +1 -1
  33. package/dist-library/reactive-md.js +123 -123
  34. package/dist-library/{runtime-DXtle_6c.js → runtime-DlFYQ4s_.js} +151 -151
  35. package/dist-library/types/editor/types.d.ts +2 -0
  36. package/dist-library/types/local/code-block.d.ts +3 -1
  37. package/dist-library/types/local/code-languages.d.ts +7 -0
  38. package/dist-library/types/local/compiled-data.d.ts +6 -0
  39. package/dist-library/types/local/compiler.d.ts +1 -0
  40. package/dist-library/types/local/diagnostics.d.ts +31 -0
  41. package/dist-library/types/local/diagram-layout.d.ts +69 -0
  42. package/dist-library/types/local/html-names.d.ts +6 -0
  43. package/dist-library/types/local/html-table.d.ts +25 -0
  44. package/dist-library/types/local/math-display.d.ts +22 -22
  45. package/dist-library/types/local/math-view.d.ts +6 -7
  46. package/dist-library/types/local/table-surface.d.ts +10 -0
  47. package/dist-library/types/local/types.d.ts +2 -0
  48. package/dist-library/types/local/visuals.d.ts +9 -0
  49. package/dist-standalone/reactive-md-standalone.css +1 -1
  50. package/dist-standalone/reactive-md-standalone.js +331 -51
  51. package/docs/README.md +84 -0
  52. package/docs/{compatibility-ch.md → compatibility/compatibility-ch.md} +121 -109
  53. package/docs/{compatibility-en.md → compatibility/compatibility-en.md} +121 -109
  54. package/docs/{source-versioning-ch.md → compatibility/source-versioning-ch.md} +159 -159
  55. package/docs/{source-versioning-en.md → compatibility/source-versioning-en.md} +159 -159
  56. package/docs/{component-development-ch.md → development/component-development-ch.md} +210 -210
  57. package/docs/{component-development-en.md → development/component-development-en.md} +210 -210
  58. package/docs/{component-protocol-ch.md → development/component-protocol-ch.md} +747 -747
  59. package/docs/{component-protocol-en.md → development/component-protocol-en.md} +747 -747
  60. package/docs/{performance-ch.md → development/performance-ch.md} +76 -76
  61. package/docs/{performance-en.md → development/performance-en.md} +76 -76
  62. package/docs/{releasing-ch.md → development/releasing-ch.md} +108 -108
  63. package/docs/{releasing-en.md → development/releasing-en.md} +108 -108
  64. package/docs/guides/local-guide-ch.md +513 -0
  65. package/docs/guides/local-guide-en.md +513 -0
  66. package/docs/{author-tools-ch.md → integration/author-tools-ch.md} +57 -57
  67. package/docs/{author-tools-en.md → integration/author-tools-en.md} +57 -57
  68. package/docs/{editor-ch.md → integration/editor-ch.md} +7 -6
  69. package/docs/{editor-en.md → integration/editor-en.md} +7 -6
  70. package/docs/{local-integration-ch.md → integration/local-integration-ch.md} +33 -15
  71. package/docs/{local-integration-en.md → integration/local-integration-en.md} +33 -15
  72. package/docs/{shareable-export-ch.md → integration/shareable-export-ch.md} +221 -209
  73. package/docs/{shareable-export-en.md → integration/shareable-export-en.md} +223 -211
  74. package/docs/{computations-formatting-ch.md → reference/computations-formatting-ch.md} +87 -87
  75. package/docs/{computations-formatting-en.md → reference/computations-formatting-en.md} +87 -87
  76. package/docs/{constraints-collections-ch.md → reference/constraints-collections-ch.md} +84 -84
  77. package/docs/{constraints-collections-en.md → reference/constraints-collections-en.md} +84 -84
  78. package/docs/{diagnostics-counting-ch.md → reference/diagnostics-counting-ch.md} +104 -84
  79. package/docs/{diagnostics-counting-en.md → reference/diagnostics-counting-en.md} +104 -84
  80. package/docs/{html-compatibility-ch.md → reference/html-compatibility-ch.md} +42 -4
  81. package/docs/{html-compatibility-en.md → reference/html-compatibility-en.md} +42 -4
  82. package/docs/{local-components-v2-ch.md → reference/local-components-v2-ch.md} +138 -138
  83. package/docs/{local-components-v2-en.md → reference/local-components-v2-en.md} +104 -104
  84. package/docs/{local-interaction-syntax-ch.md → reference/local-interaction-syntax-ch.md} +515 -492
  85. package/docs/{local-interaction-syntax-en.md → reference/local-interaction-syntax-en.md} +511 -488
  86. package/docs/{theme-protocol-ch.md → reference/theme-protocol-ch.md} +107 -107
  87. package/docs/{theme-protocol-en.md → reference/theme-protocol-en.md} +107 -107
  88. package/docs/{release-0.4.0-ch.md → releases/release-0.4.0-ch.md} +89 -89
  89. package/docs/{release-0.4.0-en.md → releases/release-0.4.0-en.md} +89 -89
  90. package/docs/{release-0.4.1-ch.md → releases/release-0.4.1-ch.md} +23 -23
  91. package/docs/{release-0.4.1-en.md → releases/release-0.4.1-en.md} +23 -23
  92. package/docs/{release-0.5.0-ch.md → releases/release-0.5.0-ch.md} +4 -4
  93. package/docs/{release-0.5.0-en.md → releases/release-0.5.0-en.md} +4 -4
  94. package/docs/{release-0.5.1-ch.md → releases/release-0.5.1-ch.md} +4 -4
  95. package/docs/{release-0.5.1-en.md → releases/release-0.5.1-en.md} +4 -4
  96. package/docs/{release-0.5.2-ch.md → releases/release-0.5.2-ch.md} +3 -3
  97. package/docs/{release-0.5.2-en.md → releases/release-0.5.2-en.md} +3 -3
  98. package/docs/{release-0.5.3-ch.md → releases/release-0.5.3-ch.md} +1 -1
  99. package/docs/{release-0.5.3-en.md → releases/release-0.5.3-en.md} +1 -1
  100. package/docs/releases/release-0.6.0-ch.md +57 -0
  101. package/docs/releases/release-0.6.0-en.md +57 -0
  102. package/docs/releases/release-0.6.1-ch.md +27 -0
  103. package/docs/releases/release-0.6.1-en.md +27 -0
  104. package/examples/conformance/README.md +53 -53
  105. package/examples/conformance/component-protocol-1.json +482 -482
  106. package/examples/conformance/component-protocol-1.schema.json +76 -76
  107. package/examples/conformance/local-draft-1.json +50 -50
  108. package/examples/conformance/local-draft-2.json +212 -212
  109. package/examples/integration/README.md +47 -45
  110. package/examples/integration/core/index.mjs +32 -32
  111. package/examples/integration/worker/index.html +19 -19
  112. package/examples/integration/worker/main.js +61 -61
  113. package/examples/integration/worker/package.json +13 -13
  114. package/examples/integration/worker/worker.js +3 -3
  115. package/examples/local/README.md +74 -74
  116. package/examples/local/charts.reactive.md +73 -73
  117. package/examples/local/html-compat.reactive.md +19 -0
  118. package/examples/local/recipes/invoice-zh.reactive.md +36 -36
  119. package/examples/local/recipes/invoice.reactive.md +36 -36
  120. package/examples/local/recipes/workshop-zh.reactive.md +33 -33
  121. package/examples/local/recipes/workshop.reactive.md +33 -33
  122. package/examples/local/showcase/README.md +25 -25
  123. package/examples/local/showcase/explore.reactive.md +102 -102
  124. package/examples/local/showcase/flow.reactive.md +86 -86
  125. package/examples/local/showcase/forms.reactive.md +126 -126
  126. package/examples/local/showcase/functions.reactive.md +119 -119
  127. package/examples/local/showcase/layout.reactive.md +100 -100
  128. package/examples/local/showcase/statistics.reactive.md +108 -108
  129. package/examples/local/showcase/tasks.reactive.md +89 -89
  130. package/examples/local/showcase/zh/explore.reactive.md +102 -102
  131. package/examples/local/showcase/zh/flow.reactive.md +86 -86
  132. package/examples/local/showcase/zh/forms.reactive.md +126 -126
  133. package/examples/local/showcase/zh/functions.reactive.md +119 -119
  134. package/examples/local/showcase/zh/layout.reactive.md +100 -100
  135. package/examples/local/showcase/zh/statistics.reactive.md +108 -108
  136. package/examples/local/showcase/zh/tasks.reactive.md +89 -89
  137. package/package.json +152 -145
  138. package/dist-library/compiler-UyPwGzJZ.js +0 -22109
  139. package/dist-library/react-fizgU3i8.js +0 -12764
  140. package/docs/local-guide-ch.md +0 -967
  141. package/docs/local-guide-en.md +0 -967
@@ -1,211 +1,223 @@
1
- # Shareable documents and static export
2
-
3
- This guide covers the single-file HTML exporter introduced with `local-draft-2`. It complements [Local mode integration](local-integration-en.md), the [syntax reference](local-interaction-syntax-en.md), [Source revisions and migration](source-versioning-en.md) and the [0.4.0 release notes](release-0.4.0-en.md).
4
-
5
- ## Output modes
6
-
7
- The rules below describe default ReactiveMD documents. Native HTML interactive export preserves `compileOptions` and whole-document HTML routing; static export disables author JavaScript. These documents have no ReactiveMD parameters. See [HTML compatibility](html-compatibility-en.md) for capability flags, isolation and the temporary routing policy.
8
-
9
- **Interactive HTML** is one self-contained `.html` file. It embeds the original source, the standalone browser runtime, React 19, the current stylesheet and print styles. Readers can open it through `file://` without Node.js, React, the reactive-md package or network access.
10
-
11
- The first rendered pass is static. After the embedded runtime hydrates it, controls become interactive. With JavaScript disabled the same static values, tables, formulas and charts remain readable. Refreshing restores the exported baseline; the reader's changes are not persisted.
12
-
13
- **Static HTML** (`--mode static`) contains read-only values and no executable script cargo. It is intended for archives, static sites and email attachments. Interactive action buttons, form widgets and the reset action are removed.
14
-
15
- Both modes use the same renderer as the React integration, so conditional content, interpolation, tables, formulas, charts and layout follow the runtime state.
16
-
17
- ## CLI
18
-
19
- The package exposes the `reactive-md` command. HTML builds require React 19 and React DOM in the project that installs the package; `lint` and `migrate` do not.
20
-
21
- ```sh
22
- reactive-md build doc.reactive.md -o doc.html
23
- reactive-md build doc.reactive.md -o doc.html --mode static
24
- reactive-md build doc.reactive.md -o doc.html --state-file doc.state.json
25
- reactive-md build doc.reactive.md -o doc.html --assets omit
26
- reactive-md lint "docs/**/*.reactive.md"
27
- reactive-md lint "docs/**/*.reactive.md" --json --strict
28
- ```
29
-
30
- Build options:
31
-
32
- | Option | Meaning |
33
- | --- | --- |
34
- | `-o, --output <file>` | Required output path. Its parent directory must already exist. |
35
- | `--mode interactive\|static` | Output mode. Default: `interactive`. |
36
- | `--state-file <json>` | Use a validated `reactive-md-state/v1` file as the starting and reset baseline. |
37
- | `--assets inline\|omit` | Inline verified local raster images (default) or leave the renderer's alt fallback. |
38
- | `--asset-root <dir>` | Additional local directory that relative image paths may resolve inside. |
39
- | `--locale en\|zh` | Renderer labels and validation messages. Default: `en`. |
40
- | `--color-scheme auto\|light\|dark` | Document color mode. Default: `auto`. |
41
- | `--title <text>` | Override the HTML title. The first heading or the input filename is used otherwise. |
42
- | `--strict` | Fail on compiler warnings; with `--assets omit`, fail when images are omitted. |
43
-
44
- Exit codes are separate so build automation can distinguish failures:
45
-
46
- | Code | Meaning |
47
- | --- | --- |
48
- | `0` | Success |
49
- | `2` | Usage or argument error |
50
- | `3` | Document compile, render, React, or packaged-artifact failure |
51
- | `4` | Input/output file failure |
52
- | `5` | Asset or security-policy failure |
53
-
54
- The CLI does not use a current preview implicitly. `--state-file` is the only way to select a non-initial baseline. `format` is not part of this release.
55
-
56
- ## Migrating source
57
-
58
- `reactive-md migrate` moves one source revision declaration to `local-draft-2`:
59
-
60
- ```sh
61
- reactive-md migrate old.reactive.md --from local-draft-1 -o new.reactive.md
62
- reactive-md migrate old.reactive.md --check --json
63
- ```
64
-
65
- By default it prints the migrated source to standard output. `-o` creates a new file with exclusive creation and refuses any existing path, including the input. `--check` never writes. `--json` prints a structured report and nothing else. `--accept-semantic-changes` allows the text-control length change and reports warnings; `--locale en|zh` selects the display language.
66
-
67
- A migration exits `1` when blocked and `0` on success. `--check` exits `1` when changes are needed or blocked, and `0` when the source is current. Usage and I/O errors exit `2`. The command does not overwrite in place and has no batch or `--write` mode. See [Source revisions and migration](source-versioning-en.md) for the checks, preserved bytes and state-digest consequences.
68
-
69
- ## Starting values and state files
70
-
71
- By default, the exported baseline is the document's author initial values. This keeps builds repeatable and avoids leaking trial inputs.
72
-
73
- A state file has this versioned shape:
74
-
75
- ```json
76
- {
77
- "format": "reactive-md-state/v1",
78
- "syntax": "local-draft-2",
79
- "sourceDigest": "fnv1a32:0123abcd",
80
- "parameters": {
81
- "people": 7,
82
- "plan": "pro"
83
- },
84
- "generator": { "name": "example-host", "version": "1.0.0" }
85
- }
86
- ```
87
-
88
- Only public, serializable binding values are stored. The file identifies the document through `sourceDigest` and the language revision through `syntax`. Internal bindings (names beginning with `@`), revisions, node IDs, AST data, timers, open panels and focus are never persisted; internal snapshot keys and IDs are implementation details, not a storage format.
89
-
90
- Resolution verifies the source digest, syntax revision, exact public parameter set and every value against the document's constraints. Unknown, missing or invalid parameters reject the file with a named diagnostic; a mismatched file is never partially applied. Slot controls such as `<range-slider>` are validated atomically.
91
-
92
- The selected state becomes the document's reset baseline. Opening, refreshing and the panel reset action therefore return to the exported values, not to a different hidden default.
93
-
94
- Hosts can create and apply the same file without the CLI:
95
-
96
- ```ts
97
- import { exportLocalState, importLocalState } from 'reactive-md';
98
-
99
- const file = exportLocalState(runtime, { name: 'example-host', version: '1.0.0' });
100
- const saved = JSON.stringify(file);
101
-
102
- const diagnostics = importLocalState(runtime, saved);
103
- ```
104
-
105
- `exportLocalState` reads public parameters only. `importLocalState` validates the source digest, syntax, parameter set and constraints, then applies the values; a failed import leaves the runtime unchanged. Both are explicit host calls: the runtime still does not save or send state by itself. Use `resolveLocalState(document, input)` to validate without touching a live runtime.
106
-
107
- The demo's export dialog can download the current preview parameters as a state file for a later CLI build. The lower-level `createLocalStateFile`, `parseLocalState`, `applyLocalState` and `serializeLocalState` remain available from `reactive-md`.
108
-
109
- ## Images
110
-
111
- Offline export defaults to `--assets inline`:
112
-
113
- - Only relative paths that resolve inside the document directory, or an explicit `--asset-root`, are read.
114
- - Absolute paths, URL schemes, protocol-relative URLs, backslashes, path traversal and symlink escapes are rejected.
115
- - Remote images are never fetched.
116
- - PNG, JPEG, GIF and WebP are detected by file contents; SVG, forged MIME types and unknown formats are rejected.
117
- - Files are limited to 8 MiB each, 24 MiB total and 64 distinct payloads. Identical content is deduplicated.
118
- - Alt text is preserved. A failure stops the build by default. `--assets omit` is the explicit opt-out and leaves the alt fallback.
119
-
120
- The renderer's global security boundary is unchanged: images are still rejected by default unless a host URL policy explicitly allows them. The exporter supplies a host policy and image resolver after it has verified each local file.
121
-
122
- ## Single-file security and printing
123
-
124
- The HTML shell includes:
125
-
126
- - a CSP that disallows connections, frames, objects, base URL changes and form submission while allowing the inline stylesheet/runtime and `data:` images;
127
- - HTML- and script-context escaping for JSON, source, titles and license notices;
128
- - the MIT and third-party notices in a non-executed `<template>`;
129
- - no CDN or remote stylesheet, font or runtime.
130
-
131
- Clicking an ordinary external link can still navigate, but opening the document itself performs no remote request. The exporter is not a sandbox for fully untrusted authors; use a sandboxed iframe when that threat model applies.
132
-
133
- Printing does not require a temporary state switch. The current runtime values are rendered in print-only nodes, so `Ctrl+P` prints the state the reader currently sees. Print CSS forces a light paper theme, hides toolbars and controls, uses printer-owned page margins, keeps headings with following content, repeats table headers, wraps long code and URLs, and constrains charts to page width. Static HTML already contains only read-only values.
134
-
135
- ## Standalone runtime API
136
-
137
- The build emits `dist-standalone/reactive-md-standalone.js` (IIFE, global `ReactiveMD`) and `reactive-md-standalone.css`. Load the stylesheet and script as classic browser assets:
138
-
139
- ```html
140
- <link rel="stylesheet" href="reactive-md-standalone.css">
141
- <script src="reactive-md-standalone.js"></script>
142
- ```
143
-
144
- Programmatic mounting:
145
-
146
- ```js
147
- const handle = ReactiveMD.mount(document.getElementById('doc'), {
148
- source: '# Hello\n\n<slider bind="n" label="Count" initial="2">\n\nValue: {{ n }}',
149
- locale: 'en',
150
- colorScheme: 'auto',
151
- });
152
- handle.getState(); // reactive-md-state/v1 snapshot
153
- handle.unmount();
154
- ```
155
-
156
- `ReactiveMD.mountAll(root)` scans only once for safe auto-mount payloads:
157
-
158
- ```html
159
- <div id="doc"></div>
160
- <script type="application/reactive-md+json" data-reactive-md-auto>
161
- {"version":1,"target":"doc","source":"# Hello","state":{"format":"reactive-md-state/v1","syntax":"local-draft-2","sourceDigest":"fnv1a32:01209266","parameters":{}},"locale":"en","colorScheme":"auto","hydrate":false}
162
- </script>
163
- ```
164
-
165
- Targets are resolved by `id`, never by an interpolated selector. Payload source is data, not executable markup. Raw `<script type="text/reactive-md">` text is deliberately not interpreted.
166
-
167
- ### `<reactive-md-doc>`
168
-
169
- The IIFE registers a light-DOM custom element. Simple options are attributes; complex options are DOM properties.
170
-
171
- ```html
172
- <reactive-md-doc src="./doc.reactive.md" locale="en" color-scheme="auto"></reactive-md-doc>
173
- ```
174
-
175
- - Attributes: `src`, `source`, `locale`, `color-scheme`, `theme`.
176
- - Properties: `source`, `state`, `urlPolicy`, `imageResolver`, `themes`.
177
- - Events: `reactive-md-diagnostics` and `reactive-md-state-change`.
178
- - `src` uses `fetch` with cancellation; an explicit source avoids network access.
179
- - Disconnecting aborts fetches, removes subscriptions and the React root, and disposes the runtime. Two elements with the same source have independent state.
180
-
181
- The element uses Light DOM so the existing document CSS, heading anchors and print styles apply. Shadow DOM is intentionally out of scope for this release.
182
-
183
- ## Security boundaries
184
-
185
- - Core and React entry points keep React external. Only the standalone IIFE bundles React.
186
- - The core entry remains React-free.
187
- - State export and import use only public binding names and validated values.
188
- - Exported HTML does not persist a reader's changes.
189
- - The demo preview still blocks images unless a host policy is supplied; the demo export dialog disables HTML export when a document contains images because it has no asset root. Use the CLI for image-bearing documents.
190
- - The export format version is `reactive-md-html/v1`; inspect it in the generated meta tags.
191
-
192
- ## Bundle baseline
193
-
194
- `npm run test:shareable` records the standalone artifact size and fails above these regression alarms:
195
-
196
- | Artifact | Current baseline | Alarm |
197
- | --- | --- | --- |
198
- | `reactive-md-standalone.js` | ≈925 kB (≈276 kB gzip) | 1024 KiB / 320 KiB gzip |
199
- | `reactive-md-standalone.css` | ≈81.2 kB (≈13.5 kB gzip) | 80 KiB / 20 KiB gzip |
200
-
201
- The 0.5 baseline includes the syntax highlighter and common language grammars for offline use.
202
-
203
- Sizes vary slightly with the minifier and React patch release. The alarm is intentionally well above normal noise while catching a React or renderer duplication regression. The full generated HTML also contains the source, notices and inline images, so it is larger than this baseline.
204
-
205
- ## Current scope
206
-
207
- Included: CLI `build`/`lint`/`migrate`, interactive and static HTML, state files, local raster inlining, print output, standalone mount APIs, auto-mount, and the Web Component.
208
-
209
- Not included in this release: `format`, UMD, remote image fetching, SVG inlining, framework plugins (Vite, Astro, Docusaurus, Next.js), Shadow DOM, and general SSR hydration guarantees outside the single-file export path.
210
-
211
- Single-file static-first hydration is covered by the Playwright Chromium checks and local Edge checks. Firefox, Safari/WebKit and general server-side hydration remain unverified and are not claimed as supported.
1
+ # Shareable documents and static export
2
+
3
+ This guide covers the single-file HTML exporter introduced with `local-draft-2`. It complements [Local mode integration](local-integration-en.md), the [syntax reference](../reference/local-interaction-syntax-en.md), [Source revisions and migration](../compatibility/source-versioning-en.md) and the [0.4.0 release notes](../releases/release-0.4.0-en.md).
4
+
5
+ ## Output modes
6
+
7
+ The rules below describe default ReactiveMD documents. Native HTML interactive export preserves `compileOptions` and whole-document HTML routing; static export disables author JavaScript. These documents have no ReactiveMD parameters. See [HTML compatibility](../reference/html-compatibility-en.md) for capability flags, isolation and the temporary routing policy.
8
+
9
+ **Interactive HTML** is one self-contained `.html` file. It embeds the original source, the standalone browser runtime, React 19, the current stylesheet and print styles. Readers can open it through `file://` without Node.js, React, the reactive-md package or network access.
10
+
11
+ The first rendered pass is static. After the embedded runtime hydrates it, controls become interactive. With JavaScript disabled the same static values, tables, formulas and charts remain readable. Refreshing restores the exported baseline; the reader's changes are not persisted.
12
+
13
+ **Static HTML** (`--mode static`) contains read-only values and no executable script cargo. It is intended for archives, static sites and email attachments. Interactive action buttons, form widgets and the reset action are removed.
14
+
15
+ Both modes use the same renderer as the React integration, so conditional content, interpolation, tables, formulas, charts and layout follow the runtime state.
16
+
17
+ ## CLI
18
+
19
+ The package exposes the `reactive-md` command. HTML builds require React 19 and React DOM in the project that installs the package; `lint` and `migrate` do not.
20
+
21
+ ```sh
22
+ reactive-md build doc.reactive.md -o doc.html
23
+ reactive-md build doc.reactive.md -o doc.html --mode static
24
+ reactive-md build doc.reactive.md -o doc.html --state-file doc.state.json
25
+ reactive-md build doc.reactive.md -o doc.html --assets omit
26
+ reactive-md lint "docs/**/*.reactive.md"
27
+ reactive-md lint "docs/**/*.reactive.md" --json --strict
28
+ ```
29
+
30
+ Build options:
31
+
32
+ | Option | Meaning |
33
+ | --- | --- |
34
+ | `-o, --output <file>` | Required output path. Its parent directory must already exist. |
35
+ | `--mode interactive\|static` | Output mode. Default: `interactive`. |
36
+ | `--state-file <json>` | Use a validated `reactive-md-state/v1` file as the starting and reset baseline. |
37
+ | `--assets inline\|omit` | Inline verified local raster images (default) or leave the renderer's alt fallback. |
38
+ | `--asset-root <dir>` | Additional local directory that relative image paths may resolve inside. |
39
+ | `--locale en\|zh` | Renderer labels and validation messages. Default: `en`. |
40
+ | `--color-scheme auto\|light\|dark` | Document color mode. Default: `auto`. |
41
+ | `--title <text>` | Override the HTML title. The first heading or the input filename is used otherwise. |
42
+ | `--strict` | Fail on compiler warnings; with `--assets omit`, fail when images are omitted. |
43
+
44
+ Exit codes are separate so build automation can distinguish failures:
45
+
46
+ | Code | Meaning |
47
+ | --- | --- |
48
+ | `0` | Success |
49
+ | `2` | Usage or argument error |
50
+ | `3` | Document compile, render, React, or packaged-artifact failure |
51
+ | `4` | Input/output file failure |
52
+ | `5` | Asset or security-policy failure |
53
+
54
+ The CLI does not use a current preview implicitly. `--state-file` is the only way to select a non-initial baseline. `format` is not part of this release.
55
+
56
+ ## Migrating source
57
+
58
+ `reactive-md migrate` moves one source revision declaration to `local-draft-2`:
59
+
60
+ ```sh
61
+ reactive-md migrate old.reactive.md --from local-draft-1 -o new.reactive.md
62
+ reactive-md migrate old.reactive.md --check --json
63
+ ```
64
+
65
+ By default it prints the migrated source to standard output. `-o` creates a new file with exclusive creation and refuses any existing path, including the input. `--check` never writes. `--json` prints a structured report and nothing else. `--accept-semantic-changes` allows the text-control length change and reports warnings; `--locale en|zh` selects the display language.
66
+
67
+ A migration exits `1` when blocked and `0` on success. `--check` exits `1` when changes are needed or blocked, and `0` when the source is current. Usage and I/O errors exit `2`. The command does not overwrite in place and has no batch or `--write` mode. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the checks, preserved bytes and state-digest consequences.
68
+
69
+ ## Starting values and state files
70
+
71
+ By default, the exported baseline is the document's author initial values. This keeps builds repeatable and avoids leaking trial inputs.
72
+
73
+ A state file has this versioned shape:
74
+
75
+ ```json
76
+ {
77
+ "format": "reactive-md-state/v1",
78
+ "syntax": "local-draft-2",
79
+ "sourceDigest": "fnv1a32:0123abcd",
80
+ "parameters": {
81
+ "people": 7,
82
+ "plan": "pro"
83
+ },
84
+ "generator": { "name": "example-host", "version": "1.0.0" }
85
+ }
86
+ ```
87
+
88
+ Only public, serializable binding values are stored. The file identifies the document through `sourceDigest` and the language revision through `syntax`. Internal bindings (names beginning with `@`), revisions, node IDs, AST data, timers, open panels and focus are never persisted; internal snapshot keys and IDs are implementation details, not a storage format.
89
+
90
+ Resolution verifies the source digest, syntax revision, exact public parameter set and every value against the document's constraints. Unknown, missing or invalid parameters reject the file with a named diagnostic; a mismatched file is never partially applied. Slot controls such as `<range-slider>` are validated atomically.
91
+
92
+ The selected state becomes the document's reset baseline. Opening, refreshing and the panel reset action therefore return to the exported values, not to a different hidden default.
93
+
94
+ Hosts can create and apply the same file without the CLI:
95
+
96
+ ```ts
97
+ import { exportLocalState, importLocalState } from 'reactive-md';
98
+
99
+ const file = exportLocalState(runtime, { name: 'example-host', version: '1.0.0' });
100
+ const saved = JSON.stringify(file);
101
+
102
+ const diagnostics = importLocalState(runtime, saved);
103
+ ```
104
+
105
+ `exportLocalState` reads public parameters only. `importLocalState` validates the source digest, syntax, parameter set and constraints, then applies the values; a failed import leaves the runtime unchanged. Both are explicit host calls: the runtime still does not save or send state by itself. Use `resolveLocalState(document, input)` to validate without touching a live runtime.
106
+
107
+ The demo's export dialog can download the current preview parameters as a state file for a later CLI build. The lower-level `createLocalStateFile`, `parseLocalState`, `applyLocalState` and `serializeLocalState` remain available from `reactive-md`.
108
+
109
+ ## Images
110
+
111
+ ### Browser
112
+
113
+ Use **Document images** in the demo to select files, or paste an image into the source editor. Accepted files create a Markdown reference at the selection and appear in the resource list. The list shows each source URL, format, size and whether the document references it; files can be replaced or removed. Imports are checked as a batch: an invalid file leaves the source and manifest unchanged.
114
+
115
+ PNG, JPEG, GIF and WebP are checked by content, declared MIME type and browser decoding. Limits are 8 MiB per image, 24 MiB total and 64 resources. SVG is unsupported. Resources are saved in IndexedDB for the current document and language; a storage warning means they remain available only for this page session.
116
+
117
+ The export dialog lists missing image references and lets you choose a local file for each one, including a local replacement for a remote URL. It never fetches remote images. All references must be supplied before HTML export. Both interactive and static exports inline the referenced files; unused resources stay out of the export. Markdown and state downloads contain no image files.
118
+
119
+ These browser resource controls apply to the ReactiveMD route, including P0 `<img>` elements. Native HTML routing keeps its separate image policy.
120
+
121
+ ### CLI
122
+
123
+ Offline export defaults to `--assets inline`:
124
+
125
+ - Only relative paths that resolve inside the document directory, or an explicit `--asset-root`, are read.
126
+ - Absolute paths, URL schemes, protocol-relative URLs, backslashes, path traversal and symlink escapes are rejected.
127
+ - Remote images are never fetched.
128
+ - PNG, JPEG, GIF and WebP are detected by file contents; SVG, forged MIME types and unknown formats are rejected.
129
+ - Files are limited to 8 MiB each, 24 MiB total and 64 distinct payloads. Identical content is deduplicated.
130
+ - Alt text is preserved. A failure stops the build by default. `--assets omit` is the explicit opt-out and leaves the alt fallback.
131
+
132
+ The renderer's global security boundary is unchanged: images are still rejected by default unless a host URL policy explicitly allows them. The exporter supplies a host policy and image resolver after it has verified each local file.
133
+
134
+ ## Single-file security and printing
135
+
136
+ The HTML shell includes:
137
+
138
+ - a CSP that disallows connections, frames, objects, base URL changes and form submission while allowing the inline stylesheet/runtime and `data:` images;
139
+ - HTML- and script-context escaping for JSON, source, titles and license notices;
140
+ - the MIT and third-party notices in a non-executed `<template>`;
141
+ - no CDN or remote stylesheet, font or runtime.
142
+
143
+ Clicking an ordinary external link can still navigate, but opening the document itself performs no remote request. The exporter is not a sandbox for fully untrusted authors; use a sandboxed iframe when that threat model applies.
144
+
145
+ Printing does not require a temporary state switch. The current runtime values are rendered in print-only nodes, so `Ctrl+P` prints the state the reader currently sees. Print CSS forces a light paper theme, hides toolbars and controls, uses printer-owned page margins, keeps headings with following content, repeats table headers, wraps long code and URLs, and constrains charts to page width. Static HTML already contains only read-only values.
146
+
147
+ ## Standalone runtime API
148
+
149
+ The build emits `dist-standalone/reactive-md-standalone.js` (IIFE, global `ReactiveMD`) and `reactive-md-standalone.css`. Load the stylesheet and script as classic browser assets:
150
+
151
+ ```html
152
+ <link rel="stylesheet" href="reactive-md-standalone.css">
153
+ <script src="reactive-md-standalone.js"></script>
154
+ ```
155
+
156
+ Programmatic mounting:
157
+
158
+ ```js
159
+ const handle = ReactiveMD.mount(document.getElementById('doc'), {
160
+ source: '# Hello\n\n<slider bind="n" label="Count" initial="2">\n\nValue: {{ n }}',
161
+ locale: 'en',
162
+ colorScheme: 'auto',
163
+ });
164
+ handle.getState(); // reactive-md-state/v1 snapshot
165
+ handle.unmount();
166
+ ```
167
+
168
+ `ReactiveMD.mountAll(root)` scans only once for safe auto-mount payloads:
169
+
170
+ ```html
171
+ <div id="doc"></div>
172
+ <script type="application/reactive-md+json" data-reactive-md-auto>
173
+ {"version":1,"target":"doc","source":"# Hello","state":{"format":"reactive-md-state/v1","syntax":"local-draft-2","sourceDigest":"fnv1a32:01209266","parameters":{}},"locale":"en","colorScheme":"auto","hydrate":false}
174
+ </script>
175
+ ```
176
+
177
+ Targets are resolved by `id`, never by an interpolated selector. Payload source is data, not executable markup. Raw `<script type="text/reactive-md">` text is deliberately not interpreted.
178
+
179
+ ### `<reactive-md-doc>`
180
+
181
+ The IIFE registers a light-DOM custom element. Simple options are attributes; complex options are DOM properties.
182
+
183
+ ```html
184
+ <reactive-md-doc src="./doc.reactive.md" locale="en" color-scheme="auto"></reactive-md-doc>
185
+ ```
186
+
187
+ - Attributes: `src`, `source`, `locale`, `color-scheme`, `theme`.
188
+ - Properties: `source`, `state`, `urlPolicy`, `imageResolver`, `themes`.
189
+ - Events: `reactive-md-diagnostics` and `reactive-md-state-change`.
190
+ - `src` uses `fetch` with cancellation; an explicit source avoids network access.
191
+ - Disconnecting aborts fetches, removes subscriptions and the React root, and disposes the runtime. Two elements with the same source have independent state.
192
+
193
+ The element uses Light DOM so the existing document CSS, heading anchors and print styles apply. Shadow DOM is intentionally out of scope for this release.
194
+
195
+ ## Security boundaries
196
+
197
+ - Core and React entry points keep React external. Only the standalone IIFE bundles React.
198
+ - The core entry remains React-free.
199
+ - State export and import use only public binding names and validated values.
200
+ - Exported HTML does not persist a reader's changes.
201
+ - The demo previews and exports images supplied through its document resource list. Missing references block HTML export until files are selected.
202
+ - The export format version is `reactive-md-html/v1`; inspect it in the generated meta tags.
203
+
204
+ ## Bundle baseline
205
+
206
+ `npm run test:shareable` records the standalone artifact size and fails above these regression alarms:
207
+
208
+ | Artifact | Current baseline | Alarm |
209
+ | --- | --- | --- |
210
+ | `reactive-md-standalone.js` | ≈925 kB (≈276 kB gzip) | 1024 KiB / 320 KiB gzip |
211
+ | `reactive-md-standalone.css` | ≈81.2 kB (≈13.5 kB gzip) | 80 KiB / 20 KiB gzip |
212
+
213
+ The 0.5 baseline includes the syntax highlighter and common language grammars for offline use.
214
+
215
+ Sizes vary slightly with the minifier and React patch release. The alarm is intentionally well above normal noise while catching a React or renderer duplication regression. The full generated HTML also contains the source, notices and inline images, so it is larger than this baseline.
216
+
217
+ ## Current scope
218
+
219
+ Included: CLI `build`/`lint`/`migrate`, interactive and static HTML, state files, local raster inlining, print output, standalone mount APIs, auto-mount, and the Web Component.
220
+
221
+ Not included in this release: `format`, UMD, remote image fetching, SVG inlining, framework plugins (Vite, Astro, Docusaurus, Next.js), Shadow DOM, and general SSR hydration guarantees outside the single-file export path.
222
+
223
+ Single-file static-first hydration is covered by the Playwright Chromium checks and local Edge checks. Firefox, Safari/WebKit and general server-side hydration remain unverified and are not claimed as supported.