@liquid-js/qr-code-styling 4.0.6 → 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 -141
- package/lib/core/qr-code-styling.d.ts +2 -2
- package/lib/core/qr-svg.d.ts +3 -3
- package/lib/figures/corner-dot.d.ts +2 -2
- package/lib/figures/corner-square.d.ts +2 -2
- package/lib/figures/dot.d.ts +2 -2
- package/lib/index.d.ts +9 -9
- package/lib/kanji.js +1 -1
- package/lib/kanji.js.map +1 -1
- package/lib/node.d.ts +12 -12
- package/lib/qr-code-styling-node.js +115 -86
- 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/lib/tools/browser-image-tools.d.ts +2 -2
- package/lib/tools/browser-utils.d.ts +3 -3
- package/lib/types/helper.d.ts +7 -7
- package/lib/utils/gradient.d.ts +4 -4
- package/lib/utils/options.d.ts +3 -3
- package/lib/utils/qrcode.d.ts +1 -1
- package/package.json +1 -15
|
@@ -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,10 +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
|
-
Array.isArray(targetValue) && Array.isArray(sourceValue) ? target[key] = sourceValue : isObject(targetValue) && isObject(sourceValue) ? target[key] = mergeDeep(
|
|
25
|
-
|
|
24
|
+
Array.isArray(targetValue) && Array.isArray(sourceValue) ? target[key] = sourceValue : isObject(targetValue) && isObject(sourceValue) ? target[key] = mergeDeep({
|
|
25
|
+
...targetValue
|
|
26
|
+
}, sourceValue) : target[key] = sourceValue;
|
|
27
|
+
}), mergeDeep(target, ...sources)) : target;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
var GradientType, DotType, CornerDotType, CornerSquareType, ShapeType, ImageMode;
|
|
@@ -30,27 +32,27 @@ var GradientType, DotType, CornerDotType, CornerSquareType, ShapeType, ImageMode
|
|
|
30
32
|
function sanitizeGradient(gradient_newGradient) {
|
|
31
33
|
if (!(gradient_newGradient = {
|
|
32
34
|
...gradient_newGradient
|
|
33
|
-
}).colorStops || !gradient_newGradient.colorStops.length) throw "Field 'colorStops' is required in gradient";
|
|
35
|
+
}).colorStops || !gradient_newGradient.colorStops.length) throw Error("Field 'colorStops' is required in gradient");
|
|
34
36
|
return gradient_newGradient.rotation = gradient_newGradient.rotation ? Number(gradient_newGradient.rotation) : 0,
|
|
35
|
-
gradient_newGradient.colorStops = gradient_newGradient.colorStops.map(
|
|
37
|
+
gradient_newGradient.colorStops = gradient_newGradient.colorStops.map(colorStop => ({
|
|
36
38
|
...colorStop,
|
|
37
39
|
offset: Number(colorStop.offset)
|
|
38
|
-
}))
|
|
40
|
+
})), gradient_newGradient;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
(GradientType = GradientType
|
|
42
|
-
(DotType = DotType
|
|
43
|
-
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",
|
|
44
46
|
DotType.horizontalLine = "horizontal-line", DotType.classy = "classy", DotType.classyRounded = "classy-rounded",
|
|
45
47
|
DotType.square = "square", DotType.smallSquare = "small-square", DotType.tinySquare = "tiny-square",
|
|
46
|
-
DotType.diamond = "diamond", (CornerDotType = CornerDotType
|
|
48
|
+
DotType.diamond = "diamond", (CornerDotType = CornerDotType ||= {}).dot = "dot",
|
|
47
49
|
CornerDotType.square = "square", CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded",
|
|
48
50
|
CornerDotType.classy = "classy", CornerDotType.outpoint = "outpoint", CornerDotType.inpoint = "inpoint",
|
|
49
|
-
(CornerSquareType = CornerSquareType
|
|
51
|
+
(CornerSquareType = CornerSquareType ||= {}).dot = "dot", CornerSquareType.square = "square",
|
|
50
52
|
CornerSquareType.extraRounded = "extra-rounded", CornerSquareType.classy = "classy",
|
|
51
|
-
CornerSquareType.outpoint = "outpoint", CornerSquareType.inpoint = "inpoint", (ShapeType = ShapeType
|
|
52
|
-
ShapeType.circle = "circle", (ImageMode = ImageMode
|
|
53
|
-
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";
|
|
54
56
|
|
|
55
57
|
let defaultOptions = {
|
|
56
58
|
document: void 0,
|
|
@@ -121,13 +123,16 @@ function numToAttr(value) {
|
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
function svgPath(strings, ...values) {
|
|
124
|
-
return strings.reduce((
|
|
126
|
+
return strings.reduce((t, v, i) => {
|
|
125
127
|
let p = "";
|
|
126
128
|
return i && (p = values[i - 1]), "number" == typeof p && (p = numToAttr(p)), `${t}${p}${v}`;
|
|
127
|
-
}
|
|
129
|
+
}, "").trim().replace(/[\s\n\r]+/gim, " ");
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
class QRCornerDot {
|
|
133
|
+
type;
|
|
134
|
+
document;
|
|
135
|
+
_element;
|
|
131
136
|
get element() {
|
|
132
137
|
return this._element;
|
|
133
138
|
}
|
|
@@ -195,9 +200,9 @@ class QRCornerDot {
|
|
|
195
200
|
let {size, x, y} = args;
|
|
196
201
|
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
197
202
|
let move = !1, i = 0;
|
|
198
|
-
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(
|
|
199
|
-
move = v.toUpperCase() == v, v) : (i++, v *= size, move && (v +=
|
|
200
|
-
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(" "));
|
|
201
206
|
}
|
|
202
207
|
basicRounded(args) {
|
|
203
208
|
let {size, x, y} = args;
|
|
@@ -290,6 +295,10 @@ class QRCornerDot {
|
|
|
290
295
|
}
|
|
291
296
|
|
|
292
297
|
class QRCornerSquare {
|
|
298
|
+
type;
|
|
299
|
+
document;
|
|
300
|
+
_element;
|
|
301
|
+
_fill;
|
|
293
302
|
get element() {
|
|
294
303
|
return this._element;
|
|
295
304
|
}
|
|
@@ -442,6 +451,9 @@ class QRCornerSquare {
|
|
|
442
451
|
}
|
|
443
452
|
|
|
444
453
|
class QRDot {
|
|
454
|
+
type;
|
|
455
|
+
document;
|
|
456
|
+
_element;
|
|
445
457
|
get element() {
|
|
446
458
|
return this._element;
|
|
447
459
|
}
|
|
@@ -624,7 +636,7 @@ class QRDot {
|
|
|
624
636
|
y,
|
|
625
637
|
size,
|
|
626
638
|
rotation: 0
|
|
627
|
-
}) :
|
|
639
|
+
}) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? this.basicSquare({
|
|
628
640
|
x,
|
|
629
641
|
y,
|
|
630
642
|
size,
|
|
@@ -645,7 +657,7 @@ class QRDot {
|
|
|
645
657
|
}
|
|
646
658
|
drawVerticalLine({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
647
659
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
648
|
-
|
|
660
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || leftNeighbor && !topNeighbor && !bottomNeighbor || rightNeighbor && !topNeighbor && !bottomNeighbor ? this.basicDot({
|
|
649
661
|
x,
|
|
650
662
|
y,
|
|
651
663
|
size,
|
|
@@ -669,7 +681,7 @@ class QRDot {
|
|
|
669
681
|
}
|
|
670
682
|
drawHorizontalLine({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
671
683
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
672
|
-
|
|
684
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || topNeighbor && !leftNeighbor && !rightNeighbor || bottomNeighbor && !leftNeighbor && !rightNeighbor ? this.basicDot({
|
|
673
685
|
x,
|
|
674
686
|
y,
|
|
675
687
|
size,
|
|
@@ -700,7 +712,7 @@ class QRDot {
|
|
|
700
712
|
y,
|
|
701
713
|
size,
|
|
702
714
|
rotation: 0
|
|
703
|
-
}) :
|
|
715
|
+
}) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? this.basicSquare({
|
|
704
716
|
x,
|
|
705
717
|
y,
|
|
706
718
|
size,
|
|
@@ -721,7 +733,7 @@ class QRDot {
|
|
|
721
733
|
}
|
|
722
734
|
drawClassy({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
723
735
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
724
|
-
|
|
736
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
|
|
725
737
|
x,
|
|
726
738
|
y,
|
|
727
739
|
size,
|
|
@@ -745,7 +757,7 @@ class QRDot {
|
|
|
745
757
|
}
|
|
746
758
|
drawClassyRounded({x, y, size, getNeighbor: bottomNeighbor}) {
|
|
747
759
|
let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
748
|
-
|
|
760
|
+
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
|
|
749
761
|
x,
|
|
750
762
|
y,
|
|
751
763
|
size,
|
|
@@ -770,32 +782,32 @@ class QRDot {
|
|
|
770
782
|
}
|
|
771
783
|
|
|
772
784
|
let browserImageTools = {
|
|
773
|
-
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) => {
|
|
774
786
|
if ("string" == typeof url) {
|
|
775
787
|
const xhr = new XMLHttpRequest;
|
|
776
|
-
xhr.onload =
|
|
788
|
+
xhr.onload = () => {
|
|
777
789
|
const reader = new FileReader;
|
|
778
|
-
reader.onloadend =
|
|
790
|
+
reader.onloadend = () => {
|
|
779
791
|
resolve(reader.result);
|
|
780
792
|
}, reader.readAsDataURL(xhr.response);
|
|
781
793
|
}, xhr.onerror = xhr.onabort = xhr.ontimeout = reject, xhr.open("GET", url, !0),
|
|
782
794
|
xhr.responseType = "blob", xhr.send();
|
|
783
795
|
} else {
|
|
784
796
|
const reader = new FileReader;
|
|
785
|
-
reader.onloadend =
|
|
797
|
+
reader.onloadend = () => {
|
|
786
798
|
resolve(reader.result);
|
|
787
799
|
}, reader.readAsDataURL(url);
|
|
788
800
|
}
|
|
789
|
-
})
|
|
790
|
-
getSize: (src, crossOrigin) => new Promise((
|
|
801
|
+
}),
|
|
802
|
+
getSize: (src, crossOrigin) => new Promise((resolve, reject) => {
|
|
791
803
|
const image = new Image;
|
|
792
804
|
"string" === crossOrigin && (image.crossOrigin = crossOrigin), image.onload = () => {
|
|
793
805
|
resolve({
|
|
794
806
|
width: image.width,
|
|
795
807
|
height: image.height
|
|
796
808
|
});
|
|
797
|
-
}, image.onerror = image.onabort = reject, "string" == typeof src ? image.src = src : browserImageTools.toDataURL(src).then(
|
|
798
|
-
})
|
|
809
|
+
}, image.onerror = image.onabort = reject, "string" == typeof src ? image.src = src : browserImageTools.toDataURL(src).then(url => image.src = url).catch(reject);
|
|
810
|
+
})
|
|
799
811
|
};
|
|
800
812
|
|
|
801
813
|
function parseColor(base) {
|
|
@@ -803,7 +815,7 @@ function parseColor(base) {
|
|
|
803
815
|
let alpha = 1;
|
|
804
816
|
if ("#" === (base = base.toLowerCase())[0]) {
|
|
805
817
|
let size = (base = base.slice(1)).length;
|
|
806
|
-
|
|
818
|
+
size <= 4 ? (m_parts = [ parseInt(base[0] + base[0], 16), parseInt(base[1] + base[1], 16), parseInt(base[2] + base[2], 16) ],
|
|
807
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) ],
|
|
808
820
|
8 === size && (alpha = parseInt(base[6] + base[7], 16) / 255)), m_parts[0] || (m_parts[0] = 0),
|
|
809
821
|
m_parts[1] || (m_parts[1] = 0), m_parts[2] || (m_parts[2] = 0);
|
|
@@ -812,11 +824,11 @@ function parseColor(base) {
|
|
|
812
824
|
value: base,
|
|
813
825
|
alpha
|
|
814
826
|
};
|
|
815
|
-
alpha =
|
|
816
|
-
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;
|
|
817
829
|
}
|
|
818
830
|
return {
|
|
819
|
-
value: "#" + m_parts.map(
|
|
831
|
+
value: "#" + m_parts.map(v => Math.max(0, Math.min(255, v)).toString(16).padStart(2, "0")).join(""),
|
|
820
832
|
alpha: Math.max(0, Math.min(1, alpha))
|
|
821
833
|
};
|
|
822
834
|
}
|
|
@@ -824,9 +836,21 @@ function parseColor(base) {
|
|
|
824
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 ] ];
|
|
825
837
|
|
|
826
838
|
class QRSVG {
|
|
839
|
+
options;
|
|
840
|
+
_element;
|
|
827
841
|
get element() {
|
|
828
842
|
return this._element;
|
|
829
843
|
}
|
|
844
|
+
defs;
|
|
845
|
+
backgroundMask;
|
|
846
|
+
backgroundMaskGroup;
|
|
847
|
+
dotsMask;
|
|
848
|
+
dotsMaskGroup;
|
|
849
|
+
lightDotsMask;
|
|
850
|
+
lightDotsMaskGroup;
|
|
851
|
+
qr;
|
|
852
|
+
document;
|
|
853
|
+
imageTools;
|
|
830
854
|
constructor(options) {
|
|
831
855
|
this.options = options, this.document = options.document, this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
832
856
|
let width = numToAttr(options.width), height = numToAttr(options.height);
|
|
@@ -867,28 +891,28 @@ class QRSVG {
|
|
|
867
891
|
};
|
|
868
892
|
} else coverLevel_margin = imageOptions.imageSize * errorCorrectionPercent, alignment_maxWidth_typeNumber = QRUtil.getPatternPosition(alignment_maxWidth_typeNumber),
|
|
869
893
|
drawImageSize = function({originalHeight, originalWidth, maxHiddenDots: JSCompiler_object_inline_x_16_hideMax_maxHiddenDots, maxHiddenAxisDots: JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper, dotSize, margin}) {
|
|
870
|
-
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 {
|
|
871
895
|
height: 0,
|
|
872
896
|
width: 0,
|
|
873
897
|
hideYDots: 0,
|
|
874
898
|
hideXDots: 0
|
|
875
899
|
};
|
|
876
|
-
JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper &&
|
|
877
|
-
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;
|
|
878
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;
|
|
879
903
|
do {
|
|
880
|
-
let
|
|
881
|
-
|
|
882
|
-
let dotsMin = Math.max(1, Math.ceil(
|
|
883
|
-
|
|
884
|
-
} while (
|
|
885
|
-
return
|
|
886
|
-
|
|
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++;
|
|
906
|
+
let dotsMin = Math.max(1, Math.ceil(newSize * JSCompiler_object_inline_y_15_dimMin_hideMin / JSCompiler_object_inline_x_14_dimMax + 2 * margin));
|
|
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++,
|
|
887
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,
|
|
888
912
|
JSCompiler_object_inline_y_15_dimMin_hideMin = JSCompiler_object_inline_x_16_hideMax_maxHiddenDots),
|
|
889
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,
|
|
890
|
-
(JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper = JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper * originalHeight / originalWidth) > (
|
|
891
|
-
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),
|
|
892
916
|
{
|
|
893
917
|
height: Math.round(JSCompiler_object_inline_y_17_maxHiddenAxisDots_maxW_upper + 2 * margin * dotSize),
|
|
894
918
|
width: Math.round(JSCompiler_object_inline_x_16_hideMax_maxHiddenDots + 2 * margin * dotSize),
|
|
@@ -898,19 +922,19 @@ class QRSVG {
|
|
|
898
922
|
}({
|
|
899
923
|
originalWidth: qr_size.width,
|
|
900
924
|
originalHeight: qr_size.height,
|
|
901
|
-
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)),
|
|
902
926
|
maxHiddenAxisDots: count - 14,
|
|
903
927
|
dotSize,
|
|
904
928
|
margin: imageOptions.margin
|
|
905
929
|
});
|
|
906
930
|
}
|
|
907
|
-
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({
|
|
908
932
|
width: drawImageSize.width,
|
|
909
933
|
height: drawImageSize.height,
|
|
910
934
|
count,
|
|
911
935
|
dotSize
|
|
912
|
-
}), this.drawDots((
|
|
913
|
-
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({
|
|
914
938
|
width: drawImageSize.width,
|
|
915
939
|
height: drawImageSize.height,
|
|
916
940
|
count,
|
|
@@ -939,10 +963,10 @@ class QRSVG {
|
|
|
939
963
|
}
|
|
940
964
|
}
|
|
941
965
|
drawDots(alignment) {
|
|
942
|
-
if (!this.qr) throw "QR code is not defined";
|
|
966
|
+
if (!this.qr) throw Error("QR code is not defined");
|
|
943
967
|
let options = this.options;
|
|
944
968
|
var count = this.qr.getModuleCount();
|
|
945
|
-
if (count > options.width || count > options.height) throw "The canvas is too small
|
|
969
|
+
if (count > options.width || count > options.height) throw Error("The canvas is too small");
|
|
946
970
|
let dotSize = this.options.dotsOptions.size;
|
|
947
971
|
var minSize_xFakeBeginning = Math.min(options.width, options.height);
|
|
948
972
|
options.imageOptions.mode == ImageMode.background && (minSize_xFakeBeginning -= 2 * dotSize * (options.imageOptions.margin || 0));
|
|
@@ -965,12 +989,12 @@ class QRSVG {
|
|
|
965
989
|
for (let j = 0; j < fakeCount_margin; j++) if (i > additionalDots - 1 && i < fakeCount_margin - additionalDots && j > additionalDots - 1 && j < fakeCount_margin - additionalDots) {
|
|
966
990
|
let ii = i - additionalDots, jj = j - additionalDots;
|
|
967
991
|
alignment && !alignment(ii, jj) ? fakeMatrix[i][j] = void 0 : fakeMatrix[i][j] = !!this.qr.isDark(jj, ii);
|
|
968
|
-
} 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);
|
|
969
993
|
}
|
|
970
994
|
alignment = QRUtil.getPatternPosition((count - 17) / 4);
|
|
971
995
|
for (let i = 0; i < fakeCount_margin; i++) {
|
|
972
|
-
count = alignment.find(
|
|
973
|
-
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),
|
|
974
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),
|
|
975
999
|
fakeMatrix[i][j] ? (dot.draw({
|
|
976
1000
|
x: minSize_xFakeBeginning + i * dotSize,
|
|
@@ -1005,11 +1029,11 @@ class QRSVG {
|
|
|
1005
1029
|
});
|
|
1006
1030
|
}
|
|
1007
1031
|
drawCorners() {
|
|
1008
|
-
if (!this.qr) throw "QR code is not defined";
|
|
1032
|
+
if (!this.qr) throw Error("QR code is not defined");
|
|
1009
1033
|
let options = this.options;
|
|
1010
|
-
if (!this._element) throw "Element code is not defined";
|
|
1034
|
+
if (!this._element) throw Error("Element code is not defined");
|
|
1011
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);
|
|
1012
|
-
[ [ 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]) => {
|
|
1013
1037
|
let x = xBeginning + column_cornersDot * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
|
|
1014
1038
|
var cornersDotMaskGroup_cornersSquareMask = this.dotsMask;
|
|
1015
1039
|
let cornersSquareMaskGroup = this.dotsMaskGroup;
|
|
@@ -1044,11 +1068,11 @@ class QRSVG {
|
|
|
1044
1068
|
size: dotSize,
|
|
1045
1069
|
getNeighbor: (xOffset, yOffset) => !squareMask[i + xOffset]?.[j + yOffset] && !dotMask[i + xOffset]?.[j + yOffset]
|
|
1046
1070
|
}), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
|
|
1047
|
-
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({
|
|
1048
1072
|
x: x + i * dotSize,
|
|
1049
1073
|
y: y + j * dotSize,
|
|
1050
1074
|
size: dotSize,
|
|
1051
|
-
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))
|
|
1052
1076
|
}), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
|
|
1053
1077
|
}
|
|
1054
1078
|
if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_cornersSquare_dot, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_cornersDot}-${row}`),
|
|
@@ -1075,7 +1099,7 @@ class QRSVG {
|
|
|
1075
1099
|
getNeighbor: (xOffset, yOffset) => !!dotMask[i + xOffset]?.[j + yOffset]
|
|
1076
1100
|
}), dot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(dot.element));
|
|
1077
1101
|
}
|
|
1078
|
-
})
|
|
1102
|
+
});
|
|
1079
1103
|
}
|
|
1080
1104
|
async drawImage({width: dw_width, height: dh_height, count, dotSize}) {
|
|
1081
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;
|
|
@@ -1107,7 +1131,7 @@ class QRSVG {
|
|
|
1107
1131
|
gradient.setAttribute("r", numToAttr(size / 2)); else {
|
|
1108
1132
|
size = x + width / 2;
|
|
1109
1133
|
let y0 = y + height / 2;
|
|
1110
|
-
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,
|
|
1111
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,
|
|
1112
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,
|
|
1113
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,
|
|
@@ -1117,14 +1141,14 @@ class QRSVG {
|
|
|
1117
1141
|
gradient.setAttribute("x1", numToAttr(size)), gradient.setAttribute("y1", numToAttr(y0)),
|
|
1118
1142
|
gradient.setAttribute("x2", numToAttr(x)), gradient.setAttribute("y2", numToAttr(y));
|
|
1119
1143
|
}
|
|
1120
|
-
options.colorStops.forEach(
|
|
1144
|
+
options.colorStops.forEach(parsed_stopCfg => {
|
|
1121
1145
|
let stop = this.document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
1122
|
-
stop.setAttribute("offset", `${numToAttr(100 * offset)}%`),
|
|
1123
|
-
stop.setAttribute("stop-color",
|
|
1146
|
+
stop.setAttribute("offset", `${numToAttr(100 * parsed_stopCfg.offset)}%`), parsed_stopCfg = parseColor(parsed_stopCfg.color),
|
|
1147
|
+
stop.setAttribute("stop-color", parsed_stopCfg.value), parsed_stopCfg.alpha < 1 && stop.setAttribute("stop-opacity", parsed_stopCfg.alpha.toFixed(7)),
|
|
1124
1148
|
gradient.appendChild(stop);
|
|
1125
|
-
})
|
|
1149
|
+
}), rect.setAttribute("fill", `url(#${name})`), this.defs.appendChild(gradient);
|
|
1126
1150
|
} else color && (options = parseColor(color), rect.setAttribute("fill", options.value),
|
|
1127
|
-
|
|
1151
|
+
options.alpha < 1 && rect.setAttribute("opacity", options.alpha.toFixed(7)));
|
|
1128
1152
|
this._element.appendChild(rect);
|
|
1129
1153
|
}
|
|
1130
1154
|
createMask(group_id) {
|
|
@@ -1139,6 +1163,12 @@ class QRSVG {
|
|
|
1139
1163
|
Object.assign(QRCodeMinimal.stringToBytesFuncs, stringToBytes_UTF8);
|
|
1140
1164
|
|
|
1141
1165
|
let QRCodeStyling$1 = class {
|
|
1166
|
+
options;
|
|
1167
|
+
container;
|
|
1168
|
+
qr;
|
|
1169
|
+
extension;
|
|
1170
|
+
svgDrawingPromise;
|
|
1171
|
+
qrSVG;
|
|
1142
1172
|
get size() {
|
|
1143
1173
|
if (this.qrSVG) return {
|
|
1144
1174
|
width: this.qrSVG.width,
|
|
@@ -1175,14 +1205,14 @@ let QRCodeStyling$1 = class {
|
|
|
1175
1205
|
this.container = container);
|
|
1176
1206
|
}
|
|
1177
1207
|
applyExtension(extension) {
|
|
1178
|
-
if (!extension) throw "Extension function should be defined.";
|
|
1208
|
+
if (!extension) throw Error("Extension function should be defined.");
|
|
1179
1209
|
this.extension = extension, this.update();
|
|
1180
1210
|
}
|
|
1181
1211
|
deleteExtension() {
|
|
1182
1212
|
this.extension = void 0, this.update();
|
|
1183
1213
|
}
|
|
1184
1214
|
async serialize() {
|
|
1185
|
-
if (!this.qr) throw "QR code is empty";
|
|
1215
|
+
if (!this.qr) throw Error("QR code is empty");
|
|
1186
1216
|
if (this.qrSVG?.element && this.svgDrawingPromise || this.setupSvg(), await this.svgDrawingPromise,
|
|
1187
1217
|
this.qrSVG?.element) return '<?xml version="1.0" standalone="no"?>\r\n' + (new XMLSerializer).serializeToString(this.qrSVG.element);
|
|
1188
1218
|
}
|
|
@@ -1190,7 +1220,7 @@ let QRCodeStyling$1 = class {
|
|
|
1190
1220
|
if (this.qr) {
|
|
1191
1221
|
var count = this.qr.getModuleCount();
|
|
1192
1222
|
this.options.imageOptions.mode == ImageMode.background && this.options.shape != ShapeType.circle && (count += 2),
|
|
1193
|
-
|
|
1223
|
+
(count = Math.ceil((this.options.shape == ShapeType.circle ? Math.sqrt(2) : 1) * count)) % 2 == 0 && --count;
|
|
1194
1224
|
var margin = this.options.backgroundOptions && this.options.backgroundOptions.margin || 0;
|
|
1195
1225
|
this.options.imageOptions.mode == ImageMode.background && (margin += this.options.imageOptions.margin || 0),
|
|
1196
1226
|
count = Math.ceil(this.options.dotsOptions.size * (count + 2 * margin)), this.qrSVG = new QRSVG({
|
|
@@ -1198,39 +1228,38 @@ let QRCodeStyling$1 = class {
|
|
|
1198
1228
|
width: count,
|
|
1199
1229
|
height: count,
|
|
1200
1230
|
errorCorrectionPercent: ErrorCorrectionPercents[this.options.qrOptions.errorCorrectionLevel]
|
|
1201
|
-
}), this.svgDrawingPromise = this.qrSVG.drawQR(this.qr).then((
|
|
1231
|
+
}), this.svgDrawingPromise = this.qrSVG.drawQR(this.qr).then(() => {
|
|
1202
1232
|
this.qrSVG?.element && this.extension?.(this.qrSVG.element, this.options);
|
|
1203
|
-
})
|
|
1233
|
+
});
|
|
1204
1234
|
}
|
|
1205
1235
|
}
|
|
1206
1236
|
};
|
|
1207
1237
|
|
|
1208
1238
|
var FileExtension;
|
|
1209
1239
|
|
|
1210
|
-
(FileExtension = FileExtension
|
|
1211
|
-
FileExtension.
|
|
1240
|
+
(FileExtension = FileExtension ||= {}).svg = "svg", FileExtension.png = "png", FileExtension.jpeg = "jpeg",
|
|
1241
|
+
FileExtension.webp = "webp";
|
|
1212
1242
|
|
|
1213
1243
|
class QRCodeStyling extends QRCodeStyling$1 {
|
|
1214
1244
|
constructor(options) {
|
|
1215
|
-
|
|
1245
|
+
let dom = (new DOMImplementation).createDocument(null, ""), imageCache = new Map, loadImage = async buff => {
|
|
1216
1246
|
if ("string" == typeof buff) {
|
|
1217
1247
|
let pr = imageCache.get(buff);
|
|
1218
|
-
return pr || (pr = fetch(buff).then(
|
|
1219
|
-
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),
|
|
1220
1250
|
data
|
|
1221
|
-
})))
|
|
1251
|
+
}))), imageCache.set(buff, pr), pr);
|
|
1222
1252
|
}
|
|
1223
1253
|
return buff = Buffer.from(buff), {
|
|
1224
|
-
contentType: await fileTypeFromBuffer(buff).then(
|
|
1254
|
+
contentType: await fileTypeFromBuffer(buff).then(r => r?.mime),
|
|
1225
1255
|
data: buff
|
|
1226
1256
|
};
|
|
1227
|
-
}
|
|
1228
|
-
let dom = (new DOMImplementation).createDocument(null, ""), imageCache = new Map;
|
|
1257
|
+
};
|
|
1229
1258
|
global.XMLSerializer = XMLSerializer$1, global.DOMParser = DOMParser$1, super({
|
|
1230
1259
|
...options,
|
|
1231
1260
|
document: options.document || dom,
|
|
1232
1261
|
imageTools: options.imageTools || {
|
|
1233
|
-
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")}`),
|
|
1234
1263
|
getSize: async data => (({data} = Buffer.isBuffer(options.image) ? {
|
|
1235
1264
|
data: options.image
|
|
1236
1265
|
} : await loadImage(data)), {
|