label-printer 0.2.5 → 0.3.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/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Label Print
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 UnitSystem = "imperial" | "metric" | "dot";
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: "normal" | "inverse", mirror?: boolean);
321
+ constructor(direction: LabelDirection, mirror?: boolean);
297
322
  get commandString(): string;
298
323
  }
299
324
 
@@ -360,57 +385,381 @@ declare class TSPLBlockCommand extends TSPLTextCommand {
360
385
  get commandString(): string;
361
386
  }
362
387
 
363
- type index$2_Alignment = Alignment;
364
- type index$2_AutoManual = AutoManual;
365
- type index$2_BarcodeHumanReable = BarcodeHumanReable;
366
- type index$2_BarcodeType = BarcodeType;
367
- type index$2_ECCLevel = ECCLevel;
368
- type index$2_GraphicMode = GraphicMode;
369
- type index$2_QRModel = QRModel;
370
- type index$2_Rotation = Rotation;
371
- type index$2_TSPLBarCommand = TSPLBarCommand;
372
- declare const index$2_TSPLBarCommand: typeof TSPLBarCommand;
373
- type index$2_TSPLBitmapCommand = TSPLBitmapCommand;
374
- declare const index$2_TSPLBitmapCommand: typeof TSPLBitmapCommand;
375
- type index$2_TSPLBlockCommand = TSPLBlockCommand;
376
- declare const index$2_TSPLBlockCommand: typeof TSPLBlockCommand;
377
- type index$2_TSPLCLSCommand = TSPLCLSCommand;
378
- declare const index$2_TSPLCLSCommand: typeof TSPLCLSCommand;
379
- type index$2_TSPLCommand = TSPLCommand;
380
- declare const index$2_TSPLCommand: typeof TSPLCommand;
381
- type index$2_TSPLCommandGroup = TSPLCommandGroup;
382
- declare const index$2_TSPLCommandGroup: typeof TSPLCommandGroup;
383
- type index$2_TSPLDirectionCommand = TSPLDirectionCommand;
384
- declare const index$2_TSPLDirectionCommand: typeof TSPLDirectionCommand;
385
- type index$2_TSPLGapCommand = TSPLGapCommand;
386
- declare const index$2_TSPLGapCommand: typeof TSPLGapCommand;
387
- type index$2_TSPLPrintCommand = TSPLPrintCommand;
388
- declare const index$2_TSPLPrintCommand: typeof TSPLPrintCommand;
389
- type index$2_TSPLQRCommand = TSPLQRCommand;
390
- declare const index$2_TSPLQRCommand: typeof TSPLQRCommand;
391
- type index$2_TSPLRawCommand = TSPLRawCommand;
392
- declare const index$2_TSPLRawCommand: typeof TSPLRawCommand;
393
- type index$2_TSPLSizeCommand = TSPLSizeCommand;
394
- declare const index$2_TSPLSizeCommand: typeof TSPLSizeCommand;
395
- type index$2_TSPLTextCommand = TSPLTextCommand;
396
- declare const index$2_TSPLTextCommand: typeof TSPLTextCommand;
397
- type index$2_TSPLVisualCommand = TSPLVisualCommand;
398
- declare const index$2_TSPLVisualCommand: typeof TSPLVisualCommand;
399
- type index$2_UnitSystem = UnitSystem;
400
- declare const index$2_alignmentToNumber: typeof alignmentToNumber;
401
- declare namespace index$2 {
402
- export { type index$2_Alignment as Alignment, type index$2_AutoManual as AutoManual, type index$2_BarcodeHumanReable as BarcodeHumanReable, type index$2_BarcodeType as BarcodeType, type index$2_ECCLevel as ECCLevel, type index$2_GraphicMode as GraphicMode, type index$2_QRModel as QRModel, type index$2_Rotation as Rotation, index$2_TSPLBarCommand as TSPLBarCommand, index$2_TSPLBitmapCommand as TSPLBitmapCommand, index$2_TSPLBlockCommand as TSPLBlockCommand, index$2_TSPLCLSCommand as TSPLCLSCommand, index$2_TSPLCommand as TSPLCommand, index$2_TSPLCommandGroup as TSPLCommandGroup, index$2_TSPLDirectionCommand as TSPLDirectionCommand, index$2_TSPLGapCommand as TSPLGapCommand, index$2_TSPLPrintCommand as TSPLPrintCommand, index$2_TSPLQRCommand as TSPLQRCommand, index$2_TSPLRawCommand as TSPLRawCommand, index$2_TSPLSizeCommand as TSPLSizeCommand, index$2_TSPLTextCommand as TSPLTextCommand, index$2_TSPLVisualCommand as TSPLVisualCommand, type index$2_UnitSystem as UnitSystem, index$2_alignmentToNumber as alignmentToNumber };
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>;
403
405
  }
