@liquid-js/qr-code-styling 1.10.7 → 2.0.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/LICENSE +21 -21
- package/lib/index.d.ts +3 -2
- package/lib/node.d.ts +2 -0
- package/lib/qr-code-styling-node.js +51 -55
- 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 +84 -74
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Denys Kozak
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Denys Kozak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrorCorrectionPercents } from "./constants/errorCorrectionPercents";
|
|
2
2
|
import { QRCodeStyling } from "./core/QRCodeStyling";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _browserUtils from "./tools/browserUtils";
|
|
4
|
+
export declare const browserUtils: typeof _browserUtils | undefined;
|
|
4
5
|
export * from "./types";
|
|
5
|
-
export { ErrorCorrectionPercents, QRCodeStyling
|
|
6
|
+
export { ErrorCorrectionPercents, QRCodeStyling };
|
package/lib/node.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { RequiredOptions } from "./core/QROptions";
|
|
|
2
2
|
import { QRCodeStyling as _QRCodeStyling } from "./index";
|
|
3
3
|
export { ErrorCorrectionPercents } from "./constants/errorCorrectionPercents";
|
|
4
4
|
export * from "./types";
|
|
5
|
+
import type * as _browserUtils from "./tools/browserUtils";
|
|
6
|
+
export declare const browserUtils: typeof _browserUtils | undefined;
|
|
5
7
|
export declare class QRCodeStyling extends _QRCodeStyling {
|
|
6
8
|
constructor(options: RequiredOptions);
|
|
7
9
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { DOMImplementation, XMLSerializer as XMLSerializer$1, DOMParser as DOMParser$1 } from '@xmldom/xmldom';
|
|
2
|
+
import { fileTypeFromBuffer } from 'file-type';
|
|
3
|
+
import sharp from 'sharp';
|
|
4
|
+
import qrcode from 'qrcode-generator';
|
|
2
5
|
|
|
3
|
-
var
|
|
4
|
-
var fileType = require('file-type');
|
|
5
|
-
var fetch = require('node-fetch');
|
|
6
|
-
var sharp = require('sharp');
|
|
7
|
-
var qrcode = require('qrcode-generator');
|
|
8
|
-
|
|
9
|
-
exports.DotType = void 0;
|
|
6
|
+
var DotType;
|
|
10
7
|
(function (DotType) {
|
|
11
8
|
DotType["dots"] = "dots";
|
|
12
9
|
DotType["rounded"] = "rounded";
|
|
@@ -14,68 +11,68 @@ exports.DotType = void 0;
|
|
|
14
11
|
DotType["classyRounded"] = "classy-rounded";
|
|
15
12
|
DotType["square"] = "square";
|
|
16
13
|
DotType["extraRounded"] = "extra-rounded";
|
|
17
|
-
})(
|
|
18
|
-
|
|
14
|
+
})(DotType || (DotType = {}));
|
|
15
|
+
var CornerDotType;
|
|
19
16
|
(function (CornerDotType) {
|
|
20
17
|
CornerDotType["dot"] = "dot";
|
|
21
18
|
CornerDotType["square"] = "square";
|
|
22
|
-
})(
|
|
23
|
-
|
|
19
|
+
})(CornerDotType || (CornerDotType = {}));
|
|
20
|
+
var CornerSquareType;
|
|
24
21
|
(function (CornerSquareType) {
|
|
25
22
|
CornerSquareType["dot"] = "dot";
|
|
26
23
|
CornerSquareType["square"] = "square";
|
|
27
24
|
CornerSquareType["extraRounded"] = "extra-rounded";
|
|
28
|
-
})(
|
|
29
|
-
|
|
25
|
+
})(CornerSquareType || (CornerSquareType = {}));
|
|
26
|
+
var GradientType;
|
|
30
27
|
(function (GradientType) {
|
|
31
28
|
GradientType["radial"] = "radial";
|
|
32
29
|
GradientType["linear"] = "linear";
|
|
33
|
-
})(
|
|
34
|
-
|
|
30
|
+
})(GradientType || (GradientType = {}));
|
|
31
|
+
var ShapeType;
|
|
35
32
|
(function (ShapeType) {
|
|
36
33
|
ShapeType["square"] = "square";
|
|
37
34
|
ShapeType["circle"] = "circle";
|
|
38
|
-
})(
|
|
35
|
+
})(ShapeType || (ShapeType = {}));
|
|
39
36
|
const TypeNumber = Array(41)
|
|
40
37
|
.fill(0)
|
|
41
38
|
.map((_, i) => i);
|
|
42
|
-
|
|
39
|
+
var ErrorCorrectionLevel;
|
|
43
40
|
(function (ErrorCorrectionLevel) {
|
|
44
41
|
ErrorCorrectionLevel["L"] = "L";
|
|
45
42
|
ErrorCorrectionLevel["M"] = "M";
|
|
46
43
|
ErrorCorrectionLevel["Q"] = "Q";
|
|
47
44
|
ErrorCorrectionLevel["H"] = "H";
|
|
48
|
-
})(
|
|
49
|
-
|
|
45
|
+
})(ErrorCorrectionLevel || (ErrorCorrectionLevel = {}));
|
|
46
|
+
var Mode;
|
|
50
47
|
(function (Mode) {
|
|
51
48
|
Mode["numeric"] = "Numeric";
|
|
52
49
|
Mode["alphanumeric"] = "Alphanumeric";
|
|
53
50
|
Mode["byte"] = "Byte";
|
|
54
51
|
Mode["kanji"] = "Kanji";
|
|
55
|
-
})(
|
|
56
|
-
|
|
52
|
+
})(Mode || (Mode = {}));
|
|
53
|
+
var FileExtension;
|
|
57
54
|
(function (FileExtension) {
|
|
58
55
|
FileExtension["svg"] = "svg";
|
|
59
56
|
FileExtension["png"] = "png";
|
|
60
57
|
FileExtension["jpeg"] = "jpeg";
|
|
61
58
|
FileExtension["webp"] = "webp";
|
|
62
|
-
})(
|
|
59
|
+
})(FileExtension || (FileExtension = {}));
|
|
63
60
|
|
|
64
61
|
const ErrorCorrectionPercents = {
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
62
|
+
[ErrorCorrectionLevel.L]: 0.07,
|
|
63
|
+
[ErrorCorrectionLevel.M]: 0.15,
|
|
64
|
+
[ErrorCorrectionLevel.Q]: 0.25,
|
|
65
|
+
[ErrorCorrectionLevel.H]: 0.3
|
|
69
66
|
};
|
|
70
67
|
|
|
71
68
|
function getMode(data) {
|
|
72
69
|
switch (true) {
|
|
73
70
|
case /^[0-9]*$/.test(data):
|
|
74
|
-
return
|
|
71
|
+
return Mode.numeric;
|
|
75
72
|
case /^[0-9A-Z $%*+\-./:]*$/.test(data):
|
|
76
|
-
return
|
|
73
|
+
return Mode.alphanumeric;
|
|
77
74
|
default:
|
|
78
|
-
return
|
|
75
|
+
return Mode.byte;
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
78
|
|
|
@@ -165,7 +162,7 @@ function sanitizeOptions(options) {
|
|
|
165
162
|
|
|
166
163
|
const defaultOptions = {
|
|
167
164
|
document: undefined,
|
|
168
|
-
shape:
|
|
165
|
+
shape: ShapeType.square,
|
|
169
166
|
width: undefined,
|
|
170
167
|
height: undefined,
|
|
171
168
|
margin: 0,
|
|
@@ -173,7 +170,7 @@ const defaultOptions = {
|
|
|
173
170
|
qrOptions: {
|
|
174
171
|
typeNumber: TypeNumber[0],
|
|
175
172
|
mode: undefined,
|
|
176
|
-
errorCorrectionLevel:
|
|
173
|
+
errorCorrectionLevel: ErrorCorrectionLevel.Q
|
|
177
174
|
},
|
|
178
175
|
imageOptions: {
|
|
179
176
|
hideBackgroundDots: true,
|
|
@@ -182,7 +179,7 @@ const defaultOptions = {
|
|
|
182
179
|
margin: 0
|
|
183
180
|
},
|
|
184
181
|
dotsOptions: {
|
|
185
|
-
type:
|
|
182
|
+
type: DotType.square,
|
|
186
183
|
color: "#000",
|
|
187
184
|
size: 10
|
|
188
185
|
}
|
|
@@ -198,10 +195,10 @@ class QRCornerDot {
|
|
|
198
195
|
const type = this._type;
|
|
199
196
|
let drawFunction;
|
|
200
197
|
switch (type) {
|
|
201
|
-
case
|
|
198
|
+
case CornerDotType.square:
|
|
202
199
|
drawFunction = this._drawSquare;
|
|
203
200
|
break;
|
|
204
|
-
case
|
|
201
|
+
case CornerDotType.dot:
|
|
205
202
|
default:
|
|
206
203
|
drawFunction = this._drawDot;
|
|
207
204
|
}
|
|
@@ -256,13 +253,13 @@ class QRCornerSquare {
|
|
|
256
253
|
const type = this._type;
|
|
257
254
|
let drawFunction;
|
|
258
255
|
switch (type) {
|
|
259
|
-
case
|
|
256
|
+
case CornerSquareType.square:
|
|
260
257
|
drawFunction = this._drawSquare;
|
|
261
258
|
break;
|
|
262
|
-
case
|
|
259
|
+
case CornerSquareType.extraRounded:
|
|
263
260
|
drawFunction = this._drawExtraRounded;
|
|
264
261
|
break;
|
|
265
|
-
case
|
|
262
|
+
case CornerSquareType.dot:
|
|
266
263
|
default:
|
|
267
264
|
drawFunction = this._drawDot;
|
|
268
265
|
}
|
|
@@ -363,22 +360,22 @@ class QRDot {
|
|
|
363
360
|
const type = this._type;
|
|
364
361
|
let drawFunction;
|
|
365
362
|
switch (type) {
|
|
366
|
-
case
|
|
363
|
+
case DotType.dots:
|
|
367
364
|
drawFunction = this._drawDot;
|
|
368
365
|
break;
|
|
369
|
-
case
|
|
366
|
+
case DotType.classy:
|
|
370
367
|
drawFunction = this._drawClassy;
|
|
371
368
|
break;
|
|
372
|
-
case
|
|
369
|
+
case DotType.classyRounded:
|
|
373
370
|
drawFunction = this._drawClassyRounded;
|
|
374
371
|
break;
|
|
375
|
-
case
|
|
372
|
+
case DotType.rounded:
|
|
376
373
|
drawFunction = this._drawRounded;
|
|
377
374
|
break;
|
|
378
|
-
case
|
|
375
|
+
case DotType.extraRounded:
|
|
379
376
|
drawFunction = this._drawExtraRounded;
|
|
380
377
|
break;
|
|
381
|
-
case
|
|
378
|
+
case DotType.square:
|
|
382
379
|
default:
|
|
383
380
|
drawFunction = this._drawSquare;
|
|
384
381
|
}
|
|
@@ -907,7 +904,7 @@ class QRSVG {
|
|
|
907
904
|
}
|
|
908
905
|
}
|
|
909
906
|
}
|
|
910
|
-
if (options.shape ===
|
|
907
|
+
if (options.shape === ShapeType.circle) {
|
|
911
908
|
const additionalDots = Math.floor((minSize / dotSize - count - 2 * this._options.margin) / 2);
|
|
912
909
|
const fakeCount = count + additionalDots * 2;
|
|
913
910
|
const xFakeBeginning = xBeginning - additionalDots * dotSize;
|
|
@@ -1104,7 +1101,7 @@ class QRSVG {
|
|
|
1104
1101
|
rect.setAttribute("clip-path", `url('#clip-path-${name}')`);
|
|
1105
1102
|
if (options) {
|
|
1106
1103
|
let gradient;
|
|
1107
|
-
if (options.type ===
|
|
1104
|
+
if (options.type === GradientType.radial) {
|
|
1108
1105
|
gradient = this._document.createElementNS("http://www.w3.org/2000/svg", "radialGradient");
|
|
1109
1106
|
gradient.setAttribute("id", name);
|
|
1110
1107
|
gradient.setAttribute("gradientUnits", "userSpaceOnUse");
|
|
@@ -1184,7 +1181,7 @@ let QRCodeStyling$1 = class QRCodeStyling {
|
|
|
1184
1181
|
if (!this._qr) {
|
|
1185
1182
|
return;
|
|
1186
1183
|
}
|
|
1187
|
-
const count = Math.ceil((this._options.shape ==
|
|
1184
|
+
const count = Math.ceil((this._options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
|
|
1188
1185
|
const size = this._options.dotsOptions.size * (count + 2 * this._options.margin);
|
|
1189
1186
|
const qrSVG = new QRSVG({
|
|
1190
1187
|
...this._options,
|
|
@@ -1256,9 +1253,10 @@ let QRCodeStyling$1 = class QRCodeStyling {
|
|
|
1256
1253
|
}
|
|
1257
1254
|
};
|
|
1258
1255
|
|
|
1256
|
+
const browserUtils = undefined;
|
|
1259
1257
|
class QRCodeStyling extends QRCodeStyling$1 {
|
|
1260
1258
|
constructor(options) {
|
|
1261
|
-
const dom = new
|
|
1259
|
+
const dom = new DOMImplementation().createDocument(null, null);
|
|
1262
1260
|
const imageCache = new Map();
|
|
1263
1261
|
const loadImage = async function (url) {
|
|
1264
1262
|
if (typeof url == "string") {
|
|
@@ -1269,7 +1267,7 @@ class QRCodeStyling extends QRCodeStyling$1 {
|
|
|
1269
1267
|
.arrayBuffer()
|
|
1270
1268
|
.then((buff) => Buffer.from(buff))
|
|
1271
1269
|
.then(async (data) => ({
|
|
1272
|
-
contentType: res.headers.get("Content-Type") || (await
|
|
1270
|
+
contentType: res.headers.get("Content-Type") || (await fileTypeFromBuffer(data).then((r) => r?.mime)),
|
|
1273
1271
|
data
|
|
1274
1272
|
})));
|
|
1275
1273
|
imageCache.set(url, pr);
|
|
@@ -1277,15 +1275,15 @@ class QRCodeStyling extends QRCodeStyling$1 {
|
|
|
1277
1275
|
}
|
|
1278
1276
|
else {
|
|
1279
1277
|
const buff = Buffer.from(url);
|
|
1280
|
-
const mime = await
|
|
1278
|
+
const mime = await fileTypeFromBuffer(buff).then((r) => r?.mime);
|
|
1281
1279
|
return {
|
|
1282
1280
|
contentType: mime,
|
|
1283
1281
|
data: buff
|
|
1284
1282
|
};
|
|
1285
1283
|
}
|
|
1286
1284
|
};
|
|
1287
|
-
global.XMLSerializer =
|
|
1288
|
-
global.DOMParser =
|
|
1285
|
+
global.XMLSerializer = XMLSerializer$1;
|
|
1286
|
+
global.DOMParser = DOMParser$1;
|
|
1289
1287
|
super({
|
|
1290
1288
|
...options,
|
|
1291
1289
|
document: options.document || dom,
|
|
@@ -1309,7 +1307,5 @@ class QRCodeStyling extends QRCodeStyling$1 {
|
|
|
1309
1307
|
}
|
|
1310
1308
|
}
|
|
1311
1309
|
|
|
1312
|
-
|
|
1313
|
-
exports.QRCodeStyling = QRCodeStyling;
|
|
1314
|
-
exports.TypeNumber = TypeNumber;
|
|
1310
|
+
export { CornerDotType, CornerSquareType, DotType, ErrorCorrectionLevel, ErrorCorrectionPercents, FileExtension, GradientType, Mode, QRCodeStyling, ShapeType, TypeNumber, browserUtils };
|
|
1315
1311
|
//# sourceMappingURL=qr-code-styling-node.js.map
|