qrlayout-core 1.0.6 → 1.0.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/README.md CHANGED
@@ -143,6 +143,7 @@ pdfDoc.save("badges.pdf");
143
143
  | `x`, `y` | `number` | Position from top-left. |
144
144
  | `w`, `h` | `number` | Width and height. |
145
145
  | `content` | `string` | Text, URL, source. Supports `{{key}}` syntax. |
146
+ | `qrSeparator` | `string` | (Optional) Separator used to join consecutive `{{variables}}` (e.g., `|`, `,`). |
146
147
  | `style.fontFamily` | `string` | Font family (e.g., 'sans-serif', 'Inter'). |
147
148
  | `style.fontSize` | `number` | Font size (px). |
148
149
  | `style.fontWeight` | `string \| number` | Font weight (e.g., 'bold', 700). |
@@ -17,6 +17,7 @@ export interface StickerElement {
17
17
  w: number;
18
18
  h: number;
19
19
  content: string;
20
+ qrSeparator?: string;
20
21
  style?: ElementStyle;
21
22
  }
22
23
  export type StickerData = Record<string, unknown>;
package/dist/pdf.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import jsPDF from "jspdf";
2
2
  import { generateQR } from "./qr/generator";
3
- function parseContent(content, data) {
4
- return content.replace(/\{\{(.*?)\}\}/g, (_, key) => {
3
+ function parseContent(content, data, separator) {
4
+ let processed = content;
5
+ if (separator) {
6
+ processed = processed.replace(/\}\}\s*\{\{/g, `}}${separator}{{`);
7
+ }
8
+ return processed.replace(/\{\{(.*?)\}\}/g, (_, key) => {
5
9
  const trimmedKey = String(key).trim();
6
10
  return data[trimmedKey] !== undefined ? String(data[trimmedKey]) : "";
7
11
  });
@@ -51,7 +55,7 @@ export async function exportToPDF(layout, dataList) {
51
55
  }
52
56
  }
53
57
  for (const element of layout.elements) {
54
- const filledContent = parseContent(element.content, data);
58
+ const filledContent = parseContent(element.content, data, element.type === "qr" ? element.qrSeparator : undefined);
55
59
  const { x, y, w, h } = element;
56
60
  if (element.type === "qr") {
57
61
  if (filledContent) {
@@ -12,8 +12,13 @@ export class StickerPrinter {
12
12
  }
13
13
  }
14
14
  // Parse variable content like "{{name}}"
15
- parseContent(content, data) {
16
- return content.replace(/\{\{(.*?)\}\}/g, (_, key) => {
15
+ parseContent(content, data, separator) {
16
+ let processed = content;
17
+ if (separator) {
18
+ // Replace spaces between braces or just consecutive braces with the separator
19
+ processed = processed.replace(/\}\}\s*\{\{/g, `}}${separator}{{`);
20
+ }
21
+ return processed.replace(/\{\{(.*?)\}\}/g, (_, key) => {
17
22
  const trimmedKey = key.trim();
18
23
  return data[trimmedKey] !== undefined ? String(data[trimmedKey]) : "";
19
24
  });
@@ -41,7 +46,7 @@ export class StickerPrinter {
41
46
  const y = this.toPx(element.y, layout.unit);
42
47
  const w = this.toPx(element.w, layout.unit);
43
48
  const h = this.toPx(element.h, layout.unit);
44
- const filledContent = this.parseContent(element.content, data);
49
+ const filledContent = this.parseContent(element.content, data, element.type === "qr" ? element.qrSeparator : undefined);
45
50
  if (element.type === "qr") {
46
51
  if (filledContent) {
47
52
  const qrUrl = await generateQR(filledContent);
@@ -153,7 +158,7 @@ export class StickerPrinter {
153
158
  zpl += `^PW${widthDots}\n`;
154
159
  zpl += `^LL${heightDots}\n`;
155
160
  for (const element of layout.elements) {
156
- const filledContent = this.parseContent(element.content, data);
161
+ const filledContent = this.parseContent(element.content, data, element.type === "qr" ? element.qrSeparator : undefined);
157
162
  const x = toDots(element.x, layout.unit);
158
163
  const y = toDots(element.y, layout.unit);
159
164
  zpl += `^FO${x},${y}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrlayout-core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "QR code layout builder, renderer, and exporter for stickers, labels, and PDFs",
5
5
  "keywords": [
6
6
  "qr",