@thermal-print/escpos 0.1.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.
- package/LICENSE +21 -0
- package/README.md +193 -0
- package/dist/command-adapters/escbematech-adapter.d.ts +30 -0
- package/dist/command-adapters/escbematech-adapter.d.ts.map +1 -0
- package/dist/command-adapters/escbematech-adapter.js +175 -0
- package/dist/command-adapters/escpos-adapter.d.ts +25 -0
- package/dist/command-adapters/escpos-adapter.d.ts.map +1 -0
- package/dist/command-adapters/escpos-adapter.js +144 -0
- package/dist/command-adapters/index.d.ts +11 -0
- package/dist/command-adapters/index.d.ts.map +1 -0
- package/dist/command-adapters/index.js +14 -0
- package/dist/command-adapters/types.d.ts +78 -0
- package/dist/command-adapters/types.d.ts.map +1 -0
- package/dist/command-adapters/types.js +8 -0
- package/dist/commands/escbematech.d.ts +867 -0
- package/dist/commands/escbematech.d.ts.map +1 -0
- package/dist/commands/escbematech.js +1387 -0
- package/dist/commands/escpos.d.ts +582 -0
- package/dist/commands/escpos.d.ts.map +1 -0
- package/dist/commands/escpos.js +1048 -0
- package/dist/converter.d.ts +47 -0
- package/dist/converter.d.ts.map +1 -0
- package/dist/converter.js +92 -0
- package/dist/encodings/cp860.d.ts +25 -0
- package/dist/encodings/cp860.d.ts.map +1 -0
- package/dist/encodings/cp860.js +187 -0
- package/dist/generator.d.ts +118 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +383 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/styles.d.ts +72 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +210 -0
- package/dist/traverser.d.ts +60 -0
- package/dist/traverser.d.ts.map +1 -0
- package/dist/traverser.js +285 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/package.json +31 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PrintNode } from '@thermal-print/core';
|
|
2
|
+
import { CommandAdapter } from './command-adapters';
|
|
3
|
+
/**
|
|
4
|
+
* Options for converting PrintNodes to ESC/POS commands
|
|
5
|
+
*/
|
|
6
|
+
export interface PrintNodeToESCPOSOptions {
|
|
7
|
+
paperWidth?: number;
|
|
8
|
+
encoding?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
cut?: boolean | 'full' | 'partial';
|
|
11
|
+
feedBeforeCut?: number;
|
|
12
|
+
commandAdapter?: CommandAdapter | 'escpos' | 'escbematech';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts PrintNode tree to ESC/POS buffer
|
|
16
|
+
*
|
|
17
|
+
* This is the main entry point for @thermal-print/escpos.
|
|
18
|
+
* Takes a universal PrintNode IR and converts it to ESC/POS commands.
|
|
19
|
+
*
|
|
20
|
+
* @param printNode - Root PrintNode of the tree to convert
|
|
21
|
+
* @param options - Conversion options
|
|
22
|
+
* @returns Buffer containing ESC/POS commands ready to be sent to printer
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const printTree: PrintNode = {
|
|
27
|
+
* type: 'document',
|
|
28
|
+
* props: {},
|
|
29
|
+
* children: [
|
|
30
|
+
* {
|
|
31
|
+
* type: 'text',
|
|
32
|
+
* props: { children: 'Hello World' },
|
|
33
|
+
* children: [],
|
|
34
|
+
* style: { textAlign: 'center', fontSize: 20 }
|
|
35
|
+
* }
|
|
36
|
+
* ],
|
|
37
|
+
* style: {}
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* const buffer = await printNodesToESCPOS(printTree, {
|
|
41
|
+
* paperWidth: 48,
|
|
42
|
+
* cut: 'full'
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function printNodesToESCPOS(printNode: PrintNode, options?: PrintNodeToESCPOSOptions): Promise<Buffer>;
|
|
47
|
+
//# sourceMappingURL=converter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../src/converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAmD,MAAM,oBAAoB,CAAC;AAErG;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,aAAa,CAAC;CAC5D;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,MAAM,CAAC,CAwCjB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printNodesToESCPOS = printNodesToESCPOS;
|
|
4
|
+
const generator_1 = require("./generator");
|
|
5
|
+
const traverser_1 = require("./traverser");
|
|
6
|
+
const command_adapters_1 = require("./command-adapters");
|
|
7
|
+
/**
|
|
8
|
+
* Create command adapter based on configuration
|
|
9
|
+
*/
|
|
10
|
+
function createCommandAdapter(config) {
|
|
11
|
+
// If no config provided, default to ESC/POS
|
|
12
|
+
if (!config) {
|
|
13
|
+
return new command_adapters_1.ESCPOSCommandAdapter();
|
|
14
|
+
}
|
|
15
|
+
// If it's already a CommandAdapter instance, return it
|
|
16
|
+
if (typeof config === 'object' && 'getName' in config) {
|
|
17
|
+
return config;
|
|
18
|
+
}
|
|
19
|
+
// If it's a string identifier, create the appropriate adapter
|
|
20
|
+
if (config === 'escpos') {
|
|
21
|
+
return new command_adapters_1.ESCPOSCommandAdapter();
|
|
22
|
+
}
|
|
23
|
+
else if (config === 'escbematech') {
|
|
24
|
+
return new command_adapters_1.ESCBematechCommandAdapter();
|
|
25
|
+
}
|
|
26
|
+
// Default to ESC/POS if unknown
|
|
27
|
+
return new command_adapters_1.ESCPOSCommandAdapter();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts PrintNode tree to ESC/POS buffer
|
|
31
|
+
*
|
|
32
|
+
* This is the main entry point for @thermal-print/escpos.
|
|
33
|
+
* Takes a universal PrintNode IR and converts it to ESC/POS commands.
|
|
34
|
+
*
|
|
35
|
+
* @param printNode - Root PrintNode of the tree to convert
|
|
36
|
+
* @param options - Conversion options
|
|
37
|
+
* @returns Buffer containing ESC/POS commands ready to be sent to printer
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const printTree: PrintNode = {
|
|
42
|
+
* type: 'document',
|
|
43
|
+
* props: {},
|
|
44
|
+
* children: [
|
|
45
|
+
* {
|
|
46
|
+
* type: 'text',
|
|
47
|
+
* props: { children: 'Hello World' },
|
|
48
|
+
* children: [],
|
|
49
|
+
* style: { textAlign: 'center', fontSize: 20 }
|
|
50
|
+
* }
|
|
51
|
+
* ],
|
|
52
|
+
* style: {}
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* const buffer = await printNodesToESCPOS(printTree, {
|
|
56
|
+
* paperWidth: 48,
|
|
57
|
+
* cut: 'full'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async function printNodesToESCPOS(printNode, options) {
|
|
62
|
+
const { paperWidth = 48, // Default to 48 chars (80mm thermal)
|
|
63
|
+
encoding = "utf-8", debug = false, cut = "full", // Default to full cut
|
|
64
|
+
feedBeforeCut = 3, // Default to 3 lines feed before cut
|
|
65
|
+
commandAdapter: commandAdapterConfig, // Command protocol adapter
|
|
66
|
+
} = options || {};
|
|
67
|
+
// Create command adapter (defaults to ESC/POS if not provided)
|
|
68
|
+
const commandAdapter = createCommandAdapter(commandAdapterConfig);
|
|
69
|
+
if (debug) {
|
|
70
|
+
console.log(`Using command adapter: ${commandAdapter.getName()}`);
|
|
71
|
+
console.log("\n========== PRINT NODE TREE (JSON) ==========");
|
|
72
|
+
console.log(JSON.stringify(printNode, null, 2));
|
|
73
|
+
console.log("============================================\n");
|
|
74
|
+
}
|
|
75
|
+
// Create ESC/POS generator with command adapter
|
|
76
|
+
const generator = new generator_1.ESCPOSGenerator(paperWidth, encoding, debug, commandAdapter);
|
|
77
|
+
// Traverse tree and generate commands
|
|
78
|
+
const traverser = new traverser_1.TreeTraverser(generator);
|
|
79
|
+
await traverser.traverse(printNode);
|
|
80
|
+
// Add cut command if requested
|
|
81
|
+
if (cut !== false) {
|
|
82
|
+
if (cut === "full") {
|
|
83
|
+
generator.cutFullWithFeed(feedBeforeCut);
|
|
84
|
+
}
|
|
85
|
+
else if (cut === "partial" || cut === true) {
|
|
86
|
+
generator.cutPartialWithFeed(feedBeforeCut);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Get final buffer
|
|
90
|
+
const buffer = generator.getBuffer();
|
|
91
|
+
return buffer;
|
|
92
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CP860 (Portuguese) Character Encoding Map
|
|
3
|
+
*
|
|
4
|
+
* Maps Unicode characters to CP860 byte values for Brazilian Portuguese support.
|
|
5
|
+
* CP860 is the standard codepage for Portuguese thermal printers.
|
|
6
|
+
*
|
|
7
|
+
* Includes special characters: ç Ç á é í ó ú à ã õ â ê ô
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Encode text to CP860 byte array
|
|
11
|
+
* Converts JavaScript string (UTF-16) to CP860 encoding for thermal printers
|
|
12
|
+
*
|
|
13
|
+
* @param text - Text to encode
|
|
14
|
+
* @returns Array of CP860 byte values
|
|
15
|
+
*/
|
|
16
|
+
export declare function encodeCP860(text: string): number[];
|
|
17
|
+
/**
|
|
18
|
+
* Test if a character is supported in CP860
|
|
19
|
+
*/
|
|
20
|
+
export declare function isCP860Supported(char: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Common Portuguese words test string
|
|
23
|
+
*/
|
|
24
|
+
export declare const CP860_TEST_STRING = "A\u00E7\u00E3o, P\u00E3o, A\u00E7\u00FAcar, Caf\u00E9, Aten\u00E7\u00E3o, Informa\u00E7\u00E3o, S\u00E3o Paulo, Jo\u00E3o, Jos\u00E9";
|
|
25
|
+
//# sourceMappingURL=cp860.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cp860.d.ts","sourceRoot":"","sources":["../../src/encodings/cp860.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkJH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAsBlD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGtD;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,yIAAwE,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CP860 (Portuguese) Character Encoding Map
|
|
4
|
+
*
|
|
5
|
+
* Maps Unicode characters to CP860 byte values for Brazilian Portuguese support.
|
|
6
|
+
* CP860 is the standard codepage for Portuguese thermal printers.
|
|
7
|
+
*
|
|
8
|
+
* Includes special characters: ç Ç á é í ó ú à ã õ â ê ô
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CP860_TEST_STRING = void 0;
|
|
12
|
+
exports.encodeCP860 = encodeCP860;
|
|
13
|
+
exports.isCP860Supported = isCP860Supported;
|
|
14
|
+
// CP860 character map (0x80-0xFF)
|
|
15
|
+
// 0x00-0x7F are standard ASCII (unchanged)
|
|
16
|
+
const CP860_MAP = {
|
|
17
|
+
// Portuguese special characters
|
|
18
|
+
ç: 0x87, // Latin small letter c with cedilla
|
|
19
|
+
Ç: 0x80, // Latin capital letter C with cedilla
|
|
20
|
+
ü: 0x81, // Latin small letter u with diaeresis
|
|
21
|
+
é: 0x82, // Latin small letter e with acute
|
|
22
|
+
â: 0x83, // Latin small letter a with circumflex
|
|
23
|
+
ã: 0x84, // Latin small letter a with tilde
|
|
24
|
+
à: 0x85, // Latin small letter a with grave
|
|
25
|
+
// á: 0x86, // REMOVED: Wrong CP860 mapping. Correct mapping is 0xa0 (see below)
|
|
26
|
+
ê: 0x88, // Latin small letter e with circumflex
|
|
27
|
+
ë: 0x89, // Latin small letter e with diaeresis
|
|
28
|
+
è: 0x8a, // Latin small letter e with grave
|
|
29
|
+
ï: 0x8b, // Latin small letter i with diaeresis
|
|
30
|
+
î: 0x8c, // Latin small letter i with circumflex
|
|
31
|
+
ì: 0x8d, // Latin small letter i with grave
|
|
32
|
+
Ã: 0x8e, // Latin capital letter A with tilde
|
|
33
|
+
Á: 0x8f, // Latin capital letter A with acute
|
|
34
|
+
É: 0x90, // Latin capital letter E with acute
|
|
35
|
+
æ: 0x91, // Latin small letter ae
|
|
36
|
+
Æ: 0x92, // Latin capital letter AE
|
|
37
|
+
ô: 0x93, // Latin small letter o with circumflex
|
|
38
|
+
ö: 0x94, // Latin small letter o with diaeresis
|
|
39
|
+
ò: 0x95, // Latin small letter o with grave
|
|
40
|
+
û: 0x96, // Latin small letter u with circumflex
|
|
41
|
+
ù: 0x97, // Latin small letter u with grave
|
|
42
|
+
ÿ: 0x98, // Latin small letter y with diaeresis
|
|
43
|
+
Ö: 0x99, // Latin capital letter O with diaeresis
|
|
44
|
+
Ü: 0x9a, // Latin capital letter U with diaeresis
|
|
45
|
+
ø: 0x9b, // Latin small letter o with stroke
|
|
46
|
+
"£": 0x9c, // Pound sign
|
|
47
|
+
Ø: 0x9d, // Latin capital letter O with stroke
|
|
48
|
+
"×": 0x9e, // Multiplication sign
|
|
49
|
+
ƒ: 0x9f, // Latin small letter f with hook
|
|
50
|
+
á: 0xa0, // Latin small letter a with acute
|
|
51
|
+
í: 0xa1, // Latin small letter i with acute
|
|
52
|
+
ó: 0xa2, // Latin small letter o with acute
|
|
53
|
+
ú: 0xa3, // Latin small letter u with acute
|
|
54
|
+
ñ: 0xa4, // Latin small letter n with tilde
|
|
55
|
+
Ñ: 0xa5, // Latin capital letter N with tilde
|
|
56
|
+
ª: 0xa6, // Feminine ordinal indicator
|
|
57
|
+
º: 0xa7, // Masculine ordinal indicator
|
|
58
|
+
// NOTE: Capital Ú doesn't exist in CP860, map to regular U
|
|
59
|
+
Ú: 0x55, // Latin capital U (fallback - CP860 doesn't have Ú)
|
|
60
|
+
"¿": 0xa8, // Inverted question mark
|
|
61
|
+
"®": 0xa9, // Registered sign
|
|
62
|
+
"¬": 0xaa, // Not sign
|
|
63
|
+
"½": 0xab, // Vulgar fraction one half
|
|
64
|
+
"¼": 0xac, // Vulgar fraction one quarter
|
|
65
|
+
"¡": 0xad, // Inverted exclamation mark
|
|
66
|
+
"«": 0xae, // Left-pointing double angle quotation mark
|
|
67
|
+
"»": 0xaf, // Right-pointing double angle quotation mark
|
|
68
|
+
"░": 0xb0, // Light shade
|
|
69
|
+
"▒": 0xb1, // Medium shade
|
|
70
|
+
"▓": 0xb2, // Dark shade
|
|
71
|
+
"│": 0xb3, // Box drawings light vertical
|
|
72
|
+
"┤": 0xb4, // Box drawings light vertical and left
|
|
73
|
+
"╡": 0xb5, // Box drawings vertical single and left double
|
|
74
|
+
"╢": 0xb6, // Box drawings vertical double and left single
|
|
75
|
+
"╖": 0xb7, // Box drawings down double and left single
|
|
76
|
+
"╕": 0xb8, // Box drawings down single and left double
|
|
77
|
+
"╣": 0xb9, // Box drawings double vertical and left
|
|
78
|
+
"║": 0xba, // Box drawings double vertical
|
|
79
|
+
"╗": 0xbb, // Box drawings double down and left
|
|
80
|
+
"╝": 0xbc, // Box drawings double up and left
|
|
81
|
+
"╜": 0xbd, // Box drawings up double and left single
|
|
82
|
+
"╛": 0xbe, // Box drawings up single and left double
|
|
83
|
+
"┐": 0xbf, // Box drawings light down and left
|
|
84
|
+
"└": 0xc0, // Box drawings light up and right
|
|
85
|
+
"┴": 0xc1, // Box drawings light up and horizontal
|
|
86
|
+
"┬": 0xc2, // Box drawings light down and horizontal
|
|
87
|
+
"├": 0xc3, // Box drawings light vertical and right
|
|
88
|
+
"─": 0xc4, // Box drawings light horizontal
|
|
89
|
+
"┼": 0xc5, // Box drawings light vertical and horizontal
|
|
90
|
+
"╞": 0xc6, // Box drawings vertical single and right double
|
|
91
|
+
"╟": 0xc7, // Box drawings vertical double and right single
|
|
92
|
+
"╚": 0xc8, // Box drawings double up and right
|
|
93
|
+
"╔": 0xc9, // Box drawings double down and right
|
|
94
|
+
"╩": 0xca, // Box drawings double up and horizontal
|
|
95
|
+
"╦": 0xcb, // Box drawings double down and horizontal
|
|
96
|
+
"╠": 0xcc, // Box drawings double vertical and right
|
|
97
|
+
"═": 0xcd, // Box drawings double horizontal
|
|
98
|
+
"╬": 0xce, // Box drawings double vertical and horizontal
|
|
99
|
+
"╧": 0xcf, // Box drawings up single and horizontal double
|
|
100
|
+
"╨": 0xd0, // Box drawings up double and horizontal single
|
|
101
|
+
"╤": 0xd1, // Box drawings down single and horizontal double
|
|
102
|
+
"╥": 0xd2, // Box drawings down double and horizontal single
|
|
103
|
+
"╙": 0xd3, // Box drawings up double and right single
|
|
104
|
+
"╘": 0xd4, // Box drawings up single and right double
|
|
105
|
+
"╒": 0xd5, // Box drawings down single and right double
|
|
106
|
+
"╓": 0xd6, // Box drawings down double and right single
|
|
107
|
+
"╫": 0xd7, // Box drawings vertical double and horizontal single
|
|
108
|
+
"╪": 0xd8, // Box drawings vertical single and horizontal double
|
|
109
|
+
"┘": 0xd9, // Box drawings light up and left
|
|
110
|
+
"┌": 0xda, // Box drawings light down and right
|
|
111
|
+
"█": 0xdb, // Full block
|
|
112
|
+
"▄": 0xdc, // Lower half block
|
|
113
|
+
"▌": 0xdd, // Left half block
|
|
114
|
+
"▐": 0xde, // Right half block
|
|
115
|
+
"▀": 0xdf, // Upper half block
|
|
116
|
+
α: 0xe0, // Greek small letter alpha
|
|
117
|
+
β: 0xe1, // Greek small letter beta (German eszett)
|
|
118
|
+
Γ: 0xe2, // Greek capital letter gamma
|
|
119
|
+
π: 0xe3, // Greek small letter pi
|
|
120
|
+
Σ: 0xe4, // Greek capital letter sigma
|
|
121
|
+
σ: 0xe5, // Greek small letter sigma
|
|
122
|
+
µ: 0xe6, // Micro sign
|
|
123
|
+
τ: 0xe7, // Greek small letter tau
|
|
124
|
+
Φ: 0xe8, // Greek capital letter phi
|
|
125
|
+
Θ: 0xe9, // Greek capital letter theta
|
|
126
|
+
Ω: 0xea, // Greek capital letter omega
|
|
127
|
+
δ: 0xeb, // Greek small letter delta
|
|
128
|
+
"∞": 0xec, // Infinity
|
|
129
|
+
φ: 0xed, // Greek small letter phi
|
|
130
|
+
ε: 0xee, // Greek small letter epsilon
|
|
131
|
+
"∩": 0xef, // Intersection
|
|
132
|
+
"≡": 0xf0, // Identical to
|
|
133
|
+
"±": 0xf1, // Plus-minus sign
|
|
134
|
+
"≥": 0xf2, // Greater-than or equal to
|
|
135
|
+
"≤": 0xf3, // Less-than or equal to
|
|
136
|
+
"⌠": 0xf4, // Top half integral
|
|
137
|
+
"⌡": 0xf5, // Bottom half integral
|
|
138
|
+
"÷": 0xf6, // Division sign
|
|
139
|
+
"≈": 0xf7, // Almost equal to
|
|
140
|
+
"°": 0xf8, // Degree sign
|
|
141
|
+
"∙": 0xf9, // Bullet operator
|
|
142
|
+
"·": 0xfa, // Middle dot
|
|
143
|
+
"√": 0xfb, // Square root
|
|
144
|
+
ⁿ: 0xfc, // Superscript n
|
|
145
|
+
"²": 0xfd, // Superscript 2
|
|
146
|
+
"■": 0xfe, // Black square
|
|
147
|
+
"\u00A0": 0x20, // Non-breaking space (U+A0) -> regular space
|
|
148
|
+
" ": 0xff, // Non-breaking space alternative
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Encode text to CP860 byte array
|
|
152
|
+
* Converts JavaScript string (UTF-16) to CP860 encoding for thermal printers
|
|
153
|
+
*
|
|
154
|
+
* @param text - Text to encode
|
|
155
|
+
* @returns Array of CP860 byte values
|
|
156
|
+
*/
|
|
157
|
+
function encodeCP860(text) {
|
|
158
|
+
const bytes = [];
|
|
159
|
+
for (let i = 0; i < text.length; i++) {
|
|
160
|
+
const char = text.charAt(i);
|
|
161
|
+
const charCode = text.charCodeAt(i);
|
|
162
|
+
// ASCII characters (0x00-0x7F) are the same in CP860
|
|
163
|
+
if (charCode < 0x80) {
|
|
164
|
+
bytes.push(charCode);
|
|
165
|
+
}
|
|
166
|
+
// Special characters mapped in CP860_MAP
|
|
167
|
+
else if (char in CP860_MAP) {
|
|
168
|
+
bytes.push(CP860_MAP[char]);
|
|
169
|
+
}
|
|
170
|
+
// Unmapped character - use '?' as fallback
|
|
171
|
+
else {
|
|
172
|
+
bytes.push(0x3f); // '?'
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return bytes;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Test if a character is supported in CP860
|
|
179
|
+
*/
|
|
180
|
+
function isCP860Supported(char) {
|
|
181
|
+
const charCode = char.charCodeAt(0);
|
|
182
|
+
return charCode < 0x80 || char in CP860_MAP;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Common Portuguese words test string
|
|
186
|
+
*/
|
|
187
|
+
exports.CP860_TEST_STRING = "Ação, Pão, Açúcar, Café, Atenção, Informação, São Paulo, João, José";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { CommandAdapter } from "./command-adapters";
|
|
2
|
+
/**
|
|
3
|
+
* ESC/POS Command Generator
|
|
4
|
+
* Manages the buffer and context for generating ESC/POS commands
|
|
5
|
+
* Pure JavaScript implementation - no Node.js dependencies
|
|
6
|
+
*/
|
|
7
|
+
export declare class ESCPOSGenerator {
|
|
8
|
+
private buffer;
|
|
9
|
+
private context;
|
|
10
|
+
private commandAdapter;
|
|
11
|
+
constructor(paperWidth?: number, encoding?: string, debug?: boolean, commandAdapter?: CommandAdapter);
|
|
12
|
+
/**
|
|
13
|
+
* Initialize printer
|
|
14
|
+
* Sets up the printer with default settings and comfortable line spacing
|
|
15
|
+
*/
|
|
16
|
+
initialize(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Set line spacing using command adapter
|
|
19
|
+
* @param dots - Line spacing in dots (0-255). Use 0 for minimal spacing, undefined for default (1/6 inch)
|
|
20
|
+
*/
|
|
21
|
+
setLineSpacing(dots?: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Set text alignment using command adapter
|
|
24
|
+
*/
|
|
25
|
+
setAlign(align: "left" | "center" | "right"): void;
|
|
26
|
+
/**
|
|
27
|
+
* Set text bold
|
|
28
|
+
* Uses ESC ! command which combines size and emphasis
|
|
29
|
+
*/
|
|
30
|
+
setBold(bold: boolean): void;
|
|
31
|
+
/**
|
|
32
|
+
* Set text size using width and height multipliers
|
|
33
|
+
* Uses ESC ! command which combines size and emphasis
|
|
34
|
+
* @param size - Character size as {width, height} multipliers (max 2x2 for ESC !)
|
|
35
|
+
*/
|
|
36
|
+
setSize(size: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
}): void;
|
|
40
|
+
/**
|
|
41
|
+
* Apply current print mode (size + bold) using command adapter
|
|
42
|
+
* This combines character size and emphasis into a single command
|
|
43
|
+
*/
|
|
44
|
+
private applyPrintMode;
|
|
45
|
+
/**
|
|
46
|
+
* Reset text formatting to defaults
|
|
47
|
+
* Note: Alignment is NOT reset here because it should persist for the entire line
|
|
48
|
+
*/
|
|
49
|
+
resetFormatting(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Add text with current formatting
|
|
52
|
+
*/
|
|
53
|
+
addText(text: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Add newline using command adapter
|
|
56
|
+
*/
|
|
57
|
+
addNewline(count?: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* Add line feed using command adapter
|
|
60
|
+
*/
|
|
61
|
+
addLineFeed(lines?: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* Add divider line
|
|
64
|
+
*/
|
|
65
|
+
addDivider(dashed?: boolean): void;
|
|
66
|
+
/**
|
|
67
|
+
* Add QR code using command adapter
|
|
68
|
+
*/
|
|
69
|
+
addQRCode(data: string, size?: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Add image from base64 or data URI
|
|
72
|
+
* Converts image to monochrome bitmap and prints using ESC/POS raster graphics
|
|
73
|
+
* @param source - Base64 string, data URI, or object with uri property
|
|
74
|
+
*/
|
|
75
|
+
addImage(source: string | {
|
|
76
|
+
uri: string;
|
|
77
|
+
}): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Apply text styles from style object
|
|
80
|
+
*/
|
|
81
|
+
applyTextStyle(style: any): void;
|
|
82
|
+
/**
|
|
83
|
+
* Apply spacing from view style
|
|
84
|
+
*/
|
|
85
|
+
applyViewSpacing(style: any, type: "before" | "after"): void;
|
|
86
|
+
/**
|
|
87
|
+
* Cut paper with full cut using command adapter
|
|
88
|
+
*/
|
|
89
|
+
cutFull(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Cut paper with partial cut using command adapter
|
|
92
|
+
*/
|
|
93
|
+
cutPartial(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Cut paper with feed then full cut using command adapter
|
|
96
|
+
* @param lines - Number of lines to feed before cutting (1-255)
|
|
97
|
+
*/
|
|
98
|
+
cutFullWithFeed(lines?: number): void;
|
|
99
|
+
/**
|
|
100
|
+
* Cut paper with feed then partial cut using command adapter
|
|
101
|
+
* @param lines - Number of lines to feed before cutting (1-255)
|
|
102
|
+
*/
|
|
103
|
+
cutPartialWithFeed(lines?: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Add raw ESC/POS command
|
|
106
|
+
* @param data - Raw buffer data to send to printer
|
|
107
|
+
*/
|
|
108
|
+
addRawCommand(data: Buffer): void;
|
|
109
|
+
/**
|
|
110
|
+
* Get the final buffer
|
|
111
|
+
*/
|
|
112
|
+
getBuffer(): Buffer;
|
|
113
|
+
/**
|
|
114
|
+
* Get paper width
|
|
115
|
+
*/
|
|
116
|
+
getPaperWidth(): number;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AAqC1E;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,cAAc,CAAiB;gBAGrC,UAAU,SAAK,EACf,QAAQ,SAAU,EAClB,KAAK,UAAQ,EACb,cAAc,CAAC,EAAE,cAAc;IAqBjC;;;OAGG;IACH,UAAU,IAAI,IAAI;IAUlB;;;OAGG;IACH,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAKnC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI;IAQlD;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAO5B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAWtD;;;OAGG;IACH,OAAO,CAAC,cAAc;IAStB;;;OAGG;IACH,eAAe,IAAI,IAAI;IAMvB;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ3B;;OAEG;IACH,UAAU,CAAC,KAAK,SAAI,GAAG,IAAI;IAK3B;;OAEG;IACH,WAAW,CAAC,KAAK,SAAI,GAAG,IAAI;IAK5B;;OAEG;IACH,UAAU,CAAC,MAAM,UAAQ,GAAG,IAAI;IAOhC;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,IAAI;IAYvC;;;;OAIG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA2F/D;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAgBhC;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI;IAgB5D;;OAEG;IACH,OAAO,IAAI,IAAI;IAKf;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;;OAGG;IACH,eAAe,CAAC,KAAK,SAAI,GAAG,IAAI;IAMhC;;;OAGG;IACH,kBAAkB,CAAC,KAAK,SAAI,GAAG,IAAI;IAMnC;;;OAGG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,SAAS,IAAI,MAAM;IAYnB;;OAEG;IACH,aAAa,IAAI,MAAM;CAGxB"}
|