label-printer 0.7.7 → 0.7.8

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
@@ -631,6 +631,7 @@ declare class Text extends LabelField {
631
631
  private type;
632
632
  private context;
633
633
  private readonly lineSpacing;
634
+ private endsWithBreak;
634
635
  /**
635
636
  * Width of the text.
636
637
  * If set, the text will be clipped to this size
package/dist/index.d.ts CHANGED
@@ -631,6 +631,7 @@ declare class Text extends LabelField {
631
631
  private type;
632
632
  private context;
633
633
  private readonly lineSpacing;
634
+ private endsWithBreak;
634
635
  /**
635
636
  * Width of the text.
636
637
  * If set, the text will be clipped to this size
package/dist/index.js CHANGED
@@ -2562,6 +2562,24 @@ var Text = class extends LabelField {
2562
2562
  this.y = y;
2563
2563
  this.formatted = formatted;
2564
2564
  }
2565
+ endsWithBreak(node) {
2566
+ if (node.nodeType == import_node_html_parser.NodeType.TEXT_NODE) {
2567
+ return node.innerText.trim() == "";
2568
+ }
2569
+ const elementNode = node;
2570
+ if (elementNode.rawTagName == BREAK_TAG) return true;
2571
+ const children = elementNode.childNodes;
2572
+ for (let i = children.length - 1; i >= 0; i--) {
2573
+ const child = children[i];
2574
+ if (child.nodeType == import_node_html_parser.NodeType.TEXT_NODE) {
2575
+ if (child.innerText.trim() == "") continue;
2576
+ return false;
2577
+ }
2578
+ if (this.endsWithBreak(child)) return true;
2579
+ return false;
2580
+ }
2581
+ return false;
2582
+ }
2565
2583
  /**
2566
2584
  * Sets the field to single line
2567
2585
  * @param width Max width of the text. Leave it undefined to allow the field to grow
@@ -2656,8 +2674,7 @@ var Text = class extends LabelField {
2656
2674
  baseFont.style = "italic";
2657
2675
  }
2658
2676
  if (tag == PARAGRAPH_TAG) {
2659
- const isAtFieldOrigin = initialX == this.x && initialY == this.y;
2660
- if (!isAtFieldOrigin) {
2677
+ if (initialX != this.x) {
2661
2678
  currentX = this.x;
2662
2679
  currentY = initialY + baseFont.size + this.lineSpacing;
2663
2680
  }
@@ -2669,20 +2686,7 @@ var Text = class extends LabelField {
2669
2686
  commands.push(command);
2670
2687
  });
2671
2688
  if (tag == PARAGRAPH_TAG) {
2672
- let paragraphEndsWithBreak = false;
2673
- for (let i = elementNode.childNodes.length - 1; i >= 0; i--) {
2674
- const node = elementNode.childNodes[i];
2675
- if (node.nodeType == import_node_html_parser.NodeType.TEXT_NODE) {
2676
- if (node.innerText.trim() == "") continue;
2677
- break;
2678
- }
2679
- const childElement = node;
2680
- if (childElement.rawTagName == BREAK_TAG) {
2681
- paragraphEndsWithBreak = true;
2682
- }
2683
- break;
2684
- }
2685
- if (!paragraphEndsWithBreak) {
2689
+ if (!this.endsWithBreak(elementNode)) {
2686
2690
  currentX = this.x;
2687
2691
  currentY += baseFont.size + this.lineSpacing;
2688
2692
  }