Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c76db7d8
authored
Dec 01, 2025
by
luoqiz
Committed by
GitHub
Dec 01, 2025
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: 修复icon丢失根属性导致的样式错误 (#6986)
1 parent
6f39e913
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletions
packages/icons/src/svg/load.ts
packages/icons/src/svg/load.ts
View file @
c76db7d
...
@@ -13,10 +13,28 @@ function parseSvg(svgData: string): IconifyIconStructure {
...
@@ -13,10 +13,28 @@ function parseSvg(svgData: string): IconifyIconStructure {
const
xmlDoc
=
parser
.
parseFromString
(
svgData
,
'image/svg+xml'
);
const
xmlDoc
=
parser
.
parseFromString
(
svgData
,
'image/svg+xml'
);
const
svgElement
=
xmlDoc
.
documentElement
;
const
svgElement
=
xmlDoc
.
documentElement
;
// 提取 SVG 根元素的关键样式属性
const
getAttrs
=
(
el
:
Element
,
attrs
:
string
[])
=>
attrs
.
map
((
attr
)
=>
el
.
hasAttribute
(
attr
)
?
`
${
attr
}
="
${
el
.
getAttribute
(
attr
)}
"`
:
''
,
)
.
filter
(
Boolean
)
.
join
(
' '
);
const
rootAttrs
=
getAttrs
(
svgElement
,
[
'fill'
,
'stroke'
,
'fill-rule'
,
'stroke-width'
,
]);
const
svgContent
=
[...
svgElement
.
childNodes
]
const
svgContent
=
[...
svgElement
.
childNodes
]
.
filter
((
node
)
=>
node
.
nodeType
===
Node
.
ELEMENT_NODE
)
.
filter
((
node
)
=>
node
.
nodeType
===
Node
.
ELEMENT_NODE
)
.
map
((
node
)
=>
new
XMLSerializer
().
serializeToString
(
node
))
.
map
((
node
)
=>
new
XMLSerializer
().
serializeToString
(
node
))
.
join
(
''
);
.
join
(
''
);
// 若根有属性,用一个 g 标签包裹内容并继承属性
const
body
=
rootAttrs
?
`<g
${
rootAttrs
}
>
${
svgContent
}
</g>`
:
svgContent
;
const
viewBoxValue
=
svgElement
.
getAttribute
(
'viewBox'
)
||
''
;
const
viewBoxValue
=
svgElement
.
getAttribute
(
'viewBox'
)
||
''
;
const
[
left
,
top
,
width
,
height
]
=
viewBoxValue
.
split
(
' '
).
map
((
val
)
=>
{
const
[
left
,
top
,
width
,
height
]
=
viewBoxValue
.
split
(
' '
).
map
((
val
)
=>
{
...
@@ -25,7 +43,7 @@ function parseSvg(svgData: string): IconifyIconStructure {
...
@@ -25,7 +43,7 @@ function parseSvg(svgData: string): IconifyIconStructure {
});
});
return
{
return
{
body
:
svgContent
,
body
,
height
,
height
,
left
,
left
,
top
,
top
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment