replaceCurrentColor 函数用于替换 SVG 文件中的 currentColor 为指定颜色。
DOMParser 和 XMLSerializer)fetch 获取 SVG 文件import { replaceCurrentColor } from '@movk/core'
// 获取并替换 SVG 中的 currentColor
try {
const svgContent = await replaceCurrentColor('/icons/star.svg', '#ff0000')
// 创建 Blob 并显示
const blob = new Blob([svgContent], { type: 'image/svg+xml' })
const url = URL.createObjectURL(blob)
const img = document.createElement('img')
img.src = url
document.body.appendChild(img)
}
catch (error) {
console.error('SVG 处理失败:', error)
}
// 只获取 SVG 内容,不替换颜色
const originalSvg = await replaceCurrentColor('/icons/star.svg')
replaceCurrentColor(path, color?)替换 SVG 文件中的 currentColor。
b6146 — refactor: 统一源码文件命名为 camelCase