label-printer 0.7.8 → 0.8.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 +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,15 @@ __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
|
+
return encoder.encode(this.commandString);
|
|
94
|
+
}
|
|
86
95
|
print(fn) {
|
|
87
96
|
fn(this.commandString);
|
|
88
97
|
}
|
|
@@ -154,6 +163,27 @@ var CommandGroup = class extends Command {
|
|
|
154
163
|
get commandString() {
|
|
155
164
|
return this.commands.map((c) => c.commandString).join("\n");
|
|
156
165
|
}
|
|
166
|
+
get commandBytes() {
|
|
167
|
+
if (this.commands.length === 0) {
|
|
168
|
+
return new Uint8Array(0);
|
|
169
|
+
}
|
|
170
|
+
const newlineBytes = new Uint8Array([10]);
|
|
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
|
+
}
|
|
178
|
+
const totalLength = byteArrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
179
|
+
const result = new Uint8Array(totalLength);
|
|
180
|
+
let offset = 0;
|
|
181
|
+
for (const arr of byteArrays) {
|
|
182
|
+
result.set(arr, offset);
|
|
183
|
+
offset += arr.length;
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
157
187
|
};
|
|
158
188
|
|
|
159
189
|
// src/commands/tspl/index.ts
|
|
@@ -1146,6 +1176,14 @@ var TSPLBitmapCommand = class _TSPLBitmapCommand extends TSPLVisualCommand {
|
|
|
1146
1176
|
return 2;
|
|
1147
1177
|
}
|
|
1148
1178
|
}
|
|
1179
|
+
get commandBytes() {
|
|
1180
|
+
const encoder = new TextEncoder();
|
|
1181
|
+
const commandBytes = encoder.encode(this.commandWithoutBytes);
|
|
1182
|
+
const result = new Uint8Array(commandBytes.length + this.bitmap.bytes.length);
|
|
1183
|
+
result.set(commandBytes, 0);
|
|
1184
|
+
result.set(this.bitmap.bytes, commandBytes.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,15 @@ 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 result = new Uint8Array(commandBytes.length + dataBytes.length);
|
|
1373
|
+
result.set(commandBytes, 0);
|
|
1374
|
+
result.set(dataBytes, commandBytes.length);
|
|
1375
|
+
return result;
|
|
1376
|
+
}
|
|
1330
1377
|
writeTo(device) {
|
|
1331
1378
|
return __async(this, null, function* () {
|
|
1332
1379
|
yield this.writeString(this.commandString, device);
|