reactive-md 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-ch.md +66 -0
- package/CHANGELOG.md +66 -0
- package/CONTRIBUTING-ch.md +6 -62
- package/CONTRIBUTING.md +5 -63
- package/README-ch.md +232 -67
- package/README-en.md +209 -71
- package/README.md +209 -71
- package/SECURITY-ch.md +3 -1
- package/SECURITY.md +3 -1
- package/THIRD_PARTY_NOTICES.md +1909 -87
- package/cli/args.mjs +33 -1
- package/cli/build.mjs +62 -1
- package/cli/check.mjs +444 -0
- package/cli/help.mjs +181 -3
- package/cli/init.mjs +1577 -0
- package/cli/main.mjs +11 -1
- package/cli/package-loader.mjs +41 -0
- package/dist-library/LocalDocumentView-6trX7xJc.js +97920 -0
- package/dist-library/{authoring-BEVyth5X.js → authoring-BsfSwQRm.js} +237 -209
- package/dist-library/compiler--ea2CKQF.js +61 -0
- package/dist-library/compiler-core-kPiH-gOV.js +11805 -0
- package/dist-library/component-state-Cq2K5gkS.js +490 -0
- package/dist-library/component-state-D_cw_EHe.js +54 -0
- package/dist-library/config-validation-DXTynAw7.js +3005 -0
- package/dist-library/default-components-Z_YMio5P.js +2346 -0
- package/dist-library/identity-MYJXKSkB.js +1443 -0
- package/dist-library/math-display-BJz4gbFc.js +24000 -0
- package/dist-library/math-sample-BGEW49zY.js +1124 -0
- package/dist-library/options-CX5m5n-J.js +115 -0
- package/dist-library/parser-standard-DlCk7sLo.js +10122 -0
- package/dist-library/props-DGlBk0e5.js +183 -0
- package/dist-library/react-ByOHunUW.js +122 -0
- package/dist-library/reactive-md-authoring.js +712 -1077
- package/dist-library/reactive-md-build.js +7966 -0
- package/dist-library/reactive-md-compiler-standard.js +33 -0
- package/dist-library/reactive-md-compiler.js +22 -0
- package/dist-library/reactive-md-default-packs.js +71 -0
- package/dist-library/reactive-md-default-preset.js +10 -0
- package/dist-library/reactive-md-export.js +111 -0
- package/dist-library/reactive-md-print.css +18 -3
- package/dist-library/reactive-md-react-runtime.js +251 -0
- package/dist-library/reactive-md-react-server.js +55 -0
- package/dist-library/reactive-md-react-unstyled.js +9 -1
- package/dist-library/reactive-md-react.js +9 -1
- package/dist-library/reactive-md-runtime-browser.js +51 -0
- package/dist-library/reactive-md-runtime.js +3 -0
- package/dist-library/reactive-md-sdk.js +6 -0
- package/dist-library/reactive-md-standalone-host.js +442 -0
- package/dist-library/reactive-md-testing-browser.js +523 -0
- package/dist-library/reactive-md-testing-react.js +221 -0
- package/dist-library/reactive-md-testing.js +638 -0
- package/dist-library/reactive-md-vite.js +959 -0
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1080 -795
- package/dist-library/registry-B9Jc3FVe.js +1174 -0
- package/dist-library/resources-BGt8mpDA.js +204 -0
- package/dist-library/runtime-C-sbfpOX.js +1157 -0
- package/dist-library/runtime-Dkq7ldyg.js +172 -0
- package/dist-library/schema-ZFufO8V0.js +39 -0
- package/dist-library/shareable-DDVL4Fi9.js +844 -0
- package/dist-library/types/authoring/catalog.d.ts +168 -0
- package/dist-library/types/authoring/conformance.d.ts +24 -0
- package/dist-library/types/{editor → authoring}/editor-i18n.d.ts +3 -24
- package/dist-library/types/authoring/extensions.d.ts +13 -0
- package/dist-library/types/authoring/index.d.ts +14 -11
- package/dist-library/types/authoring/insert.d.ts +16 -0
- package/dist-library/types/{editor → authoring}/native-components.d.ts +19 -2
- package/dist-library/types/authoring/templates.d.ts +65 -0
- package/dist-library/types/build/diagnostics.d.ts +8 -0
- package/dist-library/types/build/digest.d.ts +5 -0
- package/dist-library/types/build/entry.d.ts +9 -0
- package/dist-library/types/build/host.d.ts +36 -0
- package/dist-library/types/build/index.d.ts +99 -0
- package/dist-library/types/build/notices.d.ts +29 -0
- package/dist-library/types/build/resources.d.ts +60 -0
- package/dist-library/types/build/vite.d.ts +15 -0
- package/dist-library/types/compiler/index.d.ts +22 -0
- package/dist-library/types/compiler/result.d.ts +30 -0
- package/dist-library/types/compiler/standard.d.ts +16 -0
- package/dist-library/types/compiler/types.d.ts +69 -0
- package/dist-library/types/components/chart-motion.d.ts +12 -0
- package/dist-library/types/components/controls.d.ts +21 -0
- package/dist-library/types/{local → components}/data-table.d.ts +10 -24
- package/dist-library/types/components/default-chart-types.d.ts +22 -0
- package/dist-library/types/components/default-chart.d.ts +2 -0
- package/dist-library/types/components/default-preset.d.ts +10 -0
- package/dist-library/types/components/diagram-inspector.d.ts +24 -0
- package/dist-library/types/components/gallery.d.ts +6 -0
- package/dist-library/types/components/layout.d.ts +23 -0
- package/dist-library/types/components/mafs-plot-grid.d.ts +57 -0
- package/dist-library/types/components/mafs-visuals.d.ts +40 -0
- package/dist-library/types/components/numeric-sliders.d.ts +3 -0
- package/dist-library/types/components/uiarc/calendar/calendar.d.ts +26 -0
- package/dist-library/types/components/uiarc/date-picker/date-picker.d.ts +29 -0
- package/dist-library/types/components/uiarc/lib/motion-tokens.d.ts +2 -0
- package/dist-library/types/components/uiarc/lib/use-today.d.ts +2 -0
- package/dist-library/types/components/uiarc/motion-tokens.d.ts +60 -0
- package/dist-library/types/components/uiarc/rmd-motion.d.ts +12 -0
- package/dist-library/types/components/uiarc/select/select.d.ts +21 -0
- package/dist-library/types/components/uiarc/slider/slider.d.ts +53 -0
- package/dist-library/types/components/use-hydrated.d.ts +6 -0
- package/dist-library/types/components/visuals.d.ts +13 -0
- package/dist-library/types/export/component-state.d.ts +39 -0
- package/dist-library/types/export/index.d.ts +47 -0
- package/dist-library/types/export/requirements.d.ts +23 -0
- package/dist-library/types/export/resources.d.ts +8 -0
- package/dist-library/types/export/restoration.d.ts +52 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/compilation/compiler-core.d.ts +16 -0
- package/dist-library/types/local/compilation/compiler-services.d.ts +64 -0
- package/dist-library/types/local/compilation/compiler-structure.d.ts +46 -0
- package/dist-library/types/local/compilation/compiler-values.d.ts +9 -0
- package/dist-library/types/local/compilation/compiler.d.ts +34 -0
- package/dist-library/types/local/compilation/component-kernel.d.ts +487 -0
- package/dist-library/types/local/{dependencies.d.ts → compilation/dependencies.d.ts} +4 -3
- package/dist-library/types/local/{diagnostics.d.ts → configuration/diagnostic-messages.d.ts} +193 -65
- package/dist-library/types/local/configuration/diagnostics.d.ts +58 -0
- package/dist-library/types/local/{limits.d.ts → configuration/limits.d.ts} +15 -2
- package/dist-library/types/local/configuration/options-core.d.ts +120 -0
- package/dist-library/types/local/configuration/options.d.ts +17 -0
- package/dist-library/types/local/configuration/portable-options.d.ts +3 -0
- package/dist-library/types/local/configuration/schema-core.d.ts +32 -0
- package/dist-library/types/local/configuration/schema.d.ts +12 -0
- package/dist-library/types/local/contracts/types.d.ts +519 -0
- package/dist-library/types/local/{version.d.ts → contracts/version.d.ts} +1 -1
- package/dist-library/types/local/{computations.d.ts → evaluation/computations.d.ts} +6 -3
- package/dist-library/types/local/{expression.d.ts → evaluation/expression.d.ts} +2 -2
- package/dist-library/types/local/{math-display.d.ts → evaluation/math-display.d.ts} +2 -16
- package/dist-library/types/local/evaluation/math-sample.d.ts +23 -0
- package/dist-library/types/local/evaluation/math.d.ts +73 -0
- package/dist-library/types/local/{validation.d.ts → evaluation/validation.d.ts} +1 -1
- package/dist-library/types/local/html/html-details.d.ts +16 -0
- package/dist-library/types/local/html/html-entities.d.ts +7 -0
- package/dist-library/types/local/html/html-policy.d.ts +43 -0
- package/dist-library/types/local/html/html-recovery.d.ts +16 -0
- package/dist-library/types/local/html/html-table-names.d.ts +9 -0
- package/dist-library/types/local/{html-table.d.ts → html/html-table.d.ts} +2 -6
- package/dist-library/types/local/{html.d.ts → html/html.d.ts} +1 -1
- package/dist-library/types/local/index.d.ts +31 -24
- package/dist-library/types/local/markdown/fast-markdown.d.ts +137 -0
- package/dist-library/types/local/{footnotes.d.ts → markdown/footnotes.d.ts} +1 -1
- package/dist-library/types/local/{heading-anchors.d.ts → markdown/heading-anchors.d.ts} +12 -2
- package/dist-library/types/local/markdown/markdown-blocks.d.ts +55 -0
- package/dist-library/types/local/markdown/markdown-structure.d.ts +3 -0
- package/dist-library/types/local/markdown/plain-paragraphs.d.ts +10 -0
- package/dist-library/types/local/parsing/lexical.d.ts +21 -0
- package/dist-library/types/local/parsing/parse-budget.d.ts +67 -0
- package/dist-library/types/local/parsing/parser-capabilities.d.ts +42 -0
- package/dist-library/types/local/parsing/parser-core.d.ts +65 -0
- package/dist-library/types/local/parsing/parser-standard.d.ts +7 -0
- package/dist-library/types/local/parsing/parser.d.ts +16 -0
- package/dist-library/types/local/parsing/rmd-recovery.d.ts +48 -0
- package/dist-library/types/local/{LocalDocumentView.d.ts → rendering/LocalDocumentView.d.ts} +67 -24
- package/dist-library/types/local/rendering/legacy-component-adapter.d.ts +36 -0
- package/dist-library/types/local/rendering/render-types.d.ts +57 -0
- package/dist-library/types/local/rendering/view-revision.d.ts +75 -0
- package/dist-library/types/local/{retention.d.ts → runtime/retention.d.ts} +1 -1
- package/dist-library/types/local/runtime/runtime.d.ts +34 -0
- package/dist-library/types/local/{state.d.ts → runtime/state.d.ts} +4 -4
- package/dist-library/types/local/session/compiler-cache.d.ts +44 -0
- package/dist-library/types/local/session/incremental.d.ts +48 -0
- package/dist-library/types/local/session/parse-session.d.ts +62 -0
- package/dist-library/types/local/session/row-reuse.d.ts +46 -0
- package/dist-library/types/local/{authoring.d.ts → source/authoring.d.ts} +11 -3
- package/dist-library/types/local/source/node-walk.d.ts +3 -0
- package/dist-library/types/local/source/source-context.d.ts +63 -0
- package/dist-library/types/local/{source-migration.d.ts → source/source-migration.d.ts} +2 -2
- package/dist-library/types/local/{i18n.d.ts → theme/i18n.d.ts} +2 -2
- package/dist-library/types/local/theme/theme-name.d.ts +3 -0
- package/dist-library/types/local/{theme.d.ts → theme/theme.d.ts} +3 -3
- package/dist-library/types/local/transport/compile-patch.d.ts +127 -0
- package/dist-library/types/local/{compiled-data.d.ts → transport/compiled-data.d.ts} +1 -1
- package/dist-library/types/local/transport/flat-compiled-data.d.ts +17 -0
- package/dist-library/types/local/transport/shared-data.d.ts +10 -0
- package/dist-library/types/local/transport/worker.d.ts +265 -0
- package/dist-library/types/local/widgets/visuals.d.ts +25 -0
- package/dist-library/types/presets/default-authoring.d.ts +50 -0
- package/dist-library/types/presets/default-components.d.ts +4 -0
- package/dist-library/types/presets/default-semantics.d.ts +8 -0
- package/dist-library/types/presets/default.d.ts +11 -0
- package/dist-library/types/presets/identity.d.ts +7 -0
- package/dist-library/types/presets/packs.d.ts +4 -0
- package/dist-library/types/react/component-api.d.ts +260 -0
- package/dist-library/types/react/component-primitives.d.ts +21 -0
- package/dist-library/types/react/component-utils.d.ts +125 -0
- package/dist-library/types/react/default-theme.d.ts +6 -0
- package/dist-library/types/react/field-validation.d.ts +11 -0
- package/dist-library/types/react/index.d.ts +17 -5
- package/dist-library/types/react/overflow-text-tooltip.d.ts +6 -0
- package/dist-library/types/react/package.d.ts +69 -0
- package/dist-library/types/react/runtime/common.d.ts +4 -0
- package/dist-library/types/react/runtime/index.d.ts +8 -0
- package/dist-library/types/react/runtime/useComponentState.d.ts +30 -0
- package/dist-library/types/react/runtime/useKeys.d.ts +16 -0
- package/dist-library/types/react/runtime/useSwipe.d.ts +27 -0
- package/dist-library/types/react/runtime/useTicker.d.ts +17 -0
- package/dist-library/types/react/sdk.d.ts +110 -0
- package/dist-library/types/react/server.d.ts +15 -0
- package/dist-library/types/react/tooltip-layer.d.ts +10 -0
- package/dist-library/types/react/use-draft-field.d.ts +17 -0
- package/dist-library/types/runtime-services/browser/index.d.ts +63 -0
- package/dist-library/types/runtime-services/component-state.d.ts +152 -0
- package/dist-library/types/runtime-services/identity.d.ts +41 -0
- package/dist-library/types/runtime-services/index.d.ts +10 -0
- package/dist-library/types/runtime-services/random.d.ts +42 -0
- package/dist-library/types/runtime-services/runtime.d.ts +51 -0
- package/dist-library/types/runtime-services/scheduler.d.ts +44 -0
- package/dist-library/types/sdk/assembly.d.ts +73 -0
- package/dist-library/types/sdk/compat-profile.d.ts +57 -0
- package/dist-library/types/sdk/compiler-config.d.ts +33 -0
- package/dist-library/types/sdk/config-validation.d.ts +33 -0
- package/dist-library/types/sdk/config.d.ts +35 -0
- package/dist-library/types/sdk/hash.d.ts +9 -0
- package/dist-library/types/sdk/index.d.ts +10 -0
- package/dist-library/types/sdk/manifest.d.ts +49 -0
- package/dist-library/types/sdk/pattern.d.ts +11 -0
- package/dist-library/types/sdk/preset-core.d.ts +11 -0
- package/dist-library/types/sdk/preset.d.ts +9 -0
- package/dist-library/types/sdk/props.d.ts +33 -0
- package/dist-library/types/sdk/registry-core.d.ts +16 -0
- package/dist-library/types/sdk/registry.d.ts +18 -0
- package/dist-library/types/sdk/theme.d.ts +73 -0
- package/dist-library/types/sdk/types.d.ts +221 -0
- package/dist-library/types/sdk/version.d.ts +49 -0
- package/dist-library/types/shareable.d.ts +29 -3
- package/dist-library/types/standalone/diagnostics.d.ts +16 -0
- package/dist-library/types/standalone/events.d.ts +4 -0
- package/dist-library/types/standalone/library.d.ts +6 -0
- package/dist-library/types/standalone/payload.d.ts +15 -0
- package/dist-library/types/standalone/prepare.d.ts +21 -0
- package/dist-library/types/standalone/session.d.ts +68 -0
- package/dist-library/types/standalone/version.d.ts +7 -0
- package/dist-library/types/testing/behavior.d.ts +19 -0
- package/dist-library/types/testing/browser.d.ts +126 -0
- package/dist-library/types/testing/cases.d.ts +16 -0
- package/dist-library/types/testing/index.d.ts +13 -0
- package/dist-library/types/testing/manifest.d.ts +10 -0
- package/dist-library/types/testing/react.d.ts +45 -0
- package/dist-library/types/testing/report.d.ts +20 -0
- package/dist-library/types/testing/types.d.ts +125 -0
- package/dist-library/types/testing/values.d.ts +22 -0
- package/dist-library/types/vite/client.d.ts +36 -0
- package/dist-library/types/vite/discovery.d.ts +51 -0
- package/dist-library/types/vite/index.d.ts +31 -0
- package/dist-library/types/vite/registration.d.ts +109 -0
- package/dist-library/types-BFCrMrg0.js +52 -0
- package/dist-library/validation-W-bmny-x.js +2253 -0
- package/dist-library/values-CIt8AjiU.js +134 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +591 -95
- package/docs/README-ch.md +90 -0
- package/docs/README.md +87 -81
- package/docs/compatibility/compatibility-ch.md +22 -14
- package/docs/compatibility/compatibility-en.md +22 -14
- package/docs/compatibility/source-versioning-ch.md +15 -12
- package/docs/compatibility/source-versioning-en.md +16 -13
- package/docs/development/component-development-ch.md +51 -195
- package/docs/development/component-development-en.md +51 -195
- package/docs/development/component-development-reference-ch.md +253 -0
- package/docs/development/component-development-reference-en.md +238 -0
- package/docs/development/component-protocol-ch.md +51 -50
- package/docs/development/component-protocol-en.md +52 -49
- package/docs/development/local-module-layout-ch.md +59 -0
- package/docs/development/local-module-layout-en.md +59 -0
- package/docs/development/performance-overview-ch.md +402 -0
- package/docs/development/performance-overview-en.md +402 -0
- package/docs/development/releasing-ch.md +8 -104
- package/docs/development/releasing-en.md +8 -104
- package/docs/guides/local-guide-ch.md +28 -9
- package/docs/guides/local-guide-en.md +31 -12
- package/docs/integration/author-tools-ch.md +4 -2
- package/docs/integration/author-tools-en.md +4 -2
- package/docs/integration/codemirror-ch.md +52 -0
- package/docs/integration/codemirror-en.md +29 -0
- package/docs/integration/compiler-ch.md +47 -0
- package/docs/integration/compiler-en.md +34 -0
- package/docs/integration/directory-discovery-ch.md +53 -0
- package/docs/integration/directory-discovery-en.md +31 -0
- package/docs/integration/editor-ch.md +48 -21
- package/docs/integration/editor-en.md +48 -21
- package/docs/integration/extension-sdk-ch.md +392 -0
- package/docs/integration/extension-sdk-en.md +377 -0
- package/docs/integration/local-integration-ch.md +63 -9
- package/docs/integration/local-integration-en.md +89 -13
- package/docs/integration/repository-split-ch.md +40 -0
- package/docs/integration/repository-split-en.md +23 -0
- package/docs/integration/shareable-export-ch.md +46 -2
- package/docs/integration/shareable-export-en.md +46 -2
- package/docs/reference/computations-formatting-ch.md +4 -2
- package/docs/reference/computations-formatting-en.md +4 -2
- package/docs/reference/constraints-collections-ch.md +21 -1
- package/docs/reference/constraints-collections-en.md +21 -1
- package/docs/reference/diagnostics-counting-ch.md +1 -1
- package/docs/reference/diagnostics-counting-en.md +1 -1
- package/docs/reference/html-compatibility-ch.md +4 -0
- package/docs/reference/html-compatibility-en.md +4 -0
- package/docs/reference/local-components-v2-ch.md +2 -0
- package/docs/reference/local-components-v2-en.md +2 -0
- package/docs/reference/local-interaction-syntax-ch.md +51 -15
- package/docs/reference/local-interaction-syntax-en.md +58 -14
- package/docs/reference/theme-protocol-ch.md +79 -7
- package/docs/reference/theme-protocol-en.md +79 -7
- package/docs/reference/tolerance-ch.md +64 -0
- package/docs/reference/tolerance-en.md +57 -0
- package/docs/releases/release-0.4.0-ch.md +2 -0
- package/docs/releases/release-0.4.0-en.md +2 -0
- package/docs/releases/release-0.4.1-ch.md +2 -0
- package/docs/releases/release-0.4.1-en.md +2 -0
- package/docs/releases/release-0.5.0-ch.md +2 -0
- package/docs/releases/release-0.5.0-en.md +2 -0
- package/docs/releases/release-0.5.1-ch.md +2 -0
- package/docs/releases/release-0.5.1-en.md +2 -0
- package/docs/releases/release-0.5.2-ch.md +2 -0
- package/docs/releases/release-0.5.2-en.md +2 -0
- package/docs/releases/release-0.5.3-ch.md +2 -0
- package/docs/releases/release-0.5.3-en.md +2 -0
- package/docs/releases/release-0.6.0-ch.md +2 -0
- package/docs/releases/release-0.6.0-en.md +2 -0
- package/docs/releases/release-0.6.1-ch.md +2 -0
- package/docs/releases/release-0.6.1-en.md +2 -0
- package/docs/releases/release-0.7.0-ch.md +86 -0
- package/docs/releases/release-0.7.0-en.md +86 -0
- package/docs/releases/release-0.8.0-ch.md +126 -0
- package/docs/releases/release-0.8.0-en.md +126 -0
- package/examples/component-package/LICENSE +21 -0
- package/examples/component-package/NOTICES.md +12 -0
- package/examples/component-package/README-ch.md +101 -0
- package/examples/component-package/README.md +133 -0
- package/examples/component-package/package.json +35 -0
- package/examples/component-package/sample/document.reactive.md +14 -0
- package/examples/component-package/scripts/build-export.mjs +44 -0
- package/examples/component-package/scripts/build.mjs +130 -0
- package/examples/component-package/scripts/verify.mjs +257 -0
- package/examples/component-package/src/assets/notice.svg +4 -0
- package/examples/component-package/src/component.css +40 -0
- package/examples/component-package/src/components.tsx +105 -0
- package/examples/component-package/src/harness.tsx +34 -0
- package/examples/component-package/src/manifests.ts +71 -0
- package/examples/component-package/src/node-entry.ts +18 -0
- package/examples/component-package/src/sample.ts +4 -0
- package/examples/component-package/src/theme.css +44 -0
- package/examples/component-package/src/theme.ts +22 -0
- package/examples/component-package/tsconfig.json +15 -0
- package/examples/conformance/README-ch.md +55 -0
- package/examples/conformance/README.md +2 -0
- package/examples/conformance/local-draft-3.json +296 -0
- package/examples/game-2048-package/LICENSE +21 -0
- package/examples/game-2048-package/NOTICES.md +11 -0
- package/examples/game-2048-package/README-ch.md +97 -0
- package/examples/game-2048-package/README.md +102 -0
- package/examples/game-2048-package/package.json +35 -0
- package/examples/game-2048-package/sample/document.reactive.md +17 -0
- package/examples/game-2048-package/scripts/build-export.mjs +44 -0
- package/examples/game-2048-package/scripts/build.mjs +130 -0
- package/examples/game-2048-package/scripts/verify.mjs +180 -0
- package/examples/game-2048-package/src/component.css +161 -0
- package/examples/game-2048-package/src/components.tsx +326 -0
- package/examples/game-2048-package/src/game-engine.ts +228 -0
- package/examples/game-2048-package/src/harness.tsx +34 -0
- package/examples/game-2048-package/src/manifest.ts +85 -0
- package/examples/game-2048-package/src/node-entry.ts +30 -0
- package/examples/game-2048-package/src/sample.ts +4 -0
- package/examples/game-2048-package/tsconfig.json +15 -0
- package/examples/integration/README-ch.md +63 -0
- package/examples/integration/README.md +17 -1
- package/examples/integration/extension-sdk/README-ch.md +24 -0
- package/examples/integration/extension-sdk/README.md +24 -0
- package/examples/integration/extension-sdk/advanced-standalone.ts +6 -0
- package/examples/integration/extension-sdk/advanced.tsx +101 -0
- package/examples/integration/extension-sdk/env.d.ts +2 -0
- package/examples/integration/extension-sdk/extensions.tsx +97 -0
- package/examples/integration/extension-sdk/index.html +3 -0
- package/examples/integration/extension-sdk/main.tsx +10 -0
- package/examples/integration/extension-sdk/package.json +6 -0
- package/examples/integration/extension-sdk/standalone.ts +7 -0
- package/examples/integration/extension-sdk/tsconfig.json +8 -0
- package/examples/integration/react-comprehensive/index.html +12 -0
- package/examples/integration/react-comprehensive/main.jsx +123 -0
- package/examples/integration/react-comprehensive/package.json +18 -0
- package/examples/local/README-ch.md +76 -0
- package/examples/local/README.md +4 -2
- package/examples/local/scenarios/blog-zh.reactive.md +71 -0
- package/examples/local/scenarios/blog.reactive.md +71 -0
- package/examples/local/scenarios/classroom-zh.reactive.md +97 -0
- package/examples/local/scenarios/classroom.reactive.md +97 -0
- package/examples/local/scenarios/proposal-zh.reactive.md +79 -0
- package/examples/local/scenarios/proposal.reactive.md +79 -0
- package/examples/local/scenarios/survey-zh.reactive.md +74 -0
- package/examples/local/scenarios/survey.reactive.md +74 -0
- package/examples/local/showcase/README-ch.md +22 -0
- package/examples/local/showcase/README.md +9 -3
- package/examples/local/showcase/features.reactive.md +637 -0
- package/examples/local/showcase/zh/features.reactive.md +637 -0
- package/examples/sci-fi-theme/README-ch.md +131 -0
- package/examples/sci-fi-theme/README.md +146 -0
- package/examples/sci-fi-theme/demo/demo.css +532 -0
- package/examples/sci-fi-theme/demo/document.reactive.md +185 -0
- package/examples/sci-fi-theme/demo/index.html +13 -0
- package/examples/sci-fi-theme/demo/main.tsx +180 -0
- package/examples/sci-fi-theme/docs/design-system-ch.md +245 -0
- package/examples/sci-fi-theme/docs/design-system.md +474 -0
- package/examples/sci-fi-theme/package.json +27 -0
- package/examples/sci-fi-theme/scripts/screenshot.mjs +98 -0
- package/examples/sci-fi-theme/src/components.css +1460 -0
- package/examples/sci-fi-theme/src/index.ts +6 -0
- package/examples/sci-fi-theme/src/sci-fi.css +5 -0
- package/examples/sci-fi-theme/src/theme.ts +37 -0
- package/examples/sci-fi-theme/src/tokens.css +408 -0
- package/examples/sci-fi-theme/tsconfig.json +20 -0
- package/examples/sci-fi-theme/vite.config.ts +24 -0
- package/examples/tetris-package/LICENSE +21 -0
- package/examples/tetris-package/NOTICES.md +11 -0
- package/examples/tetris-package/README-ch.md +91 -0
- package/examples/tetris-package/README.md +95 -0
- package/examples/tetris-package/package.json +35 -0
- package/examples/tetris-package/sample/document.reactive.md +16 -0
- package/examples/tetris-package/scripts/build-export.mjs +44 -0
- package/examples/tetris-package/scripts/build.mjs +130 -0
- package/examples/tetris-package/scripts/verify.mjs +173 -0
- package/examples/tetris-package/src/component.css +145 -0
- package/examples/tetris-package/src/components.tsx +334 -0
- package/examples/tetris-package/src/harness.tsx +34 -0
- package/examples/tetris-package/src/manifests.ts +93 -0
- package/examples/tetris-package/src/node-entry.ts +16 -0
- package/examples/tetris-package/src/sample.ts +4 -0
- package/examples/tetris-package/src/tetris-engine.ts +325 -0
- package/examples/tetris-package/tsconfig.json +15 -0
- package/package.json +98 -44
- package/dist-library/compiler-Cm3ppMxG.js +0 -46044
- package/dist-library/react-Bh7_oxZp.js +0 -59655
- package/dist-library/reactive-md-editor.css +0 -2
- package/dist-library/reactive-md-editor.js +0 -3853
- package/dist-library/runtime-DlFYQ4s_.js +0 -498
- package/dist-library/types/editor/ReactiveMarkdownEditor.d.ts +0 -7
- package/dist-library/types/editor/editor-toolbar.d.ts +0 -24
- package/dist-library/types/editor/editor-view-bar.d.ts +0 -11
- package/dist-library/types/editor/extended-native-components.d.ts +0 -58
- package/dist-library/types/editor/index.d.ts +0 -9
- package/dist-library/types/editor/locale.d.ts +0 -13
- package/dist-library/types/editor/source-authoring.d.ts +0 -59
- package/dist-library/types/editor/types.d.ts +0 -48
- package/dist-library/types/editor/use-gutter-metrics.d.ts +0 -5
- package/dist-library/types/editor/use-source-history.d.ts +0 -16
- package/dist-library/types/local/compiler.d.ts +0 -4
- package/dist-library/types/local/math.d.ts +0 -48
- package/dist-library/types/local/options.d.ts +0 -36
- package/dist-library/types/local/parser.d.ts +0 -13
- package/dist-library/types/local/render-types.d.ts +0 -27
- package/dist-library/types/local/runtime.d.ts +0 -2
- package/dist-library/types/local/schema.d.ts +0 -77
- package/dist-library/types/local/types.d.ts +0 -263
- package/dist-library/types/local/visuals.d.ts +0 -12
- package/dist-library/types/local/worker.d.ts +0 -98
- package/docs/development/performance-ch.md +0 -76
- package/docs/development/performance-en.md +0 -76
- /package/dist-library/types/{editor → authoring}/command-types.d.ts +0 -0
- /package/dist-library/types/{editor → authoring}/editor-commands.d.ts +0 -0
- /package/dist-library/types/local/{locale.d.ts → contracts/locale.d.ts} +0 -0
- /package/dist-library/types/local/{collection-functions.d.ts → evaluation/collection-functions.d.ts} +0 -0
- /package/dist-library/types/local/{data-functions.d.ts → evaluation/data-functions.d.ts} +0 -0
- /package/dist-library/types/local/{dates.d.ts → evaluation/dates.d.ts} +0 -0
- /package/dist-library/types/local/{formatting.d.ts → evaluation/formatting.d.ts} +0 -0
- /package/dist-library/types/local/{html-names.d.ts → html/html-names.d.ts} +0 -0
- /package/dist-library/types/local/{text-length.d.ts → source/text-length.d.ts} +0 -0
- /package/dist-library/types/local/{colors.d.ts → theme/colors.d.ts} +0 -0
- /package/dist-library/types/local/{code-block.d.ts → widgets/code-block.d.ts} +0 -0
- /package/dist-library/types/local/{code-languages.d.ts → widgets/code-languages.d.ts} +0 -0
- /package/dist-library/types/local/{diagram-layout.d.ts → widgets/diagram-layout.d.ts} +0 -0
- /package/dist-library/types/local/{image-view.d.ts → widgets/image-view.d.ts} +0 -0
- /package/dist-library/types/local/{math-view.d.ts → widgets/math-view.d.ts} +0 -0
- /package/dist-library/types/local/{table-surface.d.ts → widgets/table-surface.d.ts} +0 -0
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
import { DEFAULT_LOCAL_BUILD_BUDGETS, LocalBuildError, buildLocalStandaloneBundle, collectLocalBuildResources, n as defineLocalTheme, r as LOCAL_REACT_PRESET_PROTOCOL, t as createLocalConfig } from "./reactive-md-build.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mkdir, readFile, readdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { build } from "vite";
|
|
8
|
+
// src/vite/discovery.ts
|
|
9
|
+
var DEFAULT_THEME_DIR = "theme";
|
|
10
|
+
var DEFAULT_PLUGIN_DIR = "plugin";
|
|
11
|
+
var THEME_STYLESHEET = "theme.css";
|
|
12
|
+
var THEME_METADATA = "theme.json";
|
|
13
|
+
var COMPONENT_STYLESHEET = "component.css";
|
|
14
|
+
/** Entry names are ordered as documented; ambiguity errors list this order. */
|
|
15
|
+
var PLUGIN_ENTRIES = Object.freeze([
|
|
16
|
+
"index.ts",
|
|
17
|
+
"index.tsx",
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.jsx",
|
|
20
|
+
"index.mts",
|
|
21
|
+
"index.mjs"
|
|
22
|
+
]);
|
|
23
|
+
var THEME_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
24
|
+
"id",
|
|
25
|
+
"name",
|
|
26
|
+
"version",
|
|
27
|
+
"protocol",
|
|
28
|
+
"colorSchemes"
|
|
29
|
+
]);
|
|
30
|
+
function compareCodeUnits(left, right) {
|
|
31
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
function sortedUnique(values) {
|
|
34
|
+
return [...new Set(values)].sort(compareCodeUnits);
|
|
35
|
+
}
|
|
36
|
+
function isInside(parent, child) {
|
|
37
|
+
const path = relative(parent, child);
|
|
38
|
+
return path === "" || !path.startsWith(`..${sep}`) && path !== ".." && !isAbsolute(path);
|
|
39
|
+
}
|
|
40
|
+
function posixRelative(root, file) {
|
|
41
|
+
return relative(root, file).split(sep).join("/");
|
|
42
|
+
}
|
|
43
|
+
function messageOf$1(error) {
|
|
44
|
+
return error instanceof Error ? error.message : String(error);
|
|
45
|
+
}
|
|
46
|
+
function isRecord(value) {
|
|
47
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
/** Canonical project root; a missing root keeps its normalized lexical path. */
|
|
50
|
+
async function canonicalRoot(root) {
|
|
51
|
+
if (typeof root !== "string" || root.length === 0) throw new TypeError("discoverDirectories requires a project root path.");
|
|
52
|
+
const normalized = resolve(root);
|
|
53
|
+
try {
|
|
54
|
+
return await realpath(normalized);
|
|
55
|
+
} catch {
|
|
56
|
+
return normalized;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function resolveScanDirectory(root, value, fallback, label) {
|
|
60
|
+
const candidate = value ?? fallback;
|
|
61
|
+
if (typeof candidate !== "string" || candidate.trim().length === 0) throw new TypeError(`${label} must be a non-empty directory path.`);
|
|
62
|
+
const directory = resolve(root, candidate);
|
|
63
|
+
if (!isInside(root, directory)) throw new Error(`${label} "${candidate}" resolves outside the project root.`);
|
|
64
|
+
let real;
|
|
65
|
+
try {
|
|
66
|
+
real = await realpath(directory);
|
|
67
|
+
} catch {
|
|
68
|
+
return directory;
|
|
69
|
+
}
|
|
70
|
+
if (!isInside(root, real)) throw new Error(`${label} "${candidate}" resolves outside the project root through a symbolic link.`);
|
|
71
|
+
return real;
|
|
72
|
+
}
|
|
73
|
+
/** Immediate child directories only. Missing roots scan as empty. */
|
|
74
|
+
async function childDirectories(directory) {
|
|
75
|
+
let entries;
|
|
76
|
+
try {
|
|
77
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const code = error.code;
|
|
80
|
+
if (code === "ENOENT" || code === "ENOTDIR") return [];
|
|
81
|
+
throw new Error(`Cannot scan ${directory}: ${messageOf$1(error)}`);
|
|
82
|
+
}
|
|
83
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => join(directory, entry.name)).sort(compareCodeUnits);
|
|
84
|
+
}
|
|
85
|
+
async function isFile(file) {
|
|
86
|
+
try {
|
|
87
|
+
return (await stat(file)).isFile();
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Read optional theme metadata under the shared file budget. */
|
|
93
|
+
async function readThemeMetadata(file) {
|
|
94
|
+
let info;
|
|
95
|
+
try {
|
|
96
|
+
info = await stat(file);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
const code = error.code;
|
|
99
|
+
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
100
|
+
throw new Error(`Theme metadata ${file} is not readable: ${messageOf$1(error)}`);
|
|
101
|
+
}
|
|
102
|
+
if (!info.isFile()) return null;
|
|
103
|
+
if (info.size > DEFAULT_LOCAL_BUILD_BUDGETS.maxFileBytes) throw new Error(`Theme metadata ${file} exceeds the ${DEFAULT_LOCAL_BUILD_BUDGETS.maxFileBytes}-byte budget.`);
|
|
104
|
+
let text;
|
|
105
|
+
try {
|
|
106
|
+
text = await readFile(file, "utf8");
|
|
107
|
+
} catch (error) {
|
|
108
|
+
throw new Error(`Theme metadata ${file} is not readable: ${messageOf$1(error)}`);
|
|
109
|
+
}
|
|
110
|
+
let value;
|
|
111
|
+
try {
|
|
112
|
+
value = JSON.parse(text);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new Error(`Invalid theme metadata ${file}: ${messageOf$1(error)}`);
|
|
115
|
+
}
|
|
116
|
+
if (!isRecord(value)) throw new Error(`Invalid theme metadata ${file}: must be a JSON object.`);
|
|
117
|
+
for (const key of Object.keys(value)) if (!THEME_METADATA_KEYS.has(key)) throw new Error(`Invalid theme metadata ${file}: unsupported key "${key}".`);
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function summarizeDiagnostics(collected) {
|
|
121
|
+
return collected.diagnostics.map((item) => `[${item.code}] ${item.message}`).join("\n");
|
|
122
|
+
}
|
|
123
|
+
/** Inline one stylesheet through the shared collector; errors name the file. */
|
|
124
|
+
async function inlineStylesheet(file, id, root, config, budgets) {
|
|
125
|
+
const declared = Object.freeze([Object.freeze({
|
|
126
|
+
id,
|
|
127
|
+
path: posixRelative(root, file)
|
|
128
|
+
})]);
|
|
129
|
+
const collected = await collectLocalBuildResources({
|
|
130
|
+
config,
|
|
131
|
+
declared,
|
|
132
|
+
root,
|
|
133
|
+
allowlist: Object.freeze([root]),
|
|
134
|
+
budgets
|
|
135
|
+
});
|
|
136
|
+
if (collected.diagnostics.length > 0) throw new Error(`Cannot inline ${file}:\n${summarizeDiagnostics(collected)}`);
|
|
137
|
+
const resource = collected.resources.find((item) => item.id === id);
|
|
138
|
+
if (!resource) throw new Error(`Cannot inline ${file}: the stylesheet was not collected.`);
|
|
139
|
+
return {
|
|
140
|
+
css: resource.css,
|
|
141
|
+
assets: collected.assets
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function metadataField(metadata, key) {
|
|
145
|
+
return metadata !== null && Object.hasOwn(metadata, key) ? metadata[key] : void 0;
|
|
146
|
+
}
|
|
147
|
+
function buildThemeInput(folder, resourceId, css, metadata) {
|
|
148
|
+
const id = metadataField(metadata, "id");
|
|
149
|
+
const name = metadataField(metadata, "name");
|
|
150
|
+
const version = metadataField(metadata, "version");
|
|
151
|
+
const protocol = metadataField(metadata, "protocol");
|
|
152
|
+
const colorSchemes = metadataField(metadata, "colorSchemes");
|
|
153
|
+
return {
|
|
154
|
+
id: id === void 0 ? `local/theme/${folder}` : id,
|
|
155
|
+
name: name === void 0 ? folder : name,
|
|
156
|
+
version: version === void 0 ? "0.0.0" : version,
|
|
157
|
+
...protocol === void 0 ? {} : { protocol },
|
|
158
|
+
...colorSchemes === void 0 ? {} : { colorSchemes },
|
|
159
|
+
css: [{
|
|
160
|
+
id: resourceId,
|
|
161
|
+
css
|
|
162
|
+
}]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function mergeAsset(assets, asset) {
|
|
166
|
+
const previous = assets.get(asset.path);
|
|
167
|
+
if (previous !== void 0) {
|
|
168
|
+
if (previous.digest !== asset.digest || previous.bytes !== asset.bytes || previous.mime !== asset.mime) throw new Error(`Resource ${asset.path} was read with conflicting contents.`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
assets.set(asset.path, asset);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Discover themes and plugins beneath a project root. Results and every nested
|
|
175
|
+
* package/resource are frozen, sorted by path, and independent of the current
|
|
176
|
+
* working directory. Missing roots produce empty results, but their normalized
|
|
177
|
+
* paths remain in `directories` so a watcher can observe later creation.
|
|
178
|
+
*/
|
|
179
|
+
async function discoverDirectories(root, options = {}) {
|
|
180
|
+
const projectRoot = await canonicalRoot(root);
|
|
181
|
+
const themeRoot = await resolveScanDirectory(projectRoot, options.themeDir, DEFAULT_THEME_DIR, "themeDir");
|
|
182
|
+
const pluginRoot = await resolveScanDirectory(projectRoot, options.pluginDir, DEFAULT_PLUGIN_DIR, "pluginDir");
|
|
183
|
+
const budgets = DEFAULT_LOCAL_BUILD_BUDGETS;
|
|
184
|
+
const config = createLocalConfig();
|
|
185
|
+
const files = /* @__PURE__ */ new Set();
|
|
186
|
+
const directories = /* @__PURE__ */ new Set([themeRoot, pluginRoot]);
|
|
187
|
+
const assets = /* @__PURE__ */ new Map();
|
|
188
|
+
const themes = [];
|
|
189
|
+
const plugins = [];
|
|
190
|
+
const themeSources = /* @__PURE__ */ new Map();
|
|
191
|
+
async function recordAssets(collectedAssets) {
|
|
192
|
+
for (const asset of collectedAssets) {
|
|
193
|
+
mergeAsset(assets, asset);
|
|
194
|
+
files.add(resolve(projectRoot, asset.path));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const themeDirectories = await childDirectories(themeRoot);
|
|
198
|
+
for (const directory of themeDirectories) directories.add(directory);
|
|
199
|
+
for (const directory of themeDirectories) {
|
|
200
|
+
const stylesheet = join(directory, THEME_STYLESHEET);
|
|
201
|
+
if (!await isFile(stylesheet)) continue;
|
|
202
|
+
const folder = basename(directory);
|
|
203
|
+
const resourceId = `directory-theme/${folder}.css`;
|
|
204
|
+
const inlined = await inlineStylesheet(stylesheet, resourceId, projectRoot, config, budgets);
|
|
205
|
+
files.add(stylesheet);
|
|
206
|
+
await recordAssets(inlined.assets);
|
|
207
|
+
const metadataFile = join(directory, THEME_METADATA);
|
|
208
|
+
const metadata = await readThemeMetadata(metadataFile);
|
|
209
|
+
files.add(metadataFile);
|
|
210
|
+
let theme;
|
|
211
|
+
try {
|
|
212
|
+
theme = defineLocalTheme(buildThemeInput(folder, resourceId, inlined.css, metadata));
|
|
213
|
+
} catch (error) {
|
|
214
|
+
throw new Error(`Invalid theme ${metadata === null ? stylesheet : metadataFile}: ${messageOf$1(error)}`);
|
|
215
|
+
}
|
|
216
|
+
themes.push(Object.freeze({
|
|
217
|
+
file: stylesheet,
|
|
218
|
+
theme
|
|
219
|
+
}));
|
|
220
|
+
themeSources.set(stylesheet, metadata === null ? stylesheet : metadataFile);
|
|
221
|
+
}
|
|
222
|
+
themes.sort((left, right) => compareCodeUnits(left.file, right.file));
|
|
223
|
+
const names = /* @__PURE__ */ new Map();
|
|
224
|
+
const ids = /* @__PURE__ */ new Map();
|
|
225
|
+
for (const discovered of themes) {
|
|
226
|
+
const source = themeSources.get(discovered.file) ?? discovered.file;
|
|
227
|
+
const previousName = names.get(discovered.theme.name);
|
|
228
|
+
if (previousName !== void 0) throw new Error(`Theme name "${discovered.theme.name}" is declared by both ${previousName} and ${source}.`);
|
|
229
|
+
names.set(discovered.theme.name, source);
|
|
230
|
+
const previousId = ids.get(discovered.theme.id);
|
|
231
|
+
if (previousId !== void 0) throw new Error(`Theme id "${discovered.theme.id}" is declared by both ${previousId} and ${source}.`);
|
|
232
|
+
ids.set(discovered.theme.id, source);
|
|
233
|
+
}
|
|
234
|
+
const pluginDirectories = await childDirectories(pluginRoot);
|
|
235
|
+
for (const directory of pluginDirectories) directories.add(directory);
|
|
236
|
+
for (const directory of pluginDirectories) {
|
|
237
|
+
const entries = [];
|
|
238
|
+
for (const name of PLUGIN_ENTRIES) {
|
|
239
|
+
const candidate = join(directory, name);
|
|
240
|
+
if (await isFile(candidate)) entries.push(candidate);
|
|
241
|
+
}
|
|
242
|
+
if (entries.length === 0) continue;
|
|
243
|
+
if (entries.length > 1) throw new Error(`Plugin directory ${directory} declares more than one entry: ${entries.join(", ")}.`);
|
|
244
|
+
const entry = entries[0];
|
|
245
|
+
const folder = basename(directory);
|
|
246
|
+
files.add(entry);
|
|
247
|
+
const stylesheet = join(directory, COMPONENT_STYLESHEET);
|
|
248
|
+
files.add(stylesheet);
|
|
249
|
+
const resources = [];
|
|
250
|
+
if (await isFile(stylesheet)) {
|
|
251
|
+
const resourceId = `directory-plugin/${folder}.css`;
|
|
252
|
+
const inlined = await inlineStylesheet(stylesheet, resourceId, projectRoot, config, budgets);
|
|
253
|
+
await recordAssets(inlined.assets);
|
|
254
|
+
resources.push(Object.freeze({
|
|
255
|
+
id: resourceId,
|
|
256
|
+
css: inlined.css
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
plugins.push(Object.freeze({
|
|
260
|
+
file: entry,
|
|
261
|
+
resources: Object.freeze(resources)
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
plugins.sort((left, right) => compareCodeUnits(left.file, right.file));
|
|
265
|
+
const sortedAssets = [...assets.values()].sort((left, right) => compareCodeUnits(left.path, right.path));
|
|
266
|
+
return Object.freeze({
|
|
267
|
+
themes: Object.freeze(themes),
|
|
268
|
+
plugins: Object.freeze(plugins),
|
|
269
|
+
files: Object.freeze(sortedUnique(files)),
|
|
270
|
+
directories: Object.freeze(sortedUnique(directories)),
|
|
271
|
+
assets: Object.freeze(sortedAssets)
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
// src/vite/registration.ts
|
|
275
|
+
function normalize$1(file) {
|
|
276
|
+
return file.replaceAll("\\", "/");
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Resolve the package exported by one `plugin/` entry module and classify it.
|
|
280
|
+
*
|
|
281
|
+
* A `LocalReactPresetPackage` is recognized by its protocol before ordinary
|
|
282
|
+
* package validation, so its implementation array is not mistaken for explicit
|
|
283
|
+
* components. An entry that provides both kinds, or a preset-like export with a
|
|
284
|
+
* wrong or missing protocol, is an error instead of a guess. The same default
|
|
285
|
+
* and single-named-export precedence as {@link readLocalReactPackage} applies.
|
|
286
|
+
*
|
|
287
|
+
* The protocol is a parameter so the generated registration module can inline
|
|
288
|
+
* this function without depending on module scope.
|
|
289
|
+
*/
|
|
290
|
+
function classifyLocalEntryPackage(namespace, file, presetProtocol) {
|
|
291
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
292
|
+
const isComponent = (value) => isRecord(value) && isRecord(value.definition) && typeof value.definition.id === "string" && typeof value.definition.name === "string" && typeof value.render === "function";
|
|
293
|
+
const isPreset = (value) => isRecord(value) && value.protocol === presetProtocol && isRecord(value.preset) && Array.isArray(value.components) && value.components.every(isComponent) && (value.resources === void 0 || Array.isArray(value.resources)) && (value.notices === void 0 || Array.isArray(value.notices));
|
|
294
|
+
const isPackage = (value) => isRecord(value) && Array.isArray(value.components) && value.components.every(isComponent) && (value.resources === void 0 || Array.isArray(value.resources)) && (value.themes === void 0 || Array.isArray(value.themes)) && (value.notices === void 0 || Array.isArray(value.notices));
|
|
295
|
+
if (!isRecord(namespace)) throw new Error(`ReactiveMD package entry ${file} did not provide a module namespace.`);
|
|
296
|
+
const entries = [];
|
|
297
|
+
if (Object.hasOwn(namespace, "default")) entries.push({
|
|
298
|
+
name: "default",
|
|
299
|
+
value: namespace.default
|
|
300
|
+
});
|
|
301
|
+
for (const key of Object.keys(namespace)) if (key !== "default") entries.push({
|
|
302
|
+
name: key,
|
|
303
|
+
value: namespace[key]
|
|
304
|
+
});
|
|
305
|
+
const distinct = [];
|
|
306
|
+
const seen = /* @__PURE__ */ new Set();
|
|
307
|
+
for (const entry of entries) {
|
|
308
|
+
const value = entry.value;
|
|
309
|
+
if (typeof value !== "object" || value === null) continue;
|
|
310
|
+
if (seen.has(value)) continue;
|
|
311
|
+
seen.add(value);
|
|
312
|
+
distinct.push(entry);
|
|
313
|
+
}
|
|
314
|
+
for (const entry of distinct) {
|
|
315
|
+
const value = entry.value;
|
|
316
|
+
if (!isRecord(value)) continue;
|
|
317
|
+
if (!(Object.hasOwn(value, "preset") || Object.hasOwn(value, "protocol") && Array.isArray(value.components)) && value.protocol !== presetProtocol) continue;
|
|
318
|
+
if (value.protocol !== presetProtocol) throw new Error(`ReactiveMD package entry ${file} export "${entry.name}" declares unsupported React preset protocol ${JSON.stringify(value.protocol)}; expected "${presetProtocol}".`);
|
|
319
|
+
if (!isPreset(value)) throw new Error(`ReactiveMD package entry ${file} export "${entry.name}" declares protocol "${presetProtocol}" but is not a valid LocalReactPresetPackage.`);
|
|
320
|
+
}
|
|
321
|
+
const presets = distinct.filter((entry) => isPreset(entry.value));
|
|
322
|
+
const packages = distinct.filter((entry) => !isPreset(entry.value) && isPackage(entry.value));
|
|
323
|
+
if (presets.length > 0 && packages.length > 0) throw new Error(`ReactiveMD package entry ${file} exports both a LocalReactPresetPackage ("${presets[0].name}") and a LocalReactPackage ("${packages[0].name}"); export exactly one package or preset package.`);
|
|
324
|
+
const candidates = presets.length > 0 ? presets : packages;
|
|
325
|
+
const preferred = distinct.find((entry) => entry.name === "default");
|
|
326
|
+
const chosen = preferred !== void 0 && candidates.includes(preferred) ? preferred : candidates.length === 1 ? candidates[0] : void 0;
|
|
327
|
+
if (chosen !== void 0) return presets.length > 0 ? {
|
|
328
|
+
kind: "preset",
|
|
329
|
+
value: chosen.value
|
|
330
|
+
} : {
|
|
331
|
+
kind: "package",
|
|
332
|
+
value: chosen.value
|
|
333
|
+
};
|
|
334
|
+
if (candidates.length > 1) {
|
|
335
|
+
const kind = presets.length > 0 ? "LocalReactPresetPackage" : "LocalReactPackage";
|
|
336
|
+
throw new Error(`ReactiveMD package entry ${file} exports more than one distinct ${kind} (${candidates.map((entry) => entry.name).join(", ")}); export one default package or exactly one distinct named package.`);
|
|
337
|
+
}
|
|
338
|
+
throw new Error(`ReactiveMD package entry ${file} must export a LocalReactPackage or LocalReactPresetPackage as its default export or as exactly one distinct named export.`);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Reject duplicate component identities and theme identities across entries.
|
|
342
|
+
*
|
|
343
|
+
* The first owner wins the reporting order; a later duplicate names both source
|
|
344
|
+
* entries so neither is silently overwritten.
|
|
345
|
+
*/
|
|
346
|
+
function assertUniqueRegistration(components, themes) {
|
|
347
|
+
const componentIds = /* @__PURE__ */ new Map();
|
|
348
|
+
const componentNames = /* @__PURE__ */ new Map();
|
|
349
|
+
for (const item of components) {
|
|
350
|
+
const priorId = componentIds.get(item.id);
|
|
351
|
+
if (priorId !== void 0) throw new Error(`ReactiveMD component id "${item.id}" is declared by ${priorId} and ${item.file}.`);
|
|
352
|
+
componentIds.set(item.id, item.file);
|
|
353
|
+
const priorName = componentNames.get(item.name);
|
|
354
|
+
if (priorName !== void 0) throw new Error(`ReactiveMD component tag <${item.name}> is declared by ${priorName} and ${item.file}.`);
|
|
355
|
+
componentNames.set(item.name, item.file);
|
|
356
|
+
}
|
|
357
|
+
const themeIds = /* @__PURE__ */ new Map();
|
|
358
|
+
const themeNames = /* @__PURE__ */ new Map();
|
|
359
|
+
for (const item of themes) {
|
|
360
|
+
const priorId = themeIds.get(item.id);
|
|
361
|
+
if (priorId !== void 0) throw new Error(`ReactiveMD theme id "${item.id}" is declared by ${priorId} and ${item.file}.`);
|
|
362
|
+
themeIds.set(item.id, item.file);
|
|
363
|
+
const priorName = themeNames.get(item.name);
|
|
364
|
+
if (priorName !== void 0) throw new Error(`ReactiveMD theme name "${item.name}" is declared by ${priorName} and ${item.file}.`);
|
|
365
|
+
themeNames.set(item.name, item.file);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/** Serialize discovery facts without functions or derived config. */
|
|
369
|
+
function discoveryMetadata(discovery) {
|
|
370
|
+
return {
|
|
371
|
+
files: Object.freeze(discovery.files.map(normalize$1)),
|
|
372
|
+
directories: Object.freeze(discovery.directories.map(normalize$1)),
|
|
373
|
+
themes: Object.freeze(discovery.themes.map((item) => Object.freeze({
|
|
374
|
+
file: normalize$1(item.file),
|
|
375
|
+
id: item.theme.id,
|
|
376
|
+
name: item.theme.name
|
|
377
|
+
}))),
|
|
378
|
+
plugins: Object.freeze(discovery.plugins.map((item) => Object.freeze({
|
|
379
|
+
file: normalize$1(item.file),
|
|
380
|
+
resources: Object.freeze(item.resources.map((resource) => resource.id))
|
|
381
|
+
}))),
|
|
382
|
+
assets: Object.freeze(discovery.assets.map((asset) => Object.freeze({
|
|
383
|
+
path: asset.path,
|
|
384
|
+
digest: asset.digest,
|
|
385
|
+
bytes: asset.bytes,
|
|
386
|
+
mime: asset.mime
|
|
387
|
+
})))
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Generate the single registration module used by every consumer.
|
|
392
|
+
*
|
|
393
|
+
* Themes are plain data, so the snapshot is embedded directly. Plugin entry
|
|
394
|
+
* modules are imported so their packages and implementations stay live under
|
|
395
|
+
* the normal Vite dependency graph. Preset entries go to `host.presets`; the
|
|
396
|
+
* built-in default is prepended unless `defaultPreset` is false. The generated
|
|
397
|
+
* module exports mutable bindings so a theme stylesheet refresh can replace the
|
|
398
|
+
* host without rebuilding the document runtime; the SDK host itself stays
|
|
399
|
+
* frozen.
|
|
400
|
+
*/
|
|
401
|
+
function createDirectoryRegistration(discovery, styleId, options = {}) {
|
|
402
|
+
const installDefaultPreset = options.defaultPreset !== false;
|
|
403
|
+
const themes = discovery.themes.map((item) => Object.freeze({
|
|
404
|
+
file: normalize$1(item.file),
|
|
405
|
+
theme: item.theme
|
|
406
|
+
}));
|
|
407
|
+
const plugins = discovery.plugins.map((item) => Object.freeze({
|
|
408
|
+
file: normalize$1(item.file),
|
|
409
|
+
resources: item.resources
|
|
410
|
+
}));
|
|
411
|
+
const imports = plugins.map((item, index) => `import * as __rmdPlugin${index} from ${JSON.stringify(item.file)};`).join("\n");
|
|
412
|
+
const pluginTable = plugins.map((item, index) => ` { file: ${JSON.stringify(item.file)}, namespace: __rmdPlugin${index}, resources: ${JSON.stringify(item.resources)} }`).join(",\n");
|
|
413
|
+
const metadata = discoveryMetadata(discovery);
|
|
414
|
+
const code = `${imports}
|
|
415
|
+
import { createReactHost } from "reactive-md/react";
|
|
416
|
+
|
|
417
|
+
const __rmdClassifyEntry = ${classifyLocalEntryPackage.toString().replace(/^export\s+/, "")};
|
|
418
|
+
|
|
419
|
+
const __rmdAssertUnique = ${assertUniqueRegistration.toString().replace(/^export\s+/, "")};
|
|
420
|
+
|
|
421
|
+
const __rmdInstallDefaultPreset = ${JSON.stringify(installDefaultPreset)};
|
|
422
|
+
const __rmdPresetProtocol = ${JSON.stringify(LOCAL_REACT_PRESET_PROTOCOL)};
|
|
423
|
+
const __rmdThemeEntries = ${JSON.stringify(themes)};
|
|
424
|
+
const __rmdPluginEntries = [
|
|
425
|
+
${pluginTable}
|
|
426
|
+
];
|
|
427
|
+
export let discovery = ${JSON.stringify(metadata)};
|
|
428
|
+
export const extensions = Object.freeze({});
|
|
429
|
+
|
|
430
|
+
function __rmdCompose(directoryEntries) {
|
|
431
|
+
const packages = [];
|
|
432
|
+
const presets = __rmdInstallDefaultPreset ? ["default"] : [];
|
|
433
|
+
const components = [];
|
|
434
|
+
const themeOwners = [];
|
|
435
|
+
for (const entry of __rmdPluginEntries) {
|
|
436
|
+
const found = __rmdClassifyEntry(entry.namespace, entry.file, __rmdPresetProtocol);
|
|
437
|
+
if (found.kind === "preset") {
|
|
438
|
+
const preset = found.value;
|
|
439
|
+
presets.push({ ...preset, resources: [...(preset.resources ?? []), ...entry.resources] });
|
|
440
|
+
for (const component of preset.components) {
|
|
441
|
+
const definition = component && component.definition;
|
|
442
|
+
if (!definition || typeof definition.id !== "string" || typeof definition.name !== "string") {
|
|
443
|
+
throw new Error("ReactiveMD preset entry " + entry.file + " contains a component without a manifest id and name.");
|
|
444
|
+
}
|
|
445
|
+
components.push({ file: entry.file, id: definition.id, name: definition.name });
|
|
446
|
+
}
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const pkg = found.value;
|
|
450
|
+
const resources = [...(pkg.resources ?? []), ...entry.resources];
|
|
451
|
+
packages.push({ ...pkg, resources });
|
|
452
|
+
for (const component of pkg.components) {
|
|
453
|
+
const definition = component && component.definition;
|
|
454
|
+
if (!definition || typeof definition.id !== "string" || typeof definition.name !== "string") {
|
|
455
|
+
throw new Error("ReactiveMD package entry " + entry.file + " contains a component without a manifest id and name.");
|
|
456
|
+
}
|
|
457
|
+
components.push({ file: entry.file, id: definition.id, name: definition.name });
|
|
458
|
+
}
|
|
459
|
+
for (const theme of pkg.themes ?? []) {
|
|
460
|
+
themeOwners.push({ file: entry.file, id: theme.id, name: theme.name });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
for (const entry of directoryEntries) {
|
|
464
|
+
themeOwners.push({ file: entry.file, id: entry.theme.id, name: entry.theme.name });
|
|
465
|
+
}
|
|
466
|
+
__rmdAssertUnique(components, themeOwners);
|
|
467
|
+
const notices = [];
|
|
468
|
+
for (const entry of __rmdPluginEntries) {
|
|
469
|
+
if (Array.isArray(entry.namespace.notices)) notices.push(...entry.namespace.notices);
|
|
470
|
+
}
|
|
471
|
+
const themes = directoryEntries.map((entry) => entry.theme);
|
|
472
|
+
// Directory styles are host resources; manifests need not reference them.
|
|
473
|
+
const resources = __rmdPluginEntries.flatMap(entry => entry.resources);
|
|
474
|
+
const host = createReactHost({ packages, themes, notices, presets, resources });
|
|
475
|
+
return { host };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
let __rmdState = __rmdCompose(__rmdThemeEntries);
|
|
479
|
+
export let host = __rmdState.host;
|
|
480
|
+
export let config = host.config;
|
|
481
|
+
export let reactConfig = host.reactConfig;
|
|
482
|
+
export let resources = host.resources;
|
|
483
|
+
export let css = host.css;
|
|
484
|
+
export let notices = host.notices;
|
|
485
|
+
let __rmdStyle;
|
|
486
|
+
if (typeof document !== "undefined") {
|
|
487
|
+
__rmdStyle = document.createElement("style");
|
|
488
|
+
__rmdStyle.dataset.reactiveMdHost = ${JSON.stringify(styleId)};
|
|
489
|
+
__rmdStyle.textContent = css;
|
|
490
|
+
document.head.append(__rmdStyle);
|
|
491
|
+
}
|
|
492
|
+
if (import.meta.hot) {
|
|
493
|
+
import.meta.hot.dispose(() => { __rmdStyle?.remove(); });
|
|
494
|
+
import.meta.hot.on("reactive-md:themes", (payload) => {
|
|
495
|
+
if (!payload || !Array.isArray(payload.themes)) return;
|
|
496
|
+
__rmdState = __rmdCompose(payload.themes);
|
|
497
|
+
host = __rmdState.host;
|
|
498
|
+
config = host.config;
|
|
499
|
+
reactConfig = host.reactConfig;
|
|
500
|
+
resources = host.resources;
|
|
501
|
+
css = host.css;
|
|
502
|
+
notices = host.notices;
|
|
503
|
+
if (payload.discovery !== undefined) discovery = payload.discovery;
|
|
504
|
+
if (__rmdStyle) __rmdStyle.textContent = css;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
`;
|
|
508
|
+
return Object.freeze({
|
|
509
|
+
code,
|
|
510
|
+
files: Object.freeze(discovery.files.map(normalize$1))
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Merge scanner assets into the offline build result. Later entries never
|
|
515
|
+
* replace a collector asset with the same path; the merged list drives both
|
|
516
|
+
* `bundle.assets` and the manifest's `inlinedAssets`.
|
|
517
|
+
*/
|
|
518
|
+
function mergeDiscoveredAssets(bundle, assets) {
|
|
519
|
+
if (assets.length === 0) return bundle;
|
|
520
|
+
const byPath = new Map(bundle.assets.map((asset) => [asset.path, asset]));
|
|
521
|
+
let added = false;
|
|
522
|
+
for (const asset of assets) {
|
|
523
|
+
const existing = byPath.get(asset.path);
|
|
524
|
+
if (existing) {
|
|
525
|
+
if (existing.digest !== asset.digest || existing.bytes !== asset.bytes || existing.mime !== asset.mime) throw new Error("ReactiveMD asset " + asset.path + " has conflicting contents.");
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
byPath.set(asset.path, asset);
|
|
529
|
+
added = true;
|
|
530
|
+
}
|
|
531
|
+
if (!added) return bundle;
|
|
532
|
+
const merged = Object.freeze([...byPath.values()].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
533
|
+
return Object.freeze({
|
|
534
|
+
...bundle,
|
|
535
|
+
assets: merged,
|
|
536
|
+
manifest: Object.freeze({
|
|
537
|
+
...bundle.manifest,
|
|
538
|
+
inlinedAssets: merged
|
|
539
|
+
})
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/** Theme entries from one snapshot, for the development refresh payload. */
|
|
543
|
+
function discoveredThemes(discovery) {
|
|
544
|
+
return Object.freeze(discovery.themes.map((item) => Object.freeze({
|
|
545
|
+
file: normalize$1(item.file),
|
|
546
|
+
theme: item.theme
|
|
547
|
+
})));
|
|
548
|
+
}
|
|
549
|
+
// src/vite/index.ts
|
|
550
|
+
var HOST = "virtual:reactive-md/host";
|
|
551
|
+
var BUNDLE = "virtual:reactive-md/bundle";
|
|
552
|
+
var REGISTRATION = "virtual:reactive-md/registration";
|
|
553
|
+
var RESOLVED = (id) => `\0${id}`;
|
|
554
|
+
var PLUGIN_ENTRY = /^index\.(?:ts|tsx|js|jsx|mts|mjs)$/;
|
|
555
|
+
var normalize = (file) => file.replaceAll("\\", "/");
|
|
556
|
+
var messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
557
|
+
var OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
558
|
+
"extensions",
|
|
559
|
+
"themeDir",
|
|
560
|
+
"pluginDir",
|
|
561
|
+
"defaultPreset"
|
|
562
|
+
]);
|
|
563
|
+
function readLocalModule(value) {
|
|
564
|
+
if (typeof value !== "string" || !value.trim() || /^[a-z]+:\/\//i.test(value)) throw new TypeError("reactiveMd requires a local extensions module.");
|
|
565
|
+
return value.trim();
|
|
566
|
+
}
|
|
567
|
+
function readRelativeDirectory(value, key) {
|
|
568
|
+
if (typeof value !== "string" || !value.trim()) throw new TypeError(`reactiveMd ${key} must be a non-empty directory path.`);
|
|
569
|
+
const path = value.trim();
|
|
570
|
+
const normalized = normalize(path);
|
|
571
|
+
if (/^[a-z]+:\/\//i.test(path) || isAbsolute(path) || normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized) || normalized.split("/").includes("..")) throw new TypeError(`reactiveMd ${key} must be a relative directory inside the Vite root.`);
|
|
572
|
+
return path;
|
|
573
|
+
}
|
|
574
|
+
/** Directory and manual options cannot be combined; nothing is guessed. */
|
|
575
|
+
function readOptions(value) {
|
|
576
|
+
if (value === void 0) return { kind: "directories" };
|
|
577
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("reactiveMd options must be an object.");
|
|
578
|
+
const record = value;
|
|
579
|
+
for (const key of Object.keys(record)) if (!OPTION_KEYS.has(key)) throw new TypeError(`reactiveMd does not accept the "${key}" option.`);
|
|
580
|
+
const hasExtensions = Object.hasOwn(record, "extensions");
|
|
581
|
+
const hasThemeDir = Object.hasOwn(record, "themeDir");
|
|
582
|
+
const hasPluginDir = Object.hasOwn(record, "pluginDir");
|
|
583
|
+
const hasDefaultPreset = Object.hasOwn(record, "defaultPreset");
|
|
584
|
+
if (hasExtensions && (hasThemeDir || hasPluginDir || hasDefaultPreset)) throw new TypeError("reactiveMd options cannot mix \"extensions\" with \"themeDir\", \"pluginDir\" or \"defaultPreset\".");
|
|
585
|
+
if (hasDefaultPreset && typeof record.defaultPreset !== "boolean") throw new TypeError("reactiveMd defaultPreset must be a boolean.");
|
|
586
|
+
if (hasExtensions) return {
|
|
587
|
+
kind: "manual",
|
|
588
|
+
entry: readLocalModule(record.extensions)
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
kind: "directories",
|
|
592
|
+
...hasThemeDir ? { themeDir: readRelativeDirectory(record.themeDir, "themeDir") } : {},
|
|
593
|
+
...hasPluginDir ? { pluginDir: readRelativeDirectory(record.pluginDir, "pluginDir") } : {},
|
|
594
|
+
...hasDefaultPreset ? { defaultPreset: record.defaultPreset } : {}
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function packageEntries() {
|
|
598
|
+
let directory = dirname(fileURLToPath(import.meta.url));
|
|
599
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
600
|
+
try {
|
|
601
|
+
const metadata = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
602
|
+
if (metadata.name === "reactive-md") return Object.entries(metadata.exports).filter(([, value]) => value && typeof value === "object" && "import" in value).map(([name]) => name === "." ? "reactive-md" : `reactive-md/${name.slice(2)}`);
|
|
603
|
+
} catch {}
|
|
604
|
+
directory = dirname(directory);
|
|
605
|
+
}
|
|
606
|
+
throw new Error("Cannot locate the installed reactive-md package exports.");
|
|
607
|
+
}
|
|
608
|
+
async function buildHost(config, source, watch) {
|
|
609
|
+
const registration = source.registration;
|
|
610
|
+
const nodeBuild = await build({
|
|
611
|
+
root: config.root,
|
|
612
|
+
configFile: false,
|
|
613
|
+
logLevel: "warn",
|
|
614
|
+
publicDir: false,
|
|
615
|
+
ssr: { noExternal: true },
|
|
616
|
+
oxc: { jsx: { development: false } },
|
|
617
|
+
plugins: [{
|
|
618
|
+
name: "reactive-md-node-host",
|
|
619
|
+
resolveId(id) {
|
|
620
|
+
if (id === "virtual:rmd-node-host") return "\0rmd-node-host";
|
|
621
|
+
if (registration && id === REGISTRATION) return RESOLVED(REGISTRATION);
|
|
622
|
+
return null;
|
|
623
|
+
},
|
|
624
|
+
load(id) {
|
|
625
|
+
if (registration && id === RESOLVED(REGISTRATION)) return registration.code;
|
|
626
|
+
if (id !== "\0rmd-node-host") return null;
|
|
627
|
+
const entry = registration ? REGISTRATION : normalize(source.entry ?? "");
|
|
628
|
+
return `import {host} from ${JSON.stringify(entry)};
|
|
629
|
+
export const {config,reactConfig,resources,notices}=host;
|
|
630
|
+
export const root=${JSON.stringify(config.root)};
|
|
631
|
+
export const allowlist=[root];`;
|
|
632
|
+
},
|
|
633
|
+
moduleParsed(info) {
|
|
634
|
+
if (!info.id.startsWith("\0")) watch(normalize(info.id.split("?")[0]));
|
|
635
|
+
}
|
|
636
|
+
}],
|
|
637
|
+
build: {
|
|
638
|
+
write: false,
|
|
639
|
+
ssr: true,
|
|
640
|
+
minify: false,
|
|
641
|
+
rolldownOptions: {
|
|
642
|
+
input: "virtual:rmd-node-host",
|
|
643
|
+
external: [
|
|
644
|
+
/^reactive-md(?:\/|$)/,
|
|
645
|
+
/^react(?:\/|$)/,
|
|
646
|
+
/^react-dom(?:\/|$)/
|
|
647
|
+
],
|
|
648
|
+
output: {
|
|
649
|
+
format: "es",
|
|
650
|
+
codeSplitting: false
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
if (Array.isArray(nodeBuild) || !("output" in nodeBuild)) throw new Error("Unexpected ReactiveMD host build output.");
|
|
656
|
+
const chunks = nodeBuild.output.filter((item) => item.type === "chunk");
|
|
657
|
+
if (chunks.length !== 1 || nodeBuild.output.length !== 1) throw new Error("The host must build to one ESM module with inline resources.");
|
|
658
|
+
const code = chunks[0].code;
|
|
659
|
+
const digest = createHash("sha256").update(code).digest("hex");
|
|
660
|
+
const directory = join(config.root, ".reactive-md");
|
|
661
|
+
await mkdir(directory, { recursive: true });
|
|
662
|
+
const hostEntry = join(directory, `host-${digest}.mjs`);
|
|
663
|
+
await writeFile(hostEntry, code);
|
|
664
|
+
try {
|
|
665
|
+
return await buildLocalStandaloneBundle({ entry: hostEntry });
|
|
666
|
+
} catch (error) {
|
|
667
|
+
if (error instanceof LocalBuildError && error.diagnostics.length > 0 && error.diagnostics.every((item) => item.code === "local.extension.export-capability")) return {
|
|
668
|
+
error: error.message,
|
|
669
|
+
diagnostics: error.diagnostics
|
|
670
|
+
};
|
|
671
|
+
throw error;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function insidePath(file, directory) {
|
|
675
|
+
return file === directory || file.startsWith(`${directory}/`);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Optional Node-only adapter. Directory mode discovers `theme/` and `plugin/`
|
|
679
|
+
* once per snapshot and generates one registration module; manual mode keeps
|
|
680
|
+
* the explicit `extensions` entry. Registration and code execution stay
|
|
681
|
+
* explicit on the consumer side.
|
|
682
|
+
*/
|
|
683
|
+
function reactiveMd(options = {}) {
|
|
684
|
+
const mode = readOptions(options);
|
|
685
|
+
const installDefaultPreset = mode.kind === "directories" ? mode.defaultPreset !== false : true;
|
|
686
|
+
let config;
|
|
687
|
+
let manualEntry;
|
|
688
|
+
let themeOption;
|
|
689
|
+
let pluginOption;
|
|
690
|
+
let themeRoot = "";
|
|
691
|
+
let pluginRoot = "";
|
|
692
|
+
let state;
|
|
693
|
+
let knownFiles = /* @__PURE__ */ new Set();
|
|
694
|
+
let generation = 0;
|
|
695
|
+
let inflight;
|
|
696
|
+
let pending;
|
|
697
|
+
const watched = /* @__PURE__ */ new Set();
|
|
698
|
+
if (mode.kind === "directories") {
|
|
699
|
+
themeOption = mode.themeDir;
|
|
700
|
+
pluginOption = mode.pluginDir;
|
|
701
|
+
}
|
|
702
|
+
function invalidateAll() {
|
|
703
|
+
generation += 1;
|
|
704
|
+
state = void 0;
|
|
705
|
+
inflight = void 0;
|
|
706
|
+
pending = void 0;
|
|
707
|
+
}
|
|
708
|
+
async function loadSnapshot() {
|
|
709
|
+
const discovery = await discoverDirectories(config.root, Object.freeze({
|
|
710
|
+
...themeOption === void 0 ? {} : { themeDir: themeOption },
|
|
711
|
+
...pluginOption === void 0 ? {} : { pluginDir: pluginOption }
|
|
712
|
+
}));
|
|
713
|
+
const registration = createDirectoryRegistration(discovery, createHash("sha256").update(config.root).digest("hex").slice(0, 16), { defaultPreset: installDefaultPreset });
|
|
714
|
+
return Object.freeze({
|
|
715
|
+
discovery,
|
|
716
|
+
registration,
|
|
717
|
+
themeRoot: resolve(config.root, themeOption ?? "theme"),
|
|
718
|
+
pluginRoot: resolve(config.root, pluginOption ?? "plugin"),
|
|
719
|
+
files: new Set(discovery.files.map(normalize))
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
function snapshot() {
|
|
723
|
+
if (state) return Promise.resolve(state);
|
|
724
|
+
const current = generation;
|
|
725
|
+
if (inflight?.generation === current) return inflight.promise;
|
|
726
|
+
const promise = (async () => {
|
|
727
|
+
const value = await loadSnapshot();
|
|
728
|
+
if (current !== generation) return snapshot();
|
|
729
|
+
state = value;
|
|
730
|
+
knownFiles = value.files;
|
|
731
|
+
return value;
|
|
732
|
+
})();
|
|
733
|
+
const record = {
|
|
734
|
+
generation: current,
|
|
735
|
+
promise
|
|
736
|
+
};
|
|
737
|
+
inflight = record;
|
|
738
|
+
promise.finally(() => {
|
|
739
|
+
if (inflight === record) inflight = void 0;
|
|
740
|
+
}).catch(() => {});
|
|
741
|
+
return promise;
|
|
742
|
+
}
|
|
743
|
+
/** `style` is a theme stylesheet/asset refresh; `structure` needs a reload. */
|
|
744
|
+
function classify(file) {
|
|
745
|
+
if (mode.kind !== "directories") return "none";
|
|
746
|
+
const target = normalize(file);
|
|
747
|
+
const theme = normalize(themeRoot);
|
|
748
|
+
if (insidePath(target, normalize(pluginRoot))) {
|
|
749
|
+
const name = target.slice(target.lastIndexOf("/") + 1);
|
|
750
|
+
if (PLUGIN_ENTRY.test(name) || name === "component.css") return "structure";
|
|
751
|
+
return knownFiles.has(target) ? "structure" : "none";
|
|
752
|
+
}
|
|
753
|
+
if (insidePath(target, theme)) return target.toLowerCase().endsWith(".json") ? "structure" : "style";
|
|
754
|
+
return knownFiles.has(target) ? "structure" : "none";
|
|
755
|
+
}
|
|
756
|
+
function invalidateVirtualModules(server, ids) {
|
|
757
|
+
for (const id of ids) {
|
|
758
|
+
const module = server.moduleGraph.getModuleById(RESOLVED(id));
|
|
759
|
+
if (module) server.moduleGraph.invalidateModule(module);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
function fullReload(server) {
|
|
763
|
+
invalidateAll();
|
|
764
|
+
invalidateVirtualModules(server, [
|
|
765
|
+
HOST,
|
|
766
|
+
REGISTRATION,
|
|
767
|
+
BUNDLE
|
|
768
|
+
]);
|
|
769
|
+
server.ws.send({ type: "full-reload" });
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Re-run discovery and push the new theme packages to the page. The document
|
|
773
|
+
* runtime keeps running; only the managed host stylesheet is replaced.
|
|
774
|
+
*/
|
|
775
|
+
async function refreshThemeStyles(server) {
|
|
776
|
+
invalidateAll();
|
|
777
|
+
let current;
|
|
778
|
+
try {
|
|
779
|
+
current = await snapshot();
|
|
780
|
+
} catch (error) {
|
|
781
|
+
server.config.logger.error(`[reactive-md] ${messageOf(error)}`);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
server.watcher.add([...current.discovery.files]);
|
|
785
|
+
invalidateVirtualModules(server, [
|
|
786
|
+
HOST,
|
|
787
|
+
REGISTRATION,
|
|
788
|
+
BUNDLE
|
|
789
|
+
]);
|
|
790
|
+
server.ws.send({
|
|
791
|
+
type: "custom",
|
|
792
|
+
event: "reactive-md:themes",
|
|
793
|
+
data: {
|
|
794
|
+
themes: discoveredThemes(current.discovery),
|
|
795
|
+
discovery: discoveryMetadata(current.discovery)
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
const bundleModule = server.moduleGraph.getModuleById(RESOLVED(BUNDLE));
|
|
799
|
+
if (bundleModule) await server.reloadModule(bundleModule);
|
|
800
|
+
}
|
|
801
|
+
async function bundle() {
|
|
802
|
+
if (pending) return pending;
|
|
803
|
+
const task = (async () => {
|
|
804
|
+
if (mode.kind === "manual") return buildHost(config, { entry: manualEntry }, (file) => watched.add(file));
|
|
805
|
+
const current = await snapshot();
|
|
806
|
+
for (const file of current.discovery.files) watched.add(normalize(file));
|
|
807
|
+
const built = await buildHost(config, { registration: current.registration }, (file) => watched.add(file));
|
|
808
|
+
return "error" in built ? built : mergeDiscoveredAssets(built, current.discovery.assets);
|
|
809
|
+
})();
|
|
810
|
+
pending = task;
|
|
811
|
+
task.catch(() => {
|
|
812
|
+
if (pending === task) pending = void 0;
|
|
813
|
+
});
|
|
814
|
+
return task;
|
|
815
|
+
}
|
|
816
|
+
return {
|
|
817
|
+
name: "reactive-md",
|
|
818
|
+
config() {
|
|
819
|
+
return {
|
|
820
|
+
optimizeDeps: {
|
|
821
|
+
exclude: packageEntries(),
|
|
822
|
+
include: [
|
|
823
|
+
"react",
|
|
824
|
+
"react/jsx-runtime",
|
|
825
|
+
"react/jsx-dev-runtime",
|
|
826
|
+
"react-dom",
|
|
827
|
+
"react-dom/client"
|
|
828
|
+
]
|
|
829
|
+
},
|
|
830
|
+
resolve: { dedupe: ["react", "react-dom"] }
|
|
831
|
+
};
|
|
832
|
+
},
|
|
833
|
+
configResolved(value) {
|
|
834
|
+
config = value;
|
|
835
|
+
if (mode.kind === "manual") {
|
|
836
|
+
manualEntry = resolve(config.root, mode.entry);
|
|
837
|
+
watched.add(normalize(manualEntry));
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
themeRoot = resolve(config.root, themeOption ?? "theme");
|
|
841
|
+
pluginRoot = resolve(config.root, pluginOption ?? "plugin");
|
|
842
|
+
},
|
|
843
|
+
configureServer(server) {
|
|
844
|
+
if (mode.kind !== "directories") return;
|
|
845
|
+
server.watcher.add([themeRoot, pluginRoot]);
|
|
846
|
+
const onDirectory = (directory) => {
|
|
847
|
+
const target = normalize(directory);
|
|
848
|
+
if (!insidePath(target, normalize(themeRoot)) && !insidePath(target, normalize(pluginRoot))) return;
|
|
849
|
+
fullReload(server);
|
|
850
|
+
};
|
|
851
|
+
const onFile = (file) => {
|
|
852
|
+
const kind = classify(file);
|
|
853
|
+
if (kind === "structure" || normalize(file).endsWith("/theme.css") && insidePath(normalize(file), normalize(themeRoot))) fullReload(server);
|
|
854
|
+
else if (kind === "style") refreshThemeStyles(server);
|
|
855
|
+
};
|
|
856
|
+
server.watcher.on("addDir", onDirectory);
|
|
857
|
+
server.watcher.on("unlinkDir", onDirectory);
|
|
858
|
+
server.watcher.on("add", onFile);
|
|
859
|
+
server.watcher.on("unlink", onFile);
|
|
860
|
+
const cleanup = () => {
|
|
861
|
+
server.watcher.off("addDir", onDirectory);
|
|
862
|
+
server.watcher.off("unlinkDir", onDirectory);
|
|
863
|
+
server.watcher.off("add", onFile);
|
|
864
|
+
server.watcher.off("unlink", onFile);
|
|
865
|
+
};
|
|
866
|
+
server.httpServer?.once("close", cleanup);
|
|
867
|
+
snapshot().then((current) => {
|
|
868
|
+
server.watcher.add([...current.discovery.directories, ...current.discovery.files]);
|
|
869
|
+
}).catch(() => {});
|
|
870
|
+
},
|
|
871
|
+
resolveId(id) {
|
|
872
|
+
if (id === HOST || id === BUNDLE) return RESOLVED(id);
|
|
873
|
+
return mode.kind === "directories" && id === REGISTRATION ? RESOLVED(id) : null;
|
|
874
|
+
},
|
|
875
|
+
async load(id) {
|
|
876
|
+
if (id === RESOLVED(HOST)) {
|
|
877
|
+
if (mode.kind === "manual") {
|
|
878
|
+
this.addWatchFile(manualEntry);
|
|
879
|
+
const styleId = createHash("sha256").update(manualEntry).digest("hex").slice(0, 16);
|
|
880
|
+
return `import * as extensions from ${JSON.stringify(normalize(manualEntry))};
|
|
881
|
+
const {host}=extensions;
|
|
882
|
+
export {host,extensions}; export const {config,reactConfig,resources,css,notices}=host;
|
|
883
|
+
export const discovery=undefined;
|
|
884
|
+
let style;
|
|
885
|
+
if(typeof document!=='undefined'){
|
|
886
|
+
style=document.createElement('style');style.dataset.reactiveMdHost=${JSON.stringify(styleId)};
|
|
887
|
+
style.textContent=host.css;document.head.append(style);
|
|
888
|
+
}
|
|
889
|
+
if(import.meta.hot)import.meta.hot.dispose(()=>style?.remove());`;
|
|
890
|
+
}
|
|
891
|
+
const current = await snapshot();
|
|
892
|
+
for (const file of current.discovery.files) if (existsSync(file)) this.addWatchFile(normalize(file));
|
|
893
|
+
return `export { host, config, reactConfig, resources, css, notices, discovery, extensions } from ${JSON.stringify(REGISTRATION)};`;
|
|
894
|
+
}
|
|
895
|
+
if (mode.kind === "directories" && id === RESOLVED(REGISTRATION)) {
|
|
896
|
+
const current = await snapshot();
|
|
897
|
+
for (const file of current.discovery.files) if (existsSync(file)) this.addWatchFile(normalize(file));
|
|
898
|
+
return current.registration.code;
|
|
899
|
+
}
|
|
900
|
+
if (id !== RESOLVED(BUNDLE)) return null;
|
|
901
|
+
const built = await bundle();
|
|
902
|
+
for (const file of watched) if (existsSync(file)) this.addWatchFile(normalize(file));
|
|
903
|
+
if (mode.kind === "manual") return `export default ${JSON.stringify(built)};`;
|
|
904
|
+
return `let bundle=${JSON.stringify(built)};
|
|
905
|
+
export {bundle as default};
|
|
906
|
+
if(import.meta.hot)import.meta.hot.accept(next=>{if(next)bundle=next.default;});`;
|
|
907
|
+
},
|
|
908
|
+
async generateBundle() {
|
|
909
|
+
const built = await bundle();
|
|
910
|
+
if ("error" in built) this.emitFile({
|
|
911
|
+
type: "asset",
|
|
912
|
+
fileName: "reactive-md-export.json",
|
|
913
|
+
source: JSON.stringify(built, null, 2)
|
|
914
|
+
});
|
|
915
|
+
else {
|
|
916
|
+
const { script, ...metadata } = built;
|
|
917
|
+
this.emitFile({
|
|
918
|
+
type: "asset",
|
|
919
|
+
fileName: "reactive-md-standalone.js",
|
|
920
|
+
source: script
|
|
921
|
+
});
|
|
922
|
+
this.emitFile({
|
|
923
|
+
type: "asset",
|
|
924
|
+
fileName: "reactive-md-export.json",
|
|
925
|
+
source: JSON.stringify({
|
|
926
|
+
...metadata,
|
|
927
|
+
scriptFile: "reactive-md-standalone.js"
|
|
928
|
+
}, null, 2)
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
watchChange(id) {
|
|
933
|
+
const file = normalize(id);
|
|
934
|
+
if (mode.kind === "directories" && classify(file) !== "none") invalidateAll();
|
|
935
|
+
else if (watched.has(file)) pending = void 0;
|
|
936
|
+
},
|
|
937
|
+
async handleHotUpdate(context) {
|
|
938
|
+
if (mode.kind === "manual") {
|
|
939
|
+
if (!watched.has(normalize(context.file))) return;
|
|
940
|
+
pending = void 0;
|
|
941
|
+
for (const id of [HOST, BUNDLE]) {
|
|
942
|
+
const module = context.server.moduleGraph.getModuleById(RESOLVED(id));
|
|
943
|
+
if (module) context.server.moduleGraph.invalidateModule(module);
|
|
944
|
+
}
|
|
945
|
+
context.server.ws.send({ type: "full-reload" });
|
|
946
|
+
return [];
|
|
947
|
+
}
|
|
948
|
+
const kind = classify(context.file);
|
|
949
|
+
if (kind === "none") return;
|
|
950
|
+
if (kind === "structure") {
|
|
951
|
+
fullReload(context.server);
|
|
952
|
+
return [];
|
|
953
|
+
}
|
|
954
|
+
await refreshThemeStyles(context.server);
|
|
955
|
+
return [];
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
export { reactiveMd as default, reactiveMd };
|