reactive-md 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-ch.md +45 -24
- package/CHANGELOG.md +45 -24
- package/CONTRIBUTING-ch.md +10 -5
- package/CONTRIBUTING.md +10 -5
- package/README-ch.md +38 -36
- package/README-en.md +45 -42
- package/README.md +45 -42
- package/SECURITY-ch.md +1 -1
- package/SECURITY.md +1 -1
- package/THIRD_PARTY_NOTICES.md +481 -1
- package/dist-library/{authoring-DJJjKYg9.js → authoring-DSC0VsNK.js} +58 -58
- package/dist-library/{compiler-UyPwGzJZ.js → compiler-CRD88BMt.js} +6218 -3363
- package/dist-library/react-Dk94rcOp.js +59658 -0
- package/dist-library/reactive-md-authoring.js +2 -2
- package/dist-library/reactive-md-editor.js +13 -0
- package/dist-library/reactive-md-react-unstyled.js +1 -1
- package/dist-library/reactive-md-react.js +1 -1
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +123 -123
- package/dist-library/{runtime-DXtle_6c.js → runtime-D8KbnCd0.js} +151 -151
- package/dist-library/types/editor/types.d.ts +2 -0
- package/dist-library/types/local/code-block.d.ts +3 -1
- package/dist-library/types/local/code-languages.d.ts +7 -0
- package/dist-library/types/local/compiled-data.d.ts +6 -0
- package/dist-library/types/local/compiler.d.ts +1 -0
- package/dist-library/types/local/diagnostics.d.ts +31 -0
- package/dist-library/types/local/diagram-layout.d.ts +69 -0
- package/dist-library/types/local/html-names.d.ts +6 -0
- package/dist-library/types/local/html-table.d.ts +25 -0
- package/dist-library/types/local/math-display.d.ts +1 -0
- package/dist-library/types/local/table-surface.d.ts +10 -0
- package/dist-library/types/local/types.d.ts +2 -0
- package/dist-library/types/local/visuals.d.ts +9 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +75 -51
- package/docs/README.md +84 -0
- package/docs/{compatibility-ch.md → compatibility/compatibility-ch.md} +28 -18
- package/docs/{compatibility-en.md → compatibility/compatibility-en.md} +28 -18
- package/docs/{source-versioning-ch.md → compatibility/source-versioning-ch.md} +2 -2
- package/docs/{source-versioning-en.md → compatibility/source-versioning-en.md} +2 -2
- package/docs/{component-development-ch.md → development/component-development-ch.md} +7 -7
- package/docs/{component-development-en.md → development/component-development-en.md} +7 -7
- package/docs/{component-protocol-ch.md → development/component-protocol-ch.md} +17 -17
- package/docs/{component-protocol-en.md → development/component-protocol-en.md} +17 -17
- package/docs/{performance-ch.md → development/performance-ch.md} +2 -2
- package/docs/{performance-en.md → development/performance-en.md} +2 -2
- package/docs/{releasing-ch.md → development/releasing-ch.md} +12 -12
- package/docs/{releasing-en.md → development/releasing-en.md} +12 -12
- package/docs/guides/local-guide-ch.md +513 -0
- package/docs/guides/local-guide-en.md +513 -0
- package/docs/{author-tools-ch.md → integration/author-tools-ch.md} +8 -8
- package/docs/{author-tools-en.md → integration/author-tools-en.md} +8 -8
- package/docs/{editor-ch.md → integration/editor-ch.md} +7 -6
- package/docs/{editor-en.md → integration/editor-en.md} +7 -6
- package/docs/{local-integration-ch.md → integration/local-integration-ch.md} +33 -15
- package/docs/{local-integration-en.md → integration/local-integration-en.md} +33 -15
- package/docs/{shareable-export-ch.md → integration/shareable-export-ch.md} +16 -4
- package/docs/{shareable-export-en.md → integration/shareable-export-en.md} +16 -4
- package/docs/{computations-formatting-ch.md → reference/computations-formatting-ch.md} +2 -2
- package/docs/{computations-formatting-en.md → reference/computations-formatting-en.md} +2 -2
- package/docs/{constraints-collections-ch.md → reference/constraints-collections-ch.md} +2 -2
- package/docs/{constraints-collections-en.md → reference/constraints-collections-en.md} +2 -2
- package/docs/{diagnostics-counting-ch.md → reference/diagnostics-counting-ch.md} +22 -2
- package/docs/{diagnostics-counting-en.md → reference/diagnostics-counting-en.md} +22 -2
- package/docs/{html-compatibility-ch.md → reference/html-compatibility-ch.md} +42 -4
- package/docs/{html-compatibility-en.md → reference/html-compatibility-en.md} +42 -4
- package/docs/{local-components-v2-ch.md → reference/local-components-v2-ch.md} +2 -2
- package/docs/{local-components-v2-en.md → reference/local-components-v2-en.md} +2 -2
- package/docs/{local-interaction-syntax-ch.md → reference/local-interaction-syntax-ch.md} +26 -7
- package/docs/{local-interaction-syntax-en.md → reference/local-interaction-syntax-en.md} +26 -7
- package/docs/{theme-protocol-ch.md → reference/theme-protocol-ch.md} +1 -1
- package/docs/{theme-protocol-en.md → reference/theme-protocol-en.md} +1 -1
- package/docs/{release-0.4.0-ch.md → releases/release-0.4.0-ch.md} +6 -6
- package/docs/{release-0.4.0-en.md → releases/release-0.4.0-en.md} +6 -6
- package/docs/{release-0.4.1-ch.md → releases/release-0.4.1-ch.md} +2 -2
- package/docs/{release-0.4.1-en.md → releases/release-0.4.1-en.md} +2 -2
- package/docs/{release-0.5.0-ch.md → releases/release-0.5.0-ch.md} +4 -4
- package/docs/{release-0.5.0-en.md → releases/release-0.5.0-en.md} +4 -4
- package/docs/{release-0.5.1-ch.md → releases/release-0.5.1-ch.md} +4 -4
- package/docs/{release-0.5.1-en.md → releases/release-0.5.1-en.md} +4 -4
- package/docs/{release-0.5.2-ch.md → releases/release-0.5.2-ch.md} +3 -3
- package/docs/{release-0.5.2-en.md → releases/release-0.5.2-en.md} +3 -3
- package/docs/{release-0.5.3-ch.md → releases/release-0.5.3-ch.md} +1 -1
- package/docs/{release-0.5.3-en.md → releases/release-0.5.3-en.md} +1 -1
- package/docs/releases/release-0.6.0-ch.md +57 -0
- package/docs/releases/release-0.6.0-en.md +57 -0
- package/examples/conformance/README.md +4 -4
- package/examples/integration/README.md +10 -8
- package/examples/integration/worker/package.json +1 -1
- package/examples/local/README.md +5 -5
- package/examples/local/html-compat.reactive.md +19 -0
- package/package.json +9 -2
- package/dist-library/react-fizgU3i8.js +0 -12764
- package/docs/local-guide-ch.md +0 -967
- package/docs/local-guide-en.md +0 -967
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
The editor has its own stylesheet at `reactive-md/editor/styles.css`. It is separate from `reactive-md/styles.css`, so a page that only edits source does not load document rendering styles.
|
|
6
6
|
|
|
7
|
-
The editor is part of the `0.
|
|
7
|
+
The editor is part of the `0.6.0` release, available on both `latest` and `next`. Existing `reactive-md`, `reactive-md/react` and `reactive-md/styles.css` imports are unchanged.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npm install reactive-md
|
|
12
|
+
npm install reactive-md
|
|
13
13
|
npm install react@19 react-dom@19
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Pin the
|
|
16
|
+
Pin the version with `npm install reactive-md@0.6.0`. The package ships ESM only and needs Node.js 22.12 or newer for tooling and server rendering.
|
|
17
17
|
|
|
18
18
|
## Minimal controlled editor
|
|
19
19
|
|
|
@@ -82,6 +82,7 @@ export function SourceEditor() {
|
|
|
82
82
|
| --- | --- |
|
|
83
83
|
| `focus(selection?)` | Focuses the textarea. Applies the optional selection. |
|
|
84
84
|
| `selectRange(range)` | Selects a source range. Ranges use the same UTF-16 half-open offsets as compile diagnostics. |
|
|
85
|
+
| `insertText(text)` | Replaces the current selection with text as one undoable edit, then places the caret after it. Read-only and disabled editors ignore the call. |
|
|
85
86
|
| `getSelection()` | Returns the current selection. |
|
|
86
87
|
| `getTextarea()` | Returns the underlying textarea, or `null` before mount. |
|
|
87
88
|
| `undo()` / `redo()` | Moves through this instance's history and emits the resulting value through `onChange`. Both are no-ops at the ends of the history and while `readOnly` or `disabled` is set. |
|
|
@@ -218,7 +219,7 @@ The editor edits source. The host handles the rest:
|
|
|
218
219
|
- Persistence: store the source. The editor does not auto-save, write local storage or send the source anywhere.
|
|
219
220
|
- Export: pass `onExport` to connect the toolbar action to your HTML export, download dialog or file service. The editor does not build a shareable HTML file.
|
|
220
221
|
|
|
221
|
-
Compilation scheduling and debouncing also stay in the host. See [Local mode integration](local-integration-en.md) and [Shareable documents and static export](shareable-export-en.md). A complete editor, preview and document-switching example is in [react-editor.tsx](
|
|
222
|
+
Compilation scheduling and debouncing also stay in the host. See [Local mode integration](local-integration-en.md) and [Shareable documents and static export](shareable-export-en.md). A complete editor, preview and document-switching example is in [react-editor.tsx](../../examples/integration/react-editor.tsx).
|
|
222
223
|
|
|
223
224
|
## Server rendering
|
|
224
225
|
|
|
@@ -232,6 +233,6 @@ If the same page also renders a document preview, import `reactive-md/styles.css
|
|
|
232
233
|
|
|
233
234
|
## Compatibility
|
|
234
235
|
|
|
235
|
-
`0.5.0` adds the editor entry and keeps `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1`. Projects that only render documents can upgrade without changing imports or source. The editor is new, so it has no older API to migrate from. See the [0.5.0 release notes](release-0.5.0-en.md) and [Versions and compatibility](compatibility-en.md).
|
|
236
|
+
`0.5.0` adds the editor entry and keeps `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1`. Projects that only render documents can upgrade without changing imports or source. The editor is new, so it has no older API to migrate from. See the [0.5.0 release notes](../releases/release-0.5.0-en.md) and [Versions and compatibility](../compatibility/compatibility-en.md).
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
0.5.3 adds compile-option-aware authoring and explicit screen/print styles. See [0.5.3 host integration](../releases/release-0.5.3-en.md). 0.6.0 adds `insertText` to the ref handle; see the [0.6.0 release notes](../releases/release-0.6.0-en.md).
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# 本地交互文档集成
|
|
2
2
|
|
|
3
|
-
本地交互模式使用 HTML 风格标签、就地参数和 `{{ 表达式 }}`。作者规则见 [新用户入门指南](local-guide-ch.md) 和 [语法规范](local-interaction-syntax-ch.md),完整文档见[示例索引](
|
|
3
|
+
本地交互模式使用 HTML 风格标签、就地参数和 `{{ 表达式 }}`。作者规则见 [新用户入门指南](../guides/local-guide-ch.md) 和 [语法规范](../reference/local-interaction-syntax-ch.md),完整文档见[示例索引](../../examples/local/README.md)。宿主通过带 `Local` 的 API 明确选择此模式。可选修订指令、升级检查与 `migrateLocalSource` 见[源码修订与迁移](../compatibility/source-versioning-ch.md),升级清单见[0.4.0 发布与迁移](../releases/release-0.4.0-ch.md)。
|
|
4
4
|
|
|
5
5
|
## 运行环境与入口
|
|
6
6
|
|
|
7
|
-
下个发行版的 P0 HTML 和三个宿主能力开关见 [HTML 部分兼容](html-compatibility-ch.md)。本版采用暂时性分流政策:任意开启作者 CSS、JavaScript 或扩展 HTML,整篇文档即按原生 HTML 渲染,停止解析 Markdown 和 ReactiveMD。
|
|
7
|
+
下个发行版的 P0 HTML 和三个宿主能力开关见 [HTML 部分兼容](../reference/html-compatibility-ch.md)。本版采用暂时性分流政策:任意开启作者 CSS、JavaScript 或扩展 HTML,整篇文档即按原生 HTML 渲染,停止解析 Markdown 和 ReactiveMD。
|
|
8
8
|
|
|
9
9
|
| 入口 | 内容 | 依赖 |
|
|
10
10
|
| --- | --- | --- |
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
| `reactive-md/react` | `LocalReactiveDocument`、`LocalDocumentView` | React 19 |
|
|
13
13
|
| `reactive-md/styles.css` | 组件、主题和文档样式 | 由宿主显式引入 |
|
|
14
14
|
|
|
15
|
-
包只提供 ESM。Node.js 22.12+ 可用于开发和 Node 端编译、运行。本地浏览器检查使用 Edge;静态 SSR 由 packed 检查覆盖;完整矩阵见[版本与兼容性](compatibility-ch.md)。可复制的项目见[独立接入示例](
|
|
15
|
+
包只提供 ESM。Node.js 22.12+ 可用于开发和 Node 端编译、运行。本地浏览器检查使用 Edge;静态 SSR 由 packed 检查覆盖;完整矩阵见[版本与兼容性](../compatibility/compatibility-ch.md)。可复制的项目见[独立接入示例](../../examples/integration/README.md)。单文件 HTML、状态文件与独立浏览器运行时见[可分享文档与静态导出](shareable-export-ch.md)。
|
|
16
16
|
|
|
17
17
|
## React
|
|
18
18
|
|
|
@@ -119,6 +119,24 @@ const result = compileLocal(source, options);
|
|
|
119
119
|
|
|
120
120
|
需要在 React 中使用自定义预算时,先调用 `compileLocal`,再把编译文档和运行时交给 `LocalDocumentView`。`LocalReactiveDocument` 和 Playground 的编译线程使用默认预算。提高节点预算后,宿主应结合实际文档测量内存和预览渲染耗时。
|
|
121
121
|
|
|
122
|
+
#### Next.js Server Components
|
|
123
|
+
|
|
124
|
+
`compileLocal` 的返回值在每一层都使用普通数据,包括 `document.dependencies`、节点 `attrs`、绑定及诊断。记录对象的原型为 `Object.prototype`,数组为 `Array.prototype`;内部字典仍可使用空原型。已有的冻结元数据和 `undefined` 字段会保留。
|
|
125
|
+
|
|
126
|
+
在服务端编译并检查 `result.ok` 后,可以直接把 `result.document` 作为属性交给 Client Component,无需 JSON 往返转换。这满足 React 对[可序列化属性中普通对象的要求](https://react.dev/reference/rsc/use-client#serializable-types-returned-by-server-components)。客户端组件负责创建、销毁 `createLocalRuntime(document)`,并把运行时交给 `LocalDocumentView`。运行时实例及宿主回调留在客户端;普通数据保证适用于编译产物。
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
// Server Component;ClientDocument 是宿主的 'use client' 包装组件。
|
|
130
|
+
import { compileLocal } from 'reactive-md';
|
|
131
|
+
import ClientDocument from './ClientDocument';
|
|
132
|
+
|
|
133
|
+
export default function Page() {
|
|
134
|
+
const result = compileLocal('<counter bind="n" label="计数" initial="2">');
|
|
135
|
+
if (!result.ok) throw new Error('编译失败');
|
|
136
|
+
return <ClientDocument document={result.document} />;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
122
140
|
### 宿主组件
|
|
123
141
|
|
|
124
142
|
宿主可以为单次编译登记叶子标签,不改变 `local-draft-2` 语法修订:
|
|
@@ -161,17 +179,17 @@ const migrated = migrateLocalSource(source, { fromVersion: 'local-draft-1' });
|
|
|
161
179
|
|
|
162
180
|
`LocalUpgradeOptions` 提供 `fromVersion` 和 `allowSemanticChanges`。无版本声明的历史文档需要 `fromVersion: 'local-draft-1'`。显式 `fromVersion` 与声明不一致时被拒绝。迁移源只接受 `local-draft-1` 和 `local-draft-2`。
|
|
163
181
|
|
|
164
|
-
迁移只改元数据指令,保留正文原始字节、BOM 和 CRLF,并且幂等。生成结果前会阻止保留绑定、新增可识别标签、编译错误和文本控件长度语义变化。完整检查与 CLI 见[源码修订与迁移](source-versioning-ch.md)。
|
|
182
|
+
迁移只改元数据指令,保留正文原始字节、BOM 和 CRLF,并且幂等。生成结果前会阻止保留绑定、新增可识别标签、编译错误和文本控件长度语义变化。完整检查与 CLI 见[源码修订与迁移](../compatibility/source-versioning-ch.md)。
|
|
165
183
|
|
|
166
184
|
### `createLocalRuntime(document: LocalDocument)`
|
|
167
185
|
|
|
168
|
-
只读命名值在可选的 `document.computations` 记录中用 `LocalComputation` 描述。`bindings` 和 `initialState` 继续只包含可写控件;`snapshot().state` 还包含该修订成功求值的计算结果。需要保留表达式错误语义时用 `evaluate(name)` 读取,失败值不会出现在快照里。见[计算与错误规则](computations-formatting-ch.md)。
|
|
186
|
+
只读命名值在可选的 `document.computations` 记录中用 `LocalComputation` 描述。`bindings` 和 `initialState` 继续只包含可写控件;`snapshot().state` 还包含该修订成功求值的计算结果。需要保留表达式错误语义时用 `evaluate(name)` 读取,失败值不会出现在快照里。见[计算与错误规则](../reference/computations-formatting-ch.md)。
|
|
169
187
|
|
|
170
188
|
为已编译文档创建独立的内存运行时。`document` 不是本地模式文档、初值超出预算或结构无效时会抛出错误。每个实例拥有独立状态;运行时本身不会保存或发送状态。
|
|
171
189
|
|
|
172
190
|
### `LocalRuntime`
|
|
173
191
|
|
|
174
|
-
`validate(): Diagnostic[]` 读取当前修订的跨字段失败提示,保留字段可编辑性,并返回缓存诊断的副本。`document.validations?: LocalValidation[]` 保存可序列化规则。数字集合为 `LocalValue` 增加 `number[]`、为 `LocalValueKind` 增加 `number-array`,原有可写选择控件继续使用字符串数组。见[条件、校验与本地集合](constraints-collections-ch.md)。
|
|
192
|
+
`validate(): Diagnostic[]` 读取当前修订的跨字段失败提示,保留字段可编辑性,并返回缓存诊断的副本。`document.validations?: LocalValidation[]` 保存可序列化规则。数字集合为 `LocalValue` 增加 `number[]`、为 `LocalValueKind` 增加 `number-array`,原有可写选择控件继续使用字符串数组。见[条件、校验与本地集合](../reference/constraints-collections-ch.md)。
|
|
175
193
|
|
|
176
194
|
| 成员 | 参数 | 返回 | 行为 |
|
|
177
195
|
| --- | --- | --- | --- |
|
|
@@ -265,7 +283,7 @@ const { retained, dropped, diagnostics } = applyLocalStateRetention(runtime, pla
|
|
|
265
283
|
|
|
266
284
|
### 在 Worker 中后台编译
|
|
267
285
|
|
|
268
|
-
Worker 由宿主提供:用你的打包工具创建 worker 入口,并保留 `compileLocal` 作为回退。可复制的浏览器示例见[独立接入示例](
|
|
286
|
+
Worker 由宿主提供:用你的打包工具创建 worker 入口,并保留 `compileLocal` 作为回退。可复制的浏览器示例见[独立接入示例](../../examples/integration/README.md)。
|
|
269
287
|
|
|
270
288
|
```ts
|
|
271
289
|
// compile.worker.ts
|
|
@@ -311,7 +329,7 @@ scheduler.schedule(source);
|
|
|
311
329
|
|
|
312
330
|
## 诊断
|
|
313
331
|
|
|
314
|
-
`Diagnostic` 的字段与稳定级别见[版本与兼容性](compatibility-ch.md)中的诊断契约。要点:`line`、`column` 和 `range` 用于程序定位;`code` 可用于当前版本的粗分类,但 0.x 不承诺跨版本稳定;`message` 是默认英文显示文本,不要解析。渲染器和 CLI 可通过共享诊断目录显示中文,回调仍收到结构化字段。
|
|
332
|
+
`Diagnostic` 的字段与稳定级别见[版本与兼容性](../compatibility/compatibility-ch.md)中的诊断契约。要点:`line`、`column` 和 `range` 用于程序定位;`code` 可用于当前版本的粗分类,但 0.x 不承诺跨版本稳定;`message` 是默认英文显示文本,不要解析。渲染器和 CLI 可通过共享诊断目录显示中文,回调仍收到结构化字段。
|
|
315
333
|
|
|
316
334
|
`onDiagnostics` 会在编译结果变化时收到编译诊断,也会收到控件写入被拒绝时的运行时诊断。编译错误文档不激活交互;运行时局部错误只替换对应内容。
|
|
317
335
|
|
|
@@ -359,7 +377,7 @@ const urlPolicy: LocalUrlPolicy = (raw, kind) => {
|
|
|
359
377
|
|
|
360
378
|
- 样式选择器以 `.md-document`、`.local-document` 和 `.md-*`、`.local-*` 类名为主。组件渲染的文档根节点是 `.md-document.local-document`。
|
|
361
379
|
- 主题变量声明在 `.md-document` 和 `.reactive-md-theme` 上,包括 `--ink`、`--surface`、`--line`、`--blue`、`--teal`、`--danger`、`--radius-*` 和字体变量。在库样式之后用 `.my-article .md-document { --blue: #245c98; }` 等规则覆盖;文档根节点自带默认值,只在祖先容器上设置变量不会覆盖根节点上的同名值。
|
|
362
|
-
- 文档开头可写 `<theme name="default">`,省略时选择 `default`。自定义主题通过 `themes` 登记;完整要求见[主题协议](theme-protocol-ch.md)。
|
|
380
|
+
- 文档开头可写 `<theme name="default">`,省略时选择 `default`。自定义主题通过 `themes` 登记;完整要求见[主题协议](../reference/theme-protocol-ch.md)。
|
|
363
381
|
- `colorScheme` 可强制深浅模式;默认 `auto` 跟随最近祖先的 `data-color-scheme` 或兼容的 `data-theme`,再跟随系统偏好。文档根节点输出独立的 `data-rmd-theme` 和已解析的 `data-color-scheme`。
|
|
364
382
|
- 文档默认 `max-width: 720px` 且水平居中。需要铺满宿主容器时,在自己的作用域内覆盖 `.md-document` 的宽度和边距。
|
|
365
383
|
- 主题优先覆盖公共变量;组件外层 `.md-*`、`.local-*` 类和语义状态属性可用于主题样式。内部节点排列不属于扩展接口;兼容要求见主题协议。
|
|
@@ -371,22 +389,22 @@ const urlPolicy: LocalUrlPolicy = (raw, kind) => {
|
|
|
371
389
|
|
|
372
390
|
单个文档源码最多 1,000,000 字符。诊断最多 100 条,单条消息最多 2,000 字符。
|
|
373
391
|
|
|
374
|
-
每个绘图组件最多 16 条曲线,整篇文档最多请求 20,000 个曲线采样点,包括隐藏区域。绘图计算还受 2,000,000 步的共享执行预算限制。每份文档最多 100 条校验规则。`data-table` 的生成行、列数和文本有单表及整篇文档预算,见[条件、校验与本地集合](constraints-collections-ch.md)。超限文档会收到诊断;表达式和数学渲染也有各自的深度与记号预算。
|
|
392
|
+
每个绘图组件最多 16 条曲线,整篇文档最多请求 20,000 个曲线采样点,包括隐藏区域。绘图计算还受 2,000,000 步的共享执行预算限制。每份文档最多 100 条校验规则。`data-table` 的生成行、列数和文本有单表及整篇文档预算,见[条件、校验与本地集合](../reference/constraints-collections-ch.md)。超限文档会收到诊断;表达式和数学渲染也有各自的深度与记号预算。
|
|
375
393
|
|
|
376
|
-
这些上限限制单个文档的工作量,不替代宿主对请求大小、并发和执行时间的控制。完整威胁边界见[安全策略](
|
|
394
|
+
这些上限限制单个文档的工作量,不替代宿主对请求大小、并发和执行时间的控制。完整威胁边界见[安全策略](../../SECURITY-ch.md)。
|
|
377
395
|
|
|
378
396
|
## 版本固定与升级
|
|
379
397
|
|
|
380
398
|
- 在 0.x 阶段固定准确的包版本,并提交 lockfile。`^0.3.0` 只允许补丁版本,但生产接入仍建议写死版本或固定 tarball 的 SHA256。
|
|
381
399
|
- 用一个包版本同时提供核心和 React 入口;不要混用不同版本的 `reactive-md` 和 `reactive-md/react`。
|
|
382
|
-
- 在应用配置或文档元数据中记录 `LOCAL_SYNTAX_VERSION`,与持久化的 `.reactive.md` 源码一起保存。语法修订变化时按[版本与兼容性](compatibility-ch.md)迁移。
|
|
400
|
+
- 在应用配置或文档元数据中记录 `LOCAL_SYNTAX_VERSION`,与持久化的 `.reactive.md` 源码一起保存。语法修订变化时按[版本与兼容性](../compatibility/compatibility-ch.md)迁移。
|
|
383
401
|
- 升级后重新编译自有文档,检查 `result.diagnostics`、渲染结果和浏览器交互。不要依赖诊断 `message` 的文本。
|
|
384
402
|
|
|
385
403
|
## 不提供的功能
|
|
386
404
|
|
|
387
|
-
默认 ReactiveMD 路径支持 P0 HTML。作者 CSS、JavaScript 和扩展 HTML 的宿主开关使用独立的原生 HTML 路径,见 [HTML 部分兼容](html-compatibility-ch.md)。本地模式仍不提供自动状态持久化或不受限的网络访问、插件或自定义组件注册、外部数据接口、Vue 支持、React 18 支持或 CommonJS 入口。状态导出与导入是宿主的显式调用。`LocalReactiveDocument` 在源码变化时从初值开始;需要保留参数时使用保留工具,或自行管理运行时和文档。
|
|
405
|
+
默认 ReactiveMD 路径支持 P0 HTML。作者 CSS、JavaScript 和扩展 HTML 的宿主开关使用独立的原生 HTML 路径,见 [HTML 部分兼容](../reference/html-compatibility-ch.md)。本地模式仍不提供自动状态持久化或不受限的网络访问、插件或自定义组件注册、外部数据接口、Vue 支持、React 18 支持或 CommonJS 入口。状态导出与导入是宿主的显式调用。`LocalReactiveDocument` 在源码变化时从初值开始;需要保留参数时使用保留工具,或自行管理运行时和文档。
|
|
388
406
|
|
|
389
407
|
|
|
390
|
-
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.
|
|
408
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](../reference/local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](../releases/release-0.4.0-ch.md)。`0.6.0` 同时提供于 `latest` 与 `next` 渠道。
|
|
391
409
|
|
|
392
|
-
|
|
410
|
+
0.5.3 新增接受编译配置的作者工具及显式屏幕、打印样式入口,见 [0.5.3 宿主集成](../releases/release-0.5.3-ch.md)。0.6.0 让 `compileLocal` 返回可跨 React Server Components 边界的普通数据,见 [0.6.0 发布说明](../releases/release-0.6.0-ch.md)。
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Local mode integration
|
|
2
2
|
|
|
3
|
-
Local interaction mode uses HTML-style tags, in-place parameters and `{{ expressions }}`. Author rules are in the [beginner guide](local-guide-en.md) and the [syntax specification](local-interaction-syntax-en.md); complete documents are in the [example index](
|
|
3
|
+
Local interaction mode uses HTML-style tags, in-place parameters and `{{ expressions }}`. Author rules are in the [beginner guide](../guides/local-guide-en.md) and the [syntax specification](../reference/local-interaction-syntax-en.md); complete documents are in the [example index](../../examples/local/README.md). Hosts explicitly select this mode through the `Local` APIs. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the optional revision directive, upgrade checks and `migrateLocalSource`, and [0.4.0 release and migration](../releases/release-0.4.0-en.md) for the upgrade checklist.
|
|
4
4
|
|
|
5
5
|
## Runtime and entries
|
|
6
6
|
|
|
7
|
-
See [HTML compatibility](html-compatibility-en.md) for the next release's P0 HTML support and host capability options. The temporary routing policy sends the entire document to native HTML when author CSS, JavaScript or extended HTML is enabled. Markdown and ReactiveMD interpretation stop in that path.
|
|
7
|
+
See [HTML compatibility](../reference/html-compatibility-en.md) for the next release's P0 HTML support and host capability options. The temporary routing policy sends the entire document to native HTML when author CSS, JavaScript or extended HTML is enabled. Markdown and ReactiveMD interpretation stop in that path.
|
|
8
8
|
|
|
9
9
|
| Entry | Contents | Dependency |
|
|
10
10
|
| --- | --- | --- |
|
|
@@ -12,7 +12,7 @@ See [HTML compatibility](html-compatibility-en.md) for the next release's P0 HTM
|
|
|
12
12
|
| `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` | React 19 |
|
|
13
13
|
| `reactive-md/styles.css` | Component, theme and document styles | Explicitly imported by the host |
|
|
14
14
|
|
|
15
|
-
The package ships ESM only. Node.js 22.12+ can be used for development and Node-side compilation and runtime. Local browser checks use Edge; static SSR is covered by the packed check; see [Versions and compatibility](compatibility-en.md) for the full matrix. Copyable projects are in [Standalone integration examples](
|
|
15
|
+
The package ships ESM only. Node.js 22.12+ can be used for development and Node-side compilation and runtime. Local browser checks use Edge; static SSR is covered by the packed check; see [Versions and compatibility](../compatibility/compatibility-en.md) for the full matrix. Copyable projects are in [Standalone integration examples](../../examples/integration/README.md). For single-file HTML, state files and the standalone browser runtime, see [Shareable documents and static export](shareable-export-en.md).
|
|
16
16
|
|
|
17
17
|
## React
|
|
18
18
|
|
|
@@ -119,6 +119,24 @@ The budget counts `LocalNode` instances created cumulatively during parsing, inc
|
|
|
119
119
|
|
|
120
120
|
To use a custom budget in React, call `compileLocal` first and pass the compiled document and runtime to `LocalDocumentView`. `LocalReactiveDocument` and the Playground compilation thread use the default budget. After raising the node budget, hosts should measure memory and preview rendering time with their actual documents.
|
|
121
121
|
|
|
122
|
+
#### Next.js Server Components
|
|
123
|
+
|
|
124
|
+
`compileLocal` returns plain data at every depth, including `document.dependencies`, node `attrs`, bindings and diagnostics. Records use `Object.prototype`; arrays use `Array.prototype`. Internal dictionaries may still use null prototypes. Existing frozen metadata and `undefined` fields are preserved.
|
|
125
|
+
|
|
126
|
+
Compile on the server, check `result.ok`, then pass `result.document` directly to a Client Component as a prop. A JSON round trip is unnecessary. This meets React's [plain-object requirement for serializable props](https://react.dev/reference/rsc/use-client#serializable-types-returned-by-server-components). In the Client Component, create and dispose `createLocalRuntime(document)` and render `LocalDocumentView` with that runtime. Runtime instances and host callbacks stay on the client; the plain-data guarantee applies to compiler output.
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
// Server Component; ClientDocument is the host's 'use client' wrapper.
|
|
130
|
+
import { compileLocal } from 'reactive-md';
|
|
131
|
+
import ClientDocument from './ClientDocument';
|
|
132
|
+
|
|
133
|
+
export default function Page() {
|
|
134
|
+
const result = compileLocal('<counter bind="n" label="Count" initial="2">');
|
|
135
|
+
if (!result.ok) throw new Error('Compilation failed');
|
|
136
|
+
return <ClientDocument document={result.document} />;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
122
140
|
### Host components
|
|
123
141
|
|
|
124
142
|
A host can register leaf tags for one compilation without changing the `local-draft-2` syntax revision:
|
|
@@ -161,17 +179,17 @@ const migrated = migrateLocalSource(source, { fromVersion: 'local-draft-1' });
|
|
|
161
179
|
|
|
162
180
|
`LocalUpgradeOptions` supplies `fromVersion` and `allowSemanticChanges`. An unversioned historical document needs `fromVersion: 'local-draft-1'`. An explicit `fromVersion` that disagrees with the declaration is rejected. Only `local-draft-1` and `local-draft-2` are accepted migration sources.
|
|
163
181
|
|
|
164
|
-
Migration changes only the metadata directive, preserves body bytes, BOM and CRLF, and is idempotent. It blocks reserved bindings, newly recognized tags, compile errors and text-control length changes before producing output. See [Source revisions and migration](source-versioning-en.md) for the exact checks and the CLI.
|
|
182
|
+
Migration changes only the metadata directive, preserves body bytes, BOM and CRLF, and is idempotent. It blocks reserved bindings, newly recognized tags, compile errors and text-control length changes before producing output. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the exact checks and the CLI.
|
|
165
183
|
|
|
166
184
|
### `createLocalRuntime(document: LocalDocument)`
|
|
167
185
|
|
|
168
|
-
Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](computations-formatting-en.md).
|
|
186
|
+
Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](../reference/computations-formatting-en.md).
|
|
169
187
|
|
|
170
188
|
Creates an independent in-memory runtime for a compiled document. Throws if `document` is not a local mode document, if initial values exceed budgets, or if the structure is invalid. Each instance has independent state; the runtime never stores or transmits state by itself.
|
|
171
189
|
|
|
172
190
|
### `LocalRuntime`
|
|
173
191
|
|
|
174
|
-
`validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](constraints-collections-en.md).
|
|
192
|
+
`validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](../reference/constraints-collections-en.md).
|
|
175
193
|
|
|
176
194
|
| Member | Parameters | Returns | Behavior |
|
|
177
195
|
| --- | --- | --- | --- |
|
|
@@ -265,7 +283,7 @@ Anonymous `@` bindings, removed or renamed parameters, timers and positional che
|
|
|
265
283
|
|
|
266
284
|
### Background compilation in a Worker
|
|
267
285
|
|
|
268
|
-
Worker support is host-provided: create the worker entry with your bundler and keep `compileLocal` as the fallback. A copyable browser example is in [Standalone integration examples](
|
|
286
|
+
Worker support is host-provided: create the worker entry with your bundler and keep `compileLocal` as the fallback. A copyable browser example is in [Standalone integration examples](../../examples/integration/README.md).
|
|
269
287
|
|
|
270
288
|
```ts
|
|
271
289
|
// compile.worker.ts
|
|
@@ -311,7 +329,7 @@ scheduler.schedule(source);
|
|
|
311
329
|
|
|
312
330
|
## Diagnostics
|
|
313
331
|
|
|
314
|
-
The fields and stability levels of `Diagnostic` are described in the diagnostics contract in [Versions and compatibility](compatibility-en.md). Key points: `line`, `column` and `range` are for programmatic location; `code` can be used for coarse classification in the current version, but 0.x does not promise cross-version stability; `message` is display text and should not be parsed.
|
|
332
|
+
The fields and stability levels of `Diagnostic` are described in the diagnostics contract in [Versions and compatibility](../compatibility/compatibility-en.md). Key points: `line`, `column` and `range` are for programmatic location; `code` can be used for coarse classification in the current version, but 0.x does not promise cross-version stability; `message` is display text and should not be parsed.
|
|
315
333
|
|
|
316
334
|
`onDiagnostics` receives compile diagnostics when the compilation result changes, and runtime diagnostics when control writes are rejected. Documents with compile errors do not activate interaction; runtime local errors replace only the corresponding content.
|
|
317
335
|
|
|
@@ -359,7 +377,7 @@ The policy receives the raw URL with leading and trailing whitespace removed, an
|
|
|
359
377
|
|
|
360
378
|
- Style selectors are mainly `.md-document`, `.local-document` and `.md-*`, `.local-*` class names. The document root rendered by components is `.md-document.local-document`.
|
|
361
379
|
- Theme variables are declared on `.md-document` and `.reactive-md-theme`, including `--ink`, `--surface`, `--line`, `--blue`, `--teal`, `--danger`, `--radius-*` and font variables. Override them after the library styles with rules such as `.my-article .md-document { --blue: #245c98; }`; the document root carries default values, so setting variables only on an ancestor container will not override same-name values on the root.
|
|
362
|
-
- Documents may start with `<theme name="default">`; omission selects `default`. Register custom themes through `themes`; see the [theme protocol](theme-protocol-en.md).
|
|
380
|
+
- Documents may start with `<theme name="default">`; omission selects `default`. Register custom themes through `themes`; see the [theme protocol](../reference/theme-protocol-en.md).
|
|
363
381
|
- `colorScheme` forces light or dark mode. The default `auto` reads the nearest ancestor's `data-color-scheme` or legacy `data-theme`, then the system preference. Each document exposes independent `data-rmd-theme` and resolved `data-color-scheme` attributes.
|
|
364
382
|
- Documents default to `max-width: 720px` and are horizontally centered. To fill the host container, override the width and margins of `.md-document` within your own scope.
|
|
365
383
|
- Prefer public variables for theme styling. Component outer `.md-*` and `.local-*` classes and semantic state attributes are theme hooks; internal node ordering is not an extension API. See the theme protocol for compatibility requirements.
|
|
@@ -371,22 +389,22 @@ A single string is limited to 100,000 characters, an array to 10,000 items, and
|
|
|
371
389
|
|
|
372
390
|
A single document source is limited to 1,000,000 characters. There are at most 100 diagnostics, and a single message is at most 2,000 characters.
|
|
373
391
|
|
|
374
|
-
Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in [constraints and collections](constraints-collections-en.md). Documents over a limit receive diagnostics; expression and math rendering also have their own depth and token budgets.
|
|
392
|
+
Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in [constraints and collections](../reference/constraints-collections-en.md). Documents over a limit receive diagnostics; expression and math rendering also have their own depth and token budgets.
|
|
375
393
|
|
|
376
|
-
These limits bound the work for a single document; they do not replace host control over request size, concurrency and execution time. See the [security policy](
|
|
394
|
+
These limits bound the work for a single document; they do not replace host control over request size, concurrency and execution time. See the [security policy](../../SECURITY.md) for the full threat boundary.
|
|
377
395
|
|
|
378
396
|
## Version pinning and upgrades
|
|
379
397
|
|
|
380
398
|
- During 0.x, pin the exact package version and commit the lockfile. `^0.3.0` allows only patch versions, but production integrations should still pin the version or the tarball SHA256.
|
|
381
399
|
- Use one package version for both the core and React entries; do not mix different versions of `reactive-md` and `reactive-md/react`.
|
|
382
|
-
- Record `LOCAL_SYNTAX_VERSION` in application configuration or document metadata, alongside the persisted `.reactive.md` source. Migrate according to [Versions and compatibility](compatibility-en.md) when the syntax revision changes.
|
|
400
|
+
- Record `LOCAL_SYNTAX_VERSION` in application configuration or document metadata, alongside the persisted `.reactive.md` source. Migrate according to [Versions and compatibility](../compatibility/compatibility-en.md) when the syntax revision changes.
|
|
383
401
|
- After upgrading, recompile your own documents and check `result.diagnostics`, rendered output and browser interactions. Do not depend on the text of diagnostic `message`.
|
|
384
402
|
|
|
385
403
|
## Features not provided
|
|
386
404
|
|
|
387
|
-
The default ReactiveMD path supports P0 HTML. Host options for author CSS, JavaScript and extended HTML use the separate native HTML path described in [HTML compatibility](html-compatibility-en.md). Local mode still provides no automatic state persistence or unrestricted network access, plugins or custom component registration, external data APIs, Vue support, React 18 support or a CommonJS entry. State export and import are explicit host calls. `LocalReactiveDocument` starts from initial values when the source changes; use retention helpers or manage the runtime and document yourself.
|
|
405
|
+
The default ReactiveMD path supports P0 HTML. Host options for author CSS, JavaScript and extended HTML use the separate native HTML path described in [HTML compatibility](../reference/html-compatibility-en.md). Local mode still provides no automatic state persistence or unrestricted network access, plugins or custom component registration, external data APIs, Vue support, React 18 support or a CommonJS entry. State export and import are explicit host calls. `LocalReactiveDocument` starts from initial values when the source changes; use retention helpers or manage the runtime and document yourself.
|
|
388
406
|
|
|
389
407
|
|
|
390
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. `0.
|
|
408
|
+
See [local-draft-2 components and migration](../reference/local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](../releases/release-0.4.0-en.md) for the upgrade checklist. `0.6.0` is available on both the `latest` and `next` channels.
|
|
391
409
|
|
|
392
|
-
|
|
410
|
+
0.5.3 adds compile-option-aware authoring and explicit screen/print styles. See [0.5.3 host integration](../releases/release-0.5.3-en.md). 0.6.0 makes `compileLocal` return plain data that can cross a React Server Components boundary; see the [0.6.0 release notes](../releases/release-0.6.0-en.md).
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# 可分享文档与静态导出
|
|
2
2
|
|
|
3
|
-
本文说明 `local-draft-2` 新增的单文件 HTML 导出能力。编译与运行时接口见[本地模式集成](local-integration-ch.md),语法见[交互语法规范](local-interaction-syntax-ch.md),修订声明与迁移见[源码修订与迁移](source-versioning-ch.md),升级说明见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
3
|
+
本文说明 `local-draft-2` 新增的单文件 HTML 导出能力。编译与运行时接口见[本地模式集成](local-integration-ch.md),语法见[交互语法规范](../reference/local-interaction-syntax-ch.md),修订声明与迁移见[源码修订与迁移](../compatibility/source-versioning-ch.md),升级说明见[0.4.0 发布与迁移](../releases/release-0.4.0-ch.md)。
|
|
4
4
|
|
|
5
5
|
## 两种产物
|
|
6
6
|
|
|
7
|
-
默认 ReactiveMD 文档遵循下述导出规则。原生 HTML 文档的交互导出保留 `compileOptions` 和整篇 HTML 路径,静态导出禁用作者 JavaScript;这类文档没有 ReactiveMD 参数。编译开关、隔离和暂时性分流政策见 [HTML 部分兼容](html-compatibility-ch.md)。
|
|
7
|
+
默认 ReactiveMD 文档遵循下述导出规则。原生 HTML 文档的交互导出保留 `compileOptions` 和整篇 HTML 路径,静态导出禁用作者 JavaScript;这类文档没有 ReactiveMD 参数。编译开关、隔离和暂时性分流政策见 [HTML 部分兼容](../reference/html-compatibility-ch.md)。
|
|
8
8
|
|
|
9
9
|
**交互式 HTML** 是一个自包含的 `.html` 文件。它内嵌原始源码、独立浏览器运行时、React 19、样式表和打印样式。读者通过 `file://` 打开即可交互,不需要 Node.js、React、reactive-md 包或网络连接。
|
|
10
10
|
|
|
@@ -62,7 +62,7 @@ reactive-md migrate old.reactive.md --check --json
|
|
|
62
62
|
|
|
63
63
|
默认把迁移后的源码写到标准输出。`-o` 使用独占创建,拒绝任何已存在的路径,包括输入文件本身。`--check` 从不写入。`--json` 只输出结构化报告。`--accept-semantic-changes` 允许文本控件长度语义变化并报告警告;`--locale en|zh` 选择显示语言。
|
|
64
64
|
|
|
65
|
-
迁移被阻止时退出 `1`,成功时退出 `0`。`--check` 在需要迁移或被阻止时退出 `1`,源码已是当前版本时退出 `0`。用法和 I/O 错误退出 `2`。命令不就地覆盖,也不提供批量或 `--write` 模式。检查项、保留字节和状态摘要影响见[源码修订与迁移](source-versioning-ch.md)。
|
|
65
|
+
迁移被阻止时退出 `1`,成功时退出 `0`。`--check` 在需要迁移或被阻止时退出 `1`,源码已是当前版本时退出 `0`。用法和 I/O 错误退出 `2`。命令不就地覆盖,也不提供批量或 `--write` 模式。检查项、保留字节和状态摘要影响见[源码修订与迁移](../compatibility/source-versioning-ch.md)。
|
|
66
66
|
|
|
67
67
|
## 起始参数与状态文件
|
|
68
68
|
|
|
@@ -106,6 +106,18 @@ Demo 导出对话框可以把当前预览参数下载为状态文件,供后续
|
|
|
106
106
|
|
|
107
107
|
## 图片
|
|
108
108
|
|
|
109
|
+
### 浏览器
|
|
110
|
+
|
|
111
|
+
在 Demo 的**文档图片**面板中选择文件,或把图片粘贴到源码编辑器。通过校验的图片会在选区处插入 Markdown 引用,并加入资源清单。清单显示引用路径、格式、大小及引用状态,支持替换和移除。批量导入中有文件不合格时,源码和清单均保持原状。
|
|
112
|
+
|
|
113
|
+
支持 PNG、JPEG、GIF、WebP,检查文件内容、声明 MIME 类型和浏览器解码结果。单张上限 8 MiB,合计 24 MiB,最多 64 项,不支持 SVG。资源按当前文档和语言保存在 IndexedDB;出现存储警告时,资源仅在当前页面会话内可用。
|
|
114
|
+
|
|
115
|
+
导出弹窗会列出缺失图片,可逐项选择本地文件,也可为远程 URL 指定本地替代文件。浏览器不会自动抓取远程图片。补齐全部引用后才能导出 HTML;交互式和静态导出都会内嵌所引用的文件,未引用资源不会打包。Markdown 和状态文件下载均不包含图片文件。
|
|
116
|
+
|
|
117
|
+
这些浏览器资源操作适用于 ReactiveMD 路由,包括 P0 `<img>` 元素。原生 HTML 路由沿用独立的图片策略。
|
|
118
|
+
|
|
119
|
+
### CLI
|
|
120
|
+
|
|
109
121
|
离线导出默认使用 `--assets inline`:
|
|
110
122
|
|
|
111
123
|
- 只读取文档目录内或显式 `--asset-root` 内的相对路径。
|
|
@@ -184,7 +196,7 @@ IIFE 会注册一个 Light DOM 自定义元素。简单选项通过属性传递
|
|
|
184
196
|
- 核心入口仍不加载 React。
|
|
185
197
|
- 状态导出与导入只使用公开绑定名和经过校验的值。
|
|
186
198
|
- 读者修改不会持久化到导出文件。
|
|
187
|
-
- Demo
|
|
199
|
+
- Demo 会预览并导出文档资源清单中已提供的图片。引用缺失时,选择对应文件后才能导出 HTML。
|
|
188
200
|
- 导出格式版本为 `reactive-md-html/v1`,可从生成的 meta 标签检查。
|
|
189
201
|
|
|
190
202
|
## 产物体积基线
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Shareable documents and static export
|
|
2
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).
|
|
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
4
|
|
|
5
5
|
## Output modes
|
|
6
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.
|
|
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
8
|
|
|
9
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
10
|
|
|
@@ -64,7 +64,7 @@ reactive-md migrate old.reactive.md --check --json
|
|
|
64
64
|
|
|
65
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
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.
|
|
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
68
|
|
|
69
69
|
## Starting values and state files
|
|
70
70
|
|
|
@@ -108,6 +108,18 @@ The demo's export dialog can download the current preview parameters as a state
|
|
|
108
108
|
|
|
109
109
|
## Images
|
|
110
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
|
+
|
|
111
123
|
Offline export defaults to `--assets inline`:
|
|
112
124
|
|
|
113
125
|
- Only relative paths that resolve inside the document directory, or an explicit `--asset-root`, are read.
|
|
@@ -186,7 +198,7 @@ The element uses Light DOM so the existing document CSS, heading anchors and pri
|
|
|
186
198
|
- The core entry remains React-free.
|
|
187
199
|
- State export and import use only public binding names and validated values.
|
|
188
200
|
- Exported HTML does not persist a reader's changes.
|
|
189
|
-
- The demo
|
|
201
|
+
- The demo previews and exports images supplied through its document resource list. Missing references block HTML export until files are selected.
|
|
190
202
|
- The export format version is `reactive-md-html/v1`; inspect it in the generated meta tags.
|
|
191
203
|
|
|
192
204
|
## Bundle baseline
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 复用计算与格式化数值
|
|
2
2
|
|
|
3
|
-
这些能力属于使用 `local-draft-2` 的 `0.4.0`。完整语法见[语法规范](local-interaction-syntax-ch.md),宿主接口见[集成说明](local-integration-ch.md),可运行文档见[账单示例](
|
|
3
|
+
这些能力属于使用 `local-draft-2` 的 `0.4.0`。完整语法见[语法规范](local-interaction-syntax-ch.md),宿主接口见[集成说明](../integration/local-integration-ch.md),可运行文档见[账单示例](../../examples/local/recipes/invoice-zh.reactive.md)。
|
|
4
4
|
|
|
5
5
|
## 命名值
|
|
6
6
|
|
|
@@ -84,4 +84,4 @@ null 格式化为空字符串,其余参数严格检查类型,不把字符串
|
|
|
84
84
|
|
|
85
85
|
## 兼容性
|
|
86
86
|
|
|
87
|
-
现有表达式和 `round(x)` 保持原有行为。新增函数名称成为本版本的保留标识符;升级前应重命名使用这些名称的旧绑定,并同步修改引用。[变更记录](
|
|
87
|
+
现有表达式和 `round(x)` 保持原有行为。新增函数名称成为本版本的保留标识符;升级前应重命名使用这些名称的旧绑定,并同步修改引用。[变更记录](../../CHANGELOG-ch.md)记载了此次扩展。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reusing calculations and formatting values
|
|
2
2
|
|
|
3
|
-
These additions belong to `0.4.0`, which uses `local-draft-2`. See the [syntax specification](local-interaction-syntax-en.md), [integration API](local-integration-en.md) and [working example](
|
|
3
|
+
These additions belong to `0.4.0`, which uses `local-draft-2`. See the [syntax specification](local-interaction-syntax-en.md), [integration API](../integration/local-integration-en.md) and [working example](../../examples/local/recipes/invoice.reactive.md).
|
|
4
4
|
|
|
5
5
|
## Named values
|
|
6
6
|
|
|
@@ -84,4 +84,4 @@ Declaration diagnostics use `local.computation.*`: `placement`, `name`, `reserve
|
|
|
84
84
|
|
|
85
85
|
## Compatibility
|
|
86
86
|
|
|
87
|
-
Existing expressions and `round(x)` keep their behavior. The new function names are reserved identifiers in this release. Rename any pre-existing bindings with these names and update their references before upgrading. The [changelog](
|
|
87
|
+
Existing expressions and `round(x)` keep their behavior. The new function names are reserved identifiers in this release. Rename any pre-existing bindings with these names and update their references before upgrading. The [changelog](../../CHANGELOG.md) lists this addition.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 条件、校验与本地集合
|
|
2
2
|
|
|
3
|
-
这些能力扩展使用 `local-draft-2` 的 `0.4.0`。[工作坊示例](
|
|
3
|
+
这些能力扩展使用 `local-draft-2` 的 `0.4.0`。[工作坊示例](../../examples/local/recipes/workshop-zh.reactive.md)把人数预算、日期区间和已选主题表格放在同一份文档里,[命名计算](computations-formatting-ch.md)保存其中间结果。
|
|
4
4
|
|
|
5
5
|
## 跨字段校验
|
|
6
6
|
|
|
@@ -79,6 +79,6 @@
|
|
|
79
79
|
|
|
80
80
|
## 集成与兼容性
|
|
81
81
|
|
|
82
|
-
`LocalDocument.validations` 保存可序列化的 `LocalValidation` 元数据,宿主可随时调用 `runtime.validate()`,调用不会修改状态。编译后的文档仍可用 `structuredClone` 传递给 Worker。对象生命周期和持久化规则见[集成说明](local-integration-ch.md)。
|
|
82
|
+
`LocalDocument.validations` 保存可序列化的 `LocalValidation` 元数据,宿主可随时调用 `runtime.validate()`,调用不会修改状态。编译后的文档仍可用 `structuredClone` 传递给 Worker。对象生命周期和持久化规则见[集成说明](../integration/local-integration-ch.md)。
|
|
83
83
|
|
|
84
84
|
新增聚合函数名 `sum`、`average`、`minOf`、`maxOf` 成为保留字,升级前需重命名冲突绑定及其引用。对 `LocalValueKind` 做穷举检查的宿主应加入 `number-array`;可写多选与清单控件仍只接受字符串。预览版发布在 `next` 渠道。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Constraints, conditional tones and local collections
|
|
2
2
|
|
|
3
|
-
These additions extend `0.4.0`, which uses `local-draft-2`. The [workshop example](
|
|
3
|
+
These additions extend `0.4.0`, which uses `local-draft-2`. The [workshop example](../../examples/local/recipes/workshop.reactive.md) combines a participant budget, a date interval and a selected-subject table. [Named calculations](computations-formatting-en.md) hold its intermediate results.
|
|
4
4
|
|
|
5
5
|
## Cross-field validation
|
|
6
6
|
|
|
@@ -79,6 +79,6 @@ An empty array displays the headers and an empty-state message. Failure of the r
|
|
|
79
79
|
|
|
80
80
|
## Integration and compatibility
|
|
81
81
|
|
|
82
|
-
`LocalDocument.validations` contains serializable `LocalValidation` metadata. Hosts can call `runtime.validate()` at any time without changing state. The compiled document remains transferable to a Worker with `structuredClone`. The [core integration guide](local-integration-en.md) describes its lifetime and persistence rules.
|
|
82
|
+
`LocalDocument.validations` contains serializable `LocalValidation` metadata. Hosts can call `runtime.validate()` at any time without changing state. The compiled document remains transferable to a Worker with `structuredClone`. The [core integration guide](../integration/local-integration-en.md) describes its lifetime and persistence rules.
|
|
83
83
|
|
|
84
84
|
The aggregate names `sum`, `average`, `minOf` and `maxOf` become reserved identifiers. Rename conflicting bindings and their references before using this release. Hosts with exhaustive `LocalValueKind` checks should add `number-array`; writable multi-select and checklist controls still require strings. The preview is published on the `next` channel.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](diagnostics-counting-en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
本页定义诊断契约、字符长度单位与资源预算作用域。
|
|
6
6
|
|
|
7
7
|
## 诊断契约
|
|
8
8
|
|
|
@@ -23,6 +23,26 @@ for (const diagnostic of result.diagnostics) {
|
|
|
23
23
|
|
|
24
24
|
诊断数量达到上限时,新警告可以被省略;新的错误优先替换已有警告。编译错误使 `ok` 为 `false`。运行时写入被拒绝时,已提交状态与 revision 保持不变。
|
|
25
25
|
|
|
26
|
+
### 原生 HTML 安全回退
|
|
27
|
+
|
|
28
|
+
| 情况 | 机器契约 | 宿主处理 |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| 原生 HTML 已转换为惰性源码 | `code: 'local.html.fallback'`,`severity: 'warning'` | 对应 HTML 已成为纯文本,可以单独放行此警告 |
|
|
31
|
+
| 未知 ReactiveMD 组件,例如 `<slidr />` | `code: 'local.component.unknown'` | 按宿主的组件策略报告或拒绝 |
|
|
32
|
+
| 致命编译失败 | `result.ok === false`,并有 `error` 诊断 | 拒绝此次编译;界面显示源码不改变失败结果 |
|
|
33
|
+
|
|
34
|
+
专用回退码覆盖两条编译路径中不支持的原生标签、属性、不完整片段和原生表格。它只说明对应 HTML 已回退,同一文档仍可能有其他问题。移除原生 HTML 中未获授权的脚本等能力裁剪继续使用 `local.html.capability`,不属于源码回退。旧诊断码仍保留注册;宿主应按专用码设置放行策略:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const result = compileLocal(source);
|
|
38
|
+
if (!result.ok) throw new Error('编译失败');
|
|
39
|
+
const unhandled = result.diagnostics.filter(d => d.code !== 'local.html.fallback');
|
|
40
|
+
if (unhandled.length) throw new Error('文档需要检查');
|
|
41
|
+
// 可以按宿主的 HTML 策略渲染 result.document。
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
不同回退原因可以保留不同消息和模板键,分类使用 `code` 与 `severity`。渲染行为见 [HTML 原文回退](html-compatibility-ch.md#原文回退)。
|
|
45
|
+
|
|
26
46
|
## 文本长度
|
|
27
47
|
|
|
28
48
|
| 用途 | 计数单位 |
|
|
@@ -81,4 +101,4 @@ for (const diagnostic of result.diagnostics) {
|
|
|
81
101
|
|
|
82
102
|
## 验收
|
|
83
103
|
|
|
84
|
-
回归用例覆盖 Unicode 长度、UTF-16 定位、CRLF、预算临界值、双语诊断字段一致性,以及警告占满时的错误保留。编辑器和 CLI 的集成检查使用真实诊断对象;业务逻辑不依赖完整消息文本。版本兼容说明见[版本与兼容性](compatibility-ch.md),命令行使用见[作者工具](author-tools-ch.md)。
|
|
104
|
+
回归用例覆盖 Unicode 长度、UTF-16 定位、CRLF、预算临界值、双语诊断字段一致性,以及警告占满时的错误保留。编辑器和 CLI 的集成检查使用真实诊断对象;业务逻辑不依赖完整消息文本。版本兼容说明见[版本与兼容性](../compatibility/compatibility-ch.md),命令行使用见[作者工具](../integration/author-tools-ch.md)。
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[中文](diagnostics-counting-ch.md)
|
|
4
4
|
|
|
5
|
-
This page defines the
|
|
5
|
+
This page defines the diagnostics contract, text-length units and resource-budget scopes.
|
|
6
6
|
|
|
7
7
|
## Diagnostics contract
|
|
8
8
|
|
|
@@ -23,6 +23,26 @@ Ranges are zero-based UTF-16 indexes with half-open intervals `[start, end)`. Li
|
|
|
23
23
|
|
|
24
24
|
When the diagnostic limit is reached, new warnings may be omitted; a new error takes priority over an existing warning. Compile errors make `ok` false. Rejected runtime writes preserve committed state and revision.
|
|
25
25
|
|
|
26
|
+
### Safe native HTML fallback
|
|
27
|
+
|
|
28
|
+
| Outcome | Machine contract | Host action |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| Native HTML converted to inert source | `code: 'local.html.fallback'`, `severity: 'warning'` | The affected HTML is already literal text; this warning can be allowed explicitly |
|
|
31
|
+
| Unknown ReactiveMD component, such as `<slidr />` | `code: 'local.component.unknown'` | Report or reject according to the host's component policy |
|
|
32
|
+
| Fatal compilation failure | `result.ok === false`, with an `error` diagnostic | Reject the compilation; rendering source text does not change this outcome |
|
|
33
|
+
|
|
34
|
+
The fallback code covers unsupported native tags, attributes, malformed fragments and native tables in both compilation routes. It does not mean the entire document has no other problems. Capability stripping, such as removing disabled scripts from native HTML, retains `local.html.capability`; it is not source fallback. Existing codes remain registered, but hosts should use the dedicated code for this allowance:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const result = compileLocal(source);
|
|
38
|
+
if (!result.ok) throw new Error('Compilation failed');
|
|
39
|
+
const unhandled = result.diagnostics.filter(d => d.code !== 'local.html.fallback');
|
|
40
|
+
if (unhandled.length) throw new Error('Document needs review');
|
|
41
|
+
// result.document is ready for rendering under the host's HTML policy.
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Messages and template keys describe the cause and may differ across fallback cases. Use `code` and `severity` for classification. See [HTML source fallback](html-compatibility-en.md#source-fallback) for rendering behavior.
|
|
45
|
+
|
|
26
46
|
## Text length
|
|
27
47
|
|
|
28
48
|
| Purpose | Unit |
|
|
@@ -81,4 +101,4 @@ Expression compilation caches hold at most 500 entries; formula compilation cach
|
|
|
81
101
|
|
|
82
102
|
## Validation
|
|
83
103
|
|
|
84
|
-
Regression cases cover Unicode lengths, UTF-16 locations, CRLF, budget boundaries, equivalent machine fields across languages, and error retention after warnings fill the diagnostic limit. Editor and CLI checks use real diagnostic objects. Business logic does not depend on complete message text. See [Versions and compatibility](compatibility-en.md) and [Author tools](author-tools-en.md).
|
|
104
|
+
Regression cases cover Unicode lengths, UTF-16 locations, CRLF, budget boundaries, equivalent machine fields across languages, and error retention after warnings fill the diagnostic limit. Editor and CLI checks use real diagnostic objects. Business logic does not depend on complete message text. See [Versions and compatibility](../compatibility/compatibility-en.md) and [Author tools](../integration/author-tools-en.md).
|