import QRCode from 'qrcode'
self.onmessage = async (e) => {
const { id, text, ecc, isBgTransparent, bgColor, fgType, fgColor1, fgColor2 } = e.data
if (!text) {
self.postMessage({ id, svgContent: '' })
return
}
try {
let svgContent = await QRCode.toString(text, {
type: 'svg',
errorCorrectionLevel: ecc,
margin: 1,
color: {
dark: fgType === 'solid' ? fgColor1 : '#000000',
light: isBgTransparent ? '#00000000' : bgColor
}
})
if (fgType !== 'solid') {
const isLinear = fgType === 'linear'
const defs = isLinear
? ``
: ``
svgContent = svgContent.replace('