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.mjs CHANGED
@@ -2537,6 +2537,24 @@ var Text = class extends LabelField {
2537
2537
  this.y = y;
2538
2538
  this.formatted = formatted;
2539
2539
  }
2540
+ endsWithBreak(node) {
2541
+ if (node.nodeType == NodeType.TEXT_NODE) {
2542
+ return node.innerText.trim() == "";
2543
+ }
2544
+ const elementNode = node;
2545
+ if (elementNode.rawTagName == BREAK_TAG) return true;
2546
+ const children = elementNode.childNodes;
2547
+ for (let i = children.length - 1; i >= 0; i--) {
2548
+ const child = children[i];
2549
+ if (child.nodeType == NodeType.TEXT_NODE) {
2550
+ if (child.innerText.trim() == "") continue;
2551
+ return false;
2552
+ }
2553
+ if (this.endsWithBreak(child)) return true;
2554
+ return false;
2555
+ }
2556
+ return false;
2557
+ }
2540
2558
  /**
2541
2559
  * Sets the field to single line
2542
2560
  * @param width Max width of the text. Leave it undefined to allow the field to grow
@@ -2631,8 +2649,7 @@ var Text = class extends LabelField {
2631
2649
  baseFont.style = "italic";
2632
2650
  }
2633
2651
  if (tag == PARAGRAPH_TAG) {
2634
- const isAtFieldOrigin = initialX == this.x && initialY == this.y;
2635
- if (!isAtFieldOrigin) {
2652
+ if (initialX != this.x) {
2636
2653
  currentX = this.x;
2637
2654
  currentY = initialY + baseFont.size + this.lineSpacing;
2638
2655
  }
@@ -2644,20 +2661,7 @@ var Text = class extends LabelField {
2644
2661
  commands.push(command);
2645
2662
  });
2646
2663
  if (tag == PARAGRAPH_TAG) {
2647
- let paragraphEndsWithBreak = false;
2648
- for (let i = elementNode.childNodes.length - 1; i >= 0; i--) {
2649
- const node = elementNode.childNodes[i];
2650
- if (node.nodeType == NodeType.TEXT_NODE) {
2651
- if (node.innerText.trim() == "") continue;
2652
- break;
2653
- }
2654
- const childElement = node;
2655
- if (childElement.rawTagName == BREAK_TAG) {
2656
- paragraphEndsWithBreak = true;
2657
- }
2658
- break;
2659
- }
2660
- if (!paragraphEndsWithBreak) {
2664
+ if (!this.endsWithBreak(elementNode)) {
2661
2665
  currentX = this.x;
2662
2666
  currentY += baseFont.size + this.lineSpacing;
2663
2667
  }