@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.
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 +85 -5
  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
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gates client-side highlighting on grammar readiness. Under `CodeProviderLazy`,
3
+ * grammars load per-language and on demand, so a block must wait until the
4
+ * grammars for its scopes are registered — otherwise `parseSource` would fall
5
+ * back to plain text. Returning `false` keeps the block showing its fallback
6
+ * until the grammars land (then it highlights), instead of flashing the cold
7
+ * plain-text output.
8
+ *
9
+ * Readiness is derived synchronously from the shared registry each render, so it
10
+ * is `true` immediately when the scopes are already registered (warm — the
11
+ * speculative preload primed them, a sibling block loaded them, or an eager
12
+ * `CodeProvider` bundled them) and a warm block never holds back its highlight.
13
+ * When cold, it kicks off the load and re-renders once ready.
14
+ *
15
+ * @param scopes - Grammar scopes the block needs (should be memoized by the caller)
16
+ * @param enabled - Whether the block will highlight client-side at all
17
+ */
18
+ export declare function useGrammarsReady(scopes: string[], enabled: boolean): boolean;
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { areGrammarsRegistered, ensureGrammars } from "../pipeline/parseSource/grammarCache.mjs";
5
+
6
+ /**
7
+ * Gates client-side highlighting on grammar readiness. Under `CodeProviderLazy`,
8
+ * grammars load per-language and on demand, so a block must wait until the
9
+ * grammars for its scopes are registered — otherwise `parseSource` would fall
10
+ * back to plain text. Returning `false` keeps the block showing its fallback
11
+ * until the grammars land (then it highlights), instead of flashing the cold
12
+ * plain-text output.
13
+ *
14
+ * Readiness is derived synchronously from the shared registry each render, so it
15
+ * is `true` immediately when the scopes are already registered (warm — the
16
+ * speculative preload primed them, a sibling block loaded them, or an eager
17
+ * `CodeProvider` bundled them) and a warm block never holds back its highlight.
18
+ * When cold, it kicks off the load and re-renders once ready.
19
+ *
20
+ * @param scopes - Grammar scopes the block needs (should be memoized by the caller)
21
+ * @param enabled - Whether the block will highlight client-side at all
22
+ */
23
+ export function useGrammarsReady(scopes, enabled) {
24
+ const [, forceUpdate] = React.useReducer(count => count + 1, 0);
25
+
26
+ // Nothing to wait for when disabled or when every scope is already registered.
27
+ const ready = !enabled || areGrammarsRegistered(scopes);
28
+ React.useEffect(() => {
29
+ if (ready) {
30
+ return undefined;
31
+ }
32
+ let cancelled = false;
33
+ // Fails open: a load error still flips ready so the block highlights what it
34
+ // can (and renders plain text for any scope that failed to register).
35
+ ensureGrammars(scopes).finally(() => {
36
+ if (!cancelled) {
37
+ forceUpdate();
38
+ }
39
+ });
40
+ return () => {
41
+ cancelled = true;
42
+ };
43
+ }, [ready, scopes]);
44
+ return ready;
45
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * On first render, kick off the heavy loaders a code block is about to need, so
3
+ * the work is already in flight before the content mounts and awaits it. The
4
+ * detection is cheap and synchronous (props + manifest); the loaders are called
5
+ * in a mount effect, so this never blocks first paint.
6
+ *
7
+ * Calling an accessor is instant under an eager `CodeProvider` and starts a
8
+ * deduped fetch under `CodeProviderLazy` (the same promise the eventual consumer
9
+ * resolves), so this is purely a head start - no extra work and no duplicate
10
+ * fetch. The signals are deliberately accurate (a fully-precomputed block sets
11
+ * neither) so a code-free or precomputed page never prefetches a chunk it won't
12
+ * use.
13
+ */
14
+ export declare function useSpeculativeCodePreload({
15
+ needsData,
16
+ hasTransforms
17
+ }: {
18
+ /**
19
+ * The block will fetch code (no complete precomputed/controlled code). Also
20
+ * covers the multi-variant case where switching will load a not-yet-present
21
+ * variant - so a fully-precomputed multi-variant block correctly sets `false`.
22
+ */
23
+ needsData: boolean;
24
+ /** Transforms will be computed client-side (manifest declares them, not yet highlighted). */
25
+ hasTransforms: boolean;
26
+ }): void;
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { useCodeContext } from "../CodeProvider/CodeContext.mjs";
5
+
6
+ /**
7
+ * On first render, kick off the heavy loaders a code block is about to need, so
8
+ * the work is already in flight before the content mounts and awaits it. The
9
+ * detection is cheap and synchronous (props + manifest); the loaders are called
10
+ * in a mount effect, so this never blocks first paint.
11
+ *
12
+ * Calling an accessor is instant under an eager `CodeProvider` and starts a
13
+ * deduped fetch under `CodeProviderLazy` (the same promise the eventual consumer
14
+ * resolves), so this is purely a head start - no extra work and no duplicate
15
+ * fetch. The signals are deliberately accurate (a fully-precomputed block sets
16
+ * neither) so a code-free or precomputed page never prefetches a chunk it won't
17
+ * use.
18
+ */
19
+ export function useSpeculativeCodePreload({
20
+ needsData,
21
+ hasTransforms
22
+ }) {
23
+ const {
24
+ loadCodeFallbackLoader,
25
+ loadIsomorphicCodeVariantLoader,
26
+ computeHastDeltasLoader
27
+ } = useCodeContext();
28
+ React.useEffect(() => {
29
+ // Best-effort head start; swallow rejections (the real consumer surfaces any
30
+ // load error). `?.()?.catch` no-ops cleanly when no provider supplies the
31
+ // accessor.
32
+ if (needsData) {
33
+ loadCodeFallbackLoader?.()?.catch(() => {});
34
+ loadIsomorphicCodeVariantLoader?.()?.catch(() => {});
35
+ }
36
+ if (hasTransforms) {
37
+ computeHastDeltasLoader?.()?.catch(() => {});
38
+ }
39
+ }, [needsData, hasTransforms, loadCodeFallbackLoader, loadIsomorphicCodeVariantLoader, computeHastDeltasLoader]);
40
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Warms ALL the live-editing dependencies a block needs — the editing engine
3
+ * (contentEditable + source-editing), the per-language grammars, the emphasis
4
+ * enhancer, and the off-main-thread worker — so they are in flight before the
5
+ * user edits. Mirrors {@link useSpeculativeCodePreload}: detection is cheap and
6
+ * synchronous, the work runs in a mount/activation effect (never blocking first
7
+ * paint), and each fetch is deduped page-wide with the eventual consumer.
8
+ *
9
+ * Timing follows `editActivation`:
10
+ * - `'eager'` (default): warms on mount once the block is `enabled` (editable).
11
+ * - `'interaction'`: warms only once the block is `activated` — `useEditable`
12
+ * fires `onActivate` on first engagement (hover / focus / click), and
13
+ * `CodeHighlighter` flips `activated`. This is the single moment that kicks off
14
+ * every editing dependency, rather than each loading on its own trigger.
15
+ *
16
+ * A read-only block sets `enabled = false` and warms nothing.
17
+ */
18
+ export declare function useSpeculativeEditingPreload({
19
+ enabled,
20
+ editActivation,
21
+ activated,
22
+ scopes
23
+ }: {
24
+ enabled: boolean;
25
+ editActivation?: 'eager' | 'interaction';
26
+ /** Whether an `'interaction'` block has engaged yet (ignored when `'eager'`). */
27
+ activated?: boolean;
28
+ /**
29
+ * Grammar scopes the editable block uses, so its grammars (main thread) and the
30
+ * worker can be warmed for live re-highlighting (should be memoized by the caller).
31
+ */
32
+ scopes?: string[];
33
+ }): void;
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { useCodeContext } from "../CodeProvider/CodeContext.mjs";
5
+ import { preloadCodeEmphasis } from "../pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs";
6
+ import { ensureGrammars } from "../pipeline/parseSource/grammarCache.mjs";
7
+
8
+ /**
9
+ * Warms ALL the live-editing dependencies a block needs — the editing engine
10
+ * (contentEditable + source-editing), the per-language grammars, the emphasis
11
+ * enhancer, and the off-main-thread worker — so they are in flight before the
12
+ * user edits. Mirrors {@link useSpeculativeCodePreload}: detection is cheap and
13
+ * synchronous, the work runs in a mount/activation effect (never blocking first
14
+ * paint), and each fetch is deduped page-wide with the eventual consumer.
15
+ *
16
+ * Timing follows `editActivation`:
17
+ * - `'eager'` (default): warms on mount once the block is `enabled` (editable).
18
+ * - `'interaction'`: warms only once the block is `activated` — `useEditable`
19
+ * fires `onActivate` on first engagement (hover / focus / click), and
20
+ * `CodeHighlighter` flips `activated`. This is the single moment that kicks off
21
+ * every editing dependency, rather than each loading on its own trigger.
22
+ *
23
+ * A read-only block sets `enabled = false` and warms nothing.
24
+ */
25
+ export function useSpeculativeEditingPreload({
26
+ enabled,
27
+ editActivation,
28
+ activated = false,
29
+ scopes
30
+ }) {
31
+ const {
32
+ editingEngineLoader,
33
+ ensureParseSourceWorker
34
+ } = useCodeContext();
35
+
36
+ // In `'interaction'` mode, wait for engagement; otherwise warm on mount.
37
+ const shouldWarm = enabled && ((editActivation ?? 'eager') !== 'interaction' || activated);
38
+ React.useEffect(() => {
39
+ // Best-effort head start; swallow rejections (the real consumers surface any
40
+ // load error). `?.()?.catch` no-ops cleanly when no provider supplies the
41
+ // accessor.
42
+ if (!shouldWarm) {
43
+ return;
44
+ }
45
+ editingEngineLoader?.()?.catch(() => {});
46
+ // Warm the emphasis enhancer too, so the first live-edit re-enhancement
47
+ // (a synchronous render-path) runs without a flash under `CodeProviderLazy`.
48
+ preloadCodeEmphasis().catch(() => {});
49
+ if (scopes && scopes.length > 0) {
50
+ // Main-thread grammars for the edited file...
51
+ ensureGrammars(scopes).catch(() => {});
52
+ // ...and the (lazily-created) worker with the same grammars, so
53
+ // off-main-thread highlighting is ready before the first keystroke. No-op
54
+ // without a worker (no provider, SSR, or no `Worker`).
55
+ ensureParseSourceWorker?.(scopes);
56
+ }
57
+ }, [shouldWarm, editingEngineLoader, ensureParseSourceWorker, scopes]);
58
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * On first render, start loading the grammar chunks a block is about to need for
3
+ * client-side highlighting, so they are in flight before `useCode` mounts and
4
+ * the parse runs. Mirrors {@link useSpeculativeCodePreload} /
5
+ * {@link useSpeculativeUseCodePreload}: detection is cheap and synchronous
6
+ * (`detectGrammarScopes` reads only metadata), the load runs in a mount effect
7
+ * (so it never blocks first paint), and `ensureGrammars` dedupes with the
8
+ * eventual consumer (`useGrammarsReady`) and is a no-op when warm.
9
+ *
10
+ * The signal is deliberately accurate so a block needs only its own languages: a
11
+ * fully-precomputed read-only block (which renders its highlighted HAST and
12
+ * never calls `parseSource`) sets `enabled = false` and loads no grammar at all,
13
+ * and a `tsx`+`css` block loads only those two grammars instead of all ten.
14
+ */
15
+ export declare function useSpeculativeGrammarPreload({
16
+ scopes,
17
+ enabled
18
+ }: {
19
+ /** Grammar scopes the block needs (should be memoized by the caller). */
20
+ scopes: string[];
21
+ /** Whether the block will highlight client-side (or live-edit). */
22
+ enabled: boolean;
23
+ }): void;
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { ensureGrammars } from "../pipeline/parseSource/grammarCache.mjs";
5
+
6
+ /**
7
+ * On first render, start loading the grammar chunks a block is about to need for
8
+ * client-side highlighting, so they are in flight before `useCode` mounts and
9
+ * the parse runs. Mirrors {@link useSpeculativeCodePreload} /
10
+ * {@link useSpeculativeUseCodePreload}: detection is cheap and synchronous
11
+ * (`detectGrammarScopes` reads only metadata), the load runs in a mount effect
12
+ * (so it never blocks first paint), and `ensureGrammars` dedupes with the
13
+ * eventual consumer (`useGrammarsReady`) and is a no-op when warm.
14
+ *
15
+ * The signal is deliberately accurate so a block needs only its own languages: a
16
+ * fully-precomputed read-only block (which renders its highlighted HAST and
17
+ * never calls `parseSource`) sets `enabled = false` and loads no grammar at all,
18
+ * and a `tsx`+`css` block loads only those two grammars instead of all ten.
19
+ */
20
+ export function useSpeculativeGrammarPreload({
21
+ scopes,
22
+ enabled
23
+ }) {
24
+ React.useEffect(() => {
25
+ // Best-effort head start; swallow rejections (the consumer surfaces any real
26
+ // load error, and `parseSource` degrades to plain text). No-op when warm.
27
+ if (enabled && scopes.length > 0) {
28
+ ensureGrammars(scopes).catch(() => {});
29
+ }
30
+ }, [enabled, scopes]);
31
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * On first render, kick off the heavy `useCode` chunks a block is about to need,
3
+ * so they are already in flight before the content subtree mounts and
4
+ * `useCode`/`useTransformManagement` awaits them. Mirrors
5
+ * {@link useSpeculativeCodePreload} / {@link useSpeculativeEditingPreload}: the
6
+ * detection is cheap and synchronous, the loaders run in a mount effect (so they
7
+ * never block first paint), and each fetch is deduped page-wide with the eventual
8
+ * consumer (the speculative preload and the consumer resolve the same promise).
9
+ *
10
+ * Where `CodeContent` is itself lazily loaded, this effect fires on the same
11
+ * commit as the content `import()`, so the chunks download concurrently rather
12
+ * than waterfalling (content → discover need → fetch).
13
+ *
14
+ * Signals are deliberately accurate so a block that needs nothing prefetches
15
+ * nothing: a block with no transforms never pulls the transform engine (the
16
+ * `jsondiffpatch` applier).
17
+ */
18
+ export declare function useSpeculativeUseCodePreload({
19
+ hasTransforms
20
+ }: {
21
+ hasTransforms: boolean;
22
+ }): void;
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { useCodeContext } from "../CodeProvider/CodeContext.mjs";
5
+ import { preloadTransformEngine } from "../useCode/transformEngineCache.mjs";
6
+
7
+ /**
8
+ * On first render, kick off the heavy `useCode` chunks a block is about to need,
9
+ * so they are already in flight before the content subtree mounts and
10
+ * `useCode`/`useTransformManagement` awaits them. Mirrors
11
+ * {@link useSpeculativeCodePreload} / {@link useSpeculativeEditingPreload}: the
12
+ * detection is cheap and synchronous, the loaders run in a mount effect (so they
13
+ * never block first paint), and each fetch is deduped page-wide with the eventual
14
+ * consumer (the speculative preload and the consumer resolve the same promise).
15
+ *
16
+ * Where `CodeContent` is itself lazily loaded, this effect fires on the same
17
+ * commit as the content `import()`, so the chunks download concurrently rather
18
+ * than waterfalling (content → discover need → fetch).
19
+ *
20
+ * Signals are deliberately accurate so a block that needs nothing prefetches
21
+ * nothing: a block with no transforms never pulls the transform engine (the
22
+ * `jsondiffpatch` applier).
23
+ */
24
+ export function useSpeculativeUseCodePreload({
25
+ hasTransforms
26
+ }) {
27
+ const {
28
+ transformEngineLoader
29
+ } = useCodeContext();
30
+ React.useEffect(() => {
31
+ // Prime the shared transform-engine cache (not just kick off the fetch), so
32
+ // the first transform-bearing block reads it synchronously and never flashes
33
+ // un-transformed files. `preloadTransformEngine` shares the provider's loader
34
+ // (page-wide dedup) and fails open. Runs in parallel with the lazy content
35
+ // import, so the cache is typically warm before `useTransformManagement` first
36
+ // renders. Passing the context loader keeps it deduped with the consumer.
37
+ if (hasTransforms) {
38
+ preloadTransformEngine(transformEngineLoader).catch(() => {});
39
+ }
40
+ }, [hasTransforms, transformEngineLoader]);
41
+ }
@@ -2,6 +2,8 @@ import * as React from 'react';
2
2
  import type { LoadCodeMeta, LoadSource, LoadVariantMeta, ParseSource, SourceTransformers, SourceEnhancers, Code, ControlledCode, LoadFallbackCodeOptions, LoadVariantOptions, Externals, VariantCode } from "../CodeHighlighter/types.mjs";
3
3
  import type { ParseSourceAsync } from "./createParseSourceWorkerClient.mjs";
4
4
  import type { PreParsedCacheEntry } from "../CodeHighlighter/CodeHighlighterContext.mjs";
5
+ import type { EditingEngineLoader } from "../useCode/editingEngineCache.mjs";
6
+ import type { CreateTransformedFiles } from "../useCode/TransformEngine.mjs";
5
7
  export type LoadFallbackCodeFn = (url: string, initialVariant: string, loaded: Code | undefined, options?: LoadFallbackCodeOptions) => Promise<{
6
8
  code: Code;
7
9
  processedGlobalsCode?: Array<Code>;
@@ -14,7 +16,10 @@ export type LoadVariantFn = (url: string | undefined, variantName: string, varia
14
16
  export type ParseCodeFn = (code: Code, parseSource: ParseSource) => Code;
15
17
  export type ParseControlledCodeFn = (controlledCode: ControlledCode, parseSource: ParseSource, preParsedCache?: Map<string, PreParsedCacheEntry>) => Code;
16
18
  export type ComputeHastDeltasFn = (parsedCode: Code, parseSource: ParseSource) => Promise<Code>;
17
- export type GetAvailableTransformsFn = (parsedCode: Code | undefined, variantName: string) => string[];
19
+ export type LoadFallbackCodeLoader = () => Promise<LoadFallbackCodeFn>;
20
+ export type LoadVariantLoader = () => Promise<LoadVariantFn>;
21
+ export type ComputeHastDeltasLoader = () => Promise<ComputeHastDeltasFn>;
22
+ export type TransformEngineLoader = () => Promise<CreateTransformedFiles>;
18
23
  /**
19
24
  * Context interface for code processing functions.
20
25
  * Provides heavy functions via context that can't be serialized across the server-client boundary.
@@ -32,7 +37,11 @@ export interface CodeContext {
32
37
  parseSourceAsync?: ParseSourceAsync;
33
38
  /** Source transformers for code transformation (e.g., TypeScript to JavaScript) */
34
39
  sourceTransformers?: SourceTransformers;
35
- /** Source enhancers for modifying parsed HAST */
40
+ /**
41
+ * Explicit source enhancers for modifying parsed HAST. When omitted, the
42
+ * provider supplies the default emphasis enhancer (`enhanceCodeEmphasis`)
43
+ * eagerly, since it powers the synchronous live-editing re-enhancement path.
44
+ */
36
45
  sourceEnhancers?: SourceEnhancers;
37
46
  /** Function to load raw source code and dependencies */
38
47
  loadSource?: LoadSource;
@@ -40,18 +49,44 @@ export interface CodeContext {
40
49
  loadVariantMeta?: LoadVariantMeta;
41
50
  /** Function to load code metadata from a URL */
42
51
  loadCodeMeta?: LoadCodeMeta;
43
- /** Heavy function: Loads fallback code with all variants and files */
44
- loadCodeFallback?: LoadFallbackCodeFn;
45
- /** Heavy function: Loads a specific code variant with its dependencies */
46
- loadIsomorphicCodeVariant?: LoadVariantFn;
47
- /** Heavy function: Parses code strings into HAST nodes */
52
+ /** Heavy function: Parses code strings into HAST nodes (kept eager - small, on the sync parse path) */
48
53
  parseCode?: ParseCodeFn;
49
- /** Heavy function: Parses controlled code for editable demos */
54
+ /** Heavy function: Parses controlled code for editable demos (kept eager - sync parse path) */
50
55
  parseControlledCode?: ParseControlledCodeFn;
51
- /** Heavy function: Computes HAST deltas for code transformations */
52
- computeHastDeltas?: ComputeHastDeltasFn;
53
- /** Heavy function: Gets available transform keys for a variant */
54
- getAvailableTransforms?: GetAvailableTransformsFn;
56
+ /**
57
+ * Lazily creates the live-editing worker (off-main-thread highlighter) and
58
+ * registers the given grammar scopes into it, so a read-only page never spins
59
+ * up the worker. Called by `CodeHighlighter` on the editable signal with the
60
+ * block's scopes. No-op during SSR or where `Worker` is unavailable.
61
+ */
62
+ ensureParseSourceWorker?: (scopes: string[]) => void;
63
+ /** Lazily loads the fallback-code loader (transitively pulls the variant loader). */
64
+ loadCodeFallbackLoader?: LoadFallbackCodeLoader;
65
+ /** Lazily loads the variant loader. */
66
+ loadIsomorphicCodeVariantLoader?: LoadVariantLoader;
67
+ /** Lazily loads the transform-delta computer (pulls jsondiffpatch). */
68
+ computeHastDeltasLoader?: ComputeHastDeltasLoader;
69
+ /**
70
+ * Lazily loads the client-side transform applier (`createTransformedFiles` —
71
+ * the `applyCodeTransform` path, which pulls `jsondiffpatch`). `useTransformManagement`
72
+ * consumes it (warm-cached so transform swaps stay synchronous once loaded);
73
+ * `CodeHighlighter` preloads it when it detects a block has transforms, so a
74
+ * block without transforms never pulls this chunk.
75
+ */
76
+ transformEngineLoader?: TransformEngineLoader;
77
+ /**
78
+ * Lazily loads the live-editing engine module — `createEditableEngine` (the
79
+ * contentEditable setup + keyboard/paste/caret handlers, pulls `react-dom`)
80
+ * AND the edit-time source manipulation (`analyzeSource`/`shiftComments`/
81
+ * `toControlledCode`), co-located in one chunk. The eager `CodeProvider`
82
+ * resolves a bundled module instantly; `CodeProviderLazy` resolves a dynamic
83
+ * `import()`. `useEditable` (via `Pre`) reads `createEditableEngine` and
84
+ * `useSourceEditing` reads the source-editing fns from the same module;
85
+ * `CodeHighlighter` preloads it when it detects an editable
86
+ * `CodeControllerContext`, unless the block opts out with
87
+ * `editActivation: 'interaction'`.
88
+ */
89
+ editingEngineLoader?: EditingEngineLoader;
55
90
  }
56
91
  export declare const CodeContext: React.Context<CodeContext>;
57
92
  export declare const useCodeContext: () => CodeContext;
@@ -4,6 +4,13 @@ import * as React from 'react';
4
4
 
5
5
  // Type definitions for the heavy functions we're moving to context
6
6
 
7
+ // Lazy accessors for the heaviest functions. Each returns the function via a
8
+ // dynamic import (deduped per page by `PreloadProvider`), so the function's
9
+ // module - and its heavy transitive deps (e.g. jsondiffpatch) - stays out of
10
+ // the initial client bundle. The accessor's *presence* (always defined when a
11
+ // CodeProvider is mounted) is the synchronously-known "is provisioned" signal
12
+ // that gates loading, replacing the previous "is the resolved fn present" check.
13
+
7
14
  /**
8
15
  * Context interface for code processing functions.
9
16
  * Provides heavy functions via context that can't be serialized across the server-client boundary.
@@ -5,8 +5,10 @@ import type { LoadCodeMeta, LoadSource, LoadVariantMeta, SourceEnhancers } from
5
5
  * Designed for cases where you need to render code blocks or demos based on
6
6
  * client-side state or dynamic content loading.
7
7
  *
8
- * Implements the Props Context Layering pattern by providing heavy functions
9
- * via context that can't be serialized across the server-client boundary.
8
+ * The heavy functions are bundled eagerly here, so they resolve instantly with
9
+ * no fetch - best when a layout will definitely render code. To keep them out of
10
+ * the initial bundle (loaded on demand, deduped across the page), use
11
+ * `CodeProviderLazy` instead.
10
12
  */
11
13
  export declare function CodeProvider({
12
14
  children,
@@ -2,126 +2,64 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import { CodeContext } from "./CodeContext.mjs";
5
- import { enhanceCodeEmphasis } from "../pipeline/enhanceCodeEmphasis/index.mjs";
5
+ import { useCodeProviderValue } from "./useCodeProviderValue.mjs";
6
+ // Heavy functions: statically imported (eager). They ship in this provider's
7
+ // chunk so its accessors resolve instantly with no fetch. Use `CodeProviderLazy`
8
+ // to keep them out of the initial bundle instead. (The default emphasis enhancer
9
+ // is eager in both providers - see useCodeProviderValue.)
6
10
  import { createParseSource } from "../pipeline/parseSource/parseSource.mjs";
7
- // Import the heavy functions
8
11
  import { loadCodeFallback } from "../pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs";
9
12
  import { loadIsomorphicCodeVariant } from "../pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs";
10
- import { parseCode } from "../pipeline/loadIsomorphicCodeVariant/parseCode.mjs";
11
- import { parseControlledCode } from "../CodeHighlighter/parseControlledCode.mjs";
12
- import { computeHastDeltas, getAvailableTransforms } from "../pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs";
13
+ import { computeHastDeltas } from "../pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs";
14
+ import * as EditingEngine from "../useCode/EditingEngine.mjs";
15
+ import { createTransformedFiles } from "../useCode/TransformEngine.mjs";
16
+ // Eager: the emphasis enhancer is bundled so the synchronous editing
17
+ // re-enhancement path has it with no fetch (zero-latency invariant).
18
+ import { enhanceCodeEmphasis } from "../pipeline/enhanceCodeEmphasis/index.mjs";
19
+
20
+ // Eager: the Starry Night engine is bundled, so the parser is created synchronously.
13
21
  import { jsx as _jsx } from "react/jsx-runtime";
14
- const DEFAULT_SOURCE_ENHANCERS = [enhanceCodeEmphasis];
22
+ const createSourceParserEager = () => createParseSource();
23
+
24
+ // Eager accessors: the function is already bundled, so the accessor resolves
25
+ // instantly. Module-level so the references are stable across renders.
26
+ const loadCodeFallbackLoaderEager = () => Promise.resolve(loadCodeFallback);
27
+ const loadVariantLoaderEager = () => Promise.resolve(loadIsomorphicCodeVariant);
28
+ const computeHastDeltasLoaderEager = () => Promise.resolve(computeHastDeltas);
29
+ const editingEngineLoaderEager = () => Promise.resolve(EditingEngine);
30
+ const transformEngineLoaderEager = () => Promise.resolve(createTransformedFiles);
15
31
 
16
32
  /**
17
33
  * Provides client-side functions for fetching source code and highlighting it.
18
34
  * Designed for cases where you need to render code blocks or demos based on
19
35
  * client-side state or dynamic content loading.
20
36
  *
21
- * Implements the Props Context Layering pattern by providing heavy functions
22
- * via context that can't be serialized across the server-client boundary.
37
+ * The heavy functions are bundled eagerly here, so they resolve instantly with
38
+ * no fetch - best when a layout will definitely render code. To keep them out of
39
+ * the initial bundle (loaded on demand, deduped across the page), use
40
+ * `CodeProviderLazy` instead.
23
41
  */
24
42
  export function CodeProvider({
25
43
  children,
26
44
  loadCodeMeta,
27
45
  loadVariantMeta,
28
46
  loadSource,
29
- sourceEnhancers = DEFAULT_SOURCE_ENHANCERS
47
+ sourceEnhancers
30
48
  }) {
31
- const [parseSource, setParseSource] = React.useState(undefined);
32
- const [parseSourceAsync, setParseSourceAsync] = React.useState(undefined);
33
- const sourceParser = React.useMemo(() => {
34
- // Only initialize Starry Night in the browser, not during SSR
35
- if (typeof window === 'undefined') {
36
- return Promise.resolve(() => {
37
- throw new Error('parseSource not available during SSR');
38
- });
39
- }
40
- return createParseSource();
41
- }, []);
42
- React.useEffect(() => {
43
- // Update the sync version when available
44
- sourceParser.then(parseSourceFn => setParseSource(() => parseSourceFn));
45
- }, [sourceParser]);
46
-
47
- // Worker for off-main-thread parsing during live editing. Lazily created
48
- // once per provider, browser-only, and torn down on unmount. The worker
49
- // client module is dynamically imported so the `new URL('./parseSourceWorker.ts',
50
- // import.meta.url)` call (which bundlers resolve to a separate worker chunk)
51
- // never runs in SSR bundles.
52
- const workerRef = React.useRef(null);
53
- React.useEffect(() => {
54
- if (typeof window === 'undefined' || typeof Worker === 'undefined') {
55
- return undefined;
56
- }
57
- let cancelled = false;
58
- let client;
59
- Promise.all([import("./createParseSourceWorkerClient.mjs"),
60
- // Share the same (lazy) grammar chunk that `createParseSource()` uses,
61
- // so the heavy TextMate JSON is fetched at most once per page load and
62
- // then `postMessage`d into the worker.
63
- import("../pipeline/parseSource/grammars.mjs")]).then(([{
64
- createParseSourceWorkerClient
65
- }, {
66
- grammars
67
- }]) => {
68
- if (cancelled) {
69
- return;
70
- }
71
- // `createParseSourceWorkerClient()` throws synchronously on browsers
72
- // that expose `Worker` but reject module workers (the typeof gate
73
- // above can't detect that). Treat the failure as "no async parser
74
- // available" so consumers transparently fall back to the synchronous
75
- // highlighter instead of leaving an unhandled rejection on the page.
76
- try {
77
- client = createParseSourceWorkerClient();
78
- } catch {
79
- return;
80
- }
81
- workerRef.current = client;
82
- client.init(grammars).then(() => {
83
- if (cancelled) {
84
- return;
85
- }
86
- setParseSourceAsync(() => client.parseSourceAsync);
87
- }).catch(() => {
88
- // Worker-side init failure (e.g. `createStarryNight` rejected).
89
- // Tear down so we don't leak the worker, and leave
90
- // `parseSourceAsync` undefined so consumers fall back to sync.
91
- if (workerRef.current === client) {
92
- workerRef.current = null;
93
- }
94
- client?.terminate();
95
- client = undefined;
96
- });
97
- }).catch(() => {
98
- // Dynamic-import failure (network error, missing chunk). Same
99
- // fallback policy: stay on the main-thread highlighter.
100
- });
101
- return () => {
102
- cancelled = true;
103
- workerRef.current = null;
104
- client?.terminate();
105
- };
106
- }, []);
107
- const context = React.useMemo(() => ({
108
- sourceParser,
109
- parseSource,
110
- // Sync version when available
111
- parseSourceAsync,
112
- // Worker-backed async version when available
113
- loadSource,
114
- loadVariantMeta,
49
+ const heavy = React.useMemo(() => ({
50
+ loadCodeFallbackLoader: loadCodeFallbackLoaderEager,
51
+ loadIsomorphicCodeVariantLoader: loadVariantLoaderEager,
52
+ computeHastDeltasLoader: computeHastDeltasLoaderEager,
53
+ editingEngineLoader: editingEngineLoaderEager,
54
+ transformEngineLoader: transformEngineLoaderEager,
55
+ defaultSourceEnhancers: [enhanceCodeEmphasis]
56
+ }), []);
57
+ const context = useCodeProviderValue({
115
58
  loadCodeMeta,
116
- sourceEnhancers,
117
- // Provide the heavy functions
118
- loadCodeFallback,
119
- loadIsomorphicCodeVariant,
120
- parseCode,
121
- parseControlledCode,
122
- computeHastDeltas,
123
- getAvailableTransforms
124
- }), [sourceParser, parseSource, parseSourceAsync, loadSource, loadVariantMeta, loadCodeMeta, sourceEnhancers]);
59
+ loadVariantMeta,
60
+ loadSource,
61
+ sourceEnhancers
62
+ }, heavy, createSourceParserEager);
125
63
  return /*#__PURE__*/_jsx(CodeContext.Provider, {
126
64
  value: context,
127
65
  children: children