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.js CHANGED
@@ -2548,6 +2548,8 @@ var BOLD_TAG = "b";
2548
2548
  var ITALIC_TAG = "i";
2549
2549
  var UNDERLINE_TAG = "u";
2550
2550
  var STRIKE_TAG = ["s", "del", "strike"];
2551
+ var PARAGRAPH_TAG = "p";
2552
+ var BREAK_TAG = "br";
2551
2553
  var Text = class extends LabelField {
2552
2554
  constructor(content, x, y, formatted = true) {
2553
2555
  super();
@@ -2632,6 +2634,13 @@ var Text = class extends LabelField {
2632
2634
  } else {
2633
2635
  const elementNode = rootNode;
2634
2636
  const tag = elementNode.rawTagName;
2637
+ if (tag == BREAK_TAG) {
2638
+ return {
2639
+ x: this.x,
2640
+ y: initialY + font.size + this.lineSpacing,
2641
+ command: this.context.generator.commandGroup([])
2642
+ };
2643
+ }
2635
2644
  let commands = [];
2636
2645
  let currentX = initialX;
2637
2646
  let currentY = initialY;
@@ -2646,12 +2655,38 @@ var Text = class extends LabelField {
2646
2655
  } else if (tag == ITALIC_TAG) {
2647
2656
  baseFont.style = "italic";
2648
2657
  }
2658
+ if (tag == PARAGRAPH_TAG) {
2659
+ const isAtFieldOrigin = initialX == this.x && initialY == this.y;
2660
+ if (!isAtFieldOrigin) {
2661
+ currentX = this.x;
2662
+ currentY = initialY + baseFont.size + this.lineSpacing;
2663
+ }
2664
+ }
2649
2665
  elementNode.childNodes.forEach((node) => {
2650
2666
  const { x, y, command } = this.generateFormattedRecursive(currentX, currentY, node, baseFont, baseFeatures);
2651
2667
  currentX = x;
2652
2668
  currentY = y;
2653
2669
  commands.push(command);
2654
2670
  });
2671
+ 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) {
2686
+ currentX = this.x;
2687
+ currentY += baseFont.size + this.lineSpacing;
2688
+ }
2689
+ }
2655
2690
  return {
2656
2691
  x: currentX,
2657
2692
  y: currentY,