|
|
|
@ -12,6 +12,18 @@ export type App = {
|
|
|
|
export function runApp(app: App, canvas: HTMLCanvasElement) {
|
|
|
|
export function runApp(app: App, canvas: HTMLCanvasElement) {
|
|
|
|
let state = app.init;
|
|
|
|
let state = app.init;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setupCanvas() {
|
|
|
|
|
|
|
|
const dpr = window.devicePixelRatio || 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvas.width = window.innerWidth * dpr;
|
|
|
|
|
|
|
|
canvas.height = window.innerHeight * dpr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvas.style.width = window.innerWidth + 'px';
|
|
|
|
|
|
|
|
canvas.style.height = window.innerHeight + 'px';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setupCanvas();
|
|
|
|
|
|
|
|
|
|
|
|
function rerender() {
|
|
|
|
function rerender() {
|
|
|
|
if (app.view.kind !== 'closure')
|
|
|
|
if (app.view.kind !== 'closure')
|
|
|
|
throw new Error('view must be a function');
|
|
|
|
throw new Error('view must be a function');
|
|
|
|
@ -19,8 +31,8 @@ export function runApp(app: App, canvas: HTMLCanvasElement) {
|
|
|
|
const viewport: Value = {
|
|
|
|
const viewport: Value = {
|
|
|
|
kind: 'record',
|
|
|
|
kind: 'record',
|
|
|
|
fields: {
|
|
|
|
fields: {
|
|
|
|
width: { kind: 'int', value: canvas.width },
|
|
|
|
width: { kind: 'int', value: window.innerWidth },
|
|
|
|
height: { kind: 'int', value: canvas.height }
|
|
|
|
height: { kind: 'int', value: window.innerHeight }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,5 +89,10 @@ export function runApp(app: App, canvas: HTMLCanvasElement) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', (e) => {
|
|
|
|
|
|
|
|
setupCanvas();
|
|
|
|
|
|
|
|
rerender();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
rerender();
|
|
|
|
rerender();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|