tauri-plugin-thermal-printer 1.0.2 → 1.2.2

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-js/index.js CHANGED
@@ -1,17 +1,247 @@
1
1
  import { invoke } from '@tauri-apps/api/core';
2
2
 
3
+ const PAPER_SIZE_CHARS_PER_LINE = {
4
+ Mm40: 21,
5
+ Mm44: 24,
6
+ Mm58: 32,
7
+ Mm72: 42,
8
+ Mm80: 48,
9
+ Mm104: 62,
10
+ };
11
+ const PAPER_SIZE_PIXELS_WIDTH = {
12
+ Mm40: 256,
13
+ Mm44: 288,
14
+ Mm58: 384,
15
+ Mm72: 512,
16
+ Mm80: 576,
17
+ Mm104: 752,
18
+ };
19
+ const DEFAULT_PAPER_SIZE = 'Mm80';
20
+ function getPaperSizeCharsPerLine(paperSize) {
21
+ return PAPER_SIZE_CHARS_PER_LINE[paperSize];
22
+ }
23
+ function getPaperSizePixelsWidth(paperSize) {
24
+ return PAPER_SIZE_PIXELS_WIDTH[paperSize];
25
+ }
26
+ // ─── Convenience style presets ────────────────────────────────────────────────
27
+ const TEXT_ALIGN = {
28
+ LEFT: 'left',
29
+ CENTER: 'center',
30
+ RIGHT: 'right',
31
+ };
32
+ const TEXT_SIZE = {
33
+ NORMAL: 'normal',
34
+ HEIGHT: 'height',
35
+ WIDTH: 'width',
36
+ DOUBLE: 'double',
37
+ };
38
+ const TEXT_FONT = {
39
+ A: 'A',
40
+ B: 'B',
41
+ C: 'C',
42
+ };
43
+ const BARCODE_TYPE = {
44
+ UPC_A: 'UPC-A',
45
+ UPC_E: 'UPC-E',
46
+ EAN13: 'EAN13',
47
+ EAN8: 'EAN8',
48
+ CODE39: 'CODE39',
49
+ ITF: 'ITF',
50
+ CODABAR: 'CODABAR',
51
+ CODE93: 'CODE93',
52
+ CODE128: 'CODE128',
53
+ };
54
+ const BARCODE_TEXT_POSITION = {
55
+ NONE: 'none',
56
+ ABOVE: 'above',
57
+ BELOW: 'below',
58
+ BOTH: 'both',
59
+ };
60
+ const QR_ERROR_CORRECTION = {
61
+ /** Low — 7% recovery */
62
+ L: 'L',
63
+ /** Medium — 15% recovery (recommended default) */
64
+ M: 'M',
65
+ /** Quartile — 25% recovery */
66
+ Q: 'Q',
67
+ /** High — 30% recovery */
68
+ H: 'H',
69
+ };
70
+ const IMAGE_MODE = {
71
+ NORMAL: 'normal',
72
+ DOUBLE_WIDTH: 'double_width',
73
+ DOUBLE_HEIGHT: 'double_height',
74
+ QUADRUPLE: 'quadruple',
75
+ };
76
+ const CUT_MODE = {
77
+ FULL: 'full',
78
+ PARTIAL: 'partial',
79
+ };
80
+ const CODE_PAGE = {
81
+ /** CP437 — ASCII only, no accented characters */
82
+ DEFAULT: 'Default',
83
+ /** CP850 — Spanish, French, Italian, German */
84
+ SPANISH: 'Spanish',
85
+ /** CP850 — Alias of Spanish */
86
+ FRENCH: 'French',
87
+ /** CP860 — Portuguese (ã, õ) */
88
+ PORTUGUESE: 'Portuguese',
89
+ /** CP863 — Canadian French */
90
+ CANADIAN_FRENCH: 'CanadianFrench',
91
+ /** CP865 — Nordic languages (å, ø, æ) */
92
+ NORDIC: 'Nordic',
93
+ /** CP1252 — Wide Western European, includes € */
94
+ WINDOWS_LATIN: 'WindowsLatin',
95
+ /** CP866 — Russian / Cyrillic */
96
+ RUSSIAN: 'Russian',
97
+ /** CP852 — Eastern Europe (Polish, Czech, Slovak, Hungarian) */
98
+ EASTERN_EUROPE: 'EasternEurope',
99
+ /** Strips accents and special chars to plain ASCII. Use when the printer
100
+ * ignores ESC t commands. á→a, é→e, ñ→n, ß→ss, ¿→?, €→EUR, etc. */
101
+ ACCENT_REMOVER: 'AccentRemover',
102
+ };
103
+ // ─── Helper builders ──────────────────────────────────────────────────────────
104
+ /** Creates a Title section */
105
+ function title(text, styles) {
106
+ return { Title: { text, styles } };
107
+ }
108
+ /** Creates a Subtitle section */
109
+ function subtitle(text, styles) {
110
+ return { Subtitle: { text, styles } };
111
+ }
112
+ /** Creates a Text section */
113
+ function text(text, styles) {
114
+ return { Text: { text, styles } };
115
+ }
116
+ /** Creates a Line separator section */
117
+ function line(character = '-') {
118
+ return { Line: { character } };
119
+ }
120
+ /** Creates a Feed section */
121
+ function feed(value, feed_type = 'lines') {
122
+ return { Feed: { feed_type, value } };
123
+ }
124
+ /** Creates a Cut section */
125
+ function cut(mode = 'partial', feedLines = 4) {
126
+ return { Cut: { mode, feed: feedLines } };
127
+ }
128
+ /** Creates a GlobalStyles section — affects all subsequent sections until changed */
129
+ function globalStyles(styles) {
130
+ return { GlobalStyles: styles };
131
+ }
132
+ /** Creates a Beep section */
133
+ function beep(times = 1, duration = 3) {
134
+ return { Beep: { times, duration } };
135
+ }
136
+ /** Creates a Drawer section */
137
+ function drawer(pin = 2, pulse_time = 120) {
138
+ return { Drawer: { pin, pulse_time } };
139
+ }
140
+ /** Creates a Table section */
141
+ function table(columns, body, options) {
142
+ return {
143
+ Table: {
144
+ columns,
145
+ body,
146
+ column_widths: options?.column_widths,
147
+ header: options?.header,
148
+ truncate: options?.truncate ?? true,
149
+ },
150
+ };
151
+ }
152
+ /** Creates a QR section */
153
+ function qr(data, options) {
154
+ return {
155
+ Qr: {
156
+ data,
157
+ size: options?.size ?? 6,
158
+ error_correction: options?.error_correction ?? 'M',
159
+ model: options?.model ?? 2,
160
+ align: options?.align,
161
+ },
162
+ };
163
+ }
164
+ /** Creates a Barcode section */
165
+ function barcode(data, barcode_type = 'CODE128', options) {
166
+ return {
167
+ Barcode: {
168
+ data,
169
+ barcode_type,
170
+ width: options?.width ?? 3,
171
+ height: options?.height ?? 80,
172
+ text_position: options?.text_position ?? 'below',
173
+ align: options?.align,
174
+ },
175
+ };
176
+ }
177
+ /** Creates a DataMatrix section */
178
+ function dataMatrix(data, size = 6) {
179
+ return {
180
+ DataMatrix: {
181
+ data,
182
+ size,
183
+ },
184
+ };
185
+ }
186
+ /** Creates a PDF417 section */
187
+ function pdf417(data, options) {
188
+ return {
189
+ Pdf417: {
190
+ data,
191
+ columns: options?.columns ?? 0,
192
+ rows: options?.rows ?? 0,
193
+ width: options?.width ?? 2,
194
+ height: options?.height ?? 3,
195
+ error_correction: options?.error_correction ?? 2,
196
+ },
197
+ };
198
+ }
199
+ /** Creates an Image section */
200
+ function image(data, options) {
201
+ return {
202
+ Image: {
203
+ data,
204
+ max_width: options?.max_width ?? 0,
205
+ align: options?.align ?? 'center',
206
+ dithering: options?.dithering ?? true,
207
+ size: options?.size ?? 'normal',
208
+ },
209
+ };
210
+ }
211
+ /** Creates a Logo section */
212
+ function logo(key_code, mode = 'normal') {
213
+ return {
214
+ Logo: {
215
+ key_code,
216
+ mode,
217
+ },
218
+ };
219
+ }
220
+ // ─── Commands ─────────────────────────────────────────────────────────────────
221
+ /**
222
+ * Sends a print job to the specified thermal printer.
223
+ * @throws {string} Error message from the printer or document generation if the job fails.
224
+ */
3
225
  async function print_thermal_printer(printJobRequest) {
4
- return await invoke('plugin:thermal-printer|print_thermal_printer', {
5
- printJobRequest: printJobRequest,
226
+ await invoke('plugin:thermal-printer|print_thermal_printer', {
227
+ printJobRequest,
6
228
  });
7
229
  }
230
+ /**
231
+ * Returns the list of available thermal printers on the current system.
232
+ * @throws {string} Error message if printer enumeration fails.
233
+ */
8
234
  async function list_thermal_printers() {
9
235
  return await invoke('plugin:thermal-printer|list_thermal_printers');
10
236
  }
237
+ /**
238
+ * Sends a test print job to verify the printer is working correctly.
239
+ * @throws {string} Error message from the printer or document generation if the job fails.
240
+ */
11
241
  async function test_thermal_printer(testPrintRequest) {
12
- return await invoke('plugin:thermal-printer|test_thermal_printer', {
242
+ await invoke('plugin:thermal-printer|test_thermal_printer', {
13
243
  printTestRequest: testPrintRequest,
14
244
  });
15
245
  }
16
246
 
17
- export { list_thermal_printers, print_thermal_printer, test_thermal_printer };
247
+ export { BARCODE_TEXT_POSITION, BARCODE_TYPE, CODE_PAGE, CUT_MODE, DEFAULT_PAPER_SIZE, IMAGE_MODE, PAPER_SIZE_CHARS_PER_LINE, PAPER_SIZE_PIXELS_WIDTH, QR_ERROR_CORRECTION, TEXT_ALIGN, TEXT_FONT, TEXT_SIZE, barcode, beep, cut, dataMatrix, drawer, feed, getPaperSizeCharsPerLine, getPaperSizePixelsWidth, globalStyles, image, line, list_thermal_printers, logo, pdf417, print_thermal_printer, qr, subtitle, table, test_thermal_printer, text, title };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-thermal-printer",
3
- "version": "1.0.2",
3
+ "version": "1.2.2",
4
4
  "author": "luis3132",
5
5
  "description": "Plugin for Tauri to send esc/pos commands to thermal_printer",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@rollup/plugin-typescript": "^12.3.0",
30
- "rollup": "^4.57.1",
30
+ "rollup": "^4.60.1",
31
31
  "typescript": "^5.9.3",
32
32
  "tslib": "^2.8.1"
33
33
  }