@mui/internal-docs-infra 0.11.1-canary.8 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChunkProvider/ChunkContext.d.mts +10 -0
- package/ChunkProvider/ChunkContext.mjs +15 -0
- package/ChunkProvider/ChunkProvider.d.mts +14 -0
- package/ChunkProvider/ChunkProvider.mjs +38 -0
- package/ChunkProvider/PreloadContext.d.mts +14 -0
- package/ChunkProvider/PreloadContext.mjs +18 -0
- package/ChunkProvider/PreloadProvider.d.mts +13 -0
- package/ChunkProvider/PreloadProvider.mjs +33 -0
- package/ChunkProvider/index.d.mts +7 -0
- package/ChunkProvider/index.mjs +7 -0
- package/ChunkProvider/types.d.mts +23 -0
- package/ChunkProvider/types.mjs +1 -0
- package/ChunkProvider/usePreload.d.mts +8 -0
- package/ChunkProvider/usePreload.mjs +21 -0
- package/CodeControllerContext/CodeControllerContext.d.mts +11 -0
- package/CodeControllerContext/CodeControllerContext.mjs +2 -1
- package/CodeHighlighter/CodeHighlighter.d.mts +15 -1
- package/CodeHighlighter/CodeHighlighter.mjs +97 -319
- package/CodeHighlighter/CodeHighlighterChunk.d.mts +42 -0
- package/CodeHighlighter/CodeHighlighterChunk.mjs +77 -0
- package/CodeHighlighter/CodeHighlighterClient.mjs +597 -128
- package/CodeHighlighter/CodeHighlighterContext.d.mts +57 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.mts +14 -2
- package/CodeHighlighter/CodeHighlighterFallbackContext.mjs +1 -3
- package/CodeHighlighter/CodeInitialSourceLoader.d.mts +10 -0
- package/CodeHighlighter/CodeInitialSourceLoader.mjs +108 -0
- package/CodeHighlighter/CodeSourceLoader.d.mts +11 -0
- package/CodeHighlighter/CodeSourceLoader.mjs +128 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.d.mts +47 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.mjs +61 -0
- package/CodeHighlighter/buildStringFallback.d.mts +29 -0
- package/CodeHighlighter/buildStringFallback.mjs +42 -0
- package/CodeHighlighter/codeToFallbackProps.d.mts +31 -2
- package/CodeHighlighter/codeToFallbackProps.mjs +347 -42
- package/CodeHighlighter/createClientProps.d.mts +17 -0
- package/CodeHighlighter/createClientProps.mjs +78 -0
- package/CodeHighlighter/errors.d.mts +6 -0
- package/CodeHighlighter/errors.mjs +10 -0
- package/CodeHighlighter/fallbackCompression.d.mts +96 -0
- package/CodeHighlighter/fallbackCompression.mjs +253 -0
- package/CodeHighlighter/fallbackFormat.d.mts +137 -0
- package/CodeHighlighter/fallbackFormat.mjs +422 -0
- package/CodeHighlighter/index.d.mts +4 -1
- package/CodeHighlighter/index.mjs +3 -1
- package/CodeHighlighter/mergeComments.d.mts +38 -0
- package/CodeHighlighter/mergeComments.mjs +80 -0
- package/CodeHighlighter/prepareInitialSource.d.mts +42 -0
- package/CodeHighlighter/prepareInitialSource.mjs +292 -0
- package/CodeHighlighter/resolveFallbackCritical.d.mts +23 -0
- package/CodeHighlighter/resolveFallbackCritical.mjs +44 -0
- package/CodeHighlighter/types.d.mts +272 -8
- package/CodeHighlighter/useCodeFallback.d.mts +94 -0
- package/CodeHighlighter/useCodeFallback.mjs +204 -0
- package/CodeHighlighter/useGrammarsReady.d.mts +18 -0
- package/CodeHighlighter/useGrammarsReady.mjs +45 -0
- package/CodeHighlighter/useSpeculativeCodePreload.d.mts +26 -0
- package/CodeHighlighter/useSpeculativeCodePreload.mjs +40 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.d.mts +33 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.mjs +58 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.d.mts +23 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.mjs +31 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.d.mts +22 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.mjs +41 -0
- package/CodeProvider/CodeContext.d.mts +47 -12
- package/CodeProvider/CodeContext.mjs +7 -0
- package/CodeProvider/CodeProvider.d.mts +4 -2
- package/CodeProvider/CodeProvider.mjs +40 -102
- package/CodeProvider/CodeProviderLazy.d.mts +40 -0
- package/CodeProvider/CodeProviderLazy.mjs +96 -0
- package/CodeProvider/constants.d.mts +26 -0
- package/CodeProvider/constants.mjs +24 -0
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +22 -2
- package/CodeProvider/index.d.mts +2 -1
- package/CodeProvider/index.mjs +9 -1
- package/CodeProvider/parseSourceWorker.mjs +33 -0
- package/CodeProvider/useCodeProviderValue.d.mts +54 -0
- package/CodeProvider/useCodeProviderValue.mjs +188 -0
- package/CoordinatedLazy/ChunkServerLoader.d.mts +25 -0
- package/CoordinatedLazy/ChunkServerLoader.mjs +97 -0
- package/CoordinatedLazy/CoordinatedContentContext.d.mts +15 -0
- package/CoordinatedLazy/CoordinatedContentContext.mjs +22 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.d.mts +11 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.mjs +13 -0
- package/CoordinatedLazy/CoordinatedGateContext.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedGateContext.mjs +19 -0
- package/CoordinatedLazy/CoordinatedLazy.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedLazy.mjs +86 -0
- package/CoordinatedLazy/CoordinatedLazyClient.d.mts +24 -0
- package/CoordinatedLazy/CoordinatedLazyClient.mjs +65 -0
- package/CoordinatedLazy/LazyContent.d.mts +26 -0
- package/CoordinatedLazy/LazyContent.mjs +80 -0
- package/CoordinatedLazy/LazyContentServer.d.mts +18 -0
- package/CoordinatedLazy/LazyContentServer.mjs +25 -0
- package/CoordinatedLazy/buildChunkRenderInputs.d.mts +8 -0
- package/CoordinatedLazy/buildChunkRenderInputs.mjs +35 -0
- package/CoordinatedLazy/createCoordinatedLazy.d.mts +32 -0
- package/CoordinatedLazy/createCoordinatedLazy.mjs +127 -0
- package/CoordinatedLazy/index.d.mts +14 -0
- package/CoordinatedLazy/index.mjs +18 -0
- package/CoordinatedLazy/resolveChunkRender.d.mts +26 -0
- package/CoordinatedLazy/resolveChunkRender.mjs +73 -0
- package/CoordinatedLazy/types.d.mts +408 -0
- package/CoordinatedLazy/types.mjs +1 -0
- package/CoordinatedLazy/useChunk.d.mts +30 -0
- package/CoordinatedLazy/useChunk.mjs +135 -0
- package/CoordinatedLazy/useCoordinatedFallback.d.mts +12 -0
- package/CoordinatedLazy/useCoordinatedFallback.mjs +40 -0
- package/CoordinatedLazy/useCoordinatedSwap.d.mts +16 -0
- package/CoordinatedLazy/useCoordinatedSwap.mjs +124 -0
- package/LICENSE +1 -1
- package/abstractCreateDemo/abstractCreateDemo.d.mts +54 -3
- package/abstractCreateDemo/abstractCreateDemo.mjs +47 -7
- package/abstractCreateDemo/resolveDemoFlag.d.mts +20 -0
- package/abstractCreateDemo/resolveDemoFlag.mjs +25 -0
- package/abstractCreateStream/abstractCreateStream.d.mts +18 -0
- package/abstractCreateStream/abstractCreateStream.mjs +45 -0
- package/abstractCreateStream/index.d.mts +2 -0
- package/abstractCreateStream/index.mjs +1 -0
- package/abstractCreateStream/types.d.mts +34 -0
- package/abstractCreateStream/types.mjs +1 -0
- package/abstractCreateTypes/TypeCode.mjs +12 -11
- package/abstractCreateTypes/typesToJsx.mjs +30 -9
- package/cli/ensureDemoClients.mjs +4 -148
- package/cli/ensureDemoPages.d.mts +45 -0
- package/cli/ensureDemoPages.mjs +99 -0
- package/cli/fileUtils/index.d.mts +11 -0
- package/cli/fileUtils/index.mjs +48 -0
- package/cli/findDemoIndexFiles.d.mts +15 -0
- package/cli/findDemoIndexFiles.mjs +121 -0
- package/cli/index.mjs +1 -1
- package/cli/loadNextConfig.d.mts +25 -0
- package/cli/loadNextConfig.mjs +60 -1
- package/cli/runBrowser.mjs +1 -1
- package/cli/runValidate.mjs +44 -1
- package/package.json +85 -5
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasis.mjs +30 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.d.mts +17 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs +52 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.d.mts +18 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.mjs +24 -0
- package/pipeline/hastUtils/hast.d.mts +27 -0
- package/pipeline/hastUtils/hastCompression.d.mts +3 -1
- package/pipeline/hastUtils/hastCompression.mjs +9 -1
- package/pipeline/hastUtils/hastDecompress.mjs +10 -4
- package/pipeline/hastUtils/hastDictionary.mjs +9 -0
- package/pipeline/hastUtils/hastUtils.d.mts +4 -3
- package/pipeline/hastUtils/hastUtils.mjs +24 -12
- package/pipeline/hastUtils/index.d.mts +2 -1
- package/pipeline/hastUtils/index.mjs +2 -1
- package/pipeline/hastUtils/stripHighlightingSpans.d.mts +6 -2
- package/pipeline/hastUtils/stripHighlightingSpans.mjs +22 -10
- package/pipeline/lintJavascriptDemoFocus/lintJavascriptDemoFocus.mjs +10 -7
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.d.mts +31 -13
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +50 -55
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.d.mts +78 -0
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs +405 -0
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.d.mts +5 -5
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs +36 -66
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.d.mts +23 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.mjs +92 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.d.mts +19 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.mjs +25 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.d.mts +17 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.mjs +26 -0
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +26 -2
- package/pipeline/loadIsomorphicCodeVariant/diffHast.mjs +563 -19
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.d.mts +49 -0
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.mjs +152 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.d.mts +51 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.mjs +161 -0
- package/pipeline/loadIsomorphicCodeVariant/flattenCodeVariant.mjs +6 -3
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.d.mts +12 -0
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.mjs +44 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.d.mts +16 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.mjs +74 -0
- package/pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs +17 -5
- package/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs +229 -15
- package/pipeline/loadIsomorphicCodeVariant/transformSource.d.mts +2 -2
- package/pipeline/loadIsomorphicCodeVariant/transformSource.mjs +56 -22
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.mts +18 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +11 -7
- package/pipeline/loadServerTypes/hastTypeUtils.d.mts +2 -2
- package/pipeline/loadServerTypes/hastTypeUtils.mjs +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.mjs +1 -1
- package/pipeline/loadServerTypesMeta/extractJSDocText.d.mts +14 -0
- package/pipeline/loadServerTypesMeta/extractJSDocText.mjs +60 -0
- package/pipeline/loadServerTypesMeta/processTypes.mjs +43 -46
- package/pipeline/loadServerTypesText/order.mjs +1 -1
- package/pipeline/loadServerTypesText/parseTypesMarkdown.mjs +3 -1
- package/pipeline/loaderUtils/index.d.mts +0 -1
- package/pipeline/loaderUtils/index.mjs +0 -1
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -1
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +19 -9
- package/pipeline/loaderUtils/resolveModulePath.mjs +23 -1
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +12 -0
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +17 -13
- package/pipeline/parseSource/addLineGutters.mjs +45 -11
- package/pipeline/parseSource/calculateFrameRanges.d.mts +22 -0
- package/pipeline/parseSource/calculateFrameRanges.mjs +69 -25
- package/pipeline/parseSource/detectGrammarScopes.d.mts +13 -0
- package/pipeline/parseSource/detectGrammarScopes.mjs +35 -0
- package/pipeline/parseSource/extendSyntaxTokens.mjs +501 -43
- package/pipeline/parseSource/frameVisibility.d.mts +47 -0
- package/pipeline/parseSource/frameVisibility.mjs +114 -0
- package/pipeline/parseSource/grammarCache.d.mts +33 -0
- package/pipeline/parseSource/grammarCache.mjs +73 -0
- package/pipeline/parseSource/grammarLoaders.d.mts +14 -0
- package/pipeline/parseSource/grammarLoaders.mjs +24 -0
- package/pipeline/parseSource/grammarMaps.d.mts +21 -1
- package/pipeline/parseSource/grammarMaps.mjs +36 -0
- package/pipeline/parseSource/isFrameSpan.d.mts +19 -0
- package/pipeline/parseSource/isFrameSpan.mjs +24 -0
- package/pipeline/parseSource/parseSource.d.mts +41 -6
- package/pipeline/parseSource/parseSource.mjs +184 -36
- package/pipeline/parseSource/redistributeFrameFallbacks.d.mts +40 -0
- package/pipeline/parseSource/redistributeFrameFallbacks.mjs +138 -0
- package/pipeline/parseSource/restructureFrames.d.mts +5 -0
- package/pipeline/parseSource/restructureFrames.mjs +179 -16
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +6 -2
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.d.mts +26 -0
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +181 -114
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.d.mts +12 -0
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.mjs +52 -0
- package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +22 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.mts +5 -8
- package/pipeline/transformTypescriptToJavascript/removeTypes.mjs +27 -93
- package/useCode/EditableEngine.d.mts +233 -0
- package/useCode/EditableEngine.mjs +1712 -0
- package/useCode/EditingEngine.d.mts +13 -0
- package/useCode/EditingEngine.mjs +14 -0
- package/useCode/Pre.browser.mjs +5 -1
- package/useCode/Pre.d.mts +127 -1
- package/useCode/Pre.mjs +417 -165
- package/useCode/SourceEditingEngine.d.mts +50 -0
- package/useCode/SourceEditingEngine.mjs +461 -0
- package/useCode/TransformEngine.d.mts +39 -0
- package/useCode/TransformEngine.mjs +208 -0
- package/useCode/editingEngineCache.d.mts +29 -0
- package/useCode/editingEngineCache.mjs +68 -0
- package/useCode/sourceLineCounts.d.mts +80 -0
- package/useCode/sourceLineCounts.mjs +284 -0
- package/useCode/subscribeToggleNudge.d.mts +3 -0
- package/useCode/subscribeToggleNudge.mjs +95 -0
- package/useCode/transformEngineCache.d.mts +21 -0
- package/useCode/transformEngineCache.mjs +60 -0
- package/useCode/useCode.d.mts +140 -1
- package/useCode/useCode.mjs +250 -19
- package/useCode/useCodeUtils.d.mts +131 -20
- package/useCode/useCodeUtils.mjs +267 -194
- package/useCode/useCopyFunctionality.d.mts +13 -1
- package/useCode/useCopyFunctionality.mjs +39 -9
- package/useCode/useEditable.browser.mjs +10 -2
- package/useCode/useEditable.d.mts +27 -106
- package/useCode/useEditable.integration.browser.d.mts +1 -0
- package/useCode/useEditable.integration.browser.mjs +870 -0
- package/useCode/useEditable.mjs +198 -1247
- package/useCode/useEditableUtils.d.mts +50 -1
- package/useCode/useEditableUtils.mjs +29 -0
- package/useCode/useFileNavigation.d.mts +91 -3
- package/useCode/useFileNavigation.mjs +201 -41
- package/useCode/useHighlightGate.d.mts +17 -0
- package/useCode/useHighlightGate.mjs +147 -0
- package/useCode/useSourceEditing.d.mts +8 -0
- package/useCode/useSourceEditing.mjs +158 -314
- package/useCode/useSourceEnhancing.d.mts +5 -1
- package/useCode/useSourceEnhancing.mjs +22 -36
- package/useCode/useTransformManagement.d.mts +93 -5
- package/useCode/useTransformManagement.mjs +496 -28
- package/useCode/useTransitionPhase.d.mts +24 -0
- package/useCode/useTransitionPhase.mjs +49 -0
- package/useCode/useUIState.d.mts +2 -2
- package/useCode/useUIState.mjs +8 -8
- package/useCode/useVariantSelection.d.mts +130 -6
- package/useCode/useVariantSelection.mjs +529 -93
- package/useCodeWindow/useCodeWindow.d.mts +19 -2
- package/useCodeWindow/useCodeWindow.mjs +98 -71
- package/useCoordinated/coordinatePreference.d.mts +439 -0
- package/useCoordinated/coordinatePreference.mjs +951 -0
- package/useCoordinated/coordinatePreference.testUtils.d.mts +21 -0
- package/useCoordinated/coordinatePreference.testUtils.mjs +69 -0
- package/useCoordinated/createSettleGate.d.mts +96 -0
- package/useCoordinated/createSettleGate.mjs +171 -0
- package/useCoordinated/index.d.mts +8 -0
- package/useCoordinated/index.mjs +8 -0
- package/useCoordinated/layoutShiftGate.d.mts +24 -0
- package/useCoordinated/layoutShiftGate.mjs +79 -0
- package/useCoordinated/pageSettleGate.d.mts +11 -0
- package/useCoordinated/pageSettleGate.mjs +13 -0
- package/useCoordinated/scheduleTasks.d.mts +23 -0
- package/useCoordinated/scheduleTasks.mjs +45 -0
- package/useCoordinated/useCoordinated.d.mts +193 -0
- package/useCoordinated/useCoordinated.mjs +469 -0
- package/useCoordinated/useCoordinatedLazy.d.mts +17 -0
- package/useCoordinated/useCoordinatedLazy.mjs +38 -0
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +16 -0
- package/useCoordinated/useCoordinatedLocalStorage.mjs +22 -0
- package/useCoordinated/useCoordinatedPreference.d.mts +20 -0
- package/useCoordinated/useCoordinatedPreference.mjs +26 -0
- package/useCoordinated/useSettleGate.d.mts +11 -0
- package/useCoordinated/useSettleGate.mjs +34 -0
- package/useDemo/exportVariant.d.mts +12 -5
- package/useDemo/exportVariant.mjs +59 -5
- package/useDemo/useDemo.d.mts +5 -2
- package/useScrollAnchor/useScrollAnchor.mjs +28 -5
- package/useStream/index.d.mts +6 -0
- package/useStream/index.mjs +6 -0
- package/useStream/streamChunks.d.mts +23 -0
- package/useStream/streamChunks.mjs +85 -0
- package/useStream/types.d.mts +45 -0
- package/useStream/types.mjs +1 -0
- package/useStream/useStream.d.mts +57 -0
- package/useStream/useStream.mjs +119 -0
- package/useStream/useStreamController.d.mts +15 -0
- package/useStream/useStreamController.mjs +90 -0
- package/withDocsInfra/withDocsInfra.d.mts +19 -0
- package/withDocsInfra/withDocsInfra.mjs +13 -5
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.d.mts +0 -8
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.mjs +0 -16
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { decompressHast } from "../hastUtils/index.mjs";
|
|
2
|
+
import { fallbackToText, redistributeRootFallback } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* WeakMap cache of decoded `HastRoot` keyed on the raw source payload
|
|
5
|
+
* object. Variant source payloads are stable references across renders
|
|
6
|
+
* (they live on the precomputed manifest / context), so identity-keying
|
|
7
|
+
* is safe and lets us amortize the decompress + `JSON.parse` cost across
|
|
8
|
+
* every consumer that reads the same variant during a render cycle.
|
|
9
|
+
*/
|
|
10
|
+
const decodedHastCache = new WeakMap();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* WeakMap cache of the DEFLATE dictionary text derived from a variant's
|
|
14
|
+
* root `fallback`. `fallbackToText` walks the whole fallback tree, so we
|
|
15
|
+
* memoize it per fallback array — the same array is reused for the variant's
|
|
16
|
+
* compressed source decode and any later re-decodes.
|
|
17
|
+
*/
|
|
18
|
+
const fallbackTextCache = new WeakMap();
|
|
19
|
+
function getFallbackText(fallback) {
|
|
20
|
+
let text = fallbackTextCache.get(fallback);
|
|
21
|
+
if (text === undefined) {
|
|
22
|
+
text = fallbackToText(fallback);
|
|
23
|
+
fallbackTextCache.set(fallback, text);
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
function isHastRoot(value) {
|
|
28
|
+
return 'type' in value && value.type === 'root';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a `VariantSource` to a live `HastRoot`, sharing one decode per
|
|
33
|
+
* source payload across all consumers (`Pre`, `useFileNavigation`,
|
|
34
|
+
* `sourceLineCounts`, …). Decompresses `hastCompressed`, parses `hastJson`,
|
|
35
|
+
* and returns live HAST trees unchanged. Returns `null` for string sources
|
|
36
|
+
* or unrecognized shapes.
|
|
37
|
+
*
|
|
38
|
+
* When a variant-level `fallback` is provided, the compressed payload is
|
|
39
|
+
* decompressed using the fallback text as a DEFLATE dictionary (matching the
|
|
40
|
+
* encoder), and each `span.frame` of a freshly decoded tree gets its
|
|
41
|
+
* per-frame `data.fallback` restored via `redistributeRootFallback`. Live
|
|
42
|
+
* HAST trees are returned untouched — they already carry their per-frame
|
|
43
|
+
* fallback and are shared, read-only inputs.
|
|
44
|
+
*
|
|
45
|
+
* **The returned tree must be treated as read-only.** Multiple consumers
|
|
46
|
+
* share the same object; mutating it would leak across them. Callers that
|
|
47
|
+
* need to mutate the HAST (e.g. the enhancer pipeline in
|
|
48
|
+
* `useSourceEnhancing`) must clone before mutating, and should not use
|
|
49
|
+
* this cache.
|
|
50
|
+
*/
|
|
51
|
+
export function decodeHastSource(source, fallback) {
|
|
52
|
+
if (source == null || typeof source === 'string') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const cached = decodedHastCache.get(source);
|
|
56
|
+
if (cached) {
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
let root;
|
|
60
|
+
let decoded = false;
|
|
61
|
+
try {
|
|
62
|
+
if ('hastJson' in source) {
|
|
63
|
+
root = JSON.parse(source.hastJson);
|
|
64
|
+
decoded = true;
|
|
65
|
+
} else if ('hastCompressed' in source) {
|
|
66
|
+
const dictionary = fallback ? getFallbackText(fallback) : undefined;
|
|
67
|
+
root = JSON.parse(decompressHast(source.hastCompressed, dictionary));
|
|
68
|
+
decoded = true;
|
|
69
|
+
} else if (isHastRoot(source)) {
|
|
70
|
+
root = source;
|
|
71
|
+
} else {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// The "not a HAST source" cases (string / null / unrecognized shape) already
|
|
76
|
+
// returned `null` above — so reaching here means a present `hastJson` /
|
|
77
|
+
// `hastCompressed` payload failed to parse or decompress. That's a real bug
|
|
78
|
+
// (most often a missing or mismatched `fallback` dictionary for
|
|
79
|
+
// `hastCompressed`), so throw rather than returning `null`: a swallowed
|
|
80
|
+
// error here only resurfaces far away as a blank render or a `null.data`
|
|
81
|
+
// crash, which is what makes it hard to track down.
|
|
82
|
+
throw new Error(`Failed to decode the source HAST payload${'hastCompressed' in source ? ' — a hastCompressed payload needs a matching fallback dictionary' : ''}: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
}
|
|
84
|
+
// Freshly decoded trees are owned by this cache, so it is safe to restore
|
|
85
|
+
// the per-frame `data.fallback` that was stripped before serialization.
|
|
86
|
+
// Live HAST inputs are shared and already carry their per-frame fallback.
|
|
87
|
+
if (decoded && fallback) {
|
|
88
|
+
redistributeRootFallback(root, fallback);
|
|
89
|
+
}
|
|
90
|
+
decodedHastCache.set(source, root);
|
|
91
|
+
return root;
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { VariantSource } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
import type { FallbackNode } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Decode a `VariantSource` into a form that carries no serialization: a plain
|
|
5
|
+
* string stays a string, while a serialized `hastCompressed` / `hastJson`
|
|
6
|
+
* payload (or a live `HastRoot`) resolves to a live `HastRoot`. The
|
|
7
|
+
* `{ hastJson }` / `{ hastCompressed }` shapes never leak out, so consumers can
|
|
8
|
+
* read the source as text (`stringOrHastToString`) or inspect / transform the
|
|
9
|
+
* HAST tree directly without handling a DEFLATE dictionary.
|
|
10
|
+
*
|
|
11
|
+
* Decoding reuses the shared `decodeHastSource` cache — so a source already
|
|
12
|
+
* decoded for rendering is not inflated again — then returns a
|
|
13
|
+
* `structuredClone` of the tree. The clone matters: `decodeHastSource` hands
|
|
14
|
+
* back a read-only tree shared with the live render, and the result here is
|
|
15
|
+
* handed to user code (the `transformVariant` hook), which must be able to
|
|
16
|
+
* mutate it without corrupting that shared tree. `fallback` is the DEFLATE
|
|
17
|
+
* dictionary for a `hastCompressed` source.
|
|
18
|
+
*/
|
|
19
|
+
export declare function decodeSource(source: VariantSource, fallback?: FallbackNode[]): VariantSource;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { decodeHastSource } from "./decodeHastSource.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decode a `VariantSource` into a form that carries no serialization: a plain
|
|
5
|
+
* string stays a string, while a serialized `hastCompressed` / `hastJson`
|
|
6
|
+
* payload (or a live `HastRoot`) resolves to a live `HastRoot`. The
|
|
7
|
+
* `{ hastJson }` / `{ hastCompressed }` shapes never leak out, so consumers can
|
|
8
|
+
* read the source as text (`stringOrHastToString`) or inspect / transform the
|
|
9
|
+
* HAST tree directly without handling a DEFLATE dictionary.
|
|
10
|
+
*
|
|
11
|
+
* Decoding reuses the shared `decodeHastSource` cache — so a source already
|
|
12
|
+
* decoded for rendering is not inflated again — then returns a
|
|
13
|
+
* `structuredClone` of the tree. The clone matters: `decodeHastSource` hands
|
|
14
|
+
* back a read-only tree shared with the live render, and the result here is
|
|
15
|
+
* handed to user code (the `transformVariant` hook), which must be able to
|
|
16
|
+
* mutate it without corrupting that shared tree. `fallback` is the DEFLATE
|
|
17
|
+
* dictionary for a `hastCompressed` source.
|
|
18
|
+
*/
|
|
19
|
+
export function decodeSource(source, fallback) {
|
|
20
|
+
if (typeof source === 'string') {
|
|
21
|
+
return source;
|
|
22
|
+
}
|
|
23
|
+
const root = decodeHastSource(source, fallback);
|
|
24
|
+
return root ? structuredClone(root) : source;
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VariantSource } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
import type { FallbackNode } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Decode a `VariantSource` to its plain text, reusing the shared
|
|
5
|
+
* `decodeHastSource` cache so a `hastCompressed` / `hastJson` payload that was
|
|
6
|
+
* already decoded for rendering is not inflated and parsed a second time.
|
|
7
|
+
*
|
|
8
|
+
* String sources are returned unchanged and need no `fallback`. For an encoded
|
|
9
|
+
* source, `fallback` supplies the DEFLATE dictionary required to decode a
|
|
10
|
+
* `hastCompressed` payload (the file's compact fallback text); omitting it for
|
|
11
|
+
* such a payload surfaces a descriptive error from `decodeHastSource` rather
|
|
12
|
+
* than a cryptic inflate failure.
|
|
13
|
+
*
|
|
14
|
+
* `null` / `undefined` sources resolve to an empty string so callers can treat
|
|
15
|
+
* a missing source the same as an empty file.
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeSourceToText(source: VariantSource | null | undefined, fallback?: FallbackNode[]): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toText } from 'hast-util-to-text';
|
|
2
|
+
import { decodeHastSource } from "./decodeHastSource.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Decode a `VariantSource` to its plain text, reusing the shared
|
|
6
|
+
* `decodeHastSource` cache so a `hastCompressed` / `hastJson` payload that was
|
|
7
|
+
* already decoded for rendering is not inflated and parsed a second time.
|
|
8
|
+
*
|
|
9
|
+
* String sources are returned unchanged and need no `fallback`. For an encoded
|
|
10
|
+
* source, `fallback` supplies the DEFLATE dictionary required to decode a
|
|
11
|
+
* `hastCompressed` payload (the file's compact fallback text); omitting it for
|
|
12
|
+
* such a payload surfaces a descriptive error from `decodeHastSource` rather
|
|
13
|
+
* than a cryptic inflate failure.
|
|
14
|
+
*
|
|
15
|
+
* `null` / `undefined` sources resolve to an empty string so callers can treat
|
|
16
|
+
* a missing source the same as an empty file.
|
|
17
|
+
*/
|
|
18
|
+
export function decodeSourceToText(source, fallback) {
|
|
19
|
+
if (source == null || typeof source === 'string') {
|
|
20
|
+
return source ?? '';
|
|
21
|
+
}
|
|
22
|
+
const root = decodeHastSource(source, fallback);
|
|
23
|
+
return root ? toText(root, {
|
|
24
|
+
whitespace: 'pre'
|
|
25
|
+
}) : '';
|
|
26
|
+
}
|
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
import type { Nodes } from 'hast';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
2
|
+
import { type SourceComments, type Transforms } from "../../CodeHighlighter/types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Async-friendly variant of {@link ParseSource}. The build-time diff path
|
|
5
|
+
* may wrap the synchronous highlighter with enhancers that need to run
|
|
6
|
+
* asynchronously, so `diffHast` accepts either return shape. `comments`
|
|
7
|
+
* is the post-transform comment map (1-indexed by line in the transformed
|
|
8
|
+
* source) when the transform repositions lines; wrappers that drive
|
|
9
|
+
* enhancers should prefer it over the source's own comment map so the
|
|
10
|
+
* enhanced frame structure aligns with the patched output.
|
|
11
|
+
*/
|
|
12
|
+
type AsyncParseSource = (source: string, fileName: string, language?: string, comments?: SourceComments) => Nodes | Promise<Nodes>;
|
|
13
|
+
/**
|
|
14
|
+
* Diffs each transformed variant against `parsedSource` and returns
|
|
15
|
+
* a `Transforms` map where every entry carries a `delta`.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: `parsedSource` is temporarily mutated for the duration of this
|
|
18
|
+
* call — `dataLn` properties are stripped from line spans before diffing
|
|
19
|
+
* (so the always-sequential gutter numbering doesn't leak into the
|
|
20
|
+
* delta) and restored in `finally`. Callers must not read from the tree
|
|
21
|
+
* concurrently, and must not invoke `diffHast` against the same
|
|
22
|
+
* `parsedSource` in parallel. Today's only caller (`loadSingleFile`)
|
|
23
|
+
* runs sequentially per variant, so the constraint is satisfied; if
|
|
24
|
+
* that ever changes, clone the source array once up front instead.
|
|
25
|
+
*/
|
|
26
|
+
export declare function diffHast(source: string, parsedSource: Nodes, filename: string, transforms: Transforms, parseSource: AsyncParseSource): Promise<Transforms>;
|
|
27
|
+
export {};
|