@thermal-print/escpos 0.2.0 → 0.3.1-beta.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/dist/command-adapters/escbematech-adapter.d.ts +1 -1
- package/dist/command-adapters/escbematech-adapter.d.ts.map +1 -1
- package/dist/command-adapters/escbematech-adapter.js +3 -40
- package/dist/command-adapters/escpos-adapter.d.ts +1 -1
- package/dist/command-adapters/escpos-adapter.d.ts.map +1 -1
- package/dist/command-adapters/escpos-adapter.js +5 -42
- package/dist/command-adapters/index.d.ts +1 -1
- package/dist/command-adapters/index.d.ts.map +1 -1
- package/dist/command-adapters/index.js +2 -7
- package/dist/command-adapters/types.d.ts +2 -1
- package/dist/command-adapters/types.d.ts.map +1 -1
- package/dist/command-adapters/types.js +1 -2
- package/dist/commands/escbematech.js +217 -306
- package/dist/commands/escpos.d.ts +2 -1
- package/dist/commands/escpos.d.ts.map +1 -1
- package/dist/commands/escpos.js +195 -268
- package/dist/converter.js +10 -13
- package/dist/encodings/cp860.js +3 -8
- package/dist/generator.d.ts +11 -5
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +50 -64
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -44
- package/dist/styles.d.ts +14 -19
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +32 -52
- package/dist/traverser.d.ts.map +1 -1
- package/dist/traverser.js +55 -32
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/package.json +18 -9
- package/LICENSE +0 -21
package/dist/converter.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const generator_1 = require("./generator");
|
|
5
|
-
const traverser_1 = require("./traverser");
|
|
6
|
-
const command_adapters_1 = require("./command-adapters");
|
|
1
|
+
import { ESCPOSGenerator } from './generator';
|
|
2
|
+
import { TreeTraverser } from './traverser';
|
|
3
|
+
import { ESCPOSCommandAdapter, ESCBematechCommandAdapter } from './command-adapters';
|
|
7
4
|
/**
|
|
8
5
|
* Create command adapter based on configuration
|
|
9
6
|
*/
|
|
10
7
|
function createCommandAdapter(config) {
|
|
11
8
|
// If no config provided, default to ESC/POS
|
|
12
9
|
if (!config) {
|
|
13
|
-
return new
|
|
10
|
+
return new ESCPOSCommandAdapter();
|
|
14
11
|
}
|
|
15
12
|
// If it's already a CommandAdapter instance, return it
|
|
16
13
|
if (typeof config === 'object' && 'getName' in config) {
|
|
@@ -18,13 +15,13 @@ function createCommandAdapter(config) {
|
|
|
18
15
|
}
|
|
19
16
|
// If it's a string identifier, create the appropriate adapter
|
|
20
17
|
if (config === 'escpos') {
|
|
21
|
-
return new
|
|
18
|
+
return new ESCPOSCommandAdapter();
|
|
22
19
|
}
|
|
23
20
|
else if (config === 'escbematech') {
|
|
24
|
-
return new
|
|
21
|
+
return new ESCBematechCommandAdapter();
|
|
25
22
|
}
|
|
26
23
|
// Default to ESC/POS if unknown
|
|
27
|
-
return new
|
|
24
|
+
return new ESCPOSCommandAdapter();
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
27
|
* Converts PrintNode tree to ESC/POS buffer
|
|
@@ -58,7 +55,7 @@ function createCommandAdapter(config) {
|
|
|
58
55
|
* });
|
|
59
56
|
* ```
|
|
60
57
|
*/
|
|
61
|
-
async function printNodesToESCPOS(printNode, options) {
|
|
58
|
+
export async function printNodesToESCPOS(printNode, options) {
|
|
62
59
|
const { paperWidth = 48, // Default to 48 chars (80mm thermal)
|
|
63
60
|
encoding = "utf-8", debug = false, cut = "full", // Default to full cut
|
|
64
61
|
feedBeforeCut = 3, // Default to 3 lines feed before cut
|
|
@@ -73,9 +70,9 @@ async function printNodesToESCPOS(printNode, options) {
|
|
|
73
70
|
console.log("============================================\n");
|
|
74
71
|
}
|
|
75
72
|
// Create ESC/POS generator with command adapter
|
|
76
|
-
const generator = new
|
|
73
|
+
const generator = new ESCPOSGenerator(paperWidth, encoding, debug, commandAdapter);
|
|
77
74
|
// Traverse tree and generate commands
|
|
78
|
-
const traverser = new
|
|
75
|
+
const traverser = new TreeTraverser(generator);
|
|
79
76
|
await traverser.traverse(printNode);
|
|
80
77
|
// Add cut command if requested
|
|
81
78
|
if (cut !== false) {
|
package/dist/encodings/cp860.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* CP860 (Portuguese) Character Encoding Map
|
|
4
3
|
*
|
|
@@ -7,10 +6,6 @@
|
|
|
7
6
|
*
|
|
8
7
|
* Includes special characters: ç Ç á é í ó ú à ã õ â ê ô
|
|
9
8
|
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.CP860_TEST_STRING = void 0;
|
|
12
|
-
exports.encodeCP860 = encodeCP860;
|
|
13
|
-
exports.isCP860Supported = isCP860Supported;
|
|
14
9
|
// CP860 character map (0x80-0xFF)
|
|
15
10
|
// 0x00-0x7F are standard ASCII (unchanged)
|
|
16
11
|
const CP860_MAP = {
|
|
@@ -154,7 +149,7 @@ const CP860_MAP = {
|
|
|
154
149
|
* @param text - Text to encode
|
|
155
150
|
* @returns Array of CP860 byte values
|
|
156
151
|
*/
|
|
157
|
-
function encodeCP860(text) {
|
|
152
|
+
export function encodeCP860(text) {
|
|
158
153
|
const bytes = [];
|
|
159
154
|
for (let i = 0; i < text.length; i++) {
|
|
160
155
|
const char = text.charAt(i);
|
|
@@ -177,11 +172,11 @@ function encodeCP860(text) {
|
|
|
177
172
|
/**
|
|
178
173
|
* Test if a character is supported in CP860
|
|
179
174
|
*/
|
|
180
|
-
function isCP860Supported(char) {
|
|
175
|
+
export function isCP860Supported(char) {
|
|
181
176
|
const charCode = char.charCodeAt(0);
|
|
182
177
|
return charCode < 0x80 || char in CP860_MAP;
|
|
183
178
|
}
|
|
184
179
|
/**
|
|
185
180
|
* Common Portuguese words test string
|
|
186
181
|
*/
|
|
187
|
-
|
|
182
|
+
export const CP860_TEST_STRING = "Ação, Pão, Açúcar, Café, Atenção, Informação, São Paulo, João, José";
|
package/dist/generator.d.ts
CHANGED
|
@@ -29,17 +29,23 @@ export declare class ESCPOSGenerator {
|
|
|
29
29
|
*/
|
|
30
30
|
setBold(bold: boolean): void;
|
|
31
31
|
/**
|
|
32
|
-
* Set text size using width and
|
|
33
|
-
* Uses ESC ! command which combines size and emphasis
|
|
34
|
-
* @param size - Character size
|
|
32
|
+
* Set text size using width/height multipliers and font selection
|
|
33
|
+
* Uses ESC ! command which combines size, font, and emphasis
|
|
34
|
+
* @param size - Character size with font: {font, width, height}
|
|
35
35
|
*/
|
|
36
36
|
setSize(size: {
|
|
37
37
|
width: number;
|
|
38
38
|
height: number;
|
|
39
|
+
font?: 0 | 1;
|
|
39
40
|
}): void;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* Update effective paper width based on current font and size
|
|
43
|
+
* Font A 1x1 → 48 cols, Font A 2x → 24 cols, Font B 1x1 → 64 cols
|
|
44
|
+
*/
|
|
45
|
+
private updatePaperWidth;
|
|
46
|
+
/**
|
|
47
|
+
* Apply current print mode (font + size + bold) using command adapter
|
|
48
|
+
* This combines font selection, character size, and emphasis into a single command
|
|
43
49
|
*/
|
|
44
50
|
private applyPrintMode;
|
|
45
51
|
/**
|
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +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,CA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;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"}
|
package/dist/generator.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ESCPOSGenerator = void 0;
|
|
37
|
-
const escpos_1 = require("./commands/escpos");
|
|
38
|
-
const styles_1 = require("./styles");
|
|
39
|
-
const command_adapters_1 = require("./command-adapters");
|
|
1
|
+
import { encodeText } from "./commands/escpos";
|
|
2
|
+
import { extractTextStyle, extractViewStyle, generateDividerLine, isBold, isDashedBorder, mapFontSizeToESCPOS, mapTextAlign, } from "./styles";
|
|
3
|
+
import { ESCPOSCommandAdapter } from "./command-adapters";
|
|
40
4
|
/**
|
|
41
5
|
* Simple buffer implementation for accumulating ESC/POS commands
|
|
42
6
|
*/
|
|
@@ -74,15 +38,17 @@ class ESCPOSBuffer {
|
|
|
74
38
|
* Manages the buffer and context for generating ESC/POS commands
|
|
75
39
|
* Pure JavaScript implementation - no Node.js dependencies
|
|
76
40
|
*/
|
|
77
|
-
class ESCPOSGenerator {
|
|
41
|
+
export class ESCPOSGenerator {
|
|
78
42
|
constructor(paperWidth = 48, encoding = "cp860", debug = false, commandAdapter) {
|
|
79
43
|
this.buffer = new ESCPOSBuffer();
|
|
80
44
|
// Use provided adapter or default to ESC/POS
|
|
81
|
-
this.commandAdapter = commandAdapter || new
|
|
45
|
+
this.commandAdapter = commandAdapter || new ESCPOSCommandAdapter();
|
|
82
46
|
this.context = {
|
|
83
47
|
paperWidth,
|
|
48
|
+
basePaperWidth: paperWidth,
|
|
84
49
|
currentAlign: "left",
|
|
85
50
|
currentSize: { width: 1, height: 1 },
|
|
51
|
+
currentFont: 0,
|
|
86
52
|
currentBold: false,
|
|
87
53
|
encoding,
|
|
88
54
|
debug,
|
|
@@ -99,8 +65,7 @@ class ESCPOSGenerator {
|
|
|
99
65
|
// Initialize with comfortable line spacing (30 dots ≈ default 1/6 inch)
|
|
100
66
|
// Common values: 10 (tight), 20 (moderate), 30 (default), 40 (spacious)
|
|
101
67
|
this.setLineSpacing(5);
|
|
102
|
-
// Apply initial print mode
|
|
103
|
-
// This ensures the narrower font (9×17) is used from the start
|
|
68
|
+
// Apply initial print mode with Font A (48 cols) as default
|
|
104
69
|
this.applyPrintMode();
|
|
105
70
|
}
|
|
106
71
|
/**
|
|
@@ -132,24 +97,46 @@ class ESCPOSGenerator {
|
|
|
132
97
|
}
|
|
133
98
|
}
|
|
134
99
|
/**
|
|
135
|
-
* Set text size using width and
|
|
136
|
-
* Uses ESC ! command which combines size and emphasis
|
|
137
|
-
* @param size - Character size
|
|
100
|
+
* Set text size using width/height multipliers and font selection
|
|
101
|
+
* Uses ESC ! command which combines size, font, and emphasis
|
|
102
|
+
* @param size - Character size with font: {font, width, height}
|
|
138
103
|
*/
|
|
139
104
|
setSize(size) {
|
|
140
|
-
|
|
105
|
+
const font = size.font ?? 0;
|
|
106
|
+
// Only update if size or font actually changed
|
|
141
107
|
if (this.context.currentSize.width !== size.width ||
|
|
142
|
-
this.context.currentSize.height !== size.height
|
|
108
|
+
this.context.currentSize.height !== size.height ||
|
|
109
|
+
this.context.currentFont !== font) {
|
|
143
110
|
this.context.currentSize = size;
|
|
111
|
+
this.context.currentFont = font;
|
|
112
|
+
this.updatePaperWidth();
|
|
144
113
|
this.applyPrintMode();
|
|
145
114
|
}
|
|
146
115
|
}
|
|
147
116
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
117
|
+
* Update effective paper width based on current font and size
|
|
118
|
+
* Font A 1x1 → 48 cols, Font A 2x → 24 cols, Font B 1x1 → 64 cols
|
|
119
|
+
*/
|
|
120
|
+
updatePaperWidth() {
|
|
121
|
+
if (this.context.currentFont === 1) {
|
|
122
|
+
// Font B: 64 cols
|
|
123
|
+
this.context.paperWidth = 64;
|
|
124
|
+
}
|
|
125
|
+
else if (this.context.currentSize.width >= 2) {
|
|
126
|
+
// Font A double-width: 24 cols
|
|
127
|
+
this.context.paperWidth = Math.floor(this.context.basePaperWidth / 2);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Font A normal: 48 cols (basePaperWidth)
|
|
131
|
+
this.context.paperWidth = this.context.basePaperWidth;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Apply current print mode (font + size + bold) using command adapter
|
|
136
|
+
* This combines font selection, character size, and emphasis into a single command
|
|
150
137
|
*/
|
|
151
138
|
applyPrintMode() {
|
|
152
|
-
const command = this.commandAdapter.getCharacterSizeCommand(this.context.currentSize.width, this.context.currentSize.height, this.context.currentBold);
|
|
139
|
+
const command = this.commandAdapter.getCharacterSizeCommand(this.context.currentSize.width, this.context.currentSize.height, this.context.currentBold, this.context.currentFont);
|
|
153
140
|
this.buffer.pushArray(command);
|
|
154
141
|
}
|
|
155
142
|
/**
|
|
@@ -159,7 +146,7 @@ class ESCPOSGenerator {
|
|
|
159
146
|
resetFormatting() {
|
|
160
147
|
this.setAlign("left");
|
|
161
148
|
this.setBold(false);
|
|
162
|
-
this.setSize({ width: 1, height: 1 });
|
|
149
|
+
this.setSize({ width: 1, height: 1, font: 0 });
|
|
163
150
|
}
|
|
164
151
|
/**
|
|
165
152
|
* Add text with current formatting
|
|
@@ -167,7 +154,7 @@ class ESCPOSGenerator {
|
|
|
167
154
|
addText(text) {
|
|
168
155
|
if (text) {
|
|
169
156
|
// Encode text to CP860 for Portuguese support
|
|
170
|
-
const encodedBytes =
|
|
157
|
+
const encodedBytes = encodeText(text);
|
|
171
158
|
this.buffer.pushArray(encodedBytes);
|
|
172
159
|
}
|
|
173
160
|
}
|
|
@@ -190,7 +177,7 @@ class ESCPOSGenerator {
|
|
|
190
177
|
*/
|
|
191
178
|
addDivider(dashed = false) {
|
|
192
179
|
this.setAlign("left");
|
|
193
|
-
const line =
|
|
180
|
+
const line = generateDividerLine(this.context.paperWidth, dashed);
|
|
194
181
|
this.addText(line);
|
|
195
182
|
this.addNewline();
|
|
196
183
|
}
|
|
@@ -217,7 +204,7 @@ class ESCPOSGenerator {
|
|
|
217
204
|
async addImage(source) {
|
|
218
205
|
try {
|
|
219
206
|
// Import Jimp dynamically to avoid loading if not needed
|
|
220
|
-
const { Jimp } = await
|
|
207
|
+
const { Jimp } = await import("jimp");
|
|
221
208
|
// Extract the actual data URI or base64 string
|
|
222
209
|
let imageSource;
|
|
223
210
|
if (typeof source === "string") {
|
|
@@ -293,32 +280,32 @@ class ESCPOSGenerator {
|
|
|
293
280
|
* Apply text styles from style object
|
|
294
281
|
*/
|
|
295
282
|
applyTextStyle(style) {
|
|
296
|
-
const textStyle =
|
|
283
|
+
const textStyle = extractTextStyle(style);
|
|
297
284
|
// Set alignment
|
|
298
|
-
const align =
|
|
285
|
+
const align = mapTextAlign(textStyle.textAlign);
|
|
299
286
|
this.setAlign(align);
|
|
300
287
|
// Set bold
|
|
301
|
-
const bold =
|
|
288
|
+
const bold = isBold(textStyle);
|
|
302
289
|
this.setBold(bold);
|
|
303
|
-
// Set size
|
|
304
|
-
const size =
|
|
290
|
+
// Set size (includes font selection based on fontSize)
|
|
291
|
+
const size = mapFontSizeToESCPOS(textStyle.fontSize);
|
|
305
292
|
this.setSize(size);
|
|
306
293
|
}
|
|
307
294
|
/**
|
|
308
295
|
* Apply spacing from view style
|
|
309
296
|
*/
|
|
310
297
|
applyViewSpacing(style, type) {
|
|
311
|
-
const viewStyle =
|
|
298
|
+
const viewStyle = extractViewStyle(style);
|
|
312
299
|
if (type === "before") {
|
|
313
300
|
// Apply top border
|
|
314
301
|
if (viewStyle.borderTop) {
|
|
315
|
-
this.addDivider(
|
|
302
|
+
this.addDivider(isDashedBorder(viewStyle.borderTop));
|
|
316
303
|
}
|
|
317
304
|
}
|
|
318
305
|
else {
|
|
319
306
|
// Apply bottom border
|
|
320
307
|
if (viewStyle.borderBottom) {
|
|
321
|
-
this.addDivider(
|
|
308
|
+
this.addDivider(isDashedBorder(viewStyle.borderBottom));
|
|
322
309
|
}
|
|
323
310
|
}
|
|
324
311
|
}
|
|
@@ -380,4 +367,3 @@ class ESCPOSGenerator {
|
|
|
380
367
|
return this.context.paperWidth;
|
|
381
368
|
}
|
|
382
369
|
}
|
|
383
|
-
exports.ESCPOSGenerator = ESCPOSGenerator;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Main API: printNodesToESCPOS(printNode, options) -> Buffer
|
|
7
7
|
*/
|
|
8
|
-
export { printNodesToESCPOS
|
|
8
|
+
export { printNodesToESCPOS } from './converter';
|
|
9
|
+
export type { PrintNodeToESCPOSOptions } from './converter';
|
|
9
10
|
export { ESCPOSGenerator } from './generator';
|
|
10
11
|
export { TreeTraverser } from './traverser';
|
|
11
|
-
export { CommandAdapter, CharacterSize } from './command-adapters/types';
|
|
12
|
+
export type { CommandAdapter, CharacterSize } from './command-adapters/types';
|
|
12
13
|
export { ESCPOSCommandAdapter } from './command-adapters/escpos-adapter';
|
|
13
14
|
export { ESCBematechCommandAdapter } from './command-adapters/escbematech-adapter';
|
|
14
15
|
export { extractTextStyle, extractViewStyle, isBold, mapFontSizeToESCPOS, mapTextAlign, calculateSpacing, isDashedBorder, generateDividerLine, mergeStyles, parseWidth, alignTextInColumn, wrapText, } from './styles';
|
|
15
16
|
export { encodeCP860 } from './encodings/cp860';
|
|
16
|
-
export * from './types';
|
|
17
|
+
export type * from './types';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAGnF,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,QAAQ,GACT,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,mBAAmB,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @thermal-print/escpos
|
|
4
3
|
*
|
|
@@ -6,50 +5,14 @@
|
|
|
6
5
|
*
|
|
7
6
|
* Main API: printNodesToESCPOS(printNode, options) -> Buffer
|
|
8
7
|
*/
|
|
9
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
-
};
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.encodeCP860 = exports.wrapText = exports.alignTextInColumn = exports.parseWidth = exports.mergeStyles = exports.generateDividerLine = exports.isDashedBorder = exports.calculateSpacing = exports.mapTextAlign = exports.mapFontSizeToESCPOS = exports.isBold = exports.extractViewStyle = exports.extractTextStyle = exports.ESCBematechCommandAdapter = exports.ESCPOSCommandAdapter = exports.TreeTraverser = exports.ESCPOSGenerator = exports.printNodesToESCPOS = void 0;
|
|
25
8
|
// Main conversion function
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(exports, "printNodesToESCPOS", { enumerable: true, get: function () { return converter_1.printNodesToESCPOS; } });
|
|
9
|
+
export { printNodesToESCPOS } from './converter';
|
|
28
10
|
// Core classes (for advanced usage)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var escpos_adapter_1 = require("./command-adapters/escpos-adapter");
|
|
34
|
-
Object.defineProperty(exports, "ESCPOSCommandAdapter", { enumerable: true, get: function () { return escpos_adapter_1.ESCPOSCommandAdapter; } });
|
|
35
|
-
var escbematech_adapter_1 = require("./command-adapters/escbematech-adapter");
|
|
36
|
-
Object.defineProperty(exports, "ESCBematechCommandAdapter", { enumerable: true, get: function () { return escbematech_adapter_1.ESCBematechCommandAdapter; } });
|
|
11
|
+
export { ESCPOSGenerator } from './generator';
|
|
12
|
+
export { TreeTraverser } from './traverser';
|
|
13
|
+
export { ESCPOSCommandAdapter } from './command-adapters/escpos-adapter';
|
|
14
|
+
export { ESCBematechCommandAdapter } from './command-adapters/escbematech-adapter';
|
|
37
15
|
// Style utilities
|
|
38
|
-
|
|
39
|
-
Object.defineProperty(exports, "extractTextStyle", { enumerable: true, get: function () { return styles_1.extractTextStyle; } });
|
|
40
|
-
Object.defineProperty(exports, "extractViewStyle", { enumerable: true, get: function () { return styles_1.extractViewStyle; } });
|
|
41
|
-
Object.defineProperty(exports, "isBold", { enumerable: true, get: function () { return styles_1.isBold; } });
|
|
42
|
-
Object.defineProperty(exports, "mapFontSizeToESCPOS", { enumerable: true, get: function () { return styles_1.mapFontSizeToESCPOS; } });
|
|
43
|
-
Object.defineProperty(exports, "mapTextAlign", { enumerable: true, get: function () { return styles_1.mapTextAlign; } });
|
|
44
|
-
Object.defineProperty(exports, "calculateSpacing", { enumerable: true, get: function () { return styles_1.calculateSpacing; } });
|
|
45
|
-
Object.defineProperty(exports, "isDashedBorder", { enumerable: true, get: function () { return styles_1.isDashedBorder; } });
|
|
46
|
-
Object.defineProperty(exports, "generateDividerLine", { enumerable: true, get: function () { return styles_1.generateDividerLine; } });
|
|
47
|
-
Object.defineProperty(exports, "mergeStyles", { enumerable: true, get: function () { return styles_1.mergeStyles; } });
|
|
48
|
-
Object.defineProperty(exports, "parseWidth", { enumerable: true, get: function () { return styles_1.parseWidth; } });
|
|
49
|
-
Object.defineProperty(exports, "alignTextInColumn", { enumerable: true, get: function () { return styles_1.alignTextInColumn; } });
|
|
50
|
-
Object.defineProperty(exports, "wrapText", { enumerable: true, get: function () { return styles_1.wrapText; } });
|
|
16
|
+
export { extractTextStyle, extractViewStyle, isBold, mapFontSizeToESCPOS, mapTextAlign, calculateSpacing, isDashedBorder, generateDividerLine, mergeStyles, parseWidth, alignTextInColumn, wrapText, } from './styles';
|
|
51
17
|
// Encodings
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(exports, "encodeCP860", { enumerable: true, get: function () { return cp860_1.encodeCP860; } });
|
|
54
|
-
// Types
|
|
55
|
-
__exportStar(require("./types"), exports);
|
|
18
|
+
export { encodeCP860 } from './encodings/cp860';
|
package/dist/styles.d.ts
CHANGED
|
@@ -12,29 +12,24 @@ export declare function extractViewStyle(style: any): ViewStyle;
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function isBold(style: TextStyle): boolean;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* ESC/POS font size mapping result
|
|
16
|
+
*/
|
|
17
|
+
export interface ESCPOSFontSize {
|
|
18
|
+
font: 0 | 1;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Maps fontSize to ESC/POS font selection + character size multipliers
|
|
16
24
|
*
|
|
17
|
-
*
|
|
18
|
-
* -
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
21
|
-
* - 25+px → 2x2 (double width, double height)
|
|
25
|
+
* Three visual levels using standard ESC/POS fonts:
|
|
26
|
+
* - Condensada: Font B 1x1 (9x17, 64 cols) — fontSize <= 10
|
|
27
|
+
* - Normal: Font A 1x1 (12x24, 48 cols) — fontSize 11-19
|
|
28
|
+
* - Expandida: Font A 2x2 (12x24, 24 cols) — fontSize >= 20
|
|
22
29
|
*
|
|
23
30
|
* Note: ESC ! command only supports up to 2x2 character size.
|
|
24
|
-
* Larger sizes (3x, 4x, etc.) would require GS ! command which may not
|
|
25
|
-
* be supported on all thermal printers (e.g., Bematech MP-4200 TH).
|
|
26
|
-
*
|
|
27
|
-
* PDF uses zoom factor (default 0.46), so actual sizes are smaller:
|
|
28
|
-
* - 16 * 0.46 = 7.36 (normal text)
|
|
29
|
-
* - 18 * 0.46 = 8.28 (medium text)
|
|
30
|
-
* - 20 * 0.46 = 9.2 (title text)
|
|
31
|
-
*
|
|
32
|
-
* We use raw fontSize values (ignoring zoom) for better differentiation
|
|
33
31
|
*/
|
|
34
|
-
export declare function mapFontSizeToESCPOS(fontSize?: number | string):
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
};
|
|
32
|
+
export declare function mapFontSizeToESCPOS(fontSize?: number | string): ESCPOSFontSize;
|
|
38
33
|
/**
|
|
39
34
|
* Maps textAlign to ESC/POS alignment
|
|
40
35
|
*/
|
package/dist/styles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAOtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAoBtD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAOhD;AAED
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAOtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAoBtD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAOhD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;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