replaceCurrentColor此函数用于获取一个 SVG 文件,并将其中的 currentColor 属性替换为指定的颜色。这对于动态改变图标颜色非常有用。
假设 /icons/star.svg 的内容是:
<svg fill="currentColor">...</svg>
import { replaceCurrentColor } from '@movk/core'
async function getColoredIcon() {
try {
// 获取 SVG 并将 currentColor 替换为红色
const redIconSvg = await replaceCurrentColor('/icons/star.svg', '#FF0000')
document.getElementById('icon-container').innerHTML = redIconSvg
}
catch (error) {
console.error('处理 SVG 失败:', error)
}
}
replaceCurrentColor(path: string, color?: string): Promise<string>
currentColor 的颜色值。如果未提供,则函数仅获取并返回原始 SVG 内容。7a568 — feat: 初始化项目结构与核心功能