@devraghu/electron-printer 1.1.0 → 2.0.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/README.md +17 -14
- package/dist/index.d.ts +175 -128
- package/dist/index.js +157 -1
- package/dist/preload/preload.cjs +1 -1
- package/dist/renderer/assets/index-CuxDGCZK.js +9 -0
- package/dist/renderer/assets/index-Dr_XYfBm.css +1 -0
- package/dist/renderer/index.html +12 -1
- package/package.json +85 -92
- package/dist/renderer/renderer.js +0 -2
- package/dist/renderer/renderer.js.LICENSE.txt +0 -1
- package/dist/renderer/renderer.min.css +0 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ yarn add @devraghu/electron-printer
|
|
|
21
21
|
This library is designed for use in the **main process only**.
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
|
|
24
|
+
import { printer } from '@devraghu/electron-printer';
|
|
25
25
|
|
|
26
26
|
const options = {
|
|
27
27
|
preview: false,
|
|
@@ -55,7 +55,7 @@ const data = [
|
|
|
55
55
|
},
|
|
56
56
|
];
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
printer
|
|
59
59
|
.print(data, options)
|
|
60
60
|
.then(() => console.log('Print successful'))
|
|
61
61
|
.catch((error) => console.error(error));
|
|
@@ -63,12 +63,14 @@ posPrinter
|
|
|
63
63
|
|
|
64
64
|
> **Note:** If you need to trigger printing from the renderer process, use IPC to communicate with the main process.
|
|
65
65
|
|
|
66
|
-
## TypeScript
|
|
66
|
+
## TypeScript
|
|
67
|
+
|
|
68
|
+
Full TypeScript support with exported types:
|
|
67
69
|
|
|
68
70
|
```typescript
|
|
69
|
-
import {
|
|
71
|
+
import { printer, type PrintData, type PrintOptions, type PrintResult } from '@devraghu/electron-printer';
|
|
70
72
|
|
|
71
|
-
const options:
|
|
73
|
+
const options: PrintOptions = {
|
|
72
74
|
preview: false,
|
|
73
75
|
margin: '0 0 0 0',
|
|
74
76
|
copies: 1,
|
|
@@ -77,7 +79,7 @@ const options: PosPrintOptions = {
|
|
|
77
79
|
pageSize: '80mm',
|
|
78
80
|
};
|
|
79
81
|
|
|
80
|
-
const data:
|
|
82
|
+
const data: PrintData[] = [
|
|
81
83
|
{
|
|
82
84
|
type: 'text',
|
|
83
85
|
value: 'Hello World',
|
|
@@ -85,7 +87,7 @@ const data: PosPrintData[] = [
|
|
|
85
87
|
},
|
|
86
88
|
];
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
printer
|
|
89
91
|
.print(data, options)
|
|
90
92
|
.then(() => console.log('Done'))
|
|
91
93
|
.catch((error) => console.error(error));
|
|
@@ -232,9 +234,9 @@ Tables can contain text and images in cells:
|
|
|
232
234
|
Retrieve a list of all available printers on the system:
|
|
233
235
|
|
|
234
236
|
```typescript
|
|
235
|
-
import {
|
|
237
|
+
import { printer } from '@devraghu/electron-printer';
|
|
236
238
|
|
|
237
|
-
const printers =
|
|
239
|
+
const printers = await printer.getPrinters();
|
|
238
240
|
console.log(printers);
|
|
239
241
|
// [{ name: 'XP-80C', isDefault: true, ... }, ...]
|
|
240
242
|
```
|
|
@@ -244,10 +246,10 @@ console.log(printers);
|
|
|
244
246
|
Open a cash drawer connected to a thermal printer:
|
|
245
247
|
|
|
246
248
|
```typescript
|
|
247
|
-
import {
|
|
249
|
+
import { printer } from '@devraghu/electron-printer';
|
|
248
250
|
|
|
249
251
|
// Open cash drawer on specific printer
|
|
250
|
-
|
|
252
|
+
printer
|
|
251
253
|
.openCashDrawer('XP-80C')
|
|
252
254
|
.then(() => console.log('Cash drawer opened'))
|
|
253
255
|
.catch((error) => console.error('Failed to open cash drawer:', error));
|
|
@@ -262,15 +264,16 @@ electron-printer/
|
|
|
262
264
|
├── src/
|
|
263
265
|
│ ├── main/
|
|
264
266
|
│ │ ├── index.ts # Main exports
|
|
265
|
-
│ │ ├──
|
|
267
|
+
│ │ ├── printer.ts # Printer API
|
|
266
268
|
│ │ ├── models.ts # TypeScript interfaces
|
|
267
269
|
│ │ └── utils.ts # Helper functions
|
|
268
270
|
│ ├── renderer/
|
|
269
271
|
│ │ ├── renderer.ts # Content rendering
|
|
270
272
|
│ │ ├── utils.ts # HTML generation
|
|
271
|
-
│ │
|
|
273
|
+
│ │ ├── index.html # Print template
|
|
274
|
+
│ │ └── index.css # Print styles
|
|
272
275
|
│ └── preload/
|
|
273
|
-
│ └── preload.ts # Preload script
|
|
276
|
+
│ └── preload.ts # Preload script
|
|
274
277
|
├── demo/ # Demo application
|
|
275
278
|
├── test/ # Playwright E2E tests
|
|
276
279
|
└── dist/ # Compiled output
|
package/dist/index.d.ts
CHANGED
|
@@ -1,128 +1,175 @@
|
|
|
1
|
-
import { DrawerOptions
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
import { DrawerOptions } from '@devraghu/cashdrawer';
|
|
2
|
+
import { getAvailablePrinters } from '@devraghu/cashdrawer';
|
|
3
|
+
import { openCashDrawer } from '@devraghu/cashdrawer';
|
|
4
|
+
import { OpenCashDrawerResult } from '@devraghu/cashdrawer';
|
|
5
|
+
import { PrinterErrorCodes } from '@devraghu/cashdrawer';
|
|
6
|
+
import { PrinterInfo } from '@devraghu/cashdrawer';
|
|
7
|
+
import { PrinterStatus } from '@devraghu/cashdrawer';
|
|
8
|
+
import { PrinterType } from '@devraghu/cashdrawer';
|
|
9
|
+
import { WebContentsPrintOptions } from 'electron';
|
|
10
|
+
|
|
11
|
+
export { DrawerOptions }
|
|
12
|
+
|
|
13
|
+
export { OpenCashDrawerResult }
|
|
14
|
+
|
|
15
|
+
declare type PaperSize = '80mm' | '78mm' | '76mm' | '57mm' | '58mm' | '44mm';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Prints data to a printer or opens a preview window
|
|
19
|
+
* @param data - array of print data to print
|
|
20
|
+
* @param options - print configuration options
|
|
21
|
+
*/
|
|
22
|
+
declare function print_2(data: PrintData[], options: PrintOptions): Promise<PrintResult>;
|
|
23
|
+
|
|
24
|
+
/** Barcode content for printing */
|
|
25
|
+
export declare interface PrintBarCodeData extends PrintDataBase {
|
|
26
|
+
type: 'barCode';
|
|
27
|
+
value: string;
|
|
28
|
+
width?: string;
|
|
29
|
+
height?: string;
|
|
30
|
+
fontsize?: number;
|
|
31
|
+
displayValue?: boolean;
|
|
32
|
+
position?: PrintPosition;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Discriminated union of all print data types */
|
|
36
|
+
export declare type PrintData = PrintTextData | PrintBarCodeData | PrintQRCodeData | PrintImageData | PrintTableData;
|
|
37
|
+
|
|
38
|
+
/** Base properties shared by all print data types */
|
|
39
|
+
declare interface PrintDataBase {
|
|
40
|
+
style?: PrintDataStyle;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* CSS Style interface - a subset of CSSStyleDeclaration properties commonly used for printing
|
|
45
|
+
* Uses Record type for flexibility while maintaining type safety
|
|
46
|
+
*/
|
|
47
|
+
declare type PrintDataStyle = {
|
|
48
|
+
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export declare const printer: {
|
|
52
|
+
print: typeof print_2;
|
|
53
|
+
openCashDrawer: typeof openCashDrawer;
|
|
54
|
+
getPrinters: typeof getAvailablePrinters;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { PrinterErrorCodes }
|
|
58
|
+
|
|
59
|
+
export { PrinterInfo }
|
|
60
|
+
|
|
61
|
+
export { PrinterStatus }
|
|
62
|
+
|
|
63
|
+
export { PrinterType }
|
|
64
|
+
|
|
65
|
+
/** Image content for printing */
|
|
66
|
+
export declare interface PrintImageData extends PrintDataBase {
|
|
67
|
+
type: 'image';
|
|
68
|
+
path?: string;
|
|
69
|
+
url?: string;
|
|
70
|
+
width?: string;
|
|
71
|
+
height?: string;
|
|
72
|
+
position?: PrintPosition;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Print configuration options.
|
|
77
|
+
*
|
|
78
|
+
* Extends Electron's WebContentsPrintOptions with additional properties for receipt printing.
|
|
79
|
+
* Inherited options include: silent, printBackground, copies, header, footer, color,
|
|
80
|
+
* margins, landscape, scaleFactor, pagesPerSheet, collate, pageRanges, duplexMode.
|
|
81
|
+
*
|
|
82
|
+
* @see https://www.electronjs.org/docs/latest/api/web-contents#contentsprintoptions-callback
|
|
83
|
+
*/
|
|
84
|
+
export declare interface PrintOptions extends Omit<WebContentsPrintOptions, 'pageSize' | 'deviceName' | 'dpi'> {
|
|
85
|
+
/**
|
|
86
|
+
* CSS width of the print container element.
|
|
87
|
+
* @example "100%", "80mm", "300px"
|
|
88
|
+
*/
|
|
89
|
+
width?: string;
|
|
90
|
+
/**
|
|
91
|
+
* CSS margin of the print container element.
|
|
92
|
+
* @example "0", "10px", "5mm 10mm"
|
|
93
|
+
*/
|
|
94
|
+
margin?: string;
|
|
95
|
+
/**
|
|
96
|
+
* When true, opens a preview window instead of printing directly.
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
preview?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Name of the target printer. Required unless `silent` or `preview` is true.
|
|
102
|
+
* Use `getPrinters()` to get available printer names.
|
|
103
|
+
*/
|
|
104
|
+
printerName?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Timeout per print item in milliseconds.
|
|
107
|
+
* Total timeout is calculated as: `data.length * timeOutPerLine + 200ms`.
|
|
108
|
+
* Used to prevent hanging when printer is disconnected.
|
|
109
|
+
* @default 400
|
|
110
|
+
*/
|
|
111
|
+
timeOutPerLine?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Paper size for printing. Can be a preset size string or custom dimensions.
|
|
114
|
+
* @example "80mm", "58mm", { width: 300, height: 400 }
|
|
115
|
+
*/
|
|
116
|
+
pageSize?: PaperSize | SizeOptions;
|
|
117
|
+
/**
|
|
118
|
+
* Print resolution in dots per inch.
|
|
119
|
+
* @example { horizontal: 300, vertical: 300 }
|
|
120
|
+
*/
|
|
121
|
+
dpi?: {
|
|
122
|
+
horizontal: number;
|
|
123
|
+
vertical: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Path to a custom HTML template file for the print window.
|
|
127
|
+
* If not provided, uses the default built-in template.
|
|
128
|
+
*/
|
|
129
|
+
pathTemplate?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Alignment for barCode and qrCode */
|
|
133
|
+
export declare type PrintPosition = 'left' | 'center' | 'right';
|
|
134
|
+
|
|
135
|
+
/** QR code content for printing */
|
|
136
|
+
export declare interface PrintQRCodeData extends PrintDataBase {
|
|
137
|
+
type: 'qrCode';
|
|
138
|
+
value: string;
|
|
139
|
+
width?: string;
|
|
140
|
+
position?: PrintPosition;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare interface PrintResult {
|
|
144
|
+
complete: boolean;
|
|
145
|
+
data?: PrintData[];
|
|
146
|
+
options?: PrintOptions;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Table content for printing */
|
|
150
|
+
export declare interface PrintTableData extends PrintDataBase {
|
|
151
|
+
type: 'table';
|
|
152
|
+
tableHeader?: PrintTableField[] | string[];
|
|
153
|
+
tableBody?: PrintTableField[][] | string[][];
|
|
154
|
+
tableFooter?: PrintTableField[] | string[];
|
|
155
|
+
tableHeaderStyle?: PrintDataStyle;
|
|
156
|
+
tableBodyStyle?: PrintDataStyle;
|
|
157
|
+
tableFooterStyle?: PrintDataStyle;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export declare type PrintTableField = PrintImageData | PrintTextData;
|
|
161
|
+
|
|
162
|
+
/** Text content for printing */
|
|
163
|
+
export declare interface PrintTextData extends PrintDataBase {
|
|
164
|
+
type: 'text';
|
|
165
|
+
value: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export declare type PrintType = 'text' | 'barCode' | 'qrCode' | 'image' | 'table';
|
|
169
|
+
|
|
170
|
+
declare interface SizeOptions {
|
|
171
|
+
height: number;
|
|
172
|
+
width: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1 +1,157 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ipcMain as w, BrowserWindow as p } from "electron";
|
|
2
|
+
import { join as d } from "node:path";
|
|
3
|
+
import { getAvailablePrinters as g, openCashDrawer as P } from "@devraghu/cashdrawer";
|
|
4
|
+
import { PrinterErrorCodes as D, PrinterStatus as R, PrinterType as k } from "@devraghu/cashdrawer";
|
|
5
|
+
const l = /* @__PURE__ */ new Set(["44mm", "57mm", "58mm", "76mm", "78mm", "80mm"]), y = {
|
|
6
|
+
"44mm": 166,
|
|
7
|
+
"57mm": 215,
|
|
8
|
+
"58mm": 219,
|
|
9
|
+
"76mm": 287,
|
|
10
|
+
"78mm": 295,
|
|
11
|
+
"80mm": 302
|
|
12
|
+
}, b = {
|
|
13
|
+
"44mm": 44e3,
|
|
14
|
+
"57mm": 57e3,
|
|
15
|
+
"58mm": 58e3,
|
|
16
|
+
"76mm": 76e3,
|
|
17
|
+
"78mm": 78e3,
|
|
18
|
+
"80mm": 8e4
|
|
19
|
+
};
|
|
20
|
+
function h(e, t, n) {
|
|
21
|
+
return new Promise((r, i) => {
|
|
22
|
+
w.once(`${e}-reply`, (o, a) => {
|
|
23
|
+
a.status ? r(a) : i(a.error);
|
|
24
|
+
}), t.send(e, n);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function E(e) {
|
|
28
|
+
if (typeof e == "string") {
|
|
29
|
+
if (!l.has(e)) {
|
|
30
|
+
const r = [...l].join(", ");
|
|
31
|
+
throw new Error(`Invalid pageSize "${e}". Valid sizes are: ${r}`);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
width: y[e],
|
|
35
|
+
height: 1200
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (typeof e == "object") {
|
|
39
|
+
if (!e.width || !e.height)
|
|
40
|
+
throw new Error("height and width properties are required for options.pageSize");
|
|
41
|
+
return {
|
|
42
|
+
width: e.width,
|
|
43
|
+
height: e.height
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { width: 219, height: 1200 };
|
|
47
|
+
}
|
|
48
|
+
function s(e) {
|
|
49
|
+
return Math.ceil(e * 264.5833);
|
|
50
|
+
}
|
|
51
|
+
async function v(e, t) {
|
|
52
|
+
if (typeof t == "string") {
|
|
53
|
+
const i = await e.executeJavaScript("document.body.clientHeight");
|
|
54
|
+
return {
|
|
55
|
+
width: b[t] ?? 58e3,
|
|
56
|
+
height: s(i)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return typeof t == "object" ? {
|
|
60
|
+
width: s(t.width),
|
|
61
|
+
height: s(t.height)
|
|
62
|
+
} : { width: 58e3, height: 1e4 };
|
|
63
|
+
}
|
|
64
|
+
function I(e, t, n) {
|
|
65
|
+
return new Promise((r, i) => {
|
|
66
|
+
const o = setTimeout(() => {
|
|
67
|
+
i(new Error("[TimedOutError] Make sure your printer is connected"));
|
|
68
|
+
}, t), a = () => clearTimeout(o);
|
|
69
|
+
n.addEventListener("abort", a, { once: !0 }), e.then((c) => {
|
|
70
|
+
a(), r(c);
|
|
71
|
+
}).catch((c) => {
|
|
72
|
+
a(), i(c);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function x(e, t) {
|
|
77
|
+
if (!t.preview && !t.printerName && !t.silent)
|
|
78
|
+
throw new Error("A printer name is required, if you don't want to specify a printer name, set silent to true");
|
|
79
|
+
if (typeof t.copies == "number" && t.copies <= 0)
|
|
80
|
+
throw new Error(`Invalid copies value: ${t.copies}. Must be a positive integer`);
|
|
81
|
+
for (const [n, r] of e.entries()) {
|
|
82
|
+
if (r.type === "image" && !r.path && !r.url)
|
|
83
|
+
throw new Error(`Print item ${n}: image requires a path or url`);
|
|
84
|
+
if (r.style && typeof r.style != "object")
|
|
85
|
+
throw new Error(`Print item ${n}: style must be an object. Example: {style: {fontSize: 12}}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (process.type === "renderer")
|
|
89
|
+
throw new Error("electron-printer: this module must be used in the main process only");
|
|
90
|
+
function M(e, t) {
|
|
91
|
+
return {
|
|
92
|
+
silent: !!e.silent,
|
|
93
|
+
printBackground: !!e.printBackground,
|
|
94
|
+
deviceName: e.printerName,
|
|
95
|
+
copies: e.copies ?? 1,
|
|
96
|
+
pageSize: t,
|
|
97
|
+
header: e.header,
|
|
98
|
+
footer: e.footer,
|
|
99
|
+
color: e.color,
|
|
100
|
+
margins: e.margins,
|
|
101
|
+
landscape: e.landscape,
|
|
102
|
+
scaleFactor: e.scaleFactor,
|
|
103
|
+
pagesPerSheet: e.pagesPerSheet,
|
|
104
|
+
collate: e.collate,
|
|
105
|
+
pageRanges: e.pageRanges,
|
|
106
|
+
duplexMode: e.duplexMode,
|
|
107
|
+
dpi: e.dpi
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function C(e, t) {
|
|
111
|
+
for (const [n, r] of t.entries()) {
|
|
112
|
+
const i = await h("render-line", e.webContents, { printItem: r, itemIndex: n });
|
|
113
|
+
if (!i.status)
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Failed to render item ${n} (type: ${r.type}): ${i.error || "Unknown error"}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function H(e, t) {
|
|
120
|
+
return new Promise((n, r) => {
|
|
121
|
+
e.webContents.print(t, (i, o) => {
|
|
122
|
+
o ? r(new Error(o)) : n({ success: i }), e.close();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async function T(e, t) {
|
|
127
|
+
x(e, t);
|
|
128
|
+
const n = E(t.pageSize), r = new p({
|
|
129
|
+
...n,
|
|
130
|
+
show: !!t.preview,
|
|
131
|
+
webPreferences: {
|
|
132
|
+
nodeIntegration: !1,
|
|
133
|
+
contextIsolation: !0,
|
|
134
|
+
sandbox: !1,
|
|
135
|
+
preload: d(import.meta.dirname, "preload/preload.cjs")
|
|
136
|
+
}
|
|
137
|
+
}), i = t.pathTemplate || d(import.meta.dirname, "renderer/index.html");
|
|
138
|
+
try {
|
|
139
|
+
if (await r.loadFile(i), await h("body-init", r.webContents, t), await C(r, e), t.preview)
|
|
140
|
+
return { complete: !0, data: e, options: t };
|
|
141
|
+
const o = await v(r.webContents, t.pageSize), a = M(t, o), c = H(r, a), m = new AbortController(), u = (t.timeOutPerLine ?? 400) * e.length + 200, { success: f } = t.silent ? await c : await I(c, u, m.signal);
|
|
142
|
+
return m.abort(), { complete: f, options: t };
|
|
143
|
+
} catch (o) {
|
|
144
|
+
throw r.close(), o;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const A = {
|
|
148
|
+
print: T,
|
|
149
|
+
openCashDrawer: P,
|
|
150
|
+
getPrinters: g
|
|
151
|
+
};
|
|
152
|
+
export {
|
|
153
|
+
D as PrinterErrorCodes,
|
|
154
|
+
R as PrinterStatus,
|
|
155
|
+
k as PrinterType,
|
|
156
|
+
A as printer
|
|
157
|
+
};
|
package/dist/preload/preload.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";const t=require("electron"),a=require("node:fs"),d=require("node:path");function i(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const o=i(a),c=i(d),l={onBodyInit:e=>{t.ipcRenderer.on("body-init",(r,n)=>{e(n)})},onRenderLine:e=>{t.ipcRenderer.on("render-line",(r,n)=>{e(n)})},sendBodyInitReply:e=>{t.ipcRenderer.send("body-init-reply",e)},sendRenderLineReply:e=>{t.ipcRenderer.send("render-line-reply",e)},readFileAsBase64:e=>{try{const r=c.resolve(e),n=process.cwd();return!r.startsWith(n+c.sep)&&r!==n?{success:!1,error:"Access denied: Path outside allowed directory"}:o.existsSync(r)?{success:!0,data:o.readFileSync(r).toString("base64")}:{success:!1,error:"File not found"}}catch(r){return{success:!1,error:r.message}}},getFileExtension:e=>c.extname(e).slice(1)};t.contextBridge.exposeInMainWorld("electronAPI",l);
|