taro-bluetooth-print 2.4.0 → 2.5.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.
- package/CHANGELOG.md +41 -0
- package/README.md +10 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/QQAdapter.d.ts +22 -0
- package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
- package/dist/types/adapters/index.d.ts +13 -0
- package/dist/types/device/MultiPrinterManager.d.ts +1 -1
- package/dist/types/drivers/StarPrinter.d.ts +243 -0
- package/dist/types/drivers/index.d.ts +1 -0
- package/dist/types/encoding/EncodingService.d.ts +41 -2
- package/dist/types/encoding/index.d.ts +2 -1
- package/dist/types/encoding/korean-japanese.d.ts +127 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/services/BatchPrintManager.d.ts +98 -5
- package/dist/types/services/PrintStatistics.d.ts +189 -0
- package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
- package/dist/types/services/index.d.ts +5 -3
- package/dist/types/utils/image.d.ts +40 -119
- package/dist/types/utils/platform.d.ts +2 -0
- package/package.json +1 -1
- package/src/adapters/AdapterFactory.ts +5 -0
- package/src/adapters/QQAdapter.ts +36 -0
- package/src/adapters/ReactNativeAdapter.ts +517 -0
- package/src/adapters/index.ts +14 -0
- package/src/config/PrinterConfigManager.ts +10 -6
- package/src/device/MultiPrinterManager.ts +10 -10
- package/src/drivers/StarPrinter.ts +555 -0
- package/src/drivers/index.ts +10 -0
- package/src/encoding/EncodingService.ts +261 -4
- package/src/encoding/index.ts +17 -1
- package/src/encoding/korean-japanese.ts +289 -0
- package/src/index.ts +1 -5
- package/src/services/BatchPrintManager.ts +312 -42
- package/src/services/PrintHistory.ts +13 -11
- package/src/services/PrintJobManager.ts +3 -3
- package/src/services/PrintStatistics.ts +504 -0
- package/src/services/PrinterStatus.ts +4 -10
- package/src/services/ScheduledRetryManager.ts +564 -0
- package/src/services/index.ts +38 -3
- package/src/utils/image.ts +476 -342
- package/src/utils/platform.ts +20 -34
|
@@ -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 {};
|
|
@@ -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';
|
|
@@ -132,7 +132,7 @@ export declare class MultiPrinterManager {
|
|
|
132
132
|
/**
|
|
133
133
|
* Print to a specific printer
|
|
134
134
|
*/
|
|
135
|
-
print(printerId: string, data: Uint8Array):
|
|
135
|
+
print(printerId: string, data: Uint8Array): void;
|
|
136
136
|
/**
|
|
137
137
|
* Broadcast data to all connected printers
|
|
138
138
|
*/
|
|
@@ -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';
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Encoding Service
|
|
3
3
|
*
|
|
4
|
-
* Provides comprehensive encoding support for
|
|
4
|
+
* Provides comprehensive encoding support for:
|
|
5
|
+
* - GBK, GB2312, Big5 (Chinese)
|
|
6
|
+
* - EUC-KR (Korean)
|
|
7
|
+
* - Shift-JIS, ISO-2022-JP (Japanese)
|
|
8
|
+
* - UTF-8
|
|
9
|
+
*
|
|
5
10
|
* Handles character conversion for thermal printer output.
|
|
6
11
|
*
|
|
7
12
|
* @example
|
|
8
13
|
* ```typescript
|
|
9
14
|
* const service = new EncodingService();
|
|
10
15
|
* const bytes = service.encode('你好世界', 'GBK');
|
|
16
|
+
* const korean = service.encode('안녕하세요', 'EUC-KR');
|
|
17
|
+
* const japanese = service.encode('こんにちは', 'Shift-JIS');
|
|
11
18
|
* const detected = service.detectEncoding('Hello 世界');
|
|
12
19
|
* ```
|
|
13
20
|
*/
|
|
14
21
|
/**
|
|
15
22
|
* Supported encoding types
|
|
16
23
|
*/
|
|
17
|
-
export type SupportedEncoding = 'GBK' | 'GB2312' | 'BIG5' | 'UTF-8' | 'UTF8';
|
|
24
|
+
export type SupportedEncoding = 'GBK' | 'GB2312' | 'BIG5' | 'UTF-8' | 'UTF8' | 'EUC-KR' | 'EUCKR' | 'SHIFT-JIS' | 'SHIFTJIS' | 'SJIS' | 'ISO-2022-JP' | 'ISO2022JP' | 'JIS';
|
|
18
25
|
/**
|
|
19
26
|
* Encoding configuration options
|
|
20
27
|
*/
|
|
@@ -130,6 +137,38 @@ export declare class EncodingService {
|
|
|
130
137
|
* @returns Big5 encoded bytes
|
|
131
138
|
*/
|
|
132
139
|
private encodeBig5;
|
|
140
|
+
/**
|
|
141
|
+
* Encode text to EUC-KR (Korean) bytes
|
|
142
|
+
*
|
|
143
|
+
* EUC-KR (KS X 1001) is the standard Korean character encoding.
|
|
144
|
+
* Supports Hangul syllables, Hanja, and special Korean characters.
|
|
145
|
+
* Uses TextEncoder when available for full coverage.
|
|
146
|
+
*
|
|
147
|
+
* @param text - Text to encode
|
|
148
|
+
* @returns EUC-KR encoded bytes
|
|
149
|
+
*/
|
|
150
|
+
private encodeKorean;
|
|
151
|
+
/**
|
|
152
|
+
* Encode text to Shift-JIS (Japanese) bytes
|
|
153
|
+
*
|
|
154
|
+
* Shift-JIS (JIS X 0201/0208) is the standard Japanese encoding.
|
|
155
|
+
* Supports Hiragana, Katakana, Kanji, and punctuation.
|
|
156
|
+
* Uses TextEncoder when available for full coverage.
|
|
157
|
+
*
|
|
158
|
+
* @param text - Text to encode
|
|
159
|
+
* @returns Shift-JIS encoded bytes
|
|
160
|
+
*/
|
|
161
|
+
private encodeShiftJis;
|
|
162
|
+
/**
|
|
163
|
+
* Encode text to ISO-2022-JP (Japanese) bytes
|
|
164
|
+
*
|
|
165
|
+
* ISO-2022-JP (JIS X 4081) uses escape sequences to switch character sets.
|
|
166
|
+
* Format: ESC ( B for ASCII, ESC $ B for JIS X 0208 (Kanji/Katakana).
|
|
167
|
+
*
|
|
168
|
+
* @param text - Text to encode
|
|
169
|
+
* @returns ISO-2022-JP encoded bytes with escape sequences
|
|
170
|
+
*/
|
|
171
|
+
private encodeIso2022Jp;
|
|
133
172
|
/**
|
|
134
173
|
* Normalize encoding name to standard format
|
|
135
174
|
* @param encoding - Encoding name
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Encoding Service Module
|
|
3
|
-
* 编码服务模块 - 负责字符集转换 (GBK, GB2312, Big5, UTF-8)
|
|
3
|
+
* 编码服务模块 - 负责字符集转换 (GBK, GB2312, Big5, EUC-KR, Shift-JIS, ISO-2022-JP, UTF-8)
|
|
4
4
|
*/
|
|
5
5
|
export { EncodingService, encodingService, type EncodingConfig, type EncodingResult, type SupportedEncoding, } from './EncodingService';
|
|
6
6
|
export { unicodeToGbk, gbkToUnicode, unicodeToBig5, big5ToUnicode, getGbkBytes, getUnicodeFromGbk, getBig5Bytes, isAscii, isCjk, isChinesePunctuation, } from './gbk-table';
|
|
7
|
+
export { encodeHangulSyllable, isKoreanHangul, isKoreanHanja, isKoreanJamo, unicodeToShiftJisHiragana, unicodeToShiftJisKatakana, isJapaneseHiragana, isJapaneseKatakana, isJapaneseKanji, ISO2022JP_ESC_ASCII, ISO2022JP_ESC_JIS0208, requiresJisX0208Escape, isJisX0201Katakana, } from './korean-japanese';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Korean & Japanese Encoding Tables
|
|
3
|
+
*
|
|
4
|
+
* Provides character mapping support for:
|
|
5
|
+
* - EUC-KR (Korean) - KS X 1001/1003 encoding
|
|
6
|
+
* - Shift-JIS (Japanese) - JIS X 0201/0208 encoding
|
|
7
|
+
* - ISO-2022-JP (Japanese) - JIS encoding with escape sequences
|
|
8
|
+
*
|
|
9
|
+
* Note: For full coverage, these use TextEncoder/TextDecoder as the primary
|
|
10
|
+
* implementation since they provide native support in modern environments.
|
|
11
|
+
* The mapping tables here serve as reference and fallback.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* KS X 1001 (Hangul) code range in EUC-KR:
|
|
15
|
+
* First byte: 0xB0-0xC8 (128-200)
|
|
16
|
+
* Second byte: 0xA1-0xFE (161-254)
|
|
17
|
+
*
|
|
18
|
+
* KS X 1003 (Hanja) code range in EUC-KR:
|
|
19
|
+
* First byte: 0xCA-0xFD
|
|
20
|
+
* Second byte: 0xA1-0xFE
|
|
21
|
+
*/
|
|
22
|
+
export declare const HANGUL_SYLLABLE_OFFSET = 44032;
|
|
23
|
+
export declare const HANGUL_INITIAL_COUNT = 21;
|
|
24
|
+
export declare const HANGUL_MEDIAL_COUNT = 21;
|
|
25
|
+
export declare const HANGUL_FINAL_COUNT = 28;
|
|
26
|
+
/**
|
|
27
|
+
* JIS X 0201 (Half-width Katakana):
|
|
28
|
+
* First byte: 0xA1-0xDF (single-byte)
|
|
29
|
+
*
|
|
30
|
+
* JIS X 0208 (Kanji):
|
|
31
|
+
* First byte: 0x81-0x9F (low) or 0xE0-0xEF (high)
|
|
32
|
+
* Second byte: 0x40-0x7E (low) or 0x80-0xFC (high)
|
|
33
|
+
*
|
|
34
|
+
* JIS X 0212 (Supplementary Kanji):
|
|
35
|
+
* First byte: 0xE0-0xEA
|
|
36
|
+
* Second byte: 0x40-0x7E or 0x80-0xFC
|
|
37
|
+
*/
|
|
38
|
+
export declare const SHIFT_JIS_KATAKANA_START = 161;
|
|
39
|
+
export declare const SHIFT_JIS_KATAKANA_END = 223;
|
|
40
|
+
export declare const SHIFT_JIS_KANJI_LOW_START = 129;
|
|
41
|
+
export declare const SHIFT_JIS_KANJI_LOW_END = 159;
|
|
42
|
+
export declare const SHIFT_JIS_KANJI_HIGH_START = 224;
|
|
43
|
+
export declare const SHIFT_JIS_KANJI_HIGH_END = 239;
|
|
44
|
+
export declare const SHIFT_JIS_KANJI_SECOND_MIN = 64;
|
|
45
|
+
export declare const SHIFT_JIS_KANJI_SECOND_MAX = 252;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a Unicode code point is a Korean Hangul syllable
|
|
48
|
+
*/
|
|
49
|
+
export declare function isKoreanHangul(code: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a Unicode code point is a Korean Hanja (Hanja)
|
|
52
|
+
*/
|
|
53
|
+
export declare function isKoreanHanja(code: number): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a Unicode code point is basic Korean (Hangul Jamo)
|
|
56
|
+
*/
|
|
57
|
+
export declare function isKoreanJamo(code: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a code point is Japanese Hiragana
|
|
60
|
+
*/
|
|
61
|
+
export declare function isJapaneseHiragana(code: number): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a code point is Japanese Katakana (full-width)
|
|
64
|
+
*/
|
|
65
|
+
export declare function isJapaneseKatakana(code: number): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a code point is Japanese Kanji (CJK Unified Ideographs in Japanese range)
|
|
68
|
+
*/
|
|
69
|
+
export declare function isJapaneseKanji(code: number): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Encode a Hangul syllable to EUC-KR bytes
|
|
72
|
+
*
|
|
73
|
+
* Hangul syllables in Unicode are algorithmically decomposable:
|
|
74
|
+
* 1. Syllable = 0xAC00 + (initial × 21 + medial) × 28 + final
|
|
75
|
+
* 2. We decompose to lead, vowel, trail
|
|
76
|
+
* 3. Then convert to EUC-KR lead/trail bytes
|
|
77
|
+
*/
|
|
78
|
+
export declare function encodeHangulSyllable(code: number): [number, number] | null;
|
|
79
|
+
/**
|
|
80
|
+
* Convert Unicode Hiragana to Shift-JIS
|
|
81
|
+
* U+3040-309F → 0x829F-0x82F1 (simplified mapping)
|
|
82
|
+
*/
|
|
83
|
+
export declare function unicodeToShiftJisHiragana(code: number): [number, number] | null;
|
|
84
|
+
/**
|
|
85
|
+
* Convert Unicode Katakana to Shift-JIS
|
|
86
|
+
* U+30A0-30FF → 0x8340-0x8396 (full-width Katakana)
|
|
87
|
+
*/
|
|
88
|
+
export declare function unicodeToShiftJisKatakana(code: number): [number, number] | null;
|
|
89
|
+
/**
|
|
90
|
+
* Convert half-width Katakana to Shift-JIS
|
|
91
|
+
* U+FF61-U+FF9F → 0xA1-0xDF
|
|
92
|
+
*/
|
|
93
|
+
export declare function unicodeToHalfWidthKatakana(code: number): number | null;
|
|
94
|
+
/**
|
|
95
|
+
* Check if a code point is in JIS X 0208 range and estimate its Shift-JIS position
|
|
96
|
+
* This is a simplified heuristic - full conversion requires large tables
|
|
97
|
+
*/
|
|
98
|
+
export declare function isInJisX0208Range(code: number): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* ISO-2022-JP (JIS X 4081) escape sequences:
|
|
101
|
+
* - ESC ( B - ASCII
|
|
102
|
+
* - ESC ( J - JIS X 0201 Roman
|
|
103
|
+
* - ESC $ B - JIS X 0208
|
|
104
|
+
* - ESC $ @ - JIS X 0208:1983 (old)
|
|
105
|
+
* - ESC $ D - JIS X 0208:1990 (new)
|
|
106
|
+
* - ESC $ ( C - JIS X 0212 supplementary
|
|
107
|
+
*/
|
|
108
|
+
/**
|
|
109
|
+
* ISO-2022-JP escape sequences
|
|
110
|
+
*/
|
|
111
|
+
export declare const ISO2022JP_ESC_ASCII: Uint8Array<ArrayBuffer>;
|
|
112
|
+
export declare const ISO2022JP_ESC_JIS0201: Uint8Array<ArrayBuffer>;
|
|
113
|
+
export declare const ISO2022JP_ESC_JIS0208: Uint8Array<ArrayBuffer>;
|
|
114
|
+
export declare const ISO2022JP_ESC_JIS0208_83: Uint8Array<ArrayBuffer>;
|
|
115
|
+
export declare const ISO2022JP_ESC_JIS0208_90: Uint8Array<ArrayBuffer>;
|
|
116
|
+
/**
|
|
117
|
+
* ISO-2022-JP text encoder state
|
|
118
|
+
*/
|
|
119
|
+
export type ISO2022JPState = 'ASCII' | 'JIS0208' | 'JIS0201';
|
|
120
|
+
/**
|
|
121
|
+
* Check if a code point requires JIS X 0208 escape sequence
|
|
122
|
+
*/
|
|
123
|
+
export declare function requiresJisX0208Escape(code: number): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Check if a code point is JIS X 0201 Katakana (half-width)
|
|
126
|
+
*/
|
|
127
|
+
export declare function isJisX0201Katakana(code: number): boolean;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export { BluetoothPrintError, ErrorCode } from './errors/BluetoothError';
|
|
|
43
43
|
export { DEFAULT_CONFIG, mergeConfig } from './config/PrinterConfig';
|
|
44
44
|
export type { PrinterConfig, AdapterConfig, DriverConfig, LoggingConfig, } from './config/PrinterConfig';
|
|
45
45
|
export { PrinterConfigManager, printerConfigManager } from './config/PrinterConfigManager';
|
|
46
|
-
export type { SavedPrinter, GlobalConfig, IConfigStorage
|
|
46
|
+
export type { SavedPrinter, GlobalConfig, IConfigStorage } from './config/PrinterConfigManager';
|
|
47
47
|
export { PluginManager } from './plugins/PluginManager';
|
|
48
48
|
export { createLoggingPlugin, createRetryPlugin } from './plugins';
|
|
49
49
|
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/types';
|