taro-bluetooth-print 2.8.1 → 2.8.4

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 CHANGED
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.8.4] - 2026-04-05
9
+
10
+ ### 修复
11
+
12
+ - image.ts: 添加 TypeScript strict mode non-null assertions,解决 noUncheckedIndexedAccess 警告
13
+
14
+ ### 性能优化
15
+
16
+ - image.ts: 移除 TypedArray 访问上的冗余 `?? 0` / `?? 255` 操作符
17
+
18
+ ## [2.8.3] - 2026-04-04
19
+
20
+ ### 性能优化
21
+
22
+ - image.ts: 移除 TypedArray 访问上的冗余 `?? 0` / `?? 255` 操作符(Uint8Array/Float32Array 元素访问永不返回 undefined)
23
+ - 影响函数:toGrayscale、adjustContrastBrightness、所有 dithering 算法、applyBilinearInterpolation、applyGammaCorrection、applyMedianFilter、applyConvolution、applyPixelate
24
+ - gzip 体积:225.96 KB → 225.79 KB(-0.17 KB),代码净减 1 行
25
+
8
26
  ## [2.8.1] - 2026-04-02
9
27
 
10
28
  ### 修复
package/README.md CHANGED
@@ -1,75 +1,53 @@
1
1
  # Taro Bluetooth Print
2
2
 
3
3
  <p align="center">
4
- <img src="https://img.shields.io/npm/v/taro-bluetooth-print?style=flat-square&color=00d8ff" alt="npm version">
5
- <img src="https://img.shields.io/npm/dm/taro-bluetooth-print?style=flat-square&color=00d8ff" alt="downloads">
6
- <img src="https://img.shields.io/npm/l/taro-bluetooth-print?style=flat-square&color=00d8ff" alt="license">
7
- <img src="https://img.shields.io/github/stars/agions/taro-bluetooth-print?style=flat-square" alt="stars">
8
- <img src="https://img.shields.io/github/forks/agions/taro-bluetooth-print?style=flat-square" alt="forks">
9
- <img src="https://img.shields.io/bundlephobia/minzip/taro-bluetooth-print?style=flat-square" alt="bundle size">
4
+ <a href="https://www.npmjs.com/package/taro-bluetooth-print" target="_blank"><img src="https://img.shields.io/npm/v/taro-bluetooth-print?style=flat-square&color=4338ca" alt="npm version"></a>
5
+ <a href="https://www.npmjs.com/package/taro-bluetooth-print" target="_blank"><img src="https://img.shields.io/npm/dm/taro-bluetooth-print?style=flat-square&color=4338ca" alt="downloads"></a>
6
+ <a href="https://github.com/agions/taro-bluetooth-print/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/npm/l/taro-bluetooth-print?style=flat-square&color=4338ca" alt="license"></a>
7
+ <a href="https://github.com/agions/taro-bluetooth-print" target="_blank"><img src="https://img.shields.io/github/stars/agions/taro-bluetooth-print?style=flat-square" alt="stars"></a>
8
+ <a href="https://github.com/agions/taro-bluetooth-print" target="_blank"><img src="https://img.shields.io/github/forks/agions/taro-bluetooth-print?style=flat-square" alt="forks"></a>
9
+ <a href="https://bundlephobia.com/package/taro-bluetooth-print" target="_blank"><img src="https://img.shields.io/bundlephobia/minzip/taro-bluetooth-print?style=flat-square" alt="bundle size"></a>
10
10
  </p>
11
11
 
12
12
  <p align="center">
13
- <strong>轻量级、高性能的 Taro 蓝牙打印库</strong><br>
14
- 支持热敏票据打印机、标签打印机,覆盖 8+ 平台
13
+ 轻量级、高性能的 Taro 蓝牙打印库 · 支持热敏票据、标签打印,覆盖 8+ 平台
15
14
  </p>
16
15
 
17
16
  ---
18
17
 
19
- ## 特性
18
+ ## 特性亮点
20
19
 
21
- ### 核心能力
20
+ ### 基础能力
22
21
 
23
- | 特性 | 说明 |
22
+ | 能力 | 说明 |
24
23
  |------|------|
25
- | 高性能打印 | 直接操作字节缓冲区,服务端缓存优化 |
26
24
  | 多平台适配 | 微信/支付宝/百度/字节跳动/QQ 小程序,H5 WebBluetooth,鸿蒙,React Native |
27
25
  | 多协议驱动 | ESC/POS(热敏)、TSPL/ZPL/CPCL(标签)、STAR 系列 |
28
- | TypeScript | 完整类型定义,IDE 智能提示 |
26
+ | 链式调用 | `printer.text(...).feed().qr(...).cut().print()`,IDE 自动补全 |
27
+ | TypeScript | 完整类型定义,无任何 `any` 暴露,无外部依赖 |
28
+ | 编码支持 | GBK / GB2312 / Big5 / UTF-8 / EUC-KR / Shift-JIS / ISO-2022-JP |
29
29
 
