fix(qr): fix svg attribute malformation when injecting gradient defs
This commit is contained in:
@@ -25,7 +25,7 @@ self.onmessage = async (e) => {
|
|||||||
? `<defs><linearGradient id="qr-grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="${fgColor1}" /><stop offset="100%" stop-color="${fgColor2}" /></linearGradient></defs>`
|
? `<defs><linearGradient id="qr-grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="${fgColor1}" /><stop offset="100%" stop-color="${fgColor2}" /></linearGradient></defs>`
|
||||||
: `<defs><radialGradient id="qr-grad" cx="50%" cy="50%" r="50%"><stop offset="0%" stop-color="${fgColor1}" /><stop offset="100%" stop-color="${fgColor2}" /></radialGradient></defs>`
|
: `<defs><radialGradient id="qr-grad" cx="50%" cy="50%" r="50%"><stop offset="0%" stop-color="${fgColor1}" /><stop offset="100%" stop-color="${fgColor2}" /></radialGradient></defs>`
|
||||||
|
|
||||||
svgContent = svgContent.replace('<svg ', `<svg >${defs}`)
|
svgContent = svgContent.replace('shape-rendering="crispEdges">', `shape-rendering="crispEdges">${defs}`)
|
||||||
// qrcode outputs <path stroke="#000000"...> so it's safe to replace
|
// qrcode outputs <path stroke="#000000"...> so it's safe to replace
|
||||||
svgContent = svgContent.replace(/stroke="#000000"/g, 'stroke="url(#qr-grad)"')
|
svgContent = svgContent.replace(/stroke="#000000"/g, 'stroke="url(#qr-grad)"')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user