/** * System preset label templates */ import type { LabelTemplate } from '../types/labelTemplate'; import { createDefaultElement } from '../types/labelTemplate'; /** Preset template definitions (without id - id assigned when applied) */ export interface PresetTemplateDef { name: string; labelType: LabelTemplate['labelType']; unit: LabelTemplate['unit']; width: number; height: number; appliedLocation: LabelTemplate['appliedLocation']; elements: Array<{ type: Parameters[0]; x: number; y: number; width?: number; height?: number; config?: Record; }>; } export const PRESET_TEMPLATES: PresetTemplateDef[] = [ { name: 'Price Label (Basic)', labelType: 'PRICE', unit: 'cm', width: 6, height: 4, appliedLocation: 'ALL', elements: [ { type: 'TEXT_PRODUCT', x: 20, y: 20, width: 180, height: 28, config: { text: 'Product Name', fontSize: 14 } }, { type: 'TEXT_PRICE', x: 20, y: 55, width: 100, height: 28, config: { text: '0.00', prefix: '$', fontSize: 18 } }, { type: 'BARCODE', x: 20, y: 95, width: 160, height: 48, config: { data: '123456789' } }, ], }, { name: 'Price Label (with QR)', labelType: 'PRICE', unit: 'cm', width: 6, height: 4, appliedLocation: 'ALL', elements: [ { type: 'TEXT_PRODUCT', x: 20, y: 20, width: 140, height: 24, config: { text: 'Product Name', fontSize: 12 } }, { type: 'TEXT_PRICE', x: 20, y: 50, width: 80, height: 24, config: { text: '0.00', prefix: '$', fontSize: 16 } }, { type: 'QRCODE', x: 180, y: 20, width: 60, height: 60, config: { data: 'https://example.com' } }, { type: 'BARCODE', x: 20, y: 90, width: 180, height: 40, config: { data: '123456789' } }, ], }, { name: 'Nutrition Label', labelType: 'NUTRITION', unit: 'cm', width: 6, height: 8, appliedLocation: 'ALL', elements: [ { type: 'TEXT_PRODUCT', x: 20, y: 20, width: 180, height: 24, config: { text: 'Product Name', fontSize: 14 } }, { type: 'NUTRITION', x: 20, y: 55, width: 200, height: 120, config: { calories: 120, fat: '5g', protein: '3g', carbs: '10g' } }, { type: 'DATE', x: 20, y: 190, width: 120, height: 24, config: { format: 'YYYY-MM-DD' } }, ], }, { name: 'Shipping Label', labelType: 'SHIPPING', unit: 'inch', width: 4, height: 6, appliedLocation: 'ALL', elements: [ { type: 'TEXT_STATIC', x: 20, y: 20, width: 200, height: 24, config: { text: 'Ship To:', fontSize: 12 } }, { type: 'TEXT_STATIC', x: 20, y: 50, width: 200, height: 60, config: { text: 'Address Line 1\nAddress Line 2\nCity, State ZIP', fontSize: 11 } }, { type: 'BARCODE', x: 20, y: 130, width: 200, height: 50, config: { data: '1234567890123' } }, { type: 'QRCODE', x: 240, y: 20, width: 80, height: 80, config: { data: 'https://tracking.example.com/123' } }, ], }, { name: 'Blank (6×4 cm)', labelType: 'PRICE', unit: 'cm', width: 6, height: 4, appliedLocation: 'ALL', elements: [], }, { name: 'Blank (4×6 inch)', labelType: 'PRICE', unit: 'inch', width: 4, height: 6, appliedLocation: 'ALL', elements: [], }, ]; /** Convert preset to full LabelTemplate with generated element ids */ export function presetToTemplate( preset: PresetTemplateDef, templateId: string ): LabelTemplate { const elements = preset.elements.map((e) => { const el = createDefaultElement(e.type, e.x, e.y); el.x = e.x; el.y = e.y; if (e.width != null) el.width = e.width; if (e.height != null) el.height = e.height; if (e.config) el.config = { ...el.config, ...e.config }; return el; }); return { id: templateId, name: preset.name, labelType: preset.labelType, unit: preset.unit, width: preset.width, height: preset.height, appliedLocation: preset.appliedLocation, showRuler: true, showGrid: true, elements, }; }