@liquid-js/qr-code-styling 1.10.6 → 2.0.0-rc.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 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.
@@ -1,12 +1,9 @@
1
- 'use strict';
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 xmldom = require('@xmldom/xmldom');
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
- })(exports.DotType || (exports.DotType = {}));
18
- exports.CornerDotType = void 0;
14
+ })(DotType || (DotType = {}));
15
+ var CornerDotType;
19
16
  (function (CornerDotType) {
20
17
  CornerDotType["dot"] = "dot";
21
18
  CornerDotType["square"] = "square";
22
- })(exports.CornerDotType || (exports.CornerDotType = {}));
23
- exports.CornerSquareType = void 0;
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
- })(exports.CornerSquareType || (exports.CornerSquareType = {}));
29
- exports.GradientType = void 0;
25
+ })(CornerSquareType || (CornerSquareType = {}));
26
+ var GradientType;
30
27
  (function (GradientType) {
31
28
  GradientType["radial"] = "radial";
32
29
  GradientType["linear"] = "linear";
33
- })(exports.GradientType || (exports.GradientType = {}));
34
- exports.ShapeType = void 0;
30
+ })(GradientType || (GradientType = {}));
31
+ var ShapeType;
35
32
  (function (ShapeType) {
36
33
  ShapeType["square"] = "square";
37
34
  ShapeType["circle"] = "circle";
38
- })(exports.ShapeType || (exports.ShapeType = {}));
35
+ })(ShapeType || (ShapeType = {}));
39
36
  const TypeNumber = Array(41)
40
37
  .fill(0)
41
38
  .map((_, i) => i);
42
- exports.ErrorCorrectionLevel = void 0;
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
- })(exports.ErrorCorrectionLevel || (exports.ErrorCorrectionLevel = {}));
49
- exports.Mode = void 0;
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
- })(exports.Mode || (exports.Mode = {}));
56
- exports.FileExtension = void 0;
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
- })(exports.FileExtension || (exports.FileExtension = {}));
59
+ })(FileExtension || (FileExtension = {}));
63
60
 
64
61
  const ErrorCorrectionPercents = {
65
- [exports.ErrorCorrectionLevel.L]: 0.07,
66
- [exports.ErrorCorrectionLevel.M]: 0.15,
67
- [exports.ErrorCorrectionLevel.Q]: 0.25,
68
- [exports.ErrorCorrectionLevel.H]: 0.3
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 exports.Mode.numeric;
71
+ return Mode.numeric;
75
72
  case /^[0-9A-Z $%*+\-./:]*$/.test(data):
76
- return exports.Mode.alphanumeric;
73
+ return Mode.alphanumeric;
77
74
  default:
78
- return exports.Mode.byte;
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: exports.ShapeType.square,
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: exports.ErrorCorrectionLevel.Q
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: exports.DotType.square,
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 exports.CornerDotType.square:
198
+ case CornerDotType.square:
202
199
  drawFunction = this._drawSquare;
203
200
  break;
204
- case exports.CornerDotType.dot:
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 exports.CornerSquareType.square:
256
+ case CornerSquareType.square:
260
257
  drawFunction = this._drawSquare;
261
258
  break;
262
- case exports.CornerSquareType.extraRounded:
259
+ case CornerSquareType.extraRounded:
263
260
  drawFunction = this._drawExtraRounded;
264
261
  break;
265
- case exports.CornerSquareType.dot:
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 exports.DotType.dots:
363
+ case DotType.dots:
367
364
  drawFunction = this._drawDot;
368
365
  break;
369
- case exports.DotType.classy:
366
+ case DotType.classy:
370
367
  drawFunction = this._drawClassy;
371
368
  break;
372
- case exports.DotType.classyRounded:
369
+ case DotType.classyRounded:
373
370
  drawFunction = this._drawClassyRounded;
374
371
  break;
375
- case exports.DotType.rounded:
372
+ case DotType.rounded:
376
373
  drawFunction = this._drawRounded;
377
374
  break;
378
- case exports.DotType.extraRounded:
375
+ case DotType.extraRounded:
379
376
  drawFunction = this._drawExtraRounded;
380
377
  break;
381
- case exports.DotType.square:
378
+ case DotType.square:
382
379
  default:
383
380
  drawFunction = this._drawSquare;
384
381
  }
