@deepseek-harness-tui/dsh-tui 0.5.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 (638) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/bin/dsh-tui.js +95 -0
  4. package/cordis.patch.yml +218 -0
  5. package/cordis.yml +185 -0
  6. package/lib/invariant.js +28 -0
  7. package/lib/types/activityPrefs.d.ts +29 -0
  8. package/lib/types/activityPrefs.d.ts.map +1 -0
  9. package/lib/types/activityPrefs.js +60 -0
  10. package/lib/types/bootstrap/state.d.ts +13 -0
  11. package/lib/types/bootstrap/state.d.ts.map +1 -0
  12. package/lib/types/bootstrap/state.js +12 -0
  13. package/lib/types/cc/cliHighlight.d.ts +20 -0
  14. package/lib/types/cc/cliHighlight.d.ts.map +1 -0
  15. package/lib/types/cc/cliHighlight.js +53 -0
  16. package/lib/types/cc/figures.d.ts +59 -0
  17. package/lib/types/cc/figures.d.ts.map +1 -0
  18. package/lib/types/cc/figures.js +69 -0
  19. package/lib/types/cc/format.d.ts +26 -0
  20. package/lib/types/cc/format.d.ts.map +1 -0
  21. package/lib/types/cc/format.js +55 -0
  22. package/lib/types/cc/hash.d.ts +25 -0
  23. package/lib/types/cc/hash.d.ts.map +1 -0
  24. package/lib/types/cc/hash.js +41 -0
  25. package/lib/types/cc/hyperlink.d.ts +21 -0
  26. package/lib/types/cc/hyperlink.d.ts.map +1 -0
  27. package/lib/types/cc/hyperlink.js +31 -0
  28. package/lib/types/cc/markdown.d.ts +43 -0
  29. package/lib/types/cc/markdown.d.ts.map +1 -0
  30. package/lib/types/cc/markdown.js +345 -0
  31. package/lib/types/cc/spinnerVerbs.d.ts +3 -0
  32. package/lib/types/cc/spinnerVerbs.d.ts.map +1 -0
  33. package/lib/types/cc/spinnerVerbs.js +190 -0
  34. package/lib/types/cc/terminal.d.ts +15 -0
  35. package/lib/types/cc/terminal.d.ts.map +1 -0
  36. package/lib/types/cc/terminal.js +84 -0
  37. package/lib/types/channel.d.ts +672 -0
  38. package/lib/types/channel.d.ts.map +1 -0
  39. package/lib/types/channel.js +2427 -0
  40. package/lib/types/childStderr.d.ts +63 -0
  41. package/lib/types/childStderr.d.ts.map +1 -0
  42. package/lib/types/childStderr.js +161 -0
  43. package/lib/types/commands.d.ts +55 -0
  44. package/lib/types/commands.d.ts.map +1 -0
  45. package/lib/types/commands.js +101 -0
  46. package/lib/types/components/ActivityLine.d.ts +29 -0
  47. package/lib/types/components/ActivityLine.d.ts.map +1 -0
  48. package/lib/types/components/ActivityLine.js +47 -0
  49. package/lib/types/components/ActivityPicker.d.ts +13 -0
  50. package/lib/types/components/ActivityPicker.d.ts.map +1 -0
  51. package/lib/types/components/ActivityPicker.js +24 -0
  52. package/lib/types/components/CommandSuggestions.d.ts +14 -0
  53. package/lib/types/components/CommandSuggestions.d.ts.map +1 -0
  54. package/lib/types/components/CommandSuggestions.js +33 -0
  55. package/lib/types/components/FileSuggestions.d.ts +12 -0
  56. package/lib/types/components/FileSuggestions.d.ts.map +1 -0
  57. package/lib/types/components/FileSuggestions.js +26 -0
  58. package/lib/types/components/GoalTodoPanel.d.ts +13 -0
  59. package/lib/types/components/GoalTodoPanel.d.ts.map +1 -0
  60. package/lib/types/components/GoalTodoPanel.js +57 -0
  61. package/lib/types/components/HelpMenu.d.ts +12 -0
  62. package/lib/types/components/HelpMenu.d.ts.map +1 -0
  63. package/lib/types/components/HelpMenu.js +12 -0
  64. package/lib/types/components/HistorySearchDialog.d.ts +16 -0
  65. package/lib/types/components/HistorySearchDialog.d.ts.map +1 -0
  66. package/lib/types/components/HistorySearchDialog.js +31 -0
  67. package/lib/types/components/InterruptedByUser.d.ts +7 -0
  68. package/lib/types/components/InterruptedByUser.d.ts.map +1 -0
  69. package/lib/types/components/InterruptedByUser.js +9 -0
  70. package/lib/types/components/LoadedContextPanel.d.ts +20 -0
  71. package/lib/types/components/LoadedContextPanel.d.ts.map +1 -0
  72. package/lib/types/components/LoadedContextPanel.js +30 -0
  73. package/lib/types/components/LogoV2.d.ts +23 -0
  74. package/lib/types/components/LogoV2.d.ts.map +1 -0
  75. package/lib/types/components/LogoV2.js +95 -0
  76. package/lib/types/components/Markdown.d.ts +24 -0
  77. package/lib/types/components/Markdown.d.ts.map +1 -0
  78. package/lib/types/components/Markdown.js +106 -0
  79. package/lib/types/components/MarkdownTable.d.ts +17 -0
  80. package/lib/types/components/MarkdownTable.d.ts.map +1 -0
  81. package/lib/types/components/MarkdownTable.js +272 -0
  82. package/lib/types/components/MessageList.d.ts +41 -0
  83. package/lib/types/components/MessageList.d.ts.map +1 -0
  84. package/lib/types/components/MessageList.js +303 -0
  85. package/lib/types/components/ModelPicker.d.ts +14 -0
  86. package/lib/types/components/ModelPicker.d.ts.map +1 -0
  87. package/lib/types/components/ModelPicker.js +15 -0
  88. package/lib/types/components/PresetPicker.d.ts +17 -0
  89. package/lib/types/components/PresetPicker.d.ts.map +1 -0
  90. package/lib/types/components/PresetPicker.js +25 -0
  91. package/lib/types/components/PromptInput.d.ts +67 -0
  92. package/lib/types/components/PromptInput.d.ts.map +1 -0
  93. package/lib/types/components/PromptInput.js +778 -0
  94. package/lib/types/components/ResumePicker.d.ts +15 -0
  95. package/lib/types/components/ResumePicker.d.ts.map +1 -0
  96. package/lib/types/components/ResumePicker.js +34 -0
  97. package/lib/types/components/RewindPicker.d.ts +14 -0
  98. package/lib/types/components/RewindPicker.d.ts.map +1 -0
  99. package/lib/types/components/RewindPicker.js +23 -0
  100. package/lib/types/components/SearchBox.d.ts +20 -0
  101. package/lib/types/components/SearchBox.d.ts.map +1 -0
  102. package/lib/types/components/SearchBox.js +33 -0
  103. package/lib/types/components/Select.d.ts +22 -0
  104. package/lib/types/components/Select.d.ts.map +1 -0
  105. package/lib/types/components/Select.js +19 -0
  106. package/lib/types/components/Spinner/GlimmerMessage.d.ts +19 -0
  107. package/lib/types/components/Spinner/GlimmerMessage.d.ts.map +1 -0
  108. package/lib/types/components/Spinner/GlimmerMessage.js +78 -0
  109. package/lib/types/components/Spinner/SpinnerAnimationRow.d.ts +31 -0
  110. package/lib/types/components/Spinner/SpinnerAnimationRow.d.ts.map +1 -0
  111. package/lib/types/components/Spinner/SpinnerAnimationRow.js +162 -0
  112. package/lib/types/components/Spinner/SpinnerGlyph.d.ts +16 -0
  113. package/lib/types/components/Spinner/SpinnerGlyph.d.ts.map +1 -0
  114. package/lib/types/components/Spinner/SpinnerGlyph.js +36 -0
  115. package/lib/types/components/Spinner/spinnerMode.d.ts +6 -0
  116. package/lib/types/components/Spinner/spinnerMode.d.ts.map +1 -0
  117. package/lib/types/components/Spinner/spinnerMode.js +1 -0
  118. package/lib/types/components/Spinner/spinnerUtils.d.ts +41 -0
  119. package/lib/types/components/Spinner/spinnerUtils.d.ts.map +1 -0
  120. package/lib/types/components/Spinner/spinnerUtils.js +104 -0
  121. package/lib/types/components/Spinner/useStalledAnimation.d.ts +16 -0
  122. package/lib/types/components/Spinner/useStalledAnimation.d.ts.map +1 -0
  123. package/lib/types/components/Spinner/useStalledAnimation.js +71 -0
  124. package/lib/types/components/StreamingMarkdown.d.ts +12 -0
  125. package/lib/types/components/StreamingMarkdown.d.ts.map +1 -0
  126. package/lib/types/components/StreamingMarkdown.js +39 -0
  127. package/lib/types/components/ThemePicker.d.ts +22 -0
  128. package/lib/types/components/ThemePicker.d.ts.map +1 -0
  129. package/lib/types/components/ThemePicker.js +51 -0
  130. package/lib/types/components/ThinkingToggle.d.ts +17 -0
  131. package/lib/types/components/ThinkingToggle.d.ts.map +1 -0
  132. package/lib/types/components/ThinkingToggle.js +30 -0
  133. package/lib/types/components/ToolUseLoader.d.ts +13 -0
  134. package/lib/types/components/ToolUseLoader.d.ts.map +1 -0
  135. package/lib/types/components/ToolUseLoader.js +17 -0
  136. package/lib/types/components/Whale.d.ts +22 -0
  137. package/lib/types/components/Whale.d.ts.map +1 -0
  138. package/lib/types/components/Whale.js +78 -0
  139. package/lib/types/components/WorkingSpinner.d.ts +26 -0
  140. package/lib/types/components/WorkingSpinner.d.ts.map +1 -0
  141. package/lib/types/components/WorkingSpinner.js +68 -0
  142. package/lib/types/components/activityFrames.d.ts +31 -0
  143. package/lib/types/components/activityFrames.d.ts.map +1 -0
  144. package/lib/types/components/activityFrames.js +83 -0
  145. package/lib/types/components/bigfont.d.ts +28 -0
  146. package/lib/types/components/bigfont.d.ts.map +1 -0
  147. package/lib/types/components/bigfont.js +91 -0
  148. package/lib/types/components/design-system/Byline.d.ts +14 -0
  149. package/lib/types/components/design-system/Byline.d.ts.map +1 -0
  150. package/lib/types/components/design-system/Byline.js +17 -0
  151. package/lib/types/components/design-system/Divider.d.ts +40 -0
  152. package/lib/types/components/design-system/Divider.d.ts.map +1 -0
  153. package/lib/types/components/design-system/Divider.js +24 -0
  154. package/lib/types/components/design-system/KeyboardShortcutHint.d.ts +19 -0
  155. package/lib/types/components/design-system/KeyboardShortcutHint.d.ts.map +1 -0
  156. package/lib/types/components/design-system/KeyboardShortcutHint.js +14 -0
  157. package/lib/types/components/design-system/ListItem.d.ts +36 -0
  158. package/lib/types/components/design-system/ListItem.d.ts.map +1 -0
  159. package/lib/types/components/design-system/ListItem.js +48 -0
  160. package/lib/types/components/design-system/LoadingState.d.ts +19 -0
  161. package/lib/types/components/design-system/LoadingState.d.ts.map +1 -0
  162. package/lib/types/components/design-system/LoadingState.js +22 -0
  163. package/lib/types/components/design-system/Pane.d.ts +17 -0
  164. package/lib/types/components/design-system/Pane.d.ts.map +1 -0
  165. package/lib/types/components/design-system/Pane.js +15 -0
  166. package/lib/types/components/design-system/ProgressBar.d.ts +22 -0
  167. package/lib/types/components/design-system/ProgressBar.d.ts.map +1 -0
  168. package/lib/types/components/design-system/ProgressBar.js +27 -0
  169. package/lib/types/components/design-system/StatusIcon.d.ts +15 -0
  170. package/lib/types/components/design-system/StatusIcon.d.ts.map +1 -0
  171. package/lib/types/components/design-system/StatusIcon.js +20 -0
  172. package/lib/types/components/design-system/ThemeProvider.d.ts +11 -0
  173. package/lib/types/components/design-system/ThemeProvider.d.ts.map +1 -0
  174. package/lib/types/components/design-system/ThemeProvider.js +135 -0
  175. package/lib/types/components/design-system/ThemedBox.d.ts +37 -0
  176. package/lib/types/components/design-system/ThemedBox.d.ts.map +1 -0
  177. package/lib/types/components/design-system/ThemedBox.js +26 -0
  178. package/lib/types/components/design-system/ThemedText.d.ts +56 -0
  179. package/lib/types/components/design-system/ThemedText.d.ts.map +1 -0
  180. package/lib/types/components/design-system/ThemedText.js +45 -0
  181. package/lib/types/components/messages/AssistantTextMessage.d.ts +18 -0
  182. package/lib/types/components/messages/AssistantTextMessage.d.ts.map +1 -0
  183. package/lib/types/components/messages/AssistantTextMessage.js +15 -0
  184. package/lib/types/components/messages/AssistantThinkingMessage.d.ts +23 -0
  185. package/lib/types/components/messages/AssistantThinkingMessage.d.ts.map +1 -0
  186. package/lib/types/components/messages/AssistantThinkingMessage.js +23 -0
  187. package/lib/types/components/messages/AssistantToolUseMessage.d.ts +23 -0
  188. package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -0
  189. package/lib/types/components/messages/AssistantToolUseMessage.js +220 -0
  190. package/lib/types/components/messages/MessageMetadata.d.ts +15 -0
  191. package/lib/types/components/messages/MessageMetadata.d.ts.map +1 -0
  192. package/lib/types/components/messages/MessageMetadata.js +20 -0
  193. package/lib/types/components/messages/UserPromptMessage.d.ts +19 -0
  194. package/lib/types/components/messages/UserPromptMessage.d.ts.map +1 -0
  195. package/lib/types/components/messages/UserPromptMessage.js +15 -0
  196. package/lib/types/components/questions/AskUserQuestionPanel.d.ts +39 -0
  197. package/lib/types/components/questions/AskUserQuestionPanel.d.ts.map +1 -0
  198. package/lib/types/components/questions/AskUserQuestionPanel.js +228 -0
  199. package/lib/types/components/shimmer.d.ts +35 -0
  200. package/lib/types/components/shimmer.d.ts.map +1 -0
  201. package/lib/types/components/shimmer.js +43 -0
  202. package/lib/types/components/whaleFrames.d.ts +25 -0
  203. package/lib/types/components/whaleFrames.d.ts.map +1 -0
  204. package/lib/types/components/whaleFrames.js +419 -0
  205. package/lib/types/customTheme.d.ts +104 -0
  206. package/lib/types/customTheme.d.ts.map +1 -0
  207. package/lib/types/customTheme.js +268 -0
  208. package/lib/types/effortPrefs.d.ts +22 -0
  209. package/lib/types/effortPrefs.d.ts.map +1 -0
  210. package/lib/types/effortPrefs.js +45 -0
  211. package/lib/types/history.d.ts +24 -0
  212. package/lib/types/history.d.ts.map +1 -0
  213. package/lib/types/history.js +75 -0
  214. package/lib/types/hooks/useBlink.d.ts +11 -0
  215. package/lib/types/hooks/useBlink.d.ts.map +1 -0
  216. package/lib/types/hooks/useBlink.js +20 -0
  217. package/lib/types/i18n.d.ts +926 -0
  218. package/lib/types/i18n.d.ts.map +1 -0
  219. package/lib/types/i18n.js +356 -0
  220. package/lib/types/index.d.ts +70 -0
  221. package/lib/types/index.d.ts.map +1 -0
  222. package/lib/types/index.js +31 -0
  223. package/lib/types/ink/Ansi.d.ts +11 -0
  224. package/lib/types/ink/Ansi.d.ts.map +1 -0
  225. package/lib/types/ink/Ansi.js +269 -0
  226. package/lib/types/ink/bidi.d.ts +18 -0
  227. package/lib/types/ink/bidi.d.ts.map +1 -0
  228. package/lib/types/ink/bidi.js +119 -0
  229. package/lib/types/ink/clearTerminal.d.ts +22 -0
  230. package/lib/types/ink/clearTerminal.d.ts.map +1 -0
  231. package/lib/types/ink/clearTerminal.js +72 -0
  232. package/lib/types/ink/colorize.d.ts +33 -0
  233. package/lib/types/ink/colorize.d.ts.map +1 -0
  234. package/lib/types/ink/colorize.js +213 -0
  235. package/lib/types/ink/components/AlternateScreen.d.ts +22 -0
  236. package/lib/types/ink/components/AlternateScreen.d.ts.map +1 -0
  237. package/lib/types/ink/components/AlternateScreen.js +74 -0
  238. package/lib/types/ink/components/App.d.ts +73 -0
  239. package/lib/types/ink/components/App.d.ts.map +1 -0
  240. package/lib/types/ink/components/App.js +597 -0
  241. package/lib/types/ink/components/AppContext.d.ts +15 -0
  242. package/lib/types/ink/components/AppContext.d.ts.map +1 -0
  243. package/lib/types/ink/components/AppContext.js +11 -0
  244. package/lib/types/ink/components/Box.d.ts +49 -0
  245. package/lib/types/ink/components/Box.d.ts.map +1 -0
  246. package/lib/types/ink/components/Box.js +153 -0
  247. package/lib/types/ink/components/Button.d.ts +37 -0
  248. package/lib/types/ink/components/Button.d.ts.map +1 -0
  249. package/lib/types/ink/components/Button.js +166 -0
  250. package/lib/types/ink/components/ClockContext.d.ts +10 -0
  251. package/lib/types/ink/components/ClockContext.d.ts.map +1 -0
  252. package/lib/types/ink/components/ClockContext.js +108 -0
  253. package/lib/types/ink/components/CursorDeclarationContext.d.ts +30 -0
  254. package/lib/types/ink/components/CursorDeclarationContext.d.ts.map +1 -0
  255. package/lib/types/ink/components/CursorDeclarationContext.js +6 -0
  256. package/lib/types/ink/components/ErrorOverview.d.ts +7 -0
  257. package/lib/types/ink/components/ErrorOverview.d.ts.map +1 -0
  258. package/lib/types/ink/components/ErrorOverview.js +49 -0
  259. package/lib/types/ink/components/Link.d.ts +8 -0
  260. package/lib/types/ink/components/Link.d.ts.map +1 -0
  261. package/lib/types/ink/components/Link.js +33 -0
  262. package/lib/types/ink/components/Newline.d.ts +13 -0
  263. package/lib/types/ink/components/Newline.d.ts.map +1 -0
  264. package/lib/types/ink/components/Newline.js +29 -0
  265. package/lib/types/ink/components/NoSelect.d.ts +20 -0
  266. package/lib/types/ink/components/NoSelect.d.ts.map +1 -0
  267. package/lib/types/ink/components/NoSelect.js +56 -0
  268. package/lib/types/ink/components/RawAnsi.d.ts +17 -0
  269. package/lib/types/ink/components/RawAnsi.d.ts.map +1 -0
  270. package/lib/types/ink/components/RawAnsi.js +45 -0
  271. package/lib/types/ink/components/ScrollBox.d.ts +78 -0
  272. package/lib/types/ink/components/ScrollBox.d.ts.map +1 -0
  273. package/lib/types/ink/components/ScrollBox.js +174 -0
  274. package/lib/types/ink/components/Spacer.d.ts +6 -0
  275. package/lib/types/ink/components/Spacer.d.ts.map +1 -0
  276. package/lib/types/ink/components/Spacer.js +19 -0
  277. package/lib/types/ink/components/StdinContext.d.ts +32 -0
  278. package/lib/types/ink/components/StdinContext.d.ts.map +1 -0
  279. package/lib/types/ink/components/StdinContext.js +16 -0
  280. package/lib/types/ink/components/TerminalFocusContext.d.ts +11 -0
  281. package/lib/types/ink/components/TerminalFocusContext.d.ts.map +1 -0
  282. package/lib/types/ink/components/TerminalFocusContext.js +45 -0
  283. package/lib/types/ink/components/TerminalSizeContext.d.ts +6 -0
  284. package/lib/types/ink/components/TerminalSizeContext.d.ts.map +1 -0
  285. package/lib/types/ink/components/TerminalSizeContext.js +3 -0
  286. package/lib/types/ink/components/Text.d.ts +56 -0
  287. package/lib/types/ink/components/Text.d.ts.map +1 -0
  288. package/lib/types/ink/components/Text.js +194 -0
  289. package/lib/types/ink/constants.d.ts +3 -0
  290. package/lib/types/ink/constants.d.ts.map +1 -0
  291. package/lib/types/ink/constants.js +2 -0
  292. package/lib/types/ink/cursor.d.ts +11 -0
  293. package/lib/types/ink/cursor.d.ts.map +1 -0
  294. package/lib/types/ink/cursor.js +1 -0
  295. package/lib/types/ink/devtools.d.ts +7 -0
  296. package/lib/types/ink/devtools.d.ts.map +1 -0
  297. package/lib/types/ink/devtools.js +1 -0
  298. package/lib/types/ink/dom.d.ts +178 -0
  299. package/lib/types/ink/dom.d.ts.map +1 -0
  300. package/lib/types/ink/dom.js +424 -0
  301. package/lib/types/ink/events/click-event.d.ts +32 -0
  302. package/lib/types/ink/events/click-event.d.ts.map +1 -0
  303. package/lib/types/ink/events/click-event.js +36 -0
  304. package/lib/types/ink/events/dispatcher.d.ts +63 -0
  305. package/lib/types/ink/events/dispatcher.d.ts.map +1 -0
  306. package/lib/types/ink/events/dispatcher.js +194 -0
  307. package/lib/types/ink/events/emitter.d.ts +20 -0
  308. package/lib/types/ink/events/emitter.d.ts.map +1 -0
  309. package/lib/types/ink/events/emitter.js +43 -0
  310. package/lib/types/ink/events/event-handlers.d.ts +47 -0
  311. package/lib/types/ink/events/event-handlers.d.ts.map +1 -0
  312. package/lib/types/ink/events/event-handlers.js +30 -0
  313. package/lib/types/ink/events/event.d.ts +19 -0
  314. package/lib/types/ink/events/event.d.ts.map +1 -0
  315. package/lib/types/ink/events/event.js +22 -0
  316. package/lib/types/ink/events/focus-event.d.ts +19 -0
  317. package/lib/types/ink/events/focus-event.d.ts.map +1 -0
  318. package/lib/types/ink/events/focus-event.js +21 -0
  319. package/lib/types/ink/events/input-event.d.ts +53 -0
  320. package/lib/types/ink/events/input-event.d.ts.map +1 -0
  321. package/lib/types/ink/events/input-event.js +180 -0
  322. package/lib/types/ink/events/keyboard-event.d.ts +40 -0
  323. package/lib/types/ink/events/keyboard-event.d.ts.map +1 -0
  324. package/lib/types/ink/events/keyboard-event.js +65 -0
  325. package/lib/types/ink/events/paste-event.d.ts +11 -0
  326. package/lib/types/ink/events/paste-event.d.ts.map +1 -0
  327. package/lib/types/ink/events/paste-event.js +13 -0
  328. package/lib/types/ink/events/resize-event.d.ts +13 -0
  329. package/lib/types/ink/events/resize-event.d.ts.map +1 -0
  330. package/lib/types/ink/events/resize-event.js +16 -0
  331. package/lib/types/ink/events/terminal-event.d.ts +112 -0
  332. package/lib/types/ink/events/terminal-event.d.ts.map +1 -0
  333. package/lib/types/ink/events/terminal-event.js +131 -0
  334. package/lib/types/ink/events/terminal-focus-event.d.ts +21 -0
  335. package/lib/types/ink/events/terminal-focus-event.d.ts.map +1 -0
  336. package/lib/types/ink/events/terminal-focus-event.js +18 -0
  337. package/lib/types/ink/focus.d.ts +74 -0
  338. package/lib/types/ink/focus.d.ts.map +1 -0
  339. package/lib/types/ink/focus.js +188 -0
  340. package/lib/types/ink/frame.d.ts +119 -0
  341. package/lib/types/ink/frame.d.ts.map +1 -0
  342. package/lib/types/ink/frame.js +43 -0
  343. package/lib/types/ink/get-max-width.d.ts +20 -0
  344. package/lib/types/ink/get-max-width.d.ts.map +1 -0
  345. package/lib/types/ink/get-max-width.js +25 -0
  346. package/lib/types/ink/hit-test.d.ts +47 -0
  347. package/lib/types/ink/hit-test.d.ts.map +1 -0
  348. package/lib/types/ink/hit-test.js +126 -0
  349. package/lib/types/ink/hooks/use-animation-frame.d.ts +27 -0
  350. package/lib/types/ink/hooks/use-animation-frame.d.ts.map +1 -0
  351. package/lib/types/ink/hooks/use-animation-frame.js +48 -0
  352. package/lib/types/ink/hooks/use-app.d.ts +8 -0
  353. package/lib/types/ink/hooks/use-app.d.ts.map +1 -0
  354. package/lib/types/ink/hooks/use-app.js +8 -0
  355. package/lib/types/ink/hooks/use-copy-on-select.d.ts +22 -0
  356. package/lib/types/ink/hooks/use-copy-on-select.d.ts.map +1 -0
  357. package/lib/types/ink/hooks/use-copy-on-select.js +40 -0
  358. package/lib/types/ink/hooks/use-declared-cursor.d.ts +31 -0
  359. package/lib/types/ink/hooks/use-declared-cursor.d.ts.map +1 -0
  360. package/lib/types/ink/hooks/use-declared-cursor.js +65 -0
  361. package/lib/types/ink/hooks/use-input.d.ts +41 -0
  362. package/lib/types/ink/hooks/use-input.d.ts.map +1 -0
  363. package/lib/types/ink/hooks/use-input.js +73 -0
  364. package/lib/types/ink/hooks/use-interval.d.ts +23 -0
  365. package/lib/types/ink/hooks/use-interval.d.ts.map +1 -0
  366. package/lib/types/ink/hooks/use-interval.js +58 -0
  367. package/lib/types/ink/hooks/use-search-highlight.d.ts +34 -0
  368. package/lib/types/ink/hooks/use-search-highlight.d.ts.map +1 -0
  369. package/lib/types/ink/hooks/use-search-highlight.js +35 -0
  370. package/lib/types/ink/hooks/use-selection.d.ts +44 -0
  371. package/lib/types/ink/hooks/use-selection.d.ts.map +1 -0
  372. package/lib/types/ink/hooks/use-selection.js +64 -0
  373. package/lib/types/ink/hooks/use-stdin.d.ts +8 -0
  374. package/lib/types/ink/hooks/use-stdin.d.ts.map +1 -0
  375. package/lib/types/ink/hooks/use-stdin.js +8 -0
  376. package/lib/types/ink/hooks/use-tab-status.d.ts +18 -0
  377. package/lib/types/ink/hooks/use-tab-status.d.ts.map +1 -0
  378. package/lib/types/ink/hooks/use-tab-status.js +58 -0
  379. package/lib/types/ink/hooks/use-terminal-focus.d.ts +11 -0
  380. package/lib/types/ink/hooks/use-terminal-focus.d.ts.map +1 -0
  381. package/lib/types/ink/hooks/use-terminal-focus.js +15 -0
  382. package/lib/types/ink/hooks/use-terminal-size.d.ts +6 -0
  383. package/lib/types/ink/hooks/use-terminal-size.d.ts.map +1 -0
  384. package/lib/types/ink/hooks/use-terminal-size.js +12 -0
  385. package/lib/types/ink/hooks/use-terminal-title.d.ts +14 -0
  386. package/lib/types/ink/hooks/use-terminal-title.d.ts.map +1 -0
  387. package/lib/types/ink/hooks/use-terminal-title.js +30 -0
  388. package/lib/types/ink/hooks/use-terminal-viewport.d.ts +32 -0
  389. package/lib/types/ink/hooks/use-terminal-viewport.d.ts.map +1 -0
  390. package/lib/types/ink/hooks/use-terminal-viewport.js +79 -0
  391. package/lib/types/ink/ink.d.ts +370 -0
  392. package/lib/types/ink/ink.d.ts.map +1 -0
  393. package/lib/types/ink/ink.js +1665 -0
  394. package/lib/types/ink/instances.d.ts +10 -0
  395. package/lib/types/ink/instances.d.ts.map +1 -0
  396. package/lib/types/ink/instances.js +13 -0
  397. package/lib/types/ink/layout/engine.d.ts +7 -0
  398. package/lib/types/ink/layout/engine.d.ts.map +1 -0
  399. package/lib/types/ink/layout/engine.js +8 -0
  400. package/lib/types/ink/layout/geometry.d.ts +86 -0
  401. package/lib/types/ink/layout/geometry.d.ts.map +1 -0
  402. package/lib/types/ink/layout/geometry.js +95 -0
  403. package/lib/types/ink/layout/node.d.ts +151 -0
  404. package/lib/types/ink/layout/node.d.ts.map +1 -0
  405. package/lib/types/ink/layout/node.js +72 -0
  406. package/lib/types/ink/layout/yoga.d.ts +69 -0
  407. package/lib/types/ink/layout/yoga.d.ts.map +1 -0
  408. package/lib/types/ink/layout/yoga.js +249 -0
  409. package/lib/types/ink/line-width-cache.d.ts +9 -0
  410. package/lib/types/ink/line-width-cache.d.ts.map +1 -0
  411. package/lib/types/ink/line-width-cache.js +45 -0
  412. package/lib/types/ink/log-update.d.ts +57 -0
  413. package/lib/types/ink/log-update.d.ts.map +1 -0
  414. package/lib/types/ink/log-update.js +710 -0
  415. package/lib/types/ink/measure-element.d.ts +19 -0
  416. package/lib/types/ink/measure-element.d.ts.map +1 -0
  417. package/lib/types/ink/measure-element.js +10 -0
  418. package/lib/types/ink/measure-text.d.ts +13 -0
  419. package/lib/types/ink/measure-text.d.ts.map +1 -0
  420. package/lib/types/ink/measure-text.js +38 -0
  421. package/lib/types/ink/node-cache.d.ts +33 -0
  422. package/lib/types/ink/node-cache.d.ts.map +1 -0
  423. package/lib/types/ink/node-cache.js +42 -0
  424. package/lib/types/ink/optimizer.d.ts +18 -0
  425. package/lib/types/ink/optimizer.d.ts.map +1 -0
  426. package/lib/types/ink/optimizer.js +83 -0
  427. package/lib/types/ink/output.d.ts +200 -0
  428. package/lib/types/ink/output.d.ts.map +1 -0
  429. package/lib/types/ink/output.js +663 -0
  430. package/lib/types/ink/parse-keypress.d.ts +132 -0
  431. package/lib/types/ink/parse-keypress.d.ts.map +1 -0
  432. package/lib/types/ink/parse-keypress.js +707 -0
  433. package/lib/types/ink/reconciler.d.ts +43 -0
  434. package/lib/types/ink/reconciler.d.ts.map +1 -0
  435. package/lib/types/ink/reconciler.js +413 -0
  436. package/lib/types/ink/render-border.d.ts +36 -0
  437. package/lib/types/ink/render-border.d.ts.map +1 -0
  438. package/lib/types/ink/render-border.js +143 -0
  439. package/lib/types/ink/render-node-to-output.d.ts +93 -0
  440. package/lib/types/ink/render-node-to-output.d.ts.map +1 -0
  441. package/lib/types/ink/render-node-to-output.js +1290 -0
  442. package/lib/types/ink/render-to-screen.d.ts +65 -0
  443. package/lib/types/ink/render-to-screen.d.ts.map +1 -0
  444. package/lib/types/ink/render-to-screen.js +189 -0
  445. package/lib/types/ink/renderer.d.ts +24 -0
  446. package/lib/types/ink/renderer.d.ts.map +1 -0
  447. package/lib/types/ink/renderer.js +136 -0
  448. package/lib/types/ink/root.d.ts +91 -0
  449. package/lib/types/ink/root.d.ts.map +1 -0
  450. package/lib/types/ink/root.js +93 -0
  451. package/lib/types/ink/screen.d.ts +443 -0
  452. package/lib/types/ink/screen.d.ts.map +1 -0
  453. package/lib/types/ink/screen.js +1295 -0
  454. package/lib/types/ink/searchHighlight.d.ts +25 -0
  455. package/lib/types/ink/searchHighlight.d.ts.map +1 -0
  456. package/lib/types/ink/searchHighlight.js +82 -0
  457. package/lib/types/ink/selection.d.ts +323 -0
  458. package/lib/types/ink/selection.d.ts.map +1 -0
  459. package/lib/types/ink/selection.js +881 -0
  460. package/lib/types/ink/squash-text-nodes.d.ts +30 -0
  461. package/lib/types/ink/squash-text-nodes.d.ts.map +1 -0
  462. package/lib/types/ink/squash-text-nodes.js +63 -0
  463. package/lib/types/ink/stringWidth.d.ts +11 -0
  464. package/lib/types/ink/stringWidth.d.ts.map +1 -0
  465. package/lib/types/ink/stringWidth.js +209 -0
  466. package/lib/types/ink/styles.d.ts +324 -0
  467. package/lib/types/ink/styles.d.ts.map +1 -0
  468. package/lib/types/ink/styles.js +307 -0
  469. package/lib/types/ink/supports-hyperlinks.d.ts +20 -0
  470. package/lib/types/ink/supports-hyperlinks.d.ts.map +1 -0
  471. package/lib/types/ink/supports-hyperlinks.js +44 -0
  472. package/lib/types/ink/tabstops.d.ts +9 -0
  473. package/lib/types/ink/tabstops.d.ts.map +1 -0
  474. package/lib/types/ink/tabstops.js +46 -0
  475. package/lib/types/ink/terminal-focus-state.d.ts +35 -0
  476. package/lib/types/ink/terminal-focus-state.d.ts.map +1 -0
  477. package/lib/types/ink/terminal-focus-state.js +57 -0
  478. package/lib/types/ink/terminal-querier.d.ts +161 -0
  479. package/lib/types/ink/terminal-querier.d.ts.map +1 -0
  480. package/lib/types/ink/terminal-querier.js +204 -0
  481. package/lib/types/ink/terminal.d.ts +80 -0
  482. package/lib/types/ink/terminal.d.ts.map +1 -0
  483. package/lib/types/ink/terminal.js +268 -0
  484. package/lib/types/ink/termio/ansi.d.ts +75 -0
  485. package/lib/types/ink/termio/ansi.d.ts.map +1 -0
  486. package/lib/types/ink/termio/ansi.js +79 -0
  487. package/lib/types/ink/termio/csi.d.ts +253 -0
  488. package/lib/types/ink/termio/csi.d.ts.map +1 -0
  489. package/lib/types/ink/termio/csi.js +347 -0
  490. package/lib/types/ink/termio/dec.d.ts +61 -0
  491. package/lib/types/ink/termio/dec.d.ts.map +1 -0
  492. package/lib/types/ink/termio/dec.js +76 -0
  493. package/lib/types/ink/termio/esc.d.ts +15 -0
  494. package/lib/types/ink/termio/esc.d.ts.map +1 -0
  495. package/lib/types/ink/termio/esc.js +57 -0
  496. package/lib/types/ink/termio/osc.d.ts +208 -0
  497. package/lib/types/ink/termio/osc.d.ts.map +1 -0
  498. package/lib/types/ink/termio/osc.js +466 -0
  499. package/lib/types/ink/termio/parser.d.ts +46 -0
  500. package/lib/types/ink/termio/parser.d.ts.map +1 -0
  501. package/lib/types/ink/termio/parser.js +366 -0
  502. package/lib/types/ink/termio/sgr.d.ts +17 -0
  503. package/lib/types/ink/termio/sgr.d.ts.map +1 -0
  504. package/lib/types/ink/termio/sgr.js +300 -0
  505. package/lib/types/ink/termio/tokenize.d.ts +50 -0
  506. package/lib/types/ink/termio/tokenize.d.ts.map +1 -0
  507. package/lib/types/ink/termio/tokenize.js +266 -0
  508. package/lib/types/ink/termio/types.d.ts +211 -0
  509. package/lib/types/ink/termio/types.d.ts.map +1 -0
  510. package/lib/types/ink/termio/types.js +68 -0
  511. package/lib/types/ink/termio.d.ts +25 -0
  512. package/lib/types/ink/termio.d.ts.map +1 -0
  513. package/lib/types/ink/termio.js +24 -0
  514. package/lib/types/ink/truncateToWidth.d.ts +7 -0
  515. package/lib/types/ink/truncateToWidth.d.ts.map +1 -0
  516. package/lib/types/ink/truncateToWidth.js +18 -0
  517. package/lib/types/ink/useTerminalNotification.d.ts +45 -0
  518. package/lib/types/ink/useTerminalNotification.d.ts.map +1 -0
  519. package/lib/types/ink/useTerminalNotification.js +70 -0
  520. package/lib/types/ink/warn.d.ts +7 -0
  521. package/lib/types/ink/warn.d.ts.map +1 -0
  522. package/lib/types/ink/warn.js +15 -0
  523. package/lib/types/ink/widest-line.d.ts +7 -0
  524. package/lib/types/ink/widest-line.d.ts.map +1 -0
  525. package/lib/types/ink/widest-line.js +19 -0
  526. package/lib/types/ink/wrap-text.d.ts +10 -0
  527. package/lib/types/ink/wrap-text.d.ts.map +1 -0
  528. package/lib/types/ink/wrap-text.js +61 -0
  529. package/lib/types/ink/wrapAnsi.d.ts +18 -0
  530. package/lib/types/ink/wrapAnsi.d.ts.map +1 -0
  531. package/lib/types/ink/wrapAnsi.js +16 -0
  532. package/lib/types/invariant.d.ts +20 -0
  533. package/lib/types/invariant.d.ts.map +1 -0
  534. package/lib/types/invariant.js +26 -0
  535. package/lib/types/modelPrefs.d.ts +37 -0
  536. package/lib/types/modelPrefs.d.ts.map +1 -0
  537. package/lib/types/modelPrefs.js +66 -0
  538. package/lib/types/modelRoute.d.ts +79 -0
  539. package/lib/types/modelRoute.d.ts.map +1 -0
  540. package/lib/types/modelRoute.js +96 -0
  541. package/lib/types/native-ts/yoga-layout/enums.d.ts +183 -0
  542. package/lib/types/native-ts/yoga-layout/enums.d.ts.map +1 -0
  543. package/lib/types/native-ts/yoga-layout/enums.js +150 -0
  544. package/lib/types/native-ts/yoga-layout/index.d.ts +788 -0
  545. package/lib/types/native-ts/yoga-layout/index.d.ts.map +1 -0
  546. package/lib/types/native-ts/yoga-layout/index.js +2571 -0
  547. package/lib/types/packaged-skills.d.ts +10 -0
  548. package/lib/types/packaged-skills.d.ts.map +1 -0
  549. package/lib/types/packaged-skills.js +63 -0
  550. package/lib/types/plugin.d.ts +33 -0
  551. package/lib/types/plugin.d.ts.map +1 -0
  552. package/lib/types/plugin.js +454 -0
  553. package/lib/types/presetPrefs.d.ts +29 -0
  554. package/lib/types/presetPrefs.d.ts.map +1 -0
  555. package/lib/types/presetPrefs.js +61 -0
  556. package/lib/types/presets.d.ts +110 -0
  557. package/lib/types/presets.d.ts.map +1 -0
  558. package/lib/types/presets.js +114 -0
  559. package/lib/types/questions.d.ts +97 -0
  560. package/lib/types/questions.d.ts.map +1 -0
  561. package/lib/types/questions.js +201 -0
  562. package/lib/types/screens/Chat.d.ts +23 -0
  563. package/lib/types/screens/Chat.d.ts.map +1 -0
  564. package/lib/types/screens/Chat.js +1263 -0
  565. package/lib/types/screens/StatusLine.d.ts +16 -0
  566. package/lib/types/screens/StatusLine.d.ts.map +1 -0
  567. package/lib/types/screens/StatusLine.js +105 -0
  568. package/lib/types/screens/StatusMetrics.d.ts +87 -0
  569. package/lib/types/screens/StatusMetrics.d.ts.map +1 -0
  570. package/lib/types/screens/StatusMetrics.js +252 -0
  571. package/lib/types/sessionHistory.d.ts +32 -0
  572. package/lib/types/sessionHistory.d.ts.map +1 -0
  573. package/lib/types/sessionHistory.js +87 -0
  574. package/lib/types/theme.d.ts +115 -0
  575. package/lib/types/theme.d.ts.map +1 -0
  576. package/lib/types/theme.js +300 -0
  577. package/lib/types/themePrefs.d.ts +28 -0
  578. package/lib/types/themePrefs.d.ts.map +1 -0
  579. package/lib/types/themePrefs.js +59 -0
  580. package/lib/types/ui.d.ts +28 -0
  581. package/lib/types/ui.d.ts.map +1 -0
  582. package/lib/types/ui.js +25 -0
  583. package/lib/types/update.d.ts +76 -0
  584. package/lib/types/update.d.ts.map +1 -0
  585. package/lib/types/update.js +203 -0
  586. package/lib/types/utils/clipboard.d.ts +43 -0
  587. package/lib/types/utils/clipboard.d.ts.map +1 -0
  588. package/lib/types/utils/clipboard.js +82 -0
  589. package/lib/types/utils/debug.d.ts +8 -0
  590. package/lib/types/utils/debug.d.ts.map +1 -0
  591. package/lib/types/utils/debug.js +12 -0
  592. package/lib/types/utils/earlyInput.d.ts +7 -0
  593. package/lib/types/utils/earlyInput.d.ts.map +1 -0
  594. package/lib/types/utils/earlyInput.js +6 -0
  595. package/lib/types/utils/env.d.ts +10 -0
  596. package/lib/types/utils/env.d.ts.map +1 -0
  597. package/lib/types/utils/env.js +9 -0
  598. package/lib/types/utils/envUtils.d.ts +8 -0
  599. package/lib/types/utils/envUtils.d.ts.map +1 -0
  600. package/lib/types/utils/envUtils.js +13 -0
  601. package/lib/types/utils/execFileNoThrow.d.ts +34 -0
  602. package/lib/types/utils/execFileNoThrow.d.ts.map +1 -0
  603. package/lib/types/utils/execFileNoThrow.js +31 -0
  604. package/lib/types/utils/fullscreen.d.ts +8 -0
  605. package/lib/types/utils/fullscreen.d.ts.map +1 -0
  606. package/lib/types/utils/fullscreen.js +10 -0
  607. package/lib/types/utils/intl.d.ts +7 -0
  608. package/lib/types/utils/intl.d.ts.map +1 -0
  609. package/lib/types/utils/intl.js +9 -0
  610. package/lib/types/utils/loaded-context.d.ts +20 -0
  611. package/lib/types/utils/loaded-context.d.ts.map +1 -0
  612. package/lib/types/utils/loaded-context.js +36 -0
  613. package/lib/types/utils/log.d.ts +7 -0
  614. package/lib/types/utils/log.d.ts.map +1 -0
  615. package/lib/types/utils/log.js +9 -0
  616. package/lib/types/utils/mentions.d.ts +30 -0
  617. package/lib/types/utils/mentions.d.ts.map +1 -0
  618. package/lib/types/utils/mentions.js +72 -0
  619. package/lib/types/utils/narration.d.ts +11 -0
  620. package/lib/types/utils/narration.d.ts.map +1 -0
  621. package/lib/types/utils/narration.js +16 -0
  622. package/lib/types/utils/semver.d.ts +9 -0
  623. package/lib/types/utils/semver.d.ts.map +1 -0
  624. package/lib/types/utils/semver.js +24 -0
  625. package/lib/types/utils/sliceAnsi.d.ts +12 -0
  626. package/lib/types/utils/sliceAnsi.d.ts.map +1 -0
  627. package/lib/types/utils/sliceAnsi.js +79 -0
  628. package/lib/types/working-activity.d.ts +19 -0
  629. package/lib/types/working-activity.d.ts.map +1 -0
  630. package/lib/types/working-activity.js +18 -0
  631. package/package.json +141 -0
  632. package/skills/audit/SKILL.md +24 -0
  633. package/skills/bug/SKILL.md +27 -0
  634. package/skills/pr-comments/SKILL.md +20 -0
  635. package/skills/practice/SKILL.md +22 -0
  636. package/skills/release-notes/SKILL.md +25 -0
  637. package/skills/review/SKILL.md +25 -0
  638. package/skills/vuln-check/SKILL.md +25 -0
