reactive-md 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG-ch.md +113 -0
  2. package/CHANGELOG.md +113 -53
  3. package/CONTRIBUTING-ch.md +62 -0
  4. package/CONTRIBUTING.md +64 -65
  5. package/LICENSE +21 -21
  6. package/README-ch.md +123 -0
  7. package/README-en.md +147 -0
  8. package/README.md +96 -38
  9. package/SECURITY-ch.md +80 -0
  10. package/SECURITY.md +58 -49
  11. package/THIRD_PARTY_NOTICES.md +85 -1
  12. package/bin/reactive-md.mjs +40 -0
  13. package/cli/args.mjs +181 -0
  14. package/cli/assets.mjs +390 -0
  15. package/cli/build.mjs +268 -0
  16. package/cli/document.mjs +130 -0
  17. package/cli/errors.mjs +61 -0
  18. package/cli/fs-utils.mjs +133 -0
  19. package/cli/glob.mjs +203 -0
  20. package/cli/help.mjs +138 -0
  21. package/cli/lint.mjs +177 -0
  22. package/cli/main.mjs +55 -0
  23. package/cli/migrate.mjs +368 -0
  24. package/cli/package.mjs +209 -0
  25. package/dist-library/reactive-md-react.js +3525 -1651
  26. package/dist-library/reactive-md.css +1 -1
  27. package/dist-library/reactive-md.js +1798 -4
  28. package/dist-library/runtime-D3QTVYaz.js +15410 -0
  29. package/dist-library/types/index.d.ts +1 -0
  30. package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
  31. package/dist-library/types/local/authoring.d.ts +63 -0
  32. package/dist-library/types/local/collection-functions.d.ts +4 -0
  33. package/dist-library/types/local/colors.d.ts +2 -0
  34. package/dist-library/types/local/computations.d.ts +53 -0
  35. package/dist-library/types/local/data-functions.d.ts +22 -0
  36. package/dist-library/types/local/data-table.d.ts +65 -0
  37. package/dist-library/types/local/dates.d.ts +2 -0
  38. package/dist-library/types/local/dependencies.d.ts +31 -0
  39. package/dist-library/types/local/diagnostics.d.ts +1450 -0
  40. package/dist-library/types/local/expression.d.ts +13 -3
  41. package/dist-library/types/local/formatting.d.ts +41 -0
  42. package/dist-library/types/local/heading-anchors.d.ts +13 -2
  43. package/dist-library/types/local/i18n.d.ts +18 -0
  44. package/dist-library/types/local/index.d.ts +18 -1
  45. package/dist-library/types/local/limits.d.ts +32 -1
  46. package/dist-library/types/local/locale.d.ts +1 -0
  47. package/dist-library/types/local/math.d.ts +6 -1
  48. package/dist-library/types/local/parser.d.ts +10 -4
  49. package/dist-library/types/local/render-types.d.ts +5 -1
  50. package/dist-library/types/local/retention.d.ts +23 -0
  51. package/dist-library/types/local/schema.d.ts +25 -3
  52. package/dist-library/types/local/source-migration.d.ts +35 -0
  53. package/dist-library/types/local/state.d.ts +80 -0
  54. package/dist-library/types/local/text-length.d.ts +13 -0
  55. package/dist-library/types/local/theme.d.ts +30 -0
  56. package/dist-library/types/local/types.d.ts +112 -4
  57. package/dist-library/types/local/validation.d.ts +32 -0
  58. package/dist-library/types/local/version.d.ts +1 -1
  59. package/dist-library/types/local/worker.d.ts +82 -0
  60. package/dist-library/types/react/index.d.ts +4 -1
  61. package/dist-library/types/shareable.d.ts +64 -0
  62. package/dist-standalone/reactive-md-standalone.css +2 -0
  63. package/dist-standalone/reactive-md-standalone.js +57 -0
  64. package/docs/author-tools-ch.md +56 -0
  65. package/docs/author-tools-en.md +56 -0
  66. package/docs/compatibility-ch.md +103 -0
  67. package/docs/compatibility-en.md +103 -0
  68. package/docs/{component-development.md → component-development-ch.md} +210 -206
  69. package/docs/component-development-en.md +210 -0
  70. package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
  71. package/docs/component-protocol-en.md +710 -0
  72. package/docs/computations-formatting-ch.md +87 -0
  73. package/docs/computations-formatting-en.md +87 -0
  74. package/docs/constraints-collections-ch.md +84 -0
  75. package/docs/constraints-collections-en.md +84 -0
  76. package/docs/diagnostics-counting-ch.md +84 -0
  77. package/docs/diagnostics-counting-en.md +84 -0
  78. package/docs/local-components-v2-ch.md +138 -0
  79. package/docs/local-components-v2-en.md +104 -0
  80. package/docs/{local-guide.md → local-guide-ch.md} +28 -8
  81. package/docs/local-guide-en.md +961 -0
  82. package/docs/local-integration-ch.md +363 -0
  83. package/docs/local-integration-en.md +363 -0
  84. package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
  85. package/docs/local-interaction-syntax-en.md +483 -0
  86. package/docs/{performance.md → performance-ch.md} +12 -3
  87. package/docs/performance-en.md +76 -0
  88. package/docs/release-0.4.0-ch.md +89 -0
  89. package/docs/release-0.4.0-en.md +89 -0
  90. package/docs/release-0.4.1-ch.md +23 -0
  91. package/docs/release-0.4.1-en.md +23 -0
  92. package/docs/releasing-ch.md +101 -0
  93. package/docs/releasing-en.md +101 -0
  94. package/docs/shareable-export-ch.md +205 -0
  95. package/docs/shareable-export-en.md +207 -0
  96. package/docs/source-versioning-ch.md +159 -0
  97. package/docs/source-versioning-en.md +159 -0
  98. package/docs/theme-protocol-ch.md +107 -0
  99. package/docs/theme-protocol-en.md +107 -0
  100. package/examples/conformance/README.md +33 -31
  101. package/examples/conformance/component-protocol-1.json +482 -194
  102. package/examples/conformance/component-protocol-1.schema.json +76 -76
  103. package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
  104. package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
  105. package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
  106. package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
  107. package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
  108. package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
  109. package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
  110. package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
  111. package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
  112. package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
  113. package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
  114. package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
  115. package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
  116. package/examples/conformance/history/v0.3.1/provenance.json +72 -0
  117. package/examples/conformance/local-draft-2.json +212 -0
  118. package/examples/integration/README.md +45 -29
  119. package/examples/integration/core/index.mjs +32 -19
  120. package/examples/integration/core/package.json +7 -7
  121. package/examples/integration/react/index.html +12 -12
  122. package/examples/integration/react/main.jsx +21 -21
  123. package/examples/integration/react/package.json +9 -9
  124. package/examples/integration/worker/index.html +19 -0
  125. package/examples/integration/worker/main.js +61 -0
  126. package/examples/integration/worker/package.json +13 -0
  127. package/examples/integration/worker/worker.js +3 -0
  128. package/examples/local/README.md +64 -58
  129. package/examples/local/catalog.reactive.md +20 -20
  130. package/examples/local/charts.reactive.md +34 -34
  131. package/examples/local/checklist.reactive.md +32 -32
  132. package/examples/local/comparison.reactive.md +47 -47
  133. package/examples/local/components.reactive.md +44 -44
  134. package/examples/local/counter.reactive.md +7 -7
  135. package/examples/local/diagnostics.reactive.md +54 -54
  136. package/examples/local/diagram.reactive.md +44 -44
  137. package/examples/local/gallery.reactive.md +61 -61
  138. package/examples/local/parameters.reactive.md +36 -36
  139. package/examples/local/planning.reactive.md +24 -24
  140. package/examples/local/pricing.reactive.md +20 -20
  141. package/examples/local/recipes/invoice-zh.reactive.md +36 -0
  142. package/examples/local/recipes/invoice.reactive.md +36 -0
  143. package/examples/local/recipes/workshop-zh.reactive.md +33 -0
  144. package/examples/local/recipes/workshop.reactive.md +33 -0
  145. package/examples/local/showcase/README.md +25 -0
  146. package/examples/local/showcase/explore.reactive.md +102 -0
  147. package/examples/local/showcase/flow.reactive.md +86 -0
  148. package/examples/local/showcase/forms.reactive.md +126 -0
  149. package/examples/local/showcase/functions.reactive.md +119 -0
  150. package/examples/local/showcase/layout.reactive.md +100 -0
  151. package/examples/local/showcase/statistics.reactive.md +108 -0
  152. package/examples/local/showcase/tasks.reactive.md +89 -0
  153. package/examples/local/showcase/zh/explore.reactive.md +102 -0
  154. package/examples/local/showcase/zh/flow.reactive.md +86 -0
  155. package/examples/local/showcase/zh/forms.reactive.md +126 -0
  156. package/examples/local/showcase/zh/functions.reactive.md +119 -0
  157. package/examples/local/showcase/zh/layout.reactive.md +100 -0
  158. package/examples/local/showcase/zh/statistics.reactive.md +108 -0
  159. package/examples/local/showcase/zh/tasks.reactive.md +89 -0
  160. package/examples/local/zh/catalog.reactive.md +20 -0
  161. package/examples/local/zh/charts.reactive.md +73 -0
  162. package/examples/local/zh/checklist.reactive.md +32 -0
  163. package/examples/local/zh/comparison.reactive.md +47 -0
  164. package/examples/local/zh/components.reactive.md +44 -0
  165. package/examples/local/zh/counter.reactive.md +7 -0
  166. package/examples/local/zh/diagnostics.reactive.md +54 -0
  167. package/examples/local/zh/diagram.reactive.md +44 -0
  168. package/examples/local/zh/gallery.reactive.md +61 -0
  169. package/examples/local/zh/parameters.reactive.md +36 -0
  170. package/examples/local/zh/planning.reactive.md +24 -0
  171. package/examples/local/zh/pricing.reactive.md +20 -0
  172. package/package.json +91 -77
  173. package/README.en.md +0 -76
  174. package/dist-library/runtime-CPzMEMcW.js +0 -11111
  175. package/docs/compatibility.md +0 -68
  176. package/docs/local-integration.md +0 -218
  177. package/docs/releasing.md +0 -92
