label-printer 0.8.0 → 0.9.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/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -854,6 +854,13 @@ declare abstract class Printer {
|
|
|
854
854
|
* @param text String to send to the printer
|
|
855
855
|
*/
|
|
856
856
|
writeRawString(text: string): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Writes raw bytes to the printer. Useful when bytes were built elsewhere
|
|
859
|
+
* (e.g. via Command.commandBytes) and transferred over the network to a service
|
|
860
|
+
* that is responsible for the physical printing.
|
|
861
|
+
* @param data Bytes to send to the printer
|
|
862
|
+
*/
|
|
863
|
+
writeRawBytes(data: Uint8Array | ArrayBuffer): Promise<void>;
|
|
857
864
|
/**
|
|
858
865
|
* Check if the device is indeed a printer
|
|
859
866
|
* @param device
|
package/dist/index.d.ts
CHANGED
|
@@ -854,6 +854,13 @@ declare abstract class Printer {
|
|
|
854
854
|
* @param text String to send to the printer
|
|
855
855
|
*/
|
|
856
856
|
writeRawString(text: string): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Writes raw bytes to the printer. Useful when bytes were built elsewhere
|
|
859
|
+
* (e.g. via Command.commandBytes) and transferred over the network to a service
|
|
860
|
+
* that is responsible for the physical printing.
|
|
861
|
+
* @param data Bytes to send to the printer
|
|
862
|
+
*/
|
|
863
|
+
writeRawBytes(data: Uint8Array | ArrayBuffer): Promise<void>;
|
|
857
864
|
/**
|
|
858
865
|
* Check if the device is indeed a printer
|
|
859
866
|
* @param device
|
package/dist/index.js
CHANGED
|
@@ -90,7 +90,12 @@ var Command = class {
|
|
|
90
90
|
*/
|
|
91
91
|
get commandBytes() {
|
|
92
92
|
const encoder = new TextEncoder();
|
|
93
|
-
|
|
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;
|
|
94
99
|
}
|
|
95
100
|
print(fn) {
|
|
96
101
|
fn(this.commandString);
|
|
@@ -167,14 +172,7 @@ var CommandGroup = class extends Command {
|
|
|
167
172
|
if (this.commands.length === 0) {
|
|
168
173
|
return new Uint8Array(0);
|
|
169
174
|
}
|
|
170
|
-
const
|
|
171
|
-
const byteArrays = [];
|
|
172
|
-
for (let i = 0; i < this.commands.length; i++) {
|
|
173
|
-
byteArrays.push(this.commands[i].commandBytes);
|
|
174
|
-
if (i < this.commands.length - 1) {
|
|
175
|
-
byteArrays.push(newlineBytes);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
175
|
+
const byteArrays = this.commands.map((c) => c.commandBytes);
|
|
178
176
|
const totalLength = byteArrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
179
177
|
const result = new Uint8Array(totalLength);
|
|
180
178
|
let offset = 0;
|
|
@@ -1179,9 +1177,11 @@ var TSPLBitmapCommand = class _TSPLBitmapCommand extends TSPLVisualCommand {
|
|
|
1179
1177
|
get commandBytes() {
|
|
1180
1178
|
const encoder = new TextEncoder();
|
|
1181
1179
|
const commandBytes = encoder.encode(this.commandWithoutBytes);
|
|
1182
|
-
const
|
|
1180
|
+
const terminator = this.commandTerminatorBytes;
|
|
1181
|
+
const result = new Uint8Array(commandBytes.length + this.bitmap.bytes.length + terminator.length);
|
|
1183
1182
|
result.set(commandBytes, 0);
|
|
1184
1183
|
result.set(this.bitmap.bytes, commandBytes.length);
|
|
1184
|
+
result.set(terminator, commandBytes.length + this.bitmap.bytes.length);
|
|
1185
1185
|
return result;
|
|
1186
1186
|
}
|
|
1187
1187
|
writeTo(device) {
|
|
@@ -1369,9 +1369,11 @@ var TSPLDownload = class extends TSPLCommand {
|
|
|
1369
1369
|
const encoder = new TextEncoder();
|
|
1370
1370
|
const commandBytes = encoder.encode(this.commandString);
|
|
1371
1371
|
const dataBytes = this.data instanceof Uint8Array ? this.data : new Uint8Array(this.data);
|
|
1372
|
-
const
|
|
1372
|
+
const terminator = this.commandTerminatorBytes;
|
|
1373
|
+
const result = new Uint8Array(commandBytes.length + dataBytes.length + terminator.length);
|
|
1373
1374
|
result.set(commandBytes, 0);
|
|
1374
1375
|
result.set(dataBytes, commandBytes.length);
|
|
1376
|
+
result.set(terminator, commandBytes.length + dataBytes.length);
|
|
1375
1377
|
return result;
|
|
1376
1378
|
}
|
|
1377
1379
|
writeTo(device) {
|
|
@@ -1608,6 +1610,18 @@ var Printer = class {
|
|
|
1608
1610
|
yield this.device.writeString(text);
|
|
1609
1611
|
});
|
|
1610
1612
|
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Writes raw bytes to the printer. Useful when bytes were built elsewhere
|
|
1615
|
+
* (e.g. via Command.commandBytes) and transferred over the network to a service
|
|
1616
|
+
* that is responsible for the physical printing.
|
|
1617
|
+
* @param data Bytes to send to the printer
|
|
1618
|
+
*/
|
|
1619
|
+
writeRawBytes(data) {
|
|
1620
|
+
return __async(this, null, function* () {
|
|
1621
|
+
if (!this.device.opened) yield this.device.openAndConfigure();
|
|
1622
|
+
yield this.device.writeData(data);
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1611
1625
|
/**
|
|
1612
1626
|
* Check if the device is indeed a printer
|
|
1613
1627
|
* @param device
|
|
@@ -2054,6 +2068,7 @@ var TSPLPrinter = class _TSPLPrinter extends Printer {
|
|
|
2054
2068
|
static try(device) {
|
|
2055
2069
|
return __async(this, null, function* () {
|
|
2056
2070
|
if (!device.opened) yield device.openAndConfigure();
|
|
2071
|
+
console.log("Response: ", device.opened);
|
|
2057
2072
|
const testCommand = new TSPLRawCommand("~!I");
|
|
2058
2073
|
yield testCommand.writeTo(device);
|
|
2059
2074
|
const response = yield device.readString(64);
|