Spaces:
Running
Running
<script> | |
// no good unbloated molecule sketch tool. | |
// we load ketcher in frame if user want's to draw | |
// create event dispatcher | |
import { createEventDispatcher } from "svelte"; | |
const dispatch = createEventDispatcher(); | |
import ClearButton from "./ClearButton.svelte"; | |
function getsmiles() { | |
const iframe = document.querySelector("iframe"); | |
const ketcher = iframe.contentWindow.ketcher; | |
ketcher.getSmiles().then((smiles) => { | |
dispatch("moleculesketched", { | |
smiles: smiles, | |
} | |
{ | |
var loadingDiv = document.getElementById("loading"); | |
loadingDiv.style.display = "flex"; | |
//load css | |
let url = | |
"https://huggingface.co/datasets/simonduerr/ketcher-2.7.2/raw/main/static/css/main.6a646761.css"; | |
fetch(url) | |
.then((res) => res.text()) | |
.then((text) => { | |
const style = document.createElement("style"); | |
style.textContent = text; | |
document.head.appendChild(style); | |
}); | |
//load ketcher | |
url = | |
"https://huggingface.co/datasets/simonduerr/ketcher-2.7.2/resolve/main/static/js/main.5445f351.js"; | |
fetch(url) | |
.then((res) => res.text()) | |
.then((text) => { | |
const script = document.createElement("script"); | |
//script.type = "module" | |
script.src = URL.createObjectURL( | |
new Blob([text], { type: "application/javascript" }) | |
); | |
document.head.appendChild(script); | |
loadingDiv.style.display = "none"; | |
}); | |
}; | |
</\script> | |
</body> | |
`; | |
</script> | |
<ClearButton on:clear={getsmiles} /> | |
<div class="composerWrapper"> | |
<iframe srcdoc={ketcherDoc} | |
{ | |
width: 100%; | |
height: 650px; | |
} | |