@@ -751,12 +748,12 @@ const dotMask = [
751
748
  [0, 0, 0, 0, 0, 0, 0]
752
749
  ];
753
750
  const alignmentCount = [
754
- [35, 47],
755
- [28, 34],
756
- [21, 23],
757
- [14, 14],
758
- [7, 7],
759
- [2, 2],
751
+ [35, 49],
752
+ [28, 36],
753
+ [21, 25],
754
+ [14, 16],
755
+ [7, 9],
756
+ [2, 4],
760
757
  [1, 1]
761
758
  ];
762
759
  class QRSVG {
@@ -907,7 +904,7 @@ class QRSVG {
907
904
  }
908
905
  }
909
906
  }
910
- if (options.shape === exports.ShapeType.circle) {
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 === exports.GradientType.radial) {
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 == exports.ShapeType.circle ? Math.sqrt(2) : 1) * this._qr.getModuleCount());
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,
@@ -1258,7 +1255,7 @@ let QRCodeStyling$1 = class QRCodeStyling {
1258
1255
 
1259
1256
  class QRCodeStyling extends QRCodeStyling$1 {
1260
1257
  constructor(options) {
1261
- const dom = new xmldom.DOMImplementation().createDocument(null, null);
1258
+ const dom = new DOMImplementation().createDocument(null, null);
1262
1259
  const imageCache = new Map();
1263
1260
  const loadImage = async function (url) {
1264
1261
  if (typeof url == "string") {
@@ -1269,7 +1266,7 @@ class QRCodeStyling extends QRCodeStyling$1 {
1269
1266
  .arrayBuffer()
1270
1267
  .then((buff) => Buffer.from(buff))
1271
1268
  .then(async (data) => ({
1272
- contentType: res.headers.get("Content-Type") || (await fileType.fromBuffer(data).then((r) => r?.mime)),
1269
+ contentType: res.headers.get("Content-Type") || (await fileTypeFromBuffer(data).then((r) => r?.mime)),
1273
1270
  data
1274
1271
  })));
1275
1272
  imageCache.set(url, pr);
@@ -1277,15 +1274,15 @@ class QRCodeStyling extends QRCodeStyling$1 {
1277
1274
  }
1278
1275
  else {
1279
1276
  const buff = Buffer.from(url);
1280
- const mime = await fileType.fromBuffer(buff).then((r) => r?.mime);
1277
+ const mime = await fileTypeFromBuffer(buff).then((r) => r?.mime);
1281
1278
  return {
1282
1279
  contentType: mime,
1283
1280
  data: buff
1284
1281
  };
1285
1282
  }
1286
1283
  };
1287
- global.XMLSerializer = xmldom.XMLSerializer;
1288
- global.DOMParser = xmldom.DOMParser;
1284
+ global.XMLSerializer = XMLSerializer$1;
1285
+ global.DOMParser = DOMParser$1;
1289
1286
  super({
1290
1287
  ...options,
1291
1288
  document: options.document || dom,
@@ -1309,7 +1306,5 @@ class QRCodeStyling extends QRCodeStyling$1 {
1309
1306
  }
1310
1307
  }
1311
1308
 
1312
- exports.ErrorCorrectionPercents = ErrorCorrectionPercents;
1313
- exports.QRCodeStyling = QRCodeStyling;
1314
- exports.TypeNumber = TypeNumber;
1309
+ export { CornerDotType, CornerSquareType, DotType, ErrorCorrectionLevel, ErrorCorrectionPercents, FileExtension, GradientType, Mode, QRCodeStyling, ShapeType, TypeNumber };
1315
1310
  //# sourceMappingURL=qr-code-styling-node.js.map