| 
									
										
										
										
											2023-11-15 03:42:37 +01:00
										 |  |  | import Qrcode from "qrcode-generator" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Creates a QR-code as Blob | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export default class Qr { | 
					
						
							| 
									
										
										
										
											2023-12-24 05:01:10 +01:00
										 |  |  |     private readonly _textToShow: string | 
					
						
							| 
									
										
										
										
											2023-11-15 03:42:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(textToShow: string) { | 
					
						
							|  |  |  |         this._textToShow = textToShow | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public toImageElement(totalSize: number): string { | 
					
						
							|  |  |  |         const typeNumber = 0 | 
					
						
							|  |  |  |         const errorCorrectionLevel = "L" | 
					
						
							|  |  |  |         const qr = Qrcode(typeNumber, errorCorrectionLevel) | 
					
						
							|  |  |  |         qr.addData(this._textToShow) | 
					
						
							|  |  |  |         qr.make() | 
					
						
							|  |  |  |         const moduleCount = qr.getModuleCount() | 
					
						
							|  |  |  |         const cellSize = Math.round(totalSize / moduleCount) | 
					
						
							|  |  |  |         return qr.createDataURL(cellSize) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |