@fairyhunter13/opentui-core 0.1.91 → 0.1.94

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 (570) hide show
  1. package/3d/SpriteResourceManager.d.ts +74 -0
  2. package/3d/SpriteUtils.d.ts +13 -0
  3. package/3d/TextureUtils.d.ts +24 -0
  4. package/3d/ThreeRenderable.d.ts +40 -0
  5. package/3d/WGPURenderer.d.ts +61 -0
  6. package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
  7. package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
  8. package/3d/animation/SpriteAnimator.d.ts +124 -0
  9. package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
  10. package/3d/canvas.d.ts +44 -0
  11. package/3d/index.d.ts +12 -0
  12. package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
  13. package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
  14. package/3d/physics/physics-interface.d.ts +27 -0
  15. package/3d.d.ts +2 -0
  16. package/3d.js +34042 -0
  17. package/3d.js.map +155 -0
  18. package/LICENSE +21 -0
  19. package/NativeSpanFeed.d.ts +41 -0
  20. package/Renderable.d.ts +334 -0
  21. package/animation/Timeline.d.ts +126 -0
  22. package/ansi.d.ts +13 -0
  23. package/buffer.d.ts +107 -0
  24. package/console.d.ts +143 -0
  25. package/edit-buffer.d.ts +98 -0
  26. package/editor-view.d.ts +73 -0
  27. package/index-e6ec7apq.js +18415 -0
  28. package/index-e6ec7apq.js.map +64 -0
  29. package/index-h066zmrb.js +12619 -0
  30. package/index-h066zmrb.js.map +43 -0
  31. package/index-ynzawt3n.js +113 -0
  32. package/index-ynzawt3n.js.map +10 -0
  33. package/index.d.ts +21 -0
  34. package/index.js +430 -0
  35. package/index.js.map +9 -0
  36. package/lib/KeyHandler.d.ts +61 -0
  37. package/lib/RGBA.d.ts +25 -0
  38. package/lib/ascii.font.d.ts +508 -0
  39. package/lib/border.d.ts +49 -0
  40. package/lib/bunfs.d.ts +7 -0
  41. package/lib/clipboard.d.ts +17 -0
  42. package/lib/clock.d.ts +15 -0
  43. package/lib/data-paths.d.ts +26 -0
  44. package/lib/debounce.d.ts +42 -0
  45. package/lib/detect-links.d.ts +6 -0
  46. package/lib/env.d.ts +42 -0
  47. package/lib/extmarks-history.d.ts +17 -0
  48. package/lib/extmarks.d.ts +89 -0
  49. package/lib/hast-styled-text.d.ts +17 -0
  50. package/lib/index.d.ts +21 -0
  51. package/lib/keymapping.d.ts +25 -0
  52. package/lib/objects-in-viewport.d.ts +24 -0
  53. package/lib/output.capture.d.ts +24 -0
  54. package/lib/parse.keypress-kitty.d.ts +2 -0
  55. package/lib/parse.keypress.d.ts +26 -0
  56. package/lib/parse.mouse.d.ts +30 -0
  57. package/lib/paste.d.ts +7 -0
  58. package/lib/queue.d.ts +15 -0
  59. package/lib/renderable.validations.d.ts +12 -0
  60. package/lib/scroll-acceleration.d.ts +43 -0
  61. package/lib/selection.d.ts +63 -0
  62. package/lib/singleton.d.ts +7 -0
  63. package/lib/stdin-parser.d.ts +76 -0
  64. package/lib/styled-text.d.ts +63 -0
  65. package/lib/terminal-capability-detection.d.ts +30 -0
  66. package/lib/terminal-palette.d.ts +50 -0
  67. package/lib/tree-sitter/assets/update.d.ts +11 -0
  68. package/lib/tree-sitter/client.d.ts +47 -0
  69. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  70. package/lib/tree-sitter/download-utils.d.ts +21 -0
  71. package/lib/tree-sitter/index.d.ts +8 -0
  72. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  73. package/lib/tree-sitter/parsers-config.d.ts +38 -0
  74. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  75. package/lib/tree-sitter/types.d.ts +81 -0
  76. package/lib/tree-sitter-styled-text.d.ts +14 -0
  77. package/lib/validate-dir-name.d.ts +1 -0
  78. package/lib/yoga.options.d.ts +32 -0
  79. package/package.json +51 -63
  80. package/parser.worker.js +869 -0
  81. package/parser.worker.js.map +12 -0
  82. package/plugins/core-slot.d.ts +72 -0
  83. package/plugins/registry.d.ts +38 -0
  84. package/plugins/types.d.ts +34 -0
  85. package/post/filters.d.ts +105 -0
  86. package/renderables/ASCIIFont.d.ts +52 -0
  87. package/renderables/Box.d.ts +72 -0
  88. package/renderables/Code.d.ts +78 -0
  89. package/renderables/Diff.d.ts +142 -0
  90. package/renderables/EditBufferRenderable.d.ts +162 -0
  91. package/renderables/FrameBuffer.d.ts +16 -0
  92. package/renderables/Input.d.ts +67 -0
  93. package/renderables/LineNumberRenderable.d.ts +74 -0
  94. package/renderables/Markdown.d.ts +173 -0
  95. package/renderables/ScrollBar.d.ts +77 -0
  96. package/renderables/ScrollBox.d.ts +124 -0
  97. package/renderables/Select.d.ts +115 -0
  98. package/renderables/Slider.d.ts +44 -0
  99. package/renderables/TabSelect.d.ts +96 -0
  100. package/renderables/Text.d.ts +36 -0
  101. package/renderables/TextBufferRenderable.d.ts +105 -0
  102. package/renderables/TextNode.d.ts +91 -0
  103. package/renderables/TextTable.d.ts +140 -0
  104. package/renderables/Textarea.d.ts +114 -0
  105. package/renderables/TimeToFirstDraw.d.ts +24 -0
  106. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  107. package/renderables/composition/VRenderable.d.ts +16 -0
  108. package/renderables/composition/constructs.d.ts +35 -0
  109. package/renderables/composition/vnode.d.ts +46 -0
  110. package/renderables/index.d.ts +22 -0
  111. package/renderables/markdown-parser.d.ts +10 -0
  112. package/renderer.d.ts +388 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +29 -0
  115. package/runtime-plugin-support.js.map +10 -0
  116. package/runtime-plugin.d.ts +11 -0
  117. package/runtime-plugin.js +16 -0
  118. package/runtime-plugin.js.map +9 -0
  119. package/syntax-style.d.ts +54 -0
  120. package/testing/manual-clock.d.ts +16 -0
  121. package/testing/mock-keys.d.ts +81 -0
  122. package/testing/mock-mouse.d.ts +38 -0
  123. package/testing/mock-tree-sitter-client.d.ts +23 -0
  124. package/testing/spy.d.ts +7 -0
  125. package/testing/test-recorder.d.ts +61 -0
  126. package/testing/test-renderer.d.ts +23 -0
  127. package/testing.d.ts +6 -0
  128. package/testing.js +675 -0
  129. package/testing.js.map +15 -0
  130. package/text-buffer-view.d.ts +42 -0
  131. package/text-buffer.d.ts +67 -0
  132. package/types.d.ts +131 -0
  133. package/utils.d.ts +14 -0
  134. package/zig-structs.d.ts +155 -0
  135. package/zig.d.ts +351 -0
  136. package/dev/keypress-debug-renderer.ts +0 -148
  137. package/dev/keypress-debug.ts +0 -43
  138. package/dev/print-env-vars.ts +0 -32
  139. package/dev/test-tmux-graphics-334.sh +0 -68
  140. package/dev/thai-debug-test.ts +0 -68
  141. package/docs/development.md +0 -141
  142. package/docs/env-vars.md +0 -140
  143. package/docs/getting-started.md +0 -353
  144. package/docs/renderables-vs-constructs.md +0 -159
  145. package/docs/tree-sitter.md +0 -311
  146. package/scripts/build.ts +0 -400
  147. package/scripts/publish.ts +0 -60
  148. package/src/3d/SpriteResourceManager.ts +0 -286
  149. package/src/3d/SpriteUtils.ts +0 -71
  150. package/src/3d/TextureUtils.ts +0 -196
  151. package/src/3d/ThreeRenderable.ts +0 -197
  152. package/src/3d/WGPURenderer.ts +0 -294
  153. package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
  154. package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
  155. package/src/3d/animation/SpriteAnimator.ts +0 -633
  156. package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
  157. package/src/3d/canvas.ts +0 -464
  158. package/src/3d/index.ts +0 -12
  159. package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
  160. package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
  161. package/src/3d/physics/physics-interface.ts +0 -31
  162. package/src/3d/shaders/supersampling.wgsl +0 -201
  163. package/src/3d.ts +0 -3
  164. package/src/NativeSpanFeed.ts +0 -300
  165. package/src/Renderable.ts +0 -1698
  166. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  167. package/src/animation/Timeline.test.ts +0 -2709
  168. package/src/animation/Timeline.ts +0 -598
  169. package/src/ansi.ts +0 -18
  170. package/src/benchmark/latest-all-bench-run.json +0 -707
  171. package/src/benchmark/latest-async-bench-run.json +0 -336
  172. package/src/benchmark/latest-default-bench-run.json +0 -657
  173. package/src/benchmark/latest-large-bench-run.json +0 -707
  174. package/src/benchmark/latest-quick-bench-run.json +0 -207
  175. package/src/benchmark/markdown-benchmark.ts +0 -1804
  176. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  177. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  178. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  179. package/src/benchmark/native-span-feed-compare.ts +0 -280
  180. package/src/benchmark/renderer-benchmark.ts +0 -754
  181. package/src/benchmark/text-table-benchmark.ts +0 -947
  182. package/src/buffer.test.ts +0 -291
  183. package/src/buffer.ts +0 -519
  184. package/src/console.test.ts +0 -612
  185. package/src/console.ts +0 -1255
  186. package/src/edit-buffer.test.ts +0 -1769
  187. package/src/edit-buffer.ts +0 -411
  188. package/src/editor-view.test.ts +0 -1032
  189. package/src/editor-view.ts +0 -284
  190. package/src/examples/ascii-font-selection-demo.ts +0 -245
  191. package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
  192. package/src/examples/assets/concrete.png +0 -0
  193. package/src/examples/assets/crate.png +0 -0
  194. package/src/examples/assets/crate_emissive.png +0 -0
  195. package/src/examples/assets/forrest_background.png +0 -0
  196. package/src/examples/assets/hast-example.json +0 -1018
  197. package/src/examples/assets/heart.png +0 -0
  198. package/src/examples/assets/main_char_heavy_attack.png +0 -0
  199. package/src/examples/assets/main_char_idle.png +0 -0
  200. package/src/examples/assets/main_char_jump_end.png +0 -0
  201. package/src/examples/assets/main_char_jump_landing.png +0 -0
  202. package/src/examples/assets/main_char_jump_start.png +0 -0
  203. package/src/examples/assets/main_char_run_loop.png +0 -0
  204. package/src/examples/assets/roughness_map.jpg +0 -0
  205. package/src/examples/build.ts +0 -115
  206. package/src/examples/code-demo.ts +0 -584
  207. package/src/examples/console-demo.ts +0 -358
  208. package/src/examples/core-plugin-slots-demo.ts +0 -759
  209. package/src/examples/diff-demo.ts +0 -699
  210. package/src/examples/draggable-three-demo.ts +0 -259
  211. package/src/examples/editor-demo.ts +0 -322
  212. package/src/examples/extmarks-demo.ts +0 -204
  213. package/src/examples/focus-restore-demo.ts +0 -310
  214. package/src/examples/fonts.ts +0 -245
  215. package/src/examples/fractal-shader-demo.ts +0 -268
  216. package/src/examples/framebuffer-demo.ts +0 -674
  217. package/src/examples/full-unicode-demo.ts +0 -181
  218. package/src/examples/golden-star-demo.ts +0 -933
  219. package/src/examples/grayscale-buffer-demo.ts +0 -249
  220. package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
  221. package/src/examples/index.ts +0 -925
  222. package/src/examples/input-demo.ts +0 -377
  223. package/src/examples/input-select-layout-demo.ts +0 -425
  224. package/src/examples/install.sh +0 -143
  225. package/src/examples/keypress-debug-demo.ts +0 -452
  226. package/src/examples/lib/HexList.ts +0 -122
  227. package/src/examples/lib/PaletteGrid.ts +0 -125
  228. package/src/examples/lib/standalone-keys.ts +0 -25
  229. package/src/examples/lib/tab-controller.ts +0 -243
  230. package/src/examples/lights-phong-demo.ts +0 -290
  231. package/src/examples/link-demo.ts +0 -220
  232. package/src/examples/live-state-demo.ts +0 -480
  233. package/src/examples/markdown-demo.ts +0 -620
  234. package/src/examples/mouse-interaction-demo.ts +0 -428
  235. package/src/examples/nested-zindex-demo.ts +0 -357
  236. package/src/examples/opacity-example.ts +0 -235
  237. package/src/examples/opentui-demo.ts +0 -1057
  238. package/src/examples/physx-planck-2d-demo.ts +0 -507
  239. package/src/examples/physx-rapier-2d-demo.ts +0 -526
  240. package/src/examples/relative-positioning-demo.ts +0 -323
  241. package/src/examples/scroll-example.ts +0 -214
  242. package/src/examples/scrollbox-mouse-test.ts +0 -112
  243. package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
  244. package/src/examples/select-demo.ts +0 -237
  245. package/src/examples/shader-cube-demo.ts +0 -772
  246. package/src/examples/simple-layout-example.ts +0 -591
  247. package/src/examples/slider-demo.ts +0 -617
  248. package/src/examples/split-mode-demo.ts +0 -445
  249. package/src/examples/sprite-animation-demo.ts +0 -443
  250. package/src/examples/sprite-particle-generator-demo.ts +0 -486
  251. package/src/examples/static-sprite-demo.ts +0 -193
  252. package/src/examples/sticky-scroll-example.ts +0 -308
  253. package/src/examples/styled-text-demo.ts +0 -282
  254. package/src/examples/tab-select-demo.ts +0 -219
  255. package/src/examples/terminal-title.ts +0 -29
  256. package/src/examples/terminal.ts +0 -305
  257. package/src/examples/text-node-demo.ts +0 -416
  258. package/src/examples/text-selection-demo.ts +0 -377
  259. package/src/examples/text-table-demo.ts +0 -503
  260. package/src/examples/text-truncation-demo.ts +0 -481
  261. package/src/examples/text-wrap.ts +0 -757
  262. package/src/examples/texture-loading-demo.ts +0 -259
  263. package/src/examples/timeline-example.ts +0 -670
  264. package/src/examples/transparency-demo.ts +0 -241
  265. package/src/examples/vnode-composition-demo.ts +0 -404
  266. package/src/index.ts +0 -22
  267. package/src/lib/KeyHandler.integration.test.ts +0 -292
  268. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  269. package/src/lib/KeyHandler.test.ts +0 -662
  270. package/src/lib/KeyHandler.ts +0 -222
  271. package/src/lib/RGBA.test.ts +0 -984
  272. package/src/lib/RGBA.ts +0 -204
  273. package/src/lib/ascii.font.ts +0 -330
  274. package/src/lib/border.test.ts +0 -83
  275. package/src/lib/border.ts +0 -168
  276. package/src/lib/bunfs.test.ts +0 -27
  277. package/src/lib/bunfs.ts +0 -18
  278. package/src/lib/clipboard.test.ts +0 -41
  279. package/src/lib/clipboard.ts +0 -47
  280. package/src/lib/clock.ts +0 -31
  281. package/src/lib/data-paths.test.ts +0 -133
  282. package/src/lib/data-paths.ts +0 -109
  283. package/src/lib/debounce.ts +0 -106
  284. package/src/lib/detect-links.test.ts +0 -98
  285. package/src/lib/detect-links.ts +0 -56
  286. package/src/lib/env.test.ts +0 -228
  287. package/src/lib/env.ts +0 -209
  288. package/src/lib/extmarks-history.ts +0 -51
  289. package/src/lib/extmarks-multiwidth.test.ts +0 -322
  290. package/src/lib/extmarks.test.ts +0 -3457
  291. package/src/lib/extmarks.ts +0 -843
  292. package/src/lib/fonts/block.json +0 -405
  293. package/src/lib/fonts/grid.json +0 -265
  294. package/src/lib/fonts/huge.json +0 -741
  295. package/src/lib/fonts/pallet.json +0 -314
  296. package/src/lib/fonts/shade.json +0 -591
  297. package/src/lib/fonts/slick.json +0 -321
  298. package/src/lib/fonts/tiny.json +0 -69
  299. package/src/lib/hast-styled-text.ts +0 -59
  300. package/src/lib/index.ts +0 -21
  301. package/src/lib/keymapping.test.ts +0 -280
  302. package/src/lib/keymapping.ts +0 -87
  303. package/src/lib/objects-in-viewport.test.ts +0 -787
  304. package/src/lib/objects-in-viewport.ts +0 -153
  305. package/src/lib/output.capture.ts +0 -58
  306. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
  307. package/src/lib/parse.keypress-kitty.test.ts +0 -663
  308. package/src/lib/parse.keypress-kitty.ts +0 -439
  309. package/src/lib/parse.keypress.test.ts +0 -1849
  310. package/src/lib/parse.keypress.ts +0 -397
  311. package/src/lib/parse.mouse.test.ts +0 -552
  312. package/src/lib/parse.mouse.ts +0 -232
  313. package/src/lib/paste.ts +0 -16
  314. package/src/lib/queue.ts +0 -65
  315. package/src/lib/renderable.validations.test.ts +0 -87
  316. package/src/lib/renderable.validations.ts +0 -83
  317. package/src/lib/scroll-acceleration.ts +0 -98
  318. package/src/lib/selection.ts +0 -240
  319. package/src/lib/singleton.ts +0 -28
  320. package/src/lib/stdin-parser.test.ts +0 -1676
  321. package/src/lib/stdin-parser.ts +0 -1248
  322. package/src/lib/styled-text.ts +0 -178
  323. package/src/lib/terminal-capability-detection.test.ts +0 -202
  324. package/src/lib/terminal-capability-detection.ts +0 -79
  325. package/src/lib/terminal-palette.test.ts +0 -878
  326. package/src/lib/terminal-palette.ts +0 -383
  327. package/src/lib/tree-sitter/assets/README.md +0 -118
  328. package/src/lib/tree-sitter/assets/update.ts +0 -331
  329. package/src/lib/tree-sitter/assets.d.ts +0 -9
  330. package/src/lib/tree-sitter/cache.test.ts +0 -270
  331. package/src/lib/tree-sitter/client.test.ts +0 -1061
  332. package/src/lib/tree-sitter/client.ts +0 -615
  333. package/src/lib/tree-sitter/default-parsers.ts +0 -80
  334. package/src/lib/tree-sitter/download-utils.ts +0 -148
  335. package/src/lib/tree-sitter/index.ts +0 -28
  336. package/src/lib/tree-sitter/parser.worker.ts +0 -1001
  337. package/src/lib/tree-sitter/parsers-config.ts +0 -75
  338. package/src/lib/tree-sitter/resolve-ft.ts +0 -62
  339. package/src/lib/tree-sitter/types.ts +0 -81
  340. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  341. package/src/lib/tree-sitter-styled-text.ts +0 -306
  342. package/src/lib/validate-dir-name.ts +0 -55
  343. package/src/lib/yoga.options.test.ts +0 -628
  344. package/src/lib/yoga.options.ts +0 -346
  345. package/src/plugins/core-slot.ts +0 -579
  346. package/src/plugins/registry.ts +0 -377
  347. package/src/plugins/types.ts +0 -46
  348. package/src/post/filters.ts +0 -888
  349. package/src/renderables/ASCIIFont.ts +0 -219
  350. package/src/renderables/Box.test.ts +0 -160
  351. package/src/renderables/Box.ts +0 -295
  352. package/src/renderables/Code.test.ts +0 -2062
  353. package/src/renderables/Code.ts +0 -357
  354. package/src/renderables/Diff.regression.test.ts +0 -226
  355. package/src/renderables/Diff.test.ts +0 -3027
  356. package/src/renderables/Diff.ts +0 -1209
  357. package/src/renderables/EditBufferRenderable.ts +0 -764
  358. package/src/renderables/FrameBuffer.ts +0 -47
  359. package/src/renderables/Input.test.ts +0 -1228
  360. package/src/renderables/Input.ts +0 -245
  361. package/src/renderables/LineNumberRenderable.ts +0 -675
  362. package/src/renderables/Markdown.ts +0 -1106
  363. package/src/renderables/ScrollBar.ts +0 -422
  364. package/src/renderables/ScrollBox.ts +0 -883
  365. package/src/renderables/Select.test.ts +0 -1010
  366. package/src/renderables/Select.ts +0 -523
  367. package/src/renderables/Slider.test.ts +0 -456
  368. package/src/renderables/Slider.ts +0 -347
  369. package/src/renderables/TabSelect.test.ts +0 -197
  370. package/src/renderables/TabSelect.ts +0 -455
  371. package/src/renderables/Text.selection-buffer.test.ts +0 -123
  372. package/src/renderables/Text.test.ts +0 -2660
  373. package/src/renderables/Text.ts +0 -147
  374. package/src/renderables/TextBufferRenderable.ts +0 -518
  375. package/src/renderables/TextNode.test.ts +0 -1058
  376. package/src/renderables/TextNode.ts +0 -325
  377. package/src/renderables/TextTable.test.ts +0 -1421
  378. package/src/renderables/TextTable.ts +0 -1344
  379. package/src/renderables/Textarea.ts +0 -732
  380. package/src/renderables/TimeToFirstDraw.ts +0 -89
  381. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  382. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  383. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  384. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  385. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  386. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
  387. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1787
  388. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  389. package/src/renderables/__tests__/Markdown.test.ts +0 -2287
  390. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  391. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
  392. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  393. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
  394. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  395. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  396. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  397. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
  398. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  399. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1864
  400. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  401. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
  402. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  403. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  404. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  405. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  406. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  407. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  408. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  409. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  410. package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
  411. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  412. package/src/renderables/composition/README.md +0 -8
  413. package/src/renderables/composition/VRenderable.ts +0 -32
  414. package/src/renderables/composition/constructs.ts +0 -127
  415. package/src/renderables/composition/vnode.ts +0 -289
  416. package/src/renderables/index.ts +0 -22
  417. package/src/renderables/markdown-parser.ts +0 -66
  418. package/src/renderer.ts +0 -2363
  419. package/src/runtime-plugin-support.ts +0 -39
  420. package/src/runtime-plugin.ts +0 -144
  421. package/src/syntax-style.test.ts +0 -841
  422. package/src/syntax-style.ts +0 -264
  423. package/src/testing/README.md +0 -210
  424. package/src/testing/capture-spans.test.ts +0 -194
  425. package/src/testing/integration.test.ts +0 -276
  426. package/src/testing/manual-clock.ts +0 -106
  427. package/src/testing/mock-keys.test.ts +0 -1356
  428. package/src/testing/mock-keys.ts +0 -449
  429. package/src/testing/mock-mouse.test.ts +0 -218
  430. package/src/testing/mock-mouse.ts +0 -247
  431. package/src/testing/mock-tree-sitter-client.ts +0 -73
  432. package/src/testing/spy.ts +0 -13
  433. package/src/testing/test-recorder.test.ts +0 -415
  434. package/src/testing/test-recorder.ts +0 -145
  435. package/src/testing/test-renderer.ts +0 -116
  436. package/src/testing.ts +0 -7
  437. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  438. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  439. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  440. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  441. package/src/tests/allocator-stats.test.ts +0 -38
  442. package/src/tests/destroy-during-render.test.ts +0 -200
  443. package/src/tests/hover-cursor.test.ts +0 -98
  444. package/src/tests/native-span-feed-async.test.ts +0 -173
  445. package/src/tests/native-span-feed-close.test.ts +0 -120
  446. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  447. package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
  448. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  449. package/src/tests/opacity.test.ts +0 -123
  450. package/src/tests/renderable.snapshot.test.ts +0 -524
  451. package/src/tests/renderable.test.ts +0 -1281
  452. package/src/tests/renderer.console-startup.test.ts +0 -65
  453. package/src/tests/renderer.control.test.ts +0 -364
  454. package/src/tests/renderer.core-slot-binding.test.ts +0 -952
  455. package/src/tests/renderer.cursor.test.ts +0 -26
  456. package/src/tests/renderer.destroy-during-render.test.ts +0 -110
  457. package/src/tests/renderer.focus-restore.test.ts +0 -228
  458. package/src/tests/renderer.focus.test.ts +0 -251
  459. package/src/tests/renderer.idle.test.ts +0 -219
  460. package/src/tests/renderer.input.test.ts +0 -2145
  461. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  462. package/src/tests/renderer.mouse.test.ts +0 -1269
  463. package/src/tests/renderer.palette.test.ts +0 -629
  464. package/src/tests/renderer.selection.test.ts +0 -49
  465. package/src/tests/renderer.slot-registry.test.ts +0 -649
  466. package/src/tests/renderer.useMouse.test.ts +0 -50
  467. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  468. package/src/tests/runtime-plugin-support.test.ts +0 -28
  469. package/src/tests/runtime-plugin.fixture.ts +0 -40
  470. package/src/tests/runtime-plugin.test.ts +0 -190
  471. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  472. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  473. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  474. package/src/tests/scrollbox.test.ts +0 -1530
  475. package/src/tests/wrap-resize-perf.test.ts +0 -229
  476. package/src/tests/yoga-setters.test.ts +0 -921
  477. package/src/text-buffer-view.test.ts +0 -705
  478. package/src/text-buffer-view.ts +0 -189
  479. package/src/text-buffer.test.ts +0 -347
  480. package/src/text-buffer.ts +0 -250
  481. package/src/types.ts +0 -152
  482. package/src/utils.ts +0 -88
  483. package/src/zig/ansi.zig +0 -268
  484. package/src/zig/bench/README.md +0 -50
  485. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
  486. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  487. package/src/zig/bench/native-span-feed_bench.zig +0 -100
  488. package/src/zig/bench/rope-markers_bench.zig +0 -713
  489. package/src/zig/bench/rope_bench.zig +0 -514
  490. package/src/zig/bench/styled-text_bench.zig +0 -470
  491. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  492. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  493. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
  494. package/src/zig/bench/utf8_bench.zig +0 -799
  495. package/src/zig/bench-utils.zig +0 -431
  496. package/src/zig/bench.zig +0 -217
  497. package/src/zig/buffer.zig +0 -2223
  498. package/src/zig/build.zig +0 -289
  499. package/src/zig/build.zig.zon +0 -16
  500. package/src/zig/edit-buffer.zig +0 -825
  501. package/src/zig/editor-view.zig +0 -802
  502. package/src/zig/event-bus.zig +0 -13
  503. package/src/zig/event-emitter.zig +0 -65
  504. package/src/zig/file-logger.zig +0 -92
  505. package/src/zig/grapheme.zig +0 -599
  506. package/src/zig/lib.zig +0 -1834
  507. package/src/zig/link.zig +0 -333
  508. package/src/zig/logger.zig +0 -43
  509. package/src/zig/mem-registry.zig +0 -125
  510. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  511. package/src/zig/native-span-feed.zig +0 -708
  512. package/src/zig/renderer.zig +0 -1386
  513. package/src/zig/rope.zig +0 -1220
  514. package/src/zig/syntax-style.zig +0 -161
  515. package/src/zig/terminal.zig +0 -975
  516. package/src/zig/test.zig +0 -70
  517. package/src/zig/tests/README.md +0 -18
  518. package/src/zig/tests/buffer_test.zig +0 -2526
  519. package/src/zig/tests/edit-buffer-history_test.zig +0 -271
  520. package/src/zig/tests/edit-buffer_test.zig +0 -1689
  521. package/src/zig/tests/editor-view_test.zig +0 -3299
  522. package/src/zig/tests/event-emitter_test.zig +0 -249
  523. package/src/zig/tests/grapheme_test.zig +0 -1304
  524. package/src/zig/tests/link_test.zig +0 -190
  525. package/src/zig/tests/mem-registry_test.zig +0 -473
  526. package/src/zig/tests/memory_leak_regression_test.zig +0 -159
  527. package/src/zig/tests/native-span-feed_test.zig +0 -1264
  528. package/src/zig/tests/renderer_test.zig +0 -1010
  529. package/src/zig/tests/rope-nested_test.zig +0 -712
  530. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  531. package/src/zig/tests/rope_test.zig +0 -2362
  532. package/src/zig/tests/segment-merge.test.zig +0 -148
  533. package/src/zig/tests/syntax-style_test.zig +0 -557
  534. package/src/zig/tests/terminal_test.zig +0 -719
  535. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
  536. package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
  537. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  538. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  539. package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
  540. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  541. package/src/zig/tests/text-buffer-view_test.zig +0 -3649
  542. package/src/zig/tests/text-buffer_test.zig +0 -2191
  543. package/src/zig/tests/unicode-width-map.zon +0 -3909
  544. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  545. package/src/zig/tests/utf8_test.zig +0 -4057
  546. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  547. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  548. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  549. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  550. package/src/zig/text-buffer-iterators.zig +0 -499
  551. package/src/zig/text-buffer-segment.zig +0 -404
  552. package/src/zig/text-buffer-view.zig +0 -1371
  553. package/src/zig/text-buffer.zig +0 -1180
  554. package/src/zig/utf8.zig +0 -1948
  555. package/src/zig/utils.zig +0 -9
  556. package/src/zig-structs.ts +0 -261
  557. package/src/zig.ts +0 -3843
  558. package/tsconfig.build.json +0 -22
  559. package/tsconfig.json +0 -28
  560. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  561. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  562. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  563. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  564. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  565. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  566. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  567. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  568. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  569. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  570. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,1344 +0,0 @@
