@liquid-js/qr-code-styling 4.0.7 → 4.0.8
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 +147 -147
- package/lib/kanji.js +1 -1
- package/lib/kanji.js.map +1 -1
- package/lib/qr-code-styling-node.js +98 -70
- 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 +1 -1
|
@@ -2,7 +2,7 @@ import { QRUtil } from "@liquid-js/qrcode-generator/lib/qrcode/QRUtil.js";
|
|
|
2
2
|
|
|
3
3
|
import { stringToBytes_UTF8 } from "@liquid-js/qrcode-generator/lib/text/stringToBytes_UTF8.js";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ErrorCorrectionLevel, TypeNumber, Mode, QRCodeMinimal } from "@liquid-js/qrcode-generator/lib/qrcode/QRCodeMinimal.js";
|
|
6
6
|
|
|
7
7
|
import sharp from "sharp";
|
|
8
8
|
|
|
@@ -19,12 +19,12 @@ function mergeDeep(target, ...sources) {
|
|
|
19
19
|
let source = sources.shift();
|
|
20
20
|
return void 0 !== source && isObject(target) && isObject(source) ? (target = {
|
|
21
21
|
...target
|
|
22
|
-
}, Object.keys(source).forEach(
|
|
22
|
+
}, Object.keys(source).forEach(key => {
|
|
23
23
|
let targetValue = target[key], sourceValue = source[key];
|
|
24
24
|
Array.isArray(targetValue) && Array.isArray(sourceValue) ? target[key] = sourceValue : isObject(targetValue) && isObject(sourceValue) ? target[key] = mergeDeep({
|
|
25
25
|
...targetValue
|
|
26
26
|
}, sourceValue) : target[key] = sourceValue;
|
|
27
|
-
})
|
|
27
|
+
}), mergeDeep(target, ...sources)) : target;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
var GradientType, DotType, CornerDotType, CornerSquareType, ShapeType, ImageMode;
|
|
@@ -34,25 +34,25 @@ function sanitizeGradient(gradient_newGradient) {
|
|
|
34
34
|
...gradient_newGradient
|
|
35
35
|
}).colorStops || !gradient_newGradient.colorStops.length) throw Error("Field 'colorStops' is required in gradient");
|
|
36
36
|
return gradient_newGradient.rotation = gradient_newGradient.rotation ? Number(gradient_newGradient.rotation) : 0,
|
|
37
|
-
gradient_newGradient.colorStops = gradient_newGradient.colorStops.map(
|
|
37
|
+
gradient_newGradient.colorStops = gradient_newGradient.colorStops.map(colorStop => ({
|
|
38
38
|
...colorStop,
|
|
39
39
|
offset: Number(colorStop.offset)
|
|
40
|
-
}))
|
|
40
|
+
})), gradient_newGradient;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
(GradientType = GradientType
|
|
44
|
-
(DotType = DotType
|
|
45
|
-
DotType.
|
|
43
|
+
(GradientType = GradientType ||= {}).radial = "radial", GradientType.linear = "linear",
|
|
44
|
+
(DotType = DotType ||= {}).dot = "dot", DotType.randomDot = "random-dot", DotType.rounded = "rounded",
|
|
45
|
+
DotType.extraRounded = "extra-rounded", DotType.verticalLine = "vertical-line",
|
|
46
46
|
DotType.horizontalLine = "horizontal-line", DotType.classy = "classy", DotType.classyRounded = "classy-rounded",
|
|
47
47
|
DotType.square = "square", DotType.smallSquare = "small-square", DotType.tinySquare = "tiny-square",
|
|
48
|
-
DotType.diamond = "diamond", (CornerDotType = CornerDotType
|
|
48
|
+
DotType.diamond = "diamond", (CornerDotType = CornerDotType ||= {}).dot = "dot",
|
|
49
49
|
CornerDotType.square = "square", CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded",
|
|
50
50
|
CornerDotType.classy = "classy", CornerDotType.outpoint = "outpoint", CornerDotType.inpoint = "inpoint",
|
|
51
|
-
(CornerSquareType = CornerSquareType
|
|
51
|
+
(CornerSquareType = CornerSquareType ||= {}).dot = "dot", CornerSquareType.square = "square",
|
|
52
52
|
CornerSquareType.extraRounded = "extra-rounded", CornerSquareType.classy = "classy",
|
|
53
|
-
CornerSquareType.outpoint = "outpoint", CornerSquareType.inpoint = "inpoint", (ShapeType = ShapeType
|
|
54
|
-
ShapeType.circle = "circle", (ImageMode = ImageMode
|
|
55
|
-
ImageMode.
|
|
53
|
+
CornerSquareType.outpoint = "outpoint", CornerSquareType.inpoint = "inpoint", (ShapeType = ShapeType ||= {}).square = "square",
|
|
54
|
+
ShapeType.circle = "circle", (ImageMode = ImageMode ||= {}).center = "center", ImageMode.overlay = "overlay",
|
|
55
|
+
ImageMode.background = "background";
|
|
56
56
|
|
|
57
57
|
let defaultOptions = {
|
|
58
58
|
document: void 0,
|
|
@@ -123,13 +123,16 @@ function numToAttr(value) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
function svgPath(strings, ...values) {
|
|
126
|
-
return strings.reduce((
|
|
126
|
+
return strings.reduce((t, v, i) => {
|
|
127
127
|
let p = "";
|
|
128
128
|
return i && (p = values[i - 1]), "number" == typeof p && (p = numToAttr(p)), `${t}${p}${v}`;
|
|
129
|
-
}
|
|
129
|
+
}, "").trim().replace(/[\s\n\r]+/gim, " ");
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
class QRCornerDot {
|
|
133
|
+
type;
|
|
134
|
+
document;
|
|
135
|
+
_element;
|
|
133
136
|
get element() {
|
|
134
137
|
return this._element;
|
|
135
138
|
}
|
|
@@ -197,9 +200,9 @@ class QRCornerDot {
|
|
|
197
200
|
let {size, x, y} = args;
|
|
198
201
|
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
199
202
|
let move = !1, i = 0;
|
|
200
|
-
this._element.setAttribute("d", [ "M", 1, .3262506, "c", 0, .0383376, -.0064626, .0758377, -.0193751, .1125001, "s", -.0356247, .076875, -.0681248, .1206252, "c", -.0325, .0437499, -.0762503, .0931247, -.1312501, .1481249, "C", .7262502, .7625008, .6566626, .8279132, .5724999, .9037505, "L", .5, .9687506, "L", .4275001, .9037505, "C", .3433374, .8279132, .2737499, .7625005, .21875, .7075007, "C", .1637501, .6525008, .1199999, .6031258, .0874999, .5593758, "S", .0322876, .4754133, .0193751, .4387506, "S", 0, .3645881, 0, .3262506, "c", 0, -.0783374, .0262499, -.1437498, .07875, -.1962499, "s", .1179124, -.07875, .1962499, -.07875, "c", .0433376, 0, .0845875, .0091625, .12375, .0274999, "S", .4716623, .1229131, .5, .1562506, "c", .0283374, -.0333375, .0620874, -.0591625, .1012502, -.0775, "c", .0391627, -.0183375, .0804126, -.0274999, .12375, -.0274999, "c", .0783374, 0, .1437497, .0262499, .1962501, .07875, "S", 1, .2479131, 1, .3262506, "z" ].map(
|
|
201
|
-
move = v.toUpperCase() == v, v) : (i++, v *= size, move && (v +=
|
|
202
|
-
numToAttr(v)))
|
|
203
|
+
this._element.setAttribute("d", [ "M", 1, .3262506, "c", 0, .0383376, -.0064626, .0758377, -.0193751, .1125001, "s", -.0356247, .076875, -.0681248, .1206252, "c", -.0325, .0437499, -.0762503, .0931247, -.1312501, .1481249, "C", .7262502, .7625008, .6566626, .8279132, .5724999, .9037505, "L", .5, .9687506, "L", .4275001, .9037505, "C", .3433374, .8279132, .2737499, .7625005, .21875, .7075007, "C", .1637501, .6525008, .1199999, .6031258, .0874999, .5593758, "S", .0322876, .4754133, .0193751, .4387506, "S", 0, .3645881, 0, .3262506, "c", 0, -.0783374, .0262499, -.1437498, .07875, -.1962499, "s", .1179124, -.07875, .1962499, -.07875, "c", .0433376, 0, .0845875, .0091625, .12375, .0274999, "S", .4716623, .1229131, .5, .1562506, "c", .0283374, -.0333375, .0620874, -.0591625, .1012502, -.0775, "c", .0391627, -.0183375, .0804126, -.0274999, .12375, -.0274999, "c", .0783374, 0, .1437497, .0262499, .1962501, .07875, "S", 1, .2479131, 1, .3262506, "z" ].map(v => "string" == typeof v ? (i = 0,
|
|
204
|
+
move = v.toUpperCase() == v, v) : (i++, v *= size, move && (v += i % 2 == 1 ? x : y),
|
|
205
|
+
numToAttr(v))).join(" "));
|
|
203
206
|
}
|
|
204
207
|
basicRounded(args) {
|
|
205
208
|
let {size, x, y} = args;
|
|
@@ -292,6 +295,10 @@ class QRCornerDot {
|
|
|
292
295
|
}
|
|
293
296
|
|
|
294
297
|
class QRCornerSquare {
|
|
298
|
+
type;
|
|
299
|
+
document;
|
|
300
|
+
_element;
|
|
301
|
+
_fill;
|
|
295
302
|
get element() {
|
|
296
303
|
return this._element;
|
|
297
304
|
}
|
|
@@ -444,6 +451,9 @@ class QRCornerSquare {
|
|
|
444
451
|
}
|
|
445
452
|
|
|
446
453
|
class QRDot {
|
|
454
|
+
type;
|
|
455
|
+
document;
|
|
456
|
+
_element;
|
|
447
457
|
get element() {
|
|
448
458
|
return this._element;
|
|
449
459
|
}
|
|
@@ -626,7 +636,7 @@ class QRDot {
|
|
|
626
636
|
y,
|
|
627
637
|
size,
|
|
628
638
|
rotation: 0
|
|
629
|
-
}) :
|
|
639
|
+
}) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? this.basicSquare({
|
|
630
640
|
x,
|
|
631
641
|
y,
|
|
632
642
|
size,
|
|
@@ -647,7 +657,7 @@ class QRDot {
|
|
|
647
657
|
}
|
|
648
658
|
drawVerticalLine({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
649
659
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
650
|
-
|
|
660
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || leftNeighbor && !topNeighbor && !bottomNeighbor || rightNeighbor && !topNeighbor && !bottomNeighbor ? this.basicDot({
|
|
651
661
|
x,
|
|
652
662
|
y,
|
|
653
663
|
size,
|
|
@@ -671,7 +681,7 @@ class QRDot {
|
|
|
671
681
|
}
|
|
672
682
|
drawHorizontalLine({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
673
683
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
674
|
-
|
|
684
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || topNeighbor && !leftNeighbor && !rightNeighbor || bottomNeighbor && !leftNeighbor && !rightNeighbor ? this.basicDot({
|
|
675
685
|
x,
|
|
676
686
|
y,
|
|
677
687
|
size,
|
|
@@ -702,7 +712,7 @@ class QRDot {
|
|
|
702
712
|
y,
|
|
703
713
|
size,
|
|
704
714
|
rotation: 0
|
|
705
|
-
}) :
|
|
715
|
+
}) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? this.basicSquare({
|
|
706
716
|
x,
|
|
707
717
|
y,
|
|
708
718
|
size,
|
|
@@ -723,7 +733,7 @@ class QRDot {
|
|
|
723
733
|
}
|
|
724
734
|
drawClassy({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
725
735
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
726
|
-
|
|
736
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
|
|
727
737
|
x,
|
|
728
738
|
y,
|
|
729
739
|
size,
|
|
@@ -747,7 +757,7 @@ class QRDot {
|
|
|
747
757
|
}
|
|
748
758
|
drawClassyRounded({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
749
759
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
750
|
-
|
|
760
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
|
|
751
761
|
x,
|
|
752
762
|
y,
|
|
753
763
|
size,
|
|
@@ -772,7 +782,7 @@ class QRDot {
|
|
|
772
782
|
}
|
|
773
783
|
|
|
774
784
|
let browserImageTools = {
|
|
775
|
-
toDataURL: url => "string" == typeof url && url.startsWith("data:") ? Promise.resolve(url) : new Promise((
|
|
785
|
+
toDataURL: url => "string" == typeof url && url.startsWith("data:") ? Promise.resolve(url) : new Promise((resolve, reject) => {
|
|
776
786
|
if ("string" == typeof url) {
|
|
777
787
|
const xhr = new XMLHttpRequest;
|
|
778
788
|
xhr.onload = () => {
|
|
@@ -788,16 +798,16 @@ let browserImageTools = {
|
|
|
788
798
|
resolve(reader.result);
|
|
789
799
|
}, reader.readAsDataURL(url);
|
|
790
800
|
}
|
|
791
|
-
})
|
|
792
|
-
getSize: (src, crossOrigin) => new Promise((
|
|
801
|
+
}),
|
|
802
|
+
getSize: (src, crossOrigin) => new Promise((resolve, reject) => {
|
|
793
803
|
const image = new Image;
|
|
794
804
|
"string" === crossOrigin && (image.crossOrigin = crossOrigin), image.onload = () => {
|
|
795
805
|
resolve({
|
|
796
806
|
width: image.width,
|
|
797
807
|
height: image.height
|
|
798
808
|
});
|
|
799
|
-
}, image.onerror = image.onabort = reject, "string" == typeof src ? image.src = src : browserImageTools.toDataURL(src).then(
|
|
800
|
-
})
|
|
809
|
+
}, image.onerror = image.onabort = reject, "string" == typeof src ? image.src = src : browserImageTools.toDataURL(src).then(url => image.src = url).catch(reject);
|
|
810
|
+
})
|
|
801
811
|
};
|
|
802
812
|
|
|
803
813
|
function parseColor(base) {
|
|
@@ -805,7 +815,7 @@ function parseColor(base) {
|
|
|
805
815
|
let alpha = 1;
|
|
806
816
|
if ("#" === (base = base.toLowerCase())[0]) {
|
|
807
817
|
let size = (base = base.slice(1)).length;
|
|
808
|
-
|
|
818
|
+
size <= 4 ? (m_parts = [ parseInt(base[0] + base[0], 16), parseInt(base[1] + base[1], 16), parseInt(base[2] + base[2], 16) ],
|
|
809
819
|
4 === size && (alpha = parseInt(base[3] + base[3], 16) / 255)) : (m_parts = [ parseInt(base[0] + base[1], 16), parseInt(base[2] + base[3], 16), parseInt(base[4] + base[5], 16) ],
|
|
810
820
|
8 === size && (alpha = parseInt(base[6] + base[7], 16) / 255)), m_parts[0] || (m_parts[0] = 0),
|
|
811
821
|
m_parts[1] || (m_parts[1] = 0), m_parts[2] || (m_parts[2] = 0);
|
|
@@ -814,11 +824,11 @@ function parseColor(base) {
|
|
|
814
824
|
value: base,
|
|
815
825
|
alpha
|
|
816
826
|
};
|
|
817
|
-
alpha =
|
|
818
|
-
3 === i ? v : 255 * v) : "none" === v ? 0 : parseFloat(v)))
|
|
827
|
+
alpha = (m_parts = (m_parts = m_parts[2].trim().split(/\s*[,/]\s*|\s+/)).map((v, i) => "%" === v[v.length - 1] ? (v = parseFloat(v) / 100,
|
|
828
|
+
3 === i ? v : 255 * v) : "none" === v ? 0 : parseFloat(v))).length > 3 ? m_parts.pop() : 1;
|
|
819
829
|
}
|
|
820
830
|
return {
|
|
821
|
-
value: "#" + m_parts.map(
|
|
831
|
+
value: "#" + m_parts.map(v => Math.max(0, Math.min(255, v)).toString(16).padStart(2, "0")).join(""),
|
|
822
832
|
alpha: Math.max(0, Math.min(1, alpha))
|
|
823
833
|
};
|
|
824
834
|
}
|
|
@@ -826,9 +836,21 @@ function parseColor(base) {
|
|
|
826
836
|
let squareMask = [ [ 1, 1, 1, 1, 1, 1, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 1, 1, 1, 1, 1, 1 ] ], dotMask = [ [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ] ];
|
|
827
837
|
|
|
828
838
|
class QRSVG {
|
|
839
|
+
options;
|
|
840
|
+
_element;
|
|
829
841
|
get element() {
|
|
830
842
|
return this._element;
|
|
831
843
|
}
|
|
844
|
+
defs;
|
|
845
|
+
backgroundMask;
|
|
846
|
+
backgroundMaskGroup;
|
|
847
|
+
dotsMask;
|
|
848
|
+
dotsMaskGroup;
|
|
849
|
+
lightDotsMask;
|
|
850
|
+
lightDotsMaskGroup;
|
|
851
|
+
qr;
|
|
852
|
+
document;
|
|
853
|
+
imageTools;
|
|
832
854
|
constructor(options) {
|
|
833
855
|
this.options = options, this.document = options.document, this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
834
856
|
let width = numToAttr(options.width), height = numToAttr(options.height);
|
|
@@ -869,28 +891,28 @@ class QRSVG {
|
|
|
869
891
|
};
|
|
870
892
|
} else coverLevel_margin = imageOptions.imageSize * errorCorrectionPercent, alignment_maxWidth_typeNumber = QRUtil.getPatternPosition(alignment_maxWidth_typeNumber),
|
|
871
893
|
drawImageSize = function({originalHeight, originalWidth, maxHiddenDots: JSCompiler_object_inline_x_16_hideMax_maxHiddenDots, maxHiddenAxisDots: JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper, dotSize, margin}) {
|
|
872
|
-
if (
|
|
894
|
+
if (originalHeight <= 0 || originalWidth <= 0 || JSCompiler_object_inline_x_16_hideMax_maxHiddenDots <= 0 || dotSize <= 0 || 4 * margin ** 2 > JSCompiler_object_inline_x_16_hideMax_maxHiddenDots) return {
|
|
873
895
|
height: 0,
|
|
874
896
|
width: 0,
|
|
875
897
|
hideYDots: 0,
|
|
876
898
|
hideXDots: 0
|
|
877
899
|
};
|
|
878
|
-
JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper &&
|
|
879
|
-
var JSCompiler_object_inline_x_14_dimMax = Math.max(originalWidth, originalHeight), JSCompiler_object_inline_y_15_dimMin_hideMin = Math.min(originalWidth, originalHeight),
|
|
900
|
+
JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper && JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper % 2 == 0 && (JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = Math.max(1, JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper - 1));
|
|
901
|
+
var JSCompiler_object_inline_x_14_dimMax = Math.max(originalWidth, originalHeight), JSCompiler_object_inline_y_15_dimMin_hideMin = Math.min(originalWidth, originalHeight), lower = 0;
|
|
880
902
|
JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = (JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper || JSCompiler_object_inline_x_16_hideMax_maxHiddenDots) - 2 * margin;
|
|
881
903
|
do {
|
|
882
|
-
let newSize =
|
|
883
|
-
|
|
904
|
+
let newSize = lower + (JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper - lower) / 2, dotsMax = Math.max(1, Math.ceil(newSize + 2 * margin));
|
|
905
|
+
dotsMax % 2 == 0 && dotsMax++;
|
|
884
906
|
let dotsMin = Math.max(1, Math.ceil(newSize * JSCompiler_object_inline_y_15_dimMin_hideMin / JSCompiler_object_inline_x_14_dimMax + 2 * margin));
|
|
885
|
-
|
|
886
|
-
} while (
|
|
887
|
-
return
|
|
888
|
-
|
|
907
|
+
dotsMin % 2 == 0 && dotsMin++, dotsMax * dotsMin > JSCompiler_object_inline_x_16_hideMax_maxHiddenDots ? JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = newSize : lower = newSize;
|
|
908
|
+
} while (Math.abs(lower - JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper) > .001);
|
|
909
|
+
return (JSCompiler_object_inline_x_16_hideMax_maxHiddenDots = Math.max(1, Math.ceil(lower + 2 * margin))) % 2 == 0 && JSCompiler_object_inline_x_16_hideMax_maxHiddenDots++,
|
|
910
|
+
(JSCompiler_object_inline_y_15_dimMin_hideMin = Math.max(1, Math.ceil(lower * JSCompiler_object_inline_y_15_dimMin_hideMin / JSCompiler_object_inline_x_14_dimMax + 2 * margin))) % 2 == 0 && JSCompiler_object_inline_y_15_dimMin_hideMin++,
|
|
889
911
|
originalWidth > originalHeight ? JSCompiler_object_inline_x_14_dimMax = JSCompiler_object_inline_x_16_hideMax_maxHiddenDots : (JSCompiler_object_inline_x_14_dimMax = JSCompiler_object_inline_y_15_dimMin_hideMin,
|
|
890
912
|
JSCompiler_object_inline_y_15_dimMin_hideMin = JSCompiler_object_inline_x_16_hideMax_maxHiddenDots),
|
|
891
913
|
JSCompiler_object_inline_x_16_hideMax_maxHiddenDots = JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = (JSCompiler_object_inline_x_14_dimMax - 2 * margin) * dotSize,
|
|
892
|
-
(JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper * originalHeight / originalWidth) > (
|
|
893
|
-
JSCompiler_object_inline_x_16_hideMax_maxHiddenDots =
|
|
914
|
+
(JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper * originalHeight / originalWidth) > (lower = (JSCompiler_object_inline_y_15_dimMin_hideMin - 2 * margin) * dotSize) && (JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = lower,
|
|
915
|
+
JSCompiler_object_inline_x_16_hideMax_maxHiddenDots = lower * originalWidth / originalHeight),
|
|
894
916
|
{
|
|
895
917
|
height: Math.round(JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper + 2 * margin * dotSize),
|
|
896
918
|
width: Math.round(JSCompiler_object_inline_x_16_hideMax_maxHiddenDots + 2 * margin * dotSize),
|
|
@@ -900,19 +922,19 @@ class QRSVG {
|
|
|
900
922
|
}({
|
|
901
923
|
originalWidth: qr_size.width,
|
|
902
924
|
originalHeight: qr_size.height,
|
|
903
|
-
maxHiddenDots: Math.floor(coverLevel_margin * (count * count - 192 - 2 * (count - 16) -
|
|
925
|
+
maxHiddenDots: Math.floor(coverLevel_margin * (count * count - 192 - 2 * (count - 16) - alignment_maxWidth_typeNumber.length ** 2 * 25)),
|
|
904
926
|
maxHiddenAxisDots: count - 14,
|
|
905
927
|
dotSize,
|
|
906
928
|
margin: imageOptions.margin
|
|
907
929
|
});
|
|
908
930
|
}
|
|
909
|
-
this.drawBackground(), this.options.imageOptions.mode != ImageMode.overlay && this.options.image &&
|
|
931
|
+
this.drawBackground(), this.options.imageOptions.mode != ImageMode.overlay && this.options.image && drawImageSize.width > 0 && drawImageSize.height > 0 && await this.drawImage({
|
|
910
932
|
width: drawImageSize.width,
|
|
911
933
|
height: drawImageSize.height,
|
|
912
934
|
count,
|
|
913
935
|
dotSize
|
|
914
|
-
}), this.drawDots((
|
|
915
|
-
this.options.imageOptions.mode == ImageMode.overlay && this.options.image &&
|
|
936
|
+
}), this.drawDots((i, j) => !(this.options.imageOptions.mode == ImageMode.center && i >= (count - drawImageSize.hideXDots) / 2 && i < (count + drawImageSize.hideXDots) / 2 && j >= (count - drawImageSize.hideYDots) / 2 && j < (count + drawImageSize.hideYDots) / 2 || i < 8 && j < 8 || i >= count - 8 && j < 8 || j >= count - 8 && i < 8)),
|
|
937
|
+
this.options.imageOptions.mode == ImageMode.overlay && this.options.image && drawImageSize.width > 0 && drawImageSize.height > 0 && await this.drawImage({
|
|
916
938
|
width: drawImageSize.width,
|
|
917
939
|
height: drawImageSize.height,
|
|
918
940
|
count,
|
|
@@ -967,12 +989,12 @@ class QRSVG {
|
|
|
967
989
|
for (let j = 0; j < fakeCount_margin; j++) if (i > additionalDots - 1 && i < fakeCount_margin - additionalDots && j > additionalDots - 1 && j < fakeCount_margin - additionalDots) {
|
|
968
990
|
let ii = i - additionalDots, jj = j - additionalDots;
|
|
969
991
|
alignment && !alignment(ii, jj) ? fakeMatrix[i][j] = void 0 : fakeMatrix[i][j] = !!this.qr.isDark(jj, ii);
|
|
970
|
-
} else fakeMatrix[i][j] = options.shape === ShapeType.circle && Math.sqrt((i - center_jAlign) * (i - center_jAlign) + (j - center_jAlign) * (j - center_jAlign)) > center_jAlign ? void 0 : i == additionalDots - 1 || i == fakeCount_margin - additionalDots || j == additionalDots - 1 || j == fakeCount_margin - additionalDots ? (j == additionalDots - 1 && (i < additionalDots + 8 || i > fakeCount_margin - additionalDots - 9) || j == fakeCount_margin - additionalDots && i < additionalDots + 8 || i == additionalDots - 1 && (j < additionalDots + 8 || j > fakeCount_margin - additionalDots - 9) || i == fakeCount_margin - additionalDots && j < additionalDots + 8) && void 0 : this.qr.isDark(
|
|
992
|
+
} else fakeMatrix[i][j] = options.shape === ShapeType.circle && Math.sqrt((i - center_jAlign) * (i - center_jAlign) + (j - center_jAlign) * (j - center_jAlign)) > center_jAlign ? void 0 : i == additionalDots - 1 || i == fakeCount_margin - additionalDots || j == additionalDots - 1 || j == fakeCount_margin - additionalDots ? (j == additionalDots - 1 && (i < additionalDots + 8 || i > fakeCount_margin - additionalDots - 9) || j == fakeCount_margin - additionalDots && i < additionalDots + 8 || i == additionalDots - 1 && (j < additionalDots + 8 || j > fakeCount_margin - additionalDots - 9) || i == fakeCount_margin - additionalDots && j < additionalDots + 8) && void 0 : this.qr.isDark(j - 2 * additionalDots < 0 ? j : j >= count ? j - 2 * additionalDots : j - additionalDots, i - 2 * additionalDots < 0 ? i : i >= count ? i - 2 * additionalDots : i - additionalDots);
|
|
971
993
|
}
|
|
972
994
|
alignment = QRUtil.getPatternPosition((count - 17) / 4);
|
|
973
995
|
for (let i = 0; i < fakeCount_margin; i++) {
|
|
974
|
-
count = alignment.find(
|
|
975
|
-
for (let j = 0; j < fakeCount_margin; j++) center_jAlign = alignment.find(
|
|
996
|
+
count = alignment.find(v => i - additionalDots > v - 3 && i - additionalDots < v + 3);
|
|
997
|
+
for (let j = 0; j < fakeCount_margin; j++) center_jAlign = alignment.find(v => j - additionalDots > v - 3 && j - additionalDots < v + 3),
|
|
976
998
|
null != fakeMatrix[i][j] && (this.lightDotsMask && (dot = count && center_jAlign && (count != alignment[0] && center_jAlign != alignment[0] || center_jAlign != alignment[0] && center_jAlign != alignment[alignment.length - 1] || count != alignment[0] && count != alignment[alignment.length - 1]) ? markerDot : overlayDot),
|
|
977
999
|
fakeMatrix[i][j] ? (dot.draw({
|
|
978
1000
|
x: minSize_xFakeBeginning + i * dotSize,
|
|
@@ -1011,7 +1033,7 @@ class QRSVG {
|
|
|
1011
1033
|
let options = this.options;
|
|
1012
1034
|
if (!this._element) throw Error("Element code is not defined");
|
|
1013
1035
|
let count = this.qr.getModuleCount(), dotSize = this.options.dotsOptions.size, cornersSquareSize = 7 * dotSize, cornersDotSize = 3 * dotSize, xBeginning = Math.floor((options.width - count * dotSize) / 2), yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1014
|
-
[ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach((
|
|
1036
|
+
[ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach(([column_cornersDot, row, dot]) => {
|
|
1015
1037
|
let x = xBeginning + column_cornersDot * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
|
|
1016
1038
|
var cornersDotMaskGroup_cornersSquareMask = this.dotsMask;
|
|
1017
1039
|
let cornersSquareMaskGroup = this.dotsMaskGroup;
|
|
@@ -1046,11 +1068,11 @@ class QRSVG {
|
|
|
1046
1068
|
size: dotSize,
|
|
1047
1069
|
getNeighbor: (xOffset, yOffset) => !squareMask[i + xOffset]?.[j + yOffset] && !dotMask[i + xOffset]?.[j + yOffset]
|
|
1048
1070
|
}), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
|
|
1049
|
-
if (this.lightDotsMask) for (let i = -1;
|
|
1071
|
+
if (this.lightDotsMask) for (let i = -1; i < 8; i++) for (let j = -1; j < 8; j++) -1 != i && 7 != i && -1 != j && 7 != j || (cornersDotMask_cornersSquare_dot.draw({
|
|
1050
1072
|
x: x + i * dotSize,
|
|
1051
1073
|
y: y + j * dotSize,
|
|
1052
1074
|
size: dotSize,
|
|
1053
|
-
getNeighbor: (ii, jj) => (jj = j + jj,
|
|
1075
|
+
getNeighbor: (ii, jj) => (jj = j + jj, (ii = i + ii) >= -1 && ii <= 7 && jj >= -1 && jj <= 7 && (-1 == ii || 7 == ii || -1 == jj || 7 == jj))
|
|
1054
1076
|
}), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
|
|
1055
1077
|
}
|
|
1056
1078
|
if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_cornersSquare_dot, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_cornersDot}-${row}`),
|
|
@@ -1077,7 +1099,7 @@ class QRSVG {
|
|
|
1077
1099
|
getNeighbor: (xOffset, yOffset) => !!dotMask[i + xOffset]?.[j + yOffset]
|
|
1078
1100
|
}), dot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(dot.element));
|
|
1079
1101
|
}
|
|
1080
|
-
})
|
|
1102
|
+
});
|
|
1081
1103
|
}
|
|
1082
1104
|
async drawImage({width: dw_width, height: dh_height, count, dotSize}) {
|
|
1083
1105
|
var image = this.options, dx = Math.floor((image.width - count * dotSize) / 2), encoding = Math.floor((image.height - count * dotSize) / 2), container_data = image.imageOptions.margin * dotSize;
|
|
@@ -1109,7 +1131,7 @@ class QRSVG {
|
|
|
1109
1131
|
gradient.setAttribute("r", numToAttr(size / 2)); else {
|
|
1110
1132
|
size = x + width / 2;
|
|
1111
1133
|
let y0 = y + height / 2;
|
|
1112
|
-
x += width / 2, y += height / 2,
|
|
1134
|
+
x += width / 2, y += height / 2, (additionalRotation_positiveRotation = ((color = ((options.rotation || 0) + additionalRotation_positiveRotation) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI)) >= 0 && additionalRotation_positiveRotation <= .25 * Math.PI || additionalRotation_positiveRotation > 1.75 * Math.PI && additionalRotation_positiveRotation <= 2 * Math.PI ? (size -= width / 2,
|
|
1113
1135
|
y0 -= height / 2 * Math.tan(color), x += width / 2, y += height / 2 * Math.tan(color)) : additionalRotation_positiveRotation > .25 * Math.PI && additionalRotation_positiveRotation <= .75 * Math.PI ? (y0 -= height / 2,
|
|
1114
1136
|
size -= width / 2 / Math.tan(color), y += height / 2, x += width / 2 / Math.tan(color)) : additionalRotation_positiveRotation > .75 * Math.PI && additionalRotation_positiveRotation <= 1.25 * Math.PI ? (size += width / 2,
|
|
1115
1137
|
y0 += height / 2 * Math.tan(color), x -= width / 2, y -= height / 2 * Math.tan(color)) : additionalRotation_positiveRotation > 1.25 * Math.PI && additionalRotation_positiveRotation <= 1.75 * Math.PI && (y0 += height / 2,
|
|
@@ -1119,14 +1141,14 @@ class QRSVG {
|
|
|
1119
1141
|
gradient.setAttribute("x1", numToAttr(size)), gradient.setAttribute("y1", numToAttr(y0)),
|
|
1120
1142
|
gradient.setAttribute("x2", numToAttr(x)), gradient.setAttribute("y2", numToAttr(y));
|
|
1121
1143
|
}
|
|
1122
|
-
options.colorStops.forEach(
|
|
1144
|
+
options.colorStops.forEach(parsed_stopCfg => {
|
|
1123
1145
|
let stop = this.document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
1124
1146
|
stop.setAttribute("offset", `${numToAttr(100 * parsed_stopCfg.offset)}%`), parsed_stopCfg = parseColor(parsed_stopCfg.color),
|
|
1125
|
-
stop.setAttribute("stop-color", parsed_stopCfg.value),
|
|
1147
|
+
stop.setAttribute("stop-color", parsed_stopCfg.value), parsed_stopCfg.alpha < 1 && stop.setAttribute("stop-opacity", parsed_stopCfg.alpha.toFixed(7)),
|
|
1126
1148
|
gradient.appendChild(stop);
|
|
1127
|
-
})
|
|
1149
|
+
}), rect.setAttribute("fill", `url(#${name})`), this.defs.appendChild(gradient);
|
|
1128
1150
|
} else color && (options = parseColor(color), rect.setAttribute("fill", options.value),
|
|
1129
|
-
|
|
1151
|
+
options.alpha < 1 && rect.setAttribute("opacity", options.alpha.toFixed(7)));
|
|
1130
1152
|
this._element.appendChild(rect);
|
|
1131
1153
|
}
|
|
1132
1154
|
createMask(group_id) {
|
|
@@ -1141,6 +1163,12 @@ class QRSVG {
|
|
|
1141
1163
|
Object.assign(QRCodeMinimal.stringToBytesFuncs, stringToBytes_UTF8);
|
|
1142
1164
|
|
|
1143
1165
|
let QRCodeStyling$1 = class {
|
|
1166
|
+
options;
|
|
1167
|
+
container;
|
|
1168
|
+
qr;
|
|
1169
|
+
extension;
|
|
1170
|
+
svgDrawingPromise;
|
|
1171
|
+
qrSVG;
|
|
1144
1172
|
get size() {
|
|
1145
1173
|
if (this.qrSVG) return {
|
|
1146
1174
|
width: this.qrSVG.width,
|
|
@@ -1192,7 +1220,7 @@ let QRCodeStyling$1 = class {
|
|
|
1192
1220
|
if (this.qr) {
|
|
1193
1221
|
var count = this.qr.getModuleCount();
|
|
1194
1222
|
this.options.imageOptions.mode == ImageMode.background && this.options.shape != ShapeType.circle && (count += 2),
|
|
1195
|
-
|
|
1223
|
+
(count = Math.ceil((this.options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * count)) % 2 == 0 && --count;
|
|
1196
1224
|
var margin = this.options.backgroundOptions && this.options.backgroundOptions.margin || 0;
|
|
1197
1225
|
this.options.imageOptions.mode == ImageMode.background && (margin += this.options.imageOptions.margin || 0),
|
|
1198
1226
|
count = Math.ceil(this.options.dotsOptions.size * (count + 2 * margin)), this.qrSVG = new QRSVG({
|
|
@@ -1200,30 +1228,30 @@ let QRCodeStyling$1 = class {
|
|
|
1200
1228
|
width: count,
|
|
1201
1229
|
height: count,
|
|
1202
1230
|
errorCorrectionPercent: ErrorCorrectionPercents[this.options.qrOptions.errorCorrectionLevel]
|
|
1203
|
-
}), this.svgDrawingPromise = this.qrSVG.drawQR(this.qr).then((
|
|
1231
|
+
}), this.svgDrawingPromise = this.qrSVG.drawQR(this.qr).then(() => {
|
|
1204
1232
|
this.qrSVG?.element && this.extension?.(this.qrSVG.element, this.options);
|
|
1205
|
-
})
|
|
1233
|
+
});
|
|
1206
1234
|
}
|
|
1207
1235
|
}
|
|
1208
1236
|
};
|
|
1209
1237
|
|
|
1210
1238
|
var FileExtension;
|
|
1211
1239
|
|
|
1212
|
-
(FileExtension = FileExtension
|
|
1213
|
-
FileExtension.
|
|
1240
|
+
(FileExtension = FileExtension ||= {}).svg = "svg", FileExtension.png = "png", FileExtension.jpeg = "jpeg",
|
|
1241
|
+
FileExtension.webp = "webp";
|
|
1214
1242
|
|
|
1215
1243
|
class QRCodeStyling extends QRCodeStyling$1 {
|
|
1216
1244
|
constructor(options) {
|
|
1217
1245
|
let dom = (new DOMImplementation).createDocument(null, ""), imageCache = new Map, loadImage = async buff => {
|
|
1218
1246
|
if ("string" == typeof buff) {
|
|
1219
1247
|
let pr = imageCache.get(buff);
|
|
1220
|
-
return pr || (pr = fetch(buff).then(
|
|
1221
|
-
contentType: res.headers.get("Content-Type") || await fileTypeFromBuffer(data).then(
|
|
1248
|
+
return pr || (pr = fetch(buff).then(res => res.arrayBuffer().then(buff => Buffer.from(buff)).then(async data => ({
|
|
1249
|
+
contentType: res.headers.get("Content-Type") || await fileTypeFromBuffer(data).then(r => r?.mime),
|
|
1222
1250
|
data
|
|
1223
|
-
})))
|
|
1251
|
+
}))), imageCache.set(buff, pr), pr);
|
|
1224
1252
|
}
|
|
1225
1253
|
return buff = Buffer.from(buff), {
|
|
1226
|
-
contentType: await fileTypeFromBuffer(buff).then(
|
|
1254
|
+
contentType: await fileTypeFromBuffer(buff).then(r => r?.mime),
|
|
1227
1255
|
data: buff
|
|
1228
1256
|
};
|
|
1229
1257
|
};
|
|
@@ -1231,7 +1259,7 @@ class QRCodeStyling extends QRCodeStyling$1 {
|
|
|
1231
1259
|
...options,
|
|
1232
1260
|
document: options.document || dom,
|
|
1233
1261
|
imageTools: options.imageTools || {
|
|
1234
|
-
toDataURL: url => "string" == typeof url && url.startsWith("data:") ? Promise.resolve(url) : loadImage(url).then((
|
|
1262
|
+
toDataURL: url => "string" == typeof url && url.startsWith("data:") ? Promise.resolve(url) : loadImage(url).then(({contentType, data}) => `data:${contentType?.replace("application/xml", "image/svg+xml")};base64,${data.toString("base64")}`),
|
|
1235
1263
|
getSize: async data => (({data} = Buffer.isBuffer(options.image) ? {
|
|
1236
1264
|
data: options.image
|
|
1237
1265
|
} : await loadImage(data)), {
|