seven365-zyprinter 0.3.0 → 0.3.1

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.
@@ -252,6 +252,7 @@ import Network
252
252
  }
253
253
 
254
254
  @objc public func printReceipt(template: [String: Any], identifier: String, completion: @escaping (Bool, String?) -> Void) {
255
+ print("ZywellSDK: Received template: \(template)")
255
256
  guard let data = formatReceiptForPrinter(template: template) else {
256
257
  completion(false, "Failed to format receipt")
257
258
  return
@@ -323,7 +324,7 @@ import Network
323
324
  printData.append(Data([0x1B, 0x61, 0x01]))
324
325
 
325
326
  // Header
326
- if let header = template["header"] as? String,
327
+ if let header = getString(template["header"]),
327
328
  let headerData = (header + "\n\n").data(using: .utf8) {
328
329
 
329
330
  // Get header size from formatting options
@@ -332,6 +333,7 @@ import Network
332
333
  let headerSize = formatting["headerSize"] {
333
334
  sizeCode = mapHeaderSizeToCode(headerSize)
334
335
  }
336
+ print("ZywellSDK: Header size code: \(sizeCode)")
335
337
 
336
338
  // Set font size (GS ! n)
337
339
  printData.append(Data([0x1D, 0x21, sizeCode]))
@@ -354,8 +356,9 @@ import Network
354
356
  if let itemSize = formatting["itemSize"] {
355
357
  itemSizeCode = mapHeaderSizeToCode(itemSize)
356
358
  }
357
- itemBold = formatting["itemBold"] as? Bool ?? false
359
+ itemBold = getBool(formatting["itemBold"])
358
360
  }
361
+ print("ZywellSDK: Item bold: \(itemBold)")
359
362
 
360
363
  // Apply item formatting
361
364
  if itemBold {
@@ -366,8 +369,8 @@ import Network
366
369
  }
367
370
 
368
371
  for item in items {
369
- if let name = item["name"] as? String,
370
- let price = item["price"] as? String {
372
+ if let name = getString(item["name"]),
373
+ let price = getString(item["price"]) {
371
374
  let line = String(format: "%@\t%@\n", name, price)
372
375
  if let lineData = line.data(using: .utf8) {
373
376
  printData.append(lineData)
@@ -385,7 +388,7 @@ import Network
385
388
  }
386
389
 
387
390
  // Total
388
- if let total = template["total"] as? String,
391
+ if let total = getString(template["total"]),
389
392
  let totalData = ("\nTotal: " + total + "\n").data(using: .utf8) {
390
393
  // Get total formatting
391
394
  var totalSizeCode: UInt8 = 0x00
@@ -394,8 +397,10 @@ import Network
394
397
  if let totalSize = formatting["totalSize"] {
395
398
  totalSizeCode = mapHeaderSizeToCode(totalSize)
396
399
  }
397
- totalBold = formatting["totalBold"] as? Bool ?? false
400
+ totalBold = getBool(formatting["totalBold"])
398
401
  }
402
+ print("ZywellSDK: Total size code: \(totalSizeCode)")
403
+ print("ZywellSDK: Total bold: \(totalBold)")
399
404
 
400
405
  // Apply total formatting
401
406
  if totalBold {
@@ -417,7 +422,7 @@ import Network
417
422
  }
418
423
 
419
424
  // Footer
420
- if let footer = template["footer"] as? String,
425
+ if let footer = getString(template["footer"]),
421
426
  let footerData = (footer + "\n").data(using: .utf8) {
422
427
  // Get footer formatting
423
428
  var footerSizeCode: UInt8 = 0x00
@@ -460,16 +465,44 @@ import Network
460
465
  default: return 0x00
461
466
  }
462
467
  } 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
468
+ switch sizeStr.lowercased() {
469
+ case "normal", "1": return 0x00
470
+ case "large", "2": return 0x11
471
+ case "xlarge", "3": return 0x22
472
+ case "4": return 0x33
467
473
  default: return 0x00
468
474
  }
475
+ } else if let sizeNum = size as? NSNumber {
476
+ switch sizeNum.intValue {
477
+ case 1: return 0x00
478
+ case 2: return 0x11
479
+ case 3: return 0x22
480
+ case 4: return 0x33
481
+ default: return 0x00
482
+ }
469
483
  }
470
484
  return 0x00
471
485
  }
472
486
 
487
+ private func getBool(_ value: Any?) -> Bool {
488
+ guard let value = value else { return false }
489
+ if let boolVal = value as? Bool { return boolVal }
490
+ if let strVal = value as? String {
491
+ return ["true", "yes", "1"].contains(strVal.lowercased())
492
+ }
493
+ if let numVal = value as? NSNumber {
494
+ return numVal.boolValue
495
+ }
496
+ return false
497
+ }
498
+
499
+ private func getString(_ value: Any?) -> String? {
500
+ guard let value = value else { return nil }
501
+ if let strVal = value as? String { return strVal }
502
+ if let numVal = value as? NSNumber { return numVal.stringValue }
503
+ return String(describing: value)
504
+ }
505
+
473
506
  // MARK: - Callback Storage
474
507
 
475
508
  private var discoveryCompletion: (([[String: Any]], String?) -> Void)?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seven365-zyprinter",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Capacitor plugin for Zywell/Zyprint thermal printer integration with Bluetooth and WiFi support",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",