@pisell/utils 3.0.4 → 3.0.6

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.
Files changed (160) hide show
  1. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  2. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  3. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
  7. package/es/arrayUtils.d.ts +76 -1
  8. package/es/arrayUtils.js +103 -24
  9. package/es/common/stateHelper.d.ts +22 -0
  10. package/es/common/stateHelper.js +23 -0
  11. package/es/common/types.d.ts +31 -0
  12. package/es/componentStorage.d.ts +38 -0
  13. package/es/componentStorage.js +106 -0
  14. package/es/constants/index.js +7 -9
  15. package/es/date.d.ts +6 -3
  16. package/es/date.js +36 -53
  17. package/es/document.d.ts +6 -3
  18. package/es/document.js +43 -67
  19. package/es/escPosPrinter/EscPosPrinter.js +353 -490
  20. package/es/escPosPrinter/index.d.ts +9 -9
  21. package/es/escPosPrinter/index.js +37 -52
  22. package/es/format.d.ts +29 -0
  23. package/es/format.js +90 -112
  24. package/es/image.d.ts +13 -10
  25. package/es/image.js +48 -60
  26. package/es/index.d.ts +39 -18
  27. package/es/index.js +40 -29
  28. package/es/jsBridge/index.d.ts +14 -106
  29. package/es/jsBridge/index.js +57 -40
  30. package/es/jsBridge/regDeviceApi.js +87 -126
  31. package/es/jsBridge/types.d.ts +129 -0
  32. package/es/locales.d.ts +11 -11
  33. package/es/locales.js +79 -69
  34. package/es/log.d.ts +11 -6
  35. package/es/log.js +37 -59
  36. package/es/miniRedux.d.ts +20 -13
  37. package/es/miniRedux.js +42 -71
  38. package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
  39. package/es/number-input/hooks/useNumberInputState.js +72 -0
  40. package/es/number-input/types.d.ts +96 -0
  41. package/es/number-input/utils/formatter.d.ts +56 -0
  42. package/es/number-input/utils/formatter.js +56 -0
  43. package/es/number-input/utils/validation.d.ts +32 -0
  44. package/es/number-input/utils/validation.js +52 -0
  45. package/es/otherUtils.d.ts +12 -9
  46. package/es/otherUtils.js +71 -120
  47. package/es/platform.d.ts +12 -9
  48. package/es/platform.js +61 -85
  49. package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
  50. package/es/select/hooks/useDebouncedSearch.js +41 -0
  51. package/es/select/hooks/useSelectState.d.ts +19 -0
  52. package/es/select/hooks/useSelectState.js +60 -0
  53. package/es/select/index.d.ts +7 -0
  54. package/es/select/types.d.ts +256 -0
  55. package/es/select/utils/filterOptions.d.ts +23 -0
  56. package/es/select/utils/filterOptions.js +29 -0
  57. package/es/select/utils/helpers.d.ts +43 -0
  58. package/es/select/utils/helpers.js +51 -0
  59. package/es/select/utils/index.d.ts +4 -0
  60. package/es/select/utils/sortOptions.d.ts +13 -0
  61. package/es/select/utils/sortOptions.js +20 -0
  62. package/es/select/utils/tagAggregation.d.ts +25 -0
  63. package/es/select/utils/tagAggregation.js +35 -0
  64. package/es/text-input/hooks/useTextInputState.d.ts +28 -0
  65. package/es/text-input/hooks/useTextInputState.js +70 -0
  66. package/es/text-input/types.d.ts +56 -0
  67. package/es/text-input/utils/validation.d.ts +28 -0
  68. package/es/text-input/utils/validation.js +51 -0
  69. package/es/typeUtils.d.ts +11 -8
  70. package/es/typeUtils.js +61 -84
  71. package/es/walletValidity.d.ts +57 -0
  72. package/es/walletValidity.js +404 -460
  73. package/es/weighing.d.ts +65 -0
  74. package/es/weighing.js +96 -0
  75. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  76. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  77. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  78. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  79. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  80. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
  81. package/lib/_virtual/_rolldown/runtime.js +23 -0
  82. package/lib/arrayUtils.d.ts +76 -1
  83. package/lib/arrayUtils.js +102 -37
  84. package/lib/common/stateHelper.d.ts +22 -0
  85. package/lib/common/stateHelper.js +23 -0
  86. package/lib/common/types.d.ts +31 -0
  87. package/lib/componentStorage.d.ts +38 -0
  88. package/lib/componentStorage.js +114 -0
  89. package/lib/constants/index.js +7 -36
  90. package/lib/date.d.ts +6 -3
  91. package/lib/date.js +43 -65
  92. package/lib/document.d.ts +6 -3
  93. package/lib/document.js +46 -62
  94. package/lib/escPosPrinter/EscPosPrinter.js +327 -403
  95. package/lib/escPosPrinter/index.d.ts +9 -9
  96. package/lib/escPosPrinter/index.js +38 -84
  97. package/lib/format.d.ts +29 -0
  98. package/lib/format.js +91 -93
  99. package/lib/image.d.ts +13 -10
  100. package/lib/image.js +48 -74
  101. package/lib/index.d.ts +39 -18
  102. package/lib/index.js +137 -68
  103. package/lib/jsBridge/index.d.ts +14 -106
  104. package/lib/jsBridge/index.js +60 -60
  105. package/lib/jsBridge/regDeviceApi.js +86 -133
  106. package/lib/jsBridge/types.d.ts +129 -0
  107. package/lib/locales.d.ts +11 -11
  108. package/lib/locales.js +79 -63
  109. package/lib/log.d.ts +11 -6
  110. package/lib/log.js +37 -61
  111. package/lib/miniRedux.d.ts +20 -13
  112. package/lib/miniRedux.js +43 -91
  113. package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
  114. package/lib/number-input/hooks/useNumberInputState.js +73 -0
  115. package/lib/number-input/types.d.ts +96 -0
  116. package/lib/number-input/utils/formatter.d.ts +56 -0
  117. package/lib/number-input/utils/formatter.js +58 -0
  118. package/lib/number-input/utils/validation.d.ts +32 -0
  119. package/lib/number-input/utils/validation.js +52 -0
  120. package/lib/otherUtils.d.ts +12 -9
  121. package/lib/otherUtils.js +86 -91
  122. package/lib/platform.d.ts +12 -9
  123. package/lib/platform.js +68 -123
  124. package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
  125. package/lib/select/hooks/useDebouncedSearch.js +42 -0
  126. package/lib/select/hooks/useSelectState.d.ts +19 -0
  127. package/lib/select/hooks/useSelectState.js +62 -0
  128. package/lib/select/index.d.ts +7 -0
  129. package/lib/select/types.d.ts +256 -0
  130. package/lib/select/utils/filterOptions.d.ts +23 -0
  131. package/lib/select/utils/filterOptions.js +30 -0
  132. package/lib/select/utils/helpers.d.ts +43 -0
  133. package/lib/select/utils/helpers.js +55 -0
  134. package/lib/select/utils/index.d.ts +4 -0
  135. package/lib/select/utils/sortOptions.d.ts +13 -0
  136. package/lib/select/utils/sortOptions.js +20 -0
  137. package/lib/select/utils/tagAggregation.d.ts +25 -0
  138. package/lib/select/utils/tagAggregation.js +35 -0
  139. package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
  140. package/lib/text-input/hooks/useTextInputState.js +71 -0
  141. package/lib/text-input/types.d.ts +56 -0
  142. package/lib/text-input/utils/validation.d.ts +28 -0
  143. package/lib/text-input/utils/validation.js +51 -0
  144. package/lib/typeUtils.d.ts +11 -8
  145. package/lib/typeUtils.js +68 -73
  146. package/lib/walletValidity.d.ts +57 -0
  147. package/lib/walletValidity.js +420 -323
  148. package/lib/weighing.d.ts +65 -0
  149. package/lib/weighing.js +114 -0
  150. package/package.json +1 -1
  151. package/es/constants/index.d.ts +0 -7
  152. package/es/firebase/config/index.d.ts +0 -13
  153. package/es/firebase/config/index.js +0 -54
  154. package/es/firebase/index.d.ts +0 -28
  155. package/es/firebase/index.js +0 -232
  156. package/lib/constants/index.d.ts +0 -7
  157. package/lib/firebase/config/index.d.ts +0 -13
  158. package/lib/firebase/config/index.js +0 -79
  159. package/lib/firebase/index.d.ts +0 -28
  160. package/lib/firebase/index.js +0 -180
