/** * DataMatrix ECC 200 Encoder * * This module handles the encoding of messages into DataMatrix matrix format. * It supports multiple encoding modes (ASCII, C40, TEXT, X12, EDIFACT, Base256) * and uses Reed-Solomon error correction. * * @module encoder */ /** * Error codes for DataMatrix validation errors. * These represent expected, recoverable error conditions. */ export type DataMatrixErrorCode = 'EMPTY_MESSAGE' | 'MESSAGE_TOO_LONG'; /** * Custom error class for DataMatrix validation errors. * * This error is thrown for expected, recoverable conditions: * - EMPTY_MESSAGE: The input message is empty (and allowEmptyMessage is false) * - MESSAGE_TOO_LONG: The encoded message exceeds DataMatrix capacity (max ~1556 bytes) * * Other errors (programming bugs) will throw standard Error. * * @example * ```typescript * try { * const svg = DATAMatrix(message); * } catch (e) { * if (e instanceof DataMatrixError) { * // Handle validation error * console.log(`Validation failed: ${e.code} - ${e.message}`); * } else { * // Unexpected programming error * throw e; * } * } * ``` */ export declare class DataMatrixError extends Error { /** Error code identifying the specific validation failure */ readonly code: DataMatrixErrorCode; constructor(code: DataMatrixErrorCode, message: string); } /** * Result of encoding a message into a DataMatrix matrix */ export interface DataMatrixResult { /** 2D array of pixel values (1 = black module, 0/undefined = white module) */ readonly matrix: readonly (readonly number[])[]; /** Width of the barcode in modules (including finder pattern) */ readonly width: number; /** Height of the barcode in modules (including finder pattern) */ readonly height: number; } /** * Encodes a message into a DataMatrix pixel matrix * * This function handles the complete encoding process: * 1. Converts message to UTF-8 * 2. Selects the most efficient encoding mode * 3. Calculates optimal symbol size * 4. Adds padding and Reed-Solomon error correction * 5. Generates the matrix with finder pattern and data placement * * @example * // Encode a simple message * const result = encodeMessage('Hello World!'); * console.log(result.width, result.height); // dimensions in modules * * @example * // For rectangular symbols * const result = encodeMessage('ABC123', true); * * @example * // Allow empty message (produces minimal DataMatrix) * const result = encodeMessage('', false, true); * * @param text - The message to encode * @param useRectangular - Use rectangular format instead of square (default: false) * @param allowEmptyMessage - Allow empty message without throwing error (default: false) * @returns DataMatrixResult containing the pixel matrix and dimensions * @throws {Error} "Message cannot be empty" - When message is empty and allowEmptyMessage is false * @throws {Error} "Message too long: encoded length X exceeds DataMatrix capacity" - When encoded message exceeds maximum capacity (~1556 bytes for largest symbol) */ export declare function encodeMessage(text: string, useRectangular?: boolean, allowEmptyMessage?: boolean): DataMatrixResult; //# sourceMappingURL=encoder.d.ts.map