reactive-md 0.5.2 → 0.5.3

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 (45) hide show
  1. package/CHANGELOG-ch.md +11 -0
  2. package/CHANGELOG.md +11 -0
  3. package/README-ch.md +7 -7
  4. package/README-en.md +8 -8
  5. package/README.md +8 -8
  6. package/cli/build.mjs +1 -1
  7. package/cli/package.mjs +1 -0
  8. package/dist-library/authoring-DJJjKYg9.js +842 -0
  9. package/dist-library/{runtime-UiQPz5ZV.js → compiler-UyPwGzJZ.js} +5631 -5389
  10. package/dist-library/react-fizgU3i8.js +12764 -0
  11. package/dist-library/reactive-md-authoring.js +1514 -0
  12. package/dist-library/reactive-md-editor.js +577 -571
  13. package/dist-library/reactive-md-print.css +284 -0
  14. package/dist-library/reactive-md-react-unstyled.js +1 -0
  15. package/dist-library/reactive-md-react.js +1 -13208
  16. package/dist-library/reactive-md.css +1 -1
  17. package/dist-library/reactive-md.js +244 -1062
  18. package/dist-library/runtime-DXtle_6c.js +498 -0
  19. package/dist-library/types/authoring/index.d.ts +24 -0
  20. package/dist-library/types/editor/command-types.d.ts +10 -0
  21. package/dist-library/types/editor/editor-commands.d.ts +2 -2
  22. package/dist-library/types/editor/editor-i18n.d.ts +1 -1
  23. package/dist-library/types/editor/native-components.d.ts +1 -1
  24. package/dist-library/types/editor/source-authoring.d.ts +5 -3
  25. package/dist-library/types/editor/types.d.ts +5 -10
  26. package/dist-library/types/local/LocalDocumentView.d.ts +4 -2
  27. package/dist-library/types/local/authoring.d.ts +9 -5
  28. package/dist-library/types/local/diagnostics.d.ts +40 -0
  29. package/dist-library/types/local/index.d.ts +1 -0
  30. package/dist-library/types/local/math-display.d.ts +72 -0
  31. package/dist-library/types/local/math-view.d.ts +2 -0
  32. package/dist-library/types/local/options.d.ts +3 -1
  33. package/dist-library/types/local/types.d.ts +10 -0
  34. package/dist-library/types/local/worker.d.ts +3 -2
  35. package/dist-library/types/react/index.d.ts +1 -1
  36. package/dist-standalone/reactive-md-standalone.js +54 -50
  37. package/docs/author-tools-ch.md +11 -5
  38. package/docs/author-tools-en.md +11 -5
  39. package/docs/editor-ch.md +237 -235
  40. package/docs/editor-en.md +237 -235
  41. package/docs/local-integration-ch.md +392 -390
  42. package/docs/local-integration-en.md +392 -390
  43. package/docs/release-0.5.3-ch.md +25 -0
  44. package/docs/release-0.5.3-en.md +25 -0
  45. package/package.json +12 -2
@@ -250,6 +250,10 @@ export declare const LOCAL_DIAGNOSTIC_MESSAGES: {
250
250
  readonly en: 'Compile option {name} must be a boolean.';
251
251
  readonly zh: '编译选项 {name} 必须是布尔值。';
252
252
  };
