buninu 0.1.1

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 (435) hide show
  1. package/.bashrc +11 -0
  2. package/ARCHITECTURE.md +452 -0
  3. package/LICENSE +21 -0
  4. package/README.md +121 -0
  5. package/apps/bun/make-bunBin.sh +84 -0
  6. package/apps/jsgotty/LICENSE +23 -0
  7. package/apps/jsgotty/LICENSES/Apache-2.0-zmodem.js.txt +201 -0
  8. package/apps/jsgotty/NOTICE +21 -0
  9. package/apps/jsgotty/README.en.md +290 -0
  10. package/apps/jsgotty/README.md +292 -0
  11. package/apps/jsgotty/client.mjs +700 -0
  12. package/apps/jsgotty/env.sh +2 -0
  13. package/apps/jsgotty/gotty.js +3325 -0
  14. package/apps/jsgotty/node_modules/.package-lock.json +35 -0
  15. package/apps/jsgotty/node_modules/node-addon-api/LICENSE.md +9 -0
  16. package/apps/jsgotty/node_modules/node-addon-api/README.md +319 -0
  17. package/apps/jsgotty/node_modules/node-addon-api/common.gypi +20 -0
  18. package/apps/jsgotty/node_modules/node-addon-api/except.gypi +25 -0
  19. package/apps/jsgotty/node_modules/node-addon-api/index.js +12 -0
  20. package/apps/jsgotty/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
  21. package/apps/jsgotty/node_modules/node-addon-api/napi-inl.h +6607 -0
  22. package/apps/jsgotty/node_modules/node-addon-api/napi.h +3201 -0
  23. package/apps/jsgotty/node_modules/node-addon-api/node_addon_api.gyp +32 -0
  24. package/apps/jsgotty/node_modules/node-addon-api/node_api.gyp +9 -0
  25. package/apps/jsgotty/node_modules/node-addon-api/noexcept.gypi +26 -0
  26. package/apps/jsgotty/node_modules/node-addon-api/nothing.c +0 -0
  27. package/apps/jsgotty/node_modules/node-addon-api/package-support.json +21 -0
  28. package/apps/jsgotty/node_modules/node-addon-api/package.json +480 -0
  29. package/apps/jsgotty/node_modules/node-addon-api/tools/README.md +73 -0
  30. package/apps/jsgotty/node_modules/node-addon-api/tools/check-napi.js +99 -0
  31. package/apps/jsgotty/node_modules/node-addon-api/tools/clang-format.js +71 -0
  32. package/apps/jsgotty/node_modules/node-addon-api/tools/conversion.js +301 -0
  33. package/apps/jsgotty/node_modules/node-addon-api/tools/eslint-format.js +79 -0
  34. package/apps/jsgotty/node_modules/ws/LICENSE +20 -0
  35. package/apps/jsgotty/node_modules/ws/README.md +548 -0
  36. package/apps/jsgotty/node_modules/ws/browser.js +8 -0
  37. package/apps/jsgotty/node_modules/ws/index.js +22 -0
  38. package/apps/jsgotty/node_modules/ws/lib/buffer-util.js +131 -0
  39. package/apps/jsgotty/node_modules/ws/lib/constants.js +19 -0
  40. package/apps/jsgotty/node_modules/ws/lib/event-target.js +292 -0
  41. package/apps/jsgotty/node_modules/ws/lib/extension.js +203 -0
  42. package/apps/jsgotty/node_modules/ws/lib/limiter.js +55 -0
  43. package/apps/jsgotty/node_modules/ws/lib/permessage-deflate.js +528 -0
  44. package/apps/jsgotty/node_modules/ws/lib/receiver.js +760 -0
  45. package/apps/jsgotty/node_modules/ws/lib/sender.js +607 -0
  46. package/apps/jsgotty/node_modules/ws/lib/stream.js +161 -0
  47. package/apps/jsgotty/node_modules/ws/lib/subprotocol.js +62 -0
  48. package/apps/jsgotty/node_modules/ws/lib/validation.js +152 -0
  49. package/apps/jsgotty/node_modules/ws/lib/websocket-server.js +562 -0
  50. package/apps/jsgotty/node_modules/ws/lib/websocket.js +1407 -0
  51. package/apps/jsgotty/node_modules/ws/package.json +70 -0
  52. package/apps/jsgotty/node_modules/ws/wrapper.mjs +21 -0
  53. package/apps/jsgotty/package-lock.json +46 -0
  54. package/apps/jsgotty/package.json +13 -0
  55. package/apps/jsgotty/patches/windowsPtyAgent.js +326 -0
  56. package/apps/jsgotty/patches/windowsTerminal.js +204 -0
  57. package/apps/jsgotty/rz.js +199 -0
  58. package/apps/jsgotty/single-exe/README.md +80 -0
  59. package/apps/jsgotty/single-exe/assetsHelper.js +90 -0
  60. package/apps/jsgotty/single-exe/assetsLoader.mjs +85 -0
  61. package/apps/jsgotty/single-exe/compiled.js +138 -0
  62. package/apps/jsgotty/single-exe/entry.mjs +9 -0
  63. package/apps/jsgotty/single-exe/packAssets.sh +7 -0
  64. package/apps/jsgotty/static/css/index.css +13 -0
  65. package/apps/jsgotty/static/css/kitty.css +61 -0
  66. package/apps/jsgotty/static/css/xterm.css +218 -0
  67. package/apps/jsgotty/static/css/xterm_customize.css +32 -0
  68. package/apps/jsgotty/static/favicon.ico +0 -0
  69. package/apps/jsgotty/static/help.md +125 -0
  70. package/apps/jsgotty/static/icon.svg +66 -0
  71. package/apps/jsgotty/static/icon_192.png +0 -0
  72. package/apps/jsgotty/static/index.html +164 -0
  73. package/apps/jsgotty/static/js/gotty.js +31537 -0
  74. package/apps/jsgotty/static/js/gotty.js.LICENSE.txt +7 -0
  75. package/apps/jsgotty/static/js/gotty.js.map +1 -0
  76. package/apps/jsgotty/static/js/gotty.licenses.txt +650 -0
  77. package/apps/jsgotty/static/js/kitty.js +1045 -0
  78. package/apps/jsgotty/static/js/windows_bridge.js +194 -0
  79. package/apps/jsgotty/static/js/xterm-addon-unicode11.js +2 -0
  80. package/apps/jsgotty/static/js/zmodem.js +1 -0
  81. package/apps/jsgotty/static/manifest.json +15 -0
  82. package/apps/jsgotty/sz.js +273 -0
  83. package/apps/jsgotty/tests/kitty-order.test.js +58 -0
  84. package/apps/jsgotty/viu.mjs +393 -0
  85. package/apps/jsgotty/wgotty +62 -0
  86. package/apps/jsgotty/windows-bridge-node.js +60 -0
  87. package/apps/jsgotty/zmodem-node.js +260 -0
  88. package/apps/jsmdcui/CHANGELOG.md +1048 -0
  89. package/apps/jsmdcui/LICENSE +22 -0
  90. package/apps/jsmdcui/README.md +1269 -0
  91. package/apps/jsmdcui/cdp-maze.js +141 -0
  92. package/apps/jsmdcui/clean.sh +9 -0
  93. package/apps/jsmdcui/demos/basic.jpg +0 -0
  94. package/apps/jsmdcui/demos/chinese.md +32 -0
  95. package/apps/jsmdcui/demos/event.md +170 -0
  96. package/apps/jsmdcui/demos/good.jpg +0 -0
  97. package/apps/jsmdcui/demos/image-processor.md +366 -0
  98. package/apps/jsmdcui/demos/image-processor.zh-TW.md +366 -0
  99. package/apps/jsmdcui/demos/img-change.md +73 -0
  100. package/apps/jsmdcui/demos/imgtool-zh.md +298 -0
  101. package/apps/jsmdcui/demos/imgtool.md +298 -0
  102. package/apps/jsmdcui/demos/maze.md +149 -0
  103. package/apps/jsmdcui/demos/reactive.md +40 -0
  104. package/apps/jsmdcui/demos/reader.md +513 -0
  105. package/apps/jsmdcui/demos/select.md +63 -0
  106. package/apps/jsmdcui/demos/todo-zh.md +190 -0
  107. package/apps/jsmdcui/demos/todo.md +191 -0
  108. package/apps/jsmdcui/edit +9 -0
  109. package/apps/jsmdcui/jsmdcui.sh +5 -0
  110. package/apps/jsmdcui/llm-maze.txt +94 -0
  111. package/apps/jsmdcui/package.json +19 -0
  112. package/apps/jsmdcui/project_structure.txt +35 -0
  113. package/apps/jsmdcui/runmd.mjs +1140 -0
  114. package/apps/jsmdcui/runtime/colorschemes/atom-dark.micro +33 -0
  115. package/apps/jsmdcui/runtime/colorschemes/bubblegum.micro +31 -0
  116. package/apps/jsmdcui/runtime/colorschemes/cmc-16.micro +47 -0
  117. package/apps/jsmdcui/runtime/colorschemes/cmc-tc.micro +43 -0
  118. package/apps/jsmdcui/runtime/colorschemes/darcula.micro +34 -0
  119. package/apps/jsmdcui/runtime/colorschemes/default.micro +1 -0
  120. package/apps/jsmdcui/runtime/colorschemes/dracula-tc.micro +49 -0
  121. package/apps/jsmdcui/runtime/colorschemes/dukedark-tc.micro +38 -0
  122. package/apps/jsmdcui/runtime/colorschemes/dukelight-tc.micro +38 -0
  123. package/apps/jsmdcui/runtime/colorschemes/dukeubuntu-tc.micro +38 -0
  124. package/apps/jsmdcui/runtime/colorschemes/geany.micro +29 -0
  125. package/apps/jsmdcui/runtime/colorschemes/gotham.micro +29 -0
  126. package/apps/jsmdcui/runtime/colorschemes/gruvbox-tc.micro +29 -0
  127. package/apps/jsmdcui/runtime/colorschemes/gruvbox.micro +26 -0
  128. package/apps/jsmdcui/runtime/colorschemes/material-tc.micro +36 -0
  129. package/apps/jsmdcui/runtime/colorschemes/monokai-dark.micro +28 -0
  130. package/apps/jsmdcui/runtime/colorschemes/monokai.micro +34 -0
  131. package/apps/jsmdcui/runtime/colorschemes/one-dark.micro +39 -0
  132. package/apps/jsmdcui/runtime/colorschemes/railscast.micro +37 -0
  133. package/apps/jsmdcui/runtime/colorschemes/simple.micro +33 -0
  134. package/apps/jsmdcui/runtime/colorschemes/solarized-tc.micro +31 -0
  135. package/apps/jsmdcui/runtime/colorschemes/solarized.micro +30 -0
  136. package/apps/jsmdcui/runtime/colorschemes/sunny-day.micro +29 -0
  137. package/apps/jsmdcui/runtime/colorschemes/twilight.micro +40 -0
  138. package/apps/jsmdcui/runtime/colorschemes/zenburn.micro +30 -0
  139. package/apps/jsmdcui/runtime/help/actions.md +161 -0
  140. package/apps/jsmdcui/runtime/help/cdp.md +124 -0
  141. package/apps/jsmdcui/runtime/help/colors.md +421 -0
  142. package/apps/jsmdcui/runtime/help/commands.md +161 -0
  143. package/apps/jsmdcui/runtime/help/copypaste.md +149 -0
  144. package/apps/jsmdcui/runtime/help/defaultkeys.md +148 -0
  145. package/apps/jsmdcui/runtime/help/help.md +1269 -0
  146. package/apps/jsmdcui/runtime/help/keybindings.md +355 -0
  147. package/apps/jsmdcui/runtime/help/linter.md +90 -0
  148. package/apps/jsmdcui/runtime/help/options.md +709 -0
  149. package/apps/jsmdcui/runtime/help/plugins.md +544 -0
  150. package/apps/jsmdcui/runtime/help/tutorial.md +112 -0
  151. package/apps/jsmdcui/runtime/jsplugins/cdp/cdp-server.js +1185 -0
  152. package/apps/jsmdcui/runtime/jsplugins/cdp/cdp.js +201 -0
  153. package/apps/jsmdcui/runtime/jsplugins/chapter/chapter.js +111 -0
  154. package/apps/jsmdcui/runtime/jsplugins/diff/diff.js +46 -0
  155. package/apps/jsmdcui/runtime/jsplugins/example/example.js +117 -0
  156. package/apps/jsmdcui/runtime/jsplugins/linter/linter.js +281 -0
  157. package/apps/jsmdcui/runtime/plugins/autoclose/autoclose.lua +75 -0
  158. package/apps/jsmdcui/runtime/plugins/ftoptions/ftoptions.lua +17 -0
  159. package/apps/jsmdcui/runtime/plugins/literate/README.md +5 -0
  160. package/apps/jsmdcui/runtime/plugins/literate/literate.lua +55 -0
  161. package/apps/jsmdcui/runtime/plugins/status/help/status.md +21 -0
  162. package/apps/jsmdcui/runtime/plugins/status/status.lua +62 -0
  163. package/apps/jsmdcui/runtime/syntax/LICENSE +22 -0
  164. package/apps/jsmdcui/runtime/syntax/PowerShell.yaml +128 -0
  165. package/apps/jsmdcui/runtime/syntax/README.md +63 -0
  166. package/apps/jsmdcui/runtime/syntax/ada.yaml +43 -0
  167. package/apps/jsmdcui/runtime/syntax/apacheconf.yaml +59 -0
  168. package/apps/jsmdcui/runtime/syntax/arduino.yaml +101 -0
  169. package/apps/jsmdcui/runtime/syntax/asciidoc.yaml +51 -0
  170. package/apps/jsmdcui/runtime/syntax/asm.yaml +123 -0
  171. package/apps/jsmdcui/runtime/syntax/ats.yaml +99 -0
  172. package/apps/jsmdcui/runtime/syntax/awk.yaml +44 -0
  173. package/apps/jsmdcui/runtime/syntax/b.yaml +87 -0
  174. package/apps/jsmdcui/runtime/syntax/bat.yaml +57 -0
  175. package/apps/jsmdcui/runtime/syntax/c.yaml +60 -0
  176. package/apps/jsmdcui/runtime/syntax/caddyfile.yaml +23 -0
  177. package/apps/jsmdcui/runtime/syntax/cake.yaml +7 -0
  178. package/apps/jsmdcui/runtime/syntax/clojure.yaml +38 -0
  179. package/apps/jsmdcui/runtime/syntax/cmake.yaml +42 -0
  180. package/apps/jsmdcui/runtime/syntax/coffeescript.yaml +56 -0
  181. package/apps/jsmdcui/runtime/syntax/colortest.yaml +19 -0
  182. package/apps/jsmdcui/runtime/syntax/conky.yaml +17 -0
  183. package/apps/jsmdcui/runtime/syntax/cpp.yaml +91 -0
  184. package/apps/jsmdcui/runtime/syntax/crontab.yaml +36 -0
  185. package/apps/jsmdcui/runtime/syntax/crystal.yaml +72 -0
  186. package/apps/jsmdcui/runtime/syntax/csharp.yaml +52 -0
  187. package/apps/jsmdcui/runtime/syntax/css.yaml +44 -0
  188. package/apps/jsmdcui/runtime/syntax/csx.yaml +8 -0
  189. package/apps/jsmdcui/runtime/syntax/cuda.yaml +68 -0
  190. package/apps/jsmdcui/runtime/syntax/cython.yaml +52 -0
  191. package/apps/jsmdcui/runtime/syntax/d.yaml +121 -0
  192. package/apps/jsmdcui/runtime/syntax/dart.yaml +46 -0
  193. package/apps/jsmdcui/runtime/syntax/default.yaml +10 -0
  194. package/apps/jsmdcui/runtime/syntax/dockerfile.yaml +36 -0
  195. package/apps/jsmdcui/runtime/syntax/dot.yaml +29 -0
  196. package/apps/jsmdcui/runtime/syntax/elixir.yaml +30 -0
  197. package/apps/jsmdcui/runtime/syntax/elm.yaml +38 -0
  198. package/apps/jsmdcui/runtime/syntax/erb.yaml +42 -0
  199. package/apps/jsmdcui/runtime/syntax/erlang.yaml +45 -0
  200. package/apps/jsmdcui/runtime/syntax/fish.yaml +48 -0
  201. package/apps/jsmdcui/runtime/syntax/forth.yaml +34 -0
  202. package/apps/jsmdcui/runtime/syntax/fortran.yaml +64 -0
  203. package/apps/jsmdcui/runtime/syntax/freebsd-kernel.yaml +14 -0
  204. package/apps/jsmdcui/runtime/syntax/fsharp.yaml +48 -0
  205. package/apps/jsmdcui/runtime/syntax/gdscript.yaml +61 -0
  206. package/apps/jsmdcui/runtime/syntax/gemini.yaml +19 -0
  207. package/apps/jsmdcui/runtime/syntax/gentoo-ebuild.yaml +48 -0
  208. package/apps/jsmdcui/runtime/syntax/gentoo-etc-portage.yaml +23 -0
  209. package/apps/jsmdcui/runtime/syntax/git-commit.yaml +35 -0
  210. package/apps/jsmdcui/runtime/syntax/git-config.yaml +14 -0
  211. package/apps/jsmdcui/runtime/syntax/git-rebase-todo.yaml +19 -0
  212. package/apps/jsmdcui/runtime/syntax/gleam.yaml +69 -0
  213. package/apps/jsmdcui/runtime/syntax/glsl.yaml +26 -0
  214. package/apps/jsmdcui/runtime/syntax/gnuplot.yaml +15 -0
  215. package/apps/jsmdcui/runtime/syntax/go.yaml +62 -0
  216. package/apps/jsmdcui/runtime/syntax/godoc.yaml +17 -0
  217. package/apps/jsmdcui/runtime/syntax/golo.yaml +73 -0
  218. package/apps/jsmdcui/runtime/syntax/gomod.yaml +31 -0
  219. package/apps/jsmdcui/runtime/syntax/graphql.yaml +47 -0
  220. package/apps/jsmdcui/runtime/syntax/groff.yaml +30 -0
  221. package/apps/jsmdcui/runtime/syntax/groovy.yaml +111 -0
  222. package/apps/jsmdcui/runtime/syntax/haml.yaml +16 -0
  223. package/apps/jsmdcui/runtime/syntax/hare.yaml +52 -0
  224. package/apps/jsmdcui/runtime/syntax/haskell.yaml +52 -0
  225. package/apps/jsmdcui/runtime/syntax/hc.yaml +52 -0
  226. package/apps/jsmdcui/runtime/syntax/html.yaml +70 -0
  227. package/apps/jsmdcui/runtime/syntax/html4.yaml +25 -0
  228. package/apps/jsmdcui/runtime/syntax/html5.yaml +25 -0
  229. package/apps/jsmdcui/runtime/syntax/ini.yaml +23 -0
  230. package/apps/jsmdcui/runtime/syntax/inputrc.yaml +14 -0
  231. package/apps/jsmdcui/runtime/syntax/java.yaml +37 -0
  232. package/apps/jsmdcui/runtime/syntax/javascript.yaml +124 -0
  233. package/apps/jsmdcui/runtime/syntax/jinja2.yaml +19 -0
  234. package/apps/jsmdcui/runtime/syntax/json.yaml +39 -0
  235. package/apps/jsmdcui/runtime/syntax/jsonnet.yaml +92 -0
  236. package/apps/jsmdcui/runtime/syntax/julia.yaml +57 -0
  237. package/apps/jsmdcui/runtime/syntax/justfile.yaml +40 -0
  238. package/apps/jsmdcui/runtime/syntax/keymap.yaml +27 -0
  239. package/apps/jsmdcui/runtime/syntax/kickstart.yaml +16 -0
  240. package/apps/jsmdcui/runtime/syntax/kotlin.yaml +66 -0
  241. package/apps/jsmdcui/runtime/syntax/kvlang.yaml +67 -0
  242. package/apps/jsmdcui/runtime/syntax/ledger.yaml +14 -0
  243. package/apps/jsmdcui/runtime/syntax/lfe.yaml +17 -0
  244. package/apps/jsmdcui/runtime/syntax/lilypond.yaml +26 -0
  245. package/apps/jsmdcui/runtime/syntax/lisp.yaml +17 -0
  246. package/apps/jsmdcui/runtime/syntax/log.yaml +92 -0
  247. package/apps/jsmdcui/runtime/syntax/lua.yaml +111 -0
  248. package/apps/jsmdcui/runtime/syntax/mail.yaml +25 -0
  249. package/apps/jsmdcui/runtime/syntax/makefile.yaml +38 -0
  250. package/apps/jsmdcui/runtime/syntax/man.yaml +12 -0
  251. package/apps/jsmdcui/runtime/syntax/markdown.yaml +64 -0
  252. package/apps/jsmdcui/runtime/syntax/mc.yaml +23 -0
  253. package/apps/jsmdcui/runtime/syntax/meson.yaml +51 -0
  254. package/apps/jsmdcui/runtime/syntax/micro.yaml +34 -0
  255. package/apps/jsmdcui/runtime/syntax/mpdconf.yaml +13 -0
  256. package/apps/jsmdcui/runtime/syntax/msbuild.yaml +6 -0
  257. package/apps/jsmdcui/runtime/syntax/nanorc.yaml +16 -0
  258. package/apps/jsmdcui/runtime/syntax/nftables.yaml +30 -0
  259. package/apps/jsmdcui/runtime/syntax/nginx.yaml +22 -0
  260. package/apps/jsmdcui/runtime/syntax/nim.yaml +27 -0
  261. package/apps/jsmdcui/runtime/syntax/nix.yaml +32 -0
  262. package/apps/jsmdcui/runtime/syntax/nu.yaml +114 -0
  263. package/apps/jsmdcui/runtime/syntax/objc.yaml +60 -0
  264. package/apps/jsmdcui/runtime/syntax/ocaml.yaml +43 -0
  265. package/apps/jsmdcui/runtime/syntax/octave.yaml +83 -0
  266. package/apps/jsmdcui/runtime/syntax/odin.yaml +64 -0
  267. package/apps/jsmdcui/runtime/syntax/pascal.yaml +45 -0
  268. package/apps/jsmdcui/runtime/syntax/patch.yaml +14 -0
  269. package/apps/jsmdcui/runtime/syntax/peg.yaml +16 -0
  270. package/apps/jsmdcui/runtime/syntax/perl.yaml +58 -0
  271. package/apps/jsmdcui/runtime/syntax/php.yaml +60 -0
  272. package/apps/jsmdcui/runtime/syntax/pkg-config.yaml +12 -0
  273. package/apps/jsmdcui/runtime/syntax/po.yaml +12 -0
  274. package/apps/jsmdcui/runtime/syntax/pony.yaml +37 -0
  275. package/apps/jsmdcui/runtime/syntax/pov.yaml +21 -0
  276. package/apps/jsmdcui/runtime/syntax/privoxy-action.yaml +14 -0
  277. package/apps/jsmdcui/runtime/syntax/privoxy-config.yaml +10 -0
  278. package/apps/jsmdcui/runtime/syntax/privoxy-filter.yaml +12 -0
  279. package/apps/jsmdcui/runtime/syntax/proto.yaml +40 -0
  280. package/apps/jsmdcui/runtime/syntax/prql.yaml +84 -0
  281. package/apps/jsmdcui/runtime/syntax/puppet.yaml +22 -0
  282. package/apps/jsmdcui/runtime/syntax/python2.yaml +60 -0
  283. package/apps/jsmdcui/runtime/syntax/python3.yaml +80 -0
  284. package/apps/jsmdcui/runtime/syntax/r.yaml +32 -0
  285. package/apps/jsmdcui/runtime/syntax/raku.yaml +42 -0
  286. package/apps/jsmdcui/runtime/syntax/reST.yaml +18 -0
  287. package/apps/jsmdcui/runtime/syntax/renpy.yaml +15 -0
  288. package/apps/jsmdcui/runtime/syntax/rpmspec.yaml +43 -0
  289. package/apps/jsmdcui/runtime/syntax/ruby.yaml +73 -0
  290. package/apps/jsmdcui/runtime/syntax/rust.yaml +78 -0
  291. package/apps/jsmdcui/runtime/syntax/sage.yaml +60 -0
  292. package/apps/jsmdcui/runtime/syntax/scad.yaml +53 -0
  293. package/apps/jsmdcui/runtime/syntax/scala.yaml +33 -0
  294. package/apps/jsmdcui/runtime/syntax/sed.yaml +13 -0
  295. package/apps/jsmdcui/runtime/syntax/sh.yaml +69 -0
  296. package/apps/jsmdcui/runtime/syntax/sls.yaml +15 -0
  297. package/apps/jsmdcui/runtime/syntax/smalltalk.yaml +55 -0
  298. package/apps/jsmdcui/runtime/syntax/solidity.yaml +41 -0
  299. package/apps/jsmdcui/runtime/syntax/sql.yaml +35 -0
  300. package/apps/jsmdcui/runtime/syntax/stata.yaml +67 -0
  301. package/apps/jsmdcui/runtime/syntax/svelte.yaml +27 -0
  302. package/apps/jsmdcui/runtime/syntax/swift.yaml +103 -0
  303. package/apps/jsmdcui/runtime/syntax/systemd.yaml +16 -0
  304. package/apps/jsmdcui/runtime/syntax/tcl.yaml +18 -0
  305. package/apps/jsmdcui/runtime/syntax/terraform.yaml +87 -0
  306. package/apps/jsmdcui/runtime/syntax/tex.yaml +32 -0
  307. package/apps/jsmdcui/runtime/syntax/toml.yaml +56 -0
  308. package/apps/jsmdcui/runtime/syntax/twig.yaml +55 -0
  309. package/apps/jsmdcui/runtime/syntax/typescript.yaml +49 -0
  310. package/apps/jsmdcui/runtime/syntax/v.yaml +80 -0
  311. package/apps/jsmdcui/runtime/syntax/vala.yaml +26 -0
  312. package/apps/jsmdcui/runtime/syntax/verilog.yaml +60 -0
  313. package/apps/jsmdcui/runtime/syntax/vhdl.yaml +37 -0
  314. package/apps/jsmdcui/runtime/syntax/vi.yaml +31 -0
  315. package/apps/jsmdcui/runtime/syntax/vue.yaml +64 -0
  316. package/apps/jsmdcui/runtime/syntax/xml.yaml +37 -0
  317. package/apps/jsmdcui/runtime/syntax/xresources.yaml +14 -0
  318. package/apps/jsmdcui/runtime/syntax/yaml.yaml +34 -0
  319. package/apps/jsmdcui/runtime/syntax/yum.yaml +12 -0
  320. package/apps/jsmdcui/runtime/syntax/zig.yaml +52 -0
  321. package/apps/jsmdcui/runtime/syntax/zscript.yaml +72 -0
  322. package/apps/jsmdcui/runtime/syntax/zsh.yaml +52 -0
  323. package/apps/jsmdcui/single-exe/README.md +473 -0
  324. package/apps/jsmdcui/single-exe/assetsHelper.js +191 -0
  325. package/apps/jsmdcui/single-exe/assetsLoader.mjs +85 -0
  326. package/apps/jsmdcui/single-exe/compiled.js +212 -0
  327. package/apps/jsmdcui/single-exe/entry.mjs +10 -0
  328. package/apps/jsmdcui/single-exe/packAssets.sh +7 -0
  329. package/apps/jsmdcui/src/MDCUI_DEFAULT_EDIT +0 -0
  330. package/apps/jsmdcui/src/buffer/backup.js +165 -0
  331. package/apps/jsmdcui/src/buffer/buffer.js +126 -0
  332. package/apps/jsmdcui/src/buffer/fixed3-codec.js +140 -0
  333. package/apps/jsmdcui/src/buffer/loc.js +38 -0
  334. package/apps/jsmdcui/src/buffer/message.js +29 -0
  335. package/apps/jsmdcui/src/build-args.js +40 -0
  336. package/apps/jsmdcui/src/config/clean.js +172 -0
  337. package/apps/jsmdcui/src/config/colorscheme.js +99 -0
  338. package/apps/jsmdcui/src/config/config.js +125 -0
  339. package/apps/jsmdcui/src/config/defaults.js +109 -0
  340. package/apps/jsmdcui/src/cui/fence-events.mjs +144 -0
  341. package/apps/jsmdcui/src/cui/heading-ids.mjs +1568 -0
  342. package/apps/jsmdcui/src/cui/id-collision.mjs +111 -0
  343. package/apps/jsmdcui/src/cui/identity.mjs +26 -0
  344. package/apps/jsmdcui/src/cui/kitty-debug.mjs +25 -0
  345. package/apps/jsmdcui/src/cui/kitty-images.mjs +280 -0
  346. package/apps/jsmdcui/src/cui/kitty-mode.mjs +6 -0
  347. package/apps/jsmdcui/src/cui/rerender-queue.mjs +66 -0
  348. package/apps/jsmdcui/src/cui/rpc.mjs +1525 -0
  349. package/apps/jsmdcui/src/cui/server.mjs +128 -0
  350. package/apps/jsmdcui/src/cui/table-render.mjs +286 -0
  351. package/apps/jsmdcui/src/cui/table-row-edit.mjs +226 -0
  352. package/apps/jsmdcui/src/cui/task-checkbox.mjs +60 -0
  353. package/apps/jsmdcui/src/cui/template-components.mjs +253 -0
  354. package/apps/jsmdcui/src/cui/text-block-resize.mjs +177 -0
  355. package/apps/jsmdcui/src/cui/tui-links.mjs +560 -0
  356. package/apps/jsmdcui/src/display/ansi-style.js +60 -0
  357. package/apps/jsmdcui/src/highlight/highlighter.js +243 -0
  358. package/apps/jsmdcui/src/highlight/parser.js +225 -0
  359. package/apps/jsmdcui/src/index.js +9573 -0
  360. package/apps/jsmdcui/src/lua/engine.js +68 -0
  361. package/apps/jsmdcui/src/platform/archive.js +50 -0
  362. package/apps/jsmdcui/src/platform/clipboard.js +278 -0
  363. package/apps/jsmdcui/src/platform/commands.js +221 -0
  364. package/apps/jsmdcui/src/platform/terminal.js +5 -0
  365. package/apps/jsmdcui/src/plugins/js-bridge.js +3377 -0
  366. package/apps/jsmdcui/src/plugins/manager.js +674 -0
  367. package/apps/jsmdcui/src/runtime/encodings.js +10 -0
  368. package/apps/jsmdcui/src/runtime/registry.js +134 -0
  369. package/apps/jsmdcui/src/screen/cell-buffer.js +81 -0
  370. package/apps/jsmdcui/src/screen/events.js +263 -0
  371. package/apps/jsmdcui/src/screen/screen.js +249 -0
  372. package/apps/jsmdcui/src/screen/vt100.js +571 -0
  373. package/apps/jsmdcui/src/shell/shell.js +70 -0
  374. package/apps/jsmdcui/testapp.md +78 -0
  375. package/apps/jsmdcui/tests/assets-helper.test.js +150 -0
  376. package/apps/jsmdcui/tests/backup.test.js +158 -0
  377. package/apps/jsmdcui/tests/cat-markdown.test.js +139 -0
  378. package/apps/jsmdcui/tests/cmphex3b64.js +95 -0
  379. package/apps/jsmdcui/tests/compiled-runtime.test.js +139 -0
  380. package/apps/jsmdcui/tests/config-settings.test.js +52 -0
  381. package/apps/jsmdcui/tests/demo.test.js +447 -0
  382. package/apps/jsmdcui/tests/docs-sync.test.js +14 -0
  383. package/apps/jsmdcui/tests/fence-events.test.js +1293 -0
  384. package/apps/jsmdcui/tests/heading-ids.test.js +559 -0
  385. package/apps/jsmdcui/tests/heading-list-selector.test.js +2393 -0
  386. package/apps/jsmdcui/tests/id-collision.test.js +514 -0
  387. package/apps/jsmdcui/tests/js-plugin-prompts.test.js +110 -0
  388. package/apps/jsmdcui/tests/key-event.md +10 -0
  389. package/apps/jsmdcui/tests/kitty-demo.md +184 -0
  390. package/apps/jsmdcui/tests/kitty-images.test.js +288 -0
  391. package/apps/jsmdcui/tests/kitty-mode.test.js +14 -0
  392. package/apps/jsmdcui/tests/platform-commands.test.js +18 -0
  393. package/apps/jsmdcui/tests/platform-terminal.test.js +8 -0
  394. package/apps/jsmdcui/tests/pty-demo.js +492 -0
  395. package/apps/jsmdcui/tests/rerender-queue.test.js +130 -0
  396. package/apps/jsmdcui/tests/table-render.test.js +150 -0
  397. package/apps/jsmdcui/tests/table-row-edit.test.js +138 -0
  398. package/apps/jsmdcui/tests/task-checkbox.test.js +33 -0
  399. package/apps/jsmdcui/tests/template-components.test.js +422 -0
  400. package/apps/jsmdcui/tests/text-block-resize.test.js +222 -0
  401. package/apps/jsmdcui/tests/textarea.md +8 -0
  402. package/apps/jsmdcui/tests/tui-links.test.js +298 -0
  403. package/apps/jsmdcui/tests/wui-responsive-images.test.js +60 -0
  404. package/apps/jsmdcui/tests/wui.test.js +108 -0
  405. package/apps/jsmdcui/tests/wv-client.js +96 -0
  406. package/apps/jsmdcui/tui +7 -0
  407. package/apps/jsmdcui/wui +9 -0
  408. package/apps/musl-la/LICENSES/Apache-2.0_LLVM_Exceptions_license.txt +311 -0
  409. package/apps/musl-la/LICENSES/Apache-2.0_license.txt +177 -0
  410. package/apps/musl-la/LICENSES/BSD-3-Clause_license.txt +43 -0
  411. package/apps/musl-la/LICENSES/GPL-3.0.txt +674 -0
  412. package/apps/musl-la/LICENSES/LGPL-3.0.txt +165 -0
  413. package/apps/musl-la/LICENSES/MIT.txt +21 -0
  414. package/apps/musl-la/LICENSES/curl_license.txt +22 -0
  415. package/apps/musl-la/LICENSES/gcc_runtime_exception.txt +73 -0
  416. package/apps/musl-la/LICENSES/zlib_license.txt +22 -0
  417. package/apps/musl-la/LICENSE_musl.txt +193 -0
  418. package/apps/musl-la/NOTICE +56 -0
  419. package/apps/musl-la/ldmusl +0 -0
  420. package/apps/musl-la/libgcc_s.so.1 +0 -0
  421. package/apps/musl-la/libstdc++.so.6 +0 -0
  422. package/apps/musl-la/musl-la.sh +5 -0
  423. package/bin/bun.sh +57 -0
  424. package/bin/glow.sh +5 -0
  425. package/bin/init.js +395 -0
  426. package/bin/jmi.sh +5 -0
  427. package/bin/jsgotty.sh +5 -0
  428. package/bin/libsh-loader.c +135 -0
  429. package/bin/libsh-loader.so +0 -0
  430. package/bin/multicall.sh +90 -0
  431. package/bin/shc.js +5 -0
  432. package/bin/switch_to_android.sh +9 -0
  433. package/bin/switch_to_linux.sh +7 -0
  434. package/icon.png +0 -0
  435. package/package.json +31 -0