@@ -1,481 +1,405 @@
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 = "";
1
+ const ALIGN_LEFT = 0;
2
+ const ALIGN_CENTER = 1;
3
+ const ALIGN_RIGHT = 2;
4
+ const EscPosPrinter = function(dotsPerLine) {
5
+ if (dotsPerLine != 384 && dotsPerLine != 576) dotsPerLine = 384;
6
+ this.widthOfColumns = new Array(6);
7
+ this.dotsPerLine = dotsPerLine;
8
+ this.charHSize = 1;
9
+ this.orderData = "";
45
10
  };
46
11
  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) str += "0" + v.toString(16);
52
- else str += v.toString(16);
53
- n >>= 8;
54
- }
55
- return str;
12
+ var str = "";
13
+ var v;
14
+ for (var i = 0; i < bytes; i++) {
15
+ v = n & 255;
16
+ if (v < 16) str += "0" + v.toString(16);
17
+ else str += v.toString(16);
18
+ n >>= 8;
19
+ }
20
+ return str;
56
21
  }
57
22
  function _unicodeToUtf8(unicode) {
58
- var c1, c2, c3, c4;
59
- if (unicode < 0) return "";
60
- if (unicode <= 127) {
61
- c1 = unicode & 127;
62
- return _numToHexStr(c1, 1);
63
- }
64
- if (unicode <= 2047) {
65
- c1 = unicode >> 6 & 31 | 192;
66
- c2 = unicode & 63 | 128;
67
- return _numToHexStr(c1, 1) + _numToHexStr(c2, 1);
68
- }
69
- if (unicode <= 65535) {
70
- c1 = unicode >> 12 & 15 | 224;
71
- c2 = unicode >> 6 & 63 | 128;
72
- c3 = unicode & 63 | 128;
73
- return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1);
74
- }
75
- if (unicode <= 1114111) {
76
- c1 = unicode >> 18 & 7 | 240;
77
- c2 = unicode >> 12 & 63 | 128;
78
- c3 = unicode >> 6 & 63 | 128;
79
- c4 = unicode & 63 | 128;
80
- return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1) + _numToHexStr(c4, 1);
81
- }
82
- return "";
23
+ var c1, c2, c3, c4;
24
+ if (unicode < 0) return "";
25
+ if (unicode <= 127) {
26
+ c1 = unicode & 127;
27
+ return _numToHexStr(c1, 1);
28
+ }
29
+ if (unicode <= 2047) {
30
+ c1 = unicode >> 6 & 31 | 192;
31
+ c2 = unicode & 63 | 128;
32
+ return _numToHexStr(c1, 1) + _numToHexStr(c2, 1);
33
+ }
34
+ if (unicode <= 65535) {
35
+ c1 = unicode >> 12 & 15 | 224;
36
+ c2 = unicode >> 6 & 63 | 128;
37
+ c3 = unicode & 63 | 128;
38
+ return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1);
39
+ }
40
+ if (unicode <= 1114111) {
41
+ c1 = unicode >> 18 & 7 | 240;
42
+ c2 = unicode >> 12 & 63 | 128;
43
+ c3 = unicode >> 6 & 63 | 128;
44
+ c4 = unicode & 63 | 128;
45
+ return _numToHexStr(c1, 1) + _numToHexStr(c2, 1) + _numToHexStr(c3, 1) + _numToHexStr(c4, 1);
46
+ }
47
+ return "";
83
48
  }
