@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
23 lines • 1.34 kB
text/typescript
import type { FallbackNode } from "../../CodeHighlighter/fallbackFormat.mjs";
import type { HastRoot, VariantSource } from "../../CodeHighlighter/types.mjs";
/**
* Resolves a `VariantSource` to a live `HastRoot`, sharing one decode per
* source payload across all consumers (`Pre`, `useFileNavigation`,
* `sourceLineCounts`, …). Decompresses `hastCompressed`, parses `hastJson`,
* and returns live HAST trees unchanged. Returns `null` for string sources
* or unrecognized shapes.
*
* When a variant-level `fallback` is provided, the compressed payload is
* decompressed using the fallback text as a DEFLATE dictionary (matching the
* encoder), and each `span.frame` of a freshly decoded tree gets its
* per-frame `data.fallback` restored via `redistributeRootFallback`. Live
* HAST trees are returned untouched — they already carry their per-frame
* fallback and are shared, read-only inputs.
*
* **The returned tree must be treated as read-only.** Multiple consumers
* share the same object; mutating it would leak across them. Callers that
* need to mutate the HAST (e.g. the enhancer pipeline in
* `useSourceEnhancing`) must clone before mutating, and should not use
* this cache.
*/
export declare function decodeHastSource(source: VariantSource | null | undefined, fallback?: FallbackNode[]): HastRoot | null;