@xincli/opentui-core 0.4.6 → 0.4.7

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 (619) hide show
  1. package/LICENSE +21 -0
  2. package/NativeSpanFeed.d.ts +52 -0
  3. package/README.md +0 -0
  4. package/Renderable.d.ts +346 -0
  5. package/animation/Timeline.d.ts +126 -0
  6. package/ansi.d.ts +17 -0
  7. package/audio.d.ts +89 -0
  8. package/buffer.d.ts +113 -0
  9. package/console.d.ts +146 -0
  10. package/edit-buffer.d.ts +97 -0
  11. package/editor-view.d.ts +72 -0
  12. package/index-m1y9e40w.js +10045 -0
  13. package/index-m1y9e40w.js.map +32 -0
  14. package/index-sqk4ajdf.js +16121 -0
  15. package/index-sqk4ajdf.js.map +58 -0
  16. package/index.d.ts +24 -0
  17. package/index.js +11709 -0
  18. package/index.js.map +35 -0
  19. package/lib/KeyHandler.d.ts +61 -0
  20. package/lib/RGBA.d.ts +42 -0
  21. package/lib/ascii.font.d.ts +508 -0
  22. package/lib/border.d.ts +51 -0
  23. package/lib/bunfs.d.ts +7 -0
  24. package/lib/clipboard.d.ts +15 -0
  25. package/lib/clock.d.ts +15 -0
  26. package/lib/data-paths.d.ts +26 -0
  27. package/lib/debounce.d.ts +42 -0
  28. package/lib/detect-links.d.ts +6 -0
  29. package/lib/env.d.ts +42 -0
  30. package/lib/extmarks-history.d.ts +17 -0
  31. package/lib/extmarks.d.ts +90 -0
  32. package/lib/hast-styled-text.d.ts +17 -0
  33. package/lib/index.d.ts +22 -0
  34. package/lib/keybinding.internal.d.ts +33 -0
  35. package/lib/objects-in-viewport.d.ts +24 -0
  36. package/lib/output.capture.d.ts +24 -0
  37. package/lib/parse.keypress-kitty.d.ts +3 -0
  38. package/lib/parse.keypress.d.ts +27 -0
  39. package/lib/parse.mouse.d.ts +30 -0
  40. package/lib/paste.d.ts +7 -0
  41. package/lib/queue.d.ts +15 -0
  42. package/lib/render-geometry.d.ts +8 -0
  43. package/lib/renderable.validations.d.ts +12 -0
  44. package/lib/scroll-acceleration.d.ts +43 -0
  45. package/lib/selection.d.ts +64 -0
  46. package/lib/singleton.d.ts +8 -0
  47. package/lib/stdin-parser.d.ts +90 -0
  48. package/lib/styled-text.d.ts +63 -0
  49. package/lib/terminal-capability-detection.d.ts +32 -0
  50. package/lib/terminal-palette.d.ts +65 -0
  51. package/lib/tree-sitter/assets/update.d.ts +12 -0
  52. package/lib/tree-sitter/client.d.ts +65 -0
  53. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  54. package/lib/tree-sitter/download-utils.d.ts +21 -0
  55. package/lib/tree-sitter/index.d.ts +7 -0
  56. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  57. package/lib/tree-sitter/parsers-config.d.ts +53 -0
  58. package/lib/tree-sitter/resolve-ft.d.ts +5 -0
  59. package/lib/tree-sitter/types.d.ts +185 -0
  60. package/lib/tree-sitter/update-assets.d.ts +3 -0
  61. package/lib/tree-sitter/update-assets.js +379 -0
  62. package/lib/tree-sitter/update-assets.js.map +12 -0
  63. package/lib/tree-sitter-styled-text.d.ts +16 -0
  64. package/lib/validate-dir-name.d.ts +1 -0
  65. package/lib/yoga.options.d.ts +32 -0
  66. package/native-event-worker-repro.worker.d.ts +1 -0
  67. package/package.json +52 -74
  68. package/parser.worker.js +1399 -0
  69. package/parser.worker.js.map +20 -0
  70. package/platform/ffi.d.ts +129 -0
  71. package/platform/runtime.d.ts +14 -0
  72. package/platform/test.d.ts +12 -0
  73. package/platform/worker.d.ts +26 -0
  74. package/platform/worker.node-test.d.ts +1 -0
  75. package/plugins/core-slot.d.ts +72 -0
  76. package/plugins/registry.d.ts +42 -0
  77. package/plugins/types.d.ts +34 -0
  78. package/post/effects.d.ts +147 -0
  79. package/post/filters.d.ts +65 -0
  80. package/post/matrices.d.ts +20 -0
  81. package/renderables/ASCIIFont.d.ts +52 -0
  82. package/renderables/Box.d.ts +85 -0
  83. package/renderables/Code.d.ts +97 -0
  84. package/renderables/Diff.d.ts +147 -0
  85. package/renderables/EditBufferRenderable.d.ts +238 -0
  86. package/renderables/FrameBuffer.d.ts +16 -0
  87. package/renderables/Input.d.ts +72 -0
  88. package/renderables/LineNumberRenderable.d.ts +78 -0
  89. package/renderables/Markdown.d.ts +255 -0
  90. package/renderables/ScrollBar.d.ts +77 -0
  91. package/renderables/ScrollBox.d.ts +128 -0
  92. package/renderables/Select.d.ts +122 -0
  93. package/renderables/Slider.d.ts +47 -0
  94. package/renderables/TabSelect.d.ts +98 -0
  95. package/renderables/Text.d.ts +36 -0
  96. package/renderables/TextBufferRenderable.d.ts +107 -0
  97. package/renderables/TextNode.d.ts +92 -0
  98. package/renderables/TextTable.d.ts +154 -0
  99. package/renderables/Textarea.d.ts +65 -0
  100. package/renderables/TimeToFirstDraw.d.ts +24 -0
  101. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  102. package/renderables/composition/VRenderable.d.ts +16 -0
  103. package/renderables/composition/constructs.d.ts +35 -0
  104. package/renderables/composition/vnode.d.ts +46 -0
  105. package/renderables/index.d.ts +23 -0
  106. package/renderables/markdown-parser.d.ts +11 -0
  107. package/renderer-theme-mode.d.ts +29 -0
  108. package/renderer.d.ts +601 -0
  109. package/runtime-plugin-support-configure.d.ts +4 -0
  110. package/runtime-plugin-support-configure.js +36 -0
  111. package/runtime-plugin-support-configure.js.map +1 -0
  112. package/runtime-plugin-support-configure.node.js +15 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +5 -0
  115. package/runtime-plugin-support.js.map +1 -0
  116. package/runtime-plugin-support.node.js +15 -0
  117. package/runtime-plugin.d.ts +16 -0
  118. package/runtime-plugin.js +473 -0
  119. package/runtime-plugin.js.map +1 -0
  120. package/runtime-plugin.node.js +15 -0
  121. package/syntax-style.d.ts +61 -0
  122. package/testing/bun-test-node.d.ts +87 -0
  123. package/testing/manual-clock.d.ts +17 -0
  124. package/testing/mock-keys.d.ts +81 -0
  125. package/testing/mock-mouse.d.ts +38 -0
  126. package/testing/mock-tree-sitter-client.d.ts +27 -0
  127. package/testing/spy.d.ts +7 -0
  128. package/testing/terminal-capabilities.d.ts +7 -0
  129. package/testing/test-recorder.d.ts +61 -0
  130. package/testing/test-renderer.d.ts +54 -0
  131. package/testing/test-streams.d.ts +12 -0
  132. package/testing.d.ts +8 -0
  133. package/testing.js +1004 -0
  134. package/testing.js.map +18 -0
  135. package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
  136. package/tests/yoga-upstream/tools/utils.d.ts +11 -0
  137. package/text-buffer-view.d.ts +42 -0
  138. package/text-buffer.d.ts +66 -0
  139. package/types.d.ts +175 -0
  140. package/utils.d.ts +14 -0
  141. package/yoga.d.ts +437 -0
  142. package/yoga.js +193 -0
  143. package/yoga.js.map +9 -0
  144. package/zig-structs.d.ts +256 -0
  145. package/zig.d.ts +496 -0
  146. package/dev/keypress-debug-renderer.ts +0 -148
  147. package/dev/keypress-debug.ts +0 -43
  148. package/dev/print-env-vars.ts +0 -32
  149. package/dev/test-tmux-graphics-334.sh +0 -68
  150. package/dev/test-tmux-theme-queries.sh +0 -151
  151. package/dev/thai-debug-test.ts +0 -68
  152. package/dev/theme-mode.ts +0 -290
  153. package/docs/development.md +0 -144
  154. package/prebuilt/aarch64-android/libopentui.so +0 -0
  155. package/scripts/build-android.ts +0 -226
  156. package/scripts/build-native-termux.sh +0 -525
  157. package/scripts/build.ts +0 -530
  158. package/scripts/dist-test.ts +0 -312
  159. package/scripts/package-prebuilt.ts +0 -110
  160. package/scripts/publish.ts +0 -60
  161. package/scripts/test-node-hook.mjs +0 -16
  162. package/scripts/test-node.ts +0 -241
  163. package/scripts/vendor-deps.sh +0 -73
  164. package/src/NativeSpanFeed.ts +0 -375
  165. package/src/Renderable.ts +0 -1878
  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 -22
  170. package/src/audio.ts +0 -479
  171. package/src/benchmark/attenuation-benchmark.ts +0 -81
  172. package/src/benchmark/audio-playback-benchmark.ts +0 -344
  173. package/src/benchmark/box-draw-benchmark.ts +0 -1042
  174. package/src/benchmark/colormatrix-benchmark.ts +0 -123
  175. package/src/benchmark/gain-benchmark.ts +0 -80
  176. package/src/benchmark/latest-all-bench-run.json +0 -707
  177. package/src/benchmark/latest-async-bench-run.json +0 -336
  178. package/src/benchmark/latest-default-bench-run.json +0 -657
  179. package/src/benchmark/latest-large-bench-run.json +0 -707
  180. package/src/benchmark/latest-quick-bench-run.json +0 -207
  181. package/src/benchmark/layout-benchmark.ts +0 -2547
  182. package/src/benchmark/markdown-benchmark.ts +0 -1796
  183. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  184. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  185. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  186. package/src/benchmark/native-span-feed-compare.ts +0 -280
  187. package/src/benchmark/render-traversal-benchmark.ts +0 -928
  188. package/src/benchmark/text-buffer-render-benchmark.ts +0 -874
  189. package/src/benchmark/text-table-benchmark.ts +0 -948
  190. package/src/buffer.test.ts +0 -292
  191. package/src/buffer.ts +0 -564
  192. package/src/console.test.ts +0 -629
  193. package/src/console.ts +0 -1253
  194. package/src/edit-buffer.test.ts +0 -1852
  195. package/src/edit-buffer.ts +0 -417
  196. package/src/editor-view.test.ts +0 -1056
  197. package/src/editor-view.ts +0 -290
  198. package/src/index.ts +0 -25
  199. package/src/lib/KeyHandler.integration.test.ts +0 -292
  200. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  201. package/src/lib/KeyHandler.test.ts +0 -662
  202. package/src/lib/KeyHandler.ts +0 -222
  203. package/src/lib/RGBA.test.ts +0 -60
  204. package/src/lib/RGBA.ts +0 -343
  205. package/src/lib/ascii.font.ts +0 -330
  206. package/src/lib/border.test.ts +0 -83
  207. package/src/lib/border.ts +0 -170
  208. package/src/lib/bunfs.test.ts +0 -27
  209. package/src/lib/bunfs.ts +0 -18
  210. package/src/lib/clipboard.test.ts +0 -63
  211. package/src/lib/clipboard.ts +0 -41
  212. package/src/lib/clock.ts +0 -35
  213. package/src/lib/data-paths.test.ts +0 -133
  214. package/src/lib/data-paths.ts +0 -109
  215. package/src/lib/debounce.ts +0 -106
  216. package/src/lib/detect-links.test.ts +0 -98
  217. package/src/lib/detect-links.ts +0 -56
  218. package/src/lib/env.test.ts +0 -228
  219. package/src/lib/env.ts +0 -209
  220. package/src/lib/extmarks-history.ts +0 -51
  221. package/src/lib/extmarks-multiwidth.test.ts +0 -324
  222. package/src/lib/extmarks.test.ts +0 -3547
  223. package/src/lib/extmarks.ts +0 -861
  224. package/src/lib/fonts/block.json +0 -405
  225. package/src/lib/fonts/grid.json +0 -265
  226. package/src/lib/fonts/huge.json +0 -741
  227. package/src/lib/fonts/pallet.json +0 -314
  228. package/src/lib/fonts/shade.json +0 -591
  229. package/src/lib/fonts/slick.json +0 -321
  230. package/src/lib/fonts/tiny.json +0 -69
  231. package/src/lib/hast-styled-text.ts +0 -59
  232. package/src/lib/index.ts +0 -22
  233. package/src/lib/keybinding.internal.test.ts +0 -342
  234. package/src/lib/keybinding.internal.ts +0 -182
  235. package/src/lib/objects-in-viewport.test.ts +0 -789
  236. package/src/lib/objects-in-viewport.ts +0 -153
  237. package/src/lib/output.capture.ts +0 -58
  238. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -347
  239. package/src/lib/parse.keypress-kitty.test.ts +0 -712
  240. package/src/lib/parse.keypress-kitty.ts +0 -470
  241. package/src/lib/parse.keypress.test.ts +0 -2020
  242. package/src/lib/parse.keypress.ts +0 -480
  243. package/src/lib/parse.mouse.test.ts +0 -552
  244. package/src/lib/parse.mouse.ts +0 -232
  245. package/src/lib/paste.ts +0 -18
  246. package/src/lib/queue.ts +0 -65
  247. package/src/lib/render-geometry.ts +0 -36
  248. package/src/lib/renderable.validations.test.ts +0 -87
  249. package/src/lib/renderable.validations.ts +0 -83
  250. package/src/lib/scroll-acceleration.ts +0 -98
  251. package/src/lib/selection.ts +0 -261
  252. package/src/lib/singleton.ts +0 -34
  253. package/src/lib/stdin-parser.test.ts +0 -2439
  254. package/src/lib/stdin-parser.ts +0 -2007
  255. package/src/lib/styled-text.ts +0 -178
  256. package/src/lib/terminal-capability-detection.test.ts +0 -226
  257. package/src/lib/terminal-capability-detection.ts +0 -98
  258. package/src/lib/terminal-palette.test.ts +0 -954
  259. package/src/lib/terminal-palette.ts +0 -441
  260. package/src/lib/tree-sitter/assets/README.md +0 -119
  261. package/src/lib/tree-sitter/assets/update.ts +0 -360
  262. package/src/lib/tree-sitter/assets.d.ts +0 -9
  263. package/src/lib/tree-sitter/cache.test.ts +0 -291
  264. package/src/lib/tree-sitter/client.test.ts +0 -1434
  265. package/src/lib/tree-sitter/client.ts +0 -847
  266. package/src/lib/tree-sitter/default-parsers.ts +0 -133
  267. package/src/lib/tree-sitter/download-utils.ts +0 -148
  268. package/src/lib/tree-sitter/index.ts +0 -75
  269. package/src/lib/tree-sitter/parser.worker.ts +0 -1098
  270. package/src/lib/tree-sitter/parsers-config.ts +0 -81
  271. package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
  272. package/src/lib/tree-sitter/resolve-ft.ts +0 -189
  273. package/src/lib/tree-sitter/types.ts +0 -132
  274. package/src/lib/tree-sitter/update-assets.ts +0 -10
  275. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  276. package/src/lib/tree-sitter-styled-text.ts +0 -314
  277. package/src/lib/validate-dir-name.ts +0 -55
  278. package/src/lib/yoga.options.test.ts +0 -628
  279. package/src/lib/yoga.options.ts +0 -346
  280. package/src/native-event-worker-repro.test.ts +0 -48
  281. package/src/native-event-worker-repro.worker.ts +0 -9
  282. package/src/native-handle.test.ts +0 -221
  283. package/src/platform/ffi.test.ts +0 -516
  284. package/src/platform/ffi.ts +0 -653
  285. package/src/platform/runtime.test.ts +0 -52
  286. package/src/platform/runtime.ts +0 -121
  287. package/src/platform/test.ts +0 -45
  288. package/src/platform/worker-handler-cleanup.fixture.ts +0 -12
  289. package/src/platform/worker-onmessage-startup.fixture.ts +0 -10
  290. package/src/platform/worker-startup.fixture.ts +0 -9
  291. package/src/platform/worker.node-test.ts +0 -153
  292. package/src/platform/worker.ts +0 -425
  293. package/src/plugins/core-slot.ts +0 -579
  294. package/src/plugins/registry.ts +0 -402
  295. package/src/plugins/types.ts +0 -46
  296. package/src/post/effects.ts +0 -948
  297. package/src/post/filters.ts +0 -512
  298. package/src/post/matrices.ts +0 -288
  299. package/src/renderables/ASCIIFont.ts +0 -219
  300. package/src/renderables/Box.test.ts +0 -474
  301. package/src/renderables/Box.ts +0 -353
  302. package/src/renderables/Code.test.ts +0 -2388
  303. package/src/renderables/Code.ts +0 -555
  304. package/src/renderables/Diff.regression.test.ts +0 -381
  305. package/src/renderables/Diff.test.ts +0 -3212
  306. package/src/renderables/Diff.ts +0 -1278
  307. package/src/renderables/EditBufferRenderable.test.ts +0 -288
  308. package/src/renderables/EditBufferRenderable.ts +0 -1152
  309. package/src/renderables/FrameBuffer.ts +0 -47
  310. package/src/renderables/Input.test.ts +0 -1310
  311. package/src/renderables/Input.ts +0 -273
  312. package/src/renderables/LineNumberRenderable.ts +0 -725
  313. package/src/renderables/Markdown.ts +0 -2144
  314. package/src/renderables/ScrollBar.ts +0 -423
  315. package/src/renderables/ScrollBox.ts +0 -903
  316. package/src/renderables/Select.test.ts +0 -1134
  317. package/src/renderables/Select.ts +0 -535
  318. package/src/renderables/Slider.test.ts +0 -456
  319. package/src/renderables/Slider.ts +0 -342
  320. package/src/renderables/TabSelect.test.ts +0 -238
  321. package/src/renderables/TabSelect.ts +0 -447
  322. package/src/renderables/Text.selection-buffer.test.ts +0 -118
  323. package/src/renderables/Text.test.ts +0 -2662
  324. package/src/renderables/Text.ts +0 -147
  325. package/src/renderables/TextBufferRenderable.ts +0 -504
  326. package/src/renderables/TextNode.test.ts +0 -1137
  327. package/src/renderables/TextNode.ts +0 -379
  328. package/src/renderables/TextTable.test.ts +0 -1411
  329. package/src/renderables/TextTable.ts +0 -1434
  330. package/src/renderables/Textarea.ts +0 -425
  331. package/src/renderables/TimeToFirstDraw.ts +0 -89
  332. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  333. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  334. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  335. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  336. package/src/renderables/__tests__/Code.test.ts +0 -55
  337. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  338. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -827
  339. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1906
  340. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  341. package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -288
  342. package/src/renderables/__tests__/Markdown.test.ts +0 -4175
  343. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  344. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -683
  345. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  346. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2120
  347. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  348. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  349. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  350. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3275
  351. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  352. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1927
  353. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  354. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1589
  355. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  356. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  357. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  358. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  359. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  360. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  361. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  362. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  363. package/src/renderables/__tests__/markdown-parser.test.ts +0 -241
  364. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  365. package/src/renderables/composition/README.md +0 -8
  366. package/src/renderables/composition/VRenderable.ts +0 -32
  367. package/src/renderables/composition/constructs.ts +0 -127
  368. package/src/renderables/composition/vnode.ts +0 -277
  369. package/src/renderables/index.ts +0 -23
  370. package/src/renderables/markdown-parser.ts +0 -79
  371. package/src/renderer-theme-mode.ts +0 -199
  372. package/src/renderer.ts +0 -4975
  373. package/src/runtime-plugin-support-configure.ts +0 -63
  374. package/src/runtime-plugin-support.ts +0 -13
  375. package/src/runtime-plugin.ts +0 -626
  376. package/src/specs/terminal-startup.md +0 -64
  377. package/src/syntax-style.test.ts +0 -841
  378. package/src/syntax-style.ts +0 -274
  379. package/src/testing/README.md +0 -219
  380. package/src/testing/bun-test-node.ts +0 -880
  381. package/src/testing/capture-spans.test.ts +0 -216
  382. package/src/testing/integration.test.ts +0 -276
  383. package/src/testing/manual-clock.ts +0 -117
  384. package/src/testing/mock-keys.test.ts +0 -1378
  385. package/src/testing/mock-keys.ts +0 -457
  386. package/src/testing/mock-mouse.test.ts +0 -218
  387. package/src/testing/mock-mouse.ts +0 -247
  388. package/src/testing/mock-tree-sitter-client.ts +0 -81
  389. package/src/testing/spy.ts +0 -13
  390. package/src/testing/terminal-capabilities.ts +0 -47
  391. package/src/testing/test-recorder.test.ts +0 -410
  392. package/src/testing/test-recorder.ts +0 -133
  393. package/src/testing/test-renderer.ts +0 -375
  394. package/src/testing/test-renderer.wait.test.ts +0 -278
  395. package/src/testing/test-streams.ts +0 -31
  396. package/src/testing.ts +0 -9
  397. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  398. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  399. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  400. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  401. package/src/tests/allocator-stats.test.ts +0 -53
  402. package/src/tests/audio.test.ts +0 -303
  403. package/src/tests/destroy-during-render.test.ts +0 -200
  404. package/src/tests/destroy-on-exit.fixture.ts +0 -36
  405. package/src/tests/destroy-on-exit.test.ts +0 -62
  406. package/src/tests/ffi-borrowed-pointer-callsites.test.ts +0 -153
  407. package/src/tests/hover-cursor.test.ts +0 -98
  408. package/src/tests/native-backed-measurement-lifecycle.test.ts +0 -133
  409. package/src/tests/native-backed-measurement-parity.test.ts +0 -322
  410. package/src/tests/native-span-feed-async.test.ts +0 -173
  411. package/src/tests/native-span-feed-close.test.ts +0 -120
  412. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  413. package/src/tests/native-span-feed-edge-cases.test.ts +0 -384
  414. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  415. package/src/tests/opacity.test.ts +0 -123
  416. package/src/tests/renderable.snapshot.test.ts +0 -524
  417. package/src/tests/renderable.test.ts +0 -1851
  418. package/src/tests/renderer.clock.test.ts +0 -270
  419. package/src/tests/renderer.console-startup.test.ts +0 -2151
  420. package/src/tests/renderer.control.test.ts +0 -458
  421. package/src/tests/renderer.core-slot-binding.test.ts +0 -962
  422. package/src/tests/renderer.cursor.test.ts +0 -26
  423. package/src/tests/renderer.custom-stdout.test.ts +0 -1112
  424. package/src/tests/renderer.destroy-during-render.test.ts +0 -147
  425. package/src/tests/renderer.focus-restore.test.ts +0 -257
  426. package/src/tests/renderer.focus.test.ts +0 -329
  427. package/src/tests/renderer.idle.test.ts +0 -219
  428. package/src/tests/renderer.input.test.ts +0 -2615
  429. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  430. package/src/tests/renderer.lifecycle.test.ts +0 -34
  431. package/src/tests/renderer.mouse.test.ts +0 -1315
  432. package/src/tests/renderer.notifications.test.ts +0 -27
  433. package/src/tests/renderer.palette.test.ts +0 -1199
  434. package/src/tests/renderer.remote.test.ts +0 -247
  435. package/src/tests/renderer.render-stats.test.ts +0 -146
  436. package/src/tests/renderer.scrollback-surface.test.ts +0 -474
  437. package/src/tests/renderer.selection.test.ts +0 -138
  438. package/src/tests/renderer.slot-registry.test.ts +0 -684
  439. package/src/tests/renderer.tracker.test.ts +0 -202
  440. package/src/tests/renderer.useMouse.test.ts +0 -83
  441. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
  442. package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +0 -48
  443. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
  444. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
  445. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
  446. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
  447. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
  448. package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
  449. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
  450. package/src/tests/runtime-plugin-support-configure.fixture.ts +0 -31
  451. package/src/tests/runtime-plugin-support-late-addition.fixture.ts +0 -17
  452. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  453. package/src/tests/runtime-plugin-support.test.ts +0 -54
  454. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
  455. package/src/tests/runtime-plugin.fixture.ts +0 -40
  456. package/src/tests/runtime-plugin.test.ts +0 -369
  457. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  458. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  459. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  460. package/src/tests/scrollbox.test.ts +0 -1895
  461. package/src/tests/wrap-resize-perf.test.ts +0 -276
  462. package/src/tests/yoga-api-coverage.test.ts +0 -409
  463. package/src/tests/yoga-callback-stress.test.ts +0 -122
  464. package/src/tests/yoga-ffi.test.ts +0 -117
  465. package/src/tests/yoga-setters.test.ts +0 -921
  466. package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +0 -124
  467. package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +0 -27
  468. package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +0 -27
  469. package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +0 -27
  470. package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +0 -157
  471. package/src/tests/yoga-upstream/YGErrataTest.test.ts +0 -40
  472. package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +0 -23
  473. package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +0 -81
  474. package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +0 -31
  475. package/src/tests/yoga-upstream/YGMeasureTest.test.ts +0 -70
  476. package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +0 -1864
  477. package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +0 -5829
  478. package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +0 -2444
  479. package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +0 -293
  480. package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +0 -315
  481. package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +0 -231
  482. package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +0 -347
  483. package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +0 -256
  484. package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +0 -2747
  485. package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +0 -129
  486. package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +0 -109
  487. package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +0 -1097
  488. package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +0 -4562
  489. package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +0 -677
  490. package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +0 -2071
  491. package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +0 -3303
  492. package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +0 -582
  493. package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +0 -2150
  494. package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +0 -1963
  495. package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +0 -1446
  496. package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +0 -354
  497. package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +0 -1760
  498. package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +0 -1161
  499. package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +0 -207
  500. package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +0 -6338
  501. package/src/tests/yoga-upstream/tools/MeasureCounter.ts +0 -54
  502. package/src/tests/yoga-upstream/tools/utils.ts +0 -81
  503. package/src/text-buffer-view.test.ts +0 -722
  504. package/src/text-buffer-view.ts +0 -193
  505. package/src/text-buffer.test.ts +0 -512
  506. package/src/text-buffer.ts +0 -250
  507. package/src/types.ts +0 -199
  508. package/src/utils.ts +0 -88
  509. package/src/yoga.ts +0 -1146
  510. package/src/zig/ansi.zig +0 -502
  511. package/src/zig/audio.zig +0 -1206
  512. package/src/zig/bench/README.md +0 -50
  513. package/src/zig/bench/buffer-color-blending_bench.zig +0 -350
  514. package/src/zig/bench/buffer-draw-box_bench.zig +0 -786
  515. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -894
  516. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  517. package/src/zig/bench/editor-view_bench.zig +0 -169
  518. package/src/zig/bench/native-span-feed_bench.zig +0 -107
  519. package/src/zig/bench/rope-markers_bench.zig +0 -713
  520. package/src/zig/bench/rope_bench.zig +0 -514
  521. package/src/zig/bench/styled-text_bench.zig +0 -476
  522. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  523. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  524. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -272
  525. package/src/zig/bench/utf8_bench.zig +0 -799
  526. package/src/zig/bench-utils.zig +0 -431
  527. package/src/zig/bench.zig +0 -223
  528. package/src/zig/buffer-methods.zig +0 -215
  529. package/src/zig/buffer.zig +0 -2515
  530. package/src/zig/build.zig +0 -700
  531. package/src/zig/build.zig.zon +0 -19
  532. package/src/zig/edit-buffer.zig +0 -900
  533. package/src/zig/editor-view.zig +0 -812
  534. package/src/zig/event-bus.zig +0 -28
  535. package/src/zig/event-emitter.zig +0 -65
  536. package/src/zig/file-logger.zig +0 -92
  537. package/src/zig/grapheme.zig +0 -838
  538. package/src/zig/handles.zig +0 -267
  539. package/src/zig/lib.zig +0 -2813
  540. package/src/zig/link.zig +0 -349
  541. package/src/zig/logger.zig +0 -43
  542. package/src/zig/mem-registry.zig +0 -126
  543. package/src/zig/miniaudio_shim.c +0 -21
  544. package/src/zig/native-renderable.zig +0 -112
  545. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  546. package/src/zig/native-span-feed.zig +0 -747
  547. package/src/zig/renderer-output.zig +0 -677
  548. package/src/zig/renderer.zig +0 -2106
  549. package/src/zig/rope.zig +0 -1220
  550. package/src/zig/split-scrollback.zig +0 -88
  551. package/src/zig/syntax-style.zig +0 -174
  552. package/src/zig/terminal.zig +0 -1652
  553. package/src/zig/test.zig +0 -82
  554. package/src/zig/tests/README.md +0 -18
  555. package/src/zig/tests/ansi_test.zig +0 -18
  556. package/src/zig/tests/audio_test.zig +0 -439
  557. package/src/zig/tests/buffer-methods_test.zig +0 -1111
  558. package/src/zig/tests/buffer_test.zig +0 -2926
  559. package/src/zig/tests/edit-buffer-history_test.zig +0 -299
  560. package/src/zig/tests/edit-buffer_test.zig +0 -1688
  561. package/src/zig/tests/editor-view_test.zig +0 -3454
  562. package/src/zig/tests/event-emitter_test.zig +0 -249
  563. package/src/zig/tests/grapheme_test.zig +0 -1329
  564. package/src/zig/tests/handles_test.zig +0 -123
  565. package/src/zig/tests/link_test.zig +0 -220
  566. package/src/zig/tests/mem-registry_test.zig +0 -473
  567. package/src/zig/tests/memory_leak_regression_test.zig +0 -234
  568. package/src/zig/tests/native-renderable_test.zig +0 -16
  569. package/src/zig/tests/native-span-feed_test.zig +0 -1266
  570. package/src/zig/tests/renderer_test.zig +0 -2604
  571. package/src/zig/tests/rope-nested_test.zig +0 -712
  572. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  573. package/src/zig/tests/rope_test.zig +0 -2362
  574. package/src/zig/tests/segment-merge.test.zig +0 -148
  575. package/src/zig/tests/split-scrollback_test.zig +0 -70
  576. package/src/zig/tests/syntax-style_test.zig +0 -558
  577. package/src/zig/tests/terminal_test.zig +0 -1489
  578. package/src/zig/tests/test-renderer.zig +0 -126
  579. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3291
  580. package/src/zig/tests/text-buffer-highlights_test.zig +0 -706
  581. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  582. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  583. package/src/zig/tests/text-buffer-selection_test.zig +0 -1056
  584. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  585. package/src/zig/tests/text-buffer-view_test.zig +0 -3672
  586. package/src/zig/tests/text-buffer_test.zig +0 -2191
  587. package/src/zig/tests/unicode-width-map.zon +0 -3909
  588. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  589. package/src/zig/tests/utf8_test.zig +0 -4060
  590. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  591. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  592. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  593. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  594. package/src/zig/tests/yoga_test.zig +0 -65
  595. package/src/zig/text-buffer-iterators.zig +0 -496
  596. package/src/zig/text-buffer-segment.zig +0 -403
  597. package/src/zig/text-buffer-view.zig +0 -1428
  598. package/src/zig/text-buffer.zig +0 -1272
  599. package/src/zig/utf8.zig +0 -1954
  600. package/src/zig/utils.zig +0 -12
  601. package/src/zig/uucode-stub.zig +0 -76
  602. package/src/zig/vendor/miniaudio/miniaudio.h +0 -93468
  603. package/src/zig/yoga.zig +0 -658
  604. package/src/zig-structs.ts +0 -381
  605. package/src/zig.ts +0 -5260
  606. package/tsconfig.build.json +0 -17
  607. package/tsconfig.json +0 -27
  608. package/tsconfig.node-test.json +0 -138
  609. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  610. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  611. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  612. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  613. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  614. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  615. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  616. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  617. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  618. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  619. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,63 +0,0 @@
