reactive-md 0.0.0-stage → 0.3.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.md +40 -0
- package/CONTRIBUTING.md +61 -0
- package/LICENSE +21 -0
- package/README.en.md +75 -0
- package/README.md +87 -2
- package/SECURITY.md +68 -0
- package/THIRD_PARTY_NOTICES.md +1967 -0
- package/dist-library/reactive-md-react.js +3514 -0
- package/dist-library/reactive-md.css +2 -0
- package/dist-library/reactive-md.js +4 -0
- package/dist-library/runtime-D4phFXOr.js +10937 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +19 -0
- package/dist-library/types/local/compiler.d.ts +3 -0
- package/dist-library/types/local/expression.d.ts +37 -0
- package/dist-library/types/local/index.d.ts +6 -0
- package/dist-library/types/local/limits.d.ts +13 -0
- package/dist-library/types/local/math-view.d.ts +14 -0
- package/dist-library/types/local/math.d.ts +43 -0
- package/dist-library/types/local/parser.d.ts +7 -0
- package/dist-library/types/local/render-types.d.ts +12 -0
- package/dist-library/types/local/runtime.d.ts +2 -0
- package/dist-library/types/local/schema.d.ts +55 -0
- package/dist-library/types/local/types.d.ts +76 -0
- package/dist-library/types/local/version.d.ts +2 -0
- package/dist-library/types/local/visuals.d.ts +3 -0
- package/dist-library/types/react/index.d.ts +2 -0
- package/docs/compatibility.md +67 -0
- package/docs/local-guide.md +936 -0
- package/docs/local-integration.md +193 -0
- package/docs/local-interaction-syntax.md +437 -0
- package/docs/performance.md +30 -0
- package/docs/releasing.md +92 -0
- package/examples/conformance/README.md +11 -0
- package/examples/conformance/local-draft-1.json +49 -0
- package/examples/integration/README.md +29 -0
- package/examples/integration/core/index.mjs +19 -0
- package/examples/integration/core/package.json +7 -0
- package/examples/integration/react/index.html +12 -0
- package/examples/integration/react/main.jsx +21 -0
- package/examples/integration/react/package.json +9 -0
- package/examples/local/README.md +66 -0
- package/examples/local/catalog.reactive.md +20 -0
- package/examples/local/charts.reactive.md +73 -0
- package/examples/local/checklist.reactive.md +32 -0
- package/examples/local/comparison.reactive.md +47 -0
- package/examples/local/components.reactive.md +44 -0
- package/examples/local/counter.reactive.md +7 -0
- package/examples/local/diagnostics.reactive.md +54 -0
- package/examples/local/diagram.reactive.md +44 -0
- package/examples/local/gallery.reactive.md +61 -0
- package/examples/local/parameters.reactive.md +36 -0
- package/examples/local/planning.reactive.md +24 -0
- package/examples/local/pricing.reactive.md +20 -0
- package/package.json +73 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './local/index.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Diagnostic, LocalDocument, LocalRuntime } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Host-owned URL allowlist. It runs only after the renderer has validated the
|
|
4
|
+
* protocol, and a thrown error denies the URL.
|
|
5
|
+
*/
|
|
6
|
+
export type LocalUrlPolicy = (url: string, kind: 'image' | 'link') => boolean;
|
|
7
|
+
export interface LocalDocumentViewProps {
|
|
8
|
+
document: LocalDocument;
|
|
9
|
+
runtime: LocalRuntime;
|
|
10
|
+
onDiagnostics?: (diagnostics: Diagnostic[]) => void;
|
|
11
|
+
urlPolicy?: LocalUrlPolicy;
|
|
12
|
+
}
|
|
13
|
+
export interface LocalReactiveDocumentProps {
|
|
14
|
+
source: string;
|
|
15
|
+
onDiagnostics?: (diagnostics: Diagnostic[]) => void;
|
|
16
|
+
urlPolicy?: LocalUrlPolicy;
|
|
17
|
+
}
|
|
18
|
+
export declare function LocalDocumentView({ document, runtime, onDiagnostics, urlPolicy, }: LocalDocumentViewProps): import("react").JSX.Element;
|
|
19
|
+
export declare function LocalReactiveDocument({ source, onDiagnostics, urlPolicy, }: LocalReactiveDocumentProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LocalValue, LocalValueKind } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The local-draft expression language.
|
|
4
|
+
*
|
|
5
|
+
* The parser produces an explicit AST. Evaluation never uses eval, Function or
|
|
6
|
+
* the global object: only the provided environment and a fixed set of pure
|
|
7
|
+
* functions are reachable. Numbers must stay finite, strings and arrays have a
|
|
8
|
+
* budget, and every operator is type checked.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LocalExpressionError extends Error {
|
|
11
|
+
readonly offset: number;
|
|
12
|
+
readonly code: string;
|
|
13
|
+
constructor(code: string, message: string, offset?: number);
|
|
14
|
+
}
|
|
15
|
+
export interface LocalExpression {
|
|
16
|
+
readonly source: string;
|
|
17
|
+
readonly dependencies: string[];
|
|
18
|
+
evaluate(env: Record<string, LocalValue>): LocalValue;
|
|
19
|
+
inferType(env: Record<string, LocalValueKind>): LocalValueKind;
|
|
20
|
+
}
|
|
21
|
+
/** Names that cannot be used as a document binding. */
|
|
22
|
+
export declare const RESERVED_NAMES: Set<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Allocation-free budget check for a value stored in the runtime or read from
|
|
25
|
+
* an expression environment. Returns a short reason, or null when the value
|
|
26
|
+
* fits. String lengths are UTF-16 code units, matching the existing
|
|
27
|
+
* concatenation budget; `len()` keeps counting code points.
|
|
28
|
+
*/
|
|
29
|
+
export declare function localValueBudgetError(value: LocalValue): string | null;
|
|
30
|
+
export declare function compileExpression(source: string): LocalExpression;
|
|
31
|
+
/** Render a template to scalar text. Arrays are rejected rather than serialized. */
|
|
32
|
+
export declare function interpolate(template: string, env: Record<string, LocalValue>): string;
|
|
33
|
+
/**
|
|
34
|
+
* Evaluate a template that is exactly one interpolation, preserving its type.
|
|
35
|
+
* Mixed templates and plain text fall back to text rendering.
|
|
36
|
+
*/
|
|
37
|
+
export declare function expressionValue(template: string, env: Record<string, LocalValue>): LocalValue;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { compileLocal } from './compiler.js';
|
|
2
|
+
export { createLocalRuntime } from './runtime.js';
|
|
3
|
+
export { compileExpression, LocalExpressionError } from './expression.js';
|
|
4
|
+
export { compileLatex, samplePlot } from './math.js';
|
|
5
|
+
export { LOCAL_SYNTAX_VERSION } from './version.js';
|
|
6
|
+
export type { Diagnostic, SourceRange, LocalValue, LocalValueKind, LocalNode, LocalBinding, LocalDocument, LocalCompileResult, LocalRuntime, LocalSnapshot } from './types.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Shared limits for source compilation, runtime values and visual work. */
|
|
2
|
+
export declare const MAX_LOCAL_DOCUMENT_LENGTH = 1000000;
|
|
3
|
+
export declare const MAX_LOCAL_STRING_LENGTH = 100000;
|
|
4
|
+
export declare const MAX_LOCAL_ARRAY_LENGTH = 10000;
|
|
5
|
+
export declare const MAX_LOCAL_VALUE_CHARACTERS = 100000;
|
|
6
|
+
export declare const MAX_LOCAL_DIAGNOSTICS = 100;
|
|
7
|
+
export declare const MAX_LOCAL_DIAGNOSTIC_LENGTH = 2000;
|
|
8
|
+
export declare const MAX_LOCAL_PLOT_CURVES = 16;
|
|
9
|
+
export declare const MAX_LOCAL_PLOT_POINTS = 20000;
|
|
10
|
+
export declare const MAX_LOCAL_PLOT_STEPS = 2000000;
|
|
11
|
+
export declare const MAX_LOCAL_EMAIL_LENGTH = 254;
|
|
12
|
+
/** Linear validation; the final dot must have text on both sides in the domain. */
|
|
13
|
+
export declare function isLocalEmail(value: string): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Safe native MathML rendering for local LaTeX.
|
|
4
|
+
*
|
|
5
|
+
* The renderer never interprets HTML, styles, macros, files or links from the
|
|
6
|
+
* source. Unknown commands are shown as literal text, so a formula that cannot
|
|
7
|
+
* be computed still remains readable. All source text passes through React as
|
|
8
|
+
* text nodes.
|
|
9
|
+
*/
|
|
10
|
+
export interface LatexViewProps {
|
|
11
|
+
source: string;
|
|
12
|
+
display?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function LatexView({ source, display }: LatexViewProps): ReactElement;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LocalValue } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Computable LaTeX for local plots.
|
|
4
|
+
*
|
|
5
|
+
* The parser builds an explicit AST; evaluation never uses eval/Function and
|
|
6
|
+
* only reads the independent variable x plus numeric bindings from the
|
|
7
|
+
* document. Unsupported structures (integrals, matrices, macros, ...) are
|
|
8
|
+
* rejected at compile time with an offset into the LaTeX source.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LatexError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly offset: number;
|
|
13
|
+
constructor(code: string, message: string, offset?: number);
|
|
14
|
+
}
|
|
15
|
+
export interface LatexExpression {
|
|
16
|
+
readonly source: string;
|
|
17
|
+
dependencies: string[];
|
|
18
|
+
evaluate(x: number, env: Record<string, LocalValue>, budget?: LatexEvaluationBudget): number;
|
|
19
|
+
}
|
|
20
|
+
/** Shared step budget used by samplePlot so the whole curve has one bound. */
|
|
21
|
+
export interface LatexEvaluationBudget {
|
|
22
|
+
steps: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
}
|
|
25
|
+
export interface PlotPoint {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number | null;
|
|
28
|
+
}
|
|
29
|
+
export interface PlotSample {
|
|
30
|
+
points: PlotPoint[];
|
|
31
|
+
endpoint: number | null;
|
|
32
|
+
}
|
|
33
|
+
export declare function compileLatex(source: string): LatexExpression;
|
|
34
|
+
/**
|
|
35
|
+
* Samples y(x) across [min, max]. Undefined points and the sample after a
|
|
36
|
+
* detected break become null so a renderer cannot join the two sides of an
|
|
37
|
+
* asymptote. The array always has exactly `samples` points.
|
|
38
|
+
*
|
|
39
|
+
* The optional final budget is shared by every curve/plot in a document. Each
|
|
40
|
+
* evaluation is limited by whatever remains of both that shared budget and the
|
|
41
|
+
* per-curve budget, and a `latex-budget` error aborts the whole sampling pass.
|
|
42
|
+
*/
|
|
43
|
+
export declare function samplePlot(expression: LatexExpression, env: Record<string, LocalValue>, min: number, max: number, samples?: number, sharedBudget?: LatexEvaluationBudget): PlotSample;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Diagnostic } from './types.js';
|
|
2
|
+
import type { LocalNode } from './types.js';
|
|
3
|
+
/** A lexical pass shields code before recognizing local tags, interpolation and math. */
|
|
4
|
+
export declare function parseLocal(source: string): {
|
|
5
|
+
nodes: LocalNode[];
|
|
6
|
+
diagnostics: Diagnostic[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { LocalNode, LocalRuntime } from './types.js';
|
|
3
|
+
/** Rendering contract shared by the React views. Kept out of types.ts so the
|
|
4
|
+
* core compiler and runtime types never depend on React. */
|
|
5
|
+
export interface LocalRenderContext {
|
|
6
|
+
runtime: LocalRuntime;
|
|
7
|
+
render(nodes?: LocalNode[], visible?: boolean): ReactNode;
|
|
8
|
+
visible: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface LocalVisualProps extends LocalRenderContext {
|
|
11
|
+
node: LocalNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { LocalValue, LocalValueKind } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Static description of the `local-draft-1` component set. The compiler reads
|
|
4
|
+
* attribute types and defaults from here; the renderer may use the same table
|
|
5
|
+
* to know which props are dynamic and which controls own public state.
|
|
6
|
+
*/
|
|
7
|
+
export type LocalComponentForm = 'leaf' | 'inline' | 'container';
|
|
8
|
+
export type LocalChildRule = 'none' | 'any' | 'inline' | 'options' | 'tabs' | 'disclosures' | 'cards' | 'diagram' | 'table' | 'plot' | 'content';
|
|
9
|
+
export type LocalPropKind = 'string' | 'number' | 'boolean' | 'enum';
|
|
10
|
+
export interface LocalPropSchema {
|
|
11
|
+
kind: LocalPropKind;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
/** Reject `{{ ... }}` in this property. Used for names, ids and enums. */
|
|
14
|
+
static?: boolean;
|
|
15
|
+
/** Accept exactly one typed interpolation in place of a literal. */
|
|
16
|
+
dynamic?: boolean;
|
|
17
|
+
values?: readonly string[];
|
|
18
|
+
default?: LocalValue;
|
|
19
|
+
integer?: boolean;
|
|
20
|
+
positive?: boolean;
|
|
21
|
+
min?: number;
|
|
22
|
+
max?: number;
|
|
23
|
+
}
|
|
24
|
+
export type LocalBindingFamily = 'text' | 'number' | 'boolean' | 'choice' | 'date' | 'timer' | 'checklist' | 'tabs' | 'diagram';
|
|
25
|
+
export interface LocalBindingSchema {
|
|
26
|
+
kind: LocalValueKind;
|
|
27
|
+
required: boolean;
|
|
28
|
+
family: LocalBindingFamily;
|
|
29
|
+
/** Only one component may own this binding, and its state cannot be shared. */
|
|
30
|
+
exclusive?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `default` is the schema default for an ordinary property. `initialRule`
|
|
34
|
+
* describes how a component produces the value of a binding when the author
|
|
35
|
+
* omits `initial`.
|
|
36
|
+
*/
|
|
37
|
+
export type LocalInitialRule = 'empty' | 'false' | 'min' | 'nearest-zero' | 'first-option' | 'first-tab' | 'first-node' | 'checked' | 'duration';
|
|
38
|
+
export interface LocalComponentSchema {
|
|
39
|
+
name: string;
|
|
40
|
+
form: LocalComponentForm;
|
|
41
|
+
childRule: LocalChildRule;
|
|
42
|
+
label: 'none' | 'required' | 'optional';
|
|
43
|
+
/** Parent component names that may directly contain this structural child. */
|
|
44
|
+
parent?: readonly string[];
|
|
45
|
+
props: Record<string, LocalPropSchema>;
|
|
46
|
+
binding?: LocalBindingSchema;
|
|
47
|
+
initialRule?: LocalInitialRule;
|
|
48
|
+
}
|
|
49
|
+
export declare const LOCAL_COMPONENTS: Readonly<Record<string, LocalComponentSchema>>;
|
|
50
|
+
export declare const LOCAL_COMPONENT_NAMES: readonly string[];
|
|
51
|
+
export declare function getLocalComponent(name: string): LocalComponentSchema | undefined;
|
|
52
|
+
export declare function getPropDefault(component: LocalComponentSchema, prop: string): LocalValue | undefined;
|
|
53
|
+
export declare function closestName(name: string, candidates: readonly string[]): string | undefined;
|
|
54
|
+
export declare function suggestComponent(name: string): string | undefined;
|
|
55
|
+
export declare function suggestAttribute(component: LocalComponentSchema, name: string): string | undefined;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface SourceRange {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
}
|
|
5
|
+
export interface Diagnostic {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
severity: 'error' | 'warning';
|
|
9
|
+
range: SourceRange;
|
|
10
|
+
line: number;
|
|
11
|
+
column: number;
|
|
12
|
+
}
|
|
13
|
+
export type LocalValue = string | number | boolean | null | string[];
|
|
14
|
+
export type LocalValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array';
|
|
15
|
+
/** Markdown nodes retain their original source ranges; component attributes remain raw decoded strings. */
|
|
16
|
+
export interface LocalNode {
|
|
17
|
+
type: string;
|
|
18
|
+
id: string;
|
|
19
|
+
range: SourceRange;
|
|
20
|
+
children?: LocalNode[];
|
|
21
|
+
name?: string;
|
|
22
|
+
attrs?: Record<string, string>;
|
|
23
|
+
value?: string;
|
|
24
|
+
depth?: number;
|
|
25
|
+
ordered?: boolean;
|
|
26
|
+
start?: number;
|
|
27
|
+
checked?: boolean | null;
|
|
28
|
+
url?: string;
|
|
29
|
+
title?: string | null;
|
|
30
|
+
alt?: string;
|
|
31
|
+
lang?: string;
|
|
32
|
+
align?: ('left' | 'center' | 'right' | null)[];
|
|
33
|
+
}
|
|
34
|
+
export interface LocalBinding {
|
|
35
|
+
name: string;
|
|
36
|
+
nodeIds: string[];
|
|
37
|
+
type: LocalValueKind;
|
|
38
|
+
initial: LocalValue;
|
|
39
|
+
min?: number;
|
|
40
|
+
max?: number;
|
|
41
|
+
step?: number;
|
|
42
|
+
options?: string[];
|
|
43
|
+
owner?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface LocalDocument {
|
|
46
|
+
syntax: 'local';
|
|
47
|
+
source: string;
|
|
48
|
+
nodes: LocalNode[];
|
|
49
|
+
initialState: Record<string, LocalValue>;
|
|
50
|
+
bindings: Record<string, LocalBinding>;
|
|
51
|
+
}
|
|
52
|
+
export type LocalCompileResult = {
|
|
53
|
+
ok: true;
|
|
54
|
+
document: LocalDocument;
|
|
55
|
+
diagnostics: Diagnostic[];
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
diagnostics: Diagnostic[];
|
|
59
|
+
};
|
|
60
|
+
export interface LocalSnapshot {
|
|
61
|
+
revision: number;
|
|
62
|
+
state: Readonly<Record<string, LocalValue>>;
|
|
63
|
+
}
|
|
64
|
+
export interface LocalRuntime {
|
|
65
|
+
document: LocalDocument;
|
|
66
|
+
snapshot(): LocalSnapshot;
|
|
67
|
+
get(node: LocalNode): LocalValue;
|
|
68
|
+
set(node: LocalNode, value: LocalValue): Diagnostic[];
|
|
69
|
+
evaluate(expression: string): LocalValue;
|
|
70
|
+
text(template: string): string;
|
|
71
|
+
reset(node: LocalNode): void;
|
|
72
|
+
resetToken(node: LocalNode): number;
|
|
73
|
+
subscribe(listener: () => void): () => void;
|
|
74
|
+
dispose(): void;
|
|
75
|
+
}
|
|
76
|
+
export declare const localKey: (node: LocalNode) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 版本与兼容性
|
|
2
|
+
|
|
3
|
+
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。公开 API 与样式接入见[本地模式集成](local-integration.md)。
|
|
4
|
+
|
|
5
|
+
## 版本对应
|
|
6
|
+
|
|
7
|
+
| 项目 | 当前值 | 说明 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| 包版本 | `0.3.0` | 安装 `reactive-md@0.3.0` |
|
|
10
|
+
| 语法版本 | `local-draft-1` | `LOCAL_SYNTAX_VERSION`;当前构建只接受这一修订 |
|
|
11
|
+
| 核心入口 | `reactive-md` | 编译、表达式与运行时,不加载 React |
|
|
12
|
+
| React 入口 | `reactive-md/react` | `LocalReactiveDocument`、`LocalDocumentView` |
|
|
13
|
+
| 样式入口 | `reactive-md/styles.css` | 一份全局样式表,由宿主显式引入 |
|
|
14
|
+
|
|
15
|
+
一个包版本只对应一个语法修订。升级包之前,记录应用使用的 `LOCAL_SYNTAX_VERSION`。如果文档源码来自另一个语法修订,保留旧包版本渲染,或按下面的迁移说明改写。`compileLocal(source)` 不提供语法版本参数,也没有其他编译 options。
|
|
16
|
+
|
|
17
|
+
## 0.x 的兼容规则
|
|
18
|
+
|
|
19
|
+
- 次版本(`0.3` 到 `0.4`)可能包含破坏性变更;补丁版本只做兼容修复和安全修复。
|
|
20
|
+
- 0.x 阶段不承诺固定弃用周期。每项破坏性变更都会写入 [变更记录](../CHANGELOG.md),说明旧写法、新写法和迁移步骤。
|
|
21
|
+
- 1.0 之前,把每次升级都当成可能需要修改文档源码或宿主代码。
|
|
22
|
+
- 应用应固定包版本,保留原始 `.reactive.md` 源码,并在升级后用自己的文档和示例重新运行编译与渲染检查。
|
|
23
|
+
|
|
24
|
+
## 破坏性变更与迁移
|
|
25
|
+
|
|
26
|
+
作者可见的语法变化会建立新的语法修订,例如 `local-draft-2`,并提升次版本、更新 `LOCAL_SYNTAX_VERSION`。核心或 React API 的变化也会记录在变更记录中。项目不自动改写源码;升级后由作者或宿主按记录迁移。
|
|
27
|
+
|
|
28
|
+
旧版配置语法不属于 `local-draft-1`。常见替换如下:
|
|
29
|
+
|
|
30
|
+
| 旧写法 | `local-draft-1` 中的做法 |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `:::card`、`:::row` 等 directive | `<card>`、`<grid>` 等标签 |
|
|
33
|
+
| YAML `state:` 声明参数 | 控件上的 `bind` 与 `initial` |
|
|
34
|
+
| YAML `computed:` | 正文中的 `{{ 表达式 }}` |
|
|
35
|
+
| `actions:`、按钮动作、`on-*` 事件 | 没有等价入口;使用组件自带的交互和面板重置 |
|
|
36
|
+
| `data:` 或外部接口数据 | 直接写在正文的 Markdown 表格;参数由控件声明 |
|
|
37
|
+
| 持久化运行状态 | 由宿主保存原始源码;文档运行时状态只在当前实例内存中 |
|
|
38
|
+
|
|
39
|
+
## 持久化什么
|
|
40
|
+
|
|
41
|
+
持久化原始 `.reactive.md` 源码。不要持久化 `LocalDocument`、`LocalNode`、`node.id`、`initialState`、`LocalSnapshot` 或运行时的参数状态:它们属于当前运行时对象,跨版本不保证结构,也不保证字段含义。`node.id` 在源码变化后会重新生成。诊断中的行号、列号和偏移量用于定位当前源码,不是稳定的持久化标识。
|
|
42
|
+
|
|
43
|
+
## 诊断契约
|
|
44
|
+
|
|
45
|
+
`Diagnostic` 包含 `code`、`message`、`severity`、`range`、`line` 和 `column`。
|
|
46
|
+
|
|
47
|
+
- `line` 和 `column` 从 1 开始;`range.start` 和 `range.end` 是当前源码字符串中的索引。
|
|
48
|
+
- `line`、`column` 和 `range` 可以用于程序定位和编辑器跳转。
|
|
49
|
+
- `code` 是字符串标识,例如 `local.type`、`expression-type`、`latex-plot-range`。在一个固定的包版本内可以按它做粗分类;0.x 不承诺跨版本稳定,次版本可能调整 code。
|
|
50
|
+
- `message` 是中文显示文本,可能随时改写。不要解析 message,也不要按完整文本做业务判断。
|
|
51
|
+
- 当前 `local-draft-1` 产生的诊断 `severity` 都是 `error`。编译错误会让 `result.ok` 为 `false` 并停用预览;运行时局部错误只影响对应内容。
|
|
52
|
+
|
|
53
|
+
## 平台与运行环境
|
|
54
|
+
|
|
55
|
+
| 环境 | 当前状态 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| Node.js 22.12+ | 开发和 Node 端消费的最低版本;22.12 与 24 均通过 CI |
|
|
58
|
+
| ESM | 唯一模块格式;不提供 CommonJS 入口 |
|
|
59
|
+
| React 19 | `reactive-md/react` 的要求;核心入口不依赖 React |
|
|
60
|
+
| Microsoft Edge(Chromium 内核) | 已完成本地浏览器验证 |
|
|
61
|
+
| Playwright Chromium | Linux CI 浏览器检查通过 |
|
|
62
|
+
| Firefox、Safari/WebKit | 未验证,不作支持声明 |
|
|
63
|
+
| SSR | `react-dom/server` 静态渲染由发布前的 packed 检查覆盖;水合未验证,使用前需自行检查 |
|
|
64
|
+
|
|
65
|
+
Node 端消费指在 Node 中导入 `reactive-md`、调用 `compileLocal` 和 `createLocalRuntime`,不需要 DOM。React 渲染要求浏览器环境或宿主自行处理服务端输出。
|
|
66
|
+
|
|
67
|
+
语言范围见[语法规范](local-interaction-syntax.md),安全边界与宿主责任见[安全策略](../SECURITY.md)。
|