ivanceras / svgbob

Convert your ascii diagram scribbles into happy little SVG
http://ivanceras.github.io/svgbob-editor/
Apache License 2.0
3.83k stars 108 forks source link

Importing svgbob as wasm within an html file #63

Closed ramu-r closed 3 years ago

ramu-r commented 4 years ago

I compiled svgbob using wasm-pack build --target web and I'm trying to import it into an html file as described here but it gives me import errors and I don't know what I'm supposed to import. I tried importing both svgbob and to_svg neither of which worked.

Can you give me any pointers on how to use this within an html file?

ivanceras commented 4 years ago

What does the error says?

ramu-r commented 4 years ago

The error says Uncaught SyntaxError: import not found: svgbob I tried importing some other things too and none of them worked.

The html file basically contains

    <script type="module">
      import init, { svgbob } from './svgbob.js';

      async function run() {
        const result = svgbob.to_svg("------------->");
        document.write(result);
        console.log(`${result}`);
      }

      run();
    </script>

My understanding of rust is pretty non existent and I wouldn't know if I'm doing something wrong here. I also found svgbob-wasm which seems to get the job done but uses an older version of svgbob.

So if svgbob wasn't meant to do this kinda thing, this ticket can be closed. But if this is something easily solvable that I'm overlooking, I'd like to try compiling svgbob to wasm and use it.

ivanceras commented 3 years ago

Please refer to wasm-bindgen tutorial on calling rust from javascript. This requires setting up a new crate which wraps svgbob functionality and exposed via wasm-bindgen to your application.