mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
feat(前端界面): 优化SVG资源引用处理性能
This commit is contained in:
1 parent
740c088bfd
commit
74b6b0ac93
1 file changed
+9
-7
@@ -1991,9 +1991,6 @@ function prefixSVGIds(svg, prefix) {
|
||||
return;
|
||||
}
|
||||
const replaceRef = (value) => {
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
let next = value.replace(/url\(#([^)]+)\)/g, (match, id) => {
|
||||
const mapped = idMap.get(id);
|
||||
return mapped ? `url(#${mapped})` : match;
|
||||
@@ -2007,10 +2004,15 @@ function prefixSVGIds(svg, prefix) {
|
||||
return next;
|
||||
};
|
||||
const attrs = ["clip-path", "fill", "filter", "href", "marker-end", "marker-mid", "marker-start", "mask", "stroke", "style", "xlink:href"];
|
||||
for (const node of svg.querySelectorAll("*")) {
|
||||
for (const attr of attrs) {
|
||||
if (node.hasAttribute(attr)) {
|
||||
node.setAttribute(attr, replaceRef(node.getAttribute(attr)));
|
||||
for (const attr of attrs) {
|
||||
for (const node of svg.querySelectorAll(`[${attr === "xlink:href" ? "*|href" : attr}*="#"]`)) {
|
||||
const value = node.getAttribute(attr);
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
const next = replaceRef(value);
|
||||
if (next !== value) {
|
||||
node.setAttribute(attr, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user