label-printer 0.7.8 → 0.8.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.
package/dist/index.d.mts CHANGED
@@ -26,6 +26,12 @@ declare abstract class Command {
26
26
  * Returns a string representation of the command
27
27
  */
28
28
  abstract get commandString(): string;
29
+ /**
30
+ * Returns a byte array representation of the command
31
+ * By default, converts commandString to bytes, but can be overridden for commands
32
+ * that include binary data (e.g., images, fonts)
33
+ */
34
+ get commandBytes(): Uint8Array;
29
35
  print(fn: (command: string) => void): void;
30
36
  /**
31
37
  * Write the command data to a device
@@ -66,6 +72,7 @@ declare abstract class CommandGroup<T extends Command> extends Command {
66
72
  print(fn: (command: string) => void): void;
67
73
  writeTo(device: Device): Promise<void>;
68
74
  get commandString(): string;
75
+ get commandBytes(): Uint8Array;
69
76
  }
70
77
 
71
78
  /**
@@ -181,6 +188,7 @@ declare class TSPLBitmapCommand extends TSPLVisualCommand {
181
188
  get commandString(): string;
182
189
  private get commandWithoutBytes();
183
190
  private get modeValue();
191
+ get commandBytes(): Uint8Array;
184
192
  writeTo(device: Device): Promise<void>;
185
193
  /**
186
194
  * Create a new bitmap command for the given image url
@@ -366,6 +374,7 @@ declare class TSPLDownload extends TSPLCommand {
366
374
  */
367
375
  constructor(fileName: string, data: Data);
368
376
  get commandString(): string;
377
+ get commandBytes(): Uint8Array;
369
378
  writeTo(device: Device): Promise<void>;
370
379
  }
371
380
 
package/dist/index.d.ts CHANGED
@@ -26,6 +26,12 @@ declare abstract class Command {
26
26
  * Returns a string representation of the command
27
27
  */
28
28
  abstract get commandString(): string;
29
+ /**
30
+ * Returns a byte array representation of the command
31
+ * By default, converts commandString to bytes, but can be overridden for commands
32
+ * that include binary data (e.g., images, fonts)
33
+ */
34
+ get commandBytes(): Uint8Array;
29
35
  print(fn: (command: string) => void): void;
30
36
  /**
31
37
  * Write the command data to a device
@@ -66,6 +72,7 @@ declare abstract class CommandGroup<T extends Command> extends Command {
66
72
  print(fn: (command: string) => void): void;
67
73
  writeTo(device: Device): Promise<void>;
68
74
  get commandString(): string;
75
+ get commandBytes(): Uint8Array;
69
76
  }
70
77
 
71
78
  /**
@@ -181,6 +188,7 @@ declare class TSPLBitmapCommand extends TSPLVisualCommand {
181
188
  get commandString(): string;
182
189
  private get commandWithoutBytes();
183
190
  private get modeValue();
191
+ get commandBytes(): Uint8Array;
184
192
  writeTo(device: Device): Promise<void>;
185
193
  /**
186
194
  * Create a new bitmap command for the given image url
@@ -366,6 +374,7 @@ declare class TSPLDownload extends TSPLCommand {
366
374
  */
367
375
  constructor(fileName: string, data: Data);
368
376
  get commandString(): string;
377
+ get commandBytes(): Uint8Array;
369
378
  writeTo(device: Device): Promise<void>;
370
379
  }
371
380
 
package/dist/index.js CHANGED
@@ -83,6 +83,20 @@ __export(commands_exports, {
83
83
 
84
84
  // src/commands/Command.ts
85
85
  var Command = class {
86
+ /**
87
+ * Returns a byte array representation of the command
88
+ * By default, converts commandString to bytes, but can be overridden for commands
89
+ * that include binary data (e.g., images, fonts)
90
+ */
91
+ get commandBytes() {
92
+ const encoder = new TextEncoder();
93
+ const encoded = encoder.encode(this.commandString);
94
+ const terminator = this.commandTerminatorBytes;
95
+ const result = new Uint8Array(encoded.length + terminator.length);
96
+ result.set(encoded, 0);
97
+ result.set(terminator, encoded.length);
98
+ return result;
99
+ }
86
100
  print(fn) {
87
101
  fn(this.commandString);
88
102
  }
@@ -154,6 +168,20 @@ var CommandGroup = class extends Command {
154
168
  get commandString() {
155
169
  return this.commands.map((c) => c.commandString).join("\n");
156
170
  }
171
+ get commandBytes() {
172
+ if (this.commands.length === 0) {
173
+ return new Uint8Array(0);
174
+ }
175
+ const byteArrays = this.commands.map((c) => c.commandBytes);
176
+ const totalLength = byteArrays.reduce((sum, arr) => sum + arr.length, 0);
177
+ const result = new Uint8Array(totalLength);
178
+ let offset = 0;
179
+ for (const arr of byteArrays) {
180
+ result.set(arr, offset);
181
+ offset += arr.length;
182
+ }
183
+ return result;
184
+ }
157
185
  };
158
186
 
159
187
  // src/commands/tspl/index.ts
@@ -1146,6 +1174,16 @@ var TSPLBitmapCommand = class _TSPLBitmapCommand extends TSPLVisualCommand {
1146
1174
  return 2;
1147
1175
  }
1148
1176
  }
1177
+ get commandBytes() {
1178
+ const encoder = new TextEncoder();
1179
+ const commandBytes = encoder.encode(this.commandWithoutBytes);
1180
+ const terminator = this.commandTerminatorBytes;
1181
+ const result = new Uint8Array(commandBytes.length + this.bitmap.bytes.length + terminator.length);
1182
+ result.set(commandBytes, 0);
1183
+ result.set(this.bitmap.bytes, commandBytes.length);
1184
+ result.set(terminator, commandBytes.length + this.bitmap.bytes.length);
1185
+ return result;
1186
+ }
1149
1187
  writeTo(device) {
1150
1188
  return __async(this, null, function* () {
1151
1189
  yield this.writeString(this.commandWithoutBytes, device);
@@ -1327,6 +1365,17 @@ var TSPLDownload = class extends TSPLCommand {
1327
1365
  get commandString() {
1328
1366
  return `DOWNLOAD "${this.fileName}", ${this.data.byteLength},`;
1329
1367
  }
1368
+ get commandBytes() {
1369
+ const encoder = new TextEncoder();
1370
+ const commandBytes = encoder.encode(this.commandString);
1371
+ const dataBytes = this.data instanceof Uint8Array ? this.data : new Uint8Array(this.data);
1372
+ const terminator = this.commandTerminatorBytes;
1373
+ const result = new Uint8Array(commandBytes.length + dataBytes.length + terminator.length);
1374
+ result.set(commandBytes, 0);
1375
+ result.set(dataBytes, commandBytes.length);
1376
+ result.set(terminator, commandBytes.length + dataBytes.length);
1377
+ return result;
1378
+ }
1330
1379
  writeTo(device) {
1331
1380
  return __async(this, null, function* () {
1332
1381
  yield this.writeString(this.commandString, device);
@@ -2007,6 +2056,7 @@ var TSPLPrinter = class _TSPLPrinter extends Printer {
2007
2056
  static try(device) {
2008
2057
  return __async(this, null, function* () {
2009
2058
  if (!device.opened) yield device.openAndConfigure();
2059
+ console.log("Response: ", device.opened);
2010
2060
  const testCommand = new TSPLRawCommand("~!I");
2011
2061
  yield testCommand.writeTo(device);
2012
2062
  const response = yield device.readString(64);