@mui/internal-docs-infra 0.11.1-canary.9 → 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.
Files changed (319) hide show
  1. package/ChunkProvider/ChunkContext.d.mts +10 -0
  2. package/ChunkProvider/ChunkContext.mjs +15 -0
  3. package/ChunkProvider/ChunkProvider.d.mts +14 -0
  4. package/ChunkProvider/ChunkProvider.mjs +38 -0
  5. package/ChunkProvider/PreloadContext.d.mts +14 -0
  6. package/ChunkProvider/PreloadContext.mjs +18 -0
  7. package/ChunkProvider/PreloadProvider.d.mts +13 -0
  8. package/ChunkProvider/PreloadProvider.mjs +33 -0
  9. package/ChunkProvider/index.d.mts +7 -0
  10. package/ChunkProvider/index.mjs +7 -0
  11. package/ChunkProvider/types.d.mts +23 -0
  12. package/ChunkProvider/types.mjs +1 -0
  13. package/ChunkProvider/usePreload.d.mts +8 -0
  14. package/ChunkProvider/usePreload.mjs +21 -0
  15. package/CodeControllerContext/CodeControllerContext.d.mts +11 -0
  16. package/CodeControllerContext/CodeControllerContext.mjs +2 -1
  17. package/CodeHighlighter/CodeHighlighter.d.mts +15 -1
  18. package/CodeHighlighter/CodeHighlighter.mjs +97 -319
  19. package/CodeHighlighter/CodeHighlighterChunk.d.mts +42 -0
  20. package/CodeHighlighter/CodeHighlighterChunk.mjs +77 -0
  21. package/CodeHighlighter/CodeHighlighterClient.mjs +597 -128
  22. package/CodeHighlighter/CodeHighlighterContext.d.mts +57 -1
  23. package/CodeHighlighter/CodeHighlighterFallbackContext.d.mts +14 -2
  24. package/CodeHighlighter/CodeHighlighterFallbackContext.mjs +1 -3
  25. package/CodeHighlighter/CodeInitialSourceLoader.d.mts +10 -0
  26. package/CodeHighlighter/CodeInitialSourceLoader.mjs +108 -0
  27. package/CodeHighlighter/CodeSourceLoader.d.mts +11 -0
  28. package/CodeHighlighter/CodeSourceLoader.mjs +128 -0
  29. package/CodeHighlighter/buildCodeHighlighterChunkProps.d.mts +47 -0
  30. package/CodeHighlighter/buildCodeHighlighterChunkProps.mjs +61 -0
  31. package/CodeHighlighter/buildStringFallback.d.mts +29 -0
  32. package/CodeHighlighter/buildStringFallback.mjs +42 -0
  33. package/CodeHighlighter/codeToFallbackProps.d.mts +31 -2
  34. package/CodeHighlighter/codeToFallbackProps.mjs +347 -42
  35. package/CodeHighlighter/createClientProps.d.mts +17 -0
  36. package/CodeHighlighter/createClientProps.mjs +78 -0
  37. package/CodeHighlighter/errors.d.mts +6 -0
  38. package/CodeHighlighter/errors.mjs +10 -0
  39. package/CodeHighlighter/fallbackCompression.d.mts +96 -0
  40. package/CodeHighlighter/fallbackCompression.mjs +253 -0
  41. package/CodeHighlighter/fallbackFormat.d.mts +137 -0
  42. package/CodeHighlighter/fallbackFormat.mjs +422 -0
  43. package/CodeHighlighter/index.d.mts +4 -1
  44. package/CodeHighlighter/index.mjs +3 -1
  45. package/CodeHighlighter/mergeComments.d.mts +38 -0
  46. package/CodeHighlighter/mergeComments.mjs +80 -0
  47. package/CodeHighlighter/prepareInitialSource.d.mts +42 -0
  48. package/CodeHighlighter/prepareInitialSource.mjs +292 -0
  49. package/CodeHighlighter/resolveFallbackCritical.d.mts +23 -0
  50. package/CodeHighlighter/resolveFallbackCritical.mjs +44 -0
  51. package/CodeHighlighter/types.d.mts +272 -8
  52. package/CodeHighlighter/useCodeFallback.d.mts +94 -0
  53. package/CodeHighlighter/useCodeFallback.mjs +204 -0
  54. package/CodeHighlighter/useGrammarsReady.d.mts +18 -0
  55. package/CodeHighlighter/useGrammarsReady.mjs +45 -0
  56. package/CodeHighlighter/useSpeculativeCodePreload.d.mts +26 -0
  57. package/CodeHighlighter/useSpeculativeCodePreload.mjs +40 -0
  58. package/CodeHighlighter/useSpeculativeEditingPreload.d.mts +33 -0
  59. package/CodeHighlighter/useSpeculativeEditingPreload.mjs +58 -0
  60. package/CodeHighlighter/useSpeculativeGrammarPreload.d.mts +23 -0
  61. package/CodeHighlighter/useSpeculativeGrammarPreload.mjs +31 -0
  62. package/CodeHighlighter/useSpeculativeUseCodePreload.d.mts +22 -0
  63. package/CodeHighlighter/useSpeculativeUseCodePreload.mjs +41 -0
  64. package/CodeProvider/CodeContext.d.mts +47 -12
  65. package/CodeProvider/CodeContext.mjs +7 -0
  66. package/CodeProvider/CodeProvider.d.mts +4 -2
  67. package/CodeProvider/CodeProvider.mjs +40 -102
  68. package/CodeProvider/CodeProviderLazy.d.mts +40 -0
  69. package/CodeProvider/CodeProviderLazy.mjs +96 -0
  70. package/CodeProvider/constants.d.mts +26 -0
  71. package/CodeProvider/constants.mjs +24 -0
  72. package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
  73. package/CodeProvider/createParseSourceWorkerClient.mjs +22 -2
  74. package/CodeProvider/index.d.mts +2 -1
  75. package/CodeProvider/index.mjs +9 -1
  76. package/CodeProvider/parseSourceWorker.mjs +33 -0
  77. package/CodeProvider/useCodeProviderValue.d.mts +54 -0
  78. package/CodeProvider/useCodeProviderValue.mjs +188 -0
  79. package/CoordinatedLazy/ChunkServerLoader.d.mts +25 -0
  80. package/CoordinatedLazy/ChunkServerLoader.mjs +97 -0
  81. package/CoordinatedLazy/CoordinatedContentContext.d.mts +15 -0
  82. package/CoordinatedLazy/CoordinatedContentContext.mjs +22 -0
  83. package/CoordinatedLazy/CoordinatedFallbackContext.d.mts +11 -0
  84. package/CoordinatedLazy/CoordinatedFallbackContext.mjs +13 -0
  85. package/CoordinatedLazy/CoordinatedGateContext.d.mts +14 -0
  86. package/CoordinatedLazy/CoordinatedGateContext.mjs +19 -0
  87. package/CoordinatedLazy/CoordinatedLazy.d.mts +14 -0
  88. package/CoordinatedLazy/CoordinatedLazy.mjs +86 -0
  89. package/CoordinatedLazy/CoordinatedLazyClient.d.mts +24 -0
  90. package/CoordinatedLazy/CoordinatedLazyClient.mjs +65 -0
  91. package/CoordinatedLazy/LazyContent.d.mts +26 -0
  92. package/CoordinatedLazy/LazyContent.mjs +80 -0
  93. package/CoordinatedLazy/LazyContentServer.d.mts +18 -0
  94. package/CoordinatedLazy/LazyContentServer.mjs +25 -0
  95. package/CoordinatedLazy/buildChunkRenderInputs.d.mts +8 -0
  96. package/CoordinatedLazy/buildChunkRenderInputs.mjs +35 -0
  97. package/CoordinatedLazy/createCoordinatedLazy.d.mts +32 -0
  98. package/CoordinatedLazy/createCoordinatedLazy.mjs +127 -0
  99. package/CoordinatedLazy/index.d.mts +14 -0
  100. package/CoordinatedLazy/index.mjs +18 -0
  101. package/CoordinatedLazy/resolveChunkRender.d.mts +26 -0
  102. package/CoordinatedLazy/resolveChunkRender.mjs +73 -0
  103. package/CoordinatedLazy/types.d.mts +408 -0
  104. package/CoordinatedLazy/types.mjs +1 -0
  105. package/CoordinatedLazy/useChunk.d.mts +30 -0
  106. package/CoordinatedLazy/useChunk.mjs +135 -0
  107. package/CoordinatedLazy/useCoordinatedFallback.d.mts +12 -0
  108. package/CoordinatedLazy/useCoordinatedFallback.mjs +40 -0
  109. package/CoordinatedLazy/useCoordinatedSwap.d.mts +16 -0
  110. package/CoordinatedLazy/useCoordinatedSwap.mjs +124 -0
  111. package/LICENSE +1 -1
  112. package/abstractCreateDemo/abstractCreateDemo.d.mts +54 -3
  113. package/abstractCreateDemo/abstractCreateDemo.mjs +47 -7
  114. package/abstractCreateDemo/resolveDemoFlag.d.mts +20 -0
  115. package/abstractCreateDemo/resolveDemoFlag.mjs +25 -0
  116. package/abstractCreateStream/abstractCreateStream.d.mts +18 -0
  117. package/abstractCreateStream/abstractCreateStream.mjs +45 -0
  118. package/abstractCreateStream/index.d.mts +2 -0
  119. package/abstractCreateStream/index.mjs +1 -0
  120. package/abstractCreateStream/types.d.mts +34 -0
  121. package/abstractCreateStream/types.mjs +1 -0
  122. package/abstractCreateTypes/TypeCode.mjs +12 -11
  123. package/abstractCreateTypes/typesToJsx.mjs +30 -9
  124. package/cli/ensureDemoClients.mjs +4 -148
  125. package/cli/ensureDemoPages.d.mts +45 -0
  126. package/cli/ensureDemoPages.mjs +99 -0
  127. package/cli/fileUtils/index.d.mts +11 -0
  128. package/cli/fileUtils/index.mjs +48 -0
  129. package/cli/findDemoIndexFiles.d.mts +15 -0
  130. package/cli/findDemoIndexFiles.mjs +121 -0
  131. package/cli/index.mjs +1 -1
  132. package/cli/loadNextConfig.d.mts +25 -0
  133. package/cli/loadNextConfig.mjs +60 -1
  134. package/cli/runBrowser.mjs +1 -1
  135. package/cli/runValidate.mjs +44 -1
  136. package/package.json +84 -4
  137. package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasis.mjs +30 -0
  138. package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.d.mts +17 -0
  139. package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs +52 -0
  140. package/pipeline/hastUtils/frameFallbackFromSpans.d.mts +18 -0
  141. package/pipeline/hastUtils/frameFallbackFromSpans.mjs +24 -0
  142. package/pipeline/hastUtils/hast.d.mts +27 -0
  143. package/pipeline/hastUtils/hastCompression.d.mts +3 -1
  144. package/pipeline/hastUtils/hastCompression.mjs +9 -1
  145. package/pipeline/hastUtils/hastDecompress.mjs +10 -4
  146. package/pipeline/hastUtils/hastDictionary.mjs +9 -0
  147. package/pipeline/hastUtils/hastUtils.d.mts +4 -3
  148. package/pipeline/hastUtils/hastUtils.mjs +24 -12
  149. package/pipeline/hastUtils/index.d.mts +2 -1
  150. package/pipeline/hastUtils/index.mjs +2 -1
  151. package/pipeline/hastUtils/stripHighlightingSpans.d.mts +6 -2
  152. package/pipeline/hastUtils/stripHighlightingSpans.mjs +22 -10
  153. package/pipeline/lintJavascriptDemoFocus/lintJavascriptDemoFocus.mjs +10 -7
  154. package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.d.mts +31 -13
  155. package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +50 -55
  156. package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.d.mts +78 -0
  157. package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs +405 -0
  158. package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.d.mts +5 -5
  159. package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs +36 -66
  160. package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.d.mts +23 -0
  161. package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.mjs +92 -0
  162. package/pipeline/loadIsomorphicCodeVariant/decodeSource.d.mts +19 -0
  163. package/pipeline/loadIsomorphicCodeVariant/decodeSource.mjs +25 -0
  164. package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.d.mts +17 -0
  165. package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.mjs +26 -0
  166. package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +26 -2
  167. package/pipeline/loadIsomorphicCodeVariant/diffHast.mjs +563 -19
  168. package/pipeline/loadIsomorphicCodeVariant/embedTransforms.d.mts +49 -0
  169. package/pipeline/loadIsomorphicCodeVariant/embedTransforms.mjs +152 -0
  170. package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.d.mts +51 -0
  171. package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.mjs +161 -0
  172. package/pipeline/loadIsomorphicCodeVariant/flattenCodeVariant.mjs +6 -3
  173. package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.d.mts +12 -0
  174. package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.mjs +44 -0
  175. package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.d.mts +16 -0
  176. package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.mjs +74 -0
  177. package/pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs +17 -5
  178. package/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs +229 -15
  179. package/pipeline/loadIsomorphicCodeVariant/transformSource.d.mts +2 -2
  180. package/pipeline/loadIsomorphicCodeVariant/transformSource.mjs +56 -22
  181. package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.mts +18 -0
  182. package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +11 -7
  183. package/pipeline/loadServerTypes/hastTypeUtils.d.mts +2 -2
  184. package/pipeline/loadServerTypes/hastTypeUtils.mjs +4 -4
  185. package/pipeline/loadServerTypes/loadServerTypes.mjs +1 -1
  186. package/pipeline/loadServerTypesMeta/extractJSDocText.d.mts +14 -0
  187. package/pipeline/loadServerTypesMeta/extractJSDocText.mjs +60 -0
  188. package/pipeline/loadServerTypesMeta/processTypes.mjs +43 -46
  189. package/pipeline/loadServerTypesText/order.mjs +1 -1
  190. package/pipeline/loadServerTypesText/parseTypesMarkdown.mjs +3 -1
  191. package/pipeline/loaderUtils/index.d.mts +0 -1
  192. package/pipeline/loaderUtils/index.mjs +0 -1
  193. package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -1
  194. package/pipeline/loaderUtils/parseImportsAndComments.mjs +19 -9
  195. package/pipeline/loaderUtils/resolveModulePath.mjs +23 -1
  196. package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +12 -0
  197. package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +17 -13
  198. package/pipeline/parseSource/addLineGutters.mjs +45 -11
  199. package/pipeline/parseSource/calculateFrameRanges.d.mts +22 -0
  200. package/pipeline/parseSource/calculateFrameRanges.mjs +69 -25
  201. package/pipeline/parseSource/detectGrammarScopes.d.mts +13 -0
  202. package/pipeline/parseSource/detectGrammarScopes.mjs +35 -0
  203. package/pipeline/parseSource/extendSyntaxTokens.mjs +501 -43
  204. package/pipeline/parseSource/frameVisibility.d.mts +47 -0
  205. package/pipeline/parseSource/frameVisibility.mjs +114 -0
  206. package/pipeline/parseSource/grammarCache.d.mts +33 -0
  207. package/pipeline/parseSource/grammarCache.mjs +73 -0
  208. package/pipeline/parseSource/grammarLoaders.d.mts +14 -0
  209. package/pipeline/parseSource/grammarLoaders.mjs +24 -0
  210. package/pipeline/parseSource/grammarMaps.d.mts +21 -1
  211. package/pipeline/parseSource/grammarMaps.mjs +36 -0
  212. package/pipeline/parseSource/isFrameSpan.d.mts +19 -0
  213. package/pipeline/parseSource/isFrameSpan.mjs +24 -0
  214. package/pipeline/parseSource/parseSource.d.mts +41 -6
  215. package/pipeline/parseSource/parseSource.mjs +184 -36
  216. package/pipeline/parseSource/redistributeFrameFallbacks.d.mts +40 -0
  217. package/pipeline/parseSource/redistributeFrameFallbacks.mjs +138 -0
  218. package/pipeline/parseSource/restructureFrames.d.mts +5 -0
  219. package/pipeline/parseSource/restructureFrames.mjs +179 -16
  220. package/pipeline/syncPageIndex/metadataToMarkdown.mjs +6 -2
  221. package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.d.mts +26 -0
  222. package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +181 -114
  223. package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.d.mts +12 -0
  224. package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.mjs +52 -0
  225. package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +22 -1
  226. package/pipeline/transformTypescriptToJavascript/removeTypes.d.mts +5 -8
  227. package/pipeline/transformTypescriptToJavascript/removeTypes.mjs +27 -93
  228. package/useCode/EditableEngine.d.mts +233 -0
  229. package/useCode/EditableEngine.mjs +1712 -0
  230. package/useCode/EditingEngine.d.mts +13 -0
  231. package/useCode/EditingEngine.mjs +14 -0
  232. package/useCode/Pre.browser.mjs +5 -1
  233. package/useCode/Pre.d.mts +127 -1
  234. package/useCode/Pre.mjs +417 -165
  235. package/useCode/SourceEditingEngine.d.mts +50 -0
  236. package/useCode/SourceEditingEngine.mjs +461 -0
  237. package/useCode/TransformEngine.d.mts +39 -0
  238. package/useCode/TransformEngine.mjs +208 -0
  239. package/useCode/editingEngineCache.d.mts +29 -0
  240. package/useCode/editingEngineCache.mjs +68 -0
  241. package/useCode/sourceLineCounts.d.mts +80 -0
  242. package/useCode/sourceLineCounts.mjs +284 -0
  243. package/useCode/subscribeToggleNudge.d.mts +3 -0
  244. package/useCode/subscribeToggleNudge.mjs +95 -0
  245. package/useCode/transformEngineCache.d.mts +21 -0
  246. package/useCode/transformEngineCache.mjs +60 -0
  247. package/useCode/useCode.d.mts +140 -1
  248. package/useCode/useCode.mjs +250 -19
  249. package/useCode/useCodeUtils.d.mts +131 -20
  250. package/useCode/useCodeUtils.mjs +267 -194
  251. package/useCode/useCopyFunctionality.d.mts +13 -1
  252. package/useCode/useCopyFunctionality.mjs +39 -9
  253. package/useCode/useEditable.browser.mjs +10 -2
  254. package/useCode/useEditable.d.mts +27 -106
  255. package/useCode/useEditable.integration.browser.d.mts +1 -0
  256. package/useCode/useEditable.integration.browser.mjs +870 -0
  257. package/useCode/useEditable.mjs +198 -1247
  258. package/useCode/useEditableUtils.d.mts +50 -1
  259. package/useCode/useEditableUtils.mjs +29 -0
  260. package/useCode/useFileNavigation.d.mts +91 -3
  261. package/useCode/useFileNavigation.mjs +201 -41
  262. package/useCode/useHighlightGate.d.mts +17 -0
  263. package/useCode/useHighlightGate.mjs +147 -0
  264. package/useCode/useSourceEditing.d.mts +8 -0
  265. package/useCode/useSourceEditing.mjs +158 -314
  266. package/useCode/useSourceEnhancing.d.mts +5 -1
  267. package/useCode/useSourceEnhancing.mjs +22 -36
  268. package/useCode/useTransformManagement.d.mts +93 -5
  269. package/useCode/useTransformManagement.mjs +496 -28
  270. package/useCode/useTransitionPhase.d.mts +24 -0
  271. package/useCode/useTransitionPhase.mjs +49 -0
  272. package/useCode/useUIState.d.mts +2 -2
  273. package/useCode/useUIState.mjs +8 -8
  274. package/useCode/useVariantSelection.d.mts +130 -6
  275. package/useCode/useVariantSelection.mjs +529 -93
  276. package/useCodeWindow/useCodeWindow.d.mts +19 -2
  277. package/useCodeWindow/useCodeWindow.mjs +98 -71
  278. package/useCoordinated/coordinatePreference.d.mts +439 -0
  279. package/useCoordinated/coordinatePreference.mjs +951 -0
  280. package/useCoordinated/coordinatePreference.testUtils.d.mts +21 -0
  281. package/useCoordinated/coordinatePreference.testUtils.mjs +69 -0
  282. package/useCoordinated/createSettleGate.d.mts +96 -0
  283. package/useCoordinated/createSettleGate.mjs +171 -0
  284. package/useCoordinated/index.d.mts +8 -0
  285. package/useCoordinated/index.mjs +8 -0
  286. package/useCoordinated/layoutShiftGate.d.mts +24 -0
  287. package/useCoordinated/layoutShiftGate.mjs +79 -0
  288. package/useCoordinated/pageSettleGate.d.mts +11 -0
  289. package/useCoordinated/pageSettleGate.mjs +13 -0
  290. package/useCoordinated/scheduleTasks.d.mts +23 -0
  291. package/useCoordinated/scheduleTasks.mjs +45 -0
  292. package/useCoordinated/useCoordinated.d.mts +193 -0
  293. package/useCoordinated/useCoordinated.mjs +469 -0
  294. package/useCoordinated/useCoordinatedLazy.d.mts +17 -0
  295. package/useCoordinated/useCoordinatedLazy.mjs +38 -0
  296. package/useCoordinated/useCoordinatedLocalStorage.d.mts +16 -0
  297. package/useCoordinated/useCoordinatedLocalStorage.mjs +22 -0
  298. package/useCoordinated/useCoordinatedPreference.d.mts +20 -0
  299. package/useCoordinated/useCoordinatedPreference.mjs +26 -0
  300. package/useCoordinated/useSettleGate.d.mts +11 -0
  301. package/useCoordinated/useSettleGate.mjs +34 -0
  302. package/useDemo/exportVariant.d.mts +12 -5
  303. package/useDemo/exportVariant.mjs +59 -5
  304. package/useDemo/useDemo.d.mts +5 -2
  305. package/useScrollAnchor/useScrollAnchor.mjs +28 -5
  306. package/useStream/index.d.mts +6 -0
  307. package/useStream/index.mjs +6 -0
  308. package/useStream/streamChunks.d.mts +23 -0
  309. package/useStream/streamChunks.mjs +85 -0
  310. package/useStream/types.d.mts +45 -0
  311. package/useStream/types.mjs +1 -0
  312. package/useStream/useStream.d.mts +57 -0
  313. package/useStream/useStream.mjs +119 -0
  314. package/useStream/useStreamController.d.mts +15 -0
  315. package/useStream/useStreamController.mjs +90 -0
  316. package/withDocsInfra/withDocsInfra.d.mts +19 -0
  317. package/withDocsInfra/withDocsInfra.mjs +13 -5
  318. package/pipeline/loaderUtils/convertCommentsToOneIndexed.d.mts +0 -8
  319. package/pipeline/loaderUtils/convertCommentsToOneIndexed.mjs +0 -16
