@sincpro/printer-expo 0.1.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/README.md +917 -0
- package/android/build.gradle +52 -0
- package/android/libs/BixolonLabelPrinterLibrary_V2.0.9.jar +0 -0
- package/android/libs/jniLibs/arm64-v8a/libbxl_common.so +0 -0
- package/android/libs/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
- package/android/libs/jniLibs/x86/libbxl_common.so +0 -0
- package/android/libs/jniLibs/x86_64/libbxl_common.so +0 -0
- package/android/libs/libcommon_V1.4.0.jar +0 -0
- package/android/libs/pdf/Bixolon_pdf.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/sincpro/ExpoBixolonModule.kt +271 -0
- package/android/src/main/java/expo/sincpro/bixolon/BixolonQRPrinter.kt +423 -0
- package/android/src/main/java/expo/sincpro/managers/BluetoothManager.kt +139 -0
- package/android/src/main/java/expo/sincpro/managers/ConnectionManager.kt +124 -0
- package/android/src/main/java/expo/sincpro/managers/PermissionManager.kt +122 -0
- package/android/src/main/java/expo/sincpro/managers/PrinterManager.kt +396 -0
- package/android/src/main/jniLibs/arm64-v8a/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/x86/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/x86_64/libbxl_common.so +0 -0
- package/build/BixolonPrinter.d.ts +4 -0
- package/build/BixolonPrinter.d.ts.map +1 -0
- package/build/BixolonPrinter.js +12 -0
- package/build/BixolonPrinter.js.map +1 -0
- package/build/ExpoBixolon.types.d.ts +45 -0
- package/build/ExpoBixolon.types.d.ts.map +1 -0
- package/build/ExpoBixolon.types.js +2 -0
- package/build/ExpoBixolon.types.js.map +1 -0
- package/build/ExpoBixolonModule.d.ts +24 -0
- package/build/ExpoBixolonModule.d.ts.map +1 -0
- package/build/ExpoBixolonModule.js +3 -0
- package/build/ExpoBixolonModule.js.map +1 -0
- package/build/QrCodePrinter.d.ts +45 -0
- package/build/QrCodePrinter.d.ts.map +1 -0
- package/build/QrCodePrinter.js +118 -0
- package/build/QrCodePrinter.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoBixolon.podspec +29 -0
- package/ios/ExpoBixolonModule.swift +33 -0
- package/ios/ExpoBixolonView.swift +36 -0
- package/package.json +63 -0
- package/src/BixolonPrinter.ts +16 -0
- package/src/ExpoBixolon.types.ts +60 -0
- package/src/ExpoBixolonModule.ts +38 -0
- package/src/QrCodePrinter.ts +201 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import ExpoBixolonModule from './ExpoBixolonModule';
|
|
2
|
+
|
|
3
|
+
export interface QRCodeOptions {
|
|
4
|
+
data: string;
|
|
5
|
+
size?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface QRCodeConstants {
|
|
9
|
+
QR_CODE_MODEL1: number;
|
|
10
|
+
QR_CODE_MODEL2: number;
|
|
11
|
+
|
|
12
|
+
ECC_LEVEL_7: number;
|
|
13
|
+
ECC_LEVEL_15: number;
|
|
14
|
+
ECC_LEVEL_25: number;
|
|
15
|
+
ECC_LEVEL_30: number;
|
|
16
|
+
|
|
17
|
+
ROTATION_NONE: number;
|
|
18
|
+
ROTATION_90_DEGREES: number;
|
|
19
|
+
ROTATION_180_DEGREES: number;
|
|
20
|
+
ROTATION_270_DEGREES: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class QrCodePrinter {
|
|
24
|
+
private static instance: QrCodePrinter;
|
|
25
|
+
private isInitialized = false;
|
|
26
|
+
|
|
27
|
+
private constructor() {}
|
|
28
|
+
|
|
29
|
+
public static getInstance(): QrCodePrinter {
|
|
30
|
+
if (!QrCodePrinter.instance) {
|
|
31
|
+
QrCodePrinter.instance = new QrCodePrinter();
|
|
32
|
+
}
|
|
33
|
+
return QrCodePrinter.instance;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public async initialize(): Promise<boolean> {
|
|
37
|
+
try {
|
|
38
|
+
if (!this.isInitialized) {
|
|
39
|
+
const result = await ExpoBixolonModule.initializePrinter();
|
|
40
|
+
this.isInitialized = result;
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error initializing QR code printer:', error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async printQRCode(options: QRCodeOptions): Promise<boolean> {
|
|
51
|
+
try {
|
|
52
|
+
if (!this.isInitialized) {
|
|
53
|
+
await this.initialize();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { data, size = 9 } = options;
|
|
57
|
+
|
|
58
|
+
if (!data || data.trim().length === 0) {
|
|
59
|
+
throw new Error('QR code data cannot be empty');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (size < 1 || size > 10) {
|
|
63
|
+
throw new Error('QR code size must be between 1 and 10');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return await ExpoBixolonModule.printQRCodeAdvanced(
|
|
67
|
+
data,
|
|
68
|
+
200,
|
|
69
|
+
100,
|
|
70
|
+
'MODEL2',
|
|
71
|
+
'ECC_LEVEL_7',
|
|
72
|
+
size,
|
|
73
|
+
'NONE'
|
|
74
|
+
);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('Error printing QR code:', error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async printSimpleQRCode(data: string, size: number = 9): Promise<boolean> {
|
|
82
|
+
return this.printQRCode({
|
|
83
|
+
data,
|
|
84
|
+
size,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public async printURLQRCode(url: string, size: number = 9): Promise<boolean> {
|
|
89
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
90
|
+
url = 'https://' + url;
|
|
91
|
+
}
|
|
92
|
+
return this.printQRCode({
|
|
93
|
+
data: url,
|
|
94
|
+
size,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async printContactQRCode(
|
|
99
|
+
contact: {
|
|
100
|
+
name: string;
|
|
101
|
+
phone?: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
company?: string;
|
|
104
|
+
title?: string;
|
|
105
|
+
},
|
|
106
|
+
size: number = 9
|
|
107
|
+
): Promise<boolean> {
|
|
108
|
+
const vCard = this.generateVCard(contact);
|
|
109
|
+
return this.printQRCode({
|
|
110
|
+
data: vCard,
|
|
111
|
+
size,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public async printWiFiQRCode(
|
|
116
|
+
ssid: string,
|
|
117
|
+
password: string,
|
|
118
|
+
encryption: 'WPA' | 'WEP' | 'nopass' = 'WPA',
|
|
119
|
+
size: number = 9
|
|
120
|
+
): Promise<boolean> {
|
|
121
|
+
const wifiString = `WIFI:T:${encryption};S:${ssid};P:${password};;`;
|
|
122
|
+
return this.printQRCode({
|
|
123
|
+
data: wifiString,
|
|
124
|
+
size,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public async printPaymentQRCode(
|
|
129
|
+
paymentData: {
|
|
130
|
+
amount: number;
|
|
131
|
+
currency: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
merchantName?: string;
|
|
134
|
+
},
|
|
135
|
+
size: number = 0
|
|
136
|
+
): Promise<boolean> {
|
|
137
|
+
const paymentString = this.generatePaymentString(paymentData);
|
|
138
|
+
return this.printQRCode({
|
|
139
|
+
data: paymentString,
|
|
140
|
+
size,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private generateVCard(contact: {
|
|
145
|
+
name: string;
|
|
146
|
+
phone?: string;
|
|
147
|
+
email?: string;
|
|
148
|
+
company?: string;
|
|
149
|
+
title?: string;
|
|
150
|
+
}): string {
|
|
151
|
+
let vCard = 'BEGIN:VCARD\nVERSION:3.0\n';
|
|
152
|
+
vCard += `FN:${contact.name}\n`;
|
|
153
|
+
|
|
154
|
+
if (contact.phone) {
|
|
155
|
+
vCard += `TEL:${contact.phone}\n`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (contact.email) {
|
|
159
|
+
vCard += `EMAIL:${contact.email}\n`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (contact.company) {
|
|
163
|
+
vCard += `ORG:${contact.company}\n`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (contact.title) {
|
|
167
|
+
vCard += `TITLE:${contact.title}\n`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
vCard += 'END:VCARD';
|
|
171
|
+
return vCard;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private generatePaymentString(paymentData: {
|
|
175
|
+
amount: number;
|
|
176
|
+
currency: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
merchantName?: string;
|
|
179
|
+
}): string {
|
|
180
|
+
return `PAYMENT:${paymentData.amount}${paymentData.currency}${
|
|
181
|
+
paymentData.description ? ':' + paymentData.description : ''
|
|
182
|
+
}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public getConstants(): QRCodeConstants {
|
|
186
|
+
return {
|
|
187
|
+
QR_CODE_MODEL1: 1,
|
|
188
|
+
QR_CODE_MODEL2: 2,
|
|
189
|
+
ECC_LEVEL_7: 7,
|
|
190
|
+
ECC_LEVEL_15: 15,
|
|
191
|
+
ECC_LEVEL_25: 25,
|
|
192
|
+
ECC_LEVEL_30: 30,
|
|
193
|
+
ROTATION_NONE: 0,
|
|
194
|
+
ROTATION_90_DEGREES: 90,
|
|
195
|
+
ROTATION_180_DEGREES: 180,
|
|
196
|
+
ROTATION_270_DEGREES: 270,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default QrCodePrinter;
|
package/src/index.ts
ADDED