feat: replace react-qr-svg with react-qrcode-logo
updated error correction to 25%pull/3083/head
parent
551ee4221b
commit
ab093ffc62
@ -1,28 +1,14 @@
|
|||||||
import { saveURLAsFile } from './saveURLAsFile';
|
import { saveURLAsFile } from './saveURLAsFile';
|
||||||
|
|
||||||
export function saveQRCode(
|
export function saveQRCode(id: string): void {
|
||||||
filename: string,
|
const qrCanvas = document.querySelector(`#${id}`) as HTMLCanvasElement;
|
||||||
width: string,
|
if (qrCanvas) {
|
||||||
height: string,
|
|
||||||
backgroundColor: string,
|
|
||||||
foregroundColor: string
|
|
||||||
): void {
|
|
||||||
const qrSVG = document.querySelector('.qr-image svg');
|
|
||||||
if (qrSVG) {
|
|
||||||
qrSVG.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
||||||
qrSVG.setAttribute('width', width);
|
|
||||||
qrSVG.setAttribute('height', height);
|
|
||||||
let content = qrSVG.outerHTML;
|
|
||||||
content = content.replaceAll(backgroundColor, 'white');
|
|
||||||
content = content.replaceAll(foregroundColor, 'black');
|
|
||||||
const file = new Blob([content], { type: 'text/plain' });
|
|
||||||
const url = URL.createObjectURL(file);
|
|
||||||
saveURLAsFile({
|
saveURLAsFile({
|
||||||
filename: `${filename}-${new Date().toISOString()}.svg`,
|
filename: `${id}-${new Date().toISOString()}.png`,
|
||||||
url,
|
url: qrCanvas.toDataURL(),
|
||||||
document,
|
document,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
window.log.info('[saveQRCode] QR code not found');
|
window.log.error('[saveQRCode] QR code not found!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue