UNPKG

react-epson-epos-sdk

Version:

React library for managing Epson printers with ePOS SDK support.

186 lines (179 loc) 6.4 kB
import { FC, ReactNode } from 'react'; declare enum PrintResult { SUCCESS = "SUCCESS", ERROR = "ERROR" } declare enum ConnectionStatus { CONNECTED = "CONNECTED", IS_CONNECTING = "IS_CONNECTING", DISCONNECTED = "DISCONNECTED", ERROR = "ERROR" } declare enum PaperSize { SIZE_80MM = 80, SIZE_58MM = 58 } declare enum PrinterCutType { CUT_NO_FEED = "no_feed", CUT_FEED = "feed", CUT_RESERVE = "reserve", FULL_CUT_NO_FEED = "no_feed_fullcut", FULL_CUT_FEED = "feed_fullcut", FULL_CUT_RESERVE = "reserve_fullcut" } declare enum PrintColor { COLOR_NONE = "none", COLOR_1 = "color_1", COLOR_2 = "color_2", COLOR_3 = "color_3", COLOR_4 = "color_4" } declare enum PrinterAlign { ALIGN_LEFT = "left", ALIGN_CENTER = "center", ALIGN_RIGHT = "right" } declare enum PrinterTextFont { FONT_A = "font_a", FONT_B = "font_b", FONT_C = "font_c", FONT_D = "font_d", FONT_E = "font_e" } declare enum PrintSymbolType { PDF417_standard = "pdf417_standard", PDF417_truncated = "pdf417_truncated", QRCODE_MODEL_1 = "qrcode_model_1", QRCODE_MODEL_2 = "qrcode_model_2", MAXICODE_MODE_2 = "maxicode_mode_2", MAXICODE_MODE_3 = "maxicode_mode_3", MAXICODE_MODE_4 = "maxicode_mode_4", MAXICODE_MODE_5 = "maxicode_mode_5", MAXICODE_MODE_6 = "maxicode_mode_6", GS1_DATABAR_STACKED = "gs1_databar_stacked", GS1_DATABAR_STACKED_OMNIDIRECTIONAL = "gs1_databar_stacked_omnidirectional", GS1_DATABAR_EXPANDED_STACKED = "gs1_databar_expanded_stacked", AZTECCODE_FULLRANGE = "azteccode_fullrange", AZTECCODE_COMPACT = "azteccode_compact", DATAMATRIX_SQUARE = "datamatrix_square", DATAMATRIX_RECTANGLE_8 = "datamatrix_rectangle_8", DATAMATRIX_RECTANGLE_12 = "datamatrix_rectangle_12", DATAMATRIX_RECTANGLE_16 = "datamatrix_rectangle_16" } declare enum PrintSymbolLevel { LEVEL_0 = "level_0",// PDF 417 error correction level 0 LEVEL_1 = "level_1",// PDF 417 error correction level 1 LEVEL_2 = "level_2",// PDF 417 error correction level 2 LEVEL_3 = "level_3",// PDF 417 error correction level 3 LEVEL_4 = "level_4",// PDF 417 error correction level 4 LEVEL_5 = "level_5",// PDF 417 error correction level 5 LEVEL_6 = "level_6",// PDF 417 error correction level 6 LEVEL_7 = "level_7",// PDF 417 error correction level 7 LEVEL_8 = "level_8",// PDF 417 error correction level 8 LEVEL_L = "level_l",// QR Code error correction level L LEVEL_M = "level_m",// QR Code error correction level M LEVEL_Q = "level_q",// QR Code error correction level Q LEVEL_H = "level_h",// QR Code error correction level H DEFAULT = "default" } interface AddTextOptions { rightPadding?: number; addNewLine?: boolean; alignRight?: boolean; capitalize?: boolean; } interface TextSize { width: number; height: number; } interface TextStyle { reverse: boolean; ul: boolean; em: boolean; color: PrintColor; } interface AddSymbolOptions { type: PrintSymbolType; level: AllowedPrintSymbolLevel; width?: number; height?: number; size?: number; } type AllowedPrintSymbolLevel = PrintSymbolLevel | number; declare class Printer { private static readonly TIMEOUT; private static readonly HEARTBEAT_XML; private printerIp; private paperSize; private textFont; private textSize; private textStyle; private cursorX; private xmlChunks; constructor(printerIp: string, paperSize: PaperSize); addXmlChunk: (xmlChunk: string) => void; setXmlChunks: (xmlChunks: string[]) => void; getXmlChunks: () => string[]; private reset; addText(text: string, { rightPadding, addNewLine, alignRight, capitalize }?: AddTextOptions): void; addNewLine(): void; setTextFont(font: PrinterTextFont): void; setTextStyle({ reverse, ul, em, color }: Partial<TextStyle>): void; setTextSize(textSize: TextSize): void; setTextAlign(align: PrinterAlign): void; addFeedLine(line: number): void; addCut(type?: PrinterCutType): void; /** * Adds a 2D barcode symbol to the print buffer in XML format. * * @param {string} data - The content/data to encode within the symbol. * * @param {Object} options - Configuration options for the symbol. * @param {PrintSymbolType} options.type - The type of 2D code to print (e.g. QR Code, PDF417, etc.). * @param {AllowedPrintSymbolLevel} options.level - Error correction level or symbol quality level, * depending on the barcode type. * @param {number} [options.width] - Optional. Specifies the width of each module (square block) in dots. * * - The valid range is: * - **QR Code**: 1 to 16 (default = 3) * - **PDF417**: 2 to 8 (default = 3) * - **Aztec/DataMatrix/GS1 DataBar**: 2 to 16 or 2 to 8 depending on type * - **MaxiCode**: Ignored * * @param {number} [options.height] - Optional. Specifies the height of each module in dots. * * - Only applies to **PDF417**, range: 2 to 8 (default = 3). For other types, height is ignored. * * @param {number} [options.size] - Optional. Size-specific attribute depending on symbol type: * * - **PDF417**: Specifies number of codewords per row (default = 0) * - **GS1 DataBar (Expanded Stacked)**: Specifies maximum width (default = 0 for auto) * - **Others (QR Code, MaxiCode, Aztec, DataMatrix)**: Ignored * * @returns {void} */ addSymbol(data: string, { type, level, width, height, size }: AddSymbolOptions): void; addHorizontalLine(): void; toXml(): string; checkOnline(): Promise<boolean>; send(): Promise<void>; private escapeXml; private sendRequest; private getCharactersPerLine; } declare const PrinterProvider: FC<{ children: ReactNode; printerIp: string | null; isDebugMode?: boolean; paperSize: PaperSize; }>; declare const usePrinter: () => { status: ConnectionStatus; printer: Printer | undefined; print: ({ retryOnError }?: { retryOnError: boolean; }) => Promise<{ printResult: PrintResult; }>; }; export { ConnectionStatus, PaperSize, PrintColor, PrintResult, PrintSymbolLevel, PrintSymbolType, Printer, PrinterAlign, PrinterCutType, PrinterProvider, PrinterTextFont, usePrinter };