@fairyhunter13/opentui-core 0.1.112 → 0.1.114

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 (591) hide show
  1. package/dev/keypress-debug-renderer.ts +148 -0
  2. package/dev/keypress-debug.ts +43 -0
  3. package/dev/print-env-vars.ts +32 -0
  4. package/dev/test-tmux-graphics-334.sh +68 -0
  5. package/dev/thai-debug-test.ts +68 -0
  6. package/docs/development.md +144 -0
  7. package/package.json +63 -51
  8. package/scripts/build.ts +400 -0
  9. package/scripts/publish.ts +60 -0
  10. package/src/3d/SpriteResourceManager.ts +286 -0
  11. package/src/3d/SpriteUtils.ts +70 -0
  12. package/src/3d/TextureUtils.ts +196 -0
  13. package/src/3d/ThreeRenderable.ts +197 -0
  14. package/src/3d/WGPURenderer.ts +294 -0
  15. package/src/3d/animation/ExplodingSpriteEffect.ts +513 -0
  16. package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +429 -0
  17. package/src/3d/animation/SpriteAnimator.ts +633 -0
  18. package/src/3d/animation/SpriteParticleGenerator.ts +435 -0
  19. package/src/3d/canvas.ts +464 -0
  20. package/src/3d/index.ts +12 -0
  21. package/src/3d/physics/PlanckPhysicsAdapter.ts +72 -0
  22. package/src/3d/physics/RapierPhysicsAdapter.ts +66 -0
  23. package/src/3d/physics/physics-interface.ts +31 -0
  24. package/src/3d/shaders/supersampling.wgsl +201 -0
  25. package/src/3d.ts +3 -0
  26. package/src/NativeSpanFeed.ts +300 -0
  27. package/src/Renderable.ts +1704 -0
  28. package/src/__snapshots__/buffer.test.ts.snap +28 -0
  29. package/src/animation/Timeline.test.ts +2709 -0
  30. package/src/animation/Timeline.ts +598 -0
  31. package/src/ansi.ts +18 -0
  32. package/src/benchmark/attenuation-benchmark.ts +81 -0
  33. package/src/benchmark/colormatrix-benchmark.ts +128 -0
  34. package/src/benchmark/gain-benchmark.ts +80 -0
  35. package/src/benchmark/latest-all-bench-run.json +707 -0
  36. package/src/benchmark/latest-async-bench-run.json +336 -0
  37. package/src/benchmark/latest-default-bench-run.json +657 -0
  38. package/src/benchmark/latest-large-bench-run.json +707 -0
  39. package/src/benchmark/latest-quick-bench-run.json +207 -0
  40. package/src/benchmark/markdown-benchmark.ts +1796 -0
  41. package/src/benchmark/native-span-feed-async-benchmark.ts +355 -0
  42. package/src/benchmark/native-span-feed-benchmark.md +56 -0
  43. package/src/benchmark/native-span-feed-benchmark.ts +596 -0
  44. package/src/benchmark/native-span-feed-compare.ts +280 -0
  45. package/src/benchmark/renderer-benchmark.ts +754 -0
  46. package/src/benchmark/text-table-benchmark.ts +948 -0
  47. package/src/buffer.test.ts +291 -0
  48. package/src/buffer.ts +554 -0
  49. package/src/console.test.ts +612 -0
  50. package/src/console.ts +1254 -0
  51. package/src/edit-buffer.test.ts +1769 -0
  52. package/src/edit-buffer.ts +411 -0
  53. package/src/editor-view.test.ts +1032 -0
  54. package/src/editor-view.ts +284 -0
  55. package/src/examples/ascii-font-selection-demo.ts +245 -0
  56. package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
  57. package/src/examples/assets/concrete.png +0 -0
  58. package/src/examples/assets/crate.png +0 -0
  59. package/src/examples/assets/crate_emissive.png +0 -0
  60. package/src/examples/assets/forrest_background.png +0 -0
  61. package/src/examples/assets/hast-example.json +1018 -0
  62. package/src/examples/assets/heart.png +0 -0
  63. package/src/examples/assets/main_char_heavy_attack.png +0 -0
  64. package/src/examples/assets/main_char_idle.png +0 -0
  65. package/src/examples/assets/main_char_jump_end.png +0 -0
  66. package/src/examples/assets/main_char_jump_landing.png +0 -0
  67. package/src/examples/assets/main_char_jump_start.png +0 -0
  68. package/src/examples/assets/main_char_run_loop.png +0 -0
  69. package/src/examples/assets/roughness_map.jpg +0 -0
  70. package/src/examples/build.ts +115 -0
  71. package/src/examples/code-demo.ts +924 -0
  72. package/src/examples/console-demo.ts +358 -0
  73. package/src/examples/core-plugin-slots-demo.ts +759 -0
  74. package/src/examples/diff-demo.ts +701 -0
  75. package/src/examples/draggable-three-demo.ts +259 -0
  76. package/src/examples/editor-demo.ts +322 -0
  77. package/src/examples/extmarks-demo.ts +196 -0
  78. package/src/examples/focus-restore-demo.ts +310 -0
  79. package/src/examples/fonts.ts +245 -0
  80. package/src/examples/fractal-shader-demo.ts +268 -0
  81. package/src/examples/framebuffer-demo.ts +674 -0
  82. package/src/examples/full-unicode-demo.ts +241 -0
  83. package/src/examples/golden-star-demo.ts +933 -0
  84. package/src/examples/grayscale-buffer-demo.ts +249 -0
  85. package/src/examples/hast-syntax-highlighting-demo.ts +129 -0
  86. package/src/examples/index.ts +926 -0
  87. package/src/examples/input-demo.ts +377 -0
  88. package/src/examples/input-select-layout-demo.ts +425 -0
  89. package/src/examples/install.sh +143 -0
  90. package/src/examples/keypress-debug-demo.ts +452 -0
  91. package/src/examples/lib/HexList.ts +122 -0
  92. package/src/examples/lib/PaletteGrid.ts +125 -0
  93. package/src/examples/lib/standalone-keys.ts +25 -0
  94. package/src/examples/lib/tab-controller.ts +243 -0
  95. package/src/examples/lights-phong-demo.ts +290 -0
  96. package/src/examples/link-demo.ts +220 -0
  97. package/src/examples/live-state-demo.ts +480 -0
  98. package/src/examples/markdown-demo.ts +725 -0
  99. package/src/examples/mouse-interaction-demo.ts +428 -0
  100. package/src/examples/nested-zindex-demo.ts +357 -0
  101. package/src/examples/opacity-example.ts +235 -0
  102. package/src/examples/opentui-demo.ts +1057 -0
  103. package/src/examples/physx-planck-2d-demo.ts +623 -0
  104. package/src/examples/physx-rapier-2d-demo.ts +655 -0
  105. package/src/examples/relative-positioning-demo.ts +323 -0
  106. package/src/examples/scroll-example.ts +214 -0
  107. package/src/examples/scrollbox-mouse-test.ts +112 -0
  108. package/src/examples/scrollbox-overlay-hit-test.ts +206 -0
  109. package/src/examples/select-demo.ts +237 -0
  110. package/src/examples/shader-cube-demo.ts +1015 -0
  111. package/src/examples/simple-layout-example.ts +591 -0
  112. package/src/examples/slider-demo.ts +617 -0
  113. package/src/examples/split-mode-demo.ts +453 -0
  114. package/src/examples/sprite-animation-demo.ts +443 -0
  115. package/src/examples/sprite-particle-generator-demo.ts +486 -0
  116. package/src/examples/static-sprite-demo.ts +193 -0
  117. package/src/examples/sticky-scroll-example.ts +308 -0
  118. package/src/examples/styled-text-demo.ts +282 -0
  119. package/src/examples/tab-select-demo.ts +219 -0
  120. package/src/examples/terminal-title.ts +29 -0
  121. package/src/examples/terminal.ts +305 -0
  122. package/src/examples/text-node-demo.ts +416 -0
  123. package/src/examples/text-selection-demo.ts +377 -0
  124. package/src/examples/text-table-demo.ts +503 -0
  125. package/src/examples/text-truncation-demo.ts +481 -0
  126. package/src/examples/text-wrap.ts +757 -0
  127. package/src/examples/texture-loading-demo.ts +259 -0
  128. package/src/examples/timeline-example.ts +670 -0
  129. package/src/examples/transparency-demo.ts +400 -0
  130. package/src/examples/vnode-composition-demo.ts +404 -0
  131. package/src/examples/wide-grapheme-overlay-demo.ts +280 -0
  132. package/src/index.ts +24 -0
  133. package/src/lib/KeyHandler.integration.test.ts +292 -0
  134. package/src/lib/KeyHandler.stopPropagation.test.ts +289 -0
  135. package/src/lib/KeyHandler.test.ts +662 -0
  136. package/src/lib/KeyHandler.ts +222 -0
  137. package/src/lib/RGBA.test.ts +984 -0
  138. package/src/lib/RGBA.ts +204 -0
  139. package/src/lib/ascii.font.ts +330 -0
  140. package/src/lib/border.test.ts +83 -0
  141. package/src/lib/border.ts +170 -0
  142. package/src/lib/bunfs.test.ts +27 -0
  143. package/src/lib/bunfs.ts +18 -0
  144. package/src/lib/clipboard.test.ts +41 -0
  145. package/src/lib/clipboard.ts +47 -0
  146. package/src/lib/clock.ts +35 -0
  147. package/src/lib/data-paths.test.ts +133 -0
  148. package/src/lib/data-paths.ts +109 -0
  149. package/src/lib/debounce.ts +106 -0
  150. package/src/lib/detect-links.test.ts +98 -0
  151. package/src/lib/detect-links.ts +56 -0
  152. package/src/lib/env.test.ts +228 -0
  153. package/src/lib/env.ts +209 -0
  154. package/src/lib/extmarks-history.ts +51 -0
  155. package/src/lib/extmarks-multiwidth.test.ts +322 -0
  156. package/src/lib/extmarks.test.ts +3457 -0
  157. package/src/lib/extmarks.ts +843 -0
  158. package/src/lib/fonts/block.json +405 -0
  159. package/src/lib/fonts/grid.json +265 -0
  160. package/src/lib/fonts/huge.json +741 -0
  161. package/src/lib/fonts/pallet.json +314 -0
  162. package/src/lib/fonts/shade.json +591 -0
  163. package/src/lib/fonts/slick.json +321 -0
  164. package/src/lib/fonts/tiny.json +69 -0
  165. package/src/lib/hast-styled-text.ts +59 -0
  166. package/src/lib/index.ts +21 -0
  167. package/src/lib/keymapping.test.ts +317 -0
  168. package/src/lib/keymapping.ts +115 -0
  169. package/src/lib/objects-in-viewport.test.ts +787 -0
  170. package/src/lib/objects-in-viewport.ts +153 -0
  171. package/src/lib/output.capture.ts +58 -0
  172. package/src/lib/parse.keypress-kitty.protocol.test.ts +340 -0
  173. package/src/lib/parse.keypress-kitty.test.ts +663 -0
  174. package/src/lib/parse.keypress-kitty.ts +439 -0
  175. package/src/lib/parse.keypress.test.ts +1849 -0
  176. package/src/lib/parse.keypress.ts +397 -0
  177. package/src/lib/parse.mouse.test.ts +552 -0
  178. package/src/lib/parse.mouse.ts +232 -0
  179. package/src/lib/paste.ts +16 -0
  180. package/src/lib/queue.ts +65 -0
  181. package/src/lib/renderable.validations.test.ts +87 -0
  182. package/src/lib/renderable.validations.ts +83 -0
  183. package/src/lib/scroll-acceleration.ts +98 -0
  184. package/src/lib/selection.ts +240 -0
  185. package/src/lib/singleton.ts +28 -0
  186. package/src/lib/stdin-parser.test.ts +2290 -0
  187. package/src/lib/stdin-parser.ts +1810 -0
  188. package/src/lib/styled-text.ts +178 -0
  189. package/src/lib/terminal-capability-detection.test.ts +202 -0
  190. package/src/lib/terminal-capability-detection.ts +79 -0
  191. package/src/lib/terminal-palette.test.ts +878 -0
  192. package/src/lib/terminal-palette.ts +383 -0
  193. package/src/lib/tree-sitter/assets/README.md +118 -0
  194. package/src/lib/tree-sitter/assets/update.ts +334 -0
  195. package/src/lib/tree-sitter/assets.d.ts +9 -0
  196. package/src/lib/tree-sitter/cache.test.ts +273 -0
  197. package/src/lib/tree-sitter/client.test.ts +1165 -0
  198. package/src/lib/tree-sitter/client.ts +607 -0
  199. package/src/lib/tree-sitter/default-parsers.ts +86 -0
  200. package/src/lib/tree-sitter/download-utils.ts +148 -0
  201. package/src/lib/tree-sitter/index.ts +28 -0
  202. package/src/lib/tree-sitter/parser.worker.ts +1042 -0
  203. package/src/lib/tree-sitter/parsers-config.ts +81 -0
  204. package/src/lib/tree-sitter/resolve-ft.test.ts +55 -0
  205. package/src/lib/tree-sitter/resolve-ft.ts +189 -0
  206. package/src/lib/tree-sitter/types.ts +82 -0
  207. package/src/lib/tree-sitter-styled-text.test.ts +1253 -0
  208. package/src/lib/tree-sitter-styled-text.ts +306 -0
  209. package/src/lib/validate-dir-name.ts +55 -0
  210. package/src/lib/yoga.options.test.ts +628 -0
  211. package/src/lib/yoga.options.ts +346 -0
  212. package/src/plugins/core-slot.ts +579 -0
  213. package/src/plugins/registry.ts +402 -0
  214. package/src/plugins/types.ts +46 -0
  215. package/src/post/effects.ts +930 -0
  216. package/src/post/filters.ts +489 -0
  217. package/src/post/matrices.ts +288 -0
  218. package/src/renderables/ASCIIFont.ts +219 -0
  219. package/src/renderables/Box.test.ts +205 -0
  220. package/src/renderables/Box.ts +326 -0
  221. package/src/renderables/Code.test.ts +2062 -0
  222. package/src/renderables/Code.ts +357 -0
  223. package/src/renderables/Diff.regression.test.ts +226 -0
  224. package/src/renderables/Diff.test.ts +3101 -0
  225. package/src/renderables/Diff.ts +1211 -0
  226. package/src/renderables/EditBufferRenderable.test.ts +288 -0
  227. package/src/renderables/EditBufferRenderable.ts +1166 -0
  228. package/src/renderables/FrameBuffer.ts +47 -0
  229. package/src/renderables/Input.test.ts +1228 -0
  230. package/src/renderables/Input.ts +247 -0
  231. package/src/renderables/LineNumberRenderable.ts +724 -0
  232. package/src/renderables/Markdown.ts +1393 -0
  233. package/src/renderables/ScrollBar.ts +422 -0
  234. package/src/renderables/ScrollBox.ts +883 -0
  235. package/src/renderables/Select.test.ts +1033 -0
  236. package/src/renderables/Select.ts +524 -0
  237. package/src/renderables/Slider.test.ts +456 -0
  238. package/src/renderables/Slider.ts +342 -0
  239. package/src/renderables/TabSelect.test.ts +197 -0
  240. package/src/renderables/TabSelect.ts +455 -0
  241. package/src/renderables/Text.selection-buffer.test.ts +123 -0
  242. package/src/renderables/Text.test.ts +2660 -0
  243. package/src/renderables/Text.ts +147 -0
  244. package/src/renderables/TextBufferRenderable.ts +518 -0
  245. package/src/renderables/TextNode.test.ts +1058 -0
  246. package/src/renderables/TextNode.ts +325 -0
  247. package/src/renderables/TextTable.test.ts +1421 -0
  248. package/src/renderables/TextTable.ts +1344 -0
  249. package/src/renderables/Textarea.ts +430 -0
  250. package/src/renderables/TimeToFirstDraw.ts +89 -0
  251. package/src/renderables/__snapshots__/Code.test.ts.snap +13 -0
  252. package/src/renderables/__snapshots__/Diff.test.ts.snap +785 -0
  253. package/src/renderables/__snapshots__/Text.test.ts.snap +421 -0
  254. package/src/renderables/__snapshots__/TextTable.test.ts.snap +215 -0
  255. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +144 -0
  256. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +816 -0
  257. package/src/renderables/__tests__/LineNumberRenderable.test.ts +1865 -0
  258. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +85 -0
  259. package/src/renderables/__tests__/Markdown.code-colors.test.ts +242 -0
  260. package/src/renderables/__tests__/Markdown.test.ts +2518 -0
  261. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +87 -0
  262. package/src/renderables/__tests__/Textarea.buffer.test.ts +682 -0
  263. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +675 -0
  264. package/src/renderables/__tests__/Textarea.editing.test.ts +2041 -0
  265. package/src/renderables/__tests__/Textarea.error-handling.test.ts +35 -0
  266. package/src/renderables/__tests__/Textarea.events.test.ts +738 -0
  267. package/src/renderables/__tests__/Textarea.highlights.test.ts +590 -0
  268. package/src/renderables/__tests__/Textarea.keybinding.test.ts +3149 -0
  269. package/src/renderables/__tests__/Textarea.paste.test.ts +357 -0
  270. package/src/renderables/__tests__/Textarea.rendering.test.ts +1866 -0
  271. package/src/renderables/__tests__/Textarea.scroll.test.ts +733 -0
  272. package/src/renderables/__tests__/Textarea.selection.test.ts +1590 -0
  273. package/src/renderables/__tests__/Textarea.stress.test.ts +670 -0
  274. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +383 -0
  275. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +310 -0
  276. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +221 -0
  277. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +89 -0
  278. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +457 -0
  279. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +158 -0
  280. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +387 -0
  281. package/src/renderables/__tests__/markdown-parser.test.ts +217 -0
  282. package/src/renderables/__tests__/renderable-test-utils.ts +60 -0
  283. package/src/renderables/composition/README.md +8 -0
  284. package/src/renderables/composition/VRenderable.ts +32 -0
  285. package/src/renderables/composition/constructs.ts +127 -0
  286. package/src/renderables/composition/vnode.ts +289 -0
  287. package/src/renderables/index.ts +23 -0
  288. package/src/renderables/markdown-parser.ts +66 -0
  289. package/src/renderer.ts +2681 -0
  290. package/src/runtime-plugin-support.ts +39 -0
  291. package/src/runtime-plugin.ts +615 -0
  292. package/src/syntax-style.test.ts +841 -0
  293. package/src/syntax-style.ts +257 -0
  294. package/src/testing/README.md +210 -0
  295. package/src/testing/capture-spans.test.ts +194 -0
  296. package/src/testing/integration.test.ts +276 -0
  297. package/src/testing/manual-clock.ts +117 -0
  298. package/src/testing/mock-keys.test.ts +1378 -0
  299. package/src/testing/mock-keys.ts +457 -0
  300. package/src/testing/mock-mouse.test.ts +218 -0
  301. package/src/testing/mock-mouse.ts +247 -0
  302. package/src/testing/mock-tree-sitter-client.ts +73 -0
  303. package/src/testing/spy.ts +13 -0
  304. package/src/testing/test-recorder.test.ts +415 -0
  305. package/src/testing/test-recorder.ts +145 -0
  306. package/src/testing/test-renderer.ts +132 -0
  307. package/src/testing.ts +7 -0
  308. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +481 -0
  309. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +19 -0
  310. package/src/tests/__snapshots__/scrollbox.test.ts.snap +29 -0
  311. package/src/tests/absolute-positioning.snapshot.test.ts +638 -0
  312. package/src/tests/allocator-stats.test.ts +38 -0
  313. package/src/tests/destroy-during-render.test.ts +200 -0
  314. package/src/tests/destroy-on-exit.fixture.ts +36 -0
  315. package/src/tests/destroy-on-exit.test.ts +41 -0
  316. package/src/tests/hover-cursor.test.ts +98 -0
  317. package/src/tests/native-span-feed-async.test.ts +173 -0
  318. package/src/tests/native-span-feed-close.test.ts +120 -0
  319. package/src/tests/native-span-feed-coverage.test.ts +227 -0
  320. package/src/tests/native-span-feed-edge-cases.test.ts +352 -0
  321. package/src/tests/native-span-feed-use-after-free.test.ts +45 -0
  322. package/src/tests/opacity.test.ts +123 -0
  323. package/src/tests/renderable.snapshot.test.ts +524 -0
  324. package/src/tests/renderable.test.ts +1281 -0
  325. package/src/tests/renderer.clock.test.ts +158 -0
  326. package/src/tests/renderer.console-startup.test.ts +185 -0
  327. package/src/tests/renderer.control.test.ts +425 -0
  328. package/src/tests/renderer.core-slot-binding.test.ts +952 -0
  329. package/src/tests/renderer.cursor.test.ts +26 -0
  330. package/src/tests/renderer.destroy-during-render.test.ts +147 -0
  331. package/src/tests/renderer.focus-restore.test.ts +257 -0
  332. package/src/tests/renderer.focus.test.ts +294 -0
  333. package/src/tests/renderer.idle.test.ts +219 -0
  334. package/src/tests/renderer.input.test.ts +2237 -0
  335. package/src/tests/renderer.kitty-flags.test.ts +195 -0
  336. package/src/tests/renderer.mouse.test.ts +1274 -0
  337. package/src/tests/renderer.palette.test.ts +629 -0
  338. package/src/tests/renderer.selection.test.ts +49 -0
  339. package/src/tests/renderer.slot-registry.test.ts +684 -0
  340. package/src/tests/renderer.useMouse.test.ts +47 -0
  341. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +76 -0
  342. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +43 -0
  343. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +67 -0
  344. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +72 -0
  345. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +44 -0
  346. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +85 -0
  347. package/src/tests/runtime-plugin-path-alias.fixture.ts +43 -0
  348. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +65 -0
  349. package/src/tests/runtime-plugin-support.fixture.ts +11 -0
  350. package/src/tests/runtime-plugin-support.test.ts +19 -0
  351. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +30 -0
  352. package/src/tests/runtime-plugin.fixture.ts +40 -0
  353. package/src/tests/runtime-plugin.test.ts +354 -0
  354. package/src/tests/scrollbox-culling-bug.test.ts +114 -0
  355. package/src/tests/scrollbox-hitgrid-resize.test.ts +136 -0
  356. package/src/tests/scrollbox-hitgrid.test.ts +909 -0
  357. package/src/tests/scrollbox.test.ts +1530 -0
  358. package/src/tests/wrap-resize-perf.test.ts +276 -0
  359. package/src/tests/yoga-setters.test.ts +921 -0
  360. package/src/text-buffer-view.test.ts +705 -0
  361. package/src/text-buffer-view.ts +189 -0
  362. package/src/text-buffer.test.ts +347 -0
  363. package/src/text-buffer.ts +250 -0
  364. package/src/types.ts +161 -0
  365. package/src/utils.ts +88 -0
  366. package/src/zig/ansi.zig +268 -0
  367. package/src/zig/bench/README.md +50 -0
  368. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +887 -0
  369. package/src/zig/bench/edit-buffer_bench.zig +476 -0
  370. package/src/zig/bench/native-span-feed_bench.zig +100 -0
  371. package/src/zig/bench/rope-markers_bench.zig +713 -0
  372. package/src/zig/bench/rope_bench.zig +514 -0
  373. package/src/zig/bench/styled-text_bench.zig +470 -0
  374. package/src/zig/bench/text-buffer-coords_bench.zig +362 -0
  375. package/src/zig/bench/text-buffer-view_bench.zig +459 -0
  376. package/src/zig/bench/text-chunk-graphemes_bench.zig +273 -0
  377. package/src/zig/bench/utf8_bench.zig +799 -0
  378. package/src/zig/bench-utils.zig +431 -0
  379. package/src/zig/bench.zig +217 -0
  380. package/src/zig/buffer-methods.zig +211 -0
  381. package/src/zig/buffer.zig +2281 -0
  382. package/src/zig/build.zig +289 -0
  383. package/src/zig/build.zig.zon +16 -0
  384. package/src/zig/edit-buffer.zig +825 -0
  385. package/src/zig/editor-view.zig +802 -0
  386. package/src/zig/event-bus.zig +13 -0
  387. package/src/zig/event-emitter.zig +65 -0
  388. package/src/zig/file-logger.zig +92 -0
  389. package/src/zig/grapheme.zig +599 -0
  390. package/src/zig/lib.zig +1854 -0
  391. package/src/zig/link.zig +333 -0
  392. package/src/zig/logger.zig +43 -0
  393. package/src/zig/mem-registry.zig +125 -0
  394. package/src/zig/native-span-feed-bench-lib.zig +7 -0
  395. package/src/zig/native-span-feed.zig +708 -0
  396. package/src/zig/renderer.zig +1393 -0
  397. package/src/zig/rope.zig +1220 -0
  398. package/src/zig/syntax-style.zig +161 -0
  399. package/src/zig/terminal.zig +987 -0
  400. package/src/zig/test.zig +72 -0
  401. package/src/zig/tests/README.md +18 -0
  402. package/src/zig/tests/buffer-methods_test.zig +1109 -0
  403. package/src/zig/tests/buffer_test.zig +2557 -0
  404. package/src/zig/tests/edit-buffer-history_test.zig +271 -0
  405. package/src/zig/tests/edit-buffer_test.zig +1689 -0
  406. package/src/zig/tests/editor-view_test.zig +3299 -0
  407. package/src/zig/tests/event-emitter_test.zig +249 -0
  408. package/src/zig/tests/grapheme_test.zig +1304 -0
  409. package/src/zig/tests/link_test.zig +190 -0
  410. package/src/zig/tests/mem-registry_test.zig +473 -0
  411. package/src/zig/tests/memory_leak_regression_test.zig +159 -0
  412. package/src/zig/tests/native-span-feed_test.zig +1264 -0
  413. package/src/zig/tests/renderer_test.zig +1017 -0
  414. package/src/zig/tests/rope-nested_test.zig +712 -0
  415. package/src/zig/tests/rope_fuzz_test.zig +238 -0
  416. package/src/zig/tests/rope_test.zig +2362 -0
  417. package/src/zig/tests/segment-merge.test.zig +148 -0
  418. package/src/zig/tests/syntax-style_test.zig +557 -0
  419. package/src/zig/tests/terminal_test.zig +754 -0
  420. package/src/zig/tests/text-buffer-drawing_test.zig +3237 -0
  421. package/src/zig/tests/text-buffer-highlights_test.zig +666 -0
  422. package/src/zig/tests/text-buffer-iterators_test.zig +776 -0
  423. package/src/zig/tests/text-buffer-segment_test.zig +320 -0
  424. package/src/zig/tests/text-buffer-selection_test.zig +1035 -0
  425. package/src/zig/tests/text-buffer-selection_viewport_test.zig +358 -0
  426. package/src/zig/tests/text-buffer-view_test.zig +3649 -0
  427. package/src/zig/tests/text-buffer_test.zig +2191 -0
  428. package/src/zig/tests/unicode-width-map.zon +3909 -0
  429. package/src/zig/tests/utf8_no_zwj_test.zig +260 -0
  430. package/src/zig/tests/utf8_test.zig +4057 -0
  431. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +267 -0
  432. package/src/zig/tests/utf8_wcwidth_test.zig +357 -0
  433. package/src/zig/tests/word-wrap-editing_test.zig +498 -0
  434. package/src/zig/tests/wrap-cache-perf_test.zig +113 -0
  435. package/src/zig/text-buffer-iterators.zig +499 -0
  436. package/src/zig/text-buffer-segment.zig +404 -0
  437. package/src/zig/text-buffer-view.zig +1371 -0
  438. package/src/zig/text-buffer.zig +1180 -0
  439. package/src/zig/utf8.zig +1948 -0
  440. package/src/zig/utils.zig +9 -0
  441. package/src/zig-structs.ts +261 -0
  442. package/src/zig.ts +3884 -0
  443. package/tsconfig.build.json +24 -0
  444. package/tsconfig.json +27 -0
  445. package/3d/SpriteResourceManager.d.ts +0 -74
  446. package/3d/SpriteUtils.d.ts +0 -13
  447. package/3d/TextureUtils.d.ts +0 -24
  448. package/3d/ThreeRenderable.d.ts +0 -40
  449. package/3d/WGPURenderer.d.ts +0 -61
  450. package/3d/animation/ExplodingSpriteEffect.d.ts +0 -71
  451. package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +0 -76
  452. package/3d/animation/SpriteAnimator.d.ts +0 -124
  453. package/3d/animation/SpriteParticleGenerator.d.ts +0 -62
  454. package/3d/canvas.d.ts +0 -44
  455. package/3d/index.d.ts +0 -12
  456. package/3d/physics/PlanckPhysicsAdapter.d.ts +0 -19
  457. package/3d/physics/RapierPhysicsAdapter.d.ts +0 -19
  458. package/3d/physics/physics-interface.d.ts +0 -27
  459. package/3d.d.ts +0 -2
  460. package/3d.js +0 -34041
  461. package/3d.js.map +0 -155
  462. package/LICENSE +0 -21
  463. package/NativeSpanFeed.d.ts +0 -41
  464. package/Renderable.d.ts +0 -334
  465. package/animation/Timeline.d.ts +0 -126
  466. package/ansi.d.ts +0 -13
  467. package/buffer.d.ts +0 -111
  468. package/console.d.ts +0 -144
  469. package/edit-buffer.d.ts +0 -98
  470. package/editor-view.d.ts +0 -73
  471. package/index-8fks7yv1.js +0 -411
  472. package/index-8fks7yv1.js.map +0 -10
  473. package/index-egy5e2rs.js +0 -12267
  474. package/index-egy5e2rs.js.map +0 -42
  475. package/index-tse8gzh0.js +0 -20614
  476. package/index-tse8gzh0.js.map +0 -67
  477. package/index.d.ts +0 -23
  478. package/index.js +0 -478
  479. package/index.js.map +0 -9
  480. package/lib/KeyHandler.d.ts +0 -61
  481. package/lib/RGBA.d.ts +0 -25
  482. package/lib/ascii.font.d.ts +0 -508
  483. package/lib/border.d.ts +0 -51
  484. package/lib/bunfs.d.ts +0 -7
  485. package/lib/clipboard.d.ts +0 -17
  486. package/lib/clock.d.ts +0 -15
  487. package/lib/data-paths.d.ts +0 -26
  488. package/lib/debounce.d.ts +0 -42
  489. package/lib/detect-links.d.ts +0 -6
  490. package/lib/env.d.ts +0 -42
  491. package/lib/extmarks-history.d.ts +0 -17
  492. package/lib/extmarks.d.ts +0 -89
  493. package/lib/hast-styled-text.d.ts +0 -17
  494. package/lib/index.d.ts +0 -21
  495. package/lib/keymapping.d.ts +0 -25
  496. package/lib/objects-in-viewport.d.ts +0 -24
  497. package/lib/output.capture.d.ts +0 -24
  498. package/lib/parse.keypress-kitty.d.ts +0 -2
  499. package/lib/parse.keypress.d.ts +0 -26
  500. package/lib/parse.mouse.d.ts +0 -30
  501. package/lib/paste.d.ts +0 -7
  502. package/lib/queue.d.ts +0 -15
  503. package/lib/renderable.validations.d.ts +0 -12
  504. package/lib/scroll-acceleration.d.ts +0 -43
  505. package/lib/selection.d.ts +0 -63
  506. package/lib/singleton.d.ts +0 -7
  507. package/lib/stdin-parser.d.ts +0 -87
  508. package/lib/styled-text.d.ts +0 -63
  509. package/lib/terminal-capability-detection.d.ts +0 -30
  510. package/lib/terminal-palette.d.ts +0 -50
  511. package/lib/tree-sitter/assets/update.d.ts +0 -11
  512. package/lib/tree-sitter/client.d.ts +0 -47
  513. package/lib/tree-sitter/default-parsers.d.ts +0 -2
  514. package/lib/tree-sitter/download-utils.d.ts +0 -21
  515. package/lib/tree-sitter/index.d.ts +0 -8
  516. package/lib/tree-sitter/parser.worker.d.ts +0 -1
  517. package/lib/tree-sitter/parsers-config.d.ts +0 -53
  518. package/lib/tree-sitter/resolve-ft.d.ts +0 -5
  519. package/lib/tree-sitter/types.d.ts +0 -82
  520. package/lib/tree-sitter-styled-text.d.ts +0 -14
  521. package/lib/validate-dir-name.d.ts +0 -1
  522. package/lib/yoga.options.d.ts +0 -32
  523. package/parser.worker.js +0 -899
  524. package/parser.worker.js.map +0 -12
  525. package/plugins/core-slot.d.ts +0 -72
  526. package/plugins/registry.d.ts +0 -42
  527. package/plugins/types.d.ts +0 -34
  528. package/post/effects.d.ts +0 -147
  529. package/post/filters.d.ts +0 -65
  530. package/post/matrices.d.ts +0 -20
  531. package/renderables/ASCIIFont.d.ts +0 -52
  532. package/renderables/Box.d.ts +0 -81
  533. package/renderables/Code.d.ts +0 -78
  534. package/renderables/Diff.d.ts +0 -142
  535. package/renderables/EditBufferRenderable.d.ts +0 -237
  536. package/renderables/FrameBuffer.d.ts +0 -16
  537. package/renderables/Input.d.ts +0 -67
  538. package/renderables/LineNumberRenderable.d.ts +0 -78
  539. package/renderables/Markdown.d.ts +0 -185
  540. package/renderables/ScrollBar.d.ts +0 -77
  541. package/renderables/ScrollBox.d.ts +0 -124
  542. package/renderables/Select.d.ts +0 -115
  543. package/renderables/Slider.d.ts +0 -47
  544. package/renderables/TabSelect.d.ts +0 -96
  545. package/renderables/Text.d.ts +0 -36
  546. package/renderables/TextBufferRenderable.d.ts +0 -105
  547. package/renderables/TextNode.d.ts +0 -91
  548. package/renderables/TextTable.d.ts +0 -140
  549. package/renderables/Textarea.d.ts +0 -63
  550. package/renderables/TimeToFirstDraw.d.ts +0 -24
  551. package/renderables/__tests__/renderable-test-utils.d.ts +0 -12
  552. package/renderables/composition/VRenderable.d.ts +0 -16
  553. package/renderables/composition/constructs.d.ts +0 -35
  554. package/renderables/composition/vnode.d.ts +0 -46
  555. package/renderables/index.d.ts +0 -23
  556. package/renderables/markdown-parser.d.ts +0 -10
  557. package/renderer.d.ts +0 -419
  558. package/runtime-plugin-support.d.ts +0 -3
  559. package/runtime-plugin-support.js +0 -29
  560. package/runtime-plugin-support.js.map +0 -10
  561. package/runtime-plugin.d.ts +0 -16
  562. package/runtime-plugin.js +0 -16
  563. package/runtime-plugin.js.map +0 -9
  564. package/syntax-style.d.ts +0 -54
  565. package/testing/manual-clock.d.ts +0 -17
  566. package/testing/mock-keys.d.ts +0 -81
  567. package/testing/mock-mouse.d.ts +0 -38
  568. package/testing/mock-tree-sitter-client.d.ts +0 -23
  569. package/testing/spy.d.ts +0 -7
  570. package/testing/test-recorder.d.ts +0 -61
  571. package/testing/test-renderer.d.ts +0 -23
  572. package/testing.d.ts +0 -6
  573. package/testing.js +0 -697
  574. package/testing.js.map +0 -15
  575. package/text-buffer-view.d.ts +0 -42
  576. package/text-buffer.d.ts +0 -67
  577. package/types.d.ts +0 -139
  578. package/utils.d.ts +0 -14
  579. package/zig-structs.d.ts +0 -155
  580. package/zig.d.ts +0 -353
  581. /package/{assets → src/lib/tree-sitter/assets}/javascript/highlights.scm +0 -0
  582. /package/{assets → src/lib/tree-sitter/assets}/javascript/tree-sitter-javascript.wasm +0 -0
  583. /package/{assets → src/lib/tree-sitter/assets}/markdown/highlights.scm +0 -0
  584. /package/{assets → src/lib/tree-sitter/assets}/markdown/injections.scm +0 -0
  585. /package/{assets → src/lib/tree-sitter/assets}/markdown/tree-sitter-markdown.wasm +0 -0
  586. /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/highlights.scm +0 -0
  587. /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  588. /package/{assets → src/lib/tree-sitter/assets}/typescript/highlights.scm +0 -0
  589. /package/{assets → src/lib/tree-sitter/assets}/typescript/tree-sitter-typescript.wasm +0 -0
  590. /package/{assets → src/lib/tree-sitter/assets}/zig/highlights.scm +0 -0
  591. /package/{assets → src/lib/tree-sitter/assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -0,0 +1,1058 @@
1
+ import { describe, expect, it } from "bun:test"
2
+ import { TextNodeRenderable, isTextNodeRenderable } from "./TextNode.js"
3
+ import { RGBA } from "../lib/RGBA.js"
4
+ import { StyledText, red, bold, t } from "../lib/styled-text.js"
5
+
6
+ describe("TextNodeRenderable", () => {
7
+ describe("Constructor and Options", () => {
8
+ it("should create TextNode with default options", () => {
9
+ const node = new TextNodeRenderable({})
10
+
11
+ expect(node.fg).toBeUndefined()
12
+ expect(node.bg).toBeUndefined()
13
+ expect(node.attributes).toBe(0)
14
+ expect(node.children).toEqual([])
15
+ })
16
+
17
+ it("should create TextNode with custom options", () => {
18
+ const fgColor = RGBA.fromInts(255, 0, 0, 255)
19
+ const bgColor = RGBA.fromInts(0, 0, 255, 255)
20
+ const attributes = 1
21
+
22
+ const node = new TextNodeRenderable({
23
+ fg: fgColor,
24
+ bg: bgColor,
25
+ attributes,
26
+ })
27
+
28
+ expect(node.fg).toEqual(fgColor)
29
+ expect(node.bg).toEqual(bgColor)
30
+ expect(node.attributes).toBe(attributes)
31
+ })
32
+
33
+ it("should parse color strings in constructor", () => {
34
+ const node = new TextNodeRenderable({
35
+ fg: "#ff0000",
36
+ bg: "blue",
37
+ })
38
+
39
+ expect(node.fg?.r).toBe(1)
40
+ expect(node.fg?.g).toBe(0)
41
+ expect(node.fg?.b).toBe(0)
42
+ expect(node.fg?.a).toBe(1)
43
+ expect(node.bg?.r).toBe(0)
44
+ expect(node.bg?.g).toBe(0)
45
+ expect(node.bg?.b).toBe(1)
46
+ expect(node.bg?.a).toBe(1)
47
+ })
48
+
49
+ it("should handle undefined colors", () => {
50
+ const node = new TextNodeRenderable({
51
+ fg: undefined,
52
+ bg: undefined,
53
+ })
54
+
55
+ expect(node.fg).toBeUndefined()
56
+ expect(node.bg).toBeUndefined()
57
+ })
58
+ })
59
+
60
+ describe("Type Guard", () => {
61
+ it("should identify TextNodeRenderable instances", () => {
62
+ const node = new TextNodeRenderable({})
63
+ const plainObject = {}
64
+
65
+ expect(isTextNodeRenderable(node)).toBe(true)
66
+ expect(isTextNodeRenderable(plainObject)).toBe(false)
67
+ expect(isTextNodeRenderable(null)).toBe(false)
68
+ expect(isTextNodeRenderable(undefined)).toBe(false)
69
+ })
70
+ })
71
+
72
+ describe("add Method", () => {
73
+ it("should add string child using add", () => {
74
+ const node = new TextNodeRenderable({})
75
+
76
+ const index = node.add("Hello")
77
+
78
+ expect(index).toBe(0)
79
+ expect(node.children).toEqual(["Hello"])
80
+ })
81
+
82
+ it("should add TextNode child using add", () => {
83
+ const parent = new TextNodeRenderable({})
84
+ const child = new TextNodeRenderable({})
85
+
86
+ const index = parent.add(child)
87
+
88
+ expect(index).toBe(0)
89
+ expect(parent.children).toEqual([child])
90
+ })
91
+
92
+ it("should add multiple children sequentially", () => {
93
+ const node = new TextNodeRenderable({})
94
+
95
+ node.add("First")
96
+ node.add("Second")
97
+ const childNode = new TextNodeRenderable({})
98
+ node.add(childNode)
99
+
100
+ expect(node.children).toEqual(["First", "Second", childNode])
101
+ })
102
+
103
+ it("should add child at specific index using add method", () => {
104
+ const node = new TextNodeRenderable({})
105
+ const child1 = new TextNodeRenderable({})
106
+ const child2 = new TextNodeRenderable({})
107
+
108
+ node.add("First")
109
+ node.add(child1, 0) // Insert at beginning
110
+ node.add(child2, 2) // Insert at end
111
+
112
+ expect(node.children).toEqual([child1, "First", child2])
113
+ })
114
+
115
+ it("should add string at specific index using add method", () => {
116
+ const node = new TextNodeRenderable({})
117
+ const child1 = new TextNodeRenderable({})
118
+
119
+ node.add("First")
120
+ node.add(child1, 0) // Insert at beginning
121
+ node.add("Middle", 1) // Insert in middle
122
+ node.add("Last") // Append at end
123
+
124
+ expect(node.children).toEqual([child1, "Middle", "First", "Last"])
125
+ })
126
+
127
+ it("should reject non-TextNode children in add method", () => {
128
+ const node = new TextNodeRenderable({})
129
+ const invalidChild = { id: "invalid" }
130
+
131
+ expect(() => {
132
+ node.add(invalidChild as any, 0)
133
+ }).toThrow("TextNodeRenderable only accepts strings, TextNodeRenderable instances, or StyledText instances")
134
+ })
135
+
136
+ it("should add StyledText child using add method", () => {
137
+ const node = new TextNodeRenderable({})
138
+ const styledText = new StyledText([
139
+ { __isChunk: true, text: "Hello", fg: RGBA.fromInts(255, 0, 0, 255), attributes: 1 },
140
+ { __isChunk: true, text: " World", fg: RGBA.fromInts(0, 255, 0, 255), attributes: 0 },
141
+ ])
142
+
143
+ const index = node.add(styledText)
144
+
145
+ expect(index).toBe(0)
146
+ expect(node.children).toHaveLength(2)
147
+ expect(node.children[0]).toBeInstanceOf(TextNodeRenderable)
148
+ expect(node.children[1]).toBeInstanceOf(TextNodeRenderable)
149
+
150
+ const firstChild = node.children[0] as TextNodeRenderable
151
+ const secondChild = node.children[1] as TextNodeRenderable
152
+
153
+ expect(firstChild.children).toEqual(["Hello"])
154
+ expect(firstChild.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
155
+ expect(firstChild.attributes).toBe(1)
156
+
157
+ expect(secondChild.children).toEqual([" World"])
158
+ expect(secondChild.fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
159
+ expect(secondChild.attributes).toBe(0)
160
+ })
161
+
162
+ it("should add StyledText child at specific index using add method", () => {
163
+ const node = new TextNodeRenderable({})
164
+ node.add("First")
165
+ node.add("Third")
166
+
167
+ const styledText = new StyledText([
168
+ { __isChunk: true, text: "Second", fg: RGBA.fromInts(255, 255, 0, 255), attributes: 2 },
169
+ ])
170
+
171
+ node.add(styledText, 1)
172
+
173
+ expect(node.children).toHaveLength(3)
174
+ expect(node.children[0]).toBe("First")
175
+ expect(node.children[1]).toBeInstanceOf(TextNodeRenderable)
176
+ expect(node.children[2]).toBe("Third")
177
+
178
+ const styledChild = node.children[1] as TextNodeRenderable
179
+ expect(styledChild.children).toEqual(["Second"])
180
+ expect(styledChild.fg).toEqual(RGBA.fromInts(255, 255, 0, 255))
181
+ expect(styledChild.attributes).toBe(2)
182
+ })
183
+ })
184
+
185
+ describe("insertBefore and remove Methods", () => {
186
+ it("should insert child before anchor node", () => {
187
+ const node = new TextNodeRenderable({})
188
+ const anchor = new TextNodeRenderable({})
189
+
190
+ node.add("First")
191
+ node.add(anchor)
192
+ node.add("Last")
193
+
194
+ node.insertBefore("Middle", anchor)
195
+
196
+ expect(node.children).toEqual(["First", "Middle", anchor, "Last"])
197
+ })
198
+
199
+ it("should throw error when anchor node not found in insertBefore", () => {
200
+ const node = new TextNodeRenderable({})
201
+ const anchor = new TextNodeRenderable({})
202
+
203
+ expect(() => {
204
+ node.insertBefore("Test", anchor)
205
+ }).toThrow("Anchor node not found in children")
206
+ })
207
+
208
+ it("should insert StyledText before anchor node", () => {
209
+ const node = new TextNodeRenderable({})
210
+ const anchor = new TextNodeRenderable({})
211
+ anchor.add("Anchor")
212
+
213
+ node.add("First")
214
+ node.add(anchor)
215
+ node.add("Last")
216
+
217
+ const styledText = new StyledText([
218
+ { __isChunk: true, text: "Middle", fg: RGBA.fromInts(128, 128, 128, 255), attributes: 4 },
219
+ ])
220
+
221
+ node.insertBefore(styledText, anchor)
222
+
223
+ expect(node.children).toHaveLength(4)
224
+ expect(node.children[0]).toBe("First")
225
+ expect(node.children[1]).toBeInstanceOf(TextNodeRenderable)
226
+ expect(node.children[2]).toBe(anchor)
227
+ expect(node.children[3]).toBe("Last")
228
+
229
+ const styledChild = node.children[1] as TextNodeRenderable
230
+ expect(styledChild.children).toEqual(["Middle"])
231
+ expect(styledChild.fg).toEqual(RGBA.fromInts(128, 128, 128, 255))
232
+ expect(styledChild.attributes).toBe(4)
233
+ })
234
+
235
+ it("should remove child from node", () => {
236
+ const node = new TextNodeRenderable({})
237
+ const child = new TextNodeRenderable({})
238
+
239
+ node.add("First")
240
+ node.add(child)
241
+ node.add("Last")
242
+
243
+ node.remove(child.id)
244
+
245
+ expect(node.children).toEqual(["First", "Last"])
246
+ expect(child.parent).toBeNull()
247
+ })
248
+
249
+ it("should throw error when child not found in remove", () => {
250
+ const node = new TextNodeRenderable({})
251
+
252
+ expect(() => {
253
+ node.remove("nonexistent-id")
254
+ }).toThrow("Child not found in children")
255
+ })
256
+ })
257
+
258
+ describe("clear Method", () => {
259
+ it("should clear all children and change log", () => {
260
+ const node = new TextNodeRenderable({})
261
+
262
+ node.add("Test")
263
+ node.add(new TextNodeRenderable({}))
264
+
265
+ expect(node.children).toHaveLength(2)
266
+
267
+ node.clear()
268
+
269
+ expect(node.children).toEqual([])
270
+ })
271
+ })
272
+
273
+ describe("Style Inheritance and Merging", () => {
274
+ it("should merge styles with parent styles", () => {
275
+ const node = new TextNodeRenderable({
276
+ fg: RGBA.fromInts(255, 0, 0, 255),
277
+ attributes: 1,
278
+ })
279
+
280
+ const parentStyle = {
281
+ bg: RGBA.fromInts(0, 0, 255, 255),
282
+ attributes: 2,
283
+ }
284
+
285
+ const merged = node.mergeStyles(parentStyle)
286
+
287
+ expect(merged.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
288
+ expect(merged.bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
289
+ expect(merged.attributes).toBe(3)
290
+ })
291
+
292
+ it("should inherit undefined styles from parent", () => {
293
+ const node = new TextNodeRenderable({
294
+ fg: RGBA.fromInts(255, 0, 0, 255),
295
+ // bg and attributes undefined (attributes defaults to 0)
296
+ })
297
+
298
+ const parentStyle = {
299
+ bg: RGBA.fromInts(0, 0, 255, 255),
300
+ attributes: 2,
301
+ }
302
+
303
+ const merged = node.mergeStyles(parentStyle)
304
+
305
+ expect(merged.fg?.r).toBe(1)
306
+ expect(merged.fg?.g).toBe(0)
307
+ expect(merged.fg?.b).toBe(0)
308
+ expect(merged.bg?.r).toBe(0)
309
+ expect(merged.bg?.g).toBe(0)
310
+ expect(merged.bg?.b).toBe(1)
311
+ expect(merged.attributes).toBe(2)
312
+ })
313
+
314
+ it("should inherit nothing when parent has no styling", () => {
315
+ const node = new TextNodeRenderable({}) // No styles defined
316
+
317
+ const parentStyle = {
318
+ fg: undefined,
319
+ bg: undefined,
320
+ attributes: 0,
321
+ }
322
+
323
+ const merged = node.mergeStyles(parentStyle)
324
+
325
+ expect(merged.fg).toBeUndefined()
326
+ expect(merged.bg).toBeUndefined()
327
+ expect(merged.attributes).toBe(0)
328
+ })
329
+
330
+ it("should combine attributes using bitwise OR", () => {
331
+ // Test various attribute combinations
332
+ const testCases = [
333
+ { nodeAttrs: 0, parentAttrs: 0, expected: 0 }, // 0 | 0 = 0
334
+ { nodeAttrs: 1, parentAttrs: 0, expected: 1 }, // 1 | 0 = 1 (bold)
335
+ { nodeAttrs: 0, parentAttrs: 2, expected: 2 }, // 0 | 2 = 2 (italic)
336
+ { nodeAttrs: 1, parentAttrs: 2, expected: 3 }, // 1 | 2 = 3 (bold + italic)
337
+ { nodeAttrs: 3, parentAttrs: 4, expected: 7 }, // 3 | 4 = 7 (bold + italic + underline)
338
+ { nodeAttrs: 7, parentAttrs: 8, expected: 15 }, // 7 | 8 = 15 (all previous + strikethrough)
339
+ ]
340
+
341
+ testCases.forEach(({ nodeAttrs, parentAttrs, expected }) => {
342
+ const node = new TextNodeRenderable({ attributes: nodeAttrs })
343
+ const parentStyle = { fg: undefined, bg: undefined, attributes: parentAttrs }
344
+
345
+ const merged = node.mergeStyles(parentStyle)
346
+ expect(merged.attributes).toBe(expected)
347
+ })
348
+ })
349
+ })
350
+
351
+ describe("gatherWithInheritedStyle Method", () => {
352
+ it("should gather chunks with inherited styles", () => {
353
+ const node = new TextNodeRenderable({
354
+ fg: RGBA.fromInts(255, 0, 0, 255),
355
+ bg: RGBA.fromInts(0, 0, 255, 255),
356
+ attributes: 1,
357
+ })
358
+
359
+ node.add("Hello")
360
+ node.add(" ")
361
+ node.add("World")
362
+
363
+ const chunks = node.gatherWithInheritedStyle()
364
+
365
+ expect(chunks).toHaveLength(3)
366
+ chunks.forEach((chunk) => {
367
+ expect(chunk.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
368
+ expect(chunk.bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
369
+ expect(chunk.attributes).toBe(1)
370
+ })
371
+
372
+ expect(chunks[0].text).toBe("Hello")
373
+ expect(chunks[1].text).toBe(" ")
374
+ expect(chunks[2].text).toBe("World")
375
+ })
376
+
377
+ it("should recursively gather from child TextNodes", () => {
378
+ const parent = new TextNodeRenderable({
379
+ fg: RGBA.fromInts(255, 0, 0, 255),
380
+ })
381
+
382
+ const child = new TextNodeRenderable({
383
+ bg: RGBA.fromInts(0, 255, 0, 255),
384
+ })
385
+
386
+ child.add("Child")
387
+ parent.add("Parent")
388
+ parent.add(child)
389
+
390
+ const chunks = parent.gatherWithInheritedStyle()
391
+
392
+ expect(chunks).toHaveLength(2)
393
+ expect(chunks[0].text).toBe("Parent")
394
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
395
+ expect(chunks[0].bg).toBeUndefined()
396
+
397
+ expect(chunks[1].text).toBe("Child")
398
+ expect(chunks[1].fg).toEqual(RGBA.fromInts(255, 0, 0, 255)) // Inherited from parent
399
+ expect(chunks[1].bg).toEqual(RGBA.fromInts(0, 255, 0, 255)) // Own style
400
+ })
401
+
402
+ it("should inherit nothing when parent has no default styling", () => {
403
+ const parent = new TextNodeRenderable({}) // No styles
404
+
405
+ const child = new TextNodeRenderable({}) // No styles
406
+ child.add("Child")
407
+
408
+ parent.add("Parent")
409
+ parent.add(child)
410
+
411
+ const chunks = parent.gatherWithInheritedStyle()
412
+
413
+ expect(chunks).toHaveLength(2)
414
+ expect(chunks[0].text).toBe("Parent")
415
+ expect(chunks[0].fg).toBeUndefined()
416
+ expect(chunks[0].bg).toBeUndefined()
417
+ expect(chunks[0].attributes).toBe(0)
418
+
419
+ expect(chunks[1].text).toBe("Child")
420
+ expect(chunks[1].fg).toBeUndefined() // Nothing inherited
421
+ expect(chunks[1].bg).toBeUndefined() // Nothing inherited
422
+ expect(chunks[1].attributes).toBe(0) // Nothing inherited
423
+ })
424
+
425
+ it("should allow children to override parent styles independently", () => {
426
+ const parent = new TextNodeRenderable({
427
+ fg: RGBA.fromInts(255, 0, 0, 255),
428
+ bg: RGBA.fromInts(0, 0, 255, 255),
429
+ attributes: 1,
430
+ })
431
+
432
+ const childOverrideFg = new TextNodeRenderable({
433
+ fg: RGBA.fromInts(0, 255, 0, 255),
434
+ })
435
+ childOverrideFg.add("Green Text")
436
+
437
+ const childOverrideBg = new TextNodeRenderable({
438
+ bg: RGBA.fromInts(255, 255, 0, 255),
439
+ })
440
+ childOverrideBg.add("Yellow BG")
441
+
442
+ const childOverrideAttrs = new TextNodeRenderable({
443
+ attributes: 2,
444
+ })
445
+ childOverrideAttrs.add("Italic")
446
+
447
+ parent.add(childOverrideFg)
448
+ parent.add(childOverrideBg)
449
+ parent.add(childOverrideAttrs)
450
+
451
+ const chunks = parent.gatherWithInheritedStyle()
452
+
453
+ expect(chunks).toHaveLength(3)
454
+
455
+ // First child: overrides fg, inherits bg and attributes
456
+ expect(chunks[0].text).toBe("Green Text")
457
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(0, 255, 0, 255)) // Overridden
458
+ expect(chunks[0].bg).toEqual(RGBA.fromInts(0, 0, 255, 255)) // Inherited
459
+ expect(chunks[0].attributes).toBe(1) // Inherited
460
+
461
+ // Second child: overrides bg, inherits fg and attributes
462
+ expect(chunks[1].text).toBe("Yellow BG")
463
+ expect(chunks[1].fg).toEqual(RGBA.fromInts(255, 0, 0, 255)) // Inherited
464
+ expect(chunks[1].bg).toEqual(RGBA.fromInts(255, 255, 0, 255)) // Overridden
465
+ expect(chunks[1].attributes).toBe(1) // Inherited
466
+
467
+ // Third child: overrides attributes (OR'd), inherits fg and bg
468
+ expect(chunks[2].text).toBe("Italic")
469
+ expect(chunks[2].fg).toEqual(RGBA.fromInts(255, 0, 0, 255)) // Inherited
470
+ expect(chunks[2].bg).toEqual(RGBA.fromInts(0, 0, 255, 255)) // Inherited
471
+ expect(chunks[2].attributes).toBe(3) // 1 | 2 = 3
472
+ })
473
+
474
+ it("should support multi-level inheritance (grandparent -> parent -> child)", () => {
475
+ const grandparent = new TextNodeRenderable({
476
+ fg: RGBA.fromInts(255, 0, 0, 255),
477
+ attributes: 1,
478
+ })
479
+
480
+ const parent = new TextNodeRenderable({
481
+ bg: RGBA.fromInts(0, 0, 255, 255),
482
+ })
483
+
484
+ const child = new TextNodeRenderable({
485
+ fg: RGBA.fromInts(0, 255, 0, 255),
486
+ attributes: 2,
487
+ })
488
+
489
+ child.add("Grandchild")
490
+ parent.add("Parent")
491
+ parent.add(child)
492
+ grandparent.add("Grandparent")
493
+ grandparent.add(parent)
494
+
495
+ const chunks = grandparent.gatherWithInheritedStyle()
496
+
497
+ expect(chunks).toHaveLength(3)
498
+
499
+ expect(chunks[0].text).toBe("Grandparent")
500
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
501
+ expect(chunks[0].bg).toBeUndefined()
502
+ expect(chunks[0].attributes).toBe(1)
503
+
504
+ expect(chunks[1].text).toBe("Parent")
505
+ expect(chunks[1].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
506
+ expect(chunks[1].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
507
+ expect(chunks[1].attributes).toBe(1)
508
+
509
+ expect(chunks[2].text).toBe("Grandchild")
510
+ expect(chunks[2].fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
511
+ expect(chunks[2].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
512
+ expect(chunks[2].attributes).toBe(3)
513
+ })
514
+
515
+ it("should support partial style overrides in children", () => {
516
+ const parent = new TextNodeRenderable({
517
+ fg: RGBA.fromInts(255, 0, 0, 255),
518
+ bg: RGBA.fromInts(0, 0, 255, 255),
519
+ attributes: 1,
520
+ })
521
+
522
+ const childPartial1 = new TextNodeRenderable({
523
+ fg: RGBA.fromInts(0, 255, 0, 255),
524
+ })
525
+ childPartial1.add("Green on Blue")
526
+
527
+ const childPartial2 = new TextNodeRenderable({
528
+ bg: RGBA.fromInts(255, 255, 0, 255),
529
+ })
530
+ childPartial2.add("Red on Yellow")
531
+
532
+ const childPartial3 = new TextNodeRenderable({
533
+ attributes: 2,
534
+ })
535
+ childPartial3.add("Red on Blue Bold+Italic")
536
+
537
+ const childPartial4 = new TextNodeRenderable({
538
+ fg: RGBA.fromInts(255, 255, 255, 255),
539
+ attributes: 4,
540
+ })
541
+ childPartial4.add("White on Blue Bold+Underline")
542
+
543
+ parent.add(childPartial1)
544
+ parent.add(childPartial2)
545
+ parent.add(childPartial3)
546
+ parent.add(childPartial4)
547
+
548
+ const chunks = parent.gatherWithInheritedStyle()
549
+
550
+ expect(chunks).toHaveLength(4)
551
+
552
+ // Child 1: only fg overridden
553
+ expect(chunks[0].text).toBe("Green on Blue")
554
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
555
+ expect(chunks[0].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
556
+ expect(chunks[0].attributes).toBe(1)
557
+
558
+ // Child 2: only bg overridden
559
+ expect(chunks[1].text).toBe("Red on Yellow")
560
+ expect(chunks[1].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
561
+ expect(chunks[1].bg).toEqual(RGBA.fromInts(255, 255, 0, 255))
562
+ expect(chunks[1].attributes).toBe(1)
563
+
564
+ // Child 3: only attributes overridden (OR'd)
565
+ expect(chunks[2].text).toBe("Red on Blue Bold+Italic")
566
+ expect(chunks[2].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
567
+ expect(chunks[2].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
568
+ expect(chunks[2].attributes).toBe(3) // 1 | 2 = 3
569
+
570
+ // Child 4: fg and attributes overridden, bg inherited
571
+ expect(chunks[3].text).toBe("White on Blue Bold+Underline")
572
+ expect(chunks[3].fg).toEqual(RGBA.fromInts(255, 255, 255, 255))
573
+ expect(chunks[3].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
574
+ expect(chunks[3].attributes).toBe(5) // 1 | 4 = 5
575
+ })
576
+ })
577
+
578
+ describe("Static Factory Methods", () => {
579
+ it("should create TextNode from string using fromString", () => {
580
+ const node = TextNodeRenderable.fromString("Hello World", {
581
+ fg: "#ff0000",
582
+ attributes: 1,
583
+ })
584
+
585
+ expect(node.children).toEqual(["Hello World"])
586
+ expect(node.fg?.r).toBe(1)
587
+ expect(node.fg?.g).toBe(0)
588
+ expect(node.fg?.b).toBe(0)
589
+ expect(node.attributes).toBe(1)
590
+ })
591
+
592
+ it("should create TextNode from nodes using fromNodes", () => {
593
+ const child1 = new TextNodeRenderable({})
594
+ const child2 = new TextNodeRenderable({})
595
+
596
+ child1.add("First")
597
+ child2.add("Second")
598
+
599
+ const parent = TextNodeRenderable.fromNodes([child1, child2], {
600
+ fg: RGBA.fromInts(255, 255, 0, 255),
601
+ })
602
+
603
+ expect(parent.children).toEqual([child1, child2])
604
+ expect(parent.fg).toEqual(RGBA.fromInts(255, 255, 0, 255))
605
+ })
606
+ })
607
+
608
+ describe("Utility Methods", () => {
609
+ it("should convert to chunks using toChunks", () => {
610
+ const node = new TextNodeRenderable({
611
+ fg: "#00ff00",
612
+ })
613
+
614
+ node.add("Test")
615
+
616
+ const chunks = node.toChunks()
617
+
618
+ expect(chunks).toHaveLength(1)
619
+ expect(chunks[0].text).toBe("Test")
620
+ expect(chunks[0].fg?.r).toBe(0)
621
+ expect(chunks[0].fg?.g).toBe(1)
622
+ expect(chunks[0].fg?.b).toBe(0)
623
+ })
624
+
625
+ it("should get children using getChildren", () => {
626
+ const node = new TextNodeRenderable({})
627
+
628
+ node.add("String child")
629
+ const textNodeChild = new TextNodeRenderable({})
630
+ node.add(textNodeChild)
631
+
632
+ const children = node.getChildren()
633
+
634
+ expect(children).toHaveLength(1)
635
+ expect(children[0]).toBe(textNodeChild)
636
+ })
637
+
638
+ it("should get children count", () => {
639
+ const node = new TextNodeRenderable({})
640
+
641
+ expect(node.getChildrenCount()).toBe(0)
642
+
643
+ node.add("First")
644
+ expect(node.getChildrenCount()).toBe(1)
645
+
646
+ node.add(new TextNodeRenderable({}))
647
+ expect(node.getChildrenCount()).toBe(2)
648
+ })
649
+
650
+ it("should find renderable by id", () => {
651
+ const node = new TextNodeRenderable({})
652
+
653
+ const child1 = new TextNodeRenderable({ id: "child1" })
654
+ const child2 = new TextNodeRenderable({ id: "child2" })
655
+
656
+ node.add(child1)
657
+ node.add(child2)
658
+
659
+ expect(node.getRenderable("child1")).toBe(child1)
660
+ expect(node.getRenderable("child2")).toBe(child2)
661
+ expect(node.getRenderable("nonexistent")).toBeUndefined()
662
+ })
663
+ })
664
+
665
+ describe("StyledText Integration", () => {
666
+ it("should work with template literal styled text", () => {
667
+ const node = new TextNodeRenderable({})
668
+ const styled = t`Hello ${red("World")} with ${bold("bold")} text!`
669
+
670
+ node.add(styled)
671
+
672
+ expect(node.children).toHaveLength(5) // All parts become TextNodeRenderable instances
673
+ expect(node.children[0]).toBeInstanceOf(TextNodeRenderable)
674
+ expect(node.children[1]).toBeInstanceOf(TextNodeRenderable)
675
+ expect(node.children[2]).toBeInstanceOf(TextNodeRenderable)
676
+ expect(node.children[3]).toBeInstanceOf(TextNodeRenderable)
677
+ expect(node.children[4]).toBeInstanceOf(TextNodeRenderable)
678
+
679
+ // Check first chunk: "Hello " (no styling)
680
+ const helloChild = node.children[0] as TextNodeRenderable
681
+ expect(helloChild.children).toEqual(["Hello "])
682
+ expect(helloChild.fg).toBeUndefined()
683
+ expect(helloChild.attributes).toBe(0)
684
+
685
+ // Check second chunk: "World" (red styling)
686
+ const redChild = node.children[1] as TextNodeRenderable
687
+ expect(redChild.children).toEqual(["World"])
688
+ expect(redChild.fg?.r).toBe(1)
689
+ expect(redChild.fg?.g).toBe(0)
690
+ expect(redChild.fg?.b).toBe(0)
691
+ expect(redChild.attributes).toBe(0)
692
+
693
+ // Check third chunk: " with " (no styling)
694
+ const withChild = node.children[2] as TextNodeRenderable
695
+ expect(withChild.children).toEqual([" with "])
696
+ expect(withChild.fg).toBeUndefined()
697
+ expect(withChild.attributes).toBe(0)
698
+
699
+ // Check fourth chunk: "bold" (bold styling)
700
+ const boldChild = node.children[3] as TextNodeRenderable
701
+ expect(boldChild.children).toEqual(["bold"])
702
+ expect(boldChild.fg).toBeUndefined()
703
+ expect(boldChild.attributes).toBe(1) // bold attribute
704
+
705
+ // Check fifth chunk: " text!" (no styling)
706
+ const textChild = node.children[4] as TextNodeRenderable
707
+ expect(textChild.children).toEqual([" text!"])
708
+ expect(textChild.fg).toBeUndefined()
709
+ expect(textChild.attributes).toBe(0)
710
+ })
711
+
712
+ it("should preserve styles when converting StyledText to TextNodes", () => {
713
+ const node = new TextNodeRenderable({})
714
+ const styledText = new StyledText([
715
+ {
716
+ __isChunk: true,
717
+ text: "Red",
718
+ fg: RGBA.fromInts(255, 0, 0, 255),
719
+ bg: RGBA.fromInts(0, 0, 0, 255),
720
+ attributes: 1,
721
+ },
722
+ { __isChunk: true, text: "Blue", fg: RGBA.fromInts(0, 0, 255, 255), attributes: 2 },
723
+ { __isChunk: true, text: "Green", fg: RGBA.fromInts(0, 255, 0, 255), attributes: 0 },
724
+ ])
725
+
726
+ node.add(styledText)
727
+
728
+ expect(node.children).toHaveLength(3)
729
+
730
+ const redNode = node.children[0] as TextNodeRenderable
731
+ expect(redNode.children).toEqual(["Red"])
732
+ expect(redNode.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
733
+ expect(redNode.bg).toEqual(RGBA.fromInts(0, 0, 0, 255))
734
+ expect(redNode.attributes).toBe(1)
735
+
736
+ const blueNode = node.children[1] as TextNodeRenderable
737
+ expect(blueNode.children).toEqual(["Blue"])
738
+ expect(blueNode.fg).toEqual(RGBA.fromInts(0, 0, 255, 255))
739
+ expect(blueNode.bg).toBeUndefined()
740
+ expect(blueNode.attributes).toBe(2)
741
+
742
+ const greenNode = node.children[2] as TextNodeRenderable
743
+ expect(greenNode.children).toEqual(["Green"])
744
+ expect(greenNode.fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
745
+ expect(greenNode.bg).toBeUndefined()
746
+ expect(greenNode.attributes).toBe(0)
747
+ })
748
+
749
+ it("should handle empty StyledText", () => {
750
+ const node = new TextNodeRenderable({})
751
+ const emptyStyledText = new StyledText([])
752
+
753
+ // Add empty StyledText
754
+ const index = node.add(emptyStyledText)
755
+ expect(index).toBe(0)
756
+
757
+ // Should have no children since empty StyledText produces no TextNodes
758
+ expect(node.children).toHaveLength(0)
759
+
760
+ // Verify that gatherWithInheritedStyle returns empty array
761
+ const chunks = node.gatherWithInheritedStyle()
762
+ expect(chunks).toHaveLength(0)
763
+ })
764
+
765
+ it("should handle StyledText with empty text chunks", () => {
766
+ const node = new TextNodeRenderable({})
767
+ const styledTextWithEmptyChunks = new StyledText([
768
+ { __isChunk: true, text: "", fg: RGBA.fromInts(255, 0, 0, 255), attributes: 1 },
769
+ { __isChunk: true, text: "middle", fg: RGBA.fromInts(0, 255, 0, 255), attributes: 0 },
770
+ { __isChunk: true, text: "", fg: RGBA.fromInts(0, 0, 255, 255), attributes: 2 },
771
+ ])
772
+
773
+ node.add(styledTextWithEmptyChunks)
774
+
775
+ expect(node.children).toHaveLength(3)
776
+
777
+ // First chunk: empty text with red styling
778
+ const emptyRedNode = node.children[0] as TextNodeRenderable
779
+ expect(emptyRedNode.children).toEqual([""])
780
+ expect(emptyRedNode.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
781
+ expect(emptyRedNode.attributes).toBe(1)
782
+
783
+ // Second chunk: "middle" with green styling
784
+ const middleNode = node.children[1] as TextNodeRenderable
785
+ expect(middleNode.children).toEqual(["middle"])
786
+ expect(middleNode.fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
787
+ expect(middleNode.attributes).toBe(0)
788
+
789
+ // Third chunk: empty text with blue styling
790
+ const emptyBlueNode = node.children[2] as TextNodeRenderable
791
+ expect(emptyBlueNode.children).toEqual([""])
792
+ expect(emptyBlueNode.fg).toEqual(RGBA.fromInts(0, 0, 255, 255))
793
+ expect(emptyBlueNode.attributes).toBe(2)
794
+ })
795
+ })
796
+
797
+ describe("Link Inheritance", () => {
798
+ it("should inherit link from parent to child", () => {
799
+ const parent = new TextNodeRenderable({
800
+ link: { url: "https://opentui.com" },
801
+ })
802
+
803
+ const child = new TextNodeRenderable({})
804
+ child.add("Child text")
805
+
806
+ parent.add("Parent text")
807
+ parent.add(child)
808
+
809
+ const chunks = parent.gatherWithInheritedStyle()
810
+
811
+ expect(chunks).toHaveLength(2)
812
+ expect(chunks[0].text).toBe("Parent text")
813
+ expect(chunks[0].link?.url).toBe("https://opentui.com")
814
+
815
+ expect(chunks[1].text).toBe("Child text")
816
+ expect(chunks[1].link?.url).toBe("https://opentui.com")
817
+ })
818
+
819
+ it("should allow child to override parent link", () => {
820
+ const parent = new TextNodeRenderable({
821
+ link: { url: "https://parent.com" },
822
+ })
823
+
824
+ const child = new TextNodeRenderable({
825
+ link: { url: "https://child.com" },
826
+ })
827
+ child.add("Child text")
828
+
829
+ parent.add("Parent text")
830
+ parent.add(child)
831
+
832
+ const chunks = parent.gatherWithInheritedStyle()
833
+
834
+ expect(chunks).toHaveLength(2)
835
+ expect(chunks[0].link?.url).toBe("https://parent.com")
836
+ expect(chunks[1].link?.url).toBe("https://child.com")
837
+ })
838
+
839
+ it("should inherit link through multiple nesting levels", () => {
840
+ const grandparent = new TextNodeRenderable({
841
+ link: { url: "https://example.com" },
842
+ })
843
+
844
+ const parent = new TextNodeRenderable({})
845
+ const child = new TextNodeRenderable({})
846
+
847
+ child.add("Grandchild")
848
+ parent.add(child)
849
+ grandparent.add(parent)
850
+
851
+ const chunks = grandparent.gatherWithInheritedStyle()
852
+
853
+ expect(chunks).toHaveLength(1)
854
+ expect(chunks[0].text).toBe("Grandchild")
855
+ expect(chunks[0].link?.url).toBe("https://example.com")
856
+ })
857
+
858
+ it("should merge link with other styles", () => {
859
+ const parent = new TextNodeRenderable({
860
+ fg: RGBA.fromInts(255, 0, 0, 255),
861
+ attributes: 1,
862
+ link: { url: "https://opentui.com" },
863
+ })
864
+
865
+ const child = new TextNodeRenderable({
866
+ bg: RGBA.fromInts(0, 0, 255, 255),
867
+ attributes: 2,
868
+ })
869
+ child.add("Styled linked text")
870
+
871
+ parent.add(child)
872
+
873
+ const chunks = parent.gatherWithInheritedStyle()
874
+
875
+ expect(chunks).toHaveLength(1)
876
+ expect(chunks[0].text).toBe("Styled linked text")
877
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
878
+ expect(chunks[0].bg).toEqual(RGBA.fromInts(0, 0, 255, 255))
879
+ expect(chunks[0].attributes).toBe(3) // 1 | 2
880
+ expect(chunks[0].link?.url).toBe("https://opentui.com")
881
+ })
882
+
883
+ it("should handle undefined link in parent", () => {
884
+ const parent = new TextNodeRenderable({})
885
+
886
+ const child = new TextNodeRenderable({
887
+ link: { url: "https://child.com" },
888
+ })
889
+ child.add("Child with link")
890
+
891
+ parent.add("Parent without link")
892
+ parent.add(child)
893
+
894
+ const chunks = parent.gatherWithInheritedStyle()
895
+
896
+ expect(chunks).toHaveLength(2)
897
+ expect(chunks[0].link).toBeUndefined()
898
+ expect(chunks[1].link?.url).toBe("https://child.com")
899
+ })
900
+
901
+ it("should preserve link when merging styles", () => {
902
+ const node = new TextNodeRenderable({
903
+ link: { url: "https://example.com" },
904
+ attributes: 1,
905
+ })
906
+
907
+ const parentStyle = {
908
+ fg: RGBA.fromInts(255, 0, 0, 255),
909
+ bg: undefined,
910
+ attributes: 2,
911
+ }
912
+
913
+ const merged = node.mergeStyles(parentStyle)
914
+
915
+ expect(merged.link?.url).toBe("https://example.com")
916
+ expect(merged.fg).toEqual(RGBA.fromInts(255, 0, 0, 255))
917
+ expect(merged.attributes).toBe(3)
918
+ })
919
+
920
+ it("should inherit link when node has no link", () => {
921
+ const node = new TextNodeRenderable({
922
+ fg: RGBA.fromInts(0, 255, 0, 255),
923
+ })
924
+
925
+ const parentStyle = {
926
+ fg: undefined,
927
+ bg: undefined,
928
+ attributes: 0,
929
+ link: { url: "https://inherited.com" },
930
+ }
931
+
932
+ const merged = node.mergeStyles(parentStyle)
933
+
934
+ expect(merged.link?.url).toBe("https://inherited.com")
935
+ expect(merged.fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
936
+ })
937
+
938
+ it("should handle complex link inheritance tree", () => {
939
+ // Grandparent with link
940
+ const grandparent = new TextNodeRenderable({
941
+ link: { url: "https://grandparent.com" },
942
+ fg: RGBA.fromInts(255, 0, 0, 255),
943
+ })
944
+
945
+ // Parent inherits link, adds bg
946
+ const parent = new TextNodeRenderable({
947
+ bg: RGBA.fromInts(0, 0, 255, 255),
948
+ })
949
+
950
+ // Child1 inherits link, overrides fg
951
+ const child1 = new TextNodeRenderable({
952
+ fg: RGBA.fromInts(0, 255, 0, 255),
953
+ })
954
+ child1.add("Child1")
955
+
956
+ // Child2 overrides link
957
+ const child2 = new TextNodeRenderable({
958
+ link: { url: "https://child2.com" },
959
+ })
960
+ child2.add("Child2")
961
+
962
+ // Child3 has no link set, should inherit from parent
963
+ const child3 = new TextNodeRenderable({
964
+ attributes: 1,
965
+ })
966
+ child3.add("Child3")
967
+
968
+ parent.add(child1)
969
+ parent.add(child2)
970
+ parent.add(child3)
971
+ grandparent.add(parent)
972
+
973
+ const chunks = grandparent.gatherWithInheritedStyle()
974
+
975
+ expect(chunks).toHaveLength(3)
976
+
977
+ // Child1: inherits link from grandparent
978
+ expect(chunks[0].text).toBe("Child1")
979
+ expect(chunks[0].link?.url).toBe("https://grandparent.com")
980
+ expect(chunks[0].fg).toEqual(RGBA.fromInts(0, 255, 0, 255))
981
+
982
+ // Child2: overrides link
983
+ expect(chunks[1].text).toBe("Child2")
984
+ expect(chunks[1].link?.url).toBe("https://child2.com")
985
+
986
+ // Child3: inherits link from grandparent
987
+ expect(chunks[2].text).toBe("Child3")
988
+ expect(chunks[2].link?.url).toBe("https://grandparent.com")
989
+ })
990
+ })
991
+
992
+ describe("Edge Cases and Error Handling", () => {
993
+ it("should handle empty strings", () => {
994
+ const node = new TextNodeRenderable({})
995
+
996
+ node.add("")
997
+ node.add(" ")
998
+
999
+ const chunks = node.gatherWithInheritedStyle()
1000
+ expect(chunks).toHaveLength(2)
1001
+ expect(chunks[0].text).toBe("")
1002
+ expect(chunks[1].text).toBe(" ")
1003
+ })
1004
+
1005
+ it("should handle nested empty TextNodes", () => {
1006
+ const parent = new TextNodeRenderable({})
1007
+ const child = new TextNodeRenderable({})
1008
+
1009
+ parent.add(child)
1010
+
1011
+ const chunks = parent.gatherWithInheritedStyle()
1012
+ expect(chunks).toHaveLength(0)
1013
+ })
1014
+
1015
+ it("should handle multiple operations in sequence", () => {
1016
+ const node = new TextNodeRenderable({})
1017
+
1018
+ // Add multiple items
1019
+ for (let i = 0; i < 5; i++) {
1020
+ node.add(`Item ${i}`)
1021
+ }
1022
+
1023
+ expect(node.children).toHaveLength(5)
1024
+
1025
+ // Clear and verify
1026
+ node.clear()
1027
+ expect(node.children).toHaveLength(0)
1028
+ })
1029
+
1030
+ it("should efficiently calculate positions for large trees", () => {
1031
+ const root = new TextNodeRenderable({})
1032
+
1033
+ // Add many children to test position calculation efficiency
1034
+ for (let i = 0; i < 10; i++) {
1035
+ const child = new TextNodeRenderable({})
1036
+ for (let j = 0; j < 5; j++) {
1037
+ child.add(`Child ${i}-${j}`)
1038
+ }
1039
+ root.add(child)
1040
+ }
1041
+
1042
+ // Insert before the 5th child - should be efficient
1043
+ const fifthChild = root.children[4] as TextNodeRenderable
1044
+ const insertChild = new TextNodeRenderable({})
1045
+ insertChild.add("Inserted")
1046
+
1047
+ const startTime = performance.now()
1048
+ root.insertBefore(insertChild, fifthChild)
1049
+ const endTime = performance.now()
1050
+
1051
+ // Should complete quickly (less than 1ms for this small tree)
1052
+ expect(endTime - startTime).toBeLessThan(1)
1053
+
1054
+ // Verify correct position
1055
+ expect(root.children.indexOf(insertChild)).toBe(4)
1056
+ })
1057
+ })
1058
+ })