dal-code 1.0.9 → 1.0.11

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 (458) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/core/keybindings.d.ts +1 -1
  3. package/dist/core/keybindings.d.ts.map +1 -1
  4. package/dist/core/keybindings.js +1 -1
  5. package/dist/core/keybindings.js.map +1 -1
  6. package/dist/core/model-config.d.ts +85 -0
  7. package/dist/core/model-config.d.ts.map +1 -1
  8. package/dist/core/model-config.js +19 -14
  9. package/dist/core/model-config.js.map +1 -1
  10. package/dist/core/session-manager.d.ts +7 -0
  11. package/dist/core/session-manager.d.ts.map +1 -1
  12. package/dist/core/session-manager.js +28 -0
  13. package/dist/core/session-manager.js.map +1 -1
  14. package/dist/extensions/llama/client.d.ts +2 -0
  15. package/dist/extensions/llama/client.d.ts.map +1 -1
  16. package/dist/extensions/llama/client.js +7 -3
  17. package/dist/extensions/llama/client.js.map +1 -1
  18. package/dist/extensions/llama/provider.d.ts.map +1 -1
  19. package/dist/extensions/llama/provider.js +20 -5
  20. package/dist/extensions/llama/provider.js.map +1 -1
  21. package/dist/main.d.ts.map +1 -1
  22. package/dist/main.js +5 -6
  23. package/dist/main.js.map +1 -1
  24. package/dist/modes/interactive/interactive-mode.d.ts +2 -1
  25. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  26. package/dist/modes/interactive/interactive-mode.js +31 -21
  27. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  28. package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
  29. package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
  30. package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
  31. package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
  32. package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
  33. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  34. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
  35. package/dist/node_modules/@dalcode/dal-office/package.json +3 -3
  36. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  37. package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
  38. package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
  39. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  40. package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
  41. package/dist/node_modules/@earendil-works/chord/LICENSE +21 -0
  42. package/dist/node_modules/@earendil-works/chord/README.md +205 -0
  43. package/dist/node_modules/@earendil-works/chord/dist/api.d.ts +15 -0
  44. package/dist/node_modules/@earendil-works/chord/dist/api.d.ts.map +1 -0
  45. package/dist/node_modules/@earendil-works/chord/dist/api.js +72 -0
  46. package/dist/node_modules/@earendil-works/chord/dist/api.js.map +1 -0
  47. package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts +6 -0
  48. package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts.map +1 -0
  49. package/dist/node_modules/@earendil-works/chord/dist/bundler.js +3 -0
  50. package/dist/node_modules/@earendil-works/chord/dist/bundler.js.map +1 -0
  51. package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts +24 -0
  52. package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts.map +1 -0
  53. package/dist/node_modules/@earendil-works/chord/dist/context/index.js +97 -0
  54. package/dist/node_modules/@earendil-works/chord/dist/context/index.js.map +1 -0
  55. package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts +119 -0
  56. package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts.map +1 -0
  57. package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +1906 -0
  58. package/dist/node_modules/@earendil-works/chord/dist/delta/index.js.map +1 -0
  59. package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts +12 -0
  60. package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts.map +1 -0
  61. package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +763 -0
  62. package/dist/node_modules/@earendil-works/chord/dist/facets/host.js.map +1 -0
  63. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts +3 -0
  64. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts.map +1 -0
  65. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +5 -0
  66. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js.map +1 -0
  67. package/dist/node_modules/@earendil-works/chord/dist/index.d.ts +11 -0
  68. package/dist/node_modules/@earendil-works/chord/dist/index.d.ts.map +1 -0
  69. package/dist/node_modules/@earendil-works/chord/dist/index.js +10 -0
  70. package/dist/node_modules/@earendil-works/chord/dist/index.js.map +1 -0
  71. package/dist/node_modules/@earendil-works/chord/dist/json.d.ts +4 -0
  72. package/dist/node_modules/@earendil-works/chord/dist/json.d.ts.map +1 -0
  73. package/dist/node_modules/@earendil-works/chord/dist/json.js +57 -0
  74. package/dist/node_modules/@earendil-works/chord/dist/json.js.map +1 -0
  75. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts +30 -0
  76. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts.map +1 -0
  77. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +377 -0
  78. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js.map +1 -0
  79. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts +26 -0
  80. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts.map +1 -0
  81. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +183 -0
  82. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js.map +1 -0
  83. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts +36 -0
  84. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts.map +1 -0
  85. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +6 -0
  86. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js.map +1 -0
  87. package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts +15 -0
  88. package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts.map +1 -0
  89. package/dist/node_modules/@earendil-works/chord/dist/node/package.js +199 -0
  90. package/dist/node_modules/@earendil-works/chord/dist/node/package.js.map +1 -0
  91. package/dist/node_modules/@earendil-works/chord/dist/node.d.ts +5 -0
  92. package/dist/node_modules/@earendil-works/chord/dist/node.d.ts.map +1 -0
  93. package/dist/node_modules/@earendil-works/chord/dist/node.js +3 -0
  94. package/dist/node_modules/@earendil-works/chord/dist/node.js.map +1 -0
  95. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts +11 -0
  96. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts.map +1 -0
  97. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +537 -0
  98. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js.map +1 -0
  99. package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts +8 -0
  100. package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts.map +1 -0
  101. package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +22 -0
  102. package/dist/node_modules/@earendil-works/chord/dist/services/errors.js.map +1 -0
  103. package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts +15 -0
  104. package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts.map +1 -0
  105. package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +99 -0
  106. package/dist/node_modules/@earendil-works/chord/dist/services/handle.js.map +1 -0
  107. package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts +25 -0
  108. package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts.map +1 -0
  109. package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +137 -0
  110. package/dist/node_modules/@earendil-works/chord/dist/services/instances.js.map +1 -0
  111. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts +5 -0
  112. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts.map +1 -0
  113. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +15 -0
  114. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js.map +1 -0
  115. package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts +37 -0
  116. package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts.map +1 -0
  117. package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +472 -0
  118. package/dist/node_modules/@earendil-works/chord/dist/services/provider.js.map +1 -0
  119. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts +15 -0
  120. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts.map +1 -0
  121. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +115 -0
  122. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js.map +1 -0
  123. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts +11 -0
  124. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts.map +1 -0
  125. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +10 -0
  126. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js.map +1 -0
  127. package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts +23 -0
  128. package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts.map +1 -0
  129. package/dist/node_modules/@earendil-works/chord/dist/services/state.js +124 -0
  130. package/dist/node_modules/@earendil-works/chord/dist/services/state.js.map +1 -0
  131. package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts +60 -0
  132. package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts.map +1 -0
  133. package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +173 -0
  134. package/dist/node_modules/@earendil-works/chord/dist/services/wire.js.map +1 -0
  135. package/dist/node_modules/@earendil-works/chord/dist/types.d.ts +203 -0
  136. package/dist/node_modules/@earendil-works/chord/dist/types.d.ts.map +1 -0
  137. package/dist/node_modules/@earendil-works/chord/dist/types.js +2 -0
  138. package/dist/node_modules/@earendil-works/chord/dist/types.js.map +1 -0
  139. package/dist/node_modules/@earendil-works/chord/package.json +62 -0
  140. package/dist/node_modules/@earendil-works/chord/src/delta/README.md +404 -0
  141. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  142. package/dist/node_modules/@earendil-works/pi-ai/README.md +3 -1
  143. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  144. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +15 -6
  145. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  146. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  147. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  148. package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
  149. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts.map +1 -1
  150. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +9 -66
  151. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
  152. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +12 -3
  153. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts.map +1 -1
  154. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +50 -3
  155. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js.map +1 -1
  156. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts.map +1 -1
  157. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +13 -58
  158. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
  159. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
  160. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +5 -1
  161. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
  162. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
  163. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -1
  164. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  165. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
  166. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -1
  167. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  168. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +30 -0
  169. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  170. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +34 -4
  171. package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  172. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  173. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  174. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
  175. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  176. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  177. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  178. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  179. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  180. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  181. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  182. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  183. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  184. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  185. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -2
  186. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  187. package/dist/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  188. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  189. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +8 -3
  190. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  191. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  192. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +2 -0
  193. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  194. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  195. package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
  196. package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
  197. package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +57 -0
  198. package/dist/node_modules/@earendil-works/pi-server/LICENSE +21 -0
  199. package/dist/node_modules/@earendil-works/pi-server/README.md +79 -0
  200. package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts +3 -0
  201. package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts.map +1 -0
  202. package/dist/node_modules/@earendil-works/pi-server/dist/cli.js +136 -0
  203. package/dist/node_modules/@earendil-works/pi-server/dist/cli.js.map +1 -0
  204. package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts +12 -0
  205. package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts.map +1 -0
  206. package/dist/node_modules/@earendil-works/pi-server/dist/config.js +55 -0
  207. package/dist/node_modules/@earendil-works/pi-server/dist/config.js.map +1 -0
  208. package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts +35 -0
  209. package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts.map +1 -0
  210. package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +4 -0
  211. package/dist/node_modules/@earendil-works/pi-server/dist/connection.js.map +1 -0
  212. package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts +25 -0
  213. package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts.map +1 -0
  214. package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +41 -0
  215. package/dist/node_modules/@earendil-works/pi-server/dist/errors.js.map +1 -0
  216. package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts +14 -0
  217. package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts.map +1 -0
  218. package/dist/node_modules/@earendil-works/pi-server/dist/handler.js +105 -0
  219. package/dist/node_modules/@earendil-works/pi-server/dist/handler.js.map +1 -0
  220. package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts +5 -0
  221. package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts.map +1 -0
  222. package/dist/node_modules/@earendil-works/pi-server/dist/index.js +5 -0
  223. package/dist/node_modules/@earendil-works/pi-server/dist/index.js.map +1 -0
  224. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts +3 -0
  225. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts.map +1 -0
  226. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js +56 -0
  227. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js.map +1 -0
  228. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts +99 -0
  229. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts.map +1 -0
  230. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js +12 -0
  231. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js.map +1 -0
  232. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts +20 -0
  233. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts.map +1 -0
  234. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js +145 -0
  235. package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js.map +1 -0
  236. package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts +8 -0
  237. package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts.map +1 -0
  238. package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +2 -0
  239. package/dist/node_modules/@earendil-works/pi-server/dist/listener.js.map +1 -0
  240. package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts +22 -0
  241. package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts.map +1 -0
  242. package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js +266 -0
  243. package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js.map +1 -0
  244. package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts +36 -0
  245. package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts.map +1 -0
  246. package/dist/node_modules/@earendil-works/pi-server/dist/radius.js +360 -0
  247. package/dist/node_modules/@earendil-works/pi-server/dist/radius.js.map +1 -0
  248. package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts +31 -0
  249. package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts.map +1 -0
  250. package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js +168 -0
  251. package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js.map +1 -0
  252. package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts +2 -0
  253. package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts.map +1 -0
  254. package/dist/node_modules/@earendil-works/pi-server/dist/serve.js +70 -0
  255. package/dist/node_modules/@earendil-works/pi-server/dist/serve.js.map +1 -0
  256. package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts +46 -0
  257. package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts.map +1 -0
  258. package/dist/node_modules/@earendil-works/pi-server/dist/server.js +549 -0
  259. package/dist/node_modules/@earendil-works/pi-server/dist/server.js.map +1 -0
  260. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts +40 -0
  261. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts.map +1 -0
  262. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +264 -0
  263. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js.map +1 -0
  264. package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts +2195 -0
  265. package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts.map +1 -0
  266. package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js +332 -0
  267. package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js.map +1 -0
  268. package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts +24 -0
  269. package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts.map +1 -0
  270. package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js +39 -0
  271. package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js.map +1 -0
  272. package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts +10 -0
  273. package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts.map +1 -0
  274. package/dist/node_modules/@earendil-works/pi-server/dist/storage.js +58 -0
  275. package/dist/node_modules/@earendil-works/pi-server/dist/storage.js.map +1 -0
  276. package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts +34 -0
  277. package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts.map +1 -0
  278. package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js +290 -0
  279. package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js.map +1 -0
  280. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts +35 -0
  281. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts.map +1 -0
  282. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +138 -0
  283. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js.map +1 -0
  284. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts +57 -0
  285. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts.map +1 -0
  286. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +189 -0
  287. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js.map +1 -0
  288. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts +6 -0
  289. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts.map +1 -0
  290. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +4 -0
  291. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js.map +1 -0
  292. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts +13 -0
  293. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts.map +1 -0
  294. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +17 -0
  295. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js.map +1 -0
  296. package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts +66 -0
  297. package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts.map +1 -0
  298. package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js +254 -0
  299. package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js.map +1 -0
  300. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts +3 -0
  301. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts.map +1 -0
  302. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +9 -0
  303. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js.map +1 -0
  304. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts +5 -0
  305. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts.map +1 -0
  306. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +4 -0
  307. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js.map +1 -0
  308. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts +24 -0
  309. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts.map +1 -0
  310. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +421 -0
  311. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js.map +1 -0
  312. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts +7 -0
  313. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts.map +1 -0
  314. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +22 -0
  315. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js.map +1 -0
  316. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts +15 -0
  317. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts.map +1 -0
  318. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +2 -0
  319. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js.map +1 -0
  320. package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts +49 -0
  321. package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts.map +1 -0
  322. package/dist/node_modules/@earendil-works/pi-server/dist/types.js +2 -0
  323. package/dist/node_modules/@earendil-works/pi-server/dist/types.js.map +1 -0
  324. package/dist/node_modules/@earendil-works/pi-server/package.json +45 -0
  325. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/CHANGELOG.md +46 -0
  326. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/LICENSE +21 -0
  327. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/README.md +33 -0
  328. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts +6 -0
  329. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts.map +1 -0
  330. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js +103 -0
  331. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js.map +1 -0
  332. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts +6 -0
  333. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts.map +1 -0
  334. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js +70 -0
  335. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js.map +1 -0
  336. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts +5 -0
  337. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts.map +1 -0
  338. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js +4 -0
  339. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js.map +1 -0
  340. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations/001_initial.sql +121 -0
  341. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts +3 -0
  342. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts.map +1 -0
  343. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js +7 -0
  344. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js.map +1 -0
  345. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts +41 -0
  346. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts.map +1 -0
  347. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js +408 -0
  348. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js.map +1 -0
  349. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts +14 -0
  350. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts.map +1 -0
  351. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js +153 -0
  352. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js.map +1 -0
  353. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts +6 -0
  354. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts.map +1 -0
  355. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js +213 -0
  356. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js.map +1 -0
  357. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts +24 -0
  358. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts.map +1 -0
  359. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js +126 -0
  360. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js.map +1 -0
  361. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts +23 -0
  362. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts.map +1 -0
  363. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js +69 -0
  364. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js.map +1 -0
  365. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts +4 -0
  366. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts.map +1 -0
  367. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js +13 -0
  368. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js.map +1 -0
  369. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts +6 -0
  370. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts.map +1 -0
  371. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js +39 -0
  372. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js.map +1 -0
  373. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts +20 -0
  374. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts.map +1 -0
  375. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js +50 -0
  376. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js.map +1 -0
  377. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts +23 -0
  378. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts.map +1 -0
  379. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js +91 -0
  380. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js.map +1 -0
  381. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts +42 -0
  382. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts.map +1 -0
  383. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js +163 -0
  384. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js.map +1 -0
  385. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts +19 -0
  386. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts.map +1 -0
  387. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js +58 -0
  388. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js.map +1 -0
  389. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts +41 -0
  390. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts.map +1 -0
  391. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js +112 -0
  392. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js.map +1 -0
  393. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts +7 -0
  394. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts.map +1 -0
  395. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js +22 -0
  396. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js.map +1 -0
  397. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts +34 -0
  398. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts.map +1 -0
  399. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js +37 -0
  400. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js.map +1 -0
  401. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts +20 -0
  402. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts.map +1 -0
  403. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js +38 -0
  404. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js.map +1 -0
  405. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts +35 -0
  406. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts.map +1 -0
  407. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js +95 -0
  408. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js.map +1 -0
  409. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts +38 -0
  410. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts.map +1 -0
  411. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js +49 -0
  412. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js.map +1 -0
  413. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts +7 -0
  414. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts.map +1 -0
  415. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js +22 -0
  416. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js.map +1 -0
  417. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts +17 -0
  418. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts.map +1 -0
  419. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js +40 -0
  420. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js.map +1 -0
  421. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts +26 -0
  422. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts.map +1 -0
  423. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js +99 -0
  424. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js.map +1 -0
  425. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts +15 -0
  426. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts.map +1 -0
  427. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js +31 -0
  428. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js.map +1 -0
  429. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts +38 -0
  430. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts.map +1 -0
  431. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js +161 -0
  432. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js.map +1 -0
  433. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts +29 -0
  434. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts.map +1 -0
  435. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js +2 -0
  436. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js.map +1 -0
  437. package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +33 -0
  438. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  439. package/dist/node_modules/@earendil-works/pi-tui/dist/layout.d.ts.map +1 -1
  440. package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js +5 -2
  441. package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js.map +1 -1
  442. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  443. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +17 -4
  444. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  445. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  446. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  447. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  448. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  449. package/examples/extensions/gondolin/package-lock.json +2 -2
  450. package/examples/extensions/gondolin/package.json +1 -1
  451. package/examples/extensions/official/package.json +1 -1
  452. package/examples/extensions/sandbox/package-lock.json +2 -2
  453. package/examples/extensions/sandbox/package.json +1 -1
  454. package/examples/extensions/with-deps/package-lock.json +2 -2
  455. package/examples/extensions/with-deps/package.json +1 -1
  456. package/examples/plugins/pi-example-plugin/package.json +1 -1
  457. package/npm-shrinkwrap.json +3 -14
  458. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC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,GACvB,WAAW,CAwBb;AAMD,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAUtF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAUlG;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAUvF","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, Container, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\ninterface ExactContainerMetrics {\n\twidth: number;\n\tgeneration: number;\n\tlastChild: Component | undefined;\n\theights: number[];\n\tprefix: number[];\n\ttotal: number;\n}\n\nconst exactContainerMetrics = new WeakMap<Container, ExactContainerMetrics>();\n\nfunction remeasureExactContainerRange(\n\tcontext: LayoutContext,\n\tmetrics: ExactContainerMetrics,\n\tchildren: Component[],\n\tstart: number,\n\twidth: number,\n): void {\n\tlet total = start === 0 ? 0 : (metrics.prefix[start - 1] ?? 0);\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst height = measureHeight(context, children[index]!, width);\n\t\tmetrics.heights[index] = height;\n\t\ttotal += height;\n\t\tmetrics.prefix[index] = total;\n\t}\n\tmetrics.heights.length = children.length;\n\tmetrics.prefix.length = children.length;\n\tmetrics.total = total;\n\tmetrics.lastChild = children.length === 0 ? undefined : children[children.length - 1];\n}\n\nfunction syncExactContainerMetrics(context: LayoutContext, component: Container, width: number): ExactContainerMetrics {\n\tconst children = component.children;\n\tlet metrics = exactContainerMetrics.get(component);\n\tif (!metrics || metrics.width !== width) {\n\t\tmetrics = {\n\t\t\twidth,\n\t\t\tgeneration: component.layoutGeneration,\n\t\t\tlastChild: undefined,\n\t\t\theights: [],\n\t\t\tprefix: [],\n\t\t\ttotal: 0,\n\t\t};\n\t\texactContainerMetrics.set(component, metrics);\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tconst generationChanged = metrics.generation !== component.layoutGeneration;\n\tmetrics.generation = component.layoutGeneration;\n\tif (children.length < metrics.heights.length) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > metrics.heights.length) {\n\t\tconst previousLast = metrics.lastChild;\n\t\tconst aligned = metrics.heights.length === 0 || previousLast === children[metrics.heights.length - 1];\n\t\tremeasureExactContainerRange(context, metrics, children, aligned ? metrics.heights.length : 0, width);\n\t\treturn metrics;\n\t}\n\tif (generationChanged) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > 0) {\n\t\tconst last = children[children.length - 1]!;\n\t\tif (last !== metrics.lastChild) {\n\t\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\t\treturn metrics;\n\t\t}\n\t\tconst previous = metrics.heights[children.length - 1]!;\n\t\tconst height = measureHeight(context, last, width);\n\t\tif (height !== previous) {\n\t\t\tmetrics.heights[children.length - 1] = height;\n\t\t\tconst total = (children.length === 1 ? 0 : metrics.prefix[children.length - 2]!) + height;\n\t\t\tmetrics.prefix[children.length - 1] = total;\n\t\t\tmetrics.total = total;\n\t\t}\n\t}\n\treturn metrics;\n}\n\nfunction firstIndexPast(prefix: number[], threshold: number): number {\n\tlet low = 0;\n\tlet high = prefix.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >> 1;\n\t\tif ((prefix[mid] ?? 0) > threshold) high = mid;\n\t\telse low = mid + 1;\n\t}\n\treturn low;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\treturn syncExactContainerMetrics(context, component, safeWidth).total;\n\t}\n\treturn component.render(safeWidth).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\tlet max = 0;\n\t\tfor (const child of component.children) {\n\t\t\tmax = Math.max(max, measureWidth(context, child, width));\n\t\t}\n\t\treturn max;\n\t}\n\treturn component.render(Math.max(1, Math.floor(width))).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction isExactContainer(component: Component): component is Container {\n\treturn component.constructor === Container;\n}\n\nfunction layoutExactContainer(\n\tcontext: LayoutContext,\n\tcomponent: Container,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst children = component.children;\n\tconst metrics = syncExactContainerMetrics(context, component, width);\n\tconst allocatedHeight = height === undefined ? metrics.total : Math.max(0, Math.floor(height));\n\tconst rect = { x, y, width, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tif (children.length === 0 || box.clip.height <= 0) return box;\n\tconst start = firstIndexPast(metrics.prefix, box.clip.y - y);\n\tconst clipBottom = box.clip.y + box.clip.height - y;\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst childHeight = metrics.heights[index]!;\n\t\tconst childY = y + (index === 0 ? 0 : metrics.prefix[index - 1]!);\n\t\tif (childY >= box.clip.y + box.clip.height) break;\n\t\tif (childHeight > 0 && childY < box.clip.y + box.clip.height && childY + childHeight > box.clip.y) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(layoutComponent(context, children[index]!, x, childY, width, childHeight, box.clip), box),\n\t\t\t);\n\t\t}\n\t\tif (index > 0 && metrics.prefix[index - 1]! >= clipBottom) break;\n\t}\n\treturn box;\n}\n\nfunction layoutLeaf(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst lines = renderCached(context, component, width);\n\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\tlet lineOffset = 0;\n\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t}\n\treturn {\n\t\tcomponent,\n\t\trect: { x, y, width, height: allocatedHeight },\n\t\tclip: intersect(clip, { x, y, width, height: allocatedHeight }),\n\t\tchildren: [],\n\t\tlines,\n\t\tlineOffset,\n\t\tlayer: 0,\n\t};\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tif (isExactContainer(component)) {\n\t\t\treturn layoutExactContainer(context, component, x, y, safeWidth, height, clip);\n\t\t}\n\t\treturn layoutLeaf(context, component, x, y, safeWidth, height, clip);\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst structuredChild = isExactContainer(node.component);\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tlet childBox: LayoutBox;\n\t\tlet contentHeight: number;\n\t\tif (structuredChild) {\n\t\t\tcontentHeight = measureHeight(context, node.component, contentWidth);\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\tchildBox = layoutComponent(\n\t\t\t\tcontext,\n\t\t\t\tnode.component,\n\t\t\t\tx,\n\t\t\t\ty - node.state.scrollTop,\n\t\t\t\tcontentWidth,\n\t\t\t\tundefined,\n\t\t\t\tclip,\n\t\t\t);\n\t\t} else {\n\t\t\tchildBox = layoutComponent(context, node.component, x, y - previousScrollTop, contentWidth, undefined, clip);\n\t\t\tcontentHeight = childBox.rect.height;\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\t}\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: structuredChild ? undefined : renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tconst padX = Math.max(0, Math.floor(node.padX ?? 0));\n\tconst padY = Math.max(0, Math.floor(node.padY ?? 0));\n\tconst innerWidth = Math.max(1, safeWidth - padX * 2);\n\tconst innerX = x + padX;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, innerWidth),\n\t\t);\n\t\tconst innerHeight = height === undefined ? undefined : Math.max(0, Math.floor(height) - padY * 2);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, innerHeight, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal + padY * 2;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y + padY;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, innerX, childY, innerWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, innerWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, innerWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = innerX;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\tconst targetStyle = `\\x1b[0m\\x1b]8;;\\x07${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintUnreadIndicator(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst count = box.scrollView?.unreadCount ?? 0;\n\tif (count <= 0 || box.clip.height <= 0) return;\n\tconst row = Math.min(screen.length, box.clip.y + box.clip.height) - 1;\n\tif (row < box.clip.y || row < 0) return;\n\tconst label = `\\x1b[7m +${count} \\x1b[27m`;\n\tconst width = visibleWidth(label);\n\tconst start = Math.max(box.clip.x, box.rect.x + box.rect.width - width);\n\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", label, start, width, totalWidth);\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n\tpaintUnreadIndicator(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAI9D,OAAO,EAAE,KAAK,SAAS,EAA8C,MAAM,UAAU,CAAC;AAWtF,MAAM,WAAW,UAAU;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iBAAiB,CAAC,EAAE,UAAU,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACrB;AAuZD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,iBAAiB,UAAQ,GAAG,iBAAiB,GAAG,SAAS,CA2B7G;AAoFD,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,IAAI,GACvB,WAAW,CAwBb;AAMD,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAUtF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAUlG;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAUvF","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getCapabilities, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, Container, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\ninterface ExactContainerMetrics {\n\twidth: number;\n\tgeneration: number;\n\tlastChild: Component | undefined;\n\theights: number[];\n\tprefix: number[];\n\ttotal: number;\n}\n\nconst exactContainerMetrics = new WeakMap<Container, ExactContainerMetrics>();\n\nfunction remeasureExactContainerRange(\n\tcontext: LayoutContext,\n\tmetrics: ExactContainerMetrics,\n\tchildren: Component[],\n\tstart: number,\n\twidth: number,\n): void {\n\tlet total = start === 0 ? 0 : (metrics.prefix[start - 1] ?? 0);\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst height = measureHeight(context, children[index]!, width);\n\t\tmetrics.heights[index] = height;\n\t\ttotal += height;\n\t\tmetrics.prefix[index] = total;\n\t}\n\tmetrics.heights.length = children.length;\n\tmetrics.prefix.length = children.length;\n\tmetrics.total = total;\n\tmetrics.lastChild = children.length === 0 ? undefined : children[children.length - 1];\n}\n\nfunction syncExactContainerMetrics(context: LayoutContext, component: Container, width: number): ExactContainerMetrics {\n\tconst children = component.children;\n\tlet metrics = exactContainerMetrics.get(component);\n\tif (!metrics || metrics.width !== width) {\n\t\tmetrics = {\n\t\t\twidth,\n\t\t\tgeneration: component.layoutGeneration,\n\t\t\tlastChild: undefined,\n\t\t\theights: [],\n\t\t\tprefix: [],\n\t\t\ttotal: 0,\n\t\t};\n\t\texactContainerMetrics.set(component, metrics);\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tconst generationChanged = metrics.generation !== component.layoutGeneration;\n\tmetrics.generation = component.layoutGeneration;\n\tif (children.length < metrics.heights.length) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > metrics.heights.length) {\n\t\tconst previousLast = metrics.lastChild;\n\t\tconst aligned = metrics.heights.length === 0 || previousLast === children[metrics.heights.length - 1];\n\t\tremeasureExactContainerRange(context, metrics, children, aligned ? metrics.heights.length : 0, width);\n\t\treturn metrics;\n\t}\n\tif (generationChanged) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > 0) {\n\t\tconst last = children[children.length - 1]!;\n\t\tif (last !== metrics.lastChild) {\n\t\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\t\treturn metrics;\n\t\t}\n\t\tconst previous = metrics.heights[children.length - 1]!;\n\t\tconst height = measureHeight(context, last, width);\n\t\tif (height !== previous) {\n\t\t\tmetrics.heights[children.length - 1] = height;\n\t\t\tconst total = (children.length === 1 ? 0 : metrics.prefix[children.length - 2]!) + height;\n\t\t\tmetrics.prefix[children.length - 1] = total;\n\t\t\tmetrics.total = total;\n\t\t}\n\t}\n\treturn metrics;\n}\n\nfunction firstIndexPast(prefix: number[], threshold: number): number {\n\tlet low = 0;\n\tlet high = prefix.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >> 1;\n\t\tif ((prefix[mid] ?? 0) > threshold) high = mid;\n\t\telse low = mid + 1;\n\t}\n\treturn low;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\treturn syncExactContainerMetrics(context, component, safeWidth).total;\n\t}\n\treturn component.render(safeWidth).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\tlet max = 0;\n\t\tfor (const child of component.children) {\n\t\t\tmax = Math.max(max, measureWidth(context, child, width));\n\t\t}\n\t\treturn max;\n\t}\n\treturn component.render(Math.max(1, Math.floor(width))).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction isExactContainer(component: Component): component is Container {\n\treturn component.constructor === Container;\n}\n\nfunction layoutExactContainer(\n\tcontext: LayoutContext,\n\tcomponent: Container,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst children = component.children;\n\tconst metrics = syncExactContainerMetrics(context, component, width);\n\tconst allocatedHeight = height === undefined ? metrics.total : Math.max(0, Math.floor(height));\n\tconst rect = { x, y, width, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tif (children.length === 0 || box.clip.height <= 0) return box;\n\tconst start = firstIndexPast(metrics.prefix, box.clip.y - y);\n\tconst clipBottom = box.clip.y + box.clip.height - y;\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst childHeight = metrics.heights[index]!;\n\t\tconst childY = y + (index === 0 ? 0 : metrics.prefix[index - 1]!);\n\t\tif (childY >= box.clip.y + box.clip.height) break;\n\t\tif (childHeight > 0 && childY < box.clip.y + box.clip.height && childY + childHeight > box.clip.y) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(layoutComponent(context, children[index]!, x, childY, width, childHeight, box.clip), box),\n\t\t\t);\n\t\t}\n\t\tif (index > 0 && metrics.prefix[index - 1]! >= clipBottom) break;\n\t}\n\treturn box;\n}\n\nfunction layoutLeaf(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst lines = renderCached(context, component, width);\n\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\tlet lineOffset = 0;\n\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t}\n\treturn {\n\t\tcomponent,\n\t\trect: { x, y, width, height: allocatedHeight },\n\t\tclip: intersect(clip, { x, y, width, height: allocatedHeight }),\n\t\tchildren: [],\n\t\tlines,\n\t\tlineOffset,\n\t\tlayer: 0,\n\t};\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tif (isExactContainer(component)) {\n\t\t\treturn layoutExactContainer(context, component, x, y, safeWidth, height, clip);\n\t\t}\n\t\treturn layoutLeaf(context, component, x, y, safeWidth, height, clip);\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst structuredChild = isExactContainer(node.component);\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tlet childBox: LayoutBox;\n\t\tlet contentHeight: number;\n\t\tif (structuredChild) {\n\t\t\tcontentHeight = measureHeight(context, node.component, contentWidth);\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\tchildBox = layoutComponent(\n\t\t\t\tcontext,\n\t\t\t\tnode.component,\n\t\t\t\tx,\n\t\t\t\ty - node.state.scrollTop,\n\t\t\t\tcontentWidth,\n\t\t\t\tundefined,\n\t\t\t\tclip,\n\t\t\t);\n\t\t} else {\n\t\t\tchildBox = layoutComponent(context, node.component, x, y - previousScrollTop, contentWidth, undefined, clip);\n\t\t\tcontentHeight = childBox.rect.height;\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\t}\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: structuredChild ? undefined : renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tconst padX = Math.max(0, Math.floor(node.padX ?? 0));\n\tconst padY = Math.max(0, Math.floor(node.padY ?? 0));\n\tconst innerWidth = Math.max(1, safeWidth - padX * 2);\n\tconst innerX = x + padX;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, innerWidth),\n\t\t);\n\t\tconst innerHeight = height === undefined ? undefined : Math.max(0, Math.floor(height) - padY * 2);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, innerHeight, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal + padY * 2;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y + padY;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, innerX, childY, innerWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, innerWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, innerWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = innerX;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\t// Same rule as tui.ts: never send an OSC 8 close to a terminal that has not\n\t// been identified as hyperlink-capable.\n\tconst linkClose = getCapabilities().hyperlinks ? \"\\x1b]8;;\\x07\" : \"\";\n\tconst targetStyle = `\\x1b[0m${linkClose}${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintUnreadIndicator(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst count = box.scrollView?.unreadCount ?? 0;\n\tif (count <= 0 || box.clip.height <= 0) return;\n\tconst row = Math.min(screen.length, box.clip.y + box.clip.height) - 1;\n\tif (row < box.clip.y || row < 0) return;\n\tconst label = `\\x1b[7m +${count} \\x1b[27m`;\n\tconst width = visibleWidth(label);\n\tconst start = Math.max(box.clip.x, box.rect.x + box.rect.width - width);\n\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", label, start, width, totalWidth);\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n\tpaintUnreadIndicator(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { allocateStackSizes, visibleStackEntries } from "./components/stack.js";
2
2
  import { getLayoutNode } from "./layout-node.js";
3
- import { cropKittyImageLine, getKittyImageMetadata, isImageLine } from "./terminal-image.js";
3
+ import { cropKittyImageLine, getCapabilities, getKittyImageMetadata, isImageLine } from "./terminal-image.js";
4
4
  import { Container, CURSOR_MARKER, compositeTuiLine } from "./tui.js";
5
5
  import { extractAnsiCode, getActiveBackgroundAnsi, getGraphemeCellRange, sliceByColumn, visibleWidth, } from "./utils.js";
6
6
  const OSC133_ZONE_PREFIX = /^(?:\x1b\]133;[ABC](?:\x07|\x1b\\))+/;
@@ -318,7 +318,10 @@ function replaceScrollbarCell(line, column, totalWidth, replacement, preserveTar
318
318
  const beforePadding = " ".repeat(Math.max(0, start - visibleWidth(before)));
319
319
  const cellPaddingBefore = " ".repeat(Math.max(0, column - start));
320
320
  const cellPaddingAfter = " ".repeat(Math.max(0, end - column - 1));
321
- const targetStyle = `\x1b[0m\x1b]8;;\x07${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : ""}`;
321
+ // Same rule as tui.ts: never send an OSC 8 close to a terminal that has not
322
+ // been identified as hyperlink-capable.
323
+ const linkClose = getCapabilities().hyperlinks ? "\x1b]8;;\x07" : "";
324
+ const targetStyle = `\x1b[0m${linkClose}${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : ""}`;
322
325
  return `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;
323
326
  }
324
327
  export function getScrollbarGeometry(box, includeHiddenAuto = false) {
@@ -1 +1 @@
1
- {"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAkB,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACtF,OAAO,EACN,eAAe,EACf,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,YAAY,GACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,kBAAkB,GAAG,sCAAsC,CAAC;AAuDlE,MAAM,qBAAqB,GAAG,IAAI,OAAO,EAAoC,CAAC;AAE9E,SAAS,4BAA4B,CACpC,OAAsB,E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,KAAK,CAAC,IAAI,CAAC,CAAC;AAAA,CACzB;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAkB,EAAE,CAAS,EAAE,CAAS,EAAgB;IACxF,MAAM,MAAM,GAAqD,EAAE,CAAC;IACpE,MAAM,KAAK,GAAG,CAAC,GAAc,EAAE,KAAa,EAAQ,EAAE,CAAC;QACtD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAAE,OAAO;QAC3C,IAAI,GAAG,CAAC,UAAU,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACxG,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,QAAQ;YAAE,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IAAA,CAC1D,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAAA,CAC/C","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, Container, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\ninterface ExactContainerMetrics {\n\twidth: number;\n\tgeneration: number;\n\tlastChild: Component | undefined;\n\theights: number[];\n\tprefix: number[];\n\ttotal: number;\n}\n\nconst exactContainerMetrics = new WeakMap<Container, ExactContainerMetrics>();\n\nfunction remeasureExactContainerRange(\n\tcontext: LayoutContext,\n\tmetrics: ExactContainerMetrics,\n\tchildren: Component[],\n\tstart: number,\n\twidth: number,\n): void {\n\tlet total = start === 0 ? 0 : (metrics.prefix[start - 1] ?? 0);\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst height = measureHeight(context, children[index]!, width);\n\t\tmetrics.heights[index] = height;\n\t\ttotal += height;\n\t\tmetrics.prefix[index] = total;\n\t}\n\tmetrics.heights.length = children.length;\n\tmetrics.prefix.length = children.length;\n\tmetrics.total = total;\n\tmetrics.lastChild = children.length === 0 ? undefined : children[children.length - 1];\n}\n\nfunction syncExactContainerMetrics(context: LayoutContext, component: Container, width: number): ExactContainerMetrics {\n\tconst children = component.children;\n\tlet metrics = exactContainerMetrics.get(component);\n\tif (!metrics || metrics.width !== width) {\n\t\tmetrics = {\n\t\t\twidth,\n\t\t\tgeneration: component.layoutGeneration,\n\t\t\tlastChild: undefined,\n\t\t\theights: [],\n\t\t\tprefix: [],\n\t\t\ttotal: 0,\n\t\t};\n\t\texactContainerMetrics.set(component, metrics);\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tconst generationChanged = metrics.generation !== component.layoutGeneration;\n\tmetrics.generation = component.layoutGeneration;\n\tif (children.length < metrics.heights.length) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > metrics.heights.length) {\n\t\tconst previousLast = metrics.lastChild;\n\t\tconst aligned = metrics.heights.length === 0 || previousLast === children[metrics.heights.length - 1];\n\t\tremeasureExactContainerRange(context, metrics, children, aligned ? metrics.heights.length : 0, width);\n\t\treturn metrics;\n\t}\n\tif (generationChanged) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > 0) {\n\t\tconst last = children[children.length - 1]!;\n\t\tif (last !== metrics.lastChild) {\n\t\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\t\treturn metrics;\n\t\t}\n\t\tconst previous = metrics.heights[children.length - 1]!;\n\t\tconst height = measureHeight(context, last, width);\n\t\tif (height !== previous) {\n\t\t\tmetrics.heights[children.length - 1] = height;\n\t\t\tconst total = (children.length === 1 ? 0 : metrics.prefix[children.length - 2]!) + height;\n\t\t\tmetrics.prefix[children.length - 1] = total;\n\t\t\tmetrics.total = total;\n\t\t}\n\t}\n\treturn metrics;\n}\n\nfunction firstIndexPast(prefix: number[], threshold: number): number {\n\tlet low = 0;\n\tlet high = prefix.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >> 1;\n\t\tif ((prefix[mid] ?? 0) > threshold) high = mid;\n\t\telse low = mid + 1;\n\t}\n\treturn low;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\treturn syncExactContainerMetrics(context, component, safeWidth).total;\n\t}\n\treturn component.render(safeWidth).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\tlet max = 0;\n\t\tfor (const child of component.children) {\n\t\t\tmax = Math.max(max, measureWidth(context, child, width));\n\t\t}\n\t\treturn max;\n\t}\n\treturn component.render(Math.max(1, Math.floor(width))).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction isExactContainer(component: Component): component is Container {\n\treturn component.constructor === Container;\n}\n\nfunction layoutExactContainer(\n\tcontext: LayoutContext,\n\tcomponent: Container,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst children = component.children;\n\tconst metrics = syncExactContainerMetrics(context, component, width);\n\tconst allocatedHeight = height === undefined ? metrics.total : Math.max(0, Math.floor(height));\n\tconst rect = { x, y, width, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tif (children.length === 0 || box.clip.height <= 0) return box;\n\tconst start = firstIndexPast(metrics.prefix, box.clip.y - y);\n\tconst clipBottom = box.clip.y + box.clip.height - y;\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst childHeight = metrics.heights[index]!;\n\t\tconst childY = y + (index === 0 ? 0 : metrics.prefix[index - 1]!);\n\t\tif (childY >= box.clip.y + box.clip.height) break;\n\t\tif (childHeight > 0 && childY < box.clip.y + box.clip.height && childY + childHeight > box.clip.y) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(layoutComponent(context, children[index]!, x, childY, width, childHeight, box.clip), box),\n\t\t\t);\n\t\t}\n\t\tif (index > 0 && metrics.prefix[index - 1]! >= clipBottom) break;\n\t}\n\treturn box;\n}\n\nfunction layoutLeaf(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst lines = renderCached(context, component, width);\n\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\tlet lineOffset = 0;\n\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t}\n\treturn {\n\t\tcomponent,\n\t\trect: { x, y, width, height: allocatedHeight },\n\t\tclip: intersect(clip, { x, y, width, height: allocatedHeight }),\n\t\tchildren: [],\n\t\tlines,\n\t\tlineOffset,\n\t\tlayer: 0,\n\t};\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tif (isExactContainer(component)) {\n\t\t\treturn layoutExactContainer(context, component, x, y, safeWidth, height, clip);\n\t\t}\n\t\treturn layoutLeaf(context, component, x, y, safeWidth, height, clip);\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst structuredChild = isExactContainer(node.component);\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tlet childBox: LayoutBox;\n\t\tlet contentHeight: number;\n\t\tif (structuredChild) {\n\t\t\tcontentHeight = measureHeight(context, node.component, contentWidth);\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\tchildBox = layoutComponent(\n\t\t\t\tcontext,\n\t\t\t\tnode.component,\n\t\t\t\tx,\n\t\t\t\ty - node.state.scrollTop,\n\t\t\t\tcontentWidth,\n\t\t\t\tundefined,\n\t\t\t\tclip,\n\t\t\t);\n\t\t} else {\n\t\t\tchildBox = layoutComponent(context, node.component, x, y - previousScrollTop, contentWidth, undefined, clip);\n\t\t\tcontentHeight = childBox.rect.height;\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\t}\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: structuredChild ? undefined : renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tconst padX = Math.max(0, Math.floor(node.padX ?? 0));\n\tconst padY = Math.max(0, Math.floor(node.padY ?? 0));\n\tconst innerWidth = Math.max(1, safeWidth - padX * 2);\n\tconst innerX = x + padX;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, innerWidth),\n\t\t);\n\t\tconst innerHeight = height === undefined ? undefined : Math.max(0, Math.floor(height) - padY * 2);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, innerHeight, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal + padY * 2;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y + padY;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, innerX, childY, innerWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, innerWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, innerWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = innerX;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\tconst targetStyle = `\\x1b[0m\\x1b]8;;\\x07${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintUnreadIndicator(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst count = box.scrollView?.unreadCount ?? 0;\n\tif (count <= 0 || box.clip.height <= 0) return;\n\tconst row = Math.min(screen.length, box.clip.y + box.clip.height) - 1;\n\tif (row < box.clip.y || row < 0) return;\n\tconst label = `\\x1b[7m +${count} \\x1b[27m`;\n\tconst width = visibleWidth(label);\n\tconst start = Math.max(box.clip.x, box.rect.x + box.rect.width - width);\n\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", label, start, width, totalWidth);\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n\tpaintUnreadIndicator(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAkB,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACtF,OA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,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAAA,CAC/C","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getCapabilities, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, Container, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\ninterface ExactContainerMetrics {\n\twidth: number;\n\tgeneration: number;\n\tlastChild: Component | undefined;\n\theights: number[];\n\tprefix: number[];\n\ttotal: number;\n}\n\nconst exactContainerMetrics = new WeakMap<Container, ExactContainerMetrics>();\n\nfunction remeasureExactContainerRange(\n\tcontext: LayoutContext,\n\tmetrics: ExactContainerMetrics,\n\tchildren: Component[],\n\tstart: number,\n\twidth: number,\n): void {\n\tlet total = start === 0 ? 0 : (metrics.prefix[start - 1] ?? 0);\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst height = measureHeight(context, children[index]!, width);\n\t\tmetrics.heights[index] = height;\n\t\ttotal += height;\n\t\tmetrics.prefix[index] = total;\n\t}\n\tmetrics.heights.length = children.length;\n\tmetrics.prefix.length = children.length;\n\tmetrics.total = total;\n\tmetrics.lastChild = children.length === 0 ? undefined : children[children.length - 1];\n}\n\nfunction syncExactContainerMetrics(context: LayoutContext, component: Container, width: number): ExactContainerMetrics {\n\tconst children = component.children;\n\tlet metrics = exactContainerMetrics.get(component);\n\tif (!metrics || metrics.width !== width) {\n\t\tmetrics = {\n\t\t\twidth,\n\t\t\tgeneration: component.layoutGeneration,\n\t\t\tlastChild: undefined,\n\t\t\theights: [],\n\t\t\tprefix: [],\n\t\t\ttotal: 0,\n\t\t};\n\t\texactContainerMetrics.set(component, metrics);\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tconst generationChanged = metrics.generation !== component.layoutGeneration;\n\tmetrics.generation = component.layoutGeneration;\n\tif (children.length < metrics.heights.length) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > metrics.heights.length) {\n\t\tconst previousLast = metrics.lastChild;\n\t\tconst aligned = metrics.heights.length === 0 || previousLast === children[metrics.heights.length - 1];\n\t\tremeasureExactContainerRange(context, metrics, children, aligned ? metrics.heights.length : 0, width);\n\t\treturn metrics;\n\t}\n\tif (generationChanged) {\n\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\treturn metrics;\n\t}\n\tif (children.length > 0) {\n\t\tconst last = children[children.length - 1]!;\n\t\tif (last !== metrics.lastChild) {\n\t\t\tremeasureExactContainerRange(context, metrics, children, 0, width);\n\t\t\treturn metrics;\n\t\t}\n\t\tconst previous = metrics.heights[children.length - 1]!;\n\t\tconst height = measureHeight(context, last, width);\n\t\tif (height !== previous) {\n\t\t\tmetrics.heights[children.length - 1] = height;\n\t\t\tconst total = (children.length === 1 ? 0 : metrics.prefix[children.length - 2]!) + height;\n\t\t\tmetrics.prefix[children.length - 1] = total;\n\t\t\tmetrics.total = total;\n\t\t}\n\t}\n\treturn metrics;\n}\n\nfunction firstIndexPast(prefix: number[], threshold: number): number {\n\tlet low = 0;\n\tlet high = prefix.length;\n\twhile (low < high) {\n\t\tconst mid = (low + high) >> 1;\n\t\tif ((prefix[mid] ?? 0) > threshold) high = mid;\n\t\telse low = mid + 1;\n\t}\n\treturn low;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\treturn syncExactContainerMetrics(context, component, safeWidth).total;\n\t}\n\treturn component.render(safeWidth).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\tif (isExactContainer(component) && !getLayoutNode(component)) {\n\t\tlet max = 0;\n\t\tfor (const child of component.children) {\n\t\t\tmax = Math.max(max, measureWidth(context, child, width));\n\t\t}\n\t\treturn max;\n\t}\n\treturn component.render(Math.max(1, Math.floor(width))).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction isExactContainer(component: Component): component is Container {\n\treturn component.constructor === Container;\n}\n\nfunction layoutExactContainer(\n\tcontext: LayoutContext,\n\tcomponent: Container,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst children = component.children;\n\tconst metrics = syncExactContainerMetrics(context, component, width);\n\tconst allocatedHeight = height === undefined ? metrics.total : Math.max(0, Math.floor(height));\n\tconst rect = { x, y, width, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tif (children.length === 0 || box.clip.height <= 0) return box;\n\tconst start = firstIndexPast(metrics.prefix, box.clip.y - y);\n\tconst clipBottom = box.clip.y + box.clip.height - y;\n\tfor (let index = start; index < children.length; index++) {\n\t\tconst childHeight = metrics.heights[index]!;\n\t\tconst childY = y + (index === 0 ? 0 : metrics.prefix[index - 1]!);\n\t\tif (childY >= box.clip.y + box.clip.height) break;\n\t\tif (childHeight > 0 && childY < box.clip.y + box.clip.height && childY + childHeight > box.clip.y) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(layoutComponent(context, children[index]!, x, childY, width, childHeight, box.clip), box),\n\t\t\t);\n\t\t}\n\t\tif (index > 0 && metrics.prefix[index - 1]! >= clipBottom) break;\n\t}\n\treturn box;\n}\n\nfunction layoutLeaf(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst lines = renderCached(context, component, width);\n\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\tlet lineOffset = 0;\n\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t}\n\treturn {\n\t\tcomponent,\n\t\trect: { x, y, width, height: allocatedHeight },\n\t\tclip: intersect(clip, { x, y, width, height: allocatedHeight }),\n\t\tchildren: [],\n\t\tlines,\n\t\tlineOffset,\n\t\tlayer: 0,\n\t};\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tif (isExactContainer(component)) {\n\t\t\treturn layoutExactContainer(context, component, x, y, safeWidth, height, clip);\n\t\t}\n\t\treturn layoutLeaf(context, component, x, y, safeWidth, height, clip);\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst structuredChild = isExactContainer(node.component);\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tlet childBox: LayoutBox;\n\t\tlet contentHeight: number;\n\t\tif (structuredChild) {\n\t\t\tcontentHeight = measureHeight(context, node.component, contentWidth);\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\tchildBox = layoutComponent(\n\t\t\t\tcontext,\n\t\t\t\tnode.component,\n\t\t\t\tx,\n\t\t\t\ty - node.state.scrollTop,\n\t\t\t\tcontentWidth,\n\t\t\t\tundefined,\n\t\t\t\tclip,\n\t\t\t);\n\t\t} else {\n\t\t\tchildBox = layoutComponent(context, node.component, x, y - previousScrollTop, contentWidth, undefined, clip);\n\t\t\tcontentHeight = childBox.rect.height;\n\t\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\t}\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: structuredChild ? undefined : renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tconst padX = Math.max(0, Math.floor(node.padX ?? 0));\n\tconst padY = Math.max(0, Math.floor(node.padY ?? 0));\n\tconst innerWidth = Math.max(1, safeWidth - padX * 2);\n\tconst innerX = x + padX;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, innerWidth),\n\t\t);\n\t\tconst innerHeight = height === undefined ? undefined : Math.max(0, Math.floor(height) - padY * 2);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, innerHeight, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal + padY * 2;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y + padY;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, innerX, childY, innerWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, innerWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, innerWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = innerX;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\t// Same rule as tui.ts: never send an OSC 8 close to a terminal that has not\n\t// been identified as hyperlink-capable.\n\tconst linkClose = getCapabilities().hyperlinks ? \"\\x1b]8;;\\x07\" : \"\";\n\tconst targetStyle = `\\x1b[0m${linkClose}${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintUnreadIndicator(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst count = box.scrollView?.unreadCount ?? 0;\n\tif (count <= 0 || box.clip.height <= 0) return;\n\tconst row = Math.min(screen.length, box.clip.y + box.clip.height) - 1;\n\tif (row < box.clip.y || row < 0) return;\n\tconst label = `\\x1b[7m +${count} \\x1b[27m`;\n\tconst width = visibleWidth(label);\n\tconst start = Math.max(box.clip.x, box.rect.x + box.rect.width - width);\n\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", label, start, width, totalWidth);\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n\tpaintUnreadIndicator(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}