generated from fastn-stack/fastn-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qrCode.js
48 lines (42 loc) · 1.71 KB
/
qrCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function qrCodeGenerate(id, url) {
id = fastn_utils.getStaticValue(id);
url = fastn_utils.getStaticValue(url);
new QRCode(document.getElementById(id), url);
}
function qrCodeGenerateWithConfig(id, url, width, height, color, bgColor, darkmode, level) {
id = fastn_utils.getStaticValue(id);
url = fastn_utils.getStaticValue(url);
width = fastn_utils.getStaticValue(width);
height = fastn_utils.getStaticValue(height);
color = fastn_utils.getStaticValue(color);
bgColor = fastn_utils.getStaticValue(bgColor);
darkmode = fastn_utils.getStaticValue(darkmode);
level = fastn_utils.getStaticValue(level);
if (darkmode) {
if (color instanceof fastn.recordInstanceClass) {
color = fastn_utils.getStaticValue(color.get("dark"));
}
if (bgColor instanceof fastn.recordInstanceClass) {
bgColor = fastn_utils.getStaticValue(bgColor.get("dark"));
}
} else {
if (color instanceof fastn.recordInstanceClass) {
color = fastn_utils.getStaticValue(color.get("light"));
}
if (bgColor instanceof fastn.recordInstanceClass) {
bgColor = fastn_utils.getStaticValue(bgColor.get("light"));
}
}
const container = document.getElementById(id); // Replace 'containerId' with the ID of your container element
while (container.firstChild) {
container.firstChild.remove();
}
new QRCode(container, {
text: url,
width: width ?? 256,
height: height ?? 256 ,
colorDark : color ?? "#000",
colorLight : bgColor ?? "#ffffff",
correctLevel : !fastn_utils.isNull(level) ? (level > 3 ? 3: (level < 0 ? 0 : level)) : QRCode.CorrectLevel.H
});
}