|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>PPTK test page</title>
|
|
|
|
<script type="module" defer>
|
|
|
|
import * as pptk from "../../src";
|
|
|
|
|
|
|
|
let canvas = document.getElementById("canvas");
|
|
|
|
let zoomState = null;
|
|
|
|
pptk.attachCanvas(canvas, {
|
|
|
|
onResize: draw
|
|
|
|
});
|
|
|
|
|
|
|
|
pptk.attachPannable(canvas, {
|
|
|
|
preventDefault: true,
|
|
|
|
center: () => [canvas.width / 2, canvas.height / 2],
|
|
|
|
onUpdate: (state) => {
|
|
|
|
zoomState = state;
|
|
|
|
draw(canvas);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
let ctx = canvas.getContext("2d");
|
|
|
|
|
|
|
|
function draw(canvas) {
|
|
|
|
if (!zoomState) return;
|
|
|
|
|
|
|
|
ctx.fillStyle = "gray";
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.ellipse(
|
|
|
|
...zoomState.get(0, 0),
|
|
|
|
5 * zoomState.scale,
|
|
|
|
5 * zoomState.scale,
|
|
|
|
0,
|
|
|
|
Math.PI * 2,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
ctx.fillStyle = "white";
|
|
|
|
ctx.fill();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
width: 100vw;
|
|
|
|
width: 100dvw;
|
|
|
|
|
|
|
|
height: 100vh;
|
|
|
|
height: 100dvh;
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.container {
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
width: 80vw;
|
|
|
|
height: 80vh;
|
|
|
|
background: black;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<canvas id="canvas">
|
|
|
|
This test requires canvas support
|
|
|
|
</canvas>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|