84
49
  EscPosPrinter.prototype.clear = function() {
85
- this.orderData = "";
50
+ this.orderData = "";
86
51
  };
87
52
  EscPosPrinter.prototype.print = function(host, sn, copies) {
88
- var that = this;
89
- return new Promise(function(resolve, reject) {
90
- var xmlobj = new XMLHttpRequest();
91
- xmlobj.timeout = 1e4;
92
- var url = "https://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
93
- xmlobj.open("POST", url, true);
94
- xmlobj.onreadystatechange = function() {
95
- if (xmlobj.readyState === XMLHttpRequest.DONE) {
96
- if (xmlobj.status.toString(10) === "200") {
97
- var re = /task_id: (\d+)/;
98
- var matches = re.exec(xmlobj.responseText);
99
- resolve(matches[1] || "");
100
- } else {
101
- reject(xmlobj.responseText);
102
- }
103
- }
104
- };
105
- xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
106
- xmlobj.send(that.orderData);
107
- });
53
+ var that = this;
54
+ return new Promise(function(resolve, reject) {
55
+ var xmlobj = new XMLHttpRequest();
56
+ xmlobj.timeout = 1e4;
57
+ var url = "https://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
58
+ xmlobj.open("POST", url, true);
59
+ xmlobj.onreadystatechange = function() {
60
+ if (xmlobj.readyState === XMLHttpRequest.DONE) if (xmlobj.status.toString(10) === "200") resolve(/task_id: (\d+)/.exec(xmlobj.responseText)[1] || "");
61
+ else reject(xmlobj.responseText);
62
+ };
63
+ xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
64
+ xmlobj.send(that.orderData);
65
+ });
108
66
  };
109
67
  EscPosPrinter.prototype.queryStatus = function(host, sn, task_id) {
110
- return new Promise(function(resolve, reject) {
111
- var xmlobj = new XMLHttpRequest();
112
- xmlobj.timeout = 1e4;
113
- var url = "https://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
114
- xmlobj.open("POST", url, true);
115
- xmlobj.onreadystatechange = function() {
116
- if (xmlobj.readyState === XMLHttpRequest.DONE) {
117
- if (xmlobj.status.toString(10) === "200") {
118
- resolve(xmlobj.responseText);
119
- } else {
120
- reject(xmlobj.responseText);
121
- }
122
- }
123
- };
124
- xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
125
- xmlobj.send();
126
- });
68
+ return new Promise(function(resolve, reject) {
69
+ var xmlobj = new XMLHttpRequest();
70
+ xmlobj.timeout = 1e4;
71
+ var url = "https://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
72
+ xmlobj.open("POST", url, true);
73
+ xmlobj.onreadystatechange = function() {
74
+ if (xmlobj.readyState === XMLHttpRequest.DONE) if (xmlobj.status.toString(10) === "200") resolve(xmlobj.responseText);
75
+ else reject(xmlobj.responseText);
76
+ };
77
+ xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
78
+ xmlobj.send();
79
+ });
127
80
  };
128
81
  EscPosPrinter.prototype.appendText = function(str) {
129
- for (var i = 0; i < str.length; i++)
130
- this.orderData += _unicodeToUtf8(str.charCodeAt(i));
82
+ for (var i = 0; i < str.length; i++) this.orderData += _unicodeToUtf8(str.charCodeAt(i));
131
83
  };
132
84
  EscPosPrinter.prototype.lineFeed = function(n) {
133
- for (var i = 0; i < n; i++) this.orderData += "0a";
85
+ for (var i = 0; i < n; i++) this.orderData += "0a";
134
86
  };
135
87
  EscPosPrinter.prototype.restoreDefaultSettings = function() {
136
- this.charHSize = 1;
137
- this.orderData += "1b40";
88
+ this.charHSize = 1;
89
+ this.orderData += "1b40";
138
90
  };
139
91
  EscPosPrinter.prototype.restoreDefaultLineSpacing = function() {
140
- this.orderData += "1b32";
92
+ this.orderData += "1b32";
141
93
  };
