reactive-md 0.9.2 → 0.9.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.
- package/CHANGELOG-ch.md +363 -333
- package/CHANGELOG.md +364 -334
- package/CONTRIBUTING-ch.md +22 -22
- package/CONTRIBUTING.md +22 -22
- package/README-ch.md +431 -431
- package/README-en.md +431 -431
- package/README.md +429 -429
- package/SECURITY-ch.md +83 -83
- package/SECURITY.md +83 -83
- package/bin/reactive-md.mjs +39 -39
- package/cli/args.mjs +263 -263
- package/cli/assets.mjs +395 -395
- package/cli/build.mjs +445 -445
- package/cli/check.mjs +444 -444
- package/cli/document.mjs +130 -130
- package/cli/errors.mjs +61 -61
- package/cli/fs-utils.mjs +133 -133
- package/cli/glob.mjs +203 -203
- package/cli/help.mjs +323 -323
- package/cli/init.mjs +1577 -1577
- package/cli/lint.mjs +177 -177
- package/cli/main.mjs +65 -65
- package/cli/migrate.mjs +368 -368
- package/cli/package-loader.mjs +41 -41
- package/cli/package.mjs +211 -211
- package/dist-library/LocalDocumentView-D6zQkTkt.js +112 -0
- package/dist-library/{LocalDocumentViewCore-DXE0I0Qc.js → LocalDocumentViewCore-CmJhemcA.js} +356 -9441
- package/dist-library/LocalReactiveDocumentCore-lAKOGAZ7.js +283 -0
- package/dist-library/LocalStaticDocumentView-2J7w0sKm.js +143 -0
- package/dist-library/{authoring-Ci_KzJ0q.js → authoring-B14SsOXZ.js} +21 -20
- package/dist-library/chart-B1TUtzm-.js +3 -0
- package/dist-library/color-values-r8Wf7ALn.js +6 -0
- package/dist-library/{compile-Dx6Uw3D9.js → compile-D50B5_Ww.js} +25 -25
- package/dist-library/compile-cache-key-6GgpETz_.js +28 -0
- package/dist-library/compiler-DLkKUK4t.js +98 -0
- package/dist-library/{compiler-core-DDDdvuLy.js → compiler-core-Niqhp9wV.js} +2877 -3262
- package/dist-library/{registry-core-C9xOunaw.js → component-kernel-IG4wOO0i.js} +72 -195
- package/dist-library/{component-state-BRwvTV0d.js → component-state-Ht-hOK0W.js} +1 -1
- package/dist-library/component-utils-eSj5IdG4.js +338 -0
- package/dist-library/computations-CffoW7Ff.js +340 -0
- package/dist-library/config-validation-Cpol91_M.js +456 -0
- package/dist-library/controls-B-CLSK8Q.js +5927 -0
- package/dist-library/controls-DWlx-AQl.js +3 -0
- package/dist-library/{coordinate-B1VFK9fd.js → coordinate-PyLPMIQK.js} +85 -85
- package/dist-library/data-BtFlkJzp.js +3 -0
- package/dist-library/{data-table-8-3F15Jf.js → data-table-Kv_ZA2Z2.js} +14 -13
- package/dist-library/data-visuals-_Z7QqYTk.js +384 -0
- package/dist-library/{default-components-s21NevON.js → default-components-jugH7Ubr.js} +327 -326
- package/dist-library/{config-DXLvctiZ.js → default-config-DIrRpuQz.js} +103 -88
- package/dist-library/default-options-DU5dxuU6.js +125 -0
- package/dist-library/{registry-D6OGkOcX.js → default-registry-BlloaZi7.js} +4 -4
- package/dist-library/default-schema-Ch-Vznpm.js +33 -0
- package/dist-library/diagram-BLepzI8l.js +3 -0
- package/dist-library/{display-B_uutKkN.js → display-y4v9v0Qd.js} +1 -1
- package/dist-library/dist-Cueh1Psp.js +4761 -0
- package/dist-library/{document-theme-C8J6UyNO.js → document-theme-DBAfnk7y.js} +57 -2
- package/dist-library/{export-CIAIPBov.js → export-heVBqgxA.js} +64 -63
- package/dist-library/gallery-BC6FYTqw.js +3 -0
- package/dist-library/{gallery-Dv1rOvL0.js → gallery-Q6VPS2ep.js} +1 -1
- package/dist-library/{html-Cr4CBwAH.js → html-CCnvzan1.js} +49 -48
- package/dist-library/{incremental-9nx92u9c.js → incremental-Bzvh8_lB.js} +526 -379
- package/dist-library/{layout-BBB2VF0S.js → layout-BfUzzO2b.js} +147 -156
- package/dist-library/layout-BnfDeUNy.js +3 -0
- package/dist-library/limits-CFERRrlC.js +10 -0
- package/dist-library/localization-COdJ6lw2.js +6 -0
- package/dist-library/mafs-CnzDC5CR.js +3 -0
- package/dist-library/math-view-B0jthpRw.js +20 -0
- package/dist-library/motion-tokens-Czk0RDmS.js +283 -0
- package/dist-library/mount-preset-C_i37FvY.js +24 -0
- package/dist-library/numeric-sliders-CkWS0-ja.js +542 -0
- package/dist-library/{observability-4KqXhIEU.js → observability-CYLuvFfL.js} +124 -43
- package/dist-library/package-core-9UK5ZdqB.js +127 -0
- package/dist-library/parser-9yNJxGip.js +8 -0
- package/dist-library/parser-standard-BPIy4HOu.js +4872 -0
- package/dist-library/plugin-packs-CZb46nuv.js +19 -0
- package/dist-library/{preset-core-DeZPA8IE.js → preset-core-BW3NWZJ9.js} +212 -210
- package/dist-library/props-pJRrfDc6.js +179 -0
- package/dist-library/react-BSo0o998.js +32 -0
- package/dist-library/reactive-md-authoring.js +268 -257
- package/dist-library/reactive-md-build.js +7 -10
- package/dist-library/reactive-md-compiler-session.js +4 -0
- package/dist-library/reactive-md-compiler-standard.js +6 -6
- package/dist-library/reactive-md-compiler.js +3 -3
- package/dist-library/reactive-md-contracts.js +6 -0
- package/dist-library/reactive-md-default-packs.js +31 -15
- package/dist-library/reactive-md-default-preset.js +7 -7
- package/dist-library/reactive-md-export.js +6 -5
- package/dist-library/reactive-md-minimal-preset.js +2 -2
- package/dist-library/reactive-md-minimal-react-preset.js +22 -20
- package/dist-library/reactive-md-minimal.css +1 -1
- package/dist-library/reactive-md-observability.js +125 -3
- package/dist-library/reactive-md-pack-style-manifest.js +797 -0
- package/dist-library/reactive-md-plugin-chart.js +6 -5
- package/dist-library/reactive-md-plugin-data.js +8 -8
- package/dist-library/reactive-md-plugin-diagram.js +7 -6
- package/dist-library/reactive-md-plugin-forms.js +14 -13
- package/dist-library/reactive-md-plugin-gallery.js +6 -5
- package/dist-library/reactive-md-plugin-navigation.js +9 -9
- package/dist-library/reactive-md-plugin-network.js +13 -13
- package/dist-library/reactive-md-plugin-plot.js +7 -6
- package/dist-library/reactive-md-print.css +304 -304
- package/dist-library/reactive-md-react-component-accordion.js +10 -0
- package/dist-library/reactive-md-react-component-alert.js +10 -0
- package/dist-library/reactive-md-react-component-anchor.js +10 -0
- package/dist-library/reactive-md-react-component-badge.js +10 -0
- package/dist-library/reactive-md-react-component-card.js +10 -0
- package/dist-library/reactive-md-react-component-chart.js +22 -0
- package/dist-library/reactive-md-react-component-checkbox.js +10 -0
- package/dist-library/reactive-md-react-component-checklist.js +10 -0
- package/dist-library/reactive-md-react-component-choices.js +10 -0
- package/dist-library/reactive-md-react-component-column.js +6 -0
- package/dist-library/reactive-md-react-component-coordinate.js +21 -0
- package/dist-library/reactive-md-react-component-counter.js +10 -0
- package/dist-library/reactive-md-react-component-data-table.js +14 -0
- package/dist-library/reactive-md-react-component-date.js +10 -0
- package/dist-library/reactive-md-react-component-diagram.js +22 -0
- package/dist-library/reactive-md-react-component-disclosure.js +10 -0
- package/dist-library/reactive-md-react-component-edge.js +22 -0
- package/dist-library/reactive-md-react-component-gallery-item.js +10 -0
- package/dist-library/reactive-md-react-component-gallery.js +10 -0
- package/dist-library/reactive-md-react-component-grid.js +10 -0
- package/dist-library/reactive-md-react-component-if.js +10 -0
- package/dist-library/reactive-md-react-component-input.js +10 -0
- package/dist-library/reactive-md-react-component-jump.js +10 -0
- package/dist-library/reactive-md-react-component-multi-select.js +10 -0
- package/dist-library/reactive-md-react-component-node.js +22 -0
- package/dist-library/reactive-md-react-component-number.js +10 -0
- package/dist-library/reactive-md-react-component-option.js +10 -0
- package/dist-library/reactive-md-react-component-panel.js +10 -0
- package/dist-library/reactive-md-react-component-plot.js +26 -0
- package/dist-library/reactive-md-react-component-progress.js +10 -0
- package/dist-library/reactive-md-react-component-quiz.js +10 -0
- package/dist-library/reactive-md-react-component-radio-group.js +10 -0
- package/dist-library/reactive-md-react-component-range-slider.js +10 -0
- package/dist-library/reactive-md-react-component-section.js +10 -0
- package/dist-library/reactive-md-react-component-select.js +10 -0
- package/dist-library/reactive-md-react-component-slider.js +10 -0
- package/dist-library/reactive-md-react-component-step.js +10 -0
- package/dist-library/reactive-md-react-component-steps.js +10 -0
- package/dist-library/reactive-md-react-component-tab.js +10 -0
- package/dist-library/reactive-md-react-component-table.js +14 -0
- package/dist-library/reactive-md-react-component-tabs.js +10 -0
- package/dist-library/reactive-md-react-component-text.js +10 -0
- package/dist-library/reactive-md-react-component-textarea.js +10 -0
- package/dist-library/reactive-md-react-component-timeline.js +14 -0
- package/dist-library/reactive-md-react-component-timer.js +10 -0
- package/dist-library/reactive-md-react-component-toggle.js +10 -0
- package/dist-library/reactive-md-react-component-tooltip.js +10 -0
- package/dist-library/reactive-md-react-component-validation.js +10 -0
- package/dist-library/reactive-md-react-minimal.js +4 -4
- package/dist-library/reactive-md-react-pack-controls.js +44 -0
- package/dist-library/reactive-md-react-pack-data.js +21 -0
- package/dist-library/reactive-md-react-pack-layout.js +36 -0
- package/dist-library/reactive-md-react-pack-visuals.js +43 -0
- package/dist-library/reactive-md-react-packed.js +50 -0
- package/dist-library/reactive-md-react-server.js +26 -25
- package/dist-library/reactive-md-react-static-server.js +24 -0
- package/dist-library/reactive-md-react-static.js +1 -0
- package/dist-library/reactive-md-react-unstyled.js +15 -12
- package/dist-library/reactive-md-react.js +15 -12
- package/dist-library/reactive-md-scan.js +1 -0
- package/dist-library/reactive-md-sdk.js +9 -9
- package/dist-library/reactive-md-standalone-configured.js +2 -2
- package/dist-library/reactive-md-standalone-host.js +2 -2
- package/dist-library/reactive-md-testing-browser.js +2 -2
- package/dist-library/reactive-md-testing-react.js +32 -32
- package/dist-library/reactive-md-testing.js +12 -12
- package/dist-library/reactive-md-worker-pool.js +401 -0
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +82 -1548
- package/dist-library/registry-core-CziAIP5P.js +125 -0
- package/dist-library/render-nodes-DKjg_TR1.js +9369 -0
- package/dist-library/requirements-DhIkxAbl.js +157 -0
- package/dist-library/resources-B_nbROgj.js +74 -0
- package/dist-library/rmd-pack-controls.css +1032 -0
- package/dist-library/rmd-pack-data.css +724 -0
- package/dist-library/rmd-pack-layout.css +1825 -0
- package/dist-library/rmd-pack-resource-chart.css +300 -0
- package/dist-library/rmd-pack-resource-controls.css +781 -0
- package/dist-library/rmd-pack-resource-data-visuals.css +501 -0
- package/dist-library/rmd-pack-resource-diagram.css +106 -0
- package/dist-library/rmd-pack-resource-gallery.css +346 -0
- package/dist-library/rmd-pack-resource-graphics.css +516 -0
- package/dist-library/rmd-pack-resource-layout.css +1480 -0
- package/dist-library/rmd-pack-resource-mafs-core.css +124 -0
- package/dist-library/rmd-pack-resource-mafs.css +129 -0
- package/dist-library/rmd-pack-resource-visual-base.css +224 -0
- package/dist-library/rmd-pack-visuals.css +1394 -0
- package/dist-library/{runtime-BpQdZmFI.js → runtime-CuJndKqK.js} +53 -52
- package/dist-library/runtime-requirement-C4-vNcf5.js +769 -0
- package/dist-library/schema-core-4sd1Vu7V.js +132 -0
- package/dist-library/{sdk-core-ChslheKs.js → sdk-core-BLsW9cCy.js} +497 -524
- package/dist-library/{session-core-dxQCJBNa.js → session-core-DLBRPV7f.js} +26 -25
- package/dist-library/{shareable-B8xMoGEa.js → shareable-C6mUerpQ.js} +145 -142
- package/dist-library/shared-bTzN-F4g.js +3 -0
- package/dist-library/structural-views-30-YD_TJ.js +11 -0
- package/dist-library/table-surface-CfZn_tk-.js +13 -0
- package/dist-library/types/assemblies/compile-cache-key.d.ts +11 -0
- package/dist-library/types/assemblies/default-config.d.ts +35 -0
- package/dist-library/types/{local/configuration/options.d.ts → assemblies/default-options.d.ts} +4 -4
- package/dist-library/types/assemblies/default-registry.d.ts +18 -0
- package/dist-library/types/{local/configuration/schema.d.ts → assemblies/default-schema.d.ts} +4 -4
- package/dist-library/types/authoring/catalog.d.ts +11 -1
- package/dist-library/types/authoring/extensions.d.ts +1 -1
- package/dist-library/types/authoring/index.d.ts +3 -3
- package/dist-library/types/authoring/templates.d.ts +1 -1
- package/dist-library/types/compiler/index.d.ts +1 -0
- package/dist-library/types/compiler/session.d.ts +19 -0
- package/dist-library/types/compiler/standard.d.ts +1 -0
- package/dist-library/types/components/entries/accordion.d.ts +3 -0
- package/dist-library/types/components/entries/alert.d.ts +3 -0
- package/dist-library/types/components/entries/anchor.d.ts +3 -0
- package/dist-library/types/components/entries/badge.d.ts +3 -0
- package/dist-library/types/components/entries/card.d.ts +3 -0
- package/dist-library/types/components/entries/chart.d.ts +3 -0
- package/dist-library/types/components/entries/checkbox.d.ts +3 -0
- package/dist-library/types/components/entries/checklist.d.ts +3 -0
- package/dist-library/types/components/entries/choices.d.ts +3 -0
- package/dist-library/types/components/entries/column.d.ts +3 -0
- package/dist-library/types/components/entries/coordinate.d.ts +3 -0
- package/dist-library/types/components/entries/counter.d.ts +3 -0
- package/dist-library/types/components/entries/data-table.d.ts +3 -0
- package/dist-library/types/components/entries/date.d.ts +3 -0
- package/dist-library/types/components/entries/diagram.d.ts +3 -0
- package/dist-library/types/components/entries/disclosure.d.ts +3 -0
- package/dist-library/types/components/entries/edge.d.ts +3 -0
- package/dist-library/types/components/entries/gallery-item.d.ts +3 -0
- package/dist-library/types/components/entries/gallery.d.ts +3 -0
- package/dist-library/types/components/entries/grid.d.ts +3 -0
- package/dist-library/types/components/entries/if.d.ts +3 -0
- package/dist-library/types/components/entries/input.d.ts +3 -0
- package/dist-library/types/components/entries/jump.d.ts +3 -0
- package/dist-library/types/components/entries/multi-select.d.ts +3 -0
- package/dist-library/types/components/entries/node.d.ts +3 -0
- package/dist-library/types/components/entries/number.d.ts +3 -0
- package/dist-library/types/components/entries/option.d.ts +3 -0
- package/dist-library/types/components/entries/panel.d.ts +3 -0
- package/dist-library/types/components/entries/plot.d.ts +3 -0
- package/dist-library/types/components/entries/progress.d.ts +3 -0
- package/dist-library/types/components/entries/quiz.d.ts +3 -0
- package/dist-library/types/components/entries/radio-group.d.ts +3 -0
- package/dist-library/types/components/entries/range-slider.d.ts +3 -0
- package/dist-library/types/components/entries/section.d.ts +3 -0
- package/dist-library/types/components/entries/select.d.ts +3 -0
- package/dist-library/types/components/entries/slider.d.ts +3 -0
- package/dist-library/types/components/entries/step.d.ts +3 -0
- package/dist-library/types/components/entries/steps.d.ts +3 -0
- package/dist-library/types/components/entries/tab.d.ts +3 -0
- package/dist-library/types/components/entries/table.d.ts +3 -0
- package/dist-library/types/components/entries/tabs.d.ts +3 -0
- package/dist-library/types/components/entries/text.d.ts +3 -0
- package/dist-library/types/components/entries/textarea.d.ts +3 -0
- package/dist-library/types/components/entries/timeline.d.ts +3 -0
- package/dist-library/types/components/entries/timer.d.ts +3 -0
- package/dist-library/types/components/entries/toggle.d.ts +3 -0
- package/dist-library/types/components/entries/tooltip.d.ts +3 -0
- package/dist-library/types/components/entries/validation.d.ts +3 -0
- package/dist-library/types/components/layout/layout.d.ts +1 -3
- package/dist-library/types/components/layout/structural-views.d.ts +3 -0
- package/dist-library/types/components/mount-preset.d.ts +2 -0
- package/dist-library/types/components/packs/controls.d.ts +2 -0
- package/dist-library/types/components/packs/data.d.ts +2 -0
- package/dist-library/types/components/packs/layout.d.ts +2 -0
- package/dist-library/types/components/packs/visuals.d.ts +2 -0
- package/dist-library/types/components/shared/data-visuals.d.ts +3 -0
- package/dist-library/types/components/shared/table-surface.d.ts +10 -0
- package/dist-library/types/components/shared/visual-helpers.d.ts +24 -0
- package/dist-library/types/components/shared/visuals.d.ts +0 -2
- package/dist-library/types/components/table/data-table-model.d.ts +48 -0
- package/dist-library/types/components/table/data-table.d.ts +1 -48
- package/dist-library/types/{local/configuration → contracts}/component-kernel.d.ts +4 -2
- package/dist-library/types/contracts/index.d.ts +8 -0
- package/dist-library/types/{local/configuration → contracts}/limits.d.ts +9 -1
- package/dist-library/types/contracts/localization.d.ts +6 -0
- package/dist-library/types/contracts/runtime-types.d.ts +19 -0
- package/dist-library/types/local/compilation/cache-version.d.ts +1 -0
- package/dist-library/types/local/compilation/compile-status.d.ts +2 -0
- package/dist-library/types/local/compilation/compiler-bindings.d.ts +1 -1
- package/dist-library/types/local/compilation/compiler-capabilities.d.ts +4 -1
- package/dist-library/types/local/compilation/compiler-core.d.ts +1 -1
- package/dist-library/types/local/compilation/compiler-embedding.d.ts +20 -0
- package/dist-library/types/local/compilation/compiler-expressions.d.ts +5 -4
- package/dist-library/types/local/compilation/compiler-structure.d.ts +1 -1
- package/dist-library/types/local/compilation/compiler-tables.d.ts +3 -2
- package/dist-library/types/local/compilation/compiler-validation.d.ts +5 -9
- package/dist-library/types/local/compilation/compiler-values.d.ts +1 -1
- package/dist-library/types/local/compilation/compiler.d.ts +1 -1
- package/dist-library/types/local/compilation/component-usage.d.ts +2 -0
- package/dist-library/types/local/compilation/runtime-requirement.d.ts +3 -0
- package/dist-library/types/local/compilation/session/incremental.d.ts +5 -1
- package/dist-library/types/local/compilation/streaming.d.ts +1 -1
- package/dist-library/types/local/configuration/diagnostic-messages.d.ts +55 -0
- package/dist-library/types/local/configuration/embedding.d.ts +4 -0
- package/dist-library/types/local/configuration/kernel-value-rules.d.ts +1 -1
- package/dist-library/types/local/configuration/options-core.d.ts +8 -2
- package/dist-library/types/local/index.d.ts +6 -1
- package/dist-library/types/local/observability-core.d.ts +20 -1
- package/dist-library/types/local/observability.d.ts +2 -0
- package/dist-library/types/local/parsing/parse-budget.d.ts +18 -2
- package/dist-library/types/local/parsing/parser-region.d.ts +13 -2
- package/dist-library/types/local/parsing/parser-tags.d.ts +6 -1
- package/dist-library/types/local/parsing/rmd-recovery.d.ts +8 -0
- package/dist-library/types/local/performance-report.d.ts +70 -0
- package/dist-library/types/local/runtime/runtime-pool.d.ts +14 -0
- package/dist-library/types/local/transport/worker-handler.d.ts +3 -0
- package/dist-library/types/local/transport/worker-job.d.ts +12 -2
- package/dist-library/types/local/transport/worker-pool.d.ts +68 -0
- package/dist-library/types/local/transport/worker.d.ts +14 -0
- package/dist-library/types/local/types.d.ts +37 -25
- package/dist-library/types/observability.d.ts +1 -0
- package/dist-library/types/presets/default-semantics.d.ts +1 -1
- package/dist-library/types/presets/identity.d.ts +1 -8
- package/dist-library/types/presets/pack-style-entry.d.ts +3 -0
- package/dist-library/types/presets/pack-style-manifest.d.ts +11 -0
- package/dist-library/types/react/component-api.d.ts +3 -2
- package/dist-library/types/react/component-loader.d.ts +61 -0
- package/dist-library/types/react/component-primitives.d.ts +5 -5
- package/dist-library/types/react/index.d.ts +9 -5
- package/dist-library/types/react/localization.d.ts +5 -6
- package/dist-library/types/react/minimal.d.ts +2 -2
- package/dist-library/types/react/package-core.d.ts +3 -0
- package/dist-library/types/react/packed.d.ts +17 -0
- package/dist-library/types/react/render-lifecycle.d.ts +9 -0
- package/dist-library/types/{local → react}/rendering/document/ExtendedHtmlFragment.d.ts +1 -1
- package/dist-library/types/{local → react}/rendering/document/LocalDocumentViewCore.d.ts +11 -4
- package/dist-library/types/react/rendering/document/LocalPooledDocumentView.d.ts +8 -0
- package/dist-library/types/react/rendering/document/LocalReactiveDocumentCore.d.ts +6 -0
- package/dist-library/types/react/rendering/document/LocalStaticDocumentView.d.ts +18 -0
- package/dist-library/types/react/rendering/document/StaticExternalSlot.d.ts +25 -0
- package/dist-library/types/react/rendering/document/StaticHostData.d.ts +14 -0
- package/dist-library/types/{local → react}/rendering/document/render-nodes.d.ts +8 -8
- package/dist-library/types/react/rendering/document/static-runtime.d.ts +11 -0
- package/dist-library/types/{local → react}/rendering/document/use-author-script.d.ts +2 -2
- package/dist-library/types/{local → react}/rendering/document/validation-state.d.ts +2 -2
- package/dist-library/types/{local → react}/rendering/document/view-render-context.d.ts +40 -8
- package/dist-library/types/{local → react}/rendering/document/view-revision.d.ts +2 -2
- package/dist-library/types/{local → react}/rendering/render-types.d.ts +5 -5
- package/dist-library/types/react/rendering/table/data-table.d.ts +5 -0
- package/dist-library/types/{local → react}/rendering/table/table-numeric-columns.d.ts +3 -3
- package/dist-library/types/react/sdk-core.d.ts +12 -3
- package/dist-library/types/react/sdk.d.ts +2 -1
- package/dist-library/types/react/server.d.ts +3 -10
- package/dist-library/types/react/static-server.d.ts +12 -0
- package/dist-library/types/scan/index.d.ts +15 -0
- package/dist-library/types/sdk/config.d.ts +2 -35
- package/dist-library/types/sdk/default-identity.d.ts +3 -0
- package/dist-library/types/sdk/index.d.ts +1 -1
- package/dist-library/types/sdk/preset.d.ts +9 -0
- package/dist-library/types/sdk/props.d.ts +8 -3
- package/dist-library/types/sdk/registry-core.d.ts +2 -2
- package/dist-library/types/sdk/registry.d.ts +2 -18
- package/dist-library/types/sdk/types.d.ts +2 -2
- package/dist-library/types/sdk/version.d.ts +2 -0
- package/dist-library/types/standalone/session-core.d.ts +1 -1
- package/dist-library/{types-Ib5kSScP.js → types-Bza88SGK.js} +1 -1
- package/dist-library/use-hydrated-W-laKPhY.js +22975 -0
- package/dist-library/validation-XXlb-spV.js +860 -0
- package/dist-library/{version-DAxuGOG2.js → version-B0G1699c.js} +24 -33
- package/dist-library/visual-frame-y5RFhJ0_.js +19 -0
- package/dist-library/visual-helpers-CRmaqCHX.js +75 -0
- package/dist-library/visuals-CdHezgh5.js +3 -0
- package/dist-library/visuals-CoVSjVD8.js +49159 -0
- package/dist-library/worker-D6WMV8xJ.js +1632 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +121 -120
- package/docs/README-ch.md +102 -101
- package/docs/README.md +102 -101
- package/docs/compatibility/compatibility-ch.md +146 -146
- package/docs/compatibility/compatibility-en.md +146 -146
- package/docs/compatibility/deprecation-ch.md +1 -1
- package/docs/compatibility/deprecation-en.md +1 -1
- package/docs/compatibility/source-versioning-ch.md +162 -162
- package/docs/compatibility/source-versioning-en.md +162 -162
- package/docs/compatibility/support-matrix-ch.md +1 -1
- package/docs/compatibility/support-matrix-en.md +1 -1
- package/docs/development/component-development-ch.md +66 -66
- package/docs/development/component-development-en.md +66 -66
- package/docs/development/component-development-reference-ch.md +269 -253
- package/docs/development/component-development-reference-en.md +254 -238
- package/docs/development/component-protocol-ch.md +768 -748
- package/docs/development/component-protocol-en.md +770 -750
- package/docs/development/extension-tutorial-ch.md +308 -308
- package/docs/development/extension-tutorial-en.md +308 -308
- package/docs/development/performance-overview-ch.md +422 -422
- package/docs/development/performance-overview-en.md +422 -422
- package/docs/guides/local-guide-ch.md +532 -532
- package/docs/guides/local-guide-en.md +532 -532
- package/docs/integration/author-tools-ch.md +66 -64
- package/docs/integration/author-tools-en.md +66 -64
- package/docs/integration/compiler-ch.md +90 -49
- package/docs/integration/compiler-en.md +77 -36
- package/docs/integration/directory-discovery-en.md +1 -1
- package/docs/integration/editor-ch.md +295 -295
- package/docs/integration/editor-en.md +303 -303
- package/docs/integration/extension-sdk-ch.md +398 -394
- package/docs/integration/extension-sdk-en.md +383 -379
- package/docs/integration/local-integration-ch.md +648 -646
- package/docs/integration/local-integration-en.md +664 -662
- package/docs/integration/shareable-export-ch.md +307 -307
- package/docs/integration/shareable-export-en.md +309 -309
- package/docs/reference/diagnostics-counting-ch.md +104 -104
- package/docs/reference/diagnostics-counting-en.md +104 -104
- package/docs/reference/html-compatibility-ch.md +93 -93
- package/docs/reference/html-compatibility-en.md +95 -95
- package/docs/reference/local-interaction-syntax-ch.md +724 -724
- package/docs/reference/local-interaction-syntax-en.md +722 -722
- package/docs/reference/public-api-ch.md +114 -7
- package/docs/reference/public-api-en.md +114 -7
- package/docs/reference/theme-protocol-ch.md +198 -198
- package/docs/reference/theme-protocol-en.md +217 -217
- package/docs/releases/release-0.4.0-ch.md +91 -91
- package/docs/releases/release-0.4.0-en.md +91 -91
- package/docs/releases/release-0.4.1-ch.md +25 -25
- package/docs/releases/release-0.4.1-en.md +25 -25
- package/docs/releases/release-0.5.0-ch.md +43 -43
- package/docs/releases/release-0.5.0-en.md +43 -43
- package/docs/releases/release-0.5.1-ch.md +41 -41
- package/docs/releases/release-0.5.1-en.md +41 -41
- package/docs/releases/release-0.5.2-ch.md +37 -37
- package/docs/releases/release-0.5.2-en.md +37 -37
- package/docs/releases/release-0.5.3-ch.md +26 -26
- package/docs/releases/release-0.5.3-en.md +26 -26
- package/docs/releases/release-0.6.0-ch.md +59 -59
- package/docs/releases/release-0.6.0-en.md +59 -59
- package/docs/releases/release-0.6.1-ch.md +29 -29
- package/docs/releases/release-0.6.1-en.md +29 -29
- package/docs/releases/release-0.7.0-ch.md +86 -86
- package/docs/releases/release-0.7.0-en.md +86 -86
- package/docs/releases/release-0.9.3-ch.md +45 -0
- package/docs/releases/release-0.9.3-en.md +45 -0
- package/examples/component-package/README-ch.md +101 -101
- package/examples/component-package/README.md +133 -133
- package/examples/conformance/README-ch.md +55 -55
- package/examples/conformance/README.md +55 -55
- package/examples/conformance/component-protocol-1.json +482 -482
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/local-draft-1.json +50 -50
- package/examples/conformance/local-draft-2.json +212 -212
- package/examples/game-2048-package/LICENSE +21 -21
- package/examples/game-2048-package/NOTICES.md +11 -11
- package/examples/game-2048-package/README-ch.md +91 -91
- package/examples/game-2048-package/README.md +98 -98
- package/examples/game-2048-package/package.json +35 -35
- package/examples/game-2048-package/sample/document.reactive.md +17 -17
- package/examples/game-2048-package/scripts/build-export.mjs +44 -44
- package/examples/game-2048-package/scripts/build.mjs +130 -130
- package/examples/game-2048-package/scripts/verify.mjs +180 -180
- package/examples/game-2048-package/src/component.css +161 -161
- package/examples/game-2048-package/src/components.tsx +326 -326
- package/examples/game-2048-package/src/game-engine.ts +228 -228
- package/examples/game-2048-package/src/harness.tsx +34 -34
- package/examples/game-2048-package/src/manifest.ts +85 -85
- package/examples/game-2048-package/src/node-entry.ts +30 -30
- package/examples/game-2048-package/src/sample.ts +4 -4
- package/examples/game-2048-package/tsconfig.json +15 -15
- package/examples/integration/README-ch.md +114 -82
- package/examples/integration/README.md +114 -82
- package/examples/integration/chat-session/index.mjs +91 -0
- package/examples/integration/chat-session/package.json +10 -0
- package/examples/integration/core/index.mjs +32 -32
- package/examples/integration/extension-sdk/README-ch.md +24 -24
- package/examples/integration/extension-sdk/README.md +24 -24
- package/examples/integration/static-embed/embed.mjs +44 -0
- package/examples/integration/static-embed/index.html +12 -0
- package/examples/integration/static-embed/main.mjs +24 -0
- package/examples/integration/static-embed/references.mjs +5 -0
- package/examples/integration/static-embed/render.mjs +10 -0
- package/examples/integration/worker/index.html +19 -19
- package/examples/integration/worker/main.js +61 -61
- package/examples/integration/worker/package.json +13 -13
- package/examples/integration/worker/worker.js +3 -3
- package/examples/local/README-ch.md +76 -76
- package/examples/local/README.md +76 -76
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/recipes/invoice-zh.reactive.md +36 -36
- package/examples/local/recipes/invoice.reactive.md +36 -36
- package/examples/local/recipes/workshop-zh.reactive.md +33 -33
- package/examples/local/recipes/workshop.reactive.md +33 -33
- package/examples/local/showcase/README-ch.md +22 -22
- package/examples/local/showcase/README.md +31 -31
- package/examples/local/showcase/explore.reactive.md +102 -102
- package/examples/local/showcase/flow.reactive.md +86 -86
- package/examples/local/showcase/forms.reactive.md +126 -126
- package/examples/local/showcase/functions.reactive.md +119 -119
- package/examples/local/showcase/layout.reactive.md +100 -100
- package/examples/local/showcase/statistics.reactive.md +108 -108
- package/examples/local/showcase/tasks.reactive.md +89 -89
- package/examples/local/showcase/zh/explore.reactive.md +102 -102
- package/examples/local/showcase/zh/flow.reactive.md +86 -86
- package/examples/local/showcase/zh/forms.reactive.md +126 -126
- package/examples/local/showcase/zh/functions.reactive.md +119 -119
- package/examples/local/showcase/zh/layout.reactive.md +100 -100
- package/examples/local/showcase/zh/statistics.reactive.md +108 -108
- package/examples/local/showcase/zh/tasks.reactive.md +89 -89
- package/examples/minimal-extension/README-ch.md +78 -78
- package/examples/minimal-extension/README.md +78 -78
- package/examples/minimal-extension/index.html +15 -15
- package/examples/minimal-extension/package.json +26 -26
- package/examples/minimal-extension/sample/document.reactive.md +10 -10
- package/examples/minimal-extension/scripts/build.mjs +32 -32
- package/examples/minimal-extension/scripts/export.mjs +72 -72
- package/examples/minimal-extension/scripts/test-node.mjs +75 -75
- package/examples/minimal-extension/src/extension.tsx +90 -90
- package/examples/minimal-extension/src/preview.tsx +12 -12
- package/examples/minimal-extension/src/source.ts +4 -4
- package/examples/minimal-extension/tsconfig.json +14 -14
- package/examples/sci-fi-theme/README-ch.md +133 -133
- package/examples/sci-fi-theme/README.md +148 -148
- package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -454
- package/examples/sci-fi-theme/demo/demo.css +638 -638
- package/examples/sci-fi-theme/demo/document.reactive.md +206 -206
- package/examples/sci-fi-theme/demo/index.html +13 -13
- package/examples/sci-fi-theme/demo/main.tsx +215 -215
- package/examples/sci-fi-theme/docs/design-system-ch.md +245 -245
- package/examples/sci-fi-theme/docs/design-system.md +474 -474
- package/examples/sci-fi-theme/package.json +28 -28
- package/examples/sci-fi-theme/scripts/screenshot.mjs +98 -98
- package/examples/sci-fi-theme/src/components.css +2370 -2370
- package/examples/sci-fi-theme/src/index.ts +6 -6
- package/examples/sci-fi-theme/src/notch.css +142 -142
- package/examples/sci-fi-theme/src/sci-fi.css +7 -7
- package/examples/sci-fi-theme/src/theme.ts +39 -39
- package/examples/sci-fi-theme/tsconfig.json +20 -20
- package/examples/sci-fi-theme/vite.config.ts +24 -24
- package/examples/tetris-package/LICENSE +21 -21
- package/examples/tetris-package/NOTICES.md +11 -11
- package/examples/tetris-package/README-ch.md +91 -91
- package/examples/tetris-package/README.md +95 -95
- package/examples/tetris-package/package.json +35 -35
- package/examples/tetris-package/sample/document.reactive.md +16 -16
- package/examples/tetris-package/scripts/build-export.mjs +44 -44
- package/examples/tetris-package/scripts/build.mjs +130 -130
- package/examples/tetris-package/scripts/verify.mjs +173 -173
- package/examples/tetris-package/src/component.css +145 -145
- package/examples/tetris-package/src/components.tsx +334 -334
- package/examples/tetris-package/src/harness.tsx +34 -34
- package/examples/tetris-package/src/manifests.ts +93 -93
- package/examples/tetris-package/src/node-entry.ts +16 -16
- package/examples/tetris-package/src/sample.ts +4 -4
- package/examples/tetris-package/src/tetris-engine.ts +325 -325
- package/examples/tetris-package/tsconfig.json +15 -15
- package/package.json +61 -2
- package/dist-library/LocalDocumentView-BuqgJZEY.js +0 -109
- package/dist-library/LocalReactiveDocumentCore-CWBe4Mm5.js +0 -275
- package/dist-library/compiler-dxLPB9Ym.js +0 -86
- package/dist-library/config-validation-D3D7Dy2J.js +0 -586
- package/dist-library/controls-DoZyLCrV.js +0 -6740
- package/dist-library/mount-preset-DMZ5wd3t.js +0 -13
- package/dist-library/options-BBp9IcHm.js +0 -121
- package/dist-library/package-core-K5xesGqy.js +0 -117
- package/dist-library/parser-standard-CBA1-hdG.js +0 -9630
- package/dist-library/plugin-packs-Bh1HhLym.js +0 -19
- package/dist-library/props-sJ8vk0cr.js +0 -183
- package/dist-library/react-0DCh-Mar.js +0 -7
- package/dist-library/resources-B0x_w3s9.js +0 -229
- package/dist-library/schema-BryM_VRW.js +0 -40
- package/dist-library/types/local/rendering/document/LocalReactiveDocumentCore.d.ts +0 -6
- package/dist-library/types/local/rendering/table/data-table.d.ts +0 -13
- package/dist-library/validation-B3RI0xOk.js +0 -1123
- package/dist-library/visual-frame-_rcd5HUv.js +0 -48
- package/dist-library/visuals-DkDhNdEZ.js +0 -72572
- /package/dist-library/types/{local/configuration → contracts}/color-values.d.ts +0 -0
- /package/dist-library/types/{local/html → contracts}/html-names.d.ts +0 -0
- /package/dist-library/types/{local/configuration → contracts}/schema-core.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/code/code-block.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/code/code-languages.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/document/LocalDocumentView.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/document/use-color-scheme.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/image/image-view.d.ts +0 -0
- /package/dist-library/types/{local → react}/rendering/math-view.d.ts +0 -0
|
@@ -1,662 +1,664 @@
|
|
|
1
|
-
# Local mode integration
|
|
2
|
-
|
|
3
|
-
**English** · [中文](local-integration-ch.md)
|
|
4
|
-
|
|
5
|
-
Local interaction mode uses HTML-style tags, in-place parameters and `{{ expressions }}`. Author rules are in the [beginner guide](../guides/local-guide-en.md) and the [syntax specification](../reference/local-interaction-syntax-en.md); complete documents are in the [example index](../../examples/local/README.md). Hosts explicitly select this mode through the `Local` APIs. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the optional revision directive, upgrade checks and `migrateLocalSource`, and [0.4.0 release and migration](../releases/release-0.4.0-en.md) for the upgrade checklist.
|
|
6
|
-
|
|
7
|
-
## Runtime and entries
|
|
8
|
-
|
|
9
|
-
ReactiveMD mixes P0 HTML with Markdown and components. Hosts grant author styles, scripts and extended HTML fragments independently. See [HTML compatibility](../reference/html-compatibility-en.md).
|
|
10
|
-
|
|
11
|
-
| Entry | Contents | Dependency |
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| `reactive-md` | `compileLocal`, `createLocalRuntime`, expression and math utilities | No React dependency |
|
|
14
|
-
| `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` | React 19 |
|
|
15
|
-
| `reactive-md/styles.css` | Component, theme and document styles | Explicitly imported by the host |
|
|
16
|
-
|
|
17
|
-
The package ships ESM only. Node.js 22.12+ can be used for development and Node-side compilation and runtime. Local browser checks use Edge; static SSR is covered by the packed check; see [Versions and compatibility](../compatibility/compatibility-en.md) for the full matrix. Copyable projects are in [Standalone integration examples](../../examples/integration/README.md). For single-file HTML, state files and the standalone browser runtime, see [Shareable documents and static export](shareable-export-en.md).
|
|
18
|
-
|
|
19
|
-
## React
|
|
20
|
-
|
|
21
|
-
Install React in a host that already has Reactive MD; when using TypeScript, also install the matching type packages:
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
npm install react@19 react-dom@19
|
|
25
|
-
npm install --save-dev @types/react@19 @types/react-dom@19
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
30
|
-
import 'reactive-md/styles.css';
|
|
31
|
-
|
|
32
|
-
const source = `# Cost estimate
|
|
33
|
-
|
|
34
|
-
<panel title="Adjust the plan">
|
|
35
|
-
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
36
|
-
<toggle bind="annual" label="Annual billing">
|
|
37
|
-
</panel>
|
|
38
|
-
|
|
39
|
-
Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
|
|
40
|
-
|
|
41
|
-
export function Article() {
|
|
42
|
-
return <LocalReactiveDocument source={source} />;
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
| Prop | Type | Component | Notes |
|
|
47
|
-
| --- | --- | --- | --- |
|
|
48
|
-
| `source` | `string` | `LocalReactiveDocument` | Recompiles on source changes and adopts the new document in the existing runtime, migrating parameter values that still satisfy their contracts. Host option changes that affect compilation semantics or a document the runtime cannot adopt create a new runtime and drop the old instance state. See [Keeping values when source changes](#keeping-values-when-source-changes) |
|
|
49
|
-
| `sourcePhase` | `'streaming' \| 'final'` | `LocalReactiveDocument` | Marks whether the source is still being generated; defaults to `final`. While `streaming`, the document renders read-only in static mode and defers side effects; independent of `strict`. A host may also set `compileOptions.sourcePhase`; the prop wins. See [Streaming source compilation](#streaming-source-compilation) |
|
|
50
|
-
| `onTransientDiagnostics` | `(diagnostics: Diagnostic[]) => void` | `LocalReactiveDocument` | Receives fixable issues from streaming snapshots; they never enter `onDiagnostics`. When generation finishes, hosts that received them get one final empty array. Omit to ignore provisional issues |
|
|
51
|
-
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | Per-compilation limits, HTML capability flags and host component schemas; omitted options use the default ReactiveMD path |
|
|
52
|
-
| `document` | `LocalDocument` | `LocalDocumentView` | Compiled document; compiled once by the host |
|
|
53
|
-
| `runtime` | `LocalRuntime` | `LocalDocumentView` | Created by the host, which is responsible for disposal |
|
|
54
|
-
| `onDiagnostics` | `(diagnostics: Diagnostic[]) => void` | Both | Receives compile diagnostics and runtime diagnostics when control writes are rejected |
|
|
55
|
-
| `urlPolicy` | `(url: string, kind: 'image' \| 'link') => boolean` | Both | Decides whether to allow an image or link after protocol checks |
|
|
56
|
-
| `locale` | `'en' \| 'zh'` | Both | Language for built-in labels, controls and displayed diagnostics; defaults to `'en'`. Callbacks keep structured diagnostics |
|
|
57
|
-
| `themes` | `readonly LocalThemeDefinition[]` | Both | Host registrations; CSS loads separately; built-in `default` is always available |
|
|
58
|
-
| `colorScheme` | `'light' \| 'dark' \| 'auto'` | Both | Defaults to `auto`, following the nearest explicit ancestor preference or the system |
|
|
59
|
-
| `hostData` | `Readonly<Record<string, unknown>>` | Both | JSON-safe host data keyed `${kind}:${ref}` for `hostComponent` nodes; never enters the worker |
|
|
60
|
-
| `hostRenderer` | `LocalHostRenderer` | Both |
|
|
61
|
-
| `externalValues` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Values for `<external>` declarations; updates never recompile or reset parameters. `LocalDocumentView` also accepts it for host-managed runtimes |
|
|
62
|
-
| `initialParameters` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Public parameter values applied once after each new runtime is created, before interaction; ordinary source updates reuse the runtime and do not reapply them. An invalid set is rejected atomically and reported through `onDiagnostics` |
|
|
63
|
-
| `onParametersChange` | `(parameters, snapshot) => void` | `LocalReactiveDocument` | Called once per commit when the public writable parameter set actually changes; initialization, rejected writes, unchanged values and external-only updates do not call it |
|
|
64
|
-
| `onSourceNavigate` | `(target: LocalSourceTarget) => void` | Both | Reports a preview node's source range; enabling it adds source metadata attributes, omitting it leaves the DOM unchanged |
|
|
65
|
-
|
|
66
|
-
Neither component has `className`, `style` or slot props. `LocalReactiveDocument` renders `<article class="md-document local-document">`; `LocalDocumentView` uses the same document container. See below for style overrides.
|
|
67
|
-
|
|
68
|
-
```tsx
|
|
69
|
-
<LocalReactiveDocument
|
|
70
|
-
source={source}
|
|
71
|
-
initialParameters={savedParameters}
|
|
72
|
-
onParametersChange={(parameters) => save(parameters)}
|
|
73
|
-
externalValues={{ exchangeRate: 7.2 }}
|
|
74
|
-
onSourceNavigate={(target) => editor.current?.selectRange(target.range)}
|
|
75
|
-
hostRenderer={(node, data, ctx) => <HostWidget node={node} data={data} ctx={ctx} />}
|
|
76
|
-
/>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Each component instance manages in-memory state independently. Changing the source recompiles and adopts the new document in the existing runtime: parameters keep their values when their bindings, types and initial definitions still match, and incompatible values fall back to the new initial values. Disposing an instance clears subscriptions and timers. To migrate values explicitly when creating a new runtime or managing the runtime yourself, use the retention helpers; see [Keeping values when source changes](#keeping-values-when-source-changes). A panel reset in the document restores its internal parameters, input drafts and component state, and displays of same-name parameters outside the panel update as well.
|
|
80
|
-
|
|
81
|
-
When a host React root shares a page with the standalone IIFE, give the host root a distinct `identifierPrefix`, for example `createRoot(container, { identifierPrefix: 'host-' })`. The bundles own separate React instances, so their default `useId` counters can overlap. Independent server-rendered roots need matching unique prefixes on the server and client too.
|
|
82
|
-
|
|
83
|
-
When compilation fails, the component renders a disabled notice and the diagnostics list, and `onDiagnostics` also receives the diagnostics. Local computation errors during runtime are displayed near the corresponding content while the rest keeps updating.
|
|
84
|
-
|
|
85
|
-
### Headings and table-of-contents links
|
|
86
|
-
|
|
87
|
-
Documents can use Markdown table-of-contents links directly, for example `[Parameter description](#parameter-description)` targeting `## Parameter description`. The renderer generates anchors from heading text, appends `-1`, `-2` and so on to duplicate headings, and handles collisions with existing heading names. Emphasis and inline code in headings participate in naming as text; both Chinese and percent-encoded fragment links work.
|
|
88
|
-
|
|
89
|
-
Each document instance has its own anchor prefix, and matching table-of-contents links target the current instance. The same page can embed multiple copies of the same source. Links still go through protocol checks and the host `urlPolicy` first; the policy receives the raw address written by the author.
|
|
90
|
-
|
|
91
|
-
Anchors for dynamic headings are computed from source initial values, and parameter changes only update the displayed heading text. Rendered DOM IDs belong to the current mounted instance; when saving a table of contents, keep the fragment links from the source.
|
|
92
|
-
|
|
93
|
-
## Incremental compilation for editing
|
|
94
|
-
|
|
95
|
-
Keep one `createLocalCompileSession()` for repeated edits of the same document:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
import { createLocalCompileSession } from 'reactive-md';
|
|
99
|
-
|
|
100
|
-
const session = createLocalCompileSession();
|
|
101
|
-
session.compile('First **paragraph**.\n\nSecond paragraph.');
|
|
102
|
-
const result = session.compile('First **paragraph**.\n\nEdited second paragraph.');
|
|
103
|
-
console.log(session.stats); // mode: 'incremental', compiledBlocks: 1, reusedBlocks: 1
|
|
104
|
-
session.dispose(); // when closing the document
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
`compile(source, options?, phase?)` returns `LocalCompileResult`; see [Streaming source compilation](#streaming-source-compilation) for phases. `compileShared` exposes the compiler-owned read-only result graph used by the Worker and preview; callers must not mutate it, and `compile` publishes an independent plain-data snapshot instead. `clear()` releases reusable state; `dispose()` releases it and ends the session. Compiling after disposal throws. Each result is an independent, serializable plain-data snapshot, so mutating an earlier result cannot corrupt cached blocks. Unchanged blocks may retain node IDs across edits. Their numbering can differ from a separate `compileLocal()` call; resolve metadata IDs within the same result.
|
|
108
|
-
|
|
109
|
-
With an unchanged declaration and binding context, only affected Markdown blocks are recompiled. Changes to declarations, component contents, options, permissions or host schemas trigger full compilation. Reference definitions, footnotes, navigation anchors, HTML, BOMs, code-delimiter changes and uncertain boundaries also use full compilation. Inputs producing diagnostics return the full compiler's diagnostics. Whole-document source and cumulative node budgets still apply, and only the current version is retained.
|
|
110
|
-
|
|
111
|
-
During consecutive component or declaration edits, the session retains the latest successful full result and defers building its block index. The next independent prose edit builds the index once and reuses the other blocks. Identical source can return an independent cached snapshot. Option changes, errors, `clear()` and `dispose()` discard deferred state.
|
|
112
|
-
|
|
113
|
-
`stats` reports the latest mode (`full`, `incremental`, `cached`, or `streaming`), block counts, reuse counts, compiled characters and an optional invalidation reason. `cacheBuilds` counts block-index construction attempts during the call, including deferred recovery. Changed blocks compile under the unchanged declaration prefix; that work is included in `compiledCharacters`. Source comparison, range relocation and complete result snapshot assembly still scale with document size.
|
|
114
|
-
|
|
115
|
-
A document consisting of one flat list or table can also establish an incremental snapshot. Simple inline plans survive row edits; unchanged rows retain node IDs after semantic validation. Rows at unchanged offsets can share objects; shifted rows are cloned with updated UTF-16 ranges. Dynamic interpolation still uses the general parser. The cumulative `stats.parse.reusedRows` / `reusedItems` counters track inline plans, while `reusedRowNodes` / `reusedItemNodes` track final row subtrees separately.
|
|
116
|
-
|
|
117
|
-
When a result patch costs too much, the Worker can return a complete successful result for the same revision and continue the patch chain from it. `metrics.patchFallback === 'cost'` identifies this choice. `patchBytes` / `fullBytes` estimate JSON UTF-8 size, not structured-clone size. This choice does not trigger a full-request retry.
|
|
118
|
-
|
|
119
|
-
`startLocalCompileWorker()`, the default `LocalCompileScheduler` fallback, and `LocalReactiveDocument` manage their own sessions. A custom `fallbackCompile` remains host-owned. `compileLocal()` remains the one-shot full compiler. See the [implementation and measurements](../development/performance-overview-en.md).
|
|
120
|
-
|
|
121
|
-
## Streaming source compilation
|
|
122
|
-
|
|
123
|
-
When a model, a collaborative replay or another producer grows a document in chunks, the host can submit the growing source to a compile session, scheduler, Worker or `LocalReactiveDocument` without waiting for the complete text. The engine accepts complete source snapshots and a phase marker only; token accumulation, model connections, conversation history, retries and cancellation stay with the host.
|
|
124
|
-
|
|
125
|
-
### Snapshots and phases
|
|
126
|
-
|
|
127
|
-
Every submission is the complete source so far. The host appends tokens to its own buffer and submits that buffer at a throttling window or structural boundary; reconnecting or replacing a damaged fragment also submits complete text. The phase is:
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
type LocalSourcePhase = 'streaming' | 'final';
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
`streaming` means the current generation is unfinished; `final` means the source is complete. The phase may be supplied as `LocalCompileOptions.sourcePhase` or as an explicit session or scheduler argument. When both are omitted, compilation keeps the existing final semantics. Only these two values are accepted at runtime; sessions and `LocalCompileScheduler` return the same `local.options.invalid` failure for any other value instead of falling back to `final`. `sourcePhase` is not part of compile identity: it does not enter `localCompileOptionsKey` and does not change `strict`:
|
|
134
|
-
|
|
135
|
-
- `strict` still controls structural recovery of the final source only. `strict: false` is not a streaming mode; it recovers structures that remain damaged in the final source as literal text and reports warnings.
|
|
136
|
-
- `sourcePhase` reports whether the source is still being generated. A streaming snapshot degrades regions that cannot be interpreted safely to literal text while keeping node identity and source ranges for the completed prefix; an unfinished tail does not fail the whole preview. `strict: false` recovery records and warnings keep their existing rules and are not marked transient. `final` compiles the complete source under the selected strict mode.
|
|
137
|
-
- Unclosed tags, attribute quotes, component bodies, interpolations and formulas that are temporarily visible during streaming should not be rewritten into syntax repairs by the host; submit the completed source and compile it normally.
|
|
138
|
-
|
|
139
|
-
### Status and transient diagnostics
|
|
140
|
-
|
|
141
|
-
Results for calls that supply an explicit phase add `status`; streaming results may also carry `transientDiagnostics`. Calls that omit the phase keep the existing result shape without either field. `diagnostics` always contains non-transient diagnostics only:
|
|
142
|
-
|
|
143
|
-
| Source phase | `status` | Result meaning |
|
|
144
|
-
| --- | --- | --- |
|
|
145
|
-
| `streaming` | `partial` | `ok: true`; returns the document that can be shown safely. Issues that later source can repair go to `transientDiagnostics`, and regions that cannot be interpreted safely stay literal. |
|
|
146
|
-
| `streaming` + deterministic error | `failed` | `ok: false`; only deterministic errors remain in `diagnostics`: options, source type or length, syntax version, budgets, native-HTML/security policy, configuration, registry and capability failures, plus internal parse failures (`local.parse.*`). |
|
|
147
|
-
| `final` | `valid` | Complete compilation succeeded without structural recovery. |
|
|
148
|
-
| `final` + `strict: false` recovery | `recovered` | Returns the document, `recoveries` and one warning per recovery. |
|
|
149
|
-
| `final` | `failed` | Keeps the final compilation error rules; errors are not marked transient. |
|
|
150
|
-
|
|
151
|
-
Transient diagnostics keep their original `code`, `message` and source range and appear only in `transientDiagnostics`; loose-mode recovery warnings keep their final diagnostic rules and are never copied into the transient list. Consumers should use `status` and the explicit fields instead of inferring the phase from diagnostic text. A streaming success may temporarily contain unclosed structures or unevaluated expressions; on `final`, clear the host's transient state and use the final `diagnostics`. Deterministic errors still fail immediately and are not repairable placeholders.
|
|
152
|
-
|
|
153
|
-
### Sessions, schedulers and Workers
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
import { LocalCompileScheduler, createLocalCompileSession } from 'reactive-md';
|
|
157
|
-
|
|
158
|
-
const session = createLocalCompileSession();
|
|
159
|
-
const partial = session.compile(snapshot, options, 'streaming');
|
|
160
|
-
if (partial.status === 'partial') {
|
|
161
|
-
render(partial.document);
|
|
162
|
-
showTransient(partial.transientDiagnostics ?? []);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const final = session.compile(completedSource, options, 'final');
|
|
166
|
-
if (final.status === 'valid' || final.status === 'recovered') {
|
|
167
|
-
clearTransient();
|
|
168
|
-
render(final.document);
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
The explicit `phase` of `compile(source, options?, phase?)` and `compileShared(source, options?, phase?)` wins over `options.sourcePhase`. An explicit `final` uses the same final compilation path as an omitted phase and only adds `status`.
|
|
173
|
-
|
|
174
|
-
`LocalCompileScheduler.schedule(source, options?, hint?, phase?)` follows the same phases:
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
const scheduler = new LocalCompileScheduler({
|
|
178
|
-
createWorker: () => new Worker(new URL('./compile.worker.ts', import.meta.url), { type: 'module' }),
|
|
179
|
-
onResult: ({ result, sourcePhase }) => applySnapshot(result, sourcePhase),
|
|
180
|
-
delay: 150,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
scheduler.schedule(snapshot, options, undefined, 'streaming');
|
|
184
|
-
scheduler.schedule(completedSource, options, undefined, 'final');
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
- Streaming snapshots share the scheduler's throttle window (`LOCAL_COMPILE_DELAY_MS`, 150 ms by default) and only the latest queued snapshot is kept; no compilation runs per token.
|
|
188
|
-
- `final` bypasses the debounce and queues immediately. It may wait for an in-flight compile, but the older result cannot be delivered because the phase is part of job identity; monotonic revisions keep later responses from overwriting earlier accepted state.
|
|
189
|
-
- Revisions increase monotonically, and a stale Worker response cannot update the current preview. Streaming jobs never join the `patch-v1` baseline; scheduling a streaming snapshot invalidates the existing baseline, and only a final result can establish a patch baseline.
|
|
190
|
-
- Worker full requests and responses echo `sourcePhase` whenever a phase was declared; phase-less legacy jobs keep the historical wire shape and omit it. A phase on the options object is honored the same way. `LocalCompileOutcome.sourcePhase` reports the result phase. Main-thread fallback uses the same semantics; a custom `fallbackCompile` receives the phase as its third argument.
|
|
191
|
-
- Worker patch retries use `retryFull` with the codes `stale-base`, `options-mismatch`, `invalid-edit` or `phase-mismatch`; the scheduler falls back to one complete request instead of trusting a misaligned patch.
|
|
192
|
-
|
|
193
|
-
Streaming snapshots never read or populate the final block, deferred-index or shared-result caches; a final compile always starts from the existing incremental or full path. Lower-level parser caches keyed by exact source text may still serve both phases, because they are pure functions of that text and options. Streaming jobs may reuse the last result for an identical snapshot, but do not depend on block-level reuse across snapshots.
|
|
194
|
-
|
|
195
|
-
### React hosts
|
|
196
|
-
|
|
197
|
-
```tsx
|
|
198
|
-
import { useState } from 'react';
|
|
199
|
-
import type { Diagnostic, LocalSourcePhase } from 'reactive-md';
|
|
200
|
-
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
201
|
-
|
|
202
|
-
export function StreamedArticle({ source, phase }: {
|
|
203
|
-
source: string;
|
|
204
|
-
phase: LocalSourcePhase;
|
|
205
|
-
}) {
|
|
206
|
-
const [transient, setTransient] = useState<Diagnostic[]>([]);
|
|
207
|
-
const [diagnostics, setDiagnostics] = useState<Diagnostic[]>([]);
|
|
208
|
-
|
|
209
|
-
return (
|
|
210
|
-
<>
|
|
211
|
-
<LocalReactiveDocument
|
|
212
|
-
source={source}
|
|
213
|
-
sourcePhase={phase}
|
|
214
|
-
onTransientDiagnostics={setTransient}
|
|
215
|
-
onDiagnostics={setDiagnostics}
|
|
216
|
-
/>
|
|
217
|
-
{transient.length > 0 && <p>{transient.length} provisional issues</p>}
|
|
218
|
-
{phase === 'final' && diagnostics.length > 0 && <p>Compilation failed; see diagnostics.</p>}
|
|
219
|
-
</>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
While streaming, `LocalReactiveDocument` renders with `mode="static"`: controls are read-only, network sessions are not established, and submissions, resets and other component side effects do not start. It still reuses the same compile session and runtime, and ordinary source updates retain compatible reader values and input drafts through the existing migration rules; a phase change does not rebuild the runtime or reset state. `final` restores the host's `mode`, `staticFirst` and full interaction. `onDiagnostics` carries non-transient diagnostics for the current snapshot; provisional issues never enter that channel. `onTransientDiagnostics` reports provisional issues only; if the host received any, finalization calls it once more with an empty array, and a later streaming snapshot without provisional issues retracts the same way. Deterministic failures still show the existing error notice.
|
|
225
|
-
|
|
226
|
-
The host must write each new snapshot to `source` and switch `sourcePhase` back to `final` when generation ends. On cancellation, document switches or unmount, stop submitting and discard old results; the engine validates revisions and phases only and does not manage generation rounds.
|
|
227
|
-
|
|
228
|
-
### Security boundaries
|
|
229
|
-
|
|
230
|
-
Streaming compilation does not change the document security model:
|
|
231
|
-
|
|
232
|
-
- The host owns model transport, credentials, retries and cancellation. ReactiveMD receives text snapshots only; it does not connect to model services or add network requests or code execution for streaming.
|
|
233
|
-
- `streaming` does not enable author HTML, scripts, CSS or other language capabilities; the host still grants them through explicit compile options. Deterministic security, configuration, version and budget errors remain final failures.
|
|
234
|
-
- During streaming, side-effecting components are deferred by static mode so incomplete content cannot submit, subscribe or perform other external actions; full interaction returns on `final`. Hosts still enforce their own permissions, CSP and untrusted-content policies.
|
|
235
|
-
|
|
236
|
-
### Performance expectations
|
|
237
|
-
|
|
238
|
-
Every accepted streaming snapshot compiles the complete source. Regions that cannot be interpreted safely are degraded to literal text through up to six stabilization passes, followed by one whole-source literal compile when damage persists; this path does not promise block-level incremental cost. The scheduler throttles and coalesces snapshots, and `final` queues immediately. Source still respects the 1,000,000-character limit and compile budgets; longer snapshots cost more per compile. Measure input-to-preview latency and compile volume on long documents, then tune the host's submission window accordingly; do not call a compile entry per token. The repository benchmark `npm run bench:streaming` reports, for a 15.5 KB / 227-block document in 64-character chunks, p50 ≈ 15–23 ms and p95 ≈ 33–53 ms per streaming snapshot across runs, exact final equality with one-shot compilation, and about 31 coalesced submissions under a 150 ms window. Treat these numbers as a baseline, not a cross-machine SLO.
|
|
239
|
-
|
|
240
|
-
## Strict parsing and local recovery
|
|
241
|
-
|
|
242
|
-
The `strict` option controls structural recovery in compiler factories, `compileLocal`, editing sessions and Workers. It defaults to `true`; omission and explicit `undefined` use the same default. Other non-boolean values are configuration errors.
|
|
243
|
-
|
|
244
|
-
```ts
|
|
245
|
-
import { createStandardCompiler } from 'reactive-md/compiler/standard';
|
|
246
|
-
|
|
247
|
-
const compiler = createStandardCompiler({ strict: false });
|
|
248
|
-
const result = compiler.compile(`<alert>
|
|
249
|
-
Unfinished content {{ missing }}.
|
|
250
|
-
|
|
251
|
-
## Next section
|
|
252
|
-
|
|
253
|
-
This **Markdown** still renders.
|
|
254
|
-
`);
|
|
255
|
-
|
|
256
|
-
if (result.status === 'recovered') {
|
|
257
|
-
console.log(result.diagnostics, result.recoveries, result.program.nodes);
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
Loose mode keeps the damaged region as original source text. Components, expressions and declarations inside it stay inert. Compilation resumes at the next reliable boundary without rewriting the source.
|
|
262
|
-
|
|
263
|
-
Complete pairs take priority, including components whose bodies cross headings. A stray closing tag becomes literal text by itself. An outer closing tag can terminate an intact outer container while its unclosed inner fragment becomes text. An unmatched, lexically complete opener can recover before an ATX heading with a preceding blank line in the same Markdown container. Code, comments, raw HTML text and unfinished attribute quotes do not supply heading boundaries. Ordinary paragraphs, blank lines and sibling components are not synchronization points; without a reliable heading, recovery extends to the outer boundary or end of file.
|
|
264
|
-
|
|
265
|
-
Each recovery records `code`, `causeRange`, `affectedRange`, `action` and `boundary`. Ranges are half-open UTF-16 offsets into the original source. Records are sorted and deduplicated.
|
|
266
|
-
|
|
267
|
-
Each finalized recovery also produces at most one warning at `causeRange` with the same stable code: `local.recovery.unclosed`, `local.recovery.mismatch`, `local.recovery.stray-close`, `local.html.repair` or `local.html.literal`. The message states what was repaired or kept as literal text, so recovery is never silent. Line and column use the raw UTF-16 source. Warnings are not emitted per token. The diagnostics budget applies: when it is full, a warning may be omitted while the recovery record remains in `recoveries`. Recovery inserts no error block in the document body.
|
|
268
|
-
|
|
269
|
-
Binding errors, computation cycles, invalid initial values, required component attributes and component shape errors remain errors and fail compilation; recovery does not downgrade them. Configuration, version and budget errors also remain fatal. References outside a literal region to declarations removed inside it remain unknown bindings. A failed result can retain recoveries completed before the failure, their warnings and the separate error that caused failure.
|
|
270
|
-
|
|
271
|
-
### HTML and details
|
|
272
|
-
|
|
273
|
-
Loose mode repairs omitted or mismatched HTML tags within an isolated fragment using parse5. The existing element, attribute and URL policies still apply; loose mode grants no script, CSS or extended HTML capability. A repaired fragment yields one `local.html.repair` warning. A mixed RMD fragment becomes literal text with one `local.html.literal` warning when ownership and source ranges cannot be preserved. Synthetic nodes carry `synthetic` and `syntheticBoundary` metadata.
|
|
274
|
-
|
|
275
|
-
Both modes support a details element without blank lines:
|
|
276
|
-
|
|
277
|
-
```html
|
|
278
|
-
<details>
|
|
279
|
-
<summary>1145</summary>
|
|
280
|
-
1145
|
|
281
|
-
</details>
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
It renders as a single disclosure in an accordion with no group title. The trigger is `1145`, the panel contains `1145`, and it starts collapsed; click, Enter and Space toggle it. Boolean `open` starts it expanded, and static output exposes the body. Rich summaries and nested details retain their content.
|
|
285
|
-
|
|
286
|
-
### Results and hosts
|
|
287
|
-
|
|
288
|
-
Factory success results include `status: 'valid' | 'recovered'`, a deeply frozen `program`, diagnostics, recoveries and optional-check coverage in `checks`. A `valid` success has no recovery warning. A `recovered` success includes the program and one warning per recovery. Failures use `status: 'failed'` and contain no program; they may retain recoveries completed before the failure and their warnings. Unrecoverable semantic, type, binding, options, version and budget errors remain errors. The `ok` and `document` aliases remain available; `document` is a separate plain-data copy.
|
|
289
|
-
|
|
290
|
-
`compileLocal` keeps its existing result type and adds `recoveries` only when present. Strict results keep their existing field shape. Export options preserve the selected mode so standalone replay compiles the same source with that mode.
|
|
291
|
-
|
|
292
|
-
Loose editing sessions use the full reference path to avoid reusing blocks across recovery boundaries. Strict mode keeps its existing optimizations. Configuration identity includes strict mode and recovery strategy version 2. Demo and editor defaults remain strict.
|
|
293
|
-
|
|
294
|
-
## Core API
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
import { compileLocal, createLocalRuntime } from 'reactive-md';
|
|
298
|
-
|
|
299
|
-
const result = compileLocal(source);
|
|
300
|
-
if (result.ok) {
|
|
301
|
-
const runtime = createLocalRuntime(result.document, {
|
|
302
|
-
externalValues: { exchangeRate: 7.2 },
|
|
303
|
-
});
|
|
304
|
-
const unsubscribe = runtime.subscribe(() => {
|
|
305
|
-
console.log(runtime.snapshot());
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
console.log(runtime.evaluate('people * 100'));
|
|
309
|
-
console.log(runtime.text('People: {{ people }}'));
|
|
310
|
-
runtime.setExternalValues({ exchangeRate: 7.3 });
|
|
311
|
-
|
|
312
|
-
unsubscribe();
|
|
313
|
-
runtime.dispose();
|
|
314
|
-
} else {
|
|
315
|
-
console.log(result.diagnostics);
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
### `compileLocal(source: string, options?: LocalCompileOptions)`
|
|
320
|
-
|
|
321
|
-
`source` is the `.reactive.md` source. The return value is a union:
|
|
322
|
-
|
|
323
|
-
- Success: `{ ok: true; document: LocalDocument; diagnostics: Diagnostic[] }`
|
|
324
|
-
- Failure: `{ ok: false; diagnostics: Diagnostic[] }`
|
|
325
|
-
|
|
326
|
-
Syntax problems are returned through diagnostics; the current build accepts only `local-draft-3`. An explicit older revision directive is rejected with a `local.version.*` diagnostic; an unversioned source keeps current-revision behavior. The source limit is 1,000,000 characters. `document` is a current runtime object and should not be treated as a persistence format.
|
|
327
|
-
|
|
328
|
-
Hosts can set the syntax node budget for a single compilation:
|
|
329
|
-
|
|
330
|
-
```ts
|
|
331
|
-
import { compileLocal, type LocalCompileOptions } from 'reactive-md';
|
|
332
|
-
|
|
333
|
-
const options: LocalCompileOptions = {
|
|
334
|
-
limits: { maxSyntaxNodes: 50_000 },
|
|
335
|
-
};
|
|
336
|
-
const result = compileLocal(source, options);
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
`limits.maxSyntaxNodes` defaults to 10,000 and accepts integers from `1` to `Number.MAX_SAFE_INTEGER`. Omitting the options, `limits` or `maxSyntaxNodes` uses the default. `0`, negative numbers, decimals, `NaN`, infinity, strings, `null` and malformed option containers return a `local.options.invalid` diagnostic; exceeding the valid node budget returns a `local.budget` diagnostic.
|
|
340
|
-
|
|
341
|
-
The budget counts `LocalNode` instances created cumulatively during parsing, including Markdown text, paragraphs, lists, tables, interpolations, components and some intermediate nodes, so it may exceed the final syntax tree node count. The setting affects only this compilation, leaves the options object untouched, and keeps other resource limits such as arrays independent. The budget comes from the host; document content cannot raise it on its own.
|
|
342
|
-
|
|
343
|
-
To use a custom budget in React, call `compileLocal` first and pass the compiled document and runtime to `LocalDocumentView`. `LocalReactiveDocument` and the Playground compilation thread use the default budget. After raising the node budget, hosts should measure memory and preview rendering time with their actual documents.
|
|
344
|
-
|
|
345
|
-
#### Next.js Server Components
|
|
346
|
-
|
|
347
|
-
`compileLocal` returns plain data at every depth, including `document.dependencies`, node `attrs`, bindings and diagnostics. Records use `Object.prototype`; arrays use `Array.prototype`. Internal dictionaries may still use null prototypes. Existing frozen metadata and `undefined` fields are preserved.
|
|
348
|
-
|
|
349
|
-
Compile on the server, check `result.ok`, then pass `result.document` directly to a Client Component as a prop. A JSON round trip is unnecessary. This meets React's [plain-object requirement for serializable props](https://react.dev/reference/rsc/use-client#serializable-types-returned-by-server-components). In the Client Component, create and dispose `createLocalRuntime(document)` and render `LocalDocumentView` with that runtime. Runtime instances and host callbacks stay on the client; the plain-data guarantee applies to compiler output.
|
|
350
|
-
|
|
351
|
-
```tsx
|
|
352
|
-
// Server Component; ClientDocument is the host's 'use client' wrapper.
|
|
353
|
-
import { compileLocal } from 'reactive-md';
|
|
354
|
-
import ClientDocument from './ClientDocument';
|
|
355
|
-
|
|
356
|
-
export default function Page() {
|
|
357
|
-
const result = compileLocal('<counter bind="n" label="Count" initial="2">');
|
|
358
|
-
if (!result.ok) throw new Error('Compilation failed');
|
|
359
|
-
return <ClientDocument document={result.document} />;
|
|
360
|
-
}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Host components
|
|
364
|
-
|
|
365
|
-
A host can register components for one compilation without changing the author syntax revision. A schema declares a `form` and may declare a scalar binding:
|
|
366
|
-
|
|
367
|
-
```ts
|
|
368
|
-
import { compileLocal, type LocalHostComponentSchema } from 'reactive-md';
|
|
369
|
-
|
|
370
|
-
const hostComponents: LocalHostComponentSchema[] = [
|
|
371
|
-
{
|
|
372
|
-
name: 'host-weather',
|
|
373
|
-
form: 'leaf',
|
|
374
|
-
props: {
|
|
375
|
-
kind: { kind: 'enum', required: true, enum: ['weather'] },
|
|
376
|
-
ref: { kind: 'string', required: true, pattern: '^[a-z-]+$' },
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
name: 'host-rating',
|
|
381
|
-
form: 'leaf',
|
|
382
|
-
props: { label: { kind: 'string' } },
|
|
383
|
-
binding: { kind: 'number', min: 0, max: 5, step: 1 },
|
|
384
|
-
},
|
|
385
|
-
];
|
|
386
|
-
const result = compileLocal(source, { hostComponents });
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
Without `hostComponents`, those tags remain unknown and fall back to source. Names must be unique lowercase kebab-case and cannot reuse one of the 49 author tag names, a P0 HTML tag name or `theme`; at most 32 schemas are accepted. `pattern` accepts only a linear-time-safe regex subset (no backreferences, lookarounds, named groups, nested quantifiers or quantified alternation). An invalid schema returns `local.options.invalid`, and an invalid authored attribute returns `local.host.attribute`; a valid host node counts as one syntax node.
|
|
390
|
-
|
|
391
|
-
`form` is `leaf`, `inline` or `container`. Inline and container tags are paired; their body is compiled as normal Markdown and ReactiveMD content, and the renderer receives `ctx.render()` for children. `binding` is optional and accepts `string`, `number` or `boolean`, with static `min`, `max`, `step`, `options`, `initialRule` and `exclusive`. A bound host component implicitly accepts `bind`, `initial` and dynamic `disabled`, and shares the built-in binding families. For example, this rating control and the built-in number share one value:
|
|
392
|
-
|
|
393
|
-
```markdown
|
|
394
|
-
<host-rating bind="rating" label="Course rating">
|
|
395
|
-
<number bind="rating" label="Numeric rating" min="0" max="5" step="1">
|
|
396
|
-
|
|
397
|
-
Current rating: {{ rating }}
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
The host renderer receives `(node, data, ctx)`. `ctx` extends the render context with `value`, a validating `setValue(value)`, `disabled`, `resetToken`, resolved `props` and `report(diagnostics)`. `setValue` goes through the runtime, so shared constraints and reset behavior still apply. Pass `hostData`, keyed `${kind}:${ref}`, only for components that declare those props; a binding-only or container host does not need host data. A missing renderer, missing declared data or a throwing renderer renders a visible placeholder instead of failing the document. `mode="static"` uses the same dispatch and passes `ctx.mode` to the renderer. Host schemas are plain data and cross the worker boundary; renderers never do.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
`
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
|
443
|
-
|
|
|
444
|
-
| `
|
|
445
|
-
| `
|
|
446
|
-
| `
|
|
447
|
-
| `
|
|
448
|
-
| `
|
|
449
|
-
| `
|
|
450
|
-
| `
|
|
451
|
-
| `
|
|
452
|
-
| `
|
|
453
|
-
| `
|
|
454
|
-
| `
|
|
455
|
-
| `
|
|
456
|
-
| `
|
|
457
|
-
| `
|
|
458
|
-
| `
|
|
459
|
-
| `
|
|
460
|
-
| `
|
|
461
|
-
| `
|
|
462
|
-
|
|
463
|
-
`
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
runtime.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
`
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
- its
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
startLocalCompileWorker
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
`
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
- `
|
|
569
|
-
- `
|
|
570
|
-
- `
|
|
571
|
-
-
|
|
572
|
-
-
|
|
573
|
-
-
|
|
574
|
-
-
|
|
575
|
-
-
|
|
576
|
-
-
|
|
577
|
-
|
|
578
|
-
`
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
`
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
- `
|
|
591
|
-
-
|
|
592
|
-
-
|
|
593
|
-
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
|
618
|
-
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
-
|
|
629
|
-
|
|
630
|
-
-
|
|
631
|
-
- `
|
|
632
|
-
- Documents
|
|
633
|
-
-
|
|
634
|
-
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
A single
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
-
|
|
651
|
-
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
1
|
+
# Local mode integration
|
|
2
|
+
|
|
3
|
+
**English** · [中文](local-integration-ch.md)
|
|
4
|
+
|
|
5
|
+
Local interaction mode uses HTML-style tags, in-place parameters and `{{ expressions }}`. Author rules are in the [beginner guide](../guides/local-guide-en.md) and the [syntax specification](../reference/local-interaction-syntax-en.md); complete documents are in the [example index](../../examples/local/README.md). Hosts explicitly select this mode through the `Local` APIs. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the optional revision directive, upgrade checks and `migrateLocalSource`, and [0.4.0 release and migration](../releases/release-0.4.0-en.md) for the upgrade checklist.
|
|
6
|
+
|
|
7
|
+
## Runtime and entries
|
|
8
|
+
|
|
9
|
+
ReactiveMD mixes P0 HTML with Markdown and components. Hosts grant author styles, scripts and extended HTML fragments independently. See [HTML compatibility](../reference/html-compatibility-en.md).
|
|
10
|
+
|
|
11
|
+
| Entry | Contents | Dependency |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `reactive-md` | `compileLocal`, `createLocalRuntime`, expression and math utilities | No React dependency |
|
|
14
|
+
| `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` | React 19 |
|
|
15
|
+
| `reactive-md/styles.css` | Component, theme and document styles | Explicitly imported by the host |
|
|
16
|
+
|
|
17
|
+
The package ships ESM only. Node.js 22.12+ can be used for development and Node-side compilation and runtime. Local browser checks use Edge; static SSR is covered by the packed check; see [Versions and compatibility](../compatibility/compatibility-en.md) for the full matrix. Copyable projects are in [Standalone integration examples](../../examples/integration/README.md). For single-file HTML, state files and the standalone browser runtime, see [Shareable documents and static export](shareable-export-en.md).
|
|
18
|
+
|
|
19
|
+
## React
|
|
20
|
+
|
|
21
|
+
Install React in a host that already has Reactive MD; when using TypeScript, also install the matching type packages:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install react@19 react-dom@19
|
|
25
|
+
npm install --save-dev @types/react@19 @types/react-dom@19
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
30
|
+
import 'reactive-md/styles.css';
|
|
31
|
+
|
|
32
|
+
const source = `# Cost estimate
|
|
33
|
+
|
|
34
|
+
<panel title="Adjust the plan">
|
|
35
|
+
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
36
|
+
<toggle bind="annual" label="Annual billing">
|
|
37
|
+
</panel>
|
|
38
|
+
|
|
39
|
+
Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
|
|
40
|
+
|
|
41
|
+
export function Article() {
|
|
42
|
+
return <LocalReactiveDocument source={source} />;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Component | Notes |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `source` | `string` | `LocalReactiveDocument` | Recompiles on source changes and adopts the new document in the existing runtime, migrating parameter values that still satisfy their contracts. Host option changes that affect compilation semantics or a document the runtime cannot adopt create a new runtime and drop the old instance state. See [Keeping values when source changes](#keeping-values-when-source-changes) |
|
|
49
|
+
| `sourcePhase` | `'streaming' \| 'final'` | `LocalReactiveDocument` | Marks whether the source is still being generated; defaults to `final`. While `streaming`, the document renders read-only in static mode and defers side effects; independent of `strict`. A host may also set `compileOptions.sourcePhase`; the prop wins. See [Streaming source compilation](#streaming-source-compilation) |
|
|
50
|
+
| `onTransientDiagnostics` | `(diagnostics: Diagnostic[]) => void` | `LocalReactiveDocument` | Receives fixable issues from streaming snapshots; they never enter `onDiagnostics`. When generation finishes, hosts that received them get one final empty array. Omit to ignore provisional issues |
|
|
51
|
+
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | Per-compilation limits, HTML capability flags and host component schemas; omitted options use the default ReactiveMD path |
|
|
52
|
+
| `document` | `LocalDocument` | `LocalDocumentView` | Compiled document; compiled once by the host |
|
|
53
|
+
| `runtime` | `LocalRuntime` | `LocalDocumentView` | Created by the host, which is responsible for disposal |
|
|
54
|
+
| `onDiagnostics` | `(diagnostics: Diagnostic[]) => void` | Both | Receives compile diagnostics and runtime diagnostics when control writes are rejected |
|
|
55
|
+
| `urlPolicy` | `(url: string, kind: 'image' \| 'link') => boolean` | Both | Decides whether to allow an image or link after protocol checks |
|
|
56
|
+
| `locale` | `'en' \| 'zh'` | Both | Language for built-in labels, controls and displayed diagnostics; defaults to `'en'`. Callbacks keep structured diagnostics |
|
|
57
|
+
| `themes` | `readonly LocalThemeDefinition[]` | Both | Host registrations; CSS loads separately; built-in `default` is always available |
|
|
58
|
+
| `colorScheme` | `'light' \| 'dark' \| 'auto'` | Both | Defaults to `auto`, following the nearest explicit ancestor preference or the system |
|
|
59
|
+
| `hostData` | `Readonly<Record<string, unknown>>` | Both | JSON-safe host data keyed `${kind}:${ref}` for `hostComponent` nodes; never enters the worker |
|
|
60
|
+
| `hostRenderer` | `LocalHostRenderer` | Both | Renderer for `hostComponent` nodes. Missing data or a missing renderer shows a placeholder. |
|
|
61
|
+
| `externalValues` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Values for `<external>` declarations; updates never recompile or reset parameters. `LocalDocumentView` also accepts it for host-managed runtimes |
|
|
62
|
+
| `initialParameters` | `Readonly<Record<string, LocalValue>>` | `LocalReactiveDocument` | Public parameter values applied once after each new runtime is created, before interaction; ordinary source updates reuse the runtime and do not reapply them. An invalid set is rejected atomically and reported through `onDiagnostics` |
|
|
63
|
+
| `onParametersChange` | `(parameters, snapshot) => void` | `LocalReactiveDocument` | Called once per commit when the public writable parameter set actually changes; initialization, rejected writes, unchanged values and external-only updates do not call it |
|
|
64
|
+
| `onSourceNavigate` | `(target: LocalSourceTarget) => void` | Both | Reports a preview node's source range; enabling it adds source metadata attributes, omitting it leaves the DOM unchanged |
|
|
65
|
+
|
|
66
|
+
Neither component has `className`, `style` or slot props. `LocalReactiveDocument` renders `<article class="md-document local-document">`; `LocalDocumentView` uses the same document container. See below for style overrides.
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<LocalReactiveDocument
|
|
70
|
+
source={source}
|
|
71
|
+
initialParameters={savedParameters}
|
|
72
|
+
onParametersChange={(parameters) => save(parameters)}
|
|
73
|
+
externalValues={{ exchangeRate: 7.2 }}
|
|
74
|
+
onSourceNavigate={(target) => editor.current?.selectRange(target.range)}
|
|
75
|
+
hostRenderer={(node, data, ctx) => <HostWidget node={node} data={data} ctx={ctx} />}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Each component instance manages in-memory state independently. Changing the source recompiles and adopts the new document in the existing runtime: parameters keep their values when their bindings, types and initial definitions still match, and incompatible values fall back to the new initial values. Disposing an instance clears subscriptions and timers. To migrate values explicitly when creating a new runtime or managing the runtime yourself, use the retention helpers; see [Keeping values when source changes](#keeping-values-when-source-changes). A panel reset in the document restores its internal parameters, input drafts and component state, and displays of same-name parameters outside the panel update as well.
|
|
80
|
+
|
|
81
|
+
When a host React root shares a page with the standalone IIFE, give the host root a distinct `identifierPrefix`, for example `createRoot(container, { identifierPrefix: 'host-' })`. The bundles own separate React instances, so their default `useId` counters can overlap. Independent server-rendered roots need matching unique prefixes on the server and client too.
|
|
82
|
+
|
|
83
|
+
When compilation fails, the component renders a disabled notice and the diagnostics list, and `onDiagnostics` also receives the diagnostics. Local computation errors during runtime are displayed near the corresponding content while the rest keeps updating.
|
|
84
|
+
|
|
85
|
+
### Headings and table-of-contents links
|
|
86
|
+
|
|
87
|
+
Documents can use Markdown table-of-contents links directly, for example `[Parameter description](#parameter-description)` targeting `## Parameter description`. The renderer generates anchors from heading text, appends `-1`, `-2` and so on to duplicate headings, and handles collisions with existing heading names. Emphasis and inline code in headings participate in naming as text; both Chinese and percent-encoded fragment links work.
|
|
88
|
+
|
|
89
|
+
Each document instance has its own anchor prefix, and matching table-of-contents links target the current instance. The same page can embed multiple copies of the same source. Links still go through protocol checks and the host `urlPolicy` first; the policy receives the raw address written by the author.
|
|
90
|
+
|
|
91
|
+
Anchors for dynamic headings are computed from source initial values, and parameter changes only update the displayed heading text. Rendered DOM IDs belong to the current mounted instance; when saving a table of contents, keep the fragment links from the source.
|
|
92
|
+
|
|
93
|
+
## Incremental compilation for editing
|
|
94
|
+
|
|
95
|
+
Keep one `createLocalCompileSession()` for repeated edits of the same document:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { createLocalCompileSession } from 'reactive-md';
|
|
99
|
+
|
|
100
|
+
const session = createLocalCompileSession();
|
|
101
|
+
session.compile('First **paragraph**.\n\nSecond paragraph.');
|
|
102
|
+
const result = session.compile('First **paragraph**.\n\nEdited second paragraph.');
|
|
103
|
+
console.log(session.stats); // mode: 'incremental', compiledBlocks: 1, reusedBlocks: 1
|
|
104
|
+
session.dispose(); // when closing the document
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`compile(source, options?, phase?)` returns `LocalCompileResult`; see [Streaming source compilation](#streaming-source-compilation) for phases. `compileShared` exposes the compiler-owned read-only result graph used by the Worker and preview; callers must not mutate it, and `compile` publishes an independent plain-data snapshot instead. `clear()` releases reusable state; `dispose()` releases it and ends the session. Compiling after disposal throws. Each result is an independent, serializable plain-data snapshot, so mutating an earlier result cannot corrupt cached blocks. Unchanged blocks may retain node IDs across edits. Their numbering can differ from a separate `compileLocal()` call; resolve metadata IDs within the same result.
|
|
108
|
+
|
|
109
|
+
With an unchanged declaration and binding context, only affected Markdown blocks are recompiled. Changes to declarations, component contents, options, permissions or host schemas trigger full compilation. Reference definitions, footnotes, navigation anchors, HTML, BOMs, code-delimiter changes and uncertain boundaries also use full compilation. Inputs producing diagnostics return the full compiler's diagnostics. Whole-document source and cumulative node budgets still apply, and only the current version is retained.
|
|
110
|
+
|
|
111
|
+
During consecutive component or declaration edits, the session retains the latest successful full result and defers building its block index. The next independent prose edit builds the index once and reuses the other blocks. Identical source can return an independent cached snapshot. Option changes, errors, `clear()` and `dispose()` discard deferred state.
|
|
112
|
+
|
|
113
|
+
`stats` reports the latest mode (`full`, `incremental`, `cached`, or `streaming`), block counts, reuse counts, compiled characters and an optional invalidation reason. `cacheBuilds` counts block-index construction attempts during the call, including deferred recovery. Changed blocks compile under the unchanged declaration prefix; that work is included in `compiledCharacters`. Source comparison, range relocation and complete result snapshot assembly still scale with document size.
|
|
114
|
+
|
|
115
|
+
A document consisting of one flat list or table can also establish an incremental snapshot. Simple inline plans survive row edits; unchanged rows retain node IDs after semantic validation. Rows at unchanged offsets can share objects; shifted rows are cloned with updated UTF-16 ranges. Dynamic interpolation still uses the general parser. The cumulative `stats.parse.reusedRows` / `reusedItems` counters track inline plans, while `reusedRowNodes` / `reusedItemNodes` track final row subtrees separately.
|
|
116
|
+
|
|
117
|
+
When a result patch costs too much, the Worker can return a complete successful result for the same revision and continue the patch chain from it. `metrics.patchFallback === 'cost'` identifies this choice. `patchBytes` / `fullBytes` estimate JSON UTF-8 size, not structured-clone size. This choice does not trigger a full-request retry.
|
|
118
|
+
|
|
119
|
+
`startLocalCompileWorker()`, the default `LocalCompileScheduler` fallback, and `LocalReactiveDocument` manage their own sessions. A custom `fallbackCompile` remains host-owned. `compileLocal()` remains the one-shot full compiler. See the [implementation and measurements](../development/performance-overview-en.md).
|
|
120
|
+
|
|
121
|
+
## Streaming source compilation
|
|
122
|
+
|
|
123
|
+
When a model, a collaborative replay or another producer grows a document in chunks, the host can submit the growing source to a compile session, scheduler, Worker or `LocalReactiveDocument` without waiting for the complete text. The engine accepts complete source snapshots and a phase marker only; token accumulation, model connections, conversation history, retries and cancellation stay with the host.
|
|
124
|
+
|
|
125
|
+
### Snapshots and phases
|
|
126
|
+
|
|
127
|
+
Every submission is the complete source so far. The host appends tokens to its own buffer and submits that buffer at a throttling window or structural boundary; reconnecting or replacing a damaged fragment also submits complete text. The phase is:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
type LocalSourcePhase = 'streaming' | 'final';
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`streaming` means the current generation is unfinished; `final` means the source is complete. The phase may be supplied as `LocalCompileOptions.sourcePhase` or as an explicit session or scheduler argument. When both are omitted, compilation keeps the existing final semantics. Only these two values are accepted at runtime; sessions and `LocalCompileScheduler` return the same `local.options.invalid` failure for any other value instead of falling back to `final`. `sourcePhase` is not part of compile identity: it does not enter `localCompileOptionsKey` and does not change `strict`:
|
|
134
|
+
|
|
135
|
+
- `strict` still controls structural recovery of the final source only. `strict: false` is not a streaming mode; it recovers structures that remain damaged in the final source as literal text and reports warnings.
|
|
136
|
+
- `sourcePhase` reports whether the source is still being generated. A streaming snapshot degrades regions that cannot be interpreted safely to literal text while keeping node identity and source ranges for the completed prefix; an unfinished tail does not fail the whole preview. `strict: false` recovery records and warnings keep their existing rules and are not marked transient. `final` compiles the complete source under the selected strict mode.
|
|
137
|
+
- Unclosed tags, attribute quotes, component bodies, interpolations and formulas that are temporarily visible during streaming should not be rewritten into syntax repairs by the host; submit the completed source and compile it normally.
|
|
138
|
+
|
|
139
|
+
### Status and transient diagnostics
|
|
140
|
+
|
|
141
|
+
Results for calls that supply an explicit phase add `status`; streaming results may also carry `transientDiagnostics`. Calls that omit the phase keep the existing result shape without either field. `diagnostics` always contains non-transient diagnostics only:
|
|
142
|
+
|
|
143
|
+
| Source phase | `status` | Result meaning |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| `streaming` | `partial` | `ok: true`; returns the document that can be shown safely. Issues that later source can repair go to `transientDiagnostics`, and regions that cannot be interpreted safely stay literal. |
|
|
146
|
+
| `streaming` + deterministic error | `failed` | `ok: false`; only deterministic errors remain in `diagnostics`: options, source type or length, syntax version, budgets, native-HTML/security policy, configuration, registry and capability failures, plus internal parse failures (`local.parse.*`). |
|
|
147
|
+
| `final` | `valid` | Complete compilation succeeded without structural recovery. |
|
|
148
|
+
| `final` + `strict: false` recovery | `recovered` | Returns the document, `recoveries` and one warning per recovery. |
|
|
149
|
+
| `final` | `failed` | Keeps the final compilation error rules; errors are not marked transient. |
|
|
150
|
+
|
|
151
|
+
Transient diagnostics keep their original `code`, `message` and source range and appear only in `transientDiagnostics`; loose-mode recovery warnings keep their final diagnostic rules and are never copied into the transient list. Consumers should use `status` and the explicit fields instead of inferring the phase from diagnostic text. A streaming success may temporarily contain unclosed structures or unevaluated expressions; on `final`, clear the host's transient state and use the final `diagnostics`. Deterministic errors still fail immediately and are not repairable placeholders.
|
|
152
|
+
|
|
153
|
+
### Sessions, schedulers and Workers
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { LocalCompileScheduler, createLocalCompileSession } from 'reactive-md';
|
|
157
|
+
|
|
158
|
+
const session = createLocalCompileSession();
|
|
159
|
+
const partial = session.compile(snapshot, options, 'streaming');
|
|
160
|
+
if (partial.status === 'partial') {
|
|
161
|
+
render(partial.document);
|
|
162
|
+
showTransient(partial.transientDiagnostics ?? []);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const final = session.compile(completedSource, options, 'final');
|
|
166
|
+
if (final.status === 'valid' || final.status === 'recovered') {
|
|
167
|
+
clearTransient();
|
|
168
|
+
render(final.document);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The explicit `phase` of `compile(source, options?, phase?)` and `compileShared(source, options?, phase?)` wins over `options.sourcePhase`. An explicit `final` uses the same final compilation path as an omitted phase and only adds `status`.
|
|
173
|
+
|
|
174
|
+
`LocalCompileScheduler.schedule(source, options?, hint?, phase?)` follows the same phases:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
const scheduler = new LocalCompileScheduler({
|
|
178
|
+
createWorker: () => new Worker(new URL('./compile.worker.ts', import.meta.url), { type: 'module' }),
|
|
179
|
+
onResult: ({ result, sourcePhase }) => applySnapshot(result, sourcePhase),
|
|
180
|
+
delay: 150,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
scheduler.schedule(snapshot, options, undefined, 'streaming');
|
|
184
|
+
scheduler.schedule(completedSource, options, undefined, 'final');
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Streaming snapshots share the scheduler's throttle window (`LOCAL_COMPILE_DELAY_MS`, 150 ms by default) and only the latest queued snapshot is kept; no compilation runs per token.
|
|
188
|
+
- `final` bypasses the debounce and queues immediately. It may wait for an in-flight compile, but the older result cannot be delivered because the phase is part of job identity; monotonic revisions keep later responses from overwriting earlier accepted state.
|
|
189
|
+
- Revisions increase monotonically, and a stale Worker response cannot update the current preview. Streaming jobs never join the `patch-v1` baseline; scheduling a streaming snapshot invalidates the existing baseline, and only a final result can establish a patch baseline.
|
|
190
|
+
- Worker full requests and responses echo `sourcePhase` whenever a phase was declared; phase-less legacy jobs keep the historical wire shape and omit it. A phase on the options object is honored the same way. `LocalCompileOutcome.sourcePhase` reports the result phase. Main-thread fallback uses the same semantics; a custom `fallbackCompile` receives the phase as its third argument.
|
|
191
|
+
- Worker patch retries use `retryFull` with the codes `stale-base`, `options-mismatch`, `invalid-edit` or `phase-mismatch`; the scheduler falls back to one complete request instead of trusting a misaligned patch.
|
|
192
|
+
|
|
193
|
+
Streaming snapshots never read or populate the final block, deferred-index or shared-result caches; a final compile always starts from the existing incremental or full path. Lower-level parser caches keyed by exact source text may still serve both phases, because they are pure functions of that text and options. Streaming jobs may reuse the last result for an identical snapshot, but do not depend on block-level reuse across snapshots.
|
|
194
|
+
|
|
195
|
+
### React hosts
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import { useState } from 'react';
|
|
199
|
+
import type { Diagnostic, LocalSourcePhase } from 'reactive-md';
|
|
200
|
+
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
201
|
+
|
|
202
|
+
export function StreamedArticle({ source, phase }: {
|
|
203
|
+
source: string;
|
|
204
|
+
phase: LocalSourcePhase;
|
|
205
|
+
}) {
|
|
206
|
+
const [transient, setTransient] = useState<Diagnostic[]>([]);
|
|
207
|
+
const [diagnostics, setDiagnostics] = useState<Diagnostic[]>([]);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<>
|
|
211
|
+
<LocalReactiveDocument
|
|
212
|
+
source={source}
|
|
213
|
+
sourcePhase={phase}
|
|
214
|
+
onTransientDiagnostics={setTransient}
|
|
215
|
+
onDiagnostics={setDiagnostics}
|
|
216
|
+
/>
|
|
217
|
+
{transient.length > 0 && <p>{transient.length} provisional issues</p>}
|
|
218
|
+
{phase === 'final' && diagnostics.length > 0 && <p>Compilation failed; see diagnostics.</p>}
|
|
219
|
+
</>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
While streaming, `LocalReactiveDocument` renders with `mode="static"`: controls are read-only, network sessions are not established, and submissions, resets and other component side effects do not start. It still reuses the same compile session and runtime, and ordinary source updates retain compatible reader values and input drafts through the existing migration rules; a phase change does not rebuild the runtime or reset state. `final` restores the host's `mode`, `staticFirst` and full interaction. `onDiagnostics` carries non-transient diagnostics for the current snapshot; provisional issues never enter that channel. `onTransientDiagnostics` reports provisional issues only; if the host received any, finalization calls it once more with an empty array, and a later streaming snapshot without provisional issues retracts the same way. Deterministic failures still show the existing error notice.
|
|
225
|
+
|
|
226
|
+
The host must write each new snapshot to `source` and switch `sourcePhase` back to `final` when generation ends. On cancellation, document switches or unmount, stop submitting and discard old results; the engine validates revisions and phases only and does not manage generation rounds.
|
|
227
|
+
|
|
228
|
+
### Security boundaries
|
|
229
|
+
|
|
230
|
+
Streaming compilation does not change the document security model:
|
|
231
|
+
|
|
232
|
+
- The host owns model transport, credentials, retries and cancellation. ReactiveMD receives text snapshots only; it does not connect to model services or add network requests or code execution for streaming.
|
|
233
|
+
- `streaming` does not enable author HTML, scripts, CSS or other language capabilities; the host still grants them through explicit compile options. Deterministic security, configuration, version and budget errors remain final failures.
|
|
234
|
+
- During streaming, side-effecting components are deferred by static mode so incomplete content cannot submit, subscribe or perform other external actions; full interaction returns on `final`. Hosts still enforce their own permissions, CSP and untrusted-content policies.
|
|
235
|
+
|
|
236
|
+
### Performance expectations
|
|
237
|
+
|
|
238
|
+
Every accepted streaming snapshot compiles the complete source. Regions that cannot be interpreted safely are degraded to literal text through up to six stabilization passes, followed by one whole-source literal compile when damage persists; this path does not promise block-level incremental cost. The scheduler throttles and coalesces snapshots, and `final` queues immediately. Source still respects the 1,000,000-character limit and compile budgets; longer snapshots cost more per compile. Measure input-to-preview latency and compile volume on long documents, then tune the host's submission window accordingly; do not call a compile entry per token. The repository benchmark `npm run bench:streaming` reports, for a 15.5 KB / 227-block document in 64-character chunks, p50 ≈ 15–23 ms and p95 ≈ 33–53 ms per streaming snapshot across runs, exact final equality with one-shot compilation, and about 31 coalesced submissions under a 150 ms window. Treat these numbers as a baseline, not a cross-machine SLO.
|
|
239
|
+
|
|
240
|
+
## Strict parsing and local recovery
|
|
241
|
+
|
|
242
|
+
The `strict` option controls structural recovery in compiler factories, `compileLocal`, editing sessions and Workers. It defaults to `true`; omission and explicit `undefined` use the same default. Other non-boolean values are configuration errors.
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import { createStandardCompiler } from 'reactive-md/compiler/standard';
|
|
246
|
+
|
|
247
|
+
const compiler = createStandardCompiler({ strict: false });
|
|
248
|
+
const result = compiler.compile(`<alert>
|
|
249
|
+
Unfinished content {{ missing }}.
|
|
250
|
+
|
|
251
|
+
## Next section
|
|
252
|
+
|
|
253
|
+
This **Markdown** still renders.
|
|
254
|
+
`);
|
|
255
|
+
|
|
256
|
+
if (result.status === 'recovered') {
|
|
257
|
+
console.log(result.diagnostics, result.recoveries, result.program.nodes);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Loose mode keeps the damaged region as original source text. Components, expressions and declarations inside it stay inert. Compilation resumes at the next reliable boundary without rewriting the source.
|
|
262
|
+
|
|
263
|
+
Complete pairs take priority, including components whose bodies cross headings. A stray closing tag becomes literal text by itself. An outer closing tag can terminate an intact outer container while its unclosed inner fragment becomes text. An unmatched, lexically complete opener can recover before an ATX heading with a preceding blank line in the same Markdown container. Code, comments, raw HTML text and unfinished attribute quotes do not supply heading boundaries. Ordinary paragraphs, blank lines and sibling components are not synchronization points; without a reliable heading, recovery extends to the outer boundary or end of file.
|
|
264
|
+
|
|
265
|
+
Each recovery records `code`, `causeRange`, `affectedRange`, `action` and `boundary`. Ranges are half-open UTF-16 offsets into the original source. Records are sorted and deduplicated.
|
|
266
|
+
|
|
267
|
+
Each finalized recovery also produces at most one warning at `causeRange` with the same stable code: `local.recovery.unclosed`, `local.recovery.mismatch`, `local.recovery.stray-close`, `local.html.repair` or `local.html.literal`. The message states what was repaired or kept as literal text, so recovery is never silent. Line and column use the raw UTF-16 source. Warnings are not emitted per token. The diagnostics budget applies: when it is full, a warning may be omitted while the recovery record remains in `recoveries`. Recovery inserts no error block in the document body.
|
|
268
|
+
|
|
269
|
+
Binding errors, computation cycles, invalid initial values, required component attributes and component shape errors remain errors and fail compilation; recovery does not downgrade them. Configuration, version and budget errors also remain fatal. References outside a literal region to declarations removed inside it remain unknown bindings. A failed result can retain recoveries completed before the failure, their warnings and the separate error that caused failure.
|
|
270
|
+
|
|
271
|
+
### HTML and details
|
|
272
|
+
|
|
273
|
+
Loose mode repairs omitted or mismatched HTML tags within an isolated fragment using parse5. The existing element, attribute and URL policies still apply; loose mode grants no script, CSS or extended HTML capability. A repaired fragment yields one `local.html.repair` warning. A mixed RMD fragment becomes literal text with one `local.html.literal` warning when ownership and source ranges cannot be preserved. Synthetic nodes carry `synthetic` and `syntheticBoundary` metadata.
|
|
274
|
+
|
|
275
|
+
Both modes support a details element without blank lines:
|
|
276
|
+
|
|
277
|
+
```html
|
|
278
|
+
<details>
|
|
279
|
+
<summary>1145</summary>
|
|
280
|
+
1145
|
|
281
|
+
</details>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
It renders as a single disclosure in an accordion with no group title. The trigger is `1145`, the panel contains `1145`, and it starts collapsed; click, Enter and Space toggle it. Boolean `open` starts it expanded, and static output exposes the body. Rich summaries and nested details retain their content.
|
|
285
|
+
|
|
286
|
+
### Results and hosts
|
|
287
|
+
|
|
288
|
+
Factory success results include `status: 'valid' | 'recovered'`, a deeply frozen `program`, diagnostics, recoveries and optional-check coverage in `checks`. A `valid` success has no recovery warning. A `recovered` success includes the program and one warning per recovery. Failures use `status: 'failed'` and contain no program; they may retain recoveries completed before the failure and their warnings. Unrecoverable semantic, type, binding, options, version and budget errors remain errors. The `ok` and `document` aliases remain available; `document` is a separate plain-data copy.
|
|
289
|
+
|
|
290
|
+
`compileLocal` keeps its existing result type and adds `recoveries` only when present. Strict results keep their existing field shape. Export options preserve the selected mode so standalone replay compiles the same source with that mode.
|
|
291
|
+
|
|
292
|
+
Loose editing sessions use the full reference path to avoid reusing blocks across recovery boundaries. Strict mode keeps its existing optimizations. Configuration identity includes strict mode and recovery strategy version 2. Demo and editor defaults remain strict.
|
|
293
|
+
|
|
294
|
+
## Core API
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { compileLocal, createLocalRuntime } from 'reactive-md';
|
|
298
|
+
|
|
299
|
+
const result = compileLocal(source);
|
|
300
|
+
if (result.ok) {
|
|
301
|
+
const runtime = createLocalRuntime(result.document, {
|
|
302
|
+
externalValues: { exchangeRate: 7.2 },
|
|
303
|
+
});
|
|
304
|
+
const unsubscribe = runtime.subscribe(() => {
|
|
305
|
+
console.log(runtime.snapshot());
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
console.log(runtime.evaluate('people * 100'));
|
|
309
|
+
console.log(runtime.text('People: {{ people }}'));
|
|
310
|
+
runtime.setExternalValues({ exchangeRate: 7.3 });
|
|
311
|
+
|
|
312
|
+
unsubscribe();
|
|
313
|
+
runtime.dispose();
|
|
314
|
+
} else {
|
|
315
|
+
console.log(result.diagnostics);
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### `compileLocal(source: string, options?: LocalCompileOptions)`
|
|
320
|
+
|
|
321
|
+
`source` is the `.reactive.md` source. The return value is a union:
|
|
322
|
+
|
|
323
|
+
- Success: `{ ok: true; document: LocalDocument; diagnostics: Diagnostic[] }`
|
|
324
|
+
- Failure: `{ ok: false; diagnostics: Diagnostic[] }`
|
|
325
|
+
|
|
326
|
+
Syntax problems are returned through diagnostics; the current build accepts only `local-draft-3`. An explicit older revision directive is rejected with a `local.version.*` diagnostic; an unversioned source keeps current-revision behavior. The source limit is 1,000,000 characters. `document` is a current runtime object and should not be treated as a persistence format.
|
|
327
|
+
|
|
328
|
+
Hosts can set the syntax node budget for a single compilation:
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
import { compileLocal, type LocalCompileOptions } from 'reactive-md';
|
|
332
|
+
|
|
333
|
+
const options: LocalCompileOptions = {
|
|
334
|
+
limits: { maxSyntaxNodes: 50_000 },
|
|
335
|
+
};
|
|
336
|
+
const result = compileLocal(source, options);
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
`limits.maxSyntaxNodes` defaults to 10,000 and accepts integers from `1` to `Number.MAX_SAFE_INTEGER`. Omitting the options, `limits` or `maxSyntaxNodes` uses the default. `0`, negative numbers, decimals, `NaN`, infinity, strings, `null` and malformed option containers return a `local.options.invalid` diagnostic; exceeding the valid node budget returns a `local.budget` diagnostic.
|
|
340
|
+
|
|
341
|
+
The budget counts `LocalNode` instances created cumulatively during parsing, including Markdown text, paragraphs, lists, tables, interpolations, components and some intermediate nodes, so it may exceed the final syntax tree node count. The setting affects only this compilation, leaves the options object untouched, and keeps other resource limits such as arrays independent. The budget comes from the host; document content cannot raise it on its own.
|
|
342
|
+
|
|
343
|
+
To use a custom budget in React, call `compileLocal` first and pass the compiled document and runtime to `LocalDocumentView`. `LocalReactiveDocument` and the Playground compilation thread use the default budget. After raising the node budget, hosts should measure memory and preview rendering time with their actual documents.
|
|
344
|
+
|
|
345
|
+
#### Next.js Server Components
|
|
346
|
+
|
|
347
|
+
`compileLocal` returns plain data at every depth, including `document.dependencies`, node `attrs`, bindings and diagnostics. Records use `Object.prototype`; arrays use `Array.prototype`. Internal dictionaries may still use null prototypes. Existing frozen metadata and `undefined` fields are preserved.
|
|
348
|
+
|
|
349
|
+
Compile on the server, check `result.ok`, then pass `result.document` directly to a Client Component as a prop. A JSON round trip is unnecessary. This meets React's [plain-object requirement for serializable props](https://react.dev/reference/rsc/use-client#serializable-types-returned-by-server-components). In the Client Component, create and dispose `createLocalRuntime(document)` and render `LocalDocumentView` with that runtime. Runtime instances and host callbacks stay on the client; the plain-data guarantee applies to compiler output.
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
// Server Component; ClientDocument is the host's 'use client' wrapper.
|
|
353
|
+
import { compileLocal } from 'reactive-md';
|
|
354
|
+
import ClientDocument from './ClientDocument';
|
|
355
|
+
|
|
356
|
+
export default function Page() {
|
|
357
|
+
const result = compileLocal('<counter bind="n" label="Count" initial="2">');
|
|
358
|
+
if (!result.ok) throw new Error('Compilation failed');
|
|
359
|
+
return <ClientDocument document={result.document} />;
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Host components
|
|
364
|
+
|
|
365
|
+
A host can register components for one compilation without changing the author syntax revision. A schema declares a `form` and may declare a scalar binding:
|
|
366
|
+
|
|
367
|
+
```ts
|
|
368
|
+
import { compileLocal, type LocalHostComponentSchema } from 'reactive-md';
|
|
369
|
+
|
|
370
|
+
const hostComponents: LocalHostComponentSchema[] = [
|
|
371
|
+
{
|
|
372
|
+
name: 'host-weather',
|
|
373
|
+
form: 'leaf',
|
|
374
|
+
props: {
|
|
375
|
+
kind: { kind: 'enum', required: true, enum: ['weather'] },
|
|
376
|
+
ref: { kind: 'string', required: true, pattern: '^[a-z-]+$' },
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
name: 'host-rating',
|
|
381
|
+
form: 'leaf',
|
|
382
|
+
props: { label: { kind: 'string' } },
|
|
383
|
+
binding: { kind: 'number', min: 0, max: 5, step: 1 },
|
|
384
|
+
},
|
|
385
|
+
];
|
|
386
|
+
const result = compileLocal(source, { hostComponents });
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Without `hostComponents`, those tags remain unknown and fall back to source. Names must be unique lowercase kebab-case and cannot reuse one of the 49 author tag names, a P0 HTML tag name or `theme`; at most 32 schemas are accepted. `pattern` accepts only a linear-time-safe regex subset (no backreferences, lookarounds, named groups, nested quantifiers or quantified alternation). An invalid schema returns `local.options.invalid`, and an invalid authored attribute returns `local.host.attribute`; a valid host node counts as one syntax node.
|
|
390
|
+
|
|
391
|
+
`form` is `leaf`, `inline` or `container`. Inline and container tags are paired; their body is compiled as normal Markdown and ReactiveMD content, and the renderer receives `ctx.render()` for children. `binding` is optional and accepts `string`, `number` or `boolean`, with static `min`, `max`, `step`, `options`, `initialRule` and `exclusive`. A bound host component implicitly accepts `bind`, `initial` and dynamic `disabled`, and shares the built-in binding families. For example, this rating control and the built-in number share one value:
|
|
392
|
+
|
|
393
|
+
```markdown
|
|
394
|
+
<host-rating bind="rating" label="Course rating">
|
|
395
|
+
<number bind="rating" label="Numeric rating" min="0" max="5" step="1">
|
|
396
|
+
|
|
397
|
+
Current rating: {{ rating }}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
The host renderer receives `(node, data, ctx)`. `ctx` extends the render context with `value`, a validating `setValue(value)`, `disabled`, `resetToken`, resolved `props` and `report(diagnostics)`. `setValue` goes through the runtime, so shared constraints and reset behavior still apply. Pass `hostData`, keyed `${kind}:${ref}`, only for components that declare those props; a binding-only or container host does not need host data. A missing renderer, missing declared data or a throwing renderer renders a visible placeholder instead of failing the document. `mode="static"` uses the same dispatch and passes `ctx.mode` to the renderer. Host schemas are plain data and cross the worker boundary; renderers never do.
|
|
401
|
+
|
|
402
|
+
If compilation reports `document.requiresRuntime === false`, you can pass the same document, `hostData` and `hostRenderer` to the runtime-free static view or its SSR entry. See [static rendering and async host data](../reference/public-api-en.md#embedding-and-multiple-documents).
|
|
403
|
+
|
|
404
|
+
### External data
|
|
405
|
+
|
|
406
|
+
`<external name="exchangeRate" type="number">` declares a read-only value for expressions and computations. Pass initial values to `createLocalRuntime(document, { externalValues })` or the `externalValues` prop. `runtime.setExternalValues(partial)` validates every entry, commits once and increments the revision once; unknown names, wrong types, non-finite numbers and budget overruns return diagnostics and keep the previous state. Equal values do not increment the revision. `getExternal(name)` and `getExternalValues()` are read-only; externals never appear in `getParameters()`, `parameterNames()` or a state file.
|
|
407
|
+
|
|
408
|
+
A missing external makes only expressions that read it fail locally; other content keeps updating, and those expressions recover when the value arrives. Missing values are never coerced to `0`, `false` or an empty string. Static export and SSR use the same rules; the export does not fetch or embed host data.
|
|
409
|
+
|
|
410
|
+
### Version inspection and migration
|
|
411
|
+
|
|
412
|
+
Three pure functions inspect and migrate source without creating a runtime. They are exported from `reactive-md`:
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
import {
|
|
416
|
+
checkLocalUpgrade,
|
|
417
|
+
inspectLocalSourceVersion,
|
|
418
|
+
migrateLocalSource,
|
|
419
|
+
} from 'reactive-md';
|
|
420
|
+
|
|
421
|
+
const info = inspectLocalSourceVersion(source);
|
|
422
|
+
const check = checkLocalUpgrade(source, { fromVersion: 'local-draft-1' });
|
|
423
|
+
const migrated = migrateLocalSource(source, { fromVersion: 'local-draft-1' });
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
`inspectLocalSourceVersion` reports the declared and effective revision, whether this compiler supports it, the directive range and version diagnostics. `checkLocalUpgrade` reports `ok`, `fromVersion`, `toVersion`, `needsMigration` and diagnostics. `migrateLocalSource` adds `source`, `changed` and precise `edits`.
|
|
427
|
+
|
|
428
|
+
`LocalUpgradeOptions` supplies `fromVersion` and `allowSemanticChanges`. An unversioned historical document needs `fromVersion: 'local-draft-1'`. An explicit `fromVersion` that disagrees with the declaration is rejected. `local-draft-1`, `local-draft-2` and `local-draft-3` are accepted migration sources.
|
|
429
|
+
|
|
430
|
+
Migration changes only the metadata directive, preserves body bytes, BOM and CRLF, and is idempotent. It blocks reserved bindings, newly recognized tags, compile errors and text-control length changes before producing output. See [Source revisions and migration](../compatibility/source-versioning-en.md) for the exact checks and the CLI.
|
|
431
|
+
|
|
432
|
+
### `createLocalRuntime(document: LocalDocument, options?: LocalRuntimeOptions)`
|
|
433
|
+
|
|
434
|
+
Named read-only values are described by `LocalComputation` in the optional `document.computations` record. `bindings` and `initialState` remain writable controls; `snapshot().state` also includes successful calculated values for its revision. Read a named value with `evaluate(name)` to preserve expression errors; failed values are absent from snapshots. See [calculation and error semantics](../reference/local-interaction-syntax-en.md).
|
|
435
|
+
|
|
436
|
+
`options.externalValues` seeds declared `<external>` values; invalid entries are treated as unavailable and can be corrected through `setExternalValues`. The runtime creates an independent in-memory instance. Throws if `document` is not a local mode document, if initial values exceed budgets, or if the structure is invalid. Each instance has independent state; the runtime never stores or transmits state by itself.
|
|
437
|
+
|
|
438
|
+
### `LocalRuntime`
|
|
439
|
+
|
|
440
|
+
`validate(): Diagnostic[]` reads advisory cross-field failures for the current revision. Dynamic `min`/`max`/`required` failures are enforced on writes and displayed on the control; `validate()` keeps its existing meaning. It preserves editability and returns copies of cached diagnostics. `document.validations?: LocalValidation[]` holds the serializable rule declarations. Numeric collections add `number[]` to `LocalValue` and `number-array` to `LocalValueKind`; existing writable selection controls keep string arrays. See [constraints and collections](../reference/local-interaction-syntax-en.md).
|
|
441
|
+
|
|
442
|
+
| Member | Parameters | Returns | Behavior |
|
|
443
|
+
| --- | --- | --- | --- |
|
|
444
|
+
| `document` | — | `LocalDocument` | The compiled result used at creation |
|
|
445
|
+
| `snapshot()` | — | `{ revision: number; state: Readonly<Record<string, LocalValue>> }` | Returns the same snapshot object when state is unchanged; state is frozen and includes available external values; use `getParameters()` for writable parameters only |
|
|
446
|
+
| `get(node, slot?)` | `LocalNode`, optional slot | `LocalValue` | Reads the value bound to the control; `slot` selects `start`/`end` or `x`/`y`; returns `null` for no binding or an unknown node; arrays are copies |
|
|
447
|
+
| `set(node, value, slot?)` | `LocalNode`, `LocalValue`, optional slot | `Diagnostic[]` | Validates all shared controls; returns an empty array and commits once on success; does not increment revision on failure |
|
|
448
|
+
| `setMany(node, values)` | `LocalNode`, slot values | `Diagnostic[]` | Atomically writes several slots of one multi-slot control; invalid batches leave state and revision unchanged |
|
|
449
|
+
| `validate()` | — | `Diagnostic[]` | Returns copies of the current advisory validation failures; does not change or reject state |
|
|
450
|
+
| `parameterNames()` | — | `readonly string[]` | Sorted public binding names; internal `@` bindings excluded |
|
|
451
|
+
| `getParameter(name)` | `string` | `LocalValue \| undefined` | Value of a public binding; `undefined` for unknown or internal names; arrays are copies |
|
|
452
|
+
| `getParameters()` | — | `Readonly<Record<string, LocalValue>>` | Frozen public-only snapshot; internal `@` keys are never included |
|
|
453
|
+
| `setParameter(name, value)` | `string`, `LocalValue` | `Diagnostic[]` | Validates every control sharing the binding; commits once; state unchanged on failure |
|
|
454
|
+
| `setParameters(values)` | `Readonly<Record<string, LocalValue>>` | `Diagnostic[]` | Validates every public value and multi-slot relation, then commits all or nothing; unknown or internal names return `local.runtime.parameter`; invalid values return `local.runtime.value`; unchanged values do not bump the revision |
|
|
455
|
+
| `getExternal(name)` | `string` | `LocalValue \| undefined` | Value of a declared external, or `undefined` when undeclared or unavailable; arrays are copies |
|
|
456
|
+
| `getExternalValues()` | — | `Readonly<Record<string, LocalValue>>` | Frozen record of the currently available external values |
|
|
457
|
+
| `setExternalValues(values)` | `Readonly<Record<string, LocalValue>>` | `Diagnostic[]` | Atomically validates partial external updates; commits and notifies once; unknown names, wrong types and budgets return `local.runtime.external` without changing state or revision |
|
|
458
|
+
| `evaluate(expression)` | `string` | `LocalValue` | Evaluates with current state; throws `LocalExpressionError` on failure; arrays are copies |
|
|
459
|
+
| `text(template)` | `string` | `string` | Renders text containing `{{ }}`; throws on failure |
|
|
460
|
+
| `reset(node)` | `LocalNode` | `void` | Restores parameters and component state within the node's subtree in one commit, notifying once |
|
|
461
|
+
| `resetToken(node)` | `LocalNode` | `number` | Incrementing token for a control's internal state, so renderers can detect resets |
|
|
462
|
+
| `subscribe(listener)` | `() => void` | `() => void` | Calls the listener on every commit; returns an unsubscribe function |
|
|
463
|
+
| `dispose()` | — | `void` | Idempotent; clears subscriptions, expression caches and reset tokens; other members throw afterwards |
|
|
464
|
+
|
|
465
|
+
`set` relies on the controls registered in the document; node metadata passed by the caller cannot loosen constraints. `disabled` and conditional hiding are for interactive display only; the host still enforces business permissions and server-side data validation.
|
|
466
|
+
|
|
467
|
+
### Parameters by name
|
|
468
|
+
|
|
469
|
+
Name-based access is for hosts that keep their own parameter values, such as a form or a URL. Only public bindings are visible: `parameterNames()` returns sorted names, `getParameter(name)` returns `undefined` for an unknown or internal name, and `getParameters()` returns a frozen public-only record. Anonymous `@` bindings never appear, and arrays returned by `getParameter` are copies.
|
|
470
|
+
|
|
471
|
+
Writes validate every control sharing the binding, including multi-slot relations, and commit once. A failed call returns diagnostics and leaves the state unchanged; unchanged values do not increase the revision. Unknown or internal names return `local.runtime.parameter`; invalid values return `local.runtime.value`.
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
const names = runtime.parameterNames(); // e.g. ['annual', 'people']
|
|
475
|
+
const people = runtime.getParameter('people'); // 2
|
|
476
|
+
|
|
477
|
+
runtime.setParameter('people', 7);
|
|
478
|
+
const diagnostics = runtime.setParameters({ people: 8, annual: true });
|
|
479
|
+
if (diagnostics.length) {
|
|
480
|
+
// Nothing was written.
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### State export and import
|
|
485
|
+
|
|
486
|
+
`exportLocalState(runtime, generator?)` writes the public parameters to a `reactive-md-state/v1` file. The file carries the document identity in `sourceDigest`, the language revision in `syntax`, and an optional generator name and version. Anonymous `@` bindings from `snapshot().state` are excluded, so a raw snapshot should not be stored as a long-term protocol. The [shareable export guide](shareable-export-en.md#starting-values-and-state-files) documents the format used by the CLI and standalone runtime.
|
|
487
|
+
|
|
488
|
+
`importLocalState(runtime, input, options?)` accepts serialized JSON or an already parsed file. It parses the payload, checks the source digest, syntax revision and exact public parameter set, validates every value, and applies the result; a failed import returns diagnostics and leaves the runtime unchanged. `options.maxLength` limits the serialized payload in bytes and defaults to 1 MiB.
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
import { exportLocalState, importLocalState } from 'reactive-md';
|
|
492
|
+
|
|
493
|
+
const file = exportLocalState(runtime, { name: 'my-host', version: '1.0.0' });
|
|
494
|
+
const saved = JSON.stringify(file);
|
|
495
|
+
|
|
496
|
+
const diagnostics = importLocalState(runtime, saved);
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
The lower-level `createLocalStateFile`, `parseLocalState`, `resolveLocalState`, `applyLocalState` and `serializeLocalState` remain available. Use `resolveLocalState(document, input)` for validation that does not touch a live runtime.
|
|
500
|
+
|
|
501
|
+
### Keeping values when source changes
|
|
502
|
+
|
|
503
|
+
`LocalReactiveDocument` reuses its runtime and migrates compatible values on ordinary source updates. Hosts that manage the runtime themselves or switch between independent documents can plan the migration explicitly:
|
|
504
|
+
|
|
505
|
+
```ts
|
|
506
|
+
import {
|
|
507
|
+
applyLocalStateRetention,
|
|
508
|
+
compileLocal,
|
|
509
|
+
createLocalRuntime,
|
|
510
|
+
planLocalStateRetention,
|
|
511
|
+
} from 'reactive-md';
|
|
512
|
+
|
|
513
|
+
const next = compileLocal(nextSource);
|
|
514
|
+
if (!next.ok) throw new Error('Fix the compile diagnostics first');
|
|
515
|
+
|
|
516
|
+
const plan = planLocalStateRetention({
|
|
517
|
+
previous: previousRuntime.document,
|
|
518
|
+
state: previousRuntime.snapshot().state,
|
|
519
|
+
next: next.document,
|
|
520
|
+
});
|
|
521
|
+
const runtime = createLocalRuntime(next.document);
|
|
522
|
+
const { retained, dropped, diagnostics } = applyLocalStateRetention(runtime, plan);
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
`planLocalStateRetention` returns the values to reuse, the retained parameter names, and dropped entries with a name and reason. A parameter is retained only when:
|
|
526
|
+
|
|
527
|
+
- its name exists as a public binding in both documents;
|
|
528
|
+
- both bindings are safely retainable: the binding has controls, every control is bound to the name, and no control is a timer or checklist;
|
|
529
|
+
- its type and initial definition are unchanged, including the effective initial value and any explicit `initial` attribute values.
|
|
530
|
+
|
|
531
|
+
Anonymous `@` bindings, removed or renamed parameters, timers and positional checklists are dropped. Each retained value is revalidated against the new document's constraints; a rejected value falls back to the new initial value and is reported as `invalid`. Drop reasons are `internal`, `unknown`, `unretainable`, `type`, `initial` and `invalid`.
|
|
532
|
+
|
|
533
|
+
`applyLocalStateRetention` first tries one atomic write so multi-slot relations stay consistent, then falls back to writing parameters individually, so one stale value does not block the others. `diagnostics` describe values rejected by the new document.
|
|
534
|
+
|
|
535
|
+
### Background compilation in a Worker
|
|
536
|
+
|
|
537
|
+
Worker support is host-provided: create the worker entry with your bundler and keep `compileLocal` as the fallback. A copyable browser example is in [Standalone integration examples](../../examples/integration/README.md).
|
|
538
|
+
|
|
539
|
+
```ts
|
|
540
|
+
// compile.worker.ts
|
|
541
|
+
import { startLocalCompileWorker } from 'reactive-md';
|
|
542
|
+
|
|
543
|
+
startLocalCompileWorker();
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
`startLocalCompileWorker()` installs the handler on the current worker global. Pass a scope explicitly only when testing or wrapping another message host.
|
|
547
|
+
|
|
548
|
+
```ts
|
|
549
|
+
// main.ts
|
|
550
|
+
import { LocalCompileScheduler } from 'reactive-md';
|
|
551
|
+
|
|
552
|
+
const scheduler = new LocalCompileScheduler({
|
|
553
|
+
createWorker: () => new Worker(new URL('./compile.worker.ts', import.meta.url), { type: 'module' }),
|
|
554
|
+
onResult: ({ source, result, mode }) => render(source, result, mode),
|
|
555
|
+
onPendingChange: (pending) => showSpinner(pending),
|
|
556
|
+
onModeChange: (mode, detail) => console.log('compile mode', mode, detail),
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
scheduler.schedule(source);
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
`LocalCompileScheduler` coalesces edits for `LOCAL_COMPILE_DELAY_MS` (150 ms; override with `delay`), keeps one compile in flight plus only the latest queued source, and discards results that a newer edit has superseded. When no worker is available, or after a worker error, it compiles on the main thread with `fallbackCompile`; the default is an internal session-backed compile with the same results as `compileLocal`, without cross-call reuse. A worker failure switches permanently to this fallback and reports it through `onModeChange`. Failures thrown by the worker or during fallback compilation use the `local.worker.compile` diagnostic code. Use `schedule(source, options?, hint?, phase?)` for streaming snapshots; `final` bypasses the debounce. See [Streaming source compilation](#streaming-source-compilation).
|
|
563
|
+
|
|
564
|
+
`onResult` receives `LocalCompileOutcome` (`source`, `result`, `duration`, `mode`, `sourcePhase`), `onPendingChange` reports whether work is queued or in flight, and `dispose()` stops the timer, terminates the worker and suppresses later callbacks.
|
|
565
|
+
|
|
566
|
+
### Other core exports
|
|
567
|
+
|
|
568
|
+
- `LOCAL_SYNTAX_VERSION`: currently the literal `'local-draft-3'`. Use it to record the syntax revision a document uses.
|
|
569
|
+
- `compileExpression(source: string)`: returns an object with `source`, `dependencies`, `evaluate(env)` and `inferType(env)`; throws `LocalExpressionError` on failure.
|
|
570
|
+
- `LocalExpressionError`: contains `code` and `offset`.
|
|
571
|
+
- `compileLatex(source: string)`: returns an object with `source`, `dependencies` and `evaluate(x, env, budget?)`; throws an error with `code` and `offset` on failure.
|
|
572
|
+
- `samplePlot(expression, env, min, max, samples = 200, sharedBudget?)`: returns `{ points: { x: number; y: number | null }[]; endpoint: number | null }`; throws when the range, sample count or budget is invalid.
|
|
573
|
+
- State files: `exportLocalState`, `importLocalState`, `createLocalStateFile`, `parseLocalState`, `resolveLocalState`, `applyLocalState` and `serializeLocalState`; `LOCAL_STATE_FORMAT` is `'reactive-md-state/v1'`.
|
|
574
|
+
- Source revisions: `inspectLocalSourceVersion`, `checkLocalUpgrade` and `migrateLocalSource`; `LocalUpgradeOptions` configures the source revision and semantic-change allowance.
|
|
575
|
+
- Retention: `planLocalStateRetention` and `applyLocalStateRetention`.
|
|
576
|
+
- Background compilation: `LocalCompileScheduler`, `LOCAL_COMPILE_DELAY_MS` and `startLocalCompileWorker`.
|
|
577
|
+
- Streaming phases: `LocalSourcePhase`, `LocalCompileStatus`; the `status` and `transientDiagnostics` fields on explicit-phase results.
|
|
578
|
+
- Type exports: `Diagnostic`, `SourceRange`, `LocalValue`, `LocalValueKind`, `LocalNode`, `LocalBinding`, `LocalComputation`, `LocalValidation`, `LocalDocument`, `LocalCompileLimits`, `LocalCompileOptions`, `LocalCompileResult`, `LocalSourcePhase`, `LocalCompileStatus`, `LocalHostPropKind`, `LocalHostPropSchema`, `LocalHostComponentForm`, `LocalHostBindingSchema`, `LocalHostComponentSchema`, `LocalExternal`, `LocalDynamicConstraint`, `LocalDynamicConstraints`, `LocalRuntimeOptions`, `LocalUpgradeOptions`, `LocalRuntime`, `LocalSnapshot`, `LocalStateFile`, `LocalStateGenerator`, `LocalStateParseResult`, `LocalStateResolution`, `LocalRetainedState`, `LocalStateRetentionReason`, `LocalStateRetentionDrop`, `LocalStateRetentionInput`, `LocalStateRetentionResult`, `LocalCompileWorker`, `LocalCompileWorkerScope`, `LocalCompileRequest`, `LocalCompileResponse`, `LocalCompileOutcome`, `LocalCompileMode`, `LocalCompileSchedulerOptions`.
|
|
579
|
+
|
|
580
|
+
`compileExpression`, `compileLatex` and `samplePlot` are lower-level utilities with the same stability level as the core API; usually only `compileLocal` and `createLocalRuntime` are needed.
|
|
581
|
+
|
|
582
|
+
## Diagnostics
|
|
583
|
+
|
|
584
|
+
The fields and stability levels of `Diagnostic` are described in the diagnostics contract in [Versions and compatibility](../compatibility/compatibility-en.md). Key points: `line`, `column` and `range` are for programmatic location; `code` supports coarse classification. Existing diagnostic codes keep their meaning within one 0.x minor series, and new codes may be added. Removal, renaming or a change of meaning requires a new minor version and migration notes. `message` is display text and should not be parsed.
|
|
585
|
+
|
|
586
|
+
`onDiagnostics` receives compile diagnostics when the compilation result changes, and runtime diagnostics when control writes are rejected. Documents with compile errors do not activate interaction; runtime local errors replace only the corresponding content.
|
|
587
|
+
|
|
588
|
+
## State, instances and cleanup
|
|
589
|
+
|
|
590
|
+
- `LocalReactiveDocument` recompiles on `source` changes and adopts the new document in its existing runtime, migrating compatible values; host option changes that affect compilation semantics or an incompatible document create a new runtime. React StrictMode is supported.
|
|
591
|
+
- When managing the lifecycle yourself, render with `<LocalDocumentView document={result.document} runtime={runtime} />` and call `runtime.dispose()` on unmount.
|
|
592
|
+
- `subscribe()` returns an unsubscribe function. `dispose()` clears remaining subscriptions; calling other runtime methods afterwards throws.
|
|
593
|
+
- `snapshot()` returns the same object until state changes, which is useful for external store subscriptions. `reset(panelNode)` commits once for the panel subtree, and subscribers receive one notification; hidden controls inside the panel are also within reset scope.
|
|
594
|
+
- Document state lives only in memory; the runtime never writes storage, cookies or the network. Refreshing or remounting starts from initial values; a source change reuses the runtime and migrates values that still satisfy the new document's contracts. Persistence is an explicit host action through `exportLocalState` and `importLocalState`; the [retention helpers](#keeping-values-when-source-changes) serve hosts that manage the runtime themselves or switch between independent documents.
|
|
595
|
+
- Hidden regions keep parameters, tab selection and checklist state; timers in hidden regions pause and stay paused when shown again until the reader starts them. Disposing an instance releases timers and subscriptions.
|
|
596
|
+
|
|
597
|
+
## Image and link policy
|
|
598
|
+
|
|
599
|
+
Images are not loaded by default, including relative-path images, so documents do not automatically request host APIs or external sites. Hosts can explicitly allow image sources through `urlPolicy`; both `LocalReactiveDocument` and `LocalDocumentView` accept this prop. Links keep safe protocol checks by default.
|
|
600
|
+
|
|
601
|
+
```tsx
|
|
602
|
+
import type { LocalUrlPolicy } from 'reactive-md/react';
|
|
603
|
+
|
|
604
|
+
const urlPolicy: LocalUrlPolicy = (raw, kind) => {
|
|
605
|
+
if (kind === 'link') return true;
|
|
606
|
+
try {
|
|
607
|
+
const url = new URL(raw);
|
|
608
|
+
return url.protocol === 'https:' && url.origin === 'https://images.example.com';
|
|
609
|
+
} catch {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
<LocalReactiveDocument source={source} urlPolicy={urlPolicy} />;
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
| Target | Without a policy | With a policy |
|
|
618
|
+
| --- | --- | --- |
|
|
619
|
+
| Images | All rejected, including relative addresses | Protocol-bearing addresses are checked first and only HTTP(S) is allowed; relative addresses are decided by the policy |
|
|
620
|
+
| Links | Relative addresses and `http`, `https`, `mailto`, `tel` allowed | Decided by the policy after protocol checks; external HTTP(S) links get `_blank` and `noopener noreferrer` |
|
|
621
|
+
|
|
622
|
+
The policy receives the raw URL with leading and trailing whitespace removed, and `'image' | 'link'`. If the policy throws, the address is rejected. The renderer always checks the protocol first; even if the policy allows it, `javascript:` or dangerous `data:` addresses cannot be used. Images allowed to load use `referrerPolicy="no-referrer"`; same-origin requests may still carry cookies, so image allowlists should avoid business API paths.
|
|
623
|
+
|
|
624
|
+
`urlPolicy` controls only rendered links and images; it is not server-side authorization or a sandbox. Hosts still need to handle CSP, network egress and isolation policies for untrusted authors.
|
|
625
|
+
|
|
626
|
+
## Theme and style scoping
|
|
627
|
+
|
|
628
|
+
`reactive-md/styles.css` is a global stylesheet, not isolated through Shadow DOM or CSS Modules. Hosts should import it explicitly once; the `reactive-md/react` library build extracts styles into this file and does not inject them automatically when importing JavaScript.
|
|
629
|
+
|
|
630
|
+
- Style selectors are mainly `.md-document`, `.local-document` and `.md-*`, `.local-*` class names. The document root rendered by components is `.md-document.local-document`.
|
|
631
|
+
- Theme variables are declared on `.md-document` and `.reactive-md-theme`, including `--ink`, `--surface`, `--line`, `--blue`, `--teal`, `--danger`, `--radius-*` and font variables. Override them after the library styles with rules such as `.my-article .md-document { --blue: #245c98; }`; the document root carries default values, so setting variables only on an ancestor container will not override same-name values on the root.
|
|
632
|
+
- Documents may start with `<theme name="default">`; omission selects `default`. Register custom themes through `themes`; see the [theme protocol](../reference/theme-protocol-en.md).
|
|
633
|
+
- `colorScheme` forces light or dark mode. The default `auto` reads the nearest ancestor's `data-color-scheme` or legacy `data-theme`, then the system preference. Each document exposes independent `data-rmd-theme` and resolved `data-color-scheme` attributes.
|
|
634
|
+
- Documents default to `max-width: 720px` and are horizontally centered. To fill the host container, override the width and margins of `.md-document` within your own scope.
|
|
635
|
+
- Prefer public variables for theme styling. Component outer `.md-*` and `.local-*` classes and semantic state attributes are theme hooks; internal node ordering is not an extension API. See the theme protocol for compatibility requirements.
|
|
636
|
+
- Neither React component accepts `className` or `style`. For local overrides, scope them with the host's own wrapper element.
|
|
637
|
+
|
|
638
|
+
## Resource limits
|
|
639
|
+
|
|
640
|
+
A single string is limited to 100,000 characters, an array to 10,000 items, and the total string length within an array to 100,000 characters. Email validation uses a length-limited linear check. The runtime rejects writes over a limit and keeps the last valid state.
|
|
641
|
+
|
|
642
|
+
A single document source is limited to 1,000,000 characters. There are at most 100 diagnostics, and a single message is at most 2,000 characters.
|
|
643
|
+
|
|
644
|
+
Each plot component has at most 16 curves; the whole document requests at most 20,000 curve sample points, including hidden regions. Plotting computation is also limited by a shared execution budget of 2,000,000 steps. A document has at most 100 validation rules. Generated `data-table` rows, columns and text have per-table and whole-document budgets described in the [syntax specification](../reference/local-interaction-syntax-en.md). Documents over a limit receive diagnostics; expression and math rendering also have their own depth and token budgets.
|
|
645
|
+
|
|
646
|
+
These limits bound the work for a single document; they do not replace host control over request size, concurrency and execution time. See the [security policy](../../SECURITY.md) for the full threat boundary.
|
|
647
|
+
|
|
648
|
+
## Version pinning and upgrades
|
|
649
|
+
|
|
650
|
+
- During 0.x, pin the exact package version and commit the lockfile. `^0.3.0` allows only patch versions, but production integrations should still pin the version or the tarball SHA256.
|
|
651
|
+
- Use one package version for both the core and React entries; do not mix different versions of `reactive-md` and `reactive-md/react`.
|
|
652
|
+
- Record `LOCAL_SYNTAX_VERSION` in application configuration or document metadata, alongside the persisted `.reactive.md` source. Migrate according to [Versions and compatibility](../compatibility/compatibility-en.md) when the syntax revision changes.
|
|
653
|
+
- After upgrading, recompile your own documents and check `result.diagnostics`, rendered output and browser interactions. Do not depend on the text of diagnostic `message`.
|
|
654
|
+
|
|
655
|
+
## Features not provided
|
|
656
|
+
|
|
657
|
+
ReactiveMD supports P0 HTML and independent author capabilities. See [HTML compatibility](../reference/html-compatibility-en.md). Automatic state persistence, unrestricted network/storage calls, Vue, React 18 and CommonJS remain outside the current API. Hosts declare read-only values and invoke state export/import explicitly.
|
|
658
|
+
|
|
659
|
+
The source [extension SDK](extension-sdk-en.md) provides custom component and theme package registration since `reactive-md@0.8.0`; follow the [component plugin development guide](../development/component-development-en.md). On ordinary source edits, `LocalReactiveDocument` tries to adopt the new document and retain compatible bindings. Use a new React `key` for independent documents, or manage documents and runtimes in the host.
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
See the [syntax specification](../reference/local-interaction-syntax-en.md) for the component tags, color options and slot state.
|
|
663
|
+
|
|
664
|
+
0.5.3 adds compile-option-aware authoring and explicit screen/print styles. See [0.5.3 host integration](../releases/release-0.5.3-en.md). 0.6.0 makes `compileLocal` return plain data that can cross a React Server Components boundary; see the [0.6.0 release notes](../releases/release-0.6.0-en.md).
|