@pisell/utils 1.0.15 → 1.0.17
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/es/escPosPrinter/EscPosPrinter.js +526 -0
- package/es/escPosPrinter/index.d.ts +9 -0
- package/es/escPosPrinter/index.js +54 -0
- package/es/firebase/index.d.ts +2 -1
- package/es/firebase/index.js +13 -8
- package/es/index.d.ts +8 -7
- package/es/index.js +1 -0
- package/lib/escPosPrinter/EscPosPrinter.js +516 -0
- package/lib/escPosPrinter/index.d.ts +9 -0
- package/lib/escPosPrinter/index.js +85 -0
- package/lib/firebase/index.d.ts +2 -1
- package/lib/firebase/index.js +9 -3
- package/lib/index.d.ts +8 -7
- package/lib/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/escPosPrinter/EscPosPrinter.js
|
|
20
|
+
var EscPosPrinter_exports = {};
|
|
21
|
+
__export(EscPosPrinter_exports, {
|
|
22
|
+
ALIGN_CENTER: () => ALIGN_CENTER,
|
|
23
|
+
ALIGN_LEFT: () => ALIGN_LEFT,
|
|
24
|
+
ALIGN_RIGHT: () => ALIGN_RIGHT,
|
|
25
|
+
HRI_POS_ABOVE: () => HRI_POS_ABOVE,
|
|
26
|
+
HRI_POS_BELOW: () => HRI_POS_BELOW,
|
|
27
|
+
MAX_COLUMNS: () => MAX_COLUMNS,
|
|
28
|
+
columnWidthWithAlignment: () => columnWidthWithAlignment,
|
|
29
|
+
default: () => EscPosPrinter_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(EscPosPrinter_exports);
|
|
32
|
+
var MAX_COLUMNS = 6;
|
|
33
|
+
var ALIGN_LEFT = 0;
|
|
34
|
+
var ALIGN_CENTER = 1;
|
|
35
|
+
var ALIGN_RIGHT = 2;
|
|
36
|
+
var HRI_POS_ABOVE = 1;
|
|
37
|
+
var HRI_POS_BELOW = 2;
|
|
38
|
+
var EscPosPrinter = function(dotsPerLine) {
|
|
39
|
+
if (dotsPerLine != 384 && dotsPerLine != 576)
|
|
40
|
+
dotsPerLine = 384;
|
|
41
|
+
this.widthOfColumns = new Array(MAX_COLUMNS);
|
|
42
|
+
this.dotsPerLine = dotsPerLine;
|
|
43
|
+
this.charHSize = 1;
|
|
44
|
+
this.orderData = "";
|
|
45
|
+
};
|
|
46
|
+
function _numToHexStr(n, bytes) {
|
|
47
|
+
var str = "";
|
|
48
|
+
var v;
|
|
49
|
+
for (var i = 0; i < bytes; i++) {
|
|
50
|
+
v = n & 255;
|
|
51
|
+
if (v < 16)
|
|
52
|
+
str += "0" + v.toString(16);
|
|
53
|
+
else
|
|
54
|
+
str += v.toString(16);
|
|
55
|
+
n >>= 8;
|
|
56
|
+
}
|
|
57
|
+
return str;
|
|
58
|
+
}
|
|
59
|
+
function _unicodeToUtf8(unicode) {
|
|
60
|
+
var c1, c2, c3, c4;
|
|
61
|
+
if (unicode < 0)
|
|
62
|
+
return "";
|
|
63
|
+
if (unicode <= 127) {
|
|
64
|
+
c1 = unicode & 127;
|
|
65
|
+
return _numToHexStr(c1, 1);
|
|
66
|
+
}
|
|
67
|
+
if (unicode <= 2047) {
|
|
68
|
+
c1 = unicode >> 6 & 31 | 192;
|
|
69
|
+
c2 = unicode & 63 | 128;
|
|
70
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1);
|
|
71
|
+
}
|
|
72
|
+
if (unicode <= 65535) {
|
|
73
|
+
c1 = unicode >> 12 & 15 | 224;
|
|
74
|
+
c2 = unicode >> 6 & 63 | 128;
|
|
75
|
+
c3 = unicode & 63 | 128;
|
|
76
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1);
|
|
77
|
+
}
|
|
78
|
+
if (unicode <= 1114111) {
|
|
79
|
+
c1 = unicode >> 18 & 7 | 240;
|
|
80
|
+
c2 = unicode >> 12 & 63 | 128;
|
|
81
|
+
c3 = unicode >> 6 & 63 | 128;
|
|
82
|
+
c4 = unicode & 63 | 128;
|
|
83
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1) + _numToHexStr(c4, 1);
|
|
84
|
+
}
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
EscPosPrinter.prototype.clear = function() {
|
|
88
|
+
this.orderData = "";
|
|
89
|
+
};
|
|
90
|
+
EscPosPrinter.prototype.print = function(host, sn, copies) {
|
|
91
|
+
return new Promise(function(resolve, reject) {
|
|
92
|
+
var xmlobj = new XMLHttpRequest();
|
|
93
|
+
var url = "http://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
|
|
94
|
+
xmlobj.open("POST", url, true);
|
|
95
|
+
xmlobj.onreadystatechange = function() {
|
|
96
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
97
|
+
alert(
|
|
98
|
+
"[status]\n" + xmlobj.status.toString(10) + "\n\n[response]\n" + xmlobj.responseText
|
|
99
|
+
);
|
|
100
|
+
var re = /task_id: (\d+)/;
|
|
101
|
+
var matches = re.exec(xmlobj.responseText);
|
|
102
|
+
resolve(matches[1]);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
106
|
+
xmlobj.send(this.orderData);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
EscPosPrinter.prototype.queryStatus = function(host, sn, task_id) {
|
|
110
|
+
var xmlobj = new XMLHttpRequest();
|
|
111
|
+
var url = "http://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
|
|
112
|
+
xmlobj.open("POST", url, true);
|
|
113
|
+
xmlobj.onreadystatechange = function() {
|
|
114
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
115
|
+
alert(
|
|
116
|
+
"[status]\n" + xmlobj.status.toString(10) + "\n\n[response]\n" + xmlobj.responseText
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=uft-8");
|
|
121
|
+
xmlobj.send();
|
|
122
|
+
};
|
|
123
|
+
EscPosPrinter.prototype.appendText = function(str) {
|
|
124
|
+
for (var i = 0; i < str.length; i++)
|
|
125
|
+
this.orderData += _unicodeToUtf8(str.charCodeAt(i));
|
|
126
|
+
};
|
|
127
|
+
EscPosPrinter.prototype.lineFeed = function(n) {
|
|
128
|
+
for (var i = 0; i < n; i++)
|
|
129
|
+
this.orderData += "0a";
|
|
130
|
+
};
|
|
131
|
+
EscPosPrinter.prototype.restoreDefaultSettings = function() {
|
|
132
|
+
this.charHSize = 1;
|
|
133
|
+
this.orderData += "1b40";
|
|
134
|
+
};
|
|
135
|
+
EscPosPrinter.prototype.restoreDefaultLineSpacing = function() {
|
|
136
|
+
this.orderData += "1b32";
|
|
137
|
+
};
|
|
138
|
+
EscPosPrinter.prototype.setLineSpacing = function(n) {
|
|
139
|
+
if (n >= 0 && n <= 255)
|
|
140
|
+
this.orderData += "1b33" + _numToHexStr(n, 1);
|
|
141
|
+
};
|
|
142
|
+
EscPosPrinter.prototype.setPrintModes = function(bold, double_h, double_w) {
|
|
143
|
+
var n = 0;
|
|
144
|
+
if (bold)
|
|
145
|
+
n |= 8;
|
|
146
|
+
if (double_h)
|
|
147
|
+
n |= 16;
|
|
148
|
+
if (double_w)
|
|
149
|
+
n |= 32;
|
|
150
|
+
this.charHSize = double_w ? 2 : 1;
|
|
151
|
+
this.orderData += "1b21" + _numToHexStr(n, 1);
|
|
152
|
+
};
|
|
153
|
+
EscPosPrinter.prototype.setCharacterSize = function(h, w) {
|
|
154
|
+
var n = 0;
|
|
155
|
+
if (h >= 1 && h <= 8)
|
|
156
|
+
n |= h - 1;
|
|
157
|
+
if (w >= 1 && w <= 8) {
|
|
158
|
+
n |= w - 1 << 4;
|
|
159
|
+
this.charHSize = w;
|
|
160
|
+
}
|
|
161
|
+
this.orderData += "1d21" + _numToHexStr(n, 1);
|
|
162
|
+
};
|
|
163
|
+
EscPosPrinter.prototype.horizontalTab = function(n) {
|
|
164
|
+
for (var i = 0; i < n; i++)
|
|
165
|
+
this.orderData += "09";
|
|
166
|
+
};
|
|
167
|
+
EscPosPrinter.prototype.setAbsolutePrintPosition = function(n) {
|
|
168
|
+
if (n >= 0 && n <= 65535)
|
|
169
|
+
this.orderData += "1b24" + _numToHexStr(n, 2);
|
|
170
|
+
};
|
|
171
|
+
EscPosPrinter.prototype.setRelativePrintPosition = function(n) {
|
|
172
|
+
if (n >= -32768 && n <= 32767)
|
|
173
|
+
this.orderData += "1b5c" + _numToHexStr(n, 2);
|
|
174
|
+
};
|
|
175
|
+
EscPosPrinter.prototype.setAlignment = function(n) {
|
|
176
|
+
if (n >= 0 && n <= 2)
|
|
177
|
+
this.orderData += "1b61" + _numToHexStr(n, 1);
|
|
178
|
+
};
|
|
179
|
+
EscPosPrinter.prototype.cutPaper = function(fullCut) {
|
|
180
|
+
this.orderData += "1d56" + (fullCut ? "30" : "31");
|
|
181
|
+
};
|
|
182
|
+
EscPosPrinter.prototype.postponedCutPaper = function(fullCut, n) {
|
|
183
|
+
if (n >= 0 && n <= 255)
|
|
184
|
+
this.orderData += "1d56" + (fullCut ? "61" : "62") + _numToHexStr(n, 1);
|
|
185
|
+
};
|
|
186
|
+
function _widthOfChar(c) {
|
|
187
|
+
if (c >= 32 && c <= 879 || c >= 65377 && c <= 65439)
|
|
188
|
+
return 12;
|
|
189
|
+
if (c == 8208 || c >= 8211 && c <= 8214 || c >= 8216 && c <= 8217 || c >= 8220 && c <= 8221 || c >= 8229 && c <= 8230 || c >= 8240 && c <= 8243 || c == 8245 || c == 8251)
|
|
190
|
+
return 24;
|
|
191
|
+
if (c >= 4352 && c <= 4607 || c >= 9312 && c <= 9471 || c >= 9632 && c <= 10175 || c >= 11904 && c <= 12255 || c >= 12288 && c <= 12687 || c >= 12704 && c <= 12783 || c >= 12800 && c <= 40959 || c >= 44032 && c <= 55295 || c >= 63744 && c <= 64255 || c >= 65072 && c <= 65103 || c >= 126976 && c <= 129535)
|
|
192
|
+
return 24;
|
|
193
|
+
if (c >= 65281 && c <= 65374 || c >= 65504 && c <= 65509)
|
|
194
|
+
return 24;
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
function columnWidthWithAlignment(width, alignment) {
|
|
198
|
+
return width & 65535 | (alignment & 3) << 16;
|
|
199
|
+
}
|
|
200
|
+
function _columnWidth(v) {
|
|
201
|
+
return v & 65535;
|
|
202
|
+
}
|
|
203
|
+
function _columnAlignment(v) {
|
|
204
|
+
return v >> 16 & 3;
|
|
205
|
+
}
|
|
206
|
+
EscPosPrinter.prototype.setColumnWidths = function() {
|
|
207
|
+
var i, remain, width, alignment;
|
|
208
|
+
if (arguments.length == 0)
|
|
209
|
+
return;
|
|
210
|
+
for (i = 0; i < MAX_COLUMNS; i++)
|
|
211
|
+
this.widthOfColumns[i] = 0;
|
|
212
|
+
remain = this.dotsPerLine;
|
|
213
|
+
for (i = 0; i < arguments.length; i++) {
|
|
214
|
+
if (i == MAX_COLUMNS)
|
|
215
|
+
return;
|
|
216
|
+
width = _columnWidth(arguments[i]);
|
|
217
|
+
alignment = _columnAlignment(arguments[i]);
|
|
218
|
+
if (width == 0 || width > remain) {
|
|
219
|
+
this.widthOfColumns[i] = columnWidthWithAlignment(remain, alignment);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.widthOfColumns[i] = arguments[i];
|
|
223
|
+
remain -= width;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
EscPosPrinter.prototype.printInColumns = function() {
|
|
227
|
+
var strcurr = new Array(MAX_COLUMNS);
|
|
228
|
+
var strrem = new Array(MAX_COLUMNS);
|
|
229
|
+
var strwidth = new Array(MAX_COLUMNS);
|
|
230
|
+
var i, j, c, w, columns, width, alignment, pos;
|
|
231
|
+
var done;
|
|
232
|
+
if (arguments.length == 0)
|
|
233
|
+
return;
|
|
234
|
+
columns = 0;
|
|
235
|
+
for (i = 0; i < arguments.length; i++) {
|
|
236
|
+
if (i == MAX_COLUMNS || this.widthOfColumns[i] == 0)
|
|
237
|
+
break;
|
|
238
|
+
strcurr[i] = "";
|
|
239
|
+
strrem[i] = arguments[i];
|
|
240
|
+
columns++;
|
|
241
|
+
}
|
|
242
|
+
do {
|
|
243
|
+
done = true;
|
|
244
|
+
pos = 0;
|
|
245
|
+
for (i = 0; i < columns; i++) {
|
|
246
|
+
width = _columnWidth(this.widthOfColumns[i]);
|
|
247
|
+
if (strrem[i].length == 0) {
|
|
248
|
+
pos += width;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
done = false;
|
|
252
|
+
strcurr[i] = "";
|
|
253
|
+
strwidth[i] = 0;
|
|
254
|
+
for (j = 0; j < strrem[i].length; j++) {
|
|
255
|
+
c = strrem[i].charCodeAt(j);
|
|
256
|
+
if (c == 10) {
|
|
257
|
+
j++;
|
|
258
|
+
break;
|
|
259
|
+
} else {
|
|
260
|
+
w = _widthOfChar(c);
|
|
261
|
+
if (w == 0) {
|
|
262
|
+
c = "?";
|
|
263
|
+
w = 12;
|
|
264
|
+
}
|
|
265
|
+
w *= this.charHSize;
|
|
266
|
+
if (strwidth[i] + w > width) {
|
|
267
|
+
break;
|
|
268
|
+
} else {
|
|
269
|
+
strcurr[i] += String.fromCharCode(c);
|
|
270
|
+
strwidth[i] += w;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (j < strrem[i].length)
|
|
275
|
+
strrem[i] = strrem[i].substring(j);
|
|
276
|
+
else
|
|
277
|
+
strrem[i] = "";
|
|
278
|
+
alignment = _columnAlignment(this.widthOfColumns[i]);
|
|
279
|
+
switch (alignment) {
|
|
280
|
+
case ALIGN_CENTER:
|
|
281
|
+
this.setAbsolutePrintPosition(pos + (width - strwidth[i]) / 2);
|
|
282
|
+
break;
|
|
283
|
+
case ALIGN_RIGHT:
|
|
284
|
+
this.setAbsolutePrintPosition(pos + (width - strwidth[i]));
|
|
285
|
+
break;
|
|
286
|
+
default:
|
|
287
|
+
this.setAbsolutePrintPosition(pos);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
this.appendText(strcurr[i]);
|
|
291
|
+
pos += width;
|
|
292
|
+
}
|
|
293
|
+
if (!done)
|
|
294
|
+
this.lineFeed(1);
|
|
295
|
+
} while (!done);
|
|
296
|
+
};
|
|
297
|
+
EscPosPrinter.prototype.appendBarcode = function(hri_pos, height, module_size, barcode_type, text) {
|
|
298
|
+
var text_length = text.length;
|
|
299
|
+
if (text_length == 0)
|
|
300
|
+
return;
|
|
301
|
+
if (text_length > 255)
|
|
302
|
+
text_length = 255;
|
|
303
|
+
if (height < 1)
|
|
304
|
+
height = 1;
|
|
305
|
+
else if (height > 255)
|
|
306
|
+
height = 255;
|
|
307
|
+
if (module_size < 1)
|
|
308
|
+
module_size = 1;
|
|
309
|
+
else if (module_size > 6)
|
|
310
|
+
module_size = 6;
|
|
311
|
+
this.orderData += "1d48" + _numToHexStr(hri_pos & 3, 1);
|
|
312
|
+
this.orderData += "1d6600";
|
|
313
|
+
this.orderData += "1d68" + _numToHexStr(height, 1);
|
|
314
|
+
this.orderData += "1d77" + _numToHexStr(module_size, 1);
|
|
315
|
+
this.orderData += "1d6b" + _numToHexStr(barcode_type, 1) + _numToHexStr(text_length, 1);
|
|
316
|
+
for (var i = 0; i < text_length; i++)
|
|
317
|
+
this.orderData += _numToHexStr(text.charCodeAt(i), 1);
|
|
318
|
+
};
|
|
319
|
+
EscPosPrinter.prototype.appendQRcode = function(module_size, ec_level, text) {
|
|
320
|
+
var text_length = text.length;
|
|
321
|
+
if (text_length == 0)
|
|
322
|
+
return;
|
|
323
|
+
if (text_length > 65535)
|
|
324
|
+
text_length = 65535;
|
|
325
|
+
if (module_size < 1)
|
|
326
|
+
module_size = 1;
|
|
327
|
+
else if (module_size > 16)
|
|
328
|
+
module_size = 16;
|
|
329
|
+
if (ec_level < 0)
|
|
330
|
+
ec_level = 0;
|
|
331
|
+
else if (ec_level > 3)
|
|
332
|
+
ec_level = 3;
|
|
333
|
+
this.orderData += "1d286b040031410000";
|
|
334
|
+
this.orderData += "1d286b03003143" + _numToHexStr(module_size, 1);
|
|
335
|
+
this.orderData += "1d286b03003145" + _numToHexStr(ec_level + 48, 1);
|
|
336
|
+
this.orderData += "1d286b" + _numToHexStr(text_length + 3, 2) + "315030";
|
|
337
|
+
for (var i = 0; i < text_length; i++)
|
|
338
|
+
this.orderData += _numToHexStr(text.charCodeAt(i), 1);
|
|
339
|
+
this.orderData += "1d286b0300315130";
|
|
340
|
+
};
|
|
341
|
+
function _diffuseDither(src_data, width, height) {
|
|
342
|
+
if (width <= 0 || height <= 0)
|
|
343
|
+
return null;
|
|
344
|
+
if (src_data.length < width * height)
|
|
345
|
+
return null;
|
|
346
|
+
var bmwidth = width + 7 >> 3;
|
|
347
|
+
var dst_data = new Array(bmwidth * height);
|
|
348
|
+
var line_buffer = new Array(2 * width);
|
|
349
|
+
var i, p, q, x, y, mask;
|
|
350
|
+
var line1, line2, b1, b2, tmp;
|
|
351
|
+
var err, e1, e3, e5, e7;
|
|
352
|
+
var not_last_line;
|
|
353
|
+
line1 = 0;
|
|
354
|
+
line2 = 1;
|
|
355
|
+
for (i = 0; i < width; i++) {
|
|
356
|
+
line_buffer[i] = 0;
|
|
357
|
+
line_buffer[width + i] = src_data[i];
|
|
358
|
+
}
|
|
359
|
+
for (y = 0; y < height; y++) {
|
|
360
|
+
tmp = line1;
|
|
361
|
+
line1 = line2;
|
|
362
|
+
line2 = tmp;
|
|
363
|
+
not_last_line = y < height - 1;
|
|
364
|
+
if (not_last_line) {
|
|
365
|
+
p = (y + 1) * width;
|
|
366
|
+
for (i = 0; i < width; i++) {
|
|
367
|
+
line_buffer[line2 * width + i] = src_data[p];
|
|
368
|
+
p++;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
q = y * bmwidth;
|
|
372
|
+
for (i = 0; i < bmwidth; i++) {
|
|
373
|
+
dst_data[q] = 0;
|
|
374
|
+
q++;
|
|
375
|
+
}
|
|
376
|
+
b1 = 0;
|
|
377
|
+
b2 = 0;
|
|
378
|
+
q = y * bmwidth;
|
|
379
|
+
mask = 128;
|
|
380
|
+
for (x = 1; x <= width; x++) {
|
|
381
|
+
var idx = line1 * width + b1;
|
|
382
|
+
if (line_buffer[idx] < 128) {
|
|
383
|
+
err = line_buffer[idx];
|
|
384
|
+
dst_data[q] |= mask;
|
|
385
|
+
} else {
|
|
386
|
+
err = line_buffer[idx] - 255;
|
|
387
|
+
}
|
|
388
|
+
b1++;
|
|
389
|
+
if (mask == 1) {
|
|
390
|
+
q++;
|
|
391
|
+
mask = 128;
|
|
392
|
+
} else {
|
|
393
|
+
mask >>= 1;
|
|
394
|
+
}
|
|
395
|
+
e7 = err * 7 + 8 >> 4;
|
|
396
|
+
e5 = err * 5 + 8 >> 4;
|
|
397
|
+
e3 = err * 3 + 8 >> 4;
|
|
398
|
+
e1 = err - (e7 + e5 + e3);
|
|
399
|
+
if (x < width)
|
|
400
|
+
line_buffer[line1 * width + b1] += e7;
|
|
401
|
+
if (not_last_line) {
|
|
402
|
+
line_buffer[line2 * width + b2] += e5;
|
|
403
|
+
if (x > 1)
|
|
404
|
+
line_buffer[line2 * width + b2 - 1] += e3;
|
|
405
|
+
if (x < width)
|
|
406
|
+
line_buffer[line2 * width + b2 + 1] += e1;
|
|
407
|
+
}
|
|
408
|
+
b2++;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return dst_data;
|
|
412
|
+
}
|
|
413
|
+
function _thresholdDither(src_data, width, height) {
|
|
414
|
+
if (width <= 0 || height <= 0)
|
|
415
|
+
return null;
|
|
416
|
+
if (src_data.length < width * height)
|
|
417
|
+
return null;
|
|
418
|
+
var bmwidth = width + 7 >> 3;
|
|
419
|
+
var dst_data = new Array(bmwidth * height);
|
|
420
|
+
var p, q, k, x, y, mask;
|
|
421
|
+
p = 0;
|
|
422
|
+
q = 0;
|
|
423
|
+
for (y = 0; y < height; y++) {
|
|
424
|
+
k = q;
|
|
425
|
+
mask = 128;
|
|
426
|
+
for (x = 0; x < width; x++) {
|
|
427
|
+
if (src_data[p] < 128) {
|
|
428
|
+
dst_data[k] |= mask;
|
|
429
|
+
}
|
|
430
|
+
p++;
|
|
431
|
+
if (mask == 1) {
|
|
432
|
+
k++;
|
|
433
|
+
mask = 128;
|
|
434
|
+
} else {
|
|
435
|
+
mask >>= 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
q += bmwidth;
|
|
439
|
+
}
|
|
440
|
+
return dst_data;
|
|
441
|
+
}
|
|
442
|
+
function _convertToGray(imgdata, width, height) {
|
|
443
|
+
var gray_data = new Array(width * height);
|
|
444
|
+
var i = 0, j = 0, x, y, r, g, b;
|
|
445
|
+
for (y = 0; y < height; y++) {
|
|
446
|
+
for (x = 0; x < width; x++) {
|
|
447
|
+
r = imgdata.data[j++] & 255;
|
|
448
|
+
g = imgdata.data[j++] & 255;
|
|
449
|
+
b = imgdata.data[j++] & 255;
|
|
450
|
+
j++;
|
|
451
|
+
gray_data[i++] = r * 11 + g * 16 + b * 5 >> 5 & 255;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return gray_data;
|
|
455
|
+
}
|
|
456
|
+
EscPosPrinter.prototype.appendImage = function(imgdata, dither) {
|
|
457
|
+
var gray_data, mono_data;
|
|
458
|
+
var w = imgdata.width;
|
|
459
|
+
var h = imgdata.height;
|
|
460
|
+
gray_data = _convertToGray(imgdata, w, h);
|
|
461
|
+
if (dither == "diffuse")
|
|
462
|
+
mono_data = _diffuseDither(gray_data, w, h);
|
|
463
|
+
else
|
|
464
|
+
mono_data = _thresholdDither(gray_data, w, h);
|
|
465
|
+
w = w + 7 >> 3;
|
|
466
|
+
this.orderData += "1d763000";
|
|
467
|
+
this.orderData += _numToHexStr(w, 2);
|
|
468
|
+
this.orderData += _numToHexStr(h, 2);
|
|
469
|
+
for (var i = 0; i < mono_data.length; i++)
|
|
470
|
+
this.orderData += _numToHexStr(mono_data[i] & 255, 1);
|
|
471
|
+
};
|
|
472
|
+
EscPosPrinter.prototype.enterPageMode = function() {
|
|
473
|
+
this.orderData += "1b4c";
|
|
474
|
+
};
|
|
475
|
+
EscPosPrinter.prototype.setPrintAreaInPageMode = function(x, y, w, h) {
|
|
476
|
+
this.orderData += "1b57";
|
|
477
|
+
this.orderData += _numToHexStr(x, 2);
|
|
478
|
+
this.orderData += _numToHexStr(y, 2);
|
|
479
|
+
this.orderData += _numToHexStr(w, 2);
|
|
480
|
+
this.orderData += _numToHexStr(h, 2);
|
|
481
|
+
};
|
|
482
|
+
EscPosPrinter.prototype.setPrintDirectionInPageMode = function(dir) {
|
|
483
|
+
if (dir >= 0 && dir <= 3)
|
|
484
|
+
this.orderData += "1b54" + _numToHexStr(dir, 1);
|
|
485
|
+
};
|
|
486
|
+
EscPosPrinter.prototype.setAbsolutePrintPositionInPageMode = function(n) {
|
|
487
|
+
if (n >= 0 && n <= 65535)
|
|
488
|
+
this.orderData += "1d24" + _numToHexStr(n, 2);
|
|
489
|
+
};
|
|
490
|
+
EscPosPrinter.prototype.setRelativePrintPositionInPageMode = function(n) {
|
|
491
|
+
if (n >= -32768 && n <= 32767)
|
|
492
|
+
this.orderData += "1d5c" + _numToHexStr(n, 2);
|
|
493
|
+
};
|
|
494
|
+
EscPosPrinter.prototype.printAndExitPageMode = function() {
|
|
495
|
+
this.orderData += "0c";
|
|
496
|
+
};
|
|
497
|
+
EscPosPrinter.prototype.printInPageMode = function() {
|
|
498
|
+
this.orderData += "1b0c";
|
|
499
|
+
};
|
|
500
|
+
EscPosPrinter.prototype.clearInPageMode = function() {
|
|
501
|
+
this.orderData += "18";
|
|
502
|
+
};
|
|
503
|
+
EscPosPrinter.prototype.exitPageMode = function() {
|
|
504
|
+
this.orderData += "1b53";
|
|
505
|
+
};
|
|
506
|
+
var EscPosPrinter_default = EscPosPrinter;
|
|
507
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
508
|
+
0 && (module.exports = {
|
|
509
|
+
ALIGN_CENTER,
|
|
510
|
+
ALIGN_LEFT,
|
|
511
|
+
ALIGN_RIGHT,
|
|
512
|
+
HRI_POS_ABOVE,
|
|
513
|
+
HRI_POS_BELOW,
|
|
514
|
+
MAX_COLUMNS,
|
|
515
|
+
columnWidthWithAlignment
|
|
516
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const EscPosPrinter = any;
|
|
2
|
+
export declare const ALIGN_LEFT = number;
|
|
3
|
+
export declare const ALIGN_CENTER = number;
|
|
4
|
+
export declare const ALIGN_RIGHT = number;
|
|
5
|
+
export declare const columnWidthWithAlignment = (
|
|
6
|
+
width: number,
|
|
7
|
+
alignment: number
|
|
8
|
+
) => any;
|
|
9
|
+
export declare const preparing = any;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/escPosPrinter/index.js
|
|
30
|
+
var escPosPrinter_exports = {};
|
|
31
|
+
__export(escPosPrinter_exports, {
|
|
32
|
+
ALIGN_CENTER: () => import_EscPosPrinter.ALIGN_CENTER,
|
|
33
|
+
ALIGN_LEFT: () => import_EscPosPrinter.ALIGN_LEFT,
|
|
34
|
+
ALIGN_RIGHT: () => import_EscPosPrinter.ALIGN_RIGHT,
|
|
35
|
+
EscPosPrinter: () => import_EscPosPrinter.default,
|
|
36
|
+
columnWidthWithAlignment: () => import_EscPosPrinter.columnWidthWithAlignment,
|
|
37
|
+
preparing: () => preparing
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(escPosPrinter_exports);
|
|
40
|
+
var import_EscPosPrinter = __toESM(require("./EscPosPrinter"));
|
|
41
|
+
var dividing = (printer) => {
|
|
42
|
+
printer.setAlignment(import_EscPosPrinter.ALIGN_LEFT);
|
|
43
|
+
printer.appendText("------------------------------------------------\n");
|
|
44
|
+
};
|
|
45
|
+
var preparing = async (ip, sn, params) => {
|
|
46
|
+
const printer = new import_EscPosPrinter.default(576);
|
|
47
|
+
const { title } = params;
|
|
48
|
+
printer.clear();
|
|
49
|
+
printer.lineFeed(1);
|
|
50
|
+
printer.setPrintModes(false, false, false);
|
|
51
|
+
printer.setAlignment(import_EscPosPrinter.ALIGN_CENTER);
|
|
52
|
+
printer.appendText("\u6253\u5370\u6D4B\u8BD5\n");
|
|
53
|
+
dividing(printer);
|
|
54
|
+
printer.setAlignment(import_EscPosPrinter.ALIGN_LEFT);
|
|
55
|
+
printer.appendText("Order time: 2023-10-19 14:15:50\n");
|
|
56
|
+
printer.appendText("Order number\n");
|
|
57
|
+
printer.appendText("D3012");
|
|
58
|
+
dividing(printer);
|
|
59
|
+
printer.setColumnWidths(
|
|
60
|
+
(0, import_EscPosPrinter.columnWidthWithAlignment)(150, import_EscPosPrinter.ALIGN_LEFT),
|
|
61
|
+
(0, import_EscPosPrinter.columnWidthWithAlignment)(426, import_EscPosPrinter.ALIGN_LEFT)
|
|
62
|
+
);
|
|
63
|
+
printer.printInColumns("Number", "Name");
|
|
64
|
+
printer.setPrintModes(true, true, true);
|
|
65
|
+
printer.printInColumns(
|
|
66
|
+
"1 x",
|
|
67
|
+
"\u6211\u662F\u5F88\u957F\u7684\u5546\u54C1\u540D\u79F0\u6211\u662F\u5F88\u957F\u7684\u5546\u54C1\u540D\u79F0\u6211\u662F\u5F88\u957F\u7684\u5546\u54C1\u540D\u79F0\u6211\u662F\u5F88\u957F\u7684\u5546\u54C1\u540D\u79F0"
|
|
68
|
+
);
|
|
69
|
+
printer.setPrintModes(false, false, false);
|
|
70
|
+
dividing(printer);
|
|
71
|
+
printer.lineFeed(4);
|
|
72
|
+
printer.cutPaper(false);
|
|
73
|
+
printer.printAndExitPageMode();
|
|
74
|
+
const result = await printer.print(ip, sn, 1);
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
ALIGN_CENTER,
|
|
80
|
+
ALIGN_LEFT,
|
|
81
|
+
ALIGN_RIGHT,
|
|
82
|
+
EscPosPrinter,
|
|
83
|
+
columnWidthWithAlignment,
|
|
84
|
+
preparing
|
|
85
|
+
});
|
package/lib/firebase/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { FirebaseApp } from 'firebase/app';
|
|
2
|
+
declare let firebaseApp: FirebaseApp;
|
|
2
3
|
export { firebaseApp };
|
|
3
4
|
export declare const getPath: (path: string) => string;
|
|
4
5
|
export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
|
package/lib/firebase/index.js
CHANGED
|
@@ -46,9 +46,15 @@ var import_app = require("firebase/app");
|
|
|
46
46
|
var import_auth = require("firebase/auth");
|
|
47
47
|
var import_database = require("firebase/database");
|
|
48
48
|
var import_config = __toESM(require("./config"));
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
49
|
+
var isClient = typeof window != "undefined" && window.document;
|
|
50
|
+
var firebaseApp = {};
|
|
51
|
+
var auth = {};
|
|
52
|
+
var database = {};
|
|
53
|
+
if (isClient && window.__wxjs_environment !== "miniprogram") {
|
|
54
|
+
firebaseApp = (0, import_app.initializeApp)(import_config.default);
|
|
55
|
+
auth = (0, import_auth.getAuth)(firebaseApp);
|
|
56
|
+
database = (0, import_database.getDatabase)(firebaseApp);
|
|
57
|
+
}
|
|
52
58
|
var getPath = (path) => {
|
|
53
59
|
return path;
|
|
54
60
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./otherUtils";
|
|
2
|
+
export * from "./typeUtils";
|
|
3
|
+
export * from "./document";
|
|
4
|
+
export * from "./date";
|
|
5
|
+
export * from "./platform";
|
|
6
|
+
export * from "./log";
|
|
7
|
+
export * from "./format";
|
|
8
|
+
export * from "./escPosPrinter";
|
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __reExport(src_exports, require("./date"), module.exports);
|
|
|
23
23
|
__reExport(src_exports, require("./platform"), module.exports);
|
|
24
24
|
__reExport(src_exports, require("./log"), module.exports);
|
|
25
25
|
__reExport(src_exports, require("./format"), module.exports);
|
|
26
|
+
__reExport(src_exports, require("./escPosPrinter"), module.exports);
|
|
26
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
28
|
0 && (module.exports = {
|
|
28
29
|
...require("./otherUtils"),
|
|
@@ -31,5 +32,6 @@ __reExport(src_exports, require("./format"), module.exports);
|
|
|
31
32
|
...require("./date"),
|
|
32
33
|
...require("./platform"),
|
|
33
34
|
...require("./log"),
|
|
34
|
-
...require("./format")
|
|
35
|
+
...require("./format"),
|
|
36
|
+
...require("./escPosPrinter")
|
|
35
37
|
});
|