diff --git a/src/app/api/orders/[id]/design-spec/route.ts b/src/app/api/orders/[id]/design-spec/route.ts index 092080c..558d3d3 100644 --- a/src/app/api/orders/[id]/design-spec/route.ts +++ b/src/app/api/orders/[id]/design-spec/route.ts @@ -40,21 +40,31 @@ export async function GET(req: Request, { params }: { params: { id: string } }) hPct: number; }; + const printAreaStartX = DISPLAY * (printArea.xPct / 100); + const printAreaStartY = DISPLAY * (printArea.yPct / 100); const printAreaWidthPx = DISPLAY * (printArea.wPct / 100); const printAreaHeightPx = DISPLAY * (printArea.hPct / 100); - // Scale: how many pixels per millimeter - const pxPerMm = printAreaWidthPx / printAreaWidthMm; + // Scale: how many millimeters per pixel + const mmPerPx = printAreaWidthMm / printAreaWidthPx; - // Convert pixel measurements to CM (divide by pxPerMm to get mm, then divide by 10 for cm) - const convertToCm = (px: number) => { - const mm = px / pxPerMm; - return (mm / 10).toFixed(1); + // Convert pixel measurements to CM + // First: subtract the print area offset to get position within print area + // Then: multiply by mmPerPx to get millimeters + // Finally: divide by 10 to get centimeters + const convertToCm = (px: number, elementPx: number | null = null) => { + if (elementPx !== null) { + // For element positions: subtract offset and scale + const relativeToStart = elementPx - px; + const mm = Math.max(0, relativeToStart * mmPerPx); + return (mm / 10).toFixed(1); + } else { + // For dimensions: just scale + const mm = px * mmPerPx; + return (mm / 10).toFixed(1); + } }; - const printAreaStartX = DISPLAY * (printArea.xPct / 100); - const printAreaStartY = DISPLAY * (printArea.yPct / 100); - const generateDesignSection = (designElements: any[], side: 'Front' | 'Back', placement: string | null, designPreview: string | null) => { if (!designElements || designElements.length === 0) return ''; @@ -68,31 +78,38 @@ export async function GET(req: Request, { params }: { params: { id: string } }) ${placement ? `
-

Design on product (reference only) — with measurement guides

-
- ${side} design placement - +

Design on product with measurement guides

+
+ ${side} design placement + - + - - + + - - + + - + + X (0cm) + Y (0cm) + + ${designElements.map((el, idx) => ` - - E${idx + 1} + + E${idx + 1} `).join('')}
-
-

━━ Red dashed: Print area boundary

-

━ Blue: X-axis (0cm at left)

-

━ Green: Y-axis (0cm at top)

-

● Orange circles: Element positions with labels (E1, E2, etc.)

+
+

━━ Red dashed line: Print area boundary

+

━ Blue line: X-axis (horizontal, 0cm at left)

+

━ Green line: Y-axis (vertical, 0cm at top)

+

● Orange circles: Element positions (E1, E2, etc.)

` : ''} @@ -112,11 +129,11 @@ export async function GET(req: Request, { params }: { params: { id: string } }) E${idx + 1} ${el.type === 'text' ? '📝 Text' : '🖼️ Image'} - X: ${convertToCm(el.x)} | Y: ${convertToCm(el.y)} + X: ${convertToCm(printAreaStartX, el.x)} | Y: ${convertToCm(printAreaStartY, el.y)} ${el.type === 'image' ? `${convertToCm(el.width)} × ${convertToCm(el.height)}` : 'N/A'} ${el.type === 'text' ? ` - Font: ${el.fontFamily}, ${Math.round(el.fontSize / pxPerMm * 10 / 10)}pt
+ Font: ${el.fontFamily}, ${Math.round(el.fontSize * mmPerPx / 10)}pt
Color: ${el.fill}
Text: "${el.text}"
Rotation: ${Math.round(el.rotation)}° @@ -173,8 +190,7 @@ export async function GET(req: Request, { params }: { params: { id: string } }) .mockup-image { max-width: 100%; height: auto; - border: 1px solid #ddd; - margin: 10px 0; + display: block; } .measurements-table { width: 100%; @@ -226,8 +242,8 @@ export async function GET(req: Request, { params }: { params: { id: string } })

Notes: