@liquid-js/qr-code-styling 2.0.4 → 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 "https://unpkg.com/@liquid-js/qr-code-styling/lib/qr-code-styling.js";
36
+ import { QRCodeStyling, browserUtils } from "./index.ts";
36
37
 
37
- const options = {
38
- shape: "circle",
38
+ const qrCode = new QRCodeStyling({
39
+ width: 300,
40
+ height: 300,
39
41
  type: "svg",
40
- data: "h",
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
- type: "extra-rounded",
44
- gradient: {
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
- cornersSquareOptions: {
55
- type: "rounded",
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
- imageSize: 1,
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
@@ -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,