From 5b2418701fe4d5f81570544f2b0307d798d15c54 Mon Sep 17 00:00:00 2001 From: 134 Date: Sun, 21 Jun 2026 23:27:56 +0800 Subject: [PATCH] fix: preserve canvas image generation aspect ratio --- components/canvas/CanvasChatPanel.tsx | 48 +++++++++++---------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index c4d56f2e5..23a79819b 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -3660,18 +3660,7 @@ export function CanvasChatPanel({ sourceImageUrls, }); const placeholderNode = placeholderNodes[index]; - const size = anchorNode - ? { - width: Math.max( - 1, - Math.round(Number(anchorNode.size?.width || dimensions.width)) - ), - height: Math.max( - 1, - Math.round(Number(anchorNode.size?.height || dimensions.height)) - ), - } - : { width: dimensions.width, height: dimensions.height }; + const size = { width: dimensions.width, height: dimensions.height }; const position = getAnchoredGenerationPosition({ anchorNode, existingNodes: currentNodes, @@ -8388,10 +8377,12 @@ export function CanvasChatPanel({ : selectedImageNodesRef.current, }); const imageParamSnapshot = imageParamsRef.current || imageParams; - const aspectRatio = - imageParamSnapshot.aspectRatio && imageParamSnapshot.aspectRatio !== "auto" - ? imageParamSnapshot.aspectRatio - : "1:1"; + const hasExplicitAspectRatio = + Boolean(imageParamSnapshot.aspectRatio) && + imageParamSnapshot.aspectRatio !== "auto"; + const aspectRatio = hasExplicitAspectRatio + ? String(imageParamSnapshot.aspectRatio) + : "1:1"; const [ratioWidthRaw, ratioHeightRaw] = aspectRatio.split(":").map((item) => Number(item)); const ratioWidth = Number.isFinite(ratioWidthRaw) && ratioWidthRaw > 0 ? ratioWidthRaw : 1; const ratioHeight = Number.isFinite(ratioHeightRaw) && ratioHeightRaw > 0 ? ratioHeightRaw : 1; @@ -8406,18 +8397,19 @@ export function CanvasChatPanel({ width: Math.max(190, Math.round((baseSide * ratioWidth) / ratioHeight)), height: baseSide, }; - const placeholderSize = anchorNode - ? { - width: Math.max( - 180, - Math.round(Number(anchorNode.size?.width || ratioPlaceholderSize.width)) - ), - height: Math.max( - 180, - Math.round(Number(anchorNode.size?.height || ratioPlaceholderSize.height)) - ), - } - : ratioPlaceholderSize; + const placeholderSize = + anchorNode && !hasExplicitAspectRatio + ? { + width: Math.max( + 180, + Math.round(Number(anchorNode.size?.width || ratioPlaceholderSize.width)) + ), + height: Math.max( + 180, + Math.round(Number(anchorNode.size?.height || ratioPlaceholderSize.height)) + ), + } + : ratioPlaceholderSize; const position = getAnchoredGenerationPosition({ anchorNode, existingNodes: currentNodes,