2024-11-22 15:48:17 +08:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'/>
|
|
|
|
<style type="text/css">
|
|
|
|
html, body {
|
|
|
|
margin: 0;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
min-height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
body {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
2024-11-22 19:25:57 +08:00
|
|
|
#output, #canvas {
|
2024-11-22 15:48:17 +08:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
2024-11-22 19:25:57 +08:00
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
background-color: burlywood;
|
2024-11-22 15:48:17 +08:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="output">
|
|
|
|
<canvas id="canvas"></canvas>
|
|
|
|
</p>
|
|
|
|
<script>
|
|
|
|
var siteURL = new URL(window.location.href);
|
|
|
|
var canvas = document.getElementById('canvas');
|
2024-11-22 19:25:57 +08:00
|
|
|
let rect = canvas.getBoundingClientRect();
|
|
|
|
canvas.setAttribute("width", rect.width);
|
|
|
|
canvas.setAttribute("height", rect.height);
|
2024-11-22 15:48:17 +08:00
|
|
|
var Module = {
|
|
|
|
print: function(text) {
|
|
|
|
console.log(text);
|
|
|
|
},
|
|
|
|
printErr: function(text) {
|
|
|
|
console.error(text);
|
|
|
|
},
|
|
|
|
canvas: (function() {
|
|
|
|
return canvas;
|
|
|
|
})(),
|
2024-11-22 19:25:57 +08:00
|
|
|
arguments: [ String(rect.width), String(rect.height), siteURL.searchParams.get("example") ?? "default" ],
|
|
|
|
onRuntimeInitialized: function () {
|
|
|
|
// const canvas = document.getElementById('canvas');
|
|
|
|
// const observer = new ResizeObserver(entries => {
|
|
|
|
// for (let entry of entries) {
|
|
|
|
// const width = entry.contentRect.width;
|
|
|
|
// const height = entry.contentRect.height;
|
|
|
|
// Module.setCanvasSize(width, height); // 调用 Wasm 函数
|
|
|
|
// canvas.setAttribute("width", width);
|
|
|
|
// canvas.setAttribute("height", height);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// observer.observe(canvas);
|
|
|
|
}
|
2024-11-22 15:48:17 +08:00
|
|
|
};
|
|
|
|
window.addEventListener("click", () => window.focus());
|
|
|
|
</script>
|
|
|
|
{{{ SCRIPT }}}
|
|
|
|
</body>
|
|
|
|
</html>
|