142
94
  EscPosPrinter.prototype.setLineSpacing = function(n) {
143
- if (n >= 0 && n <= 255) this.orderData += "1b33" + _numToHexStr(n, 1);
95
+ if (n >= 0 && n <= 255) this.orderData += "1b33" + _numToHexStr(n, 1);
144
96
  };
145
97
  EscPosPrinter.prototype.setPrintModes = function(bold, double_h, double_w) {
146
- var n = 0;
147
- if (bold) n |= 8;
148
- if (double_h) n |= 16;
149
- if (double_w) n |= 32;
150
- this.charHSize = double_w ? 2 : 1;
151
- this.orderData += "1b21" + _numToHexStr(n, 1);
98
+ var n = 0;
99
+ if (bold) n |= 8;
100
+ if (double_h) n |= 16;
101
+ if (double_w) n |= 32;
102
+ this.charHSize = double_w ? 2 : 1;
103
+ this.orderData += "1b21" + _numToHexStr(n, 1);
152
104
  };
153
105
  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);
106
+ var n = 0;
107
+ if (h >= 1 && h <= 8) n |= h - 1;
108
+ if (w >= 1 && w <= 8) {
109
+ n |= w - 1 << 4;
110
+ this.charHSize = w;
111
+ }
112
+ this.orderData += "1d21" + _numToHexStr(n, 1);
161
113
  };
162
114
  EscPosPrinter.prototype.horizontalTab = function(n) {
163
- for (var i = 0; i < n; i++) this.orderData += "09";
115
+ for (var i = 0; i < n; i++) this.orderData += "09";
164
116
  };
165
117
  EscPosPrinter.prototype.setAbsolutePrintPosition = function(n) {
166
- if (n >= 0 && n <= 65535) this.orderData += "1b24" + _numToHexStr(n, 2);
118
+ if (n >= 0 && n <= 65535) this.orderData += "1b24" + _numToHexStr(n, 2);
167
119
  };
168
120
  EscPosPrinter.prototype.setRelativePrintPosition = function(n) {
169
- if (n >= -32768 && n <= 32767) this.orderData += "1b5c" + _numToHexStr(n, 2);
121
+ if (n >= -32768 && n <= 32767) this.orderData += "1b5c" + _numToHexStr(n, 2);
170
122
  };
171
123
  EscPosPrinter.prototype.setAlignment = function(n) {
172
- if (n >= 0 && n <= 2) this.orderData += "1b61" + _numToHexStr(n, 1);
124
+ if (n >= 0 && n <= 2) this.orderData += "1b61" + _numToHexStr(n, 1);
173
125
  };
174
126
  EscPosPrinter.prototype.cutPaper = function(fullCut) {
175
- this.orderData += "1d56" + (fullCut ? "30" : "31");
127
+ this.orderData += "1d56" + (fullCut ? "30" : "31");
176
128
  };
177
129
  EscPosPrinter.prototype.postponedCutPaper = function(fullCut, n) {
178
- if (n >= 0 && n <= 255)
179
- this.orderData += "1d56" + (fullCut ? "61" : "62") + _numToHexStr(n, 1);
130
+ if (n >= 0 && n <= 255) this.orderData += "1d56" + (fullCut ? "61" : "62") + _numToHexStr(n, 1);
180
131
  };
181
132
  function _widthOfChar(c) {
182
- if (c >= 32 && c <= 879 || c >= 65377 && c <= 65439)
183
- return 12;
184
- 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)
185
- return 24;
186
- 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)
187
- return 24;
188
- if (c >= 65281 && c <= 65374 || c >= 65504 && c <= 65509)
189
- return 24;
190
- return 0;
133
+ if (c >= 32 && c <= 879 || c >= 65377 && c <= 65439) return 12;
134
+ 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) return 24;
135
+ 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) return 24;
136
+ if (c >= 65281 && c <= 65374 || c >= 65504 && c <= 65509) return 24;
137
+ return 0;
191
138
  }
192
139
  function columnWidthWithAlignment(width, alignment) {
193
- return width & 65535 | (alignment & 3) << 16;
140
+ return width & 65535 | (alignment & 3) << 16;
194
141
  }
195
142
  function _columnWidth(v) {
196
- return v & 65535;
143
+ return v & 65535;
197
144
  }
198
145
  function _columnAlignment(v) {
199
- return v >> 16 & 3;
146
+ return v >> 16 & 3;
200
147
  }
201
148
  EscPosPrinter.prototype.setColumnWidths = function() {
202
- var i, remain, width, alignment;
203
- if (arguments.length == 0) return;
204
- for (i = 0; i < MAX_COLUMNS; i++) this.widthOfColumns[i] = 0;
205
- remain = this.dotsPerLine;
206
- for (i = 0; i < arguments.length; i++) {
207
- if (i == MAX_COLUMNS)
208
- return;
209
- width = _columnWidth(arguments[i]);
210
- alignment = _columnAlignment(arguments[i]);
211
- if (width == 0 || width > remain) {
212
- this.widthOfColumns[i] = columnWidthWithAlignment(remain, alignment);
213
- return;
214
- }
215
- this.widthOfColumns[i] = arguments[i];
216
- remain -= width;
217
- }
149
+ var i, remain, width, alignment;
150
+ if (arguments.length == 0) return;
151
+ for (i = 0; i < 6; i++) this.widthOfColumns[i] = 0;
152
+ remain = this.dotsPerLine;
153
+ for (i = 0; i < arguments.length; i++) {
154
+ if (i == 6) return;
155
+ width = _columnWidth(arguments[i]);
156
+ alignment = _columnAlignment(arguments[i]);
157
+ if (width == 0 || width > remain) {
158
+ this.widthOfColumns[i] = columnWidthWithAlignment(remain, alignment);
159
+ return;
160
+ }
161
+ this.widthOfColumns[i] = arguments[i];
162
+ remain -= width;
163
+ }
218
164
  };
