|
| 1 | +/** |
| 2 | + * @param {string} content - The content. |
| 3 | + * @returns {string} data:text string |
| 4 | + */ |
1 | 5 | function importFile(content) {
|
2 | 6 | return "data:text/javascript;base64," + btoa(content);
|
3 | 7 | }
|
4 | 8 | let rti = "../";
|
5 | 9 | if (location.host === 'runtimetypeinspector.org') {
|
6 |
| - rti = '/node_modules/runtime-type-inspector/'; |
| 10 | + rti = '/node_modules/runtime-type-inspector/'; |
7 | 11 | }
|
8 | 12 | const imports = {
|
| 13 | + "@runtime-type-inspector/runtime": rti + 'src-runtime/index.mjs', |
9 | 14 | "runtime-type-inspector/": rti,
|
10 | 15 | //"@babel/core": "./babel-core.mjs",
|
11 | 16 | "@babel/parser": "./babel-parser.mjs",
|
12 | 17 | //"@babel/helper-plugin-utils": "./babel-helper-plugin-utils.mjs",
|
13 | 18 | //"@babel/plugin-syntax-typescript": "./babel-plugin-syntax-typescript.mjs",
|
14 | 19 | "fs": importFile("export default {};"),
|
15 | 20 | "typescript": importFile("export default ts;"), // UMD import
|
16 |
| - /* |
17 |
| - "path": importFile("export default {};"), |
18 |
| - "stream/web": importFile("export default {};"), |
19 |
| - "sharp": importFile("export default {};"), |
20 |
| - "onnxruntime-node": importFile("export default {};"), |
21 |
| - "onnxruntime-web": importFile(` |
22 |
| - //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); |
23 |
| - await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); |
24 |
| - //http://127.0.0.1/transformer/onnxruntime/js/common/dist/ |
25 |
| - //await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); |
26 |
| - //await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); |
27 |
| - //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); |
28 |
| - let ONNX = globalThis.ort; |
29 |
| - export default ONNX; |
30 |
| - export { |
31 |
| - ONNX |
32 |
| - }; |
33 |
| - `), |
34 |
| - */ |
| 21 | + // "path": importFile("export default {};"), |
| 22 | + // "stream/web": importFile("export default {};"), |
| 23 | + // "sharp": importFile("export default {};"), |
| 24 | + // "onnxruntime-node": importFile("export default {};"), |
| 25 | + // "onnxruntime-web": importFile(` |
| 26 | + // //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); |
| 27 | + // await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); |
| 28 | + // //http://127.0.0.1/transformer/onnxruntime/js/common/dist/ |
| 29 | + // //await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); |
| 30 | + // //await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); |
| 31 | + // //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); |
| 32 | + // let ONNX = globalThis.ort; |
| 33 | + // export default ONNX; |
| 34 | + // export { |
| 35 | + // ONNX |
| 36 | + // }; |
| 37 | + // `), |
35 | 38 | };
|
36 | 39 | const importmap = document.createElement("script");
|
37 | 40 | importmap.type = "importmap";
|
38 | 41 | importmap.textContent = JSON.stringify({imports});
|
39 |
| -const parent = document.body || document.head; |
40 |
| -if (!parent) { |
41 |
| - throw "neither <body> nor <head> available to append importmap"; |
| 42 | +const dom = document.body || document.head; |
| 43 | +if (!dom) { |
| 44 | + throw new Error("neither <body> nor <head> available to append importmap"); |
42 | 45 | }
|
43 |
| -parent.append(importmap); |
| 46 | +dom.append(importmap); |
0 commit comments