1
- import { plugin as registerBunPlugin } from "bun"
2
- import { createRuntimePlugin, type CreateRuntimePluginOptions, type RuntimeModuleEntry } from "./runtime-plugin.js"
3
-
4
- const runtimePluginSupportInstalledKey = "__opentuiCoreRuntimePluginSupportInstalled__"
5
-
6
- interface RuntimePluginSupportInstall {
7
- additionalSpecifiers: ReadonlySet<string>
8
- core?: RuntimeModuleEntry
9
- rewriteKey: string
10
- }
11
-
12
- type RuntimePluginSupportState = typeof globalThis & {
13
- [runtimePluginSupportInstalledKey]?: RuntimePluginSupportInstall
14
- }
15
-
16
- function normalizeRewriteKey(rewrite: CreateRuntimePluginOptions["rewrite"] | undefined): string {
17
- return `${rewrite?.nodeModulesRuntimeSpecifiers ?? true}:${rewrite?.nodeModulesBareSpecifiers ?? false}`
18
- }
19
-
20
- function assertCompatibleInstall(install: RuntimePluginSupportInstall, options: CreateRuntimePluginOptions): void {
21
- for (const specifier of Object.keys(options.additional ?? {})) {
22
- if (!install.additionalSpecifiers.has(specifier)) {
23
- throw new Error(
24
- `OpenTUI Core runtime plugin support is already installed without ${specifier}. Call ensureRuntimePluginSupport({ additional }) from @opentui/core/runtime-plugin-support/configure before importing @opentui/core/runtime-plugin-support.`,
25
- )
26
- }
27
- }
28
-
29
- if (options.core && options.core !== install.core) {
30
- throw new Error("OpenTUI Core runtime plugin support is already installed with a different core runtime module.")
31
- }
32
-
33
- if (options.rewrite && normalizeRewriteKey(options.rewrite) !== install.rewriteKey) {
34
- throw new Error("OpenTUI Core runtime plugin support is already installed with different rewrite options.")
35
- }
36
- }
37
-
38
- export function ensureRuntimePluginSupport(options: CreateRuntimePluginOptions = {}): boolean {
39
- const state = globalThis as RuntimePluginSupportState
40
- const install = state[runtimePluginSupportInstalledKey]
41
-
42
- if (install) {
43
- assertCompatibleInstall(install, options)
44
- return false
45
- }
46
-
47
- registerBunPlugin(createRuntimePlugin(options))
48
-
49
- state[runtimePluginSupportInstalledKey] = {
50
- additionalSpecifiers: new Set(Object.keys(options.additional ?? {})),
51
- core: options.core,
52
- rewriteKey: normalizeRewriteKey(options.rewrite),
53
- }
54
- return true
55
- }
56
-
57
- export { createRuntimePlugin, runtimeModuleIdForSpecifier } from "./runtime-plugin.js"
58
- export type {
59
- CreateRuntimePluginOptions,
60
- RuntimeModuleEntry,
61
- RuntimeModuleExports,
62
- RuntimeModuleLoader,
63
- } from "./runtime-plugin.js"
@@ -1,13 +0,0 @@
1
- import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js"
2
-
3
- export { ensureRuntimePluginSupport }
4
- export {
5
- createRuntimePlugin,
6
- runtimeModuleIdForSpecifier,
7
- type CreateRuntimePluginOptions,
8
- type RuntimeModuleEntry,
9
- type RuntimeModuleExports,
10
- type RuntimeModuleLoader,
11
- } from "./runtime-plugin-support-configure.js"
12
-
13
- ensureRuntimePluginSupport()
@@ -1,626 +0,0 @@
1
- /*
2
- * Exposes runtime-only modules (for example `@opentui/core`, `@opentui/solid`,
3
- * `solid-js`) to externally loaded plugins by rewriting matching imports to
4
- * virtual `opentui:runtime-module:*` ids.
5
- *
6
- * Why this is exact-path + prescan instead of one broad `onLoad`:
7
- * - Bun can break CJS/UMD interop if a file is routed through plugin `onLoad`
8
- * (real repro: `jsonc-parser` resolving to `lib/umd/main.js`;
9
- * https://github.com/oven-sh/bun/issues/19279,
10
- * https://github.com/oven-sh/bun/issues/21369), so arbitrary `node_modules`
11
- * JS cannot be blanket-rewritten.
12
- * - runtime `onResolve` is sync-only, so package/type/source discovery here is
13
- * synchronous and cached.
14
- * - a matched `onLoad` cannot safely fall through, so loaders must be narrow.
15
- * - Bun may canonicalize paths before `onLoad`, so loaders are registered for
16
- * both the resolved path spelling and its realpath, then canonical-checked.
17
- * - Bun may native-load `node_modules` ESM without firing `onResolve` for
18
- * nested package imports, so `node_modules` ESM is recursively prescanned and
19
- * only files that actually need runtime rewriting get exact-path loaders.
20
- *
21
- * Behavior:
22
- * - non-`node_modules` source files get a dedicated rewrite loader immediately.
23
- * - `node_modules` files are rewritten only if they are ESM (`.mjs`, `.mts`,
24
- * `.ts`, `.tsx`, `.jsx`, or `.js` under `package.json#type="module"`) and
25
- * directly or transitively need runtime-module rewriting; unrelated CJS stays
26
- * untouched.
27
- * - optional bare-specifier rewriting is preserved for sibling files in
28
- * packages already marked for runtime rewriting.
29
- *
30
- * Notes:
31
- * - import scanning is regex-based, not a full parser.
32
- * - CJS helper libraries that themselves import runtime modules are still not
33
- * supported.
34
- * - `package.json#type` caching is per plugin setup, not module-global, so a
35
- * later plugin instance in the same process can observe filesystem changes.
36
- */
37
- import { existsSync, readFileSync, realpathSync } from "node:fs"
38
- import { basename, dirname, isAbsolute, join } from "node:path"
39
- import { fileURLToPath } from "node:url"
40
- import { type BunPlugin } from "bun"
41
- import * as coreRuntime from "./index.js"
42
-
43
- export type RuntimeModuleExports = Record<string, unknown>
44
- export type RuntimeModuleLoader = () => RuntimeModuleExports | Promise<RuntimeModuleExports>
45
- export type RuntimeModuleEntry = RuntimeModuleExports | RuntimeModuleLoader
46
-
47
- interface SourceAnalysis {
48
- importSpecifiers: string[]
49
- needsRuntimeSpecifierRewrite: boolean
50
- }
51
-
52
- export interface RuntimePluginRewriteOptions {
53
- nodeModulesRuntimeSpecifiers?: boolean
54
- nodeModulesBareSpecifiers?: boolean
55
- }
56
-
57
- export interface CreateRuntimePluginOptions {
58
- core?: RuntimeModuleEntry
59
- additional?: Record<string, RuntimeModuleEntry>
60
- rewrite?: RuntimePluginRewriteOptions
61
- }
62
-
63
- const CORE_RUNTIME_SPECIFIER = "@opentui/core"
64
- const CORE_TESTING_RUNTIME_SPECIFIER = "@opentui/core/testing"
65
- const RUNTIME_MODULE_PREFIX = "opentui:runtime-module:"
66
- const MAX_RUNTIME_RESOLVE_PARENTS = 64
67
- const DEFAULT_RUNTIME_PLUGIN_REWRITE_OPTIONS: Required<RuntimePluginRewriteOptions> = {
68
- nodeModulesRuntimeSpecifiers: true,
69
- nodeModulesBareSpecifiers: false,
70
- }
71
-
72
- const DEFAULT_CORE_RUNTIME_MODULE_SPECIFIERS = [CORE_RUNTIME_SPECIFIER, CORE_TESTING_RUNTIME_SPECIFIER] as const
73
-
74
- const DEFAULT_CORE_RUNTIME_MODULE_SPECIFIER_SET = new Set<string>(DEFAULT_CORE_RUNTIME_MODULE_SPECIFIERS)
75
-
76
- export const isCoreRuntimeModuleSpecifier = (specifier: string): boolean => {
77
- return DEFAULT_CORE_RUNTIME_MODULE_SPECIFIER_SET.has(specifier)
78
- }
79
-
80
- const loadCoreTestingRuntimeModule = async (): Promise<RuntimeModuleExports> => {
81
- return (await import("./testing.js")) as RuntimeModuleExports
82
- }
83
-
84
- const escapeRegExp = (value: string): string => {
85
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
86
- }
87
-
88
- const exactSpecifierFilter = (specifier: string): RegExp => {
89
- return new RegExp(`^${escapeRegExp(specifier)}$`)
90
- }
91
-
92
- const exactPathFilter = (paths: string[]): RegExp => {
93
- const candidates = [...new Set(paths.map(sourcePath))]
94
- return new RegExp(`^(?:${candidates.map(escapeRegExp).join("|")})(?:[?#].*)?$`)
95
- }
96
-
97
- export const runtimeModuleIdForSpecifier = (specifier: string): string => {
98
- return `${RUNTIME_MODULE_PREFIX}${encodeURIComponent(specifier)}`
99
- }
100
-
101
- const resolveRuntimeModuleExports = async (moduleEntry: RuntimeModuleEntry): Promise<RuntimeModuleExports> => {
102
- if (typeof moduleEntry === "function") {
103
- return await moduleEntry()
104
- }
105
-
106
- return moduleEntry
107
- }
108
-
109
- const sourcePath = (path: string): string => {
110
- const searchIndex = path.indexOf("?")
111
- const hashIndex = path.indexOf("#")
112
- const end = [searchIndex, hashIndex].filter((index) => index >= 0).sort((a, b) => a - b)[0]
113
- return end === undefined ? path : path.slice(0, end)
114
- }
115
-
116
- const normalizedSourcePathByPath = new Map<string, string>()
117
-
118
- const normalizeSourcePath = (path: string): string => {
119
- const cleanPath = sourcePath(path)
120
- const cachedPath = normalizedSourcePathByPath.get(cleanPath)
121
- if (cachedPath !== undefined) {
122
- return cachedPath
123
- }
124
-
125
- let normalizedPath = cleanPath
126
-
127
- try {
128
- normalizedPath = realpathSync(cleanPath)
129
- } catch {
130
- normalizedPath = cleanPath
131
- }
132
-
133
- normalizedSourcePathByPath.set(cleanPath, normalizedPath)
134
- return normalizedPath
135
- }
136
-
137
- const isNodeModulesPath = (path: string): boolean => {
138
- return /(?:^|[/\\])node_modules(?:[/\\])/.test(path)
139
- }
140
-
141
- const packageTypeForPath = (
142
- path: string,
143
- packageTypeByPackageJsonPath: Map<string, "module" | "commonjs">,
144
- ): "module" | "commonjs" => {
145
- let currentDir = dirname(path)
146
-
147
- while (true) {
148
- const packageJsonPath = join(currentDir, "package.json")
149
- if (existsSync(packageJsonPath)) {
150
- const cachedPackageType = packageTypeByPackageJsonPath.get(packageJsonPath)
151
- if (cachedPackageType) {
152
- return cachedPackageType
153
- }
154
-
155
- let packageType: "module" | "commonjs" = "commonjs"
156
-
157
- try {
158
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as { type?: string }
159
- if (packageJson.type === "module") {
160
- packageType = "module"
161
- }
162
- } catch {
163
- packageType = "commonjs"
164
- }
165
-
166
- packageTypeByPackageJsonPath.set(packageJsonPath, packageType)
167
- return packageType
168
- }
169
-
170
- const parentDir = dirname(currentDir)
171
- if (parentDir === currentDir) {
172
- return "commonjs"
173
- }
174
-
175
- currentDir = parentDir
176
- }
177
- }
178
-
179
- const isNodeModulesEsmPath = (
180
- path: string,
181
- packageTypeByPackageJsonPath: Map<string, "module" | "commonjs">,
182
- ): boolean => {
183
- const normalizedPath = normalizeSourcePath(path)
184
-
185
- if (!isNodeModulesPath(normalizedPath)) {
186
- return false
187
- }
188
-
189
- if (
190
- normalizedPath.endsWith(".mjs") ||
191
- normalizedPath.endsWith(".mts") ||
192
- normalizedPath.endsWith(".ts") ||
193
- normalizedPath.endsWith(".tsx") ||
194
- normalizedPath.endsWith(".jsx")
195
- ) {
196
- return true
197
- }
198
-
199
- if (normalizedPath.endsWith(".cjs") || normalizedPath.endsWith(".cts") || !normalizedPath.endsWith(".js")) {
200
- return false
201
- }
202
-
203
- return packageTypeForPath(normalizedPath, packageTypeByPackageJsonPath) === "module"
204
- }
205
-
206
- const nodeModulesPackageRootForPath = (path: string): string | null => {
207
- let currentDir = dirname(path)
208
-
209
- while (true) {
210
- const parentDir = dirname(currentDir)
211
- if (parentDir === currentDir) {
212
- return null
213
- }
214
-
215
- if (basename(parentDir) === "node_modules") {
216
- return currentDir
217
- }
218
-
219
- if (basename(dirname(parentDir)) === "node_modules" && basename(parentDir).startsWith("@")) {
220
- return currentDir
221
- }
222
-
223
- currentDir = parentDir
224
- }
225
- }
226
-
227
- const resolveRuntimePluginRewriteOptions = (
228
- options: RuntimePluginRewriteOptions | undefined,
229
- ): Required<RuntimePluginRewriteOptions> => {
230
- return {
231
- nodeModulesRuntimeSpecifiers:
232
- options?.nodeModulesRuntimeSpecifiers ?? DEFAULT_RUNTIME_PLUGIN_REWRITE_OPTIONS.nodeModulesRuntimeSpecifiers,
233
- nodeModulesBareSpecifiers:
234
- options?.nodeModulesBareSpecifiers ?? DEFAULT_RUNTIME_PLUGIN_REWRITE_OPTIONS.nodeModulesBareSpecifiers,
235
- }
236
- }
237
-
238
- const runtimeLoaderForPath = (path: string): "js" | "ts" | "jsx" | "tsx" | null => {
239
- const cleanPath = sourcePath(path)
240
-
241
- if (cleanPath.endsWith(".tsx")) {
242
- return "tsx"
243
- }
244
-
245
- if (cleanPath.endsWith(".jsx")) {
246
- return "jsx"
247
- }
248
-
249
- if (cleanPath.endsWith(".ts") || cleanPath.endsWith(".mts") || cleanPath.endsWith(".cts")) {
250
- return "ts"
251
- }
252
-
253
- if (cleanPath.endsWith(".js") || cleanPath.endsWith(".mjs") || cleanPath.endsWith(".cjs")) {
254
- return "js"
255
- }
256
-
257
- return null
258
- }
259
-
260
- const resolveImportSpecifierPatterns = [
261
- /(from\s+["'])([^"']+)(["'])/g,
262
- /(import\s+["'])([^"']+)(["'])/g,
263
- /(import\s*\(\s*["'])([^"']+)(["']\s*\))/g,
264
- /(require\s*\(\s*["'])([^"']+)(["']\s*\))/g,
265
- ] as const
266
-
267
- const isBareSpecifier = (specifier: string): boolean => {
268
- if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("\\")) {
269
- return false
270
- }
271
-
272
- if (
273
- specifier.startsWith("node:") ||
274
- specifier.startsWith("bun:") ||
275
- specifier.startsWith("http:") ||
276
- specifier.startsWith("https:") ||
277
- specifier.startsWith("file:") ||
278
- specifier.startsWith("data:")
279
- ) {
280
- return false
281
- }
282
-
283
- if (specifier.startsWith(RUNTIME_MODULE_PREFIX)) {
284
- return false
285
- }
286
-
287
- return true
288
- }
289
-
290
- const registerResolveParent = (resolveParentsByRecency: string[], resolveParent: string): void => {
291
- const existingIndex = resolveParentsByRecency.indexOf(resolveParent)
292
- if (existingIndex >= 0) {
293
- resolveParentsByRecency.splice(existingIndex, 1)
294
- }
295
-
296
- resolveParentsByRecency.push(resolveParent)
297
-
298
- if (resolveParentsByRecency.length > MAX_RUNTIME_RESOLVE_PARENTS) {
299
- resolveParentsByRecency.shift()
300
- }
301
- }
302
-
303
- const rewriteImportSpecifiers = (code: string, resolveReplacement: (specifier: string) => string | null): string => {
304
- let transformedCode = code
305
-
306
- for (const pattern of resolveImportSpecifierPatterns) {
307
- transformedCode = transformedCode.replace(pattern, (fullMatch, prefix, specifier, suffix) => {
308
- const replacement = resolveReplacement(specifier)
309
- if (!replacement || replacement === specifier) {
310
- return fullMatch
311
- }
312
-
313
- return `${prefix}${replacement}${suffix}`
314
- })
315
- }
316
-
317
- return transformedCode
318
- }
319
-
320
- const collectImportSpecifiers = (code: string): string[] => {
321
- const specifiers = new Set<string>()
322
-
323
- for (const pattern of resolveImportSpecifierPatterns) {
324
- code.replace(pattern, (_fullMatch, _prefix, specifier) => {
325
- specifiers.add(specifier)
326
- return _fullMatch
327
- })
328
- }
329
-
330
- return [...specifiers]
331
- }
332
-
333
- const resolveFromParent = (specifier: string, parent: string): string | null => {
334
- try {
335
- const resolvedSpecifier = import.meta.resolve(specifier, parent)
336
- if (
337
- resolvedSpecifier === specifier ||
338
- resolvedSpecifier.startsWith("node:") ||
339
- resolvedSpecifier.startsWith("bun:")
340
- ) {
341
- return null
342
- }
343
-
344
- return resolvedSpecifier
345
- } catch {
346
- return null
347
- }
348
- }
349
-
350
- const resolveSourcePathFromSpecifier = (specifier: string, importer: string): string | null => {
351
- if (
352
- specifier.startsWith("node:") ||
353
- specifier.startsWith("bun:") ||
354
- specifier.startsWith("http:") ||
355
- specifier.startsWith("https:") ||
356
- specifier.startsWith("data:") ||
357
- specifier.startsWith(RUNTIME_MODULE_PREFIX)
358
- ) {
359
- return null
360
- }
361
-
362
- if (specifier.startsWith("file:")) {
363
- return sourcePath(fileURLToPath(specifier))
364
- }
365
-
366
- if (isAbsolute(specifier)) {
367
- return sourcePath(specifier)
368
- }
369
-
370
- const resolvedSpecifier = resolveFromParent(specifier, importer)
371
- if (!resolvedSpecifier) {
372
- return null
373
- }
374
-
375
- if (resolvedSpecifier.startsWith("file:")) {
376
- return sourcePath(fileURLToPath(resolvedSpecifier))
377
- }
378
-
379
- if (isAbsolute(resolvedSpecifier)) {
380
- return sourcePath(resolvedSpecifier)
381
- }
382
-
383
- return null
384
- }
385
-
386
- const rewriteImportsFromResolveParents = (code: string, resolveParentsByRecency: string[]): string => {
387
- if (resolveParentsByRecency.length === 0) {
388
- return code
389
- }
390
-
391
- const resolveFromParents = (specifier: string): string | null => {
392
- if (!isBareSpecifier(specifier)) {
393
- return null
394
- }
395
-
396
- for (let index = resolveParentsByRecency.length - 1; index >= 0; index -= 1) {
397
- const resolveParent = resolveParentsByRecency[index]
398
- const resolvedSpecifier = resolveFromParent(specifier, resolveParent)
399
- if (resolvedSpecifier) {
400
- return resolvedSpecifier
401
- }
402
- }
403
-
404
- return null
405
- }
406
-
407
- return rewriteImportSpecifiers(code, resolveFromParents)
408
- }
409
-
410
- const rewriteRuntimeSpecifiers = (code: string, runtimeModuleIdsBySpecifier: Map<string, string>): string => {
411
- return rewriteImportSpecifiers(code, (specifier) => {
412
- const runtimeModuleId = runtimeModuleIdsBySpecifier.get(specifier)
413
- return runtimeModuleId ?? null
414
- })
415
- }
416
-
417
- export function createRuntimePlugin(input: CreateRuntimePluginOptions = {}): BunPlugin {
418
- const runtimeModules = new Map<string, RuntimeModuleEntry>()
419
- runtimeModules.set(CORE_RUNTIME_SPECIFIER, input.core ?? (coreRuntime as RuntimeModuleExports))
420
- runtimeModules.set(CORE_TESTING_RUNTIME_SPECIFIER, loadCoreTestingRuntimeModule)
421
- const rewriteOptions = resolveRuntimePluginRewriteOptions(input.rewrite)
422
-
423
- for (const [specifier, moduleEntry] of Object.entries(input.additional ?? {})) {
424
- runtimeModules.set(specifier, moduleEntry)
425
- }
426
-
427
- const runtimeModuleIdsBySpecifier = new Map<string, string>()
428
- for (const specifier of runtimeModules.keys()) {
429
- runtimeModuleIdsBySpecifier.set(specifier, runtimeModuleIdForSpecifier(specifier))
430
- }
431
-
432
- return {
433
- name: "bun-plugin-opentui-runtime-modules",
434
- setup: (build) => {
435
- const resolveParentsByRecency: string[] = []
436
- const installedRewriteLoaders = new Set<string>()
437
- const nodeModulesBareRewritePackageRoots = new Set<string>()
438
- const packageTypeByPackageJsonPath = new Map<string, "module" | "commonjs">()
439
- const sourceAnalysisByPath = new Map<string, SourceAnalysis>()
440
- const nodeModulesRuntimeRewritePathsByPath = new Map<string, string[]>()
441
-
442
- const installRewriteLoader = (path: string): void => {
443
- const resolvedTargetPath = sourcePath(path)
444
- const canonicalTargetPath = normalizeSourcePath(resolvedTargetPath)
445
-
446
- if (installedRewriteLoaders.has(canonicalTargetPath)) {
447
- return
448
- }
449
-
450
- installedRewriteLoaders.add(canonicalTargetPath)
451
-
452
- // Register both the resolved path spelling and its canonical realpath so Bun
453
- // can reach the loader even if it reports the same file through a different alias.
454
- build.onLoad({ filter: exactPathFilter([resolvedTargetPath, canonicalTargetPath]) }, async (args) => {
455
- const loadedPath = normalizeSourcePath(args.path)
456
- if (loadedPath !== canonicalTargetPath) {
457
- return undefined
458
- }
459
-
460
- const nodeModulesPath = isNodeModulesPath(loadedPath)
461
- const shouldRewriteRuntimeSpecifiers = !nodeModulesPath || rewriteOptions.nodeModulesRuntimeSpecifiers
462
- const shouldRewriteBareSpecifiers = !nodeModulesPath || rewriteOptions.nodeModulesBareSpecifiers
463
- const loader = runtimeLoaderForPath(args.path)
464
-
465
- if (!loader) {
466
- throw new Error(`Unable to determine runtime loader for path: ${args.path}`)
467
- }
468
-
469
- const contents = await Bun.file(loadedPath).text()
470
- const runtimeRewrittenContents = shouldRewriteRuntimeSpecifiers
471
- ? rewriteRuntimeSpecifiers(contents, runtimeModuleIdsBySpecifier)
472
- : contents
473
-
474
- if (runtimeRewrittenContents !== contents && shouldRewriteBareSpecifiers) {
475
- registerResolveParent(resolveParentsByRecency, loadedPath)
476
- }
477
-
478
- const transformedContents = shouldRewriteBareSpecifiers
479
- ? rewriteImportsFromResolveParents(runtimeRewrittenContents, resolveParentsByRecency)
480
- : runtimeRewrittenContents
481
-
482
- return {
483
- contents: transformedContents,
484
- loader,
485
- }
486
- })
487
- }
488
-
489
- const analyzeSourcePath = (path: string): SourceAnalysis => {
490
- const normalizedPath = normalizeSourcePath(path)
491
- const cachedAnalysis = sourceAnalysisByPath.get(normalizedPath)
492
- if (cachedAnalysis) {
493
- return cachedAnalysis
494
- }
495
-
496
- let contents: string
497
- try {
498
- contents = readFileSync(normalizedPath, "utf8")
499
- } catch (error) {
500
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
501
- const analysis = { importSpecifiers: [], needsRuntimeSpecifierRewrite: false }
502
- sourceAnalysisByPath.set(normalizedPath, analysis)
503
- return analysis
504
- }
505
- throw error
506
- }
507
-
508
- const importSpecifiers = collectImportSpecifiers(contents)
509
- const analysis = {
510
- importSpecifiers,
511
- needsRuntimeSpecifierRewrite: importSpecifiers.some((specifier) =>
512
- runtimeModuleIdsBySpecifier.has(specifier),
513
- ),
514
- }
515
-
516
- sourceAnalysisByPath.set(normalizedPath, analysis)
517
- return analysis
518
- }
519
-
520
- const collectNodeModulesRuntimeRewritePaths = (path: string, visiting = new Set<string>()): string[] => {
521
- const normalizedPath = normalizeSourcePath(path)
522
-
523
- if (!isNodeModulesEsmPath(normalizedPath, packageTypeByPackageJsonPath)) {
524
- return []
525
- }
526
-
527
- const cachedPaths = nodeModulesRuntimeRewritePathsByPath.get(normalizedPath)
528
- if (cachedPaths) {
529
- return cachedPaths
530
- }
531
-
532
- if (visiting.has(normalizedPath)) {
533
- return []
534
- }
535
-
536
- visiting.add(normalizedPath)
537
-
538
- const rewritePaths = new Set<string>()
539
- const analysis = analyzeSourcePath(normalizedPath)
540
-
541
- if (analysis.needsRuntimeSpecifierRewrite) {
542
- rewritePaths.add(normalizedPath)
543
- }
544
-
545
- for (const specifier of analysis.importSpecifiers) {
546
- const resolvedPath = resolveSourcePathFromSpecifier(specifier, normalizedPath)
547
- if (!resolvedPath || !isNodeModulesEsmPath(resolvedPath, packageTypeByPackageJsonPath)) {
548
- continue
549
- }
550
-
551
- for (const nestedPath of collectNodeModulesRuntimeRewritePaths(resolvedPath, visiting)) {
552
- rewritePaths.add(nestedPath)
553
- }
554
- }
555
-
556
- visiting.delete(normalizedPath)
557
-
558
- const resolvedRewritePaths = [...rewritePaths]
559
- nodeModulesRuntimeRewritePathsByPath.set(normalizedPath, resolvedRewritePaths)
560
- return resolvedRewritePaths
561
- }
562
-
563
- for (const [specifier, moduleEntry] of runtimeModules.entries()) {
564
- const moduleId = runtimeModuleIdsBySpecifier.get(specifier)
565
-
566
- if (!moduleId) {
567
- continue
568
- }
569
-
570
- build.module(moduleId, async () => ({
571
- exports: await resolveRuntimeModuleExports(moduleEntry),
572
- loader: "object",
573
- }))
574
-
575
- build.onResolve({ filter: exactSpecifierFilter(specifier) }, () => ({ path: moduleId }))
576
- }
577
-
578
- build.onResolve({ filter: /.*/ }, (args) => {
579
- if (runtimeModuleIdsBySpecifier.has(args.path) || args.path.startsWith(RUNTIME_MODULE_PREFIX)) {
580
- return undefined
581
- }
582
-
583
- const path = resolveSourcePathFromSpecifier(args.path, args.importer)
584
- if (!path || !runtimeLoaderForPath(path)) {
585
- return undefined
586
- }
587
-
588
- const nodeModulesPath = isNodeModulesPath(path)
589
-
590
- if (!nodeModulesPath) {
591
- installRewriteLoader(path)
592
- return undefined
593
- }
594
-
595
- if (!rewriteOptions.nodeModulesRuntimeSpecifiers && !rewriteOptions.nodeModulesBareSpecifiers) {
596
- return undefined
597
- }
598
-
599
- for (const rewritePath of collectNodeModulesRuntimeRewritePaths(path)) {
600
- installRewriteLoader(rewritePath)
601
- }
602
-
603
- const packageRoot = nodeModulesPackageRootForPath(path)
604
- if (
605
- rewriteOptions.nodeModulesBareSpecifiers &&
606
- packageRoot &&
607
- nodeModulesBareRewritePackageRoots.has(packageRoot)
608
- ) {
609
- installRewriteLoader(path)
610
- return undefined
611
- }
612
-
613
- if (!rewriteOptions.nodeModulesRuntimeSpecifiers || !analyzeSourcePath(path).needsRuntimeSpecifierRewrite) {
614
- return undefined
615
- }
616
-
617
- if (rewriteOptions.nodeModulesBareSpecifiers && packageRoot) {
618
- nodeModulesBareRewritePackageRoots.add(packageRoot)
619
- }
620
-
621
- installRewriteLoader(path)
622
- return undefined
623
- })
624
- },
625
- }
626
- }