| 1 | <html> |
| 2 | <head> |
| 3 | <meta charset="utf-8"> |
| 4 | <script src="wasm_exec.js"></script> |
| 5 | </head> |
| 6 | <body style="align: center"> |
| 7 | <h3>WebAssembly Demo</h3> |
| 8 | <textarea style="width: 400px; height: 240px; margin-bottom: 20px" readonly> |
| 9 | let option = { |
| 10 | encodeVersion: 0, |
| 11 | encodeMode: 2, |
| 12 | encodeECLevel: "Q", |
| 13 | |
| 14 | outputBgColor: "#123123", |
| 15 | outputBgTransparent: true, |
| 16 | outputQrColor: "#666666", |
| 17 | outputQrWidth: 20, |
| 18 | outputCircleShape: true, |
| 19 | outputImageEncoder: "png", |
| 20 | outputMargin: 20, |
| 21 | } |
| 22 | </textarea> |
| 23 | <br/> |
| 24 | <img id="qrc" src="" style="width: 400px; margin-bottom: 20px"/> |
| 25 | <br/> |
| 26 | <button onClick="runFunction()" |
| 27 | style="width: 100px; height: 30px; font-size: 20px; background-color: #00bcd4">run</button> |
| 28 | </body> |
| 29 | |
| 30 | <script> |
| 31 | const go = new Go(); |
| 32 | WebAssembly.instantiateStreaming(fetch("com.github.yeqown.goqrcode.wasm"), go.importObject).then( |
| 33 | result => { |
| 34 | go.run(result.instance) |
| 35 | } |
| 36 | ); |
| 37 | |
| 38 | const runFunction = function runFunction() { |
| 39 | let option = { |
| 40 | encodeVersion: 0, |
| 41 | encodeMode: 2, |
| 42 | encodeECLevel: "Q", |
| 43 | |
| 44 | outputBgColor: "#123123", |
| 45 | outputBgTransparent: true, |
| 46 | outputQrColor: "#666666", |
| 47 | outputQrWidth: 20, |
| 48 | outputCircleShape: true, |
| 49 | outputImageEncoder: "png", |
| 50 | outputMargin: 20, |
| 51 | } |
| 52 | let rr = generateQRCode("https://github.com/yeqown", option); |
| 53 | console.log(generateQRCode); |
| 54 | console.log("runFunction called", rr); |
| 55 | if (rr.success) { |
| 56 | document.getElementById("qrc").src = "data:image/png;base64," + rr.base64EncodedImage; |
| 57 | } |
| 58 | } |
| 59 | </script> |
| 60 | </html> |