diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx index 8df4e4adf..62ce5f4d5 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx @@ -140,6 +140,31 @@ export function PreviewWorkspace({ setViewportState(next); }, []); + useEffect(() => { + if (!activeImageId || !logicalSize) return; + const element = viewportElementRef.current; + setViewport( + fitViewportToBounds({ + bounds: { + x: 0, + y: 0, + width: logicalSize.width, + height: logicalSize.height, + }, + canvasSize: { + width: element?.clientWidth || canvasSize.width, + height: element?.clientHeight || canvasSize.height, + }, + }), + ); + }, [ + activeImageId, + canvasSize.height, + canvasSize.width, + logicalSize, + setViewport, + ]); + const scaleViewportFromCenter = useCallback( (nextScale: number) => { const element = viewportElementRef.current;