taro-bluetooth-print 2.2.0 → 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 -22
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -6995
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/AdapterFactory.d.ts +0 -1
- package/dist/types/adapters/AlipayAdapter.d.ts +6 -34
- package/dist/types/adapters/BaiduAdapter.d.ts +6 -34
- package/dist/types/adapters/BaseAdapter.d.ts +112 -1
- package/dist/types/adapters/ByteDanceAdapter.d.ts +6 -34
- package/dist/types/adapters/TaroAdapter.d.ts +6 -34
- 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/encoding/gbk-data.d.ts +12 -0
- package/dist/types/encoding/gbk-table.d.ts +5 -1
- 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 +6 -1
- package/dist/types/services/ConnectionManager.d.ts +0 -1
- package/dist/types/services/PrintJobManager.d.ts +6 -2
- package/dist/types/services/interfaces/index.d.ts +0 -1
- package/dist/types/template/TemplateEngine.d.ts +0 -1
- package/package.json +16 -18
- package/src/adapters/AlipayAdapter.ts +8 -314
- package/src/adapters/BaiduAdapter.ts +8 -312
- package/src/adapters/BaseAdapter.ts +366 -0
- package/src/adapters/ByteDanceAdapter.ts +8 -316
- package/src/adapters/TaroAdapter.ts +8 -367
- package/src/core/EventEmitter.ts +9 -6
- package/src/drivers/TsplDriver.ts +417 -0
- package/src/encoding/gbk-data.ts +1911 -0
- package/src/encoding/gbk-table.ts +22 -498
- 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
- package/src/preview/PreviewRenderer.ts +7 -1
- package/src/queue/PrintQueue.ts +10 -6
- package/src/services/CommandBuilder.ts +30 -0
- package/src/services/PrintJobManager.ts +51 -35
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
* GBK encoding uses double-byte encoding for Chinese characters:
|
|
9
9
|
* - First byte: 0x81-0xFE
|
|
10
10
|
* - Second byte: 0x40-0xFE (excluding 0x7F)
|
|
11
|
+
*
|
|
12
|
+
* 映射数据存储在 gbk-data.ts 中,运行时解码为 Map。
|
|
13
|
+
* GBK: 23940 个字符映射
|
|
14
|
+
* Big5: 13911 个字符映射
|
|
11
15
|
*/
|
|
12
16
|
|
|
17
|
+
import { GBK_DATA, BIG5_DATA } from './gbk-data';
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* Unicode to GBK mapping table
|
|
15
21
|
* Maps Unicode code points to GBK byte pairs
|
|
@@ -33,512 +39,30 @@ export const unicodeToBig5: Map<number, number> = new Map();
|
|
|
33
39
|
export const big5ToUnicode: Map<number, number> = new Map();
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
42
|
+
* Decode flat array mapping data into forward and reverse maps.
|
|
43
|
+
* Array format: [unicode1, encoded1, unicode2, encoded2, ...]
|
|
38
44
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[0x2014, 0xa1aa], // —
|
|
50
|
-
[0x2018, 0xa1ae], // '
|
|
51
|
-
[0x2019, 0xa1af], // '
|
|
52
|
-
[0x201c, 0xa1b0], // "
|
|
53
|
-
[0x201d, 0xa1b1], // "
|
|
54
|
-
[0xff08, 0xa3a8], // (
|
|
55
|
-
[0xff09, 0xa3a9], // )
|
|
56
|
-
[0x3010, 0xa1be], // 【
|
|
57
|
-
[0x3011, 0xa1bf], // 】
|
|
58
|
-
[0x300a, 0xa1b6], // 《
|
|
59
|
-
[0x300b, 0xa1b7], // 》
|
|
60
|
-
// Common symbols
|
|
61
|
-
[0xffe5, 0xa3a4], // ¥
|
|
62
|
-
[0x00b7, 0xa1a4], // ·
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
// Initialize common mappings
|
|
66
|
-
for (const [unicode, gbk] of commonGbkMappings) {
|
|
67
|
-
unicodeToGbk.set(unicode, gbk);
|
|
68
|
-
gbkToUnicode.set(gbk, unicode);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Generate GBK mappings for GB2312 Level 1 Chinese characters (3755 characters)
|
|
73
|
-
* These are the most commonly used simplified Chinese characters
|
|
74
|
-
* Range: 0xB0A1-0xF7FE
|
|
75
|
-
*/
|
|
76
|
-
function initializeGb2312Level1(): void {
|
|
77
|
-
// GB2312 Level 1 starts at Unicode 0x4E00 region
|
|
78
|
-
// This is a simplified mapping - in production, use a complete table
|
|
79
|
-
|
|
80
|
-
// Common characters mapping (subset for demonstration)
|
|
81
|
-
// In a real implementation, this would be a complete 3755+ character table
|
|
82
|
-
const gb2312Level1: Array<[string, number]> = [
|
|
83
|
-
['啊', 0xb0a1],
|
|
84
|
-
['阿', 0xb0a2],
|
|
85
|
-
['埃', 0xb0a3],
|
|
86
|
-
['挨', 0xb0a4],
|
|
87
|
-
['哎', 0xb0a5],
|
|
88
|
-
['唉', 0xb0a6],
|
|
89
|
-
['哀', 0xb0a7],
|
|
90
|
-
['皑', 0xb0a8],
|
|
91
|
-
['癌', 0xb0a9],
|
|
92
|
-
['蔼', 0xb0aa],
|
|
93
|
-
['矮', 0xb0ab],
|
|
94
|
-
['艾', 0xb0ac],
|
|
95
|
-
['碍', 0xb0ad],
|
|
96
|
-
['爱', 0xb0ae],
|
|
97
|
-
['隘', 0xb0af],
|
|
98
|
-
['鞍', 0xb0b0],
|
|
99
|
-
['氨', 0xb0b1],
|
|
100
|
-
['安', 0xb0b2],
|
|
101
|
-
['俺', 0xb0b3],
|
|
102
|
-
['按', 0xb0b4],
|
|
103
|
-
['暗', 0xb0b5],
|
|
104
|
-
['岸', 0xb0b6],
|
|
105
|
-
['胺', 0xb0b7],
|
|
106
|
-
['案', 0xb0b8],
|
|
107
|
-
['肮', 0xb0b9],
|
|
108
|
-
['昂', 0xb0ba],
|
|
109
|
-
['盎', 0xb0bb],
|
|
110
|
-
['凹', 0xb0bc],
|
|
111
|
-
['敖', 0xb0bd],
|
|
112
|
-
['熬', 0xb0be],
|
|
113
|
-
['翱', 0xb0bf],
|
|
114
|
-
['袄', 0xb0c0],
|
|
115
|
-
['傲', 0xb0c1],
|
|
116
|
-
['奥', 0xb0c2],
|
|
117
|
-
['懊', 0xb0c3],
|
|
118
|
-
['澳', 0xb0c4],
|
|
119
|
-
['芭', 0xb0c5],
|
|
120
|
-
['捌', 0xb0c6],
|
|
121
|
-
['扒', 0xb0c7],
|
|
122
|
-
['叭', 0xb0c8],
|
|
123
|
-
['吧', 0xb0c9],
|
|
124
|
-
['笆', 0xb0ca],
|
|
125
|
-
['八', 0xb0cb],
|
|
126
|
-
['疤', 0xb0cc],
|
|
127
|
-
['巴', 0xb0cd],
|
|
128
|
-
['拔', 0xb0ce],
|
|
129
|
-
['跋', 0xb0cf],
|
|
130
|
-
['靶', 0xb0d0],
|
|
131
|
-
['把', 0xb0d1],
|
|
132
|
-
['耙', 0xb0d2],
|
|
133
|
-
['坝', 0xb0d3],
|
|
134
|
-
['霸', 0xb0d4],
|
|
135
|
-
['罢', 0xb0d5],
|
|
136
|
-
['爸', 0xb0d6],
|
|
137
|
-
['白', 0xb0d7],
|
|
138
|
-
['柏', 0xb0d8],
|
|
139
|
-
['百', 0xb0d9],
|
|
140
|
-
['摆', 0xb0da],
|
|
141
|
-
['佰', 0xb0db],
|
|
142
|
-
['败', 0xb0dc],
|
|
143
|
-
['拜', 0xb0dd],
|
|
144
|
-
['稗', 0xb0de],
|
|
145
|
-
['斑', 0xb0df],
|
|
146
|
-
['班', 0xb0e0],
|
|
147
|
-
['搬', 0xb0e1],
|
|
148
|
-
['扳', 0xb0e2],
|
|
149
|
-
['般', 0xb0e3],
|
|
150
|
-
['颁', 0xb0e4],
|
|
151
|
-
['板', 0xb0e5],
|
|
152
|
-
['版', 0xb0e6],
|
|
153
|
-
['扮', 0xb0e7],
|
|
154
|
-
['拌', 0xb0e8],
|
|
155
|
-
['伴', 0xb0e9],
|
|
156
|
-
['瓣', 0xb0ea],
|
|
157
|
-
['半', 0xb0eb],
|
|
158
|
-
['办', 0xb0ec],
|
|
159
|
-
['绊', 0xb0ed],
|
|
160
|
-
['邦', 0xb0ee],
|
|
161
|
-
['帮', 0xb0ef],
|
|
162
|
-
['梆', 0xb0f0],
|
|
163
|
-
['榜', 0xb0f1],
|
|
164
|
-
['膀', 0xb0f2],
|
|
165
|
-
['绑', 0xb0f3],
|
|
166
|
-
['棒', 0xb0f4],
|
|
167
|
-
['磅', 0xb0f5],
|
|
168
|
-
['蚌', 0xb0f6],
|
|
169
|
-
['镑', 0xb0f7],
|
|
170
|
-
['傍', 0xb0f8],
|
|
171
|
-
['谤', 0xb0f9],
|
|
172
|
-
['苞', 0xb0fa],
|
|
173
|
-
['胞', 0xb0fb],
|
|
174
|
-
['包', 0xb0fc],
|
|
175
|
-
['褒', 0xb0fd],
|
|
176
|
-
['剥', 0xb0fe],
|
|
177
|
-
// B1 section
|
|
178
|
-
['薄', 0xb1a1],
|
|
179
|
-
['雹', 0xb1a2],
|
|
180
|
-
['保', 0xb1a3],
|
|
181
|
-
['堡', 0xb1a4],
|
|
182
|
-
['饱', 0xb1a5],
|
|
183
|
-
['宝', 0xb1a6],
|
|
184
|
-
['抱', 0xb1a7],
|
|
185
|
-
['报', 0xb1a8],
|
|
186
|
-
['暴', 0xb1a9],
|
|
187
|
-
['豹', 0xb1aa],
|
|
188
|
-
['鲍', 0xb1ab],
|
|
189
|
-
['爆', 0xb1ac],
|
|
190
|
-
['杯', 0xb1ad],
|
|
191
|
-
['碑', 0xb1ae],
|
|
192
|
-
['悲', 0xb1af],
|
|
193
|
-
['卑', 0xb1b0],
|
|
194
|
-
['北', 0xb1b1],
|
|
195
|
-
['辈', 0xb1b2],
|
|
196
|
-
['背', 0xb1b3],
|
|
197
|
-
['贝', 0xb1b4],
|
|
198
|
-
['钡', 0xb1b5],
|
|
199
|
-
['倍', 0xb1b6],
|
|
200
|
-
['狈', 0xb1b7],
|
|
201
|
-
['备', 0xb1b8],
|
|
202
|
-
['惫', 0xb1b9],
|
|
203
|
-
['焙', 0xb1ba],
|
|
204
|
-
['被', 0xb1bb],
|
|
205
|
-
['奔', 0xb1bc],
|
|
206
|
-
['苯', 0xb1bd],
|
|
207
|
-
['本', 0xb1be],
|
|
208
|
-
['笨', 0xb1bf],
|
|
209
|
-
['崩', 0xb1c0],
|
|
210
|
-
['绑', 0xb1c1],
|
|
211
|
-
['甭', 0xb1c2],
|
|
212
|
-
['泵', 0xb1c3],
|
|
213
|
-
['蹦', 0xb1c4],
|
|
214
|
-
['迸', 0xb1c5],
|
|
215
|
-
['逼', 0xb1c6],
|
|
216
|
-
['鼻', 0xb1c7],
|
|
217
|
-
['比', 0xb1c8],
|
|
218
|
-
['鄙', 0xb1c9],
|
|
219
|
-
['笔', 0xb1ca],
|
|
220
|
-
['彼', 0xb1cb],
|
|
221
|
-
['碧', 0xb1cc],
|
|
222
|
-
['蓖', 0xb1cd],
|
|
223
|
-
['蔽', 0xb1ce],
|
|
224
|
-
['毕', 0xb1cf],
|
|
225
|
-
['毙', 0xb1d0],
|
|
226
|
-
['毖', 0xb1d1],
|
|
227
|
-
['币', 0xb1d2],
|
|
228
|
-
['庇', 0xb1d3],
|
|
229
|
-
['痹', 0xb1d4],
|
|
230
|
-
['闭', 0xb1d5],
|
|
231
|
-
['敝', 0xb1d6],
|
|
232
|
-
['弊', 0xb1d7],
|
|
233
|
-
['必', 0xb1d8],
|
|
234
|
-
['辟', 0xb1d9],
|
|
235
|
-
['壁', 0xb1da],
|
|
236
|
-
['臂', 0xb1db],
|
|
237
|
-
['避', 0xb1dc],
|
|
238
|
-
['陛', 0xb1dd],
|
|
239
|
-
['鞭', 0xb1de],
|
|
240
|
-
['边', 0xb1df],
|
|
241
|
-
['编', 0xb1e0],
|
|
242
|
-
['贬', 0xb1e1],
|
|
243
|
-
['扁', 0xb1e2],
|
|
244
|
-
['便', 0xb1e3],
|
|
245
|
-
['变', 0xb1e4],
|
|
246
|
-
['卞', 0xb1e5],
|
|
247
|
-
['辨', 0xb1e6],
|
|
248
|
-
['辩', 0xb1e7],
|
|
249
|
-
['辫', 0xb1e8],
|
|
250
|
-
['遍', 0xb1e9],
|
|
251
|
-
['标', 0xb1ea],
|
|
252
|
-
['彪', 0xb1eb],
|
|
253
|
-
['膘', 0xb1ec],
|
|
254
|
-
['表', 0xb1ed],
|
|
255
|
-
['鳖', 0xb1ee],
|
|
256
|
-
['憋', 0xb1ef],
|
|
257
|
-
['别', 0xb1f0],
|
|
258
|
-
['瘪', 0xb1f1],
|
|
259
|
-
['彬', 0xb1f2],
|
|
260
|
-
['斌', 0xb1f3],
|
|
261
|
-
['濒', 0xb1f4],
|
|
262
|
-
['滨', 0xb1f5],
|
|
263
|
-
['宾', 0xb1f6],
|
|
264
|
-
['摈', 0xb1f7],
|
|
265
|
-
['兵', 0xb1f8],
|
|
266
|
-
['冰', 0xb1f9],
|
|
267
|
-
['柄', 0xb1fa],
|
|
268
|
-
['丙', 0xb1fb],
|
|
269
|
-
['秉', 0xb1fc],
|
|
270
|
-
['饼', 0xb1fd],
|
|
271
|
-
['炳', 0xb1fe],
|
|
272
|
-
];
|
|
273
|
-
|
|
274
|
-
for (const [char, gbk] of gb2312Level1) {
|
|
275
|
-
const unicode = char.charCodeAt(0);
|
|
276
|
-
unicodeToGbk.set(unicode, gbk);
|
|
277
|
-
gbkToUnicode.set(gbk, unicode);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Initialize additional common characters
|
|
283
|
-
*/
|
|
284
|
-
function initializeCommonCharacters(): void {
|
|
285
|
-
// Very common characters that might not be in the basic table
|
|
286
|
-
const commonChars: Array<[string, number]> = [
|
|
287
|
-
// Numbers and basic punctuation in full-width
|
|
288
|
-
['0', 0xa3b0],
|
|
289
|
-
['1', 0xa3b1],
|
|
290
|
-
['2', 0xa3b2],
|
|
291
|
-
['3', 0xa3b3],
|
|
292
|
-
['4', 0xa3b4],
|
|
293
|
-
['5', 0xa3b5],
|
|
294
|
-
['6', 0xa3b6],
|
|
295
|
-
['7', 0xa3b7],
|
|
296
|
-
['8', 0xa3b8],
|
|
297
|
-
['9', 0xa3b9],
|
|
298
|
-
// Common words
|
|
299
|
-
['的', 0xb5c4],
|
|
300
|
-
['一', 0xd2bb],
|
|
301
|
-
['是', 0xcac7],
|
|
302
|
-
['不', 0xb2bb],
|
|
303
|
-
['了', 0xc1cb],
|
|
304
|
-
['在', 0xd4da],
|
|
305
|
-
['人', 0xc8cb],
|
|
306
|
-
['有', 0xd3d0],
|
|
307
|
-
['我', 0xced2],
|
|
308
|
-
['他', 0xcbfb],
|
|
309
|
-
['这', 0xd5e2],
|
|
310
|
-
['个', 0xb8f6],
|
|
311
|
-
['们', 0xc3c7],
|
|
312
|
-
['中', 0xd6d0],
|
|
313
|
-
['来', 0xc0b4],
|
|
314
|
-
['上', 0xc9cf],
|
|
315
|
-
['大', 0xb4f3],
|
|
316
|
-
['为', 0xceaa],
|
|
317
|
-
['和', 0xbacd],
|
|
318
|
-
['国', 0xb9fa],
|
|
319
|
-
['地', 0xb5d8],
|
|
320
|
-
['到', 0xb5bd],
|
|
321
|
-
['以', 0xd2d4],
|
|
322
|
-
['说', 0xcbb5],
|
|
323
|
-
['时', 0xcab1],
|
|
324
|
-
['要', 0xd2aa],
|
|
325
|
-
['就', 0xbecd],
|
|
326
|
-
['出', 0xb3f6],
|
|
327
|
-
['会', 0xbbe1],
|
|
328
|
-
['可', 0xbfc9],
|
|
329
|
-
['也', 0xd2b2],
|
|
330
|
-
['你', 0xc4e3],
|
|
331
|
-
['对', 0xb6d4],
|
|
332
|
-
['生', 0xc9fa],
|
|
333
|
-
['能', 0xc4dc],
|
|
334
|
-
['而', 0xb6f8],
|
|
335
|
-
['子', 0xd7d3],
|
|
336
|
-
['那', 0xc4c7],
|
|
337
|
-
['得', 0xb5c3],
|
|
338
|
-
['于', 0xd3da],
|
|
339
|
-
['着', 0xd7c5],
|
|
340
|
-
['下', 0xcfc2],
|
|
341
|
-
['自', 0xd7d4],
|
|
342
|
-
['之', 0xd6ae],
|
|
343
|
-
['年', 0xc4ea],
|
|
344
|
-
['过', 0xb9fd],
|
|
345
|
-
['发', 0xb7a2],
|
|
346
|
-
['后', 0xbaf3],
|
|
347
|
-
['作', 0xd7f7],
|
|
348
|
-
['里', 0xc0ef],
|
|
349
|
-
['用', 0xd3c3],
|
|
350
|
-
['道', 0xb5c0],
|
|
351
|
-
['行', 0xd0d0],
|
|
352
|
-
['所', 0xcbf9],
|
|
353
|
-
['然', 0xc8bb],
|
|
354
|
-
['家', 0xbcd2],
|
|
355
|
-
['种', 0xd6d6],
|
|
356
|
-
['事', 0xcac2],
|
|
357
|
-
['成', 0xb3c9],
|
|
358
|
-
['方', 0xb7bd],
|
|
359
|
-
['多', 0xb6e0],
|
|
360
|
-
['经', 0xbead],
|
|
361
|
-
['么', 0xc3b4],
|
|
362
|
-
['去', 0xc8a5],
|
|
363
|
-
['法', 0xb7a8],
|
|
364
|
-
['学', 0xd1a7],
|
|
365
|
-
['如', 0xc8e7],
|
|
366
|
-
['都', 0xb6bc],
|
|
367
|
-
['同', 0xcdac],
|
|
368
|
-
['现', 0xcfd6],
|
|
369
|
-
['当', 0xb5b1],
|
|
370
|
-
['没', 0xc3bb],
|
|
371
|
-
['动', 0xb6af],
|
|
372
|
-
['面', 0xc3e6],
|
|
373
|
-
['起', 0xc6f0],
|
|
374
|
-
['看', 0xbfb4],
|
|
375
|
-
['定', 0xb6a8],
|
|
376
|
-
['天', 0xccec],
|
|
377
|
-
['分', 0xb7d6],
|
|
378
|
-
['还', 0xbbb9],
|
|
379
|
-
['进', 0xbdf8],
|
|
380
|
-
['好', 0xbac3],
|
|
381
|
-
['小', 0xd0a1],
|
|
382
|
-
['部', 0xb2bf],
|
|
383
|
-
['其', 0xc6e4],
|
|
384
|
-
['些', 0xd0a9],
|
|
385
|
-
['主', 0xd6f7],
|
|
386
|
-
['样', 0xd1f9],
|
|
387
|
-
['理', 0xc0ed],
|
|
388
|
-
['心', 0xd0c4],
|
|
389
|
-
['她', 0xcbfd],
|
|
390
|
-
['本', 0xb1be],
|
|
391
|
-
['前', 0xc7b0],
|
|
392
|
-
['开', 0xbfaa],
|
|
393
|
-
['但', 0xb5ab],
|
|
394
|
-
['因', 0xd2f2],
|
|
395
|
-
['只', 0xd6bb],
|
|
396
|
-
['从', 0xb4d3],
|
|
397
|
-
['想', 0xcfeb],
|
|
398
|
-
['实', 0xcab5],
|
|
399
|
-
// Receipt/label common words
|
|
400
|
-
['店', 0xb5ea],
|
|
401
|
-
['铺', 0xc6cc],
|
|
402
|
-
['商', 0xc9cc],
|
|
403
|
-
['品', 0xc6b7],
|
|
404
|
-
['价', 0xbcdb],
|
|
405
|
-
['格', 0xb8f1],
|
|
406
|
-
['数', 0xcafd],
|
|
407
|
-
['量', 0xc1bf],
|
|
408
|
-
['合', 0xbacd],
|
|
409
|
-
['计', 0xbcc6],
|
|
410
|
-
['总', 0xd7dc],
|
|
411
|
-
['金', 0xbdf0],
|
|
412
|
-
['额', 0xb6ee],
|
|
413
|
-
['订', 0xb6a9],
|
|
414
|
-
['单', 0xb5a5],
|
|
415
|
-
['号', 0xbac5],
|
|
416
|
-
['日', 0xc8d5],
|
|
417
|
-
['期', 0xc6da],
|
|
418
|
-
['收', 0xcad5],
|
|
419
|
-
['银', 0xd2f8],
|
|
420
|
-
['员', 0xd4b1],
|
|
421
|
-
['找', 0xd5d2],
|
|
422
|
-
['零', 0xc1e3],
|
|
423
|
-
['付', 0xb8b6],
|
|
424
|
-
['款', 0xbfee],
|
|
425
|
-
['现', 0xcfd6],
|
|
426
|
-
['支', 0xd6a7],
|
|
427
|
-
['微', 0xcea2],
|
|
428
|
-
['信', 0xd0c5],
|
|
429
|
-
['宝', 0xb1a6],
|
|
430
|
-
['谢', 0xd0bb],
|
|
431
|
-
['光', 0xb9e2],
|
|
432
|
-
['临', 0xc1d9],
|
|
433
|
-
['欢', 0xbbb6],
|
|
434
|
-
['迎', 0xd3ad],
|
|
435
|
-
['再', 0xd4d9],
|
|
436
|
-
['次', 0xb4ce],
|
|
437
|
-
['惠', 0xbbdd],
|
|
438
|
-
['顾', 0xb9cb],
|
|
439
|
-
// Food/product related
|
|
440
|
-
['食', 0xcab3],
|
|
441
|
-
['物', 0xceef],
|
|
442
|
-
['饮', 0xd2fb],
|
|
443
|
-
['料', 0xc1cf],
|
|
444
|
-
['水', 0xcbae],
|
|
445
|
-
['果', 0xb9fb],
|
|
446
|
-
['蔬', 0xcadf],
|
|
447
|
-
['菜', 0xb2cb],
|
|
448
|
-
['肉', 0xc8e2],
|
|
449
|
-
['鱼', 0xd3e3],
|
|
450
|
-
['米', 0xc3d7],
|
|
451
|
-
['面', 0xc3e6],
|
|
452
|
-
['油', 0xd3cd],
|
|
453
|
-
['盐', 0xd1ce],
|
|
454
|
-
['糖', 0xccc7],
|
|
455
|
-
// Units
|
|
456
|
-
['元', 0xd4aa],
|
|
457
|
-
['角', 0xbdc7],
|
|
458
|
-
['分', 0xb7d6],
|
|
459
|
-
['斤', 0xbdef],
|
|
460
|
-
['克', 0xbfcb],
|
|
461
|
-
['千', 0xc7a7],
|
|
462
|
-
['万', 0xcdf2],
|
|
463
|
-
['亿', 0xd2da],
|
|
464
|
-
['个', 0xb8f6],
|
|
465
|
-
['件', 0xbcfe],
|
|
466
|
-
['份', 0xb7dd],
|
|
467
|
-
['包', 0xb0fc],
|
|
468
|
-
['袋', 0xb4fc],
|
|
469
|
-
['盒', 0xbad0],
|
|
470
|
-
['瓶', 0xc6bf],
|
|
471
|
-
['杯', 0xb1ad],
|
|
472
|
-
['碗', 0xcdeb],
|
|
473
|
-
['盘', 0xc5cc],
|
|
474
|
-
];
|
|
475
|
-
|
|
476
|
-
for (const [char, gbk] of commonChars) {
|
|
477
|
-
const unicode = char.charCodeAt(0);
|
|
478
|
-
if (!unicodeToGbk.has(unicode)) {
|
|
479
|
-
unicodeToGbk.set(unicode, gbk);
|
|
480
|
-
gbkToUnicode.set(gbk, unicode);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Initialize Big5 common characters for traditional Chinese
|
|
487
|
-
*/
|
|
488
|
-
function initializeBig5Common(): void {
|
|
489
|
-
const big5Chars: Array<[string, number]> = [
|
|
490
|
-
// Common traditional Chinese characters
|
|
491
|
-
['的', 0xa4de],
|
|
492
|
-
['一', 0xa440],
|
|
493
|
-
['是', 0xac4f],
|
|
494
|
-
['不', 0xa4a3],
|
|
495
|
-
['了', 0xa4f4],
|
|
496
|
-
['在', 0xa658],
|
|
497
|
-
['人', 0xa4a8],
|
|
498
|
-
['有', 0xa6b3],
|
|
499
|
-
['我', 0xa7da],
|
|
500
|
-
['他', 0xa5b0],
|
|
501
|
-
['這', 0xb3e4],
|
|
502
|
-
['個', 0xad50],
|
|
503
|
-
['們', 0xadcc],
|
|
504
|
-
['中', 0xa4a4],
|
|
505
|
-
['來', 0xa8d3],
|
|
506
|
-
['上', 0xa4f8],
|
|
507
|
-
['大', 0xa4a6],
|
|
508
|
-
['為', 0xac50],
|
|
509
|
-
['和', 0xa940],
|
|
510
|
-
['國', 0xb0f8],
|
|
511
|
-
// Traditional specific
|
|
512
|
-
['臺', 0xbbcf],
|
|
513
|
-
['灣', 0xc6fa],
|
|
514
|
-
['學', 0xbe78],
|
|
515
|
-
['電', 0xb9f6],
|
|
516
|
-
['腦', 0xb8a6],
|
|
517
|
-
['網', 0xba59],
|
|
518
|
-
['際', 0xbf50],
|
|
519
|
-
['機', 0xbf5a],
|
|
520
|
-
['關', 0xc340],
|
|
521
|
-
['開', 0xb6aa],
|
|
522
|
-
];
|
|
523
|
-
|
|
524
|
-
for (const [char, big5] of big5Chars) {
|
|
525
|
-
const unicode = char.charCodeAt(0);
|
|
526
|
-
if (!unicodeToBig5.has(unicode)) {
|
|
527
|
-
unicodeToBig5.set(unicode, big5);
|
|
528
|
-
big5ToUnicode.set(big5, unicode);
|
|
529
|
-
}
|
|
45
|
+
function decodeMappings(
|
|
46
|
+
data: number[],
|
|
47
|
+
forwardMap: Map<number, number>,
|
|
48
|
+
reverseMap: Map<number, number>
|
|
49
|
+
): void {
|
|
50
|
+
for (let i = 0; i < data.length; i += 2) {
|
|
51
|
+
const unicode = data[i]!;
|
|
52
|
+
const encoded = data[i + 1]!;
|
|
53
|
+
forwardMap.set(unicode, encoded);
|
|
54
|
+
reverseMap.set(encoded, unicode);
|
|
530
55
|
}
|
|
531
56
|
}
|
|
532
57
|
|
|
533
|
-
// Initialize
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
initializeBig5Common();
|
|
58
|
+
// Initialize mappings at module load time
|
|
59
|
+
decodeMappings(GBK_DATA, unicodeToGbk, gbkToUnicode);
|
|
60
|
+
decodeMappings(BIG5_DATA, unicodeToBig5, big5ToUnicode);
|
|
537
61
|
|
|
538
62
|
/**
|
|
539
63
|
* Get GBK bytes for a Unicode character
|
|
540
64
|
* @param unicode - Unicode code point
|
|
541
|
-
* @returns GBK byte pair or null if not found
|
|
65
|
+
* @returns GBK byte pair [high, low] or null if not found
|
|
542
66
|
*/
|
|
543
67
|
export function getGbkBytes(unicode: number): [number, number] | null {
|
|
544
68
|
const gbk = unicodeToGbk.get(unicode);
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,15 @@ export { EventEmitter } from './core/EventEmitter';
|
|
|
12
12
|
|
|
13
13
|
// Drivers
|
|
14
14
|
export { EscPos } from './drivers/EscPos';
|
|
15
|
+
export { TsplDriver } from './drivers/TsplDriver';
|
|
16
|
+
export type {
|
|
17
|
+
LabelSize,
|
|
18
|
+
TextOptions as TsplTextOptions,
|
|
19
|
+
BarcodeOptions as TsplBarcodeOptions,
|
|
20
|
+
QRCodeOptions as TsplQRCodeOptions,
|
|
21
|
+
BoxOptions,
|
|
22
|
+
LineOptions,
|
|
23
|
+
} from './drivers/TsplDriver';
|
|
15
24
|
|
|
16
25
|
// Adapters
|
|
17
26
|
export { TaroAdapter } from './adapters/TaroAdapter';
|
|
@@ -90,5 +99,10 @@ export type {
|
|
|
90
99
|
LoggingConfig,
|
|
91
100
|
} from './config/PrinterConfig';
|
|
92
101
|
|
|
102
|
+
// Plugin System
|
|
103
|
+
export { PluginManager } from './plugins/PluginManager';
|
|
104
|
+
export { createLoggingPlugin, createRetryPlugin } from './plugins';
|
|
105
|
+
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/types';
|
|
106
|
+
|
|
93
107
|
// Types
|
|
94
108
|
export * from './types';
|