diff --git a/src/app/api/orders/[id]/design-spec/route.ts b/src/app/api/orders/[id]/design-spec/route.ts index 0344a40..092080c 100644 --- a/src/app/api/orders/[id]/design-spec/route.ts +++ b/src/app/api/orders/[id]/design-spec/route.ts @@ -42,10 +42,95 @@ export async function GET(req: Request, { params }: { params: { id: string } }) const printAreaWidthPx = DISPLAY * (printArea.wPct / 100); const printAreaHeightPx = DISPLAY * (printArea.hPct / 100); + + // Scale: how many pixels per millimeter const pxPerMm = printAreaWidthPx / printAreaWidthMm; - // Convert pixel positions to CM - const convertToCm = (px: number) => (px / pxPerMm / 10).toFixed(1); + // 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); + }; + + 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 ''; + + return ` +
Design on product (reference only) — with measurement guides
+━━ 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.)
+| Element | +Type | +Position (CM) | +Size (CM) | +Details | +
|---|---|---|---|---|
| E${idx + 1} | +${el.type === 'text' ? '📝 Text' : '🖼️ Image'} | +X: ${convertToCm(el.x)} | Y: ${convertToCm(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 + Color: ${el.fill} + Text: "${el.text}" + Rotation: ${Math.round(el.rotation)}° + ` : ` + Rotation: ${Math.round(el.rotation)}° + `} + |
+
Order Date: ${new Date(order.createdAt).toLocaleDateString()}
- ${design.front && design.front.length > 0 ? ` -Design on product (reference only)
-| Element | -Type | -Position (CM) | -Size (CM) | -Details | -
|---|---|---|---|---|
| ${idx + 1} | -${el.type === 'text' ? '📝 Text' : '🖼️ Image'} | -X: ${convertToCm(el.x)} | Y: ${convertToCm(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 - Color: ${el.fill} - Text: "${el.text}" - Rotation: ${Math.round(el.rotation)}° - ` : ` - Rotation: ${Math.round(el.rotation)}° - `} - |
-
Design on product (reference only)
-| Element | -Type | -Position (CM) | -Size (CM) | -Details | -
|---|---|---|---|---|
| ${idx + 1} | -${el.type === 'text' ? '📝 Text' : '🖼️ Image'} | -X: ${convertToCm(el.x)} | Y: ${convertToCm(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 - Color: ${el.fill} - Text: "${el.text}" - Rotation: ${Math.round(el.rotation)}° - ` : ` - Rotation: ${Math.round(el.rotation)}° - `} - |
-
Notes: