-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
56 lines (48 loc) · 2.15 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<title>Audio Tests</title>
<script type="importmap">
{
"imports": {
"twr-wasm": "../../lib-js/index.js"
}
}
</script>
</head>
<body>
<div id="window-resizable-div" style="resize:both;overflow:hidden;width:640px;height:480px;min-width:200px;min-height:200px;">
<canvas id="window" width="640px" height="480px" tabindex="1"></canvas>
</div>
<script type="module">
"use strict";
import {twrWasmModule, twrWasmModuleAsync, twrConsoleWindow} from "twr-wasm";
const is_async = window.location.hash=="#async";
const modCon = is_async ? twrWasmModuleAsync : twrWasmModule;
const windowCanvas = document.getElementById("window");
if (windowCanvas == undefined) throw new Error(`Window example: Couldn't find window canvas!`);
const windowConsole = new twrConsoleWindow(windowCanvas);
const mod = new modCon({io:{
window: windowConsole,
}});
await mod.loadWasm(is_async ? "./window-a.wasm" : "./window.wasm");
await mod.callC(["init"]);
const windowDiv = document.getElementById("window-resizable-div");
if (windowDiv == undefined) throw new Error(`Window example: couldn't find window canvas div!`);
// window.windowConsole = windowConsole;
let prevDivWidth = windowDiv.clientWidth;
let prevDivHeight = windowDiv.clientHeight;
let resizeObserver = new ResizeObserver(() => {
const width = windowDiv.clientWidth;
const height = windowDiv.clientHeight;
if (width != prevDivWidth || height != prevDivHeight) {
prevDivWidth = width;
prevDivHeight = height;
console.log(`resizing: ${width}, ${height}`);
windowConsole.resizeWindow(width, height);
}
});
resizeObserver.observe(windowDiv);
</script>
</body>
</html>