@@ -0,0 +1,483 @@
1
+ # Reactive MD local interaction syntax specification
2
+
3
+ Syntax identifier: `local-draft-2`, 2026-10-23. If this is your first time with the syntax, read the [beginner guide](local-guide-en.md) first; this document is the complete specification. Hosts select local interaction mode through `compileLocal` and `LocalReactiveDocument`, see [integration notes](local-integration-en.md). See [Versions and compatibility](compatibility-en.md) for package version relationships, 0.x compatibility rules and migration, [Source revisions and migration](source-versioning-en.md) for the optional revision directive and `reactive-md migrate`, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade from `0.3.1` / `local-draft-1`. Complete examples are in the [example index](../examples/local/README.md).
4
+
5
+ ## 1. Positioning and scope
6
+
7
+ `0.4.0` adds invisible `computed`/`const` declarations and number, string and date functions. See [Reusing calculations and formatting values](computations-formatting-en.md) for declaration syntax, dependency and error rules, function signatures and deterministic defaults.
8
+
9
+ For cross-field validation, conditional tones, arrays and bounded table-row generation, see [Constraints and collections](constraints-collections-en.md).
10
+
11
+ See [Diagnostics and counting rules](diagnostics-counting-en.md) for source positions, text lengths and resource units. String `len()` and text-control length constraints count Unicode code points.
12
+
13
+ Reactive MD is for local interactive documents: authors write Markdown and place input controls; when readers adjust parameters, related text, formulas, charts and diagrams update immediately.
14
+
15
+ The base language requires only two connection rules: `bind` names an input, and `{{ expression }}` reads it elsewhere. Components handle their own selection, expansion, search, sorting, timing and reset.
16
+
17
+ This draft does not include external service calls, form submission, asynchronous resources, named actions, event handlers, programmable collection edits, general loop templates or arbitrary scripts. Legacy `state/data/computed/actions` configuration blocks are not part of the new syntax. Expressions can produce string or numeric arrays; checklist and multi-select components produce string arrays. Tables can use prose Markdown or bounded local row generation through `data-table`.
18
+
19
+ By default a document only keeps in-memory state for the current instance. Reopening starts from initial values; persistence is not part of the author syntax. No language version declaration, component import or YAML is required. A document may optionally declare its revision with one `<!-- reactive-md: local-draft-2 -->` line in the prologue, before the theme and body; unversioned documents use the current revision. See [Source revisions and migration](source-versioning-en.md). Hosts should explicitly select draft parsing mode and must not guess by mixing old and new syntax.
20
+
21
+ Documents may select a theme with `<theme name="default">` before the body; omission uses `default`. This is static metadata, not a component. Custom themes must be registered by the host and support both color schemes; see the [theme protocol](theme-protocol-en.md).
22
+
23
+ ## 2. Your first document
24
+
25
+ ```markdown
26
+ # Cost estimate
27
+
28
+ <panel title="Adjust the plan">
29
+ <slider bind="people" label="People" initial="2" min="1" max="20">
30
+ <toggle bind="annual" label="Annual billing">
31
+ </panel>
32
+
33
+ Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.
34
+ ```
35
+
36
+ Slider declares the number `people` with initial value 2; toggle declares the boolean `annual`, off by default. The panel provides restore-defaults by default, restoring its internal parameters at once.
37
+
38
+ When no cross-component linkage is needed, omit `bind`, for example `<counter label="People" initial="2">`. The component remains interactive; it just has no public variable.
39
+
40
+ ## 3. Markdown and tags
41
+
42
+ ### 3.1 Document structure
43
+
44
+ Headings, paragraphs, emphasis, links, images, quotes, lists, plain tables, inline code and code fences continue to use Markdown. Component tags may sit in a paragraph or a standalone block, depending on component type. Container contents continue to parse as Markdown; authors do not need to add a `markdown` attribute.
45
+
46
+ Block component start and end tags each occupy a line. Attributes in a start tag may span multiple lines. A `>` inside a tag ends the tag only when it is outside quotes. Indentation is only for readability: container content is dedented by the common indentation and then parsed as Markdown; indentation inside code fences is preserved.
47
+
48
+ The inline components `badge`, `tooltip`, `jump` and `text` can be embedded in sentences. Other components are block components; `option`, `tab`, `disclosure`, `node`, `edge` and `step` are child components restricted to specific parent containers.
49
+
50
+ ### 3.2 Two tag shapes
51
+
52
+ | Type | Form | Rules |
53
+ | --- | --- | --- |
54
+ | Void component | `<slider bind="a" label="Amplitude">` | No end tag; a trailing `/>` is also accepted |
55
+ | Container with content | `<card title="Notes">` and `</card>` | Must be explicitly closed; nesting is allowed |
56
+
57
+ Void components are fixed to `input`, `textarea`, `number`, `slider`, `range-slider`, `coordinate`, `toggle`, `checkbox`, `date`, `counter`, `timer`, `progress`, `anchor` and `edge`. The declaration tags `computed`, `const` and `validation`, and the structural `column`, also have no body. Every other component listed in this draft uses paired tags. `textarea` text is set through `initial`, so it is a void component.
58
+
59
+ For example:
60
+
61
+ ```markdown
62
+ <card title="Plan notes">
63
+ Price updates with **People**.
64
+
65
+ <slider bind="people" label="People" initial="2" min="1" max="20">
66
+
67
+ Total cost: {{ people * 100 }} USD.
68
+ </card>
69
+ ```
70
+
71
+ Tag names and attribute names use lowercase kebab-case; an end tag must match the most recently unclosed container. Automatic closing and correction of mismatched tags are not allowed. Legacy directives such as `:::card` are not interpreted as new components.
72
+
73
+ ### 3.3 Attributes
74
+
75
+ Regular attribute values are enclosed in single or double quotes; boolean attributes may omit their value. Attribute order has no semantics, and duplicate attributes are errors.
76
+
77
+ | Form | Meaning |
78
+ | --- | --- |
79
+ | `label="People"` | String |
80
+ | `max="20"` | Parsed as a number according to the component attribute definition |
81
+ | `required` | Boolean true |
82
+ | `required="false"` | Boolean false |
83
+ | `disabled="{{ people >= 20 }}"` | Dynamic boolean |
84
+ | `label="Current people: {{ people }}"` | Text interpolation |
85
+ | `bind="people"` | Static variable name |
86
+
87
+ Omitted boolean attributes use the component default rather than always assuming false; for example `panel.reset` defaults to true.
88
+
89
+ `&quot;`, `&apos;`, `&amp;`, `&lt;` and `&gt;` in attribute values decode to the corresponding characters; backslashes are not used to escape attribute quotes. Dynamic values for numeric and boolean attributes must be one complete interpolation and keep the original type; text attributes may contain multiple interpolations.
90
+
91
+ `bind`, `initial`, `name`, `id`, `value` (option identifier), `to`, `from`, `answer`, `kind`, field mappings and layout enums are static attributes. Input `min/max/step` are static constraints too; plot `min/max` may be dynamic to support adjusting the observed range. The `rows` attribute of `textarea` is a static row count, while `data-table.rows` is a required expression; do not confuse the two.
92
+
93
+ Unknown components, unknown attributes, wrong positions or wrong attribute types all produce source diagnostics. Registered tags are not executed as arbitrary HTML; authors cannot use `script`, `style`, `onclick` or other script entry points.
94
+
95
+ ### 3.4 Code, math and escaping
96
+
97
+ Tags, interpolations and formula markers inside inline code and code fences are displayed verbatim. The source revision directive in the prologue is the recognized version comment; other Markdown comments `<!-- ... -->` produce no components or variables.
98
+
99
+ Use `\{{` in prose to display a literal `{{`, and `\<slider>` or inline code to show a tag example. These backslash escapes belong only to the Markdown context and do not apply to LaTeX sources.
100
+
101
+ The parser identifies code, math regions and tag boundaries first, then interprets interpolations; syntax cannot be implemented by string replacement over the whole document. Markdown inside tags, nested containers, multi-line attributes and original line/column positions must be preserved.
102
+
103
+ ## 4. Parameters, bindings and initial values
104
+
105
+ ### 4.1 Naming and types
106
+
107
+ `bind` uses `[A-Za-z_][A-Za-z0-9_]*` and is case-sensitive. Variable types are determined by the component, not guessed from text content. `x`, `y`, `pi`, `e`, `true`, `false`, `null` and expression built-in function names are reserved.
108
+
109
+ | Component | Public value | Default initial value |
110
+ | --- | --- | --- |
111
+ | input, textarea | String | Empty string |
112
+ | date | Date string or empty string | Empty string |
113
+ | number | Number | The valid step value within range closest to 0 |
114
+ | slider | Number | min, with a default range of 0 to 100 |
115
+ | counter | Number | The valid step value within range closest to 0 |
116
+ | toggle, checkbox | Boolean | false |
117
+ | select, choices, radio-group | Option string | value of the first option |
118
+ | multi-select | String array of selected option values | Empty array |
119
+ | range-slider | Two numbers, `start` / `end` slots | start=min; end=the largest valid step not exceeding max |
120
+ | coordinate | Two numbers, `x` / `y` slots | The valid step value on each axis closest to 0 |
121
+ | table, chart with `key` | Stable row key string | Empty string (unselected) |
122
+ | tabs | Page string | value of the first tab |
123
+ | steps | Step string | value of the first step |
124
+ | diagram | Node ID string | id of the first node |
125
+ | checklist | String array of selected item IDs | Determined by the task list check marks |
126
+ | timer | Remaining seconds | duration, default 60 |
127
+
128
+ Scalar components use `initial` to override the default. `range-slider` and `coordinate` use `initial-start`/`initial-end` and `initial-x`/`initial-y` for their slots; `multi-select` accepts a comma-separated `initial` list of static option values. `timer` uses `duration` and `checklist` uses the check marks in its body; neither accepts `initial`. A `table` or `chart` selection accepts `initial` only together with `key`. Dates use real, valid `YYYY-MM-DD`; an empty string means not yet selected.
129
+
130
+ `bind` may be omitted. Unnamed components have independent internal state and do not derive a variable name from the tag. A control's `label` is required and may use dynamic text; it is also the control's accessible name.
131
+
132
+ ### 4.2 Same-name controls and declaration order
133
+
134
+ The compiler collects bindings across the whole document before rendering, including bindings in conditional regions. Prose can reference parameters that appear later. Declarations and initial values do not change with condition truth, mount count or scroll position.
135
+
136
+ Number, text or boolean inputs of the same kind may bind the same variable and stay in sync; types must match, and numeric ranges and steps must be identical. When `select/choices/radio-group` share a variable, the value set and order must also be identical. Label text may differ.
137
+
138
+ A variable may have at most one explicit `initial`. Without an explicit initial value, the default of the first control in the source is used, and all associated constraints are validated. Later controls omitting `initial` share the existing initial value. The public state of `timer/checklist/tabs/diagram/multi-select/steps` is owned by exactly one component and does not accept a second same-name owner or writes from other controls. Each numeric slot of `range-slider` and `coordinate` is exclusive too. A `table` and a `chart` may share a selection binding only when their ordered `key` sets are identical.
139
+
140
+ Referencing an undeclared variable is an immediate error and does not silently create an empty value. Component initial values are document initialization data; showing a hidden control again does not initialize it again.
141
+
142
+ ### 4.3 Updates, input drafts and reset
143
+
144
+ Valid input commits immediately and updates everything that depends on it. Composition input with a Chinese IME commits when composition ends; intermediate states such as an empty string or a minus sign in a number field remain only as an editing draft. If the value is still invalid on blur, an error is shown while other content keeps reading the last valid value.
145
+
146
+ Numeric constraints use finite numbers, `step > 0`, `min <= max`. Steps are based on min, or on 0 when min is absent, with an implementation-defined floating-point tolerance. An explicit initial outside the range or off the step is an error, not silently corrected. Default initial values are generated from constraints; when two valid values are equidistant from 0, the smaller one is used, and an error occurs when no step value is available.
147
+
148
+ Disabled controls do not accept reader input. A panel reset commits all parameters and component internal state inside it at once, triggers one consistent view update, and clears editing drafts. Displays of shared variables outside the panel change accordingly.
149
+
150
+ When a conditional region is hidden, existing state, tab selection and checklist checks are preserved. Timers in hidden regions pause and stay paused when shown again until the reader starts them. Disposing a document releases timers, subscriptions and component state.
151
+
152
+ ## 5. Text interpolation and expressions
153
+
154
+ ```markdown
155
+ People: {{ people }}.
156
+ Total: {{ people * 100 }} USD.
157
+ Billing: {{ annual ? 'annual' : 'monthly' }}.
158
+ ```
159
+
160
+ Interpolation can appear in paragraphs, headings, emphasis, lists, plain table cells and attributes that allow dynamic values. Strings, finite numbers and booleans display directly; null displays as empty; arrays must first be converted with functions such as `len` and are not implicitly output as JSON. Output is treated as text.
161
+
162
+ ### 5.1 Expression set
163
+
164
+ | Category | Supported |
165
+ | --- | --- |
166
+ | Literals | Numbers, single- or double-quoted strings, true, false, null |
167
+ | Parameters | bind names declared in the document |
168
+ | Arithmetic | `+ - * / %`, unary plus/minus, parentheses |
169
+ | Comparison | `== != < <= > >=` |
170
+ | Logic | `!`, `&&`, `\|\|` |
171
+ | Conditional | `condition ? trueValue : falseValue` |
172
+ | Math functions | abs, sqrt, floor, ceil, round, min, max, pow, sin, cos, tan, asin, acos, atan, exp, log |
173
+ | Common functions | len, contains, clamp |
174
+ | Formatting | formatNumber, formatPercent, formatScientific, formatCurrency |
175
+ | Strings | trim, lower, upper, startsWith, endsWith, replace, slice |
176
+ | Dates | dateCompare, dateDiff |
177
+ | Array aggregates | sum, average, minOf, maxOf |
178
+ | Constants | pi, e |
179
+
180
+ Precedence runs from function calls/parentheses, unary operators, multiplication/division/remainder, addition/subtraction, relational comparison, equality comparison, logical AND, logical OR, to conditional expressions; conditional expressions are right-associative and other binary operators are left-associative. Logic and conditional expressions short-circuit.
181
+
182
+ `+` accepts two numbers or two strings. Comparisons do not implicitly convert between strings and numbers; relational comparison accepts only two numbers or two strings; logical operations and if conditions must be booleans. Expression string escapes use `\\`, `\'`, `\"`, `\n`, `\t`.
183
+
184
+ min/max accept one or more numbers; pow takes a base and an exponent; clamp takes a value, lower bound and upper bound. Other math functions take one number, trigonometric functions use radians, and log is the natural logarithm. round rounds half values toward positive infinity. len computes the number of Unicode code points in a string or the length of an array; contains checks a substring or array membership.
185
+
186
+ Multiplication in prose expressions must be written `*`; use `pow` for exponents. LaTeX math regions follow their own mathematical writing rules. Expressions have no assignment, method calls, property access, custom functions or imports, and do not provide legacy runtime contexts such as `event` or `resources`.
187
+
188
+ Pipes in GFM tables must be written `\|`, for example logical OR as `\|\|`. Table parsing handles Markdown pipe escapes first, then sends cell expressions to the evaluator.
189
+
190
+ ### 5.2 Calculation errors
191
+
192
+ Division by zero, domain errors, non-finite results and type errors are shown near the corresponding content. When the parameter itself is valid, the user's new input is kept, and other independent content keeps updating; the error result shows "Unable to compute" instead of reusing an old number as a new result.
193
+
194
+ This build adds named read-only values through top-level `computed` and `const` declarations. Short calculations can still be written in place; use declarations for intermediate results shared by prose, conditions, formulas and charts. See [Reusing calculations and formatting values](computations-formatting-en.md) for dependency, error and caching rules.
195
+
196
+ ## 6. Inputs and parameter panels
197
+
198
+ All input components support `label`, optional `bind`, optional scalar `initial` and dynamic `disabled`. Additional attributes are listed below; unlisted attributes are not part of this draft.
199
+
200
+ | Component | Additional attributes and defaults |
201
+ | --- | --- |
202
+ | input | type=text/email; placeholder; required=false; min-length=0; optional max-length |
203
+ | textarea | placeholder; rows=4; required=false; min-length=0; optional max-length |
204
+ | number | optional min/max; step=1 |
205
+ | slider | min=0; max=100; step=1 |
206
+ | range-slider | bind-start/bind-end and initial-start/initial-end; min=0; max=100; step=1; optional color |
207
+ | coordinate | bind-x/bind-y and initial-x/initial-y; x-min/y-min=-5; x-max/y-max=5; step=1; optional color |
208
+ | counter | min=0; optional max; step=1 |
209
+ | toggle, checkbox | Optional color |
210
+ | date | optional min/max dates; required=false |
211
+ | select, choices, radio-group, multi-select | Body is one or more options; multi-select adds max-selected and uses a string-array value |
212
+
213
+ `range-slider` and `coordinate` expose independent number slots. Omit a slot's `bind-start`/`bind-end` or `bind-x`/`bind-y` to keep that slot internal; provide at most one explicit initial per slot. Crossing endpoints is rejected, not silently swapped. `multi-select` requires `label`, accepts `max-selected`, and normalizes writes to source order. These components also accept an optional `color`. See [local-draft-2 components and migration](local-components-v2-en.md) for the complete rules.
214
+
215
+ Selector example:
216
+
217
+ ```markdown
218
+ <choices bind="plan" label="Usage" initial="personal">
219
+ <option value="personal">Personal</option>
220
+ <option value="team">Team</option>
221
+ </choices>
222
+ ```
223
+
224
+ option.value is a non-empty, static, unique string; the body is the option's inline text, may contain emphasis, and must not contain another interactive component. select is a dropdown, choices is option cards, and radio-group is a radio button group; binding rules are the same.
225
+
226
+ `required`, length and email format show hints after the first blur and update with input afterwards. Controls allow an empty initial document value; hints do not produce submissions or network operations. New text with an invalid format remains a draft and does not replace the last valid public value. An empty initial value is public as an empty string until the reader fills it in.
227
+
228
+ `counter` has built-in decrement, increment and restore-initial buttons, and disables the corresponding action at range boundaries. `timer` supports label, optional bind and duration (positive integer seconds, default 60); it has built-in start, pause and reset, stops at zero, updates according to actual elapsed time, and does not accumulate timing error after switching to the background.
229
+
230
+ `panel` is a container supporting an optional title and reset (default true). It lays out vertically by default and provides restore-defaults. `reset="false"` hides the reset action. Nested panels are allowed: an inner reset affects only the inner panel, while an outer reset covers the whole subtree; child controls not yet shown in a condition are also in scope. Panel reset also restores table queries, sorting, paging, tab selection and diagram selection in the subtree.
231
+
232
+ ## 7. Layout and content exploration
233
+
234
+ | Container | Attributes | Body and default behavior |
235
+ | --- | --- | --- |
236
+ | card | optional title | Regular Markdown; a content card |
237
+ | grid | columns=2 (integer 1–4, maximum column count) | Direct children are card; fewer columns in narrow containers, including nested grids and embedded documents |
238
+ | tabs | optional label, bind, initial | One or more tab, first selected by default |
239
+ | tab | label required, optional value | Regular Markdown |
240
+ | accordion | optional label | One or more disclosure |
241
+ | disclosure | label required; open=false | Click to expand; multiple entries can be open at once |
242
+ | if | when required, complete boolean interpolation | Shows Markdown and components when true |
243
+ | alert | optional title; tone=info/success/warning, default info | Regular Markdown |
244
+ | badge | tone=neutral/success/warning, default neutral | Inline text |
245
+ | tooltip | text required | Focusable inline explanatory text |
246
+
247
+ When tab has no value, `tab-1`, `tab-2` and so on are generated in source order; values in the same group must be unique. Without bind, tabs do not name page state; with bind, the current value is exposed publicly. Switching tabs preserves child content state and pauses hidden timers. The initial `open` state inside accordion is restored on reset.
248
+
249
+ When if's when is false, content is not displayed, but internal parameters are still initialized according to section 4. Unknown variables or type errors in hidden branches are still compile errors.
250
+
251
+ ### 7.1 Navigation, color and guided reading
252
+
253
+ | Container or inline tag | Attributes | Body and default behavior |
254
+ | --- | --- | --- |
255
+ | jump | to required; appearance=link/button, default link; optional color | Inline Markdown; scrolls to a heading slug or explicit anchor |
256
+ | anchor | id required and unique | No body; marks an explicit jump target |
257
+ | text | color required | Inline Markdown and interpolation; sets foreground color |
258
+ | section | color required | Block Markdown; sets inherited foreground color without a border or background |
259
+ | quiz | type=choice/number, default choice; label and answer required; optional explanation and tolerance | Choice quizzes contain options; numeric quizzes have an empty body. No public bind |
260
+ | steps | optional label, bind and initial; exclusive string binding | One or more step children; first step selected by default |
261
+ | step | label required; optional value | Markdown body; omitted values become step-1, step-2 and so on |
262
+
263
+ `jump.to` and `anchor.id` match heading slugs or explicit IDs. Duplicate anchors, heading collisions and missing targets are compile errors. `quiz` answers are supplied in source for self-study; drafts and feedback stay inside the component and panel reset clears them. `steps` keeps inactive step content initialized and preserves its state; hidden timers pause. See [local-draft-2 components and migration](local-components-v2-en.md) for color validation and slot details.
264
+
265
+ Base layout uses Markdown; images use `![description](path)`, links use `[text](address)`, and horizontal rules use `---`. Images load only after the host explicitly allows them through a URL policy; by default no image requests are made. See [Image and link policy](local-integration-en.md#image-and-link-policy) for integration. This draft does not provide author tags for row, stack, spacer, icon, image or link-button, and does not expose class/style.
266
+
267
+ ## 8. Checklists
268
+
269
+ ```markdown
270
+ <checklist bind="done" label="Try it out">
271
+ - [x] Read the source document
272
+ - [ ] Adjust parameters and observe the result
273
+ - [ ] Try it at phone width
274
+ </checklist>
275
+
276
+ Completed {{ len(done) }} / 3 items.
277
+ <progress label="Completion" value="{{ len(done) / 3 * 100 }}">
278
+ ```
279
+
280
+ The checklist body is a non-empty, single-level Markdown task list, checked by the reader by default. Plain Markdown task lists remain static content. Items may contain inline Markdown but must not contain nested task lists or interactive components.
281
+
282
+ Fixed entries generate internal IDs `item-1`, `item-2` and so on in order; the public value is an array of checked IDs in source order, and `[]` when nothing is selected. Entries are not added, removed or reordered during a document instance; they are regenerated after editing the source and creating a new instance. Reset restores the initial state specified by `[x]` / `[ ]`. Supports label, optional bind and dynamic disabled.
283
+
284
+ progress is a void component; label/value are required, max defaults to 100, and value may be dynamic; max must be a positive finite number, value must be between 0 and max, and out-of-range values show a diagnostic instead of being silently clamped.
285
+
286
+ ## 9. Tables and statistical charts
287
+
288
+ ### 9.1 Shared data rules
289
+
290
+ The bodies of table, chart and timeline are each one Markdown table. Headers are non-empty and unique, and every row has the same number of columns; cells may contain interpolation. The first column is usually a label, and other columns read types according to the component.
291
+
292
+ Plain text cells display Markdown; plain decimal or scientific-notation text cells can be read as numbers, and a single complete interpolation keeps its result type. Mixed text such as `{{ price }} USD` is a display string and cannot be used as a numeric chart column. Legend labels take the plain text of headers.
293
+
294
+ There is no need to declare a YAML array first, and remote URLs, data attributes or API return values are not accepted. Errors such as empty rows, non-numeric values or missing columns are located at the corresponding cell.
295
+
296
+ ### 9.2 Enhanced tables
297
+
298
+ ```markdown
299
+ <table label="Component catalog" page-size="3">
300
+ | Name | Category | Price |
301
+ | --- | --- | ---: |
302
+ | Document | Basic | 20 |
303
+ | Form | Input | 45 |
304
+ | Chart | Visual | 80 |
305
+ </table>
306
+ ```
307
+
308
+ table supports optional label, searchable=true, sortable=true and page-size=10 (positive integer). It provides a search box, sortable headers and paging by default; paging controls are hidden when there is only one page. With `key` naming a static, nonempty, unique identifier column, `bind` and `initial` can expose the selected row as a stable string; without `key`, selection stays inside the renderer.
309
+
310
+ Search is a case-insensitive substring match over the displayed text of all columns, trimming whitespace from the query; sorting uses the full column type, numerically for numeric columns and by Unicode code point order for text otherwise, preserving the original order of equal rows. Clicking a header cycles ascending, descending and source order. Search or sort changes return to the first page, and reactive data changes clamp the current page to the valid range. No matches shows "No matching results". These interactions affect only the table.
311
+
312
+ ### 9.3 Charts
313
+
314
+ ```markdown
315
+ <chart kind="bar" title="Cost and budget">
316
+ | Item | Actual | Budget |
317
+ | --- | ---: | ---: |
318
+ | Content | 120 | 150 |
319
+ | Visual | 230 | 200 |
320
+ </chart>
321
+ ```
322
+
323
+ chart.kind defaults to bar and supports bar, line, area, scatter and donut. Supports optional title, x, y, x-label and y-label. x/y are static header names; y may be a comma-separated list of column names, so column names cannot contain commas.
324
+
325
+ | Type | Default column rules |
326
+ | --- | --- |
327
+ | bar, line, area | First column is the horizontal axis; other columns are numeric series |
328
+ | scatter | First column is the numeric horizontal axis and the rest are numeric vertical axes; x/y may also specify them |
329
+ | donut | First column is the label and second is the value; with more than two columns, y must specify the single numeric column |
330
+
331
+ line/area determine the horizontal axis as numeric or categorical from the full column type and connect in source order. donut values must be non-negative, and a zero total shows "No share to display". Series names become legends automatically; pointer and keyboard readouts are provided by default without event logic.
332
+
333
+ Numeric columns update with parameters. Calculation errors display in the corresponding chart and are not replaced with 0. With `key`, a chart can expose selection through `bind`, using the same stable row-key rules as `table`; a table and chart may share that binding only when their ordered keys match.
334
+
335
+ ### 9.4 Timelines
336
+
337
+ timeline supports optional title and unit (display text, default "minutes"), and its body is a table with either `Task`, `Start` and `Duration` columns or `事项`, `开始` and `时长` columns, plus optional `Notes` or `说明`. These column names are fixed headers; start and duration are non-negative numbers. Sorting is stable by start time, overlapping intervals are allowed, and notes are viewed with a pointer or keyboard. Table content may use interpolation.
338
+
339
+ ## 10. LaTeX math and function plots
340
+
341
+ ### 10.1 Display and plotting
342
+
343
+ Prose `$...$` is inline math and `$$...$$` is a display formula. Inline math pairs on the same line, its content cannot start or end with whitespace; use `\$` to display a literal dollar sign. Display formulas may span lines and can also be written as `$$ y = x^2 $$`. Unclosed math delimiters are errors. Standalone formulas are for layout and create no state or functions. Each `$$...$$` block inside a plot container defines one curve; the math content keeps normal LaTeX syntax and does not need `{{ }}`.
344
+
345
+ ```markdown
346
+ <slider bind="a" label="Amplitude" initial="1" min="0" max="5">
347
+
348
+ <plot min="-10" max="10">
349
+ $$ y = a \sin x + \frac{x^2}{10} $$
350
+ </plot>
351
+ ```
352
+
353
+ The plot body may contain only whitespace and one or more display formula blocks. Each block writes `y = expression` and computes only explicit real functions y(x). Use multiple formula blocks for multiple curves; do not use plain line breaks as separators.
354
+
355
+ plot supports min=-10, max=10 (dynamic allowed, requiring min < max), samples=200 (static integer 2–2000), optional label, x-label="x" and y-label="y". Each plot has at most 16 curves; the sum of curves multiplied by their sample counts across the whole document is at most 20,000, including hidden regions. Curves share a computation budget, and exceeding it stops computation and reports an error. The vertical axis is determined automatically from finite sample values in the current range; if there are no valid values, an empty state is shown. Constant curves should add visible vertical-axis headroom.
356
+
357
+ ### 10.2 Computable LaTeX
358
+
359
+ The following math forms must be supported by plotting computation in this draft. Formula layout and computation capability are validated separately; being able to lay out a formula does not mean it can be evaluated.
360
+
361
+ | Math content | Syntax |
362
+ | --- | --- |
363
+ | Numbers, four operations | `2`, `0.5`, `+`, `-`, `/`, `\cdot`, `\times` |
364
+ | Implicit multiplication | `2x`, `ax`, `a\sin x`, `(x+1)(x-1)` |
365
+ | Exponents | `x^2`, `x^{a+1}`, `e^x` |
366
+ | Fractions | `\frac{a}{b}`, `\dfrac{a}{b}`, `\tfrac{a}{b}` |
367
+ | Roots | `\sqrt{x}`, `\sqrt[3]{x}` |
368
+ | Grouping | `(...)`, `{...}`, `\left(...\right)` |
369
+ | Trigonometric functions | `\sin`, `\cos`, `\tan`, `\arcsin`, `\arccos`, `\arctan` |
370
+ | Exponential and logarithm | `\exp(x)`, `\ln x`, `\log x`, `\log_{2}x` |
371
+ | Absolute value | `\lvert x\rvert`, `\left\lvert x\right\rvert` |
372
+ | Other functions | `\min(a,b)`, `\max(a,b)` |
373
+ | Constants | `\pi`, `e` |
374
+ | Piecewise functions | `\begin{cases} ... \end{cases}` |
375
+ | Piecewise conditions | `=`, `\ne`/`\neq`, `<`, `>`, `\le`/`\leq`, `\ge`/`\geq` |
376
+
377
+ Trigonometric functions use radians; ln is the natural logarithm, log without a base is base 10 by convention, and with a subscript it uses the written base. Roots compute real numbers; odd integer roots allow negative numbers, while negative inputs to even roots are invalid samples. Absolute value accepts both paired vertical bars and `\left|...\right|`; bars must be paired, and missing boundaries are not guessed.
378
+
379
+ Multiplication must use `*` in expression contexts and may be omitted in LaTeX. LaTeX multiplication and division (including implicit multiplication) share precedence and associate left to right; exponents bind before unary minus, so `-x^2` is `-(x^2)`. `1/2x` is interpreted as `(1/2)x`; use fractions to make the denominator explicit.
380
+
381
+ A function without parentheses reads the product of the following term and ends at addition/subtraction, comparison, comma or the next function command; for example `\sin 2x` is sin(2x), `\sin x + a` is sin(x)+a, and `\sin x\cos x` is sin(x)cos(x). Use parentheses for complex arguments. `\sin^2 x` is supported and means `(sin x)^2`; inverse trigonometric functions use explicit names such as arcsin, and `\sin^{-1}` is not guessed to mean the inverse function.
382
+
383
+ `\left`, `\right`, the math spacing commands `\,`, `\;`, `\!`, `\quad` and `%` comments to end of line do not change computation. In piecewise functions, `&` separates values from conditions and `\\` separates branches; the first branch whose condition is true is used. `\text{otherwise}` may serve as the final default branch; if no branch matches, the point is undefined. Conditions support only a single comparison; express complex piecewise behavior with multiple branches.
384
+
385
+ Implicit equations, parametric curves, matrices, sums, integrals, derivatives and custom macros are not in the first version's computable set. When these structures are encountered, keep displaying the formula and point out the command or structure that cannot be computed; do not guess a plot from another formula. The math renderer must disable file, network, HTML and macro execution entry points.
386
+
387
+ ### 10.3 Parameter name mapping
388
+
389
+ A single Latin letter maps to a same-name bind, for example `a` maps to `bind="a"`. Adjacent plain letters mean multiplication: `abx` is a×b×x.
390
+
391
+ Multi-letter names are written as `\mathrm{amplitude}` and read as `bind="amplitude"` as a whole. This is a Reactive MD naming convention; the command must contain a complete valid bind name, with no spaces or interpolation.
392
+
393
+ `\alpha`, `\beta`, `\gamma`, `\theta`, `\omega`, `\lambda`, `\mu` and `\sigma` map to same-name English binds. Other Greek parameters use `\mathrm{name}` for explicit references in the first version; `\pi` is fixed as the circle constant.
394
+
395
+ `x` is the plot variable and `y` is the output marker; neither can be bound to a control. Parameters must be numbers; undeclared parameters and wrong types are diagnosed before plotting.
396
+
397
+ ### 10.4 Breaks, readouts and updates
398
+
399
+ Curves are recomputed when parameters change. Division by zero, non-real results and overflow points form breaks, and the two sides of a break are not connected directly. The plotting implementation must also subdivide suspected discontinuous intervals to avoid incorrect connections when asymptotes cross finite sample points.
400
+
401
+ A legend and pointer/keyboard readouts are provided by default. The curve legend uses the respective math formulas; move the pointer to the end of a curve to read that point's value.
402
+
403
+ ## 11. Interactive diagrams
404
+
405
+ ```markdown
406
+ <diagram bind="selected" initial="input" label="Reactive state flow" direction="right">
407
+ <node id="input" label="Input">
408
+ The reader changes parameters through controls.
409
+ </node>
410
+ <node id="compute" label="Compute">
411
+ Recompute formulas and results.
412
+ </node>
413
+ <node id="view" label="Display">
414
+ Update prose and charts.
415
+ </node>
416
+ <edge from="input" to="compute" label="State change">
417
+ <edge from="compute" to="view" label="Update result">
418
+ </diagram>
419
+ ```
420
+
421
+ diagram supports optional label, bind and initial, with direction=right/down (default right). The body contains only node, edge and whitespace. At least one node is required; node requires id and label, and its body is static Markdown notes that may contain text interpolation but not interactive controls.
422
+
423
+ node.id is a `[A-Za-z_][A-Za-z0-9_-]*` unique within the current diagram. edge requires from/to and supports an optional label; both ends must exist. Fully duplicate from/to/label combinations are errors, while parallel edges with different labels are allowed. Cycles and self-loops are allowed.
424
+
425
+ Nodes are laid out automatically from relationships, with source order determining order within a layer; cycles are grouped as a whole before layout. The first version requires no coordinates and provides no author coordinate overrides.
426
+
427
+ Nodes are clickable and keyboard-selectable by default, and the selected notes appear in the diagram's detail area. With bind, the selected node id is public; without bind, selection stays inside the component. initial must point to an existing node and defaults to the first. The labels of diagram and edge, as well as node.label, support text interpolation. node also supports dynamic tone=neutral/success/warning, default neutral.
428
+
429
+ ## 12. Component reference and syntax scope
430
+
431
+ | Purpose | Draft components |
432
+ | --- | --- |
433
+ | Parameter input | input, textarea, number, slider, range-slider, coordinate, toggle, checkbox, date, select, choices, radio-group, multi-select, option |
434
+ | Built-in actions | counter, timer, checklist, progress |
435
+ | Content organization | panel, card, grid, tabs, tab, accordion, disclosure, if |
436
+ | Navigation and prose | jump, anchor, text, section |
437
+ | Assessment and reading | quiz, steps, step |
438
+ | Hints | alert, badge, tooltip |
439
+ | Declarations and generated data | computed, const, validation, data-table, column |
440
+ | Visualization | table, chart, plot, timeline, diagram, node, edge |
441
+
442
+ 48 tag names in total. `option`, `tab`, `disclosure`, `node`, `edge`, `step` and `column` are structural children of parent components. `computed`, `const` and `validation` are document declarations; they are parsed as tags but are not rendered controls. The leading `<theme>` declaration is metadata and is not counted here. Most articles only need Markdown and two or three input/display components. Plain amounts can be written directly as `{{ total }} USD`; currency formatting and statistic cards are not entry-level requirements.
443
+
444
+ This draft does not accept legacy tags such as form, submit, button, each, list, spinner, stat or value, nor set/reset action attributes or on-* event attributes. The panel reset is a fixed boolean option, not a programmable action.
445
+
446
+ ## 13. Diagnostics and acceptance rules
447
+
448
+ Diagnostics include severity, category, a short explanation, source line/column and a fix suggestion. A structurally complete unknown tag region is displayed from escaped original source with a `local.component.unknown` warning; footnote references and definitions keep their source with a `local.footnote.unsupported` warning. Controls and interpolations inside these regions are not executed, while other prose and interactions keep working. Tag structures that cannot be reliably recovered, attribute or expression errors on known components, binding errors and resource budget problems still block compilation. Runtime local computation errors are isolated as described in section 5.
449
+
450
+ | Category | Example | What it should explain |
451
+ | --- | --- | --- |
452
+ | Tag structure | card unclosed, wrong nesting | The required end tag and start position |
453
+ | Unknown tag warning | slidr | Unknown name, spelling suggestion and local source fallback |
454
+ | Footnote warning | `[^note]` and footnote definition | Source preserved; footnote layout not yet supported |
455
+ | Invalid syntax | on-click, actions configuration block | Attribute or legacy syntax not in the current mode |
456
+ | Binding | references seats but only seat is declared | The missing parameter and candidate names |
457
+ | Initial value | initial written twice for a same-name parameter | Both conflict positions |
458
+ | Type | using a string as an if condition | Actual type and expected boolean type |
459
+ | Constraint | slider initial value exceeds max | Valid range and current value |
460
+ | Table | numeric column contains "20 USD" | Column name, row number and that a number is required |
461
+ | Diagram | edge points to a nonexistent node | The missing node ID |
462
+ | Declaration | computed inside a container or a duplicate name | Top-level placement, the conflicting name or control |
463
+ | Data table | data-table without a column, or a duplicated key | Required column and unique stable key |
464
+ | Validation | fields names a read-only declaration | Writable public binding names |
465
+ | Math | integral or missing parameter in a plot | The math fragment and supported scope |
466
+
467
+ Implementation acceptance must cover:
468
+
469
+ 1. Every regular new example compiles according to this specification; the diagnostics example reports the expected errors it lists.
470
+ 2. Headings, tables, lists and code inside Markdown containers parse normally; tags and interpolations inside code and comments are inactive.
471
+ 3. Components without bind work independently; bindings across components stay in sync, and an explicit initial value is applied only once.
472
+ 4. Forward references, conditional hiding, tab switching and panel reset follow the same state rules.
473
+ 5. Parameter panels, checklists, local catalog search and timing operations require no scripts, configuration blocks or service calls.
474
+ 6. Chart values preserve types, and empty data, error values and zero proportions have explicit displays.
475
+ 7. Regular LaTeX fractions, implicit multiplication, functions, parameters and piecewise functions are computable; unsupported structures are diagnosed clearly; discontinuities are not connected incorrectly.
476
+ 8. Diagram auto-layout, detail display and bound selection work; missing edge endpoints are errors.
477
+ 9. Chinese IME input, keyboard operation, accessible names and 375px narrow screens work.
478
+ 10. Document instances are independent, disposal cleans up, and no unintended network actions occur; complex or excessive math input can be halted by the execution budget.
479
+
480
+ These rules cover compiler, runtime and browser acceptance. See the [example index](../examples/local/README.md) for example mappings and expected observations, and the [language conformance data](../examples/conformance/README.md) for the machine-readable minimum acceptance set. Actual repository check records stay in the repository and are not part of the package.
481
+
482
+
483
+ 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.4.0` is the preview release on the `next` channel.
@@ -11,7 +11,7 @@ npm run benchmark
11
11
 
12
12
  ## 本地基线
13
13
 
14
- 2026-10-22,Reactive MD 0.3.0,Node 22.17.0,Windows x64,Intel Core Ultra 5 125H。测量时机器上也有其他开发进程运行。
14
+ 2026-10-22,Reactive MD 0.3.0,Node 22.17.0,Windows x64,Intel Core Ultra 5 125H。测量时机器上也有其他开发进程运行。该基线早于 0.4.0 发布;作为发布对比前应重新运行基准。
15
15
 
16
16
  | 场景 | 中位数 | P95 |
17
17
  | --- | ---: | ---: |
@@ -27,9 +27,18 @@ npm run benchmark
27
27
 
28
28
  ## 宿主中的大文档
29
29
 
30
- 文档源码上限为 1,000,000 个 UTF-16 代码单元,绘图和表达式还有独立计算预算,详见[安全策略](../SECURITY.md)。资源上限控制工作量,编译 API 仍是同步调用。编辑器可以合并连续输入触发的编译;处理来源不可信或较大的文档时,可以在宿主 Worker 或独立进程中编译,并由宿主控制并发和超时。
30
+ 文档源码上限为 1,000,000 个 UTF-16 代码单元,绘图和表达式还有独立计算预算,详见[安全策略](../SECURITY-ch.md)。资源上限控制工作量,编译 API 仍是同步调用。编辑器可以合并连续输入触发的编译;处理来源不可信或较大的文档时,可以在宿主 Worker 或独立进程中编译,并由宿主控制并发和超时。
31
31
 
32
- 语法节点预算默认 10,000,宿主可用 `compileLocal(source, { limits: { maxSyntaxNodes: 50_000 } })` 按次调整,见[核心 API](local-integration.md#核心-api)。提高预算后应同时测量编译、内存和最终预览渲染成本。
32
+ 语法节点预算默认 10,000,宿主可用 `compileLocal(source, { limits: { maxSyntaxNodes: 50_000 } })` 按次调整,见[核心 API](local-integration-ch.md#核心-api)。提高预算后应同时测量编译、内存和最终预览渲染成本。
33
+
34
+ ## 渲染优化契约
35
+
36
+ 参考渲染器使用编译器产出的依赖信息,跳过不可能读取已变化参数的子树。这是内部渲染优化,不是作者可见功能,也不是新的公开 API。
37
+
38
+ - 公开契约是语义等价:状态值、渲染文字、诊断、可访问属性、静态 SSR 输出和交互行为与不做条件渲染时一致,只有重新计算的范围变化。
39
+ - `document.dependencies` 是冻结、可序列化的内部映射。无法静态判断读取范围的子树标记为 `null`,对这些子树保守渲染。宿主和其他渲染器不得依赖其结构,可以完全忽略。
40
+ - 源码变化、实例销毁、面板重置,以及可能改变隐藏状态的可见性变化,仍会更新受影响的子树。优化不会抑制诊断或校验提示。
41
+ - `npm run verify:memo` 在相同文档和状态修订上比较优化渲染与无条件基线;`npm run verify:release` 包含该检查。只有两者产生等价的可观察输出,渲染优化才可接受。
33
42
 
34
43
  ## Playground 实时编辑
35
44
 
@@ -0,0 +1,76 @@
1
+ # Performance measurements
2
+
3
+ Build the language package in the source repository root, then run:
4
+
5
+ ```sh
6
+ npm run build
7
+ npm run benchmark
8
+ ```
9
+
10
+ The script warms up 3 times and measures 20 times per scenario, reporting the median and P95; raw results are written to `artifacts/benchmark.json`. Use `npm run benchmark -- --iterations 50 --output artifacts/benchmark-50.json` to change the iteration count and output location. The report includes the package version, Node version, operating system and CPU information.
11
+
12
+ ## Local baseline
13
+
14
+ 2026-10-22, Reactive MD 0.3.0, Node 22.17.0, Windows x64, Intel Core Ultra 5 125H. Other development processes were running on the machine during measurement. This baseline predates the 0.4.0 release; re-run the benchmark before using it as a release comparison.
15
+
16
+ | Scenario | Median | P95 |
17
+ | --- | ---: | ---: |
18
+ | Compile the cost example, 378 characters | 2.51 ms | 5.83 ms |
19
+ | Compile a 250-row responsive table, 7,161 characters | 17.04 ms | 28.05 ms |
20
+ | Compile a 100-section article, 15,550 characters | 45.34 ms | 59.81 ms |
21
+ | 100 consecutive state writes and expression evaluations | 0.20 ms | 0.34 ms |
22
+ | Three curves, 200 sample points each | 0.55 ms | 1.61 ms |
23
+
24
+ Timing includes correctness assertions; one measurement of a runtime scenario includes 100 updates. The plotting scenario includes breakpoint checks for regular functions and non-grid asymptotes.
25
+
26
+ These numbers measure compilation, evaluation and sampling in Node; they do not include browser layout, painting or input-to-frame latency. Use them to compare versions under the same conditions; they set no cross-machine pass thresholds and do not imply that every document within the source limit takes the same time. CI saves measurement reports for Node 24; the [first CI run](https://github.com/yao1145/ReactiveMD/actions/runs/39782886373) passed and produced a report.
27
+
28
+ ## Large documents in the host
29
+
30
+ Document source is limited to 1,000,000 UTF-16 code units, and plotting and expressions have separate computation budgets; see the [security policy](../SECURITY.md) for details. Resource limits bound the work, but the compile API remains synchronous. Editors can coalesce compilations triggered by consecutive input; when handling untrusted or large documents, compile in a host Worker or a separate process, with the host controlling concurrency and timeouts.
31
+
32
+ The syntax node budget defaults to 10,000, and hosts can adjust it per call with `compileLocal(source, { limits: { maxSyntaxNodes: 50_000 } })`, see the [Core API](local-integration-en.md#core-api). After raising the budget, measure compilation, memory and final preview rendering costs together.
33
+
34
+ ## Rendering optimization contract
35
+
36
+ The reference renderer uses dependency information produced by the compiler to skip subtrees that cannot read a changed parameter. This is an internal rendering optimization, not an author-visible feature or a new public API.
37
+
38
+ - The public contract is semantic: state values, rendered text, diagnostics, accessibility attributes, static SSR output and interactive behavior remain the same as an unconditioned render. Only the amount of recomputation changes.
39
+ - `document.dependencies` is a frozen, serializable internal map. It marks subtrees whose reads cannot be decided statically as `null`; those subtrees are rendered conservatively. Hosts and alternative renderers must not depend on its shape, and may ignore it.
40
+ - Source changes, instance disposal, panel reset and visibility changes that can alter hidden state still update the affected subtrees. The optimization never suppresses a diagnostic or a validation hint.
41
+ - `npm run verify:memo` compares the optimized renderer with the unconditioned baseline on the same documents and state revisions. `npm run verify:release` includes that check. A rendering optimization is acceptable only when both produce equivalent observable output.
42
+
43
+ ## Playground live editing
44
+
45
+ The Playground calls the public `compileLocal` in a separate module Worker and coalesces edits within 150 ms. The scheduler keeps at most one task being compiled and one latest source waiting to compile; stale results never replace the current preview or diagnostics. The editor and export always use the latest source; while waiting for compilation, the preview shows "Compiling" and keeps the previous preview. The preview component reuses the same document, avoiding a full preview rebuild on every keystroke.
46
+
47
+ Source persistence is deferred, and pending writes are flushed when switching examples or leaving the page. If the Worker is unavailable or fails, the page shows a fallback notice and compiles on the main thread after coalescing edits; that mode still has the cost of blocking on large documents. In normal Worker mode, React rendering, layout and painting after receiving compile results still run on the main thread.
48
+
49
+ The synchronous compile API and `LocalReactiveDocument` keep their existing behavior. Other hosts can refer to `demo/src/local-compile-worker.ts` and the scheduler to move compilation into a Worker they control.
50
+
51
+ ### Re-measurement
52
+
53
+ After building the language package in the repository root, run:
54
+
55
+ ```sh
56
+ node scripts/benchmark-large-documents.mjs
57
+ ```
58
+
59
+ The script warms up 3 times, measures 20 times, checks compilation results for 10-, 100-, 300- and 600-section articles and saves the median and P95. With the Playground running, run the following browser checks from the repository root; the default server is `http://127.0.0.1:5184`, which `DEMO_URL` can override.
60
+
61
+ ```sh
62
+ node demo/scripts/verify-editing.mjs
63
+ node demo/scripts/benchmark-editing.mjs
64
+ ```
65
+
66
+ The editing benchmark types 10 consecutive characters at the end of a 300-section article of about 47,000 characters, with a 20 ms interval between keystrokes, and records the latency from the input event to the next `requestAnimationFrame` callback plus main-thread long tasks. This metric observes input responsiveness and is not the time until painting completes; long-task statistics include the final preview render. `EDITING_SECTIONS` adjusts the number of sections and `EDITING_REPORT` sets the report path. All reports are written to the ignored `artifacts/` directory.
67
+
68
+ On 2026-10-22, a before/after comparison was run on the same 46,969-character article on the Windows machine above with local Edge. Both sides used the Vite development server and a 1440 × 1000 viewport; the original version was `94fd72e`, and the optimized version includes the Worker scheduling and preview reuse described in this section.
69
+
70
+ | Metric | Original | Optimized |
71
+ | --- | ---: | ---: |
72
+ | Median latency from input to next frame callback | 147.3 ms | 9.5 ms |
73
+ | Maximum latency from input to next frame callback | 157.9 ms | 36.9 ms |
74
+ | Total time to type 10 consecutive characters | 2,302 ms | 538 ms |
75
+
76
+ The raw reports are `artifacts/benchmark-editing-before.json` and `artifacts/benchmark-editing-after.json`. This is a single local observation; machine load affects the numbers. The optimization mainly reduces main-thread work triggered by keystrokes; the algorithm and single-compile speed of synchronous `compileLocal` itself are unchanged.