UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

54 lines 2.84 kB
import type { LoadCodeMeta, LoadSource, LoadVariantMeta, ParseSource, SourceEnhancers } from "../CodeHighlighter/types.mjs"; import type { CodeContext, ComputeHastDeltasLoader, LoadFallbackCodeLoader, LoadVariantLoader, TransformEngineLoader } from "./CodeContext.mjs"; import type { EditingEngineLoader } from "../useCode/editingEngineCache.mjs"; /** * The host-supplied source loaders. Identical for both providers (passed by the * consumer), so they live on the base props. */ export interface CodeProviderBaseProps { /** Function to load code metadata from a URL */ loadCodeMeta?: LoadCodeMeta; /** Function to load specific variant metadata */ loadVariantMeta?: LoadVariantMeta; /** Function to load raw source code and dependencies */ loadSource?: LoadSource; /** Explicit source enhancers; defaults to the eager emphasis enhancer. */ sourceEnhancers?: SourceEnhancers; } /** * Heavy-function provisioning supplied by a *specific* provider. The eager * `CodeProvider` passes accessors that resolve instantly to statically-bundled * functions; `CodeProviderLazy` passes accessors backed by dynamic `import()`. * Keeping these out of {@link useCodeProviderValue} is what lets the bundler keep * the heavy modules out of the lazy provider's chunk. */ export interface CodeProviderHeavyAccessors { loadCodeFallbackLoader: LoadFallbackCodeLoader; loadIsomorphicCodeVariantLoader: LoadVariantLoader; computeHastDeltasLoader: ComputeHastDeltasLoader; editingEngineLoader: EditingEngineLoader; transformEngineLoader: TransformEngineLoader; /** * Provider-specific default source enhancers. The eager `CodeProvider` passes * the bundled `enhanceCodeEmphasis` (zero-fetch); `CodeProviderLazy` passes the * lazy wrapper so the ~13 KB emphasis chunk stays out of its initial bundle. */ defaultSourceEnhancers: SourceEnhancers; } /** * Builds the {@link CodeContext} value shared by `CodeProvider` and * `CodeProviderLazy`: the (browser-only, lazily-initialized) source parser, the * worker-backed async parser for live editing, the eager synchronous parsers, * and the host loaders - plus whichever heavy-function accessors the provider * supplied. This hook never statically imports the heavy loaders. */ export declare function useCodeProviderValue(props: CodeProviderBaseProps, heavy: CodeProviderHeavyAccessors, /** * Provider-supplied source-parser creator. Eager `CodeProvider` passes a * static `() => createParseSource()`; `CodeProviderLazy` passes a dynamic * `() => import(...).then(m => m.createParseSource())` so the Starry Night * regex engine (vscode-textmate + oniguruma) stays out of the initial bundle. * Either way the consumer already awaits `sourceParser`, so there's no new * first-render penalty. */ createSourceParser: () => Promise<ParseSource>): CodeContext;