@liquid-js/qr-code-styling 3.0.0 → 3.0.2

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,137 @@
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
+ ```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)
@@ -43,9 +43,9 @@ function sanitizeGradient(gradient_newGradient) {
43
43
 
44
44
  (GradientType = GradientType || (GradientType = {})).radial = "radial", GradientType.linear = "linear",
45
45
  (DotType = DotType || (DotType = {})).dot = "dot", DotType.randomDot = "random-dot",
46
- DotType.rounded = "rounded", DotType.verticalLine = "vertical-line", DotType.horizontalLine = "horizontal-line",
47
- DotType.classy = "classy", DotType.classyRounded = "classy-rounded", DotType.square = "square",
48
- DotType.smallSquare = "small-square", DotType.extraRounded = "extra-rounded", DotType.diamond = "diamond",
46
+ DotType.rounded = "rounded", DotType.extraRounded = "extra-rounded", DotType.verticalLine = "vertical-line",
47
+ DotType.horizontalLine = "horizontal-line", DotType.classy = "classy", DotType.classyRounded = "classy-rounded",
48
+ DotType.square = "square", DotType.smallSquare = "small-square", DotType.diamond = "diamond",
49
49
  (CornerDotType = CornerDotType || (CornerDotType = {})).dot = "dot", CornerDotType.square = "square",
50
50
  CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded", CornerDotType.classy = "classy",
51
51
  CornerDotType.outpoint = "outpoint", CornerDotType.inpoint = "inpoint", (CornerSquareType = CornerSquareType || (CornerSquareType = {})).dot = "dot",
@@ -189,7 +189,7 @@ class QRCornerDot {
189
189
  let {size, x, y} = args;
190
190
  this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path");
191
191
  let move = !1, i = 0;
192
- this._element.setAttribute("d", [ "M", .925, .3538125, "c", 0, .0325869, -.0054931, .0644619, -.0164688, .095625, "S", .87825, .5147812, .850625, .5519688, "C", .823, .5891563, .7858125, .631125, .7390625, .677875, "S", .6331632, .7802256, .561625, .8446875, "L", .5, .8999375, "l", -.061625, -.05525, "C", .3668368, .7802256, .3076875, .724625, .2609375, .677875, "S", .177, .5891563, .149375, .5519688, "S", .1024444, .4806007, .0914688, .4494375, "S", .075, .3863994, .075, .3538125, "C", .075, .2872256, .0973125, .231625, .1419375, .187, "S", .2421631, .1200625, .30875, .1200625, "c", .0368369, 0, .0718994, .0077881, .1051875, .023375, "S", .4759131, .1809756, .5, .2093125, "c", .0240868, -.0283369, .0527744, -.0502881, .0860625, -.065875, "c", .0332882, -.0155869, .0683507, -.023375, .1051875, -.023375, "c", .0665869, 0, .1221875, .0223125, .1668125, .0669375, "S", .925, .2872256, .925, .3538125, "z" ].map((v => "string" == typeof v ? (i = 0,
192
+ this._element.setAttribute("d", [ "M", 1, .3262506, "c", 0, .0383376, -.0064626, .0758377, -.0193751, .1125001, "s", -.0356247, .076875, -.0681248, .1206252, "c", -.0325, .0437499, -.0762503, .0931247, -.1312501, .1481249, "C", .7262502, .7625008, .6566626, .8279132, .5724999, .9037505, "L", .5, .9687506, "L", .4275001, .9037505, "C", .3433374, .8279132, .2737499, .7625005, .21875, .7075007, "C", .1637501, .6525008, .1199999, .6031258, .0874999, .5593758, "S", .0322876, .4754133, .0193751, .4387506, "S", 0, .3645881, 0, .3262506, "c", 0, -.0783374, .0262499, -.1437498, .07875, -.1962499, "s", .1179124, -.07875, .1962499, -.07875, "c", .0433376, 0, .0845875, .0091625, .12375, .0274999, "S", .4716623, .1229131, .5, .1562506, "c", .0283374, -.0333375, .0620874, -.0591625, .1012502, -.0775, "c", .0391627, -.0183375, .0804126, -.0274999, .12375, -.0274999, "c", .0783374, 0, .1437497, .0262499, .1962501, .07875, "S", 1, .2479131, 1, .3262506, "z" ].map((v => "string" == typeof v ? (i = 0,
193
193
  move = v.toUpperCase() == v, v) : (i++, v *= size, move && (v += 1 == i % 2 ? x : y),
194
194
  numToAttr(v)))).join(" "));
195
195
  }
@@ -243,9 +243,9 @@ class QRCornerDot {
243
243
  }
244
244
  drawHeart({x, y, size, rotation}) {
245
245
  this.basicHeart({
246
- x: x - .2 * size / 2,
247
- y: y - .2 * size / 2,
248
- size: 1.2 * size,
246
+ x,
247
+ y,
248
+ size,
249
249
  rotation
250
250
  });
251
251
  }