Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 fix svg use element color error #76

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 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 @@ -28,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 [
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.
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
Loading