sketch = {
var canvas, request;
return (draw = (state) => {}, options = {}) => {
const {
setup = () => ({}),
update = (state) => state,
width = 900,
height = 450
} = options || {};
if (!canvas) canvas = html`${p8g.createCanvas(width, height)}`;
if (request) cancelAnimationFrame(request);
mutable state = setup(mutable state || {}) || mutable state;
request = requestAnimationFrame(async function tick() {
mutable state = (await update(mutable state)) || mutable state;
mutable state = (await draw(mutable state)) || mutable state;
request = requestAnimationFrame(tick);
});
invalidation.then(() => cancelAnimationFrame(request));
return canvas;
};
}