404
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_Alignment = Alignment;
445
+ type index_AutoManual = AutoManual;
446
+ type index_BarcodeHumanReable = BarcodeHumanReable;
447
+ type index_BarcodeType = BarcodeType;
448
+ type index_ECCLevel = ECCLevel;
449
+ type index_GraphicMode = GraphicMode;
450
+ type index_LabelDirection = LabelDirection;
451
+ type index_QRModel = QRModel;
452
+ type index_Rotation = Rotation;
453
+ type index_TSPLBarCommand = TSPLBarCommand;
454
+ declare const index_TSPLBarCommand: typeof TSPLBarCommand;
455
+ type index_TSPLBitmapCommand = TSPLBitmapCommand;
456
+ declare const index_TSPLBitmapCommand: typeof TSPLBitmapCommand;
457
+ type index_TSPLBlockCommand = TSPLBlockCommand;
458
+ declare const index_TSPLBlockCommand: typeof TSPLBlockCommand;
459
+ type index_TSPLCLSCommand = TSPLCLSCommand;
460
+ declare const index_TSPLCLSCommand: typeof TSPLCLSCommand;
461
+ type index_TSPLCommand = TSPLCommand;
462
+ declare const index_TSPLCommand: typeof TSPLCommand;
463
+ type index_TSPLCommandGroup = TSPLCommandGroup;
464
+ declare const index_TSPLCommandGroup: typeof TSPLCommandGroup;
465
+ type index_TSPLDiagonal = TSPLDiagonal;
466
+ declare const index_TSPLDiagonal: typeof TSPLDiagonal;
467
+ type index_TSPLDirectionCommand = TSPLDirectionCommand;
468
+ declare const index_TSPLDirectionCommand: typeof TSPLDirectionCommand;
469
+ type index_TSPLDisplay = TSPLDisplay;
470
+ declare const index_TSPLDisplay: typeof TSPLDisplay;
471
+ type index_TSPLDownload = TSPLDownload;
472
+ declare const index_TSPLDownload: typeof TSPLDownload;
473
+ type index_TSPLGapCommand = TSPLGapCommand;
474
+ declare const index_TSPLGapCommand: typeof TSPLGapCommand;
475
+ type index_TSPLPrintCommand = TSPLPrintCommand;
476
+ declare const index_TSPLPrintCommand: typeof TSPLPrintCommand;
477
+ type index_TSPLQRCommand = TSPLQRCommand;
478
+ declare const index_TSPLQRCommand: typeof TSPLQRCommand;
479
+ type index_TSPLRawCommand = TSPLRawCommand;
480
+ declare const index_TSPLRawCommand: typeof TSPLRawCommand;
481
+ type index_TSPLSizeCommand = TSPLSizeCommand;
482
+ declare const index_TSPLSizeCommand: typeof TSPLSizeCommand;
483
+ type index_TSPLTextCommand = TSPLTextCommand;
484
+ declare const index_TSPLTextCommand: typeof TSPLTextCommand;
485
+ type index_TSPLVisualCommand = TSPLVisualCommand;
486
+ declare const index_TSPLVisualCommand: typeof TSPLVisualCommand;
487
+ declare const index_alignmentToNumber: typeof alignmentToNumber;
488
+ declare namespace index {
489
+ export { type index_Alignment as Alignment, type index_AutoManual as AutoManual, type index_BarcodeHumanReable as BarcodeHumanReable, type index_BarcodeType as BarcodeType, type index_ECCLevel as ECCLevel, type index_GraphicMode as GraphicMode, type index_LabelDirection as LabelDirection, type index_QRModel as QRModel, type index_Rotation as Rotation, index_TSPLBarCommand as TSPLBarCommand, index_TSPLBitmapCommand as TSPLBitmapCommand, index_TSPLBlockCommand as TSPLBlockCommand, index_TSPLCLSCommand as TSPLCLSCommand, index_TSPLCommand as TSPLCommand, index_TSPLCommandGroup as TSPLCommandGroup, index_TSPLDiagonal as TSPLDiagonal, index_TSPLDirectionCommand as TSPLDirectionCommand, index_TSPLDisplay as TSPLDisplay, index_TSPLDownload as TSPLDownload, index_TSPLGapCommand as TSPLGapCommand, index_TSPLPrintCommand as TSPLPrintCommand, index_TSPLQRCommand as TSPLQRCommand, index_TSPLRawCommand as TSPLRawCommand, index_TSPLSizeCommand as TSPLSizeCommand, index_TSPLTextCommand as TSPLTextCommand, index_TSPLVisualCommand as TSPLVisualCommand, index_alignmentToNumber as alignmentToNumber, _default as commandGenerator };
490
+ }
491
+
492
+ type Point = {
493
+ x: number;
494
+ y: number;
495
+ };
496
+
405
497
  type PrinterLanguage = "tspl";
