qr-generator-styled 1.0.0 → 2.0.1
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/LICENSE +1 -1
- package/README.md +270 -23
- package/dist/cli/index.js +0 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/QRGenerator.d.ts +12 -0
- package/dist/lib/QRGenerator.d.ts.map +1 -1
- package/dist/lib/QRGenerator.js +47 -4
- package/dist/lib/QRGenerator.js.map +1 -1
- package/dist/lib/QRGenerator.new-features.test.d.ts +2 -0
- package/dist/lib/QRGenerator.new-features.test.d.ts.map +1 -0
- package/dist/lib/QRGenerator.new-features.test.js +235 -0
- package/dist/lib/QRGenerator.new-features.test.js.map +1 -0
- package/dist/lib/QRGenerator.test.d.ts +2 -0
- package/dist/lib/QRGenerator.test.d.ts.map +1 -0
- package/dist/lib/QRGenerator.test.js +39 -0
- package/dist/lib/QRGenerator.test.js.map +1 -0
- package/dist/lib/renderers/GradientRenderer.js +2 -2
- package/dist/lib/renderers/GradientRenderer.js.map +1 -1
- package/dist/lib/renderers/ModuleRenderer.d.ts +4 -0
- package/dist/lib/renderers/ModuleRenderer.d.ts.map +1 -1
- package/dist/lib/renderers/ModuleRenderer.js +32 -3
- package/dist/lib/renderers/ModuleRenderer.js.map +1 -1
- package/dist/lib/renderers/SVGRenderer.d.ts +23 -0
- package/dist/lib/renderers/SVGRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/SVGRenderer.js +74 -0
- package/dist/lib/renderers/SVGRenderer.js.map +1 -0
- package/dist/lib/utils/formatters.d.ts +26 -0
- package/dist/lib/utils/formatters.d.ts.map +1 -0
- package/dist/lib/utils/formatters.js +107 -0
- package/dist/lib/utils/formatters.js.map +1 -0
- package/dist/lib/utils/formatters.test.d.ts +2 -0
- package/dist/lib/utils/formatters.test.d.ts.map +1 -0
- package/dist/lib/utils/formatters.test.js +190 -0
- package/dist/lib/utils/formatters.test.js.map +1 -0
- package/dist/lib/utils/types.d.ts +72 -4
- package/dist/lib/utils/types.d.ts.map +1 -1
- package/dist/lib/utils/types.js +8 -2
- package/dist/lib/utils/types.js.map +1 -1
- package/dist/lib/utils/validators.d.ts.map +1 -1
- package/dist/lib/utils/validators.js +81 -4
- package/dist/lib/utils/validators.js.map +1 -1
- package/dist/lib/utils/validators.test.d.ts +2 -0
- package/dist/lib/utils/validators.test.d.ts.map +1 -0
- package/dist/lib/utils/validators.test.js +62 -0
- package/dist/lib/utils/validators.test.js.map +1 -0
- package/package.json +24 -6
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -11,13 +11,131 @@ A professional Node.js/TypeScript library for generating QR codes with advanced
|
|
|
11
11
|
- 🎨 **Customizable Styles**: Solid colors or multi-color gradients
|
|
12
12
|
- 🔷 **Rounded Modules**: Smooth, modern edges with radius control
|
|
13
13
|
- 🖼️ **Logo Support**: Add logos with circular or square backgrounds
|
|
14
|
-
-
|
|
14
|
+
- � **Specialized QR Types**: vCard, WiFi, Email, SMS, Geo location
|
|
15
|
+
- 📄 **SVG Export**: Vector format for perfect scalability
|
|
16
|
+
- 👁️ **Eye Customization**: Custom colors and shapes for finder patterns
|
|
17
|
+
- 📏 **Proper Margins**: Standard QR quiet zone support
|
|
18
|
+
- 📦 **Multiple Output Formats**: PNG, JPEG, SVG, Buffer, Data URL, or Canvas
|
|
15
19
|
- 🛠️ **CLI & API**: Use from command line or programmatically
|
|
16
20
|
- ✅ **Built-in Validation**: Options validated automatically
|
|
17
21
|
- 🎯 **Full TypeScript Support**: Complete type definitions included
|
|
18
22
|
- 🔧 **Modular Architecture**: Clean, maintainable code
|
|
19
23
|
|
|
20
|
-
##
|
|
24
|
+
## �️ Visual Examples
|
|
25
|
+
### Advanced Features
|
|
26
|
+
<table>
|
|
27
|
+
<tr>
|
|
28
|
+
<td align="center" valign="top">
|
|
29
|
+
<img src="docs/images/vcard-contact.png" width="180" alt="vCard Contact QR"/>
|
|
30
|
+
<br/>
|
|
31
|
+
<b>vCard Contact</b>
|
|
32
|
+
<br/>
|
|
33
|
+
<sub>Purple gradient with custom eyes</sub>
|
|
34
|
+
</td>
|
|
35
|
+
<td align="center" valign="top">
|
|
36
|
+
<img src="docs/images/wifi-network.png" width="180" alt="WiFi Network QR"/>
|
|
37
|
+
<br/>
|
|
38
|
+
<b>WiFi Network</b>
|
|
39
|
+
<br/>
|
|
40
|
+
<sub>Green gradient with rounded modules</sub>
|
|
41
|
+
</td>
|
|
42
|
+
<td align="center" valign="top">
|
|
43
|
+
<img src="docs/images/email-contact.png" width="180" alt="Email Contact QR"/>
|
|
44
|
+
<br/>
|
|
45
|
+
<b>Email Contact</b>
|
|
46
|
+
<br/>
|
|
47
|
+
<sub>Pink gradient with eye customization</sub>
|
|
48
|
+
</td>
|
|
49
|
+
<td align="center" valign="top">
|
|
50
|
+
<img src="docs/images/custom-eyes.png" width="180" alt="Custom Eyes QR"/>
|
|
51
|
+
<br/>
|
|
52
|
+
<b>Custom Eyes</b>
|
|
53
|
+
<br/>
|
|
54
|
+
<sub>Red eye accents (square modules)</sub>
|
|
55
|
+
</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</table>
|
|
58
|
+
|
|
59
|
+
### Basic Styles
|
|
60
|
+
|
|
61
|
+
<table>
|
|
62
|
+
<tr>
|
|
63
|
+
<td align="center" valign="top">
|
|
64
|
+
<img src="docs/images/basic-classic.png" width="150" alt="Classic Black & White QR"/>
|
|
65
|
+
<br/>
|
|
66
|
+
<b>Classic</b>
|
|
67
|
+
<br/>
|
|
68
|
+
<sub>Traditional black & white</sub>
|
|
69
|
+
</td>
|
|
70
|
+
<td align="center" valign="top">
|
|
71
|
+
<img src="docs/images/basic-blue.png" width="150" alt="Professional Blue QR"/>
|
|
72
|
+
<br/>
|
|
73
|
+
<b>Professional</b>
|
|
74
|
+
<br/>
|
|
75
|
+
<sub>Blue rounded design</sub>
|
|
76
|
+
</td>
|
|
77
|
+
<td align="center" valign="top">
|
|
78
|
+
<img src="docs/images/basic-green.png" width="150" alt="Eco Green QR"/>
|
|
79
|
+
<br/>
|
|
80
|
+
<b>Eco</b>
|
|
81
|
+
<br/>
|
|
82
|
+
<sub>Green with custom eyes</sub>
|
|
83
|
+
</td>
|
|
84
|
+
<td align="center" valign="top">
|
|
85
|
+
<img src="docs/images/basic-red.png" width="150" alt="Alert Red QR"/>
|
|
86
|
+
<br/>
|
|
87
|
+
<b>Alert</b>
|
|
88
|
+
<br/>
|
|
89
|
+
<sub>Red attention-grabbing</sub>
|
|
90
|
+
</td>
|
|
91
|
+
<td align="center" valign="top">
|
|
92
|
+
<img src="docs/images/basic-purple.png" width="150" alt="Creative Purple QR"/>
|
|
93
|
+
<br/>
|
|
94
|
+
<b>Creative</b>
|
|
95
|
+
<br/>
|
|
96
|
+
<sub>Purple artistic</sub>
|
|
97
|
+
</td>
|
|
98
|
+
</tr>
|
|
99
|
+
</table>
|
|
100
|
+
|
|
101
|
+
### With Logos
|
|
102
|
+
|
|
103
|
+
<table>
|
|
104
|
+
<tr>
|
|
105
|
+
<td align="center" valign="top">
|
|
106
|
+
<img src="docs/images/logo-corporate.png" width="160" alt="Corporate QR with Logo"/>
|
|
107
|
+
<br/>
|
|
108
|
+
<b>Corporate</b>
|
|
109
|
+
<br/>
|
|
110
|
+
<sub>Circle logo, professional blue</sub>
|
|
111
|
+
</td>
|
|
112
|
+
<td align="center" valign="top">
|
|
113
|
+
<img src="docs/images/logo-eco.png" width="160" alt="Eco Brand QR with Logo"/>
|
|
114
|
+
<br/>
|
|
115
|
+
<b>Eco Brand</b>
|
|
116
|
+
<br/>
|
|
117
|
+
<sub>Square logo, green gradient</sub>
|
|
118
|
+
</td>
|
|
119
|
+
<td align="center" valign="top">
|
|
120
|
+
<img src="docs/images/logo-tech.png" width="160" alt="Tech Startup QR with Logo"/>
|
|
121
|
+
<br/>
|
|
122
|
+
<b>Tech Startup</b>
|
|
123
|
+
<br/>
|
|
124
|
+
<sub>Circle logo, purple gradient</sub>
|
|
125
|
+
</td>
|
|
126
|
+
<td align="center" valign="top">
|
|
127
|
+
<img src="docs/images/logo-restaurant.png" width="160" alt="Restaurant QR with Logo"/>
|
|
128
|
+
<br/>
|
|
129
|
+
<b>Restaurant</b>
|
|
130
|
+
<br/>
|
|
131
|
+
<sub>Square logo, red gradient</sub>
|
|
132
|
+
</td>
|
|
133
|
+
</tr>
|
|
134
|
+
</table>
|
|
135
|
+
|
|
136
|
+
> 💡 **Tip**: All examples shown above were generated with this library! Check the [`examples/`](examples/) directory for source code.
|
|
137
|
+
|
|
138
|
+
## �📦 Installation
|
|
21
139
|
|
|
22
140
|
```bash
|
|
23
141
|
npm install qr-generator-styled
|
|
@@ -49,20 +167,57 @@ qr-styled --url "https://github.com" --logo ./my-logo.png --out my-qr.png
|
|
|
49
167
|
```typescript
|
|
50
168
|
import { QRGenerator, generateQRToFile } from 'qr-generator-styled';
|
|
51
169
|
|
|
52
|
-
//
|
|
170
|
+
// Basic URL QR code
|
|
53
171
|
const generator = new QRGenerator({
|
|
54
172
|
url: 'https://github.com',
|
|
55
173
|
gradient: true,
|
|
56
174
|
gradientColors: '#667eea,#764ba2'
|
|
57
175
|
});
|
|
58
176
|
|
|
59
|
-
await generator.generateToFile('qr-
|
|
177
|
+
await generator.generateToFile('qr-output.png');
|
|
178
|
+
|
|
179
|
+
// vCard contact QR code
|
|
180
|
+
const vCardGenerator = new QRGenerator({
|
|
181
|
+
type: 'vcard',
|
|
182
|
+
data: {
|
|
183
|
+
firstName: 'John',
|
|
184
|
+
lastName: 'Doe',
|
|
185
|
+
phone: '+1234567890',
|
|
186
|
+
email: 'john@example.com',
|
|
187
|
+
organization: 'Tech Corp'
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await vCardGenerator.generateToFile('contact-qr.png');
|
|
192
|
+
|
|
193
|
+
// WiFi QR code
|
|
194
|
+
const wifiGenerator = new QRGenerator({
|
|
195
|
+
type: 'wifi',
|
|
196
|
+
data: {
|
|
197
|
+
ssid: 'MyNetwork',
|
|
198
|
+
password: 'SecurePassword123',
|
|
199
|
+
encryption: 'WPA'
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
await wifiGenerator.generateToFile('wifi-qr.png');
|
|
60
204
|
|
|
61
|
-
//
|
|
205
|
+
// SVG export for scalability
|
|
206
|
+
const svgGenerator = new QRGenerator({
|
|
207
|
+
url: 'https://example.com',
|
|
208
|
+
foregroundColor: '#2196F3',
|
|
209
|
+
eyeColor: '#FF5722',
|
|
210
|
+
eyeRadius: 0.4
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const svg = await svgGenerator.generateToSVG();
|
|
214
|
+
await svgGenerator.generateToSVGFile('qr.svg');
|
|
215
|
+
|
|
216
|
+
// Helper function
|
|
62
217
|
await generateQRToFile(
|
|
63
218
|
{
|
|
64
219
|
url: 'https://github.com',
|
|
65
|
-
|
|
220
|
+
foregroundColor: '#2d3748'
|
|
66
221
|
},
|
|
67
222
|
'qr-output.png'
|
|
68
223
|
);
|
|
@@ -72,16 +227,29 @@ await generateQRToFile(
|
|
|
72
227
|
|
|
73
228
|
### Configuration Options
|
|
74
229
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
230
|
+
#### Basic Options
|
|
231
|
+
|
|
232
|
+
| Option | Type | Default | Description |
|
|
233
|
+
| ----------------- | ------------ | ------------ | ------------------------------------------------------ |
|
|
234
|
+
| `url` | `string` | _optional_ | URL or text content |
|
|
235
|
+
| `type` | `QRDataType` | `'text'` | QR data type (url, text, vcard, wifi, email, sms, geo) |
|
|
236
|
+
| `data` | `object` | _optional_ | Structured data for specialized types |
|
|
237
|
+
| `size` | `number` | `600` | Canvas size in pixels |
|
|
238
|
+
| `margin` | `number` | `4` | Quiet zone margin (4 modules standard) |
|
|
239
|
+
| `padding` | `number` | `40` | Canvas padding in pixels |
|
|
240
|
+
| `foregroundColor` | `string` | `'#000000'` | QR code color (hex format) |
|
|
241
|
+
| `color` | `string` | _deprecated_ | Use `foregroundColor` instead |
|
|
242
|
+
| `rounded` | `boolean` | `true` | Use rounded module corners |
|
|
243
|
+
| `moduleRadius` | `number` | `0.35` | Corner radius (0.0 - 0.5) |
|
|
244
|
+
| `cornerRadius` | `number` | `60` | Background corner radius |
|
|
245
|
+
| `backgroundColor` | `string` | `'#ffffff'` | Background color |
|
|
246
|
+
|
|
247
|
+
#### Eye Customization
|
|
248
|
+
|
|
249
|
+
| Option | Type | Default | Description |
|
|
250
|
+
| ----------- | -------- | ------- | --------------------------------- |
|
|
251
|
+
| `eyeColor` | `string` | `''` | Custom eye (finder pattern) color |
|
|
252
|
+
| `eyeRadius` | `number` | `0` | Eye corner radius (0.0 - 0.5) |
|
|
85
253
|
|
|
86
254
|
#### Gradient Options
|
|
87
255
|
|
|
@@ -93,12 +261,91 @@ await generateQRToFile(
|
|
|
93
261
|
|
|
94
262
|
#### Logo Options
|
|
95
263
|
|
|
96
|
-
| Option
|
|
97
|
-
|
|
|
98
|
-
| `logo`
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
264
|
+
| Option | Type | Default | Description |
|
|
265
|
+
| --------------------- | -------------------- | ----------- | ------------------------------ |
|
|
266
|
+
| `logo` | `string` | `''` | Logo image path or URL |
|
|
267
|
+
| `logoSize` | `number` | `120` | Logo size in pixels |
|
|
268
|
+
| `logoPadding` | `number` | `10` | Padding around logo |
|
|
269
|
+
| `logoShape` | `'circle'\|'square'` | `'circle'` | Logo background shape |
|
|
270
|
+
| `logoBackgroundColor` | `string` | `'#ffffff'` | Logo background color |
|
|
271
|
+
| `logoRadius` | `number` | `20` | Corner radius for square logos |
|
|
272
|
+
|
|
273
|
+
### Specialized QR Codes
|
|
274
|
+
|
|
275
|
+
#### vCard (Contact Card)
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
{
|
|
279
|
+
type: 'vcard',
|
|
280
|
+
data: {
|
|
281
|
+
firstName: 'John',
|
|
282
|
+
lastName: 'Doe',
|
|
283
|
+
organization: 'Tech Corp',
|
|
284
|
+
title: 'CEO',
|
|
285
|
+
phone: '+1234567890',
|
|
286
|
+
email: 'john@example.com',
|
|
287
|
+
url: 'https://example.com',
|
|
288
|
+
address: '123 Main St',
|
|
289
|
+
city: 'New York',
|
|
290
|
+
state: 'NY',
|
|
291
|
+
zip: '10001',
|
|
292
|
+
country: 'USA'
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### WiFi Network
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
{
|
|
301
|
+
type: 'wifi',
|
|
302
|
+
data: {
|
|
303
|
+
ssid: 'MyNetwork',
|
|
304
|
+
password: 'SecurePassword123',
|
|
305
|
+
encryption: 'WPA', // 'WPA' | 'WEP' | 'nopass'
|
|
306
|
+
hidden: false // optional
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### Email
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
{
|
|
315
|
+
type: 'email',
|
|
316
|
+
data: {
|
|
317
|
+
email: 'contact@example.com',
|
|
318
|
+
subject: 'Hello', // optional
|
|
319
|
+
body: 'Message text' // optional
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### SMS
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
{
|
|
328
|
+
type: 'sms',
|
|
329
|
+
data: {
|
|
330
|
+
phone: '+1234567890',
|
|
331
|
+
message: 'Hello!' // optional
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
#### Geo Location
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
{
|
|
340
|
+
type: 'geo',
|
|
341
|
+
data: {
|
|
342
|
+
latitude: 40.7128,
|
|
343
|
+
longitude: -74.0060
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
| `logoRadius` | `number` | `20` | Corner radius (for square) |
|
|
102
349
|
|
|
103
350
|
### API Reference
|
|
104
351
|
|
|
@@ -203,7 +450,7 @@ await generator.generateToFile('instagram-qr.png');
|
|
|
203
450
|
```typescript
|
|
204
451
|
const generator = new QRGenerator({
|
|
205
452
|
url: 'https://your-company.com',
|
|
206
|
-
|
|
453
|
+
foregroundColor: '#1a365d',
|
|
207
454
|
logo: './company-logo.png',
|
|
208
455
|
logoShape: 'square',
|
|
209
456
|
logoRadius: 15,
|
package/dist/cli/index.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { QRGenerator, generateQR, generateQRToFile } from './lib/QRGenerator.js';
|
|
6
6
|
export { DEFAULT_OPTIONS, VALID_LOGO_SHAPES, VALID_ERROR_CORRECTION_LEVELS } from './lib/utils/types.js';
|
|
7
|
-
export type { QROptions, LogoShape, ErrorCorrectionLevel } from './lib/utils/types.js';
|
|
7
|
+
export type { QROptions, QRDataType, VCardData, WiFiData, EmailData, SMSData, GeoData, LogoShape, ErrorCorrectionLevel } from './lib/utils/types.js';
|
|
8
8
|
export { validateOptions, normalizeOptions } from './lib/utils/validators.js';
|
|
9
|
+
export { formatVCard, formatWiFi, formatEmail, formatSMS, formatGeo, formatQRData } from './lib/utils/formatters.js';
|
|
9
10
|
export { BackgroundRenderer } from './lib/renderers/BackgroundRenderer.js';
|
|
10
11
|
export { GradientRenderer } from './lib/renderers/GradientRenderer.js';
|
|
11
12
|
export { ModuleRenderer } from './lib/renderers/ModuleRenderer.js';
|
|
12
13
|
export { LogoRenderer } from './lib/renderers/LogoRenderer.js';
|
|
14
|
+
export { SVGRenderer } from './lib/renderers/SVGRenderer.js';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,SAAS,EACT,SAAS,EACT,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,EACP,OAAO,EACP,SAAS,EACT,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE9E,OAAO,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
export { QRGenerator, generateQR, generateQRToFile } from './lib/QRGenerator.js';
|
|
6
6
|
export { DEFAULT_OPTIONS, VALID_LOGO_SHAPES, VALID_ERROR_CORRECTION_LEVELS } from './lib/utils/types.js';
|
|
7
7
|
export { validateOptions, normalizeOptions } from './lib/utils/validators.js';
|
|
8
|
+
export { formatVCard, formatWiFi, formatEmail, formatSMS, formatGeo, formatQRData } from './lib/utils/formatters.js';
|
|
8
9
|
export { BackgroundRenderer } from './lib/renderers/BackgroundRenderer.js';
|
|
9
10
|
export { GradientRenderer } from './lib/renderers/GradientRenderer.js';
|
|
10
11
|
export { ModuleRenderer } from './lib/renderers/ModuleRenderer.js';
|
|
11
12
|
export { LogoRenderer } from './lib/renderers/LogoRenderer.js';
|
|
13
|
+
export { SVGRenderer } from './lib/renderers/SVGRenderer.js';
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAc9B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE9E,OAAO,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -9,6 +9,10 @@ export declare class QRGenerator {
|
|
|
9
9
|
* Creates a new QR generator instance
|
|
10
10
|
*/
|
|
11
11
|
constructor(options: QROptions);
|
|
12
|
+
/**
|
|
13
|
+
* Generates QR code content from options
|
|
14
|
+
*/
|
|
15
|
+
private getQRContent;
|
|
12
16
|
/**
|
|
13
17
|
* Generates QR code and returns the canvas
|
|
14
18
|
*/
|
|
@@ -25,6 +29,14 @@ export declare class QRGenerator {
|
|
|
25
29
|
* Generates QR code and returns data URL
|
|
26
30
|
*/
|
|
27
31
|
generateToDataURL(format?: 'png' | 'jpeg'): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Generates QR code as SVG string
|
|
34
|
+
*/
|
|
35
|
+
generateToSVG(): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Generates QR code as SVG and saves to file
|
|
38
|
+
*/
|
|
39
|
+
generateToSVGFile(outputPath: string): Promise<void>;
|
|
28
40
|
/**
|
|
29
41
|
* Updates generator options
|
|
30
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QRGenerator.d.ts","sourceRoot":"","sources":["../../src/lib/QRGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"QRGenerator.d.ts","sourceRoot":"","sources":["../../src/lib/QRGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAO9C,OAAO,EAAE,SAAS,EAAmB,MAAM,kBAAkB,CAAC;AAI9D;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAsB;IAErC;;OAEG;gBACS,OAAO,EAAE,SAAS;IAc9B;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAmDjC;;OAEG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMvD;;OAEG;IACG,gBAAgB,CAAC,MAAM,GAAE,KAAK,GAAG,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAMvE;;OAEG;IACG,iBAAiB,CAAC,MAAM,GAAE,KAAK,GAAG,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAQxE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAgBtC;;OAEG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1D;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;CAajD;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAGpE;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,SAAS,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
package/dist/lib/QRGenerator.js
CHANGED
|
@@ -5,8 +5,10 @@ import { BackgroundRenderer } from './renderers/BackgroundRenderer.js';
|
|
|
5
5
|
import { GradientRenderer } from './renderers/GradientRenderer.js';
|
|
6
6
|
import { ModuleRenderer } from './renderers/ModuleRenderer.js';
|
|
7
7
|
import { LogoRenderer } from './renderers/LogoRenderer.js';
|
|
8
|
+
import { SVGRenderer } from './renderers/SVGRenderer.js';
|
|
8
9
|
import { DEFAULT_OPTIONS } from './utils/types.js';
|
|
9
10
|
import { validateOptions, normalizeOptions } from './utils/validators.js';
|
|
11
|
+
import { formatQRData } from './utils/formatters.js';
|
|
10
12
|
/**
|
|
11
13
|
* QR Code Generator with advanced styling options
|
|
12
14
|
*/
|
|
@@ -16,18 +18,32 @@ export class QRGenerator {
|
|
|
16
18
|
*/
|
|
17
19
|
constructor(options) {
|
|
18
20
|
this.options = normalizeOptions(options, DEFAULT_OPTIONS);
|
|
21
|
+
// Support deprecated 'color' field with backward compatibility
|
|
22
|
+
if (options.color && !options.foregroundColor) {
|
|
23
|
+
this.options.foregroundColor = options.color;
|
|
24
|
+
}
|
|
19
25
|
validateOptions(this.options);
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Generates QR code content from options
|
|
29
|
+
*/
|
|
30
|
+
getQRContent() {
|
|
31
|
+
const { type, url, data } = this.options;
|
|
32
|
+
// Use formatter to handle different data types
|
|
33
|
+
return formatQRData(type, url, data);
|
|
34
|
+
}
|
|
21
35
|
/**
|
|
22
36
|
* Generates QR code and returns the canvas
|
|
23
37
|
*/
|
|
24
38
|
async generate() {
|
|
25
|
-
const {
|
|
39
|
+
const { errorCorrectionLevel, size, padding, foregroundColor } = this.options;
|
|
26
40
|
const qrSize = size - padding * 2;
|
|
41
|
+
// Get formatted content based on type
|
|
42
|
+
const content = this.getQRContent();
|
|
27
43
|
// Generate QR data
|
|
28
|
-
const qrData = await QRCode.create(
|
|
44
|
+
const qrData = await QRCode.create(content, {
|
|
29
45
|
errorCorrectionLevel
|
|
30
|
-
});
|
|
46
|
+
}); // margin option not in types but works
|
|
31
47
|
const modules = qrData.modules;
|
|
32
48
|
const moduleCount = modules.size;
|
|
33
49
|
const moduleSize = qrSize / moduleCount;
|
|
@@ -41,9 +57,10 @@ export class QRGenerator {
|
|
|
41
57
|
// Create fill style (gradient or solid)
|
|
42
58
|
const gradientRenderer = new GradientRenderer(ctx, this.options);
|
|
43
59
|
const fillStyle = gradientRenderer.getFillStyle();
|
|
44
|
-
// Render QR modules
|
|
60
|
+
// Render QR modules with eye customization support
|
|
45
61
|
const moduleRenderer = new ModuleRenderer(ctx, modules, {
|
|
46
62
|
...this.options,
|
|
63
|
+
color: foregroundColor, // Use new foregroundColor
|
|
47
64
|
moduleCount,
|
|
48
65
|
moduleSize
|
|
49
66
|
});
|
|
@@ -82,11 +99,37 @@ export class QRGenerator {
|
|
|
82
99
|
}
|
|
83
100
|
return canvas.toDataURL('image/png');
|
|
84
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Generates QR code as SVG string
|
|
104
|
+
*/
|
|
105
|
+
async generateToSVG() {
|
|
106
|
+
const { errorCorrectionLevel, size } = this.options;
|
|
107
|
+
// Get formatted content based on type
|
|
108
|
+
const content = this.getQRContent();
|
|
109
|
+
// Generate QR data
|
|
110
|
+
const qrData = await QRCode.create(content, {
|
|
111
|
+
errorCorrectionLevel
|
|
112
|
+
});
|
|
113
|
+
// Use SVG renderer
|
|
114
|
+
const svgRenderer = new SVGRenderer(qrData, this.options, size);
|
|
115
|
+
return svgRenderer.generate();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generates QR code as SVG and saves to file
|
|
119
|
+
*/
|
|
120
|
+
async generateToSVGFile(outputPath) {
|
|
121
|
+
const svg = await this.generateToSVG();
|
|
122
|
+
fs.writeFileSync(outputPath, svg, 'utf-8');
|
|
123
|
+
}
|
|
85
124
|
/**
|
|
86
125
|
* Updates generator options
|
|
87
126
|
*/
|
|
88
127
|
updateOptions(options) {
|
|
89
128
|
this.options = normalizeOptions({ ...this.options, ...options }, DEFAULT_OPTIONS);
|
|
129
|
+
// Support deprecated 'color' field
|
|
130
|
+
if (options.color && !options.foregroundColor) {
|
|
131
|
+
this.options.foregroundColor = options.color;
|
|
132
|
+
}
|
|
90
133
|
validateOptions(this.options);
|
|
91
134
|
}
|
|
92
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QRGenerator.js","sourceRoot":"","sources":["../../src/lib/QRGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAU,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAa,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"QRGenerator.js","sourceRoot":"","sources":["../../src/lib/QRGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAU,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAa,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAA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