repl-sdk 0.0.0 → 1.0.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 (305) hide show
  1. package/dist/apl-fqmucPXA.js +141 -0
  2. package/dist/apl-fqmucPXA.js.map +1 -0
  3. package/dist/asciiarmor-DucZyvP0.js +57 -0
  4. package/dist/asciiarmor-DucZyvP0.js.map +1 -0
  5. package/dist/asn1-BnOEsgAm.js +145 -0
  6. package/dist/asn1-BnOEsgAm.js.map +1 -0
  7. package/dist/assets/tar-worker-CxTcoQcr.js +593 -0
  8. package/dist/assets/tar-worker-CxTcoQcr.js.map +1 -0
  9. package/dist/asterisk-QAlztEwS.js +346 -0
  10. package/dist/asterisk-QAlztEwS.js.map +1 -0
  11. package/dist/brainfuck-DZVCuF_t.js +54 -0
  12. package/dist/brainfuck-DZVCuF_t.js.map +1 -0
  13. package/dist/clike-CTYGlS6x.js +800 -0
  14. package/dist/clike-CTYGlS6x.js.map +1 -0
  15. package/dist/clojure-BhXMqnxz.js +850 -0
  16. package/dist/clojure-BhXMqnxz.js.map +1 -0
  17. package/dist/cmake-BGaNd9E7.js +72 -0
  18. package/dist/cmake-BGaNd9E7.js.map +1 -0
  19. package/dist/cobol-4yqQntpt.js +121 -0
  20. package/dist/cobol-4yqQntpt.js.map +1 -0
  21. package/dist/codemirror-De3S70Np.js +2912 -0
  22. package/dist/codemirror-De3S70Np.js.map +1 -0
  23. package/dist/coffeescript-D2dXvhEc.js +309 -0
  24. package/dist/coffeescript-D2dXvhEc.js.map +1 -0
  25. package/dist/commonlisp-CF_VNHQR.js +131 -0
  26. package/dist/commonlisp-CF_VNHQR.js.map +1 -0
  27. package/dist/crystal-DyuLTqLs.js +399 -0
  28. package/dist/crystal-DyuLTqLs.js.map +1 -0
  29. package/dist/css-DkSyTW67.js +1773 -0
  30. package/dist/css-DkSyTW67.js.map +1 -0
  31. package/dist/cypher-Dlu_3r4V.js +122 -0
  32. package/dist/cypher-Dlu_3r4V.js.map +1 -0
  33. package/dist/d-UURgV0Ux.js +180 -0
  34. package/dist/d-UURgV0Ux.js.map +1 -0
  35. package/dist/diff-B_Bi2Crb.js +26 -0
  36. package/dist/diff-B_Bi2Crb.js.map +1 -0
  37. package/dist/dockerfile-Bvk733Ga.js +202 -0
  38. package/dist/dockerfile-Bvk733Ga.js.map +1 -0
  39. package/dist/dtd-Dy74G54E.js +115 -0
  40. package/dist/dtd-Dy74G54E.js.map +1 -0
  41. package/dist/dylan-TSb-Nfix.js +315 -0
  42. package/dist/dylan-TSb-Nfix.js.map +1 -0
  43. package/dist/ebnf-4fKAGW3a.js +141 -0
  44. package/dist/ebnf-4fKAGW3a.js.map +1 -0
  45. package/dist/ecl-B59qGGVg.js +179 -0
  46. package/dist/ecl-B59qGGVg.js.map +1 -0
  47. package/dist/eiffel-Dze7nlu3.js +135 -0
  48. package/dist/eiffel-Dze7nlu3.js.map +1 -0
  49. package/dist/elm-DG7jkhNZ.js +177 -0
  50. package/dist/elm-DG7jkhNZ.js.map +1 -0
  51. package/dist/erlang-BO6gOnGA.js +675 -0
  52. package/dist/erlang-BO6gOnGA.js.map +1 -0
  53. package/dist/factor-CMxFHDqz.js +66 -0
  54. package/dist/factor-CMxFHDqz.js.map +1 -0
  55. package/dist/fcl-CDDUNjTj.js +142 -0
  56. package/dist/fcl-CDDUNjTj.js.map +1 -0
  57. package/dist/forth-B9D2JCeE.js +117 -0
  58. package/dist/forth-B9D2JCeE.js.map +1 -0
  59. package/dist/fortran-CAG2BFbe.js +468 -0
  60. package/dist/fortran-CAG2BFbe.js.map +1 -0
  61. package/dist/gas-0Aw8zDr5.js +294 -0
  62. package/dist/gas-0Aw8zDr5.js.map +1 -0
  63. package/dist/gherkin-DhZlEZiy.js +116 -0
  64. package/dist/gherkin-DhZlEZiy.js.map +1 -0
  65. package/dist/gjs-DfguZDLq.js +173 -0
  66. package/dist/gjs-DfguZDLq.js.map +1 -0
  67. package/dist/gmd-Yas-Oo8k.js +163 -0
  68. package/dist/gmd-Yas-Oo8k.js.map +1 -0
  69. package/dist/groovy-CpwJiBl7.js +224 -0
  70. package/dist/groovy-CpwJiBl7.js.map +1 -0
  71. package/dist/haskell-ySd-OUo8.js +460 -0
  72. package/dist/haskell-ySd-OUo8.js.map +1 -0
  73. package/dist/haxe-7MlzfeYV.js +515 -0
  74. package/dist/haxe-7MlzfeYV.js.map +1 -0
  75. package/dist/hbs-CxcmWxSJ.js +62 -0
  76. package/dist/hbs-CxcmWxSJ.js.map +1 -0
  77. package/dist/http-BqypyemW.js +80 -0
  78. package/dist/http-BqypyemW.js.map +1 -0
  79. package/dist/idl-4HIGJlDI.js +986 -0
  80. package/dist/idl-4HIGJlDI.js.map +1 -0
  81. package/dist/index-B3Meoznj.js +118 -0
  82. package/dist/index-B3Meoznj.js.map +1 -0
  83. package/dist/index-BQyfDUUx.js +692 -0
  84. package/dist/index-BQyfDUUx.js.map +1 -0
  85. package/dist/index-BRDroAD8.js +305 -0
  86. package/dist/index-BRDroAD8.js.map +1 -0
  87. package/dist/index-BRMAzRyM.js +179 -0
  88. package/dist/index-BRMAzRyM.js.map +1 -0
  89. package/dist/index-Bb8uYQgv.js +927 -0
  90. package/dist/index-Bb8uYQgv.js.map +1 -0
  91. package/dist/index-BlOjO66K.js +17618 -0
  92. package/dist/index-BlOjO66K.js.map +1 -0
  93. package/dist/index-BoGWnSNL.js +706 -0
  94. package/dist/index-BoGWnSNL.js.map +1 -0
  95. package/dist/index-BsRrEiOu.js +98 -0
  96. package/dist/index-BsRrEiOu.js.map +1 -0
  97. package/dist/index-C2sFZMth.js +391 -0
  98. package/dist/index-C2sFZMth.js.map +1 -0
  99. package/dist/index-C7xwOjmS.js +291 -0
  100. package/dist/index-C7xwOjmS.js.map +1 -0
  101. package/dist/index-CA3lFUx6.js +315 -0
  102. package/dist/index-CA3lFUx6.js.map +1 -0
  103. package/dist/index-CB-pPTIf.js +98 -0
  104. package/dist/index-CB-pPTIf.js.map +1 -0
  105. package/dist/index-CCa6x1FE.js +386 -0
  106. package/dist/index-CCa6x1FE.js.map +1 -0
  107. package/dist/index-CD4DINI1.js +158 -0
  108. package/dist/index-CD4DINI1.js.map +1 -0
  109. package/dist/index-CE0B_fcG.js +328 -0
  110. package/dist/index-CE0B_fcG.js.map +1 -0
  111. package/dist/index-CVGAEPMV.js +2139 -0
  112. package/dist/index-CVGAEPMV.js.map +1 -0
  113. package/dist/index-CmaT2afn.js +332 -0
  114. package/dist/index-CmaT2afn.js.map +1 -0
  115. package/dist/index-D8sUxXp5.js +83 -0
  116. package/dist/index-D8sUxXp5.js.map +1 -0
  117. package/dist/index-DIz8Vpn-.js +737 -0
  118. package/dist/index-DIz8Vpn-.js.map +1 -0
  119. package/dist/index-DNP1xT-S.js +408 -0
  120. package/dist/index-DNP1xT-S.js.map +1 -0
  121. package/dist/index-DOAqdvnQ.js +862 -0
  122. package/dist/index-DOAqdvnQ.js.map +1 -0
  123. package/dist/index-DVUMFbgi.js +152 -0
  124. package/dist/index-DVUMFbgi.js.map +1 -0
  125. package/dist/index-VeTBKRVd.js +83 -0
  126. package/dist/index-VeTBKRVd.js.map +1 -0
  127. package/dist/index-dXZeR7Bx.js +1767 -0
  128. package/dist/index-dXZeR7Bx.js.map +1 -0
  129. package/dist/index-gtqbIb6T.js +62 -0
  130. package/dist/index-gtqbIb6T.js.map +1 -0
  131. package/dist/index-pN_pUAQ7.js +2426 -0
  132. package/dist/index-pN_pUAQ7.js.map +1 -0
  133. package/dist/index-wasu5VX0.js +1150 -0
  134. package/dist/index-wasu5VX0.js.map +1 -0
  135. package/dist/javascript-Bt8B7yTi.js +993 -0
  136. package/dist/javascript-Bt8B7yTi.js.map +1 -0
  137. package/dist/julia-Bs6JJhYG.js +408 -0
  138. package/dist/julia-Bs6JJhYG.js.map +1 -0
  139. package/dist/livescript-DmzgM3Yt.js +297 -0
  140. package/dist/livescript-DmzgM3Yt.js.map +1 -0
  141. package/dist/lua-8cJgIlqe.js +257 -0
  142. package/dist/lua-8cJgIlqe.js.map +1 -0
  143. package/dist/mathematica-DNLOL9PQ.js +111 -0
  144. package/dist/mathematica-DNLOL9PQ.js.map +1 -0
  145. package/dist/mbox-Ga7d4MMN.js +118 -0
  146. package/dist/mbox-Ga7d4MMN.js.map +1 -0
  147. package/dist/mirc-Dma3B8rS.js +108 -0
  148. package/dist/mirc-Dma3B8rS.js.map +1 -0
  149. package/dist/mllike-DHn7xckP.js +335 -0
  150. package/dist/mllike-DHn7xckP.js.map +1 -0
  151. package/dist/modelica-0d55jYY0.js +148 -0
  152. package/dist/modelica-0d55jYY0.js.map +1 -0
  153. package/dist/mscgen-DdqZYINH.js +136 -0
  154. package/dist/mscgen-DdqZYINH.js.map +1 -0
  155. package/dist/mumps-Btr8VblO.js +94 -0
  156. package/dist/mumps-Btr8VblO.js.map +1 -0
  157. package/dist/nginx-DTDtBDVN.js +142 -0
  158. package/dist/nginx-DTDtBDVN.js.map +1 -0
  159. package/dist/nsis-3zG7tgur.js +63 -0
  160. package/dist/nsis-3zG7tgur.js.map +1 -0
  161. package/dist/ntriples-CvgOYMpL.js +154 -0
  162. package/dist/ntriples-CvgOYMpL.js.map +1 -0
  163. package/dist/octave-DYBj3-tl.js +201 -0
  164. package/dist/octave-DYBj3-tl.js.map +1 -0
  165. package/dist/oz-R_e8WMIi.js +232 -0
  166. package/dist/oz-R_e8WMIi.js.map +1 -0
  167. package/dist/parse-CAqQaKsh.js +21685 -0
  168. package/dist/parse-CAqQaKsh.js.map +1 -0
  169. package/dist/pascal-GD8iposT.js +106 -0
  170. package/dist/pascal-GD8iposT.js.map +1 -0
  171. package/dist/perl-DL9mHpoi.js +1106 -0
  172. package/dist/perl-DL9mHpoi.js.map +1 -0
  173. package/dist/pig-C_4T4YIV.js +102 -0
  174. package/dist/pig-C_4T4YIV.js.map +1 -0
  175. package/dist/powershell-B0suO7Vd.js +329 -0
  176. package/dist/powershell-B0suO7Vd.js.map +1 -0
  177. package/dist/properties-BR-vP1aU.js +59 -0
  178. package/dist/properties-BR-vP1aU.js.map +1 -0
  179. package/dist/protobuf-BxgpyhoW.js +78 -0
  180. package/dist/protobuf-BxgpyhoW.js.map +1 -0
  181. package/dist/pug-vHnWR0UE.js +406 -0
  182. package/dist/pug-vHnWR0UE.js.map +1 -0
  183. package/dist/puppet-Bdao66PW.js +138 -0
  184. package/dist/puppet-Bdao66PW.js.map +1 -0
  185. package/dist/python-BFGRmuZ9.js +427 -0
  186. package/dist/python-BFGRmuZ9.js.map +1 -0
  187. package/dist/q-CrbCVq4a.js +132 -0
  188. package/dist/q-CrbCVq4a.js.map +1 -0
  189. package/dist/r-V7nswm59.js +171 -0
  190. package/dist/r-V7nswm59.js.map +1 -0
  191. package/dist/render-app-island-B-i8rvGi.js +61 -0
  192. package/dist/render-app-island-B-i8rvGi.js.map +1 -0
  193. package/dist/repl-sdk.js +7 -0
  194. package/dist/repl-sdk.js.map +1 -0
  195. package/dist/rpm-C-DLY-If.js +110 -0
  196. package/dist/rpm-C-DLY-If.js.map +1 -0
  197. package/dist/ruby-JDKLJNK0.js +331 -0
  198. package/dist/ruby-JDKLJNK0.js.map +1 -0
  199. package/dist/sas-D2UG-yhZ.js +208 -0
  200. package/dist/sas-D2UG-yhZ.js.map +1 -0
  201. package/dist/scheme-BKzrkGJD.js +223 -0
  202. package/dist/scheme-BKzrkGJD.js.map +1 -0
  203. package/dist/shell-BlsXDxCn.js +223 -0
  204. package/dist/shell-BlsXDxCn.js.map +1 -0
  205. package/dist/sieve-CjwBwOY5.js +136 -0
  206. package/dist/sieve-CjwBwOY5.js.map +1 -0
  207. package/dist/simple-mode-DMneyfDu.js +131 -0
  208. package/dist/simple-mode-DMneyfDu.js.map +1 -0
  209. package/dist/smalltalk-BOIGQuhN.js +122 -0
  210. package/dist/smalltalk-BOIGQuhN.js.map +1 -0
  211. package/dist/solr-CwD7U71z.js +70 -0
  212. package/dist/solr-CwD7U71z.js.map +1 -0
  213. package/dist/sparql-DYskk2vE.js +250 -0
  214. package/dist/sparql-DYskk2vE.js.map +1 -0
  215. package/dist/spreadsheet-Bgtt3oLP.js +88 -0
  216. package/dist/spreadsheet-Bgtt3oLP.js.map +1 -0
  217. package/dist/sql-Cei9CMfk.js +343 -0
  218. package/dist/sql-Cei9CMfk.js.map +1 -0
  219. package/dist/stex-C1nZSzAw.js +231 -0
  220. package/dist/stex-C1nZSzAw.js.map +1 -0
  221. package/dist/stylus-BkS-boTH.js +566 -0
  222. package/dist/stylus-BkS-boTH.js.map +1 -0
  223. package/dist/swift-FRZi1uvB.js +292 -0
  224. package/dist/swift-FRZi1uvB.js.map +1 -0
  225. package/dist/tcl-CUcaCdmq.js +115 -0
  226. package/dist/tcl-CUcaCdmq.js.map +1 -0
  227. package/dist/textile-BnFpjsrl.js +415 -0
  228. package/dist/textile-BnFpjsrl.js.map +1 -0
  229. package/dist/tiddlywiki-CjprD-Qp.js +219 -0
  230. package/dist/tiddlywiki-CjprD-Qp.js.map +1 -0
  231. package/dist/tiki-DK9DOeWn.js +269 -0
  232. package/dist/tiki-DK9DOeWn.js.map +1 -0
  233. package/dist/toml-BOuWGMcf.js +77 -0
  234. package/dist/toml-BOuWGMcf.js.map +1 -0
  235. package/dist/troff-E1bJ0PPL.js +62 -0
  236. package/dist/troff-E1bJ0PPL.js.map +1 -0
  237. package/dist/ttcn-cfg-Dc39-fIP.js +134 -0
  238. package/dist/ttcn-cfg-Dc39-fIP.js.map +1 -0
  239. package/dist/ttcn-tKd4HLu4.js +193 -0
  240. package/dist/ttcn-tKd4HLu4.js.map +1 -0
  241. package/dist/turtle-Dq7-1WAf.js +125 -0
  242. package/dist/turtle-Dq7-1WAf.js.map +1 -0
  243. package/dist/vb-Dp90gtsv.js +197 -0
  244. package/dist/vb-Dp90gtsv.js.map +1 -0
  245. package/dist/vbscript-Bfn8O8I7.js +479 -0
  246. package/dist/vbscript-Bfn8O8I7.js.map +1 -0
  247. package/dist/velocity-BwIZK1TH.js +150 -0
  248. package/dist/velocity-BwIZK1TH.js.map +1 -0
  249. package/dist/verilog-CnT9bMk0.js +430 -0
  250. package/dist/verilog-CnT9bMk0.js.map +1 -0
  251. package/dist/vhdl-DCkMIyT9.js +159 -0
  252. package/dist/vhdl-DCkMIyT9.js.map +1 -0
  253. package/dist/webidl-BTLTThCm.js +205 -0
  254. package/dist/webidl-BTLTThCm.js.map +1 -0
  255. package/dist/xquery-BrBUuxMR.js +526 -0
  256. package/dist/xquery-BrBUuxMR.js.map +1 -0
  257. package/dist/yacas-b5lAVEIl.js +131 -0
  258. package/dist/yacas-b5lAVEIl.js.map +1 -0
  259. package/dist/z80-ClgwfNdB.js +93 -0
  260. package/dist/z80-ClgwfNdB.js.map +1 -0
  261. package/package.json +81 -9
  262. package/src/cache.js +138 -0
  263. package/src/cdn.js +93 -0
  264. package/src/codemirror.js +161 -0
  265. package/src/compilers/ember/gjs.js +212 -0
  266. package/src/compilers/ember/gmd.js +190 -0
  267. package/src/compilers/ember/hbs.js +98 -0
  268. package/src/compilers/ember/render-app-island.js +83 -0
  269. package/src/compilers/ember.js +166 -0
  270. package/src/compilers/js.js +32 -0
  271. package/src/compilers/markdown/build-compiler.js +151 -0
  272. package/src/compilers/markdown/const.js +2 -0
  273. package/src/compilers/markdown/heading-id.js +75 -0
  274. package/src/compilers/markdown/live-code-extraction.js +198 -0
  275. package/src/compilers/markdown/parse.js +22 -0
  276. package/src/compilers/markdown/parse.test.ts +363 -0
  277. package/src/compilers/markdown/sanitize-for-glimmer.js +26 -0
  278. package/src/compilers/markdown/types.ts +21 -0
  279. package/src/compilers/markdown/utils.js +78 -0
  280. package/src/compilers/markdown.js +125 -0
  281. package/src/compilers/mermaid.js +35 -0
  282. package/src/compilers/react.js +59 -0
  283. package/src/compilers/svelte.js +116 -0
  284. package/src/compilers/vue.js +58 -0
  285. package/src/compilers.js +108 -0
  286. package/src/es-module-shim.js +53 -0
  287. package/src/index.d.ts +53 -4
  288. package/src/index.js +744 -89
  289. package/src/npm.js +58 -0
  290. package/src/request.Request.test.ts +59 -0
  291. package/src/request.js +140 -0
  292. package/src/resolve.fromImports.test.ts +35 -0
  293. package/src/resolve.fromInternalImport.test.ts +69 -0
  294. package/src/resolve.js +352 -0
  295. package/src/resolve.resolvePath.test.ts +24 -0
  296. package/src/resolve.test.ts +23 -0
  297. package/src/specifier.js +71 -0
  298. package/src/specifier.test.ts +90 -0
  299. package/src/tar-worker.js +61 -0
  300. package/src/tar.js +76 -0
  301. package/src/types.ts +335 -58
  302. package/src/utils.js +28 -1
  303. package/declarations/index.d.ts +0 -73
  304. package/dist/index.js +0 -107
  305. package/dist/index.js.map +0 -1