30
30
  ### 高级打印
31
31
 
32
- | 特性 | 说明 |
32
+ | 能力 | 说明 |
33
33
  |------|------|
34
- | 图片打印 | Floyd-Steinberg 抖动算法,6 种抖动模式 |
35
- | 二维码/条码 | 原生指令支持,多种格式,格式校验 |
36
- | 暂停/恢复/取消 | 完整的打印任务控制 |
37
- | 离线缓存 | 断网自动缓存,来网自动同步 |
38
- | 打印队列 | 优先级排序,失败自动重试 |
39
- | 模板引擎 | 支持循环、条件、边框、表格等语法 |
40
- | 打印预览 | ESC/POS 命令渲染为图像预览 |
41
- | 插件系统 | 可扩展架构,支持自定义钩子 |
34
+ | 图片打印 | Floyd-Steinberg 抖动算法,6 种抖动模式,RGBA → 黑白位图 |
35
+ | 二维码/条码 | 原生指令支持 Code128/EAN/UPC/QR/PDF417 等 10+ 格式 |
36
+ | 模板引擎 | loop 循环 / condition 条件 / border 边框 / table 表格,小票标签一键渲染 |
37
+ | 暂停/恢复/取消 | 完整的打印任务生命周期控制 |
38
+ | 打印预览 | ESC/POS 命令实时渲染为 Canvas 图像,调试所见即所得 |
42
39
 
43
40
  ### 运维管理
44
41
 
45
- | 特性 | 说明 |
42
+ | 能力 | 说明 |
46
43
  |------|------|
47
- | 多打印机管理 | MultiPrinterManager 支持多设备并发 |
48
- | 打印历史 | PrintHistory 追踪打印记录和统计 |
49
- | 定时重试 | ScheduledRetryManager 指数退避,重启恢复 |
50
- | 状态检测 | PrinterStatus 检测纸张/电量状态 |
51
- | 批量优化 | BatchPrintManager 合并小任务减少开销 |
52
- | 定时调度 | PrintScheduler 支持 cron/一次性/重复间隔任务 |
53
- | 设备发现 | DiscoveryService 增强型过滤排序和设备缓存 |
54
-
55
- ### 编码支持
56
-
57
- GBK / GB2312 / Big5 / UTF-8 / EUC-KR(韩文)/ Shift-JIS / ISO-2022-JP(日文)
58
-
59
- ---
60
-
61
- ## 安装
62
-
63
- ```bash
64
- # npm
65
- npm install taro-bluetooth-print
66
-
67
- # yarn
68
- yarn add taro-bluetooth-print
69
-
70
- # pnpm
71
- pnpm add taro-bluetooth-print
72
- ```
44
+ | 离线缓存 | 断网自动缓存,来网自动同步,零任务丢失 |
45
+ | 打印队列 | 优先级排序,失败自动重试,死链自动剔除 |
46
+ | 多打印机管理 | MultiPrinterManager 多设备并发,支持负载均衡 |
47
+ | 打印历史 | PrintHistory 完整记录,含耗时/字节数/成功率统计 |
48
+ | 定时重试 | ScheduledRetryManager 指数退避,进程重启后自动恢复调度 |
49
+ | 定时调度 | PrintScheduler 支持 cron 表达式/一次性/间隔重复任务 |
50
+ | 设备发现 | DiscoveryService 增强型过滤、排序、RSSI 缓存 |
73
51
 
74
52
  ---
75
53
 
@@ -77,14 +55,19 @@ pnpm add taro-bluetooth-print
77
55
 
78
56
  | 指标 | 值 |
79
57
  |------|-----|
80
- | 包体积 | **26 KB**(gzip) |
81
- | Tree-shaking | 支持 |
82
- | 按需加载 | 编码表懒加载 |
58
+ | 包体积(gzip) | **~226 KB**(含全部驱动,无外部依赖) |
59
+ | Tree-shaking | 支持,import { BluetoothPrinter } 即用 |
60
+ | 按需加载 | 编码表懒加载,未用到的字符集不进入产物 |
61
+ | 测试覆盖 | ✅ 648 个用例,CI 全链路通过 |
83
62
 
84
63
  ---
85
64
 
86
65
  ## 快速开始
87
66
 
