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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -58,6 +58,20 @@ __export(commands_exports, {
|
|
|
58
58
|
|
|
59
59
|
// src/commands/Command.ts
|
|
60
60
|
var Command = class {
|
|
61
|
+
/**
|
|
62
|
+
* Returns a byte array representation of the command
|
|
63
|
+
* By default, converts commandString to bytes, but can be overridden for commands
|
|
64
|
+
* that include binary data (e.g., images, fonts)
|
|
65
|
+
*/
|
|
66
|
+
get commandBytes() {
|
|
67
|
+
const encoder = new TextEncoder();
|
|
68
|
+
const encoded = encoder.encode(this.commandString);
|
|
69
|
+
const terminator = this.commandTerminatorBytes;
|
|
70
|
+
const result = new Uint8Array(encoded.length + terminator.length);
|
|
71
|
+
result.set(encoded, 0);
|
|
72
|
+
result.set(terminator, encoded.length);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
61
75
|
print(fn) {
|
|
62
76
|
fn(this.commandString);
|
|
63
77
|
}
|
|
@@ -129,6 +143,20 @@ var CommandGroup = class extends Command {
|
|
|
129
143
|
get commandString() {
|
|
130
144
|
return this.commands.map((c) => c.commandString).join("\n");
|
|
131
145
|
}
|
|
146
|
+
get commandBytes() {
|
|
147
|
+
if (this.commands.length === 0) {
|
|
148
|
+
return new Uint8Array(0);
|
|
149
|
+
}
|
|
150
|
+
const byteArrays = this.commands.map((c) => c.commandBytes);
|
|
151
|
+
const totalLength = byteArrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
152
|
+
const result = new Uint8Array(totalLength);
|
|
153
|
+
let offset = 0;
|
|
154
|
+
for (const arr of byteArrays) {
|
|
155
|
+
result.set(arr, offset);
|
|
156
|
+
offset += arr.length;
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
132
160
|
};
|
|
133
161
|
|
|
134
162
|
// src/commands/tspl/index.ts
|
|
@@ -1121,6 +1149,16 @@ var TSPLBitmapCommand = class _TSPLBitmapCommand extends TSPLVisualCommand {
|
|
|
1121
1149
|
return 2;
|
|
1122
1150
|
}
|
|
1123
1151
|
}
|
|
1152
|
+
get commandBytes() {
|
|
1153
|
+
const encoder = new TextEncoder();
|
|
1154
|
+
const commandBytes = encoder.encode(this.commandWithoutBytes);
|
|
1155
|
+
const terminator = this.commandTerminatorBytes;
|
|
1156
|
+
const result = new Uint8Array(commandBytes.length + this.bitmap.bytes.length + terminator.length);
|
|
1157
|
+
result.set(commandBytes, 0);
|
|
1158
|
+
result.set(this.bitmap.bytes, commandBytes.length);
|
|
1159
|
+
result.set(terminator, commandBytes.length + this.bitmap.bytes.length);
|
|
1160
|
+
return result;
|
|
1161
|
+
}
|
|
1124
1162
|
writeTo(device) {
|
|
1125
1163
|
return __async(this, null, function* () {
|
|
1126
1164
|
yield this.writeString(this.commandWithoutBytes, device);
|
|
@@ -1302,6 +1340,17 @@ var TSPLDownload = class extends TSPLCommand {
|
|
|
1302
1340
|
get commandString() {
|
|
1303
1341
|
return `DOWNLOAD "${this.fileName}", ${this.data.byteLength},`;
|
|
1304
1342
|
}
|
|
1343
|
+
get commandBytes() {
|
|
1344
|
+
const encoder = new TextEncoder();
|
|
1345
|
+
const commandBytes = encoder.encode(this.commandString);
|
|
1346
|
+
const dataBytes = this.data instanceof Uint8Array ? this.data : new Uint8Array(this.data);
|
|
1347
|
+
const terminator = this.commandTerminatorBytes;
|
|
1348
|
+
const result = new Uint8Array(commandBytes.length + dataBytes.length + terminator.length);
|
|
1349
|
+
result.set(commandBytes, 0);
|
|
1350
|
+
result.set(dataBytes, commandBytes.length);
|
|
1351
|
+
result.set(terminator, commandBytes.length + dataBytes.length);
|
|
1352
|
+
return result;
|
|
1353
|
+
}
|
|
1305
1354
|
writeTo(device) {
|
|
1306
1355
|
return __async(this, null, function* () {
|
|
1307
1356
|
yield this.writeString(this.commandString, device);
|
|
@@ -1982,6 +2031,7 @@ var TSPLPrinter = class _TSPLPrinter extends Printer {
|
|
|
1982
2031
|
static try(device) {
|
|
1983
2032
|
return __async(this, null, function* () {
|
|
1984
2033
|
if (!device.opened) yield device.openAndConfigure();
|
|
2034
|
+
console.log("Response: ", device.opened);
|
|
1985
2035
|
const testCommand = new TSPLRawCommand("~!I");
|
|
1986
2036
|
yield testCommand.writeTo(device);
|
|
1987
2037
|
const response = yield device.readString(64);
|