seven365-zyprinter 0.1.0 → 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.
@@ -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: Record<string, any>;
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: Record<string, any>; identifier: string }): Promise<{ success: boolean }>;\n \n // Printer Status\n getPrinterStatus(options: { identifier: string }): Promise<{ status: string; paperStatus: string; connected: boolean }>;\n}\n"]}
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)?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seven365-zyprinter",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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",