label-printer 0.10.0 → 0.12.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 CHANGED
@@ -91,17 +91,27 @@ type BitmapLike = {
91
91
  */
92
92
  type BWBitmap = BitmapLike;
93
93
 
94
+ type Point = {
95
+ x: number;
96
+ y: number;
97
+ };
98
+ type Dimension = {
99
+ width: number;
100
+ height: number;
101
+ };
102
+ type Rotation = 0 | 90 | 180 | 270;
103
+
94
104
  /**
95
105
  * Interface that should be implemented by a command generator object for each language
96
106
  */
97
107
  interface CommandGenerator<T extends Command> {
98
108
  commandGroup: (commands: T[]) => CommandGroup<T>;
99
109
  print: (sets: number, copiesPerSet: number) => T;
100
- text: (content: string, x: number, y: number, font: string | "default", size: number) => T;
110
+ text: (content: string, x: number, y: number, font: string | "default", size: number, rotation?: Rotation) => T;
101
111
  upload: (name: string, data: ArrayBuffer | Uint8Array) => T;
102
112
  line: (start: Point, end: Point, thickness: number) => T;
103
113
  image: (image: BitmapLike, x: number, y: number, mode?: GraphicMode) => T;
104
- qrCode: (content: string, width: number, x: number, y: number) => T;
114
+ qrCode: (content: string, width: number, x: number, y: number, rotation?: Rotation) => T;
105
115
  barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number) => T;
106
116
  /**
107
117
  * Should instruct the printer to display the image of the label on its screen instead of printing it
@@ -144,7 +154,6 @@ declare abstract class TSPLVisualCommand extends TSPLCommand {
144
154
  constructor(x: number, y: number);
145
155
  }
146
156
 
147
- type Rotation = 0 | 90 | 180 | 270;
148
157
  type Alignment = undefined | "left" | "center" | "right";
149
158
  /**
150
159
  * Convert an alignemnt string to its number value
@@ -413,13 +422,13 @@ declare class TSPLDensityCommand extends TSPLCommand {
413
422
  declare class TSPLCommandGenerator implements CommandGenerator<TSPLCommand> {
414
423
  commandGroup(commands: TSPLCommand[]): TSPLCommandGroup;
415
424
  print(sets: number, copiesPerSet: number): TSPLCommand;
416
- text(content: string, x: number, y: number, font: string | "default", size: number): TSPLCommand;
425
+ text(content: string, x: number, y: number, font: string | "default", size: number, rotation?: Rotation): TSPLCommand;
417
426
  upload(name: string, data: ArrayBuffer | Uint8Array): TSPLCommand;
418
427
  setUp(width: number, height: number, gap: number, offset: number, direction: LabelDirection, mirror: boolean | undefined, unitSystem: UnitSystem, density: number): TSPLCommand;
419
428
  display(): TSPLCommandGroup;
420
429
  line(start: Point, end: Point, thickness: number): TSPLCommand;
421
430
  image(image: BitmapLike, x: number, y: number, mode?: GraphicMode | undefined): TSPLCommand;
422
- qrCode(content: string, width: number, x: number, y: number): TSPLCommand;
431
+ qrCode(content: string, width: number, x: number, y: number, rotation?: Rotation): TSPLCommand;
423
432
  barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number): TSPLCommand;
424
433
  /**
425
434
  * Calculates the narrow and wide element widths for a barcode type based on the
@@ -442,7 +451,6 @@ type index$3_ECCLevel = ECCLevel;
442
451
  type index$3_GraphicMode = GraphicMode;
443
452
  type index$3_LabelDirection = LabelDirection;
444
453
  type index$3_QRModel = QRModel;
445
- type index$3_Rotation = Rotation;
446
454
  type index$3_TSPLBarCommand = TSPLBarCommand;
447
455
  declare const index$3_TSPLBarCommand: typeof TSPLBarCommand;
448
456
  type index$3_TSPLBitmapCommand = TSPLBitmapCommand;
@@ -481,14 +489,9 @@ type index$3_TSPLVisualCommand = TSPLVisualCommand;
481
489
  declare const index$3_TSPLVisualCommand: typeof TSPLVisualCommand;
482
490
  declare const index$3_alignmentToNumber: typeof alignmentToNumber;
483
491
  declare namespace index$3 {
484
- 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_TSPLDensityCommand as TSPLDensityCommand, 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 };
492
+ 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, 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_TSPLDensityCommand as TSPLDensityCommand, 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 };
485
493
  }
486
494
 
487
- type Point = {
488
- x: number;
489
- y: number;
490
- };
491
-
492
495
  type PrinterLanguage = "tspl";
493
496
  type UnitSystem = "imperial" | "metric" | "dot";
494
497
 
@@ -496,11 +499,13 @@ type index$2_Command = Command;
496
499
  declare const index$2_Command: typeof Command;
497
500
  type index$2_CommandGroup<T extends Command> = CommandGroup<T>;
498
501
  declare const index$2_CommandGroup: typeof CommandGroup;
502
+ type index$2_Dimension = Dimension;
499
503
  type index$2_Point = Point;
500
504
  type index$2_PrinterLanguage = PrinterLanguage;
505
+ type index$2_Rotation = Rotation;
501
506
  type index$2_UnitSystem = UnitSystem;
502
507
  declare namespace index$2 {
503
- 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 };
508
+ export { index$2_Command as Command, index$2_CommandGroup as CommandGroup, type index$2_Dimension as Dimension, type index$2_Point as Point, type index$2_PrinterLanguage as PrinterLanguage, type index$2_Rotation as Rotation, type index$2_UnitSystem as UnitSystem, index$3 as tspl };
504
509
  }
505
510
 
506
511
  type Expand<T> = T extends infer O ? {
@@ -517,6 +522,11 @@ type Font = {
517
522
  type FontOption = Expand<Partial<Pick<Font, "style" | "weight">> & Pick<Font, "name"> & {
518
523
  size: number;
519
524
  }>;
525
+ /**
526
+ * The orientation, the label will be printed on. This allows designing a label in the natural orientation, than printing to
527
+ * a label that is rotated in the printer. The rotation is applied to all fields on the label, and it is independent from the rotation of individual fields.
528
+ */
529
+ type LabelOrientation = "normal" | "left" | "right" | "upside-down";
520
530
 
521
531
  type PrintConfig = {
522
532
  dpi: number;
@@ -539,7 +549,7 @@ declare abstract class Printable {
539
549
  /**
540
550
  * 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
541
551
  * @param printer Printer to generate the command. Important because the command is printer language specific
542
- * @returns A promise for a command. Most commands are syncronouse but some may require to access async resources
552
+ * @returns A promise for a command. Most commands are synchronous but some may require to access async resources
543
553
  */
544
554
  commandForPrinter(printer: Printer, config?: PrintConfig): Promise<Command>;
545
555
  /**
@@ -571,10 +581,11 @@ declare class Label extends Printable {
571
581
  private fonts;
572
582
  private dpi;
573
583
  private density;
584
+ private orientation;
574
585
  /**
575
586
  * List of fields on the label
576
587
  */
577
- private fields;
588
+ private container;
578
589
  private fontCounter;
579
590
  private _textWidthCorrectionFactor;
580
591
  /**
@@ -588,6 +599,11 @@ declare class Label extends Printable {
588
599
  * @param factor Correction factor (default 1.0, typical range 0.9-1.0)
589
600
  */
590
601
  setTextWidthCorrectionFactor(factor: number): void;
602
+ /**
603
+ * Change the orientation the label is printed in. This will rotate all fields in the container
604
+ * @param orientation
605
+ */
606
+ setOrientation(orientation: LabelOrientation): void;
591
607
  constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number, density?: number);
592
608
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
593
609
  /**
@@ -651,21 +667,36 @@ declare class Line extends LabelField {
651
667
  commandForLanguage(language: PrinterLanguage): Promise<Command>;
652
668
  }
653
669
 
670
+ interface RotatableField {
671
+ setRotation(rotation: Rotation): void;
672
+ getRotation(): Rotation;
673
+ }
674
+ interface PositionedField {
675
+ getPosition(): Point;
676
+ setPosition(position: Point): void;
677
+ }
678
+
679
+ declare abstract class RotatableLabelField extends LabelField implements RotatableField {
680
+ protected rotation: Rotation;
681
+ setRotation(rotation: Rotation): void;
682
+ getRotation(): Rotation;
683
+ }
684
+
654
685
  /**
655
686
  * Presents a piece of text on the label
656
687
  */
657
- declare class Text extends LabelField {
688
+ declare class Text extends RotatableLabelField implements PositionedField {
658
689
  private readonly content;
659
690
  /**
660
691
  * X coordinate in dots
661
692
  */
662
- private readonly x;
693
+ private x;
663
694
  /**
664
695
  * Y coordinate in dots
665
696
  */
666
- private readonly y;
697
+ private y;
667
698
  /**
668
- * If true, basic html elements will be interpretted, otherwise the raw string is printed out
699
+ * If true, basic html elements will be interpreted, otherwise the raw string is printed out
669
700
  */
670
701
  private readonly formatted;
671
702
  private font;
@@ -684,6 +715,8 @@ declare class Text extends LabelField {
684
715
  private height;
685
716
  private endsWithBreak;
686
717
  constructor(content: string, x: number, y: number, formatted?: boolean);
718
+ setPosition(position: Point): void;
719
+ getPosition(): Point;
687
720
  /**
688
721
  * Sets the field to single line
689
722
  * @param width Max width of the text. Leave it undefined to allow the field to grow
@@ -701,6 +734,16 @@ declare class Text extends LabelField {
701
734
  * that is registered on the label using 'registerFont'.
702
735
  */
703
736
  setFont(font: FontOption): void;
737
+ /** Advance cursor by `amount` along the character direction */
738
+ private advanceChar;
739
+ /** Advance to the next line (reset char axis, advance in line direction) */
740
+ private advanceLine;
741
+ /** How far into the current line the cursor is (for width constraint calc) */
742
+ private charOffset;
743
+ /** How many lines deep we are (for height constraint calc) */
744
+ private lineOffset;
745
+ /** Whether the cursor is at the start of its line (char axis at origin) */
746
+ private atLineStart;
704
747
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
705
748
  /**
706
749
  * Generate commands for formatted text
@@ -727,20 +770,20 @@ declare class Text extends LabelField {
727
770
  private getFontName;
728
771
  private get textWidthFunction();
729
772
  /**
730
- * This function is used to calculate the font size if no
731
- * print config is provided. This will asume that the font has square characters
773
+ * Fallback width estimate when no font metrics are available.
774
+ * Uses the TSPL x-multiplication value (dotToPoint of the dot size) as
775
+ * the per-character width, which matches the rendered width of font "0".
732
776
  */
733
777
  private defaultTextWidth;
734
778
  }
735
779
 
736
- declare class BarCode extends LabelField {
780
+ declare class BarCode extends RotatableLabelField implements PositionedField {
737
781
  private readonly content;
738
- private readonly x;
739
- private readonly y;
782
+ private x;
783
+ private y;
740
784
  private readonly type;
741
785
  private readonly height;
742
786
  private readonly barWidth;
743
- private rotation;
744
787
  private humanReadable;
745
788
  private readonly alignment;
746
789
  /**
@@ -753,22 +796,25 @@ declare class BarCode extends LabelField {
753
796
  * calculated automatically based on the symbology's standard ratio.
754
797
  */
755
798
  constructor(content: string, x: number, y: number, type: BarcodeType, height: number, barWidth?: number);
756
- setRotation(rotation: Rotation): void;
757
799
  setHumanReadable(humanReadable: BarcodeHumanReable): void;
800
+ setPosition(position: Point): void;
801
+ getPosition(): Point;
758
802
  commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
759
803
  }
760
804
 
761
- declare class Image extends LabelField {
805
+ declare class Image extends RotatableLabelField implements PositionedField {
762
806
  /**
763
807
  * X coordinate in dots
764
808
  */
765
- private readonly x;
809
+ private x;
766
810
  /**
767
811
  * Y coordinate in dots
768
812
  */
769
- private readonly y;
813
+ private y;
770
814
  private readonly image;
771
815
  constructor(x: number, y: number, image: BitmapLike);
816
+ setPosition(position: Point): void;
817
+ getPosition(): Point;
772
818
  commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
773
819
  /**
774
820
  * Create an image field for an image
@@ -782,12 +828,14 @@ declare class Image extends LabelField {
782
828
  static create(image: string | Blob, x: number, y: number, width?: number, height?: number): Promise<Image>;
783
829
  }
784
830
 
785
- declare class QRCode extends LabelField {
831
+ declare class QRCode extends RotatableLabelField implements PositionedField {
786
832
  private readonly content;
787
- private readonly x;
788
- private readonly y;
833
+ private x;
834
+ private y;
789
835
  private readonly width;
790
836
  constructor(content: string, x: number, y: number, width: number);
837
+ setPosition(position: Point): void;
838
+ getPosition(): Point;
791
839
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig | undefined): Promise<Command>;
792
840
  }
793
841
 
package/dist/index.d.ts CHANGED
@@ -91,17 +91,27 @@ type BitmapLike = {
91
91
  */
92
92
  type BWBitmap = BitmapLike;
93
93
 
94
+ type Point = {
95
+ x: number;
96
+ y: number;
97
+ };
98
+ type Dimension = {
99
+ width: number;
100
+ height: number;
101
+ };
102
+ type Rotation = 0 | 90 | 180 | 270;
103
+
94
104
  /**
95
105
  * Interface that should be implemented by a command generator object for each language
96
106
  */
97
107
  interface CommandGenerator<T extends Command> {
98
108
  commandGroup: (commands: T[]) => CommandGroup<T>;
99
109
  print: (sets: number, copiesPerSet: number) => T;
100
- text: (content: string, x: number, y: number, font: string | "default", size: number) => T;
110
+ text: (content: string, x: number, y: number, font: string | "default", size: number, rotation?: Rotation) => T;
101
111
  upload: (name: string, data: ArrayBuffer | Uint8Array) => T;
102
112
  line: (start: Point, end: Point, thickness: number) => T;
103
113
  image: (image: BitmapLike, x: number, y: number, mode?: GraphicMode) => T;
104
- qrCode: (content: string, width: number, x: number, y: number) => T;
114
+ qrCode: (content: string, width: number, x: number, y: number, rotation?: Rotation) => T;
105
115
  barCode: (content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number) => T;
106
116
  /**
107
117
  * Should instruct the printer to display the image of the label on its screen instead of printing it
@@ -144,7 +154,6 @@ declare abstract class TSPLVisualCommand extends TSPLCommand {
144
154
  constructor(x: number, y: number);
145
155
  }
146
156
 
147
- type Rotation = 0 | 90 | 180 | 270;
148
157
  type Alignment = undefined | "left" | "center" | "right";
149
158
  /**
150
159
  * Convert an alignemnt string to its number value
@@ -413,13 +422,13 @@ declare class TSPLDensityCommand extends TSPLCommand {
413
422
  declare class TSPLCommandGenerator implements CommandGenerator<TSPLCommand> {
414
423
  commandGroup(commands: TSPLCommand[]): TSPLCommandGroup;
415
424
  print(sets: number, copiesPerSet: number): TSPLCommand;
416
- text(content: string, x: number, y: number, font: string | "default", size: number): TSPLCommand;
425
+ text(content: string, x: number, y: number, font: string | "default", size: number, rotation?: Rotation): TSPLCommand;
417
426
  upload(name: string, data: ArrayBuffer | Uint8Array): TSPLCommand;
418
427
  setUp(width: number, height: number, gap: number, offset: number, direction: LabelDirection, mirror: boolean | undefined, unitSystem: UnitSystem, density: number): TSPLCommand;
419
428
  display(): TSPLCommandGroup;
420
429
  line(start: Point, end: Point, thickness: number): TSPLCommand;
421
430
  image(image: BitmapLike, x: number, y: number, mode?: GraphicMode | undefined): TSPLCommand;
422
- qrCode(content: string, width: number, x: number, y: number): TSPLCommand;
431
+ qrCode(content: string, width: number, x: number, y: number, rotation?: Rotation): TSPLCommand;
423
432
  barCode(content: string, x: number, y: number, type: BarcodeType, height: number, rotation: Rotation, humanReadable: BarcodeHumanReable, alignment: Alignment, barWidth?: number): TSPLCommand;
424
433
  /**
425
434
  * Calculates the narrow and wide element widths for a barcode type based on the
@@ -442,7 +451,6 @@ type index$3_ECCLevel = ECCLevel;
442
451
  type index$3_GraphicMode = GraphicMode;
443
452
  type index$3_LabelDirection = LabelDirection;
444
453
  type index$3_QRModel = QRModel;
445
- type index$3_Rotation = Rotation;
446
454
  type index$3_TSPLBarCommand = TSPLBarCommand;
447
455
  declare const index$3_TSPLBarCommand: typeof TSPLBarCommand;
448
456
  type index$3_TSPLBitmapCommand = TSPLBitmapCommand;
@@ -481,14 +489,9 @@ type index$3_TSPLVisualCommand = TSPLVisualCommand;
481
489
  declare const index$3_TSPLVisualCommand: typeof TSPLVisualCommand;
482
490
  declare const index$3_alignmentToNumber: typeof alignmentToNumber;
483
491
  declare namespace index$3 {
484
- 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_TSPLDensityCommand as TSPLDensityCommand, 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 };
492
+ 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, 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_TSPLDensityCommand as TSPLDensityCommand, 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 };
485
493
  }
486
494
 
487
- type Point = {
488
- x: number;
489
- y: number;
490
- };
491
-
492
495
  type PrinterLanguage = "tspl";
493
496
  type UnitSystem = "imperial" | "metric" | "dot";
494
497
 
@@ -496,11 +499,13 @@ type index$2_Command = Command;
496
499
  declare const index$2_Command: typeof Command;
497
500
  type index$2_CommandGroup<T extends Command> = CommandGroup<T>;
498
501
  declare const index$2_CommandGroup: typeof CommandGroup;
502
+ type index$2_Dimension = Dimension;
499
503
  type index$2_Point = Point;
500
504
  type index$2_PrinterLanguage = PrinterLanguage;
505
+ type index$2_Rotation = Rotation;
501
506
  type index$2_UnitSystem = UnitSystem;
502
507
  declare namespace index$2 {
503
- 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 };
508
+ export { index$2_Command as Command, index$2_CommandGroup as CommandGroup, type index$2_Dimension as Dimension, type index$2_Point as Point, type index$2_PrinterLanguage as PrinterLanguage, type index$2_Rotation as Rotation, type index$2_UnitSystem as UnitSystem, index$3 as tspl };
504
509
  }
505
510
 
506
511
  type Expand<T> = T extends infer O ? {
@@ -517,6 +522,11 @@ type Font = {
517
522
  type FontOption = Expand<Partial<Pick<Font, "style" | "weight">> & Pick<Font, "name"> & {
518
523
  size: number;
519
524
  }>;
525
+ /**
526
+ * The orientation, the label will be printed on. This allows designing a label in the natural orientation, than printing to
527
+ * a label that is rotated in the printer. The rotation is applied to all fields on the label, and it is independent from the rotation of individual fields.
528
+ */
529
+ type LabelOrientation = "normal" | "left" | "right" | "upside-down";
520
530
 
521
531
  type PrintConfig = {
522
532
  dpi: number;
@@ -539,7 +549,7 @@ declare abstract class Printable {
539
549
  /**
540
550
  * 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
541
551
  * @param printer Printer to generate the command. Important because the command is printer language specific
542
- * @returns A promise for a command. Most commands are syncronouse but some may require to access async resources
552
+ * @returns A promise for a command. Most commands are synchronous but some may require to access async resources
543
553
  */
544
554
  commandForPrinter(printer: Printer, config?: PrintConfig): Promise<Command>;
545
555
  /**
@@ -571,10 +581,11 @@ declare class Label extends Printable {
571
581
  private fonts;
572
582
  private dpi;
573
583
  private density;
584
+ private orientation;
574
585
  /**
575
586
  * List of fields on the label
576
587
  */
577
- private fields;
588
+ private container;
578
589
  private fontCounter;
579
590
  private _textWidthCorrectionFactor;
580
591
  /**
@@ -588,6 +599,11 @@ declare class Label extends Printable {
588
599
  * @param factor Correction factor (default 1.0, typical range 0.9-1.0)
589
600
  */
590
601
  setTextWidthCorrectionFactor(factor: number): void;
602
+ /**
603
+ * Change the orientation the label is printed in. This will rotate all fields in the container
604
+ * @param orientation
605
+ */
606
+ setOrientation(orientation: LabelOrientation): void;
591
607
  constructor(width: number, height: number, dimensionUnit?: UnitSystem, dpi?: number, density?: number);
592
608
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
593
609
  /**
@@ -651,21 +667,36 @@ declare class Line extends LabelField {
651
667
  commandForLanguage(language: PrinterLanguage): Promise<Command>;
652
668
  }
653
669
 
670
+ interface RotatableField {
671
+ setRotation(rotation: Rotation): void;
672
+ getRotation(): Rotation;
673
+ }
674
+ interface PositionedField {
675
+ getPosition(): Point;
676
+ setPosition(position: Point): void;
677
+ }
678
+
679
+ declare abstract class RotatableLabelField extends LabelField implements RotatableField {
680
+ protected rotation: Rotation;
681
+ setRotation(rotation: Rotation): void;
682
+ getRotation(): Rotation;
683
+ }
684
+
654
685
  /**
655
686
  * Presents a piece of text on the label
656
687
  */
657
- declare class Text extends LabelField {
688
+ declare class Text extends RotatableLabelField implements PositionedField {
658
689
  private readonly content;
659
690
  /**
660
691
  * X coordinate in dots
661
692
  */
662
- private readonly x;
693
+ private x;
663
694
  /**
664
695
  * Y coordinate in dots
665
696
  */
666
- private readonly y;
697
+ private y;
667
698
  /**
668
- * If true, basic html elements will be interpretted, otherwise the raw string is printed out
699
+ * If true, basic html elements will be interpreted, otherwise the raw string is printed out
669
700
  */
670
701
  private readonly formatted;
671
702
  private font;
@@ -684,6 +715,8 @@ declare class Text extends LabelField {
684
715
  private height;
685
716
  private endsWithBreak;
686
717
  constructor(content: string, x: number, y: number, formatted?: boolean);
718
+ setPosition(position: Point): void;
719
+ getPosition(): Point;
687
720
  /**
688
721
  * Sets the field to single line
689
722
  * @param width Max width of the text. Leave it undefined to allow the field to grow
@@ -701,6 +734,16 @@ declare class Text extends LabelField {
701
734
  * that is registered on the label using 'registerFont'.
702
735
  */
703
736
  setFont(font: FontOption): void;
737
+ /** Advance cursor by `amount` along the character direction */
738
+ private advanceChar;
739
+ /** Advance to the next line (reset char axis, advance in line direction) */
740
+ private advanceLine;
741
+ /** How far into the current line the cursor is (for width constraint calc) */
742
+ private charOffset;
743
+ /** How many lines deep we are (for height constraint calc) */
744
+ private lineOffset;
745
+ /** Whether the cursor is at the start of its line (char axis at origin) */
746
+ private atLineStart;
704
747
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig): Promise<Command>;
705
748
  /**
706
749
  * Generate commands for formatted text
@@ -727,20 +770,20 @@ declare class Text extends LabelField {
727
770
  private getFontName;
728
771
  private get textWidthFunction();
729
772
  /**
730
- * This function is used to calculate the font size if no
731
- * print config is provided. This will asume that the font has square characters
773
+ * Fallback width estimate when no font metrics are available.
774
+ * Uses the TSPL x-multiplication value (dotToPoint of the dot size) as
775
+ * the per-character width, which matches the rendered width of font "0".
732
776
  */
733
777
  private defaultTextWidth;
734
778
  }
735
779
 
736
- declare class BarCode extends LabelField {
780
+ declare class BarCode extends RotatableLabelField implements PositionedField {
737
781
  private readonly content;
738
- private readonly x;
739
- private readonly y;
782
+ private x;
783
+ private y;
740
784
  private readonly type;
741
785
  private readonly height;
742
786
  private readonly barWidth;
743
- private rotation;
744
787
  private humanReadable;
745
788
  private readonly alignment;
746
789
  /**
@@ -753,22 +796,25 @@ declare class BarCode extends LabelField {
753
796
  * calculated automatically based on the symbology's standard ratio.
754
797
  */
755
798
  constructor(content: string, x: number, y: number, type: BarcodeType, height: number, barWidth?: number);
756
- setRotation(rotation: Rotation): void;
757
799
  setHumanReadable(humanReadable: BarcodeHumanReable): void;
800
+ setPosition(position: Point): void;
801
+ getPosition(): Point;
758
802
  commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
759
803
  }
760
804
 
761
- declare class Image extends LabelField {
805
+ declare class Image extends RotatableLabelField implements PositionedField {
762
806
  /**
763
807
  * X coordinate in dots
764
808
  */
765
- private readonly x;
809
+ private x;
766
810
  /**
767
811
  * Y coordinate in dots
768
812
  */
769
- private readonly y;
813
+ private y;
770
814
  private readonly image;
771
815
  constructor(x: number, y: number, image: BitmapLike);
816
+ setPosition(position: Point): void;
817
+ getPosition(): Point;
772
818
  commandForLanguage(language: PrinterLanguage, _config?: PrintConfig | undefined): Promise<Command>;
773
819
  /**
774
820
  * Create an image field for an image
@@ -782,12 +828,14 @@ declare class Image extends LabelField {
782
828
  static create(image: string | Blob, x: number, y: number, width?: number, height?: number): Promise<Image>;
783
829
  }
784
830
 
785
- declare class QRCode extends LabelField {
831
+ declare class QRCode extends RotatableLabelField implements PositionedField {
786
832
  private readonly content;
787
- private readonly x;
788
- private readonly y;
833
+ private x;
834
+ private y;
789
835
  private readonly width;
790
836
  constructor(content: string, x: number, y: number, width: number);
837
+ setPosition(position: Point): void;
838
+ getPosition(): Point;
791
839
  commandForLanguage(language: PrinterLanguage, config?: PrintConfig | undefined): Promise<Command>;
792
840
  }
793
841