From c202dd48a8c927d45cb76575261bacf9dcf9f5a4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 1 Apr 2026 19:41:13 +0800 Subject: [PATCH] feat: redesign psd scale control and fix >100% scaling behavior --- .../agents/AgentPsdTemplateEditorDialog.tsx | 78 ++++++++++++++----- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/components/agents/AgentPsdTemplateEditorDialog.tsx b/components/agents/AgentPsdTemplateEditorDialog.tsx index e04bd5459..4c3f23cfe 100644 --- a/components/agents/AgentPsdTemplateEditorDialog.tsx +++ b/components/agents/AgentPsdTemplateEditorDialog.tsx @@ -83,6 +83,15 @@ const PREVIEW_VIEWPORT_PADDING = 56; const PREVIEW_STAGE_MAX_SCALE = 0.82; const PREVIEW_STAGE_TARGET_WIDTH = 760; const PREVIEW_STAGE_TARGET_HEIGHT = 760; +const MIN_IMAGE_SCALE = 0.4; +const MAX_IMAGE_SCALE = 3; + +function clampImageScale(value: number) { + if (!Number.isFinite(value)) { + return 1; + } + return Math.max(MIN_IMAGE_SCALE, Math.min(MAX_IMAGE_SCALE, value)); +} function createInitialState(template: AgentPsdTemplate | null, sourceImageUrl: string) { const imageAssignments: Record = {}; @@ -692,7 +701,7 @@ export function AgentPsdTemplateEditorDialog({ function nudgeImageScale(layerId: string, delta: number) { updateImagePlacement(layerId, (current) => ({ ...current, - scale: Math.max(0.4, Math.min(3, Number((current.scale + delta).toFixed(2)))), + scale: Number(clampImageScale(current.scale + delta).toFixed(2)), })); } @@ -1291,26 +1300,55 @@ export function AgentPsdTemplateEditorDialog({ 缩放 - {Math.round(selectedImagePlacement.scale * 100)}% + + {Math.round(selectedImagePlacement.scale * 100)}% + + +
+
+ + { + const newScale = clampImageScale(value[0] || 1); + // offset 本身就是相对中心位移,缩放时不应按比例放大,否则会导致画面偏移看起来像“变形”。 + updateImagePlacement(selectedImageLayer.id, (current) => ({ + ...current, + scale: newScale, + })); + }} + /> + +
+
+ 40% + 100% + 300% +
- { - const newScale = value[0] || 1; - updateImagePlacement(selectedImageLayer.id, (current) => { - // 以中心点缩放,调整偏移量保持中心位置不变 - const scaleDiff = newScale / current.scale; - return { - scale: newScale, - offsetX: current.offsetX * scaleDiff, - offsetY: current.offsetY * scaleDiff, - }; - }); - }} - />