feat(view): add canvas viewport shell

This commit is contained in:
syntaxbullet
2026-07-03 09:36:25 +02:00
parent 51027ce535
commit bd60d64bc0

30
view/CanvasViewport.tsx Normal file
View File

@@ -0,0 +1,30 @@
import { useEffect, useRef } from "react";
import type { AppStore } from "@editor/store";
export type CanvasViewportProps = {
store: AppStore;
};
export function CanvasViewport({ store }: CanvasViewportProps) {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const resizeObserver = new ResizeObserver(([entry]) => {
if (!entry) return;
const width = Math.floor(entry.contentRect.width);
const height = Math.floor(entry.contentRect.height);
canvas.width = width;
canvas.height = height;
store.dispatch("viewport.setSize", { w: width, h: height });
});
resizeObserver.observe(canvas);
return () => resizeObserver.disconnect();
}, [store]);
return <canvas ref={canvasRef} className="h-full w-full" />;
}