fix: stabilize psd template preview size
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-03-31 20:58:02 +08:00
parent dceebf0652
commit 89dfc39284

View File

@ -54,6 +54,8 @@ import { resolveTextLayout } from "@/lib/agents/psd-text-layout";
const fetcher = (url: string) => fetch(url, { cache: "no-store" }).then((res) => res.json());
const PREVIEW_VIEWPORT_PADDING = 56;
const PREVIEW_STAGE_MAX_SCALE = 0.82;
const PREVIEW_STAGE_TARGET_WIDTH = 760;
const PREVIEW_STAGE_TARGET_HEIGHT = 760;
function createInitialState(template: AgentPsdTemplate | null, sourceImageUrl: string) {
const imageAssignments: Record<string, string> = {};
@ -477,8 +479,14 @@ export function AgentPsdTemplateEditorDialog({
const updateScale = () => {
const rect = element.getBoundingClientRect();
const availableWidth = Math.max(240, rect.width - PREVIEW_VIEWPORT_PADDING);
const availableHeight = Math.max(240, rect.height - PREVIEW_VIEWPORT_PADDING);
const availableWidth = Math.max(
240,
Math.min(PREVIEW_STAGE_TARGET_WIDTH, rect.width - PREVIEW_VIEWPORT_PADDING)
);
const availableHeight = Math.max(
240,
Math.min(PREVIEW_STAGE_TARGET_HEIGHT, rect.height - PREVIEW_VIEWPORT_PADDING)
);
const nextScale = Math.min(
availableWidth / Math.max(1, selectedTemplate.width),
availableHeight / Math.max(1, selectedTemplate.height),