label-printer 0.2.6 → 0.3.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/README.md +15 -2
- package/dist/index.d.mts +445 -61
- package/dist/index.d.ts +445 -61
- package/dist/index.js +867 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +867 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# Label
|
|
1
|
+
# Label Printer
|
|
2
|
+
|
|
3
|
+
> :warning: `label-printer` is still under heavy development and is subject to frequent API changes
|
|
2
4
|
|
|
3
5
|
This package provides a js based implementation for variouse languages used for label printers
|
|
4
6
|
|
|
@@ -35,4 +37,15 @@ This layer contains code to interact with printers
|
|
|
35
37
|
|
|
36
38
|
## Documentation of supported languages
|
|
37
39
|
|
|
38
|
-
- [TSPL](documentations/TSPL.pdf)
|
|
40
|
+
- [TSPL](documentations/TSPL.pdf)
|
|
41
|
+
|
|
42
|
+
# Usefull units:
|
|
43
|
+
|
|
44
|
+
- 1 pt = 1/72 inch
|
|
45
|
+
- 1 dot = 1 / dpi
|
|
46
|
+
|
|
47
|
+
# Notes
|
|
48
|
+
|
|
49
|
+
- If a font is not working, make sure the extension is TTF
|
|
50
|
+
- If you want to use bold fonts, make sure you have one for weight 700
|
|
51
|
+
- Regular font weight is 400
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Font as Font$1 } from 'fontkit';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Convenience wrapper for a web usb device
|
|
3
5
|
* Its main purpose is to hide the details of the usb library from client code so in case
|
|
@@ -31,7 +33,7 @@ declare class UsbDevice {
|
|
|
31
33
|
* Write data to an USB device
|
|
32
34
|
* @param data Data to write
|
|
33
35
|
*/
|
|
34
|
-
writeData(data: Uint8Array): Promise<void>;
|
|
36
|
+
writeData(data: Uint8Array | ArrayBuffer): Promise<void>;
|
|
35
37
|
/**
|
|
36
38
|
* Writes a text to a device
|
|
37
39
|
* @param text Text to write
|
|
@@ -59,6 +61,7 @@ declare abstract class Command {
|
|
|
59
61
|
* Returns a string representation of the command
|
|
60
62
|
*/
|
|
61
63
|
abstract get commandString(): string;
|
|
64
|
+
print(fn: (command: string) => void): void;
|
|
62
65
|
/**
|
|
63
66
|
* Write the command data to a USB device
|
|
64
67
|
* @param device Device to write to
|
|
@@ -79,7 +82,7 @@ declare abstract class Command {
|
|
|
79
82
|
* @param data Byte array to send
|
|
80
83
|
* @param device Device to write to
|
|
81
84
|
*/
|
|
82
|
-
protected writeBytes(data: Uint8Array, device: UsbDevice): Promise<void>;
|
|
85
|
+
protected writeBytes(data: Uint8Array | ArrayBuffer, device: UsbDevice): Promise<void>;
|
|
83
86
|
/**
|
|
84
87
|
* Write the command terminator to the device
|
|
85
88
|
* @param device
|
|
@@ -95,6 +98,7 @@ declare abstract class Command {
|
|
|
95
98
|
declare abstract class CommandGroup<T extends Command> extends Command {
|
|
96
99
|
private commands;
|
|
97
100
|
constructor(commands: T[]);
|
|
101
|
+
print(fn: (command: string) => void): void;
|
|
98
102
|
write(device: UsbDevice): Promise<void>;
|
|
99
103
|
get commandString(): string;
|
|
100
104
|
}
|
|
@@ -105,6 +109,38 @@ declare abstract class CommandGroup<T extends Command> extends Command {
|
|
|
105
109
|
declare abstract class TSPLCommand extends Command {
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
type BitmapLike = {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
bytes: Uint8Array;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Helper type to transmit black and white bitmap data
|
|
119
|
+
*/
|
|
120
|
+
type BWBitmap = BitmapLike;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Interface that should be implemented by a command generator object for each language
|
|
124
|
+
*/
|
|
125
|
+
interface CommandGenerator<T extends Command> {
|
|
126
|
+
commandGroup: (commands: T[]) => CommandGroup<T>;
|
|
127
|
+
print: (sets: number, copiesPerSet: number) => T;
|
|
128
|
+
text: (content: string, x: number, y: number, font: string | "default", size: number) => T;
|
|
129
|
+
upload: (name: string, data: ArrayBuffer | Uint8Array) => T;
|
|
130
|
+
line: (start: Point, end: Point, thickness: number) => T;
|
|
131
|
+
image: (image: BitmapLike, x: number, y: number, mode?: GraphicMode) => T;
|
|
132
|
+
qrCode: (content: string, width: number, x: number, y: number) => T;
|
|
133
|
+
barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment) => T;
|
|
134
|
+
/**
|
|
135
|
+
* Should instruct the printer to display the image of the label on its screen instead of printing it
|
|
136
|
+
*/
|
|
137
|
+
display: () => T;
|
|
138
|
+
/**
|
|
139
|
+
* This should generate the needed commands to set up a label before printing
|
|
140
|
+
*/
|
|
141
|
+
setUp: (width: number, height: number, gap: number, offset: number, direction: LabelDirection, mirror: boolean, unitSystem: UnitSystem) => T;
|
|
142
|
+
}
|
|
143
|
+
|
|
108
144
|
/**
|
|
109
145
|
* A raw TSPL command. Can be used to use a command that is not yet supported
|
|
110
146
|
*/
|
|
@@ -136,15 +172,6 @@ declare abstract class TSPLVisualCommand extends TSPLCommand {
|
|
|
136
172
|
constructor(x: number, y: number);
|
|
137
173
|
}
|
|
138
174
|
|
|
139
|
-
/**
|
|
140
|
-
* Helper type to transmit black and white bitmap data
|
|
141
|
-
*/
|
|
142
|
-
type BWBitmap = {
|
|
143
|
-
width: number;
|
|
144
|
-
height: number;
|
|
145
|
-
bytes: Uint8Array;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
175
|
type Rotation = 0 | 90 | 180 | 270;
|
|
149
176
|
type Alignment = undefined | "left" | "center" | "right";
|
|
150
177
|
/**
|
|
@@ -159,7 +186,7 @@ declare const alignmentToNumber: (alignment: Alignment) => 0 | 1 | 2 | 3;
|
|
|
159
186
|
* on the values
|
|
160
187
|
*/
|
|
161
188
|
type GraphicMode = "overwrite" | "or" | "xor";
|
|
162
|
-
type
|
|
189
|
+
type LabelDirection = "normal" | "inverse";
|
|
163
190
|
type ECCLevel = "L" | "M" | "Q" | "H";
|
|
164
191
|
type AutoManual = "A" | "M";
|
|
165
192
|
type QRModel = "M1" | "M2";
|
|
@@ -252,7 +279,6 @@ declare class TSPLGapCommand extends TSPLCommand {
|
|
|
252
279
|
private readonly unitSystem;
|
|
253
280
|
constructor(gap: number, offset: number, unitSystem: UnitSystem);
|
|
254
281
|
get commandString(): string;
|
|
255
|
-
private valueWithUnit;
|
|
256
282
|
}
|
|
257
283
|
|
|
258
284
|
/**
|
|
@@ -271,7 +297,6 @@ declare class TSPLSizeCommand extends TSPLCommand {
|
|
|
271
297
|
private readonly unitSystem;
|
|
272
298
|
constructor(width: number, height: number, unitSystem: UnitSystem);
|
|
273
299
|
get commandString(): string;
|
|
274
|
-
private valueWithUnit;
|
|
275
300
|
}
|
|
276
301
|
|
|
277
302
|
/**
|
|
@@ -293,7 +318,7 @@ declare class TSPLDirectionCommand extends TSPLCommand {
|
|
|
293
318
|
* @param direction Controls the orientation of the resulting label compared to the printer
|
|
294
319
|
* @param mirror Controls mirroring relative to the center line of the label perpendicular to the printhead. See the documentsion for examples
|
|
295
320
|
*/
|
|
296
|
-
constructor(direction:
|
|
321
|
+
constructor(direction: LabelDirection, mirror?: boolean);
|
|
297
322
|
get commandString(): string;
|
|
298
323
|
}
|
|
299
324
|
|
|
@@ -360,57 +385,406 @@ declare class TSPLBlockCommand extends TSPLTextCommand {
|
|
|
360
385
|
get commandString(): string;
|
|
361
386
|
}
|
|
362
387
|
|
|
363
|
-
type
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
type
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
388
|
+
type Data = ArrayBuffer | Uint8Array;
|
|
389
|
+
/**
|
|
390
|
+
* A raw TSPL command. Can be used to use a command that is not yet supported
|
|
391
|
+
*/
|
|
392
|
+
declare class TSPLDownload extends TSPLCommand {
|
|
393
|
+
/**
|
|
394
|
+
* Name of the file on the printer
|
|
395
|
+
*/
|
|
396
|
+
private readonly fileName;
|
|
397
|
+
private readonly data;
|
|
398
|
+
/**
|
|
399
|
+
* Initialize a command with a raw body
|
|
400
|
+
* @param body
|
|
401
|
+
*/
|
|
402
|
+
constructor(fileName: string, data: Data);
|
|
403
|
+
get commandString(): string;
|
|
404
|
+
write(device: UsbDevice): Promise<void>;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
type DisplayType = "CLS" | "IMAGE" | "OFF";
|
|
408
|
+
/**
|
|
409
|
+
* Displays the image buffer on the screen
|
|
410
|
+
* {@link /documentsions/TSPL.pdf}
|
|
411
|
+
*/
|
|
412
|
+
declare class TSPLDisplay extends TSPLCommand {
|
|
413
|
+
private readonly type;
|
|
414
|
+
constructor(type: DisplayType);
|
|
415
|
+
get commandString(): string;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
declare class TSPLDiagonal extends TSPLCommand {
|
|
419
|
+
private readonly start;
|
|
420
|
+
private readonly end;
|
|
421
|
+
private readonly thickness;
|
|
422
|
+
constructor(start: Point, end: Point, thickness?: number);
|
|
423
|
+
get commandString(): string;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Command generator for tspl commands
|
|
428
|
+
*/
|
|
429
|
+
declare class TSPLCommandGenerator implements CommandGenerator<TSPLCommand> {
|
|
430
|
+
commandGroup(commands: TSPLCommand[]): TSPLCommandGroup;
|
|
431
|
+
print(sets: number, copiesPerSet: number): TSPLCommand;
|
|
432
|
+
text(content: string, x: number, y: number, font: string | "default", size: number): TSPLCommand;
|
|
433
|
+
upload(name: string, data: ArrayBuffer | Uint8Array): TSPLCommand;
|
|
434
|
+
setUp(width: number, height: number, gap: number, offset: number, direction: LabelDirection, mirror: boolean | undefined, unitSystem: UnitSystem): TSPLCommand;
|
|
435
|
+
display(): TSPLCommandGroup;
|
|
436
|
+
line(start: Point, end: Point, thickness: number): TSPLCommand;
|
|
437
|
+
image(image: BitmapLike, x: number, y: number, mode?: GraphicMode | undefined): TSPLCommand;
|
|
438
|
+
qrCode(content: string, width: number, x: number, y: number): TSPLCommand;
|
|
439
|
+
barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment): TSPLCommand;
|
|
440
|
+
private cellCount;
|
|
441
|
+
}
|
|
442
|
+
declare const _default: TSPLCommandGenerator;
|
|
443
|
+
|
|
444
|
+
type index$3_Alignment = Alignment;
|
|
445
|
+
type index$3_AutoManual = AutoManual;
|
|
446
|
+
type index$3_BarcodeHumanReable = BarcodeHumanReable;
|
|
447
|
+
type index$3_BarcodeType = BarcodeType;
|
|
448
|
+
type index$3_ECCLevel = ECCLevel;
|
|
449
|
+
type index$3_GraphicMode = GraphicMode;
|
|
450
|
+
type index$3_LabelDirection = LabelDirection;
|
|
451
|
+
type index$3_QRModel = QRModel;
|
|
452
|
+
type index$3_Rotation = Rotation;
|
|
453
|
+
type index$3_TSPLBarCommand = TSPLBarCommand;
|
|
454
|
+
declare const index$3_TSPLBarCommand: typeof TSPLBarCommand;
|
|
455
|
+
type index$3_TSPLBitmapCommand = TSPLBitmapCommand;
|
|
456
|
+
declare const index$3_TSPLBitmapCommand: typeof TSPLBitmapCommand;
|
|
457
|
+
type index$3_TSPLBlockCommand = TSPLBlockCommand;
|
|
458
|
+
declare const index$3_TSPLBlockCommand: typeof TSPLBlockCommand;
|
|
459
|
+
type index$3_TSPLCLSCommand = TSPLCLSCommand;
|
|
460
|
+
declare const index$3_TSPLCLSCommand: typeof TSPLCLSCommand;
|
|
461
|
+
type index$3_TSPLCommand = TSPLCommand;
|
|
462
|
+
declare const index$3_TSPLCommand: typeof TSPLCommand;
|
|
463
|
+
type index$3_TSPLCommandGroup = TSPLCommandGroup;
|
|
464
|
+
declare const index$3_TSPLCommandGroup: typeof TSPLCommandGroup;
|
|
465
|
+
type index$3_TSPLDiagonal = TSPLDiagonal;
|
|
466
|
+
declare const index$3_TSPLDiagonal: typeof TSPLDiagonal;
|
|
467
|
+
type index$3_TSPLDirectionCommand = TSPLDirectionCommand;
|
|
468
|
+
declare const index$3_TSPLDirectionCommand: typeof TSPLDirectionCommand;
|
|
469
|
+
type index$3_TSPLDisplay = TSPLDisplay;
|
|
470
|
+
declare const index$3_TSPLDisplay: typeof TSPLDisplay;
|
|
471
|
+
type index$3_TSPLDownload = TSPLDownload;
|
|
472
|
+
declare const index$3_TSPLDownload: typeof TSPLDownload;
|
|
473
|
+
type index$3_TSPLGapCommand = TSPLGapCommand;
|
|
474
|
+
declare const index$3_TSPLGapCommand: typeof TSPLGapCommand;
|
|
475
|
+
type index$3_TSPLPrintCommand = TSPLPrintCommand;
|
|
476
|
+
declare const index$3_TSPLPrintCommand: typeof TSPLPrintCommand;
|
|
477
|
+
type index$3_TSPLQRCommand = TSPLQRCommand;
|
|
478
|
+
declare const index$3_TSPLQRCommand: typeof TSPLQRCommand;
|
|
479
|
+
type index$3_TSPLRawCommand = TSPLRawCommand;
|
|
480
|
+
declare const index$3_TSPLRawCommand: typeof TSPLRawCommand;
|
|
481
|
+
type index$3_TSPLSizeCommand = TSPLSizeCommand;
|
|
482
|
+
declare const index$3_TSPLSizeCommand: typeof TSPLSizeCommand;
|
|
483
|
+
type index$3_TSPLTextCommand = TSPLTextCommand;
|
|
484
|
+
declare const index$3_TSPLTextCommand: typeof TSPLTextCommand;
|
|
485
|
+
type index$3_TSPLVisualCommand = TSPLVisualCommand;
|
|
486
|
+
declare const index$3_TSPLVisualCommand: typeof TSPLVisualCommand;
|
|
487
|
+
declare const index$3_alignmentToNumber: typeof alignmentToNumber;
|
|
488
|
+
declare namespace index$3 {
|
|
489
|
+
export { type index$3_Alignment as Alignment, type index$3_AutoManual as AutoManual, type index$3_BarcodeHumanReable as BarcodeHumanReable, type index$3_BarcodeType as BarcodeType, type index$3_ECCLevel as ECCLevel, type index$3_GraphicMode as GraphicMode, type index$3_LabelDirection as LabelDirection, type index$3_QRModel as QRModel, type index$3_Rotation as Rotation, index$3_TSPLBarCommand as TSPLBarCommand, index$3_TSPLBitmapCommand as TSPLBitmapCommand, index$3_TSPLBlockCommand as TSPLBlockCommand, index$3_TSPLCLSCommand as TSPLCLSCommand, index$3_TSPLCommand as TSPLCommand, index$3_TSPLCommandGroup as TSPLCommandGroup, index$3_TSPLDiagonal as TSPLDiagonal, index$3_TSPLDirectionCommand as TSPLDirectionCommand, index$3_TSPLDisplay as TSPLDisplay, index$3_TSPLDownload as TSPLDownload, index$3_TSPLGapCommand as TSPLGapCommand, index$3_TSPLPrintCommand as TSPLPrintCommand, index$3_TSPLQRCommand as TSPLQRCommand, index$3_TSPLRawCommand as TSPLRawCommand, index$3_TSPLSizeCommand as TSPLSizeCommand, index$3_TSPLTextCommand as TSPLTextCommand, index$3_TSPLVisualCommand as TSPLVisualCommand, index$3_alignmentToNumber as alignmentToNumber, _default as commandGenerator };
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
type Point = {
|
|
493
|
+
x: number;
|
|
494
|
+
y: number;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
type PrinterLanguage = "tspl";
|
|
498
|
+
type UnitSystem = "imperial" | "metric" | "dot";
|
|
499
|
+
|
|
500
|
+
type index$2_Command = Command;
|
|
501
|
+
declare const index$2_Command: typeof Command;
|
|
502
|
+
type index$2_CommandGroup<T extends Command> = CommandGroup<T>;
|
|
503
|
+
declare const index$2_CommandGroup: typeof CommandGroup;
|
|
504
|
+
type index$2_Point = Point;
|
|
505
|
+
type index$2_PrinterLanguage = PrinterLanguage;
|
|
399
506
|
type index$2_UnitSystem = UnitSystem;
|
|
400
|
-
declare const index$2_alignmentToNumber: typeof alignmentToNumber;
|
|
401
507
|
declare namespace index$2 {
|
|
402
|
-
export {
|
|
508
|
+
export { index$2_Command as Command, index$2_CommandGroup as CommandGroup, type index$2_Point as Point, type index$2_PrinterLanguage as PrinterLanguage, type index$2_UnitSystem as UnitSystem, index$3 as tspl };
|
|
403
509
|
}
|
|
404
510
|
|
|
405
|
-
type
|
|
511
|
+
type Expand<T> = T extends infer O ? {
|
|
512
|
+
[K in keyof O]: O[K];
|
|
513
|
+
} : never;
|
|
514
|
+
type FontStyle = "italic" | "normal";
|
|
515
|
+
type Font = {
|
|
516
|
+
name: string;
|
|
517
|
+
data: ArrayBufferLike;
|
|
518
|
+
font: Font$1;
|
|
519
|
+
weight: number;
|
|
520
|
+
style: FontStyle;
|
|
521
|
+
};
|
|
522
|
+
type FontOption = Expand<Partial<Pick<Font, "style" | "weight">> & Pick<Font, "name"> & {
|
|
523
|
+
size: number;
|
|
524
|
+
}>;
|
|
525
|
+
|
|
526
|
+
type PrintConfig = {
|
|
527
|
+
dpi: number;
|
|
528
|
+
textWidth: (text: string, font: FontOption) => number;
|
|
529
|
+
getFontName: (font: FontOption) => string;
|
|
530
|
+
};
|
|
531
|
+
/**
|
|
532
|
+
* A component that can be directly printed to label printer
|
|
533
|
+
*/
|
|
534
|
+
declare abstract class Printable {
|
|
535
|
+
/**
|
|
536
|
+
* Generates a printable command
|
|
537
|
+
* @param language The printing language that should be used
|
|
538
|
+
* @returns A promise of a command that can be printed
|
|
539
|
+
*/
|
|
540
|
+
abstract commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
|
|
541
|
+
/**
|
|
542
|
+
* Generates printable command for the given printer. Can be used to obtain a command for fields supported by the package then customizing it before printing
|
|
543
|
+
* @param printer Printer to generate the command. Important because the command is printer language specific
|
|
544
|
+
* @returns A promise for a command. Most commands are syncronouse but some may require to access async resources
|
|
545
|
+
*/
|
|
546
|
+
commandForPrinter(printer: Printer, config?: PrintConfig): Promise<Command>;
|
|
547
|
+
/**
|
|
548
|
+
* Obtain a command generator for the given language
|
|
549
|
+
* @param language Language to get generator for
|
|
550
|
+
*/
|
|
551
|
+
protected commandGeneratorFor(language: PrinterLanguage): CommandGenerator<any>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
declare abstract class LabelField extends Printable {
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Holds the content of a label and handles printing
|
|
559
|
+
*/
|
|
560
|
+
declare class Label extends Printable {
|
|
561
|
+
/**
|
|
562
|
+
* Width of label in dots, mm or inch
|
|
563
|
+
*/
|
|
564
|
+
private readonly width;
|
|
565
|
+
/**
|
|
566
|
+
* Height of label in dots, mm or inch
|
|
567
|
+
*/
|
|
568
|
+
private readonly height;
|
|
569
|
+
/**
|
|
570
|
+
* Units for width, height, gap and offset
|
|
571
|
+
*/
|
|
572
|
+
private readonly unitSystem;
|
|
573
|
+
private fonts;
|
|
574
|
+
private dpi;
|
|
575
|
+
/**
|
|
576
|
+
* List of fields on the label
|
|
577
|
+
*/
|
|
578
|
+
private fields;
|
|
579
|
+
private fontCounter;
|
|
580
|
+
/**
|
|
581
|
+
* Configuration used when generating commands
|
|
582
|
+
*/
|
|
583
|
+
get printConfig(): PrintConfig;
|
|
584
|
+
constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number);
|
|
585
|
+
commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
|
|
586
|
+
/**
|
|
587
|
+
* Place fields to a label
|
|
588
|
+
* @param fields
|
|
589
|
+
*/
|
|
590
|
+
add(...fields: LabelField[]): void;
|
|
591
|
+
/**
|
|
592
|
+
* Register a font to be used. Use the name provided in components to use the font.
|
|
593
|
+
* For example: textField.setFont('myFont.ttf', 12)
|
|
594
|
+
* @param file Font file. Can be a blob or a url
|
|
595
|
+
* @param name Name to be used to reference the font
|
|
596
|
+
*/
|
|
597
|
+
registerFont(font: Omit<Font, "font">): Promise<void>;
|
|
598
|
+
/**
|
|
599
|
+
* Generate a command that is complete for printing
|
|
600
|
+
* @param language Printing language to use
|
|
601
|
+
* @param gap Distance between two labels. It is measured between the two points where the sensor
|
|
602
|
+
* leaves the label and enters the next one
|
|
603
|
+
* @param direction Direction relative to printing direction. See documentation for more details
|
|
604
|
+
* @param sets Number of sets to print. If you have counters for example, it will not change in a set
|
|
605
|
+
* @param copiesPerSet Number of labels per set
|
|
606
|
+
* @param mirror Mirror the label along the vertical axis
|
|
607
|
+
* @param gapOffset Used with non uniform shaped labels. Is the distance between the point where the sensor leaves the label and the
|
|
608
|
+
* furthest point of the label in the direction of printing. Check documentation for more info
|
|
609
|
+
* TODO: Is this too TSPL Specific?
|
|
610
|
+
*/
|
|
611
|
+
fullPrintCommand(language: PrinterLanguage, gap: number, direction: LabelDirection, sets: number, copiesPerSet?: number, mirror?: boolean, gapOffset?: number): Promise<Command>;
|
|
612
|
+
/**
|
|
613
|
+
* Generate commands needed to display the label on the printer screen
|
|
614
|
+
* @param language Printing language to use
|
|
615
|
+
* @param direction Direction relative to printing direction. See documentation for more details
|
|
616
|
+
* @param mirror Mirror the label along the vertical axis
|
|
617
|
+
*/
|
|
618
|
+
fullDisplayCommand(language: PrinterLanguage, direction: LabelDirection, mirror?: boolean): Promise<CommandGroup<any>>;
|
|
619
|
+
/**
|
|
620
|
+
* Helper function that generates common commands for print and display
|
|
621
|
+
*/
|
|
622
|
+
private fullCommand;
|
|
623
|
+
private fontUploadCommands;
|
|
624
|
+
private getIndexedFont;
|
|
625
|
+
private getFontName;
|
|
626
|
+
private get fontExtension();
|
|
627
|
+
private fontKey;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Draws a line to the screen
|
|
632
|
+
*/
|
|
633
|
+
declare class Line extends LabelField {
|
|
634
|
+
private readonly start;
|
|
635
|
+
private readonly end;
|
|
636
|
+
private readonly thickness;
|
|
637
|
+
/**
|
|
638
|
+
*
|
|
639
|
+
* @param start Start point of the line. Values are in dots
|
|
640
|
+
* @param end End point of the line. Values are in dots
|
|
641
|
+
* @param thickness Thickness of the line in dots
|
|
642
|
+
*/
|
|
643
|
+
constructor(start: Point, end: Point, thickness?: number);
|
|
644
|
+
commandForLanguage(language: PrinterLanguage): Promise<Command>;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Presents a piece of text on the label
|
|
649
|
+
*/
|
|
650
|
+
declare class Text extends LabelField {
|
|
651
|
+
private readonly content;
|
|
652
|
+
/**
|
|
653
|
+
* X coordinate in dots
|
|
654
|
+
*/
|
|
655
|
+
private readonly x;
|
|
656
|
+
/**
|
|
657
|
+
* Y coordinate in dots
|
|
658
|
+
*/
|
|
659
|
+
private readonly y;
|
|
660
|
+
/**
|
|
661
|
+
* If true, basic html elements will be interpretted, otherwise the raw string is printed out
|
|
662
|
+
*/
|
|
663
|
+
private readonly formatted;
|
|
664
|
+
private font;
|
|
665
|
+
private type;
|
|
666
|
+
private context;
|
|
667
|
+
private readonly lineSpacing;
|
|
668
|
+
/**
|
|
669
|
+
* Width of the text.
|
|
670
|
+
* If set, the text will be clipped to this size
|
|
671
|
+
* If the type is set to multiline, this is where the text is split to a newline
|
|
672
|
+
*/
|
|
673
|
+
private width;
|
|
674
|
+
/**
|
|
675
|
+
* Height of the text box, if empty and the type is multiline, the box can grow infinitely
|
|
676
|
+
*/
|
|
677
|
+
private height;
|
|
678
|
+
constructor(content: string, x: number, y: number, formatted?: boolean);
|
|
679
|
+
/**
|
|
680
|
+
* Sets the field to single line
|
|
681
|
+
* @param width Max width of the text. Leave it undefined to allow the field to grow
|
|
682
|
+
*/
|
|
683
|
+
setSingleLine(width?: number): void;
|
|
684
|
+
/**
|
|
685
|
+
* Sets the field to multi line
|
|
686
|
+
* @param width Max width of text before it gets wrapped to a new line
|
|
687
|
+
* @param height Max height of the text box, leave undefined to allow the text box to grow infinitly
|
|
688
|
+
*/
|
|
689
|
+
setMultiLine(width: number, height?: number): void;
|
|
690
|
+
/**
|
|
691
|
+
* Set a font to use as a base. If no formatting is set on the text with a html tag, this will be used
|
|
692
|
+
* Note: The font name either has to be a built in font on your printer or a font
|
|
693
|
+
* that is registered on the label using 'registerFont'.
|
|
694
|
+
*/
|
|
695
|
+
setFont(font: FontOption): void;
|
|
696
|
+
commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
|
|
697
|
+
/**
|
|
698
|
+
* Generate commands for formatted text
|
|
699
|
+
* @returns
|
|
700
|
+
*/
|
|
701
|
+
private generateFormattedText;
|
|
702
|
+
/**
|
|
703
|
+
* Generate commands for plain text
|
|
704
|
+
* @returns
|
|
705
|
+
*/
|
|
706
|
+
private generatePlainText;
|
|
707
|
+
/**
|
|
708
|
+
* Iterats the nodes in a html text and generates text commands for it
|
|
709
|
+
*/
|
|
710
|
+
private generateFormattedRecursive;
|
|
711
|
+
/**
|
|
712
|
+
* Generate commands for plain text
|
|
713
|
+
* @param config
|
|
714
|
+
* @returns
|
|
715
|
+
*/
|
|
716
|
+
private generatePlainTextCore;
|
|
717
|
+
private textCommand;
|
|
718
|
+
private textLineCommand;
|
|
719
|
+
private getFontName;
|
|
720
|
+
private get textWithFunction();
|
|
721
|
+
/**
|
|
722
|
+
* This function is used to calculate the font size if no
|
|
723
|
+
* print config is provided. This will asume that the font has square characters
|
|
724
|
+
*/
|
|
725
|
+
private defaultTextWidth;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
declare class BarCode extends LabelField {
|
|
729
|
+
private readonly content;
|
|
730
|
+
private readonly x;
|
|
731
|
+
private readonly y;
|
|
732
|
+
private readonly type;
|
|
733
|
+
private readonly height;
|
|
734
|
+
private rotation;
|
|
735
|
+
private humanReadable;
|
|
736
|
+
private readonly alignment;
|
|
737
|
+
constructor(content: string, x: number, y: number, type: BarcodeType, height: number);
|
|
738
|
+
setRotation(rotation: Rotation): void;
|
|
739
|
+
setHumanReadable(humanReadable: BarcodeHumanReable): void;
|
|
740
|
+
commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
declare class Image extends LabelField {
|
|
744
|
+
/**
|
|
745
|
+
* X coordinate in dots
|
|
746
|
+
*/
|
|
747
|
+
private readonly x;
|
|
748
|
+
/**
|
|
749
|
+
* Y coordinate in dots
|
|
750
|
+
*/
|
|
751
|
+
private readonly y;
|
|
752
|
+
private readonly image;
|
|
753
|
+
constructor(x: number, y: number, image: BitmapLike);
|
|
754
|
+
commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
|
|
755
|
+
/**
|
|
756
|
+
* Create an image field for an image
|
|
757
|
+
* @param image
|
|
758
|
+
* @param x
|
|
759
|
+
* @param y
|
|
760
|
+
* @param width
|
|
761
|
+
* @param height
|
|
762
|
+
* @returns
|
|
763
|
+
*/
|
|
764
|
+
static create(image: string, x: number, y: number, width?: number, height?: number): Promise<Image>;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
declare class QRCode extends LabelField {
|
|
768
|
+
private readonly content;
|
|
769
|
+
private readonly x;
|
|
770
|
+
private readonly y;
|
|
771
|
+
private readonly width;
|
|
772
|
+
constructor(content: string, x: number, y: number, width: number);
|
|
773
|
+
commandForLanguage(language: PrinterLanguage, config?: PrintConfig | undefined): Promise<Command>;
|
|
774
|
+
}
|
|
406
775
|
|
|
407
|
-
type index$
|
|
408
|
-
declare const index$
|
|
409
|
-
type index$
|
|
410
|
-
declare const index$
|
|
411
|
-
type index$
|
|
776
|
+
type index$1_BarCode = BarCode;
|
|
777
|
+
declare const index$1_BarCode: typeof BarCode;
|
|
778
|
+
type index$1_Image = Image;
|
|
779
|
+
declare const index$1_Image: typeof Image;
|
|
780
|
+
type index$1_Label = Label;
|
|
781
|
+
declare const index$1_Label: typeof Label;
|
|
782
|
+
type index$1_Line = Line;
|
|
783
|
+
declare const index$1_Line: typeof Line;
|
|
784
|
+
type index$1_Text = Text;
|
|
785
|
+
declare const index$1_Text: typeof Text;
|
|
412
786
|
declare namespace index$1 {
|
|
413
|
-
export { index$
|
|
787
|
+
export { index$1_BarCode as BarCode, index$1_Image as Image, index$1_Label as Label, index$1_Line as Line, index$1_Text as Text, QRCode as qrCode };
|
|
414
788
|
}
|
|
415
789
|
|
|
416
790
|
/**
|
|
@@ -431,6 +805,16 @@ declare abstract class Printer {
|
|
|
431
805
|
* Close the printer USB
|
|
432
806
|
*/
|
|
433
807
|
close(): Promise<void>;
|
|
808
|
+
/**
|
|
809
|
+
* Prints a label
|
|
810
|
+
* @param label
|
|
811
|
+
*/
|
|
812
|
+
print(label: Label, sets: number, gap: number, copiesPerSet?: number, direction?: LabelDirection, mirror?: boolean, gapOffset?: number): Promise<void>;
|
|
813
|
+
/**
|
|
814
|
+
* Display label on the printer's screen
|
|
815
|
+
* @param label
|
|
816
|
+
*/
|
|
817
|
+
display(label: Label, direction?: LabelDirection, mirror?: boolean): Promise<void>;
|
|
434
818
|
/**
|
|
435
819
|
* Writes a command to the printers usb
|
|
436
820
|
* @param command Command to send to the usb
|
|
@@ -472,4 +856,4 @@ declare namespace index {
|
|
|
472
856
|
export { index_Printer as Printer, index_PrinterService as PrinterService };
|
|
473
857
|
}
|
|
474
858
|
|
|
475
|
-
export { index$
|
|
859
|
+
export { index$2 as commands, index$1 as labels, index as printers };
|