/** * Barcode Generator * * Generates ESC/POS commands for printing 1D barcodes and 2D codes. * Supports Code128, Code39, EAN-13, EAN-8, UPC-A, ITF, CODABAR, QR_CODE, and PDF417 formats. * * @example * ```typescript * const generator = new BarcodeGenerator(); * const commands = generator.generate('1234567890128', { * format: BarcodeFormat.EAN13, * height: 80, * showText: true * }); * ``` */ /** * Supported barcode formats */ export declare enum BarcodeFormat { /** Code 128 - Variable length, alphanumeric */ CODE128 = "CODE128", /** Code 39 - Variable length, alphanumeric with special chars */ CODE39 = "CODE39", /** EAN-13 - 13 digits (12 + check digit) */ EAN13 = "EAN13", /** EAN-8 - 8 digits (7 + check digit) */ EAN8 = "EAN8", /** UPC-A - 12 digits (11 + check digit) */ UPCA = "UPCA", /** ITF (Interleaved 2 of 5) - Even number of digits */ ITF = "ITF", /** CODABAR - Numeric with special start/stop chars */ CODABAR = "CODABAR", /** QR Code - 2D matrix code */ QR_CODE = "QR_CODE", /** PDF417 - 2D stacked barcode */ PDF417 = "PDF417" } /** * Barcode configuration options */ export interface BarcodeOptions { /** Barcode format */ format: BarcodeFormat; /** Barcode height in dots (1-255, default: 80) */ height?: number; /** Barcode module width (2-6, default: 3) */ width?: number; /** Show human-readable text */ showText?: boolean; /** Text position */ textPosition?: 'above' | 'below' | 'both' | 'none'; /** QR code error correction level (L/M/Q/H, default: M) */ errorCorrection?: 'L' | 'M' | 'Q' | 'H'; /** QR code model (1 or 2, default: 2) */ qrModel?: 1 | 2; /** PDF417 compression mode (0-3, default: 2) */ pdf417Compression?: 0 | 1 | 2 | 3; /** PDF417 security level (0-8, default: 2) */ pdf417Security?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; /** PDF417 columns (1-30, default: 2) */ pdf417Columns?: number; } /** * Validation result */ export interface ValidationResult { /** Whether validation passed */ valid: boolean; /** Validation errors */ errors: Array<{ field: string; message: string; code: string; }>; } /** * Barcode generator interface */ export interface IBarcodeGenerator { /** Generate barcode commands */ generate(content: string, options: BarcodeOptions): Uint8Array[]; /** Validate barcode content */ validate(content: string, format: BarcodeFormat): ValidationResult; /** Get supported formats */ getSupportedFormats(): BarcodeFormat[]; } /** * Barcode Generator class * Generates ESC/POS commands for 1D barcodes and 2D codes */ export declare class BarcodeGenerator implements IBarcodeGenerator { /** * Generate barcode ESC/POS commands * * @param content - Barcode content/data * @param options - Barcode options * @returns Array of ESC/POS command buffers */ generate(content: string, options: BarcodeOptions): Uint8Array[]; /** * Generate 1D barcode commands */ private generate1DBarcode; /** * Generate QR code commands using ESC/POS GS k 80-83 * * @param content - QR code content * @param options - QR code options * @returns Array of ESC/POS command buffers */ private generateQRCode; /** * Generate PDF417 commands using ESC/POS GS k 81 * * PDF417 is a 2D stacked barcode format supported by many thermal printers. * The printer will handle the actual encoding and generation of the PDF417 symbol. * * @param content - PDF417 content (text data) * @param options - PDF417 options * @returns Array of ESC/POS command buffers */ private generatePDF417; /** * Validate barcode content for the specified format * * @param content - Barcode content to validate * @param format - Barcode format * @returns Validation result */ validate(content: string, format: BarcodeFormat): ValidationResult; /** * Validate QR code content */ private validateQRCode; /** * Validate PDF417 content */ private validatePDF417; /** * Get list of supported barcode formats * * @returns Array of supported formats */ getSupportedFormats(): BarcodeFormat[]; /** * Validate EAN-13 content */ private validateEAN13; /** * Validate EAN-8 content */ private validateEAN8; /** * Validate UPC-A content */ private validateUPCA; /** * Validate Code 39 content */ private validateCode39; /** * Validate Code 128 content */ private validateCode128; /** * Validate ITF content */ private validateITF; /** * Validate CODABAR content */ private validateCodabar; /** * Calculate EAN check digit (works for EAN-13 and EAN-8) */ private calculateEANCheckDigit; /** * Calculate UPC-A check digit */ private calculateUPCACheckDigit; /** * Encode content for ESC/POS barcode command */ private encodeContent; /** * Encode string to UTF-8 bytes */ private encodeUTF8; /** * Get text position code */ private getTextPosition; /** * Clamp height to valid range (1-255) */ private clampHeight; /** * Clamp width to valid range (2-6) */ private clampWidth; /** * Clamp QR code size to valid range (1-16) */ private clampQRSize; /** * Clamp PDF417 columns to valid range (1-30) */ private clampPDF417Columns; } export declare const barcodeGenerator: BarcodeGenerator;