@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,50 @@
1
+ import type { Position } from "./useEditable.mjs";
2
+ import type { Code, CollapseMap, ControlledCode, Fallbacks, SourceComments, VariantSource } from "../CodeHighlighter/types.mjs";
3
+ import type { FallbackNode } from "../CodeHighlighter/fallbackFormat.mjs";
4
+ /**
5
+ * Converts a `VariantSource` (string or HAST) to a plain string. Injected into
6
+ * {@link toControlledCode} so this engine chunk never statically imports
7
+ * `stringOrHastToString` (and its `hastDecompress` dependency): the always-loaded
8
+ * `useCode` shell already has it (via `useCopyFunctionality`/`Pre`) and passes it
9
+ * in, keeping it counted in the shell instead of hoisted into its own chunk.
10
+ */
11
+ export type StringOrHastToString = (source: VariantSource, fallback?: FallbackNode[]) => string;
12
+ interface ShiftResult {
13
+ comments: SourceComments | undefined;
14
+ collapseMap: CollapseMap | undefined;
15
+ }
16
+ /**
17
+ * Counts the number of lines in a string and records which 1-indexed lines are
18
+ * empty/whitespace-only, in a single pass, without allocating a line array.
19
+ * `emptyLines` is omitted when no blank lines were found to keep the common
20
+ * case allocation-free.
21
+ */
22
+ export declare function analyzeSource(source: string): {
23
+ totalLines: number;
24
+ emptyLines?: number[];
25
+ };
26
+ /**
27
+ * Shifts 1-indexed comment line numbers after a source edit.
28
+ * Accepts a precomputed `lineDelta` (positive = lines added, negative = lines deleted)
29
+ * and the cursor `position` (0-indexed in the new text) to determine which
30
+ * comments move and by how much.
31
+ *
32
+ * When lines are deleted, comments from the deleted range are collapsed
33
+ * onto the edit line and recorded in a collapseMap so they can be restored
34
+ * if the deletion is undone (lines re-added at the same position).
35
+ *
36
+ * Empty/whitespace-only deleted lines are special: since they had no real
37
+ * content that "shifted upward" into editLine, their comments are pushed
38
+ * to editLine + 1 (like `-end` boundary markers) so the highlighted region
39
+ * shrinks instead of shifting onto the previous line.
40
+ */
41
+ export declare function shiftComments(comments: SourceComments | undefined, lineDelta: number, position: Position, existingCollapseMap: CollapseMap | undefined, oldEmptyLines?: number[]): ShiftResult;
42
+ /**
43
+ * Converts Code to ControlledCode, normalizing sources and extraFiles entries.
44
+ * VariantSource can be HAST nodes; ControlledCode requires plain strings.
45
+ * VariantExtraFiles allows plain string entries; ControlledVariantExtraFiles
46
+ * requires `{ source }` objects. Without this normalization, parseControlledCode
47
+ * reads `.source` on a string and gets `undefined`, dropping file content.
48
+ */
49
+ export declare function toControlledCode(code: Code, activeVariantKey: string | undefined, activeFallbacks: Fallbacks | undefined, toString: StringOrHastToString): ControlledCode;
50
+ export {};
@@ -0,0 +1,461 @@
1
+ // The edit-time source-manipulation runtime, split out of `useSourceEditing` so
2
+ // its pure-but-not-tiny logic (line analysis, comment/collapse shifting,
3
+ // controlled-code normalization) loads only when a block is actually edited.
4
+ // `useSourceEditing` is a thin shell that warms this chunk as soon as a block
5
+ // becomes editable and applies it synchronously thereafter (live editing never
6
+ // waits). A read-only block never pulls this chunk.
7
+
8
+ /**
9
+ * Converts a `VariantSource` (string or HAST) to a plain string. Injected into
10
+ * {@link toControlledCode} so this engine chunk never statically imports
11
+ * `stringOrHastToString` (and its `hastDecompress` dependency): the always-loaded
12
+ * `useCode` shell already has it (via `useCopyFunctionality`/`Pre`) and passes it
13
+ * in, keeping it counted in the shell instead of hoisted into its own chunk.
14
+ */
15
+
16
+ /**
17
+ * Counts the number of lines in a string and records which 1-indexed lines are
18
+ * empty/whitespace-only, in a single pass, without allocating a line array.
19
+ * `emptyLines` is omitted when no blank lines were found to keep the common
20
+ * case allocation-free.
21
+ */
22
+ export function analyzeSource(source) {
23
+ let totalLines = 1;
24
+ let emptyLines;
25
+ let lineStart = 0;
26
+ // Ignore a single trailing newline. The live contentEditable always
27
+ // terminates its serialized text with one (`toString`), and the gutter
28
+ // (`starryNightGutter`) plus the caret helpers (`getLineInfo`/`getPosition`)
29
+ // all treat that final newline as a line *terminator*, not as an extra empty
30
+ // line. Counting it here would over-report `totalLines` versus the rendered
31
+ // line elements and inflate the line delta of the first edit by one (which
32
+ // shifts every emphasis comment down a line). A source with no trailing
33
+ // newline and the same source with one therefore report the same line count.
34
+ let len = source.length;
35
+ if (len > 0 && source.charCodeAt(len - 1) === 0x0a /* \n */) {
36
+ len -= 1;
37
+ }
38
+ for (let i = 0; i <= len; i += 1) {
39
+ if (i === len || source.charCodeAt(i) === 0x0a /* \n */) {
40
+ let isEmpty = true;
41
+ for (let j = lineStart; j < i; j += 1) {
42
+ const ch = source.charCodeAt(j);
43
+ // 0x20=space, 0x09=tab, 0x0D=CR, 0x0B=VT, 0x0C=FF
44
+ if (ch !== 0x20 && ch !== 0x09 && ch !== 0x0d && ch !== 0x0b && ch !== 0x0c) {
45
+ isEmpty = false;
46
+ break;
47
+ }
48
+ }
49
+ if (isEmpty) {
50
+ if (!emptyLines) {
51
+ emptyLines = [];
52
+ }
53
+ emptyLines.push(totalLines);
54
+ }
55
+ if (i < len) {
56
+ totalLines += 1;
57
+ lineStart = i + 1;
58
+ }
59
+ }
60
+ }
61
+ return emptyLines ? {
62
+ totalLines,
63
+ emptyLines
64
+ } : {
65
+ totalLines
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Shifts 1-indexed comment line numbers after a source edit.
71
+ * Accepts a precomputed `lineDelta` (positive = lines added, negative = lines deleted)
72
+ * and the cursor `position` (0-indexed in the new text) to determine which
73
+ * comments move and by how much.
74
+ *
75
+ * When lines are deleted, comments from the deleted range are collapsed
76
+ * onto the edit line and recorded in a collapseMap so they can be restored
77
+ * if the deletion is undone (lines re-added at the same position).
78
+ *
79
+ * Empty/whitespace-only deleted lines are special: since they had no real
80
+ * content that "shifted upward" into editLine, their comments are pushed
81
+ * to editLine + 1 (like `-end` boundary markers) so the highlighted region
82
+ * shrinks instead of shifting onto the previous line.
83
+ */
84
+ export function shiftComments(comments, lineDelta, position, existingCollapseMap, oldEmptyLines) {
85
+ const hasComments = comments != null && Object.keys(comments).length > 0;
86
+ const hasCollapsed = existingCollapseMap != null && Object.keys(existingCollapseMap).length > 0;
87
+
88
+ // Nothing to shift and nothing stashed to restore. (When the comment map is
89
+ // empty but the collapseMap holds a fully-deleted frame, we must still run so
90
+ // an undo/expansion can reopen it.)
91
+ if (!hasComments && !hasCollapsed) {
92
+ return {
93
+ comments,
94
+ collapseMap: existingCollapseMap
95
+ };
96
+ }
97
+ if (lineDelta === 0) {
98
+ return {
99
+ comments,
100
+ collapseMap: existingCollapseMap
101
+ };
102
+ }
103
+
104
+ // position.line is 0-indexed in the new text.
105
+ // lineDelta is positive for insertions and negative for deletions.
106
+ // Convert to the 1-indexed line in old text that the cursor was on:
107
+ // For additions (lineDelta > 0), the re-inserted lines belong AFTER the caret
108
+ // (`position.line + 1`) when the caret is the *pre-deletion* position rather
109
+ // than a forward-typing cursor that moved down with the insert:
110
+ // - Undo of a deletion (`position.history === 'undo'`): the saved caret is
111
+ // where the delete happened and never moved, so the lines reappear after
112
+ // it. This covers a single-line merge (extent 0) — which the forward
113
+ // formula would misplace by one line — as well as multi-line deletes.
114
+ // - Re-inserting a multi-line selection (extent > 0): the saved position
115
+ // points to the selection-start where the lines begin.
116
+ // Otherwise (forward typing, or redo of an insert) the cursor is the POST-edit
117
+ // position and moved down by lineDelta, so old line = position.line - lineDelta.
118
+ // For deletions (lineDelta < 0): cursor stayed where it was, old line = position.line.
119
+ // On an undo, reverse the edit at the line the FORWARD edit pivoted on (its
120
+ // post-edit caret, supplied as `historyPivotLine`) rather than this
121
+ // destination caret — they diverge after a selection edit (e.g. Select All
122
+ // deletes from a selection that didn't start at the caret), and the
123
+ // collapseMap that holds the deleted frame is keyed by that forward pivot.
124
+ const pivotLine = position.history === 'undo' && position.historyPivotLine !== undefined ? position.historyPivotLine : position.line;
125
+ const reinsertsAfterCaret = lineDelta > 0 && (position.history === 'undo' || position.extent > 0);
126
+ let editLine = reinsertsAfterCaret ? pivotLine + 1 : pivotLine - Math.max(0, lineDelta) + 1; // 1-indexed
127
+ // A selection delete that started at column 0 removed whole lines from the
128
+ // FIRST line down; the post-edit (or restored) caret lands on the line that
129
+ // shifted up from below, so the true anchor — the last surviving line above
130
+ // the deletion — is one line higher. Without this the deleted first line is
131
+ // treated as surviving, stranding a marker that sits on it (and the undo
132
+ // can't rebuild the frame). Rides through undo via the same flag so the
133
+ // reversal anchors on the same line, keeping the collapseMap keys aligned.
134
+ if (position.deletedFromLineStart) {
135
+ editLine -= 1;
136
+ }
137
+
138
+ // When the deletion reaches the very first line, `editLine` underflows to 0:
139
+ // there is no surviving line ABOVE the deletion to anchor onto. The 1-indexed
140
+ // comment map has no line 0, so collapsed comments and their collapseMap keys
141
+ // must instead anchor on the FIRST SURVIVING line — the one that becomes the
142
+ // new line 1. `editLine` itself stays 0 so the deleted-range partition below
143
+ // still treats the old first line as deleted (not surviving); only the WRITE
144
+ // targets (collapse destination, collapseMap key, restore offsets) use this
145
+ // clamped anchor. Off the top-of-file case `collapseLine === editLine`, so the
146
+ // normal middle/bottom paths are byte-for-byte unchanged.
147
+ const collapseLine = editLine < 1 ? 1 : editLine;
148
+ const shifted = {};
149
+ let collapseMap = existingCollapseMap ? {
150
+ ...existingCollapseMap
151
+ } : {};
152
+ const newCollapsed = [];
153
+
154
+ // Build a list of comment strings to exclude from the edit line after restore.
155
+ // Uses an array (not Set) to correctly handle duplicate comment strings
156
+ // across separate collapsed entries.
157
+ let restoredComments;
158
+ // Boundary `-end`/empty-line markers were also left VISIBLE at editLine+1 when
159
+ // the range first shrank. On an undo that restores them at their true offset we
160
+ // must drop that visible boundary copy (else the marker duplicates and the copy
161
+ // shifts a full delta, landing one line past the original). Collected here and
162
+ // filtered off editLine+1 in the main loop below.
163
+ let restoredBoundaryComments;
164
+ const isUndo = position.history === 'undo';
165
+
166
+ // On expansion, check if we can restore previously collapsed comments
167
+ if (lineDelta > 0 && collapseMap[collapseLine]) {
168
+ const entries = collapseMap[collapseLine];
169
+ const restored = [];
170
+ const remaining = [];
171
+ for (const entry of entries) {
172
+ // Boundary entries (a shrunk range's `-end`/empty-line `-start`) are
173
+ // undo-only memory: they restore the marker EXACTLY on an undo. On a
174
+ // forward re-insert (or redo) the still-visible boundary copy expands the
175
+ // range as before, so the stash is dropped rather than restored — leaving
176
+ // it would re-restore the marker on a later undo of an unrelated edit.
177
+ if (entry.boundary && !isUndo) {
178
+ continue;
179
+ }
180
+ if (entry.offset <= lineDelta) {
181
+ restored.push(entry);
182
+ } else {
183
+ remaining.push(entry);
184
+ }
185
+ }
186
+
187
+ // Place restored comments at their original offsets from the edit line
188
+ restoredComments = [];
189
+ restoredBoundaryComments = [];
190
+ for (const entry of restored) {
191
+ const restoredLine = collapseLine + entry.offset;
192
+ shifted[restoredLine] = [...(shifted[restoredLine] ?? []), ...entry.comments];
193
+ if (entry.boundary) {
194
+ // Filter the visible boundary copy (at editLine+1), not the collapseLine.
195
+ restoredBoundaryComments.push(...entry.comments);
196
+ } else {
197
+ restoredComments.push(...entry.comments);
198
+ }
199
+ }
200
+ if (remaining.length > 0) {
201
+ collapseMap[collapseLine] = remaining;
202
+ } else {
203
+ delete collapseMap[collapseLine];
204
+ }
205
+ }
206
+
207
+ // O(1) lookup against the precomputed empty-line set from the old source.
208
+ const oldEmptyLineSet = oldEmptyLines && oldEmptyLines.length > 0 ? new Set(oldEmptyLines) : undefined;
209
+
210
+ // For a deletion, find range bases that are removed entirely — every line they
211
+ // highlighted is gone — so the frame must disappear (its `-start`, which is in
212
+ // the deleted block, is stashed rather than collapsed onto a surviving line
213
+ // above as a phantom highlight) and an undo can rebuild it.
214
+ //
215
+ // Two shapes qualify. Both require the `-start` to fall inside the deleted block
216
+ // `(editLine, editLine - lineDelta]`:
217
+ // 1. The `-end` is also inside the block (the selection deleted right through
218
+ // it). Both markers are stashed and an undo restores them at their offsets.
219
+ // 2. The `-end` is on `boundaryLine` — the first SURVIVING line just past the
220
+ // block. A range's `-end` is EXCLUSIVE, sitting one line below its last
221
+ // highlighted line, so a selection that removes every highlighted line stops
222
+ // with the caret on that `-end` line, leaving it intact. The range is still
223
+ // empty, so it is fully deleted; the surviving `-end` then shifts up as a
224
+ // lone marker (rendering nothing) and is the undo memory that re-pairs with
225
+ // the restored `-start`.
226
+ // (A range whose `-start` survives OUTSIDE the block only shrinks, so its `-end`
227
+ // keeps the editLine+1 placement below and stays untracked.)
228
+ let fullyDeletedRanges;
229
+ if (lineDelta < 0) {
230
+ const startBases = new Set();
231
+ const endBases = new Set();
232
+ const boundaryLine = editLine - lineDelta + 1;
233
+ for (const [lineStr, commentArr] of Object.entries(comments ?? {})) {
234
+ const line = Number(lineStr);
235
+ const inBlock = line > editLine && line <= editLine - lineDelta;
236
+ if (inBlock) {
237
+ for (const comment of commentArr) {
238
+ if (comment.endsWith('-end')) {
239
+ endBases.add(comment.slice(0, -'-end'.length));
240
+ } else if (comment.endsWith('-start')) {
241
+ startBases.add(comment.slice(0, -'-start'.length));
242
+ }
243
+ }
244
+ } else if (line === boundaryLine) {
245
+ // Only an exclusive `-end` on the boundary closes a fully-deleted range; a
246
+ // `-start` here belongs to a surviving line below and must not be paired.
247
+ for (const comment of commentArr) {
248
+ if (comment.endsWith('-end')) {
249
+ endBases.add(comment.slice(0, -'-end'.length));
250
+ }
251
+ }
252
+ }
253
+ }
254
+ for (const base of startBases) {
255
+ if (endBases.has(base)) {
256
+ (fullyDeletedRanges ??= new Set()).add(base);
257
+ }
258
+ }
259
+ }
260
+ for (const [lineStr, commentArr] of Object.entries(comments ?? {})) {
261
+ const line = Number(lineStr);
262
+ if (line <= editLine) {
263
+ // Before or at the edit line — unchanged.
264
+ // If this is the edit line and we restored comments from it, filter them out.
265
+ let arr = commentArr;
266
+ if (line === editLine && restoredComments) {
267
+ const remaining = [...commentArr];
268
+ for (const c of restoredComments) {
269
+ const idx = remaining.indexOf(c);
270
+ if (idx !== -1) {
271
+ remaining.splice(idx, 1);
272
+ }
273
+ }
274
+ arr = remaining;
275
+ }
276
+ if (arr.length > 0) {
277
+ shifted[line] = [...(shifted[line] ?? []), ...arr];
278
+ }
279
+ } else if (lineDelta < 0 && line <= editLine - lineDelta) {
280
+ // Within the deleted range — collapse comments onto the edit line.
281
+ // Three destinations:
282
+ // - Markers of a FULLY deleted range (both ends in the block): stash in
283
+ // the collapseMap ONLY, so the frame vanishes now and an undo restores
284
+ // both ends at their original offsets.
285
+ // - Surviving range-end ('-end') markers, and regular comments off an
286
+ // empty/whitespace-only deleted line: go to editLine + 1, so the range
287
+ // shrinks rather than expanding onto the line above. Left untracked so
288
+ // they shift normally as the range contracts/expands.
289
+ // - Other regular comments: collapse onto editLine AND track in the
290
+ // collapseMap so a later expansion can restore them at their offset.
291
+ const wasEmptyLine = oldEmptyLineSet?.has(line) ?? false;
292
+ const reopenable = [];
293
+ const collapseHere = [];
294
+ const toBoundary = [];
295
+ for (const comment of commentArr) {
296
+ const isEnd = comment.endsWith('-end');
297
+ let base;
298
+ if (isEnd) {
299
+ base = comment.slice(0, -'-end'.length);
300
+ } else if (comment.endsWith('-start')) {
301
+ base = comment.slice(0, -'-start'.length);
302
+ }
303
+ if (base !== undefined && fullyDeletedRanges?.has(base)) {
304
+ reopenable.push(comment);
305
+ } else if (isEnd || wasEmptyLine) {
306
+ toBoundary.push(comment);
307
+ } else {
308
+ collapseHere.push(comment);
309
+ }
310
+ }
311
+ // Offsets and the regular-collapse destination anchor on `collapseLine`
312
+ // (the first surviving line) so they stay valid at the top of the file,
313
+ // where `editLine` is 0. The boundary target stays `editLine + 1`: in the
314
+ // middle of the file that is the line just BELOW the surviving anchor, and
315
+ // at the top of the file it coincides with `collapseLine` (the new line 1).
316
+ if (reopenable.length > 0) {
317
+ newCollapsed.push({
318
+ offset: line - collapseLine,
319
+ comments: reopenable
320
+ });
321
+ }
322
+ if (collapseHere.length > 0) {
323
+ shifted[collapseLine] = [...(shifted[collapseLine] ?? []), ...collapseHere];
324
+ newCollapsed.push({
325
+ offset: line - collapseLine,
326
+ comments: collapseHere
327
+ });
328
+ }
329
+ if (toBoundary.length > 0) {
330
+ const boundaryTarget = editLine + 1;
331
+ shifted[boundaryTarget] = [...(shifted[boundaryTarget] ?? []), ...toBoundary];
332
+ // Keep the marker VISIBLE at editLine+1 (the live contracted view) AND
333
+ // stash its TRUE offset, flagged `boundary`, so an undo can restore it
334
+ // exactly. A forward re-insert ignores this stash and lets the visible
335
+ // copy expand the range instead (see the restore loop above).
336
+ newCollapsed.push({
337
+ offset: line - collapseLine,
338
+ comments: toBoundary,
339
+ boundary: true
340
+ });
341
+ }
342
+ } else {
343
+ // After the edit — shift.
344
+ let arr = commentArr;
345
+ // At the top of the file the collapse anchor (`collapseLine`) is the new
346
+ // line 1, which sits AFTER the conceptual edit point (`editLine` is 0), so
347
+ // its entry lands in this shifting branch rather than the unchanged one. On
348
+ // an undo we restored its collapsed comments to their true lines already,
349
+ // so drop those copies here before the leftover (a survivor that shifted up
350
+ // during the delete) shifts back down. In the middle of the file
351
+ // `collapseLine === editLine`, which never reaches this branch, so this is
352
+ // inert there.
353
+ if (line === collapseLine && restoredComments) {
354
+ const remaining = [...arr];
355
+ for (const c of restoredComments) {
356
+ const idx = remaining.indexOf(c);
357
+ if (idx !== -1) {
358
+ remaining.splice(idx, 1);
359
+ }
360
+ }
361
+ arr = remaining;
362
+ }
363
+ // On an undo that restored a shrunk range's boundary marker at its true
364
+ // offset, drop the still-visible boundary copy (at editLine+1) so it
365
+ // doesn't duplicate the marker and shift a full delta past the original.
366
+ if (line === editLine + 1 && restoredBoundaryComments) {
367
+ const remaining = [...arr];
368
+ for (const c of restoredBoundaryComments) {
369
+ const idx = remaining.indexOf(c);
370
+ if (idx !== -1) {
371
+ remaining.splice(idx, 1);
372
+ }
373
+ }
374
+ arr = remaining;
375
+ }
376
+ if (arr.length > 0) {
377
+ const newLine = line + lineDelta;
378
+ shifted[newLine] = [...(shifted[newLine] ?? []), ...arr];
379
+ }
380
+ }
381
+ }
382
+
383
+ // Also shift existing collapse map entries that are after the collapse anchor.
384
+ // Entries AT the anchor (e.g. a partially restored stash) stay put so further
385
+ // expansion can keep restoring from them; later ones move with the edit. Keyed
386
+ // on `collapseLine` (not `editLine`) so a stash held at the new line 1 isn't
387
+ // mistakenly shifted at the top of the file, where `editLine` is 0.
388
+ const shiftedCollapseMap = {};
389
+ for (const [lineStr, entries] of Object.entries(collapseMap)) {
390
+ const line = Number(lineStr);
391
+ if (line <= collapseLine) {
392
+ shiftedCollapseMap[line] = entries;
393
+ } else {
394
+ shiftedCollapseMap[line + lineDelta] = entries;
395
+ }
396
+ }
397
+ collapseMap = shiftedCollapseMap;
398
+ if (newCollapsed.length > 0) {
399
+ collapseMap[collapseLine] = [...(collapseMap[collapseLine] ?? []), ...newCollapsed];
400
+ }
401
+ const finalCollapseMap = Object.keys(collapseMap).length > 0 ? collapseMap : undefined;
402
+ return {
403
+ comments: shifted,
404
+ collapseMap: finalCollapseMap
405
+ };
406
+ }
407
+
408
+ /**
409
+ * Converts Code to ControlledCode, normalizing sources and extraFiles entries.
410
+ * VariantSource can be HAST nodes; ControlledCode requires plain strings.
411
+ * VariantExtraFiles allows plain string entries; ControlledVariantExtraFiles
412
+ * requires `{ source }` objects. Without this normalization, parseControlledCode
413
+ * reads `.source` on a string and gets `undefined`, dropping file content.
414
+ */
415
+ export function toControlledCode(code, activeVariantKey, activeFallbacks, toString) {
416
+ const result = {};
417
+ for (const [key, variant] of Object.entries(code)) {
418
+ if (!variant || typeof variant === 'string') {
419
+ continue;
420
+ }
421
+ // The per-file `fallback` is the DEFLATE dictionary for a `hastCompressed`
422
+ // source. It rides on the `VariantCode` in the no-`ContentLoading` path; on
423
+ // the `ContentLoading` path the active variant's fallback is stripped off
424
+ // `Code` and lives in `context.fallbacks` (`activeFallbacks`) instead — so
425
+ // prefer that for the active variant, falling back to the variant's field.
426
+ const variantFallbacks = key === activeVariantKey ? activeFallbacks : undefined;
427
+ const mainFallback = (variant.fileName ? variantFallbacks?.[variant.fileName] : undefined) ?? variant.fallback;
428
+ const source = variant.source != null ? toString(variant.source, mainFallback) : variant.source;
429
+ let extraFiles;
430
+ if (variant.extraFiles) {
431
+ extraFiles = {};
432
+ for (const [fileName, entry] of Object.entries(variant.extraFiles)) {
433
+ if (typeof entry === 'string') {
434
+ extraFiles[fileName] = {
435
+ source: entry,
436
+ ...analyzeSource(entry)
437
+ };
438
+ } else {
439
+ const entryFallback = variantFallbacks?.[fileName] ?? entry.fallback;
440
+ const extraSource = entry.source != null ? toString(entry.source, entryFallback) : null;
441
+ extraFiles[fileName] = {
442
+ source: extraSource,
443
+ ...(entry.comments ? {
444
+ comments: entry.comments
445
+ } : {}),
446
+ ...(extraSource != null ? analyzeSource(extraSource) : {})
447
+ };
448
+ }
449
+ }
450
+ }
451
+ result[key] = {
452
+ ...variant,
453
+ source,
454
+ ...(source != null ? analyzeSource(source) : {}),
455
+ ...(extraFiles ? {
456
+ extraFiles
457
+ } : {})
458
+ };
459
+ }
460
+ return result;
461
+ }
@@ -0,0 +1,39 @@
1
+ import { type TransformRuntimeDeps } from "../pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs";
2
+ import type { VariantSource, VariantCode, Transforms, SourceComments, Fallbacks } from "../CodeHighlighter/types.mjs";
3
+ import type { FallbackNode } from "../CodeHighlighter/fallbackFormat.mjs";
4
+ import type { TransformedFiles } from "./useCodeUtils.mjs";
5
+ export type { TransformRuntimeDeps };
6
+ /**
7
+ * Function signature of {@link createTransformedFiles}. Used by the
8
+ * `transformEngineLoader` accessor and `useTransformManagement` so they can
9
+ * reference the engine without statically importing this (heavy) module.
10
+ *
11
+ * `deps` (the decoder + frame-fallback helper) is injected by the caller (the
12
+ * `useCode` shell already loads them) so this engine chunk doesn't statically
13
+ * depend on them.
14
+ */
15
+ export type CreateTransformedFiles = (selectedVariant: VariantCode | null, selectedTransform: string | null, deps: TransformRuntimeDeps, fallbacks?: Fallbacks) => TransformedFiles | undefined;
16
+ /**
17
+ * Pure helper function to apply transform to a source file.
18
+ *
19
+ * @param source - The source code to transform
20
+ * @param fileName - The filename for the source
21
+ * @param transforms - Available transforms for this source
22
+ * @param selectedTransform - The transform to apply
23
+ * @param comments - Optional 1-indexed comment map for the source. Returned
24
+ * shifted onto the transformed source's line numbering.
25
+ * @returns Object with transformed source, name, and shifted comments
26
+ */
27
+ export declare function applyTransformToSource(source: VariantSource, fileName: string, transforms: Transforms | undefined, selectedTransform: string, deps: TransformRuntimeDeps, comments?: SourceComments, fallback?: FallbackNode[]): {
28
+ transformedSource: VariantSource;
29
+ transformedName: string;
30
+ transformedComments?: SourceComments;
31
+ };
32
+ /**
33
+ * Pure function to create transformed files from a variant and selected transform.
34
+ *
35
+ * @param selectedVariant - The currently selected variant
36
+ * @param selectedTransform - The transform to apply
37
+ * @returns Object with transformed files and filename mapping, or undefined if no transform
38
+ */
39
+ export declare function createTransformedFiles(selectedVariant: VariantCode | null, selectedTransform: string | null, deps: TransformRuntimeDeps, fallbacks?: Fallbacks): TransformedFiles | undefined;