@bubblebrain-ai/bubble 0.0.51 → 0.0.53

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 (481) hide show
  1. package/README.md +4 -12
  2. package/dist/agent/routing-catalog.js +3 -2
  3. package/dist/agent/subagent/router.js +5 -0
  4. package/dist/agent/subagent/runtime.d.ts +1 -0
  5. package/dist/agent/subagent/runtime.js +13 -1
  6. package/dist/agent/subagent-control.d.ts +4 -0
  7. package/dist/agent/subagent-control.js +1 -0
  8. package/dist/agent/subagent-store.js +2 -0
  9. package/dist/agent/workflow/control.d.ts +2 -0
  10. package/dist/agent/workflow/runs.d.ts +1 -0
  11. package/dist/agent/workflow/runs.js +3 -0
  12. package/dist/agent.d.ts +11 -1
  13. package/dist/agent.js +158 -57
  14. package/dist/bin.js +2 -44
  15. package/dist/config.d.ts +14 -1
  16. package/dist/config.js +45 -4
  17. package/dist/context/budget.d.ts +7 -1
  18. package/dist/context/budget.js +25 -2
  19. package/dist/context/compact-llm.d.ts +1 -1
  20. package/dist/context/compact-llm.js +5 -2
  21. package/dist/context/overflow.js +2 -0
  22. package/dist/context/projector.d.ts +8 -0
  23. package/dist/context/projector.js +55 -6
  24. package/dist/context/tool-output-truncate.d.ts +17 -1
  25. package/dist/context/tool-output-truncate.js +171 -49
  26. package/dist/feishu/agent-host/run-driver.js +3 -0
  27. package/dist/feishu/serve.js +2 -0
  28. package/dist/goal/command.d.ts +1 -1
  29. package/dist/goal/command.js +7 -2
  30. package/dist/main.d.ts +1 -1
  31. package/dist/main.js +38 -8
  32. package/dist/memory/db.js +0 -7
  33. package/dist/model-catalog.js +25 -6
  34. package/dist/model-config.js +3 -2
  35. package/dist/model-pricing.d.ts +24 -5
  36. package/dist/model-pricing.js +0 -0
  37. package/dist/model-selection.js +13 -4
  38. package/dist/network/chatgpt-transport.js +0 -34
  39. package/dist/network/errors.d.ts +19 -0
  40. package/dist/network/errors.js +24 -0
  41. package/dist/network/provider-transport.d.ts +0 -4
  42. package/dist/network/provider-transport.js +3 -35
  43. package/dist/network/retry.d.ts +6 -1
  44. package/dist/network/retry.js +9 -0
  45. package/dist/provider-model-policy.d.ts +16 -0
  46. package/dist/provider-model-policy.js +33 -0
  47. package/dist/provider-registry.d.ts +1 -1
  48. package/dist/provider-registry.js +80 -11
  49. package/dist/provider-transform.js +32 -4
  50. package/dist/provider.d.ts +6 -2
  51. package/dist/provider.js +100 -11
  52. package/dist/question/controller.js +5 -4
  53. package/dist/question/normalize.d.ts +6 -0
  54. package/dist/question/normalize.js +11 -0
  55. package/dist/rewind.d.ts +20 -0
  56. package/dist/rewind.js +29 -0
  57. package/dist/sdk/index.d.ts +1 -1
  58. package/dist/sdk/index.js +11 -3
  59. package/dist/session.d.ts +7 -0
  60. package/dist/session.js +20 -0
  61. package/dist/skills/discovery.js +18 -0
  62. package/dist/skills/registry.d.ts +12 -2
  63. package/dist/skills/registry.js +40 -5
  64. package/dist/skills/types.d.ts +2 -0
  65. package/dist/slash-commands/commands.js +120 -81
  66. package/dist/slash-commands/registry.d.ts +2 -1
  67. package/dist/slash-commands/registry.js +3 -0
  68. package/dist/slash-commands/types.d.ts +22 -4
  69. package/dist/stats/usage.d.ts +3 -1
  70. package/dist/stats/usage.js +22 -13
  71. package/dist/tasks/manager.d.ts +4 -2
  72. package/dist/tasks/manager.js +34 -9
  73. package/dist/tasks/promotion.d.ts +2 -2
  74. package/dist/tasks/promotion.js +2 -2
  75. package/dist/tools/agent-lifecycle.js +4 -0
  76. package/dist/tools/bash.d.ts +3 -1
  77. package/dist/tools/bash.js +13 -2
  78. package/dist/tools/grep.d.ts +5 -1
  79. package/dist/tools/grep.js +318 -69
  80. package/dist/tools/index.d.ts +3 -1
  81. package/dist/tools/index.js +1 -0
  82. package/dist/tools/question.js +5 -4
  83. package/dist/tools/read.js +40 -21
  84. package/dist/tui/animation-clock.d.ts +14 -0
  85. package/dist/tui/animation-clock.js +34 -0
  86. package/dist/tui/app.d.ts +176 -0
  87. package/dist/tui/app.js +1647 -0
  88. package/dist/tui/components/approval-dialog.d.ts +43 -0
  89. package/dist/tui/components/approval-dialog.js +247 -0
  90. package/dist/tui/components/bottom-sheet.d.ts +9 -0
  91. package/dist/tui/components/bottom-sheet.js +32 -0
  92. package/dist/tui/components/context-info.d.ts +54 -0
  93. package/dist/tui/components/context-info.js +388 -0
  94. package/dist/tui/components/feedback-dialog.d.ts +56 -0
  95. package/dist/tui/components/feedback-dialog.js +262 -0
  96. package/dist/tui/components/feishu-setup-dialog.d.ts +65 -0
  97. package/dist/tui/components/feishu-setup-dialog.js +332 -0
  98. package/dist/tui/components/image-preview.d.ts +32 -0
  99. package/dist/tui/components/image-preview.js +130 -0
  100. package/dist/tui/components/plan-dialog.d.ts +34 -0
  101. package/dist/tui/components/plan-dialog.js +196 -0
  102. package/dist/tui/components/provider-key-input.d.ts +18 -0
  103. package/dist/tui/components/provider-key-input.js +49 -0
  104. package/dist/tui/components/question-dialog.d.ts +25 -0
  105. package/dist/tui/components/question-dialog.js +263 -0
  106. package/dist/tui/components/responsive-transcript.d.ts +31 -0
  107. package/dist/tui/components/responsive-transcript.js +77 -0
  108. package/dist/tui/components/rewind-picker.d.ts +62 -0
  109. package/dist/tui/components/rewind-picker.js +317 -0
  110. package/dist/tui/components/session-picker.d.ts +49 -0
  111. package/dist/tui/components/session-picker.js +303 -0
  112. package/dist/tui/components/skills-panel.d.ts +59 -0
  113. package/dist/tui/components/skills-panel.js +568 -0
  114. package/dist/tui/components/stats-panel.d.ts +40 -0
  115. package/dist/tui/components/stats-panel.js +301 -0
  116. package/dist/tui/components/streaming-message.d.ts +69 -0
  117. package/dist/tui/components/streaming-message.js +393 -0
  118. package/dist/tui/components/subagent-inspector.d.ts +28 -0
  119. package/dist/tui/components/subagent-inspector.js +127 -0
  120. package/dist/tui/components/task-inspector.d.ts +26 -0
  121. package/dist/tui/components/task-inspector.js +70 -0
  122. package/dist/tui/components/tasks-pane.d.ts +88 -0
  123. package/dist/tui/components/tasks-pane.js +416 -0
  124. package/dist/tui/components/transcript.d.ts +96 -0
  125. package/dist/tui/components/transcript.js +771 -0
  126. package/dist/tui/components/welcome.d.ts +20 -0
  127. package/dist/tui/components/welcome.js +133 -0
  128. package/dist/tui/components/workflow-inspector.d.ts +30 -0
  129. package/dist/tui/components/workflow-inspector.js +136 -0
  130. package/dist/tui/composer-autocomplete.d.ts +61 -0
  131. package/dist/tui/composer-autocomplete.js +383 -0
  132. package/dist/tui/composer-style.d.ts +7 -0
  133. package/dist/tui/composer-style.js +29 -0
  134. package/dist/tui/controller/agent-event-reducer.d.ts +75 -0
  135. package/dist/tui/controller/agent-event-reducer.js +238 -0
  136. package/dist/tui/controller/composer-controller.d.ts +95 -0
  137. package/dist/tui/controller/composer-controller.js +502 -0
  138. package/dist/tui/controller/controller.d.ts +194 -0
  139. package/dist/tui/controller/controller.js +1035 -0
  140. package/dist/tui/controller/effects.d.ts +71 -0
  141. package/dist/tui/controller/effects.js +1 -0
  142. package/dist/tui/controller/goal-runtime-controller.d.ts +47 -0
  143. package/dist/tui/controller/goal-runtime-controller.js +202 -0
  144. package/dist/tui/controller/input-queue-machine.d.ts +71 -0
  145. package/dist/tui/controller/input-queue-machine.js +121 -0
  146. package/dist/tui/controller/intents.d.ts +56 -0
  147. package/dist/tui/controller/intents.js +6 -0
  148. package/dist/tui/controller/overlay-controller.d.ts +64 -0
  149. package/dist/tui/controller/overlay-controller.js +129 -0
  150. package/dist/tui/controller/ports.d.ts +57 -0
  151. package/dist/tui/controller/ports.js +9 -0
  152. package/dist/tui/controller/session-transition.d.ts +54 -0
  153. package/dist/tui/controller/session-transition.js +68 -0
  154. package/dist/tui/controller/state.d.ts +14 -0
  155. package/dist/tui/controller/state.js +36 -0
  156. package/dist/tui/controller/task-runtime-controller.d.ts +66 -0
  157. package/dist/tui/controller/task-runtime-controller.js +158 -0
  158. package/dist/tui/footer.d.ts +37 -0
  159. package/dist/tui/footer.js +80 -0
  160. package/dist/{tui-ink → tui/formatting}/edit-diff.d.ts +1 -1
  161. package/dist/{tui-ink → tui/formatting}/edit-diff.js +1 -1
  162. package/dist/{tui-ink/app-helpers.d.ts → tui/formatting/summary.d.ts} +4 -4
  163. package/dist/{tui-ink/app-helpers.js → tui/formatting/summary.js} +2 -2
  164. package/dist/tui/fullscreen.d.ts +48 -0
  165. package/dist/tui/fullscreen.js +255 -0
  166. package/dist/tui/image-display.d.ts +4 -0
  167. package/dist/tui/image-display.js +30 -12
  168. package/dist/tui/markdown-style.d.ts +5 -0
  169. package/dist/tui/markdown-style.js +23 -0
  170. package/dist/{tui-ink → tui/model}/composer-buffer.js +1 -1
  171. package/dist/tui/model/composer-types.d.ts +17 -0
  172. package/dist/tui/model/composer-types.js +1 -0
  173. package/dist/{tui-ink → tui/model}/display-history.d.ts +7 -1
  174. package/dist/{tui-ink → tui/model}/display-reconstruct.d.ts +1 -1
  175. package/dist/{tui-ink → tui/model}/display-reconstruct.js +54 -6
  176. package/dist/{tui-ink → tui/model}/file-mentions.d.ts +2 -0
  177. package/dist/{tui-ink → tui/model}/file-mentions.js +4 -0
  178. package/dist/tui/model/image-attachment.d.ts +15 -0
  179. package/dist/tui/model/image-attachment.js +1 -0
  180. package/dist/{tui-ink → tui/model}/image-paste.d.ts +7 -1
  181. package/dist/{tui-ink → tui/model}/image-paste.js +46 -0
  182. package/dist/tui/model/input-history.d.ts +1 -0
  183. package/dist/tui/model/input-history.js +1 -0
  184. package/dist/{tui-ink → tui/model}/input-queue.d.ts +1 -1
  185. package/dist/{tui-ink → tui/model}/recent-activity.js +1 -1
  186. package/dist/{tui-ink → tui/model}/subagent-view.d.ts +17 -2
  187. package/dist/{tui-ink → tui/model}/subagent-view.js +125 -4
  188. package/dist/{tui-ink → tui/model}/submit-dedupe.d.ts +1 -1
  189. package/dist/tui/model/theme-style.d.ts +10 -0
  190. package/dist/tui/model/theme-style.js +79 -0
  191. package/dist/{tui-ink → tui/model}/theme.d.ts +11 -23
  192. package/dist/{tui-ink → tui/model}/theme.js +23 -38
  193. package/dist/{tui-ink → tui/model}/trace-groups.d.ts +2 -0
  194. package/dist/{tui-ink → tui/model}/trace-groups.js +91 -30
  195. package/dist/tui/model/trace-interaction.d.ts +63 -0
  196. package/dist/tui/model/trace-interaction.js +87 -0
  197. package/dist/tui/model-picker-data.d.ts +1 -2
  198. package/dist/tui/model-picker-data.js +8 -1
  199. package/dist/tui/model-switch.js +2 -0
  200. package/dist/{tui-ink → tui}/run-session-picker.d.ts +2 -3
  201. package/dist/tui/run-session-picker.js +64 -0
  202. package/dist/tui/run.d.ts +72 -0
  203. package/dist/tui/run.js +139 -0
  204. package/dist/tui/terminal/multiplexer.d.ts +5 -0
  205. package/dist/tui/terminal/multiplexer.js +14 -0
  206. package/dist/tui/testing/fake-agent.d.ts +24 -0
  207. package/dist/tui/testing/fake-agent.js +22 -0
  208. package/dist/tui/testing/spy-host.d.ts +21 -0
  209. package/dist/tui/testing/spy-host.js +55 -0
  210. package/dist/tui/trace-groups.js +27 -6
  211. package/dist/types.d.ts +7 -0
  212. package/node_modules/@bubblebrain-ai/pi-tui/LICENSE +21 -0
  213. package/node_modules/@bubblebrain-ai/pi-tui/README.md +854 -0
  214. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts +26 -0
  215. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts.map +1 -0
  216. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js +121 -0
  217. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js.map +1 -0
  218. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts +86 -0
  219. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts.map +1 -0
  220. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js +649 -0
  221. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js.map +1 -0
  222. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts +13 -0
  223. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts.map +1 -0
  224. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js +36 -0
  225. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js.map +1 -0
  226. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts +22 -0
  227. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts.map +1 -0
  228. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js +99 -0
  229. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js.map +1 -0
  230. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts +22 -0
  231. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts.map +1 -0
  232. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js +36 -0
  233. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js.map +1 -0
  234. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts +330 -0
  235. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts.map +1 -0
  236. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js +2344 -0
  237. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js.map +1 -0
  238. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts +7 -0
  239. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts.map +1 -0
  240. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js +43 -0
  241. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js.map +1 -0
  242. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts +28 -0
  243. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts.map +1 -0
  244. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js +82 -0
  245. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js.map +1 -0
  246. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts +48 -0
  247. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts.map +1 -0
  248. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js +390 -0
  249. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js.map +1 -0
  250. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts +31 -0
  251. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts.map +1 -0
  252. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js +67 -0
  253. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js.map +1 -0
  254. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts +103 -0
  255. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts.map +1 -0
  256. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js +797 -0
  257. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js.map +1 -0
  258. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts +56 -0
  259. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts.map +1 -0
  260. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js +179 -0
  261. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js.map +1 -0
  262. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts +53 -0
  263. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts.map +1 -0
  264. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js +175 -0
  265. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js.map +1 -0
  266. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts +50 -0
  267. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts.map +1 -0
  268. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js +174 -0
  269. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js.map +1 -0
  270. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts +12 -0
  271. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts.map +1 -0
  272. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js +22 -0
  273. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js.map +1 -0
  274. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts +32 -0
  275. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts.map +1 -0
  276. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js +109 -0
  277. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js.map +1 -0
  278. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts +19 -0
  279. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts.map +1 -0
  280. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js +81 -0
  281. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js.map +1 -0
  282. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts +13 -0
  283. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts.map +1 -0
  284. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js +48 -0
  285. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js.map +1 -0
  286. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts +8 -0
  287. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts.map +1 -0
  288. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js +26 -0
  289. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js.map +1 -0
  290. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts +39 -0
  291. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts.map +1 -0
  292. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js +2 -0
  293. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js.map +1 -0
  294. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts +16 -0
  295. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts.map +1 -0
  296. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js +110 -0
  297. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js.map +1 -0
  298. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts +31 -0
  299. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts.map +1 -0
  300. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js +42 -0
  301. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js.map +1 -0
  302. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts +273 -0
  303. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts.map +1 -0
  304. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js +231 -0
  305. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js.map +1 -0
  306. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts +184 -0
  307. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts.map +1 -0
  308. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js +1174 -0
  309. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js.map +1 -0
  310. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts +28 -0
  311. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts.map +1 -0
  312. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js +46 -0
  313. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js.map +1 -0
  314. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts +10 -0
  315. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts.map +1 -0
  316. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js +1268 -0
  317. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js.map +1 -0
  318. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts +40 -0
  319. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts.map +1 -0
  320. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js +6 -0
  321. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js.map +1 -0
  322. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts +42 -0
  323. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts.map +1 -0
  324. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js +335 -0
  325. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js.map +1 -0
  326. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts +3 -0
  327. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts.map +1 -0
  328. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js +60 -0
  329. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js.map +1 -0
  330. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts +56 -0
  331. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts.map +1 -0
  332. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js +363 -0
  333. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js.map +1 -0
  334. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts +10 -0
  335. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts.map +1 -0
  336. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js +59 -0
  337. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js.map +1 -0
  338. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts +116 -0
  339. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts.map +1 -0
  340. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js +518 -0
  341. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js.map +1 -0
  342. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts +142 -0
  343. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts.map +1 -0
  344. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js +544 -0
  345. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js.map +1 -0
  346. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts +11 -0
  347. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts.map +1 -0
  348. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js +11 -0
  349. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js.map +1 -0
  350. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts +140 -0
  351. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts.map +1 -0
  352. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js +1334 -0
  353. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js.map +1 -0
  354. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts +39 -0
  355. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts.map +1 -0
  356. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js +536 -0
  357. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js.map +1 -0
  358. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts +338 -0
  359. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts.map +1 -0
  360. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js +1016 -0
  361. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js.map +1 -0
  362. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts +17 -0
  363. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts.map +1 -0
  364. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js +27 -0
  365. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js.map +1 -0
  366. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts +96 -0
  367. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts.map +1 -0
  368. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js +1193 -0
  369. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js.map +1 -0
  370. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts +25 -0
  371. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts.map +1 -0
  372. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js +96 -0
  373. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js.map +1 -0
  374. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts +73 -0
  375. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts.map +1 -0
  376. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js +188 -0
  377. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js.map +1 -0
  378. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/README.md +20 -0
  379. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/build.sh +62 -0
  380. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  381. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  382. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/src/darwin-modifiers.c +70 -0
  383. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/README.md +22 -0
  384. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/build.mjs +229 -0
  385. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  386. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  387. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/src/win32-console-mode.c +119 -0
  388. package/node_modules/@bubblebrain-ai/pi-tui/package.json +66 -0
  389. package/node_modules/get-east-asian-width/index.d.ts +60 -0
  390. package/node_modules/get-east-asian-width/index.js +30 -0
  391. package/node_modules/get-east-asian-width/license +9 -0
  392. package/node_modules/get-east-asian-width/lookup-data.js +21 -0
  393. package/node_modules/get-east-asian-width/lookup.js +138 -0
  394. package/node_modules/get-east-asian-width/package.json +71 -0
  395. package/node_modules/get-east-asian-width/readme.md +65 -0
  396. package/node_modules/get-east-asian-width/utilities.js +24 -0
  397. package/package.json +23 -10
  398. package/packages/pi-tui/node_modules/marked/LICENSE +44 -0
  399. package/packages/pi-tui/node_modules/marked/README.md +115 -0
  400. package/packages/pi-tui/node_modules/marked/bin/main.js +284 -0
  401. package/packages/pi-tui/node_modules/marked/bin/marked.js +16 -0
  402. package/packages/pi-tui/node_modules/marked/lib/marked.d.ts +760 -0
  403. package/packages/pi-tui/node_modules/marked/lib/marked.esm.js +77 -0
  404. package/packages/pi-tui/node_modules/marked/lib/marked.esm.js.map +7 -0
  405. package/packages/pi-tui/node_modules/marked/lib/marked.umd.js +79 -0
  406. package/packages/pi-tui/node_modules/marked/lib/marked.umd.js.map +7 -0
  407. package/packages/pi-tui/node_modules/marked/man/marked.1 +113 -0
  408. package/packages/pi-tui/node_modules/marked/man/marked.1.md +93 -0
  409. package/packages/pi-tui/node_modules/marked/package.json +103 -0
  410. package/dist/tui-ink/app.d.ts +0 -76
  411. package/dist/tui-ink/app.js +0 -2377
  412. package/dist/tui-ink/approval/approval-dialog.d.ts +0 -13
  413. package/dist/tui-ink/approval/approval-dialog.js +0 -184
  414. package/dist/tui-ink/approval/diff-view.d.ts +0 -7
  415. package/dist/tui-ink/approval/diff-view.js +0 -44
  416. package/dist/tui-ink/approval/select.d.ts +0 -35
  417. package/dist/tui-ink/approval/select.js +0 -98
  418. package/dist/tui-ink/code-highlight.d.ts +0 -8
  419. package/dist/tui-ink/code-highlight.js +0 -121
  420. package/dist/tui-ink/command-palette.d.ts +0 -32
  421. package/dist/tui-ink/command-palette.js +0 -158
  422. package/dist/tui-ink/compaction-progress.d.ts +0 -19
  423. package/dist/tui-ink/compaction-progress.js +0 -74
  424. package/dist/tui-ink/detect-theme.d.ts +0 -1
  425. package/dist/tui-ink/detect-theme.js +0 -1
  426. package/dist/tui-ink/feedback-dialog.d.ts +0 -19
  427. package/dist/tui-ink/feedback-dialog.js +0 -133
  428. package/dist/tui-ink/feishu-setup-picker.d.ts +0 -5
  429. package/dist/tui-ink/feishu-setup-picker.js +0 -271
  430. package/dist/tui-ink/footer.d.ts +0 -26
  431. package/dist/tui-ink/footer.js +0 -51
  432. package/dist/tui-ink/input-box.d.ts +0 -189
  433. package/dist/tui-ink/input-box.js +0 -1279
  434. package/dist/tui-ink/input-history.d.ts +0 -1
  435. package/dist/tui-ink/input-history.js +0 -1
  436. package/dist/tui-ink/markdown.d.ts +0 -103
  437. package/dist/tui-ink/markdown.js +0 -747
  438. package/dist/tui-ink/message-list.d.ts +0 -49
  439. package/dist/tui-ink/message-list.js +0 -841
  440. package/dist/tui-ink/model-picker.d.ts +0 -143
  441. package/dist/tui-ink/model-picker.js +0 -966
  442. package/dist/tui-ink/plan-confirm.d.ts +0 -7
  443. package/dist/tui-ink/plan-confirm.js +0 -115
  444. package/dist/tui-ink/question-dialog.d.ts +0 -8
  445. package/dist/tui-ink/question-dialog.js +0 -135
  446. package/dist/tui-ink/rewind-picker.d.ts +0 -8
  447. package/dist/tui-ink/rewind-picker.js +0 -102
  448. package/dist/tui-ink/run-session-picker.js +0 -22
  449. package/dist/tui-ink/run.d.ts +0 -62
  450. package/dist/tui-ink/run.js +0 -103
  451. package/dist/tui-ink/session-picker.d.ts +0 -10
  452. package/dist/tui-ink/session-picker.js +0 -113
  453. package/dist/tui-ink/stats-panel.d.ts +0 -11
  454. package/dist/tui-ink/stats-panel.js +0 -65
  455. package/dist/tui-ink/subagent-inspector.d.ts +0 -21
  456. package/dist/tui-ink/subagent-inspector.js +0 -205
  457. package/dist/tui-ink/use-terminal-size.d.ts +0 -4
  458. package/dist/tui-ink/use-terminal-size.js +0 -48
  459. package/dist/tui-ink/waiting-indicator.d.ts +0 -12
  460. package/dist/tui-ink/waiting-indicator.js +0 -129
  461. package/dist/tui-ink/welcome.d.ts +0 -25
  462. package/dist/tui-ink/welcome.js +0 -88
  463. package/dist/tui-ink/wordmark.d.ts +0 -8
  464. package/dist/tui-ink/wordmark.js +0 -103
  465. /package/dist/{tui-ink → tui/model}/composer-buffer.d.ts +0 -0
  466. /package/dist/{tui-ink → tui/model}/display-history.js +0 -0
  467. /package/dist/{tui-ink → tui/model}/input-queue.js +0 -0
  468. /package/dist/{tui-ink → tui/model}/key-events.d.ts +0 -0
  469. /package/dist/{tui-ink → tui/model}/key-events.js +0 -0
  470. /package/dist/{tui-ink → tui/model}/paste-operation-tracker.d.ts +0 -0
  471. /package/dist/{tui-ink → tui/model}/paste-operation-tracker.js +0 -0
  472. /package/dist/{tui-ink → tui/model}/recent-activity.d.ts +0 -0
  473. /package/dist/{tui-ink → tui/model}/submit-dedupe.js +0 -0
  474. /package/dist/{tui-ink → tui/model}/sync-output.d.ts +0 -0
  475. /package/dist/{tui-ink → tui/model}/sync-output.js +0 -0
  476. /package/dist/{tui-ink → tui/model}/terminal-env.d.ts +0 -0
  477. /package/dist/{tui-ink → tui/model}/terminal-env.js +0 -0
  478. /package/dist/{tui-ink → tui/model}/terminal-mouse.d.ts +0 -0
  479. /package/dist/{tui-ink → tui/model}/terminal-mouse.js +0 -0
  480. /package/dist/{tui-ink → tui/model}/width.d.ts +0 -0
  481. /package/dist/{tui-ink → tui/model}/width.js +0 -0
