reactive-md 0.5.1 → 0.5.2

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 (33) hide show
  1. package/CHANGELOG-ch.md +18 -0
  2. package/CHANGELOG.md +18 -0
  3. package/README-ch.md +7 -6
  4. package/README-en.md +8 -6
  5. package/README.md +8 -6
  6. package/dist-library/reactive-md-react.js +1661 -1630
  7. package/dist-library/reactive-md.js +323 -307
  8. package/dist-library/{runtime-CXBdLQ3A.js → runtime-UiQPz5ZV.js} +5327 -4925
  9. package/dist-library/types/local/LocalDocumentView.d.ts +10 -2
  10. package/dist-library/types/local/diagnostics.d.ts +40 -0
  11. package/dist-library/types/local/html-names.d.ts +6 -0
  12. package/dist-library/types/local/index.d.ts +1 -1
  13. package/dist-library/types/local/limits.d.ts +8 -0
  14. package/dist-library/types/local/options.d.ts +6 -1
  15. package/dist-library/types/local/render-types.d.ts +11 -0
  16. package/dist-library/types/local/types.d.ts +18 -0
  17. package/dist-library/types/local/worker.d.ts +4 -1
  18. package/dist-library/types/react/index.d.ts +1 -1
  19. package/dist-standalone/reactive-md-standalone.js +32 -32
  20. package/docs/compatibility-ch.md +7 -5
  21. package/docs/compatibility-en.md +7 -5
  22. package/docs/component-development-ch.md +4 -4
  23. package/docs/component-development-en.md +3 -3
  24. package/docs/component-protocol-ch.md +48 -11
  25. package/docs/component-protocol-en.md +48 -11
  26. package/docs/local-integration-ch.md +26 -2
  27. package/docs/local-integration-en.md +26 -2
  28. package/docs/release-0.5.2-ch.md +35 -0
  29. package/docs/release-0.5.2-en.md +35 -0
  30. package/docs/releasing-ch.md +7 -7
  31. package/docs/releasing-en.md +8 -8
  32. package/examples/conformance/README.md +1 -1
  33. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { Diagnostic, LocalCompileOptions, LocalDocument, LocalNode, LocalRuntime } from './types.js';
3
- import type { LocalRenderMode } from './render-types.js';
3
+ import type { LocalHostData, LocalHostRenderer, LocalRenderMode } from './render-types.js';
4
4
  import { type LocalColorScheme, type LocalThemeDefinition } from './theme.js';
5
5
  import { type LocalLocale, type Localize } from './i18n.js';
6
6
  /**
@@ -42,6 +42,10 @@ export interface LocalDocumentViewProps {
42
42
  staticFirst?: boolean;
43
43
  /** Trusted image URL mapping; only called after the image URL passed validation. */
44
44
  imageResolver?: LocalImageResolver;
45
+ /** JSON-safe host data keyed by `${kind}:${ref}`; never enters the worker. */
46
+ hostData?: LocalHostData;
47
+ /** Client-only renderer for hostComponent nodes; never enters the worker. */
48
+ hostRenderer?: LocalHostRenderer;
45
49
  }
