mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +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;
|
return;
|
||||||
}
|
}
|
||||||
const replaceRef = (value) => {
|
const replaceRef = (value) => {
|
||||||
if (!value) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
let next = value.replace(/url\(#([^)]+)\)/g, (match, id) => {
|
let next = value.replace(/url\(#([^)]+)\)/g, (match, id) => {
|
||||||
const mapped = idMap.get(id);
|
const mapped = idMap.get(id);
|
||||||
return mapped ? `url(#${mapped})` : match;
|
return mapped ? `url(#${mapped})` : match;
|
||||||
@@ -2007,10 +2004,15 @@ function prefixSVGIds(svg, prefix) {
|
|||||||
return next;
|
return next;
|
||||||
};
|
};
|
||||||
const attrs = ["clip-path", "fill", "filter", "href", "marker-end", "marker-mid", "marker-start", "mask", "stroke", "style", "xlink:href"];
|
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) {
|
||||||
for (const attr of attrs) {
|
for (const node of svg.querySelectorAll(`[${attr === "xlink:href" ? "*|href" : attr}*="#"]`)) {
|
||||||
if (node.hasAttribute(attr)) {
|
const value = node.getAttribute(attr);
|
||||||
node.setAttribute(attr, replaceRef(node.getAttribute(attr)));
|
if (!value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const next = replaceRef(value);
|
||||||
|
if (next !== value) {
|
||||||
|
node.setAttribute(attr, next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user