@thermal-print/escpos 0.1.0 → 0.3.0

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.
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * ESC/POS Command Set
4
3
  *
@@ -8,38 +7,34 @@
8
7
  * This file contains all documented ESC/POS commands organized by category.
9
8
  * Commands are compatible with standard ESC/POS thermal printers.
10
9
  */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UNDERLINE_2DOT = exports.UNDERLINE_1DOT = exports.UPSIDE_DOWN_OFF = exports.UPSIDE_DOWN_ON = exports.ROTATE_90_OFF = exports.ROTATE_90_ON = exports.SELECT_FONT_D = exports.selectFont = exports.CharacterFont = exports.DOUBLE_STRIKE_OFF = exports.DOUBLE_STRIKE_ON = exports.CLEAR_TABS = exports.setTabPositions = exports.setCharacterSpacing = exports.setRelativePosition = exports.setAbsolutePosition = exports.realtimePulse = exports.realtimeRequest = exports.transmitRealtimeStatus = exports.encodeText = exports.generateRasterImage = exports.generateQRCode = exports.CODEPAGE_WPC1252 = exports.CODEPAGE_CP860 = exports.CODEPAGE_CP437 = exports.cutWithFeed = exports.CUT_PARTIAL = exports.CUT_FULL = exports.feedLines = exports.LINE_FEED = exports.LINE_SPACING_DEFAULT = exports.setLineSpacing = exports.calculateCharacterSize = exports.UNDERLINE_OFF = exports.UNDERLINE_ON = exports.BOLD_OFF = exports.BOLD_ON = exports.ALIGN_RIGHT = exports.ALIGN_CENTER = exports.ALIGN_LEFT = exports.INIT = exports.GS = exports.FS = exports.ESC = exports.CAN = exports.DLE = exports.CR = exports.FF = exports.LF = exports.HT = void 0;
13
- exports.selectCharacterSize = exports.generatePDF417 = exports.printPDF417 = exports.storePDF417Data = exports.setPDF417ErrorCorrection = exports.setPDF417RowHeight = exports.setPDF417Width = exports.setPDF417Rows = exports.setPDF417Columns = exports.printBarcodeCODE128 = exports.printBarcodeCODE93 = exports.printBarcodeCODABAR = exports.printBarcodeITF = exports.printBarcodeCODE39 = exports.printBarcodeEAN8 = exports.printBarcodeEAN13 = exports.printBarcodeUPCE = exports.printBarcodeUPCA = exports.printBarcodeWithLength = exports.printBarcode = exports.BarcodeType = exports.setBarcodeWidth = exports.setBarcodeHeight = exports.setBarcodeFont = exports.setBarcodeHRI = exports.BarcodeHRIPosition = exports.defineNVBitImage = exports.printNVBitImage = exports.printDownloadedBitImage = exports.DownloadedImageMode = exports.defineDownloadedBitImage = exports.printBitImage = exports.BitImageMode = exports.setCodePage = exports.CodePage = exports.selectInternationalCharset = exports.InternationalCharset = exports.disablePanelButtons = exports.enablePanelButtons = exports.selectPaperSensorStop = exports.selectPaperSensorOutput = exports.generatePulse = exports.selectPeripheral = exports.cutAndFeedPartial = exports.cutAndFeedFull = exports.CUT_PARTIAL_ESC = exports.CUT_FULL_ESC = exports.printAndReverseFeed = exports.printAndFeed = exports.LINE_SPACING_DEFAULT_ALT = void 0;
14
- exports.executeTestPrint = exports.CANCEL = exports.UNIDIRECTIONAL_OFF = exports.UNIDIRECTIONAL_ON = exports.executeMacro = exports.END_MACRO = exports.START_MACRO = exports.setPrintingAreaWidth = exports.setLeftMargin = exports.requestStatus = exports.StatusType = exports.requestPrinterID = exports.PrinterIDType = exports.disableASB = exports.enableASB = exports.setCharacterSmoothing = exports.setCharacterColor = exports.REVERSE_PRINT_OFF = exports.REVERSE_PRINT_ON = void 0;
15
- const cp860_1 = require("../encodings/cp860");
10
+ import { encodeCP860 } from "../encodings/cp860";
16
11
  // ============================================================================
17
12
  // CONTROL CHARACTERS
18
13
  // ============================================================================
19
- exports.HT = 0x09; // Horizontal Tab
20
- exports.LF = 0x0a; // Line Feed
21
- exports.FF = 0x0c; // Form Feed
22
- exports.CR = 0x0d; // Carriage Return
23
- exports.DLE = 0x10; // Data Link Escape
24
- exports.CAN = 0x18; // Cancel
25
- exports.ESC = 0x1b; // Escape
26
- exports.FS = 0x1c; // File Separator
27
- exports.GS = 0x1d; // Group Separator
14
+ export const HT = 0x09; // Horizontal Tab
15
+ export const LF = 0x0a; // Line Feed
16
+ export const FF = 0x0c; // Form Feed
17
+ export const CR = 0x0d; // Carriage Return
18
+ export const DLE = 0x10; // Data Link Escape
19
+ export const CAN = 0x18; // Cancel
20
+ export const ESC = 0x1b; // Escape
21
+ export const FS = 0x1c; // File Separator
22
+ export const GS = 0x1d; // Group Separator
28
23
  // Initialize printer
29
24
  // ESC @ - Reset printer to default state
30
- exports.INIT = [exports.ESC, 0x40];
25
+ export const INIT = [ESC, 0x40];
31
26
  // Text alignment
32
27
  // ESC a n - Set text alignment (n: 0=left, 1=center, 2=right)
33
- exports.ALIGN_LEFT = [exports.ESC, 0x61, 0x00];
34
- exports.ALIGN_CENTER = [exports.ESC, 0x61, 0x01];
35
- exports.ALIGN_RIGHT = [exports.ESC, 0x61, 0x02];
28
+ export const ALIGN_LEFT = [ESC, 0x61, 0x00];
29
+ export const ALIGN_CENTER = [ESC, 0x61, 0x01];
30
+ export const ALIGN_RIGHT = [ESC, 0x61, 0x02];
36
31
  // Text emphasis
37
32
  // ESC E n - Turn bold on/off (n: 0=off, 1=on)
38
- exports.BOLD_ON = [exports.ESC, 0x45, 0x01];
39
- exports.BOLD_OFF = [exports.ESC, 0x45, 0x00];
33
+ export const BOLD_ON = [ESC, 0x45, 0x01];
34
+ export const BOLD_OFF = [ESC, 0x45, 0x00];
40
35
  // ESC - n - Turn underline on/off (n: 0=off, 1=on, 2=double)
41
- exports.UNDERLINE_ON = [exports.ESC, 0x2d, 0x01];
42
- exports.UNDERLINE_OFF = [exports.ESC, 0x2d, 0x00];
36
+ export const UNDERLINE_ON = [ESC, 0x2d, 0x01];
37
+ export const UNDERLINE_OFF = [ESC, 0x2d, 0x00];
43
38
  /**
44
39
  * Calculate character size using ESC ! command (compatible with more printers)
45
40
  * ESC ! only supports up to 2x2 character size
@@ -48,7 +43,7 @@ exports.UNDERLINE_OFF = [exports.ESC, 0x2d, 0x00];
48
43
  * @param bold - Whether text should be bold (optional, default: false)
49
44
  * @returns ESC/POS ESC ! n command bytes
50
45
  */