219
165
  EscPosPrinter.prototype.printInColumns = function() {
220
- var strcurr = new Array(MAX_COLUMNS);
221
- var strrem = new Array(MAX_COLUMNS);
222
- var strwidth = new Array(MAX_COLUMNS);
223
- var i, j, c, w, columns, width, alignment, pos;
224
- var done;
225
- if (arguments.length == 0) return;
226
- columns = 0;
227
- for (i = 0; i < arguments.length; i++) {
228
- if (i == MAX_COLUMNS || this.widthOfColumns[i] == 0) break;
229
- strcurr[i] = "";
230
- strrem[i] = arguments[i];
231
- columns++;
232
- }
233
- do {
234
- done = true;
235
- pos = 0;
236
- for (i = 0; i < columns; i++) {
237
- width = _columnWidth(this.widthOfColumns[i]);
238
- if (strrem[i].length == 0) {
239
- pos += width;
240
- continue;
241
- }
242
- done = false;
243
- strcurr[i] = "";
244
- strwidth[i] = 0;
245
- for (j = 0; j < strrem[i].length; j++) {
246
- c = strrem[i].charCodeAt(j);
247
- if (c == 10) {
248
- j++;
249
- break;
250
- } else {
251
- w = _widthOfChar(c);
252
- if (w == 0) {
253
- c = "?";
254
- w = 12;
255
- }
256
- w *= this.charHSize;
257
- if (strwidth[i] + w > width) {
258
- break;
259
- } else {
260
- strcurr[i] += String.fromCharCode(c);
261
- strwidth[i] += w;
262
- }
263
- }
264
- }
265
- if (j < strrem[i].length) strrem[i] = strrem[i].substring(j);
266
- else strrem[i] = "";
267
- alignment = _columnAlignment(this.widthOfColumns[i]);
268
- switch (alignment) {
269
- case ALIGN_CENTER:
270
- this.setAbsolutePrintPosition(pos + (width - strwidth[i]) / 2);
271
- break;
272
- case ALIGN_RIGHT:
273
- this.setAbsolutePrintPosition(pos + (width - strwidth[i]));
274
- break;
275
- default:
276
- this.setAbsolutePrintPosition(pos);
277
- break;
278
- }
279
- this.appendText(strcurr[i]);
280
- pos += width;
281
- }
282
- if (!done) this.lineFeed(1);
283
- } while (!done);
166
+ var strcurr = new Array(6);
167
+ var strrem = new Array(6);
168
+ var strwidth = new Array(6);
169
+ var i, j, c, w, columns, width, alignment, pos;
170
+ var done;
171
+ if (arguments.length == 0) return;
172
+ columns = 0;
173
+ for (i = 0; i < arguments.length; i++) {
174
+ if (i == 6 || this.widthOfColumns[i] == 0) break;
175
+ strcurr[i] = "";
176
+ strrem[i] = arguments[i];
177
+ columns++;
178
+ }
179
+ do {
180
+ done = true;
181
+ pos = 0;
182
+ for (i = 0; i < columns; i++) {
183
+ width = _columnWidth(this.widthOfColumns[i]);
184
+ if (strrem[i].length == 0) {
185
+ pos += width;
186
+ continue;
187
+ }
188
+ done = false;
189
+ strcurr[i] = "";
190
+ strwidth[i] = 0;
191
+ for (j = 0; j < strrem[i].length; j++) {
192
+ c = strrem[i].charCodeAt(j);
193
+ if (c == 10) {
194
+ j++;
195
+ break;
196
+ } else {
197
+ w = _widthOfChar(c);
198
+ if (w == 0) {
199
+ c = "?";
200
+ w = 12;
201
+ }
202
+ w *= this.charHSize;
203
+ if (strwidth[i] + w > width) break;
204
+ else {
205
+ strcurr[i] += String.fromCharCode(c);
206
+ strwidth[i] += w;
207
+ }
208
+ }
209
+ }
210
+ if (j < strrem[i].length) strrem[i] = strrem[i].substring(j);
211
+ else strrem[i] = "";
212
+ alignment = _columnAlignment(this.widthOfColumns[i]);
213
+ switch (alignment) {
214
+ case 1:
215
+ this.setAbsolutePrintPosition(pos + (width - strwidth[i]) / 2);
216
+ break;
217
+ case 2:
218
+ this.setAbsolutePrintPosition(pos + (width - strwidth[i]));
219
+ break;
220
+ default:
221
+ this.setAbsolutePrintPosition(pos);
222
+ break;
223
+ }
224
+ this.appendText(strcurr[i]);
225
+ pos += width;
226
+ }
227
+ if (!done) this.lineFeed(1);
228
+ } while (!done);
284
229
  };
