remove qrious from frontend to use node qrcode

pull/3/head
TZGyn 2 years ago
parent 98f3e0e619
commit ef8026eead
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

Binary file not shown.

@ -48,7 +48,6 @@
"pg": "^8.11.3", "pg": "^8.11.3",
"postgres": "^3.4.3", "postgres": "^3.4.3",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
"qrious": "^4.0.2",
"svelte-sonner": "^0.3.10", "svelte-sonner": "^0.3.10",
"tailwind-merge": "^2.0.0", "tailwind-merge": "^2.0.0",
"tailwind-variants": "^0.1.18", "tailwind-variants": "^0.1.18",

@ -1,18 +1,11 @@
<script> <script>
import { onMount } from 'svelte' import QRCode from 'qrcode'
import { default as QrCode } from 'qrious'
import Button from './ui/button/button.svelte' import Button from './ui/button/button.svelte'
import { toast } from 'svelte-sonner' import { toast } from 'svelte-sonner'
const QRcode = new QrCode()
export let errorCorrection = 'L'
export let background = '#fff' export let background = '#fff'
export let color = '#000' export let color = '#000'
export let size = '300'
export let value = '' export let value = ''
export let padding = 10
export let className = 'qrcode'
export let code = '' export let code = ''
let image = '' let image = ''
@ -38,21 +31,24 @@
} }
} }
function generateQrCode() { async function generateQrCode() {
QRcode.set({ try {
background, image = await QRCode.toDataURL(value, {
foreground: color, errorCorrectionLevel: 'L',
level: errorCorrection, margin: 1,
padding, scale: 20,
size, color: {
value, light: background,
dark: color,
},
})
} catch (e) {
image = await QRCode.toDataURL(value, {
errorCorrectionLevel: 'L',
margin: 1,
scale: 20,
}) })
image = QRcode.toDataURL()
} }
export function getImage() {
return image
} }
$: { $: {
@ -60,13 +56,9 @@
generateQrCode() generateQrCode()
} }
} }
onMount(() => {
generateQrCode()
})
</script> </script>
<img src={image} alt={value} class={className} /> <img src={image} alt={value} width={300} height={300} />
<div class="flex w-full gap-4"> <div class="flex w-full gap-4">
<Button class="w-full" on:click={copyImageToClipboard} <Button class="w-full" on:click={copyImageToClipboard}
>Copy Image</Button> >Copy Image</Button>

@ -1,32 +1,31 @@
<script> <script>
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { default as QrCode } from 'qrious' import QRCode from 'qrcode'
export let errorCorrection = 'L'
export let background = '#fff' export let background = '#fff'
export let color = '#000' export let color = '#000'
export let size = '300'
export let value = 'example.com/abcdefgh' export let value = 'example.com/abcdefgh'
export let padding = 10
export let className = 'qrcode'
let image = '' let image = ''
function generateQrCode() { async function generateQrCode() {
if (!document || !window) { if (!document || !window) {
return return
} }
const QRcode = new QrCode()
QRcode.set({
background,
foreground: color,
level: errorCorrection,
padding,
size,
value,
})
image = QRcode.toDataURL() try {
image = await QRCode.toDataURL(value, {
errorCorrectionLevel: 'L',
margin: 1,
scale: 20,
color: {
light: background,
dark: color,
},
})
} catch (e) {
image = ''
}
} }
onMount(() => { onMount(() => {
@ -34,4 +33,4 @@
}) })
</script> </script>
<img src={image} alt={value} class={className} /> <img src={image} alt={value} width={300} height={300} />

Loading…
Cancel
Save