46
50
  export interface LocalReactiveDocumentProps {
47
51
  source: string;
@@ -59,6 +63,10 @@ export interface LocalReactiveDocumentProps {
59
63
  staticFirst?: boolean;
60
64
  /** Trusted image URL mapping forwarded to `LocalDocumentView`. */
61
65
  imageResolver?: LocalImageResolver;
66
+ /** JSON-safe host data keyed by `${kind}:${ref}`; never enters the worker. */
67
+ hostData?: LocalHostData;
68
+ /** Client-only renderer for hostComponent nodes; never enters the worker. */
69
+ hostRenderer?: LocalHostRenderer;
62
70
  /**
63
71
  * Host-owned compile options. HTML capability flags select the temporary
64
72
  * whole-document native branch; the component recompiles when a flag or the
@@ -85,5 +93,5 @@ export declare function textProblem(value: string, options: {
85
93
  export declare const COMPONENTS: Record<string, (props: LocalComponentProps) => ReactNode>;
86
94
  /** Keep the two render paths in separate components so mode changes obey hook ordering. */
87
95
  export declare function LocalDocumentView(props: LocalDocumentViewProps): import("react").JSX.Element;
88
- export declare function LocalReactiveDocument({ source, onDiagnostics, urlPolicy, locale, themes, colorScheme, mode, staticFirst, imageResolver, compileOptions, }: LocalReactiveDocumentProps): import("react").JSX.Element;
96
+ export declare function LocalReactiveDocument({ source, onDiagnostics, urlPolicy, locale, themes, colorScheme, mode, staticFirst, imageResolver, hostData, hostRenderer, compileOptions, }: LocalReactiveDocumentProps): import("react").JSX.Element;
89
97
  export {};
@@ -98,6 +98,10 @@ export declare const LOCAL_DIAGNOSTIC_MESSAGES: {
98
98
  readonly en: 'Compile option limits.maxSyntaxNodes must be a positive safe integer.';
99
99
  readonly zh: '编译选项 limits.maxSyntaxNodes 必须是正安全整数。';
100
100
  };
101
+ readonly 'options.hostComponents': {
102
+ readonly en: 'Compile option hostComponents is invalid: {detail}';
103
+ readonly zh: '编译选项 hostComponents 无效:{detail}';
104
+ };
101
105
  readonly 'theme.expression': {
102
106
  readonly en: 'Theme names must be static text, not expressions.';
103
107
  readonly zh: '主题名称必须是静态文本,不能是表达式。';
@@ -290,6 +294,34 @@ export declare const LOCAL_DIAGNOSTIC_MESSAGES: {
290
294
  readonly en: 'Attribute {name} is static and cannot contain interpolations.';
291
295
  readonly zh: '属性 {name} 是静态的,不能包含插值。';
292
296
  };
297
+ readonly 'host.attributeUnknown': {
298
+ readonly en: 'Component <{component}> does not support attribute {name}.';
299
+ readonly zh: '组件 <{component}> 不支持属性 {name}。';
300
+ };
301
+ readonly 'host.attributeRequired': {
302
+ readonly en: 'Component <{component}> is missing required attribute {name}.';
303
+ readonly zh: '组件 <{component}> 缺少必需属性 {name}。';
304
+ };
305
+ readonly 'host.attributeStatic': {
306
+ readonly en: 'Attribute {name} is static and cannot contain interpolations.';
307
+ readonly zh: '属性 {name} 是静态的,不能包含插值。';
308
+ };
309
+ readonly 'host.attributeType': {
310
+ readonly en: 'Attribute {name} requires a {kind}, got "{value}".';
311
+ readonly zh: '属性 {name} 需要 {kind},当前为“{value}”。';
312
+ };
313
+ readonly 'host.attributeEnum': {
314
+ readonly en: 'Attribute {name} must be one of {values}, got "{value}".';
315
+ readonly zh: '属性 {name} 必须是 {values} 之一,当前为“{value}”。';
316
+ };
317
+ readonly 'host.attributePattern': {
318
+ readonly en: 'Attribute {name} must match pattern {pattern}.';
319
+ readonly zh: '属性 {name} 必须匹配模式 {pattern}。';
320
+ };
321
+ readonly 'host.attributeInterpolation': {
322
+ readonly en: 'Attribute {name} must be a literal matching {pattern} or one full interpolation.';
323
+ readonly zh: '属性 {name} 必须是匹配 {pattern} 的字面值,或一个完整插值。';
324
+ };
293
325
  readonly 'expression.emptyAttribute': {
294
326
  readonly en: 'Attribute {name} interpolation cannot be empty.';
295
327
  readonly zh: '属性 {name} 的插值不能为空。';
@@ -1209,6 +1241,7 @@ declare const LOCAL_DIAGNOSTIC_TEMPLATE_ALIASES: {
1209
1241
  readonly 'local.options.invalid.object': 'options.notObject';
1210
1242
  readonly 'local.options.invalid.limits': 'options.limitsNotObject';
1211
1243
  readonly 'local.options.invalid.max-syntax-nodes': 'options.maxSyntaxNodes';
1244
+ readonly 'local.options.invalid.host-components': 'options.hostComponents';
1212
1245
  readonly 'local.budget.document': 'budget.document';
1213
1246
  readonly 'local.budget.nodes': 'budget.syntaxNodes';
1214
1247
  readonly 'local.budget.nesting': 'budget.nesting';
@@ -1279,6 +1312,13 @@ declare const LOCAL_DIAGNOSTIC_TEMPLATE_ALIASES: {
1279
1312
  readonly 'local.attribute.color': 'attribute.color';
1280
1313
  readonly 'local.attribute.required': 'attribute.required';
1281
1314
  readonly 'local.attribute.static': 'attribute.static';
1315
+ readonly 'local.host.attribute.unknown': 'host.attributeUnknown';
1316
+ readonly 'local.host.attribute.required': 'host.attributeRequired';
1317
+ readonly 'local.host.attribute.static': 'host.attributeStatic';
1318
+ readonly 'local.host.attribute.type': 'host.attributeType';
1319
+ readonly 'local.host.attribute.enum': 'host.attributeEnum';
1320
+ readonly 'local.host.attribute.pattern': 'host.attributePattern';
1321
+ readonly 'local.host.attribute.interpolation': 'host.attributeInterpolation';
1282
1322
  readonly 'local.attribute.type.number': 'attribute.numberInvalid';
1283
1323
  readonly 'local.attribute.type.number-interpolation': 'attribute.numberInterpolationInvalid';
1284
1324
  readonly 'local.attribute.type.integer': 'attribute.integer';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * P0 native HTML tag names. The parser handles these before component tags, and
3
+ * host component schemas may not reuse them because document parsing would
4
+ * never dispatch such a tag to a host component.
5
+ */
6
+ export declare const LOCAL_HTML_NAMES: ReadonlySet<string>;
@@ -14,7 +14,7 @@ export type { LocalVersionDeclaration } from './types.js';
14
14
  export type { LocalLocale } from './locale.js';
15
15
  export { LOCAL_THEME_PROTOCOL, DEFAULT_LOCAL_THEME, resolveLocalTheme, isLocalThemeName } from './theme.js';
16
16
  export type { LocalColorScheme, LocalThemeDefinition, LocalThemeResolution } from './theme.js';
17
- export type { Diagnostic, LocalDiagnosticParam, LocalDiagnosticParams, SourceRange, LocalValue, LocalValueKind, LocalNode, LocalBinding, LocalComputation, LocalValidation, LocalDocument, LocalHtmlOptions, LocalHtmlPolicy, LocalCompileLimits, LocalCompileOptions, LocalCompileResult, LocalRuntime, LocalSnapshot } from './types.js';
17
+ export type { Diagnostic, LocalDiagnosticParam, LocalDiagnosticParams, SourceRange, LocalValue, LocalValueKind, LocalNode, LocalBinding, LocalComputation, LocalValidation, LocalDocument, LocalHtmlOptions, LocalHtmlPolicy, LocalCompileLimits, LocalCompileOptions, LocalCompileResult, LocalRuntime, LocalSnapshot, LocalHostPropKind, LocalHostPropSchema, LocalHostComponentSchema } from './types.js';
18
18
  export { LOCAL_STATE_FORMAT, localSourceDigest, createLocalStateFile, parseLocalState, resolveLocalState, applyLocalState, exportLocalState, importLocalState, serializeLocalState, } from './state.js';
19
19
  export type { LocalStateGenerator, LocalStateFile, LocalStateParseResult, LocalStateResolution, } from './state.js';
20
20
  export { planLocalStateRetention, applyLocalStateRetention } from './retention.js';
@@ -41,5 +41,13 @@ export declare const DEFAULT_LOCAL_DATA_TABLE_ROWS = 100;
41
41
  export declare const MAX_LOCAL_DATA_TABLE_COLUMNS = 20;
42
42
  export declare const MAX_LOCAL_DATA_DOCUMENT_ROWS = 2000;
43
43
  export declare const MAX_LOCAL_DATA_DOCUMENT_CELLS = 10000;
44
+ /** Host component schemas accepted in one compilation. */
45
+ export declare const MAX_LOCAL_HOST_COMPONENTS = 32;
46
+ /** Host component and property name length, in UTF-16 code units. */
47
+ export declare const MAX_LOCAL_HOST_NAME_LENGTH = 128;
48
+ /** Host property RegExp source length, in UTF-16 code units. */
49
+ export declare const MAX_LOCAL_HOST_PATTERN_LENGTH = 512;
50
+ /** Allowed literals in one host enum property. */
51
+ export declare const MAX_LOCAL_HOST_ENUM_VALUES = 64;
44
52
  /** Linear validation; the final dot must have text on both sides in the domain. */
45
53
  export declare function isLocalEmail(value: string): boolean;
@@ -1,4 +1,4 @@
1
- import type { LocalCompileOptions, LocalHtmlPolicy } from './types.js';
1
+ import type { LocalCompileOptions, LocalHostComponentSchema, LocalHtmlPolicy } from './types.js';
2
2
  /** Capability flags that select the temporary whole-document HTML branch. */
3
3
  export declare const LOCAL_HTML_FLAGS: readonly ['enableCss', 'enableJavaScript', 'enableExtendedHtml'];
4
4
  export type LocalHtmlFlag = (typeof LOCAL_HTML_FLAGS)[number];
@@ -10,10 +10,15 @@ export type LocalOptionCheck = {
10
10
  html: LocalHtmlPolicy;
11
11
  /** True when at least one capability flag is enabled. */
12
12
  htmlActive: boolean;
13
+ /** Validated host component schemas; empty when the option is absent. */
14
+ hostComponents: readonly LocalHostComponentSchema[];
15
+ /** Host tag name lookup; names are already lowercase kebab-case. */
16
+ hostByName: ReadonlyMap<string, LocalHostComponentSchema>;
13
17
  } | {
14
18
  ok: false;
15
19
  message: string;
16
20
  key: string;
21
+ detail?: string;
17
22
  };
18
23
  /**
19
24
  * Read and validate host compile options once. Every call site (Markdown
@@ -14,3 +14,14 @@ export interface LocalVisualProps extends Omit<LocalRenderContext, 'mode'> {
14
14
  /** Defaults to interactive so hand-built visual fixtures stay compatible. */
15
15
  mode?: LocalRenderMode;
16
16
  }
17
+ /**
18
+ * JSON-safe host data indexed by `${kind}:${ref}` for `hostComponent` nodes.
19
+ * It is read only by the client renderer and never enters the worker.
20
+ */
21
+ export type LocalHostData = Readonly<Record<string, unknown>>;
22
+ /**
23
+ * Client-only renderer for `hostComponent` nodes. Receiving `unknown` keeps the
24
+ * contract loose; a synchronous throw falls back to the inert placeholder, so
25
+ * a bad renderer never blanks the whole document.
26
+ */
27
+ export type LocalHostRenderer = (node: LocalNode, data: unknown, ctx: LocalRenderContext) => ReactNode;
@@ -187,8 +187,26 @@ export interface LocalHtmlPolicy {
187
187
  readonly enableJavaScript: boolean;
188
188
  readonly enableExtendedHtml: boolean;
189
189
  }
190
+ export type LocalHostPropKind = 'string' | 'number' | 'boolean' | 'enum';
191
+ export interface LocalHostPropSchema {
192
+ readonly kind: LocalHostPropKind;
193
+ readonly required?: boolean;
194
+ /** Reject `{{ ... }}` in this property. */
195
+ readonly static?: boolean;
196
+ /** Allowed literals for kind 'enum'; required and non-empty for enums. */
197
+ readonly enum?: readonly string[];
198
+ /** RegExp source applied to literal string values; restricted to a linear-time-safe subset. */
199
+ readonly pattern?: string;
200
+ }
201
+ export interface LocalHostComponentSchema {
202
+ readonly name: string;
203
+ readonly form: 'leaf';
204
+ readonly props: Readonly<Record<string, LocalHostPropSchema>>;
205
+ }
190
206
  export interface LocalCompileOptions extends LocalHtmlOptions {
191
207
  readonly limits?: LocalCompileLimits;
208
+ /** Host-defined leaf components recognized alongside the built-in schema. */
209
+ readonly hostComponents?: readonly LocalHostComponentSchema[];
192
210
  }
193
211
  export type LocalCompileResult = {
194
212
  ok: true;
@@ -4,7 +4,10 @@ export declare const LOCAL_COMPILE_DELAY_MS = 150;
4
4
  export interface LocalCompileRequest {
5
5
  id: number;
6
6
  source: string;
7
- /** Capability flags and limits granted for this compile. */
7
+ /**
8
+ * Capability flags, limits and host component schemas for this compile.
9
+ * `hostComponents` selects the host leaf tags the parser may build.
10
+ */
8
11
  options?: LocalCompileOptions;
9
12
  }
10
13
  export type LocalCompileResponse = {
@@ -1,5 +1,5 @@
1
1
  export { LocalDocumentView, LocalReactiveDocument } from '../local/LocalDocumentView.js';
2
2
  export type { LocalDocumentViewProps, LocalReactiveDocumentProps, LocalUrlPolicy, LocalImageResolver, } from '../local/LocalDocumentView.js';
3
- export type { LocalRenderMode } from '../local/render-types.js';
3
+ export type { LocalRenderMode, LocalHostData, LocalHostRenderer } from '../local/render-types.js';
4
4
  export type { LocalLocale } from '../local/locale.js';
5
5
  export type { LocalColorScheme, LocalThemeDefinition } from '../local/theme.js';