taro-bluetooth-print 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +10 -2
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.es.js +1 -1
  5. package/dist/index.umd.js +1 -1
  6. package/dist/logo.svg +17 -0
  7. package/dist/manifest.webmanifest +17 -0
  8. package/dist/types/adapters/QQAdapter.d.ts +22 -0
  9. package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
  10. package/dist/types/adapters/WebBluetoothAdapter.d.ts +87 -1
  11. package/dist/types/adapters/index.d.ts +13 -0
  12. package/dist/types/barcode/BarcodeGenerator.d.ts +61 -4
  13. package/dist/types/barcode/index.d.ts +1 -1
  14. package/dist/types/drivers/StarPrinter.d.ts +243 -0
  15. package/dist/types/drivers/index.d.ts +1 -0
  16. package/dist/types/encoding/EncodingService.d.ts +41 -2
  17. package/dist/types/encoding/index.d.ts +2 -1
  18. package/dist/types/encoding/korean-japanese.d.ts +127 -0
  19. package/dist/types/services/BatchPrintManager.d.ts +98 -5
  20. package/dist/types/services/PrintStatistics.d.ts +189 -0
  21. package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
  22. package/dist/types/services/index.d.ts +2 -0
  23. package/dist/types/template/TemplateEngine.d.ts +140 -1
  24. package/dist/types/utils/image.d.ts +40 -119
  25. package/dist/types/utils/platform.d.ts +2 -0
  26. package/dist/types/utils/uuid.d.ts +191 -0
  27. package/package.json +1 -1
  28. package/src/adapters/AdapterFactory.ts +5 -0
  29. package/src/adapters/QQAdapter.ts +36 -0
  30. package/src/adapters/ReactNativeAdapter.ts +506 -0
  31. package/src/adapters/WebBluetoothAdapter.ts +275 -14
  32. package/src/adapters/index.ts +19 -0
  33. package/src/barcode/BarcodeGenerator.ts +312 -6
  34. package/src/barcode/index.ts +1 -1
  35. package/src/drivers/StarPrinter.ts +556 -0
  36. package/src/drivers/index.ts +10 -0
  37. package/src/encoding/EncodingService.ts +268 -4
  38. package/src/encoding/index.ts +17 -1
  39. package/src/encoding/korean-japanese.ts +325 -0
  40. package/src/services/BatchPrintManager.ts +291 -16
  41. package/src/services/PrintStatistics.ts +504 -0
  42. package/src/services/ScheduledRetryManager.ts +560 -0
  43. package/src/services/index.ts +16 -0
  44. package/src/template/TemplateEngine.ts +543 -4
  45. package/src/utils/image.ts +507 -324
  46. package/src/utils/platform.ts +10 -10
  47. package/src/utils/uuid.ts +522 -0
  48. package/src/utils/validation.ts +1155 -0
