@risleylima/escpos 0.2.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +116 -755
  2. package/dist/adapter/index.d.ts +29 -0
  3. package/dist/adapter/index.d.ts.map +1 -0
  4. package/dist/adapter/index.js +25 -0
  5. package/dist/adapter/index.js.map +1 -0
  6. package/dist/index.d.ts +14 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +25 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/network-adapter/index.d.ts +24 -0
  11. package/dist/network-adapter/index.d.ts.map +1 -0
  12. package/dist/network-adapter/index.js +263 -0
  13. package/dist/network-adapter/index.js.map +1 -0
  14. package/dist/printer/commands-types.d.ts +37 -0
  15. package/dist/printer/commands-types.d.ts.map +1 -0
  16. package/dist/printer/commands-types.js +63 -0
  17. package/dist/printer/commands-types.js.map +1 -0
  18. package/dist/printer/commands.d.ts +169 -0
  19. package/dist/printer/commands.d.ts.map +1 -0
  20. package/dist/printer/commands.js +192 -0
  21. package/dist/printer/commands.js.map +1 -0
  22. package/dist/printer/image-loader.d.ts +17 -0
  23. package/dist/printer/image-loader.d.ts.map +1 -0
  24. package/dist/printer/image-loader.js +462 -0
  25. package/dist/printer/image-loader.js.map +1 -0
  26. package/dist/printer/image.d.ts +43 -0
  27. package/dist/printer/image.d.ts.map +1 -0
  28. package/dist/printer/image.js +132 -0
  29. package/dist/printer/image.js.map +1 -0
  30. package/dist/printer/index.d.ts +158 -0
  31. package/dist/printer/index.d.ts.map +1 -0
  32. package/dist/printer/index.js +703 -0
  33. package/dist/printer/index.js.map +1 -0
  34. package/dist/printer/profiles/bematech/mp4200th.d.ts +13 -0
  35. package/dist/printer/profiles/bematech/mp4200th.d.ts.map +1 -0
  36. package/dist/printer/profiles/bematech/mp4200th.js +29 -0
  37. package/dist/printer/profiles/bematech/mp4200th.js.map +1 -0
  38. package/dist/printer/profiles/custom/bematech-mp4200th.d.ts +13 -0
  39. package/dist/printer/profiles/custom/bematech-mp4200th.d.ts.map +1 -0
  40. package/dist/printer/profiles/custom/bematech-mp4200th.js +21 -0
  41. package/dist/printer/profiles/custom/bematech-mp4200th.js.map +1 -0
  42. package/dist/printer/profiles/custom/vkp80iii.d.ts +19 -0
  43. package/dist/printer/profiles/custom/vkp80iii.d.ts.map +1 -0
  44. package/dist/printer/profiles/custom/vkp80iii.js +87 -0
  45. package/dist/printer/profiles/custom/vkp80iii.js.map +1 -0
  46. package/dist/printer/profiles/default.d.ts +7 -0
  47. package/dist/printer/profiles/default.d.ts.map +1 -0
  48. package/dist/printer/profiles/default.js +15 -0
  49. package/dist/printer/profiles/default.js.map +1 -0
  50. package/dist/printer/profiles/index.d.ts +41 -0
  51. package/dist/printer/profiles/index.d.ts.map +1 -0
  52. package/dist/printer/profiles/index.js +98 -0
  53. package/dist/printer/profiles/index.js.map +1 -0
  54. package/dist/printer/profiles/merge.d.ts +7 -0
  55. package/dist/printer/profiles/merge.d.ts.map +1 -0
  56. package/dist/printer/profiles/merge.js +58 -0
  57. package/dist/printer/profiles/merge.js.map +1 -0
  58. package/dist/printer/profiles/types.d.ts +99 -0
  59. package/dist/printer/profiles/types.d.ts.map +1 -0
  60. package/dist/printer/profiles/types.js +8 -0
  61. package/dist/printer/profiles/types.js.map +1 -0
  62. package/dist/printer/utils.d.ts +9 -0
  63. package/dist/printer/utils.d.ts.map +1 -0
  64. package/dist/printer/utils.js +54 -0
  65. package/dist/printer/utils.js.map +1 -0
  66. package/dist/serial-adapter/index.d.ts +21 -0
  67. package/dist/serial-adapter/index.d.ts.map +1 -0
  68. package/dist/serial-adapter/index.js +180 -0
  69. package/dist/serial-adapter/index.js.map +1 -0
  70. package/dist/usb-adapter/index.d.ts +20 -0
  71. package/dist/usb-adapter/index.d.ts.map +1 -0
  72. package/dist/usb-adapter/index.js +264 -0
  73. package/dist/usb-adapter/index.js.map +1 -0
  74. package/package.json +42 -15
  75. package/CHANGELOG.md +0 -74
  76. package/docs/COVERAGE_ANALYSIS.md +0 -98
  77. package/docs/DEPENDENCIES_REVIEW.md +0 -127
  78. package/docs/JSDOC_REVIEW.md +0 -122
  79. package/docs/LIBRARY_OVERVIEW.md +0 -383
  80. package/docs/PRE_PUBLISH_CHECKLIST.md +0 -331
  81. package/docs/PUBLIC_API_ANALYSIS.md +0 -223
  82. package/docs/README.md +0 -37
  83. package/docs/SERIALPORT_V13_MIGRATION_COMPLETE.md +0 -127
  84. package/docs/TESTS_IMPLEMENTED.md +0 -129
  85. package/docs/USB_V2_REVIEW.md +0 -148
  86. package/docs/VERIFICATION_RESULTS.md +0 -172
  87. package/docs/VERSIONING.md +0 -102
  88. package/examples/printTest.js +0 -59
  89. package/index.js +0 -7
  90. package/jest.config.js +0 -16
  91. package/src/adapter/index.js +0 -75
  92. package/src/printer/commands.js +0 -199
  93. package/src/printer/image.js +0 -159
  94. package/src/printer/index.js +0 -621
  95. package/src/printer/utils.js +0 -58
  96. package/src/serial-adapter/index.js +0 -198
  97. package/src/usb-adapter/index.js +0 -283
  98. package/tests/README.md +0 -67
  99. package/tests/integration/printer-flow.test.js +0 -128
  100. package/tests/unit/adapters/adapter.test.js +0 -49
  101. package/tests/unit/adapters/serial-adapter.test.js +0 -238
  102. package/tests/unit/adapters/usb-adapter.test.js +0 -319
  103. package/tests/unit/image/image.test.js +0 -157
  104. package/tests/unit/printer/buffer.test.js +0 -60
  105. package/tests/unit/printer/commands.test.js +0 -109
  106. package/tests/unit/printer/printer.test.js +0 -405
  107. package/tests/unit/utils/utils.test.js +0 -96
