nastech-tui 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (424) hide show
  1. package/.prettierrc +11 -0
  2. package/README.md +346 -0
  3. package/eslint.config.mjs +111 -0
  4. package/package.json +51 -0
  5. package/packages/nastech-ink/ambient.d.ts +83 -0
  6. package/packages/nastech-ink/index.d.ts +40 -0
  7. package/packages/nastech-ink/index.js +1 -0
  8. package/packages/nastech-ink/nastech-ink/ambient.d.ts +83 -0
  9. package/packages/nastech-ink/nastech-ink/index.d.ts +40 -0
  10. package/packages/nastech-ink/nastech-ink/index.js +1 -0
  11. package/packages/nastech-ink/nastech-ink/package.json +54 -0
  12. package/packages/nastech-ink/nastech-ink/src/bootstrap/state.ts +9 -0
  13. package/packages/nastech-ink/nastech-ink/src/entry-exports.ts +32 -0
  14. package/packages/nastech-ink/nastech-ink/src/hooks/use-stderr.ts +15 -0
  15. package/packages/nastech-ink/nastech-ink/src/hooks/use-stdout.ts +15 -0
  16. package/packages/nastech-ink/nastech-ink/src/ink/Ansi.tsx +435 -0
  17. package/packages/nastech-ink/nastech-ink/src/ink/app-mouse.test.ts +123 -0
  18. package/packages/nastech-ink/nastech-ink/src/ink/bidi.ts +145 -0
  19. package/packages/nastech-ink/nastech-ink/src/ink/cache-eviction.ts +45 -0
  20. package/packages/nastech-ink/nastech-ink/src/ink/clearTerminal.ts +68 -0
  21. package/packages/nastech-ink/nastech-ink/src/ink/colorize.test.ts +60 -0
  22. package/packages/nastech-ink/nastech-ink/src/ink/colorize.ts +277 -0
  23. package/packages/nastech-ink/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
  24. package/packages/nastech-ink/nastech-ink/src/ink/components/App.tsx +830 -0
  25. package/packages/nastech-ink/nastech-ink/src/ink/components/AppContext.ts +20 -0
  26. package/packages/nastech-ink/nastech-ink/src/ink/components/Box.tsx +294 -0
  27. package/packages/nastech-ink/nastech-ink/src/ink/components/Button.tsx +236 -0
  28. package/packages/nastech-ink/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
  29. package/packages/nastech-ink/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
  30. package/packages/nastech-ink/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
  31. package/packages/nastech-ink/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
  32. package/packages/nastech-ink/nastech-ink/src/ink/components/Link.tsx +38 -0
  33. package/packages/nastech-ink/nastech-ink/src/ink/components/Newline.tsx +43 -0
  34. package/packages/nastech-ink/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
  35. package/packages/nastech-ink/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
  36. package/packages/nastech-ink/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
  37. package/packages/nastech-ink/nastech-ink/src/ink/components/Spacer.tsx +23 -0
  38. package/packages/nastech-ink/nastech-ink/src/ink/components/StdinContext.ts +25 -0
  39. package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
  40. package/packages/nastech-ink/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
  41. package/packages/nastech-ink/nastech-ink/src/ink/components/Text.test.ts +38 -0
  42. package/packages/nastech-ink/nastech-ink/src/ink/components/Text.tsx +336 -0
  43. package/packages/nastech-ink/nastech-ink/src/ink/constants.ts +6 -0
  44. package/packages/nastech-ink/nastech-ink/src/ink/cursor.ts +5 -0
  45. package/packages/nastech-ink/nastech-ink/src/ink/devtools.ts +2 -0
  46. package/packages/nastech-ink/nastech-ink/src/ink/dom.ts +495 -0
  47. package/packages/nastech-ink/nastech-ink/src/ink/events/click-event.ts +38 -0
  48. package/packages/nastech-ink/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
  49. package/packages/nastech-ink/nastech-ink/src/ink/events/dispatcher.ts +242 -0
  50. package/packages/nastech-ink/nastech-ink/src/ink/events/emitter.ts +40 -0
  51. package/packages/nastech-ink/nastech-ink/src/ink/events/event-handlers.ts +84 -0
  52. package/packages/nastech-ink/nastech-ink/src/ink/events/event.ts +11 -0
  53. package/packages/nastech-ink/nastech-ink/src/ink/events/focus-event.ts +18 -0
  54. package/packages/nastech-ink/nastech-ink/src/ink/events/input-event.ts +176 -0
  55. package/packages/nastech-ink/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
  56. package/packages/nastech-ink/nastech-ink/src/ink/events/mouse-event.ts +18 -0
  57. package/packages/nastech-ink/nastech-ink/src/ink/events/paste-event.ts +10 -0
  58. package/packages/nastech-ink/nastech-ink/src/ink/events/resize-event.ts +12 -0
  59. package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-event.ts +107 -0
  60. package/packages/nastech-ink/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
  61. package/packages/nastech-ink/nastech-ink/src/ink/focus.ts +219 -0
  62. package/packages/nastech-ink/nastech-ink/src/ink/frame.ts +124 -0
  63. package/packages/nastech-ink/nastech-ink/src/ink/get-max-width.ts +27 -0
  64. package/packages/nastech-ink/nastech-ink/src/ink/global.d.ts +1 -0
  65. package/packages/nastech-ink/nastech-ink/src/ink/hit-test.test.ts +38 -0
  66. package/packages/nastech-ink/nastech-ink/src/ink/hit-test.ts +224 -0
  67. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
  68. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-app.ts +9 -0
  69. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
  70. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
  71. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
  72. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-input.ts +95 -0
  73. package/packages/nastech-ink/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
  74. package/packages/nastech-ink/package.json +57 -0
  75. package/packages/nastech-ink/src/bootstrap/state.ts +9 -0
  76. package/packages/nastech-ink/src/entry-exports.ts +32 -0
  77. package/packages/nastech-ink/src/hooks/use-stderr.ts +15 -0
  78. package/packages/nastech-ink/src/hooks/use-stdout.ts +15 -0
  79. package/packages/nastech-ink/src/ink/Ansi.tsx +435 -0
  80. package/packages/nastech-ink/src/ink/app-mouse.test.ts +123 -0
  81. package/packages/nastech-ink/src/ink/app-rawmode-mouse.test.ts +91 -0
  82. package/packages/nastech-ink/src/ink/bidi.ts +145 -0
  83. package/packages/nastech-ink/src/ink/cache-eviction.ts +45 -0
  84. package/packages/nastech-ink/src/ink/clearTerminal.ts +68 -0
  85. package/packages/nastech-ink/src/ink/colorize.test.ts +60 -0
  86. package/packages/nastech-ink/src/ink/colorize.ts +277 -0
  87. package/packages/nastech-ink/src/ink/components/AlternateScreen.tsx +133 -0
  88. package/packages/nastech-ink/src/ink/components/App.tsx +855 -0
  89. package/packages/nastech-ink/src/ink/components/AppContext.ts +20 -0
  90. package/packages/nastech-ink/src/ink/components/Box.tsx +294 -0
  91. package/packages/nastech-ink/src/ink/components/Button.tsx +236 -0
  92. package/packages/nastech-ink/src/ink/components/ClockContext.tsx +133 -0
  93. package/packages/nastech-ink/src/ink/components/CursorAdvanceContext.ts +35 -0
  94. package/packages/nastech-ink/src/ink/components/CursorDeclarationContext.ts +28 -0
  95. package/packages/nastech-ink/src/ink/components/ErrorOverview.tsx +130 -0
  96. package/packages/nastech-ink/src/ink/components/Link.tsx +38 -0
  97. package/packages/nastech-ink/src/ink/components/Newline.tsx +43 -0
  98. package/packages/nastech-ink/src/ink/components/NoSelect.tsx +73 -0
  99. package/packages/nastech-ink/src/ink/components/RawAnsi.tsx +61 -0
  100. package/packages/nastech-ink/src/ink/components/ScrollBox.tsx +290 -0
  101. package/packages/nastech-ink/src/ink/components/Spacer.tsx +23 -0
  102. package/packages/nastech-ink/src/ink/components/StdinContext.ts +25 -0
  103. package/packages/nastech-ink/src/ink/components/TerminalFocusContext.tsx +63 -0
  104. package/packages/nastech-ink/src/ink/components/TerminalSizeContext.tsx +7 -0
  105. package/packages/nastech-ink/src/ink/components/Text.test.ts +38 -0
  106. package/packages/nastech-ink/src/ink/components/Text.tsx +336 -0
  107. package/packages/nastech-ink/src/ink/constants.ts +6 -0
  108. package/packages/nastech-ink/src/ink/cursor.ts +5 -0
  109. package/packages/nastech-ink/src/ink/devtools.ts +2 -0
  110. package/packages/nastech-ink/src/ink/dom.ts +495 -0
  111. package/packages/nastech-ink/src/ink/events/click-event.ts +38 -0
  112. package/packages/nastech-ink/src/ink/events/cmd-shortcuts.test.ts +65 -0
  113. package/packages/nastech-ink/src/ink/events/dispatcher.ts +242 -0
  114. package/packages/nastech-ink/src/ink/events/emitter.ts +40 -0
  115. package/packages/nastech-ink/src/ink/events/event-handlers.ts +84 -0
  116. package/packages/nastech-ink/src/ink/events/event.ts +11 -0
  117. package/packages/nastech-ink/src/ink/events/focus-event.ts +18 -0
  118. package/packages/nastech-ink/src/ink/events/input-event.ts +176 -0
  119. package/packages/nastech-ink/src/ink/events/keyboard-event.ts +57 -0
  120. package/packages/nastech-ink/src/ink/events/mouse-event.ts +18 -0
  121. package/packages/nastech-ink/src/ink/events/paste-event.ts +10 -0
  122. package/packages/nastech-ink/src/ink/events/resize-event.ts +12 -0
  123. package/packages/nastech-ink/src/ink/events/terminal-event.ts +107 -0
  124. package/packages/nastech-ink/src/ink/events/terminal-focus-event.ts +19 -0
  125. package/packages/nastech-ink/src/ink/focus.ts +219 -0
  126. package/packages/nastech-ink/src/ink/frame.ts +124 -0
  127. package/packages/nastech-ink/src/ink/get-max-width.ts +27 -0
  128. package/packages/nastech-ink/src/ink/global.d.ts +1 -0
  129. package/packages/nastech-ink/src/ink/hit-test.test.ts +38 -0
  130. package/packages/nastech-ink/src/ink/hit-test.ts +224 -0
  131. package/packages/nastech-ink/src/ink/hooks/use-animation-frame.ts +62 -0
  132. package/packages/nastech-ink/src/ink/hooks/use-app.ts +9 -0
  133. package/packages/nastech-ink/src/ink/hooks/use-cursor-advance.ts +33 -0
  134. package/packages/nastech-ink/src/ink/hooks/use-declared-cursor.ts +75 -0
  135. package/packages/nastech-ink/src/ink/hooks/use-external-process.ts +27 -0
  136. package/packages/nastech-ink/src/ink/hooks/use-input.ts +95 -0
  137. package/packages/nastech-ink/src/ink/hooks/use-interval.ts +71 -0
  138. package/packages/nastech-ink/src/ink/hooks/use-search-highlight.ts +56 -0
  139. package/packages/nastech-ink/src/ink/hooks/use-selection.ts +101 -0
  140. package/packages/nastech-ink/src/ink/hooks/use-stdin.ts +9 -0
  141. package/packages/nastech-ink/src/ink/hooks/use-tab-status.ts +71 -0
  142. package/packages/nastech-ink/src/ink/hooks/use-terminal-focus.ts +18 -0
  143. package/packages/nastech-ink/src/ink/hooks/use-terminal-title.ts +34 -0
  144. package/packages/nastech-ink/src/ink/hooks/use-terminal-viewport.ts +100 -0
  145. package/packages/nastech-ink/src/ink/hyperlinkHover.ts +52 -0
  146. package/packages/nastech-ink/src/ink/ink-cursor-advance.test.ts +234 -0
  147. package/packages/nastech-ink/src/ink/ink-resize.test.ts +50 -0
  148. package/packages/nastech-ink/src/ink/ink.tsx +2705 -0
  149. package/packages/nastech-ink/src/ink/instances.ts +10 -0
  150. package/packages/nastech-ink/src/ink/layout/engine.ts +6 -0
  151. package/packages/nastech-ink/src/ink/layout/geometry.ts +98 -0
  152. package/packages/nastech-ink/src/ink/layout/node.ts +145 -0
  153. package/packages/nastech-ink/src/ink/layout/yoga.ts +313 -0
  154. package/packages/nastech-ink/src/ink/line-width-cache.ts +38 -0
  155. package/packages/nastech-ink/src/ink/log-update.test.ts +223 -0
  156. package/packages/nastech-ink/src/ink/log-update.ts +752 -0
  157. package/packages/nastech-ink/src/ink/lru.ts +14 -0
  158. package/packages/nastech-ink/src/ink/measure-element.ts +23 -0
  159. package/packages/nastech-ink/src/ink/measure-text.ts +50 -0
  160. package/packages/nastech-ink/src/ink/node-cache.ts +53 -0
  161. package/packages/nastech-ink/src/ink/optimizer.ts +99 -0
  162. package/packages/nastech-ink/src/ink/output.ts +845 -0
  163. package/packages/nastech-ink/src/ink/parse-keypress.test.ts +133 -0
  164. package/packages/nastech-ink/src/ink/parse-keypress.ts +848 -0
  165. package/packages/nastech-ink/src/ink/reconciler.ts +382 -0
  166. package/packages/nastech-ink/src/ink/render-border.ts +206 -0
  167. package/packages/nastech-ink/src/ink/render-node-to-output.ts +1582 -0
  168. package/packages/nastech-ink/src/ink/render-to-screen.ts +236 -0
  169. package/packages/nastech-ink/src/ink/renderer.ts +169 -0
  170. package/packages/nastech-ink/src/ink/root.ts +204 -0
  171. package/packages/nastech-ink/src/ink/screen.ts +1590 -0
  172. package/packages/nastech-ink/src/ink/searchHighlight.ts +91 -0
  173. package/packages/nastech-ink/src/ink/selection.test.ts +82 -0
  174. package/packages/nastech-ink/src/ink/selection.ts +1143 -0
  175. package/packages/nastech-ink/src/ink/squash-text-nodes.ts +74 -0
  176. package/packages/nastech-ink/src/ink/stringWidth.ts +341 -0
  177. package/packages/nastech-ink/src/ink/styles.ts +750 -0
  178. package/packages/nastech-ink/src/ink/supports-hyperlinks.ts +51 -0
  179. package/packages/nastech-ink/src/ink/tabstops.ts +44 -0
  180. package/packages/nastech-ink/src/ink/terminal-focus-state.ts +52 -0
  181. package/packages/nastech-ink/src/ink/terminal-querier.ts +222 -0
  182. package/packages/nastech-ink/src/ink/terminal.test.ts +15 -0
  183. package/packages/nastech-ink/src/ink/terminal.ts +299 -0
  184. package/packages/nastech-ink/src/ink/termio/ansi.ts +75 -0
  185. package/packages/nastech-ink/src/ink/termio/csi.ts +334 -0
  186. package/packages/nastech-ink/src/ink/termio/dec.ts +99 -0
  187. package/packages/nastech-ink/src/ink/termio/esc.ts +69 -0
  188. package/packages/nastech-ink/src/ink/termio/osc.test.ts +191 -0
  189. package/packages/nastech-ink/src/ink/termio/osc.ts +724 -0
  190. package/packages/nastech-ink/src/ink/termio/parser.ts +467 -0
  191. package/packages/nastech-ink/src/ink/termio/sgr.ts +362 -0
  192. package/packages/nastech-ink/src/ink/termio/tokenize.test.ts +185 -0
  193. package/packages/nastech-ink/src/ink/termio/tokenize.ts +350 -0
  194. package/packages/nastech-ink/src/ink/termio/types.ts +230 -0
  195. package/packages/nastech-ink/src/ink/termio.ts +42 -0
  196. package/packages/nastech-ink/src/ink/useTerminalNotification.ts +110 -0
  197. package/packages/nastech-ink/src/ink/warn.ts +15 -0
  198. package/packages/nastech-ink/src/ink/widest-line.ts +22 -0
  199. package/packages/nastech-ink/src/ink/wrap-text.test.ts +17 -0
  200. package/packages/nastech-ink/src/ink/wrap-text.ts +144 -0
  201. package/packages/nastech-ink/src/ink/wrapAnsi.ts +13 -0
  202. package/packages/nastech-ink/src/native-ts/yoga-layout/enums.ts +112 -0
  203. package/packages/nastech-ink/src/native-ts/yoga-layout/index.ts +2326 -0
  204. package/packages/nastech-ink/src/utils/debug.ts +6 -0
  205. package/packages/nastech-ink/src/utils/earlyInput.ts +131 -0
  206. package/packages/nastech-ink/src/utils/env.ts +66 -0
  207. package/packages/nastech-ink/src/utils/envUtils.ts +13 -0
  208. package/packages/nastech-ink/src/utils/execFileNoThrow.test.ts +146 -0
  209. package/packages/nastech-ink/src/utils/execFileNoThrow.ts +115 -0
  210. package/packages/nastech-ink/src/utils/fullscreen.ts +3 -0
  211. package/packages/nastech-ink/src/utils/intl.ts +87 -0
  212. package/packages/nastech-ink/src/utils/log.ts +7 -0
  213. package/packages/nastech-ink/src/utils/semver.ts +57 -0
  214. package/packages/nastech-ink/src/utils/sliceAnsi.ts +106 -0
  215. package/packages/nastech-ink/text-input.d.ts +2 -0
  216. package/packages/nastech-ink/text-input.js +1 -0
  217. package/scripts/build.mjs +61 -0
  218. package/scripts/profile-tui.mjs +121 -0
  219. package/src/__tests__/activeSessionSwitcher.test.ts +157 -0
  220. package/src/__tests__/appChromeStatusRule.test.tsx +84 -0
  221. package/src/__tests__/appChromeStatusRuleDevCredits.test.tsx +73 -0
  222. package/src/__tests__/approvalAction.test.ts +50 -0
  223. package/src/__tests__/asCommandDispatch.test.ts +27 -0
  224. package/src/__tests__/blockLayout.test.ts +122 -0
  225. package/src/__tests__/clipboard.test.ts +369 -0
  226. package/src/__tests__/constants.test.ts +53 -0
  227. package/src/__tests__/createGatewayEventHandler.test.ts +1091 -0
  228. package/src/__tests__/createSlashHandler.test.ts +822 -0
  229. package/src/__tests__/creditsCommand.test.ts +144 -0
  230. package/src/__tests__/cursorDriftRegression.test.ts +114 -0
  231. package/src/__tests__/details.test.ts +115 -0
  232. package/src/__tests__/emoji.test.ts +64 -0
  233. package/src/__tests__/externalLink.test.ts +144 -0
  234. package/src/__tests__/forceTruecolor.test.ts +191 -0
  235. package/src/__tests__/gatewayClient.test.ts +394 -0
  236. package/src/__tests__/gatewayRecovery.test.ts +47 -0
  237. package/src/__tests__/markdown.test.ts +331 -0
  238. package/src/__tests__/mathUnicode.test.ts +293 -0
  239. package/src/__tests__/memoryMonitor.test.ts +102 -0
  240. package/src/__tests__/messageLine.test.ts +19 -0
  241. package/src/__tests__/messages.test.ts +92 -0
  242. package/src/__tests__/orchestratorPromptSession.test.ts +64 -0
  243. package/src/__tests__/osc52.test.ts +67 -0
  244. package/src/__tests__/parentLog.test.ts +75 -0
  245. package/src/__tests__/paths.test.ts +70 -0
  246. package/src/__tests__/platform.test.ts +556 -0
  247. package/src/__tests__/precisionWheel.test.ts +44 -0
  248. package/src/__tests__/prompt.test.ts +31 -0
  249. package/src/__tests__/providers.test.ts +65 -0
  250. package/src/__tests__/reasoning.test.ts +76 -0
  251. package/src/__tests__/rpc.test.ts +27 -0
  252. package/src/__tests__/scroll.test.ts +99 -0
  253. package/src/__tests__/slashParity.test.ts +123 -0
  254. package/src/__tests__/spawnHistoryStore.test.ts +46 -0
  255. package/src/__tests__/stateIsolation.test.ts +46 -0
  256. package/src/__tests__/statusBarTicker.test.ts +18 -0
  257. package/src/__tests__/statusRule.test.ts +32 -0
  258. package/src/__tests__/streamingMarkdown.test.ts +121 -0
  259. package/src/__tests__/subagentTree.test.ts +407 -0
  260. package/src/__tests__/syntax.test.ts +45 -0
  261. package/src/__tests__/terminalModes.test.ts +39 -0
  262. package/src/__tests__/terminalParity.test.ts +77 -0
  263. package/src/__tests__/terminalSetup.test.ts +386 -0
  264. package/src/__tests__/termux.test.ts +35 -0
  265. package/src/__tests__/termuxComposerLayout.test.ts +40 -0
  266. package/src/__tests__/text.test.ts +233 -0
  267. package/src/__tests__/textInputBurstInput.test.ts +40 -0
  268. package/src/__tests__/textInputCursorSourceOfTruth.test.ts +50 -0
  269. package/src/__tests__/textInputFastEcho.test.ts +200 -0
  270. package/src/__tests__/textInputLineNav.test.ts +55 -0
  271. package/src/__tests__/textInputPassThrough.test.ts +59 -0
  272. package/src/__tests__/textInputRightClick.test.ts +48 -0
  273. package/src/__tests__/textInputWrap.test.ts +151 -0
  274. package/src/__tests__/theme.test.ts +311 -0
  275. package/src/__tests__/turnControllerNotice.test.ts +43 -0
  276. package/src/__tests__/turnStore.test.ts +66 -0
  277. package/src/__tests__/useCompletion.test.ts +35 -0
  278. package/src/__tests__/useComposerState.test.ts +59 -0
  279. package/src/__tests__/useConfigSync.test.ts +460 -0
  280. package/src/__tests__/useInputHandlers.test.ts +77 -0
  281. package/src/__tests__/useQueue.test.ts +28 -0
  282. package/src/__tests__/useSessionLifecycle.test.ts +60 -0
  283. package/src/__tests__/useVirtualHistoryHeights.test.ts +39 -0
  284. package/src/__tests__/viewport.test.ts +58 -0
  285. package/src/__tests__/viewportStore.test.ts +85 -0
  286. package/src/__tests__/virtualHeights.test.ts +96 -0
  287. package/src/__tests__/virtualHistoryClamp.test.ts +19 -0
  288. package/src/__tests__/virtualHistoryOffsetCache.test.ts +282 -0
  289. package/src/__tests__/wheelAccel.test.ts +138 -0
  290. package/src/app/createGatewayEventHandler.ts +833 -0
  291. package/src/app/createSlashHandler.ts +130 -0
  292. package/src/app/delegationStore.ts +77 -0
  293. package/src/app/gatewayContext.tsx +19 -0
  294. package/src/app/gatewayRecovery.ts +35 -0
  295. package/src/app/inputSelectionStore.ts +15 -0
  296. package/src/app/interfaces.ts +394 -0
  297. package/src/app/overlayStore.ts +53 -0
  298. package/src/app/scroll.ts +71 -0
  299. package/src/app/setupHandoff.ts +54 -0
  300. package/src/app/slash/commands/core.ts +648 -0
  301. package/src/app/slash/commands/credits.ts +57 -0
  302. package/src/app/slash/commands/debug.ts +48 -0
  303. package/src/app/slash/commands/ops.ts +717 -0
  304. package/src/app/slash/commands/session.ts +554 -0
  305. package/src/app/slash/commands/setup.ts +20 -0
  306. package/src/app/slash/registry.ts +20 -0
  307. package/src/app/slash/types.ts +21 -0
  308. package/src/app/spawnHistoryStore.ts +159 -0
  309. package/src/app/turnController.ts +866 -0
  310. package/src/app/turnStore.ts +85 -0
  311. package/src/app/uiStore.ts +44 -0
  312. package/src/app/useComposerState.ts +367 -0
  313. package/src/app/useConfigSync.ts +288 -0
  314. package/src/app/useInputHandlers.ts +576 -0
  315. package/src/app/useLongRunToolCharms.ts +69 -0
  316. package/src/app/useMainApp.ts +1039 -0
  317. package/src/app/useSessionLifecycle.ts +366 -0
  318. package/src/app/useSubmission.ts +429 -0
  319. package/src/app.tsx +25 -0
  320. package/src/banner.ts +93 -0
  321. package/src/components/activeSessionSwitcher.tsx +635 -0
  322. package/src/components/agentsOverlay.tsx +1073 -0
  323. package/src/components/appChrome.tsx +554 -0
  324. package/src/components/appLayout.tsx +444 -0
  325. package/src/components/appOverlays.tsx +254 -0
  326. package/src/components/branding.tsx +466 -0
  327. package/src/components/fpsOverlay.tsx +30 -0
  328. package/src/components/helpHint.tsx +73 -0
  329. package/src/components/markdown.tsx +1119 -0
  330. package/src/components/maskedPrompt.tsx +34 -0
  331. package/src/components/messageLine.tsx +237 -0
  332. package/src/components/modelPicker.tsx +527 -0
  333. package/src/components/overlayControls.tsx +50 -0
  334. package/src/components/pluginsHub.tsx +238 -0
  335. package/src/components/prompts.tsx +276 -0
  336. package/src/components/queuedMessages.tsx +64 -0
  337. package/src/components/sessionPicker.tsx +227 -0
  338. package/src/components/skillsHub.tsx +308 -0
  339. package/src/components/streamingAssistant.tsx +110 -0
  340. package/src/components/streamingMarkdown.tsx +174 -0
  341. package/src/components/textInput.tsx +1340 -0
  342. package/src/components/themed.tsx +30 -0
  343. package/src/components/thinking.tsx +1224 -0
  344. package/src/components/todoPanel.tsx +93 -0
  345. package/src/config/env.ts +64 -0
  346. package/src/config/limits.ts +13 -0
  347. package/src/config/timing.ts +6 -0
  348. package/src/content/charms.ts +1 -0
  349. package/src/content/faces.ts +17 -0
  350. package/src/content/fortunes.ts +30 -0
  351. package/src/content/hotkeys.ts +37 -0
  352. package/src/content/placeholders.ts +13 -0
  353. package/src/content/setup.ts +17 -0
  354. package/src/content/verbs.ts +38 -0
  355. package/src/domain/blockLayout.ts +146 -0
  356. package/src/domain/details.ts +76 -0
  357. package/src/domain/messages.ts +91 -0
  358. package/src/domain/paths.ts +16 -0
  359. package/src/domain/providers.ts +11 -0
  360. package/src/domain/roles.ts +9 -0
  361. package/src/domain/slash.ts +10 -0
  362. package/src/domain/usage.ts +3 -0
  363. package/src/domain/viewport.ts +51 -0
  364. package/src/entry.tsx +104 -0
  365. package/src/gatewayClient.ts +730 -0
  366. package/src/gatewayTypes.ts +568 -0
  367. package/src/hooks/useCompletion.ts +112 -0
  368. package/src/hooks/useGitBranch.ts +72 -0
  369. package/src/hooks/useInputHistory.ts +11 -0
  370. package/src/hooks/useQueue.ts +76 -0
  371. package/src/hooks/useVirtualHistory.ts +554 -0
  372. package/src/lib/circularBuffer.ts +48 -0
  373. package/src/lib/clipboard.ts +182 -0
  374. package/src/lib/editor.test.ts +74 -0
  375. package/src/lib/editor.ts +47 -0
  376. package/src/lib/emoji.ts +55 -0
  377. package/src/lib/externalCli.ts +16 -0
  378. package/src/lib/externalLink.ts +435 -0
  379. package/src/lib/forceTruecolor.ts +60 -0
  380. package/src/lib/fpsStore.ts +51 -0
  381. package/src/lib/fuzzy.test.ts +109 -0
  382. package/src/lib/fuzzy.ts +177 -0
  383. package/src/lib/gracefulExit.ts +47 -0
  384. package/src/lib/history.ts +82 -0
  385. package/src/lib/inputMetrics.ts +203 -0
  386. package/src/lib/liveProgress.test.ts +116 -0
  387. package/src/lib/liveProgress.ts +79 -0
  388. package/src/lib/mathUnicode.ts +770 -0
  389. package/src/lib/memory.test.ts +155 -0
  390. package/src/lib/memory.ts +188 -0
  391. package/src/lib/memoryMonitor.ts +109 -0
  392. package/src/lib/messages.test.ts +29 -0
  393. package/src/lib/messages.ts +8 -0
  394. package/src/lib/openExternalUrl.test.ts +217 -0
  395. package/src/lib/openExternalUrl.ts +158 -0
  396. package/src/lib/osc52.ts +73 -0
  397. package/src/lib/parentLog.ts +57 -0
  398. package/src/lib/perfPane.tsx +107 -0
  399. package/src/lib/platform.ts +409 -0
  400. package/src/lib/precisionWheel.ts +48 -0
  401. package/src/lib/prompt.ts +35 -0
  402. package/src/lib/reasoning.ts +55 -0
  403. package/src/lib/rpc.ts +41 -0
  404. package/src/lib/subagentTree.ts +355 -0
  405. package/src/lib/syntax.ts +117 -0
  406. package/src/lib/terminalModes.ts +51 -0
  407. package/src/lib/terminalParity.ts +78 -0
  408. package/src/lib/terminalSetup.ts +444 -0
  409. package/src/lib/termux.ts +29 -0
  410. package/src/lib/text.test.ts +18 -0
  411. package/src/lib/text.ts +339 -0
  412. package/src/lib/todo.test.ts +21 -0
  413. package/src/lib/todo.ts +9 -0
  414. package/src/lib/viewportStore.ts +124 -0
  415. package/src/lib/virtualHeights.ts +145 -0
  416. package/src/lib/wheelAccel.ts +190 -0
  417. package/src/protocol/interpolation.ts +3 -0
  418. package/src/protocol/paste.ts +1 -0
  419. package/src/theme.ts +589 -0
  420. package/src/types/nastech-ink.d.ts +176 -0
  421. package/src/types.ts +212 -0
  422. package/tsconfig.build.json +9 -0
  423. package/tsconfig.json +19 -0
  424. package/vitest.config.ts +7 -0
