@liquid-js/qr-code-styling 2.0.4 → 2.1.0
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 +15 -34
- package/lib/qr-code-styling-node.js +5 -3
- 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 +21 -12
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>
|
|
@@ -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
|
|
@@ -888,7 +890,7 @@ class QRSVG {
|
|
|
888
890
|
if (filter && !filter(i, j)) {
|
|
889
891
|
continue;
|
|
890
892
|
}
|
|
891
|
-
if (!this._qr?.isDark(
|
|
893
|
+
if (!this._qr?.isDark(j, i)) {
|
|
892
894
|
continue;
|
|
893
895
|
}
|
|
894
896
|
dot.draw(xBeginning + i * dotSize, yBeginning + j * dotSize, dotSize, (xOffset, yOffset) => {
|
|
@@ -896,7 +898,7 @@ class QRSVG {
|
|
|
896
898
|
return false;
|
|
897
899
|
if (filter && !filter(i + xOffset, j + yOffset))
|
|
898
900
|
return false;
|
|
899
|
-
return !!this._qr && this._qr.isDark(
|
|
901
|
+
return !!this._qr && this._qr.isDark(j + yOffset, i + xOffset);
|
|
900
902
|
});
|
|
901
903
|
if (dot._element && this._dotsClipPath) {
|
|
902
904
|
this._dotsClipPath.appendChild(dot._element);
|
|
@@ -1183,7 +1185,7 @@ let QRCodeStyling$1 = class QRCodeStyling {
|
|
|
1183
1185
|
}
|
|
1184
1186
|
const count = Math.ceil((this._options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
|
|
1185
1187
|
const margin = (this._options.backgroundOptions && this._options.backgroundOptions.margin) || 0;
|
|
1186
|
-
const size = this._options.dotsOptions.size * (count + 2 * margin);
|
|
1188
|
+
const size = Math.ceil(this._options.dotsOptions.size * (count + 2 * margin));
|
|
1187
1189
|
const qrSVG = new QRSVG({
|
|
1188
1190
|
...this._options,
|
|
1189
1191
|
width: size,
|