@m430/capacitor-label-printer 0.1.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.
Files changed (150) hide show
  1. package/API.md +218 -0
  2. package/LICENSE +21 -0
  3. package/M430CapacitorLabelPrinter.podspec +21 -0
  4. package/README.md +190 -0
  5. package/android/build.gradle +46 -0
  6. package/android/libs/.gitkeep +1 -0
  7. package/android/libs/fat-generic-tspl-bluetooth-classic-0.1.16-GA.jar +0 -0
  8. package/android/src/main/AndroidManifest.xml +12 -0
  9. package/android/src/main/java/com/m430/capacitor/labelprinter/.gitkeep +1 -0
  10. package/android/src/main/java/com/m430/capacitor/labelprinter/AndroidPrinterManager.java +132 -0
  11. package/android/src/main/java/com/m430/capacitor/labelprinter/AndroidStatusMapper.java +54 -0
  12. package/android/src/main/java/com/m430/capacitor/labelprinter/LabelPrinterPlugin.java +273 -0
  13. package/android/src/main/java/com/m430/capacitor/labelprinter/VendorAndroidDeviceCatalog.java +81 -0
  14. package/android/src/main/java/com/m430/capacitor/labelprinter/VendorAndroidPrinterSession.java +189 -0
  15. package/capacitor-label-printer.podspec +21 -0
  16. package/dist/docs.json +443 -0
  17. package/dist/esm/cpcl/builder.d.ts +10 -0
  18. package/dist/esm/cpcl/builder.js +35 -0
  19. package/dist/esm/definitions.d.ts +107 -0
  20. package/dist/esm/definitions.js +1 -0
  21. package/dist/esm/errors.d.ts +1 -0
  22. package/dist/esm/errors.js +1 -0
  23. package/dist/esm/index.d.ts +9 -0
  24. package/dist/esm/index.js +11 -0
  25. package/dist/esm/tspl/builder.d.ts +13 -0
  26. package/dist/esm/tspl/builder.js +45 -0
  27. package/dist/esm/tspl/helpers.d.ts +2 -0
  28. package/dist/esm/tspl/helpers.js +6 -0
  29. package/dist/esm/types.d.ts +12 -0
  30. package/dist/esm/types.js +1 -0
  31. package/dist/esm/web.d.ts +21 -0
  32. package/dist/esm/web.js +34 -0
  33. package/dist/plugin.cjs.js +143 -0
  34. package/dist/plugin.cjs.js.map +1 -0
  35. package/dist/plugin.js +136 -0
  36. package/dist/plugin.js.map +1 -0
  37. package/ios/Plugin/.gitkeep +1 -0
  38. package/ios/Plugin/IOSPrinterManager.swift +230 -0
  39. package/ios/Plugin/IOSStatusMapper.swift +57 -0
  40. package/ios/Plugin/LabelPrinterPlugin.swift +141 -0
  41. package/ios/VendorFrameworks/.gitkeep +1 -0
  42. package/ios/VendorFrameworks/adapter.framework/Headers/BasedOtherConnectedDevice.h +17 -0
  43. package/ios/VendorFrameworks/adapter.framework/Headers/ConnectedDevice.h +213 -0
  44. package/ios/VendorFrameworks/adapter.framework/Headers/IPRTBlueToothBaseDef.h +22 -0
  45. package/ios/VendorFrameworks/adapter.framework/Headers/KeepStateConnectedDevice.h +18 -0
  46. package/ios/VendorFrameworks/adapter.framework/Headers/QueueConfig.h +18 -0
  47. package/ios/VendorFrameworks/adapter.framework/Headers/ReadOptions.h +22 -0
  48. package/ios/VendorFrameworks/adapter.framework/Headers/WroteReporter.h +23 -0
  49. package/ios/VendorFrameworks/adapter.framework/Headers/adapter.h +18 -0
  50. package/ios/VendorFrameworks/adapter.framework/Info.plist +0 -0
  51. package/ios/VendorFrameworks/adapter.framework/Modules/module.modulemap +6 -0
  52. package/ios/VendorFrameworks/adapter.framework/adapter +0 -0
  53. package/ios/VendorFrameworks/appleble.framework/Frameworks/adapter.framework/Info.plist +0 -0
  54. package/ios/VendorFrameworks/appleble.framework/Frameworks/adapter.framework/_CodeSignature/CodeResources +101 -0
  55. package/ios/VendorFrameworks/appleble.framework/Frameworks/adapter.framework/adapter +0 -0
  56. package/ios/VendorFrameworks/appleble.framework/Frameworks/ibridge.framework/Frameworks/adapter.framework/Info.plist +0 -0
  57. package/ios/VendorFrameworks/appleble.framework/Frameworks/ibridge.framework/Frameworks/adapter.framework/adapter +0 -0
  58. package/ios/VendorFrameworks/appleble.framework/Frameworks/ibridge.framework/Info.plist +0 -0
  59. package/ios/VendorFrameworks/appleble.framework/Frameworks/ibridge.framework/_CodeSignature/CodeResources +132 -0
  60. package/ios/VendorFrameworks/appleble.framework/Frameworks/ibridge.framework/ibridge +0 -0
  61. package/ios/VendorFrameworks/appleble.framework/Headers/AppleBle.h +25 -0
  62. package/ios/VendorFrameworks/appleble.framework/Info.plist +0 -0
  63. package/ios/VendorFrameworks/appleble.framework/Modules/module.modulemap +6 -0
  64. package/ios/VendorFrameworks/appleble.framework/_CodeSignature/CodeResources +252 -0
  65. package/ios/VendorFrameworks/appleble.framework/appleble +0 -0
  66. package/ios/VendorFrameworks/father.framework/Frameworks/adapter.framework/Info.plist +0 -0
  67. package/ios/VendorFrameworks/father.framework/Frameworks/adapter.framework/adapter +0 -0
  68. package/ios/VendorFrameworks/father.framework/Headers/Appendat.h +28 -0
  69. package/ios/VendorFrameworks/father.framework/Headers/Arg.h +22 -0
  70. package/ios/VendorFrameworks/father.framework/Headers/BasicBatteryVolumeArg.h +16 -0
  71. package/ios/VendorFrameworks/father.framework/Headers/BinaryCommand.h +17 -0
  72. package/ios/VendorFrameworks/father.framework/Headers/CPCLCommand.h +10 -0
  73. package/ios/VendorFrameworks/father.framework/Headers/CallbackData.h +26 -0
  74. package/ios/VendorFrameworks/father.framework/Headers/Checker.h +16 -0
  75. package/ios/VendorFrameworks/father.framework/Headers/Command.h +25 -0
  76. package/ios/VendorFrameworks/father.framework/Headers/CommandClause.h +33 -0
  77. package/ios/VendorFrameworks/father.framework/Headers/Commander.h +31 -0
  78. package/ios/VendorFrameworks/father.framework/Headers/DataWriteOperation.h +42 -0
  79. package/ios/VendorFrameworks/father.framework/Headers/DefaultCommand.h +16 -0
  80. package/ios/VendorFrameworks/father.framework/Headers/EasyArg.h +16 -0
  81. package/ios/VendorFrameworks/father.framework/Headers/FastBinary.h +20 -0
  82. package/ios/VendorFrameworks/father.framework/Headers/HexOutput.h +19 -0
  83. package/ios/VendorFrameworks/father.framework/Headers/IDataWriteCallback.h +25 -0
  84. package/ios/VendorFrameworks/father.framework/Headers/Lifecycle.h +21 -0
  85. package/ios/VendorFrameworks/father.framework/Headers/NewLineArg.h +15 -0
  86. package/ios/VendorFrameworks/father.framework/Headers/OnlyBinaryHeaderArg.h +15 -0
  87. package/ios/VendorFrameworks/father.framework/Headers/OnlyTextHeaderArg.h +16 -0
  88. package/ios/VendorFrameworks/father.framework/Headers/PImageTool.h +22 -0
  89. package/ios/VendorFrameworks/father.framework/Headers/PReplaceKit.h +16 -0
  90. package/ios/VendorFrameworks/father.framework/Headers/PSDK.h +60 -0
  91. package/ios/VendorFrameworks/father.framework/Headers/PVariableKit.h +18 -0
  92. package/ios/VendorFrameworks/father.framework/Headers/PsdkConst.h +33 -0
  93. package/ios/VendorFrameworks/father.framework/Headers/Raw.h +22 -0
  94. package/ios/VendorFrameworks/father.framework/Headers/SimpleCheck.h +16 -0
  95. package/ios/VendorFrameworks/father.framework/Headers/SingleCommand.h +32 -0
  96. package/ios/VendorFrameworks/father.framework/Headers/TSPLCommand.h +10 -0
  97. package/ios/VendorFrameworks/father.framework/Headers/WriteControl.h +12 -0
  98. package/ios/VendorFrameworks/father.framework/Headers/WriteOptions.h +28 -0
  99. package/ios/VendorFrameworks/father.framework/Headers/father.h +21 -0
  100. package/ios/VendorFrameworks/father.framework/Info.plist +0 -0
  101. package/ios/VendorFrameworks/father.framework/Modules/module.modulemap +6 -0
  102. package/ios/VendorFrameworks/father.framework/father +0 -0
  103. package/ios/VendorFrameworks/tspl.framework/Frameworks/father.framework/Frameworks/adapter.framework/Info.plist +0 -0
  104. package/ios/VendorFrameworks/tspl.framework/Frameworks/father.framework/Frameworks/adapter.framework/adapter +0 -0
  105. package/ios/VendorFrameworks/tspl.framework/Frameworks/father.framework/Info.plist +0 -0
  106. package/ios/VendorFrameworks/tspl.framework/Frameworks/father.framework/father +0 -0
  107. package/ios/VendorFrameworks/tspl.framework/Headers/BasicTSPL.h +146 -0
  108. package/ios/VendorFrameworks/tspl.framework/Headers/BasicTSPLArg.h +17 -0
  109. package/ios/VendorFrameworks/tspl.framework/Headers/GenericTSPL.h +16 -0
  110. package/ios/VendorFrameworks/tspl.framework/Headers/TBar.h +30 -0
  111. package/ios/VendorFrameworks/tspl.framework/Headers/TBarCode.h +54 -0
  112. package/ios/VendorFrameworks/tspl.framework/Headers/TBatteryVolume.h +19 -0
  113. package/ios/VendorFrameworks/tspl.framework/Headers/TBox.h +32 -0
  114. package/ios/VendorFrameworks/tspl.framework/Headers/TCircle.h +26 -0
  115. package/ios/VendorFrameworks/tspl.framework/Headers/TCleanBmpFlash.h +20 -0
  116. package/ios/VendorFrameworks/tspl.framework/Headers/TClear.h +20 -0
  117. package/ios/VendorFrameworks/tspl.framework/Headers/TCut.h +21 -0
  118. package/ios/VendorFrameworks/tspl.framework/Headers/TDensity.h +21 -0
  119. package/ios/VendorFrameworks/tspl.framework/Headers/TDirection.h +51 -0
  120. package/ios/VendorFrameworks/tspl.framework/Headers/TDmatrix.h +29 -0
  121. package/ios/VendorFrameworks/tspl.framework/Headers/TDownloadBmpFlash.h +16 -0
  122. package/ios/VendorFrameworks/tspl.framework/Headers/TGap.h +21 -0
  123. package/ios/VendorFrameworks/tspl.framework/Headers/TImage.h +36 -0
  124. package/ios/VendorFrameworks/tspl.framework/Headers/TLine.h +34 -0
  125. package/ios/VendorFrameworks/tspl.framework/Headers/TMddle.h +16 -0
  126. package/ios/VendorFrameworks/tspl.framework/Headers/TPage.h +22 -0
  127. package/ios/VendorFrameworks/tspl.framework/Headers/TPrint.h +21 -0
  128. package/ios/VendorFrameworks/tspl.framework/Headers/TQRCode.h +35 -0
  129. package/ios/VendorFrameworks/tspl.framework/Headers/TReadState.h +16 -0
  130. package/ios/VendorFrameworks/tspl.framework/Headers/TReverse.h +27 -0
  131. package/ios/VendorFrameworks/tspl.framework/Headers/TSN.h +19 -0
  132. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLCodeType.h +53 -0
  133. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLCorrectLevel.h +21 -0
  134. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLFont.h +83 -0
  135. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLImageMode.h +30 -0
  136. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLLineMode.h +37 -0
  137. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLLineType.h +21 -0
  138. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLOutDirection.h +27 -0
  139. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLRotation.h +36 -0
  140. package/ios/VendorFrameworks/tspl.framework/Headers/TSPLShowType.h +36 -0
  141. package/ios/VendorFrameworks/tspl.framework/Headers/TSPL_.h +18 -0
  142. package/ios/VendorFrameworks/tspl.framework/Headers/TSpeed.h +20 -0
  143. package/ios/VendorFrameworks/tspl.framework/Headers/TText.h +38 -0
  144. package/ios/VendorFrameworks/tspl.framework/Headers/TTextBox.h +44 -0
  145. package/ios/VendorFrameworks/tspl.framework/Headers/TVersion.h +19 -0
  146. package/ios/VendorFrameworks/tspl.framework/Headers/tspl.h +45 -0
  147. package/ios/VendorFrameworks/tspl.framework/Info.plist +0 -0
  148. package/ios/VendorFrameworks/tspl.framework/Modules/module.modulemap +6 -0
  149. package/ios/VendorFrameworks/tspl.framework/tspl +0 -0
  150. package/package.json +95 -0
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 插件内部约定的连接通道类型。
3
+ */
4
+ export type PrinterTransport = 'classic' | 'ble';
5
+ /**
6
+ * 打印负载的协议类型。
7
+ */
8
+ export type PrinterLanguage = 'tspl' | 'cpcl' | 'raw';
9
+ /**
10
+ * 统一连接状态枚举。
11
+ */
12
+ export type PrinterConnectionState = 'disconnected' | 'connecting' | 'connected';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { ConnectOptions, DiscoverDevicesOptions, LabelPrinterPlugin, PrintOptions, PrinterPermissionResult, PrinterStatus } from './definitions';
3
+ import type { PrinterConnectionState } from './types';
4
+ export declare class LabelPrinterWeb extends WebPlugin implements LabelPrinterPlugin {
5
+ isSupported(): Promise<{
6
+ supported: boolean;
7
+ }>;
8
+ checkPermissions(): Promise<PrinterPermissionResult>;
9
+ ensurePermissions(): Promise<PrinterPermissionResult>;
10
+ discoverDevices(_options?: DiscoverDevicesOptions): Promise<{
11
+ devices: [];
12
+ }>;
13
+ connect(_options: ConnectOptions): Promise<void>;
14
+ disconnect(): Promise<void>;
15
+ getConnectionState(): Promise<{
16
+ state: PrinterConnectionState;
17
+ }>;
18
+ print(_options: PrintOptions): Promise<void>;
19
+ getStatus(): Promise<PrinterStatus>;
20
+ openAppSettings(): Promise<void>;
21
+ }
@@ -0,0 +1,34 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import { UNSUPPORTED_WEB_ERROR } from './errors';
3
+ export class LabelPrinterWeb extends WebPlugin {
4
+ async isSupported() {
5
+ return { supported: false };
6
+ }
7
+ async checkPermissions() {
8
+ throw new Error(UNSUPPORTED_WEB_ERROR);
9
+ }
10
+ async ensurePermissions() {
11
+ throw new Error(UNSUPPORTED_WEB_ERROR);
12
+ }
13
+ async discoverDevices(_options) {
14
+ throw new Error(UNSUPPORTED_WEB_ERROR);
15
+ }
16
+ async connect(_options) {
17
+ throw new Error(UNSUPPORTED_WEB_ERROR);
18
+ }
19
+ async disconnect() {
20
+ throw new Error(UNSUPPORTED_WEB_ERROR);
21
+ }
22
+ async getConnectionState() {
23
+ return { state: 'disconnected' };
24
+ }
25
+ async print(_options) {
26
+ throw new Error(UNSUPPORTED_WEB_ERROR);
27
+ }
28
+ async getStatus() {
29
+ return { connected: false, message: UNSUPPORTED_WEB_ERROR };
30
+ }
31
+ async openAppSettings() {
32
+ throw new Error(UNSUPPORTED_WEB_ERROR);
33
+ }
34
+ }
@@ -0,0 +1,143 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const UNSUPPORTED_WEB_ERROR = 'Label printing is not supported on web.';
6
+
7
+ function escapeCpclText(value) {
8
+ return value.replace(/[\r\n]+/g, ' ').trim();
9
+ }
10
+ class CpclBuilder {
11
+ constructor() {
12
+ this.lines = [];
13
+ }
14
+ page(height, copies = 1, offset = 0, horizontalDpi = 200, verticalDpi = 200) {
15
+ this.lines.push(`! ${offset} ${horizontalDpi} ${verticalDpi} ${height} ${copies}`);
16
+ return this;
17
+ }
18
+ pageWidth(width) {
19
+ this.lines.push(`PAGE-WIDTH ${width}`);
20
+ return this;
21
+ }
22
+ text(font, rotation, x, y, value) {
23
+ this.lines.push(`TEXT ${font} ${rotation} ${x} ${y} ${escapeCpclText(value)}`);
24
+ return this;
25
+ }
26
+ barcode128(x, y, height, value, narrow = 1, wide = 1) {
27
+ this.lines.push(`BARCODE 128 ${narrow} ${wide} ${height} ${x} ${y} ${escapeCpclText(value)}`);
28
+ return this;
29
+ }
30
+ form() {
31
+ this.lines.push('FORM');
32
+ return this;
33
+ }
34
+ print() {
35
+ this.lines.push('PRINT');
36
+ return this;
37
+ }
38
+ build() {
39
+ return `${this.lines.join('\n')}\n`;
40
+ }
41
+ }
42
+
43
+ function mmToDots(mm, dpi = 203) {
44
+ return Math.round((mm / 25.4) * dpi);
45
+ }
46
+ function escapeTsplText(value) {
47
+ return value.replace(/"/g, '\\"');
48
+ }
49
+
50
+ class TsplBuilder {
51
+ constructor() {
52
+ this.lines = [];
53
+ }
54
+ sizeMm(width, height) {
55
+ this.lines.push(`SIZE ${width} mm,${height} mm`);
56
+ return this;
57
+ }
58
+ gapMm(gap, offset) {
59
+ this.lines.push(`GAP ${gap} mm,${offset} mm`);
60
+ return this;
61
+ }
62
+ density(level) {
63
+ this.lines.push(`DENSITY ${level}`);
64
+ return this;
65
+ }
66
+ speed(level) {
67
+ this.lines.push(`SPEED ${level}`);
68
+ return this;
69
+ }
70
+ cls() {
71
+ this.lines.push('CLS');
72
+ return this;
73
+ }
74
+ text(x, y, font, rotation, xScale, yScale, value) {
75
+ this.lines.push(`TEXT ${x},${y},"${font}",${rotation},${xScale},${yScale},"${escapeTsplText(value)}"`);
76
+ return this;
77
+ }
78
+ barcode128(x, y, height, value) {
79
+ this.lines.push(`BARCODE ${x},${y},"128",${height},1,0,2,2,"${escapeTsplText(value)}"`);
80
+ return this;
81
+ }
82
+ qrcode(x, y, cellWidth, value) {
83
+ this.lines.push(`QRCODE ${x},${y},L,${cellWidth},A,0,"${escapeTsplText(value)}"`);
84
+ return this;
85
+ }
86
+ printCopies(copies) {
87
+ this.lines.push(`PRINT 1,${copies}`);
88
+ return this;
89
+ }
90
+ build() {
91
+ return `${this.lines.join('\n')}\n`;
92
+ }
93
+ }
94
+
95
+ const LabelPrinter = core.registerPlugin('LabelPrinter', {
96
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.LabelPrinterWeb())
97
+ });
98
+
99
+ class LabelPrinterWeb extends core.WebPlugin {
100
+ async isSupported() {
101
+ return { supported: false };
102
+ }
103
+ async checkPermissions() {
104
+ throw new Error(UNSUPPORTED_WEB_ERROR);
105
+ }
106
+ async ensurePermissions() {
107
+ throw new Error(UNSUPPORTED_WEB_ERROR);
108
+ }
109
+ async discoverDevices(_options) {
110
+ throw new Error(UNSUPPORTED_WEB_ERROR);
111
+ }
112
+ async connect(_options) {
113
+ throw new Error(UNSUPPORTED_WEB_ERROR);
114
+ }
115
+ async disconnect() {
116
+ throw new Error(UNSUPPORTED_WEB_ERROR);
117
+ }
118
+ async getConnectionState() {
119
+ return { state: 'disconnected' };
120
+ }
121
+ async print(_options) {
122
+ throw new Error(UNSUPPORTED_WEB_ERROR);
123
+ }
124
+ async getStatus() {
125
+ return { connected: false, message: UNSUPPORTED_WEB_ERROR };
126
+ }
127
+ async openAppSettings() {
128
+ throw new Error(UNSUPPORTED_WEB_ERROR);
129
+ }
130
+ }
131
+
132
+ var web = /*#__PURE__*/Object.freeze({
133
+ __proto__: null,
134
+ LabelPrinterWeb: LabelPrinterWeb
135
+ });
136
+
137
+ exports.CpclBuilder = CpclBuilder;
138
+ exports.LabelPrinter = LabelPrinter;
139
+ exports.TsplBuilder = TsplBuilder;
140
+ exports.UNSUPPORTED_WEB_ERROR = UNSUPPORTED_WEB_ERROR;
141
+ exports.escapeTsplText = escapeTsplText;
142
+ exports.mmToDots = mmToDots;
143
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/errors.js","esm/cpcl/builder.js","esm/tspl/helpers.js","esm/tspl/builder.js","esm/index.js","esm/web.js"],"sourcesContent":["export const UNSUPPORTED_WEB_ERROR = 'Label printing is not supported on web.';\n","function escapeCpclText(value) {\n return value.replace(/[\\r\\n]+/g, ' ').trim();\n}\nexport class CpclBuilder {\n constructor() {\n this.lines = [];\n }\n page(height, copies = 1, offset = 0, horizontalDpi = 200, verticalDpi = 200) {\n this.lines.push(`! ${offset} ${horizontalDpi} ${verticalDpi} ${height} ${copies}`);\n return this;\n }\n pageWidth(width) {\n this.lines.push(`PAGE-WIDTH ${width}`);\n return this;\n }\n text(font, rotation, x, y, value) {\n this.lines.push(`TEXT ${font} ${rotation} ${x} ${y} ${escapeCpclText(value)}`);\n return this;\n }\n barcode128(x, y, height, value, narrow = 1, wide = 1) {\n this.lines.push(`BARCODE 128 ${narrow} ${wide} ${height} ${x} ${y} ${escapeCpclText(value)}`);\n return this;\n }\n form() {\n this.lines.push('FORM');\n return this;\n }\n print() {\n this.lines.push('PRINT');\n return this;\n }\n build() {\n return `${this.lines.join('\\n')}\\n`;\n }\n}\n","export function mmToDots(mm, dpi = 203) {\n return Math.round((mm / 25.4) * dpi);\n}\nexport function escapeTsplText(value) {\n return value.replace(/\"/g, '\\\\\"');\n}\n","import { escapeTsplText } from './helpers';\nexport class TsplBuilder {\n constructor() {\n this.lines = [];\n }\n sizeMm(width, height) {\n this.lines.push(`SIZE ${width} mm,${height} mm`);\n return this;\n }\n gapMm(gap, offset) {\n this.lines.push(`GAP ${gap} mm,${offset} mm`);\n return this;\n }\n density(level) {\n this.lines.push(`DENSITY ${level}`);\n return this;\n }\n speed(level) {\n this.lines.push(`SPEED ${level}`);\n return this;\n }\n cls() {\n this.lines.push('CLS');\n return this;\n }\n text(x, y, font, rotation, xScale, yScale, value) {\n this.lines.push(`TEXT ${x},${y},\"${font}\",${rotation},${xScale},${yScale},\"${escapeTsplText(value)}\"`);\n return this;\n }\n barcode128(x, y, height, value) {\n this.lines.push(`BARCODE ${x},${y},\"128\",${height},1,0,2,2,\"${escapeTsplText(value)}\"`);\n return this;\n }\n qrcode(x, y, cellWidth, value) {\n this.lines.push(`QRCODE ${x},${y},L,${cellWidth},A,0,\"${escapeTsplText(value)}\"`);\n return this;\n }\n printCopies(copies) {\n this.lines.push(`PRINT 1,${copies}`);\n return this;\n }\n build() {\n return `${this.lines.join('\\n')}\\n`;\n }\n}\n","import { registerPlugin } from '@capacitor/core';\nconst LabelPrinter = registerPlugin('LabelPrinter', {\n web: () => import('./web').then(m => new m.LabelPrinterWeb())\n});\nexport * from './definitions';\nexport * from './errors';\nexport * from './types';\nexport * from './cpcl/builder';\nexport * from './tspl/builder';\nexport * from './tspl/helpers';\nexport { LabelPrinter };\n","import { WebPlugin } from '@capacitor/core';\nimport { UNSUPPORTED_WEB_ERROR } from './errors';\nexport class LabelPrinterWeb extends WebPlugin {\n async isSupported() {\n return { supported: false };\n }\n async checkPermissions() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async ensurePermissions() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async discoverDevices(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async connect(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async disconnect() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async getConnectionState() {\n return { state: 'disconnected' };\n }\n async print(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async getStatus() {\n return { connected: false, message: UNSUPPORTED_WEB_ERROR };\n }\n async openAppSettings() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n}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,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,eAAe,CAAC,QAAQ,EAAE;AACpC,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,OAAO,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE;AACxC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE;AACnE,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ;;;;;;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,136 @@
1
+ import { registerPlugin, WebPlugin } from '@capacitor/core';
2
+
3
+ const UNSUPPORTED_WEB_ERROR = 'Label printing is not supported on web.';
4
+
5
+ function escapeCpclText(value) {
6
+ return value.replace(/[\r\n]+/g, ' ').trim();
7
+ }
8
+ class CpclBuilder {
9
+ constructor() {
10
+ this.lines = [];
11
+ }
12
+ page(height, copies = 1, offset = 0, horizontalDpi = 200, verticalDpi = 200) {
13
+ this.lines.push(`! ${offset} ${horizontalDpi} ${verticalDpi} ${height} ${copies}`);
14
+ return this;
15
+ }
16
+ pageWidth(width) {
17
+ this.lines.push(`PAGE-WIDTH ${width}`);
18
+ return this;
19
+ }
20
+ text(font, rotation, x, y, value) {
21
+ this.lines.push(`TEXT ${font} ${rotation} ${x} ${y} ${escapeCpclText(value)}`);
22
+ return this;
23
+ }
24
+ barcode128(x, y, height, value, narrow = 1, wide = 1) {
25
+ this.lines.push(`BARCODE 128 ${narrow} ${wide} ${height} ${x} ${y} ${escapeCpclText(value)}`);
26
+ return this;
27
+ }
28
+ form() {
29
+ this.lines.push('FORM');
30
+ return this;
31
+ }
32
+ print() {
33
+ this.lines.push('PRINT');
34
+ return this;
35
+ }
36
+ build() {
37
+ return `${this.lines.join('\n')}\n`;
38
+ }
39
+ }
40
+
41
+ function mmToDots(mm, dpi = 203) {
42
+ return Math.round((mm / 25.4) * dpi);
43
+ }
44
+ function escapeTsplText(value) {
45
+ return value.replace(/"/g, '\\"');
46
+ }
47
+
48
+ class TsplBuilder {
49
+ constructor() {
50
+ this.lines = [];
51
+ }
52
+ sizeMm(width, height) {
53
+ this.lines.push(`SIZE ${width} mm,${height} mm`);
54
+ return this;
55
+ }
56
+ gapMm(gap, offset) {
57
+ this.lines.push(`GAP ${gap} mm,${offset} mm`);
58
+ return this;
59
+ }
60
+ density(level) {
61
+ this.lines.push(`DENSITY ${level}`);
62
+ return this;
63
+ }
64
+ speed(level) {
65
+ this.lines.push(`SPEED ${level}`);
66
+ return this;
67
+ }
68
+ cls() {
69
+ this.lines.push('CLS');
70
+ return this;
71
+ }
72
+ text(x, y, font, rotation, xScale, yScale, value) {
73
+ this.lines.push(`TEXT ${x},${y},"${font}",${rotation},${xScale},${yScale},"${escapeTsplText(value)}"`);
74
+ return this;
75
+ }
76
+ barcode128(x, y, height, value) {
77
+ this.lines.push(`BARCODE ${x},${y},"128",${height},1,0,2,2,"${escapeTsplText(value)}"`);
78
+ return this;
79
+ }
80
+ qrcode(x, y, cellWidth, value) {
81
+ this.lines.push(`QRCODE ${x},${y},L,${cellWidth},A,0,"${escapeTsplText(value)}"`);
82
+ return this;
83
+ }
84
+ printCopies(copies) {
85
+ this.lines.push(`PRINT 1,${copies}`);
86
+ return this;
87
+ }
88
+ build() {
89
+ return `${this.lines.join('\n')}\n`;
90
+ }
91
+ }
92
+
93
+ const LabelPrinter = registerPlugin('LabelPrinter', {
94
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.LabelPrinterWeb())
95
+ });
96
+
97
+ class LabelPrinterWeb extends WebPlugin {
98
+ async isSupported() {
99
+ return { supported: false };
100
+ }
101
+ async checkPermissions() {
102
+ throw new Error(UNSUPPORTED_WEB_ERROR);
103
+ }
104
+ async ensurePermissions() {
105
+ throw new Error(UNSUPPORTED_WEB_ERROR);
106
+ }
107
+ async discoverDevices(_options) {
108
+ throw new Error(UNSUPPORTED_WEB_ERROR);
109
+ }
110
+ async connect(_options) {
111
+ throw new Error(UNSUPPORTED_WEB_ERROR);
112
+ }
113
+ async disconnect() {
114
+ throw new Error(UNSUPPORTED_WEB_ERROR);
115
+ }
116
+ async getConnectionState() {
117
+ return { state: 'disconnected' };
118
+ }
119
+ async print(_options) {
120
+ throw new Error(UNSUPPORTED_WEB_ERROR);
121
+ }
122
+ async getStatus() {
123
+ return { connected: false, message: UNSUPPORTED_WEB_ERROR };
124
+ }
125
+ async openAppSettings() {
126
+ throw new Error(UNSUPPORTED_WEB_ERROR);
127
+ }
128
+ }
129
+
130
+ var web = /*#__PURE__*/Object.freeze({
131
+ __proto__: null,
132
+ LabelPrinterWeb: LabelPrinterWeb
133
+ });
134
+
135
+ export { CpclBuilder, LabelPrinter, TsplBuilder, UNSUPPORTED_WEB_ERROR, escapeTsplText, mmToDots };
136
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/errors.js","esm/cpcl/builder.js","esm/tspl/helpers.js","esm/tspl/builder.js","esm/index.js","esm/web.js"],"sourcesContent":["export const UNSUPPORTED_WEB_ERROR = 'Label printing is not supported on web.';\n","function escapeCpclText(value) {\n return value.replace(/[\\r\\n]+/g, ' ').trim();\n}\nexport class CpclBuilder {\n constructor() {\n this.lines = [];\n }\n page(height, copies = 1, offset = 0, horizontalDpi = 200, verticalDpi = 200) {\n this.lines.push(`! ${offset} ${horizontalDpi} ${verticalDpi} ${height} ${copies}`);\n return this;\n }\n pageWidth(width) {\n this.lines.push(`PAGE-WIDTH ${width}`);\n return this;\n }\n text(font, rotation, x, y, value) {\n this.lines.push(`TEXT ${font} ${rotation} ${x} ${y} ${escapeCpclText(value)}`);\n return this;\n }\n barcode128(x, y, height, value, narrow = 1, wide = 1) {\n this.lines.push(`BARCODE 128 ${narrow} ${wide} ${height} ${x} ${y} ${escapeCpclText(value)}`);\n return this;\n }\n form() {\n this.lines.push('FORM');\n return this;\n }\n print() {\n this.lines.push('PRINT');\n return this;\n }\n build() {\n return `${this.lines.join('\\n')}\\n`;\n }\n}\n","export function mmToDots(mm, dpi = 203) {\n return Math.round((mm / 25.4) * dpi);\n}\nexport function escapeTsplText(value) {\n return value.replace(/\"/g, '\\\\\"');\n}\n","import { escapeTsplText } from './helpers';\nexport class TsplBuilder {\n constructor() {\n this.lines = [];\n }\n sizeMm(width, height) {\n this.lines.push(`SIZE ${width} mm,${height} mm`);\n return this;\n }\n gapMm(gap, offset) {\n this.lines.push(`GAP ${gap} mm,${offset} mm`);\n return this;\n }\n density(level) {\n this.lines.push(`DENSITY ${level}`);\n return this;\n }\n speed(level) {\n this.lines.push(`SPEED ${level}`);\n return this;\n }\n cls() {\n this.lines.push('CLS');\n return this;\n }\n text(x, y, font, rotation, xScale, yScale, value) {\n this.lines.push(`TEXT ${x},${y},\"${font}\",${rotation},${xScale},${yScale},\"${escapeTsplText(value)}\"`);\n return this;\n }\n barcode128(x, y, height, value) {\n this.lines.push(`BARCODE ${x},${y},\"128\",${height},1,0,2,2,\"${escapeTsplText(value)}\"`);\n return this;\n }\n qrcode(x, y, cellWidth, value) {\n this.lines.push(`QRCODE ${x},${y},L,${cellWidth},A,0,\"${escapeTsplText(value)}\"`);\n return this;\n }\n printCopies(copies) {\n this.lines.push(`PRINT 1,${copies}`);\n return this;\n }\n build() {\n return `${this.lines.join('\\n')}\\n`;\n }\n}\n","import { registerPlugin } from '@capacitor/core';\nconst LabelPrinter = registerPlugin('LabelPrinter', {\n web: () => import('./web').then(m => new m.LabelPrinterWeb())\n});\nexport * from './definitions';\nexport * from './errors';\nexport * from './types';\nexport * from './cpcl/builder';\nexport * from './tspl/builder';\nexport * from './tspl/helpers';\nexport { LabelPrinter };\n","import { WebPlugin } from '@capacitor/core';\nimport { UNSUPPORTED_WEB_ERROR } from './errors';\nexport class LabelPrinterWeb extends WebPlugin {\n async isSupported() {\n return { supported: false };\n }\n async checkPermissions() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async ensurePermissions() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async discoverDevices(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async connect(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async disconnect() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async getConnectionState() {\n return { state: 'disconnected' };\n }\n async print(_options) {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n async getStatus() {\n return { connected: false, message: UNSUPPORTED_WEB_ERROR };\n }\n async openAppSettings() {\n throw new Error(UNSUPPORTED_WEB_ERROR);\n }\n}\n"],"names":[],"mappings":";;AAAY,MAAC,qBAAqB,GAAG;;ACArC,SAAS,cAAc,CAAC,KAAK,EAAE;AAC/B,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE;AAChD;AACO,MAAM,WAAW,CAAC;AACzB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,KAAK,GAAG,EAAE;AACvB,IAAI;AACJ,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,aAAa,GAAG,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE;AACjF,QAAQ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AACJ,IAAI,MAAM,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE;AACnE,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;AAC9C,IAAI;AACJ;;;;;;;;;"}
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,230 @@
1
+ import Foundation
2
+ import CoreBluetooth
3
+ import adapter
4
+ import appleble
5
+
6
+ final class IOSPrinterManager: NSObject {
7
+ private let printer = AppleBle()
8
+ private let mapper = IOSStatusMapper()
9
+
10
+ private var discoveredPeripherals: [String: CBPeripheral] = [:]
11
+ private var discoveredRSSI: [String: NSNumber] = [:]
12
+ private var discoveryPrefixes: [String] = []
13
+ private var discoverySemaphore: DispatchSemaphore?
14
+ private var connectSemaphore: DispatchSemaphore?
15
+ private var connectErrorMessage: String?
16
+ private var currentPeripheral: CBPeripheral?
17
+ private(set) var connected = false
18
+ private(set) var currentDeviceId: String?
19
+ private var lastStatusCode: Int?
20
+ private var lastMessage = "disconnected"
21
+ private var lastRawMessage: String?
22
+
23
+ override init() {
24
+ super.init()
25
+ printer.delegate = self
26
+ }
27
+
28
+ func discoverDevices(namePrefixes: [String], timeoutMs: Double) -> [[String: Any]] {
29
+ discoveryPrefixes = namePrefixes
30
+ discoveredPeripherals.removeAll()
31
+ discoveredRSSI.removeAll()
32
+
33
+ let semaphore = DispatchSemaphore(value: 0)
34
+ discoverySemaphore = semaphore
35
+ printer.startScanPrinters()
36
+
37
+ let timeoutSeconds = max(timeoutMs, 500) / 1000
38
+ DispatchQueue.global().asyncAfter(deadline: .now() + timeoutSeconds) { [weak self] in
39
+ self?.printer.stopScanPrinters()
40
+ self?.discoverySemaphore?.signal()
41
+ }
42
+ _ = semaphore.wait(timeout: .now() + timeoutSeconds + 1)
43
+
44
+ return discoveredPeripherals.keys.sorted().compactMap { deviceId in
45
+ guard let peripheral = discoveredPeripherals[deviceId] else {
46
+ return nil
47
+ }
48
+
49
+ var item: [String: Any] = [
50
+ "id": deviceId,
51
+ "name": peripheral.name ?? "Unknown BLE Printer",
52
+ "transport": "ble"
53
+ ]
54
+
55
+ if let rssi = discoveredRSSI[deviceId] {
56
+ item["rssi"] = rssi.intValue
57
+ }
58
+
59
+ return item
60
+ }
61
+ }
62
+
63
+ func connect(deviceId: String) throws {
64
+ guard let peripheral = discoveredPeripherals[deviceId] ?? currentPeripheral, peripheral.identifier.uuidString == deviceId else {
65
+ throw NSError(
66
+ domain: "LabelPrinter",
67
+ code: 1,
68
+ userInfo: [NSLocalizedDescriptionKey: "printer device not found: \(deviceId)"]
69
+ )
70
+ }
71
+
72
+ connectErrorMessage = nil
73
+ let semaphore = DispatchSemaphore(value: 0)
74
+ connectSemaphore = semaphore
75
+ printer.connect(peripheral)
76
+
77
+ let waitResult = semaphore.wait(timeout: .now() + 10)
78
+ if waitResult == .timedOut {
79
+ throw NSError(
80
+ domain: "LabelPrinter",
81
+ code: 2,
82
+ userInfo: [NSLocalizedDescriptionKey: "printer connect timeout"]
83
+ )
84
+ }
85
+
86
+ guard connected else {
87
+ throw NSError(
88
+ domain: "LabelPrinter",
89
+ code: 3,
90
+ userInfo: [NSLocalizedDescriptionKey: connectErrorMessage ?? "printer connect failed"]
91
+ )
92
+ }
93
+
94
+ currentPeripheral = peripheral
95
+ currentDeviceId = deviceId
96
+ lastMessage = "ready"
97
+ }
98
+
99
+ func disconnect() {
100
+ printer.disconnect()
101
+ connected = false
102
+ currentPeripheral = nil
103
+ currentDeviceId = nil
104
+ lastStatusCode = nil
105
+ lastRawMessage = nil
106
+ lastMessage = "disconnected"
107
+ }
108
+
109
+ func getConnectionState() -> [String: Any] {
110
+ return ["state": connected ? "connected" : "disconnected"]
111
+ }
112
+
113
+ func getStatus() -> [String: Any] {
114
+ return mapper.toPluginStatus(
115
+ connected: connected,
116
+ statusCode: lastStatusCode,
117
+ message: lastMessage,
118
+ raw: lastRawMessage
119
+ )
120
+ }
121
+
122
+ func print(payload: String, copies: Int) throws {
123
+ if !connected {
124
+ throw NSError(
125
+ domain: "LabelPrinter",
126
+ code: 4,
127
+ userInfo: [NSLocalizedDescriptionKey: "printer is not connected"]
128
+ )
129
+ }
130
+ if payload.isEmpty || copies < 1 {
131
+ throw NSError(
132
+ domain: "LabelPrinter",
133
+ code: 5,
134
+ userInfo: [NSLocalizedDescriptionKey: "invalid print payload"]
135
+ )
136
+ }
137
+ guard let binary = payload
138
+ .replacingOccurrences(of: "\r\n", with: "\n")
139
+ .repeatString(max(copies, 1))
140
+ .data(using: .utf8) else {
141
+ throw NSError(
142
+ domain: "LabelPrinter",
143
+ code: 6,
144
+ userInfo: [NSLocalizedDescriptionKey: "unable to encode print payload"]
145
+ )
146
+ }
147
+
148
+ printer.write(binary)
149
+ }
150
+
151
+ private func shouldKeep(peripheral: CBPeripheral) -> Bool {
152
+ guard let name = peripheral.name, !name.isEmpty else {
153
+ return false
154
+ }
155
+ guard !discoveryPrefixes.isEmpty else {
156
+ return true
157
+ }
158
+ return discoveryPrefixes.contains { name.hasPrefix($0) }
159
+ }
160
+ }
161
+
162
+ extension IOSPrinterManager: AppleBleDelegate {
163
+ func bleDataReceived(_ revData: Data) {
164
+ lastRawMessage = String(data: revData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
165
+ if let lastRawMessage, !lastRawMessage.isEmpty {
166
+ lastMessage = lastRawMessage
167
+ }
168
+ }
169
+
170
+ func bleDidDiscoverDevies(_ peripheral: CBPeripheral, rssi RSSI: NSNumber?) {
171
+ guard shouldKeep(peripheral: peripheral) else {
172
+ return
173
+ }
174
+ let deviceId = peripheral.identifier.uuidString
175
+ discoveredPeripherals[deviceId] = peripheral
176
+ if let RSSI {
177
+ discoveredRSSI[deviceId] = RSSI
178
+ }
179
+ }
180
+
181
+ func bleDidConnect(_ peripheral: CBPeripheral) {
182
+ connected = true
183
+ currentPeripheral = peripheral
184
+ currentDeviceId = peripheral.identifier.uuidString
185
+ lastMessage = "ready"
186
+ connectSemaphore?.signal()
187
+ }
188
+
189
+ func bleDidFail(toConnect peripheral: CBPeripheral, error: (any Error)?) {
190
+ connected = false
191
+ connectErrorMessage = error?.localizedDescription ?? "printer connect failed"
192
+ connectSemaphore?.signal()
193
+ }
194
+
195
+ func bleDidDisconnectPeripheral(_ peripheral: CBPeripheral, error: (any Error)?) {
196
+ connected = false
197
+ currentPeripheral = nil
198
+ currentDeviceId = nil
199
+ lastMessage = "disconnected"
200
+ if let error {
201
+ connectErrorMessage = error.localizedDescription
202
+ }
203
+ connectSemaphore?.signal()
204
+ }
205
+
206
+ func bleDidFinishPrint(_ result: printResult) {
207
+ switch Int(result.rawValue) {
208
+ case 0:
209
+ lastMessage = "print success"
210
+ case 1:
211
+ lastMessage = "print failed"
212
+ default:
213
+ break
214
+ }
215
+ }
216
+
217
+ func blePrinterStatus(_ status: printStatus) {
218
+ lastStatusCode = Int(status.rawValue)
219
+ lastMessage = mapper.message(for: Int(status.rawValue))
220
+ }
221
+ }
222
+
223
+ private extension String {
224
+ func repeatString(_ count: Int) -> String {
225
+ guard count > 1 else {
226
+ return self
227
+ }
228
+ return String(repeating: self, count: count)
229
+ }
230
+ }
@@ -0,0 +1,57 @@
1
+ import Foundation
2
+
3
+ struct IOSStatusMapper {
4
+ func toPluginStatus(connected: Bool, statusCode: Int?, message: String, raw: String?) -> [String: Any] {
5
+ var status: [String: Any] = [
6
+ "connected": connected,
7
+ "ready": connected,
8
+ "paperOut": false,
9
+ "coverOpen": false,
10
+ "overheating": false,
11
+ "message": message
12
+ ]
13
+
14
+ if let raw {
15
+ status["raw"] = raw
16
+ } else if let statusCode {
17
+ status["raw"] = statusCode
18
+ }
19
+
20
+ guard connected, let statusCode else {
21
+ return status
22
+ }
23
+
24
+ switch statusCode {
25
+ case 0:
26
+ status["ready"] = false
27
+ status["coverOpen"] = true
28
+ case 1:
29
+ status["ready"] = false
30
+ status["paperOut"] = true
31
+ case 2:
32
+ status["ready"] = false
33
+ status["overheating"] = true
34
+ default:
35
+ break
36
+ }
37
+
38
+ return status
39
+ }
40
+
41
+ func message(for statusCode: Int) -> String {
42
+ switch statusCode {
43
+ case 0:
44
+ return "cover open"
45
+ case 1:
46
+ return "paper out"
47
+ case 2:
48
+ return "overheating"
49
+ case 3:
50
+ return "printing"
51
+ case 4:
52
+ return "battery low"
53
+ default:
54
+ return "ready"
55
+ }
56
+ }
57
+ }