seven365-zyprinter 0.3.1 → 0.4.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
CHANGED
|
@@ -178,6 +178,7 @@ getPrinterStatus(options: { identifier: string; }) => Promise<{ status: string;
|
|
|
178
178
|
| ---------------- | ------------------------------------------------------------------------------ |
|
|
179
179
|
| **`header`** | <code>string</code> |
|
|
180
180
|
| **`items`** | <code><a href="#array">Array</a><{ name: string; price: string }></code> |
|
|
181
|
+
| **`kitchen`** | <code><a href="#array">Array</a><any></code> |
|
|
181
182
|
| **`total`** | <code>string</code> |
|
|
182
183
|
| **`footer`** | <code>string</code> |
|
|
183
184
|
| **`formatting`** | <code><a href="#receiptformatting">ReceiptFormatting</a></code> |
|
package/dist/docs.json
CHANGED
|
@@ -230,6 +230,15 @@
|
|
|
230
230
|
],
|
|
231
231
|
"type": "Array<{ name: string; price: string }>"
|
|
232
232
|
},
|
|
233
|
+
{
|
|
234
|
+
"name": "kitchen",
|
|
235
|
+
"tags": [],
|
|
236
|
+
"docs": "",
|
|
237
|
+
"complexTypes": [
|
|
238
|
+
"Array"
|
|
239
|
+
],
|
|
240
|
+
"type": "Array<any>"
|
|
241
|
+
},
|
|
233
242
|
{
|
|
234
243
|
"name": "total",
|
|
235
244
|
"tags": [],
|
|
@@ -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 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"]}
|
|
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 kitchen?: Array<any>; // Support for kitchen data payload\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"]}
|
|
@@ -348,7 +348,86 @@ import Network
|
|
|
348
348
|
printData.append(Data([0x1B, 0x61, 0x00]))
|
|
349
349
|
|
|
350
350
|
// Items
|
|
351
|
-
if let
|
|
351
|
+
if let kitchen = template["kitchen"] as? [[String: Any]] {
|
|
352
|
+
// Get item formatting
|
|
353
|
+
var itemSizeCode: UInt8 = 0x00
|
|
354
|
+
var itemBold = false
|
|
355
|
+
if let formatting = template["formatting"] as? [String: Any] {
|
|
356
|
+
if let itemSize = formatting["itemSize"] {
|
|
357
|
+
itemSizeCode = mapHeaderSizeToCode(itemSize)
|
|
358
|
+
}
|
|
359
|
+
itemBold = getBool(formatting["itemBold"])
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Apply item formatting
|
|
363
|
+
if itemBold {
|
|
364
|
+
printData.append(Data([0x1B, 0x45, 0x01])) // Bold on
|
|
365
|
+
}
|
|
366
|
+
if itemSizeCode != 0x00 {
|
|
367
|
+
printData.append(Data([0x1D, 0x21, itemSizeCode])) // Set size
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
for item in kitchen {
|
|
371
|
+
var itemName = ""
|
|
372
|
+
var itemPrice = ""
|
|
373
|
+
|
|
374
|
+
// Get name from menu object
|
|
375
|
+
if let menu = item["menu"] as? [String: Any],
|
|
376
|
+
let name = getString(menu["name"]) {
|
|
377
|
+
itemName = name
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Add quantity
|
|
381
|
+
if let qty = item["quantity"] {
|
|
382
|
+
itemName += " x\(getString(qty) ?? "1")"
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Format price
|
|
386
|
+
if let price = item["total_price"] {
|
|
387
|
+
if let priceDouble = Double(getString(price) ?? "0") {
|
|
388
|
+
itemPrice = String(format: "$%.2f", priceDouble)
|
|
389
|
+
} else {
|
|
390
|
+
itemPrice = "$" + (getString(price) ?? "0.00")
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Print main item
|
|
395
|
+
let line = String(format: "%@\t%@\n", itemName, itemPrice)
|
|
396
|
+
if let lineData = line.data(using: .utf8) {
|
|
397
|
+
printData.append(lineData)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Print modifiers
|
|
401
|
+
if let modifiers = item["modifiers"] as? [[String: Any]] {
|
|
402
|
+
for mod in modifiers {
|
|
403
|
+
if let modName = getString(mod["name"]) {
|
|
404
|
+
var modLine = " + \(modName)"
|
|
405
|
+
|
|
406
|
+
// Only show price if > 0
|
|
407
|
+
if let modPrice = mod["price"],
|
|
408
|
+
let priceDouble = Double(getString(modPrice) ?? "0"),
|
|
409
|
+
priceDouble > 0 {
|
|
410
|
+
modLine += String(format: "\t$%.2f", priceDouble)
|
|
411
|
+
}
|
|
412
|
+
modLine += "\n"
|
|
413
|
+
|
|
414
|
+
if let modData = modLine.data(using: .utf8) {
|
|
415
|
+
printData.append(modData)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Reset item formatting
|
|
423
|
+
if itemSizeCode != 0x00 {
|
|
424
|
+
printData.append(Data([0x1D, 0x21, 0x00])) // Normal size
|
|
425
|
+
}
|
|
426
|
+
if itemBold {
|
|
427
|
+
printData.append(Data([0x1B, 0x45, 0x00])) // Bold off
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
} else if let items = template["items"] as? [[String: Any]] {
|
|
352
431
|
// Get item formatting
|
|
353
432
|
var itemSizeCode: UInt8 = 0x00
|
|
354
433
|
var itemBold = false
|
package/package.json
CHANGED