qrlayout-core 1.0.5 → 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
@@ -9,7 +9,7 @@ A powerful, framework-agnostic QR code layout engine for designing and printing
9
9
 
10
10
  - **Precise Layouts**: Define stickers in `mm`, `cm`, `in`, or `px`.
11
11
  - **Multiple Formats**: Export to Canvas (preview), PNG/JPEG (image), PDF (print), or ZPL (industrial thermal printers).
12
- - **Dynamic Content**: Use variable placeholders (e.g., `{{name}}`, `{{sku}}`) to batch generate unique stickers.
12
+ - **Dynamic Content**: Use variable placeholders (e.g., `{{name}}`, `{{visitorId}}`) to batch generate unique stickers.
13
13
  - **Lightweight**: Minimal dependencies. PDF export is optional to keep bundle size small.
14
14
 
15
15
  ## Keywords
@@ -125,19 +125,32 @@ pdfDoc.save("badges.pdf");
125
125
 
126
126
  | Property | Type | Description |
127
127
  |----------|------|-------------|
128
+ | `id` | `string` | Unique identifier for the layout. |
129
+ | `name` | `string` | Human-readable name of the layout. |
128
130
  | `width` | `number` | Width of the sticker. |
129
131
  | `height` | `number` | Height of the sticker. |
130
132
  | `unit` | `"mm" \| "cm" \| "in" \| "px"` | Unit of measurement. |
131
133
  | `elements` | `StickerElement[]` | List of items on the sticker. |
134
+ | `backgroundColor` | `string` | (Optional) Background color hex. |
135
+ | `backgroundImage` | `string` | (Optional) Background image URL. |
132
136
 
133
137
  ### `StickerElement` Interface
134
138
 
135
139
  | Property | Type | Description |
136
140
  |----------|------|-------------|
141
+ | `id` | `string` | Unique identifier for the element. |
137
142
  | `type` | `"text" \| "qr"` | Type of element. |
138
143
  | `x`, `y` | `number` | Position from top-left. |
139
144
  | `w`, `h` | `number` | Width and height. |
140
145
  | `content` | `string` | Text, URL, source. Supports `{{key}}` syntax. |
146
+ | `qrSeparator` | `string` | (Optional) Separator used to join consecutive `{{variables}}` (e.g., `|`, `,`). |
147
+ | `style.fontFamily` | `string` | Font family (e.g., 'sans-serif', 'Inter'). |
148
+ | `style.fontSize` | `number` | Font size (px). |
149
+ | `style.fontWeight` | `string \| number` | Font weight (e.g., 'bold', 700). |
150
+ | `style.textAlign` | `"left" \| "center" \| "right"` | Horizontal alignment. |
151
+ | `style.verticalAlign` | `"top" \| "middle" \| "bottom"` | Vertical alignment. |
152
+ | `style.color` | `string` | Text color hex code. |
153
+ | `style.backgroundColor` | `string` | Background color for the element. |
141
154
 
142
155
  ## License
143
156
 
@@ -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,20 +1,19 @@
1
1
  {
2
2
  "name": "qrlayout-core",
3
- "version": "1.0.5",
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",
7
7
  "qrcode",
8
8
  "qr-code",
9
- "qr code",
9
+ "qr-layout",
10
+ "qr-layout-designer",
10
11
  "layout",
11
- "sticker",
12
- "label",
12
+ "qr-sticker",
13
+ "qr-label",
13
14
  "generator",
14
15
  "renderer",
15
- "pdf",
16
16
  "zpl",
17
- "barcode",
18
17
  "thermal-printer"
19
18
  ],
20
19
  "author": "Shashidhar Naik <shashidharnaik8@gmail.com>",
@@ -57,8 +56,7 @@
57
56
  "jspdf": "^3.0.4"
58
57
  },
59
58
  "devDependencies": {
60
- "@types/jspdf": "^1.3.3",
61
59
  "@types/qrcode": "^1.5.6",
62
60
  "typescript": "^5.3.3"
63
61
  }
64
- }
62
+ }