@@ -0,0 +1,750 @@
1
+ import {
2
+ LayoutAlign,
3
+ LayoutDisplay,
4
+ LayoutEdge,
5
+ LayoutFlexDirection,
6
+ LayoutGutter,
7
+ LayoutJustify,
8
+ type LayoutNode,
9
+ LayoutOverflow,
10
+ LayoutPositionType,
11
+ LayoutWrap
12
+ } from './layout/node.js'
13
+ import type { BorderStyle, BorderTextOptions } from './render-border.js'
14
+
15
+ export type RGBColor = `rgb(${number},${number},${number})`
16
+ export type HexColor = `#${string}`
17
+ export type Ansi256Color = `ansi256(${number})`
18
+ export type AnsiColor =
19
+ | 'ansi:black'
20
+ | 'ansi:red'
21
+ | 'ansi:green'
22
+ | 'ansi:yellow'
23
+ | 'ansi:blue'
24
+ | 'ansi:magenta'
25
+ | 'ansi:cyan'
26
+ | 'ansi:white'
27
+ | 'ansi:blackBright'
28
+ | 'ansi:redBright'
29
+ | 'ansi:greenBright'
30
+ | 'ansi:yellowBright'
31
+ | 'ansi:blueBright'
32
+ | 'ansi:magentaBright'
33
+ | 'ansi:cyanBright'
34
+ | 'ansi:whiteBright'
35
+
36
+ /** Raw color value - not a theme key */
37
+ export type Color = RGBColor | HexColor | Ansi256Color | AnsiColor
38
+
39
+ /**
40
+ * Structured text styling properties.
41
+ * Used to style text without relying on ANSI string transforms.
42
+ * Colors are raw values - theme resolution happens at the component layer.
43
+ */
44
+ export type TextStyles = {
45
+ readonly color?: Color
46
+ readonly backgroundColor?: Color
47
+ readonly dim?: boolean
48
+ readonly bold?: boolean
49
+ readonly italic?: boolean
50
+ readonly underline?: boolean
51
+ readonly strikethrough?: boolean
52
+ readonly inverse?: boolean
53
+ }
54
+
55
+ export type Styles = {
56
+ readonly textWrap?:
57
+ | 'wrap'
58
+ | 'wrap-char'
59
+ | 'wrap-trim'
60
+ | 'end'
61
+ | 'middle'
62
+ | 'truncate-end'
63
+ | 'truncate'
64
+ | 'truncate-middle'
65
+ | 'truncate-start'
66
+
67
+ readonly position?: 'absolute' | 'relative'
68
+ readonly top?: number | `${number}%`
69
+ readonly bottom?: number | `${number}%`
70
+ readonly left?: number | `${number}%`
71
+ readonly right?: number | `${number}%`
72
+
73
+ /**
74
+ * Size of the gap between an element's columns.
75
+ */
76
+ readonly columnGap?: number
77
+
78
+ /**
79
+ * Size of the gap between element's rows.
80
+ */
81
+ readonly rowGap?: number
82
+
83
+ /**
84
+ * Size of the gap between an element's columns and rows. Shorthand for `columnGap` and `rowGap`.
85
+ */
86
+ readonly gap?: number
87
+
88
+ /**
89
+ * Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft` and `marginRight`.
90
+ */
91
+ readonly margin?: number
92
+
93
+ /**
94
+ * Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
95
+ */
96
+ readonly marginX?: number
97
+
98
+ /**
99
+ * Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
100
+ */
101
+ readonly marginY?: number
102
+
103
+ /**
104
+ * Top margin.
105
+ */
106
+ readonly marginTop?: number
107
+
108
+ /**
109
+ * Bottom margin.
110
+ */
111
+ readonly marginBottom?: number
112
+
113
+ /**
114
+ * Left margin.
115
+ */
116
+ readonly marginLeft?: number
117
+
118
+ /**
119
+ * Right margin.
120
+ */
121
+ readonly marginRight?: number
122
+
123
+ /**
124
+ * Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft` and `paddingRight`.
125
+ */
126
+ readonly padding?: number
127
+
128
+ /**
129
+ * Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
130
+ */
131
+ readonly paddingX?: number
132
+
133
+ /**
134
+ * Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
135
+ */
136
+ readonly paddingY?: number
137
+
138
+ /**
139
+ * Top padding.
140
+ */
141
+ readonly paddingTop?: number
142
+
143
+ /**
144
+ * Bottom padding.
145
+ */
146
+ readonly paddingBottom?: number
147
+
148
+ /**
149
+ * Left padding.
150
+ */
151
+ readonly paddingLeft?: number
152
+
153
+ /**
154
+ * Right padding.
155
+ */
156
+ readonly paddingRight?: number
157
+
158
+ /**
159
+ * This property defines the ability for a flex item to grow if necessary.
160
+ * See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
161
+ */
162
+ readonly flexGrow?: number
163
+
164
+ /**
165
+ * It specifies the “flex shrink factor”, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the row.
166
+ * See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
167
+ */
168
+ readonly flexShrink?: number
169
+
170
+ /**
171
+ * It establishes the main-axis, thus defining the direction flex items are placed in the flex container.
172
+ * See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
173
+ */
174
+ readonly flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse'
175
+
176
+ /**
177
+ * It specifies the initial size of the flex item, before any available space is distributed according to the flex factors.
178
+ * See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
179
+ */
180
+ readonly flexBasis?: number | string
181
+
182
+ /**
183
+ * It defines whether the flex items are forced in a single line or can be flowed into multiple lines. If set to multiple lines, it also defines the cross-axis which determines the direction new lines are stacked in.
184
+ * See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
185
+ */
186
+ readonly flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse'
187
+
188
+ /**
189
+ * The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
190
+ * See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
191
+ */
192
+ readonly alignItems?: 'flex-start' | 'center' | 'flex-end' | 'stretch'
193
+
194
+ /**
195
+ * It makes possible to override the align-items value for specific flex items.
196
+ * See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
197
+ */
198
+ readonly alignSelf?: 'flex-start' | 'center' | 'flex-end' | 'auto'
199
+
200
+ /**
201
+ * It defines the alignment along the main axis.
202
+ * See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
203
+ */
204
+ readonly justifyContent?: 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly' | 'center'
205
+
206
+ /**
207
+ * Width of the element in spaces.
208
+ * You can also set it in percent, which will calculate the width based on the width of parent element.
209
+ */
210
+ readonly width?: number | string
211
+
212
+ /**
213
+ * Height of the element in lines (rows).
214
+ * You can also set it in percent, which will calculate the height based on the height of parent element.
215
+ */
216
+ readonly height?: number | string
217
+
218
+ /**
219
+ * Sets a minimum width of the element.
220
+ */
221
+ readonly minWidth?: number | string
222
+
223
+ /**
224
+ * Sets a minimum height of the element.
225
+ */
226
+ readonly minHeight?: number | string
227
+
228
+ /**
229
+ * Sets a maximum width of the element.
230
+ */
231
+ readonly maxWidth?: number | string
232
+
233
+ /**
234
+ * Sets a maximum height of the element.
235
+ */
236
+ readonly maxHeight?: number | string
237
+
238
+ /**
239
+ * Set this property to `none` to hide the element.
240
+ */
241
+ readonly display?: 'flex' | 'none'
242
+
243
+ /**
244
+ * Add a border with a specified style.
245
+ * If `borderStyle` is `undefined` (which it is by default), no border will be added.
246
+ */
247
+ readonly borderStyle?: BorderStyle
248
+
249
+ /**
250
+ * Determines whether top border is visible.
251
+ *
252
+ * @default true
253
+ */
254
+ readonly borderTop?: boolean
255
+
256
+ /**
257
+ * Determines whether bottom border is visible.
258
+ *
259
+ * @default true
260
+ */
261
+ readonly borderBottom?: boolean
262
+
263
+ /**
264
+ * Determines whether left border is visible.
265
+ *
266
+ * @default true
267
+ */
268
+ readonly borderLeft?: boolean
269
+
270
+ /**
271
+ * Determines whether right border is visible.
272
+ *
273
+ * @default true
274
+ */
275
+ readonly borderRight?: boolean
276
+
277
+ /**
278
+ * Change border color.
279
+ * Shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor` and `borderLeftColor`.
280
+ */
281
+ readonly borderColor?: Color
282
+
283
+ /**
284
+ * Change top border color.
285
+ * Accepts raw color values (rgb, hex, ansi).
286
+ */
287
+ readonly borderTopColor?: Color
288
+
289
+ /**
290
+ * Change bottom border color.
291
+ * Accepts raw color values (rgb, hex, ansi).
292
+ */
293
+ readonly borderBottomColor?: Color
294
+
295
+ /**
296
+ * Change left border color.
297
+ * Accepts raw color values (rgb, hex, ansi).
298
+ */
299
+ readonly borderLeftColor?: Color
300
+
301
+ /**
302
+ * Change right border color.
303
+ * Accepts raw color values (rgb, hex, ansi).
304
+ */
305
+ readonly borderRightColor?: Color
306
+
307
+ /**
308
+ * Dim the border color.
309
+ * Shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor` and `borderRightDimColor`.
310
+ *
311
+ * @default false
312
+ */
313
+ readonly borderDimColor?: boolean
314
+
315
+ /**
316
+ * Dim the top border color.
317
+ *
318
+ * @default false
319
+ */
320
+ readonly borderTopDimColor?: boolean
321
+
322
+ /**
323
+ * Dim the bottom border color.
324
+ *
325
+ * @default false
326
+ */
327
+ readonly borderBottomDimColor?: boolean
328
+
329
+ /**
330
+ * Dim the left border color.
331
+ *
332
+ * @default false
333
+ */
334
+ readonly borderLeftDimColor?: boolean
335
+
336
+ /**
337
+ * Dim the right border color.
338
+ *
339
+ * @default false
340
+ */
341
+ readonly borderRightDimColor?: boolean
342
+
343
+ /**
344
+ * Add text within the border. Only applies to top or bottom borders.
345
+ */
346
+ readonly borderText?: BorderTextOptions
347
+
348
+ /**
349
+ * Background color for the box. Fills the interior with background-colored
350
+ * spaces and is inherited by child text nodes as their default background.
351
+ */
352
+ readonly backgroundColor?: Color
353
+
354
+ /**
355
+ * Fill the box's interior (padding included) with spaces before
356
+ * rendering children, so nothing behind it shows through. Like
357
+ * `backgroundColor` but without emitting any SGR — the terminal's
358
+ * default background is used. Useful for absolute-positioned overlays
359
+ * where Box padding/gaps would otherwise be transparent.
360
+ */
361
+ readonly opaque?: boolean
362
+
363
+ /**
364
+ * Behavior for an element's overflow in both directions.
365
+ * 'scroll' constrains the container's size (children do not expand it)
366
+ * and enables scrollTop-based virtualized scrolling at render time.
367
+ *
368
+ * @default 'visible'
369
+ */
370
+ readonly overflow?: 'visible' | 'hidden' | 'scroll'
371
+
372
+ /**
373
+ * Behavior for an element's overflow in horizontal direction.
374
+ *
375
+ * @default 'visible'
376
+ */
377
+ readonly overflowX?: 'visible' | 'hidden' | 'scroll'
378
+
379
+ /**
380
+ * Behavior for an element's overflow in vertical direction.
381
+ *
382
+ * @default 'visible'
383
+ */
384
+ readonly overflowY?: 'visible' | 'hidden' | 'scroll'
385
+
386
+ /**
387
+ * Exclude this box's cells from text selection in fullscreen mode.
388
+ * Cells inside this region are skipped by both the selection highlight
389
+ * and the copied text — useful for fencing off gutters (line numbers,
390
+ * diff sigils) so click-drag over a diff yields clean copyable code.
391
+ * Only affects alt-screen text selection; no-op otherwise.
392
+ *
393
+ * `'from-left-edge'` extends the exclusion from column 0 to the box's
394
+ * right edge for every row it occupies — this covers any upstream
395
+ * indentation (tool message prefix, tree lines) so a multi-row drag
396
+ * doesn't pick up leading whitespace from middle rows.
397
+ */
398
+ readonly noSelect?: boolean | 'from-left-edge'
399
+ }
400
+
401
+ const applyPositionStyles = (node: LayoutNode, style: Styles): void => {
402
+ if ('position' in style) {
403
+ node.setPositionType(style.position === 'absolute' ? LayoutPositionType.Absolute : LayoutPositionType.Relative)
404
+ }
405
+
406
+ if ('top' in style) {
407
+ applyPositionEdge(node, 'top', style.top)
408
+ }
409
+
410
+ if ('bottom' in style) {
411
+ applyPositionEdge(node, 'bottom', style.bottom)
412
+ }
413
+
414
+ if ('left' in style) {
415
+ applyPositionEdge(node, 'left', style.left)
416
+ }
417
+
418
+ if ('right' in style) {
419
+ applyPositionEdge(node, 'right', style.right)
420
+ }
421
+ }
422
+
423
+ function applyPositionEdge(
424
+ node: LayoutNode,
425
+ edge: 'top' | 'bottom' | 'left' | 'right',
426
+ v: number | `${number}%` | undefined
427
+ ): void {
428
+ if (typeof v === 'string') {
429
+ node.setPositionPercent(edge, Number.parseInt(v, 10))
430
+ } else if (typeof v === 'number') {
431
+ node.setPosition(edge, v)
432
+ } else {
433
+ node.setPosition(edge, Number.NaN)
434
+ }
435
+ }
436
+
437
+ const applyOverflowStyles = (node: LayoutNode, style: Styles): void => {
438
+ // Yoga's Overflow controls whether children expand the container.
439
+ // 'hidden' and 'scroll' both prevent expansion; 'scroll' additionally
440
+ // signals that the renderer should apply scrollTop translation.
441
+ // overflowX/Y are render-time concerns; for layout we use the union.
442
+ const y = style.overflowY ?? style.overflow
443
+ const x = style.overflowX ?? style.overflow
444
+
445
+ if (y === 'scroll' || x === 'scroll') {
446
+ node.setOverflow(LayoutOverflow.Scroll)
447
+ } else if (y === 'hidden' || x === 'hidden') {
448
+ node.setOverflow(LayoutOverflow.Hidden)
449
+ } else if ('overflow' in style || 'overflowX' in style || 'overflowY' in style) {
450
+ node.setOverflow(LayoutOverflow.Visible)
451
+ }
452
+ }
453
+
454
+ const applyMarginStyles = (node: LayoutNode, style: Styles): void => {
455
+ if ('margin' in style) {
456
+ node.setMargin(LayoutEdge.All, style.margin ?? 0)
457
+ }
458
+
459
+ if ('marginX' in style) {
460
+ node.setMargin(LayoutEdge.Horizontal, style.marginX ?? 0)
461
+ }
462
+
463
+ if ('marginY' in style) {
464
+ node.setMargin(LayoutEdge.Vertical, style.marginY ?? 0)
465
+ }
466
+
467
+ if ('marginLeft' in style) {
468
+ node.setMargin(LayoutEdge.Start, style.marginLeft || 0)
469
+ }
470
+
471
+ if ('marginRight' in style) {
472
+ node.setMargin(LayoutEdge.End, style.marginRight || 0)
473
+ }
474
+
475
+ if ('marginTop' in style) {
476
+ node.setMargin(LayoutEdge.Top, style.marginTop || 0)
477
+ }
478
+
479
+ if ('marginBottom' in style) {
480
+ node.setMargin(LayoutEdge.Bottom, style.marginBottom || 0)
481
+ }
482
+ }
483
+
484
+ const applyPaddingStyles = (node: LayoutNode, style: Styles): void => {
485
+ if ('padding' in style) {
486
+ node.setPadding(LayoutEdge.All, style.padding ?? 0)
487
+ }
488
+
489
+ if ('paddingX' in style) {
490
+ node.setPadding(LayoutEdge.Horizontal, style.paddingX ?? 0)
491
+ }
492
+
493
+ if ('paddingY' in style) {
494
+ node.setPadding(LayoutEdge.Vertical, style.paddingY ?? 0)
495
+ }
496
+
497
+ if ('paddingLeft' in style) {
498
+ node.setPadding(LayoutEdge.Left, style.paddingLeft || 0)
499
+ }
500
+
501
+ if ('paddingRight' in style) {
502
+ node.setPadding(LayoutEdge.Right, style.paddingRight || 0)
503
+ }
504
+
505
+ if ('paddingTop' in style) {
506
+ node.setPadding(LayoutEdge.Top, style.paddingTop || 0)
507
+ }
508
+
509
+ if ('paddingBottom' in style) {
510
+ node.setPadding(LayoutEdge.Bottom, style.paddingBottom || 0)
511
+ }
512
+ }
513
+
514
+ const applyFlexStyles = (node: LayoutNode, style: Styles): void => {
515
+ if ('flexGrow' in style) {
516
+ node.setFlexGrow(style.flexGrow ?? 0)
517
+ }
518
+
519
+ if ('flexShrink' in style) {
520
+ node.setFlexShrink(typeof style.flexShrink === 'number' ? style.flexShrink : 1)
521
+ }
522
+
523
+ if ('flexWrap' in style) {
524
+ if (style.flexWrap === 'nowrap') {
525
+ node.setFlexWrap(LayoutWrap.NoWrap)
526
+ }
527
+
528
+ if (style.flexWrap === 'wrap') {
529
+ node.setFlexWrap(LayoutWrap.Wrap)
530
+ }
531
+
532
+ if (style.flexWrap === 'wrap-reverse') {
533
+ node.setFlexWrap(LayoutWrap.WrapReverse)
534
+ }
535
+ }
536
+
537
+ if ('flexDirection' in style) {
538
+ if (style.flexDirection === 'row') {
539
+ node.setFlexDirection(LayoutFlexDirection.Row)
540
+ }
541
+
542
+ if (style.flexDirection === 'row-reverse') {
543
+ node.setFlexDirection(LayoutFlexDirection.RowReverse)
544
+ }
545
+
546
+ if (style.flexDirection === 'column') {
547
+ node.setFlexDirection(LayoutFlexDirection.Column)
548
+ }
549
+
550
+ if (style.flexDirection === 'column-reverse') {
551
+ node.setFlexDirection(LayoutFlexDirection.ColumnReverse)
552
+ }
553
+ }
554
+
555
+ if ('flexBasis' in style) {
556
+ if (typeof style.flexBasis === 'number') {
557
+ node.setFlexBasis(style.flexBasis)
558
+ } else if (typeof style.flexBasis === 'string') {
559
+ node.setFlexBasisPercent(Number.parseInt(style.flexBasis, 10))
560
+ } else {
561
+ node.setFlexBasis(Number.NaN)
562
+ }
563
+ }
564
+
565
+ if ('alignItems' in style) {
566
+ if (style.alignItems === 'stretch' || !style.alignItems) {
567
+ node.setAlignItems(LayoutAlign.Stretch)
568
+ }
569
+
570
+ if (style.alignItems === 'flex-start') {
571
+ node.setAlignItems(LayoutAlign.FlexStart)
572
+ }
573
+
574
+ if (style.alignItems === 'center') {
575
+ node.setAlignItems(LayoutAlign.Center)
576
+ }
577
+
578
+ if (style.alignItems === 'flex-end') {
579
+ node.setAlignItems(LayoutAlign.FlexEnd)
580
+ }
581
+ }
582
+
583
+ if ('alignSelf' in style) {
584
+ if (style.alignSelf === 'auto' || !style.alignSelf) {
585
+ node.setAlignSelf(LayoutAlign.Auto)
586
+ }
587
+
588
+ if (style.alignSelf === 'flex-start') {
589
+ node.setAlignSelf(LayoutAlign.FlexStart)
590
+ }
591
+
592
+ if (style.alignSelf === 'center') {
593
+ node.setAlignSelf(LayoutAlign.Center)
594
+ }
595
+
596
+ if (style.alignSelf === 'flex-end') {
597
+ node.setAlignSelf(LayoutAlign.FlexEnd)
598
+ }
599
+ }
600
+
601
+ if ('justifyContent' in style) {
602
+ if (style.justifyContent === 'flex-start' || !style.justifyContent) {
603
+ node.setJustifyContent(LayoutJustify.FlexStart)
604
+ }
605
+
606
+ if (style.justifyContent === 'center') {
607
+ node.setJustifyContent(LayoutJustify.Center)
608
+ }
609
+
610
+ if (style.justifyContent === 'flex-end') {
611
+ node.setJustifyContent(LayoutJustify.FlexEnd)
612
+ }
613
+
614
+ if (style.justifyContent === 'space-between') {
615
+ node.setJustifyContent(LayoutJustify.SpaceBetween)
616
+ }
617
+
618
+ if (style.justifyContent === 'space-around') {
619
+ node.setJustifyContent(LayoutJustify.SpaceAround)
620
+ }
621
+
622
+ if (style.justifyContent === 'space-evenly') {
623
+ node.setJustifyContent(LayoutJustify.SpaceEvenly)
624
+ }
625
+ }
626
+ }
627
+
628
+ const applyDimensionStyles = (node: LayoutNode, style: Styles): void => {
629
+ if ('width' in style) {
630
+ if (typeof style.width === 'number') {
631
+ node.setWidth(style.width)
632
+ } else if (typeof style.width === 'string') {
633
+ node.setWidthPercent(Number.parseInt(style.width, 10))
634
+ } else {
635
+ node.setWidthAuto()
636
+ }
637
+ }
638
+
639
+ if ('height' in style) {
640
+ if (typeof style.height === 'number') {
641
+ node.setHeight(style.height)
642
+ } else if (typeof style.height === 'string') {
643
+ node.setHeightPercent(Number.parseInt(style.height, 10))
644
+ } else {
645
+ node.setHeightAuto()
646
+ }
647
+ }
648
+
649
+ if ('minWidth' in style) {
650
+ if (typeof style.minWidth === 'string') {
651
+ node.setMinWidthPercent(Number.parseInt(style.minWidth, 10))
652
+ } else {
653
+ node.setMinWidth(style.minWidth ?? 0)
654
+ }
655
+ }
656
+
657
+ if ('minHeight' in style) {
658
+ if (typeof style.minHeight === 'string') {
659
+ node.setMinHeightPercent(Number.parseInt(style.minHeight, 10))
660
+ } else {
661
+ node.setMinHeight(style.minHeight ?? 0)
662
+ }
663
+ }
664
+
665
+ if ('maxWidth' in style) {
666
+ if (typeof style.maxWidth === 'string') {
667
+ node.setMaxWidthPercent(Number.parseInt(style.maxWidth, 10))
668
+ } else {
669
+ node.setMaxWidth(style.maxWidth ?? 0)
670
+ }
671
+ }
672
+
673
+ if ('maxHeight' in style) {
674
+ if (typeof style.maxHeight === 'string') {
675
+ node.setMaxHeightPercent(Number.parseInt(style.maxHeight, 10))
676
+ } else {
677
+ node.setMaxHeight(style.maxHeight ?? 0)
678
+ }
679
+ }
680
+ }
681
+
682
+ const applyDisplayStyles = (node: LayoutNode, style: Styles): void => {
683
+ if ('display' in style) {
684
+ node.setDisplay(style.display === 'flex' ? LayoutDisplay.Flex : LayoutDisplay.None)
685
+ }
686
+ }
687
+
688
+ const applyBorderStyles = (node: LayoutNode, style: Styles, resolvedStyle?: Styles): void => {
689
+ // resolvedStyle is the full current style (already set on the DOM node).
690
+ // style may be a diff with only changed properties. For border side props,
691
+ // we need the resolved value because `borderStyle` in a diff may not include
692
+ // unchanged border side values (e.g. borderTop stays false but isn't in the diff).
693
+ const resolved = resolvedStyle ?? style
694
+
695
+ if ('borderStyle' in style) {
696
+ const borderWidth = style.borderStyle ? 1 : 0
697
+
698
+ node.setBorder(LayoutEdge.Top, resolved.borderTop !== false ? borderWidth : 0)
699
+ node.setBorder(LayoutEdge.Bottom, resolved.borderBottom !== false ? borderWidth : 0)
700
+ node.setBorder(LayoutEdge.Left, resolved.borderLeft !== false ? borderWidth : 0)
701
+ node.setBorder(LayoutEdge.Right, resolved.borderRight !== false ? borderWidth : 0)
702
+ } else {
703
+ // Handle individual border property changes (when only borderX changes without borderStyle).
704
+ // Skip undefined values — they mean the prop was removed or never set,
705
+ // not that a border should be enabled.
706
+ if ('borderTop' in style && style.borderTop !== undefined) {
707
+ node.setBorder(LayoutEdge.Top, style.borderTop === false ? 0 : 1)
708
+ }
709
+
710
+ if ('borderBottom' in style && style.borderBottom !== undefined) {
711
+ node.setBorder(LayoutEdge.Bottom, style.borderBottom === false ? 0 : 1)
712
+ }
713
+
714
+ if ('borderLeft' in style && style.borderLeft !== undefined) {
715
+ node.setBorder(LayoutEdge.Left, style.borderLeft === false ? 0 : 1)
716
+ }
717
+
718
+ if ('borderRight' in style && style.borderRight !== undefined) {
719
+ node.setBorder(LayoutEdge.Right, style.borderRight === false ? 0 : 1)
720
+ }
721
+ }
722
+ }
723
+
724
+ const applyGapStyles = (node: LayoutNode, style: Styles): void => {
725
+ if ('gap' in style) {
726
+ node.setGap(LayoutGutter.All, style.gap ?? 0)
727
+ }
728
+
729
+ if ('columnGap' in style) {
730
+ node.setGap(LayoutGutter.Column, style.columnGap ?? 0)
731
+ }
732
+
733
+ if ('rowGap' in style) {
734
+ node.setGap(LayoutGutter.Row, style.rowGap ?? 0)
735
+ }
736
+ }
737
+
738
+ const styles = (node: LayoutNode, style: Styles = {}, resolvedStyle?: Styles): void => {
739
+ applyPositionStyles(node, style)
740
+ applyOverflowStyles(node, style)
741
+ applyMarginStyles(node, style)
742
+ applyPaddingStyles(node, style)
743
+ applyFlexStyles(node, style)
744
+ applyDimensionStyles(node, style)
745
+ applyDisplayStyles(node, style)
746
+ applyBorderStyles(node, style, resolvedStyle)
747
+ applyGapStyles(node, style)
748
+ }
749
+
750
+ export default styles