@mui/internal-docs-infra 0.11.1-canary.9 → 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 +84 -4
- 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
|
@@ -1,57 +1,362 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { hastToFallback } from "./fallbackFormat.mjs";
|
|
2
|
+
import { getLanguageFromExtension } from "../pipeline/loaderUtils/getLanguageFromExtension.mjs";
|
|
3
|
+
import { getVariantFileLineCounts } from "../useCode/sourceLineCounts.mjs";
|
|
4
|
+
|
|
5
|
+
/** Per-variant → per-file line metadata threaded for the fallback. */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a `language-{language}` hint for a file from its extension, used to
|
|
9
|
+
* scope the fallback `<code>` styling the same way the post-load tree is.
|
|
10
|
+
* Returns `undefined` when the name has no extension or it isn't recognized.
|
|
11
|
+
*/
|
|
12
|
+
function getLanguageFromFileName(fileName) {
|
|
13
|
+
if (!fileName) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
17
|
+
if (dotIndex === -1) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return getLanguageFromExtension(fileName.slice(dotIndex));
|
|
9
21
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the compact fallback for a file. Prefers the pre-extracted variant
|
|
25
|
+
* `fallback` (always emitted by the loader as a root fallback) and only derives
|
|
26
|
+
* one from the source for live/dev trees that never went through the loader.
|
|
27
|
+
*
|
|
28
|
+
* A plain-string source (an unparsed code block, e.g. `<CodeHighlighter>{code}`)
|
|
29
|
+
* is wrapped in a single focus frame so the fallback always has the same frame
|
|
30
|
+
* structure as the highlighted render — never a bare text node. `hastCompressed`
|
|
31
|
+
* payloads can't be decoded here (no DEFLATE dictionary), so without a variant
|
|
32
|
+
* `fallback` they yield `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
function sourceToFallback(source, fallback) {
|
|
35
|
+
if (fallback) {
|
|
36
|
+
return fallback;
|
|
37
|
+
}
|
|
38
|
+
if (!source) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (typeof source === 'string') {
|
|
42
|
+
// Wrap the raw code in a single focus frame so the fallback always carries a
|
|
43
|
+
// frame, matching the highlighted render (`buildRootFallback` likewise emits
|
|
44
|
+
// frames with text children) — never a bare text node. The whole source is
|
|
45
|
+
// the visible window; collapse-to-empty demotes it like any other focus frame.
|
|
46
|
+
return [['span', 'frame', {
|
|
47
|
+
dataFrameType: 'focus'
|
|
48
|
+
}, source]];
|
|
14
49
|
}
|
|
50
|
+
if ('type' in source && source.type === 'root') {
|
|
51
|
+
return hastToFallback(source);
|
|
52
|
+
}
|
|
53
|
+
if ('hastJson' in source) {
|
|
54
|
+
return hastToFallback(JSON.parse(source.hastJson));
|
|
55
|
+
}
|
|
56
|
+
// hastCompressed cannot be decoded here without the dictionary
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Derive the compact `source`/`extraSource` fallbacks and the `language` hint
|
|
62
|
+
* for a single variant. Prefers the pre-extracted per-file fallbacks in
|
|
63
|
+
* `variantHasts` (server path) and otherwise derives them from the variant's
|
|
64
|
+
* own `source`/`fallback` (dev path). `language` comes from the variant's
|
|
65
|
+
* explicit `language` or the main file's extension and is only set when a
|
|
66
|
+
* `source` is present, mirroring how consumers gate the `language-{language}`
|
|
67
|
+
* class behind a rendered source.
|
|
68
|
+
*/
|
|
69
|
+
function deriveVariantSources(variantCode, variantHasts, variantLineCounts) {
|
|
15
70
|
const fileNames = [variantCode.fileName, ...Object.keys(variantCode.extraFiles || {})].filter(name => Boolean(name));
|
|
71
|
+
const mainFile = variantCode.fileName || fileNames[0];
|
|
72
|
+
|
|
73
|
+
// Per-file line counts: prefer render-time windowing (`variantLineCounts`), else
|
|
74
|
+
// the counts the loader stored on the code (`VariantCode` / extra-file `totalLines`
|
|
75
|
+
// / `focusedLines`). So every file/variant carries its window, not just the main one.
|
|
76
|
+
const fileCounts = fileName => {
|
|
77
|
+
const threaded = variantLineCounts?.[fileName];
|
|
78
|
+
if (threaded) {
|
|
79
|
+
return threaded;
|
|
80
|
+
}
|
|
81
|
+
const file = variantCode.fileName === fileName ? variantCode : variantCode.extraFiles?.[fileName];
|
|
82
|
+
if (file && typeof file !== 'string' && file.totalLines !== undefined) {
|
|
83
|
+
return {
|
|
84
|
+
totalLines: file.totalLines,
|
|
85
|
+
focusedLines: file.focusedLines ?? file.totalLines,
|
|
86
|
+
collapsible: file.collapsible === true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Last resort: count lines off the source (a plain string with no enhancers ⇒
|
|
90
|
+
// `focusedLines === totalLines`, matching `<Pre>`'s `getSourceLineCounts`). Guarded
|
|
91
|
+
// because a `hastCompressed` source can't be decoded without its dictionary (which
|
|
92
|
+
// the server strips before this runs) — the server passes `variantLineCounts`
|
|
93
|
+
// instead, so this branch only really fires client-side where the dictionary is on
|
|
94
|
+
// the code.
|
|
95
|
+
try {
|
|
96
|
+
const counts = getVariantFileLineCounts(variantCode, fileName);
|
|
97
|
+
// `totalLines === 0` means a hast with no `root.data` counts (not a real count).
|
|
98
|
+
return counts && counts.totalLines > 0 ? counts : undefined;
|
|
99
|
+
} catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
16
103
|
let source;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
104
|
+
let extraSource;
|
|
105
|
+
if (variantHasts) {
|
|
106
|
+
// Pre-extracted fallback data (server path).
|
|
107
|
+
if (mainFile && variantHasts[mainFile]) {
|
|
108
|
+
source = variantHasts[mainFile];
|
|
109
|
+
}
|
|
110
|
+
const extra = {};
|
|
111
|
+
for (const [fName, nodes] of Object.entries(variantHasts)) {
|
|
112
|
+
if (fName !== mainFile) {
|
|
113
|
+
extra[fName] = {
|
|
114
|
+
source: nodes,
|
|
115
|
+
...fileCounts(fName)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (Object.keys(extra).length > 0) {
|
|
120
|
+
extraSource = extra;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
// No pre-extracted fallback data (e.g. dev mode). Prefer the variant's own
|
|
124
|
+
// `fallback`, falling back to deriving one from the source directly.
|
|
125
|
+
source = sourceToFallback(variantCode.source, variantCode.fallback);
|
|
126
|
+
const extra = {};
|
|
127
|
+
for (const [fName, fData] of Object.entries(variantCode.extraFiles || {})) {
|
|
128
|
+
if (typeof fData === 'object' && fData.source) {
|
|
129
|
+
const fb = sourceToFallback(fData.source, fData.fallback);
|
|
130
|
+
if (fb) {
|
|
131
|
+
extra[fName] = {
|
|
132
|
+
source: fb,
|
|
133
|
+
...fileCounts(fName)
|
|
36
134
|
};
|
|
37
135
|
}
|
|
38
|
-
|
|
39
|
-
}, {});
|
|
40
|
-
return {
|
|
41
|
-
fileNames,
|
|
42
|
-
source,
|
|
43
|
-
extraSource,
|
|
44
|
-
extraVariants
|
|
45
|
-
};
|
|
136
|
+
}
|
|
46
137
|
}
|
|
138
|
+
if (Object.keys(extra).length > 0) {
|
|
139
|
+
extraSource = extra;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const language = source ? variantCode.language ?? getLanguageFromFileName(mainFile) : undefined;
|
|
143
|
+
const mainCounts = source && mainFile ? fileCounts(mainFile) : undefined;
|
|
144
|
+
return {
|
|
145
|
+
fileNames,
|
|
146
|
+
source,
|
|
147
|
+
totalLines: mainCounts?.totalLines,
|
|
148
|
+
focusedLines: mainCounts?.focusedLines,
|
|
149
|
+
collapsible: mainCounts?.collapsible,
|
|
150
|
+
extraSource,
|
|
151
|
+
language
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export function codeToFallbackProps(variant, code,
|
|
155
|
+
// `fallbackUsesExtraFiles` / the selected file name are threaded in by both
|
|
156
|
+
// call sites for signature parity, but the per-file gating now happens
|
|
157
|
+
// upstream in `stripFallbackHastsFromCode` (which only hoists the allowed
|
|
158
|
+
// files into `allFallbackHasts`), so the derivation below reads them off the
|
|
159
|
+
// already-gated `allFallbackHasts` rather than re-applying the flags here.
|
|
160
|
+
_fileName, _needsAllFiles = false, needsAllVariants = false, allFallbackHasts, allLineCounts) {
|
|
161
|
+
const variantCode = code?.[variant];
|
|
162
|
+
if (!variantCode || typeof variantCode === 'string') {
|
|
163
|
+
return {};
|
|
164
|
+
}
|
|
165
|
+
const {
|
|
166
|
+
fileNames,
|
|
167
|
+
source,
|
|
168
|
+
totalLines,
|
|
169
|
+
focusedLines,
|
|
170
|
+
collapsible,
|
|
171
|
+
extraSource,
|
|
172
|
+
language
|
|
173
|
+
} = deriveVariantSources(variantCode, allFallbackHasts?.[variant], allLineCounts?.[variant]);
|
|
174
|
+
if (needsAllVariants) {
|
|
175
|
+
const extraVariants = Object.entries(code || {}).reduce((acc, [name, vCode]) => {
|
|
176
|
+
if (name !== variant && vCode && typeof vCode !== 'string') {
|
|
177
|
+
const {
|
|
178
|
+
fileNames: evFileNames,
|
|
179
|
+
source: evSource,
|
|
180
|
+
totalLines: evTotalLines,
|
|
181
|
+
focusedLines: evFocusedLines,
|
|
182
|
+
collapsible: evCollapsible,
|
|
183
|
+
extraSource: evExtraSource,
|
|
184
|
+
language: evLanguage
|
|
185
|
+
} = deriveVariantSources(vCode, allFallbackHasts?.[name], allLineCounts?.[name]);
|
|
186
|
+
acc[name] = {
|
|
187
|
+
fileNames: evFileNames,
|
|
188
|
+
...(evSource ? {
|
|
189
|
+
source: evSource
|
|
190
|
+
} : undefined),
|
|
191
|
+
...(evTotalLines !== undefined ? {
|
|
192
|
+
totalLines: evTotalLines
|
|
193
|
+
} : undefined),
|
|
194
|
+
...(evFocusedLines !== undefined ? {
|
|
195
|
+
focusedLines: evFocusedLines
|
|
196
|
+
} : undefined),
|
|
197
|
+
...(evCollapsible !== undefined ? {
|
|
198
|
+
collapsible: evCollapsible
|
|
199
|
+
} : undefined),
|
|
200
|
+
...(evLanguage ? {
|
|
201
|
+
language: evLanguage
|
|
202
|
+
} : undefined),
|
|
203
|
+
...(evExtraSource ? {
|
|
204
|
+
extraSource: evExtraSource
|
|
205
|
+
} : undefined)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return acc;
|
|
209
|
+
}, {});
|
|
47
210
|
return {
|
|
48
211
|
fileNames,
|
|
49
|
-
source
|
|
50
|
-
|
|
212
|
+
...(source ? {
|
|
213
|
+
source
|
|
214
|
+
} : undefined),
|
|
215
|
+
...(totalLines !== undefined ? {
|
|
216
|
+
totalLines
|
|
217
|
+
} : undefined),
|
|
218
|
+
...(focusedLines !== undefined ? {
|
|
219
|
+
focusedLines
|
|
220
|
+
} : undefined),
|
|
221
|
+
...(collapsible !== undefined ? {
|
|
222
|
+
collapsible
|
|
223
|
+
} : undefined),
|
|
224
|
+
...(language ? {
|
|
225
|
+
language
|
|
226
|
+
} : undefined),
|
|
227
|
+
...(extraSource ? {
|
|
228
|
+
extraSource
|
|
229
|
+
} : undefined),
|
|
230
|
+
extraVariants
|
|
51
231
|
};
|
|
52
232
|
}
|
|
53
233
|
return {
|
|
54
234
|
fileNames,
|
|
55
|
-
source
|
|
235
|
+
...(source ? {
|
|
236
|
+
source
|
|
237
|
+
} : undefined),
|
|
238
|
+
...(totalLines !== undefined ? {
|
|
239
|
+
totalLines
|
|
240
|
+
} : undefined),
|
|
241
|
+
...(focusedLines !== undefined ? {
|
|
242
|
+
focusedLines
|
|
243
|
+
} : undefined),
|
|
244
|
+
...(collapsible !== undefined ? {
|
|
245
|
+
collapsible
|
|
246
|
+
} : undefined),
|
|
247
|
+
...(language ? {
|
|
248
|
+
language
|
|
249
|
+
} : undefined),
|
|
250
|
+
...(extraSource ? {
|
|
251
|
+
extraSource
|
|
252
|
+
} : undefined)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Read a variant's per-file fallbacks straight off its `VariantCode` `fallback`
|
|
258
|
+
* fields (main + extra files), returning a `Fallbacks` map keyed by file name.
|
|
259
|
+
*
|
|
260
|
+
* The fallback crosses the server→client boundary exactly once: either on the
|
|
261
|
+
* `VariantCode` (no `ContentLoading`) or — after `stripFallbackHastsFromCode`
|
|
262
|
+
* moves it — on the `ContentLoading` props. This reads the former location, so
|
|
263
|
+
* the client can resolve the DEFLATE dictionary for `hastCompressed` without a
|
|
264
|
+
* hoist when there's no `ContentLoading`. Returns `undefined` when the variant
|
|
265
|
+
* carries no fallback (a string variant, a live-HAST source, or one whose
|
|
266
|
+
* fallbacks were stripped for a `ContentLoading` component) — in which case the
|
|
267
|
+
* hoisted copy is used instead.
|
|
268
|
+
*/
|
|
269
|
+
export function deriveFallbacksFromCode(code, variantName) {
|
|
270
|
+
const variant = code?.[variantName];
|
|
271
|
+
if (!variant || typeof variant === 'string') {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
const fallbacks = {};
|
|
275
|
+
if (variant.fallback && variant.fileName) {
|
|
276
|
+
fallbacks[variant.fileName] = variant.fallback;
|
|
277
|
+
}
|
|
278
|
+
if (variant.extraFiles) {
|
|
279
|
+
for (const [fileName, fileData] of Object.entries(variant.extraFiles)) {
|
|
280
|
+
if (typeof fileData === 'object' && fileData.fallback) {
|
|
281
|
+
fallbacks[fileName] = fileData.fallback;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return Object.keys(fallbacks).length > 0 ? fallbacks : undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Strip `fallback` entries from a `Code` object and return the
|
|
290
|
+
* stripped Code alongside the extracted fallbacks grouped by variant → fileName.
|
|
291
|
+
*
|
|
292
|
+
* Used on the server to separate the fallback data from the Code
|
|
293
|
+
* so Code is sent to CodeHighlighterClient without fallbacks, and
|
|
294
|
+
* the data is passed to ContentLoading as source/extraSource props.
|
|
295
|
+
*/
|
|
296
|
+
export function stripFallbackHastsFromCode(code, variantName, fallbackUsesExtraFiles, fallbackUsesAllVariants) {
|
|
297
|
+
if (!code) {
|
|
298
|
+
return {
|
|
299
|
+
strippedCode: {},
|
|
300
|
+
allFallbackHasts: {}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const allFallbackHasts = {};
|
|
304
|
+
const strippedCode = {};
|
|
305
|
+
const variantsToProcess = fallbackUsesAllVariants ? Object.keys(code) : [variantName];
|
|
306
|
+
const variantsToProcessSet = new Set(variantsToProcess);
|
|
307
|
+
for (const [key, variant] of Object.entries(code)) {
|
|
308
|
+
if (!variant || typeof variant === 'string' || !variantsToProcessSet.has(key)) {
|
|
309
|
+
strippedCode[key] = variant;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const hasts = {};
|
|
313
|
+
let changed = false;
|
|
314
|
+
|
|
315
|
+
// Main file
|
|
316
|
+
if (variant.fallback && variant.fileName) {
|
|
317
|
+
hasts[variant.fileName] = variant.fallback;
|
|
318
|
+
changed = true;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Extra files
|
|
322
|
+
let strippedExtraFiles = variant.extraFiles;
|
|
323
|
+
if ((fallbackUsesExtraFiles || fallbackUsesAllVariants) && variant.extraFiles) {
|
|
324
|
+
const newExtraFiles = {
|
|
325
|
+
...variant.extraFiles
|
|
326
|
+
};
|
|
327
|
+
for (const [fName, fData] of Object.entries(variant.extraFiles)) {
|
|
328
|
+
if (typeof fData !== 'string' && fData.fallback) {
|
|
329
|
+
hasts[fName] = fData.fallback;
|
|
330
|
+
const {
|
|
331
|
+
fallback: omittedFallback,
|
|
332
|
+
...rest
|
|
333
|
+
} = fData;
|
|
334
|
+
newExtraFiles[fName] = rest;
|
|
335
|
+
changed = true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (changed) {
|
|
339
|
+
strippedExtraFiles = newExtraFiles;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (changed) {
|
|
343
|
+
const {
|
|
344
|
+
fallback: omittedFallback,
|
|
345
|
+
...restVariant
|
|
346
|
+
} = variant;
|
|
347
|
+
strippedCode[key] = {
|
|
348
|
+
...restVariant,
|
|
349
|
+
extraFiles: strippedExtraFiles
|
|
350
|
+
};
|
|
351
|
+
} else {
|
|
352
|
+
strippedCode[key] = variant;
|
|
353
|
+
}
|
|
354
|
+
if (Object.keys(hasts).length > 0) {
|
|
355
|
+
allFallbackHasts[key] = hasts;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
strippedCode,
|
|
360
|
+
allFallbackHasts
|
|
56
361
|
};
|
|
57
362
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Code, CodeHighlighterBaseProps, CodeHighlighterClientProps } from "./types.mjs";
|
|
3
|
+
import type { CompressedFallback } from "./fallbackFormat.mjs";
|
|
4
|
+
export interface CreateClientPropsOptions<T extends {}> extends CodeHighlighterBaseProps<T> {
|
|
5
|
+
code?: Code;
|
|
6
|
+
fallback?: React.ReactNode;
|
|
7
|
+
skipFallback?: boolean;
|
|
8
|
+
processedGlobalsCode?: Array<Code>;
|
|
9
|
+
residualFallbacks?: CompressedFallback;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Assemble the props for the `'use client'` `CodeHighlighterClient` from the
|
|
13
|
+
* server/isomorphic props: rewrite the top-level URL to its hosted form, pre-render
|
|
14
|
+
* the `Content` element (functions can't cross the server-client boundary), and
|
|
15
|
+
* forward the loading `fallback` and compressed `residualFallbacks`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createClientProps<T extends {}>(props: CreateClientPropsOptions<T>): CodeHighlighterClientProps;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { replaceUrlPrefix } from "../pipeline/loaderUtils/applyUrlPrefix.mjs";
|
|
3
|
+
import { resolveFallbackCritical } from "./resolveFallbackCritical.mjs";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
/**
|
|
6
|
+
* Assemble the props for the `'use client'` `CodeHighlighterClient` from the
|
|
7
|
+
* server/isomorphic props: rewrite the top-level URL to its hosted form, pre-render
|
|
8
|
+
* the `Content` element (functions can't cross the server-client boundary), and
|
|
9
|
+
* forward the loading `fallback` and compressed `residualFallbacks`.
|
|
10
|
+
*/
|
|
11
|
+
export function createClientProps(props) {
|
|
12
|
+
const highlightAfter = props.highlightAfter === 'stream' ? 'init' : props.highlightAfter;
|
|
13
|
+
const enhanceAfter = props.enhanceAfter === 'stream' ? 'init' : props.enhanceAfter;
|
|
14
|
+
|
|
15
|
+
// Resolve the staging `fallbackCritical` on every variant of both carriers before
|
|
16
|
+
// they cross to the client: under `highlightAt: 'init'` (not `collapseToEmpty`)
|
|
17
|
+
// promote it over the plain `fallback` so the first paint is highlighted with no
|
|
18
|
+
// decompression, and always strip it so it never reaches `Content`/`ContentLoading`
|
|
19
|
+
// or bloats the payload. `code` and `precompute` are forwarded separately (the
|
|
20
|
+
// client seeds its `code` state from `precompute`), so both must be resolved.
|
|
21
|
+
const collapseToEmpty = props.collapseToEmpty ?? props.contentProps?.collapseToEmpty ?? false;
|
|
22
|
+
const code = resolveFallbackCritical(props.code, highlightAfter, collapseToEmpty);
|
|
23
|
+
const precompute = resolveFallbackCritical(props.precompute, highlightAfter, collapseToEmpty);
|
|
24
|
+
|
|
25
|
+
// Rewrite the top-level URL before it leaves the server. The client never
|
|
26
|
+
// receives `urlPrefix` (and shouldn't deal with `file://` URLs), so any
|
|
27
|
+
// local URL must be translated to its hosted form here. Variant-level URLs
|
|
28
|
+
// inside `code`/`precompute` are already rewritten upstream (by
|
|
29
|
+
// `loadIsomorphicCodeVariant` on the server, or by the demo factory for precomputed
|
|
30
|
+
// input).
|
|
31
|
+
const url = props.urlPrefix && props.url ? replaceUrlPrefix(props.url, props.urlPrefix) : props.url;
|
|
32
|
+
const contentProps = {
|
|
33
|
+
...props.contentProps,
|
|
34
|
+
code: code || precompute,
|
|
35
|
+
components: props.components,
|
|
36
|
+
name: props.name,
|
|
37
|
+
slug: props.slug,
|
|
38
|
+
url,
|
|
39
|
+
variantType: props.variantType,
|
|
40
|
+
// Thread the render-time display flags into the content channel so both
|
|
41
|
+
// `useCode`/`<Pre>` and the loading fallback honor them. A top-level prop
|
|
42
|
+
// wins over one already present in `contentProps`.
|
|
43
|
+
...(props.collapseToEmpty !== undefined ? {
|
|
44
|
+
collapseToEmpty: props.collapseToEmpty
|
|
45
|
+
} : undefined),
|
|
46
|
+
...(props.initialExpanded !== undefined ? {
|
|
47
|
+
initialExpanded: props.initialExpanded
|
|
48
|
+
} : undefined)
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
url,
|
|
52
|
+
code,
|
|
53
|
+
precompute,
|
|
54
|
+
components: props.components,
|
|
55
|
+
variants: props.variants,
|
|
56
|
+
variant: props.variant,
|
|
57
|
+
fileName: props.fileName,
|
|
58
|
+
initialVariant: props.initialVariant,
|
|
59
|
+
defaultVariant: props.defaultVariant,
|
|
60
|
+
highlightAfter: highlightAfter || 'idle',
|
|
61
|
+
enhanceAfter: enhanceAfter || 'idle',
|
|
62
|
+
skipFallback: props.skipFallback,
|
|
63
|
+
controlled: props.controlled,
|
|
64
|
+
editActivation: props.editActivation,
|
|
65
|
+
residualFallbacks: props.residualFallbacks,
|
|
66
|
+
name: props.name,
|
|
67
|
+
slug: props.slug,
|
|
68
|
+
// Use processedGlobalsCode if available, otherwise fall back to raw globalsCode
|
|
69
|
+
globalsCode: props.processedGlobalsCode || props.globalsCode,
|
|
70
|
+
// Note: it is important that we render components before passing them to the client
|
|
71
|
+
// otherwise we will get an error because functions can't be serialized
|
|
72
|
+
// On the client, in order to send data to these components, we have to set context
|
|
73
|
+
fallback: props.fallback,
|
|
74
|
+
children: /*#__PURE__*/_jsx(props.Content, {
|
|
75
|
+
...contentProps
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -106,6 +106,12 @@ export declare class ErrorCodeHighlighterClientMissingUrlForVariants extends Err
|
|
|
106
106
|
export declare class ErrorCodeHighlighterClientMissingData extends ErrorCodeHighlighterClientValidation {
|
|
107
107
|
constructor();
|
|
108
108
|
}
|
|
109
|
+
export declare class ErrorCodeHighlighterClientMissingFallbackHoist extends ErrorCodeHighlighterClientValidation {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export declare class ErrorCodeHighlighterClientDynamicContentRequiresFallback extends ErrorCodeHighlighterClientValidation {
|
|
113
|
+
constructor();
|
|
114
|
+
}
|
|
109
115
|
export declare class ErrorCodeHighlighterServerLoadVariantFailure extends ErrorCodeHighlighterServerLoader {
|
|
110
116
|
constructor(url: string, error: Error);
|
|
111
117
|
}
|
|
@@ -219,6 +219,16 @@ export class ErrorCodeHighlighterClientMissingData extends ErrorCodeHighlighterC
|
|
|
219
219
|
super(`Missing data - CodeHighlighterClient requires either \`variants\`, \`components\`, or \`code\` to be provided.`);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
+
export class ErrorCodeHighlighterClientMissingFallbackHoist extends ErrorCodeHighlighterClientValidation {
|
|
223
|
+
constructor() {
|
|
224
|
+
super(`Missing fallback data - A ContentLoading component was provided but did not hoist fallback data. ` + `Make sure your ContentLoading component calls \`useCodeFallback(props)\` and passes the component props.`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export class ErrorCodeHighlighterClientDynamicContentRequiresFallback extends ErrorCodeHighlighterClientValidation {
|
|
228
|
+
constructor() {
|
|
229
|
+
super(`Dynamic content requires a ContentLoading - The Content component loads asynchronously ` + `(e.g. via \`LazyContent\`), but no \`ContentLoading\` was provided to show while it loads, ` + `so the slot would flash empty. Provide a \`ContentLoading\` component, or render the content synchronously.`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
222
232
|
|
|
223
233
|
// === CONSOLE ERROR CLASSES ===
|
|
224
234
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type CompressedFallback } from "./fallbackFormat.mjs";
|
|
2
|
+
import type { Code, Fallbacks } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The residual fallbacks a `ContentLoading` component never renders, grouped
|
|
5
|
+
* `variant → fileName → FallbackNode[]`. They exist only as the DEFLATE
|
|
6
|
+
* dictionary for decompressing `hastCompressed`, so they ride across the
|
|
7
|
+
* boundary as a single compressed blob rather than inline plain text.
|
|
8
|
+
*/
|
|
9
|
+
export type ResidualFallbacks = Record<string, Fallbacks>;
|
|
10
|
+
/**
|
|
11
|
+
* Residual blobs whose JSON is below this many bytes are left uncompressed —
|
|
12
|
+
* the DEFLATE + base64 framing would only grow such a small payload.
|
|
13
|
+
*/
|
|
14
|
+
export declare const FALLBACK_COMPRESSION_MIN_BYTES = 128;
|
|
15
|
+
/**
|
|
16
|
+
* Build the preset-dictionary text for the residual blob from the *rendered*
|
|
17
|
+
* fallbacks (the subset `ContentLoading` paints, already on the client as plain
|
|
18
|
+
* text). Priming the residual with this text lets DEFLATE backreference the
|
|
19
|
+
* rendered file — most valuable for a near-duplicate sibling like a TypeScript
|
|
20
|
+
* variant of a rendered JavaScript file.
|
|
21
|
+
*
|
|
22
|
+
* Deterministic across server and client: variants and files are visited in
|
|
23
|
+
* sorted key order so both sides build byte-identical dictionaries (a mismatch
|
|
24
|
+
* would otherwise fail the embedded checksum on decode).
|
|
25
|
+
*/
|
|
26
|
+
export declare function residualDictionaryText(rendered: ResidualFallbacks): string;
|
|
27
|
+
/**
|
|
28
|
+
* Compress the residual fallbacks into a single self-describing blob. A single
|
|
29
|
+
* DEFLATE stream deduplicates text shared across the residual files and
|
|
30
|
+
* variants — and against the rendered subset too when `dictionaryText` is
|
|
31
|
+
* supplied (see `residualDictionaryText`).
|
|
32
|
+
*
|
|
33
|
+
* Returns `undefined` when there is nothing worth compressing (no residual, or
|
|
34
|
+
* a residual below the byte threshold), signalling the caller to keep the plain
|
|
35
|
+
* fallbacks inline.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compressResidualFallbacks(residual: ResidualFallbacks, dictionaryText?: string): CompressedFallback | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Reverse {@link compressResidualFallbacks}. `dictionaryText` must match what
|
|
40
|
+
* was used to compress; the embedded checksum throws on a mismatch rather than
|
|
41
|
+
* yielding a corrupt dictionary.
|
|
42
|
+
*/
|
|
43
|
+
export declare function decompressResidualFallbacks(blob: CompressedFallback, dictionaryText?: string): ResidualFallbacks;
|
|
44
|
+
/**
|
|
45
|
+
* Pull every `fallback` off a (post-strip) `Code` into a `ResidualFallbacks`
|
|
46
|
+
* map, returning a `Code` with those fallbacks removed. After
|
|
47
|
+
* `stripFallbackHastsFromCode` has hoisted the rendered subset, every fallback
|
|
48
|
+
* still on `Code` is residual — so this needs no scope flags.
|
|
49
|
+
*
|
|
50
|
+
* Pure: the input is left untouched; only the variants that lose a fallback are
|
|
51
|
+
* shallow-cloned.
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractResidualFallbacks(code: Code): {
|
|
54
|
+
wireCode: Code;
|
|
55
|
+
residual: ResidualFallbacks;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Scatter a decompressed `ResidualFallbacks` map back onto `Code`, restoring
|
|
59
|
+
* each `fallback` to the variant or extra file it came from — the inverse of
|
|
60
|
+
* {@link extractResidualFallbacks}. Reconstructs exactly the in-memory layout a
|
|
61
|
+
* non-consolidated payload would have had, so downstream consumers are unaware
|
|
62
|
+
* the residual ever travelled compressed.
|
|
63
|
+
*
|
|
64
|
+
* `preserveExisting` keeps any `fallback` already on the variant/extra file
|
|
65
|
+
* instead of overwriting it. The hoisted-fallback scatter passes `true`: the
|
|
66
|
+
* hoist is an *initial-paint* dictionary that, for an un-highlighted load, is a
|
|
67
|
+
* raw-string fallback whose text keeps a trailing newline that `buildRootFallback`
|
|
68
|
+
* drops — so it's the WRONG DEFLATE dictionary for a fully-loaded `hastCompressed`
|
|
69
|
+
* source, which already carries its own source-paired (structured) `fallback`.
|
|
70
|
+
* Overwriting that with the hoist makes `decodeHastSource` throw a dictionary
|
|
71
|
+
* mismatch. The hoist is only the dictionary when the variant's own was stripped,
|
|
72
|
+
* so apply it only where one isn't already present. The residual-blob scatter
|
|
73
|
+
* keeps the default (`false`): it always writes onto server-stripped, fallback-less
|
|
74
|
+
* variants, so there is nothing to preserve.
|
|
75
|
+
*
|
|
76
|
+
* Pure: only the variants that regain a fallback are shallow-cloned.
|
|
77
|
+
*/
|
|
78
|
+
export declare function scatterResidualFallbacks(code: Code, residual: ResidualFallbacks, preserveExisting?: boolean): Code;
|
|
79
|
+
/**
|
|
80
|
+
* Reduce every fallback in a rendered-subset map to its collapsed window (see
|
|
81
|
+
* `collapsedVisibleFallback`). Used by `fallbackCollapsed` to hand
|
|
82
|
+
* `ContentLoading` only the on-screen lines while the full fallbacks ride along
|
|
83
|
+
* in the residual blob.
|
|
84
|
+
*
|
|
85
|
+
* `collapsesToEmpty(variantName, fileName)` reports the `oversizedFocus: 'hide'`
|
|
86
|
+
* collapse-to-nothing case (the source's `focusedLines === 0`): such files get
|
|
87
|
+
* an empty collapsed window so the loading UI matches the hydrated render
|
|
88
|
+
* instead of briefly painting the first frame.
|
|
89
|
+
*/
|
|
90
|
+
export declare function collapseRenderedFallbacks(rendered: ResidualFallbacks, collapsesToEmpty?: (variantName: string, fileName: string) => boolean): ResidualFallbacks;
|
|
91
|
+
/**
|
|
92
|
+
* Deep-merge two residual maps (`variant → fileName → fallback`), with `b`
|
|
93
|
+
* winning on conflicts. Used to fold the rendered files' full fallbacks into
|
|
94
|
+
* the residual when `fallbackCollapsed` defers them.
|
|
95
|
+
*/
|
|
96
|
+
export declare function mergeResidualFallbacks(first: ResidualFallbacks, second: ResidualFallbacks): ResidualFallbacks;
|