package/dist/logo.svg ADDED
@@ -0,0 +1,17 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
2
+ <!-- Background circle -->
3
+ <circle cx="32" cy="32" r="30" fill="#10b981" opacity="0.1"/>
4
+ <circle cx="32" cy="32" r="28" fill="#10b981" opacity="0.2"/>
5
+ <!-- Printer body -->
6
+ <rect x="12" y="20" width="40" height="28" rx="4" fill="#10b981"/>
7
+ <!-- Paper slot -->
8
+ <rect x="16" y="8" width="32" height="16" rx="2" fill="#ffffff" stroke="#10b981" stroke-width="2"/>
9
+ <!-- Paper lines -->
10
+ <line x1="20" y1="14" x2="36" y2="14" stroke="#10b981" stroke-width="2" stroke-linecap="round"/>
11
+ <line x1="20" y1="18" x2="30" y2="18" stroke="#10b981" stroke-width="2" stroke-linecap="round"/>
12
+ <!-- Bluetooth symbol -->
13
+ <path d="M32 26 L36 30 L32 34 L28 30 Z" fill="#ffffff"/>
14
+ <line x1="32" y1="30" x2="32" y2="38" stroke="#ffffff" stroke-width="2" stroke-linecap="round"/>
15
+ <!-- Feed button -->
16
+ <rect x="46" y="36" width="4" height="6" rx="1" fill="#ffffff" opacity="0.6"/>
17
+ </svg>
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "taro-bluetooth-print",
3
+ "short_name": "蓝牙打印",
4
+ "description": "轻量级、高性能的热敏/标签蓝牙打印库",
5
+ "start_url": "/taro-bluetooth-print/",
6
+ "display": "standalone",
7
+ "background_color": "#ffffff",
8
+ "theme_color": "#10b981",
9
+ "icons": [
10
+ {
11
+ "src": "/logo.svg",
12
+ "sizes": "any",
13
+ "type": "image/svg+xml"
14
+ }
15
+ ],
16
+ "categories": ["developer tools", "utilities"]
17
+ }
@@ -0,0 +1,22 @@
1
+ import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
2
+ /**
3
+ * QQ Mini Program Bluetooth Low Energy adapter
4
+ *
5
+ * Uses the QQ mini-program's BLE APIs (qq.xxx).
6
+ * All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const adapter = new QQAdapter();
11
+ * await adapter.connect('device-id-123');
12
+ * await adapter.write('device-id-123', buffer);
13
+ * await adapter.disconnect('device-id-123');
14
+ * ```
15
+ */
16
+ export declare class QQAdapter extends MiniProgramAdapter {
17
+ /**
18
+ * Returns the QQ mini-program BLE API object
19
+ * @returns The qq global object providing BLE capabilities
20
+ */
21
+ protected getApi(): MiniProgramBLEApi;
22
+ }
@@ -0,0 +1,111 @@
1
+ import { BaseAdapter } from './BaseAdapter';
2
+ import { IPrinterAdapter, IAdapterOptions } from '../types';
3
+ /**
4
+ * React Native BLE Manager interface
5
+ * Compatible with react-native-ble-plx API
6
+ */
7
+ interface BLEManager {
8
+ startDeviceScan(serviceUUIDs: string[] | null, options: Record<string, unknown> | null, onDeviceScanned: (error: unknown, device: unknown) => void): void;
9
+ stopDeviceScan(): void;
10
+ connectToDevice(deviceIdentifier: string, options: Record<string, unknown>): Promise<unknown>;
11
+ disconnectFromDevice(deviceIdentifier: string, force?: boolean): Promise<unknown>;
12
+ discoverAllServicesAndCharacteristicsForDevice(deviceIdentifier: string): Promise<unknown>;
13
+ writeCharacteristicWithResponseForDevice(deviceIdentifier: string, serviceUUID: string, characteristicUUID: string, value: string, transactionId?: string): Promise<unknown>;
14
+ writeCharacteristicWithoutResponseForDevice(deviceIdentifier: string, serviceUUID: string, characteristicUUID: string, value: string, transactionId?: string): Promise<unknown>;
15
+ readCharacteristicForDevice(deviceIdentifier: string, serviceUUID: string, characteristicUUID: string, transactionId?: string): Promise<unknown>;
16
+ monitorCharacteristicForDevice(deviceIdentifier: string, serviceUUID: string, characteristicUUID: string, onUpdate: (error: unknown, characteristic: unknown) => void, transactionId?: string): {
17
+ remove: () => void;
18
+ };
19
+ }
20
+ /**
21
+ * React Native Bluetooth Low Energy adapter
22
+ *
23
+ * Uses react-native-ble-plx for BLE operations on iOS and Android.
24
+ * This adapter does NOT extend MiniProgramAdapter because React Native
25
+ * has a fundamentally different BLE API compared to mini-program platforms.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import BleManager from 'react-native-ble-plx';
30
+ * import { ReactNativeAdapter } from 'taro-bluetooth-print';
31
+ *
32
+ * BleManager.start({ showAlert: false });
33
+ *
34
+ * const adapter = new ReactNativeAdapter({ bleManager: BleManager });
35
+ * await adapter.connect('device-uuid-123');
36
+ * await adapter.write('device-uuid-123', buffer);
37
+ * await adapter.disconnect('device-uuid-123');
38
+ * ```
39
+ */
40
+ export declare class ReactNativeAdapter extends BaseAdapter implements IPrinterAdapter {
41
+ private bleManager;
42
+ private deviceCache;
43
+ /**
44
+ * Creates a new ReactNativeAdapter instance
45
+ *
46
+ * @param options - Configuration options
47
+ * @param options.bleManager - BLE Manager instance (e.g., from react-native-ble-plx)
48
+ * @throws {Error} If bleManager is not provided or not supported
49
+ */
50
+ constructor(options: {
51
+ bleManager: BLEManager;
52
+ });
53
+ /**
54
+ * Connect to a Bluetooth device and discover services
55
+ *
56
+ * @param deviceId - Unique identifier (UUID) of the device to connect to
57
+ * @throws {BluetoothPrintError} When connection fails or device not found
58
+ */
59
+ connect(deviceId: string): Promise<void>;
60
+ /**
61
+ * Perform the actual BLE connection
62
+ */
63
+ private performConnect;
64
+ /**
65
+ * Disconnect from a Bluetooth device
66
+ *
67
+ * @param deviceId - Unique identifier of the device to disconnect from
68
+ */
69
+ disconnect(deviceId: string): Promise<void>;
70
+ /**
71
+ * Write data to the Bluetooth device in chunks
72
+ *
73
+ * Features:
74
+ * - Automatic chunk size adjustment
75
+ * - Dynamic delay for congestion control
76
+ * - Retry with exponential backoff
77
+ * - Write timeout per chunk
78
+ *
79
+ * @param deviceId - Unique identifier of the connected device
80
+ * @param buffer - Data to write as ArrayBuffer
81
+ * @param options - Optional write settings (chunkSize, delay, retries)
82
+ * @throws {BluetoothPrintError} When write fails after all retries
83
+ */
84
+ write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
85
+ /**
86
+ * Start discovering nearby Bluetooth devices
87
+ *
88
+ * Note: This is optional in IPrinterAdapter. In React Native BLE,
89
+ * device discovery is typically done via scan events.
90
+ */
91
+ startDiscovery?(): Promise<void>;
92
+ /**
93
+ * Stop discovering nearby Bluetooth devices
94
+ */
95
+ stopDiscovery?(): Promise<void>;
96
+ /**
97
+ * Discover services and characteristics for a connected device
98
+ *
99
+ * @param deviceId - Device identifier
100
+ * @param device - Connected device object
101
+ */
102
+ private discoverServices;
103
+ /**
104
+ * Convert ArrayBuffer to base64 string for react-native-ble-plx
105
+ *
106
+ * @param buffer - ArrayBuffer to convert
107
+ * @returns Base64 encoded string
108
+ */
109
+ private arrayBufferToBase64;
110
+ }
111
+ export {};
@@ -12,6 +12,47 @@ export interface WebBluetoothRequestOptions {
12
12
  acceptAllDevices?: boolean;
13
13
  /** Optional services to access */
14
14
  optionalServices?: string[];
15
+ /** Minimum RSSI signal strength (dBm) to accept device */
16
+ minRSSI?: number;
17
+ /** Filter by device name (exact or partial match) */
18
+ name?: string;
19
+ /** Filter by manufacturer data patterns */
20
+ manufacturerDataFilter?: Array<{
21
+ companyIdentifier: number;
22
+ dataPrefix?: Uint8Array;
23
+ }>;
24
+ }
25
+ /**
26
+ * Discovered device information
27
+ */
28
+ export interface DiscoveredDevice {
29
+ /** Device instance */
30
+ device: BluetoothDevice;
31
+ /** Device name */
32
+ name: string;
33
+ /** Device ID */
34
+ deviceId: string;
35
+ /** RSSI signal strength (dBm) */
36
+ rssi?: number;
37
+ /** Timestamp when device was discovered */
38
+ discoveredAt: number;
39
+ /** Manufacturer data if available */
40
+ manufacturerData?: Map<number, Uint8Array>;
41
+ }
42
+ /**
43
+ * Device filter options for scanning
44
+ */
45
+ export interface DeviceFilterOptions {
46
+ /** Minimum RSSI threshold (dBm) */
47
+ minRSSI?: number;
48
+ /** Maximum RSSI threshold (dBm) */
49
+ maxRSSI?: number;
50
+ /** Name prefix filter */
51
+ namePrefix?: string;
52
+ /** Name exact match filter */
53
+ name?: string;
54
+ /** Service UUIDs to filter */
55
+ serviceUUIDs?: string[];
15
56
  }
