@liquid-js/qr-code-styling 1.10.3 → 1.10.4
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.
|
@@ -612,6 +612,56 @@ class QRDot {
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
+
const browserImageTools = {
|
|
616
|
+
toDataURL(url) {
|
|
617
|
+
return new Promise((resolve, reject) => {
|
|
618
|
+
if (typeof url == "string") {
|
|
619
|
+
const xhr = new XMLHttpRequest();
|
|
620
|
+
xhr.onload = function () {
|
|
621
|
+
const reader = new FileReader();
|
|
622
|
+
reader.onloadend = function () {
|
|
623
|
+
resolve(reader.result);
|
|
624
|
+
};
|
|
625
|
+
reader.readAsDataURL(xhr.response);
|
|
626
|
+
};
|
|
627
|
+
xhr.onerror = xhr.onabort = xhr.ontimeout = reject;
|
|
628
|
+
xhr.open("GET", url);
|
|
629
|
+
xhr.responseType = "blob";
|
|
630
|
+
xhr.send();
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
const reader = new FileReader();
|
|
634
|
+
reader.onloadend = function () {
|
|
635
|
+
resolve(reader.result);
|
|
636
|
+
};
|
|
637
|
+
reader.readAsDataURL(url);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
getSize(options) {
|
|
642
|
+
return new Promise((resolve, reject) => {
|
|
643
|
+
if (!options.image) {
|
|
644
|
+
return reject("Image is not defined");
|
|
645
|
+
}
|
|
646
|
+
const image = new Image();
|
|
647
|
+
if (typeof options.imageOptions.crossOrigin === "string") {
|
|
648
|
+
image.crossOrigin = options.imageOptions.crossOrigin;
|
|
649
|
+
}
|
|
650
|
+
image.onload = () => {
|
|
651
|
+
resolve({ width: image.width, height: image.height });
|
|
652
|
+
};
|
|
653
|
+
image.onerror = image.onabort = reject;
|
|
654
|
+
if (typeof options.image == "string")
|
|
655
|
+
image.src = options.image;
|
|
656
|
+
else
|
|
657
|
+
browserImageTools
|
|
658
|
+
.toDataURL(options.image)
|
|
659
|
+
.then((url) => (image.src = url))
|
|
660
|
+
.catch(reject);
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
615
665
|
function calculateImageSize({ originalHeight, originalWidth, maxHiddenDots, maxHiddenAxisDots, dotSize, margin }) {
|
|
616
666
|
const hideDots = { x: 0, y: 0 };
|
|
617
667
|
const imageSize = { x: 0, y: 0 };
|
|
@@ -682,56 +732,6 @@ function calculateImageSize({ originalHeight, originalWidth, maxHiddenDots, maxH
|
|
|
682
732
|
};
|
|
683
733
|
}
|
|
684
734
|
|
|
685
|
-
const browserImageTools = {
|
|
686
|
-
toDataURL(url) {
|
|
687
|
-
return new Promise((resolve, reject) => {
|
|
688
|
-
if (typeof url == "string") {
|
|
689
|
-
const xhr = new XMLHttpRequest();
|
|
690
|
-
xhr.onload = function () {
|
|
691
|
-
const reader = new FileReader();
|
|
692
|
-
reader.onloadend = function () {
|
|
693
|
-
resolve(reader.result);
|
|
694
|
-
};
|
|
695
|
-
reader.readAsDataURL(xhr.response);
|
|
696
|
-
};
|
|
697
|
-
xhr.onerror = xhr.onabort = xhr.ontimeout = reject;
|
|
698
|
-
xhr.open("GET", url);
|
|
699
|
-
xhr.responseType = "blob";
|
|
700
|
-
xhr.send();
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
const reader = new FileReader();
|
|
704
|
-
reader.onloadend = function () {
|
|
705
|
-
resolve(reader.result);
|
|
706
|
-
};
|
|
707
|
-
reader.readAsDataURL(url);
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
},
|
|
711
|
-
getSize(options) {
|
|
712
|
-
return new Promise((resolve, reject) => {
|
|
713
|
-
if (!options.image) {
|
|
714
|
-
return reject("Image is not defined");
|
|
715
|
-
}
|
|
716
|
-
const image = new Image();
|
|
717
|
-
if (typeof options.imageOptions.crossOrigin === "string") {
|
|
718
|
-
image.crossOrigin = options.imageOptions.crossOrigin;
|
|
719
|
-
}
|
|
720
|
-
image.onload = () => {
|
|
721
|
-
resolve({ width: image.width, height: image.height });
|
|
722
|
-
};
|
|
723
|
-
image.onerror = image.onabort = reject;
|
|
724
|
-
if (typeof options.image == "string")
|
|
725
|
-
image.src = options.image;
|
|
726
|
-
else
|
|
727
|
-
browserImageTools
|
|
728
|
-
.toDataURL(options.image)
|
|
729
|
-
.then((url) => (image.src = url))
|
|
730
|
-
.catch(reject);
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
|
|
735
735
|
const squareMask = [
|
|
736
736
|
[1, 1, 1, 1, 1, 1, 1],
|
|
737
737
|
[1, 0, 0, 0, 0, 0, 1],
|
|
@@ -750,48 +750,6 @@ const dotMask = [
|
|
|
750
750
|
[0, 0, 0, 0, 0, 0, 0],
|
|
751
751
|
[0, 0, 0, 0, 0, 0, 0]
|
|
752
752
|
];
|
|
753
|
-
const dataCount = {
|
|
754
|
-
"1": 104,
|
|
755
|
-
"2": 176,
|
|
756
|
-
"3": 272,
|
|
757
|
-
"4": 384,
|
|
758
|
-
"5": 496,
|
|
759
|
-
"6": 608,
|
|
760
|
-
"7": 704,
|
|
761
|
-
"8": 880,
|
|
762
|
-
"9": 1056,
|
|
763
|
-
"10": 1232,
|
|
764
|
-
"11": 1440,
|
|
765
|
-
"12": 1648,
|
|
766
|
-
"13": 1952,
|
|
767
|
-
"14": 2088,
|
|
768
|
-
"15": 2360,
|
|
769
|
-
"16": 2600,
|
|
770
|
-
"17": 2936,
|
|
771
|
-
"18": 3176,
|
|
772
|
-
"19": 3560,
|
|
773
|
-
"20": 3880,
|
|
774
|
-
"21": 4096,
|
|
775
|
-
"22": 4544,
|
|
776
|
-
"23": 4912,
|
|
777
|
-
"24": 5312,
|
|
778
|
-
"25": 5744,
|
|
779
|
-
"26": 6032,
|
|
780
|
-
"27": 6464,
|
|
781
|
-
"28": 6968,
|
|
782
|
-
"29": 7288,
|
|
783
|
-
"30": 7880,
|
|
784
|
-
"31": 8264,
|
|
785
|
-
"32": 8920,
|
|
786
|
-
"33": 9368,
|
|
787
|
-
"34": 9848,
|
|
788
|
-
"35": 10288,
|
|
789
|
-
"36": 10832,
|
|
790
|
-
"37": 11408,
|
|
791
|
-
"38": 12016,
|
|
792
|
-
"39": 12656,
|
|
793
|
-
"40": 13328
|
|
794
|
-
};
|
|
795
753
|
class QRSVG {
|
|
796
754
|
//TODO don't pass all options to this class
|
|
797
755
|
constructor(options) {
|
|
@@ -816,7 +774,6 @@ class QRSVG {
|
|
|
816
774
|
}
|
|
817
775
|
async drawQR(qr) {
|
|
818
776
|
const count = qr.getModuleCount();
|
|
819
|
-
const typeNumber = ((count - 17) / 4).toFixed(0);
|
|
820
777
|
const dotSize = this._options.dotsOptions.size;
|
|
821
778
|
let drawImageSize = {
|
|
822
779
|
hideXDots: 0,
|
|
@@ -830,7 +787,7 @@ class QRSVG {
|
|
|
830
787
|
const size = await this._imageTools.getSize(this._options);
|
|
831
788
|
const { imageOptions, qrOptions } = this._options;
|
|
832
789
|
const coverLevel = imageOptions.imageSize * ErrorCorrectionPercents[qrOptions.errorCorrectionLevel];
|
|
833
|
-
const maxHiddenDots = Math.floor(coverLevel *
|
|
790
|
+
const maxHiddenDots = Math.floor(coverLevel * (count * count - 3 * 8 * 8 - 2 * (count - 16)));
|
|
834
791
|
drawImageSize = calculateImageSize({
|
|
835
792
|
originalWidth: size.width,
|
|
836
793
|
originalHeight: size.height,
|