@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,422 @@
|
|
|
1
|
+
import { COLLAPSED_VISIBLE_FRAME_TYPES } from "../pipeline/parseSource/frameVisibility.mjs";
|
|
2
|
+
import { isFrameSpan } from "../pipeline/parseSource/isFrameSpan.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compact serialization format for fallback HAST trees.
|
|
6
|
+
*
|
|
7
|
+
* A `FallbackNode` is either:
|
|
8
|
+
* - a plain string (text node), or
|
|
9
|
+
* - a variable-length tuple whose meaning is determined by length:
|
|
10
|
+
* - `[tagName, children]` – no class, no props
|
|
11
|
+
* - `[tagName, className, children]` – has class, no props
|
|
12
|
+
* - `[tagName, className, properties, children]` – has class and props
|
|
13
|
+
* - `[tagName, className, properties, children, extra]` – full
|
|
14
|
+
*
|
|
15
|
+
* Where:
|
|
16
|
+
* - `tagName` – HTML element name (e.g. `'span'`, `'a'`)
|
|
17
|
+
* - `className` – space-joined class string
|
|
18
|
+
* - `properties` – remaining HTML properties (without `className`)
|
|
19
|
+
* - `children` – a single text string **or** an array of child `FallbackNode`s
|
|
20
|
+
* - `extra` – optional bag for anything else (data attributes, etc.)
|
|
21
|
+
*
|
|
22
|
+
* This eliminates the repeated `type`, `tagName`, `properties`, `children`,
|
|
23
|
+
* and `value` keys that make raw HAST costly in RSC payloads.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A residual fallback that has been DEFLATE-compressed on its own. Mirrors the
|
|
28
|
+
* `{ hastCompressed }` shape of `VariantSource`.
|
|
29
|
+
*
|
|
30
|
+
* Used for the parts of a variant's fallback that the `ContentLoading`
|
|
31
|
+
* component never renders (extra files when the loading UI shows a single file,
|
|
32
|
+
* extra variants when it shows a single variant). Those residual fallbacks
|
|
33
|
+
* exist only as the DEFLATE dictionary for decompressing `hastCompressed`, so
|
|
34
|
+
* shipping them as plain `FallbackNode[]` text would be dead weight in the
|
|
35
|
+
* initial payload. They are compressed standalone — no preset text dictionary,
|
|
36
|
+
* so the blob is self-contained — and decompressed back to `FallbackNode[]`
|
|
37
|
+
* (via `decompressFallback`) only when the full content swaps in.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Convert a HAST root into the compact `FallbackNode[]` format.
|
|
42
|
+
*/
|
|
43
|
+
export function hastToFallback(root) {
|
|
44
|
+
return convertChildren(root.children);
|
|
45
|
+
}
|
|
46
|
+
function convertChildren(children) {
|
|
47
|
+
return children.map(convertNode);
|
|
48
|
+
}
|
|
49
|
+
function convertNode(node) {
|
|
50
|
+
if (node.type === 'text') {
|
|
51
|
+
return node.value;
|
|
52
|
+
}
|
|
53
|
+
if (node.type === 'element') {
|
|
54
|
+
const el = node;
|
|
55
|
+
const {
|
|
56
|
+
className,
|
|
57
|
+
...restProps
|
|
58
|
+
} = el.properties || {};
|
|
59
|
+
let classStr = '';
|
|
60
|
+
if (className != null) {
|
|
61
|
+
classStr = Array.isArray(className) ? className.join(' ') : String(className);
|
|
62
|
+
}
|
|
63
|
+
const props = Object.keys(restProps).length > 0 ? restProps : null;
|
|
64
|
+
const kids = el.children ?? [];
|
|
65
|
+
|
|
66
|
+
// Optimize single-text-child to inline string
|
|
67
|
+
let childValue;
|
|
68
|
+
if (kids.length === 1 && kids[0].type === 'text') {
|
|
69
|
+
childValue = kids[0].value;
|
|
70
|
+
} else {
|
|
71
|
+
childValue = convertChildren(kids);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Variable-length tuple: omit trailing empty fields
|
|
75
|
+
if (props !== null) {
|
|
76
|
+
return [el.tagName, classStr, props, childValue];
|
|
77
|
+
}
|
|
78
|
+
if (classStr) {
|
|
79
|
+
return [el.tagName, classStr, childValue];
|
|
80
|
+
}
|
|
81
|
+
return [el.tagName, childValue];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// For any other node types (comment, doctype, etc.), skip
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Convert the compact `FallbackNode[]` format back into a HAST root.
|
|
90
|
+
*/
|
|
91
|
+
export function fallbackToHast(nodes) {
|
|
92
|
+
// `ElementContent` (text/element) is a subset of `RootContent`, so the mapped
|
|
93
|
+
// children satisfy `Root.children` directly.
|
|
94
|
+
return {
|
|
95
|
+
type: 'root',
|
|
96
|
+
children: nodes.map(nodeToHast)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function nodeToHast(node) {
|
|
100
|
+
if (typeof node === 'string') {
|
|
101
|
+
return {
|
|
102
|
+
type: 'text',
|
|
103
|
+
value: node
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let tagName;
|
|
107
|
+
let classStr;
|
|
108
|
+
let props;
|
|
109
|
+
let children;
|
|
110
|
+
let extra;
|
|
111
|
+
if (node.length === 2) {
|
|
112
|
+
[tagName, children] = node;
|
|
113
|
+
} else if (node.length === 3) {
|
|
114
|
+
[tagName, classStr, children] = node;
|
|
115
|
+
} else if (node.length === 5) {
|
|
116
|
+
[tagName, classStr, props, children, extra] = node;
|
|
117
|
+
} else {
|
|
118
|
+
[tagName, classStr, props, children] = node;
|
|
119
|
+
}
|
|
120
|
+
const properties = {
|
|
121
|
+
...props,
|
|
122
|
+
...extra
|
|
123
|
+
};
|
|
124
|
+
if (classStr) {
|
|
125
|
+
properties.className = classStr.split(' ');
|
|
126
|
+
}
|
|
127
|
+
const childNodes = typeof children === 'string' ? [{
|
|
128
|
+
type: 'text',
|
|
129
|
+
value: children
|
|
130
|
+
}] : children.map(nodeToHast);
|
|
131
|
+
return {
|
|
132
|
+
type: 'element',
|
|
133
|
+
tagName,
|
|
134
|
+
// The fallback tuple stores element props as `unknown`; assert they are
|
|
135
|
+
// valid HAST property values at this boundary (the one untyped seam).
|
|
136
|
+
properties: properties,
|
|
137
|
+
children: childNodes
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Extract the text content from compact `FallbackNode[]` without
|
|
143
|
+
* converting back to HAST. Used to build DEFLATE dictionaries.
|
|
144
|
+
*/
|
|
145
|
+
export function fallbackToText(nodes) {
|
|
146
|
+
return nodes.map(nodeText).join('');
|
|
147
|
+
}
|
|
148
|
+
function nodeText(node) {
|
|
149
|
+
if (typeof node === 'string') {
|
|
150
|
+
return node;
|
|
151
|
+
}
|
|
152
|
+
// children is always the last element (or second-to-last when extra is present)
|
|
153
|
+
const children = node.length === 5 ? node[3] : node[node.length - 1];
|
|
154
|
+
if (typeof children === 'string') {
|
|
155
|
+
return children;
|
|
156
|
+
}
|
|
157
|
+
return children.map(nodeText).join('');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Collects the plain text of a frame from its `.line` spans and the newline
|
|
162
|
+
* text nodes between them. Used only as a fallback when a frame is missing a
|
|
163
|
+
* precomputed `data.fallback` (which `addLineGutters` normally provides);
|
|
164
|
+
* walks the frame's direct children once without recursing into highlighting
|
|
165
|
+
* spans beyond their text.
|
|
166
|
+
*/
|
|
167
|
+
function collectFrameText(frame) {
|
|
168
|
+
let out = '';
|
|
169
|
+
const visit = nodes => {
|
|
170
|
+
for (const node of nodes) {
|
|
171
|
+
if (node.type === 'text') {
|
|
172
|
+
out += node.value;
|
|
173
|
+
} else if (node.type === 'element') {
|
|
174
|
+
visit(node.children);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
visit(frame.children);
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The frame's precomputed plain-text fallback (`frame.data.fallback`, set by
|
|
184
|
+
* `addLineGutters`), falling back to walking the frame's text when absent. This
|
|
185
|
+
* is the exact text the highlighted children render, so it doubles as the
|
|
186
|
+
* DEFLATE dictionary contribution for the frame.
|
|
187
|
+
*/
|
|
188
|
+
function framePlainText(frame) {
|
|
189
|
+
const fallbackNodes = frame.data?.fallback;
|
|
190
|
+
return fallbackNodes && fallbackNodes.length > 0 ? fallbackNodes.map(node => node.type === 'text' ? node.value : '').join('') : collectFrameText(frame);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Builds the variant-level root fallback from a final (post-enhancer) HAST
|
|
195
|
+
* root. Each `span.frame` becomes a compact frame element whose single text
|
|
196
|
+
* child is the frame's precomputed plain text (`frame.data.fallback`), so the
|
|
197
|
+
* result is directly renderable as the pre-hydration code block **and** can be
|
|
198
|
+
* redistributed back onto the decoded HAST's frames (see
|
|
199
|
+
* `redistributeRootFallback`).
|
|
200
|
+
*
|
|
201
|
+
* The frame's `data-lined` attribute is dropped (line spans don't exist in the
|
|
202
|
+
* fallback) while other frame attributes (e.g. `data-frame-type`) are kept so
|
|
203
|
+
* the fallback's layout matches the highlighted render. Non-frame top-level
|
|
204
|
+
* nodes (e.g. whitespace text between frames) are preserved in place.
|
|
205
|
+
*/
|
|
206
|
+
export function buildRootFallback(root) {
|
|
207
|
+
const syntheticChildren = [];
|
|
208
|
+
for (const child of root.children) {
|
|
209
|
+
if (child.type === 'element' && isFrameSpan(child)) {
|
|
210
|
+
const frame = child;
|
|
211
|
+
const {
|
|
212
|
+
dataLined,
|
|
213
|
+
...properties
|
|
214
|
+
} = frame.properties || {};
|
|
215
|
+
syntheticChildren.push({
|
|
216
|
+
type: 'element',
|
|
217
|
+
tagName: 'span',
|
|
218
|
+
properties,
|
|
219
|
+
children: [{
|
|
220
|
+
type: 'text',
|
|
221
|
+
value: framePlainText(frame)
|
|
222
|
+
}]
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
syntheticChildren.push(child);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return convertChildren(syntheticChildren);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** A frame node in compact `FallbackNode` form — `['span', 'frame', …]`, in any of the
|
|
232
|
+
* 3/4/5-element shapes (`className` is always the second element). */
|
|
233
|
+
function isFrameFallbackNode(node) {
|
|
234
|
+
return Array.isArray(node) && node.length >= 3 && node[0] === 'span' && typeof node[1] === 'string' && node[1].split(' ').includes('frame');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Whether a compact `fallback` already carries highlighting — i.e. at least one frame
|
|
239
|
+
* keeps nested token spans (array children) instead of flat plain text. True exactly for
|
|
240
|
+
* the promoted {@link promoteCriticalFallback} form; a plain {@link buildRootFallback} has
|
|
241
|
+
* a string child on every frame. `<Pre>` uses this to defer the decompressing decode ONLY
|
|
242
|
+
* when the first paint is already highlighted, so it never flashes plain → highlighted.
|
|
243
|
+
*/
|
|
244
|
+
export function fallbackIsHighlighted(fallback) {
|
|
245
|
+
return fallback.some(node => {
|
|
246
|
+
if (!isFrameFallbackNode(node)) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
// `children` is the last tuple slot, except the 5-element form keeps `extra` last
|
|
250
|
+
// (matches `nodeText`). An array means nested token spans, i.e. highlighted.
|
|
251
|
+
const children = node.length === 5 ? node[3] : node[node.length - 1];
|
|
252
|
+
return Array.isArray(children);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The **sparse** highlighted-visible fallback: a map from frame index to the
|
|
258
|
+
* highlighted `FallbackNode` for ONLY the frames visible on the initial collapsed
|
|
259
|
+
* render (`visibleFrames`). Off-screen frames are omitted — they flatten to exactly
|
|
260
|
+
* {@link buildRootFallback}'s plain output, so storing them would just duplicate
|
|
261
|
+
* `fallback` in the precompute. {@link promoteCriticalFallback} splices these back
|
|
262
|
+
* over the plain fallback for `highlightAt: 'init'` (paint highlighted on the first
|
|
263
|
+
* render, zero decompression). Frame indices count `span.frame` children only,
|
|
264
|
+
* matching `getInitialVisibleFrames`.
|
|
265
|
+
*
|
|
266
|
+
* The decoded `root` is shared/read-only; this only reads its frames (the synthetic
|
|
267
|
+
* visible frame reuses the frame's `children` array without mutating it, and
|
|
268
|
+
* `data-lined` is dropped via destructuring, not deletion).
|
|
269
|
+
*/
|
|
270
|
+
export function buildCriticalFallback(root, visibleFrames) {
|
|
271
|
+
const critical = {};
|
|
272
|
+
let frameIndex = 0;
|
|
273
|
+
for (const child of root.children) {
|
|
274
|
+
if (child.type === 'element' && isFrameSpan(child)) {
|
|
275
|
+
if (visibleFrames[frameIndex]) {
|
|
276
|
+
const frame = child;
|
|
277
|
+
const {
|
|
278
|
+
dataLined,
|
|
279
|
+
...properties
|
|
280
|
+
} = frame.properties || {};
|
|
281
|
+
const [node] = convertChildren([{
|
|
282
|
+
type: 'element',
|
|
283
|
+
tagName: 'span',
|
|
284
|
+
properties,
|
|
285
|
+
children: frame.children
|
|
286
|
+
}]);
|
|
287
|
+
critical[frameIndex] = node;
|
|
288
|
+
}
|
|
289
|
+
frameIndex += 1;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return critical;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Splice a sparse {@link buildCriticalFallback} diff back onto a plain `fallback`,
|
|
297
|
+
* replacing each visible frame (matched by index in document order) with its
|
|
298
|
+
* highlighted node. The result is the full highlighted-visible fallback; its text is
|
|
299
|
+
* byte-identical to `fallback` (the highlight spans only wrap the same characters), so
|
|
300
|
+
* it stays a valid DEFLATE dictionary — asserted by tests. Returns a new array; the
|
|
301
|
+
* input is not mutated.
|
|
302
|
+
*/
|
|
303
|
+
export function promoteCriticalFallback(fallback, critical) {
|
|
304
|
+
let frameIndex = 0;
|
|
305
|
+
return fallback.map(node => {
|
|
306
|
+
if (!isFrameFallbackNode(node)) {
|
|
307
|
+
return node;
|
|
308
|
+
}
|
|
309
|
+
const replacement = critical[frameIndex];
|
|
310
|
+
frameIndex += 1;
|
|
311
|
+
return replacement ?? node;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Redistributes a root fallback (built by `buildRootFallback`) back onto the
|
|
317
|
+
* frames of a decoded HAST root, setting each frame's `data.fallback` to the
|
|
318
|
+
* corresponding fallback frame's text nodes (as HAST, not the compact form).
|
|
319
|
+
*
|
|
320
|
+
* Frames align 1:1 by position because the root fallback and the decoded HAST
|
|
321
|
+
* are both derived from the same final tree. Non-frame fallback entries (e.g.
|
|
322
|
+
* inter-frame whitespace) advance the cursor without being assigned. Mutates
|
|
323
|
+
* `root` in place and returns it.
|
|
324
|
+
*/
|
|
325
|
+
export function redistributeRootFallback(root, fallback) {
|
|
326
|
+
let fallbackIndex = 0;
|
|
327
|
+
for (const child of root.children) {
|
|
328
|
+
// Advance past any non-frame fallback entries so frames stay aligned.
|
|
329
|
+
while (fallbackIndex < fallback.length && !isFallbackFrame(fallback[fallbackIndex])) {
|
|
330
|
+
fallbackIndex += 1;
|
|
331
|
+
}
|
|
332
|
+
if (child.type !== 'element' || !isFrameSpan(child)) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (fallbackIndex >= fallback.length) {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
const frameFallback = fallback[fallbackIndex];
|
|
339
|
+
fallbackIndex += 1;
|
|
340
|
+
const frame = child;
|
|
341
|
+
// The fallback frame's children are the frame's plain text.
|
|
342
|
+
const childValue = frameFallback.length === 5 ? frameFallback[3] : frameFallback[frameFallback.length - 1];
|
|
343
|
+
const nodes = typeof childValue === 'string' ? [{
|
|
344
|
+
type: 'text',
|
|
345
|
+
value: childValue
|
|
346
|
+
}] : childValue.map(node => ({
|
|
347
|
+
type: 'text',
|
|
348
|
+
value: nodeText(node)
|
|
349
|
+
}));
|
|
350
|
+
if (!frame.data) {
|
|
351
|
+
frame.data = {};
|
|
352
|
+
}
|
|
353
|
+
frame.data.fallback = nodes;
|
|
354
|
+
}
|
|
355
|
+
return root;
|
|
356
|
+
}
|
|
357
|
+
function isFallbackFrame(node) {
|
|
358
|
+
if (!Array.isArray(node) || node[0] !== 'span' || node.length < 3) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const classStr = node[1];
|
|
362
|
+
return typeof classStr === 'string' && (classStr === 'frame' || classStr.split(' ').includes('frame'));
|
|
363
|
+
}
|
|
364
|
+
function fallbackFrameType(frame) {
|
|
365
|
+
// Properties (carrying `dataFrameType`) live at index 2 of the 4- and
|
|
366
|
+
// 5-element tuple forms; the shorter forms have no properties.
|
|
367
|
+
if (frame.length >= 4) {
|
|
368
|
+
const frameType = frame[2]?.dataFrameType;
|
|
369
|
+
return typeof frameType === 'string' ? frameType : undefined;
|
|
370
|
+
}
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Reduce a root fallback to the frames visible while the code block is
|
|
376
|
+
* collapsed — the contiguous focused window (`padding-top`, `highlighted` /
|
|
377
|
+
* `focus`, `padding-bottom`). Inter-frame nodes inside that window are kept so
|
|
378
|
+
* the slice renders with the same spacing as the full fallback.
|
|
379
|
+
*
|
|
380
|
+
* Matches the runtime rule in `Pre.tsx`: when a block has no emphasis frames
|
|
381
|
+
* (the whole source is the focused window) the first frame stands in. Returns
|
|
382
|
+
* the input unchanged when it has no frames at all.
|
|
383
|
+
*
|
|
384
|
+
* When `collapsesToEmpty` is `true` the source records `focusedLines === 0`
|
|
385
|
+
* (the `oversizedFocus: 'hide'` collapse-to-nothing case): the collapsed window
|
|
386
|
+
* is intentionally empty, so the first-frame fallback is skipped and an empty
|
|
387
|
+
* array is returned. Mirrors the runtime rule in `Pre.tsx` /
|
|
388
|
+
* `getInitialVisibleSourceLines`.
|
|
389
|
+
*
|
|
390
|
+
* Used by `fallbackCollapsed` to paint only the on-screen lines while the
|
|
391
|
+
* file's full fallback rides along compressed (see the prop-compression
|
|
392
|
+
* pattern's "Splitting the Fallback by Visibility").
|
|
393
|
+
*/
|
|
394
|
+
export function collapsedVisibleFallback(fallback, collapsesToEmpty = false) {
|
|
395
|
+
if (collapsesToEmpty) {
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
let firstFrame = -1;
|
|
399
|
+
let firstVisible = -1;
|
|
400
|
+
let lastVisible = -1;
|
|
401
|
+
for (let index = 0; index < fallback.length; index += 1) {
|
|
402
|
+
const node = fallback[index];
|
|
403
|
+
if (!isFallbackFrame(node)) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (firstFrame === -1) {
|
|
407
|
+
firstFrame = index;
|
|
408
|
+
}
|
|
409
|
+
const frameType = fallbackFrameType(node);
|
|
410
|
+
if (frameType && COLLAPSED_VISIBLE_FRAME_TYPES.has(frameType)) {
|
|
411
|
+
if (firstVisible === -1) {
|
|
412
|
+
firstVisible = index;
|
|
413
|
+
}
|
|
414
|
+
lastVisible = index;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (firstVisible === -1) {
|
|
418
|
+
// No emphasis frames: the first frame is the collapsed window.
|
|
419
|
+
return firstFrame === -1 ? fallback : [fallback[firstFrame]];
|
|
420
|
+
}
|
|
421
|
+
return fallback.slice(firstVisible, lastVisible + 1);
|
|
422
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SourceComments } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Merges two `SourceComments` maps by concatenating entries per line.
|
|
4
|
+
*
|
|
5
|
+
* Both maps are keyed by line number. The function does not interpret
|
|
6
|
+
* keys — it only matches them by value — so 0-indexed and 1-indexed
|
|
7
|
+
* conventions are both supported, but **both inputs must use the same
|
|
8
|
+
* convention**. The repository's `SourceTransformer` contract supplies
|
|
9
|
+
* 1-indexed line numbers; if you build `mine` by hand, match the
|
|
10
|
+
* upstream indexing of `input` or your markers will land on the wrong
|
|
11
|
+
* lines.
|
|
12
|
+
*
|
|
13
|
+
* In non-production builds a heuristic dev warning is emitted when the
|
|
14
|
+
* two inputs look like they disagree about indexing (one contains a
|
|
15
|
+
* `0` key and the other does not). The check has no runtime cost in
|
|
16
|
+
* production builds.
|
|
17
|
+
*
|
|
18
|
+
* For any line present in either map, the resulting entry is
|
|
19
|
+
* `[...input[line] ?? [], ...mine[line] ?? []]` — `input` markers come
|
|
20
|
+
* first, the transformer's own markers (`mine`) are appended.
|
|
21
|
+
*
|
|
22
|
+
* Returns `undefined` when the merge would produce no entries (both
|
|
23
|
+
* inputs absent, both empty, or every per-line array empty). Otherwise
|
|
24
|
+
* returns a fresh object whose per-line arrays are also fresh copies,
|
|
25
|
+
* so callers may safely mutate the result without affecting either
|
|
26
|
+
* input.
|
|
27
|
+
*
|
|
28
|
+
* Intended to be called by `SourceTransformer` implementations that
|
|
29
|
+
* receive an upstream `comments` map as their 3rd argument and want to
|
|
30
|
+
* preserve those entries alongside the markers they themselves emit.
|
|
31
|
+
*
|
|
32
|
+
* @param input - Comments map received by the transformer (may be
|
|
33
|
+
* `undefined` when no upstream comments exist).
|
|
34
|
+
* @param mine - Comments map the transformer wants to emit (may be
|
|
35
|
+
* `undefined` when the transformer has none of its own). Must use
|
|
36
|
+
* the same line-indexing convention as `input`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function mergeComments(input: SourceComments | undefined, mine: SourceComments | undefined): SourceComments | undefined;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges two `SourceComments` maps by concatenating entries per line.
|
|
3
|
+
*
|
|
4
|
+
* Both maps are keyed by line number. The function does not interpret
|
|
5
|
+
* keys — it only matches them by value — so 0-indexed and 1-indexed
|
|
6
|
+
* conventions are both supported, but **both inputs must use the same
|
|
7
|
+
* convention**. The repository's `SourceTransformer` contract supplies
|
|
8
|
+
* 1-indexed line numbers; if you build `mine` by hand, match the
|
|
9
|
+
* upstream indexing of `input` or your markers will land on the wrong
|
|
10
|
+
* lines.
|
|
11
|
+
*
|
|
12
|
+
* In non-production builds a heuristic dev warning is emitted when the
|
|
13
|
+
* two inputs look like they disagree about indexing (one contains a
|
|
14
|
+
* `0` key and the other does not). The check has no runtime cost in
|
|
15
|
+
* production builds.
|
|
16
|
+
*
|
|
17
|
+
* For any line present in either map, the resulting entry is
|
|
18
|
+
* `[...input[line] ?? [], ...mine[line] ?? []]` — `input` markers come
|
|
19
|
+
* first, the transformer's own markers (`mine`) are appended.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` when the merge would produce no entries (both
|
|
22
|
+
* inputs absent, both empty, or every per-line array empty). Otherwise
|
|
23
|
+
* returns a fresh object whose per-line arrays are also fresh copies,
|
|
24
|
+
* so callers may safely mutate the result without affecting either
|
|
25
|
+
* input.
|
|
26
|
+
*
|
|
27
|
+
* Intended to be called by `SourceTransformer` implementations that
|
|
28
|
+
* receive an upstream `comments` map as their 3rd argument and want to
|
|
29
|
+
* preserve those entries alongside the markers they themselves emit.
|
|
30
|
+
*
|
|
31
|
+
* @param input - Comments map received by the transformer (may be
|
|
32
|
+
* `undefined` when no upstream comments exist).
|
|
33
|
+
* @param mine - Comments map the transformer wants to emit (may be
|
|
34
|
+
* `undefined` when the transformer has none of its own). Must use
|
|
35
|
+
* the same line-indexing convention as `input`.
|
|
36
|
+
*/
|
|
37
|
+
export function mergeComments(input, mine) {
|
|
38
|
+
if (!input && !mine) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (process.env.NODE_ENV !== 'production' && input && mine && Object.keys(input).length > 0 && Object.keys(mine).length > 0) {
|
|
42
|
+
warnOnIndexingMismatch(input, mine);
|
|
43
|
+
}
|
|
44
|
+
const result = {};
|
|
45
|
+
const lines = new Set();
|
|
46
|
+
if (input) {
|
|
47
|
+
for (const key of Object.keys(input)) {
|
|
48
|
+
lines.add(Number(key));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (mine) {
|
|
52
|
+
for (const key of Object.keys(mine)) {
|
|
53
|
+
lines.add(Number(key));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let hasAny = false;
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const merged = [...(input?.[line] ?? []), ...(mine?.[line] ?? [])];
|
|
59
|
+
if (merged.length > 0) {
|
|
60
|
+
result[line] = merged;
|
|
61
|
+
hasAny = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return hasAny ? result : undefined;
|
|
65
|
+
}
|
|
66
|
+
function warnOnIndexingMismatch(input, mine) {
|
|
67
|
+
const inputHasZero = Object.prototype.hasOwnProperty.call(input, 0);
|
|
68
|
+
const mineHasZero = Object.prototype.hasOwnProperty.call(mine, 0);
|
|
69
|
+
if (inputHasZero === mineHasZero) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Only warn when the side without a `0` key has at least one entry
|
|
74
|
+
// — otherwise we can't tell whether it would have included one.
|
|
75
|
+
const other = inputHasZero ? mine : input;
|
|
76
|
+
if (Object.keys(other).length === 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
console.warn('mergeComments: inputs appear to use different line-indexing conventions ' + '(one contains a `0` key, the other does not). Comments are 1-indexed everywhere ' + '(a `0` key means something emitted 0-indexed comments); both inputs must be ' + '1-indexed or markers will land on the wrong lines.');
|
|
80
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Code, CodeHighlighterBaseProps, ContentLoadingProps, VariantExtraFiles, VariantSource } from "./types.mjs";
|
|
3
|
+
import type { CompressedFallback } from "./fallbackFormat.mjs";
|
|
4
|
+
export interface PrepareInitialSourceOptions<T extends {}> extends CodeHighlighterBaseProps<T> {
|
|
5
|
+
code: Code;
|
|
6
|
+
initialVariant: string;
|
|
7
|
+
initialFilename: string | undefined;
|
|
8
|
+
initialSource: VariantSource;
|
|
9
|
+
initialExtraFiles?: VariantExtraFiles;
|
|
10
|
+
ContentLoading: React.ComponentType<ContentLoadingProps<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to DEFLATE-compress the consolidated residual fallbacks. This only
|
|
13
|
+
* shrinks the server→client serialized payload, so it pays off only when the
|
|
14
|
+
* result actually crosses that wire (a server render). On the client there is no
|
|
15
|
+
* wire — compressing here just to have `CodeHighlighterClient` decompress it right
|
|
16
|
+
* back is a wasted round-trip — so the isomorphic `CodeHighlighter` entry passes
|
|
17
|
+
* `typeof window === 'undefined'`. Defaults to `true` for the server-only loaders
|
|
18
|
+
* (and tests) that always produce wire output; when `false`, the fallbacks stay
|
|
19
|
+
* inline on `codeForClient`.
|
|
20
|
+
*/
|
|
21
|
+
compressResidual?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface PreparedInitialSource {
|
|
24
|
+
/** The pre-rendered loading fallback (`<ContentLoading />`). */
|
|
25
|
+
fallback: React.ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* The variant/file fallbacks the loading UI won't render, consolidated into a
|
|
28
|
+
* single DEFLATE blob. Absent when there is nothing worth compressing.
|
|
29
|
+
*/
|
|
30
|
+
residualFallbacks?: CompressedFallback;
|
|
31
|
+
/** The `Code` to send to the client (fallbacks stripped/wired out when compressed). */
|
|
32
|
+
codeForClient: Code;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Prepare the loading fallback and the wire `Code` from the initial source. Hoists
|
|
36
|
+
* the rendered subset onto `ContentLoading` props, strips those fallback HASTs off
|
|
37
|
+
* `Code`, and consolidates the rest into a compressed `residualFallbacks` blob the
|
|
38
|
+
* client decodes against the rendered text. The render *decision* (client vs server
|
|
39
|
+
* load, stream vs await) is the chunk's job; this is just the shared preparation
|
|
40
|
+
* used by the content path and the server loaders.
|
|
41
|
+
*/
|
|
42
|
+
export declare function prepareInitialSource<T extends {}>(props: PrepareInitialSourceOptions<T>): PreparedInitialSource;
|