taro-bluetooth-print 2.15.0 → 2.15.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.
- package/CHANGELOG.md +131 -38
- package/README.md +84 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,41 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [2.15.
|
|
3
|
+
## [2.15.1] - 2026-07-07
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Fixed
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- Full Mermaid architecture diagrams (6-layer system, connection sequence, print flow)
|
|
11
|
-
- **Online Documentation Link** — `homepage` and `documentation` fields added to `package.json`
|
|
12
|
-
- Live docs: https://agions.github.io/taro-bluetooth-print/
|
|
7
|
+
- **README logo 修复** — npm 注册表 README 中 logo 使用相对路径 `docs/public/logo.svg`,在 npmjs.com 上无法访问。已改为绝对 URL:`https://agions.github.io/taro-bluetooth-print/logo.svg`(GitHub Pages 托管,全球 CDN 可用)
|
|
8
|
+
- **examples 文档补全** — 为 `examples/weapp` / `examples/h5` / `examples/harmonyos` / `examples/react-native` 各添加专业 README.md,包含前置条件、快速开始、核心代码说明、平台差异、常见问题
|
|
9
|
+
- **examples/README.md 重写** — 新增平台对比表、4 大示例场景(小票 / 标签 / 队列 / 断点续传)带完整代码示例、平台功能矩阵、常见问题汇总
|
|
13
10
|
|
|
14
11
|
### Changed
|
|
15
12
|
|
|
16
|
-
- **README.md** —
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **docs/.vitepress/config.ts** — Updated SEO meta tags, OG image (`og-cover.svg`), brand theme color (`#6366f1`)
|
|
20
|
-
- **Brand Identity** — Unified design language: indigo → cyan gradient (`#4338ca` → `#6366f1` → `#0891b2`), rounded-receipt motif, Bluetooth waveform arcs, 7×7 QR matrix
|
|
21
|
-
|
|
22
|
-
### Assets
|
|
23
|
-
|
|
24
|
-
| File | Size | Purpose |
|
|
25
|
-
|:---|:---|:---|
|
|
26
|
-
| `docs/public/logo.svg` | 240×240 | Primary logo (gradient plate + receipt + BT arcs) |
|
|
27
|
-
| `docs/public/logo-mark.svg` | 64×64 | Compact icon-only variant |
|
|
28
|
-
| `docs/public/logo-dark.svg` | 240×240 | Dark background variant |
|
|
29
|
-
| `docs/public/wordmark.svg` | 560×96 | Horizontal logo with tagline |
|
|
30
|
-
| `docs/public/og-cover.svg` | 1200×630 | Social sharing card |
|
|
31
|
-
| `docs/public/hero-banner.svg` | 1600×400 | Docs landing page hero |
|
|
32
|
-
| `docs/public/favicon.svg` | 32×32 | Browser tab favicon (redesigned) |
|
|
33
|
-
|
|
34
|
-
### Documentation
|
|
35
|
-
|
|
36
|
-
- All SVG assets are inline-path (0 external dependencies)
|
|
37
|
-
- Docs build time: 19.3s, 0 errors
|
|
38
|
-
- Mermaid diagrams render correctly in VitePress
|
|
13
|
+
- **README.md** — 示例项目章节从简单表格升级为带场景代码块的专业文档(+119 行)
|
|
14
|
+
- **examples/README.md** — 从 159 行重写为 187 行专业文档,新增 4 个平台 README(各 ~120-180 行)
|
|
15
|
+
- **Brand Consistency** — 所有示例文档统一使用品牌渐变色(indigo → cyan)和文档结构模板
|
|
39
16
|
|
|
40
17
|
---
|
|
41
18
|
|
|
@@ -88,10 +65,126 @@
|
|
|
88
65
|
|
|
89
66
|
7 个 conventional commits 落地 (`be2fbdc..06f5ede`):
|
|
90
67
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
68
|
+
1. `refactor(core): simplify BluetoothPrinter & CommandBuilder`
|
|
69
|
+
2. `refactor(services): dedup ConnectionManager + PrintJobManager`
|
|
70
|
+
3. `refactor(adapters): deduplicate mini-program adapters and BaseAdapter imports`
|
|
71
|
+
4. `refactor: enforce PascalCase file naming for class-bearing modules`
|
|
72
|
+
5. `refactor: remove @ts-expect-error and dead code`
|
|
73
|
+
6. `refactor(errors): deduplicate error-code mapping tables`
|
|
74
|
+
7. `chore: update import paths after PascalCase file renames`
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## [2.13.0] - 2026-05-27
|
|
79
|
+
|
|
80
|
+
### Changed
|
|
81
|
+
|
|
82
|
+
- **架构精简**: 移除过度工程的 DI 容器系统(Container、Tokens、ServiceProvider、di-factory),约 1,048 行冗余代码
|
|
83
|
+
- **事件系统统一**: 移除冗余的 EventBus,统一使用类型安全的 EventEmitter
|
|
84
|
+
- **插件系统统一**: 移除冗余的 core/plugin PluginManager,保留 plugins/PluginManager
|
|
85
|
+
- **代码重复消除**: 重复率从 0.57% 降至 0%(8 个克隆 → 0 个)
|
|
86
|
+
- TemplateRenderer 提取 `buildTableSeparatorLine` 和 `renderFillLines` 辅助方法
|
|
87
|
+
- CpclDriver/ZplDriver 提取 `barcode-helpers.ts` mixin 模式
|
|
88
|
+
- BaseAdapter 统一重导出共享依赖,消除 ReactNativeAdapter 重复导入
|
|
89
|
+
- PreviewRenderer 合并 handleESC/handleGS 为 `handleControlSequence`
|
|
90
|
+
- gbk-lite.ts 数据去重(582 → 106 条目,减少 81.8%)
|
|
91
|
+
- **类型安全提升**: 类型断言从 124 处降至 73 处
|
|
92
|
+
- EventEmitter 内部存储改用映射类型,消除 10+ 类型断言
|
|
93
|
+
- 消除所有 `as` 类型转换中的不必要断言
|
|
94
|
+
- **错误处理改进**: 修复 6 处空 catch 块,所有异常均记录日志
|
|
95
|
+
- CloudPrintManager、QRCodeDiscoveryService、PrinterStatus、PrintScheduler
|
|
96
|
+
- **魔法数字提取**: 8 个硬编码数字提取为命名常量
|
|
97
|
+
- `DEFAULT_HEARTBEAT_INTERVAL`、`DEFAULT_RECONNECT_INTERVAL`、`DEFAULT_CONNECTION_TIMEOUT`
|
|
98
|
+
- `DEFAULT_RETRY_BASE_DELAY`、`DEFAULT_RETRY_MAX_DELAY`、`MAX_TIMEOUT_MS`
|
|
99
|
+
- **工厂模式简化**: 移除 `PrinterFactory` 对象包装,保留 `createBluetoothPrinter` 和 `createWebBluetoothPrinter` 函数
|
|
100
|
+
|
|
101
|
+
### Removed
|
|
102
|
+
|
|
103
|
+
- 删除 `src/core/di/` 目录(Container.ts、Tokens.ts、index.ts)
|
|
104
|
+
- 删除 `src/core/event/` 目录(EventBus.ts、index.ts)
|
|
105
|
+
- 删除 `src/core/plugin/` 目录(PluginManager.ts、index.ts)
|
|
106
|
+
- 删除 `src/providers/` 目录(ServiceProvider.ts、index.ts)
|
|
107
|
+
- 删除 `src/factory/di-factory.ts`
|
|
108
|
+
- 删除 5 个对应的测试文件
|
|
109
|
+
- 删除根目录多余报告文档(ARCHITECTURE_ANALYSIS.md、CODE_DUPLICATION_REPORT.md、RELEASE_v2.9.6.md)
|
|
110
|
+
|
|
111
|
+
### Added
|
|
112
|
+
|
|
113
|
+
- 新增 `src/drivers/barcode-helpers.ts` — 条码便捷方法 mixin
|
|
114
|
+
- BaseAdapter 新增共享依赖重导出
|
|
115
|
+
|
|
116
|
+
### Testing
|
|
117
|
+
|
|
118
|
+
- 1,102 tests passed, 38 skipped, 0 regressions
|
|
119
|
+
- type-check: 0 errors
|
|
120
|
+
- build: 通过
|
|
121
|
+
- 代码重复率: 0%(jscpd 检测)
|
|
122
|
+
|
|
123
|
+
### Performance
|
|
124
|
+
|
|
125
|
+
- 源代码: 25,828 行 → 24,687 行(-1,141 行,-4.4%)
|
|
126
|
+
- 源文件: 96 个 → 84 个(-12 个)
|
|
127
|
+
- 构建产物: 631 KB(gzip 231 KB)
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## [2.12.0] - 2026-05-25
|
|
132
|
+
|
|
133
|
+
### Changed
|
|
134
|
+
|
|
135
|
+
- **代码质量优化**: 全面消除 ESLint 错误和警告
|
|
136
|
+
- **测试覆盖率提升**: 从 64% 提升至 80.87%
|
|
137
|
+
- **Bug 修复**: sendAudioData 无限循环(catch 块缺少 break)
|
|
138
|
+
|
|
139
|
+
### Testing
|
|
140
|
+
|
|
141
|
+
- 434 tests passed
|
|
142
|
+
- coverage: 80.87%
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## [2.11.0] - 2026-05-04
|
|
147
|
+
|
|
148
|
+
### Changed
|
|
149
|
+
|
|
150
|
+
- **错误体系统一**: 将 14 处 `throw new Error()` 迁移为 `BluetoothPrintError` + `ErrorCode`,覆盖 ReactNativeAdapter、DeviceManager、PrinterConfigManager、PrinterFactory、PreviewRenderer、PrintQueue、CloudPrintManager、PrintJobManager、PrintScheduler、image.ts
|
|
151
|
+
- **DiscoveryService.ts**: 移除顶部 3 条 eslint-disable 规则,清理注释代码
|
|
152
|
+
- **TemplateRenderer.ts**: `itemData: any` → `Record<string, unknown>`,移除 3 处行内 eslint-disable
|
|
153
|
+
- **outputLimiter.ts**: batchProcess 错误处理规范化(instanceof Error 守卫 + message 输出)
|
|
154
|
+
- **魔数提取**: ChunkWriteStrategy 提取 7 个常量(CHUNK_SIZE_STEP、DELAY_BACKOFF_FACTOR 等),PrintHistory 提取 DEFAULT_MAX_ENTRIES,TemplateRenderer/TemplateEngine 提取 DEFAULT_PAPER_WIDTH
|
|
155
|
+
|
|
156
|
+
### Added
|
|
157
|
+
|
|
158
|
+
- 新增 ErrorCode: `QUEUE_FULL`、`QUEUE_JOB_NOT_FOUND`、`PREVIEW_FAILED`
|
|
159
|
+
|
|
160
|
+
### Testing
|
|
161
|
+
|
|
162
|
+
- 985 tests passed, 38 skipped, 0 regressions
|
|
163
|
+
- type-check: 0 errors
|
|
164
|
+
- lint: 0 errors
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
All notable changes to this project will be documented in this file.
|
|
169
|
+
|
|
170
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
171
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## [2.10.2] - 2026-05-02
|
|
176
|
+
|
|
177
|
+
### Fixed
|
|
178
|
+
|
|
179
|
+
- **代码质量优化 — 消除所有 ESLint 错误** (#37 → 0)
|
|
180
|
+
- 移除 3 个文件顶部 `eslint-disable`(共 18 条规则绕过)
|
|
181
|
+
- 修复所有非空断言 (`!`) — `Uint8Array[i]!`、`parts[x]!`、`job.nextRunTime!` 等
|
|
182
|
+
- 修复所有 `any` 类型绕过 — `as string` 改为 `typeof` 运行时检查
|
|
183
|
+
- JSON.parse 结果改用 `as Record<string, unknown>` + 类型守卫访问
|
|
184
|
+
- 异步方法 `void` → `await`,消除 `require-await` 错误
|
|
185
|
+
- `Record<string, any>` → `Record<string, unknown>`
|
|
186
|
+
- 消除 `no-base-to-string`:`String(value)` → `JSON.stringify(value)`
|
|
187
|
+
- 消除 `no-unused-vars`:废弃变量改为 `void timeout`
|
|
188
|
+
- **零 ESLint 警告/错误、零非空断言、零行内 eslint-disable 残留**
|
|
189
|
+
|
|
190
|
+
---
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<img src="
|
|
3
|
+
<img src="https://agions.github.io/taro-bluetooth-print/logo.svg" alt="taro-bluetooth-print" width="120" />
|
|
4
4
|
|
|
5
5
|
# taro-bluetooth-print
|
|
6
6
|
|
|
@@ -261,12 +261,89 @@ printer.use(createRetryPlugin({ maxRetries: 3, backoffMultiplier: 2 }));
|
|
|
261
261
|
|
|
262
262
|
## 🧪 示例项目
|
|
263
263
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
|
267
|
-
|
|
268
|
-
|
|
|
269
|
-
|
|
|
264
|
+
完整的跨平台打印示例,覆盖微信小程序 / H5 / 鸿蒙 HarmonyOS / React Native 四大平台。
|
|
265
|
+
|
|
266
|
+
| 平台 | 适配器 | 示例文件 | 文档 |
|
|
267
|
+
|:---|:---|:---|:---|
|
|
268
|
+
| 微信小程序 | `TaroAdapter` | [`printer-page.tsx`](./examples/weapp/printer-page.tsx) | [README](./examples/weapp/README.md) |
|
|
269
|
+
| H5 | `WebBluetoothAdapter` | [`index.html`](./examples/h5/index.html) | [README](./examples/h5/README.md) |
|
|
270
|
+
| 鸿蒙 HarmonyOS | `HarmonyAdapter` | [`harmony-print-service.ts`](./examples/harmonyos/harmony-print-service.ts) | [README](./examples/harmonyos/README.md) |
|
|
271
|
+
| React Native | `ReactNativeAdapter` | [`PrinterScreen.tsx`](./examples/react-native/PrinterScreen.tsx) | [README](./examples/react-native/README.md) |
|
|
272
|
+
|
|
273
|
+
### 🎯 示例场景
|
|
274
|
+
|
|
275
|
+
#### 🧾 打印小票(ESC/POS)
|
|
276
|
+
|
|
277
|
+
适用于佳博 / 芯烨 / 商米 / 汉印 / 思普瑞特等热敏打印机。
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
await printer
|
|
281
|
+
.text('=== 欢迎光临 ===', { align: 'center', bold: true })
|
|
282
|
+
.feed()
|
|
283
|
+
.text('商品A x1 ¥10.00')
|
|
284
|
+
.text('商品B x2 ¥20.00')
|
|
285
|
+
.feed()
|
|
286
|
+
.text('------------------------')
|
|
287
|
+
.text('合计: ¥30.00', { bold: true })
|
|
288
|
+
.feed(2)
|
|
289
|
+
.qr('https://example.com', { size: 6 })
|
|
290
|
+
.feed(2)
|
|
291
|
+
.cut()
|
|
292
|
+
.print();
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**适用平台:** 全部 4 个平台
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
#### 🏷️ 打印标签(TSPL / ZPL / CPCL)
|
|
300
|
+
|
|
301
|
+
适用于 TSC / Zebra / HP / 霍尼韦尔等标签打印机。
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
const driver = new TsplDriver();
|
|
305
|
+
driver
|
|
306
|
+
.size(60, 40) // 60x40mm 标签
|
|
307
|
+
.gap(3) // 3mm 间隙
|
|
308
|
+
.clear()
|
|
309
|
+
.text('商品名称', { x: 20, y: 20, font: 3 })
|
|
310
|
+
.text('¥99.00', { x: 20, y: 60, font: 4 })
|
|
311
|
+
.barcode('6901234567890', { x: 20, y: 100, type: 'EAN13' })
|
|
312
|
+
.qrcode('https://example.com', { x: 250, y: 20 })
|
|
313
|
+
.print(1);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
**适用平台:** 全部 4 个平台(需打印机支持对应协议)
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
#### 📋 打印队列(批量任务)
|
|
321
|
+
|
|
322
|
+
适用于批量打印、订单打印等场景。
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
const queue = new PrintQueue({ maxSize: 100 });
|
|
326
|
+
queue.add(printData1, { priority: 'HIGH' });
|
|
327
|
+
queue.add(printData2, { priority: 'NORMAL' });
|
|
328
|
+
queue.on('job-completed', (job) => console.log('任务完成:', job.id));
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**适用平台:** 全部 4 个平台
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
#### 🔄 断点续传(大文件打印)
|
|
336
|
+
|
|
337
|
+
适用于打印大量内容(如 100 条订单)的场景。
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
const printPromise = printer.print();
|
|
341
|
+
setTimeout(() => printer.pause(), 5000);
|
|
342
|
+
setTimeout(async () => await printer.resume(), 10000);
|
|
343
|
+
await printPromise;
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**适用平台:** 全部 4 个平台
|
|
270
347
|
|
|
271
348
|
---
|
|
272
349
|
|