@@ -0,0 +1,1290 @@
1
+ import indentString from 'indent-string';
2
+ import { applyTextStyles } from './colorize.js';
3
+ import getMaxWidth from './get-max-width.js';
4
+ import { LayoutDisplay, LayoutEdge } from './layout/node.js';
5
+ import { nodeCache, pendingClears } from './node-cache.js';
6
+ import renderBorder from './render-border.js';
7
+ import { squashTextNodesToSegments, } from './squash-text-nodes.js';
8
+ import { isXtermJs } from './terminal.js';
9
+ import { widestLine } from './widest-line.js';
10
+ import wrapText from './wrap-text.js';
11
+ // Matches detectXtermJsWheel() in ScrollKeybindingHandler.tsx — the curve
12
+ // and drain must agree on terminal detection. TERM_PROGRAM check is the sync
13
+ // fallback; isXtermJs() is the authoritative XTVERSION-probe result.
14
+ function isXtermJsHost() {
15
+ return process.env.TERM_PROGRAM === 'vscode' || isXtermJs();
16
+ }
17
+ // Per-frame scratch: set when any node's yoga position/size differs from
18
+ // its cached value, or a child was removed. Read by ink.tsx to decide
19
+ // whether the full-damage sledgehammer (PR #20120) is needed this frame.
20
+ // Applies on both alt-screen and main-screen. Steady-state frames
21
+ // (spinner tick, clock tick, text append into a fixed-height box) don't
22
+ // shift layout → narrow damage bounds → O(changed cells) diff instead of
23
+ // O(rows×cols).
24
+ let layoutShifted = false;
25
+ /** Reset the per-frame layout-shift flag. */
26
+ export function resetLayoutShifted() {
27
+ layoutShifted = false;
28
+ }
29
+ /**
30
+ * Whether any node's layout position or size shifted this frame, or a child was removed.
31
+ * @returns true when the full-damage path is needed this frame.
32
+ */
33
+ export function didLayoutShift() {
34
+ return layoutShifted;
35
+ }
36
+ let scrollHint = null;
37
+ // Rects of position:absolute nodes from the PREVIOUS frame, used by
38
+ // ScrollBox's blit+shift third-pass repair (see usage site). Recorded at
39
+ // three paths — full-render nodeCache.set, node-level blit early-return,
40
+ // blitEscapingAbsoluteDescendants — so clean-overlay consecutive scrolls
41
+ // still have the rect.
42
+ let absoluteRectsPrev = [];
43
+ let absoluteRectsCur = [];
44
+ /** Reset the scroll hint for the next frame and rotate the absolute-rect buffers. */
45
+ export function resetScrollHint() {
46
+ scrollHint = null;
47
+ absoluteRectsPrev = absoluteRectsCur;
48
+ absoluteRectsCur = [];
49
+ }
50
+ /**
51
+ * The scroll hint captured this frame, or null.
52
+ * @returns the scroll hint, or null when none was captured.
53
+ */
54
+ export function getScrollHint() {
55
+ return scrollHint;
56
+ }
57
+ // The ScrollBox DOM node (if any) with pendingScrollDelta left after this
58
+ // frame's drain. renderer.ts calls markDirty(it) post-render so the NEXT
59
+ // frame's root blit check fails and we descend to continue draining.
60
+ // Without this, after the scrollbox's dirty flag is cleared (line ~721),
61
+ // the next frame blits root and never reaches the scrollbox — drain stalls.
62
+ let scrollDrainNode = null;
63
+ /** Clear the pending scroll drain node for the next frame. */
64
+ export function resetScrollDrainNode() {
65
+ scrollDrainNode = null;
66
+ }
67
+ /**
68
+ * The ScrollBox node still draining pending scroll delta, or null.
69
+ * @returns the draining ScrollBox node, or null.
70
+ */
71
+ export function getScrollDrainNode() {
72
+ return scrollDrainNode;
73
+ }
74
+ let followScroll = null;
75
+ /**
76
+ * Read and clear the follow-scroll event recorded this frame.
77
+ * @returns the follow-scroll delta and viewport bounds, or null.
78
+ */
79
+ export function consumeFollowScroll() {
80
+ const f = followScroll;
81
+ followScroll = null;
82
+ return f;
83
+ }
84
+ // ── Native terminal drain (iTerm2/Ghostty/etc. — proportional events) ──
85
+ // Minimum rows applied per frame. Above this, drain is proportional (~3/4
86
+ // of remaining) so big bursts catch up in log₄ frames while the tail
87
+ // decelerates smoothly. Hard cap is innerHeight-1 so DECSTBM hint fires.
88
+ const SCROLL_MIN_PER_FRAME = 4;
89
+ // ── xterm.js (VS Code) smooth drain ──
90
+ // Low pending (≤5) drains ALL in one frame — slow wheel clicks should be
91
+ // instant (click → visible jump → done), not micro-stutter 1-row frames.
92
+ // Higher pending drains at a small fixed step so fast-scroll animation
93
+ // stays smooth (no big jumps). Pending >MAX snaps excess.
94
+ const SCROLL_INSTANT_THRESHOLD = 5; // ≤ this: drain all at once
95
+ const SCROLL_HIGH_PENDING = 12; // threshold for HIGH step
96
+ const SCROLL_STEP_MED = 2; // pending (INSTANT, HIGH): catch-up
97
+ const SCROLL_STEP_HIGH = 3; // pending ≥ HIGH: fast flick
98
+ const SCROLL_MAX_PENDING = 30; // snap excess beyond this
99
+ // xterm.js adaptive drain. Returns rows applied; mutates pendingScrollDelta.
100
+ function drainAdaptive(node, pending, innerHeight) {
101
+ const sign = pending > 0 ? 1 : -1;
102
+ let abs = Math.abs(pending);
103
+ let applied = 0;
104
+ // Snap excess beyond animation window so big flicks don't coast.
105
+ if (abs > SCROLL_MAX_PENDING) {
106
+ applied += sign * (abs - SCROLL_MAX_PENDING);
107
+ abs = SCROLL_MAX_PENDING;
108
+ }
109
+ // ≤5: drain all (slow click = instant). Above: small fixed step.
110
+ const step = abs <= SCROLL_INSTANT_THRESHOLD
111
+ ? abs
112
+ : abs < SCROLL_HIGH_PENDING
113
+ ? SCROLL_STEP_MED
114
+ : SCROLL_STEP_HIGH;
115
+ applied += sign * step;
116
+ const rem = abs - step;
117
+ // Cap total at innerHeight-1 so DECSTBM blit+shift fast path fires
118
+ // (matches drainProportional). Excess stays in pendingScrollDelta.
119
+ const cap = Math.max(1, innerHeight - 1);
120
+ const totalAbs = Math.abs(applied);
121
+ if (totalAbs > cap) {
122
+ const excess = totalAbs - cap;
123
+ node.pendingScrollDelta = sign * (rem + excess);
124
+ return sign * cap;
125
+ }
126
+ node.pendingScrollDelta = rem > 0 ? sign * rem : undefined;
127
+ return applied;
128
+ }
129
+ // Native proportional drain. step = max(MIN, floor(abs*3/4)), capped at
130
+ // innerHeight-1 so DECSTBM + blit+shift fast path fire.
131
+ function drainProportional(node, pending, innerHeight) {
132
+ const abs = Math.abs(pending);
133
+ const cap = Math.max(1, innerHeight - 1);
134
+ const step = Math.min(cap, Math.max(SCROLL_MIN_PER_FRAME, (abs * 3) >> 2));
135
+ if (abs <= step) {
136
+ node.pendingScrollDelta = undefined;
137
+ return pending;
138
+ }
139
+ const applied = pending > 0 ? step : -step;
140
+ node.pendingScrollDelta = pending - applied;
141
+ return applied;
142
+ }
143
+ // OSC 8 hyperlink escape sequences. Empty params (;;) — ansi-tokenize only
144
+ // recognizes this exact prefix. The id= param (for grouping wrapped lines)
145
+ // is added at terminal-output time in termio/osc.ts link().
146
+ const OSC = '\u001B]';
147
+ const BEL = '\u0007';
148
+ function wrapWithOsc8Link(text, url) {
149
+ return `${OSC}8;;${url}${BEL}${text}${OSC}8;;${BEL}`;
150
+ }
151
+ /**
152
+ * Build a mapping from each character position in the plain text to its segment index.
153
+ * Returns an array where charToSegment[i] is the segment index for character i.
154
+ * @param segments - the styled segments whose characters to map.
155
+ * @returns an array mapping each plain-text character index to its segment index.
156
+ */
157
+ function buildCharToSegmentMap(segments) {
158
+ const map = [];
159
+ for (let i = 0; i < segments.length; i++) {
160
+ const len = segments[i].text.length;
161
+ for (let j = 0; j < len; j++) {
162
+ map.push(i);
163
+ }
164
+ }
165
+ return map;
166
+ }
167
+ /**
168
+ * Apply styles to wrapped text by mapping each character back to its original segment.
169
+ * This preserves per-segment styles even when text wraps across lines.
170
+ * @param wrappedPlain - the wrapped plain text to style.
171
+ * @param segments - the original styled segments.
172
+ * @param charToSegment - character-to-segment index map for the original plain text.
173
+ * @param originalPlain - the original unwrapped plain text.
174
+ * @param trimEnabled - Whether whitespace trimming is enabled (wrap-trim mode).
175
+ * When true, we skip whitespace in the original that was trimmed from the output.
176
+ * When false (wrap mode), all whitespace is preserved so no skipping is needed.
177
+ * @returns the styled wrapped text.
178
+ */
179
+ function applyStylesToWrappedText(wrappedPlain, segments, charToSegment, originalPlain, trimEnabled = false) {
180
+ const lines = wrappedPlain.split('\n');
181
+ const resultLines = [];
182
+ let charIndex = 0;
183
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
184
+ const line = lines[lineIdx];
185
+ // In trim mode, skip leading whitespace that was trimmed from this line.
186
+ // Only skip if the original has whitespace but the output line doesn't start
187
+ // with whitespace (meaning it was trimmed). If both have whitespace, the
188
+ // whitespace was preserved and we shouldn't skip.
189
+ if (trimEnabled && line.length > 0) {
190
+ const lineStartsWithWhitespace = /\s/.test(line[0]);
191
+ const originalHasWhitespace = charIndex < originalPlain.length && /\s/.test(originalPlain[charIndex]);
192
+ // Only skip if original has whitespace but line doesn't
193
+ if (originalHasWhitespace && !lineStartsWithWhitespace) {
194
+ while (charIndex < originalPlain.length &&
195
+ /\s/.test(originalPlain[charIndex])) {
196
+ charIndex++;
197
+ }
198
+ }
199
+ }
200
+ let styledLine = '';
201
+ let runStart = 0;
202
+ let runSegmentIndex = charToSegment[charIndex] ?? 0;
203
+ for (let i = 0; i < line.length; i++) {
204
+ const currentSegmentIndex = charToSegment[charIndex] ?? runSegmentIndex;
205
+ if (currentSegmentIndex !== runSegmentIndex) {
206
+ // Flush the current run
207
+ const runText = line.slice(runStart, i);
208
+ const segment = segments[runSegmentIndex];
209
+ if (segment) {
210
+ let styled = applyTextStyles(runText, segment.styles);
211
+ if (segment.hyperlink) {
212
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
213
+ }
214
+ styledLine += styled;
215
+ }
216
+ else {
217
+ styledLine += runText;
218
+ }
219
+ runStart = i;
220
+ runSegmentIndex = currentSegmentIndex;
221
+ }
222
+ charIndex++;
223
+ }
224
+ // Flush the final run
225
+ const runText = line.slice(runStart);
226
+ const segment = segments[runSegmentIndex];
227
+ if (segment) {
228
+ let styled = applyTextStyles(runText, segment.styles);
229
+ if (segment.hyperlink) {
230
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
231
+ }
232
+ styledLine += styled;
233
+ }
234
+ else {
235
+ styledLine += runText;
236
+ }
237
+ resultLines.push(styledLine);
238
+ // Skip newline character in original that corresponds to this line break.
239
+ // This is needed when the original text contains actual newlines (not just
240
+ // wrapping-inserted newlines). Without this, charIndex gets out of sync
241
+ // because the newline is in originalPlain/charToSegment but not in the
242
+ // split lines.
243
+ if (charIndex < originalPlain.length && originalPlain[charIndex] === '\n') {
244
+ charIndex++;
245
+ }
246
+ // In trim mode, skip whitespace that was replaced by newline when wrapping.
247
+ // We skip whitespace in the original until we reach a character that matches
248
+ // the first character of the next line. This handles cases like:
249
+ // - "AB \tD" wrapped to "AB\n\tD" - skip spaces until we hit the tab
250
+ // In non-trim mode, whitespace is preserved so no skipping is needed.
251
+ if (trimEnabled && lineIdx < lines.length - 1) {
252
+ const nextLine = lines[lineIdx + 1];
253
+ const nextLineFirstChar = nextLine.length > 0 ? nextLine[0] : null;
254
+ // Skip whitespace until we hit a char that matches the next line's first char
255
+ while (charIndex < originalPlain.length &&
256
+ /\s/.test(originalPlain[charIndex])) {
257
+ // Stop if we found the character that starts the next line
258
+ if (nextLineFirstChar !== null &&
259
+ originalPlain[charIndex] === nextLineFirstChar) {
260
+ break;
261
+ }
262
+ charIndex++;
263
+ }
264
+ }
265
+ }
266
+ return resultLines.join('\n');
267
+ }
268
+ /**
269
+ * Wrap text and record which output lines are soft-wrap continuations
270
+ * (i.e. the `\n` before them was inserted by word-wrap, not in the
271
+ * source). wrapAnsi already processes each input line independently, so
272
+ * wrapping per-input-line here gives identical output to a single
273
+ * whole-string wrap while letting us mark per-piece provenance.
274
+ * Truncate modes never add newlines (cli-truncate is whole-string) so
275
+ * they fall through with softWrap undefined — no tracking, no behavior
276
+ * change from the pre-softWrap path.
277
+ */
278
+ function wrapWithSoftWrap(plainText, maxWidth, textWrap) {
279
+ if (textWrap !== 'wrap' && textWrap !== 'wrap-trim') {
280
+ return {
281
+ wrapped: wrapText(plainText, maxWidth, textWrap),
282
+ softWrap: undefined,
283
+ };
284
+ }
285
+ const origLines = plainText.split('\n');
286
+ const outLines = [];
287
+ const softWrap = [];
288
+ for (const orig of origLines) {
289
+ const pieces = wrapText(orig, maxWidth, textWrap).split('\n');
290
+ for (let i = 0; i < pieces.length; i++) {
291
+ outLines.push(pieces[i]);
292
+ softWrap.push(i > 0);
293
+ }
294
+ }
295
+ return { wrapped: outLines.join('\n'), softWrap };
296
+ }
297
+ // If parent container is `<Box>`, text nodes will be treated as separate nodes in
298
+ // the tree and will have their own coordinates in the layout.
299
+ // To ensure text nodes are aligned correctly, take X and Y of the first text node
300
+ // and use it as offset for the rest of the nodes
301
+ // Only first node is taken into account, because other text nodes can't have margin or padding,
302
+ // so their coordinates will be relative to the first node anyway
303
+ function applyPaddingToText(node, text, softWrap) {
304
+ const yogaNode = node.childNodes[0]?.yogaNode;
305
+ if (yogaNode) {
306
+ const offsetX = yogaNode.getComputedLeft();
307
+ const offsetY = yogaNode.getComputedTop();
308
+ text = '\n'.repeat(offsetY) + indentString(text, offsetX);
309
+ if (softWrap && offsetY > 0) {
310
+ // Prepend `false` for each padding line so indices stay aligned
311
+ // with text.split('\n'). Mutate in place — caller owns the array.
312
+ softWrap.unshift(...Array(offsetY).fill(false));
313
+ }
314
+ }
315
+ return text;
316
+ }
317
+ /**
318
+ * Render a laid-out node subtree into the output buffer.
319
+ * After yoga lays out the tree, each node is painted to the output object,
320
+ * which later gets written to the terminal.
321
+ * @param node - the DOM node to render.
322
+ * @param output - the output buffer receiving paint operations.
323
+ * @param options - render options: the child coordinate offset, the
324
+ * previous frame's screen for blitting, whether to skip the node's own
325
+ * blit, and the inherited background color.
326
+ */
327
+ function renderNodeToOutput(node, output, options) {
328
+ const { offsetX = 0, offsetY = 0, prevScreen, skipSelfBlit = false, inheritedBackgroundColor, } = options;
329
+ const { yogaNode } = node;
330
+ if (yogaNode) {
331
+ if (yogaNode.getDisplay() === LayoutDisplay.None) {
332
+ // Clear old position if node was visible before becoming hidden
333
+ if (node.dirty) {
334
+ const cached = nodeCache.get(node);
335
+ if (cached) {
336
+ output.clear({
337
+ x: Math.floor(cached.x),
338
+ y: Math.floor(cached.y),
339
+ width: Math.floor(cached.width),
340
+ height: Math.floor(cached.height),
341
+ });
342
+ // Drop descendants' cache too — hideInstance's markDirty walks UP
343
+ // only, so descendants' .dirty stays false. Their nodeCache entries
344
+ // survive with pre-hide rects. On unhide, if position didn't shift,
345
+ // the blit check at line ~432 passes and copies EMPTY cells from
346
+ // prevScreen (cleared here) → content vanishes.
347
+ dropSubtreeCache(node);
348
+ layoutShifted = true;
349
+ }
350
+ }
351
+ return;
352
+ }
353
+ // Left and top positions in Yoga are relative to their parent node
354
+ const x = offsetX + yogaNode.getComputedLeft();
355
+ const yogaTop = yogaNode.getComputedTop();
356
+ let y = offsetY + yogaTop;
357
+ const width = yogaNode.getComputedWidth();
358
+ const height = yogaNode.getComputedHeight();
359
+ // Absolute-positioned overlays (e.g. autocomplete menus with bottom='100%')
360
+ // can compute negative screen y when they extend above the viewport. Without
361
+ // clamping, setCellAt drops cells at y<0, clipping the TOP of the content
362
+ // (best matches in an autocomplete). By clamping to 0, we shift the element
363
+ // down so the top rows are visible and the bottom overflows below — the
364
+ // opaque prop ensures it paints over whatever is underneath.
365
+ if (y < 0 && node.style.position === 'absolute') {
366
+ y = 0;
367
+ }
368
+ // Check if we can skip this subtree (clean node with unchanged layout).
369
+ // Blit cells from previous screen instead of re-rendering.
370
+ const cached = nodeCache.get(node);
371
+ if (!node.dirty &&
372
+ !skipSelfBlit &&
373
+ node.pendingScrollDelta === undefined &&
374
+ cached &&
375
+ cached.x === x &&
376
+ cached.y === y &&
377
+ cached.width === width &&
378
+ cached.height === height &&
379
+ prevScreen) {
380
+ const fx = Math.floor(x);
381
+ const fy = Math.floor(y);
382
+ const fw = Math.floor(width);
383
+ const fh = Math.floor(height);
384
+ output.blit(prevScreen, fx, fy, fw, fh);
385
+ if (node.style.position === 'absolute') {
386
+ absoluteRectsCur.push(cached);
387
+ }
388
+ // Absolute descendants can paint outside this node's layout bounds
389
+ // (e.g. a slash menu with position='absolute' bottom='100%' floats
390
+ // above). If a dirty clipped sibling re-rendered and overwrote those
391
+ // cells, the blit above only restored this node's own rect — the
392
+ // absolute descendants' cells are lost. Re-blit them from prevScreen
393
+ // so the overlays survive.
394
+ blitEscapingAbsoluteDescendants(node, output, prevScreen, fx, fy, fw, fh);
395
+ return;
396
+ }
397
+ // Clear stale content from the old position when re-rendering.
398
+ // Dirty: content changed. Moved: position/size changed (e.g., sibling
399
+ // above changed height), old cells still on the terminal.
400
+ const positionChanged = cached !== undefined &&
401
+ (cached.x !== x ||
402
+ cached.y !== y ||
403
+ cached.width !== width ||
404
+ cached.height !== height);
405
+ if (positionChanged) {
406
+ layoutShifted = true;
407
+ }
408
+ if (cached && (node.dirty || positionChanged)) {
409
+ output.clear({
410
+ x: Math.floor(cached.x),
411
+ y: Math.floor(cached.y),
412
+ width: Math.floor(cached.width),
413
+ height: Math.floor(cached.height),
414
+ }, node.style.position === 'absolute');
415
+ }
416
+ // Read before deleting — hasRemovedChild disables prevScreen blitting
417
+ // for siblings to prevent stale overflow content from being restored.
418
+ const clears = pendingClears.get(node);
419
+ const hasRemovedChild = clears !== undefined;
420
+ if (hasRemovedChild) {
421
+ layoutShifted = true;
422
+ for (const rect of clears) {
423
+ output.clear({
424
+ x: Math.floor(rect.x),
425
+ y: Math.floor(rect.y),
426
+ width: Math.floor(rect.width),
427
+ height: Math.floor(rect.height),
428
+ });
429
+ }
430
+ pendingClears.delete(node);
431
+ }
432
+ // Yoga squeezed this node to zero height (overflow in a height-constrained
433
+ // parent) AND a sibling lands at the same y. Skip rendering — both would
434
+ // write to the same row; if the sibling's content is shorter, this node's
435
+ // tail chars ghost (e.g. "false" + "true" = "truee"). The clear above
436
+ // already handled the visible→squeezed transition.
437
+ //
438
+ // The sibling-overlap check is load-bearing: Yoga's pixel-grid rounding
439
+ // can give a box h=0 while still leaving a row for it (next sibling at
440
+ // y+1, not y). HelpV2's third shortcuts column hits this — skipping
441
+ // unconditionally drops "ctrl + z to suspend" from /help output.
442
+ if (height === 0 && siblingSharesY(node, yogaNode)) {
443
+ nodeCache.set(node, { x, y, width, height, top: yogaTop });
444
+ node.dirty = false;
445
+ return;
446
+ }
447
+ if (node.nodeName === 'ink-raw-ansi') {
448
+ // Pre-rendered ANSI content. The producer already wrapped to width and
449
+ // emitted terminal-ready escape codes. Skip squash, measure, wrap, and
450
+ // style re-application — output.write() parses ANSI directly into cells.
451
+ const text = node.attributes['rawText'];
452
+ if (text) {
453
+ output.write(x, y, text);
454
+ }
455
+ }
456
+ else if (node.nodeName === 'ink-text') {
457
+ const segments = squashTextNodesToSegments(node, inheritedBackgroundColor
458
+ ? { backgroundColor: inheritedBackgroundColor }
459
+ : undefined);
460
+ // First, get plain text to check if wrapping is needed
461
+ const plainText = segments.map(s => s.text).join('');
462
+ if (plainText.length > 0) {
463
+ // Upstream Ink uses getMaxWidth(yogaNode) unclamped here. That
464
+ // width comes from Yoga's AtMost pass and can exceed the actual
465
+ // screen space (see getMaxWidth docstring). Yoga's height for this
466
+ // node already reflects the constrained Exactly pass, so clamping
467
+ // the wrap width here keeps line count consistent with layout.
468
+ // Without this, characters past the screen edge are dropped by
469
+ // setCellAt's bounds check.
470
+ const maxWidth = Math.min(getMaxWidth(yogaNode), output.width - x);
471
+ const textWrap = node.style.textWrap ?? 'wrap';
472
+ // Check if wrapping is needed
473
+ const needsWrapping = widestLine(plainText) > maxWidth;
474
+ let text;
475
+ let softWrap;
476
+ if (needsWrapping && segments.length === 1) {
477
+ // Single segment: wrap plain text first, then apply styles to each line
478
+ const segment = segments[0];
479
+ const w = wrapWithSoftWrap(plainText, maxWidth, textWrap);
480
+ softWrap = w.softWrap;
481
+ text = w.wrapped
482
+ .split('\n')
483
+ .map(line => {
484
+ let styled = applyTextStyles(line, segment.styles);
485
+ // Apply OSC 8 hyperlink per-line so each line is independently
486
+ // clickable. output.ts splits on newlines and tokenizes each
487
+ // line separately, so a single wrapper around the whole block
488
+ // would only apply the hyperlink to the first line.
489
+ if (segment.hyperlink) {
490
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
491
+ }
492
+ return styled;
493
+ })
494
+ .join('\n');
495
+ }
496
+ else if (needsWrapping) {
497
+ // Multiple segments with wrapping: wrap plain text first, then re-apply
498
+ // each segment's styles based on character positions. This preserves
499
+ // per-segment styles even when text wraps across lines.
500
+ const w = wrapWithSoftWrap(plainText, maxWidth, textWrap);
501
+ softWrap = w.softWrap;
502
+ const charToSegment = buildCharToSegmentMap(segments);
503
+ text = applyStylesToWrappedText(w.wrapped, segments, charToSegment, plainText, textWrap === 'wrap-trim');
504
+ // Hyperlinks are handled per-run in applyStylesToWrappedText via
505
+ // wrapWithOsc8Link, similar to how styles are applied per-run.
506
+ }
507
+ else {
508
+ // No wrapping needed: apply styles directly
509
+ text = segments
510
+ .map(segment => {
511
+ let styledText = applyTextStyles(segment.text, segment.styles);
512
+ if (segment.hyperlink) {
513
+ styledText = wrapWithOsc8Link(styledText, segment.hyperlink);
514
+ }
515
+ return styledText;
516
+ })
517
+ .join('');
518
+ }
519
+ text = applyPaddingToText(node, text, softWrap);
520
+ output.write(x, y, text, softWrap);
521
+ }
522
+ }
523
+ else if (node.nodeName === 'ink-box') {
524
+ const boxBackgroundColor = node.style.backgroundColor ?? inheritedBackgroundColor;
525
+ // Mark this box's region as non-selectable (fullscreen text
526
+ // selection). noSelect ops are applied AFTER blits/writes in
527
+ // output.get(), so this wins regardless of what's rendered into
528
+ // the region — including blits from prevScreen when the box is
529
+ // clean (the op is emitted on both the dirty-render path here
530
+ // AND on the blit fast-path at line ~235 since blitRegion copies
531
+ // the noSelect bitmap alongside cells).
532
+ //
533
+ // 'from-left-edge' extends the exclusion from col 0 so any
534
+ // upstream indentation (tool prefix, tree lines) is covered too
535
+ // — a multi-row drag over a diff gutter shouldn't pick up the
536
+ // ` ⎿ ` prefix on row 0 or the blank cells under it on row 1+.
537
+ if (node.style.noSelect) {
538
+ const boxX = Math.floor(x);
539
+ const fromEdge = node.style.noSelect === 'from-left-edge';
540
+ output.noSelect({
541
+ x: fromEdge ? 0 : boxX,
542
+ y: Math.floor(y),
543
+ width: fromEdge ? boxX + Math.floor(width) : Math.floor(width),
544
+ height: Math.floor(height),
545
+ });
546
+ }
547
+ const overflowX = node.style.overflowX ?? node.style.overflow;
548
+ const overflowY = node.style.overflowY ?? node.style.overflow;
549
+ const clipHorizontally = overflowX === 'hidden' || overflowX === 'scroll';
550
+ const clipVertically = overflowY === 'hidden' || overflowY === 'scroll';
551
+ const isScrollY = overflowY === 'scroll';
552
+ const needsClip = clipHorizontally || clipVertically;
553
+ let y1;
554
+ let y2;
555
+ if (needsClip) {
556
+ const x1 = clipHorizontally
557
+ ? x + yogaNode.getComputedBorder(LayoutEdge.Left)
558
+ : undefined;
559
+ const x2 = clipHorizontally
560
+ ? x +
561
+ yogaNode.getComputedWidth() -
562
+ yogaNode.getComputedBorder(LayoutEdge.Right)
563
+ : undefined;
564
+ y1 = clipVertically
565
+ ? y + yogaNode.getComputedBorder(LayoutEdge.Top)
566
+ : undefined;
567
+ y2 = clipVertically
568
+ ? y +
569
+ yogaNode.getComputedHeight() -
570
+ yogaNode.getComputedBorder(LayoutEdge.Bottom)
571
+ : undefined;
572
+ output.clip({ x1, x2, y1, y2 });
573
+ }
574
+ if (isScrollY) {
575
+ // Scroll containers follow the ScrollBox component structure:
576
+ // a single content-wrapper child with flexShrink:0 (doesn't shrink
577
+ // to fit), whose children are the scrollable items. scrollHeight
578
+ // comes from the wrapper's intrinsic Yoga height. The wrapper is
579
+ // rendered with its Y translated by -scrollTop; its children are
580
+ // culled against the visible window.
581
+ const padTop = yogaNode.getComputedPadding(LayoutEdge.Top);
582
+ const innerHeight = Math.max(0, (y2 ?? y + height) -
583
+ (y1 ?? y) -
584
+ padTop -
585
+ yogaNode.getComputedPadding(LayoutEdge.Bottom));
586
+ const content = node.childNodes.find(c => c.yogaNode);
587
+ const contentYoga = content?.yogaNode;
588
+ // scrollHeight is the intrinsic height of the content wrapper.
589
+ // Do NOT add getComputedTop() — that's the wrapper's offset
590
+ // within the viewport (equal to the scroll container's
591
+ // paddingTop), and innerHeight already subtracts padding, so
592
+ // including it double-counts padding and inflates maxScroll.
593
+ const scrollHeight = contentYoga?.getComputedHeight() ?? 0;
594
+ // Capture previous scroll bounds BEFORE overwriting — the at-bottom
595
+ // follow check compares against last frame's max.
596
+ const prevScrollHeight = node.scrollHeight ?? scrollHeight;
597
+ const prevInnerHeight = node.scrollViewportHeight ?? innerHeight;
598
+ node.scrollHeight = scrollHeight;
599
+ node.scrollViewportHeight = innerHeight;
600
+ // Absolute screen-buffer row where the scrollable area (inside
601
+ // padding) begins. Exposed via ScrollBoxHandle.getViewportTop() so
602
+ // drag-to-scroll can detect when the drag leaves the scroll viewport.
603
+ node.scrollViewportTop = (y1 ?? y) + padTop;
604
+ const maxScroll = Math.max(0, scrollHeight - innerHeight);
605
+ // scrollAnchor: scroll so the anchored element's top is at the
606
+ // viewport top (plus offset). Yoga is FRESH — same calculateLayout
607
+ // pass that just produced scrollHeight. Deterministic alternative
608
+ // to scrollTo(N) which bakes a number that's stale by the throttled
609
+ // render; the element ref defers the read to now. One-shot snap.
610
+ // A prior eased-seek version (proportional drain over ~5 frames)
611
+ // moved scrollTop without firing React's notify → parent's quantized
612
+ // store snapshot never updated → StickyTracker got stale range props
613
+ // → firstVisible wrong. Also: SCROLL_MIN_PER_FRAME=4 with snap-at-1
614
+ // ping-ponged forever at delta=2. Smooth needs drain-end notify
615
+ // plumbing; shipping instant first. stickyScroll overrides.
616
+ if (node.scrollAnchor) {
617
+ const anchorTop = node.scrollAnchor.el.yogaNode?.getComputedTop();
618
+ if (anchorTop != null) {
619
+ node.scrollTop = anchorTop + node.scrollAnchor.offset;
620
+ node.pendingScrollDelta = undefined;
621
+ }
622
+ node.scrollAnchor = undefined;
623
+ }
624
+ // At-bottom follow. Positional: if scrollTop was at (or past) the
625
+ // previous max, pin to the new max. Scroll away → stop following;
626
+ // scroll back (or scrollToBottom/sticky attr) → resume. The sticky
627
+ // flag is OR'd in for cold start (scrollTop=0 before first layout)
628
+ // and scrollToBottom-from-far-away (flag set before scrollTop moves)
629
+ // — the imperative field takes precedence over the attribute so
630
+ // scrollTo/scrollBy can break stickiness. pendingDelta<0 guard:
631
+ // don't cancel an in-flight scroll-up when content races in.
632
+ // Capture scrollTop before follow so ink.tsx can translate any
633
+ // active text selection by the same delta (native terminal behavior:
634
+ // view keeps scrolling, highlight walks up with the text).
635
+ const scrollTopBeforeFollow = node.scrollTop ?? 0;
636
+ const sticky = node.stickyScroll ?? Boolean(node.attributes['stickyScroll']);
637
+ const prevMaxScroll = node.scrollPrevMax ?? Math.max(0, prevScrollHeight - prevInnerHeight);
638
+ // Positional check only valid when content grew — virtualization can
639
+ // transiently SHRINK scrollHeight (tail unmount + stale heightCache
640
+ // spacer) making scrollTop >= prevMaxScroll true by artifact, not
641
+ // because the user was at bottom.
642
+ const grew = scrollHeight >= prevScrollHeight;
643
+ // A shrink frame is a MEASUREMENT artifact, not real content loss:
644
+ // following it (or clamping to its smaller maxScroll) would yank an
645
+ // explicitly scrolled-away view up — all the way to 0 when the
646
+ // transient measurement drops below the viewport. Freeze the
647
+ // position for that frame; the next growth frame re-validates it.
648
+ const shrunk = scrollHeight < prevScrollHeight;
649
+ // Only real growth (or a settled measurement) refreshes the trusted
650
+ // maxScroll used by the positional at-bottom check — otherwise the
651
+ // frame AFTER an artifact shrink compares against the shrunken
652
+ // maxScroll and yanks a mid-scroll view to the bottom (opentui #709:
653
+ // content-size changes must not reset the manual-scroll state).
654
+ if (!shrunk)
655
+ node.scrollPrevMax = maxScroll;
656
+ // Positional at-bottom also fires on NO-GROWTH frames when the
657
+ // scroll position already sits at maxScroll: a wheel-down that
658
+ // lands exactly on the bottom re-pins the follow (and restores
659
+ // stickyScroll below) so the "N new messages" pill clears once the
660
+ // user scrolls home — otherwise sticky stays broken until the next
661
+ // content growth, and an idle stream leaves the pill stuck.
662
+ const atBottom = sticky ||
663
+ (scrollTopBeforeFollow >= prevMaxScroll &&
664
+ (grew || scrollTopBeforeFollow >= maxScroll));
665
+ if (atBottom && (node.pendingScrollDelta ?? 0) >= 0 && !shrunk) {
666
+ node.scrollTop = maxScroll;
667
+ node.pendingScrollDelta = undefined;
668
+ // Sync flag so useVirtualScroll's isSticky() agrees with positional
669
+ // state — sticky-broken-but-at-bottom (wheel tremor, click-select
670
+ // at max) otherwise leaves useVirtualScroll's clamp holding the
671
+ // viewport short of new streaming content. scrollTo/scrollBy set
672
+ // false; this restores true, same as scrollToBottom() would.
673
+ // Only restore when (a) positionally at bottom and (b) the flag
674
+ // was explicitly broken (===false) by scrollTo/scrollBy. When
675
+ // undefined (never set by user action) leave it alone — setting it
676
+ // would make the sticky flag sticky-by-default and lock out
677
+ // direct scrollTop writes (e.g. the alt-screen-perf test).
678
+ if (node.stickyScroll === false &&
679
+ scrollTopBeforeFollow >= prevMaxScroll) {
680
+ node.stickyScroll = true;
681
+ node.onStickyRestore?.();
682
+ }
683
+ }
684
+ const followDelta = (node.scrollTop ?? 0) - scrollTopBeforeFollow;
685
+ if (followDelta > 0) {
686
+ const vpTop = node.scrollViewportTop ?? 0;
687
+ followScroll = {
688
+ delta: followDelta,
689
+ viewportTop: vpTop,
690
+ viewportBottom: vpTop + innerHeight - 1,
691
+ };
692
+ }
693
+ // Drain pendingScrollDelta. Native terminals (proportional burst
694
+ // events) use proportional drain; xterm.js (VS Code, sparse events +
695
+ // app-side accel curve) uses adaptive small-step drain. isXtermJs()
696
+ // depends on the async XTVERSION probe, but by the time this runs
697
+ // (pendingScrollDelta is only set by wheel events, >>50ms after
698
+ // startup) the probe has resolved — same timing guarantee the
699
+ // wheel-accel curve relies on.
700
+ let cur = node.scrollTop ?? 0;
701
+ const pending = node.pendingScrollDelta;
702
+ const cMin = node.scrollClampMin;
703
+ const cMax = node.scrollClampMax;
704
+ const haveClamp = cMin !== undefined && cMax !== undefined;
705
+ if (pending !== undefined && pending !== 0) {
706
+ // Drain continues even past the clamp — the render-clamp below
707
+ // holds the VISUAL at the mounted edge regardless. Hard-stopping
708
+ // here caused stop-start jutter: drain hits edge → pause → React
709
+ // commits → clamp widens → drain resumes → edge again. Letting
710
+ // scrollTop advance smoothly while the clamp lags gives continuous
711
+ // visual scroll at React's commit rate (the clamp catches up each
712
+ // commit). But THROTTLE the drain when already past the clamp so
713
+ // scrollTop doesn't race 5000 rows ahead of the mounted range
714
+ // (slide-cap would then take 200 commits to catch up = long
715
+ // perceived stall at the edge). Past-clamp drain caps at ~4 rows/
716
+ // frame, roughly matching React's slide rate so the gap stays
717
+ // bounded and catch-up is quick once input stops.
718
+ const pastClamp = haveClamp &&
719
+ ((pending < 0 && cur < cMin) || (pending > 0 && cur > cMax));
720
+ const eff = pastClamp ? Math.min(4, innerHeight >> 3) : innerHeight;
721
+ cur += isXtermJsHost()
722
+ ? drainAdaptive(node, pending, eff)
723
+ : drainProportional(node, pending, eff);
724
+ }
725
+ else if (pending === 0) {
726
+ // Opposite scrollBy calls cancelled to zero — clear so we don't
727
+ // schedule an infinite loop of no-op drain frames.
728
+ node.pendingScrollDelta = undefined;
729
+ }
730
+ // Keep the pre-frame position on a shrink frame (measurement
731
+ // artifact) instead of clamping to the shrunken maxScroll — the
732
+ // clamp would persist the yank even after content grows back.
733
+ let scrollTop = shrunk ? cur : Math.max(0, Math.min(cur, maxScroll));
734
+ // Virtual-scroll clamp: if scrollTop raced past the currently-mounted
735
+ // range (burst PageUp before React re-renders), render at the EDGE of
736
+ // the mounted children instead of blank spacer. Do NOT write back to
737
+ // node.scrollTop — the clamped value is for this paint only; the real
738
+ // scrollTop stays so React's next commit sees the target and mounts
739
+ // the right range. Not scheduling scrollDrainNode here keeps the
740
+ // clamp passive — React's commit → resetAfterCommit → onRender will
741
+ // paint again with fresh bounds.
742
+ const clamped = haveClamp
743
+ ? Math.max(cMin, Math.min(scrollTop, cMax))
744
+ : scrollTop;
745
+ node.scrollTop = scrollTop;
746
+ // Clamp hitting top/bottom consumes any remainder. Set drainPending
747
+ // only after clamp so a wasted no-op frame isn't scheduled.
748
+ if (scrollTop !== cur)
749
+ node.pendingScrollDelta = undefined;
750
+ if (node.pendingScrollDelta !== undefined)
751
+ scrollDrainNode = node;
752
+ // A manual scroll that lands exactly on the bottom re-pins sticky
753
+ // IMMEDIATELY on this frame — the follow-block restore above only
754
+ // fires when a later frame happens, but an idle stream (turn done,
755
+ // no ticks) produces none, leaving sticky broken and the
756
+ // new-messages pill stuck at its peak count. Only restores a flag
757
+ // that was explicitly broken by scrollTo/scrollBy (=== false);
758
+ // shrink-artifact frames and still-draining scrolls are excluded.
759
+ if (!shrunk &&
760
+ node.stickyScroll === false &&
761
+ node.pendingScrollDelta === undefined &&
762
+ scrollTop >= maxScroll) {
763
+ node.stickyScroll = true;
764
+ node.onStickyRestore?.();
765
+ }
766
+ scrollTop = clamped;
767
+ if (content && contentYoga) {
768
+ // Compute content wrapper's absolute render position with scroll
769
+ // offset applied, then render its children with culling.
770
+ const contentX = x + contentYoga.getComputedLeft();
771
+ const contentY = y + contentYoga.getComputedTop() - scrollTop;
772
+ // layoutShifted detection gap: when scrollTop moves by >= viewport
773
+ // height (batched PageUps, fast wheel), every visible child gets
774
+ // culled (cache dropped) and every newly-visible child has no
775
+ // cache — so the children's positionChanged check can't fire.
776
+ // The content wrapper's cached y (which encodes -scrollTop) is
777
+ // the only node that survives to witness the scroll.
778
+ const contentCached = nodeCache.get(content);
779
+ let hint = null;
780
+ if (contentCached && contentCached.y !== contentY) {
781
+ // delta = newScrollTop - oldScrollTop (positive = scrolled down).
782
+ // Capture a DECSTBM hint if the container itself didn't move
783
+ // and the shift fits within the viewport — otherwise the full
784
+ // rewrite is needed anyway, and layoutShifted stays the fallback.
785
+ const delta = contentCached.y - contentY;
786
+ const regionTop = Math.floor(y + contentYoga.getComputedTop());
787
+ const regionBottom = regionTop + innerHeight - 1;
788
+ if (cached?.y === y &&
789
+ cached.height === height &&
790
+ innerHeight > 0 &&
791
+ Math.abs(delta) < innerHeight) {
792
+ hint = { top: regionTop, bottom: regionBottom, delta };
793
+ scrollHint = hint;
794
+ }
795
+ else {
796
+ layoutShifted = true;
797
+ }
798
+ }
799
+ // Fast path: scroll (hint captured) with usable prevScreen.
800
+ // Blit prevScreen's scroll region into next.screen, shift in-place
801
+ // by delta (mirrors DECSTBM), then render ONLY the edge rows. The
802
+ // nested clip keeps child writes out of stable rows — a tall child
803
+ // that spans edge+stable still renders but stable cells are
804
+ // clipped, preserving the blit. Avoids re-rendering every visible
805
+ // child (expensive for long syntax-highlighted transcripts).
806
+ //
807
+ // When content.dirty (e.g. streaming text at the bottom of the
808
+ // scroll), we still use the fast path — the dirty child is almost
809
+ // always in the edge rows (the bottom, where new content appears).
810
+ // After edge rendering, any dirty children in stable rows are
811
+ // re-rendered in a second pass to avoid showing stale blitted
812
+ // content.
813
+ //
814
+ // Guard: the fast path only handles pure scroll or bottom-append.
815
+ // Child removal/insertion changes the content height in a way that
816
+ // doesn't match the scroll delta — fall back to the full path so
817
+ // removed children don't leave stale cells and shifted siblings
818
+ // render at their new positions.
819
+ const scrollHeight = contentYoga.getComputedHeight();
820
+ const prevHeight = contentCached?.height ?? scrollHeight;
821
+ const heightDelta = scrollHeight - prevHeight;
822
+ const safeForFastPath = !hint ||
823
+ heightDelta === 0 ||
824
+ (hint.delta > 0 && heightDelta === hint.delta);
825
+ // scrollHint is set above when hint is captured. If safeForFastPath
826
+ // is false the full path renders a next.screen that doesn't match
827
+ // the DECSTBM shift — emitting DECSTBM leaves stale rows (seen as
828
+ // content bleeding through during scroll-up + streaming). Clear it.
829
+ if (!safeForFastPath)
830
+ scrollHint = null;
831
+ if (hint && prevScreen && safeForFastPath) {
832
+ const { top, bottom, delta } = hint;
833
+ const w = Math.floor(width);
834
+ output.blit(prevScreen, Math.floor(x), top, w, bottom - top + 1);
835
+ output.shift(top, bottom, delta);
836
+ // Edge rows: new content entering the viewport.
837
+ const edgeTop = delta > 0 ? bottom - delta + 1 : top;
838
+ const edgeBottom = delta > 0 ? bottom : top - delta - 1;
839
+ output.clear({
840
+ x: Math.floor(x),
841
+ y: edgeTop,
842
+ width: w,
843
+ height: edgeBottom - edgeTop + 1,
844
+ });
845
+ output.clip({
846
+ x1: undefined,
847
+ x2: undefined,
848
+ y1: edgeTop,
849
+ y2: edgeBottom + 1,
850
+ });
851
+ // Snapshot dirty children before the first pass — the first
852
+ // pass clears dirty flags, and edge-spanning children would be
853
+ // missed by the second pass without this snapshot.
854
+ const dirtyChildren = content.dirty
855
+ ? new Set(content.childNodes.filter(c => c.dirty))
856
+ : null;
857
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, undefined,
858
+ // Cull to edge in child-local coords (inverse of contentY offset).
859
+ edgeTop - contentY, edgeBottom + 1 - contentY, boxBackgroundColor, true);
860
+ output.unclip();
861
+ // Second pass: re-render children in stable rows whose screen
862
+ // position doesn't match where the shift put their old pixels.
863
+ // Covers TWO cases:
864
+ // 1. Dirty children — their content changed, blitted pixels are
865
+ // stale regardless of position.
866
+ // 2. Clean children BELOW a middle-growth point — when a dirty
867
+ // sibling above them grows, their yogaTop increases but
868
+ // scrollTop increases by the same amount (sticky), so their
869
+ // screenY is CONSTANT. The shift moved their old pixels to
870
+ // screenY-delta (wrong); they should stay at screenY. Without
871
+ // this, the spinner/tmux-monitor ghost at shifted positions
872
+ // during streaming (e.g. triple spinner, pill duplication).
873
+ // For bottom-append (the common case), all clean children are
874
+ // ABOVE the growth point; their screenY decreased by delta and
875
+ // the shift put them at the right place — skipped here, fast
876
+ // path preserved.
877
+ if (dirtyChildren) {
878
+ const edgeTopLocal = edgeTop - contentY;
879
+ const edgeBottomLocal = edgeBottom + 1 - contentY;
880
+ const spaces = ' '.repeat(w);
881
+ // Track cumulative height change of children iterated so far.
882
+ // A clean child's yogaTop is unchanged iff this is zero (no
883
+ // sibling above it grew/shrank/mounted). When zero, the skip
884
+ // check cached.y−delta === screenY reduces to delta === delta
885
+ // (tautology) → skip without yoga reads. Restores O(dirty)
886
+ // that #24536 traded away: for bottom-append the dirty child
887
+ // is last (all clean children skip); for virtual-scroll range
888
+ // shift the topSpacer shrink + new-item heights self-balance
889
+ // to zero before reaching the clean block. Middle-growth
890
+ // leaves shift non-zero → clean children after the growth
891
+ // point fall through to yoga + the fine-grained check below,
892
+ // preserving the ghost-box fix.
893
+ let cumHeightShift = 0;
894
+ for (const childNode of content.childNodes) {
895
+ const childElem = childNode;
896
+ const isDirty = dirtyChildren.has(childNode);
897
+ if (!isDirty && cumHeightShift === 0) {
898
+ if (nodeCache.has(childElem))
899
+ continue;
900
+ // Uncached = culled last frame, now re-entering. blit
901
+ // never painted it → fall through to yoga + render.
902
+ // Height unchanged (clean), so cumHeightShift stays 0.
903
+ }
904
+ const cy = childElem.yogaNode;
905
+ if (!cy)
906
+ continue;
907
+ const childTop = cy.getComputedTop();
908
+ const childH = cy.getComputedHeight();
909
+ const childBottom = childTop + childH;
910
+ if (isDirty) {
911
+ const prev = nodeCache.get(childElem);
912
+ cumHeightShift += childH - (prev ? prev.height : 0);
913
+ }
914
+ // Skip culled children (outside viewport)
915
+ if (childBottom <= scrollTop ||
916
+ childTop >= scrollTop + innerHeight)
917
+ continue;
918
+ // Skip children entirely within edge rows (already rendered)
919
+ if (childTop >= edgeTopLocal && childBottom <= edgeBottomLocal)
920
+ continue;
921
+ const screenY = Math.floor(contentY + childTop);
922
+ // Clean children reaching here have cumHeightShift ≠ 0 OR
923
+ // no cache. Re-check precisely: cached.y − delta is where
924
+ // the shift left old pixels; if it equals new screenY the
925
+ // blit is correct (shift re-balanced at this child, or
926
+ // yogaTop happens to net out). No cache → blit never
927
+ // painted it → render.
928
+ if (!isDirty) {
929
+ const childCached = nodeCache.get(childElem);
930
+ if (childCached &&
931
+ Math.floor(childCached.y) - delta === screenY) {
932
+ continue;
933
+ }
934
+ }
935
+ // Wipe this child's region with spaces to overwrite stale
936
+ // blitted content — output.clear() only expands damage and
937
+ // cannot zero cells that the blit already wrote.
938
+ const screenBottom = Math.min(Math.floor(contentY + childBottom), Math.floor((y1 ?? y) + padTop + innerHeight));
939
+ if (screenY < screenBottom) {
940
+ const fill = Array(screenBottom - screenY)
941
+ .fill(spaces)
942
+ .join('\n');
943
+ output.write(Math.floor(x), screenY, fill);
944
+ output.clip({
945
+ x1: undefined,
946
+ x2: undefined,
947
+ y1: screenY,
948
+ y2: screenBottom,
949
+ });
950
+ renderNodeToOutput(childElem, output, {
951
+ offsetX: contentX,
952
+ offsetY: contentY,
953
+ prevScreen: undefined,
954
+ inheritedBackgroundColor: boxBackgroundColor,
955
+ });
956
+ output.unclip();
957
+ }
958
+ }
959
+ }
960
+ // Third pass: repair rows where shifted copies of absolute
961
+ // overlays landed. The blit copied prevScreen cells INCLUDING
962
+ // overlay pixels (overlays render AFTER this ScrollBox so they
963
+ // painted into prevScreen's scroll region). After shift, those
964
+ // pixels sit at (rect.y - delta) — neither edge render nor the
965
+ // overlay's own re-render covers them. Wipe and re-render
966
+ // ScrollBox content so the diff writes correct cells.
967
+ const spaces = absoluteRectsPrev.length ? ' '.repeat(w) : '';
968
+ for (const r of absoluteRectsPrev) {
969
+ if (r.y >= bottom + 1 || r.y + r.height <= top)
970
+ continue;
971
+ const shiftedTop = Math.max(top, Math.floor(r.y) - delta);
972
+ const shiftedBottom = Math.min(bottom + 1, Math.floor(r.y + r.height) - delta);
973
+ // Skip if entirely within edge rows (already rendered).
974
+ if (shiftedTop >= edgeTop && shiftedBottom <= edgeBottom + 1)
975
+ continue;
976
+ if (shiftedTop >= shiftedBottom)
977
+ continue;
978
+ const fill = Array(shiftedBottom - shiftedTop)
979
+ .fill(spaces)
980
+ .join('\n');
981
+ output.write(Math.floor(x), shiftedTop, fill);
982
+ output.clip({
983
+ x1: undefined,
984
+ x2: undefined,
985
+ y1: shiftedTop,
986
+ y2: shiftedBottom,
987
+ });
988
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, undefined, shiftedTop - contentY, shiftedBottom - contentY, boxBackgroundColor, true);
989
+ output.unclip();
990
+ }
991
+ }
992
+ else {
993
+ // Full path. Two sub-cases:
994
+ //
995
+ // Scrolled without a usable hint (big jump, container moved):
996
+ // child positions in prevScreen are stale. Clear the viewport
997
+ // and disable blit so children don't restore shifted content.
998
+ //
999
+ // No scroll (spinner tick, content edit): child positions in
1000
+ // prevScreen are still valid. Skip the viewport clear and pass
1001
+ // prevScreen so unchanged children blit. Dirty children already
1002
+ // self-clear via their own cached-rect clear. Without this, a
1003
+ // spinner inside ScrollBox forces a full-content rewrite every
1004
+ // frame — on wide terminals over tmux (no BSU/ESU) the
1005
+ // bandwidth crosses the chunk boundary and the frame tears.
1006
+ const scrolled = contentCached && contentCached.y !== contentY;
1007
+ if (scrolled && y1 !== undefined && y2 !== undefined) {
1008
+ output.clear({
1009
+ x: Math.floor(x),
1010
+ y: Math.floor(y1),
1011
+ width: Math.floor(width),
1012
+ height: Math.floor(y2 - y1),
1013
+ });
1014
+ }
1015
+ // positionChanged (ScrollBox height shrunk — pill mount) means a
1016
+ // child spanning the old bottom edge would blit its full cached
1017
+ // rect past the new clip. output.ts clips blits now, but also
1018
+ // disable prevScreen here so the partial-row child re-renders at
1019
+ // correct bounds instead of blitting a clipped (truncated) old
1020
+ // rect.
1021
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, scrolled || positionChanged ? undefined : prevScreen, scrollTop, scrollTop + innerHeight, boxBackgroundColor);
1022
+ }
1023
+ nodeCache.set(content, {
1024
+ x: contentX,
1025
+ y: contentY,
1026
+ width: contentYoga.getComputedWidth(),
1027
+ height: contentYoga.getComputedHeight(),
1028
+ });
1029
+ content.dirty = false;
1030
+ }
1031
+ }
1032
+ else {
1033
+ // Fill interior with background color before rendering children.
1034
+ // This covers padding areas and empty space; child text inherits
1035
+ // the color via inheritedBackgroundColor so written cells also
1036
+ // get the background.
1037
+ // Disable prevScreen for children: the fill overwrites the entire
1038
+ // interior each render, so child blits from prevScreen would restore
1039
+ // stale cells (wrong bg if it changed) on top of the fresh fill.
1040
+ const ownBackgroundColor = node.style.backgroundColor;
1041
+ if (ownBackgroundColor || node.style.opaque) {
1042
+ const borderLeft = yogaNode.getComputedBorder(LayoutEdge.Left);
1043
+ const borderRight = yogaNode.getComputedBorder(LayoutEdge.Right);
1044
+ const borderTop = yogaNode.getComputedBorder(LayoutEdge.Top);
1045
+ const borderBottom = yogaNode.getComputedBorder(LayoutEdge.Bottom);
1046
+ const innerWidth = Math.floor(width) - borderLeft - borderRight;
1047
+ const innerHeight = Math.floor(height) - borderTop - borderBottom;
1048
+ if (innerWidth > 0 && innerHeight > 0) {
1049
+ const spaces = ' '.repeat(innerWidth);
1050
+ const fillLine = ownBackgroundColor
1051
+ ? applyTextStyles(spaces, { backgroundColor: ownBackgroundColor })
1052
+ : spaces;
1053
+ const fill = Array(innerHeight).fill(fillLine).join('\n');
1054
+ output.write(x + borderLeft, y + borderTop, fill);
1055
+ }
1056
+ }
1057
+ renderChildren(node, output, x, y, hasRemovedChild,
1058
+ // backgroundColor and opaque both disable child blit: the fill
1059
+ // overwrites the entire interior each render, so any child whose
1060
+ // layout position shifted would blit stale cells from prevScreen
1061
+ // on top of the fresh fill. Previously opaque kept blit enabled
1062
+ // on the assumption that plain-space fill + unchanged children =
1063
+ // valid composite, but children CAN reposition (ScrollBox remeasure
1064
+ // on re-render → /permissions body blanked on Down arrow, #25436).
1065
+ ownBackgroundColor || node.style.opaque ? undefined : prevScreen, boxBackgroundColor);
1066
+ }
1067
+ if (needsClip) {
1068
+ output.unclip();
1069
+ }
1070
+ // Render border AFTER children to ensure it's not overwritten by child
1071
+ // clearing operations. When a child shrinks, it clears its old area,
1072
+ // which may overlap with where the parent's border now is.
1073
+ renderBorder(x, y, node, output);
1074
+ }
1075
+ else if (node.nodeName === 'ink-root') {
1076
+ renderChildren(node, output, x, y, hasRemovedChild, prevScreen, inheritedBackgroundColor);
1077
+ }
1078
+ // Cache layout bounds for dirty tracking
1079
+ const rect = { x, y, width, height, top: yogaTop };
1080
+ nodeCache.set(node, rect);
1081
+ if (node.style.position === 'absolute') {
1082
+ absoluteRectsCur.push(rect);
1083
+ }
1084
+ node.dirty = false;
1085
+ }
1086
+ }
1087
+ // Overflow contamination: content overflows right/down, so clean siblings
1088
+ // AFTER a dirty/removed sibling can contain stale overflow in prevScreen.
1089
+ // Disable blit for siblings after a dirty child — but still pass prevScreen
1090
+ // TO the dirty child itself so its clean descendants can blit. The dirty
1091
+ // child's own blit check already fails (node.dirty=true at line 216), so
1092
+ // passing prevScreen only benefits its subtree.
1093
+ // For removed children we don't know their original position, so
1094
+ // conservatively disable blit for all.
1095
+ //
1096
+ // Clipped children (overflow hidden/scroll on both axes) cannot overflow
1097
+ // onto later siblings — their content is confined to their layout bounds.
1098
+ // Skip the contamination guard for them so later siblings can still blit.
1099
+ // Without this, a spinner inside a ScrollBox dirties the wrapper on every
1100
+ // tick and the bottom prompt section never blits → 100% writes every frame.
1101
+ //
1102
+ // Exception: absolute-positioned clipped children may have layout bounds
1103
+ // that overlap arbitrary siblings, so the clipping does not help.
1104
+ //
1105
+ // Overlap contamination (seenDirtyClipped): a later ABSOLUTE sibling whose
1106
+ // rect sits inside a dirty clipped child's bounds would blit stale cells
1107
+ // from prevScreen — the clipped child just rewrote those cells this frame.
1108
+ // The clipsBothAxes skip only protects against OVERFLOW (clipped child
1109
+ // painting outside its bounds), not overlap (absolute sibling painting
1110
+ // inside them). For non-opaque absolute siblings, skipSelfBlit forces
1111
+ // descent (the full-width rect has transparent gaps → stale blit) while
1112
+ // still passing prevScreen so opaque descendants can blit their narrower
1113
+ // rects (NewMessagesPill's inner Text with backgroundColor). Opaque
1114
+ // absolute siblings fill their entire rect — direct blit is safe.
1115
+ function renderChildren(node, output, offsetX, offsetY, hasRemovedChild, prevScreen, inheritedBackgroundColor) {
1116
+ let seenDirtyChild = false;
1117
+ let seenDirtyClipped = false;
1118
+ for (const childNode of node.childNodes) {
1119
+ const childElem = childNode;
1120
+ // Capture dirty before rendering — renderNodeToOutput clears the flag
1121
+ const wasDirty = childElem.dirty;
1122
+ const isAbsolute = childElem.style.position === 'absolute';
1123
+ renderNodeToOutput(childElem, output, {
1124
+ offsetX,
1125
+ offsetY,
1126
+ prevScreen: hasRemovedChild || seenDirtyChild ? undefined : prevScreen,
1127
+ // Short-circuits on seenDirtyClipped (false in the common case) so
1128
+ // the opaque/bg reads don't happen per-child per-frame.
1129
+ skipSelfBlit: seenDirtyClipped &&
1130
+ isAbsolute &&
1131
+ !childElem.style.opaque &&
1132
+ childElem.style.backgroundColor === undefined,
1133
+ inheritedBackgroundColor,
1134
+ });
1135
+ if (wasDirty && !seenDirtyChild) {
1136
+ if (!clipsBothAxes(childElem) || isAbsolute) {
1137
+ seenDirtyChild = true;
1138
+ }
1139
+ else {
1140
+ seenDirtyClipped = true;
1141
+ }
1142
+ }
1143
+ }
1144
+ }
1145
+ function clipsBothAxes(node) {
1146
+ const ox = node.style.overflowX ?? node.style.overflow;
1147
+ const oy = node.style.overflowY ?? node.style.overflow;
1148
+ return ((ox === 'hidden' || ox === 'scroll') && (oy === 'hidden' || oy === 'scroll'));
1149
+ }
1150
+ // When Yoga squeezes a box to h=0, the ghost only happens if a sibling
1151
+ // lands at the same computed top — then both write to that row and the
1152
+ // shorter content leaves the longer's tail visible. Yoga's pixel-grid
1153
+ // rounding can give h=0 while still advancing the next sibling's top
1154
+ // (HelpV2's third shortcuts column), so h=0 alone isn't sufficient.
1155
+ function siblingSharesY(node, yogaNode) {
1156
+ const parent = node.parentNode;
1157
+ if (!parent)
1158
+ return false;
1159
+ const myTop = yogaNode.getComputedTop();
1160
+ const siblings = parent.childNodes;
1161
+ const idx = siblings.indexOf(node);
1162
+ for (let i = idx + 1; i < siblings.length; i++) {
1163
+ const sib = siblings[i].yogaNode;
1164
+ if (!sib)
1165
+ continue;
1166
+ return sib.getComputedTop() === myTop;
1167
+ }
1168
+ // No next sibling with a yoga node — check previous. A run of h=0 boxes
1169
+ // at the tail would all share y with each other.
1170
+ for (let i = idx - 1; i >= 0; i--) {
1171
+ const sib = siblings[i].yogaNode;
1172
+ if (!sib)
1173
+ continue;
1174
+ return sib.getComputedTop() === myTop;
1175
+ }
1176
+ return false;
1177
+ }
1178
+ // When a node blits, its absolute-positioned descendants that paint outside
1179
+ // the node's layout bounds are NOT covered by the blit (which only copies
1180
+ // the node's own rect). If a dirty sibling re-rendered and overwrote those
1181
+ // cells, we must re-blit them from prevScreen so the overlays survive.
1182
+ // Example: PromptInputFooter's slash menu uses position='absolute' bottom='100%'
1183
+ // to float above the prompt; a spinner tick in the ScrollBox above re-renders
1184
+ // and overwrites those cells. Without this, the menu vanishes on the next frame.
1185
+ function blitEscapingAbsoluteDescendants(node, output, prevScreen, px, py, pw, ph) {
1186
+ const pr = px + pw;
1187
+ const pb = py + ph;
1188
+ for (const child of node.childNodes) {
1189
+ if (child.nodeName === '#text')
1190
+ continue;
1191
+ const elem = child;
1192
+ if (elem.style.position === 'absolute') {
1193
+ const cached = nodeCache.get(elem);
1194
+ if (cached) {
1195
+ absoluteRectsCur.push(cached);
1196
+ const cx = Math.floor(cached.x);
1197
+ const cy = Math.floor(cached.y);
1198
+ const cw = Math.floor(cached.width);
1199
+ const ch = Math.floor(cached.height);
1200
+ // Only blit rects that extend outside the parent's layout bounds —
1201
+ // cells within the parent rect are already covered by the parent blit.
1202
+ if (cx < px || cy < py || cx + cw > pr || cy + ch > pb) {
1203
+ output.blit(prevScreen, cx, cy, cw, ch);
1204
+ }
1205
+ }
1206
+ }
1207
+ // Recurse — absolute descendants can be nested arbitrarily deep
1208
+ blitEscapingAbsoluteDescendants(elem, output, prevScreen, px, py, pw, ph);
1209
+ }
1210
+ }
1211
+ // Render children of a scroll container with viewport culling.
1212
+ // scrollTopY..scrollBottomY are the visible window in CHILD-LOCAL Yoga coords
1213
+ // (i.e. what getComputedTop() returns). Children entirely outside this window
1214
+ // are skipped; their nodeCache entry is deleted so if they re-enter the
1215
+ // viewport later they don't emit a stale clear for a position now occupied
1216
+ // by a sibling.
1217
+ function renderScrolledChildren(node, output, offsetX, offsetY, hasRemovedChild, prevScreen, scrollTopY, scrollBottomY, inheritedBackgroundColor,
1218
+ // When true (DECSTBM fast path), culled children keep their cache —
1219
+ // the blit+shift put stable rows in next.screen so stale cache is
1220
+ // never read. Avoids walking O(total_children * subtree_depth) per frame.
1221
+ preserveCulledCache = false) {
1222
+ let seenDirtyChild = false;
1223
+ // Track cumulative height shift of dirty children iterated so far. When
1224
+ // zero, a clean child's yogaTop is unchanged (no sibling above it grew),
1225
+ // so cached.top is fresh and the cull check skips yoga. Bottom-append
1226
+ // has the dirty child last → all prior clean children hit cache →
1227
+ // O(dirty) not O(mounted). Middle-growth leaves shift non-zero after
1228
+ // the dirty child → subsequent children yoga-read (needed for correct
1229
+ // culling since their yogaTop shifted).
1230
+ let cumHeightShift = 0;
1231
+ for (const childNode of node.childNodes) {
1232
+ const childElem = childNode;
1233
+ const cy = childElem.yogaNode;
1234
+ if (cy) {
1235
+ const cached = nodeCache.get(childElem);
1236
+ let top;
1237
+ let height;
1238
+ if (cached?.top !== undefined &&
1239
+ !childElem.dirty &&
1240
+ cumHeightShift === 0) {
1241
+ top = cached.top;
1242
+ height = cached.height;
1243
+ }
1244
+ else {
1245
+ top = cy.getComputedTop();
1246
+ height = cy.getComputedHeight();
1247
+ if (childElem.dirty) {
1248
+ cumHeightShift += height - (cached ? cached.height : 0);
1249
+ }
1250
+ // Refresh cached top so next frame's cumShift===0 path stays
1251
+ // correct. For culled children with preserveCulledCache=true this
1252
+ // is the ONLY refresh point — without it, a middle-growth frame
1253
+ // leaves stale tops that misfire next frame.
1254
+ if (cached)
1255
+ cached.top = top;
1256
+ }
1257
+ const bottom = top + height;
1258
+ if (bottom <= scrollTopY || top >= scrollBottomY) {
1259
+ // Culled — outside visible window. Drop stale cache entries from
1260
+ // the subtree so when this child re-enters it doesn't fire clears
1261
+ // at positions now occupied by siblings. The viewport-clear on
1262
+ // scroll-change handles the visible-area repaint.
1263
+ if (!preserveCulledCache)
1264
+ dropSubtreeCache(childElem);
1265
+ continue;
1266
+ }
1267
+ }
1268
+ const wasDirty = childElem.dirty;
1269
+ renderNodeToOutput(childElem, output, {
1270
+ offsetX,
1271
+ offsetY,
1272
+ prevScreen: hasRemovedChild || seenDirtyChild ? undefined : prevScreen,
1273
+ inheritedBackgroundColor,
1274
+ });
1275
+ if (wasDirty) {
1276
+ seenDirtyChild = true;
1277
+ }
1278
+ }
1279
+ }
1280
+ function dropSubtreeCache(node) {
1281
+ nodeCache.delete(node);
1282
+ for (const child of node.childNodes) {
1283
+ if (child.nodeName !== '#text') {
1284
+ dropSubtreeCache(child);
1285
+ }
1286
+ }
1287
+ }
1288
+ // Exported for testing
1289
+ export { buildCharToSegmentMap, applyStylesToWrappedText };
1290
+ export default renderNodeToOutput;