@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,253 @@
|
|
|
1
|
+
import { compressHast, decompressHast } from "../pipeline/hastUtils/index.mjs";
|
|
2
|
+
import { collapsedVisibleFallback, fallbackToText } from "./fallbackFormat.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The residual fallbacks a `ContentLoading` component never renders, grouped
|
|
6
|
+
* `variant → fileName → FallbackNode[]`. They exist only as the DEFLATE
|
|
7
|
+
* dictionary for decompressing `hastCompressed`, so they ride across the
|
|
8
|
+
* boundary as a single compressed blob rather than inline plain text.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Residual blobs whose JSON is below this many bytes are left uncompressed —
|
|
13
|
+
* the DEFLATE + base64 framing would only grow such a small payload.
|
|
14
|
+
*/
|
|
15
|
+
export const FALLBACK_COMPRESSION_MIN_BYTES = 128;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build the preset-dictionary text for the residual blob from the *rendered*
|
|
19
|
+
* fallbacks (the subset `ContentLoading` paints, already on the client as plain
|
|
20
|
+
* text). Priming the residual with this text lets DEFLATE backreference the
|
|
21
|
+
* rendered file — most valuable for a near-duplicate sibling like a TypeScript
|
|
22
|
+
* variant of a rendered JavaScript file.
|
|
23
|
+
*
|
|
24
|
+
* Deterministic across server and client: variants and files are visited in
|
|
25
|
+
* sorted key order so both sides build byte-identical dictionaries (a mismatch
|
|
26
|
+
* would otherwise fail the embedded checksum on decode).
|
|
27
|
+
*/
|
|
28
|
+
export function residualDictionaryText(rendered) {
|
|
29
|
+
let text = '';
|
|
30
|
+
for (const variantName of Object.keys(rendered).sort()) {
|
|
31
|
+
const files = rendered[variantName];
|
|
32
|
+
for (const fileName of Object.keys(files).sort()) {
|
|
33
|
+
text += fallbackToText(files[fileName]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return text;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compress the residual fallbacks into a single self-describing blob. A single
|
|
41
|
+
* DEFLATE stream deduplicates text shared across the residual files and
|
|
42
|
+
* variants — and against the rendered subset too when `dictionaryText` is
|
|
43
|
+
* supplied (see `residualDictionaryText`).
|
|
44
|
+
*
|
|
45
|
+
* Returns `undefined` when there is nothing worth compressing (no residual, or
|
|
46
|
+
* a residual below the byte threshold), signalling the caller to keep the plain
|
|
47
|
+
* fallbacks inline.
|
|
48
|
+
*/
|
|
49
|
+
export function compressResidualFallbacks(residual, dictionaryText) {
|
|
50
|
+
if (Object.keys(residual).length === 0) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const json = JSON.stringify(residual);
|
|
54
|
+
// Measure the encoded UTF-8 byte length (isomorphic via TextEncoder), not
|
|
55
|
+
// `json.length` — which counts UTF-16 code units and undercounts multibyte
|
|
56
|
+
// payloads, so a residual that genuinely exceeds the byte threshold would
|
|
57
|
+
// otherwise be wrongly left inline. For ASCII the two are identical.
|
|
58
|
+
if (new TextEncoder().encode(json).length < FALLBACK_COMPRESSION_MIN_BYTES) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
fallbackCompressed: compressHast(json, dictionaryText)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Reverse {@link compressResidualFallbacks}. `dictionaryText` must match what
|
|
68
|
+
* was used to compress; the embedded checksum throws on a mismatch rather than
|
|
69
|
+
* yielding a corrupt dictionary.
|
|
70
|
+
*/
|
|
71
|
+
export function decompressResidualFallbacks(blob, dictionaryText) {
|
|
72
|
+
return JSON.parse(decompressHast(blob.fallbackCompressed, dictionaryText));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pull every `fallback` off a (post-strip) `Code` into a `ResidualFallbacks`
|
|
77
|
+
* map, returning a `Code` with those fallbacks removed. After
|
|
78
|
+
* `stripFallbackHastsFromCode` has hoisted the rendered subset, every fallback
|
|
79
|
+
* still on `Code` is residual — so this needs no scope flags.
|
|
80
|
+
*
|
|
81
|
+
* Pure: the input is left untouched; only the variants that lose a fallback are
|
|
82
|
+
* shallow-cloned.
|
|
83
|
+
*/
|
|
84
|
+
export function extractResidualFallbacks(code) {
|
|
85
|
+
const wireCode = {};
|
|
86
|
+
const residual = {};
|
|
87
|
+
for (const [variantName, variant] of Object.entries(code)) {
|
|
88
|
+
if (!variant || typeof variant === 'string') {
|
|
89
|
+
wireCode[variantName] = variant;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const files = {};
|
|
93
|
+
let nextVariant = variant;
|
|
94
|
+
|
|
95
|
+
// Main file — only extractable when its fileName can key the map.
|
|
96
|
+
if (variant.fallback && variant.fileName) {
|
|
97
|
+
files[variant.fileName] = variant.fallback;
|
|
98
|
+
const {
|
|
99
|
+
fallback: omitted,
|
|
100
|
+
...rest
|
|
101
|
+
} = variant;
|
|
102
|
+
nextVariant = rest;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Extra files.
|
|
106
|
+
if (variant.extraFiles) {
|
|
107
|
+
let nextExtraFiles;
|
|
108
|
+
for (const [fileName, fileData] of Object.entries(variant.extraFiles)) {
|
|
109
|
+
if (typeof fileData === 'string' || !fileData.fallback) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
files[fileName] = fileData.fallback;
|
|
113
|
+
if (!nextExtraFiles) {
|
|
114
|
+
nextExtraFiles = {
|
|
115
|
+
...variant.extraFiles
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const {
|
|
119
|
+
fallback: omitted,
|
|
120
|
+
...rest
|
|
121
|
+
} = fileData;
|
|
122
|
+
nextExtraFiles[fileName] = rest;
|
|
123
|
+
}
|
|
124
|
+
if (nextExtraFiles) {
|
|
125
|
+
nextVariant = {
|
|
126
|
+
...nextVariant,
|
|
127
|
+
extraFiles: nextExtraFiles
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
wireCode[variantName] = nextVariant;
|
|
132
|
+
if (Object.keys(files).length > 0) {
|
|
133
|
+
residual[variantName] = files;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
wireCode,
|
|
138
|
+
residual
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Scatter a decompressed `ResidualFallbacks` map back onto `Code`, restoring
|
|
144
|
+
* each `fallback` to the variant or extra file it came from — the inverse of
|
|
145
|
+
* {@link extractResidualFallbacks}. Reconstructs exactly the in-memory layout a
|
|
146
|
+
* non-consolidated payload would have had, so downstream consumers are unaware
|
|
147
|
+
* the residual ever travelled compressed.
|
|
148
|
+
*
|
|
149
|
+
* `preserveExisting` keeps any `fallback` already on the variant/extra file
|
|
150
|
+
* instead of overwriting it. The hoisted-fallback scatter passes `true`: the
|
|
151
|
+
* hoist is an *initial-paint* dictionary that, for an un-highlighted load, is a
|
|
152
|
+
* raw-string fallback whose text keeps a trailing newline that `buildRootFallback`
|
|
153
|
+
* drops — so it's the WRONG DEFLATE dictionary for a fully-loaded `hastCompressed`
|
|
154
|
+
* source, which already carries its own source-paired (structured) `fallback`.
|
|
155
|
+
* Overwriting that with the hoist makes `decodeHastSource` throw a dictionary
|
|
156
|
+
* mismatch. The hoist is only the dictionary when the variant's own was stripped,
|
|
157
|
+
* so apply it only where one isn't already present. The residual-blob scatter
|
|
158
|
+
* keeps the default (`false`): it always writes onto server-stripped, fallback-less
|
|
159
|
+
* variants, so there is nothing to preserve.
|
|
160
|
+
*
|
|
161
|
+
* Pure: only the variants that regain a fallback are shallow-cloned.
|
|
162
|
+
*/
|
|
163
|
+
export function scatterResidualFallbacks(code, residual, preserveExisting = false) {
|
|
164
|
+
const restored = {};
|
|
165
|
+
for (const [variantName, variant] of Object.entries(code)) {
|
|
166
|
+
const files = residual[variantName];
|
|
167
|
+
if (!variant || typeof variant === 'string' || !files) {
|
|
168
|
+
restored[variantName] = variant;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
let nextVariant = variant;
|
|
172
|
+
let nextExtraFiles;
|
|
173
|
+
for (const [fileName, fallback] of Object.entries(files)) {
|
|
174
|
+
if (fileName === variant.fileName) {
|
|
175
|
+
if (preserveExisting && nextVariant.fallback) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
nextVariant = {
|
|
179
|
+
...nextVariant,
|
|
180
|
+
fallback
|
|
181
|
+
};
|
|
182
|
+
} else {
|
|
183
|
+
const fileData = variant.extraFiles?.[fileName];
|
|
184
|
+
if (fileData && typeof fileData === 'object') {
|
|
185
|
+
if (preserveExisting && fileData.fallback) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (!nextExtraFiles) {
|
|
189
|
+
nextExtraFiles = {
|
|
190
|
+
...variant.extraFiles
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
nextExtraFiles[fileName] = {
|
|
194
|
+
...fileData,
|
|
195
|
+
fallback
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (nextExtraFiles) {
|
|
201
|
+
nextVariant = {
|
|
202
|
+
...nextVariant,
|
|
203
|
+
extraFiles: nextExtraFiles
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
restored[variantName] = nextVariant;
|
|
207
|
+
}
|
|
208
|
+
return restored;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Reduce every fallback in a rendered-subset map to its collapsed window (see
|
|
213
|
+
* `collapsedVisibleFallback`). Used by `fallbackCollapsed` to hand
|
|
214
|
+
* `ContentLoading` only the on-screen lines while the full fallbacks ride along
|
|
215
|
+
* in the residual blob.
|
|
216
|
+
*
|
|
217
|
+
* `collapsesToEmpty(variantName, fileName)` reports the `oversizedFocus: 'hide'`
|
|
218
|
+
* collapse-to-nothing case (the source's `focusedLines === 0`): such files get
|
|
219
|
+
* an empty collapsed window so the loading UI matches the hydrated render
|
|
220
|
+
* instead of briefly painting the first frame.
|
|
221
|
+
*/
|
|
222
|
+
export function collapseRenderedFallbacks(rendered, collapsesToEmpty) {
|
|
223
|
+
const collapsed = {};
|
|
224
|
+
for (const [variantName, files] of Object.entries(rendered)) {
|
|
225
|
+
const collapsedFiles = {};
|
|
226
|
+
for (const [fileName, fallback] of Object.entries(files)) {
|
|
227
|
+
collapsedFiles[fileName] = collapsedVisibleFallback(fallback, collapsesToEmpty?.(variantName, fileName) ?? false);
|
|
228
|
+
}
|
|
229
|
+
collapsed[variantName] = collapsedFiles;
|
|
230
|
+
}
|
|
231
|
+
return collapsed;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Deep-merge two residual maps (`variant → fileName → fallback`), with `b`
|
|
236
|
+
* winning on conflicts. Used to fold the rendered files' full fallbacks into
|
|
237
|
+
* the residual when `fallbackCollapsed` defers them.
|
|
238
|
+
*/
|
|
239
|
+
export function mergeResidualFallbacks(first, second) {
|
|
240
|
+
const merged = {};
|
|
241
|
+
for (const [variantName, files] of Object.entries(first)) {
|
|
242
|
+
merged[variantName] = {
|
|
243
|
+
...files
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
for (const [variantName, files] of Object.entries(second)) {
|
|
247
|
+
merged[variantName] = {
|
|
248
|
+
...merged[variantName],
|
|
249
|
+
...files
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return merged;
|
|
253
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Root as HastRoot } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* Compact serialization format for fallback HAST trees.
|
|
4
|
+
*
|
|
5
|
+
* A `FallbackNode` is either:
|
|
6
|
+
* - a plain string (text node), or
|
|
7
|
+
* - a variable-length tuple whose meaning is determined by length:
|
|
8
|
+
* - `[tagName, children]` – no class, no props
|
|
9
|
+
* - `[tagName, className, children]` – has class, no props
|
|
10
|
+
* - `[tagName, className, properties, children]` – has class and props
|
|
11
|
+
* - `[tagName, className, properties, children, extra]` – full
|
|
12
|
+
*
|
|
13
|
+
* Where:
|
|
14
|
+
* - `tagName` – HTML element name (e.g. `'span'`, `'a'`)
|
|
15
|
+
* - `className` – space-joined class string
|
|
16
|
+
* - `properties` – remaining HTML properties (without `className`)
|
|
17
|
+
* - `children` – a single text string **or** an array of child `FallbackNode`s
|
|
18
|
+
* - `extra` – optional bag for anything else (data attributes, etc.)
|
|
19
|
+
*
|
|
20
|
+
* This eliminates the repeated `type`, `tagName`, `properties`, `children`,
|
|
21
|
+
* and `value` keys that make raw HAST costly in RSC payloads.
|
|
22
|
+
*/
|
|
23
|
+
export type FallbackNode = string | FallbackElement;
|
|
24
|
+
/**
|
|
25
|
+
* A residual fallback that has been DEFLATE-compressed on its own. Mirrors the
|
|
26
|
+
* `{ hastCompressed }` shape of `VariantSource`.
|
|
27
|
+
*
|
|
28
|
+
* Used for the parts of a variant's fallback that the `ContentLoading`
|
|
29
|
+
* component never renders (extra files when the loading UI shows a single file,
|
|
30
|
+
* extra variants when it shows a single variant). Those residual fallbacks
|
|
31
|
+
* exist only as the DEFLATE dictionary for decompressing `hastCompressed`, so
|
|
32
|
+
* shipping them as plain `FallbackNode[]` text would be dead weight in the
|
|
33
|
+
* initial payload. They are compressed standalone — no preset text dictionary,
|
|
34
|
+
* so the blob is self-contained — and decompressed back to `FallbackNode[]`
|
|
35
|
+
* (via `decompressFallback`) only when the full content swaps in.
|
|
36
|
+
*/
|
|
37
|
+
export type CompressedFallback = {
|
|
38
|
+
fallbackCompressed: string;
|
|
39
|
+
};
|
|
40
|
+
export type FallbackElement = [tagName: string, children: string | FallbackNode[]] | [tagName: string, className: string, children: string | FallbackNode[]] | [tagName: string, className: string, properties: Record<string, unknown>, children: string | FallbackNode[]] | [tagName: string, className: string, properties: Record<string, unknown>, children: string | FallbackNode[], extra: Record<string, unknown>];
|
|
41
|
+
/**
|
|
42
|
+
* Convert a HAST root into the compact `FallbackNode[]` format.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hastToFallback(root: HastRoot): FallbackNode[];
|
|
45
|
+
/**
|
|
46
|
+
* Convert the compact `FallbackNode[]` format back into a HAST root.
|
|
47
|
+
*/
|
|
48
|
+
export declare function fallbackToHast(nodes: FallbackNode[]): HastRoot;
|
|
49
|
+
/**
|
|
50
|
+
* Extract the text content from compact `FallbackNode[]` without
|
|
51
|
+
* converting back to HAST. Used to build DEFLATE dictionaries.
|
|
52
|
+
*/
|
|
53
|
+
export declare function fallbackToText(nodes: FallbackNode[]): string;
|
|
54
|
+
/**
|
|
55
|
+
* Builds the variant-level root fallback from a final (post-enhancer) HAST
|
|
56
|
+
* root. Each `span.frame` becomes a compact frame element whose single text
|
|
57
|
+
* child is the frame's precomputed plain text (`frame.data.fallback`), so the
|
|
58
|
+
* result is directly renderable as the pre-hydration code block **and** can be
|
|
59
|
+
* redistributed back onto the decoded HAST's frames (see
|
|
60
|
+
* `redistributeRootFallback`).
|
|
61
|
+
*
|
|
62
|
+
* The frame's `data-lined` attribute is dropped (line spans don't exist in the
|
|
63
|
+
* fallback) while other frame attributes (e.g. `data-frame-type`) are kept so
|
|
64
|
+
* the fallback's layout matches the highlighted render. Non-frame top-level
|
|
65
|
+
* nodes (e.g. whitespace text between frames) are preserved in place.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildRootFallback(root: HastRoot): FallbackNode[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether a compact `fallback` already carries highlighting — i.e. at least one frame
|
|
70
|
+
* keeps nested token spans (array children) instead of flat plain text. True exactly for
|
|
71
|
+
* the promoted {@link promoteCriticalFallback} form; a plain {@link buildRootFallback} has
|
|
72
|
+
* a string child on every frame. `<Pre>` uses this to defer the decompressing decode ONLY
|
|
73
|
+
* when the first paint is already highlighted, so it never flashes plain → highlighted.
|
|
74
|
+
*/
|
|
75
|
+
export declare function fallbackIsHighlighted(fallback: FallbackNode[]): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The **sparse** highlighted-visible fallback: a map from frame index to the
|
|
78
|
+
* highlighted `FallbackNode` for ONLY the frames visible on the initial collapsed
|
|
79
|
+
* render (`visibleFrames`). Off-screen frames are omitted — they flatten to exactly
|
|
80
|
+
* {@link buildRootFallback}'s plain output, so storing them would just duplicate
|
|
81
|
+
* `fallback` in the precompute. {@link promoteCriticalFallback} splices these back
|
|
82
|
+
* over the plain fallback for `highlightAt: 'init'` (paint highlighted on the first
|
|
83
|
+
* render, zero decompression). Frame indices count `span.frame` children only,
|
|
84
|
+
* matching `getInitialVisibleFrames`.
|
|
85
|
+
*
|
|
86
|
+
* The decoded `root` is shared/read-only; this only reads its frames (the synthetic
|
|
87
|
+
* visible frame reuses the frame's `children` array without mutating it, and
|
|
88
|
+
* `data-lined` is dropped via destructuring, not deletion).
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildCriticalFallback(root: HastRoot, visibleFrames: {
|
|
91
|
+
[key: number]: boolean;
|
|
92
|
+
}): {
|
|
93
|
+
[frameIndex: number]: FallbackNode;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Splice a sparse {@link buildCriticalFallback} diff back onto a plain `fallback`,
|
|
97
|
+
* replacing each visible frame (matched by index in document order) with its
|
|
98
|
+
* highlighted node. The result is the full highlighted-visible fallback; its text is
|
|
99
|
+
* byte-identical to `fallback` (the highlight spans only wrap the same characters), so
|
|
100
|
+
* it stays a valid DEFLATE dictionary — asserted by tests. Returns a new array; the
|
|
101
|
+
* input is not mutated.
|
|
102
|
+
*/
|
|
103
|
+
export declare function promoteCriticalFallback(fallback: FallbackNode[], critical: {
|
|
104
|
+
[frameIndex: number]: FallbackNode;
|
|
105
|
+
}): FallbackNode[];
|
|
106
|
+
/**
|
|
107
|
+
* Redistributes a root fallback (built by `buildRootFallback`) back onto the
|
|
108
|
+
* frames of a decoded HAST root, setting each frame's `data.fallback` to the
|
|
109
|
+
* corresponding fallback frame's text nodes (as HAST, not the compact form).
|
|
110
|
+
*
|
|
111
|
+
* Frames align 1:1 by position because the root fallback and the decoded HAST
|
|
112
|
+
* are both derived from the same final tree. Non-frame fallback entries (e.g.
|
|
113
|
+
* inter-frame whitespace) advance the cursor without being assigned. Mutates
|
|
114
|
+
* `root` in place and returns it.
|
|
115
|
+
*/
|
|
116
|
+
export declare function redistributeRootFallback(root: HastRoot, fallback: FallbackNode[]): HastRoot;
|
|
117
|
+
/**
|
|
118
|
+
* Reduce a root fallback to the frames visible while the code block is
|
|
119
|
+
* collapsed — the contiguous focused window (`padding-top`, `highlighted` /
|
|
120
|
+
* `focus`, `padding-bottom`). Inter-frame nodes inside that window are kept so
|
|
121
|
+
* the slice renders with the same spacing as the full fallback.
|
|
122
|
+
*
|
|
123
|
+
* Matches the runtime rule in `Pre.tsx`: when a block has no emphasis frames
|
|
124
|
+
* (the whole source is the focused window) the first frame stands in. Returns
|
|
125
|
+
* the input unchanged when it has no frames at all.
|
|
126
|
+
*
|
|
127
|
+
* When `collapsesToEmpty` is `true` the source records `focusedLines === 0`
|
|
128
|
+
* (the `oversizedFocus: 'hide'` collapse-to-nothing case): the collapsed window
|
|
129
|
+
* is intentionally empty, so the first-frame fallback is skipped and an empty
|
|
130
|
+
* array is returned. Mirrors the runtime rule in `Pre.tsx` /
|
|
131
|
+
* `getInitialVisibleSourceLines`.
|
|
132
|
+
*
|
|
133
|
+
* Used by `fallbackCollapsed` to paint only the on-screen lines while the
|
|
134
|
+
* file's full fallback rides along compressed (see the prop-compression
|
|
135
|
+
* pattern's "Splitting the Fallback by Visibility").
|
|
136
|
+
*/
|
|
137
|
+
export declare function collapsedVisibleFallback(fallback: FallbackNode[], collapsesToEmpty?: boolean): FallbackNode[];
|