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,1140 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import path from 'node:path'
4
+ import { pathToFileURL } from 'node:url'
5
+ import { readAssetText, readInternalAssetText } from './single-exe/assetsHelper.js'
6
+ import { fenceEventMap, inlineFenceEventCode } from './src/cui/fence-events.mjs'
7
+ import {
8
+ readLeadingHtmlCharacterReference,
9
+ renderMarkdownWithHeadingIds,
10
+ } from './src/cui/heading-ids.mjs'
11
+ import { parseMdcuiIdentity } from './src/cui/identity.mjs'
12
+ import { renderAnsiWithDataImages } from './src/cui/kitty-images.mjs'
13
+ import {
14
+ addTuiTableRowSeparators,
15
+ convertTuiTableCheckboxes,
16
+ markHeadingTableRows,
17
+ } from './src/cui/table-render.mjs'
18
+ import {
19
+ renderMarkdownTemplateComponents,
20
+ wrapWuiTemplateComponents,
21
+ } from './src/cui/template-components.mjs'
22
+ import { REPO_ROOT } from './single-exe/compiled.js'
23
+
24
+ const csl=console.log
25
+ const cse=console.error
26
+ const mda=Bun.markdown.ansi
27
+ const mdh=Bun.markdown.html
28
+ const jss=JSON.stringify
29
+
30
+
31
+ const TEST_ROW=9
32
+ const TEST_COL=5
33
+
34
+
35
+ function logWroteFile(label,path)
36
+ {
37
+ if(!process.stdin.isRaw)
38
+ cse(mda(`- Wrote to ${label} file: ${path}`))
39
+ }
40
+
41
+ export async function readMarkdownInput(mdpath, overwriteDemo = false)
42
+ {
43
+ const file = Bun.file(mdpath);
44
+ if (!overwriteDemo && await file.exists()) return await file.text();
45
+ const assetName = path.basename(mdpath);
46
+ const internalText = readInternalAssetText(assetName);
47
+ if (internalText != null) {
48
+ await Bun.write(mdpath, internalText);
49
+ return internalText;
50
+ }
51
+ const fallbackPath = path.join(REPO_ROOT, assetName);
52
+ const fallback = Bun.file(fallbackPath);
53
+ if (await fallback.exists()) {
54
+ const fallbackText = await fallback.text();
55
+ await Bun.write(mdpath, fallbackText);
56
+ return fallbackText;
57
+ }
58
+ throw new Error(`md file not found: ${mdpath}`);
59
+ }
60
+
61
+
62
+ export async function main(tuiWidth=30, {
63
+ mdpath: requestedMdpath = null,
64
+ overwriteDemo = process.argv.includes("--overwrite-demo"),
65
+ printUi = process.argv.includes("--print-ui"),
66
+ useBundledMdcuiServer = false,
67
+ } = {})
68
+ {
69
+ const explicitMdpath = process.argv.find(i=>i.endsWith('.md'))
70
+ const mdpath = requestedMdpath || explicitMdpath || 'testapp.md'
71
+
72
+
73
+ // 1. Read markdown file
74
+ console.error('Reading:',mdpath)
75
+ let md = await readMarkdownInput(mdpath, overwriteDemo && !requestedMdpath && !explicitMdpath)
76
+
77
+ // 2. Extract js files
78
+ md = await extractJs(md,mdpath);
79
+
80
+ // 3. Create Terminal UI
81
+ let tui = createTui(md,tuiWidth)
82
+ if (printUi) {
83
+ cse(mda("\n# TUI"))
84
+ cse(tui)
85
+ cse(mda('## TUI raw'))
86
+ cse(jss(tui))
87
+ }
88
+
89
+
90
+ // 4. Create Web UI
91
+ let wui = await createWui(md,mdpath)
92
+ if (printUi) {
93
+ cse(mda('\n# HTML'))
94
+ cse(wui)
95
+ }
96
+
97
+
98
+ /*
99
+ // 5. Get character from point for TUI
100
+ let ch = charFromPoint(tui,TEST_ROW,TEST_COL)
101
+
102
+ cse(mda(
103
+ '# Slicing row,col: '+TEST_ROW+','+TEST_COL
104
+ ))
105
+
106
+ cse(jss(ch))
107
+
108
+ */
109
+
110
+
111
+ const serverPath = mdpath + "-server.js"
112
+ const useEmbeddedMdcuiServer = Boolean(
113
+ global.MDCUI_MAIN && useBundledMdcuiServer
114
+ )
115
+ cse(
116
+ `[mdcui] Starting ${useEmbeddedMdcuiServer ? "embedded" : "external"} `
117
+ + `WUI server: ${
118
+ useEmbeddedMdcuiServer
119
+ ? String(global.MDCUI_MAIN)
120
+ : path.resolve(serverPath)
121
+ }`
122
+ )
123
+ const svmod = useEmbeddedMdcuiServer
124
+ ? await import(global.MDCUI_MAIN + "-server.js")
125
+ : await import(pathToFileURL(path.resolve(serverPath)).href)
126
+
127
+ cse("\n\n"+mda('# Server'))
128
+ svmod.main();
129
+ }
130
+
131
+
132
+ // Exports
133
+
134
+
135
+ export async function extractJs(md,mdpath,{ bundling = false } = {})
136
+ {
137
+ const mdb = path.basename(mdpath)
138
+
139
+ let sctagsp = mdpath + ".front.js"
140
+ let sctags = ""
141
+ // Gather frontend script tags
142
+ let reJs = /```js front[^]+?```/g //
143
+ md = md.replace( reJs,
144
+ i=>{
145
+ sctags+=i.slice(11,-3)+'\n\n'
146
+
147
+ return '';
148
+ return i
149
+ .replace('```js front',"<scr"+"ipt>")
150
+ .slice(0,-3)+"</scr"+"ipt>"
151
+ }
152
+ )
153
+
154
+ const frontSource = sctags
155
+ sctags = "#!/usr/bin/env bun" + `
156
+
157
+ import { rpc as wuiRpcClient, runWebMdcuiLoad } from "./${mdb}-rpc.js";
158
+ let rpc = null
159
+ if(globalThis.process)
160
+ {
161
+ rpc = await import(
162
+ "./" +
163
+ (global.MDCUI_MAIN_BASE||"${mdb}") +
164
+ ".back.js"
165
+ ) ;
166
+ }
167
+ else
168
+ rpc = wuiRpcClient ;
169
+
170
+ ` + frontSource + `
171
+
172
+ if (typeof window !== "undefined")
173
+ {
174
+ // Browser
175
+ setTimeout( () => {
176
+ import("./${mdb}.front.js").then(mod=>{
177
+ Object.assign(window,mod);
178
+ window.__mdcuiFrontModule = mod;
179
+ return runWebMdcuiLoad(window, mod);
180
+ })
181
+ }, 0 ) ;
182
+ }
183
+ ` ;
184
+
185
+ await Bun.write(sctagsp,sctags);
186
+ logWroteFile("front", sctagsp)
187
+
188
+ if (bundling) {
189
+ const bundledFrontSource = "#!/usr/bin/env bun" + `
190
+
191
+ import { rpc as wuiRpcClient } from "./${mdb}-rpc.js";
192
+ const rpc = wuiRpcClient;
193
+
194
+ ` + frontSource
195
+ const bundledFrontPath = mdpath + ".tmpfs.js"
196
+ await Bun.write(bundledFrontPath, bundledFrontSource)
197
+ logWroteFile("bundling front", bundledFrontPath)
198
+
199
+ const bundledImportPath = mdpath + ".tmpfi.js"
200
+ await Bun.write(
201
+ bundledImportPath,
202
+ `import * as frontMod from "./${mdb}.tmpfs.js";
203
+ import { runWebMdcuiLoad } from "./${mdb}-rpc.js";
204
+
205
+ Object.assign(window, frontMod);
206
+ window.__mdcuiFrontModule = frontMod;
207
+ await runWebMdcuiLoad(window, frontMod);
208
+ `,
209
+ )
210
+ logWroteFile("bundling import", bundledImportPath)
211
+ }
212
+
213
+ sctagsp = mdpath + ".back.js"
214
+ sctags = "#!/usr/bin/env bun\n\n"
215
+ // Gather backend script tags
216
+ reJs = /```js back[^]+?```/g //
217
+ md = md.replace( reJs,
218
+ i=>{
219
+ sctags+=i.slice(10,-3)+'\n\n'
220
+
221
+ return '';
222
+ }
223
+ )
224
+
225
+ await Bun.write(sctagsp,sctags);
226
+ logWroteFile("back", sctagsp)
227
+
228
+ await writeRuntimeFiles(mdpath)
229
+
230
+ return md
231
+ }
232
+
233
+ export async function writeRuntimeFiles(mdpath)
234
+ {
235
+ const mdb = path.basename(mdpath)
236
+ const rpcPath = mdpath + "-rpc.js"
237
+ const serverPath = mdpath + "-server.js"
238
+ const rpcSource = await readAssetText("src/cui/rpc.mjs")
239
+ const serverSource = (await readAssetText("src/cui/server.mjs"))
240
+ .replaceAll("./rpc.mjs", `./${mdb}-rpc.js`)
241
+ .replaceAll("testapp.md", mdb)
242
+
243
+ await Bun.write(rpcPath, rpcSource)
244
+ logWroteFile("rpc", rpcPath)
245
+ await Bun.write(serverPath, serverSource)
246
+ logWroteFile("server", serverPath)
247
+
248
+ return serverPath
249
+ }
250
+
251
+
252
+ export function createTui(md,TERMINAL_WIDTH=30, context = null) // ANSI Colors
253
+ {
254
+ const templates = renderMarkdownTemplateComponents(md);
255
+ if (context && typeof context === "object")
256
+ context.preRenderHeadingData = templates.idStore;
257
+ md = templates.markdown;
258
+ const tablePlan = markHeadingTableRows(md);
259
+ md = ( renderAnsiWithDataImages(
260
+ tablePlan.markdown,{
261
+ hyperlinks:true,
262
+ columns:TERMINAL_WIDTH
263
+ }
264
+ )
265
+ || md )+'' ;
266
+ md = addTuiTableRowSeparators(md, tablePlan);
267
+ md = convertTuiTableCheckboxes(md);
268
+
269
+ return md ;
270
+
271
+ return Bun.wrapAnsi(
272
+ md,
273
+ TERMINAL_WIDTH
274
+ )
275
+ }
276
+
277
+ function parseWuiControlIdentity(info)
278
+ {
279
+ const identity = parseMdcuiIdentity(info);
280
+ return ["text", "textarea"].includes(identity?.tag)
281
+ ? { ...identity, id: identity.id ?? "" }
282
+ : null;
283
+ }
284
+
285
+ function escapeHtmlAttribute(value)
286
+ {
287
+ return String(value)
288
+ .replaceAll("&", "&amp;")
289
+ .replaceAll('"', "&quot;")
290
+ .replaceAll("<", "&lt;")
291
+ .replaceAll(">", "&gt;");
292
+ }
293
+
294
+ export function convertWuiTextareas(html, eventsById = new Map())
295
+ {
296
+ return String(html).replace(
297
+ /<pre><code class="language-([^"]+)">([^]*?)<\/code><\/pre>/g,
298
+ (whole, info, content) => {
299
+ const identity = parseWuiControlIdentity(info);
300
+ if (!identity) return whole;
301
+ const value = content.replace(/\n$/, "");
302
+ const contentLines = value.split("\n");
303
+ const cols = Math.max(1, ...contentLines.map(line => [...line].length));
304
+ const declaration = identity.id && eventsById.get(identity.id)?.tag === identity.tag
305
+ ? eventsById.get(identity.id)
306
+ : null;
307
+ const keydownHandler = declaration?.events.get("keydown");
308
+ const inputHandler = declaration?.events.get("input");
309
+ const keydownCode = keydownHandler
310
+ ? [
311
+ "const __mdcuiKeyCode=Number(event.keyCode||event.which||0);",
312
+ "const __mdcuiCodeLetter=/^Key[A-Z]$/.test(event.code||\"\")?event.code.charCodeAt(3):0;",
313
+ "const __mdcuiLetterCode=__mdcuiKeyCode>=65&&__mdcuiKeyCode<=90?__mdcuiKeyCode:__mdcuiCodeLetter;",
314
+ "const __mdcuiAltGraph=!!event.getModifierState&&event.getModifierState(\"AltGraph\");",
315
+ "const __mdcuiLetter=!__mdcuiAltGraph&&(event.ctrlKey||event.altKey||event.metaKey)&&__mdcuiLetterCode>=65&&__mdcuiLetterCode<=90;",
316
+ "if(__mdcuiLetter)Object.defineProperty(event,\"key\",{configurable:true,value:String.fromCharCode(__mdcuiLetterCode+(event.shiftKey?0:32))});",
317
+ "this.__mdcuiIdentifiedKeydown=!!event.key&&event.key!==\"Unidentified\";",
318
+ "this.__mdcuiUnidentifiedKeydown=event.key===\"Unidentified\"?{keyCode:__mdcuiKeyCode,ctrlKey:!!event.ctrlKey,shiftKey:!!event.shiftKey,altKey:!!event.altKey,metaKey:!!event.metaKey,altGraph:__mdcuiAltGraph}:null;",
319
+ "clearTimeout(this.__mdcuiKeydownReset);",
320
+ "this.__mdcuiKeydownReset=setTimeout(()=>{this.__mdcuiIdentifiedKeydown=false;this.__mdcuiUnidentifiedKeydown=null},0);",
321
+ "if(event.key!==\"Unidentified\"){\n",
322
+ "Object.defineProperty(event,\"toJSON\",{configurable:true,value:function(){const t=this.target||{};return{type:String(this.type||\"\"),key:String(this.key||\"\"),code:String(this.code||\"\"),raw:String(this.raw||\"\"),ctrlKey:!!this.ctrlKey,shiftKey:!!this.shiftKey,altKey:!!this.altKey,metaKey:!!this.metaKey,repeat:!!this.repeat,defaultPrevented:!!this.defaultPrevented,target:{id:String(t.id||\"\"),tagName:String(t.tagName||\"\"),className:String(t.className||\"\"),value:String(t.value??\"\")}}}});",
323
+ keydownHandler.modifiers.includes("prevent")
324
+ ? "event.preventDefault();"
325
+ : "",
326
+ keydownHandler.code,
327
+ "\n}",
328
+ ].join("")
329
+ : "";
330
+ const beforeInputCode = keydownHandler
331
+ ? [
332
+ "if(!this.__mdcuiIdentifiedKeydown&&event.data!=null&&event.data!==\"\"){",
333
+ "const m=this.__mdcuiUnidentifiedKeydown||{};",
334
+ "const letter=!m.altGraph&&(m.ctrlKey||m.altKey||m.metaKey)&&m.keyCode>=65&&m.keyCode<=90?String.fromCharCode(m.keyCode+(m.shiftKey?0:32)):String(event.data);",
335
+ "Object.defineProperties(event,{key:{configurable:true,value:letter},ctrlKey:{configurable:true,value:!!m.ctrlKey},shiftKey:{configurable:true,value:!!m.shiftKey},altKey:{configurable:true,value:!!m.altKey},metaKey:{configurable:true,value:!!m.metaKey}});",
336
+ "this.onkeydown(event)",
337
+ "}",
338
+ ].join("")
339
+ : "";
340
+ const inlineEventAttrs = [
341
+ keydownCode ? `onkeydown="${escapeHtmlAttribute(keydownCode)}"` : "",
342
+ beforeInputCode ? `onbeforeinput="${escapeHtmlAttribute(beforeInputCode)}"` : "",
343
+ inputHandler
344
+ ? `oninput="${escapeHtmlAttribute(inlineFenceEventCode(inputHandler))}"`
345
+ : "",
346
+ ];
347
+ const attrs = [
348
+ `data-mdcui-tag="${identity.tag}"`,
349
+ `data-mdcui-language="${escapeHtmlAttribute(info)}"`,
350
+ identity.id ? `id="${escapeHtmlAttribute(identity.id)}"` : "",
351
+ ...inlineEventAttrs,
352
+ `class="${escapeHtmlAttribute([
353
+ `language-${info}`,
354
+ ...identity.classes,
355
+ ].join(" "))}"`,
356
+ `rows="${Math.max(1, contentLines.length)}"`,
357
+ `cols="${cols}"`,
358
+ 'wrap="soft"',
359
+ 'style="box-sizing:border-box;max-width:100%;width:100%;resize:vertical;overflow-y:hidden"',
360
+ ].filter(Boolean).join(" ");
361
+ return `<textarea ${attrs}>${value}</textarea>`;
362
+ },
363
+ );
364
+ }
365
+
366
+ let wuiGraphemeSegmenter;
367
+ function firstWuiGraphemeCluster(value)
368
+ {
369
+ const input = String(value ?? "");
370
+ if (!input) return "";
371
+
372
+ if (wuiGraphemeSegmenter === undefined) {
373
+ try {
374
+ wuiGraphemeSegmenter = typeof Intl === "object"
375
+ && typeof Intl.Segmenter === "function"
376
+ ? new Intl.Segmenter(undefined, { granularity: "grapheme" })
377
+ : null;
378
+ } catch {
379
+ wuiGraphemeSegmenter = null;
380
+ }
381
+ }
382
+ const segmented = wuiGraphemeSegmenter
383
+ ?.segment(input)?.[Symbol.iterator]?.().next?.().value?.segment;
384
+ if (segmented) return segmented;
385
+
386
+ const points = [...input];
387
+ let result = points[0] ?? "";
388
+ let index = 1;
389
+ const isExtend = character => {
390
+ const point = character.codePointAt(0);
391
+ return /\p{Mark}/u.test(character)
392
+ || (point >= 0xFE00 && point <= 0xFE0F)
393
+ || (point >= 0xE0100 && point <= 0xE01EF)
394
+ || (point >= 0x1F3FB && point <= 0x1F3FF)
395
+ || (point >= 0xE0020 && point <= 0xE007F);
396
+ };
397
+ const isRegionalIndicator = character => {
398
+ const point = character?.codePointAt?.(0);
399
+ return point >= 0x1F1E6 && point <= 0x1F1FF;
400
+ };
401
+
402
+ if (isRegionalIndicator(points[0]) && isRegionalIndicator(points[1])) {
403
+ result += points[1];
404
+ index = 2;
405
+ }
406
+ while (index < points.length) {
407
+ if (isExtend(points[index])) {
408
+ result += points[index++];
409
+ continue;
410
+ }
411
+ if (points[index] === "\u200D" && index + 1 < points.length) {
412
+ result += points[index] + points[index + 1];
413
+ index += 2;
414
+ continue;
415
+ }
416
+ break;
417
+ }
418
+ return result;
419
+ }
420
+
421
+ function wuiHtmlTagAt(input, start)
422
+ {
423
+ if (input[start] !== "<") return null;
424
+ if (input.startsWith("<!--", start)) {
425
+ const commentEnd = input.indexOf("-->", start + 4);
426
+ return {
427
+ kind: "comment",
428
+ start,
429
+ end: commentEnd < 0 ? input.length : commentEnd + 3,
430
+ name: null,
431
+ closing: false,
432
+ selfClosing: false,
433
+ source: input.slice(start, commentEnd < 0 ? input.length : commentEnd + 3),
434
+ };
435
+ }
436
+ if (input.startsWith("<![CDATA[", start)) {
437
+ const close = input.indexOf("]]>", start + 9);
438
+ const end = close < 0 ? input.length : close + 3;
439
+ return {
440
+ kind: "comment",
441
+ start,
442
+ end,
443
+ name: null,
444
+ closing: false,
445
+ selfClosing: false,
446
+ source: input.slice(start, end),
447
+ };
448
+ }
449
+ if (input.startsWith("<?", start)) {
450
+ const close = input.indexOf("?>", start + 2);
451
+ const end = close < 0 ? input.length : close + 2;
452
+ return {
453
+ kind: "comment",
454
+ start,
455
+ end,
456
+ name: null,
457
+ closing: false,
458
+ selfClosing: false,
459
+ source: input.slice(start, end),
460
+ };
461
+ }
462
+
463
+ let quote = null;
464
+ let end = -1;
465
+ for (let index = start + 1; index < input.length; index++) {
466
+ const character = input[index];
467
+ if (quote) {
468
+ if (character === quote) quote = null;
469
+ continue;
470
+ }
471
+ if (character === '"' || character === "'") {
472
+ quote = character;
473
+ continue;
474
+ }
475
+ if (character === ">") {
476
+ end = index + 1;
477
+ break;
478
+ }
479
+ }
480
+ if (end < 0) return null;
481
+
482
+ const source = input.slice(start, end);
483
+ const closingMatch = source.match(
484
+ /^<\/([A-Za-z][A-Za-z0-9:-]*)(?=[\s>])/,
485
+ );
486
+ const openingMatch = closingMatch
487
+ ? null
488
+ : source.match(/^<([A-Za-z][A-Za-z0-9:-]*)(?=[\s/>])/);
489
+ return {
490
+ kind: closingMatch || openingMatch ? "tag" : "other",
491
+ start,
492
+ end,
493
+ name: String(closingMatch?.[1] ?? openingMatch?.[1] ?? "").toLowerCase() || null,
494
+ closing: Boolean(closingMatch),
495
+ selfClosing: Boolean(openingMatch && /\/\s*>$/.test(source)),
496
+ source,
497
+ };
498
+ }
499
+
500
+ function nextWuiHtmlTag(input, from)
501
+ {
502
+ let start = input.indexOf("<", from);
503
+ while (start >= 0) {
504
+ const token = wuiHtmlTagAt(input, start);
505
+ if (token?.kind !== "other") return token;
506
+ start = input.indexOf("<", start + 1);
507
+ }
508
+ return null;
509
+ }
510
+
511
+ function matchingWuiHtmlClose(input, opening)
512
+ {
513
+ if (opening?.kind !== "tag" || opening.closing || opening.selfClosing)
514
+ return null;
515
+ let depth = 1;
516
+ let scan = opening.end;
517
+ let token;
518
+ while ((token = nextWuiHtmlTag(input, scan))) {
519
+ scan = token.end;
520
+ if (token.kind !== "tag" || token.name !== opening.name) continue;
521
+ if (token.closing) {
522
+ depth--;
523
+ if (depth === 0) return token;
524
+ } else if (!token.selfClosing) {
525
+ depth++;
526
+ }
527
+ }
528
+ return null;
529
+ }
530
+
531
+ const WUI_HEADING_OPAQUE_TAGS = new Set([
532
+ "iframe",
533
+ "noembed",
534
+ "noframes",
535
+ "noscript",
536
+ "plaintext",
537
+ "script",
538
+ "style",
539
+ "textarea",
540
+ "template",
541
+ "title",
542
+ "xmp",
543
+ ]);
544
+ const WUI_RAW_TEXT_TAGS = new Set([
545
+ "iframe",
546
+ "noembed",
547
+ "noframes",
548
+ "noscript",
549
+ "plaintext",
550
+ "script",
551
+ "style",
552
+ "textarea",
553
+ "title",
554
+ "xmp",
555
+ ]);
556
+ const WUI_HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
557
+
558
+ function analyzeWuiHeadingHtml(value)
559
+ {
560
+ const input = String(value);
561
+ let headingAttribute = "data-mdcui-active-heading";
562
+ while (input.toLowerCase().includes(headingAttribute))
563
+ headingAttribute = "_" + headingAttribute;
564
+ let foreignAttribute = "data-mdcui-foreign-opaque";
565
+ while (
566
+ input.toLowerCase().includes(foreignAttribute)
567
+ || foreignAttribute === headingAttribute
568
+ ) foreignAttribute = "_" + foreignAttribute;
569
+
570
+ try {
571
+ let rewriter = new HTMLRewriter();
572
+ for (let level = 1; level <= 6; level++) {
573
+ rewriter = rewriter.on(`h${level}`, {
574
+ element(element) {
575
+ element.setAttribute(headingAttribute, "");
576
+ },
577
+ });
578
+ }
579
+ for (const tag of WUI_HEADING_OPAQUE_TAGS) {
580
+ rewriter = rewriter.on(tag, {
581
+ element(element) {
582
+ if (element.namespaceURI !== WUI_HTML_NAMESPACE)
583
+ element.setAttribute(foreignAttribute, "");
584
+ },
585
+ });
586
+ }
587
+ const transformed = rewriter.transform(new Response(input)).text();
588
+ const html = Bun.peek(transformed);
589
+ if (typeof html === "string") {
590
+ return {
591
+ html,
592
+ headingAttribute,
593
+ foreignAttribute,
594
+ ok: true,
595
+ };
596
+ }
597
+ } catch {}
598
+ return {
599
+ html: input,
600
+ headingAttribute,
601
+ foreignAttribute,
602
+ ok: false,
603
+ };
604
+ }
605
+
606
+ function stripWuiAnalysisAttributes(value, analysis)
607
+ {
608
+ let output = String(value);
609
+ if (!analysis?.ok) return output;
610
+ for (const attribute of [
611
+ analysis.headingAttribute,
612
+ analysis.foreignAttribute,
613
+ ]) {
614
+ output = output.replace(
615
+ new RegExp(`[\\t\\n\\f\\r ]+${attribute}=""`, "giu"),
616
+ "",
617
+ );
618
+ }
619
+ return output;
620
+ }
621
+
622
+ function wuiTokenHasAnalysisAttribute(token, attribute)
623
+ {
624
+ return Boolean(
625
+ token?.kind === "tag"
626
+ && token.source.toLowerCase().includes(` ${attribute.toLowerCase()}=""`),
627
+ );
628
+ }
629
+
630
+ function closingWuiOpaqueTag(input, opening)
631
+ {
632
+ if (opening?.name === "plaintext") return null;
633
+ if (!WUI_RAW_TEXT_TAGS.has(opening?.name))
634
+ return matchingWuiHtmlClose(input, opening);
635
+
636
+ const closingPattern = new RegExp(
637
+ `</${opening.name}(?=[\\s>])`,
638
+ "ig",
639
+ );
640
+ closingPattern.lastIndex = opening.end;
641
+ let match;
642
+ while ((match = closingPattern.exec(input)) !== null) {
643
+ const token = wuiHtmlTagAt(input, match.index);
644
+ if (token?.kind === "tag" && token.closing)
645
+ return token;
646
+ closingPattern.lastIndex = match.index + 2;
647
+ }
648
+ return null;
649
+ }
650
+
651
+ function wuiOpaqueRange(input, token, analysis)
652
+ {
653
+ const closing = token.selfClosing
654
+ ? token
655
+ : closingWuiOpaqueTag(input, token);
656
+ const end = closing?.end ?? input.length;
657
+ const foreign = wuiTokenHasAnalysisAttribute(
658
+ token,
659
+ analysis?.foreignAttribute,
660
+ );
661
+ const containsActiveHeading = analysis?.ok
662
+ && input.slice(token.end, end).toLowerCase().includes(
663
+ ` ${analysis.headingAttribute.toLowerCase()}=""`,
664
+ );
665
+ return {
666
+ end,
667
+ protect: token.name === "template"
668
+ ? !foreign
669
+ : !foreign && !containsActiveHeading,
670
+ };
671
+ }
672
+
673
+ function wuiDocumentBodyBoundary(input, analysis)
674
+ {
675
+ const bodyOpaqueTags = new Set([...WUI_HEADING_OPAQUE_TAGS, "code"]);
676
+ let opening = null;
677
+ let scan = 0;
678
+ let token;
679
+ while ((token = nextWuiHtmlTag(input, scan))) {
680
+ scan = token.end;
681
+ if (token.kind !== "tag") continue;
682
+
683
+ if (
684
+ !token.closing
685
+ && bodyOpaqueTags.has(token.name)
686
+ ) {
687
+ if (!WUI_HEADING_OPAQUE_TAGS.has(token.name)) {
688
+ if (!token.selfClosing) {
689
+ const closing = closingWuiOpaqueTag(input, token);
690
+ scan = closing?.end ?? input.length;
691
+ }
692
+ continue;
693
+ }
694
+ const opaque = wuiOpaqueRange(input, token, analysis);
695
+ if (opaque.protect) {
696
+ scan = opaque.end;
697
+ continue;
698
+ }
699
+ }
700
+ if (!opening && !token.closing && token.name === "body") {
701
+ opening = token;
702
+ continue;
703
+ }
704
+ if (opening && token.closing && token.name === "body")
705
+ return { opening, closing: token };
706
+ }
707
+ return null;
708
+ }
709
+
710
+ function protectWuiHeadingOpaqueHtml(
711
+ input,
712
+ markerPrefix,
713
+ analysis,
714
+ )
715
+ {
716
+ const opaqueHtml = [];
717
+ let searchable = "";
718
+ let cursor = 0;
719
+ let scan = 0;
720
+ let token;
721
+
722
+ while ((token = nextWuiHtmlTag(input, scan))) {
723
+ scan = token.end;
724
+ let end = null;
725
+ if (token.kind === "comment") {
726
+ end = token.end;
727
+ } else if (
728
+ token.kind === "tag"
729
+ && !token.closing
730
+ && WUI_HEADING_OPAQUE_TAGS.has(token.name)
731
+ ) {
732
+ const opaque = wuiOpaqueRange(input, token, analysis);
733
+ if (opaque.protect) end = opaque.end;
734
+ }
735
+ if (end == null) continue;
736
+
737
+ const marker = `\0${markerPrefix}${opaqueHtml.length}\0`;
738
+ searchable += input.slice(cursor, token.start) + marker;
739
+ opaqueHtml.push({ marker, html: input.slice(token.start, end) });
740
+ cursor = end;
741
+ scan = end;
742
+ }
743
+
744
+ searchable += input.slice(cursor);
745
+ return { searchable, opaqueHtml };
746
+ }
747
+
748
+ function wuiHtmlTagAttributeValue(token, expectedName)
749
+ {
750
+ if (token?.kind !== "tag" || token.closing) return undefined;
751
+ const input = token.source;
752
+ const opening = input.match(/^<[^\s/>]+/);
753
+ if (!opening) return undefined;
754
+ let index = opening[0].length;
755
+
756
+ while (index < input.length) {
757
+ while (/\s/u.test(input[index] ?? "")) index++;
758
+ if (input[index] === ">" || input[index] === "/" || index >= input.length)
759
+ return undefined;
760
+
761
+ const start = index;
762
+ while (index < input.length && !/[\s=/>]/u.test(input[index])) index++;
763
+ const name = input.slice(start, index).toLowerCase();
764
+ while (/\s/u.test(input[index] ?? "")) index++;
765
+
766
+ if (input[index] !== "=") {
767
+ if (name === expectedName.toLowerCase()) return "";
768
+ continue;
769
+ }
770
+ index++;
771
+ while (/\s/u.test(input[index] ?? "")) index++;
772
+ const quote = input[index] === '"' || input[index] === "'"
773
+ ? input[index++]
774
+ : null;
775
+ const valueStart = index;
776
+ if (quote) {
777
+ while (index < input.length && input[index] !== quote) index++;
778
+ const value = input.slice(valueStart, index);
779
+ if (input[index] === quote) index++;
780
+ if (name === expectedName.toLowerCase()) return value;
781
+ } else {
782
+ while (index < input.length && !/[\s>]/u.test(input[index])) index++;
783
+ if (name === expectedName.toLowerCase())
784
+ return input.slice(valueStart, index);
785
+ }
786
+ }
787
+ return undefined;
788
+ }
789
+
790
+ function wrapWuiHeadingToggleCharacter(headingHtml)
791
+ {
792
+ const input = String(headingHtml);
793
+ const opening = wuiHtmlTagAt(input, 0);
794
+ if (
795
+ opening?.kind !== "tag"
796
+ || opening.closing
797
+ || !/^h[1-6]$/.test(opening.name ?? "")
798
+ || !wuiHtmlTagAttributeValue(opening, "id")
799
+ ) return input;
800
+
801
+ let index = opening.end;
802
+ while (index < input.length) {
803
+ if (input[index] === "\0") {
804
+ const markerEnd = input.indexOf("\0", index + 1);
805
+ if (markerEnd < 0) return input;
806
+ index = markerEnd + 1;
807
+ continue;
808
+ }
809
+ if (input[index] === "<") {
810
+ const tag = wuiHtmlTagAt(input, index);
811
+ if (!tag) return input;
812
+ if (tag.kind === "other") {
813
+ index++;
814
+ continue;
815
+ }
816
+ index = tag.end;
817
+ continue;
818
+ }
819
+ if (/\s/u.test(input[index])) {
820
+ index++;
821
+ continue;
822
+ }
823
+
824
+ let end;
825
+ if (input[index] === "&") {
826
+ const reference = readLeadingHtmlCharacterReference(
827
+ input.slice(index),
828
+ );
829
+ if (reference && /^\s+$/u.test(reference.decoded)) {
830
+ index += reference.source.length;
831
+ continue;
832
+ }
833
+ end = index + (reference?.source.length ?? 1);
834
+ } else {
835
+ const grapheme = firstWuiGraphemeCluster(input.slice(index));
836
+ end = index + grapheme.length;
837
+ }
838
+ return input.slice(0, index) +
839
+ '<span class="mdcui-heading-toggle" role="button" tabindex="0" aria-expanded="true">' +
840
+ input.slice(index, end) +
841
+ "</span>" +
842
+ input.slice(end);
843
+ }
844
+ return input;
845
+ }
846
+
847
+ export function wrapWuiHeadingSections(html)
848
+ {
849
+ const analysis = analyzeWuiHeadingHtml(html);
850
+ const input = analysis.html;
851
+ const body = wuiDocumentBodyBoundary(input, analysis);
852
+ if (body) {
853
+ const contentStart = body.opening.end;
854
+ const contentEnd = body.closing.start;
855
+ return stripWuiAnalysisAttributes(
856
+ input.slice(0, contentStart) +
857
+ wrapWuiHeadingSections(input.slice(contentStart, contentEnd)) +
858
+ input.slice(contentEnd),
859
+ analysis,
860
+ );
861
+ }
862
+
863
+ let markerPrefix = "MDCUI_HEADING_OPAQUE_";
864
+ while (input.includes(markerPrefix)) markerPrefix = "_" + markerPrefix;
865
+ const { searchable, opaqueHtml } =
866
+ protectWuiHeadingOpaqueHtml(
867
+ input,
868
+ markerPrefix,
869
+ analysis,
870
+ );
871
+
872
+ const voidTags = new Set([
873
+ "area",
874
+ "base",
875
+ "br",
876
+ "col",
877
+ "embed",
878
+ "hr",
879
+ "img",
880
+ "input",
881
+ "link",
882
+ "meta",
883
+ "param",
884
+ "source",
885
+ "track",
886
+ "wbr",
887
+ ]);
888
+ const containers = [{ name: null, openLevels: [] }];
889
+ let output = "";
890
+ let cursor = 0;
891
+ let scan = 0;
892
+ let codeDepth = 0;
893
+ let token;
894
+
895
+ const closeContainerSections = (container, position) => {
896
+ if (!container?.openLevels.length) return;
897
+ output += searchable.slice(cursor, position);
898
+ cursor = position;
899
+ while (container.openLevels.length) {
900
+ output += "</section>\n";
901
+ container.openLevels.pop();
902
+ }
903
+ };
904
+
905
+ while ((token = nextWuiHtmlTag(searchable, scan))) {
906
+ scan = token.end;
907
+ if (token.kind !== "tag") continue;
908
+
909
+ if (token.closing) {
910
+ let match = -1;
911
+ for (let index = containers.length - 1; index > 0; index--) {
912
+ if (containers[index].name === token.name) {
913
+ match = index;
914
+ break;
915
+ }
916
+ }
917
+ if (match >= 0) {
918
+ for (let index = containers.length - 1; index >= match; index--)
919
+ closeContainerSections(containers[index], token.start);
920
+ containers.length = match;
921
+ }
922
+ if (token.name === "code")
923
+ codeDepth = Math.max(0, codeDepth - 1);
924
+ continue;
925
+ }
926
+
927
+ const headingMatch = (
928
+ codeDepth === 0
929
+ && (
930
+ !analysis.ok
931
+ || wuiTokenHasAnalysisAttribute(
932
+ token,
933
+ analysis.headingAttribute,
934
+ )
935
+ )
936
+ )
937
+ ? token.name?.match(/^h([1-6])$/)
938
+ : null;
939
+ if (headingMatch) {
940
+ const closing = matchingWuiHtmlClose(searchable, token);
941
+ if (!closing) continue;
942
+
943
+ const level = Number(headingMatch[1]);
944
+ const headingHtml = wrapWuiHeadingToggleCharacter(
945
+ searchable.slice(token.start, closing.end),
946
+ );
947
+ const container = containers.at(-1);
948
+ output += searchable.slice(cursor, token.start);
949
+ while (
950
+ container.openLevels.length
951
+ && container.openLevels.at(-1) >= level
952
+ ) {
953
+ output += "</section>\n";
954
+ container.openLevels.pop();
955
+ }
956
+ output += `<section>\n${headingHtml}`;
957
+ container.openLevels.push(level);
958
+ cursor = closing.end;
959
+ scan = closing.end;
960
+ continue;
961
+ }
962
+
963
+ if (token.name === "code" && !token.selfClosing) codeDepth++;
964
+ if (!token.selfClosing && !voidTags.has(token.name)) {
965
+ containers.push({ name: token.name, openLevels: [] });
966
+ }
967
+ }
968
+
969
+ for (let index = containers.length - 1; index >= 0; index--)
970
+ closeContainerSections(containers[index], searchable.length);
971
+ output += searchable.slice(cursor);
972
+ for (const opaque of opaqueHtml) {
973
+ output = output.replace(opaque.marker, opaque.html);
974
+ }
975
+ return stripWuiAnalysisAttributes(output, analysis);
976
+ }
977
+
978
+ export function convertWuiTableCheckboxes(html)
979
+ {
980
+ return String(html ?? "").replace(
981
+ /<table\b[^>]*>[\s\S]*?<\/table>/giu,
982
+ table => table
983
+ .replace(
984
+ /^<table\b([^>]*)>/iu,
985
+ (opening, attributes) =>
986
+ /\bcontenteditable\s*=/iu.test(attributes)
987
+ ? opening
988
+ : `<table${attributes} contenteditable="true">`,
989
+ )
990
+ .replace(
991
+ /(<t[dh]\b[^>]*>)(\s*)\[( |x|X)\]/giu,
992
+ (whole, opening, whitespace, state) =>
993
+ `${opening}${whitespace}<input type="checkbox"`
994
+ + `${state === " " ? "" : " checked"}>`,
995
+ ),
996
+ );
997
+ }
998
+
999
+ export async function createWui(md,mdpath,{ bundling = false } = {}) // HTML
1000
+ {
1001
+ const templates = renderMarkdownTemplateComponents(md, { mode: "wui" })
1002
+ md = templates.markdown
1003
+ const eventsById = fenceEventMap(md)
1004
+
1005
+ md = renderMarkdownWithHeadingIds(md).html;
1006
+ md = wrapWuiTemplateComponents(md, templates.idStore)
1007
+
1008
+ // Restore single quotes
1009
+ let reHrefs = /href="[^"]*?"/g // "
1010
+ md = md.replace( reHrefs,
1011
+ i=>i.replaceAll('&#x27;',"'")
1012
+ )
1013
+
1014
+
1015
+ md = md.replaceAll(
1016
+ 'class="task-list-item-checkbox" disabled',
1017
+ 'class="task-list-item-checkbox"'
1018
+ )
1019
+ md = convertWuiTableCheckboxes(md)
1020
+
1021
+ const taskItemStart = '(<li\\b(?=[^>]*\\bclass="[^"]*\\btask-list-item\\b[^"]*")[^>]*>\\s*)'
1022
+ const taskCheckbox = '(<input\\b(?=[^>]*\\btype="checkbox")[^>]*>)'
1023
+ md = md.replace(
1024
+ new RegExp(taskItemStart + taskCheckbox + '([^<]*(?:<p>[^]*?<\\/p>[^<]*)*)', 'g'),
1025
+ (whole, itemStart, checkbox, content) => {
1026
+ if (!content.trim()) return whole
1027
+ return `${itemStart}<label>${checkbox}${content}</label>`
1028
+ }
1029
+ )
1030
+
1031
+ md = convertWuiTextareas(md, eventsById)
1032
+ md = wrapWuiHeadingSections(md)
1033
+
1034
+ const mdb = path.basename(mdpath);
1035
+
1036
+ const responsiveImageStyle = `<style>
1037
+ img {
1038
+ max-width: 100%;
1039
+ height: auto;
1040
+ }
1041
+
1042
+ table {
1043
+ border-collapse: collapse;
1044
+ }
1045
+
1046
+ th, td {
1047
+ border: 1px solid black;
1048
+ padding: 4px 8px;
1049
+ }
1050
+
1051
+ th {
1052
+ background: #ddd;
1053
+ }
1054
+
1055
+ tr:nth-child(even) {
1056
+ background: #ddd;
1057
+ }
1058
+
1059
+ tr:hover {
1060
+ background: #ddddee;
1061
+ }
1062
+ </style>`;
1063
+ const moduleEntry = bundling ? `${mdb}.tmpfi.js` : `${mdb}.front.js`;
1064
+ const templatePayload = JSON.stringify(
1065
+ [...templates.idStore].map(([id, record]) => ({
1066
+ id,
1067
+ data: record.data,
1068
+ components: record.components.map(component => ({
1069
+ source: component.source,
1070
+ templateType: component.templateType,
1071
+ last: component.last,
1072
+ id: component.id,
1073
+ index: component.index,
1074
+ initialData: component.initialData,
1075
+ })),
1076
+ })),
1077
+ ).replaceAll("<", "\\u003c");
1078
+ const templateScript = `<scr`+`ipt type="application/json" id="mdcui-template-components">${templatePayload}</scr`+`ipt>`;
1079
+ const moduleScript = `<scr`+`ipt type="module" src="./${moduleEntry}"></scr`+`ipt>`;
1080
+ const isFullHtmlDocument = /^\s*<!doctype html>/i.test(md);
1081
+ if (!isFullHtmlDocument) {
1082
+ md = `<!doctype html>
1083
+ <html lang="zh-TW">
1084
+ <head>
1085
+ <meta charset="utf-8">
1086
+ <meta name="viewport" content="width=device-width, initial-scale=1">
1087
+ <title>${escapeHtmlAttribute(mdb)}</title>
1088
+ ${responsiveImageStyle}
1089
+ </head>
1090
+ <body>
1091
+ ${md}
1092
+ ${templateScript}
1093
+ ${moduleScript}
1094
+ </body>
1095
+ </html>
1096
+ `;
1097
+ } else {
1098
+ if (/<\/head\s*>/i.test(md)) {
1099
+ md = md.replace(/<\/head\s*>/i, `${responsiveImageStyle}\n</head>`);
1100
+ } else {
1101
+ md = `${responsiveImageStyle}\n${md}`;
1102
+ }
1103
+ if (/<\/body\s*>/i.test(md)) {
1104
+ md = md.replace(/<\/body\s*>/i, `${templateScript}\n${moduleScript}\n</body>`);
1105
+ } else {
1106
+ md += `\n${templateScript}\n${moduleScript}\n`;
1107
+ }
1108
+ }
1109
+
1110
+ md = annotateWuiImageSources(md)
1111
+
1112
+ await Bun.write(mdpath+".html",md)
1113
+ logWroteFile("html", mdpath+".html")
1114
+
1115
+ return md;
1116
+ }
1117
+
1118
+ function annotateWuiImageSources(html)
1119
+ {
1120
+ return String(html).replace(/<img\b[^>]*>/gi, tag => {
1121
+ if (/\bdata-mdcui-src\s*=/i.test(tag)) return tag
1122
+ const src = tag.match(/\bsrc\s*=\s*(["'])(.*?)\1/i)
1123
+ if (!src) return tag
1124
+ const attribute = ` data-mdcui-src=${src[1]}${src[2]}${src[1]}`
1125
+ return tag.replace(/\s*\/?>$/, ending => `${attribute}${ending}`)
1126
+ })
1127
+ }
1128
+
1129
+ export function charFromPoint(tui,row,col)
1130
+ {
1131
+ tui = tui.split('\n')[row-1] || ""
1132
+ return Bun.sliceAnsi(tui,col-1,col)
1133
+ }
1134
+
1135
+
1136
+ if(import.meta.main)
1137
+ main().catch(e=>{
1138
+ console.error(e?.message || e)
1139
+ process.exit(127)
1140
+ });