label-printer 0.7.6 → 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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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();
|
|
@@ -2535,6 +2537,24 @@ var Text = class extends LabelField {
|
|
|
2535
2537
|
this.y = y;
|
|
2536
2538
|
this.formatted = formatted;
|
|
2537
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
|
+
}
|
|
2538
2558
|
/**
|
|
2539
2559
|
* Sets the field to single line
|
|
2540
2560
|
* @param width Max width of the text. Leave it undefined to allow the field to grow
|
|
@@ -2607,6 +2627,13 @@ var Text = class extends LabelField {
|
|
|
2607
2627
|
} else {
|
|
2608
2628
|
const elementNode = rootNode;
|
|
2609
2629
|
const tag = elementNode.rawTagName;
|
|
2630
|
+
if (tag == BREAK_TAG) {
|
|
2631
|
+
return {
|
|
2632
|
+
x: this.x,
|
|
2633
|
+
y: initialY + font.size + this.lineSpacing,
|
|
2634
|
+
command: this.context.generator.commandGroup([])
|
|
2635
|
+
};
|
|
2636
|
+
}
|
|
2610
2637
|
let commands = [];
|
|
2611
2638
|
let currentX = initialX;
|
|
2612
2639
|
let currentY = initialY;
|
|
@@ -2621,12 +2648,24 @@ var Text = class extends LabelField {
|
|
|
2621
2648
|
} else if (tag == ITALIC_TAG) {
|
|
2622
2649
|
baseFont.style = "italic";
|
|
2623
2650
|
}
|
|
2651
|
+
if (tag == PARAGRAPH_TAG) {
|
|
2652
|
+
if (initialX != this.x) {
|
|
2653
|
+
currentX = this.x;
|
|
2654
|
+
currentY = initialY + baseFont.size + this.lineSpacing;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2624
2657
|
elementNode.childNodes.forEach((node) => {
|
|
2625
2658
|
const { x, y, command } = this.generateFormattedRecursive(currentX, currentY, node, baseFont, baseFeatures);
|
|
2626
2659
|
currentX = x;
|
|
2627
2660
|
currentY = y;
|
|
2628
2661
|
commands.push(command);
|
|
2629
2662
|
});
|
|
2663
|
+
if (tag == PARAGRAPH_TAG) {
|
|
2664
|
+
if (!this.endsWithBreak(elementNode)) {
|
|
2665
|
+
currentX = this.x;
|
|
2666
|
+
currentY += baseFont.size + this.lineSpacing;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2630
2669
|
return {
|
|
2631
2670
|
x: currentX,
|
|
2632
2671
|
y: currentY,
|