@liquid-js/qr-code-styling 2.0.3 → 2.0.5
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
|
@@ -31,52 +31,33 @@ If you have issues / suggestions / notes / questions, please open an issue or co
|
|
|
31
31
|
</head>
|
|
32
32
|
<body>
|
|
33
33
|
<div id="canvas"></div>
|
|
34
|
+
<button type="button" id="dl">Download</button>
|
|
34
35
|
<script type="module">
|
|
35
|
-
import { QRCodeStyling } from "
|
|
36
|
+
import { QRCodeStyling, browserUtils } from "./index.ts";
|
|
36
37
|
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
const qrCode = new QRCodeStyling({
|
|
39
|
+
width: 300,
|
|
40
|
+
height: 300,
|
|
39
41
|
type: "svg",
|
|
40
|
-
data: "
|
|
42
|
+
data: "https://www.facebook.com/",
|
|
41
43
|
image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
|
|
42
44
|
dotsOptions: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type: "linear",
|
|
46
|
-
rotation: Math.PI / 2,
|
|
47
|
-
colorStops: [
|
|
48
|
-
{ offset: 0, color: "blue" },
|
|
49
|
-
{ offset: 0.5, color: "red" },
|
|
50
|
-
{ offset: 1, color: "green" }
|
|
51
|
-
]
|
|
52
|
-
}
|
|
45
|
+
color: "#4267b2",
|
|
46
|
+
type: "rounded"
|
|
53
47
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
gradient: {
|
|
57
|
-
type: "linear",
|
|
58
|
-
rotation: Math.PI * 0.2,
|
|
59
|
-
colorStops: [
|
|
60
|
-
{
|
|
61
|
-
offset: 0,
|
|
62
|
-
color: "blue"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
offset: 1,
|
|
66
|
-
color: "red"
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
}
|
|
48
|
+
backgroundOptions: {
|
|
49
|
+
color: "#e9ebee"
|
|
70
50
|
},
|
|
71
51
|
imageOptions: {
|
|
72
52
|
crossOrigin: "anonymous",
|
|
73
|
-
|
|
74
|
-
margin: 1
|
|
53
|
+
margin: 20
|
|
75
54
|
}
|
|
76
|
-
};
|
|
77
|
-
const qrCode = new QRCodeStyling(options);
|
|
55
|
+
});
|
|
78
56
|
|
|
79
57
|
qrCode.append(document.getElementById("canvas"));
|
|
58
|
+
document.getElementById("dl").addEventListener("click", () => {
|
|
59
|
+
browserUtils.download(qrCode, { extension: "png" }, { width: 1200, height: 1200 });
|
|
60
|
+
});
|
|
80
61
|
</script>
|
|
81
62
|
</body>
|
|
82
63
|
</html>
|
|
@@ -107,7 +88,6 @@ new QRCodeStyling(options) => QRCodeStyling
|
|
|
107
88
|
| cornersSquareOptions | object | | Square in the corners styling options |
|
|
108
89
|
| cornersDotOptions | object | | Dots in the corners styling options |
|
|
109
90
|
| backgroundOptions | object \| boolean | `false` | QR background styling options, false to disable background |
|
|
110
|
-
| margin | number | `0` | Margin (in blocks) to add to the code |
|
|
111
91
|
|
|
112
92
|
`options.qrOptions` structure
|
|
113
93
|
|
|
@@ -153,11 +133,12 @@ new QRCodeStyling(options) => QRCodeStyling
|
|
|
153
133
|
|
|
154
134
|
`options.backgroundOptions` structure
|
|
155
135
|
|
|
156
|
-
| Property | Type | Default Value | Description
|
|
157
|
-
| -------- | ---------------- | ------------- |
|
|
158
|
-
| round | number (`0 - 1`) | `0` | Background roundnes
|
|
159
|
-
| color | string | |
|
|
160
|
-
| gradient | object | |
|
|
136
|
+
| Property | Type | Default Value | Description |
|
|
137
|
+
| -------- | ---------------- | ------------- | ----------------------------------------------------- |
|
|
138
|
+
| round | number (`0 - 1`) | `0` | Background roundnes |
|
|
139
|
+
| color | string | | |
|
|
140
|
+
| gradient | object | | |
|
|
141
|
+
| margin | number | `0` | Margin (in blocks) between background and the QR code |
|
|
161
142
|
|
|
162
143
|
Gradient structure
|
|
163
144
|
|
|
@@ -228,16 +209,16 @@ const extension = (svg, options) => {
|
|
|
228
209
|
const size = Math.min(width, height);
|
|
229
210
|
const border = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
230
211
|
const borderAttributes = {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
212
|
+
fill: "none",
|
|
213
|
+
x: (width - size + 40) / 2,
|
|
214
|
+
y: (height - size + 40) / 2,
|
|
215
|
+
width: size - 40,
|
|
216
|
+
height: size - 40,
|
|
217
|
+
stroke: "black",
|
|
237
218
|
"stroke-width": 40,
|
|
238
|
-
|
|
219
|
+
rx: 100
|
|
239
220
|
};
|
|
240
|
-
Object.keys(borderAttributes).forEach(attribute => {
|
|
221
|
+
Object.keys(borderAttributes).forEach((attribute) => {
|
|
241
222
|
border.setAttribute(attribute, borderAttributes[attribute]);
|
|
242
223
|
});
|
|
243
224
|
svg.appendChild(border);
|
package/lib/core/QROptions.d.ts
CHANGED
|
@@ -131,6 +131,8 @@ function sanitizeOptions(options) {
|
|
|
131
131
|
if (newOptions.dotsOptions.gradient) {
|
|
132
132
|
newOptions.dotsOptions.gradient = sanitizeGradient(newOptions.dotsOptions.gradient);
|
|
133
133
|
}
|
|
134
|
+
// Ensure integer dot size
|
|
135
|
+
newOptions.dotsOptions.size = Math.round(Math.max(0, newOptions.dotsOptions.size) || 10);
|
|
134
136
|
if (newOptions.cornersSquareOptions) {
|
|
135
137
|
newOptions.cornersSquareOptions = {
|
|
136
138
|
...newOptions.cornersSquareOptions
|
|
@@ -165,7 +167,6 @@ const defaultOptions = {
|
|
|
165
167
|
shape: ShapeType.square,
|
|
166
168
|
width: undefined,
|
|
167
169
|
height: undefined,
|
|
168
|
-
margin: 0,
|
|
169
170
|
data: "",
|
|
170
171
|
qrOptions: {
|
|
171
172
|
typeNumber: TypeNumber[0],
|
|
@@ -905,7 +906,8 @@ class QRSVG {
|
|
|
905
906
|
}
|
|
906
907
|
}
|
|
907
908
|
if (options.shape === ShapeType.circle) {
|
|
908
|
-
const
|
|
909
|
+
const margin = (this._options.backgroundOptions && this._options.backgroundOptions.margin) || 0;
|
|
910
|
+
const additionalDots = Math.floor((minSize / dotSize - count - 2 * margin) / 2);
|
|
909
911
|
const fakeCount = count + additionalDots * 2;
|
|
910
912
|
const xFakeBeginning = xBeginning - additionalDots * dotSize;
|
|
911
913
|
const yFakeBeginning = yBeginning - additionalDots * dotSize;
|
|
@@ -1182,7 +1184,8 @@ let QRCodeStyling$1 = class QRCodeStyling {
|
|
|
1182
1184
|
return;
|
|
1183
1185
|
}
|
|
1184
1186
|
const count = Math.ceil((this._options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
|
|
1185
|
-
const
|
|
1187
|
+
const margin = (this._options.backgroundOptions && this._options.backgroundOptions.margin) || 0;
|
|
1188
|
+
const size = Math.ceil(this._options.dotsOptions.size * (count + 2 * margin));
|
|
1186
1189
|
const qrSVG = new QRSVG({
|
|
1187
1190
|
...this._options,
|
|
1188
1191
|
width: size,
|