51
- const calculateCharacterSize = (width, height, bold = false) => {
46
+ export const calculateCharacterSize = (width, height, bold = false) => {
52
47
  // ESC ! command format:
53
48
  // Bit 0: Character font (0=Font A, 1=Font B)
54
49
  // Bit 3: Emphasis (bold)
@@ -71,38 +66,34 @@ const calculateCharacterSize = (width, height, bold = false) => {
71
66
  if (bold) {
72
67
  n |= 0x08;
73
68
  }
74
- return [exports.ESC, 0x21, n];
69
+ return [ESC, 0x21, n];
75
70
  };
76
- exports.calculateCharacterSize = calculateCharacterSize;
77
71
  // Line spacing
78
72
  // ESC 3 n - Set line spacing to n dots
79
73
  // Note: Using minimum of 18 dots for consistency with ESC/Bematech protocol
80
- const setLineSpacing = (dots) => {
74
+ export const setLineSpacing = (dots) => {
81
75
  const value = Math.max(18, Math.min(255, dots));
82
- return [exports.ESC, 0x33, value];
76
+ return [ESC, 0x33, value];
83
77
  };
84
- exports.setLineSpacing = setLineSpacing;
85
78
  // Default line spacing (30 dots = ~3.75mm)
86
- exports.LINE_SPACING_DEFAULT = [exports.ESC, 0x33, 30];
79
+ export const LINE_SPACING_DEFAULT = [ESC, 0x33, 30];
87
80
  // Paper control
88
81
  // LF - Line feed (move paper up one line)
89
- exports.LINE_FEED = [exports.LF];
82
+ export const LINE_FEED = [LF];
90
83
  // ESC d n - Print and feed n lines
91
- const feedLines = (lines) => [exports.ESC, 0x64, lines];
92
- exports.feedLines = feedLines;
84
+ export const feedLines = (lines) => [ESC, 0x64, lines];
93
85
  // GS V m - Paper cut
94
86
  // m: 0=full cut, 1=partial cut
95
- exports.CUT_FULL = [exports.GS, 0x56, 0x00];
96
- exports.CUT_PARTIAL = [exports.GS, 0x56, 0x01];
87
+ export const CUT_FULL = [GS, 0x56, 0x00];
88
+ export const CUT_PARTIAL = [GS, 0x56, 0x01];
97
89
  // Alternative: GS V m n - Cut with feed
98
- const cutWithFeed = (lines) => [exports.GS, 0x56, 0x41, lines];
99
- exports.cutWithFeed = cutWithFeed;
90
+ export const cutWithFeed = (lines) => [GS, 0x56, 0x41, lines];
100
91
  // Character code table
101
92
  // ESC t n - Select character code table
102
93
  // Common tables: 0=CP437, 3=CP860 (Portuguese), 16=WPC1252
103
- exports.CODEPAGE_CP437 = [exports.ESC, 0x74, 0x00]; // USA
104
- exports.CODEPAGE_CP860 = [exports.ESC, 0x74, 0x03]; // Portuguese
105
- exports.CODEPAGE_WPC1252 = [exports.ESC, 0x74, 0x10]; // Windows Latin-1
94
+ export const CODEPAGE_CP437 = [ESC, 0x74, 0x00]; // USA
95
+ export const CODEPAGE_CP860 = [ESC, 0x74, 0x03]; // Portuguese
96
+ export const CODEPAGE_WPC1252 = [ESC, 0x74, 0x10]; // Windows Latin-1
106
97
  // Barcode and QR Code
107
98
  // QR Code: GS ( k pL pH cn fn n1 n2 [data]
108
99
  // This is a complex command, implemented as a function
@@ -112,27 +103,26 @@ exports.CODEPAGE_WPC1252 = [exports.ESC, 0x74, 0x10]; // Windows Latin-1
112
103
  * @param size - QR code module size (1-16, default 6)
113
104
  * @returns ESC/POS command bytes
114
105
  */
115
- const generateQRCode = (data, size = 6) => {
106
+ export const generateQRCode = (data, size = 6) => {
116
107
  const commands = [];
117
108
  // QR Code model (function 165, cn=49, fn=65, n=48/49/50)
118
109
  // Model 2 (most common)
119
- commands.push(exports.GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00);
110
+ commands.push(GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00);
120
111
  // QR Code size (function 167, cn=49, fn=67, n=size)
121
- commands.push(exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, size);
112
+ commands.push(GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, size);
122
113
  // QR Code error correction (function 169, cn=49, fn=69, n=48-51)
123
114
  // 48=L(7%), 49=M(15%), 50=Q(25%), 51=H(30%)
124
- commands.push(exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x31);
115
+ commands.push(GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x31);
125
116
  // Store QR code data (function 180, cn=49, fn=80)
126
117
  const dataBytes = new TextEncoder().encode(data);
127
118
  const pL = (dataBytes.length + 3) % 256;
128
119
  const pH = Math.floor((dataBytes.length + 3) / 256);
129
- commands.push(exports.GS, 0x28, 0x6b, pL, pH, 0x31, 0x50, 0x30);
120
+ commands.push(GS, 0x28, 0x6b, pL, pH, 0x31, 0x50, 0x30);
130
121
  commands.push(...Array.from(dataBytes));
131
122
  // Print QR code (function 181, cn=49, fn=81)
132
- commands.push(exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30);
123
+ commands.push(GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30);
133
124
  return commands;
134
125
  };
135
- exports.generateQRCode = generateQRCode;
136
126
  /**
137
127
  * Generate raster image command (GS v 0)
138
128
  * @param imageData - Monochrome bitmap data (1 bit per pixel, 1=black, 0=white)
@@ -140,7 +130,7 @@ exports.generateQRCode = generateQRCode;
140
130
  * @param height - Image height in pixels
141
131
  * @returns ESC/POS command bytes
142
132
  */
143
- const generateRasterImage = (imageData, width, height) => {
133
+ export const generateRasterImage = (imageData, width, height) => {
144
134
  const commands = [];
145
135
  // Calculate bytes per line (width in bytes, rounded up to nearest byte)
146
136
  const bytesPerLine = Math.ceil(width / 8);
@@ -149,7 +139,7 @@ const generateRasterImage = (imageData, width, height) => {
149
139
  // xL xH = width in bytes (little endian)
150
140
  // yL yH = height in dots (little endian)
151
141
  // d1...dk = raster image data
152
- commands.push(exports.GS, 0x76, 0x30, 0x00); // GS v 0 m (m=0: normal)
142
+ commands.push(GS, 0x76, 0x30, 0x00); // GS v 0 m (m=0: normal)
153
143
  // Width in bytes (little endian)
154
144
  commands.push(bytesPerLine & 0xff);
155
145
  commands.push((bytesPerLine >> 8) & 0xff);
@@ -160,17 +150,15 @@ const generateRasterImage = (imageData, width, height) => {
160
150
  commands.push(...imageData);
161
151
  return commands;
162
152
  };
163
- exports.generateRasterImage = generateRasterImage;
164
153
  /**
165
154
  * Text encoding helper
166
155
  * Converts string to CP860 byte array for Brazilian Portuguese thermal printers
167
156
  */
168
- const encodeText = (text) => {
157
+ export const encodeText = (text) => {
169
158
  // CP860 is the standard codepage for Portuguese thermal printers
170
159
  // Supports: ç Ç á é í ó ú à ã õ â ê ô and other Portuguese characters
171
- return (0, cp860_1.encodeCP860)(text);
160
+ return encodeCP860(text);
172
161
  };
173
- exports.encodeText = encodeText;
174
162
  // ============================================================================
175
163
  // REAL-TIME COMMANDS
176
164
  // ============================================================================
@@ -181,33 +169,30 @@ exports.encodeText = encodeText;
181
169
  * n = 3: Transmit error status
182
170
  * n = 4: Transmit paper roll sensor status
183
171
  */
184
- const transmitRealtimeStatus = (n) => [
185
- exports.DLE,
172
+ export const transmitRealtimeStatus = (n) => [
173
+ DLE,
186
174
  0x04,
187
175
  n,
188
176
  ];
189
- exports.transmitRealtimeStatus = transmitRealtimeStatus;
190
177
  /**
191
178
  * DLE ENQ n - Real-time request to printer
192
179
  * n = 1: Recover from error and restart printing
193
180
  * n = 2: Clear buffer
194
181
  */
195
- const realtimeRequest = (n) => [exports.DLE, 0x05, n];
196
- exports.realtimeRequest = realtimeRequest;
182
+ export const realtimeRequest = (n) => [DLE, 0x05, n];
197
183
  /**
198
184
  * DLE DC4 fn a b - Generate pulse in real-time
199
185
  * fn = 1: Generate pulse
200
186
  * a = drawer (0 or 1)
201
187
  * b = pulse time
202
188
  */
203
- const realtimePulse = (drawer, pulseTime) => [
204
- exports.DLE,
189
+ export const realtimePulse = (drawer, pulseTime) => [
190
+ DLE,
205
191
  0x14,
206
192
  0x01,
207
193
  drawer,
208
194
  pulseTime,
209
195
  ];
210
- exports.realtimePulse = realtimePulse;
211
196
  // ============================================================================
212
197
  // TEXT POSITION & LAYOUT
213
198
  // ============================================================================
@@ -215,51 +200,47 @@ exports.realtimePulse = realtimePulse;
215
200
  * ESC $ nL nH - Set absolute print position
216
201
  * Position = ((nH × 256) + nL) × (horizontal motion unit)
217
202
  */
218
- const setAbsolutePosition = (position) => {
203
+ export const setAbsolutePosition = (position) => {
219
204
  const nL = position & 0xff;
220
205
  const nH = (position >> 8) & 0xff;
221
- return [exports.ESC, 0x24, nL, nH];
206
+ return [ESC, 0x24, nL, nH];
222
207
  };
223
- exports.setAbsolutePosition = setAbsolutePosition;
224
208
  /**
225
209
  * ESC \ nL nH - Set relative print position
226
210
  * Relative position = ((nH × 256) + nL) × (horizontal motion unit)
227
211
  * Supports negative values (two's complement)
228
212
  */
229
- const setRelativePosition = (position) => {
213
+ export const setRelativePosition = (position) => {
230
214
  const nL = position & 0xff;
231
215
  const nH = (position >> 8) & 0xff;
232
- return [exports.ESC, 0x5c, nL, nH];
216
+ return [ESC, 0x5c, nL, nH];
233
217
  };
234
- exports.setRelativePosition = setRelativePosition;
235
218
  /**
236
219
  * ESC SP n - Set right-side character spacing
237
220
  * Range: 0 ≤ n ≤ 255
238
221
  * Spacing = n × (horizontal motion unit)
239
222
  */
240
- const setCharacterSpacing = (dots) => [
241
- exports.ESC,
223
+ export const setCharacterSpacing = (dots) => [
224
+ ESC,
242
225
  0x20,
243
226
  Math.max(0, Math.min(255, dots)),
244
227
  ];
245
- exports.setCharacterSpacing = setCharacterSpacing;
246
228
  /**
247
229
  * ESC D n1...nk NUL - Set horizontal tab positions
248
230
  * n1-nk: Tab positions (1-255), up to 32 positions
249
231
  * Must be in ascending order, terminated with NUL
250
232
  */
251
- const setTabPositions = (positions) => {
233
+ export const setTabPositions = (positions) => {
252
234
  const validPositions = positions
253
235
  .filter((p) => p >= 1 && p <= 255)
254
236
  .slice(0, 32)
255
237
  .sort((a, b) => a - b);
256
- return [exports.ESC, 0x44, ...validPositions, 0x00];
238
+ return [ESC, 0x44, ...validPositions, 0x00];
257
239
  };
258
- exports.setTabPositions = setTabPositions;
259
240
  /**
260
241
  * ESC D NUL - Cancel all horizontal tab positions
261
242
  */
262
- exports.CLEAR_TABS = [exports.ESC, 0x44, 0x00];
243
+ export const CLEAR_TABS = [ESC, 0x44, 0x00];
263
244
  // ============================================================================
264
245
  // TEXT EMPHASIS & STYLES
265
246
  // ============================================================================
@@ -268,53 +249,52 @@ exports.CLEAR_TABS = [exports.ESC, 0x44, 0x00];
268
249
  * n = 0 or 48: Turn off double-strike mode
269
250
  * n = 1 or 49: Turn on double-strike mode
270
251
  */
271
- exports.DOUBLE_STRIKE_ON = [exports.ESC, 0x47, 0x01];
272
- exports.DOUBLE_STRIKE_OFF = [exports.ESC, 0x47, 0x00];
252
+ export const DOUBLE_STRIKE_ON = [ESC, 0x47, 0x01];
253
+ export const DOUBLE_STRIKE_OFF = [ESC, 0x47, 0x00];
273
254
  /**
274
255
  * Character font selection
275
256
  */
276
- var CharacterFont;
257
+ export var CharacterFont;
277
258
  (function (CharacterFont) {
278
259
  CharacterFont[CharacterFont["FONT_A"] = 0] = "FONT_A";
279
260
  CharacterFont[CharacterFont["FONT_B"] = 1] = "FONT_B";
280
261
  CharacterFont[CharacterFont["FONT_C"] = 2] = "FONT_C";
281
- })(CharacterFont || (exports.CharacterFont = CharacterFont = {}));
262
+ })(CharacterFont || (CharacterFont = {}));
282
263
  /**
283
264
  * ESC M n - Select character font
284
265
  * n = 0 or 48: Font A (12×24)
285
266
  * n = 1 or 49: Font B (9×17)
286
267
  * n = 2 or 50: Font C (printer dependent)
287
268
  */
288
- const selectFont = (font) => [exports.ESC, 0x4d, font];
289
- exports.selectFont = selectFont;
269
+ export const selectFont = (font) => [ESC, 0x4d, font];
290
270
  /**
291
271
  * ESC U - Select Font D (Phoenix printers only)
292
272
  * Font D: 16×24 dots
293
273
  * Warning: This is a Phoenix-specific feature and may not work on all printers
294
274
  */
295
- exports.SELECT_FONT_D = [exports.ESC, 0x51];
275
+ export const SELECT_FONT_D = [ESC, 0x51];
296
276
  /**
297
277
  * ESC V n - Turn 90° clockwise rotation mode on/off
298
278
  * n = 0 or 48: Turn off 90° clockwise rotation mode
299
279
  * n = 1 or 49: Turn on 90° clockwise rotation mode
300
280
  */
301
- exports.ROTATE_90_ON = [exports.ESC, 0x56, 0x01];
302
- exports.ROTATE_90_OFF = [exports.ESC, 0x56, 0x00];
281
+ export const ROTATE_90_ON = [ESC, 0x56, 0x01];
282
+ export const ROTATE_90_OFF = [ESC, 0x56, 0x00];
303
283
  /**
304
284
  * ESC { n - Turn upside-down printing mode on/off
305
285
  * n = 0 or 48: Turn off upside-down printing mode
306
286
  * n = 1 or 49: Turn on upside-down printing mode
307
287
  */
308
- exports.UPSIDE_DOWN_ON = [exports.ESC, 0x7b, 0x01];
309
- exports.UPSIDE_DOWN_OFF = [exports.ESC, 0x7b, 0x00];
288
+ export const UPSIDE_DOWN_ON = [ESC, 0x7b, 0x01];
289
+ export const UPSIDE_DOWN_OFF = [ESC, 0x7b, 0x00];
310
290
  /**
311
291
  * ESC - n - Turn underline mode on/off with thickness selection
312
292
  * n = 0 or 48: Turn off underline mode
313
293
  * n = 1 or 49: Turn on underline mode (1-dot thick)
314
294
  * n = 2 or 50: Turn on underline mode (2-dots thick)
315
295
  */
316
- exports.UNDERLINE_1DOT = [exports.ESC, 0x2d, 0x01];
317
- exports.UNDERLINE_2DOT = [exports.ESC, 0x2d, 0x02];
296
+ export const UNDERLINE_1DOT = [ESC, 0x2d, 0x01];
297
+ export const UNDERLINE_2DOT = [ESC, 0x2d, 0x02];
318
298
  // ============================================================================
319
299
  // LINE SPACING & PAPER CONTROL (ADDITIONAL)
320
300
  // ============================================================================
@@ -322,29 +302,27 @@ exports.UNDERLINE_2DOT = [exports.ESC, 0x2d, 0x02];
322
302
  * ESC 2 - Select default line spacing
323
303
  * Sets line spacing to approximately 4.23mm (1/6 inch)
324
304
  */
325
- exports.LINE_SPACING_DEFAULT_ALT = [exports.ESC, 0x32, 0x5];
305
+ export const LINE_SPACING_DEFAULT_ALT = [ESC, 0x32, 0x5];
326
306
  /**
327
307
  * ESC J n - Print and feed paper
328
308
  * Range: 0 ≤ n ≤ 255
329
309
  * Feed amount = n × (vertical motion unit)
330
310
  */
331
- const printAndFeed = (dots) => [
332
- exports.ESC,
311
+ export const printAndFeed = (dots) => [
312
+ ESC,
333
313
  0x4a,
334
314
  Math.max(0, Math.min(255, dots)),
335
315
  ];
336
- exports.printAndFeed = printAndFeed;
337
316
  /**
338
317
  * ESC K n - Print and reverse feed
339
318
  * Range: 0 ≤ n ≤ 255
340
319
  * Reverse feed amount = n × (vertical motion unit)
341
320
  */
342
- const printAndReverseFeed = (dots) => [
343
- exports.ESC,
321
+ export const printAndReverseFeed = (dots) => [
322
+ ESC,
344
323
  0x4b,
345
324
  Math.max(0, Math.min(255, dots)),
346
325
  ];
347
- exports.printAndReverseFeed = printAndReverseFeed;
348
326
  // ============================================================================
349
327
  // PAPER CUTTING (ADDITIONAL)
350
328
  // ============================================================================
@@ -352,32 +330,30 @@ exports.printAndReverseFeed = printAndReverseFeed;
352
330
  * ESC i - Full cut
353
331
  * Executes a full cut (cuts paper completely)
354
332
  */
355
- exports.CUT_FULL_ESC = [exports.ESC, 0x69];
333
+ export const CUT_FULL_ESC = [ESC, 0x69];
356
334
  /**
357
335
  * ESC m - Partial cut
358
336
  * Executes a partial cut (leaves connection point)
359
337
  */
360
- exports.CUT_PARTIAL_ESC = [exports.ESC, 0x6d];
338
+ export const CUT_PARTIAL_ESC = [ESC, 0x6d];
361
339
  /**
362
340
  * GS V m n - Cut paper and feed
363
341
  * m = 65 (0x41): Feed then full cut
364
342
  * m = 66 (0x42): Feed then partial cut
365
343
  * n = feed amount before cut
366
344
  */
367
- const cutAndFeedFull = (dots) => [
368
- exports.GS,
345
+ export const cutAndFeedFull = (dots) => [
346
+ GS,
369
347
  0x56,
370
348
  0x41,
371
349
  Math.max(0, Math.min(255, dots)),
372
350
  ];
373
- exports.cutAndFeedFull = cutAndFeedFull;
374
- const cutAndFeedPartial = (dots) => [
375
- exports.GS,
351
+ export const cutAndFeedPartial = (dots) => [
352
+ GS,
376
353
  0x56,
377
354
  0x42,
378
355
  Math.max(0, Math.min(255, dots)),
379
356
  ];
380
- exports.cutAndFeedPartial = cutAndFeedPartial;
381
357
  // ============================================================================
382
358
  // PERIPHERAL DEVICE CONTROL
383
359
  // ============================================================================
@@ -386,12 +362,11 @@ exports.cutAndFeedPartial = cutAndFeedPartial;
386
362
  * n = 0: Disabled
387
363
  * n = 1: Enabled
388
364
  */
389
- const selectPeripheral = (enabled) => [
390
- exports.ESC,
365
+ export const selectPeripheral = (enabled) => [
366
+ ESC,
391
367
  0x3d,
392
368
  enabled ? 0x01 : 0x00,
393
369
  ];
394
- exports.selectPeripheral = selectPeripheral;
395
370
  /**
396
371
  * ESC p m t1 t2 - Generate pulse
397
372
  * m = 0 or 48: Drawer kick-out connector pin 2
@@ -399,52 +374,47 @@ exports.selectPeripheral = selectPeripheral;
399
374
  * t1 = ON time (0-255, units of 100ms)
400
375
  * t2 = OFF time (0-255, units of 100ms)
401
376
  */
402
- const generatePulse = (connector, onTime, offTime) => [
403
- exports.ESC,
377
+ export const generatePulse = (connector, onTime, offTime) => [
378
+ ESC,
404
379
  0x70,
405
380
  connector,
406
381
  Math.max(0, Math.min(255, onTime)),
407
382
  Math.max(0, Math.min(255, offTime)),
408
383
  ];
409
- exports.generatePulse = generatePulse;
410
384
  /**
411
385
  * ESC c 3 n - Select paper sensor(s) to output paper-end signals
412
386
  * n is a bitmask for sensor selection
413
387
  */
414
- const selectPaperSensorOutput = (sensorMask) => [
415
- exports.ESC,
388
+ export const selectPaperSensorOutput = (sensorMask) => [
389
+ ESC,
416
390
  0x63,
417
391
  0x33,
418
392
  sensorMask,
419
393
  ];
420
- exports.selectPaperSensorOutput = selectPaperSensorOutput;
421
394
  /**
422
395
  * ESC c 4 n - Select paper sensor(s) to stop printing
423
396
  * n is a bitmask for sensor selection
424
397
  */
425
- const selectPaperSensorStop = (sensorMask) => [
426
- exports.ESC,
398
+ export const selectPaperSensorStop = (sensorMask) => [
399
+ ESC,
427
400
  0x63,
428
401
  0x34,
429
402
  sensorMask,
430
403
  ];
431
- exports.selectPaperSensorStop = selectPaperSensorStop;
432
404
  /**
433
405
  * ESC c 5 n - Enable/disable panel buttons
434
406
  * n = 0: Enable panel buttons
435
407
  * n = 1: Disable panel buttons
436
408
  */
437
- const enablePanelButtons = () => [exports.ESC, 0x63, 0x35, 0x00];
438
- exports.enablePanelButtons = enablePanelButtons;
439
- const disablePanelButtons = () => [exports.ESC, 0x63, 0x35, 0x01];
440
- exports.disablePanelButtons = disablePanelButtons;
409
+ export const enablePanelButtons = () => [ESC, 0x63, 0x35, 0x00];
410
+ export const disablePanelButtons = () => [ESC, 0x63, 0x35, 0x01];
441
411
  // ============================================================================
442
412
  // CHARACTER CODE TABLES
443
413
  // ============================================================================
444
414
  /**
445
415
  * International character set selection
446
416
  */
447
- var InternationalCharset;
417
+ export var InternationalCharset;
448
418
  (function (InternationalCharset) {
449
419
  InternationalCharset[InternationalCharset["USA"] = 0] = "USA";
450
420
  InternationalCharset[InternationalCharset["FRANCE"] = 1] = "FRANCE";
@@ -460,16 +430,15 @@ var InternationalCharset;
460
430
  InternationalCharset[InternationalCharset["SPAIN_II"] = 11] = "SPAIN_II";
461
431
  InternationalCharset[InternationalCharset["LATIN_AMERICA"] = 12] = "LATIN_AMERICA";
462
432
  InternationalCharset[InternationalCharset["KOREA"] = 13] = "KOREA";
463
- })(InternationalCharset || (exports.InternationalCharset = InternationalCharset = {}));
433
+ })(InternationalCharset || (InternationalCharset = {}));
464
434
  /**
465
435
  * ESC R n - Select international character set
466
436
  */
467
- const selectInternationalCharset = (charset) => [exports.ESC, 0x52, charset];
468
- exports.selectInternationalCharset = selectInternationalCharset;
437
+ export const selectInternationalCharset = (charset) => [ESC, 0x52, charset];
469
438
  /**
470
439
  * Extended code page enumeration
471
440
  */
472
- var CodePage;
441
+ export var CodePage;
473
442
  (function (CodePage) {
474
443
  CodePage[CodePage["CP437"] = 0] = "CP437";
475
444
  CodePage[CodePage["CP850"] = 2] = "CP850";
@@ -485,37 +454,35 @@ var CodePage;
485
454
  CodePage[CodePage["CP852"] = 18] = "CP852";
486
455
  CodePage[CodePage["CP858"] = 19] = "CP858";
487
456
  CodePage[CodePage["WPC1252"] = 16] = "WPC1252";
488
- })(CodePage || (exports.CodePage = CodePage = {}));
457
+ })(CodePage || (CodePage = {}));
489
458
  /**
490
459
  * ESC t n - Select character code table
491
460
  */
492
- const setCodePage = (page) => [exports.ESC, 0x74, page];
493
- exports.setCodePage = setCodePage;
461
+ export const setCodePage = (page) => [ESC, 0x74, page];
494
462
  // ============================================================================
495
463
  // GRAPHICS - BIT IMAGE
496
464
  // ============================================================================
497
465
  /**
498
466
  * Bit image modes for ESC *
499
467
  */
500
- var BitImageMode;
468
+ export var BitImageMode;
501
469
  (function (BitImageMode) {
502
470
  BitImageMode[BitImageMode["MODE_8_SINGLE"] = 0] = "MODE_8_SINGLE";
503
471
  BitImageMode[BitImageMode["MODE_8_DOUBLE"] = 1] = "MODE_8_DOUBLE";
504
472
  BitImageMode[BitImageMode["MODE_24_SINGLE"] = 32] = "MODE_24_SINGLE";
505
473
  BitImageMode[BitImageMode["MODE_24_DOUBLE"] = 33] = "MODE_24_DOUBLE";
506
- })(BitImageMode || (exports.BitImageMode = BitImageMode = {}));
474
+ })(BitImageMode || (BitImageMode = {}));
507
475
  /**
508
476
  * ESC * m nL nH d1...dk - Print bit image
509
477
  * m: Bit image mode
510
478
  * nL, nH: Number of data columns (nL + nH × 256)
511
479
  * d1...dk: Bit image data
512
480
  */
513
- const printBitImage = (mode, width, data) => {
481
+ export const printBitImage = (mode, width, data) => {
514
482
  const nL = width & 0xff;
515
483
  const nH = (width >> 8) & 0xff;
516
- return [exports.ESC, 0x2a, mode, nL, nH, ...data];
484
+ return [ESC, 0x2a, mode, nL, nH, ...data];
517
485
  };
518
- exports.printBitImage = printBitImage;
519
486
  // ============================================================================
520
487
  // GRAPHICS - DOWNLOADED BIT IMAGE
521
488
  // ============================================================================
@@ -526,28 +493,26 @@ exports.printBitImage = printBitImage;
526
493
  * Horizontal dots = x × 8
527
494
  * Vertical dots = y × 8
528
495
  */
529
- const defineDownloadedBitImage = (x, y, data) => {
496
+ export const defineDownloadedBitImage = (x, y, data) => {
530
497
  const xVal = Math.max(1, Math.min(255, x));
531
498
  const yVal = Math.max(1, Math.min(48, y));
532
- return [exports.GS, 0x2a, xVal, yVal, ...data];
499
+ return [GS, 0x2a, xVal, yVal, ...data];
533
500
  };
534
- exports.defineDownloadedBitImage = defineDownloadedBitImage;
535
501
  /**
536
502
  * Downloaded image print modes
537
503
  */
538
- var DownloadedImageMode;
504
+ export var DownloadedImageMode;
539
505
  (function (DownloadedImageMode) {
540
506
  DownloadedImageMode[DownloadedImageMode["NORMAL"] = 0] = "NORMAL";
541
507
  DownloadedImageMode[DownloadedImageMode["DOUBLE_WIDTH"] = 1] = "DOUBLE_WIDTH";
542
508
  DownloadedImageMode[DownloadedImageMode["DOUBLE_HEIGHT"] = 2] = "DOUBLE_HEIGHT";
543
509
  DownloadedImageMode[DownloadedImageMode["QUADRUPLE"] = 3] = "QUADRUPLE";
544
- })(DownloadedImageMode || (exports.DownloadedImageMode = DownloadedImageMode = {}));
510
+ })(DownloadedImageMode || (DownloadedImageMode = {}));
545
511
  /**
546
512
  * GS / m - Print downloaded bit image
547
513
  * m: Print mode (0-3)
548
514
  */
549
- const printDownloadedBitImage = (mode) => [exports.GS, 0x2f, mode];
550
- exports.printDownloadedBitImage = printDownloadedBitImage;
515
+ export const printDownloadedBitImage = (mode) => [GS, 0x2f, mode];
551
516
  // ============================================================================
552
517
  // GRAPHICS - NV BIT IMAGE
553
518
  // ============================================================================
@@ -556,8 +521,7 @@ exports.printDownloadedBitImage = printDownloadedBitImage;
556
521
  * n: NV bit image number (1-255)
557
522
  * m: Print mode (0-3, same as DownloadedImageMode)
558
523
  */
559
- const printNVBitImage = (imageNumber, mode) => [exports.FS, 0x70, Math.max(1, Math.min(255, imageNumber)), mode];
560
- exports.printNVBitImage = printNVBitImage;
524
+ export const printNVBitImage = (imageNumber, mode) => [FS, 0x70, Math.max(1, Math.min(255, imageNumber)), mode];
561
525
  /**
562
526
  * FS q n [xL xH yL yH d1...dk]1...n - Define NV bit image
563
527
  * n: Number of NV bit images to define (1-255)
@@ -566,8 +530,8 @@ exports.printNVBitImage = printNVBitImage;
566
530
  * yL, yH: Height in bytes ((yH × 256 + yL) × 8 dots)
567
531
  * d1...dk: Bit image data
568
532
  */
569
- const defineNVBitImage = (images) => {
570
- const result = [exports.FS, 0x71, Math.min(images.length, 255)];
533
+ export const defineNVBitImage = (images) => {
534
+ const result = [FS, 0x71, Math.min(images.length, 255)];
571
535
  for (const img of images.slice(0, 255)) {
572
536
  const xL = img.width & 0xff;
573
537
  const xH = (img.width >> 8) & 0xff;
@@ -577,69 +541,64 @@ const defineNVBitImage = (images) => {
577
541
  }
578
542
  return result;
579
543
  };
580
- exports.defineNVBitImage = defineNVBitImage;
581
544
  // ============================================================================
582
545
  // BARCODE CONFIGURATION
583
546
  // ============================================================================
584
547
  /**
585
548
  * Barcode HRI (Human Readable Interpretation) position
586
549
  */
587
- var BarcodeHRIPosition;
550
+ export var BarcodeHRIPosition;
588
551
  (function (BarcodeHRIPosition) {
589
552
  BarcodeHRIPosition[BarcodeHRIPosition["NOT_PRINTED"] = 0] = "NOT_PRINTED";
590
553
  BarcodeHRIPosition[BarcodeHRIPosition["ABOVE"] = 1] = "ABOVE";
591
554
  BarcodeHRIPosition[BarcodeHRIPosition["BELOW"] = 2] = "BELOW";
592
555
  BarcodeHRIPosition[BarcodeHRIPosition["BOTH"] = 3] = "BOTH";
593
- })(BarcodeHRIPosition || (exports.BarcodeHRIPosition = BarcodeHRIPosition = {}));
556
+ })(BarcodeHRIPosition || (BarcodeHRIPosition = {}));
594
557
  /**
595
558
  * GS H n - Select HRI character print position
596
559
  */
597
- const setBarcodeHRI = (position) => [
598
- exports.GS,
560
+ export const setBarcodeHRI = (position) => [
561
+ GS,
599
562
  0x48,
600
563
  position,
601
564
  ];
602
- exports.setBarcodeHRI = setBarcodeHRI;
603
565
  /**
604
566
  * GS f n - Select font for HRI characters
605
567
  * n = 0 or 48: Font A
606
568
  * n = 1 or 49: Font B
607
569
  */
608
- const setBarcodeFont = (fontB) => [
609
- exports.GS,
570
+ export const setBarcodeFont = (fontB) => [
571
+ GS,
610
572
  0x66,
611
573
  fontB ? 0x01 : 0x00,
612
574
  ];
613
- exports.setBarcodeFont = setBarcodeFont;
614
575
  /**
615
576
  * GS h n - Set barcode height
616
577
  * Range: 1 ≤ n ≤ 255 (in dots)
617
578
  * Default: 162
618
579
  */
619
- const setBarcodeHeight = (height) => [
620
- exports.GS,
580
+ export const setBarcodeHeight = (height) => [
581
+ GS,
621
582
  0x68,
622
583
  Math.max(1, Math.min(255, height)),
623
584
  ];
624
- exports.setBarcodeHeight = setBarcodeHeight;
625
585
  /**
626
586
  * GS w n - Set barcode width
627
587
  * Range: 2 ≤ n ≤ 6 (module width in dots)
628
588
  * Default: 3
629
589
  */
630
- const setBarcodeWidth = (width) => [
631
- exports.GS,
590
+ export const setBarcodeWidth = (width) => [
591
+ GS,
632
592
  0x77,
633
593
  Math.max(2, Math.min(6, width)),
634
594
  ];
635
- exports.setBarcodeWidth = setBarcodeWidth;
636
595
  // ============================================================================
637
596
  // BARCODE PRINTING
638
597
  // ============================================================================
639
598
  /**
640
599
  * Barcode symbologies
641
600
  */
642
- var BarcodeType;
601
+ export var BarcodeType;
643
602
  (function (BarcodeType) {
644
603
  BarcodeType[BarcodeType["UPC_A"] = 0] = "UPC_A";
645
604
  BarcodeType[BarcodeType["UPC_E"] = 1] = "UPC_E";
@@ -650,118 +609,107 @@ var BarcodeType;
650
609
  BarcodeType[BarcodeType["CODABAR"] = 6] = "CODABAR";
651
610
  BarcodeType[BarcodeType["CODE93"] = 72] = "CODE93";
652
611
  BarcodeType[BarcodeType["CODE128"] = 73] = "CODE128";
653
- })(BarcodeType || (exports.BarcodeType = BarcodeType = {}));
612
+ })(BarcodeType || (BarcodeType = {}));
654
613
  /**
655
614
  * GS k m d1...dk NUL - Print barcode (NUL-terminated)
656
615
  * For barcode types 0-6 (UPC-A, UPC-E, EAN-13, EAN-8, CODE39, ITF, CODABAR)
657
616
  */
658
- const printBarcode = (type, data) => {
617
+ export const printBarcode = (type, data) => {
659
618
  const bytes = data.split("").map((c) => c.charCodeAt(0));
660
- return [exports.GS, 0x6b, type, ...bytes, 0x00];
619
+ return [GS, 0x6b, type, ...bytes, 0x00];
661
620
  };
662
- exports.printBarcode = printBarcode;
663
621
  /**
664
622
  * GS k m n d1...dn - Print barcode (length-specified)
665
623
  * For barcode types 65-73 (with length prefix)
666
624
  */
667
- const printBarcodeWithLength = (type, data) => {
625
+ export const printBarcodeWithLength = (type, data) => {
668
626
  const bytes = data.split("").map((c) => c.charCodeAt(0));
669
- return [exports.GS, 0x6b, type, bytes.length, ...bytes];
627
+ return [GS, 0x6b, type, bytes.length, ...bytes];
670
628
  };
671
- exports.printBarcodeWithLength = printBarcodeWithLength;
672
629
  /**
673
630
  * Print UPC-A barcode
674
631
  * Requires 11-12 digits
675
632
  */
676
- const printBarcodeUPCA = (data) => {
633
+ export const printBarcodeUPCA = (data) => {
677
634
  if (!/^\d{11,12}$/.test(data)) {
678
635
  throw new Error("UPC-A requires 11-12 digits");
679
636
  }
680
- return (0, exports.printBarcode)(BarcodeType.UPC_A, data.slice(0, 12));
637
+ return printBarcode(BarcodeType.UPC_A, data.slice(0, 12));
681
638
  };
682
- exports.printBarcodeUPCA = printBarcodeUPCA;
683
639
  /**
684
640
  * Print UPC-E barcode
685
641
  * Requires 6-8 digits
686
642
  */
687
- const printBarcodeUPCE = (data) => {
643
+ export const printBarcodeUPCE = (data) => {
688
644
  if (!/^\d{6,8}$/.test(data)) {
689
645
  throw new Error("UPC-E requires 6-8 digits");
690
646
  }
691
- return (0, exports.printBarcode)(BarcodeType.UPC_E, data);
647
+ return printBarcode(BarcodeType.UPC_E, data);
692
648
  };
693
- exports.printBarcodeUPCE = printBarcodeUPCE;
694
649
  /**
695
650
  * Print EAN-13 barcode
696
651
  * Requires 12-13 digits
697
652
  */
698
- const printBarcodeEAN13 = (data) => {
653
+ export const printBarcodeEAN13 = (data) => {
699
654
  if (!/^\d{12,13}$/.test(data)) {
700
655
  throw new Error("EAN-13 requires 12-13 digits");
701
656
  }
702
- return (0, exports.printBarcode)(BarcodeType.EAN13, data.slice(0, 13));
657
+ return printBarcode(BarcodeType.EAN13, data.slice(0, 13));
703
658
  };
704
- exports.printBarcodeEAN13 = printBarcodeEAN13;
705
659
  /**
706
660
  * Print EAN-8 barcode
707
661
  * Requires 7-8 digits
708
662
  */
709
- const printBarcodeEAN8 = (data) => {
663
+ export const printBarcodeEAN8 = (data) => {
710
664
  if (!/^\d{7,8}$/.test(data)) {
711
665
  throw new Error("EAN-8 requires 7-8 digits");
712
666
  }
713
- return (0, exports.printBarcode)(BarcodeType.EAN8, data);
667
+ return printBarcode(BarcodeType.EAN8, data);
714
668
  };
715
- exports.printBarcodeEAN8 = printBarcodeEAN8;
716
669
  /**
717
670
  * Print CODE39 barcode
718
671
  * Supports: 0-9, A-Z, space, and symbols ($ % + - . /)
719
672
  */
720
- const printBarcodeCODE39 = (data) => {
673
+ export const printBarcodeCODE39 = (data) => {
721
674
  if (!/^[0-9A-Z $%+\-.\/]+$/.test(data)) {
722
675
  throw new Error("CODE39 supports: 0-9, A-Z, space, $%+-./ only");
723
676
  }
724
- return (0, exports.printBarcode)(BarcodeType.CODE39, data);
677
+ return printBarcode(BarcodeType.CODE39, data);
725
678
  };
726
- exports.printBarcodeCODE39 = printBarcodeCODE39;
727
679
  /**
728
680
  * Print ITF barcode (Interleaved 2 of 5)
729
681
  * Requires even number of digits
730
682
  */
731
- const printBarcodeITF = (data) => {
683
+ export const printBarcodeITF = (data) => {
732
684
  if (!/^\d+$/.test(data) || data.length % 2 !== 0) {
733
685
  throw new Error("ITF requires even number of digits");
734
686
  }
735
- return (0, exports.printBarcode)(BarcodeType.ITF, data);
687
+ return printBarcode(BarcodeType.ITF, data);
736
688
  };
737
- exports.printBarcodeITF = printBarcodeITF;
738
689
  /**
739
690
  * Print CODABAR barcode
740
691
  * Supports: 0-9, A-D, and symbols ($ + - . / :)
741
692
  */
742
- const printBarcodeCODABAR = (data) => {
693
+ export const printBarcodeCODABAR = (data) => {
743
694
  if (!/^[A-D][0-9A-D $+\-.\/:]*[A-D]$/.test(data)) {
744
695
  throw new Error("CODABAR must start and end with A-D, and contain 0-9, A-D, $+-./:");
745
696
  }
746
- return (0, exports.printBarcode)(BarcodeType.CODABAR, data);
697
+ return printBarcode(BarcodeType.CODABAR, data);
747
698
  };
748
- exports.printBarcodeCODABAR = printBarcodeCODABAR;
749
699
  /**
750
700
  * Print CODE93 barcode
751
701
  * Supports all ASCII characters (0-127)
752
702
  */
753
- const printBarcodeCODE93 = (data) => {
754
- return (0, exports.printBarcodeWithLength)(BarcodeType.CODE93, data);
703
+ export const printBarcodeCODE93 = (data) => {
704
+ return printBarcodeWithLength(BarcodeType.CODE93, data);
755
705
  };
756
- exports.printBarcodeCODE93 = printBarcodeCODE93;
757
706
  /**
758
707
  * Print CODE128 barcode
759
708
  * Supports all ASCII characters (0-127)
760
709
  */
761
- const printBarcodeCODE128 = (data) => {
762
- return (0, exports.printBarcodeWithLength)(BarcodeType.CODE128, data);
710
+ export const printBarcodeCODE128 = (data) => {
711
+ return printBarcodeWithLength(BarcodeType.CODE128, data);
763
712
  };
764
- exports.printBarcodeCODE128 = printBarcodeCODE128;
765
713
  // ============================================================================
766
714
  // 2D CODES - PDF417
767
715
  // ============================================================================
@@ -773,64 +721,58 @@ exports.printBarcodeCODE128 = printBarcodeCODE128;
773
721
  * Set PDF417 number of columns
774
722
  * fn = 0x41, n = number of columns (0 or 1-30)
775
723
  */
776
- const setPDF417Columns = (columns) => {
724
+ export const setPDF417Columns = (columns) => {
777
725
  const col = Math.max(0, Math.min(30, columns));
778
- return [exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x41, col];
726
+ return [GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x41, col];
779
727
  };
780
- exports.setPDF417Columns = setPDF417Columns;
781
728
  /**
782
729
  * Set PDF417 number of rows
783
730
  * fn = 0x42, n = number of rows (0 or 3-90)
784
731
  */
785
- const setPDF417Rows = (rows) => {
732
+ export const setPDF417Rows = (rows) => {
786
733
  const row = rows === 0 ? 0 : Math.max(3, Math.min(90, rows));
787
- return [exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x42, row];
734
+ return [GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x42, row];
788
735
  };
789
- exports.setPDF417Rows = setPDF417Rows;
790
736
  /**
791
737
  * Set PDF417 module width
792
738
  * fn = 0x43, n = module width (2-8 dots)
793
739
  */
794
- const setPDF417Width = (width) => {
740
+ export const setPDF417Width = (width) => {
795
741
  const w = Math.max(2, Math.min(8, width));
796
- return [exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x43, w];
742
+ return [GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x43, w];
797
743
  };
798
- exports.setPDF417Width = setPDF417Width;
799
744
  /**
800
745
  * Set PDF417 row height
801
746
  * fn = 0x44, n = row height (2-8 dots)
802
747
  */
803
- const setPDF417RowHeight = (height) => {
748
+ export const setPDF417RowHeight = (height) => {
804
749
  const h = Math.max(2, Math.min(8, height));
805
- return [exports.GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x44, h];
750
+ return [GS, 0x28, 0x6b, 0x03, 0x00, 0x30, 0x44, h];
806
751
  };
807
- exports.setPDF417RowHeight = setPDF417RowHeight;
808
752
  /**
809
753
  * Set PDF417 error correction level
810
754
  * fn = 0x45, m = 48 (standard mode), n = level (0-8)
811
755
  */
812
- const setPDF417ErrorCorrection = (level) => {
756
+ export const setPDF417ErrorCorrection = (level) => {
813
757
  const lvl = Math.max(0, Math.min(8, level));
814
- return [exports.GS, 0x28, 0x6b, 0x04, 0x00, 0x30, 0x45, 0x30, lvl];
758
+ return [GS, 0x28, 0x6b, 0x04, 0x00, 0x30, 0x45, 0x30, lvl];
815
759
  };
816
- exports.setPDF417ErrorCorrection = setPDF417ErrorCorrection;
817
760
  /**
818
761
  * Store PDF417 data
819
762
  * fn = 0x50, m = 48 (standard mode), followed by data
820
763
  */
821
- const storePDF417Data = (data) => {
764
+ export const storePDF417Data = (data) => {
822
765
  const bytes = new TextEncoder().encode(data);
823
766
  const pL = (bytes.length + 3) & 0xff;
824
767
  const pH = ((bytes.length + 3) >> 8) & 0xff;
825
- return [exports.GS, 0x28, 0x6b, pL, pH, 0x30, 0x50, 0x30, ...Array.from(bytes)];
768
+ return [GS, 0x28, 0x6b, pL, pH, 0x30, 0x50, 0x30, ...Array.from(bytes)];
826
769
  };
827
- exports.storePDF417Data = storePDF417Data;
828
770
  /**
829
771
  * Print PDF417 symbol
830
772
  * fn = 0x51, m = 48 (standard mode)
831
773
  */
832
- const printPDF417 = () => [
833
- exports.GS,
774
+ export const printPDF417 = () => [
775
+ GS,
834
776
  0x28,
835
777
  0x6b,
836
778
  0x03,
@@ -839,33 +781,31 @@ const printPDF417 = () => [
839
781
  0x51,
840
782
  0x30,
841
783
  ];
842
- exports.printPDF417 = printPDF417;
843
784
  /**
844
785
  * Generate complete PDF417 barcode
845
786
  * Convenience function that combines all PDF417 commands
846
787
  */
847
- const generatePDF417 = (data, options) => {
788
+ export const generatePDF417 = (data, options) => {
848
789
  const commands = [];
849
790
  if (options?.columns !== undefined) {
850
- commands.push(...(0, exports.setPDF417Columns)(options.columns));
791
+ commands.push(...setPDF417Columns(options.columns));
851
792
  }
852
793
  if (options?.rows !== undefined) {
853
- commands.push(...(0, exports.setPDF417Rows)(options.rows));
794
+ commands.push(...setPDF417Rows(options.rows));
854
795
  }
855
796
  if (options?.width !== undefined) {
856
- commands.push(...(0, exports.setPDF417Width)(options.width));
797
+ commands.push(...setPDF417Width(options.width));
857
798
  }
858
799
  if (options?.rowHeight !== undefined) {
859
- commands.push(...(0, exports.setPDF417RowHeight)(options.rowHeight));
800
+ commands.push(...setPDF417RowHeight(options.rowHeight));
860
801
  }
861
802
  if (options?.errorCorrection !== undefined) {
862
- commands.push(...(0, exports.setPDF417ErrorCorrection)(options.errorCorrection));
803
+ commands.push(...setPDF417ErrorCorrection(options.errorCorrection));
863
804
  }
864
- commands.push(...(0, exports.storePDF417Data)(data));
865
- commands.push(...(0, exports.printPDF417)());
805
+ commands.push(...storePDF417Data(data));
806
+ commands.push(...printPDF417());
866
807
  return commands;
867
808
  };
868
- exports.generatePDF417 = generatePDF417;
869
809
  // ============================================================================
870
810
  // CHARACTER EFFECTS (ADVANCED)
871
811
  // ============================================================================
@@ -875,27 +815,26 @@ exports.generatePDF417 = generatePDF417;
875
815
  * Bits 0-2: Width (0-7 for 1x-8x)
876
816
  * Bits 4-6: Height (0-7 for 1x-8x)
877
817
  */
878
- const selectCharacterSize = (widthMultiplier, heightMultiplier) => {
818
+ export const selectCharacterSize = (widthMultiplier, heightMultiplier) => {
879
819
  const w = Math.max(0, Math.min(7, widthMultiplier - 1));
880
820
  const h = Math.max(0, Math.min(7, heightMultiplier - 1));
881
821
  const n = (w & 0x07) | ((h & 0x07) << 4);
882
- return [exports.GS, 0x21, n];
822
+ return [GS, 0x21, n];
883
823
  };
884
- exports.selectCharacterSize = selectCharacterSize;
885
824
  /**
886
825
  * GS B n - Turn white/black reverse printing mode on/off
887
826
  * n = 0 or 48: Turn off white/black reverse mode
888
827
  * n = 1 or 49: Turn on white/black reverse mode
889
828
  */
890
- exports.REVERSE_PRINT_ON = [exports.GS, 0x42, 0x01];
891
- exports.REVERSE_PRINT_OFF = [exports.GS, 0x42, 0x00];
829
+ export const REVERSE_PRINT_ON = [GS, 0x42, 0x01];
830
+ export const REVERSE_PRINT_OFF = [GS, 0x42, 0x00];
892
831
  /**
893
832
  * GS ( N pL pH fn n - Select character effects
894
833
  * fn = 48: Set character color
895
834
  * fn = 49: Set character smoothing
896
835
  */
897
- const setCharacterColor = (color) => [
898
- exports.GS,
836
+ export const setCharacterColor = (color) => [
837
+ GS,
899
838
  0x28,
900
839
  0x4e,
901
840
  0x02,
@@ -903,9 +842,8 @@ const setCharacterColor = (color) => [
903
842
  0x30,
904
843
  color,
905
844
  ];
906
- exports.setCharacterColor = setCharacterColor;
907
- const setCharacterSmoothing = (enabled) => [
908
- exports.GS,
845
+ export const setCharacterSmoothing = (enabled) => [
846
+ GS,
909
847
  0x28,
910
848
  0x4e,
911
849
  0x02,
@@ -913,7 +851,6 @@ const setCharacterSmoothing = (enabled) => [
913
851
  0x31,
914
852
  enabled ? 0x01 : 0x00,
915
853
  ];
916
- exports.setCharacterSmoothing = setCharacterSmoothing;
917
854
  // ============================================================================
918
855
  // STATUS COMMANDS
919
856
  // ============================================================================
@@ -921,49 +858,45 @@ exports.setCharacterSmoothing = setCharacterSmoothing;
921
858
  * GS a n - Enable/disable Automatic Status Back (ASB)
922
859
  * n is a bitmask for status types to enable
923
860
  */
924
- const enableASB = (statusBits) => [
925
- exports.GS,
861
+ export const enableASB = (statusBits) => [
862
+ GS,
926
863
  0x61,
927
864
  statusBits,
928
865
  ];
929
- exports.enableASB = enableASB;
930
- const disableASB = () => [exports.GS, 0x61, 0x00];
931
- exports.disableASB = disableASB;
866
+ export const disableASB = () => [GS, 0x61, 0x00];
932
867
  /**
933
868
  * Printer ID types for GS I command
934
869
  */
935
- var PrinterIDType;
870
+ export var PrinterIDType;
936
871
  (function (PrinterIDType) {
937
872
  PrinterIDType[PrinterIDType["PRINTER_MODEL"] = 1] = "PRINTER_MODEL";
938
873
  PrinterIDType[PrinterIDType["TYPE_ID"] = 2] = "TYPE_ID";
939
874
  PrinterIDType[PrinterIDType["ROM_VERSION"] = 65] = "ROM_VERSION";
940
875
  PrinterIDType[PrinterIDType["FONT_TYPE"] = 66] = "FONT_TYPE";
941
876
  PrinterIDType[PrinterIDType["MANUFACTURER"] = 67] = "MANUFACTURER";
942
- })(PrinterIDType || (exports.PrinterIDType = PrinterIDType = {}));
877
+ })(PrinterIDType || (PrinterIDType = {}));
943
878
  /**
944
879
  * GS I n - Transmit printer ID
945
880
  */
946
- const requestPrinterID = (type) => [
947
- exports.GS,
881
+ export const requestPrinterID = (type) => [
882
+ GS,
948
883
  0x49,
949
884
  type,
950
885
  ];
951
- exports.requestPrinterID = requestPrinterID;
952
886
  /**
953
887
  * Status types for GS r command
954
888
  */
955
- var StatusType;
889
+ export var StatusType;
956
890
  (function (StatusType) {
957
891
  StatusType[StatusType["PAPER_SENSOR"] = 1] = "PAPER_SENSOR";
958
892
  StatusType[StatusType["DRAWER_SENSOR"] = 2] = "DRAWER_SENSOR";
959
893
  StatusType[StatusType["INK_SENSOR"] = 4] = "INK_SENSOR";
960
894
  StatusType[StatusType["PAPER_ROLL_SENSOR"] = 18] = "PAPER_ROLL_SENSOR";
961
- })(StatusType || (exports.StatusType = StatusType = {}));
895
+ })(StatusType || (StatusType = {}));
962
896
  /**
963
897
  * GS r n - Transmit status
964
898
  */
965
- const requestStatus = (type) => [exports.GS, 0x72, type];
966
- exports.requestStatus = requestStatus;
899
+ export const requestStatus = (type) => [GS, 0x72, type];
967
900
  // ============================================================================
968
901
  // MARGINS & PRINT AREA
969
902
  // ============================================================================
@@ -971,22 +904,20 @@ exports.requestStatus = requestStatus;
971
904
  * GS L nL nH - Set left margin
972
905
  * Left margin = ((nH × 256) + nL) × (horizontal motion unit)
973
906
  */
974
- const setLeftMargin = (dots) => {
907
+ export const setLeftMargin = (dots) => {
975
908
  const nL = dots & 0xff;
976
909
  const nH = (dots >> 8) & 0xff;
977
- return [exports.GS, 0x4c, nL, nH];
910
+ return [GS, 0x4c, nL, nH];
978
911
  };
979
- exports.setLeftMargin = setLeftMargin;
980
912
  /**
981
913
  * GS W nL nH - Set printing area width
982
914
  * Width = ((nH × 256) + nL) × (horizontal motion unit)
983
915
  */
984
- const setPrintingAreaWidth = (dots) => {
916
+ export const setPrintingAreaWidth = (dots) => {
985
917
  const nL = dots & 0xff;
986
918
  const nH = (dots >> 8) & 0xff;
987
- return [exports.GS, 0x57, nL, nH];
919
+ return [GS, 0x57, nL, nH];
988
920
  };
989
- exports.setPrintingAreaWidth = setPrintingAreaWidth;
990
921
  // ============================================================================
991
922
  // MACRO FUNCTIONS
992
923
  // ============================================================================
@@ -995,22 +926,21 @@ exports.setPrintingAreaWidth = setPrintingAreaWidth;
995
926
  * First call starts macro definition
996
927
  * Second call ends macro definition
997
928
  */
998
- exports.START_MACRO = [exports.GS, 0x3a];
999
- exports.END_MACRO = [exports.GS, 0x3a];
929
+ export const START_MACRO = [GS, 0x3a];
930
+ export const END_MACRO = [GS, 0x3a];
1000
931
  /**
1001
932
  * GS ^ r t m - Execute macro
1002
933
  * r: Number of times to execute macro (0-255)
1003
934
  * t: Waiting time between executions (0-255, units of 100ms)
1004
935
  * m: Macro execution mode (0 or 1)
1005
936
  */
1006
- const executeMacro = (repeatCount, waitTime, mode) => [
1007
- exports.GS,
937
+ export const executeMacro = (repeatCount, waitTime, mode) => [
938
+ GS,
1008
939
  0x5e,
1009
940
  Math.max(0, Math.min(255, repeatCount)),
1010
941
  Math.max(0, Math.min(255, waitTime)),
1011
942
  mode,
1012
943
  ];
1013
- exports.executeMacro = executeMacro;
1014
944
  // ============================================================================
1015
945
  // MISCELLANEOUS
1016
946
  // ============================================================================
@@ -1019,13 +949,13 @@ exports.executeMacro = executeMacro;
1019
949
  * n = 0 or 48: Turn off unidirectional printing
1020
950
  * n = 1 or 49: Turn on unidirectional printing
1021
951
  */
1022
- exports.UNIDIRECTIONAL_ON = [exports.ESC, 0x55, 0x01];
1023
- exports.UNIDIRECTIONAL_OFF = [exports.ESC, 0x55, 0x00];
952
+ export const UNIDIRECTIONAL_ON = [ESC, 0x55, 0x01];
953
+ export const UNIDIRECTIONAL_OFF = [ESC, 0x55, 0x00];
1024
954
  /**
1025
955
  * CAN - Cancel print data in page mode
1026
956
  * Deletes all print data in the current printable area
1027
957
  */
1028
- exports.CANCEL = [exports.CAN];
958
+ export const CANCEL = [CAN];
1029
959
  /**
1030
960
  * ESC ( A pL pH n m r t - Execute test print
1031
961
  * pL pH = 2 (fixed)
@@ -1034,8 +964,8 @@ exports.CANCEL = [exports.CAN];
1034
964
  * r = number of times to repeat
1035
965
  * t = interval time
1036
966
  */
1037
- const executeTestPrint = (pattern, mode, repeat) => [
1038
- exports.ESC,
967
+ export const executeTestPrint = (pattern, mode, repeat) => [
968
+ ESC,
1039
969
  0x28,
1040
970
  0x41,
1041
971
  0x02,
@@ -1045,4 +975,3 @@ const executeTestPrint = (pattern, mode, repeat) => [
1045
975
  repeat,
1046
976
  0x00,
1047
977
  ];
1048
- exports.executeTestPrint = executeTestPrint;