@pierre/diffs 1.5.2 → 1.6.0

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 (359) hide show
  1. package/README.md +4 -3
  2. package/dist/components/CodeView.d.ts +3 -2
  3. package/dist/components/CodeView.d.ts.map +1 -1
  4. package/dist/components/CodeView.js +24 -19
  5. package/dist/components/CodeView.js.map +1 -1
  6. package/dist/components/File.d.ts +31 -9
  7. package/dist/components/File.d.ts.map +1 -1
  8. package/dist/components/File.js +176 -90
  9. package/dist/components/File.js.map +1 -1
  10. package/dist/components/FileDiff.d.ts +32 -9
  11. package/dist/components/FileDiff.d.ts.map +1 -1
  12. package/dist/components/FileDiff.js +225 -131
  13. package/dist/components/FileDiff.js.map +1 -1
  14. package/dist/components/FileStream.d.ts +6 -4
  15. package/dist/components/FileStream.d.ts.map +1 -1
  16. package/dist/components/FileStream.js +49 -36
  17. package/dist/components/FileStream.js.map +1 -1
  18. package/dist/components/UnresolvedFile.d.ts +14 -4
  19. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  20. package/dist/components/UnresolvedFile.js +35 -16
  21. package/dist/components/UnresolvedFile.js.map +1 -1
  22. package/dist/components/VirtualizedFile.d.ts +3 -2
  23. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  24. package/dist/components/VirtualizedFile.js +28 -20
  25. package/dist/components/VirtualizedFile.js.map +1 -1
  26. package/dist/components/VirtualizedFileDiff.d.ts +3 -2
  27. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  28. package/dist/components/VirtualizedFileDiff.js +31 -24
  29. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  30. package/dist/constants.d.ts +4 -2
  31. package/dist/constants.d.ts.map +1 -1
  32. package/dist/constants.js +3 -1
  33. package/dist/constants.js.map +1 -1
  34. package/dist/editor/editor.d.ts +2 -1
  35. package/dist/editor/editor.d.ts.map +1 -1
  36. package/dist/editor/editor.js +5 -1
  37. package/dist/editor/editor.js.map +1 -1
  38. package/dist/editor/platform.d.ts +1 -1
  39. package/dist/editor/platform.js +5 -4
  40. package/dist/editor/platform.js.map +1 -1
  41. package/dist/editor/selection.d.ts +2 -2
  42. package/dist/editor/selection.d.ts.map +1 -1
  43. package/dist/editor/selection.js +31 -6
  44. package/dist/editor/selection.js.map +1 -1
  45. package/dist/editor/tokenizer.d.ts +6 -4
  46. package/dist/editor/tokenizer.d.ts.map +1 -1
  47. package/dist/editor/tokenizer.js +25 -470
  48. package/dist/editor/tokenizer.js.map +1 -1
  49. package/dist/highlighter/DiffsEditorTokenizer.d.ts +16 -0
  50. package/dist/highlighter/DiffsEditorTokenizer.d.ts.map +1 -0
  51. package/dist/highlighter/DiffsEditorTokenizer.js +0 -0
  52. package/dist/highlighter/DiffsHighlighter.d.ts +41 -0
  53. package/dist/highlighter/DiffsHighlighter.d.ts.map +1 -0
  54. package/dist/highlighter/DiffsHighlighter.js +39 -0
  55. package/dist/highlighter/DiffsHighlighter.js.map +1 -0
  56. package/dist/highlighter/backends/highlights.d.ts +26 -0
  57. package/dist/highlighter/backends/highlights.d.ts.map +1 -0
  58. package/dist/highlighter/backends/highlights.js +71 -0
  59. package/dist/highlighter/backends/highlights.js.map +1 -0
  60. package/dist/highlighter/backends/shiki.d.ts +27 -0
  61. package/dist/highlighter/backends/shiki.d.ts.map +1 -0
  62. package/dist/highlighter/backends/shiki.js +107 -0
  63. package/dist/highlighter/backends/shiki.js.map +1 -0
  64. package/dist/highlighter/highlighterType.d.ts +13 -0
  65. package/dist/highlighter/highlighterType.d.ts.map +1 -0
  66. package/dist/highlighter/highlighterType.js +32 -0
  67. package/dist/highlighter/highlighterType.js.map +1 -0
  68. package/dist/highlighter/highlights-editor.d.ts +24 -0
  69. package/dist/highlighter/highlights-editor.d.ts.map +1 -0
  70. package/dist/highlighter/highlights-editor.js +166 -0
  71. package/dist/highlighter/highlights-editor.js.map +1 -0
  72. package/dist/highlighter/highlights-stream.d.ts +20 -0
  73. package/dist/highlighter/highlights-stream.d.ts.map +1 -0
  74. package/dist/highlighter/highlights-stream.js +93 -0
  75. package/dist/highlighter/highlights-stream.js.map +1 -0
  76. package/dist/highlighter/languages/areLanguagesAttached.d.ts +2 -1
  77. package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
  78. package/dist/highlighter/languages/areLanguagesAttached.js +4 -6
  79. package/dist/highlighter/languages/areLanguagesAttached.js.map +1 -1
  80. package/dist/highlighter/languages/attachResolvedLanguages.d.ts +6 -1
  81. package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
  82. package/dist/highlighter/languages/attachResolvedLanguages.js +6 -11
  83. package/dist/highlighter/languages/attachResolvedLanguages.js.map +1 -1
  84. package/dist/highlighter/languages/constants.d.ts +1 -1
  85. package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -1
  86. package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -1
  87. package/dist/highlighter/languages/resolveLanguage.d.ts +1 -1
  88. package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
  89. package/dist/highlighter/languages/resolveLanguage.js +19 -16
  90. package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
  91. package/dist/highlighter/languages/resolveLanguages.d.ts +1 -1
  92. package/dist/highlighter/shared_highlighter.d.ts +24 -9
  93. package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
  94. package/dist/highlighter/shared_highlighter.js +59 -47
  95. package/dist/highlighter/shared_highlighter.js.map +1 -1
  96. package/dist/highlighter/shiki-editor.d.ts +25 -0
  97. package/dist/highlighter/shiki-editor.d.ts.map +1 -0
  98. package/dist/highlighter/shiki-editor.js +483 -0
  99. package/dist/highlighter/shiki-editor.js.map +1 -0
  100. package/dist/highlighter/shiki-stream.d.ts +20 -0
  101. package/dist/highlighter/shiki-stream.d.ts.map +1 -0
  102. package/dist/highlighter/shiki-stream.js +60 -0
  103. package/dist/highlighter/shiki-stream.js.map +1 -0
  104. package/dist/highlighter/stream-tokenizer.d.ts +40 -0
  105. package/dist/highlighter/stream-tokenizer.d.ts.map +1 -0
  106. package/dist/highlighter/stream-tokenizer.js +70 -0
  107. package/dist/highlighter/stream-tokenizer.js.map +1 -0
  108. package/dist/highlighter/themes/areThemesAttached.d.ts +3 -2
  109. package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
  110. package/dist/highlighter/themes/areThemesAttached.js +5 -4
  111. package/dist/highlighter/themes/areThemesAttached.js.map +1 -1
  112. package/dist/highlighter/themes/attachResolvedThemes.d.ts +5 -2
  113. package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
  114. package/dist/highlighter/themes/attachResolvedThemes.js +4 -16
  115. package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
  116. package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts +3 -1
  117. package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
  118. package/dist/highlighter/themes/cleanUpResolvedThemes.js +8 -5
  119. package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
  120. package/dist/highlighter/themes/createCSSVariablesTheme.d.ts +7 -0
  121. package/dist/highlighter/themes/createCSSVariablesTheme.d.ts.map +1 -0
  122. package/dist/highlighter/themes/createCSSVariablesTheme.js +89 -0
  123. package/dist/highlighter/themes/createCSSVariablesTheme.js.map +1 -0
  124. package/dist/highlighter/themes/createCachedLoader.d.ts +5 -0
  125. package/dist/highlighter/themes/createCachedLoader.d.ts.map +1 -0
  126. package/dist/highlighter/themes/createCachedLoader.js +15 -0
  127. package/dist/highlighter/themes/createCachedLoader.js.map +1 -0
  128. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +3 -2
  129. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
  130. package/dist/highlighter/themes/getResolvedOrResolveTheme.js +4 -4
  131. package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
  132. package/dist/highlighter/themes/getResolvedThemes.d.ts +3 -2
  133. package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
  134. package/dist/highlighter/themes/getResolvedThemes.js +4 -3
  135. package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
  136. package/dist/highlighter/themes/hasResolvedThemes.d.ts +2 -2
  137. package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
  138. package/dist/highlighter/themes/hasResolvedThemes.js +4 -3
  139. package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
  140. package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
  141. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +3 -3
  142. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js.map +1 -1
  143. package/dist/highlighter/themes/registerCustomTheme.d.ts +9 -4
  144. package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
  145. package/dist/highlighter/themes/registerCustomTheme.js +8 -16
  146. package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
  147. package/dist/highlighter/themes/resolveTheme.d.ts +3 -2
  148. package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
  149. package/dist/highlighter/themes/resolveTheme.js +4 -7
  150. package/dist/highlighter/themes/resolveTheme.js.map +1 -1
  151. package/dist/highlighter/themes/resolveThemes.d.ts +3 -2
  152. package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
  153. package/dist/highlighter/themes/resolveThemes.js +4 -7
  154. package/dist/highlighter/themes/resolveThemes.js.map +1 -1
  155. package/dist/highlighter/themes/themeResolver.d.ts +10 -4
  156. package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
  157. package/dist/highlighter/themes/themeResolver.js +141 -2
  158. package/dist/highlighter/themes/themeResolver.js.map +1 -1
  159. package/dist/highlighter/themes/types.d.ts +23 -0
  160. package/dist/highlighter/themes/types.d.ts.map +1 -0
  161. package/dist/highlighter/themes/types.js +0 -0
  162. package/dist/highlighter/tokenizer-types.d.ts +35 -0
  163. package/dist/highlighter/tokenizer-types.d.ts.map +1 -0
  164. package/dist/highlighter/tokenizer-types.js +0 -0
  165. package/dist/highlighter/types.d.ts +55 -0
  166. package/dist/highlighter/types.d.ts.map +1 -0
  167. package/dist/highlighter/types.js +0 -0
  168. package/dist/index.d.ts +22 -13
  169. package/dist/index.js +21 -18
  170. package/dist/managers/InteractionManager.d.ts.map +1 -1
  171. package/dist/managers/InteractionManager.js +2 -2
  172. package/dist/managers/InteractionManager.js.map +1 -1
  173. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +9 -1
  174. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
  175. package/dist/react/CodeView.d.ts +4 -3
  176. package/dist/react/CodeView.d.ts.map +1 -1
  177. package/dist/react/CodeView.js +47 -38
  178. package/dist/react/CodeView.js.map +1 -1
  179. package/dist/react/File.js +3 -3
  180. package/dist/react/File.js.map +1 -1
  181. package/dist/react/FileDiff.js +3 -3
  182. package/dist/react/FileDiff.js.map +1 -1
  183. package/dist/react/MultiFileDiff.js +2 -2
  184. package/dist/react/MultiFileDiff.js.map +1 -1
  185. package/dist/react/PatchDiff.js +3 -3
  186. package/dist/react/PatchDiff.js.map +1 -1
  187. package/dist/react/UnresolvedFile.js +2 -2
  188. package/dist/react/UnresolvedFile.js.map +1 -1
  189. package/dist/react/index.d.ts +9 -4
  190. package/dist/react/types.d.ts +4 -2
  191. package/dist/react/types.d.ts.map +1 -1
  192. package/dist/react/utils/renderDiffChildren.js +1 -1
  193. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  194. package/dist/react/utils/renderFileChildren.js +1 -1
  195. package/dist/react/utils/renderFileChildren.js.map +1 -1
  196. package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
  197. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  198. package/dist/react/utils/useFileDiffInstance.js +29 -24
  199. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  200. package/dist/react/utils/useFileInstance.d.ts +2 -0
  201. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  202. package/dist/react/utils/useFileInstance.js +38 -28
  203. package/dist/react/utils/useFileInstance.js.map +1 -1
  204. package/dist/react/utils/useForceUpdate.d.ts +5 -0
  205. package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
  206. package/dist/react/utils/useForceUpdate.js +27 -0
  207. package/dist/react/utils/useForceUpdate.js.map +1 -0
  208. package/dist/react/utils/useNextRenderData.d.ts +9 -0
  209. package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
  210. package/dist/react/utils/useNextRenderData.js +9 -0
  211. package/dist/react/utils/useNextRenderData.js.map +1 -0
  212. package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
  213. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  214. package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
  215. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  216. package/dist/renderers/DiffHunksRenderer.d.ts +4 -2
  217. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  218. package/dist/renderers/DiffHunksRenderer.js +82 -43
  219. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  220. package/dist/renderers/FileRenderer.d.ts +6 -2
  221. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  222. package/dist/renderers/FileRenderer.js +77 -43
  223. package/dist/renderers/FileRenderer.js.map +1 -1
  224. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  225. package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
  226. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  227. package/dist/shiki-stream/index.d.ts +3 -3
  228. package/dist/shiki-stream/index.js +1 -2
  229. package/dist/shiki-stream/stream.d.ts +4 -4
  230. package/dist/shiki-stream/stream.d.ts.map +1 -1
  231. package/dist/shiki-stream/stream.js +20 -9
  232. package/dist/shiki-stream/stream.js.map +1 -1
  233. package/dist/shiki-stream/types.d.ts +7 -38
  234. package/dist/shiki-stream/types.d.ts.map +1 -1
  235. package/dist/ssr/index.d.ts +7 -2
  236. package/dist/ssr/renderHTML.js +2 -2
  237. package/dist/ssr/renderHTML.js.map +1 -1
  238. package/dist/style.js +1 -1
  239. package/dist/style.js.map +1 -1
  240. package/dist/types.d.ts +20 -11
  241. package/dist/types.d.ts.map +1 -1
  242. package/dist/utils/canUseWASM.d.ts +13 -0
  243. package/dist/utils/canUseWASM.d.ts.map +1 -0
  244. package/dist/utils/canUseWASM.js +59 -0
  245. package/dist/utils/canUseWASM.js.map +1 -0
  246. package/dist/utils/createSpanNodeFromToken.d.ts +3 -2
  247. package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
  248. package/dist/utils/createSpanNodeFromToken.js +4 -5
  249. package/dist/utils/createSpanNodeFromToken.js.map +1 -1
  250. package/dist/utils/cssWrappers.d.ts.map +1 -1
  251. package/dist/utils/cssWrappers.js +12 -0
  252. package/dist/utils/cssWrappers.js.map +1 -1
  253. package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
  254. package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
  255. package/dist/utils/getCodeViewItemRenderData.js +19 -0
  256. package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
  257. package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
  258. package/dist/utils/getHighlighterOptions.js +3 -2
  259. package/dist/utils/getHighlighterOptions.js.map +1 -1
  260. package/dist/utils/getHighlighterThemeStyles.d.ts +2 -1
  261. package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
  262. package/dist/utils/getHighlighterThemeStyles.js +13 -3
  263. package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
  264. package/dist/utils/getTokenOptions.d.ts +7 -0
  265. package/dist/utils/getTokenOptions.d.ts.map +1 -0
  266. package/dist/utils/getTokenOptions.js +16 -0
  267. package/dist/utils/getTokenOptions.js.map +1 -0
  268. package/dist/utils/hastToHtml.d.ts +10 -0
  269. package/dist/utils/hastToHtml.d.ts.map +1 -0
  270. package/dist/utils/hastToHtml.js +125 -0
  271. package/dist/utils/hastToHtml.js.map +1 -0
  272. package/dist/utils/hydratePartialDiff.js +4 -0
  273. package/dist/utils/hydratePartialDiff.js.map +1 -1
  274. package/dist/utils/parseDiffDecorations.d.ts +2 -1
  275. package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
  276. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  277. package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
  278. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  279. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  280. package/dist/utils/parsePatchFiles.js +24 -4
  281. package/dist/utils/parsePatchFiles.js.map +1 -1
  282. package/dist/utils/renderDiffWithHighlighter.d.ts +3 -2
  283. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  284. package/dist/utils/renderDiffWithHighlighter.js +33 -48
  285. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  286. package/dist/utils/renderFileWithHighlighter.d.ts +3 -2
  287. package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
  288. package/dist/utils/renderFileWithHighlighter.js +10 -26
  289. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  290. package/dist/utils/renderTokenLines.d.ts +22 -0
  291. package/dist/utils/renderTokenLines.d.ts.map +1 -0
  292. package/dist/utils/renderTokenLines.js +250 -0
  293. package/dist/utils/renderTokenLines.js.map +1 -0
  294. package/dist/utils/resolvePreferredHighlighter.d.ts +13 -0
  295. package/dist/utils/resolvePreferredHighlighter.d.ts.map +1 -0
  296. package/dist/utils/resolvePreferredHighlighter.js +11 -0
  297. package/dist/utils/resolvePreferredHighlighter.js.map +1 -0
  298. package/dist/utils/resolveRegion.js +20 -10
  299. package/dist/utils/resolveRegion.js.map +1 -1
  300. package/dist/utils/setDeferredArrayItem.d.ts +5 -0
  301. package/dist/utils/setDeferredArrayItem.d.ts.map +1 -0
  302. package/dist/utils/setDeferredArrayItem.js +39 -0
  303. package/dist/utils/setDeferredArrayItem.js.map +1 -0
  304. package/dist/utils/tokenStyle.d.ts +11 -0
  305. package/dist/utils/tokenStyle.d.ts.map +1 -0
  306. package/dist/utils/tokenStyle.js +32 -0
  307. package/dist/utils/tokenStyle.js.map +1 -0
  308. package/dist/utils/tokensToHtml.d.ts +11 -0
  309. package/dist/utils/tokensToHtml.d.ts.map +1 -0
  310. package/dist/utils/tokensToHtml.js +48 -0
  311. package/dist/utils/tokensToHtml.js.map +1 -0
  312. package/dist/utils/updateDiffHunks.d.ts +2 -2
  313. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  314. package/dist/utils/updateDiffHunks.js +7 -3
  315. package/dist/utils/updateDiffHunks.js.map +1 -1
  316. package/dist/utils/wrapTokenFragments.js.map +1 -1
  317. package/dist/worker/WorkerPoolManager.d.ts +14 -2
  318. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  319. package/dist/worker/WorkerPoolManager.js +155 -67
  320. package/dist/worker/WorkerPoolManager.js.map +1 -1
  321. package/dist/worker/hastLinesTransport.d.ts +14 -0
  322. package/dist/worker/hastLinesTransport.d.ts.map +1 -0
  323. package/dist/worker/hastLinesTransport.js +156 -0
  324. package/dist/worker/hastLinesTransport.js.map +1 -0
  325. package/dist/worker/highlights-CpZm9DAR.js +317 -0
  326. package/dist/worker/highlights-CpZm9DAR.js.map +1 -0
  327. package/dist/worker/index.d.ts +1 -1
  328. package/dist/worker/shiki-Ci4cdHsM.js +697 -0
  329. package/dist/worker/shiki-Ci4cdHsM.js.map +1 -0
  330. package/dist/worker/stream-tokenizer-DK9xp5M5.js +427 -0
  331. package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
  332. package/dist/worker/types.d.ts +16 -3
  333. package/dist/worker/types.d.ts.map +1 -1
  334. package/dist/worker/worker-portable.js +41 -13337
  335. package/dist/worker/worker-portable.js.map +1 -1
  336. package/dist/worker/worker.js +681 -349
  337. package/dist/worker/worker.js.map +1 -1
  338. package/dist/worker/workerMessage.d.ts +24 -0
  339. package/dist/worker/workerMessage.d.ts.map +1 -0
  340. package/dist/worker/workerMessage.js +0 -0
  341. package/package.json +5 -3
  342. package/dist/highlighter/themes/constants.d.ts +0 -5
  343. package/dist/highlighter/themes/constants.d.ts.map +0 -1
  344. package/dist/highlighter/themes/constants.js +0 -6
  345. package/dist/highlighter/themes/constants.js.map +0 -1
  346. package/dist/highlighter/themes/themeResolution.d.ts +0 -7
  347. package/dist/highlighter/themes/themeResolution.d.ts.map +0 -1
  348. package/dist/highlighter/themes/themeResolution.js +0 -21
  349. package/dist/highlighter/themes/themeResolution.js.map +0 -1
  350. package/dist/shiki-stream/tokenizer.d.ts +0 -23
  351. package/dist/shiki-stream/tokenizer.d.ts.map +0 -1
  352. package/dist/shiki-stream/tokenizer.js +0 -72
  353. package/dist/shiki-stream/tokenizer.js.map +0 -1
  354. package/dist/utils/createTransformerWithState.d.ts +0 -12
  355. package/dist/utils/createTransformerWithState.d.ts.map +0 -1
  356. package/dist/utils/createTransformerWithState.js +0 -89
  357. package/dist/utils/createTransformerWithState.js.map +0 -1
  358. package/dist/worker/wasm-B9ZqxnKj.js +0 -8
  359. package/dist/worker/wasm-B9ZqxnKj.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { Element, ElementContent } from "../node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.js";