67
+ ```bash
68
+ pnpm add taro-bluetooth-print
69
+ ```
70
+
88
71
  ```typescript
89
72
  import { BluetoothPrinter, DeviceManager } from 'taro-bluetooth-print';
90
73
 
@@ -103,7 +86,7 @@ async function print() {
103
86
  const printer = new BluetoothPrinter();
104
87
  await printer.connect(devices[0].deviceId);
105
88
 
106
- // 3. 打印
89
+ // 3. 链式调用打印
107
90
  await printer
108
91
  .text('=== 欢迎光临 ===', 'GBK')
109
92
  .feed()
@@ -113,57 +96,57 @@ async function print() {
113
96
  .text('------------------------')
114
97
  .text('合计: ¥30.00', 'GBK')
115
98
  .feed(2)
116
- .qr('https://example.com')
99
+ .qr('https://example.com', { size: 6 })
117
100
  .feed(2)
118
101
  .cut()
119
102
  .print();
120
103
 
121
- // 4. 断开
122
104
  await printer.disconnect();
123
-
124
- console.log('打印完成!');
125
105
  }
126
106
  ```
127
107
 
128
108
  ---
129
109
 
130
- ## 支持的平台
110
+ ## 平台与驱动
111
+
112
+ ### 支持的平台
131
113
 
132
114
  | 平台 | 适配器 | 状态 |
133
115
  |------|--------|------|
134
- | 微信小程序 | `TaroAdapter` | [x] |
135
- | H5 (Web Bluetooth) | `WebBluetoothAdapter` | [x] |
136
- | 支付宝小程序 | `AlipayAdapter` | [x] |
137
- | 百度小程序 | `BaiduAdapter` | [x] |
138
- | 字节跳动小程序 | `ByteDanceAdapter` | [x] |
139
- | QQ 小程序 | `QQAdapter` | [x] |
140
- | 鸿蒙 HarmonyOS | `HarmonyOSAdapter` | [x] |
141
- | React Native | `ReactNativeAdapter` | [x] |
142
-
143
- ---
144
-
145
- ## 支持的驱动
146
-
147
- | 驱动 | 协议 | 适用打印机 |
148
- |------|------|-----------|
149
- | `EscPos` | ESC/POS | 热敏票据打印机(58/80mm) |
150
- | `TsplDriver` | TSPL | TSC 标签打印机 |
151
- | `ZplDriver` | ZPL | Zebra 斑马标签打印机 |
152
- | `CpclDriver` | CPCL | HP/霍尼韦尔移动打印机 |
153
- | `StarPrinter` | STAR | STAR TSP/SP700 系列票据打印机 |
116
+ | 微信小程序 | `TaroAdapter` | |
117
+ | H5 (Web Bluetooth) | `WebBluetoothAdapter` | |
118
+ | 支付宝小程序 | `AlipayAdapter` | |
119
+ | 百度小程序 | `BaiduAdapter` | |
120
+ | 字节跳动小程序 | `ByteDanceAdapter` | |
121
+ | QQ 小程序 | `QQAdapter` | |
122
+ | 鸿蒙 HarmonyOS | `TaroAdapter` | |
123
+ | React Native | `ReactNativeAdapter` | |
124
+
125
+ ### 支持的驱动
126
+
127
+ | 驱动 | 协议 | 典型品牌 |
128
+ |------|------|---------|
129
+ | `EscPos` | ESC/POS | 佳博、芯烨、商米、汉印 |
130
+ | `TsplDriver` | TSPL | TSC ME240、TA210、TTP-244 |
131
+ | `ZplDriver` | ZPL | Zebra ZD420、GT800、ZM400 |
132
+ | `CpclDriver` | CPCL | HP IR3222、霍尼韦尔移动机 |
133
+ | `StarPrinter` | STAR | STAR TSP100、TSP700、TSP800 |
134
+ | `GPrinterDriver` | 自定义 | 佳博 GP-5890X 系列 |
135
+ | `XprinterDriver` | ESC/POS | 芯烨 XP-58 系列 |
136
+ | `SprtDriver` | ESC/POS | 思普瑞特系列 |
154
137
 
155
138
  ---
156
139
 
157
- ## 配置
140
+ ## 配置与事件
158
141
 
159
142
  ```typescript
160
143
  const printer = new BluetoothPrinter();
161
144
 
162
- // 适配器参数
145
+ // 传输参数
163
146
  printer.setOptions({
164
- chunkSize: 20, // 分片大小(默认 20)
147
+ chunkSize: 20, // 分片大小 byte(默认 20)
165
148
  delay: 20, // 分片间隔 ms(默认 20)
166
- retries: 3, // 重试次数(默认 3)
149
+ retries: 3, // 写入失败重试次数(默认 3)
167
150
  });
168
151
 
169
152
  // 事件监听
@@ -185,80 +168,68 @@ printer.on('print-complete', () => {
185
168
  ## 架构
186
169
 
187
170
  ```