@@ -0,0 +1,1268 @@
1
+ import { visibleWidth } from "./utils.js";
2
+ const SYMBOLS = {
3
+ alpha: "α",
4
+ beta: "β",
5
+ gamma: "γ",
6
+ delta: "δ",
7
+ epsilon: "ϵ",
8
+ varepsilon: "ε",
9
+ zeta: "ζ",
10
+ eta: "η",
11
+ theta: "θ",
12
+ vartheta: "ϑ",
13
+ iota: "ι",
14
+ kappa: "κ",
15
+ varkappa: "ϰ",
16
+ lambda: "λ",
17
+ mu: "μ",
18
+ nu: "ν",
19
+ xi: "ξ",
20
+ pi: "π",
21
+ varpi: "ϖ",
22
+ rho: "ρ",
23
+ varrho: "ϱ",
24
+ sigma: "σ",
25
+ varsigma: "ς",
26
+ tau: "τ",
27
+ upsilon: "υ",
28
+ phi: "ϕ",
29
+ varphi: "φ",
30
+ chi: "χ",
31
+ psi: "ψ",
32
+ omega: "ω",
33
+ Gamma: "Γ",
34
+ Delta: "Δ",
35
+ Theta: "Θ",
36
+ Lambda: "Λ",
37
+ Xi: "Ξ",
38
+ Pi: "Π",
39
+ Sigma: "Σ",
40
+ Upsilon: "Υ",
41
+ Phi: "Φ",
42
+ Psi: "Ψ",
43
+ Omega: "Ω",
44
+ pm: "±",
45
+ mp: "∓",
46
+ times: "×",
47
+ div: "÷",
48
+ cdot: "·",
49
+ ast: "∗",
50
+ star: "⋆",
51
+ circ: "∘",
52
+ bullet: "•",
53
+ oplus: "⊕",
54
+ ominus: "⊖",
55
+ otimes: "⊗",
56
+ oslash: "⊘",
57
+ odot: "⊙",
58
+ bigcirc: "○",
59
+ dagger: "†",
60
+ ddagger: "‡",
61
+ amalg: "⨿",
62
+ uplus: "⊎",
63
+ sqcap: "⊓",
64
+ sqcup: "⊔",
65
+ triangleleft: "◁",
66
+ triangleright: "▷",
67
+ wr: "≀",
68
+ cap: "∩",
69
+ cup: "∪",
70
+ bigcap: "⋂",
71
+ bigcup: "⋃",
72
+ bigwedge: "⋀",
73
+ bigvee: "⋁",
74
+ bigsqcup: "⨆",
75
+ biguplus: "⨄",
76
+ bigoplus: "⨁",
77
+ bigotimes: "⨂",
78
+ bigodot: "⨀",
79
+ setminus: "∖",
80
+ in: "∈",
81
+ notin: "∉",
82
+ ni: "∋",
83
+ subset: "⊂",
84
+ supset: "⊃",
85
+ subseteq: "⊆",
86
+ supseteq: "⊇",
87
+ sqsubset: "⊏",
88
+ sqsupset: "⊐",
89
+ sqsubseteq: "⊑",
90
+ sqsupseteq: "⊒",
91
+ prec: "≺",
92
+ preceq: "≼",
93
+ succ: "≻",
94
+ succeq: "≽",
95
+ ll: "≪",
96
+ gg: "≫",
97
+ le: "≤",
98
+ leq: "≤",
99
+ leqslant: "≤",
100
+ ge: "≥",
101
+ geq: "≥",
102
+ geqslant: "≥",
103
+ ne: "≠",
104
+ neq: "≠",
105
+ equiv: "≡",
106
+ approx: "≈",
107
+ sim: "∼",
108
+ simeq: "≃",
109
+ cong: "≅",
110
+ asymp: "≍",
111
+ doteq: "≐",
112
+ propto: "∝",
113
+ parallel: "∥",
114
+ perp: "⊥",
115
+ mid: "∣",
116
+ vdash: "⊢",
117
+ dashv: "⊣",
118
+ models: "⊨",
119
+ Vdash: "⊩",
120
+ Vvdash: "⊪",
121
+ nvdash: "⊬",
122
+ nvDash: "⊭",
123
+ forall: "∀",
124
+ exists: "∃",
125
+ nexists: "∄",
126
+ neg: "¬",
127
+ land: "∧",
128
+ wedge: "∧",
129
+ lor: "∨",
130
+ vee: "∨",
131
+ to: "→",
132
+ rightarrow: "→",
133
+ longrightarrow: "→",
134
+ leftarrow: "←",
135
+ longleftarrow: "←",
136
+ gets: "←",
137
+ leftrightarrow: "↔",
138
+ longleftrightarrow: "↔",
139
+ hookleftarrow: "↩",
140
+ hookrightarrow: "↪",
141
+ twoheadleftarrow: "↞",
142
+ twoheadrightarrow: "↠",
143
+ leftharpoonup: "↼",
144
+ leftharpoondown: "↽",
145
+ rightharpoonup: "⇀",
146
+ rightharpoondown: "⇁",
147
+ rightleftharpoons: "⇌",
148
+ leftrightharpoons: "⇋",
149
+ nearrow: "↗",
150
+ searrow: "↘",
151
+ swarrow: "↙",
152
+ nwarrow: "↖",
153
+ rightsquigarrow: "⇝",
154
+ leadsto: "⇝",
155
+ Rightarrow: "⇒",
156
+ Longrightarrow: "⇒",
157
+ Leftarrow: "⇐",
158
+ Longleftarrow: "⇐",
159
+ Leftrightarrow: "⇔",
160
+ Longleftrightarrow: "⇔",
161
+ implies: "⇒",
162
+ iff: "⇔",
163
+ mapsto: "↦",
164
+ longmapsto: "↦",
165
+ uparrow: "↑",
166
+ downarrow: "↓",
167
+ partial: "∂",
168
+ nabla: "∇",
169
+ int: "∫",
170
+ iint: "∬",
171
+ iiint: "∭",
172
+ oint: "∮",
173
+ sum: "∑",
174
+ prod: "∏",
175
+ coprod: "∐",
176
+ infty: "∞",
177
+ emptyset: "∅",
178
+ varnothing: "∅",
179
+ angle: "∠",
180
+ therefore: "∴",
181
+ because: "∵",
182
+ aleph: "ℵ",
183
+ beth: "ℶ",
184
+ gimel: "ℷ",
185
+ daleth: "ℸ",
186
+ top: "⊤",
187
+ bot: "⊥",
188
+ triangle: "△",
189
+ square: "□",
190
+ lozenge: "◊",
191
+ checkmark: "✓",
192
+ complement: "∁",
193
+ wp: "℘",
194
+ prime: "′",
195
+ ldots: "…",
196
+ dots: "…",
197
+ cdots: "⋯",
198
+ vdots: "⋮",
199
+ ddots: "⋱",
200
+ ell: "ℓ",
201
+ hbar: "ℏ",
202
+ Im: "ℑ",
203
+ Re: "ℜ",
204
+ langle: "⟨",
205
+ rangle: "⟩",
206
+ vert: "|",
207
+ lvert: "|",
208
+ rvert: "|",
209
+ Vert: "‖",
210
+ lVert: "‖",
211
+ rVert: "‖",
212
+ lbrace: "{",
213
+ rbrace: "}",
214
+ backslash: "\\",
215
+ lfloor: "⌊",
216
+ rfloor: "⌋",
217
+ lceil: "⌈",
218
+ rceil: "⌉",
219
+ colon: ":",
220
+ };
221
+ const NAMED_OPERATORS = new Set([
222
+ "arccos",
223
+ "arcsin",
224
+ "arctan",
225
+ "arg",
226
+ "cos",
227
+ "cosh",
228
+ "cot",
229
+ "coth",
230
+ "csc",
231
+ "deg",
232
+ "det",
233
+ "dim",
234
+ "exp",
235
+ "gcd",
236
+ "hom",
237
+ "inf",
238
+ "ker",
239
+ "lg",
240
+ "lim",
241
+ "liminf",
242
+ "limsup",
243
+ "ln",
244
+ "log",
245
+ "max",
246
+ "min",
247
+ "Pr",
248
+ "sec",
249
+ "sin",
250
+ "sinh",
251
+ "sup",
252
+ "tan",
253
+ "tanh",
254
+ ]);
255
+ const LIMIT_OPERATORS = new Set([
256
+ "argmax",
257
+ "argmin",
258
+ "inf",
259
+ "injlim",
260
+ "lim",
261
+ "liminf",
262
+ "limsup",
263
+ "max",
264
+ "min",
265
+ "projlim",
266
+ "sup",
267
+ ]);
268
+ const DISPLAY_LIMIT_SYMBOLS = new Set([
269
+ "bigcap",
270
+ "bigcup",
271
+ "bigodot",
272
+ "bigoplus",
273
+ "bigotimes",
274
+ "bigsqcup",
275
+ "biguplus",
276
+ "bigvee",
277
+ "bigwedge",
278
+ "coprod",
279
+ "int",
280
+ "iint",
281
+ "iiint",
282
+ "oint",
283
+ "prod",
284
+ "sum",
285
+ ]);
286
+ const RELATION_COMMANDS = new Set([
287
+ "Leftarrow",
288
+ "Leftrightarrow",
289
+ "Longleftarrow",
290
+ "Longleftrightarrow",
291
+ "Longrightarrow",
292
+ "Rightarrow",
293
+ "Vdash",
294
+ "Vvdash",
295
+ "approx",
296
+ "asymp",
297
+ "cong",
298
+ "dashv",
299
+ "doteq",
300
+ "downarrow",
301
+ "equiv",
302
+ "ge",
303
+ "geq",
304
+ "geqslant",
305
+ "gets",
306
+ "gg",
307
+ "hookleftarrow",
308
+ "hookrightarrow",
309
+ "iff",
310
+ "implies",
311
+ "in",
312
+ "leadsto",
313
+ "le",
314
+ "leftarrow",
315
+ "leftharpoondown",
316
+ "leftharpoonup",
317
+ "leftrightarrow",
318
+ "leftrightharpoons",
319
+ "leq",
320
+ "leqslant",
321
+ "ll",
322
+ "longleftarrow",
323
+ "longleftrightarrow",
324
+ "longmapsto",
325
+ "longrightarrow",
326
+ "mapsto",
327
+ "mid",
328
+ "models",
329
+ "ne",
330
+ "nearrow",
331
+ "neq",
332
+ "ni",
333
+ "notin",
334
+ "nvdash",
335
+ "nvDash",
336
+ "nwarrow",
337
+ "parallel",
338
+ "perp",
339
+ "prec",
340
+ "preceq",
341
+ "propto",
342
+ "rightharpoondown",
343
+ "rightharpoonup",
344
+ "rightleftharpoons",
345
+ "rightarrow",
346
+ "rightsquigarrow",
347
+ "searrow",
348
+ "sim",
349
+ "simeq",
350
+ "sqsubset",
351
+ "sqsubseteq",
352
+ "sqsupset",
353
+ "sqsupseteq",
354
+ "subset",
355
+ "subseteq",
356
+ "succ",
357
+ "succeq",
358
+ "supset",
359
+ "supseteq",
360
+ "swarrow",
361
+ "to",
362
+ "triangleleft",
363
+ "triangleright",
364
+ "twoheadleftarrow",
365
+ "twoheadrightarrow",
366
+ "uparrow",
367
+ "vdash",
368
+ ]);
369
+ const NEGATED_SYMBOLS = {
370
+ "<": "≮",
371
+ ">": "≯",
372
+ "=": "≠",
373
+ "∈": "∉",
374
+ "∋": "∌",
375
+ "∣": "∤",
376
+ "∥": "∦",
377
+ "∼": "≁",
378
+ "≃": "≄",
379
+ "≅": "≇",
380
+ "≈": "≉",
381
+ "≡": "≢",
382
+ "≤": "≰",
383
+ "≥": "≱",
384
+ "≺": "⊀",
385
+ "≻": "⊁",
386
+ "⊂": "⊄",
387
+ "⊃": "⊅",
388
+ "⊆": "⊈",
389
+ "⊇": "⊉",
390
+ "⊢": "⊬",
391
+ "⊨": "⊭",
392
+ "↔": "↮",
393
+ "←": "↚",
394
+ "→": "↛",
395
+ "⇒": "⇏",
396
+ "⇐": "⇍",
397
+ "⇔": "⇎",
398
+ "≼": "⋠",
399
+ "≽": "⋡",
400
+ };
401
+ const BLACKBOARD = {
402
+ C: "ℂ",
403
+ H: "ℍ",
404
+ N: "ℕ",
405
+ P: "ℙ",
406
+ Q: "ℚ",
407
+ R: "ℝ",
408
+ Z: "ℤ",
409
+ };
410
+ const SUPERSCRIPTS = {
411
+ "0": "⁰",
412
+ "1": "¹",
413
+ "2": "²",
414
+ "3": "³",
415
+ "4": "⁴",
416
+ "5": "⁵",
417
+ "6": "⁶",
418
+ "7": "⁷",
419
+ "8": "⁸",
420
+ "9": "⁹",
421
+ "+": "⁺",
422
+ "-": "⁻",
423
+ "=": "⁼",
424
+ "(": "⁽",
425
+ ")": "⁾",
426
+ a: "ᵃ",
427
+ b: "ᵇ",
428
+ c: "ᶜ",
429
+ d: "ᵈ",
430
+ e: "ᵉ",
431
+ f: "ᶠ",
432
+ g: "ᵍ",
433
+ h: "ʰ",
434
+ i: "ⁱ",
435
+ j: "ʲ",
436
+ k: "ᵏ",
437
+ l: "ˡ",
438
+ m: "ᵐ",
439
+ n: "ⁿ",
440
+ o: "ᵒ",
441
+ p: "ᵖ",
442
+ r: "ʳ",
443
+ s: "ˢ",
444
+ t: "ᵗ",
445
+ u: "ᵘ",
446
+ v: "ᵛ",
447
+ w: "ʷ",
448
+ x: "ˣ",
449
+ y: "ʸ",
450
+ z: "ᶻ",
451
+ };
452
+ const SUBSCRIPTS = {
453
+ "0": "₀",
454
+ "1": "₁",
455
+ "2": "₂",
456
+ "3": "₃",
457
+ "4": "₄",
458
+ "5": "₅",
459
+ "6": "₆",
460
+ "7": "₇",
461
+ "8": "₈",
462
+ "9": "₉",
463
+ "+": "₊",
464
+ "-": "₋",
465
+ "=": "₌",
466
+ "(": "₍",
467
+ ")": "₎",
468
+ a: "ₐ",
469
+ e: "ₑ",
470
+ h: "ₕ",
471
+ i: "ᵢ",
472
+ j: "ⱼ",
473
+ k: "ₖ",
474
+ l: "ₗ",
475
+ m: "ₘ",
476
+ n: "ₙ",
477
+ o: "ₒ",
478
+ p: "ₚ",
479
+ r: "ᵣ",
480
+ s: "ₛ",
481
+ t: "ₜ",
482
+ u: "ᵤ",
483
+ v: "ᵥ",
484
+ x: "ₓ",
485
+ };
486
+ const SPACING_COMMANDS = new Set([
487
+ ",",
488
+ ":",
489
+ ";",
490
+ " ",
491
+ ">",
492
+ "enspace",
493
+ "enskip",
494
+ "medspace",
495
+ "quad",
496
+ "qquad",
497
+ "thickspace",
498
+ "thinspace",
499
+ ]);
500
+ const NEGATIVE_SPACING_COMMANDS = new Set(["!", "negmedspace", "negthickspace", "negthinspace"]);
501
+ const NEGATIVE_SPACE = "\u0000";
502
+ const IGNORED_COMMANDS = new Set([
503
+ "displaystyle",
504
+ "limits",
505
+ "nolimits",
506
+ "scriptstyle",
507
+ "scriptscriptstyle",
508
+ "textstyle",
509
+ ]);
510
+ const SIZE_COMMANDS = new Set([
511
+ "big",
512
+ "Big",
513
+ "bigg",
514
+ "Bigg",
515
+ "bigl",
516
+ "Bigl",
517
+ "biggl",
518
+ "Biggl",
519
+ "bigr",
520
+ "Bigr",
521
+ "biggr",
522
+ "Biggr",
523
+ ]);
524
+ const PLAIN_WRAPPERS = new Set([
525
+ "emph",
526
+ "mathcal",
527
+ "mathbf",
528
+ "mathfrak",
529
+ "mathit",
530
+ "mathrm",
531
+ "mathnormal",
532
+ "mathscr",
533
+ "mathsf",
534
+ "mathtt",
535
+ "mathup",
536
+ "mbox",
537
+ "overbrace",
538
+ "pmb",
539
+ "smash",
540
+ "substack",
541
+ "text",
542
+ "textbf",
543
+ "textit",
544
+ "textmd",
545
+ "textnormal",
546
+ "textrm",
547
+ "textsc",
548
+ "textsf",
549
+ "textsl",
550
+ "texttt",
551
+ "textup",
552
+ "underbrace",
553
+ "bm",
554
+ "boldsymbol",
555
+ ]);
556
+ const ACCENTS = {
557
+ acute: "\u0301",
558
+ bar: "\u0305",
559
+ breve: "\u0306",
560
+ check: "\u030c",
561
+ ddot: "\u0308",
562
+ dot: "\u0307",
563
+ grave: "\u0300",
564
+ hat: "\u0302",
565
+ mathring: "\u030a",
566
+ overleftarrow: "\u20d6",
567
+ overleftrightarrow: "\u20e1",
568
+ overline: "\u0305",
569
+ overrightarrow: "\u20d7",
570
+ tilde: "\u0303",
571
+ underline: "\u0332",
572
+ vec: "\u20d7",
573
+ widehat: "\u0302",
574
+ widetilde: "\u0303",
575
+ };
576
+ function replaceCharacters(value, replacements) {
577
+ let result = "";
578
+ for (const character of value) {
579
+ const replacement = replacements[character];
580
+ if (replacement === undefined) {
581
+ return undefined;
582
+ }
583
+ result += replacement;
584
+ }
585
+ return result;
586
+ }
587
+ function formatScript(value, kind) {
588
+ value = value.trim();
589
+ const replacements = kind === "sub" ? SUBSCRIPTS : SUPERSCRIPTS;
590
+ const unicode = replaceCharacters(value.replace(/\s*([=+-])\s*/g, "$1"), replacements);
591
+ if (unicode !== undefined) {
592
+ return unicode;
593
+ }
594
+ const prefix = kind === "sub" ? "_" : "^";
595
+ if (Array.from(value).length === 1 || (kind === "sub" && /^[A-Za-z]+$/.test(value))) {
596
+ return `${prefix}${value}`;
597
+ }
598
+ return `${prefix}(${value})`;
599
+ }
600
+ function formatFraction(numerator, denominator) {
601
+ numerator = numerator.trim();
602
+ denominator = denominator.trim();
603
+ const simpleNumerator = /^[\p{L}\p{N}.]+$/u.test(numerator);
604
+ const simpleDenominator = /^[\p{N}.]+$/u.test(denominator) || Array.from(denominator).length === 1;
605
+ return `${simpleNumerator ? numerator : `(${numerator})`}/${simpleDenominator ? denominator : `(${denominator})`}`;
606
+ }
607
+ function formatRoot(value, symbol = "√") {
608
+ value = value.trim();
609
+ return /^[\p{L}\p{N}.]+$/u.test(value) ? `${symbol}${value}` : `${symbol}(${value})`;
610
+ }
611
+ const NAMED_OPERATOR_START = "\u{f0004}";
612
+ const NAMED_OPERATOR_END = "\u{f0005}";
613
+ const NAMED_OPERATOR_LEFT_SPACING_PATTERN = /(?<=[\p{L}\p{N})\]}\u{f0001}])\u{f0004}/gu;
614
+ const NAMED_OPERATOR_RIGHT_SPACING_PATTERN = /\u{f0005}(?=[\p{L}\p{N}√\u{f0000}])/gu;
615
+ function normalizeOutput(value) {
616
+ return value
617
+ .replace(NAMED_OPERATOR_LEFT_SPACING_PATTERN, " ")
618
+ .replaceAll(NAMED_OPERATOR_START, "")
619
+ .replace(NAMED_OPERATOR_RIGHT_SPACING_PATTERN, " ")
620
+ .replaceAll(NAMED_OPERATOR_END, "")
621
+ .split("\n")
622
+ .map((line) => line.replace(/[ \t]+/g, " ").trim())
623
+ .filter((line, index, lines) => line.length > 0 || (index > 0 && index < lines.length - 1))
624
+ .join("\n")
625
+ .trim();
626
+ }
627
+ const LAYOUT_MARKER_START = "\u{f0000}";
628
+ const LAYOUT_MARKER_END = "\u{f0001}";
629
+ const LAYOUT_MARKER_PATTERN = /\u{f0000}(\d+)\u{f0001}/gu;
630
+ const TRAILING_LAYOUT_MARKER_PATTERN = /\u{f0000}(\d+)\u{f0001}$/u;
631
+ const PROTECTED_SPACE = "\u{f0002}";
632
+ function padLayoutLine(line, width, centered = false) {
633
+ const padding = Math.max(0, width - visibleWidth(line));
634
+ const left = centered ? Math.floor(padding / 2) : 0;
635
+ return `${" ".repeat(left)}${line}${" ".repeat(padding - left)}`;
636
+ }
637
+ function joinLayouts(layouts) {
638
+ if (layouts.length === 0) {
639
+ return { lines: [""], width: 0, baseline: 0 };
640
+ }
641
+ const baseline = Math.max(...layouts.map((layout) => layout.baseline));
642
+ const below = Math.max(...layouts.map((layout) => layout.lines.length - layout.baseline - 1));
643
+ const lines = [];
644
+ for (let row = 0; row <= baseline + below; row++) {
645
+ let line = "";
646
+ for (const layout of layouts) {
647
+ const sourceRow = row - baseline + layout.baseline;
648
+ line +=
649
+ sourceRow >= 0 && sourceRow < layout.lines.length
650
+ ? padLayoutLine(layout.lines[sourceRow] ?? "", layout.width)
651
+ : " ".repeat(layout.width);
652
+ }
653
+ lines.push(line.trimEnd());
654
+ }
655
+ return {
656
+ lines,
657
+ width: layouts.reduce((width, layout) => width + layout.width, 0),
658
+ baseline,
659
+ };
660
+ }
661
+ function renderLayout(source, nodes) {
662
+ const renderedLines = [];
663
+ let firstBaseline = 0;
664
+ for (const sourceLine of source.split("\n")) {
665
+ const layouts = [];
666
+ let position = 0;
667
+ let previousNode;
668
+ for (const match of sourceLine.matchAll(LAYOUT_MARKER_PATTERN)) {
669
+ const index = match.index;
670
+ const node = nodes[Number(match[1])];
671
+ if (!node) {
672
+ continue;
673
+ }
674
+ if (index > position) {
675
+ const sliced = sourceLine.slice(position, index);
676
+ const trimmed = (previousNode ? sliced.trimStart() : sliced).trimEnd();
677
+ const preserveLeadingSpace = previousNode?.type === "matrix" && /^\s/.test(sliced);
678
+ const preserveTrailingSpace = node.type === "matrix" && /\s$/.test(sliced);
679
+ const text = trimmed
680
+ ? `${preserveLeadingSpace ? " " : ""}${trimmed}${preserveTrailingSpace ? " " : ""}`
681
+ : preserveLeadingSpace || preserveTrailingSpace
682
+ ? " "
683
+ : "";
684
+ layouts.push({ lines: [text], width: visibleWidth(text), baseline: 0 });
685
+ }
686
+ if (node.type === "fraction") {
687
+ const numerator = renderLayout(node.numerator, nodes);
688
+ const denominator = renderLayout(node.denominator, nodes);
689
+ const contentWidth = Math.max(numerator.width, denominator.width, 1);
690
+ const width = contentWidth + 2;
691
+ layouts.push({
692
+ lines: [
693
+ ...numerator.lines.map((line) => padLayoutLine(line, width, true)),
694
+ ` ${"─".repeat(contentWidth)} `,
695
+ ...denominator.lines.map((line) => padLayoutLine(line, width, true)),
696
+ ],
697
+ width,
698
+ baseline: numerator.lines.length,
699
+ });
700
+ }
701
+ else if (node.type === "operator") {
702
+ const contentWidth = Math.max(visibleWidth(node.operator), node.lower === undefined ? 0 : visibleWidth(node.lower), node.upper === undefined ? 0 : visibleWidth(node.upper));
703
+ const lines = [];
704
+ if (node.upper !== undefined) {
705
+ lines.push(`${padLayoutLine(node.upper, contentWidth, true)} `);
706
+ }
707
+ lines.push(`${padLayoutLine(node.operator, contentWidth, true)} `);
708
+ if (node.lower !== undefined) {
709
+ lines.push(`${padLayoutLine(node.lower, contentWidth, true)} `);
710
+ }
711
+ layouts.push({
712
+ lines,
713
+ width: contentWidth + 1,
714
+ baseline: node.upper === undefined ? 0 : 1,
715
+ });
716
+ }
717
+ else {
718
+ const width = Math.max(0, ...node.lines.map((line) => visibleWidth(line)));
719
+ layouts.push({
720
+ lines: node.lines.map((line) => padLayoutLine(line, width)),
721
+ width,
722
+ baseline: node.baseline,
723
+ });
724
+ }
725
+ position = index + match[0].length;
726
+ previousNode = node;
727
+ }
728
+ if (position < sourceLine.length) {
729
+ const sliced = sourceLine.slice(position);
730
+ const trimmed = previousNode ? sliced.trimStart() : sliced;
731
+ const text = previousNode?.type === "matrix" && /^\s/.test(sliced) ? ` ${trimmed}` : trimmed;
732
+ layouts.push({ lines: [text], width: visibleWidth(text), baseline: 0 });
733
+ }
734
+ const lineLayout = joinLayouts(layouts);
735
+ if (renderedLines.length === 0) {
736
+ firstBaseline = lineLayout.baseline;
737
+ }
738
+ renderedLines.push(...lineLayout.lines);
739
+ }
740
+ return {
741
+ lines: renderedLines,
742
+ width: Math.max(0, ...renderedLines.map((line) => visibleWidth(line))),
743
+ baseline: firstBaseline,
744
+ };
745
+ }
746
+ class LatexParser {
747
+ constructor(source, layoutNodes, display) {
748
+ this.position = 0;
749
+ this.supported = true;
750
+ this.stackFractions = true;
751
+ this.source = source;
752
+ this.layoutNodes = layoutNodes;
753
+ this.display = display;
754
+ }
755
+ render() {
756
+ const rendered = this.parseSequence();
757
+ if (!this.supported || this.position !== this.source.length) {
758
+ return undefined;
759
+ }
760
+ return normalizeOutput(rendered);
761
+ }
762
+ parseSequence(endCharacter) {
763
+ let result = "";
764
+ while (this.position < this.source.length) {
765
+ const character = this.source[this.position];
766
+ if (endCharacter && character === endCharacter) {
767
+ this.position++;
768
+ return result;
769
+ }
770
+ if (character === "}") {
771
+ this.supported = false;
772
+ return result;
773
+ }
774
+ if (character === "{") {
775
+ this.position++;
776
+ result += this.parseSequence("}");
777
+ continue;
778
+ }
779
+ if (character === "\\") {
780
+ const command = this.parseCommand();
781
+ if (command === NEGATIVE_SPACE) {
782
+ result = result.trimEnd();
783
+ if (result.endsWith(NAMED_OPERATOR_END)) {
784
+ result = result.slice(0, -NAMED_OPERATOR_END.length);
785
+ }
786
+ }
787
+ else {
788
+ result += command;
789
+ }
790
+ continue;
791
+ }
792
+ if (character === "^" || character === "_") {
793
+ this.position++;
794
+ result = result.trimEnd();
795
+ const script = formatScript(this.parseRequiredArgument(false), character === "_" ? "sub" : "sup");
796
+ if (result.endsWith(NAMED_OPERATOR_END)) {
797
+ result = `${result.slice(0, -NAMED_OPERATOR_END.length)}${script}${NAMED_OPERATOR_END}`;
798
+ }
799
+ else {
800
+ result += script;
801
+ }
802
+ continue;
803
+ }
804
+ if (/\s/.test(character)) {
805
+ result += this.parseWhitespace();
806
+ continue;
807
+ }
808
+ if (character === "=" || character === "<" || character === ">") {
809
+ result = `${result.trimEnd()} ${character} `;
810
+ this.position++;
811
+ continue;
812
+ }
813
+ if (character === "&") {
814
+ this.position++;
815
+ continue;
816
+ }
817
+ if (character === "~") {
818
+ this.position++;
819
+ result += " ";
820
+ continue;
821
+ }
822
+ if (character === ".") {
823
+ const marker = TRAILING_LAYOUT_MARKER_PATTERN.exec(result);
824
+ const node = marker ? this.layoutNodes[Number(marker[1])] : undefined;
825
+ if (node?.type === "matrix") {
826
+ const lastLine = node.lines.length - 1;
827
+ node.lines[lastLine] = `${node.lines[lastLine] ?? ""}${character}`;
828
+ this.position++;
829
+ continue;
830
+ }
831
+ }
832
+ result += character;
833
+ this.position++;
834
+ }
835
+ if (endCharacter) {
836
+ this.supported = false;
837
+ }
838
+ return result;
839
+ }
840
+ parseWhitespace() {
841
+ while (this.position < this.source.length && /\s/.test(this.source[this.position] ?? "")) {
842
+ this.position++;
843
+ }
844
+ return " ";
845
+ }
846
+ parseCommand() {
847
+ this.position++;
848
+ if (this.position >= this.source.length) {
849
+ this.supported = false;
850
+ return "";
851
+ }
852
+ let command = "";
853
+ const first = this.source[this.position] ?? "";
854
+ if (first === "\n" || first === "\r") {
855
+ this.position++;
856
+ if (first === "\r" && this.source[this.position] === "\n") {
857
+ this.position++;
858
+ }
859
+ return " ";
860
+ }
861
+ if (/[A-Za-z]/.test(first)) {
862
+ const start = this.position;
863
+ while (this.position < this.source.length && /[A-Za-z]/.test(this.source[this.position] ?? "")) {
864
+ this.position++;
865
+ }
866
+ command = this.source.slice(start, this.position);
867
+ }
868
+ else {
869
+ command = first;
870
+ this.position++;
871
+ }
872
+ if (command === "\\") {
873
+ return "\n";
874
+ }
875
+ if (SPACING_COMMANDS.has(command)) {
876
+ return " ";
877
+ }
878
+ if (NEGATIVE_SPACING_COMMANDS.has(command)) {
879
+ return NEGATIVE_SPACE;
880
+ }
881
+ if (IGNORED_COMMANDS.has(command)) {
882
+ return "";
883
+ }
884
+ if (command === "{" ||
885
+ command === "}" ||
886
+ command === "$" ||
887
+ command === "%" ||
888
+ command === "#" ||
889
+ command === "_" ||
890
+ command === "&") {
891
+ return command;
892
+ }
893
+ if (command === "|") {
894
+ return "‖";
895
+ }
896
+ if (command === "not") {
897
+ const value = this.parseRequiredArgument(false).trim();
898
+ const negated = NEGATED_SYMBOLS[value];
899
+ if (negated !== undefined) {
900
+ return ` ${negated} `;
901
+ }
902
+ const characters = Array.from(value);
903
+ if (characters.length === 0) {
904
+ this.supported = false;
905
+ return "";
906
+ }
907
+ return ` ${characters[0]}\u0338${characters.slice(1).join("")} `;
908
+ }
909
+ if (LIMIT_OPERATORS.has(command)) {
910
+ return this.parseOperator(command, "bracket", true, true);
911
+ }
912
+ const symbol = SYMBOLS[command];
913
+ if (symbol !== undefined) {
914
+ if (DISPLAY_LIMIT_SYMBOLS.has(command)) {
915
+ return this.parseOperator(symbol, "script", true);
916
+ }
917
+ return command === "cdot" || command === "times" || RELATION_COMMANDS.has(command) ? ` ${symbol} ` : symbol;
918
+ }
919
+ if (NAMED_OPERATORS.has(command)) {
920
+ return `${NAMED_OPERATOR_START}${command}${NAMED_OPERATOR_END}`;
921
+ }
922
+ if (SIZE_COMMANDS.has(command)) {
923
+ return "";
924
+ }
925
+ if (command === "left" || command === "middle" || command === "right") {
926
+ if (this.source[this.position] === ".") {
927
+ this.position++;
928
+ }
929
+ return "";
930
+ }
931
+ if (command === "frac" || command === "dfrac" || command === "tfrac") {
932
+ const shouldStack = this.display && this.stackFractions && command !== "tfrac";
933
+ const numerator = this.parseRequiredArgument(!shouldStack);
934
+ const denominator = this.parseRequiredArgument(!shouldStack);
935
+ if (shouldStack) {
936
+ const index = this.layoutNodes.push({
937
+ type: "fraction",
938
+ numerator: normalizeOutput(numerator),
939
+ denominator: normalizeOutput(denominator),
940
+ }) - 1;
941
+ return `${LAYOUT_MARKER_START}${index}${LAYOUT_MARKER_END}`;
942
+ }
943
+ return formatFraction(numerator, denominator);
944
+ }
945
+ if (command === "sqrt") {
946
+ const degree = this.parseOptionalArgument()?.trim();
947
+ const value = this.parseRequiredArgument();
948
+ if (degree === undefined || degree === "2") {
949
+ return formatRoot(value);
950
+ }
951
+ if (degree === "3") {
952
+ return formatRoot(value, "∛");
953
+ }
954
+ if (degree === "4") {
955
+ return formatRoot(value, "∜");
956
+ }
957
+ return `${formatScript(degree, "sup")}${formatRoot(value)}`;
958
+ }
959
+ if (command === "boxed" || command === "fbox") {
960
+ return `[${this.parseRequiredArgument().trim()}]`;
961
+ }
962
+ if (command === "binom" || command === "dbinom" || command === "tbinom") {
963
+ return `(${this.parseRequiredArgument()} choose ${this.parseRequiredArgument()})`;
964
+ }
965
+ const accent = ACCENTS[command];
966
+ if (accent !== undefined) {
967
+ const value = this.parseRequiredArgument();
968
+ return Array.from(value).length === 1 ? `${value}${accent}` : `${command}(${value})`;
969
+ }
970
+ if (command === "mathbb") {
971
+ const value = this.parseRequiredArgument();
972
+ return Array.from(value, (character) => BLACKBOARD[character] ?? character).join("");
973
+ }
974
+ if (command === "operatorname") {
975
+ const starred = this.source[this.position] === "*";
976
+ if (starred) {
977
+ this.position++;
978
+ }
979
+ const operator = normalizeOutput(this.parseRequiredArgument()).trim();
980
+ return this.parseOperator(operator, "bracket", starred, true);
981
+ }
982
+ if (command === "mod" || command === "bmod") {
983
+ return " mod ";
984
+ }
985
+ if (command === "pmod" || command === "pod") {
986
+ const value = this.parseRequiredArgument().trim();
987
+ return command === "pmod" ? ` (mod ${value})` : ` (${value})`;
988
+ }
989
+ if (command === "overset" || command === "stackrel") {
990
+ const upper = this.parseRequiredArgument();
991
+ const value = this.parseRequiredArgument().trim();
992
+ return `${value}${formatScript(upper, "sup")}`;
993
+ }
994
+ if (command === "underset") {
995
+ const lower = this.parseRequiredArgument();
996
+ const value = this.parseRequiredArgument().trim();
997
+ return `${value}${formatScript(lower, "sub")}`;
998
+ }
999
+ if (PLAIN_WRAPPERS.has(command)) {
1000
+ const value = this.parseRequiredArgument();
1001
+ return command.startsWith("text") || command === "mbox" ? value : value.trim();
1002
+ }
1003
+ if (command === "begin") {
1004
+ return this.parseEnvironment();
1005
+ }
1006
+ if (command === "end") {
1007
+ this.supported = false;
1008
+ return "";
1009
+ }
1010
+ this.supported = false;
1011
+ return `\\${command}`;
1012
+ }
1013
+ parseOperator(operator, inlineLowerStyle, displayLimits, spaced = false) {
1014
+ let useDisplayLimits = displayLimits;
1015
+ let modifierPosition = this.position;
1016
+ while (modifierPosition < this.source.length && /[ \t]/.test(this.source[modifierPosition] ?? "")) {
1017
+ modifierPosition++;
1018
+ }
1019
+ const modifier = /^\\(limits|nolimits)(?![A-Za-z])/.exec(this.source.slice(modifierPosition));
1020
+ if (modifier) {
1021
+ useDisplayLimits = modifier[1] === "limits";
1022
+ this.position = modifierPosition + modifier[0].length;
1023
+ }
1024
+ let lower;
1025
+ let upper;
1026
+ while (true) {
1027
+ let scriptPosition = this.position;
1028
+ while (scriptPosition < this.source.length && /[ \t]/.test(this.source[scriptPosition] ?? "")) {
1029
+ scriptPosition++;
1030
+ }
1031
+ const kind = this.source[scriptPosition];
1032
+ if (kind !== "_" && kind !== "^") {
1033
+ break;
1034
+ }
1035
+ this.position = scriptPosition + 1;
1036
+ const value = normalizeOutput(this.parseRequiredArgument(false)).replaceAll(" ", "");
1037
+ if (kind === "_") {
1038
+ if (lower !== undefined) {
1039
+ this.supported = false;
1040
+ }
1041
+ lower = value;
1042
+ }
1043
+ else {
1044
+ if (upper !== undefined) {
1045
+ this.supported = false;
1046
+ }
1047
+ upper = value;
1048
+ }
1049
+ }
1050
+ if (this.display && useDisplayLimits && (lower !== undefined || upper !== undefined)) {
1051
+ const index = this.layoutNodes.push({ type: "operator", operator, lower, upper }) - 1;
1052
+ return `${LAYOUT_MARKER_START}${index}${LAYOUT_MARKER_END}`;
1053
+ }
1054
+ let rendered = operator;
1055
+ if (lower !== undefined) {
1056
+ rendered += inlineLowerStyle === "bracket" ? `[${lower}]` : formatScript(lower, "sub");
1057
+ }
1058
+ if (upper !== undefined) {
1059
+ rendered += formatScript(upper, "sup");
1060
+ }
1061
+ return spaced ? ` ${rendered} ` : rendered;
1062
+ }
1063
+ parseRequiredArgument(stackFractions = true) {
1064
+ const previousStackFractions = this.stackFractions;
1065
+ this.stackFractions = previousStackFractions && stackFractions;
1066
+ const value = this.parseRequiredArgumentValue();
1067
+ this.stackFractions = previousStackFractions;
1068
+ return value;
1069
+ }
1070
+ parseRequiredArgumentValue() {
1071
+ while (this.position < this.source.length && /\s/.test(this.source[this.position] ?? "")) {
1072
+ this.position++;
1073
+ }
1074
+ if (this.position >= this.source.length) {
1075
+ this.supported = false;
1076
+ return "";
1077
+ }
1078
+ if (this.source[this.position] === "{") {
1079
+ this.position++;
1080
+ return this.parseSequence("}");
1081
+ }
1082
+ if (this.source[this.position] === "\\") {
1083
+ return this.parseCommand();
1084
+ }
1085
+ const value = this.source[this.position] ?? "";
1086
+ this.position++;
1087
+ return value;
1088
+ }
1089
+ parseOptionalArgument() {
1090
+ while (this.position < this.source.length && /[ \t]/.test(this.source[this.position] ?? "")) {
1091
+ this.position++;
1092
+ }
1093
+ if (this.source[this.position] !== "[") {
1094
+ return undefined;
1095
+ }
1096
+ const end = this.source.indexOf("]", this.position + 1);
1097
+ if (end < 0) {
1098
+ this.supported = false;
1099
+ return undefined;
1100
+ }
1101
+ const value = this.source.slice(this.position + 1, end);
1102
+ this.position = end + 1;
1103
+ return this.renderNested(value);
1104
+ }
1105
+ readRawGroup() {
1106
+ while (this.position < this.source.length && /[ \t]/.test(this.source[this.position] ?? "")) {
1107
+ this.position++;
1108
+ }
1109
+ if (this.source[this.position] !== "{") {
1110
+ this.supported = false;
1111
+ return undefined;
1112
+ }
1113
+ const start = ++this.position;
1114
+ let depth = 1;
1115
+ while (this.position < this.source.length) {
1116
+ const character = this.source[this.position];
1117
+ if (character === "\\") {
1118
+ this.position += 2;
1119
+ continue;
1120
+ }
1121
+ if (character === "{")
1122
+ depth++;
1123
+ if (character === "}")
1124
+ depth--;
1125
+ if (depth === 0) {
1126
+ const value = this.source.slice(start, this.position);
1127
+ this.position++;
1128
+ return value;
1129
+ }
1130
+ this.position++;
1131
+ }
1132
+ this.supported = false;
1133
+ return undefined;
1134
+ }
1135
+ splitEnvironmentRows(body) {
1136
+ return body.split(/\\\\(?:\[[^\]\n]*\])?/);
1137
+ }
1138
+ parseEnvironment() {
1139
+ const environment = this.readRawGroup();
1140
+ if (!environment) {
1141
+ return "";
1142
+ }
1143
+ const endMarker = `\\end{${environment}}`;
1144
+ const end = this.source.indexOf(endMarker, this.position);
1145
+ if (end < 0) {
1146
+ this.supported = false;
1147
+ return "";
1148
+ }
1149
+ const body = this.source.slice(this.position, end);
1150
+ this.position = end + endMarker.length;
1151
+ if (environment === "equation" || environment === "equation*" || environment === "displaymath") {
1152
+ return this.renderNested(body).trim();
1153
+ }
1154
+ if (environment === "aligned" ||
1155
+ environment === "align" ||
1156
+ environment === "align*" ||
1157
+ environment === "alignedat" ||
1158
+ environment === "alignat" ||
1159
+ environment === "alignat*" ||
1160
+ environment === "gather" ||
1161
+ environment === "gathered" ||
1162
+ environment === "multline" ||
1163
+ environment === "multline*" ||
1164
+ environment === "split") {
1165
+ const alignedAt = ["alignedat", "alignat", "alignat*"].includes(environment);
1166
+ const alignedBody = alignedAt ? body.replace(/^\s*\{[^}]*\}/, "") : body;
1167
+ return this.splitEnvironmentRows(alignedBody)
1168
+ .map((row) => {
1169
+ const cells = row.split("&");
1170
+ const source = alignedAt
1171
+ ? Array.from({ length: Math.ceil(cells.length / 2) }, (_, index) => cells.slice(index * 2, index * 2 + 2).join("")).join(" ")
1172
+ : cells.join("");
1173
+ return this.renderNested(source).trim();
1174
+ })
1175
+ .filter(Boolean)
1176
+ .join("\n");
1177
+ }
1178
+ if (environment === "cases" || environment === "cases*") {
1179
+ const rows = this.splitEnvironmentRows(body)
1180
+ .map((row) => row.split("&").map((cell) => this.renderNested(cell, false).trim()))
1181
+ .filter((row) => row.some(Boolean));
1182
+ return rows
1183
+ .map((row, index) => {
1184
+ const value = (row[0] ?? "").replace(/,\s*$/, "");
1185
+ const condition = row[1] ?? "";
1186
+ const delimiter = index === 0 ? "⎧" : index === rows.length - 1 ? "⎩" : "⎨";
1187
+ const conditionPrefix = /^(?:if|when|for|otherwise)\b/i.test(condition) ? " " : " if ";
1188
+ return `${delimiter} ${value}${condition ? `${conditionPrefix}${condition}` : ""}`;
1189
+ })
1190
+ .join("\n");
1191
+ }
1192
+ if (["array", "matrix", "smallmatrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"].includes(environment)) {
1193
+ const matrixBody = environment === "array" ? body.replace(/^\s*\{[^}]*\}/, "") : body;
1194
+ return this.renderMatrix(environment, matrixBody);
1195
+ }
1196
+ this.supported = false;
1197
+ return body;
1198
+ }
1199
+ renderMatrix(environment, body) {
1200
+ const matrix = this.splitEnvironmentRows(body)
1201
+ .map((row) => row.split("&").map((cell) => this.renderNested(cell, false).trim()))
1202
+ .filter((row) => row.some(Boolean));
1203
+ const columnCount = Math.max(0, ...matrix.map((row) => row.length));
1204
+ const columnWidths = Array.from({ length: columnCount }, (_, column) => Math.max(0, ...matrix.map((row) => visibleWidth(row[column] ?? ""))));
1205
+ const rows = matrix.map((row) => Array.from({ length: columnCount }, (_, column) => {
1206
+ const cell = row[column] ?? "";
1207
+ return `${cell}${PROTECTED_SPACE.repeat(Math.max(0, (columnWidths[column] ?? 0) - visibleWidth(cell)))}`;
1208
+ }).join(" │ "));
1209
+ let lines;
1210
+ if (environment === "array" || environment === "matrix" || environment === "smallmatrix") {
1211
+ lines = rows;
1212
+ }
1213
+ else {
1214
+ const delimiters = {
1215
+ pmatrix: ["⎛", "⎞", "⎜", "⎟", "⎝", "⎠"],
1216
+ bmatrix: ["⎡", "⎤", "⎢", "⎥", "⎣", "⎦"],
1217
+ Bmatrix: ["⎧", "⎫", "⎨", "⎬", "⎩", "⎭"],
1218
+ vmatrix: ["│", "│", "│", "│", "│", "│"],
1219
+ Vmatrix: ["║", "║", "║", "║", "║", "║"],
1220
+ };
1221
+ const delimiter = delimiters[environment];
1222
+ if (!delimiter) {
1223
+ this.supported = false;
1224
+ return rows.join("\n");
1225
+ }
1226
+ lines = rows.map((row, index) => {
1227
+ const left = index === 0 ? delimiter[0] : index === rows.length - 1 ? delimiter[4] : delimiter[2];
1228
+ const right = index === 0 ? delimiter[1] : index === rows.length - 1 ? delimiter[5] : delimiter[3];
1229
+ return `${left} ${row} ${right}`;
1230
+ });
1231
+ }
1232
+ if (lines.length <= 1) {
1233
+ return lines[0] ?? "";
1234
+ }
1235
+ const index = this.layoutNodes.push({ type: "matrix", lines, baseline: 0 }) - 1;
1236
+ return `${LAYOUT_MARKER_START}${index}${LAYOUT_MARKER_END}`;
1237
+ }
1238
+ renderNested(source, stackFractions = true) {
1239
+ const rendered = new LatexParser(source, this.layoutNodes, this.display && stackFractions).render();
1240
+ if (rendered === undefined) {
1241
+ this.supported = false;
1242
+ return source;
1243
+ }
1244
+ return rendered;
1245
+ }
1246
+ }
1247
+ /**
1248
+ * Render a basic LaTeX math expression as terminal-friendly Unicode text.
1249
+ * Returns undefined when the expression contains unsupported or malformed syntax.
1250
+ */
1251
+ export function renderLatex(source, options = {}) {
1252
+ const layoutNodes = [];
1253
+ const rendered = new LatexParser(source, layoutNodes, options.display === true).render();
1254
+ if (rendered === undefined) {
1255
+ return undefined;
1256
+ }
1257
+ if (layoutNodes.length === 0) {
1258
+ return rendered.replaceAll(PROTECTED_SPACE, " ");
1259
+ }
1260
+ const lines = renderLayout(rendered, layoutNodes).lines;
1261
+ const indentation = Math.min(...lines.filter((line) => line.trim()).map((line) => line.length - line.trimStart().length));
1262
+ return lines
1263
+ .map((line) => line.slice(indentation).trimEnd())
1264
+ .join("\n")
1265
+ .trimEnd()
1266
+ .replaceAll(PROTECTED_SPACE, " ");
1267
+ }
1268
+ //# sourceMappingURL=latex.js.map