2
- import { BaseCodeOptions, DiffsHighlighter, FileContents, FileHeaderRenderMode, HighlightedToken, LineAnnotation, RenderFileOptions, RenderRange, ThemedFileResult } from "../types.js";
2
+ import { DiffsHighlighter } from "../highlighter/DiffsHighlighter.js";
3
+ import { BaseCodeOptions, FileContents, FileHeaderRenderMode, HighlightedToken, LineAnnotation, RenderFileOptions, RenderRange, ThemedFileResult } from "../types.js";
3
4
  import { TextDocument } from "../editor/textDocument.js";
4
5
  import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
5
6
  import "../worker/index.js";
@@ -27,7 +28,6 @@ declare class FileRenderer<LAnnotation = undefined> {
27
28
  private onRenderUpdate?;
28
29
  private workerManager?;
29
30
  readonly __id: string;
30
- private highlighter;
31
31
  private file;
32
32
  private renderCache;
33
33
  private pendingHighlightResult;
@@ -36,6 +36,7 @@ declare class FileRenderer<LAnnotation = undefined> {
36
36
  private lineCache;
37
37
  private pendingStructuralRows;
38
38
  private textDocumentCache;
39
+ private ownedRows;
39
40
  private editSessionActive;
40
41
  get fileCache(): FileContents | undefined;
41
42
  constructor(options?: FileRendererOptions, annotationSlotName?: (annotation: LineAnnotation<LAnnotation>) => string, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);
@@ -64,6 +65,8 @@ declare class FileRenderer<LAnnotation = undefined> {
64
65
  recycle(): void;
65
66
  clearRenderCache(): void;
66
67
  hydrate(file: FileContents): void;
68
+ private getHighlightWorkerManager;
69
+ private cacheHighlightResult;
67
70
  private getLocalHighlightTheme;
68
71
  getEffectiveCodeOptions(): Pick<BaseCodeOptions, 'theme' | 'tokenizeMaxLineLength'>;
69
72
  private getRenderOptions;
@@ -78,6 +81,7 @@ declare class FileRenderer<LAnnotation = undefined> {
78
81
  getLineCount(file: FileContents): number;
79
82
  updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean): void;
80
83
  applyDocumentChange(textDocument: TextDocument<'file', LAnnotation>): void;
84
+ private ownRow;
81
85
  renderFile(file?: FileContents | undefined, renderRange?: RenderRange): FileRenderResult | undefined;
82
86
  asyncRender(file: FileContents, renderRange?: RenderRange): Promise<FileRenderResult>;
83
87
  private asyncHighlight;
@@ -1 +1 @@
1
- {"version":3,"file":"FileRenderer.d.ts","names":[],"sources":["../../src/renderers/FileRenderer.ts"],"mappings":";;;;;;UAiFiB;EACf,MAAM;EACN,WAAW;EACX,YAAY;EACZ,QAAQ;EACR,WAAW;EACX;EACA;EACA;EACA;EACA;EACA;EACA;;UAkBe,4BAA4B;EAC3C,mBAAmB;;cAKR,aAAa;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,qBACR,sBACN,YAAY,eAAe,yBAErB,8CACA,gBAAgB;EAGnB,WAAW,SAAS;EAIpB,aAAa,SAAS,QAAQ;EAI9B,mBACL,iBAAiB,eAAe;EAU3B;;;;;;;EAaA,iBACL,MAAM,cACN,eAAe;;;;;;;EA2EV,eAAe,cAAc;;;;EAwB7B;EAQA;EAkBA;EAMA,QAAQ,MAAM;UA0Cb;UAWA;UAUA;EAQD,2BAA2B,KAChC;UAeM;;;;;;EAuCD,qBAAqB,MAAM,eAAe;UAyBzC;EA+BD,qBAAqB,MAAM;EAgB3B,aAAa,MAAM;EAKnB,kBACL,YAAY,YAAY,MAAM,oBAC9B,6BACA;EAmFK,oBACL,cAAc,qBAAqB;UA2G7B;EAKD,WACL,OAAM,0BACN,cAAa,cACZ;EA8IG,YACJ,MAAM,cACN,cAAa,cACZ,QAAQ;UASG;UAiCN;UAcA;UA+FA;EASD,eAAe,QAAQ;EAIvB,cACL,QAAQ,kBACR,WAAU,mBACT;EAWI,cAAc,QAAQ,mBAAmB;EAWzC,kBACL,UAAU,kBACV;EAcK,yBAAyB,QAAQ;EAYjC,mBACL,MAAM,cACN,QAAQ,kBACR,SAAS,mBACT;UAQM;UAqCA;UAgBA;UAoBA;EAaD,iBAAiB;UAIhB;UAIA"}
@@ -1,12 +1,13 @@
1
1
  import { DEFAULT_RENDER_RANGE, DEFAULT_THEMES } from "../constants.js";
2
- import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
3
- import { getThemes } from "../utils/getThemes.js";
2
+ import { HighlighterDisposedError } from "../highlighter/highlighterType.js";
4
3
  import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
5
4
  import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
5
+ import { resolvePreferredHighlighter } from "../utils/resolvePreferredHighlighter.js";
6
6
  import { areFileTargetsEqual } from "../utils/areFileTargetsEqual.js";
7
7
  import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
8
8
  import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
9
- import { hasResolvedThemes } from "../highlighter/themes/hasResolvedThemes.js";
9
+ import { hastToHtml } from "../utils/hastToHtml.js";
10
+ import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
10
11
  import { applyLineTextWithNewline } from "../utils/applyLineTextWithNewline.js";
11
12
  import { areFileRenderOptionsEqual } from "../utils/areFileRenderOptionsEqual.js";
12
13
  import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
@@ -21,7 +22,6 @@ import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
21
22
  import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
22
23
  import { isFilePlainText } from "../utils/isFilePlainText.js";
23
24
  import { renderFileWithHighlighter } from "../utils/renderFileWithHighlighter.js";
24
- import { toHtml } from "hast-util-to-html";
25
25
  //#region src/renderers/FileRenderer.ts
26
26
  function isLineCacheForFile(lineCache, file) {
27
27
  return file.cacheKey == null ? lineCache.file === file && lineCache.sourceContents === file.contents : lineCache.cacheKey === file.cacheKey;
@@ -33,7 +33,6 @@ var FileRenderer = class {
33
33
  onRenderUpdate;
34
34
  workerManager;
35
35
  __id = `file-renderer:${++instanceId}`;
36
- highlighter;
37
36
  file;
38
37
  renderCache;
39
38
  pendingHighlightResult;
@@ -42,6 +41,7 @@ var FileRenderer = class {
42
41
  lineCache;
43
42
  pendingStructuralRows;
44
43
  textDocumentCache = /* @__PURE__ */ new WeakMap();
44
+ ownedRows = /* @__PURE__ */ new WeakSet();
45
45
  editSessionActive = false;
46
46
  get fileCache() {
47
47
  return this.renderCache?.file;
@@ -51,7 +51,6 @@ var FileRenderer = class {
51
51
  this.annotationSlotName = annotationSlotName;
52
52
  this.onRenderUpdate = onRenderUpdate;
53
53
  this.workerManager = workerManager;
54
- if (workerManager?.isWorkingPool() !== true) this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES) ? getHighlighterIfLoaded() : void 0;
55
54
  }
56
55
  setOptions(options) {
57
56
  this.options = options;
@@ -158,7 +157,6 @@ var FileRenderer = class {
158
157
  this.lineCache = void 0;
159
158
  this.textDocumentCache = /* @__PURE__ */ new WeakMap();
160
159
  }
161
- this.highlighter = void 0;
162
160
  this.workerManager?.cleanUpTasks(this);
163
161
  this.file = void 0;
164
162
  }
@@ -181,13 +179,24 @@ var FileRenderer = class {
181
179
  result: massiveFile ? void 0 : cache?.result,
182
180
  renderRange: void 0
183
181
  };
184
- if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
185
- if (this.renderCache.result == null && !massiveFile) this.workerManager.highlightFileAST(this, file);
186
- } else if (this.highlighter == null) {
182
+ const workerManager = this.getHighlightWorkerManager(file);
183
+ if (workerManager != null) {
184
+ if (this.renderCache.result == null && !massiveFile) workerManager.highlightFileAST(this, file);
185
+ } else if (getHighlighterIfLoaded({ theme: this.getLocalHighlightTheme() }) == null) {
187
186
  this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);
188
- this.initializeHighlighter();
187
+ this.initializeHighlighter().catch((error) => {
188
+ if (!(error instanceof HighlighterDisposedError)) this.onHighlightError(error);
189
+ });
189
190
  }
190
191
  }
192
+ getHighlightWorkerManager(file) {
193
+ const { editSessionActive, workerManager } = this;
194
+ return !editSessionActive && workerManager?.isWorkingPool() === true && !workerManager.shouldHighlightOnMainThread(file) ? workerManager : void 0;
195
+ }
196
+ cacheHighlightResult(file, renderResult) {
197
+ const { editSessionActive, workerManager } = this;
198
+ if (!editSessionActive && workerManager?.isWorkingPool() === true) workerManager.setFileResultCache(file.cacheKey, renderResult);
199
+ }
191
200
  getLocalHighlightTheme() {
192
201
  return this.workerManager?.getFileRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
193
202
  }
@@ -247,10 +256,10 @@ var FileRenderer = class {
247
256
  canRenderFile(file, options, forcePlainText) {
248
257
  const { renderCache } = this;
249
258
  if (renderCache == null || areFileTargetsEqual(renderCache.file, file)) return true;
250
- if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true || this.highlighter != null && areThemesAttached(options.theme);
259
+ if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true && !this.workerManager.shouldHighlightOnMainThread(file) || getHighlighterIfLoaded({ theme: options.theme }) != null;
251
260
  if (renderCache.result == null && renderCache.hydrated !== true) return true;
252
- if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) return !renderCache.highlighted;
253
- return this.highlighter != null && areThemesAttached(options.theme);
261
+ if (this.getHighlightWorkerManager(file) != null) return !renderCache.highlighted;
262
+ return getHighlighterIfLoaded({ theme: options.theme }) != null;
254
263
  }
255
264
  getOrCreateLineCache(file) {
256
265
  let { lineCache } = this;
@@ -316,6 +325,7 @@ var FileRenderer = class {
316
325
  };
317
326
  })
318
327
  };
328
+ this.ownedRows.add(row);
319
329
  if (pendingStructuralRows != null) pendingStructuralRows.set(line, row);
320
330
  else result.code[line] = row;
321
331
  }
@@ -347,7 +357,7 @@ var FileRenderer = class {
347
357
  if (pendingStructuralRows !== void 0) {
348
358
  for (const [line, row] of pendingStructuralRows) if (line < nextLines.length) result.code[line] = row;
349
359
  }
350
- for (let i = prefix; i < nextLines.length - suffix; i++) result.code[i] ??= {
360
+ for (let i = prefix; i < nextLines.length - suffix; i++) result.code[i] ??= this.ownRow({
351
361
  type: "element",
352
362
  tagName: "div",
353
363
  properties: {
@@ -364,12 +374,17 @@ var FileRenderer = class {
364
374
  value: textDocument.getLineText(i)
365
375
  }]
366
376
  }]
367
- };
377
+ });
368
378
  for (let i = 0; i < result.code.length; i++) {
369
379
  const line = result.code[i];
370
- if (line?.type === "element") {
371
- line.properties["data-line"] = i + 1;
372
- line.properties["data-line-index"] = i;
380
+ if (line?.type === "element" && (line.properties["data-line"] !== i + 1 || line.properties["data-line-index"] !== i)) {
381
+ const row = this.ownedRows.has(line) ? line : this.ownRow({
382
+ ...line,
383
+ properties: { ...line.properties }
384
+ });
385
+ row.properties["data-line"] = i + 1;
386
+ row.properties["data-line-index"] = i;
387
+ result.code[i] = row;
373
388
  }
374
389
  }
375
390
  if (renderCache != null) renderCache.isDirty = true;
@@ -384,6 +399,10 @@ var FileRenderer = class {
384
399
  this.textDocumentCache.set(file, textDocument);
385
400
  file.contents = contents;
386
401
  }
402
+ ownRow(row) {
403
+ this.ownedRows.add(row);
404
+ return row;
405
+ }
387
406
  renderFile(file = this.file, renderRange = DEFAULT_RENDER_RANGE) {
388
407
  this.file = file;
389
408
  if (file == null) {
@@ -414,24 +433,26 @@ var FileRenderer = class {
414
433
  const canRenderFile = this.canRenderFile(file, options, forcePlainText);
415
434
  const newContent = !areFileTargetsEqual(file, this.renderCache.file);
416
435
  const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
417
- if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
436
+ const workerManager = this.getHighlightWorkerManager(file);
437
+ if (workerManager != null) {
418
438
  const preserveHydratedContent = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
419
439
  if (canRenderFile && !preserveHydratedContent && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
420
440
  this.renderCache.file = file;
421
441
  this.renderCache.options = options;
422
442
  this.renderCache.highlighted = false;
423
- if (this.renderCache.result == null || newContent || newRenderRange || forceHighlight) this.renderCache.result = this.workerManager.getPlainFileAST(file, renderRange.startingLine, renderRange.totalLines, lines);
443
+ if (this.renderCache.result == null || newContent || newRenderRange || forceHighlight) this.renderCache.result = workerManager.getPlainFileAST(file, renderRange.startingLine, renderRange.totalLines, lines);
424
444
  this.renderCache.renderRange = renderRange;
425
445
  }
426
- if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) this.workerManager.highlightFileAST(this, file);
446
+ if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) workerManager.highlightFileAST(this, file);
427
447
  } else {
428
448
  this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);
429
- this.highlighter ??= getHighlighterIfLoaded();
430
- const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
431
- const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLang);
449
+ const highlighter = getHighlighterIfLoaded();
450
+ const hasThemes = highlighter != null && areThemesAttached(options.theme, highlighter);
451
+ const hasLangs = highlighter != null && areLanguagesAttached(this.computedLang, highlighter);
432
452
  const canHighlight = !forcePlainText && hasLangs;
433
- if (canRenderFile && this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
434
- const { result, options } = this.renderFileWithHighlighter(file, this.highlighter, forcePlainText || !hasLangs);
453
+ const lazyLineAST = Number.isFinite(renderRange.totalLines);
454
+ if (canRenderFile && highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
455
+ const { result, options } = this.renderFileWithHighlighter(file, highlighter, forcePlainText || !hasLangs, lazyLineAST);
435
456
  this.renderCache = {
436
457
  file,
437
458
  options,
@@ -439,30 +460,44 @@ var FileRenderer = class {
439
460
  result,
440
461
  renderRange: void 0
441
462
  };
463
+ if (canHighlight) this.cacheHighlightResult(file, {
464
+ result,
465
+ options
466
+ });
442
467
  }
443
- if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(file).then(({ result, options }) => {
468
+ if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(file, lazyLineAST).then(({ result, options }) => {
469
+ if (!forcePlainText) this.cacheHighlightResult(file, {
470
+ result,
471
+ options
472
+ });
444
473
  this.applyHighlightResult(file, result, options, !forcePlainText);
474
+ }).catch((error) => {
475
+ if (!(error instanceof HighlighterDisposedError)) this.onHighlightError(error);
445
476
  });
446
477
  }
447
478
  return this.renderCache.result != null ? this.processFileResult(this.renderCache.file, renderRange, this.renderCache.result) : void 0;
448
479
  }
449
480
  async asyncRender(file, renderRange = DEFAULT_RENDER_RANGE) {
450
481
  this.file = file;
451
- const { result } = await this.asyncHighlight(file);
482
+ const { result } = await this.asyncHighlight(file, Number.isFinite(renderRange.totalLines));
452
483
  return this.processFileResult(file, renderRange, result);
453
484
  }
454
- async asyncHighlight(file) {
485
+ async asyncHighlight(file, lazyLineAST = false) {
455
486
  const forcePlainText = isFileMassive(this.getOrCreateLineCache(file).length, this.getTokenizeMaxLength());
456
487
  this.computedLang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
457
- const hasThemes = this.highlighter != null && hasResolvedThemes(getThemes(this.getLocalHighlightTheme()));
458
- const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLang);
459
- if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
460
- return this.renderFileWithHighlighter(file, this.highlighter, forcePlainText);
488
+ let highlighter = getHighlighterIfLoaded();
489
+ const hasThemes = highlighter != null && areThemesAttached(this.getLocalHighlightTheme(), highlighter);
490
+ const hasLangs = forcePlainText || highlighter != null && areLanguagesAttached(this.computedLang, highlighter);
491
+ if (highlighter == null || !hasThemes || !hasLangs) highlighter = await this.initializeHighlighter();
492
+ return this.renderFileWithHighlighter(file, highlighter, forcePlainText, lazyLineAST);
461
493
  }
462
- renderFileWithHighlighter(file, highlighter, forcePlainText = false) {
494
+ renderFileWithHighlighter(file, highlighter, forcePlainText = false, lazyLineAST = false) {
463
495
  const { options } = this.getRenderOptions(file);
464
496
  return {
465
- result: renderFileWithHighlighter(file, highlighter, options, { forcePlainText }),
497
+ result: renderFileWithHighlighter(file, highlighter, options, {
498
+ forcePlainText,
499
+ lazyLineAST
500
+ }),
466
501
  options
467
502
  };
468
503
  }
@@ -536,7 +571,7 @@ var FileRenderer = class {
536
571
  });
537
572
  }
538
573
  renderFullHTML(result) {
539
- return toHtml(this.renderFullAST(result));
574
+ return hastToHtml(this.renderFullAST(result));
540
575
  }
541
576
  renderFullAST(result, children = []) {
542
577
  children.push(createHastElement({
@@ -556,19 +591,18 @@ var FileRenderer = class {
556
591
  return [gutter, createContentColumn(result.contentAST, result.rowCount)];
557
592
  }
558
593
  renderPartialHTML(children, includeCodeNode = false) {
559
- if (!includeCodeNode) return toHtml(children);
560
- return toHtml(createHastElement({
594
+ if (!includeCodeNode) return hastToHtml(children);
595
+ return hastToHtml(createHastElement({
561
596
  tagName: "code",
562
597
  children,
563
598
  properties: { "data-code": "" }
564
599
  }));
565
600
  }
566
- async initializeHighlighter() {
567
- this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, {
601
+ initializeHighlighter() {
602
+ return getSharedHighlighter(getHighlighterOptions(this.computedLang, {
568
603
  theme: this.getLocalHighlightTheme(),
569
- preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
604
+ preferredHighlighter: resolvePreferredHighlighter(this.workerManager, this.options)
570
605
  }));
571
- return this.highlighter;
572
606
  }
573
607
  onHighlightSuccess(file, result, options, highlighted = true) {
574
608
  if (this.editSessionActive) return;
@@ -1 +1 @@
1
- {"version":3,"file":"FileRenderer.js","names":[],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport type { TextDocument } from '../editor/textDocument';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n FileHeaderRenderMode,\n HighlightedToken,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { applyLineTextWithNewline } from '../utils/applyLineTextWithNewline';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFileTargetsEqual } from '../utils/areFileTargetsEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { linesFromFileContents } from '../utils/computeFileOffsets';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport {\n FILE_ANNOTATION_HUNK_INDEX,\n FILE_ANNOTATION_LINE_INDEX,\n getFileAnnotations,\n shouldRenderFileAnnotations,\n} from '../utils/includesFileAnnotations';\nimport { isDefaultRenderRange } from '../utils/isDefaultRenderRange';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\ninterface PendingHighlightResult extends RenderFileResult {\n file: FileContents;\n highlighted: boolean;\n}\n\ninterface FileRenderCache extends RenderedFileASTCache {\n // hydrate() describes DOM that already exists, even when no reusable AST\n // was available for that server-rendered content.\n hydrated?: boolean;\n}\n\nexport interface FileRenderResult {\n file: FileContents;\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n file: FileContents;\n sourceContents: string;\n lines: string[];\n}\n\n// Explicit keys may share cached lines across equivalent file objects. Unkeyed\n// files stay isolated by object identity while still supporting edit recycle.\nfunction isLineCacheForFile(lineCache: LineCache, file: FileContents): boolean {\n return file.cacheKey == null\n ? lineCache.file === file && lineCache.sourceContents === file.contents\n : lineCache.cacheKey === file.cacheKey;\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n private highlighter: DiffsHighlighter | undefined;\n // The latest file requested by the component. The render cache may\n // intentionally keep displaying an older highlighted file while this one\n // is highlighted in the background.\n private file: FileContents | undefined;\n\n private renderCache: FileRenderCache | undefined;\n // Completed background work waits here until the next render can update its\n // DOM and layout together.\n private pendingHighlightResult: PendingHighlightResult | undefined;\n\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n private pendingStructuralRows: Map<number, HASTElement> | undefined;\n private textDocumentCache = new WeakMap<\n FileContents,\n TextDocument<'file', LAnnotation>\n >();\n\n // Edit-session state: while active, this renderer stays on the main thread\n // with editor-compatible token markup — the editor's caret/selection\n // mapping needs the token transformer, and the pool's global options are\n // not guaranteed to produce it. The pool keeps serving every surface\n // without a session.\n private editSessionActive = false;\n\n public get fileCache(): FileContents | undefined {\n return this.renderCache?.file;\n }\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private annotationSlotName: (\n annotation: LineAnnotation<LAnnotation>\n ) => string = getLineAnnotationName,\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.endEditSession();\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n /**\n * Enter edit-session mode: rendering happens locally with the token\n * transformer forced on, and worker-pool requests/results are suspended\n * for this renderer. Called on initial editor association and whenever its\n * rendering resumes after recycle.\n */\n public beginEditSession(\n file: FileContents,\n externalFile?: FileContents\n ): void {\n const { editSessionActive: wasAlreadyActive, renderCache } = this;\n this.editSessionActive = true;\n if (!wasAlreadyActive) {\n this.pendingHighlightResult = undefined;\n }\n\n this.file = file;\n if (renderCache == null) {\n return;\n }\n // Edit updates call this again before each write. That cache is already\n // private and must retain plain-text session results.\n if (wasAlreadyActive && renderCache.file === file) {\n return;\n }\n if (wasAlreadyActive) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n const { options } = this.getRenderOptions(file);\n const cacheBelongsToSession = renderCache.file === file;\n const cacheBelongsToExternal =\n externalFile != null &&\n areFileTargetsEqual(renderCache.file, externalFile);\n const { result } = renderCache;\n if (\n !renderCache.highlighted ||\n result == null ||\n !areFileRenderOptionsEqual(renderCache.options, options) ||\n (!cacheBelongsToSession && !cacheBelongsToExternal)\n ) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n if (cacheBelongsToSession) {\n return;\n }\n\n this.renderCache = {\n ...renderCache,\n file,\n result: {\n ...result,\n code: [...result.code],\n },\n };\n const { lineCache } = this;\n if (\n lineCache != null &&\n externalFile != null &&\n isLineCacheForFile(lineCache, externalFile)\n ) {\n this.lineCache = {\n cacheKey: undefined,\n file,\n sourceContents: file.contents,\n lines: lineCache.lines,\n };\n } else {\n this.lineCache = undefined;\n }\n }\n\n /**\n * Leave edit-session mode. Rendering returns to the pool when one works.\n * When `settledFile` has the content the cache already shows, the cache\n * adopts it as its identity so the next render treats it as current\n * instead of a new file.\n */\n public endEditSession(settledFile?: FileContents): void {\n this.editSessionActive = false;\n this.pendingHighlightResult = undefined;\n if (this.file == null) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n const { renderCache } = this;\n if (\n settledFile == null ||\n renderCache == null ||\n renderCache.file === settledFile ||\n !areFileTargetsEqual(renderCache.file, settledFile)\n ) {\n return;\n }\n renderCache.file = settledFile;\n }\n\n /**\n * Ensures that the DOM is compatible with editor render updates\n */\n public editorRenderReady(): boolean {\n return (\n this.renderCache?.options.useTokenTransformer === true &&\n this.renderCache.highlighted &&\n this.renderCache.result != null\n );\n }\n\n public recycle(): void {\n if (this.editSessionActive) {\n // The editor and its document survive this recycle. Keep their patched\n // highlight, line map, and document count together for the next mount.\n if (this.renderCache != null) {\n this.renderCache.renderRange = undefined;\n }\n this.pendingHighlightResult = undefined;\n this.pendingStructuralRows = undefined;\n } else {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n }\n this.highlighter = undefined;\n this.workerManager?.cleanUpTasks(this);\n this.file = undefined;\n }\n\n public clearRenderCache(): void {\n this.pendingStructuralRows = undefined;\n this.renderCache = undefined;\n this.pendingHighlightResult = undefined;\n }\n\n public hydrate(file: FileContents): void {\n this.file = file;\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n hydrated: true,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n if (\n !this.editSessionActive &&\n this.workerManager?.isWorkingPool() === true\n ) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n this.workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (this.highlighter == null) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter();\n }\n }\n\n private getLocalHighlightTheme(): RenderFileOptions['theme'] {\n return (\n this.workerManager?.getFileRenderOptions().theme ??\n this.options.theme ??\n DEFAULT_THEMES\n );\n }\n\n public getEffectiveCodeOptions(): Pick<\n BaseCodeOptions,\n 'theme' | 'tokenizeMaxLineLength'\n > {\n const poolOptions =\n this.workerManager?.isWorkingPool() === true\n ? this.workerManager.getFileRenderOptions()\n : undefined;\n return {\n theme: this.getLocalHighlightTheme(),\n tokenizeMaxLineLength:\n poolOptions?.tokenizeMaxLineLength ??\n this.options.tokenizeMaxLineLength,\n };\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n const poolOptions = this.workerManager.getFileRenderOptions();\n // Active edit sessions require `useTokenTransformer: true`\n if (\n this.editSessionActive &&\n poolOptions.useTokenTransformer !== true\n ) {\n return { ...poolOptions, useTokenTransformer: true };\n }\n return poolOptions;\n }\n const { tokenizeMaxLineLength = 1000 } = this.options;\n return {\n theme: this.getLocalHighlightTheme(),\n useTokenTransformer:\n this.editSessionActive || this.options.useTokenTransformer === true,\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFileTargetsEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n /**\n * Returns the file that the next synchronous render can commit without\n * changing the current render cache. Virtualized layouts use this to stay\n * aligned with the DOM while a replacement highlight is still pending.\n */\n public getFileForNextRender(file: FileContents): FileContents {\n const { options } = this.getRenderOptions(file);\n if (this.getReadyRenderResult(file, options) != null) {\n return file;\n }\n\n const { renderCache } = this;\n if (renderCache == null) {\n return file;\n }\n if (areFileTargetsEqual(renderCache.file, file)) {\n return renderCache.file;\n }\n\n const lines = linesFromFileContents(file.contents);\n const forcePlainText =\n file.contents.length === 0 ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n\n return this.canRenderFile(file, options, forcePlainText)\n ? file\n : renderCache.file;\n }\n\n private canRenderFile(\n file: FileContents,\n options: RenderFileOptions,\n forcePlainText: boolean\n ): boolean {\n const { renderCache } = this;\n if (renderCache == null || areFileTargetsEqual(renderCache.file, file)) {\n return true;\n }\n if (forcePlainText) {\n return (\n (renderCache.result == null && renderCache.hydrated !== true) ||\n this.workerManager?.isWorkingPool() === true ||\n (this.highlighter != null && areThemesAttached(options.theme))\n );\n }\n // Hydration has highlighted DOM without a local AST. It is still active\n // rendered content and must remain visible while a non-plain replacement\n // is prepared.\n if (renderCache.result == null && renderCache.hydrated !== true) {\n return true;\n }\n\n if (\n !this.editSessionActive &&\n this.workerManager?.isWorkingPool() === true\n ) {\n return !renderCache.highlighted;\n }\n\n return this.highlighter != null && areThemesAttached(options.theme);\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n let { lineCache } = this;\n if (lineCache == null || !isLineCacheForFile(lineCache, file)) {\n lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: file.contents,\n lines: linesFromFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n // when a emitLineCountChange is called,\n // calculate the line count using the cached text document\n public getLineCount(file: FileContents): number {\n const lines = this.getOrCreateLineCache(file);\n return this.textDocumentCache.get(file)?.lineCount ?? lines.length;\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light',\n lineCountChangeInFlight = false\n ): void {\n this.pendingStructuralRows = undefined;\n const { renderCache } = this;\n if (renderCache == null) {\n return;\n }\n const { file, result } = renderCache;\n if (result == null) {\n return;\n }\n const pendingStructuralRows = lineCountChangeInFlight\n ? new Map<number, HASTElement>()\n : undefined;\n this.pendingStructuralRows = pendingStructuralRows;\n // Same-line edits can update the document cache immediately. Structural\n // rows use post-edit indexes, so hold them until applyDocumentChange has\n // shifted the old cache; writing now would overwrite rows that must move.\n const lineCache =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache\n : undefined;\n for (const [line, tokens] of dirtyLines) {\n if (\n pendingStructuralRows == null &&\n lineCache != null &&\n line < lineCache.lines.length\n ) {\n const lineText = tokens.map((token) => token[2]).join('');\n lineCache.lines[line] = applyLineTextWithNewline(\n lineCache.lines[line] ?? '',\n lineText\n );\n }\n const row: HASTElement = {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': line + 1,\n 'data-line-type': 'context',\n 'data-line-index': line,\n },\n children: tokens.map(([char, fg, text]) => {\n if (char === 0 && fg === '') {\n if (text === '') {\n return {\n type: 'element',\n tagName: 'br',\n properties: {},\n children: [],\n };\n }\n return { type: 'text', value: text };\n }\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': char,\n style: `color:${fg};`,\n },\n children: [{ type: 'text', value: text }],\n };\n }),\n };\n if (pendingStructuralRows != null) {\n pendingStructuralRows.set(line, row);\n } else {\n result.code[line] = row;\n }\n }\n\n result.baseThemeType = themeType;\n renderCache.isDirty = true;\n if (pendingStructuralRows == null && lineCache != null) {\n file.contents = lineCache.lines.join('');\n lineCache.sourceContents = file.contents;\n }\n }\n\n // Reconcile the session source even when no highlighted result exists. A\n // suspended editor can still receive programmatic edits after cache clear.\n public applyDocumentChange(\n textDocument: TextDocument<'file', LAnnotation>\n ): void {\n const { pendingStructuralRows, renderCache } = this;\n this.pendingStructuralRows = undefined;\n const file = this.file ?? renderCache?.file;\n if (file == null) {\n return;\n }\n const result = renderCache?.result;\n // Structural edits renumber cached HAST rows. Keep the unchanged prefix\n // and suffix, and plain-fill only the window that still needs tokenizing.\n const previousLines =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache.lines\n : linesFromFileContents(file.contents);\n const nextLines = linesFromFileContents(textDocument.getText());\n if (result != null && previousLines.length !== nextLines.length) {\n const maxShared = Math.min(previousLines.length, nextLines.length);\n let prefix = 0;\n while (\n prefix < maxShared &&\n previousLines[prefix] === nextLines[prefix]\n ) {\n prefix++;\n }\n let suffix = 0;\n while (\n suffix < maxShared - prefix &&\n previousLines[previousLines.length - 1 - suffix] ===\n nextLines[nextLines.length - 1 - suffix]\n ) {\n suffix++;\n }\n\n const previousCode = result.code;\n result.code = new Array(nextLines.length);\n for (let i = 0; i < prefix; i++) {\n result.code[i] = previousCode[i];\n }\n for (let i = 0; i < suffix; i++) {\n result.code[nextLines.length - 1 - i] =\n previousCode[previousLines.length - 1 - i];\n }\n if (pendingStructuralRows !== undefined) {\n for (const [line, row] of pendingStructuralRows) {\n if (line < nextLines.length) {\n result.code[line] = row;\n }\n }\n }\n for (let i = prefix; i < nextLines.length - suffix; i++) {\n result.code[i] ??= {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': i + 1,\n 'data-line-type': 'context',\n 'data-line-index': i,\n },\n children: [\n {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': 0,\n },\n children: [\n {\n type: 'text',\n value: textDocument.getLineText(i),\n },\n ],\n },\n ],\n };\n }\n for (let i = 0; i < result.code.length; i++) {\n const line = result.code[i];\n if (line?.type === 'element') {\n line.properties['data-line'] = i + 1;\n line.properties['data-line-index'] = i;\n }\n }\n if (renderCache != null) {\n renderCache.isDirty = true;\n }\n }\n // Replace the old split-line cache with the authoritative edited document.\n const contents = textDocument.getText();\n this.lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: contents,\n lines: nextLines,\n };\n this.textDocumentCache.set(file, textDocument);\n file.contents = contents;\n }\n\n public renderFile(\n file: FileContents | undefined = this.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n this.file = file;\n if (file == null) {\n this.pendingHighlightResult = undefined;\n return undefined;\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n const readyResult = this.getReadyRenderResult(file, options);\n this.pendingHighlightResult = undefined;\n if (readyResult != null) {\n this.renderCache = {\n ...readyResult,\n file,\n renderRange: undefined,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const canRenderFile = this.canRenderFile(file, options, forcePlainText);\n const newContent = !areFileTargetsEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n if (\n !this.editSessionActive &&\n this.workerManager?.isWorkingPool() === true\n ) {\n // Hydration has highlighted DOM but no local AST. Keep that DOM until\n // its corresponding worker result is ready.\n const preserveHydratedContent =\n this.renderCache.result == null &&\n this.renderCache.highlighted &&\n !forcePlainText &&\n !newContent &&\n isDefaultRenderRange(renderRange);\n if (\n canRenderFile &&\n !preserveHydratedContent &&\n (forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange)))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = this.workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n this.highlighter ??= getHighlighterIfLoaded();\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n const canHighlight = !forcePlainText && hasLangs;\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n canRenderFile &&\n this.highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText || !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n this.applyHighlightResult(file, result, options, !forcePlainText);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n this.file = file;\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.getLocalHighlightTheme()));\n const hasLangs =\n forcePlainText ||\n (this.highlighter != null && areLanguagesAttached(this.computedLang));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n this.highlighter,\n forcePlainText\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const totalLines = this.getLineCount(file);\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const endLine = Math.min(\n renderRange.startingLine + renderRange.totalLines,\n totalLines\n );\n let rowCount = 0;\n\n const fileLevelAnnotations = shouldRenderFileAnnotations(renderRange)\n ? getFileAnnotations(this.lineAnnotations)\n : undefined;\n if (fileLevelAnnotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: FILE_ANNOTATION_HUNK_INDEX,\n lineIndex: FILE_ANNOTATION_LINE_INDEX,\n annotations: fileLevelAnnotations.map((annotation) =>\n this.annotationSlotName(annotation)\n ),\n })\n );\n rowCount++;\n }\n\n for (\n let lineIndex = renderRange.startingLine;\n lineIndex < endLine;\n lineIndex++\n ) {\n const lineNumber = lineIndex + 1;\n\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n });\n throw new Error(message);\n }\n\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n this.annotationSlotName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n file,\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(totalLines),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: totalLines,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, {\n theme: this.getLocalHighlightTheme(),\n preferredHighlighter:\n this.workerManager?.getPreferredHighlighter() ??\n this.options.preferredHighlighter,\n })\n );\n return this.highlighter;\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.editSessionActive) {\n return;\n }\n this.applyHighlightResult(file, result, options, highlighted);\n }\n\n private applyHighlightResult(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n const { file: currentFile, renderCache } = this;\n if (\n currentFile == null ||\n renderCache == null ||\n !areFileTargetsEqual(file, currentFile) ||\n !areFileRenderOptionsEqual(\n options,\n this.getRenderOptions(currentFile).options\n )\n ) {\n return;\n }\n\n const triggerRender =\n renderCache.result == null ||\n !renderCache.highlighted ||\n !areFileRenderOptionsEqual(renderCache.options, options) ||\n !areFileTargetsEqual(renderCache.file, currentFile);\n if (!triggerRender) {\n return;\n }\n\n this.pendingHighlightResult = {\n file: currentFile,\n options,\n highlighted,\n result,\n };\n this.onRenderUpdate?.();\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n if (this.editSessionActive) {\n return undefined;\n }\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n // Returns completed background work that can replace the rendered AST on\n // the next render. Reading it does not promote or discard pending work.\n private getReadyRenderResult(\n file: FileContents,\n options: RenderFileOptions\n ): PendingHighlightResult | undefined {\n const { pendingHighlightResult } = this;\n if (\n pendingHighlightResult != null &&\n areFileTargetsEqual(pendingHighlightResult.file, file) &&\n areFileRenderOptionsEqual(pendingHighlightResult.options, options)\n ) {\n return pendingHighlightResult;\n }\n\n const workerCache = this.getMatchingWorkerResultCache(file, options);\n if (workerCache == null || this.hasHighlightedRenderCache(file, options)) {\n return undefined;\n }\n return { file, highlighted: true, ...workerCache };\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFileTargetsEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,SAAS,mBAAmB,WAAsB,MAA6B;CAC7E,OAAO,KAAK,YAAY,OACpB,UAAU,SAAS,QAAQ,UAAU,mBAAmB,KAAK,WAC7D,UAAU,aAAa,KAAK;AAClC;AAMA,IAAI,aAAa;AAEjB,IAAa,eAAb,MAAmD;CAmCxC;CACC;CAGA;CACA;CAvCV,OAAwB,iBAAiB,EAAE;CAE3C;CAIA;CAEA;CAGA;CAEA,eAA2C;CAC3C,kBAA0D,CAAC;CAC3D;CACA;CACA,oCAA4B,IAAI,QAG9B;CAOF,oBAA4B;CAE5B,IAAW,YAAsC;EAC/C,OAAO,KAAK,aAAa;CAC3B;CAEA,YACE,UAAsC,EAAE,OAAO,eAAe,GAC9D,qBAEc,uBACd,gBACA,eACA;EANO,KAAA,UAAA;EACC,KAAA,qBAAA;EAGA,KAAA,iBAAA;EACA,KAAA,gBAAA;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AiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;EACjE,OAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;EACF,CAAC;CACH;AACF;AAEA,SAAS,cAAc,WAAmB,mBAAoC;CAC5E,OAAO,YAAY;AACrB"}
1
+ {"version":3,"file":"FileRenderer.js","names":[],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\n\nimport {\n DEFAULT_RENDER_RANGE,\n DEFAULT_THEMES,\n DEFAULT_TOKENIZE_MAX_LENGTH,\n} from '../constants';\nimport type { TextDocument } from '../editor/textDocument';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n HighlighterDisposedError,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n FileHeaderRenderMode,\n HighlightedToken,\n LineAnnotation,\n RenderedFileASTCache,\n RenderFileOptions,\n RenderFileResult,\n RenderRange,\n SupportedLanguages,\n ThemedFileResult,\n} from '../types';\nimport { applyLineTextWithNewline } from '../utils/applyLineTextWithNewline';\nimport { areFileRenderOptionsEqual } from '../utils/areFileRenderOptionsEqual';\nimport { areFileTargetsEqual } from '../utils/areFileTargetsEqual';\nimport { areRenderRangesEqual } from '../utils/areRenderRangesEqual';\nimport { linesFromFileContents } from '../utils/computeFileOffsets';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createContentColumn } from '../utils/createContentColumn';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport {\n createGutterGap,\n createGutterItem,\n createGutterWrapper,\n createHastElement,\n} from '../utils/hast_utils';\nimport { hastToHtml } from '../utils/hastToHtml';\nimport {\n FILE_ANNOTATION_HUNK_INDEX,\n FILE_ANNOTATION_LINE_INDEX,\n getFileAnnotations,\n shouldRenderFileAnnotations,\n} from '../utils/includesFileAnnotations';\nimport { isDefaultRenderRange } from '../utils/isDefaultRenderRange';\nimport { isFilePlainText } from '../utils/isFilePlainText';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport { resolvePreferredHighlighter } from '../utils/resolvePreferredHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceHighlight: boolean;\n}\n\ninterface PendingHighlightResult extends RenderFileResult {\n file: FileContents;\n highlighted: boolean;\n}\n\ninterface FileRenderCache extends RenderedFileASTCache {\n // hydrate() describes DOM that already exists, even when no reusable AST\n // was available for that server-rendered content.\n hydrated?: boolean;\n}\n\nexport interface FileRenderResult {\n file: FileContents;\n gutterAST: ElementContent[];\n contentAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\n\ninterface LineCache {\n cacheKey: string | undefined;\n file: FileContents;\n sourceContents: string;\n lines: string[];\n}\n\n// Explicit keys may share cached lines across equivalent file objects. Unkeyed\n// files stay isolated by object identity while still supporting edit recycle.\nfunction isLineCacheForFile(lineCache: LineCache, file: FileContents): boolean {\n return file.cacheKey == null\n ? lineCache.file === file && lineCache.sourceContents === file.contents\n : lineCache.cacheKey === file.cacheKey;\n}\n\nexport interface FileRendererOptions extends BaseCodeOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\n\nlet instanceId = -1;\n\nexport class FileRenderer<LAnnotation = undefined> {\n readonly __id: string = `file-renderer:${++instanceId}`;\n\n // The latest file requested by the component. The render cache may\n // intentionally keep displaying an older highlighted file while this one\n // is highlighted in the background.\n private file: FileContents | undefined;\n\n private renderCache: FileRenderCache | undefined;\n // Completed background work waits here until the next render can update its\n // DOM and layout together.\n private pendingHighlightResult: PendingHighlightResult | undefined;\n\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n private lineCache: LineCache | undefined;\n private pendingStructuralRows: Map<number, HASTElement> | undefined;\n private textDocumentCache = new WeakMap<\n FileContents,\n TextDocument<'file', LAnnotation>\n >();\n // Rows this renderer built itself, which edits renumber in place. Any other\n // row can be shared with the pool cache or other renderers, so an edit\n // copies it the first time it has to change.\n private ownedRows = new WeakSet<HASTElement>();\n\n // Edit-session state: while active, this renderer stays on the main thread\n // with editor-compatible token markup — the editor's caret/selection\n // mapping needs the token transformer, and the pool's global options are\n // not guaranteed to produce it. The pool keeps serving every surface\n // without a session.\n private editSessionActive = false;\n\n public get fileCache(): FileContents | undefined {\n return this.renderCache?.file;\n }\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private annotationSlotName: (\n annotation: LineAnnotation<LAnnotation>\n ) => string = getLineAnnotationName,\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {}\n\n public setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n public mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n public setLineAnnotations(\n lineAnnotations: LineAnnotation<LAnnotation>[]\n ): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n public cleanUp(): void {\n this.endEditSession();\n this.recycle();\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n /**\n * Enter edit-session mode: rendering happens locally with the token\n * transformer forced on, and worker-pool requests/results are suspended\n * for this renderer. Called on initial editor association and whenever its\n * rendering resumes after recycle.\n */\n public beginEditSession(\n file: FileContents,\n externalFile?: FileContents\n ): void {\n const { editSessionActive: wasAlreadyActive, renderCache } = this;\n this.editSessionActive = true;\n if (!wasAlreadyActive) {\n this.pendingHighlightResult = undefined;\n }\n\n this.file = file;\n if (renderCache == null) {\n return;\n }\n // Edit updates call this again before each write. That cache is already\n // private and must retain plain-text session results.\n if (wasAlreadyActive && renderCache.file === file) {\n return;\n }\n if (wasAlreadyActive) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n const { options } = this.getRenderOptions(file);\n const cacheBelongsToSession = renderCache.file === file;\n const cacheBelongsToExternal =\n externalFile != null &&\n areFileTargetsEqual(renderCache.file, externalFile);\n const { result } = renderCache;\n if (\n !renderCache.highlighted ||\n result == null ||\n !areFileRenderOptionsEqual(renderCache.options, options) ||\n (!cacheBelongsToSession && !cacheBelongsToExternal)\n ) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n if (cacheBelongsToSession) {\n return;\n }\n\n this.renderCache = {\n ...renderCache,\n file,\n result: {\n ...result,\n code: [...result.code],\n },\n };\n const { lineCache } = this;\n if (\n lineCache != null &&\n externalFile != null &&\n isLineCacheForFile(lineCache, externalFile)\n ) {\n this.lineCache = {\n cacheKey: undefined,\n file,\n sourceContents: file.contents,\n lines: lineCache.lines,\n };\n } else {\n this.lineCache = undefined;\n }\n }\n\n /**\n * Leave edit-session mode. Rendering returns to the pool when one works.\n * When `settledFile` has the content the cache already shows, the cache\n * adopts it as its identity so the next render treats it as current\n * instead of a new file.\n */\n public endEditSession(settledFile?: FileContents): void {\n this.editSessionActive = false;\n this.pendingHighlightResult = undefined;\n if (this.file == null) {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n return;\n }\n const { renderCache } = this;\n if (\n settledFile == null ||\n renderCache == null ||\n renderCache.file === settledFile ||\n !areFileTargetsEqual(renderCache.file, settledFile)\n ) {\n return;\n }\n renderCache.file = settledFile;\n }\n\n /**\n * Ensures that the DOM is compatible with editor render updates\n */\n public editorRenderReady(): boolean {\n return (\n this.renderCache?.options.useTokenTransformer === true &&\n this.renderCache.highlighted &&\n this.renderCache.result != null\n );\n }\n\n public recycle(): void {\n if (this.editSessionActive) {\n // The editor and its document survive this recycle. Keep their patched\n // highlight, line map, and document count together for the next mount.\n if (this.renderCache != null) {\n this.renderCache.renderRange = undefined;\n }\n this.pendingHighlightResult = undefined;\n this.pendingStructuralRows = undefined;\n } else {\n this.clearRenderCache();\n this.lineCache = undefined;\n this.textDocumentCache = new WeakMap();\n }\n this.workerManager?.cleanUpTasks(this);\n this.file = undefined;\n }\n\n public clearRenderCache(): void {\n this.pendingStructuralRows = undefined;\n this.renderCache = undefined;\n this.pendingHighlightResult = undefined;\n }\n\n public hydrate(file: FileContents): void {\n this.file = file;\n const { options } = this.getRenderOptions(file);\n const lines = this.getOrCreateLineCache(file);\n const massiveFile = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areFileRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n hydrated: true,\n options,\n highlighted: !massiveFile && !isFilePlainText(file),\n result: massiveFile ? undefined : cache?.result,\n // FIXME(amadeus): Add support for renderRanges\n renderRange: undefined,\n };\n const workerManager = this.getHighlightWorkerManager(file);\n if (workerManager != null) {\n if (this.renderCache.result == null && !massiveFile) {\n // We should only kick off a preload of the AST if we have a WorkerPool\n workerManager.highlightFileAST(this, file);\n }\n }\n // Lets attempt to get the highlighter/languages ready immediately\n else if (\n getHighlighterIfLoaded({ theme: this.getLocalHighlightTheme() }) == null\n ) {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n void this.initializeHighlighter().catch((error: unknown) => {\n if (!(error instanceof HighlighterDisposedError)) {\n this.onHighlightError(error);\n }\n });\n }\n }\n\n // Returns the pool when there's a valid worker AND we should use it\n private getHighlightWorkerManager(\n file: FileContents\n ): WorkerPoolManager | undefined {\n const { editSessionActive, workerManager } = this;\n return !editSessionActive &&\n workerManager?.isWorkingPool() === true &&\n !workerManager.shouldHighlightOnMainThread(file)\n ? workerManager\n : undefined;\n }\n\n private cacheHighlightResult(\n file: FileContents,\n renderResult: RenderFileResult\n ): void {\n const { editSessionActive, workerManager } = this;\n if (!editSessionActive && workerManager?.isWorkingPool() === true) {\n workerManager.setFileResultCache(file.cacheKey, renderResult);\n }\n }\n\n private getLocalHighlightTheme(): RenderFileOptions['theme'] {\n return (\n this.workerManager?.getFileRenderOptions().theme ??\n this.options.theme ??\n DEFAULT_THEMES\n );\n }\n\n public getEffectiveCodeOptions(): Pick<\n BaseCodeOptions,\n 'theme' | 'tokenizeMaxLineLength'\n > {\n const poolOptions =\n this.workerManager?.isWorkingPool() === true\n ? this.workerManager.getFileRenderOptions()\n : undefined;\n return {\n theme: this.getLocalHighlightTheme(),\n tokenizeMaxLineLength:\n poolOptions?.tokenizeMaxLineLength ??\n this.options.tokenizeMaxLineLength,\n };\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n const poolOptions = this.workerManager.getFileRenderOptions();\n // Active edit sessions require `useTokenTransformer: true`\n if (\n this.editSessionActive &&\n poolOptions.useTokenTransformer !== true\n ) {\n return { ...poolOptions, useTokenTransformer: true };\n }\n return poolOptions;\n }\n const { tokenizeMaxLineLength = 1000 } = this.options;\n return {\n theme: this.getLocalHighlightTheme(),\n useTokenTransformer:\n this.editSessionActive || this.options.useTokenTransformer === true,\n tokenizeMaxLineLength,\n };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceHighlight: true };\n }\n if (\n !areFileTargetsEqual(file, renderCache.file) ||\n !areFileRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceHighlight: true };\n }\n return { options, forceHighlight: false };\n }\n\n /**\n * Returns the file that the next synchronous render can commit without\n * changing the current render cache. Virtualized layouts use this to stay\n * aligned with the DOM while a replacement highlight is still pending.\n */\n public getFileForNextRender(file: FileContents): FileContents {\n const { options } = this.getRenderOptions(file);\n if (this.getReadyRenderResult(file, options) != null) {\n return file;\n }\n\n const { renderCache } = this;\n if (renderCache == null) {\n return file;\n }\n if (areFileTargetsEqual(renderCache.file, file)) {\n return renderCache.file;\n }\n\n const lines = linesFromFileContents(file.contents);\n const forcePlainText =\n file.contents.length === 0 ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n\n return this.canRenderFile(file, options, forcePlainText)\n ? file\n : renderCache.file;\n }\n\n private canRenderFile(\n file: FileContents,\n options: RenderFileOptions,\n forcePlainText: boolean\n ): boolean {\n const { renderCache } = this;\n if (renderCache == null || areFileTargetsEqual(renderCache.file, file)) {\n return true;\n }\n if (forcePlainText) {\n return (\n (renderCache.result == null && renderCache.hydrated !== true) ||\n (this.workerManager?.isWorkingPool() === true &&\n !this.workerManager.shouldHighlightOnMainThread(file)) ||\n getHighlighterIfLoaded({ theme: options.theme }) != null\n );\n }\n // Hydration has highlighted DOM without a local AST. It is still active\n // rendered content and must remain visible while a non-plain replacement\n // is prepared.\n if (renderCache.result == null && renderCache.hydrated !== true) {\n return true;\n }\n\n if (this.getHighlightWorkerManager(file) != null) {\n return !renderCache.highlighted;\n }\n\n return getHighlighterIfLoaded({ theme: options.theme }) != null;\n }\n\n public getOrCreateLineCache(file: FileContents): string[] {\n let { lineCache } = this;\n if (lineCache == null || !isLineCacheForFile(lineCache, file)) {\n lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: file.contents,\n lines: linesFromFileContents(file.contents),\n };\n }\n this.lineCache = lineCache;\n return lineCache.lines;\n }\n\n // when a emitLineCountChange is called,\n // calculate the line count using the cached text document\n public getLineCount(file: FileContents): number {\n const lines = this.getOrCreateLineCache(file);\n return this.textDocumentCache.get(file)?.lineCount ?? lines.length;\n }\n\n public updateRenderCache(\n dirtyLines: Map<number, Array<HighlightedToken>>,\n themeType: 'dark' | 'light',\n lineCountChangeInFlight = false\n ): void {\n this.pendingStructuralRows = undefined;\n const { renderCache } = this;\n if (renderCache == null) {\n return;\n }\n const { file, result } = renderCache;\n if (result == null) {\n return;\n }\n const pendingStructuralRows = lineCountChangeInFlight\n ? new Map<number, HASTElement>()\n : undefined;\n this.pendingStructuralRows = pendingStructuralRows;\n // Same-line edits can update the document cache immediately. Structural\n // rows use post-edit indexes, so hold them until applyDocumentChange has\n // shifted the old cache; writing now would overwrite rows that must move.\n const lineCache =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache\n : undefined;\n for (const [line, tokens] of dirtyLines) {\n if (\n pendingStructuralRows == null &&\n lineCache != null &&\n line < lineCache.lines.length\n ) {\n const lineText = tokens.map((token) => token[2]).join('');\n lineCache.lines[line] = applyLineTextWithNewline(\n lineCache.lines[line] ?? '',\n lineText\n );\n }\n const row: HASTElement = {\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': line + 1,\n 'data-line-type': 'context',\n 'data-line-index': line,\n },\n children: tokens.map(([char, fg, text]) => {\n if (char === 0 && fg === '') {\n if (text === '') {\n return {\n type: 'element',\n tagName: 'br',\n properties: {},\n children: [],\n };\n }\n return { type: 'text', value: text };\n }\n return {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': char,\n style: `color:${fg};`,\n },\n children: [{ type: 'text', value: text }],\n };\n }),\n };\n this.ownedRows.add(row);\n if (pendingStructuralRows != null) {\n pendingStructuralRows.set(line, row);\n } else {\n result.code[line] = row;\n }\n }\n\n result.baseThemeType = themeType;\n renderCache.isDirty = true;\n if (pendingStructuralRows == null && lineCache != null) {\n file.contents = lineCache.lines.join('');\n lineCache.sourceContents = file.contents;\n }\n }\n\n // Reconcile the session source even when no highlighted result exists. A\n // suspended editor can still receive programmatic edits after cache clear.\n public applyDocumentChange(\n textDocument: TextDocument<'file', LAnnotation>\n ): void {\n const { pendingStructuralRows, renderCache } = this;\n this.pendingStructuralRows = undefined;\n const file = this.file ?? renderCache?.file;\n if (file == null) {\n return;\n }\n const result = renderCache?.result;\n // Structural edits renumber cached HAST rows. Keep the unchanged prefix\n // and suffix, and plain-fill only the window that still needs tokenizing.\n const previousLines =\n this.lineCache != null && isLineCacheForFile(this.lineCache, file)\n ? this.lineCache.lines\n : linesFromFileContents(file.contents);\n const nextLines = linesFromFileContents(textDocument.getText());\n if (result != null && previousLines.length !== nextLines.length) {\n const maxShared = Math.min(previousLines.length, nextLines.length);\n let prefix = 0;\n while (\n prefix < maxShared &&\n previousLines[prefix] === nextLines[prefix]\n ) {\n prefix++;\n }\n let suffix = 0;\n while (\n suffix < maxShared - prefix &&\n previousLines[previousLines.length - 1 - suffix] ===\n nextLines[nextLines.length - 1 - suffix]\n ) {\n suffix++;\n }\n\n const previousCode = result.code;\n result.code = new Array(nextLines.length);\n for (let i = 0; i < prefix; i++) {\n result.code[i] = previousCode[i];\n }\n for (let i = 0; i < suffix; i++) {\n result.code[nextLines.length - 1 - i] =\n previousCode[previousLines.length - 1 - i];\n }\n if (pendingStructuralRows !== undefined) {\n for (const [line, row] of pendingStructuralRows) {\n if (line < nextLines.length) {\n result.code[line] = row;\n }\n }\n }\n for (let i = prefix; i < nextLines.length - suffix; i++) {\n result.code[i] ??= this.ownRow({\n type: 'element',\n tagName: 'div',\n properties: {\n 'data-line': i + 1,\n 'data-line-type': 'context',\n 'data-line-index': i,\n },\n children: [\n {\n type: 'element',\n tagName: 'span',\n properties: {\n 'data-char': 0,\n },\n children: [\n {\n type: 'text',\n value: textDocument.getLineText(i),\n },\n ],\n },\n ],\n });\n }\n for (let i = 0; i < result.code.length; i++) {\n const line = result.code[i];\n if (\n line?.type === 'element' &&\n (line.properties['data-line'] !== i + 1 ||\n line.properties['data-line-index'] !== i)\n ) {\n const row = this.ownedRows.has(line)\n ? line\n : this.ownRow({ ...line, properties: { ...line.properties } });\n row.properties['data-line'] = i + 1;\n row.properties['data-line-index'] = i;\n result.code[i] = row;\n }\n }\n if (renderCache != null) {\n renderCache.isDirty = true;\n }\n }\n // Replace the old split-line cache with the authoritative edited document.\n const contents = textDocument.getText();\n this.lineCache = {\n cacheKey: file.cacheKey,\n file,\n sourceContents: contents,\n lines: nextLines,\n };\n this.textDocumentCache.set(file, textDocument);\n file.contents = contents;\n }\n\n private ownRow(row: HASTElement): HASTElement {\n this.ownedRows.add(row);\n return row;\n }\n\n public renderFile(\n file: FileContents | undefined = this.file,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): FileRenderResult | undefined {\n this.file = file;\n if (file == null) {\n this.pendingHighlightResult = undefined;\n return undefined;\n }\n let { options, forceHighlight } = this.getRenderOptions(file);\n const readyResult = this.getReadyRenderResult(file, options);\n this.pendingHighlightResult = undefined;\n if (readyResult != null) {\n this.renderCache = {\n ...readyResult,\n file,\n renderRange: undefined,\n };\n forceHighlight = false;\n }\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n renderRange: undefined,\n };\n const lines = this.getOrCreateLineCache(file);\n const hasContent = file.contents.length > 0;\n const forcePlainText =\n !hasContent ||\n isFilePlainText(file) ||\n isFileMassive(lines.length, this.getTokenizeMaxLength());\n const canRenderFile = this.canRenderFile(file, options, forcePlainText);\n const newContent = !areFileTargetsEqual(file, this.renderCache.file);\n const newRenderRange = !areRenderRangesEqual(\n this.renderCache.renderRange,\n renderRange\n );\n const workerManager = this.getHighlightWorkerManager(file);\n if (workerManager != null) {\n // Hydration has highlighted DOM but no local AST. Keep that DOM until\n // its corresponding worker result is ready.\n const preserveHydratedContent =\n this.renderCache.result == null &&\n this.renderCache.highlighted &&\n !forcePlainText &&\n !newContent &&\n isDefaultRenderRange(renderRange);\n if (\n canRenderFile &&\n !preserveHydratedContent &&\n (forcePlainText ||\n this.renderCache.result == null ||\n (!this.renderCache.highlighted && (newContent || newRenderRange)))\n ) {\n this.renderCache.file = file;\n this.renderCache.options = options;\n this.renderCache.highlighted = false;\n if (\n this.renderCache.result == null ||\n newContent ||\n newRenderRange ||\n forceHighlight\n ) {\n this.renderCache.result = workerManager.getPlainFileAST(\n file,\n renderRange.startingLine,\n renderRange.totalLines,\n lines\n );\n }\n this.renderCache.renderRange = renderRange;\n }\n\n if (\n !forcePlainText &&\n hasContent &&\n (!this.renderCache.highlighted || forceHighlight)\n ) {\n workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const highlighter = getHighlighterIfLoaded();\n const hasThemes =\n highlighter != null && areThemesAttached(options.theme, highlighter);\n const hasLangs =\n highlighter != null &&\n areLanguagesAttached(this.computedLang, highlighter);\n const canHighlight = !forcePlainText && hasLangs;\n const lazyLineAST = Number.isFinite(renderRange.totalLines);\n\n if (\n canRenderFile &&\n highlighter != null &&\n hasThemes &&\n (forceHighlight ||\n forcePlainText ||\n (!this.renderCache.highlighted && canHighlight) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n highlighter,\n forcePlainText || !hasLangs,\n lazyLineAST\n );\n this.renderCache = {\n file,\n options,\n highlighted: canHighlight,\n result,\n renderRange: undefined,\n };\n if (canHighlight) {\n this.cacheHighlightResult(file, { result, options });\n }\n }\n\n if (!hasThemes || (!forcePlainText && !hasLangs)) {\n void this.asyncHighlight(file, lazyLineAST)\n .then(({ result, options }) => {\n if (!forcePlainText) {\n this.cacheHighlightResult(file, { result, options });\n }\n this.applyHighlightResult(file, result, options, !forcePlainText);\n })\n .catch((error: unknown) => {\n if (!(error instanceof HighlighterDisposedError)) {\n this.onHighlightError(error);\n }\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(\n this.renderCache.file,\n renderRange,\n this.renderCache.result\n )\n : undefined;\n }\n\n async asyncRender(\n file: FileContents,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<FileRenderResult> {\n this.file = file;\n const { result } = await this.asyncHighlight(\n file,\n Number.isFinite(renderRange.totalLines)\n );\n return this.processFileResult(file, renderRange, result);\n }\n\n private async asyncHighlight(\n file: FileContents,\n lazyLineAST = false\n ): Promise<RenderFileResult> {\n const lines = this.getOrCreateLineCache(file);\n const forcePlainText = isFileMassive(\n lines.length,\n this.getTokenizeMaxLength()\n );\n this.computedLang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n let highlighter = getHighlighterIfLoaded();\n const hasThemes =\n highlighter != null &&\n areThemesAttached(this.getLocalHighlightTheme(), highlighter);\n const hasLangs =\n forcePlainText ||\n (highlighter != null &&\n areLanguagesAttached(this.computedLang, highlighter));\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (highlighter == null || !hasThemes || !hasLangs) {\n highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(\n file,\n highlighter,\n forcePlainText,\n lazyLineAST\n );\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n forcePlainText = false,\n lazyLineAST = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(file, highlighter, options, {\n forcePlainText,\n lazyLineAST,\n });\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n renderRange: RenderRange,\n { code, themeStyles, baseThemeType }: ThemedFileResult\n ): FileRenderResult {\n const totalLines = this.getLineCount(file);\n const { disableFileHeader = false } = this.options;\n const contentArray: ElementContent[] = [];\n const gutter = createGutterWrapper();\n const endLine = Math.min(\n renderRange.startingLine + renderRange.totalLines,\n totalLines\n );\n let rowCount = 0;\n\n const fileLevelAnnotations = shouldRenderFileAnnotations(renderRange)\n ? getFileAnnotations(this.lineAnnotations)\n : undefined;\n if (fileLevelAnnotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: FILE_ANNOTATION_HUNK_INDEX,\n lineIndex: FILE_ANNOTATION_LINE_INDEX,\n annotations: fileLevelAnnotations.map((annotation) =>\n this.annotationSlotName(annotation)\n ),\n })\n );\n rowCount++;\n }\n\n for (\n let lineIndex = renderRange.startingLine;\n lineIndex < endLine;\n lineIndex++\n ) {\n const lineNumber = lineIndex + 1;\n\n // Sparse array - directly indexed by lineIndex\n const line = code[lineIndex];\n if (line == null) {\n const message = 'FileRenderer.processFileResult: Line doesnt exist';\n console.error(message, {\n name: file.name,\n lineIndex,\n lineNumber,\n });\n throw new Error(message);\n }\n\n // Add gutter line number\n gutter.children.push(\n createGutterItem('context', lineNumber, `${lineIndex}`)\n );\n contentArray.push(line);\n rowCount++;\n\n // Check annotations using ACTUAL line number from file\n const annotations = this.lineAnnotations[lineNumber];\n if (annotations != null) {\n gutter.children.push(createGutterGap('context', 'annotation', 1));\n contentArray.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex: lineNumber,\n annotations: annotations.map((annotation) =>\n this.annotationSlotName(annotation)\n ),\n })\n );\n rowCount++;\n }\n }\n\n // Finalize: wrap gutter and content\n gutter.properties.style = `grid-row: span ${rowCount}`;\n return {\n file,\n gutterAST: gutter.children ?? [],\n contentAST: contentArray,\n preAST: this.createPreElement(totalLines),\n headerAST: !disableFileHeader ? this.renderHeader(file) : undefined,\n totalLines: totalLines,\n rowCount,\n themeStyles: themeStyles,\n baseThemeType,\n bufferBefore: renderRange.bufferBefore,\n bufferAfter: renderRange.bufferAfter,\n css: '',\n };\n }\n\n private renderHeader(file: FileContents) {\n const { headerRenderMode = 'default', stickyHeader = false } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n mode: headerRenderMode,\n stickyHeader,\n });\n }\n\n public renderFullHTML(result: FileRenderResult): string {\n return hastToHtml(this.renderFullAST(result));\n }\n\n public renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: this.renderCodeAST(result),\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n public renderCodeAST(result: FileRenderResult): ElementContent[] {\n const gutter = createGutterWrapper();\n gutter.children = result.gutterAST;\n gutter.properties.style = `grid-row: span ${result.rowCount}`;\n const contentColumn = createContentColumn(\n result.contentAST,\n result.rowCount\n );\n return [gutter, contentColumn];\n }\n\n public renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return hastToHtml(children);\n }\n return hastToHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n public initializeHighlighter(): Promise<DiffsHighlighter> {\n return getSharedHighlighter(\n getHighlighterOptions(this.computedLang, {\n theme: this.getLocalHighlightTheme(),\n preferredHighlighter: resolvePreferredHighlighter(\n this.workerManager,\n this.options\n ),\n })\n );\n }\n\n public onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n if (this.editSessionActive) {\n return;\n }\n this.applyHighlightResult(file, result, options, highlighted);\n }\n\n private applyHighlightResult(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions,\n highlighted = true\n ): void {\n const { file: currentFile, renderCache } = this;\n if (\n currentFile == null ||\n renderCache == null ||\n !areFileTargetsEqual(file, currentFile) ||\n !areFileRenderOptionsEqual(\n options,\n this.getRenderOptions(currentFile).options\n )\n ) {\n return;\n }\n\n const triggerRender =\n renderCache.result == null ||\n !renderCache.highlighted ||\n !areFileRenderOptionsEqual(renderCache.options, options) ||\n !areFileTargetsEqual(renderCache.file, currentFile);\n if (!triggerRender) {\n return;\n }\n\n this.pendingHighlightResult = {\n file: currentFile,\n options,\n highlighted,\n result,\n };\n this.onRenderUpdate?.();\n }\n\n private getMatchingWorkerResultCache(\n file: FileContents,\n options: RenderFileOptions\n ): RenderFileResult | undefined {\n if (this.editSessionActive) {\n return undefined;\n }\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache == null || !areFileRenderOptionsEqual(options, cache.options)) {\n return undefined;\n }\n return cache;\n }\n\n // Returns completed background work that can replace the rendered AST on\n // the next render. Reading it does not promote or discard pending work.\n private getReadyRenderResult(\n file: FileContents,\n options: RenderFileOptions\n ): PendingHighlightResult | undefined {\n const { pendingHighlightResult } = this;\n if (\n pendingHighlightResult != null &&\n areFileTargetsEqual(pendingHighlightResult.file, file) &&\n areFileRenderOptionsEqual(pendingHighlightResult.options, options)\n ) {\n return pendingHighlightResult;\n }\n\n const workerCache = this.getMatchingWorkerResultCache(file, options);\n if (workerCache == null || this.hasHighlightedRenderCache(file, options)) {\n return undefined;\n }\n return { file, highlighted: true, ...workerCache };\n }\n\n private hasHighlightedRenderCache(\n file: FileContents,\n options: RenderFileOptions\n ): boolean {\n const { renderCache } = this;\n return (\n renderCache?.result != null &&\n renderCache.highlighted &&\n areFileTargetsEqual(file, renderCache.file) &&\n areFileRenderOptionsEqual(options, renderCache.options)\n );\n }\n\n public onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private getTokenizeMaxLength(): number {\n return this.options.tokenizeMaxLength ?? DEFAULT_TOKENIZE_MAX_LENGTH;\n }\n\n private createPreElement(totalLines: number): HASTElement {\n const { disableLineNumbers = false, overflow = 'scroll' } = this.options;\n return createPreElement({\n type: 'file',\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction isFileMassive(lineCount: number, tokenizeMaxLength: number): boolean {\n return lineCount > tokenizeMaxLength;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,SAAS,mBAAmB,WAAsB,MAA6B;CAC7E,OAAO,KAAK,YAAY,OACpB,UAAU,SAAS,QAAQ,UAAU,mBAAmB,KAAK,WAC7D,UAAU,aAAa,KAAK;AAClC;AAMA,IAAI,aAAa;AAEjB,IAAa,eAAb,MAAmD;CAsCxC;CACC;CAGA;CACA;C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EACrC,OAAO,KAAK,QAAQ,qBAAA;CACtB;CAEA,iBAAyB,YAAiC;EACxD,MAAM,EAAE,qBAAqB,OAAO,WAAW,aAAa,KAAK;EACjE,OAAO,iBAAiB;GACtB,MAAM;GACN,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA,OAAO;GACP;EACF,CAAC;CACH;AACF;AAEA,SAAS,cAAc,WAAmB,mBAAoC;CAC5E,OAAO,YAAY;AACrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"UnresolvedFileHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/UnresolvedFileHunksRenderer.ts"],"mappings":";;;;;;;UA+DU,0CAA0C;EAClD,0BAA0B;;KAGvB;UAEY,2CAA2C;EAC1D,2BAA2B;;cAGhB,4BACX,iCACQ,kBAAkB;UAClB;UACA;UACA;EACQ,SAAS;EAEzB,YACE,UAAS,oCAGT,sBACE,YAAY,mBAAmB,yBAEjC,gCACA,gBAAgB;EAWX,iBACL,kBAAkB,wCAClB,YAAY,0BACZ,MAAM;UAOA;UA0BA;EAUQ,WACd,OAAO,8BACP,cAAa,cACZ;EAWmB,YACpB,MAAM,kBACN,cAAa,cACZ,QAAQ;YASQ,iBACjB,gBACA,qBACC;YAMgB,2BACjB,MACA,YACC,6BAA6B;YAiBb,yBACjB,MACA,QACC,2BAA2B;YAiBX,gCAA6B,KACzC,wBACJ;YAgCgB,0BAA0B"}
1
+ {"version":3,"file":"UnresolvedFileHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/UnresolvedFileHunksRenderer.ts"],"mappings":";;;;;;;UA+DU,0CAA0C;EAClD,0BAA0B;;KAGvB;UAEY,2CAA2C;EAC1D,2BAA2B;;cAGhB,4BACX,iCACQ,kBAAkB;UAClB;UACA;UACA;EACQ,SAAS;EAEzB,YACE,UAAS,oCAGT,sBACE,YAAY,mBAAmB,yBAEjC,gCACA,gBAAgB;EAMX,iBACL,kBAAkB,wCAClB,YAAY,0BACZ,MAAM;UAOA;UA0BA;EAUQ,WACd,OAAO,8BACP,cAAa,cACZ;EAWmB,YACpB,MAAM,kBACN,cAAa,cACZ,QAAQ;YASQ,iBACjB,gBACA,qBACC;YAMgB,2BACjB,MACA,YACC,6BAA6B;YAiBb,yBACjB,MACA,QACC,2BAA2B;YAiBX,gCAA6B,KACzC,wBACJ;YAgCgB,0BAA0B"}
@@ -40,7 +40,7 @@ var UnresolvedFileHunksRenderer = class extends DiffHunksRenderer {
40
40
  else rows.push(row);
41
41
  }
42
42
  renderDiff(diff, renderRange = DEFAULT_RENDER_RANGE) {
43
- if (diff != null) this.syncInjectedRows(this.pendingConflictActions, this.pendingMarkerRows, diff);
43
+ if (diff != null) this.syncInjectedRows(this.pendingConflictActions, this.pendingMarkerRows, this.getDiffForNextRender(diff));
44
44
  return super.renderDiff(diff, renderRange);
45
45
  }
46
46
  async asyncRender(diff, renderRange = DEFAULT_RENDER_RANGE) {