285
230
  EscPosPrinter.prototype.appendBarcode = function(hri_pos, height, module_size, barcode_type, text) {
286
- var text_length = text.length;
287
- if (text_length == 0) return;
288
- if (text_length > 255) text_length = 255;
289
- if (height < 1) height = 1;
290
- else if (height > 255) height = 255;
291
- if (module_size < 1) module_size = 1;
292
- else if (module_size > 6) module_size = 6;
293
- this.orderData += "1d48" + _numToHexStr(hri_pos & 3, 1);
294
- this.orderData += "1d6600";
295
- this.orderData += "1d68" + _numToHexStr(height, 1);
296
- this.orderData += "1d77" + _numToHexStr(module_size, 1);
297
- this.orderData += "1d6b" + _numToHexStr(barcode_type, 1) + _numToHexStr(text_length, 1);
298
- for (var i = 0; i < text_length; i++)
299
- this.orderData += _numToHexStr(text.charCodeAt(i), 1);
231
+ var text_length = text.length;
232
+ if (text_length == 0) return;
233
+ if (text_length > 255) text_length = 255;
234
+ if (height < 1) height = 1;
235
+ else if (height > 255) height = 255;
236
+ if (module_size < 1) module_size = 1;
237
+ else if (module_size > 6) module_size = 6;
238
+ this.orderData += "1d48" + _numToHexStr(hri_pos & 3, 1);
239
+ this.orderData += "1d6600";
240
+ this.orderData += "1d68" + _numToHexStr(height, 1);
241
+ this.orderData += "1d77" + _numToHexStr(module_size, 1);
242
+ this.orderData += "1d6b" + _numToHexStr(barcode_type, 1) + _numToHexStr(text_length, 1);
243
+ for (var i = 0; i < text_length; i++) this.orderData += _numToHexStr(text.charCodeAt(i), 1);
300
244
  };
301
245
  EscPosPrinter.prototype.appendQRcode = function(module_size, ec_level, text) {
302
- var text_length = text.length;
303
- if (text_length == 0) return;
304
- if (text_length > 65535) text_length = 65535;
305
- if (module_size < 1) module_size = 1;
306
- else if (module_size > 16) module_size = 16;
307
- if (ec_level < 0) ec_level = 0;
308
- else if (ec_level > 3) ec_level = 3;
309
- this.orderData += "1d286b040031410000";
310
- this.orderData += "1d286b03003143" + _numToHexStr(module_size, 1);
311
- this.orderData += "1d286b03003145" + _numToHexStr(ec_level + 48, 1);
312
- this.orderData += "1d286b" + _numToHexStr(text_length + 3, 2) + "315030";
313
- for (var i = 0; i < text_length; i++)
314
- this.orderData += _numToHexStr(text.charCodeAt(i), 1);
315
- this.orderData += "1d286b0300315130";
246
+ var text_length = text.length;
247
+ if (text_length == 0) return;
248
+ if (text_length > 65535) text_length = 65535;
249
+ if (module_size < 1) module_size = 1;
250
+ else if (module_size > 16) module_size = 16;
251
+ if (ec_level < 0) ec_level = 0;
252
+ else if (ec_level > 3) ec_level = 3;
253
+ this.orderData += "1d286b040031410000";
254
+ this.orderData += "1d286b03003143" + _numToHexStr(module_size, 1);
255
+ this.orderData += "1d286b03003145" + _numToHexStr(ec_level + 48, 1);
256
+ this.orderData += "1d286b" + _numToHexStr(text_length + 3, 2) + "315030";
257
+ for (var i = 0; i < text_length; i++) this.orderData += _numToHexStr(text.charCodeAt(i), 1);
258
+ this.orderData += "1d286b0300315130";
316
259
  };
