@mui/internal-docs-infra 0.11.1-canary.8 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChunkProvider/ChunkContext.d.mts +10 -0
- package/ChunkProvider/ChunkContext.mjs +15 -0
- package/ChunkProvider/ChunkProvider.d.mts +14 -0
- package/ChunkProvider/ChunkProvider.mjs +38 -0
- package/ChunkProvider/PreloadContext.d.mts +14 -0
- package/ChunkProvider/PreloadContext.mjs +18 -0
- package/ChunkProvider/PreloadProvider.d.mts +13 -0
- package/ChunkProvider/PreloadProvider.mjs +33 -0
- package/ChunkProvider/index.d.mts +7 -0
- package/ChunkProvider/index.mjs +7 -0
- package/ChunkProvider/types.d.mts +23 -0
- package/ChunkProvider/types.mjs +1 -0
- package/ChunkProvider/usePreload.d.mts +8 -0
- package/ChunkProvider/usePreload.mjs +21 -0
- package/CodeControllerContext/CodeControllerContext.d.mts +11 -0
- package/CodeControllerContext/CodeControllerContext.mjs +2 -1
- package/CodeHighlighter/CodeHighlighter.d.mts +15 -1
- package/CodeHighlighter/CodeHighlighter.mjs +97 -319
- package/CodeHighlighter/CodeHighlighterChunk.d.mts +42 -0
- package/CodeHighlighter/CodeHighlighterChunk.mjs +77 -0
- package/CodeHighlighter/CodeHighlighterClient.mjs +597 -128
- package/CodeHighlighter/CodeHighlighterContext.d.mts +57 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.mts +14 -2
- package/CodeHighlighter/CodeHighlighterFallbackContext.mjs +1 -3
- package/CodeHighlighter/CodeInitialSourceLoader.d.mts +10 -0
- package/CodeHighlighter/CodeInitialSourceLoader.mjs +108 -0
- package/CodeHighlighter/CodeSourceLoader.d.mts +11 -0
- package/CodeHighlighter/CodeSourceLoader.mjs +128 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.d.mts +47 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.mjs +61 -0
- package/CodeHighlighter/buildStringFallback.d.mts +29 -0
- package/CodeHighlighter/buildStringFallback.mjs +42 -0
- package/CodeHighlighter/codeToFallbackProps.d.mts +31 -2
- package/CodeHighlighter/codeToFallbackProps.mjs +347 -42
- package/CodeHighlighter/createClientProps.d.mts +17 -0
- package/CodeHighlighter/createClientProps.mjs +78 -0
- package/CodeHighlighter/errors.d.mts +6 -0
- package/CodeHighlighter/errors.mjs +10 -0
- package/CodeHighlighter/fallbackCompression.d.mts +96 -0
- package/CodeHighlighter/fallbackCompression.mjs +253 -0
- package/CodeHighlighter/fallbackFormat.d.mts +137 -0
- package/CodeHighlighter/fallbackFormat.mjs +422 -0
- package/CodeHighlighter/index.d.mts +4 -1
- package/CodeHighlighter/index.mjs +3 -1
- package/CodeHighlighter/mergeComments.d.mts +38 -0
- package/CodeHighlighter/mergeComments.mjs +80 -0
- package/CodeHighlighter/prepareInitialSource.d.mts +42 -0
- package/CodeHighlighter/prepareInitialSource.mjs +292 -0
- package/CodeHighlighter/resolveFallbackCritical.d.mts +23 -0
- package/CodeHighlighter/resolveFallbackCritical.mjs +44 -0
- package/CodeHighlighter/types.d.mts +272 -8
- package/CodeHighlighter/useCodeFallback.d.mts +94 -0
- package/CodeHighlighter/useCodeFallback.mjs +204 -0
- package/CodeHighlighter/useGrammarsReady.d.mts +18 -0
- package/CodeHighlighter/useGrammarsReady.mjs +45 -0
- package/CodeHighlighter/useSpeculativeCodePreload.d.mts +26 -0
- package/CodeHighlighter/useSpeculativeCodePreload.mjs +40 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.d.mts +33 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.mjs +58 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.d.mts +23 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.mjs +31 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.d.mts +22 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.mjs +41 -0
- package/CodeProvider/CodeContext.d.mts +47 -12
- package/CodeProvider/CodeContext.mjs +7 -0
- package/CodeProvider/CodeProvider.d.mts +4 -2
- package/CodeProvider/CodeProvider.mjs +40 -102
- package/CodeProvider/CodeProviderLazy.d.mts +40 -0
- package/CodeProvider/CodeProviderLazy.mjs +96 -0
- package/CodeProvider/constants.d.mts +26 -0
- package/CodeProvider/constants.mjs +24 -0
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +22 -2
- package/CodeProvider/index.d.mts +2 -1
- package/CodeProvider/index.mjs +9 -1
- package/CodeProvider/parseSourceWorker.mjs +33 -0
- package/CodeProvider/useCodeProviderValue.d.mts +54 -0
- package/CodeProvider/useCodeProviderValue.mjs +188 -0
- package/CoordinatedLazy/ChunkServerLoader.d.mts +25 -0
- package/CoordinatedLazy/ChunkServerLoader.mjs +97 -0
- package/CoordinatedLazy/CoordinatedContentContext.d.mts +15 -0
- package/CoordinatedLazy/CoordinatedContentContext.mjs +22 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.d.mts +11 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.mjs +13 -0
- package/CoordinatedLazy/CoordinatedGateContext.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedGateContext.mjs +19 -0
- package/CoordinatedLazy/CoordinatedLazy.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedLazy.mjs +86 -0
- package/CoordinatedLazy/CoordinatedLazyClient.d.mts +24 -0
- package/CoordinatedLazy/CoordinatedLazyClient.mjs +65 -0
- package/CoordinatedLazy/LazyContent.d.mts +26 -0
- package/CoordinatedLazy/LazyContent.mjs +80 -0
- package/CoordinatedLazy/LazyContentServer.d.mts +18 -0
- package/CoordinatedLazy/LazyContentServer.mjs +25 -0
- package/CoordinatedLazy/buildChunkRenderInputs.d.mts +8 -0
- package/CoordinatedLazy/buildChunkRenderInputs.mjs +35 -0
- package/CoordinatedLazy/createCoordinatedLazy.d.mts +32 -0
- package/CoordinatedLazy/createCoordinatedLazy.mjs +127 -0
- package/CoordinatedLazy/index.d.mts +14 -0
- package/CoordinatedLazy/index.mjs +18 -0
- package/CoordinatedLazy/resolveChunkRender.d.mts +26 -0
- package/CoordinatedLazy/resolveChunkRender.mjs +73 -0
- package/CoordinatedLazy/types.d.mts +408 -0
- package/CoordinatedLazy/types.mjs +1 -0
- package/CoordinatedLazy/useChunk.d.mts +30 -0
- package/CoordinatedLazy/useChunk.mjs +135 -0
- package/CoordinatedLazy/useCoordinatedFallback.d.mts +12 -0
- package/CoordinatedLazy/useCoordinatedFallback.mjs +40 -0
- package/CoordinatedLazy/useCoordinatedSwap.d.mts +16 -0
- package/CoordinatedLazy/useCoordinatedSwap.mjs +124 -0
- package/LICENSE +1 -1
- package/abstractCreateDemo/abstractCreateDemo.d.mts +54 -3
- package/abstractCreateDemo/abstractCreateDemo.mjs +47 -7
- package/abstractCreateDemo/resolveDemoFlag.d.mts +20 -0
- package/abstractCreateDemo/resolveDemoFlag.mjs +25 -0
- package/abstractCreateStream/abstractCreateStream.d.mts +18 -0
- package/abstractCreateStream/abstractCreateStream.mjs +45 -0
- package/abstractCreateStream/index.d.mts +2 -0
- package/abstractCreateStream/index.mjs +1 -0
- package/abstractCreateStream/types.d.mts +34 -0
- package/abstractCreateStream/types.mjs +1 -0
- package/abstractCreateTypes/TypeCode.mjs +12 -11
- package/abstractCreateTypes/typesToJsx.mjs +30 -9
- package/cli/ensureDemoClients.mjs +4 -148
- package/cli/ensureDemoPages.d.mts +45 -0
- package/cli/ensureDemoPages.mjs +99 -0
- package/cli/fileUtils/index.d.mts +11 -0
- package/cli/fileUtils/index.mjs +48 -0
- package/cli/findDemoIndexFiles.d.mts +15 -0
- package/cli/findDemoIndexFiles.mjs +121 -0
- package/cli/index.mjs +1 -1
- package/cli/loadNextConfig.d.mts +25 -0
- package/cli/loadNextConfig.mjs +60 -1
- package/cli/runBrowser.mjs +1 -1
- package/cli/runValidate.mjs +44 -1
- package/package.json +85 -5
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasis.mjs +30 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.d.mts +17 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs +52 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.d.mts +18 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.mjs +24 -0
- package/pipeline/hastUtils/hast.d.mts +27 -0
- package/pipeline/hastUtils/hastCompression.d.mts +3 -1
- package/pipeline/hastUtils/hastCompression.mjs +9 -1
- package/pipeline/hastUtils/hastDecompress.mjs +10 -4
- package/pipeline/hastUtils/hastDictionary.mjs +9 -0
- package/pipeline/hastUtils/hastUtils.d.mts +4 -3
- package/pipeline/hastUtils/hastUtils.mjs +24 -12
- package/pipeline/hastUtils/index.d.mts +2 -1
- package/pipeline/hastUtils/index.mjs +2 -1
- package/pipeline/hastUtils/stripHighlightingSpans.d.mts +6 -2
- package/pipeline/hastUtils/stripHighlightingSpans.mjs +22 -10
- package/pipeline/lintJavascriptDemoFocus/lintJavascriptDemoFocus.mjs +10 -7
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.d.mts +31 -13
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +50 -55
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.d.mts +78 -0
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs +405 -0
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.d.mts +5 -5
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs +36 -66
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.d.mts +23 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.mjs +92 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.d.mts +19 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.mjs +25 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.d.mts +17 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.mjs +26 -0
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +26 -2
- package/pipeline/loadIsomorphicCodeVariant/diffHast.mjs +563 -19
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.d.mts +49 -0
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.mjs +152 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.d.mts +51 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.mjs +161 -0
- package/pipeline/loadIsomorphicCodeVariant/flattenCodeVariant.mjs +6 -3
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.d.mts +12 -0
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.mjs +44 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.d.mts +16 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.mjs +74 -0
- package/pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs +17 -5
- package/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs +229 -15
- package/pipeline/loadIsomorphicCodeVariant/transformSource.d.mts +2 -2
- package/pipeline/loadIsomorphicCodeVariant/transformSource.mjs +56 -22
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.mts +18 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +11 -7
- package/pipeline/loadServerTypes/hastTypeUtils.d.mts +2 -2
- package/pipeline/loadServerTypes/hastTypeUtils.mjs +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.mjs +1 -1
- package/pipeline/loadServerTypesMeta/extractJSDocText.d.mts +14 -0
- package/pipeline/loadServerTypesMeta/extractJSDocText.mjs +60 -0
- package/pipeline/loadServerTypesMeta/processTypes.mjs +43 -46
- package/pipeline/loadServerTypesText/order.mjs +1 -1
- package/pipeline/loadServerTypesText/parseTypesMarkdown.mjs +3 -1
- package/pipeline/loaderUtils/index.d.mts +0 -1
- package/pipeline/loaderUtils/index.mjs +0 -1
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -1
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +19 -9
- package/pipeline/loaderUtils/resolveModulePath.mjs +23 -1
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +12 -0
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +17 -13
- package/pipeline/parseSource/addLineGutters.mjs +45 -11
- package/pipeline/parseSource/calculateFrameRanges.d.mts +22 -0
- package/pipeline/parseSource/calculateFrameRanges.mjs +69 -25
- package/pipeline/parseSource/detectGrammarScopes.d.mts +13 -0
- package/pipeline/parseSource/detectGrammarScopes.mjs +35 -0
- package/pipeline/parseSource/extendSyntaxTokens.mjs +501 -43
- package/pipeline/parseSource/frameVisibility.d.mts +47 -0
- package/pipeline/parseSource/frameVisibility.mjs +114 -0
- package/pipeline/parseSource/grammarCache.d.mts +33 -0
- package/pipeline/parseSource/grammarCache.mjs +73 -0
- package/pipeline/parseSource/grammarLoaders.d.mts +14 -0
- package/pipeline/parseSource/grammarLoaders.mjs +24 -0
- package/pipeline/parseSource/grammarMaps.d.mts +21 -1
- package/pipeline/parseSource/grammarMaps.mjs +36 -0
- package/pipeline/parseSource/isFrameSpan.d.mts +19 -0
- package/pipeline/parseSource/isFrameSpan.mjs +24 -0
- package/pipeline/parseSource/parseSource.d.mts +41 -6
- package/pipeline/parseSource/parseSource.mjs +184 -36
- package/pipeline/parseSource/redistributeFrameFallbacks.d.mts +40 -0
- package/pipeline/parseSource/redistributeFrameFallbacks.mjs +138 -0
- package/pipeline/parseSource/restructureFrames.d.mts +5 -0
- package/pipeline/parseSource/restructureFrames.mjs +179 -16
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +6 -2
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.d.mts +26 -0
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +181 -114
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.d.mts +12 -0
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.mjs +52 -0
- package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +22 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.mts +5 -8
- package/pipeline/transformTypescriptToJavascript/removeTypes.mjs +27 -93
- package/useCode/EditableEngine.d.mts +233 -0
- package/useCode/EditableEngine.mjs +1712 -0
- package/useCode/EditingEngine.d.mts +13 -0
- package/useCode/EditingEngine.mjs +14 -0
- package/useCode/Pre.browser.mjs +5 -1
- package/useCode/Pre.d.mts +127 -1
- package/useCode/Pre.mjs +417 -165
- package/useCode/SourceEditingEngine.d.mts +50 -0
- package/useCode/SourceEditingEngine.mjs +461 -0
- package/useCode/TransformEngine.d.mts +39 -0
- package/useCode/TransformEngine.mjs +208 -0
- package/useCode/editingEngineCache.d.mts +29 -0
- package/useCode/editingEngineCache.mjs +68 -0
- package/useCode/sourceLineCounts.d.mts +80 -0
- package/useCode/sourceLineCounts.mjs +284 -0
- package/useCode/subscribeToggleNudge.d.mts +3 -0
- package/useCode/subscribeToggleNudge.mjs +95 -0
- package/useCode/transformEngineCache.d.mts +21 -0
- package/useCode/transformEngineCache.mjs +60 -0
- package/useCode/useCode.d.mts +140 -1
- package/useCode/useCode.mjs +250 -19
- package/useCode/useCodeUtils.d.mts +131 -20
- package/useCode/useCodeUtils.mjs +267 -194
- package/useCode/useCopyFunctionality.d.mts +13 -1
- package/useCode/useCopyFunctionality.mjs +39 -9
- package/useCode/useEditable.browser.mjs +10 -2
- package/useCode/useEditable.d.mts +27 -106
- package/useCode/useEditable.integration.browser.d.mts +1 -0
- package/useCode/useEditable.integration.browser.mjs +870 -0
- package/useCode/useEditable.mjs +198 -1247
- package/useCode/useEditableUtils.d.mts +50 -1
- package/useCode/useEditableUtils.mjs +29 -0
- package/useCode/useFileNavigation.d.mts +91 -3
- package/useCode/useFileNavigation.mjs +201 -41
- package/useCode/useHighlightGate.d.mts +17 -0
- package/useCode/useHighlightGate.mjs +147 -0
- package/useCode/useSourceEditing.d.mts +8 -0
- package/useCode/useSourceEditing.mjs +158 -314
- package/useCode/useSourceEnhancing.d.mts +5 -1
- package/useCode/useSourceEnhancing.mjs +22 -36
- package/useCode/useTransformManagement.d.mts +93 -5
- package/useCode/useTransformManagement.mjs +496 -28
- package/useCode/useTransitionPhase.d.mts +24 -0
- package/useCode/useTransitionPhase.mjs +49 -0
- package/useCode/useUIState.d.mts +2 -2
- package/useCode/useUIState.mjs +8 -8
- package/useCode/useVariantSelection.d.mts +130 -6
- package/useCode/useVariantSelection.mjs +529 -93
- package/useCodeWindow/useCodeWindow.d.mts +19 -2
- package/useCodeWindow/useCodeWindow.mjs +98 -71
- package/useCoordinated/coordinatePreference.d.mts +439 -0
- package/useCoordinated/coordinatePreference.mjs +951 -0
- package/useCoordinated/coordinatePreference.testUtils.d.mts +21 -0
- package/useCoordinated/coordinatePreference.testUtils.mjs +69 -0
- package/useCoordinated/createSettleGate.d.mts +96 -0
- package/useCoordinated/createSettleGate.mjs +171 -0
- package/useCoordinated/index.d.mts +8 -0
- package/useCoordinated/index.mjs +8 -0
- package/useCoordinated/layoutShiftGate.d.mts +24 -0
- package/useCoordinated/layoutShiftGate.mjs +79 -0
- package/useCoordinated/pageSettleGate.d.mts +11 -0
- package/useCoordinated/pageSettleGate.mjs +13 -0
- package/useCoordinated/scheduleTasks.d.mts +23 -0
- package/useCoordinated/scheduleTasks.mjs +45 -0
- package/useCoordinated/useCoordinated.d.mts +193 -0
- package/useCoordinated/useCoordinated.mjs +469 -0
- package/useCoordinated/useCoordinatedLazy.d.mts +17 -0
- package/useCoordinated/useCoordinatedLazy.mjs +38 -0
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +16 -0
- package/useCoordinated/useCoordinatedLocalStorage.mjs +22 -0
- package/useCoordinated/useCoordinatedPreference.d.mts +20 -0
- package/useCoordinated/useCoordinatedPreference.mjs +26 -0
- package/useCoordinated/useSettleGate.d.mts +11 -0
- package/useCoordinated/useSettleGate.mjs +34 -0
- package/useDemo/exportVariant.d.mts +12 -5
- package/useDemo/exportVariant.mjs +59 -5
- package/useDemo/useDemo.d.mts +5 -2
- package/useScrollAnchor/useScrollAnchor.mjs +28 -5
- package/useStream/index.d.mts +6 -0
- package/useStream/index.mjs +6 -0
- package/useStream/streamChunks.d.mts +23 -0
- package/useStream/streamChunks.mjs +85 -0
- package/useStream/types.d.mts +45 -0
- package/useStream/types.mjs +1 -0
- package/useStream/useStream.d.mts +57 -0
- package/useStream/useStream.mjs +119 -0
- package/useStream/useStreamController.d.mts +15 -0
- package/useStream/useStreamController.mjs +90 -0
- package/withDocsInfra/withDocsInfra.d.mts +19 -0
- package/withDocsInfra/withDocsInfra.mjs +13 -5
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.d.mts +0 -8
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.mjs +0 -16
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively walks a jsondiffpatch delta looking for any inserted hast
|
|
3
|
+
* element with `className === 'collapse'`. Used to mark a manifest entry
|
|
4
|
+
* as layout-affecting (phase 1, coordinated barrier so peers stay in
|
|
5
|
+
* lockstep) so the runtime doesn't have to decompress the embedded hast
|
|
6
|
+
* payload on every selection change to classify the swap.
|
|
7
|
+
*
|
|
8
|
+
* Walks every nested value rather than interpreting jsondiffpatch's
|
|
9
|
+
* opcodes (`[value]` for insert, `[oldValue, 0, 0]` for delete, `_t: 'a'`
|
|
10
|
+
* + `_N` keys for array ops). The collapse placeholder is only ever
|
|
11
|
+
* produced by `compactCollapseInTreeInPlace` on the *transform* side of
|
|
12
|
+
* the diff, so any hast element with className 'collapse' anywhere in
|
|
13
|
+
* the delta tree is necessarily part of an insertion or in-place rewrite.
|
|
14
|
+
*/
|
|
15
|
+
export function deltaContainsCollapse(delta) {
|
|
16
|
+
if (delta === null || typeof delta !== 'object') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const candidate = delta;
|
|
20
|
+
if (candidate.type === 'element') {
|
|
21
|
+
const cls = candidate.properties?.className;
|
|
22
|
+
if (cls === 'collapse') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(cls) && cls.includes('collapse')) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(delta)) {
|
|
30
|
+
for (const item of delta) {
|
|
31
|
+
if (deltaContainsCollapse(item)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
for (const value of Object.values(delta)) {
|
|
38
|
+
if (deltaContainsCollapse(value)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Splits a `Transforms` map (as produced by `diffHast`, which always
|
|
47
|
+
* carries deltas for entries that change the source — rename-only
|
|
48
|
+
* entries pass through with no delta) into the variant-level `manifest`
|
|
49
|
+
* (no `delta`) and the `embedded` map that should ride inside
|
|
50
|
+
* `source.data.transforms`.
|
|
51
|
+
*
|
|
52
|
+
* Entries with a meaningful delta land in both the manifest (with
|
|
53
|
+
* `hasDelta: true`) and the embedded map. Rename-only entries (no
|
|
54
|
+
* delta but a renamed `fileName`) land only in the manifest with
|
|
55
|
+
* `hasDelta` omitted or `false`; consumers use this flag to hide the
|
|
56
|
+
* transform toggle while still applying the rename when the user has
|
|
57
|
+
* the matching transform preference selected. Entries with neither a
|
|
58
|
+
* delta nor a rename are dropped from both.
|
|
59
|
+
*
|
|
60
|
+
* Returns `undefined` when no entry survived — callers should treat that
|
|
61
|
+
* as "no transforms to record".
|
|
62
|
+
*
|
|
63
|
+
* This is the single source of truth for the manifest / embedded split;
|
|
64
|
+
* both `computeHastDeltas` (per-file diffs) and the variant-level embed
|
|
65
|
+
* step in `loadIsomorphicCodeVariant` go through it so the wire shape
|
|
66
|
+
* stays consistent.
|
|
67
|
+
*/
|
|
68
|
+
export function splitTransformsForEmbed(transforms) {
|
|
69
|
+
const manifest = {};
|
|
70
|
+
const embedded = {};
|
|
71
|
+
let kept = false;
|
|
72
|
+
for (const [transformKey, transformValue] of Object.entries(transforms)) {
|
|
73
|
+
if (!transformValue) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const hasMeaningfulDelta = !!transformValue.delta && typeof transformValue.delta === 'object' && Object.keys(transformValue.delta).length > 0;
|
|
77
|
+
const renamed = !!transformValue.fileName;
|
|
78
|
+
if (hasMeaningfulDelta) {
|
|
79
|
+
embedded[transformKey] = transformValue;
|
|
80
|
+
// The manifest entry keeps every field except `delta` (which only
|
|
81
|
+
// ever travels embedded inside `root.data.transforms`). In
|
|
82
|
+
// particular `comments` must survive serialization: transformers
|
|
83
|
+
// that add or relocate lines emit an explicit post-transform map,
|
|
84
|
+
// and the client-side `applyCodeTransformWithComments` consults
|
|
85
|
+
// it in preference to the auto-shift fallback. Dropping it here
|
|
86
|
+
// would silently downgrade those transforms to the wipe-only
|
|
87
|
+
// remap path on hydrated payloads. `hasDelta: true` flags this
|
|
88
|
+
// entry for `getAvailableTransforms` so the transform toggle is
|
|
89
|
+
// surfaced in the UI. `hasCollapse` is propagated here so the
|
|
90
|
+
// runtime can classify the swap as layout-affecting (phase 1)
|
|
91
|
+
// versus non-layout (phase 2) without decompressing the embedded
|
|
92
|
+
// hast payload — `diffHast` sets it directly from
|
|
93
|
+
// `wiped.size > 0`; the `deltaContainsCollapse` walk only runs
|
|
94
|
+
// for legacy callers that build a `Transforms` map without going
|
|
95
|
+
// through `diffHast`.
|
|
96
|
+
const hasCollapse = transformValue.hasCollapse ?? deltaContainsCollapse(transformValue.delta);
|
|
97
|
+
// `hasCollapseInFocus` only ever comes from `diffHast`; legacy
|
|
98
|
+
// callers (that bypass the diff and so never set it) fall back
|
|
99
|
+
// to `hasCollapse`, matching the pre-focus behavior of the
|
|
100
|
+
// runtime classifier.
|
|
101
|
+
const hasCollapseInFocus = transformValue.hasCollapseInFocus ?? hasCollapse;
|
|
102
|
+
const manifestEntry = {
|
|
103
|
+
...transformValue,
|
|
104
|
+
hasDelta: true,
|
|
105
|
+
hasCollapse,
|
|
106
|
+
hasCollapseInFocus
|
|
107
|
+
};
|
|
108
|
+
delete manifestEntry.delta;
|
|
109
|
+
manifest[transformKey] = manifestEntry;
|
|
110
|
+
kept = true;
|
|
111
|
+
} else if (renamed) {
|
|
112
|
+
// Rename-only entry: no source-level change, just a `fileName`
|
|
113
|
+
// (and optionally `comments`). Keep it in the manifest so the
|
|
114
|
+
// runtime can still apply the rename when the user has the
|
|
115
|
+
// matching transform preference selected, but skip embedding —
|
|
116
|
+
// there's no delta to ride along inside `source.data.transforms`.
|
|
117
|
+
const {
|
|
118
|
+
delta: droppedDelta,
|
|
119
|
+
hasDelta: droppedHasDelta,
|
|
120
|
+
hasCollapse: droppedHasCollapse,
|
|
121
|
+
hasCollapseInFocus: droppedHasCollapseInFocus,
|
|
122
|
+
...rest
|
|
123
|
+
} = transformValue;
|
|
124
|
+
manifest[transformKey] = {
|
|
125
|
+
...rest,
|
|
126
|
+
hasDelta: false,
|
|
127
|
+
hasCollapse: false,
|
|
128
|
+
hasCollapseInFocus: false
|
|
129
|
+
};
|
|
130
|
+
kept = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!kept) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
manifest,
|
|
138
|
+
embedded
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Embeds `embedded` transforms inside `root.data.transforms` so they ride
|
|
144
|
+
* along inside the (possibly later compressed) hast payload and stay out
|
|
145
|
+
* of the variant-level wire shape that ends up in HTML / module graph.
|
|
146
|
+
*/
|
|
147
|
+
export function embedTransformsInRoot(root, embedded) {
|
|
148
|
+
root.data = {
|
|
149
|
+
...(root.data || {}),
|
|
150
|
+
transforms: embedded
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SourceComments } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Sentinel substrings a transformer puts into its returned `comments`
|
|
4
|
+
* map to mark newly-added lines that should animate in (when the
|
|
5
|
+
* transform is applied) or out (when it is reverted). The markers are
|
|
6
|
+
* metadata only — they never appear in the rendered source text.
|
|
7
|
+
* Detection is substring-based so callers can decorate them however
|
|
8
|
+
* reads best alongside any neighbouring comments
|
|
9
|
+
* (e.g. `'// @expanding-start (api key)'`).
|
|
10
|
+
*
|
|
11
|
+
* Two flavours:
|
|
12
|
+
* - `@expanding-start` / `@expanding-end` delimit a contiguous,
|
|
13
|
+
* multi-line range (inclusive on both ends).
|
|
14
|
+
* - `@expanding` on its own marks a single added line — equivalent
|
|
15
|
+
* to a same-line start+end pair, but easier to write when the
|
|
16
|
+
* addition is just one line.
|
|
17
|
+
*/
|
|
18
|
+
export declare const EXPANDING_START_MARKER = "@expanding-start";
|
|
19
|
+
export declare const EXPANDING_END_MARKER = "@expanding-end";
|
|
20
|
+
export declare const EXPANDING_SINGLE_MARKER = "@expanding";
|
|
21
|
+
/**
|
|
22
|
+
* Scans a `SourceComments` map for `@expanding`, `@expanding-start`,
|
|
23
|
+
* and `@expanding-end` markers and returns the inclusive 1-indexed
|
|
24
|
+
* line ranges they delimit.
|
|
25
|
+
*
|
|
26
|
+
* Pairing rule: walk lines in ascending order. A standalone
|
|
27
|
+
* `@expanding` immediately produces a single-line `[line, line]`
|
|
28
|
+
* range. For ranges, the first `@expanding-start` opens a range and
|
|
29
|
+
* the next `@expanding-end` closes it. Unpaired range markers (a
|
|
30
|
+
* start with no matching end, or an end with no preceding start) are
|
|
31
|
+
* silently dropped — the most likely cause is a transformer
|
|
32
|
+
* mid-iteration and the safe behaviour is "no animation for that
|
|
33
|
+
* fragment" rather than either crashing or animating an unbounded
|
|
34
|
+
* region. Nested or overlapping ranges are not supported; a second
|
|
35
|
+
* `@expanding-start` before the previous one is closed replaces the
|
|
36
|
+
* open range's start.
|
|
37
|
+
*
|
|
38
|
+
* @param comments - The remapped 1-indexed comments map.
|
|
39
|
+
* @returns Sorted `[startLine, endLine]` pairs (inclusive on both
|
|
40
|
+
* ends). Returns an empty array when `comments` is `undefined`,
|
|
41
|
+
* empty, or contains no markers.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findExpandingRanges(comments: SourceComments | undefined): Array<[number, number]>;
|
|
44
|
+
/**
|
|
45
|
+
* Fast yes/no check used by the pipeline's layout-shift classifier so
|
|
46
|
+
* it can avoid materialising the full `findExpandingRanges` array when
|
|
47
|
+
* all it needs is a boolean. Equivalent to
|
|
48
|
+
* `findExpandingRanges(...).length > 0` but short-circuits on the first
|
|
49
|
+
* matched marker.
|
|
50
|
+
*/
|
|
51
|
+
export declare function hasExpandingRanges(comments: SourceComments | undefined): boolean;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinel substrings a transformer puts into its returned `comments`
|
|
3
|
+
* map to mark newly-added lines that should animate in (when the
|
|
4
|
+
* transform is applied) or out (when it is reverted). The markers are
|
|
5
|
+
* metadata only — they never appear in the rendered source text.
|
|
6
|
+
* Detection is substring-based so callers can decorate them however
|
|
7
|
+
* reads best alongside any neighbouring comments
|
|
8
|
+
* (e.g. `'// @expanding-start (api key)'`).
|
|
9
|
+
*
|
|
10
|
+
* Two flavours:
|
|
11
|
+
* - `@expanding-start` / `@expanding-end` delimit a contiguous,
|
|
12
|
+
* multi-line range (inclusive on both ends).
|
|
13
|
+
* - `@expanding` on its own marks a single added line — equivalent
|
|
14
|
+
* to a same-line start+end pair, but easier to write when the
|
|
15
|
+
* addition is just one line.
|
|
16
|
+
*/
|
|
17
|
+
export const EXPANDING_START_MARKER = '@expanding-start';
|
|
18
|
+
export const EXPANDING_END_MARKER = '@expanding-end';
|
|
19
|
+
export const EXPANDING_SINGLE_MARKER = '@expanding';
|
|
20
|
+
|
|
21
|
+
// `@expanding` not followed by `-` — distinguishes the single-line
|
|
22
|
+
// marker from the `-start` / `-end` variants without false matches.
|
|
23
|
+
const SINGLE_MARKER_PATTERN = /@expanding(?!-)/;
|
|
24
|
+
function classifyEntries(entries) {
|
|
25
|
+
let hasStart = false;
|
|
26
|
+
let hasEnd = false;
|
|
27
|
+
let hasSingle = false;
|
|
28
|
+
if (!entries) {
|
|
29
|
+
return {
|
|
30
|
+
hasStart,
|
|
31
|
+
hasEnd,
|
|
32
|
+
hasSingle
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
if (typeof entry !== 'string') {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (entry.includes(EXPANDING_START_MARKER)) {
|
|
40
|
+
hasStart = true;
|
|
41
|
+
}
|
|
42
|
+
if (entry.includes(EXPANDING_END_MARKER)) {
|
|
43
|
+
hasEnd = true;
|
|
44
|
+
}
|
|
45
|
+
if (SINGLE_MARKER_PATTERN.test(entry)) {
|
|
46
|
+
hasSingle = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
hasStart,
|
|
51
|
+
hasEnd,
|
|
52
|
+
hasSingle
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function collectLineNumbers(comments) {
|
|
56
|
+
const lineNumbers = [];
|
|
57
|
+
for (const key of Object.keys(comments)) {
|
|
58
|
+
const line = Number(key);
|
|
59
|
+
if (Number.isFinite(line) && line > 0) {
|
|
60
|
+
lineNumbers.push(line);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
lineNumbers.sort((a, b) => a - b);
|
|
64
|
+
return lineNumbers;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Scans a `SourceComments` map for `@expanding`, `@expanding-start`,
|
|
69
|
+
* and `@expanding-end` markers and returns the inclusive 1-indexed
|
|
70
|
+
* line ranges they delimit.
|
|
71
|
+
*
|
|
72
|
+
* Pairing rule: walk lines in ascending order. A standalone
|
|
73
|
+
* `@expanding` immediately produces a single-line `[line, line]`
|
|
74
|
+
* range. For ranges, the first `@expanding-start` opens a range and
|
|
75
|
+
* the next `@expanding-end` closes it. Unpaired range markers (a
|
|
76
|
+
* start with no matching end, or an end with no preceding start) are
|
|
77
|
+
* silently dropped — the most likely cause is a transformer
|
|
78
|
+
* mid-iteration and the safe behaviour is "no animation for that
|
|
79
|
+
* fragment" rather than either crashing or animating an unbounded
|
|
80
|
+
* region. Nested or overlapping ranges are not supported; a second
|
|
81
|
+
* `@expanding-start` before the previous one is closed replaces the
|
|
82
|
+
* open range's start.
|
|
83
|
+
*
|
|
84
|
+
* @param comments - The remapped 1-indexed comments map.
|
|
85
|
+
* @returns Sorted `[startLine, endLine]` pairs (inclusive on both
|
|
86
|
+
* ends). Returns an empty array when `comments` is `undefined`,
|
|
87
|
+
* empty, or contains no markers.
|
|
88
|
+
*/
|
|
89
|
+
export function findExpandingRanges(comments) {
|
|
90
|
+
if (!comments) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const lineNumbers = collectLineNumbers(comments);
|
|
94
|
+
if (lineNumbers.length === 0) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const ranges = [];
|
|
98
|
+
let openStart = null;
|
|
99
|
+
for (const line of lineNumbers) {
|
|
100
|
+
const {
|
|
101
|
+
hasStart,
|
|
102
|
+
hasEnd,
|
|
103
|
+
hasSingle
|
|
104
|
+
} = classifyEntries(comments[line]);
|
|
105
|
+
if (hasSingle) {
|
|
106
|
+
ranges.push([line, line]);
|
|
107
|
+
}
|
|
108
|
+
// Same-line start+end (multi-line addition collapsed to one line)
|
|
109
|
+
// is a valid range.
|
|
110
|
+
if (hasStart && hasEnd) {
|
|
111
|
+
ranges.push([line, line]);
|
|
112
|
+
openStart = null;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (hasStart) {
|
|
116
|
+
openStart = line;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (hasEnd && openStart !== null) {
|
|
120
|
+
ranges.push([openStart, line]);
|
|
121
|
+
openStart = null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return ranges;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Fast yes/no check used by the pipeline's layout-shift classifier so
|
|
129
|
+
* it can avoid materialising the full `findExpandingRanges` array when
|
|
130
|
+
* all it needs is a boolean. Equivalent to
|
|
131
|
+
* `findExpandingRanges(...).length > 0` but short-circuits on the first
|
|
132
|
+
* matched marker.
|
|
133
|
+
*/
|
|
134
|
+
export function hasExpandingRanges(comments) {
|
|
135
|
+
if (!comments) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const lineNumbers = collectLineNumbers(comments);
|
|
139
|
+
let openStart = false;
|
|
140
|
+
for (const line of lineNumbers) {
|
|
141
|
+
const {
|
|
142
|
+
hasStart,
|
|
143
|
+
hasEnd,
|
|
144
|
+
hasSingle
|
|
145
|
+
} = classifyEntries(comments[line]);
|
|
146
|
+
if (hasSingle) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (hasStart && hasEnd) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (hasStart) {
|
|
153
|
+
openStart = true;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (hasEnd && openStart) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Uses addPathsToVariant for the core logic, then flattens the result
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { decodeSourceToText } from "./decodeSourceToText.mjs";
|
|
8
8
|
import { addPathsToVariant } from "./addCodeVariantPaths.mjs";
|
|
9
9
|
/**
|
|
10
10
|
* Flatten a VariantCode into a flat files structure
|
|
@@ -20,7 +20,10 @@ export function flattenCodeVariant(variant) {
|
|
|
20
20
|
// Add main file if it exists
|
|
21
21
|
if (variantWithPaths.path && variantWithPaths.source !== undefined) {
|
|
22
22
|
result[variantWithPaths.path] = {
|
|
23
|
-
source
|
|
23
|
+
// The source may be `hastCompressed`; its `fallback` is the DEFLATE
|
|
24
|
+
// dictionary needed to decode it back to text. `decodeSourceToText` reuses
|
|
25
|
+
// the shared decode cache rather than re-inflating on every export.
|
|
26
|
+
source: decodeSourceToText(variantWithPaths.source, variantWithPaths.fallback)
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -37,7 +40,7 @@ export function flattenCodeVariant(variant) {
|
|
|
37
40
|
continue;
|
|
38
41
|
}
|
|
39
42
|
result[fileWithPath.path] = {
|
|
40
|
-
source:
|
|
43
|
+
source: decodeSourceToText(fileWithPath.source, fileWithPath.fallback),
|
|
41
44
|
...(fileWithPath.metadata && {
|
|
42
45
|
metadata: fileWithPath.metadata
|
|
43
46
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Code } from "../../CodeHighlighter/types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Pure function to get available transforms from a specific variant.
|
|
4
|
+
*
|
|
5
|
+
* Variant-level `transforms` is a manifest produced by `splitTransformsForEmbed`
|
|
6
|
+
* (or by the legacy `Transforms` shape with deltas, for back-compat). Only
|
|
7
|
+
* entries that produced a real source delta are reported here — rename-only
|
|
8
|
+
* entries (manifest entries with `hasDelta: false`, kept around so the
|
|
9
|
+
* runtime can still apply the rename based on user preference) are filtered
|
|
10
|
+
* out so the transform toggle stays hidden when nothing meaningful changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAvailableTransforms(parsedCode: Code | undefined, variantName: string): string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure function to get available transforms from a specific variant.
|
|
3
|
+
*
|
|
4
|
+
* Variant-level `transforms` is a manifest produced by `splitTransformsForEmbed`
|
|
5
|
+
* (or by the legacy `Transforms` shape with deltas, for back-compat). Only
|
|
6
|
+
* entries that produced a real source delta are reported here — rename-only
|
|
7
|
+
* entries (manifest entries with `hasDelta: false`, kept around so the
|
|
8
|
+
* runtime can still apply the rename based on user preference) are filtered
|
|
9
|
+
* out so the transform toggle stays hidden when nothing meaningful changes.
|
|
10
|
+
*/
|
|
11
|
+
export function getAvailableTransforms(parsedCode, variantName) {
|
|
12
|
+
const currentVariant = parsedCode?.[variantName];
|
|
13
|
+
if (!currentVariant || typeof currentVariant !== 'object') {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const transforms = new Set();
|
|
17
|
+
const addIfMeaningful = entries => {
|
|
18
|
+
if (!entries) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const [transformKey, entry] of Object.entries(entries)) {
|
|
22
|
+
if (!entry) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// Manifest entries set `hasDelta: true` when a real delta survived
|
|
26
|
+
// serialization. Legacy entries that still carry an inline `delta`
|
|
27
|
+
// also qualify (back-compat for callers that haven't gone through
|
|
28
|
+
// `splitTransformsForEmbed`).
|
|
29
|
+
const inlineDelta = !!entry.delta && typeof entry.delta === 'object' && Object.keys(entry.delta).length > 0;
|
|
30
|
+
if (entry.hasDelta || inlineDelta) {
|
|
31
|
+
transforms.add(transformKey);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
addIfMeaningful(currentVariant.transforms);
|
|
36
|
+
if (currentVariant.extraFiles) {
|
|
37
|
+
for (const fileData of Object.values(currentVariant.extraFiles)) {
|
|
38
|
+
if (fileData && typeof fileData === 'object' && 'transforms' in fileData) {
|
|
39
|
+
addIfMeaningful(fileData.transforms);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Array.from(transforms);
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Nodes } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the set of 1-indexed source line numbers that are visible when
|
|
4
|
+
* the rendered code block is collapsed (i.e. the user hasn't clicked
|
|
5
|
+
* "expand"). Mirrors the visibility rule applied at runtime by `<Pre>`:
|
|
6
|
+
*
|
|
7
|
+
* - Frames whose `data-frame-type` is `'highlighted'`, `'focus'`,
|
|
8
|
+
* `'padding-top'`, or `'padding-bottom'` are visible.
|
|
9
|
+
* - When no such emphasis frame exists, only the first frame is shown
|
|
10
|
+
* (this matches `getInitialVisibleFrames` in `<Pre>`).
|
|
11
|
+
*
|
|
12
|
+
* `tree` must be the output of `parseSource` (a `Root` whose top-level
|
|
13
|
+
* children are frame `Element`s with `'line'` `Element` descendants).
|
|
14
|
+
* Returns an empty set for an empty/invalid tree.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getInitialVisibleSourceLines(tree: Nodes): Set<number>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { COLLAPSED_VISIBLE_FRAME_TYPES } from "../parseSource/frameVisibility.mjs";
|
|
2
|
+
import { isFrameSpan } from "../parseSource/isFrameSpan.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the set of 1-indexed source line numbers that are visible when
|
|
6
|
+
* the rendered code block is collapsed (i.e. the user hasn't clicked
|
|
7
|
+
* "expand"). Mirrors the visibility rule applied at runtime by `<Pre>`:
|
|
8
|
+
*
|
|
9
|
+
* - Frames whose `data-frame-type` is `'highlighted'`, `'focus'`,
|
|
10
|
+
* `'padding-top'`, or `'padding-bottom'` are visible.
|
|
11
|
+
* - When no such emphasis frame exists, only the first frame is shown
|
|
12
|
+
* (this matches `getInitialVisibleFrames` in `<Pre>`).
|
|
13
|
+
*
|
|
14
|
+
* `tree` must be the output of `parseSource` (a `Root` whose top-level
|
|
15
|
+
* children are frame `Element`s with `'line'` `Element` descendants).
|
|
16
|
+
* Returns an empty set for an empty/invalid tree.
|
|
17
|
+
*/
|
|
18
|
+
export function getInitialVisibleSourceLines(tree) {
|
|
19
|
+
const visible = new Set();
|
|
20
|
+
if (tree.type !== 'root') {
|
|
21
|
+
return visible;
|
|
22
|
+
}
|
|
23
|
+
const root = tree;
|
|
24
|
+
let lineNumber = 0;
|
|
25
|
+
let hasVisibleEmphasisFrame = false;
|
|
26
|
+
// First pass: collect lines under explicitly-visible emphasis frames.
|
|
27
|
+
for (const child of root.children) {
|
|
28
|
+
if (child.type !== 'element' || !isFrameSpan(child)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const frame = child;
|
|
32
|
+
const frameType = frame.properties?.dataFrameType;
|
|
33
|
+
const frameVisible = typeof frameType === 'string' && COLLAPSED_VISIBLE_FRAME_TYPES.has(frameType);
|
|
34
|
+
if (frameVisible) {
|
|
35
|
+
hasVisibleEmphasisFrame = true;
|
|
36
|
+
}
|
|
37
|
+
for (const grandChild of frame.children) {
|
|
38
|
+
if (grandChild.type === 'element' && grandChild.properties?.className === 'line') {
|
|
39
|
+
lineNumber += 1;
|
|
40
|
+
if (frameVisible) {
|
|
41
|
+
visible.add(lineNumber);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Collapse-to-nothing (oversizedFocus: 'hide'): the source records
|
|
48
|
+
// `focusedLines === 0`, meaning the collapsed window is intentionally empty.
|
|
49
|
+
// Skip the first-frame fallback so nothing is shown when collapsed.
|
|
50
|
+
if (root.data?.focusedLines === 0) {
|
|
51
|
+
return visible;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Fallback: no emphasis frame in the source — the first frame is the
|
|
55
|
+
// one shown when collapsed. Add its lines.
|
|
56
|
+
if (!hasVisibleEmphasisFrame && lineNumber > 0) {
|
|
57
|
+
let fallbackLine = 0;
|
|
58
|
+
for (const child of root.children) {
|
|
59
|
+
if (child.type !== 'element' || !isFrameSpan(child)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const frame = child;
|
|
63
|
+
for (const grandChild of frame.children) {
|
|
64
|
+
if (grandChild.type === 'element' && grandChild.properties?.className === 'line') {
|
|
65
|
+
fallbackLine += 1;
|
|
66
|
+
visible.add(fallbackLine);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Only the first frame.
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return visible;
|
|
74
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadIsomorphicCodeVariant } from "./loadIsomorphicCodeVariant.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { getFileNameFromUrl, getLanguageFromExtension } from "../loaderUtils/index.mjs";
|
|
3
3
|
import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.mjs";
|
|
4
4
|
|
|
5
5
|
// Helper function to get the source for a specific filename from a variant
|
|
@@ -74,9 +74,10 @@ function enrichVariantWithLoadedSource(base, source, comments, externals) {
|
|
|
74
74
|
...base,
|
|
75
75
|
source
|
|
76
76
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
// `loadSource` returns 1-indexed comments (the stored `Code` convention), so apply them
|
|
78
|
+
// as-is — no conversion at the source-loader boundary.
|
|
79
|
+
if (comments) {
|
|
80
|
+
enriched.comments = comments;
|
|
80
81
|
}
|
|
81
82
|
if (externals && Object.keys(externals).length > 0) {
|
|
82
83
|
enriched.externals = Object.keys(externals);
|
|
@@ -112,6 +113,14 @@ export async function loadCodeFallback(url, initialVariant, loaded, options = {}
|
|
|
112
113
|
loaded = {
|
|
113
114
|
...loaded
|
|
114
115
|
};
|
|
116
|
+
|
|
117
|
+
// When not highlighting (deferred), pass `disableParsing: true`: the source must
|
|
118
|
+
// stay a plain string so the client knows it still needs syntax highlighting (a
|
|
119
|
+
// HAST source reads as "already loaded"). `loadIsomorphicCodeVariant` still frames
|
|
120
|
+
// the loading fallback itself in that mode — line gutters + enhancers → root
|
|
121
|
+
// fallback — only the syntax colors are deferred. When highlighting, the real
|
|
122
|
+
// `sourceParser` runs and the source becomes a highlighted HAST as before.
|
|
123
|
+
|
|
115
124
|
const functionName = 'Load Fallback Code';
|
|
116
125
|
let currentMark = performanceMeasure(undefined, {
|
|
117
126
|
mark: 'Start',
|
|
@@ -381,8 +390,10 @@ export async function loadCodeFallback(url, initialVariant, loaded, options = {}
|
|
|
381
390
|
sourceEnhancers,
|
|
382
391
|
disableTransforms: true,
|
|
383
392
|
// Don't apply transforms for fallback
|
|
393
|
+
// Deferred highlight: keep the source a plain string, but still frame the
|
|
394
|
+
// loading fallback (plain-text gutters + enhancers → root fallback).
|
|
384
395
|
disableParsing: !shouldHighlight,
|
|
385
|
-
|
|
396
|
+
framePlainFallback: true,
|
|
386
397
|
globalsCode: resolvedGlobalsCode,
|
|
387
398
|
// Pass resolved globalsCode
|
|
388
399
|
output,
|
|
@@ -478,6 +489,7 @@ export async function loadCodeFallback(url, initialVariant, loaded, options = {}
|
|
|
478
489
|
sourceEnhancers,
|
|
479
490
|
disableTransforms: true,
|
|
480
491
|
disableParsing: !shouldHighlight,
|
|
492
|
+
framePlainFallback: true,
|
|
481
493
|
output,
|
|
482
494
|
urlPrefix,
|
|
483
495
|
globalsCode: globalsCodeObjects && globalsCodeObjects.length > 0 ? (() => {
|