@@ -1,199 +0,0 @@
1
- 'use strict';
2
- /**
3
- * Utility function that converts numbers into hex values
4
- * @param {Number|String} value - Number to convert to hex
5
- * @returns {String} Hexadecimal string representation (padded to even length)
6
- * @example
7
- * numToHexString(256) => '0100'
8
- * numToHexString(0) => '00'
9
- * numToHexString(15) => '0f'
10
- */
11
- const numToHexString = (value) => {
12
- let num = Number(value);
13
- let retorno = ''
14
- if (!isNaN(num)) {
15
- retorno = num.toString(16);
16
- while (retorno.length % 2 !== 0) {
17
- retorno = '0' + retorno;
18
- }
19
- }
20
- return retorno;
21
- };
22
-
23
- const commands = {
24
- LF: Buffer.from('0A', 'hex'),
25
- FS: Buffer.from('1C', 'hex'),
26
- FF: Buffer.from('0C', 'hex'),
27
- GS: Buffer.from('1D', 'hex'),
28
- DLE: Buffer.from('10', 'hex'),
29
- EOT: Buffer.from('04', 'hex'),
30
- NUL: Buffer.from('00', 'hex'),
31
- ESC: Buffer.from('1B', 'hex'),
32
- TAB: Buffer.from('74', 'hex'),
33
- EOL: Buffer.from('\n', 'ascii'),
34
-
35
- FEED_CONTROL_SEQUENCES: {
36
- CTL_LF: Buffer.from('0A', 'hex'), // Print and line feed
37
- CTL_GLF: Buffer.from('4A00', 'hex'), // Print and grafical line feed (without spaces between lines)
38
- CTL_FF: Buffer.from('0C', 'hex'), // Form feed
39
- CTL_CR: Buffer.from('0D', 'hex'), // Carriage return
40
- CTL_HT: Buffer.from('09', 'hex'), // Horizontal tab
41
- CTL_VT: Buffer.from('0B', 'hex'), // Vertical tab
42
- },
43
- CHARACTER_SPACING: {
44
- CS_DEFAULT: Buffer.from('1B2000', 'hex'),
45
- CS_SET: Buffer.from('1B20', 'hex')
46
- },
47
- LINE_SPACING: {
48
- LS_DEFAULT: Buffer.from('1B32', 'hex'),
49
- LS_SET: Buffer.from('1B33', 'hex')
50
- },
51
- HARDWARE: {
52
- HW_INIT: Buffer.from('1B40', 'hex'), // Clear data in buffer and reset modes
53
- HW_SELECT: Buffer.from('1B3D01', 'hex'), // Printer select
54
- HW_RESET: Buffer.from('1B3F0A00', 'hex'), // Reset printer hardware
55
- },
56
- CASH_DRAWER: {
57
- CD_KICK_2: Buffer.from('1B700019FA', 'hex'), // Sends a pulse to pin 2 []
58
- CD_KICK_5: Buffer.from('1B700119FA', 'hex'), // Sends a pulse to pin 5 []
59
- },
60
- MARGINS: {
61
- BOTTOM: Buffer.from('1B4F', 'hex'), // Fix bottom size
62
- LEFT: Buffer.from('1B6C', 'hex'), // Fix left size
63
- RIGHT: Buffer.from('1B51', 'hex'), // Fix right size
64
- },
65
- PAPER: {
66
- PAPER_FULL_CUT: Buffer.from('1D5600', 'hex'), // Full cut paper
67
- PAPER_PART_CUT: Buffer.from('1D5601', 'hex'), // Partial cut paper
68
- PAPER_CUT_A: Buffer.from('1D5641', 'hex'), // Partial cut paper
69
- PAPER_CUT_B: Buffer.from('1D5642', 'hex'), // Partial cut paper
70
- },
71
- TEXT_FORMAT: {
72
- TXT_NORMAL: Buffer.from('1B2100', 'hex'), // Normal text
73
- TXT_2HEIGHT: Buffer.from('1B2110', 'hex'), // Double height text
74
- TXT_2WIDTH: Buffer.from('1B2120', 'hex'), // Double width text
75
- TXT_4SQUARE: Buffer.from('1B2130', 'hex'), // Double width & height text
76
- TXT_BOLDER: Buffer.from('1B2108', 'hex'),
77
-
78
- TXT_CUSTOM_SIZE: function (width, height) { // other sizes
79
- width = width > 8 ? 8 : width;
80
- width = width < 1 ? 1 : width;
81
- height = height > 8 ? 8 : height;
82
- height = height < 1 ? 1 : height;
83
-
84
- var widthDec = (width - 1) * 16; // Values between 1-8
85
- var heightDec = height - 1; // Values between 1-8
86
- var sizeDec = widthDec + heightDec;
87
-
88
- return Buffer.from('1D21' + numToHexString(sizeDec), 'hex');
89
- },
90
-
91
- TXT_HEIGHT: {
92
- 1: Buffer.from('00', 'hex'),
93
- 2: Buffer.from('01', 'hex'),
94
- 3: Buffer.from('02', 'hex'),
95
- 4: Buffer.from('03', 'hex'),
96
- 5: Buffer.from('04', 'hex'),
97
- 6: Buffer.from('05', 'hex'),
98
- 7: Buffer.from('06', 'hex'),
99
- 8: Buffer.from('07', 'hex')
100
- },
101
- TXT_WIDTH: {
102
- 1: Buffer.from('00', 'hex'),
103
- 2: Buffer.from('10', 'hex'),
104
- 3: Buffer.from('20', 'hex'),
105
- 4: Buffer.from('30', 'hex'),
106
- 5: Buffer.from('40', 'hex'),
107
- 6: Buffer.from('50', 'hex'),
108
- 7: Buffer.from('60', 'hex'),
109
- 8: Buffer.from('70', 'hex')
110
- },
111
-
112
- TXT_UNDERL_OFF: Buffer.from('1B2D00', 'hex'), // Underline font OFF
113
- TXT_UNDERL_ON: Buffer.from('1B2D01', 'hex'), // Underline font 1-dot ON
114
- TXT_UNDERL2_ON: Buffer.from('1B2D02', 'hex'), // Underline font 2-dot ON
115
- TXT_BOLD_OFF: Buffer.from('1B4500', 'hex'), // Bold font OFF
116
- TXT_BOLD_ON: Buffer.from('1B4501', 'hex'), // Bold font ON
117
- TXT_ITALIC_OFF: Buffer.from('1B35', 'hex'), // Italic font ON
118
- TXT_ITALIC_ON: Buffer.from('1B34', 'hex'), // Italic font ON
119
-
120
- TXT_FONT_A: Buffer.from('1B4D00', 'hex'), // Font type A
121
- TXT_FONT_B: Buffer.from('1B4D01', 'hex'), // Font type B
122
- TXT_FONT_C: Buffer.from('1B4D02', 'hex'), // Font type C
123
-
124
- TXT_ALIGN_LT: Buffer.from('1B6100', 'hex'), // Left justification
125
- TXT_ALIGN_CT: Buffer.from('1B6101', 'hex'), // Centering
126
- TXT_ALIGN_RT: Buffer.from('1B6102', 'hex'), // Right justification
127
- },
128
- BARCODE_FORMAT: {
129
- BARCODE_TXT_OFF: Buffer.from('1D4800', 'hex'), // HRI barcode chars OFF
130
- BARCODE_TXT_ABV: Buffer.from('1D4801', 'hex'), // HRI barcode chars above
131
- BARCODE_TXT_BLW: Buffer.from('1D4802', 'hex'), // HRI barcode chars below
132
- BARCODE_TXT_BTH: Buffer.from('1D4803', 'hex'), // HRI barcode chars both above and below
133
-
134
- BARCODE_FONT_A: Buffer.from('1D6600', 'hex'), // Font type A for HRI barcode chars
135
- BARCODE_FONT_B: Buffer.from('1D6601', 'hex'), // Font type B for HRI barcode chars
136
-
137
- BARCODE_HEIGHT: function (height) { // Barcode Height [1-255]
138
- return Buffer.from('1D68' + numToHexString(height), 'hex');
139
- },
140
- BARCODE_WIDTH: {
141
- 1: Buffer.from('1D7702', 'hex'),
142
- 2: Buffer.from('1D7703', 'hex'),
143
- 3: Buffer.from('1D7704', 'hex'),
144
- 4: Buffer.from('1D7705', 'hex'),
145
- 5: Buffer.from('1D7706', 'hex'),
146
- },
147
- BARCODE_HEIGHT_DEFAULT: Buffer.from('1D6864', 'hex'), // Barcode height default:100
148
- BARCODE_WIDTH_DEFAULT: Buffer.from('1D7701', 'hex'), // Barcode width default:1
149
-
150
- BARCODE_UPC_A: Buffer.from('1D6B00', 'hex'), // Barcode type UPC-A
151
- BARCODE_UPC_E: Buffer.from('1D6B01', 'hex'), // Barcode type UPC-E
152
- BARCODE_EAN13: Buffer.from('1D6B02', 'hex'), // Barcode type EAN13
153
- BARCODE_EAN8: Buffer.from('1D6B03', 'hex'), // Barcode type EAN8
154
- BARCODE_CODE39: Buffer.from('1D6B04', 'hex'), // Barcode type CODE39
155
- BARCODE_ITF: Buffer.from('1D6B05', 'hex'), // Barcode type ITF
156
- BARCODE_NW7: Buffer.from('1D6B06', 'hex'), // Barcode type NW7
157
- BARCODE_CODE93: Buffer.from('1D6B48', 'hex'), // Barcode type CODE93
158
- BARCODE_CODE128: Buffer.from('1D6B49', 'hex'), // Barcode type CODE128
159
- },
160
- CODE2D_FORMAT: {
161
- TYPE_PDF417: Buffer.concat([Buffer.from('1D', 'hex'), Buffer.from('Z', 'ascii'), Buffer.from('00', 'hex')]),
162
- TYPE_DATAMATRIX: Buffer.concat([Buffer.from('1D', 'hex'), Buffer.from('Z', 'ascii'), Buffer.from('01', 'hex')]),
163
- TYPE_QR: Buffer.concat([Buffer.from('1D', 'hex'), Buffer.from('Z', 'ascii'), Buffer.from('03', 'hex')]),
164
- CODE2D: Buffer.concat([Buffer.from('1B', 'hex'), Buffer.from('Z', 'ascii')]),
165
- QR_LEVEL_L: Buffer.from('L', 'ascii'), // correct level 7%
166
- QR_LEVEL_M: Buffer.from('M', 'ascii'), // correct level 15%
167
- QR_LEVEL_Q: Buffer.from('Q', 'ascii'), // correct level 25%
168
- QR_LEVEL_H: Buffer.from('H', 'ascii') // correct level 30%
169
- },
170
- IMAGE_FORMAT: {
171
- S_RASTER_N: Buffer.from('1D763000', 'hex'), // Set raster image normal size
172
- S_RASTER_2W: Buffer.from('1D763001', 'hex'), // Set raster image double width
173
- S_RASTER_2H: Buffer.from('1D763002', 'hex'), // Set raster image double height
174
- S_RASTER_Q: Buffer.from('1D763003', 'hex'), // Set raster image quadruple
175
- },
176
- BITMAP_FORMAT: {
177
- BITMAP_S8: Buffer.from('1B2A00', 'hex'),
178
- BITMAP_D8: Buffer.from('1B2A01', 'hex'),
179
- BITMAP_S24: Buffer.from('1B2A20', 'hex'),
180
- BITMAP_D24: Buffer.from('1B2A21', 'hex')
181
- },
182
- GSV0_FORMAT: {
183
- GSV0_NORMAL: Buffer.from('1D763000', 'hex'),
184
- GSV0_DW: Buffer.from('1D763001', 'hex'),
185
- GSV0_DH: Buffer.from('1D763002', 'hex'),
186
- GSV0_DWDH: Buffer.from('1D763003', 'hex')
187
- },
188
- BEEP: Buffer.from('1B42', 'hex'), // Printer Buzzer pre hex
189
- COLOR: {
190
- 0: Buffer.from('1B7200', 'hex'), // black
191
- 1: Buffer.from('1B7201', 'hex'), // red
192
- REVERSE: Buffer.from('1DB1', 'hex'), // Reverses the colors - white text on black background
193
- UNREVERSE: Buffer.from('1DB0', 'hex') // Default: undo the reverse - black text on white background
194
- }
195
- }
196
-
197
- commands.numToHexString = numToHexString;
198
-
199
- module.exports = commands;
@@ -1,159 +0,0 @@
1
- 'use strict';
2
- const getPixels = require('get-pixels');
3
-
4
- /**
5
- * EscPos Image Object for thermal printer image processing
6
- * @class
7
- * @classdesc Converts image pixels to printer-compatible formats (bitmap/raster)
8
- * @param {Object} pixels - Pixels object formatted by the Get Pixels NPM Library
9
- * @param {Array} pixels.shape - Image dimensions [width, height, colors]
10
- * @param {Uint8Array} pixels.data - Pixel data array
11
- */
12
- class Image {
13
- constructor(pixels) {
14
- this.pixels = pixels;
15
- this.data = [];
16
- this.size = {
17
- width: this.pixels.shape[0],
18
- height: this.pixels.shape[1],
19
- colors: this.pixels.shape[2],
20
- };
21
-
22
- const rgb = (pixel) => {
23
- return {
24
- r: pixel[0],
25
- g: pixel[1],
26
- b: pixel[2],
27
- a: pixel[3]
28
- };
29
- };
30
-
31
- for (let i = 0; i < this.pixels.data.length; i += this.size.colors) {
32
- this.data.push(rgb(new Array(this.size.colors).fill(0).map((_, b) => {
33
- return this.pixels.data[i + b];
34
- })));
35
- };
36
-
37
- this.data = this.data.map((pixel) => {
38
- if (pixel.a == 0)
39
- return 0;
40
- let shouldBeWhite = pixel.r > 200 && pixel.g > 200 && pixel.b > 200;
41
- return shouldBeWhite ? 0 : 1;
42
- });
43
- }
44
-
45
- /**
46
- * Convert image to bitmap format for thermal printer
47
- * @param {Number} [density=24] - Bitmap density (dots per line)
48
- * @returns {Object} Bitmap data object with data array and density
49
- * @returns {Array} returns.data - Array of line data arrays
50
- * @returns {Number} returns.density - Density used
51
- */
52
- toBitmap(density) {
53
- density = density || 24;
54
-
55
- let ld, result = [];
56
- let x, y, b, l, i;
57
- let c = density / 8;
58
-
59
- // n blocks of lines
60
- let n = Math.ceil(this.size.height / density);
61
-
62
- for (y = 0; y < n; y++) {
63
- // line data
64
- ld = result[y] = [];
65
-
66
- for (x = 0; x < this.size.width; x++) {
67
-
68
- for (b = 0; b < density; b++) {
69
- i = x * c + (b >> 3);
70
-
71
- if (ld[i] === undefined) {
72
- ld[i] = 0;
73
- }
74
-
75
- l = y * density + b;
76
- if (l < this.size.height) {
77
- if (this.data[l * this.size.width + x]) {
78
- ld[i] += (0x80 >> (b & 0x7));
79
- }
80
- }
81
- }
82
- }
83
- }
84
-
85
- return {
86
- data: result,
87
- density: density
88
- };
89
- }
90
-
91
- /**
92
- * Convert image to raster format for thermal printer
93
- * @returns {Object} Raster data object
94
- * @returns {Array} returns.data - Raster data array
95
- * @returns {Number} returns.width - Raster width in bytes
96
- * @returns {Number} returns.height - Raster height in pixels
97
- */
98
- toRaster() {
99
- let result = [];
100
- let width = this.size.width;
101
- let height = this.size.height;
102
- let data = this.data;
103
-
104
- // n blocks of lines
105
- let n = Math.ceil(width / 8);
106
- let x, y, b, c, i;
107
-
108
- for (y = 0; y < height; y++) {
109
-
110
- for (x = 0; x < n; x++) {
111
-
112
- for (b = 0; b < 8; b++) {
113
- i = x * 8 + b;
114
-
115
- if (result[y * n + x] === undefined) {
116
- result[y * n + x] = 0;
117
- }
118
-
119
- c = x * 8 + b;
120
- if (c < width) {
121
- if (data[y * width + i]) {
122
- result[y * n + x] += (0x80 >> (b & 0x7));
123
- }
124
- }
125
- }
126
- }
127
- }
128
- return {
129
- data: result,
130
- width: n,
131
- height: height
132
- };
133
- }
134
-
135
-
136
- /**
137
- * Load an image from URL or file path
138
- * @static
139
- * @param {String} url - Image URL or file path
140
- * @param {String} [type] - Image MIME type (e.g., 'image/png', 'image/jpeg')
141
- * @returns {Promise<Image>} Promise resolving to Image instance
142
- * @throws {Error} If image cannot be loaded
143
- * @example
144
- * const image = await Image.load('/path/to/image.png', 'image/png');
145
- */
146
- static load(url, type) {
147
- return new Promise((resolve, reject) => {
148
- getPixels(url, type, (err, pixels) => {
149
- if (err)
150
- reject(err);
151
- resolve(new Image(pixels));
152
- });
153
- });
154
- }
155
- };
156
-
157
-
158
-
159
- module.exports = Image;