@@ -1,5 +1,6 @@
1
1
  import type { Root, RootData } from 'hast';
2
2
  import type { Delta } from 'jsondiffpatch';
3
+ import type { FallbackNode, CompressedFallback } from "./fallbackFormat.mjs";
3
4
  export type Components = {
4
5
  [key: string]: React.ReactNode;
5
6
  };
@@ -11,9 +12,62 @@ type CodeMeta = {
11
12
  /** Flattened path for the file */
12
13
  path?: string;
13
14
  };
15
+ /**
16
+ * Records the transforms available for a source. Each entry can provide a
17
+ * jsondiffpatch `delta` (the patch to apply against the source's parsed hast
18
+ * tree), an optional renamed `fileName`, and an optional `comments` map.
19
+ *
20
+ * When `comments` is present, it represents the post-transform comment map
21
+ * (1-indexed by line number in the transformed source) and is used as-is by
22
+ * `applyCodeTransformWithComments` instead of auto-shifting the caller's
23
+ * comments via the surviving `dataLn` mapping. Source transformers should
24
+ * only emit `comments` when they add or relocate lines; transforms that only
25
+ * wipe lines (replacing them with empty strings) are handled automatically.
26
+ *
27
+ * `hasDelta` indicates whether the entry actually produced a code-level
28
+ * difference. When `false` (or omitted), the entry is rename-only — it
29
+ * carries a renamed `fileName` (and optionally `comments`) but the
30
+ * transformed source is structurally identical to the original. Rename-only
31
+ * entries are excluded from `getAvailableTransforms` (so the toggle stays
32
+ * hidden when nothing meaningful changes) but still apply the rename when
33
+ * the user has the matching transform preference selected.
34
+ *
35
+ * `hasCollapse` indicates whether the inline `delta` (or the embedded delta
36
+ * matching this manifest entry) inserts a `.collapse` placeholder element.
37
+ * The runtime uses this flag to classify a transform swap as
38
+ * layout-affecting (phase 1: coordinated barrier so peers stay in lockstep)
39
+ * versus non-layout (phase 2: deferred until after phase 1 settles) without
40
+ * having to decompress the embedded hast payload on every selection
41
+ * change. Computed once during `splitTransformsForEmbed` and persisted on
42
+ * the manifest entry.
43
+ *
44
+ * `hasCollapseInFocus` is the focus-region-aware counterpart: it is `true`
45
+ * only when at least one `.collapse` placeholder lands inside the source
46
+ * region that is visible when the surrounding code block is *collapsed*
47
+ * (the lines covered by `data-frame-type` ∈ `'highlighted' | 'focus' |
48
+ * 'padding-top' | 'padding-bottom'`, falling back to the first frame when
49
+ * no emphasis frames exist — matching the runtime visibility rule in
50
+ * `<Pre>`). Consumers that opt into `transformLayoutShift: 'focus'` use
51
+ * this flag (instead of `hasCollapse`) while the block is collapsed, so a
52
+ * `.collapse` insertion outside the visible window doesn't force a
53
+ * coordinated barrier swap that the user wouldn't see anyway.
54
+ *
55
+ * After serialization (`output: 'hastJson' | 'hastCompressed'`), the deltas
56
+ * are moved inside the source's `HastRoot.data.transforms` so they ride
57
+ * along inside the compressed payload and never appear as plain JSON in the
58
+ * rendered HTML or in the demo module graph. In that mode the variant-level
59
+ * `transforms` field acts as a manifest — entries keep `fileName`,
60
+ * `comments` (when set), `hasDelta`, `hasCollapse`, and
61
+ * `hasCollapseInFocus` but `delta` is omitted. Consumers that need the
62
+ * delta should look it up inside the decompressed `root.data.transforms`.
63
+ */
14
64
  export type Transforms = Record<string, {
15
- delta: Delta;
65
+ delta?: Delta;
16
66
  fileName?: string;
67
+ comments?: SourceComments;
68
+ hasDelta?: boolean;
69
+ hasCollapse?: boolean;
70
+ hasCollapseInFocus?: boolean;
17
71
  }>;
