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,59 @@
1
+ /**
2
+ * @type {import('../types.ts').CompilerConfig}
3
+ */
4
+ export const jsx = {
5
+ codemirror: {
6
+ lang: async () => {
7
+ const { javascript } = await import('@codemirror/lang-javascript');
8
+
9
+ return javascript({ jsx: true });
10
+ },
11
+ },
12
+ resolve: (id) => {
13
+ /**
14
+ * NOTE: react still only publishes CJS to NPM
15
+ */
16
+ switch (id) {
17
+ case 'react':
18
+ return `https://esm.sh/react@19.2.3/es2022/react.development.mjs`;
19
+ case 'react/jsx-dev-runtime':
20
+ return `https://esm.sh/react@19.2.3/es2022/jsx-dev-runtime.development.mjs`;
21
+ case 'react-dom/client':
22
+ return `https://esm.sh/react-dom@19.2.3/es2022/client.development.mjs`;
23
+ case '@babel/standalone':
24
+ return `https://esm.sh/@babel/standalone`;
25
+ }
26
+ },
27
+ compiler: async (config, api) => {
28
+ const [reactDom, babel] = await api.tryResolveAll(['react-dom/client', '@babel/standalone']);
29
+
30
+ const { createRoot } = reactDom;
31
+
32
+ return {
33
+ async compile(text) {
34
+ const result = babel.transform(text, {
35
+ filename: `repl.js`,
36
+ presets: [
37
+ [
38
+ babel.availablePresets.react,
39
+ {
40
+ // useBuiltIns: true,
41
+ },
42
+ ],
43
+ ],
44
+ });
45
+
46
+ return result.code;
47
+ },
48
+ async render(element, component) {
49
+ const root = createRoot(element);
50
+
51
+ await new Promise((resolve) => requestAnimationFrame(resolve));
52
+ root.render(component);
53
+
54
+ // Wait for react-dom to render
55
+ await new Promise((resolve) => requestAnimationFrame(resolve));
56
+ },
57
+ };
58
+ },
59
+ };
@@ -0,0 +1,116 @@
1
+ import { esmSh } from '../cdn.js';
2
+
3
+ /**
4
+ * @type {import('../types.ts').CompilerConfig}
5
+ */
6
+ export const svelte = {
7
+ codemirror: {
8
+ lang: async () => {
9
+ const { svelte } = await import('@replit/codemirror-lang-svelte');
10
+
11
+ return svelte();
12
+ },
13
+ },
14
+
15
+ /**
16
+ * Default config, known to work with how the compiler and render functions are configured.
17
+ */
18
+ resolve: (id) => {
19
+ // This is basically an importmap.
20
+ // Because Svelte 5 is no longer bundled, we need another service to provide
21
+ // these.
22
+ //
23
+ // Svelte 5 has a tooooon of modules, and repl-sdk (at the time of writing)
24
+ // runs out of memory and crashes the browser while loading everything.
25
+ //
26
+ // There are optimizations to be had, for sure.
27
+ // But this is good for now.
28
+ //
29
+ // See also: https://github.com/sveltejs/svelte/discussions/15658
30
+ if (['svelte'].some((x) => id.startsWith(x))) {
31
+ return (
32
+ esmSh(
33
+ {
34
+ svelte: '5.35.7',
35
+ },
36
+ id,
37
+ false
38
+ ) +
39
+ // + '?target=esnext';
40
+ '?dev&target=esnext&keep-names'
41
+ );
42
+ }
43
+
44
+ // dependencies of svelte / the compiler
45
+ if (
46
+ [
47
+ 'zimmerframe',
48
+ 'locate-character',
49
+ 'acorn',
50
+ 'clsx',
51
+ 'magic-string',
52
+ '@ampproject/remapping',
53
+ '@jridgewell/sourcemap-codec',
54
+ 'axobject-query',
55
+ 'esrap',
56
+ 'is-reference',
57
+ 'aria-query',
58
+ '@sveltejs/acorn-typescript',
59
+ ].some((x) => id.startsWith(x))
60
+ ) {
61
+ return esmSh({}, id, false);
62
+ }
63
+ },
64
+ compiler: async (config, api) => {
65
+ const [svelte, compiler] = await api.tryResolveAll(['svelte', 'svelte/compiler']);
66
+
67
+ return {
68
+ compile: async (text, options) => {
69
+ /**
70
+ * source: https://github.com/sveltejs/svelte/blob/26e328689950b390189c6da31c32283d217df4b4/packages/svelte/src/compiler/index.js#L22
71
+ *
72
+ * Usages:
73
+ * https://github.com/sveltejs/svelte/blob/main/playgrounds/sandbox/run.js#L75
74
+ */
75
+ const output = await compiler.compile(text, {
76
+ /* this errors if unexpected options are passed */
77
+ generate: 'client',
78
+ fragments: 'html',
79
+ // Placeholder for now until multiple files are supported
80
+ filename: 'repl-sdk.svelte',
81
+ dev: true,
82
+ runes: true,
83
+ // experimental: {
84
+ // async: true,
85
+ // },
86
+ });
87
+
88
+ return { compiled: output.js.code, css: output.css?.code };
89
+ },
90
+ render: async (element, component, { css }) => {
91
+ const div = document.createElement('div');
92
+
93
+ if (css) {
94
+ const style = document.createElement('style');
95
+
96
+ style.innerHTML = /** @type {string} */ (css);
97
+ element.appendChild(style);
98
+ }
99
+
100
+ element.appendChild(div);
101
+
102
+ requestAnimationFrame(() => {
103
+ // @ts-ignore
104
+ svelte.mount(component, {
105
+ target: element,
106
+ props: {
107
+ /* no props */
108
+ },
109
+ });
110
+
111
+ api.announce('info', 'Done');
112
+ });
113
+ },
114
+ };
115
+ },
116
+ };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @type {import('../types.ts').CompilerConfig}
3
+ */
4
+ export const vue = {
5
+ codemirror: {
6
+ lang: async () => {
7
+ const { vue } = await import('@codemirror/lang-vue');
8
+
9
+ return vue();
10
+ },
11
+ },
12
+ /**
13
+ * Default config, known to work with how the compiler and render functions are configured.
14
+ */
15
+ resolve: (id) => {
16
+ switch (id) {
17
+ case 'vue':
18
+ return `https://cdn.jsdelivr.net/npm/vue@3.5.16/+esm`;
19
+ case '@vue/repl':
20
+ return `https://cdn.jsdelivr.net/npm/@vue/repl@4.5.1/+esm`;
21
+ }
22
+ },
23
+ compiler: async (config, api) => {
24
+ const [{ createApp }, { compileFile, useStore }] = await api.tryResolveAll([
25
+ 'vue',
26
+ '@vue/repl',
27
+ ]);
28
+
29
+ const store = useStore();
30
+
31
+ return {
32
+ compile: async (text, options) => {
33
+ const output = { js: '', css: '', ssr: '' };
34
+
35
+ await compileFile(store, {
36
+ code: text,
37
+ filename: options.fileName,
38
+ language: 'vue',
39
+ compiled: output,
40
+ });
41
+
42
+ return { compiled: output.js, css: output.css };
43
+ },
44
+ render: async (element, component, { css }, compiler) => {
45
+ const div = document.createElement('div');
46
+ const style = document.createElement('style');
47
+
48
+ style.innerHTML = /** @type {string} */ (css);
49
+
50
+ element.appendChild(div);
51
+ element.appendChild(style);
52
+
53
+ createApp(component).mount(div);
54
+ compiler.announce('info', 'Done');
55
+ },
56
+ };
57
+ },
58
+ };
@@ -0,0 +1,108 @@
1
+ import * as ember from './compilers/ember.js';
2
+ import { js } from './compilers/js.js';
3
+ import * as markdown from './compilers/markdown.js';
4
+ import { mermaid } from './compilers/mermaid.js';
5
+ import * as react from './compilers/react.js';
6
+ import { svelte } from './compilers/svelte.js';
7
+ import { vue } from './compilers/vue.js';
8
+
9
+ /**
10
+ * @type {import('./types').Options['formats']}
11
+ */
12
+ export const compilers = {
13
+ hbs: {
14
+ /**
15
+ * ember has historically used a subset of HBS, and then built its own features on top of.
16
+ *
17
+ * It is not "handlebars", but does share a lot of similarities.
18
+ * (and these continue in ember's new gjs and gts formats)
19
+ *
20
+ */
21
+ ember: ember.hbs,
22
+ },
23
+ /**
24
+ * Markdown, but every code fense can be a live "Island"
25
+ * if `live` is in the codefence's meta tag and the compiler
26
+ * is registered here, or by the user of repl-sdk.
27
+ */
28
+ md: markdown.md,
29
+
30
+ /**
31
+ * Glimmer-flavored Markdown.
32
+ *
33
+ * Like the markdow renderer, but the resulting HTML
34
+ * is a Glimmer Component, rather than just plain HTML.
35
+ *
36
+ * https://emberjs.com
37
+ * https://repl.nullvoxpopuli.com
38
+ * https://kolay.nullvoxpopuli.com
39
+ * https://tutorial.glimdown.com
40
+ * https://limber.glimdown.com
41
+ */
42
+ gmd: ember.gmd,
43
+ /**
44
+ * Glimmer-Flavored JavaScript
45
+ *
46
+ * https://emberjs.com
47
+ */
48
+ gjs: ember.gjs,
49
+ /**
50
+ * TODO:
51
+ * Glimmer-flavored TypeScript
52
+ *
53
+ * https://emberjs.com
54
+ */
55
+ // gts: ember.gts,
56
+
57
+ /**
58
+ * Just vanilla JS.
59
+ */
60
+ js,
61
+
62
+ /**
63
+ * JSX is too overloaded to treat one way.
64
+ * We need to split this, and then make folks choose which one to use
65
+ * - jsx-react
66
+ * - jsx-vue
67
+ * - jsx-solid
68
+ * - (etc)
69
+ *
70
+ * This means that as a generic compiler, we can't just have jsx support.
71
+ * And in markdown, we'll need to support choosing which flavor of jsx
72
+ * via meta tags on the codefences.
73
+ *
74
+ * For example:
75
+ * ```jsx solid
76
+ * export default <></>;
77
+ * ```
78
+ *
79
+ * or
80
+ * ```jsx react
81
+ * export default <></>;
82
+ * ```
83
+ */
84
+ jsx: {
85
+ /**
86
+ * https://react.dev/
87
+ */
88
+ react: react.jsx,
89
+
90
+ /**
91
+ * TODO:
92
+ * https://www.solidjs.com/
93
+ */
94
+ // solid: solid.jsx,
95
+ },
96
+ /**
97
+ * https://mermaid.js.org/
98
+ */
99
+ mermaid,
100
+ /**
101
+ * https://svelte.dev/
102
+ */
103
+ svelte,
104
+ /**
105
+ * https://vuejs.org/
106
+ */
107
+ vue,
108
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * es-module-shim can only be initialized once.
3
+ * it freezes its caches and options passed to it.
4
+ *
5
+ * So... here we are. Making stuff dynamic so we can have es-module-shims
6
+ * deal with the "most recent" intance of the compiler
7
+ * (since the compiler holds state,
8
+ * and our tests share all globals as they run in the same browser window).
9
+ */
10
+
11
+ /**
12
+ * @type {{
13
+ * resolve: (id: string, parentUrl: string, parentResolve: (id: string, parentUrl: string) => string) => string
14
+ * fetch: (id: string, options: RequestInit) => Promise<Response>
15
+ * }}
16
+ */
17
+ export const STABLE_REFERENCE = {
18
+ resolve: () => {
19
+ throw new Error(
20
+ `'resolve' not implemented in STABLE_REFERENCE. Has the Compiler been set up correctly?`
21
+ );
22
+ },
23
+ fetch: async () => {
24
+ throw new Error(
25
+ `'fetch' not implemented in STABLE_REFERENCE. Has the Compiler been set up correctly?`
26
+ );
27
+ },
28
+ };
29
+
30
+ globalThis.esmsInitOptions = {
31
+ shimMode: true,
32
+ // skip: [`https://esm.sh`, 'https://jspm.dev/', 'https://cdn.jsdelivr.net/'],
33
+ revokeBlobURLs: true, // default false
34
+ mapOverrides: true, // default false
35
+
36
+ /**
37
+ * @param {string} id
38
+ * @param {string} parentUrl
39
+ * @param {(id: string, parentUrl: string) => string} resolve
40
+ * @returns {string}
41
+ */
42
+ resolve: (id, parentUrl, resolve) => STABLE_REFERENCE.resolve(id, parentUrl, resolve),
43
+ // NOTE: may need source hook
44
+ // https://github.com/guybedford/es-module-shims?tab=readme-ov-file#source-hook
45
+ //
46
+
47
+ /**
48
+ * @param {string} url
49
+ * @param {RequestInit} options
50
+ * @returns {Promise<Response>}
51
+ */
52
+ fetch: (url, options) => STABLE_REFERENCE.fetch(url, options),
53
+ };
package/src/index.d.ts CHANGED
@@ -1,10 +1,59 @@
1
- import type { Options } from "./types.ts";
1
+ import type { CompilerConfig, Options } from './types.ts';
2
+ import type { EditorView } from 'codemirror';
2
3
 
3
- export const defaultFormats: Options['formats'];
4
+ export type { ErrorMessage, InfoMessage, Message, Options } from './types.ts';
5
+
6
+ export const defaultFormats: keyof Options['formats'];
4
7
  export const defaults: Options;
5
8
 
6
9
  export class Compiler {
7
- constructor(options?: Options);
10
+ constructor(options?: Partial<Options>);
11
+
12
+ compile(
13
+ format: string,
14
+ text: string,
15
+ options?: {
16
+ flavor?: string;
17
+ fileName?: string;
18
+ }
19
+ ): Promise<{ element: HTMLElement; destroy: () => void }>;
20
+
21
+ optionsFor(format: string, flavor?: string): Omit<CompilerConfig, 'compiler'>;
22
+
23
+ /**
24
+ * Cretes a codemirror editor instance
25
+ */
26
+ createEditor(
27
+ /**
28
+ * The element that the editor will be mounted on to and within
29
+ */
30
+ element: HTMLElement,
31
+
32
+ options: {
33
+ /**
34
+ * Initial text
35
+ */
36
+ text?: string | null | undefined;
37
+
38
+ /**
39
+ * Initial file format
40
+ */
41
+ format?: string | null | undefined;
42
+
43
+ /**
44
+ * When the editor's text is typed in, this callback is triggered.
45
+ * Can be used to update external state (such as a URL or some other storage).
46
+ */
47
+ handleUpdate?: (updatedText: string) => void;
48
+ }
49
+ ): Promise<{
50
+ view: EditorView;
51
+ setText: (text: string, format: string) => Promise<void>;
52
+ setFormat: (format: string) => Promise<void>;
53
+ }>;
8
54
 
9
- compile(format: string, text: string): Promise<HTMLElement>;
55
+ /**
56
+ * Clear promise, npm, tarball, (etc) caches
57
+ */
58
+ static clearCache: () => void;
10
59
  }