@liquid-js/qr-code-styling 1.10.2 → 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],
|
|
@@ -787,7 +787,7 @@ class QRSVG {
|
|
|
787
787
|
const size = await this._imageTools.getSize(this._options);
|
|
788
788
|
const { imageOptions, qrOptions } = this._options;
|
|
789
789
|
const coverLevel = imageOptions.imageSize * ErrorCorrectionPercents[qrOptions.errorCorrectionLevel];
|
|
790
|
-
const maxHiddenDots = Math.floor(coverLevel * count * count);
|
|
790
|
+
const maxHiddenDots = Math.floor(coverLevel * (count * count - 3 * 8 * 8 - 2 * (count - 16)));
|
|
791
791
|
drawImageSize = calculateImageSize({
|
|
792
792
|
originalWidth: size.width,
|
|
793
793
|
originalHeight: size.height,
|