@@ -0,0 +1,1045 @@
1
+ (function () {
2
+ const MSG_OUTPUT = "1";
3
+ const MSG_KITTY = "7";
4
+ const DEFAULT_TOUCH_SCROLL_THRESHOLD = 24;
5
+ const overlay = document.getElementById("kitty-overlay");
6
+ const terminal = document.getElementById("terminal");
7
+ const KITTY_TRACE = Boolean(window.gotty_kitty_trace);
8
+ const state = {
9
+ cols: 80,
10
+ rows: 24,
11
+ placements: new Map(),
12
+ scrollBound: false,
13
+ renderBound: false,
14
+ renderDisposables: [],
15
+ relayoutFrame: 0,
16
+ outputTail: "",
17
+ recentCursorHome: false,
18
+ recentClearLineCount: 0,
19
+ touchBound: false,
20
+ touchScroll: null,
21
+ contextMenu: null,
22
+ imageContextBound: false,
23
+ socket: null
24
+ };
25
+
26
+ function browserTerminalState() {
27
+ const xterm = terminal && terminal.__gottyXterm;
28
+ const active = xterm && xterm.buffer && xterm.buffer.active;
29
+ if (!active) {
30
+ return null;
31
+ }
32
+ const { screen, viewport } = xtermElements();
33
+ const terminalRect = terminal.getBoundingClientRect();
34
+ const screenRect = screen && screen.getBoundingClientRect();
35
+ const viewportRect = viewport && viewport.getBoundingClientRect();
36
+ return {
37
+ type: active.type || null,
38
+ baseY: active.baseY,
39
+ viewportY: active.viewportY,
40
+ cursorX: active.cursorX,
41
+ cursorY: active.cursorY,
42
+ cursorCol: active.cursorX + 1,
43
+ cursorRow: active.cursorY + 1,
44
+ absoluteCursorRow: active.baseY + active.cursorY + 1,
45
+ windowInnerWidth: window.innerWidth,
46
+ documentClientWidth: document.documentElement.clientWidth,
47
+ terminalWidth: terminalRect.width,
48
+ screenWidth: screenRect?.width ?? null,
49
+ viewportWidth: viewportRect?.width ?? null,
50
+ viewportClientWidth: viewport?.clientWidth ?? null,
51
+ viewportScrollWidth: viewport?.scrollWidth ?? null,
52
+ };
53
+ }
54
+
55
+ function sendBrowserDebug(stage, details = {}) {
56
+ if (!KITTY_TRACE) {
57
+ return;
58
+ }
59
+ const socket = state.socket;
60
+ if (!socket || socket.readyState !== 1) {
61
+ return;
62
+ }
63
+ try {
64
+ socket.send("K" + JSON.stringify({
65
+ stage,
66
+ terminal: browserTerminalState(),
67
+ ...details,
68
+ }));
69
+ } catch (error) {}
70
+ }
71
+
72
+ function xtermElements() {
73
+ if (!terminal) {
74
+ return {};
75
+ }
76
+ return {
77
+ xterm: terminal.querySelector(".xterm"),
78
+ screen: terminal.querySelector(".xterm-screen"),
79
+ rows: terminal.querySelector(".xterm-rows"),
80
+ viewport: terminal.querySelector(".xterm-viewport"),
81
+ helper: terminal.querySelector(".xterm-helper-textarea")
82
+ };
83
+ }
84
+
85
+ function ensureOverlayBounds() {
86
+ if (!overlay || !terminal) {
87
+ return;
88
+ }
89
+ const { screen } = xtermElements();
90
+ const containerRect = terminal.getBoundingClientRect();
91
+ const rect = screen ? screen.getBoundingClientRect() : containerRect;
92
+ overlay.style.left = `${rect.left - containerRect.left}px`;
93
+ overlay.style.top = `${rect.top - containerRect.top}px`;
94
+ overlay.style.width = `${rect.width}px`;
95
+ overlay.style.height = `${rect.height}px`;
96
+ }
97
+
98
+ function cellMetrics() {
99
+ ensureOverlayBounds();
100
+ const { screen, rows } = xtermElements();
101
+ const rect = (screen || terminal).getBoundingClientRect();
102
+ let cellWidth = rect.width / Math.max(1, state.cols);
103
+ let cellHeight = rect.height / Math.max(1, state.rows);
104
+ const xterm = terminal && terminal.__gottyXterm;
105
+ const rendererCell = xterm && xterm._core && xterm._core._renderService &&
106
+ xterm._core._renderService.dimensions &&
107
+ xterm._core._renderService.dimensions.css &&
108
+ xterm._core._renderService.dimensions.css.cell;
109
+
110
+ if (rendererCell) {
111
+ if (Number.isFinite(rendererCell.width) && rendererCell.width > 0) {
112
+ cellWidth = rendererCell.width;
113
+ }
114
+ if (Number.isFinite(rendererCell.height) && rendererCell.height > 0) {
115
+ cellHeight = rendererCell.height;
116
+ }
117
+ }
118
+
119
+ if (rows) {
120
+ const firstRow = rows.firstElementChild;
121
+ if (firstRow) {
122
+ const rowRect = firstRow.getBoundingClientRect();
123
+ if (rowRect.height > 0) {
124
+ cellHeight = rowRect.height;
125
+ }
126
+ }
127
+ }
128
+
129
+ return {
130
+ width: cellWidth,
131
+ height: cellHeight
132
+ };
133
+ }
134
+
135
+ function anchorOffset() {
136
+ return {
137
+ left: 0,
138
+ top: 0
139
+ };
140
+ }
141
+
142
+ function placementKey(message) {
143
+ const control = message.control || {};
144
+ const imageId = control.i || control.I || (message.image && message.image.id) || "anon";
145
+ return `${imageId}:${control.p || "0"}`;
146
+ }
147
+
148
+ function currentViewportY() {
149
+ const xterm = terminal && terminal.__gottyXterm;
150
+ const active = xterm && xterm.buffer && xterm.buffer.active;
151
+ return active ? active.viewportY : 0;
152
+ }
153
+
154
+ function createPlacementMarker(cursor) {
155
+ const xterm = terminal && terminal.__gottyXterm;
156
+ if (!xterm || typeof xterm.registerMarker !== "function") {
157
+ return null;
158
+ }
159
+ try {
160
+ const active = xterm.buffer && xterm.buffer.active;
161
+ let offset = 0;
162
+ if (active && cursor && Number.isFinite(cursor.bufferRow)) {
163
+ const currentBufferRow = active.baseY + active.cursorY + 1;
164
+ offset = Math.trunc(cursor.bufferRow - currentBufferRow);
165
+ } else if (
166
+ active && cursor && Number.isFinite(cursor.row) &&
167
+ cursor.row >= 1 && cursor.row <= state.rows
168
+ ) {
169
+ // Kitty's cursor row is 1-based within the live terminal screen.
170
+ // registerMarker() takes an offset from xterm's current 0-based row.
171
+ offset = Math.trunc(cursor.row - (active.cursorY + 1));
172
+ }
173
+ const marker = xterm.registerMarker(offset);
174
+ sendBrowserDebug("marker-created", {
175
+ protocolCursor: cursor,
176
+ offset,
177
+ markerLine: marker?.line ?? null,
178
+ });
179
+ return marker;
180
+ } catch (error) {
181
+ return null;
182
+ }
183
+ }
184
+
185
+ function disposePlacementMarker(node) {
186
+ if (!node || !node.__kittyMarker) {
187
+ return;
188
+ }
189
+ try {
190
+ node.__kittyMarker.dispose();
191
+ } catch (error) {
192
+ // The marker may already have been disposed by xterm buffer trimming.
193
+ }
194
+ node.__kittyMarker = null;
195
+ }
196
+
197
+ function removePlacementNode(node) {
198
+ if (!node) {
199
+ return;
200
+ }
201
+ disposePlacementMarker(node);
202
+ node.__kittyGeneration = (node.__kittyGeneration || 0) + 1;
203
+ revokeNodeUrl(node);
204
+ node.remove();
205
+ }
206
+
207
+ function decodeRawImage(image) {
208
+ const binary = atob(image.data);
209
+ const bytes = new Uint8ClampedArray(binary.length);
210
+ for (let i = 0; i < binary.length; i += 1) {
211
+ bytes[i] = binary.charCodeAt(i);
212
+ }
213
+
214
+ let rgba;
215
+ if (image.format === 32) {
216
+ rgba = bytes;
217
+ } else if (image.format === 24) {
218
+ rgba = new Uint8ClampedArray((bytes.length / 3) * 4);
219
+ for (let src = 0, dst = 0; src < bytes.length; src += 3, dst += 4) {
220
+ rgba[dst] = bytes[src];
221
+ rgba[dst + 1] = bytes[src + 1];
222
+ rgba[dst + 2] = bytes[src + 2];
223
+ rgba[dst + 3] = 255;
224
+ }
225
+ } else {
226
+ return null;
227
+ }
228
+
229
+ const canvas = document.createElement("canvas");
230
+ canvas.width = image.width;
231
+ canvas.height = image.height;
232
+ const context = canvas.getContext("2d");
233
+ context.putImageData(new ImageData(rgba, image.width, image.height), 0, 0);
234
+ return canvas;
235
+ }
236
+
237
+ function binaryFromBase64(base64) {
238
+ const binary = atob(base64);
239
+ const bytes = new Uint8Array(binary.length);
240
+ for (let i = 0; i < binary.length; i += 1) {
241
+ bytes[i] = binary.charCodeAt(i);
242
+ }
243
+ return bytes;
244
+ }
245
+
246
+ function stringFromBase64(base64) {
247
+ return atob(base64);
248
+ }
249
+
250
+ function inferBlobMimeType(image, control) {
251
+ const explicit = control && (control.U || control.mime);
252
+ if (explicit) {
253
+ return explicit;
254
+ }
255
+ if (!image) {
256
+ return "application/octet-stream";
257
+ }
258
+ if (image.format === 100) {
259
+ return "image/png";
260
+ }
261
+ return "application/octet-stream";
262
+ }
263
+
264
+ function canvasToBlob(canvas) {
265
+ return new Promise((resolve, reject) => {
266
+ canvas.toBlob((blob) => {
267
+ if (blob) {
268
+ resolve(blob);
269
+ return;
270
+ }
271
+ reject(new Error("Failed to create blob from canvas"));
272
+ }, "image/png");
273
+ });
274
+ }
275
+
276
+ function sourceRectangle(width, height, control = {}) {
277
+ const sourceWidth = Math.max(1, Math.trunc(Number(width) || 1));
278
+ const sourceHeight = Math.max(1, Math.trunc(Number(height) || 1));
279
+ const requestedX = Math.max(0, Math.trunc(Number.parseInt(control.x || "0", 10) || 0));
280
+ const requestedY = Math.max(0, Math.trunc(Number.parseInt(control.y || "0", 10) || 0));
281
+ const requestedWidth = Math.max(0, Math.trunc(Number.parseInt(control.w || "0", 10) || 0));
282
+ const requestedHeight = Math.max(0, Math.trunc(Number.parseInt(control.h || "0", 10) || 0));
283
+ const right = requestedWidth > 0 ? requestedX + requestedWidth : sourceWidth;
284
+ const bottom = requestedHeight > 0 ? requestedY + requestedHeight : sourceHeight;
285
+ const x = Math.min(sourceWidth, requestedX);
286
+ const y = Math.min(sourceHeight, requestedY);
287
+ const clippedRight = Math.min(sourceWidth, Math.max(x, right));
288
+ const clippedBottom = Math.min(sourceHeight, Math.max(y, bottom));
289
+ const cropWidth = clippedRight - x;
290
+ const cropHeight = clippedBottom - y;
291
+ if (cropWidth < 1 || cropHeight < 1) {
292
+ return null;
293
+ }
294
+ return {
295
+ x,
296
+ y,
297
+ width: cropWidth,
298
+ height: cropHeight,
299
+ sourceWidth,
300
+ sourceHeight,
301
+ cropped: x !== 0 || y !== 0 || cropWidth !== sourceWidth || cropHeight !== sourceHeight,
302
+ };
303
+ }
304
+
305
+ async function blobDimensions(blob) {
306
+ if (typeof createImageBitmap === "function") {
307
+ const bitmap = await createImageBitmap(blob);
308
+ const dimensions = { width: bitmap.width, height: bitmap.height };
309
+ bitmap.close();
310
+ return dimensions;
311
+ }
312
+
313
+ return new Promise((resolve, reject) => {
314
+ const probe = new Image();
315
+ const url = URL.createObjectURL(blob);
316
+ probe.onload = () => {
317
+ const dimensions = {
318
+ width: probe.naturalWidth,
319
+ height: probe.naturalHeight
320
+ };
321
+ URL.revokeObjectURL(url);
322
+ resolve(dimensions);
323
+ };
324
+ probe.onerror = (error) => {
325
+ URL.revokeObjectURL(url);
326
+ reject(error);
327
+ };
328
+ probe.src = url;
329
+ });
330
+ }
331
+
332
+ async function resolveImageAsset(image, control = {}) {
333
+ if (!image) {
334
+ return null;
335
+ }
336
+ let blob;
337
+ let dimensions;
338
+ if (image.format === 100) {
339
+ blob = new Blob([binaryFromBase64(image.data)], {
340
+ type: inferBlobMimeType(image, image.control || {})
341
+ });
342
+ dimensions = await blobDimensions(blob);
343
+ } else {
344
+ const canvas = decodeRawImage(image);
345
+ if (!canvas) {
346
+ return null;
347
+ }
348
+ blob = await canvasToBlob(canvas);
349
+ dimensions = { width: canvas.width, height: canvas.height };
350
+ }
351
+ const sourceRect = sourceRectangle(dimensions.width, dimensions.height, control);
352
+ if (!sourceRect) {
353
+ return null;
354
+ }
355
+ return {
356
+ blob,
357
+ width: sourceRect.width,
358
+ height: sourceRect.height,
359
+ sourceRect,
360
+ };
361
+ }
362
+
363
+ function revokeNodeUrl(node) {
364
+ if (node && node.__kittyObjectUrl) {
365
+ URL.revokeObjectURL(node.__kittyObjectUrl);
366
+ node.__kittyObjectUrl = "";
367
+ }
368
+ }
369
+
370
+ function layoutNode(node) {
371
+ if (!node || !node.__kittyPlacement) {
372
+ return;
373
+ }
374
+ const { control, cursor, intrinsicWidth, intrinsicHeight, sourceRect } = node.__kittyPlacement;
375
+ const metrics = cellMetrics();
376
+ const anchor = anchorOffset();
377
+ const controlCols = Math.max(0, Number.parseInt(control.c || "0", 10) || 0);
378
+ const controlRows = Math.max(0, Number.parseInt(control.r || "0", 10) || 0);
379
+ let requestedCols;
380
+ let requestedRows;
381
+ if (controlCols > 0 && controlRows > 0) {
382
+ requestedCols = controlCols;
383
+ requestedRows = controlRows;
384
+ } else if (controlCols > 0) {
385
+ requestedCols = controlCols;
386
+ requestedRows = Math.max(1, Math.round(
387
+ controlCols * metrics.width * intrinsicHeight / intrinsicWidth / metrics.height,
388
+ ));
389
+ } else if (controlRows > 0) {
390
+ requestedRows = controlRows;
391
+ requestedCols = Math.max(1, Math.round(
392
+ controlRows * metrics.height * intrinsicWidth / intrinsicHeight / metrics.width,
393
+ ));
394
+ } else {
395
+ requestedCols = Math.max(1, Math.round(intrinsicWidth / Math.max(1, metrics.width)));
396
+ requestedRows = Math.max(1, Math.round(intrinsicHeight / Math.max(1, metrics.height)));
397
+ }
398
+ const xterm = terminal && terminal.__gottyXterm;
399
+ const viewerCols = Math.max(1, Math.trunc(Number(xterm?.cols) || state.cols));
400
+ const viewerRows = Math.max(1, Math.trunc(Number(xterm?.rows) || state.rows));
401
+ const cursorCol = Math.max(1, Math.trunc(Number(cursor?.col) || 1));
402
+ // A fixed-width PTY may be wider than the browser's xterm instance. Match
403
+ // viu's final-column safety margin using the viewer's real column count,
404
+ // then scale both axes so the image is visible rather than merely clipped.
405
+ const availableViewerCols = Math.max(1, viewerCols - cursorCol);
406
+ const scale = Math.min(1, availableViewerCols / requestedCols);
407
+ const cols = Math.max(1, Math.min(requestedCols, availableViewerCols));
408
+ const rows = Math.max(1, Math.round(requestedRows * scale));
409
+ const marker = node.__kittyMarker;
410
+ const activeBuffer = xterm?.buffer?.active;
411
+ const useProtocolRow = activeBuffer?.type === "alternate" && cursor && Number.isFinite(cursor.row);
412
+ const row = useProtocolRow
413
+ ? cursor.row
414
+ : marker && !marker.isDisposed && Number.isFinite(marker.line)
415
+ ? marker.line - currentViewportY() + 1
416
+ : cursor && Number.isFinite(cursor.bufferRow)
417
+ ? cursor.bufferRow - currentViewportY()
418
+ : (cursor && cursor.row) || 1;
419
+ // Fixed-size PTYs can have more rows than the browser-side xterm. Leave
420
+ // the viewer's final row for the TUI status line in that mismatch mode.
421
+ const viewerBottomRow = Math.max(1, viewerRows - (viewerRows < state.rows ? 1 : 0));
422
+ const visibleRows = Math.max(0, Math.min(rows, viewerBottomRow - row + 1));
423
+ node.style.display = visibleRows > 0 ? "block" : "none";
424
+ node.style.left = `${anchor.left + (Math.max(1, cursor.col) - 1) * metrics.width}px`;
425
+ node.style.top = `${anchor.top + (row - 1) * metrics.height}px`;
426
+ node.style.width = `${cols * metrics.width}px`;
427
+ node.style.height = `${visibleRows * metrics.height}px`;
428
+ node.style.zIndex = String(Number.parseInt(control.z || "0", 10) || 0);
429
+ const imageElement = node.__kittyImageElement;
430
+ if (imageElement && sourceRect) {
431
+ const targetWidth = cols * metrics.width;
432
+ const targetHeight = rows * metrics.height;
433
+ const sourceScaleX = targetWidth / sourceRect.width;
434
+ const sourceScaleY = targetHeight / sourceRect.height;
435
+ imageElement.style.left = `${-sourceRect.x * sourceScaleX}px`;
436
+ imageElement.style.top = `${-sourceRect.y * sourceScaleY}px`;
437
+ imageElement.style.width = `${sourceRect.sourceWidth * sourceScaleX}px`;
438
+ imageElement.style.height = `${sourceRect.sourceHeight * sourceScaleY}px`;
439
+ }
440
+ const { screen, viewport } = xtermElements();
441
+ const overlayRect = overlay.getBoundingClientRect();
442
+ const terminalRect = terminal.getBoundingClientRect();
443
+ const screenRect = screen && screen.getBoundingClientRect();
444
+ const viewportRect = viewport && viewport.getBoundingClientRect();
445
+ sendBrowserDebug("layout", {
446
+ imageId: control.i || control.I || null,
447
+ placementId: control.p || null,
448
+ requestedCols,
449
+ requestedRows,
450
+ viewerCols,
451
+ viewerRows,
452
+ viewerBottomRow,
453
+ terminalVisibleRows: visibleRows,
454
+ availableViewerCols,
455
+ viewerScale: scale,
456
+ positionSource: useProtocolRow ? "protocol" : "marker",
457
+ sourceRect: sourceRect || null,
458
+ protocolCursor: cursor,
459
+ markerLine: marker?.line ?? null,
460
+ markerDisposed: marker?.isDisposed ?? null,
461
+ currentViewportY: currentViewportY(),
462
+ selectedRow: row,
463
+ cssLeft: node.style.left,
464
+ cssTop: node.style.top,
465
+ cssWidth: node.style.width,
466
+ cssHeight: node.style.height,
467
+ cellWidth: metrics.width,
468
+ cellHeight: metrics.height,
469
+ geometry: {
470
+ windowInnerWidth: window.innerWidth,
471
+ documentClientWidth: document.documentElement.clientWidth,
472
+ terminalWidth: terminalRect.width,
473
+ screenWidth: screenRect?.width ?? null,
474
+ viewportWidth: viewportRect?.width ?? null,
475
+ viewportClientWidth: viewport?.clientWidth ?? null,
476
+ viewportScrollWidth: viewport?.scrollWidth ?? null,
477
+ overlayWidth: overlayRect.width,
478
+ overlayClientWidth: overlay.clientWidth,
479
+ overlayScrollWidth: overlay.scrollWidth,
480
+ overlayComputedWidth: getComputedStyle(overlay).width,
481
+ overlayOverflow: getComputedStyle(overlay).overflow,
482
+ },
483
+ });
484
+ }
485
+
486
+ function relayoutAll() {
487
+ ensureOverlayBounds();
488
+ for (const node of state.placements.values()) {
489
+ layoutNode(node);
490
+ }
491
+ }
492
+
493
+ function scheduleRelayout() {
494
+ if (state.relayoutFrame) {
495
+ return;
496
+ }
497
+ state.relayoutFrame = requestAnimationFrame(() => {
498
+ state.relayoutFrame = 0;
499
+ relayoutAll();
500
+ });
501
+ }
502
+
503
+ function bindViewportScroll() {
504
+ if (state.scrollBound) {
505
+ return;
506
+ }
507
+ const { viewport } = xtermElements();
508
+ if (!viewport) {
509
+ return;
510
+ }
511
+ viewport.addEventListener("scroll", () => {
512
+ sendBrowserDebug("viewport-scroll", { currentViewportY: currentViewportY() });
513
+ relayoutAll();
514
+ }, { passive: true });
515
+ state.scrollBound = true;
516
+ }
517
+
518
+ function bindTerminalRender() {
519
+ if (state.renderBound || !terminal) {
520
+ return;
521
+ }
522
+ const xterm = terminal.__gottyXterm;
523
+ if (!xterm) {
524
+ return;
525
+ }
526
+ if (typeof xterm.onRender === "function") {
527
+ state.renderDisposables.push(xterm.onRender(() => {
528
+ scheduleRelayout();
529
+ }));
530
+ }
531
+ if (typeof xterm.onWriteParsed === "function") {
532
+ state.renderDisposables.push(xterm.onWriteParsed(() => {
533
+ scheduleRelayout();
534
+ }));
535
+ }
536
+ state.renderBound = state.renderDisposables.length > 0;
537
+ }
538
+
539
+ function dispatchSyntheticWheel(target, touch, deltaX, deltaY) {
540
+ if (!target) {
541
+ return;
542
+ }
543
+ const event = new WheelEvent("wheel", {
544
+ bubbles: true,
545
+ cancelable: true,
546
+ deltaMode: WheelEvent.DOM_DELTA_LINE,
547
+ deltaX,
548
+ deltaY,
549
+ clientX: touch.clientX,
550
+ clientY: touch.clientY
551
+ });
552
+ target.dispatchEvent(event);
553
+ }
554
+
555
+ function touchScrollThreshold() {
556
+ const configured = Number(window.touchScrollThreshold);
557
+ if (Number.isFinite(configured) && configured > 0) {
558
+ return configured;
559
+ }
560
+ return DEFAULT_TOUCH_SCROLL_THRESHOLD;
561
+ }
562
+
563
+ function bindTouchScrolling() {
564
+ if (state.touchBound || !terminal) {
565
+ return;
566
+ }
567
+
568
+ const bindTarget = terminal;
569
+ const activeTouchId = () => state.touchScroll && state.touchScroll.identifier;
570
+ const wheelTarget = () => {
571
+ const { screen, viewport, xterm } = xtermElements();
572
+ return screen || viewport || xterm || terminal;
573
+ };
574
+
575
+ bindTarget.addEventListener("touchstart", (event) => {
576
+ if (event.touches.length !== 1) {
577
+ state.touchScroll = null;
578
+ return;
579
+ }
580
+ const touch = event.touches[0];
581
+ state.touchScroll = {
582
+ identifier: touch.identifier,
583
+ lastX: touch.clientX,
584
+ lastY: touch.clientY,
585
+ residualX: 0,
586
+ residualY: 0
587
+ };
588
+ }, { passive: true });
589
+
590
+ bindTarget.addEventListener("touchmove", (event) => {
591
+ if (!state.touchScroll) {
592
+ return;
593
+ }
594
+ const touch = Array.from(event.touches).find((entry) => entry.identifier === activeTouchId());
595
+ if (!touch) {
596
+ return;
597
+ }
598
+
599
+ const deltaX = state.touchScroll.lastX - touch.clientX;
600
+ const deltaY = state.touchScroll.lastY - touch.clientY;
601
+ state.touchScroll.lastX = touch.clientX;
602
+ state.touchScroll.lastY = touch.clientY;
603
+ state.touchScroll.residualX += deltaX;
604
+ state.touchScroll.residualY += deltaY;
605
+
606
+ const threshold = touchScrollThreshold();
607
+ const stepX = state.touchScroll.residualX >= 0 ? 1 : -1;
608
+ const stepY = state.touchScroll.residualY >= 0 ? 1 : -1;
609
+ const ticksX = Math.trunc(Math.abs(state.touchScroll.residualX) / threshold);
610
+ const ticksY = Math.trunc(Math.abs(state.touchScroll.residualY) / threshold);
611
+
612
+ if (ticksX === 0 && ticksY === 0) {
613
+ return;
614
+ }
615
+
616
+ event.preventDefault();
617
+ const target = wheelTarget();
618
+ const count = Math.max(ticksX, ticksY);
619
+ for (let i = 0; i < count; i += 1) {
620
+ dispatchSyntheticWheel(
621
+ target,
622
+ touch,
623
+ i < ticksX ? stepX : 0,
624
+ i < ticksY ? stepY : 0
625
+ );
626
+ }
627
+ state.touchScroll.residualX -= ticksX * threshold * stepX;
628
+ state.touchScroll.residualY -= ticksY * threshold * stepY;
629
+ }, { passive: false });
630
+
631
+ const clearTouchScroll = () => {
632
+ state.touchScroll = null;
633
+ };
634
+ bindTarget.addEventListener("touchend", clearTouchScroll, { passive: true });
635
+ bindTarget.addEventListener("touchcancel", clearTouchScroll, { passive: true });
636
+ state.touchBound = true;
637
+ }
638
+
639
+ function ensureContextMenu() {
640
+ if (state.contextMenu) {
641
+ return state.contextMenu;
642
+ }
643
+
644
+ const menu = document.createElement("div");
645
+ menu.className = "kitty-context-menu";
646
+ menu.hidden = true;
647
+
648
+ const removeButton = document.createElement("button");
649
+ removeButton.type = "button";
650
+ removeButton.className = "kitty-context-menu__item";
651
+ removeButton.textContent = "Remove image";
652
+ menu.appendChild(removeButton);
653
+
654
+ state.contextMenu = {
655
+ root: menu,
656
+ removeButton,
657
+ targetKey: null
658
+ };
659
+
660
+ document.body.appendChild(menu);
661
+
662
+ let remClick = (e) => {
663
+
664
+ e.preventDefault();
665
+ e.stopPropagation();
666
+
667
+ if (!state.contextMenu || !state.contextMenu.targetKey) {
668
+ return;
669
+ }
670
+ const node = state.placements.get(state.contextMenu.targetKey);
671
+ if (node) {
672
+ removePlacementNode(node);
673
+ state.placements.delete(state.contextMenu.targetKey);
674
+ }
675
+ hideContextMenu();
676
+ };
677
+
678
+ removeButton.addEventListener("click",remClick)
679
+ removeButton.addEventListener("contextmenu",remClick)
680
+
681
+ document.addEventListener("pointerdown", (event) => {
682
+ if (!state.contextMenu || state.contextMenu.root.hidden) {
683
+ return;
684
+ }
685
+ if (state.contextMenu.root.contains(event.target)) {
686
+ return;
687
+ }
688
+ hideContextMenu();
689
+ }, { passive: true });
690
+
691
+ //window.addEventListener("blur", hideContextMenu);
692
+ //window.addEventListener("resize", hideContextMenu);
693
+
694
+ return state.contextMenu;
695
+ }
696
+
697
+ function showContextMenu(x, y, key) {
698
+ const menu = ensureContextMenu();
699
+ menu.targetKey = key;
700
+ menu.root.hidden = false;
701
+
702
+ const margin = 10;
703
+ const rect = menu.root.getBoundingClientRect();
704
+ let left = x - rect.width - margin;
705
+ if (left < margin) {
706
+ left = Math.min(window.innerWidth - rect.width - margin, x + margin);
707
+ }
708
+ if (left < margin) {
709
+ left = margin;
710
+ }
711
+
712
+ let top = y - rect.height - margin;
713
+ if (top < margin) {
714
+ top = Math.min(window.innerHeight - rect.height - margin, y + margin);
715
+ }
716
+ if (top < margin) {
717
+ top = margin;
718
+ }
719
+
720
+ menu.root.style.left = `${left}px`;
721
+ menu.root.style.top = `${top}px`;
722
+ }
723
+
724
+ function hideContextMenu() {
725
+ if (!state.contextMenu) {
726
+ return;
727
+ }
728
+ state.contextMenu.targetKey = null;
729
+ state.contextMenu.root.hidden = true;
730
+ }
731
+
732
+ function placementAtPoint(clientX, clientY) {
733
+ let found = null;
734
+ let foundZ = -Infinity;
735
+ let foundIndex = -1;
736
+ let index = 0;
737
+ for (const [key, node] of state.placements.entries()) {
738
+ const rect = node.getBoundingClientRect();
739
+ if (
740
+ clientX >= rect.left &&
741
+ clientX <= rect.right &&
742
+ clientY >= rect.top &&
743
+ clientY <= rect.bottom
744
+ ) {
745
+ const z = Number.parseInt(node.style.zIndex || "0", 10) || 0;
746
+ if (z > foundZ || (z === foundZ && index > foundIndex)) {
747
+ found = key;
748
+ foundZ = z;
749
+ foundIndex = index;
750
+ }
751
+ }
752
+ index += 1;
753
+ }
754
+ return found;
755
+ }
756
+
757
+ function bindImageContextMenu() {
758
+ if (state.imageContextBound || !terminal) {
759
+ return;
760
+ }
761
+
762
+ const handleRightClick = (event) => {
763
+ if (state.contextMenu && state.contextMenu.root.contains(event.target)) {
764
+ return;
765
+ }
766
+ const key = placementAtPoint(event.clientX, event.clientY);
767
+ if (!key) {
768
+ return;
769
+ }
770
+ event.preventDefault();
771
+ event.stopPropagation();
772
+ showContextMenu(event.clientX, event.clientY, key);
773
+ };
774
+
775
+ terminal.addEventListener("mousedown", (event) => {
776
+ if (event.button === 2) {
777
+ handleRightClick(event);
778
+ }
779
+ }, true);
780
+
781
+ terminal.addEventListener("contextmenu", handleRightClick, true);
782
+ state.imageContextBound = true;
783
+ }
784
+
785
+ async function placeImage(message) {
786
+ if (!overlay || !terminal || !message.image) {
787
+ return;
788
+ }
789
+
790
+ const key = placementKey(message);
791
+ const control = message.control || {};
792
+ const cursor = message.bufferCursor || message.cursor || { row: 1, col: 1 };
793
+ sendBrowserDebug("placement-start", {
794
+ key,
795
+ control,
796
+ protocolCursor: message.cursor || null,
797
+ selectedCursor: cursor,
798
+ });
799
+ if (message.image) {
800
+ message.image.control = control;
801
+ }
802
+ let node = state.placements.get(key);
803
+ if (!node) {
804
+ node = document.createElement("div");
805
+ node.className = "kitty-image";
806
+ const imageElement = document.createElement("img");
807
+ imageElement.className = "kitty-image__content";
808
+ imageElement.alt = "";
809
+ node.__kittyImageElement = imageElement;
810
+ node.appendChild(imageElement);
811
+ node.__kittyObjectUrl = "";
812
+ node.__kittyMarker = null;
813
+ node.addEventListener("contextmenu", (event) => {
814
+ showContextMenu(event.clientX, event.clientY, key);
815
+ });
816
+ state.placements.set(key, node);
817
+ overlay.appendChild(node);
818
+ }
819
+
820
+ disposePlacementMarker(node);
821
+ node.__kittyMarker = createPlacementMarker(cursor);
822
+ const generation = (node.__kittyGeneration || 0) + 1;
823
+ node.__kittyGeneration = generation;
824
+
825
+ const asset = await resolveImageAsset(message.image, control);
826
+ if (!asset || node.__kittyGeneration !== generation) {
827
+ return;
828
+ }
829
+ const objectUrl = URL.createObjectURL(asset.blob);
830
+ revokeNodeUrl(node);
831
+ node.__kittyObjectUrl = objectUrl;
832
+ node.__kittyPlacement = {
833
+ control,
834
+ cursor,
835
+ intrinsicWidth: asset.width,
836
+ intrinsicHeight: asset.height,
837
+ sourceRect: asset.sourceRect,
838
+ };
839
+ node.__kittyImageElement.src = objectUrl;
840
+ bindViewportScroll();
841
+ bindTerminalRender();
842
+ bindTouchScrolling();
843
+ bindImageContextMenu();
844
+ layoutNode(node);
845
+ }
846
+
847
+ function deleteImages(message) {
848
+ const info = message.delete || {};
849
+ sendBrowserDebug("delete", {
850
+ delete: info,
851
+ placementKeys: Array.from(state.placements.keys()),
852
+ });
853
+ if (info.scope === "a" || info.scope === "A") {
854
+ for (const node of state.placements.values()) {
855
+ removePlacementNode(node);
856
+ }
857
+ state.placements.clear();
858
+ return;
859
+ }
860
+
861
+ if (info.imageId) {
862
+ for (const [key, node] of state.placements.entries()) {
863
+ if (key.startsWith(`${info.imageId}:`)) {
864
+ removePlacementNode(node);
865
+ state.placements.delete(key);
866
+ }
867
+ }
868
+ }
869
+ }
870
+
871
+ function clearAllImages() {
872
+ deleteImages({ delete: { scope: "a" } });
873
+ }
874
+
875
+ function inspectTerminalOutput(data) {
876
+ if (typeof data !== "string" || data[0] !== MSG_OUTPUT || data.length <= 1) {
877
+ return;
878
+ }
879
+
880
+ let text;
881
+ try {
882
+ text = state.outputTail + stringFromBase64(data.slice(1));
883
+ } catch (error) {
884
+ state.outputTail = "";
885
+ return;
886
+ }
887
+
888
+ if (text.includes("\u001bc") || text.includes("\f")) {
889
+ clearAllImages();
890
+ }
891
+
892
+ const csiPattern = /\u001b\[([0-9;?]*)([A-Za-z])/g;
893
+ let match;
894
+ while ((match = csiPattern.exec(text)) !== null) {
895
+ const params = match[1];
896
+ const finalByte = match[2];
897
+ if (finalByte === "H" || finalByte === "f") {
898
+ const normalized = params === "" ? ["1"] : params.split(";");
899
+ const row = Number.parseInt(normalized[0] || "1", 10) || 1;
900
+ const col = Number.parseInt(normalized[1] || "1", 10) || 1;
901
+ state.recentCursorHome = row === 1 && col === 1;
902
+ if (state.recentCursorHome) {
903
+ state.recentClearLineCount = 0;
904
+ }
905
+ }
906
+ if (finalByte === "J") {
907
+ const mode = params === "" ? 0 : Number.parseInt(params.split(";").pop() || "0", 10) || 0;
908
+ if (mode === 2 || mode === 3 || (mode === 0 && state.recentCursorHome)) {
909
+ clearAllImages();
910
+ }
911
+ state.recentCursorHome = false;
912
+ state.recentClearLineCount = 0;
913
+ }
914
+ if (finalByte === "K") {
915
+ const mode = params === "" ? 0 : Number.parseInt(params.split(";").pop() || "0", 10) || 0;
916
+ if (state.recentCursorHome && mode === 0) {
917
+ state.recentClearLineCount += 1;
918
+ if (state.recentClearLineCount >= Math.max(4, Math.floor(state.rows / 3))) {
919
+ clearAllImages();
920
+ state.recentCursorHome = false;
921
+ state.recentClearLineCount = 0;
922
+ }
923
+ } else {
924
+ state.recentClearLineCount = 0;
925
+ }
926
+ }
927
+ if (finalByte === "h" || finalByte === "l") {
928
+ if (params === "?1049" || params === "?1047" || params === "?47") {
929
+ clearAllImages();
930
+ }
931
+ state.recentCursorHome = false;
932
+ state.recentClearLineCount = 0;
933
+ }
934
+ if (finalByte !== "H" && finalByte !== "f" && finalByte !== "K") {
935
+ state.recentCursorHome = false;
936
+ state.recentClearLineCount = 0;
937
+ }
938
+ }
939
+
940
+ state.outputTail = text.slice(-64);
941
+ }
942
+
943
+ function handleKittyMessage(payload) {
944
+ const message = JSON.parse(payload);
945
+ sendBrowserDebug("kitty-message", {
946
+ kind: message.kind,
947
+ control: message.control || null,
948
+ protocolCursor: message.cursor || message.delete?.cursor || null,
949
+ delete: message.delete || null,
950
+ });
951
+ if (message.kind === "placement") {
952
+ // The server records this cursor exactly where the Kitty APC occurred.
953
+ // Do not replace it with xterm's later cursor, which may already have
954
+ // moved because of redraw or scrolling output queued after the APC.
955
+ placeImage(message);
956
+ return true;
957
+ }
958
+ if (message.kind === "delete") {
959
+ deleteImages(message);
960
+ return true;
961
+ }
962
+ return false;
963
+ }
964
+
965
+ const nativeSend = WebSocket.prototype.send;
966
+ const nativeOnOpen = WebSocket.prototype.addEventListener;
967
+ WebSocket.prototype.addEventListener = function (type, listener, options) {
968
+ if (type !== "message") {
969
+ return nativeOnOpen.call(this, type, listener, options);
970
+ }
971
+ const wrapped = function (event) {
972
+ state.socket = this;
973
+ inspectTerminalOutput(event.data);
974
+ if (typeof event.data === "string" && event.data[0] === MSG_KITTY) {
975
+ if (handleKittyMessage(event.data.slice(1))) {
976
+ return;
977
+ }
978
+ }
979
+ const result = listener.call(this, event);
980
+ scheduleRelayout();
981
+ return result;
982
+ };
983
+ listener.__kittyWrapped = wrapped;
984
+ return nativeOnOpen.call(this, type, wrapped, options);
985
+ };
986
+
987
+ const nativeRemoveEventListener = WebSocket.prototype.removeEventListener;
988
+ WebSocket.prototype.removeEventListener = function (type, listener, options) {
989
+ if (type === "message" && listener && listener.__kittyWrapped) {
990
+ return nativeRemoveEventListener.call(this, type, listener.__kittyWrapped, options);
991
+ }
992
+ return nativeRemoveEventListener.call(this, type, listener, options);
993
+ };
994
+
995
+ const descriptor = Object.getOwnPropertyDescriptor(WebSocket.prototype, "onmessage");
996
+ Object.defineProperty(WebSocket.prototype, "onmessage", {
997
+ configurable: true,
998
+ enumerable: descriptor ? descriptor.enumerable : true,
999
+ get() {
1000
+ return this.__kittyOnMessage || null;
1001
+ },
1002
+ set(handler) {
1003
+ this.__kittyOnMessage = handler;
1004
+ if (!descriptor || !descriptor.set) {
1005
+ return;
1006
+ }
1007
+ if (typeof handler !== "function") {
1008
+ descriptor.set.call(this, handler);
1009
+ return;
1010
+ }
1011
+ descriptor.set.call(this, function (event) {
1012
+ state.socket = this;
1013
+ inspectTerminalOutput(event.data);
1014
+ if (typeof event.data === "string" && event.data[0] === MSG_KITTY) {
1015
+ if (handleKittyMessage(event.data.slice(1))) {
1016
+ return;
1017
+ }
1018
+ }
1019
+ return handler.call(this, event);
1020
+ });
1021
+ }
1022
+ });
1023
+
1024
+ window.addEventListener("resize", relayoutAll);
1025
+ bindTouchScrolling();
1026
+ bindImageContextMenu();
1027
+ const originalNativeSend = nativeSend;
1028
+ WebSocket.prototype.send = function (data) {
1029
+ if (typeof data === "string" && data[0] === "3") {
1030
+ try {
1031
+ const resize = JSON.parse(data.slice(1));
1032
+ if (resize.columns) {
1033
+ state.cols = resize.columns;
1034
+ }
1035
+ if (resize.rows) {
1036
+ state.rows = resize.rows;
1037
+ }
1038
+ } catch (error) {
1039
+ // ignore
1040
+ }
1041
+ }
1042
+ return originalNativeSend.call(this, data);
1043
+ };
1044
+ relayoutAll();
1045
+ })();