@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
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import { createFrame } from "./createFrame.mjs";
|
|
2
|
+
import { isFrameSpan } from "./isFrameSpan.mjs";
|
|
3
|
+
import { redistributeFrameFallbacks } from "./redistributeFrameFallbacks.mjs";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Represents a line element and its trailing newline text node (if any).
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
10
|
+
* A collapsed-lines placeholder span (`<span class="collapse" data-lines={n}>`)
|
|
11
|
+
* along with its anchor line numbers. Tracking both the preceding and
|
|
12
|
+
* following line lets the emitter re-attach the placeholder to whichever
|
|
13
|
+
* neighbor survives the new frame ranges, instead of silently dropping it
|
|
14
|
+
* when the preceding line is filtered out.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function isCollapsedLinesPlaceholder(node) {
|
|
18
|
+
return node.type === 'element' && node.tagName === 'span' && node.properties != null && node.properties.className === 'collapse';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Flattens all line elements and collapsed-lines placeholders from existing
|
|
23
|
+
* frames. This is a flat iteration over root.children (frames) and their
|
|
24
|
+
* direct children (lines + newline text nodes + placeholders). Not a deep
|
|
25
|
+
* recursive traversal.
|
|
14
26
|
*/
|
|
15
27
|
function flattenLineEntries(root) {
|
|
16
|
-
const
|
|
28
|
+
const lineEntries = [];
|
|
29
|
+
const placeholderEntries = [];
|
|
30
|
+
// Placeholders that have seen their `prevLine` (or none) but not yet
|
|
31
|
+
// their `nextLine`. Resolved when the next `.line` appears.
|
|
32
|
+
let pendingNextAnchor = [];
|
|
33
|
+
let lastLineNumber;
|
|
17
34
|
for (const frame of root.children) {
|
|
18
35
|
if (frame.type !== 'element' || frame.tagName !== 'span') {
|
|
19
36
|
continue;
|
|
@@ -22,8 +39,14 @@ function flattenLineEntries(root) {
|
|
|
22
39
|
for (let i = 0; i < children.length; i += 1) {
|
|
23
40
|
const child = children[i];
|
|
24
41
|
if (child.type === 'element' && child.tagName === 'span' && child.properties?.className === 'line' && typeof child.properties.dataLn === 'number') {
|
|
42
|
+
const lineNumber = child.properties.dataLn;
|
|
43
|
+
// Resolve any placeholders waiting on a following line.
|
|
44
|
+
for (const pending of pendingNextAnchor) {
|
|
45
|
+
pending.nextLine = lineNumber;
|
|
46
|
+
}
|
|
47
|
+
pendingNextAnchor = [];
|
|
25
48
|
const entry = {
|
|
26
|
-
lineNumber
|
|
49
|
+
lineNumber,
|
|
27
50
|
element: child
|
|
28
51
|
};
|
|
29
52
|
|
|
@@ -33,11 +56,67 @@ function flattenLineEntries(root) {
|
|
|
33
56
|
entry.trailingNewline = next;
|
|
34
57
|
i += 1; // Skip the newline in the next iteration
|
|
35
58
|
}
|
|
36
|
-
|
|
59
|
+
lineEntries.push(entry);
|
|
60
|
+
lastLineNumber = lineNumber;
|
|
61
|
+
} else if (isCollapsedLinesPlaceholder(child)) {
|
|
62
|
+
const entry = {
|
|
63
|
+
element: child,
|
|
64
|
+
prevLine: lastLineNumber
|
|
65
|
+
};
|
|
66
|
+
placeholderEntries.push(entry);
|
|
67
|
+
pendingNextAnchor.push(entry);
|
|
37
68
|
}
|
|
38
69
|
}
|
|
39
70
|
}
|
|
40
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
lineEntries,
|
|
73
|
+
placeholderEntries
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Collects the per-frame fallback node arrays from the existing frames, paired
|
|
79
|
+
* with the inclusive 1-based line range each frame covers (derived from its
|
|
80
|
+
* `.line` children's `data-ln`).
|
|
81
|
+
*
|
|
82
|
+
* Returns `null` when any line-bearing frame is missing a `data.fallback`, so
|
|
83
|
+
* the caller can safely skip fallback redistribution rather than emitting an
|
|
84
|
+
* incomplete result.
|
|
85
|
+
*/
|
|
86
|
+
function collectFrameFallbacks(root) {
|
|
87
|
+
const frames = [];
|
|
88
|
+
for (const frame of root.children) {
|
|
89
|
+
if (frame.type !== 'element' || !isFrameSpan(frame)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let startLine = Infinity;
|
|
93
|
+
let endLine = -Infinity;
|
|
94
|
+
for (const child of frame.children) {
|
|
95
|
+
if (child.type === 'element' && child.properties?.className === 'line' && typeof child.properties.dataLn === 'number') {
|
|
96
|
+
const lineNumber = child.properties.dataLn;
|
|
97
|
+
if (lineNumber < startLine) {
|
|
98
|
+
startLine = lineNumber;
|
|
99
|
+
}
|
|
100
|
+
if (lineNumber > endLine) {
|
|
101
|
+
endLine = lineNumber;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (endLine < startLine) {
|
|
106
|
+
// Frame carries no line elements (e.g. placeholder-only); nothing to map.
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const fallback = frame.data?.fallback;
|
|
110
|
+
if (!fallback) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
frames.push({
|
|
114
|
+
startLine,
|
|
115
|
+
endLine,
|
|
116
|
+
nodes: fallback
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return frames;
|
|
41
120
|
}
|
|
42
121
|
|
|
43
122
|
/**
|
|
@@ -48,13 +127,25 @@ function flattenLineEntries(root) {
|
|
|
48
127
|
* It's a flat iteration (not a deep recursive traversal) since the HAST structure
|
|
49
128
|
* is always Root → Frame(s) → Line(s).
|
|
50
129
|
*
|
|
130
|
+
* Per-frame `data.fallback` text is kept in sync: it is redistributed onto the
|
|
131
|
+
* new frames by shifting only the lines that cross a frame boundary (see
|
|
132
|
+
* `redistributeFrameFallbacks`), so enhancers that re-chunk frames don't
|
|
133
|
+
* invalidate the precomputed fallback.
|
|
134
|
+
*
|
|
51
135
|
* @param root - The HAST root node to restructure (mutated in place)
|
|
52
136
|
* @param frameRanges - Ordered array of frame ranges
|
|
53
137
|
* @param regionIndentLevels - Map of highlighted region index to indent level
|
|
54
138
|
*/
|
|
55
139
|
export function restructureFrames(root, frameRanges, regionIndentLevels) {
|
|
56
|
-
// Step
|
|
57
|
-
|
|
140
|
+
// Step 0: Capture existing per-frame fallbacks before the tree is rebuilt so
|
|
141
|
+
// they can be redistributed onto the new frames.
|
|
142
|
+
const oldFrameFallbacks = collectFrameFallbacks(root);
|
|
143
|
+
|
|
144
|
+
// Step 1: Flatten all lines + placeholders from existing frames.
|
|
145
|
+
const {
|
|
146
|
+
lineEntries,
|
|
147
|
+
placeholderEntries
|
|
148
|
+
} = flattenLineEntries(root);
|
|
58
149
|
|
|
59
150
|
// Build a lookup from line number to entry for O(1) access
|
|
60
151
|
const lineEntryMap = new Map();
|
|
@@ -62,30 +153,102 @@ export function restructureFrames(root, frameRanges, regionIndentLevels) {
|
|
|
62
153
|
lineEntryMap.set(entry.lineNumber, entry);
|
|
63
154
|
}
|
|
64
155
|
|
|
65
|
-
// Step 2:
|
|
66
|
-
|
|
156
|
+
// Step 2: Pre-compute the set of kept line numbers so each placeholder
|
|
157
|
+
// can decide where it belongs without re-scanning the ranges.
|
|
158
|
+
const keptLines = new Set();
|
|
67
159
|
for (const range of frameRanges) {
|
|
160
|
+
for (let line = range.startLine; line <= range.endLine; line += 1) {
|
|
161
|
+
keptLines.add(line);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Track which placeholders have been emitted to avoid duplicates when
|
|
166
|
+
// both anchors are kept across separate ranges.
|
|
167
|
+
const emittedPlaceholders = new Set();
|
|
168
|
+
|
|
169
|
+
// Index placeholders by their anchor line for O(1) lookup during emission.
|
|
170
|
+
const placeholdersAfterLine = new Map();
|
|
171
|
+
const placeholdersBeforeLine = new Map();
|
|
172
|
+
for (const placeholder of placeholderEntries) {
|
|
173
|
+
if (placeholder.prevLine !== undefined && keptLines.has(placeholder.prevLine)) {
|
|
174
|
+
// Prefer attaching to the preceding kept line (source-order stable).
|
|
175
|
+
const list = placeholdersAfterLine.get(placeholder.prevLine) ?? [];
|
|
176
|
+
list.push(placeholder);
|
|
177
|
+
placeholdersAfterLine.set(placeholder.prevLine, list);
|
|
178
|
+
} else if (placeholder.nextLine !== undefined && keptLines.has(placeholder.nextLine)) {
|
|
179
|
+
// Preceding anchor was dropped; fall back to the next kept line.
|
|
180
|
+
const list = placeholdersBeforeLine.get(placeholder.nextLine) ?? [];
|
|
181
|
+
list.push(placeholder);
|
|
182
|
+
placeholdersBeforeLine.set(placeholder.nextLine, list);
|
|
183
|
+
}
|
|
184
|
+
// Otherwise: neither anchor survives → placeholder is dropped.
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Step 3: Build new frames.
|
|
188
|
+
const newFrames = [];
|
|
189
|
+
|
|
190
|
+
// Redistribute the captured per-frame fallbacks onto the new ranges. The
|
|
191
|
+
// result is aligned to `frameRanges` by index; entries for ranges that end
|
|
192
|
+
// up empty are simply never read.
|
|
193
|
+
const redistributedFallbacks = oldFrameFallbacks ? redistributeFrameFallbacks(oldFrameFallbacks, frameRanges) : null;
|
|
194
|
+
for (let rangeIndex = 0; rangeIndex < frameRanges.length; rangeIndex += 1) {
|
|
195
|
+
const range = frameRanges[rangeIndex];
|
|
68
196
|
const children = [];
|
|
69
197
|
for (let line = range.startLine; line <= range.endLine; line += 1) {
|
|
70
198
|
const entry = lineEntryMap.get(line);
|
|
71
199
|
if (!entry) {
|
|
72
200
|
continue;
|
|
73
201
|
}
|
|
202
|
+
|
|
203
|
+
// Emit any placeholders whose preceding anchor was dropped and that
|
|
204
|
+
// are anchored before this line.
|
|
205
|
+
const before = placeholdersBeforeLine.get(line);
|
|
206
|
+
if (before) {
|
|
207
|
+
for (const placeholder of before) {
|
|
208
|
+
if (!emittedPlaceholders.has(placeholder)) {
|
|
209
|
+
children.push(placeholder.element);
|
|
210
|
+
emittedPlaceholders.add(placeholder);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
74
214
|
children.push(entry.element);
|
|
75
215
|
|
|
76
216
|
// Always add trailing newline when present to preserve original line breaks
|
|
77
217
|
if (entry.trailingNewline) {
|
|
78
218
|
children.push(entry.trailingNewline);
|
|
79
219
|
}
|
|
220
|
+
|
|
221
|
+
// Re-emit placeholders that originally followed this line.
|
|
222
|
+
const after = placeholdersAfterLine.get(line);
|
|
223
|
+
if (after) {
|
|
224
|
+
for (const placeholder of after) {
|
|
225
|
+
if (!emittedPlaceholders.has(placeholder)) {
|
|
226
|
+
children.push(placeholder.element);
|
|
227
|
+
emittedPlaceholders.add(placeholder);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
80
231
|
}
|
|
81
232
|
|
|
82
233
|
// Only create frame if it has children
|
|
83
234
|
if (children.length > 0) {
|
|
84
235
|
const indentLevel = range.regionIndex !== undefined ? regionIndentLevels.get(range.regionIndex) : undefined;
|
|
85
|
-
|
|
236
|
+
const frame = createFrame(children, range.type, indentLevel, range.truncated);
|
|
237
|
+
const fallbackNodes = redistributedFallbacks?.[rangeIndex];
|
|
238
|
+
if (fallbackNodes && fallbackNodes.length > 0) {
|
|
239
|
+
// Cast to `ElementData` because `hast-util-from-parse5` augments it
|
|
240
|
+
// with a required `position` field (upstream bug — should be
|
|
241
|
+
// optional). We never run through that parser here, so the field
|
|
242
|
+
// never exists at runtime.
|
|
243
|
+
if (!frame.data) {
|
|
244
|
+
frame.data = {};
|
|
245
|
+
}
|
|
246
|
+
frame.data.fallback = fallbackNodes;
|
|
247
|
+
}
|
|
248
|
+
newFrames.push(frame);
|
|
86
249
|
}
|
|
87
250
|
}
|
|
88
251
|
|
|
89
|
-
// Step
|
|
252
|
+
// Step 4: Replace root children
|
|
90
253
|
root.children = newFrames;
|
|
91
254
|
}
|
|
@@ -32,7 +32,9 @@ function astNodesToMarkdown(nodes) {
|
|
|
32
32
|
} else if (node.type === 'inlineCode') {
|
|
33
33
|
result += `\`${node.value}\``;
|
|
34
34
|
} else if (node.type === 'emphasis') {
|
|
35
|
-
|
|
35
|
+
// Prettier serializes emphasis with underscores; match it to keep the
|
|
36
|
+
// generated file stable when prettier formats it afterwards.
|
|
37
|
+
result += `_${astNodesToMarkdown(node.children)}_`;
|
|
36
38
|
} else if (node.type === 'strong') {
|
|
37
39
|
result += `**${astNodesToMarkdown(node.children)}**`;
|
|
38
40
|
} else if (node.type === 'link') {
|
|
@@ -1581,7 +1583,9 @@ function extractTextFromNode(node) {
|
|
|
1581
1583
|
}
|
|
1582
1584
|
if (node.type === 'emphasis') {
|
|
1583
1585
|
const emphasisText = node.children.map(child => extractTextFromNode(child)).join('');
|
|
1584
|
-
|
|
1586
|
+
// Prettier serializes emphasis with underscores; match it to keep the
|
|
1587
|
+
// generated file stable when prettier formats it afterwards.
|
|
1588
|
+
return `_${emphasisText}_`;
|
|
1585
1589
|
}
|
|
1586
1590
|
if (node.type === 'strong') {
|
|
1587
1591
|
const strongText = node.children.map(child => extractTextFromNode(child)).join('');
|
|
@@ -14,6 +14,32 @@ export type TransformHtmlCodeBlockOptions = {
|
|
|
14
14
|
* @default 60
|
|
15
15
|
*/
|
|
16
16
|
focusFramesMaxSize?: number;
|
|
17
|
+
/**
|
|
18
|
+
* How to handle a focused region larger than `focusFramesMaxSize`:
|
|
19
|
+
* `'truncate'` (default) keeps the first `focusFramesMaxSize` lines visible and
|
|
20
|
+
* hides the overflow; `'hide'` produces no visible window so the block collapses
|
|
21
|
+
* to nothing (`focusedLines === 0`, still `collapsible`) and expanding reveals
|
|
22
|
+
* the whole source. Applies to oversized `@highlight` / `@focus` regions and the
|
|
23
|
+
* auto-focus-from-line-1 case.
|
|
24
|
+
* @default 'truncate'
|
|
25
|
+
*/
|
|
26
|
+
oversizedFocus?: 'truncate' | 'hide';
|
|
27
|
+
/**
|
|
28
|
+
* Render-time default for "collapse to empty": when `true`, every authored code
|
|
29
|
+
* block collapses to an empty window (hidden until expanded) unless the block
|
|
30
|
+
* sets its own flag (` ```ts collapseToEmpty ` to force it, ` ```ts collapseToEmpty=false `
|
|
31
|
+
* to opt out). Runtime-only — the precomputed HAST is unchanged.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
collapseToEmpty?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Render-time default for "initial expanded": when `true`, every authored code
|
|
37
|
+
* block starts expanded unless the block sets its own flag
|
|
38
|
+
* (` ```ts initialExpanded ` / ` ```ts initialExpanded=false `). Runtime-only —
|
|
39
|
+
* the precomputed HAST is unchanged.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
initialExpanded?: boolean;
|
|
17
43
|
};
|
|
18
44
|
/**
|
|
19
45
|
* Rehype plugin that transforms semantic HTML code structures to use loadIsomorphicCodeVariant
|