taro-bluetooth-print 2.2.1 → 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 -14
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -81644
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/AdapterFactory.d.ts +0 -1
- package/dist/types/adapters/AlipayAdapter.d.ts +0 -1
- package/dist/types/adapters/BaiduAdapter.d.ts +0 -1
- package/dist/types/adapters/BaseAdapter.d.ts +0 -1
- package/dist/types/adapters/ByteDanceAdapter.d.ts +0 -1
- package/dist/types/adapters/TaroAdapter.d.ts +0 -1
- 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/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 +0 -1
- package/dist/types/services/ConnectionManager.d.ts +0 -1
- package/dist/types/services/PrintJobManager.d.ts +0 -1
- package/dist/types/services/interfaces/index.d.ts +0 -1
- package/dist/types/template/TemplateEngine.d.ts +0 -1
- package/package.json +15 -17
- package/src/drivers/TsplDriver.ts +417 -0
- 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
|
@@ -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
|
+
}
|
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';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Plugin, PluginHooks, PluginOptions } from './types';
|
|
2
|
+
import { BluetoothPrintError } from '../errors/BluetoothError';
|
|
3
|
+
import { PrinterState } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Manages plugins for BluetoothPrinter
|
|
6
|
+
*/
|
|
7
|
+
export declare class PluginManager {
|
|
8
|
+
private plugins;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
/**
|
|
11
|
+
* Register a plugin
|
|
12
|
+
* @param plugin - Plugin to register
|
|
13
|
+
* @param options - Plugin options
|
|
14
|
+
* @throws {BluetoothPrintError} If plugin with same name already exists
|
|
15
|
+
*/
|
|
16
|
+
register(plugin: Plugin, options?: PluginOptions): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Unregister a plugin
|
|
19
|
+
* @param name - Plugin name to unregister
|
|
20
|
+
*/
|
|
21
|
+
unregister(name: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a registered plugin
|
|
24
|
+
* @param name - Plugin name
|
|
25
|
+
* @returns Plugin instance or undefined
|
|
26
|
+
*/
|
|
27
|
+
get(name: string): Plugin | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Get all registered plugin names
|
|
30
|
+
* @returns Array of plugin names
|
|
31
|
+
*/
|
|
32
|
+
getNames(): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if a plugin is registered
|
|
35
|
+
* @param name - Plugin name
|
|
36
|
+
* @returns True if registered
|
|
37
|
+
*/
|
|
38
|
+
has(name: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a hook across all plugins
|
|
41
|
+
* @param hookName - Name of the hook to execute
|
|
42
|
+
* @param args - Arguments to pass to the hook
|
|
43
|
+
* @returns Result from hooks (last non-void result)
|
|
44
|
+
*/
|
|
45
|
+
executeHook<K extends keyof PluginHooks>(hookName: K, ...args: Parameters<NonNullable<PluginHooks[K]>>): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Execute beforeConnect hooks
|
|
48
|
+
*/
|
|
49
|
+
beforeConnect(deviceId: string): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute afterConnect hooks
|
|
52
|
+
*/
|
|
53
|
+
afterConnect(deviceId: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Execute beforeDisconnect hooks
|
|
56
|
+
*/
|
|
57
|
+
beforeDisconnect(deviceId: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Execute afterDisconnect hooks
|
|
60
|
+
*/
|
|
61
|
+
afterDisconnect(deviceId: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Execute beforePrint hooks
|
|
64
|
+
*/
|
|
65
|
+
beforePrint(buffer: Uint8Array): Promise<Uint8Array>;
|
|
66
|
+
/**
|
|
67
|
+
* Execute afterPrint hooks
|
|
68
|
+
*/
|
|
69
|
+
afterPrint(bytesSent: number): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Execute onError hooks
|
|
72
|
+
* @returns True if error should be suppressed
|
|
73
|
+
*/
|
|
74
|
+
onError(error: BluetoothPrintError): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Execute onStateChange hooks
|
|
77
|
+
*/
|
|
78
|
+
onStateChange(state: PrinterState, previousState: PrinterState): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Execute onProgress hooks
|
|
81
|
+
*/
|
|
82
|
+
onProgress(sent: number, total: number): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Clear all plugins
|
|
85
|
+
*/
|
|
86
|
+
clear(): Promise<void>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PluginFactory, PluginOptions } from '../types';
|
|
2
|
+
import { LogLevel } from '../../utils/logger';
|
|
3
|
+
export interface LoggingPluginOptions extends PluginOptions {
|
|
4
|
+
/** Log level (default: DEBUG) */
|
|
5
|
+
level?: LogLevel;
|
|
6
|
+
/** Include timestamps (default: true) */
|
|
7
|
+
timestamps?: boolean;
|
|
8
|
+
/** Log progress updates (default: false, can be noisy) */
|
|
9
|
+
logProgress?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a logging plugin instance
|
|
13
|
+
*/
|
|
14
|
+
export declare const createLoggingPlugin: PluginFactory;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PluginFactory, PluginOptions } from '../types';
|
|
2
|
+
import { ErrorCode } from '../../errors/BluetoothError';
|
|
3
|
+
export interface RetryPluginOptions extends PluginOptions {
|
|
4
|
+
/** Maximum retry attempts (default: 3) */
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
/** Initial delay in ms (default: 1000) */
|
|
7
|
+
initialDelay?: number;
|
|
8
|
+
/** Maximum delay in ms (default: 10000) */
|
|
9
|
+
maxDelay?: number;
|
|
10
|
+
/** Backoff multiplier (default: 2) */
|
|
11
|
+
backoffMultiplier?: number;
|
|
12
|
+
/** Error codes that should trigger retry */
|
|
13
|
+
retryableErrors?: ErrorCode[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a retry plugin instance
|
|
17
|
+
*/
|
|
18
|
+
export declare const createRetryPlugin: PluginFactory;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin System Exports
|
|
3
|
+
*/
|
|
4
|
+
export { PluginManager } from './PluginManager';
|
|
5
|
+
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './types';
|
|
6
|
+
export { createLoggingPlugin } from './builtin/LoggingPlugin';
|
|
7
|
+
export { createRetryPlugin } from './builtin/RetryPlugin';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { BluetoothPrintError } from '../errors/BluetoothError';
|
|
2
|
+
import { PrinterState } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin lifecycle hooks
|
|
5
|
+
*/
|
|
6
|
+
export interface PluginHooks {
|
|
7
|
+
/**
|
|
8
|
+
* Called before connecting to a device
|
|
9
|
+
* @param deviceId - Target device ID
|
|
10
|
+
* @returns Modified device ID or void
|
|
11
|
+
*/
|
|
12
|
+
beforeConnect?: (deviceId: string) => string | void | Promise<string | void>;
|
|
13
|
+
/**
|
|
14
|
+
* Called after successful connection
|
|
15
|
+
* @param deviceId - Connected device ID
|
|
16
|
+
*/
|
|
17
|
+
afterConnect?: (deviceId: string) => void | Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Called before disconnecting
|
|
20
|
+
* @param deviceId - Device ID to disconnect
|
|
21
|
+
*/
|
|
22
|
+
beforeDisconnect?: (deviceId: string) => void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Called after disconnection
|
|
25
|
+
* @param deviceId - Disconnected device ID
|
|
26
|
+
*/
|
|
27
|
+
afterDisconnect?: (deviceId: string) => void | Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Called before sending print data
|
|
30
|
+
* @param buffer - Data buffer to send
|
|
31
|
+
* @returns Modified buffer or void
|
|
32
|
+
*/
|
|
33
|
+
beforePrint?: (buffer: Uint8Array) => Uint8Array | void | Promise<Uint8Array | void>;
|
|
34
|
+
/**
|
|
35
|
+
* Called after print job completes
|
|
36
|
+
* @param bytesSent - Total bytes sent
|
|
37
|
+
*/
|
|
38
|
+
afterPrint?: (bytesSent: number) => void | Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Called when an error occurs
|
|
41
|
+
* @param error - The error that occurred
|
|
42
|
+
* @returns Whether to suppress the error (true = suppress)
|
|
43
|
+
*/
|
|
44
|
+
onError?: (error: BluetoothPrintError) => boolean | void | Promise<boolean | void>;
|
|
45
|
+
/**
|
|
46
|
+
* Called when printer state changes
|
|
47
|
+
* @param state - New printer state
|
|
48
|
+
* @param previousState - Previous state
|
|
49
|
+
*/
|
|
50
|
+
onStateChange?: (state: PrinterState, previousState: PrinterState) => void | Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Called during print progress
|
|
53
|
+
* @param sent - Bytes sent
|
|
54
|
+
* @param total - Total bytes
|
|
55
|
+
*/
|
|
56
|
+
onProgress?: (sent: number, total: number) => void | Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Plugin configuration options
|
|
60
|
+
*/
|
|
61
|
+
export interface PluginOptions {
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Plugin interface
|
|
66
|
+
*/
|
|
67
|
+
export interface Plugin {
|
|
68
|
+
/**
|
|
69
|
+
* Unique plugin name
|
|
70
|
+
*/
|
|
71
|
+
name: string;
|
|
72
|
+
/**
|
|
73
|
+
* Plugin version
|
|
74
|
+
*/
|
|
75
|
+
version?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Plugin description
|
|
78
|
+
*/
|
|
79
|
+
description?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Plugin hooks
|
|
82
|
+
*/
|
|
83
|
+
hooks: PluginHooks;
|
|
84
|
+
/**
|
|
85
|
+
* Plugin initialization
|
|
86
|
+
* @param options - Plugin options
|
|
87
|
+
*/
|
|
88
|
+
init?: (options?: PluginOptions) => void | Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Plugin cleanup
|
|
91
|
+
*/
|
|
92
|
+
destroy?: () => void | Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Plugin factory function type
|
|
96
|
+
*/
|
|
97
|
+
export type PluginFactory = (options?: PluginOptions) => Plugin;
|
|
@@ -2,7 +2,6 @@ import { IPrinterAdapter, PrinterState } from '../types';
|
|
|
2
2
|
import { IConnectionManager } from './interfaces';
|
|
3
3
|
import { BluetoothPrintError } from '../errors/BluetoothError';
|
|
4
4
|
import { EventEmitter } from '../core/EventEmitter';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Connection manager configuration
|
|
8
7
|
*/
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taro-bluetooth-print",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Taro 蓝牙打印库 v2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Taro 蓝牙打印库 v2.3 - 轻量级、高性能、跨平台支持微信、支付宝、百度、字节跳动小程序及H5 Web Bluetooth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
8
8
|
"types": "dist/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
11
12
|
"import": "./dist/index.es.js",
|
|
12
13
|
"require": "./dist/index.cjs.js",
|
|
13
|
-
"types": "./dist/types/index.d.ts",
|
|
14
14
|
"default": "./dist/index.umd.js"
|
|
15
15
|
},
|
|
16
16
|
"./package.json": "./package.json"
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\"",
|
|
35
35
|
"type-check": "tsc --noEmit",
|
|
36
36
|
"prepublishOnly": "npm run build",
|
|
37
|
-
"test": "
|
|
38
|
-
"test:watch": "
|
|
39
|
-
"test:coverage": "
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"test:coverage": "vitest run --coverage"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
42
|
"taro",
|
|
@@ -50,27 +50,25 @@
|
|
|
50
50
|
"author": "Agions",
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@tarojs/taro": "^
|
|
53
|
+
"@tarojs/taro": "^4.1.11"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/jest": "^29.5.11",
|
|
57
56
|
"@types/node": "^20.14.8",
|
|
58
57
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
59
58
|
"@typescript-eslint/parser": "^6.19.0",
|
|
59
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
60
60
|
"eslint": "^8.56.0",
|
|
61
61
|
"eslint-config-prettier": "^9.1.0",
|
|
62
62
|
"eslint-plugin-prettier": "^5.1.3",
|
|
63
63
|
"fast-check": "^4.5.3",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"rimraf": "^5.0.0",
|
|
68
|
-
"terser": "^5.24.0",
|
|
69
|
-
"ts-jest": "^29.1.1",
|
|
64
|
+
"prettier": "^3.8.1",
|
|
65
|
+
"rimraf": "^6.1.2",
|
|
66
|
+
"terser": "^5.46.0",
|
|
70
67
|
"typescript": "^5.9.3",
|
|
71
|
-
"vite": "^
|
|
72
|
-
"vite-plugin-dts": "^
|
|
73
|
-
"vitepress": "^1.0.0"
|
|
68
|
+
"vite": "^7.3.1",
|
|
69
|
+
"vite-plugin-dts": "^4.5.4",
|
|
70
|
+
"vitepress": "^1.0.0",
|
|
71
|
+
"vitest": "^4.0.18"
|
|
74
72
|
},
|
|
75
73
|
"sideEffects": false
|
|
76
74
|
}
|