Skip to content

Commit

Permalink
refactor: update embed-svg-use.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Feb 4, 2024
1 parent eb405e1 commit c9664e8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/embed-svg-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ export function embedSvgUse<T extends SVGUseElement>(
if (svgDefsElement?.querySelector(query)) return [] // already exists in defs

if (definition) { // found local embedded definition
return [
// If custom cloneNode is used, the element's style will be defined inline, and the use tag cannot override the style.
// On balance, the probability that external styles will affect defs elements is small, so origin cloneNode is used.
new Promise<void>(resolve => {
svgDefsElement?.appendChild(definition.cloneNode(true))
resolve()
}),
]
// If custom cloneNode is used, the element's style will be defined inline, and the use tag cannot override the style.
// On balance, the probability that external styles will affect defs elements is small, so origin cloneNode is used.
svgDefsElement?.appendChild(definition.cloneNode(true))
return []
} else if (svgUrl) { // no local definition but found an url
// try to fetch the svg and append it to the svgDefsElement
return [
Expand Down

0 comments on commit c9664e8

Please sign in to comment.