fix: SVG currentColor 替换为实际计算颜色
This commit is contained in:
@@ -1011,7 +1011,12 @@
|
|||||||
try {
|
try {
|
||||||
const svgClone = element.cloneNode(true);
|
const svgClone = element.cloneNode(true);
|
||||||
if (!svgClone.getAttribute("xmlns")) svgClone.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
if (!svgClone.getAttribute("xmlns")) svgClone.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
||||||
const svgStr = new XMLSerializer().serializeToString(svgClone);
|
// 替换 currentColor 为实际计算颜色
|
||||||
|
const computedColor = styles.color || window.getComputedStyle(element).color || '#000000';
|
||||||
|
const colorMatch = computedColor.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
||||||
|
const hexColor = colorMatch ? '#' + [colorMatch[1],colorMatch[2],colorMatch[3]].map(x => parseInt(x).toString(16).padStart(2,'0')).join('') : computedColor;
|
||||||
|
let svgStr = new XMLSerializer().serializeToString(svgClone);
|
||||||
|
svgStr = svgStr.replace(/currentColor/g, hexColor);
|
||||||
node.backgroundImages = ["data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgStr)))];
|
node.backgroundImages = ["data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgStr)))];
|
||||||
node.type = "RECTANGLE";
|
node.type = "RECTANGLE";
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user