webzlp
Version:
A small library using WebUSB to print labels on label printers.
62 lines • 3.97 kB
TypeScript
import * as Conf from './Configs/index.js';
import * as Cmds from './Commands/index.js';
import * as Docs from './Documents/index.js';
import * as Mux from 'web-device-mux';
export interface LabelPrinterEventMap {
reportedStatus: CustomEvent<Cmds.IStatusMessage>;
reportedError: CustomEvent<Cmds.IErrorMessage>;
}
/** Type alias for a Label Printer that communicates over USB. */
export type LabelPrinterUsb = LabelPrinter<Uint8Array>;
/** A class for working with a label printer. */
export declare class LabelPrinter<TChannelType extends Conf.MessageArrayLike> extends EventTarget implements Mux.IDevice {
private _channel;
private _channelType;
private _channelMessageTransformer;
private _streamListener?;
private _commandSet?;
private _awaitedCommands;
private _awaitedCommandTimeoutMS;
private _printerOptions;
/** Gets the read-only copy of the current config of the printer. To modify use getConfigDocument. */
get printerOptions(): Cmds.PrinterConfig;
/** Gets the model of the printer, detected from the printer's config. */
get printerModel(): string;
/** Gets the manufacturer of the printer, detected from the printer's config. */
get printerManufacturer(): string;
/** Gets the serial number of the printer, detected from the printer's config. */
get printerSerial(): string;
private _deviceCommOpts;
/** Gets the configured printer communication options. */
get printerCommunicationOptions(): Mux.IDeviceCommunicationOptions;
private _disposed;
get connected(): boolean;
get ready(): Promise<boolean>;
/** Gets a document for configuring this printer. */
getConfigDocument(): Docs.IConfigDocumentBuilder;
/** Gets a document for printing a label. */
getLabelDocument(docType?: Docs.LabelDocumentType): Docs.ILabelDocumentBuilder;
/** Construct a new printer from a given USB device. */
static fromUSBDevice(device: USBDevice, options: Mux.IDeviceCommunicationOptions): Promise<LabelPrinterUsb>;
/** Construct a new printer from a raw channel object */
static fromChannel<TChannelType extends Conf.MessageArrayLike>(channel: Mux.IDeviceChannel<TChannelType, TChannelType>, channelMessageTransformer: Cmds.MessageTransformer<TChannelType>, channelType: Conf.MessageArrayLikeType, deviceCommunicationOptions?: Mux.IDeviceCommunicationOptions, printerOptions?: Cmds.PrinterConfig): Promise<LabelPrinter<TChannelType>>;
protected constructor(channel: Mux.IDeviceChannel<TChannelType, TChannelType>, channelMessageTransformer: Cmds.MessageTransformer<TChannelType>, channelMessageType: Conf.MessageArrayLikeType, deviceCommunicationOptions?: Mux.IDeviceCommunicationOptions, printerOptions?: Cmds.PrinterConfig);
addEventListener<T extends keyof LabelPrinterEventMap>(type: T, listener: EventListenerObject | null | ((this: LabelPrinter<TChannelType>, ev: LabelPrinterEventMap[T]) => void), options?: boolean | AddEventListenerOptions): void;
removeEventListener<T extends keyof LabelPrinterEventMap>(type: T, listener: EventListenerObject | null | ((this: LabelPrinter<TChannelType>, ev: LabelPrinterEventMap[T]) => void), options?: boolean | AddEventListenerOptions): void;
private sendEvent;
private setup;
dispose(): Promise<void>;
/** Refresh the printer information cache directly from the printer. */
refreshPrinterConfiguration(): Promise<Cmds.PrinterConfig>;
/** Send a document to the printer, applying the commands. */
sendDocument(doc: Docs.IDocument, commandSet?: Cmds.CommandSet<Conf.MessageArrayLike> | undefined): Promise<boolean>;
/** Send a compiled document to the printer. */
sendCompiledDocument(doc: Docs.CompiledDocument): Promise<boolean>;
private detectLanguage;
private sendTransactionAndWait;
private handleInputError;
private parseAndDispatchMessage;
private logIfDebug;
private logResultIfDebug;
}
//# sourceMappingURL=Printer.d.ts.map