498
+ type UnitSystem = "imperial" | "metric" | "dot";
499
+
500
+ type Expand<T> = T extends infer O ? {
501
+ [K in keyof O]: O[K];
502
+ } : never;
503
+ type FontStyle = "italic" | "normal";
504
+ type Font = {
505
+ name: string;
506
+ data: ArrayBufferLike;
507
+ font: Font$1;
508
+ weight: number;
509
+ style: FontStyle;
510
+ };
511
+ type FontOption = Expand<Partial<Pick<Font, "style" | "weight">> & Pick<Font, "name"> & {
512
+ size: number;
513
+ }>;
514
+
515
+ type PrintConfig = {
516
+ dpi: number;
517
+ textWidth: (text: string, font: FontOption) => number;
518
+ getFontName: (font: FontOption) => string;
519
+ };
520
+ /**
521
+ * A component that can be directly printed to label printer
522
+ */
523
+ declare abstract class Printable {
524
+ /**
525
+ * Generates a printable command
526
+ * @param language The printing language that should be used
527
+ * @returns A promise of a command that can be printed
528
+ */
529
+ abstract commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
530
+ /**
531
+ * 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
532
+ * @param printer Printer to generate the command. Important because the command is printer language specific
533
+ * @returns A promise for a command. Most commands are syncronouse but some may require to access async resources
534
+ */
535
+ commandForPrinter(printer: Printer, config?: PrintConfig): Promise<Command>;
536
+ /**
537
+ * Obtain a command generator for the given language
538
+ * @param language Language to get generator for
539
+ */
540
+ protected commandGeneratorFor(language: PrinterLanguage): CommandGenerator<any>;
541
+ }
542
+
543
+ declare abstract class LabelField extends Printable {
544
+ }
545
+
546
+ /**
547
+ * Holds the content of a label and handles printing
548
+ */
549
+ declare class Label extends Printable {
550
+ /**
551
+ * Width of label in dots, mm or inch
552
+ */
553
+ private readonly width;
554
+ /**
555
+ * Height of label in dots, mm or inch
556
+ */
557
+ private readonly height;
558
+ /**
559
+ * Units for width, height, gap and offset
560
+ */
561
+ private readonly unitSystem;
562
+ private fonts;
563
+ private dpi;
564
+ /**
565
+ * List of fields on the label
566
+ */
567
+ private fields;
568
+ private fontCounter;
569
+ /**
570
+ * Configuration used when generating commands
571
+ */
572
+ get printConfig(): PrintConfig;
573
+ constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number);
574
+ commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
575
+ /**
576
+ * Place fields to a label
577
+ * @param fields
578
+ */
579
+ add(...fields: LabelField[]): void;
580
+ /**
581
+ * Register a font to be used. Use the name provided in components to use the font.
582
+ * For example: textField.setFont('myFont.ttf', 12)
583
+ * @param file Font file. Can be a blob or a url
584
+ * @param name Name to be used to reference the font
585
+ */
586
+ registerFont(font: Omit<Font, "font">): Promise<void>;
587
+ /**
588
+ * Generate a command that is complete for printing
589
+ * @param language Printing language to use
590
+ * @param gap Distance between two labels. It is measured between the two points where the sensor
591
+ * leaves the label and enters the next one
592
+ * @param direction Direction relative to printing direction. See documentation for more details
593
+ * @param sets Number of sets to print. If you have counters for example, it will not change in a set
594
+ * @param copiesPerSet Number of labels per set
595
+ * @param mirror Mirror the label along the vertical axis
596
+ * @param gapOffset Used with non uniform shaped labels. Is the distance between the point where the sensor leaves the label and the
597
+ * furthest point of the label in the direction of printing. Check documentation for more info
598
+ * TODO: Is this too TSPL Specific?
599
+ */
600
+ fullPrintCommand(language: PrinterLanguage, gap: number, direction: LabelDirection, sets: number, copiesPerSet?: number, mirror?: boolean, gapOffset?: number): Promise<Command>;
601
+ /**
602
+ * Generate commands needed to display the label on the printer screen
603
+ * @param language Printing language to use
604
+ * @param direction Direction relative to printing direction. See documentation for more details
605
+ * @param mirror Mirror the label along the vertical axis
606
+ */
607
+ fullDisplayCommand(language: PrinterLanguage, direction: LabelDirection, mirror?: boolean): Promise<CommandGroup<any>>;
608
+ /**
609
+ * Helper function that generates common commands for print and display
610
+ */
611
+ private fullCommand;
612
+ private fontUploadCommands;
613
+ private getIndexedFont;
614
+ private getFontName;
615
+ private get fontExtension();
616
+ private fontKey;
617
+ }
406
618
 