317
260
  function _diffuseDither(src_data, width, height) {
318
- if (width <= 0 || height <= 0) return null;
319
- if (src_data.length < width * height) return null;
320
- var bmwidth = width + 7 >> 3;
321
- var dst_data = new Array(bmwidth * height);
322
- var line_buffer = new Array(2 * width);
323
- var i, p, q, x, y, mask;
324
- var line1, line2, b1, b2, tmp;
325
- var err, e1, e3, e5, e7;
326
- var not_last_line;
327
- line1 = 0;
328
- line2 = 1;
329
- for (i = 0; i < width; i++) {
330
- line_buffer[i] = 0;
331
- line_buffer[width + i] = src_data[i];
332
- }
333
- for (y = 0; y < height; y++) {
334
- tmp = line1;
335
- line1 = line2;
336
- line2 = tmp;
337
- not_last_line = y < height - 1;
338
- if (not_last_line) {
339
- p = (y + 1) * width;
340
- for (i = 0; i < width; i++) {
341
- line_buffer[line2 * width + i] = src_data[p];
342
- p++;
343
- }
344
- }
345
- q = y * bmwidth;
346
- for (i = 0; i < bmwidth; i++) {
347
- dst_data[q] = 0;
348
- q++;
349
- }
350
- b1 = 0;
351
- b2 = 0;
352
- q = y * bmwidth;
353
- mask = 128;
354
- for (x = 1; x <= width; x++) {
355
- var idx = line1 * width + b1;
356
- if (line_buffer[idx] < 128) {
357
- err = line_buffer[idx];
358
- dst_data[q] |= mask;
359
- } else {
360
- err = line_buffer[idx] - 255;
361
- }
362
- b1++;
363
- if (mask == 1) {
364
- q++;
365
- mask = 128;
366
- } else {
367
- mask >>= 1;
368
- }
369
- e7 = err * 7 + 8 >> 4;
370
- e5 = err * 5 + 8 >> 4;
371
- e3 = err * 3 + 8 >> 4;
372
- e1 = err - (e7 + e5 + e3);
373
- if (x < width) line_buffer[line1 * width + b1] += e7;
374
- if (not_last_line) {
375
- line_buffer[line2 * width + b2] += e5;
376
- if (x > 1) line_buffer[line2 * width + b2 - 1] += e3;
377
- if (x < width) line_buffer[line2 * width + b2 + 1] += e1;
378
- }
379
- b2++;
380
- }
381
- }
382
- return dst_data;
261
+ if (width <= 0 || height <= 0) return null;
262
+ if (src_data.length < width * height) return null;
263
+ var bmwidth = width + 7 >> 3;
264
+ var dst_data = new Array(bmwidth * height);
265
+ var line_buffer = new Array(2 * width);
266
+ var i, p, q, x, y, mask;
267
+ var line1, line2, b1, b2, tmp;
268
+ var err, e1, e3, e5, e7;
269
+ var not_last_line;
270
+ line1 = 0;
271
+ line2 = 1;
272
+ for (i = 0; i < width; i++) {
273
+ line_buffer[i] = 0;
274
+ line_buffer[width + i] = src_data[i];
275
+ }
276
+ for (y = 0; y < height; y++) {
277
+ tmp = line1;
278
+ line1 = line2;
279
+ line2 = tmp;
280
+ not_last_line = y < height - 1;
281
+ if (not_last_line) {
282
+ p = (y + 1) * width;
283
+ for (i = 0; i < width; i++) {
284
+ line_buffer[line2 * width + i] = src_data[p];
285
+ p++;
286
+ }
287
+ }
288
+ q = y * bmwidth;
289
+ for (i = 0; i < bmwidth; i++) {
290
+ dst_data[q] = 0;
291
+ q++;
292
+ }
293
+ b1 = 0;
294
+ b2 = 0;
295
+ q = y * bmwidth;
296
+ mask = 128;
297
+ for (x = 1; x <= width; x++) {
298
+ var idx = line1 * width + b1;
299
+ if (line_buffer[idx] < 128) {
300
+ err = line_buffer[idx];
301
+ dst_data[q] |= mask;
302
+ } else err = line_buffer[idx] - 255;
303
+ b1++;
304
+ if (mask == 1) {
305
+ q++;
306
+ mask = 128;
307
+ } else mask >>= 1;
308
+ e7 = err * 7 + 8 >> 4;
309
+ e5 = err * 5 + 8 >> 4;
310
+ e3 = err * 3 + 8 >> 4;
311
+ e1 = err - (e7 + e5 + e3);
312
+ if (x < width) line_buffer[line1 * width + b1] += e7;
313
+ if (not_last_line) {
314
+ line_buffer[line2 * width + b2] += e5;
315
+ if (x > 1) line_buffer[line2 * width + b2 - 1] += e3;
316
+ if (x < width) line_buffer[line2 * width + b2 + 1] += e1;
317
+ }
318
+ b2++;
319
+ }
320
+ }
321
+ return dst_data;
383
322
  }
384
323
  function _thresholdDither(src_data, width, height) {
385
- if (width <= 0 || height <= 0) return null;
386
- if (src_data.length < width * height) return null;
387
- var bmwidth = width + 7 >> 3;
388
- var dst_data = new Array(bmwidth * height);
389
- var p, q, k, x, y, mask;
390
- p = 0;
391
- q = 0;
392
- for (y = 0; y < height; y++) {
393
- k = q;
394
- mask = 128;
395
- for (x = 0; x < width; x++) {
396
- if (src_data[p] < 128) {
397
- dst_data[k] |= mask;
398
- }
399
- p++;
400
- if (mask == 1) {
401
- k++;
402
- mask = 128;
403
- } else {
404
- mask >>= 1;
405
- }
406
- }
407
- q += bmwidth;
408
- }
409
- return dst_data;
324
+ if (width <= 0 || height <= 0) return null;
325
+ if (src_data.length < width * height) return null;
326
+ var bmwidth = width + 7 >> 3;
327
+ var dst_data = new Array(bmwidth * height);
328
+ var p = 0, q = 0, k, x, y, mask;
329
+ for (y = 0; y < height; y++) {
330
+ k = q;
331
+ mask = 128;
332
+ for (x = 0; x < width; x++) {
333
+ if (src_data[p] < 128) dst_data[k] |= mask;
334
+ p++;
335
+ if (mask == 1) {
336
+ k++;
337
+ mask = 128;
338
+ } else mask >>= 1;
339
+ }
340
+ q += bmwidth;
341
+ }
342
+ return dst_data;
410
343
  }
411
344
  function _convertToGray(imgdata, width, height) {
412
- var gray_data = new Array(width * height);
413
- var i = 0, j = 0, x, y, r, g, b;
414
- for (y = 0; y < height; y++) {
415
- for (x = 0; x < width; x++) {
416
- r = imgdata.data[j++] & 255;
417
- g = imgdata.data[j++] & 255;
418
- b = imgdata.data[j++] & 255;
419
- j++;
420
- gray_data[i++] = r * 11 + g * 16 + b * 5 >> 5 & 255;
421
- }
422
- }
423
- return gray_data;
345
+ var gray_data = new Array(width * height);
346
+ var i = 0, j = 0, x, y, r, g, b;
347
+ for (y = 0; y < height; y++) for (x = 0; x < width; x++) {
348
+ r = imgdata.data[j++] & 255;
349
+ g = imgdata.data[j++] & 255;
350
+ b = imgdata.data[j++] & 255;
351
+ j++;
352
+ gray_data[i++] = r * 11 + g * 16 + b * 5 >> 5 & 255;
353
+ }
354
+ return gray_data;
424
355
  }
