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';
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
export function saveQRCode(id: string): void {
 | 
			
		||||
  const qrCanvas = document.querySelector(`#${id}`) as HTMLCanvasElement;
 | 
			
		||||
  if (qrCanvas) {
 | 
			
		||||
    saveURLAsFile({
 | 
			
		||||
      filename: `${filename}-${new Date().toISOString()}.svg`,
 | 
			
		||||
      url,
 | 
			
		||||
      filename: `${id}-${new Date().toISOString()}.png`,
 | 
			
		||||
      url: qrCanvas.toDataURL(),
 | 
			
		||||
      document,
 | 
			
		||||
    });
 | 
			
		||||
  } else {
 | 
			
		||||
    window.log.info('[saveQRCode] QR code not found');
 | 
			
		||||
    window.log.error('[saveQRCode] QR code not found!');
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue