taro-bluetooth-print 2.3.0 → 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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * GPrinter (佳博) Driver
3
+ *
4
+ * 佳博 (GPrinter) 热敏打印机兼容 ESC/POS 指令集
5
+ * 大部分命令与标准 ESC/POS 兼容,部分特殊命令需要额外处理
6
+ */
7
+
8
+ import { EscPos, type EscPosOptions } from './EscPos';
9
+
10
+ /**
11
+ * GPrinter Driver for GiaoBao (佳博) thermal printers
12
+ *
13
+ * 佳博打印机基于 ESC/POS 指令集,此驱动扩展了标准 EscPos
14
+ * 添加了佳博特定的命令支持
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { GPrinterDriver } from 'taro-bluetooth-print';
19
+ *
20
+ * const driver = new GPrinterDriver();
21
+ * let commands = driver.init();
22
+ * commands = driver.text('Hello 佳博!', 'GBK');
23
+ * commands = driver.cut();
24
+ * ```
25
+ */
26
+
27
+ /**
28
+ * GPrinter options (same as EscPosOptions)
29
+ */
30
+ export type GPrinterOptions = EscPosOptions;
31
+
32
+ export class GPrinterDriver extends EscPos {
33
+ /**
34
+ * 佳博打印机特定: 打开钱箱
35
+ * @param pin 钱箱引脚 (0 或 1, 默认 0)
36
+ */
37
+ openCashDrawer(pin = 0): Uint8Array[] {
38
+ // ESC p m t1 t2
39
+ // m = 0 or 1 (pin)
40
+ // t1 = 50 (on time)
41
+ // t2 = 200 (off time)
42
+ return [new Uint8Array([0x1b, 0x70, pin, 50, 200])];
43
+ }
44
+
45
+ /**
46
+ * 佳博打印机特定: 发送声响
47
+ * @param times 次数 (1-9)
48
+ * @param duration 持续时间
49
+ */
50
+ beep(times = 3, duration = 50): Uint8Array[] {
51
+ // ESC B n t
52
+ return [new Uint8Array([0x1b, 0x42, times, duration])];
53
+ }
54
+
55
+ /**
56
+ * 佳博打印机特定: 打印自检页
57
+ */
58
+ selfTest(): Uint8Array[] {
59
+ // ESC i
60
+ return [new Uint8Array([0x1b, 0x69])];
61
+ }
62
+
63
+ /**
64
+ * 佳博打印机特定: 获取状态
65
+ * 返回打印机状态字节
66
+ */
67
+ getStatus(): Uint8Array[] {
68
+ // DLE EOT n (n = 1-4 获取不同状态)
69
+ // 状态 1: 打印机状态
70
+ // 状态 2: 脱机状态
71
+ // 状态 3: 错误状态
72
+ // 状态 4: 纸张状态
73
+ const buffers: Uint8Array[] = [];
74
+ for (let i = 1; i <= 4; i++) {
75
+ buffers.push(new Uint8Array([0x10, 0x04, i]));
76
+ }
77
+ return buffers;
78
+ }
79
+
80
+ /**
81
+ * 佳博打印机特定: 设置字符代码页
82
+ * @param codePage 代码页编号
83
+ */
84
+ setCodePage(codePage: number): Uint8Array[] {
85
+ // ESC t n
86
+ return [new Uint8Array([0x1b, 0x74, codePage])];
87
+ }
88
+
89
+ /**
90
+ * 佳博打印机特定: 打印并走纸
91
+ * @param lines 走纸行数
92
+ */
93
+ printAndFeed(lines: number): Uint8Array[] {
94
+ // ESC d n
95
+ return [new Uint8Array([0x1b, 0x64, lines])];
96
+ }
97
+
98
+ /**
99
+ * 佳博打印机特定: 设置左边界
100
+ * @param n 左边界字符数
101
+ */
102
+ setLeftMargin(n: number): Uint8Array[] {
103
+ // ESC l n
104
+ return [new Uint8Array([0x1b, 0x6c, n])];
105
+ }
106
+
107
+ /**
108
+ * 佳博打印机特定: 设置打印区域宽度
109
+ * @param n 宽度 (字符数)
110
+ */
111
+ setPrintWidth(n: number): Uint8Array[] {
112
+ // ESC W n
113
+ return [new Uint8Array([0x1b, 0x57, n])];
114
+ }
115
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * TSPL Driver
3
3
  * TSC Printer Language driver for label/barcode printers
4
- *
4
+ *
5
5
  * TSPL is commonly used in thermal transfer label printers (TSC, Zebra, etc.)
6
6
  */
7
7
 
@@ -112,11 +112,11 @@ export interface LineOptions {
112
112
 
113
113
  /**
114
114
  * TSPL Driver for label printers
115
- *
115
+ *
116
116
  * @example
117
117
  * ```typescript
118
118
  * const tspl = new TsplDriver();
119
- *
119
+ *
120
120
  * const commands = tspl
121
121
  * .size(60, 40)
122
122
  * .gap(3)
@@ -216,14 +216,7 @@ export class TsplDriver {
216
216
  * @param options - Text options
217
217
  */
218
218
  text(content: string, options: TextOptions): this {
219
- const {
220
- x,
221
- y,
222
- font = 2,
223
- rotation = 0,
224
- xMultiplier = 1,
225
- yMultiplier = 1,
226
- } = options;
219
+ const { x, y, font = 2, rotation = 0, xMultiplier = 1, yMultiplier = 1 } = options;
227
220
 
228
221
  // TEXT x, y, "font", rotation, x-mul, y-mul, "content"
229
222
  this.commands.push(
@@ -269,14 +262,7 @@ export class TsplDriver {
269
262
  * @param options - QR code options
270
263
  */
271
264
  qrcode(content: string, options: QRCodeOptions): this {
272
- const {
273
- x,
274
- y,
275
- eccLevel = 'M',
276
- cellWidth = 6,
277
- mode = 'A',
278
- rotation = 0,
279
- } = options;
265
+ const { x, y, eccLevel = 'M', cellWidth = 6, mode = 'A', rotation = 0 } = options;
280
266
 
281
267
  // QRCODE x, y, ECC level, cell width, mode, rotation, "content"
282
268
  this.commands.push(
@@ -301,7 +287,7 @@ export class TsplDriver {
301
287
  */
302
288
  line(options: LineOptions): this {
303
289
  const { x1, y1, x2, y2, thickness = 2 } = options;
304
-
290
+
305
291
  if (x1 === x2 || y1 === y2) {
306
292
  // Horizontal or vertical line - use BAR command
307
293
  const width = Math.abs(x2 - x1) || thickness;
@@ -309,7 +295,9 @@ export class TsplDriver {
309
295
  this.commands.push(`BAR ${Math.min(x1, x2)},${Math.min(y1, y2)},${width},${height}`);
310
296
  } else {
311
297
  // Diagonal line - use DIAGONAL command if supported
312
- this.commands.push(`DIAGONAL ${x1},${y1},${thickness},${Math.sqrt((x2-x1)**2 + (y2-y1)**2)},${Math.atan2(y2-y1, x2-x1) * 180 / Math.PI}`);
298
+ this.commands.push(
299
+ `DIAGONAL ${x1},${y1},${thickness},${Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)},${(Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI}`
300
+ );
313
301
  }
314
302
  return this;
315
303
  }