425
356
  EscPosPrinter.prototype.appendImage = function(imgdata, dither) {
426
- var gray_data, mono_data;
427
- var w = imgdata.width;
428
- var h = imgdata.height;
429
- gray_data = _convertToGray(imgdata, w, h);
430
- if (dither == "diffuse") mono_data = _diffuseDither(gray_data, w, h);
431
- else
432
- mono_data = _thresholdDither(gray_data, w, h);
433
- w = w + 7 >> 3;
434
- this.orderData += "1d763000";
435
- this.orderData += _numToHexStr(w, 2);
436
- this.orderData += _numToHexStr(h, 2);
437
- for (var i = 0; i < mono_data.length; i++)
438
- this.orderData += _numToHexStr(mono_data[i] & 255, 1);
357
+ var gray_data, mono_data;
358
+ var w = imgdata.width;
359
+ var h = imgdata.height;
360
+ gray_data = _convertToGray(imgdata, w, h);
361
+ if (dither == "diffuse") mono_data = _diffuseDither(gray_data, w, h);
362
+ else mono_data = _thresholdDither(gray_data, w, h);
363
+ w = w + 7 >> 3;
364
+ this.orderData += "1d763000";
365
+ this.orderData += _numToHexStr(w, 2);
366
+ this.orderData += _numToHexStr(h, 2);
367
+ for (var i = 0; i < mono_data.length; i++) this.orderData += _numToHexStr(mono_data[i] & 255, 1);
439
368
  };
440
369
  EscPosPrinter.prototype.enterPageMode = function() {
441
- this.orderData += "1b4c";
370
+ this.orderData += "1b4c";
442
371
  };
443
372
  EscPosPrinter.prototype.setPrintAreaInPageMode = function(x, y, w, h) {
444
- this.orderData += "1b57";
445
- this.orderData += _numToHexStr(x, 2);
446
- this.orderData += _numToHexStr(y, 2);
447
- this.orderData += _numToHexStr(w, 2);
448
- this.orderData += _numToHexStr(h, 2);
373
+ this.orderData += "1b57";
374
+ this.orderData += _numToHexStr(x, 2);
375
+ this.orderData += _numToHexStr(y, 2);
376
+ this.orderData += _numToHexStr(w, 2);
377
+ this.orderData += _numToHexStr(h, 2);
449
378
  };
450
379
  EscPosPrinter.prototype.setPrintDirectionInPageMode = function(dir) {
451
- if (dir >= 0 && dir <= 3) this.orderData += "1b54" + _numToHexStr(dir, 1);
380
+ if (dir >= 0 && dir <= 3) this.orderData += "1b54" + _numToHexStr(dir, 1);
452
381
  };
453
382
  EscPosPrinter.prototype.setAbsolutePrintPositionInPageMode = function(n) {
454
- if (n >= 0 && n <= 65535) this.orderData += "1d24" + _numToHexStr(n, 2);
383
+ if (n >= 0 && n <= 65535) this.orderData += "1d24" + _numToHexStr(n, 2);
455
384
  };
456
385
  EscPosPrinter.prototype.setRelativePrintPositionInPageMode = function(n) {
457
- if (n >= -32768 && n <= 32767) this.orderData += "1d5c" + _numToHexStr(n, 2);
386
+ if (n >= -32768 && n <= 32767) this.orderData += "1d5c" + _numToHexStr(n, 2);
458
387
  };
459
388
  EscPosPrinter.prototype.printAndExitPageMode = function() {
460
- this.orderData += "0c";
389
+ this.orderData += "0c";
461
390
  };
462
391
  EscPosPrinter.prototype.printInPageMode = function() {
463
- this.orderData += "1b0c";
392
+ this.orderData += "1b0c";
464
393
  };
465
394
  EscPosPrinter.prototype.clearInPageMode = function() {
466
- this.orderData += "18";
395
+ this.orderData += "18";
467
396
  };
468
397
  EscPosPrinter.prototype.exitPageMode = function() {
469
- this.orderData += "1b53";
470
- };
471
- var EscPosPrinter_default = EscPosPrinter;
472
- // Annotate the CommonJS export names for ESM import in node:
473
- 0 && (module.exports = {
474
- ALIGN_CENTER,
475
- ALIGN_LEFT,
476
- ALIGN_RIGHT,
477
- HRI_POS_ABOVE,
478
- HRI_POS_BELOW,
479
- MAX_COLUMNS,
480
- columnWidthWithAlignment
481
- });
398
+ this.orderData += "1b53";
399
+ };
400
+ //#endregion
401
+ exports.ALIGN_CENTER = ALIGN_CENTER;
402
+ exports.ALIGN_LEFT = ALIGN_LEFT;
403
+ exports.ALIGN_RIGHT = ALIGN_RIGHT;
404
+ exports.columnWidthWithAlignment = columnWidthWithAlignment;
405
+ exports.default = EscPosPrinter;