seven365-zyprinter 0.0.11 → 0.2.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 +76 -13
- package/android/src/main/java/com/mycompany/plugins/example/Example.java +119 -0
- package/dist/docs.json +935 -14
- package/dist/esm/definitions.d.ts +19 -1
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/Plugin/ZywellSDK.swift +152 -13
- package/package.json +1 -1
|
@@ -7,6 +7,24 @@ export interface ZyPrinter {
|
|
|
7
7
|
port?: number;
|
|
8
8
|
rssi?: number;
|
|
9
9
|
}
|
|
10
|
+
export interface ReceiptFormatting {
|
|
11
|
+
headerSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;
|
|
12
|
+
itemSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;
|
|
13
|
+
itemBold?: boolean;
|
|
14
|
+
totalSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;
|
|
15
|
+
totalBold?: boolean;
|
|
16
|
+
footerSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;
|
|
17
|
+
}
|
|
18
|
+
export interface ReceiptTemplate {
|
|
19
|
+
header?: string;
|
|
20
|
+
items?: Array<{
|
|
21
|
+
name: string;
|
|
22
|
+
price: string;
|
|
23
|
+
}>;
|
|
24
|
+
total?: string;
|
|
25
|
+
footer?: string;
|
|
26
|
+
formatting?: ReceiptFormatting;
|
|
27
|
+
}
|
|
10
28
|
export interface ZyprintPlugin {
|
|
11
29
|
echo(options: {
|
|
12
30
|
value: string;
|
|
@@ -41,7 +59,7 @@ export interface ZyprintPlugin {
|
|
|
41
59
|
success: boolean;
|
|
42
60
|
}>;
|
|
43
61
|
printReceipt(options: {
|
|
44
|
-
template:
|
|
62
|
+
template: ReceiptTemplate;
|
|
45
63
|
identifier: string;
|
|
46
64
|
}): Promise<{
|
|
47
65
|
success: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["// Enhanced printer interface with connection type details\nexport interface ZyPrinter {\n identifier: string;\n model: string;\n status: string;\n connectionType: 'bluetooth' | 'wifi' | 'usb';\n ipAddress?: string;\n port?: number;\n rssi?: number;\n}\n\nexport interface ZyprintPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n \n // Enhanced Printer Discovery Methods\n discoverPrinters(): Promise<{ printers: ZyPrinter[] }>;\n discoverBluetoothPrinters(): Promise<{ printers: ZyPrinter[] }>;\n discoverWiFiPrinters(options?: { networkRange?: string }): Promise<{ printers: ZyPrinter[] }>;\n \n // Connection Management\n connectToPrinter(options: { identifier: string }): Promise<{ connected: boolean }>;\n disconnectFromPrinter(options: { identifier: string }): Promise<{ disconnected: boolean }>;\n \n // Printing Methods\n printText(options: { text: string; identifier: string }): Promise<{ success: boolean }>;\n printReceipt(options: { template:
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["// Enhanced printer interface with connection type details\nexport interface ZyPrinter {\n identifier: string;\n model: string;\n status: string;\n connectionType: 'bluetooth' | 'wifi' | 'usb';\n ipAddress?: string;\n port?: number;\n rssi?: number;\n}\n\nexport interface ReceiptFormatting {\n headerSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;\n itemSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;\n itemBold?: boolean;\n totalSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;\n totalBold?: boolean;\n footerSize?: 'normal' | 'large' | 'xlarge' | 1 | 2 | 3 | 4;\n}\n\nexport interface ReceiptTemplate {\n header?: string;\n items?: Array<{ name: string; price: string }>;\n total?: string;\n footer?: string;\n formatting?: ReceiptFormatting;\n}\n\nexport interface ZyprintPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n \n // Enhanced Printer Discovery Methods\n discoverPrinters(): Promise<{ printers: ZyPrinter[] }>;\n discoverBluetoothPrinters(): Promise<{ printers: ZyPrinter[] }>;\n discoverWiFiPrinters(options?: { networkRange?: string }): Promise<{ printers: ZyPrinter[] }>;\n \n // Connection Management\n connectToPrinter(options: { identifier: string }): Promise<{ connected: boolean }>;\n disconnectFromPrinter(options: { identifier: string }): Promise<{ disconnected: boolean }>;\n \n // Printing Methods\n printText(options: { text: string; identifier: string }): Promise<{ success: boolean }>;\n printReceipt(options: { template: ReceiptTemplate; identifier: string }): Promise<{ success: boolean }>;\n \n // Printer Status\n getPrinterStatus(options: { identifier: string }): Promise<{ status: string; paperStatus: string; connected: boolean }>;\n}\n"]}
|
|
@@ -325,7 +325,21 @@ import Network
|
|
|
325
325
|
// Header
|
|
326
326
|
if let header = template["header"] as? String,
|
|
327
327
|
let headerData = (header + "\n\n").data(using: .utf8) {
|
|
328
|
+
|
|
329
|
+
// Get header size from formatting options
|
|
330
|
+
var sizeCode: UInt8 = 0x00 // Default: normal
|
|
331
|
+
if let formatting = template["formatting"] as? [String: Any],
|
|
332
|
+
let headerSize = formatting["headerSize"] {
|
|
333
|
+
sizeCode = mapHeaderSizeToCode(headerSize)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Set font size (GS ! n)
|
|
337
|
+
printData.append(Data([0x1D, 0x21, sizeCode]))
|
|
338
|
+
|
|
328
339
|
printData.append(headerData)
|
|
340
|
+
|
|
341
|
+
// Reset to normal size (GS ! 0)
|
|
342
|
+
printData.append(Data([0x1D, 0x21, 0x00]))
|
|
329
343
|
}
|
|
330
344
|
|
|
331
345
|
// Left align (ESC a 0)
|
|
@@ -333,6 +347,24 @@ import Network
|
|
|
333
347
|
|
|
334
348
|
// Items
|
|
335
349
|
if let items = template["items"] as? [[String: Any]] {
|
|
350
|
+
// Get item formatting
|
|
351
|
+
var itemSizeCode: UInt8 = 0x00
|
|
352
|
+
var itemBold = false
|
|
353
|
+
if let formatting = template["formatting"] as? [String: Any] {
|
|
354
|
+
if let itemSize = formatting["itemSize"] {
|
|
355
|
+
itemSizeCode = mapHeaderSizeToCode(itemSize)
|
|
356
|
+
}
|
|
357
|
+
itemBold = formatting["itemBold"] as? Bool ?? false
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Apply item formatting
|
|
361
|
+
if itemBold {
|
|
362
|
+
printData.append(Data([0x1B, 0x45, 0x01])) // Bold on (ESC E 1)
|
|
363
|
+
}
|
|
364
|
+
if itemSizeCode != 0x00 {
|
|
365
|
+
printData.append(Data([0x1D, 0x21, itemSizeCode])) // Set size
|
|
366
|
+
}
|
|
367
|
+
|
|
336
368
|
for item in items {
|
|
337
369
|
if let name = item["name"] as? String,
|
|
338
370
|
let price = item["price"] as? String {
|
|
@@ -342,18 +374,69 @@ import Network
|
|
|
342
374
|
}
|
|
343
375
|
}
|
|
344
376
|
}
|
|
377
|
+
|
|
378
|
+
// Reset item formatting
|
|
379
|
+
if itemSizeCode != 0x00 {
|
|
380
|
+
printData.append(Data([0x1D, 0x21, 0x00])) // Normal size
|
|
381
|
+
}
|
|
382
|
+
if itemBold {
|
|
383
|
+
printData.append(Data([0x1B, 0x45, 0x00])) // Bold off (ESC E 0)
|
|
384
|
+
}
|
|
345
385
|
}
|
|
346
386
|
|
|
347
387
|
// Total
|
|
348
388
|
if let total = template["total"] as? String,
|
|
349
389
|
let totalData = ("\nTotal: " + total + "\n").data(using: .utf8) {
|
|
390
|
+
// Get total formatting
|
|
391
|
+
var totalSizeCode: UInt8 = 0x00
|
|
392
|
+
var totalBold = false
|
|
393
|
+
if let formatting = template["formatting"] as? [String: Any] {
|
|
394
|
+
if let totalSize = formatting["totalSize"] {
|
|
395
|
+
totalSizeCode = mapHeaderSizeToCode(totalSize)
|
|
396
|
+
}
|
|
397
|
+
totalBold = formatting["totalBold"] as? Bool ?? false
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Apply total formatting
|
|
401
|
+
if totalBold {
|
|
402
|
+
printData.append(Data([0x1B, 0x45, 0x01])) // Bold on
|
|
403
|
+
}
|
|
404
|
+
if totalSizeCode != 0x00 {
|
|
405
|
+
printData.append(Data([0x1D, 0x21, totalSizeCode])) // Set size
|
|
406
|
+
}
|
|
407
|
+
|
|
350
408
|
printData.append(totalData)
|
|
409
|
+
|
|
410
|
+
// Reset total formatting
|
|
411
|
+
if totalSizeCode != 0x00 {
|
|
412
|
+
printData.append(Data([0x1D, 0x21, 0x00])) // Normal size
|
|
413
|
+
}
|
|
414
|
+
if totalBold {
|
|
415
|
+
printData.append(Data([0x1B, 0x45, 0x00])) // Bold off
|
|
416
|
+
}
|
|
351
417
|
}
|
|
352
418
|
|
|
353
419
|
// Footer
|
|
354
420
|
if let footer = template["footer"] as? String,
|
|
355
421
|
let footerData = (footer + "\n").data(using: .utf8) {
|
|
422
|
+
// Get footer formatting
|
|
423
|
+
var footerSizeCode: UInt8 = 0x00
|
|
424
|
+
if let formatting = template["formatting"] as? [String: Any],
|
|
425
|
+
let footerSize = formatting["footerSize"] {
|
|
426
|
+
footerSizeCode = mapHeaderSizeToCode(footerSize)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Apply footer formatting
|
|
430
|
+
if footerSizeCode != 0x00 {
|
|
431
|
+
printData.append(Data([0x1D, 0x21, footerSizeCode])) // Set size
|
|
432
|
+
}
|
|
433
|
+
|
|
356
434
|
printData.append(footerData)
|
|
435
|
+
|
|
436
|
+
// Reset footer formatting
|
|
437
|
+
if footerSizeCode != 0x00 {
|
|
438
|
+
printData.append(Data([0x1D, 0x21, 0x00])) // Normal size
|
|
439
|
+
}
|
|
357
440
|
}
|
|
358
441
|
|
|
359
442
|
// Line feeds
|
|
@@ -365,6 +448,28 @@ import Network
|
|
|
365
448
|
return printData
|
|
366
449
|
}
|
|
367
450
|
|
|
451
|
+
// MARK: - Helper Functions
|
|
452
|
+
|
|
453
|
+
private func mapHeaderSizeToCode(_ size: Any) -> UInt8 {
|
|
454
|
+
if let sizeInt = size as? Int {
|
|
455
|
+
switch sizeInt {
|
|
456
|
+
case 1: return 0x00
|
|
457
|
+
case 2: return 0x11
|
|
458
|
+
case 3: return 0x22
|
|
459
|
+
case 4: return 0x33
|
|
460
|
+
default: return 0x00
|
|
461
|
+
}
|
|
462
|
+
} else if let sizeStr = size as? String {
|
|
463
|
+
switch sizeStr {
|
|
464
|
+
case "normal": return 0x00
|
|
465
|
+
case "large": return 0x11
|
|
466
|
+
case "xlarge": return 0x22
|
|
467
|
+
default: return 0x00
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return 0x00
|
|
471
|
+
}
|
|
472
|
+
|
|
368
473
|
// MARK: - Callback Storage
|
|
369
474
|
|
|
370
475
|
private var discoveryCompletion: (([[String: Any]], String?) -> Void)?
|
|
@@ -373,11 +478,11 @@ import Network
|
|
|
373
478
|
}
|
|
374
479
|
|
|
375
480
|
// MARK: - POSBLEManagerDelegate
|
|
376
|
-
|
|
377
481
|
extension ZywellSDK: POSBLEManagerDelegate {
|
|
378
482
|
|
|
379
|
-
|
|
380
|
-
|
|
483
|
+
// Method 1: Already had
|
|
484
|
+
|
|
485
|
+
@objc public func poSdidUpdatePeripheralList(_ peripherals: [Any]?, rssiList: [Any]?) {
|
|
381
486
|
guard let peripherals = peripherals as? [CBPeripheral],
|
|
382
487
|
let rssis = rssiList as? [NSNumber] else { return }
|
|
383
488
|
|
|
@@ -385,30 +490,35 @@ extension ZywellSDK: POSBLEManagerDelegate {
|
|
|
385
490
|
self.peripheralRSSIs = rssis
|
|
386
491
|
}
|
|
387
492
|
|
|
388
|
-
|
|
389
|
-
|
|
493
|
+
|
|
494
|
+
// Method 2: Already had
|
|
495
|
+
@objc public func poSdidConnect(_ peripheral: CBPeripheral?) {
|
|
496
|
+
guard let peripheral = peripheral else { return }
|
|
390
497
|
DispatchQueue.main.async { [weak self] in
|
|
391
498
|
self?.connectionCompletion?(true, nil)
|
|
392
499
|
self?.connectionCompletion = nil
|
|
393
500
|
}
|
|
394
501
|
}
|
|
395
502
|
|
|
396
|
-
|
|
397
|
-
public func
|
|
398
|
-
let errorMsg = error
|
|
503
|
+
// Method 3: Already had
|
|
504
|
+
@objc public func poSdidFail(toConnect peripheral: CBPeripheral?, error: Error?) {
|
|
505
|
+
let errorMsg = error?.localizedDescription ?? "Connection failed"
|
|
399
506
|
DispatchQueue.main.async { [weak self] in
|
|
400
507
|
self?.connectionCompletion?(false, errorMsg)
|
|
401
508
|
self?.connectionCompletion = nil
|
|
402
509
|
}
|
|
403
510
|
}
|
|
404
511
|
|
|
405
|
-
|
|
406
|
-
public func poSdidDisconnectPeripheral(_ peripheral: CBPeripheral
|
|
512
|
+
// Method 4: Already had
|
|
513
|
+
@objc public func poSdidDisconnectPeripheral(_ peripheral: CBPeripheral?, isAutoDisconnect: Bool) {
|
|
407
514
|
// Handle disconnection
|
|
515
|
+
if let peripheral = peripheral {
|
|
516
|
+
print("Disconnected from: \(peripheral.name ?? "Unknown")")
|
|
517
|
+
}
|
|
408
518
|
}
|
|
409
519
|
|
|
410
|
-
|
|
411
|
-
public func
|
|
520
|
+
// Method 5: Fixed based on error
|
|
521
|
+
@objc public func poSdidWriteValue(for character: CBCharacteristic?, error: Error?) {
|
|
412
522
|
DispatchQueue.main.async { [weak self] in
|
|
413
523
|
if let error = error {
|
|
414
524
|
self?.printCompletion?(false, error.localizedDescription)
|
|
@@ -418,6 +528,35 @@ extension ZywellSDK: POSBLEManagerDelegate {
|
|
|
418
528
|
self?.printCompletion = nil
|
|
419
529
|
}
|
|
420
530
|
}
|
|
531
|
+
|
|
532
|
+
// ADD THESE COMMONLY REQUIRED METHODS:
|
|
533
|
+
|
|
534
|
+
// Method 6: Bluetooth state updates - VERY COMMONLY REQUIRED
|
|
535
|
+
@objc public func poScentralManagerDidUpdateState(_ central: Any?) {
|
|
536
|
+
if let central = central as? CBCentralManager {
|
|
537
|
+
print("Bluetooth state: \(central.state.rawValue)")
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Method 7: Did discover services
|
|
542
|
+
@objc public func poSdidDiscoverServices(_ peripheral: CBPeripheral!) {
|
|
543
|
+
// Handle service discovery
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Method 8: Did discover characteristics
|
|
547
|
+
@objc public func poSdidDiscoverCharacteristics(for service: CBService!, error: Error!) {
|
|
548
|
+
// Handle characteristic discovery
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Method 9: Did update value for characteristic
|
|
552
|
+
@objc public func poSdidUpdateValue(for characteristic: CBCharacteristic!, error: Error!) {
|
|
553
|
+
// Handle updated values
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Method 10: Did update notification state
|
|
557
|
+
@objc public func poSdidUpdateNotificationState(for characteristic: CBCharacteristic!, error: Error!) {
|
|
558
|
+
// Handle notification state changes
|
|
559
|
+
}
|
|
421
560
|
}
|
|
422
561
|
|
|
423
562
|
// MARK: - POSWIFIManagerDelegate
|
|
@@ -446,7 +585,7 @@ extension ZywellSDK: POSWIFIManagerDelegate {
|
|
|
446
585
|
}
|
|
447
586
|
|
|
448
587
|
@objc(POSWIFIManager:didReadData:tag:)
|
|
449
|
-
public func poswifiManager(_ manager: POSWIFIManager,
|
|
588
|
+
public func poswifiManager(_ manager: POSWIFIManager, didRead data: Data, tag: Int) {
|
|
450
589
|
// Handle data reading if needed
|
|
451
590
|
}
|
|
452
591
|
|
package/package.json
CHANGED