@liquid-js/qr-code-styling 3.0.1 → 3.1.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/README.md +139 -137
- package/lib/qr-code-styling-node.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -1,137 +1,139 @@
|
|
|
1
|
-
# QR Code Styling
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.org/package/@liquid-js/qr-code-styling)
|
|
4
|
-
|
|
5
|
-
JavaScript library for generating QR codes with customizable styling.
|
|
6
|
-
|
|
7
|
-
Try it here <https://styled-qr.liquidjs.io/>
|
|
8
|
-
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
|
-
<p float="left">
|
|
12
|
-
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/facebook.png" width="240" />
|
|
13
|
-
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/qr-styling.png" width="240" />
|
|
14
|
-
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/telegram.png" width="240" />
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
npm install @liquid-js/qr-code-styling
|
|
20
|
-
|
|
21
|
-
## API Documentation
|
|
22
|
-
|
|
23
|
-
<https://liquid-js.github.io/qr-code-styling/>
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
### Browser
|
|
28
|
-
|
|
29
|
-
```HTML
|
|
30
|
-
<!doctype html>
|
|
31
|
-
<html lang="en">
|
|
32
|
-
<head>
|
|
33
|
-
<meta charset="UTF-8" />
|
|
34
|
-
<title>QR Code Styling</title>
|
|
35
|
-
</head>
|
|
36
|
-
<body>
|
|
37
|
-
<div id="canvas"></div>
|
|
38
|
-
<button type="button" id="dl">Download</button>
|
|
39
|
-
<script type="module">
|
|
40
|
-
import { QRCodeStyling, browserUtils } from "https://unpkg.com/@liquid-js/qr-code-styling/lib/qr-code-styling.js";
|
|
41
|
-
|
|
42
|
-
const qrCode = new QRCodeStyling({
|
|
43
|
-
data: "https://www.facebook.com/",
|
|
44
|
-
image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
|
|
45
|
-
dotsOptions: {
|
|
46
|
-
color: "#4267b2",
|
|
47
|
-
type: "rounded",
|
|
48
|
-
size: 10
|
|
49
|
-
},
|
|
50
|
-
backgroundOptions: {
|
|
51
|
-
color: "#e9ebee",
|
|
52
|
-
margin: 1
|
|
53
|
-
},
|
|
54
|
-
imageOptions: {
|
|
55
|
-
crossOrigin: "anonymous",
|
|
56
|
-
margin: 1,
|
|
57
|
-
imageSize: 0.5
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
qrCode.append(document.getElementById("canvas"));
|
|
62
|
-
|
|
63
|
-
document.getElementById("dl").addEventListener("click", () => {
|
|
64
|
-
browserUtils.download(qrCode, { extension: "png" }, { width: 1200, height: 1200 });
|
|
65
|
-
});
|
|
66
|
-
</script>
|
|
67
|
-
</body>
|
|
68
|
-
</html>
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Node
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
import
|
|
77
|
-
import
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
1
|
+
# QR Code Styling
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.org/package/@liquid-js/qr-code-styling)
|
|
4
|
+
|
|
5
|
+
JavaScript library for generating QR codes with customizable styling.
|
|
6
|
+
|
|
7
|
+
Try it here <https://styled-qr.liquidjs.io/>
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
<p float="left">
|
|
12
|
+
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/facebook.png" width="240" />
|
|
13
|
+
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/qr-styling.png" width="240" />
|
|
14
|
+
<img style="display:inline-block" src="https://raw.githubusercontent.com/Liquid-JS/qr-code-styling/master/src/assets/telegram.png" width="240" />
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
npm install @liquid-js/qr-code-styling
|
|
20
|
+
|
|
21
|
+
## API Documentation
|
|
22
|
+
|
|
23
|
+
<https://liquid-js.github.io/qr-code-styling/>
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Browser
|
|
28
|
+
|
|
29
|
+
```HTML
|
|
30
|
+
<!doctype html>
|
|
31
|
+
<html lang="en">
|
|
32
|
+
<head>
|
|
33
|
+
<meta charset="UTF-8" />
|
|
34
|
+
<title>QR Code Styling</title>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<div id="canvas"></div>
|
|
38
|
+
<button type="button" id="dl">Download</button>
|
|
39
|
+
<script type="module">
|
|
40
|
+
import { QRCodeStyling, browserUtils } from "https://unpkg.com/@liquid-js/qr-code-styling/lib/qr-code-styling.js";
|
|
41
|
+
|
|
42
|
+
const qrCode = new QRCodeStyling({
|
|
43
|
+
data: "https://www.facebook.com/",
|
|
44
|
+
image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
|
|
45
|
+
dotsOptions: {
|
|
46
|
+
color: "#4267b2",
|
|
47
|
+
type: "rounded",
|
|
48
|
+
size: 10
|
|
49
|
+
},
|
|
50
|
+
backgroundOptions: {
|
|
51
|
+
color: "#e9ebee",
|
|
52
|
+
margin: 1
|
|
53
|
+
},
|
|
54
|
+
imageOptions: {
|
|
55
|
+
crossOrigin: "anonymous",
|
|
56
|
+
margin: 1,
|
|
57
|
+
imageSize: 0.5
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
qrCode.append(document.getElementById("canvas"));
|
|
62
|
+
|
|
63
|
+
document.getElementById("dl").addEventListener("click", () => {
|
|
64
|
+
browserUtils.download(qrCode, { extension: "png" }, { width: 1200, height: 1200 });
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Node
|
|
72
|
+
|
|
73
|
+
> :warning: **Note**: make sure to install optional peer dependencies when running on Node (not needed for browser environments)
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import { QRCodeStyling } from "@liquid-js/qr-code-styling";
|
|
77
|
+
import { writeFile } from "fs/promises";
|
|
78
|
+
import PDFDocument from "pdfkit";
|
|
79
|
+
import SVGtoPDF from "svg-to-pdfkit";
|
|
80
|
+
|
|
81
|
+
const qrCode = new QRCodeStyling({
|
|
82
|
+
data: "https://www.facebook.com/",
|
|
83
|
+
image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
|
|
84
|
+
dotsOptions: {
|
|
85
|
+
color: "#4267b2",
|
|
86
|
+
type: "rounded",
|
|
87
|
+
size: 10
|
|
88
|
+
},
|
|
89
|
+
backgroundOptions: {
|
|
90
|
+
color: "#e9ebee",
|
|
91
|
+
margin: 1
|
|
92
|
+
},
|
|
93
|
+
imageOptions: {
|
|
94
|
+
crossOrigin: "anonymous",
|
|
95
|
+
margin: 1,
|
|
96
|
+
imageSize: 0.5
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const svgCode = await qrCode.serialize();
|
|
101
|
+
|
|
102
|
+
const { width, height } = qrCode.size;
|
|
103
|
+
const buffers = [];
|
|
104
|
+
const doc = new PDFDocument({ size: [width, height] });
|
|
105
|
+
doc.on("data", (v) => buffers.push(v));
|
|
106
|
+
const buffer = await new Promise((resolve) => {
|
|
107
|
+
doc.on("end", () => {
|
|
108
|
+
resolve(Buffer.concat(buffers));
|
|
109
|
+
});
|
|
110
|
+
SVGtoPDF(doc, svgCode, 0, 0, {
|
|
111
|
+
width,
|
|
112
|
+
height,
|
|
113
|
+
assumePt: true
|
|
114
|
+
});
|
|
115
|
+
doc.end();
|
|
116
|
+
});
|
|
117
|
+
await writeFile("qr.pdf", buffer);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Kanji support
|
|
121
|
+
|
|
122
|
+
For Kanji mode to work, import `stringToBytesFuncs` from `@liquid-js/qr-code-styling/kanji` and inclue it with config.
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import { stringToBytesFuncs } from "@liquid-js/qr-code-styling/kanji";
|
|
126
|
+
|
|
127
|
+
const qrCode = new QRCodeStyling({
|
|
128
|
+
data: "漢字",
|
|
129
|
+
qrOptions: {
|
|
130
|
+
mode: Mode.kanji
|
|
131
|
+
},
|
|
132
|
+
stringToBytesFuncs
|
|
133
|
+
// ...other options
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[MIT License](https://github.com/Liquid-JS/qr-code-styling/blob/master/LICENSE)
|