@pisell/utils 3.0.6 → 3.0.7
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/arrayUtils.d.ts +23 -26
- package/es/arrayUtils.js +157 -97
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +5 -0
- package/es/common/stateHelper.d.ts +2 -6
- package/es/common/stateHelper.js +24 -22
- package/es/common/types.d.ts +10 -13
- package/es/common/types.js +1 -0
- package/es/componentStorage.d.ts +25 -27
- package/es/componentStorage.js +130 -94
- package/es/constants/index.js +9 -7
- package/es/date.js +53 -36
- package/es/document.js +67 -43
- package/es/escPosPrinter/EscPosPrinter.js +490 -353
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +52 -37
- package/es/firebase/config/index.js +54 -0
- package/es/firebase/index.js +232 -0
- package/es/format.d.ts +15 -12
- package/es/format.js +156 -89
- package/es/image.js +60 -48
- package/es/index.d.ts +24 -39
- package/es/index.js +35 -40
- package/es/jsBridge/index.d.ts +4 -8
- package/es/jsBridge/index.js +55 -56
- package/es/jsBridge/regDeviceApi.js +126 -87
- package/es/jsBridge/types.d.ts +115 -95
- package/es/jsBridge/types.js +1 -0
- package/es/locales.d.ts +8 -11
- package/es/locales.js +96 -77
- package/es/log.d.ts +6 -11
- package/es/log.js +59 -37
- package/es/miniRedux.d.ts +13 -20
- package/es/miniRedux.js +76 -42
- package/es/number-input/hooks/index.d.ts +4 -0
- package/es/number-input/hooks/index.js +5 -0
- package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
- package/es/number-input/hooks/useNumberInputState.js +128 -71
- package/es/number-input/index.d.ts +14 -0
- package/es/number-input/index.js +21 -0
- package/es/number-input/types.d.ts +88 -88
- package/es/number-input/types.js +1 -0
- package/es/number-input/utils/formatter.d.ts +10 -13
- package/es/number-input/utils/formatter.js +77 -51
- package/es/number-input/utils/index.d.ts +7 -0
- package/es/number-input/utils/index.js +8 -0
- package/es/number-input/utils/validation.d.ts +2 -7
- package/es/number-input/utils/validation.js +66 -51
- package/es/otherUtils.d.ts +9 -12
- package/es/otherUtils.js +129 -71
- package/es/platform.d.ts +9 -12
- package/es/platform.js +85 -61
- package/es/select/hooks/index.d.ts +5 -0
- package/es/select/hooks/index.js +6 -0
- package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
- package/es/select/hooks/useDebouncedSearch.js +53 -39
- package/es/select/hooks/useSelectState.d.ts +7 -7
- package/es/select/hooks/useSelectState.js +113 -56
- package/es/select/index.d.ts +8 -7
- package/es/select/index.js +13 -0
- package/es/select/types.d.ts +211 -211
- package/es/select/types.js +1 -0
- package/es/select/utils/filterOptions.d.ts +6 -7
- package/es/select/utils/filterOptions.js +31 -26
- package/es/select/utils/helpers.d.ts +9 -10
- package/es/select/utils/helpers.js +52 -42
- package/es/select/utils/index.d.ts +7 -4
- package/es/select/utils/index.js +8 -0
- package/es/select/utils/sortOptions.d.ts +5 -6
- package/es/select/utils/sortOptions.js +31 -19
- package/es/select/utils/tagAggregation.d.ts +6 -6
- package/es/select/utils/tagAggregation.js +47 -34
- package/es/text-input/hooks/index.d.ts +4 -0
- package/es/text-input/hooks/index.js +5 -0
- package/es/text-input/hooks/useTextInputState.d.ts +2 -6
- package/es/text-input/hooks/useTextInputState.js +126 -69
- package/es/text-input/index.d.ts +14 -0
- package/es/text-input/index.js +20 -0
- package/es/text-input/types.d.ts +48 -48
- package/es/text-input/types.js +1 -0
- package/es/text-input/utils/index.d.ts +5 -0
- package/es/text-input/utils/index.js +7 -0
- package/es/text-input/utils/validation.d.ts +2 -7
- package/es/text-input/utils/validation.js +70 -50
- package/es/typeUtils.js +84 -61
- package/es/walletValidity.d.ts +42 -44
- package/es/walletValidity.js +557 -396
- package/es/weighing.d.ts +45 -48
- package/es/weighing.js +106 -83
- package/lib/arrayUtils.d.ts +23 -26
- package/lib/arrayUtils.js +111 -101
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +29 -0
- package/lib/common/stateHelper.d.ts +2 -6
- package/lib/common/stateHelper.js +32 -21
- package/lib/common/types.d.ts +10 -13
- package/lib/common/types.js +17 -0
- package/lib/componentStorage.d.ts +25 -27
- package/lib/componentStorage.js +126 -96
- package/lib/constants/index.js +36 -7
- package/lib/date.js +65 -43
- package/lib/document.js +62 -46
- package/lib/escPosPrinter/EscPosPrinter.js +403 -327
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +84 -38
- package/lib/firebase/config/index.js +79 -0
- package/lib/firebase/index.js +180 -0
- package/lib/format.d.ts +15 -12
- package/lib/format.js +133 -91
- package/lib/image.js +74 -48
- package/lib/index.d.ts +24 -39
- package/lib/index.js +80 -137
- package/lib/jsBridge/index.d.ts +4 -8
- package/lib/jsBridge/index.js +76 -57
- package/lib/jsBridge/regDeviceApi.js +133 -86
- package/lib/jsBridge/types.d.ts +115 -95
- package/lib/jsBridge/types.js +17 -0
- package/lib/locales.d.ts +8 -11
- package/lib/locales.js +90 -79
- package/lib/log.d.ts +6 -11
- package/lib/log.js +61 -37
- package/lib/miniRedux.d.ts +13 -20
- package/lib/miniRedux.js +89 -43
- package/lib/number-input/hooks/index.d.ts +4 -0
- package/lib/number-input/hooks/index.js +29 -0
- package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
- package/lib/number-input/hooks/useNumberInputState.js +81 -71
- package/lib/number-input/index.d.ts +14 -0
- package/lib/number-input/index.js +41 -0
- package/lib/number-input/types.d.ts +88 -88
- package/lib/number-input/types.js +17 -0
- package/lib/number-input/utils/formatter.d.ts +10 -13
- package/lib/number-input/utils/formatter.js +49 -52
- package/lib/number-input/utils/index.d.ts +7 -0
- package/lib/number-input/utils/index.js +39 -0
- package/lib/number-input/utils/validation.d.ts +2 -7
- package/lib/number-input/utils/validation.js +52 -50
- package/lib/otherUtils.d.ts +9 -12
- package/lib/otherUtils.js +98 -86
- package/lib/platform.d.ts +9 -12
- package/lib/platform.js +123 -68
- package/lib/select/hooks/index.d.ts +5 -0
- package/lib/select/hooks/index.js +34 -0
- package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
- package/lib/select/hooks/useDebouncedSearch.js +41 -40
- package/lib/select/hooks/useSelectState.d.ts +7 -7
- package/lib/select/hooks/useSelectState.js +93 -58
- package/lib/select/index.d.ts +8 -7
- package/lib/select/index.js +53 -0
- package/lib/select/types.d.ts +211 -211
- package/lib/select/types.js +17 -0
- package/lib/select/utils/filterOptions.d.ts +6 -7
- package/lib/select/utils/filterOptions.js +37 -26
- package/lib/select/utils/helpers.d.ts +9 -10
- package/lib/select/utils/helpers.js +41 -45
- package/lib/select/utils/index.d.ts +7 -4
- package/lib/select/utils/index.js +48 -0
- package/lib/select/utils/sortOptions.d.ts +5 -6
- package/lib/select/utils/sortOptions.js +39 -18
- package/lib/select/utils/tagAggregation.d.ts +6 -6
- package/lib/select/utils/tagAggregation.js +41 -33
- package/lib/text-input/hooks/index.d.ts +4 -0
- package/lib/text-input/hooks/index.js +29 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
- package/lib/text-input/hooks/useTextInputState.js +79 -69
- package/lib/text-input/index.d.ts +14 -0
- package/lib/text-input/index.js +35 -0
- package/lib/text-input/types.d.ts +48 -48
- package/lib/text-input/types.js +17 -0
- package/lib/text-input/utils/index.d.ts +5 -0
- package/lib/text-input/utils/index.js +32 -0
- package/lib/text-input/utils/validation.d.ts +2 -7
- package/lib/text-input/utils/validation.js +58 -49
- package/lib/typeUtils.js +73 -68
- package/lib/walletValidity.d.ts +42 -44
- package/lib/walletValidity.js +393 -410
- package/lib/weighing.d.ts +45 -48
- package/lib/weighing.js +149 -104
- package/package.json +1 -1
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
- package/es/date.d.ts +0 -31
- package/es/document.d.ts +0 -16
- package/es/image.d.ts +0 -14
- package/es/typeUtils.d.ts +0 -45
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
- package/lib/_virtual/_rolldown/runtime.js +0 -23
- package/lib/date.d.ts +0 -31
- package/lib/document.d.ts +0 -16
- package/lib/image.d.ts +0 -14
- package/lib/typeUtils.d.ts +0 -45
|
@@ -1,401 +1,538 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
// Maximum columns for printing in columns function
|
|
2
|
+
export var MAX_COLUMNS = 6;
|
|
3
|
+
|
|
4
|
+
// Left alignment
|
|
5
|
+
export var ALIGN_LEFT = 0;
|
|
6
|
+
// Center alignment
|
|
7
|
+
export var ALIGN_CENTER = 1;
|
|
8
|
+
// Right alignment
|
|
9
|
+
export var ALIGN_RIGHT = 2;
|
|
10
|
+
|
|
11
|
+
// HRI above the barcode
|
|
12
|
+
export var HRI_POS_ABOVE = 1;
|
|
13
|
+
// HRI below the barcode
|
|
14
|
+
export var HRI_POS_BELOW = 2;
|
|
15
|
+
var EscPosPrinter = function EscPosPrinter(dotsPerLine) {
|
|
16
|
+
if (dotsPerLine != 384 && dotsPerLine != 576)
|
|
17
|
+
// Print width in dots. 384 for 58mm and 576 for 80mm
|
|
18
|
+
dotsPerLine = 384;
|
|
19
|
+
this.widthOfColumns = new Array(MAX_COLUMNS);
|
|
20
|
+
this.dotsPerLine = dotsPerLine;
|
|
21
|
+
this.charHSize = 1;
|
|
22
|
+
this.orderData = "";
|
|
10
23
|
};
|
|
11
24
|
function _numToHexStr(n, bytes) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return str;
|
|
25
|
+
var str = "";
|
|
26
|
+
var v;
|
|
27
|
+
for (var i = 0; i < bytes; i++) {
|
|
28
|
+
v = n & 0xff;
|
|
29
|
+
if (v < 0x10) str += "0" + v.toString(16);else str += v.toString(16);
|
|
30
|
+
n >>= 8;
|
|
31
|
+
}
|
|
32
|
+
return str;
|
|
21
33
|
}
|
|
22
34
|
function _unicodeToUtf8(unicode) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
var c1, c2, c3, c4;
|
|
36
|
+
if (unicode < 0) return "";
|
|
37
|
+
if (unicode <= 0x7f) {
|
|
38
|
+
c1 = unicode & 0x7f;
|
|
39
|
+
return _numToHexStr(c1, 1);
|
|
40
|
+
}
|
|
41
|
+
if (unicode <= 0x7ff) {
|
|
42
|
+
c1 = unicode >> 6 & 0x1f | 0xc0;
|
|
43
|
+
c2 = unicode & 0x3f | 0x80;
|
|
44
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1);
|
|
45
|
+
}
|
|
46
|
+
if (unicode <= 0xffff) {
|
|
47
|
+
c1 = unicode >> 12 & 0x0f | 0xe0;
|
|
48
|
+
c2 = unicode >> 6 & 0x3f | 0x80;
|
|
49
|
+
c3 = unicode & 0x3f | 0x80;
|
|
50
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1);
|
|
51
|
+
}
|
|
52
|
+
if (unicode <= 0x10ffff) {
|
|
53
|
+
c1 = unicode >> 18 & 0x07 | 0xf0;
|
|
54
|
+
c2 = unicode >> 12 & 0x3f | 0x80;
|
|
55
|
+
c3 = unicode >> 6 & 0x3f | 0x80;
|
|
56
|
+
c4 = unicode & 0x3f | 0x80;
|
|
57
|
+
return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1) + _numToHexStr(c4, 1);
|
|
58
|
+
}
|
|
59
|
+
return "";
|
|
48
60
|
}
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
|
|
62
|
+
// Clear the generated order data.
|
|
63
|
+
EscPosPrinter.prototype.clear = function () {
|
|
64
|
+
this.orderData = "";
|
|
51
65
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
// Print the order data.
|
|
68
|
+
EscPosPrinter.prototype.print = function (host, sn, copies) {
|
|
69
|
+
var that = this;
|
|
70
|
+
return new Promise(function (resolve, reject) {
|
|
71
|
+
var xmlobj = new XMLHttpRequest();
|
|
72
|
+
xmlobj.timeout = 10000;
|
|
73
|
+
var url = "https://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
|
|
74
|
+
xmlobj.open("POST", url, true);
|
|
75
|
+
xmlobj.onreadystatechange = function () {
|
|
76
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
77
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
78
|
+
var re = /task_id: (\d+)/;
|
|
79
|
+
var matches = re.exec(xmlobj.responseText);
|
|
80
|
+
resolve(matches[1] || "");
|
|
81
|
+
} else {
|
|
82
|
+
reject(xmlobj.responseText);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
87
|
+
xmlobj.send(that.orderData);
|
|
88
|
+
});
|
|
66
89
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
|
|
91
|
+
// Query print status.
|
|
92
|
+
EscPosPrinter.prototype.queryStatus = function (host, sn, task_id) {
|
|
93
|
+
return new Promise(function (resolve, reject) {
|
|
94
|
+
var xmlobj = new XMLHttpRequest();
|
|
95
|
+
xmlobj.timeout = 10000;
|
|
96
|
+
var url = "https://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
|
|
97
|
+
xmlobj.open("POST", url, true);
|
|
98
|
+
xmlobj.onreadystatechange = function () {
|
|
99
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
100
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
101
|
+
resolve(xmlobj.responseText);
|
|
102
|
+
} else {
|
|
103
|
+
reject(xmlobj.responseText);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
108
|
+
xmlobj.send();
|
|
109
|
+
});
|
|
80
110
|
};
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
|
|
112
|
+
//////////////////////////////////////////////////
|
|
113
|
+
// Basic ESC/POS Commands
|
|
114
|
+
//////////////////////////////////////////////////
|
|
115
|
+
|
|
116
|
+
// Append text in the order.
|
|
117
|
+
EscPosPrinter.prototype.appendText = function (str) {
|
|
118
|
+
for (var i = 0; i < str.length; i++) this.orderData += _unicodeToUtf8(str.charCodeAt(i));
|
|
83
119
|
};
|
|
84
|
-
|
|
85
|
-
|
|
120
|
+
|
|
121
|
+
// [LF] Print the contents in the buffer and feed n lines.
|
|
122
|
+
EscPosPrinter.prototype.lineFeed = function (n) {
|
|
123
|
+
for (var i = 0; i < n; i++) this.orderData += "0a";
|
|
86
124
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
125
|
+
|
|
126
|
+
// [ESC @] Restore default settings (line spacing, print modes, etc).
|
|
127
|
+
EscPosPrinter.prototype.restoreDefaultSettings = function () {
|
|
128
|
+
this.charHSize = 1;
|
|
129
|
+
this.orderData += "1b40";
|
|
90
130
|
};
|
|
91
|
-
|
|
92
|
-
|
|
131
|
+
|
|
132
|
+
// [ESC 2] Restore default line spacing.
|
|
133
|
+
EscPosPrinter.prototype.restoreDefaultLineSpacing = function () {
|
|
134
|
+
this.orderData += "1b32";
|
|
93
135
|
};
|
|
94
|
-
|
|
95
|
-
|
|
136
|
+
|
|
137
|
+
// [ESC 3] Set line spacing.
|
|
138
|
+
EscPosPrinter.prototype.setLineSpacing = function (n) {
|
|
139
|
+
if (n >= 0 && n <= 255) this.orderData += "1b33" + _numToHexStr(n, 1);
|
|
96
140
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
141
|
+
|
|
142
|
+
// [ESC !] Select print modes (double width/height or not, bold or not).
|
|
143
|
+
EscPosPrinter.prototype.setPrintModes = function (bold, double_h, double_w) {
|
|
144
|
+
var n = 0;
|
|
145
|
+
if (bold) n |= 8;
|
|
146
|
+
if (double_h) n |= 16;
|
|
147
|
+
if (double_w) n |= 32;
|
|
148
|
+
this.charHSize = double_w ? 2 : 1;
|
|
149
|
+
this.orderData += "1b21" + _numToHexStr(n, 1);
|
|
104
150
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
151
|
+
|
|
152
|
+
// [GS !] Set character size (1~8 times of normal width or height).
|
|
153
|
+
EscPosPrinter.prototype.setCharacterSize = function (h, w) {
|
|
154
|
+
var n = 0;
|
|
155
|
+
if (h >= 1 && h <= 8) n |= h - 1;
|
|
156
|
+
if (w >= 1 && w <= 8) {
|
|
157
|
+
n |= w - 1 << 4;
|
|
158
|
+
this.charHSize = w;
|
|
159
|
+
}
|
|
160
|
+
this.orderData += "1d21" + _numToHexStr(n, 1);
|
|
113
161
|
};
|
|
114
|
-
|
|
115
|
-
|
|
162
|
+
|
|
163
|
+
// [HT] Jump to the next n TAB positions.
|
|
164
|
+
EscPosPrinter.prototype.horizontalTab = function (n) {
|
|
165
|
+
for (var i = 0; i < n; i++) this.orderData += "09";
|
|
116
166
|
};
|
|
117
|
-
|
|
118
|
-
|
|
167
|
+
|
|
168
|
+
// [ESC $] Move to horizontal absolute position.
|
|
169
|
+
EscPosPrinter.prototype.setAbsolutePrintPosition = function (n) {
|
|
170
|
+
if (n >= 0 && n <= 65535) this.orderData += "1b24" + _numToHexStr(n, 2);
|
|
119
171
|
};
|
|
120
|
-
|
|
121
|
-
|
|
172
|
+
|
|
173
|
+
// [ESC \] Move to horizontal relative position.
|
|
174
|
+
EscPosPrinter.prototype.setRelativePrintPosition = function (n) {
|
|
175
|
+
if (n >= -32768 && n <= 32767) this.orderData += "1b5c" + _numToHexStr(n, 2);
|
|
122
176
|
};
|
|
123
|
-
|
|
124
|
-
|
|
177
|
+
|
|
178
|
+
// [ESC a] Set alignment.
|
|
179
|
+
EscPosPrinter.prototype.setAlignment = function (n) {
|
|
180
|
+
if (n >= 0 && n <= 2) this.orderData += "1b61" + _numToHexStr(n, 1);
|
|
125
181
|
};
|
|
126
|
-
|
|
127
|
-
|
|
182
|
+
|
|
183
|
+
// [GS V m] Cut paper.
|
|
184
|
+
EscPosPrinter.prototype.cutPaper = function (fullCut) {
|
|
185
|
+
this.orderData += "1d56" + (fullCut ? "30" : "31");
|
|
128
186
|
};
|
|
129
|
-
|
|
130
|
-
|
|
187
|
+
|
|
188
|
+
// [GS V m n] Postponed cut paper.
|
|
189
|
+
// After sending this command, the cutter will not cut until (76+n) dot lines are fed.
|
|
190
|
+
EscPosPrinter.prototype.postponedCutPaper = function (fullCut, n) {
|
|
191
|
+
if (n >= 0 && n <= 255) this.orderData += "1d56" + (fullCut ? "61" : "62") + _numToHexStr(n, 1);
|
|
131
192
|
};
|
|
193
|
+
|
|
194
|
+
//////////////////////////////////////////////////
|
|
195
|
+
// Print in Columns
|
|
196
|
+
//////////////////////////////////////////////////
|
|
197
|
+
|
|
198
|
+
// Return the width of a character.
|
|
132
199
|
function _widthOfChar(c) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
200
|
+
if (c >= 0x00020 && c <= 0x0036f || c >= 0x0ff61 && c <= 0x0ff9f) return 12;
|
|
201
|
+
if (c == 0x02010 || c >= 0x02013 && c <= 0x02016 || c >= 0x02018 && c <= 0x02019 || c >= 0x0201c && c <= 0x0201d || c >= 0x02025 && c <= 0x02026 || c >= 0x02030 && c <= 0x02033 || c == 0x02035 || c == 0x0203b) return 24;
|
|
202
|
+
if (c >= 0x01100 && c <= 0x011ff || c >= 0x02460 && c <= 0x024ff || c >= 0x025a0 && c <= 0x027bf || c >= 0x02e80 && c <= 0x02fdf || c >= 0x03000 && c <= 0x0318f || c >= 0x031a0 && c <= 0x031ef || c >= 0x03200 && c <= 0x09fff || c >= 0x0ac00 && c <= 0x0d7ff || c >= 0x0f900 && c <= 0x0faff || c >= 0x0fe30 && c <= 0x0fe4f || c >= 0x1f000 && c <= 0x1f9ff) return 24;
|
|
203
|
+
if (c >= 0x0ff01 && c <= 0x0ff5e || c >= 0x0ffe0 && c <= 0x0ffe5) return 24;
|
|
204
|
+
return 0;
|
|
138
205
|
}
|
|
139
|
-
function columnWidthWithAlignment(width, alignment) {
|
|
140
|
-
|
|
206
|
+
export function columnWidthWithAlignment(width, alignment) {
|
|
207
|
+
return width & 0xffff | (alignment & 3) << 16;
|
|
141
208
|
}
|
|
142
209
|
function _columnWidth(v) {
|
|
143
|
-
|
|
210
|
+
return v & 0xffff;
|
|
144
211
|
}
|
|
145
212
|
function _columnAlignment(v) {
|
|
146
|
-
|
|
213
|
+
return v >> 16 & 3;
|
|
147
214
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
215
|
+
|
|
216
|
+
// Set the width and alignment mode for each columns.
|
|
217
|
+
EscPosPrinter.prototype.setColumnWidths = function /*...*/
|
|
218
|
+
() {
|
|
219
|
+
var i, remain, width, alignment;
|
|
220
|
+
if (arguments.length == 0) return;
|
|
221
|
+
for (i = 0; i < MAX_COLUMNS; i++) this.widthOfColumns[i] = 0;
|
|
222
|
+
remain = this.dotsPerLine; // Dots not used
|
|
223
|
+
for (i = 0; i < arguments.length; i++) {
|
|
224
|
+
if (i == MAX_COLUMNS)
|
|
225
|
+
// Maximum columns exceeded
|
|
226
|
+
return;
|
|
227
|
+
width = _columnWidth(arguments[i]);
|
|
228
|
+
alignment = _columnAlignment(arguments[i]);
|
|
229
|
+
if (width == 0 || width > remain) {
|
|
230
|
+
// Use all free dots for the last column
|
|
231
|
+
this.widthOfColumns[i] = columnWidthWithAlignment(remain, alignment);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.widthOfColumns[i] = arguments[i];
|
|
235
|
+
remain -= width;
|
|
236
|
+
}
|
|
164
237
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
238
|
+
|
|
239
|
+
// Print in columns with the current column settings.
|
|
240
|
+
EscPosPrinter.prototype.printInColumns = function /*...*/
|
|
241
|
+
() {
|
|
242
|
+
var strcurr = new Array(MAX_COLUMNS);
|
|
243
|
+
var strrem = new Array(MAX_COLUMNS);
|
|
244
|
+
var strwidth = new Array(MAX_COLUMNS);
|
|
245
|
+
var i, j, c, w, columns, width, alignment, pos;
|
|
246
|
+
var done;
|
|
247
|
+
if (arguments.length == 0) return;
|
|
248
|
+
columns = 0;
|
|
249
|
+
for (i = 0; i < arguments.length; i++) {
|
|
250
|
+
if (i == MAX_COLUMNS || this.widthOfColumns[i] == 0) break;
|
|
251
|
+
strcurr[i] = "";
|
|
252
|
+
strrem[i] = arguments[i];
|
|
253
|
+
columns++;
|
|
254
|
+
}
|
|
255
|
+
do {
|
|
256
|
+
done = true;
|
|
257
|
+
pos = 0;
|
|
258
|
+
for (i = 0; i < columns; i++) {
|
|
259
|
+
width = _columnWidth(this.widthOfColumns[i]);
|
|
260
|
+
if (strrem[i].length == 0) {
|
|
261
|
+
pos += width;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
done = false;
|
|
265
|
+
strcurr[i] = "";
|
|
266
|
+
strwidth[i] = 0;
|
|
267
|
+
for (j = 0; j < strrem[i].length; j++) {
|
|
268
|
+
c = strrem[i].charCodeAt(j);
|
|
269
|
+
if (c == 0x0a) {
|
|
270
|
+
j++; // Drop the '\n'
|
|
271
|
+
break;
|
|
272
|
+
} else {
|
|
273
|
+
w = _widthOfChar(c);
|
|
274
|
+
if (w == 0) {
|
|
275
|
+
c = "?";
|
|
276
|
+
w = 12;
|
|
277
|
+
}
|
|
278
|
+
w *= this.charHSize;
|
|
279
|
+
if (strwidth[i] + w > width) {
|
|
280
|
+
break;
|
|
281
|
+
} else {
|
|
282
|
+
strcurr[i] += String.fromCharCode(c);
|
|
283
|
+
strwidth[i] += w;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (j < strrem[i].length) strrem[i] = strrem[i].substring(j);else strrem[i] = "";
|
|
288
|
+
alignment = _columnAlignment(this.widthOfColumns[i]);
|
|
289
|
+
switch (alignment) {
|
|
290
|
+
case ALIGN_CENTER:
|
|
291
|
+
this.setAbsolutePrintPosition(pos + (width - strwidth[i]) / 2);
|
|
292
|
+
break;
|
|
293
|
+
case ALIGN_RIGHT:
|
|
294
|
+
this.setAbsolutePrintPosition(pos + (width - strwidth[i]));
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
this.setAbsolutePrintPosition(pos);
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
this.appendText(strcurr[i]);
|
|
301
|
+
pos += width;
|
|
302
|
+
}
|
|
303
|
+
if (!done) this.lineFeed(1);
|
|
304
|
+
} while (!done);
|
|
229
305
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
306
|
+
|
|
307
|
+
//////////////////////////////////////////////////
|
|
308
|
+
// Barcode / QR Code Printing
|
|
309
|
+
//////////////////////////////////////////////////
|
|
310
|
+
|
|
311
|
+
// Append barcode in the order.
|
|
312
|
+
EscPosPrinter.prototype.appendBarcode = function (hri_pos, height, module_size, barcode_type, text) {
|
|
313
|
+
var text_length = text.length;
|
|
314
|
+
if (text_length == 0) return;
|
|
315
|
+
if (text_length > 255) text_length = 255;
|
|
316
|
+
if (height < 1) height = 1;else if (height > 255) height = 255;
|
|
317
|
+
if (module_size < 1) module_size = 1;else if (module_size > 6) module_size = 6;
|
|
318
|
+
this.orderData += "1d48" + _numToHexStr(hri_pos & 3, 1);
|
|
319
|
+
this.orderData += "1d6600";
|
|
320
|
+
this.orderData += "1d68" + _numToHexStr(height, 1);
|
|
321
|
+
this.orderData += "1d77" + _numToHexStr(module_size, 1);
|
|
322
|
+
this.orderData += "1d6b" + _numToHexStr(barcode_type, 1) + _numToHexStr(text_length, 1);
|
|
323
|
+
for (var i = 0; i < text_length; i++) this.orderData += _numToHexStr(text.charCodeAt(i), 1);
|
|
244
324
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
325
|
+
|
|
326
|
+
// Append QR code in the order.
|
|
327
|
+
EscPosPrinter.prototype.appendQRcode = function (module_size, ec_level, text) {
|
|
328
|
+
var text_length = text.length;
|
|
329
|
+
if (text_length == 0) return;
|
|
330
|
+
if (text_length > 65535) text_length = 65535;
|
|
331
|
+
if (module_size < 1) module_size = 1;else if (module_size > 16) module_size = 16;
|
|
332
|
+
if (ec_level < 0) ec_level = 0;else if (ec_level > 3) 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++) this.orderData += _numToHexStr(text.charCodeAt(i), 1);
|
|
338
|
+
this.orderData += "1d286b0300315130";
|
|
259
339
|
};
|
|
340
|
+
|
|
341
|
+
//////////////////////////////////////////////////
|
|
342
|
+
// Image Printing
|
|
343
|
+
//////////////////////////////////////////////////
|
|
344
|
+
|
|
345
|
+
// Grayscale to mono - diffuse dithering.
|
|
260
346
|
function _diffuseDither(src_data, width, height) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
347
|
+
if (width <= 0 || height <= 0) return null;
|
|
348
|
+
if (src_data.length < width * height) return null;
|
|
349
|
+
var bmwidth = width + 7 >> 3;
|
|
350
|
+
var dst_data = new Array(bmwidth * height);
|
|
351
|
+
var line_buffer = new Array(2 * width);
|
|
352
|
+
var i, p, q, x, y, mask;
|
|
353
|
+
var line1, line2, b1, b2, tmp;
|
|
354
|
+
var err, e1, e3, e5, e7;
|
|
355
|
+
var not_last_line;
|
|
356
|
+
line1 = 0;
|
|
357
|
+
line2 = 1;
|
|
358
|
+
for (i = 0; i < width; i++) {
|
|
359
|
+
line_buffer[i] = 0;
|
|
360
|
+
line_buffer[width + i] = src_data[i];
|
|
361
|
+
}
|
|
362
|
+
for (y = 0; y < height; y++) {
|
|
363
|
+
tmp = line1;
|
|
364
|
+
line1 = line2;
|
|
365
|
+
line2 = tmp;
|
|
366
|
+
not_last_line = y < height - 1;
|
|
367
|
+
if (not_last_line) {
|
|
368
|
+
p = (y + 1) * width;
|
|
369
|
+
for (i = 0; i < width; i++) {
|
|
370
|
+
line_buffer[line2 * width + i] = src_data[p];
|
|
371
|
+
p++;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
q = y * bmwidth;
|
|
375
|
+
for (i = 0; i < bmwidth; i++) {
|
|
376
|
+
dst_data[q] = 0;
|
|
377
|
+
q++;
|
|
378
|
+
}
|
|
379
|
+
b1 = 0;
|
|
380
|
+
b2 = 0;
|
|
381
|
+
q = y * bmwidth;
|
|
382
|
+
mask = 0x80;
|
|
383
|
+
for (x = 1; x <= width; x++) {
|
|
384
|
+
var idx = line1 * width + b1;
|
|
385
|
+
if (line_buffer[idx] < 128) {
|
|
386
|
+
// Black pixel
|
|
387
|
+
err = line_buffer[idx];
|
|
388
|
+
dst_data[q] |= mask;
|
|
389
|
+
} else {
|
|
390
|
+
err = line_buffer[idx] - 255;
|
|
391
|
+
}
|
|
392
|
+
b1++;
|
|
393
|
+
if (mask == 1) {
|
|
394
|
+
q++;
|
|
395
|
+
mask = 0x80;
|
|
396
|
+
} else {
|
|
397
|
+
mask >>= 1;
|
|
398
|
+
}
|
|
399
|
+
e7 = err * 7 + 8 >> 4;
|
|
400
|
+
e5 = err * 5 + 8 >> 4;
|
|
401
|
+
e3 = err * 3 + 8 >> 4;
|
|
402
|
+
e1 = err - (e7 + e5 + e3);
|
|
403
|
+
if (x < width) line_buffer[line1 * width + b1] += e7;
|
|
404
|
+
if (not_last_line) {
|
|
405
|
+
line_buffer[line2 * width + b2] += e5;
|
|
406
|
+
if (x > 1) line_buffer[line2 * width + b2 - 1] += e3;
|
|
407
|
+
if (x < width) line_buffer[line2 * width + b2 + 1] += e1;
|
|
408
|
+
}
|
|
409
|
+
b2++;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return dst_data;
|
|
322
413
|
}
|
|
414
|
+
|
|
415
|
+
// Grayscale to mono - threshold dithering.
|
|
323
416
|
function _thresholdDither(src_data, width, height) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
417
|
+
if (width <= 0 || height <= 0) return null;
|
|
418
|
+
if (src_data.length < width * height) return null;
|
|
419
|
+
var bmwidth = width + 7 >> 3;
|
|
420
|
+
var dst_data = new Array(bmwidth * height);
|
|
421
|
+
var p, q, k, x, y, mask;
|
|
422
|
+
p = 0;
|
|
423
|
+
q = 0;
|
|
424
|
+
for (y = 0; y < height; y++) {
|
|
425
|
+
k = q;
|
|
426
|
+
mask = 0x80;
|
|
427
|
+
for (x = 0; x < width; x++) {
|
|
428
|
+
if (src_data[p] < 128) {
|
|
429
|
+
// Black pixel
|
|
430
|
+
dst_data[k] |= mask;
|
|
431
|
+
}
|
|
432
|
+
p++;
|
|
433
|
+
if (mask == 1) {
|
|
434
|
+
k++;
|
|
435
|
+
mask = 0x80;
|
|
436
|
+
} else {
|
|
437
|
+
mask >>= 1;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
q += bmwidth;
|
|
441
|
+
}
|
|
442
|
+
return dst_data;
|
|
343
443
|
}
|
|
444
|
+
|
|
445
|
+
// RGB to grayscale.
|
|
344
446
|
function _convertToGray(imgdata, width, height) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
447
|
+
var gray_data = new Array(width * height);
|
|
448
|
+
var i = 0,
|
|
449
|
+
j = 0,
|
|
450
|
+
x,
|
|
451
|
+
y,
|
|
452
|
+
r,
|
|
453
|
+
g,
|
|
454
|
+
b;
|
|
455
|
+
for (y = 0; y < height; y++) {
|
|
456
|
+
for (x = 0; x < width; x++) {
|
|
457
|
+
r = imgdata.data[j++] & 0xff;
|
|
458
|
+
g = imgdata.data[j++] & 0xff;
|
|
459
|
+
b = imgdata.data[j++] & 0xff;
|
|
460
|
+
j++; // Skip the Alpha channel
|
|
461
|
+
gray_data[i++] = r * 11 + g * 16 + b * 5 >> 5 & 0xff;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return gray_data;
|
|
355
465
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
466
|
+
|
|
467
|
+
// Append image in the order.
|
|
468
|
+
EscPosPrinter.prototype.appendImage = function (imgdata, dither) {
|
|
469
|
+
var gray_data, mono_data;
|
|
470
|
+
var w = imgdata.width;
|
|
471
|
+
var h = imgdata.height;
|
|
472
|
+
gray_data = _convertToGray(imgdata, w, h);
|
|
473
|
+
if (dither == "diffuse") mono_data = _diffuseDither(gray_data, w, h);
|
|
474
|
+
/* if (dither == "threshold") */else mono_data = _thresholdDither(gray_data, w, h);
|
|
475
|
+
w = w + 7 >> 3;
|
|
476
|
+
this.orderData += "1d763000";
|
|
477
|
+
this.orderData += _numToHexStr(w, 2);
|
|
478
|
+
this.orderData += _numToHexStr(h, 2);
|
|
479
|
+
for (var i = 0; i < mono_data.length; i++) this.orderData += _numToHexStr(mono_data[i] & 0xff, 1);
|
|
368
480
|
};
|
|
369
|
-
|
|
370
|
-
|
|
481
|
+
|
|
482
|
+
//////////////////////////////////////////////////
|
|
483
|
+
// Page Mode Commands
|
|
484
|
+
//////////////////////////////////////////////////
|
|
485
|
+
|
|
486
|
+
// Enter page mode.
|
|
487
|
+
EscPosPrinter.prototype.enterPageMode = function () {
|
|
488
|
+
this.orderData += "1b4c";
|
|
371
489
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
490
|
+
|
|
491
|
+
// Set print area in page mode.
|
|
492
|
+
// x, y: origin of the print area (the left-top corner of the print area)
|
|
493
|
+
// w, h: width and height of the print area
|
|
494
|
+
EscPosPrinter.prototype.setPrintAreaInPageMode = function (x, y, w, h) {
|
|
495
|
+
this.orderData += "1b57";
|
|
496
|
+
this.orderData += _numToHexStr(x, 2);
|
|
497
|
+
this.orderData += _numToHexStr(y, 2);
|
|
498
|
+
this.orderData += _numToHexStr(w, 2);
|
|
499
|
+
this.orderData += _numToHexStr(h, 2);
|
|
378
500
|
};
|
|
379
|
-
|
|
380
|
-
|
|
501
|
+
|
|
502
|
+
// Set print direction in page mode.
|
|
503
|
+
// dir: 0:not rotated; 1:90-degree clockwise rotated;
|
|
504
|
+
// 2:180-degree clockwise rotated; 3:270-degree clockwise rotated
|
|
505
|
+
EscPosPrinter.prototype.setPrintDirectionInPageMode = function (dir) {
|
|
506
|
+
if (dir >= 0 && dir <= 3) this.orderData += "1b54" + _numToHexStr(dir, 1);
|
|
381
507
|
};
|
|
382
|
-
|
|
383
|
-
|
|
508
|
+
|
|
509
|
+
// Set absolute print position in page mode.
|
|
510
|
+
EscPosPrinter.prototype.setAbsolutePrintPositionInPageMode = function (n) {
|
|
511
|
+
if (n >= 0 && n <= 65535) this.orderData += "1d24" + _numToHexStr(n, 2);
|
|
384
512
|
};
|
|
385
|
-
|
|
386
|
-
|
|
513
|
+
|
|
514
|
+
// Set relative print position in page mode.
|
|
515
|
+
EscPosPrinter.prototype.setRelativePrintPositionInPageMode = function (n) {
|
|
516
|
+
if (n >= -32768 && n <= 32767) this.orderData += "1d5c" + _numToHexStr(n, 2);
|
|
387
517
|
};
|
|
388
|
-
|
|
389
|
-
|
|
518
|
+
|
|
519
|
+
// Print contents in the buffer and exit page mode.
|
|
520
|
+
EscPosPrinter.prototype.printAndExitPageMode = function () {
|
|
521
|
+
this.orderData += "0c";
|
|
390
522
|
};
|
|
391
|
-
|
|
392
|
-
|
|
523
|
+
|
|
524
|
+
// Print contents in the buffer and keep in page mode.
|
|
525
|
+
EscPosPrinter.prototype.printInPageMode = function () {
|
|
526
|
+
this.orderData += "1b0c";
|
|
393
527
|
};
|
|
394
|
-
|
|
395
|
-
|
|
528
|
+
|
|
529
|
+
// Clear contents in the buffer and keep in page mode.
|
|
530
|
+
EscPosPrinter.prototype.clearInPageMode = function () {
|
|
531
|
+
this.orderData += "18";
|
|
396
532
|
};
|
|
397
|
-
|
|
398
|
-
|
|
533
|
+
|
|
534
|
+
// Discard contents in the buffer and exit page mode.
|
|
535
|
+
EscPosPrinter.prototype.exitPageMode = function () {
|
|
536
|
+
this.orderData += "1b53";
|
|
399
537
|
};
|
|
400
|
-
|
|
401
|
-
export { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, columnWidthWithAlignment, EscPosPrinter as default };
|
|
538
|
+
export default EscPosPrinter;
|