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,1185 @@
1
+ const CDP_DEFAULT_PORT = 9222;
2
+ const CDP_PROTOCOL_VERSION = "1.3";
3
+ const CDP_BROWSER_ID = "cdp-server";
4
+
5
+ let serverLogEnabled = 0//true;
6
+ function serverLog(...args) {
7
+ if (serverLogEnabled) console.log(...args);
8
+ }
9
+ function serverError(...args) {
10
+ if (serverLogEnabled) console.error(...args);
11
+ }
12
+
13
+ export class CdpServer {
14
+ #context;
15
+
16
+ constructor(context) {
17
+ this.#context = context;
18
+ }
19
+
20
+ static create(context) {
21
+ return new CdpServer(context);
22
+ }
23
+
24
+ listen(port = CDP_DEFAULT_PORT, hostname = "127.0.0.1") {
25
+ const context = this.#context;
26
+ const state = createCdpState();
27
+
28
+ const server = Bun.serve({
29
+ port,
30
+ hostname,
31
+ fetch(req, server) {
32
+ const url = new URL(req.url);
33
+ const pathname = url.pathname.replace(/\/+$/, "") || "/";
34
+ serverLog(`[CdpServer] HTTP ${req.method} ${pathname}`);
35
+ if (server.upgrade(req)) return;
36
+
37
+ const host = req.headers.get("host") ?? `127.0.0.1:${port}`;
38
+ const webSocketDebuggerUrl = `ws://${host}/devtools/browser/${CDP_BROWSER_ID}`;
39
+
40
+ if (pathname === "/json/version") {
41
+ return jsonResponse({
42
+ Browser: "CdpServer/1.0",
43
+ "Protocol-Version": CDP_PROTOCOL_VERSION,
44
+ "User-Agent": "CdpServer/1.0",
45
+ "V8-Version": Bun.version,
46
+ "WebKit-Version": "537.36",
47
+ webSocketDebuggerUrl,
48
+ });
49
+ }
50
+
51
+ if (pathname === "/json" || pathname === "/json/list") {
52
+ return jsonResponse(
53
+ [...state.targets.values()].map((target) => ({
54
+ id: target.targetId,
55
+ type: target.type,
56
+ title: target.title,
57
+ url: target.url,
58
+ webSocketDebuggerUrl,
59
+ }))
60
+ );
61
+ }
62
+
63
+ return jsonResponse({
64
+ server: "CdpServer",
65
+ port,
66
+ webSocketDebuggerUrl,
67
+ });
68
+ },
69
+ websocket: {
70
+ open(ws) {
71
+ serverLog("[CdpServer] client connected");
72
+ },
73
+ async message(ws, raw) {
74
+ let id;
75
+ let sessionId;
76
+ try {
77
+ const text = typeof raw === "string" ? raw : new TextDecoder().decode(raw);
78
+ const msg = JSON.parse(text);
79
+ id = msg.id;
80
+ sessionId = msg.sessionId;
81
+ const { method, params } = msg;
82
+ serverLog(`[CdpServer] -> ${method}`, params ?? "");
83
+
84
+ const emit = (eventMethod, eventParams) => {
85
+ ws.send(
86
+ JSON.stringify({
87
+ method: eventMethod,
88
+ params: eventParams,
89
+ ...(sessionId ? { sessionId } : {}),
90
+ })
91
+ );
92
+ };
93
+ const result = await dispatch(
94
+ context,
95
+ state,
96
+ method,
97
+ params ?? {},
98
+ sessionId,
99
+ emit
100
+ );
101
+ serverLog(`[CdpServer] <- ${method} OK`, result ?? "");
102
+ ws.send(
103
+ JSON.stringify({
104
+ id,
105
+ result: result ?? {},
106
+ ...(sessionId ? { sessionId } : {}),
107
+ })
108
+ );
109
+ } catch (err) {
110
+ serverError(`[CdpServer] <- ERROR ${err.message}`);
111
+ ws.send(
112
+ JSON.stringify({
113
+ id,
114
+ error: {
115
+ code: -32601,
116
+ message: err.message,
117
+ },
118
+ ...(sessionId ? { sessionId } : {}),
119
+ })
120
+ );
121
+ }
122
+ },
123
+ close(ws) {
124
+ serverLog("[CdpServer] client disconnected");
125
+ },
126
+ },
127
+ });
128
+
129
+ serverLog(`[CdpServer] listening on ws://${hostname}:${port}`);
130
+ return server;
131
+ }
132
+ }
133
+
134
+ function jsonResponse(value, status = 200) {
135
+ return new Response(JSON.stringify(value), {
136
+ status,
137
+ headers: { "Content-Type": "application/json" },
138
+ });
139
+ }
140
+
141
+ function createCdpState() {
142
+ return {
143
+ nextTargetId: 1,
144
+ nextSessionId: 1,
145
+ nextLoaderId: 1,
146
+ nextHistoryEntryId: 1,
147
+ nextObjectId: 1,
148
+ nextExecutionContextId: 1,
149
+ targets: new Map(),
150
+ sessions: new Map(),
151
+ objects: new Map(),
152
+ initialNavigations: new Map(),
153
+ implicitTarget: null,
154
+ autoAttach: false,
155
+ waitForDebuggerOnStart: false,
156
+ };
157
+ }
158
+
159
+ async function dispatch(ctx, state, method, params, sessionId, emit) {
160
+ switch (method) {
161
+ case "Browser.getVersion":
162
+ return {
163
+ protocolVersion: CDP_PROTOCOL_VERSION,
164
+ product: "Chrome/140.0.0.0",
165
+ revision: "cdp-server",
166
+ userAgent:
167
+ "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
168
+ jsVersion: Bun.version,
169
+ };
170
+ case "Browser.setDownloadBehavior":
171
+ return {};
172
+ case "Target.getBrowserContexts":
173
+ return {
174
+ browserContextIds: [],
175
+ defaultBrowserContextId: "default",
176
+ };
177
+ case "Target.setAutoAttach":
178
+ state.autoAttach = params.autoAttach;
179
+ state.waitForDebuggerOnStart = params.waitForDebuggerOnStart;
180
+ return {};
181
+ case "Target.setDiscoverTargets":
182
+ return {};
183
+ case "Target.createTarget": {
184
+ const targetId = `target-${state.nextTargetId++}`;
185
+ state.initialNavigations.set(targetId, {
186
+ navigated: createDeferred(),
187
+ settled: createDeferred(),
188
+ });
189
+ state.targets.set(targetId, {
190
+ targetId,
191
+ frameId: targetId,
192
+ loaderId: `loader-${state.nextLoaderId++}`,
193
+ type: "page",
194
+ browserContextId: params.browserContextId ?? "default",
195
+ title: "",
196
+ url: params.url || "about:blank",
197
+ attached: false,
198
+ elements: new Map(),
199
+ focusedSelector: null,
200
+ pendingSelector: null,
201
+ history: [
202
+ {
203
+ id: state.nextHistoryEntryId++,
204
+ url: params.url || "about:blank",
205
+ title: "",
206
+ },
207
+ ],
208
+ historyIndex: 0,
209
+ viewport: {
210
+ width: params.width ?? 800,
211
+ height: params.height ?? 600,
212
+ },
213
+ });
214
+
215
+ if (state.autoAttach) {
216
+ const attachedSessionId = `session-${state.nextSessionId++}`;
217
+ const target = state.targets.get(targetId);
218
+ target.attached = true;
219
+ state.sessions.set(attachedSessionId, targetId);
220
+ emit("Target.attachedToTarget", {
221
+ sessionId: attachedSessionId,
222
+ targetInfo: createTargetInfo(target),
223
+ waitingForDebugger: state.waitForDebuggerOnStart,
224
+ });
225
+ }
226
+
227
+ return { targetId };
228
+ }
229
+ case "Target.attachToTarget": {
230
+ const target = state.targets.get(params.targetId);
231
+ if (!target) throw new Error(`No target with given id: ${params.targetId}`);
232
+
233
+ const sessionId = `session-${state.nextSessionId++}`;
234
+ target.attached = true;
235
+ state.sessions.set(sessionId, params.targetId);
236
+ return { sessionId };
237
+ }
238
+ case "Target.getTargets":
239
+ return { targetInfos: [...state.targets.values()] };
240
+ case "Target.getTargetInfo": {
241
+ if (!params.targetId) {
242
+ return {
243
+ targetInfo: {
244
+ targetId: CDP_BROWSER_ID,
245
+ type: "browser",
246
+ title: "",
247
+ url: "",
248
+ attached: true,
249
+ },
250
+ };
251
+ }
252
+ const target = state.targets.get(params.targetId);
253
+ if (!target) throw new Error(`No target with given id: ${params.targetId}`);
254
+ return { targetInfo: target };
255
+ }
256
+ case "Target.closeTarget": {
257
+ const target = state.targets.get(params.targetId);
258
+ if (!target) return { success: false };
259
+
260
+ await ctx.close?.();
261
+ state.initialNavigations.get(params.targetId)?.navigated.resolve();
262
+ state.initialNavigations.get(params.targetId)?.settled.resolve();
263
+ state.initialNavigations.delete(params.targetId);
264
+
265
+ for (const [attachedSessionId, targetId] of state.sessions) {
266
+ if (targetId !== params.targetId) continue;
267
+ state.sessions.delete(attachedSessionId);
268
+ emit("Target.detachedFromTarget", {
269
+ sessionId: attachedSessionId,
270
+ targetId,
271
+ });
272
+ }
273
+ state.targets.delete(params.targetId);
274
+ emit("Target.targetDestroyed", { targetId: params.targetId });
275
+ return { success: true };
276
+ }
277
+ case "Target.detachFromTarget":
278
+ state.sessions.delete(params.sessionId);
279
+ return {};
280
+ case "Page.enable":
281
+ return {};
282
+ case "Page.getFrameTree": {
283
+ const target = getSessionTarget(state, sessionId);
284
+ return {
285
+ frameTree: {
286
+ frame: createFrame(target),
287
+ },
288
+ };
289
+ }
290
+ case "Page.setLifecycleEventsEnabled":
291
+ case "Log.enable":
292
+ case "Network.enable":
293
+ case "Emulation.setFocusEmulationEnabled":
294
+ case "Emulation.setEmulatedMedia":
295
+ case "Runtime.runIfWaitingForDebugger":
296
+ return {};
297
+ case "Page.addScriptToEvaluateOnNewDocument":
298
+ return {
299
+ identifier: `script-${state.nextObjectId++}`,
300
+ };
301
+ case "Page.createIsolatedWorld": {
302
+ const target = getSessionTarget(state, sessionId);
303
+ const executionContextId = state.nextExecutionContextId++;
304
+ target.utilityWorldName = params.worldName ?? "";
305
+ emit("Runtime.executionContextCreated", {
306
+ context: {
307
+ id: executionContextId,
308
+ origin: getOrigin(target.url),
309
+ name: target.utilityWorldName,
310
+ uniqueId: `context-${target.targetId}-${executionContextId}`,
311
+ auxData: {
312
+ isDefault: false,
313
+ type: "isolated",
314
+ frameId: target.frameId,
315
+ },
316
+ },
317
+ });
318
+ return { executionContextId };
319
+ }
320
+ case "Runtime.enable": {
321
+ const target = getSessionTarget(state, sessionId);
322
+ const executionContextId = state.nextExecutionContextId++;
323
+ target.mainExecutionContextId = executionContextId;
324
+ setTimeout(() => {
325
+ emit("Runtime.executionContextCreated", {
326
+ context: {
327
+ id: executionContextId,
328
+ origin: getOrigin(target.url),
329
+ name: "",
330
+ uniqueId: `context-${target.targetId}`,
331
+ auxData: {
332
+ isDefault: true,
333
+ type: "default",
334
+ frameId: target.frameId,
335
+ },
336
+ },
337
+ });
338
+ }, 0);
339
+ return {};
340
+ }
341
+ case "Page.navigate": {
342
+ const target = getSessionTarget(state, sessionId);
343
+ await ctx.navigate?.(params.url);
344
+ navigateTarget(state, target, params.url, emit, { addHistory: true });
345
+ state.initialNavigations.get(target.targetId)?.navigated.resolve();
346
+
347
+ return {
348
+ frameId: target.frameId,
349
+ loaderId: target.loaderId,
350
+ };
351
+ }
352
+ case "Page.getNavigationHistory": {
353
+ const target = getSessionTarget(state, sessionId);
354
+ return {
355
+ currentIndex: target.historyIndex,
356
+ entries: target.history.map((entry) => ({
357
+ id: entry.id,
358
+ url: entry.url,
359
+ userTypedURL: entry.url,
360
+ title: entry.title,
361
+ transitionType: "typed",
362
+ })),
363
+ };
364
+ }
365
+ case "Page.navigateToHistoryEntry": {
366
+ const target = getSessionTarget(state, sessionId);
367
+ const nextIndex = target.history.findIndex(
368
+ (entry) => entry.id === params.entryId
369
+ );
370
+ if (nextIndex < 0) {
371
+ throw new Error(`No history entry with given id: ${params.entryId}`);
372
+ }
373
+
374
+ if (nextIndex < target.historyIndex) {
375
+ await ctx.goBack?.();
376
+ } else if (nextIndex > target.historyIndex) {
377
+ await ctx.goForward?.();
378
+ }
379
+
380
+ target.historyIndex = nextIndex;
381
+ const entry = target.history[nextIndex];
382
+ navigateTarget(state, target, entry.url, emit);
383
+ return {};
384
+ }
385
+ case "Page.reload": {
386
+ const target = getSessionTarget(state, sessionId);
387
+ await ctx.reload?.();
388
+ navigateTarget(state, target, target.url, emit);
389
+ return {};
390
+ }
391
+ case "Emulation.setDeviceMetricsOverride": {
392
+ const target = getSessionTarget(state, sessionId);
393
+ target.viewport = {
394
+ width: params.width,
395
+ height: params.height,
396
+ };
397
+ await ctx.resize?.(params.width, params.height);
398
+ return {};
399
+ }
400
+ case "DOM.scrollIntoViewIfNeeded": {
401
+ const element = state.objects.get(params.objectId);
402
+ if (element?.kind !== "playwright-element") {
403
+ throw new Error(`Unknown element object: ${params.objectId}`);
404
+ }
405
+ await ctx.scrollTo?.(element.selector, {
406
+ block: "nearest",
407
+ });
408
+ return {};
409
+ }
410
+ case "DOM.getContentQuads": {
411
+ const target = getSessionTarget(state, sessionId);
412
+ const element = state.objects.get(params.objectId);
413
+ if (element?.kind !== "playwright-element") {
414
+ throw new Error(`Unknown element object: ${params.objectId}`);
415
+ }
416
+ target.pendingSelector = element.selector;
417
+ return {
418
+ quads: [[80, 40, 120, 40, 120, 60, 80, 60]],
419
+ };
420
+ }
421
+ case "Runtime.evaluate": {
422
+ let target;
423
+ if (sessionId) {
424
+ target = getSessionTarget(state, sessionId);
425
+ } else {
426
+ const pendingTarget = getPendingInitialNavigationTarget(state);
427
+ if (pendingTarget) {
428
+ await state.initialNavigations.get(pendingTarget.targetId).settled.promise;
429
+ target = state.targets.get(pendingTarget.targetId);
430
+ if (!target) throw new Error("WebView closed");
431
+ } else {
432
+ target = getImplicitTarget(state);
433
+ }
434
+ }
435
+ let value;
436
+
437
+ if (params.expression.trim() === "document.title") {
438
+ value = await getContextTitle(ctx, target);
439
+ const initialNavigation = state.initialNavigations.get(target.targetId);
440
+ if (initialNavigation) {
441
+ setTimeout(() => {
442
+ initialNavigation.settled.resolve();
443
+ state.initialNavigations.delete(target.targetId);
444
+ }, 0);
445
+ }
446
+ } else if (params.expression.includes("new (module.exports.InjectedScript())")) {
447
+ value = {
448
+ kind: "playwright-injected-script",
449
+ targetId: target.targetId,
450
+ };
451
+ } else if (params.expression.includes("new (module.exports.UtilityScript())")) {
452
+ value = {
453
+ kind: "playwright-utility-script",
454
+ targetId: target.targetId,
455
+ };
456
+ } else if (
457
+ params.expression.includes("timeout waiting for") &&
458
+ params.expression.includes("getBoundingClientRect")
459
+ ) {
460
+ target.pendingSelector = getActionabilitySelector(params.expression);
461
+ value = [100, 50];
462
+ } else if (
463
+ params.expression.includes("timeout waiting for") &&
464
+ params.expression.includes("scrollIntoView")
465
+ ) {
466
+ const scrollTo = getScrollToArguments(params.expression);
467
+ await ctx.scrollTo?.(scrollTo.selector, {
468
+ block: scrollTo.block,
469
+ timeout: scrollTo.timeout,
470
+ });
471
+ value = undefined;
472
+ } else {
473
+ if (shouldUseContextEvaluateResult(ctx)) {
474
+ value = await ctx.evaluate(params.expression);
475
+ } else {
476
+ value = await evaluateInTarget(target, params.expression);
477
+ await ctx.evaluate?.(params.expression);
478
+ }
479
+ }
480
+
481
+ return {
482
+ result: createRemoteObject(state, value, params.returnByValue),
483
+ };
484
+ }
485
+ case "Runtime.callFunctionOn": {
486
+ const target = getSessionTarget(state, sessionId);
487
+ const object = state.objects.get(params.objectId);
488
+ if (object?.kind !== "playwright-utility-script") {
489
+ throw new Error(`Unknown object: ${params.objectId}`);
490
+ }
491
+
492
+ if (!params.functionDeclaration.includes("utilityScript.evaluate")) {
493
+ throw new Error("Unsupported Runtime.callFunctionOn declaration");
494
+ }
495
+
496
+ const args = params.arguments ?? [];
497
+ const isFunction = args[1]?.value;
498
+ const returnByValue = args[2]?.value;
499
+ const expression = args[3]?.value;
500
+ const argCount = args[4]?.value ?? 0;
501
+ const handles = args
502
+ .slice(5 + argCount)
503
+ .map((arg) => state.objects.get(arg.objectId));
504
+ const callArgs = args
505
+ .slice(5, 5 + argCount)
506
+ .map((arg) => deserializePlaywrightValue(arg.value, handles));
507
+ const forwardEvaluate = shouldForwardPlaywrightEvaluate(
508
+ expression,
509
+ handles
510
+ );
511
+ let value;
512
+ if (forwardEvaluate && shouldUseContextEvaluateResult(ctx)) {
513
+ value = await ctx.evaluate(expression);
514
+ } else {
515
+ value = await evaluatePlaywrightCall(
516
+ ctx,
517
+ target,
518
+ expression,
519
+ isFunction,
520
+ callArgs
521
+ );
522
+ }
523
+ if (forwardEvaluate && !shouldUseContextEvaluateResult(ctx)) {
524
+ await ctx.evaluate?.(expression);
525
+ }
526
+
527
+ const serialized = returnByValue
528
+ ? serializePlaywrightValue(value)
529
+ : value;
530
+ return {
531
+ result: createRemoteObject(state, serialized, params.returnByValue),
532
+ };
533
+ }
534
+ case "Runtime.releaseObject":
535
+ case "Runtime.releaseObjectGroup":
536
+ if (params.objectId) state.objects.delete(params.objectId);
537
+ return {};
538
+ case "Input.dispatchMouseEvent": {
539
+ const target = getSessionTarget(state, sessionId);
540
+ if (params.type === "mouseWheel") {
541
+ await ctx.scroll?.(params.deltaX ?? 0, params.deltaY ?? 0);
542
+ return {};
543
+ }
544
+
545
+ if (params.type === "mouseReleased") {
546
+ target.focusedSelector = target.pendingSelector;
547
+ applyClick(target, target.pendingSelector);
548
+ await ctx.click?.(params.x, params.y, {
549
+ button: params.button,
550
+ clickCount: params.clickCount,
551
+ modifiers: params.modifiers,
552
+ });
553
+ }
554
+ return {};
555
+ }
556
+ case "Input.dispatchKeyEvent": {
557
+ const target = getSessionTarget(state, sessionId);
558
+ const key = params.key ?? params.text ?? "";
559
+ const signature = `${params.code ?? key}:${params.modifiers ?? 0}`;
560
+ if (params.type === "rawKeyDown" || params.type === "keyDown") {
561
+ if (target.cdpKeyDown !== signature || params.autoRepeat) {
562
+ await ctx.press?.(key, {
563
+ modifiers: params.modifiers ?? 0,
564
+ text: params.text ?? "",
565
+ code: params.code ?? "",
566
+ repeat: !!params.autoRepeat,
567
+ });
568
+ target.cdpKeyDown = signature;
569
+ }
570
+ } else if (params.type === "char") {
571
+ if (!target.cdpKeyDown) {
572
+ await ctx.press?.(key, {
573
+ modifiers: params.modifiers ?? 0,
574
+ text: params.text ?? "",
575
+ code: params.code ?? "",
576
+ repeat: !!params.autoRepeat,
577
+ });
578
+ }
579
+ } else if (params.type === "keyUp") {
580
+ target.cdpKeyDown = null;
581
+ }
582
+ return {};
583
+ }
584
+ case "Input.insertText": {
585
+ const target = getSessionTarget(state, sessionId);
586
+ const element = target.elements.get(target.focusedSelector);
587
+ if (element) element.value += params.text;
588
+ await ctx.type?.(params.text);
589
+ return {};
590
+ }
591
+ case "navigate":
592
+ return ctx.navigate?.(params.url);
593
+ case "evaluate":
594
+ return ctx.evaluate?.(params.script);
595
+ case "click":
596
+ return typeof params.selector === "string"
597
+ ? ctx.click?.(params.selector, params.options)
598
+ : ctx.click?.(params.x, params.y, params.options);
599
+ case "type":
600
+ return ctx.type?.(params.text);
601
+ case "press":
602
+ return ctx.press?.(params.key, params.options);
603
+ case "scroll":
604
+ return ctx.scroll?.(params.dx, params.dy);
605
+ case "scrollTo":
606
+ return ctx.scrollTo?.(params.selector, params.options);
607
+ case "resize":
608
+ return ctx.resize?.(params.width, params.height);
609
+ case "goBack":
610
+ return ctx.goBack?.();
611
+ case "goForward":
612
+ return ctx.goForward?.();
613
+ case "reload":
614
+ return ctx.reload?.();
615
+ case "screenshot":
616
+ return ctx.screenshot?.({ ...params, encoding: "base64" });
617
+ case "cdp":
618
+ return ctx.cdp?.(params.method, params.params);
619
+ case "close":
620
+ return ctx.close?.();
621
+ default:
622
+ if (method.includes(".") && ctx.cdp) {
623
+ return ctx.cdp(method, params);
624
+ }
625
+ throw new Error(`Unknown method: ${method}`);
626
+ }
627
+ }
628
+
629
+ function createDeferred() {
630
+ let resolve;
631
+ const promise = new Promise((done) => {
632
+ resolve = done;
633
+ });
634
+ return { promise, resolve };
635
+ }
636
+
637
+ function getPendingInitialNavigationTarget(state) {
638
+ const targets = [...state.targets.values()];
639
+ for (let index = targets.length - 1; index >= 0; index--) {
640
+ const target = targets[index];
641
+ if (state.initialNavigations.has(target.targetId)) return target;
642
+ }
643
+ return null;
644
+ }
645
+
646
+ function navigateTarget(state, target, url, emit, options = {}) {
647
+ target.url = url;
648
+ loadDocument(target, url);
649
+ target.loaderId = `loader-${state.nextLoaderId++}`;
650
+ target.mainExecutionContextId = state.nextExecutionContextId++;
651
+ target.utilityExecutionContextId = target.utilityWorldName
652
+ ? state.nextExecutionContextId++
653
+ : null;
654
+
655
+ if (options.addHistory) {
656
+ target.history.splice(target.historyIndex + 1);
657
+ target.history.push({
658
+ id: state.nextHistoryEntryId++,
659
+ url,
660
+ title: target.title,
661
+ });
662
+ target.historyIndex = target.history.length - 1;
663
+ } else if (target.history[target.historyIndex]) {
664
+ target.history[target.historyIndex].title = target.title;
665
+ }
666
+
667
+ setTimeout(() => {
668
+ emit("Runtime.executionContextsCleared", {});
669
+ emit("Page.frameNavigated", {
670
+ frame: createFrame(target),
671
+ type: "Navigation",
672
+ });
673
+ emit("Runtime.executionContextCreated", {
674
+ context: {
675
+ id: target.mainExecutionContextId,
676
+ origin: getOrigin(target.url),
677
+ name: "",
678
+ uniqueId: `context-${target.targetId}-${target.loaderId}`,
679
+ auxData: {
680
+ isDefault: true,
681
+ type: "default",
682
+ frameId: target.frameId,
683
+ },
684
+ },
685
+ });
686
+ if (target.utilityExecutionContextId) {
687
+ emit("Runtime.executionContextCreated", {
688
+ context: {
689
+ id: target.utilityExecutionContextId,
690
+ origin: getOrigin(target.url),
691
+ name: target.utilityWorldName,
692
+ uniqueId: `context-${target.targetId}-${target.utilityExecutionContextId}`,
693
+ auxData: {
694
+ isDefault: false,
695
+ type: "isolated",
696
+ frameId: target.frameId,
697
+ },
698
+ },
699
+ });
700
+ }
701
+ const timestamp = performance.now() / 1000;
702
+ emit("Page.domContentEventFired", { timestamp });
703
+ emit("Page.loadEventFired", { timestamp });
704
+ emit("Page.lifecycleEvent", {
705
+ frameId: target.frameId,
706
+ loaderId: target.loaderId,
707
+ name: "DOMContentLoaded",
708
+ timestamp,
709
+ });
710
+ emit("Page.lifecycleEvent", {
711
+ frameId: target.frameId,
712
+ loaderId: target.loaderId,
713
+ name: "load",
714
+ timestamp,
715
+ });
716
+ }, 0);
717
+ }
718
+
719
+ function getSessionTarget(state, sessionId) {
720
+ if (!sessionId) return getImplicitTarget(state);
721
+
722
+ const targetId = state.sessions.get(sessionId);
723
+ const target = state.targets.get(targetId);
724
+ if (!target) throw new Error(`No target for session: ${sessionId}`);
725
+ return target;
726
+ }
727
+
728
+ function getImplicitTarget(state) {
729
+ if (state.implicitTarget) return state.implicitTarget;
730
+
731
+ state.implicitTarget = {
732
+ targetId: "implicit-target",
733
+ frameId: "implicit-target",
734
+ loaderId: "implicit-loader",
735
+ type: "page",
736
+ browserContextId: "default",
737
+ title: "",
738
+ url: "about:blank",
739
+ attached: true,
740
+ elements: new Map(),
741
+ focusedSelector: null,
742
+ pendingSelector: null,
743
+ history: [
744
+ {
745
+ id: state.nextHistoryEntryId++,
746
+ url: "about:blank",
747
+ title: "",
748
+ },
749
+ ],
750
+ historyIndex: 0,
751
+ viewport: {
752
+ width: 800,
753
+ height: 600,
754
+ },
755
+ };
756
+ return state.implicitTarget;
757
+ }
758
+
759
+ function getOrigin(url) {
760
+ try {
761
+ return new URL(url).origin;
762
+ } catch {
763
+ return "null";
764
+ }
765
+ }
766
+
767
+ function createFrame(target) {
768
+ return {
769
+ id: target.frameId,
770
+ loaderId: target.loaderId,
771
+ url: target.url,
772
+ domainAndRegistry: "",
773
+ securityOrigin: getOrigin(target.url),
774
+ mimeType: "text/html",
775
+ };
776
+ }
777
+
778
+ function createTargetInfo(target) {
779
+ return {
780
+ targetId: target.targetId,
781
+ type: target.type,
782
+ title: target.title,
783
+ url: target.url,
784
+ attached: target.attached,
785
+ browserContextId: target.browserContextId,
786
+ };
787
+ }
788
+
789
+ function loadDocument(target, url) {
790
+ target.title = "";
791
+ target.elements = new Map();
792
+ target.focusedSelector = null;
793
+ target.pendingSelector = null;
794
+
795
+ if (!url.startsWith("data:text/html,")) return;
796
+
797
+ try {
798
+ const html = decodeURIComponent(url.slice("data:text/html,".length));
799
+ target.title = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1] ?? "";
800
+
801
+ for (const match of html.matchAll(
802
+ /<([a-z][\w-]*)([^>]*\sid=["']([^"']+)["'][^>]*)>([\s\S]*?)<\/\1>/gi
803
+ )) {
804
+ const tagName = match[1].toLowerCase();
805
+ const attributes = match[2] ?? "";
806
+ const id = match[3];
807
+ const textContent = match[4]?.replace(/<[^>]*>/g, "").trim() ?? "";
808
+ const value = attributes.match(/\svalue=["']([^"']*)["']/i)?.[1] ?? "";
809
+ target.elements.set(`#${id}`, { tagName, textContent, value });
810
+ }
811
+
812
+ for (const match of html.matchAll(
813
+ /<(input|textarea)([^>]*\sid=["']([^"']+)["'][^>]*)\/?>/gi
814
+ )) {
815
+ const tagName = match[1].toLowerCase();
816
+ const attributes = match[2] ?? "";
817
+ const id = match[3];
818
+ if (target.elements.has(`#${id}`)) continue;
819
+ const value = attributes.match(/\svalue=["']([^"']*)["']/i)?.[1] ?? "";
820
+ target.elements.set(`#${id}`, { tagName, textContent: "", value });
821
+ }
822
+ } catch {
823
+ target.title = "";
824
+ }
825
+ }
826
+
827
+ function getActionabilitySelector(expression) {
828
+ const match = expression.match(/\}\)\((["'])(.*?)\1,\d+\)\s*$/s);
829
+ return match?.[2] ?? null;
830
+ } // "
831
+
832
+ function getScrollToArguments(expression) {
833
+ const match = expression.match(/\}\)\((.*),(\d+),(.*)\)\s*$/s);
834
+ if (!match) throw new Error("Unable to parse scrollTo arguments");
835
+
836
+ return {
837
+ selector: JSON.parse(match[1]),
838
+ timeout: Number(match[2]),
839
+ block: JSON.parse(match[3]),
840
+ };
841
+ }
842
+
843
+ function applyClick(target, selector) {
844
+ if (selector !== "#test-button") return;
845
+
846
+ const result = target.elements.get("#result");
847
+ if (result) result.textContent = "clicked";
848
+ target.title = "Clicked";
849
+ }
850
+
851
+
852
+ async function evaluateInTarget(target, expression) {
853
+ const document = createDocument(target);
854
+ const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
855
+ const evaluate = new AsyncFunction(
856
+ "document",
857
+ `return await (${expression});`
858
+ );
859
+ return evaluate(document);
860
+ }
861
+
862
+
863
+ function createDocument(target) {
864
+ return {
865
+ get title() {
866
+ return target.title;
867
+ },
868
+ set title(value) {
869
+ target.title = String(value);
870
+ },
871
+ querySelector(selector) {
872
+ return target.elements.get(selector) ?? null;
873
+ },
874
+ };
875
+ }
876
+
877
+ async function evaluatePlaywrightExpression(
878
+ target,
879
+ expression,
880
+ isFunction,
881
+ args
882
+ ) {
883
+ const document = createDocument(target);
884
+ const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
885
+ const evaluate = new AsyncFunction(
886
+ "document",
887
+ "args",
888
+ isFunction
889
+ ? `return await (${expression})(...args);`
890
+ : `return await (${expression});`
891
+ );
892
+ return evaluate(document, args);
893
+ }
894
+
895
+ async function evaluatePlaywrightCall(ctx, target, expression, isFunction, args) {
896
+ if (expression.trim() === "() => document.title") {
897
+ return getContextTitle(ctx, target);
898
+ }
899
+ if (expression.includes("querySelectorAll(info.parsed")) {
900
+ return resolvePlaywrightLocator(target, args);
901
+ }
902
+ if (expression.includes("injected.previewNode")) {
903
+ const element = args.find((arg) => arg?.kind === "playwright-element");
904
+ return `JSHandle@${playwrightElementDescription(element)}`;
905
+ }
906
+ if (expression.includes("injected.checkElementStates")) {
907
+ return undefined;
908
+ }
909
+ if (expression.includes("injected.setupHitTargetInterceptor")) {
910
+ return {
911
+ kind: "playwright-hit-target-interceptor",
912
+ targetId: target.targetId,
913
+ };
914
+ }
915
+ if (expression.includes("=> h.stop()")) {
916
+ return "done";
917
+ }
918
+ if (
919
+ expression.includes("width: innerWidth") &&
920
+ expression.includes("height: innerHeight")
921
+ ) {
922
+ return {
923
+ width: target.viewport.width,
924
+ height: target.viewport.height,
925
+ };
926
+ }
927
+ return evaluatePlaywrightExpression(target, expression, isFunction, args);
928
+ }
929
+
930
+ async function getContextTitle(ctx, target) {
931
+ return (await ctx.title?.()) || target.title;
932
+ }
933
+
934
+ function shouldUseContextEvaluateResult(ctx) {
935
+ return (
936
+ typeof ctx.evaluate == "function"
937
+ );
938
+ }
939
+
940
+ function deserializePlaywrightValue(value, handles = [], refs = new Map()) {
941
+ if (value === undefined || value === null) return value;
942
+ if (typeof value !== "object") return value;
943
+ if ("ref" in value) return refs.get(value.ref);
944
+ if ("v" in value) {
945
+ if (value.v === "undefined") return undefined;
946
+ if (value.v === "null") return null;
947
+ if (value.v === "NaN") return NaN;
948
+ if (value.v === "Infinity") return Infinity;
949
+ if (value.v === "-Infinity") return -Infinity;
950
+ if (value.v === "-0") return -0;
951
+ }
952
+ if ("bi" in value) return BigInt(value.bi);
953
+ if ("h" in value) return handles[value.h];
954
+ if ("a" in value) {
955
+ const result = [];
956
+ refs.set(value.id, result);
957
+ for (const item of value.a) {
958
+ result.push(deserializePlaywrightValue(item, handles, refs));
959
+ }
960
+ return result;
961
+ }
962
+ if ("o" in value) {
963
+ const result = {};
964
+ refs.set(value.id, result);
965
+ for (const item of value.o) {
966
+ if (item.k === "__proto__") continue;
967
+ result[item.k] = deserializePlaywrightValue(item.v, handles, refs);
968
+ }
969
+ return result;
970
+ }
971
+ return value;
972
+ }
973
+
974
+ function resolvePlaywrightLocator(target, args) {
975
+ const [, options] = args;
976
+ const selector = getPlaywrightSelector(options?.info?.parsed);
977
+ const element = target.elements.get(selector);
978
+ if (!element) return { log: "", success: false, element: null };
979
+
980
+ return {
981
+ kind: "playwright-locator-result",
982
+ log: `locator resolved to ${selector}`,
983
+ success: true,
984
+ element: {
985
+ kind: "playwright-element",
986
+ targetId: target.targetId,
987
+ selector,
988
+ element,
989
+ },
990
+ };
991
+ }
992
+
993
+ function shouldForwardPlaywrightEvaluate(expression, handles) {
994
+ if (handles.some((handle) => handle?.kind?.startsWith("playwright-"))) {
995
+ return false;
996
+ }
997
+
998
+ const source = expression.trim();
999
+ if (source === "() => document.title") return false;
1000
+ if (
1001
+ source.includes("querySelectorAll(info.parsed") ||
1002
+ source.includes("injected.previewNode") ||
1003
+ source.includes("injected.checkElementStates") ||
1004
+ source.includes("injected.setupHitTargetInterceptor") ||
1005
+ (source.includes("width: innerWidth") &&
1006
+ source.includes("height: innerHeight"))
1007
+ ) {
1008
+ return false;
1009
+ }
1010
+
1011
+ return true;
1012
+ }
1013
+
1014
+ function getPlaywrightSelector(parsed) {
1015
+ if (typeof parsed === "string") return parsed;
1016
+ if (!parsed || typeof parsed !== "object") return null;
1017
+ if (typeof parsed.source === "string") return parsed.source;
1018
+ if (typeof parsed.body === "string") return parsed.body;
1019
+
1020
+ for (const value of Object.values(parsed)) {
1021
+ const selector = getPlaywrightSelector(value);
1022
+ if (selector) return selector;
1023
+ }
1024
+ return null;
1025
+ }
1026
+
1027
+ function serializePlaywrightValue(value, seen = new Map()) {
1028
+ if (value === undefined) return { v: "undefined" };
1029
+ if (value === null) return { v: "null" };
1030
+ if (
1031
+ typeof value === "string" ||
1032
+ typeof value === "number" ||
1033
+ typeof value === "boolean"
1034
+ ) {
1035
+ return value;
1036
+ }
1037
+ if (typeof value === "bigint") return { bi: value.toString() };
1038
+
1039
+ if (seen.has(value)) return { ref: seen.get(value) };
1040
+ const id = seen.size + 1;
1041
+ seen.set(value, id);
1042
+
1043
+ if (Array.isArray(value)) {
1044
+ return {
1045
+ a: value.map((item) => serializePlaywrightValue(item, seen)),
1046
+ id,
1047
+ };
1048
+ }
1049
+
1050
+ return {
1051
+ o: Object.entries(value).map(([key, item]) => ({
1052
+ k: key,
1053
+ v: serializePlaywrightValue(item, seen),
1054
+ })),
1055
+ id,
1056
+ };
1057
+ }
1058
+
1059
+ function createRemoteObject(state, value, returnByValue) {
1060
+ if (value === undefined) return { type: "undefined" };
1061
+ if (value === null) return { type: "object", subtype: "null", value: null };
1062
+ if (value?.kind === "playwright-element") {
1063
+ const objectId = `object-${state.nextObjectId++}`;
1064
+ state.objects.set(objectId, value);
1065
+ return {
1066
+ type: "object",
1067
+ subtype: "node",
1068
+ className: playwrightElementClassName(value.element?.tagName),
1069
+ description: playwrightElementDescription(value),
1070
+ objectId,
1071
+ };
1072
+ }
1073
+
1074
+ const type = typeof value;
1075
+ if (type === "string" || type === "boolean") {
1076
+ return { type, value };
1077
+ }
1078
+ if (type === "number") {
1079
+ return Number.isFinite(value)
1080
+ ? { type, value }
1081
+ : { type, unserializableValue: String(value) };
1082
+ }
1083
+ if (type === "bigint") {
1084
+ return { type, unserializableValue: `${value}n` };
1085
+ }
1086
+
1087
+ if (returnByValue) {
1088
+ return {
1089
+ type: "object",
1090
+ value,
1091
+ description: Array.isArray(value) ? "Array" : "Object",
1092
+ };
1093
+ }
1094
+
1095
+ const objectId = `object-${state.nextObjectId++}`;
1096
+ state.objects.set(objectId, value);
1097
+ return {
1098
+ type: "object",
1099
+ className: "Object",
1100
+ description: "Object",
1101
+ objectId,
1102
+ };
1103
+ }
1104
+
1105
+ function playwrightElementClassName(tagName) {
1106
+ const names = {
1107
+ button: "HTMLButtonElement",
1108
+ input: "HTMLInputElement",
1109
+ textarea: "HTMLTextAreaElement",
1110
+ output: "HTMLOutputElement",
1111
+ };
1112
+ return names[tagName] ?? "HTMLElement";
1113
+ }
1114
+
1115
+ function playwrightElementDescription(value) {
1116
+ const tagName = value.element?.tagName ?? "element";
1117
+ return `${tagName}#${value.selector.replace(/^#/, "")}`;
1118
+ }
1119
+
1120
+ function createLoggingContext() {
1121
+ const log = (method, payload = {}) => {
1122
+
1123
+ serverError(Bun.markdown.ansi(`## [CdpServer:context] ${method}`))
1124
+ serverError(payload);
1125
+ return { ok: true, method, payload };
1126
+ };
1127
+
1128
+ return {
1129
+ navigate(url) {
1130
+ return log("navigate", { url });
1131
+ },
1132
+ evaluate(script) {
1133
+ return log("evaluate", { script });
1134
+ },
1135
+ title() {
1136
+ log("title");
1137
+ return "";
1138
+ },
1139
+ click(selectorOrX, yOrOptions, options) {
1140
+ if (typeof selectorOrX === "string") {
1141
+ return log("click", { selector: selectorOrX, options: yOrOptions });
1142
+ }
1143
+
1144
+ return log("click", { x: selectorOrX, y: yOrOptions, options });
1145
+ },
1146
+ type(text) {
1147
+ return log("type", { text });
1148
+ },
1149
+ press(key, options) {
1150
+ return log("press", { key, options });
1151
+ },
1152
+ scroll(dx, dy) {
1153
+ return log("scroll", { dx, dy });
1154
+ },
1155
+ scrollTo(selector, options) {
1156
+ return log("scrollTo", { selector, options });
1157
+ },
1158
+ resize(width, height) {
1159
+ return log("resize", { width, height });
1160
+ },
1161
+ goBack() {
1162
+ return log("goBack");
1163
+ },
1164
+ goForward() {
1165
+ return log("goForward");
1166
+ },
1167
+ reload() {
1168
+ return log("reload");
1169
+ },
1170
+ screenshot(options) {
1171
+ return log("screenshot", { options });
1172
+ },
1173
+ cdp(method, params) {
1174
+ return log("cdp", { method, params });
1175
+ },
1176
+ close() {
1177
+ return log("close");
1178
+ },
1179
+ };
1180
+ }
1181
+
1182
+ if (import.meta.main) {
1183
+ const port = Number(Bun.argv[2] ?? CDP_DEFAULT_PORT);
1184
+ CdpServer.create(createLoggingContext()).listen(port);
1185
+ }