407
- type index$1_Command = Command;
408
- declare const index$1_Command: typeof Command;
409
- type index$1_CommandGroup<T extends Command> = CommandGroup<T>;
410
- declare const index$1_CommandGroup: typeof CommandGroup;
411
- type index$1_PrinterLanguage = PrinterLanguage;
412
- declare namespace index$1 {
413
- export { index$1_Command as Command, index$1_CommandGroup as CommandGroup, type index$1_PrinterLanguage as PrinterLanguage, index$2 as tspl };
619
+ /**
620
+ * Draws a line to the screen
621
+ */
622
+ declare class Line extends LabelField {
623
+ private readonly start;
624
+ private readonly end;
625
+ private readonly thickness;
626
+ /**
627
+ *
628
+ * @param start Start point of the line. Values are in dots
629
+ * @param end End point of the line. Values are in dots
630
+ * @param thickness Thickness of the line in dots
631
+ */
632
+ constructor(start: Point, end: Point, thickness?: number);
633
+ commandForLanguage(language: PrinterLanguage): Promise<Command>;
634
+ }
635
+
636
+ /**
637
+ * Presents a piece of text on the label
638
+ */
639
+ declare class Text extends LabelField {
640
+ private readonly content;
641
+ /**
642
+ * X coordinate in dots
643
+ */
644
+ private readonly x;
645
+ /**
646
+ * Y coordinate in dots
647
+ */
648
+ private readonly y;
649
+ /**
650
+ * If true, basic html elements will be interpretted, otherwise the raw string is printed out
651
+ */
652
+ private readonly formatted;
653
+ private font;
654
+ private type;
655
+ private context;
656
+ private readonly lineSpacing;
657
+ /**
658
+ * Width of the text.
659
+ * If set, the text will be clipped to this size
660
+ * If the type is set to multiline, this is where the text is split to a newline
661
+ */
662
+ private width;
663
+ /**
664
+ * Height of the text box, if empty and the type is multiline, the box can grow infinitely
665
+ */
666
+ private height;
667
+ constructor(content: string, x: number, y: number, formatted?: boolean);
668
+ /**
669
+ * Sets the field to single line
670
+ * @param width Max width of the text. Leave it undefined to allow the field to grow
671
+ */
672
+ setSingleLine(width?: number): void;
673
+ /**
674
+ * Sets the field to multi line
675
+ * @param width Max width of text before it gets wrapped to a new line
676
+ * @param height Max height of the text box, leave undefined to allow the text box to grow infinitly
677
+ */
678
+ setMultiLine(width: number, height?: number): void;
679
+ /**
680
+ * Set a font to use as a base. If no formatting is set on the text with a html tag, this will be used
681
+ * Note: The font name either has to be a built in font on your printer or a font
682
+ * that is registered on the label using 'registerFont'.
683
+ */
684
+ setFont(font: FontOption): void;
685
+ commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
686
+ /**
687
+ * Generate commands for formatted text
688
+ * @returns
689
+ */
690
+ private generateFormattedText;
691
+ /**
692
+ * Generate commands for plain text
693
+ * @returns
694
+ */
695
+ private generatePlainText;
696
+ /**
697
+ * Iterats the nodes in a html text and generates text commands for it
698
+ */
699
+ private generateFormattedRecursive;
700
+ /**
701
+ * Generate commands for plain text
702
+ * @param config
703
+ * @returns
704
+ */
705
+ private generatePlainTextCore;
706
+ private textCommand;
707
+ private textLineCommand;
708
+ private getFontName;
709
+ private get textWithFunction();
710
+ /**
711
+ * This function is used to calculate the font size if no
712
+ * print config is provided. This will asume that the font has square characters
713
+ */
714
+ private defaultTextWidth;
715
+ }
716
+
717
+ declare class BarCode extends LabelField {
718
+ private readonly content;
719
+ private readonly x;
720
+ private readonly y;
721
+ private readonly type;
722
+ private readonly height;
723
+ private rotation;
724
+ private humanReadable;
725
+ private readonly alignment;
726
+ constructor(content: string, x: number, y: number, type: BarcodeType, height: number);
727
+ setRotation(rotation: Rotation): void;
728
+ setHumanReadable(humanReadable: BarcodeHumanReable): void;
729
+ commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
730
+ }
731
+
732
+ declare class Image extends LabelField {
733
+ /**
734
+ * X coordinate in dots
735
+ */
736
+ private readonly x;
737
+ /**
738
+ * Y coordinate in dots
739
+ */
740
+ private readonly y;
741
+ private readonly image;
742
+ constructor(x: number, y: number, image: BitmapLike);
743
+ commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
744
+ /**
745
+ * Create an image field for an image
746
+ * @param image
747
+ * @param x
748
+ * @param y
749
+ * @param width
750
+ * @param height
751
+ * @returns
752
+ */
753
+ static create(image: string, x: number, y: number, width?: number, height?: number): Promise<Image>;
754
+ }
755
+
756
+ declare class QRCode extends LabelField {
757
+ private readonly content;
758
+ private readonly x;
759
+ private readonly y;
760
+ private readonly width;
761
+ constructor(content: string, x: number, y: number, width: number);
762
+ commandForLanguage(language: PrinterLanguage, config?: PrintConfig | undefined): Promise<Command>;
414
763
  }
415
764
 
416
765
  /**
@@ -431,6 +780,16 @@ declare abstract class Printer {
431
780
  * Close the printer USB
432
781
  */
433
782
  close(): Promise<void>;
783
+ /**
784
+ * Prints a label
785
+ * @param label
786
+ */
787
+ print(label: Label, sets: number, gap: number, copiesPerSet?: number, direction?: LabelDirection, mirror?: boolean, gapOffset?: number): Promise<void>;
788
+ /**
789
+ * Display label on the printer's screen
790
+ * @param label
791
+ */
792
+ display(label: Label, direction?: LabelDirection, mirror?: boolean): Promise<void>;
434
793
  /**
435
794
  * Writes a command to the printers usb
436
795
  * @param command Command to send to the usb
@@ -464,12 +823,4 @@ declare class PrinterService {
464
823
  static requestPrinter(): Promise<Printer | undefined>;
465
824
  }
466
825
 
467
- type index_Printer = Printer;
468
- declare const index_Printer: typeof Printer;
469
- type index_PrinterService = PrinterService;
470
- declare const index_PrinterService: typeof PrinterService;
471
- declare namespace index {
472
- export { index_Printer as Printer, index_PrinterService as PrinterService };
473
- }
474
-
475
- export { index$1 as commands, index as printers };
826
+ export { BarCode, Command, CommandGroup, Image, Label, Line, type Point, Printer, type PrinterLanguage, PrinterService, Text, type UnitSystem, QRCode as qrCode, index as tspl };