18
72
  export interface ExternalImportItem {
19
73
  name: string;
@@ -24,9 +78,25 @@ export type Externals = Record<string, ExternalImportItem[]>;
24
78
  export interface HastRoot extends Root {
25
79
  data?: RootData & {
26
80
  totalLines?: number;
81
+ /**
82
+ * Number of source lines visible inside the focused window when the code
83
+ * block is collapsed — the sum of frame sizes whose `data-frame-type` is
84
+ * `'highlighted'`, `'focus'`, `'padding-top'`, or `'padding-bottom'`.
85
+ * Equals `totalLines` when no emphasis directives are present (the whole
86
+ * source is the focused window). Set by `enhanceCodeEmphasis`.
87
+ */
88
+ focusedLines?: number;
27
89
  collapsible?: boolean;
28
90
  frameSize?: number;
29
91
  appliedEnhancers?: string[];
92
+ /**
93
+ * Transform deltas embedded in the hast root so they get compressed along
94
+ * with the tree and stay out of the rendered HTML / module graph. The
95
+ * variant-level `transforms` field is a `TransformManifest` (keys only)
96
+ * that mirrors `Object.keys(this.transforms)`. `hast-util-to-jsx-runtime`
97
+ * does not serialize `Root.data` to the DOM.
98
+ */
99
+ transforms?: Transforms;
30
100
  };
31
101
  }
32
102
  export type VariantSource = string | HastRoot | {
@@ -42,6 +112,15 @@ export type VariantExtraFiles = {
42
112
  [fileName: string]: string | {
43
113
  /** Source content for this file */
44
114
  source?: VariantSource;
115
+ /**
116
+ * Compact fallback for this extra file.
117
+ * See `VariantCode.fallback` for details.
118
+ */
119
+ fallback?: FallbackNode[];
120
+ /** Line counts for this file. See `VariantCode.totalLines` / `focusedLines`. */
121
+ totalLines?: number;
122
+ focusedLines?: number;
123
+ collapsible?: boolean;
45
124
  /** Language for syntax highlighting (e.g., 'tsx', 'css'). Derived from fileName extension if not provided. */
46
125
  language?: string;
47
126
  /** Transformations that can be applied to this file */
@@ -76,6 +155,41 @@ export type VariantCode = CodeMeta & {
76
155
  url?: string;
77
156
  /** Main source content for this variant */
78
157
  source?: VariantSource;
158
+ /**
159
+ * Compact fallback (highlighting spans removed) for the main source.
160
+ * Converted from HAST via `hastToFallback` for smaller RSC payloads.
161
+ * Used as the visual fallback before full highlighting loads, and its text
162
+ * content (via `fallbackToText`) serves as the DEFLATE dictionary for
163
+ * decompressing `hastCompressed` payloads.
164
+ */
165
+ fallback?: FallbackNode[];
166
+ /**
167
+ * Staging-only highlighted-visible fallback, stored **sparsely**: a map from frame
168
+ * index to the highlighted `FallbackNode` for ONLY the frames visible on the initial
169
+ * (collapsed, `collapseToEmpty: false`) render. Off-screen frames are omitted — they
170
+ * are byte-identical to `fallback`'s plain output, so storing them would just
171
+ * duplicate `fallback` in the precompute. Computed at load time (where the source is
172
+ * still a live `HastRoot`, so no decompression) and carried in precomputed payloads
173
+ * alongside `fallback`. Under `highlightAt: 'init'` the server/client boundary
174
+ * `promoteCriticalFallback`s it over `fallback` so the first paint is highlighted with
175
+ * no client-side decompression, then deletes it: `fallbackCritical` must NEVER reach
176
+ * the `Content`/`ContentLoading` components. The promoted `fallback` has byte-identical
177
+ * text, so it stays a valid DEFLATE dictionary. See `resolveFallbackCritical`.
178
+ */
179
+ fallbackCritical?: {
180
+ [frameIndex: number]: FallbackNode;
181
+ };
182
+ /**
183
+ * Line counts for this variant's main source — the same for the full (highlighted)
184
+ * source and its `fallback`, since they're the same file. `totalLines` is the whole
185
+ * file; `focusedLines` is the collapsed-window size. The loader surfaces them
186
+ * with `collapsible` (notably for deferred plain-string sources, where the compact
187
+ * `fallback` drops `root.data` and a string can't recompute the metadata) so
188
+ * consumers can size and flag the `<code>` without re-deriving from counts.
189
+ */
190
+ totalLines?: number;
191
+ focusedLines?: number;
192
+ collapsible?: boolean;
79
193
  /** Additional files associated with this variant */
80
194
  extraFiles?: VariantExtraFiles;
81
195
  /** Prefix for metadata keys, e.g. /src */
@@ -106,6 +220,7 @@ export type Code = {
106
220
  export type CollapseMap = Record<number, Array<{
107
221
  offset: number;
108
222
  comments: string[];
223
+ boundary?: true;
109
224
  }>>;
110
225
  export type ControlledVariantExtraFiles = {
111
226
  [fileName: string]: {
@@ -133,14 +248,58 @@ export type ControlledCode = {
133
248
  * Base props passed to Content components for rendering code examples.
134
249
  * These props provide the necessary data for displaying code, previews, and metadata.
135
250
  */
136
- type BaseContentProps = CodeIdentityProps & Pick<CodeContentProps, 'code' | 'components' | 'variantType'>;
251
+ type BaseContentProps = CodeIdentityProps & Pick<CodeContentProps, 'code' | 'components' | 'variantType'> & {
252
+ /**
253
+ * Render-time "collapse to empty": collapse the code block to an empty window so
254
+ * the whole block is hidden until the reader expands it. Runtime-only — it
255
+ * never changes the precomputed HAST, only how it's rendered.
256
+ */
257
+ collapseToEmpty?: boolean;
258
+ /**
259
+ * Whether the (collapsible) code block starts expanded. Runtime-only. Lives
260
+ * on `contentProps` rather than `useCode` opts so the loading fallback can
261
+ * see it too.
262
+ */
263
+ initialExpanded?: boolean;
264
+ };
137
265
  export type ContentProps<T extends {}> = BaseContentProps & T;
266
+ /**
267
+ * Record of `fileName → compact fallback` extracted from variants.
268
+ * Used as the DEFLATE dictionary for `hastCompressed` decompression and
269
+ * as the visual fallback before full highlighting loads.
270
+ */
271
+ export type Fallbacks = Record<string, FallbackNode[]>;
272
+ /**
273
+ * A framed fallback for one file: the compact `source` frames plus the file's
274
+ * loading metadata (`totalLines` whole-file, `focusedLines` collapsed-window,
275
+ * `collapsible` frame state). Carried per extra file so a `ContentLoading` can
276
+ * render the full framed code — with the right collapsed window — for every
277
+ * file/variant passed to the fallback, not just the displayed one. The main
278
+ * file's equivalent metadata lives on the variant as top-level fields alongside
279
+ * its top-level `source`.
280
+ */
281
+ export type ContentLoadingFile = {
282
+ source: FallbackNode[];
283
+ totalLines?: number;
284
+ focusedLines?: number;
285
+ collapsible?: boolean;
286
+ };
138
287
  export type ContentLoadingVariant = {
139
288
  fileNames?: string[];
140
- source?: React.ReactNode;
141
- extraSource?: {
142
- [fileName: string]: React.ReactNode;
143
- };
289
+ source?: FallbackNode[];
290
+ /** Loading metadata for the main `source` file. See {@link ContentLoadingFile}. */
291
+ totalLines?: number;
292
+ focusedLines?: number;
293
+ collapsible?: boolean;
294
+ /**
295
+ * Language hint for the rendered `source` (e.g. `'tsx'`, `'css'`). Derived
296
+ * from the variant's explicit `language` when set, otherwise from the
297
+ * selected file name's extension. Consumers typically forward this as a
298
+ * `language-{language}` class on the fallback `<code>` element so it picks
299
+ * up the same language-scoped styling as the post-load tree.
300
+ */
301
+ language?: string;
302
+ extraSource?: Record<string, ContentLoadingFile>;
144
303
  };
145
304
  export type BaseContentLoadingProps = ContentLoadingVariant & CodeIdentityProps & {
146
305
  extraVariants?: Record<string, ContentLoadingVariant>;
@@ -149,6 +308,34 @@ export type ContentLoadingProps<T extends {}> = BaseContentLoadingProps & T & {
149
308
  component: React.ReactNode;
150
309
  components?: Record<string, React.ReactNode>;
151
310
  initialFilename?: string;
311
+ /**
312
+ * Name of the variant currently selected for the fallback render — the
313
+ * same key passed to `codeToFallbackProps` and used to look up
314
+ * `component` / `components`. Consumers use this when labeling the main
315
+ * variant in the fallback UI or when generating per-file slugs.
316
+ */
317
+ initialVariant?: string;
318
+ /**
319
+ * Set when the surrounding `CodeHighlighter` uses `fallbackCollapsed`: the
320
+ * `source` here is only the collapsed window, and the hidden lines arrive
321
+ * later with the full content. A `ContentLoading` should disable any expand
322
+ * control while this is true — expanding would reveal nothing until the
323
+ * full content swaps in. `useCodeFallback` re-exposes it as `collapsed`.
324
+ */
325
+ fallbackCollapsed?: boolean;
326
+ /**
327
+ * Render-time "collapse to empty": the loading placeholder should paint an empty
328
+ * collapsed window (the whole block hidden until expanded), matching the
329
+ * hydrated render. `useCodeFallback` honors this by demoting collapsed-
330
+ * visible frame types in the returned `source`.
331
+ */
332
+ collapseToEmpty?: boolean;
333
+ /**
334
+ * Whether the block starts expanded. The loading placeholder uses it to
335
+ * paint the full content (not just the collapsed window) when the hydrated
336
+ * block will start expanded.
337
+ */
338
+ initialExpanded?: boolean;
152
339
  };
153
340
  export type LoadCodeMeta = (url: string) => Promise<Code>;
154
341
  export type LoadVariantMeta = (variantName: string, url: string) => Promise<VariantCode>;
@@ -160,9 +347,32 @@ export type LoadSource = (url: string) => Promise<{
160
347
  /** Comments extracted from the source code, keyed by line number */
161
348
  comments?: SourceComments;
162
349
  }>;
163
- export type TransformSource = (source: string, fileName: string) => Promise<Record<string, {
350
+ /**
351
+ * Function that transforms a source file into one or more derived sources.
352
+ *
353
+ * @param source - The source code string to transform.
354
+ * @param fileName - File name (used for extension detection / diagnostics).
355
+ * @param comments - Optional comment map for `source`, keyed by 1-indexed
356
+ * line number (the convention everywhere a `Code` is stored). Transformers
357
+ * that want to shift comments manually should return a `comments` map
358
+ * alongside each transformed source, using the same 1-indexed line scheme
359
+ * relative to the returned source string.
360
+ * @returns A record keyed by transform name. Each entry must contain the
361
+ * transformed `source` string, optionally a renamed `fileName`, and
362
+ * optionally a `comments` map (1-indexed). The runtime applies `comments`
363
+ * verbatim when present; when omitted, surviving lines' comments are
364
+ * shifted automatically based on which source lines survived the transform.
365
+ *
366
+ * Transformers that only **remove** lines should replace those lines with
367
+ * empty strings rather than dropping them — the empty lines collapse
368
+ * automatically at runtime and the auto-shift correctly maps the
369
+ * surviving lines' comments. Only transformers that **add lines** or
370
+ * completely replace the file need to return an explicit `comments` map.
371
+ */
372
+ export type TransformSource = (source: string, fileName: string, comments?: SourceComments) => Promise<Record<string, {
164
373
  source: string;
165
374
  fileName?: string;
375
+ comments?: SourceComments;
166
376
  }> | undefined>;
167
377
  /**
168
378
  * Parses source code into a HAST tree with syntax highlighting.
@@ -213,6 +423,14 @@ export interface LoadFileOptions {
213
423
  disableTransforms?: boolean;
214
424
  /** Disable parsing source strings to AST */
215
425
  disableParsing?: boolean;
426
+ /**
427
+ * When parsing is skipped (`disableParsing`/deferred highlight) and the source
428
+ * stays a plain string, still derive a *framed* loading fallback from it —
429
+ * line-guttered plain-text HAST + enhancers → root fallback. Set by the loading
430
+ * fallback loader so the un-highlighted initial paint is framed (rendered code
431
+ * needs frames); left off for lazy variant loads that don't paint a fallback.
432
+ */
433
+ framePlainFallback?: boolean;
216
434
  /** Maximum recursion depth for loading nested extra files */
217
435
  maxDepth?: number;
218
436
  /** Set of already loaded file URLs to prevent circular dependencies */
@@ -296,8 +514,31 @@ export interface CodeLoadingProps {
296
514
  fallbackUsesExtraFiles?: boolean;
297
515
  /** Whether fallback content should include all variants */
298
516
  fallbackUsesAllVariants?: boolean;
517
+ /**
518
+ * Paint only the collapsed window in the `ContentLoading` fallback and defer
519
+ * each file's full fallback into the compressed payload. Shrinks the initial
520
+ * HTML of a collapsed block to its on-screen lines, but removes the hidden
521
+ * lines from the server-rendered markup — so it is **only** appropriate for
522
+ * content that will not be crawled (authenticated or internal pages). See the
523
+ * prop-compression pattern's "Splitting the Fallback by Visibility".
524
+ * @default false
525
+ */
526
+ fallbackCollapsed?: boolean;
299
527
  /** Enable controlled mode for external code state management */
300
528
  controlled?: boolean;
529
+ /**
530
+ * When the live-editing engine loads for an editable block:
531
+ * - `'eager'` (default): load it as soon as the block is editable, and let
532
+ * `CodeHighlighter` speculatively preload it on first render.
533
+ * - `'interaction'`: defer the load until the reader hovers, focuses, or
534
+ * clicks the code, and suppress the speculative preload — so a block the
535
+ * reader never engages does not fetch the engine chunk at all.
536
+ *
537
+ * Only meaningful for editable blocks (a `CodeControllerContext` exposing
538
+ * `setCode`); ignored otherwise.
539
+ * @default 'eager'
540
+ */
541
+ editActivation?: 'eager' | 'interaction';
301
542
  /** Raw code string for simple use cases */
302
543
  children?: string;
303
544
  /**
@@ -368,7 +609,20 @@ export interface CodeClientRenderingProps {
368
609
  * Base props containing essential properties shared across CodeHighlighter components and helper functions.
369
610
  * This serves as the foundation for other CodeHighlighter-related interfaces.
370
611
  */
371
- export interface CodeHighlighterBaseProps<T extends {}> extends CodeIdentityProps, CodeContentProps, CodeLoadingProps, CodeFunctionProps, CodeRenderingProps<T> {}
612
+ export interface CodeHighlighterBaseProps<T extends {}> extends CodeIdentityProps, CodeContentProps, CodeLoadingProps, CodeFunctionProps, CodeRenderingProps<T> {
613
+ /**
614
+ * Render-time "collapse to empty": collapse the code block to an empty window so
615
+ * the whole block is hidden until expanded. Threaded into `contentProps` and
616
+ * consumed by `useCode`/`<Pre>`. Runtime-only — the precomputed HAST is
617
+ * unchanged.
618
+ */
619
+ collapseToEmpty?: boolean;
620
+ /**
621
+ * Whether the (collapsible) code block starts expanded. Threaded into
622
+ * `contentProps` so both `useCode` and the loading fallback honor it.
623
+ */
624
+ initialExpanded?: boolean;
625
+ }
372
626
  /**
373
627
  * Props for the client-side CodeHighlighter component.
374
628
  * Used when rendering happens in the browser with lazy loading and interactive features.
@@ -380,6 +634,16 @@ export interface CodeHighlighterClientProps extends CodeIdentityProps, CodeConte
380
634
  */
381
635
  highlightAfter?: 'init' | 'hydration' | 'idle';
382
636
  enhanceAfter?: 'init' | 'hydration' | 'idle';
637
+ /**
638
+ * The variant/file fallbacks a `ContentLoading` component never renders,
639
+ * consolidated into a single DEFLATE blob (see `compressResidualFallbacks`).
640
+ * The rendered subset crosses plain on `ContentLoading` props; this carries
641
+ * everything else compressed. Decompressed once on the client — using the
642
+ * hoisted rendered text as its preset dictionary — and scattered back onto
643
+ * `Code` before the content decodes. Absent when there is no residual worth
644
+ * compressing.
645
+ */
646
+ residualFallbacks?: CompressedFallback;
383
647
  }
384
648
  /**
385
649
  * Main props for the CodeHighlighter component.
@@ -0,0 +1,94 @@
1
+ import * as React from 'react';
2
+ import type { ContentLoadingVariant, HastRoot } from "./types.mjs";
3
+ /**
4
+ * Render-time "collapse to empty" for the loading placeholder: demotes every
5
+ * collapsed-visible frame type in a fallback `HastRoot` to its hidden variant
6
+ * (matching `<Pre>`'s live rewrite) so the collapse CSS paints an empty window,
7
+ * and records `focusedLines: 0`. Mutates the freshly-decoded root in place.
8
+ */
9
+ export declare function applyCollapseToEmptyToFallbackHast(root: HastRoot): HastRoot;
10
+ /** A decoded extra-file fallback: the rendered `HastRoot` plus its line counts. */
11
+ export interface UseCodeFallbackFile {
12
+ source: HastRoot;
13
+ totalLines?: number;
14
+ focusedLines?: number;
15
+ collapsible?: boolean;
16
+ }
17
+ export interface UseCodeFallbackResult {
18
+ source?: HastRoot;
19
+ fileNames?: string[];
20
+ extraSource?: Record<string, UseCodeFallbackFile>;
21
+ extraVariants?: Record<string, UseCodeFallbackVariantResult>;
22
+ /**
23
+ * `true` when the surrounding `CodeHighlighter` uses `fallbackCollapsed`, so
24
+ * `source` is only the collapsed window. A `ContentLoading` should disable any
25
+ * expand control while this is set — the hidden lines arrive with the full
26
+ * content, not the fallback.
27
+ */
28
+ collapsed?: boolean;
29
+ /**
30
+ * Line counts for the displayed file, threaded from the server (the compact
31
+ * `source` has dropped `root.data`, where they live). A `ContentLoading` mirrors
32
+ * them onto the fallback `<code>` as `data-total-lines` / `data-focused-lines` so
33
+ * it matches the hydrated `<Pre>`. `focusedLines` is the visible-window size —
34
+ * forced to 0 here when `collapseToEmpty` empties the painted window, so it stays
35
+ * consistent with the demoted `source`. `collapsible` is threaded separately
36
+ * from the enhancer/loader because counts alone cannot describe whether the
37
+ * collapsed frame structure has hidden content to expand into.
38
+ */
39
+ totalLines?: number;
40
+ focusedLines?: number;
41
+ collapsible?: boolean;
42
+ /**
43
+ * Ready-to-render `<code>` for the displayed file — the rendered `source` with
44
+ * `data-filename` / `data-collapsible` / `data-total-lines` / `data-focused-lines`
45
+ * and the `language-{language}` class already applied, matching `<Pre>`. Drop it
46
+ * into a `<pre>` so a `ContentLoading` needn't re-wire (or drift from) those
47
+ * attributes. `null` when there's no source to paint.
48
+ */
49
+ code?: React.ReactNode;
50
+ }
51
+ export interface UseCodeFallbackVariantResult {
52
+ fileNames?: string[];
53
+ source?: HastRoot;
54
+ totalLines?: number;
55
+ focusedLines?: number;
56
+ collapsible?: boolean;
57
+ extraSource?: Record<string, UseCodeFallbackFile>;
58
+ }
59
+ interface UseCodeFallbackProps extends ContentLoadingVariant {
60
+ initialVariant?: string;
61
+ initialFilename?: string;
62
+ extraVariants?: Record<string, ContentLoadingVariant>;
63
+ fallbackCollapsed?: boolean;
64
+ collapseToEmpty?: boolean;
65
+ totalLines?: number;
66
+ focusedLines?: number;
67
+ collapsible?: boolean;
68
+ }
69
+ /**
70
+ * Hook for `ContentLoading` components to hoist fallback data
71
+ * to `CodeHighlighterClient` for text-dictionary derivation.
72
+ *
73
+ * On the server-rendered path, Code is stripped of `fallback` entries
74
+ * and the data arrives on ContentLoading as `source`/`extraSource` props
75
+ * in compact `FallbackNode[]` format. This hook converts them back to
76
+ * `HastRoot` for rendering and hoists the compact form for dictionaries.
77
+ *
78
+ * On the client-loaded path, `useInitialData` already hoists directly,
79
+ * so this hook simply passes props through.
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * function MyContentLoading(props: ContentLoadingProps<{}>) {
84
+ * const { source, extraSource } = useCodeFallback(props);
85
+ * return (
86
+ * <div>
87
+ * {source && hastToJsx(source)}
88
+ * </div>
89
+ * );
90
+ * }
91
+ * ```
92
+ */
93
+ export declare function useCodeFallback(props?: UseCodeFallbackProps): UseCodeFallbackResult;
94
+ export {};
@@ -0,0 +1,204 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { fallbackToHast } from "./fallbackFormat.mjs";
5
+ import { resolveCollapsedFrameType } from "../pipeline/parseSource/frameVisibility.mjs";
6
+ import { isFrameSpan } from "../pipeline/parseSource/isFrameSpan.mjs";
7
+ import { hastToJsx } from "../pipeline/hastUtils/index.mjs";
8
+ import { CodeHighlighterFallbackContext } from "./CodeHighlighterFallbackContext.mjs";
9
+
10
+ /**
11
+ * Render-time "collapse to empty" for the loading placeholder: demotes every
12
+ * collapsed-visible frame type in a fallback `HastRoot` to its hidden variant
13
+ * (matching `<Pre>`'s live rewrite) so the collapse CSS paints an empty window,
14
+ * and records `focusedLines: 0`. Mutates the freshly-decoded root in place.
15
+ */
16
+ export function applyCollapseToEmptyToFallbackHast(root) {
17
+ for (const child of root.children) {
18
+ if (child.type !== 'element' || !isFrameSpan(child)) {
19
+ continue;
20
+ }
21
+ const frameType = typeof child.properties.dataFrameType === 'string' ? child.properties.dataFrameType : undefined;
22
+ const resolved = resolveCollapsedFrameType(frameType, true);
23
+ if (resolved === frameType) {
24
+ continue;
25
+ }
26
+ if (!resolved || resolved === 'normal') {
27
+ delete child.properties.dataFrameType;
28
+ } else {
29
+ child.properties.dataFrameType = resolved;
30
+ }
31
+ }
32
+ root.data = {
33
+ ...root.data,
34
+ focusedLines: 0
35
+ };
36
+ return root;
37
+ }
38
+
39
+ /** A decoded extra-file fallback: the rendered `HastRoot` plus its line counts. */
40
+
41
+ function convertVariantSource(variant, collapseToEmpty = false) {
42
+ const rewrite = nodes => collapseToEmpty ? applyCollapseToEmptyToFallbackHast(nodes) : nodes;
43
+ // Collapse-to-empty empties every painted window, so report `focusedLines: 0` to
44
+ // match the demoted `source` (mirrors `<Pre>`'s `collapseToEmpty ? 0 : ...`).
45
+ const focused = value => collapseToEmpty ? 0 : value;
46
+ let source;
47
+ let extraSource;
48
+ if (variant.source) {
49
+ source = rewrite(fallbackToHast(variant.source));
50
+ }
51
+ if (variant.extraSource) {
52
+ extraSource = {};
53
+ for (const [fName, file] of Object.entries(variant.extraSource)) {
54
+ extraSource[fName] = {
55
+ source: rewrite(fallbackToHast(file.source)),
56
+ totalLines: file.totalLines,
57
+ focusedLines: focused(file.focusedLines),
58
+ collapsible: collapseToEmpty ? true : file.collapsible
59
+ };
60
+ }
61
+ }
62
+ return {
63
+ fileNames: variant.fileNames,
64
+ source,
65
+ totalLines: variant.totalLines,
66
+ focusedLines: focused(variant.focusedLines),
67
+ collapsible: collapseToEmpty ? true : variant.collapsible,
68
+ extraSource
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Hook for `ContentLoading` components to hoist fallback data
74
+ * to `CodeHighlighterClient` for text-dictionary derivation.
75
+ *
76
+ * On the server-rendered path, Code is stripped of `fallback` entries
77
+ * and the data arrives on ContentLoading as `source`/`extraSource` props
78
+ * in compact `FallbackNode[]` format. This hook converts them back to
79
+ * `HastRoot` for rendering and hoists the compact form for dictionaries.
80
+ *
81
+ * On the client-loaded path, `useInitialData` already hoists directly,
82
+ * so this hook simply passes props through.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * function MyContentLoading(props: ContentLoadingProps<{}>) {
87
+ * const { source, extraSource } = useCodeFallback(props);
88
+ * return (
89
+ * <div>
90
+ * {source && hastToJsx(source)}
91
+ * </div>
92
+ * );
93
+ * }
94
+ * ```
95
+ */
96
+ export function useCodeFallback(props) {
97
+ const ctx = React.useContext(CodeHighlighterFallbackContext);
98
+ const {
99
+ setFallbackHasts,
100
+ onHookCalled
101
+ } = ctx || {};
102
+ const variantName = props?.initialVariant;
103
+ const mainFile = props?.initialFilename || props?.fileNames?.[0];
104
+ const source = props?.source;
105
+ const extraSource = props?.extraSource;
106
+ const propsExtraVariants = props?.extraVariants;
107
+ const ctxExtraVariants = ctx?.extraVariants;
108
+
109
+ // Signal to parent that useCodeFallback was called with props.
110
+ // Only fires when props are provided — calling without props is the
111
+ // exact misuse we want to detect. Child effects fire before parent
112
+ // effects, so the flag is set before the parent's validation runs.
113
+ const hasProps = !!props;
114
+ React.useEffect(() => {
115
+ if (hasProps) {
116
+ onHookCalled?.();
117
+ }
118
+ }, [hasProps, onHookCalled]);
119
+
120
+ // Hoist fallback data to CodeHighlighterClient via effect (not during render).
121
+ // Deps use individual fields to avoid re-running when the props object identity changes.
122
+ React.useEffect(() => {
123
+ if (!setFallbackHasts || !variantName) {
124
+ return;
125
+ }
126
+
127
+ // Hoist main variant source/extraSource (compact format). `extraSource` entries
128
+ // are `{ source, totalLines, focusedLines }` objects now, so hoist `.source`.
129
+ if (source || extraSource) {
130
+ const hasts = {};
131
+ if (source && mainFile) {
132
+ hasts[mainFile] = source;
133
+ }
134
+ if (extraSource) {
135
+ for (const [fName, file] of Object.entries(extraSource)) {
136
+ hasts[fName] = file.source;
137
+ }
138
+ }
139
+ if (Object.keys(hasts).length > 0) {
140
+ setFallbackHasts(variantName, hasts);
141
+ }
142
+ }
143
+
144
+ // Hoist extra variant fallbacks
145
+ const allExtraVariants = propsExtraVariants || ctxExtraVariants;
146
+ if (allExtraVariants) {
147
+ for (const [name, variant] of Object.entries(allExtraVariants)) {
148
+ if (variant.source) {
149
+ const hasts = {};
150
+ const evMainFile = variant.fileNames?.[0];
151
+ if (evMainFile && variant.source) {
152
+ hasts[evMainFile] = variant.source;
153
+ }
154
+ if (variant.extraSource) {
155
+ for (const [fName, file] of Object.entries(variant.extraSource)) {
156
+ hasts[fName] = file.source;
157
+ }
158
+ }
159
+ if (Object.keys(hasts).length > 0) {
160
+ setFallbackHasts(name, hasts);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ }, [setFallbackHasts, variantName, mainFile, source, extraSource, propsExtraVariants, ctxExtraVariants]);
166
+ if (!props) {
167
+ return {};
168
+ }
169
+ const collapseToEmpty = props.collapseToEmpty === true;
170
+
171
+ // Resolve extraVariants: prefer props, fall back to context
172
+ const allExtraVariants = propsExtraVariants || ctxExtraVariants;
173
+ let resolvedExtraVariants;
174
+ if (allExtraVariants) {
175
+ resolvedExtraVariants = {};
176
+ for (const [name, variant] of Object.entries(allExtraVariants)) {
177
+ resolvedExtraVariants[name] = convertVariantSource(variant, collapseToEmpty);
178
+ }
179
+ }
180
+ const converted = convertVariantSource(props, collapseToEmpty);
181
+ const {
182
+ totalLines,
183
+ focusedLines,
184
+ collapsible
185
+ } = converted;
186
+ // Build the displayed file's `<code>` once, here, so every ContentLoading paints
187
+ // identical attributes to `<Pre>` (created via `React.createElement` to keep this a
188
+ // `.ts` logic hook). `null` when there's nothing to paint. Extra files/variants
189
+ // carry their own `source` + counts on `extraSource` / `extraVariants` for the
190
+ // consumer to render the same way.
191
+ const code = converted.source ? /*#__PURE__*/React.createElement('code', {
192
+ className: props.language ? `language-${props.language}` : undefined,
193
+ 'data-filename': props.fileNames?.[0],
194
+ 'data-collapsible': collapsible ? '' : undefined,
195
+ 'data-total-lines': totalLines,
196
+ 'data-focused-lines': focusedLines
197
+ }, hastToJsx(converted.source)) : null;
198
+ return {
199
+ ...converted,
200
+ extraVariants: resolvedExtraVariants,
201
+ collapsed: props.fallbackCollapsed,
202
+ code
203
+ };
204
+ }