fix: svg rendering (#9291)

* fix: svg max-width

* fix: disable sanitizer
This commit is contained in:
one 2025-08-19 12:21:48 +08:00 committed by GitHub
parent 86545f4fff
commit 585e49ac65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,4 @@
import { makeSvgSizeAdaptive } from '@renderer/utils'
import DOMPurify from 'dompurify'
/**
* Renders an SVG string inside a host element's Shadow DOM to ensure style encapsulation.
@ -15,12 +14,14 @@ export function renderSvgInShadowHost(svgContent: string, hostElement: HTMLEleme
throw new Error('Host element for SVG rendering is not available.')
}
// Sanitize the SVG content
const sanitizedContent = DOMPurify.sanitize(svgContent, {
USE_PROFILES: { svg: true, svgFilters: true },
RETURN_DOM_FRAGMENT: false,
RETURN_DOM: false
})
// FIXME: Sanitize the SVG content
// const sanitizedContent = DOMPurify.sanitize(svgContent, {
// USE_PROFILES: { svg: true, svgFilters: true },
// RETURN_DOM_FRAGMENT: false,
// RETURN_DOM: false
// })
const sanitizedContent = svgContent
const shadowRoot = hostElement.shadowRoot || hostElement.attachShadow({ mode: 'open' })

View File

@ -331,12 +331,14 @@ export const makeSvgSizeAdaptive = (element: Element): Element => {
}
}
// 设置 max-width
// 如果没有则设置 max-width
// 优先使用测量得到的宽度值,否则回退到 width 属性值
if (measuredWidth !== undefined) {
element.style.setProperty('max-width', `${measuredWidth}px`)
} else if (widthStr) {
element.style.setProperty('max-width', widthStr)
if (!element.style.getPropertyValue('max-width')) {
if (measuredWidth !== undefined) {
element.style.setProperty('max-width', `${measuredWidth}px`)
} else if (widthStr) {
element.style.setProperty('max-width', widthStr)
}
}
// 调整 width 和 height