You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/util/saveQRCode.ts

29 lines
863 B
TypeScript

import { saveURLAsFile } from './saveURLAsFile';
export function saveQRCode(
filename: string,
width: string,
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({
filename: `${filename}-${new Date().toISOString()}.svg`,
url,
document,
});
} else {
window.log.info('[saveQRCode] QR code not found');
}
}