@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 CHANGED
@@ -1,137 +1,139 @@
1
- # QR Code Styling
2
-
3
- [![Version](https://img.shields.io/npm/v/@liquid-js/qr-code-styling.svg)](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
- ```js
74
- import { QRCodeStyling } from "@liquid-js/qr-code-styling";
75
- import { writeFile } from "fs/promises";
76
- import PDFDocument from "pdfkit";
77
- import SVGtoPDF from "svg-to-pdfkit";
78
-
79
- const qrCode = new QRCodeStyling({
80
- data: "https://www.facebook.com/",
81
- image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
82
- dotsOptions: {
83
- color: "#4267b2",
84
- type: "rounded",
85
- size: 10
86
- },
87
- backgroundOptions: {
88
- color: "#e9ebee",
89
- margin: 1
90
- },
91
- imageOptions: {
92
- crossOrigin: "anonymous",
93
- margin: 1,
94
- imageSize: 0.5
95
- }
96
- });
97
-
98
- const svgCode = await qrCode.serialize();
99
-
100
- const { width, height } = qrCode.size;
101
- const buffers = [];
102
- const doc = new PDFDocument({ size: [width, height] });
103
- doc.on("data", (v) => buffers.push(v));
104
- const buffer = await new Promise((resolve) => {
105
- doc.on("end", () => {
106
- resolve(Buffer.concat(buffers));
107
- });
108
- SVGtoPDF(doc, svgCode, 0, 0, {
109
- width,
110
- height,
111
- assumePt: true
112
- });
113
- doc.end();
114
- });
115
- await writeFile("qr.pdf", buffer);
116
- ```
117
-
118
- ### Kanji support
119
-
120
- For Kanji mode to work, import `stringToBytesFuncs` from `@liquid-js/qr-code-styling/kanji` and inclue it with config.
121
-
122
- ```js
123
- import { stringToBytesFuncs } from "@liquid-js/qr-code-styling/kanji";
124
-
125
- const qrCode = new QRCodeStyling({
126
- data: "漢字",
127
- qrOptions: {
128
- mode: Mode.kanji
129
- },
130
- stringToBytesFuncs
131
- // ...other options
132
- });
133
- ```
134
-
135
- ## License
136
-
137
- [MIT License](https://github.com/Liquid-JS/qr-code-styling/blob/master/LICENSE)
1
+ # QR Code Styling
2
+
3
+ [![Version](https://img.shields.io/npm/v/@liquid-js/qr-code-styling.svg)](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)