taro-bluetooth-print 2.2.1 → 2.3.1

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 (56) hide show
  1. package/CHANGELOG.md +57 -165
  2. package/README.md +142 -285
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.es.js +1 -81644
  5. package/dist/index.umd.js +1 -1
  6. package/dist/types/adapters/AdapterFactory.d.ts +0 -1
  7. package/dist/types/adapters/AlipayAdapter.d.ts +0 -1
  8. package/dist/types/adapters/BaiduAdapter.d.ts +0 -1
  9. package/dist/types/adapters/BaseAdapter.d.ts +0 -1
  10. package/dist/types/adapters/ByteDanceAdapter.d.ts +0 -1
  11. package/dist/types/adapters/TaroAdapter.d.ts +0 -1
  12. package/dist/types/adapters/WebBluetoothAdapter.d.ts +0 -1
  13. package/dist/types/config/PrinterConfig.d.ts +0 -1
  14. package/dist/types/core/BluetoothPrinter.d.ts +1 -2
  15. package/dist/types/core/EventEmitter.d.ts +6 -26
  16. package/dist/types/core/index.d.ts +6 -0
  17. package/dist/types/drivers/CpclDriver.d.ts +304 -0
  18. package/dist/types/drivers/EscPos.d.ts +0 -1
  19. package/dist/types/drivers/GPrinterDriver.d.ts +63 -0
  20. package/dist/types/drivers/TsplDriver.d.ts +251 -0
  21. package/dist/types/drivers/ZplDriver.d.ts +325 -0
  22. package/dist/types/drivers/index.d.ts +9 -0
  23. package/dist/types/encoding/gbk-lite.d.ts +8 -0
  24. package/dist/types/encoding/gbk-table.d.ts +8 -30
  25. package/dist/types/index.d.ts +10 -5
  26. package/dist/types/plugins/PluginManager.d.ts +87 -0
  27. package/dist/types/plugins/builtin/LoggingPlugin.d.ts +14 -0
  28. package/dist/types/plugins/builtin/RetryPlugin.d.ts +18 -0
  29. package/dist/types/plugins/index.d.ts +7 -0
  30. package/dist/types/plugins/types.d.ts +97 -0
  31. package/dist/types/services/CommandBuilder.d.ts +0 -1
  32. package/dist/types/services/ConnectionManager.d.ts +1 -2
  33. package/dist/types/services/PrintJobManager.d.ts +0 -1
  34. package/dist/types/services/index.d.ts +8 -0
  35. package/dist/types/services/interfaces/index.d.ts +0 -1
  36. package/dist/types/template/TemplateEngine.d.ts +0 -1
  37. package/package.json +36 -20
  38. package/src/adapters/BaseAdapter.ts +6 -8
  39. package/src/core/BluetoothPrinter.ts +15 -15
  40. package/src/core/EventEmitter.ts +15 -15
  41. package/src/core/index.ts +7 -0
  42. package/src/drivers/CpclDriver.ts +549 -0
  43. package/src/drivers/GPrinterDriver.ts +115 -0
  44. package/src/drivers/TsplDriver.ts +405 -0
  45. package/src/drivers/ZplDriver.ts +543 -0
  46. package/src/drivers/index.ts +37 -0
  47. package/src/encoding/gbk-lite.ts +108 -0
  48. package/src/encoding/gbk-table.ts +80 -58
  49. package/src/index.ts +27 -23
  50. package/src/plugins/PluginManager.ts +195 -0
  51. package/src/plugins/builtin/LoggingPlugin.ts +99 -0
  52. package/src/plugins/builtin/RetryPlugin.ts +103 -0
  53. package/src/plugins/index.ts +10 -0
  54. package/src/plugins/types.ts +119 -0
  55. package/src/services/ConnectionManager.ts +22 -22
  56. package/src/services/index.ts +16 -0
