label-printer 0.7.6 → 0.7.7

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
@@ -2523,6 +2523,8 @@ var BOLD_TAG = "b";
2523
2523
  var ITALIC_TAG = "i";
2524
2524
  var UNDERLINE_TAG = "u";
2525
2525
  var STRIKE_TAG = ["s", "del", "strike"];
2526
+ var PARAGRAPH_TAG = "p";
2527
+ var BREAK_TAG = "br";
2526
2528
  var Text = class extends LabelField {
2527
2529
  constructor(content, x, y, formatted = true) {
2528
2530
  super();
@@ -2607,6 +2609,13 @@ var Text = class extends LabelField {
2607
2609
  } else {
2608
2610
  const elementNode = rootNode;
2609
2611
  const tag = elementNode.rawTagName;
2612
+ if (tag == BREAK_TAG) {
2613
+ return {
2614
+ x: this.x,
2615
+ y: initialY + font.size + this.lineSpacing,
2616
+ command: this.context.generator.commandGroup([])
2617
+ };
2618
+ }
2610
2619
  let commands = [];
2611
2620
  let currentX = initialX;
2612
2621
  let currentY = initialY;
@@ -2621,12 +2630,38 @@ var Text = class extends LabelField {
2621
2630
  } else if (tag == ITALIC_TAG) {
2622
2631
  baseFont.style = "italic";
2623
2632
  }
2633
+ if (tag == PARAGRAPH_TAG) {
2634
+ const isAtFieldOrigin = initialX == this.x && initialY == this.y;
2635
+ if (!isAtFieldOrigin) {
2636
+ currentX = this.x;
2637
+ currentY = initialY + baseFont.size + this.lineSpacing;
2638
+ }
2639
+ }
2624
2640
  elementNode.childNodes.forEach((node) => {
2625
2641
  const { x, y, command } = this.generateFormattedRecursive(currentX, currentY, node, baseFont, baseFeatures);
2626
2642
  currentX = x;
2627
2643
  currentY = y;
2628
2644
  commands.push(command);
2629
2645
  });
2646
+ 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) {
2661
+ currentX = this.x;
2662
+ currentY += baseFont.size + this.lineSpacing;
2663
+ }
2664
+ }
2630
2665
  return {
2631
2666
  x: currentX,
2632
2667
  y: currentY,