@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
|
@@ -2,6 +2,18 @@ import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import { toText } from 'hast-util-to-text';
|
|
3
3
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
4
4
|
import { decompressHast } from "./hastCompression.mjs";
|
|
5
|
+
import { fallbackToText } from "./fallbackFormat.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the DEFLATE dictionary text for a `hastCompressed` payload from a
|
|
9
|
+
* compact `fallback`. The loader compresses each file with its own fallback
|
|
10
|
+
* text as the dictionary (see `loadIsomorphicCodeVariant`), so the same
|
|
11
|
+
* fallback must be supplied here to decode it. Returns `undefined` when no
|
|
12
|
+
* fallback is given (payloads compressed without a dictionary).
|
|
13
|
+
*/
|
|
14
|
+
function fallbackDictionary(fallback) {
|
|
15
|
+
return fallback ? fallbackToText(fallback) : undefined;
|
|
16
|
+
}
|
|
5
17
|
export function hastToJsx(hast, components) {
|
|
6
18
|
return toJsxRuntime(hast, {
|
|
7
19
|
Fragment,
|
|
@@ -10,19 +22,19 @@ export function hastToJsx(hast, components) {
|
|
|
10
22
|
components
|
|
11
23
|
});
|
|
12
24
|
}
|
|
13
|
-
export function hastOrJsonToJsx(hastOrJson, components) {
|
|
25
|
+
export function hastOrJsonToJsx(hastOrJson, components, fallback) {
|
|
14
26
|
let hast;
|
|
15
27
|
if ('hastJson' in hastOrJson) {
|
|
16
28
|
try {
|
|
17
29
|
hast = JSON.parse(hastOrJson.hastJson);
|
|
18
30
|
} catch (error) {
|
|
19
|
-
throw new Error(`Failed to parse hastJson: ${
|
|
31
|
+
throw new Error(`Failed to parse hastJson: ${error instanceof Error ? error.message : String(error)}`);
|
|
20
32
|
}
|
|
21
33
|
} else if ('hastCompressed' in hastOrJson) {
|
|
22
34
|
try {
|
|
23
|
-
hast = JSON.parse(decompressHast(hastOrJson.hastCompressed));
|
|
35
|
+
hast = JSON.parse(decompressHast(hastOrJson.hastCompressed, fallbackDictionary(fallback)));
|
|
24
36
|
} catch (error) {
|
|
25
|
-
throw new Error(`Failed to parse hastCompressed: ${
|
|
37
|
+
throw new Error(`Failed to parse hastCompressed: ${error instanceof Error ? error.message : String(error)}`);
|
|
26
38
|
}
|
|
27
39
|
} else {
|
|
28
40
|
hast = hastOrJson;
|
|
@@ -34,7 +46,7 @@ export function hastOrJsonToJsx(hastOrJson, components) {
|
|
|
34
46
|
components
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
|
-
export function stringOrHastToString(source) {
|
|
49
|
+
export function stringOrHastToString(source, fallback) {
|
|
38
50
|
if (typeof source === 'string') {
|
|
39
51
|
return source;
|
|
40
52
|
}
|
|
@@ -43,13 +55,13 @@ export function stringOrHastToString(source) {
|
|
|
43
55
|
try {
|
|
44
56
|
hast = JSON.parse(source.hastJson);
|
|
45
57
|
} catch (error) {
|
|
46
|
-
throw new Error(`Failed to parse hastJson: ${
|
|
58
|
+
throw new Error(`Failed to parse hastJson: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
59
|
}
|
|
48
60
|
} else if ('hastCompressed' in source) {
|
|
49
61
|
try {
|
|
50
|
-
hast = JSON.parse(decompressHast(source.hastCompressed));
|
|
62
|
+
hast = JSON.parse(decompressHast(source.hastCompressed, fallbackDictionary(fallback)));
|
|
51
63
|
} catch (error) {
|
|
52
|
-
throw new Error(`Failed to parse hastCompressed: ${
|
|
64
|
+
throw new Error(`Failed to parse hastCompressed: ${error instanceof Error ? error.message : String(error)}`);
|
|
53
65
|
}
|
|
54
66
|
} else {
|
|
55
67
|
hast = source;
|
|
@@ -58,7 +70,7 @@ export function stringOrHastToString(source) {
|
|
|
58
70
|
whitespace: 'pre'
|
|
59
71
|
});
|
|
60
72
|
}
|
|
61
|
-
export function stringOrHastToJsx(source, highlighted, components) {
|
|
73
|
+
export function stringOrHastToJsx(source, highlighted, components, fallback) {
|
|
62
74
|
if (typeof source === 'string') {
|
|
63
75
|
return source;
|
|
64
76
|
}
|
|
@@ -67,13 +79,13 @@ export function stringOrHastToJsx(source, highlighted, components) {
|
|
|
67
79
|
try {
|
|
68
80
|
hast = JSON.parse(source.hastJson);
|
|
69
81
|
} catch (error) {
|
|
70
|
-
throw new Error(`Failed to parse hastJson: ${
|
|
82
|
+
throw new Error(`Failed to parse hastJson: ${error instanceof Error ? error.message : String(error)}`);
|
|
71
83
|
}
|
|
72
84
|
} else if ('hastCompressed' in source) {
|
|
73
85
|
try {
|
|
74
|
-
hast = JSON.parse(decompressHast(source.hastCompressed));
|
|
86
|
+
hast = JSON.parse(decompressHast(source.hastCompressed, fallbackDictionary(fallback)));
|
|
75
87
|
} catch (error) {
|
|
76
|
-
throw new Error(`Failed to parse hastCompressed: ${
|
|
88
|
+
throw new Error(`Failed to parse hastCompressed: ${error instanceof Error ? error.message : String(error)}`);
|
|
77
89
|
}
|
|
78
90
|
} else {
|
|
79
91
|
hast = source;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./hastCompression.mjs";
|
|
2
2
|
export * from "./hastUtils.mjs";
|
|
3
3
|
export { getHastTextContent, getShallowTextContent } from "./getHastTextContent.mjs";
|
|
4
|
-
export { stripHighlightingSpans } from "./stripHighlightingSpans.mjs";
|
|
4
|
+
export { stripHighlightingSpans } from "./stripHighlightingSpans.mjs";
|
|
5
|
+
export { frameFallbackFromSpans } from "./frameFallbackFromSpans.mjs";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./hastCompression.mjs";
|
|
2
2
|
export * from "./hastUtils.mjs";
|
|
3
3
|
export { getHastTextContent, getShallowTextContent } from "./getHastTextContent.mjs";
|
|
4
|
-
export { stripHighlightingSpans } from "./stripHighlightingSpans.mjs";
|
|
4
|
+
export { stripHighlightingSpans } from "./stripHighlightingSpans.mjs";
|
|
5
|
+
export { frameFallbackFromSpans } from "./frameFallbackFromSpans.mjs";
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Root as HastRoot } from 'hast';
|
|
2
2
|
/**
|
|
3
|
-
* Strip all non-
|
|
3
|
+
* Strip all non-structural `<span>` elements from a HAST tree while preserving
|
|
4
4
|
* semantic structure and text content. Produces a "links-only" version of the
|
|
5
5
|
* tree suitable as a lightweight server-rendered fallback for deferred highlighting.
|
|
6
6
|
*
|
|
7
|
-
* - All `<span>` elements except frame spans: removed, children promoted
|
|
7
|
+
* - All `<span>` elements except frame and collapse spans: removed, children promoted
|
|
8
8
|
* - Frame `<span>` elements (`frame`): preserved with their data attributes
|
|
9
|
+
* (except `data-lined`, which is redundant once line spans are gone)
|
|
10
|
+
* - Collapse `<span>` elements (`collapse`): preserved with their `data-lines`
|
|
11
|
+
* attribute so CSS can size the placeholder, keeping the fallback render's
|
|
12
|
+
* height in sync with the fully-highlighted render
|
|
9
13
|
* - `<a>` elements: preserved, children recursively processed
|
|
10
14
|
* - text nodes: preserved, adjacent text nodes merged
|
|
11
15
|
* - other elements (pre, code, etc.): preserved, children recursively processed
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { hasClassName, isFrameSpan } from "../parseSource/isFrameSpan.mjs";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Strip all non-
|
|
4
|
+
* Strip all non-structural `<span>` elements from a HAST tree while preserving
|
|
3
5
|
* semantic structure and text content. Produces a "links-only" version of the
|
|
4
6
|
* tree suitable as a lightweight server-rendered fallback for deferred highlighting.
|
|
5
7
|
*
|
|
6
|
-
* - All `<span>` elements except frame spans: removed, children promoted
|
|
8
|
+
* - All `<span>` elements except frame and collapse spans: removed, children promoted
|
|
7
9
|
* - Frame `<span>` elements (`frame`): preserved with their data attributes
|
|
10
|
+
* (except `data-lined`, which is redundant once line spans are gone)
|
|
11
|
+
* - Collapse `<span>` elements (`collapse`): preserved with their `data-lines`
|
|
12
|
+
* attribute so CSS can size the placeholder, keeping the fallback render's
|
|
13
|
+
* height in sync with the fully-highlighted render
|
|
8
14
|
* - `<a>` elements: preserved, children recursively processed
|
|
9
15
|
* - text nodes: preserved, adjacent text nodes merged
|
|
10
16
|
* - other elements (pre, code, etc.): preserved, children recursively processed
|
|
@@ -17,9 +23,8 @@ export function stripHighlightingSpans(root) {
|
|
|
17
23
|
children: processChildren(root.children)
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
return className === 'frame' || Array.isArray(className) && className.includes('frame');
|
|
26
|
+
function isCollapseSpan(element) {
|
|
27
|
+
return hasClassName(element, 'collapse');
|
|
23
28
|
}
|
|
24
29
|
function processChildren(children) {
|
|
25
30
|
const flat = children.flatMap(node => {
|
|
@@ -27,24 +32,31 @@ function processChildren(children) {
|
|
|
27
32
|
return [node];
|
|
28
33
|
}
|
|
29
34
|
const element = node;
|
|
30
|
-
if (element.tagName === 'span' && !isFrameSpan(element)) {
|
|
35
|
+
if (element.tagName === 'span' && !isFrameSpan(element) && !isCollapseSpan(element)) {
|
|
31
36
|
// Unwrap highlighting spans: replace with recursively-processed children
|
|
32
37
|
return processChildren(element.children);
|
|
33
38
|
}
|
|
39
|
+
if (isCollapseSpan(element)) {
|
|
40
|
+
// Collapse placeholders carry one empty `<span/>` per collapsed
|
|
41
|
+
// line as a structural payload (consumer CSS sizes them by
|
|
42
|
+
// intrinsic layout). The children are inert: no recursion needed,
|
|
43
|
+
// and reusing the same element reference keeps downstream JSX
|
|
44
|
+
// caches (WeakMap-keyed) stable across re-renders.
|
|
45
|
+
return [element];
|
|
46
|
+
}
|
|
34
47
|
// Keep semantic spans, links, and other elements — process their children
|
|
35
48
|
const processed = {
|
|
36
49
|
...element,
|
|
37
50
|
children: processChildren(element.children)
|
|
38
51
|
};
|
|
39
|
-
// Strip data-lined
|
|
40
|
-
//
|
|
52
|
+
// Strip data-lined from frame spans since line spans are removed in the
|
|
53
|
+
// fallback HAST.
|
|
41
54
|
if (isFrameSpan(element) && processed.properties) {
|
|
42
55
|
const {
|
|
43
56
|
dataLined,
|
|
44
|
-
dataAsString,
|
|
45
57
|
...rest
|
|
46
58
|
} = processed.properties;
|
|
47
|
-
if (dataLined !== undefined
|
|
59
|
+
if (dataLined !== undefined) {
|
|
48
60
|
processed.properties = rest;
|
|
49
61
|
}
|
|
50
62
|
}
|
|
@@ -297,13 +297,16 @@ function reportPreview(context, sourceCode, {
|
|
|
297
297
|
if (options.wrapReturn && returnStatement) {
|
|
298
298
|
const hasParens = hasReturnParens(sourceCode, returnStatement);
|
|
299
299
|
if (hasParens) {
|
|
300
|
-
// Already `return (...)` — just insert the comment inside
|
|
300
|
+
// Already `return (...)` — just insert the comment inside. The focus
|
|
301
|
+
// sits one level deeper than the function body, so `@padding 2` keeps
|
|
302
|
+
// the `return (` line and the function signature/closing brace visible
|
|
303
|
+
// as context when collapsed.
|
|
301
304
|
const lineStartOffset = sourceCode.getIndexFromLoc({
|
|
302
305
|
line: firstNode.loc.start.line,
|
|
303
306
|
column: 0
|
|
304
307
|
});
|
|
305
308
|
if (isSingleLine) {
|
|
306
|
-
return fixer.insertTextBeforeRange([lineStartOffset, lineStartOffset], `${indentation}// @focus\n`);
|
|
309
|
+
return fixer.insertTextBeforeRange([lineStartOffset, lineStartOffset], `${indentation}// @focus @padding 2\n`);
|
|
307
310
|
}
|
|
308
311
|
const lastLineStartOffset = sourceCode.getIndexFromLoc({
|
|
309
312
|
line: lastNode.loc.end.line,
|
|
@@ -311,7 +314,7 @@ function reportPreview(context, sourceCode, {
|
|
|
311
314
|
});
|
|
312
315
|
const lastLine = sourceCode.lines[lastNode.loc.end.line - 1];
|
|
313
316
|
const lastIndentation = lastLine.match(/^\s*/)?.[0] ?? '';
|
|
314
|
-
return [fixer.insertTextBeforeRange([lineStartOffset, lineStartOffset], `${indentation}// @focus-start\n`), fixer.insertTextAfterRange([lastLineStartOffset, lastLineStartOffset + lastLine.length], `\n${lastIndentation}// @focus-end`)];
|
|
317
|
+
return [fixer.insertTextBeforeRange([lineStartOffset, lineStartOffset], `${indentation}// @focus-start @padding 2\n`), fixer.insertTextAfterRange([lastLineStartOffset, lastLineStartOffset + lastLine.length], `\n${lastIndentation}// @focus-end`)];
|
|
315
318
|
}
|
|
316
319
|
|
|
317
320
|
// No parens — wrap `return <X>` into `return (\n // comment\n <X>\n)`
|
|
@@ -319,9 +322,9 @@ function reportPreview(context, sourceCode, {
|
|
|
319
322
|
const returnIndentation = sourceCode.lines[returnStatement.loc.start.line - 1].match(/^\s*/)?.[0] ?? '';
|
|
320
323
|
const innerIndentation = `${returnIndentation} `;
|
|
321
324
|
if (isSingleLine) {
|
|
322
|
-
return [fixer.replaceTextRange([returnKeywordEnd, firstNode.range[0]], ` (\n${innerIndentation}// @focus\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${returnIndentation})`)];
|
|
325
|
+
return [fixer.replaceTextRange([returnKeywordEnd, firstNode.range[0]], ` (\n${innerIndentation}// @focus @padding 2\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${returnIndentation})`)];
|
|
323
326
|
}
|
|
324
|
-
return [fixer.replaceTextRange([returnKeywordEnd, firstNode.range[0]], ` (\n${innerIndentation}// @focus-start\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${innerIndentation}// @focus-end\n${returnIndentation})`)];
|
|
327
|
+
return [fixer.replaceTextRange([returnKeywordEnd, firstNode.range[0]], ` (\n${innerIndentation}// @focus-start @padding 2\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${innerIndentation}// @focus-end\n${returnIndentation})`)];
|
|
325
328
|
}
|
|
326
329
|
|
|
327
330
|
// Non-wrapper: wrapReturn with implicit-return arrow — wrap expression in parens with comment.
|
|
@@ -332,9 +335,9 @@ function reportPreview(context, sourceCode, {
|
|
|
332
335
|
const arrowIndentation = sourceCode.lines[arrowToken.loc.start.line - 1].match(/^\s*/)?.[0] ?? '';
|
|
333
336
|
const innerIndentation = `${arrowIndentation} `;
|
|
334
337
|
if (isSingleLine) {
|
|
335
|
-
return [fixer.replaceTextRange([arrowToken.range[1], firstNode.range[0]], ` (\n${innerIndentation}// @focus\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${arrowIndentation})`)];
|
|
338
|
+
return [fixer.replaceTextRange([arrowToken.range[1], firstNode.range[0]], ` (\n${innerIndentation}// @focus @padding 2\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${arrowIndentation})`)];
|
|
336
339
|
}
|
|
337
|
-
return [fixer.replaceTextRange([arrowToken.range[1], firstNode.range[0]], ` (\n${innerIndentation}// @focus-start\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${innerIndentation}// @focus-end\n${arrowIndentation})`)];
|
|
340
|
+
return [fixer.replaceTextRange([arrowToken.range[1], firstNode.range[0]], ` (\n${innerIndentation}// @focus-start @padding 2\n${innerIndentation}`), fixer.insertTextAfterRange(lastNode.range, `\n${innerIndentation}// @focus-end\n${arrowIndentation})`)];
|
|
338
341
|
}
|
|
339
342
|
}
|
|
340
343
|
|
|
@@ -1,19 +1,37 @@
|
|
|
1
|
-
import type { VariantSource, Transforms } from "../../CodeHighlighter/types.mjs";
|
|
1
|
+
import type { VariantSource, Transforms, SourceComments } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
import type { FallbackNode } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
2
3
|
/**
|
|
3
|
-
* Applies a specific transform to a variant source and returns the transformed
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Applies a specific transform to a variant source and returns the transformed
|
|
5
|
+
* source plus a remapped copy of the supplied `comments` map. See
|
|
6
|
+
* {@link applyCodeTransformWithCommentsCore} for the full contract; this wrapper
|
|
7
|
+
* binds the built-in `decodeHastSource`.
|
|
8
|
+
*
|
|
8
9
|
* @throws Error if the transform key doesn't exist or patching fails
|
|
9
10
|
*/
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function applyCodeTransformWithComments(source: VariantSource, transforms: Transforms, transformKey: string, comments?: SourceComments, fallback?: FallbackNode[]): {
|
|
12
|
+
source: VariantSource;
|
|
13
|
+
comments?: SourceComments;
|
|
14
|
+
};
|
|
11
15
|
/**
|
|
12
|
-
* Applies multiple transforms to a variant source in sequence
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @returns The transformed variant source in the same format as the input
|
|
16
|
+
* Applies multiple transforms to a variant source in sequence, shifting
|
|
17
|
+
* comments through each hop. See {@link applyCodeTransformsWithCommentsCore};
|
|
18
|
+
* this wrapper binds the built-in `decodeHastSource`.
|
|
19
|
+
*
|
|
17
20
|
* @throws Error if any transform key doesn't exist or patching fails
|
|
18
21
|
*/
|
|
19
|
-
export declare function
|
|
22
|
+
export declare function applyCodeTransformsWithComments(source: VariantSource, transforms: Transforms, transformKeys: string[], comments?: SourceComments, fallback?: FallbackNode[]): {
|
|
23
|
+
source: VariantSource;
|
|
24
|
+
comments?: SourceComments;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Convenience wrapper around {@link applyCodeTransformWithComments} for
|
|
28
|
+
* callers that don't need the shifted comments map. Returns the transformed
|
|
29
|
+
* `VariantSource` directly.
|
|
30
|
+
*/
|
|
31
|
+
export declare function applyCodeTransform(source: VariantSource, transforms: Transforms, transformKey: string, fallback?: FallbackNode[]): VariantSource;
|
|
32
|
+
/**
|
|
33
|
+
* Convenience wrapper around {@link applyCodeTransformsWithComments} for
|
|
34
|
+
* callers that don't need the shifted comments map. Returns the transformed
|
|
35
|
+
* `VariantSource` directly.
|
|
36
|
+
*/
|
|
37
|
+
export declare function applyCodeTransforms(source: VariantSource, transforms: Transforms, transformKeys: string[], fallback?: FallbackNode[]): VariantSource;
|
|
@@ -1,65 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
// Standalone (server/build) entry to the transform-application core. Binds the
|
|
2
|
+
// concrete `decodeHastSource` so callers that don't inject one — the
|
|
3
|
+
// `loadIsomorphicCodeVariant` pipeline, tests, and anything importing
|
|
4
|
+
// `@mui/internal-docs-infra/pipeline/loadIsomorphicCodeVariant` — keep the
|
|
5
|
+
// original API. The client-side `useCode/TransformEngine` instead imports the
|
|
6
|
+
// core (`./applyCodeTransformWithComments`) directly and injects the shell's
|
|
7
|
+
// already-loaded decoder, so the engine chunk never statically pulls
|
|
8
|
+
// `decodeHastSource` (and its `hastDecompress` dependency).
|
|
9
|
+
|
|
10
|
+
import { decodeHastSource } from "./decodeHastSource.mjs";
|
|
11
|
+
import { frameFallbackFromSpans } from "../hastUtils/index.mjs";
|
|
12
|
+
import { applyCodeTransformWithComments as applyCodeTransformWithCommentsCore, applyCodeTransformsWithComments as applyCodeTransformsWithCommentsCore } from "./applyCodeTransformWithComments.mjs";
|
|
13
|
+
|
|
14
|
+
// The built-in hast helpers, bound once for callers that don't inject their own
|
|
15
|
+
// (the `loadIsomorphicCodeVariant` server/build pipeline, tests, etc.).
|
|
16
|
+
const builtinDeps = {
|
|
17
|
+
decode: decodeHastSource,
|
|
18
|
+
frameFallbackFromSpans
|
|
19
|
+
};
|
|
20
|
+
|
|
2
21
|
/**
|
|
3
|
-
* Applies a specific transform to a variant source and returns the transformed
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
7
|
-
*
|
|
22
|
+
* Applies a specific transform to a variant source and returns the transformed
|
|
23
|
+
* source plus a remapped copy of the supplied `comments` map. See
|
|
24
|
+
* {@link applyCodeTransformWithCommentsCore} for the full contract; this wrapper
|
|
25
|
+
* binds the built-in `decodeHastSource`.
|
|
26
|
+
*
|
|
8
27
|
* @throws Error if the transform key doesn't exist or patching fails
|
|
9
28
|
*/
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error(`Transform "${transformKey}" not found in transforms`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Determine the format of the source and apply the appropriate transform strategy
|
|
17
|
-
if (typeof source === 'string') {
|
|
18
|
-
// For string sources, deltas are typically line-array based (from transformSource)
|
|
19
|
-
const sourceLines = source.split('\n');
|
|
20
|
-
const patched = patch(sourceLines, transform.delta);
|
|
21
|
-
if (!Array.isArray(patched)) {
|
|
22
|
-
throw new Error(`Patch for transform "${transformKey}" did not return an array`);
|
|
23
|
-
}
|
|
24
|
-
return patched.join('\n');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// For Hast node sources, deltas are typically node-based (from diffHast)
|
|
28
|
-
let sourceRoot;
|
|
29
|
-
const isHastJson = 'hastJson' in source;
|
|
30
|
-
if (isHastJson) {
|
|
31
|
-
sourceRoot = JSON.parse(source.hastJson);
|
|
32
|
-
} else {
|
|
33
|
-
sourceRoot = source;
|
|
34
|
-
}
|
|
29
|
+
export function applyCodeTransformWithComments(source, transforms, transformKey, comments, fallback) {
|
|
30
|
+
return applyCodeTransformWithCommentsCore(source, transforms, transformKey, builtinDeps, comments, fallback);
|
|
31
|
+
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Applies multiple transforms to a variant source in sequence, shifting
|
|
35
|
+
* comments through each hop. See {@link applyCodeTransformsWithCommentsCore};
|
|
36
|
+
* this wrapper binds the built-in `decodeHastSource`.
|
|
37
|
+
*
|
|
38
|
+
* @throws Error if any transform key doesn't exist or patching fails
|
|
39
|
+
*/
|
|
40
|
+
export function applyCodeTransformsWithComments(source, transforms, transformKeys, comments, fallback) {
|
|
41
|
+
return applyCodeTransformsWithCommentsCore(source, transforms, transformKeys, builtinDeps, comments, fallback);
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
44
|
+
/**
|
|
45
|
+
* Convenience wrapper around {@link applyCodeTransformWithComments} for
|
|
46
|
+
* callers that don't need the shifted comments map. Returns the transformed
|
|
47
|
+
* `VariantSource` directly.
|
|
48
|
+
*/
|
|
49
|
+
export function applyCodeTransform(source, transforms, transformKey, fallback) {
|
|
50
|
+
return applyCodeTransformWithComments(source, transforms, transformKey, undefined, fallback).source;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param transformKeys - Array of transform keys to apply in order
|
|
56
|
-
* @returns The transformed variant source in the same format as the input
|
|
57
|
-
* @throws Error if any transform key doesn't exist or patching fails
|
|
54
|
+
* Convenience wrapper around {@link applyCodeTransformsWithComments} for
|
|
55
|
+
* callers that don't need the shifted comments map. Returns the transformed
|
|
56
|
+
* `VariantSource` directly.
|
|
58
57
|
*/
|
|
59
|
-
export function applyCodeTransforms(source, transforms, transformKeys) {
|
|
60
|
-
|
|
61
|
-
for (const transformKey of transformKeys) {
|
|
62
|
-
currentSource = applyCodeTransform(currentSource, transforms, transformKey);
|
|
63
|
-
}
|
|
64
|
-
return currentSource;
|
|
58
|
+
export function applyCodeTransforms(source, transforms, transformKeys, fallback) {
|
|
59
|
+
return applyCodeTransformsWithComments(source, transforms, transformKeys, undefined, fallback).source;
|
|
65
60
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ElementContent } from 'hast';
|
|
2
|
+
import type { HastRoot, VariantSource, Transforms, SourceComments } from "../../CodeHighlighter/types.mjs";
|
|
3
|
+
import type { FallbackNode } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Decodes a `VariantSource` to a live `HastRoot` (or `null` for string /
|
|
6
|
+
* unrecognized shapes).
|
|
7
|
+
*/
|
|
8
|
+
export type DecodeHastSource = (source: VariantSource | null | undefined, fallback?: FallbackNode[]) => HastRoot | null;
|
|
9
|
+
/** Rebuilds a frame's lazy fallback from its post-transform spans. */
|
|
10
|
+
export type FrameFallbackFromSpans = (spans: ElementContent[]) => ElementContent[];
|
|
11
|
+
/**
|
|
12
|
+
* Hast helpers the transform core needs but must NOT import statically, so the
|
|
13
|
+
* client `useCode/TransformEngine` chunk doesn't pull `decodeHastSource` /
|
|
14
|
+
* `frameFallbackFromSpans` (and their `hastDecompress` dependency). The
|
|
15
|
+
* always-loaded `useCode` shell already has both and injects them; the
|
|
16
|
+
* standalone `applyCodeTransform` wrapper binds the built-ins for server/build
|
|
17
|
+
* callers.
|
|
18
|
+
*/
|
|
19
|
+
export interface TransformRuntimeDeps {
|
|
20
|
+
decode: DecodeHastSource;
|
|
21
|
+
frameFallbackFromSpans: FrameFallbackFromSpans;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Applies a specific transform to a variant source and returns the transformed source
|
|
25
|
+
* along with a remapped copy of the supplied `comments` map (when any) shifted to
|
|
26
|
+
* line up with the renumbered `dataLn` values in the transformed tree.
|
|
27
|
+
*
|
|
28
|
+
* **Return shape, by input shape:**
|
|
29
|
+
* - `string` input → `string` output.
|
|
30
|
+
* - HAST-backed input (`HastRoot`, `{ hastJson }`, or `{ hastCompressed }`)
|
|
31
|
+
* that actually applies a delta → live `HastRoot` output, regardless of the
|
|
32
|
+
* input wire shape. The serialized wire shapes are *not* re-emitted: every
|
|
33
|
+
* downstream reader in this package funnels through `decodeHastSource`,
|
|
34
|
+
* which accepts a live root directly, so re-stringifying / re-compressing
|
|
35
|
+
* here would just be undone by the next consumer (and would defeat the
|
|
36
|
+
* shared decode cache, which is keyed on payload identity). Callers
|
|
37
|
+
* outside this package that need a serialized payload must re-encode
|
|
38
|
+
* the returned root themselves.
|
|
39
|
+
* - Rename-only entries (`hasDelta: false`) and unknown-transform passthrough
|
|
40
|
+
* return the original `source` object untouched (same shape and identity).
|
|
41
|
+
*
|
|
42
|
+
* @param source - The original variant source (string, `HastRoot`,
|
|
43
|
+
* `{ hastJson }`, or `{ hastCompressed }`)
|
|
44
|
+
* @param transforms - Object containing all available transforms
|
|
45
|
+
* @param transformKey - The key of the specific transform to apply
|
|
46
|
+
* @param deps - Hast helpers (`decode`, `frameFallbackFromSpans`) injected so
|
|
47
|
+
* this module never statically imports them; see {@link TransformRuntimeDeps}.
|
|
48
|
+
* @param comments - Optional 1-indexed comment map keyed by the source's original
|
|
49
|
+
* line numbers. Returned shifted so each entry now sits on the line its
|
|
50
|
+
* original source line occupies in the transformed tree; entries whose
|
|
51
|
+
* source line was wiped by the transform are dropped.
|
|
52
|
+
* @returns `{ source, comments }` where `source` is the transformed variant
|
|
53
|
+
* source (see "Return shape" above) and `comments` is the remapped map
|
|
54
|
+
* (or `undefined` when no comments were passed).
|
|
55
|
+
* @throws Error if the transform key doesn't exist or patching fails
|
|
56
|
+
*/
|
|
57
|
+
export declare function applyCodeTransformWithComments(source: VariantSource, transforms: Transforms, transformKey: string, deps: TransformRuntimeDeps, comments?: SourceComments, fallback?: FallbackNode[]): {
|
|
58
|
+
source: VariantSource;
|
|
59
|
+
comments?: SourceComments;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Applies multiple transforms to a variant source in sequence. Comments are
|
|
63
|
+
* shifted by each transform in turn so the returned map lines up with the
|
|
64
|
+
* fully-transformed source.
|
|
65
|
+
*
|
|
66
|
+
* @param source - The original variant source
|
|
67
|
+
* @param transforms - Object containing all available transforms
|
|
68
|
+
* @param transformKeys - Array of transform keys to apply in order
|
|
69
|
+
* @param deps - Hast helpers (`decode`, `frameFallbackFromSpans`) injected so
|
|
70
|
+
* this module never statically imports them; see {@link TransformRuntimeDeps}.
|
|
71
|
+
* @param comments - Optional 1-indexed comment map for the original source
|
|
72
|
+
* @returns `{ source, comments }` after applying every transform in order
|
|
73
|
+
* @throws Error if any transform key doesn't exist or patching fails
|
|
74
|
+
*/
|
|
75
|
+
export declare function applyCodeTransformsWithComments(source: VariantSource, transforms: Transforms, transformKeys: string[], deps: TransformRuntimeDeps, comments?: SourceComments, fallback?: FallbackNode[]): {
|
|
76
|
+
source: VariantSource;
|
|
77
|
+
comments?: SourceComments;
|
|
78
|
+
};
|