@connexup/react-native-xprinter 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 +20 -0
- package/NativeXPrinter.podspec +23 -0
- package/README.md +24 -0
- package/android/build.gradle +73 -0
- package/android/gradle.properties +5 -0
- package/android/libs/printer-lib-3.4.7.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/connexup/xprinter/Errors.kt +11 -0
- package/android/src/main/java/com/connexup/xprinter/Util.kt +106 -0
- package/android/src/main/java/com/connexup/xprinter/XPrinterPackage.kt +77 -0
- package/android/src/main/java/com/connexup/xprinter/esc/Convert.kt +211 -0
- package/android/src/main/java/com/connexup/xprinter/esc/XPrinterESCModule.kt +1995 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Convert.kt +46 -0
- package/android/src/main/java/com/connexup/xprinter/printer/DeviceConnection.kt +14 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Printers.kt +153 -0
- package/android/src/main/java/com/connexup/xprinter/printer/XPrinterPrinterModule.kt +295 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/Convert.kt +151 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/XPrinterTSPLModule.kt +1408 -0
- package/android/src/main/java/com/connexup/xprinter/utils/XPrinterUtilsModule.kt +54 -0
- package/ios/ESC/ESCConvert.swift +283 -0
- package/ios/ESC/Models/RCTESCPrintBarCodeRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintBitmapRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintPDF417Request.swift +27 -0
- package/ios/ESC/Models/RCTESCPrintQRCodeRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableBarcode.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintTableRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableRow.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTextRequest.swift +21 -0
- package/ios/ESC/Models/RCTESCPrintTextSizeRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSelectBitmapModelRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSetNetAllRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetPrintAreaRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetTextStyleRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCWifiConfigRequest.swift +23 -0
- package/ios/ESC/NativeXPrinterESC.swift +1339 -0
- package/ios/ESC/RCTNativeXPrinterESC.h +10 -0
- package/ios/ESC/RCTNativeXPrinterESC.mm +541 -0
- package/ios/Errors.swift +11 -0
- package/ios/NativeErrorInfo.swift +21 -0
- package/ios/Printer/Connecter.swift +214 -0
- package/ios/Printer/Models/RCTDeviceConnectStatusChangeEvent.swift +19 -0
- package/ios/Printer/Models/RCTNetDevice.swift +21 -0
- package/ios/Printer/Models/RCTUSBDevice.swift +17 -0
- package/ios/Printer/Models/RCTUpdateUdpNetConfigRequest.swift +21 -0
- package/ios/Printer/NativeXPrinterPrinter.swift +209 -0
- package/ios/Printer/Printers.swift +59 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.h +12 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.mm +123 -0
- package/ios/PrinterSDK/Headers/CPCLCommand.h +324 -0
- package/ios/PrinterSDK/Headers/KDS_Log.h +47 -0
- package/ios/PrinterSDK/Headers/LabelDocument.h +32 -0
- package/ios/PrinterSDK/Headers/LabelImageTranster.h +19 -0
- package/ios/PrinterSDK/Headers/POSBLEManager.h +164 -0
- package/ios/PrinterSDK/Headers/POSCommand.h +760 -0
- package/ios/PrinterSDK/Headers/POSImageTranster.h +34 -0
- package/ios/PrinterSDK/Headers/POSPrinter.h +47 -0
- package/ios/PrinterSDK/Headers/POSPrinterSDK.h +13 -0
- package/ios/PrinterSDK/Headers/POSWIFIManager.h +162 -0
- package/ios/PrinterSDK/Headers/PTable.h +50 -0
- package/ios/PrinterSDK/Headers/PrinterProfile.h +28 -0
- package/ios/PrinterSDK/Headers/TSCBLEManager.h +142 -0
- package/ios/PrinterSDK/Headers/TSCCommand.h +701 -0
- package/ios/PrinterSDK/Headers/TSCPrinterSDK.h +15 -0
- package/ios/PrinterSDK/Headers/TSCWIFIManager.h +99 -0
- package/ios/PrinterSDK/Headers/WIFIConnecter.h +131 -0
- package/ios/PrinterSDK/Headers/ZPLCommand.h +372 -0
- package/ios/PrinterSDK/libPrinterSDK.a +0 -0
- package/ios/TSPL/Models/RCTTSPLBarRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLBarcodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLBitmapCompressionRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBitmapRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBoxRequest.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLEraseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLPDFBase64Request.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLPutBMPRequest.swift +17 -0
- package/ios/TSPL/Models/RCTTSPLQRCodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLReverseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLTextRequest.swift +25 -0
- package/ios/TSPL/NativeXPrinterTSPL.swift +831 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.h +10 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.mm +445 -0
- package/ios/TSPL/TSPLConvert.swift +140 -0
- package/ios/Utils/Models/RCTCheckIsPureWhiteImageRequest.swift +16 -0
- package/ios/Utils/NativeXPrinterUtils.swift +17 -0
- package/ios/Utils/RCTNativeXPrinterUtils.h +10 -0
- package/ios/Utils/RCTNativeXPrinterUtils.mm +38 -0
- package/ios/Utils.swift +126 -0
- package/lib/module/esc/NativeXPrinterESC.js +218 -0
- package/lib/module/esc/NativeXPrinterESC.js.map +1 -0
- package/lib/module/esc/index.js +324 -0
- package/lib/module/esc/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/printer/NativeXPrinterPrinter.js +30 -0
- package/lib/module/printer/NativeXPrinterPrinter.js.map +1 -0
- package/lib/module/printer/index.js +110 -0
- package/lib/module/printer/index.js.map +1 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js +143 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js.map +1 -0
- package/lib/module/tspl/index.js +347 -0
- package/lib/module/tspl/index.js.map +1 -0
- package/lib/module/type.js +12 -0
- package/lib/module/type.js.map +1 -0
- package/lib/module/util.js +4 -0
- package/lib/module/util.js.map +1 -0
- package/lib/module/utils/NativeXPrinterUtils.js +5 -0
- package/lib/module/utils/NativeXPrinterUtils.js.map +1 -0
- package/lib/module/utils/index.js +17 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts +343 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts.map +1 -0
- package/lib/typescript/src/esc/index.d.ts +122 -0
- package/lib/typescript/src/esc/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts +61 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts.map +1 -0
- package/lib/typescript/src/printer/index.d.ts +32 -0
- package/lib/typescript/src/printer/index.d.ts.map +1 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts +261 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts.map +1 -0
- package/lib/typescript/src/tspl/index.d.ts +128 -0
- package/lib/typescript/src/tspl/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +9 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/lib/typescript/src/util.d.ts +2 -0
- package/lib/typescript/src/util.d.ts.map +1 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts +10 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +9 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/esc/NativeXPrinterESC.ts +516 -0
- package/src/esc/index.ts +489 -0
- package/src/index.ts +5 -0
- package/src/printer/NativeXPrinterPrinter.ts +84 -0
- package/src/printer/index.ts +160 -0
- package/src/tspl/NativeXPrinterTSPL.ts +388 -0
- package/src/tspl/index.ts +535 -0
- package/src/type.ts +11 -0
- package/src/util.ts +1 -0
- package/src/utils/NativeXPrinterUtils.ts +14 -0
- package/src/utils/index.ts +27 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BarcodeRequest,
|
|
3
|
+
type BarRequest,
|
|
4
|
+
BitmapAlgorithmType,
|
|
5
|
+
type BitmapCompressionRequest,
|
|
6
|
+
type BitmapRequest,
|
|
7
|
+
type BoxRequest,
|
|
8
|
+
DEFAULT_BITMAP_ALGORITHM_TYPE,
|
|
9
|
+
DEFAULT_EC_LEVEL,
|
|
10
|
+
DEFAULT_NARROW,
|
|
11
|
+
DEFAULT_PRINT_STATUS_TIMEOUT,
|
|
12
|
+
DEFAULT_QR_MASK,
|
|
13
|
+
DEFAULT_QR_MODE,
|
|
14
|
+
DEFAULT_QR_MODEL,
|
|
15
|
+
DEFAULT_READABLE,
|
|
16
|
+
DEFAULT_ROTATION,
|
|
17
|
+
DEFAULT_WIDE,
|
|
18
|
+
Direction,
|
|
19
|
+
type EraseRequest,
|
|
20
|
+
NativeXPrinterTSPL,
|
|
21
|
+
type PDFBase64Request,
|
|
22
|
+
PrinterStatus,
|
|
23
|
+
type PutBMPRequest,
|
|
24
|
+
type QRCodeRequest,
|
|
25
|
+
type ReverseRequest,
|
|
26
|
+
type Spec,
|
|
27
|
+
type TextRequest,
|
|
28
|
+
} from './NativeXPrinterTSPL';
|
|
29
|
+
import { XPrinterPCLExecutor } from '../type';
|
|
30
|
+
|
|
31
|
+
export class XPrinterTSPL
|
|
32
|
+
implements Omit<Spec, 'getConstants' | 'printerStatus'>
|
|
33
|
+
{
|
|
34
|
+
private readonly module: Spec;
|
|
35
|
+
|
|
36
|
+
constructor(module: Spec) {
|
|
37
|
+
this.module = module;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
sizeInch = async (connectInfo: string, width: number, height: number) => {
|
|
41
|
+
return this.module.sizeInch(connectInfo, width, height);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
sizeMm = async (connectInfo: string, width: number, height: number) => {
|
|
45
|
+
return this.module.sizeMm(connectInfo, width, height);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
gapInch = async (connectInfo: string, m: number, n: number) => {
|
|
49
|
+
return this.module.gapInch(connectInfo, m, n);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
gapMm = async (connectInfo: string, m: number, n: number) => {
|
|
53
|
+
return this.module.gapMm(connectInfo, m, n);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
speed = async (connectInfo: string, speed: number) => {
|
|
57
|
+
return this.module.speed(connectInfo, speed);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
density = async (connectInfo: string, density: number) => {
|
|
61
|
+
return this.module.density(connectInfo, density);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
direction = async (
|
|
65
|
+
connectInfo: string,
|
|
66
|
+
direction: Direction,
|
|
67
|
+
isMirror: boolean
|
|
68
|
+
) => {
|
|
69
|
+
return this.module.direction(connectInfo, direction, isMirror);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
cls = async (connectInfo: string) => {
|
|
73
|
+
return this.module.cls(connectInfo);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
box = async (connectInfo: string, payload: BoxRequest) => {
|
|
77
|
+
return this.module.box(connectInfo, payload);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
bar = async (connectInfo: string, payload: BarRequest) => {
|
|
81
|
+
return this.module.bar(connectInfo, payload);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
barcode = async (
|
|
85
|
+
connectInfo: string,
|
|
86
|
+
payload: Omit<
|
|
87
|
+
BarcodeRequest,
|
|
88
|
+
'readable' | 'rotation' | 'narrow' | 'wide'
|
|
89
|
+
> & {
|
|
90
|
+
readable?: BarcodeRequest['readable'];
|
|
91
|
+
rotation?: BarcodeRequest['rotation'];
|
|
92
|
+
narrow?: BarcodeRequest['narrow'];
|
|
93
|
+
wide?: BarcodeRequest['wide'];
|
|
94
|
+
}
|
|
95
|
+
) => {
|
|
96
|
+
return this.module.barcode(connectInfo, {
|
|
97
|
+
...payload,
|
|
98
|
+
readable: payload.readable ?? DEFAULT_READABLE,
|
|
99
|
+
rotation: payload.rotation ?? DEFAULT_ROTATION,
|
|
100
|
+
narrow: payload.narrow ?? DEFAULT_NARROW,
|
|
101
|
+
wide: payload.wide ?? DEFAULT_WIDE,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
text = async (
|
|
106
|
+
connectInfo: string,
|
|
107
|
+
payload: Omit<TextRequest, 'rotation'> & {
|
|
108
|
+
rotation?: BarcodeRequest['rotation'];
|
|
109
|
+
}
|
|
110
|
+
) => {
|
|
111
|
+
return this.module.text(connectInfo, {
|
|
112
|
+
...payload,
|
|
113
|
+
rotation: payload.rotation ?? DEFAULT_ROTATION,
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
offsetInch = async (connectInfo: string, offset: number) => {
|
|
118
|
+
return await this.module.offsetInch(connectInfo, offset);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
offsetMm = async (connectInfo: string, offset: number) => {
|
|
122
|
+
return this.module.offsetMm(connectInfo, offset);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
reference = async (connectInfo: string, x: number, y: number) => {
|
|
126
|
+
return this.module.reference(connectInfo, x, y);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
qrcode = async (
|
|
130
|
+
connectInfo: string,
|
|
131
|
+
payload: Omit<
|
|
132
|
+
QRCodeRequest,
|
|
133
|
+
'ecLevel' | 'mode' | 'rotation' | 'model' | 'mask'
|
|
134
|
+
> & {
|
|
135
|
+
ecLevel?: QRCodeRequest['ecLevel'];
|
|
136
|
+
mode?: QRCodeRequest['mode'];
|
|
137
|
+
rotation?: QRCodeRequest['rotation'];
|
|
138
|
+
model?: QRCodeRequest['model'];
|
|
139
|
+
mask?: QRCodeRequest['mask'];
|
|
140
|
+
}
|
|
141
|
+
) => {
|
|
142
|
+
return this.module.qrcode(connectInfo, {
|
|
143
|
+
...payload,
|
|
144
|
+
ecLevel: payload.ecLevel ?? DEFAULT_EC_LEVEL,
|
|
145
|
+
mode: payload.mode ?? DEFAULT_QR_MODE,
|
|
146
|
+
rotation: payload.rotation ?? DEFAULT_ROTATION,
|
|
147
|
+
model: payload.model ?? DEFAULT_QR_MODEL,
|
|
148
|
+
mask: payload.mask ?? DEFAULT_QR_MASK,
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
print = async (connectInfo: string, count: number) => {
|
|
153
|
+
return this.module.print(connectInfo, count);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
printWithResponse = async (
|
|
157
|
+
connectInfo: string,
|
|
158
|
+
count: number,
|
|
159
|
+
timeout: number
|
|
160
|
+
) => {
|
|
161
|
+
return this.module.printWithResponse(connectInfo, count, timeout);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
feed = async (connectInfo: string, length: number) => {
|
|
165
|
+
return this.module.feed(connectInfo, length);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
backFeed = async (connectInfo: string, length: number) => {
|
|
169
|
+
return this.module.backFeed(connectInfo, length);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
formFeed = async (connectInfo: string) => {
|
|
173
|
+
return this.module.formFeed(connectInfo);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
limitFeedMm = async (connectInfo: string, length: number) => {
|
|
177
|
+
return this.module.limitFeedMm(connectInfo, length);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
limitFeedInch = async (connectInfo: string, length: number) => {
|
|
181
|
+
return this.module.limitFeedInch(connectInfo, length);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
home = async (connectInfo: string) => {
|
|
185
|
+
return this.module.home(connectInfo);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
codePage = async (connectInfo: string, page: string) => {
|
|
189
|
+
return this.module.codePage(connectInfo, page);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
sound = async (connectInfo: string, level: number, interval: number) => {
|
|
193
|
+
return this.module.sound(connectInfo, level, interval);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
bitmap = async (connectInfo: string, payload: BitmapRequest) => {
|
|
197
|
+
if (!payload.algorithmType) {
|
|
198
|
+
payload.algorithmType = DEFAULT_BITMAP_ALGORITHM_TYPE;
|
|
199
|
+
}
|
|
200
|
+
return this.module.bitmap(connectInfo, payload);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
bitmapCompression = async (
|
|
204
|
+
connectInfo: string,
|
|
205
|
+
payload: BitmapCompressionRequest
|
|
206
|
+
) => {
|
|
207
|
+
if (!payload.algorithmType) {
|
|
208
|
+
payload.algorithmType = DEFAULT_BITMAP_ALGORITHM_TYPE;
|
|
209
|
+
}
|
|
210
|
+
return this.module.bitmapCompression(connectInfo, payload);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
pdfBase64 = async (
|
|
214
|
+
connectInfo: string,
|
|
215
|
+
payload: Omit<PDFBase64Request, 'algorithmType'> & {
|
|
216
|
+
algorithmType?: PDFBase64Request['algorithmType'];
|
|
217
|
+
}
|
|
218
|
+
) => {
|
|
219
|
+
return this.module.pdfBase64(connectInfo, {
|
|
220
|
+
...payload,
|
|
221
|
+
algorithmType: payload.algorithmType ?? BitmapAlgorithmType.THRESHOLD,
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
erase = async (connectInfo: string, payload: EraseRequest) => {
|
|
226
|
+
return this.module.erase(connectInfo, payload);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
reverse = async (connectInfo: string, payload: ReverseRequest) => {
|
|
230
|
+
return this.module.reverse(connectInfo, payload);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
cut = async (connectInfo: string) => {
|
|
234
|
+
return this.module.cut(connectInfo);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
setPeel = async (connectInfo: string, isOpen: boolean) => {
|
|
238
|
+
return this.module.setPeel(connectInfo, isOpen);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
setTear = async (connectInfo: string, isOpen: boolean) => {
|
|
242
|
+
return this.module.setTear(connectInfo, isOpen);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
setCutter = async (connectInfo: string, pieces: number) => {
|
|
246
|
+
return this.module.setCutter(connectInfo, pieces);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
putBMP = async (connectInfo: string, payload: PutBMPRequest) => {
|
|
250
|
+
return this.module.putBMP(connectInfo, payload);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
blineInch = async (connectInfo: string, m: number, n: number) => {
|
|
254
|
+
return this.module.blineInch(connectInfo, m, n);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
blineMm = async (connectInfo: string, m: number, n: number) => {
|
|
258
|
+
return this.module.blineMm(connectInfo, m, n);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
setPrinterModel = async (connectInfo: string, model: string) => {
|
|
262
|
+
return this.module.setPrinterModel(connectInfo, model);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
getPrinterModel = async (connectInfo: string) => {
|
|
266
|
+
return this.module.getPrinterModel(connectInfo);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
printerStatus = async (
|
|
270
|
+
connectInfo: string,
|
|
271
|
+
timeout: number = DEFAULT_PRINT_STATUS_TIMEOUT
|
|
272
|
+
) => {
|
|
273
|
+
const { status } = await this.module.printerStatus(connectInfo, timeout);
|
|
274
|
+
let _status: PrinterStatus;
|
|
275
|
+
switch (status) {
|
|
276
|
+
case 0x00:
|
|
277
|
+
_status = PrinterStatus.PRINTER_STATUS_NORMAL;
|
|
278
|
+
break;
|
|
279
|
+
case 0x01:
|
|
280
|
+
_status = PrinterStatus.PRINTER_STATUS_COVER_OPEN;
|
|
281
|
+
break;
|
|
282
|
+
case 0x02:
|
|
283
|
+
_status = PrinterStatus.PRINTER_STATUS_PAPER_JAM;
|
|
284
|
+
break;
|
|
285
|
+
case 0x03:
|
|
286
|
+
_status = PrinterStatus.PRINTER_STATUS_PAPER_JAM_AND_COVER_OPEN;
|
|
287
|
+
break;
|
|
288
|
+
case 0x04:
|
|
289
|
+
_status = PrinterStatus.PRINTER_STATUS_OUT_OF_PAPER;
|
|
290
|
+
break;
|
|
291
|
+
case 0x05:
|
|
292
|
+
_status = PrinterStatus.PRINTER_STATUS_OUT_OF_PAPER_AND_COVER_OPEN;
|
|
293
|
+
break;
|
|
294
|
+
case 0x08:
|
|
295
|
+
_status = PrinterStatus.PRINTER_STATUS_NO_RIBBON;
|
|
296
|
+
break;
|
|
297
|
+
case 0x09:
|
|
298
|
+
_status = PrinterStatus.PRINTER_STATUS_NO_RIBBON_AND_COVER_OPEN;
|
|
299
|
+
break;
|
|
300
|
+
case 0x0a:
|
|
301
|
+
_status = PrinterStatus.PRINTER_STATUS_NO_RIBBON_AND_PAPER_JAM;
|
|
302
|
+
break;
|
|
303
|
+
case 0x0b:
|
|
304
|
+
_status =
|
|
305
|
+
PrinterStatus.PRINTER_STATUS_NO_RIBBON_AND_PAPER_JAM_AND_COVER_OPEN;
|
|
306
|
+
break;
|
|
307
|
+
case 0x0c:
|
|
308
|
+
_status = PrinterStatus.PRINTER_STATUS_NO_RIBBON_AND_OUT_OF_PAPER;
|
|
309
|
+
break;
|
|
310
|
+
case 0x0d:
|
|
311
|
+
_status =
|
|
312
|
+
PrinterStatus.PRINTER_STATUS_NO_RIBBON_AND_OUT_OF_PAPER_AND_COVER_OPEN;
|
|
313
|
+
break;
|
|
314
|
+
case 0x10:
|
|
315
|
+
_status = PrinterStatus.PRINTER_STATUS_PAUSED;
|
|
316
|
+
break;
|
|
317
|
+
case 0x20:
|
|
318
|
+
_status = PrinterStatus.PRINTER_STATUS_PRINTING;
|
|
319
|
+
break;
|
|
320
|
+
case 0x80:
|
|
321
|
+
_status = PrinterStatus.PRINTER_STATUS_OTHER_ERROR;
|
|
322
|
+
break;
|
|
323
|
+
case -1:
|
|
324
|
+
_status = PrinterStatus.PRINTER_STATUS_TIMOUT_OR_DATA_ERROR;
|
|
325
|
+
break;
|
|
326
|
+
default:
|
|
327
|
+
_status = PrinterStatus.PRINTER_STATUS_UNKNOWN;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
debugCode: status,
|
|
332
|
+
status: _status,
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export const xPrinterTSPL = new XPrinterTSPL(NativeXPrinterTSPL);
|
|
338
|
+
|
|
339
|
+
export class XPrinterTSPLExecutor extends XPrinterPCLExecutor {
|
|
340
|
+
sizeInch = async (width: number, height: number) => {
|
|
341
|
+
return xPrinterTSPL.sizeInch(this.connectInfo, width, height);
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
sizeMm = async (width: number, height: number) => {
|
|
345
|
+
return xPrinterTSPL.sizeMm(this.connectInfo, width, height);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
gapInch = async (m: number, n: number) => {
|
|
349
|
+
return xPrinterTSPL.gapInch(this.connectInfo, m, n);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
gapMm = async (m: number, n: number) => {
|
|
353
|
+
return xPrinterTSPL.gapMm(this.connectInfo, m, n);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
speed = async (speed: number) => {
|
|
357
|
+
return xPrinterTSPL.speed(this.connectInfo, speed);
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
density = async (density: number) => {
|
|
361
|
+
return xPrinterTSPL.density(this.connectInfo, density);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
direction = async (direction: Direction, isMirror: boolean) => {
|
|
365
|
+
return xPrinterTSPL.direction(this.connectInfo, direction, isMirror);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
cls = async () => {
|
|
369
|
+
return xPrinterTSPL.cls(this.connectInfo);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
box = async (payload: BoxRequest) => {
|
|
373
|
+
return xPrinterTSPL.box(this.connectInfo, payload);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
bar = async (payload: BarRequest) => {
|
|
377
|
+
return xPrinterTSPL.bar(this.connectInfo, payload);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
barcode = async (
|
|
381
|
+
payload: Omit<
|
|
382
|
+
BarcodeRequest,
|
|
383
|
+
'readable' | 'rotation' | 'narrow' | 'wide'
|
|
384
|
+
> & {
|
|
385
|
+
readable?: BarcodeRequest['readable'];
|
|
386
|
+
rotation?: BarcodeRequest['rotation'];
|
|
387
|
+
narrow?: BarcodeRequest['narrow'];
|
|
388
|
+
wide?: BarcodeRequest['wide'];
|
|
389
|
+
}
|
|
390
|
+
) => {
|
|
391
|
+
return xPrinterTSPL.barcode(this.connectInfo, payload);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
text = async (
|
|
395
|
+
payload: Omit<TextRequest, 'rotation'> & {
|
|
396
|
+
rotation?: BarcodeRequest['rotation'];
|
|
397
|
+
}
|
|
398
|
+
) => {
|
|
399
|
+
return xPrinterTSPL.text(this.connectInfo, payload);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
offsetInch = async (offset: number) => {
|
|
403
|
+
return await xPrinterTSPL.offsetInch(this.connectInfo, offset);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
offsetMm = async (offset: number) => {
|
|
407
|
+
return xPrinterTSPL.offsetMm(this.connectInfo, offset);
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
reference = async (x: number, y: number) => {
|
|
411
|
+
return xPrinterTSPL.reference(this.connectInfo, x, y);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
qrcode = async (
|
|
415
|
+
payload: Omit<
|
|
416
|
+
QRCodeRequest,
|
|
417
|
+
'ecLevel' | 'mode' | 'rotation' | 'model' | 'mask'
|
|
418
|
+
> & {
|
|
419
|
+
ecLevel?: QRCodeRequest['ecLevel'];
|
|
420
|
+
mode?: QRCodeRequest['mode'];
|
|
421
|
+
rotation?: QRCodeRequest['rotation'];
|
|
422
|
+
model?: QRCodeRequest['model'];
|
|
423
|
+
mask?: QRCodeRequest['mask'];
|
|
424
|
+
}
|
|
425
|
+
) => {
|
|
426
|
+
return xPrinterTSPL.qrcode(this.connectInfo, payload);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
print = async (count: number) => {
|
|
430
|
+
return xPrinterTSPL.print(this.connectInfo, count);
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
printWithResponse = async (count: number, timeout: number) => {
|
|
434
|
+
return xPrinterTSPL.printWithResponse(this.connectInfo, count, timeout);
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
feed = async (length: number) => {
|
|
438
|
+
return xPrinterTSPL.feed(this.connectInfo, length);
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
backFeed = async (length: number) => {
|
|
442
|
+
return xPrinterTSPL.backFeed(this.connectInfo, length);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
formFeed = async () => {
|
|
446
|
+
return xPrinterTSPL.formFeed(this.connectInfo);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
limitFeedMm = async (length: number) => {
|
|
450
|
+
return xPrinterTSPL.limitFeedMm(this.connectInfo, length);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
limitFeedInch = async (length: number) => {
|
|
454
|
+
return xPrinterTSPL.limitFeedInch(this.connectInfo, length);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
home = async () => {
|
|
458
|
+
return xPrinterTSPL.home(this.connectInfo);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
codePage = async (page: string) => {
|
|
462
|
+
return xPrinterTSPL.codePage(this.connectInfo, page);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
sound = async (level: number, interval: number) => {
|
|
466
|
+
return xPrinterTSPL.sound(this.connectInfo, level, interval);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
bitmap = async (payload: BitmapRequest) => {
|
|
470
|
+
return xPrinterTSPL.bitmap(this.connectInfo, payload);
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
bitmapCompression = async (payload: BitmapCompressionRequest) => {
|
|
474
|
+
return xPrinterTSPL.bitmapCompression(this.connectInfo, payload);
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
pdfBase64 = async (
|
|
478
|
+
payload: Omit<PDFBase64Request, 'algorithmType'> & {
|
|
479
|
+
algorithmType?: PDFBase64Request['algorithmType'];
|
|
480
|
+
}
|
|
481
|
+
) => {
|
|
482
|
+
return xPrinterTSPL.pdfBase64(this.connectInfo, {
|
|
483
|
+
...payload,
|
|
484
|
+
algorithmType: payload.algorithmType ?? BitmapAlgorithmType.THRESHOLD,
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
erase = async (payload: EraseRequest) => {
|
|
489
|
+
return xPrinterTSPL.erase(this.connectInfo, payload);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
reverse = async (payload: ReverseRequest) => {
|
|
493
|
+
return xPrinterTSPL.reverse(this.connectInfo, payload);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
cut = async () => {
|
|
497
|
+
return xPrinterTSPL.cut(this.connectInfo);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
setPeel = async (isOpen: boolean) => {
|
|
501
|
+
return xPrinterTSPL.setPeel(this.connectInfo, isOpen);
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
setTear = async (isOpen: boolean) => {
|
|
505
|
+
return xPrinterTSPL.setTear(this.connectInfo, isOpen);
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
setCutter = async (pieces: number) => {
|
|
509
|
+
return xPrinterTSPL.setCutter(this.connectInfo, pieces);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
putBMP = async (payload: PutBMPRequest) => {
|
|
513
|
+
return xPrinterTSPL.putBMP(this.connectInfo, payload);
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
blineInch = async (m: number, n: number) => {
|
|
517
|
+
return xPrinterTSPL.blineInch(this.connectInfo, m, n);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
blineMm = async (m: number, n: number) => {
|
|
521
|
+
return xPrinterTSPL.blineMm(this.connectInfo, m, n);
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
setPrinterModel = async (model: string) => {
|
|
525
|
+
return xPrinterTSPL.setPrinterModel(this.connectInfo, model);
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
getPrinterModel = async () => {
|
|
529
|
+
return xPrinterTSPL.getPrinterModel(this.connectInfo);
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
printerStatus = async (timeout?: number) => {
|
|
533
|
+
return xPrinterTSPL.printerStatus(this.connectInfo, timeout);
|
|
534
|
+
};
|
|
535
|
+
}
|
package/src/type.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const PARAMS_ERROR = 'PARAMS_ERROR';
|
|
2
|
+
export const COMMON_ERROR = 'COMMON_ERROR';
|
|
3
|
+
export const PRINTER_NOT_FOUND_ERROR = 'PRINTER_NOT_FOUND_ERROR';
|
|
4
|
+
export const NOT_YET_IMPLEMENTED_ERROR = 'NOT_YET_IMPLEMENTED_ERROR';
|
|
5
|
+
|
|
6
|
+
export class XPrinterPCLExecutor {
|
|
7
|
+
readonly connectInfo: string;
|
|
8
|
+
constructor(connectInfo: string) {
|
|
9
|
+
this.connectInfo = connectInfo;
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/util.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const replaceImagePath = (path: string) => path.replace('file://', '');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
isPureWhiteImage: (payload: CheckIsPureWhiteImageRequest) => Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const NativeXPrinterUtils = TurboModuleRegistry.getEnforcing<Spec>(
|
|
8
|
+
'NativeXPrinterUtils'
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export interface CheckIsPureWhiteImageRequest {
|
|
12
|
+
bitmapPath: string | null;
|
|
13
|
+
bitmapContent: string | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CheckIsPureWhiteImageRequest,
|
|
3
|
+
NativeXPrinterUtils,
|
|
4
|
+
type Spec,
|
|
5
|
+
} from './NativeXPrinterUtils';
|
|
6
|
+
import { replaceImagePath } from '../util';
|
|
7
|
+
|
|
8
|
+
class XPrinterUtils implements Omit<Spec, 'getConstants'> {
|
|
9
|
+
private readonly module: Spec;
|
|
10
|
+
|
|
11
|
+
constructor(module: Spec) {
|
|
12
|
+
this.module = module;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async isPureWhiteImage(
|
|
16
|
+
payload: CheckIsPureWhiteImageRequest
|
|
17
|
+
): Promise<boolean> {
|
|
18
|
+
return await this.module.isPureWhiteImage({
|
|
19
|
+
...payload,
|
|
20
|
+
bitmapPath: payload.bitmapPath
|
|
21
|
+
? replaceImagePath(payload.bitmapPath)
|
|
22
|
+
: null,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const xPrinterUtils = new XPrinterUtils(NativeXPrinterUtils);
|