@@ -0,0 +1,83 @@
1
+ /** @type {any} */
2
+ let bootWaiter;
3
+ /** @type {any} */
4
+ let createWaiter;
5
+
6
+ /**
7
+ * Wait to boot the app until the Element is in the DOM.
8
+ * because This old way of making a whole app requires that the element
9
+ * be present in the app.
10
+ *
11
+ * We really need renderComponent(...)
12
+ * https://github.com/emberjs/ember.js/pull/20781
13
+ *
14
+ * @param {{
15
+ * element: Element,
16
+ * modules: { [name: string]: any},
17
+ * selector: string,
18
+ * log: (type: 'error' | 'info', message: string) => void;
19
+ * component: unknown
20
+ * }} options
21
+ */
22
+ export async function renderApp({ element, modules, selector, component, log }) {
23
+ const App = modules.application.default;
24
+ const registerDestructor = modules.destroyable.registerDestructor;
25
+ const destroy = modules.destroyable.destroy;
26
+ const Resolver = modules.resolver.default;
27
+ const Router = modules.router.default;
28
+ const Route = modules.route.default;
29
+ const schedule = modules.runloop.schedule;
30
+
31
+ bootWaiter ||= modules.testWaiters.buildWaiter('repl-output:waiting-for-boot');
32
+ createWaiter ||= modules.testWaiters.buildWaiter('repl-output:waiting-for-creation');
33
+
34
+ const bootToken = bootWaiter.beginAsync();
35
+ const createToken = createWaiter.beginAsync();
36
+
37
+ class EphemeralApp extends App {
38
+ modulePrefix = 'ephemeral-render-output';
39
+ rootElement = element;
40
+ Resolver = Resolver.withModules({
41
+ 'ephemeral-render-output/templates/application': { default: component },
42
+ 'ephemeral-render-output/routes/application': {
43
+ default: class Application extends Route {
44
+ /**
45
+ * @param {unknown[]} args
46
+ */
47
+ constructor(...args) {
48
+ super(...args);
49
+
50
+ registerDestructor(() => {
51
+ bootWaiter.endAsync(bootToken);
52
+ });
53
+ }
54
+ afterModel() {
55
+ schedule('afterRender', () => {
56
+ requestAnimationFrame(() => {
57
+ log('info', 'Ember Island Rendered');
58
+ bootWaiter.endAsync(bootToken);
59
+ createWaiter.endAsync(createToken);
60
+ });
61
+ });
62
+ }
63
+ },
64
+ },
65
+ 'ephemeral-render-output/router': {
66
+ default: class BoilerplateRouter extends Router {
67
+ location = 'none';
68
+ rootURL = '/';
69
+ },
70
+ },
71
+ });
72
+ }
73
+
74
+ log('info', 'Booting Ember Island');
75
+
76
+ const app = EphemeralApp.create({
77
+ rootElement: element,
78
+ });
79
+
80
+ return () => {
81
+ destroy(app);
82
+ };
83
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @typedef {import('../types.ts').CompilerConfig} CompilerConfig
3
+ */
4
+
5
+ /**
6
+ * Other `@ember` (and `@glimmer`) packages are bundled in ember-source,
7
+ * and typecilaly use a build plugin to resolve from `@ember/*` imports.
8
+ */
9
+ const externalPackages = [
10
+ '@ember/test-helpers',
11
+ '@ember/string',
12
+ '@ember/test-waiters',
13
+ '@ember/render-modifiers',
14
+ '@glimmer/component',
15
+ ];
16
+
17
+ /**
18
+ * @param {string} id
19
+ * @returns {string | undefined | (() => Record<string, unknown>)}
20
+ */
21
+ function resolve(id) {
22
+ if (id === '@ember/template-compiler/runtime') {
23
+ return `https://esm.sh/*ember-source/dist/packages/@ember/template-compiler/runtime.js`;
24
+ }
25
+
26
+ const isExternalEmber = externalPackages.some((name) => id.startsWith(name));
27
+
28
+ if (isExternalEmber) {
29
+ return `https://esm.sh/*${id}`;
30
+ }
31
+
32
+ if (id.startsWith('@ember')) {
33
+ return `https://esm.sh/*ember-source/dist/packages/${id}`;
34
+ }
35
+
36
+ if (id.startsWith('@glimmer')) {
37
+ return `https://esm.sh/*ember-source/dist/dependencies/${id}.js`;
38
+ }
39
+
40
+ if (id.startsWith('@embroider/macros')) {
41
+ return () => ({
42
+ // passthrough, we are not doing dead-code-elimination
43
+
44
+ /**
45
+ * @param {unknown} x
46
+ */
47
+ macroCondition: (x) => Boolean(x),
48
+ // I *could* actually implement this
49
+ dependencySatisfies: () => true,
50
+ isDevelopingApp: () => true,
51
+ getGlobalConfig: () => ({
52
+ WarpDrive: {
53
+ debug: false,
54
+ env: {
55
+ DEBUG: false,
56
+ TESTING: false,
57
+ PRODUCTION: true,
58
+ },
59
+ activeLogging: false,
60
+ compatWith: '99.0',
61
+ features: {},
62
+ deprecations: {},
63
+ polyfillUUID: false,
64
+ includeDataAdapter: false,
65
+ },
66
+ }),
67
+ });
68
+ }
69
+ }
70
+
71
+ /**
72
+ Example:
73
+
74
+ Uncaught (in promise) Error: Assertion Failed: You attempted to update `count` on `Demo`, but it had already been used previously in the same computation. Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.
75
+
76
+ `count` was first used:
77
+
78
+ - While rendering:
79
+ {{outlet}} for -top-level
80
+ -top-level
81
+ {{outlet}} for application
82
+ Demo
83
+ this.foos.value
84
+ this.foos
85
+
86
+ Stack trace for the update:
87
+ *
88
+ * @param {PromiseRejectionEvent} e
89
+ * @param {(message: string) => void} handle
90
+ */
91
+ function onUnhandled(e, handle) {
92
+ if (!e.reason?.message) return;
93
+
94
+ let reason = e.reason.message;
95
+
96
+ if (reason.includes('Stack trace for the update:')) {
97
+ reason += ' (see console)';
98
+ }
99
+
100
+ handle(reason);
101
+ }
102
+
103
+ /**
104
+ * @type {CompilerConfig}
105
+ */
106
+ export const gjs = {
107
+ resolve,
108
+ onUnhandled,
109
+ codemirror: {
110
+ lang: async () => {
111
+ const { gjs } = await import('codemirror-lang-glimmer-js');
112
+
113
+ return gjs();
114
+ },
115
+ },
116
+ compiler: async (...args) => {
117
+ const gjs = await import('./ember/gjs.js');
118
+
119
+ return gjs.compiler(...args);
120
+ },
121
+ };
122
+
123
+ /**
124
+ * @type {CompilerConfig}
125
+ */
126
+ export const hbs = {
127
+ resolve,
128
+ onUnhandled,
129
+ codemirror: {
130
+ lang: async () => {
131
+ const { glimmer } = await import('codemirror-lang-glimmer');
132
+
133
+ return glimmer();
134
+ },
135
+ },
136
+ compiler: async (...args) => {
137
+ const hbs = await import('./ember/hbs.js');
138
+
139
+ return hbs.compiler(...args);
140
+ },
141
+ };
142
+
143
+ /**
144
+ * @type {CompilerConfig}
145
+ */
146
+ export const gmd = {
147
+ resolve,
148
+ onUnhandled,
149
+ codemirror: {
150
+ lang: async () => {
151
+ const { glimdown } = await import('codemirror-lang-glimdown');
152
+
153
+ return glimdown();
154
+ },
155
+ support: async () => {
156
+ const { gjs } = await import('codemirror-lang-glimmer-js');
157
+
158
+ return [gjs().support];
159
+ },
160
+ },
161
+ compiler: async (...args) => {
162
+ const hbs = await import('./ember/gmd.js');
163
+
164
+ return hbs.compiler(...args);
165
+ },
166
+ };
@@ -0,0 +1,32 @@
1
+ import { assert } from '../utils.js';
2
+
3
+ /**
4
+ * @type {import('../types.ts').CompilerConfig}
5
+ */
6
+ export const js = {
7
+ codemirror: {
8
+ lang: async () => {
9
+ const { javascript } = await import('@codemirror/lang-javascript');
10
+
11
+ return javascript();
12
+ },
13
+ },
14
+ compiler: async (config, api) => {
15
+ return {
16
+ compile: async (text, options) => {
17
+ // No compiling needed. Just JS
18
+ return text;
19
+ },
20
+ render: async (element, fun, extra, compiler) => {
21
+ assert(
22
+ `js document must have a function for a default export. Instead received: ${typeof fun}`,
23
+ typeof fun === 'function'
24
+ );
25
+
26
+ await fun(element);
27
+
28
+ compiler.announce('info', 'Done');
29
+ },
30
+ };
31
+ },
32
+ };
@@ -0,0 +1,151 @@
1
+ /**
2
+ * @typedef {import('unified').Plugin} UPlugin
3
+ */
4
+ import rehypeRaw from 'rehype-raw';
5
+ import rehypeStringify from 'rehype-stringify';
6
+ import remarkGfm from 'remark-gfm';
7
+ import remarkParse from 'remark-parse';
8
+ import remarkRehype from 'remark-rehype';
9
+ import { unified } from 'unified';
10
+ import { visit } from 'unist-util-visit';
11
+
12
+ import { GLIMDOWN_PREVIEW, GLIMDOWN_RENDER } from './const.js';
13
+ import { headingId } from './heading-id.js';
14
+ import { liveCodeExtraction } from './live-code-extraction.js';
15
+ import { sanitizeForGlimmer } from './sanitize-for-glimmer.js';
16
+
17
+ /**
18
+ * @param {import('./types').InternalOptions} options
19
+ *
20
+ * @returns {import('unified').Processor<import('hast').Root>}
21
+ */
22
+ export function buildCompiler(options) {
23
+ let compiler = unified().use(remarkParse).use(remarkGfm, { singleTilde: true }).use(headingId);
24
+
25
+ /**
26
+ * If this were "use"d after `remarkRehype`,
27
+ * remark is gone, and folks would need to work with rehype trees
28
+ */
29
+ if (options.remarkPlugins) {
30
+ options.remarkPlugins.forEach((plugin) => {
31
+ // Arrays are how plugins are passed options (for some reason?)
32
+ // why not just invoke the the function?
33
+ if (Array.isArray(plugin)) {
34
+ // @ts-ignore - unified processor types are complex and change as plugins are added
35
+ compiler = compiler.use(plugin[0], ...plugin.slice(1));
36
+ } else {
37
+ // @ts-ignore - unified processor types are complex and change as plugins are added
38
+ compiler = compiler.use(plugin);
39
+ }
40
+ });
41
+ }
42
+
43
+ // TODO: we only want to do this when we have pre > code.
44
+ // code can exist inline.
45
+ // @ts-ignore - unified processor types are complex and change as plugins are added
46
+ compiler = compiler.use(liveCodeExtraction, {
47
+ code: {
48
+ classList: ['repl-sdk__snippet'],
49
+ ...options.code,
50
+ },
51
+ demo: {
52
+ classList: ['repl-sdk__demo'],
53
+ ...options.code,
54
+ },
55
+ isLive: options.isLive,
56
+ isPreview: options.isPreview,
57
+ isBelow: options.isBelow,
58
+ needsLive: options.needsLive,
59
+ ALLOWED_FORMATS: options.ALLOWED_FORMATS,
60
+ getFlavorFromMeta: options.getFlavorFromMeta,
61
+ });
62
+
63
+ // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))
64
+ // remark rehype is needed to convert markdown to HTML
65
+ // However, it also changes all the nodes, so we need another pass
66
+ // to make sure our Glimmer-aware nodes are in tact
67
+ // @ts-ignore - unified processor types are complex and change as plugins are added
68
+ compiler = compiler.use(remarkRehype, { allowDangerousHtml: true });
69
+
70
+ // Convert invocables to raw format, so Glimmer can invoke them
71
+ // @ts-ignore - unified processor types are complex and change as plugins are added
72
+ compiler = compiler.use(() => (/** @type {unknown} */ tree) => {
73
+ visit(/** @type {import('hast').Root} */ (tree), function (node) {
74
+ // We rely on an implicit transformation of data.hProperties => properties
75
+ const nodeObj = /** @type {Record<string, unknown>} */ (/** @type {unknown} */ (node));
76
+ const properties = /** @type {Record<string, unknown>} */ (
77
+ typeof node === 'object' && node !== null && 'properties' in node ? node.properties : {}
78
+ );
79
+
80
+ if (properties?.[/** @type {string} */ (/** @type {unknown} */ (GLIMDOWN_PREVIEW))]) {
81
+ return 'skip';
82
+ }
83
+
84
+ if (nodeObj.type === 'element' || ('tagName' in nodeObj && nodeObj.tagName === 'code')) {
85
+ if (properties?.[/** @type {string} */ (/** @type {unknown} */ (GLIMDOWN_RENDER))]) {
86
+ nodeObj.type = 'glimmer_raw';
87
+
88
+ return;
89
+ }
90
+
91
+ return 'skip';
92
+ }
93
+
94
+ if (nodeObj.type === 'text' || nodeObj.type === 'raw') {
95
+ // definitively not the better way, but this is supposed to detect "glimmer" nodes
96
+ if (
97
+ 'value' in nodeObj &&
98
+ typeof nodeObj.value === 'string' &&
99
+ nodeObj.value.match(/<\/?[_A-Z:0-9].*>/g)
100
+ ) {
101
+ nodeObj.type = 'glimmer_raw';
102
+ }
103
+
104
+ nodeObj.type = 'glimmer_raw';
105
+
106
+ return 'skip';
107
+ }
108
+
109
+ return;
110
+ });
111
+ });
112
+
113
+ if (options.rehypePlugins) {
114
+ options.rehypePlugins.forEach((plugin) => {
115
+ // Arrays are how plugins are passed options (for some reason?)
116
+ // why not just invoke the the function?
117
+ if (Array.isArray(plugin)) {
118
+ // @ts-ignore - unified processor types are complex and change as plugins are added
119
+ compiler = compiler.use(plugin[0], ...plugin.slice(1));
120
+ } else {
121
+ // @ts-ignore - unified processor types are complex and change as plugins are added
122
+ compiler = compiler.use(plugin);
123
+ }
124
+ });
125
+ }
126
+
127
+ // @ts-ignore - unified processor types are complex and change as plugins are added
128
+ compiler = compiler
129
+ .use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] })
130
+ .use(() => (/** @type {unknown} */ tree) => {
131
+ visit(/** @type {import('hast').Root} */ (tree), 'glimmer_raw', (node) => {
132
+ /** @type {Record<string, unknown>} */ (node).type = 'raw';
133
+ });
134
+ });
135
+
136
+ // @ts-ignore - unified processor types are complex and change as plugins are added
137
+ compiler = compiler.use(sanitizeForGlimmer);
138
+
139
+ // Finally convert to string! oofta!
140
+ // @ts-ignore - unified processor types are complex and change as plugins are added
141
+ compiler = compiler.use(rehypeStringify, {
142
+ collapseEmptyAttributes: true,
143
+ closeSelfClosing: true,
144
+ allowParseErrors: true,
145
+ allowDangerousCharacters: true,
146
+ allowDangerousHtml: true,
147
+ });
148
+
149
+ // @ts-ignore
150
+ return compiler;
151
+ }
@@ -0,0 +1,2 @@
1
+ export const GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');
2
+ export const GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');
@@ -0,0 +1,75 @@
1
+ import { kebabCase } from 'change-case';
2
+ import { visit } from 'unist-util-visit';
3
+
4
+ /**
5
+ * @param {import('mdast').PhrasingContent[]} children
6
+ * @return {string}
7
+ */
8
+ function getDefaultId(children) {
9
+ return formatDefaultId(extractText(children));
10
+ }
11
+
12
+ /**
13
+ * @param {import('mdast').PhrasingContent[]} children
14
+ * @return {string}
15
+ */
16
+ function extractText(children) {
17
+ return children
18
+ .map(
19
+ /**
20
+ * @param {any} child
21
+ */
22
+ (child) => {
23
+ const isEmpty = !child.value?.trim();
24
+
25
+ if (!isEmpty) {
26
+ return child.value;
27
+ } else if (child.children && child.children.length > 0) {
28
+ return extractText(child.children);
29
+ } else {
30
+ return '';
31
+ }
32
+ }
33
+ )
34
+ .join(' ');
35
+ }
36
+
37
+ /**
38
+ * @param {string} value
39
+ */
40
+ function formatDefaultId(value) {
41
+ return kebabCase(value.replaceAll(/\\s+/g, ' ').trim());
42
+ }
43
+
44
+ /**
45
+ * @param {import('mdast').Heading} node
46
+ * @param {string} id
47
+ */
48
+ function setNodeId(node, id) {
49
+ if (!node.data) node.data = {};
50
+ if (!node.data.hProperties) node.data.hProperties = {};
51
+
52
+ /** @type {any} */ (node.data).id = node.data.hProperties.id = id;
53
+ }
54
+
55
+ export function headingId(options = { defaults: false }) {
56
+ /**
57
+ * @param {import('mdast').Root} node
58
+ */
59
+ return function (node) {
60
+ visit(node, 'heading', (node) => {
61
+ const lastChild = node.children[node.children.length - 1];
62
+
63
+ if (lastChild && lastChild.type === 'text') {
64
+ const string = lastChild.value.replace(/ +$/, '');
65
+ const matched = string.match(/ {#([^]+?)}$/);
66
+
67
+ if (matched) {
68
+ return;
69
+ }
70
+ }
71
+
72
+ setNodeId(node, getDefaultId(node.children));
73
+ });
74
+ };
75
+ }
@@ -0,0 +1,198 @@
1
+ import { visit } from 'unist-util-visit';
2
+
3
+ import { nextId } from '../../utils.js';
4
+ import { GLIMDOWN_PREVIEW, GLIMDOWN_RENDER } from './const.js';
5
+
6
+ /**
7
+ * Swaps live codeblocks with placeholders that the compiler can then
8
+ * use to insert compiled-from-other-sources' code into those placeholders.
9
+ *
10
+ * @type {import('unified').Plugin<[
11
+ * {
12
+ * demo: {
13
+ * classList: string[]
14
+ * },
15
+ * code: {
16
+ * classList: string[]
17
+ * },
18
+ * isLive: (meta: string, lang: string) => boolean,
19
+ * ALLOWED_FORMATS: string[],
20
+ * isPreview: (meta: string) => boolean,
21
+ * isBelow: (meta: string) => boolean,
22
+ * needsLive: (lang: string) => boolean
23
+ * getFlavorFromMeta: (meta: string, lang: string) => string | undefined
24
+ * },
25
+ * ], import('mdast').Root>}
26
+ */
27
+ export function liveCodeExtraction(options) {
28
+ const { code, demo, isLive, ALLOWED_FORMATS, isPreview, isBelow, needsLive, getFlavorFromMeta } =
29
+ options;
30
+ let { classList: snippetClasses } = code || {};
31
+ let { classList: demoClasses } = demo || {};
32
+
33
+ snippetClasses ??= [];
34
+ demoClasses ??= [];
35
+
36
+ /**
37
+ * @param {import('mdast').Code} node
38
+ */
39
+ function isRelevantCode(node) {
40
+ if (node.type !== 'code') return false;
41
+
42
+ let { meta, lang } = node;
43
+
44
+ if (!lang) {
45
+ return false;
46
+ }
47
+
48
+ meta = meta?.trim() ?? '';
49
+
50
+ if (!isLive(meta, lang)) {
51
+ return false;
52
+ }
53
+
54
+ if (!ALLOWED_FORMATS.includes(lang)) {
55
+ return false;
56
+ }
57
+
58
+ return true;
59
+ }
60
+
61
+ /**
62
+ * @param {import('mdast').Code} code
63
+ * @param {string[]} [classes]
64
+ */
65
+ function enhance(code, classes = []) {
66
+ code.data ??= {};
67
+ code.data['hProperties'] ??= {};
68
+ // This is secret-to-us-only API, so we don't really care about the type
69
+ code.data['hProperties'][/** @type {string} */ (/** @type {unknown} */ (GLIMDOWN_PREVIEW))] =
70
+ true;
71
+
72
+ return {
73
+ data: {
74
+ hProperties: { className: classes, 'data-repl-output': true },
75
+ },
76
+ type: 'div',
77
+ hProperties: { className: classes },
78
+ children: [code],
79
+ };
80
+ }
81
+
82
+ /**
83
+ * @template T
84
+ * @param {T[]} array
85
+ * @param {number} index
86
+ * @param {T[]} replacement
87
+ */
88
+ function flatReplaceAt(array, index, replacement) {
89
+ array.splice(index, 1, ...replacement);
90
+ }
91
+
92
+ // because we mutate the tree as we iterate,
93
+ // we need to make sure we don't loop forever
94
+ const seen = new Set();
95
+
96
+ return function transformer(tree, file) {
97
+ visit(tree, ['code'], function (node, index, parent) {
98
+ if (parent === null || parent === undefined) return;
99
+ if (index === null || index === undefined) return;
100
+ if (node.type !== 'code') return;
101
+
102
+ /** @type {import('mdast').Code} */
103
+ const codeNode = node;
104
+
105
+ const isRelevant = isRelevantCode(codeNode);
106
+
107
+ if (!isRelevant) {
108
+ const enhanced = enhance(codeNode, snippetClasses);
109
+
110
+ /** @type {unknown[]} */ (parent.children)[index] = /** @type {unknown} */ (enhanced);
111
+
112
+ return 'skip';
113
+ }
114
+
115
+ if (seen.has(codeNode)) {
116
+ return 'skip';
117
+ }
118
+
119
+ seen.add(codeNode);
120
+
121
+ const { meta, lang, value } = codeNode;
122
+
123
+ if (!lang) {
124
+ return 'skip';
125
+ }
126
+
127
+ /**
128
+ * Sometimes, meta is not required,
129
+ * like with the `mermaid` language
130
+ *
131
+ * NOTE: that if a flavor is required, meta is present
132
+ * if the flavor is provided
133
+ */
134
+ if (!meta) {
135
+ if (needsLive(lang)) {
136
+ return 'skip';
137
+ }
138
+ }
139
+
140
+ file.data.liveCode ??= [];
141
+
142
+ const code = value.trim();
143
+ const id = nextId();
144
+
145
+ const invokeNode = /** @type {import('mdast').Html} */ ({
146
+ type: 'html',
147
+ data: {
148
+ hProperties: {
149
+ [/** @type {string} */ (/** @type {unknown} */ (GLIMDOWN_RENDER))]: true,
150
+ },
151
+ },
152
+ value: `<div id="${id}" class="${demoClasses}"></div>`,
153
+ });
154
+
155
+ const wrapper = enhance(codeNode, snippetClasses);
156
+
157
+ /** @type {unknown[]} */ (file.data.liveCode).push({
158
+ format: lang,
159
+ flavor: getFlavorFromMeta(meta ?? '', lang),
160
+ code,
161
+ placeholderId: id,
162
+ meta,
163
+ });
164
+
165
+ const live = isLive(meta || '', lang);
166
+ const preview = isPreview(meta || '');
167
+ const below = isBelow(meta || '');
168
+
169
+ if (live && preview && below) {
170
+ flatReplaceAt(/** @type {unknown[]} */ (parent.children), index, [
171
+ /** @type {unknown} */ (wrapper),
172
+ /** @type {unknown} */ (invokeNode),
173
+ ]);
174
+
175
+ return 'skip';
176
+ }
177
+
178
+ if (live && preview) {
179
+ flatReplaceAt(/** @type {unknown[]} */ (parent.children), index, [
180
+ /** @type {unknown} */ (invokeNode),
181
+ /** @type {unknown} */ (wrapper),
182
+ ]);
183
+
184
+ return 'skip';
185
+ }
186
+
187
+ if (live) {
188
+ /** @type {unknown[]} */ (parent.children)[index] = /** @type {unknown} */ (invokeNode);
189
+
190
+ return 'skip';
191
+ }
192
+
193
+ /** @type {unknown[]} */ (parent.children)[index] = /** @type {unknown} */ (wrapper);
194
+
195
+ return;
196
+ });
197
+ };
198
+ }