@liquid-js/qr-code-styling 1.9.1 → 1.10.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/lib/core/QROptions.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface RequiredOptions extends Options {
|
|
|
4
4
|
shape: ShapeType;
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
|
+
margin: number;
|
|
7
8
|
data: string;
|
|
8
9
|
qrOptions: {
|
|
9
10
|
typeNumber: TypeNumber;
|
|
@@ -20,6 +21,7 @@ export interface RequiredOptions extends Options {
|
|
|
20
21
|
type: DotType;
|
|
21
22
|
color: string;
|
|
22
23
|
gradient?: Gradient;
|
|
24
|
+
size: number;
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
export declare const defaultOptions: RequiredOptions;
|
|
@@ -168,6 +168,7 @@ const defaultOptions = {
|
|
|
168
168
|
shape: exports.ShapeType.square,
|
|
169
169
|
width: undefined,
|
|
170
170
|
height: undefined,
|
|
171
|
+
margin: 0,
|
|
171
172
|
data: "",
|
|
172
173
|
qrOptions: {
|
|
173
174
|
typeNumber: TypeNumber[0],
|
|
@@ -182,7 +183,8 @@ const defaultOptions = {
|
|
|
182
183
|
},
|
|
183
184
|
dotsOptions: {
|
|
184
185
|
type: exports.DotType.square,
|
|
185
|
-
color: "#000"
|
|
186
|
+
color: "#000",
|
|
187
|
+
size: 10
|
|
186
188
|
}
|
|
187
189
|
};
|
|
188
190
|
|
|
@@ -772,9 +774,7 @@ class QRSVG {
|
|
|
772
774
|
}
|
|
773
775
|
async drawQR(qr) {
|
|
774
776
|
const count = qr.getModuleCount();
|
|
775
|
-
const
|
|
776
|
-
const realQRSize = this._options.shape === exports.ShapeType.circle ? minSize / Math.sqrt(2) : minSize;
|
|
777
|
-
const dotSize = Math.floor(realQRSize / count);
|
|
777
|
+
const dotSize = this._options.dotsOptions.size;
|
|
778
778
|
let drawImageSize = {
|
|
779
779
|
hideXDots: 0,
|
|
780
780
|
hideYDots: 0,
|
|
@@ -859,8 +859,7 @@ class QRSVG {
|
|
|
859
859
|
throw "The canvas is too small.";
|
|
860
860
|
}
|
|
861
861
|
const minSize = Math.min(options.width, options.height);
|
|
862
|
-
const
|
|
863
|
-
const dotSize = Math.floor(realQRSize / count);
|
|
862
|
+
const dotSize = this._options.dotsOptions.size;
|
|
864
863
|
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
865
864
|
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
866
865
|
const dot = new QRDot({ svg: this._element, type: options.dotsOptions.type, document: this._document });
|
|
@@ -898,7 +897,7 @@ class QRSVG {
|
|
|
898
897
|
}
|
|
899
898
|
}
|
|
900
899
|
if (options.shape === exports.ShapeType.circle) {
|
|
901
|
-
const additionalDots = Math.floor((minSize / dotSize - count) / 2);
|
|
900
|
+
const additionalDots = Math.floor((minSize / dotSize - count - 2 * this._options.margin) / 2);
|
|
902
901
|
const fakeCount = count + additionalDots * 2;
|
|
903
902
|
const xFakeBeginning = xBeginning - additionalDots * dotSize;
|
|
904
903
|
const yFakeBeginning = yBeginning - additionalDots * dotSize;
|
|
@@ -948,9 +947,7 @@ class QRSVG {
|
|
|
948
947
|
throw "Element code is not defined";
|
|
949
948
|
}
|
|
950
949
|
const count = this._qr.getModuleCount();
|
|
951
|
-
const
|
|
952
|
-
const realQRSize = options.shape === exports.ShapeType.circle ? minSize / Math.sqrt(2) : minSize;
|
|
953
|
-
const dotSize = Math.floor(realQRSize / count);
|
|
950
|
+
const dotSize = this._options.dotsOptions.size;
|
|
954
951
|
const cornersSquareSize = dotSize * 7;
|
|
955
952
|
const cornersDotSize = dotSize * 3;
|
|
956
953
|
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
@@ -1176,8 +1173,13 @@ let QRCodeStyling$1 = class QRCodeStyling {
|
|
|
1176
1173
|
if (!this._qr) {
|
|
1177
1174
|
return;
|
|
1178
1175
|
}
|
|
1179
|
-
this._options.
|
|
1180
|
-
const
|
|
1176
|
+
const count = Math.ceil((this._options.shape == exports.ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
|
|
1177
|
+
const size = this._options.dotsOptions.size * (count + 2 * this._options.margin);
|
|
1178
|
+
const qrSVG = new QRSVG({
|
|
1179
|
+
...this._options,
|
|
1180
|
+
width: size,
|
|
1181
|
+
height: size
|
|
1182
|
+
});
|
|
1181
1183
|
this._svg = qrSVG.getElement();
|
|
1182
1184
|
this._svgDrawingPromise = qrSVG.drawQR(this._qr).then(() => {
|
|
1183
1185
|
if (!this._svg)
|