/** * Printer types * Type definitions for printer operations */ import type {EncodingType, Node} from '../compiler' import type {PrintError} from '../shared' // ============= Core Types ============= /** * Printer configuration for each printer */ export interface PrinterConfig { address: string // "bt:MAC" | "lan:IP:PORT" | "ble:UUID" copies?: number // Number of copies (default: 1) delayBetweenCopies?: number // Delay between copies in ms options?: PrinterOptions // Printer-specific options } /** * Printer-specific options */ export interface PrinterOptions { // Encoding encoding?: EncodingType // 'utf8' (default) or 'ascii' (removes Vietnamese tones) codepage?: number // Custom ESC/POS codepage number (optional, for advanced users) // Paper settings (in millimeters) paperWidthMm?: number // Paper width in mm (common: 32, 40, 50, 58, 60, 80) marginMm?: number // Global margin in mm for both left and right (default: 1mm, applies to text and images) lineSpacing?: number // Line spacing in 1/180 inch units (default: 60, range: 0-255) // Printer type printerType?: 'receipt' | 'label' // Printer type (default: 'receipt') // Label settings (only for printerType = 'label') labelHeightMm?: number // Label height in mm (measure your label, e.g., 30, 40, 50, 60, 80) labelGapMm?: number // Gap between labels in mm (optional - auto-estimated if not provided) disableCutPaper?: boolean // Disable auto-cut (default: false) // Connection keepAlive?: boolean // Keep connection alive after printing } /** * Main print job configuration */ export interface PrintJob { printers: PrinterConfig[] // List of printers documents: Node[][] // List of documents options?: JobOptions // Job-level options } /** * Job-level options */ export interface JobOptions { concurrent?: boolean // Print concurrently (default: false) continueOnError?: boolean // Continue if a printer fails (default: false) onJobComplete?: (address: string, success: boolean, error?: PrintError) => void onProgress?: (completed: number, total: number) => void } // ============= Result Types ============= /** * Native print result with detailed error info */ export interface NativePrintResult { success: boolean error?: { code: string message: string step?: 'connect' | 'send' | 'disconnect' | 'test' | 'unknown' retryable?: boolean suggestion?: string } } /** * Print result for single operations */ export interface PrintResult { success: boolean error?: PrintError // Standardized error with code } /** * Native print options */ export interface NativePrintOptions { keepAlive?: boolean timeout?: number // milliseconds } /** * Native image print options (internal - passed to native bridge) * Extends ImageOptions (which already extends NativePrintOptions) */ export interface NativeImagePrintOptions extends ImageOptions { paperWidthMm?: number // Paper width in mm (for margin calculation) alignNum?: number // Image alignment as number: 0=left, 1=center, 2=right (converted from align string) } /** * Image options (public API - used for both document nodes and direct print) * Replaces ImageNodeOptions from compiler/types.ts */ export interface ImageOptions extends NativePrintOptions { widthPx?: number // Image width in pixels (auto-calculated from paperWidthMm if not set) align?: 'left' | 'center' | 'right' // Image alignment (default: 'left') marginMm?: number // Margin in millimeters for both left and right isCutPaper?: boolean // Cut paper after printing } /** * Multi-printer result */ export interface MultiPrinterResult { success: boolean // Overall success results: Map // Per-printer results totalDuration: number // Total time in ms } /** * Individual printer result */ export interface PrinterResult { success: boolean error?: PrintError // Standardized error with code duration?: number // Time in ms }