16
57
  /**
17
58
  * Web Bluetooth adapter for H5 environment
@@ -29,6 +70,8 @@ export interface WebBluetoothRequestOptions {
29
70
  */
30
71
  export declare class WebBluetoothAdapter extends BaseAdapter {
31
72
  private devices;
73
+ private discoveredDevices;
74
+ private connectionCleanupTimeout;
32
75
  /**
33
76
  * Check if Web Bluetooth API is supported in the current browser
34
77
  * @returns True if Web Bluetooth is supported
@@ -52,10 +95,12 @@ export declare class WebBluetoothAdapter extends BaseAdapter {
52
95
  connect(deviceId: string): Promise<void>;
53
96
  /**
54
97
  * Disconnect from a Bluetooth device
98
+ * Enhanced to properly clean up all resources and event listeners
55
99
  *
56
100
  * @param deviceId - Bluetooth device ID
101
+ * @param force - If true, force disconnection even if device not found in cache
57
102
  */
58
- disconnect(deviceId: string): Promise<void>;
103
+ disconnect(deviceId: string, force?: boolean): void;
59
104
  /**
60
105
  * Write data to the Bluetooth device
61
106
  *
@@ -65,6 +110,42 @@ export declare class WebBluetoothAdapter extends BaseAdapter {
65
110
  * @throws {BluetoothPrintError} When write fails
66
111
  */
67
112
  write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
113
+ /**
114
+ * Get device ID from a BluetoothDevice instance
115
+ * Handles different browser implementations
116
+ *
117
+ * @param device - BluetoothDevice instance
118
+ * @returns Device ID string
119
+ */
120
+ getDeviceId(device: BluetoothDevice): string;
121
+ /**
122
+ * Get device information including RSSI
123
+ *
124
+ * @param deviceId - Bluetooth device ID
125
+ * @returns Device info object with RSSI and metadata
126
+ */
127
+ getDeviceInfo(deviceId: string): {
128
+ deviceId: string;
129
+ name: string;
130
+ rssi?: number;
131
+ connected: boolean;
132
+ } | null;
133
+ /**
134
+ * Filter discovered devices by criteria
135
+ *
136
+ * @param devices - Array of discovered devices
137
+ * @param filter - Filter criteria
138
+ * @returns Filtered array of devices
139
+ */
140
+ filterDevices(devices: DiscoveredDevice[], filter: DeviceFilterOptions): DiscoveredDevice[];
141
+ /**
142
+ * Sort devices by signal strength (RSSI)
143
+ *
144
+ * @param devices - Array of discovered devices
145
+ * @param ascending - Sort in ascending order (weakest first), default false (strongest first)
146
+ * @returns Sorted array
147
+ */
148
+ sortByRSSI(devices: DiscoveredDevice[], ascending?: boolean): DiscoveredDevice[];
68
149
  /**
69
150
  * Build request options for navigator.bluetooth.requestDevice
70
151
  */
@@ -89,4 +170,9 @@ export declare class WebBluetoothAdapter extends BaseAdapter {
89
170
  * Clean up device information
90
171
  */
91
172
  private cleanupDeviceInfo;
173
+ /**
174
+ * Generate a fallback device ID when device.id is not available
175
+ * Uses device name + first seen timestamp as identifier
176
+ */
177
+ private generateFallbackDeviceId;
92
178
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Adapters barrel export
3
+ */
4
+ export { BaseAdapter, MiniProgramAdapter } from './BaseAdapter';
5
+ export type { MiniProgramBLEApi, ServiceInfo, BLECharacteristic, BLECharacteristicProperties, } from './BaseAdapter';
6
+ export { TaroAdapter } from './TaroAdapter';
7
+ export { AlipayAdapter } from './AlipayAdapter';
8
+ export { BaiduAdapter } from './BaiduAdapter';
9
+ export { ByteDanceAdapter } from './ByteDanceAdapter';
10
+ export { QQAdapter } from './QQAdapter';
11
+ export { ReactNativeAdapter } from './ReactNativeAdapter';
12
+ export { WebBluetoothAdapter } from './WebBluetoothAdapter';
13
+ export { AdapterFactory } from './AdapterFactory';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Barcode Generator
3
3
  *
4
- * Generates ESC/POS commands for printing 1D barcodes.
5
- * Supports Code128, Code39, EAN-13, EAN-8, UPC-A, ITF, and CODABAR formats.
4
+ * Generates ESC/POS commands for printing 1D barcodes and 2D codes.
5
+ * Supports Code128, Code39, EAN-13, EAN-8, UPC-A, ITF, CODABAR, QR_CODE, and PDF417 formats.
6
6
  *
7
7
  * @example
8
8
  * ```typescript
@@ -31,7 +31,11 @@ export declare enum BarcodeFormat {
31
31
  /** ITF (Interleaved 2 of 5) - Even number of digits */
32
32
  ITF = "ITF",
33
33
  /** CODABAR - Numeric with special start/stop chars */
34
- CODABAR = "CODABAR"
34
+ CODABAR = "CODABAR",
35
+ /** QR Code - 2D matrix code */
36
+ QR_CODE = "QR_CODE",
37
+ /** PDF417 - 2D stacked barcode */
38
+ PDF417 = "PDF417"
35
39
  }
36
40
  /**
37
41
  * Barcode configuration options
@@ -47,6 +51,16 @@ export interface BarcodeOptions {
47
51
  showText?: boolean;
48
52
  /** Text position */
49
53
  textPosition?: 'above' | 'below' | 'both' | 'none';
54
+ /** QR code error correction level (L/M/Q/H, default: M) */
55
+ errorCorrection?: 'L' | 'M' | 'Q' | 'H';
56
+ /** QR code model (1 or 2, default: 2) */
57
+ qrModel?: 1 | 2;
58
+ /** PDF417 compression mode (0-3, default: 2) */
59
+ pdf417Compression?: 0 | 1 | 2 | 3;
60
+ /** PDF417 security level (0-8, default: 2) */
61
+ pdf417Security?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
62
+ /** PDF417 columns (1-30, default: 2) */
63
+ pdf417Columns?: number;
50
64
  }
51
65
  /**
52
66
  * Validation result
@@ -74,7 +88,7 @@ export interface IBarcodeGenerator {
74
88
  }
75
89
  /**
76
90
  * Barcode Generator class
77
- * Generates ESC/POS commands for 1D barcodes
91
+ * Generates ESC/POS commands for 1D barcodes and 2D codes
78
92
  */
79
93
  export declare class BarcodeGenerator implements IBarcodeGenerator {
80
94
  /**
@@ -85,6 +99,29 @@ export declare class BarcodeGenerator implements IBarcodeGenerator {
85
99
  * @returns Array of ESC/POS command buffers
86
100
  */
87
101
  generate(content: string, options: BarcodeOptions): Uint8Array[];
102
+ /**
103
+ * Generate 1D barcode commands
104
+ */
105
+ private generate1DBarcode;
106
+ /**
107
+ * Generate QR code commands using ESC/POS GS k 80-83
108
+ *
109
+ * @param content - QR code content
110
+ * @param options - QR code options
111
+ * @returns Array of ESC/POS command buffers
112
+ */
113
+ private generateQRCode;
114
+ /**
115
+ * Generate PDF417 commands using ESC/POS GS k 81
116
+ *
117
+ * PDF417 is a 2D stacked barcode format supported by many thermal printers.
118
+ * The printer will handle the actual encoding and generation of the PDF417 symbol.
119
+ *
120
+ * @param content - PDF417 content (text data)
121
+ * @param options - PDF417 options
122
+ * @returns Array of ESC/POS command buffers
123
+ */
124
+ private generatePDF417;
88
125
  /**
89
126
  * Validate barcode content for the specified format
90
127
  *
@@ -93,6 +130,14 @@ export declare class BarcodeGenerator implements IBarcodeGenerator {
93
130
  * @returns Validation result
94
131
  */
95
132
  validate(content: string, format: BarcodeFormat): ValidationResult;
133
+ /**
134
+ * Validate QR code content
135
+ */
136
+ private validateQRCode;
137
+ /**
138
+ * Validate PDF417 content
139
+ */
140
+ private validatePDF417;
96
141
  /**
97
142
  * Get list of supported barcode formats
98
143
  *
@@ -139,6 +184,10 @@ export declare class BarcodeGenerator implements IBarcodeGenerator {
139
184
  * Encode content for ESC/POS barcode command
140
185
  */
141
186
  private encodeContent;
187
+ /**
188
+ * Encode string to UTF-8 bytes
189
+ */
190
+ private encodeUTF8;
142
191
  /**
143
192
  * Get text position code
144
193
  */
@@ -151,5 +200,13 @@ export declare class BarcodeGenerator implements IBarcodeGenerator {
151
200
  * Clamp width to valid range (2-6)
152
201
  */
153
202
  private clampWidth;
203
+ /**
204
+ * Clamp QR code size to valid range (1-16)
205
+ */
206
+ private clampQRSize;
207
+ /**
208
+ * Clamp PDF417 columns to valid range (1-30)
209
+ */
210
+ private clampPDF417Columns;
154
211
  }
155
212
  export declare const barcodeGenerator: BarcodeGenerator;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Barcode Generator Module
3
- * 条码生成模块 - 负责一维条码生成
3
+ * 条码生成模块 - 负责一维条码和二维条码生成
4
4
  */
5
5
  export { BarcodeGenerator, barcodeGenerator, BarcodeFormat } from './BarcodeGenerator';
6
6
  export type { BarcodeOptions, ValidationResult, IBarcodeGenerator } from './BarcodeGenerator';
@@ -0,0 +1,243 @@
1
+ import { IPrinterDriver, IQrOptions } from '../types';
2
+ /**
3
+ * Alignment options for text positioning
4
+ */
5
+ export type Alignment = 'left' | 'center' | 'right';
6
+ /**
7
+ * Barcode types supported by STAR printers
8
+ */
9
+ export type BarcodeType = 'CODE39' | 'CODE128' | 'EAN13';
10
+ /**
11
+ * STAR printer driver options
12
+ */
13
+ export interface StarPrinterOptions {
14
+ /** Use the EncodingService for GBK/UTF-8 encoding (default: true) */
15
+ useEncodingService?: boolean;
16
+ /** Show warnings for unsupported characters (default: true) */
17
+ showEncodingWarnings?: boolean;
18
+ /** Fallback character for unsupported characters (default: '?') */
19
+ fallbackChar?: string;
20
+ /** Enable international character mode (default: true) */
21
+ internationalCharset?: boolean;
22
+ }
23
+ /**
24
+ * Barcode options for STAR printers
25
+ */
26
+ export interface StarBarcodeOptions {
27
+ /** Barcode height in dots (default: 40) */
28
+ height?: number;
29
+ /** Barcode width (default: 2) */
30
+ width?: number;
31
+ /** HRI text position: 'none' | 'above' | 'below' | 'both' (default: 'below') */
32
+ hri?: 'none' | 'above' | 'below' | 'both';
33
+ /** Barcode type: CODE39, CODE128, EAN13 */
34
+ type?: BarcodeType;
35
+ }
36
+ /**
37
+ * QR code options for STAR printers
38
+ */
39
+ export interface StarQrOptions {
40
+ /** QR code model (default: 2) */
41
+ model?: 1 | 2;
42
+ /** QR code cell size in dots (default: 4) */
43
+ cellSize?: number;
44
+ /** Error correction level: 'L' | 'M' | 'Q' | 'H' (default: 'M') */
45
+ errorCorrection?: 'L' | 'M' | 'Q' | 'H';
46
+ }
47
+ /**
48
+ * Image print options
49
+ */
50
+ export interface StarImageOptions {
51
+ /** Enable dithering (default: true) */
52
+ dithering?: boolean;
53
+ /** Threshold for binarization 0-255 (default: 128) */
54
+ threshold?: number;
55
+ /** Print in greyscale mode (default: false) */
56
+ greyscale?: boolean;
57
+ }
58
+ /**
59
+ * STAR TSP/TSP700 series thermal printer driver
60
+ *
61
+ * Implements the STAR command set for thermal receipt printers.
62
+ * Supports text, images, QR codes, barcodes, and paper control.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const driver = new StarPrinter();
67
+ * const commands = [
68
+ * ...driver.init(),
69
+ * ...driver.text('Hello World!'),
70
+ * ...driver.feed(3),
71
+ * ...driver.cut()
72
+ * ];
73
+ * ```
74
+ */
75
+ export declare class StarPrinter implements IPrinterDriver {
76
+ private readonly logger;
77
+ private readonly encodingService;
78
+ private readonly useEncodingService;
79
+ private readonly internationalCharset;
80
+ private _boldEnabled;
81
+ private _alignment;
82
+ /**
83
+ * Creates a new StarPrinter driver instance
84
+ * @param options - Driver options
85
+ */
86
+ constructor(options?: StarPrinterOptions);
87
+ /**
88
+ * Initialize the printer to default state
89
+ * Sends ESC @ to reset printer to power-on defaults
90
+ *
91
+ * @returns Array of command buffers
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const commands = driver.init();
96
+ * ```
97
+ */
98
+ init(): Uint8Array[];
99
+ /**
100
+ * Print text content with specified encoding
101
+ *
102
+ * Supports GBK, UTF-8, EUC-KR, Shift-JIS, ISO-2022-JP through EncodingService.
103
+ * When using ESC/POS compatible mode, text is output as-is with line feed.
104
+ *
105
+ * @param content - Text content to print
106
+ * @param encoding - Text encoding (default: 'GBK')
107
+ * @returns Array of command buffers
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * driver.text('Hello World', 'UTF-8');
112
+ * driver.text('你好世界', 'GBK');
113
+ * ```
114
+ */
115
+ text(content: string, encoding?: string): Uint8Array[];
116
+ /**
117
+ * Feed paper by specified number of lines
118
+ *
119
+ * @param lines - Number of lines to feed (default: 1, max: 255)
120
+ * @returns Array of command buffers
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * driver.feed(3); // Feed 3 lines
125
+ * ```
126
+ */
127
+ feed(lines?: number): Uint8Array[];
128
+ /**
129
+ * Cut the paper using the built-in cutter
130
+ *
131
+ * Note: Not all STAR printers have a cutter. For printers without cutter,
132
+ * this will attempt a full paper cut which may result in no action.
133
+ *
134
+ * @returns Array of command buffers
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * driver.cut();
139
+ * ```
140
+ */
141
+ cut(): Uint8Array[];
142
+ /**
143
+ * Print a QR code
144
+ *
145
+ * Uses STAR's built-in QR code command when available (GS W 01 pattern),
146
+ * otherwise falls back to printing QR code as a raster image.
147
+ *
148
+ * @param content - Content to encode in the QR code
149
+ * @param options - QR code options (model, cellSize, errorCorrection)
150
+ * @returns Array of command buffers
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * driver.qr('https://example.com', { model: 2, cellSize: 6, errorCorrection: 'M' });
155
+ * ```
156
+ */
157
+ qr(content: string, options?: IQrOptions | StarQrOptions): Uint8Array[];
158
+ /**
159
+ * Print a barcode
160
+ *
161
+ * Supports CODE39, CODE128, and EAN13 barcode types.
162
+ * HRI (Human Readable Interpretation) text can be positioned above,
163
+ * below, or both sides of the barcode.
164
+ *
165
+ * @param data - Barcode data content
166
+ * @param options - Barcode options (type, height, width, hri)
167
+ * @returns Array of command buffers
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * driver.barcode('123456789012', { type: 'EAN13', height: 60 });
172
+ * driver.barcode('ABC-1234', { type: 'CODE39', width: 3 });
173
+ * ```
174
+ */
175
+ barcode(data: string, options?: StarBarcodeOptions): Uint8Array[];
176
+ /**
177
+ * Print a raster image
178
+ *
179
+ * Converts RGBA image data to 1-bit bitmap using dithering and sends
180
+ * to the printer using STAR's raster image command.
181
+ *
182
+ * @param data - RGBA pixel data (Uint8Array, 4 bytes per pixel)
183
+ * @param width - Image width in pixels
184
+ * @param height - Image height in pixels
185
+ * @param options - Image print options (dithering, threshold, greyscale)
186
+ * @returns Array of command buffers
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const imageData = new Uint8Array(width * height * 4); // RGBA
191
+ * driver.image(imageData, 200, 100, { dithering: true });
192
+ * ```
193
+ */
194
+ image(data: Uint8Array, width: number, height: number, options?: StarImageOptions): Uint8Array[];
195
+ /**
196
+ * Sound a beep/buzzer on supported printers
197
+ *
198
+ * Sends a command to activate the printer's built-in buzzer.
199
+ * Useful for alerting operators to print completion or errors.
200
+ *
201
+ * @returns Array of command buffers
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * driver.beep();
206
+ * ```
207
+ */
208
+ beep(): Uint8Array[];
209
+ /**
210
+ * Enable or disable bold text
211
+ *
212
+ * When bold is enabled, subsequent text will be printed in bold.
213
+ * This state persists until explicitly disabled.
214
+ *
215
+ * @param on - true to enable bold, false to disable
216
+ * @returns Array of command buffers
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * driver.bold(true);
221
+ * driver.text('Bold Text');
222
+ * driver.bold(false);
223
+ * ```
224
+ */
225
+ bold(on: boolean): Uint8Array[];
226
+ /**
227
+ * Set text alignment
228
+ *
229
+ * Controls horizontal text alignment for subsequent text.
230
+ * Alignment persists until explicitly changed.
231
+ *
232
+ * @param align - Alignment: 'left' | 'center' | 'right'
233
+ * @returns Array of command buffers
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * driver.align('center');
238
+ * driver.text('Centered Title');
239
+ * driver.align('left');
240
+ * ```
241
+ */
242
+ align(align: Alignment): Uint8Array[];
243
+ }
@@ -7,3 +7,4 @@ export { GPrinterDriver, type GPrinterOptions } from './GPrinterDriver';
7
7
  export { TsplDriver, type LabelSize, type TextOptions, type BarcodeOptions, type QRCodeOptions, type BoxOptions, type LineOptions, } from './TsplDriver';
8
8
  export { ZplDriver, type ZplLabelSize, type ZplTextOptions, type ZplBarcodeOptions, type ZplQRCodeOptions, type ZplBoxOptions, } from './ZplDriver';
9
9
  export { CpclDriver, type CPCLPageSize, type CpclTextOptions, type CpclBarcodeOptions, type CpclQRCodeOptions, type CpclLineOptions, type CpclBoxOptions, } from './CpclDriver';
10
+ export { StarPrinter, type StarPrinterOptions, type Alignment, type BarcodeType, type StarBarcodeOptions, type StarQrOptions, type StarImageOptions, } from './StarPrinter';