Skip to content

Commit

Permalink
fix: 馃悰 fix svg use element color error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojie09 authored and qq15725 committed Feb 4, 2024
1 parent 9827cad commit eb405e1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/embed-svg-use.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cloneNode } from './clone-node'
import { contextFetch } from './fetch'
import type { Context } from './context'

Expand Down Expand Up @@ -29,12 +28,12 @@ export function embedSvgUse<T extends SVGUseElement>(

if (definition) { // found local embedded definition
return [
cloneNode(definition, context)
.then(clonedChildNode => {
if (!svgDefsElement?.querySelector(query)) {
svgDefsElement?.appendChild(clonedChildNode)
}
}),
// 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()
}),
]
} else if (svgUrl) { // no local definition but found an url
// try to fetch the svg and append it to the svgDefsElement
Expand Down

0 comments on commit eb405e1

Please sign in to comment.