253
+ readonly 'options.markdownBreaks': {
254
+ readonly en: 'Compile option markdownBreaks must be a boolean.';
255
+ readonly zh: '编译选项 markdownBreaks 必须为布尔值。';
256
+ };
253
257
  readonly 'component.unknownSuggestion': {
254
258
  readonly en: 'Unknown component <{name}>. Did you mean <{suggestion}>?';
255
259
  readonly zh: '未知组件 <{name}>。是否想使用 <{suggestion}>?';
@@ -806,6 +810,34 @@ export declare const LOCAL_DIAGNOSTIC_MESSAGES: {
806
810
  readonly en: 'Plot parameter "{name}" must be a number, but is {kind}.';
807
811
  readonly zh: '绘图参数“{name}”必须是数字,但当前为 {kind}。';
808
812
  };
813
+ readonly 'math.displayUnsupportedCommand': {
814
+ readonly en: 'Formula command \\{name} is not supported; it is displayed as literal text.';
815
+ readonly zh: '公式命令 \\{name} 不受支持;已按原文显示。';
816
+ };
817
+ readonly 'math.displayUnsupportedEnvironment': {
818
+ readonly en: 'Formula environment {name} is not supported; it is displayed as literal text.';
819
+ readonly zh: '公式环境 {name} 不受支持;已按原文显示。';
820
+ };
821
+ readonly 'math.displayBudget': {
822
+ readonly en: 'Formula exceeds a display resource limit ({limit}); it is displayed as literal text.';
823
+ readonly zh: '公式超过显示资源上限({limit});已按原文显示。';
824
+ };
825
+ readonly 'math.displayStrayEnd': {
826
+ readonly en: 'Formula has an unmatched \\end; it is displayed as literal text.';
827
+ readonly zh: '公式中存在未匹配的 \\end;已按原文显示。';
828
+ };
829
+ readonly 'math.displayEnvironmentUnclosed': {
830
+ readonly en: 'Formula environment {name} is missing its closing brace; it is displayed as literal text.';
831
+ readonly zh: '公式环境 {name} 缺少结束花括号;已按原文显示。';
832
+ };
833
+ readonly 'math.displayEnvironmentMissingName': {
834
+ readonly en: 'Formula environment is missing its name; \\begin is displayed as literal text.';
835
+ readonly zh: '公式环境缺少名称;\\begin 已按原文显示。';
836
+ };
837
+ readonly 'math.displaySyntax': {
838
+ readonly en: 'Formula structure cannot be displayed and is shown as literal text.';
839
+ readonly zh: '公式结构无法显示,已按原文显示。';
840
+ };
809
841
  readonly 'table.missingHeader': {
810
842
  readonly en: 'The table for <{name}> is missing a header.';
811
843
  readonly zh: '<{name}> 的表格缺少表头。';
@@ -1299,6 +1331,7 @@ declare const LOCAL_DIAGNOSTIC_TEMPLATE_ALIASES: {
1299
1331
  readonly 'local.html.unsafe-url': 'html.unsafeUrl';
1300
1332
  readonly 'local.html.capability': 'html.capability';
1301
1333
  readonly 'local.options.invalid.html-flag': 'options.htmlFlag';
1334
+ readonly 'local.options.invalid.markdown-breaks': 'options.markdownBreaks';
1302
1335
  readonly 'local.component.unknown.suggestion': 'component.unknownSuggestion';
1303
1336
  readonly 'local.component.unknown': 'component.unknownPlain';
1304
1337
  readonly 'local.attribute.format': 'attribute.lowercase';
@@ -1444,6 +1477,13 @@ declare const LOCAL_DIAGNOSTIC_TEMPLATE_ALIASES: {
1444
1477
  readonly 'local.math.compute': 'math.computeFailed';
1445
1478
  readonly 'local.math.binding.unknown': 'math.bindingUnknown';
1446
1479
  readonly 'local.math.binding.type': 'math.bindingType';
1480
+ readonly 'local.math.display.unsupported-command': 'math.displayUnsupportedCommand';
1481
+ readonly 'local.math.display.unsupported-environment': 'math.displayUnsupportedEnvironment';
1482
+ readonly 'local.math.display.budget': 'math.displayBudget';
1483
+ readonly 'local.math.display.stray-end': 'math.displayStrayEnd';
1484
+ readonly 'local.math.display.environment-unclosed': 'math.displayEnvironmentUnclosed';
1485
+ readonly 'local.math.display.environment-missing-name': 'math.displayEnvironmentMissingName';
1486
+ readonly 'local.math.display.syntax': 'math.displaySyntax';
1447
1487
  readonly 'local.table.header.missing': 'table.missingHeader';
1448
1488
  readonly 'local.table.header.interpolation': 'table.headerInterpolation';
1449
1489
  readonly 'local.table.header.empty': 'table.headerEmpty';
@@ -1,6 +1,7 @@
1
1
  export { analyzeLocalSource, completeLocalSource, renameLocalBinding, formatLocalSource } from './authoring.js';
2
2
  export type { AuthorToken, AuthorBinding, AuthorAnalysis, AuthorCompletion, AuthorCompletionKind, AuthorRename } from './authoring.js';
3
3
  export { compileLocal } from './compiler.js';
4
+ export { localCompileOptionsKey } from './options.js';
4
5
  export { formatLocalDiagnostic, LOCAL_DIAGNOSTIC_CODES, isLocalDiagnosticCode, localDiagnosticTemplate, localDiagnosticTemplateKeys, } from './diagnostics.js';
5
6
  export type { LocalDiagnosticDetails } from './diagnostics.js';
6
7
  export { countLocalCodePoints } from './text-length.js';
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Pure-TypeScript MathML parser for local LaTeX display.
3
+ *
4
+ * This module owns the single parsing implementation used by the React view
5
+ * (`math-view.tsx`) and by display diagnostics. It must stay React-free so the
6
+ * compiler can inspect formulas without importing the renderer.
7
+ *
8
+ * Parsing never throws: unsupported constructs are represented as literal
9
+ * MathML text, and the same constructs are reported as source-ranged issues.
10
+ * That keeps "rendered as literal text" and "reported as a warning" in sync.
11
+ */
12
+ import type { LocalDiagnosticParams } from './types.js';
13
+ export type LocalMathDisplayIssueReason = 'unsupported-command' | 'unsupported-environment' | 'budget' | 'syntax';
14
+ /** One display-compatibility issue; offsets are relative to the formula body. */
15
+ export interface LocalMathDisplayIssue {
16
+ /** Inclusive UTF-16 offset into the formula body. */
17
+ start: number;
18
+ /** Exclusive UTF-16 offset into the formula body. */
19
+ end: number;
20
+ reason: LocalMathDisplayIssueReason;
21
+ /** English message for the issue (localize with `messageKey`/`params`). */
22
+ message: string;
23
+ /** Coarse machine code reported on `Diagnostic.code`. */
24
+ code: string;
25
+ /** Template key registered in `diagnostics.ts`. */
26
+ messageKey: string;
27
+ params?: LocalDiagnosticParams;
28
+ }
29
+ /** Lightweight MathML tree consumed by the React view. */
30
+ export interface MathNode {
31
+ tag: string;
32
+ attrs?: Readonly<Record<string, string>>;
33
+ text?: string;
34
+ children?: MathNode[];
35
+ }
36
+ export interface LocalMathDisplayParse {
37
+ /** `null` means the whole formula must be shown as bounded literal text. */
38
+ node: MathNode | null;
39
+ issues: LocalMathDisplayIssue[];
40
+ }
41
+ /** Diagnostic code emitted for every display-compatibility issue. */
42
+ export declare const MATH_DISPLAY_DIAGNOSTIC_CODE = "local.math.display";
43
+ export declare const MATH_DISPLAY_MESSAGE_KEYS: {
44
+ readonly 'unsupported-command': 'local.math.display.unsupported-command';
45
+ readonly 'unsupported-environment': 'local.math.display.unsupported-environment';
46
+ readonly budget: 'local.math.display.budget';
47
+ readonly 'stray-end': 'local.math.display.stray-end';
48
+ readonly 'environment-unclosed': 'local.math.display.environment-unclosed';
49
+ readonly 'environment-missing-name': 'local.math.display.environment-missing-name';
50
+ readonly syntax: 'local.math.display.syntax';
51
+ };
52
+ export declare const MAX_LOCAL_MATH_DISPLAY_SOURCE = 50000;
53
+ export declare const MAX_LOCAL_MATH_DISPLAY_TOKENS = 20000;
54
+ export declare const MAX_LOCAL_MATH_DISPLAY_DEPTH = 120;
55
+ export declare const MAX_LOCAL_MATH_DISPLAY_FALLBACK = 2000;
56
+ /** Bounded literal text used when the whole formula cannot be rendered. */
57
+ export declare function boundedLocalMathLiteral(source: string): string;
58
+ /**
59
+ * Parse the formula body once for both rendering and diagnostics.
60
+ *
61
+ * `node === null` means the renderer must fall back to bounded literal text;
62
+ * `issues` then contains exactly one budget or syntax issue.
63
+ */
64
+ export declare function parseLocalMathDisplay(source: string): LocalMathDisplayParse;
65
+ /**
66
+ * Report every construct that the display renderer degrades to literal text.
67
+ *
68
+ * Offsets are relative to the formula body (`LocalNode.value`). Compute-only
69
+ * limitations (for example `\int` in `<plot>`) are intentionally not reported:
70
+ * they do not affect display.
71
+ */
72
+ export declare function inspectLocalMathDisplay(source: string): LocalMathDisplayIssue[];
@@ -2,6 +2,8 @@ import { type ReactElement } from 'react';
2
2
  /**
3
3
  * Safe native MathML rendering for local LaTeX.
4
4
  *
5
+ * Parsing and support detection live in the React-free `math-display` module,
6
+ * so compile-time diagnostics use exactly the same rules as this renderer.
5
7
  * The renderer never interprets HTML, styles, macros, files or links from the
6
8
  * source. Unknown commands are shown as literal text, so a formula that cannot
7
9
  * be computed still remains readable. All source text passes through React as
@@ -10,6 +10,8 @@ export type LocalOptionCheck = {
10
10
  html: LocalHtmlPolicy;
11
11
  /** True when at least one capability flag is enabled. */
12
12
  htmlActive: boolean;
13
+ /** Render ordinary Markdown soft line breaks as `break` nodes. */
14
+ markdownBreaks: boolean;
13
15
  /** Validated host component schemas; empty when the option is absent. */
14
16
  hostComponents: readonly LocalHostComponentSchema[];
15
17
  /** Host tag name lookup; names are already lowercase kebab-case. */
@@ -31,4 +33,4 @@ export declare function readLocalCompileOptions(options: LocalCompileOptions | u
31
33
  * recompile on flag/limit changes and to keep worker races keyed by more than
32
34
  * the source text. Unknown keys are deliberately ignored.
33
35
  */
34
- export declare function localCompileOptionsKey(options: LocalCompileOptions | undefined): string;
36
+ export declare function localCompileOptionsKey(options?: LocalCompileOptions): string;
@@ -205,6 +205,16 @@ export interface LocalHostComponentSchema {
205
205
  }
206
206
  export interface LocalCompileOptions extends LocalHtmlOptions {
207
207
  readonly limits?: LocalCompileLimits;
208
+ /**
209
+ * Render ordinary Markdown soft line breaks as `<br>`.
210
+ *
211
+ * Defaults to `false`, which keeps the historical behavior where a soft
212
+ * break is ordinary collapsible whitespace. When `true`, each source soft
213
+ * break becomes a `break` node; explicit hard breaks, code, formulas and
214
+ * native HTML are left untouched. The source text is never rewritten, so
215
+ * every node keeps its original offsets.
216
+ */
217
+ readonly markdownBreaks?: boolean;
208
218
  /** Host-defined leaf components recognized alongside the built-in schema. */
209
219
  readonly hostComponents?: readonly LocalHostComponentSchema[];
210
220
  }
@@ -5,8 +5,9 @@ export interface LocalCompileRequest {
5
5
  id: number;
6
6
  source: string;
7
7
  /**
8
- * Capability flags, limits and host component schemas for this compile.
9
- * `hostComponents` selects the host leaf tags the parser may build.
8
+ * Capability flags, Markdown break handling, limits and host component
9
+ * schemas for this compile. `hostComponents` selects the host leaf tags the
10
+ * parser may build; `markdownBreaks` turns soft breaks into `break` nodes.
10
11
  */
11
12
  options?: LocalCompileOptions;
12
13
  }
@@ -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, LocalHostData, LocalHostRenderer } from '../local/render-types.js';
3
+ export type { LocalRenderMode, LocalRenderContext, 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';