188
- +----------------------+
189
- | BluetoothPrinter |
190
- | (Core) |
191
- +----------+-----------+
192
- |
193
- +-----+-----+
194
- | |
195
- +----v---+ +---v----+
196
- | Driver | | Adapter |
197
- | Layer | | Layer |
198
- +---+----+ +----+----+
199
- | |
200
- +------+------+
201
- |
202
- +-----v-----+
203
- | Services |
204
- | (PrintJob, |
205
- | Cache, |
206
- | Queue...) |
207
- +-----------+
171
+ ┌─────────────────────────────────────────┐
172
+ BluetoothPrinter (Core) │
173
+ text() feed() qr() cut() image() print()│
174
+ └──────────────┬──────────────────────────┘
175
+
176
+ ┌─────────┼─────────┐
177
+ ▼ ▼
178
+ ┌─────────┐ ┌──────────┐
179
+ Drivers │ │ Adapters
180
+ EscPos │ │ TaroAdapter│
181
+ │ Tspl │ │ WebBluetooth│
182
+ │ Zpl │ │ ReactNative │
183
+ └────┬────┘ └─────┬────┘
184
+ └──────────┬──────────┘
185
+
186
+ ┌──────────────────────────────────────┐
187
+ │ Services │
188
+ │ PrintJob · Cache · Queue · History │
189
+ Statistics · Scheduler · Batch │
190
+ └──────────────────────────────────────┘
208
191
  ```
209
192
 
210
193
  ---
211
194
 
212
195
  ## 示例项目
213
196
 
214
- - [微信小程序示例](https://github.com/Agions/taro-bluetooth-print/tree/main/examples/weapp)
215
- - [H5 示例](https://github.com/Agions/taro-bluetooth-print/tree/main/examples/h5)
216
- - [鸿蒙示例](https://github.com/Agions/taro-bluetooth-print/tree/main/examples/harmonyos)
217
- - [React Native 示例](https://github.com/Agions/taro-bluetooth-print/tree/main/examples/react-native)
197
+ | 示例 | 路径 |
198
+ |------|------|
199
+ | 微信小程序 | [examples/weapp](./examples/weapp) |
200
+ | H5 | [examples/h5](./examples/h5) |
201
+ | 鸿蒙 | [examples/harmonyos](./examples/harmonyos) |
202
+ | React Native | [examples/react-native](./examples/react-native) |
218
203
 
219
204
  ---
220
205
 
221
206
  ## 文档
222
207
 
223
- - [快速开始](https://agions.github.io/taro-bluetooth-print/guide/getting-started) - 5 分钟入门
224
- - [功能特性](https://agions.github.io/taro-bluetooth-print/guide/features) - 全部功能介绍
225
- - [驱动支持](https://agions.github.io/taro-bluetooth-print/guide/drivers) - ESC/POS、TSPL、ZPL、CPCL
226
- - [核心概念](https://agions.github.io/taro-bluetooth-print/guide/core-concepts) - 架构设计与原理
227
- - [API 参考](https://agions.github.io/taro-bluetooth-print/api) - 完整的 API 文档
228
- - [常见问题](https://agions.github.io/taro-bluetooth-print/guide/faq) - FAQ
208
+ - [快速开始](https://agions.github.io/taro-bluetooth-print/guide/getting-started) · 5 分钟入门
209
+ - [功能特性](https://agions.github.io/taro-bluetooth-print/guide/features) · 全部功能
210
+ - [驱动支持](https://agions.github.io/taro-bluetooth-print/guide/drivers) · ESC/POS、TSPL、ZPL
211
+ - [核心概念](https://agions.github.io/taro-bluetooth-print/guide/core-concepts) · 架构设计
212
+ - [API 参考](https://agions.github.io/taro-bluetooth-print/api) · 完整 API
213
+ - [常见问题](https://agions.github.io/taro-bluetooth-print/guide/faq) · FAQ
229
214
 
230
215
  ---
231
216
 
232
- ## 贡献
233
-
234
- 欢迎贡献代码!
217
+ ## 开发
235
218
 
236
219
  ```bash
237
- # 克隆仓库
238
220
  git clone https://github.com/Agions/taro-bluetooth-print.git
239
221
  cd taro-bluetooth-print
240
-
241
- # 安装依赖
242
222
  pnpm install
243
223
 
244
- # 运行测试
245
- pnpm test
246
-
247
- # 构建
248
- pnpm build
249
-
250
- # 本地文档
251
- pnpm docs:dev
224
+ pnpm test # 测试(648 用例)
225
+ pnpm lint # ESLint + Prettier
226
+ pnpm type-check # TypeScript 检查
227
+ pnpm build # 构建产物
228
+ pnpm docs:dev # 本地文档
252
229
  ```
253
230
 
254
231
  ---
255
232
 
256
233
  ## 许可证
257
234
 
258
- [MIT](./LICENSE) © Agions
259
-
260
- ---
261
-
262
- <p align="center">
263
- Made with ❤️ by <a href="https://github.com/agions">Agions</a>
264
- </p>
235
+ [MIT](./LICENSE) · Copyright © 2024-present Agions