@@ -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,325 @@
1
+ /**
2
+ * ZPL Driver
3
+ * Zebra Printer Language driver for Zebra label printers
4
+ *
5
+ * ZPL is the industry standard for industrial label printing
6
+ */
7
+ /**
8
+ * ZPL Label size configuration
9
+ */
10
+ export interface ZplLabelSize {
11
+ /** Label width in dots */
12
+ width: number;
13
+ /** Label height in dots */
14
+ height: number;
15
+ /** Label gap in dots (default: 0) */
16
+ gap?: number;
17
+ }
18
+ /**
19
+ * Text format options
20
+ */
21
+ export interface ZplTextOptions {
22
+ /** X position in dots */
23
+ x: number;
24
+ /** Y position in dots */
25
+ y: number;
26
+ /** Font name (default: 0 for built-in) */
27
+ font?: string;
28
+ /** Font rotation: N=0, R=90, I=270, B=180 (default: N) */
29
+ rotation?: 'N' | 'R' | 'I' | 'B';
30
+ /** Horizontal magnification (1-10, default: 1) */
31
+ xMultiplier?: number;
32
+ /** Vertical magnification (1-10, default: 1) */
33
+ yMultiplier?: number;
34
+ /** Field orientation: N=normal, R=rotated, I=inverted, B=bottom-up */
35
+ orientation?: 'N' | 'R' | 'I' | 'B';
36
+ }
37
+ /**
38
+ * Barcode options
39
+ */
40
+ export interface ZplBarcodeOptions {
41
+ /** X position in dots */
42
+ x: number;
43
+ /** Y position in dots */
44
+ y: number;
45
+ /** Barcode type: 128, 39, 93, EAN13, EAN8, UPCE, CODE51, etc. */
46
+ type: '128' | '39' | '93' | 'EAN13' | 'EAN8' | 'UPCA' | 'UPCE' | 'CODE51' | 'MSI' | 'PLESSEY';
47
+ /** Barcode height in dots (default: 50) */
48
+ height?: number;
49
+ /** Show human-readable text (default: Y) */
50
+ showText?: 'Y' | 'N';
51
+ /** Check digit: Y=validate, N=no check (default: Y) */
52
+ checkDigit?: 'Y' | 'N';
53
+ /** Interpretation line: Y=print, N=omit (default: Y) */
54
+ interpretLine?: 'Y' | 'N';
55
+ /** Interpretation line above: Y=above, N=below (default: N) */
56
+ interpretLineAbove?: 'Y' | 'N';
57
+ }
58
+ /**
59
+ * QR Code options
60
+ */
61
+ export interface ZplQRCodeOptions {
62
+ /** X position in dots */
63
+ x: number;
64
+ /** Y position in dots */
65
+ y: number;
66
+ /** Model: 2 (default) or 1 */
67
+ model?: 1 | 2;
68
+ /** Magnification factor 1-10 (default: 4) */
69
+ magnification?: number;
70
+ /** Error correction level: L(~7%), M(~15%), Q(~25%), H(~30%) */
71
+ errorCorrection?: 'L' | 'M' | 'Q' | 'H';
72
+ }
73
+ /**
74
+ * Box/Rectangle options
75
+ */
76
+ export interface ZplBoxOptions {
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
+ /** Border thickness (default: 2) */
86
+ borderThickness?: number;
87
+ /** Corner rounding (0-10, default: 0) */
88
+ cornerRounding?: number;
89
+ }
90
+ /**
91
+ * ZPL Driver for Zebra label printers
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const zpl = new ZplDriver();
96
+ *
97
+ * const commands = zpl
98
+ * .startFormat()
99
+ * .labelHome(10, 10)
100
+ * .text('Product Name', { x: 50, y: 50 })
101
+ * .barcode('1234567890', { x: 50, y: 150, type: '128' })
102
+ * .qrcode('https://example.com', { x: 300, y: 50 })
103
+ * .print()
104
+ * .getCommands();
105
+ * ```
106
+ */
107
+ export declare class ZplDriver {
108
+ private commands;
109
+ private readonly logger;
110
+ /**
111
+ * Initialize ZPL driver with default settings
112
+ */
113
+ constructor();
114
+ /**
115
+ * Start label format (^XA)
116
+ */
117
+ startFormat(): this;
118
+ /**
119
+ * End label format (^XZ)
120
+ */
121
+ endFormat(): this;
122
+ /**
123
+ * Set label home position
124
+ * @param x - X position in dots
125
+ * @param y - Y position in dots
126
+ */
127
+ labelHome(x: number, y: number): this;
128
+ /**
129
+ * Set field data (^FD)
130
+ * @param content - Field content
131
+ */
132
+ fieldData(content: string): this;
133
+ /**
134
+ * Set field origin
135
+ * @param x - X position in dots
136
+ * @param y - Y position in dots
137
+ */
138
+ fieldOrigin(x: number, y: number): this;
139
+ /**
140
+ * Set print width
141
+ * @param width - Width in dots
142
+ */
143
+ printWidth(width: number): this;
144
+ /**
145
+ * Set label length
146
+ * @param length - Length in dots
147
+ */
148
+ labelLength(length: number): this;
149
+ /**
150
+ * Set label gap
151
+ * @param gap - Gap in dots
152
+ */
153
+ labelGap(gap: number): this;
154
+ /**
155
+ * Set print quantity
156
+ * @param quantity - Number of labels
157
+ */
158
+ quantity(quantity: number): this;
159
+ /**
160
+ * Add text to label
161
+ * @param content - Text content
162
+ * @param options - Text options
163
+ */
164
+ text(content: string, options?: ZplTextOptions): this;
165
+ /**
166
+ * Add text with explicit field origin
167
+ * @param content - Text content
168
+ * @param x - X position
169
+ * @param y - Y position
170
+ * @param font - Font name (default: 0)
171
+ * @param rotation - Rotation
172
+ */
173
+ textAt(content: string, x: number, y: number, font?: string, rotation?: 'N' | 'R' | 'I' | 'B'): this;
174
+ /**
175
+ * Use built-in font
176
+ * @param content - Text content
177
+ * @param x - X position
178
+ * @param y - Y position
179
+ * @param height - Character height (40-400)
180
+ * @param width - Character width (30-300)
181
+ */
182
+ font(content: string, x: number, y: number, height?: number, width?: number): this;
183
+ /**
184
+ * Add scalable font
185
+ * @param content - Text content
186
+ * @param x - X position
187
+ * @param y - Y position
188
+ * @param fontName - Font name (e.g., "0" for built-in, or loaded font name)
189
+ * @param fontHeight - Height multiplier
190
+ * @param fontWidth - Width multiplier
191
+ */
192
+ scalableText(content: string, x: number, y: number, fontName?: string, fontHeight?: number, fontWidth?: number): this;
193
+ /**
194
+ * Add barcode
195
+ * @param content - Barcode content
196
+ * @param options - Barcode options
197
+ */
198
+ barcode(content: string, options: ZplBarcodeOptions): this;
199
+ /**
200
+ * Add Code 128 barcode
201
+ * @param content - Barcode content
202
+ * @param x - X position
203
+ * @param y - Y position
204
+ * @param height - Barcode height
205
+ */
206
+ code128(content: string, x?: number, y?: number, height?: number): this;
207
+ /**
208
+ * Add Code 39 barcode
209
+ * @param content - Barcode content
210
+ * @param x - X position
211
+ * @param y - Y position
212
+ * @param height - Barcode height
213
+ */
214
+ code39(content: string, x?: number, y?: number, height?: number): this;
215
+ /**
216
+ * Add EAN-13 barcode
217
+ * @param content - Barcode content (12 or 13 digits)
218
+ * @param x - X position
219
+ * @param y - Y position
220
+ * @param height - Barcode height
221
+ */
222
+ ean13(content: string, x?: number, y?: number, height?: number): this;
223
+ /**
224
+ * Add QR code
225
+ * @param content - QR code content
226
+ * @param options - QR code options
227
+ */
228
+ qrcode(content: string, options?: ZplQRCodeOptions): this;
229
+ /**
230
+ * Add rectangle/border
231
+ * @param options - Box options
232
+ */
233
+ box(options: ZplBoxOptions): this;
234
+ /**
235
+ * Add line
236
+ * @param x1 - Start X
237
+ * @param y1 - Start Y
238
+ * @param x2 - End X
239
+ * @param y2 - End Y
240
+ * @param thickness - Line thickness
241
+ */
242
+ line(x1: number, y1: number, x2: number, y2: number, thickness?: number): this;
243
+ /**
244
+ * Add circle
245
+ * @param x - Center X
246
+ * @param y - Center Y
247
+ * @param diameter - Diameter in dots
248
+ * @param borderThickness - Border thickness
249
+ */
250
+ circle(x: number, y: number, diameter: number, borderThickness?: number): this;
251
+ /**
252
+ * Add diagonal line
253
+ * @param x - Start X
254
+ * @param y - Start Y
255
+ * @param width - Width
256
+ * @param height - Height
257
+ * @param thickness - Line thickness
258
+ */
259
+ diagonal(x: number, y: number, width: number, height: number, thickness?: number): this;
260
+ /**
261
+ * Add ellipse
262
+ * @param x - Center X
263
+ * @param y - Center Y
264
+ * @param width - Width
265
+ * @param height - Height
266
+ * @param borderThickness - Border thickness
267
+ */
268
+ ellipse(x: number, y: number, width: number, height: number, borderThickness?: number): this;
269
+ /**
270
+ * Add image from raw bitmap
271
+ * Note: For best results, use pre-processed images. This is a placeholder for future implementation.
272
+ * @param _x - X position (placeholder)
273
+ * @param _y - Y position (placeholder)
274
+ * @param _width - Image width (placeholder)
275
+ * @param _height - Image height (placeholder)
276
+ * @param _bitmap - Binary bitmap data (placeholder)
277
+ */
278
+ image(_x: number, _y: number, _width: number, _height: number, _bitmap: Uint8Array): this;
279
+ /**
280
+ * Set darkness/print density
281
+ * @param value - Darkness value (0-30, default: 15)
282
+ */
283
+ setDarkness(value?: number): this;
284
+ /**
285
+ * Set print speed
286
+ * @param speed - Speed: 1=slowest, 2-5=medium, 6-13=fast, 14=max
287
+ */
288
+ setSpeed(speed: number): this;
289
+ /**
290
+ * Print configuration label (useful for testing)
291
+ */
292
+ printConfigLabel(): this;
293
+ /**
294
+ * Calibrate sensors
295
+ */
296
+ calibrate(): this;
297
+ /**
298
+ * Reset printer
299
+ */
300
+ reset(): this;
301
+ /**
302
+ * Get all commands as string
303
+ */
304
+ getCommands(): string;
305
+ /**
306
+ * Get commands as buffer for sending to printer
307
+ */
308
+ getBuffer(): Uint8Array;
309
+ /**
310
+ * Get raw command list
311
+ */
312
+ getCommandList(): string[];
313
+ /**
314
+ * Clear all commands
315
+ */
316
+ resetCommands(): this;
317
+ /**
318
+ * Print label (end format)
319
+ */
320
+ print(quantity?: number): this;
321
+ /**
322
+ * Escape special characters in field data
323
+ */
324
+ private escapeField;
325
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Printer Drivers Module
3
+ * 打印机驱动模块 - 支持多种打印机协议
4
+ */
5
+ export { EscPos, type EscPosOptions } from './EscPos';
6
+ export { GPrinterDriver, type GPrinterOptions } from './GPrinterDriver';
7
+ export { TsplDriver, type LabelSize, type TextOptions, type BarcodeOptions, type QRCodeOptions, type BoxOptions, type LineOptions, } from './TsplDriver';
8
+ export { ZplDriver, type ZplLabelSize, type ZplTextOptions, type ZplBarcodeOptions, type ZplQRCodeOptions, type ZplBoxOptions, } from './ZplDriver';
9
+ export { CpclDriver, type CPCLPageSize, type CpclTextOptions, type CpclBarcodeOptions, type CpclQRCodeOptions, type CpclLineOptions, type CpclBoxOptions, } from './CpclDriver';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 精简版 GBK 编码数据
3
+ * 包含约 3500 个最常用汉字,覆盖 99% 日常使用场景
4
+ * 使用二分查找,内存占用极低
5
+ */
6
+ export declare const GBK_LITE: number[];
7
+ export declare function binarySearchGbk(unicode: number): number | null;
8
+ export declare function isInCommonRange(unicode: number): boolean;
@@ -1,53 +1,31 @@
1
1
  /**
2
- * GBK Encoding Table
2
+ * GBK Encoding Table - 懒加载版本
3
3
  *
4
- * This module provides character mapping tables for GBK, GB2312, and Big5 encodings.
5
- * GBK is a superset of GB2312 and covers most Chinese characters used in simplified Chinese.
6
- * Big5 is used for traditional Chinese characters.
4
+ * 优化策略:
5
+ * 1. 默认使用精简版编码表 (gbk-lite.ts,约 3500 常用字)
6
+ * 2. 遇到非常用字时动态加载完整编码表
7
+ * 3. 二分查找代替 Map,大幅减少内存占用
7
8
  *
8
- * GBK encoding uses double-byte encoding for Chinese characters:
9
- * - First byte: 0x81-0xFE
10
- * - Second byte: 0x40-0xFE (excluding 0x7F)
11
- *
12
- * 映射数据存储在 gbk-data.ts 中,运行时解码为 Map。
13
9
  * GBK: 23940 个字符映射
14
10
  * Big5: 13911 个字符映射
15
11
  */
16
- /**
17
- * Unicode to GBK mapping table
18
- * Maps Unicode code points to GBK byte pairs
19
- */
20
12
  export declare const unicodeToGbk: Map<number, number>;
21
- /**
22
- * GBK to Unicode mapping table
23
- * Maps GBK byte pairs to Unicode code points
24
- */
25
13
  export declare const gbkToUnicode: Map<number, number>;
26
- /**
27
- * Unicode to Big5 mapping table
28
- */
29
14
  export declare const unicodeToBig5: Map<number, number>;
30
- /**
31
- * Big5 to Unicode mapping table
32
- */
33
15
  export declare const big5ToUnicode: Map<number, number>;
34
16
  /**
35
17
  * Get GBK bytes for a Unicode character
36
- * @param unicode - Unicode code point
37
- * @returns GBK byte pair [high, low] or null if not found
18
+ * 先查精简表,查不到再懒加载完整表
38
19
  */
39
20
  export declare function getGbkBytes(unicode: number): [number, number] | null;
40
21
  /**
41
22
  * Get Unicode character from GBK bytes
42
- * @param high - High byte
43
- * @param low - Low byte
44
- * @returns Unicode code point or null if not found
23
+ * 懒加载完整表
45
24
  */
46
25
  export declare function getUnicodeFromGbk(high: number, low: number): number | null;
47
26
  /**
48
27
  * Get Big5 bytes for a Unicode character
49
- * @param unicode - Unicode code point
50
- * @returns Big5 byte pair or null if not found
28
+ * 懒加载完整表
51
29
  */
52
30
  export declare function getBig5Bytes(unicode: number): [number, number] | null;
53
31
  /**
@@ -1,20 +1,22 @@
1
1
  /**
2
2
  * Taro Bluetooth Print Library
3
- * A lightweight, high-performance Bluetooth printing library for Taro
3
+ * 轻量级、高性能的蓝牙打印库
4
4
  *
5
5
  * @packageDocumentation
6
6
  */
7
7
  export { BluetoothPrinter } from './core/BluetoothPrinter';
8
8
  export type { PrinterEvents } from './core/BluetoothPrinter';
9
9
  export { EventEmitter } from './core/EventEmitter';
10
- export { EscPos } from './drivers/EscPos';
10
+ export * from './drivers';
11
11
  export { TaroAdapter } from './adapters/TaroAdapter';
12
+ export { AlipayAdapter } from './adapters/AlipayAdapter';
13
+ export { BaiduAdapter } from './adapters/BaiduAdapter';
14
+ export { ByteDanceAdapter } from './adapters/ByteDanceAdapter';
15
+ export { WebBluetoothAdapter } from './adapters/WebBluetoothAdapter';
12
16
  export { AdapterFactory } from './adapters/AdapterFactory';
13
17
  export { BaseAdapter } from './adapters/BaseAdapter';
14
- export { WebBluetoothAdapter } from './adapters/WebBluetoothAdapter';
15
18
  export type { WebBluetoothRequestOptions } from './adapters/WebBluetoothAdapter';
16
- export { ConnectionManager } from './services/ConnectionManager';
17
- export type { ConnectionManagerConfig, ConnectionManagerEvents, } from './services/ConnectionManager';
19
+ export * from './services';
18
20
  export { DeviceManager } from './device/DeviceManager';
19
21
  export type { BluetoothDevice, ScanOptions, DeviceManagerEvents } from './device/DeviceManager';
20
22
  export { PrintQueue } from './queue/PrintQueue';
@@ -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';