taro-bluetooth-print 2.2.0 → 2.3.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 +38 -0
- package/README.md +128 -22
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -6995
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/AdapterFactory.d.ts +0 -1
- package/dist/types/adapters/AlipayAdapter.d.ts +6 -34
- package/dist/types/adapters/BaiduAdapter.d.ts +6 -34
- package/dist/types/adapters/BaseAdapter.d.ts +112 -1
- package/dist/types/adapters/ByteDanceAdapter.d.ts +6 -34
- package/dist/types/adapters/TaroAdapter.d.ts +6 -34
- package/dist/types/adapters/WebBluetoothAdapter.d.ts +0 -1
- package/dist/types/config/PrinterConfig.d.ts +0 -1
- package/dist/types/core/BluetoothPrinter.d.ts +0 -1
- package/dist/types/drivers/EscPos.d.ts +0 -1
- package/dist/types/drivers/TsplDriver.d.ts +251 -0
- package/dist/types/encoding/gbk-data.d.ts +12 -0
- package/dist/types/encoding/gbk-table.d.ts +5 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/plugins/PluginManager.d.ts +87 -0
- package/dist/types/plugins/builtin/LoggingPlugin.d.ts +14 -0
- package/dist/types/plugins/builtin/RetryPlugin.d.ts +18 -0
- package/dist/types/plugins/index.d.ts +7 -0
- package/dist/types/plugins/types.d.ts +97 -0
- package/dist/types/services/CommandBuilder.d.ts +6 -1
- package/dist/types/services/ConnectionManager.d.ts +0 -1
- package/dist/types/services/PrintJobManager.d.ts +6 -2
- package/dist/types/services/interfaces/index.d.ts +0 -1
- package/dist/types/template/TemplateEngine.d.ts +0 -1
- package/package.json +16 -18
- package/src/adapters/AlipayAdapter.ts +8 -314
- package/src/adapters/BaiduAdapter.ts +8 -312
- package/src/adapters/BaseAdapter.ts +366 -0
- package/src/adapters/ByteDanceAdapter.ts +8 -316
- package/src/adapters/TaroAdapter.ts +8 -367
- package/src/core/EventEmitter.ts +9 -6
- package/src/drivers/TsplDriver.ts +417 -0
- package/src/encoding/gbk-data.ts +1911 -0
- package/src/encoding/gbk-table.ts +22 -498
- package/src/index.ts +14 -0
- package/src/plugins/PluginManager.ts +193 -0
- package/src/plugins/builtin/LoggingPlugin.ts +97 -0
- package/src/plugins/builtin/RetryPlugin.ts +109 -0
- package/src/plugins/index.ts +10 -0
- package/src/plugins/types.ts +119 -0
- package/src/preview/PreviewRenderer.ts +7 -1
- package/src/queue/PrintQueue.ts +10 -6
- package/src/services/CommandBuilder.ts +30 -0
- package/src/services/PrintJobManager.ts +51 -35
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
3
|
-
|
|
1
|
+
import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
|
|
4
2
|
/**
|
|
5
3
|
* Alipay Bluetooth Low Energy adapter
|
|
6
4
|
*
|
|
5
|
+
* Uses the Alipay mini-program's BLE APIs (my.xxx).
|
|
6
|
+
* All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
|
|
7
|
+
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
10
|
* const adapter = new AlipayAdapter();
|
|
@@ -12,35 +13,6 @@ import { BaseAdapter } from './BaseAdapter';
|
|
|
12
13
|
* await adapter.disconnect('device-id-123');
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export declare class AlipayAdapter extends
|
|
16
|
-
|
|
17
|
-
* Connects to a Bluetooth device and discovers services
|
|
18
|
-
*
|
|
19
|
-
* @param deviceId - Bluetooth device ID
|
|
20
|
-
* @throws {BluetoothPrintError} When connection fails
|
|
21
|
-
*/
|
|
22
|
-
connect(deviceId: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Disconnects from a Bluetooth device
|
|
25
|
-
*
|
|
26
|
-
* @param deviceId - Bluetooth device ID
|
|
27
|
-
*/
|
|
28
|
-
disconnect(deviceId: string): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes data to the Bluetooth device in chunks with retry logic
|
|
31
|
-
*
|
|
32
|
-
* @param deviceId - Bluetooth device ID
|
|
33
|
-
* @param buffer - Data to write as ArrayBuffer
|
|
34
|
-
* @param options - Write options (chunk size, delay, retries)
|
|
35
|
-
* @throws {BluetoothPrintError} When write fails after retries
|
|
36
|
-
*/
|
|
37
|
-
write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Discovers services and characteristics for a device
|
|
40
|
-
* Caches the writeable characteristic for future writes
|
|
41
|
-
*
|
|
42
|
-
* @param deviceId - Bluetooth device ID
|
|
43
|
-
* @throws {BluetoothPrintError} When no writeable characteristic is found
|
|
44
|
-
*/
|
|
45
|
-
private discoverServices;
|
|
16
|
+
export declare class AlipayAdapter extends MiniProgramAdapter {
|
|
17
|
+
protected getApi(): MiniProgramBLEApi;
|
|
46
18
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
3
|
-
|
|
1
|
+
import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
|
|
4
2
|
/**
|
|
5
3
|
* Baidu Bluetooth Low Energy adapter
|
|
6
4
|
*
|
|
5
|
+
* Uses the Baidu smart program's BLE APIs (swan.xxx).
|
|
6
|
+
* All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
|
|
7
|
+
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
10
|
* const adapter = new BaiduAdapter();
|
|
@@ -12,35 +13,6 @@ import { BaseAdapter } from './BaseAdapter';
|
|
|
12
13
|
* await adapter.disconnect('device-id-123');
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export declare class BaiduAdapter extends
|
|
16
|
-
|
|
17
|
-
* Connects to a Bluetooth device and discovers services
|
|
18
|
-
*
|
|
19
|
-
* @param deviceId - Bluetooth device ID
|
|
20
|
-
* @throws {BluetoothPrintError} When connection fails
|
|
21
|
-
*/
|
|
22
|
-
connect(deviceId: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Disconnects from a Bluetooth device
|
|
25
|
-
*
|
|
26
|
-
* @param deviceId - Bluetooth device ID
|
|
27
|
-
*/
|
|
28
|
-
disconnect(deviceId: string): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes data to the Bluetooth device in chunks with retry logic
|
|
31
|
-
*
|
|
32
|
-
* @param deviceId - Bluetooth device ID
|
|
33
|
-
* @param buffer - Data to write as ArrayBuffer
|
|
34
|
-
* @param options - Write options (chunk size, delay, retries)
|
|
35
|
-
* @throws {BluetoothPrintError} When write fails after retries
|
|
36
|
-
*/
|
|
37
|
-
write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Discovers services and characteristics for a device
|
|
40
|
-
* Caches the writeable characteristic for future writes
|
|
41
|
-
*
|
|
42
|
-
* @param deviceId - Bluetooth device ID
|
|
43
|
-
* @throws {BluetoothPrintError} When no writeable characteristic is found
|
|
44
|
-
*/
|
|
45
|
-
private discoverServices;
|
|
16
|
+
export declare class BaiduAdapter extends MiniProgramAdapter {
|
|
17
|
+
protected getApi(): MiniProgramBLEApi;
|
|
46
18
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IPrinterAdapter, IAdapterOptions, PrinterState } from '../types';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Service information cache entry
|
|
5
4
|
*/
|
|
@@ -7,6 +6,64 @@ export interface ServiceInfo {
|
|
|
7
6
|
serviceId: string;
|
|
8
7
|
characteristicId: string;
|
|
9
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* BLE characteristic properties (common across all mini-program platforms)
|
|
11
|
+
*/
|
|
12
|
+
export interface BLECharacteristicProperties {
|
|
13
|
+
write?: boolean;
|
|
14
|
+
writeWithoutResponse?: boolean;
|
|
15
|
+
read?: boolean;
|
|
16
|
+
notify?: boolean;
|
|
17
|
+
indicate?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* BLE characteristic (common across all mini-program platforms)
|
|
21
|
+
*/
|
|
22
|
+
export interface BLECharacteristic {
|
|
23
|
+
uuid: string;
|
|
24
|
+
properties: BLECharacteristicProperties;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Unified mini-program BLE API interface.
|
|
28
|
+
* All mini-program platforms (Taro/WeChat, Alipay, Baidu, ByteDance)
|
|
29
|
+
* share the same API shape, only the global object differs.
|
|
30
|
+
*/
|
|
31
|
+
export interface MiniProgramBLEApi {
|
|
32
|
+
createBLEConnection(options: {
|
|
33
|
+
deviceId: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
closeBLEConnection(options: {
|
|
36
|
+
deviceId: string;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
getBLEConnectionState(options: {
|
|
39
|
+
deviceId: string;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
connected: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
writeBLECharacteristicValue(options: {
|
|
44
|
+
deviceId: string;
|
|
45
|
+
serviceId: string;
|
|
46
|
+
characteristicId: string;
|
|
47
|
+
value: ArrayBuffer;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
getBLEDeviceServices(options: {
|
|
50
|
+
deviceId: string;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
services: Array<{
|
|
53
|
+
uuid: string;
|
|
54
|
+
}>;
|
|
55
|
+
}>;
|
|
56
|
+
getBLEDeviceCharacteristics(options: {
|
|
57
|
+
deviceId: string;
|
|
58
|
+
serviceId: string;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
characteristics: BLECharacteristic[];
|
|
61
|
+
}>;
|
|
62
|
+
onBLEConnectionStateChange(callback: (res: {
|
|
63
|
+
deviceId: string;
|
|
64
|
+
connected: boolean;
|
|
65
|
+
}) => void): void;
|
|
66
|
+
}
|
|
10
67
|
/**
|
|
11
68
|
* Base adapter class that provides common functionality for all platform-specific adapters
|
|
12
69
|
*/
|
|
@@ -91,3 +148,57 @@ export declare abstract class BaseAdapter implements IPrinterAdapter {
|
|
|
91
148
|
*/
|
|
92
149
|
protected cleanupDevice(deviceId: string): void;
|
|
93
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Base adapter for mini-program platforms (Taro/WeChat, Alipay, Baidu, ByteDance).
|
|
153
|
+
*
|
|
154
|
+
* Implements connect/disconnect/write/discoverServices once with adaptive transmission.
|
|
155
|
+
* Subclasses only need to implement `getApi()` to return the platform-specific BLE API object.
|
|
156
|
+
*/
|
|
157
|
+
export declare abstract class MiniProgramAdapter extends BaseAdapter {
|
|
158
|
+
/**
|
|
159
|
+
* Returns the platform-specific BLE API object.
|
|
160
|
+
* Subclasses must implement this to return the appropriate global (Taro, my, swan, tt).
|
|
161
|
+
*/
|
|
162
|
+
protected abstract getApi(): MiniProgramBLEApi;
|
|
163
|
+
/**
|
|
164
|
+
* Connects to a Bluetooth device and discovers services
|
|
165
|
+
*
|
|
166
|
+
* @param deviceId - Bluetooth device ID
|
|
167
|
+
* @throws {BluetoothPrintError} When connection fails
|
|
168
|
+
*/
|
|
169
|
+
connect(deviceId: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Disconnects from a Bluetooth device
|
|
172
|
+
*
|
|
173
|
+
* @param deviceId - Bluetooth device ID
|
|
174
|
+
*/
|
|
175
|
+
disconnect(deviceId: string): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Writes data to the Bluetooth device in chunks with adaptive transmission.
|
|
178
|
+
*
|
|
179
|
+
* Features:
|
|
180
|
+
* - Automatic chunk size adjustment based on success/failure rate
|
|
181
|
+
* - Dynamic delay adjustment for congestion control
|
|
182
|
+
* - Periodic connection state checks
|
|
183
|
+
* - Exponential backoff for retries
|
|
184
|
+
* - Write timeout per chunk
|
|
185
|
+
*
|
|
186
|
+
* @param deviceId - Bluetooth device ID
|
|
187
|
+
* @param buffer - Data to write as ArrayBuffer
|
|
188
|
+
* @param options - Write options (chunk size, delay, retries)
|
|
189
|
+
* @throws {BluetoothPrintError} When write fails after retries
|
|
190
|
+
*/
|
|
191
|
+
write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Check connection state, throw if disconnected
|
|
194
|
+
*/
|
|
195
|
+
private checkConnectionState;
|
|
196
|
+
/**
|
|
197
|
+
* Discovers services and characteristics for a device.
|
|
198
|
+
* Caches the writeable characteristic for future writes.
|
|
199
|
+
*
|
|
200
|
+
* @param deviceId - Bluetooth device ID
|
|
201
|
+
* @throws {BluetoothPrintError} When no writeable characteristic is found
|
|
202
|
+
*/
|
|
203
|
+
private discoverServices;
|
|
204
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
3
|
-
|
|
1
|
+
import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
|
|
4
2
|
/**
|
|
5
3
|
* ByteDance Bluetooth Low Energy adapter
|
|
6
4
|
*
|
|
5
|
+
* Uses the ByteDance mini-program's BLE APIs (tt.xxx, for Douyin/TikTok etc).
|
|
6
|
+
* All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
|
|
7
|
+
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
10
|
* const adapter = new ByteDanceAdapter();
|
|
@@ -12,35 +13,6 @@ import { BaseAdapter } from './BaseAdapter';
|
|
|
12
13
|
* await adapter.disconnect('device-id-123');
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export declare class ByteDanceAdapter extends
|
|
16
|
-
|
|
17
|
-
* Connects to a Bluetooth device and discovers services
|
|
18
|
-
*
|
|
19
|
-
* @param deviceId - Bluetooth device ID
|
|
20
|
-
* @throws {BluetoothPrintError} When connection fails
|
|
21
|
-
*/
|
|
22
|
-
connect(deviceId: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Disconnects from a Bluetooth device
|
|
25
|
-
*
|
|
26
|
-
* @param deviceId - Bluetooth device ID
|
|
27
|
-
*/
|
|
28
|
-
disconnect(deviceId: string): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes data to the Bluetooth device in chunks with retry logic
|
|
31
|
-
*
|
|
32
|
-
* @param deviceId - Bluetooth device ID
|
|
33
|
-
* @param buffer - Data to write as ArrayBuffer
|
|
34
|
-
* @param options - Write options (chunk size, delay, retries)
|
|
35
|
-
* @throws {BluetoothPrintError} When write fails after retries
|
|
36
|
-
*/
|
|
37
|
-
write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Discovers services and characteristics for a device
|
|
40
|
-
* Caches the writeable characteristic for future writes
|
|
41
|
-
*
|
|
42
|
-
* @param deviceId - Bluetooth device ID
|
|
43
|
-
* @throws {BluetoothPrintError} When no writeable characteristic is found
|
|
44
|
-
*/
|
|
45
|
-
private discoverServices;
|
|
16
|
+
export declare class ByteDanceAdapter extends MiniProgramAdapter {
|
|
17
|
+
protected getApi(): MiniProgramBLEApi;
|
|
46
18
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
3
|
-
|
|
1
|
+
import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
|
|
4
2
|
/**
|
|
5
3
|
* Taro Bluetooth Low Energy adapter
|
|
6
4
|
*
|
|
5
|
+
* Uses the Taro framework's BLE APIs (compatible with WeChat mini-program).
|
|
6
|
+
* All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
|
|
7
|
+
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
9
10
|
* const adapter = new TaroAdapter();
|
|
@@ -12,35 +13,6 @@ import { BaseAdapter } from './BaseAdapter';
|
|
|
12
13
|
* await adapter.disconnect('device-id-123');
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export declare class TaroAdapter extends
|
|
16
|
-
|
|
17
|
-
* Connects to a Bluetooth device and discovers services
|
|
18
|
-
*
|
|
19
|
-
* @param deviceId - Bluetooth device ID
|
|
20
|
-
* @throws {BluetoothPrintError} When connection fails
|
|
21
|
-
*/
|
|
22
|
-
connect(deviceId: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Disconnects from a Bluetooth device
|
|
25
|
-
*
|
|
26
|
-
* @param deviceId - Bluetooth device ID
|
|
27
|
-
*/
|
|
28
|
-
disconnect(deviceId: string): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes data to the Bluetooth device in chunks with retry logic
|
|
31
|
-
*
|
|
32
|
-
* @param deviceId - Bluetooth device ID
|
|
33
|
-
* @param buffer - Data to write as ArrayBuffer
|
|
34
|
-
* @param options - Write options (chunk size, delay, retries)
|
|
35
|
-
* @throws {BluetoothPrintError} When write fails after retries
|
|
36
|
-
*/
|
|
37
|
-
write(deviceId: string, buffer: ArrayBuffer, options?: IAdapterOptions): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Discovers services and characteristics for a device
|
|
40
|
-
* Caches the writeable characteristic for future writes
|
|
41
|
-
*
|
|
42
|
-
* @param deviceId - Bluetooth device ID
|
|
43
|
-
* @throws {BluetoothPrintError} When no writeable characteristic is found
|
|
44
|
-
*/
|
|
45
|
-
private discoverServices;
|
|
16
|
+
export declare class TaroAdapter extends MiniProgramAdapter {
|
|
17
|
+
protected getApi(): MiniProgramBLEApi;
|
|
46
18
|
}
|
|
@@ -2,7 +2,6 @@ import { IAdapterOptions, IQrOptions, PrinterState, IPrinterAdapter } from '../t
|
|
|
2
2
|
import { EventEmitter } from './EventEmitter';
|
|
3
3
|
import { BluetoothPrintError } from '../errors/BluetoothError';
|
|
4
4
|
import { IConnectionManager, IPrintJobManager, ICommandBuilder } from '../services/interfaces';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Event types emitted by BluetoothPrinter
|
|
8
7
|
*/
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TSPL Driver
|
|
3
|
+
* TSC Printer Language driver for label/barcode printers
|
|
4
|
+
*
|
|
5
|
+
* TSPL is commonly used in thermal transfer label printers (TSC, Zebra, etc.)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Label size configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface LabelSize {
|
|
11
|
+
/** Label width in mm */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Label height in mm */
|
|
14
|
+
height: number;
|
|
15
|
+
/** Gap between labels in mm (default: 3) */
|
|
16
|
+
gap?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Text position and style
|
|
20
|
+
*/
|
|
21
|
+
export interface TextOptions {
|
|
22
|
+
/** X position in dots */
|
|
23
|
+
x: number;
|
|
24
|
+
/** Y position in dots */
|
|
25
|
+
y: number;
|
|
26
|
+
/** Font size (1-8, default: 2) */
|
|
27
|
+
font?: number;
|
|
28
|
+
/** Rotation (0, 90, 180, 270, default: 0) */
|
|
29
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
30
|
+
/** Horizontal multiplier (1-10, default: 1) */
|
|
31
|
+
xMultiplier?: number;
|
|
32
|
+
/** Vertical multiplier (1-10, default: 1) */
|
|
33
|
+
yMultiplier?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Barcode options
|
|
37
|
+
*/
|
|
38
|
+
export interface BarcodeOptions {
|
|
39
|
+
/** X position in dots */
|
|
40
|
+
x: number;
|
|
41
|
+
/** Y position in dots */
|
|
42
|
+
y: number;
|
|
43
|
+
/** Barcode type */
|
|
44
|
+
type: '128' | '39' | 'EAN13' | 'EAN8' | 'UPCA' | 'QRCODE';
|
|
45
|
+
/** Height in dots (default: 100) */
|
|
46
|
+
height?: number;
|
|
47
|
+
/** Narrow bar width (default: 2) */
|
|
48
|
+
narrow?: number;
|
|
49
|
+
/** Wide bar width (default: 4) */
|
|
50
|
+
wide?: number;
|
|
51
|
+
/** Show human-readable text (default: true) */
|
|
52
|
+
showText?: boolean;
|
|
53
|
+
/** Rotation (0, 90, 180, 270, default: 0) */
|
|
54
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* QR Code options
|
|
58
|
+
*/
|
|
59
|
+
export interface QRCodeOptions {
|
|
60
|
+
/** X position in dots */
|
|
61
|
+
x: number;
|
|
62
|
+
/** Y position in dots */
|
|
63
|
+
y: number;
|
|
64
|
+
/** Error correction level (L, M, Q, H, default: M) */
|
|
65
|
+
eccLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
66
|
+
/** Cell width (1-10, default: 6) */
|
|
67
|
+
cellWidth?: number;
|
|
68
|
+
/** Mode (A=Auto, M=Manual, default: A) */
|
|
69
|
+
mode?: 'A' | 'M';
|
|
70
|
+
/** Rotation (0, 90, 180, 270, default: 0) */
|
|
71
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Box/Rectangle options
|
|
75
|
+
*/
|
|
76
|
+
export interface BoxOptions {
|
|
77
|
+
/** X position in dots */
|
|
78
|
+
x: number;
|
|
79
|
+
/** Y position in dots */
|
|
80
|
+
y: number;
|
|
81
|
+
/** Width in dots */
|
|
82
|
+
width: number;
|
|
83
|
+
/** Height in dots */
|
|
84
|
+
height: number;
|
|
85
|
+
/** Line thickness (default: 2) */
|
|
86
|
+
thickness?: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Line options
|
|
90
|
+
*/
|
|
91
|
+
export interface LineOptions {
|
|
92
|
+
/** Start X position in dots */
|
|
93
|
+
x1: number;
|
|
94
|
+
/** Start Y position in dots */
|
|
95
|
+
y1: number;
|
|
96
|
+
/** End X position in dots */
|
|
97
|
+
x2: number;
|
|
98
|
+
/** End Y position in dots */
|
|
99
|
+
y2: number;
|
|
100
|
+
/** Line thickness (default: 2) */
|
|
101
|
+
thickness?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* TSPL Driver for label printers
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const tspl = new TsplDriver();
|
|
109
|
+
*
|
|
110
|
+
* const commands = tspl
|
|
111
|
+
* .size(60, 40)
|
|
112
|
+
* .gap(3)
|
|
113
|
+
* .clear()
|
|
114
|
+
* .text('Product Name', { x: 50, y: 50, font: 3 })
|
|
115
|
+
* .barcode('1234567890', { x: 50, y: 100, type: '128' })
|
|
116
|
+
* .print(1)
|
|
117
|
+
* .getBuffer();
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare class TsplDriver {
|
|
121
|
+
private commands;
|
|
122
|
+
private readonly logger;
|
|
123
|
+
private dpi;
|
|
124
|
+
/**
|
|
125
|
+
* Set printer DPI (dots per inch)
|
|
126
|
+
* @param dpi - DPI value (203 or 300)
|
|
127
|
+
*/
|
|
128
|
+
setDPI(dpi: 203 | 300): this;
|
|
129
|
+
/**
|
|
130
|
+
* Convert mm to dots
|
|
131
|
+
*/
|
|
132
|
+
mmToDots(mm: number): number;
|
|
133
|
+
/**
|
|
134
|
+
* Convert dots to mm
|
|
135
|
+
*/
|
|
136
|
+
dotsToMm(dots: number): number;
|
|
137
|
+
/**
|
|
138
|
+
* Set label size
|
|
139
|
+
* @param width - Label width in mm
|
|
140
|
+
* @param height - Label height in mm
|
|
141
|
+
*/
|
|
142
|
+
size(width: number, height: number): this;
|
|
143
|
+
/**
|
|
144
|
+
* Set gap between labels
|
|
145
|
+
* @param gap - Gap size in mm
|
|
146
|
+
* @param offset - Offset in mm (default: 0)
|
|
147
|
+
*/
|
|
148
|
+
gap(gap: number, offset?: number): this;
|
|
149
|
+
/**
|
|
150
|
+
* Set print speed
|
|
151
|
+
* @param speed - Speed level (1-10)
|
|
152
|
+
*/
|
|
153
|
+
speed(speed: number): this;
|
|
154
|
+
/**
|
|
155
|
+
* Set print density
|
|
156
|
+
* @param density - Density level (0-15)
|
|
157
|
+
*/
|
|
158
|
+
density(density: number): this;
|
|
159
|
+
/**
|
|
160
|
+
* Set print direction
|
|
161
|
+
* @param direction - 0=normal, 1=reversed
|
|
162
|
+
*/
|
|
163
|
+
direction(direction: 0 | 1): this;
|
|
164
|
+
/**
|
|
165
|
+
* Clear image buffer
|
|
166
|
+
*/
|
|
167
|
+
clear(): this;
|
|
168
|
+
/**
|
|
169
|
+
* Add text to label
|
|
170
|
+
* @param content - Text content
|
|
171
|
+
* @param options - Text options
|
|
172
|
+
*/
|
|
173
|
+
text(content: string, options: TextOptions): this;
|
|
174
|
+
/**
|
|
175
|
+
* Add barcode to label
|
|
176
|
+
* @param content - Barcode content
|
|
177
|
+
* @param options - Barcode options
|
|
178
|
+
*/
|
|
179
|
+
barcode(content: string, options: BarcodeOptions): this;
|
|
180
|
+
/**
|
|
181
|
+
* Add QR code to label
|
|
182
|
+
* @param content - QR code content
|
|
183
|
+
* @param options - QR code options
|
|
184
|
+
*/
|
|
185
|
+
qrcode(content: string, options: QRCodeOptions): this;
|
|
186
|
+
/**
|
|
187
|
+
* Draw a box/rectangle
|
|
188
|
+
* @param options - Box options
|
|
189
|
+
*/
|
|
190
|
+
box(options: BoxOptions): this;
|
|
191
|
+
/**
|
|
192
|
+
* Draw a line
|
|
193
|
+
* @param options - Line options
|
|
194
|
+
*/
|
|
195
|
+
line(options: LineOptions): this;
|
|
196
|
+
/**
|
|
197
|
+
* Fill a rectangular area
|
|
198
|
+
* @param x - X position
|
|
199
|
+
* @param y - Y position
|
|
200
|
+
* @param width - Width
|
|
201
|
+
* @param height - Height
|
|
202
|
+
*/
|
|
203
|
+
bar(x: number, y: number, width: number, height: number): this;
|
|
204
|
+
/**
|
|
205
|
+
* Reverse a rectangular area (white becomes black and vice versa)
|
|
206
|
+
* @param x - X position
|
|
207
|
+
* @param y - Y position
|
|
208
|
+
* @param width - Width
|
|
209
|
+
* @param height - Height
|
|
210
|
+
*/
|
|
211
|
+
reverse(x: number, y: number, width: number, height: number): this;
|
|
212
|
+
/**
|
|
213
|
+
* Print the label
|
|
214
|
+
* @param copies - Number of copies (default: 1)
|
|
215
|
+
* @param sets - Number of sets (default: 1)
|
|
216
|
+
*/
|
|
217
|
+
print(copies?: number, sets?: number): this;
|
|
218
|
+
/**
|
|
219
|
+
* Feed labels
|
|
220
|
+
* @param count - Number of labels to feed
|
|
221
|
+
*/
|
|
222
|
+
feed(count?: number): this;
|
|
223
|
+
/**
|
|
224
|
+
* Cut paper (if cutter available)
|
|
225
|
+
*/
|
|
226
|
+
cut(): this;
|
|
227
|
+
/**
|
|
228
|
+
* Beep the buzzer
|
|
229
|
+
*/
|
|
230
|
+
beep(): this;
|
|
231
|
+
/**
|
|
232
|
+
* Home the print head
|
|
233
|
+
*/
|
|
234
|
+
home(): this;
|
|
235
|
+
/**
|
|
236
|
+
* Escape special characters in string
|
|
237
|
+
*/
|
|
238
|
+
private escapeString;
|
|
239
|
+
/**
|
|
240
|
+
* Get all commands as string
|
|
241
|
+
*/
|
|
242
|
+
getCommands(): string;
|
|
243
|
+
/**
|
|
244
|
+
* Get commands as buffer for sending to printer
|
|
245
|
+
*/
|
|
246
|
+
getBuffer(): Uint8Array;
|
|
247
|
+
/**
|
|
248
|
+
* Clear all commands
|
|
249
|
+
*/
|
|
250
|
+
reset(): this;
|
|
251
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GBK/Big5 Encoding Data
|
|
3
|
+
*
|
|
4
|
+
* 紧凑的编码映射数据。
|
|
5
|
+
* 扁平数组格式: [unicode1, gbk1, unicode2, gbk2, ...]
|
|
6
|
+
* GBK: 23940 个字符映射
|
|
7
|
+
* Big5: 13911 个字符映射
|
|
8
|
+
*
|
|
9
|
+
* 由脚本自动生成,请勿手动编辑。
|
|
10
|
+
*/
|
|
11
|
+
export declare const GBK_DATA: number[];
|
|
12
|
+
export declare const BIG5_DATA: number[];
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* GBK encoding uses double-byte encoding for Chinese characters:
|
|
9
9
|
* - First byte: 0x81-0xFE
|
|
10
10
|
* - Second byte: 0x40-0xFE (excluding 0x7F)
|
|
11
|
+
*
|
|
12
|
+
* 映射数据存储在 gbk-data.ts 中,运行时解码为 Map。
|
|
13
|
+
* GBK: 23940 个字符映射
|
|
14
|
+
* Big5: 13911 个字符映射
|
|
11
15
|
*/
|
|
12
16
|
/**
|
|
13
17
|
* Unicode to GBK mapping table
|
|
@@ -30,7 +34,7 @@ export declare const big5ToUnicode: Map<number, number>;
|
|
|
30
34
|
/**
|
|
31
35
|
* Get GBK bytes for a Unicode character
|
|
32
36
|
* @param unicode - Unicode code point
|
|
33
|
-
* @returns GBK byte pair or null if not found
|
|
37
|
+
* @returns GBK byte pair [high, low] or null if not found
|
|
34
38
|
*/
|
|
35
39
|
export declare function getGbkBytes(unicode: number): [number, number] | null;
|
|
36
40
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { BluetoothPrinter } from './core/BluetoothPrinter';
|
|
|
8
8
|
export type { PrinterEvents } from './core/BluetoothPrinter';
|
|
9
9
|
export { EventEmitter } from './core/EventEmitter';
|
|
10
10
|
export { EscPos } from './drivers/EscPos';
|
|
11
|
+
export { TsplDriver } from './drivers/TsplDriver';
|
|
12
|
+
export type { LabelSize, TextOptions as TsplTextOptions, BarcodeOptions as TsplBarcodeOptions, QRCodeOptions as TsplQRCodeOptions, BoxOptions, LineOptions, } from './drivers/TsplDriver';
|
|
11
13
|
export { TaroAdapter } from './adapters/TaroAdapter';
|
|
12
14
|
export { AdapterFactory } from './adapters/AdapterFactory';
|
|
13
15
|
export { BaseAdapter } from './adapters/BaseAdapter';
|
|
@@ -38,4 +40,7 @@ export { PlatformType, detectPlatform, isPlatformSupported } from './utils/platf
|
|
|
38
40
|
export { BluetoothPrintError, ErrorCode } from './errors/BluetoothError';
|
|
39
41
|
export { DEFAULT_CONFIG, mergeConfig } from './config/PrinterConfig';
|
|
40
42
|
export type { PrinterConfig, AdapterConfig, DriverConfig, LoggingConfig, } from './config/PrinterConfig';
|
|
43
|
+
export { PluginManager } from './plugins/PluginManager';
|
|
44
|
+
export { createLoggingPlugin, createRetryPlugin } from './plugins';
|
|
45
|
+
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/types';
|
|
41
46
|
export * from './types';
|