fix(qr): fix svg attribute malformation when injecting gradient defs

This commit is contained in:
2026-03-04 03:15:19 +00:00
parent f8953984ef
commit 858e880c38

View File

@@ -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><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
svgContent = svgContent.replace(/stroke="#000000"/g, 'stroke="url(#qr-grad)"')
}