@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,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a `{@link symbol}` reference into markdown.
|
|
3
|
+
*
|
|
4
|
+
* A link is emitted only when `symbol` is documented on the current page (so a
|
|
5
|
+
* heading with a matching anchor exists). Otherwise the reference renders as a
|
|
6
|
+
* plain code span - this keeps references to internal helpers, or to symbols
|
|
7
|
+
* that live on another page, from producing dangling `#anchor` links that fail
|
|
8
|
+
* the docs link checker.
|
|
9
|
+
*
|
|
10
|
+
* When `documentedNames` is omitted every reference is linked (legacy behavior,
|
|
11
|
+
* used only when no documented-name set is threaded through).
|
|
12
|
+
*/
|
|
13
|
+
function renderJSDocLink(symbol, documentedNames) {
|
|
14
|
+
if (!documentedNames || documentedNames.has(symbol)) {
|
|
15
|
+
return `[\`${symbol}\`](#${symbol.toLowerCase()})`;
|
|
16
|
+
}
|
|
17
|
+
return `\`${symbol}\``;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Extracts text content from a JSDoc description array.
|
|
22
|
+
*
|
|
23
|
+
* typescript-api-extractor returns a description as an array of JSDoc nodes when
|
|
24
|
+
* the comment contains `{@link}` tags: plain-text nodes carry a `text` property,
|
|
25
|
+
* while link nodes carry the referenced symbol in `name.escapedText`. Link nodes
|
|
26
|
+
* are turned into markdown via {@link renderJSDocLink}, gated on `documentedNames`.
|
|
27
|
+
*/
|
|
28
|
+
export function extractJSDocText(nodes, documentedNames) {
|
|
29
|
+
return nodes.map(node => {
|
|
30
|
+
if (typeof node === 'object' && node !== null) {
|
|
31
|
+
// Regular text nodes have a 'text' property with content
|
|
32
|
+
if ('text' in node) {
|
|
33
|
+
const text = node.text;
|
|
34
|
+
if (typeof text === 'string' && text) {
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// JSDocLink nodes (kind 325) have the symbol name in name.escapedText
|
|
39
|
+
if ('name' in node) {
|
|
40
|
+
const name = node.name;
|
|
41
|
+
if (name && typeof name.escapedText === 'string') {
|
|
42
|
+
return renderJSDocLink(name.escapedText, documentedNames);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return '';
|
|
47
|
+
}).join('');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks if an array looks like JSDoc description nodes from typescript-api-extractor.
|
|
52
|
+
* These have properties like 'pos', 'end', 'kind', 'text' from the TypeScript AST.
|
|
53
|
+
*/
|
|
54
|
+
export function isJSDocNodeArray(value) {
|
|
55
|
+
if (value.length === 0) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const first = value[0];
|
|
59
|
+
return typeof first === 'object' && first !== null && 'pos' in first && 'end' in first && 'kind' in first;
|
|
60
|
+
}
|
|
@@ -3,55 +3,18 @@ import { fileURLToPath } from 'url';
|
|
|
3
3
|
import { parseFromProgram } from 'typescript-api-extractor';
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { createOptimizedProgram } from "./createOptimizedProgram.mjs";
|
|
6
|
+
import { extractJSDocText, isJSDocNodeArray } from "./extractJSDocText.mjs";
|
|
6
7
|
import { PerformanceTracker } from "./performanceTracking.mjs";
|
|
7
8
|
import { nameMark } from "../loadPrecomputedCodeHighlighter/performanceLogger.mjs";
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
-
* Extracts text content from a JSDoc description array.
|
|
11
|
-
* typescript-api-extractor returns description as an array of JSDoc nodes
|
|
12
|
-
* when the comment contains @link tags.
|
|
13
|
-
*/
|
|
14
|
-
function extractJSDocText(nodes) {
|
|
15
|
-
return nodes.map(node => {
|
|
16
|
-
if (typeof node === 'object' && node !== null) {
|
|
17
|
-
// Regular text nodes have a 'text' property with content
|
|
18
|
-
if ('text' in node) {
|
|
19
|
-
const text = node.text;
|
|
20
|
-
if (typeof text === 'string' && text) {
|
|
21
|
-
return text;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// JSDocLink nodes (kind 325) have the symbol name in name.escapedText
|
|
25
|
-
// Convert {@link symbolName} to [`symbolName`](#symbolName) markdown link
|
|
26
|
-
if ('name' in node) {
|
|
27
|
-
const name = node.name;
|
|
28
|
-
if (name && typeof name.escapedText === 'string') {
|
|
29
|
-
return `[\`${name.escapedText}\`](#${name.escapedText.toLowerCase()})`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return '';
|
|
34
|
-
}).join('');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Checks if an array looks like JSDoc description nodes from typescript-api-extractor.
|
|
39
|
-
* These have properties like 'pos', 'end', 'kind', 'text' from the TypeScript AST.
|
|
40
|
-
*/
|
|
41
|
-
function isJSDocNodeArray(value) {
|
|
42
|
-
if (value.length === 0) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const first = value[0];
|
|
46
|
-
return typeof first === 'object' && first !== null && 'pos' in first && 'end' in first && 'kind' in first;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
10
|
/**
|
|
50
11
|
* Strips functions from objects so they can cross the worker boundary.
|
|
51
12
|
* Structured clone can't handle functions but handles everything else fine.
|
|
52
|
-
* Also normalizes typescript-api-extractor JSDoc description arrays to strings
|
|
13
|
+
* Also normalizes typescript-api-extractor JSDoc description arrays to strings,
|
|
14
|
+
* resolving `{@link}` references against `documentedNames` so only symbols with
|
|
15
|
+
* a heading on the page become anchor links.
|
|
53
16
|
*/
|
|
54
|
-
function stripFunctions(value, visited = new WeakMap()) {
|
|
17
|
+
function stripFunctions(value, documentedNames, visited = new WeakMap()) {
|
|
55
18
|
// Primitives, null, undefined - return as-is
|
|
56
19
|
if (value === null || value === undefined || typeof value !== 'object') {
|
|
57
20
|
return value;
|
|
@@ -66,13 +29,13 @@ function stripFunctions(value, visited = new WeakMap()) {
|
|
|
66
29
|
if (Array.isArray(value)) {
|
|
67
30
|
// Normalize JSDoc description arrays to strings
|
|
68
31
|
if (isJSDocNodeArray(value)) {
|
|
69
|
-
return extractJSDocText(value);
|
|
32
|
+
return extractJSDocText(value, documentedNames);
|
|
70
33
|
}
|
|
71
34
|
const result = [];
|
|
72
35
|
visited.set(value, result);
|
|
73
36
|
for (const item of value) {
|
|
74
37
|
if (typeof item !== 'function') {
|
|
75
|
-
result.push(stripFunctions(item, visited));
|
|
38
|
+
result.push(stripFunctions(item, documentedNames, visited));
|
|
76
39
|
}
|
|
77
40
|
}
|
|
78
41
|
return result;
|
|
@@ -84,12 +47,45 @@ function stripFunctions(value, visited = new WeakMap()) {
|
|
|
84
47
|
for (const key of Object.keys(value)) {
|
|
85
48
|
const propValue = value[key];
|
|
86
49
|
if (typeof propValue !== 'function') {
|
|
87
|
-
result[key] = stripFunctions(propValue, visited);
|
|
50
|
+
result[key] = stripFunctions(propValue, documentedNames, visited);
|
|
88
51
|
}
|
|
89
52
|
}
|
|
90
53
|
return result;
|
|
91
54
|
}
|
|
92
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Collects every symbol name documented on this page - all exports and resolved
|
|
58
|
+
* types across all variants. `{@link}` references are linked only when they hit
|
|
59
|
+
* this set, since those are the names that get a heading (and thus an anchor).
|
|
60
|
+
*/
|
|
61
|
+
function collectDocumentedNames(variantData) {
|
|
62
|
+
const names = new Set();
|
|
63
|
+
const addName = name => {
|
|
64
|
+
if (!name) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
names.add(name);
|
|
68
|
+
// Namespaced exports (e.g. "Menu.Root") are also referenced by their flat
|
|
69
|
+
// ("MenuRoot") and leaf ("Root") forms in {@link} comments.
|
|
70
|
+
if (name.includes('.')) {
|
|
71
|
+
names.add(name.replaceAll('.', ''));
|
|
72
|
+
names.add(name.slice(name.lastIndexOf('.') + 1));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
for (const variant of Object.values(variantData)) {
|
|
76
|
+
for (const node of variant.allTypes) {
|
|
77
|
+
addName(node.name);
|
|
78
|
+
}
|
|
79
|
+
if (variant.typeNameMap) {
|
|
80
|
+
for (const [flatName, dottedName] of Object.entries(variant.typeNameMap)) {
|
|
81
|
+
addName(flatName);
|
|
82
|
+
addName(dottedName);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return names;
|
|
87
|
+
}
|
|
88
|
+
|
|
93
89
|
/**
|
|
94
90
|
* Recursively collects all source file dependencies of a given source file.
|
|
95
91
|
* This walks the import graph starting from the given file and collects all
|
|
@@ -391,7 +387,8 @@ export async function processTypes(request) {
|
|
|
391
387
|
}
|
|
392
388
|
|
|
393
389
|
// Strip functions so data can cross worker boundary (structured clone can't handle functions)
|
|
394
|
-
const
|
|
390
|
+
const documentedNames = collectDocumentedNames(variantData);
|
|
391
|
+
const serializedVariantData = stripFunctions(variantData, documentedNames);
|
|
395
392
|
return {
|
|
396
393
|
success: true,
|
|
397
394
|
variantData: serializedVariantData,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
export const cssVariables = [];
|
|
10
10
|
export const dataAttributes = ['data-checked', 'data-unchecked', 'data-open', 'data-closed', 'data-panel-open', 'data-popup-open', 'data-popup-side', 'data-list-empty', 'data-pressed', 'data-selected', 'data-highlighted', 'data-dragging', 'data-orientation', 'data-disabled', 'data-readonly', 'data-required', 'data-valid', 'data-invalid', 'data-dirty', 'data-touched', 'data-uncentered', 'data-anchor-hidden', '__EVERYTHING_ELSE__', 'data-starting-style', 'data-ending-style'];
|
|
11
|
-
export const props = ['aria-label', 'aria-labelledby', 'name', 'label', 'defaultChecked', 'checked', 'onCheckedChange', 'indeterminate', 'defaultValue', 'value', 'onValueChange', 'onValueCommitted', 'allValues', 'defaultInputValue', 'inputValue', 'onInputValueChange', 'defaultOpen', 'open', 'onOpenChange', 'defaultPressed', 'pressed', 'onPressedChange', 'onPressedCommitted', 'snapPoints', 'defaultSnapPoint', 'snapPoint', 'onSnapPointChange', 'onClick', 'closeOnClick', 'errors', 'hidden', 'hiddenUntilFound', 'autoHighlight', 'keepHighlight', 'highlightItemOnHover', '__EVERYTHING_ELSE__', 'step', 'smallStep', 'largeStep', 'minStepsBetweenValues', 'min', 'max', 'allowWheelScrub', 'format', 'autoFocus', 'container', 'align', 'alignOffset', 'side', 'sideOffset', 'arrowPadding', 'anchor', 'collisionAvoidance', 'collisionBoundary', 'collisionPadding', 'sticky', 'positionMethod', 'trackAnchor', 'trackCursorAxis', 'initialFocus', 'finalFocus', 'match', 'forceShow', 'disabled', 'readOnly', 'required', 'valid', 'invalid', 'openOnHover', 'delay', 'closeDelay', 'timeout', 'disableHoverablePopup', 'loop', 'orientation', 'inputRef', 'validate', 'validationMode', 'validationDebounceTime', 'id', 'children', 'className', 'style', 'keepMounted', 'render'];
|
|
11
|
+
export const props = ['aria-label', 'aria-labelledby', 'name', 'label', 'defaultChecked', 'checked', 'onCheckedChange', 'indeterminate', 'defaultValue', 'value', 'onValueChange', 'onValueCommitted', 'allValues', 'defaultInputValue', 'inputValue', 'onInputValueChange', 'defaultOpen', 'open', 'onOpenChange', 'collapseToEmpty', 'showCollapsedFocus', 'initialExpanded', 'initialCollapsed', 'defaultPressed', 'pressed', 'onPressedChange', 'onPressedCommitted', 'snapPoints', 'defaultSnapPoint', 'snapPoint', 'onSnapPointChange', 'onClick', 'closeOnClick', 'errors', 'hidden', 'hiddenUntilFound', 'autoHighlight', 'keepHighlight', 'highlightItemOnHover', '__EVERYTHING_ELSE__', 'step', 'smallStep', 'largeStep', 'minStepsBetweenValues', 'min', 'max', 'allowWheelScrub', 'format', 'autoFocus', 'container', 'align', 'alignOffset', 'side', 'sideOffset', 'arrowPadding', 'anchor', 'collisionAvoidance', 'collisionBoundary', 'collisionPadding', 'sticky', 'positionMethod', 'trackAnchor', 'trackCursorAxis', 'initialFocus', 'finalFocus', 'match', 'forceShow', 'disabled', 'readOnly', 'required', 'valid', 'invalid', 'openOnHover', 'delay', 'closeDelay', 'timeout', 'disableHoverablePopup', 'loop', 'orientation', 'inputRef', 'validate', 'validationMode', 'validationDebounceTime', 'id', 'children', 'className', 'style', 'keepMounted', 'render'];
|
|
12
12
|
|
|
13
13
|
// Namespace member parts order (for sorting ComponentName.Part members)
|
|
14
14
|
// These define the order of parts within a component's namespace
|
|
@@ -13,9 +13,11 @@ import { organizeTypesByExport } from "./organizeTypesByExport.mjs";
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Decode HTML entities commonly found in markdown.
|
|
16
|
+
* `&` is unescaped LAST to avoid double-unescaping inputs like `<`,
|
|
17
|
+
* which should decode to `<` rather than `<`.
|
|
16
18
|
*/
|
|
17
19
|
function decodeHtmlEntities(text) {
|
|
18
|
-
return text.replace(/"/g, '"').replace(/&
|
|
20
|
+
return text.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, "'").replace(/'/g, "'").replace(/&/g, '&').replace(/“/g, '"') // Left double quote
|
|
19
21
|
.replace(/”/g, '"'); // Right double quote
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -58,7 +58,11 @@ export interface ImportsAndComments {
|
|
|
58
58
|
externals: Record<string, ExternalImport>;
|
|
59
59
|
/** The processed code with comments removed (if comment processing was requested) */
|
|
60
60
|
code?: string;
|
|
61
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Map of 1-indexed output line numbers (in `code`, after comment removal) to arrays of
|
|
63
|
+
* comment content (if comment processing was requested). 1-indexed is the canonical
|
|
64
|
+
* `Code` convention, matching the HAST `dataLn` gutter the enhancers read.
|
|
65
|
+
*/
|
|
62
66
|
comments?: Record<number, string[]>;
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
@@ -304,10 +304,14 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
304
304
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
305
305
|
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
306
306
|
if (shouldCollect) {
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
// Record the comment 1-indexed: `Code` comments are always 1-indexed (the
|
|
308
|
+
// convention the enhancers match against the `dataLn` line gutter). `outputLine`
|
|
309
|
+
// is tracked 0-indexed internally, so add one at the point of storage.
|
|
310
|
+
const commentLine = commentStartOutputLine + 1;
|
|
311
|
+
if (!comments[commentLine]) {
|
|
312
|
+
comments[commentLine] = [];
|
|
309
313
|
}
|
|
310
|
-
comments[
|
|
314
|
+
comments[commentLine].push(...stripCommentMarkers(commentText));
|
|
311
315
|
}
|
|
312
316
|
if (shouldStrip) {
|
|
313
317
|
anyCommentStripped = true;
|
|
@@ -350,10 +354,14 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
350
354
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
351
355
|
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
352
356
|
if (shouldCollect) {
|
|
353
|
-
|
|
354
|
-
|
|
357
|
+
// Record the comment 1-indexed: `Code` comments are always 1-indexed (the
|
|
358
|
+
// convention the enhancers match against the `dataLn` line gutter). `outputLine`
|
|
359
|
+
// is tracked 0-indexed internally, so add one at the point of storage.
|
|
360
|
+
const commentLine = commentStartOutputLine + 1;
|
|
361
|
+
if (!comments[commentLine]) {
|
|
362
|
+
comments[commentLine] = [];
|
|
355
363
|
}
|
|
356
|
-
comments[
|
|
364
|
+
comments[commentLine].push(...stripCommentMarkers(commentText));
|
|
357
365
|
}
|
|
358
366
|
if (shouldStrip) {
|
|
359
367
|
anyCommentStripped = true;
|
|
@@ -526,10 +534,12 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
526
534
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
527
535
|
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
528
536
|
if (shouldCollect) {
|
|
529
|
-
|
|
530
|
-
|
|
537
|
+
// Record 1-indexed (the `Code` convention); see the other recording sites above.
|
|
538
|
+
const commentLine = commentStartOutputLine + 1;
|
|
539
|
+
if (!comments[commentLine]) {
|
|
540
|
+
comments[commentLine] = [];
|
|
531
541
|
}
|
|
532
|
-
comments[
|
|
542
|
+
comments[commentLine].push(...stripCommentMarkers(commentText));
|
|
533
543
|
}
|
|
534
544
|
if (shouldStrip) {
|
|
535
545
|
anyCommentStripped = true;
|
|
@@ -44,7 +44,26 @@ export const VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.
|
|
|
44
44
|
/**
|
|
45
45
|
* Static asset extensions that should NOT be resolved as JS modules
|
|
46
46
|
*/
|
|
47
|
-
const STATIC_ASSET_EXTENSIONS = ['.css', '.scss', '.
|
|
47
|
+
const STATIC_ASSET_EXTENSIONS = ['.css', '.scss', '.json', '.svg', '.png', '.jpg', '.jpeg', '.gif', '.webp', '.woff2'];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Asset extensions that are intentionally unsupported.
|
|
51
|
+
* Importing one of these throws so the issue surfaces at build time.
|
|
52
|
+
*/
|
|
53
|
+
const UNSUPPORTED_ASSET_EXTENSIONS = ['.sass',
|
|
54
|
+
// use '.scss' instead
|
|
55
|
+
'.less',
|
|
56
|
+
// legacy
|
|
57
|
+
'.ico',
|
|
58
|
+
// legacy
|
|
59
|
+
'.woff',
|
|
60
|
+
// legacy, use '.woff2' (https://web.dev/articles/font-best-practices#use_woff2)
|
|
61
|
+
'.eot',
|
|
62
|
+
// legacy
|
|
63
|
+
'.ttf',
|
|
64
|
+
// desktop font format
|
|
65
|
+
'.otf' // desktop font format
|
|
66
|
+
];
|
|
48
67
|
|
|
49
68
|
/**
|
|
50
69
|
* Checks if a file path or import path represents a static asset
|
|
@@ -601,6 +620,9 @@ export async function resolveImportResult(importResult, readDirectory, options =
|
|
|
601
620
|
url,
|
|
602
621
|
includeTypeDefs
|
|
603
622
|
}] of Object.entries(importResult)) {
|
|
623
|
+
if (UNSUPPORTED_ASSET_EXTENSIONS.some(ext => importPath.endsWith(ext))) {
|
|
624
|
+
throw new Error(`Unsupported import extension: "${importPath}".`);
|
|
625
|
+
}
|
|
604
626
|
if (isStaticAsset(importPath)) {
|
|
605
627
|
// Static asset - use url as-is
|
|
606
628
|
staticAssets.push(url);
|
|
@@ -5,7 +5,19 @@ import type { Externals } from "../../CodeHighlighter/types.mjs";
|
|
|
5
5
|
* Parse options for create* factory call parsing
|
|
6
6
|
*/
|
|
7
7
|
export interface ParseOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Only extract metadata (url + options), skipping variant-import resolution.
|
|
10
|
+
* Treats the call as `create*(url, options?)`. Implies {@link ParseOptions.noVariants}.
|
|
11
|
+
*/
|
|
8
12
|
metadataOnly?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The factory has no variants argument: its call shape is `create*(url, options?)`
|
|
15
|
+
* (e.g. `createStream`), so the argument after `url` is the options
|
|
16
|
+
* object rather than variants. Use this (with `replacePrecomputeValue`) to build
|
|
17
|
+
* a precompute loader for a no-variants factory. Unlike `metadataOnly`, variant
|
|
18
|
+
* resolution is simply not applicable rather than intentionally skipped.
|
|
19
|
+
*/
|
|
20
|
+
noVariants?: boolean;
|
|
9
21
|
allowExternalVariants?: boolean;
|
|
10
22
|
allowMultipleFactories?: boolean;
|
|
11
23
|
}
|
|
@@ -603,21 +603,23 @@ async function processCreateFactoryMatch(match, code, filePath, parseOptions, im
|
|
|
603
603
|
// Validate URL argument
|
|
604
604
|
validateUrlArgument(urlArg, functionName, filePath);
|
|
605
605
|
|
|
606
|
-
// Validate variants argument (skip
|
|
606
|
+
// Validate variants argument (skip when there is no variants argument)
|
|
607
607
|
const {
|
|
608
|
-
metadataOnly = false
|
|
608
|
+
metadataOnly = false,
|
|
609
|
+
noVariants = false
|
|
609
610
|
} = parseOptions;
|
|
610
|
-
|
|
611
|
+
const skipVariants = metadataOnly || noVariants;
|
|
612
|
+
if (!skipVariants && structuredVariants !== undefined) {
|
|
611
613
|
validateVariantsArgument(structuredVariants, functionName, filePath);
|
|
612
614
|
}
|
|
613
615
|
|
|
614
616
|
// Extract URL (typically import.meta.url)
|
|
615
617
|
const url = urlArg.trim();
|
|
616
618
|
|
|
617
|
-
// Resolve variants using structured data (skip
|
|
619
|
+
// Resolve variants using structured data (skip when there is no variants argument)
|
|
618
620
|
let variants;
|
|
619
621
|
let namedExports;
|
|
620
|
-
if (!
|
|
622
|
+
if (!skipVariants) {
|
|
621
623
|
if (structuredVariants !== undefined) {
|
|
622
624
|
// Use regular variants argument
|
|
623
625
|
const variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
|
|
@@ -786,12 +788,14 @@ function findFirstCreateFactoryCall(code, filePath, parseOptions = {}, startInde
|
|
|
786
788
|
|
|
787
789
|
// Validate the function follows the convention
|
|
788
790
|
const {
|
|
789
|
-
metadataOnly = false
|
|
791
|
+
metadataOnly = false,
|
|
792
|
+
noVariants = false
|
|
790
793
|
} = parseOptions;
|
|
791
|
-
|
|
792
|
-
|
|
794
|
+
const skipVariants = metadataOnly || noVariants;
|
|
795
|
+
if (skipVariants) {
|
|
796
|
+
// No variants argument: expect 1-2 arguments (url, options?)
|
|
793
797
|
if (structured.length < 1 || structured.length > 2) {
|
|
794
|
-
throw new Error(`Invalid ${functionName} call in ${filePath}. ` + `Expected 1-2 arguments (url, options?) but got ${structured.length} arguments. ` + `
|
|
798
|
+
throw new Error(`Invalid ${functionName} call in ${filePath}. ` + `Expected 1-2 arguments (url, options?) but got ${structured.length} arguments. ` + `For a no-variants factory, calls should follow: create*(url, options?)`);
|
|
795
799
|
}
|
|
796
800
|
} else if (hasGenerics && structured.length <= 2) {
|
|
797
801
|
// When generics are present AND we have 1-2 arguments, expect (url, options?)
|
|
@@ -804,8 +808,8 @@ function findFirstCreateFactoryCall(code, filePath, parseOptions = {}, startInde
|
|
|
804
808
|
}
|
|
805
809
|
|
|
806
810
|
// Handle different argument patterns based on mode
|
|
807
|
-
if (
|
|
808
|
-
//
|
|
811
|
+
if (skipVariants) {
|
|
812
|
+
// No variants argument: expect 1-2 arguments (url, options?)
|
|
809
813
|
if (structured.length === 1) {
|
|
810
814
|
const [urlArg] = structured;
|
|
811
815
|
return {
|
|
@@ -847,7 +851,7 @@ function findFirstCreateFactoryCall(code, filePath, parseOptions = {}, startInde
|
|
|
847
851
|
argumentsEndIndex: endIndex
|
|
848
852
|
};
|
|
849
853
|
}
|
|
850
|
-
} else if (!
|
|
854
|
+
} else if (!skipVariants && hasGenerics && structured.length === 1) {
|
|
851
855
|
// Generics-only mode (non-metadata): expect 1 argument (url) - use generics as variants
|
|
852
856
|
const [urlArg] = structured;
|
|
853
857
|
return {
|
|
@@ -865,7 +869,7 @@ function findFirstCreateFactoryCall(code, filePath, parseOptions = {}, startInde
|
|
|
865
869
|
argumentsStartIndex: parenIndex + 1,
|
|
866
870
|
argumentsEndIndex: endIndex
|
|
867
871
|
};
|
|
868
|
-
} else if (!
|
|
872
|
+
} else if (!skipVariants && structured.length >= 2) {
|
|
869
873
|
// Normal mode: expect 2-3 arguments (url, variants, options?)
|
|
870
874
|
if (structured.length === 2) {
|
|
871
875
|
const [urlArg, secondArg] = structured;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Example copied from https://github.com/wooorm/starry-night#example-adding-line-numbers
|
|
2
2
|
|
|
3
3
|
import { createFrame } from "./createFrame.mjs";
|
|
4
|
+
import { isFrameSpan } from "./isFrameSpan.mjs";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Counts the number of lines in a HAST tree without mutating it.
|
|
@@ -127,26 +128,59 @@ export function starryNightGutter(tree, sourceLines, frameSize = 120) {
|
|
|
127
128
|
replacement.push(createFrame(frameLines));
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
131
|
+
// When `sourceLines` is provided, attach a precomputed `fallback` hast to
|
|
132
|
+
// every frame (including single-frame output).
|
|
133
|
+
//
|
|
134
|
+
// `frame.data.fallback` is a basic hast node array (single `{ type: 'text' }`
|
|
135
|
+
// node) carrying the same text the highlighted hast would render. It is set
|
|
136
|
+
// here, before the enhancer pipeline runs, so enhancers can read and keep it
|
|
137
|
+
// in sync. Enhancers only modify spans (never the plain-text output), so a
|
|
138
|
+
// frame's fallback stays valid unless the frame is restructured — in which
|
|
139
|
+
// case `restructureFrames` shifts the corresponding lines between frames.
|
|
140
|
+
//
|
|
141
|
+
// Downstream, these per-frame fallbacks are collected into the variant-level
|
|
142
|
+
// root fallback and also let the renderer skip running
|
|
143
|
+
// `stripHighlightingSpans` per frame at render time. Every frame except the
|
|
144
|
+
// last covers `frameSize` source lines, each of which was followed by a
|
|
145
|
+
// newline separator in the original source, so its text ends with a trailing
|
|
146
|
+
// '\n'. The final frame only carries a trailing newline if the source itself
|
|
147
|
+
// ends with one. Without this trailing '\n', the plain-text fallback and the
|
|
148
|
+
// highlighted render disagree by exactly one newline per non-final frame,
|
|
149
|
+
// which causes a layout shift during lazy hydration when a frame toggles
|
|
150
|
+
// between the two.
|
|
151
|
+
if (sourceLines) {
|
|
139
152
|
const lastIndex = replacement.length - 1;
|
|
140
153
|
for (let frameIndex = 0; frameIndex < replacement.length; frameIndex += 1) {
|
|
141
154
|
const frame = replacement[frameIndex];
|
|
142
|
-
if (frame.type === 'element' && frame.tagName === 'span' && frame
|
|
155
|
+
if (frame.type === 'element' && frame.tagName === 'span' && isFrameSpan(frame)) {
|
|
143
156
|
// Extract line range from child .line elements
|
|
144
157
|
const lineChildren = frame.children.filter(c => c.type === 'element' && c.properties?.className === 'line' && typeof c.properties.dataLn === 'number');
|
|
145
158
|
if (lineChildren.length > 0) {
|
|
146
159
|
const startLine = Number(lineChildren[0].properties.dataLn) - 1;
|
|
147
160
|
const endLine = Number(lineChildren[lineChildren.length - 1].properties.dataLn);
|
|
148
161
|
const joined = sourceLines.slice(startLine, endLine).join('\n');
|
|
149
|
-
|
|
162
|
+
// Non-final frames are always followed by more content, so their text
|
|
163
|
+
// ends with the line separator. The final frame's text ends with a
|
|
164
|
+
// newline only when the source itself does — mirroring the highlighted
|
|
165
|
+
// render, whose last `.line` span is then followed by a trailing `\n`
|
|
166
|
+
// text node. `sourceLines` has one more entry than `lineNumber` exactly
|
|
167
|
+
// when the source ended with a newline (the empty segment after it
|
|
168
|
+
// never became a line). This keeps the plain-text fallback the same
|
|
169
|
+
// height as the highlighted render (no hydration jump) AND makes the
|
|
170
|
+
// root fallback dictionary an exact match for the raw source text.
|
|
171
|
+
const sourceEndsWithNewline = sourceLines.length > lineNumber;
|
|
172
|
+
const text = frameIndex < lastIndex || sourceEndsWithNewline ? `${joined}\n` : joined;
|
|
173
|
+
// Cast to `ElementData` because `hast-util-from-parse5` augments
|
|
174
|
+
// it with a required `position` field (upstream bug — should be
|
|
175
|
+
// optional). We're not running through that parser here, so the
|
|
176
|
+
// field never exists at runtime.
|
|
177
|
+
if (!frame.data) {
|
|
178
|
+
frame.data = {};
|
|
179
|
+
}
|
|
180
|
+
frame.data.fallback = [{
|
|
181
|
+
type: 'text',
|
|
182
|
+
value: text
|
|
183
|
+
}];
|
|
150
184
|
}
|
|
151
185
|
}
|
|
152
186
|
}
|
|
@@ -66,6 +66,23 @@ export interface EnhanceCodeEmphasisOptions {
|
|
|
66
66
|
* @default 12
|
|
67
67
|
*/
|
|
68
68
|
focusFramesMaxSize?: number;
|
|
69
|
+
/**
|
|
70
|
+
* How to handle a focused region that exceeds `focusFramesMaxSize`.
|
|
71
|
+
*
|
|
72
|
+
* - `'truncate'` (default) — keep the first `focusFramesMaxSize` lines visible
|
|
73
|
+
* as a window and hide the overflow.
|
|
74
|
+
* - `'hide'` — produce no visible-window frame at all: the block collapses to
|
|
75
|
+
* nothing (`focusedLines === 0`) while staying `collapsible`, so the collapsed
|
|
76
|
+
* state is empty and expanding reveals the whole source.
|
|
77
|
+
*
|
|
78
|
+
* Applies to every focus trigger — an oversized `@highlight` region, an
|
|
79
|
+
* oversized `@focus` / `@focus-start` region, and the auto-focus-from-line-1
|
|
80
|
+
* case (no emphasis comments) when the source exceeds `focusFramesMaxSize`.
|
|
81
|
+
* Regions that fit within `focusFramesMaxSize` are unaffected.
|
|
82
|
+
*
|
|
83
|
+
* @default 'truncate'
|
|
84
|
+
*/
|
|
85
|
+
oversizedFocus?: 'truncate' | 'hide';
|
|
69
86
|
/**
|
|
70
87
|
* When `true`, throws an error if a `@highlight-text` match has to be
|
|
71
88
|
* fragmented across element boundaries (producing `data-hl-part` spans).
|
|
@@ -79,6 +96,11 @@ export interface EnhanceCodeEmphasisOptions {
|
|
|
79
96
|
* use this to visually shift collapsible regions horizontally when
|
|
80
97
|
* surrounding context lines are hidden. Off by default since most demos
|
|
81
98
|
* don't need it and it bloats the rendered HTML.
|
|
99
|
+
*
|
|
100
|
+
* Indent and padding are alternatives for conveying surrounding context.
|
|
101
|
+
* Combining this with the `paddingFrameMaxSize` option throws (configure one
|
|
102
|
+
* or the other); a per-region `@padding` directive in the source is allowed
|
|
103
|
+
* and ignored while this is set.
|
|
82
104
|
* @default false
|
|
83
105
|
*/
|
|
84
106
|
emitFrameIndent?: boolean;
|