-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c56affc
commit da93e3c
Showing
1 changed file
with
27 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,46 @@ | ||
/** | ||
* @param {string} content - The content. | ||
* @returns {string} data:text string | ||
*/ | ||
function importFile(content) { | ||
return "data:text/javascript;base64," + btoa(content); | ||
} | ||
let rti = "../"; | ||
if (location.host === 'runtimetypeinspector.org') { | ||
rti = '/node_modules/runtime-type-inspector/'; | ||
rti = '/node_modules/runtime-type-inspector/'; | ||
} | ||
const imports = { | ||
"@runtime-type-inspector/runtime": rti + 'src-runtime/index.mjs', | ||
"runtime-type-inspector/": rti, | ||
//"@babel/core": "./babel-core.mjs", | ||
"@babel/parser": "./babel-parser.mjs", | ||
//"@babel/helper-plugin-utils": "./babel-helper-plugin-utils.mjs", | ||
//"@babel/plugin-syntax-typescript": "./babel-plugin-syntax-typescript.mjs", | ||
"fs": importFile("export default {};"), | ||
"typescript": importFile("export default ts;"), // UMD import | ||
/* | ||
"path": importFile("export default {};"), | ||
"stream/web": importFile("export default {};"), | ||
"sharp": importFile("export default {};"), | ||
"onnxruntime-node": importFile("export default {};"), | ||
"onnxruntime-web": importFile(` | ||
//await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); | ||
await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); | ||
//http://127.0.0.1/transformer/onnxruntime/js/common/dist/ | ||
//await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); | ||
//await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); | ||
//await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); | ||
let ONNX = globalThis.ort; | ||
export default ONNX; | ||
export { | ||
ONNX | ||
}; | ||
`), | ||
*/ | ||
// "path": importFile("export default {};"), | ||
// "stream/web": importFile("export default {};"), | ||
// "sharp": importFile("export default {};"), | ||
// "onnxruntime-node": importFile("export default {};"), | ||
// "onnxruntime-web": importFile(` | ||
// //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); | ||
// await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); | ||
// //http://127.0.0.1/transformer/onnxruntime/js/common/dist/ | ||
// //await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); | ||
// //await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); | ||
// //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); | ||
// let ONNX = globalThis.ort; | ||
// export default ONNX; | ||
// export { | ||
// ONNX | ||
// }; | ||
// `), | ||
}; | ||
const importmap = document.createElement("script"); | ||
importmap.type = "importmap"; | ||
importmap.textContent = JSON.stringify({imports}); | ||
const parent = document.body || document.head; | ||
if (!parent) { | ||
throw "neither <body> nor <head> available to append importmap"; | ||
const dom = document.body || document.head; | ||
if (!dom) { | ||
throw new Error("neither <body> nor <head> available to append importmap"); | ||
} | ||
parent.append(importmap); | ||
dom.append(importmap); |