@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,157 +0,0 @@
1
- 'use strict';
2
-
3
- const Image = require('../../../src/printer/image');
4
-
5
- // Mock get-pixels
6
- jest.mock('get-pixels', () => {
7
- return jest.fn((url, type, callback) => {
8
- // Simula pixels de uma imagem 4x4 RGB
9
- const mockPixels = {
10
- shape: [4, 4, 3], // width, height, channels
11
- data: new Uint8Array(4 * 4 * 3).fill(0)
12
- };
13
-
14
- // Preenche alguns pixels como "pretos" (valores baixos)
15
- for (let i = 0; i < 8; i++) {
16
- mockPixels.data[i] = 50; // Pixel escuro
17
- }
18
-
19
- // Preenche outros como "brancos" (valores altos)
20
- for (let i = 24; i < 48; i++) {
21
- mockPixels.data[i] = 250; // Pixel claro
22
- }
23
-
24
- callback(null, mockPixels);
25
- });
26
- });
27
-
28
- describe('Image', () => {
29
- describe('load', () => {
30
- it('should load image from URL', async () => {
31
- const image = await Image.load('test.png', 'image/png');
32
- expect(image).toBeInstanceOf(Image);
33
- expect(image.size.width).toBe(4);
34
- expect(image.size.height).toBe(4);
35
- expect(image.size.colors).toBe(3);
36
- });
37
-
38
- it('should reject on error', async () => {
39
- const getPixels = require('get-pixels');
40
- getPixels.mockImplementationOnce((url, type, callback) => {
41
- callback(new Error('Load failed'), null);
42
- });
43
-
44
- await expect(Image.load('invalid.png', 'image/png')).rejects.toThrow('Load failed');
45
- });
46
- });
47
-
48
- describe('Constructor', () => {
49
- it('should create image from pixels', () => {
50
- const mockPixels = {
51
- shape: [2, 2, 3],
52
- data: new Uint8Array([0, 0, 0, 255, 255, 255, 0, 0, 0, 255, 255, 255])
53
- };
54
-
55
- const image = new Image(mockPixels);
56
- expect(image.size.width).toBe(2);
57
- expect(image.size.height).toBe(2);
58
- expect(image.size.colors).toBe(3);
59
- expect(image.data.length).toBe(4);
60
- });
61
-
62
- it('should convert pixels to binary data', () => {
63
- const mockPixels = {
64
- shape: [2, 2, 4], // width, height, channels (RGBA)
65
- data: new Uint8Array([
66
- 0, 0, 0, 255, // Pixel 0: preto (RGB=0,0,0)
67
- 255, 255, 255, 255, // Pixel 1: branco (RGB=255,255,255)
68
- 0, 0, 0, 255, // Pixel 2: preto (RGB=0,0,0)
69
- 255, 255, 255, 255 // Pixel 3: branco (RGB=255,255,255)
70
- ])
71
- };
72
-
73
- const image = new Image(mockPixels);
74
- expect(image.data[0]).toBe(1); // Preto = 1 (r=0, g=0, b=0, não é branco)
75
- expect(image.data[1]).toBe(0); // Branco = 0 (r>200, g>200, b>200)
76
- expect(image.data[2]).toBe(1); // Preto = 1
77
- expect(image.data[3]).toBe(0); // Branco = 0
78
- });
79
-
80
- it('should handle transparent pixels', () => {
81
- const mockPixels = {
82
- shape: [1, 1, 4], // RGBA
83
- data: new Uint8Array([255, 255, 255, 0]) // Transparente
84
- };
85
-
86
- const image = new Image(mockPixels);
87
- expect(image.data[0]).toBe(0); // Transparente = 0
88
- });
89
- });
90
-
91
- describe('toBitmap', () => {
92
- it('should convert to bitmap format', async () => {
93
- const image = await Image.load('test.png', 'image/png');
94
- const bitmap = image.toBitmap(24);
95
-
96
- expect(bitmap).toHaveProperty('data');
97
- expect(bitmap).toHaveProperty('density');
98
- expect(bitmap.density).toBe(24);
99
- expect(Array.isArray(bitmap.data)).toBe(true);
100
- });
101
-
102
- it('should use default density of 24', async () => {
103
- const image = await Image.load('test.png', 'image/png');
104
- const bitmap = image.toBitmap();
105
-
106
- expect(bitmap.density).toBe(24);
107
- });
108
-
109
- it('should handle different densities', async () => {
110
- const image = await Image.load('test.png', 'image/png');
111
- const bitmap8 = image.toBitmap(8);
112
- const bitmap24 = image.toBitmap(24);
113
-
114
- expect(bitmap8.density).toBe(8);
115
- expect(bitmap24.density).toBe(24);
116
- });
117
-
118
- it('should generate correct bitmap structure', async () => {
119
- const image = await Image.load('test.png', 'image/png');
120
- const bitmap = image.toBitmap(8);
121
-
122
- expect(bitmap.data.length).toBeGreaterThan(0);
123
- bitmap.data.forEach(line => {
124
- expect(Array.isArray(line)).toBe(true);
125
- });
126
- });
127
- });
128
-
129
- describe('toRaster', () => {
130
- it('should convert to raster format', async () => {
131
- const image = await Image.load('test.png', 'image/png');
132
- const raster = image.toRaster();
133
-
134
- expect(raster).toHaveProperty('data');
135
- expect(raster).toHaveProperty('width');
136
- expect(raster).toHaveProperty('height');
137
- expect(Array.isArray(raster.data)).toBe(true);
138
- });
139
-
140
- it('should calculate correct raster dimensions', async () => {
141
- const image = await Image.load('test.png', 'image/png');
142
- const raster = image.toRaster();
143
-
144
- // Width should be rounded up to nearest 8-bit boundary
145
- expect(raster.width).toBeGreaterThan(0);
146
- expect(raster.height).toBe(image.size.height);
147
- });
148
-
149
- it('should generate correct raster data structure', async () => {
150
- const image = await Image.load('test.png', 'image/png');
151
- const raster = image.toRaster();
152
-
153
- expect(raster.data.length).toBe(raster.width * raster.height);
154
- });
155
- });
156
- });
157
-
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- const Printer = require('../../../src/printer');
4
-
5
- describe('SpecBuffer', () => {
6
- let printer;
7
- let mockAdapter;
8
-
9
- beforeEach(() => {
10
- mockAdapter = {
11
- write: jest.fn().mockResolvedValue(true)
12
- };
13
- printer = new Printer(mockAdapter);
14
- });
15
-
16
- describe('Buffer Operations', () => {
17
- it('should initialize with empty buffer', () => {
18
- const buffer = printer.buffer.flush();
19
- expect(buffer.length).toBe(0);
20
- });
21
-
22
- it('should write data to buffer', () => {
23
- printer.buffer.write('Hello', 'ascii');
24
- const buffer = printer.buffer.flush();
25
- expect(buffer.toString('ascii')).toBe('Hello');
26
- });
27
-
28
- it('should write hex data to buffer', () => {
29
- printer.buffer.write('1B40', 'hex');
30
- const buffer = printer.buffer.flush();
31
- expect(buffer.toString('hex').toUpperCase()).toBe('1B40');
32
- });
33
-
34
- it('should concatenate multiple writes', () => {
35
- printer.buffer.write('Hello', 'ascii');
36
- printer.buffer.write(' World', 'ascii');
37
- const buffer = printer.buffer.flush();
38
- expect(buffer.toString('ascii')).toBe('Hello World');
39
- });
40
-
41
- it('should flush and clear buffer', () => {
42
- printer.buffer.write('Test', 'ascii');
43
- const buffer1 = printer.buffer.flush();
44
- const buffer2 = printer.buffer.flush();
45
-
46
- expect(buffer1.toString('ascii')).toBe('Test');
47
- expect(buffer2.length).toBe(0);
48
- });
49
-
50
- it('should handle Buffer objects', () => {
51
- const testBuffer = Buffer.from('Test', 'ascii');
52
- // SpecBuffer.write expects (data, type), but can handle Buffer directly
53
- // We'll test through printer methods instead
54
- printer.print('Test');
55
- const buffer = printer.buffer.flush();
56
- expect(buffer.toString('ascii')).toBe('Test');
57
- });
58
- });
59
- });
60
-
@@ -1,109 +0,0 @@
1
- 'use strict';
2
-
3
- const commands = require('../../../src/printer/commands');
4
-
5
- describe('Commands', () => {
6
- describe('numToHexString', () => {
7
- it('should convert number to hex string', () => {
8
- const result = commands.numToHexString(255);
9
- expect(result).toBe('ff');
10
- });
11
-
12
- it('should pad odd-length hex strings with leading zero', () => {
13
- const result = commands.numToHexString(15);
14
- expect(result).toBe('0f');
15
- });
16
-
17
- it('should handle zero', () => {
18
- const result = commands.numToHexString(0);
19
- expect(result).toBe('00');
20
- });
21
-
22
- it('should handle large numbers', () => {
23
- const result = commands.numToHexString(256);
24
- expect(result).toBe('0100');
25
- });
26
-
27
- it('should return empty string for NaN input', () => {
28
- const result = commands.numToHexString('invalid');
29
- expect(result).toBe('');
30
- });
31
-
32
- it('should return empty string for NaN value', () => {
33
- const result = commands.numToHexString(NaN);
34
- expect(result).toBe('');
35
- });
36
-
37
- it('should return empty string for undefined', () => {
38
- const result = commands.numToHexString(undefined);
39
- expect(result).toBe('');
40
- });
41
- });
42
-
43
- describe('TXT_CUSTOM_SIZE', () => {
44
- it('should clamp width to 8 when width > 8', () => {
45
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(10, 2);
46
- // When width is clamped to 8, the calculation is:
47
- // widthDec = (8 - 1) * 16 = 112 (0x70)
48
- // heightDec = (2 - 1) = 1 (0x01)
49
- // sizeDec = 112 + 1 = 113 (0x71)
50
- expect(result.toString('hex').toUpperCase()).toContain('1D2171');
51
- });
52
-
53
- it('should clamp width to 1 when width < 1', () => {
54
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(0, 2);
55
- // When width is clamped to 1, the calculation is:
56
- // widthDec = (1 - 1) * 16 = 0 (0x00)
57
- // heightDec = (2 - 1) = 1 (0x01)
58
- // sizeDec = 0 + 1 = 1 (0x01)
59
- expect(result.toString('hex').toUpperCase()).toContain('1D2101');
60
- });
61
-
62
- it('should clamp height to 8 when height > 8', () => {
63
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(2, 10);
64
- // When height is clamped to 8, the calculation is:
65
- // widthDec = (2 - 1) * 16 = 16 (0x10)
66
- // heightDec = (8 - 1) = 7 (0x07)
67
- // sizeDec = 16 + 7 = 23 (0x17)
68
- expect(result.toString('hex').toUpperCase()).toContain('1D2117');
69
- });
70
-
71
- it('should clamp height to 1 when height < 1', () => {
72
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(2, 0);
73
- // When height is clamped to 1, the calculation is:
74
- // widthDec = (2 - 1) * 16 = 16 (0x10)
75
- // heightDec = (1 - 1) = 0 (0x00)
76
- // sizeDec = 16 + 0 = 16 (0x10)
77
- expect(result.toString('hex').toUpperCase()).toContain('1D2110');
78
- });
79
-
80
- it('should clamp both width and height when both are out of range', () => {
81
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(10, 0);
82
- // When both are clamped: width=8, height=1
83
- // widthDec = (8 - 1) * 16 = 112 (0x70)
84
- // heightDec = (1 - 1) = 0 (0x00)
85
- // sizeDec = 112 + 0 = 112 (0x70)
86
- expect(result.toString('hex').toUpperCase()).toContain('1D2170');
87
- });
88
-
89
- it('should handle valid range values correctly', () => {
90
- const result = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(4, 3);
91
- // widthDec = (4 - 1) * 16 = 48 (0x30)
92
- // heightDec = (3 - 1) = 2 (0x02)
93
- // sizeDec = 48 + 2 = 50 (0x32)
94
- expect(result.toString('hex').toUpperCase()).toContain('1D2132');
95
- });
96
-
97
- it('should handle boundary values (1 and 8)', () => {
98
- const result1 = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(1, 1);
99
- expect(result1.toString('hex').toUpperCase()).toContain('1D2100');
100
-
101
- const result2 = commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(8, 8);
102
- // widthDec = (8 - 1) * 16 = 112 (0x70)
103
- // heightDec = (8 - 1) = 7 (0x07)
104
- // sizeDec = 112 + 7 = 119 (0x77)
105
- expect(result2.toString('hex').toUpperCase()).toContain('1D2177');
106
- });
107
- });
108
- });
109
-