1
- import { MeasureMode } from "yoga-layout"
2
- import { type RenderableOptions, Renderable } from "../Renderable"
3
- import type { OptimizedBuffer } from "../buffer"
4
- import { type BorderStyle, BorderCharArrays, parseBorderStyle } from "../lib/border"
5
- import { convertGlobalToLocalSelection, type Selection, type LocalSelectionBounds } from "../lib/selection"
6
- import { StyledText, stringToStyledText } from "../lib/styled-text"
7
- import { RGBA, parseColor, type ColorInput } from "../lib/RGBA"
8
- import { SyntaxStyle } from "../syntax-style"
9
- import { type TextChunk, TextBuffer } from "../text-buffer"
10
- import { TextBufferView } from "../text-buffer-view"
11
- import type { RenderContext } from "../types"
12
-
13
- // Large sentinel height for text measurement. The Zig measure path currently
14
- // ignores height, but we pass an effectively unbounded value so if height-aware
15
- // measuring is introduced later, table sizing remains stable.
16
- const MEASURE_HEIGHT = 10_000
17
-
18
- export type TextTableCellContent = TextChunk[] | null | undefined
19
- export type TextTableContent = TextTableCellContent[][]
20
- export type TextTableColumnWidthMode = "content" | "full"
21
- export type TextTableColumnFitter = "proportional" | "balanced"
22
-
23
- interface ResolvedTableBorderLayout {
24
- left: boolean
25
- right: boolean
26
- top: boolean
27
- bottom: boolean
28
- innerVertical: boolean
29
- innerHorizontal: boolean
30
- }
31
-
32
- interface TextTableCellState {
33
- textBuffer: TextBuffer
34
- textBufferView: TextBufferView
35
- syntaxStyle: SyntaxStyle
36
- }
37
-
38
- interface TextTableLayout {
39
- columnWidths: number[]
40
- rowHeights: number[]
41
- columnOffsets: number[]
42
- rowOffsets: number[]
43
- columnOffsetsI32: Int32Array
44
- rowOffsetsI32: Int32Array
45
- tableWidth: number
46
- tableHeight: number
47
- }
48
-
49
- interface CellPosition {
50
- rowIdx: number
51
- colIdx: number
52
- }
53
-
54
- interface RowRange {
55
- firstRow: number
56
- lastRow: number
57
- }
58
-
59
- type TableSelectionMode = "single-cell" | "column-locked" | "grid"
60
-
61
- interface SelectionResolution {
62
- mode: TableSelectionMode
63
- anchorCell: CellPosition | null
64
- anchorColumn: number | null
65
- }
66
-
67
- interface CellSelectionCoords {
68
- anchorX: number
69
- anchorY: number
70
- focusX: number
71
- focusY: number
72
- }
73
-
74
- export interface TextTableOptions extends RenderableOptions<TextTableRenderable> {
75
- content?: TextTableContent
76
- wrapMode?: "none" | "char" | "word"
77
- columnWidthMode?: TextTableColumnWidthMode
78
- columnFitter?: TextTableColumnFitter
79
- cellPadding?: number
80
- showBorders?: boolean
81
- border?: boolean
82
- outerBorder?: boolean
83
- selectable?: boolean
84
- selectionBg?: ColorInput
85
- selectionFg?: ColorInput
86
- borderStyle?: BorderStyle
87
- borderColor?: ColorInput
88
- borderBackgroundColor?: ColorInput
89
- backgroundColor?: ColorInput
90
- fg?: ColorInput
91
- bg?: ColorInput
92
- attributes?: number
93
- }
94
-
95
- export class TextTableRenderable extends Renderable {
96
- private _content: TextTableContent
97
- private _wrapMode: "none" | "char" | "word"
98
- private _columnWidthMode: TextTableColumnWidthMode
99
- private _columnFitter: TextTableColumnFitter
100
- private _cellPadding: number
101
- private _showBorders: boolean
102
- private _border: boolean
103
- private _outerBorder: boolean
104
- private _hasExplicitOuterBorder: boolean
105
- private _borderStyle: BorderStyle
106
- private _borderColor: RGBA
107
- private _borderBackgroundColor: RGBA
108
- private _backgroundColor: RGBA
109
- private _defaultFg: RGBA
110
- private _defaultBg: RGBA
111
- private _defaultAttributes: number
112
- private _selectionBg: RGBA | undefined
113
- private _selectionFg: RGBA | undefined
114
- private _lastLocalSelection: LocalSelectionBounds | null = null
115
- private _lastSelectionMode: TableSelectionMode | null = null
116
-
117
- private _cells: TextTableCellState[][] = []
118
- private _prevCellContent: TextTableCellContent[][] = []
119
- private _rowCount: number = 0
120
- private _columnCount: number = 0
121
-
122
- private _layout: TextTableLayout = this.createEmptyLayout()
123
- private _layoutDirty: boolean = true
124
- private _rasterDirty: boolean = true
125
-
126
- private _cachedMeasureLayout: TextTableLayout | null = null
127
- private _cachedMeasureWidth: number | undefined = undefined
128
-
129
- private readonly _defaultOptions = {
130
- content: [] as TextTableContent,
131
- wrapMode: "word" as "none" | "char" | "word",
132
- columnWidthMode: "full" as TextTableColumnWidthMode,
133
- columnFitter: "proportional" as TextTableColumnFitter,
134
- cellPadding: 0,
135
- showBorders: true,
136
- border: true,
137
- outerBorder: true,
138
- selectable: true,
139
- selectionBg: undefined as ColorInput | undefined,
140
- selectionFg: undefined as ColorInput | undefined,
141
- borderStyle: "single" as BorderStyle,
142
- borderColor: "#FFFFFF",
143
- borderBackgroundColor: "transparent",
144
- backgroundColor: "transparent",
145
- fg: "#FFFFFF",
146
- bg: "transparent",
147
- attributes: 0,
148
- } satisfies Partial<TextTableOptions>
149
-
150
- constructor(ctx: RenderContext, options: TextTableOptions = {}) {
151
- super(ctx, { ...options, flexShrink: options.flexShrink ?? 0, buffered: true })
152
-
153
- this._content = options.content ?? this._defaultOptions.content
154
- this._wrapMode = options.wrapMode ?? this._defaultOptions.wrapMode
155
- this._columnWidthMode = options.columnWidthMode ?? this._defaultOptions.columnWidthMode
156
- this._columnFitter = this.resolveColumnFitter(options.columnFitter)
157
- this._cellPadding = this.resolveCellPadding(options.cellPadding)
158
- this._showBorders = options.showBorders ?? this._defaultOptions.showBorders
159
- this._border = options.border ?? this._defaultOptions.border
160
- this._hasExplicitOuterBorder = options.outerBorder !== undefined
161
- this._outerBorder = options.outerBorder ?? this._border
162
- this.selectable = options.selectable ?? this._defaultOptions.selectable
163
- this._selectionBg = options.selectionBg ? parseColor(options.selectionBg) : undefined
164
- this._selectionFg = options.selectionFg ? parseColor(options.selectionFg) : undefined
165
- this._borderStyle = parseBorderStyle(options.borderStyle, this._defaultOptions.borderStyle)
166
- this._borderColor = parseColor(options.borderColor ?? this._defaultOptions.borderColor)
167
- this._borderBackgroundColor = parseColor(
168
- options.borderBackgroundColor ?? this._defaultOptions.borderBackgroundColor,
169
- )
170
- this._backgroundColor = parseColor(options.backgroundColor ?? this._defaultOptions.backgroundColor)
171
- this._defaultFg = parseColor(options.fg ?? this._defaultOptions.fg)
172
- this._defaultBg = parseColor(options.bg ?? this._defaultOptions.bg)
173
- this._defaultAttributes = options.attributes ?? this._defaultOptions.attributes
174
-
175
- this.setupMeasureFunc()
176
- this.rebuildCells()
177
- }
178
-
179
- public get content(): TextTableContent {
180
- return this._content
181
- }
182
-
183
- public set content(value: TextTableContent) {
184
- this._content = value ?? []
185
- this.rebuildCells()
186
- }
187
-
188
- public get wrapMode(): "none" | "char" | "word" {
189
- return this._wrapMode
190
- }
191
-
192
- public set wrapMode(value: "none" | "char" | "word") {
193
- if (this._wrapMode === value) return
194
- this._wrapMode = value
195
- for (const row of this._cells) {
196
- for (const cell of row) {
197
- cell.textBufferView.setWrapMode(value)
198
- }
199
- }
200
- this.invalidateLayoutAndRaster()
201
- }
202
-
203
- public get columnWidthMode(): TextTableColumnWidthMode {
204
- return this._columnWidthMode
205
- }
206
-
207
- public set columnWidthMode(value: TextTableColumnWidthMode) {
208
- if (this._columnWidthMode === value) return
209
- this._columnWidthMode = value
210
- this.invalidateLayoutAndRaster()
211
- }
212
-
213
- public get columnFitter(): TextTableColumnFitter {
214
- return this._columnFitter
215
- }
216
-
217
- public set columnFitter(value: TextTableColumnFitter) {
218
- const next = this.resolveColumnFitter(value)
219
- if (this._columnFitter === next) return
220
- this._columnFitter = next
221
- this.invalidateLayoutAndRaster()
222
- }
223
-
224
- public get cellPadding(): number {
225
- return this._cellPadding
226
- }
227
-
228
- public set cellPadding(value: number) {
229
- const next = this.resolveCellPadding(value)
230
- if (this._cellPadding === next) return
231
- this._cellPadding = next
232
- this.invalidateLayoutAndRaster()
233
- }
234
-
235
- public get showBorders(): boolean {
236
- return this._showBorders
237
- }
238
-
239
- public set showBorders(value: boolean) {
240
- if (this._showBorders === value) return
241
- this._showBorders = value
242
- this.invalidateRasterOnly()
243
- }
244
-
245
- public get outerBorder(): boolean {
246
- return this._outerBorder
247
- }
248
-
249
- public set outerBorder(value: boolean) {
250
- if (this._outerBorder === value) return
251
-
252
- this._hasExplicitOuterBorder = true
253
- this._outerBorder = value
254
- this.invalidateLayoutAndRaster()
255
- }
256
-
257
- public get border(): boolean {
258
- return this._border
259
- }
260
-
261
- public set border(value: boolean) {
262
- if (this._border === value) return
263
-
264
- this._border = value
265
-
266
- if (!this._hasExplicitOuterBorder) {
267
- this._outerBorder = value
268
- }
269
-
270
- this.invalidateLayoutAndRaster()
271
- }
272
-
273
- public get borderStyle(): BorderStyle {
274
- return this._borderStyle
275
- }
276
-
277
- public set borderStyle(value: BorderStyle) {
278
- const next = parseBorderStyle(value, this._defaultOptions.borderStyle)
279
- if (this._borderStyle === next) return
280
- this._borderStyle = next
281
- this.invalidateRasterOnly()
282
- }
283
-
284
- public get borderColor(): RGBA {
285
- return this._borderColor
286
- }
287
-
288
- public set borderColor(value: ColorInput) {
289
- const next = parseColor(value)
290
- if (this._borderColor === next) return
291
- this._borderColor = next
292
- this.invalidateRasterOnly()
293
- }
294
-
295
- public override shouldStartSelection(x: number, y: number): boolean {
296
- if (!this.selectable) return false
297
-
298
- this.ensureLayoutReady()
299
-
300
- const localX = x - this.x
301
- const localY = y - this.y
302
- return this.getCellAtLocalPosition(localX, localY) !== null
303
- }
304
-
305
- public override onSelectionChanged(selection: Selection | null): boolean {
306
- this.ensureLayoutReady()
307
-
308
- const previousLocalSelection = this._lastLocalSelection
309
- const localSelection = convertGlobalToLocalSelection(selection, this.x, this.y)
310
- this._lastLocalSelection = localSelection
311
- const dirtyRows = this.getDirtySelectionRowRange(previousLocalSelection, localSelection)
312
-
313
- if (!localSelection?.isActive) {
314
- this.resetCellSelections()
315
- this._lastSelectionMode = null
316
- } else {
317
- this.applySelectionToCells(localSelection, selection?.isStart ?? false)
318
- }
319
-
320
- if (dirtyRows !== null) {
321
- this.redrawSelectionRows(dirtyRows.firstRow, dirtyRows.lastRow)
322
- }
323
-
324
- return this.hasSelection()
325
- }
326
-
327
- public override hasSelection(): boolean {
328
- for (const row of this._cells) {
329
- for (const cell of row) {
330
- if (cell.textBufferView.hasSelection()) {
331
- return true
332
- }
333
- }
334
- }
335
-
336
- return false
337
- }
338
-
339
- public getSelection(): { start: number; end: number } | null {
340
- for (const row of this._cells) {
341
- for (const cell of row) {
342
- const selection = cell.textBufferView.getSelection()
343
- if (selection) {
344
- return selection
345
- }
346
- }
347
- }
348
-
349
- return null
350
- }
351
-
352
- public override getSelectedText(): string {
353
- const selectedRows: string[] = []
354
-
355
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
356
- const rowSelections: string[] = []
357
-
358
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
359
- const cell = this._cells[rowIdx]?.[colIdx]
360
- if (!cell || !cell.textBufferView.hasSelection()) continue
361
-
362
- const selectedText = cell.textBufferView.getSelectedText()
363
- if (selectedText.length > 0) {
364
- rowSelections.push(selectedText)
365
- }
366
- }
367
-
368
- if (rowSelections.length > 0) {
369
- selectedRows.push(rowSelections.join("\t"))
370
- }
371
- }
372
-
373
- return selectedRows.join("\n")
374
- }
375
-
376
- protected override onResize(width: number, height: number): void {
377
- this.invalidateLayoutAndRaster(false)
378
- super.onResize(width, height)
379
- }
380
-
381
- protected override renderSelf(buffer: OptimizedBuffer): void {
382
- if (!this.visible || this.isDestroyed) return
383
-
384
- if (this._layoutDirty) {
385
- this.rebuildLayoutForCurrentWidth()
386
- }
387
-
388
- if (!this._rasterDirty) return
389
-
390
- buffer.clear(this._backgroundColor)
391
-
392
- if (this._rowCount === 0 || this._columnCount === 0) {
393
- this._rasterDirty = false
394
- return
395
- }
396
-
397
- this.drawBorders(buffer)
398
- this.drawCells(buffer)
399
-
400
- this._rasterDirty = false
401
- }
402
-
403
- protected override destroySelf(): void {
404
- this.destroyCells()
405
- super.destroySelf()
406
- }
407
-
408
- private setupMeasureFunc(): void {
409
- const measureFunc = (
410
- width: number,
411
- widthMode: MeasureMode,
412
- _height: number,
413
- _heightMode: MeasureMode,
414
- ): { width: number; height: number } => {
415
- const hasWidthConstraint = widthMode !== MeasureMode.Undefined && Number.isFinite(width)
416
- const rawWidthConstraint = hasWidthConstraint ? Math.max(1, Math.floor(width)) : undefined
417
- const widthConstraint = this.resolveLayoutWidthConstraint(rawWidthConstraint)
418
- const measuredLayout = this.computeLayout(widthConstraint)
419
- this._cachedMeasureLayout = measuredLayout
420
- this._cachedMeasureWidth = widthConstraint
421
-
422
- let measuredWidth = measuredLayout.tableWidth > 0 ? measuredLayout.tableWidth : 1
423
- let measuredHeight = measuredLayout.tableHeight > 0 ? measuredLayout.tableHeight : 1
424
-
425
- if (widthMode === MeasureMode.AtMost && rawWidthConstraint !== undefined && this._positionType !== "absolute") {
426
- measuredWidth = Math.min(rawWidthConstraint, measuredWidth)
427
- }
428
-
429
- // Keep intrinsic height even under AtMost constraints. Clamping here can under-report
430
- // content height during Yoga measure passes and leave parent scroll extents stale.
431
- return {
432
- width: measuredWidth,
433
- height: measuredHeight,
434
- }
435
- }
436
-
437
- this.yogaNode.setMeasureFunc(measureFunc)
438
- }
439
-
440
- private rebuildCells(): void {
441
- const newRowCount = this._content.length
442
- const newColumnCount = this._content.reduce((max, row) => Math.max(max, row.length), 0)
443
-
444
- if (this._cells.length === 0) {
445
- this._rowCount = newRowCount
446
- this._columnCount = newColumnCount
447
- this._cells = []
448
- this._prevCellContent = []
449
-
450
- for (let rowIdx = 0; rowIdx < newRowCount; rowIdx++) {
451
- const row = this._content[rowIdx] ?? []
452
- const rowCells: TextTableCellState[] = []
453
- const rowRefs: TextTableCellContent[] = []
454
-
455
- for (let colIdx = 0; colIdx < newColumnCount; colIdx++) {
456
- const cellContent = row[colIdx]
457
- rowCells.push(this.createCell(cellContent))
458
- rowRefs.push(cellContent)
459
- }
460
-
461
- this._cells.push(rowCells)
462
- this._prevCellContent.push(rowRefs)
463
- }
464
-
465
- this.invalidateLayoutAndRaster()
466
- return
467
- }
468
-
469
- this.updateCellsDiff(newRowCount, newColumnCount)
470
- this.invalidateLayoutAndRaster()
471
- }
472
-
473
- private updateCellsDiff(newRowCount: number, newColumnCount: number): void {
474
- const oldRowCount = this._rowCount
475
- const oldColumnCount = this._columnCount
476
- const keepRows = Math.min(oldRowCount, newRowCount)
477
- const keepCols = Math.min(oldColumnCount, newColumnCount)
478
-
479
- for (let rowIdx = 0; rowIdx < keepRows; rowIdx++) {
480
- const newRow = this._content[rowIdx] ?? []
481
- const cellRow = this._cells[rowIdx]
482
- const refRow = this._prevCellContent[rowIdx]
483
-
484
- for (let colIdx = 0; colIdx < keepCols; colIdx++) {
485
- const cellContent = newRow[colIdx]
486
- if (cellContent === refRow[colIdx]) continue
487
-
488
- const oldCell = cellRow[colIdx]
489
- oldCell.textBufferView.destroy()
490
- oldCell.textBuffer.destroy()
491
- oldCell.syntaxStyle.destroy()
492
-
493
- cellRow[colIdx] = this.createCell(cellContent)
494
- refRow[colIdx] = cellContent
495
- }
496
-
497
- if (newColumnCount > oldColumnCount) {
498
- for (let colIdx = oldColumnCount; colIdx < newColumnCount; colIdx++) {
499
- const cellContent = newRow[colIdx]
500
- cellRow.push(this.createCell(cellContent))
501
- refRow.push(cellContent)
502
- }
503
- } else if (newColumnCount < oldColumnCount) {
504
- for (let colIdx = newColumnCount; colIdx < oldColumnCount; colIdx++) {
505
- const cell = cellRow[colIdx]
506
- cell.textBufferView.destroy()
507
- cell.textBuffer.destroy()
508
- cell.syntaxStyle.destroy()
509
- }
510
- cellRow.length = newColumnCount
511
- refRow.length = newColumnCount
512
- }
513
- }
514
-
515
- if (newRowCount > oldRowCount) {
516
- for (let rowIdx = oldRowCount; rowIdx < newRowCount; rowIdx++) {
517
- const newRow = this._content[rowIdx] ?? []
518
- const rowCells: TextTableCellState[] = []
519
- const rowRefs: TextTableCellContent[] = []
520
-
521
- for (let colIdx = 0; colIdx < newColumnCount; colIdx++) {
522
- const cellContent = newRow[colIdx]
523
- rowCells.push(this.createCell(cellContent))
524
- rowRefs.push(cellContent)
525
- }
526
-
527
- this._cells.push(rowCells)
528
- this._prevCellContent.push(rowRefs)
529
- }
530
- } else if (newRowCount < oldRowCount) {
531
- for (let rowIdx = newRowCount; rowIdx < oldRowCount; rowIdx++) {
532
- const row = this._cells[rowIdx]
533
- for (const cell of row) {
534
- cell.textBufferView.destroy()
535
- cell.textBuffer.destroy()
536
- cell.syntaxStyle.destroy()
537
- }
538
- }
539
- this._cells.length = newRowCount
540
- this._prevCellContent.length = newRowCount
541
- }
542
-
543
- this._rowCount = newRowCount
544
- this._columnCount = newColumnCount
545
- }
546
-
547
- private createCell(content: TextTableCellContent): TextTableCellState {
548
- const styledText = this.toStyledText(content)
549
- const textBuffer = TextBuffer.create(this._ctx.widthMethod)
550
- const syntaxStyle = SyntaxStyle.create()
551
-
552
- textBuffer.setDefaultFg(this._defaultFg)
553
- textBuffer.setDefaultBg(this._defaultBg)
554
- textBuffer.setDefaultAttributes(this._defaultAttributes)
555
- textBuffer.setSyntaxStyle(syntaxStyle)
556
- textBuffer.setStyledText(styledText)
557
-
558
- const textBufferView = TextBufferView.create(textBuffer)
559
- textBufferView.setWrapMode(this._wrapMode)
560
-
561
- return { textBuffer, textBufferView, syntaxStyle }
562
- }
563
-
564
- private toStyledText(content: TextTableCellContent): StyledText {
565
- if (Array.isArray(content)) {
566
- return new StyledText(content)
567
- }
568
-
569
- if (content === null || content === undefined) {
570
- return stringToStyledText("")
571
- }
572
-
573
- return stringToStyledText(String(content))
574
- }
575
-
576
- private destroyCells(): void {
577
- for (const row of this._cells) {
578
- for (const cell of row) {
579
- cell.textBufferView.destroy()
580
- cell.textBuffer.destroy()
581
- cell.syntaxStyle.destroy()
582
- }
583
- }
584
-
585
- this._cells = []
586
- this._prevCellContent = []
587
- this._rowCount = 0
588
- this._columnCount = 0
589
- this._layout = this.createEmptyLayout()
590
- }
591
-
592
- private rebuildLayoutForCurrentWidth(): void {
593
- const maxTableWidth = this.resolveLayoutWidthConstraint(this.width)
594
-
595
- let layout: TextTableLayout
596
- if (this._cachedMeasureLayout !== null && this._cachedMeasureWidth === maxTableWidth) {
597
- layout = this._cachedMeasureLayout
598
- } else {
599
- layout = this.computeLayout(maxTableWidth)
600
- }
601
- this._cachedMeasureLayout = null
602
- this._cachedMeasureWidth = undefined
603
-
604
- this._layout = layout
605
- this.applyLayoutToViews(layout)
606
- this._layoutDirty = false
607
-
608
- if (this._lastLocalSelection?.isActive) {
609
- this.applySelectionToCells(this._lastLocalSelection, true)
610
- }
611
- }
612
-
613
- private computeLayout(maxTableWidth?: number): TextTableLayout {
614
- if (this._rowCount === 0 || this._columnCount === 0) {
615
- return this.createEmptyLayout()
616
- }
617
-
618
- const borderLayout = this.resolveBorderLayout()
619
- const columnWidths = this.computeColumnWidths(maxTableWidth, borderLayout)
620
- const rowHeights = this.computeRowHeights(columnWidths)
621
- const columnOffsets = this.computeOffsets(
622
- columnWidths,
623
- borderLayout.left,
624
- borderLayout.right,
625
- borderLayout.innerVertical,
626
- )
627
- const rowOffsets = this.computeOffsets(
628
- rowHeights,
629
- borderLayout.top,
630
- borderLayout.bottom,
631
- borderLayout.innerHorizontal,
632
- )
633
- return {
634
- columnWidths,
635
- rowHeights,
636
- columnOffsets,
637
- rowOffsets,
638
- columnOffsetsI32: new Int32Array(columnOffsets),
639
- rowOffsetsI32: new Int32Array(rowOffsets),
640
- tableWidth: (columnOffsets[columnOffsets.length - 1] ?? 0) + 1,
641
- tableHeight: (rowOffsets[rowOffsets.length - 1] ?? 0) + 1,
642
- }
643
- }
644
-
645
- private isFullWidthMode(): boolean {
646
- return this._columnWidthMode === "full"
647
- }
648
-
649
- private computeColumnWidths(maxTableWidth: number | undefined, borderLayout: ResolvedTableBorderLayout): number[] {
650
- const horizontalPadding = this.getHorizontalCellPadding()
651
- const intrinsicWidths = new Array(this._columnCount).fill(1 + horizontalPadding)
652
-
653
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
654
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
655
- const cell = this._cells[rowIdx]?.[colIdx]
656
- if (!cell) continue
657
-
658
- const measure = cell.textBufferView.measureForDimensions(0, MEASURE_HEIGHT)
659
- const measuredWidth = Math.max(1, measure?.widthColsMax ?? 0) + horizontalPadding
660
- intrinsicWidths[colIdx] = Math.max(intrinsicWidths[colIdx], measuredWidth)
661
- }
662
- }
663
-
664
- if (maxTableWidth === undefined || !Number.isFinite(maxTableWidth) || maxTableWidth <= 0) {
665
- return intrinsicWidths
666
- }
667
-
668
- const maxContentWidth = Math.max(1, Math.floor(maxTableWidth) - this.getVerticalBorderCount(borderLayout))
669
- const currentWidth = intrinsicWidths.reduce((sum, width) => sum + width, 0)
670
-
671
- if (currentWidth === maxContentWidth) {
672
- return intrinsicWidths
673
- }
674
-
675
- if (currentWidth < maxContentWidth) {
676
- if (this.isFullWidthMode()) {
677
- return this.expandColumnWidths(intrinsicWidths, maxContentWidth)
678
- }
679
-
680
- return intrinsicWidths
681
- }
682
-
683
- if (this._wrapMode === "none") {
684
- return intrinsicWidths
685
- }
686
-
687
- return this.fitColumnWidths(intrinsicWidths, maxContentWidth)
688
- }
689
-
690
- private expandColumnWidths(widths: number[], targetContentWidth: number): number[] {
691
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)))
692
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0)
693
-
694
- if (totalBaseWidth >= targetContentWidth) {
695
- return baseWidths
696
- }
697
-
698
- const expanded = [...baseWidths]
699
- const columns = expanded.length
700
- const extraWidth = targetContentWidth - totalBaseWidth
701
- const sharedWidth = Math.floor(extraWidth / columns)
702
- const remainder = extraWidth % columns
703
-
704
- for (let idx = 0; idx < columns; idx++) {
705
- expanded[idx] += sharedWidth
706
- if (idx < remainder) {
707
- expanded[idx] += 1
708
- }
709
- }
710
-
711
- return expanded
712
- }
713
-
714
- private fitColumnWidths(widths: number[], targetContentWidth: number): number[] {
715
- if (this._columnFitter === "balanced") {
716
- return this.fitColumnWidthsBalanced(widths, targetContentWidth)
717
- }
718
-
719
- return this.fitColumnWidthsProportional(widths, targetContentWidth)
720
- }
721
-
722
- private fitColumnWidthsProportional(widths: number[], targetContentWidth: number): number[] {
723
- const minWidth = 1 + this.getHorizontalCellPadding()
724
- const hardMinWidths = new Array(widths.length).fill(minWidth)
725
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)))
726
-
727
- const preferredMinWidths = baseWidths.map((width) => Math.min(width, minWidth + 1))
728
- const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0)
729
-
730
- const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths
731
- const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0)
732
- const clampedTarget = Math.max(floorTotal, targetContentWidth)
733
-
734
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0)
735
-
736
- if (totalBaseWidth <= clampedTarget) {
737
- return baseWidths
738
- }
739
-
740
- const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx])
741
- const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0)
742
- if (totalShrinkable <= 0) {
743
- return [...floorWidths]
744
- }
745
-
746
- const targetShrink = totalBaseWidth - clampedTarget
747
- const integerShrink = new Array(baseWidths.length).fill(0)
748
- const fractions = new Array(baseWidths.length).fill(0)
749
- let usedShrink = 0
750
-
751
- for (let idx = 0; idx < baseWidths.length; idx++) {
752
- if (shrinkable[idx] <= 0) continue
753
-
754
- const exact = (shrinkable[idx] / totalShrinkable) * targetShrink
755
- const whole = Math.min(shrinkable[idx], Math.floor(exact))
756
- integerShrink[idx] = whole
757
- fractions[idx] = exact - whole
758
- usedShrink += whole
759
- }
760
-
761
- let remainingShrink = targetShrink - usedShrink
762
-
763
- while (remainingShrink > 0) {
764
- let bestIdx = -1
765
- let bestFraction = -1
766
-
767
- for (let idx = 0; idx < baseWidths.length; idx++) {
768
- if (shrinkable[idx] - integerShrink[idx] <= 0) continue
769
- if (fractions[idx] > bestFraction) {
770
- bestFraction = fractions[idx]
771
- bestIdx = idx
772
- }
773
- }
774
-
775
- if (bestIdx === -1) break
776
-
777
- integerShrink[bestIdx] += 1
778
- fractions[bestIdx] = 0
779
- remainingShrink -= 1
780
- }
781
-
782
- return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - integerShrink[idx]))
783
- }
784
-
785
- private fitColumnWidthsBalanced(widths: number[], targetContentWidth: number): number[] {
786
- const minWidth = 1 + this.getHorizontalCellPadding()
787
- const hardMinWidths = new Array(widths.length).fill(minWidth)
788
- const baseWidths = widths.map((width) => Math.max(1, Math.floor(width)))
789
- const totalBaseWidth = baseWidths.reduce((sum, width) => sum + width, 0)
790
- const columns = baseWidths.length
791
-
792
- if (columns === 0 || totalBaseWidth <= targetContentWidth) {
793
- return baseWidths
794
- }
795
-
796
- const evenShare = Math.max(minWidth, Math.floor(targetContentWidth / columns))
797
- const preferredMinWidths = baseWidths.map((width) => Math.min(width, evenShare))
798
- const preferredMinTotal = preferredMinWidths.reduce((sum, width) => sum + width, 0)
799
- const floorWidths = preferredMinTotal <= targetContentWidth ? preferredMinWidths : hardMinWidths
800
- const floorTotal = floorWidths.reduce((sum, width) => sum + width, 0)
801
- const clampedTarget = Math.max(floorTotal, targetContentWidth)
802
-
803
- if (totalBaseWidth <= clampedTarget) {
804
- return baseWidths
805
- }
806
-
807
- const shrinkable = baseWidths.map((width, idx) => width - floorWidths[idx])
808
- const totalShrinkable = shrinkable.reduce((sum, value) => sum + value, 0)
809
- if (totalShrinkable <= 0) {
810
- return [...floorWidths]
811
- }
812
-
813
- const targetShrink = totalBaseWidth - clampedTarget
814
- const shrink = this.allocateShrinkByWeight(shrinkable, targetShrink, "sqrt")
815
-
816
- return baseWidths.map((width, idx) => Math.max(floorWidths[idx], width - shrink[idx]))
817
- }
818
-
819
- private allocateShrinkByWeight(shrinkable: number[], targetShrink: number, mode: "linear" | "sqrt"): number[] {
820
- const shrink = new Array(shrinkable.length).fill(0)
821
-
822
- if (targetShrink <= 0) {
823
- return shrink
824
- }
825
-
826
- const weights = shrinkable.map((value) => {
827
- if (value <= 0) {
828
- return 0
829
- }
830
-
831
- return mode === "sqrt" ? Math.sqrt(value) : value
832
- })
833
- const totalWeight = weights.reduce((sum, value) => sum + value, 0)
834
-
835
- if (totalWeight <= 0) {
836
- return shrink
837
- }
838
-
839
- const fractions = new Array(shrinkable.length).fill(0)
840
- let usedShrink = 0
841
-
842
- for (let idx = 0; idx < shrinkable.length; idx++) {
843
- if (shrinkable[idx] <= 0 || weights[idx] <= 0) continue
844
-
845
- const exact = (weights[idx] / totalWeight) * targetShrink
846
- const whole = Math.min(shrinkable[idx], Math.floor(exact))
847
- shrink[idx] = whole
848
- fractions[idx] = exact - whole
849
- usedShrink += whole
850
- }
851
-
852
- let remainingShrink = targetShrink - usedShrink
853
-
854
- while (remainingShrink > 0) {
855
- let bestIdx = -1
856
- let bestFraction = -1
857
-
858
- for (let idx = 0; idx < shrinkable.length; idx++) {
859
- if (shrinkable[idx] - shrink[idx] <= 0) continue
860
-
861
- if (
862
- bestIdx === -1 ||
863
- fractions[idx] > bestFraction ||
864
- (fractions[idx] === bestFraction && shrinkable[idx] > shrinkable[bestIdx])
865
- ) {
866
- bestIdx = idx
867
- bestFraction = fractions[idx]
868
- }
869
- }
870
-
871
- if (bestIdx === -1) {
872
- break
873
- }
874
-
875
- shrink[bestIdx] += 1
876
- fractions[bestIdx] = 0
877
- remainingShrink -= 1
878
- }
879
-
880
- return shrink
881
- }
882
-
883
- private computeRowHeights(columnWidths: number[]): number[] {
884
- const horizontalPadding = this.getHorizontalCellPadding()
885
- const verticalPadding = this.getVerticalCellPadding()
886
- const rowHeights = new Array(this._rowCount).fill(1 + verticalPadding)
887
-
888
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
889
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
890
- const cell = this._cells[rowIdx]?.[colIdx]
891
- if (!cell) continue
892
-
893
- const width = Math.max(1, (columnWidths[colIdx] ?? 1) - horizontalPadding)
894
- const measure = cell.textBufferView.measureForDimensions(width, MEASURE_HEIGHT)
895
- const lineCount = Math.max(1, measure?.lineCount ?? 1)
896
- rowHeights[rowIdx] = Math.max(rowHeights[rowIdx], lineCount + verticalPadding)
897
- }
898
- }
899
-
900
- return rowHeights
901
- }
902
-
903
- private computeOffsets(
904
- parts: number[],
905
- startBoundary: boolean,
906
- endBoundary: boolean,
907
- includeInnerBoundaries: boolean,
908
- ): number[] {
909
- const offsets: number[] = [startBoundary ? 0 : -1]
910
- let cursor = offsets[0] ?? 0
911
-
912
- for (let idx = 0; idx < parts.length; idx++) {
913
- const size = parts[idx] ?? 1
914
- const hasBoundaryAfter = idx < parts.length - 1 ? includeInnerBoundaries : endBoundary
915
- cursor += size + (hasBoundaryAfter ? 1 : 0)
916
- offsets.push(cursor)
917
- }
918
-
919
- return offsets
920
- }
921
-
922
- private applyLayoutToViews(layout: TextTableLayout): void {
923
- const horizontalPadding = this.getHorizontalCellPadding()
924
- const verticalPadding = this.getVerticalCellPadding()
925
-
926
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
927
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
928
- const cell = this._cells[rowIdx]?.[colIdx]
929
- if (!cell) continue
930
-
931
- const colWidth = layout.columnWidths[colIdx] ?? 1
932
- const rowHeight = layout.rowHeights[rowIdx] ?? 1
933
- const contentWidth = Math.max(1, colWidth - horizontalPadding)
934
- const contentHeight = Math.max(1, rowHeight - verticalPadding)
935
-
936
- if (this._wrapMode === "none") {
937
- cell.textBufferView.setWrapWidth(null)
938
- } else {
939
- cell.textBufferView.setWrapWidth(contentWidth)
940
- }
941
-
942
- cell.textBufferView.setViewport(0, 0, contentWidth, contentHeight)
943
- }
944
- }
945
- }
946
-
947
- private resolveBorderLayout(): ResolvedTableBorderLayout {
948
- return {
949
- left: this._outerBorder,
950
- right: this._outerBorder,
951
- top: this._outerBorder,
952
- bottom: this._outerBorder,
953
- innerVertical: this._border && this._columnCount > 1,
954
- innerHorizontal: this._border && this._rowCount > 1,
955
- }
956
- }
957
-
958
- private getVerticalBorderCount(borderLayout: ResolvedTableBorderLayout): number {
959
- return (
960
- (borderLayout.left ? 1 : 0) +
961
- (borderLayout.right ? 1 : 0) +
962
- (borderLayout.innerVertical ? Math.max(0, this._columnCount - 1) : 0)
963
- )
964
- }
965
-
966
- private getHorizontalBorderCount(borderLayout: ResolvedTableBorderLayout): number {
967
- return (
968
- (borderLayout.top ? 1 : 0) +
969
- (borderLayout.bottom ? 1 : 0) +
970
- (borderLayout.innerHorizontal ? Math.max(0, this._rowCount - 1) : 0)
971
- )
972
- }
973
-
974
- private drawBorders(buffer: OptimizedBuffer): void {
975
- if (!this._showBorders) {
976
- return
977
- }
978
-
979
- const borderLayout = this.resolveBorderLayout()
980
-
981
- if (this.getVerticalBorderCount(borderLayout) === 0 && this.getHorizontalBorderCount(borderLayout) === 0) {
982
- return
983
- }
984
-
985
- buffer.drawGrid({
986
- borderChars: BorderCharArrays[this._borderStyle],
987
- borderFg: this._borderColor,
988
- borderBg: this._borderBackgroundColor,
989
- columnOffsets: this._layout.columnOffsetsI32,
990
- rowOffsets: this._layout.rowOffsetsI32,
991
- drawInner: this._border,
992
- drawOuter: this._outerBorder,
993
- })
994
- }
995
-
996
- private drawCells(buffer: OptimizedBuffer): void {
997
- this.drawCellRange(buffer, 0, this._rowCount - 1)
998
- }
999
-
1000
- private drawCellRange(buffer: OptimizedBuffer, firstRow: number, lastRow: number): void {
1001
- const colOffsets = this._layout.columnOffsets
1002
- const rowOffsets = this._layout.rowOffsets
1003
- const cellPadding = this._cellPadding
1004
-
1005
- for (let rowIdx = firstRow; rowIdx <= lastRow; rowIdx++) {
1006
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1 + cellPadding
1007
-
1008
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
1009
- const cell = this._cells[rowIdx]?.[colIdx]
1010
- if (!cell) continue
1011
- buffer.drawTextBuffer(cell.textBufferView, (colOffsets[colIdx] ?? 0) + 1 + cellPadding, cellY)
1012
- }
1013
- }
1014
- }
1015
-
1016
- private redrawSelectionRows(firstRow: number, lastRow: number): void {
1017
- if (firstRow > lastRow) return
1018
-
1019
- if (this._backgroundColor.a < 1) {
1020
- this.invalidateRasterOnly()
1021
- return
1022
- }
1023
-
1024
- const buffer = this.frameBuffer
1025
- if (!buffer) return
1026
-
1027
- this.clearCellRange(buffer, firstRow, lastRow)
1028
- this.drawCellRange(buffer, firstRow, lastRow)
1029
- this.requestRender()
1030
- }
1031
-
1032
- private clearCellRange(buffer: OptimizedBuffer, firstRow: number, lastRow: number): void {
1033
- const colWidths = this._layout.columnWidths
1034
- const rowHeights = this._layout.rowHeights
1035
- const colOffsets = this._layout.columnOffsets
1036
- const rowOffsets = this._layout.rowOffsets
1037
-
1038
- for (let rowIdx = firstRow; rowIdx <= lastRow; rowIdx++) {
1039
- const cellY = (rowOffsets[rowIdx] ?? 0) + 1
1040
- const rowHeight = rowHeights[rowIdx] ?? 1
1041
-
1042
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
1043
- const cellX = (colOffsets[colIdx] ?? 0) + 1
1044
- const colWidth = colWidths[colIdx] ?? 1
1045
- buffer.fillRect(cellX, cellY, colWidth, rowHeight, this._backgroundColor)
1046
- }
1047
- }
1048
- }
1049
-
1050
- private ensureLayoutReady(): void {
1051
- if (!this._layoutDirty) return
1052
- this.rebuildLayoutForCurrentWidth()
1053
- }
1054
-
1055
- private getCellAtLocalPosition(localX: number, localY: number): CellPosition | null {
1056
- if (this._rowCount === 0 || this._columnCount === 0) return null
1057
- if (localX < 0 || localY < 0 || localX >= this._layout.tableWidth || localY >= this._layout.tableHeight) {
1058
- return null
1059
- }
1060
-
1061
- let rowIdx = -1
1062
- for (let idx = 0; idx < this._rowCount; idx++) {
1063
- const top = (this._layout.rowOffsets[idx] ?? 0) + 1
1064
- const bottom = top + (this._layout.rowHeights[idx] ?? 1) - 1
1065
- if (localY >= top && localY <= bottom) {
1066
- rowIdx = idx
1067
- break
1068
- }
1069
- }
1070
-
1071
- if (rowIdx < 0) return null
1072
-
1073
- let colIdx = -1
1074
- for (let idx = 0; idx < this._columnCount; idx++) {
1075
- const left = (this._layout.columnOffsets[idx] ?? 0) + 1
1076
- const right = left + (this._layout.columnWidths[idx] ?? 1) - 1
1077
- if (localX >= left && localX <= right) {
1078
- colIdx = idx
1079
- break
1080
- }
1081
- }
1082
-
1083
- if (colIdx < 0) return null
1084
-
1085
- return { rowIdx, colIdx }
1086
- }
1087
-
1088
- private applySelectionToCells(localSelection: LocalSelectionBounds, isStart: boolean): void {
1089
- const minSelY = Math.min(localSelection.anchorY, localSelection.focusY)
1090
- const maxSelY = Math.max(localSelection.anchorY, localSelection.focusY)
1091
-
1092
- const firstRow = this.findRowForLocalY(minSelY)
1093
- const lastRow = this.findRowForLocalY(maxSelY)
1094
- const selection = this.resolveSelectionResolution(localSelection)
1095
- const modeChanged = this._lastSelectionMode !== selection.mode
1096
- this._lastSelectionMode = selection.mode
1097
- const lockToAnchorColumn = selection.mode === "column-locked" && selection.anchorColumn !== null
1098
-
1099
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
1100
- if (rowIdx < firstRow || rowIdx > lastRow) {
1101
- this.resetRowSelection(rowIdx)
1102
- continue
1103
- }
1104
-
1105
- const cellTop = (this._layout.rowOffsets[rowIdx] ?? 0) + 1 + this._cellPadding
1106
-
1107
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
1108
- const cell = this._cells[rowIdx]?.[colIdx]
1109
- if (!cell) continue
1110
-
1111
- if (lockToAnchorColumn && colIdx !== selection.anchorColumn) {
1112
- cell.textBufferView.resetLocalSelection()
1113
- continue
1114
- }
1115
-
1116
- const cellLeft = (this._layout.columnOffsets[colIdx] ?? 0) + 1 + this._cellPadding
1117
- let coords: CellSelectionCoords = {
1118
- anchorX: localSelection.anchorX - cellLeft,
1119
- anchorY: localSelection.anchorY - cellTop,
1120
- focusX: localSelection.focusX - cellLeft,
1121
- focusY: localSelection.focusY - cellTop,
1122
- }
1123
-
1124
- const isAnchorCell =
1125
- selection.anchorCell !== null &&
1126
- selection.anchorCell.rowIdx === rowIdx &&
1127
- selection.anchorCell.colIdx === colIdx
1128
- const forceSet = isAnchorCell && selection.mode !== "single-cell"
1129
-
1130
- if (forceSet) {
1131
- coords = this.getFullCellSelectionCoords(rowIdx, colIdx)
1132
- }
1133
-
1134
- const shouldUseSet = isStart || modeChanged || forceSet
1135
-
1136
- if (shouldUseSet) {
1137
- cell.textBufferView.setLocalSelection(
1138
- coords.anchorX,
1139
- coords.anchorY,
1140
- coords.focusX,
1141
- coords.focusY,
1142
- this._selectionBg,
1143
- this._selectionFg,
1144
- )
1145
- } else {
1146
- cell.textBufferView.updateLocalSelection(
1147
- coords.anchorX,
1148
- coords.anchorY,
1149
- coords.focusX,
1150
- coords.focusY,
1151
- this._selectionBg,
1152
- this._selectionFg,
1153
- )
1154
- }
1155
- }
1156
- }
1157
- }
1158
-
1159
- private resolveSelectionResolution(localSelection: LocalSelectionBounds): SelectionResolution {
1160
- const anchorCell = this.getCellAtLocalPosition(localSelection.anchorX, localSelection.anchorY)
1161
- const focusCell = this.getCellAtLocalPosition(localSelection.focusX, localSelection.focusY)
1162
- const anchorColumn = anchorCell?.colIdx ?? this.getColumnAtLocalX(localSelection.anchorX)
1163
-
1164
- if (
1165
- anchorCell !== null &&
1166
- focusCell !== null &&
1167
- anchorCell.rowIdx === focusCell.rowIdx &&
1168
- anchorCell.colIdx === focusCell.colIdx
1169
- ) {
1170
- return {
1171
- mode: "single-cell",
1172
- anchorCell,
1173
- anchorColumn,
1174
- }
1175
- }
1176
-
1177
- const focusColumn = this.getColumnAtLocalX(localSelection.focusX)
1178
- if (anchorColumn !== null && focusColumn === anchorColumn) {
1179
- return {
1180
- mode: "column-locked",
1181
- anchorCell,
1182
- anchorColumn,
1183
- }
1184
- }
1185
-
1186
- return {
1187
- mode: "grid",
1188
- anchorCell,
1189
- anchorColumn,
1190
- }
1191
- }
1192
-
1193
- private getColumnAtLocalX(localX: number): number | null {
1194
- if (this._columnCount === 0) return null
1195
- if (localX < 0 || localX >= this._layout.tableWidth) return null
1196
-
1197
- for (let colIdx = 0; colIdx < this._columnCount; colIdx++) {
1198
- const colStart = (this._layout.columnOffsets[colIdx] ?? 0) + 1
1199
- const colEnd = colStart + (this._layout.columnWidths[colIdx] ?? 1) - 1
1200
- if (localX >= colStart && localX <= colEnd) {
1201
- return colIdx
1202
- }
1203
- }
1204
-
1205
- return null
1206
- }
1207
-
1208
- private getFullCellSelectionCoords(rowIdx: number, colIdx: number): CellSelectionCoords {
1209
- const colWidth = this._layout.columnWidths[colIdx] ?? 1
1210
- const rowHeight = this._layout.rowHeights[rowIdx] ?? 1
1211
- const contentWidth = Math.max(1, colWidth - this.getHorizontalCellPadding())
1212
- const contentHeight = Math.max(1, rowHeight - this.getVerticalCellPadding())
1213
-
1214
- return {
1215
- anchorX: -1,
1216
- anchorY: 0,
1217
- focusX: contentWidth,
1218
- focusY: contentHeight,
1219
- }
1220
- }
1221
-
1222
- private findRowForLocalY(localY: number): number {
1223
- if (this._rowCount === 0) return 0
1224
- if (localY < 0) return 0
1225
-
1226
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
1227
- const rowStart = (this._layout.rowOffsets[rowIdx] ?? 0) + 1
1228
- const rowEnd = rowStart + (this._layout.rowHeights[rowIdx] ?? 1) - 1
1229
- if (localY <= rowEnd) return rowIdx
1230
- }
1231
-
1232
- return this._rowCount - 1
1233
- }
1234
-
1235
- private getSelectionRowRange(selection: LocalSelectionBounds | null): RowRange | null {
1236
- if (!selection?.isActive || this._rowCount === 0) return null
1237
-
1238
- const minSelY = Math.min(selection.anchorY, selection.focusY)
1239
- const maxSelY = Math.max(selection.anchorY, selection.focusY)
1240
-
1241
- return {
1242
- firstRow: this.findRowForLocalY(minSelY),
1243
- lastRow: this.findRowForLocalY(maxSelY),
1244
- }
1245
- }
1246
-
1247
- private getDirtySelectionRowRange(
1248
- previousSelection: LocalSelectionBounds | null,
1249
- currentSelection: LocalSelectionBounds | null,
1250
- ): RowRange | null {
1251
- const previousRange = this.getSelectionRowRange(previousSelection)
1252
- const currentRange = this.getSelectionRowRange(currentSelection)
1253
-
1254
- if (previousRange === null) return currentRange
1255
- if (currentRange === null) return previousRange
1256
-
1257
- return {
1258
- firstRow: Math.min(previousRange.firstRow, currentRange.firstRow),
1259
- lastRow: Math.max(previousRange.lastRow, currentRange.lastRow),
1260
- }
1261
- }
1262
-
1263
- private resetRowSelection(rowIdx: number): void {
1264
- const row = this._cells[rowIdx]
1265
- if (!row) return
1266
-
1267
- for (const cell of row) {
1268
- cell.textBufferView.resetLocalSelection()
1269
- }
1270
- }
1271
-
1272
- private resetCellSelections(): void {
1273
- for (let rowIdx = 0; rowIdx < this._rowCount; rowIdx++) {
1274
- this.resetRowSelection(rowIdx)
1275
- }
1276
- }
1277
-
1278
- private createEmptyLayout(): TextTableLayout {
1279
- return {
1280
- columnWidths: [],
1281
- rowHeights: [],
1282
- columnOffsets: [0],
1283
- rowOffsets: [0],
1284
- columnOffsetsI32: new Int32Array([0]),
1285
- rowOffsetsI32: new Int32Array([0]),
1286
- tableWidth: 0,
1287
- tableHeight: 0,
1288
- }
1289
- }
1290
-
1291
- private resolveLayoutWidthConstraint(width: number | undefined): number | undefined {
1292
- if (width === undefined || !Number.isFinite(width) || width <= 0) {
1293
- return undefined
1294
- }
1295
-
1296
- if (this._wrapMode !== "none" || this.isFullWidthMode()) {
1297
- return Math.max(1, Math.floor(width))
1298
- }
1299
-
1300
- return undefined
1301
- }
1302
-
1303
- private getHorizontalCellPadding(): number {
1304
- return this._cellPadding * 2
1305
- }
1306
-
1307
- private getVerticalCellPadding(): number {
1308
- return this._cellPadding * 2
1309
- }
1310
-
1311
- private resolveColumnFitter(value: TextTableColumnFitter | undefined): TextTableColumnFitter {
1312
- if (value === undefined) {
1313
- return this._defaultOptions.columnFitter
1314
- }
1315
-
1316
- return value === "balanced" ? "balanced" : "proportional"
1317
- }
1318
-
1319
- private resolveCellPadding(value: number | undefined): number {
1320
- if (value === undefined || !Number.isFinite(value)) {
1321
- return this._defaultOptions.cellPadding
1322
- }
1323
-
1324
- return Math.max(0, Math.floor(value))
1325
- }
1326
-
1327
- private invalidateLayoutAndRaster(markYogaDirty: boolean = true): void {
1328
- this._layoutDirty = true
1329
- this._rasterDirty = true
1330
- this._cachedMeasureLayout = null
1331
- this._cachedMeasureWidth = undefined
1332
-
1333
- if (markYogaDirty) {
1334
- this.yogaNode.markDirty()
1335
- }
1336
-
1337
- this.requestRender()
1338
- }
1339
-
1340
- private invalidateRasterOnly(): void {
1341
- this._rasterDirty = true
1342
- this.requestRender()
1343
- }
1344
- }