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.
- package/dist/apl-fqmucPXA.js +141 -0
- package/dist/apl-fqmucPXA.js.map +1 -0
- package/dist/asciiarmor-DucZyvP0.js +57 -0
- package/dist/asciiarmor-DucZyvP0.js.map +1 -0
- package/dist/asn1-BnOEsgAm.js +145 -0
- package/dist/asn1-BnOEsgAm.js.map +1 -0
- package/dist/assets/tar-worker-CxTcoQcr.js +593 -0
- package/dist/assets/tar-worker-CxTcoQcr.js.map +1 -0
- package/dist/asterisk-QAlztEwS.js +346 -0
- package/dist/asterisk-QAlztEwS.js.map +1 -0
- package/dist/brainfuck-DZVCuF_t.js +54 -0
- package/dist/brainfuck-DZVCuF_t.js.map +1 -0
- package/dist/clike-CTYGlS6x.js +800 -0
- package/dist/clike-CTYGlS6x.js.map +1 -0
- package/dist/clojure-BhXMqnxz.js +850 -0
- package/dist/clojure-BhXMqnxz.js.map +1 -0
- package/dist/cmake-BGaNd9E7.js +72 -0
- package/dist/cmake-BGaNd9E7.js.map +1 -0
- package/dist/cobol-4yqQntpt.js +121 -0
- package/dist/cobol-4yqQntpt.js.map +1 -0
- package/dist/codemirror-De3S70Np.js +2912 -0
- package/dist/codemirror-De3S70Np.js.map +1 -0
- package/dist/coffeescript-D2dXvhEc.js +309 -0
- package/dist/coffeescript-D2dXvhEc.js.map +1 -0
- package/dist/commonlisp-CF_VNHQR.js +131 -0
- package/dist/commonlisp-CF_VNHQR.js.map +1 -0
- package/dist/crystal-DyuLTqLs.js +399 -0
- package/dist/crystal-DyuLTqLs.js.map +1 -0
- package/dist/css-DkSyTW67.js +1773 -0
- package/dist/css-DkSyTW67.js.map +1 -0
- package/dist/cypher-Dlu_3r4V.js +122 -0
- package/dist/cypher-Dlu_3r4V.js.map +1 -0
- package/dist/d-UURgV0Ux.js +180 -0
- package/dist/d-UURgV0Ux.js.map +1 -0
- package/dist/diff-B_Bi2Crb.js +26 -0
- package/dist/diff-B_Bi2Crb.js.map +1 -0
- package/dist/dockerfile-Bvk733Ga.js +202 -0
- package/dist/dockerfile-Bvk733Ga.js.map +1 -0
- package/dist/dtd-Dy74G54E.js +115 -0
- package/dist/dtd-Dy74G54E.js.map +1 -0
- package/dist/dylan-TSb-Nfix.js +315 -0
- package/dist/dylan-TSb-Nfix.js.map +1 -0
- package/dist/ebnf-4fKAGW3a.js +141 -0
- package/dist/ebnf-4fKAGW3a.js.map +1 -0
- package/dist/ecl-B59qGGVg.js +179 -0
- package/dist/ecl-B59qGGVg.js.map +1 -0
- package/dist/eiffel-Dze7nlu3.js +135 -0
- package/dist/eiffel-Dze7nlu3.js.map +1 -0
- package/dist/elm-DG7jkhNZ.js +177 -0
- package/dist/elm-DG7jkhNZ.js.map +1 -0
- package/dist/erlang-BO6gOnGA.js +675 -0
- package/dist/erlang-BO6gOnGA.js.map +1 -0
- package/dist/factor-CMxFHDqz.js +66 -0
- package/dist/factor-CMxFHDqz.js.map +1 -0
- package/dist/fcl-CDDUNjTj.js +142 -0
- package/dist/fcl-CDDUNjTj.js.map +1 -0
- package/dist/forth-B9D2JCeE.js +117 -0
- package/dist/forth-B9D2JCeE.js.map +1 -0
- package/dist/fortran-CAG2BFbe.js +468 -0
- package/dist/fortran-CAG2BFbe.js.map +1 -0
- package/dist/gas-0Aw8zDr5.js +294 -0
- package/dist/gas-0Aw8zDr5.js.map +1 -0
- package/dist/gherkin-DhZlEZiy.js +116 -0
- package/dist/gherkin-DhZlEZiy.js.map +1 -0
- package/dist/gjs-DfguZDLq.js +173 -0
- package/dist/gjs-DfguZDLq.js.map +1 -0
- package/dist/gmd-Yas-Oo8k.js +163 -0
- package/dist/gmd-Yas-Oo8k.js.map +1 -0
- package/dist/groovy-CpwJiBl7.js +224 -0
- package/dist/groovy-CpwJiBl7.js.map +1 -0
- package/dist/haskell-ySd-OUo8.js +460 -0
- package/dist/haskell-ySd-OUo8.js.map +1 -0
- package/dist/haxe-7MlzfeYV.js +515 -0
- package/dist/haxe-7MlzfeYV.js.map +1 -0
- package/dist/hbs-CxcmWxSJ.js +62 -0
- package/dist/hbs-CxcmWxSJ.js.map +1 -0
- package/dist/http-BqypyemW.js +80 -0
- package/dist/http-BqypyemW.js.map +1 -0
- package/dist/idl-4HIGJlDI.js +986 -0
- package/dist/idl-4HIGJlDI.js.map +1 -0
- package/dist/index-B3Meoznj.js +118 -0
- package/dist/index-B3Meoznj.js.map +1 -0
- package/dist/index-BQyfDUUx.js +692 -0
- package/dist/index-BQyfDUUx.js.map +1 -0
- package/dist/index-BRDroAD8.js +305 -0
- package/dist/index-BRDroAD8.js.map +1 -0
- package/dist/index-BRMAzRyM.js +179 -0
- package/dist/index-BRMAzRyM.js.map +1 -0
- package/dist/index-Bb8uYQgv.js +927 -0
- package/dist/index-Bb8uYQgv.js.map +1 -0
- package/dist/index-BlOjO66K.js +17618 -0
- package/dist/index-BlOjO66K.js.map +1 -0
- package/dist/index-BoGWnSNL.js +706 -0
- package/dist/index-BoGWnSNL.js.map +1 -0
- package/dist/index-BsRrEiOu.js +98 -0
- package/dist/index-BsRrEiOu.js.map +1 -0
- package/dist/index-C2sFZMth.js +391 -0
- package/dist/index-C2sFZMth.js.map +1 -0
- package/dist/index-C7xwOjmS.js +291 -0
- package/dist/index-C7xwOjmS.js.map +1 -0
- package/dist/index-CA3lFUx6.js +315 -0
- package/dist/index-CA3lFUx6.js.map +1 -0
- package/dist/index-CB-pPTIf.js +98 -0
- package/dist/index-CB-pPTIf.js.map +1 -0
- package/dist/index-CCa6x1FE.js +386 -0
- package/dist/index-CCa6x1FE.js.map +1 -0
- package/dist/index-CD4DINI1.js +158 -0
- package/dist/index-CD4DINI1.js.map +1 -0
- package/dist/index-CE0B_fcG.js +328 -0
- package/dist/index-CE0B_fcG.js.map +1 -0
- package/dist/index-CVGAEPMV.js +2139 -0
- package/dist/index-CVGAEPMV.js.map +1 -0
- package/dist/index-CmaT2afn.js +332 -0
- package/dist/index-CmaT2afn.js.map +1 -0
- package/dist/index-D8sUxXp5.js +83 -0
- package/dist/index-D8sUxXp5.js.map +1 -0
- package/dist/index-DIz8Vpn-.js +737 -0
- package/dist/index-DIz8Vpn-.js.map +1 -0
- package/dist/index-DNP1xT-S.js +408 -0
- package/dist/index-DNP1xT-S.js.map +1 -0
- package/dist/index-DOAqdvnQ.js +862 -0
- package/dist/index-DOAqdvnQ.js.map +1 -0
- package/dist/index-DVUMFbgi.js +152 -0
- package/dist/index-DVUMFbgi.js.map +1 -0
- package/dist/index-VeTBKRVd.js +83 -0
- package/dist/index-VeTBKRVd.js.map +1 -0
- package/dist/index-dXZeR7Bx.js +1767 -0
- package/dist/index-dXZeR7Bx.js.map +1 -0
- package/dist/index-gtqbIb6T.js +62 -0
- package/dist/index-gtqbIb6T.js.map +1 -0
- package/dist/index-pN_pUAQ7.js +2426 -0
- package/dist/index-pN_pUAQ7.js.map +1 -0
- package/dist/index-wasu5VX0.js +1150 -0
- package/dist/index-wasu5VX0.js.map +1 -0
- package/dist/javascript-Bt8B7yTi.js +993 -0
- package/dist/javascript-Bt8B7yTi.js.map +1 -0
- package/dist/julia-Bs6JJhYG.js +408 -0
- package/dist/julia-Bs6JJhYG.js.map +1 -0
- package/dist/livescript-DmzgM3Yt.js +297 -0
- package/dist/livescript-DmzgM3Yt.js.map +1 -0
- package/dist/lua-8cJgIlqe.js +257 -0
- package/dist/lua-8cJgIlqe.js.map +1 -0
- package/dist/mathematica-DNLOL9PQ.js +111 -0
- package/dist/mathematica-DNLOL9PQ.js.map +1 -0
- package/dist/mbox-Ga7d4MMN.js +118 -0
- package/dist/mbox-Ga7d4MMN.js.map +1 -0
- package/dist/mirc-Dma3B8rS.js +108 -0
- package/dist/mirc-Dma3B8rS.js.map +1 -0
- package/dist/mllike-DHn7xckP.js +335 -0
- package/dist/mllike-DHn7xckP.js.map +1 -0
- package/dist/modelica-0d55jYY0.js +148 -0
- package/dist/modelica-0d55jYY0.js.map +1 -0
- package/dist/mscgen-DdqZYINH.js +136 -0
- package/dist/mscgen-DdqZYINH.js.map +1 -0
- package/dist/mumps-Btr8VblO.js +94 -0
- package/dist/mumps-Btr8VblO.js.map +1 -0
- package/dist/nginx-DTDtBDVN.js +142 -0
- package/dist/nginx-DTDtBDVN.js.map +1 -0
- package/dist/nsis-3zG7tgur.js +63 -0
- package/dist/nsis-3zG7tgur.js.map +1 -0
- package/dist/ntriples-CvgOYMpL.js +154 -0
- package/dist/ntriples-CvgOYMpL.js.map +1 -0
- package/dist/octave-DYBj3-tl.js +201 -0
- package/dist/octave-DYBj3-tl.js.map +1 -0
- package/dist/oz-R_e8WMIi.js +232 -0
- package/dist/oz-R_e8WMIi.js.map +1 -0
- package/dist/parse-CAqQaKsh.js +21685 -0
- package/dist/parse-CAqQaKsh.js.map +1 -0
- package/dist/pascal-GD8iposT.js +106 -0
- package/dist/pascal-GD8iposT.js.map +1 -0
- package/dist/perl-DL9mHpoi.js +1106 -0
- package/dist/perl-DL9mHpoi.js.map +1 -0
- package/dist/pig-C_4T4YIV.js +102 -0
- package/dist/pig-C_4T4YIV.js.map +1 -0
- package/dist/powershell-B0suO7Vd.js +329 -0
- package/dist/powershell-B0suO7Vd.js.map +1 -0
- package/dist/properties-BR-vP1aU.js +59 -0
- package/dist/properties-BR-vP1aU.js.map +1 -0
- package/dist/protobuf-BxgpyhoW.js +78 -0
- package/dist/protobuf-BxgpyhoW.js.map +1 -0
- package/dist/pug-vHnWR0UE.js +406 -0
- package/dist/pug-vHnWR0UE.js.map +1 -0
- package/dist/puppet-Bdao66PW.js +138 -0
- package/dist/puppet-Bdao66PW.js.map +1 -0
- package/dist/python-BFGRmuZ9.js +427 -0
- package/dist/python-BFGRmuZ9.js.map +1 -0
- package/dist/q-CrbCVq4a.js +132 -0
- package/dist/q-CrbCVq4a.js.map +1 -0
- package/dist/r-V7nswm59.js +171 -0
- package/dist/r-V7nswm59.js.map +1 -0
- package/dist/render-app-island-B-i8rvGi.js +61 -0
- package/dist/render-app-island-B-i8rvGi.js.map +1 -0
- package/dist/repl-sdk.js +7 -0
- package/dist/repl-sdk.js.map +1 -0
- package/dist/rpm-C-DLY-If.js +110 -0
- package/dist/rpm-C-DLY-If.js.map +1 -0
- package/dist/ruby-JDKLJNK0.js +331 -0
- package/dist/ruby-JDKLJNK0.js.map +1 -0
- package/dist/sas-D2UG-yhZ.js +208 -0
- package/dist/sas-D2UG-yhZ.js.map +1 -0
- package/dist/scheme-BKzrkGJD.js +223 -0
- package/dist/scheme-BKzrkGJD.js.map +1 -0
- package/dist/shell-BlsXDxCn.js +223 -0
- package/dist/shell-BlsXDxCn.js.map +1 -0
- package/dist/sieve-CjwBwOY5.js +136 -0
- package/dist/sieve-CjwBwOY5.js.map +1 -0
- package/dist/simple-mode-DMneyfDu.js +131 -0
- package/dist/simple-mode-DMneyfDu.js.map +1 -0
- package/dist/smalltalk-BOIGQuhN.js +122 -0
- package/dist/smalltalk-BOIGQuhN.js.map +1 -0
- package/dist/solr-CwD7U71z.js +70 -0
- package/dist/solr-CwD7U71z.js.map +1 -0
- package/dist/sparql-DYskk2vE.js +250 -0
- package/dist/sparql-DYskk2vE.js.map +1 -0
- package/dist/spreadsheet-Bgtt3oLP.js +88 -0
- package/dist/spreadsheet-Bgtt3oLP.js.map +1 -0
- package/dist/sql-Cei9CMfk.js +343 -0
- package/dist/sql-Cei9CMfk.js.map +1 -0
- package/dist/stex-C1nZSzAw.js +231 -0
- package/dist/stex-C1nZSzAw.js.map +1 -0
- package/dist/stylus-BkS-boTH.js +566 -0
- package/dist/stylus-BkS-boTH.js.map +1 -0
- package/dist/swift-FRZi1uvB.js +292 -0
- package/dist/swift-FRZi1uvB.js.map +1 -0
- package/dist/tcl-CUcaCdmq.js +115 -0
- package/dist/tcl-CUcaCdmq.js.map +1 -0
- package/dist/textile-BnFpjsrl.js +415 -0
- package/dist/textile-BnFpjsrl.js.map +1 -0
- package/dist/tiddlywiki-CjprD-Qp.js +219 -0
- package/dist/tiddlywiki-CjprD-Qp.js.map +1 -0
- package/dist/tiki-DK9DOeWn.js +269 -0
- package/dist/tiki-DK9DOeWn.js.map +1 -0
- package/dist/toml-BOuWGMcf.js +77 -0
- package/dist/toml-BOuWGMcf.js.map +1 -0
- package/dist/troff-E1bJ0PPL.js +62 -0
- package/dist/troff-E1bJ0PPL.js.map +1 -0
- package/dist/ttcn-cfg-Dc39-fIP.js +134 -0
- package/dist/ttcn-cfg-Dc39-fIP.js.map +1 -0
- package/dist/ttcn-tKd4HLu4.js +193 -0
- package/dist/ttcn-tKd4HLu4.js.map +1 -0
- package/dist/turtle-Dq7-1WAf.js +125 -0
- package/dist/turtle-Dq7-1WAf.js.map +1 -0
- package/dist/vb-Dp90gtsv.js +197 -0
- package/dist/vb-Dp90gtsv.js.map +1 -0
- package/dist/vbscript-Bfn8O8I7.js +479 -0
- package/dist/vbscript-Bfn8O8I7.js.map +1 -0
- package/dist/velocity-BwIZK1TH.js +150 -0
- package/dist/velocity-BwIZK1TH.js.map +1 -0
- package/dist/verilog-CnT9bMk0.js +430 -0
- package/dist/verilog-CnT9bMk0.js.map +1 -0
- package/dist/vhdl-DCkMIyT9.js +159 -0
- package/dist/vhdl-DCkMIyT9.js.map +1 -0
- package/dist/webidl-BTLTThCm.js +205 -0
- package/dist/webidl-BTLTThCm.js.map +1 -0
- package/dist/xquery-BrBUuxMR.js +526 -0
- package/dist/xquery-BrBUuxMR.js.map +1 -0
- package/dist/yacas-b5lAVEIl.js +131 -0
- package/dist/yacas-b5lAVEIl.js.map +1 -0
- package/dist/z80-ClgwfNdB.js +93 -0
- package/dist/z80-ClgwfNdB.js.map +1 -0
- package/package.json +81 -9
- package/src/cache.js +138 -0
- package/src/cdn.js +93 -0
- package/src/codemirror.js +161 -0
- package/src/compilers/ember/gjs.js +212 -0
- package/src/compilers/ember/gmd.js +190 -0
- package/src/compilers/ember/hbs.js +98 -0
- package/src/compilers/ember/render-app-island.js +83 -0
- package/src/compilers/ember.js +166 -0
- package/src/compilers/js.js +32 -0
- package/src/compilers/markdown/build-compiler.js +151 -0
- package/src/compilers/markdown/const.js +2 -0
- package/src/compilers/markdown/heading-id.js +75 -0
- package/src/compilers/markdown/live-code-extraction.js +198 -0
- package/src/compilers/markdown/parse.js +22 -0
- package/src/compilers/markdown/parse.test.ts +363 -0
- package/src/compilers/markdown/sanitize-for-glimmer.js +26 -0
- package/src/compilers/markdown/types.ts +21 -0
- package/src/compilers/markdown/utils.js +78 -0
- package/src/compilers/markdown.js +125 -0
- package/src/compilers/mermaid.js +35 -0
- package/src/compilers/react.js +59 -0
- package/src/compilers/svelte.js +116 -0
- package/src/compilers/vue.js +58 -0
- package/src/compilers.js +108 -0
- package/src/es-module-shim.js +53 -0
- package/src/index.d.ts +53 -4
- package/src/index.js +744 -89
- package/src/npm.js +58 -0
- package/src/request.Request.test.ts +59 -0
- package/src/request.js +140 -0
- package/src/resolve.fromImports.test.ts +35 -0
- package/src/resolve.fromInternalImport.test.ts +69 -0
- package/src/resolve.js +352 -0
- package/src/resolve.resolvePath.test.ts +24 -0
- package/src/resolve.test.ts +23 -0
- package/src/specifier.js +71 -0
- package/src/specifier.test.ts +90 -0
- package/src/tar-worker.js +61 -0
- package/src/tar.js +76 -0
- package/src/types.ts +335 -58
- package/src/utils.js +28 -1
- package/declarations/index.d.ts +0 -73
- package/dist/index.js +0 -107
- package/dist/index.js.map +0 -1
package/src/types.ts
CHANGED
|
@@ -1,62 +1,339 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { FileDescription } from 'tarparser';
|
|
3
|
+
|
|
4
|
+
export interface RequestAnswer {
|
|
5
|
+
inTarFile: string;
|
|
6
|
+
ext: string;
|
|
7
|
+
from: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface PublicMethods {
|
|
11
|
+
announce: (type: 'error' | 'info', message: string) => void;
|
|
12
|
+
getCompiler: (format: string, flavor?: string) => Promise<Compiler>;
|
|
13
|
+
getAllowedFormats: () => string[];
|
|
14
|
+
getFlavorsFor: (format: string) => string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Will try to use a shimmed import, or will return null.
|
|
18
|
+
*/
|
|
19
|
+
tryResolve: (
|
|
20
|
+
moduleName: string,
|
|
21
|
+
fallback?: (moduleName?: string) => Promise<object | undefined>
|
|
22
|
+
) => Promise<any>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Import many modules in parallel.
|
|
26
|
+
* For each array entry,
|
|
27
|
+
* Will try to use a shimmed import, or will return null.
|
|
28
|
+
*
|
|
29
|
+
* Optionally accepts a fallback function for proxying to a CDN, if desired.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
tryResolveAll: (
|
|
33
|
+
moduleNames: string[],
|
|
34
|
+
fallback?: (moduleName?: string) => Promise<unknown>
|
|
35
|
+
) => Promise<any[]>;
|
|
36
|
+
compile: (
|
|
37
|
+
format: string,
|
|
38
|
+
text: string,
|
|
39
|
+
options?: {
|
|
40
|
+
flavor?: string;
|
|
41
|
+
fileName?: string;
|
|
42
|
+
}
|
|
43
|
+
) => Promise<{ element: HTMLElement; destroy: () => void }>;
|
|
44
|
+
|
|
45
|
+
optionsFor: (
|
|
46
|
+
format: string,
|
|
47
|
+
flavor?: string
|
|
48
|
+
) => {
|
|
49
|
+
resolve?: (id: string) => string | undefined;
|
|
50
|
+
versions?: { [packageName: string]: string };
|
|
51
|
+
needsLiveMeta?: boolean;
|
|
52
|
+
[option: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Does this compiler support the given format?
|
|
57
|
+
*/
|
|
58
|
+
canCompile: (
|
|
59
|
+
format: string,
|
|
60
|
+
flavor?: string
|
|
61
|
+
) =>
|
|
62
|
+
| {
|
|
63
|
+
result: true;
|
|
64
|
+
}
|
|
65
|
+
| { result: false; reason: string };
|
|
66
|
+
}
|
|
67
|
+
export interface ResolvedCompilerOptions {
|
|
68
|
+
resolve: { [importPath: string]: unknown };
|
|
69
|
+
needsLiveMeta?: boolean;
|
|
70
|
+
versions?: { [packageName: string]: string };
|
|
71
|
+
userOptions?: Options['options'];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type CompileResult =
|
|
75
|
+
| string
|
|
76
|
+
| {
|
|
77
|
+
compiled: string;
|
|
78
|
+
[option: string]: unknown;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export interface Compiler {
|
|
82
|
+
/**
|
|
83
|
+
* Convert a string from "fileExtension" to standard JavaScript.
|
|
84
|
+
* This will be loaded as a module and then passed to the render method.
|
|
85
|
+
*
|
|
86
|
+
* You may return either just a string, or an object with a `compiled` property that is a string -- any additional properties will be passde through to the render function -- which may be useful if there is accompanying CSS.
|
|
87
|
+
*/
|
|
88
|
+
compile: (text: string, options: Record<string, unknown>) => Promise<CompileResult>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* For the root of a node rendered for this compiler,
|
|
92
|
+
* how will this particular library / framework
|
|
93
|
+
* render in to the given element?
|
|
94
|
+
*
|
|
95
|
+
* Example:
|
|
96
|
+
* ```js
|
|
97
|
+
* {
|
|
98
|
+
* async compiler() {
|
|
99
|
+
* const { createRoot } = await import('react-dom/client');
|
|
100
|
+
*
|
|
101
|
+
* return {
|
|
102
|
+
* render(element, defaultExport) {
|
|
103
|
+
* const root = createRoot(element);
|
|
104
|
+
*
|
|
105
|
+
* root.render(defaultExport);
|
|
106
|
+
* },
|
|
107
|
+
* // ...
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param {HTMLElement} the element to render in to, this is provided by repl-sdk.
|
|
114
|
+
* @param {any} defaultExport the default export from the compiled module.
|
|
115
|
+
* @param {{ compiled: string } & Record<string, unknown>} extras the compiled string (for reference), as well as any extra information that may have been returned from the compile function.
|
|
116
|
+
*/
|
|
117
|
+
render: (
|
|
118
|
+
element: HTMLElement,
|
|
119
|
+
defaultExport: unknown,
|
|
120
|
+
extras: { compiled: string } & Record<string, unknown>,
|
|
121
|
+
compiler: PublicMethods
|
|
122
|
+
) => Promise<void | (() => void)>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Sometimes libraries do not publish browser-compatible modules,
|
|
126
|
+
* and require additional transpilation.
|
|
127
|
+
* Usually this happens by the consuming application's build process -- but in this REPL,
|
|
128
|
+
* we are kind of not exactly a consuming application, but still need to handle the further
|
|
129
|
+
* build concerns.
|
|
130
|
+
*
|
|
131
|
+
* For example, `import.meta.env.DEV` is not a platform native thing that and requires
|
|
132
|
+
* a build plugin. Vite has one built in, but all other tools need to manually specify
|
|
133
|
+
* what to do with `import.meta.env.DEV`.
|
|
134
|
+
*
|
|
135
|
+
* Another example, some component frameworks may use templates, which can only be compiled
|
|
136
|
+
* by the host application, as the details of how a template is compiled are private API,
|
|
137
|
+
* and can vary in minor releases of the template compiler.
|
|
138
|
+
*
|
|
139
|
+
* This should be a map of file extensions to async functions that must return either the
|
|
140
|
+
* original file text or additionally transformed text.
|
|
141
|
+
*
|
|
142
|
+
* ```js
|
|
143
|
+
* handlers: {
|
|
144
|
+
* // When resolving a .js file from a CDN or NPM, replace `import.meta.env.DEV` with `true`
|
|
145
|
+
* js: async(text) => {
|
|
146
|
+
* return text.replaceAll('import.meta.env.DEV', 'true');
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* This could also be used to run the same build step on fetched files as
|
|
152
|
+
* the files provided to the REPL.
|
|
153
|
+
*
|
|
154
|
+
* ```js
|
|
155
|
+
* let compiler = {
|
|
156
|
+
* compile: async (text) => { ... },
|
|
157
|
+
* render: async (element, compiled, ...rest) => { ... },
|
|
158
|
+
* handlers: {
|
|
159
|
+
* js: async(text) => {
|
|
160
|
+
* return compiler.compile(text);
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
handlers?: {
|
|
167
|
+
[fileExtension: string]: (text: string) => Promise<CompileResult>;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface CompilerConfig {
|
|
172
|
+
/**
|
|
173
|
+
* Extensions for codemirror, providing syntax highlighting and other editor features (completions, etc)
|
|
174
|
+
*/
|
|
175
|
+
codemirror: {
|
|
176
|
+
lang: () => Promise<unknown>;
|
|
177
|
+
support?: () => Promise<unknown>;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* When using this file extension in markdown documents,
|
|
182
|
+
* should we only evaluate the code block if the "live"
|
|
183
|
+
* meta is attached to the codefence?
|
|
184
|
+
*
|
|
185
|
+
* If you don't use markdown-embedded rendering,
|
|
186
|
+
* you can ignore this option. Default behavior is "false",
|
|
187
|
+
* but it doesn't matter if you don't render markdown anyway.
|
|
188
|
+
*
|
|
189
|
+
* For example, with `needsLiveMeta: false`:
|
|
190
|
+
* \`\`\`js
|
|
191
|
+
* console.log('hello');
|
|
192
|
+
* \`\`\`
|
|
193
|
+
* will be evaluated and log to the console.
|
|
194
|
+
* However, with `needsLiveMeta: true`, the above snippet would not
|
|
195
|
+
* be evaluated. To evaluate a snippet with `needsLiveMeta: true`:
|
|
196
|
+
* \`\`\`js live
|
|
197
|
+
* console.log('hello');
|
|
198
|
+
* \`\`\`
|
|
199
|
+
*/
|
|
200
|
+
needsLiveMeta?: boolean;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Synchronously extend the way resolution works
|
|
204
|
+
* This is "import map as a function", which allows for more flexibility than just the static import map.
|
|
205
|
+
*
|
|
206
|
+
* This may not return a promise.
|
|
207
|
+
* But we can return functions that return promises.
|
|
208
|
+
*
|
|
209
|
+
*/
|
|
210
|
+
resolve?: (
|
|
211
|
+
id: string
|
|
212
|
+
) =>
|
|
213
|
+
| string
|
|
214
|
+
| (() => Record<string, unknown>)
|
|
215
|
+
| (() => Promise<Record<string, unknown>>)
|
|
216
|
+
| undefined;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* This optional method provides the opportunity to reformat messages that would be displayed to the REPL.
|
|
220
|
+
*/
|
|
221
|
+
onUnhandled?: (e: PromiseRejectionEvent, handle: (msg: string) => void) => void;
|
|
222
|
+
|
|
223
|
+
compiler: (
|
|
224
|
+
/**
|
|
225
|
+
* The config for the compiler may be passed by the caller.
|
|
226
|
+
* Common use case for this object is specifying what versions
|
|
227
|
+
* of the compiler/library/framework dependencies to use.
|
|
228
|
+
*/
|
|
229
|
+
config: { versions: { [packageName: string]: string }; [option: string]: unknown },
|
|
230
|
+
/**
|
|
231
|
+
* The public methods provided from the compiler
|
|
232
|
+
*/
|
|
233
|
+
api: PublicMethods
|
|
234
|
+
) => Promise<Compiler>;
|
|
235
|
+
}
|
|
236
|
+
|
|
1
237
|
export interface Options {
|
|
238
|
+
/**
|
|
239
|
+
* Events will be emitted on this object.
|
|
240
|
+
* Not required, but could be useful for providing lots of feedback to the user.
|
|
241
|
+
*/
|
|
242
|
+
on?: {
|
|
243
|
+
/**
|
|
244
|
+
* Public-log messages will be emitted here.
|
|
245
|
+
* These include:
|
|
246
|
+
* - errors
|
|
247
|
+
* - what is being fetched / compiled
|
|
248
|
+
*/
|
|
249
|
+
log?: (type: 'error' | 'info', message: string) => void;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Map of pre-resolved JS values to use as the import map
|
|
254
|
+
* These could assume the role of runtime virtual modules.
|
|
255
|
+
*
|
|
256
|
+
* These will take precedence over the importMap, and implicit CDN fallback.
|
|
257
|
+
*/
|
|
258
|
+
resolve?: { [importPath: string]: unknown };
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Specifies which vesions of dependencies to when pulling from a CDN.
|
|
262
|
+
* Defaults to latest.
|
|
263
|
+
*/
|
|
264
|
+
versions?: { [packageName: string]: string };
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Map of file extensions to compiler configurations
|
|
268
|
+
*/
|
|
2
269
|
formats: {
|
|
3
|
-
[fileExtension: string]:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
270
|
+
[fileExtension: string]:
|
|
271
|
+
| CompilerConfig
|
|
272
|
+
| {
|
|
273
|
+
[flavor: string]: CompilerConfig;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
options?: {
|
|
278
|
+
[format: string]:
|
|
279
|
+
| KnownDefaultOptions
|
|
280
|
+
| {
|
|
281
|
+
[flavor: string]: { [option: string]: unknown };
|
|
282
|
+
}
|
|
283
|
+
| {
|
|
284
|
+
[option: string]: unknown;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Show extra debug logging or not
|
|
290
|
+
*/
|
|
291
|
+
logging?: boolean | undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
interface KnownDefaultOptions {
|
|
295
|
+
md?: {
|
|
296
|
+
rehypePlugins?: unknown[];
|
|
297
|
+
remarkPlugins?: unknown[];
|
|
298
|
+
CopyComponent?: string;
|
|
299
|
+
ShadowComponent?: string;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
import type { ImportMap as ManifestImports } from 'resolve.imports';
|
|
304
|
+
|
|
305
|
+
export interface UntarredPackage {
|
|
306
|
+
/**
|
|
307
|
+
* the package.json
|
|
308
|
+
*/
|
|
309
|
+
manifest: {
|
|
310
|
+
name: string;
|
|
311
|
+
version: string;
|
|
312
|
+
exports?: ManifestExports;
|
|
313
|
+
imports?: Record<string, ManifestImports>;
|
|
314
|
+
main?: string;
|
|
315
|
+
module?: string;
|
|
316
|
+
browser?: string;
|
|
317
|
+
};
|
|
318
|
+
contents: {
|
|
319
|
+
[path: string]: FileDescription;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
type ManifestExport = string | string[] | { [condition: string]: ManifestExport };
|
|
324
|
+
|
|
325
|
+
export interface ManifestExports {
|
|
326
|
+
[importPath: string]: ManifestExport;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export interface InfoMessage {
|
|
330
|
+
type: 'info';
|
|
331
|
+
message: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface ErrorMessage {
|
|
335
|
+
type: 'error';
|
|
336
|
+
message: string;
|
|
61
337
|
}
|
|
62
338
|
|
|
339
|
+
export type Message = InfoMessage | ErrorMessage;
|
package/src/utils.js
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {string} message
|
|
3
3
|
* @param {unknown} test
|
|
4
|
-
* @asserts test
|
|
4
|
+
* @returns {asserts test}
|
|
5
5
|
*/
|
|
6
6
|
export function assert(message, test) {
|
|
7
7
|
if (!test) {
|
|
8
8
|
throw new Error(message);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
let i = 0;
|
|
13
|
+
|
|
14
|
+
export function nextId() {
|
|
15
|
+
i += 1;
|
|
16
|
+
|
|
17
|
+
return `repl_${i}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const fakeDomain = 'repl.sdk';
|
|
21
|
+
export const tgzPrefix = 'file:///tgz.repl.sdk/';
|
|
22
|
+
export const unzippedPrefix = 'file:///tgz.repl.sdk/unzipped';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} url
|
|
26
|
+
*/
|
|
27
|
+
export function prefix_tgz(url) {
|
|
28
|
+
return `${tgzPrefix}${url}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {unknown} x
|
|
33
|
+
* @returns {x is Record<string, unknown>}
|
|
34
|
+
*/
|
|
35
|
+
export function isRecord(x) {
|
|
36
|
+
return typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
37
|
+
}
|
package/declarations/index.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export declare class Compiler {
|
|
2
|
-
constructor(options?: Options);
|
|
3
|
-
|
|
4
|
-
compile(format: string, text: string): Promise<HTMLElement>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export declare const defaultFormats: Options['formats'];
|
|
8
|
-
|
|
9
|
-
export declare const defaults: Options;
|
|
10
|
-
|
|
11
|
-
declare interface Options {
|
|
12
|
-
formats: {
|
|
13
|
-
[fileExtension: string]: {
|
|
14
|
-
/**
|
|
15
|
-
* When using this file extension in markdown documents,
|
|
16
|
-
* should we only evaluate the code block if the "live"
|
|
17
|
-
* meta is attached to the codefence?
|
|
18
|
-
*
|
|
19
|
-
* If you don't use markdown-embedded rendering,
|
|
20
|
-
* you can ignore this option. Default behavior is "false",
|
|
21
|
-
* but it doesn't matter if you don't render markdown anyway.
|
|
22
|
-
*
|
|
23
|
-
* For example, with `needsLiveMeta: false`:
|
|
24
|
-
* \`\`\`js
|
|
25
|
-
* console.log('hello');
|
|
26
|
-
* \`\`\`
|
|
27
|
-
* will be evaluated and log to the console.
|
|
28
|
-
* However, with `needsLiveMeta: true`, the above snippet would not
|
|
29
|
-
* be evaluated. To evaluate a snippet with `needsLiveMeta: true`:
|
|
30
|
-
* \`\`\`js live
|
|
31
|
-
* console.log('hello');
|
|
32
|
-
* \`\`\`
|
|
33
|
-
*/
|
|
34
|
-
needsLiveMeta?: boolean;
|
|
35
|
-
compiler: () => Promise<{
|
|
36
|
-
/**
|
|
37
|
-
* Convert a string from "fileExtension" to standard JavaScript.
|
|
38
|
-
* This will be loaded as a module and then passed to the render method.
|
|
39
|
-
*/
|
|
40
|
-
compile: (text: string) => Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* For the root of a node rendered for this compiler,
|
|
43
|
-
* how will this particular library / framework
|
|
44
|
-
* render in to the given element?
|
|
45
|
-
*
|
|
46
|
-
* Example:
|
|
47
|
-
* ```js
|
|
48
|
-
* {
|
|
49
|
-
* async compiler() {
|
|
50
|
-
* const { createRoot } = await import('react-dom/client');
|
|
51
|
-
*
|
|
52
|
-
* return {
|
|
53
|
-
* render(element, defaultExport) {
|
|
54
|
-
* const root = createRoot(element);
|
|
55
|
-
*
|
|
56
|
-
* root.render(defaultExport);
|
|
57
|
-
* },
|
|
58
|
-
* // ...
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @param {HTMLElement} the element to render in to, this is provided by repl-sdk.
|
|
65
|
-
* @param {any} the default export from the compiled module.
|
|
66
|
-
*/
|
|
67
|
-
render: (element: HTMLElement, defaultExport: any) => void;
|
|
68
|
-
}>;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { }
|
package/dist/index.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
function assert(message, test) {
|
|
2
|
-
if (!test) {
|
|
3
|
-
throw new Error(message);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
assert(`There is no document. repl-sdk is meant to be ran in a browser`, globalThis.document);
|
|
7
|
-
const defaultFormats = {
|
|
8
|
-
mermaid: {
|
|
9
|
-
compiler: async () => {
|
|
10
|
-
return {
|
|
11
|
-
compile: async (text) => {
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const defaults = {
|
|
18
|
-
formats: defaultFormats
|
|
19
|
-
};
|
|
20
|
-
const secret = Symbol.for("__repl-sdk__compiler__");
|
|
21
|
-
assert(
|
|
22
|
-
`There is already an instance of repl-sdk, and there can only be one. Make sure that your dependency graph is correct.`,
|
|
23
|
-
!globalThis[secret]
|
|
24
|
-
);
|
|
25
|
-
class Compiler {
|
|
26
|
-
/** @type {Options} */
|
|
27
|
-
#options;
|
|
28
|
-
/**
|
|
29
|
-
* Options may be passed to the compiler to add to its behavior.
|
|
30
|
-
*/
|
|
31
|
-
constructor(options = defaults) {
|
|
32
|
-
this.#options = options;
|
|
33
|
-
globalThis[secret] = this;
|
|
34
|
-
globalThis.window.esmsInitOptions = {
|
|
35
|
-
shimMode: true,
|
|
36
|
-
skip: `https://esm.sh/`,
|
|
37
|
-
revokeBlobURLs: true,
|
|
38
|
-
// default false
|
|
39
|
-
// Permit overrides to import maps
|
|
40
|
-
mapOverrides: true,
|
|
41
|
-
// default false
|
|
42
|
-
// Hook all module resolutions
|
|
43
|
-
resolve: (id, parentUrl, resolve) => {
|
|
44
|
-
if (id.startsWith("blob:")) return id;
|
|
45
|
-
if (id.startsWith("https://")) return id;
|
|
46
|
-
console.log("Resolving", id);
|
|
47
|
-
return `https://esm.sh/*${id}`;
|
|
48
|
-
},
|
|
49
|
-
// Hook source fetch function
|
|
50
|
-
fetch: async (url, options2) => {
|
|
51
|
-
console.log(`Fetching`, url);
|
|
52
|
-
if (url.endsWith("example.js")) {
|
|
53
|
-
const transformed = `export const js = 'transformed'`;
|
|
54
|
-
return new Response(new Blob([transformed], { type: "application/javascript" }));
|
|
55
|
-
}
|
|
56
|
-
const response = await fetch(url, options2);
|
|
57
|
-
return response;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @param {string} format
|
|
63
|
-
* @param {string} text
|
|
64
|
-
*/
|
|
65
|
-
async compile(format, text) {
|
|
66
|
-
await import("es-module-shims");
|
|
67
|
-
const compiler = await this.#getCompiler(format);
|
|
68
|
-
const compiledText = await compiler.compile(text);
|
|
69
|
-
const asBlobUrl = textToBlobUrl(compiledText);
|
|
70
|
-
const { default: defaultExport } = await importShim(
|
|
71
|
-
/* @vite-ignore */
|
|
72
|
-
asBlobUrl
|
|
73
|
-
);
|
|
74
|
-
return this.#render(compiler, defaultExport);
|
|
75
|
-
}
|
|
76
|
-
async #getCompiler(format) {
|
|
77
|
-
const config = this.#options.formats[format];
|
|
78
|
-
assert(
|
|
79
|
-
`${format} is not a configured format. The currently configured formats are ${Object.keys(this.#options.formats).join(", ")}`,
|
|
80
|
-
config
|
|
81
|
-
);
|
|
82
|
-
const compiler = await config.compiler();
|
|
83
|
-
return compiler;
|
|
84
|
-
}
|
|
85
|
-
async #render(compiler, whatToRender) {
|
|
86
|
-
const div = this.#createDiv();
|
|
87
|
-
await compiler.render(div, whatToRender);
|
|
88
|
-
return div;
|
|
89
|
-
}
|
|
90
|
-
#createDiv() {
|
|
91
|
-
let div = document.createElement("div");
|
|
92
|
-
div.setAttribute("data-repl-output", "");
|
|
93
|
-
div.id = "some-random-string";
|
|
94
|
-
return div;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function textToBlobUrl(text) {
|
|
98
|
-
const blob = new Blob([text], { type: "text/javascript" });
|
|
99
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
100
|
-
return blobUrl;
|
|
101
|
-
}
|
|
102
|
-
export {
|
|
103
|
-
Compiler,
|
|
104
|
-
defaultFormats,
|
|
105
|
-
defaults
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.js","../src/index.js"],"sourcesContent":["/**\n * @param {string} message\n * @param {unknown} test\n * @asserts test\n */\nexport function assert(message, test) {\n if (!test) {\n throw new Error(message);\n }\n}\n","/**\n * @typedef {import(\"./types.ts\").Options} Options\n */\nimport { assert } from './utils.js';\n\nassert(`There is no document. repl-sdk is meant to be ran in a browser`, globalThis.document);\n\nexport const defaultFormats = {\n mermaid: {\n compiler: async () => {\n return {\n compile: async (text) => {},\n };\n },\n },\n};\n\nexport const defaults = {\n formats: defaultFormats,\n};\n\nconst secret = Symbol.for('__repl-sdk__compiler__');\n\nassert(\n `There is already an instance of repl-sdk, and there can only be one. Make sure that your dependency graph is correct.`,\n !globalThis[secret]\n);\n\nexport class Compiler {\n /** @type {Options} */\n #options;\n\n /**\n * Options may be passed to the compiler to add to its behavior.\n */\n constructor(options = defaults) {\n this.#options = options;\n\n globalThis[secret] = this;\n globalThis.window.esmsInitOptions = {\n shimMode: true,\n skip: `https://esm.sh/`,\n revokeBlobURLs: true, // default false\n // Permit overrides to import maps\n mapOverrides: true, // default false\n // Hook all module resolutions\n resolve: (id, parentUrl, resolve) => {\n if (id.startsWith('blob:')) return id;\n if (id.startsWith('https://')) return id;\n\n console.log('Resolving', id);\n /**\n * TODO: locally defined scope\n * vs\n * proxy to esm.sh\n */\n\n /**\n * For esm.sh, we want all imports to declare they don't want\n * their dependencies bundled. We want to have every import go\n * through this resolve/fetch combo of things so we have a chance\n * to compile if we need to.\n */\n return `https://esm.sh/*${id}`;\n },\n // Hook source fetch function\n fetch: async (url, options) => {\n console.log(`Fetching`, url);\n /**\n * Do transformations here based on file extension\n */\n if (url.endsWith('example.js')) {\n const transformed = `export const js = 'transformed'`;\n return new Response(new Blob([transformed], { type: 'application/javascript' }));\n }\n\n const response = await fetch(url, options);\n\n // if (response.url.endsWith('.ts')) {\n // const source = await response.body();\n // const transformed = tsCompile(source);\n // return new Response(new Blob([transformed], { type: 'application/javascript' }));\n // }\n return response;\n },\n };\n // addShim();\n }\n\n /**\n * @param {string} format\n * @param {string} text\n */\n async compile(format, text) {\n await import('es-module-shims');\n\n const compiler = await this.#getCompiler(format);\n\n // TODO: pass this through es-module-shims\n // for getting the actual module back\n const compiledText = await compiler.compile(text);\n\n const asBlobUrl = textToBlobUrl(compiledText);\n\n const { default: defaultExport } = await importShim(/* @vite-ignore */ asBlobUrl);\n\n return this.#render(compiler, defaultExport);\n }\n\n async #getCompiler(format) {\n const config = this.#options.formats[format];\n\n assert(\n `${format} is not a configured format. ` +\n `The currently configured formats are ${Object.keys(this.#options.formats).join(', ')}`,\n config\n );\n\n const compiler = await config.compiler();\n\n return compiler;\n }\n\n async #render(compiler, whatToRender) {\n const div = this.#createDiv();\n\n await compiler.render(div, whatToRender);\n\n return div;\n }\n\n #createDiv() {\n let div = document.createElement('div');\n div.setAttribute('data-repl-output', '');\n div.id = 'some-random-string';\n return div;\n }\n}\n\nfunction addShim() {\n let url = 'https://ga.jspm.io/npm:es-module-shims@1.10.0/dist/es-module-shims.js';\n\n if (document.querySelector('script[src=\"${url}\"]')) {\n // Shim is already present\n return;\n }\n\n let script = document.createElement('script');\n // script.setAttribute('async', '');\n script.setAttribute('src', `<script async src=\"${url}\"></script>`);\n\n document.head.appendChild(script);\n}\n\n/**\n * @param {string} text\n */\nfunction textToBlobUrl(text) {\n const blob = new Blob([text], { type: 'text/javascript' });\n\n const blobUrl = URL.createObjectURL(blob);\n return blobUrl;\n}\n"],"names":["options"],"mappings":"AAKO,SAAS,OAAO,SAAS,MAAM;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,OAAO;AAAA,EACxB;AACH;ACJA,OAAO,kEAAkE,WAAW,QAAQ;AAEhF,MAAC,iBAAiB;AAAA,EAC5B,SAAS;AAAA,IACP,UAAU,YAAY;AACpB,aAAO;AAAA,QACL,SAAS,OAAO,SAAS;AAAA,QAAE;AAAA,MACnC;AAAA,IACK;AAAA,EACF;AACH;AAEY,MAAC,WAAW;AAAA,EACtB,SAAS;AACX;AAEA,MAAM,SAAS,OAAO,IAAI,wBAAwB;AAElD;AAAA,EACE;AAAA,EACA,CAAC,WAAW,MAAM;AACpB;AAEO,MAAM,SAAS;AAAA;AAAA,EAEpB;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,UAAU,UAAU;AAC9B,SAAK,WAAW;AAEhB,eAAW,MAAM,IAAI;AACrB,eAAW,OAAO,kBAAkB;AAAA,MAClC,UAAU;AAAA,MACV,MAAM;AAAA,MACN,gBAAgB;AAAA;AAAA;AAAA,MAEhB,cAAc;AAAA;AAAA;AAAA,MAEd,SAAS,CAAC,IAAI,WAAW,YAAY;AACnC,YAAI,GAAG,WAAW,OAAO,EAAG,QAAO;AACnC,YAAI,GAAG,WAAW,UAAU,EAAG,QAAO;AAEtC,gBAAQ,IAAI,aAAa,EAAE;AAa3B,eAAO,mBAAmB,EAAE;AAAA,MAC7B;AAAA;AAAA,MAED,OAAO,OAAO,KAAKA,aAAY;AAC7B,gBAAQ,IAAI,YAAY,GAAG;AAI3B,YAAI,IAAI,SAAS,YAAY,GAAG;AAC9B,gBAAM,cAAc;AACpB,iBAAO,IAAI,SAAS,IAAI,KAAK,CAAC,WAAW,GAAG,EAAE,MAAM,yBAA0B,CAAA,CAAC;AAAA,QAChF;AAED,cAAM,WAAW,MAAM,MAAM,KAAKA,QAAO;AAOzC,eAAO;AAAA,MACR;AAAA,IACP;AAAA,EAEG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMD,MAAM,QAAQ,QAAQ,MAAM;AAC1B,UAAM,OAAO,iBAAiB;AAE9B,UAAM,WAAW,MAAM,KAAK,aAAa,MAAM;AAI/C,UAAM,eAAe,MAAM,SAAS,QAAQ,IAAI;AAEhD,UAAM,YAAY,cAAc,YAAY;AAE5C,UAAM,EAAE,SAAS,cAAa,IAAK,MAAM;AAAA;AAAA,MAA8B;AAAA,IAAS;AAEhF,WAAO,KAAK,QAAQ,UAAU,aAAa;AAAA,EAC5C;AAAA,EAED,MAAM,aAAa,QAAQ;AACzB,UAAM,SAAS,KAAK,SAAS,QAAQ,MAAM;AAE3C;AAAA,MACE,GAAG,MAAM,qEACiC,OAAO,KAAK,KAAK,SAAS,OAAO,EAAE,KAAK,IAAI,CAAC;AAAA,MACvF;AAAA,IACN;AAEI,UAAM,WAAW,MAAM,OAAO;AAE9B,WAAO;AAAA,EACR;AAAA,EAED,MAAM,QAAQ,UAAU,cAAc;AACpC,UAAM,MAAM,KAAK;AAEjB,UAAM,SAAS,OAAO,KAAK,YAAY;AAEvC,WAAO;AAAA,EACR;AAAA,EAED,aAAa;AACX,QAAI,MAAM,SAAS,cAAc,KAAK;AACtC,QAAI,aAAa,oBAAoB,EAAE;AACvC,QAAI,KAAK;AACT,WAAO;AAAA,EACR;AACH;AAoBA,SAAS,cAAc,MAAM;AAC3B,QAAM,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,kBAAiB,CAAE;AAEzD,QAAM,UAAU,IAAI,gBAAgB,IAAI;AACxC,SAAO;AACT;"}
|